Awesome PHP has been relocated permanently to its own Github repository. No further updates will made to this gist.
Please open an issue for any new suggestions.
;; | |
;; NS CHEATSHEET | |
;; | |
;; * :require makes functions available with a namespace prefix | |
;; and optionally can refer functions to the current ns. | |
;; | |
;; * :import refers Java classes to the current namespace. | |
;; | |
;; * :refer-clojure affects availability of built-in (clojure.core) | |
;; functions. |
<?php | |
// this is the easiest way to add a delete command, by using one of the helper methods: | |
$query = new Solarium_Query_Update; | |
$query->addDeleteQuery('*:*'); | |
$query->addCommit(); | |
$client->update($query); | |
// alternatively you can construct the command yourself: |
<?php | |
// secure hashing of passwords using bcrypt, needs PHP 5.3+ | |
// see http://codahale.com/how-to-safely-store-a-password/ | |
// salt for bcrypt needs to be 22 base64 characters (but just [./0-9A-Za-z]), see http://php.net/crypt | |
$salt = substr(strtr(base64_encode(openssl_random_pseudo_bytes(22)), '+', '.'), 0, 22); | |
// 2y is the bcrypt algorithm selector, see http://php.net/crypt | |
// 12 is the workload factor (around 300ms on my Core i7 machine), see http://php.net/crypt |
<?php | |
function longest_common_substring($words) | |
{ | |
$words = array_map('strtolower', array_map('trim', $words)); | |
$sort_by_strlen = create_function('$a, $b', 'if (strlen($a) == strlen($b)) { return strcmp($a, $b); } return (strlen($a) < strlen($b)) ? -1 : 1;'); | |
usort($words, $sort_by_strlen); | |
// We have to assume that each string has something in common with the first | |
// string (post sort), we just need to figure out what the longest common | |
// string is. If any string DOES NOT have something in common with the first | |
// string, return false. |
#!/bin/bash | |
# | |
# Watch current directory (recursively) for file changes, and execute | |
# a command when a file or directory is created, modified or deleted. | |
# | |
# Written by: Senko Rasic <senko.rasic@dobarkod.hr> | |
# | |
# Requires Linux, bash and inotifywait (from inotify-tools package). | |
# | |
# To avoid executing the command multiple times when a sequence of |
fibs = {0: 0, 1: 1} | |
def _fib(n): | |
if n in fibs: return fibs[n] | |
if n % 2 == 0: | |
fibs[n] = ((2 * fib((n / 2) - 1)) + fib(n / 2)) * fib(n / 2) | |
return fibs[n] | |
else: | |
fibs[n] = (fib((n - 1) / 2) ** 2) + (fib((n+1) / 2) ** 2) | |
return fibs[n] |
# If not running interactively, don't do anything | |
[ -z "$PS1" ] && return | |
# simple history browsing | |
export HISTCONTROL=erasedups | |
export HISTSIZE=10000 | |
shopt -s histappend | |
bind '"\e[A"':history-search-backward | |
bind '"\e[B"':history-search-forward |
<?php | |
/* | |
Place this script in the Yii framework folder (yii-x.y.z.rxxx/yii-phar.php) and run it | |
to package the framework into a single phar file. | |
In the "index.php" of your application, assuming you placed the packaged framework under | |
your application's "protected" folder, add the following line at the top: |
Awesome PHP has been relocated permanently to its own Github repository. No further updates will made to this gist.
Please open an issue for any new suggestions.
GitHub supports several lightweight markup languages for documentation; the most popular ones (generally, not just at GitHub) are Markdown and reStructuredText. Markdown is sometimes considered easier to use, and is often preferred when the purpose is simply to generate HTML. On the other hand, reStructuredText is more extensible and powerful, with native support (not just embedded HTML) for tables, as well as things like automatic generation of tables of contents.