The problem was to find the maximum contiguous sum of series of numbers.
$ pip install pytest
$ py.test --doctest-modules
#!/bin/bash | |
{ coproc bc_proc { bc; read; } >&3; } 3>&1 | |
echo "1 + 2" >&${bc_proc[1]} | |
echo "2 + 5" >&${bc_proc[1]} |
#!/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) |
<?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))); | |
} |
<?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, |
#!/usr/bin/php -q | |
<?php | |
function check_socket($host, $port) | |
{ | |
$conn = @fsockopen($host, $port, $errno, $errstr, 2); | |
if ($conn) { | |
fclose($conn); | |
return true; | |
} |
#!/usr/bin/env node | |
var net = require('net'), | |
repl = require('repl'); | |
var mood = function () { | |
var m = [ "^__^", "-___-;", ">.<", "<_>" ]; | |
return m[Math.floor(Math.random() * m.length)]; | |
}; |
#!/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')); |
<?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); | |
} |