Skip to content

Instantly share code, notes, and snippets.

View jvkersch's full-sized avatar

Joris Vankerschaver jvkersch

View GitHub Profile
# Conway's famed FRACTRAN program to compute prime numbers.
# See https://en.wikipedia.org/wiki/FRACTRAN
def apply(num, prog):
while True:
for f, d in prog:
if num*f % d == 0:
yield (num := num*f // d)
break
else:
""" Mixing threads and processes (fork) is a bad idea.
When a process forks, only the thread that was running at the time of the
fork is copied to the child process. That means that if a lock was acquired
by a background thread in the main process, that lock will appear as locked
in the child process, with no way to unlock it.
"""
import os
;; Derivation of the Y combinator following Jim Weirich's approach.
(define fact-improver
(lambda (partial)
(lambda (n) (if (= n 0) 1 (* n (partial (- n 1)))))))
(define err
(lambda () (error "Should not be called")))
(define fx-naive
@jvkersch
jvkersch / over_underlay.py
Last active February 24, 2019 07:19
Different behaviors in overlay vs underlay when it comes to updating. Create a 1D selection by right-dragging on the plot, and try dragging the selection back and forth. This works as expected when the selection is drawn using an overlay, but not when it is drawn as an underlay.
import numpy as np
from chaco.api import ArrayPlotData, Plot, VPlotContainer
from chaco.tools.api import RangeSelection, RangeSelectionOverlay
from enable.api import Component, ComponentEditor
from traits.api import Enum, HasTraits, Instance
from traitsui.api import UItem, View
class A(HasTraits):
@jvkersch
jvkersch / v1.2.10.patch
Last active January 16, 2019 14:53
Version 1.2.10 of Velvet: diff between the tarball downloaded from EBI and the version on GitHub
diff --git a/Makefile b/Makefile
index 3e47adc..a4b46e2 100644
--- a/Makefile
+++ b/Makefile
@@ -3,8 +3,8 @@ CFLAGS = -Wall
DEBUG = -g
LIBS = -lm
OPT = -O3
-MAXKMERLENGTH=31
-CATEGORIES=2
### Keybase proof
I hereby claim:
* I am jvkersch on github.
* I am jvkersch (https://keybase.io/jvkersch) on keybase.
* I have a public key whose fingerprint is 781F C24B 38CF A1DE 8033 74D9 41FC 9BEB 1315 D073
To claim this, I am signing this object:
Adapted from https://github.com/JuliaLang/PackageCompiler.jl/issues/144.
Compile the C code with
gcc runjl.c -o runjl -Wall -std=gnu99 -I'/Applications/Julia-1.0.app/Contents/Resources/julia/include/julia' -DJULIA_ENABLE_THREADING=1 -fPIC -L'/Applications/Julia-1.0.app/Contents/Resources/julia/lib' -Wl,-rpath,'/Applications/Julia-1.0.app/Contents/Resources/julia/lib' -Wl,-rpath,'/Applications/Julia-1.0.app/Contents/Resources/julia/lib/julia' -ljulia
Use PackageCompiler.jl to produce a shared library from the Julia file.
@jvkersch
jvkersch / traceback_info.c
Last active April 5, 2018 16:42
Parasail traceback info (start of query/sequence, no. of mismatches/indels)
/* Find begin of query/sequence, together with number of mismatches/indels
* for parasail SG trace-enabled alignment.
*
* Note: defines (T, STRIPED) must match the kind of alignment used.
*
* Compile with gcc -Wall traceback_info.c -o traceback_info -lparasail
*/
#include <assert.h>
#include <stdio.h>
@jvkersch
jvkersch / scheme.py
Created December 12, 2017 18:11
scheme interpreter
#!/usr/bin/env python3
# TODO
# 2. support block structure
from collections import deque, namedtuple
import contextlib
from functools import reduce
import operator
import re
@jvkersch
jvkersch / Titanic-MWE.ipynb
Last active November 28, 2017 09:26
Seaborn plot indeterminacy minimal working example (Titanic dataset)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.