Skip to content

Instantly share code, notes, and snippets.

View sample.jl
function rand_first_index(n, k)
r = rand()
p = k/n
i = 1
while p < r
i += 1
p += (1-p)k/(n-(i-1))
return i
View with.jl
isexpr(x::Expr, ts...) = x.head in ts
isexpr{T}(x::T, ts...) = T in ts
macro with(exprs...)
exprs = collect(exprs)
target = nothing
if length(exprs) > 1 && !isexpr(exprs[end], :(::))
target = esc(exprs[end])
View userbehaviours.clj
;; The app tag is kind of like global scope. You assign behaviors that affect
;; all of Light Table to it.
[:app "dark"]
[:app :lt.objs.plugins/load-js "user_compiled.js"]
[:app :lt.objs.langs.julia/julia-path "C:\\Users\\Mike\\Julia 0.3.0-prerelease\\bin\\julia.exe"]
;; The editor tag is applied to all editors
[:editor :lt.objs.editor/no-wrap]
[:editor "june"]
View cueball.clj
(ns cueball
(:use [cljs.compiler :exclude [munge macroexpand-1]]
;; Implementation of `quote` with unquoting
(defn seqable? [e]
(if-not (string? e)
(try (seq e)
(catch Exception e false))))
View paredit.clj
;; Paredit's features (
;; in clojure/clarity.
;; All examples can be done quickly with the keyboard in e.g.
;; Sublime Text - no plugins required.
defn my-command []
View Dict.nb
SetAttributes[Dictionary, Orderless];
Dictionary[key_ -> val_, ___][key_] := val;
Dictionary[___][key_] := key;
d_Dictionary.key_ ^:= d[key];
x_ /. Dictionary[rs___] ^:= x /. {rs};
Dictionary[{rs___}] := Dictionary[rs];
Assoc[Dictionary[key_ -> _, rs___], key_ -> val_] :=
Dictionary[key -> val, rs];
Assoc[Dictionary[rs___], key_ -> val_] := Dictionary[key -> val, rs];

Keybase proof

I hereby claim:

  • I am MikeInnes on github.
  • I am onemoreminute ( on keybase.
  • I have a public key whose fingerprint is DBF9 C2D0 9AEA 16E5 6A95 FAEF DFD3 2796 D8FD 8A25

To claim this, I am signing this object:

MikeInnes / startup.jl
Last active Jun 23, 2021
Some useful macros for Julia
View startup.jl
# Repeat an operation n times, e.g.
# @dotimes 100 println("hi")
macro dotimes(n, body)
for i = 1:$(esc(n))