RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.27.0 | Fund Crystal's development: http://is.gd/X7PRtI | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Gitter: https://gitter.im/crystal-lang/crystal
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 245 seconds]
gangstacat has quit [Ping timeout: 252 seconds]
rohitpaulk has joined #crystal-lang
gangstacat has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 245 seconds]
blove has joined #crystal-lang
blove has quit [Client Quit]
blove has joined #crystal-lang
blove has quit [Client Quit]
sevensidedmarble has quit [Remote host closed the connection]
blove has joined #crystal-lang
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 244 seconds]
kandayo has quit [Read error: Connection reset by peer]
rohitpaulk has joined #crystal-lang
<FromGitter> <redcodefinal> Hey been working with `UDPSocket` and I'm trying to get it to send packets to a broadcast address (255.255.255.255). I can't really find much in the way of documentation on how to use the `Socket#setsockopt` method. Currently I have a working version of this in ruby ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ This gives a permission denied error. ... [https://git
<FromGitter> ... ter.im/crystal-lang/crystal?at=5bf629ade25cc2740523bde9]
rohitpaulk has quit [Ping timeout: 268 seconds]
<FromGitter> <redcodefinal> Also additional info, I'm running this code as root.
rohitpaulk has joined #crystal-lang
<FromGitter> <redcodefinal> Never mind I figured it out, it turns out optval needs a bool as integer value.
<FromGitter> <redcodefinal> `u.setsockopt LibC::SO_BROADCAST, 1`
<FromGitter> <jemc> Trying to write a Crystal program that uses the `llvm` library. Here's the example program I'm trying to compile (https://play.crystal-lang.org/#/r/5lhk). I get a similar link error locally as the one seen there. I have `llvm-config50` present on my `$PATH`. What else do I need to do to get LLVM to link properly with my Crystal program?
<FromGitter> <jemc> I noticed there is a sample Crystal program using `llvm` in the main repo here, but I don't see any special linking instructions nearby: https://github.com/crystal-lang/crystal/blob/0004179c9576c89d14e617423828af6f31e6d7a1/samples/llvm/brainfuck.cr
jemc has joined #crystal-lang
korzybski has quit [Quit: korzybski]
sp3ncer has joined #crystal-lang
blove has quit [Quit: WeeChat 2.2]
rohitpaulk has quit [Ping timeout: 264 seconds]
<FromGitter> <proyb6> Is it possible to declare variable as a pointer so I could make it refer to the data in particular memory?
<FromGitter> <hello2dj> hello, guys, what's the difference between Slice and Array, when to use Slice or Array
jemc has quit [Ping timeout: 252 seconds]
jemc has joined #crystal-lang
rohitpaulk has joined #crystal-lang
jemc has quit [Ping timeout: 250 seconds]
<FromGitter> <j8r> If you ask, you don't need it
<FromGitter> <j8r> You rather mean Tuple vs Array. Tuple is an immutable Array
<FromGitter> <hello2dj> yes
<FromGitter> <hello2dj> thank you
<FromGitter> <j8r> @proyb6 you can declare a Pointer like `var = pointerof(true)`. The type will be `Pointer(Bool)`. You can modify the value with `var.value = false`
sp3ncer has quit [Quit: Textual IRC Client: www.textualapp.com]
rohitpaulk has quit [Ping timeout: 252 seconds]
<FromGitter> <proyb6> @j8r What if the context.response for HTTP could also use pointerof(context.response)?
<FromGitter> <j8r> I'm happy with the performance https://github.com/j8r/con#benchmarks :)
ashirase has quit [Ping timeout: 276 seconds]
ashirase has joined #crystal-lang
<FromGitter> <j8r> @proyb6 Context (https://github.com/crystal-lang/crystal/blob/master/src/http/server/context.cr#L3) is a class, you already pass it by reference
<FromGitter> <icyleaf> Hi guys, Is there has solution to reflecting a struct or class outside itself in Crystal?
<FromGitter> <proyb6> @j8r I see, like your CON shard!
rohitpaulk has joined #crystal-lang
korzybski has joined #crystal-lang
korzybski has quit [Client Quit]
rohitpaulk has quit [Ping timeout: 268 seconds]
<FromGitter> <j8r> @icyleaf what's reflecting? You can have a method returning `self` to have the current object
<FromGitter> <kingsleyh> Hi - if anyone with Dev skills is interested in helping out on SushiChain (blockchain project) please contact me - I’m open to giving out coins or future equity - obviously we have no worth right now - but once listed on an exchange then we will have some worth - we have lots of interesting things to do :)
<FromGitter> <vladfaust> @j8r are you intending to keep the naming as Cretin ..?
<FromGitter> <j8r> @vladfaust haha I think yes, second degree humor. I've purposely started with C to have alternative names like Configuration Object Notation or Crystal Object Notation.
<FromGitter> <j8r> Cretin is similar to Git
<FromGitter> <j8r> (https://en.wikipedia.org/wiki/Git#Naming) . Con can also means scam, and dumb in French. ⏎ All of this means this serialization format is designed to be used by even the dumbest person, like me 😄
<FromGitter> <rishavs> Is there an elegant way to convert an array into a hash or json? Currently i am using map and doing gnarly string operations. ⏎ my input is `["tag1", "tag2", "tag3"]` and the expected output is `{"tag1" => true, "tag2" => true, "tag3" => true}`
<FromGitter> <yxhuvud> if you have true for all the values, have you looked at Set?
<FromGitter> <rishavs> I am fine with any recurring dummy value. I generally use true or 1. I haven't used sets before
<FromGitter> <rishavs> My keys are unique, so sets might be good here
<FromGitter> <j8r> @rishavs what do you need at the end?
<FromGitter> <j8r> a list of non duplicated values?
<FromGitter> <rishavs> this :D `{"tag1" => true, "tag2" => true, "tag3" => true}`
<FromGitter> <rishavs> I generally convert this hash into json to insert into my database
<FromGitter> <rishavs> For example, if I do ⏎ ⏎ ```myarray = ["nature", "news"] ⏎ pp [myarray, [true, true]].to_h ``` ⏎ ⏎ i get `{"nature" => "news", true => true}` but I want `{"nature" => true, "news"=> true}` [https://gitter.im/crystal-lang/crystal?at=5bf6a72aed6bcf1ef841c08e]
<FromGitter> <j8r> https://carc.in/#/r/5lpb
DTZUZO has joined #crystal-lang
<FromGitter> <rishavs> Thanks! Can I also do this with map?
<FromGitter> <vladfaust> Any way to get a *NamedTuple* which is a diff between two NamedTuples?
<FromGitter> <vladfaust> NM, expanding namedtuple for myself
<jokke> RX14: hey there o/ i'm testing out the pub-relay and i get a 503 back from my mastodon instance when i try to subscribe to the pub-relay. Any idea what that means? The instance is accessible from the pub-relay and responds correctly for other routes.
<RX14> what does the log say
<jokke> which one?
<RX14> the relay...
<jokke> sec
<RX14> if its a 503 there should be a fairly clear error in the logs
<jokke> RX14: not much: https://p.jokke.space/pVvx/
<jokke> that's all i see
<RX14> ...huh
<RX14> i cant even find a place where it could return a 503
<RX14> oh wait jokke
<jokke> it's not pub-relay that's returning 503
<jokke> it's my instance
<RX14> yeah
<RX14> oops
<jokke> np :)
<RX14> check the logs for that then?
<RX14> its probably a dupe subscription or something
<jokke> there's nothing in the logs except that 503 was returned
<RX14> weird
<jokke> yeah
<RX14> try unsubscribing and resubscribing to the relay
<jokke> i did :/
<jokke> oh wait
<jokke> unsubscribing?
<jokke> how?
<RX14> yes
<RX14> it should have the relay as pending or something in the mastodon dashboard
<jokke> yes
<jokke> i can click on x
<jokke> (i did this already though)
<RX14> ok, thats unsubscribing
<RX14> go tell eugen :P
<jokke> if i do that, nothing will be sent to pub-relay though
<jokke> or is that irrelevant
<RX14> well its not working anyway is it
<jokke> well. no
<RX14> i meant unsubscribe and resubscribe to see if it starts working
<RX14> but it clearly doesnt
<jokke> ah yeah
<jokke> no
<jokke> maybe loggin the server response body would provide some insight
<jokke> *logging
<RX14> perhaps mastodon having better logging would provide some insight
<jokke> heh yeah
<jokke> no luck so far
<FromGitter> <fenicks> Hi everyone
<FromGitter> <vladfaust> Hello, @fenicks
<FromGitter> <vladfaust> NamedTuple#diff: https://carc.in/#/r/5lq1
<FromGitter> <fenicks> Hey @vladfaust
<FromGitter> <fenicks> I'm looking a way to set which core a crystal program can use. It's called cpu affinity most of the time.
<FromGitter> <vladfaust> Have no idea what are you talking about :)
<FromGitter> <fenicks> @vladfaust , ok you now when you build and run a program on multi-core machine, you can specify which core your program will use. On Windows odd core ID are master (more powerful), on linux even core Id are master.
<FromGitter> <vladfaust> TIL
<FromGitter> <Sija> @fenicks I guess you'd need to use `sched_setaffinity(2)` (https://linux.die.net/man/2/sched_setaffinity) - on linux - and friends - on other systems
<FromGitter> <fenicks> @Sija Thanks. I was looking for a crystal shards if not I'll use a C binding. Nice!
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 244 seconds]
<FromGitter> <rishavs> Need some help with creating json like strings. I have a hash which I convert to json. But now inside the string a lot of "\" come which I dont want. https://carc.in/#/r/5ls2
<FromGitter> <Blacksmoke16> use `puts`
<FromGitter> <bararchy> yeha `pp` shows escape letters, if you print or `puts` those strings you wont see it
<FromGitter> <rishavs> @Blacksmoke16 the problem is that I am trying to add these string to some fancy db queries via string interpolation. ⏎ For example; ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5bf6cbdbc6cf4524d15d7e85]
<FromGitter> <rishavs> or a better example is `INSERT INTO books VALUES (1, '{"title": "Sleeping Beauties", "genres": ["Fiction", "Thriller", "Horror"], "published": false}'); `
<FromGitter> <bararchy> oh no
<FromGitter> <bararchy> this is an SQLi waiting to happen
<FromGitter> <bararchy> never interpolate inside a query string, always use Parameterized Queries and Prepared Statements
<FromGitter> <sdzyba> I remember a discussion regarding dependency importing in Crystal. ⏎ Just saw an interesting (although not "native") way to do explicit imports in Ruby: https://github.com/ciconia/modulation
<FromGitter> <rishavs> dont SQLi only happen when you are accepting user input? If my app itself is generating the query, i dont think anyone can inject anything in the sql
<FromGitter> <bararchy> @rishavs if the data is never from user input you should be "safe" unless a change occuer and you forget about this part of the code and then half a year later your whole DB is in pastebin
<FromGitter> <bararchy> better to use ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5bf6cdcf375c40294bacac18]
<FromGitter> <bararchy> ^ this style
<FromGitter> <bararchy> And if you really want to do a good job, follow: https://www.owasp.org/index.php/SQL_Injection_Prevention_Cheat_Sheet
<FromGitter> <rishavs> gotcha. good point. so I will have to do something like this ⏎ `INSERT INTO books VALUES (1, $1), "'{"title": "Sleeping Beauties", "genres": ["Fiction", "Thriller", "Horror"], "published": false}'"`
<FromGitter> <rishavs> but my original problem still remains, getting a json like string without \
<FromGitter> <bararchy> @rishavs your example have `\` only because you print with `pp`, it's not really there
<FromGitter> <rishavs> oh! did i really waste an hour over something like ?? T_T
<FromGitter> <bararchy> => https://carc.in/#/r/5lsj
<FromGitter> <rishavs> lmao. thanks @bararchy
<FromGitter> <bararchy> np :) good luck
rohitpaulk has joined #crystal-lang
korzybski has joined #crystal-lang
<FromGitter> <j8r> @bararchy thanks, nice read indeed!
<FromGitter> <jemc> Still having trouble linking LLVM to compile a program that uses the `llvm` library in Crystal. I have tried with both LLVM 5 and LLVM 6 (installed with `dnf`, my package manager). I downloaded this sample from the main crystal repo (https://github.com/crystal-lang/crystal/blob/master/samples/llvm/brainfuck.cr) as `~/1/llvm-example.cr` and ran `env LLVM_CONFIG=/usr/bin/llvm-config-64 crystal ~/1/llvm-example.cr
<FromGitter> ... --verbose`
<FromGitter> <jemc> I get a linker error that looks like this: https://gist.github.com/jemc/12397618da8fd917b8937c9537979b94
<FromGitter> <jemc> summary: ⏎ `undefined reference to 'llvm::User::anchor()'` ⏎ `clang-6.0: error: linker command failed with exit code 1`
<FromGitter> <jemc> is there anything special I need to do to get crystal to link properly to LLVM?
<FromGitter> <jemc> I wonder if it is an issue where the LLVM version I am using in my Crystal program needs to be exactly the same version that was used to compile Crystal itself? That would be a pain, but maybe not surprising?
DTZUZO has quit [Ping timeout: 240 seconds]
korzybski has quit [Quit: korzybski]
<FromGitter> <jemc> Yeah, that seemed to do it. With `crystal --version`, I learned that my `crystal` binary was compiled against `LLVM 4.0.0`. I installed that and switched to `LLVM_CONFIG=/usr/bin/llvm-config-4.0-64`, and no more linker error 🎉
<FromGitter> <Blacksmoke16> nice oen
rohitpaulk has quit [Ping timeout: 240 seconds]
<FromGitter> <jgaskins> Since shard dependencies mostly just pull from GitHub, is there a convention in Crystal for setting a version while the next version is in development so that, for example, version `1.5` isn't potentially every commit between `1.5` and `1.6`?
<FromGitter> <vladfaust> @jgaskins didn't fully understand the question, but usually shards use Semantic Versioning and minor versions only - e.g. `0.1.0`, `0.2.0` - because the language is not 1.0 yet
<FromGitter> <vladfaust> We use patch versions for breaking functionality (i.e. `0.1.0` -> `0.2.0`) and minor versions for bugfixes and new non-breaking functionality (i.e. `0.1.0` -> `0.1.1`)
<FromGitter> <vladfaust> Was confused about naming, looked at https://semver.org/
<FromGitter> <jgaskins> @vladfaust Those numbers were made up to have a reference point. :-)
<FromGitter> <jgaskins> What I mean is, if I set my shard to version `1.5`, and someone installs it as a dependency for their app, then I push a commit, version `1.5` now points to a new version of the code.
<oprypin> jgaskins, it looks at tags in the repo primarily
<FromGitter> <jgaskins> ahhh, cool. I was thinking of using tags, but just wanted to make sure there wasn't already a convention for it.
<FromGitter> <jgaskins> thanks!
<oprypin> it is normal to change this version only on release, then tag it, then leave it alone even if it's not really that version anymore
<FromGitter> <Blacksmoke16> and when making the version be sure to add a `v` before it
<FromGitter> <Blacksmoke16> i.e. `v0.1.0`
<FromGitter> <vladfaust> Hey @RX14, could this be in stdlib? https://carc.in/#/r/5luu
<RX14> probably not
<FromGitter> <vladfaust> Why?
<RX14> whats the usecase
<RX14> why pick the lhs then the values differ for the same key?
<FromGitter> <vladfaust> I'm creating a changeset feature for an ORM: https://carc.in/#/r/5luv
<FromGitter> <vladfaust> I can't know instance vars in macros, that's why
<FromGitter> <vladfaust> Cannot hook `name=`
<FromGitter> <Blacksmoke16> i had an idea for the serializeable stuff, have a `path` annotation property that will go thru the json obj and set that ivar to the value at the end
<FromGitter> <Blacksmoke16> as currently its not simple to do if you dont want to define a bunch of nested objects, and just want 1 value from it
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/5luy
<FromGitter> <Blacksmoke16> is doable now using `key` and `root`, but can't have multiple properties with same key name so wouldnt work for x/y/z
DTZUZO has joined #crystal-lang
Vexatos has quit [Quit: ZNC Quit]
RX14 has quit [Quit: Fuck this shit, I'm out!]
akaiiro has quit [Ping timeout: 252 seconds]
RX14 has joined #crystal-lang
RX14 has quit [Client Quit]
RX14 has joined #crystal-lang
Vexatos has joined #crystal-lang
Vexatos has quit [Quit: ZNC Quit]
RX14 has quit [Quit: Fuck this shit, I'm out!]
RX14 has joined #crystal-lang
Vexatos has joined #crystal-lang
akaiiro has joined #crystal-lang
Vexatos has quit [Quit: ZNC Quit]
RX14 has quit [Quit: Fuck this shit, I'm out!]
RX14 has joined #crystal-lang
Vexatos has joined #crystal-lang