I spent the weekend hacking at my Salty library for Clojure. Salty is a thin wrapper around the Selenium WebDriver framework, and it allows you to programmatically control a web browser like Firefox, as I've mentioned before. It turns out there is already a Clojure lib for WebDriver---clj-webdriver---that is full-featured, easy to use, and very mature. For that reason, I'm probably not going to invest too much more effort in Salty. But that's fine: I mostly wanted to try this as a learning exercise, and clj-webdriver makes it easier for me to check my homework. Here's a few notes on what I think I got right and what I think I got wrong.
Sunday, November 27, 2011
Sunday, November 20, 2011
Re-formatting variable names
(Series: From PHP to Clojure)
Here's a simple problem: as part of my Salty lib, I want a function that will take camel-case variable names, as used by Java, and convert them to the dash format that's idiomatic in Clojure. In other words, I want a function that will take the string "someVariableName" (camel case)and return "some-variable-name" (with dashes).
Here's a simple problem: as part of my Salty lib, I want a function that will take camel-case variable names, as used by Java, and convert them to the dash format that's idiomatic in Clojure. In other words, I want a function that will take the string "someVariableName" (camel case)and return "some-variable-name" (with dashes).
Monday, November 7, 2011
Salty: a Clojure wrapper for the Selenium Java WebDriver
After my last post, I thought it might be fun to make a full-blown clojure library for working with Selenium WebDriver. I want to do a lot of Compojure/Noir development, and I can see where it might be handy to automate logging in and clicking things with Firefox and IE.
Just to get started, I've set up a repository on github, and have written one quick and dirty test function.
It's not really useful, it's just a quick spot-check you can run at the REPL to make sure everything's set up right. Make sure salty is in your classpath, and then, at the REPL, type (salty.impl/test-with-google). You should see Firefox start up, open up the main Google page, search for "clojure", and then quit. The output in your REPL should be:
More to come...
Just to get started, I've set up a repository on github, and have written one quick and dirty test function.
It's not really useful, it's just a quick spot-check you can run at the REPL to make sure everything's set up right. Make sure salty is in your classpath, and then, at the REPL, type (salty.impl/test-with-google). You should see Firefox start up, open up the main Google page, search for "clojure", and then quit. The output in your REPL should be:
Original page title is Google Page title after searching is clojure - Google Search nil
More to come...
Monday, October 31, 2011
Clojure and the Firefox Zombie
Since it's Halloween, I thought it might be fun to use Clojure to turn Firefox into a mindless zombie, slavishly obeying my every command. Muahahaha.
Saturday, October 29, 2011
A simple API
I've been watching Rich Hickey's talk on simplicity, and trying to take it to heart. He's right: easy is easy, and simple is hard. It takes a lot of work, and careful use of the right tools, to end up with "simple."
So here's one tool (dare I say pattern?) that might be useful in building a simple API. I'm building on some posts and IRC conversations that I've run across, so most of this is not original with me, but I'm writing it down here for future reference.
In the spirit of classic "design pattern" methodology, here is the scenario we're trying to address. We need to write some functions that refer to some kind of state. The specific example I'm using is connecting to an IMAP server: I want to establish a connection, grab some message headers, selectively grab the message contents, and so on. Obviously, I don't want to negotiate a separate connection for each and ever IMAP operation I write code for. I want to connect once, and then share that connection with each of the functions that needs to use it.
Keeping up with starting out
There seems to be an impedance mismatch between the frequency with which I make posts about the easiest way to get started with Clojure, and the release of even easier ways to get started, so I'm going to just bag that thread. I'll just summarize my advice in a few simple bullet points:
- If you have to choose between adding clojure to an existing environment that's already heavily customized, and creating a fresh/clean environment via VirtualBox or some other equivalent, I recommend the fresh/clean environment. If you have a reasonably decent processor, it should be responsive enough to be useful, and the advice you find on the web will be a lot easier to apply if your OS is clean.
- If you don't know emacs, it's worth learning just to get to use paredit.
- If you like GUI IDE's, Eclipse + CounterClockwise works well.
Spring Security on Compojure
I've moved away from using Spring Security for my Compojure/Noir-based web app, but I did eventually get an answer to my question on Stack Overflow, so if anyone's interested, they can look up the example in the answer.
http://stackoverflow.com/questions/6901210/compojure-noir-using-spring-security-for-auth-auth
http://stackoverflow.com/questions/6901210/compojure-noir-using-spring-security-for-auth-auth
Subscribe to:
Posts (Atom)