/home/shakir

09 Jan, 2008

Batch rename files with Krename

Posted by: shakir In: Information Insemination

When I was previously recovering lost files of my home folder, I wrote scripts to automatically rename recovered files based on their meta info so that I don’t need to go through them one by one. That worked for me at that time, but I must say it was quite a tedious exercise, as there were so many file types that I need to deal with. That all changed when I found myself krename, a Qt based batch file rename program.

It’s available for Debian / Ubuntu and installable via this command:

shakir@herugrim ~ $ sudo apt-get install krename

Using it is as simple as adding files to the application’s workspace, and here I’ll show an example on how to rename JPEG files.

Upon clicking Functions on the Filename tab, you’ll be presented with this screen:

and you’ll get the next screen upon selecting JPEG EXIF Info.

Add whatever EXIF Info that you would like to rename your files to, click Finish, and you’re done..

Tags:

07 Jan, 2008

Set up dual monitor in Linux

Posted by: shakir In: Information Insemination

I’ve just bought ViewSonic VA2226w from Lowyat, and has been able to use it in dual monitor mode with my XPS M1330 (nvidia based) and Kubuntu. The ViewSonic that I bought is a 22" LCD monitor with resolutions up to 1680×1050 (only just as high as my 15.2" Inspiron 6000’s screen)..

I was using nvidia-config to configure the dual display, and after some trial and error, I come out with this /etc/X11/xorg.conf file:

Section "ServerLayout"
    Identifier     "Layout0"
    Screen      0  "Screen0" RightOf "Screen1"
    Screen      1  "Screen1" 0 0
    InputDevice    "Keyboard0" "CoreKeyboard"
    InputDevice    "Mouse0" "CorePointer"
EndSection

Section "Files"
    RgbPath         "/usr/X11R6/lib/X11/rgb"
    FontPath        "unix/:7100"
EndSection

Section "Module"
    Load           "dbe"
    Load           "extmod"
    Load           "type1"
    Load           "freetype"
    Load           "glx"
EndSection

Section "ServerFlags"
    Option         "Xinerama" "1"
EndSection

Section "InputDevice"
    # generated from default
    Identifier     "Mouse0"
    Driver         "mouse"
    Option         "Protocol" "auto"
    Option         "Device" "/dev/psaux"
    Option         "Emulate3Buttons" "no"
    Option         "ZAxisMapping" "4 5"
EndSection

Section "InputDevice"
    # generated from default
    Identifier     "Keyboard0"
    Driver         "kbd"
EndSection

Section "Monitor"
    # HorizSync source: edid, VertRefresh source: edid
    Identifier     "Monitor1"
    VendorName     "Unknown"
    ModelName      "LCD"
    HorizSync       30.0 - 75.0
    VertRefresh     60.0
    Option         "DPMS"
EndSection

Section "Monitor"
    # HorizSync source: edid, VertRefresh source: edid
    Identifier     "Monitor0"
    VendorName     "Unknown"
    ModelName      "ViewSonic VA2226w"
    HorizSync       30.0 - 82.0
    VertRefresh     50.0 - 75.0
    Option         "DPMS"
EndSection

Section "Device"
    Identifier     "Videocard0"
    Driver         "nvidia"
    VendorName     "NVIDIA Corporation"
    BoardName      "GeForce 8400M GS"
    BusID          "PCI:1:0:0"
    Screen          0
EndSection

Section "Device"
    Identifier     "Videocard1"
    Driver         "nvidia"
    VendorName     "NVIDIA Corporation"
    BoardName      "GeForce 8400M GS"
    BusID          "PCI:1:0:0"
    Screen          1
EndSection

Section "Screen"
    Identifier     "Screen1"
    Device         "Videocard0"
    Monitor        "Monitor1"
    DefaultDepth    24
    Option         "TwinView" "0"
    Option         "metamodes" "DFP: 1280x800 +0+0"
    SubSection     "Display"
        Depth       24
    EndSubSection
EndSection

Section "Screen"
    Identifier     "Screen0"
    Device         "Videocard1"
    Monitor        "Monitor0"
    DefaultDepth    24
    Option         "TwinView" "0"
    Option         "metamodes" "CRT: nvidia-auto-select +0+0"
    SubSection     "Display"
        Depth       24
    EndSubSection
EndSection

and here’s my work desk at home (after some clean up :) )

 

p/s: Hope nobody mind me using the Microsoft keyboard and mouse set :D

Tags: ,

Often time the Master Boot Record (MBR) is also lost / corrupted when the we’re having problem with the partition table, and so here I extend my previous post on recovering lost partition table using the Ubuntu Live CD.

First of all, let’s mount the related stuff;

ubuntu@ubuntu:~$ sudo mount -o ro /dev/sda1 /media/
ubuntu@ubuntu:~$ sudo mount -o bind /dev/ /media/dev/
ubuntu@ubuntu:~$ sudo mount -o bind /proc/ /media/proc/

and then chroot

ubuntu@ubuntu:~$ sudo chroot /media/

Once we are in the chroot environment, run grub

bash:~# grub

Assuming you are installing grub on your first harddisk, and your root filesystem in the first partition of your first harddisk, your journey should be something like this;

    GNU GRUB  version 0.97  (640K lower / 3072K upper memory)

 [ Minimal BASH-like line editing is supported.  For the first word, TAB
   lists possible command completions.  Anywhere else TAB lists the possible
   completions of a device/filename.]

grub> root (hd0,0)
 Filesystem type is ext2fs, partition type 0x83

grub> setup (hd0)
 Checking if "/boot/grub/stage1" exists... yes
 Checking if "/boot/grub/stage2" exists... yes
 Checking if "/boot/grub/e2fs_stage1_5" exists... yes
 Running "embed /boot/grub/e2fs_stage1_5 (hd0)"...  16 sectors are embedded.
succeeded
 Running "install /boot/grub/stage1 (hd0) (hd0)1+16 p (hd0,0)/boot/grub/stage2
/boot/grub/grub.conf"... succeeded
Done.

grub> quit

Once you’re done with that, you might want to unmount whatever you have mounted before;

ubuntu@ubuntu:~$ sudo umount /media/proc/
ubuntu@ubuntu:~$ sudo umount /media/dev/
ubuntu@ubuntu:~$ sudo umount /media

and then reboot to see if your problem is really fixed..

My friend suddenly ask me for a Ubuntu Live CD and upon being asked he told me that he has not been able to boot his machine for getting the Operating System not found error. I’m posting here on how did I helped him out with the problem for documentation.

The program I used was gpart, and to use it in Ubuntu (Live CD) is to add Universe repository to /etc/apt/sources.list as this;

deb http://archive.ubuntu.com/ubuntu gutsy main restricted universe

and run this commands to install it.

ubuntu@ubuntu:~$ sudo apt-get update
ubuntu@ubuntu:~$ sudo apt-get install gpart

By running the next command, gpart will search the whole disk for possible partitions and write it’s findings to the partition table:

ubuntu@ubuntu:~$ sudo gpart /dev/sda -W /dev/sda

That’s it. Just reboot and see if your system is now bootable…

p/s: Other than gpart, testdisk can also be used for partition recovery, but i’m not covering it here..

This post is just a quick recap on how to configure passwordless ssh login.

In my setting, herugrim is my local machine, and anduril is the remote machine with the ip address of 192.168.1.10

The first step is to (optionally) generate RSA key for use with SSH. Make sure you dont use any passphrase for this or you’ll later need to enter the passphrase upon login instead of password, which doesn’t really server our purpose here.

shakir@herugrim ~ $ ssh-keygen -t rsa -C shakir@192.168.1.10
Generating public/private rsa key pair.
Enter file in which to save the key (/home/shakir/.ssh/id_rsa): /home/shakir/.ssh/id_rsa.192.168.1.10
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/shakir/.ssh/id_rsa.192.168.1.10.
Your public key has been saved in /home/shakir/.ssh/id_rsa.192.168.1.10.pub.
The key fingerprint is: 11:d9:23:2e:68:05:59:d9:ac:5a:00:69:17:3a:b4:24  

Now we can copy the public key to the server. Instead of doing it manually, OpenSSH has a nice program to do just what we need:

shakir@herugrim ~ $ ssh-copy-id -i .ssh/id_rsa.192.168.1.10.pub shakir@192.168.1.10

So now lets test if our passwordless login is successful:

shakir@herugrim ~ $ ssh shakir@192.168.1.10 -i .ssh/id_rsa.192.168.1.10
shakir@anduril:~$

Great, it works :) The next thing to do is to just make sure you keep your private key safe..

Beginning version 7 of vim, it has this nice auto completion feature. It is by default however limited to words that has already been in the current workspace. To use it, simply press [ctrl] +n or [ctrl] + p key while in edit mode. For example:

We can however *teach* vim to autocomplete a whole bunch of other stuffs as well, by using something so called Dictionaries. With this idea we can have auto completion for Python, Ruby, PHP, Bash, and any other programming languages code.

For an example, let’s try to install Python dictionary, by downloading it from here:

http://www.vim.org/scripts/script.php?script_id=850

The next thing to do is to extract the downloaded file to the appropriate folder:

shakir@herugrim ~ $ mkdir ~/.vim
shakir@herugrim ~ $ tar xvzf pydiction-0.5.tar.gz -C ~/.vim

and add this lines to your ~/.vimrc (be sure to replace "/home/shakir" to your own home directory)

if has("autocmd")
    autocmd FileType python set complete+=k/home/shakir/.vim/pydiction-0.5/pydiction isk+=.,(
endif " has("autocmd"

and let’s see the result:

Browse around the Vim script page and your customized Vim could be just as good if not better than some IDEs.. :)

Tags: ,

26 Dec, 2007

CSS for code block

Posted by: shakir In: Information Insemination

If you’re wondering how do I actually get the nicely boxed code block in my blog as this;

 

then the answer to it is just to have this in my CSS:

pre {
        border: 1px dashed #bbb;
        font-size: 75%;
        padding: 5px;
        color: #808080;
        background: #F1F1FF;
        overflow: auto;
}

and later I would just wrap whatever text I want to be in the box with the pre tag in my HTML codes, like this;

<pre>
This is a code example
</pre>

and should get this output (including the dashed-box):

This is a code example

and that’s all. It’s just so easy..

Tags:

17 Dec, 2007

How to create a Wordpress plugin

Posted by: shakir In: Information Insemination

I’m into writing a plugin for Wordpress, and so let me just share here how easy it is to actually create one.

For an example, we’re going to write a plugin that will insert a Google Adsense to our blog post.

From our Wordpress installation directory, create a file named google_adds.php in the wp-contents/plugins/ directory and add these lines;

 


To see what it does, login to your Wordpress admin panel and go to the Plugins section.

As what can be seen from the screenshot, the information of the plugins there were taken from the comments on our plugin code. We can now activate the plugin, but for now our plugin doesn’t really do anything useful.

Let’s go back to our PHP code, and add some lines to be as the following

"  .$text;
}

/*
  Add filter is a built in Wordpress function, and the_content
  is a Wordpress variable of a single post content.
*/
add_filter('the_content', 'adsense');

?>

Let’s see if it works

That’s it, our first fully functioning Google Adsense plugin :)

One nice thing about Python as compared to some other scripting languages, is that it has a shell that enables us to test our Python script on the fly without needing to write a script file first

It’s nice and all that, but when you’re too used to IDEs which has features such as auto completion etcetera, you’ll feel like something is not right about the default python shell.

That changes when I come to IPython, one of the few other enhanced Python shell. The one feature I like most is the auto complete feature, which among other by using it I don’t need to remember module names, and at the same time would list and try Python modules that I’ve never heard of.

In Ubuntu, or debian in general, the package is called ipython, and to install it just;

shakir@herugrim ~ $ sudo apt-get install ipython

Can you spot the differences between this

shakir@herugrim ~ $ python
Python 2.5.1 (r251:54863, Oct  5 2007, 13:36:32)
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import command
Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named command
>>> import commands
>>> status, output = commands.getoutputstatus ('ls')
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'module' object has no attribute 'getoutputstatus'
>>> status, output = commands.getstatusoutput ('ls')
>>> print output
Desktop
Documents
Music
Photos
>>>
shakir@herugrim ~ $

and this?

shakir@herugrim ~ $ ipython
Python 2.5.1 (r251:54863, Oct  5 2007, 13:36:32)
Type "copyright", "credits" or "license" for more information.

IPython 0.8.1 -- An enhanced Interactive Python.
?       -> Introduction to IPython's features.
%magic  -> Information about IPython's 'magic' % functions.
help    -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.

In [1]: import command
---------------------------------------------------------------------------
           Traceback (most recent call last)

/home/shakir/ in ()

: No module named command

In [2]: import commands

In [3]: status, output = commands.
commands.__all__           commands.__hash__          commands.__setattr__
commands.__class__         commands.__init__          commands.__str__
commands.__delattr__       commands.__name__          commands.getoutput
commands.__dict__          commands.__new__           commands.getstatus
commands.__doc__           commands.__reduce__        commands.getstatusoutput
commands.__file__          commands.__reduce_ex__     commands.mk2arg
commands.__getattribute__  commands.__repr__          commands.mkarg

In [3]: status, output = commands.gets
commands.getstatus        commands.getstatusoutput

In [3]: status, output = commands.getstatusoutput('ls')

In [4]: print output
Desktop
Documents
Music
Photos

In [5]:
Do you really want to exit ([y]/n)? y
shakir@herugrim ~ $

I hope you can guess when did I press the [tab] key :)

Tags: ,

I get this error when creating a BoundMetaData object in SQLAlchemy 0.3.10. The fix is to just use MetaData instead of  BoundMetaData. BoundMetaData is deprecated and replaced with MetaData

Example code:

from sqlalchemy import *

db = create_engine('sqlite:///test.db')
metadata = MetaData(db)

"""
  Continue with the rest of your Python code
"""

  • tebu: nak tanya sikit, untuk maxis punya kenapa dia ada keluar error +CME ERROR: SIM PIN required. user: maxis pass: wap betui ka..sim pin tu nak ke
  • shakir: Ditesh: I'm still able to download the game here from my end, but anyway, I've emailed you the game. p/s: The new Golden Axe game is in the making
  • Ditesh Gathani: Hi, I've been trying to download the said software but the site keeps timing out. Would it be possible for you to share the software through email?
  • apis: he he T Bag....
  • apis: cayalah
  • achoi: Salam, Buku tentang network security xde ke bang. Klu ada nk tempah awl² skit.hee :D
  • shakir: I blog about this actually because I was frustrated when I got no reply from the hosting company after reporting to them about this, though there was
  • Danesh: Talk to the hosting company and get to sponsor you a co-hosted package for your discovery... :D
  • shakir: Thanks for the invite bang. But then, I'm just a (PHP) script kiddie, tak layak nak masuk competition ni.. :)
  • shakir: I've already updated the firmware, and I don't keep copy of it. Sorry.

About


Twitter

Disclaimer

The information in this weblog is provided "AS IS" with no warranties, and confers no rights. This weblog does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my own personal opinion. Inappropriate comments will be deleted at the authors discretion. All code samples (if any, ever) are provided "AS IS" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.