Skip to content

Instantly share code, notes, and snippets.

View cblunt's full-sized avatar
👨‍💻
Coding

Chris Blunt cblunt

👨‍💻
Coding
View GitHub Profile
@cblunt
cblunt / cloudfiles-copy.rb
Created February 14, 2014 07:24
Quick script to recursively copy files from 1 folder to another on Rackspace Cloudfiles
require 'rubygems'
require 'fog'
# Configuration
CONTAINER_NAME = "your_container_name"
IGNORE_TYPES = ["application/directory"]
MAX_TRIES = 3
CF_USERNAME = "your_rackspace_username"
CF_API_KEY = "your_rackspace_api_key"
@cblunt
cblunt / hash_rocket_replace.rb
Last active August 29, 2015 13:55
Replace ruby rocket-syntax hash keys with JSON style
# Simple regex to replace ruby rocket-syntax hash keys with JSON style.
# e.g. Replace :some_key => "value" with some_key: "value"
#
# (Tested in sublime)
/:([a-zA-Z0-9_-]*)(( *)=>\ *)/$1: /
@cblunt
cblunt / README.md
Last active December 23, 2015 12:19
A simple widget for Dashing (http://http://shopify.github.io/dashing) to retrieve open and overdue invoices from FreeAgent and display their total value.

Description

A simple Dashing job to display the total value of open/overdue invoices from FreeAgent.

Dependencies

An app id/secret and access token setup via FreeAgent Developer.

Freeagent Api Gem

Add it to dashing's gemfile:

@cblunt
cblunt / myapp
Last active November 26, 2016 22:57
Rails app init.d script for passenger-standalone
#!/bin/bash
### BEGIN INIT INFO
# Provides: myapp passenger in standalone
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# X-Interactive: true
# Short-Description: Start/stop myapp.com web site
### END INIT INFO
#PATH=/sbin:/usr/sbin:/bin:/usr/bin
@cblunt
cblunt / freeagent_api_notes.md
Last active December 17, 2015 23:29
Notes from working with the FreeAgent API

Sample

{ "expense":
  {
    "user":"https://api.freeagent.com/v2/users/93049",
    "category":"https://api.freeagent.com/v2/categories/249",
    "dated_on":"2013-05-08",
    "gross_value":"-100.0", # Note required if a mileage expense
    "sales_tax_rate":"20.0",

"description":"TEST expense from API",

@cblunt
cblunt / codebase-import-tickets.rb
Created February 8, 2013 12:56
A simple Ruby script to bulk import a list of tickets into CodeBase (http://codebasehq.com). Depends on the codebase_api gem.
require 'rubygems'
# 1. Without Bundler
# $ gem install activesupport codebase_api
require 'active_support/core_ext/string'
require 'codebase_api'
# 2. With a Bundler Gemfile:
# # ./Gemfile
# gem 'codebase_api'
@cblunt
cblunt / MaskedImageView.java
Created July 25, 2012 11:22
Android MaskedImageView - Uses the Background resource as a mask for the src bitmap. If set, foregroundBitmap is overlaid on top of the masked image.
package com.example;
import android.content.Context;
import android.graphics.*;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.NinePatchDrawable;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.ImageView;
@cblunt
cblunt / AppActivity.java
Created May 9, 2012 10:15
Android: Custom Styled Dialog without border or title
public void showCustomDialog() {
Dialog dialog = new Dialog(this, R.style.Theme.CustomDialog);
dialog.setContentView(R.layout.custom_dialog);
// ...
dialog.show();
}
@cblunt
cblunt / spec_support.rb
Created February 27, 2012 13:36
Handy helper methods for RSpecs, e.g. logging in as a user.
# spec/support/spec_support.rb
def login_as(user = nil)
user ||= Factory.create(:user)
session[:user_id] = user.id
end
def current_user
User.find(session[:user_id])
rescue
# DEPRECATED: use https://gist.github.com/cblunt/1042832
# rails new my-app -m [raw url to this file]
gem 'json'
# Slim template
gem 'slim-rails'
gem 'simple_form'