Skip to content

Instantly share code, notes, and snippets.

View WaleedAshraf's full-sized avatar
:octocat:
Focusing

Waleed Ashraf WaleedAshraf

:octocat:
Focusing
View GitHub Profile
asyncapi: '2.0.0-rc2'
id: 'urn:demo'
info:
title: Demo
version: '1.0'
channels:
userEvents:
description: User Events Channel
publish:
summary: Publish User related events
@WaleedAshraf
WaleedAshraf / dns-sync.sh
Created August 19, 2019 14:41 — forked from matthiassb/dns-sync.sh
Init.d script for keeping WSL resolv.conf in-sync with Windows
#! /bin/bash
### BEGIN INIT INFO
# Provides: dns-sync
# Required-Start:
# Required-Stop:
# Default-Start: S
# Default-Stop:
# Short-Description: Synchronizes /etc/resolv.conf in WLS with Windows DNS - Matthias Brooks
### END INIT INFO
@WaleedAshraf
WaleedAshraf / nodejs-major-changes.md
Last active April 25, 2018 16:36
A list of Major/Notable changes in Node.js versions to help users migrate.

Version 5.0.0

  • buffer: (Breaking) Removed both 'raw' and 'raws' encoding types from Buffer, these have been deprecated for a long time (Sakthipriyan Vairamani) #2859.
  • console: (Breaking) Values reported by console.time() now have 3 decimals of accuracy added (Michaël Zasso) #3166.
  • fs:
    • fs.readFile*(), fs.writeFile*(), and fs.appendFile*() now also accept a file descriptor as their first argument (Johannes Wüller) #3163.
    • (Breaking) In fs.readFile(), if an encoding is specified and the internal toString() fails the error is no longer thrown but is passed to the callback (Evan Lucas) #3485.
  • (Breaking) In fs.read() (using the fs.read(fd, length, position, encoding, callback) form), if the internal toString() fails the error is no longer thrown but is passe
@WaleedAshraf
WaleedAshraf / serverless-app-5.js
Last active April 20, 2018 20:56
Building you first Serverless app in Node.js with AWS Lambda + S3 + API Gateway
const im = require('imagemagick');
const fs = require('fs');
const AWS = require('aws-sdk');
const s3 = new AWS.S3();
exports.handler = async (event) => {
const operation = event.queryStringParameters ? event.queryStringParameters.operation : null;
let data = JSON.parse(event.body);
switch (operation) {
case 'ping':
@WaleedAshraf
WaleedAshraf / serverless-app-4.xml
Created April 19, 2018 13:02
Building you first Serverless app in Node.js with AWS Lambda + S3 + API Gateway
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>HEAD</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>Authorization</AllowedHeader>
@WaleedAshraf
WaleedAshraf / serverless-app-4.js
Created April 19, 2018 13:00
Building you first Serverless app in Node.js with AWS Lambda + S3 + API Gateway
{
"Version": "2012-10-17",
"Id": "Policy1522618459372",
"Statement": [
{
"Sid": "Stmt1522618452845",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:*",
"Resource": "arn:aws:s3:::foobucketlambda/*"
@WaleedAshraf
WaleedAshraf / serverless-app-3.js
Last active April 20, 2018 20:57
Building you first Serverless app in Node.js with AWS Lambda + S3 + API Gateway
const im = require('imagemagick');
const fs = require('fs');
exports.handler = async (event) => {
const operation = event.queryStringParameters ? event.queryStringParameters.operation : null;
let data = JSON.parse(event.body);
switch (operation) {
case 'ping':
return sendRes(200, 'pong');
case 'convert':
@WaleedAshraf
WaleedAshraf / serverless-app-2.js
Last active April 20, 2018 20:58
Building you first Serverless app in Node.js with AWS Lambda + S3 + API Gateway
exports.handler = async (event) => {
const operation = event.queryStringParameters ? event.queryStringParameters.operation : null;
let data = JSON.parse(event.body);
switch (operation) {
case 'ping':
return sendRes(200, 'pong');
case 'convert':
return await operate(data);
default:
return sendRes(401, `Unrecognized operation "${operation}"`);
@WaleedAshraf
WaleedAshraf / serverless-app-1.js
Last active April 20, 2018 20:58
Building you first Serverless app in Node.js with AWS Lambda + S3 + API Gateway
exports.handler = async (event) => {
return sendRes(200,'Hello');
};
const sendRes = (status, body) => {
var response = {
statusCode: status,
headers: {
"Content-Type": "text/html"
},
@WaleedAshraf
WaleedAshraf / smsWorker.js
Created March 25, 2018 19:04
Switching from cluster module to PM2 & RabbitMQ
// exports RabbitMQ connection
const MQ = require('./rabbitmq-config');
MQ.on('sms', function(data) {
sendSMS(data); // use twilio or something to send sms
});