Skip to content

Instantly share code, notes, and snippets.

@brianstorti
brianstorti / insertion_sort.rb
Created May 3, 2011 14:41
Insertion sort in ruby
# Insertion sort (inefficient on large lists)
require 'test/unit'
def sort(a)
n = a.size - 1
1.upto(n) do |i|
new_value = a[i]
j = i
while j > 0 && a[j - 1] > new_value do
cd ~/Dropbox
mkdir -p repos/myrepo.git
cd !$
git --bare init
cd ~/Projects/myrepo
git remote add dropbox file://$HOME/Dropbox/repos/myrepo.git
git push dropbox master
@brianstorti
brianstorti / select_reject_collect.rb
Created May 29, 2011 17:19
Ruby - select x reject x collect
a = [1,2,3,4]
a.select{|n| n > 2} # 3,4
a.reject{|n| n > 2} # 1,2
a.collect{|n| n * 2} # 2,4,6,8
@brianstorti
brianstorti / dbi.rb
Created May 30, 2011 02:07
DBI example
require 'dbi'
begin
dbh = DBI.connect("DBI:Mysql:test:localhost", "root", "")
row = dbh.select_one("SELECT VERSION()")
puts "Server version: #{row[0]}"
rescue DBI::DatabaseError => e
puts "An error occurred"
ensure
dbh.disconnect if dbh
# Path to your oh-my-zsh configuration.
export ZSH=$HOME/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
export ZSH_THEME="prose"
# Set to this to use case-sensitive completion
@brianstorti
brianstorti / prose.zsh-theme
Created July 8, 2011 02:18
Prose theme for zsh
if [ "x$OH_MY_ZSH_HG" = "x" ]; then
OH_MY_ZSH_HG="hg"
fi
function virtualenv_info {
[ $VIRTUAL_ENV ] && echo '('`basename $VIRTUAL_ENV`') '
}
function hg_prompt_info {
$OH_MY_ZSH_HG prompt --angle-brackets "\
@brianstorti
brianstorti / gist:1081829
Created July 14, 2011 02:17
Delete on zsh
#add to .zshrc
bindkey "^[[3~" delete-char
bindkey "^[3;5~" delete-char
@brianstorti
brianstorti / gist:1105142
Created July 25, 2011 20:43
Oracle kill user session
# connected as sys
SELECT * FROM V$SESSION WHERE USERNAME LIKE 'CODEIT_BRIANSTORTI'
ALTER SYSTEM KILL SESSION 'sid,serial#' IMMEDIATE;
@brianstorti
brianstorti / gist:1106722
Created July 26, 2011 13:12
Oracle unlock user
ALTER USER <<USERNAME>> ACCOUNT UNLOCK
@brianstorti
brianstorti / gist:1107445
Created July 26, 2011 18:25
Add swap Ubuntu
sudo dd if=/dev/zero of=/swapfile bs=1M count=2048
sudo mkswap /swapfile
gksu gedit /etc/fstab
add to the end:
/swapfile none swap sw 0 0
reboot