Skip to content

Instantly share code, notes, and snippets.

View nesquena's full-sized avatar

Nathan Esquenazi nesquena

View GitHub Profile
''' Project Euler # 17, Nathan Esquenazi '''
words = {
1000 : 'thousand',
100 : 'hundred',
90 : 'ninety',
80 : 'eighty',
70 : 'seventy',
60 : 'sixty',
50 : 'fifty',
class Demo:
def __init__(self, n):
self.iv = n
def hello(self):
return "Hello, self.iv = %s" % self.iv
k = Demo(99)
m = getattr(k, "hello")
# Reia script
module Sundays
def first_day_is_sunday(y, m)
calendar::day_of_the_week(y, m, 1) == 7
end
def count_valid_months
[ 1 | y in 1901..2000, m in 1..12, first_day_is_sunday(y,m) ].size()
end
@nesquena
nesquena / .bash_profile
Created May 31, 2009 07:17
simple git branch ps1 with colored dirty state
# COLORS
LIGHT_GRAY="\[\033[0;37m\]"; BLUE="\[\033[1;36m\]"; RED="\[\033[0;31m\]"; LIGHT_RED="\[\033[1;31m\]";
GREEN="\[\033[0;32m\]"; WHITE="\[\033[1;37m\]"; LIGHT_GRAY="\[\033[0;37m\]"; YELLOW="\[\033[1;33m\]";
# GIT PROMPT (http://gist.github.com/120804)
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ \(\1\)/';
}
function parse_git_status {
git status 2> /dev/null | sed -e '/(working directory clean)$/!d' | wc -l;
}

Bundling Overview

l$ scp -i ~/.ec2/id_xxx ~/.ec2/cert-XXXXXXXXXXXXXX.pem ~/.ec2/pk-XXXXXXXXXXXXX.pem root@xxx.xxx.xx.xxx:/mnt
l$ ssh root@xxx.xxx.xx.xxx -i ~/.ec2/keys/id_xxx-keypair
r$ export RUBYLIB=/usr/lib/site_ruby/
r$ ec2-bundle-vol -p <BUNDLENAME> -d /mnt -k /mnt/pk-XXXXXXXXXXXXX.pem -c /mnt/cert-XXXXXXXXXXXXXX.pem -u <account_id> -r i386
r$ ls -l /mnt/<BUNDLENAME>.*
r$ ec2-upload-bundle -b <BUCKETNAME> -m /mnt/<BUNDLENAME>.manifest.xml -a <access_key> -s <secret_access_key>

r$ sudo rm /mnt/.*

# For rails, running memcache in development mode
# check if memcached is running; if it is, enable caching
# To start use $ memcached -m 64 -l 127.0.0.1 -p 11211 -vv -u root
begin
Timeout.timeout(0.5) { TCPSocket.open("localhost", 11211) { } }
config.action_controller.perform_caching = true
config.cache_store = :mem_cache_store, "localhost:11211", { :namespace => "quub" }
rescue StandardError
config.action_controller.perform_caching = false
config.cache_store = :file_store, "#{Rails.root}/tmp/cache"
- form_tag '/login' do
.flash= flash[:notice]
%p
= label_tag :username
= text_field_tag :username, :value => params[:username]
%p
= label_tag :password
= text_field_tag :password, :value => params[:password]
%p
= submit_tag "Login"
desc "Generate and deploy assets"
task :deploy_assets, :roles => :app do
# get the previous timestamp
old_timestamp = File.read("config/deploy_timestamp").to_i rescue 0
# generate timestamp into config/deploy_timestamp
timestamp = Time.now.to_i
File.open("config/deploy_timestamp", 'w') do |f|
f.write(timestamp)
end
namespace :db do
namespace :indexes do
desc "Prints a list of unindexed foreign keys so you can index them"
task :missing => :environment do
indexes = {}
conn = ActiveRecord::Base.connection
conn.tables.each do |table|
indexed_columns = conn.indexes(table).map { |i| i.columns }.flatten
conn.columns(table).each do |column|
if column.name.match(/_id/) && !indexed_columns.include?(column.name)
create_table :stores do |t|
t.string :auth_key
t.string :contact_name, :section_name
t.string :location, :store_name
end
create_table :sections do |t|
t.string :auth_key
t.string :name
end