Skip to content

Instantly share code, notes, and snippets.

class Device
# ...
def friendly_name
"#{self.customer.device_name_prefix} #{self.device_number}"
end
end
class Device
validates_uniqueness_of :device_number, :scope => :customer_id
after_create: assign_device_number
def assign_device_number
begin
device_number = self.customer.devices.map(&:device_number).compact.max) || 0 + 1
save!
rescue Whatever gets thrown for validation error
for i in $(find db/migrate |grep mondrian |cut -d '/' -f 3 | cut -d '_' -f 1 )
do
rake db:migrate:down VERSION=$i
rake db:migrate:up VERSION=$i
done
rake mondrian:init
# Wrong!
# If foo is valid but bar is not, foo is still saved.
# This breaks the transactional nature
#
def create
Foo.transaction do
@foo = Foo.create(params[:foo])
@bar = Bar.create(params[:bar])
if @foo.save and @bar.save
redirect_to some_url
[beaker:~/dev/mastermind] jzellman> git pull
From git@github.com:frogmetrics/mastermind
b27a181..62304b8 master -> origin/master
Already up-to-date.
[beaker:~/dev/mastermind] jzellman> git status
# On branch master
nothing to commit (working directory clean)
[beaker:~/dev/mastermind] jzellman> git pull
From git@github.com:frogmetrics/mastermind
+ 62304b8...b27a181 HEAD -> origin/HEAD (forced update)
[beaker:~/dev/mastermind] jzellman> git fetch origin
git statusFrom git@github.com:frogmetrics/mastermind
b27a181..62304b8 master -> origin/master
[beaker:~/dev/mastermind] jzellman> git status
# On branch master
nothing to commit (working directory clean)
[beaker:~/dev/mastermind] jzellman> git pull
From git@github.com:frogmetrics/mastermind
+ 62304b8...b27a181 HEAD -> origin/HEAD (forced update)
Already up-to-date.
[beaker:~/dev/mastermind] jzellman> git status
# On branch master
# Your branch is ahead of 'origin/master' by 322 commits.
#
nothing to commit (working directory clean)
[beaker:~/dev/mastermind] jzellman> git push origin master
git Everything up-to-date
[beaker:~/dev/mastermind] jzellman> git status
# On branch master
nothing to commit (working directory clean)
starting vacuum...end.
transaction type: TPC-B (sort of)
scaling factor: 50
number of clients: 25
number of transactions per client: 100000
number of transactions actually processed: 2500000/2500000
tps = 319.300264 (including connections establishing)
tps = 319.306314 (excluding connections establishing)
def current_brand
@_cached_brand ||= current_user.nil? ? look_up_from_reseller :
current_user.company.reseller.brand
end
#! /usr/bin/env python
# Reads in a file from stdin and converts its encoding from 8859 to utf-8
# Writes to stdout and lines that fail to stderr
# Example usage ./convert.py < in.txt 1> out.txt 2> errors.txt
import sys
for line_number, line in enumerate(sys.stdin.readlines()):
try:
sys.stdout.write(unicode(line, "8859").encode("utf-8"))
except UnicodeDecodeError as e: