Skip to content

Instantly share code, notes, and snippets.

View valsteen's full-sized avatar

Vincent Alsteen valsteen

View GitHub Profile
@valsteen
valsteen / gist:d3669888ed5c37b7ccf9
Created December 24, 2014 12:39
django-autocomplete-light==2.0.3 + jquery.formset.js 1.3-pre
<script src="{% static 'js/jquery.formset.js' %}"></script>
<script>
$(function () {
$('#myformset tbody tr').formset({
'added': function (row) {
var widget = $(".autocomplete-light-widget", row);
widget.yourlabsWidget('destroy');
widget.find('input').yourlabsAutocomplete('destroy');
widget.trigger('initialize');
}
@valsteen
valsteen / gist:29a22d6e7cd57360b174
Last active September 20, 2015 16:23
how to keep python interpreter busy in ableton
def pause(self):
# helper for rconsole. This blocks ableton inside python on purpose, otherwise the console thread
# is super slow ( python interpreter is only active when needed )
def lock():
if self.console_event.isSet():
return
# this trick works with Event and not with just time.sleep, because in python2 Event.wait is a loop+sleep, which keeps the interpreter busy
self.console_event.wait(0.1)
self.schedule_message(3, lock)
@valsteen
valsteen / controlsurface.py
Created September 20, 2015 16:34
MIDI to sysex
def reply_sysex(self, message):
from array import array
try:
raw = array('B')
raw.fromstring(message.encode('utf-16-le'))
raw = raw.tolist()
raw.insert(0, 240)
raw.append(247)
self._send_midi(tuple(raw), False)
@valsteen
valsteen / backlog.xsl
Created September 4, 2012 07:35
XSL to transform jira stories ( issue navigator -> view as XML ) as printable slides
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>
<!--
note : customfield_10002 may change depending on your jira setup. Inspect your xml output to insert the replace with the relevant field ID.
-->
<xsl:output method="html"/>
<xsl:template match="/">
<style>
@valsteen
valsteen / django-crossdomainxhr-middleware.py
Last active December 15, 2015 11:59 — forked from vicalejuri/django-crossdomainxhr-middleware.py
Add Access-Control-Allow-Headers support
import re
from django.utils.text import compress_string
from django.utils.cache import patch_vary_headers
from django import http
try:
import settings
XS_SHARING_ALLOWED_ORIGINS = settings.XS_SHARING_ALLOWED_ORIGINS
@valsteen
valsteen / adventofcode23.py
Created December 23, 2015 15:58
Python solution for Advent of Code day 23 http://adventofcode.com/day/23
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import re
from collections import defaultdict
from functools import partial
i = """jio a, +18
inc a
tpl a
@valsteen
valsteen / myclass.py
Last active December 31, 2015 09:09
Demonstration of private variables, one using name mangling of attributes prepended by a double underscore, and using a closure like in javascript
def myclass_factory():
"""
Run this test with nosetests --with-doctest myclass.py
>>> myclass = myclass_factory()
>>> myclass.__private_attribute
Traceback (most recent call last):
...
AttributeError: 'MyClass' object has no attribute '__private_attribute'
@valsteen
valsteen / reorder.py
Created April 22, 2016 12:24
stupid utility that receives timestamped lines in any order and various formats, then outputs them reordered
import dateutil.parser
import re
import sys
import pytz
tz = pytz.timezone("Europe/Vienna")
res = []
for line in sys.stdin:
@valsteen
valsteen / Main.java
Last active November 9, 2020 11:36
java enterprise ternary operator
package com.company;
/**
java -cp . com.company.Main "4" "3" "2"
4 is even
3 is not even
2 is even
*/
@valsteen
valsteen / adventofcode2020_day23_part_2.rs
Created February 28, 2021 19:43
Advent of code 2020 day 23 part 2
/*
solution to the second part of https://adventofcode.com/2020/day/23
it executes in less than a minute in release mode, but it ain't pretty
main points:
- double linked list to easily insert/split/remove
- the nodes are not individual values, but ranges instead
- because looking up a value in a linked list takes so long, there is a hashmap pointing to the
slices for each value. everytime a slice is added or changed, all the values of the slice