Skip to content

Instantly share code, notes, and snippets.

View dillonhafer's full-sized avatar
🍄
Nintendo Power

Dillon Hafer dillonhafer

🍄
Nintendo Power
View GitHub Profile
SET @oldsite = 'http://www.oldsite.com';
SET @newsite = 'http://www.newsite.com';
UPDATE wp_options SET option_value = replace(option_value, @oldsite, @newsite) WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = REPLACE (guid, @oldsite, @newsite);
UPDATE wp_posts SET post_content = REPLACE (post_content, @oldsite, @newsite);
UPDATE wp_postmeta SET meta_value = REPLACE (meta_value, @oldsite, @newsite);
@dillonhafer
dillonhafer / grc.rb
Created August 28, 2014 02:10
Get random passwords from GRC
require 'nokogiri'
require 'open-uri'
class Grc
attr_accessor :hex, :ascii, :alpha
PAGE_URL = "https://www.grc.com/passwords.htm"
def initialize
chars = fetch
@hex = chars[0].text
@dillonhafer
dillonhafer / space.sh
Created September 12, 2014 18:59
Determine how much space a file or directory takes on disk.
#!/bin/bash
function space {
SEARCH_PATH='.'
if (( $# == 1 ))
then
SEARCH_PATH=$1
fi
du -ch $SEARCH_PATH | grep total
}
@dillonhafer
dillonhafer / rails_version.sh
Created October 7, 2014 16:25
Check for the current version of Rails
function rails_version {
if (( $# == 1 )); then
VERSION="$1-stable"
else
VERSION='master'
echo -e "\033[1;33mUsage: rails_version [BRANCH]\033[0m"
echo -e "\033[1;33mExample: rails_version 4-1\033[0m"
fi
URL="https://raw.githubusercontent.com/rails/rails/$VERSION/RAILS_VERSION"
VERSION_NUMBER=$(curl -s $URL)
@dillonhafer
dillonhafer / example.md
Created November 19, 2014 06:44
Emoji spinner in ruby

You can display a spinning clock while performing network tasks.

puts "Starting nmap scan..."
scan_results = ""
spin_during {
  scan_results = %x(nmap -Pn dillonhafer.com)
}
puts scan_results
@dillonhafer
dillonhafer / functions.sh
Last active August 29, 2015 14:10
Push local database to heroku
function dumper {
if (( $# != 1 )); then
echo "Usage: dumper [DATABASE]"
echo "Creates pg_dump: pg_dump -Fc --no-acl --no-owner DATABASE > DATABASE.dump"
else
pg_dump -Fc --no-acl --no-owner $1 > $1.dump
fi
}
function push_dev_db {
@dillonhafer
dillonhafer / translate-to-spanish
Created November 25, 2014 19:30
Translate selected text to Spanish with Google translate
on run {input, parameters}
tell application "Google Chrome"
set newTab to make new tab at end of tabs of window 1
set translateURL to "https://translate.google.com/#auto/es/"
set URL of newTab to translateURL & input
end tell
return input
end run
@dillonhafer
dillonhafer / spec_prepare.rake
Created March 12, 2015 14:52
Cloning the dev env for tests using MySql
namespace :spec do
task :clone_structure do
environments = YAML.load(File.read('config/database.yml'))
test = environments["test"]
dev = environments["development"]
puts "Deleting #{test["database"]}..."
`echo 'DROP DATABASE #{test["database"]};' | mysql -u #{test["username"]} -p'#{test["password"]}'`
puts "Creating #{test["database"]}..."
`echo 'CREATE DATABASE #{test["database"]};' | mysql -u #{test["username"]} -p'#{test["password"]}'`
puts "Importing schema into #{test["database"]} from #{dev["database"]}..."
@dillonhafer
dillonhafer / AppleWiredKeyboard.ahk
Created March 31, 2015 13:27
Mac style command keys for windows
; IMPORTANT INFO ABOUT GETTING STARTED: Lines that start with a
; semicolon, such as this one, are comments. They are not executed.
; This script has a special filename and path because it is automatically
; launched when you run the program directly. Also, any text file whose
; name ends in .ahk is associated with the program, which means that it
; can be launched simply by double-clicking it. You can have as many .ahk
; files as you want, located in any folder. You can also run more than
; one ahk file simultaneously and each will get its own tray icon.
@dillonhafer
dillonhafer / ping-log.sh
Created April 16, 2015 12:03
How to log ping with a timestamp
ping 8.8.8.8 | while read pong; do echo "$(date): $pong"; done | tee > ~/Desktop/ping.log