Skip to content

Instantly share code, notes, and snippets.

View prcaen's full-sized avatar

Pierrick CAEN prcaen

View GitHub Profile
@prcaen
prcaen / gist:1153708
Created August 18, 2011 09:13
[PHP] - Distinct double in a multi dimensional array
<?php
/**
* Get a distinct multi dimensional array
*
* @param array $array
* array to distinct
* @param string $keySearch
* string key to search double array
* @param boolean $overwrite = false
* boolean to allow values to be overwritten
@prcaen
prcaen / html5-file-kickstart.html
Created November 5, 2011 11:02
HTML5 file kickstart
<!DOCTYPE html>
<!--[if IE 7]> <html class="no-js ie7 oldie" lang="lang"> <![endif]-->
<!--[if IE 8]> <html class="no-js ie8 oldie" lang="lang"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="${1:fr}"> <!--<![endif]-->
<head>
<meta charset="utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<!-- Geo position -->
@prcaen
prcaen / gist:1365016
Created November 14, 2011 20:19
[JS] - strrchr
function strrchr (haystack, needle) {
var pos = 0;
if (typeof needle !== 'string')
needle = String.fromCharCode(parseInt(needle, 10));
needle = needle.charAt(0);
pos = haystack.lastIndexOf(needle);
if (pos === -1)
@prcaen
prcaen / gist:1435422
Created December 5, 2011 21:23
[PHP] - Two digits
private function twoDigits($number)
{
if($number <= 9)
return '0' . $number;
else
return $number;
}
@prcaen
prcaen / generateRandomKey.js
Created December 20, 2011 11:00
[JS] - generateRandomKey
function generateRandomKey(size)
{
var keyset = 'abcdefghijklmnopqrstuvwxyz0123456789';
var randomKey = '';
for (var i = 0; i < size; i++)
{
var rnum = Math.floor(Math.random() * keyset.length);
randomKey += keyset.substring(rnum,rnum + 1);
}
@prcaen
prcaen / GoogleCalendar.java
Created January 2, 2012 08:42
[Java] GoogleCalendar Android Manager
public class GoogleCalendar {
private Context _context;
private GoogleCalendarCallback _callback;
public GoogleCalendar(Context c, GoogleCalendarCallback cb) {
_context = c;
_callback = cb;
}
public void add(final String title, final Long dateStart, final Long dateEnd,
@prcaen
prcaen / gist:2778423
Created May 23, 2012 23:11
[Symfony] - Bash aliases
# Symfony aliases
## Cache
alias sf_cache_clear="php app/console cache:clear" # Clears the cache
alias sf_cache_warmup="php app/console cache:warmup" # Warms up an empty cache
## Doctrine
alias sf_doctrine_="php app/console doctrine:cache:clear-metadata" # Clears all metadata cache for a entity manager
alias sf_doctrine_="php app/console doctrine:cache:clear-query" # Clears all query cache for a entity manager
alias sf_doctrine_="php app/console doctrine:cache:clear-result" # Clears result cache for a entity manager
alias sf_doctrine_="php app/console doctrine:database:create" # Creates the configured databases
@prcaen
prcaen / gist:2996342
Created June 26, 2012 15:09
[PHP] - [Symfony] - sfValidatorBIC
<?php
/**
*
*/
class sfValidatorBIC extends sfValidatorBase
{
protected $validator;
protected $errors;
protected function configure($options = array(), $messages = array())
@prcaen
prcaen / gist:3413601
Created August 21, 2012 08:41
Backup database periodically
# At 9, 13, 16 and 19 hour every monday, tuesday, wednesday, thursday and friday
* 9,13,16,19 * * 1,2,3,4,5 root /Applications/XAMPP/xamppfiles/bin/mysqldump -u root --all-databases | gzip > /Users/pierrick/Documents/Backups/Sites/database_`date +"%m_%d_%Y_%H_%M"`.sql.gz
@prcaen
prcaen / twoDigitsYear.java
Last active December 11, 2015 15:38
Return year with two digits If is already a two digits year it return the two digits eg : - 2014 => 14 - 14 => 14
private int _twoDigitsYear(int year) {
if (year > 0)
year = year % 100;
return year;
}