the codemonky

ramblings, musing and code snippets from shawn veader
Apr 23
Permalink

Starting down the path of objectifying C

OK, so I’ve had my head in and out of books lately trying to learn obj-C and Cocoa. So far it’s not too bad. Kinda fun to be back into a little more strict C-style world, while still maintaining some cool OO features.

My biggest gotchas/gripes I’ve found so far?

1) Having to add a nil to the end of a declared NSArray or NSDictionary (or their mutable variants).

[NSArray arrayWithObjects:@"1", @"2", @"3", nil];

That just seems like something that could be abstracted away for you…

2) Declaring a NSDictionary with keys and values is backward from what I would expect from Ruby land.

// what I expect
[NSDictionary dictionaryWithObjectsAndKeys:
              @"key1", @"value1", @"key2", @"value2",nil];
// what reality is
[NSDictionary dictionaryWithObjectsAndKeys:
              @"value1", @"key1", @"value2", @"key2",nil];

3) And as you can see from the examples above… the biggest gotcha of all is that to declare a string you have to prefix it with @.

(Hopefully I’ll start actually putting up stuff on this tumblelog again now…)

Jan 06
Permalink

Orkut.com.br needs to die!

Yes, I’m just one of the many who have fallen into the stupid Brazilian Orkut fake kid pages. There is a whole profile based off images from my Flickr stream.

http://www.orkut.com/Main#Album.aspx?uid=6447389076309092886&aid=1230630259
http://www.orkut.com/Main#Album.aspx?uid=499062161829329821&aid=1

I know I could toggle the “Friends & Family” setting on Flickr but I have too many people who look at my stream who are real friends and family that I don’t want to have to send a link or require them to sign up to see the pictures.

Of course Google, the owner of Orkut.com, is of absolutely no help. Reporting abuse on the site gives me this wonderful canned response:

Thank you for your reporting of abuse on Orkut on “2009-01-06”.

Based on our review and consideration of Orkut’s terms of service, we understand that this content does not currently break any policies on Orkut. If you believe that a mistake has been made, please re-submit your complaint with additional information to help our support team better understand your concerns with this content.
Thanks Google. Thanks!!!!?!?!

Glad they are so willing to help fight their site turning into a steaming pile of crap with pedophiles, etc.

Sigh, such is life on the interwebs.

Update: a friend of a friend works at Google and was able to get at least one of the accounts nuked this morning.
Nov 14
Permalink

Testing… Testing… This thing on?

Well it looks pike I forgot about my tumblog for some time now. Guess it is time to resurrect it.

Stay tunes for ramblings about languages I’m learning at the moment.

First up…. Erlang.

Jun 20
Permalink
Google does Atlanta

Google does Atlanta

May 15
Permalink

Endless Pages

Having heard a blurb on an endless page plugin on the RailsEnvy podcast, I decided to check it out. I wasn’t happy with how the plugin worked, so I whipped up something similar.

(Original post mentioned on RailsEnvy: link)

I decided most of what was needed was a mix of the wonderful will_paginate plugin and some Javascript. Thus endlesspage.js was born.

After including endlesspage.js in your layout, you should be able to do follow along below on how to set it up.

In the Controller: pastie

In the Views: pastie

Here is the file: endlesspage.js

(Sorry, but I couldn’t get Tumblr to cooperate with dumping in code.)

Let me know if you find this helpful…

UPDATE: I was informed (and confirmed myself) that the gem version of will_paginate doesn’t have the page_count method. The substitute method is total_pages.

Apr 18
Permalink
Apr 11
Permalink

silencing deprecations

OK, so if you’re stuck in Rails 1.2.X land like I am, you’re probably tired of seeing all the deprecation warnings when you run your test suite. (Yes, I know pagination is going away but someone might severly punish me for will_paginate at the moment.)

 Add this to your test/test_helper.rb

 

 ActiveSupport::Deprecation.silenced= true

 
Apr 10
Permalink

Git on OSX

Hit a roadblock compiling git tonight. Thanks to jnewland for the last piece of the puzzle.

curl -O http://kernel.org/pub/software/scm/git/git-1.5.4.5.tar.bz2 
tar ixf git-1.5.4.5.tar.bz2
cd git-1.5.4.5
./configure --prefix=/usr/local
make NO_MSGFMT=1
sudo make install 
Apr 02
Permalink
Apple goodness

Apple goodness

Mar 18
Permalink

establish_connection may harm you

So I have a reporting Rails application that is looking at the databases of two other Rails apps. I import the models using an svn:external link. I then have initializers that do a bit of “magic” switching which databases the models use and what their table names are based on the schema. We use Postgres so the “databases” are actually schemas in the same physical database.

unless RAILS_ENV.downcase == 'test'
# point all of the vanguard models to the champion_#{RAILS_ENV} database
Dir[File.expand_path('app/models/vanguard/*.rb',RAILS_ROOT)].each do |file|
model_str = $1.classify if file =~ /\/vanguard\/(.*?)\.rb$/

next unless model_str
# skip the models that aren't active record models
next if %w(...).include?(model_str)

eval("#{model_str}.instance_eval('establish_connection \"champion_#{RAILS_ENV}\"')")
table_name = eval("#{model_str}.table_name")
eval("#{model_str}.instance_eval('set_table_name \"vanguard.#{table_name}\"')")
end
end

I kept running into a problem where the maximum number of connections to this database was being exceeded. After poking around some I believe establish_connection isn’t doing the smart thing. It seems to blindly establish a connection each time it is called disregarding the fact that the connection might already be open.

I switched the logic such that the “primary” database is now this external connection and sub-class all of my internal models to use an abstract ActiveRecord class that points to a different database. The number of connections has dropped significantly.