Skip to content

Instantly share code, notes, and snippets.

View madeingnecca's full-sized avatar
🏠
Working from home

Damiano Seno madeingnecca

🏠
Working from home
  • Venice - Italy
View GitHub Profile
@madeingnecca
madeingnecca / gist:3790046
Created September 26, 2012 19:31
MYSQL utils
# Execute query from string.
mysql -D <DATABASE> -h <HOST> -u <USER> -p -e 'DELETE FROM table';
# Dump only tables with specific prefix. *NEEDS REVISION*
mysqldump -u <USER> -p <DATABASE> $(mysql -u <USER> -p -D <DATABASE> -Bse "SHOW TABLES LIKE 'PREFIX_%'");
@madeingnecca
madeingnecca / gist:3790060
Last active October 11, 2015 02:38
IMAGEMAGICK utils
# Convert a list of pngs to an animated gif.
convert -delay 20 -loop 0 *.png animation.gif
# Resize image
convert image.jpg -resize 150x image_resized.jpg
# Resize and crop to size.
# Note: specify the smallest dimension in -resize.
convert image.jpg -resize x300 -gravity center -crop 400x300+0+0 image_resized_and_cropped.jpg
@madeingnecca
madeingnecca / gist:3790097
Last active October 11, 2015 02:38
APACHE utils
# Canonical host name for your website.
# THANKS DRUPAL7.
# If your site can be accessed both with and without the 'www.' prefix, you
# can use one of the following settings to redirect users to your preferred
# URL, either WITH or WITHOUT the 'www.' prefix. Choose ONLY one option:
#
# To redirect all users to access the site WITH the 'www.' prefix,
# (http://example.com/... will be redirected to http://www.example.com/...)
RewriteCond %{HTTP_HOST} .
@madeingnecca
madeingnecca / gist:3790129
Created September 26, 2012 19:43
WORDPRESS db utils
# Reset post metas.
delete from wp_postmeta where post_id in (select ID from wp_posts where post_type in('attachment','revision','post'))
# Reset posts.
delete from wp_posts where post_type in('attachment','revision','post')
# Migrate blog, from domainOLD.com to domain.com.
update wp_options set option_value = 'http://domain.com' where option_name = 'siteurl';
update wp_options set option_value = 'http://domain.com' where option_name = 'home';
update wp_posts set guid = replace(guid, 'http://domainOLD.com', 'http://domain.com');
@madeingnecca
madeingnecca / gist:3790169
Last active October 11, 2015 02:38
PHP - current directory size (exec)
<?php
header("Content-type: text/plain; charset=utf8");
$pwd = dirname(__FILE__);
print "$pwd\n";
print exec("du -ch " . escapeshellarg($pwd));
@madeingnecca
madeingnecca / gist:4130191
Created November 22, 2012 09:28
CSS - devices media query
/* Thanks http://css-tricks.com/snippets/css/media-queries-for-standard-devices/ */
/* Smartphones (portrait and landscape) ----------- */
@media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
/* Styles */
}
/* Smartphones (landscape) ----------- */
@madeingnecca
madeingnecca / gist:4160553
Last active July 14, 2017 00:48
BASH utils
#!/bin/bash
# Cleans directory from cvs dir/files.
# http://snippets.dzone.com/posts/show/934
find "$1" -name 'CVS' -exec rm -rf '{}' \; -print
# Generate fake file with a specific size (useful for uploads)
head -c 3000000 /dev/urandom > upload_test_3MB.zip
# Extracts count per page name in an access_log Apache file
@madeingnecca
madeingnecca / gist:5160671
Created March 14, 2013 11:34
MYSQL - list columns of a table
SELECT column_name,column_type
FROM information_schema.columns
WHERE table_schema = DATABASE()
AND table_name='table'
ORDER BY ordinal_position;
@madeingnecca
madeingnecca / gist:5171501
Last active December 15, 2015 00:18
DRUPAL 7 - get ID from entity
<?php
// Method 1: get both id key and id value. Verbose way.
$entity_wrapper = entity_metadata_wrapper($entity_type, $entity);
$pri = $entity_wrapper->entityKey('id');
$entity_id = $entity_wrapper->$pri->value();
// Method 2: get only id value. More succint way.
list($entity_id) = entity_extract_ids($entity_type, $entity);
@madeingnecca
madeingnecca / gist:5211505
Created March 21, 2013 08:25
MULTIMEDIA - video/audio samples
http://static.bouncingminds.com/ads/5secs/baileys_5sec.mp4
http://static.bouncingminds.com/ads/5secs/dodson_5sec.mp4
http://static.bouncingminds.com/ads/15secs/dogs_600.mp4
http://static.bouncingminds.com/ads/15secs/dogs_600.flv
http://static.bouncingminds.com/ads/15secs/horse_how_to_600.mp4