This file contains hidden or 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 | |
// 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])) { |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
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; |
This file contains hidden or 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 | |
/** | |
* procedural wrappers for web request/response variables | |
* | |
* @author Jesus A. Domingo <[email protected]> | |
* @license MIT | |
*/ | |
/** | |
* Gets a request parameter (from $_GET over $_POST combination) |
This file contains hidden or 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 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], |
This file contains hidden or 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 | |
namespace noodlehaus\minsql; | |
# create pdo conn, or get last used, or null | |
function connect(...$args) { | |
static $pdo = null; | |
if (!count($args)) | |
return $pdo; |
This file contains hidden or 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 function_stringify($func) { | |
$ref = new ReflectionFunction($func); | |
if ($ref->isInternal()) | |
return '[internal]'; | |
$top = $ref->getStartLine() - 1; | |
$len = $ref->getEndLine() - $top; |