Skip to content

Instantly share code, notes, and snippets.

View getify's full-sized avatar
💭
Just coding

Kyle Simpson getify

💭
Just coding
View GitHub Profile
@getify
getify / 1.js
Last active July 27, 2023 15:50
demonstrating how to use "nodegit" to modify and read from a local bare git repo
/*
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.
@getify
getify / 1.js
Last active January 9, 2018 08:26
horribly convoluted bug, badly illustrated. **NOTE: this is not the real code, it's an ugly illustration of kinda what the bug was in my real code.
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
@getify
getify / 1.js
Last active June 2, 2021 15:41
Proposal: curried function declarations in javascript -- aka, making FP development in JS much much nicer
// Standard:
function fn(x) {
return function(y){
return function(z){
return x * y / z;
};
};
}
@getify
getify / Monokai (SL) - ESNext.tmTheme
Created October 3, 2017 16:41
modifications to Sublime Text 3 - Monokai (SL) theme via "Sublime Linter" package, in part to style some ES6 features better
<?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>
@getify
getify / 1.js
Last active August 17, 2017 03:23
mapZip(..): kinda like the inverse of flatMap(..) I guess
var list = [1,2,3,4,5];
zip( list, map( x => x ** 2, list ) );
// [[1,1],[2,4],[3,9],[4,16],[5,25]]
@getify
getify / 1.js
Last active April 3, 2020 15:16
"destructuring + restructuring": merging objects with defaults using destructuring instead of `extend(..)`
// most common approach, using extend(..)
var defaults = {
url: "http://some.base.url/api",
method: "post",
headers: [
"Content-Type: text/plain"
]
};
@getify
getify / 1.js
Last active December 6, 2017 14:07
comparing single recursion vs binary recursion
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;
}
@getify
getify / 1.js
Created June 29, 2017 19:31
arrow functions readability fun
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!
@getify
getify / 1.js
Last active October 15, 2017 01:35
generators as object iterator
// ugly way
var obj = {
a: 1,
b: 2,
c: 3,
[Symbol.iterator]() {
var keys = Object.keys(this);
var idx = 0;
return {
@getify
getify / 1.js
Last active February 15, 2017 19:11
comparing FPO
function lowercase(v) {
return v.toLowerCase();
}
function uppercase(v) {
return v.toUpperCase();
}
var words = ["Now","Is","The","Time"];
var moreWords = ["The","Quick","Brown","Fox"];