Skip to content

Instantly share code, notes, and snippets.

(ns demo.core
(:require [clojure.core.typed :as t]))
;; Map vs Vector AST representation
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; * Maps
(t/defalias M (t/U '{:op ':if :test M :then M :else M}
'{:op ':do :e1 M :e2 M}
(defn seqable? [x]
(or (instance? clojure.lang.ISeq x)
(instance? clojure.lang.Seqable x)
(instance? Iterable x)
(instance? CharSequence x)
(instance? java.util.Map x)
(nil? x)
(.. x getClass isArray)))
@aishraj
aishraj / Hint.md
Created November 13, 2011 09:59 — forked from yuvipanda/Hint.md
Card Shuffling Solution (InterviewStreet CodeSprint Fall 2011)

The main observation is that the card at index i (1 <= i <= N) ends up at index K * i % (N + 1) after 1 shuffle. So after x shuffles, the card will be at position K^x * i % (N + 1). We want to find the smallest x such that K^x * i = i for all i. In other words, we want K^x = 1. This is known as the multiplicative order of K mod (N + 1). Lagrange's theorem implies that this will be a factor of phi(N + 1) where phi is the Euler Totient function. So we can check all factors of phi(N + 1) and find the smallest one which works. See: http://en.wikipedia.org/wiki/Euler's_totient_function http://en.wikipedia.org/wiki/Lagrange's_theorem_(group_theory)

@death
death / gist:2316075
Created April 6, 2012 02:22
DCPU-16 Lisp implementation
(defpackage #:dcpu-16
(:use #:cl)
(:export
#:make-ram #:ram-read #:ram-write #:ram-size
#:execute #:debug
#:load-program #:assemble-program
#:set #:add #:sub #:mul
#:div #:mod #:shl #:shr
#:and #:bor #:xor #:ife
#:ifn #:ifg #:ifb #:jsr
@reborg
reborg / clojure-irc-pdf-links
Last active July 16, 2017 15:18
PDF Links #Clojure IRC
@ghadishayban
ghadishayban / vendor_asm.sh
Created February 12, 2018 01:46
a script that vendors asm and writes itself as git commit 'transaction data'
#!/bin/bash
# author Ghadi Shayban <gshayban@gmail.com>
set -e
if [ -z ${1+x} ]
then
echo provide an asm git sha / ref
exit 1
fi
@bitemyapp
bitemyapp / gist:8739525
Last active May 7, 2021 23:22
Learning Haskell
@hiredman
hiredman / scratch.clj
Created August 12, 2013 20:10
capture class bytes
(def classbytes (atom {}))
(defn bytes-of-forms [form]
(push-thread-bindings
{clojure.lang.Compiler/LOADER
(proxy [clojure.lang.DynamicClassLoader] [@clojure.lang.Compiler/LOADER]
(defineClass
([name bytes src]
(swap! classbytes assoc name bytes)
@mbland
mbland / README.md
Created October 1, 2012 14:51 — forked from JanDupal/README.md
Quick'n'dirty Jekyll plugin for sorted cycle

Jekyll sorted_for plugin

Quick'n'dirty Jekyll plugin for sorted cycle.

Install

Copy sorted_for.rb to _plugins/ directory of your Jekyll site.

Usage

This document has moved!

It's now here, in The Programmer's Compendium. The content is the same as before, but being part of the compendium means that it's actively maintained.