Skip to content

Instantly share code, notes, and snippets.

@saghul
saghul / zmq_websocket_gateway.py
Created June 28, 2011 18:49
A ZeroMQ - WebSocket gateway
# coding=utf8
# Copyright (C) 2011 Saúl Ibarra Corretgé <[email protected]>
#
import hashlib
import os
import re
import socket
import struct
@bayerj
bayerj / quaternions.py
Created July 17, 2013 07:15
Some quaternion code for numpy/Theano.
def q_mult(q1, q2):
w1, x1, y1, z1 = q1[:, 0], q1[:, 1], q1[:, 2], q1[:, 3]
w2, x2, y2, z2 = q2[:, 0], q2[:, 1], q2[:, 2], q2[:, 3]
w = w1 * w2 - x1 * x2 - y1 * y2 - z1 * z2
x = w1 * x2 + x1 * w2 + y1 * z2 - z1 * y2
y = w1 * y2 + y1 * w2 + z1 * x2 - x1 * z2
z = w1 * z2 + z1 * w2 + x1 * y2 - y1 * x2
if isinstance(q1, np.ndarray):
w = w[:, np.newaxis]
@nirum
nirum / pax.py
Created April 23, 2020 00:00
Routines for loading/saving pytrees to disk as hdf5 files.
"""Save/load pytrees to disk."""
import collections
import h5py
import jax
import numpy as np
def save(filepath, tree):
"""Saves a pytree to an hdf5 file.