Skip to content

Instantly share code, notes, and snippets.

@mlconnor
mlconnor / country_codes
Last active September 26, 2015 19:48
Holds PHP country codes and links to flags.
<?php
// http://en.wikipedia.org/wiki/ISO_3166-1
// these are iso
$country_codes = array(
'AD' => "Andorra",
'AE' => "United Arab Emirates",
'AF' => "Afghanistan",
'AG' => "Antigua and Barbuda",
'AI' => "Anguilla",
'AL' => "Albania",
@mlconnor
mlconnor / numeric_abbr.php
Created September 2, 2011 19:29
Numeric abbreviation
<?php
/* this turns numbers like 45000 into 45K */
print "0=" . numeric_abbr(0) . "\n\n";
print "9=" . numeric_abbr(9) . "\n\n";
print "10=" . numeric_abbr(10) . "\n\n";
print "100=" . numeric_abbr(100) . "\n\n";
print "999=" . numeric_abbr(999) . "\n\n";
print "1000=" . numeric_abbr(1000) . "\n\n";
@mlconnor
mlconnor / grid.php
Created December 30, 2011 16:30
PHP Grid Builder
<?php
$column_width = 60;
$gutter_width = 20;
$columns = 12;
if ( isset($_GET['column_width']) ) {
$column_width = $_GET['column_width'];
}
if ( isset($_GET['gutter_width']) ) {
@mlconnor
mlconnor / generate_grid.php
Created January 6, 2012 21:12
PHP Grid Generator
<?php
/**
* This script will generate a grid overlay for
* a 960 style grid given three params, column_width, gutter_width, height.
* and columns. These will default if not provided. The result
* will be a PNG file. The height specifies the height of the image which
* defaults to 1.
*/
$expires = 60*60*24* 30;
@mlconnor
mlconnor / LocaleDates
Created February 21, 2012 19:21
This Java code will print out a list of the locale, country name, iso3166 code, iso639-2 code, and the corresponding date formats used in that country.
import java.text.SimpleDateFormat;
import java.util.*;
import java.io.*;
import java.text.DateFormat;
// this seems to work for everything but hindi and thailand
public class LocaleDates {
static public void main(String[] args) throws IOException {
@mlconnor
mlconnor / country_date_formats.csv
Created February 22, 2012 20:49
Listing of countries with their preferred date formats, ISO3166 code, ISO629-2
ISO 3166 Country Code ISO639-2 Country Code Country ISO 3166 Country Code ISO639-2 Lang Language Date Format
ALB AL Albania sqi sq Albanian yyyy-MM-dd
ARE AE United Arab Emirates ara ar Arabic dd/MM/yyyy
ARG AR Argentina spa es Spanish dd/MM/yyyy
AUS AU Australia eng en English d/MM/yyyy
AUT AT Austria deu de German dd.MM.yyyy
BEL BE Belgium fra fr French d/MM/yyyy
BEL BE Belgium nld nl Dutch d/MM/yyyy
BGR BG Bulgaria bul bg Bulgarian yyyy-M-d
BHR BH Bahrain ara ar Arabic dd/MM/yyyy
@mlconnor
mlconnor / proxy_curl.php
Created March 14, 2012 16:21
PHP CURL Code to grab a file through a proxy
<?php
print get_file('http://www.google.com');
function get_file($url) {
$curl = curl_init();
$options = default_ops(array(CURLOPT_URL => $url));
curl_setopt_array($curl, $options);
$output = curl_exec($curl);
@mlconnor
mlconnor / myParseIni.php
Created May 11, 2012 19:33
My Parse Ini Implementation in PHP
function myParseIni($iniStr, $processSections = false) {
// this will split on lines and then remove comments
$lines = preg_grep('|^\s*;|', preg_split('/$\R?^/m', $iniStr), PREG_GREP_INVERT);
$results = array();
$section = null;
foreach ($lines as $line) {
// print $line;
$matches = array();
if ( $processSections && preg_match('/^\s*\[\s*([^\s:]+)\s*(?::\s*(\S+))?\s*\]\s*$/', $line, $matches) ) {
@mlconnor
mlconnor / OgnlPath.php
Created May 15, 2012 21:41
Ognl Like Path Parser
$context = json_decode('{"this":{"that":{"some":[0,1,{"in":{"some":{"place":6}}}]}}}');
if ( ! $context ) throw new Exception('json parsing failed');
print OgnlPath::getValue('this.that.some[2].in.some.place', $context );
class OgnlPath {
public static function getValue($expression, $context) {
$tokens = preg_split('/(\[[^\]]+\])|(?:\.)/', $expression, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
print_r($tokens);
//print "context is " . print_r($context, true) . "\n";
foreach ($tokens as $index => $match) {
@mlconnor
mlconnor / ArrayMath.php
Created May 17, 2012 19:02
A php class that allows you to do functions across arrays of objects or arrays
$am = new ArrayMath();
$am->options = array('a'=>'sum', 'b'=>'avg', 'c'=>'max', 'd'=>'min', 'e'=>'prod');
$result = array(
array('a'=>1, 'b'=>2, 'c'=>3, 'd'=>5, 'e'=>2),
array('a'=>2, 'b'=>3, 'c'=>4, 'd'=>6, 'e'=>3),
array('a'=>3, 'b'=>4, 'c'=>0, 'd'=>7, 'e'=>4)
);
print_r($am->run($result));
/* RETURNS