Katipo Project Survival Kit

Katipo Developers Blog

Archive for the 'random' Category

Quick Ruby script to write file types report

Wednesday, April 27th, 2011

Today I had to evaluate whether it was worth it to use Kete’s bulk import facility to migrate an existing site’s content to Kete or whether to just have someone drag the content over page by page.

To figure this out, I wanted to know roughly how many pages along with other files were on the site. I knew that it wasn’t going to absolutely massive, so I started by grabbing all of the site’s public content with wget (the details coming from http://linuxreviews.org/quicktips/wget/):

wget -p -r --wait=20 --limit-rate=20K -U Mozilla http://the_site/

I let that run in the background while I did other work.

When it finished I wrote up a little (ugly, unDRY, but took < 5 minutes) Ruby to give me a report by file type and called it file_report.rb based on a skeleton grabbed from http://blogs.sourceallies.com/2009/12/word-counts-example-in-ruby-and-scala/:

require 'yaml' # Change rootDir to the location of downloaded site rootDir = "/path/to/roodDir/for/entire/downloaded/site" raise rootDir + " does not exist" unless File.directory? rootDir # recursively add files and directories to report_hash based on their type def files(rootDir, report_hash) report_hash['directories'] = report_hash['directories'] || Array.new Dir.foreach(rootDir) do |dir| if dir != "." && dir != ".." dir_path = rootDir + "/" + dir if File.directory?(dir_path) puts "Processing " + dir report_hash['directories'] = report_hash['directories'] << dir_path Dir.foreach(dir_path) do |file| if file != "." && file != ".." file_path = rootDir + "/" + dir + "/" + file if File.directory?(file_path) report_hash['directories'] = report_hash['directories'] << file_path files(file_path, report_hash) else # add path to report_hash's entry for the file extension extension = File.extname(file).sub('.', '') report_hash[extension] = report_hash[extension] || Array.new report_hash[extension] = report_hash[extension] << file_path end end end else # add path to report_hash's entry for the file extension extension = File.extname(dir).sub('.', '') report_hash[extension] = report_hash[extension] || Array.new report_hash[extension] = report_hash[extension] << dir_path end end end end t1 = Time.now report_hash = Hash.new files(rootDir, report_hash) puts "File type counts: " report_hash.each do |k, v| puts "#{k} : #{v.size}" end puts "Writing complete report" File.open('report.yml', "w") do |f| f.write(report_hash.to_yaml) end t2 = Time.now puts "Finished in " + (t2 - t1).to_s + " seconds"

Finally, I called it with:

ruby file_report.rb

Nothing flash, but handy to have when you need it. I saved myself a lot of clicking around on their website.

Sharl is your friend

Monday, October 11th, 2010

Sometimes your linux server partitions fill up faster than you expect and suddenly you are getting warning emails screaming at you.

This is when Sharl comes in handy.

ls -Sharl

It is a quick way to list the contents of a dir by size of file with the biggest ones being the last on the list just right there above the command prompt allowing you to easy banish those not needed tar, sql, zip files that are not needed with flourish to free up as much space as one can with the least number of keystrokes

Kakama Technical Overview

Friday, June 4th, 2010

I’ve just posted a technical overview of how Kakama functions. You can view it at Kakama.org

Using git feature branches to make your master branch commits list concise

Thursday, March 18th, 2010

When you’re starting off, it’s fairly easy to commit to the master branch. But once your application is released, you probably want to keep things stable on the master branch. So use feature branches.

(more…)

IE7 and IE8 cannot support URI’s with underscores

Monday, September 28th, 2009

Stumbled upon this. If you’re going to make a URI (domain or sub domain) with an underscore, think twice. IE7 and IE8 do not support these URI’s when dealing with cookies.

For more details, see this blog post, detailing the symptoms.

http://blog.patrick-morgan.net/2008/09/problems-with-ie7-sessions-not-saved-in.html

Have fun testing your application with Cucumber

Friday, September 4th, 2009

When I started on a new Ruby on Rails project at Katipo Communications, I evaluated a range of testing libraries, and decided on Cucumber. It’s simple and has a flexible style of feature testing. For more info about it, see the Cucumber Wiki Documentation. In this post, I’ll detail some of my experiences with it for other developers who are considering using it.

(more…)

Getting the Most out of Your Website

Friday, August 21st, 2009

These are some preparation notes for a panel discussion with the NZ Industry Training Federation – ITOs Marketing and Communications Network. We were asked to respond to three questions:

  1. My website is a dog’s breakfast, my boss wants it fixed, what do I need to do/think about mys elf before I contact a company?
  2. What are the most common mistakes you see being made on organisation’s website?
  3. How do you measure value for money on your website?

(more…)

Make Rails logger available in code normally outside of logger scope

Saturday, January 24th, 2009

Here’s a quick one. Say you are debugging a bit of code in a plugin that doesn’t fall under the Rails app you are working on’s ActiveSupport context and thus “logger.debug” is not available to you.

You could write up your own logging mechanism, with or without using the Logger gem. However, if what you are working on is run by the Rails app and thus has the apps global constants available, you could simply tie it into the existing logger object in the Rails app like so in your file:

logger = RAILS_DEFAULT_LOGGER

Then you can use logger.debug, logger.info, etc. to your heart’s content. One caveat, if you are working on a gem or a something more general that won’t necessarily always be run in the context of Rails, then you will want to pull your use of logger out before distributing your code. Otherwise you add a dependency on Rails that you may not intend.

Adding Gist commands to emacs

Thursday, January 15th, 2009

You have to give Logical Awesome credit for how much work they do to integrate GitHub’s services with tools that developers use.

The Gist service is a good example. First they added command line support for it, then they simultaneously added in-editor support in Textmate, vim, and my own personal favorite emacs. The blog post announcing gist support in emacs and vim is here.

So how do you add the gist support to emacs?

First, you’ll need an account on github.com and have set up your ~/.gitconfig as outlined in here.

Then download or clone the gist.el file from http://github.com/defunkt/gist.el, copy only the gist.el file from that repository to someplace in your emacs load path (in my case /Users/walter/Library/Preferences/Aquamacs Emacs/ because I use Aquamacs on a Mac), and add a line to your ~/.emacs file or in my case /Users/walter/Library/Preferences/Aquamacs Emacs/Preferences.el that looks like this:

(require ‘gist)

Then you have to either restart your emacs program or do M-x load-library and answer prompt with gist for the new gist commands to be available.

Now you have M-x commands like these:

gist-view-gist
view gists after they’re posted
gist-region
Post the current region as a new paste at gist.github.com
Copies the URL into the kill ring.
gist-region-private
Post the current region as a new private paste at gist.github.com
Copies the URL into the kill ring.
gist-buffer
Post the current buffer as a new paste at gist.github.com.
Copies the URL into the kill ring.
gist-buffer-private
Post the current buffer as a new private paste at gist.github.com.
Copies the URL into the kill ring.
gist-region-or-buffer
Post either the current region, or if mark is not set, the current buffer as a new paste at gist.github.com
Copies the URL into the kill ring.
gist-region-or-buffer-private
you can probably guess…
gist-fetch
Given an gist id, fetches a Gist and inserts it into a new buffer
If the Gist already exists in a buffer, switches to it.

Very useful stuff for collaboration, but without leaving your editor.

Enjoy,
Walter

Testing Colour Contrast in Web pages

Friday, October 3rd, 2008

One commonly overlooked aspect of website accessibility is the contrast ratio between foreground and background colours.

White poor contrast can cause readability issues for well-sighted visitors, it can be even more of a problem for those visitors with a visual impairment.

Because of this, The New Zealand Government Web Standards and Requirements v 1.0 and W3C’s Techniques for Web Content Accessibility Guidelines v 1.0 both contain standards requiring content have sufficient contrast between foreground and background colours.

For example, The New Zealand Government Standards state:

“Ensure that foreground and background colour combinations provide sufficient contrast for navigation, text and informational elements when viewed by someone having colour deficits or when viewed on a black and white screen.”

Continue below for details on how to test for adequate colour contrast in your design or web pages.

(more…)


Katipo Developers Blog is proudly powered by WordPress
Entries (RSS) and Comments (RSS).