Skip to content

Instantly share code, notes, and snippets.

View vgoklani's full-sized avatar

Vishal Goklani vgoklani

View GitHub Profile
@dfm
dfm / line.py
Created July 15, 2013 15:38
emcee: line with 2D errors.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import division, print_function
import emcee
import numpy as np
import matplotlib.pyplot as pl
np.random.seed(123)
@kwmsmith
kwmsmith / pairwise_cython.pyx
Last active August 12, 2022 04:25
Numba vs. Cython: Parallel Cython with OMP
#cython:boundscheck=False
#cython:wraparound=False
import numpy as np
from cython.parallel cimport prange
from libc.math cimport sqrt
cdef inline double dotp(int i, int j, int N, double[:, ::1] X) nogil:
cdef:
int k
import numpy as np
import pylab as pl
x = np.random.uniform(1, 100, 1000)
y = np.log(x) + np.random.normal(0, .3, 1000)
pl.scatter(x, y, s=1, label="log(x) with noise")
pl.plot(np.arange(1, 100), np.log(np.arange(1, 100)), c="b", label="log(x) true function")
pl.xlabel("x")
pl.ylabel("f(x) = log(x)")
import collections
import json
import redis
import threading
from tornado import gen
from tornado import ioloop
from tornado import web
from tornado.options import define
from tornado.options import options
import tornadoredis
@dwf
dwf / reader.pyx
Last active February 10, 2017 08:45
A proof-of-concept for a multi-threaded pre-fetching loader for .NPY files.
"""
A proof-of-concept multi-threaded chunked NPY format reader.
"""
__author__ = "David Warde-Farley"
__credits__ = ["David Warde-Farley"]
__license__ = "3-clause BSD"
__email__ = 'd dot warde dot farley at gmail DOT com"
import threading
from numpy.lib.format import read_magic, read_array_header_1_0
@larsmans
larsmans / csc_columnwise_max.pyx
Created March 11, 2013 22:36
Columnwise maximum of scipy.sparse.csc_matrix, in Cython
cimport numpy as np
def csc_columnwise_max(np.ndarray[np.float64_t, ndim=1] data,
np.ndarray[int, ndim=1] indices,
np.ndarray[int, ndim=1] indptr,
np.ndarray[np.float64_t, ndim=1] out):
cdef double mx
cdef int n_features = indptr.shape[0] - 1
cdef int i, j
@craigdub
craigdub / tornado pika example.py
Last active July 12, 2016 08:18
Simple tornado web server with rabbitmq's pika
import tornado.ioloop
import tornado.web
import pika
import logging
from pika.adapters.tornado_connection import TornadoConnection
TORNADO_PORT = 8889
RMQ_USER = 'user'
RMQ_PWD = 'password'
@mickey06
mickey06 / gist:4770903
Created February 12, 2013 16:00
Flask login with wtfoms validation
class LoginForm(flask_wtf.Form):
"""
Validate login from
"""
email_validator = [flask_wtf.Required()]
pwd_validator = [flask_wtf.Required(), flask_wtf.Length(2)]
email = flask_wtf.TextField(u'email', validators=email_validator)
password = flask_wtf.PasswordField(u'password', validators=pwd_validator)
submit = flask_wtf.SubmitField("Login")
"""
This is a simple example of WebSocket + Tornado + Redis Pub/Sub usage.
Do not forget to replace YOURSERVER by the correct value.
Keep in mind that you need the *very latest* version of your web browser.
You also need to add Jacob Kristhammar's websocket implementation to Tornado:
Grab it here:
http://gist.github.com/526746
Or clone my fork of Tornado with websocket included:
http://github.com/pelletier/tornado
Oh and the Pub/Sub protocol is only available in Redis 2.0.0:
@lbolla
lbolla / futures_test.py
Last active April 24, 2023 17:59
Tornado and concurrent.futures
from concurrent.futures import ThreadPoolExecutor
from functools import partial, wraps
import time
import tornado.ioloop
import tornado.web
EXECUTOR = ThreadPoolExecutor(max_workers=4)