Skip to content

Instantly share code, notes, and snippets.

View almarklein's full-sized avatar

Almar Klein almarklein

View GitHub Profile
@almarklein
almarklein / bb64.js
Created January 12, 2018 22:38
Efficient JavaScript implementation of Base64 encoding/decoding of bytes (Uint8Array)
"use strict";
function base64encode(b, last_two) {
"use strict";
console.assert(b.BYTES_PER_ELEMENT == 1);
// Most Base64 encoders use +/ for the last two characters, but not all
if (last_two === undefined) last_two = '+/';
// Init charcodes array
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" + last_two;
var charcodes = new Uint8Array(64);
## Option 1 - strings for verbatim html, dicts for elements with attributes
class MyReactlikeWidget(ReactLike):
name = event.StringProp('john', settable=True)
def render(self):
return ['greet: ',
dict(type='b',
onclick=lambda:print('clicked!'),
innerHTML='hi ' + self.name),
@almarklein
almarklein / messagepool.py
Created January 25, 2016 21:53
Multi-process communication via a message pool implemented using UDP multicast
# Copyright 2016 (C) Almar Klein. Consider this 2-clause BSD licensed.
"""
I initially wrote this to be included in flexx for multiple processes
on the same machine to communicate, more specifically, to allow a Flexx
CLI to get info on and terminate running server processes. I tested it
to work on Windows and Linux. I eventuially discarded this approach
because I don't fully get how UDP multicast works. It's important for
this to only work for localhost, and I am not sure if it does, or how
hard it is to compromise this. I went with a simpler approach based on
http requests using Tornado.
D:\dev>conda build pyapps\conda-recipes\freeimage
Removing old build environment
Removing old work directory
BUILD START: freeimage-3.17.0-vc10_1
Fetching package metadata: ........
Solving package specifications: ...........
The following NEW packages will be INSTALLED:
msvc_runtime: 1.0.1-vc10_0 [vc10]
pip: 7.1.2-py34_0
@almarklein
almarklein / bokeh_line_pick.py
Last active November 24, 2015 16:01
How to pick a line among multiple lines in Bokeh
import numpy as np
from bokeh.plotting import output_notebook, show, figure
from bokeh.models import Plot, CustomJS, TapTool, ColumnDataSource, Line, DataRange1d
output_notebook()
p = figure()
t = np.linspace(0, 5, 100)
l1 = p.line(t, np.sin(t), color='#ff0000', nonselection_color='#888', line_width=5)
l2 = p.line(t, np.sin(t+1), color='#00ff00', nonselection_color='#888', line_width=5)
#l3 = p.line(t, np.sin(t+2), color='#0000ff', nonselection_color='#888', line_width=5)
c:\Anaconda34>Scripts\conda-build c:\almar\devel\conda-recipes\freeimage
Removing old build environment
Removing old work directory
BUILD START: freeimage-3.17.0-vc10_1
Fetching package metadata: ......
Solving package specifications: .........
The following NEW packages will be INSTALLED:
pip: 7.1.2-py34_0
python: 3.4.3-0
@almarklein
almarklein / vispy_pres.py
Created August 28, 2014 14:24
Vispy pres minimal
import itertools
import os
import hashlib
import numpy as np
import vispy
from vispy import app
from vispy import scene
from vispy import gloo
@almarklein
almarklein / _angle.py
Last active August 29, 2015 14:05
angle backend that I wrote about half a year ago and is tight to Qt
# -*- coding: utf-8 -*-
# Copyright (c) 2014, Vispy Development Team.
# Distributed under the (new) BSD License. See LICENSE.txt for more info.
"""
vispy backend for Qt (PySide and PyQt4).
"""
from __future__ import division
@almarklein
almarklein / test_warmup.py
Last active August 29, 2015 13:59
Testing warmup issue for vispy
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright (c) 2014, Vispy Development Team. All Rights Reserved.
# Distributed under the (new) BSD License. See LICENSE.txt for more info.
# -----------------------------------------------------------------------------
from __future__ import print_function
import sys
import ctypes
class Image(np.ndarray):
def __new__(cls, array):
return array.view(cls)
def __repr__(self):
n = 'x'.join([str(i) for i in self.shape])
dtype = self.dtype
ndim = self.ndim
if self.shape[-1] in (1,3,4):