Skip to content

Instantly share code, notes, and snippets.

View chrisdothtml's full-sized avatar
🙂

Chris Deacy chrisdothtml

🙂
View GitHub Profile
@chrisdothtml
chrisdothtml / JupyterPageFollower.user.js
Last active May 31, 2023 18:24
jupyter notebook page follower
// ==UserScript==
// @name jupyter notebook page follow
// @namespace http://tampermonkey.net/
// @version 0.3
// @description Add 'page follow' feature to jupyter notebook pages
// @author Chris Deacy
// @match http*://*/notebook*/*
// @downloadURl https://gist.github.com/chrisdothtml/51c2b5ca2dc9c498fe27d0d464b47801/raw/JupyterPageFollower.user.js
// @updateURl https://gist.github.com/chrisdothtml/51c2b5ca2dc9c498fe27d0d464b47801/raw/JupyterPageFollower.user.js
// @grant none
#!/bin/bash
# ------------------------------------------------------------
# Import a shell script from a relative path
# Usage: import <path>
# ------------------------------------------------------------
function import() {
local args=($@)
local relative_path=${args[-1]}
local res=(`caller 0`)
@chrisdothtml
chrisdothtml / octave.md
Created August 25, 2019 02:24 — forked from obstschale/octave.md
An Octave introduction cheat sheet.

Octave CheatSheet

GNU Octave is a high-level interpreted language, primarily intended for numerical computations.
(via GNU Octave)

Basics

  • not equal ~=
  • logical AND &amp;&amp;
@chrisdothtml
chrisdothtml / get-issue-refs.js
Created August 14, 2019 19:07
Get fixed issue references from GitHub pull request body
/*
* Get fixed issue references from GitHub pull request body
*/
function getIssueRefs(pullRequestBody, defaultRepoName) {
// ref: https://help.github.com/en/articles/closing-issues-using-keywords
const keywords = 'close|closed|closes|fix|fixed|fixes|resolve|resolved|resolves';
// ref: https://help.github.com/en/articles/autolinked-references-and-urls#issues-and-pull-requests
const refTypes = [
// #000
'#',
@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

@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))
})
}
/*
* 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 / 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)
@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 / 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