PhotoAlt
Mar 29

Image Post

builtwithbootstrap:

CSSDeck

@cssdeck is a Collection of Pure CSS Creations! Let’s form a big collection of items built with pure CSS and HTML and help frontend coders realize the power and flexibility of CSS. Hopefully the creations will help them get better at the new features of CSS (and in general too) and they’ll start making more use of it in their projects :)

wow, that looks suprisingly similar to http://dribbble.com, which I just heard about, although the functionality is like completely different…  also http://beta.theexpressiveweb.com/ by adobe is really nifty! the futureeee of the web is exciting :). I remember back in the day being so impressed by the css zen garden; how far we’ve come! 

(via sillysia)

Selenium::Remote::Driver - mouse_move_to_location

I’ve been trying to figure out how to use move the mouse in Selenium Webdriver. I’m using perl, so I’m using the Perl bindings obviously - Selenium::Remote::Driver has a function called mouse_move_to_location, and the documentation for that is the same as what is provided officially by the Selenium project, and both weren’t very forthcoming with why I couldn’t get it to work.

I’ve been banging my head against the wall for this one and eventually just gave up, but the whole time the answer was staring me in the face. The syntax for the arguments to this function in the documentation is different from any of the others - it accepts a hash, like {element => $element}, not just a WebElement or a Sizzle locator or anything like that. Sheesh. I feel pretty dumb about that, but at least it’s solved now :)

Selenium WebDriver, Perl, and Saucelabs.

Last year, Selenium introduced WebDriver, an automated browser program that runs the browser in the same way that a user would.  Saucelabs offers a way to test multiple browsers on multiple operating systems in parallel, completely automated, by running the Selenium software and selling time on their servers. Perl is fun. Saucelabs doesn’t have documentation for connecting to their OnDemand service using WebDriver and Perl, so I’d like to explain how to do that. 

Using Gordon Child’s Selenium::Remote::Driver, it’s pretty straightforward to use Perl to run tests on Saucelabs using WebDriver. Get Selenium::Remote::Driver if you don’t have it (sudo CPAN install Selenium::Remote::Driver). 

#! /usr/bin/perl
use strict;
use warnings;
use Selenium::Remote::Driver;

my $desc = "perl webdriver bindings and selenium!";

my $login = "loginName";
my $apiKey = "myApiKey";
my $host = "$login:$apiKey\@ondemand.saucelabs.com";

my $driver = new Selenium::Remote::Driver(
'remote_server_addr' => $host,
'port' => "80",
'browser_name' => "firefox",
'version' => "7",
'platform' => "WINDOWS",
'extra_capabilities' => {'name' => $desc},
); $driver->get('http://www.google.com'); print $driver->get_title(); $driver->quit();

Plugin your login name and api key and that should get you up and running. The script opens FF7 on Windows 2003, gets google.com and outputs “Google” as the title of the webpage. 

For anyone using the Selenium RC WWW::Selenium bindings, things are a bit different in Selenium::Remote::Driver - namely, many of the events (clicking, getting information) are done as methods to a new Selenium::Remote::WebElement object, not the selenium driver object. It was a bit of a pain to migrate over, but I think it’s a lot cleaner now. So far, everything I did with WWW::Selenium I’ve been able to duplicate with Selenium::Remote::Driver, and in most cases it’s much simpler and more elegant :)

Using Perl’s CPAN Library Without Root

At my work I ssh into a linux box somewhere in the cloud. Since I’m not Ops, I don’t have root access on the box, but I am consistently running into situations where I need to install modules from CPAN on to the box. Without sudo, I was having a lot of trouble writing code with new functionality and not being able to utilize the CPAN library.

But, luckily, stackoverflow came to my rescue. Or, in particular, Chas Owens did, with the following simple three lines:

wget -O- http://cpanmin.us | perl - -l ~/perl5 App::cpanminus local::lib
eval `perl -I ~/perl5/lib/perl5 -Mlocal::lib`
echo
'eval `perl -I ~/perl5/lib/perl5 -Mlocal::lib`' >> ~/.profile

So, the first line runs a script to install App::cpanminus and local::lib. cpanm is CPAN without all the customization options, so you can just cpanm Module::Name and not worry about a thing. local::lib lets you install to non-root directories. The second line uses local::lib to tell perl where to look for the new modules, and the third line exports it to ones .bash_profile so it’s used each time we log in.

Finally, since the scripts I’m writing actually get run as root, 

use lib("~/perl5/lib/perl5");

I just have to insert that line into my script to tell perl where to look. 

tl;dr - I <3 CPAN & stackoverflow.

OS X Lion doesn’t always play nicely with CPAN :(

So, I am trying to set up the Net::IMAP::Simple::SSL perl module installed on my Macbook running OS X Lion 10.7. BUT ALAS apparently Apple uses a stupid deprecated version of gcc in the bloated 4.5gb Xcode, leading my sudo cpan install Net::IMAP::Simple::SSL command to fail during the installation of the EV module.

The exact error code was

t/11_signal.t …… 1/24 Argument “EV::RUN_ONCE” isn’t numeric in subroutine entry at t/11_signal.t line 48.

So, intrepid explorer that I am, I threw that into Google in hopes of stumbling on to someone else’s solution. Lucky for me, the first result was a mailing list post about my exact problem, and the first response to that post contained a link to a submitted bug at LLVM.org where the final comment contained a tiny patch to one the EV.xs file in the EV module.

I downloaded the tarball of the EV module from CPAN and did the usual:

tar -xvzf EV-4.03
cd EV-4.03
perl Makefile.PL
// says some stuff
make
// says some other stuff
make test
// says some more stuff, then breaks

As expected it was throwing the same error from before. According to the bugfix from the LLVM.org, I needed to change one and a half lines of code in EV.xs so I opened it up in Emacs and M-g g’d to line 426 on a whim. (Probably more reliable would’ve been C-s newCONSTSUB). Around there, I added in the lines

const void* civ_start = const_iv;
for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ— > civ_start; )

which replaced the old for loop above the newCONSTSUB thing. So, problems solved, thanks to the Google, no thanks to the stupid Apple Xcode gcc. Grrr…

EasyPG for Emacs on OS X, or sometimes Emacs doesn’t load the env paths you might expect

EasyPG is an Emacs package that allows you to interface with GnuPG (Gnu Privacy Guard) natively Emacs. It’s pretty handy to be able to encrypt files on your own machine for sensitive data, and the interface is largely transparent - files with the .gpg extension are automatically encrypted and decrypted for you. Nifty, eh?

According to the EmacsWiki, Easy PG is included in the more recent versions of Emacs (22+ iirc), but when I tried to save a file as .gpg, I’d get the following error in my minibuffer:

Searching for program: no such file or directory, gpg

So, I figured, cool, I guess I don’t have it installed. ‘which gpg’ and ‘locate gpg’ confirmed my suspicions, so I set out obtaining GnuPG. For OS X, there’s a pretty handy automatic installer over at MacGPG and the dmg even had an uninstaller. I ended up using homebrew (‘brew install gpg’) since that was a bit simpler.

So now here I am with a working copy of gpg, fixed up my $PATH with ‘/usr/local/bin/’ where gpg was located, and Emacs was still giving the same error! “Searching for program: no such file or directory, gpg.” I gave up a few times because I was sure I had gpg in the right paths, and everything was pointing to the right places; even opening up a shell within emacs I was able to access gpg.

As it turns out, there are some peculiarities that one might encounter when running Emacs as an application on OS X. In particular, Emacs doesn’t pick up the $PATH variable unless you tell it to, and the shell won’t read off of ~/.bashrc unless you tell it to. This apparently only occurs when running Emacs off the dock or from Spotlight or something. Since my Emacs is running from a shortcut on the dock, I finally found my solution!

Explicitly adding the path to gpg in my ~/.emacs fixed the problem as expected; joy and happiness abounded. In case you’re curious whether your exec-path has what you’re expecting, ‘C-h v exec-path’ is the command you’re looking for. And now, I can encrypt and decrypt things at will, oh boy!

(add-to-list ‘exec-path “/usr/local/bin”)

Alternatively, it seems like you can also manually set the path to gpg in the epg-gpg-program variable: (setq epg-gpg-program “/usr/local/bin/gpg”). For extra credit, I also edited /etc/profile so that the Emacs shell would pick up the proper $PATH environment too.

#/etc/profile begin
    if [ -x /usr/libexec/path_helper ]; then
        eval `/usr/libexec/path_helper -s`
        defaults write $HOME/.MacOSX/environment PATH "$PATH"
    fi
    #/etc/profile end

Using an Identity File in Emacs Tramp Mode

Emacs has a remote editing mode where you can login to a remote computer via ssh/whathaveyou, and edit the file with your local emacs instance. This is particularly awesome if the remote box doesn’t have any flavor of emacs, and instead only has vi. The mode is called Tramp

TRAMP stands for `Transparent Remote (file) Access, Multiple Protocol’. This package provides remote file editing, […] using a combination of rsh and rcp or other work-alike programs, such as ssh/scp.

It’s pretty straightforward to get Tramp installed. I followed the instructions in the manual and used cvs to checkout and update a local copy in ~/emacs/tramp, and then I added ~/emacs/tramp/lisp to my loadpath in ~/.emacs:

(add-to-list ‘load-path “~/emacs/tramp/lisp/”)
(require ‘tramp)

The problem I ran into was that I didn’t have a password for the box I wanted to ssh into. All I had was a .pem identity file. (Perhaps it’s also called an rsa key? I’m not really sure). Googling permutations of ‘emacs’, ‘tramp’, ‘permissions’, ‘identity’, ‘ssh’, ‘key’ and such was for once not providing me with a straightforward solution, but I got lucky on one search and ran into some stuff about the ~/.ssh/config file that solved the problem for me.

In ~/.ssh/config, you can specify an alias for a hostname and also specify default settings for that host, such as the username, identity file, and some other things. What’s more, Tramp will automatically pick up on these settings so if your ~/.ssh/config file has the identity file reference, Tramp will too :). My ~/.ssh/config entry looks something like:

Host ALIAS_FOR_REMOTE_BOX
   HostName REMOTE_BOX_ADDRESS
   Username DEFAULT_USERNAME
   IdentityFile PATH/TO/IDENTITY.FILE

So now, I can ssh into that box from the command line with just ssh ALIAS, or if I’m inside emacs, C-x C-f /ALIAS:/path/to/files.  Awesome :)

Inserting a Newline in Emacs’s Search and Replace

So, I wanted to Search and Replace (M-%) something earlier this week, but I wanted to use a newline character in the query or the replace. As it turns out, there is a way that you can do this, which makes sense because, after all, you can do everything in Emacs. After starting the search and replace, you can use C-q C-j to insert a new line.

Other clever solutions include yanking a newline character and pasting it in with C-y, but I’m too lazy for all that jazz.

Page 1 of 1