Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

About this user

« Newer Snippets
Older Snippets »
5 total  XML / RSS feed 

Rake task that adds all unversioned files to the repository

task :add_all_to_svn do
  `svn status --show-updates`.each { |l|
    l = l.split
    system("svn add #{l.last}") if l.first == "?" # File is not under version control
  }
end

ActiveRecord attribute calls interception

I need to intercept attribute calls and add some additional info to them.

class ActiveRecord::Base
  def self.multilingual_field(fieldname)
    module_eval <<-end_eval
      def #{fieldname}
        send("#{fieldname}_\#{Locale.language.short_name}")
      end

      def #{fieldname}=(value)
        send("#{fieldname}_\#{Locale.language.short_name}=",value)
      end
    end_eval
  end
end

Default content-type in Rails

I always forget this.

class ApplicationController < ActionController::Base
  include AuthenticatedSystem
  
  before_filter :set_encoding
  
  private
    def set_encoding
      @headers["Content-type"] ||= "text/html; charset=utf8"
    end
end

My mom's recipe for okroshka (cold soup)

Ingredients:
Bunch of spring onions
0.5 kg of cucumbers 
4 potatoes
5 eggs
Bunch of fennel
1 carrot
3 garlics
0.5 kg of a boiled sousage
Sour cream
1L of kefir


Boil water and let it to get cold.
Put all sour cream and kefir there.
Boil 4 not so small potatoes and 1 carrot.
Boil 5 eggs and then put them under cold water.
While everything is boiling crumble cucumbers, spring onions (only green part), a fennel, garlics and a sousage.
Let potatoes and a carrot to get cold and then crumble them too.
Put everything into the water.
Salt and pepper to your taste.
Put it into a refrigerator and let it to get really cold.

Bon appetit!

PHP as FastCGI program

If you have problem with compiling php as cgi-fastcgi *run* make clean. It worked for me and, probably, it will work for you.

And here's my ./configure options for compiling php as cgi-fastcgi with some features I need.

simanyay $ make clean
simanyay $ ./configure --prefix=/usr/local/php5/ --enable-mbstring --with-mysql=/usr/local/mysql --with-mysql-sock=/t
mp/mysql.sock --with-mysqli --with-pdo-mysql=/usr/local/mysql --enable-force-cgi-redirect --enable-fastcgi --with-cur
l --with-sockets --enable-memory-limit --with-config-file-scan-dir=/usr/local/php5/sharecfg
simanyay $ make
simanyay $ sudo make install
simanyay $ /usr/local/php5/bin/php -v
PHP 5.1.4 (cgi-fcgi) (built: May 23 2006 20:03:51)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies
« Newer Snippets
Older Snippets »
5 total  XML / RSS feed