Skip to content

Instantly share code, notes, and snippets.

View edw's full-sized avatar

Edwin Watkeys edw

View GitHub Profile
@edw
edw / binary.py
Last active May 12, 2020 14:58
Binary search in Python
def containsMatch(nums, lower, upper, match):
"""Returns `True` if `match` occurs within indices
[`lower`, `upper`] of sorted list `nums`."""
while True:
i = (upper + lower) // 2
cur = nums[i]
if match == cur:
return True
elif lower >= upper:
@edw
edw / let-optionally.scm
Created April 27, 2020 15:18
Scheme `let-optionally`
(define-syntax let-optionally
(syntax-rules (_)
((_ vs () e f ...)
(let () e f ...))
((_ vs (_ xv ...) e f ...)
(if (null? vs)
(let-optionally '() (xv ...) e f ...)
(let-optionally (cdr vs) (xv ...) e f ...)))
((_ vs ((x v) xv ...) e f ...)
(if (null? vs)
@edw
edw / get-pid.clj
Created April 20, 2020 12:28
Get pid in Clojure under Linux for older Java implementation
(defn get-pid
"Get pid under Linux for older Java implementations"
[]
(-> (java.io.File. "/proc/self")
.getCanonicalFile
.getName
Integer/parseInt))
@edw
edw / clojure-web-service-infra.md
Last active February 18, 2020 17:54
Docs for Writing Clojure Web Services
@edw
edw / igspace.text
Created January 17, 2020 19:17
IGSPACE
[ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀]
@edw
edw / euler.clj
Last active September 3, 2019 21:05
Problem 61 solution.
;;; Solution to https://projecteuler.net/problem=61
(defn quadratic-formula [a b c]
(let [x (Math/sqrt (- (* b b) (* 4 a c)))]
(set [(/ (+ (* -1 b) x) (* 2 a))
(/ (- (* -1 b) x) (* 2 a))])))
(defn whole-number? [n]
(when (and (number? n)
(== (Math/round n) n))
@edw
edw / init.el
Created April 4, 2019 12:03
Recent Emacs Dotfile Finds
(add-hook 'before-save-hook 'whitespace-cleanup)
(defun smart-open-line-above ()
"Insert an empty line above the current line.
Position the cursor at it's beginning, according to the current mode."
(interactive)
(move-beginning-of-line nil)
(newline-and-indent)
(forward-line -1)
(indent-according-to-mode))
@edw
edw / gerbil-index-transcript.md
Created December 22, 2018 16:20
Gerbil Index Transcript
> (load "/Users/edw/dev/i7t/thunknyc/names/index.ss")
"/Users/edw/dev/i7t/thunknyc/names/index.ss"
> (def e (all-exports))
> (hash-ref e 'display)
((gerbil/compiler/ssxi (imported syntax))
 (gerbil/core (imported syntax))
 (scheme/r5rs (imported syntax))
 (scheme/write (imported syntax))
 (std/parser/grammar (imported syntax)))
@edw
edw / README.md
Last active December 19, 2018 19:05
Zippers in Scheme

Zippers

Please see .

@edw
edw / gerbil-cookbook.md
Created December 19, 2018 11:52
Gerbil Cookbook

In Gerbil Scheme, how do I …

Import R7RS libraries?

In the root of the directory structure that contains your libraries:

$ cat > gerbil.pkg
(prelude: :scheme/r7rs)
^D