#ot1-perplexing-regexing
1 messages Β· Page 560 of 1
ye
soup infact is my wife, but im not old enough to have a wife in the law books
who is that? sorry if he iconic, Me nEw to python community
hes the creator of python
he's the creator of python
damn
guido van rossum
HOLY!! Sorry your honor! For not knowing You you were. I am now informed who the masterpiece in the photo is. Cheers to all!
has kosayoda always been typing btw?
yes
yea
yes
yep
yep
Just everyone says a form of yes
yup
ye
Oui
ja
Π΄Π°
hanji
hyan
lol
speaker
k'taka
well its 4 for me
i see
tf?
Sad
Ik fluent hindi
But thts not my mother tongue
sameee but 6 years
I basically learnt hindi from cartoons lol
same
shinchan?
the normal one.
pink chocolate
whatever its called.
i like cookie 
is it just the colour or is the flavor different?
haha
next scaleios
what a coincidence.
lul
ok byebyebee
....
ooof
too dark too
electricity gone ?
Naw.
milk chocolate
flutter chocolate
hey guys
.love @polar knoll @median dome
Python Discord ModMail#6914 β€ Sir Lancebot#9543 scored 63%!
β
Your relationship will most likely work out. It won't be perfect and you two need to spend a lot of time together, but if you keep on having contact, the good times in your relationship will outweigh the bad ones.
.love @median dome @royal lake
Sir Lancebot#9543 β€ Python#4329 scored 86%!
β
Your relationship will most likely work out well. Don't hesitate on making contact with each other though, as your relationship might suffer from a lack of time spent together. Talking with each other and spending time together is key.
.love @wide verge @royal lake
David Bartholomew IIII#1448 β€ Python#4329 scored 59%!
β
Your relationship has a reasonable amount of working out. But do not overestimate yourself there. Your relationship will suffer good and bad times. Make sure to not let the bad times destroy your relationship, so do not hesitate to talk to each other, figure problems out together etc.
most interesting
.love @median dome @royal lake#4329
Sir Lancebot#9543 β€ @deleted-user#43777 scored 61%!
β
Your relationship will most likely work out. It won't be perfect and you two need to spend a lot of time together, but if you keep on having contact, the good times in your relationship will outweigh the bad ones.
Unable to convert 'love not really, i read the code' to valid command, tag, or Cog.
.src love
does anyone here using windows have a second to test something for me?
sure
what do u need to test?
def windows_memory_percent():
import ctypes
from ctypes import wintypes
class MemoryStatus(ctypes.Structure):
_fields_ = [
('ullTotalPageFile', ctypes.c_uint64),
('ullAvailPageFile', ctypes.c_uint64),
('ullTotalVirtual', ctypes.c_uint64),
('ullTotalPhys', ctypes.c_uint64),
('ullAvailVirtual', ctypes.c_uint64),
('ullAvailPhys', ctypes.c_uint64),
('ullAvailExtendedVirtual', ctypes.c_uint64),
('dwLength', wintypes.DWORD),
('dwMemoryLoad', wintypes.DWORD)
]
memStatStruct = MemoryStatus()
memStatStruct.dwLength = ctypes.sizeof(memStatStruct)
ctypes.windll.kernel32.GlobalMemoryStatusEx(ctypes.byref(memStatStruct))
return memStatStruct.dwMemoryLoad
# import psutil
x = [1,1] * int(1e8)
print(windows_memory_percent())
Just let me know if that returns a number or throws an error
gives me 0
well i guess I have some more work to do
Maybe I screwed something up since this wasn't a proper python file, but
interesting
Lemme see what IDLE says
Maybe I need to use a pointer π
I got 0 in IDLE
might be because it exceeded memory limits
at x = [1,1] * int(1e8)
Anyone familiar with sockets / winsock and python + cpp that could help me figure out what is wrong with my setup?
I have a cpp server running that sends an image as bytes, first the amount of images, then it loops through a vector and sends the image size and then the bytes. I have a python client that receives the messages. First iteration is fine but on second iteration the image size that should be an independant message is suddenly in the beginning of the image bytes
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
@wraith hound u know regex?
Not really
why would anyone do this http[s]? ???
optional s
Why not ask in pygen though?
ye
accepts http or https
ye
but
? makes it zero or more
the ? does that itself
what
he means that the [] are redundant
ye pretty sure they are
this regex is
http[s]?:\/\/(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*(),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+
?: within () would make it a non-capturing group
not sure what it means when its not in ()
ah, interesting
aaaaAAAA
!src
There's gotta be a url regex in there somewhere I can look at
(https?://[^\s]+)
Okay then.
the problem with that regex
@low chasm wtf
taim trahvel
Huh?
how
I'm just too good at this
Aboo can see the future
Indeed
lol
lol
like this: https://medium.com/flutter-community/navigate-without-a-buildcontext-in-flutter-code-guide-2d344ee0e4d6 ?
O
ye
oh my
I'm a bad, bad person
infinimata's response was to a different thing
sussy
a likely story
#ot1-perplexing-regexing and do not the cat
agreed
ah shit, I the cat
π
my guy lol
Ye
bruh nice
Pipfile lines 1 to 9
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true```
Ya, it's kinda new
bad code tho
4/27
deletes redundant pipfile statement
Bad Python bot code or bad other code?
this code
oh
the literal code it shows
smh
guess i need to parse a poetry.lock and convert it to a poppyfile.lock
ugh
poppy
bruh I'm never going to figure this out haha
I can no longer python3 -m robbie... how sad
goodbye robbie π
idk why it just refuses to work
and I can never find any good resources
._. it's installing the package with the name src
I would take a look at how flask handles setup and package structure tbh
It has a similar structure to yours, with scripts and a src dir
hmm
is it called getx
FYI
no
Getx.to(Page())
hmm
it can do more than state management
i will try it for future apps π
ah. yes, this helped
yes
it should be src/robbie/<all of robbie's code>, not src/<all of robbie's code>
so now.. I can do
#!/usr/bin/env python3
from robbie.__main__ import main
from robbie.utils import entrypoint
@entrypoint
def _entry():
main()
and it works
nice
tf is robbie
what does it do
robbie
on second thought
...
Does it work now?
yes
+-------------+ +-----------+
input -> | |---------->| | >----------+
| HTTP POST | | SNEKBOX | execution |
result <- | |<----------| | <----------+
+-------------+ +-----------+
^ ^
| |- Executes python code
| |- Returns result
| +-----------------------
|
|- HTTP POST Endpoint receives request and returns result
+---------------------------------------------------------
yert
k
i broke my snekbox lol
good
Is there such a way to clean unused site packages in pip
i think theres a pip pacjage for that
Does it clean itself
fuckin hell
there is no null safety on that package
:/
what was that
oh nothing
lmao
since there's both a pyproject.toml and a pipfile
I uh
did the unspeakable.
i created two virtual enviroments
soup
u know a language is old when it supports goto label statements
!pypi toml
Hello I'm Brazilian and I would like to know what you think of Brazil (I don't know how to speak English)
Henlo
POETRY IS GREAT
is it
yes
I've neva been, but Football seems great there! soccer as some would call it
i managed to turn @polar knoll into a wheel without much packaging knowledge
How to confuse everyone 101
because I can't tell what the difference is
what is football and what is soccer
do you mean football or soccer
by "football" do you mean football or soccer \π©
my brain hurts
When I say football I mean Soccer, because I don't like saying soccer
... but what is soccer to you
Thats Why when I refer to Footbal in America, I say "American Football"
It... Is nothing...
:faint:
why does chocolate dipped lemons sound good
No
it does tho
No
mkay
K
I sure do love my chocolate dipped lemons
it... does
β¦ it really does
i need to try this
if I do I'll send a picture
Chocolate oranges are a thing, cant imagine why lemons wouldnt be
mhm
Yes please
i don't imagine chocolate lemons being bad at all, with sugar from the chocolate tbh
chocolate lemon sounds kinda good
lemons are less acidic than limes so...yeah. better than chocolate covered limes
:sus:
flake9
lol
dont they all have to be on at the same time
Hello, I need some help linking up pycharm accounts using github, rq, where can I access the sign in page on pycharm?
wait nvm, got it
havent used pycharm is a super long time but i think when u do a push it prompts u for an account
yeah it does
yeah
I was just trying to sync my chromebook account with my desktop
now all I need to do is learn how to use linux right, and see if I can sync projects then I'll be in the clear
I'm trying to figure out the best way to do because 100% there's no way this is efficient. I'm making chess and I'm now realizing my method of checking if a move will put the player in check, won't actually work, The way I have it now is by iterating over the board (dict), if the piece belongs to the opponent, check all possible legal moves, append them and return that list. Then make the move and check if that new position is in the list.
This works great if the king is the one moving but doesn't if it's not as it only checks the moves up to a piece - not past it. I've realized now that I need at least 2 layers of depth for any other piece (opponent moves -> player responses -> opponent moves to response). That means I have to find all possible opponent moves + for each one of those moves, find all possible responses + for each of those, find all possible opponent moves and return that.
I've had the thought of running this on a separate thread and running it right after a player makes a move in the game loop (with the exception of maybe running it at start of game (with a depth of 1), and causing the main thread to block until it gets that list. The issues is it will have to run:
for opponent_pieces:
for opponent_pieces.legal_moves():
for player_piece.legal_moves(`board):
for opponent_pieces.legal_moves(``board):```
and I'm a bit concerned about the complexity/time it'll take. I had some idea of caching a piece's possible moves - hashing them based on their current position - letting the loops use the cache if the piece hasn't moved but is there a better way to approach this?
you can cache the "in-check" positions from the previous move
would probably just be a set of coordinates or something
but wouldn't that be invalid after the opponent moves?
then you can calculate it again
doesn't that negate the purpose of caching it
you don't run into your quarduply nested for loops
it's just move_target in in_check_squares
Here
Ok
see that works if I'm moving the king but doesn't work in a position like this:
Thatβs a good question
@vapid nymph https://github.com/Saransh-py/Ranzers.git
Lmao
hello Bois
bruh why did they call it memoization, coulda called it caching
simple and effective
yeah
So, you say that windows is the best, but beside better app support, why is that?
What benefits does it have
I think windows i the most common and hence is supported by all applications
It's slower than Linux, heavier, and is limited in customization
besides app support
many dev tools are better in linux
^
you get gcc chan builtin
Hence why a lot of devs use linux
and i have to use mingw like a n00b
this only is the main reason for me. lol
Lmao
in what way is it slower?
it just uses more resources
And more and more apps are being ported to Linux
More resources being used can result in it being slower
Why not
mAcOs iS bEsT ok goodbye
can
not in my pc
No you fucking come back here
πββοΈ
On low end machines, people use linux over windows
ah! to be frank I am using windows from past 10 years. so i am used to it and don't want to change. that's all π
Sure on a decent pc it won't make a difference
thats exactly the problem
But the fact is there that Linux uses less resources
people are resistant to change
Windows shoves updates down your throat
exactly when you need to do something important
Yep
that's where the problem comes. also windows 10 is resource hungry
But for most users, windows is fine
that is a valid reason
yes, I think that's called the... boomer mentality
Guys how can you write a schema for a toml?
I think so, anyways... that people are reluctant to change simply because it's not what they're used to
yeah
atleast they can experiment with stuff
they wont even TRY other things
I don't think you can truly bash Linux without using a modern Linux distro thoroughly
bash Linux? is that an awful pun?
go to #python-discussion
Oh shit
I'm so good at puns I don't even know when I'm making em
have you seen garuda linux. i like its design. fluid tabs
this genius, it's almost frightening
you can add rainmeter
but its limited
its 10:40 am here
Garuda is a no-go, truthfully
Haha
Including deleting the root π
design aside it has cool features
worth trying
I'm not the most fond of it
no
Just use arch
Arch-derivatives will never be good
Some are half decebt
it has built in BTRFS and ZRAM
Though we can all agree, fuck manjaro
If you don't want Arch, you don't want an Arch derivative
You can get it
Why are you comparing Arch to ootb
ootb...
Oh wait
give a mac to a windows user and he will ask how the hell should i copy. there's no ctrl button. (and vice-versa)\
Ha yeah
well the point is for a newbie, garuda is a nice distro
Arch's DIY... there's almost nothing ootb
If your a new user
yes
A newbie's not going to know how to use btrfs lmfao
Do not at all use arch or a deritive
or what zram even is
zram is automatic
sad i use arch btw noises
no one needs to know anything
For newbies, just go with lubuntu, kubuntu, or xubuntu
If your a new user
i heard of a chromeOS too. never saw it tho
Ah no
eww
Then you simply forgot to tick the install additional software option
My school uses chromebook
sudo die
no
i installed proprietary drivers
hmm
a lot of screen tear
Open source?
Did you use bumblebee or something
I can only assume you did something wrong
i dont understand why the fuck do schools give students the worst OSes to work on. also some shitty IDEs too like code:blocks
yes
Chromebook are cheap and easy to moderate
I truthfully don't believe ChromeOS is bad
It's good at what it does
this is funny as shit
But school ruined it for me
but I'd never personally use it willingly
Lmao
my school still used windows 7. lmao
anyways i tried linux and stuff, and until windows breaks, i wont switch
That's fair
same here
tbh I don't really ever trust the word of "tried linux"
I balance both of em
tbh you dont trust anything
I mean it's just one of those things
tbh i trust windows
which linux will you suggest me to use. i have 4 gigs of ram. and i want a nice design too
If you found it that bad, you must be doing something wrong
Kubuntu is nice
you can make linux look like whatever
nice design can be achieved by any distro right?
ye
So is Xubuntu
Distro is not what matters, usually
k .thanks
Kubuntu is just very easy to customize out of the box
epic
will be back later
And it's beginner friendly
Guys is there a way to define schemas for toml?
Kubuntu is nice, but might take too much RAM
So the IDE can suggest stuff
as in?
Anyways, it's 1:16 am, and I should sleep, gn yall
Like json config schemas
there is a toml extension na?
There is
but I don't think there's a way to tell the IDE what to look for
that wouldn't make much sense
Yeah, but the schema for a custom definition
The IDEs themselves add stuff like that
There's json schemas
It depends on the JSON, doesn't it?
Yeah but you can basically put a link at the top of the file and it suggests stuff based off of that
Ik vscode does that, not sure of pycharm and others
Yeah. A cool thing is it can be more than just vscode settings :)
I'm curious if such a thing exists for toml or yaml
hmm
Why not json
you can't have comments in JSON
yaml
u can have comments
Joe yes imma out him would use toml
i edited a tsconfig.json and it was filled with comments
You can't have comments in JSON
yaml is a superset of json
bruh
toml, for ease of use
Toml because in toml you can have sections
tables ftw
your choice, i had go wtih yaml
Actually, thinking about this. Toml sections make the most sense for the different things these configuration are for
yea
toml does makes more sense for config
Ye
In [1]: import json
In [2]: json.loads("""{\n "owo": "uwu" # this is a comment\n}""")
---------------------------------------------------------------------------
JSONDecodeError Traceback (most recent call last)
?
If anyone wants to devils advocate against toml please do so
bruh
In [3]: json.loads("""{\n "owo": "uwu"\n}""")
Out[3]: {'owo': 'uwu'}
is not a comment in json
sad
ig some parsers just ignore //
^
JSON has comments
can have*
JSON doesn't have comments
its not recommended
Iirc vscode literally calls it json with comments
ye
ye
ye
It depends entirely on the implementation
but JSON itself does not have comments
ye
and ini/toml/yaml are better suited for configuration
Ini looks just like toml ngl
π
they're the exact same syntax wise, I think
but... what?
!pypi toml
Tom's Obv- yes
While we're at it
it's configparser
!pypi ini
!pypi configparser
ye
Source code: Lib/configparser.py
This module provides the ConfigParser class which implements a basic configuration language which provides a structure similar to whatβs found in Microsoft Windows INI files. You can use this to write Python programs which can be customized by end users easily.
Note
This library does not interpret or write the value-type prefixes used in the Windows Registry extended version of INI syntax.
"TOML is somewhat similar to the INI format, but unlike INI, it has a standard specification and well-defined syntax for nested structures."
yes
interesting
Cool so the next step for me is to abstract away the settings to a toml
precisely
Yes all of the default settings are literally coded into the bot ;-;
that or use a Python file
Eh
like how setuptools has setup()
Nah
that way you can more easily govern what's put in
Wdym
with type-hints
and like.. mypy apir or something for checking
and whatever else... baked right in
toml + pydantic/dataclasses/metaclassess
no parsing and what-not
can i keep kubunto os along with windows 8.1 without losing my data
Yes
!pypi pydantic
Whats mypy
!pypy mypy
i already use TOML for all my GUI's
you can use the API in your code to enforce static typing
Pydantic can take user input and changes it to a model
I don't know what that means
Validates its all the correct type
The example
from datetime import datetime
from typing import List, Optional
from pydantic import BaseModel
class User(BaseModel):
id: int
name = 'John Doe'
signup_ts: Optional[datetime] = None
friends: List[int] = []
external_data = {'id': '123', 'signup_ts': '2017-06-01 12:22', 'friends': [1, '2', b'3']}
user = User(**external_data)
print(user)
#> User id=123 name='John Doe' signup_ts=datetime.datetime(2017, 6, 1, 12, 22) friends=[1, 2, 3]
print(user.id)
#> 123
!pypi serde
Yeah I guess
or... in general
basically you make a struct statically typed with attribute names as the keys
and like JSON, for example (with serde_json)... it'll map it to the struct
I'm confused lol
that is dope
#[derive(Serialize, Deserialize, Debug)]
struct MyJSON {
name: &str,
age: i32
}
let my_object: MyJSON = serde_json.from_str(r#"{"name": "John Doe", "age": 42}"#).unwrap();
My Rust is... Rusty, but that's it, basically
whats r#
OK yea same thing I think
i thought that was just r
So gonna use toml and pydantic
Damn this seems easy enough to redo the config
in Python, you have to say like "\""
The hard part is actually gonna be going through the entire bot and replacing the old config variables lol
damn
It's such a good library
I love strongly typed things
Like things don't have to be typed with JSON, but it's faster and much safer
hi
because you don't need to have an attribute for every single key-value field... you can leave out what you don't need
im a freshe
so
struct MyJSON {
name: &str
}
for
{
"name": "Mr. Oooga-Booga",
"age": 42.0
}
is still valid... but age just goes poof
@last mantle yo
if one of my ram modules is 2400mhz can i have another ram module with a higher clock
or should they both stay the same
hm
so they will both run at then slowest clock
if they are differnet clock speeds
interesting
idk if they will be compatible
but if they are it makes sense to run at the common clock
yes
ok
@alpine edge Your past few messages haven't been meaningful, please don't post such messages
Hi
So I have been working on a reminder app made entirely in kivy and kivymd and I needed some help in testing it out. If anyone wants to help in testing please fill out the following form. You must have an android device and a telegram account for bug reporting. Here are some screen shots of the app https://forms.gle/SyD48QX1aJkEPLi89
cool, but python is not really recommended for mobile app dev, but its ok
the ui is nice
yep learnt that the hard way when working on dev...wanted to see how far python can go on mobile dev
thanks!
that... is a bit sus
why did you have to shorten the url there was no need to
its literally longer than just https://pydis.com/timeline/
I just dicovered this url_shortener on reddit http://www.shadyurl.com/
It's fun but you're right but there was no need to π
shadyurl
buy priority queue then, ik its $20 per month, if don't want to then you just have to face the normal queue, orjust play on another server lol
Oh just, you know, play on another server
@halcyon cosmos answering you here since it was a js question:
removing the ) after 'ready' on line 6 should fix the problem
ok wait
I probably won't be able to answer if you have any follow up questions because I have 0 experience with discord.js
oh ok
the () => {...} is (yet another) syntax for making an anonymous function
the bot.on takes this function as one of its arguments
Node.js is very event oriented, so a lot of things use arrow functions to respond to events
also console.Log should be console.log
ok
uff yeah thanks for the help man!

but its still not starding
hmm
can i get in a Voice with you
and you help me tehr
ther
nah, like I said I have no experience with discord.js
Can you show the code?
I've used d.js before
are arrow functions = anonymous functions?
also are there commands in d.js
Yes, they're like lambdas but more powerful
as in?
Yes, although you have to implement them yourself. But if you follow the guide, it's easy
o ok
Wdym?
like how are they more powerful
yeah wait
const Discord = require('discord.js')
const bot = new Discord.Client();
bot.on('ready', () => {
console.log('Bot online')
}
this is the Code
to become the bot Online
as in multiple functions?
That won't make the bot go online
oh ok
ok
ur missing a closing )
No, just that arrow functions can have statements longer than one line
So wherever the bot is written, should I write the client?
oh alright
Yes, replace bot with client
ye
wait
waiting
no
where
after everything
ok
just put it in the end
At the end of your index.js
ye
You should follow https://discordjs.guide
It's a really good way to learn discord.js
i follow this https://www.youtube.com/watch?v=5U-DOBPTvLA
ok
the actual guide is better
tis one
Assuming that's the video I'm thinking of
Alright, making a bot is cool and all, but there are some prerequisites to it. To create a bot with discord.js, you should have a fairly decent grasp of JavaScript itself.
from the guide ^^
okay
I should steal that for this server
Alright, making a bot is cool and all, but there are some prerequisites to it. To create a bot with discord.py, you should have a fairly decent grasp of Python itself. While you can make a bot with very little Python and programming knowledge, trying to do so without understanding the language first will only hinder you. You may get stuck on many uncomplicated issues, struggle with solutions to incredibly easy problems, and all-in-all end up frustrated. Sounds pretty annoying.
That part is so well written
I don't check the guide
bruh
ye
To create a bot with discord.py, you should have a fairly decent grasp of Python itself.
#discord-bots: This sign can't stop me because I can't read
lol
Lol
haha
ye
ive never really tried d.js
the onmessage triggers me
why
idk
bruh
i like commands more
well
the way dpy handles it
hmm
i forget its name
commandeer or something
That's cause node.js is event oriented
not having command handling in the library itself is a weird choice
It's not a d.js thing
hmm
D.js has commando
It's just that a lot of people prefer to implement it themselves
Which is something they teach you how to do in the guide
hey do you have a video which is better?
docs are usually good
ok
d.js docs are also surprisingly nice
damn
well
chad
hmm
bruh
moment
no
do you think this Video is good? https://www.youtube.com/watch?v=O2GBIusajOg
dew it
seriously tho i prefer d.js over d.py, and even if you dont like it you should give it a shot
try C# then π so many languages
whats that?
making guis in C# is pretty nice
Flutter is a UI toolkit that works with Dart
oh why
Evorage, did you get to see my C# app? π
no? wheres that
This is a C# WPF app calling to Rust code via FFI
ooo nice
ive always know WPF is powerful but i struggled with it
OHHH your fractal thing, that was WPF? nice
haha
Woah
So that's how you maintained good quality?
by the way, do you know any visual GUI editors that aren't Visual Studio/Blend?
how long have you been learning C# @gritty zinc ?
not long if i remember right, doing great tho lol
I just don't want to install the gigabytes-big C# workload for VS π©
that was my second day, I think
ive always used Unity even for just GUI stuff π very powerful
yikes
π
SECOND AND U MADE THAT? smh iβm slow
I think I'd sooner use Electron than start using a gameengine for a simple GUI π
JEEZ your second day, wow im impressed, by my second day i had a label in the centre saying hello world
Qt Designer for Qt
and I don't plan to use electron
good π
Woah
concattmed reptile pro
some things were annoying to do, I spent like an hour of two just figuring out how to make an image from bytes
how did you do that in the end?
the answer turned out to be
private static BitmapSource ArrToGrayscale(byte[] array, uint w, uint h) {
var format = PixelFormats.Gray8;
var wbm = new WriteableBitmap((int) w, (int) h, 96, 96, format,
null); //TODO: use the other override to work with the pointer to array directly
wbm.WritePixels(new Int32Rect(0, 0, (int) w, (int) h), array, (int) w, 0);
return wbm;
}
how to do it with just BitmapImage like you can (supposedly) with rgb images? hell if I know π©
looks complicated π
passing a Vec<uint8> comparatively wasn't too horrible
// ReSharper disable once InconsistentNaming
public struct FFIVec
{
public unsafe byte* Ptr;
public ulong Len;
public ulong Cap;
}
[DllImport("fractal_calculator.dll")]
private static extern FFIVec calculate_mandelbrot_vec(
F xMin,
F xMax,
F yMin,
F yMax,
uint width,
uint height,
uint maxIters,
F horizon
);
// ReSharper disable once InconsistentNaming
private static byte[] FFIVecToArr(FFIVec vec) {
var totLen = vec.Len;
var temp = new byte[totLen];
unsafe {
Marshal.Copy(new IntPtr(vec.Ptr), temp, 0, (int) vec.Len);
}
return temp;
}
specify it's an external function, yeah, loaded from a dll
hmm
and the Rust side looks like
#[no_mangle]
pub extern "C" fn calculate_mandelbrot_vec(
x_min: F,
x_max: F,
y_min: F,
y_max: F,
width: u32,
height: u32,
max_iters: u32,
horison: F,
) -> FFIVec<u8> {
let arr = calculate_mandelbrot(
x_min, x_max, y_min, y_max, width, height, max_iters, horison,
);
arr.into_raw_vec().into()
}
plus I had to make my own FFIVec struct
you made a dll from a rust script?
yeah, all it took was
[lib]
crate-type = ["cdylib", "rlib"]
name = "fractal_calculator"
in cargo-toml
interesting
"C" means make the function follow the C function calling convention. There's only two options - that, or ASM
asm is assembly?
and I'm okay with it not being callable from assembly π
lol
the cdylib here makes it generate a DLL
goes way over my head lol, nice tho
(I'm also specifying rlib is so that the binary crate I use for testing doesn't break)
(dunno why)
is it possible to make a dll from python scripts then?
to be fair you can just import them
no?
lol
but there are libraries to call python functions from compiled langs
for, say, scripting purposes
i dont really get how dll's work π’ i just know you can import them and they run their code
ooo nice
as far as I'm aware, DLLs are basically exes but without an entry point
you can't run them directly, but besides that they can be full-fledged programs
ah yeah that makes sense, just a bunch of functions you can call with no main()
oh, and here's the struct:
#[repr(C)]
pub struct FFIVec<T> {
pub ptr: *mut T,
pub len: u64,
pub cap: u64,
}
impl<T> From<Vec<T>> for FFIVec<T> {
fn from(vec: Vec<T>) -> Self {
Self::new(vec)
}
}
impl<T> FFIVec<T> {
pub fn new(mut x: Vec<T>) -> Self {
let s = Self {
ptr: x.as_mut_ptr(),
len: x.len() as u64,
cap: x.capacity() as u64,
};
mem::forget(x);
s
}
}
normal Rust Vecs don't have a #[repr(C)]
so they aren't FFI-safe
so I needed this tiny struct (three fields and a method to make it from a normal Vec)
it's exactly like a Vec works, but it's guaranteed π
whereas Vecs, I guess, can potentially not be in the right memory layout
I'm actually surprised I didn't need any unsafe code on the Rust side.
one would think forget would be unsafe, but no:
forget is not marked as unsafe, because Rustβs safety guarantees do not include a guarantee that destructors will always run. For example, a program can create a reference cycle using Rc, or call process::exit to exit without running destructors. Thus, allowing mem::forget from safe code does not fundamentally change Rustβs safety guarantees.
That said, leaking resources such as memory or I/O objects is usually undesirable. The need comes up in some specialized use cases for FFI or unsafe code, but even then, ManuallyDrop is typically preferred.
Because forgetting a value is allowed, any unsafe code you write must allow for this possibility. You cannot return a value and expect that the caller will necessarily run the valueβs destructor.
The need comes up in some specialized use cases for FFI
As always, Rust docs don't fail to be relatable π
yeah but the dual [[]]
see the docs
can't find any search results on it
its a 10 min read
The Notion API seems useful
Maybe I'll write something on there and publish it on my website
it means it's a list, I believe
not just a single option
yeah
horison or horizon
?
lol
shit
very true freind
include = ["default-config.toml"]
in my pyproject.toml for poetry
but how do i actually make it include the file with the wheel
or is that not possible?
wait nvm
it doesn't bundle with the file in that case 
need to learn responsive website building. html, css and javascript for free. any suggestion from where to learn. (video lectures)
I haven't taken this course myself, but this coursera course has really good ratings and is free. https://www.coursera.org/learn/html-css-javascript-for-web-developers
thanks man