Skip to content

Instantly share code, notes, and snippets.

View tommeier's full-sized avatar

Tom Meier tommeier

View GitHub Profile
#!/usr/bin/env ruby
require 'rubygems'
require 'yaml'
if ARGV.size < 1
puts "Usage: github-test.rb my-project.gemspec"
exit
end
require 'rubygems/specification'
#add this to your ~/.bash_profile and reload teminal
function delete_all_local_branches {
printf "\n\n\n\n== Would you like to delete ALL local branches? \nTHIS ACTION CANNOT BE UNDONE WITHOUT A WIZARDS HAT\nPlease select option (or any key to skip):\n"
echo "1) Delete all - (git branch branch_name -D)"
echo "-) Skip"
read -n1 -s -r -t30 INPUT
case "$INPUT" in
"1")
echo "== Deleting ALL local branches (please wait)..."
git for-each-ref --shell --format="%(refname)" refs/heads | \
class Something
CONSTANT_VALUES = ["Hooray - I have substance!", "Something Else"]
def self.do_something
puts "Constant value = #{Something::CONSTANT_VALUES.inspect}"
puts "Method Value = #{self.apply_something(Something::CONSTANT_VALUES)}"
end
def self.apply_something(values)
value_changed = [*values]
@tommeier
tommeier / Ruby Prof analysis
Created October 14, 2010 02:31
How to use Ruby Prof to analyse method
#Use ruby prof to analyse
require 'ruby-prof'
result = RubyProf.profile do
#Code to analyse in a method
end
# Print a graph profile to text
@tommeier
tommeier / gist:668606
Created November 9, 2010 02:00
Analyse your remote branches in origin (run in a git repo, with remote of origin)
function analyse_remote_branches {
printf "\n\n== Loading remote branches..\n"
git gc --prune=now
git remote prune origin
git for-each-ref --shell --format="%(refname)" refs/remotes/origin | \
while read branch
do
branch_name=${branch/refs\/remotes\/origin\//}
printf "\nRemote Branch : ${branch_name}\n"
result=`git log master..origin/${branch_name//\'/} --pretty=format:" -------> %h | %ar | %an | %s" --abbrev-commit --date-order --decorate -n 4`
@tommeier
tommeier / install_rvm.sh
Created February 10, 2011 00:20
Install RVM via bash script - Flawless Victory!
function install_rvm {
#Instructions : http://rvm.beginrescueend.com/rvm/install/
echo "===> Installing RVM >>"
bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )
#Reload shell
. ~/.rvm/scripts/rvm
result=`type rvm | head -1`
echo "===> Result of testing RVM : '$result'"
@tommeier
tommeier / remove_system_gems.sh
Created February 10, 2011 00:24
Remove all the old crufty system gems
#Uninstall crappy old system gems
function remove_system_gems {
echo "Uninstalling all system gems... This could take a while..."
for x in `gem list --no-versions`; do gem uninstall $x --all --quiet --ignore-dependencies --user-install --executables; done
#TODO : Add check for trailing slash and remove
system_location=$@
if [ "$system_location" == "" ]; then
system_location='/Library/Ruby/Gems/1.8'
fi
folder_names=( 'specifications' 'gems' 'cache' 'doc' 'bundler/gems' )
#Changing an existing (MASSIVE) app from old school rails 2.3.5 land to > 2.3.8 (switching it to 2.3.11) with things like rails_xss can be a nightmare. Mainly because *EVERYTHING* is suddenly html escaped.
#To quickly find EVERY incidence of html escaping where you don't want it, on your views edit your test framework that browses the site
#In this example, the test framework was Webrat, so i (bundle open webrat) found the root method for loading a page response, and scanned the response.body for harmful display items. This will then load the page and print during the tests. In webrat the file is session.rb and "def request_page(url, http_method, data)" is the root method. Webrat 0.7.3
def request_page(url, http_method, data) #:nodoc:
h = headers
h['HTTP_REFERER'] = @current_url if @current_url
@tommeier
tommeier / xvfb_daemon.sh
Created April 27, 2011 10:44
Xvfb startup init script for headless selenium with multiple displays for Jenkins or Teamcity CI server
#!/bin/bash
# /etc/init.d/xvfb_daemon
# Xvfb startup script.
# Tom Meier <tom@venombytes.com>
#
### BEGIN INIT INFO
# Provides: xvfb
# Short-Description: Start/stop/restart daemon
# Description: Controls the Xvfb daemon which starts/stops the X Virtual Framebuffer server
# Example Use:
@tommeier
tommeier / close_open_connections.sql
Created May 13, 2011 03:55
Close open sql connections in postgres for testing
SELECT COUNT(Pg_terminate_backend(procpid))
FROM pg_stat_activity
WHERE datname = '#{db_config[:database]}'
AND usename NOT IN (SELECT usename
FROM pg_user
WHERE usesuper);