Skip to content

Instantly share code, notes, and snippets.


Drew Olson drewolson

View GitHub Profile
drewolson / reflection.go
Last active Aug 10, 2022
Golang Reflection Example
View reflection.go
package main
import (
type Foo struct {
FirstName string `tag_name:"tag 1"`
LastName string `tag_name:"tag 2"`
drewolson / chat.go
Created Oct 25, 2012
simple golang chat server
View chat.go
package main
import (
type Client struct {
incoming chan string
outgoing chan string
drewolson / gen_server.rb
Created Oct 25, 2013
A naive implementation of gen_server in Ruby, for demonstration purposes.
View gen_server.rb
require "ostruct"
require "securerandom"
module GenServer
class << self
def call(pid, method, *args)
entry = fetch_entry(pid)
value, state = entry.module.send(method, entry.state, *args)
entry.state = state
update_entry(pid, entry)
drewolson / async_pmap.clj
Last active Oct 3, 2017
pmap using core.async
View async_pmap.clj
(ns async-example.core
(:require [clojure.core.async :refer :all])
(defn my-pmap [f col]
(let [chans (repeatedly (count col) chan)]
(doseq [[c e] (map vector chans col)]
(go (>! c (f e))))
(map <!! chans)))
drewolson / chat_server.rb
Created Nov 3, 2012
celluloid chat server
View chat_server.rb
require "socket"
require "rubygems"
require "bundler/setup"
require "celluloid"
module Chat
class ConnectionListener
include Celluloid
drewolson / non_spooky.rb
Last active Dec 31, 2015
JavaScript: spooky action at a distance
View non_spooky.rb
foo = 1
lambda do
if true
puts foo
foo = 2
drewolson / streams.js
Created Jun 21, 2013
streams2 example
View streams.js
var Readable = require("stream").Readable;
function buildStream() {
var i = 0;
var stream = new Readable({objectMode: true});
stream._read = function (n) {
if (i < 10) {
} else {
drewolson / curry3.js
Last active Dec 18, 2015
Functional Javascript curry3 example
View curry3.js
// The code below refers to examples found on page 120 of the PDF
// required functions
var _ = require("underscore")._;
var plays = [{artist: "Burial", track: "Archangel"},
{artist: "Ben Frost", track: "Stomp"},
{artist: "Ben Frost", track: "Stomp"},
{artist: "Burial", track: "Archangel"},
drewolson / collect.go
Created Oct 16, 2012
go higher order functions
View collect.go
package main
import "fmt"
func collect(vals []int, f func(int) int) []int {
length := len(vals)
newVals := make([]int, length, length)
for i, val := range vals {
newVals[i] = f(val)
View gist:1500444
socket = require ""
class Server
constructor: ->
@io = socket.listen 6788
@io.configure =>
@io.set "log level", -1