Skip to content

Instantly share code, notes, and snippets.

class Portfolio extends Composite {
public function __construct() {
parent::__construct();
$this->addChild(
new Template("../views/head.html"),
new Menu(
new Template("../views/menu.html")
),
<div class="block">
<div class="inner">
<h2>Files found:</h2>
<table>
<tr>
<th>Last modified</th>
<th>File name</th>
</tr>
[iterator getFiles]
@Gerjo
Gerjo / Bernstein
Created August 19, 2013 17:23
Bernstein basis polynomial
///
///
///
///
float BernsteinBasis(const int d, const int n, float x) {
// Binomial coefficient:
const int b = Factorial(d) / (Factorial(d - n) * Factorial(n));
// Bernstein polynomial:
@Gerjo
Gerjo / Line intersection
Created August 14, 2013 15:17
Line intersection
Line.prototype.intersection = function(other) {
// Quick hack to make this work. I've taken this code from my C++ project.
var p1 = this.a;
var d1 = this.b;
var p2 = other.a;
var d2 = other.b;
console.log("--- starting intersection --");
//function solve(p1, d1, p2, d2) {
@Gerjo
Gerjo / Variadic template multiton
Last active December 20, 2015 03:19
Variadic template multiton
template <class T, typename...PARAMS>
T* Load(const std::string& ident, PARAMS...args) {
// Create a hash from the first parameter:
long hash = StringHash(ident);
auto it = resources.find(hash);
if (it != resources.end())
{
@Gerjo
Gerjo / CCL broken
Created July 17, 2013 20:46
Connected Component Labeling - the slow and broken version.
void ConnectedComponentLabeling() {
std::vector<Color> colors;
colors.push_back(Color::Red);
colors.push_back(Color::Blue);
colors.push_back(Color::Purple);
colors.push_back(Color::Yellow);
colors.push_back(Color::Green);
colors.push_back(Color::Grey);
colors.push_back(Color::Cyan);
@Gerjo
Gerjo / bezier
Created July 17, 2013 11:06
Bézier interpolation
/// Calculate a point on a bézier curve. Works for any number of control
/// points.
///
/// TODO: contemplate a generic version that does not require std::vector.
/// perhaps iterators or clever template usage? Resort to C style arrays?
///
///
/// @param points A collection indicating the control points.
/// @param delta Interval at which to calculate the point, ranges from 0 to 1.
/// @return a point on a bézier curve.
function blaat(var upperbound) {
var result = 0;
for(var i = 0; i < upperbound; ++i) {
for(var j = i; j < upperbound; ++j) {
++result;
}
}
return result;
}
@Gerjo
Gerjo / 12lineweb
Created January 24, 2013 17:06
Small threaded webserver, should work most of the time, probably.
#include <cstdlib>
#include <thread>
#include <iostream>
#include <cstring>
#include <unistd.h>
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <sys/socket.h>
#include <arpa/inet.h>
@Gerjo
Gerjo / merc history.php
Created November 20, 2012 18:32
Mercurial stats script.
#!/usr/bin/php
<?php
if(!isset($argv[1])) {
print "Usage: $argv[0] path" . PHP_EOL;
exit;
}
date_default_timezone_set("UTC");