├── scripts ├── ls_stats │ ├── visualize.sh │ ├── stats-ls.rb │ └── generate_chart.rb ├── go_project.sh ├── check_thins.rb ├── mount_ramfs.sh ├── reload_varnish.sh ├── restore_db.sh ├── check_before_commit.rb └── copy_s3_bucket.rb └── .bash_profile /scripts/ls_stats/visualize.sh: -------------------------------------------------------------------------------- 1 | open `ruby generate_chart.rb` -------------------------------------------------------------------------------- /scripts/go_project.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | cd /Users/zog/Projects/$1/trunk -------------------------------------------------------------------------------- /scripts/check_thins.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | error = 0 4 | ARGV.each do |port| 5 | res = `ps aux|grep 'thin server' | grep ':#{port}'` 6 | if res == "" 7 | error += 1 8 | print "Error: no server on port #{port}\n" 9 | end 10 | end 11 | 12 | exit error 13 | -------------------------------------------------------------------------------- /scripts/mount_ramfs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ramfs_size_mb=1024 3 | mount_point=/Users/zog/ramfs 4 | 5 | ramfs_size_sectors=$((${ramfs_size_mb}*1024*1024/512)) 6 | ramdisk_dev=`hdid -nomount ram://${ramfs_size_sectors}` 7 | newfs_hfs -v 'Volatile HD' ${ramdisk_dev} 8 | mkdir -p ${mount_point} 9 | mount -o noatime -t hfs ${ramdisk_dev} ${mount_point} 10 | chown zog:staff ${mount_point} 11 | chmod 1777 ${mount_point} 12 | mkdir -p ${mount_point}/postgresql 13 | chown postgres:postgres ${mount_point}/postgresql 14 | 15 | #CREATE TABLESPACE ram LOCATION '/Users/zog/ramfs/postgresql'; 16 | -------------------------------------------------------------------------------- /scripts/reload_varnish.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Reload a varnish config 3 | # Author: Kristian Lyngstol 4 | 5 | FILE="/usr/local/Cellar/varnish/2.1.4/etc/varnish/default.vcl" 6 | 7 | # Hostname and management port 8 | # (defined in /etc/default/varnish or on startup) 9 | HOSTPORT="localhost:8081" 10 | NOW=`date +%s` 11 | 12 | error() 13 | { 14 | echo 1>&2 "Failed to reload $FILE." 15 | exit 1 16 | } 17 | 18 | varnishadm -T $HOSTPORT vcl.load reload$NOW $FILE || error 19 | varnishadm -T $HOSTPORT vcl.use reload$NOW || error 20 | echo Current configs: 21 | varnishadm -T $HOSTPORT vcl.list 22 | -------------------------------------------------------------------------------- /scripts/restore_db.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | BASE_DIR='/usr/local/pgsql/' 4 | PGCTL=$BASE_DIR'bin/pg_ctl' 5 | DB_DIRNAME='data' 6 | BACKUP_DB_DIRNAME='backup.local.'`date +%m%d%Y` 7 | REGEX='.*\.tar' 8 | 9 | # Let's stop the server 10 | $PGCTL stop -D $BASE_DIR$DB_DIRNAME 11 | if [[ $1 =~ $REGEX ]]; then 12 | cd /tmp 13 | DUMP=$DB_DIRNAME'_tmp' 14 | mkdir $DUMP 15 | cd $DUMP 16 | tar -xf $1 17 | cd .. 18 | else 19 | DUMP=$1 20 | fi 21 | 22 | mv $BASE_DIR$DB_DIRNAME $BASE_DIR$BACKUP_DB_DIRNAME 23 | mv $DUMP $BASE_DIR$DB_DIRNAME 24 | cp $BASE_DIR$BACKUP_DB_DIRNAME/*.conf $BASE_DIR$DB_DIRNAME 25 | chmod -R 700 $BASE_DIR$DB_DIRNAME 26 | 27 | # Let's start the server again 28 | $PGCTL start -D $BASE_DIR$DB_DIRNAME -------------------------------------------------------------------------------- /scripts/ls_stats/stats-ls.rb: -------------------------------------------------------------------------------- 1 | require 'date' 2 | require 'yaml' 3 | 4 | RAILS_ROOT = '/Users/zog/Projects/ls-server' 5 | class Array; def sum; inject( nil ) { |sum,x| sum ? sum+x : x }; end; end 6 | 7 | today = Date.today 8 | results = {today => {:code => {}, :tests => {}}} 9 | 10 | lines_cmd = "wc -l `find #{RAILS_ROOT} -name '*.%s'`" 11 | 12 | %w(rb yml sass js haml).each do |ext| 13 | lines = `#{lines_cmd % ext}` 14 | results[today][:code][:"#{ext}_lines"] = lines.match(/.*?(\d+)? total/m)[1].to_i rescue 0 15 | end 16 | 17 | results[today][:code][:total] = results[today][:code].values.sum 18 | 19 | tests_lines_cmd = "wc -l `find #{RAILS_ROOT}/test -name '*.*'`" 20 | lines = `#{tests_lines_cmd}` 21 | results[today][:tests][:lines] = lines.match(/.*?(\d+)? total/m)[1].to_i rescue 0 22 | results[today][:tests][:ratio] = (results[today][:tests][:lines].to_f / results[today][:code][:total] * 10000).to_i.to_f / 100 23 | puts results.to_yaml -------------------------------------------------------------------------------- /scripts/ls_stats/generate_chart.rb: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | require 'gchart' 3 | require 'yaml' 4 | 5 | data = open('tracking_stats_ls.yml').read 6 | data.gsub!(/\n---\s*\n/m, "\n") 7 | data = YAML::load(data).sort 8 | code = data.map{|h| h[1][:code][:total]} 9 | test = data.map{|h| h[1][:tests][:lines]} 10 | #p data 11 | #sp data.map{|h| h[1][:code][:total]} 12 | 13 | puts Gchart.line(:size => '800x300', 14 | :title => "Code lines evolution", 15 | :bg => 'efefef', 16 | :line_colors => "FF0000,00FF00,0000FF", 17 | :legend => ['Total lines count', 'Test lines count'], 18 | :axis_with_labels => ['x', 'y', 'r'], 19 | :axis_labels => [data.map{|k| k[0].strftime "%d/%m"}.join("|")], 20 | :data => [code.map{|v| v - code.min}, test.map{|v| v - test.min}]#, 21 | #:max_value => code.max + 1000, 22 | #:min_value => code.min - 1000 23 | ).gsub(/chxr=.*/, "chxr=1,#{code.min},#{code.max}|2,#{test.min},#{test.max}") 24 | -------------------------------------------------------------------------------- /.bash_profile: -------------------------------------------------------------------------------- 1 | export SVN_EDITOR=vim 2 | export PS1="\u:\[\e[0;36m\]\W\[\e[m\] \[\033[31m\]\`ruby -e \"print (%x{git branch 2> /dev/null}.grep(/^\*/).first || '').gsub(/^\* (.+)$/, '(\1) ') rescue ''\"\`\[\033[37m\]# " 3 | 4 | export PATH=$(echo $PATH | sed -e 's;:\?/opt/local/lib/postgresql83/bin;;' -e 's;/opt/local/lib/postgresql83/bin:\?;;') 5 | export PATH=/usr/local/cuda/bin:/usr/local/pgsql/bin/:$PATH 6 | export PATH=/usr/local/sbin:$PATH 7 | export DYLD_LIBRARY_PATH=/usr/local/cuda/lib:$DYLD_LIBRARY_PAT 8 | 9 | alias gols='cd ~/Projects/ls-server' 10 | alias gomile="cd ~/Projects/luxurysociety/branches;cd \`ls -ld milestone-* |tail -n1|egrep -o 'milestone-.*'\`" 11 | alias gostats='cd ~/Projects/Stats\ Api/rails' 12 | alias gosub='cd /Users/zog/Projects/luxurysociety/branches/subscriptions' 13 | alias gowhite='cd /Users/zog/Projects/luxurysociety/branches/whiteboard' 14 | alias mate_conflicts="svn st |grep C|awk '{ FS = \" \" } ; {print $2}'|xargs mate" 15 | alias resolve_conflicts="svn st |grep C|awk -F \" \" '{print $2}'|xargs svn resolved" 16 | alias reset_log='echo "" > log/development.log;echo "" > log/test.log' 17 | alias solr_start='gols;rake sunspot:solr:start;cd -' 18 | alias solr_stop='gols;rake sunspot:solr:stop;cd -' 19 | alias solr_restart='gols;rake sunspot:solr:start;rake sunspot:solr:stop;cd -' 20 | alias goto='. ~/go_project.sh $1' 21 | #alias trim='echo $1;sed "s/^[ \t]*$//" $1 > .trim_tmp; mv .trim_tmp $1' 22 | alias trim='sed "s/^[ \t]*$//" $1 > .trim_tmp; mv .trim_tmp $1' 23 | alias get_last_ls_dump="cd /Users/zog/Projects/luxurysociety/dumps;/opt/local/bin/s3cmd ls s3://woa/saves/db/|tail -n1|egrep -o 's3:\/\/.*'|xargs /opt/local/bin/s3cmd get;ls -l|egrep -o 'ls_.*bz2'|tail -n1|xargs bunzip2;ls -l|egrep -o 'ls_.*'|tail -n1|xargs ./prep_db.rb > REBUILD_DB" 24 | alias check='ruby ~/scripts/check_before_commit.rb|less -f -R' 25 | alias clear_prod_files='find public -name prod-*|xargs rm' 26 | alias edit_bash_profile='mate ~/.bash_profile' 27 | alias gui='open /Users/zog/Projects/ls-design' 28 | 29 | alias pgrep='ps aux|grep -i $1' 30 | 31 | [[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" -------------------------------------------------------------------------------- /scripts/check_before_commit.rb: -------------------------------------------------------------------------------- 1 | #!/opt/local/bin/ruby 2 | diff = `git diff` 3 | 4 | errors = false 5 | haml_diffs = /--git .*? b\/([^\n]*\.haml)\n(.*?)((\ndiff)|(\Z))/m 6 | js_diffs = /--git .*? b\/([^\n]*\.js)\n(.*?)((\ndiff)|(\Z))/m 7 | files_diffs = /--git .*? b\/([^\n]*\.rb)\n(.*?)((\ndiff)|(\Z))/m 8 | trailing_comma = /(.*,(\t|\s)*$)/ 9 | wandering_puts = /(\+(\t|\s)*(p(uts|\s)|debugger).*?$)/ 10 | haml_wandering_puts = /(\+(\t|\s)*-(\t|\s)*p(uts|\s).*?$)/ 11 | js_wandering_puts = /(\+(\t|\s)*console\.log.*?$)/ 12 | xxx = /(xxx)/i 13 | 14 | COLORS = { 15 | :bold => 1, 16 | :red => 31, 17 | :green => 32 18 | } 19 | 20 | def custom msg, color 21 | "\e[#{color}m#{msg}\e[0m" 22 | end 23 | 24 | COLORS.each do |color, code| 25 | eval " 26 | def #{color} msg 27 | custom msg, #{code} 28 | end 29 | " 30 | end 31 | 32 | def puts_notice msg 33 | puts green(msg) 34 | end 35 | 36 | def puts_error msg 37 | puts bold(red(msg)) 38 | end 39 | 40 | def puts_ok msg 41 | puts bold(green(msg)) 42 | end 43 | 44 | if !diff.empty? && files = diff.scan(files_diffs) and files.any? 45 | files.each do |file| 46 | if match = file[1].scan(wandering_puts) and match.any? 47 | puts_error "you've got #{match.size} puts in #{file[0]}:" 48 | errors = true 49 | match.each do |m| 50 | puts red(">>> ") + m[0] 51 | end 52 | puts "\n" 53 | end 54 | if match = file[1].scan(xxx) and match.any? 55 | puts_error "you've got #{match.size} XXX in #{file[0]}:" 56 | errors = true 57 | match.each do |m| 58 | puts red(">>> ") + m[0] 59 | end 60 | puts "\n" 61 | end 62 | end 63 | end 64 | 65 | if !diff.empty? && haml = diff.scan(haml_diffs) and haml.any? 66 | haml.each do |h| 67 | if match = h[1].scan(trailing_comma) and match.any? 68 | puts_error "you've got #{match.size} trailing comma(s) in #{h[0]}:" 69 | errors = true 70 | match.each do |m| 71 | puts red(">>> ") + m[0] 72 | end 73 | puts "\n" 74 | end 75 | if match = h[1].scan(haml_wandering_puts) and match.any? 76 | puts_error "you've got #{match.size} puts in #{h[0]}:" 77 | errors = true 78 | match.each do |m| 79 | puts red(">>> ") + m[0] 80 | end 81 | puts "\n" 82 | end 83 | end 84 | end 85 | 86 | if !diff.empty? && js_files = diff.scan(js_diffs) and js_files.any? 87 | js_files.each do |file| 88 | if match = file[1].scan(js_wandering_puts) and match.any? 89 | puts_error "you've got #{match.size} 'console.log' in #{file[0]}:" 90 | errors = true 91 | match.each do |m| 92 | puts red(">>> ") + m[0] 93 | end 94 | puts "\n" 95 | end 96 | end 97 | end 98 | 99 | 100 | puts_ok "**** No errors, go ! ****" unless errors 101 | puts "\n" 102 | puts_notice "Here are the modified files: \n\n" 103 | puts `git status` 104 | puts "\n" 105 | puts_notice "Here is the complete diff (READ IT YOU LAZY BASTARD): \n\n" 106 | puts diff 107 | 108 | #puts "> Do you want to commit these changes ? (y/N)" 109 | #choice = gets 110 | #if choice.chomp.downcase == 'y' 111 | # if errors 112 | # puts 'The script detected some errors, are you sure you want to commit? (y/N)' 113 | # choice = gets 114 | # return unless choice.chomp.downcase == 'y' 115 | # end 116 | # puts_ok "**** revision : #{12} ****" 117 | #else 118 | # puts_ok 'See you' 119 | #end -------------------------------------------------------------------------------- /scripts/copy_s3_bucket.rb: -------------------------------------------------------------------------------- 1 | require 'optparse' 2 | 3 | S3CMD_PATH = '/opt/local/bin/s3cmd' 4 | # HELPERS 5 | ######################## 6 | class Logger 7 | COLORS = { 8 | :bold => 1, 9 | :red => 31, 10 | :green => 32 11 | } 12 | 13 | def self.custom msg, color 14 | "\e[#{color}m#{msg}\e[0m" 15 | end 16 | 17 | COLORS.each do |color, code| 18 | eval " 19 | def self.#{color} msg 20 | custom msg, #{code} 21 | end 22 | " 23 | end 24 | 25 | def self.log msg 26 | puts green(msg) 27 | end 28 | 29 | def self.error msg 30 | raise bold(red(msg)) 31 | end 32 | 33 | def self.puts_ok msg 34 | puts bold(green(msg)) 35 | end 36 | end 37 | 38 | ######################### 39 | class Bucket 40 | VERBOSITY = 0 41 | @@current_bucket = nil 42 | 43 | def initialize bucket_name 44 | @name = bucket_name 45 | end 46 | 47 | def self.init bucket_name 48 | return if @@current_bucket == bucket_name 49 | Logger.log "Initializing conf for bucket #{bucket_name}" 50 | Logger.error "missing conf file ~/.s3cfg_#{bucket_name}" unless File.exists?(File.join(Dir.home, ".s3cfg_#{bucket_name}")) 51 | `cp ~/.s3cfg ~/.s3cfg.backup` if File.exists?(File.join(Dir.home, ".s3cfg")) 52 | `cp ~/.s3cfg_#{bucket_name} ~/.s3cfg` 53 | @@current_bucket = bucket_name 54 | end 55 | 56 | def name; @name end 57 | 58 | def self.restore 59 | Logger.log "Restoring intial conf" 60 | `mv ~/.s3cfg.backup ~/.s3cfg` 61 | @@current_bucket = nil 62 | end 63 | 64 | def self.get_bucket path, options={} 65 | dir_name = options[application] || path 66 | bucket = path.split('/').first 67 | self.init bucket 68 | `mkdir -p #{dir_name}` unless File.exists?(dir_name) 69 | Logger.log("Getting s3://#{path} to #{dir_name}") 70 | `#{S3CMD_PATH} get #{VERBOSITY > 0 ? "-v" : ""} --recursive --skip-existing s3://#{path}/ #{dir_name}` 71 | dir_name 72 | end 73 | 74 | def self.put_bucket path, options={} 75 | dir_name = options[:dir_name] || path 76 | bucket = path.split('/').first 77 | self.init bucket 78 | Logger.error("#{dir_name} does not exist") unless File.exists?(dir_name) 79 | Logger.log("Putting #{dir_name} to s3://#{path}/") 80 | puts "#{S3CMD_PATH} put #{VERBOSITY > 0 ? "-v" : ""} --recursive --skip-existing #{dir_name} s3://#{path}/" 81 | #`#{S3CMD_PATH} put #{VERBOSITY > 0 ? "-v" : ""} --recursive --skip-existing #{dir_name} s3://#{path}/` 82 | dir_name 83 | end 84 | 85 | def self.replicate src, dest, options={} 86 | tmp_dir_name = "tmp_#{src}" 87 | get_bucket src, :dir_name => tmp_dir_name 88 | put_bucket dest, :dir_name => "#{tmp_dir_name}/*" 89 | `rm -rf #{tmp_dir_name}` unless options[:keep_local_copy] 90 | nil 91 | end 92 | end 93 | 94 | ######################### 95 | options = {} 96 | OptionParser.new do |opts| 97 | opts.banner = "Usage: #{File.basename(__FILE__)} [options] task params" 98 | 99 | opts.on('-s', '--source BUCKET', 'Source bucket') do |s| 100 | options[:source] = s 101 | end 102 | 103 | opts.on('-d', '--dest BUCKET', 'Destination bucket') do |d| 104 | options[:destination] = d 105 | end 106 | 107 | opts.on('-h', '--help', 'Display this screen') do 108 | puts opts 109 | exit 110 | end 111 | end.parse! 112 | 113 | SOURCE_BUCKET = options[:source] || ENV['SOURCE_BUCKET'] || 'luxurysociety_dev' 114 | DEST_BUCKET = options[:destination] || ENV['DEST_BUCKET'] || 'luxurysociety_staging' 115 | 116 | #source_bucket = Bucket.new(SOURCE_BUCKET) 117 | #destination_bucket = Bucket.new(DEST_BUCKET) 118 | #source_bucket.list 119 | #Logger.log '----' 120 | #puts source_bucket.list 10, true 121 | #destination_bucket.list 122 | #Bucket.restore 123 | --------------------------------------------------------------------------------