Skip to content

Instantly share code, notes, and snippets.

View gdementen's full-sized avatar

Gaëtan de Menten gdementen

  • Federal Planning Bureau
  • Belgium
View GitHub Profile
@gdementen
gdementen / dynamic_factor_range_test.html
Created February 5, 2019 14:33
attempt to create a bokeh categorical plot with dynamic factors
<!DOCTYPE HTML>
<html>
<head>
<title>Sandbox</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
@gdementen
gdementen / frozen.py
Last active March 19, 2023 18:18
qtpy frozen column example
# taken from
# http://blindvic.blogspot.be/2010/12/frozen-column-example-pyqt4-python3.html
# conversion to qtpy, russian comments removal and a few minor improvements done by Gaëtan de Menten
# That blog post was itself inspired from
# http://python.su/forum/viewtopic.php?id=7346
# see also
# http://objexx.com/labs.Efficient-Qt-Frozen-Columns-and-Rows.html
# to make it more efficient for large tables
@gdementen
gdementen / petowner_comprehension1.py
Last active September 16, 2016 19:36 — forked from kentquirk/petowner_comprehension1.py
Set up output first
# 1) like others pointed out, you should use a defaultdict in this case
# 2) otherwise use setdefault
output = {}
for element in elements:
output.setdefault(element["owner"], []).append(element["pet"])
# 3) if, for some reason, this does not work in your case, use a dict comprehension (if available for your version of Python, 2.7+ I think)
output = {e["owner"]: [] for e in elements}
for element in elements:
@gdementen
gdementen / strange_sum.py
Last active July 29, 2016 08:19
Strange sum
>>> l = [4873.40374783,
5821.07686377,
5781.99852348,
5555.53769711,
0.0,
0.0,
0.0,
0.0]
>>> a = np.array(l)
>>> b = np.empty((8, 2))
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@gdementen
gdementen / test.yml
Created February 11, 2015 12:39
Test case for cont_regr
entities:
person:
fields:
- age: int
- gender: bool
- test: {type: float, initialdata: false}
processes:
test: cont_regr(age, mult=0.5, filter=gender)
@gdementen
gdementen / default.patch
Created July 3, 2014 13:42
Alexis Eidelman Default values Patch for LIAM2
diff --git a/src_liam/data.py b/src_liam/data.py
index 31fe79b..44f11b6 100644
--- a/src_liam/data.py
+++ b/src_liam/data.py
@@ -35,7 +35,7 @@ def append_carray_to_table(array, table, numlines=None, buffersize=10 * MB):
class ColumnArray(object):
- def __init__(self, array=None):
+ def __init__(self, array=None, default_values=None):
@gdementen
gdementen / sidewalk.patch
Created July 3, 2014 13:35
Alexis Eidelman Sidewalk Patch for LIAM2
### Eclipse Workspace Patch 1.0
#P liam2
Index: src/alignment.py
===================================================================
--- src/alignment.py (revision 960)
+++ src/alignment.py (working copy)
@@ -2,6 +2,7 @@
from itertools import izip
import os
@gdementen
gdementen / mt.py
Last active May 29, 2021 14:13
Example of multithreading a numba function by releasing the GIL through ctypes
import ast
from timeit import repeat
import threading
from ctypes import pythonapi, c_void_p
import math
import numpy as np
try:
import numexpr as ne
nthreads = ne.ncores
@gdementen
gdementen / crash.py
Last active December 17, 2015 19:29
Crashing Python with numba jit()
import numpy as np
from numba import jit, double, autojit, void
def func(result, a):
for i in range(len(result)):
result[i] = a[i]
func_nb = jit(void[:](double[:], double[:]))(func)
#func_nb = autojit(func)