Skip to content

Instantly share code, notes, and snippets.

@thejohnfreeman
thejohnfreeman / count.cpp
Created March 17, 2012 22:04
Count common elements of sorted C arrays using STL
/* A model of output iterator that will count every time it gets incremented. */
class Counter {
public:
/* Implement a getter if you want. */
int n;
Counter(int n = 0) : n(n) {}
Counter(Counter const& other) : n(other.n) {}
Counter& operator* () { return *this; }
template <typename T>
@thejohnfreeman
thejohnfreeman / gist:2210474
Created March 26, 2012 23:09
Color mangling in Diagramly
1. Create rectangle.
2. Set custom fill color to "4af" (light blue)
3. Create another rectangle.
4. Resize it to be smaller than the first (it will sit in a corner).
5. Set custom fill color on the new rectangle to "f66" (light red)
6. Export as PNG
The generated image will have the two rectangles in the correct dimensions.
The larger rectangle will have a blue that looks darker, more saturated than what I saw in the browser, but that's fine.
@thejohnfreeman
thejohnfreeman / main
Created April 15, 2012 21:41
Mocha vs Node
#!/usr/bin/env mocha
/* Change "mocha" to "node" in the first line, and it works. */
var requirejs = require("requirejs");
var one = requirejs("./one");
console.log(one);
@thejohnfreeman
thejohnfreeman / test.cpp
Last active December 10, 2015 08:29
Generic concatenation
#include <iostream>
#include <sstream>
struct Tester {
static void print(std::ostream& out) {}
template <typename Head, typename... Tail>
static void print(std::ostream& out, const Head& head, const Tail&... tail) {
out << head;
#include <iostream>
function toTitleCase(str) {
return str.replace(/_/g, " ").replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
}
@thejohnfreeman
thejohnfreeman / 0_reuse_code.js
Created July 17, 2014 14:56
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
.pipe(require('through2-spy')({objectMode: true/false}, function(){}))
foo2