Skip to content

Instantly share code, notes, and snippets.

View mircobabini's full-sized avatar

Mirco Babini mircobabini

View GitHub Profile
@mircobabini
mircobabini / ifor.php
Created December 8, 2012 15:22
returns the first true-valued value
<?
/**
* returns the first true-valued value
*
* @param mixed $if
* @param mixed $or
* @return mixed
*
* @package Handframe/Tool/Function
* @author Mirco Babini <mirkolofio@gmail.com>
@mircobabini
mircobabini / round_step.php
Created December 8, 2012 15:23
rounds a float to the nearest on step-scale
<?
/**
* rounds a float to the nearest on step-scale
*
* @param float $value value to round
* @param float $step step-scale,
* @return float rounded value
*
* @package Handframe/Tool/Function
* @author Mirco Babini <mirkolofio@gmail.com>
@mircobabini
mircobabini / list-them-all.js
Created December 9, 2012 12:22
useful to create large lists from others on twitter
/**
* useful to create large lists from others on twitter
*
* @author Mirco Babini <mirkolofio@gmail.com>
* @license http://creativecommons.org/licenses/by-nc/3.0/
*
* @usage
* gimmeabeer (listid);
* gimmeabeer ([listid1, listid2, ..]);
*/
@mircobabini
mircobabini / get_called_class.php
Created February 23, 2013 10:45
Retro-support of get_called_class()
<?
/**
* Retro-support of get_called_class()
* @author laurence(at)sol1(dot)com(dot)au
*/
if (!function_exists ('get_called_class'))
{
function get_called_class ($bt = false, $l = 1)
{
if (!$bt) $bt = debug_backtrace ();
@mircobabini
mircobabini / google-contacts-vcards-cleaner.php
Last active December 14, 2015 04:39
Google contacts vcards cleaner
<?
require "vcard-extendible.php"; // https://github.com/nuovo/vCard-parser
class GCards extends vCard {
/**
* @return bool
*/
public function hasTel () {
return (sizeof ($this->tel) > 0);
}
public function hasMail () {
@mircobabini
mircobabini / wp-load-addition.php
Last active December 15, 2015 23:09
Additions for wp-load.php Wordpress' loader. It enables hostname-specific Wordpress' configuration files (wp-config-HOSTNAME.php).
<?
// [..]
/**
* Hostname specific wp-config statement
*
* @author Mirco Babini <mirkolofio@gmail.com>
* @uses hostname (): */
if (!function_exists ('hostname')) {
function hostname () { return trim (php_uname ("n")); } } /*
@mircobabini
mircobabini / LinuxSystem.php
Last active December 16, 2015 01:59
PHP Simple interactions with Shell
<?
/**
* @author _LameMind <lamemind@gmail.com>
*/
abstract class LinuxSystem {
/**
* @param string $question
* @param array $admittedValues
* @return mixed
*/
<?
/**
* @param string $olddomain
* @param string $newdomain
* @param string $infile
* @param string $outfile
* @return int|bool
*/
function wp_sql_domain_changer ($olddomain, $newdomain, $infile = null, $outfile = null) {
$infile = ($infile === null) ? 'input.sql' : $infile;
@mircobabini
mircobabini / fill-the-space.php
Created April 24, 2013 08:57
Dedicato a chi non mette lo spazio prima delle parentesi. Con immenso odio, M.
<?
$input = "input.java";
$c = file_get_contents ($input); // get the mess
$c = str_replace ('(', " (", $c); // fill the space
$c = preg_replace ('#\s\s+\(#', " (", $c); // remove multiple spaces
file_put_contents ("output.java", $c); // spread the world
// one day you will regret it