Skip to content

Instantly share code, notes, and snippets.

@ofx
ofx / rbf.py
Last active November 18, 2019 15:20
#!/usr/bin/python
import math
import numpy as np
from numpy import linalg as LA
# Function to approximate
def f(x):
@ofx
ofx / bitfield.cpp
Last active November 15, 2018 12:06
#include <array>
#include <assert.h>
#include <bitset>
#include <iostream>
#include <limits.h>
#include <ostream>
template <size_t N> class bitfield : public std::bitset<N> {
public:
bitfield(std::array<unsigned char, N / CHAR_BIT> bytes)
@ofx
ofx / alu16.cpp
Last active November 10, 2018 17:07
16-bits ALU
#include <assert.h>
#include <bitset>
#include <iostream>
#include <limits>
#include <random>
#define ALU_ADD 0
#define ALU_SUB 1
#define ALU_AND 2
#define ALU_OR 3
def convert(x, N):
y = x % N
x = x // N
if (x == 0):
return [y]
else:
return convert(x, N) + [y]
print(convert(10001, 16))
@ofx
ofx / threadpool.c
Created August 18, 2018 11:47
Old threadpool implementation (pthread)
//
// threadpool.c
// threadpool
//
#include "threadpool.h"
static void *sweep(void *voidtask)
{
task *task = voidtask;
import sys
# Constants
OPERATORS = ['*', '/', '+', '-']
DECIMAL_SYMBOLS = [',', '.']
SIGN_SYMBOLS = ['-', '+']
PARENTHESIS_OPEN = '('
PARENTHESIS_CLOSE = ')'
PRECEDENCE = [[PARENTHESIS_OPEN], ['*', '/'], ['+', '-']]
@ofx
ofx / collatz.cpp
Last active March 29, 2018 12:58
Collatz Conjecture
#include <iostream>
#include <ctime>
#include <tuple>
constexpr const std::tuple<unsigned long, unsigned long> max(const unsigned int a, const unsigned int b)
{
const auto c = [](auto&& s, const unsigned long n) constexpr -> const unsigned int {
if (n == 1) return 1;
return 1 + s(s, n % 2 ? n * 3 + 1 : n / 2);
};
#!/bin/bash
if [ "$1" != "" ]; then
git submodule deinit -f -- $1
rm -rf .git/modules/$1
git rm -f $1
fi
float k1 = 0.0;
float k2 = 0.0;
float k3 = 0.0;
float p1 = 0.0;
float p2 = 0.0;
const int lk = 12;
void mainImage( out vec4 fragColor, in vec2 fragCoord )
@ofx
ofx / gist:f3b28f5765b5a7d8edc3
Created March 17, 2015 12:23
Build a kd-tree for 2d points, with two consecutive x-levels and one y-level.
#!/usr/bin/python
import sys
import numpy
import Queue
import numpy as np
import random
import matplotlib.pyplot as plt