1
2
3
4
import java.util.Scanner;

public class AsciiSquare {
...

Java On ascii square

by Jeremy Weiskotten, May 21, 2008 19:10

Here's a different approach...

5170ca260dbd2cdfd5a887a4dba7636f Talk
1
2
3
4
class WhoIsQuery
    query = ARGV[0]
    puts "Querying whois with #{query} ..."
...

Ruby On Whois refactoring

by Jeremy Weiskotten, May 14, 2008 19:31

You can use Enumerable#any?...

5170ca260dbd2cdfd5a887a4dba7636f Talk
1
2
3
def self.valid?(key)
  !(h = find_by_key(key)).nil? && h.invitation_details_count < h.total
end

Ruby On Better Nest Ifs

by Jeremy Weiskotten, April 21, 2008 15:04 Star_fullStar_fullStar_full

Here's a one-liner...

5170ca260dbd2cdfd5a887a4dba7636f Talk

Ruby On before_filter in model???

by Jeremy Weiskotten, April 21, 2008 14:55

There's a similar set of re...

5170ca260dbd2cdfd5a887a4dba7636f Talk
1
2
3
4
class Race < ActiveRecord::Base
  
  before_validation :set_abbreviation
...

Ruby On Help generating abbreviatio...

by Jeremy Weiskotten, April 08, 2008 00:24 Star_fullStar_fullStar_fullStar_fullStar_full

The problem is with chop.na...

5170ca260dbd2cdfd5a887a4dba7636f Talk
1
2
3
4
@week_endings ||= Actual.get_week_endings(4.weeks.ago.to_date)
last = @week_endings.last.week_ending
6.times do |i|
...

Ruby On Appending future dates to t...

by Jeremy Weiskotten, April 03, 2008 19:55

I think you can simplify it...

5170ca260dbd2cdfd5a887a4dba7636f Talk
1
2
3
4
def calculate_price_of_credits(credits, rates=nil)
  rates ||= [ [50000, 0.005], [25000, 0.006], [10000, 0.007], [5000, 0.008], [0, 0.01] ]

...

Ruby On Ugly method for calculating...

by Jeremy Weiskotten, March 08, 2008 01:30

A slightly more condensed v...

5170ca260dbd2cdfd5a887a4dba7636f Talk
1
2
3
4
def calculate_price_of_credits(credits)
  rates = [ 0.005, 0.006, 0.007, 0.008, 0.01 ]
  tiers = [ 50000, 25000, 10000,  5000,    0 ]
...

Ruby On Ugly method for calculating...

by Jeremy Weiskotten, March 07, 2008 21:21

Here's a refactoring with a...

5170ca260dbd2cdfd5a887a4dba7636f Talk

Ruby On Simple model methods to ret...

by Jeremy Weiskotten, March 06, 2008 18:43

rpheath, no it won't return...

5170ca260dbd2cdfd5a887a4dba7636f Talk

Ruby On Simple model methods to ret...

by Jeremy Weiskotten, March 05, 2008 21:05

rpheath, that's not going t...

5170ca260dbd2cdfd5a887a4dba7636f Talk
1
2
3
4
def self.get_budgeted_hours(charge, rollup)
  @value = find_by_charge_id_and_rollup_id(charge, rollup)
  (@value && @value.budgeted_hours) || '0'
...

Ruby On Simple model methods to ret...

by Jeremy Weiskotten, March 05, 2008 01:10

The dynamic find_by is good...

5170ca260dbd2cdfd5a887a4dba7636f Talk
1
month.months.ago

Ruby On last_number_of_months

by Jeremy Weiskotten, January 22, 2008 11:51

Rails provides an alternati...

5170ca260dbd2cdfd5a887a4dba7636f Talk
1
NameAddress[] entries = (NameAddress[]) list.toArray(new NameAddress[list.size()]);

Java On clean up nested loops?

by Jeremy Weiskotten, January 17, 2008 19:42 Star_fullStar_fullStar_fullStar_full

One thing you can do easily...

5170ca260dbd2cdfd5a887a4dba7636f Talk
1
2
3
4
class User
  has_many :messages do
    def by_type(type, options={})
...

Ruby On Rails has_many count

by Jeremy Weiskotten, January 12, 2008 21:18

To improve on Ryan's refact...

5170ca260dbd2cdfd5a887a4dba7636f Talk
1
2
3
4
<p>Messages:</p>

<p>
...

Ruby On Rails has_many count

by Jeremy Weiskotten, January 11, 2008 00:19 Star_fullStar_fullStar_fullStar_fullStar_full

You should let ActiveRecord...

5170ca260dbd2cdfd5a887a4dba7636f Talk
1
2
3
4
<script type="text/javascript">
window.onload = function() {
       var anchors = document.getElementsByTagName('a');
...

JavaScript On Shorten links

by Jeremy Weiskotten, January 08, 2008 14:31

This isn't a refactoring pe...

5170ca260dbd2cdfd5a887a4dba7636f Talk

PHP On Replace user input with link

by Jeremy Weiskotten, January 02, 2008 23:21

Some examples of PHP linkif...

5170ca260dbd2cdfd5a887a4dba7636f Talk
1
2
3
4
class ConnectFourBoard
  AIM = 4 # number of neighbouring tokens to obtain

...

Ruby On connect-four

by Jeremy Weiskotten, January 02, 2008 00:48

Some minor changes... origi...

5170ca260dbd2cdfd5a887a4dba7636f Talk
1
2
3
4
public class Car {

  public static class Builder {
...

Java Fluent Builder

by Jeremy Weiskotten, December 24, 2007 02:56, 1 refactoring, tagged with java, fluent interface, builder

Here's an example of the Bu...

5170ca260dbd2cdfd5a887a4dba7636f Talk
1
2
3
4
def list_for_blogentries(user)
  hash = user.blogentries.group_by {|entry| entry.created_at.to_s(:db).first(10)}
  hash.each_pair {|date, entries| puts date; entries.each {|entry| puts link_for_entry entry}}
...

Ruby On Refactor my blog item helper

by Jeremy Weiskotten, December 19, 2007 14:48

I'm not sure what your link...

5170ca260dbd2cdfd5a887a4dba7636f Talk
1
2
3
4
  # Action to toggle a favorite
  def favorite
    message = Message.find params[:id]
...

Ruby On Refactor my favorite action.

by Jeremy Weiskotten, December 12, 2007 18:39 Star_fullStar_fullStar_fullStar_full

I'd move the favorites mana...

5170ca260dbd2cdfd5a887a4dba7636f Talk
1
2
3
4
  def which_class?
    self.language = 'sh_' + 
    {
...

Ruby On class picker

by Jeremy Weiskotten, December 10, 2007 00:31 Star_fullStar_fullStar_full

Here's another way to do it...

5170ca260dbd2cdfd5a887a4dba7636f Talk
1
2
3
4
  def which_class?    
    lang = self.language.downcase
    lang.gsub!('+', 'p')
...

Ruby On class picker

by Jeremy Weiskotten, December 10, 2007 00:28 Star_fullStar_full

Here's another solution. Pl...

5170ca260dbd2cdfd5a887a4dba7636f Talk
1
2
3
4
def which_class
  if self.language == "C/C++"
     self.language = "sh_cpp"
...

Ruby On class picker

by Jeremy Weiskotten, December 10, 2007 00:21 Star_fullStar_full

A couple of initial impress...

5170ca260dbd2cdfd5a887a4dba7636f Talk

Ruby On Why does this look weird in...

by Jeremy Weiskotten, December 07, 2007 14:58 Star_fullStar_fullStar_fullStar_full

Have you tried validating t...

5170ca260dbd2cdfd5a887a4dba7636f Talk