Skip to content

Instantly share code, notes, and snippets.

💃

Joseph Wynn wildlyinaccurate

💃
Block or report user

Report or block wildlyinaccurate

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@wildlyinaccurate
wildlyinaccurate / safe-component.jsx
Created Jun 21, 2017
Proof-of-concept for making React components "safe" or "optional" by catching errors during rendering.
View safe-component.jsx
// Paste this into https://preactjs.com/repl to see it working
// This function takes any component, and returns a higher-order (wrapper)
// component. This wrapper attempts to render the wrapped component, catching
// any errors.
const safeComponent = (Component) => function WrappedComponent () {
// Handle both class components and stateless functional components
const wrappedRender = Component.prototype.render || Component
try {
@wildlyinaccurate
wildlyinaccurate / client.js
Last active Jun 4, 2017
Simplified approach for hydrating statically-rendered React components on the client.
View client.js
import React from 'react'
import ReactDOM from 'react-dom'
const hydrateComponent = (scriptEl) => {
const componentId = scriptEl.getAttribute('data-hydration-data-id')
const componentElement = document.querySelector(`[data-hydration-component-id="${componentId}"]`)
const props = JSON.parse(scriptEl.innerHTML)
import(componentId).then(Component => ReactDOM.render(<Component {...props} />, componentElement))
}
@wildlyinaccurate
wildlyinaccurate / morph-duplicate-style-checker.js
Last active May 31, 2017
Check any Morph-powered page for duplicate styles.
View morph-duplicate-style-checker.js
var page = require('webpage').create()
var system = require('system')
if (system.args.length === 1) {
console.log('Usage: morph-style-checker.js <URL>')
phantom.exit(1)
}
var url = system.args[1]
@wildlyinaccurate
wildlyinaccurate / ubuntu-setup.sh
Last active Sep 17, 2019
Setting up a new Ubuntu machine
View ubuntu-setup.sh
#!/usr/bin/env bash
# Generate an ED25519 key and display the public key
ssh-keygen -o -a 100 -t ed25519
cat ~/.ssh/id_ed25519.pub
read -p 'You should add your public key to GitHub now. Press any key to continue...'
# Add custom repositories
sudo add-apt-repository ppa:ubuntu-mozilla-daily/firefox-aurora
@wildlyinaccurate
wildlyinaccurate / main.sh
Last active Oct 7, 2015
Using Docker's save/load commands to share and run images without using a registry
View main.sh
REGISTRY=registry.yourdomain.com
# You may want/need to pull the latest images on a machine which has access to the registry
docker pull $REGISTRY/foo
docker pull $REGISTRY/bar
# You can save the images as tarballs and distribute them as you please
docker save --output=/home/user/images/foo.tar $REGISTRY/foo
docker save --output=/home/user/images/bar.tar $REGISTRY/bar
View spottheerror.js
(function() {
'use strict'
var container = document.querySelector('.post-content')
var items = container.querySelectorAll('[data-collection-item]')
[].slice.call(items).forEach(function(item) {
// ...
})
View workflows.md

Merge all the things (current workflow for the responsive-news repo)

  1. Branch from develop
  2. Commit as you go
  3. Merge develop into your branch
  4. Push branch, create PR
  5. When branch is ready to merge, merge the PR

Pros

View workflows.md

Hotfix workflows

"Traditional" gitflow workflow

  1. Create hotfix-branch from release
  2. Commit to hotfix-branch
  3. Merge hotfix-branch into both release and develop

Pros

View add.js
// Fuck the addition operator. Real programmers work in binary!
function add(a, b) {
// XOR to get the sum of the bits
var sum = a ^ b;
// "Carry" bits are common to both numbers
var carry = (a & b) << 1;
if (sum & carry) {
// Rinse and repeat until there are no leftover bits
You can’t perform that action at this time.