Skip to content

Instantly share code, notes, and snippets.

var sys = require('sys'),
Path = require('path'),
Mu = require('../mu'),
Script = process.binding('evals').Script;
exports.compile = compile;
exports.compilePartial = compilePartial;
function RenderEventEmitter(options) {
this.chunkSize = options.chunkSize || 1024;
[org.clojars.ithayer/plaid-penguin "1.0.0"]
@ithayer
ithayer / tf-idf.clj
Created June 28, 2011 06:32
Simple tf-idf in 30 lines of clojure. Inspired by a nice simple scala implementation: https://github.com/felipehummel/TinySearchEngine/blob/master/scala/tinySearch.scala and matches as closely as possible the computation.
(ns ignacio.tfidf (:require [clojure.contrib.string :as string])) ;; Simple tfidf in clojure, for fun.
(def stopwords (set (string/split #"\n" (slurp "./stopwords.txt"))))
(defn tokenize [raw-text] ;; Lowercases and splits on non-letters, non-numbers.
(remove stopwords (string/split #"[^a-z0-9äöüáéíóúãâêîôûàèìòùçñ]+" (string/lower-case raw-text))))
(defn idf2 [n-docs match] (Math/pow (Math/log (/ n-docs (count (keys match)))) 2))
(defn index-one [fname] ;; Index for one file. Given an fname, returns a map of token -> map of (fname, count)
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 = {}
@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.
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)
<!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}}.
(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
@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
@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)))