<FromGitter>
<martinium> do you put exception handling in a class or should it be done outside of a class
<FromGitter>
<ezrast> That's a program design question that doesn't have a straightforward answer. It depends on what you want the class to be responsible for.
<FromGitter>
<martinium> I'm basically just experimenting with the language to learn
<FromGitter>
<martinium> I am using an example that gets chuck norris jokes and have made some edits
<FromGitter>
<martinium> the number on id's doesn't match the amount of jokes available
<FromGitter>
<martinium> so basically if my random number generator creates an id that doesn't exist I want it to ignore the exception and to attempt the method again
vikaton has joined #crystal-lang
<FromGitter>
<martinium> I think I got it
<FromGitter>
<ezrast> if you're not using classes already there's no need to bring them into the picture; just wrap your joke-getting code in a loop that retries until a joke is succesfully retrieved, and `rescue` the offending exception.
<FromGitter>
<martinium> yeah I just got it to work
<FromGitter>
<martinium> I ran some tests with a joke id that didn't exist
<FromGitter>
<martinium> without it got the exception
<FromGitter>
<martinium> with this it retries
<FromGitter>
<martinium> :+1:
<FromGitter>
<ezrast> it retries with the same id though?
<FromGitter>
<martinium> nope
<FromGitter>
<martinium> a diff id
<FromGitter>
<martinium> since the number is randomly generated
<FromGitter>
<martinium> each time the command is run
<FromGitter>
<martinium> :)
mgarciaisaia has joined #crystal-lang
<FromGitter>
<martinium> but thanks for pointing me in right direction
<FromGitter>
<martinium> is it possible to run a program compiled with crystal on a server and have it's output display on a webpage generated by crystal?
mgarciaisaia has quit [Ping timeout: 256 seconds]
<FromGitter>
<ezrast> you can search the book I linked earlier and the API docs at https://crystal-lang.org/api/0.20.5/ for "HTTP server" and find some examples. I am not terribly familiar with them myself though.
mgarciaisaia has joined #crystal-lang
<FromGitter>
<martinium> gotcha
mgarciaisaia has quit [Ping timeout: 276 seconds]
soveran has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Changing host]
mgarciaisaia has joined #crystal-lang
soveran has quit [Ping timeout: 255 seconds]
greenbigfrog has quit [Remote host closed the connection]
mgarciaisaia1 has joined #crystal-lang
mgarciaisaia has quit [Ping timeout: 240 seconds]
mgarciaisaia1 has quit [Quit: Leaving.]
vikaton has quit [Quit: Connection closed for inactivity]
jaitaiwan has quit [Ping timeout: 260 seconds]
jaitaiwan has joined #crystal-lang
unshadow has quit [Quit: leaving]
soveran has joined #crystal-lang
soveran has quit [Ping timeout: 255 seconds]
soveran has joined #crystal-lang
soveran has quit [Changing host]
soveran has joined #crystal-lang
bjz has joined #crystal-lang
soveran has quit [Client Quit]
matp has quit [Remote host closed the connection]
matp has joined #crystal-lang
bjz has quit [Ping timeout: 240 seconds]
soveran has joined #crystal-lang
bjz has joined #crystal-lang
greenbigfrog has joined #crystal-lang
akwiatkowski has joined #crystal-lang
soveran has quit [Remote host closed the connection]
matp has quit [Remote host closed the connection]
matp has joined #crystal-lang
Raimondi has quit [Read error: Connection reset by peer]
Raimondi has joined #crystal-lang
soveran has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Changing host]
yopp has quit [Ping timeout: 240 seconds]
soveran has quit [Ping timeout: 240 seconds]
unshadow has joined #crystal-lang
soveran has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Changing host]
soveran has quit [Remote host closed the connection]
soveran has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Changing host]
matp has quit [Remote host closed the connection]
matp has joined #crystal-lang
gloscombe has joined #crystal-lang
splitty_ has quit [Quit: Leaving]
splitty_ has joined #crystal-lang
Dreamer3 has joined #crystal-lang
<FromGitter>
<crisward> Anyone had any luck using oauth2 with google api's?
gloscombe has quit [Quit: leaving]
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<FromGitter>
<TheLonelyGhost> Nothing here. Any idea how to detect if a file contains binary data instead of, say, UTF-8 text?
<FromGitter>
<crisward> I'm guessing you mean apart from file extension?
<FromGitter>
<crisward> @mverzilli Thanks for that, I'll give it a go. Seem to be going around in circles, That should be the logo for oauth.
<FromGitter>
<crisward> @mverzilli how are you setting scope?
<FromGitter>
<TheLonelyGhost> @crisward Thanks. I was trying to build a tool to ignore binary files, but not sure what text encoding the files might be. I suppose I can assume it will be UTF-8 most of the time in this instance, but it leaves the program open for bugs related to this assumption.
<FromGitter>
<crisward> I think I came across a crystal mime-type plugin which detected filetypes, but not base on their file extension. Not sure where though.
<Papierkorb>
Using the `magic` library?
<FromGitter>
<TheLonelyGhost> Only other thing I can think of is to reimplement `file` in crystal
<FromGitter>
<TheLonelyGhost> wait, is there a magic library?
<FromGitter>
<TheLonelyGhost> because that would be perfect
<Papierkorb>
Yes, it's called "magic", and is what `file` uses. But I don't know if there's a shard for it
<FromGitter>
<TheLonelyGhost> Personally, I use gitlab as a primary host. Not sure how many others do too
<Papierkorb>
That looks like a wrapper for imagemagick
<FromGitter>
<TheLonelyGhost> Not much luck on finding an existing shard for `magic` (in the sense I require, at least)
* FromGitter
* TheLonelyGhost nods
michael_campbell has quit [Quit: ZNC 1.6.1 - http://znc.in]
<FromGitter>
<TheLonelyGhost> Taking a look at Crystal-MimeTypes... doesn't look like I can use it in this case. I might be able to extend it with values from `/usr/share/misc/magic.mgc` (which is what `file` uses), but since it's a binary file itself, I'm not yet sure how to do so
<FromGitter>
<TheLonelyGhost> Thanks for the suggestions so far
<Papierkorb>
TheLonelyGhost, you should be able to use libmagic directly
<Papierkorb>
within a `lib`
<FromGitter>
<TheLonelyGhost> true. I might just do that.
<FromGitter>
<TheLonelyGhost> I think I have a workaround for my main use-case, but I'll add that to my to-do list.
gloscombe has joined #crystal-lang
<FromGitter>
<TheLonelyGhost> On an interesting note, `file src/somefile.cr` ends up detecting that it's a Ruby file. Any thoughts on contributing to libmagic to differentiate source files from ruby?
<FromGitter>
<TheLonelyGhost> although, perhaps that would be better suited for post-1.0
<FromGitter>
<TheLonelyGhost> when the API has stabilized more, I suppose
<Papierkorb>
I guess it'll always have difficulties telling them apart
<Papierkorb>
You could use `: Type` as marker, but those are optional
<FromGitter>
<TheLonelyGhost> Can't really blame the tool. Some Crystal is 100% compatible as Ruby too. Not sure how it should handle it in that case.
unshadow has quit [Quit: leaving]
soveran has quit [Remote host closed the connection]
Renich has joined #crystal-lang
soveran has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Changing host]
soveran has quit [Ping timeout: 245 seconds]
soveran has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Changing host]
DeBot has quit [Remote host closed the connection]
DeBot has joined #crystal-lang
<rkeene>
I've decided what to do to bootstrap Crystal -- as someone suggested I'm going to make a bitcode/IR distribution, and pretty that up with a configure script that verifies LLVM compatibility, etc -- it would be great if there were a Crystal-hosted crystal-bootstrap package like this
<rkeene>
Is any given (new) version of Crystal guarenteed to be able to be compiled by itself ?
<BlaXpirit>
rkeene, by itself? yes
<rkeene>
Okay
<FromGitter>
<MaxLap> Compiler-wise, is it expected that a Bool | Nil takes up 16 bytes? I mean, data wise. it's 1.5 bits of data, fitting it in 2 bits would make sense, but i feel that 128 bits is a lot. I'm just wondering if it's a bug or a known issue that hasn't been addressed
Renich has quit [Quit: leaving]
<RX14>
"1.5 bits"
<RX14>
it's a u32+i1
<RX14>
u32 for the type ID, as with any union in crystal
<RX14>
so llvm should align that to 64bit i would think
<RX14>
and yes, it does
<rkeene>
Alright, I've got a basic working crystal-bootstrap and llvm bitcode is stable enough to make this go, but probably still need to make it depend on the exact version of LLVM for Crystal to be happy
<RX14>
yes, the llvm-ir text representation is llvm-version specific
<RX14>
as the text format is only really meant for debuggin
<rkeene>
No, llvm bitcode is stable from X.Y to all X.Z and X+1.0
<rkeene>
(Where Z is X+N and N is a positive integer)
<rkeene>
Well, yes, the text-ir is version specific -- but I never said anything about that
<RX14>
oh nevermind
<RX14>
i thought you meant text ir
<RX14>
i forgot that bitcode exists
<rkeene>
No, bitcode
<rkeene>
But Crystal will probably want to link against the exact same LLVM anyway
<RX14>
well
<RX14>
the llvm-ext.a will be llvm-version specific
<RX14>
but you dont need to store that
<RX14>
oh actually yes
<rkeene>
Is that all ? I'm going to compile that each time
<RX14>
the bitcode will be version specific too
<rkeene>
I'm going to include the source for src/ext and src/llvm
<RX14>
you need the whole source anyway though...
<rkeene>
Not the parts written in Crystal, since those are compiled already -- to LLVM bitcode
<RX14>
no but you need the whole source to build anyway
<rkeene>
To build the bitcode I do, but this project is to create the distribution that you can build without Crystal
<RX14>
since the source is needed to compile anything witht hat compiler
<rkeene>
Oh
<rkeene>
Okay
<RX14>
so why not check it out before
<RX14>
and just ditch the seperation
<rkeene>
Because the idea is to build Crystal without Crystal on a given platform
<RX14>
but you don't need crystal to unpack a tarball do you
<rkeene>
I can create the bitcode on any platform, and then use "llc" to translate it into object code for the current platform
<RX14>
both are required to bootstrap a working crystal install
<RX14>
compiler is essentially useless without a stdlib source checkout
<rkeene>
I'm going to include the crystal source (from a source release, not a checkout)
<RX14>
well it doesn't matter as long as you have it
<RX14>
but i thought you implied that you would only include src/ext and src/llvm
<rkeene>
Until you told me I needed the Crystal source to use it
<rkeene>
Then I said "Oh" "Okay" -- acknowledging that fact
unshadow has joined #crystal-lang
gloscombe has quit [Remote host closed the connection]
marciogm has joined #crystal-lang
marciogm has quit [Ping timeout: 245 seconds]
soveran has quit []
<rkeene>
Is there any way to have Crystal print what LLVM version it's link against ?
<FromGitter>
<drosehn> <dreamer3> (from this morning) - it used to be true that I could use `brew` to install crystal with my homebrew prefix set to `/opt/homebrew`. I've been doing that for months, but my most recent attempt to `brew upgrade crystal` ran into some new problems. That happened last night, and I am still trying to figure those out. The problems I'm seeing could be due to the way I have things setup on my mac.
<FromGitter>
<drosehn> <rkeene> I suspect you'd need to use some operating-system command to do that. `ldd` maybe? (at least on some OS's, although not in macOS).
<FromGitter>
<drosehn> maybe `otool` on some OS's.
<rkeene>
It's alright, I've sorted it out
<rkeene>
I just created a Makefile.local with an "llvm-version" target that when built produces that file containing the version from the Make macro LLVM_CONFIG processed as $(shell $(LLVM_CONFIG) --version)
<FromGitter>
<drosehn> That's probably a much better tactic.
<Papierkorb>
Am a emacs newbie, could someone give me a hint how to install the emacs-crystal-mode? I'm using spacemacs, is there anything special I need to consider?
bjz has joined #crystal-lang
<FromGitter>
<drosehn> <rkeene> -> which OS are you working with? (just curious)
<Yxhuvud>
papierkorb: sadly, the authors don't consider it stable enough to put in a package repo, so you would have to download it, and possibly compile it yourself. Check out the repo, tell your .emacs to load the relevant file in it. (or at least that is how I have solved similar issues in the past before there was package repos)
<Yxhuvud>
I've been too lazy to install it yet, but my patience of running crystal with ruby-mode is running out so I will look at it soonish.
<Papierkorb>
Yxhuvud: Ok, I'll give it a shot when I'm working on a Ruby project tomorrow at work then, Atom should last me until the fork by dotmilk on Github is 'released'
<Papierkorb>
Or even put as "layer" into spacemacs
<FromGitter>
<mjago> @yxhuvud I’ve tried it a couple of times but always end up disabling it - (non-spacemacs). It slows emacs down to a crawl for me.
<Yxhuvud>
mjago: crystal-mode? I don't use spacemacs.
<FromGitter>
<mjago> emacs-crystal-mode yes
<FromGitter>
<mjago> sorry I meant @Papierkorb You can just download it - put it in .emacs.d somewhere and initialise it from init.el etc - preferably compile it
matp has quit [Remote host closed the connection]
matp has joined #crystal-lang
<RX14>
emacs-crystal-mode works for me
<RX14>
not slow
<RX14>
i use spacemacs so I installed the layer
<FromGitter>
<mjago> Maybe I’ll try a different Emacs - 25.1.1 currently. Something doesn’t agree
<Yxhuvud>
Hmm, I actually took the time to download and install it now. no performance issues that I can see. Some silly messages coming on indent though.
<Yxhuvud>
I can see myself adding a tool format menu option. do tool format support working on STDIN/STDOUT or would I have to create a tempfile?
<RX14>
the spacemacs layer has code for that
<RX14>
which you should be able to nick
<RX14>
although it does it on save
<RX14>
so it just uses the file on disk
<Yxhuvud>
ok. perhaps that is good enough. I won't do it tonight though - for some reason I'm very tired :/
<FromGitter>
<mjago> @RX14 thanks for info - it’s already better than what I had (not slow) - I’ll check it out
unshadow has quit [Read error: Connection reset by peer]
unshadow has joined #crystal-lang
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]