Sass Language Highlighting in Textmate January 15th, 2008
If Haml and Sass are decluttering your life you may wanna check this… and create a new language in textmate bundles>bundle editor>edit languages
What would subversion do? June 26th, 2007
Ever wondered what subversion is going to do on an update so you can catch those merges before they happen? Well this is what you are missing…
svn st -u
This will display the update information without actually doing the actual update. Sweet.
Using SciTE As SVN_EDITOR June 25th, 2007
Command line svn is ace, it gives you loads more control and you can quickly get at the information you need (yeah yeah adding files is a pain in the bum but its a bit better with this command aliased).
Recently I have been working on a .net project and have been stuck using notepad as my SVN_EDITOR, mainly because I couldn’t get it to work with SciTE straight away. But notepad sucks, so I spent a quick 5 mins RTFMing this eveing and found the answer. Just type the following into a command window and all will be well…
SVN_EDITOR="C:\Program Files\Scintilla Text Editor\SciTE.exe" -open
Mother Vulpine Single Launch June 16th, 2007
If you have a spare £1.58 I suggest that you head over to iTunes and buy Mother Vulpine’s debut single ‘Keep you wits sharp (Her Words Are Quick)’. I was really impressed with their set when I saw them support the Eagles of Death Metal at the London Astoria the other month. They had loads of manic energy, loud guitars, catchy songs and \m/(>_<)\m/.
Since then I have been impatiently waiting for them to release something and their single didn’t disappoint. Both songs capture the raw energy that made them great live, and it has been on constant repeat on my iPod since Friday. They deserve to be big and I can’t wait for another release or an album. I just really hope they don’t end up being over produced like every other English rock band I have liked.
SVN Windows Network Speed June 5th, 2007
We’ve been having some problems with the speed of checkout and updates using SVN on a Windows server, it seemed to only be a problem with large binary files. After lots of seaching groups and finding nothing (and there plently of posts) we found that the issue was the settings on the network card on the server.
Thanks to Pete Marley for the solution to this
The script tag June 2nd, 2007
I have been spending some time recently increasing my knowledge of javascript, one of the more an interesting topics that kept coming up is the use of, and the issues around, the <script> tag. This post is the product of the notes that I have taken from various resources on the web.
Best Practice
As I hate technical articles that don’t give you the code or the solution until the very last page, I will start with the “best practice” for including javascript in your HTML document.
There are three basic steps you should take when you want to include javascript in your page:
- move your javascript into a separate file
- reference it with the src attribute
- place the script tag that references it as close to the closing body tag as possible.
If you follow these steps your page should look something like this.
<html>
<head>
...
</head>
<body>
...
<script xsrc="linkTo.js" mce_src="linkTo.js"></script>
</body>
</html>
The reasons why its suggested you deal with the script tag this way is to get round various issues with how browsers handle javascript and also just good coding practice.
Separate javascript from content
Separating the javascript from the HTML into its own file has a number of obvious benefits including the ability to:
- test it in isolation
- maintain the source easier
- minify it for production
- gzip it from the server
- cache it
But the placement of this script tag is important when considering the performance of your page.
Load scripts as late as possible
The major problem with the script tag is that when the browser identifies the it, it then loads, compiles and executes the javascript and while doing so, blocks the rest of the HTML components being processed slowing the perceived loading time of the page. The defer attribute was introduced to resolve this, however this isn’t supported by the majority of browsers and its best not to use it.
The hack to get round this waiting until the last moment to load the scripts by placing them as close to the closing body tag as possible. This way the rest of the content of the page will have been loaded and the user can view the page content as the scripts are being processed.
Ignore other attributes
None of the other attributes on the script tag have been included as they are not really needed, type is required in XHTML but it could be argued its best to leave it out. It was introduced to replace the now deprecated language attribute to allows the specification a mime type for a script. The problem with this is that the mime type for javascript was only recently issued (it is either “application/javascript” or “application/ecmascript”) and most major browsers don’t support it. They do however support the non-standard “text/javascript” but using that just seems wrong. Also if you use the src attribute, as suggested, then the browser ignores the type and relies on the server providing the correct mime type for the linked javascript file.
Other issues
Don’t Use the HTML comment hack
Nesting HTML comments just isn’t needed anymore. The script tag was introduced in Netscape Navigator 2 as a way of introducing programs into html documents. As it is just a html tag browsers that didn’t recognise it just wrote the contents out to the page. The html comment hack was introduced to solve this problem for Nestcape 1 and Mosaic. However every other browser since then has supported it, so for about the last 10 years it hasn’t been necessary to include it in your script tag.
Be aware of the script tag hack
The src attribute on the script tag in not constrained by the Same Origin policy, this means that it can run with the same authority as other scripts on the page. This can be used to steal cookies and misuse the authorization with a server.
References
- http://www.quirksmode.org/js/placejs.html
- http://javascript.crockford.com/script.html
- http://www.w3schools.com/tags/tag_script.asp
- http://www.w3.org/TR/html4/interact/scripts.html
Viewing Javascript errors in Safari May 20th, 2007
I am currently writing some javascript that will do some fancy syntax highlighting for the code snippets on my blog. Almost straight away I started getting some javascript errors, which is to be expected, and I went to fired up Firefox and used firebug to have a poke around. This time however there seemed to a problem specific to Firefox (which it turned out to be my bad coding, but thats not the point) so I wanted to check it in Safari (webkit).
So I fired it up but when I loaded the page I couldnt find a javascript console in any menu to check for the same errors. So I attatched Drosera and I still couldn’t find an option O_o.
After a quick google and I found this link which gave me the solution. Typing the command below into terminal enables a debug menu which, amongst other things, gives you access to a javascript console.
defaults write com.apple.Safari IncludeDebugMenu 1
Specifying a version for the rails command April 15th, 2007
The current project I am working on required me to generate a rails project using for a much older version of rails than the default I currently had installed. rails —help didn’t suggest there was a way to do this. However looking at the command itself:
#!/usr/local/bin/ruby
#
# This file was generated by RubyGems.
#
# The application ‘rails’ is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'rubygems'
version = "> 0"
if ARGV.size > 0 && ARGV[0][0]==95 && ARGV[0][-1]==95
if Gem::Version.correct?(ARGV[0][1..-2])
version = ARGV[0][1..-2]
ARGV.shift
end
end
require_gem 'rails', version
load 'rails'
you can see that it accepts a version as an argument.
So:
rails _1.0.0_ your-project-name
will generate you a project using the rails 1.0.0 gem. Sweet. Oh and obviously you should then freeze your rails project to that version or tag
.
The Aadvark Test April 13th, 2007
The aadvark test is one that will run before all other tests in your build to ensure that the database you are running against has been migrated to the latest version. This simple yet cool idea came from a client I recently worked with, the extra check to ensure you are running your tests against the latest database saved me a few times.
# The weird name is to make it run first, before other tests
class AardvarkTest < Test::Unit::TestCase
def test_should_ensure_that_databases_migrations_are_up_to_date
latest_migration = Dir.chdir(RAILS_ROOT + '/db/migrate') do
Dir['*.rb'].map{ |f| f.sub(/^0+/, '').to_i }.max
end
database_version = ActiveRecord::Base.connection.select_one('SELECT * FROM schema_info')['version'].to_i
assert_equal(latest_migration, database_version)
end
end

