Skip to content

Instantly share code, notes, and snippets.

@maio
maio / core.clj
Last active December 17, 2015 10:59
Monads
(ns monads.core
(:use [clojure.algo.monads
:only (domonad with-monad m-lift m-seq m-reduce m-when
identity-m
sequence-m
maybe-m
state-m fetch-state set-state
writer-m write
cont-m run-cont call-cc
maybe-t)]))
(def words "down before how around quickly off been does thing story book kind has near list quite set read keep with form boy who such she made play be say open call mountain said state light show one to for her work here left when hear as our place just thing are ask study need were even something question great close that begin us tell while side then here word high take his other who grow talk above learn it father few did what oil face over even those spell does number down in work where go might we add right mile story letter some much before big he car help don't came take come river about between food any much begin between these all thought being than few example why again face three its something your high but miss country add old from should should there about song no same who same land school mile own more found know have see did important know head seem set need got ask almost must school my its when air right here question did thing four is think follow go show soon also change or after such not
@maio
maio / test.t
Last active December 13, 2015 21:59
BDD vs xyzUnit style unit-tests
describe "StringCalculator" => sub {
it "returns sum of comma delimited numbers" => sub {
is(add("$a,$b"), $a + $b);
};
it "treats newline as delimiter" => sub {
is(add("$a\n$b"), $a + $b);
};
describe 'delimiter marker //<delimiter-spec>\n' => sub {
@maio
maio / whisper-graphite-retentions.pl
Last active December 12, 2015 01:38
Whisper/Graphite retentions string parsing (precision:period,precision:period,...)
func parse_time($str) {
# Mapping from whisper.py
my %unit_multiplier = (
s => 1,
m => 60,
h => 3600,
d => 86400,
w => 86400 * 7,
y => 86400 * 365
);
@maio
maio / migration.clj
Last active December 11, 2015 08:49
Clojure model migrations
;; Alternatives - http://www.clojure-toolbox.com (Database Migrations)
(ns wools.models.migration
(:require [clojure.java.jdbc :as sql]))
(def migrations
[{:id "create balance table"
:up #(sql/create-table :balance
[:ts :timestamp "NOT NULL" "DEFAULT CURRENT_TIMESTAMP"]
[:amount :int "NOT NULL"])}])
@maio
maio / gist:2862867
Created June 3, 2012 09:58
Smart semi-colon in Emacs (and Vim)
;; Port of Coderush's smart semi-colon feature to Emacs
;;
;; When I hit semi-colon anywhere, Emacs will move cursor to the end of current
;; line and insert semi-colon (if it's not already there).
;;
;; Idea from last @CoderetreatCZ - HK
(defun maio/electric-semicolon ()
(interactive)
(end-of-line)
@maio
maio / after.js
Created August 22, 2011 15:08
convert tests to jasmine
describe("TODO List", function() {
beforeEach(function() {
storage = new TestCookieStorage;
tasks = storage.load_tasks();
users = storage.load_users();
});
it("loads tasks from storage", function() {
expect(tasks.length).toEqual(1);
});
@maio
maio / ipaste.vim
Created August 17, 2011 21:03
Detect correct indentation for pasted text. Helps when moving code around.
nmap P :call <SID>pasteAbove()<CR>
nmap p :call <SID>pasteBelow()<CR>
fun! s:pasteAbove()
let indentDiff = s:detectIndentDiff("O")
exe "norm! P"
call s:fixPasteIndent(indentDiff)
endfun
fun! s:pasteBelow()
@maio
maio / Expect.t
Created August 9, 2011 21:34
Jasmine matchers clone in Perl
# Perl clone of:
# https://github.com/pivotal/jasmine/wiki/Matchers
# https://github.com/pivotal/jasmine/wiki
use Test::Spec;
# usage
describe 'Expect' => sub {
describe 'implementing matcher' => sub {
it toEqual => sub {
@maio
maio / tests.java
Created July 18, 2011 20:23
Re: Pětiminutové intro do Mockito knihovny
public void testGetTotalPriceReturnsSumOfAllItemsPrices() {
basket.addItem(new Item(1));
basket.addItem(new Item(2));
assertThat(basket.getTotalPrice(), is(3));
}
public void testClearMakesBasketEmpty() {
basket.addItem(new Item());
basket.clear();