Skip to content

Instantly share code, notes, and snippets.

View maxcountryman's full-sized avatar
🦀

Max Countryman maxcountryman

🦀
View GitHub Profile
(definterface INode
(getCar [])
(getCdr [])
(setCar [x])
(setCdr [x])
(valAt [i]))
(deftype Node [^:volatile-mutable car ^:volatile-mutable cdr]
INode
(getCar [_] car)
(definterface INode
(getCar [])
(getCdr [])
(setCar [x])
(setCdr [x])
(valAt [i]))
(deftype Node [^:volatile-mutable car ^:volatile-mutable cdr]
INode
(getCar [_] car)
(definterface INode
(getCar [])
(getCdr [])
(setCar [x])
(setCdr [x]))
(deftype Node [^:volatile-mutable car ^:volatile-mutable cdr]
INode
(getCar [_] car)
(getCdr [_] cdr)
import java.util.Arrays;
class DynamicArray<E> {
private transient Object[] elementData;
private int size;
private int modCount = 0;
private int a = 2;
public DynamicArray(int initialCapacity) {
if (initialCapacity < 0)
class Node<T> {
// data cell, i.e. car
public T car;
// pointer or next cell, i.e. cdr
public Node cdr;
public Node(T car) {
this.car = car;
}
@maxcountryman
maxcountryman / gogo.core.clj
Last active December 20, 2015 02:49
Tiny macro library for `clojure.core.async/go`.
(ns gogo.core
(:require [clojure.core.async :refer [go]]))
;; ## Macros Wrapping Macros
;;
;; `gogo` is a tiny, simple macro library that wraps the `go` macro of
;; `clojure.core.async`. Its purpose is to provide helpers after the fashion of
;; things like `when-let` and `if-let`.
from rauth.service import OAuth1Service
# Get a real consumer key & secret from https://dev.twitter.com/apps/new
twitter = OAuth1Service(
name='twitter',
consumer_key='J8MoJG4bQ9gcmGh8H7XhMg',
consumer_secret='7WAscbSy65GmiVOvMU5EBYn5z80fhQkcFWSLMJJu4',
request_token_url='https://api.twitter.com/oauth/request_token',
access_token_url='https://api.twitter.com/oauth/access_token',
authorize_url='https://api.twitter.com/oauth/authorize',
(def conn (with-connection ["irc.example.com" 6667 "foo" "bar" "Foo Bar"]
(defcallback foo [{:keys [command]}]
(println command))))
(run conn)
(defn add-row [cnt acc]
(let [prev (last acc)]
(loop [n 0 row []]
(if (= n cnt)
row
(let [a (nth prev (- n 1) 0)
b (nth prev n 0)]
(recur (inc n) (conj row (if (zero? (+ a b)) 1 (+ a b)))))))))
@maxcountryman
maxcountryman / nonblocking-socket.clj
Last active December 17, 2015 17:39
Playing around with agents. Fun!
(require '[clojure.java.io :as io])
(import [java.net Socket])
(def irc (agent {:socket (Socket. "irc.strangeloop.io" 7000)}))
(send irc (fn [{:keys [socket]}]
(doseq [line (line-seq (io/reader socket))]
(println line))))