Skip to content

Instantly share code, notes, and snippets.

@johnstew
johnstew / jagnoster.zsh-theme
Created October 1, 2018 18:03
Custom J Agnoster ZSH Theme
# vim:ft=zsh ts=2 sw=2 sts=2
#
# agnoster's Theme - https://gist.github.com/3712874
# A Powerline-inspired theme for ZSH
#
# # README
#
# In order for this theme to render correctly, you will need a
# [Powerline-patched font](https://github.com/Lokaltog/powerline-fonts).
# Make sure you have a recent version: the code points that Powerline
@johnstew
johnstew / timer.js
Created July 30, 2018 15:50
timer timer timer
class Timer {
constructor(duration) {
const initDuration = (duration || 1) * 60;
this.initDuration = initDuration;
this.duration = initDuration;
this.intervalId = -1;
this.interval = 1000;
this.displayDuration = `${duration}:00`;
}
class Foo {
async getData() {
try {
const f1 = await this.fakeAsyncCall();
const f2 = await this.fakeAsyncCall();
const f3 = await this.fakeAsyncCall();
const f4 = await this.fakeAsyncCall();
console.log(f1, f2, f3, f4); // 'foo data' x 4
// Variable assignment
const getData = async () => {
try {
const data = await fakeAsyncCall();
console.log(data); // foo data
} catch (error) {
console.error(`Uh oh: ${error}`);
}
}
// Variable Assignment
const getData = async function () {
try {
const data = await fakeAsyncCall();
console.log(data); // foo data
} catch (error) {
console.error(`Uh oh: ${error}`);
}
};
async function getData() {
try {
const data = await fakeAsyncCall();
console.log(data); // foo data
} catch (error) {
console.error(`Uh oh: ${error}`);
}
}
function fakeAsyncCall(resultText = 'foo data') {
return new Promise((resolve, reject) => {
if (typeof resultText !== 'string') {
return reject('result text should equal string');
}
setTimeout(() => { resolve(resultText) }, 1000);
});
}
async function getData() {
async function getData() {
const f1 = await fakeAsyncCall();
const f2 = await fakeAsyncCall();
const f3 = await fakeAsyncCall();
const f4 = await fakeAsyncCall();
console.log(f1, f2, f3, f4); // 'foo data' x 4
}
function fakeAsyncCall(resultText = 'foo data') {
return new Promise((resolve) => {
setTimeout(() => resolve(resultText), 1000);
});
}
function getData() {
fakeAsyncCall()
.then(fakeAsyncCall)
.then(fakeAsyncCall)
@johnstew
johnstew / index.js
Created July 13, 2017 20:31
Exploring App State
function equal(objA, objB) {
const sObjA = JSON.stringify(objA);
const sObjB = JSON.stringify(objB);
return (sObjA === sObjB);
}
class AppState {
constructor(state = {}, components = []) {
this.state = state;
this.components = components;