This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # copy of http://ietherpad.com/x9mkM1vS4q | |
| # some notes of the discussion with JEG2 on #rmu irc channel at http://ietherpad.com/x9mkM1vS4q | |
| Blogs | |
| - Dave Thomas ( http://pragdave.pragprog.com/ ) | |
| - Jim Weirich ( http://onestepback.org/ ) | |
| - James Edward Gray II ( http://blog.grayproductions.net/ ) | |
| - Aaron Patterson ( http://tenderlovemaking.com/ ) | |
| - timeless ( https://github.com/judofyr/timeless ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # takes an arbitrary sql string and a connection (user and pass) and its params | |
| # and returns the csv output | |
| # $1 => sql string (required) | |
| # $2 => params for mysql command other than -u ie.user and -p ie.password (optional) | |
| # $3 => mysql connection command giving user and password (optional) | |
| # tested on mysql. | |
| # TODO: | |
| # 1. remove 'INTO OUTFILE' sql and convert using sed from tsv to csv. | |
| # also use raw mode and see how it escapes comma and tabs. another benefit is that if the | |
| # mysql runs remotely we will not be able to cat the file |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #http://stackoverflow.com/questions/1552598/building-multi-line-strings-programatically-in-ruby | |
| # multi_line strings in ruby with a margin to have a handle on whitespace eg. indent | |
| # TODO: rewrite it to use gsub and a single regex eg. code = <<-CODE.gsub(/^\s+/,''); | |
| # quite a lot of the temporary strings are created | |
| # hal fulton author of "the ruby way" | |
| # http://www.informit.com/articles/article.aspx?p=683059&seqNum=3 | |
| str = <<end.margin | |
| |This here-document has a "left margin" | |
| |at the vertical bar on each line. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # markup multilines in a string so as to denote where we want the line to begin explicitly, | |
| # we can nest them too for "indentation" | |
| # inspired from an article by hal fulton author of "The Ruby Way" | |
| # http://www.informit.com/articles/article.aspx?p=683059&seqNum=3 | |
| # gisted at https://gist.github.com/809145 | |
| # String#margin was splitting the string by creating temporary string while this use a regex | |
| class String | |
| # usage |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Add your own tasks in files placed in lib/tasks ending in .rake, | |
| # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. | |
| require(File.join(File.dirname(__FILE__), 'config', 'boot')) | |
| require 'rake' | |
| require 'rake/testtask' | |
| require 'rake/rdoctask' | |
| require 'tasks/rails' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # get the attributes after the class is loaded | |
| # tried two approaches first, overrding :attr_accessor, :attr_reader, :attr_writer is safest | |
| # it works but the method has to patched. if a class already has a patched defination then might have to use | |
| # method-chaining ie. alias. Patching is messy (sometimes) and politically incendiary :-) | |
| # Secondly, tried matching method-names to instance-variables where it if of the pattern | |
| # method-named foo for instance-variable @foo | |
| # but the instance variable is defined only when the variable is defined for | |
| # the first time, even if nil | |
| # this seems cleaner, but has two problems, it does not work and it is not perfect. we might have a | |
| # method-named foo for instance-variable @bar. This problem also exists in the first method |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| advantages of rails html helper and rendering of whitespace in erb templates | |
| == code | |
| <div> | |
| <textarea rows='300' cols='30' style="background-color:#DDDDFF"> | |
| <%= "hello\nworld" %> | |
| </textarea> | |
| </div> | |
| == html. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # scan a string, yielding the offset matched | |
| # http://www.rubular.com/r/qCz3jnyfZs | |
| require 'pp' | |
| class String | |
| def scan_offset(regex, old_offset=0, &block) | |
| regex = Regexp.new(regex) | |
| match = regex.match(self) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # can we delete elements while iterating | |
| # what about external iterators | |
| # usually have seen that the array is cloned and the delete operation | |
| # done on a copy of the array, this maybe because we are using an internal iterator | |
| require 'pp' | |
| foo = [*'1'..'10'].map!(&:to_i) | |
| pp "before:" | |
| pp foo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| The input element in rails formhelper always closes the tag | |
| Is it possible to have some text or image enclosed in an input tag, and to do it cleanly | |
| what is the rails way to do this? | |
| do we lose anything like, a closing tag with a minus to remove trailing spaces <-%> | |
| <% form_for(@message) do |f| %> | |
| <%= f.error_messages %> | |
| <p> | |
| <%= f.label :enabled, "Enabled (Y/N)" %></br> | |
| <%= f.radio_button :enabled, "yes", :checked => true %>Yes</input> |