Skip to content

Instantly share code, notes, and snippets.

View noodlehaus's full-sized avatar
😎
TPC rewrite

noodlehaus noodlehaus

😎
TPC rewrite
View GitHub Profile
@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 / .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 / .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 / 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 / .tmux.conf
Last active August 15, 2016 16:12
tmux settings
# behaviour
set -g base-index 1
set -g pane-base-index 1
set -g visual-activity on
set -g default-terminal "screen-256color"
setw -g monitor-activity on
# ctrl-a instead of ctrl-b
# set-option -g prefix C-a
@noodlehaus
noodlehaus / 00-aphpy-concept.php
Last active December 25, 2015 14:39
aphpy concept
<?php
// bootstrap file
use aphpy as app;
$blogs = app\load(__DIR__.'/fruits.php');
$books = app\load(__DIR__.'/books.php');
$v1 = app\prefix('v1', [
'books' => $books,
@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 / mysqli-extras.php
Created December 25, 2015 14:32
mysqli + extras, php7
<?php declare(strict_types=1);
# Executes a select and returns a single row.
function mysqli_select_one($db, string $sql, ...$params) {
$stmt = mysqli_interpolate($db, $sql, ...$params);
if (
!mysqli_stmt_execute($stmt) ||
false === ($result = mysqli_stmt_get_result($stmt))
@noodlehaus
noodlehaus / php-recipes.markdown
Last active August 10, 2017 14:41
Some patterns I use in plain old PHP apps

pulling values from arrays

$name = @$_POST['name'];
# => null or the value for name

defaults for associative arrays

@noodlehaus
noodlehaus / header-flush.php.text
Last active March 22, 2016 01:44
header flushing code from zend-diactoros
array_walk($headers, function ($value, $key) {
# validate header key (ref: zend-diactoros)
if (! preg_match('/^[a-zA-Z0-9\'`#$%&*+.^_|~!-]+$/', $key)) {
throw new InvalidArgumentException("Invalid header name - {$key}");
}
# validate header values (ref: zend-diactoros)
$values = is_array($value) ? $value : [$value];
foreach ($values as $val) {