Skip to content

Instantly share code, notes, and snippets.

View StarpTech's full-sized avatar

Dustin Deus StarpTech

View GitHub Profile
@StarpTech
StarpTech / range-channels-backpressure.go
Created January 28, 2018 11:47
When a channel is closed sent messages are proceed until the "range" is closed
package main
import (
"fmt"
"sync"
"time"
)
func main() {
var wg sync.WaitGroup
@StarpTech
StarpTech / range-channels.go
Created January 28, 2018 11:45
When a channel is closed all buffered and blocked messages are proceed until the "range is finish
package main
import (
"fmt"
"sync"
"time"
)
func main() {
var wg sync.WaitGroup
@StarpTech
StarpTech / event-loop-examples.js
Created May 23, 2017 10:05
Great examples to understand the differences of setImmediate, setTimeout and nextTick()
/**
* setImmediate callbacks are fired off the event loop, once per iteration in the order that they were queued.
* So on the first iteration of the event loop, callback A is fired.
* Then on the second iteration of the event loop, callback B is fired, then on the third iteration of the event loop callback C is fired, etc.
* This prevents the event loop from being blocked and allows other I/O or timer callbacks to be called in the mean time (as is the case of the 0ms timeout, which is fired on the 1st or 2nd loop iteration).
*/
setImmediate(function A() {
setImmediate(function B() {
console.log(1);
@StarpTech
StarpTech / hemera-hapi.js
Last active April 22, 2017 08:51
Hemera with Hapi
'use strict'
const Hapi = require('hapi')
const server = new Hapi.Server()
server.connection({ port: 80 })
server.register({
register: require('hapi-hemera'),
options: {
@StarpTech
StarpTech / hemera.js
Last active April 5, 2017 19:05 — forked from dasheck0/hemera.js
/**
* Created by s.neidig on 15/03/17.
*/
const Hemera = require('nats-hemera');
const nats = require('nats');
const HemeraJoi = require('hemera-joi');
const connection = nats.connect('nats://0.0.0.0:4222');
const hemera = new Hemera(connection, {
@StarpTech
StarpTech / bundle-writer-example.js
Last active February 14, 2017 12:24
How to create a bundle writer in LassoJs
// ************************************
// ***** bundle-writer-example.js *****
//*************************************
var myWriter = require('./bundle-writer');
module.exports = function (myLasso, pluginConfig) {
myLasso.config.writer = myWriter(pluginConfig, myLasso.config);
};
// ****************************
var nc1 = require('../lib/nats').connect();
var nc2 = require('../lib/nats').connect();
var os = require('os')
///////////////////////////////////////
// Request Performance
///////////////////////////////////////
var start;
var loop = 100000;
var hash = 1000;
@StarpTech
StarpTech / memory-leak-pub.js
Last active January 18, 2017 19:03
Memory leak Node-Nats
var nats = require('../lib/nats').connect();
///////////////////////////////////////
// Publish Performance
//
// Setup:
// NodeJs: 6.9.2, Windows 10
///////////////////////////////////////
@StarpTech
StarpTech / transaction-builder.js
Last active December 16, 2015 16:23
Transaction Builder for Orientdb in NodeJs
/* ----------------------------Transaction Builder-------------------------------
Spec: https://github.com/orientechnologies/orientdb/wiki/SQL-batch
- Bluebird promise library
EXAMPLE:
var tx = new Transaction();
var s0 = tx.add(query1);
var s1 = tx.add(query2); //In query2 you can use the result of query1 with $0 ($<index>)
@StarpTech
StarpTech / underlyingArray.go
Last active December 15, 2015 12:58
Get the data of an Array by a Slice.
var c int = 1
intSlice := []int{100, 1, 2, 3, 4}
newSlice := intSlice[c:]
fmt.Printf("Points to the Slice %p\n",&intSlice) //0xc20005d020
fmt.Printf("Points to the first Element of the underlying Array: %d\n",&intSlice[0]) //833223995872