Skip to content

Instantly share code, notes, and snippets.

View zachariahtimothy's full-sized avatar

Zach Curtis zachariahtimothy

View GitHub Profile
(function( $ ){
var rinput = /^(?:color|date|datetime|datetime-local|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,
rCRLF = /\r?\n/g,
rselectTextarea = /^(?:select|textarea)/i;
$.prototype.serialize = function(args){
var options = args || {};
return this.map(function(){
return this.elements ? jQuery.makeArray( this.elements ) : this;
})
@zachariahtimothy
zachariahtimothy / Gruntfile.js
Created April 24, 2013 19:45
Grunt calling Express Node API Application
// Generated on 2013-04-23 using generator-webapp 0.1.7
'use strict';
var path = require('path');
// # Globbing
// for performance reasons we're only matching one level down:
// 'test/spec/{,*/}*.js'
// use this if you want to match all subfolders:
// 'test/spec/**/*.js'
@zachariahtimothy
zachariahtimothy / apiServer.js
Created April 24, 2013 19:49
Express as an API application exported for interoperability with Grunt.
/**
* Module dependencies.
*/
var express = require('express');
var http = require('http');
var app = express();
// all environments
app.use(express.favicon());
@zachariahtimothy
zachariahtimothy / gist:5455126
Created April 24, 2013 20:05
Code to export email addresses and forwarders from cPanel using Browser developer tools
// Email Addresses ///
var rows = $("#table_email_accts tr.dt_info_row"),
returnString = "";
rows.each(function(i, item){
var tdList = [];
$(item).find('td:eq(0)').each(function(s, subItem){
tdList.push($(subItem).text());
});
returnString += tdList + "\n";
});
@zachariahtimothy
zachariahtimothy / RequirejsStub.js
Created April 24, 2013 20:35
RequireJS ADM Stub
define([], function(){
'use strict';
var MODULE = {
};
return MODULE;
});
@zachariahtimothy
zachariahtimothy / FlowRouterSSR and CollectionsFS
Created November 2, 2015 20:34
Sets up context for using CollectionsFS with FlowRouterSSR. Allows the .url() function to work server side.
//Hack to make CollectionFS work with FlowRouter.
if (Meteor.isServer) {
let originalFind = Collections.Media.find;
let originalFindOne = Collections.Media.findOne;
Collections.Media.__proto__.findOne = function (selector, options) {
let self = this;
return FlowRouter.ssrContext.withValue(null, function() {
return originalFindOne.call(self, selector, options);
});
@zachariahtimothy
zachariahtimothy / Freshbooks Estimate Hour Extraction
Created December 8, 2015 22:54
Console script to run to extract total hours from Estimate. This is helpful if you have multiple line items with multiple bill rates.
var total = 0;
$('.invbody-items').find('.quantity').each(function (i, item) {
var me = $(item).text().trim();
me = parseFloat(me, 10);
if (me) { total += me; }
});
console.log('Total Hours:', total);
@zachariahtimothy
zachariahtimothy / gist:aa9acd432bd382880381052016412cc6
Last active November 17, 2016 16:43
Calculate an average date in C++ based on array of dates
int wean_dates_size = bgi->wean_dates.size();
if (wean_dates_size > 0) {
pigknows::Date wean_date;
pigknows::DoubleCell dateTotals;
// Get a baseline time (date does not matter as since it will be used )
struct std::tm baseTime = {0,0,0,27,9,82}; /* October 27, 1982 (Zachs bday :) */
std::time_t x = std::mktime(&baseTime);
for(int i=0; i< wean_dates_size; ++i) {
@zachariahtimothy
zachariahtimothy / generateNowConfig.js
Last active August 24, 2018 17:38
Generates a now.json file for static docker deployments on now that require .env files (which are ignored in .gitignore)
const path = require('path');
const fs = require('fs');
// Generates now.json
// Writes a now config for static site copying .env to now.json
function main() {
const baseDir = path.join(__dirname, '../');
const envFile = fs.readFileSync(path.join(baseDir, '.env'));
const envLines = envFile.toString().split('\n');
const nowConfig = {
@zachariahtimothy
zachariahtimothy / TaylorMade.js
Created November 30, 2018 15:51
Access unstated state
class TaylorMade extends React.Component {
myCounter = null;
shouldComponentUpdate() {
if (this.myCounter) {
console.log('Bomb.com, I have a counter!');
}
return true;
}
render() {