Skip to content

Instantly share code, notes, and snippets.

View dnch's full-sized avatar

Dan Cheail dnch

  • melbourne, au
View GitHub Profile
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?==+:~=::::::::::::~
<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>
@dnch
dnch / gist:1350453
Created November 9, 2011 05:02 — forked from damncabbage/gist:1350367
Calculating Mass-Assignable ActiveRecord Attributes
class Article < ActiveRecord::Base
# Has attributes: :title, :body, :active
attr_protected :active
end
class Image < ActiveRecord::Base
# Has attributes: :title, :filename, :active
attr_accessible :title
module ResourcefulRequestHelper
# Iterates through each route defined for the current controller, yielding
# each one to allow the same set of assertions / expectations to be tested.
#
# Usage:
# ======
# describe UsersController do
# let(:user) { double('user') }
#
[server] administrator:~$ nc -zvw 1 207.97.227.239 22
github.com [207.97.227.239] 22 (ssh) : No route to host
[server] administrator:~$ nc -zvw 1 207.97.227.239 80
github.com [207.97.227.239] 80 (www) open
class FancyMiddleware
def initialize(app)
@app = app
@excluded_paths = []
end
def call(env)
# env variable may be wrong here
if @excluded_paths.include(env["REQUEST_PATH"])
# do magic
@dnch
dnch / user.rb
Created December 19, 2011 22:50 — forked from jimsynz/user.rb
WTF!
class User
include Mongoid::Document
field :email
validates_format_of :email, :with => /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}$/i, :message => "is not a valid email adress."
end
class FoosController < AbstractController::Base
def update
@foo = Foo.find(params[:id])
# If our changed object saves...
if @foo.update_attributes(params[:attributes])
# Now, we check for changes. In some situations, we might
# use @foo.notify_changed? but given that update_attributes
# clobbers the dirty state of your instance, we need to
@dnch
dnch / babies_controller.rb
Created December 22, 2011 22:49 — forked from ptagell/babies_controller.rb
Update controller
def update
if @baby.update_attributes(params[:baby])
if params[:notify] == true
flash[:notice] = "Done"
else
redirect_to(root_url(:host => with_subdomain(@baby.subdomain)), :notice => 'Your baby was successfully updated and everyone has been told the good news.')
end
else
render :action => "edit"
end
# Given a big (~25MB) text file, I want to extract
# and process lines that are prefixed with a certain
# string. In the actual case, known_prefixes is
# approximately 50 elements long with potential for growth
known_prefixes = %w(aa ab ax fy fx)
regex = "^#{known_prefixes.join("|")} "
IO.foreach(big_ass_text_file).each |row|
if row =~ regex