$ psql "dbname=YOUR_DB_NAME host=YOUR_EC2_HOST user=YOUR_USER password=YOUR_PASS port=5432 sslmode=require"
No relations found.
CREATE TABLE artists (id int, name varchar(80));
CREATE TABLE releases (id int, name varchar(80));
CREATE TABLE recordings (id int, artist_id int, release_id int, name varchar(80));
INSERT INTO artists (id, name) VALUES (1, 'Underworld');
INSERT INTO releases (id, name) VALUES (1, 'Oblivion With Bells');
INSERT INTO recordings (id, artist_id, release_id, name) VALUES (1, 1, 1, 'To Heal');
INSERT INTO artists (id, name) VALUES (2, 'Stars');
INSERT INTO releases (id, name) VALUES (2, 'In Our Bedroom After the War');
INSERT INTO recordings (id, artist_id, release_id, name) VALUES (2, 2, 2, 'The Night Starts Here');
/* Get all recordings of each artist, and show the release */
SELECT rec.name AS recording, a.name AS artist, rel.name AS release
FROM recordings AS rec
INNER JOIN artists AS a
ON rec.artist_id = a.id
INNER JOIN releases AS rel
ON rec.release_id = rel.id;
recording | artist | release
To Heal | Underworld | Oblivion With Bells
The Night Starts Here | Stars | In Our Bedroom After the War
GhostDriver is a project that lets you write Selenium WebDriver automation tests that run using the PhantomJS headless WebKit, instead of a traditional web browser.
Put another way, PhantomJS can replace Firefox and friends in your WebDriver scripts - and it doesn’t require a display, so testing complex web apps from the command line is just about as easy as using a GUI browser. Very cool!
Getting your system ready to run Python scripts that use GhostDriver can be done in a few brief steps, if you have homebrew on OS X.
A natural next step, when developing automated test cases based on experiments like the one above, is to start storing your code into a Python unittest script.
Here’s an example of how one might start organizing the code above:
If all is right with the world, running the above script will print output along the lines of the text below.
current_url is now 'http://www.google.com/search?hl=en&source=hp&q=selenium&gbv=2&oq=selenium'
Ran 1 test in 2.770s
That’s all for the moment. Now, go forth and Ghost Drive!
For instructional purposes (either when experimenting on your own, or when demonstrating code to others) it’s always useful to be able to run snippets of code in a REPL, or a similar environment allowing fast turnaround in the edit/compile/run cycle.
When using Java, the customary IDEs offer ways to get REPL-like behavior, but what if you don’t want to use a traditional Java IDE?
Perhaps you just want to demonstrate a trivial bit of code without much overhead.
In that situation, a couple of nice options for Java are:
Use GroovyConsole as a Java REPL
Edit your code in Vim, and compile and run it without leaving the editor
1. Using GroovyConsole
If you’re on a Mac, GroovyConsole can be installed via the homebrew groovy formula (or, just get it from http://groovy.codehaus.org):
brew install groovy
Launch GroovyConsole with this command:
Then simply type in a code snippet and run it with <Command-R> (or on Windows, <CTRL-R>):
2. Using Vim as an improvised Java IDE
First, launch vim and write a small program - for example, Foo.java:
Then, compile your program without leaving vim by passing the file open in your vim buffer to javac, using the :! command sequence and %
If all goes well, you’ll temporarily be dropped to the shell, with no visible errors, and get prompted to press ENTER to continue back to vim:
Back in the editor, use :!java Foo to invoke the Java class file you just created with javac:
Finally, you’ll see your program’s output in the console.
For further fun, try compiling with javac -g %, then launch your class file with jdb Foo to debug your program from within vim.
Lately I’ve been looking for reasons to use OmniGraffle for diagramming.
And with the steps to set up static web hosting in S3 (as mentioned in my last post) still fresh in mind, it seems like a good time to document what I did. And the steps are simple enough that a diagram might just be enough to cover the important bits.
So here it is - someday it’ll be interesting to look back on this and see what’s easier/more streamlined in this process, and what remains the same: