Rails Performance Test

Filed under:rails — posted by admin on July 19, 2009 @ 2:46 pm
  • Install ruby-prof gem

  • gem install ruby-prof

  • Prepare fixtures test/fixtures/xxx for testing. Test one by one as the following:

  • ruby test/unit/xxx_test.rb

  • Edit test/performance/browsing_test.rb

  • require 'test_helper'
    require 'performance_test_help'

    # Profiling results for each test method are written to tmp/performance.
    class BrowsingTest < ActionController::PerformanceTest
    def test_homepage
    get '/'
    end
    end

  • Benchmarking

  • rake test:benchmark


    Started
    BrowsingTest#test_homepage (1062 ms warmup)
    process_time: 406 ms
    memory: 0.00 KB
    objects: 0
    gc_runs: 0
    gc_time: 0 ms
    .
    Finished in 10.501 seconds.

    5 tests, 0 assertions, 0 failures, 0 errors

  • Profiling

  • rake test:profile


    Started
    BrowsingTest#test_homepage (858 ms warmup)
    process_time: 655 ms
    memory: unsupported
    objects: unsupported
    .
    Finished in 32.845 seconds.

    3 tests, 0 assertions, 0 failures, 0 errors

YoWant$ Stock Insider Reports

Filed under:web2.0 — posted by admin on July 8, 2009 @ 10:21 am

I want to make money through insiders.

“Insiders might sell their shares for many reasons, but they buy for only one: they think the price will rise”

- Peter Lynch

Get real-time insider trading reports and analysis
Visit YoWantS

Sending data from rails to javascript using JSON

Filed under:rails — posted by admin on January 6, 2008 @ 12:38 am

RJS templates are a beauty, really. They allow you to run javascript code generated by rails, to be executed on the browser. Usually, this javascript code affects the DOM. But RJS, as it is often used now, is for affecting the look and behavior of a page with javascript. What if you have data that needs to be transferred from Ruby on Rails to the Javascript in the browser?

Well, my first inkling was to write a helper function that converted a matrix in Ruby, one by one, to a matrix in Javascript. But it felt ugly, like specialized complexity that’s just in your face. There has to be a better way, since I can’t be the first one to run into this problem.

Of course, there is and that’s using JSON–JavaScript Object Notation. A simple way to think of it is as XML, with less overhead, because JSON is simply that, a way to represent data in a standard format that’s easy for both humans to read and machines to parse.

In Rails 1.1+ (apparently, this has been around since at least May 2006), there’s been an extension added to Object class, and that’s to_json(). That’s right. You can serialize any object in rails to JSON, simply by calling to_json(). However, it’s not documented in the Rails API, so your best bet is to google for it.

As a quick and dirty way to demonstrate it, you can have this in your controller:

def some_action
# some type of data from somewhere in the database
@data = Data.find(1)
end

and then the following in your view somewhere:

You should be able to create helper functions that generate the javascript tags and the enclosing javascript so that it’d be a bit prettier, so it’d look like this in your view instead:

<%= act_on_data(@data) %>

Neat. So in this way, you can pass your data from your server to code in your views that isn’t to be displayed in HTML, but in some other form. One person has tied Adobe’s Flex in with Rails for this very purpose. Tip!

But one other thing that I realized after reading through JSON for the masses, is somewhat startling…at least to me. And in hindsight, perhaps it was because it never seemed easy to do in XML.

Usually data transfer languages such as XML and the like are declarative languages. They say the “what” instead of the “how”. That hasn’t stopped people from trying to do remote procedure calls with XML-RPC. But with JSON, it really is an object notation, meaning that you can put functions as data. So the example I gave before of javascript classes, they can instead be written in JSON notion in the source code and it would still work.

Therefore, the javascript interpreter itself IS the parser for JSON. You don’t need a separate parser in javascript like you do in XML. If JSON really does have cross-language compatibility, that’s actually rather neat. This implies that JSON-RPC is possible, and of course, a quick search on Google reveals that this is exactly what people are trying.

This kind of reminds me of how Von Neumann’s computer architecture was novel at the time because it treated program commands and data as the same thing. Before, computers had one place for data, and one place for a program. You didn’t store programs the same place that you stored data. By the same token, it also reminds me of how Lisp’s data is pretty much its code, and vice versa, and that’s where it derives a lot of its power.

Looking into the future (meaning, here on out, I’m talking out of my ass), perhaps that makes it easier to do distributed computing, and the stitching together of applications so very much desired by the Service Orientated Architecture crowd, but also a host of security issues. You might be able to get javascript programs that update each other on the fly in the field, instead of going all the way back to the server for updates (maybe).

Retrieve data using javascript in a rails application

Filed under:Uncategorized — posted by admin on @ 12:02 am

:o nchange=>remote_function(:url =>{:action => ‘Yr_action’},:with =>
“‘id=’+this.value”, :method=>:post)

FFTW Manual

Filed under:Uncategorized — posted by admin on December 30, 2007 @ 10:39 am

http://blog.weshoes.com/fftw-3.1.2/doc/html/index.html

Add iG:Syntax Hilter buttons in quicktags

Filed under:wordpress — posted by admin on @ 9:56 am

Please check http://blog.weshoes.com/iG_Syntax_Hilter_MANUAL.html#quicktags

textile syntax

Filed under:wordpress — posted by admin on @ 9:41 am

The following code is the syntax sample for textile. The output is shown after the code

[code]h2{color:green}. This is a title

h3. This is a subhead

p{color:red}. This is some text of dubious character. Isn't the use of "quotes" just lazy writing -- and theft of 'intellectual property' besides? I think the time has come to see a block quote.

bq[fr]. This is a block quote. I'll admit it's not the most exciting block quote ever devised.

Simple list:

#{color:blue} one
# two
# three

Multi-level list:

# one
## aye
## bee
## see
# two
## x
## y
# three

Mixed list:

* Point one
* Point two
## Step 1
## Step 2
## Step 3
* Point three
** Sub point 1
** Sub point 2

Well, that went well. How about we insert an old-fashioned hypertext link? Will the quote marks in the tags get messed up? No!

"This is a link (optional title)":http://www.textism.com

table{border:1px solid black}.
|_. this|_. is|_. a|_. header|
<{background:gray}. |\2. this is|{background:red;width:200px}. a|^<>{height:200px}. row|
|this|<>{padding:10px}. is|^. another|(bob#bob). row|

An image:

!/common/textist.gif(optional alt text)!

# Librarians rule
# Yes they do
# But you knew that

Some more text of dubious character. Here is a noisome string of CAPITAL letters. Here is something we want to _emphasize_.
That was a linebreak. And something to indicate *strength*. Of course I could use my own HTML tags if I felt like it.

h3. Coding

This is some code, "isn't it". Watch those quote marks! Now for some preformatted text:


	$text = str_replace("

%::%

","",$text);
	$text = str_replace("%::%

","",$text);
	$text = str_replace("%::%","",$text);


This isn't code.

So you see, my friends:

* The time is now
* The time is not later
* The time is not yesterday
* We must act[/code]

h2{color:green}. This is a title

h3. This is a subhead

p{color:red}. This is some text of dubious character. Isn’t the use of “quotes” just lazy writing — and theft of ‘intellectual property’ besides? I think the time has come to see a block quote.

bq[fr]. This is a block quote. I’ll admit it’s not the most exciting block quote ever devised.

Simple list:

#{color:blue} one
# two
# three

Multi-level list:

# one
## aye
## bee
## see
# two
## x
## y
# three

Mixed list:

* Point one
* Point two
## Step 1
## Step 2
## Step 3
* Point three
** Sub point 1
** Sub point 2

Well, that went well. How about we insert an old-fashioned hypertext link? Will the quote marks in the tags get messed up? No!

“This is a link (optional title)”:http://www.textism.com

table{border:1px solid black}.
|_. this|_. is|_. a|_. header|
<{background:gray}. |\2. this is|{background:red;width:200px}. a|^<>{height:200px}. row|
|this|<>{padding:10px}. is|^. another|(bob#bob). row|

An image:

!/wp-admin/images/notice.gif(optional alt text)!

# Librarians rule
# Yes they do
# But you knew that

Some more text of dubious character. Here is a noisome string of CAPITAL letters. Here is something we want to _emphasize_.
That was a linebreak. And something to indicate *strength*. Of course I could use my own HTML tags if I felt like it.

h3. Coding

This is some code, "isn't it". Watch those quote marks! Now for some preformatted text:


	$text = str_replace("

%::%

","",$text);
	$text = str_replace("%::%

","",$text);
	$text = str_replace("%::%","",$text);


This isn’t code.

So you see, my friends:

* The time is now
* The time is not later
* The time is not yesterday
* We must act

tinymce and quicktags

Filed under:wordpress — posted by admin on @ 8:52 am

One of the very first tasks I always perform on every new WordPress installation I do is to go into my user profile and turn off the visual WYSIWYG editor(e.g. tinymce). I prefer to handle all my formatting markup myself because it gives me more control over the final product. However, I do use quicktags to increase my productivity.

Do you use any formatting plugins for faster, easier, on-the-fly markup? If you use one of these plugins, why do you use that specific markup plugin? For instance, I use TextileWrapper on my own blog because I like how easy it is to add just a single character or two to a line or phrase to get the formatting I want. I originally used Text Control – and I still prefer – but it broke on a WordPress upgrade awhile back and is no longer being supported by the author, forcing me to find an alternative. TextileWrapper is an excellent plugin in its own right and continues to function well through each upgrade.

TinyMCE configuration

Filed under:wordpress — posted by admin on @ 8:41 am

TinyMCE’s configuration is determined when the WordPress edit page is loaded and are controlled by options set in the TinyMCE initialization process. More documentation on the configuration options can be found in the TinyMCE Configuration Reference.

In the WordPress version of TinyMCE, these options are set in a file entitled tiny_mce_gzip.php, which can be found in %WordPress_root%/wp-includes/js/tinymce.

Rails and relative_url_root

Filed under:rails — posted by admin on @ 7:31 am

And add a line at the end of config/environment.rb

ActionController::AbstractRequest.relative_url_root = "/netvibez"  

 

What this does is change the Rails application to run starting with a netvibez in the first part of the URL. It is useful!!!

For example, we need this when we develop facebook application. It is the canvas_path (http://apps.facebook.com/netvibez)


next page


image: detail of installation by Bronwyn Lace