HTML stripper
str = <<HTML_TEXTApplication error
Change this error message for exceptions thrown outside of an action (like in Dispatcher setups or broken Ruby code) in public/500.html
HTML_TEXT puts str.gsub(/<\/?[^>]*>/, "")
TextSnippets > minofare > ruby
2784 users tagging and storing useful source code snippets
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 (or not, you can keep them private!)
Michael Baumgarten http://www.minofare.com
str = <<HTML_TEXTApplication error
Change this error message for exceptions thrown outside of an action (like in Dispatcher setups or broken Ruby code) in public/500.html
HTML_TEXT puts str.gsub(/<\/?[^>]*>/, "")
# wdays is an array with the days of the week # to exclude days (eg: wdays = [0,6] for sunday and saturday ) def calculate_working_days(d1,d2,wdays) diff = d2 - d1 holidays = 0 ret = (d2-d1).divmod(7) holidays = ret[0].truncate * wdays.length d1 = d2 - ret[1] while(d1 <= d2) if wdays.include?(d1.wday) holidays += 1 end d1 += 1 end diff - holidays end
d1 = Date.new( 2006, 12, 1 )
d2 = Date.new( 2007, 1, 15 )
weekdays = (d1..d2).reject { |d| [0,6].include? d.wday }
weekdays.length
def find_directories directories = [] entries = `ls -l`.split/\n/ # get long-format directory listing entries.shift # toss away the totals line entries.each do |entry| is_directory = (entry[0] == 'd') # is it a directory? directories << dir if is_directory end directories end
drwx------ 24 jcohen jcohen 816 Aug 19 11:04 Documents
irb> s = "Jeff" => "Jeff" irb> s[0] => 74
irb> s[0,1] => "J"