Skip to content

Instantly share code, notes, and snippets.

@olimortimer
olimortimer / controller.php
Created December 19, 2012 15:45
CakePHP: Dynamic Validation Rules
<?php
class UsersController extends AppController {
[...]
$this->User->setValidationRule('account');
[...]
@olimortimer
olimortimer / gist:4223236
Created December 6, 2012 09:30
PHP: Colour Functions
<?php
/**
* Pretty accurate way of calculating the Luma (Brightness) value
*
* @param array|int|false $r
* @param int|false $g
* @param int|false $b
* @return int
*/
@olimortimer
olimortimer / gist:3898175
Last active October 11, 2015 18:07
PHP: Multi-dimensional sort
<?php
// Sorting a multi-dimensional array (of objects), by price
usort($products, function($a, $b) {
$a = (object) $a;
$b = (object) $b;
if ($a->price == $b->price) {
return 0;
} else {
// return $a->price > $b->price ? -1 : 1; // DESC
return $a->price > $b->price ? 1 : -1; // ASC
@olimortimer
olimortimer / gist:3504331
Created August 28, 2012 21:03
JS: Bootstrap Modal Confirmation (Multiple Records)
<a href="delete?id=1" class="confirm">Delete 1</a>
<a href="delete?id=2" class="confirm">Delete 2</a>
<a href="delete?id=3" class="confirm">Delete 3</a>
<div class="modal hide fade" id="confirm-delete" role="dialog" aria-labelledby="confirm-delete-header" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="confirm-delete-header">Delete Confirmation</h3>
</div>
<div class="modal-body">
@olimortimer
olimortimer / gist:3369299
Created August 16, 2012 11:02
CLI: Magento Permissions
find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
chmod 550 pear
chmod 550 mage
chmod -R 777 media var
@olimortimer
olimortimer / gist:3284352
Created August 7, 2012 10:23
CLI: Magento Install
version=1.7.0.2
wget http://www.magentocommerce.com/downloads/assets/$version/magento-$version.tar.gz
tar -zxvf magento-$version.tar.gz
mv magento/* magento/.htaccess .
chmod -R o+w media var
chmod o+w app/etc
rm -rf magento/ magento-$version.tar.gz
rm -rf index.php.sample LICENSE.txt LICENSE.html LICENSE_AFL.txt php.ini.sample RELEASE_NOTES.txt
@olimortimer
olimortimer / gist:3169001
Created July 24, 2012 09:09
JS: Check for empty response
$.ajax({
url: 'http://www.website.com/ajax',
data: '&ajaxcmd=getSomeInfo&id=' + id,
dataType: 'html',
success:function(output){
var regex = /^\s*$/;
if(regex.test(output)) {
alert('Empty response');
} else {
alert('Not empty');
@olimortimer
olimortimer / jQueryMobileBlock.js
Created July 2, 2012 23:19 — forked from MorningZ/jQueryMobileBlock.js
JS: Block page whilst showing jQuery loading message
/*
The jQuery Mobile "loading" message allows users to click on UI items around it
Using Mike Alsup's BlockUI, we can stop this
http://jquery.malsup.com/block/#download
Thanks to MorningZ
https://gist.github.com/MorningZ
*/
// Add this right before the closing <body> tag
@olimortimer
olimortimer / gist:3032672
Created July 2, 2012 10:48
JS: jQuery Replace HREF Query String
// www.website.com/page?id=100
$('#pageLink').attr('href', $('#pageLink').attr('href').replace(/((\?|&)id\=)[0-9]*/, '$1' + '123'));
// www.website.com/page?id=123
@olimortimer
olimortimer / drop-shadows.htm
Created June 24, 2012 19:56
CSS: Drop-shadows
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>CSS drop-shadows</title>
<style>
body {
padding:20px 0 30px;
font:14px/1.5 Arial, sans-serif;
text-align:center;