Skip to content

Instantly share code, notes, and snippets.

View niczak's full-sized avatar

Nicholas Kreidberg niczak

  • Exacta Systems
  • Minneapolis, MN
  • LinkedIn in/niczak
View GitHub Profile
@niczak
niczak / gist:882246
Created March 22, 2011 22:38
Example of how to use PHP data w/ JavaScript functions
<?php
// Connect to database
$hDB = pg_connect("connection_parms_go_here");
// Grab list of tags
$hRes = pg_query($hDB, "SELECT sTag FROM tags WHERE bActive ='t' ORDER BY sTag");
pg_close($hDB);
// Store dataset in an array
$aRes = pg_fetch_all($hRes);
@niczak
niczak / gist:937909
Created April 22, 2011 23:07
IP detection and blocking w/ PHP.
<?php
// Define your DB table and application name.
define("sTABLE", "IP");
define("sAPP", "FooBar");
// Define SQL query to pull data from the IP table.
$sSQL = sprintf("SELECT * FROM %s WHERE (IP='%s' and sApp='%s') ORDER BY dRev DESC",
sTABLE, $_SERVER['REMOTE_ADDR'], sAPP);
// Example connection string.
@niczak
niczak / gist:983908
Created May 20, 2011 22:01
Basic example of creating/using cookies w/ JavaScript.
<!DOCTYPE HTML>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type="text/javascript">
function fnSetCookie(sName, sMode)
{
document.cookie=""+sName+"="+sMode + "; Expires=Wed, 09 Jun 2021 23:59:00 GMT;";
}
function fnGetCookie(sName)
@niczak
niczak / gist:1032563
Created June 17, 2011 23:13
DateTime Modification Function
<?php
fnDate_Modify($sModification)
{
/*
$sModification can be any incrementing
or decrementing string accepted by the
strtotime() function.
*/
@niczak
niczak / gist:1114960
Created July 29, 2011 23:25
Crystal Reports Leave Liability
SELECT e.display_employee, e.first_name, e.last_name, e.display_employee empid,
e.other_string3 employee_type, e.other_number3,
e.other_number1 salary, e.full_time_equiv_pct fte, sy.other_number1 serviceyears,
sum(case when bos.bank='DRI_ANNUAL'
then bos.balance
else 0
end) AL,
sum(case when bos.bank='T_SICK'
then bos.balance
else 0
@niczak
niczak / gist:1142507
Created August 12, 2011 17:26
PHP File Upload
<?php
function fnProcess_File($aFile, $hDB=NULL)
{
// Function process a single uploaded file
// Define file upload path
$sFile_Path = "/home/nicholas/Develop/PHP/FileUpload/Uploads";
// If no files uploaded return to caller
@niczak
niczak / gist:1150238
Created August 16, 2011 21:37
jQuery Form Validation
function fnValidate()
{
var aFields =
{"First Name":"sFirst",
"Last Name":"sLast",
"DRI Affiliation":"sAffil1",
"DRI Email":"sEmail_DRI"};
var bValid = true;
@niczak
niczak / gist:1238703
Created September 23, 2011 23:21
HTML Dropdown Menu Generator
<?php
function fnDisplay_DropDown($aFields, $sName, $sSel=NULL, $sClass=NULL, $sID=NULL)
{
if(empty($aFields) || empty($sName))
die("Parameter missing in call to fnDisplay_DropDown()");
if(!(is_array($aFields)))
die("Array passed to fnDisplay_DropDown() is in invalid format.");
$sHTML = sprintf(" <select name=\"%s\"%s%s>\n", $sName,
@niczak
niczak / gist:1293445
Created October 17, 2011 18:52
PHP Database String Replace Function
<?php
/*
dbfix.php
A function used to do a global string replacement in a
specific database table/column.
$aReplacements = array("search"=>"home.dri.edu", "replace="=>"oldintranet.dri.edu");
Sample usage: fnDB_Fix($hDB, "hr_menu_entries", $aReplacements);
Written: 10/17/2011, Nicholas Kreidberg
@niczak
niczak / gist:1296923
Created October 18, 2011 22:26
Simple Page Scraping
<!DOCTYPE html>
<html>
<!--[if lt IE 7 ]> <html lang="en" class="no-js ie6"> <![endif]-->
<!--[if IE 7 ]> <html lang="en" class="no-js ie7"> <![endif]-->
<!--[if IE 8 ]> <html lang="en" class="no-js ie8"> <![endif]-->
<!--[if IE 9 ]> <html lang="en" class="no-js ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html lang="en" class="no-js"> <!--<![endif]-->
<head>
<meta charset="UTF-8">
<title>Simple Page Scraping</title>