Skip to content

Instantly share code, notes, and snippets.

View noodlehaus's full-sized avatar

noodlehaus noodlehaus

View GitHub Profile
@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) {
@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" },
@noodlehaus
noodlehaus / git-prompt.sh
Created December 9, 2013 06:53
git path info in PS1
# 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\] "
@noodlehaus
noodlehaus / .vimrc
Last active December 30, 2015 18:29
vimrc settings, given pathogen and some plugins are already installed
" pathogen
execute pathogen#infect()
syntax on
filetype on
filetype plugin on
filetype indent on
" core settings
set ruler
set tabstop=2
@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 / 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 / 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 / nomad.php
Created September 2, 2013 02:18
markdown-like, but not. function for formatting text.
<?php
function nomad($text) {
$text = htmlentities($text);
// strong
$text = preg_replace_callback('@\*(.+)\*@U', function ($m) {
return '<strong>'.trim($m[1]).'</strong>';
}, $text);
@noodlehaus
noodlehaus / fmt-test.php
Last active December 21, 2015 03:08
markdown-like string formatting function
<?php
include './fmt.php';
$text = '';
if (strtolower($_SERVER['REQUEST_METHOD']) === 'post')
$text = $_POST['text'];
?>
<!DOCTYPE html>
<html>
@noodlehaus
noodlehaus / ui-styles.css
Created July 25, 2013 08:59
controls style palette
@import url(http://fonts.googleapis.com/css?family=Open+Sans:400italic,700italic,400,700);
/*----------------
* control styles
*/
body {
color: #333;
font-size: 14px;
line-height: 19px;