Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS 

Helpful extensions to core Ruby classes

If you find yourself doing this a lot:

   1  
   2  <% if @collection.any? -%>
   3  <ol>
   4    <% for item in @collection %>
   5      <li><%= item %></li>
   6    <% end -%>
   7  </ol>
   8  <% end -%>


...you might want to extend two Ruby core classes to automagically print out HTML-lists. Extend Array with:

   1  
   2  def to_html_list(type = :ol)
   3    self.inject("<#{type}>\n") { |output, item| output << "\t<li>#{item}</li>\n" } << "</#{type}>\n" if self.any?
   4  end


Now you can produce both OL (default) and UL lists. You can easily convert a Hash into a DL-list by extending it like so:

   1  
   2  def to_html_list
   3    self.inject("<dl>\n") { |o, p| o << "\t<dt>#{p[0]}</dt>\n\t<dd>#{p[1]}</dd>\n" } << "</dl>\n" if self.any?
   4  end


Extending core classes is a bit dangerous but I use these in almost every Rails project.

create linux bootdisk and fix grub after windows reinstall

Boot Disk Method
1. Create boot disk.
For Fedora Core 3:
   1  
   2  /sbin/grub-install /dev/fd0

For Fedora Core 4+:
   1  mkbootdisk `uname -r`

2. Reinstall Windows.
3. boot with floppy then
   1  grub-install /dev/hdb


Rescue CD
1. Boot using FC3 CD then
   1  
   2  linux rescue
   3  chroot /mnt/sysimage
   4  grub-install /dev/hdb


http://www.fedoraforum.org/forum/showthread.php?t=1272

To synchronize linux time -

My motherboard's battery's kind of out - so I have do this at startup (I added this in /etc/rc.d/rc.local)
   1  
   2  /usr/sbin/ntpdate pool.ntp.org 
« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS