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 / readfileLimit.php
Created March 30, 2012 17:36
php readfile with limit bitrate
<?php
$file = $_SERVER['QUERY_STRING'];
header("Content-length: ".filesize($file));
header("Content-type: ".mime_content_type($file));
readfileLimit($file);
function readfileLimit($file, $limit='20k')
@stefanocudini
stefanocudini / nanogrep.sh
Created April 3, 2012 18:11
nano with grep
#/!bin/bash
line=$(grep $1 $2 -n | cut -d':' -f1)
nano +$line $2
@stefanocudini
stefanocudini / unbanip
Created April 3, 2012 19:30
unban ip from all chains in iptables
#!/bin/bash
chains=$(iptables -L | grep "Chain fail2ban" | cut -d' ' -f2)
for chain in $chains
do
iptables -D $chain -s $1 -j DROP
done
@stefanocudini
stefanocudini / jquery-tooltip.js
Created April 15, 2012 01:06
jquery simplest autocomplete code
$('input:text').focus()
.on('keyup',function(e) {
var hovertag$ = tool$.children('.hover');
switch(e.keyCode)
{
case 38: //freccia su
hovertag$.removeClass('hover').prev('a').addClass('hover');
break;
@stefanocudini
stefanocudini / jquery-contaninsi.js
Created April 26, 2012 21:58
jquery :contains() case insensitive selector
$.extend($.expr[':'], { //definizione di :conaints() case insesitive
'containsi': function(elem, i, match, array)
{
return (elem.textContent || elem.innerText || '').toLowerCase()
.indexOf((match[3] || "").toLowerCase()) >= 0;
}
});
//example
$("a:containsi('text')");
@stefanocudini
stefanocudini / filter-results.js
Created April 27, 2012 14:53
jquery plugin filter results
/*
<label class="count" id="countresults">Results<em></em></label>
<input id="findres" type="text" size="8" value="" />
<div id="actives">
<div id="activesempty">Nessun elemento trovato.</div>
</div>
*/
$(function() {
$('#findres').finder({
@stefanocudini
stefanocudini / select text.js
Created April 28, 2012 18:36
select text range
function createSelection(start, end, field) {
if ( field.createTextRange ) {
/*
IE calculates the end of selection range based
from the starting point.
Other browsers will calculate end of selection from
the beginning of given text node.
*/
@stefanocudini
stefanocudini / perfomance.js
Created May 2, 2012 01:18
javascritp simple test performance
var start = new Date().getMilliseconds();
//operations
var end = new Date().getMilliseconds();
var diff = end - start;
console.log(diff);
@stefanocudini
stefanocudini / randcolor.js
Created May 31, 2012 17:11
random hex color javascript
function track_randcolor() //restituisce un array con valori RGB 0-255
{
function toHex(n) {
n = parseInt(n,10);
if (isNaN(n)) return "00";
n = Math.max(0,Math.min(n,255));
return "0123456789ABCDEF".charAt((n-n%16)/16) +
"0123456789ABCDEF".charAt(n%16);
}
function rgb2hex(rgb) { //converte da array di valori 0-255 e stringa esadecimale
@stefanocudini
stefanocudini / xml2array.php
Created July 25, 2012 17:24
convert xml file to array object in one line
<?
function xml2array($xml)
{
return (empty($xml) ? array() : json_decode(json_encode(simplexml_load_string($xml)),true) );
}
?>