Skip to content

Instantly share code, notes, and snippets.

// Javascript Doubly Ended Queue
var deque = function() {
var node = function(data, prev, next) {
var that = {};
that.data = data;
that.prev = prev;
that.next = next;
return that;
}
// Javascript Doubly Ended Queue
var Dequeue = function() {
this._head = new Dequeue.Node();
this._tail = new Dequeue.Node();
this._head._next = this._tail;
this._tail._prev = this._head;
}
Dequeue.Node = function(data) {
this._data = data;
# deployment
sudo gem install capistrano
# yeah rails
sudo gem install rails
# mongrel
sudo gem install mongrel
# xml processing in ruby
# get up to date
sudo apt-get update
sudo apt-get upgrade
# basic development tools
sudo apt-get install emacs git-core subversion build-essential
# ruby stuff
sudo apt-get install ruby rdoc ri libopenssl-ruby ruby1.8-dev irb
def field_changed?(attr, old, value)
if column = column_for_attribute(attr)
if column.type == :integer && column.null && (old.nil? || old == 0)
# For nullable integer columns, NULL gets stored in database for blank (i.e. '') values.
# Hence we don't record it as a change if the value changes from nil to ''.
# If an old value of 0 is set to '' we want this to get changed to nil as otherwise it'll
# be typecast back to 0 (''.to_i => 0)
value = nil if value.blank?
# else no!!!!!!!!!!! not the else branch
# value = column.type_cast(value)
u = Unit.find(123)
u.position #=> 14
u.position = "14"
u.position_changed? #=> false
u = Unit.find(42)
u.position #=> 0
u.position = "0"
u.position_changed? #=> true
[core]
repositoryformatversion = 0
filemode = true
bare = true
sharedrepository = 1
[receive]
denyNonFastforwards = true
ssh gitserver.com
mkdir -p /var/data/repos/myrepo.git
cd /var/data/repos/myrepo.git
git --bare init --shared=group
namespace :data do
# on my slow machine takes 5m09.209s
desc 'Set positions per parent_id, position, short_name via SQL'
task :sql_set_positions => :environment do
parents_sql = 'SELECT DISTINCT parent_id FROM units'
children_sql = %q{
SELECT
id FROM units
WHERE
namespace :data do
desc 'Set positions per parent_id, position, short_name via stored procedure'
task :sp_set_positions => :environment do
sql = 'CALL set_positions()'
puts sql
ActiveRecord::Base.connection.execute(sql)
end
end