Skip to content

Instantly share code, notes, and snippets.

View gavinblair's full-sized avatar

Gavin Blair gavinblair

View GitHub Profile
@gavinblair
gavinblair / async.js
Created February 21, 2013 16:45
asynchronous callbacks, passing in a parameter
var id = "hi";
doifconnected(function(id){
alert(id);
}, id);
function doifconnected(callback, id){
setTimeout(function(){
if(1 == 1) {
callback(id);
}
@gavinblair
gavinblair / Default (Windows).sublime-keymap
Created February 1, 2013 16:13
ctrl+t in sublime text opens a new tab in Chrome (rather than switching the characters on either side of your cursor!)
[
{ "keys": ["ctrl+t"], "command": "exec", "args": { "cmd": ["C:\\newtab.bat"]} }
]
$(document).ready(function(){
var retina = window.devicePixelRatio > 1 ? true : false;
if(retina) {
$("html").addClass("retina");
$('img').each(function(){
$(this).attr("src", $(this).attr("src").replace("/l/", "/h/"));
});
}
});
@gavinblair
gavinblair / functions.php
Created December 7, 2012 18:52
wordpress ajax
<?php
// wp-admin/admin-ajax.php?action=getspeaker&a=b&c=d...
add_action( 'wp_ajax_nopriv_getspeaker', 'getspeaker' );
add_action( 'wp_ajax_getspeaker', 'getspeaker' );
function getspeaker(){
$offset = $_REQUEST['offset'];
@gavinblair
gavinblair / eventstream.php
Created November 20, 2012 19:13
Simple Server Sent Events Example
<?php
header('Cache-Control: no-cache');
header('Content-Type: text/event-stream');
$data = '';
// do stuff, get $something
$result = db_query('SELECT COUNT(*) as count FROM users WHERE last_login > date_add(current_timestamp, interval -15 minute)');
$usercount = db_fetch_array($result)[0]->count;
@gavinblair
gavinblair / weinre.bat
Created November 13, 2012 18:37
open weinre server and page in chrome
@echo off
set ip_address_string="IPv4 Address"
for /f "usebackq tokens=2 delims=:" %%f in (`ipconfig ^| findstr /c:%ip_address_string%`) do (
start C:\Users\User\AppData\Local\Google\Chrome\Application\chrome.exe http://%%f:8080
"C:\Program Files (x86)\nodejs\node.exe" node_modules\weinre\weinre\ --boundHost -all-
goto :eof
)
@gavinblair
gavinblair / script.js
Created October 31, 2012 13:43
replace which folder to grab img src's from
//responsive images
retina = window.devicePixelRatio > 1 ? true : false;
var l = "l";
if(retina) {
$("html").addClass("retina");
l = 'h';
$('img').each(function(){
$(this).attr("src", $(this).attr("src").replace("/l/", "/h/"));
});
}
@gavinblair
gavinblair / jquery.referrer.js
Created October 4, 2012 15:05 — forked from SeanJA/jquery.referrer.js
Get the referrer with jQuery: A useless bookmarklet
javascript:(function(){ jQuery.fn.referrer = function() { return jQuery(document).prop("referrer").toString(); }; alert(jQuery().referrer()); })();
@gavinblair
gavinblair / preload.js
Created October 2, 2012 14:06
Preload image function
function preload(source) {
var i = new Image();
i.src = source;
}
@gavinblair
gavinblair / Main.lua
Created August 24, 2012 18:13
@berdandy's Particle Fountain
function setup()
displayMode(STANDARD)
availableScenes = { Scene1() }
currentScene = availableScenes[1]
iparameter("SceneSelect",1,#availableScenes,1)
parameter("Size",50,500,150)