Skip to content

Instantly share code, notes, and snippets.

@nbrew
nbrew / migration_name.sh
Created May 6, 2011 22:21
Capture migration file name after script/generate migration
echo "exists db/migrate
create db/migrate/20110506220427_add_shared_column_to_resources.rb
"| head -n 2 | tail -n 1 | sed -e 's/.*create[[:space:]]*\(db\/migrate\)/\1/'
@nbrew
nbrew / add_gitosis_origin.sh
Created July 5, 2011 21:32
Simple script for adding existing project to git/gitosis
# from http://snippets.aktagon.com/snippets/329-Simple-script-for-adding-existing-project-to-git-gitosis
GIT_USER=git
SERVER=xxx.com
APP=xxx
touch tmp/.gitignore log/.gitignore vendor/.gitignore
find . -type d -empty | grep -v "vendor" | grep -v ".git" | grep -v "tmp" | xargs -I xxx touch xxx/.gitignore
cat <<EOF<<EOF >>.gitignore
@nbrew
nbrew / bulk_svn_to_git.sh
Created July 6, 2011 01:18
Migrate a list of existing svn repositories to git using svn2git
#!/bin/bash
set -v # verbose output
#
# Migrate a list of existing subversion repositories to git using svn2git. Assumes
# the following repository layouts:
# svn://example.com/<repository>/
# assets/
# branches/
# trunk/
@nbrew
nbrew / config_deployment_user.sh
Created July 6, 2011 23:29
Add a new user, group and generate keys for that user.
#!/bin/bash
set -v
function usage() {
echo ""
echo "usage: ./$0 deployment_username [deployment_group]"
echo ""
echo "Examples:"
echo " ./$0 marshmallow deployers"
exit 1
@nbrew
nbrew / authinabox.rb
Created December 7, 2011 20:29 — forked from peterc/gist:40246
Single File Data Mapper Authentication for Sinatra
# NAME: authinabox
# VERSION: 1.01 (Dec 27, 2008)
# AUTHOR: Peter Cooper [ http://www.rubyinside.com/ github:peterc twitter:peterc ]
# DESCRIPTION: An "all in one" Sinatra library containing a User model and authentication
# system for both session-based logins OR HTTP Basic auth (for APIs, etc).
# This is an "all in one" system so you will probably need to heavily tailor
# it to your own ideas, but it will work "out of the box" as-is.
# COMPATIBILITY: - Tested on 0.3.2 AND the latest rtomayko Hoboken build! (recommended for the latter though)
# - NEEDS DataMapper!
# - Less work needed if you use initializer library -- http://gist.github.com/40238
@nbrew
nbrew / kerio-connect-monit-config
Created February 3, 2012 17:51
Kerio Connect Monit Configuration
#
# for use on linux systems with kerio-connect installed via rpm
#
check process kerio-connect with pidfile /var/run/kms.pid
group mail
start program = "/etc/init.d/kerio-connect start"
stop program = "/etc/init.d/kerio-connect stop"
if failed host 127.0.0.1 port 25 protocol smtp then restart
if 5 restarts within 5 cycles then timeout
depends on kerio_mailserver_bin
@nbrew
nbrew / ipalindromei.rb
Created February 9, 2012 00:31
Largest palindrome made from the product of two 3-digit numbers.
# http://projecteuler.net/problem=4
def palindrome? s
s.to_s == s.to_s.reverse
end
products = []
nums = (100..999).to_a
nums.each do |n|
nums.each do |x|
products << product if palindrome? n*x
@nbrew
nbrew / disable_sleep_proxy_client.sh
Created February 29, 2012 22:32
Mac OS X 10.6 DNS Failure After Sleep Fix
#!/bin/bash
# add the -DisableSleepProxyClient flag to mDNSResponder.plist
sudo sed -i -e \
's#\(<string>-launchd\)\(</string>\)#\1 -DisableSleepProxyClient\2#' \
/System/Library/LaunchDaemons/com.apple.mDNSResponder.plist
@nbrew
nbrew / gist:1952490
Created March 1, 2012 19:30
DNS Troubleshooting Excerpt
scutil --dns shows:
resolver #1
domain : comcast.net.
nameserver\[0] : 208.67.222.222
nameserver\[1] : 208.67.220.220
order : 200000
Indeed, /etc/resolv.conf was generated as:
@nbrew
nbrew / install_w3af.sh
Created March 1, 2012 23:11
Install w3af with requirements on Mac OS X
#!/bin/bash
# Attempts to install the web application vulnerability scanner w3af and it's prerequisites.
# For more information about w3af, see: http://w3af.sourceforge.net/
# USAGE: pypi_install package_name version_number md5_checksum
# checksum is optional; package and version are required
function pypi_install() {
name=$1
version=$2