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
/* | |
NOTE: This code assumes a bare git repo in ./bare-git/, | |
which should have at least one text file in its root, | |
named "greetings.txt". | |
This code updates the contents of a "greetings.txt" | |
file, and creates a new file called "greetings-XXX.txt" | |
(with XXX being a random number). It then creates a new | |
commit for these changes. Finally, it reads and dumps | |
the new current contents of the repo, file by file. |
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
var y; | |
foo(); | |
// values: 3 10 | |
// value: 4 10 | |
// ******************************* | |
function foo() { | |
for (let i=0; i<2; i++) { | |
let obj = { x: 2 }; // <-- bug because of `let` here |
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
// Standard: | |
function fn(x) { | |
return function(y){ | |
return function(z){ | |
return x * y / z; | |
}; | |
}; | |
} |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>name</key> | |
<string>Monokai</string> | |
<key>settings</key> | |
<array> | |
<dict> | |
<key>settings</key> |
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
var list = [1,2,3,4,5]; | |
zip( list, map( x => x ** 2, list ) ); | |
// [[1,1],[2,4],[3,9],[4,16],[5,25]] |
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
// most common approach, using extend(..) | |
var defaults = { | |
url: "http://some.base.url/api", | |
method: "post", | |
headers: [ | |
"Content-Type: text/plain" | |
] | |
}; |
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 reverseStr(str) { | |
if (str.length <= 1) return str; | |
var firstChar = str[0]; | |
var restStr = str.substr(1); | |
return (restStr.length > 1 ? reverseStr(restStr) : restStr) + | |
firstChar; | |
} |
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
var f = (x,y) => z => x + y + z | |
// POP QUIZ: how do you use `f(..)` here? | |
// (x,y) is the parameter inputs to `f(..)`. But what does `f(..)` return? | |
// To my eyes, on a first left-to-right read, calling `f(..)` returns a `z` value. | |
// But that's not the case, because `z` isn't a value to return, it's the parameter to another function! |
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
// ugly way | |
var obj = { | |
a: 1, | |
b: 2, | |
c: 3, | |
[Symbol.iterator]() { | |
var keys = Object.keys(this); | |
var idx = 0; | |
return { |
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 lowercase(v) { | |
return v.toLowerCase(); | |
} | |
function uppercase(v) { | |
return v.toUpperCase(); | |
} | |
var words = ["Now","Is","The","Time"]; | |
var moreWords = ["The","Quick","Brown","Fox"]; |