Skip to content

Instantly share code, notes, and snippets.

View noodlehaus's full-sized avatar

noodlehaus noodlehaus

View GitHub Profile
@noodlehaus
noodlehaus / 00-badphp-context-concept.php
Last active December 25, 2015 14:40
badphp\context
<?php
require __DIR__.'/request.php';
require __DIR__.'/response.php';
use badphp\context\request;
use badphp\context\response;
/**
* Request handling examples
@noodlehaus
noodlehaus / .bashrc
Created March 2, 2015 01:35
bash prompt
# get bash completion for brew
if [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion
fi
# git prompt
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ \(\1\)/'
}
@noodlehaus
noodlehaus / .vimrc
Last active August 15, 2016 16:12
vim config
" pathogen
execute pathogen#infect()
syntax on
filetype plugin indent on
" colors
set t_Co=256
colorscheme Monokai
@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'];
<?php
function function_stringify($func) {
$ref = new ReflectionFunction($func);
if ($ref->isInternal())
return '[internal]';
$top = $ref->getStartLine() - 1;
$len = $ref->getEndLine() - $top;
@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;
@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],
<?php
/**
* procedural wrappers for web request/response variables
*
* @author Jesus A. Domingo <jesus.domingo@gmail.com>
* @license MIT
*/
/**
* Gets a request parameter (from $_GET over $_POST combination)
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 / mappings.txt
Created January 15, 2014 02:58
example of ES parent-child mapping + query syntax
# topic mappings
POST /index/topic/_mapping -d '{
"topic": {
"properties": {
"section_id": { "type": "integer" },
"title": { "type": "string" },
"message": { "type": "string" },
"post_count": { "type": "integer" },
"status": { "type": "string", "index": "not_analyzed" },
"created_at": { "type": "integer" },