Skip to content

Instantly share code, notes, and snippets.

View sorenlouv's full-sized avatar

Søren Louv-Jansen sorenlouv

View GitHub Profile
@sorenlouv
sorenlouv / launch.json
Created October 11, 2017 11:09
Run Jest in vscode with breakpoints
{
"version": "0.2.0",
"configurations": [
{
"name": "Jest",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/node_modules/react-scripts/scripts/test.js",
"args": ["--runInBand", "--env=jsdom"],
"cwd": "${workspaceRoot}"
@sorenlouv
sorenlouv / launch.json
Created September 29, 2017 12:37
VSCode config for Jest runner
{
"version": "0.2.0",
"configurations": [
{
"name": "Jest",
"type": "node",
"request": "launch",
"args": ["--runInBand"],
"port": 9229,
"address": "localhost",
@sorenlouv
sorenlouv / jest-clear-cache.MD
Created September 26, 2017 11:35
Jest clear cache

Find cache location

npx jest --showConfig | grep cacheDirectory

Remove cache

rm -rf /var/folders/pg/hdsyy6t57jd8zgqlj4s2qk_r0000gn/T/jest_dx
@sorenlouv
sorenlouv / determine-changed-props.js
Last active April 18, 2024 16:21
Determine which props causes React components to re-render
import React, { Component } from 'react';
export default function withPropsChecker(WrappedComponent) {
return class PropsChecker extends Component {
componentWillReceiveProps(nextProps) {
Object.keys(nextProps)
.filter(key => {
return nextProps[key] !== this.props[key];
})
.map(key => {
@sorenlouv
sorenlouv / compare.js
Created August 31, 2017 12:39
Compare react perf
const LOCAL_STORAGE_KEY = 'react_perf_benchmark';
function setBenchmark() {
localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(Perf.getWasted()));
}
function compareBenchmark() {
const originalWasted = JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY));
const newTable = Perf.getWasted()
.map(row => {
@sorenlouv
sorenlouv / eslint+prettier.MD
Last active April 16, 2018 00:46
ESLint + prettier setup

Install packages

yarn add eslint prettier eslint-{config,plugin}-prettier eslint-plugin-react  --dev --exact

package.json

{
 "scripts": {
```
git reset --hard origin/master@{1}
```
@sorenlouv
sorenlouv / simple-port-forwarding.js
Last active February 19, 2023 22:06
Simple Port forwarding with Node.js
// npm install http-proxy
var httpProxy = require('http-proxy');
var targetHost = '192.168.99.100';
var port = 8489;
httpProxy.createProxyServer({target:'http://' + targetHost + ':' + port}).listen(port);
@sorenlouv
sorenlouv / batch-promise.js
Last active June 29, 2022 14:31
Execute promises sequentially in batches
var Q = require('q');
function batchPromises(items, fn, options) {
var results = [];
var index = (options.batchSize - 1);
function getNextItem() {
index++;
if (items.length > index) {
var nextItem = items[index];
@sorenlouv
sorenlouv / triangle.js
Last active February 27, 2016 19:33
Pascal's Triangle Example
pascalTriangle(10);
function pascalTriangle(levels) {
return _.reduce(_.range(levels), function(triangle, i) {
var row = _.reduce(_.range(i + 1), function(row, j) {
var isFirst = j === 0;
var isLast = j === i;
if (isFirst || isLast) {
row.push(1);
} else {