- DRY ou Don't Repeat Yourself
- KISS ou Keep It Simple, Stupid!
- YAGNI ou You Ain't Gonna Need It!
- SOLID
- STUPID
- Law Of Demeter
- Tell, don't ask!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function is_in_subnet($subnet, $ip) | |
{ | |
list($subnet_ip, $subnet_mask) = explode('/', $subnet); | |
$begin = (ip2long($subnet_ip) & ip2long($subnet_mask)) + 1; | |
$end = (ip2long($subnet_ip) | (~ip2long($subnet_mask))) + 1; | |
$ip = ip2long($ip); | |
return ($ip >= $begin && $ip <= $end); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
$url = $argv[1]; | |
$data = array('foo' => 'bar'); | |
echo '>>>>> request : ' . $url . PHP_EOL; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
var net = require('net'), | |
repl = require('repl'); | |
var mood = function () { | |
var m = [ "^__^", "-___-;", ">.<", "<_>" ]; | |
return m[Math.floor(Math.random() * m.length)]; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/php -q | |
<?php | |
function check_socket($host, $port) | |
{ | |
$conn = @fsockopen($host, $port, $errno, $errstr, 2); | |
if ($conn) { | |
fclose($conn); | |
return true; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$db = new PDO('mysql:unix_socket=/tmp/mysql.sock;dbname=mybdd', 'root', 'root'); | |
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | |
/** | |
CREATE SCHEMA `mybdd`; | |
CREATE TABLE `users` ( | |
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT, | |
`firstname` VARCHAR(255) NOT NULL, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function uchrA($str) { | |
return html_entity_decode(preg_replace('/\\\u([\da-fA-F]{4})/', '&#x\1;', $str)); | |
} | |
function uchrB($str) { | |
return utf8_decode(json_decode(sprintf('"%s"', $str))); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
TEST=${TEST:+'test'} | |
function prime_factors_of { | |
local number=$1 | |
for (( divisor=2; number > 1; divisor++ )); do | |
for (( ; number % divisor == 0; number /= divisor )); do | |
prime_factors=("${prime_factors[@]}" $divisor) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
{ coproc bc_proc { bc; read; } >&3; } 3>&1 | |
echo "1 + 2" >&${bc_proc[1]} | |
echo "2 + 5" >&${bc_proc[1]} |
OlderNewer