Skip to content

Instantly share code, notes, and snippets.

@scurker
scurker / react-dom-factories-to-react-create-element.js
Last active February 9, 2022 11:50
Convert `DOM.div` element factories from `react-dom-factories` to `React.createElement('div', ...)`
export default function transformer(file, api, options) {
const j = api.jscodeshift;
const root = j(file.source);
let hasModifications = false;
const reactDomFactoriesModuleName = 'react-dom-factories';
const findReact = (j, root) => {
// Check for import
// i.e. `import React from 'react'`
@scurker
scurker / perf.js
Created November 5, 2018 20:04
Capturing Page Load Metrics with Puppeteer
const puppeteer = require('puppeteer');
(async function() {
const browser = await puppeteer.launch({ devtools: true });
const page = await browser.newPage();
// Login
await page.goto('http://localhost:8080');
await page.type('#login', 'username');
@scurker
scurker / index.js
Last active December 12, 2017 22:43
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var currency_js_1 = require("currency.js");
currency_js_1.default(1).add(1.1);
@scurker
scurker / withAsync.jsx
Created May 8, 2017 21:27
An async higher order component that resolves a promise via props
import { h, Component } from 'preact';
class AsyncComponent extends Component {
constructor() {
super();
this.state = { loading: true };
this.getAsyncState = this.getAsyncState.bind(this);
this.update = this.update.bind(this);
}
let [ up, down, left, right, esc, space ] = [38, 40, 37, 39, 27, 32];
const webpack = require('webpack')
, path = require('path');
module.exports = {
entry: {
'global': './src/app.jsx',
},
resolve: {
extensions: ['.js', '.jsx']
},
@scurker
scurker / AsyncComponent.jsx
Created January 20, 2017 22:16
Async Component in Preact
import { h, Component } from 'preact';
class AsyncComponent extends Component {
constructor() {
super();
this.state = { loading: true };
this.getAsyncState = this.getAsyncState.bind(this);
this.update = this.update.bind(this);
}
@scurker
scurker / Git Aliases
Last active December 28, 2015 19:09
Git Aliases
git config alias.undo-commit 'reset --soft HEAD^'
git config alias.ls "log --pretty=format:'%C(yellow)%h%Creset %s %C(cyan)(%cr)%Creset %Cgreen<%cn>%Creset'"
@scurker
scurker / pre-commit-console
Created September 30, 2013 21:26
Stop console statements from going to git
#!/bin/sh
# Stop console.log statements from going into github
for file in `git diff-index --name-only HEAD --cached | egrep \.js$`; do
OUT=$(awk '/console\.(log|debug|warn|info)/ { print "\\t"NR": "; print $0; print "\\n" }' $file)
if [ -n "$OUT" ]; then
echo -e "\n".$file