Node and Nginx

On a project of mine, I wanted to route a subdirectory to my Node API using Nginx but keep all other paths on a different directory. Here’s how I accomplished it:

server {
        listen   80; ## listen for ipv4; this line is default and implied
        #listen   [::]:80 default ipv6only=on; ## listen for ipv6

        root /var/www;
        index index.html index.htm;

        # Make site accessible from http://localhost/

        location /api/ {
            proxy_pass http://localhost:3000;
            proxy_set_header Host $host;
            proxy_buffering off;

Basically, I’m using a regex directive so anything that starts with “api” in the url will be routed to Node.

Getting so much done with Trello

At work, we use JIRA to track our tasks and such.

At home, I’ve been using Trello. Even though it’s just me, I do find it motivating to keep moving the cards over to the completed column. It helps me keep track of what I’m doing and what I have to do. Also great for jotting down ideas.

Check out my board! I just went through and labeled all the tasks based on JS/CSS/Python/Node. Haha.


I’ve listened to a fair share of podcasts over the last few years. One that I haven’t gotten tired of is called Smart Passive Income.

It sounds like something spammy where you listen for awhile and get nothing out of it. But actually, he doesn’t really sell on his podcast and actually gives really good advice on starting a business online.

I’ve also listened a lot to Javascript Jabbers but after awhile, I didn’t want to hear people debate code anymore.

Anyways, check them out on iTunes if you’re like me and just need something to listen to. :) I try any podcast once.

Vimeo API and Backbone View

Here’s a rough example of how to create a Backbone view that incorporates the Vimeo API. I plan on cleaning it up a bit but it’s a rough sketch since I don’t have my full application built yet.

var Backbone = require('backbone');
var template = require('templates/video');
var $ = require('jquery');

module.exports = Backbone.View.extend({
    videoUrl: '//',
    events: {
        'click button': '_playButtonPressed'
    render: function () {
        $(this.el).html(template({url: this.videoUrl}));
        this.$player = $('iframe');
        this.url = window.location.protocol + this.$player.attr('src').split('?')[0];
        this.$status = $('.status');
    _listenMessages: function () {
        if (window.addEventListener) {
            window.addEventListener('message', _.bind(this._onMessageRecieved, this), false);
    _onMessageRecieved: function (e) {
        var data = JSON.parse(;

        switch (data.event) {
            case 'ready':

            case 'playProgress':

            case 'pause':

            case 'finish':
    _onReady: function () {
        this._post('addEventListener', 'pause');
        this._post('addEventListener', 'finish');
        this._post('addEventListener', 'playProgress');
    _onProgress: function (data) {
        this.$status.text(data.seconds + 's played');
    _onPause: function () {
    _onFinish: function () {
    _playButtonPressed: function (e) {
    _post: function (action, value) {
        var data = {
            method: action

        if (value) {
            data.value = value;

        var message = JSON.stringify(data);
        this.$player[0].contentWindow.postMessage(message, this.url);

Flask Restless

Today I was playing around with Flask-Restless and using a MySQL database. I’m pretty impressed with Flask-Restless. If all you really want to do is store data and have a REST api, it does the job well.

Here was the beginning bits of my app. I made a bit more progress but I just want to show just a sample. The first part is just the standard stuff. Importing and shit.

import flask
import flask.ext.sqlalchemy
import flask.ext.restless

More standard stuff but I’m plugging in some configs:

# create app

app = flask.Flask(__name__)
app.config['DEBUG'] = True
app.config['SQLALCHEMY_DATABASE_URI'] = 'databaseurlgoeshere'
db = flask.ext.sqlalchemy.SQLAlchemy(app)

Then I defined some SQLAlchemy models.:

# models

class User(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(24), unique=True)
    password = db.Column(db.String(24))
    type = db.Column(db.String(20))
    active = db.Column(db.Boolean)

class Event(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    event_name = db.Column(db.String(100))
    event_type = db.Column(db.String(10), unique=True)
    active = db.Column(db.Boolean)

class Asset(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    asset_title = db.Column(db.String(250))
    description = db.Column(db.Text)
    type = db.Column(db.String(20), unique=True)
    created_by = db.Column(db.Integer, db.ForeignKey(''))
    active = db.Column(db.Boolean)

class CompleteEvent(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    event_id = db.Column(db.Integer, db.ForeignKey(''))
    user_id = db.Column(db.Integer, db.ForeignKey(''))
    event_data = db.Column(db.Text)
    active = db.Column(db.Boolean)

class List(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    title = db.Column(db.Text)
    assets = db.relationship('ListAsset', backref='List', lazy='dynamic')
    active = db.Column(db.Boolean)

class ListAsset(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    list_id = db.Column(db.Integer, db.ForeignKey(''))
    active = db.Column(db.Boolean)

The rest of this is just a matter of creating database tables first. Then instantiate a manager and pass in the app and the db configs. Then create endpoints:

# create db tables


# create manager

manager = flask.ext.restless.APIManager(app, flask_sqlalchemy_db=db)

# create endpoints

manager.create_api(User, methods=['GET'])
manager.create_api(Event, methods=['GET'])
manager.create_api(Asset, methods=['GET'])
manager.create_api(CompleteEvent, methods=['GET'])
manager.create_api(List, methods=['GET'])

# start flask

I’m still a Python newbie but if I can get this far, anyone can. :)

The Fish Story

I went to this restaurant one time and had a significantly bad time. However, in retrospect, it was pretty funny.

At this restaurant, food was alright for the price it was at. I had gone with a couple of my friends and we just wanted something to eat. I didn’t have a problem from the get go even though the restaurant was super cramped. But my biggest issue was that the waitress was rude. She took our order. I wanted the shrimp tempura and what I ended up getting was the mackerel.

We tried to tell her that maybe she got the wrong order. We said “Excuse me, I don’t think this is the right dish…” And then the war begins.

And while standing at another table, she raised her voice and was like “No. That is what you order. I took your order. I know. You ordered the shrimp tempura and then changed it the second time. I heard you. That’s what you said.” Even then I never said the word mackerel the whole time I was ordering.

I was like “Okay, it’s fine. I’ll just eat this” because I’m not one to make a scene for one, let alone a scene while the table she was helping was just staring at her and us.

And she went ON AND ON about how she heard me say that I ordered the mackerel and that she was right.


We splitted the bill and told her to put 14 dollars on a credit card and the rest in cash. She didn’t bother to return our change. Instead of letting us fill out the tip, she kept our change and charged the card 12 dollars and added 2 dollars in the tip to make it 14.

The money part wasn’t a big deal as it was only a few bucks… but you know, we should get our change back just as principle. However, now whenever I eat the fish, I always laugh and think about this experience.

A team of one

The thing about starting a business is that you pretty much have to rely on yourself for the first bit. Pave the way. Set up the processes. I’ve done it all before a few years ago (on a smaller scaled and more ad-hoc).

And if you’re doing this while working a full time job, it might even require burning the midnight oil which is ironic because I’m writing this post at midnight while I’m waiting for my VPS process to finish installing.

I’ve been using Trello to track my ideas, tasks I’ve completed, tasks I want to complete, things I have in progress, and things I’m going to eventually need help with. Fortunately for me, I haven’t had much I couldn’t do on my own and the things I would need help with, I won’t need to find help until later this year. Most of all, I’ve been able to also keep track of all my other projects, like freelance and volunteer work.

I will disclose what my big idea is in a few months. I’ve talked to several people about my idea and some are on the skeptical side but most are onboard and think it’s unique. It’s still in the baby stages and I don’t want to over promise on anything. This post is just to say that I’ve been loving Trello. It keeps me organized and the mobile app is great when I think of new ideas. I just quickly add it to the board and hash it out later. Should try it!

Avoiding the Catastrophe with Backbone Views

I don’t want to disclose what I’m working on but suffice to say, it’s another Backbone application. I’ve taken the time to read up on how to manage views.

The one thing I will say is that I’ve started to let views generate their own el. In the Backbone application I work on at work, I’ve encountered some real problems defining el and making sure there’s no zombies views. It’s terrible.

You can read more about what I’m talking about in this better said blog post.