Installing latest PhantomJS on Ubuntu (>= Lucid Lynx)
15 Apr 2013
Tags:
ubuntu, phantomjs
If this somehow lands as a search result and not the official phantomjs site, then read on. No need to build the source since the official site does that for us. Go to the downloads section of phantomjs and download the zipped file for Ubuntu. After downloading, run the following
tar -xvf phantomjs-1.9.0-linux-i686.tar.bz2 sudo cp phantomjs-1.9.0-linux-i686/bin/phantomjs /usr/local/bin/
running phantomjs --version should now give you 1.9.0 or whatever version you dowloaded.
parsing Valums Ajax Fileuploader
27 Mar 2013
Tags:
ajax, javascript
I've been using valums fileuploader for quite a while now. I got the old version which still works but there's an issue with parsing the files depending on the browser that sent the form.
In IE, params[:qqfile] is a tempfile. In other browser, params[:qqfile] is the filename of the file uploaded. Once you know this, it's easy to read the file depending on this particular param
if params[:qqfile].is_a?(String) # FF / Chrome # use request.body.read else # IE ? # use params[:qqfile].read end
Capistrano deploy fails after changing repo URL
26 Oct 2012
Tags:
capistrano
We changed repository from codebase to github and I found out that our capistrano script now fails because it is still referencing the old url. I, of course, changed the git url on the deploy script but I still get the same issue. Googling for it led me to this stackoverflow question. The answer to that question didn't really worked but the comment by Jakub Arnold fixed it.
So the solution is to delete the shared/cached-copy folder.
using mechanize with ssl gives "OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed" error
26 Mar 2012
Tags:
gem, openssl, mechanize
I was given a task to scrape a site that uses ssl. So the first thing I thought of was using Mechanize. When going to the site that uses ssl, I was presented with the following error
OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
At first it was a real pain having to find the right tutorial to set the certificates that you'd use and how to tell mechanize to use them. To help those who might need this in the future, here it is.
First, download the list of certificates from http://curl.haxx.se/docs/caextract.html and save it to a filename. We'll use cacert.pem for this blog. Move cacert.pem inside the lib folder.
Next part is setting up the scraper agent.
cert_store = OpenSSL::X509::Store.new cert_store.add_file = 'lib/cacert.pem' agent = Mechanize.new agent.cert_store = cert_store agent.get 'https://github.com'
And that's it! Enjoy!
overriding the window.confirm dialog
08 Feb 2012
Tags:
javascript
I need to use jQuery Dialog for confirming if a user wants to do a certain action or not. So a link_to with a :confirm attribute will use jquery instead of the browser confirm prompt.
This is the final code (each section will be explained later).
var dialogOptions = { autoOpen: false, modal: true, draggable: false, resizable: false, width: 500, show: 'fold', hide: 'fold', buttons: { "Yes": function() {currentLink.attr('data-answer', 'yes').trigger('click');$(this).dialog('close')}, "No": function() {$(this).dialog('close')} } } $('#global-confirm-dialog').dialog(dialogOptions); $('a[data-confirm]').click(function(event) { currentLink = $(this); var dialog = $('#global-confirm-dialog'); if (currentLink.attr('data-answer') != 'yes') { event.stopImmediatePropagation(); dialog.children('.question').text(currentLink.attr('data-confirm')); dialog.dialog('open') event.preventDefault(); } currentLink.attr('data-answer', 'no'); });