Skip to content

Instantly share code, notes, and snippets.

@gnarmis
gnarmis / .emacs.minimal
Last active August 29, 2015 14:01
Minimal Emacs Config for Fast Startup
; Want a fast emacs startup? Copy this to ~/.emacs.minimal and:
;
; cp ~/.emacs ~/.emacs.bak
; echo "(load-file \"/absolute/path/to/.emacs.minimal\")" > ~/.emacs
;
; Switch it back if you don't like it.
;
;; cutoff for word wrap
(setq-default fill-column 79)
@gnarmis
gnarmis / git-recent-branches
Last active August 29, 2015 14:01
List Git Branches by Recency
#!/bin/bash
#
# Blame @gnarmis if this doesn't work
#
# Put this anywhere on your $PATH (~/bin is recommended). Then git will see it
# and you'll be able to do `git recent-branches`.
#
# Show top 5 most recent branches:
# $ git recent-branches | head -n 5
#
@gnarmis
gnarmis / gist:0d08ad5603014efea52f
Last active August 29, 2015 14:02
Swift on the Command Line
So, this is where swift lives, after you've installed XCode 6 Beta:
/Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift
Also, there's a directory named swift which has various libraries:
/Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift
To start playing in a terminal:
ruby-1.9.2-p180 :001 > cat = Object.new
=> #<Object:0x0000010085bc58>
ruby-1.9.2-p180 :002 > puts cat.methods.sort
!
!=
!~
<=>
==
===
=~
ruby-1.9.2-p180 :004 > def cat.has_nine_lives?
ruby-1.9.2-p180 :005?> true
ruby-1.9.2-p180 :006?> end
=> nil
ruby-1.9.2-p180 :007 > cat.has_nine_lives?
=> true
@gnarmis
gnarmis / gist:1050563
Created June 28, 2011 05:43
Finding the Largest Prime Factor of a Composite Number
def maxPrimeFactor(n) #=> maxPrimeFactor(600851475143) => 6857 in 2007.562 ms
# limit the ridiculous range safely
range = n**(1/Math.sqrt(n.to_s.length).floor.to_f)
ary = (1..range).to_a
# Sieve of Eratosthenes (replace with Sieve of Atkin?)
for i in ary
for j in ary
if i != j
if (j % i == 0)
ary.delete(j)
@gnarmis
gnarmis / sassycoffee.sh
Created August 9, 2011 21:23
Single script to watch and compile both CoffeeScript and Sass files
#!/bin/bash
# run `compass watch` at pwd
# run `coffee -o scripts/ -cw coffee/` at pwd
type -P compass &>/dev/null || { echo "Compass command not found."; exit 1; }
type -P coffee &>/dev/null || { echo "Coffee command not found."; exit 1; }
if [ ! -d sass/ ] || [ ! -d scripts/ ]
then
echo "Project not setup correctly! Put sass files in sass/ and coffee in coffee/"
else
@gnarmis
gnarmis / piping_example.rb
Created September 19, 2012 21:09
Piping arguments through multiple functions in Ruby
# piping example in Ruby
def foo(data)
data[:a] += 1
data
end
def bar(data)
data[:b] += 10
data
@gnarmis
gnarmis / functional_hash.rb
Created September 26, 2012 16:57
Ruby Hashes as functions of keys to values
# In Clojure, hash-maps are truly functions of keys to values.
# So you can do `(:a {:a 1})` and get `1` as the result
# Why not put this in Ruby?
# access keys of a hash like a function
class Object
def respond_to?(method)
if (method.to_s =~ /^_.*/) == 0
true
@gnarmis
gnarmis / example_user.json
Created December 7, 2012 03:19
Example Twitter User Features
"user": {
"contributors_enabled": false,
"created_at": "Wed Sep 23 18:48:46 +0000 2009",
"default_profile": false,
"default_profile_image": false,
"description": "Mura is a Japanese Fusion Restaurant serving steak, sushi, seafood. Located in North Hills. Serving lunch and dinner.",
"favourites_count": 0,
"follow_request_sent": null,
"followers_count": 665,
"following": null,