Skip to content

Instantly share code, notes, and snippets.

@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 / 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
@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 = []
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]
$ ruby duopaste.rb
== Sinatra/1.0 has taken the stage on 4567 for development with backup from Mongrel
require 'duopaste'
run Sinatra::Application