Sunday, December 19, 2010

A quick update

Wow this year is passing by so fast. I still can't believe it's almost Christmas. My advisor says each year gets faster and faster. So maybe this is a sign of me getting older?

Anyway, this year is almost over. I enjoyed a lot teaching the Exploring the Internet class (http://91-113-204-f10.wiki.uml.edu) this semester. It was lots of work of course, together with the two class I was taking, and my research work. But it was fun. I learned a lot, both from my students and myself.  Earlier, I just learned that I got A in both classes. My research is going well, slowly. So I guess this year is good.

With this semester over, I'm really glad that I can finally concentrate on my research. Got a conference paper due late January. I also should finish resubmitting a journal paper asap. When I'm done with these papers, I'm going to extend the work of my first paper into another. It's gonna be a busy winter for me. The best part of it is that, if my plan goes well, I'm going to graduate in 2 years! :)

After posting scores into ISIS this weekend for the class I was teaching, this semester is officially behind! :)

Thursday, October 07, 2010

Unharness my potential

This Monday, I stayed up all night to finish a proposal draft. I did it! 30 pages in one night. Wow, I never realized I could have so much potential. Then I started to ponder over how much more work I could get done, and how to do things more efficiently. My ultimate goal is to graduate in two years.




This Ph.D comic says all. Truly we all have our ups and downs. But there's always a better way to organize time. Therefore I'm making a plan to be more efficient.

Below are the things that take up a lot of my time. I'm listing my solutions to save time.

To save time on parking

This semester parking is really a pain. To save time, I should:.

(In pseudo-Python)

#! /usr/bin/python
if (go_to_bed_last_night <= 1am):
        while (6:30am <
                get_up() 
                go_to_school()
else:
        while (7:30am < time <= 8:00am):
                get_up() 
        while (8:00am <= time < 11:30am): 
                work_at_home()
        while (11:30am <= time < 12:00pm): 
                lunch()
        go_to_school() 
while(1):
        work_hard()    

To save time on cooking
Monday -- Friday: simple lunch and dinner
Saturday -- Sunday: quality lunch, simple dinner

To save time on shopping
  1. No shopping list, no go.
  2. The frequency should be less than twice per week. Go right before supermarkets close, to get things fast.
  3. Go to Costco no more then once per week. Only visit in the weekends.
  4. Do NOT go to malls unless absolutely necessary
To save time on TA work

This is the tricky part, since I have to spend lots of time making all the slides because the old version is out of date. Besides borrowing some slides from slideshare.net and give credits, and reminding myself that enough is enough, I can't think of any to save more time.

Misc.
  • No more than one movie at home per two weeks. Try to stop watching TV. Go to cinemas no more than once per 3 months.
  • Try to stay away from Google Reader Play, Google Reader, Facebook, Renren, or any social network, unless it's work-related.
  • Check email less frequently
  • Do not chat with people in the lab, and do not get involved

Friday, September 17, 2010

Perspective

Perspective: "

Civilians Killed In Iraq and Afghanistan Compared to 9/11



For the full article, see Prose Before Hos: Perspective On 9/11 And The Invasions Of Iraq & Afghanistan.



"

The Illustrated Guide to a Ph.D.

This is so true.

The Illustrated Guide to a Ph.D.: "

Matthew Might, a computer science professor at the University of Utah, writes: “Every fall, I explain to a fresh batch of Ph.D. students what a Ph.D. is. It’s hard to describe it in words. So, I use pictures.” Here it goes. Matt’s Illustrated Guide:


Imagine a circle that contains all of human knowledge:



By the time you finish elementary school, you know a little:



By the time you finish high school, you know a bit more:



With a bachelor’s degree, you gain a specialty:



A master’s degree deepens that specialty:



Reading research papers takes you to the edge of human knowledge:



Once you’re at the boundary, you focus:



You push at the boundary for a few years:



Until one day, the boundary gives way:



And, that dent you’ve made is called a Ph.D.:



Of course, the world looks different to you now:



So, don’t forget the bigger picture:



Keep pushing.


You can find Matt’s Illustrated Guide hosted on his web site. This guide/reality check is published under a Creative Commons License. You can also buy a print version for $6.50. (The money goes to charity.) Matt offers more insights for Ph.D. students here.


The Illustrated Guide to a Ph.D. is a post from: Open Culture. Visit us at www.openculture.com

"

A Hoodie With a Hidden Vulcan Salute

Saw this on Google Reader. I'd love to get one of these!

A Hoodie With a Hidden Vulcan Salute: "

From Fashionably Geek: Holy crap that is brilliant. When zipped, it’s just a hand on a hoodie. Unzip and it’s the Vulcan salute. Lie down on your side and it’s the Vulcan shocker.


Product Page ($40)




"

Saturday, September 11, 2010

Once Again, D.C. Boasts the Country's Worst Drivers

Once Again, D.C. Boasts the Country's Worst Drivers: "

Most of the drivers around this region -- whether they're from Maryland, Virginia or the District -- just plain suck. This is not new.



But a new report released by Allstate Insurance Corporation indicates that Washington, D.C. is, in fact, the hellish nexus of American traffic. Washington -- probably because the city, aside from its own crazy drivers, attracts a nightmarish mish-mash of drivers from two other jurisdictions who also have terrible drivers -- finished dead last in the report's rankings. Some other fun facts from the report: D.C. boasts a 95.5 percent 'relative accident likelihood' against the national average and an average of 5.1 years between accidents. (In comparison, the top city on the list, Fort Collins, Colorado, has a negative-31.2 percent accident likelihood and averages 14.5 years between accidents.) Looking for sympathy? Don't look too far: Baltimore finished but one slot ahead of D.C. in 192nd place. Arlington (174th) and Alexandria (177th) didn't fare spectacularly either. Here's a PDF with the complete results.



Of course, like I said, this is just the same old, same old for those of us who live here -- after all, D.C. finished dead last in this exact same report last year. No one can ever accuse us of being inconsistently bad drivers, I guess.



Add to digg
Email this Article
Add to Facebook
Add to Google


"

Friday, May 14, 2010

How to traverse a tree in Python

I was preparing for an interview. So here's my summary of tree traverse in Python.



1. Using recursion


#! /usr/bin/python

class Node:
        def __init__(self,value,left=None,right=None):
                self.value=value;self.left=left;self.right=right

def traverse(node):
        if node==None: return
        print node.value
        traverse(node.left)
        traverse(node.right)

def main():
        n1=Node(1)
        n2=Node(2)
        n3=Node(3,n1,n2)
        n4=Node(4)
        n5=Node(5,n3,n4)
        traverse(n5)

if __name__ == "__main__":
        main()
"""
Result:

5
3
1
2
4
"""

You may ask: Can I traverse a tree w/o recursion? Surely you can! The easiest way to do so is using a stack. Python has a build-in type--list. It has append() and pop() that can be used as stack push and stack pop.

2. No recursion:

#! /usr/bin/python

def treeWalker(node):
        lifo=[]
        while True:
                print node.value
                if node.left!=None:
                        lifo.append(node)
                        node=node.left
                else:
                        try:
                                node=lifo.pop()
                        except:
                                return None
                        node=node.right

class Node:
        def __init__(self, value, left=None, right=None):
                self.value=value;self.left=left;self.right=right

if __name__ == "__main__":
        n1=Node(1)
        n2=Node(2)
        n3=Node(3,n1,n2)
        n4=Node(4)
        n5=Node(5,n3,n4)
        treeWalker(n5)

"""
Result:
5
3
1
2
4
"""

Wednesday, February 17, 2010

Java: ==, .equals(), compareTo(), and compare()

Java: ==, .equals(), compareTo(), and compare()

Equality comparison: One way for primitives, Four ways for objects

Comparison Primitives Objects
a == b, a != bEqual values Compares references, not values. The use of == with object references is generally limited to the following:
  • Comparing to see if a reference is null.
  • Comparing two enum values. This works because there is only one object for each enum constant.
  • You want to know if two references are to the same object
a.equals(b) N/A Compares values for equality. Because this method is defined in the Object class, from which all other classes are derived, it's automatically defined for every class. However, it doesn't perform an intelligent comparison for most classes unless the class overrides it. It has been defined in a meaningful way for most Java core classes. If it's not defined for a (user) class, it behaves the same as ==.

It turns out that defining equals() isn't trivial; in fact it's moderately hard to get it right, especially in the case of subclasses. The best treatment of the issues is in Horstmann's Core Java Vol 1. [TODO: Add explanation and example]

a.compareTo(b)N/A Comparable interface. Compares values and returns an int which tells if the values compare less than, equal, or greater than. If your class objects have a natural order, implement the Comparable interface and define this method. All Java classes that have a natural ordering implement this (String, Double, BigInteger, ...).
compare(a, b)N/A Comparator interface. Compares values of two objects. This is implemented as part of the Comparator interface, and the typical use is to define one or more small utility classes that implement this, to pass to methods such as sort() or for use by sorting data structures such as TreeMap and TreeSet. You might want to create a Comparator object for the following.
  • Multiple comparisions. To provide several different ways to sort somthing. For example, you might want to sort a Person class by name, ID, age, height, ... You would define a Comparator for each of these to pass to the sort() method.
  • System class. To provide comparison methods for classes that you have no control over. For example, you could define a Comparator for Strings that compared them by length.
  • Strategy pattern. To implement a Strategey pattern, which is a situation where you want to represent an algorithm as an object that you can pass as a parameter, save in a data structure, etc.

If your class objects have one natural sorting order, you may not need this.

Comparing Object references with the == and != Operators

The two operators that can be used with object references are comparing for equality (==) and inequality (!=). These operators compare two values to see if they refer to the same object. Although this comparison is very fast, it is often not what you want.

Usually you want to know if the objects have the same value, and not whether two objects are a reference to the same object. For example,

if (name == "Mickey Mouse")   // Legal, but ALMOST SURELY WRONG

This is true only if name is a reference to the same object that "Mickey Mouse" refers to. This will be false if the String in name was read from input or computed (by putting strings together or taking the substring), even though name really does have exactly those characters in it.

Many classes (eg, String) define the equals() method to compare the values of objects.

Comparing Object values with the equals() Method

Use the equals() method to compare object values. The equals() method returns a boolean value. The previous example can be fixed by writing:

if (name.equals("Mickey Mouse"))  // Compares values, not refererences.

Because the equals() method makes a == test first, it can be fairly fast when the objects are identical. It only compares the values if the two references are not identical.

Other comparisons - Comparable interface

The equals method and == and != operators test for equality/inequality, but do not provide a way to test for relative values. Some classes (eg, String and other classes with a natural ordering) implement the Comparable interface, which defines a compareTo method. You will want to implement Comparable in your class if you want to use it with Collections.sort() or Arrays.sort() methods.

Defining a Comparator object

As described in the table above on compare(), you can create Comparators to sort any arbitrary way for any class. For example, the String class defines the CASE_INSENSITIVE_ORDER comparator.

If you override equals, you should also override hashCode()

Overriding hashCode(). The hashCode() method of a class is used for hashing in library data structures such as HashSet and HashMap. If you override equals(), you should override hashCode() or your class will not work correctly in these (and some other) data structures.

Shouldn't .equals and .compareTo produce same result?

The general advice is that if a.equals(b) is true, then a.compareTo(b) == 0 should also be true. Curiously, BigDecimal violates this. Look at the Java API documentation for an explanation of the difference. This seems wrong, although their implementation has some plausibiliby.

Other comparison methods

String has the specialized equalsIgnoreCase() and compareToIgnoreCase(). String also supplies the constant String.CASE_INSENSITIVE_ORDER Comparator.

The === operator (Doesn't exist - yet?)

Comparing objects is somewhat awkward, so a === operator has been proposed. One proposal is that
a === b would be the same as ((a == b) || ((a != null) && a.equals(b)))

Common Errors

Using == instead of equals() with Objects
When you want to compare objects, you need to know whether you should use == to see if they are the same object, or equals() to see if they may be a different object, but have the same value. This kind of error can be very hard to find.

Tuesday, February 16, 2010

25+ Alternative & Open Source Database Engines

25+ Alternative & Open Source Database Engines: "

Almost every web developer has a favorite database that he/she feels comfortable working with as all the tricks & gimmicks are already experienced.


It can be one of the popular databases below:



or even simpler ones like XML, text, etc.


It is understandable why these databases are frequently used; they are well-documented, have a community behind them, integrated with most popular CMSs', easy-to-use, offered by most of the hosting companies ,etc..


But there are also many other databases which are getting popular day-by-day & may have advantages over what you're already using.


Here are 25+ open source alternative databases that you may consider using in your next project:


MongoDB


MongoDB


It is an open source, high-performance, scalable, schema-free & document-oriented (JSON-like data schemas) database.


There are ready to use drivers for most popular programming languages like PHP,Python, Perl, Ruby, JavaScript, C++ + more.


Hypertable


Hypertable


Hypertable is a high performance distributed data storage system designed to support applications requiring maximum performance, scalability, and reliability.


It is modeled after Google's BigTable and mostly focuses on large-scale datasets.


Apache CouchDB


Apache CouchDB


A document-oriented database that can be queried and indexed in a MapReduce fashion using JavaScript.


CouchDB offers a RESTful JSON API which can be accessed from any environment allowing HTTP requests



Neo4j


Neo4j Graph Database


It is an embedded, disk-based, and fully transactional Java persistence engine that stores data structured in graphs rather than tables.


Neo4j offer a massive scalability. It can handle graphs of several billion nodes/relationships/properties on a single machine and can be scaled across multiple machines.


Riak


Riak


Riak is a very ideal database for web applications as it combines:



  • a decentralized key-value store

  • a flexible map/reduce engine

  • a friendly HTTP/JSON query interface.


Oracle Berkeley DB


Oracle Berkeley DB


It is an embeddable database engine that provides developers with fast, reliable, local persistence with zero administration.


Oracle Berkeley DB is a library that links directly into your application & enables you to make simple function calls rather than sending messages to a remote server for a better performance.


Apache Cassandra


Apache Cassandra


Cassandra is a highly scalable second-generation distributed database that is used by giants like Facebook, Digg, Twitter, Cisco & more..


It aims to provide a consistent, fault-tolerant & highly available environment for storing data.


Memcached


Memcached


Memcached is an in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering.


It is intended for use in speeding up dynamic web applications by alleviating database load.


Firebird


Firebird


Firebird is a relational database that can run on Linux, Windows & various UNIX platforms.


It offers high performance and powerful language support for stored procedures and triggers.


Redis


Redis


Redis is an advanced fast key-value database written in C which can be used like memcached, in front of a traditional database, or on its own.


It has support for many programming languages & used by popular projects like GitHub or Engine Yard.


There is also a PHP client named Rediska for managing Redis databases.


HBase


Hadoop HBase


HBase is a distributed & column-oriented store which can also be called as the Hadoop database.


The project aims to host very large tables like "billions of rows, millions of columns".


It has a REST-ful web service gateway that supports XML, Protobuf, and binary data encoding options.


Keyspace


Keyspace


It is a consistently replicated, fault-tolerant key-value store that works in Windows OS.


Keyspace offers high availability by masking server/network failures & appearing as a single, highly available service.


4store


4store


4store is a database storage and query engine that holds RDF data.


It is written in ANSI C99, designed to run on UNIX-like systems & offers a high performance, scalable & stable platform.


MariaDB


MariaDB


MariaDB is a backward compatible, drop-in replacement branch of the MySQL® Database Server.


It includes all major open source storage engines + the Maria storage engine.


Drizzle


Drizzle


It is a fork of MySQL that focuses on being a reliable database optimized for Cloud and Net applications.


HyperSQL


HyperSQL


It is a SQL relational database engine written in Java.


HyperSQL offers a small & fast database engine which has in-memory and disk-based tables, supports embedded/server modes.


Also, it has tools such as a command line SQL tool & GUI query apps.


MonetDB


MonetDB


MonetDB is a database system for high-performance applications in data mining, OLAP, GIS, XML Query, text & multimedia retrieval.


Others



Special Downloads:

Ajaxed Add-To-Basket Scenarios With jQuery And PHP

Free Admin Template For Web Applications

jQuery Dynamic Drag’n Drop

ScheduledTweets


Advertisements:

SSLmatic – Cheap SSL Certificates (from $19.99/year)

Follow WebResourcesDepot At Twitter And Get More Resources!



Tags: , ,


Related posts






"