Software packaging with NSIS
NSIS (Nullsoft Scriptable Installing System) is an open-source tool for packaging software that allows you to create a compressed installation file for your Windows application. It is an excellent alternative to commercial software like InstallShield and Advanced Installer. For a simple packaging (specifying necessary files, license.txt and uninstallation), the learning curve is very reasonable. Download it from the sourceforge website, install it and start with an example script. I modified the Modern UI 2 script in the examples folder to suit my application package.
Using TestU01 to test PRNGs
1. Download TestU01 from the developer's website: http://www.iro.umontreal.ca/~simardr/testu01/tu01.html
2. Unzip the tarball, and build the package (README is actually useful.)
./configure --prefix=${HOME}/Setup/TestU01/install-dir
make
make install
3. Add the path to libraries ${HOME}/Setup/TestU01/install-dir/lib to LD_LIBRARY_PATH
3. Test simple application: Go to examples, build birth1.c as instructed in README
4. Test an example user-defined RNG:
gcc -c my16807.c -I/home/ndtrung/Setup/TestU01-1.2.3/install-dir/include/
gcc ex3.c my16807.o -o test -ltestu01 -lmylib -I ${HOME}/Setup/TestU01/install-dir/include/ -L ${HOME}/Setup/TestU01/install-dir/lib/
./test
5. Modify my16807.c for the RNG of interest and rebuild.
6. Apply test batteries to a user-defined RNG:
// file ex8.c
#include "unif01.h"
#include "ulcg.h"
#include "ulec.h"
#include "my16807.h"
#include <stdio.h>
int main (void)
{
unif01_Gen *gen;
gen = CreateMy16807 (12345);
bbattery_SmallCrush (gen);
DeleteMy16807 (gen);
return 0;
}
Build:
gcc ex8.c my16807.o -o test -ltestu01 -lmylib -I ${HOME}/Setup/TestU01/install-dir/include/ -L ${HOME}/Setup/TestU01/install-dir/lib/
and run:
./test
How to submit dependent jobs to a scheduler (Torque) a computing cluster
Assuming that the submission of
qsub queue_first.txt
returns job_id1. The next qsub command will enqueue the second job after the first job has terminated with or without errors.
qsub -W depend=afterany:job_id1 queue_second.txt
Replace afterany with afterok for the case where the first job completed without errors.
Using ffmpeg for create movies from a series of images
Assuming you have a series of image files, image.00000000.ppm, image.00001000.ppm,
image.00002000.ppm, image.00003000.ppm, etc.
To generate a movie using ffmpeg, use the following command:
ffmpeg -i image.%05d000.ppm -sameq -r 20 movie.mpg
The format string says that after using 5 places for the number and padding zeroes to the left, put extra 000 to the file name. This is because ffmpeg can only understand the right-most digit via the %05d format.
Downgrade the PDF version to reduce the file size
gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -dCompatibilityLevel=1.5 -sOutputFile=output.pdf input.pdf
Combine PDFs into a single PDF
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=output.pdf input1.pdf input2.pdf
Extract pages from a PDF file
gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -dFirstPage=22 -dLastPage=36 -sOutputFile=outfile_p22-p36.pdf inputfile.pdf
Remove an offending ssh key from known hosts
sed -i '6d' ~/.ssh/known_hosts
where 6 is the entry returned.
On Mac OS X, an empty string ' ' should be added in front of the line number:
sed -i '' '6d' ~/.ssh/known_hosts
Extract MP3
Remember to update youtube-dl first
pip install --upgrade youtube-dl
then use
youtube-dl --extract-audio --audio-format mp3 [url]
External mount point
Use the mount command to see all the devices mounted
mount | grep "Name of the external drive"
For example, it gives /run/media/uname
gnuplot quick steps
# Set graph title
set title "Title of the graph"
# Set logarithmic scale for the y axis
set logscale y
# Put the legend at the bottom, reverse the order of sample and text, aligned to Left, length of sample = 0.2
set key bottom reverse Left samplen 0.2
# Set output context
set term postscript enhanced color font "Times-Roman,14" # set term svg
# Set output destination
set output "test.eps"
# Plot the lines
plot 'data-file1.txt' using 1:3 w lp, 'data-file2.txt' using 1:3 w lp
Remove invalid characters in a document when opened with gedit
iconv -c -f 'UTF-8' -t 'UTF-8//IGNORE' input-file | tr -d '\0' >output-file
Alternatively, open vi and substitute the invalid characters with an empty string
:%s/\%o302//g
Find a pattern (string) in all the files in the current directory
grep -rnw . -e 'CCFLAGS'
Install and setup LaTeX on Windows
- Install MikTeX from ${Setup}/ProTeX/MikTeX/Setup
- Install TeXnicCenter, specify the path to MikTex: C:\Program Files\MikTeX\miktex\bin and paths to Acrobat.exe
- Automatically close the PDF output file before re-compiling the tex file:
Go to Build -> Define Output Profiles -> Choose LaTeX=> PDF profile
Then in the Viewer tab, for View Project's Output and Forward Search, switch to DDE command:
[DocOpen("%bm.pdf")][FileOpen("%bm.pdf")]
Server: acroview; Topic: control
For Closing document before running LaTeX, use DDE command:
[DocClose("%bm.pdf")]
Server: acroview; Topic: control
If a package is missing, specify the path to packages in: ${Setup}/ProTeX/MikTeX/tm