Skip to content

Instantly share code, notes, and snippets.

@eqhmcow
eqhmcow / hfsc-shape.sh
Last active August 2, 2023 11:59
HFSC - linux traffic shaping's best kept secret
#!/bin/bash
# As the "bufferbloat" folks have recently re-discovered and/or more widely
# publicized, congestion avoidance algorithms (such as those found in TCP) do
# a great job of allowing network endpoints to negotiate transfer rates that
# maximize a link's bandwidth usage without unduly penalizing any particular
# stream. This allows bulk transfer streams to use the maximum available
# bandwidth without affecting the latency of non-bulk (e.g. interactive)
# streams.
@Aneurysm9
Aneurysm9 / .tmux.conf
Created April 9, 2012 14:22
tmux Config
# Set the prefix to ^A.
unbind C-b
set -g prefix ^A
bind a send-prefix
# Bind appropriate commands similar to screen.
# lockscreen ^X x
unbind ^X
bind ^X lock-server
unbind x
@jboner
jboner / latency.txt
Last active July 25, 2024 11:30
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@arvearve
arvearve / gist:4158578
Created November 28, 2012 02:01
Mathematics: What do grad students in math do all day?

Mathematics: What do grad students in math do all day?

by Yasha Berchenko-Kogan

A lot of math grad school is reading books and papers and trying to understand what's going on. The difficulty is that reading math is not like reading a mystery thriller, and it's not even like reading a history book or a New York Times article.

The main issue is that, by the time you get to the frontiers of math, the words to describe the concepts don't really exist yet. Communicating these ideas is a bit like trying to explain a vacuum cleaner to someone who has never seen one, except you're only allowed to use words that are four letters long or shorter.

What can you say?

@alekstorm
alekstorm / git-reviewers
Last active April 15, 2023 05:51
Finds likely good reviewers for a commit or range of commits by getting a diff, then running `git blame` on the previous versions of each changed hunk. Outputs a sorted list of reviewer names, emails, and how many lines you've both touched. To use, name the file `git-reviewers`, put it somewhere in your $PATH, make it executable, and call it wit…
#!/usr/bin/env bash -ue
if [[ $# -lt 1 || $# -gt 2 ]]; then
echo "Usage: git $(basename "$0" | sed 's/^git-//') <end-commit> [<start-commit>]"
exit 1
fi
diff_range="$1^..$1"
end_commit="$1^"
if [[ $# -eq 2 ]]; then
@DamnedFacts
DamnedFacts / fake-uname.c
Last active September 29, 2020 04:18
Fake uname information in order to make tools, such as megacli, work: Gentoo-11 tmp # gcc -Wall -fPIC -c fake-uname.c Gentoo-11 tmp # gcc -Wall -shared -o libfake-uname.so fake-uname.o Now we get libfake-uname.so, use LD_PRELOAD=./libfake-uname.so to preload it, over uname from glibc: Gentoo-11 tmp # LD_PRELOAD=./libfake-uname.so LD_LIBRARY_PATH…
#define _GNU_SOURCE
#include <unistd.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/utsname.h>
#include <stdio.h>
#include <string.h>
int uname(struct utsname *buf)
@Apsu
Apsu / gpg-pam-exec
Last active August 22, 2022 14:55
PAM-integrated GPG-agent with passphrase presetting
#!/usr/bin/env bash
# grab PAM-provided auth token
read token
# grab our user, $USER isn't always set
USER="$(id -un)"
# switch to PAM_USER if passed, buffer return value
$([[ "$PAM_USER" != "$USER" ]] && echo su - "$PAM_USER" -s) /usr/local/bin/gpg-preset-passphrase <<< "$token"
@eddieantonio
eddieantonio / python.vim
Last active March 27, 2018 22:15
Vim Syntastic: automatically switch between python2 and python3 syntax checkers.
" Place this file in {VIMHOME}/after/ftplugin/python.vim
" Must have syntastic >= 3.5.0-29
" Use Python 3 when the shebang calls for it.
let b:syntastic_python_python_exec =
\ syntastic#util#parseShebang()['exe'] =~# '\m\<python3'
\ ? 'python3'
\ : 'python'
@ttaubert
ttaubert / onion-gen.js
Created November 2, 2014 13:14
Generating custom .onion names with the WebCrypto API
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
/*
* thirty-two
* https://github.com/chrisumbel/thirty-two
*
# Check installed RAM, disable VM if 8Gb or more.
mem_inst=`/usr/sbin/sysctl -n hw.memsize`
if [ "$mem_inst" -ge "8589934592" ]; then
echo "8Gb+ Memory installed."
if [ "$action" == "unload" ]; then
sudo nvram boot-args="vm_compressor=2"
sudo pmset -a hibernatemode 0
echo "vm.compressor_mode set to 2"