Sorry the the confusion, anyone who has been checking out the the Mephisto Contact Form Plugin from the old SVN repository. The latest version with an update for Rails 2.3 is at:
Category: Technical Page 7 of 15
A while back I bought a copy of Now, Discover your Strengths by Marcus Buckingham and Donald Clifton, and have only just got around to reading it. The book comes with a single-use code that lets you take an online personality test with 180 questions, with the aim of determining your 5 core strengths. The test takes about half an hour and is not onerous.
The book outlines one main idea. Find your natural talents and capitalize on these, building them up into strengths. Shape your work and life in ways that use your natural talents, as this will make you more effective, productive and happy. Although anyone can learn anything, people with a natural talent in an area are going to be able to reach a higher level of capability and success. Mitigate your weaknesses by partnering with people who have complementary strengths, developing a support system to help you, improving your skills in the area just enough to stop them from detracting from your strengths or simply stop doing things that play to your weaknesses.
The core concept of playing to your strengths is covered from many angles in the book and with supporting stories of successful people like Bill Gates and Warren Buffett. There is then a detailed description of each of the strengths that the online personality test can highlight. The last part of the book is interesting and focuses on building organisations which play to people’s strengths, management of people with different strengths and some thoughts on the staff review process in organisations.
Overall, the book was a very quick read with low information density. The online test was fun. You can see my results below. I don’t think it told me anything too new – I already know that I’m pretty analytical, like to learn, focus strongly on achieving tasks etc. The core idea about playing to and building your strengths does seem a good one from the personal satisfaction and cost/benefit point of view (assuming society values the areas you have talents in, and your areas of weakness don’t get in the way too often).
Please note that the following text is Copyright 2000 The Gallup Organization.
Analytical
Your Analytical theme challenges other people: “Prove it. Show me why what you are claiming is true.” In the face of this kind of questioning some will find that their brilliant theories wither and die. For you, this is precisely the point. You do not necessarily want to destroy other people’s ideas, but you do insist that their theories be sound. You see yourself as objective and dispassionate. You like data because they are value free. They have no agenda. Armed with these data, you search for patterns and connections. You want to understand how certain patterns affect one another. How do they combine? What is their outcome? Does this outcome fit with the theory being offered or the situation being confronted? These are your questions. You peel the layers back until, gradually, the root cause or causes are revealed. Others see you as logical and rigorous. Over time they will come to you in order to expose someone’s “wishful thinking” or “clumsy thinking” to your refining mind. It is hoped that your analysis is never delivered too harshly. Otherwise, others may avoid you when that “wishful thinking” is their own.
Learner
You love to learn. The subject matter that interests you most will be determined by your other themes and experiences, but whatever the subject, you will always be drawn to the process of learning. The process, more than the content or the result, is especially exciting for you. You are energized by the steady and deliberate journey from ignorance to competence. The thrill of the first few facts, the early efforts to recite or practice what you have learned, the growing confidence of a skill mastered—this is the process that entices you. Your excitement leads you to engage in adult learning experiences—yoga or piano lessons or graduate classes. It enables you to thrive in dynamic work environments where you are asked to take on short project assignments and are expected to learn a lot about the new subject matter in a short period of time and then move on to the next one. This Learner theme does not necessarily mean that you seek to become the subject matter expert, or that you are striving for the respect that accompanies a professional or academic credential. The outcome of the learning is less significant than the “getting there.”
Command
Command leads you to take charge. Unlike some people, you feel no discomfort with imposing your views on others. On the contrary, once your opinion is formed, you need to share it with others. Once your goal is set, you feel restless until you have aligned others with you. You are not frightened by confrontation; rather, you know that confrontation is the first step toward resolution. Whereas others may avoid facing up to life’s unpleasantness, you feel compelled to present the facts or the truth, no matter how unpleasant it may be. You need things to be clear between people and challenge them to be clear-eyed and honest. You push them to take risks. You may even intimidate them. And while some may resent this, labeling you opinionated, they often willingly hand you the reins. People are drawn toward those who take a stance and ask them to move in a certain direction. Therefore, people will be drawn to you. You have presence. You have Command.
Focus
“Where am I headed?” you ask yourself. You ask this question every day. Guided by this theme of Focus, you need a clear destination. Lacking one, your life and your work can quickly become frustrating. And so each year, each month, and even each week you set goals. These goals then serve as your compass, helping you determine priorities and make the necessary corrections to get back on course. Your Focus is powerful because it forces you to filter; you instinctively evaluate whether or not a particular action will help you move toward your goal. Those that don’t are ignored. In the end, then, your Focus forces you to be efficient. Naturally, the flip side of this is that it causes you to become impatient with delays, obstacles, and even tangents, no matter how intriguing they appear to be. This makes you an extremely valuable team member. When others start to wander down other avenues, you bring them back to the main road. Your Focus reminds everyone that if something is not helping you move toward your destination, then it is not important. And if it is not important, then it is not worth your time. You keep everyone on point.
Input
You are inquisitive. You collect things. You might collect information—words, facts, books, and quotations—or you might collect tangible objects such as butterflies, baseball cards, porcelain dolls, or sepia photographs. Whatever you collect, you collect it because it interests you. And yours is the kind of mind that finds so many things interesting. The world is exciting precisely because of its infinite variety and complexity. If you read a great deal, it is not necessarily to refine your theories but, rather, to add more information to your archives. If you like to travel, it is because each new location offers novel artifacts and facts. These can be acquired and then stored away. Why are they worth storing? At the time of storing it is often hard to say exactly when or why you might need them, but who knows when they might become useful? With all those possible uses in mind, you really don’t feel comfortable throwing anything away. So you keep acquiring and compiling and filing stuff away. It’s interesting. It keeps your mind fresh. And perhaps one day some of it will prove valuable.
A little while back, a few colleagues and I were spiking a proxy concept based on extending an existing web server. We wanted to check out an instance variable (eg, @very_secret) in a framework object which did not have an accessor. In the past, we’d used send (eg, secretive_object.send :hello_private) to get at privates, but send is only for methods. We were just digging around doing some debugging, so we opened the relevant class and added a public accessor for the instance variable to see what was happening. However, we thought there must be a more elegant way to do access instance variables outside the class, and one has just come to mind (at last!):
secretive_object.instance_eval { @very_secret }
instance_eval lets us run the code block in the context of secretive_object. Ie, self == secretive_object, so we can get at all the hidden stuff.
It’s a rather different approach to other languages like C# and Java where accessing private variables and private methods are part of a reflection/introspection API.
Deploying Rails Applications: A Step-by-Step Guide by Ezra Zygmuntowicz, Bruce Tate and Clinton Begin is a good read, if a little dated. It was published in May 2008, and you can see that things have moved on a little in the Rails world since then. None the less, quite a lot of the information is still relevant and useful.
The book covers some basic Rails and version control concerns at the start, then rapidly launches into chapters devoted to Rails hosting options available from shared hosts to virtual and dedicated servers. The advice given is good and is in line with my experiences. Unix configuration is given in depth which would be very handy if you had not set up a server before. Next is a good discussion of Capistrano and automating deployments. The examples all use subversion. However, these days I expect the majority of Rails source code is pulled with Git. There is also a chapter on managing mongrels and setting up monitoring solutions. This is still relevant if you want to use mongrels, however these days Passenger is probably the best choice, and it does not have such complex management and configuration requirements. The scaling out chapter is useful and pulls together handy information including details on MySql replication/clustering. There’s a chapter on deploying on Windows and also some suggestions around performance and profiling.
I haven’t come across another book that brings together a structured collection of useful information to help you move from running rails locally to having a cluster of scalable production servers and the automated deployment process required to support it. Despite being too old to cover Git and Passenger, I’d still recommend having a read of this book if you’re at the stage of planning to launch a Rails site or looking to scale your VPS up to a cluster.
So yes, everyone has heard that Mac OS X and TextMate is the epitome of Rails development, and that it is so awesome that it brings tears of joy to developers eyes, &c. However, for those of us who either don’t have a Mac, or get to work on client provided hardware (often running Windows), there are a few options available.
Developing on Windows XP, with InstantRails is workable. It is easy to get everything you need and have your apps up and running quickly. However, performance is, well, quite frankly, terrible for anything you do on the command line. Mainly, this bites when running tests, doing migrations, generating files etc. Performance running Mongrel is good enough for development.
What about Cygwin? Subjectively, I found it provided similar speed to Windows Ruby/Rails.
So this brings us to virtualisation. Recently, I’ve been testing out VirtualBox running Ubuntu on top of Windows XP. This has had surprisingly good results. On the same machine, the virtual Ubuntu running Rails tasks has about 4 times (!!!) faster performance, even though it has less memory and system resources!
Here are some stats to give you and idea of the advantage.
Machine is a 2.4ghz quad core, 4gig of memory running Windows XP. Using VirtualBox 2.1.4 for virtualized Ubuntu Intrepid 64 bit, with 1.5gig of memory allocated. Figures are in seconds and approximate (taken with a wrist watch).
| generate scaffold | db:migrate with no changes | run tests for medium sized rails app | |
|---|---|---|---|
| Windows XP & Instant Rails | 7 | 7 | 25 |
| VirtualBox Ubuntu on same Windows XP | 1.5 | 1.5 | 6 |
Some of these commands / tests rely on hitting a MySQL database. However, I’m interested in overall development speed for both platforms, not in Ruby speed in particular, so I think it is fair game to include these in the results.
So if you want to do Rails Dev on Windows, I highly recommend trying a virtual machine running Linux!
In a fit of TextMate jealousy, several months ago, I scoured the web for a way to get find-file functionality info my favourite Ruby/Rails editor, vim. I was very happy to find that Jamis Buck had developed an aweseome plugin do to this. It is a little fiddly to install, but worth the trouble. Here’s some simplified steps to get you going.
- Install Jamis’s ruby gem
sudo gem install jamis-fuzzy_file_finder --source=http://gems.github.com
- Download this fuzzyfinder script and pop it in your ‘~/.vim/plugin’ directory. Note that the most recent versions of this script are incompatible with Jamis’s plugin.
- Grab the latest version of ‘fuzzyfinder_textmate.vim’ from http://github.com/jamis/fuzzyfinder_textmate/tree/master and pop it in your ‘~/.vim/plugin’ directory
Then, if you want to have a similar sort of light-weight Rails ‘IDE’ I enjoy coding with, see my config files below:
.vimrc
source $VIMRUNTIME/vimrc_example.vim behave xterm set nu set tabstop=2 set shiftwidth=2 set softtabstop=2 set ai set expandtab set smarttab let g:rubycomplete_rails = 1 map f :FuzzyFinderTextMate<CR> map n :tabnew<CR> map c :tabclose<CR> map m :tabnext<CR> let g:fuzzy_ignore = "*.svn" let g:fuzzy_ignore = "*.swp" let g:fuzzy_ignore = "*.jpg" let g:fuzzy_ignore = "*.gif" let g:fuzzy_ignore = "*~" set nobackup
.gvimrc
source ~/.vimrc set selectmode=mouse set columns=100 set lines=50
In this set up, there are no chords etc. Instead, when not in edit mode, ‘n’ will open a new tab. ‘f’ will let you find a new file to open in the current tab. ‘c’ will close the current tab and ‘m’ will move between tabs. So in a normal workflow, you might decide to swap the file in the current tab for a new one (simply press ‘f’), or if you need another file open, hit ‘n’ for new tab, and then ‘f’ to load the relevant file. My text description doesn’t do it justice, but I find this works very well to get you to the file you want quickly, and let you have the files you’re interested in open all at the same time.
One last note, remember to start vim/gVim in the root of your rails directory.
Happy Vimming 🙂
UPDATE
These files are now available from my github dotfiles repository, including the gem inside of the vim/gems_required directory.
Thanks very much to Nigel for inviting me to present on REST at St George Bank in Kogarah, and to ThoughtWorks for the time in the middle of the day to give the talk. It was a fun session and the people attending asked quite a number of good questions. Here are the slides. Please note that they are about 10mb (thanks to all the images). There’s some extra information in the “Notes” pane as well.
Packt Publishing kindly sent me a copy of RESTful PHP Web Services by Samisa Abeysinghe to review. The book’s cover claims that it will help you “Learn the basic architectural concepts and steps through examples of consuming and creating RESTful web services in PHP”. The book succeeds in providing simple steps and examples of creating and consuming web services, but falls short on REST architectural concepts and design principles.
The book starts with a very brief introduction to the principles of REST, and rapidly moves on to a discussion of PHP tools frameworks. The introduction misses some important REST / RESTful web service concepts such as hypermedia, application vs resource state and the relevance of utilising HTTP headers and status codes. Some of the information in the introduction is confusing. For example, on page 12, it says “Resources can have multiple representations that reflect different application states”. This does sound a little odd – resources can have multiple representations, for example, for different requested content types. Representations should reflect resource state, not application state. Also, the coverage of HTTP verbs is misleading, especially when POST and PUT are discussed.
The next couple of chapters discuss PHP support for HTTP, using libraries such as CURL, and XML parsing strategies. The author chooses realistic examples for code samples, such as Flickr and Yahoo Maps clients. The last example given is quite cool – using earthquake latitudes and longitudes from an Australian government site to plot points on Yahoo maps. The example code is generally simple and easy to follow. However, it would have been nice to see some sort of separation between view and data access logic.
The following chapter is a worked example of building RESTful services for a library lending books. It is a good example, and becomes the basis for most future chapters. The resource design and URLs are reasonable, although it may have been nice to have “loans” as resources in their own right. Using links between resources, rather than just relying on known URLs would also benefit the design.
Later chapters cover alternative frameworks such as Zend and WSO2 using the library lending system as an example for code samples. These chapters are useful as they give an idea how the frameworks look when put in practice. It does look as though PHP and frameworks still have significant limitations around routing flexibility from the examples (eg, the .php extension seems to mandatory in URLs). There is also a chapter on debugging with tips around tools and troubleshooting XML parsing issues.
The writing style is generally clear and easy to read. There are occasionally some odd turns of phrase, such as on page 10: “AJAX makes Web applications to become more interactive, faster, and more user-friendly”.
Overall, I would recommend this book to people wanting to write simple URI template based web services or clients in PHP, and also to people interested in getting an overview of libraries and frameworks currently available in the PHP ecosystem. To gain an understanding of the REST architectural constraints and designing good RESTful systems, I would recommend RESTful Web Services, and if you wanted to take it further, digging into Roy Fielding’s thesis and the HTTP 1.1 Spec.
“JavaScript: The Good Parts” was kindly lent to me by my friend and colleague Dave Cameron. It was a highly informative read, and a good length at just under 150 pages. The aim of the book is to define an elegant, recommended subset of JavaScript that allows you to do everything you need, and work around problems in the language. The book is aimed at people who already have a good grasp of programming in other languages.
I learnt quite a bit from the book. Here are a few of the most important parts that come to mind:
- JavaScript has function scope, not block scope so it is best to declare variables at the top of functions.
- It is important to put { on the same line as the block opening keyword (eg, function, if etc) rather than on the next line. Otherwise, you may run into problems with some JavaScript implementations auto-adding ; in the wrong place.
- Using the === and !== operators are safer and better than the == and != operators as they do no coerce types.
- The ‘new’ operator is a bad way to make new objects in JavaScript and should be avoided. Functions starting with a capital letter should always be called with the new operator by convention. Failing to do this will add all the functionality of the object you are trying to create to the global object (thanks to the this references)!
- You can always pass any number of arguments to a function. Extra arguments are not bound to function parameters, missing arguments will be undefined. Inside the function all arguments are accessible using the ‘arguments’ variable which is an array-like object.
- Lots of things are false. Eg, 0, NaN, empty string, null, and undefined.
- hasOwnProperty(name) is great in for(property in object) loops to find members of your object rather inherited members.
- Object.beget(someOtherObject) allows prototypal inheritance from someOtherObject.
- JavaScript arrays are really just objects with numerical property names and the length property, so if you use a for in loop, you’ll get indices in random order.
- It is a good idea to ‘namespace’ your code in a single global variable for your application to avoid conflicts with other libraries. Eg, myApp = {}; myApp.myVariable = 5;
- If you don’t used var, a global variable is created.
- Closures let you make information private and give you encapsulation.
- Inner functions have access to the variables defined in an outer function.
Creating objects with private data:
var incrementer = function() {
var value = 0;
return {
increment: function (inc) {
value += typeof inc === 'number' ? inc : 1;
},
getValue: function() {
return value;
}
};
};
var myIncrementer = incrementer();
Functional inheritance
var mammal = function(spec) {
var that = {};
that.getName = function() {
return spec.name;
};
return that;
};
var myMammal = mammal({name: 'Fred'});
myMammal.getName() === 'Fred'
var cat = function(spec) {
var that = mammal(spec);
var super_getName = that.superior('getName');
that.purr = function { /* new catty stuff */ };
that.getName = function {
return super_getName() + ' the Cat!';
};
return that;
};
var myCat = cat({name: 'Kitty'});
myCat.getName() === 'Kitty the Cat!'
// Helpers
Object.method('superior', function(name) {
var that = this, method = that[name];
return function() { return method.apply(that, arguments); };
});
Function.prototype.method = function(name, func) {
this.prototype[name] = func;
return this;
};
There were a few things that I thought could be improved in the book. First of all, although the structure was adequate, it did lend itself to repetition. For example, scope is covered on p36 (in Functions section) and p102 (Awful parts), with very similar words. Secondly, I did not find the frequent syntax diagrams added much to the narrative.
Despite these small blemishes, I’m glad to have read Crockford’s book. I now understand much better which parts of JavaScript to use, and how to build good object oriented code in JavaScript.
When defining an XML document, when are attributes most appropriate, and when are elements best? This is something that I’ve generally decided based more on intuition than a good set of rules.
Recently, at work, the need has arisen to define quite a few XML message payloads. I’ve also had the good fortune to work with Erik Doernenburg and we had a chat about attributes vs. elements. Largely thanks to Erik, here are some guidelines that could come in handy when making such a decision.
An attribute is best used to represent:
- an id
- metadata (eg, like rel and class in HTML)
- a value from a small, closed set of values which interpreting programs rely on (eg, values that end up as application constants)
If none of the above apply, an element would likely be the best choice.