Skip to content
Browse files

initial commit

  • Loading branch information...
1 parent d87596c commit 25876b296897042ba90c4c4b7901594102a2f9ef @vatrai committed
Showing with 726 additions and 0 deletions.
  1. +28 −0 README
  2. +75 −0 backup
  3. +13 −0 git_ignore
  4. +40 −0 gitconfig
  5. +29 −0 irbrc
  6. +178 −0 my_zshrc
  7. +335 −0 sake
  8. +10 −0 screenrc
  9. +18 −0 search_file
View
28 README
@@ -0,0 +1,28 @@
+* Setting this up *
+
+* Clone the repo:
+
+* Create couple of symbolic links:
+
+ $ ln -s ~/dot_files/my_zshrc ~/.zshrc
+ $ ln -s ~/dot_files/irbrc ~/.irbrc
+ $ ln -s ~/dot_files/gitconfig ~/.gitconfig
+ $ mkdir ~/bin (if bin directory doesn't exist)
+ $ ln -s ~/sake ~/bin/sake
+ $ ln -s ~/dot_files/screenrc ~/.screenrc
+
+* Modify ~/dot_files/my_zshrc
+
+ You may have to modify the my_zshrc file to your liking a bit. The PATH and
+ other stuff is configured according to the way, I have setup my machine.You may need to
+ change that.
+
+* Switch to zsh :
+
+ $ chsh
+
+* Close the terminal
+* Logout from your active session.
+* Open terminal and voila, you should have zsh with new prompt and everything working.
+
+
View
75 backup
@@ -0,0 +1,75 @@
+#!/usr/bin/env ruby
+
+require "rubygems"
+require "configatron"
+require "yaml"
+require "fileutils"
+
+class Backup
+ include FileUtils
+ attr_accessor :config, :config_dir
+ def initialize
+ @config_dir = File.join(ENV['HOME'],'.backup')
+ config_hash = YAML.load_file(File.join(config_dir,"backup.yml"))
+ configatron.configure_from_hash(config_hash)
+ end
+
+ def run_command(arg)
+ command = arg.first
+ unless can_backup?
+ puts "Warning - backup target is missing and cant run backups"
+ exit(1)
+ end
+ case command
+ when "archive"
+ archive_folders()
+ else
+ backup_all()
+ archive_folders()
+ end
+ end
+
+ def can_backup?
+ File.directory?(configatron.target)
+ end
+
+ def can_archive?
+ File.directory?(configatron.archive.source)
+ end
+
+ def archive_folders
+ return unless can_archive?
+ system("rsync #{rsync_command_options} #{configatron.archive.source} #{configatron.target}")
+ keep_dirs = configatron.archive.exclude.split(",")
+ keep_dirs.each do |dir|
+ tobe_deleted = File.join(configatron.archive.source,dir)
+ puts "Going to delete all contents of #{tobe_deleted}"
+ rm_r Dir.glob("#{tobe_deleted}/*")
+ end
+ end
+
+ def rsync_command_options
+ "-avl --inplace --stats --progress"
+ end
+
+ def backup_has_exclude?
+ File.exists?(backup_exclude)
+ end
+
+ def backup_exclude
+ File.join(config_dir,"exclude.txt")
+ end
+
+ def backup_all
+ if backup_has_exclude?
+ system("rsync #{rsync_command_options} --delete --exclude-from '#{backup_exclude}' #{configatron.backup.source} #{configatron.target}")
+ else
+ system("rsync #{rsync_command_options} --delete #{configatron.backup.source} #{configatron.target}")
+ end
+ end
+end
+
+if __FILE__ == $0
+ b = Backup.new()
+ b.run_command(ARGV)
+end
View
13 git_ignore
@@ -0,0 +1,13 @@
+.*.swp
+tags
+.swo
+*.elc
+jferris-*.gemspec
+*.scratch.*
+nbproject
+.idea
+.DS_Store
+.rbenv-version
+*.iml
+.rvmrc
+config/database.yml
View
40 gitconfig
@@ -0,0 +1,40 @@
+# ADD LOCAL CONFIGURATION HERE
+
+
+# DO NOT EDIT BELOW THIS LINE
+[color]
+ diff = auto
+ status = auto
+ branch = auto
+[core]
+ excludesfile = ~/.gitignore
+ editor = vim
+ autocrlf = input
+[alias]
+ ci = commit
+ co = checkout
+ c = commit -m
+ a = add
+ di = diff
+ dic = diff --cached
+ pl = pull
+ ps = push
+ plre = pull --rebase
+ st = status
+ out = log origin..HEAD
+ bra = branch -a
+
+[user]
+ name = Vishnu Atrai
+ email = me@vishnuatrai.com
+[mergetool "diffmerge"]
+ cmd = diffmerge --merge --result=$MERGED $LOCAL $BASE $REMOTE
+ trustExitCode = false
+[github]
+ user = vatrai
+[difftool "Kaleidoscope"]
+ cmd = ksdiff-wrapper git \"$LOCAL\" \"$REMOTE\"
+[difftool]
+ prompt = false
+[diff]
+ tool = Kaleidoscope
View
29 irbrc
@@ -0,0 +1,29 @@
+# print SQL to STDOUT
+if ENV.include?('RAILS_ENV') && !Object.const_defined?('RAILS_DEFAULT_LOGGER')
+ require 'logger'
+end
+
+# Autocomplete
+require 'irb/completion'
+
+# Prompt behavior
+ARGV.concat [ "--readline", "--prompt-mode", "simple" ]
+
+# History
+require 'irb/ext/save-history'
+IRB.conf[:SAVE_HISTORY] = 100
+IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-save-history"
+
+# Easily print methods local to an object's class
+class Object
+ def local_methods
+ (methods - Object.instance_methods).sort
+ end
+end
+
+# copy a string to the clipboard
+def pbcopy(string)
+ `echo "#{string}" | pbcopy`
+ string
+end
+require "rubygems"
View
178 my_zshrc
@@ -0,0 +1,178 @@
+setopt correct
+
+# Use Emacs keybinds
+bindkey -e
+
+PS1='%2~> '
+
+setopt prompt_subst
+
+# git theming default: Variables for theming the git info prompt
+ZSH_THEME_GIT_PROMPT_PREFIX="git:(" # Prefix at the very beginning of the prompt, before the branch name
+ZSH_THEME_GIT_PROMPT_SUFFIX=")" # At the very end of the prompt
+
+autoload colors zsh/terminfo
+ if [[ "$terminfo[colors]" -ge 8 ]]; then
+ colors
+ fi
+
+for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do
+ eval PR_$color='%{$terminfo[bold]$fg[${(L)color}]%}'
+ eval PR_LIGHT_$color='%{$fg[${(L)color}]%}'
+ (( count = $count + 1 ))
+done
+PR_NO_COLOUR="%{$terminfo[sgr0]%}"
+
+
+function precmd() {
+ head_info=$(git symbolic-ref HEAD 2> /dev/null)
+ # rvm_use=$(rvm info|egrep -C 1 'homes'|grep 'gem'|cut -d\: -f 2|cut -d\" -f 2 )
+ #
+ # if [[ $rvm_use =~ 'not set' ]]; then
+ # rvm_flag='system'
+ # else
+ # rvm_flag=$rvm_use[(ws:/:)-1]
+ # fi
+
+ rvm_prompt_info=$(~/.rvm/bin/rvm-prompt 2> /dev/null)
+
+ # if [[ $rvm_prompt_info =~ ' ' ]]; then
+ # rvm_flag='system'
+ # else
+ rvm_flag=$rvm_prompt_info
+ # fi
+
+ RPROMPT='$PR_RED$rvm_flag$PR_NO_COLOUR'
+ if [[ $head_info =~ '^refs*' ]]; then
+ branch_name=$head_info[(ws:/:)-1]
+ output=$(git diff-files --exit-code --quiet)
+ if [[ $? == 0 ]]; then
+ PROMPT='%2~ $PR_RED$ZSH_THEME_GIT_PROMPT_PREFIX$PR_NO_COLOUR$PR_GREEN$branch_name$PR_NO_COLOUR$PR_RED$ZSH_THEME_GIT_PROMPT_SUFFIX$PR_NO_COLOUR$PR_CYAN>$PR_NO_COLOUR '
+ else
+ PROMPT='%2~ $PR_RED$ZSH_THEME_GIT_PROMPT_PREFIX$PR_NO_COLOUR$PR_GREEN$branch_name$PR_NO_COLOUR$PR_RED$ZSH_THEME_GIT_PROMPT_SUFFIX$PR_NO_COLOUR$PR_MAGENTA*$PR_NO_COLOUR '
+ fi
+ else
+ PROMPT='%2~~>'
+ fi
+}
+
+#history stuff
+## Command history configuration
+HISTFILE=$HOME/.zsh_history
+HISTSIZE=10000
+SAVEHIST=10000
+
+setopt hist_ignore_dups # ignore duplication command history list
+setopt share_history # share command history data
+
+setopt hist_verify
+setopt inc_append_history
+setopt extended_history
+setopt hist_expire_dups_first
+
+# completion related stuff
+## fixme - the load process here seems a bit bizarre
+
+setopt noautomenu
+setopt complete_in_word
+setopt always_to_end
+
+unsetopt flowcontrol
+
+WORDCHARS=''
+
+autoload -U compinit
+compinit
+
+zmodload -i zsh/complist
+
+## case-insensitive (all),partial-word and then substring completion
+if [ "x$CASE_SENSITIVE" = "xtrue" ]; then
+ zstyle ':completion:*' matcher-list 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
+ unset CASE_SENSITIVE
+else
+ zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
+fi
+
+zstyle ':completion:*' list-colors ''
+
+unsetopt MENU_COMPLETE
+#setopt AUTO_MENU
+
+# should this be in keybindings?
+bindkey -M menuselect '^o' accept-and-infer-next-history
+
+zstyle ':completion:*:*:*:*:*' menu yes select
+# zstyle ':completion:*:*:*:*:processes' force-list always
+
+zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01'
+zstyle ':completion:*:*:*:*:processes' command "ps -u `whoami` -o pid,user,comm -w -w"
+
+# Load known hosts file for auto-completion with ssh and scp commands
+if [ -f ~/.ssh/known_hosts ]; then
+ zstyle ':completion:*' hosts $( sed 's/[, ].*$//' $HOME/.ssh/known_hosts )
+ zstyle ':completion:*:*:(ssh|scp):*:*' hosts `sed 's/^\([^ ,]*\).*$/\1/' ~/.ssh/known_hosts`
+fi
+#end of completion related stuff
+
+# Aliases
+alias g='git'
+alias gst='git status'
+alias gl='git pull'
+alias gup='git fetch && git rebase'
+alias gp='git push'
+alias gd='git diff | mate'
+alias gdv='git diff -w "$@" | vim -R -'
+alias gc='git commit -v'
+alias gca='git commit -v -a'
+alias gb='git branch'
+alias gba='git branch -a'
+alias gcount='git shortlog -sn'
+alias gcp='git cherry-pick'
+alias grst='git reset --hard HEAD'
+alias gf="git fetch"
+alias gsi="git submodule init"
+alias gsu="git submodule update"
+alias grh="git reset --hard"
+alias s="sake"
+alias be="bundle exec"
+
+alias psr="ps axu|grep ruby"
+alias ..2="cd ../.."
+alias ..3="cd ../../.."
+alias r="rake"
+alias screen="screen -h 5000"
+alias emacs="open -a Emacs.app"
+alias em="/Applications/Emacs.app/Contents/MacOS/bin/emacsclient --no-wait"
+alias cl="cd ~/apps/CyncAbl-R3"
+alias rls="cd ~/apps/rails"
+alias ls="ls -G"
+export EDITOR="vim"
+
+
+
+#export PATH=/opt/ree/bin:/opt/git/bin:/opt/local/bin:/opt/local/sbin:$HOME/bin:$PATH
+
+export PATH=/usr/local/bin:$HOME/bin:$PATH
+alias ru='ps -ef | grep ruby'
+
+export CC=/usr/bin/gcc-4.5
+export LC_CTYPE=en_US.UTF-8 export LC_ALL=en_US.UTF-8
+
+
+#export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:/usr/local/Cellar/mysql/5.1.55/lib"
+#rvm_archflags="-arch i386"
+
+#export JRUBY_OPTS=--1.9
+
+# Oracle specific
+export DYLD_LIBRARY_PATH="/usr/local/oracle/instantclient_10_2"
+export SQLPATH="/usr/local/oracle/instantclient_10_2"
+export TNS_ADMIN="/usr/local/oracle/network/admin"
+export NLS_LANG="AMERICAN_AMERICA.UTF8"
+export PATH=$PATH:$DYLD_LIBRARY_PATH
+
+source ~/apps/auto-rake/auto_rake.sh
+
+#[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
+PATH=$PATH:$HOME/.rvm/bin
View
335 sake
@@ -0,0 +1,335 @@
+#!/usr/bin/env ruby
+require "rubygems"
+require "rake"
+require "rake/tasklib"
+require "colored"
+require "fileutils"
+begin
+ require "mysql"
+rescue LoadError
+end
+
+require "grit"
+
+class Object
+ def blank?
+ respond_to?(:empty?) ? empty? : !self
+ end
+
+ # An object is present if it's not blank.
+ def present?
+ !blank?
+ end
+
+ def presence
+ self if present?
+ end
+end
+
+class NilClass #:nodoc:
+ def blank?
+ true
+ end
+end
+
+class FalseClass #:nodoc:
+ def blank?
+ true
+ end
+end
+
+class TrueClass #:nodoc:
+ def blank?
+ false
+ end
+end
+
+class Array #:nodoc:
+ alias_method :blank?, :empty?
+end
+
+class Hash #:nodoc:
+ alias_method :blank?, :empty?
+end
+
+class String #:nodoc:
+ def blank?
+ self !~ /\S/
+ end
+end
+
+class Numeric #:nodoc:
+ def blank?
+ false
+ end
+end
+
+include FileUtils
+
+Rake.application.init("sake")
+
+desc "Push current branch"
+task :gp do
+ branch_name = @git_help.current_branch
+ puts "Pushing branch #{branch_name}"
+ system("git push origin #{branch_name}")
+end
+
+desc "Force push current branch"
+task :gpf do
+ branch_name = @git_help.current_branch
+ puts "Force pushing branch #{branch_name}"
+ system("git push origin #{branch_name} --force")
+end
+
+desc "Merge remote of current with current branch"
+task :gm do
+ branch_name = @git_help.current_branch
+ puts "Merging origin/#{branch_name} with #{branch_name}"
+ system("git merge origin/#{branch_name}")
+end
+
+desc "Rebase remote of current with current branch"
+task :gb do
+ branch_name = @git_help.current_branch
+ puts "Rebasing origin/#{branch_name} with #{branch_name}"
+ system("git rebase origin/#{branch_name}")
+end
+
+desc "Show diff"
+task :gd do
+ system("git diff")
+end
+
+desc "Do hard reset"
+task :grst do
+ system("git reset --hard HEAD")
+end
+
+desc "Clone code from one of the CRRC repos"
+task :gcs do
+ project_name = ENV['project']
+ system("git clone git@code.crrc.ca:#{project_name}.git")
+end
+
+desc "Creating a tracking local branch"
+task :gct do
+ branch_name = ENV['branch']
+ if(branch_name.blank?)
+ abort("Argument branch=".red+"<branch_name>".green)
+ else
+ system("git checkout --track -b #{branch_name} origin/#{branch_name}")
+ end
+end
+
+desc "Creating local branch for all branches"
+task :create_branch do
+ repo = Grit::Repo.new(".")
+ local_branches = repo.branches.collect { |x| x.name }
+ puts local_branches.join(",")
+ remote_origin_branches = repo.remotes.collect { |x| x.name =~ /^origin\/(.+)/ ? $1 : nil }.compact
+ puts "********** Remote origin branches are **********"
+ puts remote_origin_branches.join(",")
+ remote_origin_branches.each do |branch_name|
+ if branch_name != 'HEAD' && !local_branches.include?(branch_name)
+ puts "********** Creating branch #{branch_name}"
+ system("git checkout --track -b #{branch_name} origin/#{branch_name}")
+ elsif(branch_name != 'HEAD' && local_branches.include?(branch_name))
+ puts "########## Rebasing branch #{branch_name} with origin/#{branch_name}"
+ system("git checkout #{branch_name}")
+ system("git rebase origin/#{branch_name}")
+ end
+ end
+end
+
+desc "drop a table from particular db"
+task :drop_table do
+ db = ENV['db']
+ table_name = ENV['table']
+
+ username = ENV['user'] || 'root'
+ password = ENV['password'] || ''
+ host = ENV['host'] || 'localhost'
+
+ if !db.blank? && !table_name.blank?
+ puts "Going to drop #{table_name} from #{db}"
+ db_util = Sake::Database.new()
+ db_util.delete_table(db,table_name,username,password,host)
+ else
+ abort("Please supply db and table to delete")
+ end
+end
+
+
+desc "Update all Solaro related repos"
+task :slu do
+ solaro_dir = File.join(ENV['HOME'],'checkout','solaro')
+ cd(solaro_dir) { system("git fetch") }
+ securo_admin_dir = File.join(ENV['HOME'],'checkout','securo_admin')
+ cd(securo_admin_dir) { system("git fetch") }
+ payment_dir = File.join(ENV['HOME'],'checkout','securo_payment_middleware')
+ cd(payment_dir) { system("git fetch") }
+ solaro_revision_dir = File.join(ENV['HOME'],'solaro_revision')
+ cd(solaro_revision_dir) { system("git fetch") }
+ gitosis_dir = File.join(ENV['HOME'],'gitosis-admin')
+ cd(gitosis_dir) { system("git fetch") }
+end
+
+desc "Globally available task list"
+task :default do
+ Rake.application.tasks.each do |task|
+ puts sprintf("%-25s : %s",task.name.bold.red,task.comment || "runs #{task.name}".blue)
+ end
+end
+
+desc "Update solaro"
+task :sl do
+ solaro_dir = File.join(ENV['HOME'],'checkout','solaro')
+ cd(solaro_dir) do
+ system("git fetch")
+ Rake.application.invoke_task("gm")
+ end
+end
+
+desc "Update rails and arel"
+task :ru do
+ rails_dir = File.join(ENV['HOME'],'checkout','rails')
+ cd(rails_dir) do
+ system("git fetch")
+ system("git fetch upstream")
+ system("git rebase upstream/master")
+ end
+
+ arel_dir = File.join(ENV['HOME'],'checkout','arel')
+ cd(arel_dir) do
+ system("git fetch")
+ Rake.application.invoke_task('gb')
+ end
+
+ rack_dir = File.join(ENV['HOME'],'checkout','rack')
+ cd(rack_dir) do
+ system("git fetch")
+ Rake.application.invoke_task('gb')
+ end
+end
+
+desc "truncate db"
+task :dbt do
+ db = ENV['db']
+ username = ENV['user'] || 'root'
+ password = ENV['password'] || ''
+ host = ENV['host'] || 'localhost'
+
+ if not db.blank?
+ db_util = Sake::Database.new()
+ db_util.truncate_db(db,username,password,host)
+ else
+ abort("Please supply db name to truncate")
+ end
+end
+
+desc "Run ruby"
+task :run_ruby do
+ ruby "~/checkout/solaro/sandbox/benchmark_find_select.rb"
+end
+
+desc 'delete files'
+task :df do
+ folder = ENV['dir']
+ pattern = ENV['pattern'] || 'rb'
+ count = (ENV['count'] || 12).to_i
+ Dir["#{folder}/**/*.#{pattern}"].each_with_index do |file,index|
+ FileUtils.rm(file) if index > count
+ end
+end
+
+desc "sandbox db"
+task :box_db do
+ db = ENV['db'] || 'sandbox'
+ username = ENV['user'] || 'root'
+ password = ENV['password'] || ''
+ host = ENV['host'] || 'localhost'
+
+ file =<<-EOD
+common: &common
+ adapter: mysql
+ reconnect: false
+ pool: 5
+ host: #{host}
+ username: #{username}
+ password: #{password}
+
+development:
+ <<: *common
+ database: #{db}_development
+
+test:
+ <<: *common
+ database: #{db}_test
+
+production:
+ <<: *common
+ database: #{db}_production
+ EOD
+
+ current_dir = Dir.pwd.split("/").last
+ if(current_dir == 'config')
+ File.open("database.yml","w") { |fl| fl.write(file)}
+ else
+ cd("config") do
+ File.open("database.yml","w") { |fl| fl.write(file)}
+ end
+ end
+ ['production','development','test'].each do |db_env|
+ db_name = "#{db}_#{db_env}"
+ puts "Going to recreate #{db_name}"
+ system("mysqladmin -h #{host} -u #{username} -f drop #{db_name}")
+ system("mysqladmin -h #{host} -u #{username} -f create #{db_name}")
+ end
+end
+
+
+module Sake
+ class Git
+ def current_branch
+ cmd_output = `git symbolic-ref HEAD`
+ branch_name = cmd_output.strip.split("/")[-1]
+ branch_name
+ end
+ end
+ class Database
+ def truncate_db(db,username = 'root',password = '', host = 'localhost')
+ puts "Truncating Database : ".bold + db.red.bold
+ puts "** Press enter to continue **".green.bold
+
+ STDIN.getc
+ begin
+ connection = Mysql.connect(host,username,password,db)
+ result = connection.real_query("show tables")
+ tables = []
+ result.each_hash { |table| tables << table.values.first }
+ connection.real_query("set foreign_key_checks = 0;")
+ tables.each do |table|
+ puts "Truncating #{table}"
+ connection.real_query("truncate #{table}")
+ end
+ connection.real_query("set foreign_key_checks = 1;")
+ ensure
+ connection.close()
+ end
+ end
+
+ def delete_table(db,table_name,username = 'root',password = '',host = 'localhost')
+ begin
+ connection = Mysql.connect(host,username,password,db)
+ result = connection.real_query("drop table #{table_name}")
+ ensure
+ connection.close()
+ end
+ end
+ end
+
+end
+@git_help = Sake::Git.new()
+
+Rake.application.top_level()
View
10 screenrc
@@ -0,0 +1,10 @@
+#change the hardstatus settings to give an window list at the bottom of the
+#screen, with the time and date and with the current window highlighted
+hardstatus alwayslastline
+hardstatus string '%{= kG}%-Lw%{= kW}%50> %n%f* %t%{= kG}%+Lw%< %{= kG}%-=%c:%s%{-}'
+escape ``
+screen -t local 1
+screen -t work 0
+
+
+
View
18 search_file
@@ -0,0 +1,18 @@
+#!/bin/bash
+if [ ! -n "$1" ]
+ then
+ echo "****** Invalid Arguments *******"
+ echo "Usage: Search for a string."
+ exit 0
+fi
+search_string=$1
+echo -e ''"\033[1m************** :: Search Results for ${search_string} :: ************* \033[0m"
+find . -type f |egrep -v '\.(svn|png|jpg|jpeg|o|git|so|class|elc|rbx|rbc|a|bundle|dylib)'|while read x;
+#for x in `find . -type f |egrep -v '\.(svn|png|jpg|jpeg|o|git|so)'`
+do
+ if [ `egrep -c -e "$search_string" "$x"` -ne 0 ]
+ then
+ echo -e "\033[1m ------- :: $x :: ----------- \033[0m"
+ egrep -n -e "$search_string" "${x}" --color=always -C 1
+ fi
+done

0 comments on commit 25876b2

Please sign in to comment.
Something went wrong with that request. Please try again.