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 / 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 / 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 / build.gradle
Last active August 29, 2015 14:10
Gradle build file for Android app with volley
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
defaultConfig {
applicationId "com.plymouthsoftware.android.volleyapp"
minSdkVersion 8
targetSdkVersion 21
@cblunt
cblunt / ProductsActivity.java
Created December 16, 2014 18:25
Parsing list of objects in JSON
public class ProductsActivity extends Activity {
// ...
// onCreate(), etc.
// ...
/**
* Assuming a JSON feed similar to:
* {
* "products": [
{
"message": "JSON Response OK",
"code": 200,
"images": [
{
"url": "http://assets.chrisblunt.com/wp-content/uploads/2012/12/IMG_20120619_202506-e1356946615784.jpg",
"title": "Hand Sunset"
},
{
"url": "http://assets.chrisblunt.com/wp-content/uploads/2010/01/PC280118.jpg",
@cblunt
cblunt / string_extensions.js
Created July 22, 2009 09:28
Adds an attributize() method to javascript String objects. Converts the sender string into an object attribute format for submission to a server.
Object.extend(String.prototype, {
/**
* Converts an underscore string into object attribute format for submission
* to a server (Based on Rails).
*
* To attributize the string client_firstName
* "client_firstName".attributize()
* => client[first_name]
*
* To attributize the string client_addresses__street
@cblunt
cblunt / form_tag_id_helper.rb
Created February 6, 2010 09:28
Small helper to get the generated id of form tags in a Rails fields_for block (http://chrisblunt.com/blog/2009/10/12/rails-getting-the-id-of-form-fields-inside-a-fields_for-block/)
# app/helpers/application_helper.rb
def sanitized_object_name(object_name)
object_name.gsub(/\]\[|[^-a-zA-Z0-9:.]/,"_").sub(/_$/,"")
end
def sanitized_method_name(method_name)
method_name.sub(/\?$/, "")
end
def form_tag_id(object_name, method_name)
@cblunt
cblunt / factories.rb
Created October 15, 2010 14:01 — forked from technicalpickles/factories.rb
Simulate paperclip attachments with FactoryGirl in Rails 3
Factory.define :application do |factory|
factory.attachment :sample, "public/samples/sample.doc", "application/msword"
end
@cblunt
cblunt / adb-list-packages.sh
Created June 21, 2011 13:14
List packages installed on an Android device
adb shell pm list packages
# 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'