Felipe Oliveira
Blog about Java and Scala from Enterprise-Class Web Consultant.
Saturday, July 2, 2011
Friday, April 8, 2011
Saturday, March 12, 2011
Wednesday, March 2, 2011
CookieBaker: Dead Simple Java Library to Use HTTP Cookies as POJOs
CookieBaker is a dead simple Java library to read and write cookies in POJO form to avoid string splits and joins all over your codebase. Behind the scenes CookieBaker stores the cookie in JSON format using Jackson. CookieBaker also provides HMAC support, currently using SHA1 by default.
Usage
Define a simple Pojo with a default constructor
public class SampleObject implements Serializable { private String myString; public SampleObject() {} public String getMyString() { return myString; } public void setMyString(String myString) { this.myString = myString; } }Set Cookie
CookieBaker.saveCookie(response, cookieName, mySampleObjectInstance);
Get Cookie
SampleObject o = CookieBaker.getCookie(request, SampleObject.class, cookieName);
Install
git clone git@github.com:feliperazeek/CookieBaker.git
cd CookieBaker
mvn install
Import jar to your CLASSPATH or add Maven dependency to your project.
<dependency> <groupId>geeks.aretotally.in</groupId> <artifactId>cookiebaker</artifactId> <version>0.1</version> </dependency>
Roadmap
Integrate HTML5 Local Storage with browser auto-detection.
Thursday, February 24, 2011
Interviewing with Google - Part 1
Last year I had a life changing experience, I got a total unexpected email, a couple actually, from Google inquiring for an interview. It was a position with Google's engineering team in Mountain Ville, California, a dream come true for any programmer, engineer, sysadmin or whatever you call yourself. I was ecstatic, it didn't feel real, it seemed like a dream, just a dream.
I had a first screening with a HR person and I felt it went great, the recruiter was an ex-programmer from Boston, he owned his own software company before joining Google. From what I had researched online he seemed to have some real skills, I went through some of his opensource code, I started to feel some butterflies. A couple of days later I got a call from him and the conversation went great, I told him what I was all about and I could tell he appreciated my passion and my appreciation for our profession. I kept wondering why he would left his own software company to be a recruiter for Google, but then again, it was Google! Apparently the conversation went so well I got upgraded to a Senior Recruiter, I didn't really know what that meant; unfortunately after our first call I didn't feel that great. But I couldn't help myself but have California Dreams with my partner in crime.
The first interview was scheduled for a couple of weeks later and that's when my journey begun. I did some research and it was clear I had to master three things: Data Structures, Algorithms and Big-O notation; most of us obviously use all three things at some level on a daily basis, but only at a some level. I knew I had to master it! I was determined to make it happen, whatever it cost, however much effort it would take. My first decision was to cut off all my extra curriculum activities, I used to work out on a daily basis, a combination of daily sessions of Brazilian Jiu Jitsu and Crossfit, crossed that off my schedule. I didn't stop my weekly private chess class, I figured that had to help somehow, it was chess. With my schedule cleared I had to start thinking about how to move forward; I went to Amazon and bought a few books to prepare myself. After putting aside all my extra curriculum activities, forgetting I had a social life, reading for two days straight and doing exercises on sites like TopCoder.com, I realized I needed help; I had to progress faster. I just couldn't accept I didn't know everything in two whole days of studying, I was never very patient. I was never the "scholar" type either, I made my career, a successful one so far, by being smart, fast, being able to make things happen and understanding the business; but I was never one who could teach about the mastery of different types of binary trees for example, I never felt the need to. Deep inside I felt it was a little silly actually, I obviously had a lot to learn.
At the same time, I was reading about all these bad experiences, horror stories and it made me nervous, very nervous. I was affraid to fail miserably for the first time in my life, but thankfully I had some great people around me. My partner who suffered the most throughout the process and who I am so thankful for; I had also had with me my friend, mentor and old-time confident Zack Preble. He's one of those guys you just appreciate to have crossed your path. I didn't want to disappoint him and I definetely didn't want to disappoint my family. I remember when I called my dad to tell him the news, he was so proud, and nothing in the world makes me happier than making my family proud. I frequently wonder why I think about my father and Zack in close thoughts; I have come to the conclusion that from my prespective if anyone is going to be as good a father as mine was, it is going to be Zack, he has two very blessed kids.
The following Monday, I went to the website of Florida Atlantic University which was close to my old residence in Boca Raton and went through the list of Computer Science professors, there had to be someone who could help me. Then I spotted a name that popped up from the screen right the way, Oge Marques, there had to be a brazilian name I thought. I did some research and he was brazilian, something felt warm in my heart right the way, I felt closure I guess, something clicked right. The very next morning I gave him a call and told him my story, he was a little reluctant at first because of his busy schedule but I could feel he wanted to help me. Oge didn't make any promises and I really respected him for that. We agreed to meet in his office after work and it was clear, from the very first moment, we were the total opposites, he was the scholar and I was the one in the "real world". But we shared one thing, we were extremely passionate to learn! For the first time I met someone who was passionate about it as I was and it was infactuating to be around him. He went over and taught me about as much as he could in that short period of time, binary operations, graphs, trees, etc.
I kept studying like an animal; I would work all day, study with Oge at night, then read and do some more exercises until I couldn't keep my eyes opened anymore. Sometimes I wouldn't sleep at all, I was never a big fan of sleeping, my dad always said while you sleep life passes by. I read numerous books, new books and classics. I got to read some great ones like Donald Knuth (which I didn't understand that much), re-read Introduction to Algorithms which we all read in college, Sedgewick, the super fun Programming Pearls and some other great ones.The Art of Programming from Knuth felt like Art of War from Szu Tzu; the first time I read Art of War I probabily understood about five percent of.
The weekend before the interview I went to Anguilla which is a very small island in the Caribe. It was summer, the weather was gorgeous and the place was even more beatiful; it is truly paradise. I spent the days reading by the beach while having tropical drinks, I was going mad at that point. The day finally came and I received a call from this random stiff who had graduated from some big-name university, I am pretty sure it was Stanford. He didn't really care much about what I had to say, he just wanted me to answer the programming exercises on Google Docs. He would paste a question on Google Docs and I had to answer on Google Docs, he would watch as I typed. First I had to explain what I was going to do and why, explain why that was the most optimal solution. Once we got to an agreement on the first part, I started writing code, not using my favorite IDE, I had to use Google Docs. I answered all the exercises correctly, they were all about sorting, searching, binary searching, etc and I had to know the Big-O of everything I did.
The interviewer asked me to write an algorithm that would check if the result of a Sudoku's game was correct, he also asked me to describe what data structure I would use. I told him I would create a huge series of if statements, it wouldn't be pretty, but it would be optimal, O(1). I also told him it didn't matter the code wouldn't be as easy to maintain because the rules of the game rarely change, if ever. I started writing the code to support the answer and he said he didn't need to see, that was the perfect answer; and just like that the call was over. He told me before hanging up someone was going to get in touch with me for another phone interview. My body was filled with joy and happiness, I was going to make my family proud.
What I didn't understand was that the story wouldn't end the way I expected and I would still have loved it anyway. The second part of this story to follow another day....
Friday, February 18, 2011
Thinking In Reverse - Not Taking Orders From Your Boss in Realtime
Today I was talking to my crazy, crazy-smart and great friend Mike Marshall, the creator of Massh (http://m.a.tt/er/massh/ - look how badass his domain is, a.tt, get it now?) about how difficult it is for some people adapt to new things. We were also talking about Realtime Webapps, how many wasteful pull apps we have done over the years (open a connection, make a request, get nothing in return and then do it all over again).
It's funny how you need to totally think in reverse sometimes to understand something. I remember the first time I heard about Kanban, that inventory and scheduling system created by Taiicho Onho, the father of Toyota's Production System (That used to sound a lot more impressive before the latest scandals Toyota had with their cars). Traditionally production systems and scheduling systems use/used a "Push" method, its success requires forecasting and all the issues that come with trying to "predict the future". In simpler terms, it means that traditionally our boss tells us what to do, sometimes one task at the time, sometimes a whole pile of tasks and he/she tries to predict how much work you and your peers are gonna get done. Kanban solves the forecast craziness by just eliminating it completely by using a "Pull" method when there's demand; that means you go to your boss (or a Kanban taskboard) and gets a task (a Kanban card) to work on. When you are done, you repeat the same process; That avoids your boss giving you too many tasks that just sit there in your pile while someone else, right next to you sometimes, has nothing to do. That also avoids you finishing all your tasks and going waste time on your favorite website because your boss is not there to give you more tasks. It makes sense! Somehow this whole process of just eliminating a problem completely reminds me of NoSQL databases (transactions, isolation levels, locking) but we'll leave that for another day.
In traditional webapps the client requests information from the server, a "Pull method". Then Ajax came a long and webpages became more alive, things seem to change without a full refresh but in a lot of cases there's still a lot of requests to the server involved. As there's a new breakthrough on the Web every once in a while, every five years some would say, we are starting to see become mainstream pushes from the server to clients (that's right - clients) to create realtime webapps that won't require the stupid pull requests I described before (I know Comet and Bayeux have been around for a while, take it easy). It works in reverse just like Kanban. I heard it be called Ajax Push, Reverse Ajax, HTTP Streaming; call it whatever-hell you like, I hate marketing buzz words because they seem to get outdated so fast. When you think of Ajax (Async Javascript and XML) do you think of XML or JSON? JSON!
Riding on this wave there's node.js which I love but I decided to create a little example in Java. Poor Java, I love Java, but it gets so much criticism nowadays; you can do a lot of cool stuff with Java! So since today I was bored out of my mind at work I decided to spend the day to set something up; I came up with a simple sample application I am calling Jaye (because of Node.js' Kickass Faye which is also based on Comet and Bayeux).
I created the whole thing today, code, hosting, deployment, etc. It is using Cloudbees for hosting, very impressive, super easy to setup, just worked! I created a free account, verified my email, uploaded a war and boom I was done! You gotta love PaaS, great job guys! It is using Raphael JS for the map, a SVG vector map by the way, we are not talking about gifs, excuse me. That means it works on different zoom levels, it works on mobile phones and it is very very cool for all geeks reading this.
I want to add more features of course, that's just a sample application; if you want to help me, fork Jaye on the always awesome Github.
Monday, February 14, 2011
Developers like to rewrite apps from scratch - but shold we?
The first version(s) of a successful application is focused, does what it needs to do and seems to have a killer feature its audience love; sometimes that killer feature was just an accident or maybe it was the plan the whole time. We developers, the creators, also know there are a few rough edges, maybe a few things that don't perform as well as possible so, at some point, we just decide to rewrite the whole entire thing.
A lot of times there is a valid point behind that decision. Maybe there is some new technology that addresses that certain business problem much more efficiently or maybe the codebase just got too big, difficult to manage and most of it is useless anyway. Unfortunately a lot of times we just decide to rewrite from scratch because our nature as programmers got the better of the situation, we got a little lazy and our heads just got clouded with naive thoughts of brilliance; we do not like to improve incrementally, we believe we can just build something straight out better, no matter how long it took to build what is currently in production. We ignore geek history and lessons learned from the whole horror stories like Netscape's. Do you remember how cool Netscape used to be? Now do you remember Netscape Communicator? Netscape 4? Netscape 5? Ugh. If you do not, get out of here and go ask your mommy to make your cereal! In more recent days, Digg.com's disaster comes to mind.
Fellow programers, yes programmers (I know that is not a cool term anymore but that's what we are - we are not engineers, I can barely use a screwdriver), be aware of the "Second System Syndrome", term first used by Fred Brooks.
It is easier to write code than to understand code that already exists and it is a lot cooler (who are we kidding). When we rewrite those applications we try to add every feature the first version(s) did no have because we think that we will do a better job, a sense of confidence that sounds more like a wish. So before you throw away years if hardwork and knowledge, try to really understand what you are leaving behind; and if it does make sense to rewrite from scratch, keep in mind what the priorities are and the core features that made the application a success in the first place.
By the way, I myself just proposed a partial rewrite of a 10-years system that is very successful. Did it make sense? Yes. But did my wild dreams of cool programming with Scala and hopefully some real-time Bayeux influence my decision? Hell yea!
(This is my first post from my new home/matchbox in NYC - goodbye sunshine state, we had a great run together).