Skip to content

Instantly share code, notes, and snippets.

@NathanKleekamp
NathanKleekamp / fib.js
Last active September 16, 2019 12:34
A recursive Fibonacci Sequence generator
const fib = (count, result = [0, 1]) => {
if (count <= 2 || count === 0) {
return result;
}
const { length } = result;
return fib(count - 1, result.concat(result[length - 1] + result[length - 2]));
};
const fib5 = fib(5) // [0, 1, 1, 2, 3]
const fib10 = fib(10) // [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
@NathanKleekamp
NathanKleekamp / sumSequence.js
Created September 6, 2019 19:05
Adding together a sequence
// With a loop O(n)
const sumSequenceLoop = (seq) => seq.reduce((accum, current) => accum + current);
console.log(sumSequenceLoop([1, 2, 3, 4])) // 10
console.log(sumSequenceLoop([2, 4, 6])) // 12
console.log(sumSequenceLoop([3, 6, 9, 12])); // 30
// With Gauss's formula O(1)
const sumSequence = (seq) => seq.length * (seq[0] + seq[seq.length - 1]) / 2;
console.log(sumSequence([1, 2, 3, 4])) // 10
console.log(sumSequence([2, 4, 6])) // 12
@NathanKleekamp
NathanKleekamp / submodules.md
Created June 16, 2019 15:55 — forked from manasthakur/submodules.md
Using git submodules to version-control Vim plugins

Using git-submodules to version-control Vim plugins

If you work across many computers (and even otherwise!), it's a good idea to keep a copy of your setup on the cloud, preferably in a git repository, and clone it on another machine when you need. Thus, you should keep the .vim directory along with your .vimrc version-controlled.

But when you have plugins installed inside .vim/bundle (if you use pathogen), or inside .vim/pack (if you use Vim 8's packages), keeping a copy where you want to be able to update the plugins (individual git repositories), as well as your vim-configuration as a whole, requires you to use git submodules.

Creating the repository

Initialize a git repository inside your .vim directory, add everything (including the vimrc), commit and push to a GitHub/BitBucket/GitLab repository:

cd ~/.vim
@NathanKleekamp
NathanKleekamp / keybase.md
Created April 24, 2019 12:54
Keybase proof

Keybase proof

I hereby claim:

  • I am nathankleekamp on github.
  • I am nkleekamp (https://keybase.io/nkleekamp) on keybase.
  • I have a public key ASDv_4O70JdjPRxKu2xc0i5F93E1IPeLEZt-EZ1SV14vzgo

To claim this, I am signing this object:

@NathanKleekamp
NathanKleekamp / README.md
Created April 10, 2019 01:48 — forked from rduplain/README.md
Code Quarterly's 2011 Q&A with Rich Hickey, by Michael Fogus

From the Archives: Code Quarterly's 2011 Q&A with Rich Hickey

Rich Hickey is frequently quoted as saying:

You can reach a point with Lisp where, between the conceptual simplicity, the large libraries, and the customization of macros, you are able to write only code that matters. And, once there, you are able to achieve a very high degree of focus, such as you would when playing Go, or playing a musical instrument, or meditating. And then, as with those activities, there can be a feeling of elation that accompanies that mental state of focus.

@NathanKleekamp
NathanKleekamp / delete-submodule.sh
Created September 1, 2018 12:00
Remove submodule
# Remove the submodule entry from .git/config
git submodule deinit -f path/to/submodule
# Remove the submodule directory from the superproject's .git/modules directory
rm -rf .git/modules/path/to/submodule
# Remove the entry in .gitmodules and remove the submodule directory located at path/to/submodule
git rm -f path/to/submodule
# Taken from https://stackoverflow.com/a/36593218
@NathanKleekamp
NathanKleekamp / rest.js
Last active September 1, 2018 11:53
A JS utility to get all but the first items in an array
// const rest = array => array.slice(1, array.length);
const rest = ([first, ...rest]) => rest
const testArray = [1, 2, 3, 4, 5];
rest(testArray) // [2, 3, 4, 5];
rest([]).length === 0; // true
Array.isArray(rest([])); // true
@NathanKleekamp
NathanKleekamp / last.js
Last active August 22, 2018 01:26
Last item from an array utility
const last = array => array.slice(-1);
const testArray = [0, 1, 2, 3];
last(testArray); // [3]
@NathanKleekamp
NathanKleekamp / isOdd.js
Created August 22, 2018 00:57
isOdd utility fn
const complement = fn => (...args) => !fn.apply(null, args);
const isEven = x => x % 2 === 0;
const isOdd = complement(isEven);
isEven(2); // false
isEven(1); // true
isEven(0); // false
@NathanKleekamp
NathanKleekamp / isEven.js
Created August 22, 2018 00:56
isEven js utility fn
const isEven = x => x % 2 === 0;
isEven(2); // true
isEven(1); // false
isEven(0); // true