This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"crypto/rand" | |
"encoding/hex" | |
"encoding/json" | |
"fmt" | |
"github.com/garyburd/redigo/redis" | |
"io" | |
"time" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE ScopedTypeVariables #-} | |
module Main where | |
import Network (listenOn, withSocketsDo, accept, PortID(..), Socket) | |
import Control.Concurrent (forkIO) | |
import Control.Exception (handle, IOException) | |
import Control.Monad (liftM) | |
import System.IO (hSetBuffering, hPutStr, hClose, hGetContents, BufferMode(..), Handle, readFile) | |
import Debug.Trace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set a, data | |
jsr strlen | |
set b, a | |
set a, data | |
jsr reverse | |
jsr print | |
set PC, end | |
; reverse the string in place at [a], of len b | |
:reverse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Partial Scheme interpreter | |
# Heavily inspired by Peter Norvig's Lispy (http://norvig.com/lispy.html) | |
# TODO: add more datatypes (strings, floats) | |
# TODO: allow multiple arguments, like (+ 1 2 3 4 5) | |
class Env < Hash | |
def initialize(ks = [], vs = [], outer = nil) | |
@outer = outer | |
ks.zip(vs).each {|item| store(item[0], item[1])} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1.8 | |
> 1.to_a | |
[1] | |
> 1.respond_to?(:to_a) | |
true | |
> a,b = 10 | |
[10] | |
> a | |
[10] | |
> b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Befunge-93 interpreter (http://en.wikipedia.org/wiki/Befunge) | |
class BefungeParser | |
attr_accessor :stack, :program, :px, :py, :direction, :debug_mode | |
Binary_ops = ['*', '+', '-', '/', '%'] | |
def initialize(code) | |
@stack = [] | |
@program = [] | |
@px = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A very simple Brainfuck interpreter | |
class BFParser | |
attr_accessor :memory, :loop_out, :loop_in, :code_size, :code | |
def initialize(code, stack_size = 10000) | |
@memory = [0] * stack_size | |
@code = code.split(//) | |
@code_size = code.length | |
@loop_in = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
solveRPN :: String -> Float | |
solveRPN = head . foldl ff [] . words | |
where ff (x:y:ys) "*" = (x * y):ys | |
ff (x:y:ys) "+" = (x + y):ys | |
ff (x:y:ys) "-" = (y - x):ys | |
ff (x:y:ys) "/" = (y / x):ys | |
ff (x:y:ys) "^" = (y ** x):ys | |
ff (x:y:ys) "log" = (logBase x y):ys | |
ff (x:xs) "ln" = log x:xs | |
ff xs "sum" = [sum xs] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ruby duopaste.rb | |
== Sinatra/1.0 has taken the stage on 4567 for development with backup from Mongrel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'duopaste' | |
run Sinatra::Application |
NewerOlder