Skip to content

Instantly share code, notes, and snippets.

rrees / isort.cfg
Created Apr 3, 2020
An isort config that is compatible with Black
View isort.cfg
rrees /
Created Jun 24, 2016
Hackerrank Python 3 stub
import sys
# Import n lines from a file
t = int(input().strip())
for a0 in range(t):
n = int(input().strip())
View hackerrank-stub2.clj
(use '[clojure.string :only (split triml)])
let [
n_t (read-line)
n (Integer/parseInt n_t)
let [
rrees / hackerrank-stub.clj
Created May 5, 2016
Hackerrank stub for handling IO
View hackerrank-stub.clj
(let [in (slurp *in*)
lines (clojure.string/split in #"\s")]
(println lines))
View gist:fce1c870d422ccbf8cc0
View Pysistence example
base_data_sources = make_dict({
'business': BusinessDataSource(clientUS),
'money': USMoneyDataSource(clientUS),
'technology': TechnologyDataSource(clientUS),
'sport': SportUSDataSource(clientUS),
'comment': CommentIsFreeDataSource(clientUS),
'culture': CultureDataSource(clientUS),
'top_stories': TopStoriesDataSource(clientUS),
'video': VideoDataSource(clientUS),
rrees / gist:4145023
Created Nov 25, 2012
Clojure tail recursion
View gist:4145023
(defn all-nums? [cs]
(let [i (first cs) r (rest cs)]
(if (and i (Character/isDigit i))
(if (empty? r) true (recur r))
(all-nums? (seq "1234")) ;; true
(all-nums? (seq "12a4")) ;; false
(all-nums? (seq "")) ;; false
rrees / gist:4034692
Created Nov 7, 2012
Balanced parens example
View gist:4034692
(defn balanced?
([s] (apply balanced? 0 (seq s)))
([current-count x & xs]
(let [new-count
(= x \() (inc current-count)
(= x \)) (dec current-count)
:else current-count)]
rrees / gist:2850527
Created Jun 1, 2012
Core logic example
View gist:2850527
(ns euroclojure.logic
(:use [clojure.core.logic]))
(defn query []
(run 1 [q]
(membero q [1 2 3])))
;; 1
(defn query-all []
rrees / gist:2819932
Created May 28, 2012
Event reducer example
View gist:2819932
(def example-story-events [
:title "Funding cut again"
:tags [:science]
:author ["Chuck Newton"]
:tags [:politics]