Skip to content

Instantly share code, notes, and snippets.

View polaris's full-sized avatar

Jan Deinhard polaris

  • Berlin
View GitHub Profile
@polaris
polaris / heap.cpp
Created November 20, 2017 18:15
A heap implementation in C++
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
template <typename T>
void swap(T& vec, std::size_t a, std::size_t b);
constexpr std::size_t firstChild(std::size_t i);
@polaris
polaris / parity.cpp
Last active October 10, 2017 17:20
Compute the parity of a word
short parity(unsigned long x) {
short result = 0;
while (x) {
result ^= 1
x &= (x - 1);
}
return result;
}
@polaris
polaris / timePointAsString.cpp
Created June 20, 2016 11:53
Convert a std::chrono::system_clock::time_point to std::string
static std::string timePointAsString(const std::chrono::system_clock::time_point& tp) {
std::time_t t = std::chrono::system_clock::to_time_t(tp);
std::string ts = std::ctime(&t);
ts.resize(ts.size()-1);
return ts;
}

Erlang Application Loading

directory layout

./hello_app.erl
./ebin
  ./hello.app

code

@polaris
polaris / gist:2593239
Created May 4, 2012 08:19
SC Observer
UJAM.Node = SC.Object.extend({
parentNode: null,
childNodes: [],
childsDidChange: function () {
alert('child nodes changed');
}.observes('childNodes'),
addChild: function (node) {
this.childNodes.push(node);
@polaris
polaris / build log
Created January 14, 2012 20:02
Problems loading node files with node v0.7.0-pre
$ node-waf clean configure build
'clean' finished successfully (0.014s)
Setting srcdir to : /Users/jan/Projects/node.js/nodekeeper2
Setting blddir to : /Users/jan/Projects/node.js/nodekeeper2/build
Checking for program g++ or c++ : /usr/bin/g++
Checking for program cpp : /usr/bin/cpp
Checking for program ar : /usr/bin/ar
Checking for program ranlib : /usr/bin/ranlib
Checking for g++ : ok
Checking for node path : ok /Users/jan/.node_libraries
@polaris
polaris / gist:1582778
Created January 9, 2012 12:42
Client
var ctx = new webkitAudioContext();
var startTime = 0;
function playSound(buffer) {
var src = ctx.createBufferSource();
src.buffer = buffer;
src.looping = false;
src.connect(ctx.destination);
src.noteOn(startTime);
@polaris
polaris / NodeKeeper problem
Created February 8, 2011 19:12
nodekeeper.cc
#include <v8.h>
#include <node.h>
#include <node_events.h>
#include <c-client-src/zookeeper.h>
#include <iostream>
using namespace node;
using namespace v8;
@polaris
polaris / helloworld.cc
Created February 3, 2011 20:41
node.js extension causing a segmentation fault
#include <v8.h>
#include <node.h>
#include <node_events.h>
#include <boost/thread.hpp>
#include <boost/bind.hpp>
#include <iostream>
using namespace node;
using namespace v8;