How To Connect To SQL Server In Sahi

Jul 12, 2013

1373908671_databaseSahi includes JDBC support that allows you to read and write to popular databases. In this example we'll be connecting to a SQL Server database.

The Gist...

First off, you need to download the Microsoft Java Database Connectivity (JDBC) driver for SQL Server. This is just a jar that Sahi uses to connect to SQL Server. I'm using version 4 in this example but other versions should work. Next, tell Sahi where to find the JDBC jar (putting it in Sahi's extlib folder is a good idea). And finally, use the dang thing.

Download and install the JDBC

  1. Download the Microsoft JDBC
  2. Check the sqljdbc_4.0.2206.100_enu.tar.gz
  3. Unzip the file and navigate to Microsoft JDBC Driver 4.0 for SQL Server\sqljdbc_4.0\enu\
  4. Copy the file sqljdbc4.jar to Sahi's exlib folder: eg. C:\sahi_pro\extlib\db\ (your Sahi path might be different)

Add the JDBC jar to Sahi's dashboard.bat

  1. Open sahi_pro\userdata\bin\start_dashboard.bat and add the following line:

SET SAHI\_EXT\_CLASS\_PATH=%SAHI\_USERDATA\_DIR%\\extlib\\db\\sqljdbc4.jar;

Use it!

Now that you have the JDBC driver installed and configured in Sahi, it's time to use it. Sahi includes a method _getDB to handle calls to a database. It uses two other methods, select and update to do the heavy lifting. The gist here is we create a variable to handle the db connection (which returns an object) and then use that object to select or update data in the database.

Here's an example...

// config...
var $dbServer = "localhost";
var $dbUser = "sa";
var $dbPass = "password";
var $dbName = "myDB";

// create a handle object...
var $db = \_getDB("com.microsoft.sqlserver.jdbc.SQLServerDriver","jdbc:sqlserver://"+$dbServer+";databaseName="+$dbName+"", $dbUser, $dbPass);

// get all rows from a table...
var $rows = $db.select("Select \* from MyTable");
\_alert($rows.length); // output number of rows returned...
\_alert($rows\[0\].toString()); // output the first row returned...

That's it!

Amazon EC2 Ubuntu HowTos

Feb 24, 2013

ec2Having a server in the cloud is a nicety. That Amazon gives you one free for a year to tinker with... that's being downright friendly!

The following are some notes/howtos for setting up an Ubuntu Amazon EC2 instance. I post them to help me remember them but they might also be useful to others...

Allow SSH Access

If you'd prefer to just ssh into your instance instead of using key/pair...

1. Login using the key/pair you created when setting up your EC2 instance:

ssh -i myprivatekey.pem [email protected]

2. edit your sshd_config file and uncomment and/or set PasswordAuthentication yes:

sudo pico /etc/ssh/sshd\_config

3. Reload SSH:

sudo reload ssh

4. Create a new user and set the user's password:

useradd NAME
passwd // enter password twice...

Install LAMP

1. Update Ubuntu's package database, install and run Taskel. Select the LAMP server (don't deselect anything that is also checked) and let it install:

sudo apt-get update
sudo tasksel

2. Install PHPMyAdmin; select Apache2, enter a root password and say No to config the database later:

sudo apt-get install phpmyadmin

3. Verify by going to: http://myIPaddress/phpmyadmin and login as root with the password you entered. Of course you'll probably want to secure/move this!

Install XRDP on Ubuntu 12.10

Installing X11 on your instance--should you be so inclined--may prove tricky... I tried MANY ways of doing it (OpenBox/FluxBox, VNC, etc...) but each attempt ended in failure. I found victory with XRDP!

1. Found from the instructions here. First install Gnome (will take a while)...

export DEBIAN\_FRONTEND=noninteractive
sudo apt-get update
sudo apt-get install -y ubuntu-desktop

2. Ubuntu 12.10 no longer includes gnome-session-2d, so install fallback and edit .xession to use it:

sudo apt-get install gnome-session-fallback
pico .xsession
gnome-session --session=gnome-fallback // add/change this line in .xession
/etc/init.d/xrdp restart

3. Edit Xwrapper file and set allowed_users=anybody:

pico /etc/X11/Xwrapper.config

4. Create a new Security Group Rule for RDP(i.e. open port 590x (where x is the vncserver id))

5. Install RDP client on your local machine...

Install Chromium brownser on Ubuntu 12.10

FireFox is in need of Unity by default and it appears it doesn't exist on 12.10. I wanted Chrome on there anyway but it didn't work either. Chromium does:

sudo apt-get install chromium-browser

Headed To GTAC New York

Feb 18, 2013

I'm looking forward to attending this year's Google Test Automation Conference (GTAC) in New York!

Adding Copy Filename and Copy Path to Sublime Text's Sidebar

Feb 14, 2013

Sublime_Text_Logo[1]My text editor of choice is Sublime Text but right out of the box, it does not include copy filename or copy file path in the sidebar (both of which I use constantly). Seems that whenever I install it on a new machine (which I just did) I forget how to install the Package Control package, which offers such goodies. Therefore, I thought I would park the instructions here for your--and more importantly, my--convenience.

It's pretty easy...

  1. In Sublime Text, type ctrl+` to access the console
  2. Copy the code below, paste it in the console and hit return
  3. Restart Sublime Text
import urllib2,os; pf='Package Control.sublime-package'; ipp=sublime.installed\_packages\_path(); os.makedirs(ipp) if not os.path.exists(ipp) else None; urllib2.install\_opener(urllib2.build\_opener(urllib2.ProxyHandler())); open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen('http://sublime.wbond.net/'+pf.replace(' ','%20')).read()); print('Please restart Sublime Text to finish installation')

Now, when right/ctrl-clicking a file or files in Sublime Text's sidebar, you should see a wealth of options including copy path/name.

If for some reason this fails to work, you can download and install manually with the instructions here...

Now that you have Package Control installed, use it by typing shift-ctrl-p. You can then, as you might imagine, control Sublime packages. Eg. install, remove, etc.... My two must-haves are: SideBarEnhancements and All Complete. To install them:

  1. Click shift-ctrl-p
  2. Start typing "install" and select Package Control: Install Package
  3. A package prompt appears; start typing the package name, eg. All Auto Complete

That's it! Just repeat these steps for each package you'd like to install.

Chromebook Advanced Shell Commands

Feb 12, 2013

chromebookAs I mentioned in my Chromebook review, the Chromebook has a limited built-in shell that you can access via keys: ctrl-alt-t. You can then enter help to see the available commands... the best of which is the ability to ssh into a unix machine and get your mitts on a full shell! But after fooling around in it a bit, I found there are even more commands available when entering the command help_advanced. The available advanced commands are:

connectivity Shows connectivity status. connectivity help for more details

experimental_storage < status | enable | disable > Enable or disable experimental storage features.

ff_debug [] [--help] [--list_valid_tags] [--reset] Add and remove flimflam debugging tags.

modem [args...] Interact with the 3G modem. Run "modem help" for detailed help.

modem_set_carrier carrier-name Configures the modem for the specified carrier.

network_logging A function that enables a predefined set of tags useful for debugging the specified device.

network_diag A function that performs a suite of network diagnostics. Saves a copy of the output to your download directory.

route [-n] [-6] Display the routing tables.

set_apn [-n ] [-u ] [-p ] Set the APN to use when connecting to the network specified by . If is not specified, use the network-id of the currently registered network.

set_apn -c Clear the APN to be used, so that the default APN will be used instead.

set_arpgw Turn on extra network state checking to make sure the default gateway is reachable.

tpcontrol {status|taptoclick [on|off]|sensitivity [1-5]|set } tpcontrol {syntp [on|off]} Manually adjust advanced touchpad settings.

tracepath [-n] [/port] Trace the path/route to a network host.

wpa_debug [] [--help] [--list_valid_level] [--reset] Set wpa_supplicant debugging level.

syslog Logs a message to syslog.

chaps_debug [start|stop|] Sets the chapsd logging level. No arguments will start verbose logging.]`

Still not what I want but a step forward...

I Heart My Chromebook - A Review

Feb 9, 2013

chromebookI've always been a fan of smaller laptops (my 13" Macbook is a personal fav) so when Google released their Chromebooks, they had my attention. I eventually couldn't resist and picked up the Samsung, arm-based Chromebook XE303 for the extremely reasonable price of $249.

After having a couple weeks on it, I must say I really REALLY like it. It's been shockingly easy to abandon my Macbook in favor of my smaller, lighter Chromebook. In fact, there's very few things in my daily (non-work) routine that I can't do on the Chromebook... Chrome Remote Desktop solves the rest.

What's good:

  • Price!
  • The keyboard and trackpad are great and responsive
  • Battery life - @4.5 hours video; @6.5 hours surfing/etc...
  • Small and light
  • Boots in seconds; wakes instantaneously
  • ChromeOS is simple, intuitive and impressively powerful
  • Chrome Remote Desktop bridges most gaps
  • Overall design is very "Mac-like"
  • Many great, free apps/extensions
  • Setup. If you use Google/Chrome, once you sign in, all your stuff is already there

The bad:

  • The screen is kinda crappy... though certainly servicable
  • Lack of AirTunes equivalent... Google, please make this happen!
  • Lack of full *nix shell is bothersome
  • Power adapter is clunky; wish it was micro usb

One thing that might put ChromeOS over the top for me (and I'm sure I'm not alone) is to allow access to its underlying Linux distro. Like OS X, ChromeOS is just a window manager on top of unix (in this case Linux). I would love to see them continue the trend and allow access to it's Linux underbelly. In short, give me a full shell!

Long story only slightly longer, this Chromebook is a keeper and has me thinking devious thoughts about selling the Macbook and in its stead, getting a Mac Mini server to command via CRD! And I guess I'll need a new signature... something like:

Written on my Chromebook... or maybe not (even if it is true).

Watir-Webdriver Sort Test

Jan 24, 2013

watir.logoWhile convalescing this past weekend from some kinda cold/funk that's been making the rounds, I spent some time playing with Watir-Webdriver. I really like Watir and have heard good things about Webdriver, so I wanted to see for myself. As an exercise, I decided to port my Sahi sort test from a previous post... here's what I came up with.

\# ~ sort test...

require 'rubygems'
require 'watir-webdriver'

browser = Watir::Browser.start 'http://www.javascriptkit.com/script/script2/sorttable.shtml', :chrome

# initial sort...
browser.link(:text => 'Name').click

# collect table column elements in an array...
app\_sorted\_values = Array.new
# itterate through each row (skip the 1st)...
browser.table(:id, 'table0').rows.each.drop(1).each do |row|
    app\_sorted\_values << row.cell.text
 end

# sort with ruby case-insensitive...
ruby\_sorted\_values = app\_sorted\_values.sort {|a,b| a.upcase <=> b.upcase}

puts "App sort: #{app\_sorted\_values} \\nRuby sort: #{ruby\_sorted\_values}"

browser.close

Do feel free to comment and/or make suggestions!