Wednesday, January 28, 2009
Tuesday, January 27, 2009
Useful Python Libraries for Science and Engineering
Following are some Python libraries I used to build data analysis software for a recent research/engineering project:
I also came across Python(x,y), which hosts a single prepackaged distribution containing all these packages and more, including Eclipse configured with PyDev.
I also came across Python(x,y), which hosts a single prepackaged distribution containing all these packages and more, including Eclipse configured with PyDev.
Labels:
Python Libraries
Thursday, January 22, 2009
Configure Windows XP to Render Fonts Better
While configuring a new computer today I needed to enable ClearType fonts on Windows XP. Believe me, this makes
fonts on large LCD screens much sharper and smoother. Here's how:
Start --> Control Panel --> Display --> Appearance tab --> Effects. --> Use the following method to smooth edges of screen fonts check box --> ClearTypeor
Right click on Desktop --> Properties --> Appearance tab --> Effects. --> Use the following method to smooth edges of screen fonts check box --> ClearTypeSee HOW TO: Use ClearType to Enhance Screen Fonts in Windows XP for more details.
Monday, January 19, 2009
Upgrade Java to 1.5 (at least), Please
I can't believe software is still being created using Java 1.3 (or older) and deployed on systems running Java
1.3. If at all possible, it's time to move forward people. At least upgrade to Java 1.5 (marketing: Java 5)
as this is a huge leap forward over 1.3 and is supported by most tools and environments I come across. I wish
everyone was using Java 1.6, but that might be asking too much.
Following are some reasons to upgrade to Java 1.5:
Following are some reasons to upgrade to Java 1.5:
- The latest JVMs perform much more efficiently.
- Assert facility -- allows programmers to make statements about what they believe their program is doing and quickly uncovers misconceptions.
- Generics -- allows much enhanced type safety (at compile time, as opposed to runtime), and eliminates casting.
- Enhanced for loops -- eliminates error prone indexing of for loops and loops that are easier to understand.
- Auto boxing and unboxing -- eliminates manual conversion between primitives and class types and results in cleaner and easier to read code.
- Type safe enumerations -- much cleaner, easier to use, and safer than current techniques of using a combination of constant ints, strings, and arrays.
- Regular expressions -- very, very useful for parsing and validating strings.
- Static import -- less typing and cleaner code
- Chained exceptions -- better error reporting and reduced chances of losing exception information.
- Logging API -- very useful for server applications.
-
Larger API to work with including:
- JDBC (database connectivity) updates.
- New classes for threading (concurrency).
- New IO classes.
- New classes for converting between strings and various types.
- New XML processing classes, including XPath (very useful).
- New security classes.
- New Java 2D drawing and image IO framework.
- New printing API.
- Lots of changes to Swing/AWT.
- New collection classes and interfaces.
Thursday, January 15, 2009
Obscuring URLs
I stumbled upon an old article today entitled How to Obscure Any URL: How Spammers And Scammers Hide and
Confuse.
Quoting from its summary, the article describes three ways to obscure URLs:
- Meaningless or deceptive text can be added after "http://" and before an "@" symbol.
- The domain name can be expressed as an IP address, in dotted-decimal, dword, octal or hexadecimal format.
- Characters in the URL can be expressed as hexadecimal (base 16) numbers
- Use indices or hashes for object references. For example, www.mywebsite.com/myapp?objectref=1.
- Use a hash function (say MD5 or SHA-1) to hash the URL and use the result as a key to the real URL. For example, www.mywebsite.com/this/is/a/private/path might become www.mywebsite.com/f061a171dfc30635462850684f98b886. This is similar to what URL shortening services such as TinyUrl do.
- How to Obscure Any URL: How Spammers And Scammers Hide and Confuse, www.pc-help.org, 2002
Tuesday, January 13, 2009
Movies Watched in 2008
In this post I will list some movies I watched in 2008. The list is not complete because I didn't start
recording what I watched until late in the year.
My rating scheme consists of 0 to 4 stars with the following meanings:
Now for the list. These are grouped by rating:
****
4 Months, 3 Weeks and 2 Days (2008)
Battlestar Galactica (Seasons 1-3)
Black Snake Moan (2007)
Blade Runner (1982)
Children Of Men (2007)
Dark Night (2008)
Edge of Heaven, The (2008)
Gone Baby Gone (2007)
Juno (2008)
Little Children (2006)
No Country for Old Men (2007)
Pans Labrinth (2007)
Pulp Fiction (1994)
Savages, The (2007)
***
3:10 to Yuma (2007)
Atonement (2007)
Before the Devil Knows You're Dead (2007)
Brave One, The (2007)
Burn After Reader (2008)
Charlie Wilson's War (2007)
Eastern Promises (2007)
Forgetting Sarah Marshall (2008)
Hard Candy (2006)
Iron Man (2008)
Let There be Blood (2008)
Religulous (2008)
Rock n Rolla (2008)
Sweeney Todd (2007)
Traitor (2008)
Wall-E (2008)
**
Bank Job, The (2008)
Beowulf (2007)
Cloverfield (2008)
Hancock (2008)
Hell Boy II (2008)
Incredible Hulk, The (2008)
I am Legend (2007)
In the Valley of Elah (2007)
Michael Clayton (2008)
Rendition (2007)
Tropic Thunder (2008)
W (2008)
Wanted (2008)
X-Files: I Want to Believe (2008)
Zodiac (2007)
*
Gabriel (2007)
Rambo (2008)
Star Wars: The Clone Wars (2008)
My rating scheme consists of 0 to 4 stars with the following meanings:
- _ = No stars -- Don't watch, garbage; not even worth a star
- * = Watchable -- If you have nothing else to watch, this may suffice, but could be boring
- ** = OK -- Fun, somewhat interesting, but otherwise an average movie; forgettable
- *** = Liked it -- Moving, exiting, interesting, or fun; may leave an impression on me and I may ponder it later
- **** = Loved it -- Left a lasting impression on me, and I generally reflect on it later; deeply moving, very exiting, or very interesting; generally has very good acting, good plot, good character development (the complete package); could easily watch multiple times
Now for the list. These are grouped by rating:
****
4 Months, 3 Weeks and 2 Days (2008)
Battlestar Galactica (Seasons 1-3)
Black Snake Moan (2007)
Blade Runner (1982)
Children Of Men (2007)
Dark Night (2008)
Edge of Heaven, The (2008)
Gone Baby Gone (2007)
Juno (2008)
Little Children (2006)
No Country for Old Men (2007)
Pans Labrinth (2007)
Pulp Fiction (1994)
Savages, The (2007)
***
3:10 to Yuma (2007)
Atonement (2007)
Before the Devil Knows You're Dead (2007)
Brave One, The (2007)
Burn After Reader (2008)
Charlie Wilson's War (2007)
Eastern Promises (2007)
Forgetting Sarah Marshall (2008)
Hard Candy (2006)
Iron Man (2008)
Let There be Blood (2008)
Religulous (2008)
Rock n Rolla (2008)
Sweeney Todd (2007)
Traitor (2008)
Wall-E (2008)
**
Bank Job, The (2008)
Beowulf (2007)
Cloverfield (2008)
Hancock (2008)
Hell Boy II (2008)
Incredible Hulk, The (2008)
I am Legend (2007)
In the Valley of Elah (2007)
Michael Clayton (2008)
Rendition (2007)
Tropic Thunder (2008)
W (2008)
Wanted (2008)
X-Files: I Want to Believe (2008)
Zodiac (2007)
*
Gabriel (2007)
Rambo (2008)
Star Wars: The Clone Wars (2008)
Tuesday, January 6, 2009
Adding an index to your document in Latex
Source code required:
- Include the package
makeidx
, e.g.\usepackage{makeidx}
. - Call
\makeindex
in your preamble. - Add index to keywords where desired, e.g.
\index{keyword}
,\index{keyword!subkeyword}
, -
\index{keyword!subkeyword!subsubkeyword}
. - Call
\printindex
where your want the index to be generated (usually at the end of the document).
Compiling:
- Run latex on your main latex file, e.g.
latex main.tex
. This will create amain.idx
file. - Run
makeindex
on the index file, e.g.makeindex main.idx
, to generate the index filemain.ind
. - Run latex again on your main file, e.g.
latex main.tex
.
or
- Run
texify
on your main latex file (e.g.texify main.tex
) to automatically do all the necessary steps outlined above (and more if necessary).
Example:
\documentclass{book}
\usepackage{index}
\makeindex
\begin{document}
This is some very important text about
Latex \index{latex}. Here is some more.
\printindex
\end{document}
References
- Leslie Lamport, MakeIndex: An Index Processor For Latex, 1987.
Thursday, January 1, 2009
The Danger of Static Variables in Multithreaded Environments: An Example
I fixed a very subtle bug the other day that illustrates the dangers of using static variables in multithreaded environments, such as multi-user web applications. I had implemented a Singleton class in a non-multithreaded desktop application many months ago that contained a static map (actually Java's HashMap) of database (DB) connections. The map was used to cache opened connections to different DBs so they could be reused by different parts of the application. When some part of the application needed a connection, my singleton was used to get one such that if an opened connection already existed it was returned; otherwise a new connection was opened, added to the map, and returned (a trivial connection pool if you will).
A little while ago I needed to update this class for use in a multithreaded server for a web application. So, I replaced the singleton with a class that could be instantiated by each user (i.e. thread) using the default constructor. When doing the changes, I missed removing the static storage class from the declaration of the map instance and ended up with a class something like this (only shows what is necessary):
class MyConnectionManager { private static final Map<String,Connection> _map = new HashMap<String,Connection>(); public Connection getConnection(String db) { if (!_map.containsKey(db)) _map.put(db, makeNewConnection(db)); return _map.get(db); } .... }Even though I did have unique instances of the manager class for each user/thread, all instances used the same Map. There are at least two threading issues here. The first is that two or more different users could use the same connection. Even if the Connection class is thread safe, we still have a problem if thread A closes the connection while thread B is using it. The second issue is that HashMap is not thread safe. One fix to all thread safety issues in this case is simply to remove the static storage class from the declaration of the Map instance.
Labels:
Concurrency,
Java
Subscribe to:
Posts (Atom)