Monthly Archives: January 2009

Windows 7 first impressions

The first surprising thing about the Windows 7 beta is that it works great running in VMware, so if you have a relativly new vesion of VMware installed then it is well worth installing the beta to have a look.

The UI is distinctly vista like with the the round start buton and start menu, and similar dialogs, but for some reason it doesnt give off that hateful vibe that Vista does (having installed vista and immediatly removed it reverting back to trusty XP, Im no fan).

The beta comes with some nifty little apps like sticky notes and a great snipping tool for taking screen shots along with the usual games, calculator and of course paint (which is a nicely updated version in the vein of office 2007). It also comes with an IE 8 beta which may be of interest to some.

Overall i like the feel of Windows 7 and after seeing this beta I have high hopes of eventually upgrading my Windows XP machine to it.

So Microsoft, please dont f*$k it up before release.

Crop and resize an image using MiniMagick

During my dealings with twitter avatars (see here) I discovered how to resize and crop an image using MiniMagick. This is useful when dealing with twitter avatars as the large size ones that the twitter api provides are not always square and the smaller ones may be too small for some applications. Below is the simple function :

def resize_and_crop(image, size)         
  if image.width  image.height 
    remove = ((image.width - image.height)/2).round
    image.shave("#{remove}x0")
  end
  image.resize("#{size}x#{size}")
  return image
end

Pulling avatars from twitter in a Rails App

Something which may be of use to all bloggers and social app builders is that it is pretty easy to pull someones twitter profile photo in RoR heres the code :

# call the twitter api
url = 'http://twitter.com/users/show/show.xml?email='+CGI.escape(test@test.test)

# get the XML data as a string
xml_data = Net::HTTP.get_response(URI.parse(url)).body

# extract profile image tag information
doc = REXML::Document.new(xml_data)
profile_image = nil
doc.elements.each('user/profile_image_url') do |ele|
        profile_image = ele.text
end
	
# if we have an image and its not a default avatar then continue
if profile_image and ! profile_image.include? "static.twitter.com"
	begin
		profile_image=profile_image.gsub("_normal","_bigger")
		filename="/tmp/"+rand(100000).to_s+File.extname(profile_image).downcase
		file=open(filename,"w")
		file.write(open(profile_image).read)
		file.close
		# do as you will with the avatar
	rescue
		#fail
	end
else
	#fail
end