Skip to content

Instantly share code, notes, and snippets.

View jvkersch's full-sized avatar

Joris Vankerschaver jvkersch

View GitHub Profile
# -*- coding: utf-8 -*-
from __future__ import division, print_function
from traits.etsconfig.api import ETSConfig
ETSConfig.toolkit = 'qt4'
from traits.api import HasTraits, Instance, String
from traitsui.api import Action, Controller, Handler, Item, View
import sys, traits, traitsui
print ('python version :',sys.version) # 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)]
#!/usr/bin/env python
"""Horrible hacked-together script to reformat import statements along
something that vaguely resembles our coding standard. To be called from
within Emacs via
(defun jvk/python-reformat-import ()
(interactive)
(save-excursion
(let ((pmin (py-statement-point-begin))
(pmax (py-statement-point-end)))
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{CJKutf8}
\usepackage[english]{babel}
\usepackage{hyperref}
\title{Korean Class \\
26 November 2016 \\
{\small \url{%
# Mangled version of Chaco's lasso demo that has a LassoSelection that
# constrains the selection to be parallel to the coordinate axes.
import sys
# Major library imports
from numpy import sort, compress, arange
from numpy.random import random
import numpy as np
@jvkersch
jvkersch / little_schemer.el
Created September 20, 2016 12:07
The code from "The Little Schemer", translated to Emacs Lisp
;;; -*- lexical-binding: t -*-
(defun atom? (x) (not (listp x)))
(atom? 'abc)
(atom? 1)
(atom? '(a b c))
(defun member (a lat)
(cond ((null lat) nil)
from numpy import empty
def mandelbrot_escape(x, y, n):
""" Mandelbrot set escape time algorithm in real and complex components
"""
z_x = x
z_y = y
for i in range(n):
z_x, z_y = z_x**2 - z_y**2 + x, 2*z_x*z_y + y
""" Self-contained code example to listen for postgres events.
This is the Python 3 counterpart of
http://bjorngylling.com/2011-04-13/postgres-listen-notify-with-node-js.html
Preconditions: create a database and a trigger with
CREATE TABLE foo (id serial primary key, name varchar);
@jvkersch
jvkersch / update-emacs-ppa.sh
Created February 20, 2016 21:26 — forked from DamienCassou/update-emacs-ppa.sh
Emacs-snapshot and emacs24 build script for Ubuntu PPA
#! /usr/bin/env bash
# Author: Damien Cassou
#
# This is the script I use to build Emacs packages for Ubuntu. These
# packages are uploaded to
# https://launchpad.net/~cassou/+archive/emacs/. Each package is
# either build from a Debian package or from
# http://emacs.naquadah.org/.
#!/usr/bin/env python
# -*- coding: utf-8
""" A script to check whether shows listed on SBS have Korean subtitles.
"""
import argparse
import logging
import re
@jvkersch
jvkersch / mem_usage.py
Created October 21, 2015 17:30
Aggregate memory usage of a process and its children.
"""Aggregate memory usage of a process and its children.
This utility measures the resident set size of a process and its children, and
returns the result either in bytes or formatted in a more convenient
format. Note: this "total resident size" is often an inflated measure of how
much memory a process group uses, as it will double-count e.g. memory used by
dynamic libraries and shared memory. It serves well as (a) a conservative
estimate, and (b) when sampled over time, to estimate changes in memory usage.
Requires psutil.