weblog d’un abbe


This posting may harm your computer

Filed under: Experiences, Fun — Tags: , , — abbe @ 2036

Google goes mad



Instantaneous fortune

Filed under: Fun — Tags: , — abbe @ 1419
        In the year 2054, the entire defense budget will purchase just one
        aircraft.  This aircraft will have to be shared by the Air Force and
        Navy 3-1/2 days each per week except for leap year, when it will be
        made available to the Marines for the extra day.
        Software is like entropy.  It is difficult to grasp, weighs nothing,
        and obeys the Second Law of Thermodynamics, i.e., it always increases.
        It is very expensive to achieve high unreliability.  It is not uncommon
        to increase the cost of an item by a factor of ten for each factor of
        ten degradation accomplished.
        Although most products will soon be too costly to purchase, there will
        be a thriving market in the sale of books on how to fix them.
        In any given year, Congress will appropriate the amount of funding
        approved the prior year plus three-fourths of whatever change the
        administration requests -- minus 4-percent tax.
                -- Norman Augustine


Hacking a codegen

Filed under: Experiences, Fun, Hacking, Yippee!! — Tags: , , , , , , — abbe @ 0456

So, finally I’ve hacked a basic AMD64 code generator, after so many tries. This code generator is hacked in Common Lisp, and is currently generating a code for a very simple toy like language. I’ve not written any grammar specification for it. It is a LISP like language. This piece of code generator is dedicated to one of my cool friend Edwin Jose, and is thus named as louzer. Following is an example of the language for which louzer generates code.

	 (let principal rate time amount x)
	 (= principal 1000)
	 (= rate 10)
	 (= time 100)
	 (= x 100)
	 (= amount
		(/ (* principal (* rate time))
	 (print "Amount (%d) - %d is %d.\\n"  amount x (- amount x))
	 (print "Hello World, louzer\\n"))

The language code is also embedded along with the source code in the LISP file. Following is how I’m using it with GNU clisp implementation:

% clisp louzer.lisp |tee test.S
.section .text
.extern printf
.type main,@function
.globl main
 pushq %rbp
 movq %rsp, %rbp
 subq $40, %rsp
 movq $1000, %rbx
 movq %rbx, -8(%rbp)
 movq $10, %rbx
 movq %rbx, -16(%rbp)
 movq $100, %rbx
 movq %rbx, -24(%rbp)
 movq $100, %rbx
 movq %rbx, -40(%rbp)
 movq -16(%rbp), %rbx
 imul -24(%rbp), %rbx
 imul -8(%rbp), %rbx
 movq %rbx, %rax
 movq $100, %rbx
 xorq %rdx,%rdx
 idiv %rbx
 movq %rax, -32(%rbp)
 leaq __string_0,%rdi
 movq -32(%rbp), %rsi
 movq -40(%rbp), %rdx
 movq -32(%rbp), %rbx
 subq -40(%rbp), %rbx
 movq %rbx, %rcx
 xorq %rax,%rax
 call printf
 leaq __string_1,%rdi
 xorq %rax,%rax
 call printf
 xorq %rax, %rax
 movq %rbp, %rsp
 popq %rbp
.section .rodata
__string_1: .string "Hello, louzer World\n"
__string_0: .string "Amount (%d) - %d is %d.\n"
/* Generated by louzer :) */

Above is the piece of AMD64 assembly code emitted by the louzer. So, now time to assemble and link the above assembly code and generate the output of the above code.

% cc -o test test.S
% ./test
Amount (10000) - 100 is 9900.
Hello, louzer World

Voila. Oh, sorry to keep you waiting, now you can download the louzer.lisp and have fun. BtW, code is not perfect and has couple of limitations, which I’ve not fixed due to lack of time, as I’ve an exam day after tomorrow. So, I’ll be able to work on it only after 20081219. Happy hacking codegens…;)

NOTE (for Grammar Nazis): Forgive me for any grammatical mistakes you encounter above, and ofcourse point out the mistake :).

P.S. Forgot to mention, you’ll need an AMD64 architecture CPU, toolchain and POSIX OS to test out above stuff.


Ready to assassinate spam

Filed under: Experiments, Fun, Hacking — Tags: , , , , , — abbe @ 2136

Since a week or two, I noticed I suddenly started to get many spams (at the rate of around 10/day) delivered to my gmail inbox. I reported them every time, but that is of not much use. So tired of reporting spams, I started to create filters (in gmail) based on From address, ‘Subject’ etc. to delete them as soon they arrive, and I noticed that some of the ham mails also got deleted due to my filters. So, to get rid of this problem yesternight I installed SpamAssassin (which I’m afraid of installing earlier because I heard of its complex configuration) on my box integrated with postfix instance on my Gentoo GNU/Linux. The installation (thanks to portage) is very easy and integration with postfix is also quite easy and well documented on its wiki. And now, the best part, my SpamAssassin today recognized those mails as spam, which gmail‘s spam filters delivered into my inbox :).

Following is a Gnus hack to report spam as ham and ham as spam :

(defun my-gnus-mark-spam()
  (gnus-summary-save-in-pipe "spamc -L spam")
  ;; substitute "nnmaildir:spam" with the name of group holding "spam"
  (gnus-summary-move-article nil "nnmaildir:spam"))

(defun my-gnus-mark-ham()
  (gnus-summary-save-in-pipe "spamc -L ham")
  (gnus-summary-respool-article nil))

;; in summary mode use "B s" and "B h" keys to mark a mail as spam and ham
;; respectively for SpamAssassin to learn, and to also move to "spam" maildir
;; or respool mail accordingly
(define-key gnus-summary-mode-map (kbd "B s") 'my-gnus-mark-spam)
(define-key gnus-summary-mode-map (kbd "B h") 'my-gnus-mark-ham)

I could have used Gnus built-in spam filtering, but Gnus is not the only MUA I use ;) . Anyways, happy assassinating spam…;)


fake identd server

Filed under: Fun, Hacking — Tags: , , — abbe @ 2007
-- identd: RFC1413 incompliant identd server
-- author: Ashish Shukla <gmail.com!wahjava>
-- license: GNU GPLv2 or later version at your option
-- special thanks to: consolers on #emacs
-- 1. Compile the file: abbe@chateau $ ghc --make identd.hs
-- 2. Make it setuid root: abbe@chateau $ chown 0 identd; chmod u+s identd
-- 3. Execute it: abbe@chateau $ ./identd abbe
-- happy faking ident

import System.IO (hGetContents, hClose, openFile, hPutStrLn, hGetLine)
import System.Random (randomRIO)
import IO
import Network.BSD
import Network.Socket

import System.Environment (getArgs, getProgName)

import System.Posix.User (getUserEntryForName, setUserID, UserEntry, userID)

import Control.Exception (evaluate)

wordsFile = "/usr/share/dict/words"

loadWords :: FilePath -> IO [String]
loadWords fileName = do
    handle <- openFile fileName ReadMode
    contents <- hGetContents $ handle
    let listOfWords = lines contents
    lenWords <- evaluate (length $ listOfWords)
    hClose handle
    return listOfWords

getUserName :: [String] -> IO String
getUserName words = do
    index <- randomRIO (0, length words - 1) :: IO Int
    return (words !! index)

handleSocket :: [String] -> IO (Socket, SockAddr) -> IO Bool
handleSocket words struct = do
  (socket, sockaddr) <- struct
  handle <- socketToHandle socket ReadWriteMode
  line <- hGetLine handle
  name <- getUserName words
  -- logged-in from a LISP Machine ;)
  hPutStrLn handle $ (withoutWS line) ++ " : USERID : LISPM : " ++ name
  hClose handle
  return True
  where withoutWS = filter (\x -> x `notElem` [ '\r', '\n'])

main = do
  args <- getArgs
  progName <- getProgName
  if null args
    then putStrLn $ "Usage: " ++ progName ++ " [username]"
    else do
        user <- getUserEntryForName $ args !! 0
        let uid = userID user
        rng <- getStdGenuu
        ssock <- socket AF_INET6 Stream defaultProtocol
        bindSocket ssock (SockAddrInet6 113 0 (0,0,0,0) 0)
        setUserID uid
        words <- loadWords wordsFile
        sockaddr <- getSocketName $ ssock
        listen ssock 5
        loopForever (handleSocket words . accept) ssock
        sClose ssock
  where loopForever function y = do
            retval <- function y
            if retval
              then (loopForever function y)
              else return ()

Happy faking ident…;)


Red Hat releases SELinux Users Guide

Filed under: Yippee!! — Tags: , , , — abbe @ 1847

So, Red Hat released a SELinux User Guide which looks great :), and in the authoring team there is a friend . Looks like I should get back to
Fedora or should I SELinux-ify existing Gentoo GNU/Linux and ArchLinux installations.


Imagine, there’s no INDEX

Filed under: Fun — Tags: , , , , — abbe @ 1548
"Imagine" by John Lennon
Words by: Kirill Ponomarew <krion@FreeBSD.org>

Imagine there's no INDEX
It's easy if you try
It was a hard decision
It should now go and die
Imagine all the people
Building INDEX today...

Imagine there's no ports
Is it so hard to do ?
Nothing to break or fix for
And no GNOME too
Imagine all the people
Fetching INDEX today...

You may say I'm a dreamer
But the hacks must go away
I hope someday you won't break it
And let the downloads rule the day

Imagine there's no cluster
I wonder if you can
Two hundreds ports are broken
Please help us, Uncle Sam
Imagine all the people
Loving INDEX today...

You may say I'm a dreamer
But the hacks must go away
I hope someday you won't break it
And let the downloads rule the day

Copied from http://www.mavetju.org/unix/freebsd-songbook.php#imagine.


Filed under: Uncategorized — abbe @ 1355



bitlbee-otr 1.2.3 update

Filed under: Fun, Hacking — Tags: , , , — abbe @ 0826

I’ve added some fixes to the existing bitlbee-otr tarball related to OTR help. Please update your installation, if you’re not getting help information related to OTR support in your bitlbee-otr installation. Happy IMing off-the-record…:)



Filed under: Fun, Hacking, Yippee!! — Tags: , , , , — abbe @ 1035

/me has pasted "blog.el -- the blog client for posting to wordpress blogs" at http://paste.lisp.org/display/69993
/me has pasted "metaweblog.el -- an emacs lisp library to access metaweblog capable blogs" at http://paste.lisp.org/display/69994

Happy blogging…;)

« Newer PostsOlder Posts »

Create a free website or blog at WordPress.com.