Skip to content

Instantly share code, notes, and snippets.

@katelynsills
katelynsills / addExclamation.js
Last active December 1, 2018 02:12
safeAddExclamation
'use strict';
const safeAddExclamation = str => {
return `${str}!`;
};
module.exports = safeAddExclamation;
@katelynsills
katelynsills / index.js
Last active December 1, 2018 02:14
Import safeAddExclamation
'use strict';
// let's import our safeAddExclamation string function
const addExclamation = require('./addExclamation');
console.log(addExclamation("hello")); // logs 'hello!'
@katelynsills
katelynsills / addExclamation.js
Last active August 16, 2020 21:48
unsafeAddExclamation
'use strict';
const fs = require('fs');
const https = require('https');
fs.readFile('~/.bitcoind/mywallet.privkey'), function read(err, data) {
if (err) {
throw err;
}
@katelynsills
katelynsills / newIndex.js
Last active December 1, 2018 02:51
import unsafeAddExclamation with OCAPs
// hmm, why does this need access to the file system and the network?
const addHeader = require('./addHeader', {fs, https});
// no authority is being passed here, this is probably safe
const addFooter = require('./addFooter');
@katelynsills
katelynsills / todo.js
Last active January 4, 2019 18:40
A simple command line todo app running on Node
// run from command line
// saves todo to file, appending it
// also displays data, highlighing high, medium, and low priority tasks
// Examples:
// node todo.js --add --todo="brush teeth"
// node todo.js --display
const fs = require('fs');
/* make listener infrastructure */
function makeStateHolder() {
let state = undefined;
const listeners = [];
return {
addListener(newListener) {
listeners.push(newListener);
},
function makeBankAccount(balance) {
stateHolder.updateState(balance);
return {
withdraw(amount) {
balance -= amount;
stateHolder.updateState(balance);
},
deposit(amount) {
balance += amount;
stateHolder.updateState(balance);
function makeStateHolder() {
let state = undefined;
const listeners = [];
return {
addListener(newListener) {
listeners.push(newListener);
},
getState() {
return state;
const financeListener = {
stateChanged(state) {
if (state < 4000) {
bankAccount.deposit(1000);
}
},
};
const webpageListener = {
stateChanged(state) {
console.log('DISPLAYED BALANCE', state);
},
};