Sunday, November 29, 2009

Swfobject helper

This Rails plugin makes including an swf object easier, no more writing javascript for that, just plain ruby.

To install this plugin:
  script/plugin install git://github.com/japetheape/swfobject_helper.git
Make sure swfobject.js is in your javascripts dir (download here:http://code.google.com/p/swfobject/)

http://agilewebdevelopment.com/plugins/swfobject_helper_plugin

Check your scripts with JSLint on Rails

Here's how you use it:

  1. Make sure you have Java installed (5.0 or later) – it's required to run Rhino.
  2. Install the plugin:
    ./script/plugin install git://github.com/psionides/jslint_on_rails.git
  3. Run the rake task:
    rake jslint

Voila :) That's all you need to check your JS code. You will get a result like this (if everything goes well):

Running JSLint:

checking public/javascripts/Event.js... OK
checking public/javascripts/Map.js... OK
checking public/javascripts/Marker.js... OK
checking public/javascripts/Reports.js... OK

No JS errors found.

If you've messed up something, you will get such results instead:

Running JSLint:

checking public/javascripts/Event.js... 2 errors:

Lint at line 24 character 15: Use '===' to compare with 'null'.
if (a == null && b == null) {

Lint at line 72 character 6: Extra comma.
},

checking public/javascripts/Marker.js... 1 error:

Lint at line 275 character 27: Missing radix parameter.
var x = parseInt(mapX);

Found 3 errors.
rake aborted!
JSLint test failed.

http://psionides.jogger.pl/2009/11/23/check-your-scripts-with-jslint-on-rails/

Saturday, November 28, 2009

Rails 2.3.5

Rails 2.3.5 changes:
  1. Minor Bug Fixes and deprecation warnings
  2. Ruby 1.9 Support
  3. Fix filtering parameters when there are Fixnum or other un-dupable values
  4. Improvements to ActionView::TestCase
  5. Compatiblity with the rails_xss plugin
http://github.com/rails/rails/tree/v2.3.5

Thursday, November 26, 2009

WebROaR

Ruby Application Server
  • Dead simple Ruby on Rails™ Application Deployment
  • 5 to 55% faster than other deployment stacks
  • Admin Panel with run time performance numbers
  • Exception Notifications
  • Free & Open Source Software
Features
  • Simplified deployment with maximum performance
  • Runs Ruby on Rails™ as well as other Rack compliant applications
  • Run multiple applications simultaneously
  • Intelligent load balancing
  • Dynamically reap stuck Ruby processing instances
  • Provides run time performance data for the deployed applications
  • Generates notifications in case exceptions occur in any of the deployed applications
Download
  • WebROaR can be downloaded and installed using the following commands:

    gem sources -a http://gems.github.com
    sudo gem install webroar
    sudo webroar install

  • Or if one likes living in the fast lane, the edge version can be installed using the following commands:

    git clone git://github.com/webroar/webroar
    cd webroar
    sudo rake install
http://webroar.in

Wednesday, November 25, 2009

Creating images from unicode text using rmagick

To create images from the unicode text, we can use the "encoding" method for the Draw object.
Example:
require "RMagick"
def show_textimg
bg = Magick::Image.new(120,20){self.background_color = "#9E9E9E"}
text = Magick::Draw.new
text.encoding = "Unicode"
text.text(23,14,"ドの半角⇔全角")
text.draw(bg)
bg.write "#{RAILS_ROOT}/public/images/text.jpg"
end
http://thinkingrails.blogspot.com/2009/08/creating-images-from-unicode-text-using.html

Tuesday, November 24, 2009

Amp

About Amp

Amp is a general-purpose version-control system. It currently implements Mercurial, and we hope to support git, bazaar, svn, cvs, and darcs in the future. Why? Well, that leads us to the question: "Why Amp?"

Amp is NOT:

Amp does not define a repository format, and most likely never will.

Then why make a VCS?

Amp exists because there's plenty of excellent repository formats out there, but none of them are truly good software. We chose Mercurial as our first VCS to implement because it comes closest to what we feel is a solid user experience, and that's what we're building upon.

Amp exists to make VCS work for you. Want to add your own commands? Write a few lines of code. Want to use git's commands on a Mercurial repository, switches and all? Amp is working on it. Our goal is to produce a piece of software that lets you forget that you're working on git project one moment and a Mercurial project the next.

Amp's Features

  • Workflows - customizable command sets (e.g. git's commands, svn's commands)
  • Commands - work with your VCS on your terms
  • Ampfiles - tweak amp's settings for a specific repository with one file
  • Want more features? Help develop Amp! We've got a lot planned!
http://amp.carboni.ca/

Sunday, November 22, 2009

Diagnose and Prevent AJAX Performance Issues!

AJAX improves user experience by moving more code to the browser. Frameworks accelerate development, but lead to opaque application behavior and new performance issues.
dynaTrace AJAX Edition aims to solve these issues:

  • Understand performance as real users experience it
  • Differentiate between browser or server bottlenecks
  • Trace asynchronous JavaScript executions for the full round-trip
  • Analyze JavaScript, AJAX remoting, network and rendering performance in real-time
  • Save performance data for interactive offline analysis
  • Transform Selenium/Watir tests into performance tests and integrate them with your CI environment
http://ejohn.org/blog/deep-tracing-of-internet-explorer/
http://ajax.dynatrace.com/pages/

Wednesday, November 18, 2009

Redmine

Redmine is a flexible project management web application. Written using Ruby on Rails framework, it is cross-platform and cross-database.

Redmine is open source and released under the terms of the GNU General Public License v2 (GPL).

Overview

  • Multiple projects support
  • Flexible role based access control
  • Flexible issue tracking system
  • Gantt chart and calendar
  • News, documents & files management
  • Feeds & email notifications
  • Per project wiki
  • Per project forums
  • Time tracking
  • Custom fields for issues, time-entries, projects and users
  • SCM integration (SVN, CVS, Git, Mercurial, Bazaar and Darcs)
  • Issue creation via email
  • Multiple LDAP authentication support
  • User self-registration support
  • Multilanguage support
  • Multiple databases support
http://www.redmine.org/

nested relations in ActiveRecord

class State < ActiveRecord::Base
has_many :cities
end

class City < ActiveRecord::Base
has_many :streets
belongs_to :state
end

class Street < ActiveRecord::Base
has_many :houses
belongs_to :city
end

class House < ActiveRecord::Base
belongs_to :street
end
How do you get all of the Houses in virginia?

Well, you could do this:

virginia.cities.collect{|c| c.streets}.flatten.uniq.collect{|s| s.houses}.flatten.uniq
... but that's epically lame. It looks like shit and produces an metric ton of queries and as a result is highly inefficient.

How about this:

House.find(
:all,
:include => {:street => {:city => :state}},
:conditions => {'states.id' => virginia.id}
)

This is a single query with joins where appropriate, and it's a finder on House which is what you're getting anyways. Makes sense, no?

http://joshsharpe.com/archives/56

Understanding the MySQL forks

But in the distributed revision control world we live in, it's never really that simple. Here are some other notes:

  • XtraDB is an InnoDB fork and "mostly" only a storage engine. It has a future in MariaDB and Drizzle, but may not make it into MySQL (about to be owned by Oracle, who also owns InnoDB).
  • OurDelta collects more patches than just the Percona patches, and enables the PBXT storage engine. There's also a repository of OurDelta for 5.1 - binaries just aren't out yet.
  • Like XtraDB, PBXT has a future in Drizzle, MariaDB and *maybe* also MySQL (Oracle may be more friendly towards PBXT than XtraDB, but Oracle is not known to be friendly so who knows!). I left PBXT absent from the diagram for not having much of a lineage with previous MySQL releases (flames welcome if you disagree).
  • XtraDB draws a lot from the Google patches for MySQL/InnoDB (not present on the diagram either).
  • Drizzle is now incompatible with everything else in MySQL-land terms (replication, partitioning, etc), and they're happy to be. In storage engine terms, they're still compatible though, which leads me to describe Drizzle as a completely new "userland", with storage engine options still remaining very similar.
  • MariaDB is both a new storage engine (Maria) and a userland "delta" of MySQL. I call it a delta since it is trying to keep binary-format compatibility with MySQL wherever it can. This means that it makes a good retrofit, but it limits what they can do without changing things like the .frm format, etc.
  • The InnoDB plugin has a weird history. Oracle announced it as an optional replacement for the 5.1 InnoDB but not much has become of it since introduction. I would have expected 5.4 to be based off the plugin, but it's not (at least at this point).
  • MySQL is the real loser in the direction the patches are moving. While all other forks are free to share amongst themselves (where compatible) and take from MySQL, MySQL will only accept a patch if the author signs a Contributor's License Agreement. They need to do this - otherwise they can't sell OEM copies, which still make a large chunk of sales. Until recently, MySQL didn't accept any InnoDB patches unless they came downstream from Oracle, and Oracle keeps InnoDB development as a closely guarded secret - which makes influencing it very difficult.
http://mtocker.livejournal.com/50931.html

Tuesday, November 17, 2009

JSGI

JSGI is a web server interface specification for JavaScript, inspired by Ruby’s Rack (http://rack.rubyforge.org/) and Python’s WSGI (http://www.wsgi.org/). It provides a common API for connecting JavaScript frameworks and applications to webservers.

Jack is a collection of JSGI compatible handlers (connect web servers to JavaScript web application/frameworks), middleware (intercept and manipulate requests to add functionality), and other utilities (to help build middleware, frameworks, and applications).

http://jackjs.org/

Narwhal

Narwhal is a cross-platform, multi-interpreter, general purpose JavaScript platform. It aims to provide a solid foundation for building JavaScript applications, primarily outside the web browser. Narwhal includes a package manager, module system, and standard library for multiple JavaScript interpreters. Currently Narwhal’s Rhino support is the most complete, but other engines are available too.

Narwhal’s standard library conforms to the ServerJS standard. It is designed to work with multiple JavaScript interpreters, and to be easy to add support for new interpreters. Wherever possible, it is implemented in pure JavaScript to maximize reuse of code among engines.

Combined with Jack, a Rack-like JSGI compatible library, Narwhal provides a platform for creating server-side JavaScript web applications and frameworks such as Nitro.

http://narwhaljs.org/

Sunday, November 15, 2009

DB Charmer – ActiveRecord Connection Magic Plugin

DbCharmer is a simple yet powerful plugin for ActiveRecord that does a few things:

  1. Allows you to easily manage AR models’ connections (switch_connection_to method)
  2. Allows you to switch AR models’ default connections to a separate servers/databases
  3. Allows you to easily choose where your query should go (on_* methods family)
  4. Allows you to automatically send read queries to your slaves while masters would handle all the updates.
  5. Adds multiple databases migrations to ActiveRecord

Thursday, November 12, 2009

OurDelta

OurDelta produces enhanced builds for MySQL 5.0 and builds for MariaDB 5.1, on common production platforms. James Purser of Open Source On The Air describes OurDelta as “a new distribution for MySQL”.

http://ourdelta.org/

Firebug HTTP Time Monitor

Firebug now uses a component called http-activity-distributor that allows to register a listener and get notifications about various phases of each network request (DNS Lookup, connecting, sending, etc.). The most important thing is that one of the parameters passed to the listener is a time-stamp. This is something what was missing till now.

Having the time-stamp is critical since Javascript code (and Firebug is entirely implemented in Javascript) is executed on Firefox UI thread. In case when the UI is blocked by time expensive operation (e.g. DOM rendering, script execution, etc.) any event sent to a Javascript handler (and so, handled on the UI thread) can be delayed. So, getting the time-stamp withing JS handler can produce impaired time results.

Firebug Net panel now fixes this problem and the timing info is correct. See couple of examples I have analyzed when testing with a nice online tool called Cuzillion developed by Steve Souders.

Inline Scripts Block

Inline scripts block downloads and any resources (e.g. images) below an inline script don't get downloaded until the script finishes execution.

Let's imagine a page with following structure.

<html>
<head></head>
<body>
<img src="resource.cgi" />
<script> {an inline script running for 5 sec } </script>
<img src="resource.cgi" />
</body>
</html>
Here is a timeline of such page displayed in Firebug.

Inline Scripts Block

The first image resource.cgi starts downloading immediately after the page itself is downloaded. The second image resource.cgi starts downloading after 5 sec delay caused by the inline script. Try the example online.

The green area represents connecting time an the purple area represents waiting for response time. The blue line shows when DOMContentLoaded event was fired and the red line is associated with page load event.

Connection Limit

Firefox limits the number of connections per server to 6. If the limit is reached other requests wait in an internal queue. This value can be changed by editing network.http.max-persistent-connections-per-server preference in about:config

See how the timeline looks like for a page that loads 8 images.

Firefox Limits the number of connections

See the last two images. These are waiting in a queue (light brown area) till there is a free connection. The 7th image starts downloading as soon as the first image finishes and share the same connection (see, there is no green connection time). Similarly, the 8th image starts when the 2nd is completed. Try the example online.

http://www.softwareishard.com/blog/firebug/firebug-http-time-monitor/

Firebug 1.5: XHR Breakpoints

Create XHR Breakpoint

In order to create a XHR breakpoint, the Net panel offers the same breakpoint bar that is already well known from the Script panel.

Breakpoint bar within the Net panel.

So, creating a new breakpoint for XHR request is as easy as clicking on the appropriate row with the request the user wants to debug.

As soon as the breakpoint is there and a request to the same URL is executed by the current page again, Firebug halt's Javascript execution at the source line where the request has been initiated.

Javascript execution halted on XHR Breakpoint

You can see two things on this screenshot. First, there is no breakpoint in the source code so, you don't have to know the source code line in advance to start debugging and second, the breakpoint is listed in the Breakpoints side panel in a new section called XHR Breakpoints.

Set Breakpoint Condition

If you want to halt the Javascript execution only in specific cases you can specify a condition. Again, this is done in the same way as specifying condition for regular Javascript breakpoint - just right click on the breakpoint circle .

Condition editor for XHR breakpoints

The condition editor allows to specify a Javascript expression that if evaluated to true activates the breakpoint. The condition is evaluated in a scope with some built-in variables that can be used in your expression.

Couple of examples:

Halt JS execution only if URL parameter count is present and equal to 1.
URL: http://www.example.com?count=1
Expression: count == 1

Halt JS execution only if posted data contains string key.
URL: http://www.example.com?count=1
Expression: $postBody.indexOf("key") >= 0

See online demo here.

http://www.softwareishard.com/blog/firebug/firebug-15-xhr-breakpoints/

Firebug 1.5: Break On Next

The entire feature is represented by a new Break On button that is available in Firebug's main toolbar.

Break On Next button in Firebug's UI

The logic of the button depends on the panel that is currently selected in Firebug. For instance, if the Script panel is selected and the feature activated (by clicking on the button that starts throbbing Break On Next Activated), the debugger halts as soon as the next line of Javascript is executed. So, this is the moment when you have to e.g. press a button in your web app and see what code is actually called.

Here is how the button works in other Firebug panels (the button is disabled for panels, which doesn't support this feature):

  • Script: Break on the next executed script.
  • HTML: Break on HTML mutation (element addition or removal and attribute change).
  • Net: Break on XMLHttpRequest execution.
  • Console: Break on Javascript error.
http://www.softwareishard.com/blog/firebug/firebug-15-break-on-next/

Wednesday, November 11, 2009

Closure Compiler

The Closure Compiler is a tool for making JavaScript download and run faster. It is a true compiler for JavaScript. Instead of compiling from a source language to machine code, it compiles from JavaScript to better JavaScript. It parses your JavaScript, analyzes it, removes dead code and rewrites and minimizes what's left. It also checks syntax, variable references, and types, and warns about common JavaScript pitfalls.

http://code.google.com/closure/compiler/
http://code.google.com/closure/compiler/docs/error-ref.html

Monday, November 9, 2009

Tooltip.js

jQuery:
tip.init(object) #tooltip will be taken from object "helper" attribute
img src="..." helper="..."
tip.init('img[helper]')
var tip = {
init : function(e){
$(e).bind("mouseenter", this.createTip);
$(e).mouseleave(function(){$("#tip").remove()});
$(e).click(function(){$("#tip").remove()});
$(e).mousemove(function(e){$("#tip").css({left:e.pageX+30,
top:e.pageY-16})});
},
createTip : function(e) {
var obj=$(e.currentTarget),
title=$.trim(obj.attr("helper"));
if(title.length>0){
return $("#tip").length === 0 ?
$("<div>").html("<span>"+$.trim(obj.attr("helper"))+"</span>").
attr("id","tip").
css({left:e.pageX+30,
top:e.pageY-16,
position:'absolute',
border:'1px solid #FFE222',
background:'#FFFBC2',
color:'#514721',
padding:'5px 10px',
textTransform:'lowercase',
fontVariant:'small-caps',
zIndex:9000}).
appendTo("body") : null;
} else {return false}
}
};
Prototype:
tip.createTip(container,object) #tooltip will be taken from object "title" attribute
<div id="container">
<img src="..." title="..." />
</div>
tip.createTip($('container'),'img[title]')
var tip = {
title : '',
opacity: .8,
marginX: 30,
marginY: -46,
position : function(i,e){
return i.setStyle({left:e.clientX+this.marginX+'px',
top:e.clientY+this.marginY+'px'})
},
enter : function(i){
var tip=this;
$(i).observe(antHill.events.menter,function(e){
var div,obj=$(e.currentTarget);
tip.title=obj.readAttribute("title");
obj.writeAttribute("title",'');
if($("tip")===null){
div=new Element('div',{id:'tip'});
div.addClassName('tooltip').
setOpacity(tip.opacity).
innerHTML="<span>"+tip.title+"</span>";
tip.position(div,e);
$($$('body')[0]).insert({bottom:div});
}
Event.stop(e)}.bindAsEventListener($(i)));
},
leave : function(i){
$(i).observe(antHill.events.mleave,function(e){
$("tip").remove();
$(i).writeAttribute("title",tip.title);
Event.stop(e)}.bindAsEventListener($(i)));
},
move : function(i){
$(i).observe(antHill.events.mmove,function(e){
antHill.tip.position($("tip"),e);
Event.stop(e)}.bindAsEventListener($(i)));
},
init : function(i){
this.enter(i);
this.leave(i);
this.move(i);
},
createTip : function(c,i){c.select(i).
each(function(i){tip.init(i)})}
};

Thursday, November 5, 2009

AutoMySQLBackup

A script to take daily, weekly and monthly backups of your MySQL databases using mysqldump. Features - Backup mutiple databases - Single backup file or to a seperate file for each DB - Compress backup files - Backup remote servers - E-mail logs ...

http://sourceforge.net/projects/automysqlbackup/

7 Free Tools to Minify your Scripts and CSS

  1. JSMin (JavaScript Minifier) - removes comments and unnecessary whitespace from JavaScript files
  2. JSO (JavaScript Optimizer) - allows you to manage your JavaScript and CSS resources and to reduce the amount of data transfered between the server and the client.
  3. Packer – An online JavaScript Compressor
  4. JSCompress.com – Online tool that uses either JSMin or Packer to compress your files
  5. CSS Compressor – Online tool that compresses your CSS file
  6. DigitalOverload JavaScript Minifier – Online tool that minifies your JavaScript files
  7. YUI Compressor – A JavaScript minifier designed to be 100% safe and yields a higher compression ratio than most other tools.
http://www.devcurry.com/2009/11/7-free-tools-to-minify-your-scripts-and.html

Sunday, November 1, 2009

Caja

Caja allows websites to safely embed DHTML web applications from third parties, and enables rich interaction between the embedding page and the embedded applications. It uses an object-capability security model to allow for a wide range of flexible security policies, so that the containing page can effectively control the embedded applications' use of user data and to allow gadgets to prevent interference between gadgets' UI elements.

Today, some websites embed third-party code using iframes. This approach does not prevent a wide variety of attacks: redirection to phishing pages which could pretend to be a login page for the embedding application; stopping the browser from working until the user downloads malware; stealing history information about which sites a user has visited so that more target phishing attacks can be done; and port scanning the user's local network. Finally, even though a website can choose not to give data to an iframe app, once it has done so it can place no further restrictions on what the iframe app can do with it — it cannot stop the iframe app from sending that data elsewhere.

Caja addresses these problems which are not addressed by iframe jails; and it does so in a very flexible way. If a container wishes to allow an embedded application to use a particular web service, but not to send arbitrary network requests, then it can give the application an object that interacts with that web service, but deny access to XMLHttpRequest. Under Caja, passing objects grants authority, and denying access to objects denies authority, as is typical in an object-capability environment. Information leakage can be prevented by allowing user data to be encapsulated in objects that can be rendered in user-readable form but not read by scripts ; we can prevent leakage without solving the problem of covert channels.

http://code.google.com/p/google-caja/