This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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 #{+ - / *}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# # 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Parallel remote logs | |
$ fab hoststask tail_log --linewise | |
""" | |
from fabric.decorators import parallel, task | |
from fabric.tasks import run | |
@task |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""KDE knotify logging handler""" | |
import logging | |
import dbus | |
class KNotifyHandler(logging.Handler): | |
"""Log messages to kde notifications""" | |
def __init__(self, level=logging.NOTSET): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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++ { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |