Skip to main content

Posts

Showing posts from September, 2008

Make your rails app launch the web browser when starting

In jruby, if you ever want to start the browser pointing to your application's base index page after rails finishes initialzing your application, you can take advantage of java.awt.Desktop::desktop.browse. java.awt.Desktop::desktop.browse will open the default OS's browser and point it to an URL you pass to it (tested on Windows, failed in Ubuntu+Firefox, don't know if it works on MacOSX or Solaris). Add these lines at the end of environment.rb to launch the browser: include Java java.awt.Desktop::desktop.browse( java.net.URI.new('http://localhost:3000'))

How to make Net::SSH work with Jruby on Windows

Net::SFTP works like a charm in Jruby on Linux. However, when I tested my application in Windows, I ran into a fail "to load -- dl/import ssh" error and then into "IOError (The system cannot find the path specified)". To work around the errors, I had to make some changes to the Net::SSH code to make it work. There are 2 files you need to change gems\net-ssh-2.0.4\lib\net\ssh\known_hosts.rb and gems\net-ssh-2.0.4\lib\net\ssh\authentication\pageant.rb. For known_hosts.rb change the add(host, key) method located at the end of file to read like this: # Tries to append an entry to the current source file for the given host # and key. If it is unable to (because the file is not writable, for # instance), an exception will be raised. def add(host, key) begin #jpt File.open(source, "a") do |file| blob = [Net::SSH::Buffer.from(:key, key).to_s].pack("m*").gsub(/\s/, "") file.puts "#{host} #

Java-jruby program to turn on computers remotely

Using wakeonlan.rb from Kevin R. Bullock, I was able to creat a small jruby swing-gui program for turning on remote computers using Wake On LAN. The program displays in an array buttons corresponding to the computers listed in a text file. When you click the button, the program sends a WOL packet to the computer to turn it on. The code is the following (note that you need wakeonlan.rb in the same folder): # Copyright (c) 2008 Juan Pablo Tarquino # # Permission is hereby granted, free of charge, to any person # obtaining a copy of this software and associated documentation # files (the "Software"), to deal in the Software without # restriction, including without limitation the rights to use, # copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following # conditions: # # The above copyright notice and this permission notice shall be # included in al

New Avery 5160 template for Jasper Reports

I had to create an Avery 5160 (address labels 3x10) template for jasper for work. If you would like to use that production-ready template you can download it from here . The template has been used in a production environment, however, as always, make sure it works for you before printing too many labels :).

Ruby script to get a batch of MARC records

At work we bought a lot of new books for our new library. Our libraries use aprogram called LibraryPro which can import MARC records to add books to the catalog. To save ourselves some time, I look on the web for a script to get MARC records from the Internet and found this excellent script from William Denton. Because I needed to get batches of records and modify the records gotten to follow our custom dewey decimal number (number/category/author), I modified his script to accomplish that and this is how it looks now: #!/usr/local/bin/ruby -w # Script to get a batch of MARC records # #original code taken from http://www.miskatonic.org/library/zmarc.html # original programmer # William Denton wtd@pobox.com # April 2007 # modifications made by Juan Pablo Tarquino http://jptarqu.blogspot.com # Released under the MIT License. # Copyright (c) 2007 William Denton # Copyright (c) 2008 Juan Pablo Tarquino # # Permission is hereby granted, free of charge, to any person # obtaining a cop

Update on Tomcat on SSL

At work, I set up Tomcat 6.0.16 to use SSL using the instructions from http://techtracer.com/2007/09/12/setting-up-ssl-on-tomcat-in-3-easy-steps/ . However, I had to modify some of the steps to make it work on mys system: When generating the Keystore file, make sure you tell keytool that you wnat RSA: keytool -genkey -alias techtracer -keypass yourpassword -keystore techtracer.bin -storepass yourpassword -keyalg RSA Also, in tomcat's sever.xml, use the code snippet from the official documentation (http://tomcat.apache.org/tomcat-6.0-doc/ssl-howto.html) instead of his snippet, e.g.: < connector port="8443" minsparethreads="5" maxsparethreads="75" enablelookups="true" disableuploadtimeout="true" acceptcount="100" maxthreads="200" scheme="https" secure="true" sslenabled="true" keystorefile="/home/yourself/apache/webapps/techtracer.bin" keystorepass="yourpassword