Skip to content

Instantly share code, notes, and snippets.

View tbl3rd's full-sized avatar
👣
Scalawag

Tom Lyons tbl3rd

👣
Scalawag
View GitHub Profile
(defn f [x n] (if (> x 1) n (recur (+ x (rand)) (+ 1 n))))
(defn e [n] (reduce + (repeatedly n #(f 0.0 0))))
(e 100000000) ;; 271828198 YMMV
@tbl3rd
tbl3rd / naur.org
Created August 21, 2019 00:54
Programming as Theory Building, by Peter Naur

Programming as Theory Building, by Peter Naur

from Microprocessing and Microprogramming, Volume 15, Issue 5, May 1985, Pages 253-261.

Introduction

The present discussion is a contribution

@tbl3rd
tbl3rd / commas.clj
Last active April 7, 2022 13:41
Codes Without Commas for SoftEng Meetup
"We will waste 45 minutes writing a do-nothing program in a
60-year-old programming language. The program explains a
mistake made by 2 physicists in 1957. (And don't miss the
lame joke at the end.) Luncheon will be served as usual."
(ns commas
"CODES WITHOUT COMMAS -- with apologies to F.H.C. Crick et al")
(comment "http://www.pnas.org/content/43/5/416" is the paper.
The year is 1957. What do we know now?)
({:ID "rs3131972",
"200557070005_R06C01" {:GT "1/1",
:IGC "0.853",
:GTZ "1/1",
:R "0.861",
:NORMY "0.828",
:BAF "1",
:LRR "-0.053",
:GTA "1/1",
:THETA "0.975",
@tbl3rd
tbl3rd / vcf-header-metadata.edn
Last active July 24, 2018 12:36
Parse header metadata from a Variant Call Format file into a Clojure map. (See https://github.com/tbl3rd/vcf)
{"p95Red" "8992",
"Extension(A)" "Extension(A)|Extension|25349|405",
"zcallVersion" "1.0.0.0",
"manifestFile" "Broad_GWAS_supplemental_15061359_A1.bpm",
"chipWellBarcode" "200557070005_R06C01",
"Biotin(High)" "Biotin(High)|Staining|618|4165",
"analysisVersionNumber" "1",
"picardVersion" "07b46e26eb638116226b10df9f3f653b82b8ea95",
"String(MM)" "String(MM)|Stringency|896|237",
"arrayType" "Broad_GWAS_supplemental_15061359_A1",
@tbl3rd
tbl3rd / vcf.clj
Created June 21, 2018 01:01
Clojure spec Variant Call Format files loosely with examples.
(ns vcf
"Hack VCFs."
(:require [clojure.java.io :as io]
[clojure.spec.alpha :as s]
[clojure.string :as str])
(:import [java.util.zip GZIPInputStream]))
;; Sketch a loose spec of a VCF file, but ::vcf-file takes too long,
;; so this is mostly just for documentation.
;;

Clojure now has many tools for debugging.

  • Cider NREPL debugger
  • clojure.tools.trace
  • #dbg
  • :break/when metadata
  • pre- and post-conditions
  • clojure.spec

good old println

@tbl3rd
tbl3rd / partition.clj
Created March 3, 2016 02:41
partition stream
(->> (range)
(partition 2)
(take 5))
;;=> ((0 1) (2 3) (4 5) (6 7) (8 9))
@tbl3rd
tbl3rd / dogit.sh
Last active August 29, 2015 14:24
Run a git command on all repos in a directory tree.
#!/bin/bash
function help {
local dogit="$1"
local lines=(
"$dogit: Run a git command on all repos in a directory tree."
""
"Usage: $dogit <directory> [<command> ...]"
""
"Where: <directory> is the root of a tree of git repos."
@tbl3rd
tbl3rd / manage-logs.conf
Last active August 29, 2015 14:18
manage logs without a framework
# Fnord
description "Manage Fnord remote logs from fnorders"
start on stopped rc RUNLEVEL=[2345]
stop on runlevel [016S]
task