Automatic Lossless Reduction Of All Your Websites Images

NOTE: If you are on windows you can leave now.

  • LOSSLESS size reduction (10-97% size reduction) in the cloud
  • optmizes all images(jpg+png) from a given folder

Install:
sudo gem install smusher
#if you do not have get ruby + rubygems first
See Install instructions

Usage:
smusher /my_app/public/images

smusher LOCAL_FOLDER or IMAGE

Output:
smushing /my_app/public/images/cart_small.png
3322 -> 537                              = 16%

smushing /my_app/public/images/pro_icon.png
3022 -> 260                              = 8%

smushing /my_app/public/images/message.png
2898 -> 138                              = 4%

smushing /my_app/public/images/logo.png
6799 -> 9677                             = 142%
reverted!

Protection
As you see images that get larger or empty or cannot be processed are reverted.

has_a_location – the Latitude Longitude – Rails Plugin

Easy handling of latitude/longitude information, build on top of acts_as_mappable (aka geokit).

has_a_location Installation instructions

Usage

class User < ActiveRecord::Base
  has_a_location
end

@user.location = [11.101,22.121]# latitude , longitude
@user.in_radius(100) #find in 100 miles radius

#this location will not be stored since it is the "default location"
@user.location = [0,0] 

show_map if @user.location

All options and Readme

The Black White Tree Testing Method

snow tree by plain ethos

TDD often is well understood, but seldom put to good use. Spikes grow larger, hard to test aspects are skipped and sooner or later your test coverage looks like this.

.

Therefore i want to show you the Black-White-Tree testing method, which is easy to adopt and results in full C1(path) coverage with easy to maintain, independent tests.

.

.

ice tree by serendipitypeace2007

ice tree by serendipitypeace2007

The principle is simple:

When designing a new method build Black-Box tests for it, often 2-3 are sufficient if they exersice all paths within this method(not necessarily its sub-methods), represented by the trunk and the black branches.

describe :price do
  it "sums prices and applies discounts" do
    Order.new(:items=>items,:discount=>20).price.should == 22.5
  end
  it "costs nothing if it is free" do
    Order.new(:items=>items,:free=>true,:discount=>10).price.should == 0
  end
end

Then write White Box tests, for the public method, mocking everything out with forged return values to verify that every method is called and the call-results are used logically.

describe :price do
  ...
  it "uses sum_price and apply_discount" do
    order = Order.new(:items=>items,:discount=>10)
    order.expects(:sum_prices).returns 100
    order.expects(:apply_discount).with(10,100).returns 20
    order.price.should == 20
  end
end

Then build the method, making all White Box and some of the Black Box tests pass.
Repeat for every sub-method.

Numbers for Humans – Humanize for Numeric

number_with_precision(result.round(2)) — BE GONE!

Usage
1.humanize == “1”
1000000.humanize == “1.000.000”
1000.12345.humanize == “1.000,12”

Install

#config/initializers/numeric_humanize.rb
class Numeric
  def humanize(rounding=2,delimiter=',',separator='.')
    value = respond_to?(:round_with_precision) ? round(rounding) : self
    
    #see number with delimeter
    parts = value.to_s.split('.')
    parts[0].gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{delimiter}")
    parts.join separator
  end
end