This is just a blog to try and spread some of the knowledge that has been freely given to me by the wider community, without which I'd get absolutely nothing accomplished. I hope this benefits some of you out there.

Tuesday, August 25, 2009

Command Line English -> Foreign Language Dictionary



I have been studying Japanese for years. I love trying to learn the language, but it takes constant work. Lately what I've been trying to do is listen to NHK radio(their national news network) online. This has been great but since I'm not nearly fluent I have a lot of words I want to look up. And being at work I need to be able to look up something fast and continue on with what I'm doing i.e. resubmitting a search to an online dictionary is not going to cut it.

I found a great online dictionary at freedict, but as I mentioned above, it is a bit cumbersome. So I wrote a small python script to do the look up on that site for me. Put this on your path and you've got a commandline multi-language dictionary. This particular site does a lot of different translation, so I am going to modify my script so you can specify what exactly you want to translate and expand away from just Japanese to English. But for now, enjoy:


#!/usr/local/bin/python2.5

import urllib
import sys
import re

pattern = re.compile('')

data = urllib.urlencode({"search":sys.argv[1],"exact":"true","max":"10","to":"English","from":"Japanese","fname":"eng2jap2","back":"jap.html"})

file = urllib.urlopen("http://www.freedict.com/onldict/onldict.php",data)
results = pattern.sub('**',file.read())

pattern = re.compile('<(.|\n)*?>')
results = pattern.sub('',results)

pattern = re.compile('\s*\n+')
results = pattern.sub('\n',results)

pattern = re.compile('New search')
results = pattern.sub('',results)

pattern = re.compile('Online Dictionary Search Results')
results = pattern.sub('',results)

pattern = re.compile('\s\s\sJapanese')
results = pattern.sub('',results)

pattern = re.compile('\s\s\sEnglish')
results = pattern.sub('\n',results)

pattern = re.compile(' ')
results = pattern.sub('',results)

results = results.split('\n')
iterator = iter(results)

while True:
try:
line = iterator.next()
if '**' in line:
pattern = re.compile('\s*[A-Za-z]+')
match = pattern.match(line)
if match is not None:
line = line + iterator.next()
line = line.replace('**',' ')
print line
except StopIteration:
break




It is not perfect yet, but it'll do the job 95% of the time.

Friday, August 14, 2009

CPAN, Perl's Mothership



I recently wrote post about setting up a new mail server and how during that process I needed to install cpan as well as compile and install a perl module from source.

1. Download the zip/tar archive and uncompress e.g. tar xzvf my-perl-module.tar.gz

2. cd my-perl-module. Read the README and INSTALL files.

3. Run perl Makefile.pl PREFIX=/my/perl/directory.

4. Run 'make' and then 'make test'

5. Run 'make install'

6. Enjoy your new, bitchingly cool, perl module.

If this explanation is inadequate or you want a second opinion, check out cpan for more detailed, and probably correct, instructions.

On a related note, you can install modules using cpan itself. cpan was already installed, but not configured, with CentOS 5, but any modern version of linux will either come with it or have a way to easily install with apt-get/yum, etc.

The configuration I did was just the default, but I did have to install gcc before I could finish.

Once you do finish configuring cpan, to run it is dead easy: cpan

Running 'help' will get you a list of commands for the cpan shell. I just used it for installing modules so all that was necessary is just entering 'install your_desired_module' e.g. 'install DBI'

You can find the exact name of the module you need at search cpan.

That should take care of everything for you.

CentOS 5 Mail Server: Postfix, Dovecot, SpamAssassin, MailScanner



I have recently had the pleasure of setting up a new mail server. The old machine was not doing a good enough job of cutting down on spam and it needed an update. There are some great tutorials out there, but as is often the case there are minor changes that need to be made. I thought I'd document my experience to help anybody else along.

Following the tutorial regarding the setting up of postfix and dovecot just a matter of typing. I skipped Squirelmail and setting up the firewall as the mail server was going to be behind one already. MailScanner, although this should've bee a piece of cake, was giving me some grief. Nearly all of it boiled down to permissions. I knew they were wrong, but I wasn't given any indiction as to what about them was wrong i.e. who was the service running as, what permission did they need and on what file. MailScanner appeared to be working in that it scanned for viruses and then deposited the mail for postfix to process, but that was as far as the mail was getting. After much digging and playing around with configuration files I found out that the owner on /var/spool/postfix/active/random/file was actually root. I don't know what the file is, but it is necessary to deliver your mail, and the owner must be postfix, not root. After fixing that, one of my problems went away. The other problem was with Clamav.

For some reason installing Clamav via yum on CentOS 5 gives you a /etc/clamd.conf file that is slightly different than what you'd expect. The location of the socket that clamd will use is different than in the tutorial and will have to be changed either in /etc/MailScanner/MailScanner.conf or /etc/clamd.conf so they match. The exact part you'll need to change in MailScanner.conf is the Clamd Socket. It defaults to /tmp/clamd.sock, or something like that but in the clamd.conf file it will be in /var/run/clamav/clamd.sock. Go figure.

My Recommendation on this is to follow the tutorial to the letter as far as creating directories goes. If the permissions are at all wrong it will become obvious very quickly and be somewhat difficult to track down.

One thing to note, make sure to get all the perl modules needed before installing MailScanner. If you don't you'll have to look in /var/log/maillog to see which module you're missing and install it before you can go any further. I have little experience with perl but I did learn how to setup and configure cpan as well as install a module from source.



Followers