<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 
 <title>Zumba Tech</title>
 <link href="http://tech.zumba.com/atom.xml" rel="self"/>
 <link href="http://tech.zumba.com"/>
 <updated>2016-09-13T02:18:58+00:00</updated>
 <id>http://tech.zumba.com</id>
 <author>
   <name>Zumba Tech</name>
   <email>engineering@zumba.com</email>
 </author>

 
 <entry>
   <title>Zumbatech takes on #hackforchange</title>
   <summary>How Zumbatech contributed to Hackforchange utilizing opensource tools.</summary>
   <link href="http://tech.zumba.com/2015/06/15/zumbatech-at-hackforchange//"/>
   <author>
	<name>Chris Saylor</name>
	<email>christopher.saylor@zumba.com</email>
   </author>
   <updated>2015-06-15T00:00:00+00:00</updated>
   <id>http://tech.zumba.com/2015/06/15/zumbatech-at-hackforchange</id>
   <content type="html">&lt;p&gt;On June 6, 2015, a team of engineers from Zumbatech decided to contribute in
an all-day hackathon event called &lt;a href=&quot;http://hackforchange.org/&quot;&gt;Hackforchange&lt;/a&gt;.
This is a national effort for civic hacking that brings engineers and designers
together to make a positive impact in our communities.&lt;/p&gt;

&lt;h2 id=&quot;lets-not-re-invent-the-wheel&quot;&gt;Let’s not re-invent the wheel&lt;/h2&gt;

&lt;p&gt;The day before the event, our team got together to figure out what we were going to work
on that would give the most impact to our community. We chose to work on generating visualizations
of Florida vendor transactions. The first thing we noticed is that a couple of projects had
already been underway to create restful APIs and alternate data formats for this data. We decided
that an API that is specific to this data set wouldn’t be very reusable for other data sets, &lt;em&gt;and&lt;/em&gt;
it would still take an engineer’s effort to visualize the data from those APIs.&lt;/p&gt;

&lt;p&gt;We wanted to make something that is generic enough to work with any sort of data set,
be flexible enough for other engineers to create tools and visualizations via an API,
and be easy enough for non-engineers to construct visualizations that fit their needs.
A daunting task, especially for it to be &lt;em&gt;mostly&lt;/em&gt; completed in a single hackathon.
After some planning and discussion, we came up with a solution ready for hacking!&lt;/p&gt;

&lt;h2 id=&quot;hackathon&quot;&gt;Hackathon&lt;/h2&gt;

&lt;p&gt;Bright and early on that Saturday morning, we arrived in the &lt;a href=&quot;http://thelabmiami.com/&quot;&gt;LAB Miami&lt;/a&gt; offices to
work on a project we called &lt;a href=&quot;https://github.com/cjsaylor/datamnom&quot;&gt;Datamnom&lt;/a&gt;. The idea
of the project is to make a generic ingestion program that can take in multiple data sources and
populate an &lt;a href=&quot;https://www.elastic.co/products/elasticsearch&quot;&gt;Elasticsearch&lt;/a&gt; index. Once the data
is in Elasticsearch, a tool called &lt;a href=&quot;https://www.elastic.co/products/kibana&quot;&gt;Kibana&lt;/a&gt; can be hooked
up to the Elasticsearch index we populated to create visualizations.&lt;/p&gt;

&lt;p&gt;After writing a prototype &lt;a href=&quot;https://nodejs.org&quot;&gt;nodejs&lt;/a&gt; program and setting up a &lt;a href=&quot;https://www.vagrantup.com/&quot;&gt;Vagrant&lt;/a&gt;
environment, we had Kibana up and running with data to visualize:&lt;/p&gt;

&lt;p&gt;&lt;img alt=&quot;Kibana running FL Vendor data&quot; class=&quot;img-responsive&quot; src=&quot;/img/blog/visualization1.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Here is team Zumba demoing our work to the Florida CFO, Jeff Atwater:&lt;/p&gt;

&lt;p&gt;&lt;img alt=&quot;Team Zumba demoing Datamnom to Jeff Atwater and others&quot; class=&quot;img-responsive&quot; src=&quot;/img/blog/miamiherald-hackathon.jpg&quot; /&gt;&lt;/p&gt;

&lt;p&gt;via &lt;a href=&quot;http://miamiherald.typepad.com/the-starting-gate/2015/06/florida-cfo-jeff-atwater-spent-the-morning-with-a-coworking-space-full-of-young-hackers-this-is-dress-down-day-for-me.html&quot;&gt;Miami Herald&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;presentation-and-reception&quot;&gt;Presentation and Reception&lt;/h2&gt;

&lt;p&gt;After importing about 8 years worth of Florida Vendor transactions, the team presented our idea and applications
to the group. Other groups that were working with this data set decided to use our tools to make their own visualizations.&lt;/p&gt;

&lt;div class=&quot;row&quot;&gt;
    &lt;div class=&quot;col-md-6&quot;&gt;
        &lt;blockquote class=&quot;twitter-tweet&quot; lang=&quot;en&quot;&gt;&lt;p lang=&quot;en&quot; dir=&quot;ltr&quot;&gt;Team &lt;a href=&quot;https://twitter.com/zumbatech&quot;&gt;@zumbatech&lt;/a&gt; presents FL State Payments API and visualization app. &lt;a href=&quot;https://twitter.com/hashtag/hackforchange?src=hash&quot;&gt;#hackforchange&lt;/a&gt; &lt;a href=&quot;http://t.co/R48vs6AnUZ&quot;&gt;pic.twitter.com/R48vs6AnUZ&lt;/a&gt;&lt;/p&gt;&amp;mdash; Code For Miami (@CodeForMiami) &lt;a href=&quot;https://twitter.com/CodeForMiami/status/607296202191872000&quot;&gt;June 6, 2015&lt;/a&gt;&lt;/blockquote&gt;
        &lt;script async=&quot;&quot; src=&quot;//platform.twitter.com/widgets.js&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;
    &lt;/div&gt;
    &lt;div class=&quot;col-md-6&quot;&gt;
        &lt;blockquote class=&quot;twitter-tweet&quot; lang=&quot;en&quot;&gt;&lt;p lang=&quot;en&quot; dir=&quot;ltr&quot;&gt;Using &lt;a href=&quot;https://twitter.com/zumbatech&quot;&gt;@zumbatech&lt;/a&gt;&amp;#39;s Payments API, &lt;a href=&quot;https://twitter.com/robdotd&quot;&gt;@robdotd&lt;/a&gt; and team visualize printing costs across FL departments. &lt;a href=&quot;https://twitter.com/hashtag/hackforchange?src=hash&quot;&gt;#hackforchange&lt;/a&gt; &lt;a href=&quot;http://t.co/eB0BpAgpyV&quot;&gt;pic.twitter.com/eB0BpAgpyV&lt;/a&gt;&lt;/p&gt;&amp;mdash; Code For Miami (@CodeForMiami) &lt;a href=&quot;https://twitter.com/CodeForMiami/status/607297271928131585&quot;&gt;June 6, 2015&lt;/a&gt;&lt;/blockquote&gt;
        &lt;script async=&quot;&quot; src=&quot;//platform.twitter.com/widgets.js&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;
    &lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;row&quot;&gt;
    &lt;div class=&quot;col-md-6&quot;&gt;
        &lt;blockquote class=&quot;twitter-tweet&quot; lang=&quot;en&quot;&gt;&lt;p lang=&quot;en&quot; dir=&quot;ltr&quot;&gt;State challenge group is visualizing Vendor Data in a bunch of different ways and automating new viz. &lt;a href=&quot;https://twitter.com/hashtag/hackforchange?src=hash&quot;&gt;#hackforchange&lt;/a&gt; &lt;a href=&quot;http://t.co/ZGZYnUrcS6&quot;&gt;pic.twitter.com/ZGZYnUrcS6&lt;/a&gt;&lt;/p&gt;&amp;mdash; Code For Miami (@CodeForMiami) &lt;a href=&quot;https://twitter.com/CodeForMiami/status/607218433437089792&quot;&gt;June 6, 2015&lt;/a&gt;&lt;/blockquote&gt;
        &lt;script async=&quot;&quot; src=&quot;//platform.twitter.com/widgets.js&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;
    &lt;/div&gt;
    &lt;div class=&quot;col-md-6&quot;&gt;
        &lt;blockquote class=&quot;twitter-tweet&quot; lang=&quot;en&quot;&gt;&lt;p lang=&quot;en&quot; dir=&quot;ltr&quot;&gt;Great presentation from &lt;a href=&quot;https://twitter.com/CodeforFTL&quot;&gt;@CodeforFTL&lt;/a&gt; and group! &lt;a href=&quot;https://twitter.com/hashtag/hackforchange?src=hash&quot;&gt;#hackforchange&lt;/a&gt; &lt;a href=&quot;https://twitter.com/knightfdn&quot;&gt;@knightfdn&lt;/a&gt; &lt;a href=&quot;https://twitter.com/CFJBLaw&quot;&gt;@CFJBLaw&lt;/a&gt; &lt;a href=&quot;https://twitter.com/wyncode&quot;&gt;@wyncode&lt;/a&gt; &lt;a href=&quot;https://twitter.com/socrata&quot;&gt;@socrata&lt;/a&gt; &lt;a href=&quot;http://t.co/sEidId7pE9&quot;&gt;pic.twitter.com/sEidId7pE9&lt;/a&gt;&lt;/p&gt;&amp;mdash; Code For Miami (@CodeForMiami) &lt;a href=&quot;https://twitter.com/CodeForMiami/status/607297689525481473&quot;&gt;June 6, 2015&lt;/a&gt;&lt;/blockquote&gt;
        &lt;script async=&quot;&quot; src=&quot;//platform.twitter.com/widgets.js&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;
    &lt;/div&gt;
&lt;/div&gt;

&lt;h1 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h1&gt;

&lt;p&gt;We had a fun time at LAB Miami hacking together a project we think can really help
lawmakers, researchers, and reporters visualize public data in a way that allows them
to ask the right questions and help our communities.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>W3C Push API Crash Course</title>
   <summary>Getting started with push notifications in Google Chrome</summary>
   <link href="http://tech.zumba.com/2015/05/29/chrome-push-api//"/>
   <author>
	<name>Nick Comer</name>
	<email>nicholas@zumba.com</email>
   </author>
   <updated>2015-05-29T00:00:00+00:00</updated>
   <id>http://tech.zumba.com/2015/05/29/chrome-push-api</id>
   <content type="html">&lt;p&gt;W3C’s &lt;a href=&quot;http://www.w3.org/TR/push-api/&quot;&gt;Push API&lt;/a&gt; is exciting. Almost as exciting as all the possibilities that arise from having a persistent presence in your users’ browser. At Zumba, we already have ideas for it, and I was in charge of doing the gritty work of getting notifications to show up in the browser, but also developing a way to manage who gets those notifications. I had a lot of questions along the way that I will lay out and give you straight answers. Let’s get pushing already!&lt;/p&gt;

&lt;h2 id=&quot;the-serviceworker&quot;&gt;The ServiceWorker&lt;/h2&gt;
&lt;p&gt;The &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker&quot;&gt;&lt;strong&gt;ServiceWorker&lt;/strong&gt;&lt;/a&gt; is where the Push API lives. A &lt;strong&gt;ServiceWorker&lt;/strong&gt; is a JavaScript file that defines activities that are allowed to run continuously, well after the life-cycle of a web-page. If you have heard of &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/Worker/Worker&quot;&gt;&lt;strong&gt;WebWorkers&lt;/strong&gt;&lt;/a&gt;, ServiceWorkers are quite similar, but they will continue to work in the background even after a user has closed the web-page, which is key to being available to show notifications.&lt;/p&gt;

&lt;h3 id=&quot;serviceworker-registration&quot;&gt;ServiceWorker Registration&lt;/h3&gt;
&lt;p&gt;Before we get started with registering, you need to set up a Google Application that can be used with Google Cloud Messaging to actually send the notifications; it is free for development and takes about 2-3 minutes.&lt;/p&gt;

&lt;h4 id=&quot;google-application-setup&quot;&gt;Google Application Setup&lt;/h4&gt;
&lt;ol&gt;
  &lt;li&gt;Go to &lt;a href=&quot;https://console.developers.google.com&quot;&gt;Google Developer Console&lt;/a&gt; and &lt;strong&gt;create&lt;/strong&gt; a new application.&lt;/li&gt;
  &lt;li&gt;Note your new applications &lt;strong&gt;Project Number&lt;/strong&gt;:
&lt;img src=&quot;/img/blog/google-api-console-app-id.png&quot; alt=&quot;Google API Project Number&quot; class=&quot;img-responsive&quot; /&gt;&lt;/li&gt;
  &lt;li&gt;Go to the new application and under &lt;strong&gt;APIs &amp;amp; auth&lt;/strong&gt; click &lt;strong&gt;APIs&lt;/strong&gt; and look for “messaging” and enable:
    &lt;ul&gt;
      &lt;li&gt;&lt;em&gt;Google Cloud Messaging for Chrome&lt;/em&gt;&lt;/li&gt;
      &lt;li&gt;&lt;em&gt;Google Cloud Messaging for Android&lt;/em&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Under the same sidebar menu, go to &lt;strong&gt;Credentials&lt;/strong&gt; and generate new &lt;strong&gt;Public API access&lt;/strong&gt; keys for &lt;strong&gt;server&lt;/strong&gt;. Keep them handy for a little later on.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;manifestjson&quot;&gt;manifest.json&lt;/h4&gt;
&lt;p&gt;Google Chrome relies on a simple JSON file to detect your websites Google Cloud app. It is placed in the root of your website and it goes a little something like this:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/81e37636d6b0a55788f1.js?file=manifest.json&quot;&gt; &lt;/script&gt;

&lt;p&gt;Replace &lt;code class=&quot;highlighter-rouge&quot;&gt;application_project_number&lt;/code&gt; with the project number of your Google App from the steps above. Moving on!&lt;/p&gt;

&lt;hr /&gt;

&lt;h4 id=&quot;serviceworker-life-cycle&quot;&gt;ServiceWorker Life-Cycle&lt;/h4&gt;
&lt;p&gt;ServiceWorkers have a registration process that goes through the following steps:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;install&lt;/strong&gt;: currently being installed&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;waiting&lt;/strong&gt;: waiting on registration&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;active&lt;/strong&gt;: registered and running&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h4 id=&quot;scope&quot;&gt;Scope&lt;/h4&gt;
&lt;p&gt;ServiceWorkers also have a &lt;em&gt;scope&lt;/em&gt; which is set to the directory under which it can be found. For example, if your service worker script is located at &lt;code class=&quot;highlighter-rouge&quot;&gt;/static/js/muh/scripts/ServiceWorker.js&lt;/code&gt; Then its &lt;em&gt;scope&lt;/em&gt; will be: &lt;code class=&quot;highlighter-rouge&quot;&gt;/static/js/muh/scripts/&lt;/code&gt;. This will not work; your users will not be doing their browsing in your static assets, so placing this script further up the directory tree is highly recommended. Service Workers also will not install if not served over HTTPS.&lt;/p&gt;

&lt;h4 id=&quot;registering&quot;&gt;Registering&lt;/h4&gt;
&lt;p&gt;Now that you know what to expect with setting up a suitable environment for your service worker let’s get it installed.&lt;/p&gt;

&lt;p&gt;A good installation script should also consider that their might be a service worker already in place and running. To check for that let’s do the following:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/81e37636d6b0a55788f1.js?file=check-sw-reg.js&quot;&gt; &lt;/script&gt;

&lt;p&gt;Now that we have the installation status: we know if registration of the service worker is necessary. Assuming registration is necessary:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/81e37636d6b0a55788f1.js?file=reg-sw.js&quot;&gt; &lt;/script&gt;

&lt;p&gt;&lt;strong&gt;ServiceWorkerRegistrations&lt;/strong&gt; are important to push because they hold the key to our next step which is the &lt;strong&gt;PushManager&lt;/strong&gt;. Once we have a reliable way to either register a ServiceWorker or retrieve an existing ServiceWorker’s registration, we can continue to…&lt;/p&gt;

&lt;h3 id=&quot;the-pushmanager&quot;&gt;The PushManager&lt;/h3&gt;
&lt;p&gt;The &lt;strong&gt;PushManager&lt;/strong&gt; is a creatively named API that manages our push subscriptions. The entry point for it can be found on that &lt;code class=&quot;highlighter-rouge&quot;&gt;ServiceWorkerRegistration&lt;/code&gt; I mentioned above. You should take the same approach with this as with service worker registrations. The functions you should know about are: &lt;code class=&quot;highlighter-rouge&quot;&gt;getSubscription&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;subscribe&lt;/code&gt;.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/81e37636d6b0a55788f1.js?file=pm-get-sub.js&quot;&gt; &lt;/script&gt;

&lt;p&gt;As you can see here, we check for an existing push subscription, then if one is not found we attempt to get permission for one. This attempt is when the user is prompted to approve notifications.&lt;/p&gt;

&lt;h3 id=&quot;putting-it-together&quot;&gt;Putting It Together&lt;/h3&gt;
&lt;p&gt;So, putting the two together, you probably end up with something like this:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/81e37636d6b0a55788f1.js?file=sw-pm-together.js&quot;&gt; &lt;/script&gt;

&lt;p&gt;This will auto-register a service-worker and will subscribe your website to push notifications and send the push subscription to your server.&lt;/p&gt;

&lt;h4 id=&quot;pushsubscription&quot;&gt;PushSubscription&lt;/h4&gt;
&lt;p&gt;Providing that everything went well, and the user agreed to be notified, you will be given a &lt;strong&gt;PushSubscription&lt;/strong&gt; object that will contain details about how to execute a push notification. (&lt;a href=&quot;http://www.w3.org/TR/push-api/#idl-def-PushSubscription&quot;&gt;PushSubscription&lt;/a&gt;) This object contains an &lt;code class=&quot;highlighter-rouge&quot;&gt;endpoint&lt;/code&gt; attribute which is the entry point for push notifications. (The Push API is still in flux, but I would recommend keeping the &lt;code class=&quot;highlighter-rouge&quot;&gt;endpoint&lt;/code&gt;; Google is the only one running a W3C compliant push server but I am sure there will be more to come and this will be what distinguishes them.)&lt;/p&gt;

&lt;p&gt;What distinguishes this user is the subscriptionId, which is like a device ID and will be how you reach this particular user with your push notifications.&lt;/p&gt;

&lt;h4 id=&quot;using-the-pushsubscription&quot;&gt;Using the PushSubscription&lt;/h4&gt;
&lt;p&gt;Once you have the &lt;code class=&quot;highlighter-rouge&quot;&gt;subscriptionId&lt;/code&gt;, you can send it to Google Cloud Messaging endpoint like so:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/81e37636d6b0a55788f1.js?file=gcm-send-req.sh&quot;&gt; &lt;/script&gt;

&lt;p&gt;Put your Google Cloud project API key next to &lt;code class=&quot;highlighter-rouge&quot;&gt;key=&lt;/code&gt; and put the users &lt;code class=&quot;highlighter-rouge&quot;&gt;subscriptionId&lt;/code&gt; in &lt;code class=&quot;highlighter-rouge&quot;&gt;registration_ids&lt;/code&gt; and this will send notifications but we need to tell the service worker how to receive them, and what to do with them.&lt;/p&gt;

&lt;h4 id=&quot;receiving-notifications-with-serviceworker&quot;&gt;Receiving Notifications with ServiceWorker&lt;/h4&gt;
&lt;p&gt;ServiceWorkers run in a completely different global context than a DOMWindow. The global object in a ServiceWorker is &lt;code class=&quot;highlighter-rouge&quot;&gt;self&lt;/code&gt;, and the event to look out for is &lt;code class=&quot;highlighter-rouge&quot;&gt;onpush&lt;/code&gt;. A very simple notifier service worker will look something like this:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/81e37636d6b0a55788f1.js?file=simple-service-worker.js&quot;&gt; &lt;/script&gt;

&lt;p&gt;This will extract that push data out of the event and show it as a notification.&lt;/p&gt;

&lt;h3 id=&quot;the-bad-news&quot;&gt;The Bad News&lt;/h3&gt;
&lt;p&gt;W3C’s Push API is very new. Google Chrome is the only browser to begin working on implementation and it still isn’t finished. With that in mind, the Chromium development team has intentionally blocked arbitrary data from being sent through the Push API for now &lt;a href=&quot;https://code.google.com/p/chromium/issues/detail?id=449184&quot;&gt;(chromium issue #449184)&lt;/a&gt;. The reason stated is that as of right now, the API does not mandate encryption of incoming push messages. Without mandatory encryption, anyone can easily use a &lt;a href=&quot;https://en.wikipedia.org/wiki/Man-in-the-middle_attack&quot;&gt;Man-in-the-middle attack&lt;/a&gt; to put bad data into push messages.&lt;/p&gt;

&lt;p&gt;As stated in the linked chromium issue, push messages are really just fancy pings at this point. But those pings &lt;em&gt;can&lt;/em&gt; be used to tell clients to fetch the latest data from your servers.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;I will continue to follow the Push API and keep this article updated if any important developments occur. Drop me a line on &lt;a href=&quot;https://twitter.com/nkcmr&quot;&gt;twitter&lt;/a&gt; if you have any questions. Happy pushing!&lt;/p&gt;

&lt;h4 id=&quot;other-helpful-resources&quot;&gt;Other Helpful Resources:&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://www.html5rocks.com/en/tutorials/service-worker/introduction/&quot;&gt;Introduction to Service Worker&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker_API&quot;&gt;MDN: ServiceWorker API&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=SmZ9XcTpMS4&quot;&gt;Jake Archibald: The ServiceWorker is coming, look busy | JSConf EU 2014&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Relational Database Design</title>
   <summary>Conventions and strategies to create a schema that will grow with your application and organization.</summary>
   <link href="http://tech.zumba.com/2015/05/22/database-design//"/>
   <author>
	<name>Justin Oakley</name>
	<email>justin.oakley@zumba.com</email>
   </author>
   <updated>2015-05-22T00:00:00+00:00</updated>
   <id>http://tech.zumba.com/2015/05/22/database-design</id>
   <content type="html">&lt;p&gt;Schema design is something that is very important to any application where data is to be stored and retrieved.  It is also a topic that is often debated, controversial and discarded as something simple to be done during development.  However, Proper planning BEFORE development is done will help save a lot of time down the road.&lt;/p&gt;

&lt;p&gt;Over my last 15 years in application development, I have been refining techniques, best practices and conventions with regard to designing database schemas so that they can be used in real world enterprise solutions.  In this article I will discuss some things I have learned so far and share my opinions and experiences.  The views expressed in this article are my own and may or may not reflect that of Zumba.&lt;/p&gt;

&lt;h3 id=&quot;overview---the-basics&quot;&gt;Overview - The Basics&lt;/h3&gt;
&lt;p&gt;Wikipedia explains a relational database as a digital database whose organization is based on the relational model of data, as proposed by E.F. Codd in 1970. This model organizes data into one or more tables (or “relations”) of rows and columns, with a unique key for each row. Generally, each entity type described in a database has its own table, the rows representing instances of that type of entity and the columns representing values attributed to that instance. Because each row in a table has its own unique key, rows in a table can be linked to rows in other tables by storing the unique key of the row to which it should be linked (where such unique key is known as a “foreign key”). Codd showed that data relationships of arbitrary complexity can be represented using this simple set of concepts.&lt;/p&gt;

&lt;p&gt;That’s a basic description of a relational database.  When designing a database schema, it is important to know the purpose of the application(s) in which it will be used and where the data may be transported at a later time.&lt;/p&gt;

&lt;h3 id=&quot;where-to-begin&quot;&gt;Where to begin&lt;/h3&gt;
&lt;p&gt;So, now that we have the basics covered and some definitions listed, it’s time to dig in and start designing.  The first thing you need to do is decide (or learn) the purpose of the application.  You will also want to know if there is to be any reporting performed on the data and if there is a data warehouse that will process this data for further consumption at a later date.&lt;/p&gt;

&lt;p&gt;For the purpose of this article, we will assume that this is an application that handles products that are delivered to the end user digitally like an interactive book.  The following are some questions you will want to ask the product owners at the start of a project.  Most of questions should be asked in general for all aspects of the software design.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Who is the audience of the application?
    &lt;ul&gt;
      &lt;li&gt;Who will be using the application and how?&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Are there administrative areas?
    &lt;ul&gt;
      &lt;li&gt;If so, will there be different statuses / states of items?&lt;/li&gt;
      &lt;li&gt;Do changes to these need to be monitored and logged?&lt;/li&gt;
      &lt;li&gt;Will there be a need to see real-time statistics?&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Does admin activity need to be logged and reported?&lt;/li&gt;
  &lt;li&gt;Does regular user activity need to be logged and reported?&lt;/li&gt;
  &lt;li&gt;Will there be a need for real-time reporting of user activity?&lt;/li&gt;
  &lt;li&gt;Will the application need to interact with 3rd party systems?&lt;/li&gt;
  &lt;li&gt;How long must data be stored to be compliant with any rules that must be followed?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are other questions that may be more specific to the type of application.&lt;/p&gt;

&lt;h3 id=&quot;naming-conventions&quot;&gt;Naming Conventions&lt;/h3&gt;
&lt;p&gt;Just as coding standards and variable naming conventions are important, so are the naming of tables and columns.  This is one of the more controversial subjects on database design.  The interesting thing about “best practices” is they change and flip flop regularly.  So, as such, many will agree and disagree with what I view as proper naming.  Also, in some cases frameworks may require you to use certain naming conventions.  If you are bound by such restrictions, then try to use as much of this as possible.&lt;/p&gt;

&lt;p&gt;So let’s just get to it then.&lt;/p&gt;

&lt;h4 id=&quot;tables&quot;&gt;Tables&lt;/h4&gt;
&lt;p&gt;The name should describe what is in the table and be very obvious to someone looking at the list of tables in your database.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;For tables that will map back to an object in code, use singular object names like ‘&lt;strong&gt;product&lt;/strong&gt;’, ‘&lt;strong&gt;user&lt;/strong&gt;’, ‘&lt;strong&gt;color&lt;/strong&gt;’, etc.&lt;/li&gt;
  &lt;li&gt;Join Tables that facilitate 1 to many relationships will have the main object listed first and the attribute name second and joined together with an underscore (eg. ‘&lt;strong&gt;product_language&lt;/strong&gt;’, ‘&lt;strong&gt;user_product&lt;/strong&gt;’).&lt;/li&gt;
  &lt;li&gt;Tables that store logged data will have a suffix of ‘_log’ (eg. ‘&lt;strong&gt;activity_log&lt;/strong&gt;’).&lt;/li&gt;
  &lt;li&gt;Tables that store historical states of objects or object/attributes will contain a suffix of ‘_hist’ as in “history” (eg. ‘&lt;strong&gt;product_status_hist&lt;/strong&gt;’).&lt;/li&gt;
  &lt;li&gt;When extending another table, typically a table in a framework that you want to be able to update without issue, you will add a meta table named the same as the table being extended with the suffix ‘&lt;strong&gt;_meta&lt;/strong&gt;’ (eg. ‘&lt;strong&gt;user_meta&lt;/strong&gt;’).&lt;/li&gt;
  &lt;li&gt;If this application will be packaged within an existing database, then all tables should contain the same prefix.  The prefix should be small, kept to &amp;lt;= 3 characters + an underscore (eg. ‘&lt;strong&gt;zba_&lt;/strong&gt;’).&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;columns&quot;&gt;Columns&lt;/h4&gt;
&lt;p&gt;Names of your columns should be as self-explanatory as possible when someone is simply looking at a list of names without seeing the full structure of the table to see types.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Try to avoid reserved words or words that are used in the SQL language.  For instance, don’t name a description column ‘desc’.  However, a suffix of ‘_desc’ is fine.  More on that later.&lt;/li&gt;
  &lt;li&gt;Most objects will have a “Name” element.  It is very easy to just call the column ‘name’ and be done with it.
    &lt;ul&gt;
      &lt;li&gt;However, if you use the table name (or portion of) and add the suffix of ‘&lt;strong&gt;_name&lt;/strong&gt;’, that will help to ensure that your query will not be ambiguous and that you will be able to pull data from a single query without having to specify an alias for each column name that is named generically.&lt;/li&gt;
      &lt;li&gt;In fact, any commonly used elements of an object should have their column name begin with the table so that the same simple usage can be achieved.  The convention for this would be to use ‘&lt;strong&gt;TABLE_&lt;/strong&gt;’ as a prefix to the generic name.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;When adding a column that is a foreign key to another table’s id, it should be named as the foreign table name + ‘_id’ (eg. in the product table, you would create the column ‘&lt;strong&gt;color_id&lt;/strong&gt;’ to reference the color table).
    &lt;ul&gt;
      &lt;li&gt;This format should be used for any foreign key columns.  The pattern is ‘&lt;strong&gt;FOREIGN-TABLE_FOREIGN-TABLE-COLUMN&lt;/strong&gt;’.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;When adding a column that is used as a flag (1 or 0, true or false, etc.), it should contain the prefix: ‘is_’.  So, an active flag would be named as ‘&lt;strong&gt;is_active&lt;/strong&gt;’, published flag would be ‘&lt;strong&gt;is_published&lt;/strong&gt;’.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;constraints&quot;&gt;Constraints&lt;/h4&gt;
&lt;p&gt;Constraints are used to create restrictions on Foreign Keys and indexes or just to put a restriction on the data going into the column.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Foreign Key&lt;/strong&gt;: Use the prefix ‘&lt;strong&gt;fk_&lt;/strong&gt;’ and follow this format: ‘&lt;strong&gt;fk_MAIN-TABLE_ref_FOREIGN-TABLE_FOREIGN-TABLE-COLUMN&lt;/strong&gt;’  (eg. ‘&lt;strong&gt;fk_product_ref_color_id&lt;/strong&gt;’).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Unique Index&lt;/strong&gt;: Use the prefix ‘&lt;strong&gt;udx_&lt;/strong&gt;’ and follow this format: ‘&lt;strong&gt;udx_MAIN-TABLE_MAIN-TABLE-COLUMN&lt;/strong&gt;’   (eg. ‘&lt;strong&gt;udx_product_product_name&lt;/strong&gt;’).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Non-Unique Index&lt;/strong&gt;: Use the prefix ‘&lt;strong&gt;idx_&lt;/strong&gt;’ and follow this format: ‘&lt;strong&gt;idx_MAIN-TABLE_MAIN-TABLE-COLUMN&lt;/strong&gt;’   (eg. ‘&lt;strong&gt;idx_product_product_name&lt;/strong&gt;’).&lt;/li&gt;
  &lt;li&gt;Multi-column indexes follow the same convention as single column unique and non-unique, except, you just keep appending the column names that are used.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;defaults-conventions&quot;&gt;Defaults Conventions&lt;/h3&gt;
&lt;p&gt;Now that the naming conventions are covered, let’s talk about some conventions when creating tables and how to put this to good use in your applications.&lt;/p&gt;

&lt;h4 id=&quot;standard-tables&quot;&gt;Standard Tables&lt;/h4&gt;
&lt;p&gt;Just about every web application will need one or all of the following tables.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;user&lt;/strong&gt;: This table may already exist if you are using an existing framework.
    &lt;ul&gt;
      &lt;li&gt;If using a framework, you may want to extend the user data in a table called ‘&lt;strong&gt;user_meta&lt;/strong&gt;’.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;role&lt;/strong&gt;: Just as you need users to use your system, you will want to differentiate those users. If using a framework in your application, this table may already exist.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;status&lt;/strong&gt;: Something in your application will likely have a need for different statuses.  This is typically a small table and should likely make use of bit masks (discussed later).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are other standard tables based on what type of application you are building.  &lt;strong&gt;product&lt;/strong&gt; might be a another common table.  But if your app does not deal with products, this might not be needed.&lt;/p&gt;

&lt;h4 id=&quot;standard-columns&quot;&gt;Standard Columns&lt;/h4&gt;
&lt;ul&gt;
  &lt;li&gt;All tables should have the following column.
    &lt;ul&gt;
      &lt;li&gt;A primary key column named simply ‘&lt;strong&gt;id&lt;/strong&gt;’.  This column can be simply a number or a large UUID string.  Unless there is a really good reason, the ID should generally be an integer of whatever size you think the table may grow.  The UUID can be another column in the table.
        &lt;ul&gt;
          &lt;li&gt;If numeric, It should be set to autoincrement (in databases that support it, or create a trigger and sequence in DBs such as Oracle to achieve the same thing).&lt;/li&gt;
          &lt;li&gt;If using a UUID string style, there is no autoincrement.  You will need to handle the generated value another way.&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Nearly all tables should have the following columns.  The only exception to this is when maintaining integrity is not important.
    &lt;ul&gt;
      &lt;li&gt;An ‘&lt;strong&gt;is_active&lt;/strong&gt;’ column with a default of 1 or true.  Instead of deleting from this table, you will set this to 0 or false.  This requires that your queries that select data be aware of the column and its purpose.&lt;/li&gt;
      &lt;li&gt;A ‘&lt;strong&gt;created&lt;/strong&gt;’ column with a default as specified below.  This should be set on row creation and not altered afterwards.&lt;/li&gt;
      &lt;li&gt;A ‘&lt;strong&gt;modified&lt;/strong&gt;’ column with a default as specified below.  This will contain a timestamp of when the most recent change was made to the record.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;column-types&quot;&gt;Column Types&lt;/h3&gt;

&lt;h4 id=&quot;basic-columns&quot;&gt;Basic Columns&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;Flag columns should be stored as either boolean column types (if supported) or 1-byte integers where they will hold either a 0 or 1.&lt;/li&gt;
  &lt;li&gt;Description or other columns that will hold markup or a lot of text should be some type of &lt;strong&gt;TEXT&lt;/strong&gt; column based on what is appropriate for the length of the data and what is supported by your database.&lt;/li&gt;
  &lt;li&gt;String values should be stored in VARCHAR type columns.  The length should be adequate to support the max length of the data.  I, personally, like using binary increments.  However, there is no benefit of doing so.  Just be sure it is large enough to support the data being stored.&lt;/li&gt;
  &lt;li&gt;When adding a foreign key column, be sure to set its type to be the same as the column that it references.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;date-and-time-columns&quot;&gt;Date and Time Columns&lt;/h4&gt;
&lt;p&gt;For columns that store date and time data, there are two ways to approach this.  Perform you calculations and procedures in the &lt;strong&gt;database&lt;/strong&gt; or the &lt;strong&gt;code&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;database&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;When offloading calculations and functions onto the database server, You will want to use datetime column types that are supported by the database server you are using.&lt;/li&gt;
      &lt;li&gt;At a minimum, you should choose a date and time column that that is as granular as 1 second.&lt;/li&gt;
      &lt;li&gt;You should use the same column type for all of your date-time columns so it will be obvious and predictable to anyone using the data.&lt;/li&gt;
      &lt;li&gt;For the ‘&lt;strong&gt;created&lt;/strong&gt;’ column, you will specify the default as whatever equates to NOW() for the column type chosen.&lt;/li&gt;
      &lt;li&gt;For the ‘&lt;strong&gt;modified&lt;/strong&gt;’ column, you will want to create a trigger that will set the value to whatever value was used for the default of the ‘created’ column ON UPDATE&lt;/li&gt;
      &lt;li&gt;The Date and Time column type should support timezone as well so that the time can be meaningful and re-produced reliably.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;code&lt;/strong&gt;
    &lt;ul&gt;
      &lt;li&gt;When writing code that can be used on multiple databases or when you want to perform manipulations or calculations in the code or directly in the SQL, then you should use a numeric type to store the data.&lt;/li&gt;
      &lt;li&gt;The data should be stored as a unix timestamp (Number of seconds since epoch).  So the column must be at least as large as an INTEGER(10).&lt;/li&gt;
      &lt;li&gt;The Integer type should also be unsigned.&lt;/li&gt;
      &lt;li&gt;For the ‘&lt;strong&gt;created&lt;/strong&gt;’ column, you will specify the default as whatever equates to CURRENT_TIMESTAMP in the database or 0 and handle the value in the code.&lt;/li&gt;
      &lt;li&gt;For the ‘&lt;strong&gt;modified&lt;/strong&gt;’ column, you will want to have code that is centralized in whatever base object everything extends to set this value to be the current timestamp.&lt;/li&gt;
      &lt;li&gt;Timestamps should be set using UTC timezone with the proper offset for the timezone desired.  An additional column to store the timezone may be required as well.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;joining-records&quot;&gt;Joining records&lt;/h3&gt;
&lt;p&gt;Join tables are the most common way to store many-to-many relationships.  These tables typically just contain the IDs of both tables and the standard columns.  Sometimes, there may be some additional meta data.  But that is up to how they are being used.&lt;/p&gt;

&lt;p&gt;Another option that works for attribute tables that have a relatively small number of records is to use &lt;strong&gt;bit masks&lt;/strong&gt;.  To use a bit mask:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Create your attribute table as normal except for the addition of 1 column called ‘&lt;strong&gt;bitmask&lt;/strong&gt;’.&lt;/li&gt;
  &lt;li&gt;The value would start at 2 for the first row and then go up by the power of 2 from there.
    &lt;ul&gt;
      &lt;li&gt;An easy way to achieve this is to create a trigger that will set the column value = the product of ‘&lt;strong&gt;id&lt;/strong&gt;’ x 2 AFTER INSERT if possible.&lt;/li&gt;
      &lt;li&gt;The data type of the bitmask column should be an unsigned integer that is large enough to account for all of your records as the power of 2 increases.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Your main object table will then have a column called ‘&lt;strong&gt;FOREIGN-TABLE_bitmask&lt;/strong&gt;’ (eg. ‘&lt;strong&gt;language_bitmask&lt;/strong&gt;’).
    &lt;ul&gt;
      &lt;li&gt;To store the relationships, you will simply OR the languages bitmask values together and store that sum in the language_bitmask column.
        &lt;ul&gt;
          &lt;li&gt;Just a tip, you can simply add all of the values together and it will yield the same final number as OR-ing them all together.&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
      &lt;li&gt;To query the data (Example: pull product and language data), you would join language lang with product prod ON (prod.lang_bitmask &amp;amp; lang.bitmask = lang.bitmask).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The examples shown above are more pseudo code as I’m trying to not be database specific.  But you should be able to adapt them to your environment fairly easily.  Bitmasks cut down on the number of joins and will provide some performance improvements.  Just make sure the columns are indexed.&lt;/p&gt;

&lt;h3 id=&quot;warehousing&quot;&gt;Warehousing&lt;/h3&gt;
&lt;p&gt;One of the benefits of following these conventions and standards is that it will make the data very easy to be reported on and warehoused for Business Intelligence reporting and insights.  In order to tie data together from multiple applications and systems, a &lt;strong&gt;Data Warehouse&lt;/strong&gt; is used.  There are many different commercial solutions for this in existence (Cognos, Oracle BI, Tableau, …etc.).  However, they all basically store processed data in a database of their own.&lt;/p&gt;

&lt;p&gt;The database in a data warehouse will not be designed the same as the database used in an application.  Multiple queries per second are not as important as data integrity.  The structure is set up in a way to facilitate the generation of reports as fast as possible while still maintaining the integrity of the data.&lt;/p&gt;

&lt;h4 id=&quot;etl&quot;&gt;ETL&lt;/h4&gt;
&lt;p&gt;In order for the warehouse to collect data from many disparate systems, it uses what is called an &lt;strong&gt;ETL&lt;/strong&gt; process.  &lt;strong&gt;ETL&lt;/strong&gt; stands for &lt;strong&gt;E&lt;/strong&gt;xtract, &lt;strong&gt;T&lt;/strong&gt;ransform, &lt;strong&gt;L&lt;/strong&gt;oad.  Essentially, what it does in a basic sense is&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Pull data from the application database.&lt;/li&gt;
  &lt;li&gt;Transform the data or parse it so that it will fit into its schema and be able to be used with the data from the other systems.&lt;/li&gt;
  &lt;li&gt;Insert / Update records in the warehouse database with the newly transformed data.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;why-is-this-relevant&quot;&gt;Why Is This Relevant&lt;/h4&gt;
&lt;p&gt;The way that the ETL process determines what should be brought into the warehouse is based on multiple factors.  However, the main one is based on when data changes.  So columns like ‘created’ and ‘modified’ help to determine what records have changed since it last ran.  The ‘is_active’ column is used to help with letting the warehouse know when data is “deleted” (A soft delete).&lt;/p&gt;

&lt;p&gt;Having a consistent numerical id column allows the warehouse to tie back records to the records in the application database tables.  The warehouse will use its own IDs, but will need to be able to keep track of changes in the application.  And the ID column is the best one to use.&lt;/p&gt;

&lt;h3 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;This article is a general guideline for schema design and is intended to be a starting point for application database design.  It should be extended and altered where necessary.  Following these guidelines will help to build a solid foundation for any application.  I hope this has been informative and/or thought provoking.&lt;/p&gt;

&lt;p&gt;Thanks for reading.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>How We Do CSS at Zumba</title>
   <summary>This is how we do CSS at Zumba.</summary>
   <link href="http://tech.zumba.com/2015/03/31/how-we-do-css//"/>
   <author>
	<name>Kaue Ribeiro</name>
	<email>kaue.ribeiro@zumba.com</email>
   </author>
   <updated>2015-03-31T00:00:00+00:00</updated>
   <id>http://tech.zumba.com/2015/03/31/how-we-do-css</id>
   <content type="html">&lt;p&gt;As you may or may not know Zumba’s website consists of a robust app that includes a fully custom ecommerce shop that supports international transactions, class and training search and registration, Zumba Instructor Network (ZIN) admin portal and many other apps. Our in-house tech department is responsible for managing the interactive products, developing, testing and deploying the projects.&lt;/p&gt;

&lt;p&gt;I was inspired by the teams at &lt;a href=&quot;http://dev.ghost.org/css-at-ghost/&quot; target=&quot;_blank&quot;&gt;Ghost&lt;/a&gt; and &lt;a href=&quot;https://github.com/styleguide/css&quot; target=&quot;_blank&quot;&gt;Github&lt;/a&gt; to write this article to give you an idea of how we do CSS at Zumba.&lt;/p&gt;

&lt;h3 id=&quot;intro---browser-and-device-support&quot;&gt;Intro - Browser and Device Support&lt;/h3&gt;
&lt;p&gt;We try to keep our code as light, modular and DRY as possible. We use Modernizr, Autoprefixer and some Foundation components. We try to keep our nesting no more than 4 levels deep and we try to make sure that  our naming convention lends itself to reusable components.&lt;/p&gt;

&lt;p&gt;We support the last few versions of popular browsers (Chrome, Safari and Firefox). At the time of writing this we currently support IE 8+. About 2% of our users still use IE 8; we are not out of the woods yet.&lt;/p&gt;

&lt;p&gt;We made the leap to a responsive application with our recent redesign of the site. Therefore, we support a wide range of desktop, tablet and mobile devices. At the time of writing this we don’t currently support smart watches. We will soon, though… so, “watch” out for that… sorry.&lt;/p&gt;

&lt;h3 id=&quot;preprocessor&quot;&gt;Preprocessor&lt;/h3&gt;
&lt;p&gt;We use Sass with Compass as our preprocessor. Our team is proficient and has much training on this popular pre-processor and it’s large following helps.&lt;/p&gt;

&lt;h3 id=&quot;foldersandwich-structure&quot;&gt;Folder/Sandwich Structure&lt;/h3&gt;
&lt;p&gt;Here’s the fun stuff - we structured our css based on a few important factors:&lt;/p&gt;

&lt;h4 id=&quot;modularity-and-reusability&quot;&gt;+ Modularity and Reusability&lt;/h4&gt;
&lt;p&gt;Develop components that can be reused throughout the application.&lt;/p&gt;

&lt;h4 id=&quot;css-rules&quot;&gt;+ CSS Rules&lt;/h4&gt;
&lt;p&gt;Consider the size of the compiled stylesheets per section of the site to not exceed IE9’s rules limit of 4,095. Our previous site was compiled into two massive stylesheets and we learned the hard way. We currently break it down per section of the site. See examples below.&lt;/p&gt;

&lt;h4 id=&quot;light-stylesheets&quot;&gt;+ Light stylesheets&lt;/h4&gt;
&lt;p&gt;Keeping the stylesheet declaration low kills two birds with one stone. We break the stylesheets down into individual sheets that contain only the rules for each section of the site—this has the added benefit of avoiding unnecessary or redundant styles per section. Doing this helps us keep our stylesheets light.&lt;/p&gt;

&lt;p&gt;Can I have my sandwich with a side of css?
Zumba is a happy and energetic fitness lifestyle company. That doesn’t mean we can’t have our sandwich and eat it too. We decided to structure our css like a sandwich order.&lt;/p&gt;

&lt;div&gt;&lt;img src=&quot;/img/blog/sandwich-breakdown.jpg&quot; alt=&quot;sandwich&quot; class=&quot;img-responsive&quot; /&gt;&lt;/div&gt;

&lt;h4 id=&quot;plate&quot;&gt;Plate&lt;/h4&gt;
&lt;p&gt;The plate represents the foundation of the code and is reused throughout the site.
Example:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;plate
|— _angular.scss
|— _animations.scss
|— _fonts.scss
|— _icons.scss
|— _mixins.scss
|— _typography.scss
|— _variables.scss
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;h4 id=&quot;toppings&quot;&gt;Toppings&lt;/h4&gt;
&lt;p&gt;These can be added to your sandwich to make it as delicious as you want it. These consist of mini components that can be reused throughout the site, but is not necessary for every page.
Example:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;toppings
|— _button.scss
|— _input.scss
|— _shares.scss
|— _tooltip.scss
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;h4 id=&quot;sandwich&quot;&gt;Sandwich&lt;/h4&gt;
&lt;p&gt;These nom noms can contain a combination of toppings to make a complete sandwich or component. These are usually a bit more complex and a little more specific. Sandwiches can be used throughout the entire site and can be customized per section of the site to meet that section’s needs or requirements.
Example:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sandwich
|— _accordion.scss
|— _featured.scss
|— _form.scss
|— _hero-slider.scss
|— _modal.scss
|— _pagination.scss
|— _rangeslider.scss
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;h4 id=&quot;example-of-our-overall-structure&quot;&gt;Example of our overall structure:&lt;/h4&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;assets-build/css-blt
|— checkout/
|— classes/
|— consumer/
|— header-footer/
|— plate/
|— sandwiches/
|— shop/
|— toppings/
|— _settings.scss
|— classes.scss
|— consumer.scss
|— header-footer.scss
|— main.scss
|— shop.scss
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;h4 id=&quot;mainscss---consists-of-the-basics-of-our-pages-layout&quot;&gt;main.scss - Consists of the basics of our pages’ layout.&lt;/h4&gt;

&lt;script src=&quot;https://gist.github.com/neptunz/0d6bfe832eb85b6e73a7.js&quot;&gt;&lt;/script&gt;

&lt;h3 id=&quot;css-structure&quot;&gt;CSS structure&lt;/h3&gt;
&lt;p&gt;This is an example of how we expect our stylesheets to be laid out. This is not an actual file.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/neptunz/6b55d2e0db2d0190c540.js&quot;&gt;&lt;/script&gt;

&lt;ul&gt;
  &lt;li&gt;Each file is named after the page or the page module it supports&lt;/li&gt;
  &lt;li&gt;We never style ID’s only Classes&lt;/li&gt;
  &lt;li&gt;Keep nesting down to a minimum and no deeper than 4 levels including pseudo selectors&lt;/li&gt;
  &lt;li&gt;Group related properties wherever possible&lt;/li&gt;
  &lt;li&gt;Media queries go after properties and the order should reflect mobile first&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;naming&quot;&gt;Naming&lt;/h3&gt;

&lt;h4 id=&quot;variables-and-mixins&quot;&gt;Variables and Mixins&lt;/h4&gt;
&lt;p&gt;Our variables and mixing naming is pretty specific in order to avoid any confusion. We have been here long enough to understand that the company likes to make simple to drastic changes to support the business in general. We have to develop keeping scalability in mind and this variable/mixin strategy just makes more sense for us.&lt;/p&gt;

&lt;h4 id=&quot;mixin&quot;&gt;Mixin&lt;/h4&gt;

&lt;script src=&quot;https://gist.github.com/neptunz/65b4c6cc19a4c4ad2fd6.js&quot;&gt;&lt;/script&gt;

&lt;h4 id=&quot;color-variables&quot;&gt;Color Variables&lt;/h4&gt;

&lt;script src=&quot;https://gist.github.com/neptunz/c473d1fb7056fb22ef46.js&quot;&gt;&lt;/script&gt;

&lt;h4 id=&quot;classes&quot;&gt;Classes&lt;/h4&gt;
&lt;p&gt;Our preferred technique is a more descriptive naming convention over deep nesting.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/neptunz/2c49168fb55be1cbbd25.js&quot;&gt;&lt;/script&gt;

&lt;h4 id=&quot;media-queries&quot;&gt;Media Queries&lt;/h4&gt;
&lt;p&gt;For the most part we target based on viewport width. We have a feature or two that depends on the detection of touch. We stick to three basic breakpoints and rarely make exceptions for custom breakpoints. We don’t want to compromise code quality to consider every viewport width consideration.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/neptunz/b1467ce5f11c61b22297.js&quot;&gt;&lt;/script&gt;

&lt;h4 id=&quot;typography&quot;&gt;Typography&lt;/h4&gt;

&lt;script src=&quot;https://gist.github.com/neptunz/d2ce9353c6f1025922df.js&quot;&gt;&lt;/script&gt;

&lt;h4 id=&quot;linting&quot;&gt;Linting&lt;/h4&gt;
&lt;p&gt;Currently our linting consists of pull request code reviews. This is what we look for:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Levels of nesting&lt;/li&gt;
  &lt;li&gt;Indentation&lt;/li&gt;
  &lt;li&gt;Flag the use of ID’s&lt;/li&gt;
  &lt;li&gt;Spacing after selectors and properties&lt;/li&gt;
  &lt;li&gt;Formatting of properties&lt;/li&gt;
  &lt;li&gt;Code that’s commented out&lt;/li&gt;
  &lt;li&gt;Formatting of selectors - lowercase and hyphened preferred&lt;/li&gt;
  &lt;li&gt;Null values should be 0 or none instead of 0px&lt;/li&gt;
  &lt;li&gt;Use of color names should use variables&lt;/li&gt;
  &lt;li&gt;Duplicate selectors or properties&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;the-fun-never-ends&quot;&gt;The fun never ends&lt;/h4&gt;
&lt;p&gt;This post and our style guide that is soon to come will never be a done deal written in stone. What we build today is cutting edge and future proof until the future is now and we realize how crazy we were when we developed using archaic methods and tools. The tech world moves at an insane pace and that’s what makes our job fun. New technologies will emerge and we will use them to make our applications and our lives as developers better. Therefore, this is relevant for the time being and I hope that it covers us for a very long time, but we all can’t be surprised if we have to come back and revise this to support new new. Until then, we will enjoy this sandwich.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Zumba&lt;sup&gt;&amp;reg;&lt;/sup&gt; Technology Day</title>
   <summary>We are looking for a few good engineers to help us achieve our technical vision.</summary>
   <link href="http://tech.zumba.com/2014/12/30/zumba-tech-day//"/>
   <author>
	<name>Julian Castaneda</name>
	<email>julian.castaneda@zumba.com</email>
   </author>
   <updated>2014-12-30T00:00:00+00:00</updated>
   <id>http://tech.zumba.com/2014/12/30/zumba-tech-day</id>
   <content type="html">&lt;p&gt;Let me start out by saying, that before I started working here at Zumba&lt;sup&gt;®&lt;/sup&gt;, my perception of companies that were not “tech companies” was completely wrong. I was very naive, and thought that ‘those’ companies did not have the correct culture to nurture and expand my career as a software engineer. Not all companies are the same, but at least there are some companies, such as Zumba&lt;sup&gt;®&lt;/sup&gt; that strongly believe in technology. Our team is constantly innovating, and we are on top of the latest technology. Don’t believe me? Here is some inside knowledge about our Zumba&lt;sup&gt;®&lt;/sup&gt; Technology Day.&lt;/p&gt;

&lt;p&gt;Nowadays, a lot of the big tech companies have some sort of program that incentivizes it’s employees to tinker with ideas that are not part of their assigned work. Apparently this concept was &lt;a href=&quot;http://www.fastcodesign.com/1663137/how-3m-gave-everyone-days-off-and-created-an-innovation-dynamo&quot;&gt;started by 3m&lt;/a&gt; and then was made famous by Google with their  “20 percent program”, in which employees get 20% of their time to work on side projects or ideas. Following in their footsteps, we decided to implement a similar program in-house called “Zumba&lt;sup&gt;®&lt;/sup&gt; Technology Day”, where the technology department gets at least one day a month (usually the last Thursday of the month) to actually experiment and come up with new ideas that can benefit the company.&lt;/p&gt;

&lt;p&gt;The way our tech day works is pretty simple. It started simply with a google doc that we used as master list of ideas that anyone at anytime could go in and update. Over time, we refined the process to a Kanban project in Jira. This change made it easier to maintain and team members can now take ownership of what they want to work on and invite other team members to contribute. Note that we do not force anyone to use the google doc or the Jira project. In fact, we only have 2 actual rules:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The only interrupts that will be taken are business critical interrupts.&lt;/li&gt;
  &lt;li&gt;The Technology team must work on something that stabilizes our current systems or designs for the future. This includes documenting what we now have, designing a future vision, prototyping something that will help solve a business problem, documenting an improvement to the development process, automating tests, writing scripts, bashing a bunch of pet peeve bugs, researching an alternative technology,  or the like.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It’s been a year and half since we established the Zumba&lt;sup&gt;®&lt;/sup&gt; Technology Day in our department and during this time it has proven to be a success. Not only some of the ideas/projects that we have implemented started with a tech day and became actual projects that are now vital part of our company, but it has also allowed us to have a day where we can interact with each other in a different setting. We have created a work setting that we can work without the pressure of a deadline and restrictions from the business- It’s our time to be creative!&lt;/p&gt;

&lt;p&gt;If you have been missing working with exciting technologies and experienced engineers on solutions to complex problems, then &lt;a href=&quot;http://tech.zumba.com/careers.html&quot;&gt;Join the team&lt;/a&gt;! We have several openings for software engineers and frontend developers.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Caching CakePHP 2.x routes</title>
   <summary>Tutorial of how to cache the CakePHP 2.x routes.</summary>
   <link href="http://tech.zumba.com/2014/10/26/cakephp-caching-routes//"/>
   <author>
	<name>Juan Basso</name>
	<email>juan.basso@zumba.com</email>
   </author>
   <updated>2014-10-26T00:00:00+00:00</updated>
   <id>http://tech.zumba.com/2014/10/26/cakephp-caching-routes</id>
   <content type="html">&lt;p&gt;At Zumba we are continuously looking for optimization in our applications. These optimizations help
to reduce the server loads, consequently reducing the number of servers and saving money. Besides
that, it gives a better user experience for the end user by serving content
faster and in some cases saving on consumer bandwidth (specially for mobile users).&lt;/p&gt;

&lt;p&gt;This week we profiled our app using &lt;a href=&quot;http://www.xdebug.org/docs/profiler&quot;&gt;Xdebug profiler&lt;/a&gt; and we
identified the router was responsible for a big part of the request time. In our main app we use over 130
custom routes which makes CakePHP generate an object for each route, and consequently parse and generate
a regex for each route. This takes significant time and many function calls to do it.&lt;/p&gt;

&lt;p&gt;In order to optimize the routing time, we started looking at options to optimize our routing process. After
some research and deep checking in our codebase as well as CakePHP’s code, we found we could cache the routes easily.
The solution we found is easily applicable for many other CakePHP applications. Basically it consists
of exporting the compiled routes into a file and loading it instead of connecting them on every
request to the Router. This strategy is similar of how &lt;a href=&quot;https://github.com/nikic/FastRoute/blob/v0.2.0/src/functions.php#L32-L61&quot;&gt;FastRoute&lt;/a&gt;
caches their routes.&lt;/p&gt;

&lt;p&gt;First, we moved all the &lt;code class=&quot;highlighter-rouge&quot;&gt;Router::connect()&lt;/code&gt; to another file called &lt;code class=&quot;highlighter-rouge&quot;&gt;routes.connect.php&lt;/code&gt;. On the &lt;code class=&quot;highlighter-rouge&quot;&gt;routes.php&lt;/code&gt;
we added the logic for the caching. In the end, we ended up with something like this:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/jrbasso/37a6938b752b726b0a32.js?file=routes.connect.php&quot;&gt; &lt;/script&gt;

&lt;script src=&quot;https://gist.github.com/jrbasso/37a6938b752b726b0a32.js?file=routes.php&quot;&gt; &lt;/script&gt;

&lt;p&gt;We had a couple options here. For example, we used &lt;code class=&quot;highlighter-rouge&quot;&gt;var_export&lt;/code&gt; instead of &lt;code class=&quot;highlighter-rouge&quot;&gt;serialize&lt;/code&gt;. It changes how the
application caches the file and adds some extra steps to the process. Using &lt;code class=&quot;highlighter-rouge&quot;&gt;serialize&lt;/code&gt; you can just cache
in memory (using some cache engine like APC), avoiding writing routes to the disk and avoiding to change
the default route class.&lt;/p&gt;

&lt;p&gt;We chose to use &lt;code class=&quot;highlighter-rouge&quot;&gt;var_export&lt;/code&gt; and dump the output to a file because it allows PHP to opcache the file,
avoiding to re-parse everything again on every request. Using &lt;code class=&quot;highlighter-rouge&quot;&gt;serialize&lt;/code&gt; it generate a string that needs
to be parsed and executed on every request. Depending of your app and the number of routes that you have,
the use of &lt;code class=&quot;highlighter-rouge&quot;&gt;serialize&lt;/code&gt; is simpler and faster than &lt;code class=&quot;highlighter-rouge&quot;&gt;var_export&lt;/code&gt;. Give both approaches a try and compare
the performance between them.&lt;/p&gt;

&lt;p&gt;Using &lt;code class=&quot;highlighter-rouge&quot;&gt;var_export&lt;/code&gt; brings some consequences, which is the requirement of implementing the magic method
&lt;code class=&quot;highlighter-rouge&quot;&gt;__set_state&lt;/code&gt;. This method is not implemented in CakePHP core until the version 2.6. I opened the PR
&lt;a href=&quot;https://github.com/cakephp/cakephp/pull/4953&quot;&gt;cakephp/cakephp#4953&lt;/a&gt; to support it on CakePHP 2.6+.
So, to solve this problem in CakePHP prior to 2.6 we created a class that extends Cake’s &lt;code class=&quot;highlighter-rouge&quot;&gt;CakeRoute&lt;/code&gt;
to implement the magic method and this looks like it:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/jrbasso/37a6938b752b726b0a32.js?file=ZumbaRoute.php&quot;&gt; &lt;/script&gt;

&lt;p&gt;&lt;i&gt;PS: This code is not compatible with PHP 5.2. If you are using PHP 5.2, stop everything and upgrade
your PHP version.&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;With this class and changing the default route class in the &lt;code class=&quot;highlighter-rouge&quot;&gt;routes.php&lt;/code&gt; you can cache the routes
using &lt;code class=&quot;highlighter-rouge&quot;&gt;var_export&lt;/code&gt;. If you have plugins with routes, you may need to do some additional changes.
If you have plugins but these plugins doesn’t have any route, Cake automatically create a route to it using
the &lt;code class=&quot;highlighter-rouge&quot;&gt;PluginShortRoute&lt;/code&gt; (which also doesn’t implement the magic method). It means you probably will
have to remove these classes from your routes before build the cache. Knowing these limitations you
can also workaround this type of issue by creating another extended classes.&lt;/p&gt;

&lt;p&gt;If you are wondering why we create a temporary file and rename it to the final filename it is to avoid
a concurrency issue between one request writing the file and another request reading the file at the
same time. It could be avoided by using file lock, but it would stop all concurrent requests
until the cache is finally done and stored on the disk. Using a temporary file and renaming it
is an atomic operation, so it is avoided. Thanks &lt;a href=&quot;http://josediazgonzalez.com/about/&quot;&gt;Jose Diaz Gonzalez&lt;/a&gt;
(&lt;a href=&quot;https://twitter.com/savant&quot;&gt;@savant&lt;/a&gt;) for pointing it out.&lt;/p&gt;

&lt;p&gt;We used the &lt;code class=&quot;highlighter-rouge&quot;&gt;sha1_file()&lt;/code&gt; function to clear any kind of cache when a route is changed in &lt;code class=&quot;highlighter-rouge&quot;&gt;routes.connect.php&lt;/code&gt;.
Everytime you change the file, the SHA1 of the file will change
and consequently it will generate another cache file. This allows the cached file to regenerate for
seamless deployments where routes where changed.&lt;/p&gt;

&lt;p&gt;I would like to present some numbers of these changes, but it is very subjective because it depends a
lot from the hardware (specially the disk), the number and type of routes, etc. What I can say is
for our case the time to load the routes are half of the time from connecting on every request and
to generate an URL using &lt;code class=&quot;highlighter-rouge&quot;&gt;Router::url()&lt;/code&gt; (or via some helper/controller) it is four times faster on
the first route that hits the last route (usually the generic one from Cake).&lt;/p&gt;

&lt;p&gt;One interesting thing we found on the tests were that loading the cached file and routing to the
first route was faster than connecting all the routes via &lt;code class=&quot;highlighter-rouge&quot;&gt;Router::connect()&lt;/code&gt; and matching the first
route (which just compile one route).&lt;/p&gt;

&lt;p&gt;In summary, the changes to cache the routes are small for most of the applications. There is
different approaches that you have to test and decide which one fits better for your application.
Also, some limitations could block your cache, but most likely there is a workaround for it. If you
can’t find one, contact me and I can try to help you.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Developing With AngularJS? Forget jQuery Exists.</title>
   <summary>Understanding how jQuery's power and familiarity can unintentionally subvert AngularJS' goals.</summary>
   <link href="http://tech.zumba.com/2014/08/02/angularjs-forget-jquery//"/>
   <author>
	<name>Stephen Young</name>
	<email>stephen.young@zumba.com</email>
   </author>
   <updated>2014-08-02T00:00:00+00:00</updated>
   <id>http://tech.zumba.com/2014/08/02/angularjs-forget-jquery</id>
   <content type="html">&lt;p&gt;Before I begin, take a moment to remember how hard our lives were before &lt;a href=&quot;http://jquery.com/&quot;&gt;jQuery&lt;/a&gt; ironed out the treacherous wrinkles of cross-browser development.  Client-side Javascript is to jQuery as mammals are to sharks with frickin’ laser beams attached to their heads.  &lt;strong&gt;Zumba® Tech&lt;/strong&gt; engineers are big fans of jQuery.&lt;/p&gt;

&lt;p&gt;Now, if you are writing an AngularJS application, do us all a favor and &lt;strong&gt;forget jQuery exists&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Here’s the rub — the power of simple jQuery scripts can sometimes be incongruent with the goals and maintainability of an &lt;a href=&quot;https://angularjs.org/&quot;&gt;AngularJS&lt;/a&gt; application.  jQuery is a library with a lot going on under the hood, but it is primarily used for these things:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Performing AJAX operations&lt;/li&gt;
  &lt;li&gt;Animating HTML elements&lt;/li&gt;
  &lt;li&gt;Handling browser events&lt;/li&gt;
  &lt;li&gt;Querying, traversing, and manipulating the DOM&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;There are caveats when using jQuery to execute &lt;em&gt;any&lt;/em&gt; the above actions within an AngularJS app, but this post is focused on the last two:  Events and DOM interactions.&lt;/p&gt;

&lt;h2 id=&quot;separation-of-concerns&quot;&gt;Separation of Concerns&lt;/h2&gt;
&lt;p&gt;Querying for CSS selectors is very difficult to do without implicitly tying your code to the DOM; it’s nigh impossible.  This can lead to brittle code in the long run.  For example, when you write &lt;code class=&quot;highlighter-rouge&quot;&gt;$('.soso')&lt;/code&gt; you create an implied contract that the HTML template will contain an element with the &lt;code class=&quot;highlighter-rouge&quot;&gt;soso&lt;/code&gt; class.  If you later remove the &lt;code class=&quot;highlighter-rouge&quot;&gt;soso&lt;/code&gt; class and add a new &lt;code class=&quot;highlighter-rouge&quot;&gt;awesome&lt;/code&gt; class to the element, you have broken the contract and the Javascript may stop working.&lt;/p&gt;

&lt;p&gt;At a fundamental level, the principle of separation of concerns was violated.  The &lt;code class=&quot;highlighter-rouge&quot;&gt;soso&lt;/code&gt; class was given &lt;em&gt;meaning&lt;/em&gt; outside of its implied styling.  Worse still, nothing in the HTML template indicated that the &lt;code class=&quot;highlighter-rouge&quot;&gt;soso&lt;/code&gt; class was more than just a boring presentational element of the page.&lt;/p&gt;

&lt;p&gt;DOM traversal is also problematic.  For example, using jQuery you can query for a specific element, get that element’s siblings, find any links that are children of those siblings, and bind a click event to those links.  This kind of script is easy to write, but it is tied to the structure of the template.  Adding or removing DOM elements in the hierarchy can very easily break the script.&lt;/p&gt;

&lt;h2 id=&quot;manually-querying-the-dom-is-like-writing-sql&quot;&gt;Manually Querying the DOM Is Like Writing SQL&lt;/h2&gt;
&lt;p&gt;Here’s some pseudo code for you.  Use your imagination.&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;SELECT DOMElement FROM document WHERE document.id = &quot;#navBar&quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;This is conceptually equivalent to writing &lt;code class=&quot;highlighter-rouge&quot;&gt;$('#navBar')&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Querying the DOM is a low level task that is akin to writing SQL statements.  You would never sprinkle SQL statements around your backend codebase, so why do the same thing inside your AngularJS directives?&lt;/p&gt;

&lt;h2 id=&quot;indigestion&quot;&gt;Indigestion&lt;/h2&gt;
&lt;p&gt;One of the awesome features of AngularJS is &lt;a href=&quot;https://docs.angularjs.org/guide/databinding&quot;&gt;two way data binding&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Any changes to the view are immediately reflected in the model, and any changes in the model are propagated to the view.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;AngularJS periodically loops over the properties of the “model” and updates the DOM if the data has changed.  This is called the $digest cycle.  When you use &lt;code class=&quot;highlighter-rouge&quot;&gt;ngClick&lt;/code&gt; or &lt;code class=&quot;highlighter-rouge&quot;&gt;scope.$watch&lt;/code&gt;, or even the &lt;code class=&quot;highlighter-rouge&quot;&gt;$timeout&lt;/code&gt; service, AngularJS will automatically kick-off a $digest cycle for you.&lt;/p&gt;

&lt;p&gt;However, when you manually bind click events via &lt;code class=&quot;highlighter-rouge&quot;&gt;$(element).on()&lt;/code&gt;, AngularJS is not aware of those event handlers.  Data in the model could be updated, but the view will likely remain stale.  You could manually call &lt;code class=&quot;highlighter-rouge&quot;&gt;scope.$digest&lt;/code&gt; or &lt;code class=&quot;highlighter-rouge&quot;&gt;scope.$apply&lt;/code&gt;, but this quickly becomes messy and bug-prone.  If you use lots of manual $digest calls, you are bound to start getting AngularJS errors about trying to start a digest cycle when one is already in progress.  Trust me.&lt;/p&gt;

&lt;h2 id=&quot;refactoring-a-problematic-directive&quot;&gt;Refactoring a Problematic Directive&lt;/h2&gt;
&lt;p&gt;Breaking away from the jQuery methodology is hard.  I figure that the best way to illustrate these concepts is by example. So, I’ve cooked up a brittle, jQuery-style directive that I’m going to refactor into a resilient, reusable “AngularJS Way” component.&lt;/p&gt;

&lt;h3 id=&quot;the-template&quot;&gt;The Template&lt;/h3&gt;

&lt;script src=&quot;https://gist.github.com/young-steveo/29dec391126238005e5e.js?file=a.html&quot;&gt;&lt;/script&gt;

&lt;p&gt;Let’s say we want the content paragraphs to toggle visibility when the user clicks on the corresponding links in the list, and we want the &lt;code class=&quot;highlighter-rouge&quot;&gt;li&lt;/code&gt; elements to indicate the active paragraph.  The following directive gets the job done.&lt;/p&gt;

&lt;h3 id=&quot;the-brittle-directive&quot;&gt;The Brittle Directive&lt;/h3&gt;

&lt;script src=&quot;https://gist.github.com/young-steveo/29dec391126238005e5e.js?file=a.js&quot;&gt;&lt;/script&gt;

&lt;p&gt;The above code is somewhat clean on the surface, but there are a lot of implied dependencies on the DOM.  For example, the directive will only work if the links remain children of &lt;code class=&quot;highlighter-rouge&quot;&gt;li&lt;/code&gt; tags.  The directive will break if the DOM is modified to put the links inside of a &lt;code class=&quot;highlighter-rouge&quot;&gt;div&lt;/code&gt; or &lt;code class=&quot;highlighter-rouge&quot;&gt;p&lt;/code&gt; tag.&lt;/p&gt;

&lt;p&gt;Every time a link is clicked, the code traverses the DOM.  That’s expensive in a large system.  It could be refactored to cache the DOM traversal, but doing this introduces a new dependency on the state of the DOM.  For example:  What if some of the HTML gets changed to be inserted dynamically?  Suddenly the variables will be empty at linking time, yet again breaking the directive.  Event delegation mitigates this, but we still don’t solve the problem of hidden functionality.  When examining the HTML, it is not clear that there is behavior attached to the links and paragraphs.&lt;/p&gt;

&lt;h3 id=&quot;use-the-scope&quot;&gt;Use the Scope&lt;/h3&gt;
&lt;p&gt;We need to divorce the data/state from the template’s attributes and classes.  To do that we can introduce &lt;code class=&quot;highlighter-rouge&quot;&gt;ngClass&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;ngClick&lt;/code&gt;, and &lt;code class=&quot;highlighter-rouge&quot;&gt;ngIf&lt;/code&gt; to the template. We can then keep track of the links’ states inside the directive scope, and leave the DOM manipulation to Angular.&lt;/p&gt;

&lt;h3 id=&quot;the-new-and-improved-template-amp-directive&quot;&gt;The New and Improved Template &amp;amp; Directive&lt;/h3&gt;
&lt;script src=&quot;https://gist.github.com/young-steveo/29dec391126238005e5e.js?file=c.html&quot;&gt;&lt;/script&gt;

&lt;script src=&quot;https://gist.github.com/young-steveo/29dec391126238005e5e.js?file=c.js&quot;&gt;&lt;/script&gt;

&lt;ol&gt;
  &lt;li&gt;There are no dependencies on the DOM at all.  It’s just a directive that wraps an object called &lt;code class=&quot;highlighter-rouge&quot;&gt;scope.active&lt;/code&gt; that contains some boolean values.  The booleans get flipped on and off when the &lt;code class=&quot;highlighter-rouge&quot;&gt;select&lt;/code&gt; function is called. This directive is relatively immune to DOM updates.  You could change all of the classes in the template; you could delete and add new HTML; you could change &lt;code class=&quot;highlighter-rouge&quot;&gt;a&lt;/code&gt; tags into &lt;code class=&quot;highlighter-rouge&quot;&gt;div&lt;/code&gt; tags or &lt;code class=&quot;highlighter-rouge&quot;&gt;p&lt;/code&gt; tags into &lt;code class=&quot;highlighter-rouge&quot;&gt;span&lt;/code&gt; tags.  &lt;strong&gt;Nothing will break in the JS file&lt;/strong&gt;.  There are no classes being toggled in the directive.  If a developer decides to change the classes on the &lt;code class=&quot;highlighter-rouge&quot;&gt;li&lt;/code&gt; elements from &lt;code class=&quot;highlighter-rouge&quot;&gt;active&lt;/code&gt; to &lt;code class=&quot;highlighter-rouge&quot;&gt;awesomesauce&lt;/code&gt;, &lt;em&gt;everything still works&lt;/em&gt;. This is awesome.&lt;/li&gt;
  &lt;li&gt;There is no DOM traversal happening at all.  This is awesome; and it’s fast.&lt;/li&gt;
  &lt;li&gt;Looking at the HTML reveals how this widget works.  It is declarative, which is awesome. (there’s a theme here)&lt;/li&gt;
  &lt;li&gt;Since all of the click operations are handled by &lt;code class=&quot;highlighter-rouge&quot;&gt;ngClick&lt;/code&gt;, everything will remain inside the digest cycle, and I don’t have to use &lt;code class=&quot;highlighter-rouge&quot;&gt;scope.$apply&lt;/code&gt; anywhere.  It will just work.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;jquery-under-the-hood&quot;&gt;jQuery Under the Hood&lt;/h3&gt;
&lt;p&gt;AngularJS ships with &lt;a href=&quot;https://docs.angularjs.org/api/ng/function/angular.element&quot;&gt;jqLite&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;jqLite is a tiny, API-compatible subset of jQuery that allows Angular to manipulate the DOM in a cross-browser compatible way. jqLite implements only the most commonly needed functionality with the goal of having a very small footprint.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The interesting thing here is that Angular uses jqLite to perform DOM manipulation such as adding and removing classes for the &lt;code class=&quot;highlighter-rouge&quot;&gt;ngClass&lt;/code&gt; directive.  This allows &lt;code class=&quot;highlighter-rouge&quot;&gt;ngClass&lt;/code&gt; and other built-in directives to be an abstraction that separates the queries from your code.&lt;/p&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;
&lt;p&gt;jQuery is a badass tool for scripting interactions with the DOM.  It’s a &lt;strong&gt;global&lt;/strong&gt; hammer that you can whip out anywhere in the code and smash out your feature on the spot.  This is awesome, but it leads to brittle, non-reusable, hard to maintain code (inside AngularJS, at least).&lt;/p&gt;

&lt;h4 id=&quot;tldr&quot;&gt;TL;DR&lt;/h4&gt;
&lt;p&gt;When trying to solve a problem or add functionality to an AngularJS app, start by forgetting about jQuery solutions.  Reach for directives like &lt;code class=&quot;highlighter-rouge&quot;&gt;ngClick&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;ngClass&lt;/code&gt;.  Doing so will likely result in a more elegant solution.&lt;/p&gt;

</content>
 </entry>
 
 <entry>
   <title>Enforce code standards with composer, git hooks, and phpcs</title>
   <summary>Reduce number of back-and-forths in pull requests by enforcing code quality at the commit level.</summary>
   <link href="http://tech.zumba.com/2014/04/14/control-code-quality//"/>
   <author>
	<name>Chris Saylor</name>
	<email>christopher.saylor@zumba.com</email>
   </author>
   <updated>2014-04-14T00:00:00+00:00</updated>
   <id>http://tech.zumba.com/2014/04/14/control-code-quality</id>
   <content type="html">&lt;p&gt;Maintaining code quality on projects where there are many developers contributing
is a tough assignment. How many times have you tried to contribute to an open-source project
only to find the maintainer rejecting your pull request on the grounds of some invisible coding
standard? How many times as a maintainer of an open-source project (or internal) have you had a
hard time reading code because there were careless tabs/spaces mixed, &lt;code class=&quot;highlighter-rouge&quot;&gt;if&lt;/code&gt; statements with no brackets,
and other such things. Luckily there are tools that can assist maintainers. In this post,
I’ll be going over how to use &lt;a href=&quot;http://getcomposer.org&quot;&gt;composer&lt;/a&gt;, &lt;a href=&quot;http://git-scm.com/book/en/Customizing-Git-Git-Hooks&quot;&gt;git hooks&lt;/a&gt;, and &lt;a href=&quot;https://github.com/squizlabs/PHP_CodeSniffer&quot;&gt;phpcs&lt;/a&gt; to
enforce code quality rules.&lt;/p&gt;

&lt;p&gt;There are a couple of things to keep in mind. First, you want this process to be as simple as possible.
Secondly, you want it to be easy to run when necessary. Finally, you want
it to be universally accepted as part of your contribution procedure.&lt;/p&gt;

&lt;h3 id=&quot;there-is-no-catch&quot;&gt;There Is No Catch&lt;/h3&gt;

&lt;p&gt;What if I told you that it could be done without the developer even knowing it’s happening?&lt;/p&gt;

&lt;p&gt;Most modern PHP projects use composer as their dependency manager. Before you can make anything work, you need to run &lt;code class=&quot;highlighter-rouge&quot;&gt;composer install&lt;/code&gt;.
This is where the magic happens.&lt;/p&gt;

&lt;h3 id=&quot;phpcs-dependency&quot;&gt;Phpcs Dependency&lt;/h3&gt;

&lt;p&gt;First, we need a development dependency specified to install phpcs. It looks something like this:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&quot;require-dev&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;squizlabs/php_codesniffer&quot;&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;2.0.*@dev&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;h3 id=&quot;install-scripts&quot;&gt;Install Scripts&lt;/h3&gt;

&lt;p&gt;Composer has a handy schema entry called &lt;code class=&quot;highlighter-rouge&quot;&gt;scripts&lt;/code&gt;. It supports a script hook
&lt;code class=&quot;highlighter-rouge&quot;&gt;post-install-cmd&lt;/code&gt;. We will use this to install a git pre-commit hook. Adding to
our example above:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&quot;require-dev&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;squizlabs/php_codesniffer&quot;&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;2.0.*@dev&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&quot;scripts&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&quot;post-install-cmd&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
            &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;bash contrib/setup.sh&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;This will run a bash script called &lt;code class=&quot;highlighter-rouge&quot;&gt;setup.sh&lt;/code&gt; when the command &lt;code class=&quot;highlighter-rouge&quot;&gt;composer install&lt;/code&gt; is run.&lt;/p&gt;

&lt;h3 id=&quot;setup-the-git-pre-commit-hook&quot;&gt;Setup the Git Pre-commit Hook&lt;/h3&gt;

&lt;p&gt;In our &lt;code class=&quot;highlighter-rouge&quot;&gt;setup.sh&lt;/code&gt;, we will need to copy a &lt;code class=&quot;highlighter-rouge&quot;&gt;pre-commit&lt;/code&gt; script into the &lt;code class=&quot;highlighter-rouge&quot;&gt;.git/hooks&lt;/code&gt; directory:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;#!/bin/sh&lt;/span&gt;

cp contrib/pre-commit .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;This will copy our pre-commit script from the &lt;code class=&quot;highlighter-rouge&quot;&gt;contrib&lt;/code&gt; directory to the hooks section
of the special git directory and make it executable.&lt;/p&gt;

&lt;h3 id=&quot;create-the-pre-commit-hook&quot;&gt;Create the Pre-commit Hook&lt;/h3&gt;

&lt;p&gt;Whenever a contributing developer attempts to commit their code, it will run our &lt;code class=&quot;highlighter-rouge&quot;&gt;pre-commit&lt;/code&gt; script.
Now all we need to do is run the code sniffer rules on relavent files specific to this commit:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/cjsaylor/10503398.js&quot;&gt; &lt;/script&gt;

&lt;p&gt;This script will get the staged files of the commit, run a php lint check (always nice), and apply the
code sniffer rules to the staged files.&lt;/p&gt;

&lt;p&gt;If there is a code standards violation, the phpcs process will return a non-zero exit status which will
tell git to abort the commit.&lt;/p&gt;

&lt;h3 id=&quot;bringing-it-all-together&quot;&gt;Bringing it all together&lt;/h3&gt;

&lt;p&gt;With all of these things in place, the workflow is as follows:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Developer runs &lt;code class=&quot;highlighter-rouge&quot;&gt;composer install&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;PHP Code Sniffer is installed via a dev dependency.&lt;/li&gt;
  &lt;li&gt;The post-install command automatically copies the pre-commit hook into the developer’s local git hooks.&lt;/li&gt;
  &lt;li&gt;When the developer commits code, the pre-commit hook fires and checks the staged files for coding standards violations and lint checks.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is a relatively simple setup that can save pull request code reviews a significant amount of time preventing
back-and-forth on simple things such as mixed tabs/spaces, bracket placement, etc.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Asynchronous Control Flow with jQuery.Deferred</title>
   <summary>How to adapt callback structures to callback queues using deferred objects (promises).</summary>
   <link href="http://tech.zumba.com/2014/01/16/asynchronous-control-flow-jquery-deferred//"/>
   <author>
	<name>Stephen Young</name>
	<email>stephen.young@zumba.com</email>
   </author>
   <updated>2014-01-16T00:00:00+00:00</updated>
   <id>http://tech.zumba.com/2014/01/16/asynchronous-control-flow-jquery-deferred</id>
   <content type="html">&lt;p&gt;&lt;strong&gt;Zumba® Tech&lt;/strong&gt; is a big fan of javascript promises; they free our code from &lt;a href=&quot;http://callbackhell.com/&quot;&gt;callback hell&lt;/a&gt; by allowing us to use a more elegant and abstract structure.  With promises, asynchronous control flow becomes intuitive (first &lt;code class=&quot;highlighter-rouge&quot;&gt;a&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;b&lt;/code&gt;, then &lt;code class=&quot;highlighter-rouge&quot;&gt;c&lt;/code&gt;) and fun.  Today, I’ll show you how to adapt a third party library that uses callbacks to a promise interface.&lt;/p&gt;

&lt;h2 id=&quot;well-be-using-jquerydeferred&quot;&gt;We’ll be using jQuery.Deferred&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/cjsaylor&quot;&gt;Chris Saylor&lt;/a&gt; blogged about the node.js &lt;a href=&quot;http://engineering.zumba.com/2013/11/06/handling-asynchronism-with-promises/&quot;&gt;async module&lt;/a&gt; last November.  I’m going to focus on the client side for this post, but the principles apply to any environment.&lt;/p&gt;

&lt;p&gt;There are many great promise libraries:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/kriskowal/q&quot;&gt;Q&lt;/a&gt; — A tool for making and composing asynchronous promises&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/tildeio/rsvp.js&quot;&gt;RSVP.js&lt;/a&gt; — tools for organizing asynchronous code&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/cujojs/when&quot;&gt;when.js&lt;/a&gt; — the promise library from &lt;a href=&quot;http://cujojs.com/&quot;&gt;cujoJS&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There’s even a spec for &lt;a href=&quot;https://github.com/domenic/promises-unwrapping&quot;&gt;promises in ES6&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;However, until the native spec is fully supported we’ll be using jQuery.Deferred &lt;sup&gt;&lt;a href=&quot;#footnote1&quot;&gt; [1] &lt;/a&gt;&lt;/sup&gt; on the client.&lt;/p&gt;

&lt;h2 id=&quot;a-typical-scenario&quot;&gt;A Typical Scenario&lt;/h2&gt;
&lt;p&gt;We recently built a new internal app to handle some administrative tasks.  We used &lt;a href=&quot;http://getbootstrap.com/&quot;&gt;Bootstrap&lt;/a&gt; to get up and running quickly, and we stumbled upon a great library for handling our dialog boxes called &lt;a href=&quot;http://bootboxjs.com/&quot;&gt;bootbox.js&lt;/a&gt; from &lt;a href=&quot;https://github.com/makeusabrew&quot;&gt;Nick Payne&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Here is a typical snippet of code, straight from bootbox:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/young-steveo/a5ee77a20aa2073b8693.js&quot;&gt;&lt;/script&gt;

&lt;p&gt;With this code, bootbox will open a dialog containing the &lt;code class=&quot;highlighter-rouge&quot;&gt;&quot;Hello world!&quot;&lt;/code&gt; text.  The callback is fired after the user clicks on the &lt;code class=&quot;highlighter-rouge&quot;&gt;&quot;ok&quot;&lt;/code&gt; button and the &lt;code class=&quot;highlighter-rouge&quot;&gt;Example.show(&quot;Hello world callback&quot;);&lt;/code&gt; code is executed.&lt;/p&gt;

&lt;p&gt;This is already sweet, but soon we found ourselves writing a lot of boilerplate when we implemented the &lt;code class=&quot;highlighter-rouge&quot;&gt;confirm&lt;/code&gt; dialogs:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/young-steveo/4f31aa607868c1e4b5bc.js#file-bootbox-confirm-example-js&quot;&gt;&lt;/script&gt;

&lt;p&gt;That’s not overly messy, but handling these conditions in every confirmation dialog with inline callbacks didn’t appeal to us.&lt;/p&gt;

&lt;h2 id=&quot;wrapping-bootbox-with-an-adapter&quot;&gt;Wrapping Bootbox With an Adapter&lt;/h2&gt;
&lt;p&gt;First we created a new object that wraps the bootbox logic.  We called it &lt;strong&gt;Popper&lt;/strong&gt; (we’re not always clever with lib naming).&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/young-steveo/088f8cbd24b6d8da4368.js&quot;&gt;&lt;/script&gt;

&lt;h3 id=&quot;returning-a-deferred-object&quot;&gt;Returning a Deferred Object&lt;/h3&gt;
&lt;p&gt;The above snippet isn’t very impressive.  However, now that we have a wrapper we can adapt the bootbox interface to use a deferred object:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/young-steveo/767257dcc8f02afed149.js&quot;&gt;&lt;/script&gt;

&lt;p&gt;In effect, confirming the bootbox dialog will resolve the deferred object, and canceling the dialog will reject the deferred object.  Our implementation code now looks like this:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/young-steveo/2e738d200567bff63ea6.js&quot;&gt;&lt;/script&gt;

&lt;p&gt;This has a couple of advantages:
* There are no more messy &lt;code class=&quot;highlighter-rouge&quot;&gt;if&lt;/code&gt; blocks to parse; the code is more “flat”.
* We’ve changed the flow of the application from using a single, multipurpose callback into using separate callbacks with unique concerns.&lt;/p&gt;

&lt;h3 id=&quot;jqueryajax-returns-a-deferred&quot;&gt;jQuery.ajax returns a Deferred&lt;/h3&gt;
&lt;p&gt;There were many cases where we would fire off an ajax request after the user confirmed the dialog.  Since jQuery returns a deferred object from &lt;code class=&quot;highlighter-rouge&quot;&gt;$.ajax&lt;/code&gt;, we were able to envelop that logic into our adapter as well:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/young-steveo/ef94a5f5efaed5daafca.js&quot;&gt;&lt;/script&gt;

&lt;h2 id=&quot;a-few-steps-further&quot;&gt;A Few Steps Further&lt;/h2&gt;
&lt;p&gt;The above code is nice, but there are still a few outstanding issues:
* &lt;code class=&quot;highlighter-rouge&quot;&gt;.done&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;.fail&lt;/code&gt; are not very semantic method names for confirming or canceling a dialog.
* It would be nice to register callbacks that fire as soon as the buttons are clicked, and additional callbacks that fire after the ajax responds.&lt;/p&gt;

&lt;p&gt;To solve these issues, we created a map of semantic method names (&lt;code class=&quot;highlighter-rouge&quot;&gt;ok&lt;/code&gt; maps to &lt;code class=&quot;highlighter-rouge&quot;&gt;done&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;cancel&lt;/code&gt; maps to &lt;code class=&quot;highlighter-rouge&quot;&gt;fail&lt;/code&gt;, etc).  Popper’s methods return a new object that contains these semantic methods, making our implementation code look beautiful:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/young-steveo/20f935fd9648865b6969.js&quot;&gt;&lt;/script&gt;

&lt;h2 id=&quot;the-source&quot;&gt;The Source&lt;/h2&gt;
&lt;p&gt;Here’s a link to the &lt;a href=&quot;https://gist.github.com/young-steveo/8463120&quot;&gt;full Popper.js source&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;I hope I’ve expanded your toolbelt a little by showing you how to use a promise pattern in a real-world scenario.&lt;/p&gt;

&lt;p&gt;Do you like the Popper lib?  Leave us a comment!&lt;/p&gt;

&lt;p&gt;&lt;a name=&quot;footnote1&quot;&gt;[ 1 ]&lt;/a&gt; &lt;em&gt; We know that &lt;a href=&quot;http://api.jquery.com/category/deferred-object/&quot;&gt;jQuery.Deferred&lt;/a&gt; objects are not Promise/A+ compliant, and we sympathize with why that’s non-optimal.  However, since we are already using jQuery in most of our projects, jQuery.Deferred solves 95% of our needs without requiring us to depend on an additional library.&lt;/em&gt;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Introducing Json Serializer - An open source library to serialize to JSON</title>
   <summary>Serialize PHP content in JSON, with support to unserialization, even for objects.</summary>
   <link href="http://tech.zumba.com/2014/01/06/json-serializer//"/>
   <author>
	<name>Juan Basso</name>
	<email>juan.basso@zumba.com</email>
   </author>
   <updated>2014-01-06T00:00:00+00:00</updated>
   <id>http://tech.zumba.com/2014/01/06/json-serializer</id>
   <content type="html">&lt;p&gt;After the release of some of our libraries, such as &lt;a href=&quot;https://github.com/zumba/symbiosis&quot;&gt;Symbiosis&lt;/a&gt;,
&lt;a href=&quot;https://github.com/zumba/mongounit&quot;&gt;MongoUnit&lt;/a&gt; and &lt;a href=&quot;https://github.com/zumba/csv-policy&quot;&gt;CSV Policy&lt;/a&gt;,
we are proud to announce our newest open source project: &lt;a href=&quot;https://github.com/zumba/json-serializer&quot;&gt;Json Serializer&lt;/a&gt;.
The Json Serializer–as the name suggests–serializes content in JSON format. It is a very simple concept, but very
useful in some cases.&lt;/p&gt;

&lt;h3 id=&quot;use-case&quot;&gt;Use Case&lt;/h3&gt;

&lt;p&gt;Applications are becoming increasingly more complex, and companies are worried about their consumers. At Zumba we are no
different. Our ecommerce system handles thousands of consumers daily and we have many new features coming. Without
a decoupled and maintainable system we can’t grow very fast.&lt;/p&gt;

&lt;p&gt;In our shopping cart we implement some entity classes and some other classes to group the entities together. For example,
we have entities to represent the cart item, the cart message, the promotions/coupons applied, etc. All these entities
are associated to a main cart entity that represents the consumer cart. This cart entity is stored in our database
so users can switch between devices and/or come back a few days later and add the items to the cart, etc. The system does not
rely on the user session.&lt;/p&gt;

&lt;p&gt;For some time we just serialized the cart using the PHP &lt;code class=&quot;highlighter-rouge&quot;&gt;serialize()&lt;/code&gt; function and stored it in a binary field in
a MongoDB collection. It worked very well until we had to extract the data to use in marketing emails, analytics, etc.
The serialize function doesn’t generate an easily encoded string that is easy to parse by another system that is not PHP
based. We couldn’t keep creating code around our shopping cart to have analytics or marketing information either. The
solution was to store the cart in a format that would be easy for PHP to quickly serialize/unserialize and
also easy to integrate with partners or different tools. The solution was to encode the entities in
JSON.&lt;/p&gt;

&lt;p&gt;JSON is very well supported by many languages and tools. Since we are using MongoDB to store the carts we can easily
generate queries directly from MongoDB to have some statistics. This change decreased the performance of managing carts,
but in the main scope it was a gain.&lt;/p&gt;

&lt;h3 id=&quot;what-about-jsonserializable-in-php-54&quot;&gt;What about &lt;code class=&quot;highlighter-rouge&quot;&gt;JsonSerializable&lt;/code&gt; in PHP 5.4?&lt;/h3&gt;

&lt;p&gt;The &lt;a href=&quot;http://php.net/JsonSerializable&quot;&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;JsonSerializable&lt;/code&gt; interface&lt;/a&gt; is used with the &lt;code class=&quot;highlighter-rouge&quot;&gt;json_encode()&lt;/code&gt; function to serialize an
object. This means it is very useful to convert your class to JSON when you are
responding with the entity to your API, for example; however, it doesn’t support unserialization.&lt;/p&gt;

&lt;h3 id=&quot;what-about-using-jsonencode-with-the-serializable-interface&quot;&gt;What about using &lt;code class=&quot;highlighter-rouge&quot;&gt;json_encode&lt;/code&gt; with the &lt;code class=&quot;highlighter-rouge&quot;&gt;Serializable&lt;/code&gt; interface?&lt;/h3&gt;

&lt;p&gt;Nope. If your entity implements &lt;code class=&quot;highlighter-rouge&quot;&gt;Serializable&lt;/code&gt; you can define how to serialize and unserialize, but PHP wraps their
serializable code around it which means the output is not 100% JSON.&lt;/p&gt;

&lt;h3 id=&quot;hmmm-so-what-about-jms-serializer&quot;&gt;Hmmm, so what about JMS Serializer?&lt;/h3&gt;

&lt;p&gt;&lt;a href=&quot;http://jmsyst.com/libs/serializer&quot;&gt;JMS Serializer&lt;/a&gt; is a great library and does serialize to JSON, but it doesn’t have
as many features as this library. For example, when you de-serialize, you have to pass the class where the
data was generated. Also, they don’t support nested encoding.&lt;/p&gt;

&lt;h3 id=&quot;why-not-just-create-a-method-to-aggregate-all-the-data-and-respond-as-json&quot;&gt;Why not just create a method to aggregate all the data and respond as JSON?&lt;/h3&gt;

&lt;p&gt;Yes, you can. But are you sure you want to make a method to cover all situations and nested levels to aggregate
everything? In our case it would be painful and would require more code than this library. If it works for you,
go for it. You probably will get better performance, and it will probably be easier to store the JSON however you want
(I mean not in the same structure of your classes, as the &lt;code class=&quot;highlighter-rouge&quot;&gt;JsonSerializer&lt;/code&gt; does).&lt;/p&gt;

&lt;h3 id=&quot;you-are-convincing-me-but-i-have-so-much-crap-on-my-classes-can-i-ignore-some-of-the-properties&quot;&gt;You are convincing me, but I have so much crap on my classes. Can I ignore some of the properties?&lt;/h3&gt;

&lt;p&gt;Not a problem. The library supports the magic methods &lt;code class=&quot;highlighter-rouge&quot;&gt;__sleep()&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;__wakeup()&lt;/code&gt;.  In each class you can
define what will be stored in the JSON and what to execute when unserialized. It works exactly the same way as the
&lt;code class=&quot;highlighter-rouge&quot;&gt;serialize()&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;unserialize()&lt;/code&gt; functions.&lt;/p&gt;

&lt;h3 id=&quot;ok-but-my-code-is-a-little-complex-i-have-some-double-linked-lists-some-recursing-objects-etc&quot;&gt;Ok, but my code is a little complex. I have some double linked lists, some recursing objects, etc.&lt;/h3&gt;

&lt;p&gt;This is also not a problem. The library handles code recursion. You can call the serialize method and enjoy it.&lt;/p&gt;

&lt;h3 id=&quot;fcking-amazing-but-i-doubt-it-will-work-in-my-old-environment&quot;&gt;F*cking amazing, but I doubt it will work in my old environment.&lt;/h3&gt;

&lt;p&gt;The library supports PHP 5.3.6 and above. We don’t need any other dependency. If you are using any PHP version before
that, stop now, read some blogs, and go upgrade your system! PHP 5.3 only has a few months of support left.&lt;/p&gt;

&lt;h3 id=&quot;is-the-library-compatible-with-serializable-or-jsonserializable&quot;&gt;Is the library compatible with &lt;code class=&quot;highlighter-rouge&quot;&gt;Serializable&lt;/code&gt; or &lt;code class=&quot;highlighter-rouge&quot;&gt;JsonSerializable&lt;/code&gt;?&lt;/h3&gt;

&lt;p&gt;Yep. Each one has different functionality, so everything is fine. You can still use &lt;code class=&quot;highlighter-rouge&quot;&gt;Serializable&lt;/code&gt; with
&lt;code class=&quot;highlighter-rouge&quot;&gt;serialize()&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;unserialize()&lt;/code&gt; functions. You can use &lt;code class=&quot;highlighter-rouge&quot;&gt;JsonSerializable&lt;/code&gt; with &lt;code class=&quot;highlighter-rouge&quot;&gt;json_encode()&lt;/code&gt; to respond to your
API and our library to serialize the object for internal storage.&lt;/p&gt;

&lt;h3 id=&quot;you-are-talking-too-much-youre-like-a-car-salesmen-do-you-have-some-code-to-show&quot;&gt;You are talking too much; you’re like a car salesmen. Do you have some code to show?&lt;/h3&gt;

&lt;p&gt;Indeed, let’s go to an example:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/jrbasso/e0801a89bacad0262189.js?file=json_serializer.php&quot;&gt; &lt;/script&gt;

&lt;p&gt;Is that clear?&lt;/p&gt;

&lt;h3 id=&quot;wow-amazing-how-can-i-get-it&quot;&gt;Wow, amazing! How can I get it?&lt;/h3&gt;

&lt;p&gt;You can install via composer (package &lt;code class=&quot;highlighter-rouge&quot;&gt;zumba/json-serializer&lt;/code&gt;), or download directly from &lt;a href=&quot;https://github.com/zumba/json-serializer&quot;&gt;GitHub&lt;/a&gt;.
If you find something wrong, or something that we can improve, feel free to open a &lt;a href=&quot;https://github.com/zumba/json-serializer/issues&quot;&gt;GitHub issue&lt;/a&gt;.
If you want to make a pull request, even better. :)&lt;/p&gt;

&lt;p&gt;You are welcome to check our other open source projects on &lt;a href=&quot;https://github.com/zumba&quot;&gt;https://github.com/zumba&lt;/a&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Tame Stale Pull Requests with Drill Sergeant</title>
   <summary>Get notified via email when github pull requests become stale.</summary>
   <link href="http://tech.zumba.com/2013/12/07/keep-tabs-on-pull-requests//"/>
   <author>
	<name>Chris Saylor</name>
	<email>christopher.saylor@zumba.com</email>
   </author>
   <updated>2013-12-07T00:00:00+00:00</updated>
   <id>http://tech.zumba.com/2013/12/07/keep-tabs-on-pull-requests</id>
   <content type="html">&lt;p&gt;Our tech team uses a process similar to the &lt;a href=&quot;http://scottchacon.com/2011/08/31/github-flow.html&quot;&gt;Github Flow&lt;/a&gt;, whereby all changes are pushed to the main branch
of a repo by way of Github pull requests. We use this internally, but it is also the most common mechanism for open source projects to get community contributions on Github. We think it’s a great way to encourage code reviews and incremental improvements prior to going into a main production pushable branch, however it’s not without its pain points.&lt;/p&gt;

&lt;h3 id=&quot;stale-pull-requests--death-to-open-source&quot;&gt;Stale Pull Requests &lt;code class=&quot;highlighter-rouge&quot;&gt;==&lt;/code&gt; Death to Open Source&lt;/h3&gt;

&lt;p&gt;How many times have you come across an open source project that does &lt;em&gt;almost&lt;/em&gt; what you need? How many of these have pull requests that are one or more months old? It’s discouraging when you know that you could contribute and fix whatever problem may exist with the project but you know that the maintainer has abandoned or is not responsive to merging pull requests. As both a maintainer of open source projects, it’s critical to stay up-to-date and aware of open pull requests.&lt;/p&gt;

&lt;h3 id=&quot;introducing-drill-sergeant&quot;&gt;Introducing Drill Sergeant&lt;/h3&gt;

&lt;p&gt;As a part of our development lifecycle, stale pull requests mean that QA doesn’t have the opportunity to begin testing until it is merged. Therefore, it is vital that the dev team know about pull requests to be reviewed and merged as soon as possible. We developed an open source tool called &lt;a href=&quot;https://github.com/zumba/drill-sergeant&quot;&gt;Drill Sergeant&lt;/a&gt; to send reports via email of any pull request older than a specified period.&lt;/p&gt;

&lt;h3 id=&quot;reporting-for-duty&quot;&gt;Reporting for Duty&lt;/h3&gt;

&lt;p&gt;An example report from running Drill Sergeant against the CakePHP project configured for one week staleness looks something like this:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://tech.zumba.com/img/blog/drill-sergeant.png&quot; alt=&quot;Drill Sergeant Report&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The command for the above:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;GITHUB_TOKEN=atokenhere drillsergeant -e &quot;myemail@address&quot; -r &quot;cakephp/cakephp&quot; -s 168 # 24 * 7
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;h3 id=&quot;schedule-it-with-crontab&quot;&gt;Schedule It with Crontab&lt;/h3&gt;

&lt;p&gt;This tool is meant to be run on a schedule and it’s easy to setup to get daily reports:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;0 0 * * *	GITHUB_TOKEN=atokenhere drillsergeant -e &quot;myemail@address&quot; -r &quot;cakephp/cakephp&quot; -s 168
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;h3 id=&quot;install-it&quot;&gt;Install It&lt;/h3&gt;

&lt;p&gt;The full instructions can be found in the &lt;a href=&quot;https://npmjs.org/package/drill-sergeant&quot;&gt;readme of the project&lt;/a&gt;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Handling Asynchronism with Promises</title>
   <summary>Using the async library in Node.js for combining multiple MongoDB aggregation queries into a single list without blocking the event queue.</summary>
   <link href="http://tech.zumba.com/2013/11/06/handling-asynchronism-with-promises//"/>
   <author>
	<name>Chris Saylor</name>
	<email>christopher.saylor@zumba.com</email>
   </author>
   <updated>2013-11-06T00:00:00+00:00</updated>
   <id>http://tech.zumba.com/2013/11/06/handling-asynchronism-with-promises</id>
   <content type="html">&lt;p&gt;While experimenting with Node.js for a coding game we are working on called &lt;a href=&quot;https://node-defender.herokuapp.com&quot;&gt;Node Defender&lt;/a&gt;&lt;sup&gt;1&lt;/sup&gt; for the &lt;a href=&quot;http://ultimatedeveloperevent.com/boston-2013/&quot;&gt;Ultimate Developer Conference&lt;/a&gt;, many asynchronous problems arose that we were unaccustomed to dealing with since we are primarily a PHP shop (read: synchronous). The examples covered in this post are specific to MongoDB, but the essence can be applied to any asynchronous process.&lt;/p&gt;

&lt;h3 id=&quot;intro&quot;&gt;Intro&lt;/h3&gt;

&lt;p&gt;First, let’s discuss the problem. The game server is a Node.js app that hosts both the websocket communication as well as a leaderboard of top scores and top categories. In the backend, we use MongoDB to store all the games that occur and use MongoDB’s &lt;a href=&quot;http://docs.mongodb.org/manual/aggregation/&quot;&gt;aggregation framework&lt;/a&gt; to get the top 10 scores and the top scores in each category: Kills, damage, highest round achieved, and “wave clears”. Retrieving the top score for each category requires separate queries to MongoDB; each query is asynchronous. How would we go about sending one request to the leaderboard that executes these 4 queries and returns them all without causing the event loop of Node.js to hang waiting for synchronous requests? The answer is “promises.” &lt;a href=&quot;http://martinfowler.com/aboutMe.html&quot;&gt;Martin Fowler&lt;/a&gt; does a good writeup about what a promise is in javascript in &lt;a href=&quot;http://martinfowler.com/bliki/JavascriptPromise.html&quot;&gt;this post&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&quot;the-aggregate&quot;&gt;The Aggregate&lt;/h3&gt;

&lt;p&gt;Each game is represented in MongoDB as a document containing various values for calculating the score. In order to get the highest value in various categories the following aggregate query needs to be run:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/cjsaylor/7323403.js?file=category_aggregate.js&quot;&gt; &lt;/script&gt;

&lt;p&gt;For a quick explanation:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The &lt;code class=&quot;highlighter-rouge&quot;&gt;sorter&lt;/code&gt; controls which category by which we’re going to sort; descending in this case.&lt;/li&gt;
  &lt;li&gt;The &lt;code class=&quot;highlighter-rouge&quot;&gt;$project&lt;/code&gt; is the projection of the aggregate we’d like MongoDB to return. In this case: the player’s name and the value of the category.&lt;/li&gt;
  &lt;li&gt;Finally, the &lt;code class=&quot;highlighter-rouge&quot;&gt;$limit&lt;/code&gt; of 1, we just want the top value.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;async-all-the-things&quot;&gt;Async All the Things&lt;/h3&gt;

&lt;p&gt;Where does the promise come into play? With the &lt;a href=&quot;https://npmjs.org/package/async&quot;&gt;async&lt;/a&gt; library, we can use a mapping to get the above aggregate for all required categories, execute in parallel, and return the results to one callback called the promise. In typical promise setups, there would be separate functions for a success, failure, and always. In our case, we’re going to setup our promise to receive all conditions and let that method determine how to handle the success and failure results.&lt;/p&gt;

&lt;p&gt;We use the async “map” method to accomplish this. It allows us to pass an array of categories to the above aggregate, run the getTopCategory method against each one, compile the results, and then call our promise.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/cjsaylor/7323403.js?file=promise.js&quot;&gt; &lt;/script&gt;

&lt;p&gt;Explanation:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The &lt;code class=&quot;highlighter-rouge&quot;&gt;map&lt;/code&gt; array contains the categories we want to run with the aggregate queries.&lt;/li&gt;
  &lt;li&gt;We bind the &lt;code class=&quot;highlighter-rouge&quot;&gt;db&lt;/code&gt; (which is the connector to MongoDB) to the &lt;code class=&quot;highlighter-rouge&quot;&gt;getTopCategory&lt;/code&gt; method, which allows this method to have direct access to the &lt;code class=&quot;highlighter-rouge&quot;&gt;db&lt;/code&gt; instance without having to pass it in as a parameter.&lt;/li&gt;
  &lt;li&gt;Finally, the promise anonymous method attached to the &lt;code class=&quot;highlighter-rouge&quot;&gt;Async.map&lt;/code&gt; parameter gets the results (or errors) from all of the category aggregates and compiles them into a single list to be consumed by the calling method.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h3&gt;

&lt;p&gt;Using the “promise” pattern with the &lt;code class=&quot;highlighter-rouge&quot;&gt;async&lt;/code&gt; library, we can make concurrent asynchronous requests and return the results of asynchronous queries into one unified usable list back to the callee. This prevents our request from blocking other requests to Node because the event loop isn’t waiting on a series of synchronous queries to MongoDB.&lt;/p&gt;

&lt;h3 id=&quot;footnotes&quot;&gt;Footnotes&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Node Defender is a javascript programming game where you defend against waves of murderous server side code that wants nothing more than to kill and disconnect your client. The client code is open source, and we will be doing a series of blog posts about the construction of the project as well as the infrastructure used to run it.&lt;/li&gt;
&lt;/ol&gt;
</content>
 </entry>
 
 <entry>
   <title>Incorporating Mongounit into Multi-datasource Models with Traits</title>
   <summary>Incorporating Mongounit into Multi-datasource Models with Traits</summary>
   <link href="http://tech.zumba.com/2013/10/30/multiple-data-sources-phpunit-testing//"/>
   <author>
	<name>Chris Saylor</name>
	<email>christopher.saylor@zumba.com</email>
   </author>
   <updated>2013-10-30T00:00:00+00:00</updated>
   <id>http://tech.zumba.com/2013/10/30/multiple-data-sources-phpunit-testing</id>
   <content type="html">&lt;p&gt;A while back we open sourced &lt;a href=&quot;https://github.com/zumba/mongounit&quot;&gt;Mongounit&lt;/a&gt;, a PHPUnit extension for testing models utilizing mongodb. One key issue that we’ve discovered as we incorporate MongoDB into more of our data models is that extending Mongounit’s TestCase class limits that unit test towards Mongo only as the datasource. Since only a portion of our data is in Mongo while the remaining is in MySQL, limiting a test case to work with one datasource or another is too limiting.&lt;/p&gt;

&lt;h3 id=&quot;workarounds&quot;&gt;Workarounds&lt;/h3&gt;

&lt;p&gt;The first workaround we employed (as we use PHPUnit’s dbunit extension) was to separate the tests of methods that use MongoDB versus methods that use MySQL into separate unit test clases. This worked for a while until we encountered situations where it was either not convienient to split into separate unit tests, or a method was interacting (or calling via protected methods) both data sources.&lt;/p&gt;

&lt;p&gt;The second workaround was to manually set and clear data in mongo in the test cases, which works of course, but causes a lot of duplicate code strewn throughout the test code base.&lt;/p&gt;

&lt;h3 id=&quot;enter-54-and-traits&quot;&gt;Enter 5.4 and Traits&lt;/h3&gt;

&lt;p&gt;PHP does not support the concept of &lt;a href=&quot;http://en.wikipedia.org/wiki/Multiple_inheritance&quot;&gt;multiple inheritance&lt;/a&gt; which could have easily solved our problem. However, in PHP 5.4, a usable alternative is available. We are fortunate that our code base is workable on PHP 5.4, although not everyone is in the same position. For those not on PHP 5.3 and below, one of the above workarounds will have to suffice.&lt;/p&gt;

&lt;p&gt;One of the nice features of 5.4 was the introduction of &lt;a href=&quot;http://php.net/traits&quot;&gt;traits&lt;/a&gt;. Traits provide a simple way to re-use common methods and was a great solution to our lack of multiple inheritance. The first step was to actually create a useful trait in Mongounit to serve as means of attaching mongo support to test cases that extends the dbunit extension.&lt;/p&gt;

&lt;p&gt;You can see Mongounit’s trait implementation in &lt;a href=&quot;https://github.com/zumba/mongounit/blob/master/src/Zumba/PHPUnit/Extensions/Mongo/TestTrait.php&quot;&gt;Github&lt;/a&gt; available as of version 1.1.3.&lt;/p&gt;

&lt;p&gt;The next step was to use the trait in our dbunit based test case. This means seting up the “setup” and “teardown” methods from the trait as well as implementing the abstract methods required for connecting to mongo and retrieving fixture data. These methods are the same as what is available in the &lt;a href=&quot;https://github.com/zumba/mongounit/blob/master/src/Zumba/PHPUnit/Extensions/Mongo/TestCase.php&quot;&gt;TestCase&lt;/a&gt;, so in our case, it was a matter of moving the implementation into the trait method.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/cjsaylor/7243308.js&quot;&gt; &lt;/script&gt;

&lt;p&gt;Now that our test case has implemented the trait, we now have access to setup fixtures for both MySQL and Mongo and utilize both within the same test case.&lt;/p&gt;

&lt;h3 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h3&gt;

&lt;p&gt;Using some of the “newer” features of PHP, we are able to make our test cases more flexable and easier to use without having to reimplement entirely what mongounit does into a dbunit extended class.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Symbiosis: Instanced Dispatcher Support Added</title>
   <summary>New version of Symbiosis (v1.2)</summary>
   <link href="http://tech.zumba.com/2013/09/22/symbiosis-instanced-dispatchers//"/>
   <author>
	<name>Chris Saylor</name>
	<email>christopher.saylor@zumba.com</email>
   </author>
   <updated>2013-09-22T00:00:00+00:00</updated>
   <id>http://tech.zumba.com/2013/09/22/symbiosis-instanced-dispatchers</id>
   <content type="html">&lt;p&gt;A new version of Symbiosis &lt;a href=&quot;https://github.com/zumba/symbiosis/releases/tag/v1.2&quot;&gt;v1.2&lt;/a&gt; has been released.&lt;/p&gt;

&lt;h3 id=&quot;introducing-instanced-dispatchers&quot;&gt;Introducing Instanced Dispatchers&lt;/h3&gt;

&lt;p&gt;Prior to v1.2, all events were globally registered via a &lt;a href=&quot;https://github.com/zumba/symbiosis/blob/v1.1.5/Zumba/Symbiosis/Event/EventManager.php#L19&quot;&gt;statically defined event manager&lt;/a&gt;. This posed issues when some models needed to have events contained to themselves, instead of available in the global event space.&lt;/p&gt;

&lt;p&gt;To solve this issue, we’ve added an &lt;a href=&quot;https://github.com/zumba/symbiosis/blob/v1.2/src/Zumba/Symbiosis/Event/EventRegistry.php&quot;&gt;Event Registry&lt;/a&gt;. This has the same API and functionality of the Event Manager, but in an instanced state. Now you can create an Event Registry anywhere and register events specifically to it. The Event Manager remains backwards compatible, but under the hood, it is using a static instance of the new Event Registry system.&lt;/p&gt;

&lt;h3 id=&quot;composer-update&quot;&gt;Composer update&lt;/h3&gt;

&lt;p&gt;We’ve also improved the composer setup to properly use the &lt;a href=&quot;https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md&quot;&gt;PSR-0&lt;/a&gt; standard. As such, the autoloader has been removed. If you were using Symbiosis prior to v1.2 and were using the autoloader directly, you will need to update to use the composer autoloader.&lt;/p&gt;

&lt;h3 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h3&gt;

&lt;p&gt;Symbiosis is now more flexable to implement. Our next steps will be to improve the plugin system to be more (and less) coupled to the event system.&lt;/p&gt;

&lt;p&gt;See the full changeset: &lt;a href=&quot;https://github.com/zumba/symbiosis/pull/15/files&quot;&gt;https://github.com/zumba/symbiosis/pull/15/files&lt;/a&gt;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Join the Zumba Engineering Team</title>
   <summary>We are looking for a few good engineers to help us achieve our technical vision.</summary>
   <link href="http://tech.zumba.com/2013/08/06/join-the-engineering-team//"/>
   <author>
	<name>Chris Saylor</name>
	<email>christopher.saylor@zumba.com</email>
   </author>
   <updated>2013-08-06T00:00:00+00:00</updated>
   <id>http://tech.zumba.com/2013/08/06/join-the-engineering-team</id>
   <content type="html">&lt;p&gt;Our engineering team is in the process of adopting new technologies to solve complex business problems, and we’re looking for additional engineers to help us out.&lt;/p&gt;

&lt;h2 id=&quot;introduction&quot;&gt;Introduction&lt;/h2&gt;

&lt;p&gt;Zumba offers a unique opportunity of providing a startup feel with the security of an established company. Our business is growing, and as such our technology stack also needs to grow with it. This allows us to work on newer technologies (when it makes sense), so there’s always something to learn.&lt;/p&gt;

&lt;h2 id=&quot;what-to-expect&quot;&gt;What to expect&lt;/h2&gt;

&lt;p&gt;The Zumba system operates on AWS linux based instances with a mix of MySQL and MongoDB driving our applications in a service oriented architecture. Our deployments work on a continous integration strategy as we use unit testing coupled with Jenkins CI server to deploy quality code to production.&lt;/p&gt;

&lt;p&gt;Our projects are scheduled and structured with the scrum methodology in two-week sprints.&lt;/p&gt;

&lt;p&gt;If you join our engineering team, you will be up and making your first commit within a few hours as your environment is managed by our vagrant setup.&lt;/p&gt;

&lt;p&gt;Various positions offer unique opportunities to work on fascinating technologies:&lt;/p&gt;

&lt;h3 id=&quot;frontend&quot;&gt;Frontend&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Use sass to style and build rich applications.&lt;/li&gt;
  &lt;li&gt;Work with backbone.js and require.js to make our applications more interactive.&lt;/li&gt;
  &lt;li&gt;Drive the user experience using modern web frameworks and mixins.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Positions:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://tech.zumba.com/careers.html#job-fe_dev/&quot;&gt;Frontend Developer&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;backend&quot;&gt;Backend&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Work with advanced PHP techniques as more of our application moves to PHP 5.4.&lt;/li&gt;
  &lt;li&gt;Solve difficult performance issues by utilizing different datastores, such as Memcached, MongoDB, and Elasticsearch.&lt;/li&gt;
  &lt;li&gt;Help us explore and improve our architecture with the JVM and Scala.&lt;/li&gt;
  &lt;li&gt;Continuously improve our continous integration strategy.&lt;/li&gt;
  &lt;li&gt;Work with other engineers that are excited about the technologies they bring to the table.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Positions:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://tech.zumba.com/careers.html#job-sr_soft_eng/&quot;&gt;Senior Software Engineer&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://tech.zumba.com/careers.html#job-soft_eng/&quot;&gt;Software Engineer&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;join-us&quot;&gt;Join Us&lt;/h2&gt;

&lt;p&gt;If working with exciting technologies and experienced engineers on solutions to complex problems is what you’ve been missing, then &lt;a href=&quot;http://tech.zumba.com/careers.html&quot;&gt;Join the team&lt;/a&gt;! We have several openings for software engineers and frontend developers.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Introducing Zlogd - An open source universal logging agent</title>
   <summary>Socket server for external apps to ship logs in a non-blocking fashion.</summary>
   <link href="http://tech.zumba.com/2013/06/20/introducing-zlogd//"/>
   <author>
	<name>Chris Saylor</name>
	<email>christopher.saylor@zumba.com</email>
   </author>
   <updated>2013-06-20T00:00:00+00:00</updated>
   <id>http://tech.zumba.com/2013/06/20/introducing-zlogd</id>
   <content type="html">&lt;p&gt;Logging is a critical part to an application’s life-cycle. It helps identify problems when they occur and track trends of events.&lt;/p&gt;

&lt;p&gt;There are many ways and products to accomplish this depending on your goal, but today we’re introducing our open-source logging agent to help: &lt;a href=&quot;https://npmjs.org/package/zlogd&quot;&gt;Zlogd&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;use-case&quot;&gt;Use case&lt;/h2&gt;

&lt;p&gt;In many instances in web applications, multiple servers are involved, each involving one or many log files. When tracking down a problem or examining for trends, this becomes very problematic.&lt;/p&gt;

&lt;p&gt;Zlogd is meant to solve this problem as being a universal logging agent. Zlogd runs locally on each server and listens to a socket file. The application then will start logging output to the socket file where Zlogd will package and ship the log message to a central logging location.&lt;/p&gt;

&lt;h2 id=&quot;zlogd-workflow&quot;&gt;Zlogd Workflow&lt;/h2&gt;

&lt;p&gt;In our proposed stack configuration, our central logging server will contain the following:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Logstash agent for receiving all messages from all the Zlogd instances.&lt;/li&gt;
  &lt;li&gt;Elastic search for Logstash to store the messages&lt;/li&gt;
  &lt;li&gt;Kibana3 to have one interface to examine the logs&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The workflow would then lend itself to this configuration:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://tech.zumba.com/img/blog/zlogd_workflow.jpg&quot; alt=&quot;Zlogd Workflow&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;benefits&quot;&gt;Benefits&lt;/h2&gt;

&lt;p&gt;Since our stack is mostly PHP, that means each request is synchronous. If there are multiple loggers enabled (ie, write to file, ship to newrelic on warning/error, etc), the customer is on the hook for waiting for that log event to process through all those loggers. This shortens the logging time during the request by only having to write to a single logger (the Zlogd sock file) thereby increasing application performance.&lt;/p&gt;

&lt;p&gt;This also facilitates the central logging paradigm, which allows the consolidation of all application logs.&lt;/p&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;Zlogd hopes to solve the problem of fractured logging and be flexible enough to work with any log collecting apparatus. This is a relatively new system, and as such we will be working the kinks out of this first version release. Feel free to fork and open a pull request to implement your flavor of log transport (graylog2, splunk, loggly, etc).&lt;/p&gt;

&lt;h2 id=&quot;reference&quot;&gt;Reference&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://npmjs.org/package/zlogd&quot;&gt;Nodejs NPM package&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/zumba/zlogd&quot;&gt;Github repo&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Middleman.js Project Open Sourced</title>
   <summary>A library giving you control over the execution of third party libs.</summary>
   <link href="http://tech.zumba.com/2013/02/11/middleman-open-sourced//"/>
   <author>
	<name>Stephen Young</name>
	<email>stephen.young@zumba.com</email>
   </author>
   <updated>2013-02-11T00:00:00+00:00</updated>
   <id>http://tech.zumba.com/2013/02/11/middleman-open-sourced</id>
   <content type="html">&lt;p&gt;We’re on a roll this week, and it’s only Monday! Yesterday Chris Saylor introduced &lt;a href=&quot;http://engineering.zumba.com/2013/02/10/mongounit-open-sourced/&quot;&gt;Mongounit&lt;/a&gt;. Today I am going to show you another open source project we’ve written called &lt;a href=&quot;https://github.com/zumba/middleman.js&quot;&gt;Middleman.js&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Middleman is a javascript library that can be used in a browser or as a node.js module.  It allows you to hook into the execution of any function to apply prefiltering to that function’s arguments; globally change the function’s execution context; pipe that function’s arguments to several others; or, overload the function to behave differently.  It does all this for you seamlessly, so you can simply call the original function as you normally would.&lt;/p&gt;

&lt;h3 id=&quot;example&quot;&gt;Example&lt;/h3&gt;
&lt;p&gt;For a practical example we need to start with some assumptions: You have a new mobile project that communicates with a RESTful server API.  After a few weeks of development some project requirements change and now every ajax url must start with &lt;code class=&quot;highlighter-rouge&quot;&gt;/api&lt;/code&gt;.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;You don’t want to manually find every ajax call in the project and prepend the url strings with &lt;code class=&quot;highlighter-rouge&quot;&gt;/api&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;You don’t want to force your team to remember to do this as you develop.&lt;/li&gt;
  &lt;li&gt;You want to implement this new requirement as seamlessly as possible.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;jQuery’s powerful ajax methods are well known, but let’s say you’re working with a more simplified library like &lt;a href=&quot;http://zeptojs.com&quot;&gt;Zepto.js&lt;/a&gt; which was built for mobile. Middleman.js can solve this problem with just a few lines:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/young-steveo/be236d9dee00f9f0f088.js?file=middleman-example.js&quot;&gt; &lt;/script&gt;

&lt;h3 id=&quot;seamless&quot;&gt;Seamless&lt;/h3&gt;
&lt;p&gt;You can call &lt;code class=&quot;highlighter-rouge&quot;&gt;$.ajax&lt;/code&gt; as you normally would.  The filter method will be executed first, and the array &lt;code class=&quot;highlighter-rouge&quot;&gt;args&lt;/code&gt; that is returned by the filter method will be passed to the original &lt;code class=&quot;highlighter-rouge&quot;&gt;$.ajax&lt;/code&gt; method as parameters.&lt;/p&gt;

&lt;p&gt;Object &lt;em&gt;references&lt;/em&gt; are passed by value in Javascript, which is why you don’t see me doing anything with the &lt;code class=&quot;highlighter-rouge&quot;&gt;ajaxSettings&lt;/code&gt; variable after I’ve modified it’s &lt;code class=&quot;highlighter-rouge&quot;&gt;url&lt;/code&gt; property.  See &lt;a href=&quot;http://docstore.mik.ua/orelly/webprog/jscript/ch11_02.htm&quot;&gt;this&lt;/a&gt; for more details.&lt;/p&gt;

&lt;h3 id=&quot;context&quot;&gt;Context&lt;/h3&gt;
&lt;p&gt;In the previous example, Middleman will use the &lt;code class=&quot;highlighter-rouge&quot;&gt;lib&lt;/code&gt; object for context when executing the ajax method (in this case Zepto.js).  However, Middleman can also take an optional &lt;code class=&quot;highlighter-rouge&quot;&gt;context&lt;/code&gt; parameter that will be used instead, like this:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/young-steveo/be236d9dee00f9f0f088.js?file=middleman-context-example.js&quot;&gt; &lt;/script&gt;

&lt;p&gt;Notice that the context of the &lt;code class=&quot;highlighter-rouge&quot;&gt;stringify&lt;/code&gt; method became &lt;code class=&quot;highlighter-rouge&quot;&gt;Array&lt;/code&gt;.  Had I passed &lt;code class=&quot;highlighter-rouge&quot;&gt;context : Object,&lt;/code&gt; instead, the output would have been &lt;code class=&quot;highlighter-rouge&quot;&gt;[object Array]&lt;/code&gt; instead of &lt;code class=&quot;highlighter-rouge&quot;&gt;a,b,c,d&lt;/code&gt;.  You’ve probably seen this kind of behavior in other popular libraries like &lt;a href=&quot;http://underscorejs.org/&quot;&gt;Underscore.js&lt;/a&gt;’s &lt;code class=&quot;highlighter-rouge&quot;&gt;_.bind&lt;/code&gt; method.&lt;/p&gt;

&lt;h3 id=&quot;final-word&quot;&gt;Final word&lt;/h3&gt;
&lt;p&gt;Currently there is no way to disable Middleman’s meddling once you’ve called the map function.  We’re planning to incorporate an internal registery in a future release that will allow you to inspect the Middleman object to see what methods have been overloaded, and also make it easy for Middleman to flip it’s filters on or off at a granular level.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Repository - &lt;a href=&quot;https://github.com/zumba/middleman.js&quot;&gt;Middleman.js&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;License - MIT&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Mongounit Project Open Sourced</title>
   <summary>Zumba&amp;reg;'s second open source project, Mongounit, has been open sourced.</summary>
   <link href="http://tech.zumba.com/2013/02/10/mongounit-open-sourced//"/>
   <author>
	<name>Chris Saylor</name>
	<email>christopher.saylor@zumba.com</email>
   </author>
   <updated>2013-02-10T00:00:00+00:00</updated>
   <id>http://tech.zumba.com/2013/02/10/mongounit-open-sourced</id>
   <content type="html">&lt;p&gt;Introducing &lt;a href=&quot;https://github.com/zumba/mongounit&quot;&gt;Mongounit&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Mongounit is a PHPUnit extension modeled after dbunit that allows for fixture-based unit testing of mongo db backed code.&lt;/p&gt;

&lt;p&gt;One of our more recent projects has given the team exposure to MongoDB. As such, we needed an easy way to test the models that utilize mongo in a similar fashion to how we test models that talk to mysql. Using this framework, it’s easy to implement mongo test cases to easily create fixture data in collections, or simply clear collections between test cases.&lt;/p&gt;

&lt;p&gt;See an example &lt;a href=&quot;https://github.com/zumba/mongounit/blob/master/examples/PizzaTest.php&quot;&gt;Testcase&lt;/a&gt;&lt;/p&gt;

&lt;h3 id=&quot;more-info&quot;&gt;More info&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Repository - &lt;a href=&quot;https://github.com/zumba/mongounit&quot;&gt;Mongounit&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;License - MIT&lt;/li&gt;
  &lt;li&gt;CI Build - &lt;a href=&quot;https://travis-ci.org/zumba/mongounit&quot;&gt;Travis CI&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
 </entry>
 
 <entry>
   <title>Mocking Singleton PHP classes with PHPUnit</title>
   <summary>Convenient way to mock singleton classes for easy, reusable testing.</summary>
   <link href="http://tech.zumba.com/2012/11/26/singleton-class-phpunit-mocking//"/>
   <author>
	<name>Chris Saylor</name>
	<email>christopher.saylor@zumba.com</email>
   </author>
   <updated>2012-11-26T00:00:00+00:00</updated>
   <id>http://tech.zumba.com/2012/11/26/singleton-class-phpunit-mocking</id>
   <content type="html">&lt;p&gt;In many of our projects, utilities and vendor classes are implemented with a &lt;a href=&quot;http://en.wikipedia.org/wiki/Singleton_pattern&quot;&gt;singleton pattern&lt;/a&gt;.  If you’re not familiar, a singleton pattern looks something like:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/4131481.js?file=singleton.php&quot;&gt; &lt;/script&gt;

&lt;p&gt;In this post, we’ll cover a nice way to inject a PHPUnit mock object for use in testing methods that utilize singleton classes.&lt;/p&gt;

&lt;h3 id=&quot;inception&quot;&gt;Inception&lt;/h3&gt;

&lt;p&gt;First, we need to identify how this sort of mechanism is mocked.  The key aspect of the singleton class is the protected static self attribute.  This is what we’re most interested in for injecting our mock object.  In our example singleton class, the &lt;code class=&quot;highlighter-rouge&quot;&gt;self&lt;/code&gt; attribute is protected (which is usually the case), so we’ll need the use of the reflection class in order to “unprotect” and inject.&lt;/p&gt;

&lt;h3 id=&quot;mock-class&quot;&gt;Mock Class&lt;/h3&gt;

&lt;p&gt;Now we will look at the code to do the above.  First, a sample class that implements our singleton as part of a normal method:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/4131481.js?file=sample_class.php&quot;&gt; &lt;/script&gt;

&lt;p&gt;In this exercise, we will mock &lt;code class=&quot;highlighter-rouge&quot;&gt;Someclass&lt;/code&gt;’s &lt;code class=&quot;highlighter-rouge&quot;&gt;hello&lt;/code&gt; method to make it return a different string.  This is a super-simplified example, normally you would want to do this sort of thing for classes that do network based things, such as an emailer, REST service connector, etc.&lt;/p&gt;

&lt;p&gt;Let’s create our mock class:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/4131481.js?file=someclass_mock.php&quot;&gt; &lt;/script&gt;

&lt;p&gt;The &lt;code class=&quot;highlighter-rouge&quot;&gt;expects&lt;/code&gt; method creates the mock object and injects that mock object into the &lt;code class=&quot;highlighter-rouge&quot;&gt;self&lt;/code&gt; attribute.  The method you test that utilizes the singleton will get the mock object when they call the &lt;code class=&quot;highlighter-rouge&quot;&gt;getInstance&lt;/code&gt; method.&lt;/p&gt;

&lt;h3 id=&quot;example-use&quot;&gt;Example Use&lt;/h3&gt;

&lt;p&gt;Here is our PHPUnit test case.  We instantiate the class we want to test, mock the singleton object, and alter the output of the method.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/4131481.js?file=sample_test.php&quot;&gt; &lt;/script&gt;

&lt;h3 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h3&gt;

&lt;p&gt;This technique is really nice for common utility classes. We typically use them in the &lt;code class=&quot;highlighter-rouge&quot;&gt;setUp&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;tearDown&lt;/code&gt; methods, so we can test the other parts of the method that are important for their logic, and leave a single test to test the actual functionality of the singleton class we’re mocking.&lt;/p&gt;

</content>
 </entry>
 
 <entry>
   <title>Some CakePHP optimizations</title>
   <summary>Few tips in how optimize CakePHP applications to get better response times and save money</summary>
   <link href="http://tech.zumba.com/2012/11/05/cakephp-optimizations//"/>
   <author>
	<name>Juan Basso</name>
	<email>juan.basso@zumba.com</email>
   </author>
   <updated>2012-11-05T00:00:00+00:00</updated>
   <id>http://tech.zumba.com/2012/11/05/cakephp-optimizations</id>
   <content type="html">&lt;p&gt;Our site and system has a lot of throughput and it make us use more instances and try to reduce the load
in every part. It makes the company happy (save money) and also make the customer happy (faster load).
On this article I will go over few things in terms of architecture and some code changes/strategies that
could make your application faster as well.&lt;/p&gt;

&lt;h3 id=&quot;architecture&quot;&gt;Architecture&lt;/h3&gt;

&lt;p&gt;All our infra-structure is hosted by Amazon AWS. So, some tips are only for Amazon, but others can be
reused by other hosting.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;Install &lt;a href=&quot;http://php.net/apc&quot;&gt;APC&lt;/a&gt; or any other opcode cache. It is kind of trivial, but just to make
sure.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;Move things out of the box. We moved all our assets to &lt;a href=&quot;http://aws.amazon.com/s3/&quot;&gt;S3&lt;/a&gt; and
&lt;a href=&quot;http://aws.amazon.com/cloudfront/&quot;&gt;CloudFront&lt;/a&gt;. It helps in two ways:&lt;/li&gt;
  &lt;li&gt;reduce the load in host boxes (&lt;a href=&quot;http://aws.amazon.com/ec2/&quot;&gt;EC2&lt;/a&gt;), giving more CPU and memory for the PHP applications&lt;/li&gt;
  &lt;li&gt;Allow the browser to make more concurrent requests, since the host is usually different (ok, you can do the same with the same box).&lt;/li&gt;
  &lt;li&gt;Scale a little vertical before go horizontal. We had an experience of using many boxes of small size
in Amazon EC2. But after some math and tests, we identified that getting few large instances is better
than many small instances. The server handle more request simultaneously and it is faster, and cheaper.
The cheaper is kind of weird to hear, because these boxes are expensive, but it is true. You can
replace like 5 medium instances (m1.medium) by one high-memory extra large (m2.xlarge).&lt;/li&gt;
  &lt;li&gt;Avoid network requests. They could be fast, but you always have the overhead of the protocol,
transmission, etc. I will give one example on the code portion.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;code&quot;&gt;Code&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Store the cake caches locally. All our cache is based on &lt;a href=&quot;http://memcached.org/&quot;&gt;Memcached&lt;/a&gt;. The
internal cake caches (&lt;code class=&quot;highlighter-rouge&quot;&gt;_cake_core_&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;_cake_model_&lt;/code&gt;) wasn’t different. But these caches don’t
change that often, so why use network for that? So we simply changed these 2 caches to use APC instead
of Memcache. It reduced couple milliseconds on each request with a ridiculous change.&lt;/li&gt;
  &lt;li&gt;Do you change your files often in production? Do you have an automatized deployment process? Do
you restart your webserver every deploy? If you answered yes for these questions, you may disable
the configuration &lt;code class=&quot;highlighter-rouge&quot;&gt;apc.stat&lt;/code&gt; on production. This configuration, when enabled, makes the APC check
every request if the file you are trying to load was modified to re-create the opcode cache. If you
don’t change the files in production, why re-check it? Disabling it make your code run mostly in memory
only.&lt;/li&gt;
  &lt;li&gt;Check your APC configurations. Don’t let APC run out of memory
enough to cache all your code.&lt;/li&gt;
  &lt;li&gt;Do you use cake query cache or cached view based on the model? If no, create a method on your
&lt;code class=&quot;highlighter-rouge&quot;&gt;AppModel&lt;/code&gt; called &lt;code class=&quot;highlighter-rouge&quot;&gt;_clearCache&lt;/code&gt; and make it returns &lt;code class=&quot;highlighter-rouge&quot;&gt;true&lt;/code&gt;. Why? By default Cake do some
inflections and try loop thru the caches on the &lt;code class=&quot;highlighter-rouge&quot;&gt;app/tmp/cache/&lt;/code&gt; folder to delete the cached files when
you make some database change operation (INSERT/UPDATE/DELETE). We did that and we got a huge improvement.
One reason is because our sessions are stored in database, causing a insert/update in every single request.&lt;/li&gt;
  &lt;li&gt;View cache. You can use cake view cache or other system, like &lt;a href=&quot;https://www.varnish-cache.org/&quot;&gt;Varnish&lt;/a&gt;.
Depending of your system cake view cache is enough and give more flexibility, since you can still add some
PHP in the caches. Just be careful with restrict pages. Sometimes the cache will make it public for people
with the URL. See more details on &lt;a href=&quot;http://book.cakephp.org/2.0/en/core-libraries/helpers/cache.html&quot;&gt;CakePHP Documentation&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;requestAction&lt;/code&gt; and elements. Most of the sites has some dynamic content which need to render several
times, for example the site menu. Usually the content comes from database and you have to add the request
to the model into the &lt;code class=&quot;highlighter-rouge&quot;&gt;AppController&lt;/code&gt;. It causes one or more query per request, which probably is
unnecessary to do in all requests, since it will be the same for few minutes or even hours. The solution is
use the &lt;a href=&quot;http://book.cakephp.org/2.0/en/controllers.html#Controller::requestAction&quot;&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;requestAction&lt;/code&gt;&lt;/a&gt;
inside the element and use the &lt;a href=&quot;http://book.cakephp.org/2.0/en/views.html#caching-elements&quot;&gt;cache element&lt;/a&gt;.
All built-in CakePHP and very simple to use. In the end, after the first request (which could be a little
bit slower than usual because the &lt;code class=&quot;highlighter-rouge&quot;&gt;requestAction&lt;/code&gt;) the code will get the raw html rendered from the cache,
saving a good time and CPU from your database.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h3&gt;

&lt;p&gt;The changes above show few actions you could do to improve your site performance and save money with your
hosting. There is much more tips to say, but I guess these are the most simple to implement in short time
and take advantage of the results.&lt;/p&gt;

&lt;p&gt;Some of the tips or concept are valid for non-CakePHP sites as well.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Schema.org Product Microdata and Breadcrumbs</title>
   <summary>How to solve the problem of breadcrumbs inside product page</summary>
   <link href="http://tech.zumba.com/2012/09/19/schema-org-and-breadcrumb//"/>
   <author>
	<name>Juan Basso</name>
	<email>juan.basso@zumba.com</email>
   </author>
   <updated>2012-09-19T00:00:00+00:00</updated>
   <id>http://tech.zumba.com/2012/09/19/schema-org-and-breadcrumb</id>
   <content type="html">&lt;p&gt;This week I was looking to improve our shop &lt;abbr title=&quot;Search Engine Optimization&quot;&gt;SEO&lt;/abbr&gt; and
one of the things was the &lt;a href=&quot;http://www.w3.org/TR/2011/WD-microdata-20110525/&quot;&gt;microdata for HTML5&lt;/a&gt;.
It is really cool feature from HTML5, helping crawlers to understand more about the site and providing
a better results for users. For example, Google shows rich snippets in their results, so you can see
page author, breadcrumbs, review information, product prices, etc. You can see few examples on
&lt;a href=&quot;http://www.google.com/webmasters/tools/richsnippets&quot;&gt;Google Rich Snippets Testing Tool&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Looking at &lt;a href=&quot;http://support.google.com/webmasters/bin/answer.py?hl=en&amp;amp;answer=1211158&quot;&gt;Google Webmaster&lt;/a&gt;
documentation, they recommend do use the microdata from &lt;a href=&quot;http://schema.org&quot;&gt;schema.org&lt;/a&gt;, which is a
schema made by search providers like Bind, Google, Yahoo! and Yandex. The schema contains a lot of types
useful for you website. This works very well in many cases, but some times it requires layout changes to
fit well.&lt;/p&gt;

&lt;p&gt;Before I explain the problem, a little description of microdata in HTML5. Most of HTML tags can have the
attributes &lt;code class=&quot;highlighter-rouge&quot;&gt;itemprop&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;itemscope&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;itemtype&lt;/code&gt;. The &lt;code class=&quot;highlighter-rouge&quot;&gt;itemprop&lt;/code&gt; define the property name and usually the
content of the tag is the value, for example a name. &lt;code class=&quot;highlighter-rouge&quot;&gt;itemscope&lt;/code&gt; define a block of properties, for example
a product. &lt;code class=&quot;highlighter-rouge&quot;&gt;itemtype&lt;/code&gt; contains the URL which contais the definition of the &lt;code class=&quot;highlighter-rouge&quot;&gt;itemscope&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;It means that if you want to describe a product, you create a some &lt;code class=&quot;highlighter-rouge&quot;&gt;itemscope&lt;/code&gt; with, for example, a &lt;code class=&quot;highlighter-rouge&quot;&gt;div&lt;/code&gt;
and define all the properties there, like &lt;code class=&quot;highlighter-rouge&quot;&gt;name&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;price&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;reviews&lt;/code&gt;, etc. It sounds great and worked for
almost everything in the page, except one thing: breadcrumbs! The &lt;a href=&quot;http://schema.org/Product&quot;&gt;Product type&lt;/a&gt;
do not have any property for categories or breadcrumbs, it is part from the
&lt;a href=&quot;http://schema.org/WebPage&quot;&gt;WebPage type&lt;/a&gt;. But you can not define property for multiple scopes or in a
different scope with microdata.&lt;/p&gt;

&lt;p&gt;Unfortunately I didn’t find any solution with schema.org only, then I had to use schema.org and the
deprecated &lt;a href=&quot;http://www.data-vocabulary.org/&quot;&gt;data-vocabulary&lt;/a&gt;. The code in the end was something similar
with that:&lt;/p&gt;

&lt;script type=&quot;text/javascript&quot; src=&quot;https://gist.github.com/4287cc6dbfefafac8bb2.js&quot;&gt; &lt;/script&gt;

&lt;p&gt;This is not the best solution, but it was the balance between do not change the layout because the
microdata and have a nice presentation in search provider results. I hope the schema.org covers it once
breadcrumbs are not restricted to WebPage type or any of the sub-types.&lt;/p&gt;

&lt;p&gt;Do you have a better solution using microdata?&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>CakeFest 2012</title>
   <summary>Experiencie from our team in the CakeFest 2012</summary>
   <link href="http://tech.zumba.com/2012/09/18/cakefest-2012//"/>
   <author>
	<name>Juan Basso</name>
	<email>juan.basso@zumba.com</email>
   </author>
   <updated>2012-09-18T00:00:00+00:00</updated>
   <id>http://tech.zumba.com/2012/09/18/cakefest-2012</id>
   <content type="html">&lt;p&gt;This post is a little bit late, but two of our team participated in &lt;a href=&quot;http://cakefest.org&quot;&gt;CakeFest 2012&lt;/a&gt;.
This was a really nice event, with friendly people, and great topics.&lt;/p&gt;

&lt;p&gt;If you missed the event, you can check the slides on &lt;a href=&quot;https://joind.in/event/view/985&quot;&gt;Joind.in&lt;/a&gt;.
If you would like to see the pictures, &lt;a href=&quot;http://www.facebook.com/media/set/?set=a.10151390633853135.572122.339964833134&amp;amp;type=1&quot;&gt;Facebook&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Thanks Zumba&lt;sup&gt;®&lt;/sup&gt; for this opportunity. Thanks to everybody that helped to organize CakeFest and everybody we met there.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Our First Presentation - Javascript the important bits</title>
   <summary>Zumba&amp;reg;'s First Training Presentation - Javascript the important bits</summary>
   <link href="http://tech.zumba.com/2012/09/11/first-zumba-presentation//"/>
   <author>
	<name>Chris Saylor</name>
	<email>christopher.saylor@zumba.com</email>
   </author>
   <updated>2012-09-11T00:00:00+00:00</updated>
   <id>http://tech.zumba.com/2012/09/11/first-zumba-presentation</id>
   <content type="html">&lt;p&gt;Part of being a web developer is having to work with multiple languages and multiple technologies.  We are in the process of moving all our front-end javascript to &lt;a href=&quot;http://backbonejs.org&quot;&gt;backbone.js&lt;/a&gt;, and I thought it would be a good idea to have a refresher on javascript and jQuery to get the team in the right mindset during this transition.&lt;/p&gt;

&lt;p&gt;Our first presentation has been put on our public &lt;a href=&quot;http://www.slideshare.net/zumbatech&quot;&gt;slideshare&lt;/a&gt; account: &lt;a href=&quot;http://www.slideshare.net/zumbatech/javascript-the-importantbits&quot;&gt;Javascript: the Important Bits&lt;/a&gt;.&lt;/p&gt;

&lt;div style=&quot;text-align: center&quot;&gt;
	&lt;iframe src=&quot;http://www.slideshare.net/slideshow/embed_code/14234104&quot; width=&quot;427&quot; height=&quot;356&quot; frameborder=&quot;0&quot; marginwidth=&quot;0&quot; marginheight=&quot;0&quot; scrolling=&quot;no&quot; style=&quot;border:1px solid #CCC;border-width:1px 1px 0;margin-bottom:5px&quot; allowfullscreen=&quot;allowfullscreen&quot;&gt; &lt;/iframe&gt;
&lt;/div&gt;

&lt;p&gt;In the near future, we’re also doing something similar for PHP, including new 5.4 features, namespaces with autoload, and other similar topics.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Symbiosis Project Open Sourced</title>
   <summary>Zumba&amp;reg;'s first open source project, Symbiosis, has been open sourced.</summary>
   <link href="http://tech.zumba.com/2012/08/21/symbiosis-open-sourced//"/>
   <author>
	<name>Chris Saylor</name>
	<email>christopher.saylor@zumba.com</email>
   </author>
   <updated>2012-08-21T00:00:00+00:00</updated>
   <id>http://tech.zumba.com/2012/08/21/symbiosis-open-sourced</id>
   <content type="html">&lt;p&gt;I’m excited to announce that we have open-sourced our first project: &lt;a href=&quot;https://github.com/zumba/symbiosis&quot;&gt;Symbiosis&lt;/a&gt;.  &lt;a href=&quot;https://github.com/zumba/symbiosis&quot;&gt;Symbiosis&lt;/a&gt; is a PHP library that allows for easy integration of an event driven plugin system to any PHP project.  It also allows the event system to be used stand-alone from the plugin system.&lt;/p&gt;

&lt;h3 id=&quot;plug-me-in&quot;&gt;Plug Me In&lt;/h3&gt;

&lt;p&gt;In a &lt;a href=&quot;http://tech.zumba.com/2012/08/04/using-application-events-to-hook-in-plugins/&quot;&gt;previous post&lt;/a&gt;, I described how we used a rudamentary event system to modularize our cart system.  Now, we’ve taken a big step in making that sort of modularization easy to implement in many of our projects, and hopefully many of yours.  There are many differences between our example in the &lt;a href=&quot;http://tech.zumba.com/2012/08/04/using-application-events-to-hook-in-plugins/&quot;&gt;previous post&lt;/a&gt; and our open-sourced version:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;The event that gets passed to the listeners is now an object.  Instead of just passing an array of data, we pass an event object. Not only is the data available, but several key flow control methods as well.  Such as stopping propagation of the event, suggesting the client prevent further actions, as well as an easy way to trigger the event.&lt;/li&gt;
  &lt;li&gt;We’ve included the plugin system.  Prior, we wrote off how to include the plugin, but with an event driven mechanism, I realized that this was an important step.  The plugin manager included with &lt;a href=&quot;https://github.com/zumba/symbiosis&quot;&gt;Symbiosis&lt;/a&gt; includes a couple of key attributes.  While developing with a rudamentary version of the plugin manager, I quickly realized that we needed to be able to control the order of some plugins.  I’ve added a priority order to the plugin framework that allows you to set the order in which the plugins are executed.  I’ve also added the ability to disable plugins from startup.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;example-of-symbiosis-in-action&quot;&gt;Example of Symbiosis in Action&lt;/h3&gt;

&lt;p&gt;With a few lines of code, you can see how easy it is to include a plugin system in your PHP project:&lt;/p&gt;

&lt;p&gt;First we construct our plugin:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/3414629.js?file=application_plugin.php&quot;&gt; &lt;/script&gt;

&lt;noscript&gt;All example code is available in a github gist: https://gist.github.com/3414629&lt;/noscript&gt;

&lt;p&gt;The plugin must extend &lt;code class=&quot;highlighter-rouge&quot;&gt;\Zumba\Symbiosis\Framework\Plugin&lt;/code&gt; to implement all the proper methods and have default attributes.&lt;/p&gt;

&lt;p&gt;Next, we register the plugins in the application bootstrap:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/3414629.js?file=application_bootstrap.php&quot;&gt; &lt;/script&gt;

&lt;p&gt;And finally, somewhere in our application, we need to trigger the event that the plugin is listening:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/3414629.js?file=application_somewhere.php&quot;&gt; &lt;/script&gt;

&lt;p&gt;When the event is triggered, the anonymous function we registered in our sample plugin should execute:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/3414629.js?file=output.txt&quot;&gt; &lt;/script&gt;

&lt;h3 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h3&gt;

&lt;p&gt;We found this project useful in our own applications, and we hope that you may find it useful as well.  We’ve included a way of installation either via a git submodule, &lt;a href=&quot;https://github.com/zumba/symbiosis/downloads&quot;&gt;download&lt;/a&gt;, or a &lt;a href=&quot;http://getcomposer.org/&quot;&gt;composer&lt;/a&gt; install.  The project has 100% code coverage in &lt;a href=&quot;http://www.phpunit.de/manual/current/en/&quot;&gt;PHPUnit&lt;/a&gt; tests, and we feel comfortable with it’s stability.&lt;/p&gt;

&lt;p&gt;You can see more examples and full documentation on the &lt;a href=&quot;https://github.com/zumba/symbiosis/wiki&quot;&gt;Symbiosis Wiki&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you see anything that could be improved, let us know by opening an issue in the github project, or submit a patch.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Creating bash completion to your console application</title>
   <summary>Shows how to create a file compatible with bash_completion.d and interact with user application</summary>
   <link href="http://tech.zumba.com/2012/08/20/creating-bash-completion//"/>
   <author>
	<name>Juan Basso</name>
	<email>juan.basso@zumba.com</email>
   </author>
   <updated>2012-08-20T00:00:00+00:00</updated>
   <id>http://tech.zumba.com/2012/08/20/creating-bash-completion</id>
   <content type="html">&lt;p&gt;The number of console applications are growing more and more in web application environment. Many frameworks of
many languages uses it and save a lot of time from developers and sysops to do some operations or even create
cron jobs.&lt;/p&gt;

&lt;p&gt;In our company it is not different. We use tons of jobs to do many operations and sometimes makes hard to
remember the exactly name of the jobs. To simplify a little bit, we implemented support to
&lt;a href=&quot;http://bash-completion.alioth.debian.org/&quot;&gt;bash completion&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Our jobs has a “starter” (common executable file, which load the configurations, basic stuffs, and run the
target operation), similar the frameworks. In our case, we call &lt;code class=&quot;highlighter-rouge&quot;&gt;/app_folder/job ClassName [methodName]&lt;/code&gt; and
the &lt;code class=&quot;highlighter-rouge&quot;&gt;job&lt;/code&gt; is just a shell script to execute &lt;code class=&quot;highlighter-rouge&quot;&gt;php job.php $@&lt;/code&gt;. The &lt;code class=&quot;highlighter-rouge&quot;&gt;job.php&lt;/code&gt; do the bootstrap part and loads
the classname from the first parameter in a specific namespace. For example, our base namespace is
&lt;code class=&quot;highlighter-rouge&quot;&gt;Zumba\Job&lt;/code&gt;, if you pass &lt;code class=&quot;highlighter-rouge&quot;&gt;job Engineering&lt;/code&gt; it will try to load the class &lt;code class=&quot;highlighter-rouge&quot;&gt;Zumba\Job\Engineering&lt;/code&gt;.
By default we call the method &lt;code class=&quot;highlighter-rouge&quot;&gt;execute&lt;/code&gt;, but if you pass the second parameter we try to run that method
instead of &lt;code class=&quot;highlighter-rouge&quot;&gt;execute&lt;/code&gt;, making one job class reusable for multiple actions.&lt;/p&gt;

&lt;p&gt;This weekend I saw the &lt;a href=&quot;https://github.com/AD7six/cakephp-completion&quot;&gt;bash completion for CakePHP&lt;/a&gt; from
&lt;a href=&quot;http://ad7six.com/&quot;&gt;Andy Dawson&lt;/a&gt; and had an idea to do the same for our service application, because
we frequently forget the exactly job class or method name and add extra steps to verify these names
before execute the job. I read his code, made some research and finally get our bash completion working
fine.&lt;/p&gt;

&lt;p&gt;First thing you need to do is make your application returns the available options for the first and
second parameter. It means you will be able to get the available options from console by executing some
command. PS: If your application do not change often or you don’t want or can update your app, you can have
the parameters hard coded in the bash completion script.&lt;/p&gt;

&lt;p&gt;In our case, I could add a job class to get that informaiton, but I prefered to use a symbolic method and
parse with an &lt;code class=&quot;highlighter-rouge&quot;&gt;if&lt;/code&gt; in the &lt;code class=&quot;highlighter-rouge&quot;&gt;job.php&lt;/code&gt; file. I used that way to avoid create a job class for this proposal and
be one more in the list and share the structure from the others methods, which is a little complicated
(we have some logs, register execution, etc.). But few free to do the way you want. In the end, you can run
my script like &lt;code class=&quot;highlighter-rouge&quot;&gt;job __check__&lt;/code&gt; to get the available classes or &lt;code class=&quot;highlighter-rouge&quot;&gt;job __check__ SpecificJobClass&lt;/code&gt; to get
the available methods.&lt;/p&gt;

&lt;p&gt;The PHP portion is basically that:&lt;/p&gt;

&lt;script type=&quot;text/javascript&quot; src=&quot;https://gist.github.com/3398491.js&quot;&gt;&lt;/script&gt;

&lt;noscript&gt;The code is available on &lt;a href=&quot;https://gist.github.com/3398491&quot;&gt;https://gist.github.com/3398491&lt;/a&gt;&lt;/noscript&gt;

&lt;p&gt;With that, from the console we are able to execute the check (&lt;code class=&quot;highlighter-rouge&quot;&gt;job __check__&lt;/code&gt;) and the list of available jobs:
&lt;code class=&quot;highlighter-rouge&quot;&gt;Job1 MyCustom MyApp TopSecret StopTheCompany&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This was the first step from the script. The second part is get a list of the available methods, ie when
execute the &lt;code class=&quot;highlighter-rouge&quot;&gt;job __check__ StopTheCompany&lt;/code&gt; we get something like: &lt;code class=&quot;highlighter-rouge&quot;&gt;shutdownServers dropDatabase removeAppCode&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now is time to make the bash interact with your code. You need to create a script in your
&lt;code class=&quot;highlighter-rouge&quot;&gt;/etc/bash_completion.d/&lt;/code&gt; folder, with permission 0644. It will be like the code below.&lt;/p&gt;

&lt;script type=&quot;text/javascript&quot; src=&quot;https://gist.github.com/3398516.js&quot;&gt;&lt;/script&gt;

&lt;noscript&gt;The code is available on &lt;a href=&quot;https://gist.github.com/3398516&quot;&gt;https://gist.github.com/3398516&lt;/a&gt;&lt;/noscript&gt;

&lt;p&gt;To explain a bit, the last line will tell bash to complete the executable &lt;code class=&quot;highlighter-rouge&quot;&gt;job&lt;/code&gt; using the function
&lt;code class=&quot;highlighter-rouge&quot;&gt;_my_application&lt;/code&gt; (defined few lines above). The function basically test the number of parameters and
call your application with the current parameters and transmit to the bash completion. In our case, we have
just two parameters, as you can see.&lt;/p&gt;

&lt;p&gt;After save the file in the &lt;code class=&quot;highlighter-rouge&quot;&gt;/etc/bash_completion.d&lt;/code&gt; restart your bash/console/terminal and you can try to
use the completion. I guess I don’t need to put some examples how to use or how it looks like. If you never
used bash completion it is not the place to get started.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Creating a testing interface for your API</title>
   <summary>Tired to use curl, crap scripts, remember fields to test your API? Make a simple interface to make it easily.</summary>
   <link href="http://tech.zumba.com/2012/08/16/test-interface//"/>
   <author>
	<name>Juan Basso</name>
	<email>juan.basso@zumba.com</email>
   </author>
   <updated>2012-08-16T00:00:00+00:00</updated>
   <id>http://tech.zumba.com/2012/08/16/test-interface</id>
   <content type="html">&lt;p&gt;Couple months ago we started an integration with &lt;a href=&quot;http://www.ooyala.com&quot;&gt;Ooyala&lt;/a&gt;, using JSON API.
They provide the &lt;a href=&quot;http://support.ooyala.com/developers/documentation/concepts/book_api.html&quot;&gt;documentation&lt;/a&gt; to the methods
and I saw they have a simple interface to test their methods: &lt;a href=&quot;https://api.ooyala.com/docs/api_scratchpad?url=/assets&amp;amp;method=GET&quot;&gt;Ooyala API Scratchpad&lt;/a&gt;.
This interface was very useful while we integrate with them and I thought: &lt;em&gt;“Why we don’t have one interface like that for our API?”&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I started a page with &lt;a href=&quot;http://twitter.github.com/bootstrap/&quot;&gt;Twitter Bootstrap&lt;/a&gt; to have a similar functionality, which the goal
was to get an interface easy to developers see the response for multiple HTTP protocols, set the parameters, etc.
The initial page looks like this:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://tech.zumba.com/img/blog/test-interface-1.png&quot; alt=&quot;API Test Page&quot; /&gt;&lt;/p&gt;

&lt;p&gt;For the request, I used &lt;a href=&quot;http://jquery.com&quot;&gt;jQuery&lt;/a&gt; AJAX. It means that some HTTP methods (usually &lt;code class=&quot;highlighter-rouge&quot;&gt;PUT&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;DELETE&lt;/code&gt;)
are not supported by old browsers, but we don’t care as it is an internal tool and everybody uses Chrome or Firefox.
Doing the request you get a JSON response formatted, like that:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://tech.zumba.com/img/blog/test-interface-2.png&quot; alt=&quot;API Test Page Response&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Developers liked this page, but it wasn’t good enough to me. Then I get the response from
&lt;a href=&quot;http://tech.zumba.com/2012/08/05/self-documentation/&quot;&gt;Creating Self Documentation to your API&lt;/a&gt; (also thru AJAX) and made an
autocomplete integrated with the parameters generation. Resulting something like that:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://tech.zumba.com/img/blog/test-interface-3.png&quot; alt=&quot;API Test Page Autocomplete&quot; /&gt;
&lt;img src=&quot;http://tech.zumba.com/img/blog/test-interface-4.png&quot; alt=&quot;API Test Page Parameters&quot; /&gt;&lt;/p&gt;

&lt;p&gt;This exemplifies how the annotations are important. We get all the API methods, method descriptions, method parameters,
HTTP method, etc. from the annotation and generate nice pages like that.&lt;/p&gt;

&lt;p&gt;The productivity of using this page was greatly improved with not having to toggle between the tester and the documentation.
As it is an internal tool, why not complement adding some request log in this tool to show possible errors or behaviors?!
I got some help from &lt;a href=&quot;http://www.chromephp.com/&quot;&gt;ChromePHP&lt;/a&gt; (that put log messages on the response header), integrated
with our log system and then parsed it from the response, showing in the page as well.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://tech.zumba.com/img/blog/test-interface-5.png&quot; alt=&quot;API Test Page Logs&quot; /&gt;&lt;/p&gt;

&lt;p&gt;After have it in our API, we started this blog and looking the &lt;a href=&quot;http://disqus.com/api/docs/&quot;&gt;Disqus API&lt;/a&gt; I saw they have
a similar tool called &lt;a href=&quot;http://disqus.com/api/console/&quot;&gt;Disqus Console&lt;/a&gt;. Again, it helped me with some integration.
If you have an API, make this type of tool for you client. He definitely will like it.&lt;/p&gt;

&lt;h3 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h3&gt;

&lt;p&gt;I spent one day to create this tool and people are saving time every day. It means sometimes you should take a break
and spend some time doing simple tools to gain in long term.&lt;/p&gt;

&lt;p&gt;You can see what annotations, some open source projects and few lines of code are able to do. Use it! As I told
in the annotations post, it is a simple thing with many benefits.&lt;/p&gt;

&lt;p&gt;Do you want the code of that page? Sure, why not?! &lt;a href=&quot;https://gist.github.com/3365894&quot;&gt;https://gist.github.com/3365894&lt;/a&gt;.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Tech Team at Zumba Convention 2012</title>
   <summary>Tech team also have fun in the company and went to Zumba Instructor Convention 2012</summary>
   <link href="http://tech.zumba.com/2012/08/13/zumba-convention-2012//"/>
   <author>
	<name>Juan Basso</name>
	<email>juan.basso@zumba.com</email>
   </author>
   <updated>2012-08-13T00:00:00+00:00</updated>
   <id>http://tech.zumba.com/2012/08/13/zumba-convention-2012</id>
   <content type="html">&lt;p&gt;This weekend happened the &lt;a href=&quot;http://convention.zumba.com&quot;&gt;Zumba® Instructor Convention 2012&lt;/a&gt;, a meeting
between thousands of &lt;abbr title=&quot;Zumba Instructor Network&quot;&gt;ZIN™&lt;/abbr&gt; members. It happens every year
and all the home office is invited to attend and participate. It is an odd experience that we hadn’t in any
other company and it’s a great opportunity to get feedback from our users and not only from our boss, that
sometimes don’t reflect the reality.&lt;/p&gt;

&lt;p&gt;As the convention happened during business days, we closed the IT department and went there to have some fun,
exercise (even if it’s just walking around, because as you know mostly IT people are not dancers, further
between professionals), party, interact and for some craziness.&lt;/p&gt;

&lt;p&gt;This kind of opportunity is nice to see that you helped to make that happen, people are happy and having fun
together because you made your job. It is very gratifying and, my friend, no money can pay it. Back in the
office you can see the results too, just look in the face and behavior from people, they look more friendly
and relaxed, what is improving the productivity.&lt;/p&gt;

&lt;p&gt;Below you can see a picture with few people from our department in the convention. Yes, we are with this
sleepy-face because we were in the Daddy Yankee show in the previous night.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://tech.zumba.com/img/blog/it_conv2012.jpg&quot; alt=&quot;IT Team Picture&quot; /&gt;
Left to right: Daniel Matsinger, Girish Raut, Cristiano da Silva, Chris Saylor, Ralph Valdes, Juan Basso&lt;/p&gt;

&lt;p&gt;If you think it is just one more convention, look how is that convention…&lt;/p&gt;

&lt;div style=&quot;text-align: center&quot; itemprop=&quot;video&quot; itemscope=&quot;itemscope&quot; itemtype=&quot;http://schema.org/VideoObject&quot;&gt;
	&lt;meta itemprop=&quot;url&quot; content=&quot;http://youtu.be/aiTfMQw2Joc&quot; /&gt;
	&lt;iframe itemprop=&quot;embedUrl&quot; width=&quot;560&quot; height=&quot;315&quot; src=&quot;http://www.youtube-nocookie.com/embed/aiTfMQw2Joc&quot; frameborder=&quot;0&quot; allowfullscreen=&quot;allowfullscreen&quot;&gt; &lt;/iframe&gt;
&lt;/div&gt;
</content>
 </entry>
 
 <entry>
   <title>Frisby.js or&amp;#58; How I Learned to Stop Worrying and Love the Service Test</title>
   <summary>Using Frisby.js to test API endpoints at the request level.</summary>
   <link href="http://tech.zumba.com/2012/08/11/using-frisbyjs-to-test-api-endpoints//"/>
   <author>
	<name>Chris Saylor</name>
	<email>christopher.saylor@zumba.com</email>
   </author>
   <updated>2012-08-11T00:00:00+00:00</updated>
   <id>http://tech.zumba.com/2012/08/11/using-frisbyjs-to-test-api-endpoints</id>
   <content type="html">&lt;p&gt;Writing a public facing API can be a daunting task, and making sure your endpoints behave how your customers and partners expect is always a challenge.  In this article, I will go over how to use &lt;a href=&quot;http://nodejs.org/&quot;&gt;NodeJS&lt;/a&gt;, &lt;a href=&quot;http://frisbyjs.com/&quot;&gt;Frisby.js&lt;/a&gt;, and &lt;a href=&quot;https://github.com/mhevery/jasmine-node/&quot;&gt;Jasmine-node&lt;/a&gt; to test your API, and how to involve your customers and partners in the process.&lt;/p&gt;

&lt;h3 id=&quot;behavior-driven-development&quot;&gt;Behavior Driven Development&lt;/h3&gt;

&lt;p&gt;Frisby.js and Jasmine are very conducive to the idea of &lt;abbr title=&quot;Behavior Driven Development&quot;&gt;BDD&lt;/abbr&gt;.  When creating an API (especially in conjunction with a partner), &lt;abbr title=&quot;Behavior Driven Development&quot;&gt;BDD&lt;/abbr&gt; is a fantastic way to drive coordination between &lt;del&gt;business requirements&lt;/del&gt; user stories and code.  Frisby.js gives a nice set of methods to turn a user story into a functioning test case.&lt;/p&gt;

&lt;h3 id=&quot;writing-frisbyjs-test-cases&quot;&gt;Writing Frisby.js Test Cases&lt;/h3&gt;

&lt;p&gt;Suppose you have a user story about getting a user’s profile by ID and returning some basic information.  The test you would write would be similar to this:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/297ca7d642b380867188.js&quot;&gt; &lt;/script&gt;

&lt;noscript&gt;The code is available on &lt;a href=&quot;https://gist.github.com/297ca7d642b380867188&quot;&gt;https://gist.github.com/297ca7d642b380867188&lt;/a&gt;&lt;/noscript&gt;

&lt;p&gt;To execute the above test, execute the following from the command line:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;jasmine-node --verbose&lt;/code&gt;&lt;/p&gt;

&lt;h3 id=&quot;integrating-with-partners-and-customers&quot;&gt;Integrating with Partners and Customers&lt;/h3&gt;

&lt;p&gt;Communicating problems, changes, and features of an API to a partner or customer can be problematic.  Our approach was to separate this kind of testing framework for the API from our internal API repository.  This way, we can share the API test repository, allow the tests to show some example uses of the API, and provide an avenue for partners to report an issue.&lt;/p&gt;

&lt;p&gt;With the use of &lt;a href=&quot;https://github.com&quot;&gt;Github&lt;/a&gt;, a partner can fork our testing repo at any time, write a test case for the issue they are having, and submit a pull request.  We can then verify by reproducing the issue from their pull request test case and truely know that we’ve resolved the partner’s issue when their own test case passes with the fix.&lt;/p&gt;

&lt;h3 id=&quot;caveats&quot;&gt;Caveats&lt;/h3&gt;

&lt;p&gt;There is a small drawback to service-level testing (as opposed to unit testing).  Since you’ll be making actual requests to your API, you don’t have the luxury of fixtures creating clean databases after the test case is run.  So, depending on the data changed in the request, you’d have to chain a cleanup method after the test case is run.&lt;/p&gt;

&lt;p&gt;Also, as opposed to unit tests, the failed test will not pinpoint in the code where the error happens, so you’d need to rely on other tools, such as logging, to find the issue in the source.&lt;/p&gt;

&lt;h3 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h3&gt;

&lt;p&gt;With a BDD approach and the use of some clever testing tools, it’s easier than ever to test an externally available service for full coverage and to provide a better channel of communication with partners to resolve bugs and implement features.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Creating Self Documentation to your API</title>
   <summary>Show an idea how to self document the API endpoints using code</summary>
   <link href="http://tech.zumba.com/2012/08/05/self-documentation//"/>
   <author>
	<name>Juan Basso</name>
	<email>juan.basso@zumba.com</email>
   </author>
   <updated>2012-08-05T00:00:00+00:00</updated>
   <id>http://tech.zumba.com/2012/08/05/self-documentation</id>
   <content type="html">&lt;p&gt;When we started our internal web-service we had a problem between the team that works in
the web-service application and the front end developers because the front end
developers didn’t know exactly what was the expected parameters, endpoints, HTTP verb,
etc. This increased the delay in delivery features and in some cases caused a few bugs.&lt;/p&gt;

&lt;p&gt;Looking at the problem, &lt;a href=&quot;https://github.com/cjsaylor&quot;&gt;Chris Saylor&lt;/a&gt; had a great
idea to use the controller annotation and generate a page with that. He started with
some proof of concept, which was very well accepted by the front end developers and than
Chris and I improved that page content and layout.&lt;/p&gt;

&lt;p&gt;As part of the page content improvement, we started to use our own annotations, similar
many projects do, ie:
- &lt;a href=&quot;http://www.phpdoc.org/docs/latest/for-users/list-of-tags.html&quot;&gt;PHPDoc&lt;/a&gt;
- &lt;a href=&quot;http://www.phpunit.de/manual/current/en/appendixes.annotations.html&quot;&gt;PHPUnit&lt;/a&gt;
- &lt;a href=&quot;http://doctrine-orm.readthedocs.org/en/latest/reference/annotations-reference.html&quot;&gt;Doctrine&lt;/a&gt;
- &lt;a href=&quot;http://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/index.html#annotations-for-controllers&quot;&gt;Symfony&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We created tags like &lt;code class=&quot;highlighter-rouge&quot;&gt;@inputParam&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;@optionalInputParam&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;@returnParam&lt;/code&gt;, etc. It helped
us to create a more useful documentation page, with more relevant information for front end
developers instead of a regular PHP documentation that doesn’t help front end developers at all.&lt;/p&gt;

&lt;p&gt;In our web-service we created a method that reponse HTML or JSON, depending of
&lt;code class=&quot;highlighter-rouge&quot;&gt;Accept&lt;/code&gt; header. If the browser requests the site, it accepts &lt;code class=&quot;highlighter-rouge&quot;&gt;text/html&lt;/code&gt; and we provide a
HTML page using &lt;a href=&quot;http://twitter.github.com/bootstrap/&quot;&gt;Twitter Bootstrap&lt;/a&gt; with
&lt;a href=&quot;http://jquery.com&quot;&gt;jQuery&lt;/a&gt; and make an AJAX request to the same URL, getting the JSON version
(that is usually what our web-service response) and generating the HTML with all URI and
parameters required for that.&lt;/p&gt;

&lt;p&gt;Below is an example of our JSON response:&lt;/p&gt;

&lt;script type=&quot;text/javascript&quot; src=&quot;https://gist.github.com/3266700.js&quot;&gt; &lt;/script&gt;

&lt;noscript&gt;The code is available on &lt;a href=&quot;https://gist.github.com/3266700&quot;&gt;https://gist.github.com/3266700&lt;/a&gt;&lt;/noscript&gt;

&lt;p&gt;With jQuery we loop thru all the controllers and actions and generate the page. Also we
have a search with jQuery to filter results, making the life much easier to front end
developers.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://tech.zumba.com/img/blog/service_documentation.png&quot; alt=&quot;Service Documentation Sample View&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Before you ask why we separate the HTML in one file and the content in an AJAX, the answer is
simple. Our web-service is designed to performance and always response in JSON (yes, we can
support different outputs, but it is our internal web-service and we don’t want to add more
complexity). The HTML portion is a static file, not a PHP file. Another reason is make
this method reusable, like we have for our web test interface (I will describe in another
post).&lt;/p&gt;

&lt;script type=&quot;text/javascript&quot;&gt;
	// Hack to fix the reddit link, because this link was inserted without the end slash
	reddit_url = 'http://engineering.zumba.com/2012/08/05/self-documentation';
&lt;/script&gt;

</content>
 </entry>
 
 <entry>
   <title>Using Application Events to Hook in Plugins</title>
   <summary>How to use application level events to encapsulate core code from add-on code.</summary>
   <link href="http://tech.zumba.com/2012/08/04/using-application-events-to-hook-in-plugins//"/>
   <author>
	<name>Chris Saylor</name>
	<email>christopher.saylor@zumba.com</email>
   </author>
   <updated>2012-08-04T00:00:00+00:00</updated>
   <id>http://tech.zumba.com/2012/08/04/using-application-events-to-hook-in-plugins</id>
   <content type="html">&lt;p&gt;In many instances, having a plugin system (even for closed-source applications) is a convenient and safe approach to adding functionality to a product.  It minimizes risk by not having to modify the core of the source.  In this article, I’ll be discussing how we implemented a plugin system for our cart software to allow for plugins.&lt;/p&gt;

&lt;h3 id=&quot;benefits-of-plugins-versus-adding-the-functionality-in-place&quot;&gt;Benefits of Plugins versus Adding the functionality in Place&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;It prevents gargantuan classes to handle every situation that your software might need to handle.&lt;/li&gt;
  &lt;li&gt;Allows for easier testing of the individual plugins.&lt;/li&gt;
  &lt;li&gt;Provides various ways of including the plugins (including ways for filtering in specific situations).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;event-horizon&quot;&gt;Event Horizon&lt;/h3&gt;

&lt;p&gt;Application events come in many shapes and sizes.  We chose to utilize a static class for “registering” the event to a callback method.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/efc61cb87783055d3c9e.js&quot;&gt; &lt;/script&gt;

&lt;noscript&gt;The code is available on &lt;a href=&quot;https://gist.github.com/efc61cb87783055d3c9e&quot;&gt;https://gist.github.com/efc61cb87783055d3c9e&lt;/a&gt;&lt;/noscript&gt;

&lt;p&gt;This adds a callable entry to the events array per event “tag”.  Notice that &lt;code class=&quot;highlighter-rouge&quot;&gt;$events&lt;/code&gt; can be an array, so assigning multiple events to the same callback is very easy to do.  Now all we need is a way to trigger the events we register to this class at runtime.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/36bd768ec37fdd697e81.js&quot;&gt; &lt;/script&gt;

&lt;noscript&gt;The code is available on &lt;a href=&quot;https://gist.github.com/36bd768ec37fdd697e81&quot;&gt;https://gist.github.com/36bd768ec37fdd697e81&lt;/a&gt;&lt;/noscript&gt;

&lt;p&gt;When triggering an event, we simply pass an array of data to the callback that was registered.  So all our callbacks should have a signature similar to: &lt;code class=&quot;highlighter-rouge&quot;&gt;public function someCallback($data = array())&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now we have all the tools we need in order to start registering and triggering events.&lt;/p&gt;

&lt;p&gt;Many frameworks have started to provide this kind of application runtime events (which inspired this kind of system), such as &lt;a href=&quot;http://book.cakephp.org/2.0/en/core-libraries/events.html&quot;&gt;CakePHP 2.x&lt;/a&gt;, as well as ORMs such as &lt;a href=&quot;http://doctrine-orm.readthedocs.org/en/latest/reference/events.html&quot;&gt;Doctrine2&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&quot;plug-and-play&quot;&gt;Plug and Play&lt;/h3&gt;

&lt;p&gt;Now that we have our event system in place, it’s time to use it for our plugins.  There are many ways to include a “plugin” structure that I won’t cover here.  What I will cover is once you have your plugin included, how to use our event system to call it.&lt;/p&gt;

&lt;p&gt;We have several uses for plugins for our cart system. Chief among them is refreshing the status of the items in the cart on certain actions, such as when adding an item to the cart.  When structuring our plugin using an event system, we just need to expose a registration method that registers its own callbacks to all the events that it should listen for and react to when operations occur on the cart.  For example:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/9acaa7d1504e57ece36e.js&quot;&gt; &lt;/script&gt;

&lt;noscript&gt;The code is available on &lt;a href=&quot;https://gist.github.com/9acaa7d1504e57ece36e&quot;&gt;https://gist.github.com/9acaa7d1504e57ece36e&lt;/a&gt;&lt;/noscript&gt;

&lt;h3 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h3&gt;

&lt;p&gt;With this type of setup, when we need additional things to happen on certain actions, we don’t have to go back and modify the core part of the app and risk introducing regression errors.  We simply write a plugin, register the event, and can concentrate the unit tests on the plugin callbacks themselves.&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>CakePHP and Code Coverage</title>
   <summary>How to ignore CakePHP core files from code coverage in Jenkins when testing the application.</summary>
   <link href="http://tech.zumba.com/2012/08/03/cakephp-test-and-code-coverage//"/>
   <author>
	<name>Juan Basso</name>
	<email>juan.basso@zumba.com</email>
   </author>
   <updated>2012-08-03T00:00:00+00:00</updated>
   <id>http://tech.zumba.com/2012/08/03/cakephp-test-and-code-coverage</id>
   <content type="html">&lt;p&gt;Recently we started a new API application in &lt;a href=&quot;http://www.cakephp.org&quot;&gt;CakePHP&lt;/a&gt; 2.2 and put some code and unit tests.
When we put the code in &lt;a href=&quot;http://jenkins-ci.org/&quot;&gt;Jenkins CI&lt;/a&gt; to a continuous integration we setup the code coverage
and in the reports we got couple CakePHP core files as not covered.&lt;/p&gt;

&lt;p&gt;Our application doesn’t care about cover Cake files, and we also don’t want to include Cake core tests in our
&lt;abbr title=&quot;Continuous Integration&quot;&gt;CI&lt;/abbr&gt;. Leaving these files in CI give reports that our code is not well
covered, which it is not true and hide the uncovered code from our app.&lt;/p&gt;

&lt;p&gt;As CakePHP, we also use &lt;a href=&quot;http://www.phpunit.de&quot;&gt;PHPUnit&lt;/a&gt; in other project, but there we use the &lt;code class=&quot;highlighter-rouge&quot;&gt;phpunit.xml&lt;/code&gt;
configuration file. Using the configuration file is easy to put folders/files on
&lt;a href=&quot;http://www.phpunit.de/manual/current/en/code-coverage-analysis.html&quot;&gt;black and white lists&lt;/a&gt;, but it is not possible when
using CakePHP because it has their own runner system. Our solution was figure out a way using code. We changed our
test suite to do it, see below.&lt;/p&gt;

&lt;script type=&quot;text/javascript&quot; src=&quot;https://gist.github.com/3260166.js&quot;&gt; &lt;/script&gt;

&lt;noscript&gt;The code is available on &lt;a href=&quot;https://gist.github.com/3260166&quot;&gt;https://gist.github.com/3260166&lt;/a&gt;&lt;/noscript&gt;

&lt;p&gt;With the code above you can run in your console: &lt;code class=&quot;highlighter-rouge&quot;&gt;./Console/cake test app AllApp --coverage-html=./report&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You can replace the &lt;code class=&quot;highlighter-rouge&quot;&gt;--coverage-html&lt;/code&gt; by &lt;code class=&quot;highlighter-rouge&quot;&gt;--coverage-clover&lt;/code&gt; to use in Jenkins (or both, like in our case).&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>Kicking Off the Blog</title>
   <summary>This article just explain the goals of this blog and to announce open source projects from the company</summary>
   <link href="http://tech.zumba.com/2012/07/21/kicking-off-the-blog//"/>
   <author>
	<name>Chris Saylor</name>
	<email>christopher.saylor@zumba.com</email>
   </author>
   <updated>2012-07-21T00:00:00+00:00</updated>
   <id>http://tech.zumba.com/2012/07/21/kicking-off-the-blog</id>
   <content type="html">&lt;p&gt;Zumba Fitness&lt;sup&gt;®&lt;/sup&gt;’s techology department will begin blogging about the technology that we use,
the problems that we encounter, and the cool things that’s in development.&lt;/p&gt;

&lt;p&gt;We’ll also use this as a platform to announce projects that our team has decided to
open-source.  We look forward to feedback (and hopefully some pull-requests) from
the community.&lt;/p&gt;
</content>
 </entry>
 
 
</feed>
