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
@dillonhafer
dillonhafer / safari-google-song.osa
Last active October 24, 2017 16:43
Get currently playing song/artist in Google Play
#!/usr/bin/osascript
#
# Usage ./safari-google-song.osa [tab url]
#
# Example: ./safari-google-song.osa play.google.com
# Example: ./safari-google-song.osa spotify.com
on replace_chars(this_text, search_string, replacement_string)
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
@dillonhafer
dillonhafer / cheats-database.xml
Last active March 22, 2018 18:53
Cheat database to auto-load OpenEmu Gameshark codes
<?xml version="1.0" encoding="UTF-8"?>
<systems>
<system id="openemu.system.gb">
<game title="Pokemon - Silver Version (USA, Europe)">
<hashes>
<hash md5="2ac166169354e84d0e2d7cf4cb40b312"/>
</hashes>
<cheats>
<cheat code="019973D5+019974D5+019975D5" type="GameShark" description="Infinite Money"/>
<cheat code="01277AD5+010F7BD5" type="GameShark" description="Infinite Casino Coins"/>
@dillonhafer
dillonhafer / opentabs.scpt
Created July 12, 2017 13:19
Apple script for iTerm
#!/usr/bin/osascript
tell application "iTerm2"
tell current window
set serverTab to (create tab with default profile)
tell sessions[1] of serverTab to split vertically with default profile
tell sessions[1] of serverTab to write text "yarn start"
tell sessions[2] of serverTab to write text "yarn run watch-css"
select first tab
end tell
@dillonhafer
dillonhafer / database.yml
Last active May 31, 2017 17:15
Dynamic Database YAML
<% branch = `git rev-parse --abbrev-ref HEAD`.match(/(PHI-\d+)/).try(:captures).try(:first) || "development" %>
default: &default
adapter: postgresql
encoding: unicode
pool: 5
timeout: 5000
variables:
statement_timeout: 15000
@dillonhafer
dillonhafer / host_and_port.rb
Created May 28, 2017 22:20
Get the development server host and port in Rails 3,4,5
# Rails 5.1
require 'rails/commands/server/server_command'
# Rails 5.0
require 'rails/commands/server'
def __host_and_port__
options = Rails::Server::Options.new.parse!(ARGV)
options.values_at(:Host, :Port)
end
@dillonhafer
dillonhafer / post-checkout
Last active May 15, 2017 17:18
Use a different database per git branch
branch=$(git rev-parse --abbrev-ref HEAD | grep -o 'PHI-\d*')
if [[ -z "$branch" ]]; then
issue="development"
fi
db="s/^DATABASE_URL=.*/DATABASE_URL=postgresql:\/\/localhost\/phishing_$branch/"
sed -i '' $db .env
function gonew {
if (( $# == 1 )); then
new_project="$GOPATH/src/github.com/dillonhafer/$1"
if [ -d "$new_project" ]; then
echo -e "\033[0;31mProject already exists\033[0m"
return
fi
mkdir -p $new_project
cd $new_project

Keybase proof

I hereby claim:

  • I am dillonhafer on github.
  • I am dillonh (https://keybase.io/dillonh) on keybase.
  • I have a public key ASBy5iE6KvFce-o4RviZEeJAyOQMsQCZYsNDvhMbhzl-2Qo

To claim this, I am signing this object:

@dillonhafer
dillonhafer / pre-commit
Last active January 25, 2017 16:38
Pre-commit hook for jira branches
#!/bin/sh
#
# Given a branch name like "feature/PHI-432-use-citext-emails"
#
# And .git/config has the following line
#
# [commit]
# template = ~/.gitmessage.projectA
#
# Then empty commit messages have [PHI-432] after the second line.
@dillonhafer
dillonhafer / Tabular.rb
Last active January 10, 2017 22:37
Great way to parse tables with capybara - h/t https://github.com/briandunn
module Tabular
module TableHelper
def columns(*column_names)
map {|row| row.slice(*column_names) }
end
alias column columns
end
def hashes_from_table(selector='table')
actual = find(selector)