View text files using less, including very large files. It also opens gzip-ed files. Use less -S to truncate long lines (instead of wrapping around).
Friday, November 16, 2012
Wednesday, August 22, 2012
Information about your Linux system
Here are some commands that give information about your linux system.
To get the number of CPU's/cores in the system, use
To see if your processor supports 64-bit OS, you can Google the processor name (got using /proc/cpuinfo). To see if your OS is 64-bit, use
To see where (in which directories) a package is installed in Ubuntu, use
dpkg -L <packagename>
To get the number of CPU's/cores in the system, use
less /proc/cpuinfo
To see if your processor supports 64-bit OS, you can Google the processor name (got using /proc/cpuinfo). To see if your OS is 64-bit, use
uname -a
If it says x_86_64 somewhere in the output, then it is a 64-bit OS, else it is probably a 32-bit OS.To see where (in which directories) a package is installed in Ubuntu, use
dpkg -L <packagename>
Friday, August 3, 2012
Displaying Unicode text in the terminal / console
If gnome-terminal has problems displaying Unicode (UTF-8) characters properly, try using konsole (from KDE). It worked for me.
Thursday, July 5, 2012
LaTeX Beamer Tips
To include videos, do
\usepackage{multimedia}
\movie[externalviewer]{\includegraphics{poster.jpg}}{film.mp4}
\usepackage{multimedia}
\movie[externalviewer]{\includegraphics{poster.jpg}}{film.mp4}
Without externalviewer, the PDF viewer attempts to play the video within itself (this usually does not work).
To cover/uncover parts of slide, do
\uncover<1-4>{Show this throughout.}To cover/uncover parts of slide, do
\uncover<2-4>{Show this after the first transition.}
\only<3-4>{Show this after the second transition.}
\only<4>{Show this after the third transition.}
Roughly, \uncover puts the text on the slide before the transition but hides it. \only doesn't put the text on the slide until the specified transition. You can replace the text with image (\includegraphics), environment, etc.
To have text on the left and an explanatory image on the right, (within the frame) do
\begin{columns}
\begin{column}{0.5\textwidth}
\begin{itemize}
\item Blah
\item Blah Blah
\end{itemize}
\end{column}
\begin{column}{0.5\textwidth}
\centering \includegraphics{Blah.jpg}
\end{column}
\end{columns}
To display slide numbers in the footer, (in the preamble) do
\useoutertheme{infolines}
\setbeamertemplate{headline}{}
\setbeamertemplate{footline}{\insertframenumber/\inserttotalframenumber}
Move \insert... to headline to display in the header.
Friday, March 23, 2012
Debugging and Profiling in Python
To debug hello.py, do
You will immediately get the debug prompt, with the execution stopped before the first line of the program. You can now use:
l - to display source code around the line to be executed next
n - to execute the next line of code
s - to step into the next line of code
b <line no.> - to set breakpoints
b - to list breakpoints
clear <breakpt no.> - to clear breakpoints
c - to continue execution
tbreak <line no.> followed by c - to execute till a particular line
p <var> - to print contents of variables,
vars(obj) - to print contents of objects (same as obj.__dict__)
dir(obj) - to list attributes/methods of objects
help - to get more help.
To profile hello.py, do
$ python -m cProfile hello.py
The program will be run and you will get a profiler report on the console.
To debug a particular part of the code, do
import cProfile
profile = cProfile.Profile()
profile.enable()
profile.dump_stats('something.prof')
$ python -m pdb hello.py
You will immediately get the debug prompt, with the execution stopped before the first line of the program. You can now use:
l - to display source code around the line to be executed next
n - to execute the next line of code
s - to step into the next line of code
b <line no.> - to set breakpoints
b - to list breakpoints
clear <breakpt no.> - to clear breakpoints
c - to continue execution
tbreak <line no.> followed by c - to execute till a particular line
p <var> - to print contents of variables,
vars(obj) - to print contents of objects (same as obj.__dict__)
dir(obj) - to list attributes/methods of objects
help - to get more help.
To profile hello.py, do
$ python -m cProfile hello.py
The program will be run and you will get a profiler report on the console.
To debug a particular part of the code, do
import cProfile
profile = cProfile.Profile()
profile.enable()
# do something
profile.disable()profile.dump_stats('something.prof')
To view the dump file, use cprofilev.
Monday, March 12, 2012
Lagrangian duality
Given an minimization problem
min f(x)
s.t. g_i(x) = 0, i=1..m
h_j(x) <= 0, j=1..p,
the Lagrangian function is
L = f(x) + \sum_i \alpha_i g_i(x) + \sum_j \beta_j h_j(x)
where \alpha_i is unconstrained, and \beta_j >= 0.
See more on Wikipedia.
min f(x)
s.t. g_i(x) = 0, i=1..m
h_j(x) <= 0, j=1..p,
the Lagrangian function is
L = f(x) + \sum_i \alpha_i g_i(x) + \sum_j \beta_j h_j(x)
where \alpha_i is unconstrained, and \beta_j >= 0.
See more on Wikipedia.
Monday, February 20, 2012
Literal strings in Python
Some of the many ways one can construct strings in Python:
s = "qwe\nasd\nzxc" #gives 'qwe\nasd\nzxc'
s = 'qwe\nasd\nzxc' #gives 'qwe\nasd\nzxc'
s = 'qwe\
s = 'qwe\nasd\nzxc' #gives 'qwe\nasd\nzxc'
s = 'qwe\
\nasd\
\nzxc' #gives 'qwe\nasd\nzxc'
s = '''qwe
asd
zxc''' #gives 'qwe\nasd\nzxc'
s = '''qwe\\n
asd
zxc''' #gives 'qwe\\n\nasd\nzxc'
s = r'qwe\n\
asd\
zxc' #gives 'qwe\\n\\\nasd\\\nzxc'; => \n in the string is always accompanied by a '\'.
s = u'qwe\u0020asd' #gives a Unicode string 'qwe asd' (the Unicode code for space is 20)
s = ur'qwe\u0020asd' #gives a Unicode string 'qwe asd'
s = ur'qwe\\u0020asd' #gives a Unicode string 'qwe\\\\u0020asd' (the desired format for use in regular expressions.
s = u'qwe\u0020asd'.encode('utf-8') #gives an encoding of the Unicode string in the specified encoding ('utf-8')
s1 = unicode(s, 'utf-8') #gives a Unicode string after decoding the content of s according to specified encoding
Subscribe to:
Posts (Atom)