Wednesday, October 16, 2013

Piping stderr

To pipe stderr (instead of stdout) use `|&' instead of `|'. This works from Bash 4 onwards. It is shorthand for `2>&1 |', which redirects bytes sent to stderr (2) to stdout (1), and then pipes it (|).

[Courtesy stackoverflow.]

Saturday, October 5, 2013

Simple Java development setup

A simple setup for small Java development projects could be:
  • Create the source directory ($PROJ_HOME) which will contain all .java files.
  • Create the directory $PROJ_HOME/proj_name which will contain all the .class files.
  • Add $PROJ_HOME to the CLASSPATH.
  • During development, keep a terminal open with working directory $PROJ_HOME, and run "javac *.java -d ." to compile all source files and store the class files in proj_name.
  • Run a class from anywhere using java proj_name.ClassName [args].
In addition:
  • Store metadata files etc. required by the code in $PROJ_HOME/meta. If they need to be passed by command line arguments, you can pass $PROJ_HOME/meta/datafile.txt as an argument wherever you are running the class.
  • Store sample test data files to quickly test the code in $PROJ_HOME/test.

Saturday, September 7, 2013

Enabling Indic transliteration on web pages

Enable typing in Indian languages in web pages using Pramukh IME. This javascript library is very easy to integrate into your website, and supports 20 Indian languages.

Also, it is open source; so you can add new languages, or change the keyboard layout for existing ones.

Tuesday, August 6, 2013

Rendering math in blogs

To render LaTeX-style mathematical formulae in blogs, use MathJax, as shown here. Once set up, you can do
  • \( <math text> \) for inline math
  • \[ <math text> \] for equations

Friday, August 2, 2013

LaTeX to HTML

To generate a HTML version of a TeX document:
  • First ensure that all metadata files are up-to-date (e.g. if you have references in the tex file, run latex; bibtex; latex; latex to ensure that the .bbl file is ok).
  • Run latex2html -split +1 -show_section_numbers -no_footnode myfile.tex. This will create a directory myfile containing myfile.html (among other things).
    • -split +1 causes all subsections within a section to be in a single page (-split 0 will cause the whole document to be in a single page)
    • -no_footnode causes footnotes to be included in the same page where they are referenced.
    • See man latex2html for more options.

Wednesday, July 3, 2013

Random reordering of lines in a file

To generate a random reordering or shuffling of lines in a file, use
shuf inp.txt > out.txt

Monday, June 24, 2013

Python tips

To compile a python script without executing it, do
python -m py_compile my_script.py
[Courtesy: stackoverflow]