Skip to content

Instantly share code, notes, and snippets.

@joshmcarthur
joshmcarthur / gist:1603677
Created January 12, 2012 22:57
JSON thing
# Can do this
object =
key: 1
value: 2
# But also presumably this...
object2 = new Ext.extend(Ext.Panel,
items: []
dockedItems: []
layout: 'fit'
@joshmcarthur
joshmcarthur / app.coffee
Created February 8, 2012 08:21
GET /deals/:latitude/:longitude
# Create a GET route, with named route segments for the latitude and longitude
app.get '/deals/:latitude/:longitude', (req, resp) ->
# Set the response content type to JSON
resp.contentType("application/json")
# Build the URI for retrieving deals from TreatMe
api_options = {
host: 'treatme.co.nz',
port: 80,
@joshmcarthur
joshmcarthur / app.coffee
Created February 8, 2012 08:26
GET /geocode
app.get '/geocode', (req, resp) ->
# Set the content type of the response
resp.contentType("application/json")
# Assemble the base URL to Google's geocoding service
geocode_url = {
host: 'maps.googleapis.com',
port: 80,
path: '/maps/api/geocode/json?sensor=true'
@joshmcarthur
joshmcarthur / git-browse
Created February 27, 2012 20:05
git-browse: Open repositories in Github from a Terminal
#!/usr/bin/env ruby
#### git-browse
### Open a github repository in the default browser
### Author: @sudojosh
### Usage: Run `git browse` inside a repo with at least one github remote
### Installation: Download, run `chmod +x git-browse`, and then copy somewhere on your path
### for example, /usr/local/bin/
remotes = `git remote -v`
@joshmcarthur
joshmcarthur / gist:2244508
Created March 29, 2012 22:42
Base Chart Class
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
#
#= require jquery.jqplot
#= require jqplot.dateAxisRenderer
#= require jqplot.enhancedLegendRenderer
#= require jqplot.highlighter
class LolChart
@joshmcarthur
joshmcarthur / gist:2364410
Created April 12, 2012 03:11
A Nicer Way of Building Records for accepts_nested_attributes_for
class YourModel < ActiveRecord::Base
has_one :listing
accepts_nested_attributes_for :listing
attr_accessible :listing_attributes
# Make sure we always have a listing
after_initialize :build_listing, :unless => :listing
end
@joshmcarthur
joshmcarthur / form_errors.rb
Created May 10, 2012 02:38
Render Rails form errors with Twitter Bootstrap styles
# config/initializers/form_errors.rb
#
# Wraps a <div> tag around the field with an error with the
# correct classes for Twitter bootstrap to style the inputs
# with errors correctly (red border/red box-shadow)
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance_tag|
"<div class='control-group error'>#{html_tag}</div>".html_safe
end
@joshmcarthur
joshmcarthur / trello-cards-from-csv.rb
Created May 30, 2012 22:32
A Ruby script to import Trello cards from a CSV file
#!/usr/bin/env ruby
# You can skip this bit if you wish - you will need the 'ruby-trello' gem installed, and
# optionally, 'foreman' to run the script with.
require 'bundler/setup'
Bundler.require
require 'trello'
require 'csv'
@joshmcarthur
joshmcarthur / application_modal.coffe
Created June 22, 2012 01:30
A simple Coffeescript class to build a Twitter Bootstrap modal
# You may want to call this something more specific - for example, in
# Latter, this is called 'GameModal'
class ApplicationModal
constructor: (options) ->
@options = $.extend {
header: 'Modal Heading'
content: ''
open_now: true
@joshmcarthur
joshmcarthur / gist:2993102
Created June 26, 2012 03:32
Reprocessing paperclip attachments
# Image is your ActiveRecord model
Image.find_each do |image|
# file is your
image.file.reprocess!
end