<FromGitter>
<Blacksmoke16> this is what `forall` is for
<FromGitter>
<Blacksmoke16> 👍 nvm
<FromGitter>
<mistergibson> I'd like to develop with crystal on the ppc (PowerPC) 64bit platform. Where do I check up, from time to time, on the multi-arch porting efforts?
<FromGitter>
<mistergibson> Essentially, I'd like to run crystal programs anywhere I can run Ruby apps.
<FromGitter>
<Blacksmoke16> prob easier said than done ha
<FromGitter>
<rurounijones_gitlab> Say I have a hash where the values are `String | BigDecimal | Float64` then I do some fiddling and the values are now only `String | Float64`. Is there a way to have the Hash's types recalculated to reflect the updated values? I am assuming I could create a new hash and copy the values across but I was wondering if there way another way
<FromGitter>
<Blacksmoke16> naw, would have to make a new hash
<FromGitter>
<Blacksmoke16> as the types are tied to the instance of `Hash`
<FromGitter>
<Blacksmoke16> or might be better to use structs, depending on what you're doing
<FromGitter>
<rurounijones_gitlab> Bleh, didn't think so, was hoping. Ach well off to create more hashes
<FromGitter>
<Blacksmoke16> 😬
<FromGitter>
<Blacksmoke16> what are you trying to do?
<FromGitter>
<rurounijones_gitlab> Data source is format A - Target requires format B - Munging data from one to the other
<FromGitter>
<rurounijones_gitlab> which requires fiddling with A then merging A with another copy of A that is updated compared to the original
<FromGitter>
<Blacksmoke16> i see
<FromGitter>
<Blacksmoke16> is a hash the best structure to use?
<FromGitter>
<rurounijones_gitlab> Structs don't have .each
<FromGitter>
<rurounijones_gitlab> And need mutable so NamedTuples and Tuples are out
<FromGitter>
<Blacksmoke16> you can define it yourself and include `Enumerable`
<FromGitter>
<Blacksmoke16> got a simple playground example?
<FromGitter>
<rurounijones_gitlab> No, nothing playground'ish. I also need the ability to reference things using a[key] and since Crystal doesn't have #send
<FromGitter>
<Blacksmoke16> possible a diff approach that doesn't require that would be better?
<FromGitter>
<Blacksmoke16> even using a struct that would result in a union of all types
<FromGitter>
<rurounijones_gitlab> I could possible use structs everywhere and then explicitly reference every attribute that needs updating instead of using `.each` to iterate but since "redefine the hash" is hopefully the last blocker to getting this working I am goign to do that then think about alternatives
<FromGitter>
<Blacksmoke16> okey dokey
<FromGitter>
<Blacksmoke16> id have to see an example to have anymore ideas
<FromGitter>
<rurounijones_gitlab> Can anyone sanity check this. AFAIK this should work looking at docs and examples. The fact that the prepared statement in the error message is "" is suspicious ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ `Unhandled exception in spawn: bind message supplies 1 parameters, but prepared statement "" requires 0 (PQ::PQError)` [https://gitter.im/crystal-lang/crystal?at=5e36487ad9895b17c3c74236]
Dreamer3 has quit [Ping timeout: 268 seconds]
Dreamer3 has joined #crystal-lang
Dreamer3 has quit [Ping timeout: 268 seconds]
nonuse has joined #crystal-lang
Dreamer3 has joined #crystal-lang
Dreamer3 has quit [Ping timeout: 265 seconds]
Dreamer3 has joined #crystal-lang
nonuse has left #crystal-lang ["WeeChat 1.6"]
<FromGitter>
<grkek> @confact Damn nice star from me
<FromGitter>
<grkek> quick note the http.cr file is out of the src folder which is not recommended at all you can do it but your source code should be in the src folder always.
FromGitter has quit [Remote host closed the connection]
FromGitter has joined #crystal-lang
alex`` has joined #crystal-lang
alexherbo2 has joined #crystal-lang
fifr has quit [Ping timeout: 260 seconds]
fifr has joined #crystal-lang
<alex``>
how to convert a time range to an array of time with a given interval?
<alex``>
today -> next month, with interval '2 days' being a list of every 2 days to the next month
_whitelogger has joined #crystal-lang
<FromGitter>
<ImAHopelessDev_gitlab> UNLEASH the Enums!
<FromGitter>
<ImAHopelessDev_gitlab> @rurounijones_gitlab try `where id = ?`? not sure
<FromGitter>
<ImAHopelessDev_gitlab> mysql does the escaping internally with prepared
lvmbdv has quit [Quit: HE COMES]
lvmbdv has joined #crystal-lang
<alex``>
@ImAHopelessDev do you have an example?
Dreamer3 has quit [Ping timeout: 265 seconds]
Dreamer3 has joined #crystal-lang
ur5us has joined #crystal-lang
ur5us has quit [Ping timeout: 260 seconds]
<alex``>
is there a shortcut to `list.map { |item| something(item) }`
<alex``>
found `&->something(String)`
<alex``>
I figured out myself but I can't find the doc for it
<FromGitter>
<636f7374> After running the program for a while, it will have this crash.
<FromGitter>
<636f7374> After I added same_thread, the problem of `pointer being freed was not allocated` disappeared, but the problem of` Duplicate large block deallocation` appeared.
<FromGitter>
<636f7374> OKay, I found it, the problem is caused by different threads inserting data.
<FromGitter>
<tenebrousedge> the TimeRange looks fine. You might consider whether Iterable would be better than Enumerable; I don't know that it would make much difference.
<alex``>
tenebrousedge I have the following error now
<alex``>
this 'initialize' doesn't explicitly initialize instance variable '@begin' of TimeRange, rendering it nilable
<FromGitter>
<Blacksmoke16> try making the first one `def self.new` instead
FromGitter has quit [Remote host closed the connection]
FromGitter has joined #crystal-lang
<alex``>
hm
<alex``>
it works.. but I don't know why
<FromGitter>
<tenebrousedge> initialize is special
<alex``>
there is something that bug me, is step = 1.second
<alex``>
default value in both
<alex``>
I want just to forward
<alex``>
removing default value in self.new works now
<alex``>
black magic
<alex``>
step in the initializer is out of the scope to you?
<alex``>
or it is fine to include it when creating the object
<alex``>
it looks a bit more natural to me to define it not in the object creation
return0e has quit [Remote host closed the connection]
<FromGitter>
<Blacksmoke16> wouldnt you need to define it in both so no matter what overload is used it works correctly
<FromGitter>
<Blacksmoke16> otherwise i guess you could make it nilable, and within the actual initializer check if nil, if so use 1.second otherwise use the given value
<FromGitter>
<636f7374> @grkek I may want to open an issue asking about the problem of hash in the thread.
<FromGitter>
<tenebrousedge> is there some reason to expect Hash to be thread-safe?
<alex``>
I face another problem :(, I have now my `Chronic::Range(range)` and `step`, it works great to set `step` to `1.day`, etc. but my end usage would be for the command-line, how can I specify (shell) `chronic-period <format> <begin> <end> <step>` to `chronic-period '%F' '7 days ago' 'tommorow' '1.days'`
<FromGitter>
<grkek> It is mutable
<FromGitter>
<grkek> so it should not be safe right ?
<FromGitter>
<grkek> I am not quite sure
<FromGitter>
<636f7374> @grkek Ok my mistake, i should use linked list (LRU)
<alex``>
I want `1.day` from the command-line (string) be callable as `1.day` (time span)
<FromGitter>
<636f7374> @grkek thank you for your help. :)
<FromGitter>
<grkek> oh no problem :D
<alex``>
I want to avoid something too verbose like calling `Time.span.new(days: options.days.to_i, hours: options.hours.to_i, etc.)`
<FromGitter>
<tenebrousedge> your options are going to generally be kinda verbose
<alex``>
I found my command-line chronic-period has too many ordered arguments
<FromGitter>
<grkek> well then mr alex mess it up B-)
Dreamer3 has quit [Ping timeout: 268 seconds]
Dreamer3 has joined #crystal-lang
Dreamer3 has quit [Ping timeout: 265 seconds]
JuanMiguel has joined #crystal-lang
JuanMiguel has quit [Remote host closed the connection]
<FromGitter>
<tenebrousedge> I think it uses `is_a?` under the hood, so you can use the class rather than the type
_ht has joined #crystal-lang
<FromGitter>
<Blacksmoke16> why not just overload `handle`
<FromGitter>
<Blacksmoke16> `handle result`
_ht has quit [Quit: _ht]
_ht has joined #crystal-lang
* FromGitter
* tenebrousedge shrugs
JuanMiguel has joined #crystal-lang
JuanMiguel has quit [Read error: Connection reset by peer]
_ht has quit [Quit: _ht]
_ht has joined #crystal-lang
<FromGitter>
<andrewc910> Hey everyone, I am finishing up my docs this week for a initial release of my authentication shard. Let me know what you think! https://github.com/andrewc910/contrive
<FromGitter>
<andrewc910> Any suggestions are appreciated! This week i am focusing on guides & crystal documentation but will get back to actual development after.
<alex``>
what is the best between string.strip.split(/\s*\.\.\s*/).map { |x| x.split(/\s*\+\s*/) }
<alex``>
and doing split("..") / split('+') and call strip on each element
<FromGitter>
<oren> i want to write a static site generator in crystal. i mainly need to figure out how to convert md to html and also inject a few links and maybe css into the generated html. any pointers?
<FromGitter>
<tenebrousedge> do `split('+').map(&.split("..")`
<alex``>
on each element I can call the parser to return a time, but I still have one logic with my output, is "does my return data has more than a single value, if yes, timerange, else time"
<FromGitter>
<Blacksmoke16> is one you want to use
<alex``>
tenebrousedge I fail to see the gain of `string.scan(/([\d-]+)[\s+]+(([\w\s]+) \.\. ([\w\s]+))/)` vs `split("..").map(&.split("+")`
<FromGitter>
<tenebrousedge> `scan` could be used if your inputs were saner
<alex``>
:(
<FromGitter>
<tenebrousedge> it allows you to capture specific elements without needing `strip`
<alex``>
I actually used '+' and '..' as separator because I thought it was the simpler x(
<alex``>
btw &. chaining with argument is net
<FromGitter>
<tenebrousedge> it just means you have to do negative matching (exclusion) rather than positive matching
<FromGitter>
<tenebrousedge> and yes, Crystal > Ruby in some respects
<alex``>
I'm amazed how crystal tackled ruby quirks in the little details
<alex``>
how to handle named arguments, block &->receiver.meth(type), etc.
<FromGitter>
<tenebrousedge> named arguments in Ruby are becoming more like Crystal
<alex``>
named arguments look like a plug
<alex``>
in ruby
<FromGitter>
<tenebrousedge> Ruby's equivalent to `&->` has some advantages over Crystal
<alex``>
what is ruby requivalent to &-> ?
<FromGitter>
<tenebrousedge> you can do `some_arr.map(&an_object.transformation.another.method(:my_method))`
<alex``>
it could be nice to have a document Difference with Ruby, how Crystal approched the features when choosing to do differently
<FromGitter>
<tenebrousedge> :/
<FromGitter>
<tenebrousedge> it would be a small book
<alex``>
like class Foo::Bar is possible in Crystal, while in Ruby the module has to be declared first
<alex``>
in ruby to not have 2 indent level I have done
<alex``>
module Foo; end
<alex``>
class Foo::Bar ..
<alex``>
hm
<alex``>
my result of tokenize(text) is an array(array(string)), the array can have 1 (for time) or 2 values (for time range). given this output, I thought I can define 2 `handle` functions using overloading, with tuple of 1 element, and tuple of 2 elements
<alex``>
how can I do that?
<alex``>
since I have an array, I guess if I pass `handle(tokens)` it will not work
<alex``>
or maybe `handle(...token)` (not sure if `...` work with array
<alex``>
it looks cleaner than doing case/when
ur5us has joined #crystal-lang
<FromGitter>
<tenebrousedge> a tuple is probably not going to work there, but you can do `handle(tokens)` or `handle(tokens[0], tokens[1])`
<FromGitter>
<dscottboggs_gitlab> that's exactly right
<alex``>
I don't feel satisfied when doing that xd
sagax has joined #crystal-lang
<FromGitter>
<dscottboggs_gitlab> I always debate whether abstractions over those sorts of things are a bad idea to create, because they would have to be implemented in such a inefficient manner that it creates opportunities to use them without understanding how inefficient it might be to use them.
<FromGitter>
<dscottboggs_gitlab> like I could make a macro that you could install as a shard and just do ⏎ ⏎ ```require "array_to_tuple" ⏎ some_array.to_tuple # => tuple of values``` ⏎ ⏎ But is that *the right* abstraction? C++ is full of abstractions, and look where that got it [https://gitter.im/crystal-lang/crystal?at=5e3732933aca1e4c5f5d75ae]
<alex``>
that is fair
<alex``>
when having an argument named `def handle(time)` `def handle(begin, end)`, do you thing it's better to just `time`, `time : String`, or name the variable differently time_str or something?
<FromGitter>
<dscottboggs_gitlab> TBH it's down to personal preference. Crystal type restrictions are a restriction that applies at compile time and doesn't reflect an optimization in the resulting code. So if you want more safety, go for more restrictions. If a method is generic and you think you may send various types to it later, save yourself some debugging time and leave it off
<FromGitter>
<Blacksmoke16> could also type restrict an argument to `_`
<FromGitter>
<Blacksmoke16> so its clear to other readers that it should accept any types
<FromGitter>
<dscottboggs_gitlab> you can write crystal like it's a shell script, and I sometimes do, but if I were creating a huge production app in Crystal I'd insist on every type being annotated as much as possible. It communicates intent which is important for collaboration, but less so for a sub-500 line script that only you're going to use 😂
<FromGitter>
<dscottboggs_gitlab> hey there @Blacksmoke16 how's things?
<FromGitter>
<Blacksmoke16> at least until you can use `Enum` in a generic
<FromGitter>
<tenebrousedge> so it works unless the type is `Nil`?
<FromGitter>
<tenebrousedge> no, it just splodes
<FromGitter>
<Blacksmoke16> prob since `type` in this context is `Enum`
<FromGitter>
<Blacksmoke16> `self?` in that context is `Enum?`
<FromGitter>
<tenebrousedge> I suspect you can't get there from here
<FromGitter>
<Blacksmoke16> hmm
<FromGitter>
<Blacksmoke16> ogh
<FromGitter>
<tenebrousedge> maybe in a macro?
<FromGitter>
<Blacksmoke16> `Unhandled exception: Unknown enum Enum value: 0 (Exception)` is what im getting now when i removed those type restrictions
<FromGitter>
<Blacksmoke16> Might have to rethink my approach
<FromGitter>
<Blacksmoke16> Wanted to avoid reopening the types themselves, but that seems like the best approach
<FromGitter>
<Blacksmoke16> Option*
<FromGitter>
<dscottboggs_gitlab> 👍
<FromGitter>
<dscottboggs_gitlab> monkey-patch it all day
<FromGitter>
<Blacksmoke16> If just for deseralization I'd be ok with it I guess
alexherbo24 has joined #crystal-lang
<FromGitter>
<dscottboggs_gitlab> sometimes there's just no other way to do it
alex`` has quit [Ping timeout: 240 seconds]
<FromGitter>
<Blacksmoke16> Always wondered if it's considered a feature or a smell
<FromGitter>
<Blacksmoke16> Depends on the context I guess
alexherbo2 has quit [Ping timeout: 260 seconds]
alexherbo24 is now known as alexherbo2
<FromGitter>
<dscottboggs_gitlab> both? haha ⏎ ⏎ Like, probably shouldn't do it, but sometimes it's really helpful. Idk I'm definitely more quick to reach for that kinda stuff than most people.
<FromGitter>
<dscottboggs_gitlab> idk it depends on your priorities maybe.
<FromGitter>
<dscottboggs_gitlab> there are extremes you can take on both the maintainability and the performance-at-all-costs side
alex`` has joined #crystal-lang
<FromGitter>
<Blacksmoke16> Very true
<FromGitter>
<oren> so i can use 'marked' to generate html from a markdown file. now the question is what's the best way to inject some html to the generated dom (i want to have a custom HTML header for each index.html page.
<FromGitter>
<Blacksmoke16> Another md file?
<FromGitter>
<tenebrousedge> a layout file
<FromGitter>
<tenebrousedge> for sure
<FromGitter>
<tenebrousedge> but I'm not sure what the point of yet another static site generator is
<FromGitter>
<oren> @Blacksmoke16 how do i inject one md into another?
<FromGitter>
<oren> @tenebrousedge can you elaborate on 'a layout file'? also, i can't find a static site generator that allow me to customize the links expect for Docsify but there is a bug with the nav bar (https://github.com/docsifyjs/docsify/issues/876#issuecomment-557937055)
<FromGitter>
<straight-shoota> But `Number#humanize` won't work for formatting time spans
<FromGitter>
<oren> i have the content of html file in a variable. i want to create a new file. I don't see it in the docs for the File object - https://crystal-lang.org/api/0.32.1/File.html