Skip to content

Instantly share code, notes, and snippets.

View niczak's full-sized avatar

Nicholas Kreidberg niczak

  • Exacta Systems
  • Minneapolis, MN
  • X @niczak
View GitHub Profile
@niczak
niczak / format_date.php
Created December 7, 2010 00:37
Functions to add ordinal suffix to day values and convert integer months to string.
<?php
// Add ordinal suffix to day
function fnDay_Format($iday)
{
if(empty($iday))
die("No parameter passed to function.");
else
$iday = intval($iday);
@niczak
niczak / randomfile.php
Created December 27, 2010 22:46
Randomizes image file names in current directory for use w/ digital frames that don't support shuffle.
<?php
/*
randomfile.php
A quickie script that will take all images in
current directory, back them up to ./Orig and
rename all files in parent directory w/ random
numbers.
Written: 12/27/2010 - Nicholas Kreidberg
Revised: 12/27/2010 - Nicholas Kreidberg
@niczak
niczak / link_twitter.html
Created January 4, 2011 19:47
Two lines of JavaScript to convert @ names to Twitter profile links.
@niczak
niczak / gist:841548
Created February 24, 2011 01:02
Convert PostgreSQL timestamp to human readable date.
<?php
// Convert PostgreSQL timestamp to human readable date
function fnDisplay_Timestamp($sDT)
{
// Assuming $sDT is in format: YYYY-MM-DD HH:MM:SS.MS
if(empty($sDT))
fnErr("No parameter passed to fnDisplay_Timestamp() function.");
$aDT = explode(' ', $sDT);
@niczak
niczak / gist:842553
Created February 24, 2011 17:56
A function that will generate and return an HTML select element.
<?php
/*
Here is an example function call, array abbreviated for the example.
$afields = array("Jan"=>"January", "Feb"=>"February", "Mar"=>"March);
echo fnDisplay_DropDown($afields, "Months", "Mar", "required");
Results in:
<select name="Months" class="required">
<option value="Jan">January</option>
<option value="Feb">February</option>
@niczak
niczak / gist:843202
Created February 25, 2011 00:37
TextMate commands to escape/unescape quotes.
#!/usr/bin/env ruby
/* Thanks to @TextMateUser for help with this. */
/* Escape quotes */
puts STDIN.readlines.collect{|line| line.gsub('"','\\"')}
/* Remove escaping */
puts STDIN.readlines.collect{|line| line.gsub('\\"','"')}
@niczak
niczak / gist:852100
Created March 3, 2011 00:42
Function that sanitizes incoming $_POST data for insertion into MySQL/PostgreSQL.
<?php
////////////////////////////////////////////////////
// Written By: Nicholas Kreidberg //
// Revised By: Nicholas Kreidberg //
// Revised On: 10/01/2010 //
// Desc: fnSanitizePost() takes a $_POST array & //
// sanitizes all strings for insertion into a db. //
// Call: $aclean_post = fnSanitizePost($_POST); //
////////////////////////////////////////////////////
@niczak
niczak / gist:856945
Created March 6, 2011 01:59
Apache Virtual Host Config w/ MAMP
#
# Ports to listen on
#
Listen 8888
#
# Use name-based virtual hosting.
#
@niczak
niczak / gist:869992
Created March 14, 2011 22:18
Function/method for getting data (using an associative array map) from a form into a database.
<?php
/*
A simple example including sample function call and array map below.
This routine can be easily extended/customized to suit more complex
or just individual needs for a given dataset/table.
*/
function fnDB_Update($aFields, $aPost, $hDB, $sTable, $bQuery=TRUE)
{
@niczak
niczak / gist:876921
Created March 18, 2011 21:56
CSV Parser -> PostgreSQL Inserter
<?php
/*
csvparse.php
Function that will parse a CSV and insert
data into a postgres database.
Revised: 3/18/2011, Nicholas Kreidberg
CSV Structure [For This Example]:
1,1001,Description,Foo,Bar