Skip to content

Instantly share code, notes, and snippets.

@kolypto
kolypto / generators.py
Created July 27, 2021 15:21
Advanced examples for Python generators: next(), send(), throw(), yield
# https://docs.python.org/3/library/typing.html#typing.Generator
# 💥💥💥 Simple generator: yield values one by one
# This function pauses to return a value to the outer scope, then proceeds
DICTIONARY = {
'a': 'apple',
'b': 'banana',
'c': 'cat',
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 March 10, 2025 20:15
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 July 1, 2025 17:26
How to search my own Gists
@mohanpedala
mohanpedala / bash_strict_mode.md
Last active July 20, 2025 13:18
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