Skip to content

Instantly share code, notes, and snippets.

@OmisNomis
OmisNomis / Recursion-1.js
Last active March 8, 2018 13:29
Multi-dimensional Object
// Given this Object
const obj1 = {
one: 1,
two: 2,
three: { four: 4, five: { six: 6 } },
seven: 7,
eight: { nine: 9, ten: 10 },
eleven: { twelve: { thirteen: { fourteen: 14 } } },
};
@OmisNomis
OmisNomis / Recursion-2.js
Created March 8, 2018 08:33
Recursion Function
const flattenObject = object => {
let obj = {};
Object.keys(object).forEach(key => {
if (typeof object[key] !== 'object') {
obj[key] = object[key];
} else {
obj = { ...obj, ...flattenObject(object[key]) };
}
});
return obj;
@OmisNomis
OmisNomis / server.js
Created March 22, 2018 12:41
Node Express example
'use strict';
const mongoose = require('mongoose');
const morgan = require('morgan');
const bodyParser = require('body-parser');
const app = require('express')();
const port = 8000;
/** Mongoose Schema setup */
@OmisNomis
OmisNomis / goTutorial1.go
Last active March 23, 2018 09:08
Go Tutorial Series
package main
import "fmt"
// The entry point for the application is the 'main' function in the 'main' package.
// The main function must take no arguments and return no values.
func main() {
fmt.Println("Hello World")
}
@OmisNomis
OmisNomis / goTutorial2.go
Created April 9, 2018 11:26
Go Tutorial Series
package main
import (
"github.com/kataras/iris"
"github.com/kataras/iris/middleware/logger"
"github.com/kataras/iris/middleware/recover"
)
func main() {
app := iris.New()
@OmisNomis
OmisNomis / expressCluster1.js
Created April 12, 2018 10:14
Express application with Node Clustering
'use strict';
/*
* Highly scalable Express server
* Purely for example purposes, until I start the blog properly!
*/
const cluster = require('cluster');
if (cluster.isMaster) {
@OmisNomis
OmisNomis / goTutorial3.go
Last active April 15, 2018 17:16
Go Tutorial Series
package main
import (
"github.com/kataras/iris"
"github.com/kataras/iris/middleware/logger"
"github.com/kataras/iris/middleware/recover"
mgo "gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
)
@OmisNomis
OmisNomis / GoRPCTutorial1.go
Last active April 18, 2018 14:34
Go RPC Tutorial
package main
import (
"log"
)
// Make a new ToDo type that is a typed collection of fields
// (Title and Status), both of which are of type string
type ToDo struct {
Title, Status string
@OmisNomis
OmisNomis / GoRPCTutorial2.go
Created April 19, 2018 07:57
Go RPC Tutorial
package main
import (
"log"
)
// Make a new ToDo type that is a typed collection of fields
// (Title and Status), both of which are of type string
type ToDo struct {
Title, Status string
@OmisNomis
OmisNomis / GoRPCTutorial3.go
Created April 19, 2018 08:24
Go RPC Tutorial
func main() {
task := new(Task)
// Publish the receivers methods
err := rpc.Register(task)
if err != nil {
log.Fatal("Format of service Task isn't correct. ", err)
}
// Register a HTTP handler
rpc.HandleHTTP()
// Listen to TPC connections on port 1234