Sunday, June 26, 2016

End of programmerdays

This blog has moved to https://programmerdays.com

As of now, I will stop posting to this website.

Saturday, June 18, 2016

Paid to exercise

We live in a weird world. Recently, I've been getting paid to exercise.

My company has partnered with another company called Jiff. After I registered my fitbit account to Jiff, Jiff gives me points based on how many steps I take and how much I sleep. I can then redeem those points for prepaid cards or I can enter raffles.

Here are some numbers for you:

  • 600 points will give you a $20 gift card.
  • 50 points will give you a raffle ticket for things like an ipad mini or a new fitbit.

For the last few months, I have gotten around 500 points per month. It could be a little bit higher if 1) I always remembered to wear my fitbit and 2) I entered things into a food log (which I always forget to do). All in all, it takes me a little over a month to make $20.

So far, I've entered a couple of raffles (but haven't won anything yet) and I have gotten 1 visa prepaid debit card.

I had a little trouble using the virtual $20 prepaid card. First, I wanted to use it with iTalki. But I found out that there is a processing fee. If I used it there, I'd have a remaining balance, and then I'd be stuck trying to figure out how to spend the leftover balance. Then I tried to buy some credits for my digital ocean account. For some reason, the charge was rejected. Finally, I successfully was able to spend it all on credits for indoor hoops.

It is fitting that I was able to use money generated from my fitness activities to do more exercise.

Wednesday, June 15, 2016

Fitbit is a good company

The band on my fitbit Charge HR somehow got an air bubble. Soon after the seams started to become unglued. I was afraid that the band might get caught on something and rip apart at any moment.

So, I went to the fitbit forums and found that others were experiencing the same issue. I sent an email to fitbit with a picture and a description of my problem. They replied within a couple of hours asking for my order number and mailing address. Before I knew it, a replacement fitbit was being prepared for me, and it arrived a few days later.

I am very impressed by fitbit's customer service. Some companies seem to operate by trying to squeeze every penny out of you (t.v. cable companies, airlines, etc ...) In contrast, my interactions with fitbit have all been easy and reasonable.

I don't remember if I mentioned this before, but since I'm talking about my fitbit, here are the things I most use the fitbit for:

  • using it as a silent alarm to wake me up before my wife
  • checking the time
  • checking my historical resting heart rate
  • using it as a reminder to never be too lazy

Saturday, June 11, 2016

Nginx Gunicorn Flask stack

I followed this wonderful guide to set up my flask + gunicorn + nginx application jjjdddfff.com on digital ocean. If you want to do the same, you should probably go there. Here are some additional notes that I took for myself.

What is the stack made of?

nginx is your http server. You tell the nginx server what port to listen to and where to pass requests. It can handle some requests on its own, like serving static resources like images, or redirects from one url to another. If it doesn't handle a request on its own, it can pass it to your app server, which in my case is gunicorn.

gunicorn is your python app server. It translates http requests into wsgi (web server gateway interface) compatible requests, which are forwarded to whatever will process the request.

flask is a python web framework. It will contain all the business logic of creating a response for a given request.

An alternative stack might be something like apache/uWsgi/django. Because it's all new to me, so I can't say with any authority which is better. I just needed to start somewhere, and after googling/reading a bit, I settled on this stack. At the worst, I think all of the pieces are plug and play. If I am unhappy with any piece of the puzzle, I don't think it will be too much trouble to switch out pieces of the stack. Right?

What do you need to do

You should look to the guide for the explicit steps, but I think it boils down to the following. First, install the software you need (nginx and virtualenv) and then within a virtual envinronment (gunicorn and flask). Then you need to write a couple of scripts.

Configure a web server (nginx)

In script, /etc/nginx/sites-enabled/homepage, I set up my web server (nginx) to listen to http requests and pass them to our app server (gunicorn) via a sock file.

server {
    listen 80;
    server_name jjjdddfff.com;

    location / {
        include proxy_params;
        proxy_pass http://unix:/home/username/homepage/homepage.sock;
    }
}
server {
    server_name www.jjjdddfff.com;
    return 301 $scheme://jjjdddfff.com$request_uri;
}

Set up application server (gunicorn)

In script /etc/init/homepage.conf, I created an upstart file that tells ubuntu to start your web application (homepage) that is bound to that "sock" file used in the web server.

description "Gunicorn application server running homepage"

start on runlevel [2345]
stop on runlevel [!2345]

respawn
setuid username
setgid www-data

script
    cd /home/username/homepage
    . venv/bin/activate
    gunicorn --workers 1 --bind unix:homepage.sock -m 007 homepage
end script

Create a web application (flask)

In script, /home/username/homepage/homepage.py, I set up a flask application which will handle all the business logic of processing requests.

from flask import Flask
application = Flask(__name__)

@application.route("/")
def home():
    return "Hello world"

if __name__ == "__main__":
    application.run(host='0.0.0.0')

Some helpful commands

Test the web server.

sudo nginx -t
sudo service nginx restart

Test the application server.

sudo stop homepage
sudo start homepage

Tuesday, June 7, 2016

Indoor Hoops

I had my first experience playing basketball with Indoorhoops.com.

I first signed up for a game a couple of weeks ago, on the Sunday of Mother's day, but there weren't enough people, and the scheduled game was cancelled.

I tried again, and this time there were enough people, and I got to play. I haven't played full court basketball in a couple of years, so I was a little bit nervous whether I could keep up. In the end, I think my skill level was just fine. I'm not sure where I would rank among all the players there, but the team I played on won a few games, and I contributed to those wins somewhat. Basically, I didn't stick out like a sore thumb of incompetence, so that was good.

I think there were about 12 people for a 5v5 game. The winner stayed on, and if you lost, you had a pretty decent chance of getting in the next game, just by hitting some free throws. I think I played for about an hour and half straight, before I volunteered to sit one out.

It was a hot day, and the court was hot too. This was OK with me, and probably helped me get a good workout. The court I went to was a bit small, which was Ok as well, because I probably would've gotten tired faster if it were bigger.

It was a good experience, and I plan on doing it again.

If you want to try it out, consider using this link: https://indoorhoops.com/in/refer/CNFJN12678, so that I can get some referral credits.

Sunday, June 5, 2016

My Virtual Private Server

I bought a server

As a professional computer programmer I have written and deployed a lot of code. Almost all of this code has run on machines that someone else had set up for me. This is a gap of knowledge and understanding and experience that I want to shrink.

This weekend, I made a step towards reducing my knowledge gap by purchasing access to a VPS (virtual private server) from Digital Ocean. With it, I can now start up a linux server "in the cloud" in a couple of minutes. I didn't and don't fully understand what that meant (because of my previously noted knowledge gap), but I signed up for an account and bought some credits anyway.

What did I buy?

I bought something that Digital Ocean calls 'droplets'. Droplets are a virtual server that has an operating system, like Ubuntu, and a set of resources like a hard drive, RAM, bandwidth and an IP address. You can then connect to your droplet via ssh and do whatever unix stuff you like.

I bought the cheapest one which is an Ubuntu server with 512 MB of RAM, 20 GB hard disk and 1000 GB of transfer. It costs $5/month or .007 cents per hour. I used a coupon code, for $10, so I won't start paying for a little while.

For now, I'm still in the process of configuring it. Until I have something like a web server running on it, I have been shutting down the server whenever I am not actively working on it. I think this will save me some cents.

Oh yeah, like I said, I'm a dummy - so without understanding things, I also bought a domain name from google domains. It's jjjdddfff.com. I'm still learning how the server works, so getting a domain name is a bit premature, and money not well spent. Oh well, I guess it'll be motivation to get something working sooner than later.

What have I done so far

So far, I've followed some of digital ocean's tutorials and done the basics. I used ssh to connect to my virtual server from my home machine. I added a non root unix user that has sudo privileges. I added some firewalls.

Next, I plan on installing components for a web stack. And after that, who knows?

Spending Spree

Within the last couple of days, I have been on a spending spree. I bought:

There are so many free options on the internet, so I have always been reluctant to pay for anything. In the past, I've read and used resources right up to the pay wall, and then I go try something else. This strategy works. You can learn and improve in a lot of ways.

But recently I feel like I've hit the point of diminishing returns. I also see now that time is more scarce than dollars. So, I've decided to cross the pay wall for a few items.

I'll write some more details on each of the things I'm now paying for later.