Skip to content

Instantly share code, notes, and snippets.

View sbstp's full-sized avatar

Simon Bernier St-Pierre sbstp

View GitHub Profile
@sbstp
sbstp / notation.rs
Created October 28, 2015 03:40
Polish/Reverse polish notation in rust
#![feature(box_syntax)]
use self::Expr::*;
enum Expr {
Val(i32),
Var(char),
Add(Box<Expr>, Box<Expr>),
Sub(Box<Expr>, Box<Expr>),
Mul(Box<Expr>, Box<Expr>),
def session_plugin(callback):
def wrapper(*args, **kwargs):
params = inspect.signature(callback).parameters
if 'session' in params.keys():
kwargs['session'] = request.environ.get('beaker.session')
return callback(*args, **kwargs)
return wrapper
require('lib/test');
// Circular reference detection.
function checkCircularRefs(obj, parents)
{
var val;
parents = parents || [];
for (var key in obj)
{
if (!obj.hasOwnProperty(key)) continue;
@sbstp
sbstp / lxc.md
Last active April 22, 2016 06:15
Linux containers cheat sheet

Linux containers cheat sheet

A straightforward cheat sheet for linux containers (lxc).

Bridge setup

In order for the container to appear as a physical computer on the network, you need to create a bridge network interface on the host computer. Make sure that you have the package bridge-utils (usually comes with lxc).

function format(text, args) {
return text.replace(/\{([\s\S]+?)\}/g, function(match, index) {
var val = args[index];
if (val == null) {
return match;
}
return val;
});
};
#!/bin/bash
# Requires pygments (the python library)
# Installation:
# pip install pygments
# Download the script and make it executable.
# Usage:
# code <filename>
pygmentize -f terminal $1 | less -R
var re = /([^\s"']+)|"([^"]*)"/g;
var match;
var parts = [];
while (match = re.exec(text)) {
parts.push(match[1] || match[2]);
}
console.log(parts);
function split(string) {
var curr
, lastQuoteIndex = 0
, lastSpaceIndex = 0
, parts = []
, isInQuotes = false;
for (var i = 0; i < string.length; i++) {
curr = string[i];
@sbstp
sbstp / bind.js
Last active August 29, 2015 13:57
function bind(fn, context) {
return function () {
return fn.apply(context, arguments);
}
}
function hey() {
console.log(this, arguments);
return 'moist';
}