A Month of Java Class

Technically it has been more than a month but for the last month, while I’ve been recovering from my surgery and getting sick every 2 weeks I’ve been stuck on a Java program that we were assigned. So it is technically really late, however, medical needs, yadda yadda means it’s not. I’ve finally got it working and I want to, now, share the solution so that if anyone else runs into trouble they can at least use my code for a reference since the rest of the code out there is utter shit.

Here’s the program I wrote, it includes the prompt for the question and a note from my Professor. The book is How to Program Java, Late Objects Version by Deitel:

So that’s my solution for printing a hollow box in Java when you want the perimeter of the box to be a specific size. Here’s some SEO nonsense so people actually find this, print a square in java, print a hollow square in java, java print a square, java print a hollow square. (I don’t normally do that nonsense but rather than someone else spending a bunch of time on this they can get here.)

Here’s a sample of the program output:

![Program output](http://cl.ly/1g082h3X2q280V2S0y3U/iTerm.png)

Cherokee, uWSGi, Django, Python server set up.

Preamble:

As promised in my last blog post this post is going to be all about how to set up a server to run Cherokee with uWSGI for deploying Django or other Python applications.

Server setup:

I am going to make some assumptions about your server environment:

  1. You are running Ubuntu 10.04 or similar. Older versions may have some changes that need to be made.
  2. This is a brand new server or VPS running at either Slicehost or The Rackspace Cloud. Other companies may work but I’ve only tested here.
  3. You have set the machine up, at least doing the steps here and here.
  4. You have a Django project you can deploy.
  5. You are running an operating system that is intelligent enough to give you a shell and open ssh tunnels.

Now that your server is set up you can run this shell script to install all of the software we will be using:

Yes I am installing Python modules server wide and no I don’t care about the problems that can come with that, since, I am only going to be running one application from this server. If you think you are going to have a problem with that install the python modules in the appropriate directories or sub-directories how ever you want to do that.

Now that everything is installed, let’s get it set up. Here are the steps:

  1. Set up our postgres username, password, and database. Here is a link to get setup.
  2. Copy your Django project to: /home/username/
  3. Sync your database
  4. Start the cherokee admin by running: cherokee-admin
  5. Open a second shell and run: ssh -l username -L 9090:localhost:9090 IPADDRESSFORYOURSERVER (Now you can go to localhost:9090 on your computer’s browser and get to the Cherokee admin interface.) You’ll need to use the username and password that come up from Step 4 above.

You can now start the Cherokee server by clicking the start server button (cool huh?) Once it is started follow the directions here:
http://www.cherokee-project.com/doc/cookbook_uwsgi.html
Edit your django_wsgi.py and uwsgi.xml files to match your application’s settings. Once that is done you should be able to start your site as long as things are correct. Oh, and don’t put your Django files in /var/www.

Configuration Options:

Here are some more configuration options:

1. Have the Cherokee server match multiple domains to the same virtual host:

Dock

  1. a. Serve your admin media: 

Dock

b. Create a new rule as type Directory with the web directory being your admin media path (in this case mine is /media):

Dock

c. Change to the Handler tab choose Static Content and put the full path to your admin media in the Document Root including the trailing slash:

Dock

You can play with the other settings for it like gzip, deflate, and traffic shaping.
3. Change the user that the uWSGI process runs as, click Sources and select your uWSGI app:

Dock

I had to change this to the user where my code was deployed: /home/username/ for things to work correctly.

  1. Traffic monitoring. You can enable it by going to Status, then clicking on the virtual server, and checking enable at the bottom. You may need to choose RRDTool Graphs in General -> Network -> Information Collector:

Dock

Dock

  1. Looking at your log files if something isn’t working:
    You just need to cat or tail /var/log/cherokee/cherokee.error. If you want it to log somewhere else you can configure it by clicking vServers -> your vServer -> Logging and changing the path there:

Dock

Tips and Tricks:

If you get something like:
uWSGI Error, wsgi application not found
Make sure that you have set the user that the uWSGI process runs as (step 4 in Configuration Options), save and hard restart the server.

New Django/Python deployment stack: Django, Cherokee, and uWSGI.

What I had:

In the past couple of months I have been looking for alternatives to my current web stack. My current web stack is:

  • Django (my favorite web framework),
  • nginx (frontend web server),
  • apache + mod_wsgi (to serve the Django application), and
  • PostgreSQL the database, obviously.

Django isn’t getting replaced because I like it and I can’t get my coding partner to switch to anything else no matter how magical or revolutionary.

I fucking hate nginx configuration files so that was going out the window as soon as I could find a suitable replacement. Apache + mod_wsgi I’m not entirely unhappy with but the extra memory usage from Apache bloatware and, again, the ugly configuration files are annoying, especially, with non-standard PYTHONPATHs. Yes, I know I can do sys.path magic to work around it but I shouldn’t have to, this is 2010 not 1990, fuck that.

PostgreSQL is a great database server and I’m happy that the Django ORM just works with it so I don’t have to build my own ORM, big plus. I would love to give CouchDB a chance but I don’t have the time to rewrite _everything_ to work with it, I’ll use it with something else.

What I Found:

Looking for other web servers I came across Cherokee (http://www.cherokee-project.com/). The documentation on the Cherokee site is phenomenal, when have you EVER seen screen casts for how to configure your web server? Oh, and what is that? A screencast about deploying Django using uWSGI or Flup? Why, yes, that what you are seeing, isn’t that great? That isn’t the only good thing, Cherokee stacks up, speed wise, with nginx, has plenty of configuration “wizards”, and has a web front end for configuring the web server. I was mostly sold just from the documentation, compare this with this. The Apache docs may be informational but they are completely worthless if I want to get something done, today.

Configuring Cherokee is like using the WebFaction hosting interface, easy to use and as powerful as you want it to be. In fact, in the next blog post about how to set everything up you can see the similarities. (Disclaimer: I work for WebFaction so I am a little biased, however, in the 10 years that I have been dealing with web hosts I have never seen another hosting company build something so great at what it does: allow you to do as much or as little as you need, to get things done.)

After hours of looking through the different ways to serve WSGI applications I finally settled on uWSGI, mostly because it is written completely in C and has a really easy install process (read: one command, make). uWSGI is also able to used with Cherokee and Django really easily, see the screencast here: http://www.cherokee-project.com/screencasts.html#django_uwsgi. Now that is what I was looking for, easy to configure, easy to use, powerful, and fast. Also, setting the PYTHONPATH is as simple as 1 or more XML tags, like so:

<pythonpath>/path/you/are/adding/</pythonpath>

Fantastic! Have another path you want used? Add another line, that’s it.

Processes are automatically managed and restarted when they are killed. uWSGI has amusing errors, such as:

  • …brutally killing workers…
  • DAMN ! process 14955 died 🙁 trying respawn …

Log files are much more fun to read when they include some humor even if shit is wildly broken.

Next post will be about how to set all of this up, from nothing to a working deployment of a working Django app using Cherokee and uWSGI.

 

A new iPhone launches without me.

When it comes to iPhone launches I have seen them from multiple sides, consumer, employee, and, this year, developer. There are a lot of negative comments about Apple and at&t that fly around during the an iPhone launch from people who don’t know much about the process of launching a product, having been on all sides of an iPhone launch I’m uniquely qualified to paint the whole picture, for people who haven’t been there. Here it is:

My previous job was as a Customer Care Trainer for Convergys Corporation. (I’m currently a Support Engineer for WebFaction and a developer of Mac and iOS applications, among other things.) Here is a bit of background about Convergys (you are welcome to look them up on Google, their site convergys.com, and Wikipedia), Convergys is an outsourcing company for different things Human Resources Management, customer care, customer service, payroll, and just about anything else you can think of outsourcing (provided you have enough money). There are quite a few different departments that have different functions, even though my NDA is up I’m still not going to go into that, it’s bad form.

The part of the company I worked for was in charge of Customer Care, meaning call centers. In the call center I worked in, our project was the at&t wireless division for postpaid customers. That is anyone who has a postpaid account but doesn’t have a company status or doesn’t get a discount on their service for working for a company.

For the 3 years that I worked as a trainer an iPhone was launched each year. Many people have had to deal with at&t customer care for those 3 iPhone launches and hated every minute of it because they thought agents were incompetent and/or stupid. I’m going to discuss how an iPhone launch looks from the inside of a call center.

Here are the different phases:

1. The Apple announcement
2. The Unknowns
3. The Complaints
4. Launch Day

1. The Apple announcement

Apple announces their wonderful, magical, revolutionary product.

We all watch in wonder as Apple reveals the greatest product we have ever seen and that it is going to be available only on at&t’s network. Great, wow! That will be fantastic for business, those of us who had at&t already were incredibly happy: we could get one at a discount like with every other device, right? No one we talk to has any information about the product or knows anything other than what was in the Apple announcement.

2. The Unknowns

We start getting calls for the (new) iPhone immediately, but, we don’t know anything about it. Thousands of these calls ended up with irate customers because we were “stupid” and/or “incompetent”.

Here’s a quick overview of of at&t’s training process:

First, at&t has to get the information from Apple, this takes time. I’m not quite certain on the amount of time because I didn’t work for at&t directly. Once at&t gets the information it goes to the curriculum designers who then turn it into a training course depending on the amount of material and the suggested delivery method it may end up in a couple of different forms: Self based, Instructor led, or a combination of both. Once the course design is complete an Instructor Guide and Participant Guide are created, the material is then sent to the Training Council. The Training Council is made up of incredibly smart people, lawyers, and pedagogy experts who then review all of the material in the course and guides.

The Training Councils’ feedback is incorporated into the course and guides and sent for review again. (Apple and at&t are very similar, right?) Once the course is approved it is scheduled for Master-trainer training. The Master trainers then deliver the training to the trainers in their various call centers via speakerphone and screen sharing.

Trainers, then, after being certified can deliver the training to the rest of the call center. The logistics for training an entire call center of 300+ people for a training, no matter the length, is frightening. Call centers are a Statistician’s wet dream, there are metrics for EVERYTHING and they all impact each other in some way (the metrics not the Statisticians). Depending on the client, not meeting certain metrics is monetarily punishable. The biggest metric with most clients is SLA, Service Level Agreements, which say “your center will be filled with X number of agents, X number of hours, with less than X% variance”, training time comes out of that SLA. Clients are reasonable and allow for a certain number of training hours per month that are used up with “other” training that has already happened, additional training always come out of the SLA.

To add to the problem of lost revenue and not meeting financials, is scheduling. Call centers are composed of, mostly, 2 types of people: lower-class middle aged people and uneducated young people (possibly students). This means that they all have their specific schedules that can’t bend for anything. Even though all agents want to get off the phone for training as much as possible, scheduling them for it is nigh impossible.

Did I mention that there are normally 3 – 5 trainings and they all have to be completed in a very short timeframe, less than a week in some cases? The activation training, for the first iPhone, didn’t come until the day before. We had no idea how the activation was going to work until the day before the first iPhone launched. Training 10,000 people across the country through multiple outsourcing partners is an incredibly daunting task. If you don’t believe me, try it.

3. The Complaints

As soon as people get off the phone with at&t for the first time or visit the Web site and get nothing the Complaints phase starts. People start bitching and whining about everything, their incompetent wireless carrier with the retarded agents they have to deal with. I’m not going to cover for all of the agents that work for at&t because there are those “retards” who either don’t care or just suck at their job.

Next complaint is almost always the price or the required data plan, the lack of “updated features” or .

I’ll let you in on a little secret about phone reception issues: THEY ALL FUCKING HAVE THEM. Almost every phone there is, if you hold it incorrectly, will lose reception, sometimes completely. The Samsung Sync one of the best sellers for at&t in 2007 had the antennae at the bottom of the device which is right where people hold flip phones, guess what? If you put your hand over or on the bottom of the device you will lose service.

Some of the training I did was device specific, the Samsung BlackJack, Sync, BlackBerry Pearl, AT&T 8525, Palm Treo 680 and 750, and a couple others, they all had the same problem to some degree. Cedar City does not have the best coverage area with at&t so training on the phones was difficult. One of the trick I learned, that seems to work on all devices is to hold the phone with 2 fingers, in the air, sideways. In most cases the “bars” will increase by 2, if you are in a low coverage area. Try it, it works.

4. Launch Day

An iPhone launch, in the service industry, is about the closest you can come to hell. The first iPhone launch was especially bad. All of the unknowns combined with a device manufacturer that had some control in the way the device was launched made it a very trying experience. Being a Trainer I was only required to take production phone calls for 4 hours a month to stay fresh, I usually did 5 – 7 hours depending on my class and administrative load.

Being the good Trainer, I volunteered to take phone calls for 6 hours on Launch Day; it was hell. Since the activation process was something magical happening in Cupertino there was basically nothing we could do. Being able to do nothing is extremely frustrating; it is doubly frustrating for customers who just spent ~$700 on a device that had never existed and the wanted to use. Spending 20 minute making sure there is nothing I can do from my end then sending them to apple to wait on hold for another hour or 2 before getting to someone who could help hurts for a control freak like me.

iPhone 3G was a much better launch, things didn’t blow up as much. The training was a little easier since it was mostly just feature education and updated specs. iPhone 3GS was even easier, the complaints that got worse were the ones about customers not being eligible for upgrades. The upgrade eligibly thing is a hard thing to understand because of all of the metrics that went into it. My thoughts are that upgrading to a new iPhone from an iPhone should be allowed at the normal 2 year contract pricing, sadly my pay grade didn’t get to make decisions.

The launch of the iPhone 4 was much different, I watched from a developer perspective. Instead of the dread at another WWDC where a new iPhone would be launched, I was excited to see what new magic would come from the conference, instead of new price plans to learn there were new APIs. It was a very different feeling to sit back in my chair and watch (on Twitter) the launch of the newest iPhone without me having to do anything.

There is a tremendous amount of work that goes into launch any product, ask any developer. Launching a product that spans multiple companies that have never worked together is an insane amount of work. I’m thankful for all of the work everyone has done to get things launched as well as they were, with the amount of work I put in thinking about everyone else is incredible. There could have been improvements to the process but that can be said for anything.

Fantastic article.

“Destroying the Earth is harder than you may have been led to believe.”

http://qntm.org/destroy

Fantastic (long) piece about the different ways to destroy the world.

Gizmodo Denied Press Passes for WWDC Keynote

This is so, so enjoyable. I can’t believe they were stupid enough to wait for a press pass.

Gizmodo Denied Press Passes for WWDC Keynote: “

Brian Lam:

It’s no surprise: Apple has not responded to our requests to attend the WWDC keynote on Monday at 10am PST. But we’ll still cover the news. Want to help?

WWDC attendees, be warned: guard your conference badges Sunday night if you’re at a bar.

(If Gizmodo’s editors were smart, they’d have purchased WWDC conference badges if they wanted to attend the keynote. But of course, that’s a big ‘if’.)

(Via Daring Fireball.)

Business is Hard Part II

People are not always who you expect them to be.

I behave mostly the same whether I am at work (IRC), in person, or in IM/regular chat I try to behave the same way in business dealings. I am not going to intentionally fuck someone over for me to make an extra couple dollars. I also will not intentionally leave a project that we have a contract for unfinished. I will work to deliver everything that I agreed to deliver and if I cannot I will refund accordingly.

I have found out, over the last week, that not everyone is like that. I recently had the misfortune of renting from a person I had known for about 10 years. I knew he was a smart business man otherwise he would not have made the 100s of millions of dollars he has in the bank or the summer homes in New Zealand but I never thought he would fuck me over.

In renting from him I chose the best possible location then went through the list of available buildings his being the only one in my price range in roughly the right vicinity so I took it. It was old and cold. The floor was an awful ugly brown, there was a huge back room with cracks in the doors and windows that air would directly blow through.

When I first moved into the building there was talk of the ceiling leaking and that it would be fixed by the first weekend I was there. The work crew came out and “fixed” the roof and I thought everything was cool. Two weeks later it rained and the ceiling was leaking again, turns out, the work crew didn’t actually repair the leak they only replaced the ceiling tiles to make it look like they had done the work. We immediately called the landlord who came down and looked around. We told him about the numerous violations for electricity and wiring in the building and he said, “You make better detectives than tenants” and then he told us “If you don’t like it, get the hell out.”

Get the hell out.

I had not anticipated that as a response I would get, knowing this guy for the last 10 years I would have thought it would be something like “We’ll fix it, give us a couple days” or even “It’s going to take a week to get it fixed” but never “Get the hell out”. So now I am left scrambling. I have about 20 computers in a building with monitors and all sorts of electrical equipment with a ceiling that is raining. I have clients who have been to the building that know that is where we are located.

I make arrangements for the computers to be stored out of the weather. Now what? Broken and beaten we begin to look for another storefront, some guy offered to let us use part of his building. Do I want to be bounded by his hours? No. Do I want to be stuck in some shitty corner of town? No. Do I want to have my business directly affected by another person? Not only no, but hell no. I have too much experience with business to know that this is a bad idea.

Now I go looking through every other building in town. I found one! The perfect fucking building, downtown, right in the main traffic area, big enough to hold all of the equipment and still have space leftover, but not big enough to kill me with the heating bill. (The old place cost $175 for power for one month.) The only problem was the landlord. He had, to that point turned down 7 potential renters. There was an arcade, a lawyer, and a few other tenants that definitely made more money than we did and had bigger community ties than we did.

Some people really are good people.

I called and talked to the new landlord expecting that we would get rejected out right without even being looked at completely. The landlord told me to write up the information he would need to make a decision and process our application. Since I figured we had no chance at getting the place I was brutally honest about us and our financial situation, as well as, 2/3 of us having extremely bad credit. I was also extremely forthright about our services and lack of ability to get into the building for another month because of the financial situation caused by the first rental.

Over the next couple of phone calls with a good word put in by our prospective neighbors (whom we all knew and liked) it was settled that we had the place the very next day. I called the landlord back to let him know we couldn’t accept because of the financial situation. The landlord agreed to drop the rent with security deposit from $1200 to just the $700 for rent. After pouring through my finances it wasn’t possible for me to pay that much after all of the damages done from the first place.

On the call following this the landlord

insisted that the first payment be $500 rather than the $700 and that we have 17 days of free rent

. Yes, you read that right, he insisted that we have 17 days of free rent and that we only pay the security deposit. In which world does this happen? Until now I had no idea that there were people that were this “good”. Of course, we accepted and signed the lease as soon as his wife could get there to give us the papers.

If you try, sometimes things will work out.

Three days before this we were broken and bruised not knowing if we could succeed without a building. Now we were set up with a better location in a better building with less wasted space.

Lesson learned here:

Be the Juggernaut; break through every fucking wall anyone can throw at you.

Switching up my life and educational goals.

The back story:

When I first started University (Fall 2006) I had declared Business Management as the thing I wanted to spend my life doing. Business people made lots of money, business people drank expensive liquor, and drove nice cars what teenager (I was 18) doesn’t want that? Before I actually started school I had gotten a job at a call center (Convergys Corporation) and was working at, for Southern Utah, a good wage $8.50/hr that had awesome benefits like tuition reimbursement. After about 2 months I got promoted to a Training position where, since I was staff, I was only able to get reimbursement if I was “majoring” in a business field. I quickly saw, after being a middle manager, that business management was something I completely did not want to do.

At that point I changed my “major” to Economics because it was interesting, it was a business class so I could still get my tuition reimbursement, and people with BS or BA in Econ get into Graduate/Law schools really easily. Economics was fun and I would still like to get a Graduate degree in Economics but at this point in my school career it is completely pointless to stick with it as a major. I started University wanting to learn stuff with a degree as a “happy accident” so I didn’t immediately start taking the Math classes that I would need for graduating to make room for classes I wanted to take. This and the 2 semesters I took off for work at Convergys have come back to haunt me. Instead of graduating at the end of April I am a Junior with at least 3 more semesters to go with the number of math classes needed for a degree in Economics I would end up being at University for 3 more years just finishing the math classes because they have to be taken in order.

The now:

That has led me to this latest change: I am changing my “major” to German and keeping the “minor” in Philosophy. I will get done 1.5 years sooner than I normally would and that should be enough liberal art education to get into Grad school for almost anything. The department I am going to is made up of the language teachers and the Philosophy professor. Since I have worked very closely with the German professor before this is like going back to an old friend’s house after a long, awful trip. My excitement for school has been replenished and I am feeling up to a full work load for the Fall semester. Knowing there is an end and liking the way the end looks is a very comforting thing.

Cheers!