As easy as 1, 2, 3!
Updated:
- Aug, 08, 2022 update
config
docs for npm 8+ - Jul 27, 2021 add private scopes
- Jul 22, 2021 add dist tags
- Jun 20, 2021 update for
--access=public
- Sep 07, 2020 update docs for
npm version
// apache_request_headers replicement for nginx | |
if (!function_exists('apache_request_headers')) { | |
function apache_request_headers() { | |
foreach($_SERVER as $key=>$value) { | |
if (substr($key,0,5)=="HTTP_") { | |
$key=str_replace(" ","-",ucwords(strtolower(str_replace("_"," ",substr($key,5))))); | |
$out[$key]=$value; | |
}else{ | |
$out[$key]=$value; | |
} |
var p1 = { | |
x: 20, | |
y: 20 | |
}; | |
var p2 = { | |
x: 40, | |
y: 40 | |
}; |
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 |
// NOTICE 2020-04-18 | |
// Please see the comments below about why this is not a great PRNG. | |
// Read summary by @bryc here: | |
// https://github.com/bryc/code/blob/master/jshash/PRNGs.md | |
// Have a look at js-arbit which uses Alea: | |
// https://github.com/blixt/js-arbit | |
/** |
Below are many examples of function hoisting behavior in JavaScript. Ones marked as works
successfuly print 'hi!' without errors.
To play around with these examples (recommended) clone them with git and execute them with e.g. node a.js
(I may be using incorrect terms below, please forgive me)
Because pointers can be ugh
To understand a pointer, let's review "regular" variables first. If you're familiar with a programming language without pointers like JavaScript, this is what you think when you hear "variable".
When declaring a variable by identifier (or name), the variable is synonymous with its value.
// these are just for trying to make the same code shorter | |
// original code | |
document.onkeydown=function(e){e=e||window.event;document.getElementById(e.keyCode==37?"kill-good":e.keyCode==39?"kill-bad":"sg").click();}; | |
// optimized | |
document.onkeydown=function(e){document.getElementById(e.keyCode==37?"kill-good":e.keyCode==39?"kill-bad":"sg").click()} | |
// shorter version. Left = yes, Other keys = no | |
document.onkeyup=function(e){document.getElementById(e.keyCode==37?'kill-good':'kill-bad').click()} |
var CLerp = | |
{ | |
time: 0, // Program / game elapsed time | |
lerps: [], | |
doLerp: function(v0, v1, t, f, id) | |
{ | |
var self = this; | |
var id = id || null; |