Skip to content

Instantly share code, notes, and snippets.

View ignacysokolowski's full-sized avatar

Ignacy Sokolowski ignacysokolowski

  • Berlin, Germany
  • 03:25 (UTC +02:00)
  • X @ignacy
View GitHub Profile
@konradhalas
konradhalas / namedtuple_example.py
Last active March 15, 2017 18:02
This is a short example of a new "typed" named tuple syntax (Python 3.6). It's a very clean and easy way to define data classes with a type hinting and inheritance support.
from typing import NamedTuple # >= Python.3.6.0
class Employee(NamedTuple):
name: str
department: str
salary: int
is_remote: bool = False # >= Python.3.6.1
bob = Employee(name='Bob', department='IT', salary=10000, is_remote=True)
@slevithan
slevithan / xregexp-lookbehind2.js
Created April 14, 2012 21:06
Simulating lookbehind in JavaScript (take 2)
// Simulating infinite-length leading lookbehind in JavaScript. Uses XRegExp.
// Captures within lookbehind are not included in match results. Lazy
// repetition in lookbehind may lead to unexpected results.
(function (XRegExp) {
function prepareLb(lb) {
// Allow mode modifier before lookbehind
var parts = /^((?:\(\?[\w$]+\))?)\(\?<([=!])([\s\S]*)\)$/.exec(lb);
return {
@dbr
dbr / musicalTorrents.py
Created October 5, 2009 23:29
Encode file as MIDI
#!/usr/bin/env python2.6
# Converts an arbitrary file to MIDI. Obviously.
# Note the output files can be.. long (a 25KiB file becomes about 10 hours),
# and may cause players to lockup while opening (the aforementioned 10 hour
# file took Quicktime Player 7 about 5-10 seconds to open)
import smidi
def fileToMidi(input_fname, output_fname):