Well... it's my birthday so you can all suck it up and read my programming thoughts. Today was the day I was supposed to have like fifteen apps on the market, and a slew of accomplishments to boast of, but, unfortunately I'm not quite there...
Now, I'll be the first to tell you that I'm still a newbie to the programming world, but I have come a good way. Considering my status, I should probably refrain from saying this, but whatever.. My thoughts on the subject are simple.
It's much more fun than difficult.
The secret to programming is fun assignments
I have taken more than my share of online programming classes... and there is a very long list of classes that I have not finished, with a considerably shorter list of classes that I have completed in entirety. And the secret really is fun assignments
One of the more recent classes I've been taking encouraged students to take a very simple python script, and explain it to a non-programmer. Well, I figured I'd give it a shot
There was a fun Youtube game going around called RickRolling
, which included directing people to Rick Astley's "Never Gonna Give You Up".
Here is how you can permanently Rick Roll your roommate
Hopefully this is fun for you, and I can excite you a bit about programming. This consists of one script, we will call rickroll.py. Here is the code, and I will try to walk you through it. Unfortunately, I am assuming that all of my readers are working on a Unix (Mac) environment.
So, what this program does:
While this program is running, it will open the Rick Astley video every five minutes, but let's walk through the code
Every line starting with '#' is a comment
and will be ignored by the program. It is simply for the developer's use. The first two lines are import
statements, which bring in other python code from the Python Core Library. We then set up a while
loop that will keep repeating as long as the condition, the part between the '()' is true (e.x 1>0.. "word" == "word"), and sicne we explicitly say True... it will always be True). First thing in this loop is we tell the program to wait for 5 minutes (time.sleep(300)). Then we open the browser with that URL and repeat this loop.
Running the Code
To run this code you will need to save those lines of Python script on the computer you want to do it to. So, ask your buddy to use his computer.
I'm sorry, this probably isn't the easiest way to perform this task, but it will set you up well for the extra credit.
Open up Terminal
and perform the following commands: (Can open up terminal by pressing Command+Spacebar on a Mac and typing Terminal.
(hit return, this will take you to your Desktop directory, i.e where your Desktop files are saved)
(this will open up a default text editor on Mac)
(Copy and paste the rickroll.py code)
(Save it by pressing Control+x+s at the same time)
(Exit emacs by pressing Control+x+c)
python rickroll.py (will start the script and the video should play every five minutes)
If you're buddy gets back on his computer and decides whatever happening in Terminal is probably opening the video, and exits out of Terminal, then this program will stop. So, let's not let him do that
. To make this happen we will be using Unix's built in Screen
. Doing this is very simple. Before typing python rickroll.py
, add the following commands:
screen -D -R
(this will let you run a program in the OS background)
(it will open a new session for you to type what program you want to run as well)
(this will start running the script)
(Press Control+a+d to exit this session and keep the program in the background)
You can now exit out of the Terminal application and return the computer to your friend
I Feel Guilty
If you really feel bad and your friend is getting angry, maybe you let him off the hook.
To stop the process, you just need to enter the following commands:
(Open up Terminal again)
screen -D -R
(get back to background session)
(Press Control+x+c to cancel the Python program)
So if you do decide to run this program on somebody, please let me know how it goes.