Skip to content

Instantly share code, notes, and snippets.

@cam-gists
cam-gists / pdo.class.php
Created October 4, 2012 16:28
PHP: PDO Wrapper
<?php
/**
* PDO Wrapper Class
* @author Christopher A. Moore <[email protected]>
*
* @refs :
* http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/
* @test
*/
@cam-gists
cam-gists / log.php
Created October 2, 2012 20:18
PHP: Logger
<?php
/**
* Debug / Logger
*
* @author : christopher a. moore <[email protected]>
* @Usage :
* $log = new Log();
* $log->debug = true;
* $log->msg('Initialize Debug Class');
@cam-gists
cam-gists / mongo_aggregate.js
Created October 1, 2012 01:46
MongoDB: Aggregate Array Values
// ref: http://stackoverflow.com/questions/12654451/twitter-data-finding-the-most-mentioned-user-in-mongodb
// ref: http://stackoverflow.com/questions/12665866/mongodb-aggregating-array-items/12666156#comment17092191_12666156
var count = 0;
db.COLLECTION.find({key: "value"},{key_to_count:1}).forEach(
function (doc) {
count += doc.key_to_count.length;
}
)
print("key_to_count: " + count);
@cam-gists
cam-gists / config.php
Created September 11, 2012 05:43
PHP : config file
<?php
/**
* @author <Chris Moore>
* Config file sets all global options
* And Loads all Dependencies
* */
/**
* @param environment = prod, dev , etc. ..
@cam-gists
cam-gists / debug.php
Created September 11, 2012 05:41
ChromePHP: Extend Chrome PHP for DRY Debug
<?php
/**
* Base Class
* Extends ChromPhp to allow for Rapid Debugging based on needs
*/
class Base extends ChromePhp
{
public function __construct()
{
@cam-gists
cam-gists / js2phpobj.js
Created September 8, 2012 05:10
JavaScript / PHP: JSON Object to PHP Object
/**
* Converts a JS object to PHP object
**/
function jsObj2phpObj(object){
var json = '{';
for(property in object){
var value = object[property];
if(typeof(value) == 'string'){
json += '"' + property + '":"' + value + '",'
} else {
@cam-gists
cam-gists / gist:3532096
Created August 30, 2012 16:15
PHP: Pretty Print JSON
<?php
echo "<pre>";
$pattern = array(',"', '{', '}');
$replacement = array(",\n\t\"", "{\n\t", "\n}");
echo str_replace($pattern, $replacement, $data);
@cam-gists
cam-gists / quova.php
Created August 30, 2012 15:37
PHP: Quova / Neustar API IP Intel
<?php
/**
* Quova : http://developer.quova.com/
* *
* Key Rate Limits
* 2 Calls per second
* 1,000 Calls per day
*/
// initiate curl and set options
$ipin = '174.79.250.40'; // $_SERVER['REMOTE_ADDR'];
@cam-gists
cam-gists / weather.php
Created August 20, 2012 16:07
PHP: Google Weather API
<?php
function GetWeather($state,$country,$langauge,$waetherIcons){
// auf der Basis von http://www.web-spirit.de/webdesign-tutorial/9/Wetter-auf-eigener-Website-mit-Google-Weather-API
$api = simplexml_load_string(utf8_encode(file_get_contents("http://www.google.com/ig/api?weather=".$state."-".$country."&hl=".$langauge)));
// $trans = array("ä" => "ä", "Ä" => "Ä", "ü" => "ü", "Ü" => "Ü", "ö" => "ö", "Ö" => "Ö", "ß" => "ß");
$trans = array("ü" => "ü", "ö" => "ö", "ä" => "ä", "ß" => "ß");
$weather = array();
$i = 1;
foreach($api->weather->forecast_conditions as $GoogleWeather){
@cam-gists
cam-gists / links.php
Created August 20, 2012 16:06
PHP: Convert URLS -> Links