Skip to content

Instantly share code, notes, and snippets.

View chrisdothtml's full-sized avatar
🙂

Chris Deacy chrisdothtml

🙂
View GitHub Profile
@chrisdothtml
chrisdothtml / keybindings.json5
Last active May 12, 2018 20:14
VS Code config files
[
{
"key": "cmd+y",
"command": "redo",
"when": "editorTextFocus && !editorReadonly"
},
{
"key": "shift+alt+down",
"command": ""
},
@chrisdothtml
chrisdothtml / config.json
Last active April 29, 2017 20:06
Sample for gist-perf
{
"iterations": 100
}
@chrisdothtml
chrisdothtml / sieve-of-eratosthenes.js
Last active June 29, 2018 13:00
Generate prime numbers
/**
* Generate Set of prime numbers up to `maxPrime`
* https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
*
* @param {Number} maxPrime
* @returns {Set}
*/
function getPrimes (maxPrime) {
const sieve = new Map
const result = new Set
@chrisdothtml
chrisdothtml / fibonacci.js
Last active June 15, 2018 02:03
Generate fibonacci sequence
/**
* Generate fibonacci sequence up to `maxNum`
* https://en.wikipedia.org/wiki/Fibonacci_number
*
* @param {number} maxNum
*/
function fibonacci (maxNum) {
const result = [0, 1]
let newNum, index
@chrisdothtml
chrisdothtml / recaman.js
Created June 15, 2018 02:03
Generate Recamán sequence
/**
* Generate Recamán sequence up to `maxNum`
* https://youtu.be/FGC5TdIiT9U
*
* @param {Number} maxNum
* @returns {Set}
*/
function recaman (maxNum) {
const result = new Set([0])
let current, hop
@chrisdothtml
chrisdothtml / get-factors.js
Last active June 29, 2018 12:22
Get all factors of a number
/**
* Get all factors of a number
*
* @param {Number} num
* @returns {Set}
*/
function getFactors (num) {
const numRoot = Math.sqrt(num)
const isEven = num % 2 === 0
const incr = isEven ? 1 : 2
@chrisdothtml
chrisdothtml / perfect-number.js
Created June 29, 2018 12:25
Perfect number checker
/**
* Indicates whether the sum of the factors of a number
* are equal to the number
* https://en.wikipedia.org/wiki/Perfect_number
*
* @param {Number} num
* @returns {Boolean}
*/
function isPerfectNumber (num) {
const numRoot = Math.sqrt(num)
/*
* Calculate the persistence of a number;
* based on Numberphile video:
* https://www.youtube.com/watch?v=Wim9WJeDTHQ
*/
function calculatePersistence (num) {
let result = 1
while ((num = multiplyItems(getDigits(num))) > 0)
result++
return result
@chrisdothtml
chrisdothtml / cli.js
Created April 15, 2019 22:51
Get piped input in nodejs script
function getPipedInput () {
return new Promise(resolve => {
let result = ''
process.stdin.resume()
process.stdin.setEncoding('utf8')
process.stdin.on('data', chunk => (result += chunk))
process.stdin.on('end', () => resolve(result))
})
}
@chrisdothtml
chrisdothtml / readme.md
Last active May 8, 2019 19:27
Simple CLI to switch between npmrc configs

Setup

1. Download script

curl https://gist.githubusercontent.com/chrisdothtml/509fdbe3bfec1a11bbc346e4b44c3604/raw/switch-npmrc.js > "$HOME/switch-npmrc.js"

2. Add alias to .bash_profile or similar