Skip to content

Instantly share code, notes, and snippets.

@ahammar
ahammar / DesugarDo.hs
Created November 5, 2011 13:37
Naive do-notation desugarer
import Data.Generics
import Language.Haskell.Parser
import Language.Haskell.Pretty
import Language.Haskell.Syntax
main = do
input <- getContents
case parseModule input of
ParseOk mod -> putStrLn $ prettyPrint $ everywhere (mkT desugarExp) mod
ParseFailed loc msg -> failed loc msg
@fabianp
fabianp / gist:1342033
Created November 5, 2011 21:18
Low rank approximation for the lena image
"""
Low rank approximation for the lena image
"""
import numpy as np
import scipy as sp
from scipy import linalg
import pylab as pl
X = sp.lena().astype(np.float)
pl.gray()
@copiousfreetime
copiousfreetime / memstats.rb
Created November 15, 2011 03:06
useful info from /proc/[pid]/smaps
#!/usr/bin/env ruby
#------------------------------------------------------------------------------
# Aggregate Print useful information from /proc/[pid]/smaps
#
# pss - Roughly the amount of memory that is "really" being used by the pid
# swap - Amount of swap this process is currently using
#
# Reference:
# http://www.mjmwired.net/kernel/Documentation/filesystems/proc.txt#361
@avdi
avdi / match_method.rb
Created December 6, 2011 21:27
Defining method_missing and respond_to? in one fell swoop
# Do you ever define #method_missing and forget #respond_to? I sure
# do. It would be nice if we could do them both at the same time.
module MatchMethodMacros
def match_method(matcher, &method_body)
mod = Module.new do
define_method(:method_missing) do |method_name, *args|
if matcher === method_name.to_s
instance_exec(method_name, *args, &method_body)
else
@semperos
semperos / clj->js.clj
Created January 22, 2012 19:43
ClojureScript to JavaScript (from mmcgrana)
(defn clj->js
"Recursively transforms ClojureScript maps into Javascript objects,
other ClojureScript colls into JavaScript arrays, and ClojureScript
keywords into JavaScript strings."
[x]
(cond
(string? x) x
(keyword? x) (name x)
(map? x) (.strobj (reduce (fn [m [k v]]
(assoc m (clj->js k) (clj->js v))) {} x))
@hugoduncan
hugoduncan / gist:1666286
Created January 23, 2012 23:15
jekyll-mumamo with clojure-mode support
; highlight support for multiple languages
(defconst mumamo-highlight-tag-start-regex
(rx "{%"
(0+ space)
"highlight"
space
(submatch
(1+ (any "a-za-z")))
(0+ space)
"%}"
@hugoduncan
hugoduncan / gist:1690974
Created January 27, 2012 21:17
rvm crate
(ns pallet.crate.rvm
"Standard rvm install"
(:require
[pallet.crate.git :as git]
[pallet.action.conditional :as conditional]
[pallet.action.exec-script :as exec-script]
[pallet.action.package :as package]
[pallet.action.remote-file :as remote-file]
[pallet.action.user :as user]
[pallet.context :as context]
# Emulates the QuickCheck ?SOMETIMES macro.
module Sometimes
def run_with_retries(example_to_run, retries)
self.example.metadata[:retries] ||= retries
retries.times do |t|
self.example.metadata[:retried] = t + 1
self.example.instance_variable_set(:@exception, nil)
example_to_run.run
break unless self.example.exception
@rferraz
rferraz / cometd_client.clj
Created February 5, 2012 06:12
Clojure CometD client example
(ns test.cometd-client
(:import (org.cometd.bayeux.client ClientSessionChannel$MessageListener)
(org.cometd.client BayeuxClient BayeuxClient$State)
(org.cometd.client.transport ClientTransport LongPollingTransport)
(org.eclipse.jetty.client HttpClient)))
(def channel-name "/my-channel")
(def client-url "http://localhost:8080/cometd")
@stuarthalloway
stuarthalloway / gist:1980351
Created March 5, 2012 18:56
frinj unit conversion running inside a Datomic datalog query
;; lein settings
(defproject foo "1.0.0-SNAPSHOT"
:description "Test App"
:dependencies [[com.datomic/datomic "0.1.2678"]
[frinj "0.1.2" :exclusions [org.clojure/clojure]]])
;; load libs
(use 'frinj.core 'frinj.calc)
(frinj-init!)
(use '[datomic.api :only (q db) :as d])