Skip to content

Instantly share code, notes, and snippets.

#?(:clj
(defn cljs-env?
"Take the &env from a macro, and tell whether we are expanding into cljs."
[env]
(boolean (:ns env)))
(defmacro if-cljs
"Return then if we are generating cljs code and else for Clojure code.
https://groups.google.com/d/msg/clojurescript/iBY5HaQda4A/w1lAQi9_AwsJ"
[then else]
@grav
grav / medley.md
Last active December 4, 2020 04:20
Getting Interlisp-D running with Medley on Debian 3.1

Install VirtualBox (eg on Mac: brew cask install virtualbox)

Download Debian 3.1 from here: https://virtualboxes.org/images/debian/

Create a new VM in VirtualBox and select the vdi file from the above archive as a disk. Check the VM settings:

  • Make sure the disk is mounted as an IDE device, SATA errors out on boot (in the Storage tab)
  • Also, make sure the pointing device is set to PS/2 Mouse (in the General tab)
@grav
grav / render.js
Created June 25, 2017 18:47
Save a dynamically rendered page with Chrome Headless browser
// Needs a running Chrome Headless, eg:
// /Applications/Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Chrome\ Canary --headless --remote-debugging-port=9222 https://chromium.org
// Run with node, eg `node render.js output.html`
const CDP = require('chrome-remote-interface');
const fs = require('fs')
CDP((client) => {
// Extract used DevTools domains.
const {Page, Runtime} = client;
import SimpleHTTPServer
import SocketServer
import urllib
import re
class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
match = re.search('^/proxy.ashx?\?url=(.+)$',self.path)
if match:
self.send_response(200)
echo -e "\n\n------------ select from ms sql"
sqlcmd -S geotesterapache.cloudapp.net -U sa -P xxx -d skm_test_db -Q "select top 1 * from matrikel"
echo -e "\n\n------------ try parsing the spatial data"
export C_STR='MSSQL:driver=ODBC Driver 13 for SQL Server;server=geotesterapache.cloudapp.net;database=skm_test_db;UID=sa;PWD=xxx;tables=matrikel'
ogrinfo --debug on "$C_STR" -sql "select top 1 * from matrikel"
echo -e "\n\n------------ try querying through postgresql"
service postgresql start
psql -c "create database geotest encoding=UTF8 template=template0;"
@grav
grav / osc.py
Last active June 19, 2016 19:45
Simple oscillator in python, using pyext (http://grrrr.org/research/software/py/)
class osc(pyext._class):
t = 0.0
f = 0.0
def bang_3(self):
print "SR:",self._samplerate(),"BS:",self._blocksize(),"F:",self.f
def _dsp(self):
# if _dsp is present it must return True to enable DSP
@grav
grav / create-reminder.swift
Last active January 29, 2016 12:36
Creating an EKReminder
// remember to
// import EventKit
let s = EKEventStore.init()
s.requestAccessToEntityType(EKEntityType.Reminder) { (comp, e) -> Void in
print(comp,e)
let r = EKReminder.init(eventStore: s)
r.title = "Testreminder!"
let d = NSDate.init().dateByAddingTimeInterval(60)
let a = EKAlarm.init(absoluteDate: d)
(defn js-iterator-to-vec
[it]
(loop [a []]
(if-let [v (-> (.next it)
(.-value))]
(recur (conj a v))
a)))
@grav
grav / gist:57fd2c4da27edfdd1467
Last active August 29, 2015 14:24
replete build instructions
git clone https://github.com/clojure/clojurescript
cd clojurescript
brew install maven # for building clojurescript
./script/build
cd ..
@grav
grav / gist:5d36a83c6c32c05ed1d1
Last active August 29, 2015 14:20
promises and clojurescript
(defn setup-midi!
[]
(.then (.requestMIDIAccess js/navigator)
(fn [midi-access]
(.forEach (.-outputs midi-access)
(fn [o]
(let [name (.-name o)]
(when (= "IAC"
(apply str (take 3 name)))
(.then (.open o)