Skip to content

Instantly share code, notes, and snippets.

View noodlehaus's full-sized avatar

noodlehaus noodlehaus

View GitHub Profile
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;
@noodlehaus
noodlehaus / rankings.php
Created July 18, 2014 08:58
ranking formula example -- stackoverflow.com/questions/16168727/
<?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],
@noodlehaus
noodlehaus / minsql.php
Last active August 29, 2015 14:06
minsql concept
<?php
namespace noodlehaus\minsql;
# create pdo conn, or get last used, or null
function connect(...$args) {
static $pdo = null;
if (!count($args))
return $pdo;
<?php
function function_stringify($func) {
$ref = new ReflectionFunction($func);
if ($ref->isInternal())
return '[internal]';
$top = $ref->getStartLine() - 1;
$len = $ref->getEndLine() - $top;
@noodlehaus
noodlehaus / pico.php
Last active August 29, 2015 14:12
routing functions from dispatch
<?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'];
@noodlehaus
noodlehaus / routes-example.php
Last active September 21, 2015 02:38
simple routing library with type hints
<?php
require __DIR__.'/routes.php';
use badphp\routes\{
function get,
function post,
function lookup
};
# let's create some routes
@noodlehaus
noodlehaus / gist:66dbc0a1887706d523a9
Last active September 26, 2015 07:58
resample uploaded images (old version)
<?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 ) {
@noodlehaus
noodlehaus / gist:1153656
Created August 18, 2011 08:29
patch the req object in express to include the pause() and resume() methods for event buffering (for async middleware)
/*
* 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
@noodlehaus
noodlehaus / JS array binary search
Created August 29, 2011 14:30
Binary search implementation for JS arrays
@noodlehaus
noodlehaus / jsonv
Created September 28, 2011 06:42
CLI tool for getting values from JSON text files.
#!/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);
}