Skip to content

Instantly share code, notes, and snippets.

View bensooraj's full-sized avatar

Ben Sooraj bensooraj

  • Hyderabad, India
View GitHub Profile
@bensooraj
bensooraj / main.go
Created December 8, 2020 08:10
Go Channels 1
package main
import (
"fmt"
"time"
)
func main() {
doWork := func(done <-chan interface{}, strings <-chan string) <-chan interface{} {
completed := make(chan interface{})
@bensooraj
bensooraj / mqConnectionTest_GET_LOOP.js
Created May 28, 2020 18:01
Receiving messages from IBM MQ using the mq-mqi-nodejs
// Relevant samples: https://github.com/ibm-messaging/mq-dev-patterns/tree/master/Node.js
require('dotenv').config();
console.log("Environment variables: ", process.env);
const fs = require("fs");
const mq = require('ibmmq'); // import the package containing the MQI library
const MQC = mq.MQC; // refer to constant values exported by the package.
@bensooraj
bensooraj / System Design.md
Created November 26, 2018 03:38 — forked from vasanthk/System Design.md
System Design Cheatsheet

System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?
@bensooraj
bensooraj / detectText.js
Created May 4, 2018 11:56
Text Detection | Google Cloud Vision API
// Imports the Google Cloud client library
const vision = require('@google-cloud/vision');
// Creates a client
const client = new vision.ImageAnnotatorClient();
// Uploaded image, available in base64Image format,
// is converted to a Buffer
let imageBuffer = Buffer.from(req.body.base64Image, 'base64');
// Call the Cloud Vision client, to detect text
client
@bensooraj
bensooraj / index.html
Last active April 30, 2018 01:06
Email obfuscation using CSS
<div class="contactemail" style="margin-bottom: 25px;">
@bensooraj
bensooraj / default.conf
Created March 20, 2018 10:23
default.conf | Express Application | Load Balancing
upstream node_cluster {
server 127.0.0.1:3000; # Node.js instance 1
server 127.0.0.1:3001; # Node.js instance 2
server 127.0.0.1:3002; # Node.js instance 3
}
server {
listen 80 default_server;
listen [::]:80 default_server;
@bensooraj
bensooraj / nginx.conf
Last active March 20, 2018 10:22
nginx.conf | Express Generated Application
#user nobody;
worker_processes 1;
error_log logs/error.log;
error_log logs/error.log notice;
error_log logs/error.log info;
#pid logs/nginx.pid;
@bensooraj
bensooraj / pm2.sh
Created March 20, 2018 05:47
Useful PM2 commands
# To run multiple instances of a node app run on different ports on the localhost
PORT=3001 pm2 start bin/www -f
┌──────────┬────┬──────┬──────┬────────┬─────────┬────────┬─────┬───────────┬───────────┬──────────┐
│ App name │ id │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │ user │ watching │
├──────────┼────┼──────┼──────┼────────┼─────────┼────────┼─────┼───────────┼───────────┼──────────┤
│ www │ 0 │ fork │ 4697 │ online │ 0 │ 16s │ 0% │ 34.4 MB │ Bensooraj │ disabled │
│ www │ 1 │ fork │ 4704 │ online │ 0 │ 0s │ 0% │ 13.0 MB │ Bensooraj │ disabled │
└──────────┴────┴──────┴──────┴────────┴─────────┴────────┴─────┴───────────┴───────────┴──────────┘
@bensooraj
bensooraj / index.js
Created January 1, 2018 11:52 — forked from zerbfra/index.js
node-postgres connection and query with async/await
const pg = require('pg')
// create a config to configure both pooling behavior
// and client options
// note: all config is optional and the environment variables
// will be read if the config is not present
var config = {
user: '', // env var: PGUSER
database: '', // env var: PGDATABASE
password: '', // env var: PGPASSWORD