Skip to content

Instantly share code, notes, and snippets.

View mxcl's full-sized avatar

Max Howell mxcl

View GitHub Profile
@mxcl
mxcl / .profile
Created April 22, 2009 16:13
My Bash .profile file
#!/bin/bash
alias ..="cd .."
alias ls="ls -p"
alias la="ls -lA"
alias l="ls -l"
alias ll="ls -l"
alias psf="ps -cU `whoami`"
alias grep="grep --color=auto"
alias cack="ack --cpp"
@mxcl
mxcl / flac2mp3.md
Created June 5, 2009 11:28
Simplest functional FLAC to MP3 converter script you can make
@mxcl
mxcl / rsync+watcher.rb
Created July 18, 2009 09:32
rsync whenever the directory the script is in changes using the OS X FSEvents API
#!/usr/bin/ruby
require 'osx/foundation'
OSX.require_framework '/System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework'
include OSX
$d=File.basename Dir.pwd
Dir.chdir '..'
fsevents_cb = proc do |stream, ctx, numEvents, paths, marks, eventIDs|
system "rsync --delete -rt --rsh=ssh '#{$d}' 'methylblue.com:public_html/'"
# This is more "Ruby", and I agree that I don't necessarily agree with
# all the syntax choices. The else condition isn't required as the
# function returns nil if no other code paths executed. You could argue
# that, that is a regression waiting to happen though.
def just_one_kind_of_response? item, controller
case controller
when 'actions'
item.comments.blank? or item.suggestions.blank? or detail.comments.blank?
when 'thoughts'
@mxcl
mxcl / fswatcher.c
Created November 27, 2009 10:38
C code to watch a directory for changes
// gcc -o fswatcher -framework Carbon fswatcher.c
#include <CoreServices/CoreServices.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/dir.h>
static time_t timestamp = 0;
static void callback(ConstFSEventStreamRef stream,
@mxcl
mxcl / tell
Created February 4, 2010 13:40
Convenience script for running certain Applescripts
#!/usr/bin/ruby
#
# Example usage:
# tell iTunes to pause
# tell iTunes to play
# tell Linkinus to quit
#
# http://twitter.com/mxcl
# we add it back later
@mxcl
mxcl / fixnum+base62.rb
Created February 6, 2010 16:17
Readable Base 62 encoder
# Use this for your URL shortening needs
# Base 62 is as good as you can easily get for URL shortening
# And it's effective: 1_000_000 => '4c92'
# Challenge: fork and speed up the implementation!
class Fixnum
TOKENS = ('0'..'9').to_a + ('a'..'z').to_a + ('A'..'Z').to_a
# NOTE returns nil for 0
def to_62_s
@mxcl
mxcl / HeinleinQuote.md
Created February 24, 2010 17:34
Robert A. Heinlein Quote

“A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly. Specialization is for insects.”

I think it's from “The moon is a harsh mistress”

@mxcl
mxcl / install_homebrew.markdown
Created March 6, 2010 15:14
Installs Homebrew to /usr/local so you don't need sudo to `brew install`
@mxcl
mxcl / gist:360525
Created April 8, 2010 20:52
Make your Xcode templates less rubbish
def inreplace path, before=nil, after=nil
[*path].each do |path|
f = File.open path, 'r'
s = f.read.gsub before, after
f.reopen(path, 'w').write s
f.close
end
end
require 'pathname'