Skip to content

Instantly share code, notes, and snippets.

@mstaicu
mstaicu / init.vim
Last active January 14, 2021 12:38
Neovim draft configuration file
"Variables {{{
let mapleader=","
" }}}
" Globals {{{
syntax enable
set fileencoding=utf-8
set listchars=space:· " show whitespaces as dots
@mstaicu
mstaicu / Flow.js
Created February 18, 2019 11:35
Promise composition for async control flow
function retry(fn) {
return function(data) {
return new Promise((resolve, reject) => {
var retries = 10,
error;
function attempt() {
if (retries === 0) {
reject(error);
}
@mstaicu
mstaicu / event-loop.md
Created February 12, 2018 20:23 — forked from jesstelford/event-loop.md
What is the JS Event Loop and Call Stack?

Regular Event Loop

This shows the execution order given JavaScript's Call Stack, Event Loop, and any asynchronous APIs provided in the JS execution environment (in this example; Web APIs in a Browser environment)


Given the code

@mstaicu
mstaicu / LoadingEnhancer.js
Last active July 13, 2017 12:30
Loading enhancer Higher-order Component
import React from 'react';
export default function(LoadingComponent, WrappedComponent) {
return function(props) {
return (
{
(props.status === 'LOADING') ? <LoadingComponent /> : <WrappedComponent {...props.data} />
}
)
};
@mstaicu
mstaicu / AnalyticsHOC.js
Last active July 15, 2019 07:49
A React Higher-order Component for sending analytics based on the original post of David Tang for DailyJS
import React from 'react';
export default function(mapPropsToData, WrappedComponent) {
return function(props) {
function onClick(event) {
if (event.target.tagName === 'A') {
const data = mapPropsToData ? mapPropsToData(props) : {};
// Process data
}