Skip to content

Instantly share code, notes, and snippets.

View dnch's full-sized avatar

Dan Cheail dnch

  • melbourne, au
View GitHub Profile
<form onsubmit="return makeFieldsTheSameValue();">
<!--
It's important that your input fields have unique ID attributes,
otherwise we won't be able to reference them easily via JavaScript.
-->
<label for="field_one">Field One</label>
<input type="text" name="field_one" value="" id="field_one">
<label for="field_two">Field Two</label>
Originally From: http://www.peo.gov.au/multimedia/library/pages/0148.html
DDDDDDDDDNNNNNNNNNNNNNNNDDDDDDDDDDDDD8OOZ7I$O8DD$I==~~~~~~~~~~~~~~~~~~~~~~~~~~~~
NNNNNNNNNNNNNNNMNMMNMNMNNNDNDDDD7I$O8OZZ8O7$D8DD$,?::~~~~~~~~~~~~~~~~~~~~~~~~~~~
NNNNDNNMMNMMMMMMMMMMMMMMMMNNNO7$DDODOO88I??ZI+IDOD88DZ+~~~::~::::::~:~~~~~~~:~~~
NNNNMMMMMMMMMMMMMMMMMMMMMMN8ZOZD8O$$OZZ$ZZZ$ZZZZ$Z$+888O?:~~~::::::::~~~~:::~~~~
DNNNMMNMNMMMMMMMMMMMMMMM8ZODN88DDD8DNDDD8D8DD88DDDN$7II~77,,:::~:::::::~~~~~~~~~
NNNNMMNMMMMMMMMMMMMMMNDZZZDDNDNDNN8NNDDD8DDDNDDNNDNZ8DO7I$==I+,::::::::~~~::~~~~
NNNNMMMMMMMMMMMMMMMMN8I7O88D88NDN8$88Z$O888O8NDDDNND8DDZ$7?++???:::~::::::::::::
NNNNMMMMMMMMMMMMMMM8O$$Z8DNN8D8OZZO88DDDDDDD8DDDDNND8DDZZ77I?==+:~=::::::::::::~
@dnch
dnch / gist:1084171
Created July 15, 2011 06:04
Grep Rails Routes
function grr {
if [[ -f ./Gemfile ]]; then
bundle exec rake routes | awk '{ print $1; }' | grep $1
else
rake routes | awk '{ print $1; }' | grep $1
end
}
@dnch
dnch / gist:1069126
Created July 7, 2011 08:54
I'm losing my mind...
SELECT (field_a + field_b + field_c) AS virtual_field, *
FROM "table_name"
WHERE ("table_name".reference_id = 9999 AND (virtual_field > 0))
AND (boolean_field = 't')
ORDER BY virtual_field DESC
function mate() {
if [[ `pwd` == ~ && $1 = "." ]]; then
echo "Steadfastly refusing to open your entire home directory in TextMate."
else
/usr/local/bin/mate $1
fi
}
[PlanetExpress] dan: ~/Desktop [ no repo | ree-1.8.7-2010.02@test ]
> gem install rails -v=2.2.2
Successfully installed activesupport-2.2.2
Successfully installed activerecord-2.2.2
Successfully installed actionpack-2.2.2
Successfully installed actionmailer-2.2.2
Successfully installed activeresource-2.2.2
Successfully installed rails-2.2.2
6 gems installed
it "determines the controller name" do
helper.instance_eval do
stub(:params).and_return(controller: 'foos')
resource_name.should == 'foos'
namespace.should == nil
end
end
#!/usr/bin/env ruby
class Foo
attr_accessor :bar, :baz, :florp
def initialize(properties = {})
properties.each do |key, value|
self.send("#{key}=", value)
end
end
class IncrementJumpingFormBuilder < ActionView::Helpers::FormBuilder
def fields_for_with_nested_attributes(association_name, args, block)
name = "#{object_name}[#{association_name}_attributes]"
association = args.first
if association.respond_to?(:new_record?)
association = [association] if @object.send(association_name).is_a?(Array)
elsif !association.is_a?(Array)
association = @object.send(association_name)
# First thing we need is the raw connection to our database. ActiveRecord makes this quite easy...
pg_connection = ModelName.connection.raw_connection
# Next, tell PG that we're going to be copying a boat load of data into model_names...
pg_connection.exec "COPY model_names (field_a, field_b, field_c) FROM STDIN"
# Process our file line-by-line
IO.foreach("path/to/file.tsv", "r") do |line|
# Convert our tab-delimited string into an array