<Disrecollection>
Oh, alright On another note, I just tried to run a really simple thing on the command line and it's giving back this huge error about missing -lxml2 ?
Kug3lis is now known as Kug3lis_off
<FromGitter>
<faultyserver> probably crystagiri depends on a specific version
<FromGitter>
<faultyserver> should be able to just `brew install libxml2` or `sudo apt-get install libxml2`
<Disrecollection>
I'll try that. This error has been driving me insane.
<Disrecollection>
Yeah it appears to be something with Crystagiri, seeing as some other simple scripts are compiling just fine.
<FromGitter>
<faultyserver> I've never been a fan of the *giri family of libraries for exactly that reason
<Disrecollection>
Well darn. This was supposed to be sort of my "getting into crystal" project, and I learned a bit, but I'm not sure where to go from here.
<Disrecollection>
I guess I'm gonna go run through excercism? Apparently it has some code challenges.
<FromGitter>
<faultyserver> projecteuler.net is where I like to go when starting with a new language
<FromGitter>
<faultyserver> it's more logic focused than anything else, so after you've done it once, it's less of "how do I solve this problem" kind of thing, and more of a "how can this language best express the solution"
Disrecollection has quit [Quit: Leaving.]
<FromGitter>
<fridgerator> if anyone is interested, @elorest will be presenting Amber at a ruby meetup, live here in a few minutes: https://www.youtube.com/watch?v=cccojlwyTNQ
Disrecollection has joined #crystal-lang
<FromGitter>
<bigtunacan> @Disrecollection have you looked at meta scraper as an alternative?
<Disrecollection>
Yeah, that could definitly work. I'll note it as a possibility, and once I hit up that project again in a bit we'll see if it goes.
Disrecollection has quit [Quit: Leaving.]
Disrecollection has joined #crystal-lang
<Disrecollection>
I want to compare 2 strings with each other and count the differences. In C, I know how to do it because strings are just an array of characters which I can iterate through as normal. I wonder what the Crystal solution might be. Is there a standard method to convert a string to an array of characters(and one to determine the length of an array?)
<FromGitter>
<johnjansen> you need levenstein i assume
<FromGitter>
<johnjansen> look at the `String` class
<Disrecollection>
Oh yes this looks like it will fit perfectly. Thank you.
<FromGitter>
<johnjansen> no problem … FYI its available in most languages … you can also take a look at https://github.com/johnjansen/text (not for Levenshtein - although its there) but there are other `text` features you might want
<FromGitter>
<johnjansen> like WhiteSimilarity
<Disrecollection>
So I'm looking at the string class, and it says some methods are instance, but it has those as using a # when I thought # was for comments? do I still use those methods by appending . to the end of an obj, or am I confused/missed something?
<FromGitter>
<johnjansen> any of those can be called as `”mystring”.blank?` or `”mystring”.at(1)` etc
<Disrecollection>
Alright. And is 0 not falesy in crystal?
<FromGitter>
<johnjansen> that does a better job of explaining it than i would have ;-)
<Disrecollection>
Thanks again for all the help.
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
livcd has quit [Ping timeout: 245 seconds]
livcd has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
Philpax_ has joined #crystal-lang
<Disrecollection>
Yeah so I got back on the project with metascraper(Ikeep thinking metasploit) and gave it a whirl. Installed the deps, etc. But when I try to run crystal main.cr it still has the "can't find -lxml2" even though that appears to be installed all good.
<Disrecollection>
Running xubuntu 16.04
<Disrecollection>
Uninstalled Crystal w/ autoremove, ran sudo apt-get install libxml2-dev and things seem to be working now.
greengriminal has joined #crystal-lang
rohitpaulk has joined #crystal-lang
greengriminal has quit [Quit: This computer has gone to sleep]
<Disrecollection>
What does it mean when something in Crystal is in ||? |example|
rohitpaulk has quit [Ping timeout: 245 seconds]
rohitpaulk has joined #crystal-lang
yogg-saron has joined #crystal-lang
<Disrecollection>
In a block, at the start, is it some sort of local var or something?
<Disrecollection>
When you use {|example| puts example}?
<Disrecollection>
So it's some form of local variable that gets assigned a value based on the argument from the yield...?
Disrecollection has quit [Quit: Leaving.]
<FromGitter>
<bararchy> local var created in block scope
<FromGitter>
<bararchy> [1,2,3].each do |num| ; puts num; end ⏎ Will produce "1" "2" "3"
<FromGitter>
<overnet> Hi all. What is the regex engine that crystal lang uses? and is possible add to the Crystal the same regex engine as Ruby uses or Golang? As a current crystals regex engine has limitations in the max regex length. Golang and Ruby do not have this limitation and this is one of the reasons that stopped us from using crystal and we had to choose Golang. ⏎ Thanks!
<FromGitter>
<overnet> Is it possible to change this regex engine?
<FromGitter>
<bararchy> Not that I'm aware of, but PCRE is one of the most known engines, if you can find the issue of "limited string" or W\E you're seeing, we can maybe trace that back to a solution :) ⏎ ⏎ Like, if we find that PCRE can have some argument like `limit PCRE::UNLIMITED_STRING` etc ... in the C code
Kug3lis is now known as Kug3lis_off
Kug3lis_off is now known as Kug3lis
<FromGitter>
<overnet> For example in Golang you can easily use regex with 1 00 000 characters long and over, In Crystal regex with even 20 000 characters long fails to work, can you extend this limit please?
Kug3lis is now known as Kug3lis_off
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 268 seconds]
Raimondii is now known as Raimondi
<FromGitter>
<bararchy> When you say "fail" what does it do ?
<FromGitter>
<bararchy> @Val Does it really matters ? as in , if it's in a container , why do we care what OS it is ?
<FromGitter>
<Val> The size matter you know
<FromGitter>
<Val> The freshness too
<FromGitter>
<Val> I don't care about the distrib (Ubuntu/Debian/CentOS/etc.) but a recent one is better for available libraries
rohitpaulk has quit [Ping timeout: 255 seconds]
<FromGitter>
<overnet> @bararchy thank you for the link but is it posible to fix it on the language level as a permanent fix? I did not get what exactly I have to do. Can I open it as a new issue on the crystal github repo, as this work out of the box on Golang?
<FromGitter>
<Val> @bararchy what do you think about a simple upgrade to 16.04, not a distribution change ?
<FromGitter>
<akzhan> What do you think about replacing of PCRE with RE2 engine?
<FromGitter>
<bararchy> @overnet ⏎ ⏎ 1) You can open an issue requesting that Crystal will change it's Regex engine to X , where X should be made in Crystal or use a different C engine in binding. ⏎ 2) You can re-compile libpcre with the flag in the link which will make it work as you want with Crystal. ⏎ ... [https://gitter.im/crystal-lang/crystal?at=59390712cf9c13503c65e11a]
<FromGitter>
<bararchy> @Val I'm not against, was just asking :) ⏎ moving to a new set of libs will make things work better I guess, as long as it's inside a docker it's really not that big of a deal , you can open an issue regarding that
<FromGitter>
<bararchy> @akzhan RE2 is in C++, does that matters binding wise ?
<FromGitter>
<akzhan> @bararchy pcre and re2 api’s very similar, but re2 doesn’t support back references (affair). it’s faster that’s very appropriated for routers for example.
<FromGitter>
<bararchy> I guess adding it as a shard makes sense then
yogg-saron has quit [Read error: Connection reset by peer]
mark_66 has joined #crystal-lang
<FromGitter>
<overnet> @bararchy how can I do this =>"You can re-compile libpcre with the flag in the link which will make it work as you want with Crystal" across multiple servers multiple ENV and OSs? I do not think that this is correct solution, I do not need to do all this with Golang
<FromGitter>
<bararchy> @overnet I linked you above a new Regex engine I found in shards, maybe try it instead ?
<FromGitter>
<akzhan> As I seen crystal-dfa need more development.
rohitpaulk has joined #crystal-lang
<FromGitter>
<akzhan> It supports basics only
<FromGitter>
<bararchy> Maybe it's enoguh for @overnet usecase ? we can only Hope :) ⏎ and strt binding the R2 lib
<FromGitter>
<overnet> @bararchy thank you for the link, does not work for me, it is very limited.
<FromGitter>
<overnet> I need full regex support
<FromGitter>
<bararchy> Then I guess using R2 is the best solution , @akzhan is that something you are doing ? Or just suggested ?
<FromGitter>
<overnet> @bararchy Sorry but I did not get this, how can I use R2 in Crystal ?
<FromGitter>
<overnet> @bararchy Sorry but I did not get this, how can I use R2 in Crystal?
<FromGitter>
<akzhan> just suggested for now. have no time yet.
<FromGitter>
<akzhan> Weekend will commit String.compare, later try to look at RE2. Thanks for the point to crystal-dfa, it’s great point to setup adapter.
<FromGitter>
<akzhan> it allows to use /regexp/ syntax with simple move.
hightower2 has joined #crystal-lang
<hightower2>
Hey folks!
<FromGitter>
<sdogruyol> hey
<FromGitter>
<bararchy> @overnet You can't right now, we need to implament that by Shard or addpter via STD( less likely) , right now it seems @akzhan is interested in adding R2 as a Shard, so ... for now just wait , or create it your self I guess
rohitpaulk has quit [Ping timeout: 240 seconds]
<FromGitter>
<overnet> @bararchy Ok, thank you.
<FromGitter>
<straight-shoota> I don't suppose RE2 would get into stlib. While being faster than PCRE it does not support backreferences, lookahead/-behind and recursion. PCRE is a general purpose engine and RE2 is only suitable for tasks where you don't need these specific features and it would probably only be worth if regular expressions are heavily used.
<FromGitter>
<bew> is it wanted behaviour that a module must be declared before inclusion? I thought it could be defined anywhere: https://carc.in/#/r/25l2
<FromGitter>
<straight-shoota> For production, I would strongly recommend using a higher cost. Cost 6 takes just a few milliseconds on a halfway decent CPU.
greengriminal has quit [Quit: This computer has gone to sleep]
<FromGitter>
<eliasjpr> also consider the cost to be higher if is a public facing vs private, # of users
<FromGitter>
<straight-shoota> Current default is 10 which should be suitable for most cases. Better make it bigger if performance is available. The complexity and time consumption make these hashes secure.
<FromGitter>
<straight-shoota> You just need to calculate it once in a while to login your user.
<FromGitter>
<codenoid> "performance is available" how we know is performance is avaible ?
<FromGitter>
<codenoid> ok, then i need some sleep, thanks ^_^
<sauer2>
Hi, a question regarding nil? : How comes I still sometimes have to cast a Mytype | Nil manually to Mytype, despite checking for myvar.nil? ?
<FromGitter>
<eliasjpr> that means the var can be nil at a give point in time
<FromGitter>
<eliasjpr> if you guarantee the var is never nil then no need to cast
<sauer2>
Well, I guarantee that with unless myvar.nil?, don't I?
<jhass>
myvar is likely a method call, instance variable, class variable or closured variable
<FromGitter>
<bew> you should use `if myvar` instead imo
<sauer2>
why doesn't it work for class variables?
<jhass>
because another thread might change it between your check and next read
<FromGitter>
<eliasjpr> Do you always initialize the class variable?
<sauer2>
yes
Kug3lis_ has quit [Read error: Connection reset by peer]
<FromGitter>
<eliasjpr> you should post an example it will help to understand what you are doing
Kug3lis has joined #crystal-lang
<sauer2>
ok
<sauer2>
module Lox class Environment def initialize(enclosing : Environment | Nil) @enclosing = enclosing @values = {} of String => Type end def initialize() initialize(nil) end def get(name : Token) value = @values.fetch(name.lexeme, nil) unless value.nil? return value end unless @enclosing.nil? return @enclosing.as(Environment).get(name) end raise RuntimeError.new(name, "Undefined vari
<FromGitter>
<luislavena> It was a branch on crystal repo.
<jhass>
riddley: you just create a git repo somewhere, preferably github
<FromGitter>
<luislavena> shards are decentralized, use git (github, gitlab, bitbucket) as distribution mechanism
<riddley>
any idea if that branch will ever see daylight?
<riddley>
thanks very much to that pointer
<FromGitter>
<luislavena> Not sure, but perhaps is worth taking that code, creating a real life shard with it, get more eyes into it and perhaps can be moved into stdlib.
<FromGitter>
<luislavena> I think there is some minor touches to IO in there to make it work, but can't remember the details.
<FromGitter>
<asterite> We can probably merge it. It's missing support for some tar formats (there are *many* formats). We could maybe mark it as "incomplete" or "unstable" until we finish working on it, but at least tars created by crystal will be able to be read by crystal
<FromGitter>
<bew> jhass: indeed, the type in `a : Int32|Nil = 1` is simply ignored
<FromGitter>
<luislavena> @asterite what about making that a separate shard instead? that will allow more free exploration and faster contribution/release cycles
<FromGitter>
<asterite> @luislavena It's probably a good idea. If anyone wants to create a shard from that branch and continue working on it, please go ahead :-). Eventually we can merge that shard into the std if we find it convenient
<FromGitter>
<bew> yes, in fact, everything is working well :D
<FromGitter>
<luislavena> @asterite there was some IO additions in it, let me pull the change, not sure about that.
<FromGitter>
<luislavena> Correct, code within `{{ }}` is evaluated at compile time, if you need to compare versions at runtime, you can use SemanticVersion from the stdlib
greengriminal has quit [Quit: This computer has gone to sleep]
greengriminal has joined #crystal-lang
<crystal-gh>
[crystal] asterite pushed 4 new commits to master: https://git.io/vHXa2
<crystal-gh>
crystal/master faf2a54 Ary Borenszweig: Compiler: error if passing void lib fun call to call, or to assignment. Related to #4414
<crystal-gh>
crystal/master 47a4289 Ary Borenszweig: Fixed #4414: ICE when passing nil through a varargs C call
<crystal-gh>
crystal/master 32d3d8e Ary Borenszweig: Fixed #4353: responds_to? doesn't work for generic type metaclass
greengriminal has quit [Quit: This computer has gone to sleep]
<hightower2>
I see I can't create symbols in runtime. Does this essentially mean that I can't turn strings received via the network to Symbol objects? Or?
greengriminal has joined #crystal-lang
greengriminal has quit [Client Quit]
greengriminal has joined #crystal-lang
pduncan has quit [Ping timeout: 260 seconds]
<FromGitter>
<bew> yes
<crystal-gh>
[crystal] asterite closed pull request #4216: Separation of constructor methods in docs (master...pr-4071) https://git.io/vScRs
greengriminal has quit [Quit: This computer has gone to sleep]
vikaton has joined #crystal-lang
<FromGitter>
<danielwestendorf> Is there a HTTP recording/replaying shard for Crystal? Similar to https://github.com/vcr/vcr? If not, what are people using to stub out HTTP requests?
<hightower2>
What's the recommended way to slurp a file? E.g. if I want to pass file contents to INI.parse()?
<FromGitter>
<bew> I think it's `content = File.read("some/path")`
<hightower2>
Oh, missed it in the API listing, thanks
<Disrecollection>
I'm trying to create a file and then write either text or a jpg to it, File.write takes a slice, which is of type Bytes? Which is an alias for something? How do I convert .jpg and strings to Bytes?
<Disrecollection>
Slice is some form of safe pointer..?
<FromGitter>
<bew> yes, it's a pointer with a size
<Disrecollection>
Okay, so I need to go read up on how Crystal handles pointers. i feel like there is a better way to create and write to files...
greengriminal has joined #crystal-lang
<FromGitter>
<bew> to get a `Bytes` from a string, there is `String#to_slice`
greengriminal has quit [Remote host closed the connection]
<FromGitter>
<bew> and yes, `Bytes` is an alias to `Slice(UInt8)`
<Disrecollection>
I totally missed the String method. Thanks! But I'm probably going to have to implement my own method for the .jpg images anyway.
<hightower2>
Indeed, thanks. I used ret= {} of Symbol=> Bool | Int64 | String
<hightower2>
My next problem is that I want to provide a basic, interactive REPL as part of my app. (Like, the app runs, and opens an interactive shell which is aware of the modules/classes/etc in the current process)
<hightower2>
I tried installing Icr and calling Icr::Console.new.start
<hightower2>
This gives me the REPL, but it is unaware of the program's state - I don't see modules/classes in it which do exist in the process
<hightower2>
Any hints about that? (I'm not using Icr for any particular reason - just thought it'd work, which may not be true)
<FromGitter>
<bew> the running process is compiled, you have no access to crystal's modules/classes/etc..
<FromGitter>
<bew> tl;dr you can't do what you want here
<FromGitter>
<bew> why do you want/need this?
<hightower2>
I do this often in Ruby - instead of putting the main thread to sleep, I run interactive IRB session in it, and the user can use it to access the live, running process' state
<hightower2>
for whatever - introspection, stats, changing the values etc.
<Papierkorb>
Not possible in Crystal in the same sense as Ruby allows to
<FromGitter>
<bew> yeah, but ruby is interpreted, crystal is compiled, this is not the same flexibility at run time (and crystal waaay much faster than ruby because of that)
<hightower2>
Right, sure
<hightower2>
Ok, thanks
<Disrecollection>
Is there a quick way to join multiple strings together?
<FromGitter>
<bew> there is `{"a", "b", "c"}.join`
<hightower2>
Disrecollection, in addition to "a" + "b" ?
LastWhisper____ has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<Disrecollection>
So I'm writing text to files pretty perfectly now, but I'm unsure how to write .jpg to files. I'm able to grab the Bytes, and place them in a new file, but it's not encoded correctly. I notice there is an encoding parameter for File.write, and I'm wondering if that's the key.
<Disrecollection>
I tried taking a look at Encoding in the API, but it didn't seem helpful
<Papierkorb>
Disrecollection: How are you writing the Bytes?
<Disrecollection>
.to_slice ?
<Papierkorb>
...?
<Disrecollection>
One sec.
<Disrecollection>
I open an instance of the File class with .open("name","w") then I use the .write method(thinkIwant.to_slice)
<Papierkorb>
That's correct. The #to_slice call is a noop though.
<FromGitter>
<bew> what is the type of `thingIwant` ?
<Disrecollection>
noop?
<Papierkorb>
no-op
<Disrecollection>
?
<Papierkorb>
no-operation. Doesn't do anything.
<Papierkorb>
(in this case)
<Disrecollection>
Think I found an error. I believe I'm writing the URL loc of the image instead of the image itself. Duh. I'm gonna go fix that, see if it was the problem.
<FromGitter>
<bew> how do you get the jpg content to write?
<Disrecollection>
It uh, seem I don't know. I can access an XML node which is just the <img src = "url"></> but I don't know how to access that url or get the bytes of the .jpg to copy over via File.write.
<crystal-gh>
[crystal] asterite pushed 1 new commit to master: https://git.io/vHXFZ
<crystal-gh>
crystal/master 54415ff Ary Borenszweig: Fixed codegen for x86