This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Duplicate count | |
SELECT <column>, COUNT(*) count FROM <table> GROUP BY <column> HAVING count > 1; | |
-- Find duplicates | |
SELECT * FROM <table> | |
INNER JOIN (SELECT <column> FROM <table> | |
GROUP BY <column> HAVING count(id) > 1) duplicate ON <table1>.<column> = duplicate.<column> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Used to pad numbers inputs to 2 decimal places | |
function padNumber($input) { | |
// Rather than store $(this).val(), it's best to keep checking for changes | |
// When we move off the input | |
$input.on('blur', function () { | |
// Ignore if there's no value | |
if ($(this).val() === '') return; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('#select2').select2({ | |
data: data, | |
// Add our 'needsclick' to each item, so FastClick doesn't get applied | |
formatResult: function(result, container, query, escapeMarkup) { | |
container.addClass('needsclick'); | |
return result.text; | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add our 'needsclick' to our a href for each item, so FastClick doesn't get applied | |
$('#typehead').data('typeahead').render = function (items) { | |
// We basically do what the normal typeahead function does... | |
var that = this; | |
items = $(items).map(function (i, item) { | |
i = $(that.options.item).attr('data-value', item); | |
// ...but we add 'needsclick' to the a href | |
i.find('a').addClass('needsclick').html(that.highlighter(item)); | |
return i[0]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function randomPassword($length = 8) { | |
$password = false; | |
$characters = 'abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789'; | |
$charsLength = strlen($characters) - 1; | |
for ($i = 0; $i < $length; $i++) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function parse_csv($filepath, $namedfields = true) { | |
$max_row_size = 0; // Maximum row size - 0 is unlimited | |
$delimiter = ','; // The field delimiter | |
$enclosure = '"'; // The field enclosure character | |
$fields = $content = false; | |
// Open our files |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- This finds all records with non-ASCII characters | |
SELECT * FROM locations WHERE NOT HEX(name) REGEXP '^([0-7][0-9A-F])*$'; | |
UPDATE locations SET name = REPLACE(name, '‡', 'á'); -- HEX E280A1 / HEX C3A1 | |
UPDATE locations SET name = REPLACE(name, 'Ž', 'é'); -- HEX C5BD / HEX C3A9 | |
UPDATE locations SET name = REPLACE(name, 'Ÿ', 'ü'); -- HEXC5B8 / HEX C3BC | |
UPDATE locations SET name = REPLACE(name, 'š', 'ö'); -- HEX C5A1 / HEX C3B6 | |
UPDATE locations SET name = REPLACE(name, 'Š', 'ä'); -- HEX C5A0 / HEX C3A4 | |
UPDATE locations SET name = REPLACE(name, '§', 'ß'); -- HEX C2A7 / HEX C39F | |
UPDATE locations SET name = REPLACE(name, 'Õ', '\''); -- HEX C395 / HEX 27 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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 & Indian Ocean</option> | |
<option value="18058">Middle East</option> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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', |