Category: snippets

simple MagicCloud example

Simple demo of the MagicCloud gem, as the docs are not explicit about how to output an image:

require "magic_cloud"

words = [
 ['test', 50],
 ['me', 40],
 ['tenderly', 30]

cloud =, rotate: :free, scale: :log)
img = cloud.draw(800, 600)

what time is it in that city?

My iOS app needs to know what hour of the day it is in a particular city.

NSDate *date = [NSDate date];
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSCalendarUnit unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
[calendar setTimeZone:[NSTimeZone timeZoneWithName:@"Australia/Canberra"]];

NSDateComponents *dateComponents = [calendar components:unitFlags fromDate:date];
NSInteger hour = [dateComponents hour];

if (hour > 2 && hour < 12) { // app is only available between midday and 2am

// tell the user to come back later


To see a list of available timezone names, launch Terminal on OSX and type:

ls /usr/share/zoneinfo/