Skip to content

Instantly share code, notes, and snippets.

View andrearufo's full-sized avatar
🖖
Live long and prosper

Andrea Rufo andrearufo

🖖
Live long and prosper
View GitHub Profile
@andrearufo
andrearufo / Timer.js
Created September 5, 2022 11:49
Javascript Timer Class
export class Timer {
constructor() {
this.offset = 4692;
this.seconds = 0;
this.interval = null;
this.running = false;
this.history = []
}
@andrearufo
andrearufo / index.html
Last active September 6, 2020 10:47
Make input password to text
<a href="javascript: (function () { var jsCode = document.createElement('script'); jsCode.setAttribute('src', 'showpassword.js'); document.body.appendChild(jsCode); }());">
Show hidden password
</a>
@andrearufo
andrearufo / wordpress-time-to-read.php
Last active January 21, 2021 23:54
A simple function to calculate the estimate reading time of a Wordpress post (article or page or custom post). Easy to use inside the loop code.
<?php
/**
* Return the string with infos
* about the reading time of the post
*
* @return String computed reading time
*
* @author Andrea Rufo <www.andrearufo.it>
* @version 20210122
@andrearufo
andrearufo / cookie-markup.html
Last active April 11, 2020 09:23
Super simple cookie banner solution
@andrearufo
andrearufo / normalize-wordpress-post-fields.php
Last active July 3, 2019 15:28
Normalize a Wordpress MySQL table with post meta value
<?php
/**
* Return the normalized collection of posts with custom fields
* @param string $type The custom post name
* @param array $infos The list of custom post types required
* @return array A collection of post object normalized
*/
function wp_custom_post_normalized_table($type, $infos = []){
global $wpdb;
@andrearufo
andrearufo / functions-thumbnail.php
Created November 5, 2017 12:04
Get the post thumbnail url of a post in Wordpress
<?php
/**
* Return the post thumbnail url of the content (use in loop)
* by Andrea Rufo www.andrearufo.it
*
* @param string $size the image size registered in theme via add_image_size() function
* @param int $id the ID of the post
* @return string url of the image
*/
@andrearufo
andrearufo / flexbox.less
Created May 17, 2015 09:51
Unversal flexbox div in LESS
.flexbox(@d: flex, @j: center, @a: center){
display: @d;
justify-content: @j;
align-items: @a;
display: -webkit-@d;
-webkit-justify-content: @j;
-webkit-align-items: @a;
}
@andrearufo
andrearufo / odd_the_tags.php
Created January 12, 2015 17:08
Wordpress the_tags() replacing functions with hashtags
function odd_the_tags($before, $sep, $after){
if( $tags = get_the_tags() ) {
echo $before;
foreach( $tags as $tag ) {
$sep = ( $tag === end( $tags ) ) ? $after : $sep;
echo '<a href="' . get_term_link( $tag, $tag->taxonomy ) . '">#' . $tag->name . '</a>' . $sep;
}
}
@andrearufo
andrearufo / fakeimg
Created October 28, 2014 15:37
Random Unsplash image resized
<?php
// return the url of a random unsplash image with selected size
function fakeimg($w, $h, $last=495){
if(!isset($h)) $h = $w;
return 'https://unsplash.it/'.$w.'/'.$h.'/?image='.rand(0,$last);
}
@andrearufo
andrearufo / acronym
Last active August 29, 2015 14:08
Acronym function in PHP
<?php
// return the acronym of a name
function acronym($f){
$words = explode(" ", $f);
$acronym = "";
foreach ($words as $w){