Skip to content

Instantly share code, notes, and snippets.

View olvlvl's full-sized avatar

Olivier Laviale olvlvl

View GitHub Profile
@olvlvl
olvlvl / gist:ab24aa248f54d713e2d9
Created January 23, 2016 12:56
Version log template
**Updated requirements**
**Backward incompatible changes**
**New features**
**Other changes**
**Fixed**
_short_pwd ()
{
local PRE= NAME="$1" LENGTH="$2";
[[ "$NAME" != "${NAME#$HOME/}" || -z "${NAME#$HOME}" ]] &&
PRE+='~' NAME="${NAME#$HOME}" LENGTH=$[LENGTH-1];
((${#NAME}>$LENGTH)) && NAME="/...${NAME:$[${#NAME}-LENGTH+4]}";
echo "$PRE$NAME"
}
export CLICOLOR=1
@olvlvl
olvlvl / gist:7788d6bd8a4e172bbc92
Created February 6, 2015 09:49
Create annotation from declared variables
<?php
$__a = "/**\n";
foreach (array_diff_key(get_defined_vars(), [ '__a' => true, '__k' => true, '__v' => true ]) as $__k => $__v)
{
$__v = is_object($__v) ? '\\' . get_class($__v) : gettype($__v);
$__a .= " * @var \$$__k $__v\n";
}
@olvlvl
olvlvl / test.php
Last active August 29, 2015 14:04
issue-activerecord-4
<?php
use ICanBoogie\ActiveRecord;
use ICanBoogie\ActiveRecord\Connections;
use ICanBoogie\ActiveRecord\Model;
use ICanBoogie\ActiveRecord\Models;
use ICanBoogie\ActiveRecord\Query;
// in the bootstrap of your application
@olvlvl
olvlvl / compute.php
Created January 16, 2014 16:18
Package weight computing for Composer
<?php
$stable_sort = function(&$array, $picker=null)
{
static $transform, $restore;
$i = 0;
if (!$transform)
{
@olvlvl
olvlvl / created_at.php
Last active December 30, 2015 09:19
I wanted to create traits for properties such as `created_at` and `updated_at` for my ActiveRecord implementation, but it looks like even if the methods are aliased, PHP consider that there is a clash and throw a fatal error. That makes me sad. Is there a solution to that ?
<?php
namespace ICanBoogie\ActiveRecord;
/**
* Defines the `created_at` property and the corresponding getter/setter.
*
* @property \ICanBoogie\DateTime $created_at The date and time at which the record was created.
*/
trait CreatedAtProperty
<?php
class Baz
{
protected $foo;
public function __construct($foo)
{
$this->foo = $foo;
}
@olvlvl
olvlvl / gist:4228184
Created December 6, 2012 20:46
comments/1005
<?php
function utf_remove_accents_and_ligs($string) {
$utfNoAccentsNoLigsEquivalent=array(
0xc3 => array(
0xc380 => 'A', 0xc381 => 'A', 0xc382 => 'A', 0xc383 => 'A', 0xc384 => 'A', 0xc385 => 'A', 0xc386 => 'AE', 0xc387 => 'C',
0xc388 => 'E', 0xc389 => 'E', 0xc38a => 'E', 0xc38b => 'E', 0xc38c => 'I', 0xc38d => 'I', 0xc38e => 'I', 0xc38f => 'I',
0xc390 => 'D', 0xc391 => 'N', 0xc392 => 'O', 0xc393 => 'O', 0xc394 => 'O', 0xc395 => 'O', 0xc396 => 'O', 0xc398 => 'O',
0xc399=> 'U', 0xc39a => 'U', 0xc39b => 'U', 0xc39c => 'U', 0xc39d => 'Y', 0xc39f => 'S', 0xc3a0 => 'a', 0xc3a1 => 'a',
0xc3a2 => 'a', 0xc3a3 => 'a', 0xc3a4 => 'a', 0xc3a5 => 'a', 0xc3a6 => 'ae', 0xc3a7 => 'c', 0xc3a8 => 'e', 0xc3a9 => 'e',
@olvlvl
olvlvl / stable_sort.php
Created January 7, 2012 14:23
Stable sort function
/*
* This file is part of the ICanBoogie package.
*
* (c) Olivier Laviale <olivier.laviale@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ICanBoogie;
@olvlvl
olvlvl / fielapi-xhr
Created August 31, 2011 13:33
Asynchronous file transfer using the FileAPI and XHR interfaces
window.addEventListener
(
'load', function()
{
var fileInput = document.getElementById('file-input');
fileInput.addEventListener
(
'change', function(ev)
{