Skip to content

Instantly share code, notes, and snippets.

View ghoseb's full-sized avatar
🏋️‍♂️

Baishampayan Ghose ghoseb

🏋️‍♂️
View GitHub Profile
(ns type-level-tagger
{:doc "Implements State-of-the-art Unsupervised Part-of-speech Tagger
from \"Simple Type-Level Unsuperivsed POS Tagging\"
by Yoong-Keok Lee, Aria Haghighi and Regina Barzilay
(http://www.cs.berkeley.edu/~aria42/pubs/typetagging.pdf)
blog post: http://wp.me/pcW6S-x"
:author "Aria Haghighi (aria42@gmail.com)"}
(:use [clojure.java.io :only [reader]]
[clojure.contrib.duck-streams :only [with-out-writer]]
[clojure.contrib.seq-utils :only [indexed]]
@cs224
cs224 / levenshtein-allison.clj
Created March 27, 2011 16:36
levenshtein-allison.clj
;;; implementation in clojure of the levenshtein allison algorithm as defined here:
;;; http://www.csse.monash.edu.au/~lloyd/tildeFP/Haskell/1998/Edit01/
(defn min3 [w nw n]
(if (< w nw) w (min nw n)))
(defn generate-diagonale [a b nw fn-diag-above fn-diag-below start]
(if start
(lazy-cat (list nw) (generate-diagonale a b nw fn-diag-above fn-diag-below false))
(if (or (empty? a) (empty? b)) '()
@alandipert
alandipert / isbn13.clj
Created August 27, 2011 18:11
ISBN-13 validation
(defn isbn13? [isbn13]
(let [nums (map #(Integer/parseInt %) (re-seq #"\d" isbn13))
first-nums (butlast nums)
sum (->> first-nums
(map vector (cycle [1 3]))
(map (partial apply *))
(reduce +))
last-num (last nums)]
(= last-num
(- 10 (mod sum 10)))))
@nathanmarz
nathanmarz / gist:1246228
Created September 27, 2011 20:56
Exception cause predicate
;; Determine if any of the causes of the exception was of the specified type
(defn exception-cause? [klass ^Throwable t]
(->> (iterate #(.getCause ^Throwable %) t)
(take-while identity)
(some (partial instance? klass))
boolean))
@svs
svs / gist:2478214
Created April 24, 2012 09:23
Question about Rich Hickey's 'use hashes not classes' statement

So I don't have a model called Person, but I use hashes like {:name => "Siddharth", :sex => "Y"}. Great. Now I want to validate the presence of certain fields before persisting to the database. What do I do?

Module PersonValidation
  function validate_presence_of_name(person_hash)
    person_hash[:errors][:name] = "EEENKKK!" unless person_hash[:name]
  end
  
  ...
 ...
@stuarthalloway
stuarthalloway / gist:2651196
Created May 10, 2012 05:22
Datomic queries against Java collections
// Datomic example code
package datomic.examples;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import static datomic.Peer.*;
@jmgimeno
jmgimeno / bfc.clj
Created June 14, 2012 07:20
Brainf*** compiler (Alan Dipert)
(defn bfc
[program]
(let [allowed #{\+ \- \< \> \[ \] \.}
src (->> program (filter allowed)
(interpose \space) (apply str))
fns (zipmap '(- + < > . ?) (repeatedly gensym))]
(letfn [(bfc* [s]
(if (vector? s)
`(while (not (~(fns '?))) ~@(map bfc* s))
`(~(fns s))))]
@wmorgan
wmorgan / gist:3054620
Created July 5, 2012 16:18
Mustache templating for Clojure
(ns potato.core
(:use [slingshot.slingshot :only [throw+ try+]])
(:use [clojure.string :only [trim split]]))
;; use this provide template values at write time (i.e. not compile time).
;; "name" will be the name of the template variable. "context", when not nil,
;; will be the value previously returned by *template-value* for the enclosing
;; section.
(defn ^:dynamic *template-value* [name context])
(ns example.storm.clj.spout.kafka-spout
(:import ; [example.storm.spout UnreliableKafkaSpout]
[storm.kafka HostPort KafkaSpout SpoutConfig StringScheme]))
(def ^:dynamic *kafka-hosts* ["kafka-1.example.net"
"kafka-2.example.net"
"kafka-3.example.net"])
(def ^:dynamic *kafka-ports* [9093
9094
(defbolt split-category ["category" "event"]
[tuple collector]
(let [event (.getString tuple 0)
category "testing_category2"]
(comment
(emit-bolt! collector [category event] :anchor tuple)
)
(emit-bolt! collector [category event] :anchor tuple :stream "3")
(ack! collector tuple)))