Skip to content

Instantly share code, notes, and snippets.

@DuoSRX
DuoSRX / bf.scala
Created March 8, 2015 23:05
Brainfuck in Scala
import scala.util.parsing.combinator.RegexParsers
object BF extends App {
val raw = "+foobar+++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>."
val program = BFParser.parseAll(BFParser.program, raw).get
val vm = new VM(program)
vm.run
}
trait Command
@DuoSRX
DuoSRX / Main.hs
Created December 7, 2014 06:07
simplistic haskell web server
{-# 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

Keybase proof

I hereby claim:

  • I am duosrx on github.
  • I am duosrx (https://keybase.io/duosrx) on keybase.
  • I have a public key whose fingerprint is E7BB 0DC5 2071 C340 14A0 68DE 477F 5091 D9BC 863D

To claim this, I am signing this object:

@DuoSRX
DuoSRX / brainfuck.rs
Created May 26, 2014 19:26
Brainfuck in Rust
use std::char::from_u32;
use std::str::from_char;
#[deriving(Eq, Show)]
pub enum Command {
Add(int),
Move(int),
Output,
LoopIn,
LoopOut,
@DuoSRX
DuoSRX / sidekiq.go
Last active May 6, 2021 07:54
Enqueue Sidekiq jobs from Go
package main
import (
"crypto/rand"
"encoding/hex"
"encoding/json"
"fmt"
"github.com/garyburd/redigo/redis"
"io"
"time"
@DuoSRX
DuoSRX / gist:2363468
Created April 11, 2012 23:30
random dcpu16 stuff
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
@DuoSRX
DuoSRX / schemy.rb
Created December 12, 2011 22:51
Schemy
# 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])}
# 1.8
> 1.to_a
[1]
> 1.respond_to?(:to_a)
true
> a,b = 10
[10]
> a
[10]
> b
# 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
# 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 = []