Skip to content

Instantly share code, notes, and snippets.

View stefanocudini's full-sized avatar
🏔️
working from Alps

Stefano Cudini stefanocudini

🏔️
working from Alps
View GitHub Profile
@stefanocudini
stefanocudini / format_time.php
Created July 30, 2012 21:52
seconds to h:m:s
<?
function format_time($t,$f=':') // t = seconds, f = separator
{
return sprintf("%02d%s%02d%s%02d", floor($t/3600), $f, ($t/60)%60, $f, $t%60);
}
?>
@stefanocudini
stefanocudini / human2bytes.php
Created September 9, 2012 20:48
convert human to bytes file size
<?
function human2bytes_2($t)
{
if( preg_match("#([0-9.]{1,})(B|KB|MB|GB|TB)#",$t,$maches) )
{
$num = $maches[1];
$unit = $maches[2];
$mm = array('B'=>1,
'KB'=>1024,
@stefanocudini
stefanocudini / bytes2human.php
Created September 9, 2012 21:30
convert size bytes to human
<?
function bytes2human($size)
{
$mod = 1024;
$units = array('B','KB','MB','GB','TB');
for ($i = 0; $size > $mod; $i++) {
$size /= $mod;
}
return round($size, 2).$units[$i];
@stefanocudini
stefanocudini / gist:4175271
Created November 30, 2012 11:33
leaflet draw grid
drawGrid function() {
var xFact = 10,
yFact = 6;
var m = this.map,
bb = m.getBounds(),
xmin = m.latLngToLayerPoint( bb.getNorthWest() ).x,
ymin = m.latLngToLayerPoint( bb.getNorthWest() ).y,
xmax = m.latLngToLayerPoint( bb.getSouthEast() ).x,
@stefanocudini
stefanocudini / thumb.php
Created December 22, 2012 13:55
php images thumbnails generator
<?
/*
generatore di thumbnail
copyleft 2008 Stefano Cudini
stefano.cudini@gmail.com
utilizzo:
<img src="thumb.php?thumb=nomefile.jpg" />
<img src="thumb.php?thumb=nomefile.jpg&tnsize=120&thumbquad=1&tnmargin=2&qualit=90&thumbcut=0&thumbround=1&thumbrad=10" />
*/
@stefanocudini
stefanocudini / tunnel-autossh.sh
Created December 28, 2012 04:06
make tunnel autossh for mounting remte nfs resource
#!/bin/sh
# crea un tunnel ssh che si ricollega in caso di disconnessione
#trasferisce in Remoto sulla porta PREMOTE la porta local PLOCAL
SERV=easyblog.it
USER=tunnel
P_SSH_L=22
P_SSH_R=2222
@stefanocudini
stefanocudini / ping-hosts.sh
Last active December 10, 2015 08:38
ping for multiple hosts, check /etc/hosts is online
#!/bin/sh
HOSTS=/etc/hosts
MEHOST=$(hostname)
DNSHOST=$(cut -d' ' -f2 /etc/resolv.conf)
GWHOST=$(ip route | grep default | cut -d' ' -f3)
IGNORE="^$\|^#\|^127\|$MEHOST\|$DNSHOST"
#echo $IGNORE
HOSTS=$(grep -v $IGNORE $HOSTS | tr '\t' ' ' | cut -d' ' -f1 | sort | uniq)
@stefanocudini
stefanocudini / userip.sh
Created January 25, 2013 18:25
get ip of specifica user logged
#!/bin/bash
#last -i | grep z4k | grep logged | head -n1 | cut -d' ' -f15
if [ ! -z $1 ]; then
who --ips | grep ^$1 | rev | cut -d' ' -f1 | rev | tail -n1
fi
@stefanocudini
stefanocudini / fail2ban-addignoreip.sh
Last active December 11, 2015 17:48
add ignorep in all fail2ban jails
#!/bin/bash
#references:
#http://www.fail2ban.org/wiki/index.php/Commands
if [ -z "$1" ]
then
#echo "specify ip"
exit 0
fi
@stefanocudini
stefanocudini / seltext.js
Created January 25, 2013 23:51
plugin jquery for select html element
(function($){
$.fn.selText = function() {
var obj = this[0];
if ($.browser.msie) {
var range = obj.offsetParent.createTextRange();
range.moveToElementText(obj);
range.select();
} else if ($.browser.mozilla || $.browser.opera) {
var selection = obj.ownerDocument.defaultView.getSelection();
var range = obj.ownerDocument.createRange();