Skip to content

Instantly share code, notes, and snippets.

View StarpTech's full-sized avatar

Dustin Deus StarpTech

View GitHub Profile
@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 / 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 / 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
"use strict";
const _ = require("lodash");
function groupByTimeWindow(start, end) {
return function(o) {
const date = new Date(o.timestamp);
if (date.getUTCHours() >= start && date.getUTCHours() <= end)
return o.consumption_Wh;
return 0;
@StarpTech
StarpTech / arangodb.js
Last active April 11, 2018 09:24
Manage Multi-Tenancy in Arangojs
// initialize
// The maximum number of requests is equal to
// maxSockets * 2 with keepAlive: true or equal to maxSockets with keepAlive: false.
const arangodb = new Arangojs.Database({
url: "http://localhost:8529", // Base URL of the ArangoDB server or list of server URLs.
agentOptions: {
maxSockets: 100,
keepAlive: true
},
loadBalancingStrategy: 'ROUND_ROBIN'
@StarpTech
StarpTech / fab.ts
Last active October 29, 2018 12:10
Small library to validate numeric data structures in a functional-style
/**
* Small library to validate numeric data structures in a functional-style
* All functions are right associative
* If you are looking for more sophisticated features have a look at
* https://ramdajs.com/
*/
export interface FabPattern {
[index: string]: (input: number) => boolean;
}
@StarpTech
StarpTech / graphql-caching.md
Last active November 4, 2018 18:48
Notes about Caching in GraphQL

Graphql cache challenges

How to practice HTTP Caching?

GraphQL queries are usually POST requests. POST request aren't cached by nature. This means that we need different solutions to deliver our content efficiently.

@StarpTech
StarpTech / redis-cache-service.js
Last active April 15, 2021 16:26
Simple Redis Cache Client for Node.js
'use strict';
const assert = require('assert');
/**
* The redis client is https://github.com/luin/ioredis
*/
/*
const redisClient = new Redis({
@StarpTech
StarpTech / react-hooks-axios.js
Created June 3, 2019 22:03
React Hooks Axios Client
// Inspired by https://www.robinwieruch.de/react-hooks-fetch-data/
const dataFetchReducer = (state, action) => {
switch (action.type) {
case 'REQUEST_INIT':
return { ...state, isLoading: true, isError: false };
case 'REQUEST_SUCCESS':
return { ...state, isLoading: false, isError: false, data: action.payload };
case 'REQUEST_FAILURE':
return { ...state, isLoading: false, isError: true };
@StarpTech
StarpTech / docker-compose.cypress.yml
Last active December 7, 2020 03:54
Generate Github Actions Workflow to run Cypress Tests in parallel (with artifact support + Basic Auth)
version: '3.4'
services:
cypress:
container_name: 'cypress-e2e'
image: 'cypress/included:3.4.1'
working_dir: /e2e
volumes:
- .:/e2e
environment: