Skip to content

Instantly share code, notes, and snippets.

View stephenwil's full-sized avatar

Stephen Wilson stephenwil

View GitHub Profile
@stephenwil
stephenwil / jest.setUpTests.js
Last active August 4, 2020 13:55
Been around the houses trying to get old library that still uses React.createClass to run through jest. Tried babel transform createclass but no luck. This simply patches React during testing
import createClass from 'create-react-class'
import React from 'react'
Enzyme.configure({ adapter: new Adapter() });
// Until lib-x gets updated to React 16
Object.assign(React, {
createClass
})
@stephenwil
stephenwil / remove-empty-constructor.js
Last active July 1, 2020 11:26 — forked from tkers/remove-empty-constructor.js
jscodeshift for removing empty constructors
/*
Removes empty constructors (ignoring calls to super)
Run with codeshift:
jscodeshift -t ./remove-empty-constructor.js --extensions js,jsx --ignore-pattern 'node_modules' src/
*/
export default function transformer(file, api) {
const j = api.jscodeshift
const root = j(file.source)
@stephenwil
stephenwil / launch.json
Created February 5, 2020 14:42
Visual Code launch.json, to debug jest tests
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "attach",
"name": "Attach to Chrome",
@stephenwil
stephenwil / virtual-scrolling-angular.html
Last active May 21, 2019 08:42
Large Array creation & virtual scrolling in angular
<cdk-virtual-scroll-viewport itemSize="50" class="example-viewport">
<div *cdkVirtualFor="let item of items" class="example-item">{{item}}</div>
</cdk-virtual-scroll-viewport>
@stephenwil
stephenwil / openweather-api-svg-symbol.svg
Created April 30, 2019 11:04
An icon set in one complete <svg> block, making use of <symbol> such that you can refer to the svgs via <use> rather than inline them.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@stephenwil
stephenwil / index.html
Last active May 23, 2019 10:00
An icon set in one complete <svg> block, making use of <symbol> such that you can refer to the svgs via <use> rather than inline them.
<html>
<head>
</head>
<body>
<svg xmlns="http://www.w3.org/2000/svg" xlink="http://www.w3.org/1999/xlink">
<use xlink:href="https://gist.github.com/stephenwil/b0ec7b72daecdbe562ec248ee9b4480e#file-openweather-api" x="100" y="300" />
</svg>
</body>
</html>
@stephenwil
stephenwil / scottish-schools-2018.json
Last active April 17, 2019 14:33
Scottish Schools at 2018
This file has been truncated, but you can view the full file.
[
{
"SeedCode": "8212627",
"LA Name": "North Ayrshire",
"Centre Type": "Local Authority",
"School Name": "Abbey Primary School",
"Address 1": "Claremont Crescent",
"Address 2": "",
"Address 3": "KILWINNING",
"Post code": "KA13 7HG",
const mapEnum = (type: any, value: any) => {
const x = findKey(type, (v: any,i: any, a: any) => {
// console.log(v,i,a,v2);
return v === value
});
console.log(x);
return x;
}
@stephenwil
stephenwil / Context.tsx
Created May 29, 2018 09:59
Typescript HOC Context
export const withContext = <P extends {}>(Component: React.ComponentType<P>) =>
class WithContext extends React.PureComponent<P & IAppContext> {
render() {
return (
<AppContext.Consumer>
{(context: any) => <Component {...this.props} {...context} />}
</AppContext.Consumer>
);
}
};
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.