Skip to content

Instantly share code, notes, and snippets.

View funkjedi's full-sized avatar

Tim Robertson funkjedi

View GitHub Profile
@funkjedi
funkjedi / gist:5675336
Created May 30, 2013 02:07
Super simple super tiny ajax function
function xhr(url, post) {
var req = window.ActiveXObject
? new ActiveXObject('Microsoft.XMLHTTP')
: new XMLHttpRequest();
if (post) {
req.open("POST", url, true);
req.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
req.setRequestHeader('Connection', 'close');
req.send(post);
@funkjedi
funkjedi / 217-1.js
Last active October 2, 2018 19:09
Code snippets from blog
errorOccurred = lastErrorOccurred = new Date().getTime();
_back = function(h) {
if (_backOk) {
if (_backCallback) {
_backCallback();
_backCallback = null;
}
var hh = parseInt(h);
var m = $.browser.netscape ? 2 : $.browser.msie ? 3 : 7;
if (hh > m) {
@funkjedi
funkjedi / gist:4353932
Created December 21, 2012 16:44
Bookmarklet for obtaining hi-res image previews from iStock
javascript:(function(){zoomFile.size=zoomFile.maxSize;top.location.href=zoomFile.mGetImageURL()})();
@funkjedi
funkjedi / gist:4169508
Created November 29, 2012 14:40
Geocode address
<?php
function geocode_address($address) {
$output = array('address' => $address);
$response = json_decode(file_get_contents("http://maps.googleapis.com/maps/api/geocode/json?address=" . urlencode($address) . "&sensor=false"));
switch ($output['status'] = $response->status) {
case 'OK':
$output['latitude'] = $response->results[0]->geometry->location->lat;
$output['longitude'] = $response->results[0]->geometry->location->lng;
$output['location_type'] = $response->results[0]->geometry->location_type;
@funkjedi
funkjedi / gist:4138022
Created November 24, 2012 01:53
Unicode transliteration
<?php
function utf8_translit($string) {
$characters = array(
#"" /* 0080 '<control>' */ => "",
#"" /* 0081 '<control>' */ => "",
#"" /* 0082 'BREAK PERMITTED HERE' */ => "",
#"" /* 0083 'NO BREAK HERE' */ => "",
#"" /* 0084 '<control>' */ => "",
#"" /* 0085 'NEXT LINE (NEL)' */ => "",
@funkjedi
funkjedi / gist:1345948
Created November 7, 2011 19:48
Generate patch file
diff -rupN original/ new/ > original.patch
@funkjedi
funkjedi / gist:1327528
Created October 31, 2011 13:46
Purge mysql binary logs
PURGE BINARY LOGS BEFORE '2011-10-30 10:06:06';
@funkjedi
funkjedi / gist:1248612
Created September 28, 2011 17:39
Reset file and directory permissions
find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
@funkjedi
funkjedi / StringScanner.php
Created August 28, 2011 17:41
Ruby corelib StringScanner ported to PHP
<?php
define('FLAG_MATCHED', 1 << 0);
class StringScanner implements ArrayAccess
{
protected
$str = '',
$len = 0,
$flags,