Life Applied

Life Applied

Nov 18 / 5:23am

API route in Rails

I am beginning to flush our an api in rails that will leverage OAuth as the authentication mechanism. I looked at this article as a starting point: http://www.jbarnette.com/2009/04/07/http-apis.html.  This is exactly how I would envision laying out my api urls, but there is one update I want to note for Rails 3.1.1.

 

In your routes.rb file it should be:

 

 

namespace :api do

    namespace :v1 do

      resources  :widgets

    end

  end

 

Jun 25 / 7:20am

Dumbing down my smartphone

I had been having some "dead-air" issues with my HTC Incredible so Verizon kindly sent me a new device in the hopes that it would correct the issue. I received the second HTC incredible but that device had an issue if constantly rebooting.  I took it to the Verizon store and they diagnosed that the battery was the problem and so they would send me a new battery.  The new battery wouldn't arrive for a few days so I would be without a phone during that time. I really wasn't too upset about it as I was looking forward to being "disconnected." But what I didn't realize how liberating it would truly be.

I first realized it when I went to meet someone for coffee without a device on me. While I was waiting for the person to arrive I just sat there thinking. Not really thinking about anything deep and meaningful, but simply allowing my mind to wander. Boy did it feel good. If I had my phone with me I would have been checking my email, reading Google Reader, checking Twitter or a handful of other things to keep me occupied. I was able to just sit and think and it felt fantastic!

The new device is still not working so while I am waiting for my third device I have switched back to my original. But I decided to dumb it down. My plan is very good so not having data does not make sense for me, but what I am going to do is remove all of the apps that allow me to waste time and clean-up my home screen to remove applications that distract me.  I am also disconnecting my email from the phone. Essentially I am removing any application that I would use while sitting in a doctor's office or something that will interrupt my day like emails popping up.

We'll see how it works out.  I probably won't be caught up on the latest news or emails, but those things can wait until I get back to my laptop which I am never too far away from.

Jun 18 / 4:58am

Idea Dating

I am sure most of have met that special someone, spent some time with them on our own and when the time was right took them out with your friends and family only to find they weren'y exactly what you thought they were.

I think ideas are very similiar to this.  Ideas start out in your head while you are in the shower, walking down the street, sitting in the airport and they bake. At first you might think wow this is the greatest idea ever. Why has no-one ever thought of this.  If you're an engineer you will probably want to get "doing" right away and start executing on your idea. But I think we should liken ideas to dating. It should go through several phases before we actually execute or "marry" ourselves to the idea.

The Meeting: in this phase you and the idea meet as I described above. In the real world hopefully it isn't in the shower, but it could be at a bar, church etc. You get to know eachother. You compare this idea to others you've had. You consider if you want to spend more time thinking about this idea.

Getting to Know You: In this phase you have realized there might be something to this idea, you want to learn more. So you right down some pros and cons to the idea. Perhaps you do a little research to see if anyone has done this before and if not why. Perhaps you see if there is a possible market for this idea by doing some searches online.

Introducing to your Friends & Family: This is often where ideas and in the real world where relationships can fail. When you're with your new found love at home on the couch watching Netflix or out at a restaurant alone, everything seems peachy. This seems like the greatest relationship ever. Now you have to introduce them to your friends. How will your friends like the person, how will each party react, will they fit in. This part is very critical because you want to integrate the person into your life. Much like a real-world relationship it is important for an idea to go through this stage. You need to vette the idea amongst other people. You need to see if they would use it. Have their heard of something similiar, would they pay money for it or know someone who might. What issues can they come up with to help  you further refine the idea.

Let's Take it to the next Level: In this stage you feel pretty confident you like the idea and want to spend more time with it, but you are not 100% sure you are going to marry yourself to it. So you want to spend some more time talking with possible users/customers. Perhaps you can do some mockups or prototypes to show and present your idea to more people and further refine the idea into something that would deliver value.

Getting Married: In this stage you have found you like the idea enough to devote your time, money and other resources to attempt to execute on this idea.

 

Often times I find myself going through stage 1 & 2 and then skipping right to Getting Married. I think it is important for an idea to go through all of these phases so as not to waste any time you could have been devoted on getting to know someone else ;)

 

 

May 17 / 5:45pm

Bull Riding...

While flipping through the channels the other night I came across bull riding. In watching a little of it I had some questions as to how the sport works.

Most important question is who picks the bulls?

Do the riders pick their own bull? Or do they bring their own with them? Maybe it is some jury picking type process whereby all of the bulls are led into the ring and the riders rank their favorite.  The reason this is important is because it doesn't seem fair. I mean what if one rider stays longer on his bull because it was more tame than another? Or is there some minimum level or "pissed offedness" that a bull must possess in order to qualify?

I'm trying to expand my horizons.

May 4 / 5:31pm

RoR send_file not working on Apache

I have Rails 3 running on an Apache web server on Slicehost and was using send_file() for Boply after someone made a file purchase. The problem was it would successfully email the file to the purchaser but if they clicked in their browser to download it was sending an 0 byte file. And of course "it works on my local machine." The problem as it turns out is that Rails 3 added a new configuration property to production.rb.

Namely this one: config.action_dispatch.x_sendfile_header = "X-Sendfile".

 

This configuration property leverages Apache to stream the file to the user's machien rather than letting Rails do it. But the problem I was facing was that I did not have the mod_xsendfile module enabled in Apache so it wasn't working.

Apr 27 / 11:56am

Using rake to send email asynchronously

For Boply I had been sending out the notification emails when the user confirmed their order. The issue with that of course is that it could be slow or it might never respond depending on the SMTP server. Given that I decided to queue the emails and send out later. To do that I did the following:

 

1. Create a model called EmailQueue (order_id, method_name).

This will store the orderId as well as the method name in the Notifier to call

2. On confirmation of the order put an entry into the email_queues table

3. Create a rake task to send the emails

    I added a new file in lib/tasks called mailer.rake with the following contents:

desc "Send any notification emails"

task :send_emails => :environment do

queuedEmails = EmailQueue.find(:all)

for qEmail in queuedEmails

order = Order.find(qEmail.order_id)

notification = Notifier.send(qEmail.method_name, order)

notification.deliver

qEmail.destroy

end

end

 

4. I am using slicehost so I createda file called runCron.sh which will be called from a cron job to run the rake task

 

#!/bin/bash

cd <root of your rails app>

rake RAILS_ENV=production send_emails

 

5. Finally I added to the crontab

crontab -e 

*/5 * * * * <path to shell script>/runCron.sh

Mar 27 / 6:08pm

sqlite and Windows 64-bit

If you are using sqlite in a Windows 64-bit environment and you are running into the following error: 

"System.AccessViolationException: Attempted to read or write protected memory"

you might want to try using sqlite3.

Feb 23 / 6:02am

rake db:migrate

If you want to run a migration to your production db when using Ruby on Rails run the following command:

 

rake db:migrate RAILS_ENV=production

Feb 13 / 6:42am

Choosing the right undershirt

It is not too often that I have to pull out the dress shirts from the closet and don my business casual attire, but it seems I have been doing it more and more recently. When I do I always seem to be stuck with the time honored dilema of choosing the right undershirt. I like an undershirt because is provides sweat protection and offers an additional level of comfort under my dress shirt. I don't like it though because I feel it looks kind of ratty when you are able to see the undershirt (This is a new. Maybe I am going for the more metro-look here) In this regard I see a a few options each which present their own pros and cons. 

 

  1. the sleeveless undershirt aka. "A-shirt", "wife beater". We all know this one and seems to have been the choice of our Grandparents generatation. I like the idea here of an additional layer and not being able to see it above the collar of the dress shirt, but it does not seem to afford much in the way of sweat protection
  2. the traditional t-shirt undershirt with the straight-across collar. I like this one and it is my fall-back because it is comfortable and offers a lot of protection, but I am not sure I like the white collar sitting above the dress-shirt collar
  3. no undershirt. I have been trying this one out recently as I was trying to see how I liked the look of no-undershirt showing about the dress shirt collar. I have to say I didn't like it. I felt almost naked and without the extra level of sweat protection I felt nervous if I had to go into a stressful situation
  4. the v-neck. I have not yet tried this option, but I think I am going to give it a shot. It seems it would offer the sweat protection I desire, would not show a collar above the dress shirt collar and would give the comfort of the traditional t-shirt undershirt.

Is anyone else faced with the same questions when you put on a dress shirt?  What do you think about having the white part of the undershirt show above the dress shirt?

 

Jan 9 / 4:53am

Things to keep in mind when buying a house

Here are just a list of things I have compiled that I have learned I need to keep in mind when buying a house. These are in no order and are by no means complete. I will continue to add to them and hope you will help me:

  1. price per square foot
  2. gas heat or electric
  3. size of lot
  4. location
  5. cul-de-sac or not
  6. on a busy street or not
  7. speed limit on street in front of your house
  8. distance your house is from your neighbors
  9. how  your garage faces. Do you have to see your neighbor everytime you walk out your garage
  10. shrubs/trees between houses
  11. real wood floors or wood veneer
  12. number of stairs
  13. is there a heating/cooling unit per floor or does it use a damper system
  14. homeowners association cost
  15. city water or not
  16. septic system or not
  17. school districts
  18. noise from airplanes flying over
  19. how often do you get re-zoned for schools
  20. property taxes
  21. age of kids around, if you want kids the same age as yours
  22. types of jobs people have in the neighborhood
  23. proximity to shops
  24. proximity to parks
  25. wooded lot
  26. distance from work
  27. which way does the traffic flow when driving to and from work
  28. proximity to friends/family
  29.  Age of the building and components such as the roof and HVAC systems
  30. Distance to a fire hydrant (will affect insurance rate)
  31. The socioeconomic demographic of adjacent neighborhoods
  32. Planned future road expansion
  33. Crime rate.