Skip to content

Instantly share code, notes, and snippets.

samzhao

Block or report user

Report or block samzhao

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@samzhao
samzhao / index.js
Last active Jun 30, 2018
Usage of delayedMap helper
View index.js
const toListItem = async item => {
const { thing } = await sendRequest();
return thing;
};
const delayTime = 100;
const items = delayedMap(listOfStuff, toListItem, delayTime);
@samzhao
samzhao / index.js
Created Jun 30, 2018
Delayed map helper
View index.js
const delayedMap = async (list, iterator, delayTime) => {
let promises = [];
for (const item of list) {
await delay(delayTime);
promises.push(await iterator(item));
}
return Promise.all(promises);
};
@samzhao
samzhao / index.js
Created Jun 30, 2018
Making async/await delay helper work in a loop
View index.js
const delay = time =>
new Promise(resolve => setTimeout(resolve, time));
const list = new Array(10).fill();
for (let index of list.keys()) {
await delay(1000);
console.log(index);
}
@samzhao
samzhao / index.js
Created Jun 30, 2018
Bad example of using async/await for delaying calls in a loop
View index.js
const delay = time =>
new Promise(resolve => setTimeout(resolve, time));
const list = new Array(10).fill();
list.forEach(async (_, index) => {
await delay(1000);
console.log(index);
});
@samzhao
samzhao / index.js
Created Jun 30, 2018
Delay with async/await
View index.js
const delay = time =>
new Promise(resolve => setTimeout(resolve, time));
const sendRequest = async () => {
await delay(1000);
return axios.get(API_URL);
}
// request fires after 1 second
sendRequest();
@samzhao
samzhao / index.js
Last active Jun 30, 2018
Simple Async/await Example
View index.js
import axios from 'axios';
const API_URL = "https://jsonplaceholder.typicode.com/posts/1";
// Before async/await
const logPostId = () => {
axios.get(API_URL)
.then(resp => {
const { data } = resp;
const { id } = data;
View .irbrc
# load libraries
require 'rubygems' rescue nil
require 'wirble'
#require 'json'
alias q exit
class Object
def local_methods
(methods - Object.instance_methods).sort
View .tmux.conf
set-option -g default-shell /bin/zsh
set-option -g default-terminal "screen-256color"
set-option -g base-index 1
setw -g pane-base-index 1
set-option -g xterm-keys on
setw -g aggressive-resize on
set -s escape-time 0
View .zshrc
# Path to your oh-my-zsh installation.
export ZSH=$HOME/.oh-my-zsh
export EDITOR='vim'
source ~/.bin/tmuxinator.zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
View .vimrc
syntax enable
colorscheme monokai
set tabstop=2
set softtabstop=2
set expandtab
set smarttab
set number
set showcmd
set cursorline
You can’t perform that action at this time.