Skip to content

Instantly share code, notes, and snippets.

View funkjedi's full-sized avatar

Tim Robertson funkjedi

View GitHub Profile
@funkjedi
funkjedi / functions.php
Created February 26, 2015 16:21
Extend qTranslate Slug for WordPress to automatically generate slugs qTranslate-X
<?php
add_action('admin_footer', 'qtranslate_slug_snippet');
function qtranslate_slug_snippet() {
?>
<script>
function string_to_slug(str) {
str = str.replace(/^\s+|\s+$/g, ''); // trim
str = str.toLowerCase();
@funkjedi
funkjedi / gist:5820170bc0c7642a4cb4
Last active August 29, 2015 14:18
Scroll to anchor
// Handle links with href started with '#' only.
jQuery(document).on('click', 'a[href]', function(e) {
// target element id
var id = jQuery(this).attr('href');
if (!id.match(/^#/) || jQuery(id).length === 0 || jQuery(this).hasClass('ui-tabs-anchor')) {
return;
}
// prevent standard hash navigation (avoid blinking in IE)
/**
* Based on goog.userAgent.flash
* @license Apache-2.0
* @see {@link https://code.google.com/p/closure-library/source/browse/closure/goog/useragent/flash.js}
*/
function getFlashVersion() {
var getVersion = function(desc) {
var matches = desc.match(/[\d]+/g);
if (!matches) {
return "";
@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,
@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 / 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:1345948
Created November 7, 2011 19:48
Generate patch file
diff -rupN original/ new/ > original.patch
@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: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: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()})();