Skip to content

Instantly share code, notes, and snippets.

View bluefuton's full-sized avatar

Chris R bluefuton

View GitHub Profile
@bluefuton
bluefuton / subversion.rake
Created April 7, 2010 10:45
Subversion: Rake task to mark any new files as added
namespace :svn do
desc "Subversion: mark any new files as added"
task :add do
system "svn status | grep '^\?' | sed -e 's/? *//' | sed -e 's/ /\ /g' | xargs svn add"
end
end
@bluefuton
bluefuton / cli_color.class.php
Created October 11, 2010 14:12
CliColor: add colour to command line output
<?php
// Based upon http://goo.gl/406o
class CliColor
{
private $foreground_colors = array();
private $background_colors = array();
public function __construct()
{
// Set up shell colors
@bluefuton
bluefuton / capistrano_mysql.rb
Created October 28, 2010 15:58
Capistrano: clone dev database to another stage (for example - cap staging mysql:clone_dev_db)
namespace :mysql do
task :clone_dev_db do
require 'ostruct'
db_config = OpenStruct.new(YAML.load_file("config/database.yml"))
dev_db = db_config.development
stage_db = db_config.send(stage)
cmd = "mysqldump -u #{dev_db['username']} -h #{dev_db['host']} -p'#{dev_db['password']}' #{dev_db['database']} " +
"--add-drop-table | mysql -u #{stage_db['username']} -p'#{stage_db['password']}' -h #{stage_db['host']} #{stage_db['database']}"
run cmd
end
@bluefuton
bluefuton / Automagic virtual hosts with mod_vhost_alias
Created November 17, 2010 11:58
Automagic virtual hosts with mod_vhost_alias
NameVirtualHost *:80
<VirtualHost *:80>
VirtualDocumentRoot "/Users/my.name/sandbox/%1"
</VirtualHost>
@bluefuton
bluefuton / to_sentence.php
Created November 22, 2010 17:39
Simple implementation of Rails' .to_sentence for PHP
<?php
class ArrayExtensions
{
public function to_sentence($array)
{
$count = count($array);
switch ($count)
{
case 0:
@bluefuton
bluefuton / codeigniter_facebook_p3p.php
Created February 4, 2011 10:38
Output P3P header so that cookies are accessible to Facebook canvas iframe in IE
<?php
// Output P3P header so that cookies are accessible to Facebook canvas iframe in IE
$p3p_header = 'policyref="/w3c/p3p.xml", CP="NOI DSP COR CURa ADMa DEVa PSAa PSDa OUR NOR UNI COM NAV"';
$this->output->set_header('P3P: '.$p3p_header);
@bluefuton
bluefuton / deploy_cached_copy_check.rb
Created May 20, 2011 10:31
Capistrano task to remove the cached-copy folder when the SVN URL of the cached-copy is different to the SVN URL of the deployed code
# When you switch SVN branches for deployment, Capistrano doesn't detect the change and
# simply does an 'svn up' on whatever branch you had previously deployed.
# This task checks if the cached copy's SVN URL matches the SVN URL you're deploying,
# and removes the cached copy if it doesn't match
namespace :cached_copy do
task :check do
cached_copy_path = "#{shared_path}/cached-copy"
# Does the cached copy exist?
cached_copy_exists = capture("if [ -d '#{cached_copy_path}' ]; then echo '1'; fi")
@bluefuton
bluefuton / grab_tweets.rb
Created August 18, 2011 16:25
Grab last 200 tweets
require 'rubygems'
require 'json'
require 'net/http'
require 'cgi'
twitter_user = 'agencyrepublic'
url = "http://twitter.com/statuses/user_timeline/#{twitter_user}.json?count=200&include_rts=1"
resp = Net::HTTP.get_response(URI.parse(url))
results = JSON.parse(resp.body)
@bluefuton
bluefuton / gist:1308773
Created October 24, 2011 11:01
FQL: Get photos of me
SELECT pid, src_big
FROM photo
WHERE pid IN(
SELECT pid
FROM photo_tag
WHERE subject = me()
)
@bluefuton
bluefuton / gist:1308809
Created October 24, 2011 11:23
FQL: get photos of me and a friend
SELECT pid, src_big
FROM photo
WHERE pid IN(
SELECT pid
FROM photo_tag
WHERE subject = me()
)
AND pid IN(
SELECT pid
FROM photo_tag