Posts

Showing posts from November, 2005

Lucene Search Engine

This is fantastic, Lucene is a awsome project and now they will have Lucene4c

Path to Relationship Destruction

These are the most dangerous in a relationship that will ultimately destroy it.
Contempt, Stonewalling, Defensiveness, Critisism

Don't let them ruin your life

The Power of Profitable Thinking

The man onstage tells the folks with their eyes shut to think "bad thoughts" as their arms are pressed down by their partners. The arms go down easily. Then the man tells them to repeat the process, this time thinking positive thoughts. No arms go down, even though some of the people pushing down have gotten on their toes to get more leverage. "Thoughts radiate physically," the man says. "Change your thoughts and you change your actions, your results, your destiny. I'm here to help you think about what you think about and to help you manage your thoughts. I'm Jim Fannin. I coach champions."

self-discipline, concentration, optimism, relaxation, and en- joyment

http://www.fortune.com/fortune/smallbusiness/managing/articles/0,15114,1110596-1,00.html

BlueBalls everywhere - this is amazing

Image
Check out the original because it's animated and a thousand times cooler.

This image is from http://blueballfixed.ytmnd.com/

Vim vi how to reload a file your editing

5.8. How do I reload/re-edit the current file?

You can use the ":edit" command, without specifying a file name, to reload
the current file. If you have made modifications to the file, you can use
":edit!" to force the reload of the current file (you will lose your
modifications).

For more information, read

:help :edit
:help :edit!
:help 'confirm'

from - http://vimdoc.sourceforge.net/cgi-bin/vimfaq2html3.pl#5.8

ActionScript casting objects

Here is the example supplied by Macromedia

function bark(myAnimal:Animal) {
var foo:Dog = Dog(myAnimal);
foo.bark();
}

var curAnimal:Animal = new Dog();
bark(curAnimal); // will work
curAnimal = new Cat();
bark(curAnimal); // won't work


import Dog;
function bark(myAnimal:Animal) {
var foo:Dog = Dog(myAnimal);
if (foo) {
foo.bark();
}
}

ActionScript casting a string

If you do a string comparision that fails when by all indications that it should pass, you should do the following

var String tmpvar = someFunction();
if(tmpvar == "equivalentvalue"){
trace("true");
} else {
trace("false");
}

OUTPUT is:false
Instead Cast the return value to a String

var String tmpvar = new String(someFunction());
if(tmpvar == "equivalentvalue"){
trace("true");
} else {
trace("false");
}

OUTPUT is:true

var myArray:Array = new Array();
var someString:String = "asdf";
myArray[0] = someString;
.
.
.
var testVar:Object = myArray[0];
if (testVar instanceof String || typeof(testVar) == "string")
{
var typedVar:String = String(testVar);
// do something with typedVar
}

python shutdown hook method UPDATE

I think using atexit module -
http://docs.python.org/lib/module-atexit.html is cleaner

--
Lawrence - http://www.oluyede.org/blog
"Anyone can freely use whatever he wants but the light at the end
of the tunnel for most of his problems is Python"

5. Duncan Booth
Nov 16, 3:48 am show options
Newsgroups: comp.lang.python
From: Duncan Booth - Find messages by this author
Date: 16 Nov 2005 08:48:15 GMT
Local: Wed, Nov 16 2005 3:48 am
Subject: Re: Shutdown hook


Lawrence Oluyede wrote:

Correct, although this won't catch all cases where a program is exiting.
For example, on Windows, if you use Ctrl+C to terminate a program the
atexit function *is* called, but if you use Ctrl+Break the atexit function
is not called unless you install a suitable signal handler:

import signal
def sigbreak(signum, frame):
sys.exit("***break")

signal.signal(signal.SIGBREAK, sigbreak)

Even then there are still other ways to terminate a process which will not

Python Shutdown hook comp.lang.python

My comp.lang.python post.....

Does any one know if python has the ability to run a shutdown hook.

For example you set a method to run when the python process is shutting
down, like it recieved a kill signal?

Basically looking for an effect like the following java code.
Runtime.getRuntime().addShutdownHook(new Thread(this));

Reply

2. Ben Finney
Nov 15, 5:55 pm show options
Newsgroups: comp.lang.python
From: Ben Finney - Find messages by this author
Date: Wed, 16 Nov 2005 09:55:17 +1100 (EST)
Local: Tues, Nov 15 2005 5:55 pm
Subject: Re: Shutdown hook

Steve wrote:
> Does any one know if python has the ability to run a shutdown hook.

When the Python runtime system wants to exit, it raises a SystemExit
exception.

Catch that exception at the top level of your code, and do whatever
you like. (It might be polite to actually exit at some point, of
course. sys.exit(exitcode) will do so -- raising another SystemExit
exception.)

--
\ "I took it easy today. I just pretty much layed around in my |

Razr Phone just like a Razor

Image
I love my Razr V3 phone. I only care about 3 features on my phone - Signal, Battery Life and that it has a address book.

This phone was rumored to have great Signal Strength and Battery Life and it's all true.

I have had the phone for 3 months and wanted to inform the world.

http://direct.motorola.com/ENS/web_producthome.asp?Country=USA&language=ENS&productid=29302

Off and Away LA , Las Vegas and beyond

Soon I am off to LA again and then to Las Vegas for Laurie's birthday, I can't wait, maybe we will even have dinner saterday at the stratosphere

;)

python how to add item to a dictionary

python how to add item to a dictionary
Here is an example:

mydictionary = {}
mydictionary["new key"] = "new value"
mydictionary[1] = "monday"
mydictionary[(3,"wed")] = ["pick up billy","go to market","date with laurie"]

python how to access global variable from method / function

>>> v = 1
>>> global v
>>> print v
1
>>> def i():
... global v
... v = v + 1
... print v

http://www.python.org/doc/2.0.1/ref/global.html

python how to i++

Python doesn't have i++

you can do:

i += 1


i++ in c/java returns it's value
while i += 1 does not return a value it just increments

python switch case statement

Python doesn't have switch case statements.

But I found code that will simulate a switch case statement

result = {
'a': lambda x: x * 5,
'b': lambda x: x + 7,
'c': lambda x: x - 2
}[value](x)

to catch an error if no key found

try:
{'option1': function1,
'option2': function2,
'option3': function3,
'option4': function4}[value]()
except KeyError:
# default action

I would probably use

switch = {'option1': function1,
'option2': function2,
'option3': function3,
'option4': function4}
if value in switch:
switch[value]()
else:
pass
#default

How to yank (aka copy) 3 letters in Vi or Vim

How to yank (aka copy to the clipboard) 3 letters in Vi or Vim
Example: yank 3 characters.
3yl

Which is 3y(the letter L)l

Test if variable exists in python

Here is how to test if a variable exists

try: x
except NameError:
# x doesn't exist, do something
else:
# x exists, do something else

Most affordable college towns

Most affordable college towns

http://money.cnn.com/2005/11/02/real_estate/college_towns/index.htm

http://www.ttu.edu/administration/enrmgt/emplan/ch1abc.php

How to remove a file in python

How to remove a file in python

Here is an example

import os
os.remove("/tmp/workingfile.txt")

Firefox Extension Competition / Contest

Firefox Extension Competition / Contest

Today it was just announced that there would be a Firefox 1.5 Extension Contest. Which are going to give away Alienware computers and O'Reilly Books. I saw the annoucement on slashdot.org.

Press Release
Contest Page

How to make a Python Comment

The csharp, pound, number sign
aka -> #

# is the python comment character
example:

def helloworld():
print "Hello World\n" # this print the standard Hello World

helloworld()

How to get UTC time in python

It's this easy to get UTC time

import math
import time
int(math.floor(time.time()))

Python IDE written in python

Should be exciting I will be trying WingWare's Python IDE for he first time. http://wingware.com/. I have high expectations for it hope I am not disappointed but heard that it has hi cpu utilization.

Mount Baldy

All Saints Day,
Happy Birthday Laurie!!!!

Today we woke up at robert's house in west hollywood after a fun night at the LA holloween street fair. I worked all day and Laurie studied. We took a break and drove up to Mount Baldy which was nice and very cute. Surprisingly very little to do. Next stop, Laurie is doing more studying and I am doing more programming for work. Later Laurie, Laurie's friends and I will be going to the rain forest cafe for dinner.

How to copy a file in Java

Java doesn't provide a copy method for files but it can be done.

A good way to do it is to use the
org.apache.commons.io.FileUtils.copyFileToDirectory(File source, File destinationDirectory)'

http://jakarta.apache.org/commons/io/

but here is a simple example using streams

void copy(File src, File dst) throws IOException {
InputStream in = new FileInputStream(src);
OutputStream out = new FileOutputStream(dst);

// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
}

As long as the files are on the same volume, you just need to use the java.io.File.renameTo() method. Using this call for files and directories works equally well, but due to some platform-specific runtime implementation differences, this is one of those things that falls into the write once, test multiple places, and tweak until done catago…