Skip to content

Instantly share code, notes, and snippets.

View unfulvio's full-sized avatar

Fulvio Notarstefano unfulvio

  • Fukuoka, Japan
  • 21:47 (UTC +09:00)
View GitHub Profile
@unfulvio
unfulvio / .htaccess
Created June 12, 2013 02:32
Protect a website folder (or root) with http password using .htaccess and .htpasswd
AuthUserFile /local/path/.htpasswd
AuthType Basic
AuthName "Insert a message here"
Require valid-user
@unfulvio
unfulvio / dt-toggle.js
Created June 17, 2013 14:33
Make every <dd> (definition description) element in a <dl> (definition llist) toggleable by the <dt> (definition term) element. Useful for creating toggleable lists, FAQs lists, etc.
$('#dl-container-id').on('click', 'dt.class-name', function() {
$(this).next().toggle();
});
@unfulvio
unfulvio / functions.php
Last active July 15, 2021 05:17
WordPress HTML Minification Class to compress HTML (removal of whitespaces, line breaks, new lines, comments). Preserves script comments (if removed might break some javascripts like Google Analytics or Adsense) and IE specific tags.
/* Minifies HTML and removes comments (except IE tags and comments within script tags)
*
* To disable compression of code portions, use '<!--wp-html-compression no compression-->' tag
*
* @see http://forrst.com/posts/Wordpress_Minify_output_HTML-29q
* @see http://www.intert3chmedia.net/2011/12/minify-html-javascript-css-without.html
*/
class WP_HTML_Compression
{
// Settings
@unfulvio
unfulvio / functions.php
Last active August 29, 2015 13:56
Just a self updating copyright year range
<?php
/**
* Copyright Years
* Outputs an years range based on specified year to current year
*
* @param int $copyYear - the year since the copyright starts (should be lower than current year)
* @return string - a range of years (eg. "2000-2010")
*/
function copyright( $copyYear ) {
@unfulvio
unfulvio / functions.php
Created March 6, 2014 02:27
WordPress: get only terms connected to posts of a specified type
<?php
/**
* Get Terms used by Post Type
* Fetches only terms actually used by posts of a specified post type
*
* @param string $taxonomy the taxonomy to look for terms
* @param string $post_type the post type to match the taxonomy terms found
*
* @return array the query result (an array of taxonomy terms as objects)
@unfulvio
unfulvio / functions.php
Created July 9, 2014 08:08
Limit WordPress media uploader maximum upload file size
<?php
/**
* Limit WordPress media uploader maximum upload file size
* Uploading very large images is pointless as they will hardly ever be used at full size.
* Crunching larger files takes more memory; larger files take more space too.
*
* @param mixed $file the uploaded file item to filter
*
* @return array $file the filtered file item with response
@unfulvio
unfulvio / functions.php
Created July 9, 2014 08:35
WordPress development: define WP_DEBUG conditionally using cookies
<?php
/**
* Sets a 'wp_debug' cookie for logged in WordPress administrators
* In conjunction with a properly configured wp-config.php, it can enable WP_DEBUG mode conditionally.
*
* @link http://wordpress.stackexchange.com/questions/69549/define-wp-debug-conditionally-for-admins-only-log-errors-append-query-arg-f
*/
function set_admin_debug_cookie( $user_login, $user ) {
@unfulvio
unfulvio / collation.php
Last active January 13, 2021 12:57
PHP Script to alter and convert all tables in a MySQL database to use a different character set and collation
<?php
// enter your database name
$database_name = 'name';
// enter your database user name
$database_username = 'user';
// enter your database user password
$database_password = 'password';
$connection = mysql_connect( 'localhost', $database_username, $database_password );
@unfulvio
unfulvio / thinkpad.sh
Created May 30, 2015 14:11
Fix to re-enable Bluetooth on Thinkpad machines in Ubuntu in the event of a hardware hard off switch
echo options thinkpad_acpi dbg_bluetoothemul=1 bluetooth_state=1 | sudo tee -a /etc/modprobe.d/thinkpad_acpi.conf
@unfulvio
unfulvio / example.sh
Created June 19, 2015 11:05
Add all unversioned files to SVN
# See: http://stackoverflow.com/questions/1071857/how-do-i-svn-add-all-unversioned-files-to-svn
svn add --force * --auto-props --parents --depth infinity -q