Skip to content

Instantly share code, notes, and snippets.

@pandauxstudio
pandauxstudio / gist:6400924
Created August 31, 2013 22:05
Query to replace a part of a string in a db column.
UPDATE `Resource`
SET FileName = REPLACE(FileName, '/trt/web', '')
WHERE FileName LIKE ('/trt/web%');
@pandauxstudio
pandauxstudio / gist:7352116
Last active December 27, 2015 15:59
Drop all database tables with/without MySQL login.
# With MySQL login
DROP DATABASE dbName;
CREATE DATABASE dbName;
# Without MySQL login
/usr/bin/mysqldump -uuser_name -psecretpassword --add-drop-table database_name | grep ^DROP | /usr/bin/mysql -uuser_name -psecretpassword database_name
@pandauxstudio
pandauxstudio / gist:7556974
Created November 20, 2013 03:02
Synchronise two selected.
var countrySelects = $('[name="addresscountry"], [name="deliverycountry"]');
countrySelects.change(function(e) {
countrySelects.val(this.value);
});
@pandauxstudio
pandauxstudio / gist:8045773
Created December 19, 2013 20:31
Add image placeholder if image is not found.
$("img").error(function () {
$(this).attr('src', '/images/photo-placeholder.jpg');
});
@pandauxstudio
pandauxstudio / gist:8066425
Created December 21, 2013 07:18
Remove past months of months select of current year
removePastMonths = function (selectedYear, momentId) {
var curYear = (new Date).getFullYear();
var curMonth = (new Date).getMonth();
var monthSelect = $("#doneMomentMonth");
var monthSelectOptions = $("#doneMomentMonth > option");
// If current year is selected, remove past months
if (selectedYear == curYear) {
@pandauxstudio
pandauxstudio / gist:8310908
Created January 8, 2014 02:43
Basic image cropping.
function momentImgResize(img, maxWidth, maxHeight) {
if (img.data('type') == 'placeholder') {
return;
}
var widthHeightRatio = 1.5;
var imgWidth = img.width();
var imgHeight = img.height();
$monthName = date("F", mktime(0, 0, 0, $monthNum, 10));
@pandauxstudio
pandauxstudio / gist:9101728
Created February 19, 2014 21:14
Timezone-Adjusted Timestamp
// Source: http://stackoverflow.com/questions/2834353/php-how-do-i-convert-a-server-timestamp-to-the-users-timezone
$timestamp = time();
echo 'Unix timestamp: ' . $timestamp;
$dt = DateTime::createFromFormat('U', $timestamp);
$dt->setTimeZone(new DateTimeZone($timezone));
$adjusted_timestamp = $dt->format('U') + $dt->getOffset();
echo ' Timestamp adjusted for: ' . $timezone . $adjusted_timestamp;
@pandauxstudio
pandauxstudio / gist:9379460
Last active August 29, 2015 13:57
Change database and table character set, this is useful for supporting Arabic language
ALTER DATABASE databasename CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE tablename CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
Exec mysql client as root
$ mysqld -u mysql --skip-grant-tables &
Update your password
$ mysql -u root
Reload privileges
mysql> update mysql.user set password=password('newpassword') where user='root';
Kill mysqld