Skip to content

Instantly share code, notes, and snippets.

View robey's full-sized avatar

Robey Pointer robey

View GitHub Profile
@robey
robey / test.cpp
Created April 5, 2012 03:50
my failures with lambda in c++
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
template<typename A, typename Func> auto map_3(const A& orig, Func f) -> std::vector<decltype(f(begin(A())))> {
std::vector<decltype(f(begin(A())))> rv;
rv.resize(orig.size());
std::transform(begin(orig), end(orig), begin(rv), f);
return rv;
@robey
robey / aes.dcpu.txt
Created May 10, 2012 06:28
AES encryption for the DCPU
;----------------------------------------------------------------------------
; AES encryption for the DCPU.
;----------------------------------------------------------------------------
; Fits into 0x400 words, with its tables and key buffer.
; Initialize with a key, for encryption or decryption, then feed it a buffer
; of 16 bytes (8 words) at a time. Check out the unit tests at the end for
; example usage.
;
; Speed: SLOW!
; set_key varies from 3400-4400 cycles for encryption (based on key size);
@robey
robey / gist:4410421
Last active December 10, 2015 08:48
I'm probably not ever going to get around to implementing this, but maybe it will help others who are looking for ideas. It's a floppy disk format i came up with back in May when we were told the DCPU would have a floppy disk drive, but we weren't told what the interface would be like yet. Some of the parameters are flexible in the spec because …

dios disk format

disk/block size

the disk block size is 1KB, or 512 words. each disk has 18 tracks of 80 sectors, or 1440 blocks. a hypothetical hard drive could have up to 64k blocks (64MB) using an addressing scheme of one word block ids.

ascii encoding

@robey
robey / font-loader.js
Created January 25, 2013 02:21
old quick-n-dirty way to convert a font image (for the DCPU) into "dat" lines.
var Fonts = {
fontMemory: [ ],
fontSource: [ ],
// load font from image
loadFont: function(filename) {
var canvas = document.createElement('canvas');
canvas.style.display = "none";
document.body.appendChild(canvas);
@robey
robey / gist:4992726
Created February 20, 2013 03:52
bit_blit or memmove for DCPU
; ----- blit from B (len X) into C -- preserves A Y Z
:blit
ifl b, c
bra blit.backward.extern
:blit.forward.extern
set i, b
set j, c
add x, b
; blit from [I, X) forward into J
:blit.forward
@robey
robey / gist:5189414
Created March 18, 2013 18:12
idempotent service metrics

idempotent operations to store service metrics: we weren't able to come up with a good solution to this.

our rule of thumb for network failures was that packets will get lost, so you can have two behaviors for server operations:

  • at LEAST once: if a response gets lost, retry. you may end up doing the same operation twice.

  • at MOST once: if a response gets lost, give up. the operation might have been lost before the server saw it.

if your operations are idempotent, you can use "at least once" mode for everything. we did that for almost every server i can think of. it was an explicit design goal of flock (the social graph database) and finagle (the server-building toolkit).

@robey
robey / robeys 16bit cpu
Last active December 15, 2015 04:29
theoretical 16-bit CPU
16 registers:
/ / / / / / E F <- value registers (r0 - r5)
/ / / / / / S P <- index registers (a0 - a5)
E = extended (carry/rollover) result
F = flags:
set on result of each binary operation, or load into register
x x x x x x x x / Q x x x M N C Z
(Q) interrupts are queueing
(M) masked: in comparisons, left & right != 0

Using "terminal-notifier" here: https://github.com/alloy/terminal-notifier

Make a helper script for terminal-notifier to keep you from killing yourself:

$ cat ~/bin/terminal-notifier 
#!/bin/bash
/Applications/terminal-notifier.app/Contents/MacOS/terminal-notifier "$@"
{$C-} { Ctrl-break doesn't stop us now! }
{
ZEdit - WWIV full-screen editor
Command line:
ZEDIT [options] filename
Public ("official") releases:
v1.1 - May 30, 1989
@robey
robey / gist:5923601
Created July 3, 2013 23:00
Running two processes in parallel (not tested in real life, typed from an airport)
task "test", run: ->
Q.all(
exec "long-ass process"
exec "another long-ass process"
)