Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrea Bergamasco vjandrea

View GitHub Profile
@vjandrea
vjandrea / calendario_produzione.php
Last active Dec 29, 2016
Workdays calendar with Italian localization, used as blueprint for my reports.
View calendario_produzione.php
<?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');
@vjandrea
vjandrea / parlamentari.php
Created Mar 18, 2013
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…
View parlamentari.php
<?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 Mar 24, 2013
Generates a graph of Parliament seats grouped by coalition, data is contained in an array that generates a tsv, graph engine is D3 library.
View legislature.php
<?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 Oct 4, 2013
Laravel 4 query logger. Put this in template's footer. Credits to: http://stackoverflow.com/a/19085511
View laravel_query_logger.html
<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 Dec 24, 2015
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.
View createFromArray.php
<?php
$data = [
[ 'id' => 0 ],
[ 'id' => 1 ],
[ 'id' => 2,
'children' => [
[ 'id' => 3 ],
[ 'id' => 4,
'children' => [
@vjandrea
vjandrea / highlight.php
Created Oct 15, 2014
String highlight preserving case
View highlight.php
<?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 / lightbox4all.user.js
Last active Aug 3, 2016
Ligthbox 4 All Greasemonkey Script
View lightbox4all.user.js
// ==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 / money_round.inc.php
Created Nov 3, 2015
Round to nearest defined cents
View money_round.inc.php
/*
* 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 Nov 3, 2015
Laravel obfuscate email
View laravel_email.php
// $ composer require laravelcollective/html
{{ HTML::mailto('a@b.c') }}
@vjandrea
vjandrea / .htaccess
Last active Jan 27, 2016
Laravel .htaccess that supports a static section published under /public/ [http://stackoverflow.com/questions/29217937/how-to-route-to-a-static-folder-in-laravel]
View .htaccess
<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]