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
#lang racket | |
(define (obj state msg) | |
(match msg | |
['init (cons state (curry obj state))] | |
['get-x (cons state (curry obj state))] | |
[(list 'set-x x) (cons x (curry obj x))] | |
['ping (cons "pong" (curry obj state))])) | |
(define-syntax-rule (send! obj msg) |
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
module Main where | |
import Test.Hspec | |
import VM | |
($=) = shouldBe | |
main :: IO () | |
main = hspec $ do | |
describe "runVM" $ do |
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 LambdaCase #-} | |
import Control.Concurrent | |
import Control.Concurrent.Chan | |
import Control.Monad | |
import Network.Socket | |
import System.IO | |
data MainMessage = Accept Socket SockAddr | |
| MsgReceived String |
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
class dotdict(dict): | |
def __getattribute__(self, key): | |
if key in self: | |
return self[key] | |
return dict.__getattribute__(self, key) | |
d = dotdict(a=1, b=2) | |
print d.a, d.b | |
print d.c |
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
// So I don't lose it | |
function boxCollide(a, b) { | |
if ((a.y+a.h <= b.y) || (a.y >= b.y+b.h)) return false; | |
if ((a.x+a.w <= b.x) || (a.x >= b.x+b.w)) return false; | |
return true; | |
} |
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
#include <cstring> | |
#include <iostream> | |
#include <thread> | |
#include <future> | |
#include <queue> | |
std::mutex mqMutex; | |
std::queue<std::tuple<size_t, std::promise<void*>&>> mq; | |
void * alloc(size_t len) { |
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
function cps_prim(f) { | |
return function() { | |
var r = arguments.reverse(); | |
return r[0]( f.apply(this, arguments.slice(1).reverse()) ); | |
} | |
} | |
function _sqrt() { return cps_prim(function(x) { return 6; }); } | |
function _mul(a, b) { return a*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
/* sums the digits of the factorial 10 (since not much larger can be held by a double) | |
copyright (c) 2011 darkf | |
use for anything, CC-0 or public domain etc */ | |
#include <stdio.h> | |
#include <string.h> | |
double f(int n){return !n?1:n*f(n-1);} | |
int g(char* b){int x=0,i;for(i=0;i<strlen(b);i++)x+=b[i]-'0';return x;} | |
main(){char b[256];double x=f(10);sprintf(b,"%.0f",x);printf("%d",g(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
/* blokvm -- a darkf implementation of blockeduser's terrible vm | |
copyright (c) 2012 darkf */ | |
#include <stdio.h> | |
#include <stdlib.h> | |
/* 3 * 255^2 */ | |
#define BITMAP_SIZE 195075 | |
#define JMP fseek(fp, PC, SEEK_SET); |
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
# mockup of a game-oriented behavior modeling language, v6 (1/13/2012) | |
# copyright (c) 2012 darkf | |
# define player as an object that is both movable, drawable and a rigid body (via tags) | |
player <- Object() | |
player is Movable, RigidBody, Drawable # three tags | |
tiles <- Array2D(64, 64) # 2-dimensional array of size 64x64 for holding map tiles | |
# Array2D is by default tagged with Iterable, Indexable | |
tiles is Drawable # add a Drawable tag so we can treat it as a game object |
OlderNewer