-
#!/bin/bash
-
for i in $(find $(pwd) -name '*.7z')
-
do
-
cd $(dirname $i)
-
7z x $i
-
done
Batch unzip 7z archives
Batch unrar archives
-
#!/bin/bash
-
for i in $(find $(pwd) -name '*.rar')
-
do
-
cd $(dirname $i)
-
unrar e $i
-
done
Batch unzip archives
-
#!/bin/bash
-
for i in $(find $(pwd) -name '*.zip')
-
do
-
cd $(dirname $i)
-
unzip $i
-
done
Convert all *.ppt files in a directory to *.pdf (or any format suported by OpenOffice to PDF)
I believe that everybody came across the need to convert some Microsoft Office document into PDF format. Under GNU/Linux this can be accomplished very simply.
If you are a student and all the courses are in PowerPoint and you want to read them as PDF under GNU/Linux using the awesome evince, then you will appreciate this tutorial. ( Question to the reader: Why does Evince look so good, while the GNU/Linux version of Acrobat Reader is so sluggish ?)
Steps to follow:
1) Install OpenOffice
2) Install Cups-PDF:
-
sudo apt-get install cups-pdf (Ubuntu)
-
sudo yum install cups-pdf (Fedora)
3) Create a PDF directory in your home directory if it doesn’t exist:
-
mkdir ~/PDF
4) For converting a single *.ppt file to *.pdf you should use:
-
soffice -norestore -nofirststartwizard -nologo -headless -pt PDF your_pdf_file.ppt
But this can be achieved easily using OpenOffice GUI.
Now I will show you how easy is to convert all the files in a directory to PDF files and then merge them in a single PDF file. You just have to go to the directory containing your files and then execute :
-
find . -type f -name "*.ppt" -exec soffice -norestore -nofirststartwizard -nologo -headless -pt PDF {} \;
Find will search in the current directory for all the files (due to “-type f”) and having the extension ppt (due to -name “*.ppt”) and convert them into PDF files.
You might also use *.doc (Microsoft Word), and i think (not tested) that also *.pptx and *.docx (Microsoft Office 2007) could be used. The output files will be stored in the ~/PDF directory.
Now the PDF merging stage. There are many tools that can do this under Linux, but I prefer pdftk which can be installed using:
-
sudo apt-get install pdftk (Ubuntu)
-
sudo yum install pdftk (Fedora)
And here is the easiest way to merge all the PDF files in a directory:
-
pdftk *.pdf output merged.pdf
where merged.pdf is the name of the merged file
).
A sample IPtables configuration script
PATH=/sbin:/usr/sbin:/bin:/usr/bin export PATH # flush all chains iptables -F # set the default policy for each of the pre-defined chains iptables -P INPUT DROP iptables -P OUTPUT DROP iptables -P FORWARD DROP #qemu, kvm iptables -A POSTROUTING -s 192.168.122.0/24 -d ! 192.168.122.0/24 -j MASQUERADE #create a new chain for reporting droped packets iptables -N LOGDROP iptables -A LOGDROP -j LOG iptables -A LOGDROP -j DROP # allow establishment of connections initialised by my outgoing packets iptables -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT #qemu, kvm iptables -A INPUT -i virbr0 -p udp -m udp --dport 53 -j ACCEPT iptables -A INPUT -i virbr0 -p tcp -m tcp --dport 53 -j ACCEPT iptables -A INPUT -i virbr0 -p udp -m udp --dport 67 -j ACCEPT iptables -A INPUT -i virbr0 -p tcp -m tcp --dport 67 -j ACCEPT iptables -A INPUT -p tcp --dport 111 -j DROP # accept anything on localhost iptables -A INPUT -i lo -j ACCEPT #!!!!#drop everything else iptables -A INPUT -j LOGDROP #qemu, kvm iptables -A FORWARD -d 192.168.122.0/24 -o virbr0 -m state --state RELATED,ESTABLISHED -j ACCEPT iptables -A FORWARD -s 192.168.122.0/24 -i virbr0 -j ACCEPT iptables -A FORWARD -i virbr0 -o virbr0 -j ACCEPT iptables -A FORWARD -o virbr0 -j REJECT --reject-with icmp-port-unreachable iptables -A FORWARD -i virbr0 -j REJECT --reject-with icmp-port-unreachable #!!!!#drop everything else iptables -A OUTPUT -p tcp -m tcp --dport 5432 -j DROP iptables -A OUTPUT -p tcp -m tcp --dport 8443 -j DROP iptables -A OUTPUT -p tcp -m tcp --dport 5432 -j DROP iptables -A OUTPUT -p tcp -m tcp --dport 8080 -j DROP iptables -A OUTPUT -p tcp -m tcp --dport 1900 -j DROP iptables -A OUTPUT -p tcp -m tcp --dport 135 -j DROP iptables -A OUTPUT -p tcp -m tcp --dport 435 -j DROP iptables -A OUTPUT -p tcp -m tcp --dport 631 -j DROP iptables -A OUTPUT -p tcp -m tcp --dport 111 -j DROP iptables -A OUTPUT -p tcp -m tcp --dport 25 -j DROP iptables -A OUTPUT -p tcp -m tcp --dport 4444 -j DROP iptables -A OUTPUT -p tcp -m tcp --dport 8099 -j DROP iptables -A OUTPUT -p tcp -m tcp --dport 6000 -j DROP iptables -A OUTPUT -p tcp -m tcp --dport 2049 -j DROP iptables -A OUTPUT -p tcp -m tcp --dport 5901 -j ACCEPT iptables -A OUTPUT -j ACCEPT #iptables -A LOGDROP -m limit --limit 1/sec -j LOG --log-prefix "iptables denied: " --log-level 7 #iptables -A LOGDROP -j DROP
Compiling Erlang – A “personal” experience
To respond to all the questions that I have received last day I will make some clarifications.
First of all, one of the jobs were I use Erlang is Distributed programming. More specifically I am building an application that changes a lot (while I am trying to develop some algorithms, and from this comes the desire to use a functional language) which needs to perform a humangous number of floating point operations (yes C is a better language, Octave is very good for doing math, and MPI is what academia uses, BUT I decided to use Erlang to do this job although I read some articles regarding some limitations of its floating point operations).
So I needed to optimize in some way the floating point precision of Erlang. To the reader it might look like this is nonsense. Why do you use Erlang ? Answer: because it is easy to learn, it is a functional language, you can think in higher order constructs (well suited when you are doing a proof of a concept), you have a concurency model at you disposal (communication is done using message passing), you think more and code less (well you encode more in your head and write less), and if someone asks you : why didn’t you use the Abstract Factory, Object pool, Singleton, Adapter, Composite, Decorator, Flyweight, Iterator, Memento patterns, I can answer with satisfaction: it is functional programming, not OOP, so these patterns are provided by the language constructs.
Therefore I looked some ways to adapt the environment in which I develop, to what I need. Furthermore, let me bring up the fact that Slackware users have to compile almost everything. The argument might be that they want to squize every bit of performance from their system.
The following question comes up: “If I compile myself the Erlang VM, will the performance of my system increase ?”. It depends. I am sure that the Erlang team does its best to provide the highest performance while maintaining the portability, by not making any assumptions about the underlying hardware. And usually, portability is more important than performance. Besides, what will you think that will happen if some software developer makes a program that has its highest performance on the Intel platform ? Do you think that AMD, and Sun will be happy ? Or vice-sersa, Sun’s Niagara vs. Intel’s processors.
This is the user’s job: to adapt what is provided to him (for free) to its needs. And so I did. So should everybody do. Do you have a server motherboard ? If yes, did you know that it has I/O processors ? Would somebody develop an “read call” version that uses specifically the instructions of the I/O processor? It seems not, the basic strategy is: “I/O in Erlang is slow”, but what can you do about it ?
So the least I could do was to compile Erlang with the Intels compiler, to tell the processor to use a more strict model when performing divisions and square roots, to speed up the floating point operations (with a trade-off towards precission) and the memory transfer.
So, if you use Erlang for I/O bound oprations for some sort (parsing XML, using it as a gateway for some sort of services) this kind of optimization does not improve the performance at all. You should look for other types of optimizations.
Regarding the tests that I performed, the comparison was made with the CC=gcc, no other arguments provided. The ./configure will uses the Makefile’s provided optimization level (-O3, -O2). Please note that it is not always wise to optimise everything, since for example unrolling loops increases the code size. So the
icc -gcc-version=420 -mssse3 -ip -par-threshold=50 -fp-model strict -prec-div -prec-sqrt -pc80 -opt-streaming-stores always -par-threshold=50 -par-runtime-control -par-schedule-static-balanced -static-libgcc -static-intel
can be interpreted as follows:
- “I will provide you” parameters that correspond to the gcc version 4 (again, please note that I do NOT give optimization directives such as -O3 or -O2, firstly because are specified in the Makefiles, and secondly because I think that the Erlang team has performed extensive profiling to see were optimization enhances performence or not).
- “If you can” please increase the precision of sqrt and div
- “Use the existing resources as well as you can” (-mssse3)
- “My threads are memory bound”, and every one of them has what to do (do not steal data from neighboring threads, just do your work !)
Last but not least “Open a Bash console …”, yes I really meant it. I do not insult anyone’s intelligence. This might be crucial detail. I remember that back some time, while I was working at a project I was setting the path to a program using Bash style, while I was working in a C shell and I didn’t know what was going on (I know the prompt is different, but somebody tried to make a joke by compiling the source code and altering the prompt). Secondly, if somebody searches Google, one might see that not setting the path, or not setting it correctly is an often mistake.
Compiling Erlang with Intel® C++ Compiler Professional Edition for Linux
First of all, a big plus to Intel for providing the compiler free on Linux, for non-comercial use. Compiling Erlang with the Intel Compiler has greatly increased the speed of the Erlang VM (in my case, with the trade-off of increasing slightly the memory requirements). You should expect something about 20% to 30% overall speedup.
But compilling it, took me some time. A succesful compilation envolves the followin steps:
- Prepare the source code, install the necessary libraries that Erlang needs to be compiled (see the previous post).
- Install Intel® C++ Compiler Professional Edition for Linux.
- Open a Bash console and go to your Erlang source directory.
- Set the paths to Intel’s compiler and libraries:
-
LD_LIBRARY_PATH=/opt/intel/Compiler/11.1/056/lib/intel64:$LD_LIBRARY_PATH
-
PATH=/opt/intel/Compiler/11.1/056/mkl/lib/em64t:/opt/intel/Compiler/11.1/056/lib/intel64:/opt/intel/Compiler/11.1/056/bin/intel64/:$PATH
-
- Run ./configure with the following options:
-
./configure CC=icc CFLAGS="-gcc-version=420 -xssse3 -mssse3 -ip -par-threshold=50 -fp-model strict -prec-div -prec-sqrt -pc80 -opt-streaming-stores always -par-threshold=50 -par-runtime-control -par-schedule-static-balanced -static-libgcc -static-intel" –enable-smp-support –enable-threads –enable-kernel-poll –enable-hipe –with-ssl
This optimizes:
-
- floating point operations they are more exact, and less fast (internal representation on 80 bit -pc80)
- memory operations
But to get this we need:
- we compile for Intel 64 bit processors
- we use the SSSE3 instructions that my processor is capable of
- we assume that threads are memory bounded so we use -opt-streaming-stores, and a static threading model
- we statically link any needed Intel libraries -static-intel
- we statically link libgcc, but I don’t think this is necessary (and increases the size of the executable)