Skip to content

Instantly share code, notes, and snippets.

@darkf
darkf / dotdict.py
Created October 31, 2014 09:55
JS-style lookups for Python dicts
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
@darkf
darkf / box_collide.js
Created December 26, 2014 10:38
AABB Box Collision Test
// 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;
}
@darkf
darkf / alloc_task.cpp
Created June 5, 2015 05:37
Useless parallel stack allocator in C++
#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) {
@darkf
darkf / BKTree.hs
Last active October 11, 2015 09:58
Simple BK-tree implementation in Haskell
data BKTree a = Node a [(Int, BKTree a)] deriving (Eq, Show)
lev :: Eq a => [a] -> [a] -> Int
lev [] b = length b
lev a [] = length a
lev a b = minimum [ lev (init a) b + 1
, lev a (init b) + 1
, lev (init a) (init b) + (if last a == last b then 0 else 1)
]
@darkf
darkf / bloom.py
Created October 11, 2015 11:51
Simple Python hash table and Bloom filter
def sillyhash(x):
return x % 16
class BloomFilter:
SIZE = 32
HASH_FNS = [hash, sillyhash]
def __init__(self):
self.n = BloomFilter.SIZE
self.bitset = [0]*self.n
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveGeneric #-}
import Data.List
import Data.Ord (comparing)
import Control.Applicative ((<|>))
import Criterion.Main
import GHC.Generics (Generic)
import Control.DeepSeq
interface Point2D {
x: number;
y: number;
}
interface Point3D extends Point2D {
z: number;
}
function f(pt: Point2D) {}
type Weight = Float
type Threshold = Float
perceptron :: [Weight] -> Threshold -> [Float] -> Bool
perceptron ws t xs = sum (zipWith (*) ws xs) >= t
-- OR gate
or_p = perceptron [1, 1] 1
-- AND gate
type Weight = Float
type Bias = Float
-- type Neuron = Bias -> [Weight] -> [Float] -> Float
-- Artificial neuron, given some activation function f.
-- A neuron is simply a function from a vector of weights, and a vector of values, to an activation value.
neuron :: (Float -> Float) -> Bias -> [Weight] -> [Float] -> Float
--neuron :: (Float -> Float) -> Neuron
neuron f b ws xs = f (sum (zipWith (*) ws xs) + b)

A Free Browser For All

Today's Web is in a state of disarray. We are constantly being bombarded by advertisements (possibly malicious!), trackers, malware scripts, and bloated JavaScript-heavy websites which put too much effort into being complicated.

We want a browser liberated from these plagues: a browser that is built from the ground up for privacy, liberty and security. We want a browser that does not bow down to the status quo and accept "You shalt be tracked."

A browser that does not exist for spending 1% of your battery life on fetching, parsing, compiling and running JavaScript just to display the basic layout of a page.

We want a liberated browser, for humans to use in order to safely and efficiently communicate with the wasteland that the Web is today.