Skip to content

Instantly share code, notes, and snippets.

View noodlehaus's full-sized avatar

noodlehaus noodlehaus

View GitHub Profile
@noodlehaus
noodlehaus / web_app.php
Last active December 15, 2017 06:39
bare bones routing function for 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])) {
@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 / 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 / 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" },
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;
<?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 / rankings.php
Created July 18, 2014 08:58
ranking formula example -- stackoverflow.com/questions/16168727/
<?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],
@noodlehaus
noodlehaus / minsql.php
Last active August 29, 2015 14:06
minsql concept
<?php
namespace noodlehaus\minsql;
# create pdo conn, or get last used, or null
function connect(...$args) {
static $pdo = null;
if (!count($args))
return $pdo;
<?php
function function_stringify($func) {
$ref = new ReflectionFunction($func);
if ($ref->isInternal())
return '[internal]';
$top = $ref->getStartLine() - 1;
$len = $ref->getEndLine() - $top;