Skip to content

Instantly share code, notes, and snippets.

View binura-g's full-sized avatar

Binura Gunasekara binura-g

  • WSO2 Inc
  • Sydney, Australia
View GitHub Profile
version: '2'
services:
nginx:
restart: always
build:
context: .
dockerfile: Dockerfile-nginx
container_name: nginx-container
ports:
- "443:443"
server {
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
server_name _;
ssl_certificate /etc/nginx/ssl/nginx.crt;
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/file.h>
#include <unistd.h>
#include <string.h>
struct record {
int userid;
char username[6];
};
kubectl run my-app — image=gcr.io/some-repo/my-app:v1 — port 3000
@binura-g
binura-g / main.js
Last active January 15, 2019 03:13
Callback Hell example
const fs = require('fs');
const file = 'sample.txt';
// Execution Starts here
// We just want to read some data from a file, update it, write it back and read it again.
// This is what it will look like with callbacks - welcome to the Callback Hell!
read(file, data => {
console.log('READ-1:', data);
// Now we'll change the text.
@binura-g
binura-g / no-func-hell.js
Last active January 29, 2018 15:11
Callback Hell without function decomposition
const fs = require('fs');
const FILE = 'sample.txt';
// Read the file for the first time and display contents
fs.readFile(FILE, 'utf8', (err, data) => {
if (err) console.log('Error:', err);
console.log(data);
// Now write 'Updated content' to the file
fs.writeFile(FILE, 'Updated content', err => {
@binura-g
binura-g / main.js
Created January 29, 2018 16:10
Promises Example 1
const fs = require("fs");
const FILE = "sample.txt";
// This function returns a promise that the 'text' we pass into
// this function has been asynchrnously written into our FILE.
const writePromise = text => {
return new Promise((resolve, reject) => {
fs.writeFile(FILE, text, err => {
if (err) reject(err);
else resolve();
@binura-g
binura-g / promiseTemplate.js
Created January 29, 2018 16:17
Promises example 2
const myPromise = new Promise((resolve, reject) => {
// do something asynchronous which eventually calls either:
//
// resolve(someValue); // when fulfilled
// or
// reject("failure reason"); // upon failure or rejection
});
@binura-g
binura-g / main.js
Last active January 15, 2019 02:32
Async and Await example 1
const fs = require("fs");
const FILE = "sample.txt";
// Writes given text to a file asynchronously.
// Returns a Promise.
function write(text) {
return new Promise((resolve, reject) => {
fs.writeFile(FILE, text, err => {
if (err) reject(err);
else resolve();
@binura-g
binura-g / ultimate-ut-cheat-sheet.md
Created April 2, 2018 03:41 — forked from yoavniran/ultimate-ut-cheat-sheet.md
The Ultimate Unit Testing Cheat-sheet For Mocha, Chai and Sinon

The Ultimate Unit Testing Cheat-sheet

For Mocha, Chai and Sinon

using mocha/chai/sinon for node.js unit-tests? check out my utility: mocha-stirrer to easily reuse test components and mock require dependencies