Skip to content

Instantly share code, notes, and snippets.

View etale-cohomology's full-sized avatar

Diego Alonso etale-cohomology

View GitHub Profile
@etale-cohomology
etale-cohomology / compress HTTP GET requests
Last active October 21, 2021 00:12
The 'Accept-Encoding' HTTP request header can be used to tell the HTTP server you want compressed data. The server responds with a `Content-Encoding` header.
curl https://api.binance.com/api/v3/exchangeInfo --header 'Accept-Encoding: gzip, deflate' | gunzip -
@etale-cohomology
etale-cohomology / calculus0.py
Created October 11, 2017 21:44
The fundamental theorem of calculus, in discrete version!
# The fundamental theorem of calculus, in discrete version!
import numpy as np
np.set_printoptions(linewidth=200, precision=2)
print('This Python snippet shows how the sum of many differences is one difference of endpoinds!')
print('You can consider this the "discrete fundamental theorem of calculus"!')
# ----------------------------------------------------------------------
N_VALUES = 16
@etale-cohomology
etale-cohomology / add1.cu
Last active October 12, 2017 09:50
A minimal CUDA program that naively performs vector addition, component-wise!
// Compile and run with:
// nvcc add1.cu -o add1 && ./add1
// This minimal CUDA program performs vector addition, component-wise!
#include <stdio.h>
#define N_ELEMENTS 8
@etale-cohomology
etale-cohomology / load_ndarray.py
Created March 11, 2016 00:54
Load a NumPy array from disk, either from a .npy file or from a .7z file. No need to include extension
def load_ndarray(filename):
"""Load a NumPy array from disk into memory, with extension .npy or .7z. If no extension is
included in the argument, first assume it's .npy, then .7z.
Args:
filename (str): Name of the NumPy array (in disk).
Returns:
ndarray
"""
@etale-cohomology
etale-cohomology / save_ndarray.py
Created March 11, 2016 00:53
Save a NumPy array to disk with optional compression using 7z
def save_ndarray(ndarray, filename, compress=False):
"""Store a single NumPy array on an .npy binary file. Tries to keep allow_pickle at False.
Optional multithreaded compression using 7-zip (needs to be in the PATH).
Args:
ndarray (ndarray): Array to be stored on disk.
filename (str): The file's name on disk. No need for .npy extension
compress (bool, optional): Set to True to save array as .npy and then compress it to .7z
Returns:
@etale-cohomology
etale-cohomology / vispy0.py
Created March 11, 2016 00:51
A small working example of vispy, along with some notes
"""Vispy is based on OpenGL ES 2.0.
Vispy offers a Pythonic object-oriented interface to OpenGL, useful to those
who know OpenGL.
It is critical to use as few OpenGL draw calls as possible. Every draw incurs
a significant overhead. High performance is achieved by rendering all similar
primitive types at once (batch rendering).
The vertex shader is executed for EACH vertex that is given to the rendering
@contextlib.contextmanager # Create factory function for *with* context managers
def timeit():
"""Time execution of code, based on time.clock(). Call using a *with* statement!
Examples:
with timeit():
a @ a
"""
start = time.clock()
yield # The decorated func must return a generator-iterator