Skip to content

Instantly share code, notes, and snippets.

View anaynayak's full-sized avatar

Anay Nayak anaynayak

View GitHub Profile
@anaynayak
anaynayak / ps1_chef_node_name
Created March 30, 2012 15:18
Set terminal prompt based on chef client node name
export PS1="\[\e[36;1m\]\u@\[\e[32;1m\]`cat /etc/chef/client.rb | grep node_name |sed 's/node_name "\(.*\)\"/\1/'` \w\a\e[32;1m\]> \[\e[0m\]"
@anaynayak
anaynayak / sshgen.rb
Created April 7, 2012 02:38 — forked from warwickp/sshgen.rb
Knife plugin to generate OpenSSH config file from a Chef search
## Knife plugin to generate an OpenSSH config file from a Chef search
# From Harvest. www.getharvest.com
#
# Source: https://github.com/harvesthq/knife-plugins
#
# See http://wiki.opscode.com/display/chef/Knife+Plugins
# See http://www.openbsd.org/cgi-bin/man.cgi?query=ssh_config&sektion=5
#
## Install
# Place in .chef/plugins/knife/sshgen.rb
# (1) copy the newrelic rpm java client into #{RAILS_ROOT}/solr/newrelic
# (2) add a newrelic.yml in that directory with you API key
# (3) add this monkey patch in an initializer to load newrelic with the solr server
Sunspot::Rails::Server.class_eval do
def run
command = ['java']
command << "-Xms#{min_memory}" if min_memory
command << "-Xmx#{max_memory}" if max_memory
command << "-Djetty.port=#{port}" if port
command << "-Dsolr.data.dir=#{solr_data_dir}" if solr_data_dir
@anaynayak
anaynayak / nc.py
Last active December 17, 2015 17:18
import socket
import sys
host = sys.argv[1]
port = int(sys.argv[2])
sock = socket.socket()
sock.connect((host,port))
print sock.recv(4096)
sock.close
@anaynayak
anaynayak / fix_all_evil_things.sh
Last active December 21, 2015 04:28
Handy script to clean up bad code
#!/bin/sh
rm -rf *
mv .git/config /tmp/git_config
rm -rf .git
git init
mv -f /tmp/git_config .git/config
touch .gitignore
git add .
git commit -m "Code cleanup"
git push -f
@anaynayak
anaynayak / Berksfile
Created August 19, 2013 16:47
Vagrantfile with proxy support, custom chef version installation using vagrant-omnibus, vagrant-cachier for caching packages, vagrant-butcher for managing vagrant chef client and node lifecycle, vagrant-berkshelf for pulling opscode cookbooks.
site :opscode
cookbook 'ntp'
@anaynayak
anaynayak / url_requests.js
Created October 9, 2013 13:38
phantom.js script to log all http requests from a page
var page = require('webpage').create(),
system = require('system'),
address;
if (system.args.length === 1) {
console.log('Usage: phantomjs url_requests.js http://some.url.com');
phantom.exit(1);
} else {
address = system.args[1];
var logUrl = function (req) {
@anaynayak
anaynayak / recursive-git.zsh
Created February 24, 2014 05:03
A 'git' function that lets you recursively fire the same git command.
function git {
if [ -d .git ]; then
/usr/bin/git $*
else
for dir in $(find . -maxdepth 2 -name ".git"); do
cd ${dir%/*}
/usr/bin/git $*
cd -
done
fi
#!/bin/sh
# /etc/init.d/tightvncserver
VNCUSER='pi'
case "$1" in
start)
su $VNCUSER -c '/usr/bin/tightvncserver :1'
echo "Starting TightVNC Server for $VNCUSER "
;;
stop)
pkill Xtightvnc
@anaynayak
anaynayak / fq
Last active November 5, 2015 16:37
#!/usr/bin/env python
import sys
import json
from collections import OrderedDict
opts = {
'format' : 'txt',
'keys' : sys.argv[1:]
}