- Newcomers will already be familiar with double quotes from their language. In English, we must use double quotes " to identify a passage of quoted text. If we were to use a single quote ', the reader may misinterpret it as a contraction. The other meaning of a passage of text surrounded by the ' indicates the 'colloquial' meaning. It makes sense to stay consistent with pre-existing languages, and this may likely ease the learning and interpretation of code.
- Double quotes eliminate the need to escape apostrophes (as in contraptions). Consider the string: "I'm going to the mall", vs. the otherwise escaped version: 'I'm going to the mall'.
- Double quotes mean a string. When you learn a new language like Java, Python, or C, double quotes are always used. This is because, as mentioned above, double quotes have always been used in language to indicate quoted passages of text. Old books will use double quo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[user] | |
email = [email protected] | |
name = caub | |
[alias] | |
a = add --all | |
au = add -u | |
b = branch | |
br = branch -r | |
amend = commit --amend -C HEAD |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { Readable } = require('stream'); | |
const ys = Buffer.from('y\n'.repeat(2**16)); | |
class Y extends Readable { | |
_read(size) { | |
this.push(ys.slice(0, size)); | |
} | |
} | |
new Y().pipe(process.stdout); // test with node yes | pv -r > /dev/null |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 2 globals defined at boot of nodejs engine | |
rl = cb => require('readline').createInterface({input:process.stdin}).on('line',cb); | |
print = console.log; | |
/* | |
Let's call an integer "repetitive" if it contains two of the same digit in a row. For example, 12232 is repetitive but 1232 is not. | |
Given a positive integer n < 10^15, return the number of nonrepetitive integers in [1..n]. | |
*/ | |
// prog | |
rl(s=>{r=0;d=s.length-1;for(i=0;i<=d;i++){r+=(i>0&&s[i-1]<s[i]?s[i]-1:s[i])*9**(d-i);if(s[i-1]==s[i]){r--;break}}for(i=0;i<d;i++)r+=9**i;print(r)}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function $(container, selector) { | |
const els = | |
typeof selector === 'string' | |
? container.querySelectorAll(selector) | |
: typeof container === 'string' ? document.querySelectorAll(container) : [container]; | |
const fns = { | |
removeClass(...cls) { | |
els.forEach(el => { | |
el.classList.remove(...cls); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create table foo_version ( | |
id VARCHAR(32), | |
v BIGINT, | |
data TEXT, | |
PRIMARY KEY (id, v) | |
); | |
create table foo ( | |
id VARCHAR(32), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.import = function (transformer) { | |
const ROOT = location.origin; | |
const REQUIRE_CACHE = new Map(); | |
const RE_EXT = /\.js\w*$/; | |
function fqn(url, dirname) { | |
const {href} = new URL(url.startsWith('http') ? url : (url.startsWith('/') ? ROOT : dirname) + url), | |
last = href.lastIndexOf('/'), dir = href.slice(0, last+1), name = href.slice(last+1), | |
filename = name ? (RE_EXT.test(name) ? name: name+'.js') : 'index.js'; | |
return {dir, abs: dir+filename}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function(gen) { // coroutine, equivalent to https://github.com/tj/co | |
const it = gen(); | |
return Promise.resolve().then(function pump(v) { | |
const next = it.next(v); | |
if(next.done) return next.value; | |
return Promise.resolve(next.value).then(pump, it.throw.bind(it)); | |
}); | |
}; |
- dom builder examples https://jsfiddle.net/crl/tfo58xmt/5/ https://jsfiddle.net/crl/7jo9zp5t/22/
- like
<input type="search">
but not https://jsfiddle.net/364Lbu1w/3/ - contenteditable https://jsfiddle.net/crl/eumxoudn/39/ react https://jsfiddle.net/crl/eumxoudn/11/
- designs address form | list | checkbox | increment buttons /5 | button | dropdown | circle nav
- fps-meter https://output.jsbin.com/banewul/
- play with unicodes https://jsfiddle.net/crl/s0xbrwv5/10/, golden ratio https://jsfiddle.net/crl/bveyL2uf/6/
- slot machine https://jsfiddle.net/crl/sbh0hrfu/
- canvas vs svg https://jsfiddle.net/crl/vbtbm83k/17/
- cancellable fetch https://jsfiddle.net/crl/8ns0abst/6/
-
Shortening
const
to something likeref
,val
,cst
because- it's the most frequently used keyword
- conflicts with
console.log
auto-completion
-
null
should beObject.freeze(Object.create(null))
or a specialSymbol.nullable
-
([] =~= []) // true
shallow compare -
({ a: {} } =*= { a: {} }) // true
deep compare