Skip to main content

Posts

Showing posts from 2012

Using (R)?ex for Fame and Fortune

Overview (R)?ex , according to its website, is a tool written in Perl for configuration management and software deployment. The only requirement to have is an SSH connection to the remote server(s). Alternative Uses (R)?ex is a very capable tool to automate system administration tasks. For example, I have recently built an RPM build script that copies my local code/files to a build server, builds an RPM package, and downloads the finished RPM to my RPM repository on my local box. I have also used it to generate reports. One recent report was required to see how many of our servers were able to access a certain DNS view. In fact, the use cases are pretty much unlimited. You can use (R)?ex for any process that requires some sort of automation on a remote server. That said, as powerful as it is, (R)?ex still requires some initial setup to become usable. I have included a couple of my tips below. Tips and Tricks Code Structure Rexify.org Wiki recommends using revision control s...

Networking with Multiple Guests on VirtualBox

IT Support I showed up to work on my first day a couple of weeks ago and the first thing that I was given was a company Mac... A Mac! My absolutely brilliant idea was to ask IT support if I was allowed to wipe the hard-drive clean and install my favorite Linux distribution. After giving me the classic thousand-yard stare that every IT dude gives every time you ask for something, he told me that "it was not supported". Long story short, at the end of the first week, I was left with this piece of brushed Aliminum brick running some applications that does not even run on Linux but required by my new company. Virtualization Solution? Of course virtualization. Needless to say, this was a complex setup with multiple requirements: * I want to run a Fedora guest for every day use. There is nothing that can match Konsole running on a bleeding edge distribution out there. * I also need to run a CentOS guest for certain tasks such as building RPMs and other production related tas...

Android OAuth2 REST client with Spring for Android

Overview In this article, I will try to explain how to design an Android OAuth2 client that can interact with a Smyfony2 back-end implementation using Spring for Android and Spring Social. Before we start, I need to emphasize a couple of points. First of all, I am not an Android expert; I am still learning. Secondly, I like to leverage existing tools so I have chosen Spring Social for Android for this article. It satisfies my requirements for this tutorial but it may not be suitable for every case. Finally, I will not be explaining the server side implementation in this article. Read my previous FOSRestBundle and FOSOAuthServerBundle articles if you need starters. Raw Data Let's first look at the raw data that we will fetch from the server. Because I have been using the Conversation and Message examples for a while now, I will stick with the same pattern in this article. Let's say we would like to retrieve a list of conversations by a specific user from a REST endpoi...

A Parcelable Tutorial for Android

Parcelable Interface Overview In one of my earlier posts, I mentioned writing an article about FOSOAuthBundle integration with an Android client. To keep that article to the point, I need to explain some concepts beforehand. One of the important concepts is the Android Parcelable interface that allows data to be transferred between different processes/threads. Certain network operations with Android such as authentication with OAuth2 and then fetching data from a REST endpoint should be performed in the background in order not to block the UI thread. This requires data to be fetched by a service (I have opted for Intent Services in my implementation) in the background and then passed back to the calling activity/fragment with a result callback. This is where the Parcelable interface comes into play. Basically, the Parcelable interface allows your classes to be flattened inside a message container called a Parcel to facilitate high performance inter process communication. The rece...

Atomicly update an embedded document with Doctrine MongoDB ODM

I had to deal with an unexpected problem recently. In my setup, I have a Conversation document which contains multiple Message documents embedded inside - a one-to-many mapping basically - and I need to atomically push a new Message when a user replies to a conversation. Below is the initial code that I implemented: public function reply($conversationId, Message $message, $flush = true) { $this->dm->createQueryBuilder($this->class) ->update() ->field('archivers')->unsetField() ->field('repliedBy')->set($message->getUserId()) ->field('repliedBody')->set($message->getBody()) ->field('repliedAt')->set(new \DateTime()) ->field('modifiedAt')->set(new \DateTime()) ->field('messages')->push($message) ->field('id')->equals(new \MongoId($conversationId)) ->getQuery() ->execut...

Updates to managed documents under Doctrine MongoDB ODM

If you update a document returned by Doctrine MongoDB ODM, changes to that document will be flushed to even if you do not call the persist() method on that document. That is because the document returned is a managed document. In fact, the persist() call gets ignored for these managed documents. From the documentation : If X is a preexisting managed document, it is ignored by the persist operation. However, the persist operation is cascaded to documents referenced by X, if the relationships from X to these other documents are mapped with cascade=PERSIST or cascade=ALL. In my case, this recently caused an issue where duplicate embedded documents ended up being pushed into a parent document because I was using and updating the parent document for generating a custom Symfony2 form. Turned out to be a bad idea... If you need to update these type of documents, detach them first.

Recent News and Articles - July 2012

Google announced the Google Compute Engine . Even though it is too early to comment, as a customer of Amazon's EC2 services, I am loving this; competition is definitely good news for business. For the gamers out there, Epic Games introduced the Unreal Engine 4 recently. Have a look at the Wired article to understand the implications of this new engine on the gaming and hardware industry. Here is the development walk-through . There is also a showcase demo available for a preview. Warning, shameless self promotion here: the Symfony Blog picked my article about creating a custom JMSSerializerBundle handler .

Creating a Custom JMSSerializerBundle Handler

A couple of days ago, I had to create a custom JMSSerializerBundle handler to process the serialization of a certain property of one of my models. In my case, I have a user model that has a single associated avatar stored on Amazon S3. The problem is that this avatar URI consists of just the path section (for example: /avatars/12/34/43/123443.jpg) instead of the full URL. This is required to allow my application to work with multiple buckets, each of which corresponds to a different environment such as development, production, etc. However, the Android client I am currently working on (or any other REST client for that matter) needs the full URL of each avatar returned from the server. Injecting this logic into the model class was obviously not a really good idea, so I decided to write a custom JMSSerializerBundle handler to achieve my objective. The idea is the have the custom handler access the required system services and transform the avatar path from a relative on to a full one...

Android Development

I have recently started developing a new application for the Android platform. It had been a while since I experimented with Android and this really manifested itself when I started this new project a couple of months ago. Having to deal with new Android features and corresponding backwards compatibility issues, I experienced a steep learning curve. This article highlights the lessons learned during this process. JDK Selection I have been a Linux user since 2001 and never looked back since then. So if you are developing on Linux, make sure to replace the default OpenJDK with Oracle's. This will save you a lot of headache dealing with peculiar errors and exceptions during the initial set-up process. Selecting an IDE I really like NetBeans and still develop with this IDE when it comes to PHP; it definitely feels much more intuitive than Eclipse. However, when it comes to Android development, it did not take long for me to realize I was fighting an uphill battle. With its excellen...

Setting up a Symfony2 REST service with FOSRestBundle

Installation First thing is to download and setup the FOSRestBundle. If you are running Symfony 2.0.x, get the FOSRestBundle version 0.6, otherwise, download the code in the master branch. The FOSRestBundle depends on the JMSSerializerBundle so the following instructions are going to include some extra information for setting up this bundle to complete our REST service. First thing is to install our dependencies. Add the following to your deps file: [metadata] git=http://github.com/schmittjoh/metadata.git version=1.1.0 [JMSSerializerBundle] git=git://github.com/schmittjoh/JMSSerializerBundle.git target=bundles/JMS/SerializerBundle [FOSRest] git=git://github.com/FriendsOfSymfony/FOSRest.git target=fos/FOS/Rest [FOSRestBundle] git=git://github.com/FriendsOfSymfony/FOSRestBundle.git target=bundles/FOS/RestBundle version=origin/0.6 Run the vendors script to install these bundles: php bin/vendors install Next, update your app/autoload.php file...

Securing Symfony2 REST services with FOSOAuthServerBundle

Overview In my previous article, I wrote about setting up a Symfony2 REST service using FOSRestBundle. However, this REST service was behind a firewall protected by a generic form_login provider. Not really ideal if you wish to open your REST API to other applications. So in this article, I will try to explain how to set up FOSOAuthServerBundle to protect your REST API methods using OAuth2. Before we start getting into the gritty details, it is a good idea to have a look at the official OAuth2 documentation . Let's begin... FOSOAuthServerBundle Installation You have to install v1.1.0 of FOSOAuthServerBundle if you are using Symfony 2.0.x. If not, see the docs . First, add the following entries to your deps file: [FOSOAuthServerBundle] git=git://github.com/FriendsOfSymfony/FOSOAuthServerBundle.git target=bundles/FOS/OAuthServerBundle version=origin/1.1.x [oauth2-php] git=git://github.com/FriendsOfSymfony/oauth2-php.git Run the vendors script to install these...