Skip to content

Instantly share code, notes, and snippets.

@elfeffe
elfeffe / gist:11294549
Created April 25, 2014 16:02
Clean inputs on focus, and refill on blur
<script type="text/javascript">
jQuery.fn.doCleanInputs = function () {
jQuery(this).each(function() {
var default_value = this.value;
jQuery(this).focus(function(){
if(this.value == default_value) {this.value = '';}
});
jQuery(this).blur(function(){
if(this.value == '') {this.value = default_value;}
@elfeffe
elfeffe / attributes-values.txt
Last active September 26, 2015 12:25
Find all values for one attribute in Magento by SQL
SELECT DISTINCT value FROM catalog_category_entity_varchar WHERR attribute_id = 1906
ORDER BY value DESC
SELECT
table_schema as `Database`,
table_name AS `Table`,
round(((data_length + index_length) / 1024 / 1024), 2) `Size in MB`
FROM information_schema.TABLES
ORDER BY (data_length + index_length) DESC;
SELECT table_schema "Data Base Name",
sum( data_length + index_length ) / 1024 /
1024 "Data Base Size in MB",
sum( data_free )/ 1024 / 1024 "Free Space in MB"
FROM information_schema.TABLES
GROUP BY table_schema ;
set @a=null,@c=null,@b=concat("show tables where",ifnull(concat(" `Tables_in_",database(),"` like '",@c,"' and"),'')," (@a:=concat_ws(',',@a,`Tables_in_",database(),"`))");
Prepare `bd` from @b;
EXECUTE `bd`;
DEALLOCATE PREPARE `bd`;
set @a:=concat('optimize table ',@a);
PREPARE `sql` FROM @a;
EXECUTE `sql`;
DEALLOCATE PREPARE `sql`;
SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE';
show global status like '%Threads_connected%';
show global status like 'open%';
@elfeffe
elfeffe / optimize_media.sh
Created October 18, 2016 09:10 — forked from colinmollenhour/optimize_media.sh
Optimize PNG and JPEG images - incrementally
#!/bin/bash
#
# Optimize all jpg and png files in the cwd
# Run it again to optimize new files since the last run
#
# Example:
# echo "optimize_media.sh > /tmp/optimize.log" | sudo -u www-data bash -s
#
# Colin Mollenhour 2016
@elfeffe
elfeffe / mysqlsnapshot.sh
Created October 18, 2016 09:10 — forked from colinmollenhour/mysqlsnapshot.sh
MySQL Snapshot Script
#!/bin/bash
DBNAME=mwe
SNAPSHOT_DAYS=7
ARCHIVE_DAYS=60
mysqldump=/usr/bin/mysqldump
gzip=/bin/gzip
function error() {
echo $1 >> $logfile.tmp
@elfeffe
elfeffe / mongobackup.sh
Created October 18, 2016 09:13 — forked from colinmollenhour/mongobackup.sh
Simple daily dump of mongo databases.
#!/bin/bash
cd /media/dumps
name=$(date +%b-%d)
year=$(date +%Y)
[ -d $year ] || mkdir $year || { echo "Could not create directory '$year'"; exit 1; }
mongodump --db t3_mage --out $name &> mongodump.log
if [ $? ]; then
tar -czf snapshots/$year/$name.tgz $name
if [ $(($(date +%d | sed 's/^0*//') % 10)) == 0 ]; then