Skip to content

Instantly share code, notes, and snippets.

@hipsterjazzbo
hipsterjazzbo / ajax.php
Created March 16, 2011 04:08
A CodeIgniter controller to enable dynamic AJAX access to models from views.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Ajax extends CI_Controller {
function __construct()
{
parent::__construct();
}
/**
@hipsterjazzbo
hipsterjazzbo / tweets.php
Created July 3, 2011 04:29
Quick tweet curl
<?php
$query = 'weekendhacker';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://search.twitter.com/search.json?q=$query");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$json = curl_exec($ch);
$tweets = json_decode($json);
@hipsterjazzbo
hipsterjazzbo / is_cached
Created July 28, 2011 01:43
Check is client is cached in the DB
public function is_cached($client_id)
{
$query = $this->db->select('id')->where('client_id', $client_id)->get('clients');
if($query->num_rows() == 0) {
return false;
}
return true;
}
<?php
// option 1
$config['admin']['example'] = array(
'table' => 'tbl_example',
'name' => 'Example',
'fields' => array(
'field_1' => 'Field 1 Title',
'field_2' => 'Field 2 Title',
'field_3' => 'Field 3 Title'
<?
function print_if($string, $condition = null)
{
if (is_null($condition))
{
if (is_null($string) || empty($string))
{
return '';
}
/**
* Determines the reconciliation status of the packing slip
*
* @return string $status The status of the packing slip. One of 'reconciled', 'partial', or 'unreconciled'
*/
function status()
{
// Get just the unreconciled item's first, because if it this is 0 we don't need to reconciled ones
$unreconciled_items = Actual_item_model::where(['packing_slip_id' => $this->id, 'merchant_invoice_line_item_id' => 0])->find();
<?php
function new_recurring_instance($job_template_id)
{
$job_template = Job_template_model::find($job_template_id);
$new_job_instance = Job_model::create();
// Copy some fields from template
$new_job_instance->company_id = $job_template->company_id;
<?php
public static function group_by(Array $objects, $group_by_property)
{
$grouped_objects = [];
foreach($objects as $object)
{
$property_value = $object->{$group_by_property};
#!/bin/bash
# Fergus Staging Deploy Script
# Update git to staging
cd /var/www/fergus_internal_demo;
#!/bin/bash
function bgtext {
echo -e $(tput setab 24)" $1"$(tput sgr0);
<?php
//TODO get URL from parameters and authenticate it with an expiring hash/timestamp
$url = 'http://traffic.libsyn.com/atpfm/atp95.mp3';
// Forward these headers from original request
$requestHeaders = [];
if (isset($_SERVER['HTTP_USER_AGENT'])) $requestHeaders[] = 'User-Agent: ' . $_SERVER['HTTP_USER_AGENT'];
if (isset($_SERVER['HTTP_RANGE'])) $requestHeaders[] = 'Range: ' . $_SERVER['HTTP_RANGE'];