Skip to content

Instantly share code, notes, and snippets.

View vjandrea's full-sized avatar

Andrea Bergamasco vjandrea

View GitHub Profile
@vjandrea
vjandrea / highlight.php
Created October 15, 2014 19:11
String highlight preserving case
<?php
// http://www.webdevdoor.com/php/highlight-search-keyword-string-function/#comment-445598
function highlight($haystack, $needle, $color = ‘#F00′)
{
return preg_replace("/($needle)/i", sprintf('<span style="color: %s">$1</span>', $color), $haystack);
}
@vjandrea
vjandrea / money_round.inc.php
Created November 3, 2015 15:34
Round to nearest defined cents
/*
* Rounds to the nearest 5 cents
* Modified from @dancameron's version
* For $mode values see http://php.net/manual/en/function.round.php
*
* @param float $amount
* @param int $mode (default = PHP_ROUND_HALF_UP)
* @return float
*/
function round_money($amount = 0.0, $mode = PHP_ROUND_HALF_UP) {
@vjandrea
vjandrea / laravel_email.php
Created November 3, 2015 16:29
Laravel obfuscate email
// $ composer require laravelcollective/html
{{ HTML::mailto('a@b.c') }}
@vjandrea
vjandrea / parlamentari.php
Created March 18, 2013 15:14
List of members of Parliament in Italy built as PHP array. Under construction. Root key: "camera"/"senato" = low / high Chamber<br /> id = id used on chamber website nome = full name, family name first procedimento = past trials and legal issues sesso = sex datanascita = birthdate partito = political party regione = italian region of election (u…
<?php
$parlamentare["camera"] = array('id' => "302940", 'nome' => "ABRIGNANI Ignazio", 'procedimento' => "Indagato per dissipazione post-fallimentare");
$parlamentare["camera"] = array('id' => "34960", 'nome' => "ADORNATO Ferdinando");
$parlamentare["camera"] = array('id' => "305782", 'nome' => "AGOSTINELLI Donatella");
$parlamentare["camera"] = array('id' => "302873", 'nome' => "AGOSTINI Luciano");
$parlamentare["camera"] = array('id' => "305840", 'nome' => "AGOSTINI Roberta");
$parlamentare["camera"] = array('id' => "306300", 'nome' => "AIELLO Ferdinando");
$parlamentare["camera"] = array('id' => "305575", 'nome' => "AIRAUDO Giorgio");
$parlamentare["camera"] = array('id' => "306112", 'nome' => "ALBANELLA Luisella");
$parlamentare["camera"] = array('id' => "305518", 'nome' => "ALBERTI Dino");
@vjandrea
vjandrea / legislature.php
Created March 24, 2013 19:50
Generates a graph of Parliament seats grouped by coalition, data is contained in an array that generates a tsv, graph engine is D3 library.
<?php
/*
Data is organized in two arrays: $orientamento keeps the political orientation as:
- SX = left
- CSX = centre-left
- Centro = centre
- CDX = centre-right
- Misto = mixed group
The second array is $gruppo_parlamentare, keeps track of date, chamber, name of party in the coalition.
The value assigned is the number of seats in the given chamber.
@vjandrea
vjandrea / laravel_query_logger.html
Created October 4, 2013 11:40
Laravel 4 query logger. Put this in template's footer. Credits to: http://stackoverflow.com/a/19085511
<script type="text/javascript">
var queries = {{ json_encode(DB::getQueryLog()) }};
console.log('/****************************** Database Queries ******************************/');
console.log(' ');
$.each(queries, function(id, query) {
console.log(' ' + query.time + ' | ' + query.query + ' | ' + query.bindings[0]);
});
console.log(' ');
console.log('/****************************** End Queries ***********************************/');
</script>
@vjandrea
vjandrea / createFromArray.php
Last active December 24, 2015 16:09
Example in procedural code for a tree parser based on an array that i'd like to implement in ClosureTable It echoes the code that should be executed once implemented.
<?php
$data = [
[ 'id' => 0 ],
[ 'id' => 1 ],
[ 'id' => 2,
'children' => [
[ 'id' => 3 ],
[ 'id' => 4,
'children' => [
@vjandrea
vjandrea / .htaccess
Last active January 27, 2016 16:58
Laravel .htaccess that supports a static section published under /public/ [http://stackoverflow.com/questions/29217937/how-to-route-to-a-static-folder-in-laravel]
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
@vjandrea
vjandrea / lightbox4all.user.js
Last active August 3, 2016 07:11
Ligthbox 4 All Greasemonkey Script
// ==UserScript==
// @name Lightbox 4 all
// @namespace http://vjandrea.net
// @description Open all images in lightbox
// @require http://lokeshdhakar.com/projects/lightbox2/js/jquery-1.11.0.min.js
// @require http://lokeshdhakar.com/projects/lightbox2/js/lightbox.js
// @version 1.3.1
// @grant none
// ==/UserScript==
@vjandrea
vjandrea / calendario_produzione.php
Last active December 29, 2016 16:50
Workdays calendar with Italian localization, used as blueprint for my reports.
<?php
/**
* This script generates a simple list of days formatted as "Dayofweek day(numeric) Month"
* I use this calendar as blueprint for my reports.
* 4th revision with better formatting and some refactoring
*/
define("TOTAL_DAYS", 150);
setlocale(LC_ALL, 'it_IT', 'it', 'IT', 'ita', 'italian');