Roger's woze

September 22, 2008

pro mormon stats

Filed under: Uncategorized — rogerdpack @ 3:38 am

I love blog posts biased toward the mormon faith, being one myself.

http://religionus.blogspot.com/2008/05/united-states-church-membership.html

“all is well in zion”
“zion prospereth”

-=R

September 19, 2008

how to override Symbol#to_proc in rails, or Symbol#to_proc on steroids

Filed under: Uncategorized — rogerdpack @ 6:18 pm

So it turns out that if you override Symbol#to_proc in rails in a file which you “load” from the console…welll—it doesn’t work. If, however, you load it from environment.rb then it works.
ex:
This allows you to do:
a = Program.find(:all)
a.map &:school__name # double underscore
=> ['school name', 'school name']
a.map &:name_and_code
=> [['program 1 name', 'program 1 code'], ['prog2 name', 'prog2 code']]

class Symbol
    alias :o ld_to_proc :to_proc
    def to_proc
      me = self.to_s
      if me =~ /_and_/
        first, second = me.split('_and_')
        proc {|obj, *args| [obj.send(first, *args), obj.send(second)]}
      elsif me =~ /__/
        first, second = me.split('__')
        proc { |obj, *args| obj.send(first, *args).send(second) }
      else
        old_to_proc
      end

    end
end

September 18, 2008

gruff examples

Filed under: Uncategorized — rogerdpack @ 11:03 pm

Hard to find some high quality gruff examples–well here they are!

http://wilkboardonline.com/roger/p2p/gruff_examples/output/

September 17, 2008

fastest mysql all_hashes around

Filed under: Uncategorized — rogerdpack @ 8:22 pm

so…mysqlplus has a new all_hashes. It’s faster. Like 5% faster.

Now add slim-attributes [pennysmalls.com]

It’s faster [esp. with many columns, but even with fewer]
to the tuns of
@utime=2.66>

@utime=0.37>

wowza
121_000 line query

However–this seems to only help for many column db’s and only for the load time for very very large queries–which is probably not the bottleneck [but it does help--esp. if you have monster queries].

September 6, 2008

how to install mongrel on ruby 1.9

Filed under: Uncategorized — rogerdpack @ 4:41 pm

svn co svn://rubyforge.org/var/svn/mongrel/trunk mongrel_trunk
cd mongrel_trunk
vi lib/mongrel/handler.rb # go to line 207 or so and change all the “: false” to “then false”
sudo ruby setup.rb
done!

September 4, 2008

thesis speedup

Filed under: Uncategorized — rogerdpack @ 7:53 pm

bisected regexes?
only save…start and end :)

how to pass a method in ruby

Filed under: Uncategorized — rogerdpack @ 3:01 pm

In Python, you can pass a method by [or get a pointer to a method] by NOT using ()’s
–ex:
a.my_method_name # pointer in Python

so…how to do this in Ruby?

answer: pass a proc object and then call .call(params) on it, or pass an instance and a symbol to call for its method name, i.e.
proc {|args| a.my_method_name(args) } # and then call .call on it
or
[a, :my_method_name] # and then call it via param_name[0].send(param_name[1], arg1, arg2, arg3)

I suppose you could abstract this to a new class that just does this for you, like instance.get_bound_method_name and then call it, but the way explained is one example.

I think Python calls these callables or “first class functions” or something along those lines.

September 3, 2008

microcredit–and you get it back!

Filed under: Uncategorized — rogerdpack @ 12:00 am

Don’t actually know if this is an “efficient” microcredit firm, but here’s a link [paypal's partners].

https://www.microplace.com/

« Newer Posts

Powered by WordPress