ChanServ changed the topic of #crystal-lang to: The Crystal programming language | | Crystal 0.22.0 | Fund Crystal's development: | Paste > 3 lines of text to | GH: | Docs: | API: | Logs:
j has joined #crystal-lang
j is now known as Guest27523
Guest27523 has quit [Client Quit]
zipR4ND has quit [Ping timeout: 260 seconds]
LastWhisper____ has joined #crystal-lang
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 268 seconds]
Raimondii is now known as Raimondi
rohitpaulk has joined #crystal-lang
LastWhisper____ has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
VectorGraphics has quit [Quit: Leaving]
rohitpaulk has quit [Ping timeout: 240 seconds]
<FromGitter> <elorest> I keep seeing class definitions inside of a class definition. What is the point or advantage to this? Are there docs on this anywhere?
<oprypin> elorest, it's just for namespace purposes. you can also make it private to the class iirc
<oprypin> i dont think it's ever explicitly mentioned in the docs
<oprypin> just seems easy to miss for someone who this feels natural to. could be a nice addition to docs
rohitpaulk has joined #crystal-lang
Kug3lis_off is now known as Kug3lis
<FromGitter> <elorest> Cool thanks. Any idea how you would make it private? ⏎
Kug3lis is now known as Kug3lis_off
snsei has joined #crystal-lang
snsei has quit [Ping timeout: 258 seconds]
<FromGitter> <bew> @elorest the Hair class?
mark_66 has joined #crystal-lang
jack_ has joined #crystal-lang
<jack_> hi guys, I have a hash with symbols as keys, how to convert these keys to String? (I am a newbie in Crystal)
<jack_> h = {:a => 1, :b => "2"}
<jack_> my key is just a string "a"
<FromGitter> <bararchy> jack use ` .to_s`
<jack_> do you mean `h.to_s`?
<jack_> what I want is to be able to access h["a"]
<FromGitter> <sdogruyol> why don't `h["a".to_sym] ?
<jack_> ah, my key is in a variable
<jack_> h = {:a => 1, :b => "2"}
<jack_> key = "a"
<jack_> I need h[key]
<jack_> but to_sym does not exist in Crystal
<jack_> also, the docs say"You can't dynamically create symbols"
<FromGitter> <sdogruyol> didn't know that
<FromGitter> <sdogruyol> thanks
<rohitpaulk> If the keys are finite and well known (they should be, else you probably shouldn't be using symbols), you could maintain a separate mapping from string -> symbol
mark_66 has quit [Read error: Connection reset by peer]
mark_66 has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 272 seconds]
<FromGitter> <elorest> @bew yes.
<FromGitter> <crisward> I've complete a few websites now in crystal and the one slight annoyance is having to recompile the code on every template change. Is anyone working on a solution to this? The recompile may only take 10 seconds, but that feels like an eternity when you've only changed something small, eg added a html tag somewhere. Not sure if there are any ways to speed this up, or some kind of run time compilation while in
<FromGitter> ... dev mode?
<FromGitter> <sdogruyol> @crisward definitely need a non-compile template engine
snsei has joined #crystal-lang
<FromGitter> <crisward> @sdogruyol any ideas on how this could be achieved? There are obviously parts of the template which contain crystal code, and others which are just strings (ie html), just not sure how they'd be separated. The other possibility is compiling the templates independently and dynamically linking them to the app, again not sure of the implications of this, how fast it would be etc.
rohitpaulk has joined #crystal-lang
snsei has quit [Ping timeout: 245 seconds]
jack_ has quit [Quit: Page closed]
<FromGitter> <sdogruyol> as of now idk any way to achieve that
<FromGitter> <sdogruyol> but i'd really love to have that too
Kug3lis_off is now known as Kug3lis
<FromGitter> <bew> @crisward the independant templates, with linking is a good idea imo, will be fast! No plugin system like this exists currently but it can be done:)
<FromGitter> <bew> whaat kind of crystal code do you have in your templates?
<RX14> you could extract each bit of crystal code and turn it into a function
<RX14> the problem is that it's hard to do reloads then
<RX14> you reload and the crystal code has changed, now what, you exit?
<RX14> i guess you'd need another tool which kept running the compiler on exit
<RX14> it'd be weird to integrate with source watcher tools
<RX14> but possible i'm sure
<FromGitter> <sdogruyol> i wonder how other compiled languages handle this
<RX14> i'd make it mostly abstract from crystal code however
<RX14> so that the parts that were crystal code were small
<RX14> don't want to recompile every time you change a for loop
<FromGitter> <sdogruyol> yeah
<RX14> and I think other compiled languages just use dynamic templates
<RX14> or a templating language that can be interpreted
<RX14> and has a compiler too
<RX14> which gets you both benefits but not the expressiveness
<RX14> so it'd be like jinja2 and you'd interpret it in dev and compile it in prod
<RX14> but thats just a guess i havent actually done research
jhass has quit [*.net *.split]
fmcevoy has quit [*.net *.split]
badeball has quit [*.net *.split]
cyberarm has quit [*.net *.split]
dom96 has quit [*.net *.split]
lhz has quit [*.net *.split]
foca has quit [*.net *.split]
<RX14> i need to do some benchmarking on crystal-db/crystal-pg I think
<FromGitter> <sdogruyol> why
<RX14> crystal doesn't really score all too well on the DB heavy techempower benchmarks
<FromGitter> <sdogruyol> yeah kinda
<FromGitter> <sdogruyol> are you still keeping the results private?
zipR4ND has joined #crystal-lang
<RX14> well they've been having some problems with the continuous benchmarking
<RX14> that results I showed you was basically how far they got before it broke lol
<RX14> which happened to include crystal because c was high up in the alphabet
<FromGitter> <sdogruyol> lol
<RX14> kemal wasn't on there at all
<FromGitter> <sdogruyol> :D
<FromGitter> <sdogruyol> hope they fix it soon
<RX14> and thats why i didn't want to share it
<RX14> because it wasn't meant to be really seen
<FromGitter> <sdogruyol> how did you see it then :P
<RX14> irc
<FromGitter> <crisward> @bew I make a call to get a list of pages for a menu, this runs a method on my pages class which returns all page titles and paths with the same parent id from a database.
<FromGitter> <crisward> @bew but there can be lots of reasons to what to get dynamic data and place it in a template
badeball has joined #crystal-lang
jhass has joined #crystal-lang
dom96 has joined #crystal-lang
cyberarm has joined #crystal-lang
foca has joined #crystal-lang
lhz has joined #crystal-lang
jamie_ca has quit [Ping timeout: 240 seconds]
jamie_ca has joined #crystal-lang
snsei has joined #crystal-lang
snsei has quit [Ping timeout: 246 seconds]
<FromGitter> <straight-shoota> @crisward I'm working on an implementation of Jinja2 in Crystal: It's a dynamic interpreted template engine, so templates can be changed at runtime without recompilation.
rohitpaulk has quit [Ping timeout: 260 seconds]
<FromGitter> <crisward> @straight-shoota Thanks, will take a look.
Kug3lis is now known as Kug3lis_off
max__ has joined #crystal-lang
max__ is now known as Guest34920
Guest34920 has left #crystal-lang [#crystal-lang]
A124 has joined #crystal-lang
Guest34920 has joined #crystal-lang
Guest34920 has quit [Client Quit]
splitty___ has joined #crystal-lang
yogg-saron has joined #crystal-lang
splitty__ has quit [Ping timeout: 260 seconds]
<crystal-gh> [crystal] MakeNowJust opened pull request #4486: Semantic: disallow to use return/break/next inside ensure (master...fix/crystal/disallow-control-in-ensure)
yogg-saron has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
yogg-saron has joined #crystal-lang
<crystal-gh> [crystal] bcardiff closed pull request #4477: Remove TODO due to 0.22 released (master...fix/enum/rm-todo-self)
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 268 seconds]
Raimondii is now known as Raimondi
<travis-ci> crystal-lang/crystal#a8b9336 (master - Enum: remove TODO due to 0.22 released (#4477)): The build has errored.
<DeBot> (Remove TODO due to 0.22 released)
A124 has quit [Disconnected by services]
A124 has joined #crystal-lang
Kug3lis_off is now known as Kug3lis
Kug3lis is now known as Kug3lis_off
Kug3lis_off is now known as Kug3lis
snsei has joined #crystal-lang
snsei has quit [Ping timeout: 246 seconds]
LastWhisper____ has joined #crystal-lang
yogg-saron has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Aytan72 has joined #crystal-lang
<Aytan72> Howdy
<Aytan72> Any suggestions on debugging Crystal? Other than a bunch of puts statements :)
<FromGitter> <sdogruyol> lldb
<Aytan72> FromGitter: Thanks
<FromGitter> Aytan72, I'm a bot, *bleep, bloop*. I relay messages between here and
crystal-lang407 has joined #crystal-lang
crystal-lang407 is now known as invisiwill
<FromGitter> <AytanLeibowitz> Thanks @sdogruyol
<invisiwill> Hey Aytan
<Aytan72> Hey Will, welcome!
invisiwill has quit [Ping timeout: 260 seconds]
<FromGitter> <invisiwill> Trying to connect to redshift. I'm using the pg shard but that doesn't seem to work. I get a connection refused message - even though the same info connects from the cli. Any ideas?
<FromGitter> <invisiwill> I was thinking of using the c bindings for postgres or maybe the c bindings for odbc which redshift officially supports odbc and jdbc drivers.
<FromGitter> <invisiwill> My first attempt was to rewrite the pg shard to work with redshift but after 3 hours of that last night it seems more ambitious than I had time for giving my limited knowledge of crystal and debugging it properly.
<crystal-gh> [crystal] ysbaddaden pushed 6 new commits to master:
<crystal-gh> crystal/master 0c6135b Julien Portalier: Use arc4random_buf to fill random bytes on OpenBSD
<crystal-gh> crystal/master 0538f66 Julien Portalier: Extract Sys::Random from SecureRandom...
<crystal-gh> crystal/master 704a05b Julien Portalier: Add Random::System...
<FromGitter> <sdogruyol> hmm
<FromGitter> <sdogruyol> does redshift use the standard postgres protocol?
<FromGitter> <invisiwill> Yeah, it seems to. Redshift was forked from PG 8 by amazon. You can use the standard pg cli to connect to it.
<FromGitter> <invisiwill> In Rails there's an AR adapter for Redshift which uses a lot of the same code as the Postgres adapter.
<FromGitter> <sdogruyol> didnt know that
<FromGitter> <fridgerator> since there is a different AR adapter, makes me wonder if there are some differences
<FromGitter> <invisiwill> I was thinking the same thing. But I haven't found the differences yet.
<FromGitter> <fridgerator> are you using a connection string like `postgres://username:password@hostname/database_name` ?
<FromGitter> <invisiwill> I think the adapter was more about the differences in data types but it could have connection differences that I didn't spot.
<FromGitter> <invisiwill> Redshift uses a lot less data types than PG.
<FromGitter> <invisiwill> Yes, am using the connection string properly. PQ::ConnInfo comes back with the proper data to connect.
<FromGitter> <fridgerator> ah ok
<FromGitter> <invisiwill> We are working on building a high speed micro-service in crystal that uses a socket interface to connect with a Rails app so I may end up building a shard for interfacing with Redshift when I get to a deeper understanding of Crystal. Anyways, I'm going to continue digging. If anybody has any ideas ping me. :)
<FromGitter> <invisiwill> Also, I'll contribute by open sourcing the shard if I can get to that point.
<crystal-gh> [crystal] akzhan opened pull request #4487: raise(Exception): Setup callstack on raise only if not already set. (master...setup-callstack-on-raise-only-if-not-already-set)
<Papierkorb> ^ +1
<FromGitter> <sdogruyol> @invisiwill that's great to hear
<RX14> so
<RX14> i managed to link a program on crystal
<RX14> but it doesn't output to stdout like i intended lol
<FromGitter> <bew> what do you mean "link a program to crystal" ?
<RX14> oops
<RX14> i mean windows
<Papierkorb> You have to explicitly enable stdin/out on Windows
<FromGitter> <bew> oh ok
<Papierkorb> Else it's a "windows" program without output, even if ran on CMD
<RX14> Papierkorb, how?
<Papierkorb> it was a linker flag
wontruefree has joined #crystal-lang
<Papierkorb> You want to choose the "console" subsystem
<Papierkorb> What linker do you use?
<Papierkorb> Or are you using mingw as "linker"?
<RX14> no i'm using link.exe
<RX14> clang generates an obj file then i link it using the msvc linker
<Papierkorb> something like that
<RX14> step 1 is generating that obj file on linux using --cross-compile
<RX14> which the compiler currently can't do afaik
<RX14> still no stdout
wontruefree has quit [Ping timeout: 240 seconds]
<RX14> let me paste my code
<RX14> this
<travis-ci> crystal-lang/crystal#eeac6ac (master - Merge pull request #4450 from ysbaddaden/extract-sys-random-namespace): The build was fixed.
<DeBot> (Crystal::System::Random namespace)
<Papierkorb> only ever had to deal with mingw, no idea if it does more set up magic
<Papierkorb> you can also AllocateConsole() i think
<RX14> windows font rendering is horrendous lol
<FromGitter> <invisiwill> In case anyone was curious ... changing the startup_params in src/pq/ seemed to work. Redshift doesn't know what 'application_name' is and doesn't like that utf8 is lowercase. It wants UTF8. The PG shard considers all connection errors to be connection refused. So, just had to add 'e' to that rescue and output the real error.
<RX14> Papierkorb, i linked it with debug and ran it in the VS debugger
<RX14> and it seemed to call all the right things
<FromGitter> <invisiwill> hmmm... might offer up a pr for that error message output fix on pg. that could be helpful for others.
<FromGitter> <fridgerator> @invisiwill :thumbsup:
mojo has joined #crystal-lang
<FromGitter> <invisiwill> I will build a redshift shard in the near future now that I could make the pg one work with redshift the other modifications should be fairly simple.
<FromGitter> <fridgerator> nice
<FromGitter> <invisiwill> Redshift Speed + Crystal Speed = Blazing fast
<FromGitter> <fridgerator> :fire:
<FromGitter> <invisiwill> May also do a benchmark blog post when we get it all working to contribute the info back to the community.
<FromGitter> <fridgerator> that would be awesome
<Kug3lis> Hi, is it possible to compile Crystal to Library?
<RX14> lol Papierkorb
<RX14> i just read my source code again
<RX14> LibWindows.get_std_handle(LibWindows::STD_INPUT_HANDLE)
<RX14> ...
<Papierkorb> lol
<RX14> ok
<RX14> problem solved
<RX14> we can link with msvc only
<RX14> ok the crystal compiler produces correct object files too
<RX14> this is also a good sign
<RX14> so basically all that needs to change is the linking stange
<RX14> then we can compile on windows
<FromGitter> <bew> Kug3lis yes
<FromGitter> <bew> See for an example
<Kug3lis> bew thanks
mark_66 has quit [Remote host closed the connection]
mojo has quit [Quit: leaving]
<FromGitter> <sdogruyol> @RX14 awesome
<FromGitter> <fridgerator> that is awesome
pduncan has quit [Ping timeout: 258 seconds]
<FromGitter> <bararchy> Cool !!!
<FromGitter> <bew> Insane work from from the llvm team, so cool x)
Kug3lis is now known as Kug3lis_off
<FromGitter> <drosehn> indeed, very nice.
Aytan72 has quit []
Kug3lis_off is now known as Kug3lis
rohitpaulk has joined #crystal-lang
<FromGitter> <asterite> Hi! I don't understand... we knew that LLVM produced correct windows executables. The main challenge is implementing the std, the bindings to the Windows API, exception handling, etc. LLVM was never a barrier for Windows support as far as I know
<FromGitter> <asterite> Or am I missing something?
<Papierkorb> you're not
<FromGitter> <bararchy> I think the point was " with no modifications" no ? Because until now, there was changes to the compiler which needed to be made in order to produce windows builds
<FromGitter> <bararchy> right ?
<FromGitter> <asterite> Yes, to generate exception code for windows, for example. But nothing specific to LLVM other than that. At least the only changes in are to the std. For example the context switch in Fiber needs some asm code for each platform
rohitpaulk has quit [Ping timeout: 255 seconds]
rohitpaulk has joined #crystal-lang
<FromGitter> <elorest> Is there a way to do checks inside of an object for what the type is for instance: ⏎ ⏎ ```code paste, see link``` []
<FromGitter> <asterite> T.class.is_a?(Field.class)
<FromGitter> <asterite> though I would never reopen Array
<FromGitter> <asterite> I mean, T.is_a?(Field.class)
<FromGitter> <elorest> I went with `if T.class.to_s == "Field" `
<FromGitter> <elorest> @asterite First off I'm honored to have you answer. Secondly what would you do if you wanted to be able to return only visible objects in an array without having to right the select 20 times.
<FromGitter> <elorest> I tried `class Project::FieldArray < Array` but got an error.
<FromGitter> <mverzilli> Wouldn't this work for you? ⏎ ⏎ ```code paste, see link``` []
rocky has joined #crystal-lang
rohitpaulk has quit [Remote host closed the connection]
<Kug3lis> So begin, rescue does not work with inline blocks?
<Papierkorb> Is that block stored and called later, when that scope there is long gone, or immediately yielded to Kug3lis?
<Kug3lis> its WebsocketHandler so I guess later called
<Papierkorb> then that scope of the rescue is long gone. Works as expected.
<Papierkorb> Put the begin/rescue in the block.
<Kug3lis> yeah, I just wanted to not get much code duplicate :D
<Kug3lis> the idea was to wrap everything with one rescue so if somewhere something fails I will have only single place to send error to client :)
<Papierkorb> the scope inside the on_message is that "somewhere something" as far the client is concerned
<FromGitter> <crisward> ```code paste, see link``` ⏎ ⏎ anyone any idea why this doesn't work...? []
<Papierkorb> echo also prints a trailing new-line
<FromGitter> <crisward> not with lines[0]
<FromGitter> <crisward> just ``[ -f /some/template.slang ] && echo "1" || echo "0"`.lines[0] == "1"` works
<FromGitter> <crisward> it just doesn't work with the if macro
<FromGitter> <crisward> I open for any better way of detecting if a file exists at compile time...
<Papierkorb> in crystal play, or add a `pp`
<Papierkorb> crisward
<FromGitter> <crisward> Thanks, I had the pp inside the if else, which didn't work, but did when I assigned it to a var. Many thanks!
ragmaanir has joined #crystal-lang
ragmaanir has quit [Quit: Leaving]
zipR4ND1 has joined #crystal-lang
zipR4ND has quit [Ping timeout: 240 seconds]
<Kug3lis> Hmm, does anybody image how to get IP address from HTTP::WebSocket server side?
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
<FromGitter> <elorest> @mverzilli Yeah that works thanks.
Yxhuvud has joined #crystal-lang
rocky has quit [Quit: Leaving...]
<Kug3lis> Got it working by modifying original http::server and requestprocesor :(
<FromGitter> <straight-shoota> there is pr for this crystal-lang/crystal#1722