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 / inst_wout_new.js
Created March 28, 2012 17:55
Javascript instance without new
// Constructor function makes a Person model
var Person = function (lastName, firstName) {
// What's that? I'm not feeling like myself today!
if (!(this instanceof Person)) {
// Just call myself with new then!
return new Person(lastName, firstName);
}
this.lastName = lastName;
this.firstName = firstName;
@aaronmccall
aaronmccall / interval_ajax.js
Created July 2, 2012 17:57
a periodic ajax update with jQuery
$(function () {
setInterval(function () {
$.post('/has-changed', function (data) {
if (data == '1') {
$(document.body).css('backgroundColor', 'red');
}
});
}, 15);
});
@aaronmccall
aaronmccall / prune_empties.py
Created July 10, 2012 22:51
fastest way to prune empty strings from a python list
pruned_list = filter(None, list_of_strings)
@aaronmccall
aaronmccall / unix_line_endings.sh
Created September 18, 2012 17:25
command to convert \r\n to \n line endings
tr '\015' '\n' < file_with_carriage_returns.txt > out && mv out file_with_carriage_returns.txt
@aaronmccall
aaronmccall / pubsub.js
Created October 17, 2012 19:38
tiny standalone pubsub in javascript
//PubSub
(function(attachTo, defaultContext) {
var topics = {},
attachTo = attachTo||this,
defaultContext = defaultContext||this,
__slice = function (obj) { return [].prototype.slice.call(obj) };
attachTo.publish = function() {
var args = __slice(arguments),
topic = args.shift();
@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;
@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 / 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 / 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 / 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" {} +