Skip to content

Instantly share code, notes, and snippets.

View jeffreytgilbert's full-sized avatar

Jeffrey Gilbert jeffreytgilbert

View GitHub Profile
@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
var
express = require( 'express' ),
connect = require('connect'),
app = express();
count = 0;
app.configure( function() {
app.use(connect.urlencoded());
app.use(connect.json());
});
@jeffreytgilbert
jeffreytgilbert / show-me-your-plugins.js
Created April 3, 2014 17:01
Scan over all the plugins available in a browser. Does not work under mozilla browsers who have disabled this ability.
var $$$i = 0,
$$mt = [];
while(navigator.mimeTypes[$$$i]){
$$mt.push(navigator.mimeTypes[$$$i]);
$$$i++;
}
console.table($$mt.map(function(i,v,a){
return {
'name':i.description||i.enabledPlugin.description,
@jeffreytgilbert
jeffreytgilbert / sized-async-queue.js
Created April 3, 2014 17:00
Example of sized queues, for things like, oh, i don't know, running limited numbers of selenium tests in parallel or downloading images two at a time or whatever.
var runningProcessCount = 0,
processQueuePosition = 1,
processLimit = 2,
totalProcesses = 10;
function throttleProcesses(){
if(processLimit > runningProcessCount){
fakeProcess();
return true;
} else {
# Path to your oh-my-zsh configuration.
ZSH=$HOME/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
#ZSH_THEME="robbyrussell"
#ZSH_THEME="cloud"
#ZSH_THEME="wedisagree" # throws an error
# oh-my-zsh Zen Theme
### Git
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[green]%}%{$reset_color%}%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg_no_bold[white]%}☁%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_AHEAD="%{$fg_no_bold[magenta]%}▴%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_BEHIND="%{$fg_no_bold[magenta]%}▾%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_STAGED="%{$fg_no_bold[green]%}✚%{$reset_color%}"
@jeffreytgilbert
jeffreytgilbert / chase-credit-card-page-has-no-balance.js
Created December 30, 2013 19:34
A little script to show the running balance on the chase cc page because they decided it's not important to keep a running balance...
(function(){
var amounts = document.querySelectorAll('#Posted tbody .amount');
var balance = Number(document.querySelector('#AccountDetailTable .card-accountdetailcol tbody tr td:nth-child(2)').innerText.substr(1).replace(',',''));
var iii=0;
var amount = '';
var element = null;
var elementsArray = [];
for(iii=0; iii < amounts.length; iii++) {
element = amounts[iii];
@jeffreytgilbert
jeffreytgilbert / warnings-filtered-out-of-phantomjs-stream.js
Last active January 1, 2016 13:58
These are the relevant bits to filter the output from a phantomjs instance when it's dumping out warnings from the old Qt library on OS X 10.9 Mavericks, since the phantom lib doesn't look to be getting updated for another 3 months or so.
var stream = require('stream'),
util = require('util');
function FilterThirdPartyWarnings(options){
// allow use without new
if (!(this instanceof FilterThirdPartyWarnings)) {
return new FilterThirdPartyWarnings(options);
}
stream.Transform.call(this, options);