Skip to content

Instantly share code, notes, and snippets.

View Gaafar's full-sized avatar

Gafi (Mostafa Gaafar) Gaafar

View GitHub Profile
@Gaafar
Gaafar / index.js
Created November 20, 2016 08:39
Get Github repos with contributors
const bb = require('bluebird');
const axios = require('axios');
const f = require('lodash/fp');
const autheader = 'token xxx';
const fetch = (page, continuePredicate, accumulator = [] ) =>
axios.get('https://api.github.com/orgs/:org/repos', {
params: {
page,
per_page: 100
const makeRequest = () => {
return promise1()
.then(value1 => {
// do something
return Promise.all([value1, promise2(value1)])
})
.then(([value1, value2]) => {
// do something
return promise3(value1, value2)
})
const makeRequest = async () => {
await callAPromise()
await callAPromise()
await callAPromise()
await callAPromise()
await callAPromise()
throw new Error("oops");
}
makeRequest()
// this will not work in top level
// await makeRequest()
// this will work
makeRequest().then((result) => {
// do something
})
const makeRequest = async () => {
const value1 = await promise1()
const value2 = await promise2(value1)
return promise3(value1, value2)
}
@Gaafar
Gaafar / linux-server.sh
Last active May 20, 2017 21:23
machine setup
# install zsh
sudo apt-get update
sudo apt-get install zsh git -y
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
chsh -s $(which zsh)
# manual: edit theme in ~/.zshrc to "clean"
# ssh-key
ssh-keygen -t rsa
@Gaafar
Gaafar / dot-function.md
Last active July 24, 2017 04:49
dot-function

Motivation

Easy access for a property in higher order functions, enables composition & piping

Examples

const strings = ["", "a"]
const filteredStrings = strings.filter(.length) // ["a"]
@Gaafar
Gaafar / certbot-renew
Last active November 12, 2017 16:35
certbot renew cron
# cron tab
# 0 0 */5 * * /root/certbot-renew
#!/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
#old /root/certbot-auto renew
certbot renew
# don't forget chmod +x /root/certbot-renew
@Gaafar
Gaafar / curryExample.js
Last active January 7, 2018 23:24
ES6 Currying Example
function add (x, y) {return x+y}
let curry = (f, ...args) => f.bind.apply(f,[null, ...args])
let add4 = curry(add,4)
console.log(add4(5)) //9
let add4n6 = curry(add4,6)
console.log(add4n6()) //10
const makeRequest = () => {
return callAPromise()
.then(() => callAPromise())
.then(() => callAPromise())
.then(() => callAPromise())
.then(() => callAPromise())
.then(() => {
throw new Error("oops");
})
}