Skip to content

Instantly share code, notes, and snippets.

# Copyright 2018 The JAX Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@Zaharid
Zaharid / rand_rot.py
Last active June 8, 2016 13:29
Random rotation of dimension n
import numpy as np
import numpy.linalg as la
def rand_unit(n):
r = np.random.randn(n)
return r/la.norm(r)
def householder(unit_v):
return np.eye(len(unit_v)) - 2*np.outer(unit_v,unit_v)
@Zaharid
Zaharid / multilogging.py
Created June 26, 2015 11:42
Proper way to manage logging for multiple processes.
# -*- coding: utf-8 -*-
"""
Created on Fri Jun 26 13:16:22 2015
@author: zah
"""
import multiprocessing
import logging
@Zaharid
Zaharid / minclient.py
Last active August 29, 2015 14:06
Minimun websocket client for tornado
from tornado.websocket import websocket_connect
from tornado import ioloop
from tornado import gen
@gen.coroutine
def onconnect(future):
ws = future.result()
while 1:
m = input("message?\n")
ws.write_message(m)
msg = yield ws.read_message()