Tag Archives: howto

Black pointer: Never lose track of your mouse pointer again

I’ve tried several ways to keep track of my mouse pointer.  It’s kind of hard from time to time.  Adding more than one monitor does not help at all!

Recently a colleague gave me the tip to make the mouse pointer black… and larger. I tried this and found that the mouse pointer was much easier to spot.  No surprise there, really.  After all, white on white tends to become a bit hard to keep track of, tiny silhouette outline or not.

I was told how to do this in Windows (Control Panel > Mouse > Pointer, but that’s another story).

In Gnome (I’m running Ubuntu 8.10) you do it in the System > Preferences > Appearance dialog (see below).  In my version of Window’s there’s no settings under Appearance > Mouse.

Appearance Preferences

Next you click the “Customize” button:

Customize Theme

In the new dialog select the “Pointer”-tab and select the color of pointer you want.  In order to resize it, see the “size slider” below the list of pointers (there seems to be three distinct sizes to choose from).

Click “Close” once you’re done, and voila, you have a new and much easier to spot mouse pointer!

Search and Replace in MySQL

I’ve come across a problem in one of my projects at work. It consists of searching and replacing data in a MySQL server. The data to be replaced is an old URL used in lots of text fields all over the place, it is the customers own site URL but since they moved, they now want all URLs to point to their new location.

Searching the web and checking up the MySQL function database returns the following useful command:

REPLACE(str, from_str, to_str)

It would in my case be used like this:

UPDATE myTable SET theTextField =
REPLACE(theTextField, 'http://the.old.site', 'http://the.new.site');

myTable is the table containing the data I want to replace, theTextField is the exact field in which this data is located. Obviously “http://the.old.site” is the existing information, that I want to replace, and “http://the.new.site” is the information this string should be replaced with.

Very simple, very elegant (well… if you forget about the site URL in the database in the first place…) Now all I have to do is try it out as well. (Expect more reports on the progress of this work!)

Hacking Windows Remote Connection (MSTSC.EXE)

WARNING: The below tip will kick out one of the already logged in users. This behavior may have been added after I came up with this advice, or I’ve always been the evil person on the block 😀

Ever been turned down by a Windows machine over Remote Desktop because it already had too many connections?

Even though there are no way to connect using the standard remote desktop program you can still “hack” a connection. Sure the limitation exists, probably to sell more licenses or to protect the host server from getting too many connections, but to get past it you do the following:

mstsc /v:myhost.com /F /console

Where myhost.com is the name or ipnumber of the server you are trying to remote to. /F means a full screen connection, /console means to connect to the “console session of the server” (whatever that means, it anyhow results in you getting in although the server would otherwise refuse you).

The full format of the MSTSC command call are:

MSTSC [<Connection File>] [/v:<server[:port]>] [/console] [/f[ullscreen]]
[/w:<width> /h:<height>]

<Connection File> refers to an rdp file to be used with the connection (good if you need to make local drivers or other resources available or set up the connection otherwise).

You can also call MSTSC with the “/edit” switch if you wish to edit a connection file:

MSTSC /edit <Connection File>

Finally you may also migrate files by using the “/migrate” switch (not 100% sure how this is done though since I don’t have an older version file to test with).

Badblocks

It took me some time to find out the equivalent of Window’s checkdisk/scandisk/chkdisk on Linux, but trust me, there are several.

For starters I am going to take a look at badblocks, a command that as the name implies, looks for bad blocks.

The basic format of badblocks are:

badblocks [options] device

If you have a fresh drive with no data or data that can be deleted on it you can do:

badblocks -s -w /dev/sdb

Note however, the -w command will erase all existing data on the drive so do not use it for drives with existing file systems on them. You cannot use -w on a mounted drive, unmount it first. The -s flag makes the command show a progress bar. This could come in handy when you are testing larger drives since even the fastest systems will take at least an hour to test an average sized drive (my 400GB took about 2 hours on a SATAII system).

If you want to test the drive without deleting data you can use the -n switch which will use non-destructive write-read mode, however, this switch can, for obvious reasons, not be combined with the -w switch.

badblocks -s -n /dev/sdb

Links:

How to add a body on load function with Javascript

This is an article on how to add a javascript function that will be run when a web page has loaded. We begin by defining a function for running after a page (or actually window) has been loaded:

function bodyOnLoad() {
  ..
  ..
}

And then we’ll do:

window.onload = bodyOnLoad;

However, we also want to make sure our setting of the load event doesn’t remove some other setting. This is done by also keeping any older events.

We store the previous on load event by doing;

var prevOnLoad = window.onload;

And we redefine our bodyOnLoad function:

function bodyOnLoad() {
  prevOnLoad();
  ..
  ..
}

However, we can make the creation of the function and the setting of the event a little bit more effective by doing:

window.onload = function() {
  prevOnLoad();

  ..
  ..
}

You still need to get prevOnLoad before you do that

This becomes even more obvious once we create a function for adding new load events:

function addLoadEvent(func) {
  var prevOnLoad = window.onload;
  window.onload = function() {
    prevOnLoad();
    func();
  }
}

In this way, we can concentrate on creating the new load event outside of the function for adding it to the window.onload.

function myEvent(){
  ..
  ..
}
addLoadEvent(myEvent);

We might even do:

addLoadEvent(
  function (){
    ..
    ..
  }
);

Notice the difference between curly braces “{}” and parenthesis “()”

Finally, we have to make sure there is a load event set for the window before calling it from the new event, so we need to check for this:

function addLoadEvent(func) {
  var prevOnLoad = window.onload;
  if (typeof prevOnLoad != 'function') {
    window.onload = func;
  }
  else {
    window.onload = function() {
      prevOnLoad();
      func();
    }
  }
}