Skip to content

Instantly share code, notes, and snippets.

View ahawthorne's full-sized avatar

Andrew Hawthorne ahawthorne

View GitHub Profile
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName site.lvh.me
ServerAlias www.site.lvh.me
DocumentRoot /var/www/site
<Directory /var/www/site>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
@ahawthorne
ahawthorne / en.yml
Last active December 18, 2015 21:59
Rails i18n format - eg. "Fri, 10/26/2012"
en:
hello: "Hello world"
time:
formats:
date_only1: "%a, %m/%d/%Y"
date:
formats:
date_only1: "%a, %m/%d/%Y"
@ahawthorne
ahawthorne / detect_ie.js
Last active December 17, 2015 20:19
JavaScript to detect IE version using conditional tags and add classes to the html tag.
window.ie = (function() {
var undef,
v = 3,
htmlClass = document.documentElement.className,
div = document.createElement('div'),
all = div.getElementsByTagName('span');
do {
div.innerHTML = '<!--[if gt IE ' + (++v) + ']><span></span><!endif]-->';
} while (all[0]);
@ahawthorne
ahawthorne / gist:3940260
Created October 23, 2012 17:37
search and replace, recalculate string-length in serialized array
<?php
$in = file_get_contents('input.sql');
// change domain(s)
$in = preg_replace('/old.example.com/', 'new.example.com', $in);
$in = preg_replace('/older.example.com/', 'newer.example.com', $in);
// recalculate string lengths in serialized arrays
$out = preg_replace('/s:(\d+):\\\"(.*?)\\\";/e', "'s:'.strlen('$2').':\"$2\";'", $in);
@ahawthorne
ahawthorne / .bashrc
Created May 18, 2012 20:10
msysgit ssh-agent
SSH_ENV="$HOME/.ssh/environment"
# start the ssh-agent
function start_agent {
echo "Initializing new SSH agent..."
# spawn ssh-agent
ssh-agent | sed 's/^echo/#echo/' > "$SSH_ENV"
echo succeeded
chmod 600 "$SSH_ENV"
. "$SSH_ENV" > /dev/null
@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;
@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 / 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 / .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 / .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