Skip to content

Instantly share code, notes, and snippets.

View gcoop's full-sized avatar

Gavin Cooper gcoop

  • Surfline.com
  • Newport Beach, CA
View GitHub Profile
@gcoop
gcoop / gist:954009
Created May 3, 2011 19:19
ffmpeg-mplayer-image-capture
ffmpeg -i "http://127.0.0.1:8080" -ss 1 -s 120x90 -an ~/Desktop/image.jpg
wget "127.0.0.1:8080" -O "/image.jpg"
mplayer -frames 1 "http://127.0.0.1:8080" -vo png
mplayer -tv driver=v4l:fps=15 -vo jpeg "http://127.0.0.1:8080"
@gcoop
gcoop / php-unit-html-integration-test.php
Created April 1, 2011 12:37
Template for PHP unit integration tests, testing HTML strings.
<?php
require_once 'test_integration_html_HTML.php';
/**
* Suite of tests for the home page.
*
* @usage
* 1. Just define more functions, any functions starting with the name test will be run.
* 2. Each test function should have one or more asserts. Try not too have too many.
* 3. Each function should test a bunch of similiar stuff for this page like, banners or spot list.
<?php
function _cmpAscA($m, $n) {
if ($m->unixstart == $n->unixstart)
return 0;
return ($m->unixstart < $n->unixstart) ? -1 : 1;
}
function _cmpDescA($m, $n) {
if ($m->unixstart == $n->unixstart)
@gcoop
gcoop / singleton.php
Created February 21, 2011 16:17
Singleton Pattern in PHP
<?php
/**
* PHP Singleton pattern (same as Java singleton).
*
* Analytics::incrementView(this); // Within the photo class for example.
*/
class Analytics
{
private static $instance;
@gcoop
gcoop / fb-og-wp.php
Last active September 24, 2015 19:48
Simple script to add obvious Facebook Open Graph attributes to Wordpress posts.
<?php
function fbOg()
{
if (is_single())
{
global $post;
$images = preg_split("/\"/", get_the_post_thumbnail( $post->ID, 'thumbnail' ));
$first_image = isset($images[5]) ? $images[5] : 'http://example.com/blogLogo.jpg'; // Hardcoded fallback.
@gcoop
gcoop / functions.php
Created January 26, 2011 14:16
Include thumbnail in WP RSS
<?php
function dorphin_rss_item()
{
global $post;
$d = get_post_custom();
if (!empty($d['thumb_image']))
{
?>
<enclosure url="<?php echo(CDN_IMAGE.$d['thumb_image'][0]); ?>" type="image/jpeg" />
@gcoop
gcoop / js-browser-detection.js
Created January 14, 2011 11:19
I still need to know what the client is!
// Feature detection rocks.
// But what if you want to display something different on a different browser?
// You still need to know what browser the client is in.
//
// For example thanks to modernizr I know geoLocation exists, but I also know that FF's
// Allow location bar isn't very obvious to the user and I want to provide some help.
// Thus I need to make sure I style the helper in the correct place. Using .firefox .geo-helper
// I place it top right but in chrome I can place it somewhere else.
window.BrowserDetection = (function (window,document,undefined) {
var browser,
applicationCache.onUpdateReady = function () {
applicationCache.swapCache();
alert('New version of site available please refresh');
}
window.onOnline = function () {
// Fire an update to the cache.
applicationCache.update();
}
(function(window, document, $, undefined){
var SDK = function () {
var id,
cb,
key,
secret,
v = 1,
blacklabel_id = 2,
url = 'http://example.com/restserver.php',
canCache = (("localStorage" in window) &&
// Protected self calling pattern.
(function(window,document,$,undefined){
})(this,this.document,this.jQuery);
// setInterval replacement, async recursion.
// setInterval doesn't wait for completion even if the function is longer than the timeout, below does.
(function foobar() { // Recursive but doesn't fire before completed.
doStuff();