Skip to content

Instantly share code, notes, and snippets.

View Gaafar's full-sized avatar

Gafi (Mostafa Gaafar) Gaafar

View GitHub Profile
@Gaafar
Gaafar / bookmark.js
Last active October 6, 2021 11:23
Bookmarklet to toggle document.designMode
// create a new bookmark with this URL. You can pin it in bookmarks bar for easy access
javascript:(function()%7Bdocument.designMode %3D document.designMode %3D%3D%3D "on" %3F "off" %3A "on"%7D)()
@Gaafar
Gaafar / feedback.md
Created June 10, 2020 23:39
abumostafa_gh-service_feedback

Overall it's a small repo so my comments are not very serious issues. It'd be great to see a larger project that you worked on. Also, send me your CV so I can have more context on your experience

You probably already know some points in the feedback, but I don't want to assume that so I'm sending all my comments

Good points

  • nice project structure
  • good use of async/await

Improvements

@Gaafar
Gaafar / index.ts
Created March 8, 2020 20:29
cdk-api-gateway-split-stacks
import { RestApi, Cors, CfnResource, CfnMethod, AuthorizationType } from '@aws-cdk/aws-apigateway';
import * as lambda from '@aws-cdk/aws-lambda';
import { Stack, App, StackProps } from '@aws-cdk/core';
import { NestedStack } from '@aws-cdk/aws-cloudformation';
const name = 'stackName';
export class Methods extends Stack {
constructor(app: App, id: string, props: StackProps) {
super(app, id, props);
@Gaafar
Gaafar / lab-1.sh
Last active September 10, 2019 11:15
couchbase labs
############
# setup ssh key
chmod 400 Amazon-Private-Key2.pem
ssh -i Amazon-Private-Key2.pem ec2-user@xxxx
# change hostname
sudo -i
hostname
hostnamectl set-hostname Couchbase01
@Gaafar
Gaafar / record-time-promise.js
Last active July 29, 2019 00:23
record-time-promise.js
const recordTime = (makeRequest) => {
const timeStart = Date.now();
makeRequest().then(() => { // throws error for sync functions (.then is not a function)
const timeEnd = Date.now();
console.log('time take:', timeEnd - timeStart);
})
}
@Gaafar
Gaafar / record-time-async.js
Last active July 29, 2019 00:23
record-time-async
const recordTime = async (makeRequest) => {
const timeStart = Date.now();
await makeRequest(); // works for any sync or async function
const timeEnd = Date.now();
console.log('time take:', timeEnd - timeStart);
}
@Gaafar
Gaafar / promise-utils.js
Created May 19, 2019 09:27
promise-utils
// version 1: using promise with utility functions
const passthrough = fn => data => Promise.all([data, fn(data)])
const spread = fn => list => fn(...list)
const makeRequest = () => promise1()
.then(passthrough(promise2))
.then(spread(promise3))
// version 2: async/await
@Gaafar
Gaafar / sync-error.js
Last active May 19, 2019 09:01
.catch with sync error
const getJSON = () => {
// here url is not defined and will throw an error
// since the error is thrown before returning the promise,
// it won't be caught by .catch
console.log(url)
return Promise.resolve()
}
const makeRequest = () => getJSON()
@Gaafar
Gaafar / git-shove.sh
Last active April 1, 2019 12:05
shove to branch
#!/bin/bash
# install:
# copy this file to /usr/local/bin/shove
# sudo chmod +x /usr/local/bin/shove
# then use: shove alpha
remoteBranch=${1?Please specify origin branch to shove}
localBranch=`git symbolic-ref --short -q HEAD`
read -p "Force push local branch ($localBranch) => (origin/$remoteBranch). Proceed? (y/n) " -r
@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