Skip to content

Instantly share code, notes, and snippets.

View aziraphale's full-sized avatar

Andrew Gillard aziraphale

View GitHub Profile
@aziraphale
aziraphale / windowsFixGlobArgv.php
Last active January 11, 2016 16:14
Windows' cmd.exe doesn't expand filename globs passed to PHP (and others). This function expands glob strings in PHP's $argv array.
<?php
/**
* Fixes PHP's $argv array (or, rather, a list of filenames that is assumed to
* come from $argv) to expand glob strings on Windows, where the cmd.exe shell
* doesn't expand globs before passing arguments to called commands/programs.
*
* @link https://gist.github.com/aziraphale/edf8a1b1ad049f4e08ee
* @param array $argv
* @return array
@aziraphale
aziraphale / php-scalar-type-hinting.php
Created May 12, 2015 09:39
Curious hack to allow scalar type hinting in PHP 5.2+
<?php
// Definining these four classes is actually optional; the code functions fine
// without them, but IDEs obviously bitch about undefined classes.
// All have final-private constructors to prevent them ever being instantiated
// (or we could pass *actual objects* of these types to our type-hinted
// functions, where we'd have code that expected a string suddenly finding
// itself dealing with an object!
class string { final private function __construct(){} }
class boolean { final private function __construct(){} }
@aziraphale
aziraphale / gist:7d71b139ed77a30a75ec
Created October 5, 2014 18:45
Get (canonical) URL bookmarklet
javascript:var u; try { u=document.querySelector("link[rel=canonical]").href; } catch (e) {} if(u){ if(prompt("Canonical URL: - Press OK to navigate", u)) { window.location=u; } else { /* Chrome goes silly if I don't do something here */ u=null; } } else { prompt("No canonical URL found. Displaying current URL:", window.location.href); }
@aziraphale
aziraphale / gist:5066105
Created March 1, 2013 17:03
Disable touch events on touchscreen devices when using JoelBesada's ScrollPath plugin (https://github.com/JoelBesada/scrollpath)
// Disable panning around the page on touchscreen devices (as this is totally incompatible with ScrollPath)
$(document).one('touchstart', function(){
$(document).on('touchmove', function(ev){
ev.preventDefault();
});
// Also hide the scrollbar
$('.sp-scroll-bar').hide();
});
@aziraphale
aziraphale / bcrypt-php-times.txt
Created September 4, 2012 08:04
Bcrypt in PHP Timings
To get an idea of the ideal number of bcrypt "rounds" to use for highest security without requiring
excessive CPU time, I wrote a little PHP script to hash a 9-character password with every possible
number of rounds (from 4 to 31), timing how long it takes to perform each hash.
This test was performed on an Intel Core i5-2500 CPU @ 3.3 GHz, running Windows 7 64-bit and
PHP 5.4.0 (x86; VC9; CLI). The machine was being used for general development work at the same
time, but the script was only single-threaded and the development work wasn't particularly heavy,
so the times should be fairly accurate.
RESULTS (times in seconds):
@aziraphale
aziraphale / example.html
Created March 10, 2012 11:47 — forked from maxsum-corin/example.html
Short plugin that implements a vertical buttonset for radio buttons, checkboxes and button elements with jQuery UI (this fork also introduces correct plugin behaviour, re: collections/chainability)
<html>
<head>
<title>Test</title>
<link rel="stylesheet" media="all" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.7/themes/start/jquery-ui.css"></link>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.7/jquery-ui.min.js"></script>
<script src="jquery.myplugin.js"></script>
<script>
$(document).ready(function(){
//call plugin