Linux
Realtime collaborative text editing
by Mostafa on Nov.21, 2008, under Linux, Software
A while ago, I came across Etherpad. It a web based platform that allows multiple users to simultaneously edit a single text file. Since it doesn’t seem to support any kind of mark-up at the moment, it would seem that it’s not terribly useful for word processing tasks. Perhaps it’s good for real-time collaborative coding and the creation of agenda type lists …
The software equivalent of Etherpad is Gobby. It’s a multi-platform tool that claims to run on Microsoft Windows, Mac OS X, Linux and other Unix-like platforms — making it almost as flexible as a web-based service. There are a number of other advantages:
- Flexibility and security that comes from having absolute control over the sessions.
- Syntax highlighting!
Bash process substitution
by Mostafa on Oct.03, 2008, under Linux, Software
From the Advanced Bash-Scripting Guide:
“Piping the stdout of a command into the stdin of another is a powerful technique. But, what if you need to pipe the stdout of multiple commands? This is where process substitution comes in.
Process substitution feeds the output of a process (or processes) into the stdin of another process.”
The syntax is:
>(cmd_list) <(cmd_list)
Example: comparing the head of two files using diff
$ diff -u <(head -n3 /var/log/dmesg) <(head -n3 /tmp/dmesg) --- /proc/self/fd/63 2009-05-26 19:52:45.144544140 +0100 +++ /proc/self/fd/62 2009-05-26 19:52:45.149544007 +0100 @@ -1,3 +1,3 @@ -Initializing cgroup subsys cpuset -Initializing cgroup subsys cpu -Linux version 2.6.27.21-170.2.56.fc10.i686 (mockbuild@xenbuilder2.fedora.redhat.com) (gcc version 4.3.2 20081105 (Red Hat 4.3.2-7) (GCC) ) #1 SMP Mon Mar 23 23:37:54 EDT 2009 +Linux version 2.6.22.9-61.fc6 (brewbuilder@hs20-bc2-4.build.redhat.com) (gcc version 4.1.2 20070626 (Red Hat 4.1.2-13)) #1 SMP Thu Sep 27 18:48:03 EDT 2007 +BIOS-provided physical RAM map: + BIOS-e820: 0000000000000000 - 000000000009f000 (usable)
The diff header clearly shows that file descriptors are used as the underlying mechanism.
Embedding fonts in a PDF document
by Mostafa on Oct.03, 2008, under How To ..., LaTeX, Linux, Software
It is often a good idea (or a requirement) to embed the used font faces in a PDF document. This is easily accomplished using ps2pdf during the final stage of conversion of a document from PS to PDF:
$ ps2pdf -sPAPERSIZE=a4 -dPDFSETTINGS=/printer -dCompatibilityLevel=1.3 \ -dMaxSubsetPct=100 -dSubsetFonts=true -dEmbedAllFonts=true \ 'input_file.ps' 'output_file.pdf'
An explanation of the command options can be found in the Ps2pdf.htm file in the Ghostscript documentations (or here).
[Source]
Re-encoding MP3 files using LAME
by Mostafa on Jun.06, 2008, under How To ..., Linux, Software
I have some MP3 files encoded at a constant bitrate of 320kbps that my phone seems to have trouble playing smoothly. So, I looked into LAME.
The files I had were named using the following scheme:
01 - Title of track 01.mp3 02 - Title of track 02.mp3 ...
I used the BASH for-loop construct to process the files:
$ for A in *.mp3;\ # Process one mp3 at a time do B=${A%.mp3};\ # Extract track number and title C=${B#?? -};\ # Extract the title D=${B%% - *};\ # Extract the track number lame --vbr-new -V0 -q0\ # Variable-bitrate, high-quality --mp3input\ # Inputs are MP3 files --tt "$C"\ # ID3v2 tags: title --ta 'Artist Name'\ # ID3v2 tags: artist --tl 'Album Title'\ # ID3v2 tags: album --ty 2007\ # ID3v2 tags: year --tn "$D"\ # ID3v2 tags: track no. --tg 'GENRE'\ # ID3v2 tags: genre "$A" processed/"$A";\ # Keep filename and save in ./processed/ done
Since no bit-rate bounds are explicitly provided, the re-encoded files can contain anything between 32kbps and 320kbps. The LAME man-page provides an extensive list of options and their meanings.
Processing files using ‘find’
by Mostafa on Mar.26, 2008, under How To ..., Linux, Software
In its most basic form, find is often used to locate files that are subsequently piped through a complex set of commands for processing. However, this particular method is easily broken by files that contain spaces in their names.
This is where the ‘exec’ option provided by find comes in handy. From the man-page:
-exec command ; Execute command; true if 0 status is returned. All following arguments to find are taken to be arguments to the command until an argument consisting of ‘;’ is encountered. The string ‘{}’ is replaced by the current file name being processed everywhere it occurs in the arguments to the command, not just in arguments where it is alone, as in some versions of find. Both of these constructions might need to be escaped (with a ‘\’) or quoted to protect them from expansion by the shell. See the EXAMPLES sec- tion for examples of the use of the ‘-exec’ option. The speci- fied command is run once for each matched file. The command is executed in the starting directory. There are unavoidable security problems surrounding use of the -exec option; you should use the -execdir option instead.
An example that recursively touches all *.log files from the current directory would be:
$ find . -name \*.log -exec touch {} \;
Saving power with Linux
by Mostafa on Dec.03, 2007, under Linux
An interesting site with numerous tips and tricks on power efficient computing using Linux:
It is also home to the rather useful “PowerTOP” tool. If the testimonials are anything to go by, everyone running a recent release of Linux should give this a try.
Extracting Audio/Video
by Mostafa on Dec.01, 2007, under How To ..., Linux, Software
It’s really easy to extract either audio or video from a multimedia file using ‘ffmpeg‘. To extract audio only:
$ ffmpeg -i inputfile -vn -acodec copy outputfile
And for video only, replace ‘-vn‘ with ‘-an‘ and ‘-acodec‘ with ‘-vcodec‘.
ffmpeg is also commonly used as a transcoding tool.
SSH Blacklisting
by Mostafa on Nov.29, 2007, under How To ..., Linux, Software
After getting around 1500 failed ssh login attempts a day for a while on a server I manage, I decided to look into tools that automatically blacklist offending IPs.
Sshblack fits the bill perfectly. A HOWTO (including an init-script) for REDHAT-like systems is available from the OSS Watch Wiki.
User installation of additional TeX/LaTeX classes and styles
by Mostafa on Aug.09, 2007, under How To ..., LaTeX, Linux
When you are the sysadmin, you can simply drop the new class/style files under the system TeX path (e.g. /usr/share/texmf/tex/) and run ‘texhash’ to have them automatically picked up. But what do you do when you are just a regular user?
TeX/LaTeX looks at the TEXINPUTS environment variable to look for additional locations to search for included/referenced files. Therefore, new classes/styles can be easily added as follows:
- Create a directory for the files:
$ mkdir -p $HOME/tex/latex
- Place the new class files into that folder (each class can be in its own directory and contain subdirectories):
$ cp -a fancy-class $HOME/tex/latex/
- Export the TEXINPUTS variable and also add it to your $HOME/.bash_profile:
$ export TEXINPUTS=.:$HOME/tex/latex//:$TEXINPUTS
The ‘.’ ensures that the working directory is included in the search path. The double-‘//’ tells bash to also include files in subdirectories of ‘$HOME/tex’ recursively.
New BibTeX files can also be added locally in a similar fashion. The variables to set are then BSTINPUTS and BIBINPUTS.
The environment variable to set for MakeIndex styles is: INDEXSTYLE.
Source: AstroNat – Installation at The Smithsonian/NASA Astrophysics Data System
UPDATE [16 July 2009] The Kpathsea manual provides a wealth of information about usable environment variables.
Network Security
by Mostafa on Aug.09, 2007, under How To ..., Linux, Software
A list of very interesting articles:
http://backtrack.offensive-security.com/index.php?title=ExternalHowto