Skip to content

Instantly share code, notes, and snippets.

View citizen428's full-sized avatar

Michael Kohl citizen428

View GitHub Profile
;;; Ruby/Rails development
;; RVM support
;; Ruby Version Manager
(require 'rvm)
(rvm-use-default)
;; automatically add 'end' after class, module, def etc.
;; automatically pair braces, single and double quotes
(require 'ruby-electric)
# Get the official Emacs repo:
git clone http://repo.or.cz/r/emacs.git/
# Get the fullscreen patch
git remote add typester git://github.com/typester/emacs.git
git fetch typester
# Create a patch and apply to HEAD
# I had merge conflicts when rebasing and
# build failures for origin/emacs-23
require 'httparty'
class GitHub
include HTTParty
base_uri 'http://github.com/api/v2/yaml'
API_METHODS = {
:watched => '/repos/watched/' }
class << self

Gist Clients

Want to create a Gist from your editor, the command line, or the Services menu? Here's how.

Editor Support

user=> ; get the expt funtion
user=> (use '[clojure.contrib.math :only (expt)])
nil
user=> (expt 2 3)
8
user=> ; function to calculate no. of pairs for n people
user=> (defn number-pairs [n] (/ (* n (- n 1)) 2))
#'user/number-pairs
user=> ; how many pairs for 23 people?
user=> (number-pairs 23)
class Fixnum
alias_method :intdiv, :/
def /(divisor)
(self % divisor) == 0 ? self.intdiv(divisor) : self.to_f/divisor
end
end
user=> ; generate random number
user=> (rand)
0.8545074632292601
user=> ; infinite list of random numbers
user=> ; make sure to set *print-length*
user=> (set! *print-length* 10)
10
user=> (repeatedly rand)
(0.13569783475252373 0.585868618595554 0.7048671603900427 0.1440943435265447 0.24546858003727567 0.15406959135696596 0.41117257771529947 0.1115848319639422 0.669215744258339 0.1521494621978804 ...)
user=> ; get the reductions function from seq-utils
(use '(incanter core charts io))
(def usage (read-dataset "report.csv" :header true))
(def instance-types
(set (filter #(re-find #"BoxUsage" %) ($ :UsageType usage))))
(with-data (->> ($rollup :sum :UsageValue :UsageType usage)
($where {:UsageType {:$in instance-types}}))
(view (bar-chart :UsageType :UsageValue
:title "EC Instance Usage"