1
2
3
4
// Don't know why you need hash > 0 and page.length > 1
// In case you don't need those conditions
var page = document.location.toString().split("#")[1];
...

JavaScript On Small Javascript Code

by Tien Dung, October 06, 2008 04:21 Star_fullStar_fullStar_fullStar_full
5071c5b861341c0dcfcf6ac86327701f Talk

Ruby On Cleaner Ruby

by Tien Dung, September 22, 2008 01:53

@Adam: cool refactoring :D

5071c5b861341c0dcfcf6ac86327701f Talk
1
2
3
4
def square(number)
  return number**2
end
...

Ruby On Conditional Assignment

by Tien Dung, September 22, 2008 01:27 Star_fullStar_fullStar_fullStar_fullStar_full

temp variable based version...

5071c5b861341c0dcfcf6ac86327701f Talk

Ruby On Conditional Assignment

by Tien Dung, September 22, 2008 00:01

Hi Daniel, can you ask Marc...

5071c5b861341c0dcfcf6ac86327701f Talk

Ruby On Conditional Assignment

by Tien Dung, September 21, 2008 22:31

Thanks Daniel. I found the ...

5071c5b861341c0dcfcf6ac86327701f Talk

Ruby On Conditional Assignment

by Tien Dung, September 21, 2008 16:19

Don't know who vote 1 star ...

5071c5b861341c0dcfcf6ac86327701f Talk
1
2
3
4
def square(number)
  return number**2
end
...

Ruby On Conditional Assignment

by Tien Dung, September 21, 2008 15:58 Star_fullStar_fullStar_fullStar_fullStar_full

Refactor Amos King .max fun...

5071c5b861341c0dcfcf6ac86327701f Talk
1
2
3
4
def square(number)
  return number**2
end
...

Ruby On Conditional Assignment

by Tien Dung, September 21, 2008 15:43 Star_fullStar_full

I prefer using temp variabl...

5071c5b861341c0dcfcf6ac86327701f Talk

Ruby On require_dependency

by Tien Dung, September 21, 2008 00:13

Thanks for your help guys :...

5071c5b861341c0dcfcf6ac86327701f Talk
1
2
3
4
def equate(level)
  (level + 300 * (2 ** (level / 7.0))).floor
end
...

Ruby On Cleaner Ruby

by Tien Dung, September 20, 2008 23:57

Man, you made your code ove...

5071c5b861341c0dcfcf6ac86327701f Talk
1
# Duplicated post, please help to delete

Ruby On Cleaner Ruby

by Tien Dung, September 20, 2008 23:34
5071c5b861341c0dcfcf6ac86327701f Talk
1
2
3
4
class Listing < ActiveRecord::Base
  require_dependency "listing/property_related"
  require_dependency "listing/price_related"
...

Ruby require_dependency

by Tien Dung, September 18, 2008 01:08, 3 refactorings

Rails require_dependency usage

5071c5b861341c0dcfcf6ac86327701f Talk
1
2
3
4
function state_classes(updateall) {
    var value = display.value * 1, tempcolor;
    var element, state, 
...

JavaScript On Color elements by state of ...

by Tien Dung, September 16, 2008 06:44

or using eval(..)

5071c5b861341c0dcfcf6ac86327701f Talk
1
2
3
4
function state_classes(updateall) {
    var value = display.value * 1, tempcolor;
    var element, state, states = ["Unknown", "Gas", "Liquid", "Solid"];
...

JavaScript On Color elements by state of ...

by Tien Dung, September 16, 2008 00:52
5071c5b861341c0dcfcf6ac86327701f Talk
1
2
3
4
function saveAndSet(obj, newValues) {
  var oldValues = {};
  for (var p in newValues) 
...

JavaScript On Setting focus after alert

by Tien Dung, August 19, 2008 00:41

Hi Daniel,

I create a sav...

5071c5b861341c0dcfcf6ac86327701f Talk
1
2
3
4
class UsersController < ApplicationController
  def index
    @users = find_all_and_order_by(params[:order_by])
...

Ruby On showing records in Ascendin...

by Tien Dung, August 06, 2008 14:07

Hi DG,

1) We should not pu...

5071c5b861341c0dcfcf6ac86327701f Talk
1
2
3
4
/**
 * http://www.openjs.com/scripts/events/keyboard_shortcuts/
 * Version : 2.01.B
...

JavaScript On Handling Keyboard Shortcuts...

by Tien Dung, August 06, 2008 07:22

My final attempt :)

5071c5b861341c0dcfcf6ac86327701f Talk
1
times -= events.map(&:datetime)

Ruby On two for loops cleanup?

by Tien Dung, July 31, 2008 02:05

Shortest version :)

5071c5b861341c0dcfcf6ac86327701f Talk
1
2
3
4
/**
 * http://www.openjs.com/scripts/events/keyboard_shortcuts/
 * Version : 2.01.B
...

JavaScript Handling Keyboard Shortcuts...

by Tien Dung, July 29, 2008 09:30, 1 refactoring

I found below code very use...

5071c5b861341c0dcfcf6ac86327701f Talk
1
2
3
4
module ThinkingSphinx
  class Search
    class << self
...

Ruby How to extend a class prope...

by Tien Dung, July 29, 2008 04:09, No refactoring, tagged with ruby metaprogramming

Recently, I need to extend ...

5071c5b861341c0dcfcf6ac86327701f Talk

JavaScript On countdown timer (minutes &a...

by Tien Dung, July 28, 2008 23:43

Hi Steve, just change to fu...

5071c5b861341c0dcfcf6ac86327701f Talk
1
2
3
4
##
# Fun with if .. else assignment ;)
# Change
...

Ruby On Horrible method to parse a ...

by Tien Dung, July 26, 2008 03:29
5071c5b861341c0dcfcf6ac86327701f Talk
1
2
3
4
def tab(name, options = {})
  match = [ controller.controller_name, root_of_path ].map(&:humanize).include?( name )
  content_tag( :li, link_to("<span>#{name}</span>", options), match ? { :class => "active" } : nil )
...

Ruby On How to DRY this up

by Tien Dung, July 25, 2008 13:58 Star_fullStar_fullStar_fullStar_full
5071c5b861341c0dcfcf6ac86327701f Talk
1
2
3
4
var odump = (function(){
  var max, INDENT = "                                   "; // As long as you need :)
  
...

JavaScript On Recursively dump an object

by Tien Dung, July 25, 2008 10:00

More JavaScript magic and e...

5071c5b861341c0dcfcf6ac86327701f Talk
1
2
3
4
function thousands(num, decpoint, sep) {
  decpoint = decpoint || ".";
  sep = sep || ",";
...

JavaScript On Thousands

by Tien Dung, July 25, 2008 09:03 Star_fullStar_fullStar_fullStar_fullStar_full

No RegExp refactor :)

5071c5b861341c0dcfcf6ac86327701f Talk