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 / numToStr.php
Created January 8, 2014 20:36
Convert numbers to words.
<?php
function numToStr($val) {
$aLookup = array(
0 => "zero",
1 => "one",
2 => "two",
3 => "three",
4 => "four",
5 => "five",
@niczak
niczak / gist:5799935
Created June 17, 2013 20:14
Twitter API v1.1
<?php
function buildBaseString($baseURI, $method, $params) {
$r = array();
ksort($params);
foreach($params as $key=>$value){
$r[] = "$key=" . rawurlencode($value);
}
return $method."&" . rawurlencode($baseURI) . '&' . rawurlencode(implode('&', $r));
}
@niczak
niczak / gist:5716548
Created June 5, 2013 19:31
UpSert Logic for Eloquent ORM
<?php
// search model for matching key
$record = FormDB::find('blah@blah.com');
if($record) {
// record exists, update data
$record->text = "Updated";
$record->save();
} else {
@niczak
niczak / gist:5470218
Last active April 12, 2021 08:22
Check file extension w/ JavaScript
function checkFile(file) {
var extension = file.substr((file.lastIndexOf('.') +1));
if (!/(pdf|zip|doc)$/ig.test(extension)) {
alert("Invalid file type: "+extension+". Please use DOC, PDF or Zip.");
$("#file").val("");
}
}
@niczak
niczak / gist:5286125
Created April 1, 2013 16:50
URL Parser
function getParameterByName(param)
{
param = param.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + param + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.search);
if(results == null)
return "";
else
return decodeURIComponent(results[1].replace(/\+/g, " "));
@niczak
niczak / gist:4196906
Last active October 13, 2015 12:37
Extend error_log() capability with output buffering
<?php
// create dummy array for example
$array = array("one", "two", "three");
// turn on output buffering
ob_start();
// use var_dump to output the contents of the array/object
var_dump($array);
@niczak
niczak / gist:2501891
Created April 26, 2012 18:48
PHP Encrypt/Decrypt Class
<?php
class Encryption {
var $skey = "yourSecretKey"; // change this
public function safe_b64encode($string) {
$data = base64_encode($string);
$data = str_replace(array('+','/','='),array('-','_',''),$data);
return $data;
}
@niczak
niczak / gist:2362980
Created April 11, 2012 21:50
Time Sheet Summary [Crystal]
select
e.last_name,
e.first_name,
e.display_employee,
e.other_string3,
case when tso.pay_code in ('SICK', 'FURLOUGH_LEAVE', 'ANNUAL') then pc.short_description else ld3.short_description end proj_desc,
case when tso.pay_code in ('SICK', 'FURLOUGH_LEAVE', 'ANNUAL') then 'leave' else 'charge' end usage,
ld1.ld1 account_id,
ld1.short_description account_name,
ld3.ld1 project,
<?php
/*
db_utils.inc
Collection of database-related function used
by DRI applications.
Written: 03/30/2012, Nicholas Kreidberg
Revised: 03/30/2012, Nicholas Kreidberg
@niczak
niczak / gist:2174340
Created March 23, 2012 19:55
CSV Contact Generator
<?php
// database connection/retrieval code removed
$sCSV = NULL;
while($aRes = pg_fetch_assoc($rRes))
{
// first, middle, last, suffix, company, department,
// title, bus. street, bus. city, bus. state, bus. zip,