Skip to content

Instantly share code, notes, and snippets.

const List = require('./list');
const l = new List(50);
// setup
for (let i = 0; i < 50; i++) {
l.set(i, i);
}
console.log(l.get(5) === 5);
@oakfang
oakfang / pr.sh
Created August 9, 2016 08:12
Command line PRs with github templates
# Make sure to export EDITOR in your .bashrc as either vim or nano.
# Make sure to install vipe (npm i -g juliangruber/vipe)
# Make sure to install hub (brew install hub)
# Don't forget to add your PR title as the first block
alias pr="cat .github/PULL_REQUEST_TEMPLATE.md | vipe | hub pull-request -b develop -F -"
@oakfang
oakfang / gn.sh
Created June 13, 2016 14:39
One command to rule them all.
# Source this from your .bashrc/.zshrc
GIT_CORE="$(git --exec-path)"
gn() {
command=$1
shift
if [ -f "${GIT_CORE}/git-${command}" ]; then
git "$command" "$@"
else
@oakfang
oakfang / tact.py
Last active May 4, 2016 12:11
Using python 3.5 typing module and some magic to enforce actual and semantic types
import typing
import functools
from abc import ABCMeta
from inspect import signature, getcallargs
class InterfaceMeta(ABCMeta):
def __new__(cls, name, bases, namespace, **kwargs):
if bases:
namespace['__specs__'] = {name: signature(namespace[name]) for name in namespace if name not in ('__qualname__', '__module__')}
@oakfang
oakfang / util.py
Created May 4, 2016 07:09
Add an unbound method to a class (Python 2)
from types import MethodType
LAMBDA_NAME = '<lambda>'
def extend(cls, method, name=None):
method_name = method.__name__
if method_name == LAMBDA_NAME and name is None:
raise NameError('Please provide a usable name for a lambda method')
elif name is not None:
method_name = name
@oakfang
oakfang / xain-el.js
Last active May 1, 2016 13:08
Use Xain for elements
'use strict';
const {reactive, link, pipe, observable, observe} = require('xain');
function Xain(state) {
class _Xain {
constructor(props={}) {
const reaction = this.constructor.reaction || (() => ({}));
this.props = reactive(Object.assign({}, reaction(state), props));
observe(this.props, this.__renderToScreen.bind(this));
@oakfang
oakfang / main.py
Last active April 3, 2016 07:13
quest main server
from journey import System, import_all_hooks
from journey.sources import tcp_server_source
import_all_hooks()
sys = System(tcp_server_source('', 3030))
data = sys.run()
print(data['statistics'])
@oakfang
oakfang / hashtags.js
Created March 16, 2016 14:20
Extract unicode hashtags from text
'use strict';
const twitter = require('twitter-text');
function extractTags(text) {
const tags = twitter.extractHashtagsWithIndices(text);
let buffer = '';
let i = 0;
for (let t of tags) {
buffer += text.substring(i, t.indices[0]);
@oakfang
oakfang / test.py
Last active March 14, 2016 14:35
Using facade.dll to run rust code via python
from facade import dll
import utils
print utils.multi_sum(3)
@oakfang
oakfang / rux.js
Created March 6, 2016 06:36
Exrtact s State Stream from a redux store
import { BehaviourSubject } from 'rx';
export function getStateStream(store) {
const sub = new BehaviourSubject(store.getState());
store.subscribe(state => sub.toNext(sub));
return sub.asObservable();
}