Skip to content

Instantly share code, notes, and snippets.

@ithayer
ithayer / clojure-flow-1.clj
Created July 28, 2012 21:31
Clojure Thrush Operator Code Examples
;; Start of what the above flow in clojure would look like.
;; Tokenization step.
(->> (clojure.string/split (slurp "/tmp/X") #" ") tokenize-word)
;; For debugging, just look at the first 100 words...
(->> (clojure.string/split (slurp "/tmp/X") #" ") tokenize-word (take 100))
;; or, look at some in the middle...
(->> (clojure.string/split (slurp "/tmp/X") #" ")
# Should enable the little battery icon.
xfce4-power-manager
echo "Setting middle button emulation"
xinput set-int-prop 12 "Evdev Middle Button Emulation" 8 1
echo "Turning off dual mode video"
sudo sh -c "echo OFF > /sys/kernel/debug/vgaswitcheroo/switch"
echo "Turhing off bluetooth"
@ithayer
ithayer / hoisting-loop.js
Created April 4, 2012 05:33
Simple example of Javascript variable hoisting
// Demonstration of how easy it is for this to mess up your loops.
var txt = ["a","b","c"];
for (var i = 0; i < 3; ++i ) {
var msg = txt[i];
setTimeout(function() { alert(msg); }, i*1000);
}​
// Alerts 'c', 'c', 'c'
@ithayer
ithayer / gist:2219525
Created March 27, 2012 19:31
Simple JAX-WS UsernameToken security generation with Clojure (SOAP, AXIS, WSDL)
(defn create-security-header
"Given an optional environment (:stage, :prod), creates the authentication."
[credentials]
(let [soap-factory (SOAPFactory/newInstance)
security (.. soap-factory (createElement (QName. security-namespace "Security")))
user-token (.. soap-factory (createElement (QName. security-namespace "UsernameToken")))
username (.. soap-factory (createElement (QName. security-namespace "Username")))
password (.. soap-factory (createElement (QName. security-namespace "Password")))]
(.. username (addTextNode (get credentials :username)))
(.. password (addTextNode (get credentials :password)))
@ithayer
ithayer / pull-s3-package.py
Created February 21, 2012 08:02
s3-package python scripts: easily manage large binary files in a git repo
#!/usr/bin/env python
#
# This script reads packages from .s3.
# Given a directory, will pull all .s3 packages in it recursively.
# Or, if you specify a .s3 file, it will pull just that package.
#
# Copyright (C) 2010-2012 ReadyForZero (ReadyForZero.com)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
(defmachine PaymentsMachine
(state :user-submitted
(on-in (fn [data]
(log/put "User submitted ...")
(send-email "..."))))
(state :sent-off
(on-in (fn [data]
(log/put "sent payment"))))
(state :error
<!doctype html>
<html lang="en">
<head>
<title>Ember Bug</title>
</head>
<body>
<script src="http://code.jquery.com/jquery-1.7.1.js"></script>
<script src="https://github.com/downloads/emberjs/ember.js/ember-0.9.1.js"></script>
<script type="text/x-handlebars" data-template-name="president">
The President of the United States is {{name}}.
0: clojure.lang.LazySeq.sval(LazySeq.java:47)
1: clojure.lang.LazySeq.seq(LazySeq.java:63)
2: clojure.lang.RT.seq(RT.java:450)
3: clojure.core$seq.invoke(core.clj:122)
4: clojure.core$dorun.invoke(core.clj:2450)
5: clojure.core$doall.invoke(core.clj:2465)
6: pallet.core$parallel_lift.invoke(core.clj:720)
7: pallet.core$lift_nodes_for_phase$fn__8250.invoke(core.clj:742)
8: clojure.lang.ArrayChunk.reduce(ArrayChunk.java:58)
9: clojure.core$r.invoke(core.clj:797)
@ithayer
ithayer / create-heroku
Created July 4, 2011 19:20
Clojure on Heroku with Noir and Mongo Demo
# Commands to initialize a simple heroku noir app. You can cut and paste them together.
# Install latest version of noir. If an older version is installed, remove it first.
lein plugin install lein-noir "1.1.0-SNAPSHOT"
# Create new noir project.
lein noir new noir-mongo-heroku
cd noir-mongo-heroku
# Create instructions for heroku.
echo 'web: lein run' > Procfile
# Create git repository.
def solve(eq,var='x'):
eq1 = eq.replace("=","-(")+")"
c = eval(eq1,{var:1j})
return -c.real/c.imag
class CalculatorHandler:
def __init__(self):
self.log = {}