Skip to content

Instantly share code, notes, and snippets.

@marciomassari
marciomassari / start.sql
Created July 18, 2018 23:33
MySQL command line
mysql -u root -p
@marciomassari
marciomassari / slackspotify.sh
Created July 10, 2018 21:01
Script To Set Current Spotify Song As Slack Status
#!/bin/bash
APIKEY="SPOTIFY-API-KEY"
trap onexit INT
function reset() {
echo 'Resetting status'
curl -s -d "payload=$json" "https://slack.com/api/users.profile.set?token="$APIKEY"&profile=%7B%22status_text%22%3A%22%22%2C%22status_emoji%22%3A%22%22%7D" > /dev/null
}
@marciomassari
marciomassari / bash_profile.sh
Last active September 15, 2018 00:07
Raspberry Bash Profile
#!/bin/bash
let upSeconds="$(/usr/bin/cut -d. -f1 /proc/uptime)"
let secs=$((${upSeconds}%60))
let mins=$((${upSeconds}/60%60))
let hours=$((${upSeconds}/3600%24))
let days=$((${upSeconds}/86400))
UPTIME=`printf "%d days, %02dh%02dm%02ds" "$days" "$hours" "$mins" "$secs"`
# get the load averages
read one five fifteen rest < /proc/loadavg
@marciomassari
marciomassari / functions.php
Last active November 8, 2020 12:32
WooCommerce - Show category images on single product page
<?php
$terms = get_the_terms( $post->ID, 'product_cat' );
foreach ( $terms as $term ){
$category_name = $term->name;
$category_thumbnail = get_woocommerce_term_meta($term->term_id, 'thumbnail_id', true);
$image = wp_get_attachment_url($category_thumbnail);
echo '<img src="' . $image . '" alt="' . $term->name . '" />';
}
?>
@marciomassari
marciomassari / redirect-fb.html
Last active July 7, 2017 12:48
Launch Facebook App from Browser
<!-- Find Facebook ID on https://findmyfbid.com -->
<!-- Fanpage -->
<a href="fb://page/facebook_id">Launch Facebook App</a>
<!-- Profile -->
<a href="fb://profile/facebook_id">Launch Facebook App</a>
@marciomassari
marciomassari / template-page.php
Created July 6, 2017 21:18
Wordpress - List Child Pages on Template Page
<?php
$args = array(
'post_parent' => $post->ID,
'post_type' => 'page',
'orderby' => 'menu_order'
);
$child_query = new WP_Query( $args );
?>
@marciomassari
marciomassari / masked_init.js
Last active March 3, 2017 13:22
Brazilian Input Mask for jQuery Masked Input Plugin
//CPF
$("input.cpf").mask("999.999.999-99");
//Data Nascimento
$("input.nascimento").mask("99/99/9999");
//CEP
$("input.cep").mask("99999-999");
//Telefone
@marciomassari
marciomassari / alt_images.php
Created January 23, 2017 16:24
Alt WP Images
<?php
if(empty($alt_text)) // If not, Use the Caption
{
$attachment = get_post($post->ID);
$alt_text = trim(strip_tags( $attachment->post_excerpt ));
}
if(empty($alt_text)) // Finally, use the title
{
$attachment = get_post($post->ID);
$alt_text = trim(strip_tags( $attachment->post_title ));
@marciomassari
marciomassari / functions.php
Last active January 23, 2017 14:15
Remove Query Strings
<?php
function _remove_script_version( $src ){
$parts = explode( '?ver', $src );
return $parts[0];
}
add_filter( 'script_loader_src', '_remove_script_version', 15, 1 );
add_filter( 'style_loader_src', '_remove_script_version', 15, 1 );
?>
@marciomassari
marciomassari / wp-cli-install.sh
Last active May 9, 2021 14:03
WP-CLI - Install WordPress
// install WordPress
wp core download --locale=pt_BR
// configuration wp-config.php
wp core config --dbname=testecli --dbuser=root --dbpass=root --dbprefix=wp_ --locale=pt_BR
// generate database
wp db create
// install WordPress