Skip to content

Instantly share code, notes, and snippets.

View ivan-marquez's full-sized avatar

Jose Ivan Marquez ivan-marquez

View GitHub Profile
@ivan-marquez
ivan-marquez / tessel_vx.x.x.js
Created June 24, 2018 00:06
Flow typed definitions for Tessel projects.
// flow-typed signature: 41c26b1157e954a0cd4ce3efa2131537
// flow-typed version: <<STUB>>/tessel_v^2.0.0/flow_v0.75.0
/**
* This is an autogenerated libdef stub for:
*
* 'tessel'
*
* Fill this stub out by replacing all the `any` types.
*
@ivan-marquez
ivan-marquez / reactor.js
Created October 22, 2018 14:56 — forked from mohsen1/reactor.js
Reactor Pattern in JavaScript
function Event(name){
this.name = name;
this.callbacks = [];
}
Event.prototype.registerCallback = function(callback){
this.callbacks.push(callback);
}
function Reactor(){
this.events = {};
@ivan-marquez
ivan-marquez / scroll-to-bottom.js
Created January 7, 2019 11:41
Detect when scroll reaches bottom of window.
export function scrolledToBottom(window, marginFromBottom = 0) {
const documentBody = window.document.body;
const documentElement = window.document.documentElement;
const scrollTop =
(documentElement && documentElement.scrollTop) || documentBody.scrollTop;
const scrollHeight =
(documentElement && documentElement.scrollHeight) ||
documentBody.scrollHeight;
@ivan-marquez
ivan-marquez / monitor.js
Created March 8, 2019 12:55
monitor the processing time of any functions
module.exports = (start, tag) => {
if (start) {
let endTime = process.hrtime(start)
let duration = parseInt((endTime[0] * 1000) + (endTime[1] / 1000000))
console.log(`Duration for ${tag}: ${duration} msec`)
} else {
return process.hrtime()
}
}
@ivan-marquez
ivan-marquez / bdd.json
Created June 13, 2019 20:35
VS Code snippet for BDD unit test with Jest
{
"BDD Unit Test": {
"prefix": "bdd",
"body": [
"describe('Given $1', () => {",
" afterEach(() => {",
" jest.resetAllMocks();",
" });",
" describe('when $2', () => {",
" test('then $3', async () => {",
@ivan-marquez
ivan-marquez / polling.js
Last active February 3, 2024 00:13
Long polling implementation in Js
const axios = require('axios').default;
function getAPIClient() {
const axiosConfig = {
baseURL: 'https://csrng.net/csrng/csrng.php',
timeout: 5000,
};
return axios.create(axiosConfig);
}
@ivan-marquez
ivan-marquez / online_checker.go
Last active July 24, 2019 19:26
Simple goroutines and channels implementation for concurrent processing.
/*
* Package statuschecker checks the status of a given url and prints the online status
* to the console.
*/
package main
import (
"fmt"
"net/http"
@ivan-marquez
ivan-marquez / user_test.go
Created September 8, 2019 01:01 — forked from wrunk/user_test.go
Golang unit test for panic scenario
func TestUserFail(t *testing.T) {
func() {
defer func() {
if r := recover(); r == nil {
t.Errorf("TestUserFail should have panicked!")
}
}()
// This function should cause a panic
CreateUser(12, "hello")
@ivan-marquez
ivan-marquez / awsgobuild.sh
Created October 19, 2019 20:53
Bash script to build AWS Lambda functions in Go
export GO111MODULE=on
env GOOS=linux go build -ldflags="-s -w" -o main
zip main.zip main
@ivan-marquez
ivan-marquez / BabylonjsVisual.ts
Created December 6, 2020 02:24 — forked from AndyCross/BabylonjsVisual.ts
Use BabylonJS in PowerBI
declare module BABYLON {
export class Engine {
constructor(canvas:HTMLElement, antialias:boolean);
runRenderLoop(it:any);
resize();
}
export class Scene {
constructor(engine:Engine);
render();
}