Skip to content

Instantly share code, notes, and snippets.

View snorfalorpagus's full-sized avatar

Joshua Arnott snorfalorpagus

View GitHub Profile
@GaelVaroquaux
GaelVaroquaux / 00README.rst
Last active September 15, 2023 03:58
Copy-less bindings of C-generated arrays with Cython

Cython example of exposing C-computed arrays in Python without data copies

The goal of this example is to show how an existing C codebase for numerical computing (here c_code.c) can be wrapped in Cython to be exposed in Python.

The meat of the example is that the data is allocated in C, but exposed in Python without a copy using the PyArray_SimpleNewFromData numpy

@ddemidov
ddemidov / Makefile
Created June 13, 2012 18:38
Hello world in OpenCL
hello: hello.cpp
g++ -std=c++0x -o hello hello.cpp -lOpenCL
@acrosby
acrosby / rtree_large_test.py
Last active December 9, 2020 15:50
Sample code for python rtree bulk loading of 10,000,000 points and a nearest neighbor query.
from rtree import index
from random import random
from datetime import datetime
timer = datetime.now()
# Create 10,000,000 random numbers between 0 and 1
rands = [random() for i in range(10000000)]
# Function required to bulk load the random points into the index
@miguelgrinberg
miguelgrinberg / rest-server.py
Last active March 29, 2024 09:05
The code from my article on building RESTful web services with Python and the Flask microframework. See the article here: http://blog.miguelgrinberg.com/post/designing-a-restful-api-with-python-and-flask
#!flask/bin/python
from flask import Flask, jsonify, abort, request, make_response, url_for
from flask_httpauth import HTTPBasicAuth
app = Flask(__name__, static_url_path = "")
auth = HTTPBasicAuth()
@auth.get_password
def get_password(username):
if username == 'miguel':
@dan-blanchard
dan-blanchard / .1.miniconda.md
Last active December 11, 2019 22:38
Quicker Travis builds that rely on numpy and scipy using Miniconda

For ETS's SKLL project, we found out the hard way that Travis-CI's support for numpy and scipy is pretty abysmal. There are pre-installed versions of numpy for some versions of Python, but those are seriously out of date, and scipy is not there are at all. The two most popular approaches for working around this are to (1) build everything from scratch, or (2) use apt-get to install more recent (but still out of date) versions of numpy and scipy. Both of these approaches lead to longer build times, and with the second approach, you still don't have the most recent versions of anything. To circumvent these issues, we've switched to using Miniconda (Anaconda's lightweight cousin) to install everything.

A template for installing a simple Python package that relies on numpy and scipy using Miniconda is provided below. Since it's a common s

@tonyseek
tonyseek / README.rst
Last active November 5, 2022 15:20
Build Python binding of C++ library with cffi (PyPy/Py3K compatible)

Run with Python:

pip-2.7 install cffi
PYTHON=python2.7 sh go.sh

Run with PyPy:

pip-pypy install cffi
PYTHON=pypy sh go.sh
@clavery
clavery / decorators.py
Last active August 3, 2022 16:48
Flask decorator for rate limiting w/ Redis
import logging
import time
from functools import wraps
from flask import request, jsonify
import redis
r = redis.StrictRedis(host='localhost', port=6379, db=0)
logger = logging.getLogger(__name__)
@timlinux
timlinux / pdf_generator.py
Last active March 20, 2022 20:11
Generate a QGIS map PDF using python
# coding=utf-8
# A simple demonstration of to generate a PDF using a QGIS project
# and a QGIS layout template.
#
# This code is public domain, use if for any purpose you see fit.
# Tim Sutton 2015
import sys
from qgis.core import (
@snorfalorpagus
snorfalorpagus / README.md
Created January 25, 2016 10:37
Using distutils and build_clib to build a C library

Using distutils and build_clib to build a C library

This repository demonstrates how to build a C library that is included in the module distribution.

To build the C library:

python setup.py build_clib
@alq666
alq666 / haproxy-stats
Created May 24, 2016 14:10
HAProxy metrics
0. pxname [LFBS]: proxy name
1. svname [LFBS]: service name (FRONTEND for frontend, BACKEND for backend,
any name for server/listener)
2. qcur [..BS]: current queued requests. For the backend this reports the
number queued without a server assigned.
3. qmax [..BS]: max value of qcur
4. scur [LFBS]: current sessions
5. smax [LFBS]: max sessions
6. slim [LFBS]: configured session limit
7. stot [LFBS]: cumulative number of connections