Skip to content

Instantly share code, notes, and snippets.

View sandys's full-sized avatar

Sandeep Srinivasa sandys

View GitHub Profile
# history
HISTFILE=~/.zsh_history
HISTSIZE=10000
SAVEHIST=100000
setopt appendhistory autocd extendedglob
setopt EXTENDED_HISTORY # puts timestamps in the history
BLACK="%{"$'\033[01;30m'"%}"
GREEN="%{"$'\033[01;32m'"%}"
@sandys
sandys / rails.md
Created March 18, 2011 07:33
random tidbits about rails

You need to create a getter and setter method to create a virtual attribute

 def full_name
  [first_name, last_name].join(' ')
 end

 def full_name=(name)
  split = name.split(' ', 2)
  self.first_name = split.first
  self.last_name = split.last

end

@sandys
sandys / search_api.rb
Created March 22, 2012 15:48
Ruby script to talk to google custom search api
require 'google/api_client'
client = Google::APIClient.new(:key => 'something')
client.authorization = nil
search = client.discovered_api('customsearch')
offset = 100
1.step(10,10) do |i|
#cx is gotten from the API registration page
@sandys
sandys / gist:2428218
Created April 20, 2012 12:36
debugging SOAP services
sudo tcpdump -A -i wlan0 |& tee /tmp/out
figure out the exact post command and use net/http to execute it
@sandys
sandys / hn-stylesheet
Created April 21, 2012 08:26
stylesheet for HN
body { margin: 35px 0 0; } table { background: none; } /* header */ table td[bgcolor] { margin: 0 0 20px 0; padding: 5px; display: block; background-color: #eee; position: fixed; z-index: 100; top: 0; left: 0; width: 100%; box-sizing: border-box; } table td[bgcolor] b a { font-size: 12px; width: 99px; } table td[bgcolor] a { font-size: 12px; } .pagetop b { margin-right: 20px; } table tr[style]:nth-child(2) { height: 15px ; } tbody tr:nth-child(3) table { margin-left: 0; display: block; } tbody tbody tr:nth-child(3n) { height: 12px ; } tbody tr:nth-child(3n) table { width: 100%; } tbody { position: relative; } /* hide numbering */ tbody tbody td.title:first-child { font-size: 1px; visibility: hidden; } .title:nth-child(3) { position: relative; z-index: 1; padding: 0 0 2px 0; } .title a { font-size: 14px; } .title a:visited { color: #999; } .subtext { padding: 2px 0; color: #fff; position: relative; } .subtext * { z-index: 10; color: #444; } /* points */ .subtext span { font-weight: bold; position: absolute; le
@sandys
sandys / hdparm.conf
Created May 1, 2012 14:53
raid setup on providerservice
#get data about current RAID
#1 block = 1kb
cat /proc/mdstat
mdadm --detail --scan
#to get to the real fstab
mount /dev/md1 /tmp/1
vi /tmp/1/etc/fstab #find out the md # of the partition that u want to reformat
mdadm --detail /dev/md6 #more details about that partition, especially the /dev/sda6 + /dev/sdb6 info
@sandys
sandys / secure_servers
Created May 3, 2012 07:50
Securing server processes by creating a non-privileged user to run commands
#add a system user
sudo adduser --system --home=/opt/openerp --group openerp
#copying config files to correct locations
#The below commands make the file owned and writeable only by the openerp user and group and only readable by openerp #and root.
sudo cp /opt/openerp/server/install/openerp-server.conf /etc/
sudo chown openerp: /etc/openerp-server.conf
sudo chmod 640 /etc/openerp-server.conf
#running the command
@sandys
sandys / etc_monit_conf.d_localhost
Created May 4, 2012 12:59
secure and self contained ruby deployment with multiple load-balanced, boot-persistent and highly available thin servers, and a multi-user rvm environment
set httpd port 2812 and # Monit will run on port 2812
allow sss:sss123 #set your username and password to loin to your Monit
@sandys
sandys / postgres.sh
Created May 9, 2012 07:54
postgresql master slave setup on the same machine
pg_createcluster 9.1 testing --start #/etc/postgresql/9.1/testing/
pg_lsclusters
pg_dropcluster 9.1 testing --stop
#follow with rm -rf or potential error
rm -rf /var/lib/postgresql/9.1/testing/
Moved the Write Ahead Log (WAL) to its own partition (so fsyncs of the WAL don't flush all of the dirty data files)
@sandys
sandys / gitolite_setup.sh
Created May 18, 2012 04:37
Gitolite installation using a secure user
#Notice that when we created the user, we used –disable-password, which prevents us logging into the machine using a password. Therefore we’ll need to upload a ssh key for running the installer. Here, I will create a public and private keypair with the name id_rsa_gitolite.
sudo adduser --system --shell /bin/bash --gecos 'git version control' --group --disabled-password --home /home/gitolite gitolite