Friday, August 26, 2016

Listing SOLR Collections, Java

Every now and then I need to get the list of collections in a SOLR cloud instance from a Java program. The docs seemed opaque on how to do it, so:

CollectionAdminResponse response = new    CollectionAdminRequest.List().process(server);
ArrayList cols =      (ArrayList)response.getResponse().get("collections");


Monday, November 23, 2015

Changes to .gitignore - Updating the Repository

I frequently start a git project without a .gitignore or often add entries to a .gitignore later. And then I have to update the repository to remove entries that match those entries. Here's the sequence I use:


git rm -r --cached .
 and then 
git add .git commit -m "..."git push...

Wednesday, November 11, 2015

HTML Flash Messages

Occasionally, and especially during the debugging phase of a development effort, I like to be able to create a message that appears in the web page on which I'm working, one that disappears after a few seconds. A flash message.

In the past, I've accomplished this in a variety of ways, including timeouts and so on. And some frameworks (Tapestry, e.g.) provide this kind of thing from the server as a built-in mechanism. But I'm just interested in doing this from within javascript.

Anyway, I was recently fooling around with prototypes and extending the javascript String object, and it occurred to me that a String extension to flash a message would be trivial to do, epsecially with JQuery to handle the timing parts. So I wrote this:

String.prototype.flash = function(){
    $(".flash").html(this).fadeIn("fast");
    setTimeout(function(){
        $(".flash").fadeOut("slow");
    }, 3500);
}
Coupled with a
element in the HTML in which to display the message


I am able to write flash messages off typical JS Strings:

("This is COOOOOL...").flash();
Which will show that message inside the DIV, then get rid of it after 3.5 seconds. I could extend it to parameterize the time and even the fade effects. But sometimes simpler is bester.

https://gist.github.com/scarton/98aa2588f1e66e022f64

Saturday, November 7, 2015

Creating an MD5 Hash From a String in Java

Using the MessageDigest Class, here's code to create an MD5 Hash of a String:


public static String makeAuthKey(String k) {
    MessageDigest hasher = MessageDigest.getInstance("MD5");
    byte[] kbh = hasher.digest(kb);
    String bs = new BigInteger(1,kbh).toString(16);
    return bs;
}


Java/Spring Caching

File it under "another thing I need to do a lot"... Some kind of caching of java objects.

Turns out there is a neat cache library from google called Guava that's very easy to inject into Spring and easy to configure and access.

The Spring beans look like this:


<bean id="cacheBuilderSpec"
  class="com.google.common.cache.CacheBuilderSpec"
  factory-method="parse"
  c:cacheBuilderSpecification="${cacheSpecification}" />

<bean id="cacheBuilderFromSpec"
  class="com.google.common.cache.CacheBuilder"
  factory-method="from"
  c:spec-ref="cacheBuilderSpec" />

<bean id="cache"
  factory-bean="cacheBuilderFromSpec"
  factory-method="build" />



And where the injected $cacheSpecification looks like this:

cacheSpecification=expireAfterAccess=12h,maximumSize=100

Using it in my code then becomes a simple matter of injecting the 'cache' bean into whatever class I'm using and then accessing it with these kinds of code:

cache.getIfPresent(object)
cache.invalidate(object)

Saturday, March 7, 2015

Windows Explorer Opening to a Particular Folder

Dumb Windows Things annoy me, which means I'm annoyed a lot :-)

One thing is that opening Windows Explorer always opens to the user's "home" directory. As a developer, that's almost always the last place I want to be. What I really want is to have a shortcut that opens Windows Explorer on a specific folder, or on the root of my C: drive.

Turns out, this is trivially easy. Open properties on the link and add the folder to the end of the "Target":

      %windir%\explorer.exe C:

Voila...

Saturday, February 14, 2015

Laptop Sleep Versus Shutdown after a Windows Upgrade Failure

I have a Dell XPS laptop running Windows 7. Recently, MS pushed out an update which, for some reason, never really completed - I was left with a message about Windows shutting down after the upgrade was complete.  I had left the machine on to perform the upgrade overnight, so it was a surprise to see this the next morning.

Well, not figuring out anything else to do, I pushed the power off button and then again to restart the laptop. Every time I did this, I would end up at the same place - with the message that Windows would restart after is was complete. I tried to get into safe startup mode (F8), but that never worked. I was getting a little concerned and called an IT guy to help.

He suggested that when I power off the laptop, I hold the power button down and not just press it. Well, that worked fine. I should have realized it, but simply pressing the power button puts the laptop in sleep or hibernate mode and then pressing it again starts back where it was left off. I knew how this worked in normal operations, but was surprised (though shouldn't have been?) to find the same during an update. So - lesson learned...

Friday, February 6, 2015

Internet Connection Failure...

Weirdest thing happened. After starting my laptop (Dell XPS 17, Windows 7), I had no internet connectivity. The network connections were fine - I could see other machines on my domain, but no connect out to the internet. My laptop is set up with an external monitor (LG Electronics 34UM94-P 34-Inch LCD - waaay cool!), mouse and keyboard. And the keyboard and mouse are USB connected to the monitor, which in turn is connected to the XPS laptop.

Did a bunch of poking around for possibilities. In the end, what worked was shutting down the laptop, unplugging the USB and the monitor, and then restarting the laptop. It came up fine, with full network and internet access. Then plugged in the monitor - still had internet; and then the USB. Internet and network access was fine and the keyboard and mouse worked.

Don't know why, but recording this for posterity!

Monday, January 26, 2015

Installing Oracle Java in Ubuntu, Something I seem to do a lot!

I create Virtual Box Virtual Machines for just about every project, so I end up installing Java on them a lot. I like the Oracle JDK, but for licensing reasons, that install is not available as part of the "normal" apt repository.

I installed Java via a PPA (http://askubuntu.com/questions/4983/what-are-ppas-and-how-do-i-use-them) by webupd8team (http://www.webupd8.org/2012/01/install-oracle-java-jdk-7-in-ubuntu-via.html). I ran these commands to add the PPA to the apt-get repo and update that repo, install Java7, and set up the various java 7 environment variables.

add-apt-repository ppa:webupd8team/java

apt-get update
apt-get install oracle-java7-installer
apt-get install oracle-java7-set-default

This installs the java 7 version. Same commands work with 8 by changing the version number.

Saturday, January 24, 2015

Switching to an SSD

I switched over to an SSD to replace the HDDs on my Dell XPS laptop. What a speed improvement. And, this is way too easy.

I was a little nervous about going to an SSD for everything - I had read that there are limits to the number of write operations an SSD can support before failure. But a little online reading put my mind at ease - mostly the thinking that on a 3 year old laptop, the computer itself will be out of date before the SSD fails.  The laptop is an XPS 17. It has an I7 quad code CPU, 16GB of RAM, and dual 750GB HDD drives. So I went ahead.

I ordered a Samsung 850 1TB SSD from Amazon (http://www.amazon.com/gp/product/B00LF10KTE/ref=oh_aui_detailpage_o03_s00?ie=UTF8&psc=1). When it arrived, I also realized it did not come with a USB cable, so I ordered that next (http://www.amazon.com/gp/product/B00HJZJI84/ref=oh_aui_detailpage_o00_s00?ie=UTF8&psc=1).

Once I had both, I installed the Samsung migration tool that came with the SSD and ran the clone from my C: drive to the new SSD. It took about 3 hours to clone about 650GB. Word to the wise: make sure nothing else besides the migration tool is running or the clone might be incomplete.

After that was complete, I shut down the laptop, unscrewed that back panel and removed the #1 HDD. Then plugged in the SSD and screwed it in. It all fit perfectly. I booted the laptop, also no problems. And boot time was remarkably quick.

And that's it. I am thrilled with the speed.

Monday, April 21, 2014

VirtualBox Ubuntu Slow Shared Folders Under Windows

Often, especially with large file transfers, it seems that the shared folders facility in VirtualBox (running Ubuntu, but not sure that matters), running as a Windows guest, are very slow.

I added these lines

255.255.255.255        VBOXSVR #PRE
255.255.255.255        VBOXSRV #PRE


To this file:

\windows\system32\drivers\etc\lmhosts

And then restarted the VM. I saw a big improvement.

Monday, April 7, 2014

Shared Folders Issue on VirtualBox Ubuntu

I recently upgraded my VirtualBox Guest Editions to 4.3.10 and the shared mounts that I normally create stopped working. I was running this mount:

sudo mount -t vboxsf Dropbox /home/steve/Dropbox
And getting this error:

mount: wrong fs type, bad option, bad superblock on /home/steve/Dropbox,
missing codepage or helper program, or other error
In some cases useful info is found in syslog - try
dmesg | tail  ...

After some research, it turns out that after the Guest Editions upgrade, the symlink for mount.vboxsf was broken. Here's what I ran to correct it:
cd /sbin
sudo rm mount.vboxsf
sudo ln /usr/lib/x86_64-linux-gnu/VBoxGuestAdditions/mount.vboxsf mount.vboxsf
This did the trick. Thanks to this post for the tip:

http://superuser.com/questions/736024/cannot-share-host-directory-with-virtualbox-guest-mint-16-64-bit

UPDATE: this may be fixed in the next Guest Editions release:

https://www.virtualbox.org/ticket/12879

Thursday, March 20, 2014

Creating a Java, Marklogic development stack on an Ubuntu 13.10 VirtualBox VM

I wrote about building a Java-based development stack using Ubuntu on a VirtualBox VM some time back (http://www.tractare.blogspot.com/2011/10/ubuntuvirtualboxjava-team-development.html, and http://www.tractare.blogspot.com/2011/10/ubuntuvirtualboxjava-team-development_04.html). But that was a couple of years ago and the technology has changed, so this is a rewrite. Also, that version didn't include Marklogic, which is a part of the stack for this particular application. So here's the stack I'm building out and the steps I took to get there.

First off, I'm building this in Virtual Box  4.3.8, installed on a Dell XPS laptop quad-code I7, 16GB RAM and dual 750GB HDD running Windows 7. Second, some of these kits I installed using PPAs, so if you have security concerns about PPAs, you'll need to find other ways for those tools.

The development stack I'm installing is this:

  • Ubuntu 64bit 13.10 with VB Guest Editions
  • DropBox
  • Oracle Java 7
  • JEdit
  • Git 
  • Maven
  • Tomcat 7
  • Chrome Browser
  • Eclipse Kepler
  • Marklogic 7
Installation Process:
A. Create the Virtual Machine...
  1. Downloaded the Ubuntu 13.10 64bit Desktop ISO  image from http://www.ubuntu.com/download/desktop
  2. Created a new VirtualBox VM targeting a linux/Ubuntu 64 bit OS with 10GB Ram and an 80GB Drive.
  3. Started that new VM and pointed it at the ISO image to install. (and chose to install rather than to try Ubuntu).
  4. After answering all the usual questions (where am I), restarted the VM and mounted the VB Guest Additions. The ran them via the autorun. Installing Guest Editions is a critical part of making a useful VM in VirtualBox. Don't leave home without it.
  5. Shut down the VM and opened the VirtualBox Manager Settings for my new VM; Changed the following:
  6. General->Advanced:
    Shared Clipboard=bidirectional
    Drag'n'Drop=Bidirectional
  7. System->Processor:
    4 CPUs
  8. Display->Video: 128MB
  9. OK to save all that, then start the VM again.
B. General VM Stuff, and Dropbox...
  1. The default gnome desktop has a bunch of stuff I don't use (word processing and so on),  so I removed and uninstalled them using the Ubuntu Software Center.
  2. I like to be able to do things in root, so I changed the root password. Saves having to sudo all the time!
    sudo passwd root
  3. Next, opened a terminal (and pinned it to the launcher) and started in on the stack. and I switched to root user (su root).
  4. Dropbox: I run Dropbox on the Windows machine and I don't see the point of running it in the guest Ubuntu VM as well. But I like having those folders and files available. So I create a shared folder and mount that in the Ubuntu VM.

    1. in Devices->Shared Folders Settings, create a new "Machine Folder" that points at the Dropbox folder on the Host.
    2. Create a directory of the same name in Ubuntu (Dropbox, in my case).
    3. Mount that:
       sudo mount -t vboxsf Dropbox /home/cup/Dropbox
C. Java, JEdit, Git, Maven...
  1. Java: If this is a new, clean Ubuntu install then there is no pre-installed Java. If you are trying to upgrade, you should check for and remove any extant Java installation.

    I installed Java via a PPA (http://askubuntu.com/questions/4983/what-are-ppas-and-how-do-i-use-them) by webupd8team (http://www.webupd8.org/2012/01/install-oracle-java-jdk-7-in-ubuntu-via.html). I ran these commands to add the PPA to the apt-get repo and update that repo, install Java7, and set up the various java 7 environment variables.
    
    add-apt-repository ppa:webupd8team/java
    apt-get update
    apt-get install oracle-java7-installerapt-get install oracle-java7-set-default
    
    
  2. JEdit: Installed this via the software center. This installed version 5.which is good enough for my purposes. 
  3. Git: simple - sudo apt-get install git
  4. Maven -- also simple sudo apt-get install maven
  5. Tomcat7 -- Installed directly from the Ubuntu Software Center.
D. Chrome Browser...
  1. Chrome Browser: Via PPA:

    wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
    sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
    apt-get update
    apt-get install google-chrome-stable
E. Eclipse...
  1. Eclipse: A bit of a pain in the neck, I followed this guide: http://blog.thismagpie.com/2012/07/installing-eclipse-juno-42-on-lubuntu.html. Downloaded the Eclipse Linux 64 tar.gz distribution and saved that file. Then ran these commands as root:
    
    tar -zxvf eclipse-...
    sudo cp -r eclipse /opt
    cd /usr/local/bin
    cp -r /opt/eclipse/eclipse eclipse
    
    After that, I ran eclipse from the command line and then pinned it to the launcher.
  2. One issue I had with Eclipse was that the command menus didn't work. I had to edit the eclipse.desktop file in ~/.local/share/applications to get it to work by commenting out the Exec and adding this one:
    
    
    Exec=env UBUNTU_MENUPROXY= /usr/local/bin/eclipse
F. Marklogic...
  1. Downloaded Marklogic7 for 64Bit RedHat Linix and ran these commands
    apt-get install alien
    alien --to-deb --verbose MarkLogic-4.1-6.x86_64.rpm
    dpkg -i marklogic_4.1-6_amd64.deb
    /etc/init.d/MarkLogic start
    
    The one issue I had with the ML install is that the Marklogic script in /etc/init.d runs under /bin/sh and Ubuntu's default shell is bash. So I changed the first line of that script to #!/bin/bash
And that's it. I now have a reasonable development stack to create Web based Java code using Marklogic.


Thursday, February 13, 2014

Accessing a Web Server on a Virtual Box Ubuntu Guest from the Host Server

I do a lot of development of web applications in VirtualBox virtual machines running Ubuntu. Although I could (and sometimes do) set up the virtual machine to have multiple monitors, I usually don't, instead leaving one monitor for the host OS (Win7) and another for the VM.  So it's handy for me to be able to run a browser on the host OS and access a web application on the VM. In VirtualBox, I accomplish this with Port Forwarding.

Go into settings for the VM and select Network->Advanced and click Port Forwarding.

Then enter the IP address of your host machine, the port to forward, the IP address of the guest and the port the web application runs on.The example below sets up forwarding from http://localhost:8080 to a web application running on port 8080 (Tomcat in this case) on the VM:





Mint as a new VM?

UPDATE: after going through all of this, the OS locked up on me. I had to hard-stop it and then could notrestart - VirtualBox couldn't find the boot disk. So I'm going back to Ubuntu. I don't know why this happened, but I don't have time to explore it either...


I've gotten in the habit of created Ubuntu virtual machines on my laptop for various projects. I have a new one starting up and decided to create a new VM for that. I was going to install Ubuntu, but I recently heard about the Mint OS. Kind of an Ubuntu clone with a different desktop - Cinnamon instead of Unity. Since Unity isn't my favorite part of Ubuntu, I thought I'd give mint a try. So here's the blow-by-blow.

I have a Dell XPS I7 quad-core with 16Gb RAM and 2x750GB HDDs. The hardware is a beast. It's running Win7. I use Oracle VirtualBox to create the VMs.

I downloaded the 64 bit ISO of the Cinnamon version of mint from http://www.linuxmint.com/

I already have VirtualBox installed, so I started out by creating a new VM in VirtualBox. I specified a 64bit Ubuntu system with 10gb RAM and an 80GB hard drive. In settings I put the following:

  1. General->Advanced: Bidirectional Shared Clipboard and Bidirectional Drag'n'Drop
  2. System->Processor: 4 CPUs, 100% execution cap, Enable PAE/NX
  3. Display->Video: Max Video memory (128 MB), 1 monitor, Enable 3D Acceleration (more on monitors below).
  4. Network->Advanced->Port Forwarding: I add in some forwarding depending on what I'm doing so that I can run a browser on the Win7 host OS and access a web server on the Guest VM. But that can't be done until we know the IP address of the Guest. See image below.
  5. Shared Folders: I create two -- one for a directory on the Win7 HDD through which I can share files and another to the Dropbox directory on the Win7 HDD. I could install Dropbox on the VM OS, but why have those files duplicated on the host and the guest. I make these shared folders Automount and *not* readonly. See image below




Now, I'm ready to install the OS into the VM, which is easy the first time I click "Start" in the VM. I have to say, if I screw that part up, I haven't looked into how to install on a second start :-) - I just point at my downloaded ISO and go...

Unlike Ubuntu, there are no questions or anything. So I'm guessing I need to customize it after the install. First things first, reset the root password:  sudo passwd root -- That makes all the installs easier.

And I set up the mounts to Dropbox and the shared folder:

sudo mkdir /home/Dropbox
sudo chmod 777 /home/Dropbox
sudo mount -t vboxsf Dropbox /home/Dropbox
sudo mkdir /home/Sharing
sudo chmod 777 /home/Sharing
sudo mount -t vboxsf Sharing /home/Sharing

And created a shell script I can run when starting up to make those mounts (I can never remember the mount command).

More on the various tools and apps I installed later...