Skip to content

Instantly share code, notes, and snippets.

View theKashey's full-sized avatar
🤔
what's happening?

Anton Korzunov theKashey

🤔
what's happening?
View GitHub Profile
componentDidMount() {
new IntersectionObserver(async ([entry], obs) => {
if (!entry.isIntersecting) return;
obs.unobserve(this.root);
this.setState({loading: true});
const {load} = this.props;
const Child = interopDefault(await load());
setTimeout(() => {
//ReactDOM.hydrate(<Child {...props} />, this.root);
@theKashey
theKashey / binaryCode.js
Created April 15, 2019 07:36
osme geometry encoder
var codingCoefficient = 1000000,
base64 = require('./ybase64.js'); // this is just atob
function getShiftsPoint (path, codingCoefficient) {
var res = [];
for (var i = 0, l = path.length, prev = [0, 0]; i < l; i++) {
res.push([
Math.round((path[i][0] - prev[0]) * codingCoefficient),
Math.round((path[i][1] - prev[1]) * codingCoefficient)
]);
import test from 'ava';
import sinon from 'sinon';
// ^ uses a real FS
// nothing before would be mocked
import rewiremock from 'rewiremock/node';
import mockfs from 'mock-fs';
import mountfs from 'mountfs';
import fs from 'fs';
@theKashey
theKashey / ava-rewiremock.js
Created March 19, 2019 04:24
ava rewiremock
import test from 'ava';
import sinon from 'sinon';
// nothing would be mocked before import
import rewiremock from 'rewiremock/node';
import fs from 'fs';
// ^ only this "FS" would be mocked
rewiremock('fs').mockThrough(() => sinon.stub());
// ^ this line would be "hoisted"
class Example extends Component {
state = {
filterText: "",
};
// *******************************************************
// NOTE: this example is NOT the recommended approach.
// See the examples below for our recommendations instead.
// *******************************************************
@theKashey
theKashey / fixModuleResolution.js
Created March 18, 2019 05:26
Host node.js module resultion
console.log(require.extensions);
// to prevent name resolution races - hoist some extensions to top of the list
const hoistExtensions = (hoistedExtensions) => {
const restExtensions = {};
Object
.keys(require.extensions)
.forEach(name => {
@theKashey
theKashey / browserDetection.js
Last active March 16, 2019 22:58
maps.js. Uses ymb/yms module system (https://github.com/yandex/ymb)
// code from https://api-maps.yandex.ru/2.1.73/map.js?callback=__jsonp_ymaps_map&mode=release&flags=
// see it live - https://yandex.com/maps/?ll=150.854710%2C-35.491643&z=7
// "import mapping"
["theme.browser.current", ".v", function (ym) {
var browser = ym.env.browser,
mapper = browser.eventMapper,
browserEngineLowerCase = browser.engine.toLowerCase(),
availableEngines = {
@theKashey
theKashey / requireLazy package.json
Created March 4, 2019 23:41
Webpack "lazy" require done right - just create `requireLazy` directory and drop these file there.
{
"internal": "true",
"main": "require-server.js",
"browser": "require-browser.js"
}
@theKashey
theKashey / browser.js
Created March 3, 2019 21:48
How to separate files by "environment", just drop it in a SUB DIRECTORY!
export default "IS BROWSER";
@theKashey
theKashey / webpack.config.js
Created January 18, 2019 00:43
webpack + hot loader + ts
/* eslint-disable */
const path = require('path')
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const sassRegex = /\.(scss|sass)$/;
const getStyleLoaders = (cssOptions, preProcessor) => {
const loaders = [
require.resolve('style-loader'),