Skip to content

Instantly share code, notes, and snippets.

Avatar

darkf

  • Zero page
View GitHub Profile
@darkf
darkf / event.cpp
Created Feb 8, 2014
Simple event system in C++
View event.cpp
#include <functional>
#include <map>
#include <typeinfo>
#include <iostream>
struct Event {
virtual ~Event() {}
};
struct TestEvent : Event {
std::string msg;
@darkf
darkf / langs.md
Last active Mar 24, 2019
Computer Languages darkf Claims To Know
View langs.md

Computer Languages darkf Claims To Know

Main Programming Languages

  • C
  • C++
  • C#
  • Java
View testcase.py
import mmap
import cffi
ffi = cffi.FFI()
ffi.cdef("struct test { int x; };")
ref = None
def alloc():
@darkf
darkf / rpn.rkt
Created Aug 12, 2012
Racket pure-functional RPN calculator
View rpn.rkt
#lang racket
(define (op? e)
(member e '(+ *)))
(define (op->procedure op)
(case op
[(+) +]
[(*) *]))
@darkf
darkf / easing.js
Created Aug 11, 2017 — forked from gre/easing.js
Simple Easing Functions in Javascript - see https://github.com/gre/bezier-easing
View easing.js
/*
* Easing Functions - inspired from http://gizma.com/easing/
* only considering the t value for the range [0, 1] => [0, 1]
*/
EasingFunctions = {
// no easing, no acceleration
linear: function (t) { return t },
// accelerating from zero velocity
easeInQuad: function (t) { return t*t },
// decelerating to zero velocity
@darkf
darkf / ecs.py
Last active Jul 21, 2017
Hypothetical Entity-Component System in Python
View ecs.py
# Let's define a hypothetical Entity-Component System for a one-dimensional text-based game.
# Copyright (c) 2013 darkf
# First authored 5/14/2013
# Licensed under the terms of the WTFPL
from magic import Game, Entity, Component, system, query
# Components are pure-data models
PositionC = Component(x=0)
View turingmachine.c
#include <stdio.h>
#include <assert.h>
#include <string.h>
// unfortunately there does not exist a magical computer with unbounded memory for an infinite tape
#define TAPE_SIZE 64
typedef struct {
char symbol; // input symbol
char write; // output symbol
@darkf
darkf / github_contrib_overlap.py
Created Mar 20, 2017
A quick script for seeing the intersection between contributors to different GitHub repositories
View github_contrib_overlap.py
from github import Github
from collections import Counter
import sys
USER = None
PASSWORD = None
def get_repo(repo_name):
contribs = list(g.get_repo(repo_name).get_contributors())
View idk.py
import random
# types are first class
List :: Type
List[Int] :: Type # just List indexed by another type ;)
xs = [1, 2, 3] # inferred type: xs :: List[Int]
for(xs, print)
@darkf
darkf / PrimeEnc.hs
Last active Sep 7, 2016
Baseless number encoder
View PrimeEnc.hs
import Data.Numbers.Primes (primes, primeFactors)
import Data.List (elemIndex)
import Control.Monad (forM_)
data N = P N | Z | Prod [N] deriving (Eq, Show)
primes' = 1 : primes
primeIndex n = let Just idx = elemIndex n primes' in idx
encode :: Int -> N
You can’t perform that action at this time.