Skip to content

Instantly share code, notes, and snippets.

// @flow
import {Record} from 'immutable';
const TestRec = Record({a: 0, b: 0});
// Flow gives an error for the `rec` argument's type:
//
// RecordClass
// Ineligible value used in/as type annotation (did you forget 'typeof'?)
// TestRec
function postJson(method, url, params) {
let xhr = new XMLHttpRequest();
xhr.open(method, url, true);
xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
xhr.send(JSON.stringify(params));
xhr.onreadystatechange = function() {
let status;
let data;
if (xhr.readyState === 4) {
status = xhr.status;
;; depends on [org.imgscalr/imgscalr-lib "4.2"]
(ns XXX.image
(:refer-clojure :exclude [read])
(:require [clojure.java.io :as io])
(:import [org.imgscalr Scalr Scalr$Method Scalr$Mode]
[java.awt Image]
[java.awt.image RenderedImage BufferedImageOp]
[javax.imageio ImageIO ImageWriter ImageWriteParam IIOImage]
(definterface IPrimitiveTester
(getType [^int x])
(getType [^long x])
(getType [^float x])
(getType [^double x])
(getType [^byte x])
(getType [^short x])
(getType [^char x])
(getType [^boolean x])
(getType [^Object x]))
## Solve Every Sudoku Puzzle
## See http://norvig.com/sudoku.html
## Throughout this program we have:
## r is a row, e.g. 'A'
## c is a column, e.g. '3'
## s is a square, e.g. 'A3'
## d is a digit, e.g. '9'
## u is a unit, e.g. ['A1','B1','C1','D1','E1','F1','G1','H1','I1']
;;;; Translation of Peter Norvig's sudoku solver to idiomatic Clojure
;;;; See http://norvig.com/sudoku.html
;;;;
;;;; Throughout this program we have:
;;;; r is a row, e.g. :a
;;;; c is a column, e.g. 3
;;;; s is a square, e.g. [:a 3]
;;;; d is a digit, e.g. 9
;;;; u is a unit, e.g. [[:a 1] [:b 1] [:c 1] ... [:i 1]]
;;;; grid is a grid, e.g. 81 non-blank chars, e.g. starting with ".18...7..."
@jkk
jkk / karma.clj
Created December 22, 2010 05:04
karma.clj
;; re http://groups.google.com/group/clojure/browse_thread/thread/55faa29db75192d0
(ns user
(use [clojure.java.io :only [reader]]))
(def re-vote #"([A-z]{1,16})(\+\+|\-\-)")
(defn extract-votes
[line]
(map rest (re-seq re-vote line)))
;; in response to https://gist.github.com/733674
(def m
{"Lisa Rose" {"Lady in the Water" 2.5 "Snakes on a Plane" 3.5}
"Gene Seymour" {"Lady in the Water" 3.0 "Snakes on a Plane" 3.5}})
;; one way
(reduce
(fn [m [critic movie rating]]
(assoc-in m [movie critic] rating))
user www www;
worker_processes 5;
error_log logs/error.log;
pid logs/nginx.pid;
worker_rlimit_nofile 8192;
events {
worker_connections 4096;
}
(ns user
(:require [clojure.string :as str]
[clojure.java.io :as io]))
(def postcode-trie
(with-open [r (io/reader "/Users/tin/src/clj/playground/postcodes.txt")]
(reduce
(fn [trie line]
(let [[postcode region] (.split line ",")
postcode (str/replace postcode " " "")]