Skip to content

Instantly share code, notes, and snippets.

View ahawthorne's full-sized avatar

Andrew Hawthorne ahawthorne

View GitHub Profile
@ahawthorne
ahawthorne / .rvmrc
Created July 13, 2011 15:49
more useful .rvmrc
# enter your gemset below
rvm ruby-1.9.2-p180@eyd
# no need to edit below here
alias rails="bundle exec rails"
alias specjour="bundle exec specjour"
alias rspec="bundle exec rspec"
alias rake="bundle exec rake"
_VIM=$(which vim)
@ahawthorne
ahawthorne / .rvmrc
Created July 14, 2011 17:21
setup function for ~/.rvmrc
# This function will pull an .rvmrc from a gist and place it in a directory
# Add this function to /home/username/.rvmrc
#
# usage: setup_rvmrc gemset /path/to/application/
# example setup_rvmrc 1.9.2@app /var/www/app/
#
# NOTE: The trailing slash on the path is important.
function setup_rvmrc() {
_REPO="git://gist.github.com/1080580.git"
@ahawthorne
ahawthorne / .bash_profile
Created January 27, 2012 23:18
OSX ssh-agent forwarding -> .bash_profile
#####################
# ssh-agent stuff #
#####################
# get the ssh agent started
SSH_ENV="$HOME/.ssh/environment"
function start_agent {
echo "Initialising new SSH agent..."
/usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
echo succeeded
@ahawthorne
ahawthorne / build_redirect.sh
Created February 21, 2012 19:55
Build RerwiteRules from CSV
#!/bin/bash
# Pass in a csv file from STDIN as follows. No spaces.
#
# pattern,substitution
# pattern,substitution
if ! [ -t 0 ]; then
STDIN=`cat /dev/stdin`
fi
@ahawthorne
ahawthorne / views.php
Created March 9, 2012 03:36
Drupal 6 views 2.16 fix
#!/usr/bin/env php
<?php
// set some server variables so Drupal doesn't freak out
$_SERVER['SCRIPT_NAME'] = '/views';
$_SERVER['SCRIPT_FILENAME'] = '/views';
$_SERVER['HTTP_HOST'] = 'example.com';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['REQUEST_METHOD'] = 'POST';
@ahawthorne
ahawthorne / .gitignore
Created March 14, 2012 17:42
Wordpress .gitignore
wp-content/uploads/
wp-conten/files_mf/
stats/
wp-config.php
sitemap.xml
*.gz
*.sql
*.mysql
*.zip
@ahawthorne
ahawthorne / .vimrc-addon
Created March 14, 2012 23:13
Format horrible css in to readable css
" Add the map below to .vimrc as one long line.
" Restart vim, open horribly formatted css, press F9
" Then gg=G to fix formatting
" Win.
map <F9> :%s/\n\+\s*//g<CR>:%s/:[ ]*/:/g<CR>:%s/}/}\r\r/g<CR>:%s/;/;\r\t/g<CR>:%s/[ ]*{/ {\r\t/g<CR>:%s/\(\t\)\?\/\*\(.*\)\*\//\1\/\*\r\1\2\r\1\*\/\r\1/ge<CR>:%s/\(\t\)\?\/\*/\1\/\*\r\1/ge<CR>:%s/\(\n\+\)\?\(\t\)\?\*\//\r\2\*\/\r\2\1\2/ge<CR>:%s/^\t}/}/g<CR>:%s/\t\([^:]\+\):/\t\1: /g<CR>:%s/[ ]*!important/ !important/ge<CR>:%s/\t\n//ge<CR>:%s/\n\{3,\}/\r\r/ge<CR>:%s/\(\n^$\)\{2,\}//ge<CR>:let err=0<CR>:while err == 0<CR>try<CR> %s/^\([^,\t]\+\),\([^$]\)/\1,\r\2/g<CR>catch /^Vim\%((\a\+)\)\=:E/<CR>endtry<CR>:endwhile<CR>gg=G<CR>
@ahawthorne
ahawthorne / helpers.rb
Created March 28, 2012 17:48
ruby strip_tags and text_trim
def strip_tags(text)
return text.gsub(/<\/?[^>]*>/, "")
end
def text_trim(text, len, trail = '...')
if len < text.size then
text.scan(/.{1,#{len}} /) do |match|
return match.rstrip + trail
break
end
@ahawthorne
ahawthorne / fix example.sh
Created April 2, 2012 17:29
wordpress hacked. arg.
#!/bin/bash
# MAKE A BACKUP OF THE SITE!
# change directory to webroot
cd /var/www/hackedwordpresssite.com/html
# Get a list of files that contain the string "god_mode_off" and save it to a file
# command switches may differ depending on linux release
find . -type f -iname "*.php" | xargs -I{} grep -il god_mode_off {} > bad.list
@ahawthorne
ahawthorne / settings.php
Created April 13, 2012 03:21
Fix for Content Translation - Ubercart checkout SSL issue
<?php
function custom_url_rewrite_outbound(&$path, &$options, $original_path) {
global $base_url;
if (strstr($base_url, 'https')) {
switch (true) {
case ((bool) strstr($path, 'cart/checkout')):
case ((bool) strstr($path, 'uc_js_util')):
case ((bool) strstr($path, 'admin_menu')):
$options['base_url'] = str_replace('http','https',$options['base_url']);
break;