Skip to content

Instantly share code, notes, and snippets.

View khaledosman's full-sized avatar
🤘

Khaled Osman khaledosman

🤘
View GitHub Profile
@khaledosman
khaledosman / firebase-cloud-messaging.js
Last active October 8, 2019 09:58
Firebase Cloud Messaging Push Notifications Server Setup
const { google } = require('googleapis')
const axios = require('axios')
const firebaseServiceAccount = {
type: '',
project_id: '',
private_key_id: '',
private_key: '',
client_email: '',
client_id: '',
@khaledosman
khaledosman / launch.json
Created September 26, 2019 10:22
VSCode debugging configuration for serverless-offline plugin
{
"configurations": [
{
"name": "Lambda",
"type": "node",
"request": "launch",
"runtimeArgs": ["--inspect", "--debug-port=9229"],
"program": "${workspaceFolder}/node_modules/serverless/bin/serverless",
"args": ["offline"],
"port": 9229,
@khaledosman
khaledosman / apollo-server-graphql-serverless-lambda-handler.js
Created September 23, 2019 16:26
Graphql Setup in a serverless AWS Lambda
const { ApolloServer, gql } = require('apollo-server-lambda')
const { resolvers } = require('../graphql/resolvers')
const responseCachePlugin = require('apollo-server-plugin-response-cache')
// Construct a schema, using GraphQL schema language
const typeDefs = gql`
type Query {
hello: String
}
`
@khaledosman
khaledosman / serverless.yml
Created September 19, 2019 11:55
production ready serverless template
service:
name: <serviceName>
app: <serverless dashboard app name>
org: <serverless dashboard org name>
custom:
aws_profile: <aws profile>
warmup:
enabled: true
https://www.azurefromthetrenches.com/azure-functions-vs-aws-lambda-scaling-face-off/
https://www.azurefromthetrenches.com/azure-functions-significant-improvements-in-http-trigger-scaling/
@khaledosman
khaledosman / create-inline-webworker.js
Created August 13, 2019 11:46
creates web worker
function createWebWorker (func) {
// Build a worker from an anonymous function body
const blobURL = URL.createObjectURL(new Blob(['(',
func.toString(),
')()'], { type: 'application/javascript' }))
const worker = new Worker(blobURL)
@khaledosman
khaledosman / chunk-promise-execution.ts
Last active March 6, 2020 15:40
chunked / batched promise execution
export function runInSeries (funcs: Array<() => Promise<any>>): Promise<any> {
const results = []
return funcs.reduce((accumulator, f) => accumulator.then(async () => {
const result = await f()
results.push(result)
return results
}), Promise.resolve())
}
export function runInParallel (funcs: Array<() => Promise<any>>): Promise<any[]> {
@khaledosman
khaledosman / update-versions.js
Created June 26, 2019 11:43
updates android and ios app versions based on package.json
const fs = require('fs');
const pad = require('pad');
fs.readFile('./package.json', 'utf8', (packageErr, packageJson) => {
const json = JSON.parse(packageJson);
const version = json.version;
const v = version.split('.');
const versionCodeString = `${v[0]} ${pad(3, v[1], '0')} ${pad(4, v[2], '0')}`;
const versionCodeNumber = parseInt(versionCodeString.replace(/ /g, ''), 10);
@khaledosman
khaledosman / filterObjectByKeys.js
Created June 24, 2019 12:28
Function to filter an object and return specific keys only
function _filterObjectByKeys (object, keys) {
console.log({ object, keys })
return Object.keys(object).reduce((accum, key) => {
if (keys.includes(key)) {
return { ...accum, [key]: object[key] }
} else {
return accum
}
}, {})
}