Refactor
:my
=>
'code'
Codes
Refactorings
Popular
Best
Submit
Spam
Account
Logout
Login
JavaScript doesn't seem to be activated, expect things to be ugly and sloppy!
More Jobs
Recent
Array#split_with(something)
StringExt.cs (String Extension)
showing records in Ascending or Descening order on click
Too many if else if
link_to with an image_tag and text
Ruby Custom Sort
Rails - Multiple instances and folder creation
MySQL original PHP 5 wrapper class
objects that deliver formatted HTML
Easy - descending range
Popular
link_to with an image_tag and text
Too many if else if
showing records in Ascending or Descening order on click
StringExt.cs (String Extension)
Array#split_with(something)
Exercise: Deaf Grandma
Find the Intersection of Arrays with a Hash
two for loops cleanup?
MySQL original PHP 5 wrapper class
Object with Field names as resources
Pastable version of
Building a dynamic date range
<div style="overflow:auto;border:solid 1px #ccc;background:#000;color:#F8F8F8"> <div class="section"> <pre style="float:left;margin:0 10px;border-right:0;color:#666;">1 2 3 4 5 6 7 8 9 10</pre> <pre class="sunburst"><span style="color:#E28964;">class</span> <span style="text-decoration:underline;">Article<span style="color:#9B5C2E;font-style:italic;"> <span style="color:#9B5C2E;font-style:italic;"><</span> ActiveRecord::Base</span></span> <span style="color:#AEAEAE;font-style:italic;"> <span style="color:#AEAEAE;font-style:italic;">#</span> Find all articles in the given date range based on the published_at field</span> <span style="color:#E28964;">def</span> <span style="color:#89BDFF;">self.find_archived</span>(<span style="color:#3E87E3;">year<span style="color:#3E87E3;">,</span> month<span style="color:#E28964;">=</span><span style="color:#65B042;"><span style="color:#65B042;">"</span>January<span style="color:#65B042;">"</span></span></span>) start_date <span style="color:#E28964;">=</span> <span style="color:#9B859D;">Date</span>.<span style="color:#89BDFF;">parse</span>(<span style="color:#65B042;"><span style="color:#65B042;">"</span><span style="color:#DAEFA3;"><span style="color:#DAEFA3;">#{</span>month<span style="color:#DAEFA3;">}</span></span>/01/<span style="color:#DAEFA3;"><span style="color:#DAEFA3;">#{</span>year<span style="color:#DAEFA3;">}</span></span><span style="color:#65B042;">"</span></span>) end_date <span style="color:#E28964;">=</span> (month <span style="color:#E28964;">==</span> <span style="color:#65B042;"><span style="color:#65B042;">"</span>January<span style="color:#65B042;">"</span></span>) <span style="color:#E28964;">?</span> start_time <span style="color:#E28964;">+</span> <span style="color:#3387CC;">1</span>.<span style="color:#89BDFF;">years</span> : start_date <span style="color:#E28964;">+</span> <span style="color:#3387CC;">1</span>.<span style="color:#89BDFF;">months</span> <span style="color:#3E87E3;">self</span>.<span style="color:#89BDFF;">find</span>(<span style="color:#3387CC;"><span style="color:#3387CC;">:</span>all</span>, <span style="color:#3387CC;"><span style="color:#3387CC;">:</span>conditions</span> => {<span style="color:#3387CC;"><span style="color:#3387CC;">:</span>published_at</span> => start_date .. end_date}) <span style="color:#E28964;">end</span> <span style="color:#E28964;">end</span> </pre> </div> </div> <a href="http://refactormycode.com/codes/293-building-a-dynamic-date-range" style="color:#fff" title="As seen on RefactorMyCode.com"><img alt="Small_logo" src="http://refactormycode.com/images/small_logo.gif" style="border:0" /></a>