Skip to content

Instantly share code, notes, and snippets.

View dagostoni's full-sized avatar

David dagostoni

  • Italy
View GitHub Profile
@dagostoni
dagostoni / propel-query-debug.php
Last active December 17, 2015 22:39
propel query debug
<?php
$con = Propel::getConnection(MediaPeer::DATABASE_NAME);
$con->useDebug(true);
echo $con->getLastExecutedQuery();
@dagostoni
dagostoni / gist:5756023
Created June 11, 2013 10:54
Add empty directory to a git repository
Create in the directory a .gitignore file with this content:
# Ignore everything in this directory
*
# Except this file
!.gitignore
@dagostoni
dagostoni / gist:5803961
Created June 18, 2013 09:28
create zip file with password on mac
terminal
zip -e [file.zip] [file list]
@dagostoni
dagostoni / gist:7531058
Last active December 28, 2015 16:49
Verifica Codice Fiscale
<?php
function checkTaxCodeIt($tax_code){
$odd = array('0' => 1, '1' => 0, '2' => 5, '3' => 7, '4' => 9, '5' => 13, '6' => 15, '7' => 17, '8' => 19, '9' => 21, 'A' => 1, 'B' => 0, 'C' => 5, 'D' => 7, 'E' => 9, 'F' => 13, 'G' => 15, 'H' => 17, 'I' => 19, 'J' => 21, 'K' => 2, 'L' => 4, 'M' => 18, 'N' => 20, 'O' => 11, 'P' => 3, 'Q' => 6, 'R' => 8, 'S' => 12, 'T' => 14, 'U' => 16, 'V' => 10, 'W' => 22, 'X' => 25, 'Y' => 24, 'Z' => 23);
$even = array('0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9, 'A' => 0, 'B' => 1, 'C' => 2, 'D' => 3, 'E' => 4, 'F' => 5, 'G' => 6, 'H' => 7, 'I' => 8, 'J' => 9, 'K' => 10, 'L' => 11, 'M' => 12, 'N' => 13, 'O' => 14, 'P' => 15, 'Q' => 16, 'R' => 17, 'S' => 18, 'T' => 19, 'U' => 20, 'V' => 21, 'W' => 22, 'X' => 23, 'Y' => 24, 'Z' => 25);
$tax_code = strtoupper($tax_code);
if($tax_code == '') return false;
if(strlen($tax_code) != 16) return false;
@dagostoni
dagostoni / gist:7531076
Created November 18, 2013 16:44
Verifica Partita Iva
<?php
function checkVatIt($vat){
if($vat == '') return false;
if(strlen($vat) != 11) return false;
if(!preg_match("/^[0-9]+$/", $vat)) return false;
$vat = str_split($vat);
$x = 0;
$y = 0;
@dagostoni
dagostoni / gist:7598930
Created November 22, 2013 12:09
Get enum indexes from table field using mysql
<?php
function getEnumIndexes($table, $field){
$enum = array();
$sql = "SHOW COLUMNS FROM ".addslashes($table)." WHERE Field = '".addslashes($field)."'";
$result = mysql_query($sql);
if($row = mysql_fetch_assoc($result)){
$string = $row['Type'];
$string = preg_replace('/^enum\(|\)$/i', '', $string);
$tmp = explode(',', $string);
@dagostoni
dagostoni / function.php
Last active October 18, 2015 21:21
select by range/distance geo/latitude/longitude
<?php
public static function distance($lat1, $lon1, $lat2, $lon2, $unit) {
$theta = $lon1 - $lon2;
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
$dist = acos($dist);
$dist = rad2deg($dist);
$miles = $dist * 60 * 1.1515;
$unit = strtoupper($unit);
if ($unit == "K") {
@dagostoni
dagostoni / gist:64c162a274b6ef9d673b
Created May 20, 2015 09:56
visualizza file nascosti nel finder / show hidden files in finder
defaults write com.apple.finder AppleShowAllFiles YES
defaults write com.apple.finder AppleShowAllFiles NO
@dagostoni
dagostoni / cookiechoices.js
Last active August 29, 2015 14:22
Cookie Choice Google
/*
Copyright 2014 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
@dagostoni
dagostoni / gist:8237ceb90186c88dd4ab
Created May 29, 2015 08:59
Google Analytics Anonimize
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXXX-X', 'auto');
ga('set', 'anonymizeIp', true);
ga('send', 'pageview');
</script>