Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

{
/* Keybindings for emacs emulation. Compiled by Jacob Rus.
*
* To use: copy this file to ~/Library/KeyBindings/
* after that any Cocoa applications you launch will inherit these bindings
*
* This is a pretty good set, especially considering that many emacs bindings
* such as C-o, C-a, C-e, C-k, C-y, C-v, C-f, C-b, C-p, C-n, C-t, and
* perhaps a few more, are already built into the system.
*
@gnarmis
gnarmis / yummly-api.clj
Last active December 14, 2015 17:59
Yummly API
(defn yummly-api [auth]
{:endpoint "http://api.yummly.com/v1"
:resources {:recipe-search "/api/recipes"}
:params ["q", "requirePictures", "allowedIngredient[]", "excludedIngredient[]",
"allowedDiet[]", "allowedAllergy[]", "allowedCuisine[]",
"allowedCourse[]", "allowedHoliday[]", "excludedCuisine[]",
"excludedCourse[]", "excludedHoliday[]", "maxTotalTimeInSeconds",
"nutrition.ATTR.{min|max}", "maxResult", "start",
"flavor.ATTR.{min|max}", "facetField[]"]
:auth {"_app_id" (:app-id auth),
@gnarmis
gnarmis / minmaxheap.py
Created January 27, 2013 10:01
min max heap implementation in python
from math import log, floor, pow
class MinMaxHeap(object):
"""an implementation of min-max heap using an array,
which starts at 1 (ignores 0th element)
"""
def __init__(self, array=[]):
super(MinMaxHeap, self).__init__()
@gnarmis
gnarmis / euler-three.clj
Created January 5, 2013 18:47
Solution to Project Euler problem 3. Require Clojure 1.5 RC1 and runs in less than a quarter of a second in my Clojure REPL.
(ns euler.three
(require [clojure.core.reducers :as r]))
(declare largest-prime-factor-for)
(declare factors-of)
(declare source-factors)
(declare source-naturals)
(declare factor?)
(declare prime?)
(declare certainty)
@gnarmis
gnarmis / gardner.hs
Last active December 10, 2015 06:28
Gardner's canceling digits puzzle, also related to Project Euler problem #33
-- turn an Integer into a list of digits
digits = map (read . (:[])) . show
-- is a given fraction special?
special :: Integer -> Integer -> Bool
special n d
| (n_rf / d_rf) == ((realToFrac (head ns)) / (realToFrac (head ds))) = True
| otherwise = False
where n_rf = realToFrac n
d_rf = realToFrac d
@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,
@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 / experiments.rb
Created September 21, 2012 09:13
Experimenting with bastardized functional-ness in Ruby
#ruby1.9.3
def defn name, &b
Object.send :define_method, name, &b
end
# this also works (surprisingly), albeit with a warning
# def defn name
# Object.send(:define_method, name)
# end
@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 / 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