Skip to content

Instantly share code, notes, and snippets.

View cmpute's full-sized avatar
🏠
Working from home

Jacob Zhong cmpute

🏠
Working from home
View GitHub Profile
@cmpute
cmpute / gimps_stats.py
Last active December 3, 2021 05:41
Fetch GIMPS result into database
# requirements: pandas, lxml
import pandas as pd
import sqlite3, time
from datetime import datetime
def fetch():
df = pd.read_html('https://www.mersenne.org/report_recent_results/')[1] # first table is the login form
print(datetime.now().strftime('%c'), ">> Table fetched, data summary:")
print(df)
@cmpute
cmpute / map_loader.py
Created May 16, 2021 03:18
Load and parse INTERACTION dataset
import enum
from io import RawIOBase
import os.path as osp
import xml.etree.ElementTree as xml
from collections import namedtuple
from pathlib import Path
from matplotlib import pyplot as plt
from matplotlib import cm, colors as mcolors
from itertools import islice, filterfalse
@cmpute
cmpute / test_spherical.cpp
Last active May 8, 2021 02:49
Boost RTree with spherical coordinate system
// This code snippet test rtree with spherical coordinate system.
// It will generate grid points of a cubic grid and store them in an rtree.
// And then query is done by find points within some (approximate) distance
// from query point. The query point can be specified by command line args.
//
// Commandline options:
// no args: query point (0, 0, 0) with radius 2
// 3 args: query point (x, y, z) with radius 2
// 4 args: query point (x, y, z) with radius r
@cmpute
cmpute / plane_ransac.pyx
Created April 20, 2021 20:05
Simple RANSAC implemented using Cython
# cython: embedsignature=True, profile=True
from libc.math cimport log, sqrt
from libc.stdlib cimport rand, srand
from libc.time cimport time, time_t
import numpy as np
cimport numpy as np
cimport cython
from cython.view cimport array
@cmpute
cmpute / conda-github-runner.dockerfile
Last active February 3, 2021 03:12
Github action runner image with conda installed
# See https://github.com/tcardonne/docker-github-runner for instructions
FROM tcardonne/github-runner:ubuntu-20.04
RUN curl -L -o miniconda.sh https://repo.anaconda.com/miniconda/Miniconda2-latest-Linux-x86_64.sh
RUN bash miniconda.sh -b -p /miniconda
ENV CONDA="/miniconda"
ENTRYPOINT ["/entrypoint.sh"]
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
@cmpute
cmpute / zipfile.py
Created November 13, 2020 00:22
Patch Python built-in ZipFile class for faster file reading
"""
This moduled provide patched version of builtin Zipfile class as in https://github.com/ThomasPinna/python_zipfile_improvement
You can have better speed when read several files from a zip file containing a large number of files
Modifications are marked with '===== PATCH ====='
"""
import io
import struct
from zipfile import *
from zipfile import (_CD_COMMENT_LENGTH, _CD_EXTRA_FIELD_LENGTH,
_CD_FILENAME_LENGTH, _CD_LOCAL_HEADER_OFFSET,
@cmpute
cmpute / snippets.sh
Last active February 1, 2021 22:54
My linux command cheatsheet
# git: remove all remote branches except for master/main
git branch -r | grep -Eo 'cmpute/.*' | cut -c 8- - | xargs -n 10 git push cmpute --delete
# tar: unzip multiple tarballs in a row
find <INPUT_DIR> -name "*.tgz" | xargs tar -xz -C <OUTPUT_DIR> --checkpoint=10000 -f
# wavpack: compress DSD files
wavpack <INPUT_FILES> <OUTPUT_FILES> -h -m -v –-import-id3
# slurm: Run a slurm interactive session with gpu on Greatlakes
@cmpute
cmpute / client.py
Last active December 2, 2020 15:40
Simplest IPC service for large data in Python
import numpy as np
import msgpack
import msgpack_numpy
msgpack_numpy.patch()
import socket, time, os
from socket_helpers import recv_msg, send_msg
sout = socket.socket(family=socket.AF_UNIX, type=socket.SOCK_DGRAM)
sout.connect("/tmp/ros-ipc-data.sock")
@cmpute
cmpute / bessel_coeffs.py
Created June 12, 2020 20:29
Chebyshev estimation of modified Bessel function
# This scripts calculates the Chebyshev approximation of Bessel functions
#
# Chebyshev approximation intro:
# - https://en.wikipedia.org/wiki/Approximation_theory#Chebyshev_approximation
# - https://mathworld.wolfram.com/ChebyshevApproximationFormula.html
# - http://www.chebfun.org/examples/cheb/ExactChebCoeffs.html
# - https://www.eeeguide.com/chebyshev-approximation/
#
# Online modified Bessel function calculator
# - https://www.wolframalpha.com/input/?i=BesselI%5B0%2Cx%5D
@cmpute
cmpute / mp-tqdm.py
Last active May 7, 2020 17:08
Tqdm in Multiprocessing
from time import sleep
from tqdm import trange, tqdm
from random import random
from multiprocessing import Pool, Manager
from itertools import count
def _wrap_func(func, args, pool, nlock):
n = -1
with nlock:
n = next(i for i,v in enumerate(pool) if v == 0)