Skip to content

Instantly share code, notes, and snippets.

Avatar
🌮
Will work for tacos

John Stewart johnstew

🌮
Will work for tacos
View GitHub Profile
@johnstew
johnstew / jagnoster.zsh-theme
Created Oct 1, 2018
Custom J Agnoster ZSH Theme
View jagnoster.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 Jul 30, 2018
timer timer timer
View timer.js
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`;
}
View async-await-7.js
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
View async-await-6.js
// Variable assignment
const getData = async () => {
try {
const data = await fakeAsyncCall();
console.log(data); // foo data
} catch (error) {
console.error(`Uh oh: ${error}`);
}
}
View async-await-5.js
// Variable Assignment
const getData = async function () {
try {
const data = await fakeAsyncCall();
console.log(data); // foo data
} catch (error) {
console.error(`Uh oh: ${error}`);
}
};
View async-await-4.js
async function getData() {
try {
const data = await fakeAsyncCall();
console.log(data); // foo data
} catch (error) {
console.error(`Uh oh: ${error}`);
}
}
View async-await-3.js
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() {
View async-await-2.js
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
}
View async-await-1.js
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 Jul 13, 2017
Exploring App State
View index.js
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;
You can’t perform that action at this time.