Skip to content

Instantly share code, notes, and snippets.

View aneurysmjs's full-sized avatar
💭
асинхорнный

Аневризма aneurysmjs

💭
асинхорнный
View GitHub Profile
@aneurysmjs
aneurysmjs / index.html
Last active October 29, 2019 08:58
CSS stuff
<!--
even though the "blue" comes later in the list of classes,
but CSS rules of precedence actually depends of the order of
classes in the stylesheet
-->
<span class="red blue">
so I'm red
</span>
@aneurysmjs
aneurysmjs / git-tricks.md
Last active July 6, 2023 09:00
git tricks

ignore files temporarily

start ignoring changes to a file:

git update-index --assume-unchanged path/to/file

keep tracking again:

git update-index --no-assume-unchanged path/to/file

see here

get a list of files marked --assume-unchanged:

git ls-files -v | grep '^[[:lower:]]'

@aneurysmjs
aneurysmjs / useErrorHook.tsx
Last active October 21, 2019 21:05
handle promise exceptions inside a hook
/**
* @link this is taken from here for reference
* https://github.com/testing-library/react-hooks-testing-library/issues/20#issuecomment-476628600
*/
import { useState, useEffect } from 'react';
import { renderHook } from '@testing-library/react-hooks';
describe('error hook tests', () => {
function useError(obj: Error | string): boolean {
if (obj.constructor.name === 'Error') {
@aneurysmjs
aneurysmjs / bundle.js
Last active October 17, 2019 09:20
bundle-tricks
// .babelrc
{
"presets": [
[
"@babel/preset-env",
{
// this tells @babel "hey, don'y change any of the modules, let Webpack handle it
"modules": false
// you only get the individual pollyfill that you need
"useBuiltIns": "usage"
@aneurysmjs
aneurysmjs / types-vs-interface.ts
Created October 15, 2019 17:10
types vs interfaces
interface Base {
id: string;
timestamp: string;
}
interface Product extends Base {
price: number;
stock: number;
}
@aneurysmjs
aneurysmjs / reducers-performance.js
Last active October 8, 2019 12:55
benchmarking each type of reducer
const { PerformanceObserver, performance } = require('perf_hooks');
const obs = new PerformanceObserver((items) => {
console.log(items.getEntries()[0]);
performance.clearMarks();
});
obs.observe({ entryTypes: ['measure'] });
const has = Object.prototype.hasOwnProperty;
@aneurysmjs
aneurysmjs / connect.js
Created September 30, 2019 11:33
Simplified version of react-redux's connect HOC
const connect = (mapStateToProps) => (Component) => {
return class Connect extends React.Component {
state = mapStateToProps(store.getState());
componentDidMount() {
// когда store меняется, обновит компонент
this.unsubscribe = store.subscribe(this.update);
}
componentWillUnmount() {
@aneurysmjs
aneurysmjs / proto-tricks.js
Last active September 30, 2019 08:06
couple of tricks about prototypal inheritance
/**
* understanding .constructor property
*/
function User() {
}
// when functions are created, they're given a "prototype" property which is an object
console.log(User.prototype); // {}
// The type of a box is always defined by the 'display' property:
/**
* block:
* 100% of parent's width
* vertically, one after another
*/
/**
* inline-block:
// Partial application and currying are two different techniques for specializing a generalized function
// Partial application takes some of the arguments now and then takes all of the rest arguments later
function partial(fn, ...firstArgs) {
return function applied(...lastArgs) {
return fn(...firstArgs, ...lastArgs);
};
}