Skip to content

Instantly share code, notes, and snippets.

View Grayson's full-sized avatar

Grayson Hansard Grayson

View GitHub Profile
@Grayson
Grayson / getDefaultAppForURL.py
Created October 4, 2008 19:56
Get default application for url schemes.
#!/usr/bin/env python
# usage: python getDefaultAppForURL.py 'http://' 'ftp://' 'afp://'...
from LaunchServices import LSGetApplicationForURL, kLSRolesViewer
from Foundation import NSURL
from sys import argv
for arg in argv[1:]:
url = NSURL.URLWithString_(arg)
if url == None: continue
@Grayson
Grayson / updateWebkit.sh
Created October 8, 2008 01:34
A WebKit.app updater script.
#!/usr/bin/env bash
# Echo some information to STDOUT as well as show a growl notification if available
function notify {
if [[ -f /usr/local/bin/growlnotify ]]; then
echo $1 | /usr/local/bin/growlnotify "Updating WebKit"
fi
echo $1
}
@Grayson
Grayson / git-hash-from-commit-number
Created October 11, 2008 14:43
Prints a git hash based on commit number.
#!/usr/bin/env python
# Grayson Hansard, 2008
# This is a simple python script that I wrote as part of a system to
# use the number of git commits on a project as an incremental build number system.
import os, sys
if len(sys.argv) < 2:
print "Usage git hash-from-commit-number <commit-number>"
// Simple way of getting a list of ivar names for an Objective-C class.
#import <objc/runtime.h>
@interface NSObject (ivars)
-(NSArray *)ivars {
unsigned int ivarCount = 0;
Ivar *ivars = class_copyIvarList([self class], &ivarCount);
if (ivars && ivarCount) {
NSMutableArray *array = [NSMutableArray array];
@Grayson
Grayson / isOptionKeyPressed.scpt
Created August 18, 2011 14:03
Applescript snippet to test if Option key is held down.
on isOptionKeyPressed()
return (do shell script "/usr/bin/python -c 'import Cocoa; print Cocoa.NSEvent.modifierFlags() & Cocoa.NSAlternateKeyMask > 1'") is "True"
end isOptionKeyPressed
@Grayson
Grayson / gist:1707245
Created January 30, 2012 22:37
Quick calculation of the number of git commands in your bash history.
# Just copy and paste the following into your shell prompt.
echo "scale=4;" `cat ~/.bash_history | grep -e "^ *git" | wc -l` "/" `cat ~/.bash_history | wc -l` " * 100" | bc
@Grayson
Grayson / gist:1707428
Created January 30, 2012 23:16
Recent git command breakdown
#!/usr/bin/env bash
total=`cat ~/.bash_history | grep -e "^ *git" | awk '{print $1}' | sort | uniq -c | awk '{print $1}'`
oldifs=$IFS
IFS=$'\n'
for l in `cat ~/.bash_history | grep -e "^ *git" | awk '{print $2}' | sort | uniq -c`; do
count=`echo $l | awk '{print $1}'`
gitcmd=`echo $l | awk '{print $2}'`
percentage=`echo "scale=4; $count / $total * 100" | bc`

Keybase proof

I hereby claim:

  • I am Grayson on github.
  • I am Grayson (https://keybase.io/Grayson) on keybase.
  • I have a public key whose fingerprint is C240 DA4B 8327 D87F F17C D56D 40C3 43A9 4889 DCCF

To claim this, I am signing this object:

@Grayson
Grayson / reeder-opml.py
Created April 11, 2014 18:24
Import OPML into Reeder-Mac
import os
import shutil
import sqlite3
from sys import argv
from xml.dom.minidom import parse
def dom_element_to_insert(elem):
return (elem.getAttribute('xmlUrl'),elem.getAttribute('text'), elem.getAttribute('title'), elem.getAttribute('htmlUrl'))
def main(path_to_opml):
@Grayson
Grayson / crayons.tsv
Created December 13, 2015 19:42
Color values from OSX's "Crayon" color picker pane
Name CSS Hex R G B
Licorice #000000 0x000000 0 0 0
Lead #191919 0x191919 25 25 25
Tungsten #333333 0x333333 51 51 51
Iron #4C4C4C 0x4C4C4C 76 76 76
Steel #666666 0x666666 102 102 102
Tin #7F7F7F 0x7F7F7F 127 127 127
Nickel #808080 0x808080 128 128 128
Aluminum #999999 0x999999 153 153 153
Magnesium #B3B3B3 0xB3B3B3 179 179 179