Skip to content

Instantly share code, notes, and snippets.

-- generate random assembly for tiny
opcodes = {
{{ 'AND', 'm', 'm' }, { 'AND', 'm', 'c' }},
{{ 'OR', 'm', 'm' }, { 'OR', 'm', 'c' }},
{{ 'XOR', 'm', 'm' }, { 'XOR', 'm', 'c' }},
{{ 'NOT', 'm' }},
{{ 'MOV', 'm', 'm' }, { 'MOV', 'm', 'c' }},
{{ 'RANDOM', 'm' }},
{{ 'ADD', 'm', 'm' }, { 'ADD', 'm', 'c' }},
{{ 'SUB', 'm', 'm' }, { 'SUB', 'm', 'c' }},
@silverweed
silverweed / rocalc.y
Last active August 29, 2015 14:15
Roman numbers calculator
/* Roman numbers calculator
* compile with something like: `bison rocalc.y && gcc -o rocalc rocalc.tab.c -lm`
* Requires: Bison >= 3.0
* Author: silverweed
*/
%{
#include <math.h>
#include <stdio.h>
#include <string.h>
int yylex(void);
@silverweed
silverweed / Makefile
Last active August 29, 2015 14:15
Roman numbers calculator - enhanced
rovars: rovars.tab.c lex.yy.c
gcc -o rovars $^ -lm
rovars.tab.c: rovars.y
bison -d $<
lex.yy.c: rovars.l
flex $<
@silverweed
silverweed / minifier.awk
Created April 20, 2015 14:14
C minifier
#!/usr/bin/gawk -f
# C / C++ code minifier by silverweed
# Strips all superfluous blank spaces still producing compilable code.
# Somewhat tested.
BEGIN {
for (i = 1; i < length(ARGV); ++i) {
if (match(ARGV[i],/^-([0-9]+)$/,mch)) {
maxlines = mch[1]
}
# http://www.reddit.com/r/dailyprogrammer/comments/32vlg8/20150417_challenge_210_hard_loopy_robots/
type Point{T <: Real}
x :: T
y :: T
end
const NORTH = uint8(0)
const EAST = uint8(1)
const SOUTH = uint8(2)
const WEST = uint8(3)
@silverweed
silverweed / pypkpclient.py
Created May 12, 2015 10:47
Minimalistic pokepon client
#!/usr/bin/python3
# simple Pokepon client
# by silverweed
import telnetlib
import getpass
import hashlib
import sys
import signal
from threading import Thread
import re
@silverweed
silverweed / primes.rock
Last active August 29, 2015 14:21
ROCK interpreter
-- Example ROCK program
-- Print all primes up to limit.
-- Note: the function calling convention is that:
-- 1- arguments are passed via the $arg, $arg2, ... variables.
-- 2- return values are passed via the $res, $res2, ... variables.
-- 3- all those variables must be declared by the callee.
-- 4- internally, all functions use labels with names prefixed by
-- function_name_*
-- 5- internally, all functions call variables with a leading _.
-- This means that all variables starting with a _ should be considered
@silverweed
silverweed / hash.c
Created June 7, 2015 13:49
tiny hash map library
/* experimental hash library in ANSI C
* @author silverweed
* @license GNU GPL v3
*/
#include "hash.h"
#include <stdlib.h>
#define DEBUG 1
#if DEBUG >= 1
@silverweed
silverweed / clock.coffee
Created July 9, 2015 10:33
Simple countdown clock in Coffeescript
window.startClock = (finalTime, startingDiffHrs) ->
$ = init()
drawCircle = (coord) ->
sw 2
s circle coord...
fcol 0, 0, 0
f circle coord[0], coord[1], coord[2]/20
for i in [1..10]
a = 2*PI/10 * i
{-# LANGUAGE OverloadedStrings, ExtendedDefaultRules #-}
module Main where
import Database.MongoDB
import Data.Text (unpack)
import Data.Int (Int64)
import Data.List (groupBy, nub)
import Data.DateTime (DateTime, fromSeconds, toGregorian')
import Data.UnixTime (diffUnixTime, secondsToUnixDiffTime, fromEpochTime, udtSeconds)