Skip to content

Instantly share code, notes, and snippets.

View terrywang's full-sized avatar

Terry Wang terrywang

View GitHub Profile

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns                     on recent CPU
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 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs 4X memory

@denji
denji / nginx-tuning.md
Last active May 8, 2025 19:46
NGINX tuning for best performance

NGINX Tuning For Best Performance

For this configuration you can use web server you like, i decided, because i work mostly with it to use nginx.

Generally, properly configured nginx can handle up to 400K to 500K requests per second (clustered), most what i saw is 50K to 80K (non-clustered) requests per second and 30% CPU load, course, this was 2 x Intel Xeon with HyperThreading enabled, but it can work without problem on slower machines.

You must understand that this config is used in testing environment and not in production so you will need to find a way to implement most of those features best possible for your servers.

@XVilka
XVilka / TrueColour.md
Last active April 27, 2025 10:17
True Colour (16 million colours) support in various terminal applications and terminals

THIS GIST WAS MOVED TO TERMSTANDARD/COLORS REPOSITORY.

PLEASE ASK YOUR QUESTIONS OR ADD ANY SUGGESTIONS AS A REPOSITORY ISSUES OR PULL REQUESTS INSTEAD!

@dcai
dcai / git_update_moodle.sh
Last active October 26, 2017 03:39
git_update_moodle.sh
#!/bin/bash
# Your github username
github_user="dcai"
# The remote name of your github repo, it usually origin
github_remote_name="github"
### STOP CONFIG SINCE HERE! ###
github_diff_root="https://github.com/$github_user/moodle/compare/"
@huacnlee
huacnlee / move_files.rb
Last active December 20, 2015 17:49
将一个目前下面的文件,根据文件名前缀分散到不同的文件夹,比如 a12.jpg -> a/1/a12.jpg, b287.jpg -> b/2/b287.jpg 此方法用于处理由于最初设计上传文件夹没有分层次导致一个目录文件过多的问题。可以将一个目录下面的文件分散到子目录中
require "fileutils"
root_dir = "/Users/jason/Downloads/images"
Dir.chdir(root_dir)
puts Dir.pwd
Dir.glob("**/*.{jpg}").each do |fname|
tfname = fname.split("/").last
if fname.match("[small|large|normal]_")
tfname = fname.split("_").last
end
p1,p2 = tfname[0,1],tfname[1,1]
@rodjek
rodjek / 0_description.md
Last active December 19, 2015 03:18
check_puppet_run_health

check_puppet_run_health

A Nagios check that connects to PuppetDB and determines the Puppet agent run health on a host.

Requires

  • PuppetDB
  • A puppetmaster configured to send reports to PuppetDB

States

@smoser
smoser / apt-go-fast
Last active January 15, 2020 22:12
apt-go-fast: streamline apt-get by removing things you don't want or need and using eatmydata
#!/bin/sh
# https://gist.github.com/smoser/5823699
set -e
[ "$(id -u)" = "0" ] && sudo="" || sudo="sudo"
[ -e "/usr/bin/apt-get.distrib" ] ||
$sudo dpkg-divert --local --rename --add /usr/bin/apt-get
$sudo tee /usr/bin/apt-get >/dev/null <<"EOF"
#!/bin/sh
@fields
fields / Vagrantfile
Created May 20, 2013 15:48
Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
# override these variables in ~/.vagrant.d/Vagrantfile for your local changes
$local_username ||= `whoami`.strip
$local_projects_directory ||= "~/projects/vagrant/"
$vm_memory ||= "4096"
$vm_cpus ||= "4"
$server_root_password = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
@thbar
thbar / .bash_profile
Created May 15, 2013 13:37
How to quickly switch Mac OS X terminal background between black and white.
# based on http://stackoverflow.com/questions/549186/change-background-of-terminal-app-from-the-commandline
function darkback {
osascript -e "tell application \"Terminal\" to set background color of window 1 to {0,0,0}"
}
function lightback {
osascript -e "tell application \"Terminal\" to set background color of window 1 to {65535,65535,65535}"
}
@Jerry-Fix
Jerry-Fix / ubuntu 12.04 preseed
Created April 13, 2013 17:03
ubuntu 12.04 preseed for cobbler
d-i debian-installer/locale string en_US
d-i debian-installer/language string en
d-i debian-installer/country string US
d-i debian-installer/locale string en_US.UTF-8
d-i debian-installer/allow_unauthenticated string true
d-i console-setup/ask_detect boolean false
d-i console-setup/layoutcode string us