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 / titleIndex.js
Created March 16, 2014 08:06
How to create an index of titles in a HTML page with jQuery
$(window).ready( function(){
var titid = 0;
$('.documentation h3').each(function(){
titid = titid+1;
$(this).attr('id', 'tit'+titid);
$('#indice').append('<li><a href="#tit' + titid + '">' + $(this).text() + '</a></li>');
})

A simple html+css popup at page open

When you open the page, a series of divs appears over your content with important messages or images. You can close it with a simple click !

A Pen by Andrea Rufo on CodePen.

License.

@andrearufo
andrearufo / gaussiandice
Created September 18, 2014 22:10
Super simple Gaussian distribution with two dice
<pre>
<?php
$n = 10000;
$min = 1;
$max = 20;
$values = array();
@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){
@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 / 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 / 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 / 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 / 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 / cookie-markup.html
Last active April 11, 2020 09:23
Super simple cookie banner solution