Skip to content

Instantly share code, notes, and snippets.

View smnh's full-sized avatar

Simon Hanukaev smnh

View GitHub Profile
@smnh
smnh / markdownify.js
Created December 8, 2020 13:00
Using shortcodes with marked
import React from 'react';
import ReactHtmlParser from 'react-html-parser';
import marked from 'marked';
import _ from 'lodash';
import withPrefix from './withPrefix';
const ShortCodes = {
figure: function(attrs) {
@smnh
smnh / promiseAllPool.js
Created November 22, 2017 15:24
Promise all with pool of concurrent promises
/**
* Like Promise.all(), this method resolves if all promises returned by invoking the "callback" are resolved, or rejects
* if at least one of these promises is rejected. This method ensures that only "poolSize" number of promises are
* executed at the same time. The "total" parameter specifies the number of total promises that need to be executed,
* therefore, the "callback" will be invoked "total" number of times. The "callback" is invoked with a single "index"
* parameter specifying the index of the invocation.
*
* @example
* let items = [...]
@smnh
smnh / flattenData.js
Last active December 25, 2023 07:52
Function for flattening data before indexing it to Elasticsearch (http://smnh.me/indexing-and-searching-arbitrary-json-data-using-elasticsearch)
const _ = require('lodash');
module.exports = {
flattenData
};
/**
* This function flattens objects by converting them into a flat array of objects having four fields:
* - "key": the path of the field in the original object
* - "type": the type of the field value
@smnh
smnh / synchronizing-rotation-animation-part-2.m
Last active July 29, 2021 08:00
Synchronizing rotation animation between the keyboard and the attached view - Part 2
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(keyboardWillChangeFrame:)
name:UIKeyboardWillChangeFrameNotification object:nil];
}
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
@smnh
smnh / synchronized-keyboard-view-rotation-animation-between.m
Last active August 29, 2015 13:58
Synchronizing rotation animation between the keyboard and the attached view
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter]
addObserver:self selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter]
addObserver:self selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification object:nil];
}
@smnh
smnh / web-font-loading-detection-without-timers.html
Created April 9, 2014 22:25
Web font loading detection, without timers
<!DOCTYPE html>
<html>
<head>
<link href="http://fonts.googleapis.com/css?family=Skranji" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="wrapper" style="position:absolute; overflow:hidden;">
<div id="content" style="position:relative; white-space: nowrap; font-family: serif;">
<div id="innerWrapper" style="position:absolute; width:100%; height:100%; overflow:hidden;">
<div id="innerContent"></div>