gheegh has quit [Remote host closed the connection]
* phaul
is thinking maybe when there is an error we should just let it die and spill the error on stderr instead of the extra work to move it over to stdout. And we should report back stderr.
s3nd1v0g1us has joined #ruby
clemens3 has joined #ruby
s3nd1v0g1us has quit [Client Quit]
clemens3_ has quit [Ping timeout: 268 seconds]
<c-c>
phaul so you type command but it won't show errors in the console?
<ntt>
Hi, I'd like to extract all values from an Hash with a predefined key. The hash is composed by other hash. Example: h = { :node1 => { :ip => 1.2.3.4, ....}, :node2 => { :ip = 2.3.4.5,...}, ...} , how can I extral all "ip" values in an Array?
<baweaver>
What have you tried?
<ntt>
flatten
<ntt>
but it seems I need to know the "level"
<baweaver>
Do you know how map works?
clemens3 has joined #ruby
<ntt>
nope... But i'm going to read the doc. is this the right way to do whis?
<baweaver>
&>> [1, 2, 3].map { |v| v * 2 } # Map makes a new list by transforming elements using a function, in this case doubling each number
laaron has quit [Remote host closed the connection]
<baweaver>
Could be
<baweaver>
or perhaps we're not
<baweaver>
You'll have more luck leading with your question though :)
cgfbee has joined #ruby
nowhere_man has quit [Ping timeout: 258 seconds]
nakuku has quit [Ping timeout: 245 seconds]
<ntt>
baweaver: thank you. I'm reading the doc. I do not understand if there is the possibility to traverse a very complex Hash reading the value of only one key (in my case "ipaddress") without using map on each sub-hash
<baweaver>
ntt: Do you only want the IP?
<ntt>
yes
<ntt>
but the Hash is very complex, with multiple Hash inseide
<ntt>
iside
<ntt>
*
<baweaver>
That's not really too complex.
<baweaver>
Break it down a bit, you have a hash with nested hashes
<baweaver>
the key is the name of the node, and the value is its configuration
<ntt>
yes
<ntt>
but should I use map on each value?
<baweaver>
So when using map, ask the configuration what the IP is
<baweaver>
Why?
<baweaver>
It's a hash, how do you get a single value from a hash?
<ntt>
ok... just a moment... I'll give you a more complex example
<ntt>
wow... ok. I'll give a try. Really thank you
<baweaver>
Traces basically go down through a hash until it can finally find a key that matches
<baweaver>
or key and value, but that's a different thing.
<ntt>
sure. I'm reading documentation on your github repo
<ntt>
it works :) thank you
<baweaver>
The two articles up top explain how it works
teclator has quit [Remote host closed the connection]
<ntt>
I think it's a good idea pass only environment[:nodes] instead the complete hash. This can reduce the complexity and cpu cycles
<baweaver>
Yeah, trace is slow-ish because of how it works
<baweaver>
Though to be fair it won't matter unless you have something like 10k nodes or more
<baweaver>
and even then, maybe a quarter second
<ntt>
ok... but I'd like to use best-practices in my code if possible
<baweaver>
The answer to what's the best way to do something is: it depends
mikecmpbll has joined #ruby
<baweaver>
Now if there were a way to potentially know what those paths are you could use dig instead.
<ntt>
unfortunately the only information I have is that I have to search in environment[:nodes] (instead of the complete hash)
<ntt>
but the number of nodes is small (around 30)
<baweaver>
but my advice for sysadmin type tasks: optimize for writing time, not runtime, until it becomes an actual issue.
V1s1ble has joined #ruby
<V1s1ble>
I'm trying to figure out how to map through dictionary and only produce one dict with lists of sub values: https://bpaste.net/show/c2fc6656e374
<baweaver>
for 30 nodes the time difference is non-existent
<V1s1ble>
The tricky part is merging the values/lists...
<baweaver>
So merge based on similar keys?
<al2o3-cr>
ntt: for that example in plain ruby; h[:nodes].map { |k,v| v.values }.map { |ipaddress:, **| ipaddress }
<phaul>
it's fine. but why store something that holds cells inside Entry instead. Like Array or Hash. Probably Array. and then just index []
<phaul>
simpler loop would be ('@' .. 'AL').each do |col_letter| ...
<ryouba>
phaul: because the cell values are only my input. i plan on adding some methods inside of the Entry class that do stuff with those cell values and produce the output. not sure about the name 'Entry' yet...
conta has quit [Ping timeout: 255 seconds]
<ryouba>
wow, nice! thank you for that loop! i didn't think it'd work like that, too. i still feel like it's advanced magic anyways (that it knows to wrap from Z to AA)
ixti has joined #ruby
marmotini_ has quit [Ping timeout: 245 seconds]
v01d4lph4 has quit [Remote host closed the connection]
<hightower2>
Hey folks how would I produce a pointer to a function? E.g. I have an instance method myobj.something() and I want to pass 'something' around like I would pass a block
<phaul>
myobj.method(:something)
<barg>
was pry invented in between the two? so, byebug then pry then pry-byebug?
<hightower2>
phaul, fabulous, thanks!
<hightower2>
just brilliant
v01d4lph4 has quit [Ping timeout: 250 seconds]
<havenwood>
barg: you can just check the repos, but the order of invention should be pry, byebug, pry-byebug. there were other debuggers for earlier versions of Ruby.
sylario has joined #ruby
<barg>
where does a repo gvie away the date of creation?
<havenwood>
barg: just look at the first commit
<havenwood>
they have dates
gnufied has joined #ruby
Xeago_ has joined #ruby
Xeago has quit [Ping timeout: 250 seconds]
Xeago_ is now known as Xeago
bijan_ has quit [Remote host closed the connection]
<leftylink>
I wanted to demonstrate waiting on IO (and therefore still benefitting from threads in the presence of the GVL) with `sleep 5` but it turns out Kernel.sleep also qualifies
<phaul>
ah. ok. I misunderstood you point nm
ravenous_ has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<ruby[bot]>
jmosco: we in #ruby do not like pastebin.com, it loads slowly for most, has ads which are distracting and has terrible formatting. Please use https://gist.github.com
ged has quit [Read error: Connection reset by peer]
ged_ has joined #ruby
<leftylink>
jmosco: note that when I do `zsh -c "echo $'\u2388 '"` I get a snowflake-like symbol, whereas if I do `env LC_CTYPE=C zsh -c 'echo $"\u2388"'` , I get "zsh:1: character not in range". You may wish to check whether that environment variable (or any of the related environment variables) are set as you expect them to be
<leftylink>
where "the related environment variables" are I assume the ones output by `locale` command
bruul has quit [Ping timeout: 272 seconds]
bruul has joined #ruby
Fernando-Basso has joined #ruby
ged_ is now known as ged
mahlon has quit [Ping timeout: 272 seconds]
<lunarkitty>
I'm curious, are there any new gui gems that have potential?
tdy2 has joined #ruby
spacesuitdiver has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
v01d4lph4 has joined #ruby
mahlon has joined #ruby
v01d4lph4 has quit [Ping timeout: 245 seconds]
conta has joined #ruby
spacesuitdiver has joined #ruby
hahuang65 has joined #ruby
<jmosco>
hmm
<jmosco>
al2o3-cr: same error
gnufied has quit [Remote host closed the connection]
<ruby[bot]>
naeemarsalan: we in #ruby do not like pastebin.com, it loads slowly for most, has ads which are distracting and has terrible formatting. Please use https://gist.github.com
<phaul>
ignore that for now I'll look at pastebin
<phaul>
ah. I get what's happening
<naeemarsalan>
thanks its a very silly attempt but im kinda of ideas...
<naeemarsalan>
just nudge me in the right direction :P
<phaul>
so. when the API returns an object that doesn't define a nice inspect method ruby default's it to the string with the class name and memory/address/object_id thingy
<naeemarsalan>
right okay, would i have to define inspect in the api and then i will be able to get the values as normal json most likely?
jaddison has quit [Quit: jaddison]
<phaul>
no. Have you tried calling get on it?
tdy2 has joined #ruby
doitliao has quit [Ping timeout: 244 seconds]
<naeemarsalan>
how would i do that?
<naeemarsalan>
how would i even set that as a class?
ellcs has quit [Ping timeout: 264 seconds]
<phaul>
something returned the object that when printed looked like <Oxidized::Node::Stats:0x00000001dcc228>. That object can receive a get (according to the docs). Then it will return a hash.
<naeemarsalan>
oh one sec
fluxAeon has quit [Ping timeout: 246 seconds]
Swyper has joined #ruby
naeemarsalan has quit [Ping timeout: 256 seconds]
Swyper has quit [Ping timeout: 244 seconds]
naeemarsalan has joined #ruby
<naeemarsalan>
Well i tried a few combination and nothing, so its http://url/nodes/stats.json returns an array like { "NodeName" : "#<Oxidized::Node::Stats:0x00000001dcc228>", ....}
fluxAeon has joined #ruby
<Radar>
naeemarsalan: Can we see some code that will cause this same issue to happen on our machines?