Skip to content

Instantly share code, notes, and snippets.

View edw's full-sized avatar

Edwin Watkeys edw

View GitHub Profile
@edw
edw / README.md
Created November 13, 2020 17:30
Building OG vi on Big Sur

Building OG vi on Big Sur

  1. Make sure developer tools are installed.
  2. Get the source from Freshmeat.
  3. Run tar xvfj ex-050325.tar.bz2 && cd ex-050325.
  4. Add include <sys/ioctl.h> to file ex.h.
  5. Run the following:
make install INSTALL=/usr/bin/install \
 PREFIX=${HOME}/.local/ \
@edw
edw / problem62.go
Created July 11, 2020 12:18
Project Euler Problem 62
// Solves problem 62 by iterating over all ints in increasing order
// and storing each in a map keyed by the lexigraphically-sorted
// cube of that number's digits. Repeat until storing an int results
// in the map key having five values associated with it.
//
// https://projecteuler.net/problem=62
//
// It turns out big ints weren't necessary to solve the problem,
// but re-writing numerics code from regular to big numbers is
// a huge PITA, so it's better to start with math/big if you think
@edw
edw / caching.go
Last active July 8, 2020 14:49
Coins solutions
package main
import "fmt"
func main() {
fmt.Printf("%d\n", iter(36, []int{25, 10, 5, 1})) // descending order, reverse of naive.
}
type Cache map[string]int
@edw
edw / iterator.sld
Last active May 22, 2020 22:41
Collection Iterators in R7RS Scheme
;; Collection Iterators
;; Edwin Watkeys
;; May 22, 2020
;; MIT Licensed
(define-library (iterator)
(import (scheme base) (scheme list) (srfi 111) (chibi generic))
(export iterable? iterate map reduce next empty into done?
icons imake inext iempty imap-proc)
;; Collection Iterators
;; Edwin Watkeys
;; May 22, 2020
;; MIT Licensed
(define-library (iterator)
(import (scheme base) (scheme list) (srfi 111) (chibi generic))
(export iterable? iterate map reduce next empty into done?
icons imake inext iempty imap-proc)
@edw
edw / iterator.sld
Created May 22, 2020 22:40
Collection Iterators for R7RS Scheme
;; Collection Iterators
;; Edwin Watkeys
;; May 22, 2020
;; MIT Licensed
(define-library (iterator)
(import (scheme base) (scheme list) (srfi 111) (chibi generic))
(export iterable? iterate map reduce next empty into done?
icons imake inext iempty imap-proc)
@edw
edw / atomic-box-test.sld
Last active May 19, 2020 16:31
Scheme implementation of Clojure style atoms
(define-library (atomic-box-test)
(import (scheme base) (scheme write) (chibi test) (atomic-box) (srfi 18))
(export run-tests)
(begin
(define (thread-spawn thunk)
(let ((t (make-thread thunk)))
(thread-start! t)
t))
@edw
edw / syntax-rules-ex.scm
Last active May 18, 2020 15:41
A working but not recommended macro
;;; This is not a good use of macros. See below for an
;;; example implementation of COND.
(define-syntax proc-all
(syntax-rules ()
((_ exp () body ...)
(begin body ...))
((_ exp (match matches ...) body ...)
(unless (= exp match) (proc-all exp (matches ...) body ...)))))
@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)