Skip to content

Instantly share code, notes, and snippets.

@cjbell
cjbell / gist:1705440
Created January 30, 2012 17:03
MY_Input ip_address while under ELB
<?php
class MY_Input extends CI_Input {
function __construct()
{
parent::__construct();
}
/**
* Fetch the IP Address
@cjbell
cjbell / gist:1716759
Created February 1, 2012 12:06
Codeigniter template for Lee
<?php
// Controller (method)
class Base extends CI_Controller {
function index(){
$data = array(
'page' => 'home',
'view' => 'pages/base/index.php'
);
$this->load->view('templates/base.php', $data);
@cjbell
cjbell / gist:1779690
Created February 9, 2012 12:31
Facebook Login
<div id="fb-root"></div>
<script src="https://connect.facebook.net/en_US/all.js"></script>
<script type="text/javascript" charset="utf-8">
FB.init({
appId : 'APP ID HERE',
status : true,
cookie : true,
xfbml : true,
});
</script>
<?php
if(!empty($page->page_headline)){
?>
<h1><?= $page->page_headline ?></h1>
<?php
}
?>
@cjbell
cjbell / gist:3082487
Created July 10, 2012 10:13
State machine
(function(window, $){
var StateMachine = function(){};
StateMachine.fn = StateMachine.prototype;
$.extend(StateMachine.fn, {
subscribe: $.subscribe,
publish: $.publish
});
StateMachine.fn.add = function(controller){
@cjbell
cjbell / gist:4083279
Created November 16, 2012 02:07
Heroku Deploy For Rails
function heroku_deploy(){
rake assets:precompile && g add . && g ca -m "Assets pre-compiled" && git push origin "$@" && git push heroku "$@":master && heroku run rake db:migrate
}
@cjbell
cjbell / gist:4086312
Created November 16, 2012 10:40
Simple grid
$container-width: 960;
$num-columns: 24;
$column-width: 30;
$gutter-width: ($container-width - $num-columns * $column-width) / $num_columns;
$container-px-width: $container-width * 1px;
$column-px-width: $column-width * 1px;
$column-pct-width: ($column-width / $container-width) * 100%;
$gutter-px-width: $gutter-width * 1px;
$gutter-pct-width: ($gutter-width / $container-width) * 100%;
@cjbell
cjbell / gist:4322604
Created December 17, 2012 21:48
Get Cached Wordpress Tweet
<?php
function get_cached_tweet($name){
$cache_name = $name . "_tweets";
if ( false === ($tweet = get_transient($cache_name))) {
// Get tweets
$site = "https://api.twitter.com/1/statuses/user_timeline.json?screen_name=".$name."&count=1";
$result = wp_remote_get($site);
$json = $result['body'];
if (!is_a($json, WP_Error)) {
@cjbell
cjbell / gist:4492733
Last active December 10, 2015 21:08
Heroku deploy for Middleman. Useage: heroku_deploy master
function heroku_deploy(){
middleman build && git add . && git commit -am "Site built and deployed." && git push origin "$@" && git push heroku "$@":master
}
@cjbell
cjbell / can_have_state.rb
Created January 10, 2013 12:10
Ultra simple state for models.
module CanHaveState
def can_have_state(states = {})
class_eval do
const_set("STATES", states.freeze)
const_set("STATE_CODE_TO_NAME", self::STATES.invert.freeze)
states.each do |type, value|
# Create some helper methods and scopes
scope type, where(:state => value)