Skip to content

Instantly share code, notes, and snippets.

import React from 'react';
export default function useUpdateEffect(callback, properties, cleanup) {
let initialized = React.useRef(false);
React.useEffect(() => {
if (initialized.current) {
callback(properties);
} else {
initialized.current = true;
{"lastUpload":"2020-05-06T14:05:50.026Z","extensionVersion":"v3.4.3"}
@afahy
afahy / wilks.js
Last active April 9, 2018 07:12
Calculate Wilks coefficient
/*
Calculate Wilks Coefficient to compare Powerlifting totals across bodyweights
https://en.wikipedia.org/wiki/Wilks_Coefficient
wilks(#body_weight, female?);
*/
const men = [
-216.0475144,
16.2606339,
@afahy
afahy / day1.js
Last active December 8, 2015 23:51
Advent of code solutions
// solves http://adventofcode.com/day/1/
const floors = (input) => (input.match(/\(/g) || []).length - (input.match(/\)/g) || []).length;
@afahy
afahy / flexgrid.scss
Created April 23, 2013 16:08
Flexible box model based grid ala bootstrap's grid semantics (`.container`, `.row`, `.span{n}`). Can set number of cols to be something other than 12.
@import "compass/utilities/general/clearfix";
@import "compass/css3/box";
@import "compass/css3/box-sizing";
$num-cols: 12;
.container {
@include pie-clearfix;
margin-right: auto;
margin-left: auto;
@afahy
afahy / getTemplate.js
Created April 10, 2012 17:03
Quick Underscore extension to get / precompile templates
/**
* _.getTemplate( selector ) returns a precompiled ( and cached ) template function based on selector html; assumes jQuery and Underscore
* @param { Selector } selector path to element ( most commonly a script tag with type= eg "x-underscore-template" ) containing template src
* @return {[type]} precompiled template function; pass in data object, returns rendered template text for .html() or .innerHTML =
*/
( function( global, _, undefined ) {
var templates = {};
_.getTemplate = function( selector ) {
@afahy
afahy / each.js
Created January 6, 2012 04:39
Simple each( obj | array ) function
// each( collection { obj || array }, callback, [ context ] )
// iterates over a collection, runs callback with either collection or optional context as value of 'this'
//
// callback sent the following arguments:
// * current item value
// * index or key
// * collection
( function( global ) {
@afahy
afahy / objTests.js
Created December 28, 2011 20:03
Simple testing for variable types
// Can substitute "this" ( / "global" ) for whatever object you want to extend, eg "library.util" or whatever
//
// Creates:
//
// isBoolean( obj )
// isNumber( obj )
// isString( obj )
// isFunction( obj )
// isArray( obj )
// isDate( obj )
@afahy
afahy / tmpl-jquery.js
Created December 15, 2011 22:57
Simple templating / string replacement function
( function( $ ) {
function Template( src ) {
if ( src && typeof src === 'string' ) {
this.src = src;
}
}
$.extend( Template.prototype, {
render : function( data ) {
return this.src.replace(/\$\{\s?([a-zA-Z_$][0-9a-zA-Z_$]*?)\s?\}/g, function(match, key) {
return data && data[key] ? data[key] : '';
@afahy
afahy / node-and-npm-in-30-seconds.sh
Created April 8, 2011 20:08 — forked from isaacs/node-and-npm-in-30-seconds.sh
Installing node.js and npm
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl http://npmjs.org/install.sh | sh