Skip to content

Instantly share code, notes, and snippets.

View mattsta's full-sized avatar
🐢
Moving slowly and fixing things

Matt Stancliff mattsta

🐢
Moving slowly and fixing things
View GitHub Profile
@mattsta
mattsta / setup.sh
Last active June 5, 2023 06:22
ubuntu 20 / lambdalabs pyenv+poetry+cuda12 bring-up
#!/usr/bin/env bash
## PURPOSE: Fix problems with the currently outdated lambdalabs default image.
# Does:
# - Installs latest Python 3.10 using pyenv
# - Installs the current poetry environment (assuming this is running in a poetry project dir)
# - Installs latest pytorch CUDA 12 nightly into current poetry environment
# Script for "normal-maxing" the default lambdalabs image as of June 2023.
#!/usr/bin/env bash
# mac vm_stat output is unreadable by default (it reports values as multiple of 16384 byte pages),
# so convert the results to actual GB used automatically.
# this python one liner is a list comprehension because it has to hack around
# python not allowing single-line for loops directly.
vm_stat | python -c 'import sys; [print(f"{l:<35}{int(sz) * 16384 / 2**30:>15,.2f} GB") for idx, (l, sz) in enumerate(x.strip().strip(".").split(":") for x in sys.stdin) if idx > 0]'
@mattsta
mattsta / speedups.c
Created December 11, 2021 19:24
a more optimized version of speedups.c from python websockets project with more efficient cascading XOR calculation for large data using Intel SIMD from 32 byte blocks then 16 byte blocks then 8 byte blocks then 1 byte blocks.
/* C implementation of performance sensitive functions. */
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <assert.h>
#include <stdint.h> /* uint32_t, uint64_t */
#include <stdio.h>
#if __AVX2__
@mattsta
mattsta / hsetup.sh
Created December 10, 2020 19:27
quick install steps for haproxy-2.3.2
#!/usr/bin/env bash
set -e
set -x
sudo apt install libssl-dev libsystemd-dev libpcre2-dev -y
wget http://www.haproxy.org/download/2.3/src/haproxy-2.3.2.tar.gz
tar xfvzp hap*
@mattsta
mattsta / hundreds.erl
Last active August 29, 2015 14:20
This is an erlang version of https://gist.github.com/gigamonkey/6249d85021bc8bf54eb4 (with a minor change to 'combos'/'combineAdjacent' for easier reading)
#!/usr/bin/env escript
% Problem statement:
% Write a program that outputs all possibilities to put + or - or nothing between the
% numbers 1, 2, ..., 9 (in this order) such that the result is always 100.
% For example: 1 + 2 + 34 – 5 + 67 – 8 + 9 = 100.
% Generate all combos of digits 1-9 with +, -, or nothing in between.
combos([N]) -> [[N]];
combos([N|Ns]) -> [[N, X] ++ Rest || X <- [plus, minus, empty], Rest <- combos(Ns)].
@mattsta
mattsta / reformatted.hs
Created February 23, 2015 17:50
commandstats reformatted
{'ver': {'status': 'UNKNOWN', 'version': ''}}
{'cmds': {'sorted by calls': [{'get': '158,696,585 times'},
{'set': '71,614,064 times'},
{'ping': '23,045,904 times'},
{'exists': '1,425,952 times'},
{'info': '1,403,483 times'},
{'replconf': '1,370,802 times'},
{'mget': '700,439 times'},
{'del': '163,092 times'},
{'setex': '139 times'},
@mattsta
mattsta / mem_size_bench.c
Created December 20, 2014 19:54
benchmark memory operations from small 32 bytes to 4+ MB. results reported as factional nanoseconds.
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <string.h>
static long long ustime(void) {
struct timeval tv;
long long ust;
gettimeofday(&tv, NULL);
@mattsta
mattsta / gist:8810a0cdf18f45875ebf
Created December 20, 2014 16:06
dont sue me sue
* THIS CONVERSATION IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS CONVERSATION, EVEN IF ADVISED OF THE
@mattsta
mattsta / thing.hs
Created December 3, 2014 21:51
Script/Non-Script Speeds
127.0.0.1:6379> script load "return redis.call('georadius', '{global}:z:locations:'..ARGV[1], ARGV[2], ARGV[3], 10, 'km', 'withdistance', 'ascending')"
"1c4c03da2a57cf99d50d57aba9a1d431526b2b9e"
127.0.0.1:6379> script load "return redis.call('get', 'abc')"
"b86fdf4c29439ed5d9a52c206d90e2b2d8cfc42c"
Geo tests (key doesn't exist, so just testing getting an empty reply):
matt@ununoctium:~/repos/redis/src% redis-benchmark -n 10000 georadius {global}:z:locations:u1 51.0500000 3.7166700 10 km withdistance ascending
====== georadius {global}:z:locations:u1 51.0500000 3.7166700 10 km withdistance ascending ======
10000 requests completed in 0.08 seconds
@mattsta
mattsta / soooooon.t
Created November 16, 2014 18:19
DEBUG JEMALLOC INFO
matt@ununoctium:~/repos/redis/src% ./redis-cli -p 6379 debug jemalloc info
___ Begin jemalloc statistics ___
Version: 3.6.0-0-g46c0af68bd248b04df75e4f92d5fb804c3d75340
Assertions disabled
Run-time option settings:
opt.abort: false
opt.lg_chunk: 22
opt.dss: "secondary"
opt.narenas: 32
opt.lg_dirty_mult: 3