ua has quit [Read error: Connection reset by peer]
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 240 seconds]
Raimondii is now known as Raimondi
ua has joined #crystal-lang
flaviodesousa has joined #crystal-lang
alex`` has joined #crystal-lang
ashirase has quit [Ping timeout: 252 seconds]
ashirase has joined #crystal-lang
_whitelogger has joined #crystal-lang
emilsp has joined #crystal-lang
<FromGitter>
<Qwerp-Derp> Why don't we have a `delegate` keyword instead of keeping everything into a module that makes all the methods in that delegate abstract by default? IMO modules and delegates are two different things covered under the same umbrella keyword, modules provide functionality out of the box while delegates make it so that a class must conform in a way
<Groogy>
that's not what the word delegate means though? are you talking about mixins?
<FromGitter>
<Qwerp-Derp> isn't `delegate` the same thing as `interface`? that's what it is in swift (`TableViewControllerDelegate` etc.)
<FromGitter>
<vladfaust> Trying to extend with `===`, getting interesting results: https://carc.in/#/r/4sze. Bug or what?
<FromGitter>
<girng> crystal is awesome!!!
<hightower2>
girng you bet :)
<Groogy>
how do you tell a kemal application to shutdown?
<FromGitter>
<girng> i just made a dos deflate scrip that reads nginx's error.log and bans the ip with iptables for xxxx amount of time. it's in a loop do 3 second interval and cpu usage is 0.0% goes to 1.2-5.0% if the log file is 100k, reads the log file, puts the ips in a hash increments their `errors` property, if the errors property is greater than XXXX ban them. ⏎ ⏎ you have to set it up correctly with nginx's rate limiting
<FromGitter>
... though. i use like `limit_req_zone $binary_remote_addr zone=mylimit:10m rate=15r/s;` and then `limit_req zone=mylimit burst=10 nodelay;` so you don't accidentally block legit users. i've been testing it and it works great. ⏎ ⏎ my cpu usage on my vps doesn't go to 60% when i dos it now ;) it goes to 5% usage, then the ip g ... [https://gitter.im/crystal-lang/crystal?at=5b7ea13c4be56c591884b6db]
<FromGitter>
<yxhuvud> groogy: have you tried Cntrl-C ?
<FromGitter>
<girng> this is epic because when i compile with --static, i can just drag my file in vps and chmod it and it's READY to go! love the --static feature so freaking epic and is working great for my project!
<Groogy>
Yeah just worried if that keeps it in the background? Since it says "Kemal is going to take a rest!"
zorp has joined #crystal-lang
<FromGitter>
<bararchy> hi Groogy :)
<FromGitter>
<bararchy> long time since i saw you here
<Groogy>
Eh I peak in from time to time
<FromGitter>
<rishavs> I am still struggling a lot with ECR. Specially around the data passing area. does anyone have any crystal app that I can grokk and which uses pure unadulterated ECRs and doesn't uses any view framework (like Kemal which has its own spin on ECR rendering)
<oprypin>
rishavs, there isnt anything complicated. imagine that it's just a macro that gets copypasted into your code
<oprypin>
if you write `a = 5; invoke_ecr_template` then a will be available to ecr
justinmcp has joined #crystal-lang
<FromGitter>
<rishavs> that isn't happening consistently for me :(
<FromGitter>
<rishavs> I will ask the specific questions later today when I get home from work, maybe I am making some very obvious mistakes
<FromGitter>
<rishavs> I only get the time to code on my pet projects rather late at night, so end up making weird errors -__-
<FromGitter>
<rishavs> Can you clear up something in layman's terms? When should I use ECR. embed vs ECR.render vs ECR.def_to_s?
<FromGitter>
<rishavs> From what I understand, I can just use render and it should suffice for all uses cases. embed is same as render but allows me to define dynamic file paths to the ecrs.
<FromGitter>
<DanielSokil> Hello, I have a question regarding Ecr.
<oprypin>
didnt know about the other approach because i havent used ECR in years
<FromGitter>
<rishavs> Since I really don't have the experience to build upon, I am just not clear when to use embed and when to use render
<FromGitter>
<rishavs> ie. If both ⏎ ⏎ ```io = IO::Memory.new ⏎ ECR.embed "greeting.ecr", io ⏎ io.to_s # => "Hello World!"``` ⏎ ⏎ when should I use one over the other? or can I just use render and forget the other methods exist ? [https://gitter.im/crystal-lang/crystal?at=5b7eb43594f8164c178ba594]
<FromGitter>
<asterite> `render` returns the rendered string. `embed` appends the rendered template to an IO
<FromGitter>
<asterite> So if you are implementing a web view, you can: 1. use `render`, and do `context.response.print(rendered_value)` or 2. use `embed`, and do `ECR.embed "template.ecr", context.response`. That is, pass `context.response` to `embed`, because the response is an IO. I don't know which one is more efficient, though
<FromGitter>
<rishavs> thanks
<Groogy>
what DB shard is recommended?
DTZUZO has quit [Read error: Connection reset by peer]
<FromGitter>
<rishavs> You can use the base db driver which is pretty feature complete IMO. or you can use ORMs like Granite (amber), Crecto, LuckyRecords etc. all of which are in active development and pretty nifty.
<FromGitter>
<straight-shoota> @asterite `embed` should be more efficient. Even ignoring the used memory size (`render` needs to put the entire string in memory, `embed` writes directly to the socket but with a buffer), the first byte is sent much faster, because it doesn't need to wait for the entire template to render.
<hightower2>
also see 'core' and jennifer.cr (although for jennifer the instructions are I would say very incomplete, and I had a terrible time trying to get it to work. Once I did though, it worked)
<Groogy>
trying tohow do I provide the password when opening the connection though?
<FromGitter>
<straight-shoota> This is better because the content at the begining can already be transmitted over the network while the rest is still being rendered. And the client can already start parsing it.
<hightower2>
Groogy, you generally provide a database DSN which contains user, pw, host and port. such as "postgres://USER:PASS@HOST:PORT/DBNAME"
<hightower2>
(also contains driver name and db name, as the example shows)
<Groogy>
hmmm still denied access
<Groogy>
weird
<hightower2>
Groogy, everything must be correct to work. Try doing this connection manually using the exact same params (host, port, user, pass, and database name)
<Groogy>
duh spelling error
<FromGitter>
<rishavs> @Groogy you might be already doing this, but remember to not check in db paths in your repo
<FromGitter>
<rishavs> better to keep it as an environment variable and then use utils like Dotenv to load them at run time
<FromGitter>
<giuseongit> hi guys, can I alias a keyword in crystal?
<hightower2>
giuseongit: you can alias a type or union of types, and/or you can use a macro to mimick an "alias"
<hightower2>
show us a more specific example of what you had in mind
<FromGitter>
<giuseongit> With an ex professor of mine we were wondering if is it possible to create a crystal-based dsl for education purposes. It might be used by very young childs (~10 years), so I was asking if I can alias the keywords in order to produce a readable language by kids since I'm not english
<FromGitter>
<marten> hi, i'm trying to get the type system to work with the following:
<hightower2>
giuseongit: well, I'd say you can do a simple alias (like for example, rename "puts" into "show"), like this: macro show(args) puts({{args}}) end
<hightower2>
giuseongit: although I am not sure how "complete" of a language you can make with this, as opposed to writing a "proper" DSL syntax
<FromGitter>
<marten> but that seems to fail with "in line 10: type must be Array(Action), not (Array(Eat:Class) | Array(Sleep:Class) | Nil)"
<FromGitter>
<girng> @marten how does it take in a string if it ccepts an array?
<FromGitter>
<marten> (updated above, forgot to add the else-branch to prevent returning nil to my minimal sample, but still doesn't work)
<FromGitter>
<marten> it should take in a string and then return the class of a subclass of Action
<FromGitter>
<marten> if i just specify it's returning `Array(Class)` the compiler says `in line 10: type must be Array(Object:Class), not (Array(Action) | Array(Eat:Class) | Array(Sleep:Class))`
<hightower2>
marten: yes, for sure you can't say Array(Class) for multiple reasons. One being that saying it returns "some class" is not enough for the type system, and even then you couldn't say just "class"
<FromGitter>
<bmulvihill> I think part of the problem is because you are returning the class, not an instance of the class. i.e. ( Sleep.new)
<FromGitter>
<marten> yeah the instantiation is happening elsewhere in the code, to new up an action you need some objects which i didn't want to pass in to what's the `foo` method here
<FromGitter>
<marten> but if there's no way around it i guess it'll have to do for now
<FromGitter>
<giuseongit> @hightower2 oh well, I didn't think about it. Well then I can count the declaration of a method as impossibile to reword (leaving syntax unaltered, I mean)
<FromGitter>
<diegogub_gitlab> hello! someone knows how to compare times in crystal?
<FromGitter>
<diegogub_gitlab> or taking diff between 2 Time
<f1refly>
It returns some int32, probably representing... well something? The docs are rather vague, play with it a bit i'd say
<FromGitter>
<asterite> number of seconds
<f1refly>
would probably good to write that down
<FromGitter>
<asterite> @giuseongit you can modify the lexer/parser of crystal to use keywords of another language. You'll have to compile a new compiler for that, though. Otherwise, there's no way you can do it
<FromGitter>
<diegogub_gitlab> @F1ks3r thank, yes..using seconds and minutes works. I was searching for something like: t.after(t2). but this way works the same
<FromGitter>
<asterite> @diegogub_gitlab what's `t.after(t2)`? You can do `t > t2`. Is that what you mean?
<FromGitter>
<diegogub_gitlab> @asterite you are right, some of the stupid Golang flashback
shalmezad has joined #crystal-lang
<FromGitter>
<asterite> :-)
<jokke>
is there a shard for writing to clipboard?
<oprypin>
jokke, sfml LOL
<jokke>
oprypin: :D
<oprypin>
it works tho
<oprypin>
giuseongit, crystal seems really quite good for the purpose, UNTIL you think about the useless error messages that it might start spewing for any tiny typo
<oprypin>
(i'm not saying they're bad in general but only after this kind of interference)
<jokke>
how do i detect the build system?
<jokke>
ie DARWIN/LINUX
<FromGitter>
<j8r> the OS?
<FromGitter>
<j8r> you can use macros
<jokke>
yeah which ones?
<FromGitter>
<j8r> `{% if flag?(:linux) %}`
<FromGitter>
<j8r> or `{% if flag?(:darwin) %}`
<jokke>
ah great
<jokke>
thanks
<FromGitter>
<rishavs> can i return an io object as an http server response? so far, i only know how to send strings like html, json etc
<FromGitter>
<rishavs> my use case is that I want to try sending the output of `ECR.embed "greeting.ecr", io` directly without converting it to string
<FromGitter>
<rishavs> nice. gonna try this out. @straight-shoota was saying that this might be a more effiecint way of using ECRs compared to ECR.render in my http server
<FromGitter>
<rishavs> it worked. but i am able to see any noticeable different between the two. Still I will keep it in mind when I need to start optimizing. Thanks @Sija
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 272 seconds]
Raimondii is now known as Raimondi
zorp has quit [Ping timeout: 256 seconds]
<FromGitter>
<asterite> @rishavs I don't think the difference in performance can be seen with a human eye
akaiiro has joined #crystal-lang
bmcginty has quit [Ping timeout: 260 seconds]
bmcginty has joined #crystal-lang
akaiiro has quit [Remote host closed the connection]
<FromGitter>
<r00ster91> What about changing the type restriction of every arg which can't be lower than 0 to `UInt32` in the std? Instead of raising an `ArgumentError` with a message like "Negative size".
akaiiro has joined #crystal-lang
<z64>
most user code will more often than not only be using Int32. if the user does arithmatic with that value - meaning they don't have a literal in their code for automatic cast - they will have to manually write out foo((a + b).to_u32)
<z64>
try doing (-1).to_u32
<z64>
that will overflow and more than likely cause hidden or confusing problems. much simpler to keep everything at Int32 and safely raise a runtime exception, and the code easier to read without any casts
<FromGitter>
<r00ster91> Hmm okay yeah you are right. Probably not a good idea if it will hide bugs and will result in more code with to_u32 conversions
<FromGitter>
<geolessel> The error I'm receiving is commented out at the bottom of that file.
return0xe has quit [Read error: Connection reset by peer]
hightower2 has quit [Remote host closed the connection]
shalmezad has quit [Quit: This computer has gone to sleep]
wontruefree has joined #crystal-lang
akaiiro has joined #crystal-lang
johndescs has quit [Ping timeout: 240 seconds]
johndescs has joined #crystal-lang
alex`` has quit [Ping timeout: 255 seconds]
return0e has joined #crystal-lang
<FromGitter>
<Sevensidedmarble> Quick question, is the @[Link:] format what can be used to call an outside C file?
<FromGitter>
<Sevensidedmarble> I basically have a single c file and header I'd like to be able to call
<FromGitter>
<Sevensidedmarble> and do I need to compile my C library down to an object file first?
<FromGitter>
<Sevensidedmarble> sorry if these are stupid questions but I am pretty bad with C
<FromGitter>
<Sevensidedmarble> I think `@[Link(ldflags: "#{__DIR__}/hello.o")]` would be roughly the form right?
zorp has quit [Ping timeout: 265 seconds]
<FromGitter>
<Timbus> Seems like it should. I saw that approach being taken for .a files
<FromGitter>
<Sevensidedmarble> also if the compiled code has a struct say, how could I use that as a type in a `fun` call from crystal?
<FromGitter>
<Timbus> but, .a files might be passed differently
<FromGitter>
<Timbus> like with a -l in front of them
<FromGitter>
<Timbus> You need to declare that struct in crystal, to match
<FromGitter>
<Sevensidedmarble> ahhhh
<FromGitter>
<Sevensidedmarble> can I reference the definition in C?
<FromGitter>
<Sevensidedmarble> or do I have to actually copy it
<FromGitter>
<Timbus> No, crystal can't parse the header for you :(
akaiiro has quit [Ping timeout: 265 seconds]
<FromGitter>
<Sevensidedmarble> that'd be pretty cool
<FromGitter>
<Timbus> It's one of those things that seems easy but there's many edge cases that would betray too many user's expectations. And if it doesn't work 100% of the time, you can't trust it. Ya know
<FromGitter>
<Timbus> dlang had this same problem. Maybe libclang could solve it
<FromGitter>
<Sija> there’s couple of shards helping with that tho'
<FromGitter>
<Timbus> Yeah you can statically convert the headers, that's cool
<FromGitter>
<Sevensidedmarble> wow
<FromGitter>
<Sevensidedmarble> I could probably just copy the necessary definitions, I have a very small header file I want to work with
<FromGitter>
<Sevensidedmarble> I'm not sure how the idiom of like `typedef struct Cell Cell`in c translates to crystal though
<FromGitter>
<Timbus> Hmm, looking at than manpage for ld, linking to a .a file is a slightly different syntax so it might not work as cleanly as you expect. might wanna test it on a tiny hello-world first
<FromGitter>
<Sevensidedmarble> it seems to work ok for me if I compile to a .o file
<FromGitter>
<Timbus> nice
<FromGitter>
<Timbus> thanks for confirming because I need to do the same thing soon :D