Skip to content

Instantly share code, notes, and snippets.

View stanchan's full-sized avatar
🏠
Working from home

Stan Chan stanchan

🏠
Working from home
View GitHub Profile
@stanchan
stanchan / falsehoods-programming-time-list.md
Created February 18, 2022 19:37 — forked from timvisee/falsehoods-programming-time-list.md
Falsehoods programmers believe about time, in a single list

Falsehoods programmers believe about time

This is a compiled list of falsehoods programmers tend to believe about working with time.

Don't re-invent a date time library yourself. If you think you understand everything about time, you're probably doing it wrong.

Falsehoods

  • There are always 24 hours in a day.
  • February is always 28 days long.
  • Any 24-hour period will always begin and end in the same day (or week, or month).
@stanchan
stanchan / win10-winrm.ps1
Created September 26, 2021 16:31
Windows Update Event Loop
param($global:RestartRequired=0,
$global:MoreUpdates=0,
$global:MaxCycles=5,
$MaxUpdatesPerCycle=500)
$Logfile = "C:\Windows\Temp\win-pre-provision.log"
$EC2ConfigZipPath = "C:\Installers"
$PostScriptPath = "A:\win10-post.ps1"
$PostScript = $(Split-Path $PostScriptPath -Leaf)
@stanchan
stanchan / latency.txt
Created August 8, 2021 18:11 — forked from jboner/latency.txt
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
@stanchan
stanchan / lock.sh
Created January 4, 2019 01:17
Lock File Management Script
#!/bin/bash
[[ -z $1 ]] && echo "Usage: \"$0\" [sleep interval in seconds]" && exit 99
LOCKFILE=/tmp/.${0##*/}.exclusivelock
SLEEP_INTERVAL=$1
WAIT=30
declare -A LOCK_FDS=()
lock() {
@stanchan
stanchan / 01-mac-profiling.md
Created August 24, 2018 20:28 — forked from loderunner/01-mac-profiling.md
Profiling an application in Mac OS X

Profiling an application in Mac OS X

Finding which process to profile

If your system is running slowly, perhaps a process is using too much CPU time and won't let other processes run smoothly. To find out which processes are taking up a lot of CPU time, you can use Apple's Activity Monitor.

The CPU pane shows how processes are affecting CPU (processor) activity:

@stanchan
stanchan / 00-venv-sitepackages.py
Created March 30, 2018 16:38
Fix IPython for VIRTUAL_ENV
import os
import sys
from warnings import warn
virtualenv = os.environ.get('VIRTUAL_ENV')
if virtualenv:
version = os.listdir(os.path.join(virtualenv, 'lib'))[0]
@stanchan
stanchan / clean_teleport.yml
Last active January 19, 2018 00:55
Clean up Teleport
---
- hosts: teleport:teleport_auth:teleport_proxy
gather_facts: False
vars:
systemd_service_dir: /lib/systemd/system
tasks:
- name: CAUTION! WARNING! DANGER!
pause:
prompt: "You are about to wipe this teleport (There is no going back!) [Press Ctrl+C and then 'A' to abort]"
@stanchan
stanchan / 2_prometheus_scrapes
Created October 25, 2017 02:34
2_prometheus_scrapes
scrape_configs:
{% for server in prometheus_scrape %}
- job_name: {{ server.split('.')[0] }}
static_configs:
- targets:
- '{{ server }}'
{% endfor %}
@stanchan
stanchan / .ignore
Created July 19, 2017 15:27
ignore
.DS_Store
.vagrant
**/*.retry
inventory/devtest/hosts
inventory/**/hosts.bak
inventory/vagrant_ansible_inventory
inventory/**/group_vars/fake_hosts.yml
inventory/**/host_vars/
temp
.idea
@stanchan
stanchan / java.sh
Created May 17, 2017 23:07
Java Profile
#!/bin/sh
export JAVA_HOME=/usr/java/jdk
export JRE_HOME=$JAVA_HOME/jre
export J2RE_HOME=$JAVA_HOME/jre
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$J2RE_HOME/bin:$PATH