Author Archives: kevin

About kevin

I write the posts

links for 2011-05-19

Liked what you read? I am available for hire.

No, I won’t be friends with you on Facebook

I’m back on Facebook. I probably won’t approve your friend request, however. This tends to upset people and oddly the people who get the most upset are the people with 1000+ friends.

Here are some reasons why I won’t be friends with you on Facebook:

– I don’t want people that I don’t know very well seeing my Wall or photos. At some point in the future, people may have an incentive to make me look bad and reducing the number of people that can access my Wall, and photos, is a good way to help solve that problem. I also don’t want to be worrying all the time about managing what people are tagging and posting to my Wall.

– When I have a small group of friends, all of the updates in my News Feed are from people I care about. It’s easier to keep up with everyone in my social group.

So that’s that. The problem is that a lot of people I know only have Facebook accounts, and use them as their omnibus social media/Internet presence and for these people, adding on Facebook is their way of connecting with me. I don’t see a good way around this problem.

The good news is that if you want to keep up with me, it’s pretty easy – I have a Twitter account, this blog, a quarterly newsletter, a Bitbucket account for sharing code I’ve written recently, a Delicious account for sharing cool links I’ve read lately, and a LinkedIn.

Also, there’s a good chance I’ll add you on Facebook if we’ve spent more than an hour hanging out sometime over the last year. I don’t ever reject anyone, just keep their request pending, in the hopes that we’ll hang out more in the future.

John Graham-Cumming wrote a good post about the same topic over a year ago. I tried to find it, but it’s been swallowed by the Internet.

Liked what you read? I am available for hire.

links for 2011-05-17

Liked what you read? I am available for hire.

Test if your server is up, using Ruby

How do you know if your website is up, right now? Maybe you are browsing it and got an error, or a friend texted to tell you it was down. Otherwise your website might be down and you'd have no idea. Here is a simple script that will help you learn faster whether your website is up or down. I wrote it in Ruby to start learning Ruby syntax.

require 'uri'
require 'net/http'
require 'net/smtp'

def send_email(to, opts={})
    # Send an email. In Ruby, the ||= operator means 'only assign the
    # new value if the value has not been set yet'
    opts[:server]      ||= 'localhost'
    opts[:port]        ||= 25
    opts[:ehlo_domain] ||= 'localhost'
    opts[:username]    ||= 'username'
    opts[:password]    ||= 'password'
    opts[:from]        ||= 'youremail@domain.com'
    opts[:from_alias]  ||= 'First Last'
    opts[:subject]     ||= 'Test email'
    opts[:body]        ||= 'This is a test!'

    # the following says 'create a new string called msg containing everything
    # from here to the END_OF_MESSAGE marker'
    # then, we fill in the email with all of the values we filled in above. Note
    # that there has to be a newline between the subject and the body of the
    # message.
    # This is a plaintext message - to send HTML emails, we would need a more
    # complex template.
    msg = <<END_OF_MESSAGE
From: #{opts[:from_alias]} <#{opts[:from]}>
To: <#{to}>
Subject: #{opts[:subject]}

#{opts[:body]}
END_OF_MESSAGE
    Net::SMTP.start(opts[:server], opts[:port], opts[:ehlo_domain],
                    opts[:username], opts[:password], :plain) do |smtp|
        smtp.send_message msg, opts[:from], to
    end
end

# test for main method
if __FILE__ == $0
    # the domain we want to check
    url = 'http://testdomain.com'
    my_email = "myemail@gmail.com"
    r = Net::HTTP.get_response(URI.parse(url))
    if r.code != "200"
        # we have a big problem, server is down or other
        opts = {
            :server     => 'smtp.yoursmtpserver.com',
            :port       => 587,   # should be 25 or 587
            :ehlo_domain => 'localhost',      #this doesn't matter too much
            :username   => 'yoursmtpusername',
            :password   => 'yoursmtppassword',
            :from_alias => 'testdomain.com Admin',
            :subject    => 'The website is down',
            :body       => "Hey,\nan attempt to reach the homepage returned " + 
            "the status code " + r.code.to_s() + ". \n\nYou should check it out."
        }
        send_email my_email, opts
    end
end
That will send an HTTP request to your website. If the request was successful, you'll get an HTTP Header Response that says 'Status Code: 200 OK'. If we don't get a 200, this means the site is definitely wrong. We may get a 200 and still have problems with the database or other, but this is meant to be a simple test. Other well known codes are 404 (File Not Found), 500 (Internal Server Error), and 418 (I'm a teapot). Once you've got the script in place, save it as "is_server_up.rb" somewhere on a computer which has lots of uptime (your school's CS server, a remote SSH server, or otherwise). Your laptop is a bad choice because when you close your laptop, or are not connected to the Internet, the test will not be able to run. The computer hosting your website is also a bad choice because if that computer goes down, your website will be down but the script will not run. On a Linux or Mac machine, type
$ crontab -e
which should open up a Terminal text editor. Then type:
0-59/2 * * * * /usr/local/bin/ruby /path/to/your/file/is_server_up.rb
where
/usr/local/bin/ruby
is the path to the Ruby executable on your laptop. If you don't know where it is, try typing "which ruby" in the Terminal. If nothing comes up, you probably need to download Ruby. The
0-59/2
bit says to run the script every 2 minutes. You might be worried that fetching your homepage every 2 minutes will generate an extra 720 hits to your site every day and affect your Analytics stats. However, Analytics will only measure visits from browsers that can execute Javascript, and this Ruby script will not execute any Javascript, so you are safe. Note that if you have an important site, or one which generates revenue, you probably should not use this tool - there are better tools like Pingdom that will let you know right away whether your site is down.

Liked what you read? I am available for hire.

links for 2011-05-16

Liked what you read? I am available for hire.

links for 2011-05-13

Liked what you read? I am available for hire.

Advice from freshman year

I wrote this post in March of my freshman year at Penn. I might emphasize different things now and have a little more tact but I think it's worth reposting. Some of the advice here is Penn-specific; having a car definitely helped solve some of these problems. I must admit I wasn't that great at following my own advice. The Quad If your friends are all wearing City Sports t-shirts, buy a City Sports t-shirt. You are, as a freshman and right out of high school, most likely a stranger in a strange land, and it won't hurt to blend in as much as possible. If you are planning on joining a fraternity, start investing in Ralph Lauren. Get a fake ID. Get a good quality one that scans and blacklights, which will set you back around $120. You will need it to get into the clubs and bars around Philadelphia. Keep your room clean. If you can, stack your beds. It's hard to socialize in a small room. Buy alcohol. You will be popular with your friends if you can supply alcohol to them. You will always be able to do schoolwork. Go out. Be generous with your money. If you have money (and if you go to Penn, I am guessing you do). Smile. Nobody likes a grouch. Enter your room with a purpose: Use your room to change clothes, to pick up or drop off schoolbooks, to sleep, to drink with your friends, and to hook up with sloppy drunk chicks. You will not be social in your room. Get off your damn computer. If I had a nickel for every hour I spent checking Facebook, or walking by people's dorms seeing them staring at their computers, I would be rich enough to donate a building. Don't eat alone. Going down to the dining hall and trying to find people doesn't count. Meals are a great time to catch up with people that you don't see every day. Make your habits social habits. If you really like playing basketball, find friends to play basketball with. Reading and playing online poker are nice habits but you will not make friends doing them. Then again, I write a blog and have Google Reader as my homepage.

Liked what you read? I am available for hire.