Smooth.

This slideshow requires JavaScript.

I’m taking a break from the tech-centric stuff today to bring you my smoothie recipe. I play it fast and loose with the ingredients, which pretty much change daily depending on what’s in my fridge.

Ingredients:
1 cup Juice or Milk (I often use Almond milk)
1 heaping teaspoon Creatine, Cacao Powder, Powdered Peanut Butter, and Coconut Oil
1 scoop Vanilla protein Powder
1 scoop Egg White protein powder
1/2 cup rolled oats
1 teaspoon Honey
Kale
Some yogurt
Strawberries

Nutrition Facts:
A shit-ton of protein
Lots of fiber
Complex carbs for energy through the day
Healthy fats to lubricate your arteries
Lots of calories

Feel free to add in Bananas or blueberries (I do this often). Blend it all up.

Makes around 3 cups of smoothie. Drink it quickly, or it will start to separate. Enjoy!

Working with Google Adsense – Part Two

Read part one
TLDR: I gave Google a few bucks to promote my Chrome Extension, Niceties.
After one month of Google Adsense campaigning, I’m here to bring you the results, which were pretty good!

google adwords

First, the numbers.
Clicks: 81
Views: 4,288
Cost: $6.92

The good news: Over four thousand impressions. That’s pretty cool. 81 clicks is decent.

The bad news: these impressions didn’t really translate into more people downloading my application. I now hover around 35 active weekly users, up from around 25. This is awesome, but I have a feeling that these additional users are more due to my buddy Avanish promoting my app on his social media channels.

I’m probably going to close this campaign. It was fun, and a good learning experience, but since I’m not making any money from the application, it doesn’t benefit me to continue marketing it.

Happy Tax Day!

brace yourself

Get a site like mine!

My friend and co-worker Ashpak Shaikh asked me to put together a how-to on a personal website like mine, so I figured I’d write it up as a blog post, just in case anyone else wants to do something similar. It’s super simple, cheap, and easy to maintain.

1) Buy a domain name.

I’ve been using nameCheap.com for a few years now with no problems. I’ve been advised to avoid GoDaddy for numerous reasons, so I can’t really speak to the pros and cons of each service. I can say that NameCheap has everything I need at a cheap price. It’s just a domain name, don’t go crazy with it.

Also – if you find a domain name you like that’s open, snatch it up as soon as you can. People have written scripts that buy up domain names after they’ve been searched, then they sell the name for a profit. They’re assholes.

2) Find some hosting.

I use Amazon EC2, which was free for my first year, and has been averaging around $13-15 per month since. It gives you full terminal access for any imaginable kind of server – Ubuntu, Red Hat, CentOS, even Windows. It also scales automatically if more people visit the site, with the ability to limit the scaling to a dollar amount.
There are cheaper services, namely DigitalOcean. I haven’t used them. Again, whatever floats your boat is fine here.

3) Point your domain name toward your new host.

AWS Tutorial
DigitalOcean Tutorial

4) Set up your server. I use a LAMP setup.

LAMP tutorial for Amazon
LAMP for Digital Ocean

5) Install WordPress.

This tutorial is fucking thorough. It actually covers a lot of what I’ve said here already.

6) Add plugins.

Plugins are a fun and useful part of WordPress. My favorites are Jetpack for monitoring site statistics and social media broadcasting, as well as SyntaxHighlighter for showing my pretty code. There are so many out there. You can even write your own!

That’s all for now! Thanks for reading.

Working with Google AdSense

For fun and experience, I’m looking into using AdSense to promote my free Chrome Extension, Niceties. First, I added a new campaign with a low daily expenditure of 25 cents per day. Next, I created an ad.

I picked a nice headline, and some grabby descriptions. I also pointed the URL to my site’s homepage, rather than my app’s. However, when the ad’s clicked, it still takes the user to the Niceties Chrome Store page.

AdWords setup

One annoying problem: Google disallows using a different URL for the target and the homepage. I just got an email saying my ad has been rejected! So, unfortunately, I had to change them to both be the same.

I also picked out a few cool keywords to help target the users I’m looking for. All that was left to do was enter my payment info, and I’m all set! In one month, I’ll post the results.

Working with the TP-Link TL-WA5210G

I recently picked up two TP-Link point-to-point WiFi extenders for my dad’s shop behind his house. This will allow us to view his Uniden Guardian cameras from anywhere we have access to the internet!

Now that I’ve connected to the router and am logged in to the interface, I have 3 options: AP Client Router, AP Router, and AP. However, the guide doesn’t define these well, so I’m looking up which I should use. We’re going to try AP first.

After a bit of haggling, I found this guide which helped a bit.

After 2 hours, we’re still having issues connecting to the house’s router, though, and the lack of manufacturer diagrams for network setup isn’t helping.

We finally got it to work by simply restarting the equipment and running through the instructions we found again. The feed from the cameras is steady, high-speed, and can handle all four cameras with ease. All in all, this wasn’t the easiest setup, but the gear is weatherproof, holds a signal, and should serve for many years to come.

Big news and a great comic

San Diego skyline
I’ve accepted a co-op at Intuit starting January 26th! I’ll be moving to San Diego, California for 6 months for this great opportunity.

Since I still have a few classes to take before I graduate, I have a lot of work to do so I can still graduate on time. I have to test out of three classes and take one class online.

Here’s a great comic about Java vs. Javascript! I love it.

XBMC Remote Music Client

For the past few days, I’ve been looking into a way to automatically, remotely play music through my speakers when I walk into my room. I’ve done some research and have a pretty simple solution!

Hardware:
The Remote: HTC One M8: the Remote Control phone. This runs Yatse and sends commands to the media client.

The Client: Moto X: This is a spare Android phone I had lying around. This will be the media client.

The Server: For the server, I’m looking into a DIY NAS setup, with up to 32tb of storage space and room for expansion. For testing purposes, though, I’ll be using an old Optiplex GX520 that’s been gathering dust.

Software:

The client runs SPMC, an official fork of XMBC. It doesn’t have to be rooted, which is good, because my phone’s not rooted.
To handle the automation side of things, I’ll be using Trigger to open SPMC and begin media playback.

The server will run FreeNAS and serve media over the network.

Setup:
Client
SPMC
I installed SPMC without a hitch, enabled Remote Web control under settings, then was able to connect my main phone to the client to control it remotely using Yatse. Neat!

Trigger/Tasker setup
So this is where it gets a bit complicated. We need to install Tasker (Paid App) and Trigger, Android apps that allow for automation. On the remote control phone, I set up my tasks using this guide. The guide also mentions this API documentation, which I assume will come in handy in the future.

Server
Serverside, I burned FreeNAS to a bootable USB drive. It took a very long time to complete the image transfer to the thumb drive – 12002.592716 secs, or 3.33 hours.

Booting my server from said thumb drive: While booting, it appeared that the installer had frozen. However, this thread says it just takes a long time on first boot.

5 minutes pass.

Okay, FreeNAS is controlled via a neat web interface, whose location is presented by the server. I’m continuing forward using this guide. So far, it’s been the easiest part of this setup. I even moved it into the closet already!

I’m just remotely installing some plugins.
Web UI

Now, it’s time to test the NAS! I’m copying my music library for this initial test.
First Copy!
So exciting! It’s working! And the speed isn’t terrible, considering it’s reading off my external drive, then sending the data over wifi to the NAS. Again, since the hardware I have now is just for testing, I’m not ultra concerned about it.

I’ve started configuring the plugin I installed, MiniDLNA, using this guide. MiniDLNA grabs my media files and streams them over my network to any client computer – in this case, my phone.

Next steps: Configure the client’s SPMC to connect to the NAS.

PHP Beer Server – Part Two

Part One

Today, we’ll be fleshing out the method bodies of our PHP Beer Service.

First, I’m going to fix the getMethods function.

Old:

/*
 * getMethods returns a Vector of methods accessable to a client
 */
function getMethods( $params ) {
    $methods = array(
                     'getPrice(String beer)',
                     'setPrice(String beer, Double price)',
                     'getBeers()',
                     'getCheapest()',
                     'getCostliest()'
                     );
    return new xmlrpcresp( new xmlrpcval($methods), "vector");
}

New:

/*
 * getMethods returns an Array of methods accessable to a client
 */
function getMethods( $params ) {
    $methods = array(
                     new xmlrpcval('getPrice(String beer)', 'string'),
                     new xmlrpcval('setPrice(String beer, Double price)', 'boolean'),
                     new xmlrpcval('getBeers()', 'array'),
                     new xmlrpcval('getCheapest()', 'string'),
                     new xmlrpcval('getCostliest()', 'string')
                     );
    return new xmlrpcresp( new xmlrpcval($methods), "array" );
}

Here, I’ve updated the getMethods function a bit. I found out that to correctly return the array, it needs to be an array of xmlrpcval objects. So, easy fix.

I made an associative array to hold the beer data. Keeping it simple.

$beersArray = array(
                    'Bud' => '6.99',
                    'Coors' => '8.49',
                    'Corona' => '13.99',
                    'Genesee' => '4.99',
                    'Guinness Draught' => '12.99',
                    'Labatt' => '7.99',
                    'Sam Adams' => '12.49'
                    );

Now that we have our array, we can start on the getPrice function. Thanks to PHP’s enormous amount of well-built methods, it’s as simple as using Array Search.

/*
 * getPrice returns a Double price for a beer
 */
function getPrice( $beer ){
    return new xmlrpcval(array_search( $beer, $beersArray ), 'double');
}

Now, I’m going to move on to function getBeers. I have a feeling I might run into an issue here, since PHP doesn’t support Vectors like Java – I’m passing back an array. We’ll see how this goes in testing.

/*
 * getBeers accepts no parameters, returns a Vector of beers and their prices
 */
function getBeers() {
    return new xmlrpcval($beersArray, 'array');
}

For our next function, getCheapest, it was a little harder to think of a solution, since we have to look through the array, find the minimum value, and then find its corresponding key. Thankfully, a quick Google search led me to StackOverflow, which had the exact solution.

/*
 * getCheapest accepts no parameters, returns a String of the cheapest beer on tap
 */
function getCheapest(){
    return new xmlrpcval(array_keys($beersArray, min($beersArray)), 'string');
}

GetCostliest was ultra easy, since it’s just one function change, from min to max.

/*
 * getCostliest accepts no parameters, returns a String of the costliest beer on tap
 */
function getCostliest(){
    return new xmlrpcval(array_keys($beersArray, max($beersArray)), 'string');
}

SetPrice function wasn’t too difficult, either. Here’s what I came up with.

/*
 * setPrice returns true if set correctly; sets the price for a beer given
 * String $beer
 * Double $price
 */
function setPrice( $beer, $price ){
    if($beersArray[$beer]){ //if the beer exists in the array
        $beersArray[$beer] = $price; //set its value to $price
        return new xmlrpcval(true, 'boolean');
    }
    else{ //we couldn't find that beer
        return new xmlrpcval(false, 'boolean'); //so don't update its price
    }

Great! So, looks like I have all my methods filled in now. Time to test!
Full PHP server file:

<?php
include "lib/xmlrpc.inc";
include "lib/xmlrpcs.inc";
include "lib/xmlrpc_wrappers.inc";

$beersArray = array(
                    'Bud' => 6.99,
                    'Coors' => 8.49,
                    'Corona' => 13.99,
                    'Genesee' => 4.99,
                    'Guinness Draught' => 12.99,
                    'Labatt' => 7.99,
                    'Sam Adams' => 12.49
                    );

/*
 * getMethods returns a Vector of methods accessable to a client
 */
function getMethods( $params ) {
    $methods = array(
                     new xmlrpcval('getPrice(String beer)', 'string'),
                     new xmlrpcval('setPrice(String beer, Double price)', 'boolean'),
                     new xmlrpcval('getBeers()', 'array'),
                     new xmlrpcval('getCheapest()', 'string'),
                     new xmlrpcval('getCostliest()', 'string')
                     );
    return new xmlrpcresp( new xmlrpcval($methods), "array" );
}

/*
 * getPrice returns a Double price for a beer
 */
function getPrice( $beer ){
    return new xmlrpcval(array_search( $beer, $beersArray ), 'double');
}

/*
 * setPrice returns true if set correctly; sets the price for a beer given
 * String $beer
 * Double $price
 */
function setPrice( $beer, $price ){
    if($beersArray[$beer]){ //if the beer exists in the array
        $beersArray[$beer] = $price; //set its value to $price
        return new xmlrpcval(true, 'boolean');
    }
    else{ //we couldn't find that beer
        return new xmlrpcval(false, 'boolean'); //so don't update its price
    }
}

/*
 * getBeers accepts no parameters, returns a Vector of beers and their prices
 */
function getBeers() {
    return new xmlrpcval($beersArray, 'array');
}

/*
 * getCheapest accepts no parameters, returns a String of the cheapest beer on tap
 */
function getCheapest(){
    return new xmlrpcval(array_keys($beersArray, min($beersArray)), 'string');
}

/*
 * getCostliest accepts no parameters, returns a String of the costliest beer on tap
 */
function getCostliest(){
    return new xmlrpcval(array_keys($beersArray, max($beersArray)), 'string');
}

//declare signature, provide documentation
//the php server supports remote introspection
$getMethods_sig = array(array($xmlrpcArray));
$getMethods_doc = "Returns a Vector of methods accessable to a client.";

$getPrice_sig = array(array($xmlrpcArray, $xmlrpcDouble));
$getPrice_doc = "Returns a Double price for a given beer.";

$setPrice_sig = array(array($xmlrpcArray, $xmlrpcString, $xmlrpcDouble));
$setPrice_doc = "Returns true if set correctly; sets the price for a beer given.";

$getBeers_sig = array(array($xmlrpcArray));
$getBeers_doc = "Returns a Vector of the beers on tap";

$getCheapest_sig = array(array($xmlrpcArray));
$getCheapest_doc = "Returns a String of the cheapest beer on tap";

$getCostliest_sig = array(array($xmlrpcArray));
$getCostliest_doc = "Returns a String of the costliest beer on tap";

new xmlrpc_server(array('beer.getMethods' =>
                        array(
                                'function' => 'getMethods',
                                'signature' => $getMethods_sig,
                                'docstring' => $getMethods_doc),
                        'beer.getPrice' =>
                              array(
                                      'function' => 'getPrice',
                                      'signature' => $getPrice_sig,
                                      'docstring' => $getPrice_doc),
                        'beer.setPrice' =>
                              array(
                                      'function' => 'setPrice',
                                      'signature' => $setPrice_sig,
                                      'docstring' => $setPrice_doc),
                        'beer.getBeers' =>
                              array(
                                      'function' => 'getBeers',
                                      'signature' => $getBeers_sig,
                                      'docstring' => $getBeers_doc),
                        'beer.getCheapest' =>
                              array(
                                      'function' => 'getCheapest',
                                      'signature' => $getCheapest_sig,
                                      'docstring' => $getCheapest_doc),
                        'beer.getCostliest' =>
                              array(
                                      'function' => 'getCostliest',
                                      'signature' => $getCostliest_sig,
                                      'docstring' => $getCostliest_doc)
                        ));


?>

PHP Beer Server – Part One

As a followup to my eCommerce site series, I’ll be writing up a project I’m starting for the same Server Programming class. It’s a XML-RPC PHP server that handles beer! Yum.

Beer.

The professor was nice enough to allow us to use a library that handles the nitty-gritty of XML-RPC, so I’ve started to stub in the necessary methods.

<?php
include "lib/xmlrpc.inc";
include "lib/xmlrpcs.inc";
include "lib/xmlrpc_wrappers.inc";

/*
 * getMethods returns a Vector of methods accessable to a client
 */
function getMethods( $params ) {
    $methods = array(
                     'getPrice(String beer)',
                     'setPrice(String beer, Double price)',
                     'getBeers()',
                     'getCheapest()',
                     'getCostliest()'
                     );
    return new xmlrpcresp( new xmlrpcval($methods), "vector");
}

/*
 * getPrice returns a Double price for a beer
 */
function getPrice( $beer ){
    
}

/*
 * setPrice returns true if set correctly; sets the price for a beer given
 * String $beer
 * Double $price
 */
function setPrice( $beer, $price ){
    
}

/*
 * getBeers accepts no parameters, returns a Vector of beers and their prices
 */
function getBeers() {
    
}

/*
 * getCheapest accepts no parameters, returns a String of the cheapest beer on tap
 */
function getCheapest(){
    
}

/*
 * getCostliest accepts no parameters, returns a String of the costliest beer on tap
 */
function getCostliest(){
    
}

//declare signature, provide documentation
//the php server supports remote introspection
$getMethods_sig = array(array($xmlrpcArray));
$getMethods_doc = "Returns a Vector of methods accessable to a client.";

$getPrice_sig = array(array($xmlrpcArray, $xmlrpcDouble));
$getPrice_doc = "Returns a Double price for a given beer.";

$setPrice_sig = array(array($xmlrpcArray, $xmlrpcString, $xmlrpcDouble));
$setPrice_doc = "Returns true if set correctly; sets the price for a beer given.";

$getBeers_sig = array(array($xmlrpcArray));
$getBeers_doc = "Returns a Vector of the beers on tap";

$getCheapest_sig = array(array($xmlrpcArray));
$getCheapest_doc = "Returns a String of the cheapest beer on tap";

$getCostliest_sig = array(array($xmlrpcArray));
$getCostliest_doc = "Returns a String of the costliest beer on tap";

new xmlrpc_server(array('beer.getMethods' =>
                        array(
                                'function' => 'getMethods',
                                'signature' => $getMethods_sig,
                                'docstring' => $getMethods_doc),
                        'beer.getPrice' =>
                              array(
                                      'function' => 'getPrice',
                                      'signature' => $getPrice_sig,
                                      'docstring' => $getPrice_doc),
                        'beer.setPrice' =>
                              array(
                                      'function' => 'setPrice',
                                      'signature' => $setPrice_sig,
                                      'docstring' => $setPrice_doc),
                        'beer.getBeers' =>
                              array(
                                      'function' => 'getBeers',
                                      'signature' => $getBeers_sig,
                                      'docstring' => $getBeers_doc),
                        'beer.getCheapest' =>
                              array(
                                      'function' => 'getCheapest',
                                      'signature' => $getCheapest_sig,
                                      'docstring' => $getCheapest_doc),
                        'beer.getCostliest' =>
                              array(
                                      'function' => 'getCostliest',
                                      'signature' => $getCostliest_sig,
                                      'docstring' => $getCostliest_doc)
                        ));


?>

So thanks to the awesomeness that is Edd Dumbill’s XML-RPC PHP library, that’s pretty much everything besides the body of each method. Tune in next time for part two!