Skip to content

Instantly share code, notes, and snippets.

<?php
/* Shorten a URL using Google's goo.gl API. Requires an API key. */
function googl_shorten_url($url, $api_key) {
$endpoint = 'https://www.googleapis.com/urlshortener/v1';
$ch = curl_init(sprintf('%s/url?key=%s', $endpoint, $api_key));
curl_setopt_array($ch, array(
\CURLOPT_POST => true
, \CURLOPT_AUTOREFERER => true
, \CURLOPT_FOLLOWLOCATION => true
, \CURLOPT_SSL_VERIFYPEER => false
<?php
function github_markdown($text) {
$ch = curl_init('https://api.github.com/markdown/raw');
curl_setopt_array($ch, array(
\CURLOPT_POST => true
, \CURLOPT_RETURNTRANSFER => true
, \CURLOPT_POSTFIELDS => $text
, \CURLOPT_SSL_VERIFYPEER => false
, CURLOPT_HTTPHEADER => array('Content-Type: text/plain')));
<?php
/**
* SplClassLoader implementation that implements the technical interoperability
* standards for PHP 5.3 namespaces and class names.
*
* http://groups.google.com/group/php-standards/web/final-proposal
*
* // Example which loads classes for the Doctrine Common package in the
* // Doctrine\Common namespace.

Awesome PHP

A list of amazingly awesome PHP libraries, resources and shiny things.

Composer

<?php
/* From: http://www.php.net/manual/en/function.str-getcsv.php#88773 and http://www.php.net/manual/en/function.str-getcsv.php#91170 */
if(!function_exists('str_putcsv'))
{
function str_putcsv($input, $delimiter = ',', $enclosure = '"')
{
// Open a memory "file" for read/write...
$fp = fopen('php://temp', 'r+');
// ... write the $input array to the "file" using fputcsv()...
fputcsv($fp, $input, $delimiter, $enclosure);
#!/bin/bash
#
# Steam installer for Debian wheezy (32- and 64-bit)
#
# Place into empty directory and run.
#
download() {
local url="$1"
local filename="$(basename "$url")"
@kafene
kafene / cd.sh
Last active December 21, 2015 04:08 — forked from mbadran/gist:130469
silent pushd (aliased to cd)
function cd {
if (("$#" > 0)); then
if [ "$1" == "-" ]; then
builtin popd >/dev/null
elif [ "$1" == "--" ]; then
dirs -v
return $?
elif [ "$1" == "." ]; then
# break out of symlinked dir (cd into realpath)
builtin pushd "`pwd -P`" >/dev/null

Microframework

This is a PHP (5.3+) microframework based on anonymous functions.

Features

  • requested URLs matched using regular expressions
  • request methods (matches using regular expressions too)
  • differenced FIFO queues for each $priority
  • command line usage
  • backward compatibility
  • integrated Dependency Injection and settings system
  • named patterns
@kafene
kafene / cmd.md
Created September 11, 2013 18:00 — forked from KenMacD/cmd.md