Skip to main content

Posts

Network Discovery in Public Networks - Windows 7

I have my office LAN configured as a Public Domain Network; Yeah I know, I should've made it Work. My bad. But the problem is the Network Discovery feature is unavailable and even if I enable this via the Network and Sharing center it doesn't get activated. So I have to manually type in the computer names, IPs. Or else I should remove/forget the network and reconfigure it as Work domain and I don't know how to do it either :-( Should Google... :-)

Convert a set of pdf file images to eps images

I needed to submit a book to Springer and they wanted figures in .eps format. I had all my figures embedded in latex so had to find a way of converting all pdf to eps. So here goes the script I found online. OK, but I had many pdf figures. So this simple command will help to iterate through all pdf images in the folder and pass it to the above script after removing the .pdf extension. ls | grep pdf | while read x; do pdf2eps 1 ${x%.*}; done

Streams and Pipelines in UNIX environments

Linux shells use three standard I/O streams, each of which is associated with a well-known file descriptor:   stdout is the standard output stream , which displays output from commands. It has file descriptor 1. stderr is the standard error stream , which displays error output from commands. It has file descriptor 2. stdin is the standard input stream , which provides input to commands. It has file descriptor 0. Redirecting output ls x* z* >stdout.txt 2>stderr.txt Standard output in the first file and the errors in the second file. Output redirection using n> usually overwrites existing files. You can control this with the noclobber option of the set builtin. ls x* z* 2>&1 >output.txt This will redirect all errors to standard output and standard output is redirected to the file. The errors will be displayed in the terminal and the output is written to a file.   ...

grep useful commands

a_file ------- boot book booze machine boots bungie bark aardvark broken$tuff robots grep "boo" a_file  boot book booze boots grep -n "boo" a_file 1:boot 2:book 3:booze 5:boots grep -vn "boo" a_file 4:machine 6:bungie 7:bark 8:aaradvark 9:robots grep -c "boo" a_file 4 grep -l "boo" * Prints out the file names grep -i "BOO" a_file ignores case grep -x "boo" a_file  exact matches echo "i want to search for this text" > search grep -f search a_file

Embedding tex in pdf figures

It's often required to include latex symbols in publication ready figures. For example Greek symbols in LaTex can be written as \alpha which appear as the actual alpha symbol when compiled. The same effect can be embedded in figures and these figures can be separately compiled for convenience. This means that you don't have to create any intermediate files (such as pstex) in your actual tex file but rather have standalone pdf figures. You need to have a few things in hand and this is done in Ubuntu (or any Linux system) 1. Dia 2. fig2pdf (sudo apt-get install fig2pdf) - this will install a whole range of other converters, fig2eps etc. 3. XFig (this will be installed from the fig2pdf command itself) 4. Latex (comes with the Ubuntu distribution) OK. In Ubuntu you can test if everything is available by typing in the commands, e.g. if you type fig2pdf it should know the command and should tell you the usage. Now we proceed to create a figure in Dia. You see that t...

Playing with prime numbers

A prime number is a number that is divisible only by itself, for example the first few prime numbers are 2,3,5,7,11,13,17,..... The straightforward way to find all prime numbers is to iterate through the numbers and see each number meets a specific criterion. The program does this by, Check if the number ends with a 2,4,5,6,8 or a 0. If this is the case it's not prime. Check if the number is divisible by 3 or 7, then it's not prime These 2 conditions alone doesn't suffice. For example take the number 1079, this is divisible by 13, so we have to check if each number can be divided by any other prime numbers which are lower than the number itself. But there's a shortcut. We don't have to check with every prime number lower than the number. Take the prime number 37. We take it's square root rounded down, which is 6. Then we check the prime numbers only upto 7 because otherwise we do unnecessary checks, e.g. we can check 2*6. 3*6, 5*6 but as soon as we go 7*6 ...

B'day paradox problem

Birthday paradox problem is to fill a room with n people and get the probability of at least 2 people having the same b'day. This is given for 25 people as 1-(364.363.362....341)/(365^24). This can be done using the following snippet in C++. http://en.wikipedia.org/wiki/Birthday_problem#Calculating_the_probability void bDayParadox() {     float result = 1.0;     int numerator = 364.0;     for (int i = 0; i < 24; i++) {         result = result * (numerator / 365.0);                numerator = numerator - 1.0;     }     std::cout << 1.0-result << std::endl; }