Author Archives: kevin

About kevin

I write the posts

links for 2010-11-05

Liked what you read? I am available for hire.

links for 2010-11-04

Liked what you read? I am available for hire.

Google Finance killed my weekend project

One annoying thing about Google Finance is that there’s no way to see how your portfolio’s value has changed over time. You can see your cost basis and the current value but none of the intermediate values. Way back when I used to log into MSN Money and record the value in a spreadsheet every day. That didn’t last very long.

Over the weekend I built a tool that keeps track of how much your portfolio’s worth. Every night at midnight it would grab the current value of all your portfolios and store it in my database, and then when you visited my site again, it would display a chart with all of the daily values of your portfolios. I got the entire backend working, and got to the point where the app was displaying all of the daily values on the page in plain text. Here’s my cost basis and a week’s worth of daily values, with some numbers blurred.

This weekend I was going to turn those numbers into a pretty Annotated Time Line using the Google Chart API. Unfortunately (or fortunately), I checked Google Finance today and it turns out that they just built the portfolio value chart into their main product.

Google Finance portfolio view

It’s pretty cool that they put the chart in there; obviously it would have been nice to have visitors to my own site, and I built it so that anyone can log in and check the values, but also a little deflating, that my project won’t be useful for people. Guess I’ll have more time to work on my other projects. In the meantime though, I got better at XML parsing, learned a ton about OAuth, implemented an app with user-specific data for the first time, and got better at programming.

You can grab the code I was using here, or check your own portfolio here.

To learn how you can outperform the Dow by 10%, or to learn more about the app, you should email me here.

Liked what you read? I am available for hire.

links for 2010-11-03

Liked what you read? I am available for hire.

Escaping from your email

I only download my email once every four hours. Otherwise I check it too much. This works really well and my "need to check" email addiction has totally shut off.

For this to work on your own email, you want to set up a Gmail account with an address that no one knows, as well as access to a cron task scheduler. Cron is an application that runs tasks on a set schedule, so every minute or every year or every Monday at 5pm, etc. If you have Mac or Linux, and you're the type of person that keeps their computer on 24/7, you can run "cron jobs" from your local machine (you want to edit the /etc/crontab file - here are some instructions). I use my web hosting provider's cron service, because it will run even when my laptop is shut down.

Here's the script:

 
import imaplib
from datetime import datetime
import email
import smtplib
import sys
import os
import random
import base64

def main():
    #check user
    if os.isatty(sys.stdin.fileno()):
        #i'm trying to get my email by cheating, not a cron
        print "Are you sure you want to do this?"
        ans = raw_input()
        if ans != "yes":
            return
        no_of_mults = 3
        for i in range(no_of_mults):
            a = random.randint(1000,9999)
            b = random.randint(1000,9999)
            print "What is " + str(a) + " * " + str(b) + "?"
            ans = float(raw_input())
            if ans != a*b:
                print "Sorry, incorrect answer."
                return

    imap_domain = "imap.gmail.com"
    imap_port = 993
    imap_username =  base64.b64decode('my_gmail_username_encoded')
    imap_password = base64.b64decode('my_gmail_pass_encoded')

    #smtp settings
    smtp_domain = "my_smtp_host.com"
    smtp_port = 587
    smtp_username = "my_smtp_user"
    smtp_password = "my_smtp_pass"

    email_recipients = ['kburkeorg@gmail.com']

    imap_server = imaplib.IMAP4_SSL(imap_domain, imap_port)
    imap_server.login(imap_username, imap_password)

    server = smtplib.SMTP(smtp_domain, smtp_port)
    server.ehlo()
    server.starttls()
    server.ehlo()
    server.login(smtp_username, smtp_password)

    imap_server.select('INBOX')

    status, email_ids = imap_server.search(None, '(UNSEEN)')

    recipient = email_recipients

    count = 0
    for e in email_ids[0].split(' '):
        if e is not '':
            try:
                raw_msg = imap_server.fetch(e, '(RFC822)')
                msg = email.message_from_string(raw_msg[1][0][1])

                #modify reply-to so we preserve email address
                if not msg['Reply-To']:
                    msg['Reply-To'] = msg['From']

                result = server.sendmail(msg['From'], recipient, msg.as_string())
                count += 1

            except smtplib.SMTPRecipientsRefused, e:
                print "SMTPRecipientRefused" + str(e)
                continue
            except Exception, err:
                print err
                continue

    # so I can see how many messages were printed
    print "Sent " + str(count) + " messages."
    filename = "/home/kevinburke/webapps/b/sent.txt"
    with open(filename, 'w') as f:
        f.write(str(count))
    print datetime.now()

    server.quit()

if __name__ == "__main__":
    main()

Then in your cron file, you want to add the following line:

0 */4 * * * /usr/bin/python /path/to/email/file.py

where

/path/to/email/file
is the filepath to wherever you saved the script above. The 0 means run the script at the top of the hour, and the */4 means run it once every 4 hours.

Liked what you read? I am available for hire.

links for 2010-11-02

  • The algorithm used by this cron is as follows: On start-up, look for a file named .crontab in the home directories of all account holders. For each crontab file found, determine the next time in the future that each command is to be run. Place those commands on the Franta-Maly event list with their corresponding time and their "five field" time specifier. Enter main loop: Examine the task entry at the head of the queue, compute how far in the future it is to be run. Sleep for that period of time. On awakening and after verifying the correct time, execute the task at the head of the queue (in background) with the privileges of the user who created it. Determine the next time in the future to run this command and place it back on the event list at that time value.
  • (tags: vim)
  • wow: "I wanted to see if I could make myself smarter, by strategically placing notes to myself. Intelligence, as I define it, is getting the right information at the right time at the right place, towards whatever end you are going for." Lion emerged from his experiment a changed man. As a result of spending months thinking and writing down his thoughts with a pen, his brain had started to work in new ways. "You can think about hidden subjects - things that are really important, but that people don't have the time to think about, such as: 'How do we communicate?' 'How is thinking structured?' 'What am I doing?'

Liked what you read? I am available for hire.

links for 2010-11-01

  • "Uncertainty allows mothers to select for their children the father who would be best for them. The point is that paternity was ambiguous and it was effectively up to the mother to name her child’s father, or not… Many men have, of course, ended up raising children who were not genetically their own, but really, does it matter…in making paternity conditional on a test rather than the say-so of the mother, it has removed from women a powerful instrument of choice." - is she serious? the choice to sleep around with whoever you want and foist the child on your unwitting husband?
  • we show that punitive house demolitions (those targeting Palestinian suicide terrorists and terror operatives) cause an immediate, significant decrease in the number of suicide attacks. The effect dissipates over time and by geographic distance.  In contrast, we observe that precautionary house demolitions (demolitions justified by the location of the house but not related to the identity or any action of the house’s owner) cause a significant increase in the number of suicide terror attacks.  The results are consistent with the view that selective violence is an effective tool to combat terrorist groups, whereas indiscriminate violence backfires.
  • lots of common design patterns
  • facebook is unhappy medium between highly private, public conversations: Because Facebook has chosen to emphasize growth over monetization these past few years, they have de-prioritized close, meaningful connections over broadly relevant ones with a larger group of friends.  While this will help them get to a billion users faster, and increase their share of brand spend on advertising (where Facebook is really killing it these days), it may create vulnerability to another social network player who focuses on a more tightly-defined social graph with only a few, specific & meaningful Intimate relationships. Intimate relationships that might just monetize more powerfully with 3 close friends, than they do with 300 acquaintances. Better be careful, Zuck. maybe there's a reason Facebook should care more about Intimacy & Privacy that has absolutely nothing to do with government regulation, and everything to do with simply making more Meaning... not to mention more Money, as well.  
  • breathe out before taking a shot, immediately start chewing a savory hors d'oeuvre, then breathe out

Liked what you read? I am available for hire.

When corporations are more ethical than individuals

We were discussing piracy and plagiarism in class today. It's common knowledge that most young people don't consider downloading or copying music from a friend to be stealing. I was going to raise my hand and talk about how the music industry is actually doing fine - it's shifted more now to live shows, merchandise, and commercial licensing. Commercial licensing made me realize that on some issues corporations act much more ethically than individuals; that is, a corporation's larger liability leads them to act more ethically, because the damages are higher. For example, TV companies and commercial makers pay artists to license music during songs; the costs of them playing the songs without permission is much higher. I would also guess that, all other things equal, employees of a centrally owned, national corporation would act more ethically than a mom-and-pop operation in the same line of work. This analysis only really applies to physical crimes like harassment and theft; I believe that employees of big corporations would act more ethically in these areas than individuals, or small firms. There's no individual equivalent to corporate malfeasance, option backdating or share price manipulation.

Liked what you read? I am available for hire.

links for 2010-10-31

  • not many people have ever seen a trick for testing divisibility by 7. Here’s the trick. Remove the last digit from the number, double it, and subtract it from the first part of the number. Do this repeatedly until you get something you recognize as being divisible by 7 or not.
  • Any word you have to hunt for in a thesaurus is the wrong word. There are no exceptions to this rule. You think you might have misspelled a word? O.K., so here is your choice: either look it up in the dictionary, thereby making sure you have it right - and breaking your train of thought and the writer's trance in the bargain - or just spell it phonetically and correct it later.

Liked what you read? I am available for hire.

Preaching the opposite of what you practice

Half a century ago, nursing books warned against being too cuddly and warm with children. Harry Harlow is an extremely famous psychologist who experimented with monkeys to show the opposite - that children seek affection and warmth, and it helps them grow. He gave monkeys a choice between two 'mothers' - a wire mother that dispensed milk and a cloth mother that had no food - and the monkeys overwhelmingly chose the cloth mother. Furthermore, monkeys that could choose only the wire mother later had psychological problems. This was groundbreaking work at the time. So you would expect that Harlow would apply the same lessons to his personal life, right? Not quite:
Harry Harlow did not discover what children need by watching his own. In fact, Harlow was a hard-drinking, possibly alcoholic, workaholic who ignored his two sons so completely that it led his first wife to divorce him. After his boys were grown, he reacquainted himself with them, but his younger son said that although they got along, "we were never father and son." In fact, Harlow's insights about child rearing were not based on studying children at all but came out of his research with monkeys.
Are the people who preach loudest about X the most likely to have shortcomings in their ability to do X? Maybe there are two reasons for preaching loudly about something: 1) You believe you're better at it than everyone else and want to stress its importance to raise your status. 2) People who lack skills in area X try to cover it up by overachieving in other areas, but remain unwilling or unable to improve their skills in area X.

Liked what you read? I am available for hire.