Skip to content

Instantly share code, notes, and snippets.

@noodlehaus
noodlehaus / web_app.php
Last active Dec 15, 2017
bare bones routing function for PHP.
View web_app.php
<?php
// minimal routing
function web_app($routes, $req_verb, $req_path) {
$req_verb = strtoupper($req_verb);
$req_path = trim(parse_url($req_path, PHP_URL_PATH), '/');
$found = false;
if (isset($routes[$req_verb])) {
View procweb.php
<?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)
@noodlehaus
noodlehaus / php-recipes.markdown
Last active Aug 10, 2017
Some patterns I use in plain old PHP apps
View php-recipes.markdown

pulling values from arrays

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

defaults for associative arrays

@noodlehaus
noodlehaus / detach.js
Created Feb 14, 2017
detach methods as functions
View detach.js
function detach(fn, cls) {
if (typeof cls.prototype[fn] !== 'function') {
throw new Error(fn + ' is not an instance function');
}
return cls.prototype[fn].call.bind(cls.prototype[fn]);
}
var slice = detach('slice', Array);
var map = detach('map', Array);
@noodlehaus
noodlehaus / private.xml
Last active Oct 7, 2016
Karabiner bindings for pok3r
View private.xml
<?xml version="1.0"?>
<root>
<!-- mac management -->
<item>
<name>Set Command_L + Esc to Window Switch</name>
<identifier>private.cmd_l_esc_to_window_switch</identifier>
<autogen>
__KeyToKey__
KeyCode::ESCAPE,
@noodlehaus
noodlehaus / .vimrc
Last active Aug 15, 2016
vim config
View .vimrc
" pathogen
execute pathogen#infect()
syntax on
filetype plugin indent on
" colors
set t_Co=256
colorscheme Monokai
@noodlehaus
noodlehaus / .tmux.conf
Last active Aug 15, 2016
tmux settings
View .tmux.conf
# 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 / header-flush.php.text
Last active Mar 22, 2016
header flushing code from zend-diactoros
View header-flush.php.text
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) {
@noodlehaus
noodlehaus / mappings.txt
Created Jan 15, 2014
example of ES parent-child mapping + query syntax
View mappings.txt
# 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" },
@noodlehaus
noodlehaus / git-prompt.sh
Created Dec 9, 2013
git path info in PS1
View git-prompt.sh
# alias
alias ls='gls --color=always --group-directories-first'
alias ll='ls -l'
# git prompt
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\.\1/'
}
export PS1="\[\033[38m\]\u@\h\[\033[01;36m\]:\w\[\033[32m\]\$(parse_git_branch)\[\033[37m\]$\[\033[00m\] "