Skip to content

Instantly share code, notes, and snippets.

View unfulvio's full-sized avatar
🇹🇼

Fulvio Notarstefano unfulvio

🇹🇼
  • Taipei, Taiwan
View GitHub Profile
@unfulvio
unfulvio / vagrant_setdate.sh
Last active June 30, 2022 16:33
How to change server time on a Vagrant box on Virtualbox
#!/bin/bash
# Log in into the box
vagrant ssh
# VirtualBox syncs host time with guest, so we need to shut off VBox Guest Additions first
sudo service vboxadd-service stop
# Now you can set any date and time
sudo date -s "2020-10-01 10:25:00"
@unfulvio
unfulvio / epson-iscan-networked-scanner.md
Created July 5, 2017 04:14
Get Epson iScan to work in Ubuntu with a networked/wireless scanner

If you see this error upon starting iScan aka "Image Scan for Linux":

“Could not send command to scanner. Check the scanner’s status.”

It means the iScan couldn't find the scanner. This happens often if it's not connected via USB, but lives in a wireless network for instance.

Do the following:

cd /etc/sane.d/
@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
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 / 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 / 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 / m_array_keys_from_string.php
Created June 29, 2015 10:25
Make a multidimensional array with keys from a string with a variable amount of key names placed between square brackets
<?php
/**
* Problem:
* Given a string similar to '[key][subkey][otherkey]'
* we want to make a multidimensional array $array['key']['subkey']['otherkey']
*
* Original question on Stackoverflow:
* @link http://stackoverflow.com/questions/31103719/php-make-a-multidimensional-associative-array-from-key-names-in-a-string-separat/31104168
* There are alternative solutions posted.
*/
@unfulvio
unfulvio / uninstall.sh
Last active June 12, 2018 19:04
Remove Intel Graphics Drivers for Linux and roll back to defaults in Ubuntu
#Source: http://theclonker.de/?p=89
sudo apt-get update
sudo sh -c 'echo "\nPackage: *\nPin: release a=trusty*\nPin-Priority: 1001\n\nPackage: *\nPin: origin download.01.org\nPin-Priority: -100\n" > /etc/apt/preferences.d/intel-removal'
sudo apt-get dist-upgrade
sudo rm /etc/apt/preferences.d/intel-removal
sudo rm /etc/apt/sources.list.d/intellinuxgraphics.list*
sudo apt-get update
# Use the following to find your i915 driver versions:
# dpkg --get-selections | grep i915
# then replace the version you find here and execute this line:
@unfulvio
unfulvio / functions.php
Created February 13, 2017 13:02 — forked from mgibbs189/functions.php
FacetWP - WooCommerce Memberships fix
<?php
add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) {
if ( 'wc_user_membership' == $query->get( 'post_type' ) ) {
$is_main_query = false;
}
return $is_main_query;
}, 10, 2 );
@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)