Skip to content

Instantly share code, notes, and snippets.

Avatar

Chris Howie cdhowie

View GitHub Profile
View optional.hpp
#ifndef OPTIONAL_HPP
#define OPTIONAL_HPP
#include <utility>
namespace gamesolver {
template <typename T>
class optional {
public:
@cdhowie
cdhowie / promise-node-shim.js
Created Apr 13, 2017
Simple shim for promise-nodecb interop without requiring a full-blown promise library. (Useful as a boilerplate for AWS Lambda functions.)
View promise-node-shim.js
Promise.fromCallback = fn =>
new Promise((r, j) => {
fn((err, result) => err ? j(err) : r(result));
});
Promise.prototype.nodeify = function (cb) {
cb && this.then(r => cb(null, r), cb);
return cb ? undefined : this;
};
@cdhowie
cdhowie / README.md
Last active Oct 16, 2016
ES5-compatible defer shim
View README.md

ES5-compatible polyfill for Promise.defer() that will work regardless of whether the Promise constructor invokes the passed function synchronously or asynchronously.

@cdhowie
cdhowie / README.md
Last active Oct 1, 2016
Simple implementation of a promise queue that allows only some number of concurrent tasks to execute at once
View README.md

promise-queue.js

Simple implementation of a Promises/A+ queue module.

Exports a single function that creates a new queue, and can be passed a configuration object with the following keys:

  • concurrency: The maximum number of concurrently-executing functions. (Default: 1)
  • Promise: Promise constructor. (Default: global.Promise)

The return value is the enqueue function, which accepts a single function as its argument. It will return a promise for the result of that function. The function is considered executing until this promise resolves; that is, if the function returns a promise, it will still be considered executing until that promise is settled.

View node-exception.log
> mocha --bail --slow 125 --timeout 10000 --check-leaks api-server/tests/index.js
NET 6043: listen2 null 4567 4 false undefined
NET 6043: _listen2: create a handle
NET 6043: bind to ::
NET 6043: listen2 127.0.0.1 4568 4 false undefined
NET 6043: _listen2: create a handle
NET 6043: bind to 127.0.0.1
@cdhowie
cdhowie / README.md
Last active Jul 17, 2019
DNS proxy to fix Netflix stupidity
View count-distinct-lines.py
#!/bin/env python
import fileinput
counts = {}
for line in fileinput.input():
chomped = line.rstrip('\r\n')
counts[chomped] = counts.get(chomped, 0) + 1
View sandbox.lua
do
-- Don't allow error() to be replaced out from underneath the security checks!
local real_error = error
do
local real_collectgarbage = collectgarbage
collectgarbage = function(oper)
if oper == 'collect' or oper == 'count' then
return real_collectgarbage(oper)
@cdhowie
cdhowie / lua-printproxy.cs
Created Nov 15, 2013
Proxying print() calls in Lua to C# (using Eluant)
View lua-printproxy.cs
using System;
using System.Text;
using Eluant;
class Example {
static void Main() {
using (var runtime = new LuaRuntime()) {
using (var proxy = runtime.CreateFunctionFromDelegate(new Action<LuaTable>(PrintProxy))) {
runtime.Globals["printproxy"] = proxy;
}
@cdhowie
cdhowie / Gate.cs
Last active Dec 16, 2015
Gate class
View Gate.cs
/*
The MIT License (MIT)
Copyright (c) 2013 Chris Howie <me@chrishowie.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
You can’t perform that action at this time.