Skip to content

Instantly share code, notes, and snippets.

@drslump
drslump / incremental.js
Last active August 29, 2015 14:02
incremental parsing proof of concept for metascript
/*
Incremental parser wrapper for the compiler service.
Designed to be used for integration on text editors, to keep an up to date
representation of the source code in its textual and AST forms.
// create compiler for some source code
compiler = Meta.compilerFromString(code)
// wrap the compiler with the incremental parser
parser = new IncrementalParser(compiler)
{
// private field init
var a = 1;
// Private functions
function func2() {
};
// public field init
$scope.b = 1; // For controllers
function fish_right_prompt --description 'Right prompt section'
set -l last_status $status
set -l prompt
# pyenv
set -l pyenv "$PYENV_VERSION"
if not test -n "$pyenv"
set pyenv "$PYENV_LOCAL_VERSION"
end
@drslump
drslump / memoize_benchmark.py
Last active August 29, 2015 13:56
Benchmarking the use of memoize for regular expression transformations
#!/usr/bin/env python
def memoize(fn):
""" Memoization decorator for a function taking one or more arguments.
NOTE: Only hashable values can be given as arguments to the function.
http://code.activestate.com/recipes/578231-probably-the-fastest-memoization-decorator-in-the-/#c4
"""
class memodict(dict):
def __getitem__(self, *args):
@drslump
drslump / djb2.boo
Created February 18, 2014 07:34
djb2 hash implementation
def djb2(data as string):
""" Computes a 32bit hash using the djb2 algorithm """
payload = System.Text.Encoding.ASCII.GetBytes(data)
result as uint = 5381
for ch in payload:
unchecked:
result = result * 33 + ch
return result & 0xffffffff
@drslump
drslump / RectanglePacking.php
Created December 25, 2013 22:53
rectangle packing in PHP for Metin Gür
<?php
class RectanglePacking {
private $root = array();
private $usedHeight = 0;
private $usedWidth = 0;
function __construct($width, $height) {
@drslump
drslump / Protocol.boo
Created November 20, 2013 20:52
proof of concept for a Nailgun server in .Net
"""
Protocol should be compatible with Nailgun (http://www.martiansoftware.com/nailgun/protocol.html)
"""
namespace boodaemon
from System import UInt32
from System.IO import BinaryReader, BinaryWriter
from System.Net.IPAddress import NetworkToHostOrder, HostToNetworkOrder
from System.Text import ASCIIEncoding
@drslump
drslump / cfg-parser.py
Last active December 28, 2015 17:29
Simple hand coded parser for alarms config
class CfgParser:
def __init__(self, src):
self.src = src
self.idx = 0
def rowcol(self, ofs=None):
ofs = self.idx if ofs is None else ofs
lines = self.src.split('\n')
accum = 0
import Boo.Lang.Compiler.Ast
def Method1(x, y):
print 'Method1', x, y
def Method2(x, y, z):
print 'Method2', x, y, z
macro BindArg(expr as Expression):
for fn in ('Method1', 'Method2'):
@drslump
drslump / pyenv-mktmp
Created October 29, 2013 17:33
Place this file in your path and give it executable permissions
#!/bin/sh
pyenv virtualenv "$1"
echo "Entering a new shell session with version '$1'"
echo "Press ctrl+d or exit to terminate it"
export PYENV_VERSION="$1"
$SHELL