Skip to content

Instantly share code, notes, and snippets.

View alexeychikk's full-sized avatar
🧙‍♂️

Alex Zinkevych alexeychikk

🧙‍♂️
View GitHub Profile
@alexeychikk
alexeychikk / test.js
Created February 2, 2024 12:00
Test Promise.all
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
(async () => {
const reportGC = async () => {
global.gc();
await sleep(1000);
console.log('GC\nb() results:\n', process.memoryUsage());
};
let endPromise = Promise.resolve();
const options = {
...this.compilerOptions,
target: ts.ScriptTarget.ES5,
};
// @ts-expect-error foo
const scriptTransformers = ts.getTransformers(options).scriptTransformers;
const transformer: ts.TransformerFactory<ts.SourceFile> = (context) => {
return (sourceFile) => {
const visitor = (node: ts.Node): ts.Node => {
@alexeychikk
alexeychikk / hxformat.json
Last active May 14, 2023 13:42
Config for haxe-formatter that resembles default code style of Prettier
{
"indentation": {
"character": " "
},
"wrapping": {
"maxLineLength": 80,
"implementsExtends": {
"defaultWrap": "fillLine",
"rules": [
{
@alexeychikk
alexeychikk / memoryLeakTest.js
Created December 2, 2020 10:20
memoryLeakTest.js
// RUN WITH
// node --expose_gc memoryLeakTest.js
class A {
async b() {
return { foo: "bar".repeat(1000) };
}
async c() {
return Promise.resolve({ foo: "bar".repeat(1000) });
@alexeychikk
alexeychikk / Thunkify.ts
Created October 28, 2019 11:28
Thunkify
// tslint:disable: no-any
export type Thunkify<
Actions extends { [key: string]: (...args: any) => any }
> = {
[actionKey in keyof Actions]: ReturnType<Actions[actionKey]> extends ((
...args: any
) => Promise<any>)
?
| ((
...args: Parameters<Actions[actionKey]>
@alexeychikk
alexeychikk / createContextHOC.tsx
Created August 7, 2019 09:50
TypeScript React createContextHOC generic factory
import React from "react";
/*
// Usage:
export type WithPleasure = {
pleasure: number;
};
const PleasureContext = React.createContext<WithPleasure>({
pleasure: 13
@alexeychikk
alexeychikk / actions.js
Created December 27, 2017 11:27
Cancellation middleware for redux-axios-middleware
import {
CANCEL_ACTION_REQUESTS,
CANCEL_ALL_ACTION_REQUESTS
} from './constants';
export function cancelActionRequest(actionType) {
return { type: CANCEL_ACTION_REQUESTS, actionType };
}
export function cancelAllActionRequests() {
@alexeychikk
alexeychikk / ReactComment.jsx
Last active September 5, 2022 17:35
Simple React HTML comment
/*
Usage (I however think that the code is self explanatory)
<ReactComment text={`
Very long comment with html link
<a href="https://gist.github.com/alexeychikk/bfe72a072a9a962f2da900b6151e4aae">Star me :)</a>
`} />
*/
import React, {Component, PropTypes} from 'react';
@alexeychikk
alexeychikk / redux-context-fix.js
Last active September 21, 2016 10:02
Simple workaround to redux shouldComponentUpdate disregards react context
/**
* Usage
*
import React, { Component, PropTypes } from 'react';
import ReduxContextFix from '../util/reduxContextFix';
class ScreenSizeAware extends Component {
static childContextTypes = {
screenData: PropTypes.object
};