Skip to content

Instantly share code, notes, and snippets.

View chrismcg's full-sized avatar

Chris McGrath chrismcg

View GitHub Profile
@chrismcg
chrismcg / plantuml.sh
Created April 17, 2013 13:11
PlantUML helper script for OSX. Generates a png and opens it
#!/bin/sh
# You need to download the jar from http://plantuml.sourceforge.net/ and put in ~/plantuml
# or alter the path below
java -jar ~/plantuml/plantuml.jar -tpng $@
open ${@%plantuml}png
[5] pry(main)> str = "The voucher entitles you to:> a kir> input> dish> dessert> coffee> a glass of wine"
=> "The voucher entitles you to:> a kir> input> dish> dessert> coffee> a glass of wine"
[6] pry(main)> str.split(/>/)[1..-1]
=> [" a kir", " input", " dish", " dessert", " coffee", " a glass of wine"]
chris@luath % dig a +short www.rubyireland.com
rubyireland.com.
204.232.175.78
chris@luath % dig ns +short www.rubyireland.com
rubyireland.com.
ns2.dnsimple.com.
ns3.dnsimple.com.
ns1.dnsimple.com.
ns4.dnsimple.com.
@chrismcg
chrismcg / gist:5212237
Created March 21, 2013 11:01
Simple ember jasmine spec
describe "StateLabelView", ->
stateLabelView = null
beforeEach ->
stateLabelView = App.StateLabelView.create()
Ember.run -> stateLabelView.append()
afterEach ->
Ember.run -> stateLabelView.remove()
@chrismcg
chrismcg / date_helper_patch.rb
Created January 16, 2013 13:04
Monkey patch Rails 2.3.x to not require symbol keys for date.order
require 'action_view/helpers/date_helper'
class ActionView::Helpers::DateTimeSelector
def translated_date_order
order = I18n.translate(:'date.order', :locale => @options[:locale]) || []
order.map { |item| item.to_sym }
end
end

I'm struggling with a problem related to using partial_fields and nested data. The examples below are a simplification of my actual problem but are enough I hope to demonstrate it.

Say I'm building a CMS and it supports multiple languages. In the editor for this CMS I'd like to show all the content the user can access and this access is restricted by the locales they can see and whether a particular piece of content has been set as visible yet.

Below are two ways I tried unsuccessfully to map this. Am I going to need to use parent/child documents?

curl -XDELETE 'http://localhost:9201/test_cms'

curl -XPUT 'http://localhost:9201/test_cms'
@chrismcg
chrismcg / 1 The requirements.txt
Created October 15, 2012 14:18
Config for running Localeapp in staging/production on Heroku
- poll every 5 minutes on :staging env
- poll on deployment only on :production env (not only dyno restart)
This assumes you've setup separate production/staging environments as described in:
https://devcenter.heroku.com/articles/multiple-environments
Especially the part about setting the RAILS_ENV/RACK_ENV on the staging environment.
The "polling" on deployment takes advantage of the fact that heroku runs the
@chrismcg
chrismcg / Gemfile
Created October 8, 2012 13:58
Sinatra and Localeapp
source :rubygems
gem 'sinatra'
gem 'localeapp'
chris@zippy % console
/Users/chris/.rvm/gems/ruby-1.9.3-p0@hablo/gems/actionpack-3.2.6/lib/action_dispatch/http/mime_type.rb:102: warning: already initialized constant ZIP
Loading development environment (Rails 3.2.6)
[1] pry(main)> class Foo; end
=> nil
[2] pry(main)> f = Foo.new
=> #<Foo:0x007fa9db90fa60>
[3] pry(main)> f.model_name
NoMethodError: undefined method `model_name' for #<Foo:0x007fa9db90fa60>
from (pry):3:in `<main>'
@chrismcg
chrismcg / MRI-1.9.3.txt
Created June 13, 2012 08:36
Yaml load benchmarking
chris@zippy % rvm 1.9.3-p0,1.9.3-p194 do ruby psych_benchmarker.rb
Calculating -------------------------------------
YAML 3929 i/100ms
-------------------------------------------------
YAML 44438.5 (±11.9%) i/s - 220024 in 5.035159s
Calculating -------------------------------------
YAML 350 i/100ms
-------------------------------------------------
YAML 3563.2 (±1.9%) i/s - 17850 in 5.011440s