Skip to content

Instantly share code, notes, and snippets.

View subhog's full-sized avatar

Hubert OG subhog

View GitHub Profile
@subhog
subhog / loop.js
Created October 8, 2020 07:52
Async loop example
const CHANGE = true;
let calculate = () => {
return new Promise((resolve) => {
setTimeout(() => {
resolve(5)
}, 100);
})
}
@subhog
subhog / switchByMap.ts
Last active March 25, 2020 13:17
Showcasing DistinctElements and SwitchByMap RX operators
import { red, yellow } from "chalk";
import { differenceWith, isEqual } from "lodash";
import { Observable, of, Subject } from "rxjs";
import {
concatMap, delay, groupBy, map, mergeMap, scan, switchMap,
} from "rxjs/operators";
/*
Transform stream of arrays into stream of distinct elements
@subhog
subhog / useImmer.js
Created January 20, 2020 21:04
The simplest useImmer hook
import { useReducer } from "react";
import produce from "immer";
export default (initialState) => (
/*
First, we need to apply the `useReducer` hook.
React reducer signature is `(state, action)`, where `state` is the current state
and `action` is the argument provided to the `set` method.
In our case, `action` is just the `producer` method we'll pass to immer.
@subhog
subhog / flatten.js
Last active August 30, 2016 10:24
Flatten array exercise (JS)
// See live demo: https://repl.it/DCWZ
// Flatten array exercise
// Hubert Orlik–Grzesik
// hubert@orlikarnia.com
// 2016C
// Of course, in real-life environment I would write:
//
@subhog
subhog / install.js
Last active August 29, 2015 14:11
impact-dev
var Term = {
BLACK: '\033[30m',
RED: '\033[31m',
GREEN: '\033[32m',
YELLOW: '\033[33m',
BLUE: '\033[34m',
MAGENTA: '\033[35m',
CYAN: '\033[36m',
WHITE: '\033[37m',
GRAY: '\033[38m',
#!/bin/bash
if [ ! -e $HOME/.meteor ];
then
sudo curl https://install.meteor.com/ | sh
fi
sudo apt-get update
sudo apt-get install -y python-software-properties
sudo add-apt-repository ppa:chris-lea/node.js
@subhog
subhog / nextAnywhere.js
Last active August 29, 2015 13:57
Find next (or previous) matching element in the DOM, wherever it is in the tree.
(function($) {
var getNext = function(item) {
if(item.length === 0) return null;
if(item.next().length > 0) return item.next();
return getNext(item.parent());
};
var getPrev = function(item) {
if(item.length === 0) return null;
if(Meteor.isServer) {
Nodetime.profile({
accountKey: '...',
appName: '...',
debug: true,
mongodbMetrics: true,
});