<FromGitter>
<HertzDevil> do we have a clear stopping point for 1.0.0-pre1 yet
<straight-shoota>
nope
<FromGitter>
<HertzDevil> π
<straight-shoota>
not sure what we're waiting on
deavmi has quit [Read error: Connection reset by peer]
deavmi has joined #crystal-lang
f1refly has joined #crystal-lang
f1reflyylmao has quit [Ping timeout: 272 seconds]
chachasmooth has quit [Ping timeout: 240 seconds]
chachasmooth has joined #crystal-lang
<FromGitter>
<Daniel-Worrall> @RespiteSage I setup a private leaderboard for Crystal on my account and shared it in the crystal discord. Forgot to share it here
<kevinsjoberg>
Kind of repetitive when referencing the matchdata over and over. And the explicit casting I can't do much about. At least it works.
<kevinsjoberg>
If you see improvements I'd love to hear it. π
<yxhuvud>
Why are you bothering to create a class?
<kevinsjoberg>
Does it matter? I'm more concerned about the implementation. I'm aware I could just have methods in the global object. I will probably clean up a bit later, I'll have each day wrapped in a module instead, and then a class for more complicated problems.
<kevinsjoberg>
Ignore that for now. π
<raz>
hm hm, one thing that i always find an eyesore (in many languages) are the constant `hash["foobar"]` references. it's annoying to read and write. that's one of the few things i like about js, where you can often just say `hash.foobar`. i wonder if sth like that could be considered as syntactic sugar for crystal.
<raz>
(or more specifically i wonder: are there terrible side-effects and problems that it would cause?)
<jhass>
but still I wouldn't monkey patch, I would decorate
<FromGitter>
<naqvis> :D
<raz>
uhlala! π§
<jhass>
have a struct wrappking a Hash(String, V) and wrapping child hashes
* raz
is tempted to actually try that out and see how it goes
<raz>
i suppose it could interfere with other uses of method_missing, but other than that... hmmm.
<jhass>
record Properties(V); data : Hash(String, V) { macro method_missing(call); data[{{call.name.id.stringify}}]; end } + wrapping if the child value is a Hash(String, _) too
<jhass>
then just monkey patch Hash with def p; Properties.new(self); end; or so
<raz>
ya, i think i will try that out in one part of my codebase
<raz>
just to see whether it blows up terribly or is actually the future of crystal
<FromGitter>
<naqvis> God forbid :P
<jhass>
yeah, I have lots of semantic concerns :)
<FromGitter>
<naqvis> don't like this terribly pythonic way into crystal
<jhass>
dedicated decorator ain't so bad
<FromGitter>
<naqvis> yeah true
<FromGitter>
<naqvis> but not something cooked into language
<raz>
what are the concerns tho, i'm curious? i'm sure i'm missing something but can't think of what it is
<jhass>
because it can restrict to string keys and doesn't conflict with standard methods
<jhass>
First of all, it can only work for Hash(String|Symbol, _)
<jhass>
second it's super easy to clash with one of the tons of methods on Hash
<raz>
hmm yea... true on that
<raz>
well, i'm a simple man. i'm mostly like... instead of
<jhass>
mmh, #compare can do case insenstive full match
<FromGitter>
<bararchy> Does it use libPCRE?
<jhass>
I think it's inbuilt
<jhass>
using some unicode tables
<jhass>
#index(Regex) or .downcase.includes?(.downcase) are the other options I see
<jhass>
one or the other is probably faster depending on small vs large input
<jhass>
well, for Regex just matches?, no need for index
<FromGitter>
<bararchy> `Regex` and LibPCRE are an issue as it might not be a true string (blobs) and makes libpcre to invalid mem access. β `downcase` is risky as my input is large, and it does too many mem allocations
<FromGitter>
<bararchy> `compare` is nice, but it's `==` I want to see if `LargeString.includes?(PartialString`)
<straight-shoota>
barachy it should be easy to adapt the implementation of String#compare for this use case
MasterdonX has quit [Ping timeout: 265 seconds]
<erdnaxeli>
hi, is there any reason that the logger does not write to stderr by default?
<FromGitter>
<Blacksmoke16> it can write to whatever you want it to, but not all logs are errors
<FromGitter>
<Blacksmoke16> would be fairly easy to make something to do what you want
<straight-shoota>
I presume the question is about why the default was chosen as it is
<FromGitter>
<tenebrousedge> I think that today is a good day to use my crystal `scanf` lib
<FromGitter>
<tenebrousedge> hmm, maybe I don't need integers there though
<FromGitter>
<Blacksmoke16> id imagine stdout is more convenient when just wanting to see the output
<erdnaxeli>
yep the question was about the default
<erdnaxeli>
I know I can change it :)
<erdnaxeli>
I just surprised me that Log.info write to STDOUT
<erdnaxeli>
it just*
<straight-shoota>
Yeah, it depends on the type of application what you expect
<straight-shoota>
for a CLI app that processes streams from stdin/stdout, you would expect to stderr. But a server application would log to stdout.
<FromGitter>
<j8r> even `log.error`?
<FromGitter>
<j8r> anyway as said, it is configurable
<straight-shoota>
yes, there's no point in redirecting log events to different streams based on severity. At least not by default.
<FromGitter>
<j8r> simpler to have every log in the same place by default yes
<jhass>
on the contrary, it would easily lead to an out of order combined log
<erdnaxeli>
yes
<FromGitter>
<j8r> for example it is usually wanted for reverse proxies/ http servers. Depends of the app, indeed
<erdnaxeli>
I agree
<erdnaxeli>
btw IΒ love that crystal is simple enough to just write a 10 lines one shot script
<FromGitter>
<Blacksmoke16> i'd hope you're building the script and not just using it like bash
<erdnaxeli>
why?
<FromGitter>
<Blacksmoke16> is not as efficient since it has to recompile the script everytime
<FromGitter>
<Blacksmoke16> maybe not a big deal, but deff slower than if you built it and just used the binary
<erdnaxeli>
oh yes. But I am parsing a 300Mo CSV file, the compilation time is not significant here ^^
<erdnaxeli>
it seems that it takes 2s to compile, on a 30s job
<FromGitter>
<Blacksmoke16> fair enough, just something to keep in mind, esp for small quick scripts
<erdnaxeli>
still, it is just a one shot script, IΒ already should have deleted it :p
<erdnaxeli>
yes you're right
<raz>
yup i've done that too. i usually write these one-shots in ruby - but when the data is big they can often run with minimal changes as crystal
<FromGitter>
<RespiteSage> @Daniel-Worrall Thanks for the leaderboard!
<FromGitter>
<RespiteSage> Also, TIL that you can assign variables to the first elements of an array with `a, b = arr`. Very useful for splitting input strings in todays AoC (don't think that's a spoiler).
<FromGitter>
<j8r> or use partition
<yxhuvud>
I have no idea how that would help with todays solution. that is probably an artifact of how your particular solution works
<FromGitter>
<RespiteSage> Hm... I guess so. I just felt like `a, b = line.split(...)` was the most obvious solution for parsing.
<FromGitter>
<RespiteSage> @yxhuvud Wow, nice golfing! I'm mostly going for solving the puzzle relatively cleanly.
<yxhuvud>
I think mine is clean :D
<FromGitter>
<RespiteSage> That's fair. It's still more readable than basically any other language in that number of lines.
<FromGitter>
<RespiteSage> Not saying it isn't clean; I suspect I'm probably thinking of "clean" in different terms than you are.
<yxhuvud>
Well, AoC plays by different rules than other coding. No need to care about maintenance etc. I usually introduce slightly more structure in later tasks, but it just wasn't beneficial here.
<FromGitter>
<RespiteSage> I look forward to seeing how more experienced devs (than me) solve the later puzzles especially.
<FromGitter>
<RespiteSage> Yeah, that's true. I have to say that it's really nice not to worry about validating input.
<yxhuvud>
oh you may want to do that while error seeking. :D
<yxhuvud>
faulty assumptions about how the input works can easily break a solution.
<FromGitter>
<RespiteSage> Yeah, I misread the Part 2 as an AND instead of a XOR, so my first solution was wrong.
<FromGitter>
<RespiteSage> *OR instead of a XOR
<FromGitter>
<RespiteSage> Also, I do have to agree with you (after looking at it a bit more) that your solution is clean.
<FromGitter>
<anapsix> greetings everyone! β I've wrote some code to configure my application, but I wonder if I'm over-complicating it β The idea here is to be able to create config with defaults, or read it from file, if present. The config file can be set via environment variable `MYAPP_CONFIG`. If any of the config options are missing from file, it woulduse defaults. β Would you take a look and let me know what you think,
<FromGitter>
<j8r> also for debug, you could use `config.elasticsearch.to_yaml STDOUT`
<FromGitter>
<j8r> Also, I don't really recommend `CONFIG = Config.new`
<FromGitter>
<anapsix> > also for debug, you could use `config.elasticsearch.to_yaml STDOUT` β β ah, good point
<FromGitter>
<j8r> the constant can cause headaches in specs. a class getter could at least enabled to overwrite the class var in specs
<FromGitter>
<j8r> for example to test different confs
<FromGitter>
<j8r> also, no need to define defaults in the getters
<FromGitter>
<j8r> they are already defined in the initializer
<FromGitter>
<j8r> also, the `key: "host"` annotations can be superfluous
<FromGitter>
<Blacksmoke16> remember your SOLID principles :p
<FromGitter>
<Blacksmoke16> injecting a `Config` obj as an initializer arg would be much easier to test
<FromGitter>
<j8r> sure, but can be very annoying to pass a config object around
<FromGitter>
<anapsix> > they are already defined in the initializer β β but if I don't do it in both places (getter and initializer) I'll have a discrepancy of defaults when creating `App::Config` from file, and default when file is not readable.. wouldn't I?
<FromGitter>
<Blacksmoke16> i mean instantiate a `Config` object once, and have it be passed to the things that need config info, versus using a global const to access them
<FromGitter>
<Blacksmoke16> @j8r can be, are solutions/ways to make it less painful tho
<FromGitter>
<Blacksmoke16> like really just doing `def initialize(@config : Config = CONFIG); end` might be enough
<FromGitter>
<Blacksmoke16> use the global singleton by default, but still allows providing a mock for testing
<FromGitter>
<Blacksmoke16> sorry to be clear i mean you use that initializer for things that *USE* config, not in the Config type itself
<FromGitter>
<anapsix> ah, right β maybe I'm lazy, but using MyApp::CONFIG seems easy enough
<FromGitter>
<Blacksmoke16> sure, but gl testing that
<FromGitter>
<anapsix> we'll burn that bridge when we come to it :P
<FromGitter>
<anapsix> thank you for your input @j8r and @Blacksmoke16 β always appreciated
<FromGitter>
<anapsix> <3
MasterdonX has joined #crystal-lang
<frojnd>
Hi there. I'm using google cloud apis and return string gives me with quotes: `"foo bar"` so when I build a json with JSON.build json.field "foo" bar ... bar being "foo bar" with double quotes it end json looks like this: { "foo": "\"bar\"" } can I somehow remove first and last double quote from a string... I also noticed it escapes new lines so simetimes I see { "foo": "\"bar\"\n" }
<FromGitter>
<tenebrousedge> I guess the simple way would be `string[1..-2]` but idk about the json field stuff
<FromGitter>
<Blacksmoke16> are you sure its actually a problem and not just being escaped for printing to console?
<frojnd>
Yeah ur right
<frojnd>
I forgot I'm using jq to get the translated string from google api :/
<frojnd>
I have -r option there to get string without double quotes and hopefully without new lines
<FromGitter>
<Blacksmoke16> should use `oq` π
<frojnd>
Yeah, jq -r works like a charm
<frojnd>
Or maybe not
<oprypin>
frojnd, something isn't right there. you gotta fix it at the api level so it doesn't give you that
<frojnd>
I still have `\n` inside json
<frojnd>
Well google apis translate translates everything each char
<oprypin>
show
<frojnd>
Maybe I'm passing new lines
<oprypin>
show what you gave to it and what it have to you
<FromGitter>
<anapsix> > should use `oq` π β after discovering `oq`, I no longer use `yq`
<FromGitter>
<j8r> I don't know, as a user, I like to just download an have the thing work
yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
yxhuvud has joined #crystal-lang
<FromGitter>
<ImAHopelessDev_gitlab> what would be nice: notepad++ addon for crystal, that lists all the method names for each Class. which when clicked, goes to the method
<FromGitter>
<watzon> I want to know not who, but why anyone uses Notepad++. I mean I get it, I started with it back in the day, but I don't think I've touched it once since 2010.
<FromGitter>
<ImAHopelessDev_gitlab> notepad and notepad++ still amazing til this day, and over time with the degradation of bloatware apps, will continue to even be more amazing
<FromGitter>
<watzon> But vim
<FromGitter>
<ImAHopelessDev_gitlab> i switched from vscode to regular notepad and yielded like 500mb ram
<FromGitter>
<ImAHopelessDev_gitlab> vim good too, i guess i just haven't got into it cuz console experience is hard for me
<FromGitter>
<Blacksmoke16> i mean who really cares about 500mb...
<FromGitter>
<watzon> I'm going to try and do all of my AoC challenges with just vim. So far I have day 1 in C and day 2 in C++, both wholly with Vim.
<FromGitter>
<watzon> I'm also going for a different language each day. God help me.
<FromGitter>
<Blacksmoke16> it should be expected given one is a text editor, not an ide
<FromGitter>
<watzon> I mean whatever works, it just surprises me given how powerful and light other IDEs have become. VSCode is surprisingly lightweight for what it's made with.
<FromGitter>
<ImAHopelessDev_gitlab> @watzon doesn't' that get irritating doing it another language? or do you like the challenge of it (if it is)?
<FromGitter>
<watzon> Then again, some people still use Ed
<FromGitter>
<watzon> @ImAHopelessDev_gitlab I like the challenge. Gets me to think in different ways.
<FromGitter>
<ImAHopelessDev_gitlab> if i use another language, i'll literally get upset and a headache
<FromGitter>
<watzon> My headaches will come when I start trying to use Erlang and ADA
<FromGitter>
<watzon> Lol
<FromGitter>
<ImAHopelessDev_gitlab> yeah, nt
<FromGitter>
<ImAHopelessDev_gitlab> nty
<FromGitter>
<ImAHopelessDev_gitlab> i tried the functional language paradigm. ain't going through that again
<FromGitter>
<watzon> I like it, but at the same time I feel like some languages take it too far
<oprypin>
straight-shoota: at some point i will need some way to discover all the possible properties/types that the doc generator exposes. is there a list of all possible keys, a complete test suite or a demo project that exercises everything?
<FromGitter>
<ImAHopelessDev_gitlab> a good analogy is: i'm a right handed person and can throw a baseball with good accuracy and speed. using a functional language makes me feel like I'm on the mound in the world series and required to throw with my left hand.
<FromGitter>
<ImAHopelessDev_gitlab> and i've spent my entire life/childhood learning how to throw with my right hand, then i have to switch? WTFF
<oprypin>
isnt it just a question of applying json::serializable
<oprypin>
nvm just need to read the issue
<straight-shoota>
just JSON::Serializable would be poor for an external API
<straight-shoota>
the compilers internal data structures (ASTNodes etc.) are too much focused on code details and the decorators used by the docs generator are too much focused on HTML
<straight-shoota>
export data needs something in between
<straight-shoota>
abstracted enough but not specifc to HTML output generation
<FromGitter>
<Blacksmoke16> anyone else getting achievements on the forums for things they didnt actually do?
<FromGitter>
<Blacksmoke16> when reading external docs, and the docs reference a type. Do you think its nice to have that type linked to the API docs. Or i guess what im really thinking is should *every* usage be linked, or is that a bit much?
<FromGitter>
<Blacksmoke16> or maybe link the first usage in a paragraph/section, then just backtick the other ones?
<FromGitter>
<ImAHopelessDev_gitlab> @RespiteSage i fixed it locally but basically fiddled around with dev tools and css properties. something to do with position: sticky and z-index
<FromGitter>
<3n-k1> @Blacksmoke16 i know several times now i've seen a type i wanted info on and didn't know what module it was in
<FromGitter>
<Blacksmoke16> fair enough, my as well just link them all then
<FromGitter>
<Blacksmoke16> doesnt hurt anything
postmodern has joined #crystal-lang
<FromGitter>
<ImAHopelessDev_gitlab> rofl wow this bug
<FromGitter>
<ImAHopelessDev_gitlab> i kept thinking why my monsters all had 0 HP, monster_level was going to `0` ROFL
<FromGitter>
<Blacksmoke16> Hm?
<FromGitter>
<Blacksmoke16> Ah
<FromGitter>
<Blacksmoke16> What's with all the to_i calls
<FromGitter>
<ImAHopelessDev_gitlab> when i was adding the new parameter `main_mob_ids`, i misclicked to add the comma and hit backspace, this removed the letter `l` from monster_level. no idea how that happened
<FromGitter>
<ImAHopelessDev_gitlab> from an exported json file. it only happens once at startup, so no worries
<FromGitter>
<ImAHopelessDev_gitlab> i just use json.parse as an abstraction layer so i can statically type my classes
<FromGitter>
<ImAHopelessDev_gitlab> the exported json file is from adminer.php (which is connected to my local mysql db). so the output on some of the values is a PITA to deal with. that's why it looks messy
<FromGitter>
<Blacksmoke16> Why not just use from json
<FromGitter>
<Blacksmoke16> include a module, literally nothing else to do
<FromGitter>
<ImAHopelessDev_gitlab> example, this field. it's an array of int32s. but it's exported as a string. so it needs to be converted to it, only if size > 0. or just 0 (int32) if the string is empty
<FromGitter>
<Blacksmoke16> use a converter
<FromGitter>
<ImAHopelessDev_gitlab> and if delimited by `;`, it has to be split by `;`, etc
<FromGitter>
<ImAHopelessDev_gitlab> iuno i tried that before but raged
<FromGitter>
<Blacksmoke16> but real question is, why are you storing an array of values separated by a `;`?
<FromGitter>
<ImAHopelessDev_gitlab> because i edit all my game data in a database with adminer.php
<FromGitter>
<Blacksmoke16> wouldnt it make more sense to use like a `JSON` column, or a mapping table or something?
<FromGitter>
<ImAHopelessDev_gitlab> iuno
<FromGitter>
<ImAHopelessDev_gitlab> i have a large Monsters hash that is used, when that monster id is read from the level
<FromGitter>
<ImAHopelessDev_gitlab> so it maps,y es
<FromGitter>
<ImAHopelessDev_gitlab> if main_monster = Monsters[monster_id]?
<FromGitter>
<Blacksmoke16> mk
<FromGitter>
<Blacksmoke16> i feel like most of your problems are self inflicted :p