Skip to content

Instantly share code, notes, and snippets.

BRIGHT = 8
def color(s, fg, bg):
return "\033[%d;3%d;4%dm%s\033[0m" % (
bool(fg & BRIGHT),
fg & ~BRIGHT,
bg & ~BRIGHT,
s,
)
@heiner
heiner / welford_test.py
Last active November 4, 2021 23:41
Various equivalent implementations of Welford's Algorithm, including its "parallel" version
#
# pytest -svx welford_test.py
#
"""
Cf. Sutton-Barto
http://www.incompleteideas.net/book/first/ebook/node19.html
and
https://math.stackexchange.com/a/103025/5051
as well as
https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Parallel_algorithm
@juniorprincewang
juniorprincewang / test_cudaLaunchKernel.cu
Last active October 10, 2022 13:38
cudaLaunchKernel usage
// Copyright (c) 2019, NVIDIA Corporation. All rights reserved.
//
// This work is made available under the Nvidia Source Code License-NC.
// To view a copy of this license, visit
// https://nvlabs.github.io/stylegan2/license.html
// From https://github.com/NVlabs/stylegan2/blob/master/test_nvcc.cu
#include <cstdio>
void checkCudaError(cudaError_t err)
@apsun
apsun / delet_tweets.md
Last active September 10, 2023 05:06
Delete your old tweets with this disgusting bash script

100% free. Runs completely locally on your machine. Bypasses the 3200 tweet limit. May require some eye bleach for the script. Here's how to use it:

  1. Go to settings -> account -> your Twitter data and request a download. This may take a few hours. You'll get an email with a link to download a zip file. Extract the zip file and navigate to the data directory.

  2. Go to Twitter in a web browser and find any Tweet you want to delete. We're going to use it to extract your authentication credentials for the next step. Open developer tools, delete the tweet, and find the request

#include <cstdio>
#include <random>
#include "openbw/bwgame.h"
#include "openbw/actions.h"
int main() {
std::mt19937 rng(std::random_device{}());
@timothymugayi
timothymugayi / tqdm_threadpool.py
Created December 6, 2019 15:37
How to run tqdm in multiple threads
import time
from random import randrange
from multiprocessing.pool import ThreadPool
from tqdm import tqdm
def func_call(position, total):
text = 'progressbar #{position}'.format(position=position)
@BoQsc
BoQsc / Gists.md
Last active June 10, 2024 19:02
How to search my own Gists
@mohanpedala
mohanpedala / bash_strict_mode.md
Last active June 12, 2024 09:04
set -e, -u, -o, -x pipefail explanation
@negrinho
negrinho / latency.txt
Created July 16, 2018 21:11 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers Simplified (~2012)
---------------------------------- log2 log10
L1 cache reference 0 0 ~ 1 ns
Branch mispredict 3 1
L2 cache reference 4 1
Mutex lock/unlock 6 2
Main memory reference 8 2
Compress 1K bytes with Zippy 13 4
Send 1K bytes over 1 Gbps network 14 4
Read 4K randomly from SSD* 18 5
@batzner
batzner / tensorflow_rename_variables.py
Last active May 25, 2023 06:15
Small python script to rename variables in a TensorFlow checkpoint
import sys, getopt
import tensorflow as tf
usage_str = 'python tensorflow_rename_variables.py --checkpoint_dir=path/to/dir/ ' \
'--replace_from=substr --replace_to=substr --add_prefix=abc --dry_run'
def rename(checkpoint_dir, replace_from, replace_to, add_prefix, dry_run):
checkpoint = tf.train.get_checkpoint_state(checkpoint_dir)