Skip to content

Instantly share code, notes, and snippets.

View jeremyheiler's full-sized avatar

Jeremy Heiler jeremyheiler

View GitHub Profile
(ns parsing)
;; http://www.cs.nott.ac.uk/~pszgmh/monparsing.pdf
(defn parse
[p input]
(p (seq input)))
(defn result
[v]
@jeremyheiler
jeremyheiler / 2015.txt
Last active January 9, 2016 23:28
Books Read
Book | Author
----------------------------------------
The Martian | Andy Weir
1984 | George Orwell
Starship Troopers | Robert A. Heinlein
The Gods Themselves | Isaac Asimov
Dune | Frank Herbert
@jeremyheiler
jeremyheiler / Main.java
Last active January 3, 2016 07:39
Read a file with one line of Java.
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Paths;
public class Main {
public static void main(String[] args) throws Exception {
System.out.println(new String(Files.readAllBytes(Paths.get("/foo.txt")), "UTF-8"));
}
}
user> (defn foo [& {:keys [bar] :or {bar 1}}] bar)
#'user/foo
user> (foo)
1
user> (foo :baz 2)
1
user> (foo :bar 2)
2
// var foo = bar = 42;
{
"type": "Program",
"body": [
{
"type": "VariableDeclaration",
"declarations": [
{
"type": "VariableDeclarator",
"id": {
@jeremyheiler
jeremyheiler / gist:6695635
Last active December 23, 2015 21:19
variable and function definitions for a javascript-based lisp?
;; javascripty
(var foo 42)
(var inc (function (x) (+ x 1)))
(function dec (x) (- x 1))
;; clojurey
(def foo 42)
(def inc (fn [x] (x + 1)))
(defn dec [x] (- x 1))
(defmacro apply (f arr)
`(f ~@arr))
(apply str ["foo" "bar" "baz"])
;; macroexpands to:
(str "foo" "bar" "baz")
@jeremyheiler
jeremyheiler / mc.lisp
Created September 17, 2013 03:57
My first lisp program.
; Missionaries and Cannibals
;-------------------------------------------------------------------------------
; main method
( defmethod mc ()
( establish-operators )
( setup )
( solve )
)
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#define BUFFER_SIZE 5
struct reqdata
{
char *data;
size_t len;
@jeremyheiler
jeremyheiler / gist:6432956
Created September 4, 2013 05:05
Print the contents of a file to stdout.
#include <stdio.h>
#include <errno.h>
int main(int argc, char **argv)
{
if (argc == 1) return 0;
if (argc == 2) {
char *filename = argv[1];
FILE *fp = fopen(filename, "r");
if (!fp) {