Skip to content

Instantly share code, notes, and snippets.

View klang's full-sized avatar
🏠
Working from home

Karsten Lang klang

🏠
Working from home
View GitHub Profile
(defproject hello-world "1.0.0-SNAPSHOT"
:description "FIXME: write"
:dependencies [[org.clojure/clojure "1.1.0"]
[org.clojure/clojure-contrib "1.1.0"]
[compojure "0.4.0-SNAPSHOT"]
[ring/ring-jetty-adapter "0.2.0"]])
@juergenhoetzel
juergenhoetzel / lein-swank.el
Created May 30, 2010 22:20
Launch a Leiningen Swank Process and connect
We couldn’t find that file to show.
(ns life (:use clojure.test clojure.set))
(def under-populated 1)
(def over-populated 4)
(def fertile 3)
(defn north [[x y]] [x (inc y)])
(defn south [[x y]] [x (dec y)])
(defn east [[x y]] [(inc x) y])
(defn west [[x y]] [(dec x) y])
<?php
// Define the 'class' class
$class = Obj()
->fn('new', function ($class) {
$newClass = Obj($class->methods)
->fn('new', function($class) {
$obj = Obj($class->imethods);
$args = func_get_args();
array_shift($args);
@amalloy
amalloy / .emacs
Created September 27, 2010 20:33
(defun smart-line-beginning ()
"Move point to the beginning of text on the current line; if that is already the current position of point, then move it to the beginning of the line."
(interactive)
(let ((pt (point)))
(beginning-of-line-text)
(when (eq pt (point))
(beginning-of-line))))
(global-set-key "\C-a" 'smart-beginning-of-line)
(defn list-classes [bytes]
(with-open [jar-is (JarInputStream. (java.io.ByteArrayInputStream. bytes))]
(doall (map
(fn [entry] (-> (.getName entry)
(.replaceAll "\\.class$" "")
(.replaceAll "/" ".")))
(filter
#(.endsWith (.getName %) ".class")
(take-while identity (repeatedly #(.getNextEntry jar-is))))))))
@prasincs
prasincs / sha1-hash.clj
Created February 15, 2011 08:36
clojure sha1 hash
(defn get-hash [type data]
(.digest (java.security.MessageDigest/getInstance type) (.getBytes data) ))
(defn sha1-hash [data]
(get-hash "sha1" data))
(defn get-hash-str [data-bytes]
(apply str
(map
#(.substring
(set! *unchecked-math* true)
(defmacro iloop [[b t n] & body]
`(loop [~@b]
(when ~t
~@body
(recur ~n))))
(defn count-primes [^long n]
(let [c (inc n)
@alexander-yakushev
alexander-yakushev / tetris.clj
Created September 10, 2011 00:28
Tetris implementation in Clojure
(ns tetris.core
(:import (java.awt Color Dimension BorderLayout)
(javax.swing JPanel JFrame JOptionPane JButton JLabel)
(java.awt.event KeyListener))
(:use clojure.contrib.import-static deflayout.core
clojure.contrib.swing-utils)
(:gen-class))
(import-static java.awt.event.KeyEvent VK_LEFT VK_RIGHT VK_DOWN VK_UP VK_SPACE)
@blacktaxi
blacktaxi / ruby-fmt.clj
Created January 25, 2012 14:42
Ruby-like string interpolation in Clojure
; Ruby has an awesome feature -- string interpolation. Read about it on the internet.
; On the other hand, Clojure only has cumbersome Java string formatting, which can not be
; used without pain after you've tried Ruby.
; So here's this simple macro that basically allows you to do most things you could do
; with Ruby string interpolation in Clojure.
(ns eis.stuff
(:require [clojure.string]))