Merging PDF Files Using Ghostscript

If you have to merge PDF files, you need no other than Ghostscript (which is installed by default with many Linux distributions). Here's the command line:

gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=firstANDsecond.pdf -dBATCH first.pdf second.pdf

pdf
ghostscript
tips

PySWIP: Facts and Rules

PySWIP is a Python module which enables accessing SWI-Prolog's foreign language interface using our beloved computer language. Here's a small tutorial on adding facts and rules to prolog knowledgebase.

First, adding facts and rules, based on examples in a Prolog tutorial.

from pyswip import Prolog
p = Prolog()

# something ...

python
prolog
pyswip

Getting the Currently Playing Song Info on Amarok via DCOP

Here's a sample application for using DCOP with Python. Needed to install python-dcop on Debian. It works on KDE 3.5 with Amarok 1.4 (won't work on KDE 4)

import pydcop

playerService = pydcop.DCOPObject('amarok', 'player')

d = dict(
   title=playerService.title(),
   artist=playerService.artist(),
   album=playerService.album ...

python
DCOP
amarok
KDE

Ctypes Strings

I've written bulk of PySWIP last summer, it is based on Nathan Denny's proolog.py. This is the first project that I used ctypes, a fantastic package which allows calling C functions from dynamic libraries that I use to link libpl.so (Linux) or libpl.dll (Windows) of ...

python
ctypes
prolog
pyswip

SEND + MORE = MONEY

Finding valid and distinct integers for digits S, E, N, D, M, O, R and Y in the equation SEND + MORE = MONEY is a classical constraint programming problem. Here's the slightly modified version of the sample program at Wikipedia constraint programming entry for SWI-Prolog using clp library:

:- use_module(library ...

send more money
sendmory
constraint programming
prolog

Shameful Past

A few hours ago, when I was dealing with my thesis, I've come up with a Python function that constructs a tour for a given TSP instance using the nearest neighbor heuristic:

def nearestneighbor(size, dists):
   tour = [0]*size
   candy = [True]*size
   candy[0] = False

   for i in range ...

python
nearest neighbor

Freeeze for Marvin3

Today, I added a keyword called freeze to Marvin3. Basically, when called inside a routine, it pops the top element from the stack and replaces routine's code with a word that pushes that value onto the stack. This way we can create a write-once routine, which is similar to ...

marvin3

99 Bottles of Beer in Marvin3

How to write 99 bottles of beer in Marvin3?

:bottles dup dup 1 > [" bottles"] [" bottle"] ifte cat ;

:sing
    bottles dup " of beer on the wall," cat println
    " of beer. " cat println
    "Take one down, pass it around." println ;

:theend  "No more beer left." println ;

:beers  [dup 0 >] [sing decr] while ...

marvin3
marvin
99 bottles

Marvin3 is launched

Marvin3 is a new cross-platform stack-based language developed in Python. Marvin3 features object-oriented-programming, anonymous routines, eager lists, variables, lexical scope, combinators and support for modules.

This is from my Marvin3 project home. Marvin has evolved into Marvin3 and is becoming ready to be tried by the audience. In order to ...

marvin3
marvin

Ubuntu is Great

Last week, I received 20 (1 install + 1 live) Ubuntu Linux 5.04 (Hoary Hedgehog) CDs FOR FREE (details will follow). Of course in no time I installed it. I have to say that Hoary rocks! I was using Warthy before, and this new release fixes the few problems Warthy ...

ubuntu
hoary hedgehog
linux
FOSS