Fixing the ClassNotFoundException when running cassandra-cli


A problem I have seen frequently reported when trying to run cassandra-cli is the ClassNotFoundException.
The most likely cause of this exception is a problem with the cassandra_home path.

You have to make sure you have the correct path to the Cassandra root directory in your enviornment variables.
– If it doesn’t already exist, add a user/system variable called CASSANDRA_HOME.
– Set it to /your_path_to_cassandra/apache-casssandra-0.8.4 or c:\your_path_to_cassandra\apache-casssandra-0.8.4 depending on your system.

This should solve the problem

Finding out public IP from console on Linux


My site of choice to lookup my public IP is http://www.whatismyip.com. This is very easy to use from a browser but not as straight forward if you only have access to the console. The trick is to use wget and a regular expression to extrac the IP address.

The script below is taken from wolfvorkian1 at http://ubuntuforums.org/archive/index.php/t-228660.html

wget -qO - www.whatismyip.com/automation/n09230945.asp | egrep -m1 -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'

This will just display your external public IP

Deleting all folders and sub-folders with a given name with Windows Shell


This particular script came in handy when I copied a project that was under source control with SVN and wanted to “unbind” it. The easiest way to do that is to delete all the .svn folders and sub-folders inside the project’s directory.

This could be achieved by doing a search in Windows for “.svn”, selecting all the returned directories and deleting them. But if this way is not an option, here is a scrip that will do the trick:

for /f "tokens=* delims=" %%i in ('dir /s /b /a:d *svn') do (  rd /s /q "%%i")
  1. create a file with any text editor
  2. paste this script in
  3. save it with a .cmd extension (e.g. delete_svn.cmd)
  4. there are 2 ways to run the script:
    • from the Command Prompt
      • go to the top directory where you want to do the deletion (let’s call it working directory)
      • type [path_to_cmd_file]\delete_svn.cmd and then Enter
    • from the Windows Explorer
      • copy the .cmd file to the working directory
      • double-click on it

This should take care of recursively deleting all the directories called .svn

Setting color from resource on Android


It is straight forward to set a color for text or background for example with the Android SDK but there is a mistake I made several times when getting started and this is what I want to cover in this short post.

Let’s take the example of setting the background color of a View and following the best practices, we want to use a color defined in colors.xml in the values directory of res.

The signature for the method used is setBackgroundColor(int color)

The mistake I made was to call it as myView.setBackgroundColor(R.colors.my_color) which does not trigger any warnings or errors at compile time nor at runtime but will give you grey no matter what color code you defined.

When thinking about it, it makes sense because R.colors.my_color returns the id value of the resource and not the actual color defined by the resource. So what we need to write instead is:
myView.setBackgroundColor(getResources().getColor(R.colors.my_color))

Note: if you are calling this outside of an Activity class or a class extending Activity, you need to specify the context for getResources so you may end-up with something like this:
myView.setBackgroundColor(context.getResources().getColor(R.colors.my_color))

Getting “The process cannot access the file because it is being used by another process” when trying to start a website


Today when trying to start a website that was mysteriously stopped on my development machine, I got the following error message:
The process cannot access the file because it is being used by another process. (Exception from HRESULT: 0x80070020)

This is a very misleading error message and I spent some time looking at my running processes and checking with EMCO’s UnlockIT to try figuring out what was locking my files. Looking at the Events log gives a little more accurate error that looks like this:

Source: HttpEvent
Msg: Unable to bind to the underlying transport for [::]:80. The IP Listen-Only list may contain a reference to an interface which may not exist on this machine. The data field contains the error number.
--------------------------------------------------------------
Source: IIS-W3SVC
Msg: The World Wide Web Publishing Service (WWW Service) did not register the URL prefix http://*:80/ for site 1. The site has been disabled. The data field contains the error number.

The actual issue is actually about the binding of the site. It you have any other process using port 80 (or whatever port you assigned to this site), you will get that error message when trying to start it.

To solve this problem, you have 2 options:
1. Change the port number for the problematic site’s binding to any available port
2. Turn off the service using the conflicting port (you can also assign a different port to that service)

All-in-all, this is a very minor problem that can be very easily resolved but the initial error message is leading us down the wrong path.

Hope this will help someone with the same issue

Note: my environment is Windows 7 x86 and running IIS 7.5

Update: Just finally found out that what took over my port 80 was Skype. No idea why and I have no intention on finding out so from now on, Skype is off.

Disabling relay for localhost SMTP server (Sendmail) on Linux


Why would one want to do that?

Well, I am in a situation where I need to load test a server and one of the tasks accomplished by that server is to send out emails. I want the test to be as close to a production scenario without actually sending out the emails. Many options came to my mind but none of them would have provided what I was looking for:
– turning off the SMTP server: the application would have to wait for the connection to timeout which skews our tests
– using random invalid email addresses as destination: that would result in a bunch of bounce backs which is not, again, what is happening in production
etc…

The best way was to have my application point at the localhost SMTP server (Sendmail) and disable relaying to the emails never actually get sent to their destination. The description below assumes that you are using the default configuration of Sendmail which manages relaying permissions using the access file.

To accomplish what I wanted, all I had to do was edit the access file located in /etc/mail/
In that file, for each source, there are 4 possible values: OK, RELAY, REJECT and DISCARD. OK relays even if other rules are not satisfied, RELAY enables relaying for this source and REJECT rejects the emails and sends a message back. The one we are interested in is DISCARD which just silently discards the message without generating an error message. It almost turns out SMTP server into a mock server.

So, the 3 lines we had to modify were:
Connect:localhost        DISCARD
Connect:127                  DISCARD
Connect:[IPv6:::1]          DISCARD

This will cover all local requests using IPv4 and IPv6.

Final step is to restart sendmail for those changes to take effect: sudo /etc/init.d/sendmail restart

Note: you will need sudo to edit the access file.

Animation speeds in SQL Server Management Studio


Wow, I can’t believe this is not available in the options and that we have to resort to edit config files.

Anyway, big thanks to Euan for this tip :

  1. Close SQL Server Management Studio.
  2. Open this file in a text editor
    Win XP: C:\Documents and Settings\<username>\My Documents\SQL Server Management Studio\Settings\CurrentSettings\<yyyy-mm-dd>.vssettings
    Win Vista/7:
    C:\Users\<username>\Documents\SQL Server Management Studio\Settings\CurrentSettings\<yyyy-mm-dd>.vssettings
  3. Search for “AnimationSpeed” and replace the existing value (5) with your desired speed; 10 being the fastest choice, I do not know what is the lowest (1?). Save.
  4. Open SQL Server Management Studio and it should now animate at your desired speed.

A couple of notes:

  • <yyyy-mm-dd> is a time stamp because several versions of the config file are saved with different names. Obviously, you will want to edit the one with the most recent date
  • In addition to setting the animation speed, there is also a setting called Animation that can be set to false and will eliminate the animations altogether.
Follow

Get every new post delivered to your Inbox.