Skip to content

Instantly share code, notes, and snippets.

View gavinblair's full-sized avatar

Gavin Blair gavinblair

View GitHub Profile
@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 / 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 / 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 / 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 / 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'];
$(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 / 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"]} }
]
@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);
}
#box{
display: block;
height: 100px;
width: 100px;
background: green;
position: relative;
opacity: .5;
border: 2px solid blue;
}
@gavinblair
gavinblair / post.md
Last active December 15, 2015 04:29
Explode Code: Hello World

March 19, 2013 - On February 5, 2013 we had our first Explode Code Talks event. It was a huge success - over 50 people came to Big Viking Games to see five talks, eat pizza and mingle with other web/mobile/game developers.

This Friday, March 22nd will be a different kind of event called Hello World.

Hello World! is an opportunity to learn something new. Pick a programming language or framework that you don't know and build something with it - anything*!

Then, bring your work to this event, show it off like it's the next Facebook, and eat pizza!

This is an open event and everyone is invited to participate.