Skip to content

Instantly share code, notes, and snippets.

View hanford's full-sized avatar
🌝

Jack Hanford hanford

🌝
View GitHub Profile
@hanford
hanford / service.js
Last active February 9, 2018 20:06
import Service, { Router } from '@eaze/service'
import { auth, isAdmin } from '@eaze/middleware'
class Acacia extends Service {
static router () {
return (
<Router>
<Get route='/products' handler={(req, res) => res.send(200)} />
<Post route='/products/create' middleware={[ isAdmin ]} handler={(req, res) => res.send(200)} />
<Patch route='/products/:id' middleware={[ isAdmin ]} handler={(req, res) => res.send(200)} />
//npm init -y
//npm install --save puppeteer
//usage: node script.js /path/to/input.html /path/to/output.pdf
//script.js
const puppeteer = require('puppeteer');
(async () => {
@addyosmani
addyosmani / workbox.md
Last active January 20, 2024 16:14
Workbox recipes

Workbox runtime caching recipes

Your Service Worker script will need to import in Workbox and initialize it before calling any of the routes documented in this write-up, similar to the below:

importScripts('workbox-sw.prod.v1.3.0.js');
const workbox = new WorkboxSW();

// Placeholder array populated automatically by workboxBuild.injectManifest()
@EQuimper
EQuimper / clear.txt
Created June 16, 2017 16:17
React-Native clear Watchman + Cache
watchman watch-del-all && rm -rf node_modules/ && yarn cache clean && yarn install && yarn start -- --reset-cache
@dannycroft
dannycroft / tti.js
Created June 16, 2017 06:06
TTI - console measurement
var t = window.performance.timing;
var interactive = t.domInteractive - t.domLoading;
var dcl = t.domContentLoadedEventStart - t.domLoading;
var complete = t.domComplete - t.domLoading;
console.log('interactive: ' + interactive + 'ms, ' + 'dcl: ' + dcl + 'ms, complete: ' + complete + 'ms');
@gaearon
gaearon / connect.js
Last active May 3, 2025 05:27
connect.js explained
// connect() is a function that injects Redux-related props into your component.
// You can inject data and callbacks that change that data by dispatching actions.
function connect(mapStateToProps, mapDispatchToProps) {
// It lets us inject component as the last step so people can use it as a decorator.
// Generally you don't need to worry about it.
return function (WrappedComponent) {
// It returns a component
return class extends React.Component {
render() {
return (

Virtual DOM and diffing algorithm

There was a [great article][1] about how react implements it's virtual DOM. There are some really interesting ideas in there but they are deeply buried in the implementation of the React framework.

However, it's possible to implement just the virtual DOM and diff algorithm on it's own as a set of independent modules.

@amitchhajer
amitchhajer / Count Code lines
Created January 5, 2013 11:08
Count number of code lines in git repository per user
git ls-files -z | xargs -0n1 git blame -w | perl -n -e '/^.*\((.*?)\s*[\d]{4}/; print $1,"\n"' | sort -f | uniq -c | sort -n