I will be heading off to the Boston Gameloop 2010 conference at the Microsoft NERD center in Cambridge, MA tomorrow night. I decided to travel by the means of the Bolt Bus which provides both power outlets for laptops as well as free Internet for the trip. I am not quite sure the quality of either, but I expect to at least be online occasionally tomorrow night to chat on and off. I think I am going to take this time to work more on my Ruby on Rails project, Type Aloud, which I am hoping to launch sometime around the beginning of October. I will be sending around some beta invites when the site is ready to rock and roll.
Lazy loading is a software design pattern that delays the initialization of resources until the first time they are to be used inside of an application. Thus, for certain applications that rarely use memory intensive resources, you only need to initialize when there is a guarantee it is to be used. This has obvious performance and efficiency benefits. As a C++ programmer by trade I find it rather irritating that there is not a generic class that automatically handles lazy loading for me. So like any good lazy fuck I decided to spend a few hours and write one of my own. I currently have two use cases for this little tidbit.
When you have available a default construct its use is quite simple and straight forward. This object allocates the class with the default constructor when it is first called directly through any of the accessor operators, or directly with the get method. In this particular example when loaded it correctly returns the unique identifier.
class Unique { public: Unique() : m_uuid(boost::uuids::random_generator()()) { } const boost::uuids::uuid& uuid() { return m_uuid; } private: boost::uuids::uuid m_uuid; }; int main(int argc, char* argv[]) { thunk::lazy_loader<Unique> loader; const boost::uuids::uuid& u = loader->uuid(); std::cout<<"uuid: "<<boost::lexical_cast<std::string>(u)<<std::endl; return 0; }
The second example uses a boost function structure as a factory method, and it is executed instead of the default constructor. The factory method takes a reference to a boost shared pointer and correctly calls the constructor with any obligatory parameters. The boost shared pointer is owned by the lazy loader implementation and is used to maintain a reference counted state.
class Unique { public: Unique() : m_uuid(boost::uuids::random_generator()()) { } Unique(const boost::uuids::uuid& u) : m_uuid(u) { } const boost::uuids::uuid& uuid() { return m_uuid; } private: boost::uuids::uuid m_uuid; }; static void factory(boost::shared_ptr<Unique>& impl) { impl = boost::shared_ptr<Unique>( new Unique(boost::uuids::nil_uuid()) ); } int main(int argc, char* argv[]) { thunk::lazy_loader<Unique> loader(&factory); const boost::uuids::uuid& u = loader->uuid(); std::cout<<"uuid: "<<boost::lexical_cast<std::string>(u)<<std::endl; return 0; }
I am still working on a better method for initializing with a n-argument constructor. I have made my current progress available on my Github.com repository available for use with the standard three-clause BSD license. If you have any questions or bugfixes please feel free to submit them through Github.
The guys over at Digg have been gracious enough to invite me as one of the first people to use the new Digg 4 alpha. Let me say, the design and speed of the new Digg is simply amazing. It really shows how awesome a Cassandra backend can be. I’m glad to be choosing a NoSQL option for my upcoming project.
Also, in order to add this feed I need to post this bad boy up – db998ce11c694408adff259cf458c5c4 – have a good holiday!
My buddy, and fellow NJIT graduate, noble prize laureat, open source developer, Kenny Katzgrau wrote up a great post on How To Get A Job As A Programmer.
Anyone that may be interested in computer science as a major in college (or if you are already sitting in classes) that thinks they want to be a programmer may want to go read his little tidbit. If you’re in college to become a programmer I am personally of the opinion that you’ve already missed your calling. Switch majors immediately. You should love this craft before you decide to make it a career.
After work each night for the past couple of months I have been getting my hands dirty with Ruby/Rails development. I can imagine that most developers out there grow to love rake, but for the life of me I literally hate executing a series of commands on a regular basis. The programmer in me loves automation, and while in development I find myself dropping, re-creating and migrating the database constantly. Why should I have to issue three commands?
rake db:drop rake db:create rake db:migrate
After a little bit of searching I found that this can be accomplished in two commands.
rake db:reset rake db:migrate
Welp, that’s not enough for me because I am just that damn lazy. So, a simple rake task to bounce a database.
namespace :db do
desc "Drop, create and migrate the current database"
task :bounce => :environment do
Rake::Task['db:reset'].invoke
Rake::Task['db:migrate'].invoke
end
end
I hope you enjoy it as much as I do.
rake db:bounce
Unless you’ve been under the rock for the past couple of weeks, by now you should have heard about AT&T killing the unlimited data plans for both the iPhone and iPad, then grandfathering in the iPad plans for people who buy theirs before the deadline and finally caving in and allowing a 30 day “grace” window until the deadline. If have been following that news then you most certainly have heard about the release of the iPhone 4.0 on the AT&T network and Apple’s change of tune on mobile advertising as soon as they decide to start their own ad network built in natively into the operating system. The big news obviously is the caps on data, 200MB and 2GB respectively, and how many people are rather irritated because the iPhone is built around connectivity. There has been continuous coverage on podcasts and blogs regarding how the 200MB plan is essentially crap and the 2GB plan is a necessity, but what people are not talking about is Apple is now going to be delivering advertisements to your iPhones and iPads which are going to consume quite a bit of bandwidth that you will now be paying quite a pretty penny for.
Of course one could argue that mobile advertisements have always been on the applications that are available through the App Store, but Apple themselves are toting these media rich advertisements that allow for running video, interactive games and streaming audio which out of all the possible digital mediums consume the most bandwidth. So not only are we now going to have advertisements pushed upon us, but the cheaper bill that AT&T is waving around in our faces will most likely be non-existant if these iAds push us over our bandwidth limit.
Of course Apple neglected to mention this little tidbit in their press conference earlier this week. Even though I am eligible for an upgrade on my account I think I am going to wait to see what happens with this whole bandwidth fiasco that AT&T is pulling, and more off, hoping that Verizon will get an iPhone this time next year coupled with an unlimited data plan that I can actually use in the New York City metro area. Here’s to dreams.