Skip to content

Instantly share code, notes, and snippets.

View claj's full-sized avatar

Linus Ericsson claj

  • Sweden
  • 09:57 (UTC +02:00)
View GitHub Profile
@daveray
daveray / seesaw-repl-tutorial.clj
Created December 7, 2011 04:55
Seesaw REPL Tutorial
; A REPL-based, annotated Seesaw tutorial
; Please visit https://github.com/daveray/seesaw for more info
;
; This is a very basic intro to Seesaw, a Clojure UI toolkit. It covers
; Seesaw's basic features and philosophy, but only scratches the surface
; of what's available. It only assumes knowledge of Clojure. No Swing or
; Java experience is needed.
;
; This material was first presented in a talk at @CraftsmanGuild in
; Ann Arbor, MI.
@stuarthalloway
stuarthalloway / Datomic News Updates
Created June 18, 2012 14:53
Datomic update examples against a social news database
;; Datomic example code
;; demonstrates various update scenarios, using a news database
;; that contains stories, users, and upvotes
;; grab an in memory database
(use '[datomic.api :only (q db) :as d])
(def uri "datomic:mem://foo")
(d/create-database uri)
(def conn (d/connect uri))
@stuarthalloway
stuarthalloway / gist:2002582
Created March 8, 2012 18:39
Datomic extent query
;; Datomic example code
;;
;; The extent of entity ?x is all datoms that are about ?x.
;; Drop this into your rules.
;;
;; Demonstrates
;;
;; 1. recursive query (extent calls itself)
;; 2. disjunction (different extent bodies are ORed)
;; 3. component attributes (e.g. your arm is a component, your brother isn't)
@zerg000000
zerg000000 / user.clj
Last active November 12, 2022 23:03
S3 presign (post) example aws-api
(require '[buddy.core.codecs.base64 :as base64]
'[cognitect.aws.util :as util]
'[clojure.string :as str]
'[jsonista.core :as json]
'[cognitect.aws.credentials :as creds]
'[cognitect.aws.http :as http])
(import '[java.util Date])
(defn host-style-bucket-uri [bucket]
(str "http://" bucket ".s3.amazonaws.com/"))
@alandipert
alandipert / midi.clj
Created March 31, 2010 12:37
Play music with Clojure and javax.sound.midi
(import '(javax.sound.midi MidiSystem Synthesizer))
(defn play-note [synth channel note-map]
(let [{:keys [note velocity duration]
:or {note 60
velocity 127
duration 1000}} note-map]
(. channel noteOn note velocity)
(Thread/sleep duration)
(. channel noteOff note)))
(ns net.cgrand.decay
"Exponentially decaying lists. See http://awelonblue.wordpress.com/2013/01/24/exponential-decay-of-history-improved/
for background and http://clj-me.cgrand.net/2013/02/12/decaying-lists-log-scale-for-lists/ for documentation")
;; PRNG, formulas straight from java.util.Random javadoc
(defn- seed ^long [^long n]
(bit-and (unchecked-multiply n 0x5DEECE66D)
(unchecked-dec (bit-shift-left 1 48))))
(defn- next-seed ^long [^long seed]
@martinklepsch
martinklepsch / logging.cljc
Last active October 22, 2018 18:27
simple Clojurescript logging using Google Closure logging tools
;; This previously was CLJX but has now been updated to use cljc. Thanks @caskolkm
;; https://gist.github.com/caskolkm/39d823f5bac7051d3062
(ns app.logging
(:refer-clojure :exclude [time])
(:require #?(:clj [clojure.tools.logging :as log]
:cljs [goog.log :as glog]))
#?(:cljs (:import goog.debug.Console)))
#?(:cljs
@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.
@pelle
pelle / accounts.clj
Created May 8, 2012 14:37
Using database functions in Datomic transactions and annotating transaction history
(use '[datomic.api :only [q db] :as d])
(def uri "datomic:mem://accounts")
;; create database
(d/create-database uri)
;; connect to database
(def conn (d/connect uri))
@aphyr
aphyr / gist:f72e72992dade4578232
Last active December 17, 2016 08:00
Clojure Keyword.intern
commit 8e51c34ca4d97e48750850d5ba09956f89783b4e
Author: Kyle Kingsbury <aphyr@aphyr.com>
Date: Wed May 7 19:06:15 2014 -0700
Improve Keyword.intern performance
Keyword interning is an expensive factor in many Clojure
serialization/deserialization paths, especially where the same set of
keywords are created and freed repeatedly; e.g. iterating over records
with similar structure. There are two principle costs to keyword