Skip to content

Instantly share code, notes, and snippets.

View diegolamonica's full-sized avatar

Diego La Monica diegolamonica

View GitHub Profile
@diegolamonica
diegolamonica / timing.js
Created September 5, 2021 16:24
Convert seconds to HH:mm:ss format
function timing(duration) {
const slots = []
duration = Math.ceil(duration)
while (duration > 59 && slots.length < 2) {
slots.push( (duration % 60).toString().padStart(2, '0'))
duration = Math.floor(duration / 60)
}
if( duration > 0 ) slots.push(duration);
return slots.reverse().join(':')
}
@diegolamonica
diegolamonica / humanReadableSize.js
Last active February 16, 2019 19:18
Transforms Bytes measure unit into a human readable format
function humanReadableSize(bytes) {
var sizes = ['b', 'Kb', 'MB', 'GB', 'TB'],
transformed = bytes,
/*
* The lowest measure is byte
*/
index = 0;
/*
* Limits the conversion to managed sizes.
*/
@diegolamonica
diegolamonica / gist:4054526
Created November 11, 2012 10:51
Wordpress: Seeking for multiple post types in the loop
<?php
add_filter('request', 'myCustomRequest', 0);
function myCustomRequest($req){
if(!is_admin()){
/*
* In admin context we will ignore it
*/
if(!isset($req['page'])){
/*
/**
*
* Check if the given date is valid
* @param string $date
*
* @param string $separator
*
* @param string $format defines the order which year month and day are in the $date string
* this string supports "d" for days "m" for month and "y" for year
*
@diegolamonica
diegolamonica / SubmitToServer.htm
Created July 25, 2012 09:51
Submit outer HTML to the Server
<html>
<head>
<script type="text/javascript">
/**
* Submit the outerHTML of the given ElementId to an URL
*
* @param elementId: the ID of the Element which the HTML will be submitted.
* @param page: the url (relaitve to the current page or absolute) to the server page that will receive the html
* @param target (optional): the target of the form, leave it empty to sumbit the content to the same window.