Keep Calm v1.1 now on iOS

After about a month in the review process (Apple rejected it a few times) Keep Calm 1.1 is now available for iOS, adding support for iOS 6 (including the new iPhone) along with the option to upgrade to Pro to access loads of new features.

The Pro feature – available through an in-app purchase of 69p/99c – allows you to do the following:

  • Modify text color
  • Modify font
  • Add a shadow to the text and icon
  • Change the icon to a custom image from your photos (and control the brightness/contrast)
  • Change the background to an image from your photos
  • Choose between a flat color, radial gradient or linear gradient for the background
  • Save at standard resolution, wallpaper resolution (device specific) or square for using on services like Instagram

Regardless of whether you purchase the extra features the app will still save all your posters (and this version adds the option to delete them too!) so that you can go back and share/edit them at a later date.

Keep Calm v1.1 on the App Store

Issues with Keep Calm 1.0 on iOS 6

I am aware of reports that Keep Calm Creator 1.0 is crashing on some devices running iOS 6. Currently it seems to be primarily fourth-generation iOS devices (iPod Touch 4G, iPhone 4 and iPad 2) that are affected however I’ve had reports from other users.

The issue seems to be related to a change in how Apple lets developers hide the status bar at the top of the screen from iOS 5 to 6 which has led to it crashing on iOS 6.

I have now submitted an update to Apple that fixes these issues and adds loads of new features. It currently looks like the update should be available early next week (1-2 business days) so issues should be resolved by 9/26/12.

Apologies if you’ve been affected by this bug!

If you’re interested, I’ve also now made my App Store statistics for Keep Calm publicly accessible.

Generating large Fibonacci numbers with C++

EDIT: This is a really, really stupid way of handling large numbers in C++. It is a nice proof of concept in terms of how you can do the ‘unit addition’ that you might have learnt in school pragmatically, but if you really want to be handling large numbers you need to be using something like GMP.

This morning I set myself the challenge of writing a Python program to generate large Fibonacci numbers, however I later rewrote it in C++ and it worked a lot better, so I’ve stuck with the C++ version. In fact, execution times were up to 60 times faster in C++.

The main problem I had is the limitations of standard integer types in C++. A 32bit, unsigned long will limit you to just over 4 billion. A 64bit, unsigned long will limit you to roughly 1.844 x 10^19, which gives you about 20 digits. The problem is that the 48th and 93rd numbers in the Fibonacci sequence will exceed these limits respectively. Therefore I created an alternative solution.

I basically ended up storing numbers in strings and then splitting them into a single character array before adding them, effectively doing column addition digitally. Whilst this is ridiculously inefficient for the smaller Fibonacci numbers (i.e. less than 2^64), it will happily allow you to calculate numbers significantly higher than the limits of your CPU.

Annoyingly the executable is quite large (on Windows) and I have to include the vector library so I can have variable length arrays but other than that minor issue the program will run ridiculously quickly – I can calculate the first 50,000 in a matter of seconds although anything exceeding this takes significantly longer.

If you’re using GCC then you could probably adapt this and reduce executable size by replacing the vector stuff with VLAs but I was using the VC++ compiler so I couldn’t and I wanted this to work cross platform.┬áHere is the full source code (I’m going for Apache license even though there isn’t much of it):

 Copyright 2012 Programming Thomas
Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 See the License for the specific language governing permissions and
 limitations under the License.

 To compile with VC++ use the VS command line and cl /Ox fibonacci.cpp
 To compile with G++ use g++ -o fibonacci fibonacci.cpp
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
std::string intToString(int s)
 std::string toReturn = "";
 while (s > 0)
 char v = s % 10 + 48;
 toReturn = v + toReturn;
 s = (s - (s % 10)) / 10;
 return toReturn;
int stringToInt(std::string s)
 int v = 0;
 for (int n = 0; n < s.length(); n++)
 if (s[n] >= 48 && s[n] < 58) v = (v * 10) + s[n] - 48;
 else break;
 return v;
std::string add(std::string a, std::string b)
 std::vector<char> aList;
 int n;
 for (n = 0; n < b.length(); n++) aList.push_back(b[n] - 48);
 int offset = b.length() - a.length();
 for (n = 0; n < a.length(); n++) aList[n + offset] += a[n] - 48;
 for (n = aList.size() - 1; n > 0; n--)
 aList[n - 1] += (aList[n] - aList[n] % 10) / 10;
 aList[n] = aList[n] % 10;
 std::string toReturn = intToString(aList[n]);
 for (n = 1; n < aList.size(); n++) toReturn += 48 + aList[n];
 return toReturn;
int main(int argc, char* argv[])
 if (argc > 1)
 int SIZE = stringToInt(argv[1]);
 std::cout << "Going to calculate the first " << SIZE << " terms." << std::endl;

 std::string a = "1", b = "1", c;
 std::ofstream file;"fib" + intToString(SIZE) + ".txt").c_str());
 file << "1";
 for (int i = 2; i <= SIZE; i++)
 file << std::endl << b;
 c = add(a,b);
 a = b;
 b = c;

 std::cout << "Calculated values and written to file";

 return 0;
 std::cout << "You should supply a number of items (fibonacci 100 for example)" << std::endl;
 return 1;

Please click here for the raw source file and here for the EXE. To use the program, open up a command line and execute fibonacci followed by the total number of numbers you wish to generate. It will then output this to an appropriately named text file.

Note that because a rather large amount of text gets written to a file whilst the program is running (it isn’t possible to cache it before writing because generating anything above 100,000 items is going to use a lot of RAM) it is probably worthwhile running this on a reasonably fast hard disk or SSD rather than a USB drive.

Analyzing Reddit’s comments

Last weekend I wrote a C# program that will analyze text reasonably efficiently and output the word frequencies to a CSV file (admittedly tab separated at the moment). I then released all of the source on GitHub but I hadn’t really done any proper analysis with it other than the books I was using from Project Gutenberg.

I was having a look at Reddit’s API today and I stumbled across the option to stick .json on the end of most Reddit URLs to get the API data. I then wrote a relatively simple Python script that would poll this page once a minute (the page in theory gets updated every thirty seconds but I found it seemed to be updated once a minute). I then had a dictionary with a key for each comment’s ID and I kept a copy of the comment’s content in the dictionary. I also stripped out all HTML to ensure text analysis would work properly. Each minute it would also save the dictionary to a JSON file and the text to a text file.

I than ran Word Frequency over it to build up this CSV file – to view the full thing make sure you press download (I then recommend importing it into Excel so you can sort it). I collected a total of 10,091 comments which amounted to a total of 289,713 words (an average of 28.71 words per comment) and found that the most common word was, unsurprisingly, the. Pronouns, connectives and simple verbs (is, see, etc) make up the top 100 however nouns tend to creep in further down. Incredibly, 9gag is only used seven times across all of the comments.