Skip to content

Instantly share code, notes, and snippets.

View chico's full-sized avatar

Chico Charlesworth chico

View GitHub Profile
@chico
chico / stub_exit_call.js
Created February 12, 2022 22:01
4 - Testing with sinon & mock-stdin
sinon.stub(process, 'exit')
...
assert(process.exit.called)
@chico
chico / stub_input_to_the_console.js
Created February 12, 2022 21:59
3 - Testing with sinon & mock-stdin
import mockStdin from 'mock-stdin'
const stubStdin = (input, delay) => {
let stdin = mockStdin.stdin()
setTimeout(() => stdin.send(input), delay)
}
...
stubStdin('\n', 100)
@chico
chico / spy_console.js
Last active February 12, 2022 21:58
2 - Testing with sinon & mock-stdin
const spy = sinon.spy(console, 'log')
...
assert(spy.calledWith('Hello spy'))
@chico
chico / testing_with_sinon_and_mock_stdin.md
Last active February 12, 2022 21:58
1 - Testing with sinon & mock-stdin

yarn add -D sinon mock-stdin

@chico
chico / generate_code_img.sh
Last active February 12, 2022 12:11
Generate code image from a gist URL using carbon-now-cli
wget -nv -O code ${1:-shorturl.at/bkzQ1}
yarn global add carbon-now-cli
carbon-now -h code
@chico
chico / ilovegists.js
Created February 12, 2022 11:35
I love gists
console.log('I ❤️ gists')

Hello

This is a test

const test = () => { console.log('test') }
test()

Cool ya?

@chico
chico / unsplash_access_token.txt
Created May 21, 2021 22:51
Generate OAuth access token for unsplash API
1. Go to https://unsplash.com/oauth/applications & click on your application
2. Get the access key (aka client_id) & secret key (client_secret)
3. Add http://localhost:3000/callback as a Redirect URI in the 'Redirect URI & Permissions' section
4. Tick 'Public access' and 'Read user access' and 'Write likes access' permissions
5. Click Save
@chico
chico / localStorageSize.js
Created April 11, 2019 11:07
Get the size of localStorage, copied from https://stackoverflow.com/a/15720835, execute it in the JavaScript console
var _lsTotal=0,_xLen,_x;for(_x in localStorage){ if(!localStorage.hasOwnProperty(_x)){continue;} _xLen= ((localStorage[_x].length + _x.length)* 2);_lsTotal+=_xLen; console.log(_x.substr(0,50)+" = "+ (_xLen/1024).toFixed(2)+" KB")};console.log("Total = " + (_lsTotal / 1024).toFixed(2) + " KB");
@chico
chico / firefox_osx_alias_command.sh
Last active January 11, 2019 10:02
firefox osx alias command
alias firefox="open -a Firefox 'https://www.bbc.com' && open -a Firefox 'https://flipboard.com' && open -a Firefox 'https://twitter.com' && open -a Firefox 'http://producthunt.com' && open -a Firefox 'https://blog.codinghorror.com'"