Skip to content

Instantly share code, notes, and snippets.

View kenaniah's full-sized avatar

Kenaniah Cerny kenaniah

  • Rancho Palos Verdes, CA
  • 00:54 (UTC -07:00)
View GitHub Profile
@kenaniah
kenaniah / csv_reader.php
Last active December 15, 2015 06:39
CSV Reader
<?php
$reader = fopen("file.csv", "r");
$headers = null;
while($row = fgetcsv($reader)):
if(!$headers):
foreach($row as $k => $v) $row[$k] = trim(preg_replace("/\s+/", " ", $v));
$headers = $row;
continue;
endif;
@kenaniah
kenaniah / gist:2409921
Created April 17, 2012 23:37
Example PDO Database Extension
<?php
/**
* Database abstraction and query result classes (requires PHP 5.3)
*
* This class is built primarily for PostgreSQL 8.4+
* Compatibility with other database types is not guaranteed
*
* @author Kenaniah Cerny <kenaniah@gmail.com>
* @version 1.2.0
* @license http://creativecommons.org/licenses/by-sa/3.0/
@kenaniah
kenaniah / template.php
Created April 15, 2012 22:52
PHP Template Engine
<?php
/**
* Simple, scoped template rendering engine
*
* Variables may be passed to templates by setting dynamic
* properties of this class or by passing them at call time.
*
* @author Kenaniah Cerny <kenaniah@gmail.com> https://github.com/kenaniah/insight
* @license http://creativecommons.org/licenses/by-sa/3.0/
* @copyright Copyright (c) 2009, Kenaniah Cerny
@kenaniah
kenaniah / lockfile.sh
Created November 9, 2011 06:28
Linux lockfile wrapper
#!/bin/bash
# Lock file script written to ensure only once process at a time holds a lock
# Automatically kills zombie processes past the threshold
# https://gist.github.com/1350609
if [ $# -ne 3 ]; then
echo "Usage: `basename $0` <lockfile> <timeout> <command>";
exit 2;
fi
@kenaniah
kenaniah / hstore2json.sql
Created October 26, 2011 04:59 — forked from booo/hs_2json.sql
hstore to json function for postgresql
CREATE OR REPLACE FUNCTION public.hstore2json (
hs public.hstore
)
RETURNS text AS
$body$
DECLARE
rv text;
r record;
BEGIN
rv:='';