Tuesday, April 27, 2010

Mac OSX lib tools

I keep forgetting there names

nm --help
otool --help

For example to determine the arch of a lib hit it with these commands(not the best way but it works)

nm -arch i386 libname
nm -arch x86_64 libname

installing id3lib-ruby on mac

UPDATE 2) Fink is busted on 10.6 the lib has not built correctly and is crashing... switch to macports and install id3lib from there then (re)install the gem with this

sudo env ARCHFLAGS="-arch x86_64" gem install id3lib-ruby -- --with-opt-dir=/opt/local

UPDATE 1) Hold up... there is an easier way..

sudo env ARCHFLAGS="-arch i386" gem install id3lib-ruby -- --with-opt-dir=/sw

Confirm the result with this
arch -i386 irb
>> require 'id3lib'
=> true
>> tag = ID3Lib::Tag.new('talk.mp3')
=> []
>> 

ORIGINAL POST:
The default id3lib gem is way to stale for it to build on OSX 10.6...
so you need to start hacking stuff, in truth the maintainer is already
handled the problems u just need the newest version..

download the source code and untar it;
http://github.com/robinst/id3lib-ruby (the upper right has the
download source link or just git it)

then do this;

export PATH=/sw
export DYLD_LIBRARY_PATH=/sw/lib
cd to/the/source
sudo CONFIGURE_ARGS="--with-opt-dir=/usr/local" ruby setup.rb

confirm success with $ irb >> require 'rubygems' => false >> require 'id3lib' => true >>

Monday, April 26, 2010

Rails non-RESTful form_for

if you dont use the "map.resources" line in routes you are not making a restful app that means that the *_path *_url helper break too get around it you need to spec the url in form_for etc

<% form_for( @object, :url => {:action => 'update', :id => @object } :name => 'form') do |form| %> 

OpenSSL::SSL::SSLError: hostname was not match with the server certificate

OpenSSL::SSL::SSLError: hostname was not match with the server certificate

option 1) disable the ssl and raise all the errors so we can see them in the environment.rb or an initializer somewhere it can't be done in the config

ActionMailer::Base::raise_delivery_errors = true
ActionMailer::Base::smtp_settings[:enable_starttls_auto] = false


option 2) rebuild your snake oil cert ..
before you do this check that its going to work

hostname
openssl x509 -in  /etc/ssl/certs/ssl-cert-snakeoil.pem -noout -text


if the hostnames already match then forget it.. otherwise execute these commands to fix it and check..

make-ssl-cert generate-default-snakeoil --force-overwrite
openssl x509 -in  /etc/ssl/certs/ssl-cert-snakeoil.pem -noout -text

Friday, April 23, 2010

Rails Cookie and ActiveRecord Sessions

Rails by default uses an encrypted cookie store. Problem is that this store is limited to 4k if you need the space you should switch to something else

Here is how to switch to an active record store:

add the following line to config/environment.rb

config.action_controller.session_store = :active_record_store
Then to create the sessions table execute;

rake db:sessions:create
rake db:migrate

Saturday, April 17, 2010

iPhone dev; $non_lazy_ptr linker error

There are 3 causes that I know of for a $non_lazy_ptr linker error;

1) You forgot to instantiate your template functions and they are begin used from other files
2) You forgot to add the body of a virtual function (or you did and messed up its name space)
3) You forgot to instantiate the class variable.

If you forget to instantiate your templates so that another file can
use them. Then the iPhone version of gcc's linker is going to spit a
$non_lazy_ptr error for it.

For example if you code is a generic kind of setter function:

template <typename type>
void GenericClass::set(type _val)
{
  ((DataClass<type>*)holders[column])->set(_val);
  dirty = true;
}

Then the fix(using explicit instantiation) is to add the missing template instantiations to the file end of the file that defines the
template for each type of template you will end up using.

template void GenericRecord::setAssigns(int _val);
template void GenericRecord::setAssigns(bool _val);

Check here for more details on it;
http://gcc.gnu.org/onlinedocs/gcc/Template-Instantiation.html

For Missing virtual function bodies
class  GenericClass{ 
 virtual void set(int _val):
};

void set(int _val)
{
  ((DataClass<type>*)holders[column])->set(_val);
  dirty = true;
}

Then your fix is to add the missing namespace
void GenericClass::set(int _val)
{
  val = _val;
  dirty = true;
}

If you problem is a missing class variable instantiation, Then it might look something like this;

class  GenericClass{ 
 static int _val;
};

then your fix is this;
class  GenericClass{ 
 static int _val;
};

int GenericClass::_val;

Also note that this same error spat out when you miss instantiation of
a virtual functions body (but it refers to the vtable) and static
class variables.

Wednesday, April 14, 2010

Executing sql from rails console

All ways useful...

ActiveRecord::Base.connection.execute("SELECT * FROM users")
ActiveRecord::Base.connection.execute("select * from customers").fetch_row
results = ActiveRecord::Base.connection.execute("select * from customers")

while row = results.fetch_row do
# process row here
end

Monday, April 12, 2010

Rails built in Date parsing fixes

Rails(2.3.5) date parsing is busted IMO.

Try this: Place a date_select that allows blanks into a form and then enter the date 2010, "", 31 -- IE no month and the day 31 and submit the form. The result is a crash from a MultiparameterAssignmentErrors exception.

I dont care why it was does it.. to me its wrong here is the fix;


module ActiveRecord
  class Base
    def assign_multiparameter_attributes(pairs)
      begin
        execute_callstack_for_multiparameter_attributes(
        extract_callstack_for_multiparameter_attributes(pairs))
      rescue  MultiparameterAssignmentErrors => e
        e.errors.each { |err|
          self.errors.add(err.attribute)
        }
      end
    end
  end
end

Friday, April 9, 2010

Rails - Tarantula spider testing - finding broken I18n translations

Again with Tarantula - here a way to test all pages for missing translations while you are spidering.

class Relevance::Tarantula::MissingI18nTranslationHtmlHandler
  include Relevance::Tarantula

  def handle(result)
    begin
      response = result.response
      return unless response.html?
      if /translation missing/.match(response.body)
        error_result = result.dup
        error_result.success = false
        error_result.description = "Broken Translation"
        error_result
      end
    rescue 
    end
    return nil
  end
end

class TarantulaTest < ActionController::IntegrationTest
  fixtures :all
  require 'ruby-debug'
  def test_tarantula
    login_all_users
    t = tarantula_crawler(self)
    t.handlers << Relevance::Tarantula::MissingI18nTranslationHtmlHandler.new
    t.crawl "/"
  end
  def login_all_users
  end
end

RAILS - tarantula

Tarantula and excellent rails fuzzy spider. But its doc sucks..

The docs advise to unpack the gem into the vendors dir... and then add this the rake file

load File.join(RAILS_ROOT, Dir["vendor/gems/tarantula-*/tasks/*.rake"])

Dont unpack it. Total waste of space and time... load it from the gem install location it like this

tarantula_path =  Gem::required_location("tarantula", "")
if tarantula_path
  Dir[ File.join(tarantula_path, "..","tasks","*.rake") ].each { 
    |rakefile| load rakefile 
  }
end

ordering of includes.

When an active record has 2 belongs_to lines pointing to the same table the searching fails... notice the ordering of the includes.



(rdb:1)  Customer.find(:all, :conditions => ["#{Address.table_name}.name_given = 'kdFJf6J6Mdx'"], :include => [:address, :shipping_address] )
[]
(rdb:1)  Customer.find(:all, :conditions => ["#{Address.table_name}.name_given = 'kdFJf6J6Mdx'"], :include => [:shipping_address, :address] )
[#<Customer id: 81, ...SNIP... >]

Rails/Ruby backtraces

Rails/Ruby backtraces


begin
  asd
rescue => e
  logger.info "BACKTRACED HERE"
  bt = e.backtrace.delete_if{ |l| !(/private_stuff/ =~ l) }
  logger.info YAML::dump(bt)
end

mysql bug?

Mysql converting strings to numbers... be careful;

SELECT id FROM table_name WHERE (id = '2 asdfasdf  20');