Skip to content

Instantly share code, notes, and snippets.

@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 / 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: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: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: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: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 / controller.php
Created December 19, 2012 15:45
CakePHP: Dynamic Validation Rules
<?php
class UsersController extends AppController {
[...]
$this->User->setValidationRule('account');
[...]
@olimortimer
olimortimer / ral_colours.php
Last active April 22, 2023 16:19
PHP: RAL Colours as RGB
<?php
// Includes text RGB to show text as white or black. This value was calculated using;
// $brightness = sqrt( (R * R * .299) + (G * G * .587) + (B * B * .114) )
// If $brightness was greater than 130, then the text was set to white
$ral_colours => array(
'RAL 1000' => array(
'rgb' => '190,189,127',
'name' => 'Green Beige',
@olimortimer
olimortimer / rebuild_tree.php
Last active March 17, 2019 08:04
PHP: Convert 'Adjacency List Model' database to a 'Nested Set Model' database
<?php
rebuild_tree(1, 1);
function rebuild_tree($parent_id, $left) {
// The right value of this node is the left value + 1
$right = $left+1;
// Get all children of this node
@olimortimer
olimortimer / gist:5299980
Created April 3, 2013 10:11
Create chained dropdowns on the fly
<select name="location_tree[1]" id="location-tree-1">
<option value="0" selected="selected">Please Select...</option>
<option value="2">Africa</option>
<option value="203">Asia</option>
<option value="332">Asia Pacific</option>
<option value="1299">Caribbean</option>
<option value="1749">Central America</option>
<option value="1925">Europe</option>
<option value="17949">India &amp; Indian Ocean</option>
<option value="18058">Middle East</option>