Skip to content

Instantly share code, notes, and snippets.

@iNem0o
iNem0o / gist:3992650
Created November 1, 2012 09:15
Étendre un tableau associatif sans réécrire les valeurs déja présentes avec PHP
<?php
$tab = array(
'cle1' => 1,
'cle2'=> 2,
'cle3'=> 3
);
$tab += array(
'cle2'=> 7, // ne sera pas utilisé car déja présent
'cle4' => 4 // sera ajouté car n'existe pas
);
@iNem0o
iNem0o / Go home PHP, you're drunk !
Created March 26, 2013 15:53
Go home PHP, you're drunk !
$a = 10+25.99+0.01;
echo '<br>$a = 10+25.99+0.01 = 36';
echo '<br>round($a) = '.round($a);
echo '<br>$a - round($a) = '.($a-round($a));
<?php
$data = array();
for($i = 0;$i<= 10000;$i++) {
$data[md5($i)] = $i;
}
$start = microtime(true);
foreach($data as $k => $v) {
$data[$k] = 'benchkmark';
}
@iNem0o
iNem0o / gist:5263718
Last active December 15, 2015 12:59
Vérifier la longueur d'une chaine en PHP : strlen() vs isset()
<?php
$string = "hello world";
$taille = 5;
$t = microtime(true);
for($i = 0;$i<10000;$i++) {
if(strlen($string) >= $taille) {
}
}
echo '<br> strlen($string) > 5 : '.round((microtime(true)-$t)*1000,2)." ms";
<?php
class DateTimeDeluxe extends DateTime {
public function isFirst($daystring) {
return $this -> diff(new DateTime("first ".$daystring." of ".strtolower($this -> format("F")))) -> days === 0;
}
}
$newDate = new DateTimeDeluxe();
// premier lundi du mois ?
var_dump($newDate -> isFirst('monday'));
@iNem0o
iNem0o / gist:5627152
Created May 22, 2013 12:24
Quick-and-dirty benchmark
<?php
$root = 'var';
for($i = 0;$i <= 10; $i++) {
$varName = $root.$i;
$$varName = $i;
}
$timer = microtime(true);
for($j = 0;$j <= 100; $j++) {
$var = $var1.' qsd '.$var2.' qsd '.$var3.' qsd '.$var4.' qsd '.$var5.' qsd '.$var6.' qsd '.$var7.' qsd';
@iNem0o
iNem0o / rtl_sdr, multimon-ng and kalibrate-rtl RPi Installer
Last active August 2, 2022 19:46
Installer script for rtl_sdr, multimon-ng and kalibrate-rtl on raspberry pi  
#!/bin/sh
# install :
# curl -o installer.sh https://gist.github.com/iNem0o/6346423/raw && chmod +x installer.sh && sudo ./installer.sh
sudo apt-get update
sudo apt-get --no-install-recommends -y install git cmake libusb-1.0-0-dev libpulse-dev libx11-dev screen qt4-qmake libtool autoconf automake libfftw3-dev
mkdir ~/src
echo "Installation de rtl_sdr"
@iNem0o
iNem0o / gist:7660947
Created November 26, 2013 16:02
ob_disable()
function ob_disable() {
ini_set('output_buffering', 'off');
ini_set('zlib.output_compression', false);
ini_set('implicit_flush', true);
ob_implicit_flush(true);
while (ob_get_level() > 0) {
$level = ob_get_level();
ob_end_clean();
if (ob_get_level() == $level) break;
}
@iNem0o
iNem0o / HipChatNotifier.php
Created March 17, 2014 21:16
Simple PHP notifier for HipChat
<?php
namespace inem0o\Tools;
/**
* Class HipChatNotifier
* Allow you to notify a room on HipChat
* @package inem0o\Tools
*/
class HipChatNotifier
{
/**
<?php
class LinkCore {
protected function getBaseLink($args) {
echo '<br>LinkCore -> '.$args;
}
}
class Link extends LinkCore {
public function getBaseLink($args) {