Skip to content

Instantly share code, notes, and snippets.

(defn cmp-order
([a b] (cmp-order a b >))
([a b pred]
(if (pred (:price a) (:price b))
true
(if (== (:price a) (:price b))
(if (< (:id a) (:id b))
true
false)
@minimal
minimal / rpn-calc.clj
Created July 29, 2010 23:16
Programming Praxis rpn calculator
;; Reverse polish calculator
;; http://programmingpraxis.com/2009/02/19/rpn-calculator/
;; given args [19 2.14 + 4.5 2 4.3 / - *] should equate to
;; (* (+ 19 2.14) (- 4.5 ( / 2 4.3)))
;; test with (test/run-tests 'user)
(require '[clojure.test :as test])
(def test-calc (* (+ 19 2.14) (- 4.5 ( / 2 4.3))))
(def operators #{+ - / *})
@minimal
minimal / jsminify.py
Created January 5, 2011 17:02
minify js with closure compiler
#!/usr/bin/env python
# JS Minify
# Python script that can process all JavaScript files in a directory
# through the Closure compiler
# original: http://taylanpince.com/blog/posts/automated-javascript-minification-with-fabric/
import os
from optparse import OptionParser
@minimal
minimal / amqpws.coffee
Created January 28, 2011 18:49
Simple amqp queue subscribing.coffee
# # Simple amqp queue subscribing
# _Chris McDevitt_
#
# * experimenting with jquery 1.5 deferreds
# * functional for now
# * no handling of disonnections, session, big messages etc
#
root = this
mqws = (obj) -> new wrapper(obj)
@minimal
minimal / commit-msg
Created October 21, 2011 09:29
Git precommit hooks - pylint and forbidden strings
#!/bin/sh
# From Gerrit Code Review 2.1.6.1
#
# Part of Gerrit Code Review (http://code.google.com/p/gerrit/)
#
# Copyright (C) 2009 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
@minimal
minimal / paratail.py
Created October 26, 2011 18:27
Fabric Parallel remote logs
"""
Parallel remote logs
$ fab hoststask tail_log --linewise
"""
from fabric.decorators import parallel, task
from fabric.tasks import run
@task
@minimal
minimal / knotify_log.py
Created November 23, 2011 15:14
KDE knotify logging handler
"""KDE knotify logging handler"""
import logging
import dbus
class KNotifyHandler(logging.Handler):
"""Log messages to kde notifications"""
def __init__(self, level=logging.NOTSET):
@minimal
minimal / fabfile.py
Created March 16, 2012 15:49
Write git revision during fab deploy
# todo: check working copy is clean, master branch etc
@runs_once
def build():
"Build source distribution locally"
store_git_revision()
with settings(warn_only=True):
local("rm dist/*")
local("python setup.py sdist")
@minimal
minimal / cuberoot.go
Last active October 6, 2015 00:57
Go tour exercises
package main
import "fmt"
import "math/cmplx"
func Cbrt(x complex128) complex128 {
z := 1.0+0i
zold := z
cont := true
for i := 0; cont == true ; i++ {
@minimal
minimal / test_importer.py
Created August 10, 2012 14:51
Await data from non blocking function
import time
def await_data(func, *args, **kwargs):
"""
Given a function and its args keep calling until data is returned
Tries do deal with mongo slowness to show recently inserted data
"""
thefunc = partial(func, *args, **kwargs)
max_times = 10