Skip to content

Instantly share code, notes, and snippets.

@cam-gists
cam-gists / v2class.php
Created May 30, 2013 22:49
PHP: V2 class block
/**
* Class Name
*
* @author <Christopher A. Moore> cmoore@valuationvision.com, chris@camdesigns.net
* @package V2 | Valuationvision
* @usage
*
*/
@cam-gists
cam-gists / loc.php
Created March 11, 2013 22:37
PHP: Detect city and state ( infodb.com )
<?php
function detect_city($ip) {
$default = 'Hollywood, CA';
if (!is_string($ip) || strlen($ip) < 1 || $ip == '127.0.0.1' || $ip == 'localhost')
$ip = '8.8.8.8';
$curlopt_useragent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)';
@cam-gists
cam-gists / short_ar.php
Created January 26, 2013 00:41
PHP : Short Active Record
public function updateOrder($data = array())
{
$sql = 'UPDATE `user` SET ';
foreach ($data as $key => $value) {
if(is_numeric($value)){
$sql .= "`$key` = $value,";
}else{
$sql .= "`$key` = '$value',";
}
}
@cam-gists
cam-gists / betterindents.php
Created January 11, 2013 22:09
better indents??
<?php
$array = array(
'within' => 0,
'near' => 0,
'exceed' =>
);
foreach($data as $key => $value)
{
$r = businessHours(strtotime($value->ordereddate))/3600;
$diff = $r - $value->standard_sla;
@cam-gists
cam-gists / swiftmailer.php
Created December 26, 2012 22:13
PHP: PEAR swiftmailer
require_once 'swift_required.php';
// Mailer Config
$transport = Swift_MailTransport::newInstance();
// Message Setup
$message = Swift_Message::newInstance()
->setSubject('You now have access to Dropbox')
->setFrom(array('help@valuationvision.com' => 'Valuation Vision'))
->setTo(array($client_data->email => $client_data->firstname.' '.$client_data->lastname))
@cam-gists
cam-gists / dropbox.utility.class.php
Created December 19, 2012 22:50
PHP: Dropbox Utility Class
<?php
/**
* Dropbox helper Methods
*
* @author <Christopher A. Moore> cmoore@valuationvision.com, chris@camdesigns.net
* @package Dropbox API Extension
*/
class DropboxUtility
{
@cam-gists
cam-gists / phone.php
Created November 28, 2012 21:33
PHP: format Phone Number
function format_phone($phone)
{
$phone = preg_replace("/[^0-9]/", "", $phone);
if(strlen($phone) == 7)
return preg_replace("/([0-9]{3})([0-9]{4})/", "$1-$2", $phone);
elseif(strlen($phone) == 10)
return preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/", "($1) $2-$3", $phone);
else
return $phone;
@cam-gists
cam-gists / backup.php
Created November 12, 2012 17:31
PHP / Shell / AWS: snapsot backup
#!/usr/bin/php
<?php
// Pear Lib
require_once "XML/Unserializer.php";
$options = array(
                        'complexType' => 'object',
                        'encoding' => 'utf-8',
                        'parseAttributes' => TRUE,
                        'returnResult' => TRUE
@cam-gists
cam-gists / input.css
Created October 29, 2012 23:27
CSS: nice inputs
input{
border-radius: 5px;
box-shadow:inset 0 1px 3px #8dcfff;
background: #fff;
}
@cam-gists
cam-gists / hyphens.js
Created October 26, 2012 16:50
JS: Add hyphens as you type
function mask(str, textbox, loc, delim) {
var locs = loc.split(',');
for (var i = 0; i <= locs.length; i++) {
for (var k = 0; k <= str.length; k++) {
if (k == locs[i]) {
if (str.substring(k, k + 1) != delim) {
str = str.substring(0, k) + delim + str.substring(k, str.length)
}
}