Skip to content

Instantly share code, notes, and snippets.

huyanhvn / latency.txt
Created April 15, 2017 02:02 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
View latency.txt
Latency Comparison Numbers
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
huyanhvn / enable-luks-howto
Created July 25, 2016 18:12
Enable LUKS disk encryption with a key file
View enable-luks-howto
# Create strong LUKS key
openssl genrsa -out /root/luks.key 4096
chmod 400 /root/luks.key
# Fill random data to the device
shred -v --iterations=1 /dev/xvdb
# Format device
echo "YES" | cryptsetup luksFormat /dev/xvdb --key-file /root/luks.key
huyanhvn / jmeter-example.jmx
Created July 21, 2016 17:49
View jmeter-example.jmx
<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="2.9" jmeter="3.0 r1743807">
<TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="cic-proxy-latency-test" enabled="true">
<stringProp name="TestPlan.comments"></stringProp>
<boolProp name="TestPlan.functional_mode">false</boolProp>
<boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
<elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
<collectionProp name="Arguments.arguments"/>
huyanhvn / aws-s3
Last active March 11, 2016 14:49
View aws-s3
aws s3api list-objects --bucket BUCKETNAME --output json --query "[sum(Contents[].Size), length(Contents[])]”
"Version": "2012-10-17",
"Id": "PutObjPolicy",
"Statement": [
"Sid": "DenyUnEncryptedObjectUploads",
huyanhvn / chef-vault
Last active May 2, 2016 16:09
View chef-vault
### knife.rb:
knife[:vault_mode] = "client"
data_bag_path "/Users/hnguyen/data_bags"
### Creating a Vault
Vault creation is very similar to data bag creation. Specify a Vault name, and Item name inside of that vault as well as the default JSON data to go into the vault. You can optionally specify a node search, and/or a list of Chef Server users who should have access to the vault.
knife vault create [vault] [item] '{}'
knife vault create [vault] [item] '{}' -S 'search' -A 'user1,user2'
huyanhvn / apache-stuff
Created August 19, 2015 16:24
View apache-stuff
RewriteEngine On
RewriteMap some_map dbm=sdbm:/var/www/
RewriteCond %{QUERY_STRING} some[iI]d=(\d+)
RewriteCond ${some_map:%1} !=""
RewriteRule ^/some/thing/view\.asp$ /some/thing/else/${some_map:%1}? [P]
huyanhvn / tcpdump
Last active August 29, 2015 14:23
View tcpdump
# tcpdump -i eth0 -A -s65535 port 8080
intecepts all packets goving over port 8080 on eth0 network interface.
-s means size of each packet. so it dumps first 65k of the packet. default is much short and will truncate long http responses.
-A means show packets as ascii on screen
-w filename
for non plain text protocol (e.g. LDAP), write to file and use wireshark.
huyanhvn / chef-stuff
Last active August 29, 2015 14:21
Chef stuff
View chef-stuff
### berks ignore ssl
$ cat ~/.berkshelf/config.json
"ssl": {
"verify": false
### berks Faraday SSL error
export SSL_CERT_FILE=/etc/openssl/cert.pem
huyanhvn / sublime-key-bindings
Last active May 11, 2016 13:42
sublime user key bindings
View sublime-key-bindings
{ "keys": ["ctrl+x"], "command": "cut" },
{ "keys": ["ctrl+c"], "command": "copy" },
{ "keys": ["ctrl+v"], "command": "paste" },
{ "keys": ["ctrl+shift+v"], "command": "paste_and_indent" },
{ "keys": ["ctrl+s"], "command": "save" },
{ "keys": ["ctrl+z"], "command": "undo" },
{ "keys": ["ctrl+shift+z"], "command": "redo" },
{ "keys": ["ctrl+y"], "command": "redo_or_repeat" },
{ "keys": ["ctrl+u"], "command": "soft_undo" },
huyanhvn / linux-tricks
Last active September 3, 2018 15:37
Linux tricks
View linux-tricks
### Kill process and all its children
kill -- -$(ps -o pgid= $PID | grep -o '[0-9]*') (signal TERM)
kill -9 -$(ps -o pgid= $PID | grep -o '[0-9]*') (signal KILL)
ps aux | awk '{print $2, $4, $11}' | sort -k2rn | head -n 10
### SSH menu