Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View aaronmccall's full-sized avatar

Aaron McCall aaronmccall

  • METER Group, Inc. USA
  • Kennewick, WA
View GitHub Profile
@aaronmccall
aaronmccall / placeholder.js
Created January 4, 2011 22:45
shim for browsers that don't support the html5 placeholder attribute
setup_placeholders = (function() {
$.support.placeholder = false;
test = document.createElement('input');
if('placeholder' in test) {
$.support.placeholder = true;
return function() {}
} else {
return function(){
@aaronmccall
aaronmccall / timestamped_console.js
Created September 2, 2019 00:28
Add seconds.milliseconds at the end of every console call
const now = () => new Date().toISOString().replace(/^.*:([\d.]+)Z$/, '$1')
if (
process.env.NODE_ENV === 'development'
|| (localStorage.debug === 'true' && !console.__ts__)
) {
['log', 'debug', 'info', 'warn', 'error'].forEach(method => {
const original = console[method]
console[method] = (...args) => original.call(console, ...args, `| ${now()}`)
})
@aaronmccall
aaronmccall / People.coffee
Created January 4, 2017 22:21
How to replace coffee-react in your project
# Finally, ensure that all of your JSX in your components is in raw JS
import React from 'react'
export class People extends React.Component
onPersonClick: (personId) => @context.router.push("/people/#{personId}")
render: ->
{ data } = @props
`(
<div>
<h1>People</h1>
@aaronmccall
aaronmccall / Readme.md
Last active June 4, 2016 03:07
Example of oboe.js + pagination in &-collection

This was implemented for a real world application that was pulling in a large amount of data from multiple databases (SQL and MongoDB).

In order to improved TTFP (time to first page of results) and thus user-perceived performance, the API was converted to stream the results objects as it completed them.

Oboe.js allowed us to take advantage of that streaming API by parsing the incoming JSON stream on the browser-side.

@aaronmccall
aaronmccall / Readme.md
Last active June 4, 2016 02:44
An expirement

This was an experiment to come up with an efficient cache key generator for lat/lng origin/destination pairs.

It seemed to work pretty well, generating nearly a million keys in 66ms.

@aaronmccall
aaronmccall / findit.sh
Created July 31, 2013 13:32
Recursive find in files with line numbers
# Recursive find in files with line numbers
find directory/ -name "*.html" -exec grep -ni "my search here" {} +
@aaronmccall
aaronmccall / LICENSE.txt
Last active December 18, 2015 01:09 — forked from 140bytes/LICENSE.txt
recursaprop: Eliminates the need to do data && data.prop && data.prop.subprop testing when accessing properties of objects. Given a dot-notated property (foo.bar.baz) of an object, returns the property or undefined if it or any step in the path does not exist.
DO WHAT THE HECK YOU WANT TO PUBLIC LICENSE
Version 1, December 2013
Copyright (C) 2013 Aaron McCall <https://github.com/aaronmccall>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE HECK YOU WANT TO PUBLIC LICENSE
@aaronmccall
aaronmccall / resolver.js
Last active December 16, 2015 16:19
Eliminates the need to do obj && obj.prop && obj.prop.subprop testing
function resolver(prop_string, obj) {
if (!obj) return;
if (prop_string.indexOf('.') === -1) return obj[prop_string];
var props = prop_string.split('.'),
p = props.length,
result = obj,
i = 0,
prop;
for (; i<p; i++) {
prop = props[i];
@aaronmccall
aaronmccall / calcWeight.js
Created January 28, 2013 23:27
javascript function for calculating best weight given target weight, minimum increment, preferred increment and number of minimum increments available
/*
* Function to calculate optimum weight to use based on preferred and minimum weight increments
* Args:
* startingWeight: the target weight
* minIncrement: the smallest increment that weight can increase by
* prefIncrement: this is our normal smallest increment (typically 2 * 2.5 with most weight sets)
* minMultiplier: how many of our minimum increment are available before we must return to our preferred
* increment.
*/
function calcWeight(startingWeight, minIncrement, prefIncrement, minMultiplier) {
@aaronmccall
aaronmccall / top_of_the_props.js
Created November 14, 2012 15:33
Fitocracy helpers
var Totp = (function ($, _) {
var body = $(document.body),
btn = $('<button type="button" class="pill-btn red-btn" id="top_of_the_props">Top Proppers</button>'),
counts = {},
pub = {},
names = [],
template = "",
url = 'https://www.fitocracy.com/notifications/?start=0&end=1000000',
key, count, list, renderer;