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 / frames_server.php
Created February 3, 2014 22:42
PHP - Frames Server
<?php
define('FRAMES_COUNT', 100);
define('FRAME_FORMAT', 'frames/frame%04s.jpg');
define('CONTENT_TYPE', 'image/jpg');
$base = dirname(__FILE__);
$next = (int) $_COOKIE['next_frame'];
$frame = $base . '/' . sprintf(FRAME_FORMAT, $next);
@madeingnecca
madeingnecca / map.geojson
Last active January 4, 2016 05:38
Test map
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@madeingnecca
madeingnecca / gist:6704301
Last active December 23, 2015 22:39
DRUPAL 7 - variables
# "Development" variables.
drush vset cache 0;
drush vset block_cache 0;
drush vset cache_lifetime 0;
drush vset page_cache_maximum_age 0;
drush vset page_compression 0;
drush vset preprocess_css 0;
drush vset preprocess_js 0;
# Set a better default for registration setting.
@madeingnecca
madeingnecca / cpinput.php
Last active December 17, 2015 15:19
PHP - copy input files and dirs.
<?php
// Usage: cd SRC; pbpaste | sort | php cpinput.php DEST.
$cwd = getcwd();
$dest = $argv[1];
$mode = 0777;
while (($f = trim(fgets(STDIN)))) {
if (is_dir("$cwd/$f")) {
mkdir("$dest/$f", $mode, TRUE);
}
@madeingnecca
madeingnecca / gist:5580161
Created May 14, 2013 22:25
MULTIMEDIA - video to gif
# Extract frames. One every 1 second(s)
ffmpeg -i video.mp4 -r 1 scenes/scene_%04d.png
# Convert png to png8 to decrease size.
for f in $(ls scenes | grep -i png); do convert "scenes/$f" "PNG8:scenes/$f"; done;
# Create animation
convert -delay 100 -loop 0 scenes/*.png animation.gif
@madeingnecca
madeingnecca / gist:5540710
Last active December 17, 2015 03:08
DRUPAL - views get count query
<?php
// Inspired by: /sites/all/modules/views/plugins/views_plugin_query_default.inc
$view = views_get_view($view_name);
$view->build('default');
$count_query = $view->build_info['count_query'];
$count_query->addMetaData('view', $view);
$base_table_data = views_fetch_data($view->base_table);
$access_tag = $base_table_data['table']['base']['access query tag'];
@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
@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: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: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