Skip to content

Instantly share code, notes, and snippets.

View jeffreytgilbert's full-sized avatar

Jeffrey Gilbert jeffreytgilbert

View GitHub Profile
'use strict'
console.log "I'm the client code"
# A global reference, because coffeescript wraps everything in a closure
root = global ? window
root.Meteor.subscribe 'messages'
root.Meteor.subscribe 'rooms'
# root.Meteor.startup ->
@jeffreytgilbert
jeffreytgilbert / gist:5304682
Created April 3, 2013 19:55
Example form handling for jquery for handling submissions from multiple forms on a page depending on which was submitted. The reason you want to catch the submission event is because people can click "enter" and a text input and it will submit the form regardless of your button type.
$('form').submit(function(event){
event.preventDefault();
event.stopPropogation(); // same thing
$(this); // <-- the form that was submitted
$('input', this); // <-- all the inputs for this form that need validation
$('input', this).each(function(){
var element = $(this); // <-- this is the current field which can be validated
if(element.attr('required') == 'required' && element.val().trim() != '' && element.val() ){
@jeffreytgilbert
jeffreytgilbert / test-styles.css
Created September 8, 2014 20:32
Simple css file for zeroing out borders, padding, and margins on iframes and soon to include css animations for other tests where detecting keyframe progression may be possible.
iframe {
margin: 0;
padding: 0;
border: 0;
overflow: hidden;
}
@jeffreytgilbert
jeffreytgilbert / index.html
Created September 8, 2014 20:30
Main document for loading throttling tests in various browsers. This document loads the other test frames in various ways where they are outside and inside the viewport, then moves them all back into the viewport once tests have completed.
<!DOCTYPE html>
<meta charset="utf-8">
<head>
<link href="test-styles.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#eeeeff" bottommargin="0" rightmargin="0" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<div style="float:left;position:relative; border:10px solid royalblue; width:820px; height:1100px;">
<!-- show 1 iframe and box out the other -->
@jeffreytgilbert
jeffreytgilbert / js-test-frame.html
Created September 8, 2014 20:27
Framed documents which try and force redraws in the browser and then measure the rates at which they redraw to discover discrepancies in browser behavior.
<!DOCTYPE html>
<meta charset="utf-8">
<head>
<link href="test-styles.css" rel="stylesheet" type="text/css">
<style>
body {
margin:0;
padding:0;
background-color:#ff99ff;
}
@jeffreytgilbert
jeffreytgilbert / js-perf-struct-frame.html
Created September 8, 2014 20:22
A container to frame content so positioning it outside of the viewport is easier.
<!DOCTYPE html>
<meta charset="utf-8">
<head>
<link href="test-styles.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#FFFF99" bottommargin="0" rightmargin="0" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<div style="position:relative; border:10px solid #228b22; width:820px; height:250px;">
<!-- first frame is positioned where it will be in view by the container iframe in the parent document -->
var open = require('open');
var url = require('url');
var http = require('http');
var twitterAPI = require('node-twitter-api');
var Q = require('q');
var authObject = (function () {
var deferred = Q.defer();
var twitter = {};
var token = {};
@jeffreytgilbert
jeffreytgilbert / posers.js
Last active August 29, 2015 14:02
Sometimes android browsers get iphone envy and try to pretend they're mobile safari... So I broke it down by os by feature detection, because i needed to for this.
// see if this is a mobile browser
var w = window, d = document;
var regex = /mobi|android|webos|blackberry|ipad|ipod|iphone|tablet|phone|kindle/i;
r.mobile = regex.test(ua) || regex.test(w.navigator.platform);
if (r.mobile) {
if (w.chrome || w.performance) { // this is an android device posing as an iPhone
if (w.Worker) { // android 4.4+
@jeffreytgilbert
jeffreytgilbert / FPSUtils
Last active August 29, 2015 14:01
Measure FPS at a sub second sampling level. Check can be throttled by time passed, based as a guesstimate of (frames x frame time) given stage FPS as a limit. When Flash throttles playback, timers are limited to 2 per second and up to 2 frames per second, so you can't improve that by using timers vs frames.
package FPSUtils {
import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.display.Stage;
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.IEventDispatcher;
import flash.external.ExternalInterface;
import flash.utils.clearInterval;
import flash.utils.getTimer;
@jeffreytgilbert
jeffreytgilbert / solution-timer.js
Last active August 29, 2015 14:00
CommonJS module for managing a timeline of timers with an optional execution time limit. The timers can all be paused and resumed independent of the execution timer. This was tested to within 1/100th of a second accuracy in Chrome, but uses Date.now() which is not compatible with some older browsers (IE 9 for instance). Easy to replace with new …
'use strict';
// ****** BEGIN SOLUTION TIMER ******* //
module.exports = (function () {
// all times will be measured in seconds by default
return function (_arrayOfTimes, _scriptTimeLimit, _timerCallback, _timeLimitCallback, _useMilliseconds) { // _useSeconds - add this later to add the ability to measure in milliseconds
var _startTime = 0, // the time this script started
_initialPlayTime = 0, // the time the playhead initially started