Skip to content

Instantly share code, notes, and snippets.

View vgoklani's full-sized avatar

Vishal Goklani vgoklani

View GitHub Profile
@mblondel
mblondel / kernel_kmeans.py
Last active March 23, 2026 16:57
Kernel K-means.
"""Kernel K-means"""
# Author: Mathieu Blondel <[email protected]>
# License: BSD 3 clause
import numpy as np
from sklearn.base import BaseEstimator, ClusterMixin
from sklearn.metrics.pairwise import pairwise_kernels
from sklearn.utils import check_random_state

Performance of Flask, Tornado, GEvent, and their combinations

Wensheng Wang, 10/1/11

Source: http://blog.wensheng.org/2011/10/performance-of-flask-tornado-gevent-and.html

When choosing a web framework, I pretty much have eyes set on Tornado. But I heard good things about Flask and Gevent. So I tested the performance of each and combinations of the three. I chose something just a little more advanced than a "Hello World" program to write - one that use templates. Here are the codes:

1, Pure Flask (pure_flask.py)

@frankrowe
frankrowe / shp2gj.py
Last active November 1, 2022 17:54
PyShp, shp to geojson in python
import shapefile
# read the shapefile
reader = shapefile.Reader("my.shp")
fields = reader.fields[1:]
field_names = [field[0] for field in fields]
buffer = []
for sr in reader.shapeRecords():
atr = dict(zip(field_names, sr.record))
geom = sr.shape.__geo_interface__
buffer.append(dict(type="Feature", \
@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'