Skip to content

Instantly share code, notes, and snippets.

View delonnewman's full-sized avatar

Delon R. Newman delonnewman

View GitHub Profile
" General
set nocompatible
filetype on
filetype plugin on
filetype indent plugin on
set ofu=syntaxcomplete#Complete
set modeline
set history=1000
set clipboard+=unnamed
set ffs=unix,dos,mac
@delonnewman
delonnewman / run.php
Created April 29, 2017 07:15 — forked from greut/run.php
A web server in pure PHP (non-concurrent and concurrent)
#!/usr/bin/env php
<?php
$app = function($request) {
$body = <<<EOS
<!DOCTYPE html>
<html>
<meta charset=utf-8>
<title>Hello World!</title>
function escape_mb_chars($str) {
$first = preg_replace_callback('/\p{C}/u', function ($m) {
$char = current($m);
return substr(json_encode($char), 1, -1);
}, $str);
return rtrim($first, '\n');
}
@delonnewman
delonnewman / diff.clj
Created August 9, 2016 04:55
Joseph McCarthy's diff function in WonderScript
; vim: set ft=clojure
; Joseph McCarthy's diff function
; see:
; J. McCarthy, Recursive Functions of Symbolic Expressions and Their Computation by Machine, Part I, April 1960
;
; diff [y; x] = [atom[y] →
; [eq[y; x] → ONE; T → ZERO];
; eq[car [Y]; PLUS] → cons [PLUS; maplist[cdr[y]; λ[[z]; diff[car [z]; x]]]];
; eq[car [y]; TIMES] → cons[PLUS; maplist[cdr[y];
; λ[[z]; cons [TIMES; maplist[cdr [y];
@delonnewman
delonnewman / fish-prompt.sh
Created August 3, 2016 18:32 — forked from gak/fish-prompt.sh
My custom fish prompt code explained at http://geraldkaszuba.com/tweaking-fish-shell/
function _common_section
printf $c1
printf $argv[1]
printf $c0
printf ":"
printf $c2
printf $argv[2]
printf $argv[3]
printf $c0
printf ", "
; from https://aan.io/dumping-datomic-schema/
(let [dbval (d/db conn)]
(->> (d/q '[:find ?ident
:in $ ?p
:where
[:db.part/db :db.install/attribute ?attr]
[?attr :db/ident ?ident]]
dbval :db.part/user)
(map (fn [attr] [(d/entity dbval (first attr))]))
(map (fn [attr]
@delonnewman
delonnewman / macros.js
Last active March 7, 2016 22:01
Some macros written in WonderScript as JavaScript data structures (found in the core library).
ws.eval(
['defmacro', 'let', ['form'],
['do',
['def', 'bindings',
['map', ['pair', ['form', 1]] , ['fn', ['x'], ['.concat', ['array', '`def'], 'x']]]],
['def', 'exprs', ['.slice', 'form', 2]],
['.concat', ['array', '`do'], 'bindings', 'exprs']]]);
ws.eval(
['defmacro', 'deftype', ['form'],
@delonnewman
delonnewman / fib.clj
Last active March 7, 2016 21:56
Showing the Fibonacci Sequence approximating the Golden Ratio in WonderScript
(def fib
(memoize
(fn [n]
(cond (=== n 0) 0
(=== n 1) 1
:else (+ (fib (- n 1)) (fib (- n 2)))))))
(let [fibs (map (range 20) fib)
pairs (pair fibs)
ratios (reduce pairs (fn [memo xs] (.concat memo (apply div (.reverse xs)))) [])]
@delonnewman
delonnewman / math.rb
Last active April 25, 2020 07:31
Just for Fun: Symbolic Math in Ruby
module Expression
OPTS = {
:+ => :add,
:- => :sub,
:* => :mult,
:/ => :div,
:** => :exp
}
def +(other)
@delonnewman
delonnewman / fun.rb
Last active November 18, 2015 20:29
fun.rb - functional Ruby, taking some ideas from Clojure
class Hash
def to_proc
lambda { |x| self[x] }
end
end
class Array
def to_proc
lambda { |x| self[x] }
end