Skip to content

Instantly share code, notes, and snippets.

Max Howell mxcl

View GitHub Profile
@mxcl
mxcl / .profile
Created Apr 22, 2009
My Bash .profile file
View .profile
#!/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 Jun 5, 2009
Simplest functional FLAC to MP3 converter script you can make
@mxcl
mxcl / rsync+watcher.rb
Created Jul 18, 2009
rsync whenever the directory the script is in changes using the OS X FSEvents API
View rsync+watcher.rb
#!/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/'"
View this_is_a_bit_more_readable.rb
# 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 Nov 27, 2009
C code to watch a directory for changes
View fswatcher.c
// 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 Feb 4, 2010
Convenience script for running certain Applescripts
View tell
#!/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 Feb 6, 2010
Readable Base 62 encoder
View fixnum+base62.rb
# 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 Feb 24, 2010
Robert A. Heinlein Quote
View HeinleinQuote.md

“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 Mar 6, 2010
Installs Homebrew to /usr/local so you don't need sudo to `brew install`
@mxcl
mxcl / gist:360525
Created Apr 8, 2010
Make your Xcode templates less rubbish
View gist:360525
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'
You can’t perform that action at this time.