Prototype Trim()
Monday, 03 March 2008
Here's a nice little addon to the Prototype Ajax library that adds the ability to trim text, etc. with Prototype.
First add this to one of your .js include files,
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
return this.replace(/\s+$/,"");
}
now with protoype loaded you can trim your text simply and effectivly,
$('myfield').value.trim() == '';
this will simply get the value from the textbox 'myfield', trim it for whitespace and then compare it to see if it's empty.
Sweet!
Thanks goes to SOMACON.COM for this one.
Firefox Addons (3rd edition)
Thursday, 03 January 2008
More really decent Firefox Addons...
ColorZilla
...provides an eyedropper, like photoshopThrashMail.net
...dummy email address generatorFFmyIp
...displays your machine's ip addressLoremIpsum Content Generator
...generates lorem ipsum text for your web designsFireFtp
...ftp file manager addon for firefoxFireBug
...the best web debugger in historyWeb Developer Toolbar
...very competent web design addonDelicious Toolbar
...add your del.ici.ous links to firefoxYSlow
...addon to FireBug, ranks your sites performance and offers solutuions to speed it upFireCookie
...addon to FireBug, gives you total control of cookiesTails
...Microformats statusbar extension, lights up when it sees microformat code in a webpagePicLens
...instantly transforms your browser into a full-screen 3D experience for viewing images across the web
All tested to work with the latest Firefox 2.0.0.11 build.
Unit Testing
Recommended Gems + Deployment
Tuesday, 29 May 2007
After a while of development with Ruby on Rails, you build up a few notes on what you should always have, or recommended setups. So to complement all my other notes, here's a little collection of Ruby Gems that I'd recommend you add to your collection, and some command lines to help you.
Startup + Deployment
Basics
ruby -v
// returns ruby version
rails [app]
// creates new app in current directory
script/generate
// generates templates, models, views, etc.
rake db:migrate
// runs pending database migration plans
script/server
// starts mongrel or webrick web server
script/server -p 3030 -e production
// starts mongrel in production mode at port 3030
script/server -d
// starts mongrel in development mode silently
// terminte it with these two:
ps aux | grep mongrel
// shows active processes named 'mongrel'
kill 31290
// terminate process 31290
Adding + Removing Gems
sudo gem install [gem]
// installs gem [gem]
sudo gem uninstall [gem]
// uninstalls gem [gem]
Required Gems
sudo gem install rails --include-dependencies
// the web framework ruby sits on
sudo gem install mongrel --include-dependencies
// mongrel is RoR's webserver
sudo gem install mongrel_cluster
// cluster-based mongrels
gem install capistrano -v 1.4.1
// makes it easy to deploy your RoR app
sudo gem install deprec -v 1.2.3 -y
// adds deprec deployment recipies
Capifying your App
To make your app ready for deployment to your remote server, do:
cap --apply-to .
// creates the capify .caprc file
deprec --apply-to . --name myapp --domain myapp.com
// generate your apps deploy.rb file
cap show_tasks
// show available capistrano tasks
Getting Cutting-Edge Builds
Freezing your Rails to the Edge
When building your app, you may want to make sure it will only ever use the Ruby version you've got now; rather than the one you might have in the future (if you upgrade ruby later). You know, if certain commands get depreciated later on, or if the command you use now doesn't work in the next version of ruby, but you need to upgrade your server's Ruby build for the other apps.
...to freeze rails, navigate to your apps dir, then run;
rake rails:freeze:edge
rake rails:update
...un-freeze it with;
rake rails:unfreeze
...to check what versions your running, try;
script/about
Gem Maintenance
Updating Ruby on Rails
gem update
// updates all installed gems
gem update --system
// updates 'gem' -> latest version
gem cleanup
// deletes any previous unneeded gem files
rake rails::update
// updates your app to latest rails release
Extra Gems
sudo gem install termios --include-dependencies
// wrapper for the UNIX termios command
// prevents passwords you enter in
// Capistrano from being displayed in
// your Terminal for all to see
sudo gem install tzinfo --remote
// timezone library, provides
// daylight-saving awareness and
// different time zones
sudo gem install redcloth
// adds support for Textile formatting
sudo gem install feed-normalizer
// ruby RSS/ATOM feed reader + dependencies
sudo gem install mysql
// builds in better mysql performance









