September 2010
38 posts
Answer by Mladen Jablanović for How can I get SQL... →
It seems thatm in Rails 2.x, a private method called ActiveRecord::Base#construct_finder_sql could be used, I need to test it more and see whether it will work for me: ActionType.find(:all,...
Sep 29th
Answer by Mladen Jablanović for Iterate over a... →
Take look at Enumerable#each_cons method: ([nil]+array+[nil]).each_cons(3){|prev, curr, nxt| puts "prev: #{prev} curr: #{curr} next: #{nxt}" } prev: curr: a next: b prev: a curr: b next:...
Sep 29th
Answer by Mladen Jablanović for Iterate hash for... →
As others have pointed out, Hashes are not about order. It’s true that 1.9 hashes are ordered, but that’s just a convenience, not their primary feature. If the order is important to you, just use…
Sep 29th
How can I get SQL statement created by... →
I am using will_paginate with some complicated queries and it is unable to correctly calculate number of total records (in order to display proper number of page links) - namely because of…
Sep 28th
1 note
Comment by Mladen Jablanović on Delete all the... →
File.open('/tmp/file', 'w') {} should be enough.
Sep 28th
Comment by Mladen Jablanović on How can I get SQL... →
Thanks, I’ll keep that in mind when we migrate to 3. I forgot to mention that we’re still using 2.3.x, sorry.
Sep 28th
Comment by Mladen Jablanović on How can I get SQL... →
Thanks, I’ll give it a try. Do you perhaps know whether it constructs SQL mimicking AR behaviour, or wraps AR somehow? I.e. can I rely that it will give exactly the same query AR#find would?
Sep 28th
Comment by Mladen Jablanović on Ruby or Python... →
+1 for the Zen part about taking the slightly longer way learning. :)
Sep 28th
Comment by Mladen Jablanović on Why cant I do if... →
@swanand: zero? and empty? are there in core lib (not sure which classes you had in mind, though).
Sep 24th
RT @newsycombinator: Leaving .net http://j.mp/9tEHWD
Sep 23rd
Answer by Mladen Jablanović for validation before... →
From ActiveRecord::Base docs: Sometimes you want to be able to read the raw attribute data without having the column-determined typecast run its course first. That can be done by using the ...
Sep 22nd
Comment by Mladen Jablanović on Check if a... →
What’s the point of the first eval?
Sep 19th
Comment by Mladen Jablanović on noob confused... →
I don’t think it’s very useful for Sequel?
Sep 19th
Comment by Mladen Jablanović on noob confused... →
I think your question is too broad. What exactly puzzled you in the Sequel documentation? I think the README there is extremely well-writen, both for beginners and, as a reference, for experienced…
Sep 19th
Answer by Mladen Jablanović for Fill sparse array →
Range.new(*rare.transpose.first.sort.values_at(0,-1)).inject([]){|a,i| a<<[i, Hash[rare][i] || a.last.last] } Step-by-step explanation: rare.transpose.first.sort.values_at(0,-1) finds min and…
Sep 17th
Comment by Mladen Jablanović on How to DRY up a... →
@Steve: Shouldn’t it be country.state.try(:name) instead?
Sep 17th
Answer by Mladen Jablanović for Array of indexes... →
Functional, not-very-readable solution: (a[0,1]+a.each_cons(2).reject{|i,j| j-i==1}.flatten+a[-1,1]). each_slice(2).map{|i,j| i..j} And a nice one: class Array # splits array to sub-arrays...
Sep 17th
Comment by Mladen Jablanović on Better data... →
Just a small remark: prior to 1.9, Ruby’s Hash wasn’t ordered, so there’s no guarantee that each here would traverse the hash in the same order it was defined. If the order is important, one should…
Sep 16th
Answer by Mladen Jablanović for Trace the code in... →
There is Kernel#set_trace_func which mostly covers what you require: proc takes up to six parameters: an event name, a filename, a line number, an object id, a binding, and the name of a…
Sep 14th
Answer by Mladen Jablanović for Can you use Ruby... →
For example, you can write more-or-less standard RoR application, and access it from a browser on your touchscreen-equipped PC. The vendor should have provided accessibility features for it such as…
Sep 13th
Answer by Mladen Jablanović for Create array... →
So, couple of things: Unlike in PHP, Ruby makes difference between arrays (Array class) and associative arrays (Hash class). You need key->value type of structure, you should use Hash, which you…
Sep 11th
Koja je poenta potrošiti gornjih 50 piksela na ogroman naslov koji se ni ne vidi ceo?! #wp7 #fail
Sep 10th
Answer by Mladen Jablanović for ruby variable... →
In Ruby you don’t “create variables”, you are creating objects (an array, in your case), and assign them to variables. So, in your example, you have a single array with two names, local_ar and ...
Sep 9th
Comment by Mladen Jablanović on Calculate... →
@randomguy: Hey, thanks for the credits, it’s really nice to have an effort of such magnitude recognized! :o)
Sep 9th
Answer by Mladen Jablanović for Calculate... →
There is a method. Here it is: class Numeric def percents self * 100 end end 0.56.percents => 56.0
Sep 9th
Comment by Mladen Jablanović on ruby string escape... →
@Gz Rain: You don’t have to escape anything if you are using parametrized queries, or ORM (which you do, if you are using ActiveRecord). ORM will do all the needed escaping for you.
Sep 9th
Comment by Mladen Jablanović on Object methods and... →
You haven’t said anything about the actual object these methods belong to, and whether param is part of its state.
Sep 9th
Answer by Mladen Jablanović for Why doesn't Ruby... →
I think there’s another reason: ++ in Ruby wouldn’t be remotely useful as in C and its direct successors. The reason being the for keyword: while it’s essential in C, it’s mostly superfluous in…
Sep 8th
Comment by Mladen Jablanović on Ruby can only show... →
Let’s get this straight, you are judging language by its ability to deal with timezones?
Sep 8th
Comment by Mladen Jablanović on Search ruby hash... →
Of course that any solution should traverse whole hash when there are no blanks.
Sep 7th
Gledao “The Ghost Writer” Polanskog u bioskopu. Dobra fotografija i puno aluzija na Tonija Blera.
Sep 6th
Comment by Mladen Jablanović on What does "" (two... →
@AboutRuby: A single literal on a line (specifically, on a last line in a method) shows very clear intention IMHO. It’s one of Ruby idioms.
Sep 6th
Jel gledao neko novi Karate Kid, razmišljam da posle par godina posetim bioskop? :) Ozbiljno pitam.
Sep 5th
Comment by Mladen Jablanović on Ruby print out a... →
Why should the first indicate “five give or minus a half”? Lack of decimal digits doesn’t have to imply rounding of any kind.
Sep 4th
Comment by Mladen Jablanović on Does anyone have... →
I completely understand the attachment to VS (I simply can’t imagine writing C# without it), but, believe me, you don’t need it for Ruby. IMHO, the most valuable tool in Ruby is irb.
Sep 4th
Šta fali novim #limundo pravilima, osim što destimuliše one kojima ne odgovara aukcija kao način prodaje?
Sep 2nd
Answer by Mladen Jablanović for Comparing the... →
In general, if you have array arr of N such arrays, you can just check if there are any duplicates there: arr.length == arr.uniq.length because, for example: ...
Sep 1st
RT @markoa: Cvetanje Tise - Radi se o tome da jedan insekt, izvesni Palingenia Longicauda, provodiu mulju reke kao larva… http://tumbl …
Sep 1st