Senin, 13 Juni 2011

Tentang "Wimpy" and "Brawny" Core Processor

Dari sudut pandang lisensi aplikasi, tidak semua jenis multi-core processor dianggap sama.

Misalnya, lisensi Oracle DB pada Sun T series dihitung dengan pengali 0.5 per core (lengkapnya disini), sedangkan aplikasi IBM mempunyai metrik yang dinamakan IBM "Processor Value Unit" (PVU), bisa dibaca disini.

Mereka dibedakan dari kemampuan si core nya, termasuk kedalam golongan "wimpy" core adalah Sparc T series, Intel Atom dan ARM family, core mereka dibuat untuk hemat energi dan kemampuan clock-rate nya lebih rendah.

Sebaliknya, golongan "brawny" adalah core dengan performa penuh, diantaranya Intel Xeon, Itanium, AMD Opteron, IBM Power6/Power7, Sparc-VII+, HP PA-RISC.

Rabu, 26 Januari 2011

Perl diamond operator in Haskell

As a Perl enthusiastic system admin, i'm troubled to forget the following snippets:
while (<>) { print(uc); }

What nice about the construct is that the diamond operator <> will automatically handling read from stdin, whether you give it from a pipe, from the arguments, or wait from keyboard if none given.

As a Haskell newbie, below are my current attempt to mimicking that:
import System.IO
import System.Environment
import qualified Data.ByteString.Lazy.Char8 as BS
import Control.Monad (liftM)
import Data.Char (toUpper)

main = getArgs >>= grabContents >>= BS.putStr
where grabContents args =
if null args then BS.hGetContents stdin
else mapM BS.readFile args >>= return . BS.concat


Working on it further, i try to abstract it like so:
(<>) :: (BS.ByteString -> IO a) -> IO a
(<>) f = do
args <- getArgs
contents <- if null args
then BS.hGetContents stdin
else getArgs >>= mapM BS.readFile >>= return . BS.concat
f contents


So, we can write main function which quite nice in a imperative sense like below:
main = (<>) (\ str ->
do let str' = BS.map toUpper str
BS.putStr str')


Some note: First, I'm using ByteString here because based on my dirty inspection (just simply using something like "time myprog args ..."), ByteString is higher in performance than plain String or Data.Text. I still believe that String, ByteString, Text has their own goodness and still make a mind how to justify on any given situation, one of them is the best to pick.

Second note, it is also the lazy version of ByteString i'm using, because i notice that function getContents of that module behave lazy as i expected --I just expect it won't read the whole data file and store it to memory at once. Using the lazy version, i just confident as reading line by line as the perl <> operator do.

My further investigation would be whether using getContents does not break when i'm do for example treat "\n\n" as line/record field separator instead of standard "\n". Perl have this capability as simple as assign any line separator we want in $/ predefined global variable.

Selasa, 04 Januari 2011

GHC-7.0.1 build on FreeBSD-8

Here are the quick n dirty way building haskell ghc 7:

Download source tarball from http://haskell.org/ghc/dist/7.0.1/ghc-7.0.1-src.tar.bz2

Extract it!

At this stage, i already installed ghc version 6.10.4 installed via binary port mechanics (something like: pkg_add -r ghc) and cabal-install-0.8.2 via source manually.

On the first gmake run, i hit error on iconv not found, so install it.

The next, error on gmp can not relocated or something. I have installed gmp-5.0.1 installed via port in math/gmp.

So here the configure and make command which finally finish without error:

./configure --with-iconv-includes=/usr/local/include --with-iconv-libraries=/usr/local/lib --with-gmp-includes=/usr/local/include --with-gmp-libraries=/usr/local/lib --prefix=/usr/local/ghc7

gmake -j5 LDFLAGS="-L/usr/local/lib -I/usr/local/include"

gmake install


It took about 50 minutes on standard HP ML115 single dual-core 2.2GHz and 8GB memory.

Rabu, 30 Juni 2010

Rescuing Email Problem

Jika suatu saat anda bosan dengan kelakuan outlook express yang lamban karena file inbox yang besar, berikut catatan tips untuk bermain-main dengannya.

Pertama, ada software yang dulu pernah saya gunakan untuk mengconvert format dbx menjadi mbox, namanya DbxConv.exe, ini linknya:

DbxConv - DBX to MBOX converter

Cara menggunakannya mudah saja, jalankan DbxConv.exe tanpa argumen atau option -? untuk melihat sinopsis usagenya.


DbxConv.exe Inbox.dbx
No conversion options selected, using MBOXO-converter...
Processing mailbox "Inbox.dbx" (5357 messages)...
1 of 1 mailboxes converted to MBOXO-format!


Maka akan dihasilkan file output Inbox.mbx yang sudah dalam format mbox.

Kedua, mungkin anda percaya bahwa format maildir lebih baik dari pada format mbox, ada beberapa tools konversi dari mbox ke maildir yang tersedia pada freebsd (or linux), diantaranya mb2md atau mbox2mdir, tapi keduanya tidak bekerja sebagaimana yang saya inginkan, dimana mb2md menyatakan file mbox hasil dari DbxConv.exe bukan dalam format mbox, sementara mbox2mdir tidak membuat layout maildir sebagaimana mestinya (tidak ada direktori cur, new, dan tmp) jadi sepertinya mbox2mdir lebih seperti utiliti formail bawaan procmail yang hanya memisahkan satu file mbox menjadi banyak file-file mail terpisah. Akhirnya, ternyata script perl yang cukup sederhana ini yang bekerja seperti yang saya inginkan:

http://untroubled.org/mbox2maildir

Contoh penggunaan:


$ mkdir Maildir
$ ./scripts/perls/mbox2maildir Inbox.mbx ~Maildir/inbox-m8-2009


Ketiga, ya tentu saja anda menginginkan untuk bisa searching, ya ngga? dari hasil pencarian, yang cukup melelahkan, karena kata kuncinya terlalu umum (belum ketemu yang pas), sepertinya utiliti yang terbaik yang saya dapatkan adalah mairix

Tanpa baca dulu dokumentasinya mairix(1) dan mairixrc(5) terlebih dulu, saya jamin (hehe) anda akan bingung cara menggunakannya, berikut panduan singkat saja berdasarkan apa yang saya lakukan:


$ cat <<EOF > ~/.mairixrc
base=~/Maildir
mformat=maildir
maildir=inbox-m8-????
mfolder=mfolder
mformat=maildir
database=~/Maildir/mairix_database
EOF
$ mairix
$ mairix s:reedho
Matched 6 messages
$ mairix -r s:reedho
/home/reedho/Maildir/inbox-m8-2009/cur/1277869084.29442.mbox:2,S
/home/reedho/Maildir/inbox-m8-2009/cur/1277869085.29442.mbox:2,S
/home/reedho/Maildir/inbox-m8-2009/cur/1277869100.29442.mbox:2,S
/home/reedho/Maildir/inbox-m8-2009/cur/1277869108.29442.mbox:2,S
/home/reedho/Maildir/inbox-m8-2009/cur/1277869227.29442.mbox:2,S
/home/reedho/Maildir/inbox-m8-2009/cur/1277869228.29442.mbox:2,S


Keempat, tentu saja ini karena semuanya formatnya sudah maildir kita cari MUA yang support, sebelumnya saya pake Alpine yang nampaknya pada standard port install freebsd tidak support maildir, akhirnya kembali menggunakan The Mutt E-Mail Client.

Konfigurasi mutt lebih membingungkan lagi daripada mairix, karena waktu sudah mendesak, searching mutt maildir ke google, akhirnya working configuration saya yang bekerja berdasarkan tutorial di sini Mutt & Maildir Mini-HOWTO adalah sebagai berikut:


$ cat .muttrc
set mbox_type=Maildir
set folder="~/Maildir"
set mask="!^\\.[^.]"
set mbox="~/Maildir/mfolder"
set record="+.Sent"
set postponed="+.Drafts"
set spoolfile="~/Maildir/mfolder"
mailboxes `echo -n "+ "; find ~/Maildir -maxdepth 1 -type d -name "inbox*" | xargs`
macro index c "?" "open a different folder"
macro pager c "?" "open a different folder"
macro index C "?" "copy a message to a mailbox"
macro index M "?" "move a message to a mailbox"
macro compose A "?" "attach message(s) to this message"


Terakhir, kelima, mungkin terpikir juga bisa gak ya kalo mau disearch via web, seperti The Mail Archive gitu dech.. hm, karena waktu nya sudah habis, saya belum sempat setup MHonArc: A mail-to-HTML converter, silahkan diexplore.

Rabu, 16 Juni 2010

Perl chap password checker

If your NAS performing chap authentication to RADIUS server (e.g. FreeRADIUS), this article will briefly show a simple perl script to check the chap authentication given you have the "Cleartext-password" and the "auth_detail" log for a given authentication request.

For example, the log request is follow:


Wed Jun 16 00:00:00 2010
Packet-Type = Access-Request
User-Name = "xxxxxxxxxxxxxxxxxxxxxxx"
CHAP-Password = 0x01427b3a4c7121b834d330159a44487597
NAS-IP-Address = x.x.x.x
Service-Type = Framed-User
Framed-Protocol = PPP
Calling-Station-Id = "xxxxxxxxxxxxxxx"
CHAP-Challenge = 0xe9d3017252bc81d810d6fb37e4d60bee


And you have the Cleartext-password is for example m@!s3curEp455w0Rd, then the following is the perl script to do the job:


#!/usr/bin/env perl

use warnings;
use strict;
use Digest::MD5 qw(md5 md5_hex md5_base64);

my $chap_password = shift || die;
my $chap_challenge = shift || die;
my $cleartext_password = shift || die;

$chap_password =~ s/^0x//;
$chap_challenge =~ s/^0x//;

my $chap_id = substr($chap_password, 0, 2);
my $chap_id_binstr = pack('H2', $chap_password);
my $chap_challenge_binstr = pack('H32', $chap_challenge);

my $md5_hash = md5_hex($chap_id_binstr,$cleartext_password,$chap_challenge_binstr);
substr($chap_password, 0, 2, '');

print $md5_hash eq $chap_password ? "OK" : "INCORRECT", "\n";


Here the example of running the script:


reedho>./radchk.pl 0x01427b3a4c7121b834d330159a44487597 0xe9d3017252bc81d810d6fb37e4d60bee m@!s3curEp455w0Rd
INCORRECT