TinyApps.Org
Small is beautiful


 HOME

  0. Internet
  1. Text
  2. Graphics
  3. System
  4. File
  5. Misc
  6. Palm
  7. OS X

 BLOG

 DOCS

 FAQ

 RSS (?)




Batch crop images with GIMP and ImageMagick #
  1. Backup your images!
  2. With GIMP's Rectangle Select tool, highlight area to crop and note values for Position and Size:

    Position: 940, 645 | Size: 93, 30
  3. $ mogrify -crop 93x30+940+645 *.png

/nix | Feb 21, 2010

Delete multiple pages in a DjVu document with djvm #
djvm (a command line tool bundled with DjVuLibre), does not accept multiple pages or page ranges for the delete argument. Here are a few workarounds for deleting all pages in a range, even pages, or odd pages:
  • Delete pages 1-42
    for i in $(jot 42 1) ; do djvm -d file.djvu 1 ; done
  • Delete pages 441-449
    count=441 ; until [ $count -gt 449 ] ; do djvm -d file.djvu 441 ; count=`expr $count + 1` ; done
  • Delete even pages 204 to 2
    for (( COUNTER=204; COUNTER>=2; COUNTER-=2 )) ; do djvm -d file.djvu $COUNTER ; done
  • Delete odd pages 329 to 105
    for (( COUNTER=329; COUNTER>=105; COUNTER-=2 )) ; do djvm -d file.djvu $COUNTER ; done
Many thanks to DutchDaemon and s0xxx for their answers in this thread, and to SilentGhost for this answer on Stack Overflow.

/nix | Feb 15, 2010

Linux Mint 8 (Helena) - Add Firefox shortcut / launcher to Desktop #
This should really be simpler...
  1. Right click on Desktop and select "Create Launcher"
  2. Click the springboard icon at top left
  3. Enter the following path: /usr/share/pixmaps and then double click the Firefox icon
  4. Enter the values below:
    • Type: Application
    • Name: Firefox
    • Command: firefox %u
    • Comment: blank
  5. Click OK

/nix | Feb 06, 2010

HTML Tidy: Batch processing files #
HTML Tidy does not natively support wildcards in filenames (e.g., *.html), but batch processing in bash is possible with a simple for loop:
  for f in *.html;do tidy -m -i $f;done
-m = modify original input files
-i = indent element content

(For a complete list of arguments, see the man page.)

/nix | Jan 24, 2010

Detect the character encoding of a file #
The aforementioned Perl module Unicode::Japanese includes ujguess, which attempts to detect the character encoding of a given file. The Unix program file is often suggested on forums and the like for this purpose, but it only returns the file type, not the encoding. Here's an illustration of the difference, using a Shift JIS-encoded file:
$ file foo
foo: UTF-8 Unicode text, with no line terminators

$ ujguess foo
sjis
and an EUC-encoded one:
$ file bar
bar: ISO-8859 text, with CRLF line terminators

$ ujguess bar
euc

/nix | Jan 03, 2010

Convert numbers and spaces from full-width (double-byte) to half-width (single-byte) #

Within filenames (using Bash, Perl, and Unicode-Japanese-0.47):
  1. $sudo perl -MCPAN -e shell
  2. cpan> install Unicode::Japanese
  3. Save the following script (adapted largely from togdon's example) as full2half.sh and make it executable (chmod u+x):
    #!/bin/bash
    for file in *;do
    newfile=$(echo $file | perl -MUnicode::Japanese -e'print Unicode::Japanese->new(<>)->z2h->get;')
    test "$file" != "$newfile" && mv "$file" "$newfile"
    done
  4. cd to desired directory and run script:
    $ /path/to/full2half.sh
    Convert full-width numbers and spaces to half-width
Within file contents (using OpenOffice.org):
  1. Tools > Options... (in OS X it's OpenOffice.org > Preferences...)
  2. Language Settings > Languages > check "Enabled for Asian languages" > OK
  3. Highlight text > Format > Change Case > Full-width or Half-width

/nix | Jan 02, 2010

Batch replace text in PDF files #
Simple text replacements in simple PDF documents can be made with changepagestring.pl, part of CAM-PDF-1.52, which, by the way, includes many other cool tools like:
$ perl -MCPAN -e shell
If this is the first time you've run CPAN, it will ask you a series of questions - the default answers worked fine for me. When the cpan> prompt appears, install the CAM::PDF module:
cpan> install CAM::PDF
Now let's see if our PDF allows modification:
$ pdfinfo.pl pcasm-book.pdf 
File:         pcasm-book.pdf
File Size:    1071411 bytes
Pages:        195
Author:       Paul A. Carter
CreationDate: D:20050320210800
Creator:      LaTeX with hyperref package
Keywords:     80x86 assembly programming
Producer:     pdfTeX-1.10b
Subject:      80x86 Assembly Language Programming
Title:        PC Assembly Language
Page Size:    variable
Optimized:    no
PDF version:  1.4
Security
  Passwd:     none
  Print:      yes
  Modify:     yes
  Copy:       yes
  Add:        yes
As it does, let's batch replace the word "Borland" with the word "Inprise" and name the new file output.pdf:
$ changepagestring.pl -o pcasm-book.pdf Borland Inprise output.pdf
That seems to have worked, but there are still instances of "Borland" in the file - why were they not changed? The following script by Adam314 will output the entire file, including the hidden PDF formatting codes:
#!/usr/bin/perl
use warnings;
use strict;
use CAM::PDF;
 
my $infile = '/path/pcasm-book.pdf';

#open file
my $doc = CAM::PDF->new($infile) || die "$CAM::PDF::errstr\n";
 
#look for string
for my $page (1..$doc->numPages) {
	my $content = $doc->getPageContent($page);
		print $content
		}
Sure enough, the string "Borland" only shows up twice. Where are all the others? Why, surrounded by hideous formatting code like these examples:
Borl)1(and)1('s
Borlan)1(d's)-2
Borlan)1(d)-497
Borl)1(and)-241
In his link above, Adam314 offers advice for replacing instances like these with regex. At this point I grew rather weary, however, especially as text replacements were wont to cut off or run into other words. However, for simple text replacements in simple PDF documents, changepagestring.pl may come in handy.

/nix | Dec 13, 2009

Blosxom alternatives, microblogs, etc. #
  • Chyrp "is a blogging engine designed to be very lightweight while retaining functionality. It is powered by PHP and has very powerful theme and extension engines, so you can personalize it however you want."
  • FlatPress "is an open-source standard-compliant multi-lingual extensible blogging engine which does not require a DataBase Management System to work."
  • Jekyll "is a blog-aware, static site generator in Ruby" (via Jalada)
  • NanoBlogger (first covered over 5 years ago; still under active development) "is a small weblog engine written in Bash for the command line. It uses common UNIX tools such as cat, grep, and sed to create static HTML content."
  • PluXml "is a script to create a site or a blog, no need for knowledge in programming nor d' need; a database on its lodging, a traditional environment php is enough for him. PluXml wants to be light and easy d' use thanks to an interface d' simple administration and the storage of your writings in easily transportable XML files." (translation via Babelfish)
  • PyBlosxom "is a lightweight file-based weblog system. The project started as a Python clone of Blosxom but has since evolved into a beast of its own. PyBlosxom focuses on three things: simplicity, extensibility, and community."
  • reprise - "Minimal static blog with atom and tag support." Available as a single Ruby or Python file.

/nix | Dec 03, 2009

Have ls return human readable formats (KB, MB, GB, etc) #
Like du and df, ls supports the -h switch for using unit suffixes (Byte, Kilobyte, Megabyte, Gigabyte, etc), turning this:
$ ls -l
 505223 aida16en.zip
  10273 atomicwebserver.zip
1359260 camstudio20.zip
into this:
$ ls -lh
494K aida16en.zip
 11K atomicwebserver.zip
1.3M camstudio20.zip

/nix | Nov 16, 2009

Create multiple empty files #
The following examples create three empty files of 1MB each:

Unix:
$ for i in {1..3}; do dd if=/dev/zero of=/path/$i bs=1m count=1; done
or,
$ for i in {1..3}; do mkfile 1m /path/$i; done
Windows:
C:\>for /L %x in (1,1,3) do fsutil file createnew %x 1048576
Notes:
  • mkfile can generate sparse files with the -n option.
  • The Windows for loop set is (start,step,end).
  • See also Generate Files with Random Content and Size in Bash, which introduces this script:
    no_of_files=10;
    counter=1;
    while [[ $counter -le $no_of_files ]];
     do echo Creating file no $counter;
      dd bs=1024 count=$RANDOM skip=$RANDOM if=/dev/sda of=random-file.$counter;
      let "counter += 1";
     done

/nix | Nov 13, 2009



Categories
/blosxom
/mac
/misc
/nix
/palm
/windows

Blosxom Archive
2010: 3 2 1
2009: 12 11 10 9 8 7 6 5 4 3 2 1
2008: 12 11 10 9 8 7 6 5 4 3 2 1
2007: 12 11 10 9 8 7 6 5 4 3 2 1
2006: 12 11 10 9 8 7 6 5 4 3 2 1
2005: 12 11 10

Blogger Archive
2005: 10 9 8 7 6 5 4 3 2 1
2004: 12 11 10 9 8 7 6 5 4 3 2 1
2003: 12 11 10 9 8 7 6

Ezine Archive
2004: 4 3 2 1
2003: 12 9 8 7 6 5 4 2 1
2002: 12 10 9 8 7 6 5 3 2 1
2001: 12 11 10