Thursday, December 1, 2011

Linux and Java: Disk usage, Memory check, JVM virtual memory, Processor Info, Kernel Info

Check disk usage:
df -h

Check file size in a directory
du -sh *


Check memory usage, display total memory in MB:
free -t -m


Set JVM virtual memory:
java -jar -Xms128m -Xmx512m bigapp.jar

Processor Info:
cat /proc/cpuinfo

Kernel version:
uname -r

Sunday, October 23, 2011

Acrobat: The crop page pop-up menu in Acrobat X tools

In the latest version of Acrobat professional readers,
Clicking on Tools > Pages > Crop only shows manual rectangle crop selection. 
There is no pop-up menu showing me options such as "removed white margins" etc as in older versions.


The way to crop pages is to  make a rectangle with the crop tool, 
then double-click there is an check-box to remove white margins, similar to older versions.


ScreenSnapz.png





Wednesday, October 19, 2011

Latex: how to number your equation at any line


1. Number each line


\begin{align}
\label{equ:example}
D_{o_1o_2}&(t) =  ((v_{x_1}-v_{x_2})^2+(v_{y_1}-v_{y_2})^2) \cdot t^2
\\  & + \left( (x_1-x_2)(v_{x_1}-v_{x_2})+(y_1-y_2)(v_{y_1}-v_{y_2}) \right )\cdot 2t
\\  & +(x_1-x_2)^2+(y_1-y_2)^2
\end{align}


2. Number one line

\begin{align}
\label{equ:example}
\notag D_{o_1o_2}&(t) =  ((v_{x_1}-v_{x_2})^2+(v_{y_1}-v_{y_2})^2) \cdot t^2
\notag \\  & + \left( (x_1-x_2)(v_{x_1}-v_{x_2})+(y_1-y_2)(v_{y_1}-v_{y_2}) \right )\cdot 2t
\notag \\  & +(x_1-x_2)^2+(y_1-y_2)^2
\end{align}

3. No numbering

\begin{align*}
\label{equ:example}
 D_{o_1o_2}&(t) =  ((v_{x_1}-v_{x_2})^2+(v_{y_1}-v_{y_2})^2) \cdot t^2 
\\  & + \left( (x_1-x_2)(v_{x_1}-v_{x_2})+(y_1-y_2)(v_{y_1}-v_{y_2}) \right )\cdot 2t 
\\  & +(x_1-x_2)^2+(y_1-y_2)^2
\end{align*}

Wednesday, October 12, 2011

In-memory index structures

Points
K-d tree (Point K-d tree)


Recursive subdivision of point-set into two halves using
vertical/horizontal line.
Horizontal line on even levels, vertical on odd levels
One point in each leaf
    Alternating splits on dimensions.
    Cost in two dimensions: O(√N + T) query time, O(N) storage
    Cost in higher dimensions: O(N^(1-1/d) + T) time complexity for d > 2
      Range tree
        Nested binary search trees
        Cost in two dimensions: O((logN)^2 + T) query time, O(NlogN) storage, Fractional cascading reduces query complexity to O(log N + T).
          Quadtree
            Division into 4 subspaces
            Point and region versions
            Range query complexity similar to K-d tree

            Can be used for compressing/clustering
            information (Point versus region quadtree)



            Intervals

            Used for stabbing queries on 1-d intervals
            – Root defined by median end-point
            – Left child stores all intervals that end before the median
            – Right child stores all intervals that begin after the median
            – The root stores all intervals that intersect the median; order by left end-points and by right end-points in separate lists


            Used together with Range Tree for window query:
            O(N log N) storage, O(N log N) construction time, O((logN)^2 + T) query time



            Voronoi Diagram for NN Search

            O(N) space, O(N log N) construction time, O(logN) query time


            kth order Voronoi diagram defines the partitioning based on k-closest sites. For 2 dimensions, O(k(N-k)) space, O(k2N log k + kN log N) construction time, O(k + logN) query time.

            A number of approximate algorithms.

            References:

            Computational geometry, algorithms and applications, de Berg et al, Springer.


            Wednesday, September 14, 2011

            Josm editor User Manual PDF

            I want to use Josm editor for a project. But it seems there is no pdf version of the entire user manual. So I create this pdf file and share online. It can be downloaded here

            Wednesday, September 7, 2011

            How To Install Python + Django + Aptana Studio on Windows 7

            In this article, I will explain how to get Python, Django, and Aptana Studio running smoothly on windows.

            1. Install Python


            •  Go to http://www.python.org/download/ and download the Python. I am currently using the 2.7 version. Note that the latest version may not work with Windows yet.
            •  Execute and install what you’ve just downloaded with the default options
            • open command window and type 'python' to test if it is successfully installed. If command not recognized, follow these steps to add the path in Windows 7. Start -> Control Panel -> System and Security->Systems-> Advanced system settings->Environment Variables-> System Variables -> PATH->modify PATH by appending ;C:\Python27;C:\Python27\Scripts”. Also make sure you have a semicolon (;) before what you write.
            2. Installing Django
            • Go to http://www.djangoproject.com/download/ and download the version that best suits you. Version 1.3 works fine for me.
            • Extract the files to a folder. WinZip will do the job. Please REMEMBER THE FOLDER WHERE YOU EXTRACTED DJANGO.
            • Open a command prompt (Start > Run > Type in “cmd” and press OK). In the black window that is going to show up, type in cd “[directory_of_django]“. For example: cd "C:\www\python\Django-1.3″. 
            • setup.py install
            3. Installing aptana studio
            Aptana studio is a version of eclipse that already comes with HTML and CSS editors, and installing PyDev in it is really easy.
            • Go to http://www.aptana.org/studio/download and download the standalone full installer version.
            • go to Window > Preferences > PyDev > Interpreter – Python and click “Auto-Config”
            • Click OK on everything else
            4. Installing MySQL for Python
            If you are going to use django with MySQL, you will probably need to perform those steps:
            • Go to http://www.codegood.com/downloads and download
            • MySQL-python-1.2.2.win32-py2.6.exe, if you have a 32 bit OS or MySQL-python-1.2.2.win-amd64-py2.6.exe, if you have a 64 bit OS. In doubt, download the first one.
            • Install it.
            Have fun!

            Tuesday, September 6, 2011

            Django Csrf verification failed


            The first problem is met when I am connecting Django with MySql.
            Installing MySqldb (or MySql-python) from the site:

            The second problem is Forbidden (403) CSRF verification failed. Request aborted.
            Assuming everything else is fine.
            The solution is to add into "settings.py=>MIDDLEWARE_CLASSES"
            the line
            'django.middleware.csrf.CsrfResponseMiddleware',



            How to use CSRF

            To enable CSRF protection for your views, follow these steps:
            1. Add the middleware 'django.middleware.csrf.CsrfViewMiddleware' to your list of middleware classes,MIDDLEWARE_CLASSES. (It should come and before any view middleware that assume that CSRF attacks have been dealt with.)
              Alternatively, you can use the decorator csrf_protect() on particular views you want to protect (see below).
            2. In any template that uses a POST form, use the csrf_token tag inside the
              element if the form is for an internal URL, e.g.:
              {% csrf_token %}
              This should not be done for POST forms that target external URLs, since that would cause the CSRF token to be leaked, leading to a vulnerability.
            3. In the corresponding view functions, ensure that the 'django.core.context_processors.csrf' context processor is being used. Usually, this can be done in one of two ways:
              1. Use RequestContext, which always uses 'django.core.context_processors.csrf' (no matter what your TEMPLATE_CONTEXT_PROCESSORS setting). If you are using generic views or contrib apps, you are covered already, since these apps use RequestContext throughout.
              2. Manually import and use the processor to generate the CSRF token and add it to the template context. e.g.:
                from django.core.context_processors import csrf from django.shortcuts import render_to_response  def my_view(request):     c = {}     c.update(csrf(request))     # ... view code here     return render_to_response("a_template.html", c) 
                You may want to write your own render_to_response() wrapper that takes care of this step for you.
            The utility script extras/csrf_migration_helper.py can help to automate the finding of code and templates that may need these steps. It contains full help on how to use it.

            Thursday, August 25, 2011

            latex argmax and argmin

            Latex does not have built-in support for argmax and argmin.
            The following are two tricks that works for me.

            \underset{x}{\operatorname{argmax}}{content}
            \underset{x}{\operatorname{argmax}}{content}

            Cheers!

            Convert ArrayList to Array in Java. ArrayList to Array. Java Collection

            A lot of time I have to convert ArrayList to Arrays in my Java program. Although this is a simple task, many people don’t know how to do this and end up in iterating the java.util.ArrayList to convert it into arrays. I saw such code in one of my friends work and I thought to share this so that people don’t end up writing easy thing in complicated way.


            ArrayList class has a method called toArray() that we are using in our example to convert it into Arrays.


            Following is simple code snippet that converts an array list of countries into string array.

            List list = new ArrayList;
            
            list.add("India");
            list.add("Switzerland");
            list.add("Italy");
            list.add("France");
            String [] countries = list.toArray(new String[0]);


            So to convert ArrayList of any class into array use following code. Convert T into the class whose arrays you want to create.

            List list = new ArrayList;
            
            T [] countries = list.toArray(new T[list.size()]);

            Convert Array to ArrayList


            We just saw how to convert ArrayList in Java to Arrays. But how to do the reverse? Well, following is the small code snippet that converts an Array to ArrayList:

            
            
            String[] countries = {"India", "Switzerland", "Italy", "France"};
            List list = new ArrayList(Arrays.asList(countries));
            System.out.println("ArrayList of Countries:" + list);

            Converting UTM coordinates into latitude and longitude coordinates

            The coordinates used in the raw GPS data are sometimes in the UTM (Universal
            Transverse Mercator coordinate system) format.
            There is a need to convert them into into latitude and longitude coordinates for reverse-geocoding with Google Map API.

            There may be many ways of doing the conversion. The following are two ways:
            1. The method introduced by Salkosuo (java lib)http://www.ibm.com/developerworks/java/library/j-coordconvert/
            2. Postgis extension provides in-database conversion function.

            Kill Processes From The Command Prompt In Windows 7


            A few processes start with Windows implicitly by default.
            One way to remove these processes is to use msconfig in run.
            Then tick off any program that should not start up with Windows.

            But some processes do stay even the first way is applied. Use these commands to kill them. (Caution: do know what you are doing before doing it)

            In CMD window:
            1. Enter command 'tasklist'
            2. To kill a process with a name. E.g. To kill firefox, enter the command 'Taskkill /IM firefox.exe /F', /F means by force.
            3. To kill a process with PID, enter 'Taskkill /PID 364 /F'

            Tuesday, August 16, 2011

            How to remove ^M from file using VI

            Sometimes DOS files have "^M" at the end of each line, which causes problem for perl to read lines correctly.
            We can use VI to remove these annoying ^M.

            =============Using VI================

            Type the following command at the terminal.

            vi file_name.txt


            Basically vi is the name of a text editor under linux/mac.
            After issuing this command, you should be able to see the command window showing the content of the file.

            Next step is to remove the annoying ^M at the end of each line.
            Type the following command in VI editor. Do not miss the semi-colon at the begining.

            :%s/[ctrlkey+v and ctrl-key+M]/\r/g

            You should be able to see the following at the left-bottom corner of the command window:
            :%s/^V^M/\r/g

            The command above is meant to replace ^M with a new line symbol "\n".

            Press enter and wait for a while for every occurrence of ^M to be replaced.
            Depending on the size of your file, it can take a while and the screen appears frozen.
            When the replacing is done, type the following command to save and exit from VI.

            :x

            Good luck!

            Thursday, August 4, 2011

            Database conferences

            ConferenceConf. Dates
            Paper DeadlineNotificationLocation
            SIGMOD 201220/05-25/05
            01/11/201114/02/2012Scottsdale, Arizona, USA
            VLDB 201227/08-31/08
            1st day per monthMay 19, 2012
            Istanbul, Turkey
            ICDE 2012@Arlington, USApril 01-05, 2012
            July 19, 2012Sep 27, 2012ICDE 2012
            EDBT 2012@Berlin21/03-25/03
            Oct 6 2011-EDBT 2012
            MDM 2012@London06/06-09/09
            --London
            SSTD 2011@MinneapolisAug 24-26, 2011
            25/02/2011Apr 29, 2011-
            DASFAA 201202-05/04/2012
            30/09/2011Pusan /South Korea
            DEXA 2011 @ Toulouse, France29/08-02/09/2011
            --DEXA 2011
            SSDBM @ Portland, OregonJul 20-22, 2011
            JanuaryMar 28, 2011
            ICDM @ Vancouver, CanadaDec 11-14, 2011
            Jun 17, 2011Sep 16, 2011-

            How to Be a Successful PhD Student (zz)

            Getting a Ph.D. can be a very rewarding experience both personally and professionally. Being a successful Ph.D. graduate student, however, can be more complicated than some expect. Being a Ph.D. student means finding balance in several areas of life, working hard, making connections with others and cultivating certain personality traits necessary to succeed in your program of choice.


            Instructions

              • 1

                Build a relationship with a good supervisor, mentor or adviser early. You should preferably choose someone who is well-supported with grants or has tenure in order to eventually make use of the resources he has. Consult with your supervisor for professional guidance and advice. Don't be afraid to switch supervisors if you find that you have trouble working with the one you have.

              • 2

                Prepare to work very hard for long periods of time. Most Ph.D. students seldom stop working, even through weekends. Getting a Ph.D. is not supposed to be easy; find a routine and a schedule that works for you as early as you can.

              • 3

                Take care of yourself. Due to the heavy workload of the basic Ph.D. program, it is easy to let your health and well-being take a backseat to other priorities. Try to take some weekends or holidays off. Despite the heavy course load, you will need to learn when you need a short break in order to avoid burning out. Exercise when you can. Always eat right, even during late-night study sessions.

              • 4

                Connect with other graduate students. The best people to get to know during your Ph.D. are people who know exactly what you are going through because they are going through it at the same time. Arrange for study dates, coffee breaks or days out.

              • 5

                Begin cultivating an expertise in your field early. Start by reading all of the literature you can in your field of specialization. It is difficult to add anything to the field you study if you don't know what is already out there. Also, try going to conferences in your field to find out what questions or research currently predominate the field.

              • 6

                Research, write and publish. Getting a Ph.D. usually means that you have committed yourself to a research-based, academically focused career path. This means that you too must research, explore, pose questions, find answers and share them with the rest of your colleagues. Start by narrowing down your field of interest and doing some extensive research in that area. Hire a librarian to help you find all the materials you need. Enlist your supervisor to help you formulate ideas and get your writing ready for scholarly journal publication.

              • 7

                Find ways to motivate yourself when you are feeling burnt out or are pulling an all-nighter; using a rewards system or reminding yourself of your professional goals are two such ways to do so.

              • 8

                Be prepared to compete with your friends on a certain level. Your superiors will naturally compare you to them; try not to let this fact interfere with your personal life.



            Read more: How to Be a Successful PhD Student | eHow.com http://www.ehow.com/how_7827462_successful-phd-student.html#ixzz1U4OUY9HL