- By Edmond Lau
- Highly Recommended 👍
- http://www.theeffectiveengineer.com/
- They are the people who get things done. Effective Engineers produce results.
| #!/boot/bzImage | |
| # Linux kernel initialization code, translated to bash | |
| # (Minus floppy disk handling, because seriously, it's 2017.) | |
| # Not 100% accurate, but gives you a good idea of how kernel init works | |
| # GPLv2, Copyright 2017 Hector Martin <[email protected]> | |
| # Based on Linux 4.10-rc2. | |
| # Note: pretend chroot is a builtin and affects the current process | |
| # Note: kernel actually uses major/minor device numbers instead of device name |
L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns
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
| #!/usr/bin/env python | |
| import sys, os, time, atexit | |
| from signal import SIGTERM | |
| class Daemon: | |
| """ | |
| A generic daemon class. | |
| Usage: subclass the Daemon class and override the run() method |
| function goinit { | |
| export GOROOT=/usr/local/Cellar/go/1.2.1/libexec | |
| if [ $# -lt 1 ] | |
| then | |
| echo "No directories were created." | |
| export GOPATH=$(pwd -P) | |
| export PATH=$PATH:$GOPATH:$GOPATH/bin | |
| else | |
| echo "$1 being created" | |
| mkdir $1 |
| module CallPrice | |
| function callprice(S0, K, r, T, sigma, paths) | |
| Csum = 0.0 | |
| for j = 1:paths | |
| Zs = randn() | |
| Zj = T*(r-sigma.^2/2) + Zs*T.^0.5*sigma | |
| STj = exp(Zj)*S0 | |
| Csum += exp(-r*T)*max(STj - K,0.0) | |
| end | |
| return Csum/paths |
| This is the list of exit codes for wget: | |
| 0 No problems occurred | |
| 1 Generic error code | |
| 2 Parse error — for instance, when parsing command-line options, the .wgetrc or .netrc… | |
| 3 File I/O error | |
| 4 Network failure | |
| 5 SSL verification failure | |
| 6 Username/password authentication failure | |
| 7 Protocol errors |
| #!/bin/bash | |
| # bash generate random alphanumeric string | |
| # | |
| # bash generate random 32 character alphanumeric string (upper and lowercase) and | |
| NEW_UUID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1) | |
| # bash generate random 32 character alphanumeric string (lowercase only) | |
| cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1 |
| These are snippets of py.test in action, used in a talk given at | |
| PyCon AU 2012 in Hobart, Tasmania. They are all relevant for | |
| py.test 2.2 except where specified. Where taken from open source | |
| projects I have listed a URL, some examples are from the py.test | |
| documentation, some are from my workplace. | |
| Apart from things called test_*, these functions should probably | |
| be in your conftest.py, although they can generally start life in | |
| your test files. |
| // A sprintf-like function using d3.js | |
| // https://gist.github.com/2045912 | |
| function d3_sprintf(strings, formatters) { | |
| return formatters.reduce(function (strings, formatter, i) { | |
| strings[i] = formatter(strings[i]); | |
| return strings | |
| }, strings).join(""); | |
| }; |