Skip to content

Instantly share code, notes, and snippets.

View listenrightmeow's full-sized avatar
🦍

Mike Dyer listenrightmeow

🦍
View GitHub Profile
@listenrightmeow
listenrightmeow / params.js
Created February 7, 2012 22:53
queryParams
queryParams: function() {
var query = {},
search = window.location.search,
fields = ['postalcode', 'range', 'franchise'];
fields.map(function(param){
var p = escape(unescape(param)),
regex = new RegExp("[?&]" + p + "(?:=([^&]*))?","i"),
match = regex.exec(search);
if(match == null) return;
log = function (kwargs) {
try {
var console = window.console,
debug =
window.location.toString().indexOf('_mode=debug') !== -1;
kwargs = $.extend({
name: '',
id: '',
args: []
@listenrightmeow
listenrightmeow / remove.js
Created April 20, 2012 01:28
Extend JS natives
Array.prototype.remove = function(member) {
var index = this.indexOf(member);
index > -1 && this.splice(index, 1);
}
return this;
}
['one', 'two', 'three'].remove('two');
['four', 'five', 'six'].remove('three');
<?php defined('SYSPATH') or die('No direct access allowed.');
/*
* Author : Mike Dyer
* @Anchor.php
*
* @params :
* uri : anchor location
* title : anchor text
* attrs : valid anchor attributes
*
Kohana::modules(array(
// 'auth' => MODPATH.'auth', // Basic authentication
// 'cache' => MODPATH.'cache', // Caching with multiple backends
// 'codebench' => MODPATH.'codebench', // Benchmarking tool
// 'database' => MODPATH.'database', // Database access
// 'image' => MODPATH.'image', // Image manipulation
// 'orm' => MODPATH.'orm', // Object Relationship Mapping
// 'unittest' => MODPATH.'unittest', // Unit testing
// 'userguide' => MODPATH.'userguide', // User guide and API documentation
'ui' => MODPATH.'ui', // Load custom UI module
@listenrightmeow
listenrightmeow / assets.rake
Last active February 14, 2017 06:21
Rails 3 asset pipeline deploy task with s3 and cloudfront support
namespace :assets do
desc 'Precompile assets and upload to S3'
task :sync => :environment do
assets = build_asset_dir
raise 'asset directory is empty: aborting' unless assets.size > 1
invalid_files = build_assets assets
delete_old_assets assets
invalidate_files invalid_files unless invalid_files.empty?
x = setInterval(function(){
--w >= 0 ? console.log([w / 86400, (w / 3600) % 24, (w / 60) % 60, w % 60].map(function(n){
return n < 10 ? '0' + ~~n : ~~n
}).join(':')) : clearInterval(x);
}, [1e3, w = 10][0]);
@listenrightmeow
listenrightmeow / week.php
Created February 26, 2013 23:31
Build array of dates from defined date object
$cols = array();
$date = new DateTime(date('Y-m-d', strtotime('-1 week')));
for ($i = 0; $i < 7; $i++) {
$cols[$date->format('l')] = array(
'label' => $date->format('Y-m-d')
);
$date->modify('+1 day');
@listenrightmeow
listenrightmeow / ssllogo.php
Created March 26, 2013 18:40
Crop and letterbox PHP GD image
<?php
$url = $_REQUEST['image'];
$max_width = 500;
$max_height = 500;
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
@listenrightmeow
listenrightmeow / leaflet.js
Created April 3, 2013 22:44
Production leaflet.js example
var Leaflet = Fidel.declare({
defaults : {
imperial : 1609.344,
locations : [],
map : null,
markers : [],
options : {},
pin : {
size : {
w : 48,