Skip to content

Instantly share code, notes, and snippets.

@eliasmalik
eliasmalik / cw-scraper.gs
Created May 3, 2020 22:36
codewars-scraper
function insert(val, i, xs) {
return xs.slice(0, i).concat(val).concat(xs.slice(i));
}
function validateURL(url) {
return !url.match('codepen');
}
function fetch(url) {
var response = UrlFetchApp.fetch(url);
@eliasmalik
eliasmalik / pipePWithUndos.md
Last active August 25, 2019 14:47
Piped promise-returning functions with undo steps

Problem

I want a function to pipe together a series of promise returning functions. However, I also want to specify an undo function for each piped function. If any function returns a rejected promise, the undo function corresponding to that step should be called.

I'm free to let my undo function return a resolved promise, which indicates a recovery and continues down the pipe, or a rejected promise, which results in breaking the promise chain and skipping to the catch statement (if any).

Based on this SO answer, this is the form of the solution if you know how many steps you have:

steps[1]
  .then(
 (...args) => steps[2](...args).then(null, undos[2]),
@eliasmalik
eliasmalik / limited_streamed_data.js
Last active March 7, 2019 23:57
Sketch for G1 to stream lots of data from one place (twilio) to disk
var accountSid = 'ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; // Your Account SID from www.twilio.com/console
var authToken = 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz'; // Your Auth Token from www.twilio.com/console
var client = require('twilio')(accountSid, authToken);
const fs = require('fs');
const path = require('path');
const axios = require('axios');
const async = require('async');
var tasks = [];
const BASE_URL = 'https://api.twilio.com/';
@eliasmalik
eliasmalik / .zshrc
Created March 26, 2017 16:39
Zsh config
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
####
#### oh-my-zsh setup
####
# Path to your oh-my-zsh installation.
export ZSH=/Users/elias/.oh-my-zsh
@eliasmalik
eliasmalik / init.zsh
Last active October 16, 2017 15:36
Initialise fresh OSX install
#!/usr/bin/env zsh
## Manual
# install Firefox, Chrome, VLC, 1password, Wunderlist, SourceTree, Spectacle
# Atom, iTerm2, Dash, Pocket, LittleFlocker, LittleSnitch, Keybase
## Auto
echo "##### install brew #####\n"
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Keybase proof

I hereby claim:

  • I am eliascodes on github.
  • I am eliascodes (https://keybase.io/eliascodes) on keybase.
  • I have a public key ASB8zjqKLY2kRS8JzVH29wxgMVHBIhwrc5QW_yqVr0K9mAo

To claim this, I am signing this object:

@eliasmalik
eliasmalik / ggi.sh
Created June 14, 2016 18:05
Download Github gitignore and paste it into current directory
#!/usr/bin/env bash
function ggi {
domain="https://raw.githubusercontent.com"
path="/github/gitignore/master/${1^}.gitignore"
file=$(curl ${domain}${path})
target=$(pwd)/.gitignore
touch ${target}
echo "$file" > ${target}