Skip to content

Instantly share code, notes, and snippets.

@jeremycw
jeremycw / interpreter.rb
Last active May 9, 2022 19:59
Basic expression interpreter
class Interpreter
attr_reader :user
def initialize(user)
@user = user
end
def evaluate(expression)
return send(*expression.map { |arg| arg.is_a?(Array) ? evaluate(arg) : arg })
end
@jeremycw
jeremycw / stackless_coroutine.rb
Last active July 12, 2020 09:18
Stackless Coroutine implementation in ruby
#Copyright (c) 2019 Jeremy Williams
#Permission is hereby granted, free of charge, to any person obtaining a copy
#of this software and associated documentation files (the "Software"), to deal
#in the Software without restriction, including without limitation the rights
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#copies of the Software, and to permit persons to whom the Software is
#furnished to do so, subject to the following conditions:
#The above copyright notice and this permission notice shall be included in all
@jeremycw
jeremycw / async.rb
Created May 21, 2019 16:36
Async Program
class FooBar
include AsyncProgram::Program
attr_accessor :state
async_program(:state) do |p|
p.while { |data| data.loop == true }
p.run { |data| puts "looping" }
p.if { |data| data.status == 'ready' }
p.run { |data| puts data.status }
@jeremycw
jeremycw / sse.coffee
Created August 29, 2012 14:19
SSE implementation in CoffeeScript
cluster = require('cluster')
http = require('http')
zmq = require('zmq')
numCPUs = require('os').cpus().length
NODES = ['tcp://localhost:5555']
if cluster.isMaster
publisher = zmq.socket('pub')
@jeremycw
jeremycw / vim.rb
Created December 2, 2011 23:09 — forked from uasi/vim.rb
Vim formula for Homebrew
require 'formula'
class Vim < Formula
homepage 'http://www.vim.org/'
url 'ftp://ftp.vim.org/pub/vim/unix/vim-7.3.tar.bz2'
head 'https://vim.googlecode.com/hg/'
sha256 '5c5d5d6e07f1bbc49b6fe3906ff8a7e39b049928b68195b38e3e3d347100221d'
version '7.3.294'
def features; %w(tiny small normal big huge) end