WishBoy has quit [Remote host closed the connection]
kiyote23 has quit [Ping timeout: 244 seconds]
ta_ has joined #ruby-lang
stardiviner has quit [Ping timeout: 245 seconds]
benlovell has joined #ruby-lang
kapil__ has joined #ruby-lang
fclausen has quit [Ping timeout: 272 seconds]
ta_ has quit [Ping timeout: 265 seconds]
skade has quit [Quit: Computer has gone to sleep.]
tmi1 has joined #ruby-lang
tkuchiki has joined #ruby-lang
loincloth has joined #ruby-lang
banister has quit [Read error: Connection reset by peer]
loincloth has quit [Ping timeout: 264 seconds]
postmodern has quit [Quit: Leaving]
rahul_j has quit [Quit: rahul_j]
rahul_j has joined #ruby-lang
tkuchiki has quit [Remote host closed the connection]
tkuchiki has joined #ruby-lang
stardiviner has joined #ruby-lang
ur5us has joined #ruby-lang
tobiassvn has joined #ruby-lang
saramic has quit [Remote host closed the connection]
stardiviner has quit [Ping timeout: 240 seconds]
ur5us has quit [Ping timeout: 245 seconds]
arBmind1 has quit [Quit: Leaving.]
shazaum has joined #ruby-lang
tobiassvn has quit [Ping timeout: 276 seconds]
DEac- has quit [Ping timeout: 250 seconds]
DEac- has joined #ruby-lang
tmi1 has quit [Quit: Leaving.]
<yorickpeterse>
<3 pg window functions
<yorickpeterse>
all this crappy Ruby code used for calculating percentages can be removed \0/
<tbuehlmann>
\o/
<ljarvis>
less rants?
<ljarvis>
haha just kidding
<ljarvis>
unpossible
<tbuehlmann>
will be pg window function rants then
Forgetful_Lion has quit [Remote host closed the connection]
arBmind has joined #ruby-lang
<yorickpeterse>
Actually I have nothing bad to say about window functions so far
<yorickpeterse>
What does frighten me is that the more I see this code, the more I'm scared how this ever worked as a whole
<yorickpeterse>
There are so many small, recurring patterns that really make you wonder if people were coding with their asses instead of their brains
stardiviner has joined #ruby-lang
seank_ has quit []
chills42 has joined #ruby-lang
seank_ has joined #ruby-lang
skade has joined #ruby-lang
pepperbreath has quit [Quit: Leaving.]
rahul_j has quit [Quit: rahul_j]
<ljarvis>
if i could code with my ass, i would be rich
vondruch has quit [Ping timeout: 272 seconds]
vondruch has joined #ruby-lang
workmad3 has quit [Ping timeout: 265 seconds]
<maloik>
why is that? I wouldn't pay to see it...
<ljarvis>
well that's because i haven't marketted it, so you're not drawn in
<maloik>
yea I really don't think there's much you could do to sell that to me :P
<ljarvis>
ohhh if only i had an ass that could type. You would see
TrebleChef has joined #ruby-lang
<TrebleChef>
I cant seem to get my head around block variables, I have read many of the tutorials, but they all seems lacking in some element. I just don't understand how the block variable can be called before it is declared. Any help would be much appreciated
<maloik>
better start practicing
<maloik>
called before it's declared? what makes you think that's the case?
rahul_j has joined #ruby-lang
<TrebleChef>
it is my understanding that the block variable is whats between the pipes like |variable|
<maloik>
gist an example of code you don't get :-)
<maloik>
in an example like my_array.each do |block_var|; ... ; end; the block_var is a variable containing one element of your array upon each iteration
<maloik>
it's similar to "for each item in my_array..." that you'll find in a lot of other languages
<TrebleChef>
right, and that seems to make sense to me, just as in any for each loop
<maloik>
well that works in ruby as well, it's just not used a whole lot
<TrebleChef>
I get your example maloik, I just don't get the one on the page ii referenced
<ljarvis>
TrebleChef: the second example should explain what's happening
<TrebleChef>
the block variable is |http| and if you change it, the entire thing breaks, which means it is referencing the "http" below it... not above
<TrebleChef>
this is where my head asplodes
<ljarvis>
no
<ljarvis>
TrebleChef: that http variable is not the same one as below
<ljarvis>
wait, i thought you meant outside the block
<TrebleChef>
then how come if I change it, the code breaks? in any foreach loop, the name shouldn't matter
<ljarvis>
TrebleChef: does my second example not make sense?
<maloik>
TrebleChef: did you change the name of the variable as well as the place the variable is being used in the line underneath it?
<TrebleChef>
yes, the link you posted at eval.in makes sense... I get it in when used as a foreach
<TrebleChef>
yes, if I change it in BOTH places it works..
<ljarvis>
right... the second example
<ljarvis>
the one that actually explains how it works
vondruch has quit [Quit: Ex-Chat]
<TrebleChef>
so, my lack of understanding is, apparently http is set equal to "print( http.get( '/en/about/license.txt' ).body )" after I have declared it in |http|
vondruch has joined #ruby-lang
<maloik>
no, not at all
<TrebleChef>
but ina foreach loop, its assigned it 1 at a time first...
<ljarvis>
no
<ljarvis>
my second example really clears this up...
<maloik>
forget the each loop for a minute, take a good look at that other example
<ljarvis>
TrebleChef: the `do |...| ..` stuff is a block, something that is technically owned by the method. So the method can call it, with any variables it likes
Lewix has joined #ruby-lang
Lewix has joined #ruby-lang
<ljarvis>
so in my example, 'http' is the value on line 10 (an instance of HTTP). It's only available during this block
donove has joined #ruby-lang
donove has joined #ruby-lang
<ljarvis>
you can name it whatever you want. In this case, we've named this value 'http'
<TrebleChef>
"you can name it whatever you want"..... well if I rename it from |http| to |dog| it does not work...
<TrebleChef>
so where is the hook link between the word http and what it is referencing on line 10?
<ljarvis>
sure it does, you just need to update your references to use the 'dog' variable, and not the non-existant 'http' variable
<TrebleChef>
there is something fundamental I am missing..
<TrebleChef>
refernces on line 10?
<ljarvis>
TrebleChef: that value is being assigned to 'http' implicitly
<TrebleChef>
so sometimes bloack variables are the iterative individual elements like in a typically for-each loop (to me this is most intuitive). Other times, like in your example it wiil be the output or product on a stanza of code (this is where I struggle)... But I think I am getting it.
<[spoiler]>
also make sure you check for the existence of a block in case your method modifies things *before* block is passed.
<ljarvis>
TrebleChef: do you use any other languages?
<[spoiler]>
yeah but if your `puts "called run()"` was something that modified stuff on the fs, or otherwise, it wouldn't be pleasant
<TrebleChef>
I think I am struggling with the versatility of ruby, perhaps...
<ljarvis>
TrebleChef: do you know of the concept of passing functions as arguments?
loincloth has joined #ruby-lang
konr has joined #ruby-lang
<TrebleChef>
loosely...
<ljarvis>
ok we won't go down that road as it might get more confusing
<TrebleChef>
I really appreciate all the help
loincloth has quit [Ping timeout: 245 seconds]
<TrebleChef>
so the move data between pipes in pwoershell we use the "$_" which is whatever the last bit of code yeilded
malconis has joined #ruby-lang
malconis has quit [Remote host closed the connection]
malconis has joined #ruby-lang
rahul_j has quit [Quit: rahul_j]
workmad3 has joined #ruby-lang
<TrebleChef>
its starting to seem to me like in ruby, you can name it whatever you like, such as, |whatever| , where whatever is either the individual iterative element, or the product of the previous piece bit of code. In the manner you can use additional code in some manner.
<ljarvis>
yeah that's unfortunately unrelated. Does this javascript code make sense? https://eval.in/239859
revath has quit [Ping timeout: 244 seconds]
dabradley has joined #ruby-lang
<TrebleChef>
yes
<ljarvis>
ok so, this is possible because javascript has first class functions. In this case, 'x' is a function. Ruby does not, so it gets around that with a new syntax for passing blocks to methods. The same code in Ruby is https://eval.in/239860
g0bl1n has joined #ruby-lang
<ljarvis>
so, instead of passing a method as an argument and then calling it in "do_x", we use a block. We then call that block with the yield keyword, passing the argument "foo"
<TrebleChef>
okay, this is what I was looking for. I need to digest.
<TrebleChef>
i cant believe i found someone able to understand that i didn't want to know what to do, but why I was doing it...
<TrebleChef>
its starting to sink in
<workmad3>
you can also pass lambdas and procs to methods in ruby (and also request a Method object and pass that)... leading to this code that is closer to the JS example ljarvis gave, but not particularly idiomatic ruby most of the time: https://gist.github.com/workmad3/c182ef09b3059bae72de
<ljarvis>
dude
brooks has joined #ruby-lang
<ljarvis>
i was specifically trying to avoid talking about procs and lambdas :)
<[spoiler]>
lambda and Proc might be overkill for now, let's stick to blocks. :-)
<TrebleChef>
hahaha, yes
<workmad3>
heh :) ok
* maloik
gets out the mop to clean up bits of brain
<ljarvis>
that was actually my next entry (capturing the block)
ur5us has joined #ruby-lang
<TrebleChef>
next time you see someone like me here, try sending them to what i just linked. it explains what you just did, and you might save some keystrokes.
matp_ has joined #ruby-lang
<workmad3>
TrebleChef: my experience with explaining blocks/procs/lambdas to newcomers to ruby is that explanations need to change quite a bit depending on which bit of common reference you can find with the newcomer :)
<[spoiler]>
`Any return statements used in a Proc will also return from the method that called that Proc.` doesn't this throw a local jump error instead?
<[spoiler]>
well raise
<TrebleChef>
also, i just realized because i work with powershell, which DOES use first class functions it was making this harder to learn
<workmad3>
[spoiler]: depends on whether that context has finished or not
<ljarvis>
yeah more languages are less like ruby with this stuff
<workmad3>
[spoiler]: ok... now modify it to return -1 if nothing is found ;)
<[spoiler]>
also, if you desperately want a return just use a lambda
<workmad3>
[spoiler]: or otherwise execute some code after the find, only if nothing was found
<[spoiler]>
yeah
jgpawletko has joined #ruby-lang
<workmad3>
[spoiler]: tbh, I can't recall ever making any use of that behaviour in blocks/procs explicitly, mainly because Enumerable is so good in ruby
<workmad3>
[spoiler]: and due to the habit in ruby of avoiding explicit returns :)
enebo has joined #ruby-lang
rcvalle has joined #ruby-lang
<workmad3>
[spoiler]: but afaik, the rationale for that behaviour in procs/blocks is so that constructs like .each behave more like a normal for loop
emmesswhy has joined #ruby-lang
<[spoiler]>
Oh right. I get the reasoning behind it. I still find it awkward to use, personally
<maloik>
sorry to be putting this here people, but #ror is being its usual helpful self... we have a view that takes forever to render, what tools can you recommend to profile the page and benchmark any possible fixes?
<brocktimus>
maloik: stackprof if you're on MRI >= 2.1
<yorickpeterse>
I never had much success with stackprof and the newer MRI 2.1 tools
<ljarvis>
they're pretty good
<yorickpeterse>
e.g. stackprof would show the weirdest lines as being slow, when that was not the case
oleo has joined #ruby-lang
<[spoiler]>
aw I used peek, peek is cute
oleo has quit [Changing host]
oleo has joined #ruby-lang
oleo has quit [Client Quit]
mcclurmc_ has quit [Ping timeout: 256 seconds]
Stichoza has joined #ruby-lang
Stichoza has quit [Client Quit]
<maloik>
I really hope this view isn't just death by 1000 papercuts, and that I manage to spot a couple falling pianos as well
charliesome has quit [Quit: zzz]
shinnya_ has joined #ruby-lang
Mon_Ouie has quit [Ping timeout: 255 seconds]
Caius has joined #ruby-lang
yalue has joined #ruby-lang
<yorickpeterse>
It's Rails, probably somebody is querying half the database in a view
<yorickpeterse>
only to then use a single field
whippythellama has joined #ruby-lang
<maloik>
that's not it actually, the query is like 120ms or so
<maloik>
the views take 19k ms
<maloik>
well 13k by now... ish
<maloik>
came from even more than that
<[spoiler]>
Raisl: "Hello database. Yes, this is Rails, no it's-- oh you want a password? Yeah, sure. *tells the password* So um, I need something, but I don't remember where I put it, can you SELECT * FROM everywhere? Thaaaaankies! ~"
npassaro has joined #ruby-lang
<maloik>
:D
Lewix has quit []
oleo has joined #ruby-lang
loincloth has joined #ruby-lang
Nixsos has quit [Read error: Connection reset by peer]
loincloth has quit [Ping timeout: 245 seconds]
mattyohe has joined #ruby-lang
shambrarian has joined #ruby-lang
qba73 has quit [Remote host closed the connection]
qba73 has joined #ruby-lang
j2p2 has joined #ruby-lang
Nixsos has joined #ruby-lang
setanta_ has joined #ruby-lang
goodcodeguy has joined #ruby-lang
rahul_j has joined #ruby-lang
vishaltelangre has joined #ruby-lang
chouhoulis has quit [Remote host closed the connection]
rikkipitt has joined #ruby-lang
chouhoulis has joined #ruby-lang
qba73 has quit [Remote host closed the connection]
vishaltelangre has quit [Quit: Leaving]
skade has quit [Quit: Computer has gone to sleep.]
grekko has joined #ruby-lang
suavemint has joined #ruby-lang
|jemc| has joined #ruby-lang
tkuchiki has quit [Remote host closed the connection]
tkuchiki has joined #ruby-lang
kfpratt has quit [Read error: Connection reset by peer]
jo__ has joined #ruby-lang
kfpratt has joined #ruby-lang
<maloik>
ljarvis: seems peek doesn't really let you drill down a whole lot
<maloik>
also, the mounted engine doesn't seem to work :(
<maloik>
the route you install
tkuchiki has quit [Ping timeout: 244 seconds]
<ljarvis>
tbh we did have to mess around with it quite a bit
mistym has joined #ruby-lang
qba73 has joined #ruby-lang
<maloik>
it's mostly the drilling down that I need sadly
<maloik>
like... it's pretty obvious that this specific partial is slow :D I need to know where it's coming from
gregf_ has quit [Quit: leaving]
mistym has quit [Remote host closed the connection]
chills42 has quit [Remote host closed the connection]
matp_ has quit [Remote host closed the connection]
matp has joined #ruby-lang
kapil__ has quit [Quit: Connection closed for inactivity]
araujo has quit [Ping timeout: 255 seconds]
loincloth has joined #ruby-lang
deryl has joined #ruby-lang
mistym has joined #ruby-lang
gregf_ has joined #ruby-lang
|jemc| has quit [Ping timeout: 265 seconds]
<DefV>
maloik: if you find a good solution, let me know
apeiros_ has quit [Read error: Connection reset by peer]
<DefV>
so far my solution has always been putting <%= benchmark do %> blocks in my partial
<DefV>
sectioning out
apeiros_ has joined #ruby-lang
<DefV>
but, do enable GC logging
loincloth has quit [Ping timeout: 265 seconds]
<DefV>
if you have a large view or a lot of partials GC may be a serious percentage of your request
araujo has joined #ruby-lang
araujo has quit [Changing host]
araujo has joined #ruby-lang
cmhobbs has joined #ruby-lang
klmlfl has joined #ruby-lang
apeiros_ has quit [Ping timeout: 256 seconds]
ur5us has joined #ruby-lang
ur5us has quit [Ping timeout: 240 seconds]
konr has quit [Quit: Connection closed for inactivity]
shazaum has quit [Changing host]
shazaum has joined #ruby-lang
Nixsos has quit [Ping timeout: 245 seconds]
deryl is now known as ddd
slawrence00 has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
nofxx has joined #ruby-lang
fedexo has joined #ruby-lang
fedexo_ has joined #ruby-lang
Nixsos has joined #ruby-lang
Lewix has joined #ruby-lang
Lewix has joined #ruby-lang
Xzyx987X_ has quit [Ping timeout: 272 seconds]
apeiros_ has joined #ruby-lang
Xzyx987X has joined #ruby-lang
Xzyx987X has quit [Read error: Connection reset by peer]
stamina has joined #ruby-lang
Xzyx987X has joined #ruby-lang
chills42 has joined #ruby-lang
mistym has quit [Remote host closed the connection]
<yorickpeterse>
MONGOID TO POSTGRES: FUN FOR THE WHOLE FAMILY
<yorickpeterse>
DO YOU DEFINE METHODS SUCH AS "FROM" ON YOUR MODELS? WELL SCREW YOU, THAT WON'T WORK ANYMORE
<yorickpeterse>
ugh
__butch__ has joined #ruby-lang
* yorickpeterse
goes to find-replace half the codebase
<apeiros_>
interference with ORM methods?
<yorickpeterse>
Yes, AR defines "from" as well
<yorickpeterse>
(it's a class method in both cases)
<ljarvis>
dont even mention your orm unless you're gonna show it to us apeiros_!
<apeiros_>
ljarvis: you already mentioned it for me :)
<apeiros_>
but namespace poisoning is a problem
<ljarvis>
marketing 101
tenderlove has joined #ruby-lang
<apeiros_>
(not just for orms)
<yorickpeterse>
there's this wonderful thing called "mirrors", but hardly anybody uses them
AKASkip has joined #ruby-lang
<yorickpeterse>
e.g. we have them in Rbx to fix cases like people overwriting random Array methods and expecting things to "just" work
<apeiros_>
mind to explain how those work?
<yorickpeterse>
In a nutshell: you have a String and a StringMirror
<yorickpeterse>
The StringMirror defines whatever internals you need
<yorickpeterse>
You then basically do something like StringMirror.new(my_string).some_method_people_mess_with
<apeiros_>
I see
<apeiros_>
the pattern I wish for inspection in ruby (so it could e.g. also work with BasicObject)