PeerPressure Available Now on the App Store!

PeerPressure Video

Blazing Cloud and Lucky Knives are excited to announce the official release of PeerPressure, an iPhone application that creates a virtual support group to help you meet your goals.

Choose from over 250 goal templates ranging from “Be Happier” to “Write a Book” or create your very own. PeerPressure draws in your friends via Twitter, Facebook, and email for positive support. Achieve one of your milestones? PeerPressure will send out a notification of your success to your friends. Forget to update or miss one of your milestones? PeerPressure will alert your friends that a bit of encouragement is needed to get you back on track. Queue up as many goals as you like while focusing on your main objective. Every time you start a goal, a custom webpage is created to help you and your friends chart your goal’s progress.

Over the past month, we’ve been testing PeerPressure at Blazing Cloud to see how a bit of peer pressure can push us to meet our goals. Our fearless founder Sarah invited us to track her goal of creating notes for programmers starting out in Rails 3. As she met her milestones, we received updates on her progress  and cheered her on.

This week, I’ll invite my friends to track my progress as I get back into running. Follow my progress at twitter.com/billdevine and send some peer pressure.

Visit the App Store today to download PeerPressure and start achieving your goals.

For Additional information visit PeerPressure visit http://www.peer-pressure.com/

iPad custom fonts

Wish I had found this doc earlier for a project I just completed. So custom fonts can be embedded in iOS 3.2 as described in What’s New in iOS: iOS 3.2:

Custom Font Support
Applications that want to use custom fonts can now include those fonts in their application bundle and register those fonts with the system by including the UIAppFonts key in their Info.plist file. The value of this key is an array of strings identifying the font files in the application’s bundle. When the system sees the key, it loads the specified fonts and makes them available to the application.

For more information about the keys you can include in your application’s Info.plist file, see Information Property List Key Reference.

Understanding git submodule

We recently upgrade & add some little features to our extension carousel based on “Infinite Carousel” by CatchMyFame.com. We were working in our extension repository, focusing just in javascript implementation within a test app. When we integrated to our radiant project and run it locally, it worked just fine. But after deploy I got:

** Could not load extension from file: infinite_carousel_extension.
**#<NameError: uninitialized constant InfiniteCarouselExtension>

Looking into releases/12355/ vendor/extensions/infinite_carousel folder reveals no files whatsoever. Then I realized something obvious about how radiant works. It looks in their extension folders for the _extension.rb file, which in our case no longer exists. The directory was created, but none of the content was pulled in.

In my short experience, understanding Git, you have to understand its implementation something for which I am still struggling  with myself.

Submodule

Git submodule essentially allows you to attach an external repository inside another repository at a specific path.

Having submodules in a repository is fantastic. It creates some sort of independence  but if I look in my repository, all I have is an empty directory rather than the actual contents, which can be frustrating, right?

First things first: Adding Submodule to your git repository

$ git submodule add <external_repository>  <submodule_path_repository>

Since we  added a radiant extension, the git submodule add <external_path> <submodule_path> was done when we run script/extension install infinite_carousel

In order to fill in the submodule’s path with the files from the external repository, you must first initialize the submodules and then update them.

$ git submodule init

$ git submodule update

Working in a Submodule

Git submodules are locked to a specific revision and don’t automatically track the external project’s HEAD.

The checked out submodules is a full Git repository in and of itself and  it should be treated as such. So, if you want to make changes locally in your submodule, you must repeat the usual steps .

$ git add <submodule files changed>

$ git commit -m <your comments>

Git submodules are implemented using two parts: the .gitmodules file and special type of tree object. Together, they define a specific revision of a specific repository which is checked out into a specific location in your project.

[submodule "vendor/extensions/infinite_carousel"]

path = vendor/extensions/infinite_carousel
url = git://github.com/blazingcloud/radiant-carousel-extension.git

The file contains:

Path ==> location in your repository where the submodule should live.

Url ==> is the url of the repository to clone from. Our example is a github url but I assume that it should equally be a path to another repository.  Although, I haven’t tried it.

If you want your main project to use the new HEAD of the submodule, you simply need to  add and commit the submodule’s directory as you would with any other file.

Removing Submodules

So, we ended up removing the submodule from our main repository. It was not the right approach for our case.

Note:  script/extension install <extension_name> in your Radiant Project generates sub-module repository <references to original repository>. So if you want your extension to be part of you main repository, submodule is not a good option.

We couldn’t find  a git submodule <command> that removes everything in one command. We had to do a couple things to remove the submodule.

  1. Remove the submodule’s entry in the .gitmodules file. Use your favorite editor and remove the tree object [submodule] url path
  2. Remove the submodule’s entry in the .git/config, which it is only present if you’ve run “git submodule init” on the repository. If you haven’t, you can skip this step.
  3. Remove the path created for the submodule “git rm –cached <plugin path>

Rails 3: ActiveRecord

Rails 3 cheat sheet Part 2: ActiveRecord

Everything you know from Rails 2 still works and will for some time, but there is new cool stuff AND some of the Rails 2 syntax is deprecated and will eventually go away, so you should be aware.

1) Use first, last, all (not find(:first), find(:last) and find(:all)

2) New query syntax:
find(:conditions => …) will be deprecated, instead you can use the following methods:

  • where – provides conditions on the relation, what gets returned.
  • select – choose what attributes of the models you wish to have returned from the database.
  • group – groups the relation on the attribute supplied.
  • having – provides an expression limiting group relations (GROUP BY constraint).
  • includes – includes other relations pre-loaded.
  • order – orders the relation based on the expression supplied.
  • limit – limits the relation to the number of records specified.

For a complete list and more details, see Pratik Naik’s post. The key thing to note is that ActiveRecord finder methods return a relation and no SQL is executed until it needs to be.

Examples:

Person.where(:last_name => "Woo").order(:first_name)
Person.where(:last_name => "Woo").order(:first_name).limit(1)

You can optionally specify ASC or DESC when calling order

Person.order("last_name DESC").limit(2)

You can call these methods in any sequence

Person.order(:first_name).where(:last_name => "Woo")
Person.where(:last_name => "Woo").order("first_name")

Multiline document.write

I was just refactoring some HTML and needed to move some of my markup out of the HTML file and into a JavaScript method so I can re-use it in multiple HTML files. Using document.write, I didn’t want to put all of the HTML on one line, and also didn’t want to have to add the concatenation operator to each line. I did a quick search for “javascript document.write multiple lines” in google and came up with a useful little tidbit. If you don’t mind the output of the HTML all on one line you can just escape the newline characters in your method call like this:

document.write('<div id="outer">\
<div id="inner">blah blah blah</div>\
</div>');

super simple way to keep your code easy to read without too much work. All I did was use a search and replace to find all “\n” characters and replace them with “\\n”.

Thanks to Bernard Marx’s post on webmasterworld for this info!

sysctl

Occasionally my shared memory segment settings in my /etc/rc file aren’t applied correctly during startup and I get the following error when I try to start Postgres:

FATAL:  could not create shared memory segment: Cannot allocate memory
DETAIL:  Failed system call was shmget(key=5432001, size=33554432, 03600).
HINT:  This error usually means that PostgreSQL's request for a shared memory segment exceeded available memory or swap space. To reduce the request size (currently 33554432 bytes), reduce PostgreSQL's shared_buffers parameter (currently 3584) and/or its max_connections parameter (currently 103).
	The PostgreSQL documentation contains more information about shared memory configuration.

I would expect my shared memory size to be 167772160 instead of 33554432 since my /etc/rc file looks like this:

sysctl -w kern.sysv.shmmax=167772160
sysctl -w kern.sysv.shmmin=1
sysctl -w kern.sysv.shmmni=32
sysctl -w kern.sysv.shmseg=8
sysctl -w kern.sysv.shmall=65536

Restarting my machine helps, but doing that is just painful.

This may be obvious, but I learned that you can apply the sysctl command even if it doesn’t happen during startup. So all I had to do to fix my Postgres problem was:

> sudo sysctl -w kern.sysv.shmmax=16777216
kern.sysv.shmmax: 33554432 -> 167772160
> sudo sysctl -w kern.sysv.shmseg=8
kern.sysv.shmseg: 64 -> 8
> sudo sysctl -w kern.sysv.shmall=65536
kern.sysv.shmall: 8192 -> 65536

To see a list of all the kernel variables, type sysctl -A. Check out the sysctl man page for more details.

Test First SEO: Pretty Urls with Rails and to_slug Plugin

I used to do search engine marketing before making the career switch to software engineering and I’ve been doing some work on classes.blazingcloud.net to help Google figure out what we are all about. The contents of the url is one of the many ways to improve Google’s understanding of a webpage. ‘Pretty Urls’ is search engine optimization (SEO) lingo for semantic urls that describe in words what the page is about. In my quest to prettify our urls, I found the to_slug Rails plugin. I ran the plugin install:

script/plugin install git://github.com/ludo/to_slug.git

Then I started up Rails console to try out my new to_slug method.

>> "hello world".to_slug
=> "hello-world"

Next I wanted to include pretty urls in my routes, so I wrote a spec:

  describe "Routes" do
    it "for Course#show should have pretty urls" do
      route_for(:controller => "courses", :action => "show", :slug => "hello-world", :id => 1).should == "/courses/show/1/hello-world"
    end
  end

After running the spec & getting my expected failure, I added a route:

map.pretty_course 'courses/show/:id/:slug', :controller => 'courses', :action => 'show'

My test passed, so I went on to update the links. I can now use the following code and it will go to my desired pretty url:

pretty_course_path(:slug => course.name.to_slug, :controller => 'courses', :action => 'show', :id => course.id)

BieberFy




Here at Blazing Cloud we are happy to announce the launch of our first official product, BieberFy! BieberFy was inspired by Justin Bieber and the overwhelming response to his floppy teenage hair cut. So we thought, what would be better then to make an app that could give anyone Justin Bieber’s hair du? I mean, haven’t you always wondered what you would look like with Justin Bieber’s hair? Okay, maybe thats a stretch, wondering what you would look like with Justin Biebers likeness and all, but if  your curiosity gets the better of you there IS an app for that now.

BieberFy is an application that runs on iOS 4 for the iPhone and iPod touch. BieberFy takes advantage of the devices built in camera by displaying an overlay that gives you three Justin Bieber hair styles to choose from.  The initial version of the app allows you to take a photo with one of the hair styles, preview it and if you choose to accept, it will save it to the device’s built in photo album.

BieberFy is available for sale world wide via the iTunes app store for $0.99.

We hope you have just as much fun with this app as we do!

Converting a UTF-16 file to UTF-8

Lorien recently received a bunch of SVG files encoded in UTF-16 that her Aptana editor didn’t support well. She discovered this because ever time she needed to move to the next character, she needed to arrow right twice.

There were a few interesting properties of a UTF-16 file that we discovered by reading  this post:

  • This encoding is often used on Windows systems
  • UTF-16 uses two bytes per character
  • The beginning of a UTF-16 file contains a BOM (Byte Order Mark) that looks like \0xFF\0xFE

She wanted to run a regular expression over the files, but it didn’t work because the files contained double-byte characters. The files didn’t have any special characters as they all looked like ASCII characters, so to fix her issue all we needed to do was to convert the files down to UTF-8.

We discovered a Unix utility program called iconv that helps with character set conversion. A basic run looks like:

iconv -f utf-16 -t utf-8 inputFile > outputFile

After writing a  simple shell script to convert all the files, her problem was solved.

#!/bin/bash
mkdir -p out
for f in `ls -1 *.svg`; do
 iconv -f utf-16 -t utf-8 $f > out/$f
done

Rails 3: getting started

Rails 3 Cliff Notes, Part 1: getting started

  1. Requires Ruby 1.8.7 or higher, but Ruby 1.9.2 is very stable and you should use it for new projects (unless you deploy on Heroku). Use rvm to remain sane when switching between new and old projects. By creating a .rvmrc file, rvm will automatically switch you to the right version of Ruby and set of gems when you cd into the directory.
  2. Heroku requires 1.8.7 for Rails 3. To create a heroku app for rails 3, you need to use the “bamboo” stack
    heroku create --stack bamboo-ree-1.8.7
    
  3. You must use bundler which means that the only gems that Rails will use are the ones declared in your Gemfile. Very cool.
    • I plan to use Heroku, so I want to make sure that I’m only using sqlite3 in development and test.
    • I like rspec, so I also add it to my Gemfile (added to development as well as test, so I can use generators
    • Update: if you scaffold and rspec generates view specs, it will use webrat steps, but there is no gem dependency, you need to add webrat to the Gemfile
  4. No more script/console, use the rails command for everything
  5. Set up the test framework that you like first, then the rails generators will create the correct corresponding tests, specs, or whatever
$ rvm install 1.9.2
$ rvm use 1.9.2
$ rvm gemset create rails3
$ rvm use 1.9.2@rails3
$ rails new myapp
$ cd myapp
$ echo "rvm use 1.9.2@rails3" >> .rvmrc
$ vi Gemfile   # add the following to your gemfile 
group :development, :test do
 gem 'sqlite3-ruby', :require => 'sqlite3'
 gem "rspec-rails", ">= 2.0.0.beta.22"
 gem "webrat"      # currently generated view specs require this
end
$ bundle install
$ rails generate rspec:install
$ rails generate scaffold note title:string content:text
$ rake db:migrate
$ rails server

Good resources