Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
Focusing

Waleed Ashraf WaleedAshraf

:octocat:
Focusing
View GitHub Profile
View asyncapi-example.yaml
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 Aug 19, 2019 — forked from matthiassb/dns-sync.sh
Init.d script for keeping WSL resolv.conf in-sync with Windows
View dns-sync.sh
#! /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 Apr 25, 2018
A list of Major/Notable changes in Node.js versions to help users migrate.
View nodejs-major-changes.md

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 Apr 20, 2018
Building you first Serverless app in Node.js with AWS Lambda + S3 + API Gateway
View serverless-app-5.js
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 Apr 19, 2018
Building you first Serverless app in Node.js with AWS Lambda + S3 + API Gateway
View serverless-app-4.xml
<?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 Apr 19, 2018
Building you first Serverless app in Node.js with AWS Lambda + S3 + API Gateway
View serverless-app-4.js
{
"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 Apr 20, 2018
Building you first Serverless app in Node.js with AWS Lambda + S3 + API Gateway
View serverless-app-3.js
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 Apr 20, 2018
Building you first Serverless app in Node.js with AWS Lambda + S3 + API Gateway
View serverless-app-2.js
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 Apr 20, 2018
Building you first Serverless app in Node.js with AWS Lambda + S3 + API Gateway
View serverless-app-1.js
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 Mar 25, 2018
Switching from cluster module to PM2 & RabbitMQ
View smsWorker.js
// exports RabbitMQ connection
const MQ = require('./rabbitmq-config');
MQ.on('sms', function(data) {
sendSMS(data); // use twilio or something to send sms
});
You can’t perform that action at this time.