Skip to content

Instantly share code, notes, and snippets.

View Gaafar's full-sized avatar

Gafi (Mostafa Gaafar) Gaafar

View GitHub Profile
const makeRequest = async () => {
const data = await getJSON()
if (data.needsAnotherRequest) {
const moreData = await makeAnotherRequest(data)
console.log(moreData)
return moreData
} else {
console.log(data)
return data
}
@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

const makeRequest = () => {
return promise1()
.then(value1 => {
// do something
return promise2(value1)
.then(value2 => {
// do something
return promise3(value1, value2)
})
})
@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
const makeRequest = async () => {
try {
// this parse may fail
const data = JSON.parse(await getJSON())
console.log(data)
} catch (err) {
console.log(err)
}
}
@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 / 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);
})
}
const makeRequest = () => {
return getJSON()
.then(data => {
if (data.needsAnotherRequest) {
return makeAnotherRequest(data)
.then(moreData => {
console.log(moreData)
return moreData
})
} else {