Showing posts with label English. Show all posts
Showing posts with label English. Show all posts

Monday, May 4, 2009

a python script to generate cue file

Abstract

A python script to generate cue file from file names in a same folder is given.

Sometimes we have lessless music (ape, flac…) split in to different files, and a cue file may help orgnize them in some music jukebox application, i.e foobar2000. so I create a really silly script to help me…

#!/usr/bin/env python
# -*- coding: UTF-8 -*-

import os
import sys
import glob
from string import Template
from optparse import OptionParser

cue_head='''REM GENRE $GENRE
REM DATE $DATE
REM DISCID $DISCID
PERFORMER "$PERFORMER"
TITLE "$ALBUMTITLE"'''

cue_file='''
FILE "$FILE" WAVE
TRACK $TRACK AUDIO
TITLE "$TRACKTITLE"
INDEX 01 00:00:00'''

def cue_gen():
"""
generate cue file
"""
parser = OptionParser()
parser.add_option('-d', dest='dir',
type='string')
parser.add_option('-s', dest='sfx',
type='string', default='ape')
options, args = parser.parse_args()

if options.dir is None:
directory = os.getcwd()
else:
directory = options.dir
suffix = options.sfx
print directory, suffix

files = glob.glob(os.path.join(directory, '*.'+suffix))
files = [ff[1] for ff in [os.path.split(f) for f in files]]
files.sort()
for file in files:
print file
begin = int(raw_input('Title offset? '))

genre = raw_input('Genre? ')
date = raw_input('Date? ')
discId = raw_input('DiscId? ')
performer = raw_input('Performer? ')
albumTitle = raw_input('Title? ')
d1 = dict(GENRE = genre,
DATE = date,
DISCID = discId,
PERFORMER = performer,
ALBUMTITLE = albumTitle)
head = Template(cue_head).substitute(d1)
cuepath = os.path.join(directory, (albumTitle+'.cue'))

f = open(cuepath, 'w')
f.write(head)

track = 0
for file in files:
trackTitle = file[begin:-(len(suffix)+1)]
track = track + 1
d2 = dict(FILE = file,
TRACK = track,
TRACKTITLE = trackTitle)
body = Template(cue_file).substitute(d2)
f.write(body)

f.close()

if __name__ == '__main__':
cue_gen()

I know it’s quite rough and a lot of enhancement can be made… maybe it should search for the right file extension automatically or even search the genre for the internet, and that’s just why I put it here, hopefully some of you would help to improve it XD

Sunday, May 3, 2009

Migrate to a blog is just like move to a new house...

It's tiring, but offers a great opportunity to review my stuffs - what I have been writing about, what kind of blog I hope to have, whether my posts are well tagged...

And when I was trying to make a list of all programing/makeup languages I've used, I found some of them get so rusty that I cannot even remember how to define a function in it...Hmm it doesn't sound good :(

Thursday, April 30, 2009

My Comments on Books about Shell Programming

Abastract
In this article I shall introduce several books about shell programming and hopefully it will help you to determine the right one for you.

I have to learn shell to carry out some of my experiments recently, and to be honest, I don’t feel like shell very much since there are so many modern script languages out there… Anyway, as shell is so widely used, it’s not too bad to spend some time on it.

  • A Practical Guide to Linux Commands, Editors, and Shell Programming is a nice book to start for newbies :)
  • Unix Shell Programming is the best book on shell programming I’ve found, which explains how shell works clearly
  • Classic Shell Scripting is not structured as well as the the previous one, but it has a chapter on security and explains some basic ideas in more details. If you get confused while reading the previous book, check this one.
  • Unix Shell by Example explains all popular shells, including sh, bash , csh and ksh, if you are going to script for different shells you may very likely find this book useful.

Monday, April 27, 2009

Google logo today is so~ COOL!

So impressive.

Finally get Xorg-1.6 work with nVidia MX440

Abstract

I describe a solution to the problem that Xorg 1.6 fails to work with Mx440 and kernel 2.6.29 in Arch Linux

I'm currently using an old PC in the lab, which features a MX440 video card, last week I updated my Arch Linux and got Xorg 1.6, and that was the start of a nightmare...

Xorg refuse to work with the legacy driver (nvidia-96xx), and won't start if the xorg.conf file exists, which is used to specify the screen resolution(though the pc is quite old, I got a big widescreen monitor…). I browsed the Arch user forum and tried all the solutions given, and finally get it work with add “nopat” option to the kernel in the grub munu.lst like this:

title Arch Linux
root (hd0,4)
kernel /vmlinuz26 root=/dev/disk/by-uuid/99b8f60e-c1eb-4482-a22f-6a49a5572401 ro vga=0x317 nopat
initrd /kernel26.img

Hopefully this can be useful ;)

Monday, March 30, 2009

Clone Arch Linux to another computer

I’ve just cloned my arch linux installation from my lab pc to my laptop, and it is much easier than I’ve expected. First I packed every thing up into a tar in a removable disk like this: (you need to change sdxx and sdyy below to your corresponding partition)

#mount the backup disk
mkdir /mnt/backup
mount /dev/sdxx /mnt/backup
cd /
tar -cvpzf /mnt/backup/BACKUP_FILE.tar.gz --exclude=/{dev,lost+found,mnt,proc,sys,tmp,}/* /

Then in my laptop:

# boot with arch iso
# mount the dest partition
mkdir /mnt/arch
mount –t ext3 /dev/sdyy /mnt/arch
# mount the backup disk
mkdir /mnt/backup
mount –t vfat /dev/sdxx /mnt/backup
# expand the installation tar
cd /mnt/arch
tar –xvpzf /mnt/backup/BACKUP_FILE.tar.gz
# something necessary to boot
chroot /mnt/arch
cd /dev
mknod -m 660 console c 5 1
mknod -m 660 null c 1 3
# modify the /etc/fstab
# make a new boot ramdisk
mkinitcpio -p kernel26
# install grub
# modify /boot/grub/menu.lst
exit
umount /dev/sdxx
umount /dev/sdyy
shutdown –r now
# have fun

Besides what are listed here, I also changed my video card driver and edited my /etc/xorg.conf file. The workflow works well for Arch Linux, but might not work exactly with other distro(e.g. mkinicpio seems to be Arch-only), in this case you may need to consult the all-mighty adviser – Google ;)

Monday, March 23, 2009

Cannot use visudo?

Su is not always the best tool to grand permission to users, so I installed sudo on my Arch Linux system. However when I tried to issue visudo, I got the following error:

bash-3.2# visudo
bash: visudo: command not found
The reason of this is quite simple - /usr/sbin is not in the PATH environment variable by default, and you can locate the visudo command by:
bash-3.2# whereis visudo
visudo: /usr/sbin/visudo /usr/share/man/man8/visudo.8.gz
so just use the full path to visudo:
bash-3.2# /usr/sbin/visudo
then everything goes right.

Sunday, March 22, 2009

Script to set all pdf bookmarks to zoom: inherit

When you create a bookmark in Acrobat, it automaticly sets the current zoom setting to te bookmark. This may be smart and sweet for someone, but to me it's stupid and annoying. Since when I read a file in a large screen, I want a greater zoom, while on a smaller screen, I wanna save space and see more content; setting a zoom for bookmarks screws things up. Finally I found {a great perl script} that can convert all pdf bookmark to zoom: inherit.

Use the bookmarks-fitpage.pl script from the zip, which set all bookmarks to zoom: inherit (the script is named as fitpage, which is a bit confusing...)

Notice that the script only works for PDF version 1.4 or earlier, if you're using Acrobat 9, you can convert the file to pdf-1.4 (Acrobat 5) by going to menu: advanced>print production>preflight, the wizard will do a nice convert job for you.

VIM in GNU coding style

I guess I'll start working on GCC recently, so I tried to prepare my VIM for GNU coding style. However, it's not as easy as I hoped, since VIM seems to favor BSD style more than GNU style which is a great waste of screen space in my view...Anyway, after a vast amount of Googling and attempts, it works now. Here's what I did to VIM: create a file named c.vim in my "~/.vim/after/ftplugin" directory, with the following content:
"GNU Coding Standards
setlocal cindent
setlocal cinoptions=>4,n-2,{2,^-2,:2,=2,g0,h2,p5,t0,+2,(0,u0,w1,m1
setlocal expandtab
setlocal shiftwidth=2
setlocal tabstop=8
setlocal softtabstop=2
setlocal textwidth=80
setlocal fo-=ro fo+=cql
I have to put it here otherwise the settings might be overrode by VIM's default ftplugin settings.

Friday, April 4, 2008

OniBlade English Language pack re-upload

http://huangyuanjie.googlepages.com/RU2EN.ZIP

Extract the zip into the game install dir, and have fun:)

There is not any changes made, just 'cause I found the original download link fail to work.

There could be countless errors... so if you do love the game, wait for the official English release.