<FromGitter>
<Qwerp-Derp> @faustinoaq Maybe there should be a feature that places an `end` statement automatically when you type stuff like `class` or `module` etc.? I personally don't use the extensions, I prefer to type the class and stuff out.
<FromGitter>
<Qwerp-Derp> ^ This is for the VSCode plugin
<FromGitter>
<bew> maybe this could be done by snippets, I personally have 15-20 snippets in my crystal workflow (in vim), to auto-add end, indentation, define a method, add brackets for macros, add a block (with/without args), etc.. @faustinoaq I don't know if vscode allows plugins to define snippets, if it is, I think it would be the way to go!
<FromGitter>
<Qwerp-Derp> There's already something like where you type `class` for example and press Tab, the whole thing extends to a full `class`
<FromGitter>
<Qwerp-Derp> With like an end statement
<FromGitter>
<Qwerp-Derp> But I personally don't use it (don't ask me why :P), I think the auto-`end` with things like `class`, `def`, `case` and stuff would be great
rohitpaulk has quit [Ping timeout: 240 seconds]
<FromGitter>
<bew> Oh ok, so there's already some snippets 🆒
<FromGitter>
<Qwerp-Derp> Yeah, my phrasing was a bit odd :P, by "extension" I meant things like that `class` and Tab thing
<FromGitter>
<bew> But then what's the difference for you between the already-there class snippet, and the auto-end you're suggesting?
<FromGitter>
<bew> Does the class snippet do too much things for you?
<FromGitter>
<Qwerp-Derp> Nah, the Tab just feels unnatural to me for some strange reason, since there's already auto-indentation
<FromGitter>
<bew> Then change the key bound for the expand-snippet action? (Or sth like that)
<FromGitter>
<Qwerp-Derp> Yeah, good point
<FromGitter>
<bew> I personaly have it to the key above tab (not existant on some keyboard)
<FromGitter>
<Qwerp-Derp> Can you make a function that takes a type as an argument?
<Papierkorb_>
crisward, as long they're not simply blocking VPN protocols for the home users
<txdv>
lol to stop email leaks
<txdv>
poor old people dont understand how this shit works
<FromGitter>
<ekremkaraca> Wikipedia is still blocked here
<Papierkorb_>
crisward, Or go full China and scan all connections for suspicious behaviour
<txdv>
the people responsible for the leaks are not even using github, google drive or dropbox
<FromGitter>
<bararchy> well Papierkorb_ , you can always exfil data using multiple protocols if really needed https://github.com/ytisf/PyExfil
<txdv>
china is fucked up
<txdv>
i have to block it entirely
<FromGitter>
<crisward> @ekremkaraca I can see why, their are lots of articles on there about censorship in turkey. Kind of cyclical.
<txdv>
because if you don't block china and forget a patch for 1 week, your server will be compromised
rohitpaulk has joined #crystal-lang
<Papierkorb_>
bararchy, of course you can. But it's still a cat & mouse game.
<FromGitter>
<bararchy> in the end, I say, block all or allow all, middle ground is for noobs hahah
<Papierkorb_>
Of course, but most users *are* noobs
<FromGitter>
<bararchy> most users are not why you block github
<FromGitter>
<bararchy> XD
<Papierkorb_>
Not that long ago, you could surf for free from an airplane because they didn't deny outgoing DNS, which is great for tunneling. 1) Holy shit we can go online while crossing continents?! 2) Lawl.
<FromGitter>
<bararchy> XD
<FromGitter>
<bararchy> VPlane (nextGen VPN) , it's an idea for a new service, hahah
<FromGitter>
<bararchy> can never be targeted by a single state
<FromGitter>
<bararchy> LOL
<FromGitter>
<ekremkaraca> @crisward because of expressing that having a relationship between one of our minister and so called Islamic State
snsei has quit [Remote host closed the connection]
<FromGitter>
<mjago> wayland
<Papierkorb_>
ansarizafar, that rule-syntax looks inherently incompatible with Crystal. Not that it's technically possible, but it'll always be plain bad.
<Papierkorb_>
We have proper types, including ranges. You can even check for those.
rohitpaulk has quit [Ping timeout: 240 seconds]
<Papierkorb_>
ansarizafar, First architecture that comes to my mind: have a `abstract class Rule`, and then `class RequiredRule < Rule` etc. Now, you add a method to the RuleSet class you just created called `#rule`. You overload this method for each Rule sub-class, basically passing through all arguments to the Rule's #initialize. The kicker is now that the #rule method is defined like: `def rule(requires); @rules << RequireRule.new(requires); end`. Now,
<Papierkorb_>
the user can write `rules.rule(requires: "Foo")`.
<Papierkorb_>
Do note that this kind of library is *only* useful to validate variable "structures" like Hash, which are *no that common* in good Crystal code. In fact, I wouldn't use a library like this in my normal code. I'd instead simply use JSON.mapping with a custom converter for checks. Or even better, contribute a `validator:` option to the JSON.mapping function.
<FromGitter>
<ansarizafar> In my use case, I want to validate parameters, sent by the users to a common Api endpoint(a variable Hash ). Keys are not known in advance so JSON.mapping can't be used.
<Papierkorb_>
Is that shared API endpoint really required, or can you fix it?
<Papierkorb_>
In any case, what I wrote above still holds: Using OOP paradigms instead of a random-rule-string gets you many benefits: 1) Type safety 2) The compiler complains when you mis-type 3) Nicer to read and write in general 4) It may be a ns faster.
<FromGitter>
<ansarizafar> It's a Graphql inspired data layer(Single end point for all api calls), that I am trying to port from Nodejs. I have successfully ported most of the code including jwt authentication and role based authorization only the last part parameter validation is left.
<Papierkorb_>
In that case, yes if there's not already a suitable validation shard for you (check crystalshards.xyz), you do need a lib like this. As long you don't replicate the exact validation API, you'll be fine
<FromGitter>
<ansarizafar> I have searched crystalshards.xyz but no luck.
<FromGitter>
<ansarizafar> I guess my use case is different
<Papierkorb_>
Surprising, would've guessed there's already a dynamic-structure validation lib
<Papierkorb_>
ansarizafar, please take my apologies then. Many devs coming from dynamic languages try to cram their dynamic knowledge into a static language, so I generally advise to check those static solutions first instead.
<FromGitter>
<ansarizafar> You are right. I am still thinking in JavaScript.
<FromGitter>
<ansarizafar> Forget the syntax. I am looking for a good validation lib for dynamic structures.
<Papierkorb_>
Without thinking about the details, I think you could create something nice to use by either 1) overloading a common #rule method 2) having a method per kind-of-rule (#requires, ...) - Benefit of 2) is that the text editor has an easy time to auto-complete, easier to understand, and less ambigoous
<FromGitter>
<ansarizafar> The idea of a Validator class with separate methods for each rule is good. But I don't want to write multiple statements to apply multiple validators for each parameter key in each api method. I need to automate the process somehow. ⏎ ⏎ ```validate(parameters, rules)``` [https://gitter.im/crystal-lang/crystal?at=59d208de7f323fc375f7eb3c]
<Papierkorb_>
You could exploit `with X yield` for this. It's a bit advanced, but it lets you define the implicit self for the time of the block yield. Say you have `validate("foo"){ requires("bar"); in_range(1..4) }`. #validate could build a `RuleDsl.new(field_name)`, with yield that to the block. That Dsl class then has the `#requires` etc. methods. Then you save typing, but can keep the logic
<Papierkorb_>
Even more interesting, this would allow you to effortlessly define schemas for hierarchies.
<FromGitter>
<krypton97> Some nice stuffs from google
<FromGitter>
<krypton97> Courious to see if it outperforms react-native or nah
<FromGitter>
<schoening> Has anyone been working on android / ios build recently?
<Papierkorb_>
schoening, would also be interested hearing about Android
claudiuinberlin has quit [Read error: Connection reset by peer]
puskuruk has joined #crystal-lang
<Groogy>
@ansarizafar it sounds like you want contract tests then? It's what I have implemented
<Papierkorb_>
Groogy: he wants to validate data structures, not method arguments (... maybe that too?)
<Groogy>
In my use case, I want to validate parameters, sent by the users to a common Api endpoint
<Groogy>
oh yeah you are right I just misread that part
<Groogy>
yeah no my library is not for that
<Papierkorb_>
... I mean you could add that to your lib lul. if it works with dynamic and static structures, allowing to (only) validate structures and/or method arguments at once, that'd be kinda cool
<Groogy>
hmmm could you write up example what you mean?
<Groogy>
you mean like "oh this hash should have a format sort of like this"?
<Papierkorb_>
yes
<Papierkorb_>
It's right now not exactly what your lib is after as far I understand, and while it's not directly the core usage for it(?), it may be an interesting addition on the long run.
<Groogy>
hmm attached to a hash obj or whenever it enters a function?
<Groogy>
well the library is more "a contract" between the programmer and the lib/class. Telling oyu what it expects, and what it ensures will be true
puskuruk has quit [Ping timeout: 260 seconds]
<Groogy>
where this can kind of fit
<Papierkorb_>
Well, for a function contract, like you're already doing. After that it'd be interesting to be able to invoke a validation on a structure alone
<Papierkorb_>
Groogy: To catch stupid input from the programmer, and from the user too?
<Groogy>
Well the code is not added when you compile in release mode by default. Contract programming is an extension of defensive programming. "Let the application fuck up and catch it as early as possible"
<Groogy>
though you could of course enable it in release mode without much overhead but just like normal asserts, if you do a stupid test it is gonna be super slow
<Groogy>
could have a requires_r, ensures_r and invariant_r which are always compiled in release mode as well or something like that
<Papierkorb_>
Honestly, I think it's a security issue when asserts are removed in release mode builds (Same in C, meh)
<Groogy>
Or you know what! I could just do a static list you can build yourself
<Groogy>
marking certian classes as always generting their contracts
<Groogy>
i.e I always want this to fail, even in release
<Papierkorb_>
I'd actually prefer an explicit opt-out rather than opt-in
<Groogy>
hmm the overhead should be quite negible with the new design actually.. so yeah
<Papierkorb_>
I'd use your lib to e.g. shield me from malicious user input. If I forget in the heat of the moment to opt-in my class, I'd be f'd.
<Groogy>
you can also catch the exception so :)
<Groogy>
should probably allow some how custom exception in the contract if you want to
<Papierkorb_>
And even if the checks are expensive (not because of unnecessary overhead, but because the check the programmer wrote is) then ... so what? Apparently, it's a complex thing to check for.
<Papierkorb_>
Really interesting would be if somehow, you could call only the method contract (without the underlying method), to test validations in specs easily
<Papierkorb_>
Without having to catch an exception, it returning the error message or nil (or even Bool) would be great for that
<Groogy>
Actually I can do that super easy papier :D
<Papierkorb_>
That on_contract_fail hook sounds useful
<Groogy>
though you should probably run the tests, because the ensure test is usually on what you return fro mthe function
<Groogy>
so you would have ot mock the return value somehow
<Papierkorb_>
you have ensure contracts?
<Groogy>
yeah
<Groogy>
requires, ensure and invariants(class tests, run before and after every method call)
<Papierkorb_>
ah, well, could you separate them from the argument contracts for the spec thing?
<Groogy>
could just ignore running them yeah
<Papierkorb_>
So that one could write some table-esque spec as test. Hopefully more readable than having to think up arguments that should trigger an ensure
<Groogy>
actually talking about this, I should focus bit more on the library and make it so it integrates well with the specs system in Crystal
<Groogy>
would be cool if I could autogenerate specs from contracts somehow
<Groogy>
since the information is "literally there"
<Papierkorb_>
Allowing calling the validations on their own, and a neat README.md chapter explaining this (and/or sample code) would be fine I guess
<Papierkorb_>
You can do that for simple tests. But is it worth it?
<Papierkorb_>
Are you then testing the contracts intention, or the contracts code the programmer just wrote?
<Groogy>
contracts intention, what the contract "guarrantees"
<Groogy>
I mean like so you can do crystal spec
<Groogy>
and get reasonable info back
<Papierkorb_>
`requires(foo, to_equal: "Bar")`. you can check that, but what if I actually meant to write "barr" instead?
<Groogy>
nah was thinking just a spec helper that scans the constants in CrystalClear module and dynamically creates tests for you or some such
<Groogy>
so you get the dots and F's, etc.
<Papierkorb_>
Oh a `expect_that_it(requires(foo, to_equal: "bar"))` macro?
<Groogy>
kind of yeah
<Papierkorb_>
You could do that, yep.
<Groogy>
and then voila you don't have to write two different sets of tests, you can just magically use crystal spec
<Papierkorb_>
And would rather nicely. I mean, the it text would almost always say what the block does almost exactly anyway
<Papierkorb_>
Oh, I would've used spec in any case
<Papierkorb_>
A shard not offering spec integration doesn't prevent specs (thankfully)
<Groogy>
No no, but I mean I can integrate better with specs than currently
<Papierkorb_>
Yes
<Groogy>
damnit I was only supposed to do a small face lift xD
sz0 has quit [Quit: Connection closed for inactivity]
<Groogy>
hmmmmmm is there a flag turned on when you are running specs that my macros could look at?
<Groogy>
because I could literally do ( condition ).should eq true
<Papierkorb_>
The generated code of the users business logic shouldn't change
<Groogy>
hmmm true
<Groogy>
so it has to be applied outside of the contracts somehow
<Papierkorb_>
Just pull the pre and post checks into their own methods, which you also call from the "real" code, and then you can call these like normal
<Papierkorb_>
In fact, that might turn out to be an interesting feature for edge-cases (in non-testing logic), while being helpful for testing
<Groogy>
if you want to be sure your ensure contract should fail
<Papierkorb_>
Can't you split the pre/post steps there too?
<Groogy>
yeah so you can do expect_require_contract_fail(...) if you want to etc.
<Papierkorb_>
If I want to make sure the ensures are correct, I don't want the test to fail because I didn't think of some random arguments
<Papierkorb_>
That could work
<Groogy>
yeah that's what I mean you can do a mock return value to test on that you are 100% sure should fail the value
<Groogy>
and if it doesn't, the contract is wrong
<Papierkorb_>
yes
<Groogy>
maybe should name it expect_contract_fail! (with a bang) then will actually call the method on the object while the expect_require_* and expect_ensure_* and expect_invariant_* will only do the tests
<Groogy>
or hmmm
<Groogy>
problem becomes ensure needs the return value
<Groogy>
or *an* return value, will think on it during the day
<Papierkorb_>
ffs. Hitting `e` while in a random file of someone elses github repository will fork the whole thing and put you into editing mode of that file, without asking if you want to
<FromGitter>
<bararchy> Yap, happend to me to, github shourtcuts
ShalokShalom is now known as ShalokShalom2
balduin has joined #crystal-lang
balduin has quit [Ping timeout: 248 seconds]
ShalokShalom has joined #crystal-lang
ShalokShalom2 has quit [Ping timeout: 258 seconds]
LastWhisper____ has joined #crystal-lang
p0p0pr37 has quit [Ping timeout: 258 seconds]
sz0 has joined #crystal-lang
<FromGitter>
<jwaldrip> @asterite looking like a release this week?
<FromGitter>
<jwaldrip> Im drooling over the upcoming changes, on the edge of my seat...
<FromGitter>
<bew> and in some advanced programming in UNIX books
<FromGitter>
<bew> and no, your solution won't work (the reopening)
<linuksz>
why?
<linuksz>
does it close the fd first?
<FromGitter>
<bew> iirc a background job has no specific fd modification, it just don't run, or if it runs (like with `bg` it uses the same stdout/err as the shell (see the link above)
<FromGitter>
<jose-rodrigues> What is the bash equivalent of what you want to do?
<FromGitter>
<bew> probably `fg`
<linuksz>
'yes &'
<linuksz>
this: 'fg 1'
<FromGitter>
<jose-rodrigues> OK but why are you trying to play around with outputs?
<FromGitter>
<jose-rodrigues> yes& keep the stdout
<linuksz>
oh. indeed.
<linuksz>
now tried it. :|
<FromGitter>
<bew> linuksz, when you run `yes &` is `sh`, you'll see that the output still flow as hell ^^
snsei has joined #crystal-lang
<linuksz>
then bash don't have a an equivalent for this
<FromGitter>
<jwaldrip> @bew they are marked as approved. Is there work to be done on them still?
<linuksz>
i want to redirect the output of bg jobs to /dev/null, and reopen to STDOUT with the 'fg' command
<linuksz>
maybe a SIGSTOP first, then reopen, then SIGCONT?
<FromGitter>
<jose-rodrigues> I don't this this is possible
<FromGitter>
<bew> either way, linuksz: when you want to change the fd of a process you're executing (like: for a redirection to a file), you need to 1. fork, 2. open the files with proper fd & 3. exec the program. you can't change the fds of another process, anly your own
<FromGitter>
<jose-rodrigues> @bew 42sh trained you well :D
<FromGitter>
<bew> and I wasn't even on the process execution part of the project! ^^ @sdogruyol it's a project at Epitech, were we need write a basic shell
<FromGitter>
<jose-rodrigues> @sdogruyol Epitech is a french dev school
<FromGitter>
<sdogruyol> lol
<FromGitter>
<sdogruyol> good one
<FromGitter>
<jose-rodrigues> Sorry my sentence was wrong. so you thinked it was a person. :)
<linuksz>
oh, i now see that LibC.dup2 closes the fd before modifying it
<linuksz>
it's not clear for me what reopen does. i thought that if fildes1 is reopened to fildes2, then anything written to fildes1 will go to fildes2. but why does it return a file descriptor? the C function dup2 returns int.
<crystal-gh>
[crystal] mverzilli closed pull request #5022: Increase the precision of Time and Time::Span to nanoseconds (master...feature/time) https://git.io/vdJCp
<FromGitter>
<bew> did you read the man page of this function?
<FromGitter>
<bew> @jwaldrip #5022 merged by @mverzilli 🎉
<FromGitter>
<bew> only #5007 missing
<FromGitter>
<jwaldrip> 1 more!!!
<FromGitter>
<jwaldrip> thats the one I want is #5007
<FromGitter>
<bew> go ping the issue!
<crystal-gh>
[crystal] mverzilli pushed 1 new commit to master: https://git.io/vdcru
<FromGitter>
<DRVTiny> How to avoid stupid variable initialization in my class?
snsei has quit [Remote host closed the connection]
<FromGitter>
<mverzilli> suppose the compiler let's you get away without initializing @status_type. What happens if you catch that exception outside of HTTPException and then call `type()` on it?
snsei has joined #crystal-lang
<FromGitter>
<DRVTiny> ```Unhandled exception of the type Exception catched: Illegal HTTP status code received``` ⏎ ⏎ I dont need to call "type()" on "some", because i know that "some" is not an HTTPException (i've checked this earlier) [https://gitter.im/crystal-lang/crystal?at=59d2671a210ac269209ab36f]
<FromGitter>
<DRVTiny> code and type methods are not defined in the class Exception, so i have to check Exception class, i must know that before doing anything with exception object (how to operate with the object of possibly unknown class?)
Xadusons has joined #crystal-lang
Xadusons has left #crystal-lang [#crystal-lang]
mark_66 has quit [Remote host closed the connection]
snsei has quit [Remote host closed the connection]
<FromGitter>
<mverzilli> so you know that "some" is not an HTTPException but the compiler doesn't. Crystal checks that you properly initialized all ivars. You can for example initialize @status_type in the rescue clause of the HTTPException constructor so that all codepaths result on it being correctly initialized
<FromGitter>
<mverzilli> you can declare @status_type as `String?` and initialize it to `nil` to signal that it's not set
Groogy2 has joined #crystal-lang
Groogy has quit [Disconnected by services]
Groogy2 is now known as Groogy
Groogy_ has joined #crystal-lang
<Groogy>
ah finally home, time for some crystal <3
linuksz has quit [Quit: Leaving.]
<Groogy>
bew you here?
<Groogy>
oh right gotta tag you like @bew since you are on gitter :P
<FromGitter>
<bararchy> how can I "sample" from hash ?
<FromGitter>
<mverzilli> calling `sample` on `keys` doesn't cut it?
nikkkk has joined #crystal-lang
<FromGitter>
<bararchy> yeha, that's what I do, just wanted to know if there is a sample that will return a k=>v pair
<Groogy>
I don't get why I get two "doing 'require' var > 5 here
<Groogy>
most of the stuff is also placed in a sub module under the class to keep the namespace clean
<crystal-gh>
[crystal] straight-shoota opened pull request #5069: Fix for YAML spec failure with new nanoseconds precision (master...fix-yaml-spec-nanoseconds) https://git.io/vdCZm
<FromGitter>
<bew> (maybe it was when I removed the 2 `\{{method}}` that are not useful? no idea, don't have to find why r8t now ^)
pawnbox has joined #crystal-lang
<crystal-gh>
[crystal] akzhan opened pull request #5070: Time constructor now expect nanoseconds instead of milliseconds. (master...time-constructor=now-expect-nanoseconds-instead-of-milliseconds) https://git.io/vdClX
<FromGitter>
<jwaldrip> @akzhan I about jumped on the breaking changes too.
<FromGitter>
<jwaldrip> @akzhan @straight-shoota : good job on #5069 and #5070 ... SO EXCITED FOR THIS RELEASE
pawnbox has quit [Ping timeout: 240 seconds]
<Groogy>
@bew I got it to work by just "hashing" it kinda
<FromGitter>
<bew> Groogy I don't get what you're trying to do with the CLASS_DATA things
<FromGitter>
<bew> Also, maybe you didn't see it, you can replace: `\{{("contract_pre_" + name.stringify).id}}` by `contract_pre_\{{name}}`
<FromGitter>
<bew> (And the same apply for all your added methods)
pawnbox has joined #crystal-lang
pawnbox has quit [Ping timeout: 240 seconds]
<FromGitter>
<Qwerp-Derp> Why does JSON have `JSON::Any` and `JSON::Type`? Isn't it better to replace all uses of `JSON::Type` with instances of `JSON::Any`?
<FromGitter>
<georgeu2000> Are there any tutorials on this?
<FromGitter>
<jose-rodrigues> @georgeu2000You don't want to use a framework?
<FromGitter>
<opensas> @Qwerp-Derp it's a wrapper for all json types, allowing you to traverse unknown json structures. Once I had to implement a generic method to traverse unkwon json structures and I could do it just fine using JSON::Type, a case statement and recursive calls, have a look at: https://github.com/opensas/json-mappings-generator/blob/master/src/json-mappings-generator.cr#L70