Skip to content

Instantly share code, notes, and snippets.

View samdphillips's full-sized avatar

Sam Phillips samdphillips

  • Oakland, California
View GitHub Profile
@samdphillips
samdphillips / gist:2760405
Created May 21, 2012 03:08
racket hack for reporting shadowed bindings
#lang racket/base
(require (for-syntax racket/base)
(only-in racket/base
[define orig-define]))
(define-syntax (define stx)
(syntax-case stx ()
[(_ x e)
(when (identifier-binding #'x)
@samdphillips
samdphillips / gist:560b8fb1d293d6a91a67
Last active August 29, 2015 14:05
Bitmap doesn't draw correctly at scales larger than 1. (At least not on Racket 6.1 on OSX 10.9.4)
#lang racket/base
(require racket/class
(only-in racket/draw
make-bitmap)
(only-in racket/gui
canvas%
frame%)
(only-in racket/math
exact-ceiling)
@samdphillips
samdphillips / gist:d3448919252d2c245a29
Created September 9, 2014 04:01
Integrating Racket Classes and Struct Generics
#lang racket/base
(require racket/block
racket/class
racket/generic)
(define gar<%>
(interface ()
do-foo
do-bar))
ask patches
[ set chemical chemical * (90 - evaporation-rate) / 90 ;; slowly evaporate chemical
set water water * water-evaporation-rate
recolor-patch ]
@samdphillips
samdphillips / kv_extract.py
Created January 13, 2015 20:00
Basic kv_extract text utility
import re
import sys
keys = sys.argv[1:]
kv_re = re.compile(r'(?P<key>[^ =]+)=(?P<value>\S+)')
def strip_comma(s):
if s[-1] == ',':
return s[:-1]
return s
import sys
d = {}
for line in sys.stdin:
key,value = line.strip().split('\t')
count, running_value = d.get(key, [0, 0])
d[key] = (count + 1, running_value + float(value))
for k,v in d.iteritems():
import sys
from datetime import datetime, timedelta
from syslog import syslog
five_sec = timedelta(seconds=5)
last = datetime.now()
count = 0
while True:
@samdphillips
samdphillips / avg_by_time.py
Last active August 29, 2015 14:14
Random text manipulation
import json
from collections import namedtuple
from datetime import datetime
from log_dumb import *
def from_json():
return map(json.loads)
# WIP
import boto3
import logging
import requests
import spur
AMI_ID = "ami-1c1d9664"
SG_IDS = ['sg-f3d1e28b']
@samdphillips
samdphillips / macros_by_example.md
Last active May 12, 2018 07:42
Macros by Example in Typed Racket

Macros By Example in Typed Racket

Based on ftp://www.cs.indiana.edu/pub/techreports/TR206.pdf

(Yep people still have FTP servers out there...)

NO HYGIENE. NO LITERALS.

Just matches a sexp and expands it (once.)