Sunday, October 18, 2015

Flexible tests with DataProviders and Strategies

DataProviders

TestNG DataProviders are a powerful way to parameterize test classes, allowing you to run a single test method many times with different inputs.

For example, say we'd like to assert that a group of web search engines have a 'search box' on their home page, but because they're maintained by different companies, don't have a common HTML locator. Here we use a DataProvider to maintain a list of URLs and their corresponding 'search box' IDs, go to the URL and assert the search box is visible.

However, let's say that one day DuckDuckGo adds an ad to their main page that hides the 'search box' until you close it, but we still want to assert that the 'search box' is still there. We could add some complexity to our @Test method that clicks the ad, but only for duckduckgo.com, or we could add a second DataProvider and a second @Test that does the additional step. Both of these make the test awful to read, unfortunately.

Using Strategies

I've found that using DataProviders to provide assertion Strategies is a great way to solve this type of problem. Here we create interface SearchEngine, and implementing classes DefaultSearchEngine and DuckDuckGo to abstract the varying behavior away of preparing the page from the test method. And then provide a SearchEngine to the test method using searchBoxProvider.

Tuesday, November 5, 2013

Proxy Nodejitsu drone witth nginx

When developing an Angluar application, I needed to make requests to remove servers, and encountered the "Access-Control-Allow-Origin" problem. To overcome this, I decided to proxy the remote server using nginx. Since a remote server was a nodejitsu drone, I needed to modify my nginx configuration a little further than normal: Note the proxy_set_header Host line. This is needed because nodejitsu proxies their drones according to the Host header (docs).

Wednesday, October 30, 2013

Unit testing state transitions with ui-router and karma/jasmine

Testing ui-router state transitions with karma/jasmine is straightforward. The unit test: And karma configuration: Note the html preprocessor and inclusion of the views in the "files" array.

Thursday, April 11, 2013

Extended desktop using XFCE

In the XFCE display settings manager, if you see your screen but instead of extending the desktop it clones the desktop on both displays.




To enable this. use xrandr
You should see something like this

LVDS1 connected 1366x768+0+0 (normal left inverted right x axis y axis) 310mm x 174mm

blahblah

HDMI1 connected 1280x720+1366+0 (normal left inverted right x axis y axis) 16mm x 9mm

To extend the desktop and use the HDMI connected monitor on the right side, do this:
➜  ~  xrandr --output HDMI1 --right-of LVDS1



Wednesday, October 10, 2012

Use Meld as a diff tool for git

To view git diff through meld, my favorite diff viewing tool, do the following:

  1. Write a small script in ~/bin/gitdiff, or wherever you like to store your scripts
    #!/bin/bash
    meld $2 $5


  2. git config --global diff.external ~/bin/gitdiff
Done!

RESTful API development using Node

Below are some helpful things I've come across while developing a RESTful API for a project of mine. I'll be updating this as I go.
  • REST-esting using curl -- a guide to using curl for testing RESTful API's
  • Postman Chrome Extension. Much better than using curl, in my opinion. 
  • Apigee is a web service meant to serve as a middleman between your server and clients. Useful for things like rate limiting, limited JSON->XML conversion, and even load balancing. 

Thursday, September 20, 2012

Fixing Penn State Wireless Network Stability Issues on Linux

On Linux Mint (and I'm assuming most Gnome-based distributions of Linux), NetworkManager does a bad job staying connected to the new psu network that has spread to most of campus.
wicd is an alternative network manager that seems to relieve a lot of the problems that NetworkManager had.

Install wicd
$ sudo apt-get install wicd
Then edit or create an encryption template "psu" as /etc/wicd/encryption/templates/psu. Note that this file may exist already but is probably outdated (as of today, mine was outdated). Find my version of the psu encryption template here: https://bitbucket.org/zachwolfe/dotfiles/src/2dc9a24fbc7b/etc/wicd/encryption/templates/psu
Then open the wicd-gtk client and connect to the "psu" network using the "psu" encryption template you just defined. You should also select the "use these settings for all networks sharing this essid" checkbox as well for obvious reasons.

Saturday, September 15, 2012

HP dm4 laptop right click fix

On Linux Mint Cinnamon, (and probably most Ubuntu versions at or before 12) my hp dm4's synaptics touchpad did not automatically detect that it has a right a left button.

To fix this, create the directory /etc/X11/xorg.conf.d/

$ sudo mkdir -p /etc/X11/xorg.conf.d

Then place this file into /etc/X11/xorg.conf.d:
https://bitbucket.org/zachwolfe/dotfiles/src/88321594ef20/etc/X11/xorg.conf.d/50-synaptics.conf

Restart the X Server (Ctrl Alt Backspace or log out or reboot)

Wednesday, August 1, 2012

nginx HTTP/HTTPS setup

Setting up nginx SSL is pretty easy. I'm running nginx/1.0.10.

Use make-ssl-cert to make your SSL certificate.
make-ssl-cert /usr/share/ssl-cert/ssleay.cnf /etc/ssl/private/zachwolfe.org.crt Copy this file to /etc/ssl/private/zachwolfe.org.key and /etc/ssl/certs/zachwolfe.org.crt.

Modify /etc/ssl/private/zachwolfe.org.key to only include the key (as follows):
-----BEGIN CERTIFICATE-----
...key text is here....
-----END RSA PRIVATE KEY-----


Modify /etc/ssl/certs/zachwolfe.org.crt to only include the certificate (as follows):
-----BEGIN RSA PRIVATE KEY-----
...certificate text is here....
-----END CERTIFICATE-----


nginx setup:
File /etc/nginx/conf.d/zachwolfe.org.ssl.conf
server {
    listen       443;
    server_name  zachwolfe.org;

    ssl                  on;
    ssl_certificate      /etc/ssl/certs/zachwolfe.org.crt;
    ssl_certificate_key  /etc/ssl/private/zachwolfe.org.key;

    ssl_session_timeout  5m;

    ssl_protocols  SSLv2 SSLv3 TLSv1;
    ssl_ciphers  HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers   on;

    location / {
        root /var/www/;
        index  index.html index.htm;
    }
}


File /etc/nginx/conf.d/zachwolfe.org.conf
server {
    listen       80;
    server_name  zachwolfe.org;
    access_log /var/log/nginx/zachwolfe.org.access.log;

    location / {
        root /var/www/;
        index  index.html index.htm;
}

Wednesday, June 27, 2012

Running vim as a server without X

So far, running vim as a server without X is impossible as far as I know. I don't understand why vim depends on X at all, especially for this case.

$ vim --servername foobarbaz
doesn't work, and even worse, silently fails. No warnings, errors, etc.

I thought it could be that vim didn't have some kind of compile option, but:
$ vim --version | grep client
+clientserver +clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments


The only way to use vim's built in server is to give it a valid DISPLAY value at startup. This makes vim behave a little slower, which is especially noticeable at startup.

DISPLAY=:11 vim --servername foobarbaz





To start a server:
DISPLAY=:0.0 vim --servername mainVim

To edit a file on an already running vim server:
DISPLAY=:0.0 vim --servername MAINVIM --remote-tab-silent `find -type f -name filename`

Wednesday, June 13, 2012

Compiling GNU/screen with vertical split support

Yum (on RHEL5) GNU/screen doesn't come with the vertical split patch. We just need a newer version.
git clone git://git.savannah.gnu.org/screen.git
$ cd screen/src
$ ./autogen.sh
$ ./configure
$ make
# make install

Monday, May 21, 2012

Workaround for ssh session git pushes failing

$ git push origin master

(gnome-ssh-askpass:22648): Gtk-WARNING **: cannot open display:

This occurs because the SSH_ASKPASS environment variable is set to "/usr/libexec/openssh/gnome-ssh-askpass", which is the nice gtk window that pops up when you're running gnome. I don't want this, because I do most of my work over SSH, so simply change SSH_ASKPASS to something else. In my ~/.bashrc
alias git="SSH_ASKPASS='' git"

Then: $ source ~/.bashrc

Fixes it up.

Sunday, April 15, 2012

Running PyBrain in a virtual environment

I recently worked on a class project using Neural Networks and PyBrain. Because my university gives High Performance Computing cluster accounts to students that request them, I decided it would be a good idea to put them to use.

To install PyBrain on a machine with no python installation or administrator access:

  1. Download and compile python 2.6.x
  2. Download virtualenv
  3. Create a virtualenv using the aforementioned python binary.
    python virtualenv -p /path/to/python2.6 ENV
  4. Source the virtual environment's environment
    source ENV/bin/activate
  5. Download and compile BLAS. Ensure to use -fPIC if your system requires it. Make sure NOOPTS and OPTS are correct.
  6. Download and compile LAPAC.
  7. Use pip to install numpy
    LAPACK=~/lapack-3.4.0/liblapack.a BLAS=~/BLAS/libfblas.a ~/scratch/work/ENV/bin/pip install numpy
  8. Download and compile scipy. set the --fcompiler option to gnu95, to ensure numpy and scipy use the same compiler.
    LAPACK=~/lapack-3.4.0/liblapack.a BLAS=~/BLAS/libfblas.a ~/scratch/work/ENV/bin/python setup.py build --fcompiler=gnu95
  9. Use pip to install pybrain.
    ~/scratch/work/ENV/bin/pip install pybrain
  10. Test pybrain.
    python
    >>import pybrain


Tuesday, March 13, 2012

Automount NTFS partition using Ubuntu 11.10

To automount an NTFS partiton, add the following to /etc/fstab:
15 UUID=58C7049A417B945D /media/media ntfs rw,auto,users,exec,nl=utf8,umask=003,gd=46,uid=1000 0 2

Substituting your partition's UUID and mount point (I chose /media/media). To find your partiton's UUID, run sudo blkid


Then, test with:
mount /media/media
This yields an error:
mozach@dm4:~$ mount /media/media
Mount is denied because setuid and setgid root ntfs-3g is insecure with the
external FUSE library. Either remove the setuid/setgid bit from the binary
or rebuild NTFS-3G with integrated FUSE support and make it setuid root.
Please see more information at
http://tuxera.com/community/ntfs-3g-faq/#unprivileged


To fix this we must recompile ntfs-3g to include FUSE support.
Download ntfs-3g source:
zach@dm4:~/ntfs$ wget http://tuxera.com/opensource/ntfs-3g_ntfsprogs-2012.1.15.tgz
Decompress:
zach@dm4:~/ntfs$ tar -xvzf ntfs-3g_ntfsprogs-2012.1.15.tgz
Configure (including internal FUSE support):
zach@dm4:~/ntfs/ntfs-3g_ntfsprogs-2012.1.15$ ./configure --with-fuse=internal
Compile:
zach@dm4:~/ntfs/ntfs-3g_ntfsprogs-2012.1.15$ make
Install:
zach@dm4:~/ntfs/ntfs-3g_ntfsprogs-2012.1.15$ sudo make install

Reboot and /media/media should be mounted automatically.

Friday, February 10, 2012

Fedora Core 16 bash hanging on 'command not found'

$ sasdasd
bash: sasdasd: command not found...
*wait for a few seconds*

Fedora thought the feature of attempting to look up an invalid command in the yum database was good to enable by default. I see how this is useful, but I find it really annoying (simply because it's slow).

To remove (as root):
sed -i 's/SoftwareSourceSearch=true/SoftwareSourceSearch=false/' /etc/PackageKit/CommandNotFound.conf

Wednesday, December 28, 2011

Root Droid Incredible 2

  1. Disconnect phone
  2. Download and install HTC Droid Incredible 2 drivers (http://downloads.unrevoked.com/HTCDriver3.0.0.007.exe)
  3. Download http://droid.neolobster.com/roms/vwhk-12102011-c.zip MD5: 26a2dbcb96d82153add7edaccd157996
  4. Run the following commands:
  5. adb shell rm -r /data/local/tmp/* adb push zergRush /data/local/tmp/zergRush adb push misc_version /data/local/tmp/misc_version adb shell chmod 777 /data/local/tmp/zergRush adb shell chmod 777 /data/local/tmp/misc_version adb shell /data/local/tmp/zergRush adb shell /data/local/tmp/sh -c '/data/local/tmp/misc_version -s 2.18.605.3' adb reboot bootloader fastboot oem rebootRUU fastboot erase cache fastboot flash zip RUU_Vivo_W_Gingerbread_S_VERIZON_WWE_2.18.605.3_Radio_1.09.01.0622_NV_VZW1.92_release_199487_signed.zip fastboot reboot
  6. Run Revolutionary ( http://revolutionary.io/ )
  7. Follow the instructions from http://forum.xda-developers.com/showthread.php?t=1219246
    The purpose of this guide is to walk you through the process of rooting your phone running 2.3.3 ONLY! I will do the best I can to make this as painless as possible and help you achieve your goals of S-Off.


    ***THIS THREAD IS ONLY FOR OBTAINING S-OFF, OBTAINING ROOT, AND INSTALLING CLOCKWORK MOD RECOVERY! ANY QUESTION REGARDING INSTALLING ROMS DO NOT BELONG HERE AND WILL NOT BE ANSWERED! ONLY ISSUES REGARDING ROOT WILL BE ANSWERED BY MYSELF OR OTHER MEMBERS.***

    What you will need: (** = File is attached to OP)

    Windows XP or higher (Thats all I have, someone else with MAC and/or Linux will need to assist and I can add it to the OP)

    http://revolutionary.io/ .:UPDATE:. PRE4 now available
    This site is where you will download the rooting tools and obtain a beta key. When you click on the download button for your OS, make sure you view the box that pops up requesting your OS version, phone model, HBoot version, and phone serial number. Without doing this you cannot root your phone so do it or you are screwed. There are two ways to get your phone serial number: 1) Remove the battery and look at the white sticker or 2) On your phone, go to Settings -> About Phone -> Phone Identity and under Device Serial Number you will see it. After you receive your code COPY AND PASTE it onto a word document or notepad because there are times when you will get confused with the font type from the Revolutionary site. Example, in my beta key, the lower case L looks exactly like the capital I and it threw me off. Also, the key IS case sensitive so keep that in mind.

    If running windows, you will need these drivers:
    http://downloads.unrevoked.com/HTCDriver3.0.0.007.exe
    If running Linux, reports show that you do not need any drivers.
    If running Mac OS, I currently do not know so someone please let me know and I will update.

    http://goo-inside.me/superuser/su-2....fgh-signed.zip **
    This file is required to obtain ROOT AFTER you have S-Off.

    http://forum.xda-developers.com/atta...1&d=1308537076 (WINDOWS) **
    http://forum.xda-developers.com/atta...1&d=1308537076 (LINUX) **
    http://dl.dropbox.com/u/33327355/cwm-4.0.1.4-vivow.img **
    These two items are in case Revolutionary tool fails to install CWM on your phone OR if you want to do this offline at another location. Fastboot and abd tool is the software that will take the img file of CWM and flash it onto your phone after S-OFF is obtained.

    Prepping your Phone:

    Turn off FAST BOOT in the settings located: SETTINGS -> POWER

    Turn on Unknown Sources: SETTINGS -> APPLICATIONS
    Turn on USB Debugging: SETTINGS -> APPLICATIONTS -> DEVELOPMENT

    Installing Root:

    1 - First, install the HTC drivers on your computer. It is a very simple step and you should have no issues doing this at all. Also look at your installed programs list and confirm HTC Sync is not installed. This will stop your device from being detected by Revolutionary to other problems when rooting.

    2 - Extract the Fastboot and ABD zip file onto the root of your local disk drive (ex. C:\android-win-tools )

    3 - Copy/Cut and Paste the CWM img file into the Fastboot and ABD folder (ex. C:\android-win-tools\cwm-4.0.1.4-vivow.img) Doing this will prep your PC to flash CWM in the event the Revolutionary tool does not download and install it.

    4 - Place phone in "Disk Drive" mode then Copy/Cut and Paste the root su zip file (do not extract it) onto the root of your SDCard on your phone (ex. x:\su-2.3.6.3-efgh-signed.zip )

    5 - Place phone in "Charge Only" mode. A lot ot people run into issues and not realize this was not selected.

    6 - Run the Revolutionary file now that everything is set to go.

    7 - You will get a prompt to enter your beta code. This is the code you received when you downloaded the revolutionary file and entered the information to obtain the beta key.

    8 - Sit back and WAIT while the application does what is needed. This process will take anywhere from 3 to 5minutes so be PATIENT.

    9 - Upon completion, you will get a prompt to install CWM. Say yes here! Once done skip to step 10.

    9a - If the revolutionary app crashes or fails to download/install, leave your phone in the state it is (HBoot mode and should say "Fastboot USB". Open a command prompt in windows (Start - Run - type CMD).

    9b - If you did exactly as told, type "CD.." until you see "C:\"

    9c - Type the following:
    CD android-win-tools
    fastboot flash recovery cwm-4.0.1.4-vivow.img

    9d - This process takes about 30sec max. Almost done!!!

    10 - On your phone, back track to the main menu of HBoot using the volume keys and Power button and select recovery (2nd Option). In a few seconds your will be in CWM.

    11 - As long as you copied the signed zip file to the root of your sdcard, perform the following:
    "Install Zip From SDCard" (5th Option)
    "Choose Zip From SDCard" (2nd Option)
    Select the root/su zip file (su-2.3.6.3-efgh-signed.zip)
    Choose Yes and wait.
    Back track to main menu and reboot





Thursday, December 1, 2011

Compiling Pidgin 2.10.0 on Fedora 10

At work I run Fedora 10, and compiling pidgin was annoying enough for me to want to write down the options I used to finally get the configure script to be happy.

./configure --disable-vv --disable-gstreamer --disable-gtkspell --disable-meanwhile --disable-avahi --disable-nm