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
server { | |
listen 8080; | |
server_name myserver; | |
root /path/to/root; | |
access_log /var/log/myserver-access.log; | |
error_log /var/log/myserver-error.log debug; |
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 get_rank($votes_min, $votes_item, | |
$rating_average_global, $rating_average_item) { | |
return | |
($votes_item / ($votes_item + $votes_min)) * $rating_average_item + | |
($votes_min / ($votes_item + $votes_min)) * $rating_average_global; | |
} | |
$data = array( | |
[5, 10], |
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 | |
namespace noodlehaus\minsql; | |
# create pdo conn, or get last used, or null | |
function connect(...$args) { | |
static $pdo = null; | |
if (!count($args)) | |
return $pdo; |
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 function_stringify($func) { | |
$ref = new ReflectionFunction($func); | |
if ($ref->isInternal()) | |
return '[internal]'; | |
$top = $ref->getStartLine() - 1; | |
$len = $ref->getEndLine() - $top; |
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 | |
# @author Jesus A. Domingo | |
# @license MIT <http://noodlehaus.mit-license.org> | |
namespace noodlehaus\pico; | |
# returns the value for an http request header | |
function request_header($name) { | |
$headers = &$GLOBALS['app/state']['request_headers']; |
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 | |
require __DIR__.'/routes.php'; | |
use badphp\routes\{ | |
function get, | |
function post, | |
function lookup | |
}; | |
# let's create some routes |
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 save_and_resample($fname, $oname, $tname, $type, $imagew, $imageh) | |
{ | |
$imgr = ( $imagew > $imageh ) ? IMAGE_MAX_THUMB_WIDTH/$imagew : IMAGE_MAX_THUMB_HEIGHT/$imageh ; | |
$neww = $imagew * $imgr; | |
$newh = $imageh * $imgr; | |
$fulw = $imagew; | |
$fulh = $imageh; | |
if ( $neww > IMAGE_MAX_THUMB_WIDTH ) { |
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
/* | |
* patches the req object to have the pause() and resume() functions | |
* for event buffering (for async middleware). | |
* code is take from express' utils file | |
*/ | |
const http = require('http'), | |
req = http.IncomingMessage.prototype; | |
// patch req object for async middleware |
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
/** | |
* Taken from http://www.dweebd.com/javascript/binary-search-an-array-in-javascript/ | |
*/ | |
Array.prototype.find = function (needle, comparator) { | |
var low = 0, | |
high = this.length - 1, | |
i, | |
comparison; | |
while (low <= high) { | |
i = Math.floor((low + high) / 2); |
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 | |
const fs = require('fs'); | |
var args = process.argv.slice(2); | |
if (args.length < 2) { | |
console.log('Usage: jsonv <jsonfile> <json-path-1> ... <json-path-n>'); | |
process.exit(1); | |
} |
OlderNewer