This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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" }, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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\] " |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" pathogen | |
execute pathogen#infect() | |
syntax on | |
filetype on | |
filetype plugin on | |
filetype indent on | |
" core settings | |
set ruler | |
set tabstop=2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require __DIR__.'/request.php'; | |
require __DIR__.'/response.php'; | |
use badphp\context\request; | |
use badphp\context\response; | |
/** | |
* Request handling examples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function nomad($text) { | |
$text = htmlentities($text); | |
// strong | |
$text = preg_replace_callback('@\*(.+)\*@U', function ($m) { | |
return '<strong>'.trim($m[1]).'</strong>'; | |
}, $text); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include './fmt.php'; | |
$text = ''; | |
if (strtolower($_SERVER['REQUEST_METHOD']) === 'post') | |
$text = $_POST['text']; | |
?> | |
<!DOCTYPE html> | |
<html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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; |