<havenwood>
mememeIAMMEE: ^ it's a pattern for zero as the default value for an undefined key
<havenwood>
mememeIAMMEE: the same for an Array isn't what people usually want, Hash.new([])
<havenwood>
mememeIAMMEE: because that Array is the value for *every* key, that exact Array, not a new one for each missing key
za1b1tsu has quit [Ping timeout: 246 seconds]
<havenwood>
this makes a *fresh* Array for each default key value: Hash.new { |h, k| h[k] = [] }
<havenwood>
mememeIAMMEE: But yeah, you don't have to use default Hash values. You can just ensure they're something there before shoveling if you prefer..
<havenwood>
{}[:no_default] #=> nil
<havenwood>
{}[:no_default] += 1 #!> ERROR
<havenwood>
Hash.new(0)[:default] += 1 #=> 1
<havenwood>
mememeIAMMEE: make sense?
chouhoulis has quit [Ping timeout: 245 seconds]
chouhoulis has joined #ruby
<mememeIAMMEE>
Um
<mememeIAMMEE>
Kind of but
<mememeIAMMEE>
does Hash.new { |h, k| h[k] = [] } not create a lot of empty keys?
SeepingN has quit [Quit: The system is going down for reboot NOW!]
<Yxhuvud>
not me. the more experience I get with grape the more I prefer pure rails
RougeR has quit [Ping timeout: 252 seconds]
ciro has quit [Quit: WeeChat 2.2]
<jammanbo>
I think I just figured it out. The formatters are defined per endpoint *I think*, so you can just `present` your object and if you've defined both a :json and a :html formatter, the appropriate one will be used.
elphe has joined #ruby
<jammanbo>
But, yes I agree, Rails API looks increasingly like it would have been the better choice.
<jammanbo>
I feel bad for saying that. Grape is great. Lots of love to the developers. It's just a steep curve.
elphe has quit [Ping timeout: 246 seconds]
paraxial has joined #ruby
bhaak has quit [Ping timeout: 245 seconds]
za1b1tsu has quit [Ping timeout: 245 seconds]
za1b1tsu has joined #ruby
RougeR has joined #ruby
Cork has quit [Ping timeout: 252 seconds]
Cork has joined #ruby
za1b1tsu has quit [Ping timeout: 252 seconds]
elphe has joined #ruby
elphe has quit [Ping timeout: 252 seconds]
Sina_ is now known as Sina
za1b1tsu has joined #ruby
marz_d`ghostman has quit [Ping timeout: 246 seconds]
cpruitt has joined #ruby
elphe has joined #ruby
cpruitt has quit [Ping timeout: 250 seconds]
elphe has quit [Ping timeout: 252 seconds]
cpruitt has joined #ruby
<leitz>
Don't feel bad; accept that some tools are better for some jobs. We all have picked up the wrong tool at times. Like Perl. :P
cpruitt has quit [Ping timeout: 244 seconds]
RougeR has quit [Ping timeout: 264 seconds]
cpruitt has joined #ruby
aufi_ has joined #ruby
cpruitt has quit [Ping timeout: 240 seconds]
aufi has quit [Ping timeout: 264 seconds]
cpruitt has joined #ruby
cpruitt has quit [Remote host closed the connection]
vqrs has quit [Ping timeout: 240 seconds]
cpruitt has joined #ruby
thejs has joined #ruby
RougeR has joined #ruby
bmurt has joined #ruby
vqrs has joined #ruby
jammanbo has quit [Quit: Page closed]
AndreYuhai has joined #ruby
thy0 has joined #ruby
<AndreYuhai>
Hello, does an instance object get garbage collected when I assign something else to the same variable which was holding the referred object before? Or how does this works? Any sources?
apeiros has joined #ruby
apeiros__ has joined #ruby
snickers has quit [Ping timeout: 252 seconds]
apeiros has quit [Ping timeout: 240 seconds]
<tbuehlmann>
AndreYuhai: yup, it gets GCed if it's not referenced anymore
<AndreYuhai>
tbuehlmann: Thank you. ^^ I was wondering whether it would take so much memory because I instantiate an object a lot of times but always assigning it to the same variable.
<ruby[bot]>
al2o3-cr: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
<al2o3-cr>
#=> #<RangeError: 0x00002adc74b53558 is recycled object>
<AndreYuhai>
al2o3-cr: well looks like we don't even need to call it. I guess?
<al2o3-cr>
not really.
ua_ has joined #ruby
<AndreYuhai>
al2o3-cr: Thank you for the example. :)
<al2o3-cr>
AndreYuhai: np ;)
elphe has joined #ruby
simmaniac has joined #ruby
sysvalve has quit [Ping timeout: 245 seconds]
bmurt has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
dionysus69 has quit [Quit: ZNC 1.7.1+deb2 - https://znc.in]
elphe has quit [Ping timeout: 252 seconds]
levifig has quit [Ping timeout: 272 seconds]
audy has quit [Ping timeout: 272 seconds]
noodle has quit [Quit: /quit]
RougeR has quit [Ping timeout: 272 seconds]
ChrisBr has quit [Ping timeout: 272 seconds]
sticaz has quit [Ping timeout: 272 seconds]
sagax has quit [Ping timeout: 272 seconds]
Sp4rKy has quit [Ping timeout: 272 seconds]
sticaz has joined #ruby
RougeR has joined #ruby
ChrisBr has joined #ruby
leafyleong has joined #ruby
Sp4rKy has joined #ruby
bmurt has joined #ruby
asphyxia has quit [Ping timeout: 272 seconds]
noodle has joined #ruby
sysvalve has joined #ruby
redlegion has quit [Quit: Fuck this, I'm out.]
elphe has joined #ruby
simmaniac has quit [Ping timeout: 240 seconds]
DarthGandalf has quit [Ping timeout: 240 seconds]
Rapture has joined #ruby
DarthGandalf has joined #ruby
amelliaa has joined #ruby
<apeiros__>
AndreYuhai: to elaborate a bit on tbuehlmann's response: it *can* get GCed from the moment it is not referenced anymore. but how immediate that is depends on a number of factors. that's also why finalizers are usually a bad idea.
apeiros__ is now known as apeiros
ZzZombo has joined #ruby
<AndreYuhai>
apeiros: What factors for example?
maufart__ has joined #ruby
<apeiros>
depends on the gc, and I'm not fully up to date with ruby's progress on its mark & sweep gc
<apeiros>
but f.ex. it's afaik split in young and old generations
aufi_ has quit [Ping timeout: 246 seconds]
<havenwood>
tricolor now!
<apeiros>
so an object which existed for a long time already will take longer to be actually collected
discopatrick has joined #ruby
<apeiros>
hah, good, I see I can just refer to havenwood for this :)
<apeiros>
havenwood: tricolor? so they can't use a "simple" bitmap field anymore for marking?
<apeiros>
that's the one optimization I remember well since that allowed *nix' COW fork to work in a meaningful way :)
<apeiros>
I also seem to remember something like "arenas" being used for the implementation of the generations?
* apeiros
notices that he's reeeeally fuzzy by now on how ruby 2.5 or even 2.6's gc actually works :-(
<havenwood>
apeiros: trying to find a good writeup, because i don't recall the details
graphene has quit [Remote host closed the connection]
<blood>
when using system, the same issue occurs
lxsameer has quit [Ping timeout: 272 seconds]
graphene has joined #ruby
eckhardt has joined #ruby
apeiros has quit [Remote host closed the connection]
lxsameer has joined #ruby
<NL3limin4t0r>
blood: Is log.txt created? If the file is made by you try to remove it and run the script again to ensure that it at least can locate/create the file.
jdawgaz has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<blood>
NL3limin4t0r: if i move the write line before the call to my cmd, it creates it
jdawgaz has joined #ruby
<blood>
for some reason calling the cmd just gets stuck there and never returns
lxsameer has quit [Ping timeout: 272 seconds]
resnik2 has joined #ruby
graphene has quit [Remote host closed the connection]
<ruby[bot]>
resnik2: I'm terribly sorry, I could not evaluate your code because of an error: NoMethodError:undefined method `[]' for nil:NilClass
graphene has joined #ruby
<resnik2>
Can anyone tell me why there isn't a race condition on +=?
duderonomy has joined #ruby
<baweaver>
resnik2
<baweaver>
gah, enter key
<resnik2>
good answer.
<baweaver>
So....
<baweaver>
How far down that rabbit hole do you want? :D
chouhoulis has quit [Remote host closed the connection]
<resnik2>
I don't understand why the timer thread doesn't kick in and suspend the currently running thread
lxsameer has joined #ruby
apeiros has joined #ruby
<NL3limin4t0r>
blood: Does your console command return when ran in a standard cmd terminal?
<baweaver>
Because the very succinct answer is Associative operations
<baweaver>
1 + 2 + 3 == 1 + (2 + 3). You could apply them in any order
kwerle has joined #ruby
<baweaver>
It's distributable as well because of the presence of an empty value, known as identity, defined by a type and a binary operation.
kwerle has quit [Client Quit]
<baweaver>
Or, more simply, plus and 0
<resnik2>
baweaver, are you replying to me?
<baweaver>
0 + 1 == 1 + 0 == 1
<baweaver>
You asked why there isn't a race condition
furrymcgee has joined #ruby
<blood>
NL3limin4t0r: good point it does not. However, the cmd is never being executed as it should be writing to another log file indicating it is running. If i execute the cmd manually, the log is updated as expected.
<resnik2>
yes, I asked why the native thread doesn't switch to the other ruby thread in the middle of retrieaval / set operation
<blood>
basically the cmd starts a weblogic process and eventually enters a running state
<resnik2>
in MRI, obviously.
<baweaver>
Technically there is a race condition, but because plus behaves in an associative manner you're not going to notice it
<baweaver>
Try it with - or /
nfk has joined #ruby
<baweaver>
No matter what order you add or multiply numbers in, you'll get the same result
lxsameer has quit [Ping timeout: 244 seconds]
apeiros has quit [Ping timeout: 264 seconds]
<baweaver>
If you want to see the order execution, use the block arg for times and output that.
<baweaver>
@n = 0; 20.times.map { |t| p t; Thread.start { 10000.times { @n += 1 } }; p t }.each(&:join); puts @n
<nfk>
tk's virtual event handling is driving me up the wall with the absolute lack of ruby specific documentation and none of tcl or python results i can google being of much use
chouhoulis has joined #ruby
apeiros has joined #ruby
<resnik2>
I think I'm not getting it. Thread #1 -> GET(@n) -> 0 -> +1 <CONTEXT SWITCH> -> SET @n=1. Thread#2 -> GET(@n) -> 0 -> +1 -> SET @n=1. <CONTEXT SWITCH>
elphe has joined #ruby
<resnik2>
already lost 1
<nfk>
i got to the point of being able to call the handler (which is a bit ugly but whatever) but then the program gets a TypeError of all things...
<NL3limin4t0r>
blood: Hmm, that's strange. Are you sure you point to the right direction? You could test if using backticks instead of using Open3 helps.
<NL3limin4t0r>
eg. result = `your cmd command here`
lxsameer has joined #ruby
<blood>
I just tried executing 'dir' and same result
<blood>
ok let me try that
<NL3limin4t0r>
You might need to escape backslashes
<NL3limin4t0r>
I'm guessing the command is send to a mingw32 shell instead.
<resnik2>
it seems the answer is NEVER on mri.
vutral|kali has joined #ruby
<nfk>
is it just me or virtual event in ruby/tk handling is not working as it's supposed to?
<apeiros>
it's quite possible that newer rubies don't schedule other threads between +=/-= in certain cases (e.g. numeric receiver), in that case you'd indeed not have a race condition.
<nfk>
*virtual event handling
lxsameer has joined #ruby
dellavg_ has joined #ruby
<apeiros>
but relying on that would be relying on an implementation detail. the code is not correct.
eckhardt has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
lxsameer has quit [Ping timeout: 252 seconds]
<NL3limin4t0r>
I once read an article somewhere about this exact issue, comparing MRI and JRuby. However I currently can't seem to find it.
lxsameer has joined #ruby
<NL3limin4t0r>
Point is that the code breaks when running it in JRuby if you coun't on it being thread safe (which it obviously isn't).
<NL3limin4t0r>
count*
nowhere_man has quit [Ping timeout: 252 seconds]
<resnik2>
apeiros, yeah, something's strange going on there, but it also works fine on 1.9, so I guess something's tricky with ruby scheduler. The whole thing popped up when I was conducting Mutex#synchronize benchmarks.
VeryBewitching has joined #ruby
lxsameer has quit [Ping timeout: 240 seconds]
<resnik2>
And those were needed because somehow I've got a feeling hiredis is doing bad job of multithreading in mri
<VeryBewitching>
Hey folks, I'm trying to find a way to undefine a method in a module, not really getting anywhere; in a test environment I'd like the Service method redefined, how would I go about removing the original? https://gist.github.com/bewitchingme/3e7a75e05dc5a57641908c47567572c7
tdy has joined #ruby
<VeryBewitching>
Oddly, simply redefining it has no effect to the test, it simply uses the original definition
cd has joined #ruby
<blood>
NL3limin4t0r: so i got it installed but it doesn't seem to be doing anything
<VeryBewitching>
I've tried undef_method and remove_method in the module, to no effect.
<NL3limin4t0r>
blood: You should be able to call `byebug` inside your script to set a breakpoint you can build ruby logic around it if you want `byebug if false` will never break your code.
<NL3limin4t0r>
The most important commants are `c` to continue until the next break point, `n` to execute the next statement and `s` to step into a method of the current line.
thejs has quit [Ping timeout: 250 seconds]
<NL3limin4t0r>
and obviously `exit` and `help`
<blood>
so running `c` in byebug will go to next `byebug` command i have in my rb file?
<blood>
byebug creates a breakpoint ?
<NL3limin4t0r>
yep
<blood>
ok when i use `c` it just runs for a few more seconds then exits