<oprypin>
heck, i keep running into `Invalid memory access (signal 11) at address 0x4` with Halite
<oprypin>
well at least it's the same cause as before
<oprypin>
hmm is there any rate limiting solution? say i know how many calls i am allowed in an hour, but i don't want to just wait hour/N before allowing a next request. some burst should be allowed.
jrayhawk has joined #crystal-lang
jrayhawk has quit [Read error: Connection reset by peer]
jrayhawk has joined #crystal-lang
<FromGitter>
<Blacksmoke16> Group the requests into 1 hour buckets, keeping track of the total made per bucket. When the bucket is full, sleep till start of next
<FromGitter>
<Blacksmoke16> I have some code I can share for what we use at work
<FromGitter>
<Blacksmoke16> Uses redis as the backend
<oprypin>
Blacksmoke16, the api can block me itself, i dont want to reach that point 😂
<oprypin>
"some burst should be allowed." but not too much burst
<oprypin>
exceptions are such amazing control flow, i cant even. poor c++ users having to avoid them
<FromGitter>
<Blacksmoke16> Right, you wouldn't hit the limit with this approach
<FromGitter>
<Blacksmoke16> And would all for bursts of up to the limit
<FromGitter>
<Blacksmoke16> Allow
deavmi has quit [Read error: Connection reset by peer]
deavmi has joined #crystal-lang
<oprypin>
Blacksmoke16, oh i see. was just confused because the api itself happens to track quota in hour increments
<FromGitter>
<Blacksmoke16> prob can do without the multiplier part
<oprypin>
mm
<FromGitter>
<munjalpatel> Hey folks, ⏎ ⏎ I am trying to make a very simple piece of code work for last few hours but really going no where. ⏎ I am using `Kemal` and trying to simply get `String` from the posted `json` like this: ⏎ ... [https://gitter.im/crystal-lang/crystal?at=5fc1b1650219b46a26636ef6]
<FromGitter>
<Blacksmoke16> `.as(String)`?
<FromGitter>
<Blacksmoke16> the value of `"name"` is a union of all those types, so you just need to tell it, hey i know this should be a string
<FromGitter>
<munjalpatel> Thanks @Blacksmoke16 .. that makes sense .. I misunderstood `.json()` to be `JSON::Any` only
<FromGitter>
<Blacksmoke16> np
<FromGitter>
<munjalpatel> However, I am implementing a validation logic so what would be a good way to raise an exception if someone posts a non-string value for "name"? ⏎ I tried `typeof` however it keeps giving me `(Array(JSON::Any) | Bool | Float64 | Hash(String, JSON::Any) | Int64 | String | Nil))` union
<FromGitter>
<Blacksmoke16> `is_a? String`?
<FromGitter>
<Blacksmoke16> the union represents the *possible* types, `is_a?` checks the type of the current value
<FromGitter>
<munjalpatel> Great .. thanks .. will try that!
<FromGitter>
<Blacksmoke16> depending on what you're doing there are also other frameworks that may be better suited than kemal
<FromGitter>
<rishavs> @Blacksmoke16 means https://github.com/athena-framework/athena ⏎ Though if you are only doing an api server, I still hold, you do not need any framework. the std lib modules are good enough.
<FromGitter>
<watzon> If you feel like reinventing the wheel. Unless your API is very basic that's rarely a good idea.
Seich has quit [Quit: Gone fishing.]
Seich has joined #crystal-lang
Seich has quit [Quit: Gone fishing.]
Seich has joined #crystal-lang
_whitelogger has joined #crystal-lang
_whitelogger has joined #crystal-lang
f1reflyylmao has quit [Quit: bye fags]
f1refly has joined #crystal-lang
jrayhawk has quit [Read error: Connection reset by peer]
jrayhawk has joined #crystal-lang
jrayhawk has quit [Remote host closed the connection]
<yxhuvud>
odd. make clean && make spec in main crystal repo (latest master) fails with .build/all_spec: symbol lookup error: .build/all_spec: undefined symbol: __libc_start_main, version WeakRef(T)#initialize</home/linus/prog/crystal/spec/std/weak_ref_spec.cr::Foo>:(Int32 | Nil)
riffraff169 has left #crystal-lang [#crystal-lang]
riffraff169 has joined #crystal-lang
* FromGitter
* tenebrousedge really wants the `shards` PR that fixes all the tests to be merged 😬
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
postmodern has joined #crystal-lang
<FromGitter>
<rishavs> In an HTTP Server, how can I pass arguments/values from one middleware to another? Is adding a custom param to act as a store the way to go?
<straight-shoota>
yes
<straight-shoota>
you can add a custom ivar to HTTP::Context
<FromGitter>
<rishavs> Thanks! So my plan is to have an auth middleware which will extract the userid into a param which can then be used by subsequent middlewares and the response.
<FromGitter>
<Blacksmoke16> 👍 thats a common thing
<FromGitter>
<j8r> @rishavs I sounds like you should start to look at a web framework
<FromGitter>
<j8r> it goes beyond a simple HTTP server
<FromGitter>
<j8r> Usually framework have a simple way to put a set of routes behind auth. And some, without even monkey-patching the HTTP context
<FromGitter>
<rishavs> I actually want to use the std lib only. There is just so much learning that way. I have only ever used high level frameworks before and i really didn't understand much about how things worked. But using the std lib has been quite a revelation
<FromGitter>
<j8r> You know you're starting to make your own web framework. Might be fine, if the goal is to learn
<FromGitter>
<rishavs> yeah sort of. 😅 ⏎ I code mostly for fun and stress release. My day job is non coding.
<FromGitter>
<j8r> even though you could be Program Manager of the Program Manager product haha 😆
<FromGitter>
<rishavs> ^_^
<FromGitter>
<Dan-Do> It seems my regex is wrong, it matches the whole string, but I want multiple small matches: ⏎ `"__foo__bar____foo__bar__".match(/.*(foo).*(bar).*/)`
<FromGitter>
<Dan-Do> it matches `foo__bar____foo__bar`
<FromGitter>
<Blacksmoke16> prob need a `?` in there somewhere to make it lazy
<FromGitter>
<Blacksmoke16> now that i think about it never actually closed the loop on it. I.e. adding links to API docs/readme
<straight-shoota>
yeah
<straight-shoota>
it's completely hidden
<straight-shoota>
I'd recommend to put it on a website, not github wiki
<straight-shoota>
next to api docs
<FromGitter>
<Blacksmoke16> wiki was a quick solution to get something out there
<FromGitter>
<Blacksmoke16> longer term deff need something a bit more robust
<FromGitter>
<Blacksmoke16> at least for the stuff that doesnt really relate to any specific thing in the API docs
<FromGitter>
<Blacksmoke16> like the cookbook/guides/higher level docs etc
<oprypin>
Blacksmoke16, just start the investment right now. put a much lower bar for what "doesnt really relate to any specific thing in the API docs"
<oprypin>
wiki is a bunch of markdown files. make an explicit bunch of markdown files instead. in the repo.
<FromGitter>
<Blacksmoke16> Sounds like a good winter project
<FromGitter>
<Blacksmoke16> good news is a good amount is already written, so would just be moving it around a bit
<yxhuvud>
Famous last words. Risk is that you will realize exactly how much is missing :)
FromGitter has quit [Read error: Connection reset by peer]
FromGitter has joined #crystal-lang
<FromGitter>
<ImAHopelessDev_gitlab> what's up with the acronyms "IMO", "IMHO", and "JMO" used on the internet nowadays? i see it a lot on github and IT related discussions. i don't remember this being a thing 5-7 years ago
sorcus has quit [Quit: WeeChat 2.9]
<straight-shoota>
IMO that didn't change. At least I've jused it 10 years ago.
sorcus has joined #crystal-lang
<FromGitter>
<ImAHopelessDev_gitlab> maybe i just didn't notice it back then and now have
<yxhuvud>
nowadays? they have existed at the very least since the 80s.