<FromGitter>
<watzon> I have bitcoin wallet generation working, now it's time to add bitcoin derivatives
<FromGitter>
<grkek> It popped up on my news feed, awesome work @watzon props to you
ur5us has quit [Ping timeout: 265 seconds]
_ht has joined #crystal-lang
_whitelogger has joined #crystal-lang
<FromGitter>
<watzon> Thanks :)
_ht has quit [Remote host closed the connection]
_ht has joined #crystal-lang
flaviodesousa has joined #crystal-lang
flaviodesousa has quit [Client Quit]
<FromGitter>
<naqvis> ```code paste, see link``` ⏎ ⏎ doesn't work and returns compilation error `Error: no overload matches 'bar' with type Proc(Bool)`, But if type annotation is removed in `bar`, it works. Why is that? is this a expected behavior? [https://gitter.im/crystal-lang/crystal?at=5ea29e183ea9b172a488376c]
<FromGitter>
<grkek> You need to pass it a (Bool | Int32 | Float64)
<FromGitter>
<naqvis> yeah, isn't that proc returning Bool?
<jhass>
I think crystal currently is not smart about this, it needs to be literally the union
<FromGitter>
<xmonader> but that doesn't seem to be ok when i try WikiServer::docspath = "mypath"
<FromGitter>
<straight-shoota> `docspath` is a local variable, you can't access it from outside the module scope. You need a class variable for this, which can be declared using the `class_property` macro: `class_property docspath = ""`
<FromGitter>
<straight-shoota> This exposes `docspath` and `docspath=` methods on the module. At callsite the syntax is `TfWiki::WikiServer.docspath = "..."`
<FromGitter>
<c2akula> Hey guys, I'm a total beginner to Crystal. I program in C/C++/Go/Matlab mostly. I need help with converting a do..while loop construct in Pascal to an iterator based one in Crystal. I'm working through Goldberg's Genetic Algorithms book to learn the language. On pg.63 fig.3.5, the snippet of Pascal code is as follows: ⏎ ⏎ ```repeat (Find wheel slot) ⏎ j = j+1; ⏎ until (partsum >= rand) or
<FromGitter>
<straight-shoota> sry, `popsize.times` instead of `popsize.each`
<FromGitter>
<straight-shoota> this is assuming j starts at 0
<FromGitter>
<straight-shoota> That's an almost literal transformation. With knowing some more context, you might also be able to use `pop.each` for example
ur5us has quit [Ping timeout: 240 seconds]
zorp has joined #crystal-lang
<FromGitter>
<ImAHopelessDev_gitlab> @xmonader did @straight-shoota help with your issue?
<FromGitter>
<ImAHopelessDev_gitlab> > I'm sure their creator did at least! ⏎ ⏎ ROFL
<FromGitter>
<Zed-Inc> What do you guys use crystal for?
<FromGitter>
<straight-shoota> Somewhere you're calling `TfWiki::WikiServer.send_from_dirsinfo` which tries to call an instance method as a class method
<FromGitter>
<tenebrousedge> that could be a thing too
<FromGitter>
<straight-shoota> It's probably the call in the `get` handler. That code is in class scope
<FromGitter>
<straight-shoota> To fix this you would need to get access to an instance of `WikiServer` inside the get handler
<FromGitter>
<xmonader> so i can't have the routes defined in a class and using data from that class. got it
<FromGitter>
<xmonader> will try to define another module to use and do include module
<FromGitter>
<straight-shoota> Yeah, you should usually define the handlers on top level scope. It doesn't make any difference where that code is literally, but top level makes it easier to understand how it applies
<FromGitter>
<straight-shoota> I'm not sure how including another module could help with that
<FromGitter>
<xmonader> will make it globally for now and see. thank you guys so much it was driving me crazy
<FromGitter>
<straight-shoota> You probably just need to make `s` (your `WikiServer` instance) accessible.
<FromGitter>
<straight-shoota> if it's a local variable in top level scope, it should be as simple as `s.send_from_dirsinfo(env, filename)` in the get handler.
hightower2 has quit [Remote host closed the connection]
<FromGitter>
<straight-shoota> (only works in the same file, though)
<FromGitter>
<straight-shoota> Making it a class variable (like `WikiServer.instance`) would probably be better.
<FromGitter>
<straight-shoota> This is assuming you actually want to share the same instance between handlers, which means it needs to be concurrency safe
<FromGitter>
<xmonader> So my plan was I'd just pass the walker `w` to wikiserver and that w has all the info for the handlers to use
<FromGitter>
<tenebrousedge> okay but `get` isn't an instance method
<FromGitter>
<Blacksmoke16> im not sure how smart it is to use a class var to share state between requests
<FromGitter>
<Blacksmoke16> unless that state is truly global, i.e. can be safely shared
<FromGitter>
<xmonader> i'm not attached to kemal, i can use any other thing that's lightweight enough
<FromGitter>
<Blacksmoke16> well that was a general thought not specific to kemal
<FromGitter>
<grkek> Use Grip
<FromGitter>
<grkek> it JUST WORKS(TM)
<FromGitter>
<c2akula> @straight-shoota thanks for the reply. what kind of context would help? I tried doing something like `pop.each { |ind| partsum += ind.fitness if partsum < rand }, I don't think it's the same logic and the `until` loop.
<FromGitter>
<straight-shoota> @c2akula Like what are the contents of the actual variables. Your logic isn't exactly the same but should have the same result. I'd suggest `break if partsum >= rand` though to stop entirely instead of skipping every iteration from now on.
<FromGitter>
<tenebrousedge> `pop[0...popsize].reduce(0) {|m, e| break if m >= rand; m + e.fitness }`
<FromGitter>
<straight-shoota> @xmonader Your problem is simply that the handler needs to have access to `WikiServer`. It doesn't execute in instance scope.
<FromGitter>
<tenebrousedge> or you could use `take_while`
<FromGitter>
<c2akula> @straight-shoota The Pascal code is returning the index of the item inside `pop` at the time of breaking out of the loop. It's a roulette wheel selection algorithm. The entire code listing is as follows: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ea2e5b42bf9ef12699f98ea]
<FromGitter>
<tenebrousedge> hmm
<FromGitter>
<tenebrousedge> ``pop[0...popsize].each_with_index.reduce(0) {|m, (e, idx)| break idx if m >= rand; m + e.fitness }`
<FromGitter>
<tenebrousedge> might need `each.with_index`
<FromGitter>
<c2akula> @tenebrousedge If I'm understanding correctly, this snippet is iterating over each item in `pop` with its corresponding index, starting out with a memo (partsum) of `0` and returning `idx` from the block when `m>=rand`?
<FromGitter>
<tenebrousedge> yes
<FromGitter>
<straight-shoota> each_with_index + reduce is an option, but I'd probabaly go with this: ⏎ ⏎ ```popsize.times do |j| ⏎ partsum += pop[j].fitness ⏎ break j if partsum >= rand ⏎ end ``` ⏎ ⏎ Seems better readable [https://gitter.im/crystal-lang/crystal?at=5ea2e711afa1f51d4e19a1d7]
<FromGitter>
<tenebrousedge> but is the partsum guaranteed to exceed `rand` ?
<FromGitter>
<c2akula> @tenebrousedge yes not sure about guaranteed, but definitely can
<FromGitter>
<straight-shoota> > but is the partsum guaranteed to exceed `rand` ? ⏎ ⏎ If no, it would just be `|| popsize` because the iterator returns nil.
<FromGitter>
<tenebrousedge> `each` is fine too though
<FromGitter>
<c2akula> @c2akula `sumfitness` is the sum of the fitnesses of all the individuals in `pop`. `rand = random * sumfitness` is essentially just randomly spinning the roulette wheel. Since `partsum` is the sum of the fitness of each individual as well, we're just checking which happens earlier, either we add all the fitnesses, in which case we selected the last individual in `pop`, in the other case, we land on some
<FromGitter>
... individual.
<FromGitter>
<xmonader> @Blacksmoke16 I've some rules to apply on the served file so i need to hook in the serving phase
<FromGitter>
<Blacksmoke16> @xmonader copy the handler and modify it to what you want to do?
<FromGitter>
<Blacksmoke16> that seems like a better approach no?
<FromGitter>
<xmonader> @straight-shoota but i won't be using any of class features and these handlers require broad scope? and if i can just use them with modules variables it'd be okay
<FromGitter>
<straight-shoota> We schould probably make StaticFileHandler modular to make resusing for custom implementations easier
<FromGitter>
<xmonader> @Blacksmoke16 isn't it based on the public/assets dir to use?
<FromGitter>
<tenebrousedge> @c2akula can't you just take a random element from the array then?
<FromGitter>
<Blacksmoke16> @xmonader you can specify the dir it should use
<FromGitter>
<straight-shoota> @xmonader Module variables are class variables. They're called the same and work exactly the same way on any type, whether it's a module, class or struct.
<FromGitter>
<c2akula> @tenebrousedge Would this compile down to something like the following? Seems like it's doing more work due to the `find`? I could be wrong, and with more individuals inside `pop`, the following might be doing more runtime checks. ⏎ ⏎ > each_with_index + reduce is an option, but I'd probabaly go with this: ⏎ > ```cr ⏎ > popsize.times do |j| ... [https://gitter.i
<FromGitter>
<c2akula> @tenebrousedge You can randomly select, but the reason for the roulette wheel selection is to give higher fitness individuals more chances at selection.
<FromGitter>
<c2akula> @c2akula a random selection wouldn't give you that behavior
<FromGitter>
<tenebrousedge> k
<FromGitter>
<straight-shoota> performance wise, both approaches should probably be similar. I'm not sure, it depends on LLVM optimizaions. But it's nothing to worry about really.
<FromGitter>
<xmonader> It seems to work now yaay!
<FromGitter>
<c2akula> @straight-shoota Thanks. C/C++ world can mess with your thinking at times and not thinking in terms of performance can be hard work. :D
<FromGitter>
<c2akula> @c2akula Thanks a lot, will try both the approaches and will get back :)
<FromGitter>
<xmonader> @Blacksmoke16 that's not what i want, what i want whenever u ask for /afilename.md -> i get the unique afilename.md from the the dir i'm serving from after some preprocessing
<FromGitter>
<xmonader> @tenebrousedge @straight-shoota @Blacksmoke16 thank you for all of the help ^_^ i'm sure i'll be back again with more questions
<FromGitter>
<c2akula> @tenebrousedge thanks Kai
<FromGitter>
<tenebrousedge> :plus1:
<FromGitter>
<straight-shoota> @c2akula So what the algorithm does is essentially weigh the random chance of each individual based on its fitness. I suppose there's no trivial O(1) solution for this. But for repeated use, pop would need to be shuffled.
<FromGitter>
<straight-shoota> (For the first use too obviously, but I'm not sure where the data comes from so it could already be in random order)
<FromGitter>
<c2akula> @straight-shoota that's right. "shuffling" happens when `pop` is replaced with a new `pop` from the selected individuals, you generate new ones through the "recombination" and "mutation" operators.
<FromGitter>
<c2akula> @straight-shoota In this case because each individual is essentially a bit-string, they are generated randomly.
Mikaela has joined #crystal-lang
hightower2 has joined #crystal-lang
<disruptek>
decided to use nim for my premiere competitor. thanks for all your help!
<FromGitter>
<j8r> disruptek why not contributing to an existing OSS one?
<FromGitter>
<j8r> kdenlive or openshot
<FromGitter>
<grkek> Guys I think I have the corona virus
<FromGitter>
<grkek> and I might die
<FromGitter>
<grkek> very soon
<FromGitter>
<grkek> R.I.P me, all I wanted was a post apocalyptic earth
<FromGitter>
<xmonader> is FileUtils.cp("srcdir/*", "destdir") valid to copy all files in srcdir? or i should do something like Dir.glob("*/**") ?
<FromGitter>
<tenebrousedge> that looks like it should work
<FromGitter>
<tenebrousedge> do you have `icr` ?
<FromGitter>
<xmonader> what is icr?
<FromGitter>
<j8r> @grkek G.R.I.P? was is a vision? I think yes
<FromGitter>
<tenebrousedge> you can test those sort of questions
<FromGitter>
<tenebrousedge> `icr` is a Crystal REPL, more or less
<FromGitter>
<grkek> @j8r I honestly have a hard time breathing, because my shoulders hurt like a bitch
<FromGitter>
<grkek> I will check my temperature now and will keep you guys updated
<FromGitter>
<xmonader> @tenebrousedge where can i find that? do you mean the online playground?
<FromGitter>
<dweqv> Do we have ruby's `undump`, complementing `String#dump`, somewhere in the stdlib? Or is there another way to read/eval the escaped string back in resulting in the unescaped version?
<oz>
What are the default sinks / levels for the new logger in 0.34? I'm updating an (old) program where I setup a `Log.for` in the shard's module, but it never logs anything. 😕
<FromGitter>
<Blacksmoke16> idt there are any defaults atm
<FromGitter>
<Blacksmoke16> would have to setup the backends and such you want
<oz>
Thankms. It looks like my issue was from the source-thing. The doc is pointing to setup `Log.for "something"` but `setup_with_env` will ignore this source by default (at least in 0.34).
robacarp has joined #crystal-lang
<robacarp>
oz: So, the stdlib Log module is pretty _library_ focused. It allows a bunch of disparate libraries to use a unified logging system, which is then subscribed to, silenced, etc by the final application.
<robacarp>
By default, Log::IOBackend emits to stdout, which is the important (and kind of unexpected to me) part of that line
<FromGitter>
<j8r> Is the name robacarp related to magicarp?
<FromGitter>
<j8r> (to stay on the topic :D )
<oz>
robacarp: indeed. In the end I used `setup_from_env` the update the builder to the log-level I want for the app [depending on some env. vars].
<oz>
s/the update/to update/
<FromGitter>
<straight-shoota> oz, yeah the default in 0.34.0 is to only log top level scope (that is is, not "." in the log source). This will change in 0.35.0 to log all sources by default.
<FromGitter>
<straight-shoota> So that `Log.builder.bind "*", :info, Log::IOBackend.new` won't be necessary in the next release
<oz>
I think it's a more sensible default.
<robacarp>
@j8r I've had people ask me that many times, but I have honestly no idea what a magicarp is ...
<FromGitter>
<j8r> haha
<robacarp>
@straight-shoota, good to know. Log is a nicely done package either way, didn't mean to rag on the design. I appreciate all the design thought that went into it.
_ht has quit [Ping timeout: 240 seconds]
<oz>
Same. In the end, I removed code. So 💯
_ht has joined #crystal-lang
<FromGitter>
<watzon> @straight-shoota that makes me happy. I love the new Log design, but it's not all that intuitive right now.
<FromGitter>
<grkek> So has anyone looked into the `io << a << b << c << d` being slower than `io.print("#{a} #{b} #{c} #{d}")`
<FromGitter>
<grkek> ?
<FromGitter>
<tenebrousedge> uh, that sounds totally normal
<FromGitter>
<tenebrousedge> one method call should be faster than four, all other things being equal
<FromGitter>
<grkek> Isn't interpolation slower?
<FromGitter>
<tenebrousedge> it should be pretty irrelevant at that level but you can use stringbuilder if you really need to
<FromGitter>
<watzon> Interpolation is actually one of the faster String building methods
<FromGitter>
<watzon> Def faster than concatenation
<FromGitter>
<watzon> I didn't know it was faster than IO streaming, but I can see how it would be
<FromGitter>
<tenebrousedge> but at the same time, that should probably not be a limiting factor for your application
<FromGitter>
<watzon> Likely not
<hightower2>
I would use something from LibC.
<hightower2>
(j/k :)
<FromGitter>
<watzon> Lmao
<FromGitter>
<grkek> I would write nand logic just to print faster
ua_ has joined #crystal-lang
ua has quit [Ping timeout: 265 seconds]
<FromGitter>
<straight-shoota> @grkek a series of `<<` needs to allocate a new string for every intermediate step. Interpolation allocates only once in the best case, i.e. when the resulting string length is < 64 bytes.
<FromGitter>
<watzon> Hmm that's interesting. I didn't know about the byte limit. So each 64 byte block allocates a new String?
<hightower2>
grkek maybe you were thinking of a.to_s(io); b.to_s(io); ...
<FromGitter>
<grkek> We really need the tips and tricks for crystal
<FromGitter>
<watzon> I'll start working on some ;) lol
<FromGitter>
<straight-shoota> No, 64 bytes is just the default size of a string builder. If you append more strings, it needs to expand.
<FromGitter>
<watzon> I am working on a pretty big project right now that I'm going to be using Crystal for
<FromGitter>
<straight-shoota> But actually, IIRC there has been some performance improvement, so the interpolation actually sums up the individual string lenght before allocating, so it really just allocates once
<hightower2>
I think it would be great if these "tips" were part of official docs. I think nothing would beat complete docs that threat individual subjects from the basics at the top to pro level at the bottom.
<hightower2>
s/threat/treat/
<FromGitter>
<watzon> That's pretty great. I like when something as convenient as interpolation is actually fast as well.
<FromGitter>
<watzon> `String.build` is still faster than using individual concatenation operations, right? Or is it about the same?
<FromGitter>
<watzon> Np haha. You're right, it's the parentheses.
<FromGitter>
<c2akula> @straight-shoota @tenebrousedge Hey guys, how're you doing? So I went back and implemented both your versions of the `select` procedure along with some benchmarks. Here are the results along with the code. ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ Let me know what you think? I've tested their output and they are identical, indicating to me that they are doing the same thing. Thanks :)
<FromGitter>
<tenebrousedge> semantically, I like using `find` for this
<FromGitter>
<tenebrousedge> but whatever works
sz0 has joined #crystal-lang
sagax has quit [Ping timeout: 240 seconds]
<FromGitter>
<c2akula> @tenebrousedge The following is the `#find` version. ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ Recently I read both the volumes of "Elegant Objects" by Yegor Bugayenko. His suggestion to use a declarative approach to code resonated with me. I believe the `#find` version fit that bill to the T. I can see where you are coming from. [https://gitter.im/crystal-lang/crystal?at=5ea324171eb8bd3978f242d9]
<FromGitter>
<naqvis> i'm experiencing an interesting situation, where line below the one triggering exception is getting executed and run time generated exception is not what code raised, but something like `Unhandled exception: can't execute `baz = Dummy.new(foo)` `foo` has no type (Exception) ⏎ ⏎ pesudo-code like this ⏎ ⏎ ```foo = bar_which_can_raise_exception(params) ⏎ baz = Dummy.new(foo)```
<FromGitter>
<naqvis> question is, why exception is not propagated above?
<FromGitter>
<tenebrousedge> @c2akula interesting results. I'll check out the books
<FromGitter>
<c2akula> @tenebrousedge no worries. thanks btw. laters!
<FromGitter>
<kingsleyh> does anyone know if there is a way to not get all the deps when doing: shards build mything
<FromGitter>
<grkek> why wouldn't you want all the deps?
<FromGitter>
<Blacksmoke16> you mean like non dev deps?
<FromGitter>
<kingsleyh> I'm building my app to check some things - and I don't want to wait for it to fetch an build all the deps each time - as non of the deps change
<FromGitter>
<Blacksmoke16> try with shards master
<FromGitter>
<kingsleyh> like it goes to the internet and fetches all the deps
<FromGitter>
<user45789> indeed, just wanted to share my finding xD
<FromGitter>
<user45789> also i tought it could be cool to include a free crystal youtube video course made by derek banas on the web page https://www.youtube.com/watch?v=DxFP-Wjqtsc
<FromGitter>
<Blacksmoke16> prob not the best idea considering that the video is already 2 years old
<FromGitter>
<Blacksmoke16> helpful? yes, but maintainable? no
<FromGitter>
<Blacksmoke16> i.e. some of the examples probably wouldnt compile anymore
<FromGitter>
<ImAHopelessDev_gitlab> > but whats the goal here? seems kinda silly to use crystal to make static HTML files when you could just create HTML itself ⏎ ⏎ oh boy
<FromGitter>
<watzon> I didn't know Derek did a Crystal video haha
<FromGitter>
<watzon> Personally I like what Paul and Jeremy did with Lucky's HTML DSL, but that's not static content
<FromGitter>
<asterite> about that benchmark before, `each.with_index` is slow because it allocates an iterator, but `each_with_index` is fast. That's probably all the mystery around that benchmark
<yxhuvud>
OTOH, if the difference between them actually matters you are most probably measuring something that doesn't matter.
Dreamer3 has joined #crystal-lang
<oprypin>
Stephie, is it time for event loop work on Windows yet? the prerequisite is there ;)
<Stephie>
uhh
<Stephie>
promise valid for, whenever i have time :/
<Stephie>
i really have uni stuff going on till june
sagax has joined #crystal-lang
<oprypin>
alright, do what you gotta do :>
sagax has quit [Remote host closed the connection]
sagax has joined #crystal-lang
<yxhuvud>
Oh, you are not done with uni yet. Thought you had passed that by now
<FromGitter>
<ImAHopelessDev_gitlab> i just realized how much i like how crystal's docs are structured
<FromGitter>
<sardaukar> why is setting :debug fine, but setting a variable with a value of :debug blow up?
<FromGitter>
<Blacksmoke16> prob related to how autocasting symbols works
<FromGitter>
<sardaukar> this... sucks :D
<FromGitter>
<sardaukar> very non-intuitive
<FromGitter>
<Blacksmoke16> did you checkout that issue?
<FromGitter>
<Blacksmoke16> it helps fix some of thjis
<FromGitter>
<sardaukar> didn't read the whole thing, will do
<FromGitter>
<sardaukar> still feel like not being able to use a var here is pretty weird
<FromGitter>
<sardaukar> it's already weird that I can pass a literal Symbol to an overload that takes `level : Severity`
ur5us has joined #crystal-lang
<FromGitter>
<straight-shoota> @sardaukar The symbol syntax is just a short cut and unfortunately only works when literals are used as method arguments. The full name would be `Log::Severity::Debug`. The compiler can autocast that literal based on the type restriction of the methdo definition. But it's impossible to know when it's assigned to an untyped local variable.
<FromGitter>
<straight-shoota> You can make it work by adding a type restriction to the var: `level : Log::Severity = :debug`
woodruffw has quit [Ping timeout: 256 seconds]
<FromGitter>
<sardaukar> @straight-shoota thanks, that makes sense
<FromGitter>
<sardaukar> but what if I want it to be an assignment? `level : ::Log::Severity = options["--debug"].as(Bool) ? :verbose : :info`
<FromGitter>
<sardaukar> ?
<FromGitter>
<Blacksmoke16> At this point just don't use the symbols