Wednesday, March 26, 2008

Using Greasemonkey to "fix" a webpage

Do you use a webpage that doesn't quite get the job done? Is there just something missing? Greasmonkey to the rescue. Greasemonkey is an addon for Firefox that allows you to "fix/hack" web pages. You add different scripts to Greasemonkey that hack the page you are visiting. When the page loads, the Greasemonkey script that goes with that page is run. The script doesn't actually hack the web page on the server, it alters the way you see the web page on your computer. You can find Greasemonkey scripts here. These scripts do such varied things as adding a currency converter to eBay, a auto save for web text boxes, a bunch of stuff for Facebook (get rid of adds/spam all your friends/change page colors/make peoples profile pictures larger), etc. Heres a good run down of some good scripts.Lifehacker lists some good ones too. The July 2007 ABA Journal lists Greasemonkey as number 43 of 101 tips, tricks and tools to make you a more productive, less stressed-out lawyer.

For example,I do a lot of case research using Lexis. Aside from noting passages using Google Notebook, I like to download cases onto my hard drive so I can read the later and make notes on them using Acrobat Professional or Foxit. One annoyance I ran into was naming cases and articles I downloaded. Usually I am downloading tons of cases that I've found during a search. Its faster if I simply copy the title into the filename box. However, my friendly Nexis page tersely tells me "Filename should not contain spaces! Try again."

Try again? What is this, a guess the right filename contest? Now, I know what you are thinking, why can't I just delete the spaces? Well, you try doing that with 50 cases. So my solution was to create a Greasemonkey script that adds a "Strip Spaces" button to Lexis that replaces spaces with underscores.

For those interested, heres the code (this is Javascript, but see this post for a little better understanding of code generally):
// This script will add a Strip Spaces button to the Lexis download page.
//
// ==UserScript==
// @name ReplaceWUnderscore
// @namespace http://techoflaw.blogspot.com
// @description Adds a Strip Spaces button to Lexis
// @include http://w3.lexis.com/research2/delivery/*
// ==/UserScript==
//


var eltAfter, newElement;
eltAfter = document.getElementById('delDwnldName');
if (!eltAfter)
eltAfter=document.getElementsByName('fileName')[0];//for some reason the getdocument is dift that the search
if(eltAfter)
{
//add the script
scriptAfter=document.getElementsByTagName('head')[0];//document.getElementsByName("script")[0];
newScript = document.createElement('script');
newScript.setAttribute("type","text/javascript");
newScript.innerHTML="function stripspaces (){obj=document.getElementById('delDwnldName');if(!obj) obj=document.getElementsByName('fileName')[0];str= obj.value;str=str.replace(/ /g,'_');obj.value=str;};"
scriptAfter.parentNode.insertBefore(newScript, scriptAfter.nextSibling);

//add the button
newElement = document.createElement('input');
newElement.setAttribute("value","Strip Spaces");
newElement.setAttribute("class","browseButton");
newElement.setAttribute("onclick","stripspaces();");

newElement.setAttribute("type","button");
eltAfter.parentNode.insertBefore(newElement, eltAfter.nextSibling);
}

Wednesday, March 12, 2008

TimelineIt - free web app

I recently stumbled on a blog by some law students doing something similar to this blog, only Mac centric. The guys at Mac Law Students recommended a web app for creating legal time lines called TimelineIt. This topic relates to one of my earlier posts so I decided to give it a try. The app works fairly well, you can see my time line at top. The only problem that I had is that it wont do events in the minute/second/hour range. The app is better suited for multi day events. TimeLineXpress still has my vote but you may disagree. Its hard to beat free.

Monday, March 10, 2008

Hide Outlook Without Closing

Tired of Outlook taking up valuable space on your taskbar?
Minimize it to your status bar! Here's how.

  1. Right click on the Outlook logo in the status bar (all those icons over by the clock)
  2. select "Hide When Minimized"
  3. Minimize Outlook
  4. Voila! Free space
__________
Share This Post!

Thursday, March 6, 2008

Simple Remote Folder Synchronization (FolderShare)

Every once in a while you stumble upon a piece of software that, after using it for only a short time, you can't imagine ever living without again. Foldershare is one of those pieces of software for me. I initially downloaded it to be a simple backup method after reading one too many horror stories of "bricked" hard drives, and hearing one too many weird clicks coming from the dark netherregions of my own computer.

Foldershare, at it's simplest, allows you to automatically synchronize specific folders among two or more computers. This overly simple description doesn't begin to touch on ease of mind of always knowing that every change you make to every document is automatically being whisked away and stored safely on another hard drive; far away from the danger of the coffee mug sitting next to your computer just waiting for a chance to tip over and let it's half-caf goodness ooze into your keyboard, and turn your beloved laptop into an awkward paperweight.

OK, so maybe I'm a little bit more paranoid about backing things up than the average bear (I really don't think my coffee mug is out to get me... I drink tea), but my peculiarities are really not the point of this post... I promise. Below you'll see a picture of Foldershare in action... Quietly whisking away every change I make to the Commissioner v. Estate of Bosch file while at school to the safety of my desktop computer at home ("King Ebenezer" is the name of my laptop, named after a song. OFFICE, is predictably, my office computer).











But as the name (FolderSHARE) indicates, file backup is not the main or only purpose. Once this is installed on your home computer you will be able to access any file on your computer, from any computer anywhere in the world (provided that it's turned on). Also, folders can be shared with one or more friends/colleagues.

In spite of my praise for it... Foldershare does leave a bit to be desired. My wishlist includes 1) ability to exclude designated extensions; 2) unlimited libraries (current limit 10); 3) folder hierarchy maintained after delete; 4) automated maintenance of the trash folder (or sending them straight to the recycle bin); and 5) better compatibility when a file is open on both computers at the same time.

Even after I've laid out this wishlist Foldershare is something I would highly recommend to everybody, whether you're on the go alot or not.

Wednesday, March 5, 2008

Intro To Simple Code

I've debated a little about whether to publish this post. Hopefully your practice will be so busy you wont have time to look at code (or can pay someone to do it). On the other hand, it might pay to at least understand some concepts in order to benefit from the power of automation. Bill and I need to set the stage for some simple (trust us) code that will make your life easier (really - trust us). This post is only for the most daring so if you don't like it - just don't read it.

Programs

A program is made up of a collection of commands for the computer. Think of it as a script in a play, the computer simply follows the script. For example a program that draws a circle on the screen might say:


1. Get access the screen to draw on
2. Grab a red pen
3. Draw a circle with the pen
4. Quit

Functions

We might want our program to draw many red circles all over the screen. In that case, it may be simpler to combine steps 2 and 3 into what is called a function. With a function we can say:
function DrawRedCircle = 1) Grab a red pen then 2) draw a circle with the pen at a certain location. We put the steps inside the function.
Now our program might work like this:


1. get access to the screen
2. DrawRedCircle (at the top right of the screen)
3. DrawRedCircle (at the bottom left)
4. DrawRedCircle (middle)
5. Quit

Variables

Now lets say we want to write a function that averages several numbers together. Our program needs to 1) add all the numbers together and 2) divide them. Our function might look like this:


function average(numbers 50, 60,95,85)
...
SumOfTheNumbers=50+60+95+85
AverageOfTheNumbers=SumOfTheNumbers/4
...

What the expression "SumOfTheNumbers=" did is put the result of the addition away in a memory location somewhere. SumOfTheNumbers (and AverageOfTheNumbers) is called a variable. A variable is kind of like a pocket that you can put stuff in and use it later. In this case SumOfTheNumbers is storing the sum of the numbers, 290. AverageOfTheNumbers holds the average, 72.5.

Function Parameters

Sometimes a function needs to take certain inputs and do some work on them, these inputs are passed into variables called parameters. For example, our Average function could take our numbers as parameters. For example our function would look like this.


function AverageFourNumbers(FirstNumber, SecondNumber, ThirdNumber, FourthNumber)
{
SumOfTheNumbers=FirstNumberSecondNumber+ThirdNumber+FourthNumber
AverageOfTheNumbers=SumOfTheNumbers/4
}

As you can see, the function adds together the four parameters FirstNumber, SecondNumber, ThirdNumber, FourthNumber and then averages. To use our new function we code:


AverageFourNumbers(50, 60,95,85)

Function Returns

We may want our functions to spit out a value so that our program can either store it or do more processing on it. An output from a function is called a return value. For example, our average function would be far more useful if it returned an average so that we could write that to a file or something. A function that returns the average might look something like this:


function AverageFourNumbers(FirstNumber, SecondNumber, ThirdNumber, FourthNumber)
{
SumOfTheNumbers=FirstNumberSecondNumber+ThirdNumber+FourthNumber
AverageOfTheNumbers=SumOfTheNumbers/4
return AverageOfTheNumbers
}


To use this we can write:


MyGPA=AverageFourNumbers(50, 60,95,85)

Lets pretend we wrote a function that would store a GPA to a file. We'd probably want it to take the GPA and a file to save it in as parameters. Calling the function might look something like this:


StoreGPA(MyGPA, MyFile)

Objects

An object is a way to wrap related variables and functions into one package. A good example of "relatedness" is a program that models a bouncing ball. In that case, we need a number of variables to describe the ball. A bouncing ball also has a number of actions that it performs, these actions are stored in functions. When talking about objects programmers use a little different terminology. Variables that are inside the object are called properties. Functions that are inside the object are called methods.

Lets "describe" a ball object:


Ball
{
Properties=
Color
Size
BounceSpeed
Type
etc.
Methods=
DoBounce
Stop
}

We can set the properties of our ball something like:


Ball.Color = red
Ball.size =15
Ball.BounceSpeed =2

We can make the ball bounce by calling the DoBounce method (assuming we/others have done the programming for the method):


Ball.DoBounce

Repitition and Evaluation

A program repeats a process by doing what is called a loop. With loops you can tell to computer to repeat a group of commands for a certain number of times or until a condition occurs.
An example of looping 100 times:


For Number=1 to 100
...do some stuff
Next Number

An example of looping until a condition occurs:


Number=1
Do Until Number=100
Number=Number+1
...do some stuff
Loop

Both of the examples did the same thing but one used what is known as a For Loop which does an operation a set number of times. The other example used a conditional loop that stops when a condition occurs .Both types are useful in different situations.

Evaluation is accomplished with an if statement. An if statement allows you to test if a condition has occurred. For example:


if Number=100 then
DisplayMessage("Number is one hundred")
end if

The above example uses an if statement to test whether the variable Number is 100. If it is then the pretend DisplayMessage function is called.

Strings and Numbers

A computer stores to general types of information, words and numbers. Collections of words are called strings. Numbers can come in several types integers,floats and doubles for example. An integer is a whole number (no decimals) and can be positive or negative. A float can be a decimal. Strings are enclosed in quotations. For example:


MyString = "This is an example of a string"


Numbers don't need quotations. For example:


MyNumber = 1


Putting it all together


To tie this all together, lets look at the macro we recorded in this post. The code strips all the returns so that pastes from Acrobat files aren't all messed up. It looks like this:


Sub Macro1()
'
' Macro1 Macro
'
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^p"
.Replacement.Text = " "
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub

This function is in a language called Visual Basic (VB). VB is the language that the Microsoft Office applications use for their automation. Office allows you to do tons of cool stuff to save time with VB.

The code shows a function called Macro1. VB makes a distinction between functions that return a value (see the returns section above) and functions that do not. Functions that return a value are simply called a "function." Functions that do not return a value are (confusingly) called a "sub procedure." Hence, the "sub Macro1" and "end sub" in the code above.

After the function name line you see three lines that start with a single quote ('). In VB a single quote is the beginning of a comment. Anything after a single quote is not run by the computer, its not considered code. Comments allow you to "show your work" like in algebra. Basically, you can write notes about what each line is supposed to do etc. The 3 lines of comments above just give the name of the function.

Next we see that the function does alot with some "Selection" thing. Selection is an object (see the discussion of objects above). Inside the Selection object there are various properties and methods. The Macro1 function sets and runs those properties an methods to get the result we want. The first two lines of code are:


Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting

Remember placing a period after an object name is the way to access properties and methods within the object (its kind of like a door to the inside of the object). In this case, the function accesses the Find property. Actually Find is itself an object. The Selection object has a Find object inside. To get even more wild, the Find object has a Replacement object inside of it. ClearFormatting is a method. So whats going on? Well the Find and Replace objects represent the Find what and Replace with fields on the Find and Replace box (at right). Word allows you to find words or phrases with specific formatting, like bold/italic/etc. The ClearFormatting function does the equivalent of clearing that setting out on the Find and Replace box for both the Find what (our function's Find object) and the Replace with (our function's Replacement object).

The next line of code says:
With Selection.Find

A "With" block is just a shortcut so that we don't have to type the object name over and over. It simply means that all the properties and methods used following the "With" will belong to the Find object (Selection.Find).

The code that follows isn't all that important to understand specifically. It just sets up our find by setting the properties of the find object. These properties will be used when we do the search to determine how the search will be done. Four properties are important though.
.Text = "^p"
.Replacement.Text = " "
.Forward = True
.Wrap = wdFindContinue


The Text property is what we are searching for. Here, the paragraph character (^p). The Text property of the Replacement object is what we will replace the paragraph character with. Here, a space. Forward tells the search to look forward and wrap tells it to wrap the search around when it gets to the end of the document.

The last line of the function calls the Find object's Execute method with a parameter telling it to replace all occurances of the string we are looking for (^p).

__________
Share This Post!

Monday, March 3, 2008

JDSupra: Free Documents

JD Supra is a free online collection of legal documents contributed by other attorney's firms and other groups with a legal slant to them. As of now there isn't much specifically for South Dakota (surprise surprise), but there is an interesting amicus brief from the Abourezk v. ProBush.com case. It's hard to tell from my quick once-over, but this may be, for now, a better source for federal documents than for the states. There are already several thousand documents uploaded and so if you're stuck on something, keep this source in your pocket for an example. My only criticism for now is no browsing feature, it's search only.
__________
Share This Post!