Skip to content

Instantly share code, notes, and snippets.

View cbilson's full-sized avatar

Chris Bilson cbilson

View GitHub Profile
@hiredman
hiredman / core.clj
Created October 25, 2011 22:56
srepl.clj
(ns srepl.core
(:use [clojure.main :only [repl]]
[clojure.pprint :only [pprint with-pprint-dispatch code-dispatch]])
(:import (jline.console ConsoleReader)
(jline.console.completer Completer))
(:gen-class))
(defmulti super-dispatch class)
(defmethod super-dispatch :default [thing]
@ctford
ctford / at_all.clj
Created March 11, 2012 20:44
A short piano piece in Overtone
(ns overtunes.songs.at-all
(:use
[overtone.live :only [at now]]
[overtone.inst.sampled-piano :only [sampled-piano]]))
(defn bpm [beats-per-minute]
(let [start (now)
ms-per-minute (* 60 1000)
ms-per-beat (/ ms-per-minute beats-per-minute)]
#(+ start (* ms-per-beat %))))
@pedroteixeira
pedroteixeira / SpamLord.java
Created March 11, 2012 23:15
coursera nlp pa1
// Modified SpamLord.java to call clojure code
public List<Contact> processFile(String fileName, BufferedReader input) {
List<Contact> contacts = new ArrayList<Contact>();
// for each line
Matcher m;
String email;
try {
List results = new spamlord().process(input);
@paxan
paxan / gist:3901864
Last active October 11, 2015 18:37
A Common Crawl Experiment (moved to https://github.com/paxan/ccooo)
@jimwhite
jimwhite / Treasure.clj
Last active December 16, 2015 22:29
A Groovy and a Clojure solution for Google Code Jam practice Treasure [https://code.google.com/codejam/contest/2270488/dashboard#s=p3].
;; My first bit of Clojure.
;; https://code.google.com/codejam/contest/2270488/dashboard#s=p3
(def test_chests '({:name 1 :opener 1 :contents ()} {:name 2 :opener 1 :contents (1 3)} {:name 3 :opener 2 :contents ()} {:name 4 :opener 3 :contents (2)}))
(defn remove-first [pred lst]
(if (pred (first lst)) (rest lst) (cons (first lst) (remove-first pred (rest lst)))))
;; Return sequence of chest names to open all the chests starting with the given list (multiset) of keys.
;; Return nil if there is no combination that opens all the chests.
(defun nrepl-eval-expression-at-point-in-repl ()
(interactive)
(let ((form (nrepl-expression-at-point)))
;; Strip excess whitespace
(while (string-match "\\`\s+\\|\n+\\'" form)
(setq form (replace-match "" t t form)))
(set-buffer "*nrepl*")
(goto-char (point-max))
(insert form)
(nrepl-return)))
@codereflection
codereflection / CurrentThreadTaskScheduler.cs
Created December 20, 2013 20:04
Getting unit tests to run under a single thread. Just inherit the WithASingleThreadRestriction class from your unit tests and they'll run under a single thread making unit testing much easier.
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
namespace Tests
{
public class CurrentThreadTaskScheduler : TaskScheduler
{
protected override void QueueTask(Task task)
@edubkendo
edubkendo / ctags_subl_coffee.md
Created June 9, 2012 15:11
Ctags, Sublime Text, Coffeescript

Ctags with Sublime Text and Coffeescript

Get Ctags

Step one is to install Exuberant Ctags on your system. For those on an Ubuntu system, this is as simple as:

sudo apt-get install ctags

Get the Sublime Text Plug-in

@stuarthalloway
stuarthalloway / gist:5199642
Created March 19, 2013 20:11
Draw a pedestal dataflow with dorothy + Graphviz
;; from leiningen, use [dorothy/dorothy "0.0.3"]
(require '[dorothy.core :as dot])
;; dataflow copied from chat
;; https://github.com/pedestal/samples/blob/master/chat/chat-client/app/src/chat_client/behavior.clj
(def dataflow '{:transform
{:outbound {:init {} :fn outbound-transform}
:inbound {:init {} :fn inbound-transform}
:nickname {:init nil :fn nickname-transform}}
:effect {:outbound send-message-to-server}
@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))