Friday, November 27, 2009

How to convert a JPG file to PDF

You need to have installed "ImageMagick" or "GraphicsMagick"
In Ubuntu or Debian you can install it with the command:
sudo apt install imagemagick

or
sudo apt install graphicsmagick

Then you go to your work directory.
cd my/work/directory/path
And write the command
convert myfile.jpg myfile.pdf

Or with GraphicsMagick
gm convert file.jpg file.pdf

To convert multiple images:
gm convert file1.png file2.png file3.jpg file.pdf

For more, just run:
man gm

With ImageMagick you can also convert multiple JPG files into one multi-image PDF
convert *.jpg -adjoin myfiles.pdf

To merge multiple PDFs into one file:

$ pdftk file1.pdf file2.pdf file3.pdf cat output file123.pdf

CONVERTING  WITH  IMG2PDF

sudo apt install img2pdf

img2pdf --pagesize Letter input.jpg -o output.pdf

man img2pdf 



=====///////

Sunday, October 11, 2009

Create, mount and copy floppy disks images under Linux

If we need it we can create an empty image and mount it using linux's loop devices.
(link to page)

Creating an empty floppy image (1.44MB):
$ dd bs=512 count=2880 if=/dev/zero of= /path/imagefile.img
Format it:
$ mkfs.msdos /path/imagefile.img

There's a more direct way to do this.
Create & format a floppy image of 1.44 MB:
$ /sbin/mkfs.msdos -C /path/imagefile.img 1440

Mounting it:
$ sudo mkdir /media/floppy1/
$ sudo mount -o loop /path/imagefile.img /media/floppy1/

If you want to transfer some files to Windows in VirtualBox then, after copying your files into the floppy image, you have to umount the image.
$ umount /media/floppy1

Now in VirtualBox you start Windows and mount the floppy image (Devices ==> Mount Floppy ==> Floppy Image) as you see in the picture.

Then you can transfer the files from the floppy image to Windows. Do not forget to unmount the floppy image once you're done or you'll get an error next time you try to boot into Windows. This is because the virtual machine tries to boot first from the floppy image.
In case you need to transfer bigger files, instead of a floppy image you can use a CDROM image. If you already have the files in a CD, that's easier since you can directly mount the CD.

Sunday, October 04, 2009

Password-Protect Compressed Zip Archives

(link to note)
The Zip program allows you to password-protect your Zip archives using the -P option. You shouldn't use this option. It's completely insecure, as you can see in the following example (the actual password is 12345678):

$ zip -P 12345678 moby.zip *.txt

Because you had to specify the password on the command line, anyone viewing your shell's history (and you might be surprised how easy it is for other users to do so) can see your password in all its glory. Don't use the -P option!

Instead, just use the -e option, which encrypts the contents of your Zip file and also uses a password. The difference, however, is that you're prompted to type the password in, so it won't be saved in the history of your shell events.

$ zip -e moby.zip *.txt
Enter password:
Verify password:
adding: job.txt (deflated 65%)
adding: moby-dick.txt (deflated 61%)
adding: paradise_lost.txt (deflated 56%)

The only part of this that's saved in the shell is zip -e moby.zip *.txt. The actual password you type disappears into the ether, unavailable to anyone viewing your shell history.

Caution - The security offered by the Zip program's password protection isn't that great. In fact, it's pretty easy to find a multitude of tools floating around the Internet that can quickly crack a password-protected Zip archive. Think of password-protecting a Zip file as the difference between writing a message on a postcard and sealing it in an envelope: It's good enough for ordinary folks, but it won't stop a determined attacker.

Also, the version of zip included with some Linux distros may not support encryption, in which case you'll see a zip error: "encryption not supported." The only solution: recompile zip from source. Ugh.

----------
In case you want to ZIP a directory, this is the command:
zip  -re  myDirectory.zip  myDirectory

Monday, September 28, 2009

Tuesday, August 25, 2009

How to create a custom Ubuntu distro

(link to note)
*Get the packaged you need
sudo apt-get install squahfs-tools mkisofs

*Load the squashfs
sudo modprobe squashfs

create a iso image of Dapper CD
* confirm that cdrom is not mounted, if it is then
sudo umount /cdrom

* dd if /dev/hdc of=/pathtoiso/image.iso
else dd if /dev/cdrom of=/pathtoiso/image.iso

* Create a working directory
mkdir ~/custom

* move the iso to custom
mv /pathtoiso/image.iso ~/custom
cd ~/custom

* mount the image.iso
mkdir mnt
sudo mount -o loop image.iso mnt

* get the contents of iso in to a local dir
mkdir extract
rsync –exclude=/casper/filesystem.squashfs -a mnt/ extract

*Mount squashfs
mkdir squahfs
sudo mount -t squashfs -o loop mnt/casper/filesystem.squashfs squashfs
mkdir tmp
sudo cp -r squashfs/* edit

*Mount the root
sudo chroot edit
mount -t proc none /proc
mount -t sysfs none /sys
export HOME=/root

*Customization
Now you have all the settings ready and you can readily customise by apt-get
for eg, to add mplayer
sudo apt-get install mplayer

*The default backgrounds and splashscreens can be simpley copied .

*Edit LiveCD user
sudo vi edit/usr/share/initramfs-tools/scripts/casper-bottom/10adduser
sudo vi edit/usr/share/initramfs-tools/scripts/casper

*Cleanup
rm -rf /tmp/*
umount /proc
umount /sys
exit

chmod +w extraxt/casper/filesystem.manifest
sudo chroot edit dpkg-query -W –showformat=’${Package} ${Version}\n’ > extract/casper/filesystem.manifest
sudo cp extract/casper/filesystem.manifest extract/casper/filesystem.manifest-desktop
sudo sed -ie ‘/ubiquity/d’ extract/casper/filesystem.manifest-desktop
sudo mksquashfs edit extract/casper/filesystem.squashfs
sudo vim extract-cd/README.diskdefines

*Generate new md5sum
sudo -s
rm extract/md5sum.txt
(cd extract && find . -type f -print0 | xargs -0 md5sum > md5sum.txt)
exit

*Create the iso
cd extract
sudo mkisofs -r -V “$IMAGE_NAME” -cache-inodes -J -l -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -o ../custom.iso .

*You can test the cd by
qemu -cdrom custom.iso -boot d

*Burn the iso using k3b or nautilus-cd-burner
or
cdrecord dev=/dev/hdc custom.iso

Friday, May 29, 2009

Converting VOB or MP4 to FLV format

FLV file converter in Linux
(link to page)
Using "mencoder" to create "flv" from "VOB" DVD video format files

Many websites nowadays are using swf and flv file formats to play videos hosted on their site or sites, it's advantage is clear in that the file itself is often in comparison to regular video format files, smaller and easier to upload so the site is able to hold and run more video content with much less bandwidth than would normally be required.

#> mencoder inputfile.VOB -of lavf -ovc lavc -lavcopts vcodec=flv:vbitrate=150 -ofps 25 -oac mp3lame -lameopts abr:br=32 -srate 22050 -vf scale=720 -o outputfile.flv

In our first test video conversion format a file named VTS_01_2.VOB was successfully converted from a 776.9Mb file to a 17mb outputfile.flv although the video and audio was brilliant the file stopped short of it's actual completion target in other words outputfile.flv was considerably shorter than it should have been, we have concluded from this that the VOB file is corrupt and the conversion terminates at that point. Having obtained another dvd with which to copy from we tried again, you should not this recording was original obtained from a small video recorder and transfered to DVD which we then migrated to a flash video (flv). Below is how we archived it, please note the above mencoder script is different to the one below which did eventually work.

#> mplayer dvd://1 -dumpstream -dumpfile myvideo.vob
#> mencoder myvideo.vob -of lavf -ovc lavc -lavcopts vcodec=flv:vbitrate=150 -ofps 25 -oac mp3lame -lameopts abr:br=32 -srate 8000 -vf scale=720 -o outputfile.flv

It is important to note the above "mplayer" command it does not play the file not visibly at least but dumps or rips 1 or more VTS_01_n.VOB files into a single "vob" extension file that can then be converted into a video file format you require. The input file has been altered to reflect the file output from mplayer and "-srate" has been altered to "8000". If you think a graphical user interface is the way to go you may be right it would take a lot of the guess work and fun out of using command line, but for now command line seems much better than "gui". Ahh problems with the above it turns out with an "-srate of 8000" you might get some rapid clicking when transfered to a website or you tube, through some investigation and some trial and error we came up with the following which you might think is much better.

#> mplayer dvd://1 -dumpstream -dumpfile myvideo.vob
#> mencoder myvideo.vob -of lavf -ovc lavc -lavcopts vcodec=flv:vbitrate=150 -ofps 25 -oac mp3lame -lameopts abr:br=32 -srate 44100 -vf scale=720 -o outputfile.flv

The "flv" format files can only support 8000, 22050 and 44100 I believe for the available -srate.
----------------------------------
Converting MP4 to FLV
ffmpeg -i myvideo.mp4 -ar 44100 myvideo.flv

Monday, March 30, 2009

Graphs with PyXPlot

These are the contents of mydata.dat file:
--------------------------------------
8 4.3950
16 7.7879
24 11.0650
32 14.4312
40 17.3884
48 21.6769
56 23.7509
64 27.7398
72 31.5975
80 35.7720
88 39.2403
96 44.0992
----------------------------
Note: The separation between numbers is a tab space.
-------------------------------------------
$ pyxplot

____ __ ______ _ _ PYXPLOT
| _ \ _ _\ \/ / _ \| | ___ | |_ Version 0.6.3.1
| |_) | | | |\ /| |_) | |/ _ \| __| 26/02/2007
| __/| |_| |/ \| __/| | (_) | |_
|_| \__, /_/\_\_| |_|\___/ \__| Copyright (C) 2006-7 Dominic Ford
|___/

With thanks to Joerg Lehmann and Andre Wobst for writing PyX, and to
Ross Church for his many helpful suggestions along the way.

Send comments, bug reports, feature requests and coffee supplies to:
coders@pyxplot.org.uk

pyxplot> set ylabel 'Average'
pyxplot> set xlabel 'n'
pyxplot> plot 'mydata.dat'
pyxplot> exit

Goodbye. Have a nice day.

coders@pyxplot.org.uk
------------------------------------
Other examples:
Bar Charts

Script

set multiplot
set nodisplay
set samples 25
width=7
gold_ratio = 1/((1+sqrt(5))/2)

set width width
set xrange [-10.9:10.9]
set yrange [-1.2:1.2]
set nokey

# Plot 0 (bottom left)
set xlabel 'x'
set ylabel 'y'
set label 1 '(a)' at -9,0.8
set label 2 'histeps' -3.7,0.8
plot 'example6.dat' with histeps, 'example6.dat' with points

# Plot 1 (bottom right)
set origin 1*width, 0*width*gold_ratio
set xlabel 'x'
set ylabel 'linkaxis 0'
set label 1 '(b)' at -9,0.8
set label 2 'boxes' -3.7,0.8
plot 'example6.dat' with boxes, 'example6.dat' with points

# Plot 2 (middle left)
set origin 0*width, 1*width*gold_ratio
set xlabel 'linkaxis 0'
set ylabel 'y'
set label 1 '(c)' at -9,0.8
set label 2 'fsteps' -3.7,0.8
plot 'example6.dat' with fsteps, 'example6.dat' with points

# Plot 3 (middle right)
set origin 1*width, 1*width*gold_ratio
set xlabel 'linkaxis 1'
set ylabel 'linkaxis 2'
set label 1 '(d)' at -9,0.8
set label 2 'steps' -3.7,0.8
plot 'example6.dat' with steps, 'example6.dat' with points

# Plot 4 (top left)
set origin 0*width, 2*width*gold_ratio
set xlabel 'linkaxis 0'
set ylabel 'y'
set label 1 '(e)' at -9,0.8
set label 2 'impulses' -3.7,0.8
plot 'example6.dat' with impulses, 'example6.dat' with points

# Plot 5 (top right)
set origin 1*width, 2*width*gold_ratio
set boxfrom -0.5
set xlabel 'linkaxis 1'
set ylabel 'linkaxis 4'
set label 1 '(f)' at -9,0.8
set label 2 'boxes' -3.7,0.8
plot 'example6.dat' with boxes, 'example6.dat' with points

set display
refresh

Sunday, March 29, 2009

Python: Random numbers

(link to webpage)


>>> random.random() # Random float x, 0.0 <= x <>
0.37444887175646646
>>> random.uniform(1, 10) # Random float x, 1.0 <= x <>
1.1800146073117523
>>> random.randint(1, 10) # Integer from 1 to 10, endpoints included
7
>>> random.randrange(0, 101, 2) # Even integer from 0 to 100
26
>>> random.choice('abcdefghij') # Choose a random element
'c'

>>> items = [1, 2, 3, 4, 5, 6, 7]
>>> random.shuffle(items)
>>> items
[7, 3, 2, 5, 6, 4, 1]

>>> random.sample([1, 2, 3, 4, 5], 3) # Choose 3 elements
[4, 1, 5]

---------------------------------
Using the Random Module
(link)
>>>
import random

>>> # 0.0 <= float <>
>>> random.random()
0.41360177662769904

>>> # 10.0 <= float <>
>>> random.uniform(10,20)
15.743669918803288

>>> # 10 <= int <= 20 (can be 20)
>>> random.randint(10,20)
10

>>> # 10 <= int < step="2) random.randrange(10,20,2)
16

>>> # choose from a list
>>> random.choice([1, 2, 3, 5, 9])
2

>>> # make a list into random order
>>> cards = range(52)
>>> random.shuffle(cards) # order is random now
>>> cards[:5] # get 5 cards
[37, 14, 42, 44, 6]
-------------------------------------------

Wednesday, March 04, 2009

Mommy, I found it! — 15 Practical Linux Find Command Examples

One very basic example with the command 'find':
find . -name '*.txt' -type f

(link to article)
This article is written by SathiyaMoorthy
Apart from the basic operation of looking for files under a directory structure, you can also perform several practical operations using find command that will make your command line journey easy.

In this article, let us review 15 practical examples of Linux find command that will be very useful to both newbies and experts.

Monday, March 02, 2009

Configuring a printer

With the next command you can call the printer GUI configurator in Ubuntu.

$ sudo system-config-printer


Saturday, February 14, 2009

rtorrent

# This is an example resource file for rTorrent. Copy to
# ~/.rtorrent.rc and enable/modify the options as needed. Remember to
# uncomment the options you wish to enable.

# Maximum and minimum number of peers to connect to per torrent.
#min_peers = 40
#max_peers = 100

# Same as above but for seeding completed torrents (-1 = same as downloading)
#min_peers_seed = 10
#max_peers_seed = 50

# Maximum number of simultanious uploads per torrent.
max_uploads = 2

# Global upload and download rate in KiB. "0" for unlimited.
download_rate = 0
upload_rate = 5

# Default directory to save the downloaded torrents.
#directory = ./

# Default session directory. Make sure you don't run multiple instance
# of rtorrent using the same session directory. Perhaps using a
# relative path?
#session = ./session

# Watch a directory for new torrents, and stop those that have been
# deleted.
#schedule = watch_directory,5,5,load_start=./watch/*.torrent
#schedule = untied_directory,5,5,stop_untied=

# Close torrents when diskspace is low.
schedule = low_diskspace,5,60,close_low_diskspace=100M

# Stop torrents when reaching upload ratio in percent,
# when also reaching total upload in bytes, or when
# reaching final upload ratio in percent.
# example: stop at ratio 2.0 with at least 200 MB uploaded, or else ratio 20.0
#schedule = ratio,60,60,"stop_on_ratio=200,200M,2000"

# The ip address reported to the tracker.
#ip = 127.0.0.1
ip = rakshasa.no

# The ip address the listening socket and outgoing connections is
# bound to.
#bind = 127.0.0.1
#bind = rakshasa.no

# Port range to use for listening.
#port_range = 6890-6999

# Start opening ports at a random position within the port range.
#port_random = no

# Check hash for finished torrents. Might be usefull until the bug is
# fixed that causes lack of diskspace not to be properly reported.
#check_hash = no
# Set whetever the client should try to connect to UDP trackers.
#use_udp_trackers = yes

# Alternative calls to bind and ip that should handle dynamic ip's.
#schedule = ip_tick,0,1800,ip=rakshasa
#schedule = bind_tick,0,1800,bind=rakshasa

# Encryption options, set to none (default) or any combination of the following:
# allow_incoming, try_outgoing, require, require_RC4, enable_retry, prefer_plaintext
#
# The example value allows incoming encrypted connections, starts unencrypted
# outgoing connections but retries with encryption if they fail, preferring
# plaintext to RC4 encryption after the encrypted handshake
#
# encryption = allow_incoming,enable_retry,prefer_plaintext

# Enable DHT support for trackerless torrents or when all trackers are down.
# May be set to "disable" (completely disable DHT), "off" (do not start DHT),
# "auto" (start and stop DHT as needed), or "on" (start DHT immediately).
# The default is "off". For DHT to work, a session directory must be defined.
#
# dht = auto

# UDP port to use for DHT.
#
# dht_port = 6881
# Enable peer exchange (for torrents not marked private)
#
# peer_exchange = yes

#
# Do not modify the following parameters unless you know what you're doing.
#

# Hash read-ahead controls how many MB to request the kernel to read
# ahead. If the value is too low the disk may not be fully utilized,
# while if too high the kernel might not be able to keep the read
# pages in memory thus end up trashing.
#hash_read_ahead = 10

# Interval between attempts to check the hash, in milliseconds.
#hash_interval = 100

# Number of attempts to check the hash while using the mincore status,
# before forcing. Overworked systems might need lower values to get a
# decent hash checking rate.
#hash_max_tries = 10