Skip to content

Instantly share code, notes, and snippets.

View bdelespierre's full-sized avatar
🚩
Working from home

Benjamin Delespierre bdelespierre

🚩
Working from home
View GitHub Profile
CREATE TABLE IF NOT EXISTS _EL_INFORME_DE_LA_MUERTE (
CAMPAIGNID INT UNSIGNED NOT NULL,
ADASSETID INT UNSIGNED NOT NULL,
COUNTRY_CODE CHAR(2) NOT NULL DEFAULT '',
CITY_CODE VARCHAR(50) NOT NULL DEFAULT '',
TYPE ENUM('DISPLAY','CLICK','SALE','POST_VIEW','POST_CLICK'),
AMOUNT INT UNSIGNED NOT NULL DEFAULT 0,
DATE_SAVE DATE,
PRIMARY KEY (CAMPAIGNID, ADASSETID, TYPE, DATE_SAVE)
) ENGINE=MyISAM;
<?php
// cet algorithme est d'une telle violence
$dim = 3;
$d = 32; // lol
$v1 = array_randn($dim);32;
$v2 = array_randn($dim);
@bdelespierre
bdelespierre / hamming_dist_keywords
Created December 17, 2014 14:58
Keywords hamming distance
<?php
$campaigns = [
'foo' => ['keywords' => ['a','b','c']],
'bar' => ['keywords' => ['b','c','e']],
'baz' => ['keywords' => ['d','f','b']],
];
$allKeywords = array_unique(call_user_func_array('array_merge', array_map(function($c) { return $c['keywords']; }, $campaigns)));
<?php
function formatGUID($chars, $uppercase = false, $braces = false, $hyphen = true)
{
$c = $chars;
$h = $hyphen ? '-' : '';
$g =
"{$c[00]}{$c[01]}{$c[02]}{$c[03]}{$c[04]}{$c[05]}{$c[06]}{$c[07]}{$h}".
"{$c[08]}{$c[09]}{$c[10]}{$c[11]}{$h}".
"{$c[12]}{$c[13]}{$c[14]}{$c[15]}{$h}".
@bdelespierre
bdelespierre / stumbleupon_likes_rss_parser.php
Created January 15, 2014 18:11
Surpress StumbleUpon url and replace them with actual ones from your StumbleUpon likes feed
<?php
function stumble2url ($url) {
$doc = new DOMDocument;
if (!@$doc->loadHTMLFile($url))
return null;
return ($iframe = $doc->getElementById('tb-stumble-frame'))
? $iframe->getAttribute('src')
@bdelespierre
bdelespierre / Fibonacci
Last active December 30, 2015 04:19
Fibonnaci numbers generator
<?php
// quick'n dirty
class Fibonacci implements Iterator {
public function __construct () {
$this->rewind();
}
<?php
// how to reverse the singleton pattern
class Service {
public static $data;
public static function inc () {
static::$data++;
}
}
<?php
namespace CommandLine;
class Colors {
public static $_backgroundColors = array(
'black' => '40',
'red' => '41',
'green' => '42',
<?php
spl_autoload_register(function($classname) {
if (strpos($classname, '\\with') === false)
return false;
list($namespace, $class) = str_split($classname, strrpos($classname, '\\'));
$class = substr($class, 1);
$parts = explode('\\with', $classname);
@bdelespierre
bdelespierre / gist:7004662
Created October 16, 2013 08:47
Easily launch any virtualbox vm in headless mode or stop it using a simple configuration file
#!/bin/bash
function usage {
echo "Usage: $0 [file] [start|stop|status|connect]"
}
if [ -z $1 ]; then
usage
exit 0
fi