Skip to content

Instantly share code, notes, and snippets.

@julianburr
julianburr / example.sh
Created March 23, 2021 12:08
Git - delete merged branches locally and remote
# https://stackoverflow.com/questions/6127328/how-can-i-delete-all-git-branches-which-have-been-merged
# Delete local branches that have been merged i.e. into "main"
git branch --merged main | grep -v "(^\*|main)" | xargs git branch -d
# Delete remote branches that have been merged i.e. into "main
git branch -r --merged main | grep -v "(^\*|main)" | sed 's/origin\///' | xargs -n 1 git push --delete origin
@julianburr
julianburr / workshop.md
Last active November 6, 2019 00:32
Model Generator Workshop

Model Generator Workshop

Model Generator was created to solve a bunch of core problems we had to deal with in regards to API data flows within our React apps. We wanted to use Redux (because it seemed the best solution to store the data at the time), but needed to address the following:

  1. Redux Boilerplate
  2. Data Fetching
  3. State Normalisation

1. Redux Boilerplate

@julianburr
julianburr / dumb-cache-provider.js
Last active January 20, 2019 12:17
Why Suspense Will Be a Game Changer - Dumbest Cache Provider Example
// Yep, we're doing it, just storing the data on a plain old object
let data = {};
export default (fetchFn, getKey = (x) => x) => (args) => {
// Get unique identifier from arguments
const key = getKey(args);
if (data[key]) {
if (typeof data[key].then === 'function') {
// Fetch has already been triggered
// So throw the stored promise instead of triggering another request
@julianburr
julianburr / suspense-boundaries.js
Last active August 27, 2019 09:48
Why Suspense Will Be a Game Changer - Suspense Boundaries
class App extends Component {
render () {
return (
<Suspense fallback={<p>Loading...</p>}>
<DeepNesting>
<ThereMightBeSeveralAsyncComponentsHere />
</DeepNesting>
</Suspense>
);
}
@julianburr
julianburr / concurrent-mode.js
Created January 20, 2019 02:46
Why ... - Concurrent mode
// Instead of this...
ReactDOM.render(<App />, document.getElementById('root'));
// ...we do this
ReactDOM.createRoot(document.getElementById(‘root’)).render(<App />);
@julianburr
julianburr / suspense.js
Last active January 29, 2019 09:37
Why Suspense Will Be a Game Changer - Suspense
import createResource from './magical-cache-provider';
const dataResource = createResource((id) => fetchData(id));
class DynamicData extends Component {
render () {
const data = dataResource.read(this.props.id);
return <p>Data loaded 🎉</p>;
}
}
@julianburr
julianburr / context.js
Last active August 27, 2019 09:45
Why Suspense Will Be a Game Changer - Context
const DataContext = React.createContext();
class DataContextProvider extends Component {
// We want to be able to store multiple sources in the provider,
// so we store an object with unique keys for each data set +
// loading state
state = {
data: {},
fetch: this.fetch.bind(this)
};
@julianburr
julianburr / local-state.js
Last active January 20, 2019 02:51
Why Suspense Will Be a Game Changer - Local State
class DynamicData extends Component {
state = {
loading: true,
error: null,
data: null
};
componentDidMount () {
fetchData(this.props.id)
.then((data) => {
@julianburr
julianburr / experiment.js
Created April 25, 2018 22:13
Babel plugin for safe reading and setting of deeply nested objects in js
const exceptions = ["console"];
function getExp(node, all) {
let str = all;
let id = "";
if (node.property.type === "Identifier") {
str = `.${node.property.name}${str ? str : ""}`;
} else if (node.property.type === "NumericLiteral") {
str = `.${node.property.value}${str ? str : ""}`;
} else if (node.property.type === "StringLiteral") {
@julianburr
julianburr / parse-headers.js
Created November 6, 2017 14:00
Node script that downloads Sketch ObjC headers and parses them into json files
const fs = require('fs-extra');
const path = require('path');
const request = require('request');
const rimraf = require('rimraf');
const AdmZip = require('adm-zip');
const chalk = require('chalk');
const DOWNLOAD_SOURCE =
'https://github.com/abynim/Sketch-Headers/archive/master.zip';
const DOWNLOAD_TARGET = path.resolve(__dirname, '../headers/objc.zip');