Translation through Wikipedia

June 9, 2007 – 9:49 am

Here’s a small neat script that I coded yesterday in about 1.5 hours - Wikislate

The script was created to simplify a process that I’ve been using for some time. Being a math&cs student, I’ve acquired the unique mathematical-technical jargon (and I keep doing so).
The problem is that I live and study in Israel - in the Hebrew language. Given the fact that there’s a great English mathematical knowledge-base online (Wolfram is the first website that crosses my mind right now), I had to know the English equivalents of the Hebrew mathematical terms.
The method that I found was to load up the Hebrew Wikipedia page for the term, and then look for the English interwiki link - for the English version of the article.
Most of the time, I only had to read the title of the English page to know I was at the right place.

Yesterday night, after desperately trying to get asleep (my brain suddenly decided to start intensive thinking the night before an exam - took me 2 hours to get asleep) , I came up with the idea to code a quick and simple PHP script that will do the work for me, and act as my scientific terms dictionary. I had some spare ( I decided it was spare ) time, and the above code was the result of a quick coding session. As the code came along, I thought that incorporating Google’s “Did you mean” is a neat feature. So in case a term wasn’t found, it tries the Google search for it, just to get the “Did you mean” line for you :)

I hope other people will find it useful. I might improve it, making it use shiny AJAX and maybe even have a db store the searched terms for autocompletion.
I have the intention to write a bit about how it was done (really fairly simple) - again, if there’s enough interest.

Enjoy, and please comment about it!

Print a Book at Home in 24 Hours

May 22, 2007 – 3:25 pm

This post is being written on the 21st but will be published only tomorrow, the 22nd, the reason will follow.

Today is the birthday of a very good friend of mine ( we’ll call him Y ). He is celebrating together with 2 other friends (A and G) this evening. I’ve spent about 4 hours together with some buddies to try and find gifts, resulting in great presents found for the other 2 guys, but not for Y.

As I arrived back home, the idea just struck me. I decided to make a printed book version of a widely unpopular, fictional blog that he had written together with G. I will not link to the blog in order to keep their identity secret. (Identifying themselves with this blog will make them look quite mad, sick, twisted, and plain stupid).

I was very excited and highly motivated about this project. The time was 16:00. I set down to write a script in perl that will fetch me all the posts from the blog. Perl kept crashing for some reason, so I switched to python. The problem was that this blog (hosted on www.israblog.co.il) was nowhere near valid XHTML, and was lacking advanced RSS syndication (I later found out that there is an RSS feed, but only for the last posts). After 1.5 hours (17:30) I had a working script, using sgmlop - a library for python for SGML parsing (I’m still not sure what it means, but it worked). Only then did I realize, that there could be multiple pages per month. I gave up on trying to figure the number of pages and fetch the posts in each page, and I fell back to the simple method of Copy-Paste. In retrospect, the scripting time could have been used to finish it, If I had used the copy-paste method instead.

After some work (and with some help from a friend), I had all the posts in a Word document, in a chronological order, ready to be printed. Now I only had to figure out how to print it, so that the pages could be folded to form the booklets that form a binded book. As seen in the following illustration ( Notice that being an Hebrew speaker, I printed a right-to-left book, and so is the book in the diagram. For left-to-right, you’ll have to reverse the order ):

a 2 sheets - 8 pages booklet

This is the base “structure” of our book. If you look at the point where the pages are attached to each other, in a hardcover book, you will notice the book is organized into several booklets that are binded together. I got a recommendation to have 5-6 pages (sheets of paper) from Here , but I ended up working with 7-pages booklets. Each sheet of paper is printed with 2 pages, on both sides, in landscape orientation.

In order to print those booklets ( the sample 2 sheets one in the diagram ) the pages have to be ordered as follows (again, for right-to-left books):

  • first page - first side: A | H
  • first page - second side: G | B
  • second page - first side: C | F
  • second page - second side: E | D

I knew most of the above at this point, but I had no idea about how I’m going to achieve this goal.

Then, a guy named Stephen, from Canada - who has been my team leader in two HL2 mod projects :Shock and Price of Peace - said ‘Hi’ on MSN. It turns out that he is some extreme Word guru, and that he had some free time (and, well, that he just couldn’t miss the opportunity to share his knowledge :P) so he decided to help me.

Our first approach was to use “Columns”. Found under the “Format” menu, it’s a neat feature that let you format your document into columns. The idea was that each page will have 2 columns, that will represent the pages in the booklet, and that the page will fold in between them. We discussed this option a bit, and I started my work. It basically consisted of having 2 open documents at a time - the original and the columned - and having to mix and match, using copy-paste, the different pages from the original, into the appropriate columns. It was certainly doable, but at the same time a nightmare, prone to errors and limits further editing.

Stephen then had an epiphany - he introduced me to a very cool feature in word called textbox linking. Apparently, it is possible to link two (or more) textboxes - in a certain order - so that when the text entered to the first textbox exceeds the textbox’s space, it flows into the next textbox in order. He sent me a file aptly named “Ben is so lucky to have me.doc” - I sure was. The file consisted of two large textboxes, set in a landscape oriented page, with equal margins etc.

From there, I’ve create my 7 pages booklet “template” [Edit - I thought that I should post a sample template , so here it is (left-to-right version) - click me], using linked textboxes, ordered as explained above. Now, all that was left was to paste the original document inside the first textbox, cut everything after the last line on the last textbox (it’s the rest of the document that won’t fit in the current booklet), print, and repeat.

The time was about 21:30, and I had started to make several print attempts.
1am.jpg

As seen in the picture, by 1:00AM I had 3 booklets printed and arranged.
230am.jpg

2:25AM, stitching the booklets together, using the method explained in Here with some improvisation.
3am.jpg

3:05AM - all done stitching, applied some glue over the stitches using improvised clamps. One hour left for the 12 hours mark - and I went to sleep :) . Well, I cheated on the title - it took a bit more than 24 Hours because you have to wait for the glue to dry. However, I think that now I can cut most of the time that went into research and printing failures, and meet the 24 hours limit.

Got up at 10:15AM - by now the glue has mostly dried, and we have a perfect (in first-time DIY scale…) cover-less book !

Time to create the cover. I cut three pieces of cardboard (not sure if that’s the right term, only familiar with the Hebrew name for it), two 16cm x 22cm for the sides and one 1.5cm x 22cm for the spine. I connected them using electric tape (that’s what I had around), the result :

cover.jpg

Finally, applied glue to the cover and the spine, and let dry between two heavy books (with some metal parts on the stitched booklets, pushing them downwards):

1120.jpg

It’s 11:20AM, so that’s 12 hours + 5 minutes. Now we just have to wait for the glue to dry, and then maybe decorate the cover.

At 16:00 - 24 hours mark - the glue was not fully dried, but I had to leave the house, and it was not only until around 22:00 that I had to deliver the present. So yes, not really 24 hours, as stated above, but it can be done in 24 hours !

I aimed (yeah right) for an underground look and feel, so I was ok with the cardboard and electric tape cover, but for the next time I’ll try to achieve higher quality (by covering it with some decorative paper etc). I’d also leave two empty pages, at the beginning and the end, to glue to the cover in order to secure the cover better, and hide the internal spine.

Anyway, I’ve linked to the sites that helped me, here are my thanks. I also greatly thank Stephen who really saved me. This post is getting way too long and unfocused, so if I find anything missing or not detailed enough, I’ll post a follow-up.

I can just tell you that the gift was a success , and that the cover fell off :(. It says on the cover of my glue ( I used carpenter’s glue, figured that both paper and cardboard are made of wood :P guess I should have used PVC glue ) that it takes 12-24 to completely dry, well, that’s a lesson for next time.

Ben

So…

May 18, 2007 – 10:36 pm

Yeah, well, it’s my blog. Hi.

So, hmm, basically, I’m not really that much of a writer. I think I just started this blog because it happens to me quite often that when I search stuff on google, I find useful information on personal blogs, of all places. Solutions to coding problems (yes, I’m a coder) , interesting reviews and recommendations, and articles.

I thought that I should give back to the web, publish more code that I write, and help others with problems that I have solved. The hosting plan and domain were purchased about 2 months ago, and only now I write my first post, well, I’m a busy man XD

There’s more to come next. I don’t want to put too much effort to the first posts, as there’s a high chance that I will abandon this blog quickly, and no one will ever read them.

Anyway, I’ll post something small and quick that I had coded some days ago in 10 minutes.

Some weeks ago I’ve been contacted by an online buddy to whom I didn’t speak in 2 or 3 years. It was a period during which I was highly enthusiastic about 3d and animation, and he was one of the experts in the forum where I used to “hang” :P . The short conversation with him inspired me to do some 3d modeling, and I came up with something (quite lame) for a quick modeling challenge in some forum.

So, I had a time limit, and I wanted to keep measure of time as I was modeling. The right thing to do was certainly to program a stopwatch in python using pygame ! I’ll just post the code now, and will look for a code highlighting plug-in for wordpress later.

import pygame,pygame.font
from pygame.locals import *
 
#yuck, global vars ^_^
font=None
surface=None
time=[0,0,0] # an array to keep the current time measurement which is being rendered
start_state=[0,0,0] #the time measurement from which to start counting
start_tick=0 # the number of ticks when we began counting
on=False #wheter the stopwatch should be running or not
 
def main():
    global font,surface,on
 
    video_flags = DOUBLEBUF
    pygame.init() #initialize pygame
    surface = pygame.display.set_mode((200,100), video_flags) #create our main window SDL surface
    surface.fill((255,255,255)) #fill with white
 
    font = pygame.font.Font('INK2SCRI.TTF',60) #load up a ttf font
    last_tick = pygame.time.get_ticks()	# initialize the tick count
 
    while 1: #do forever
        event = pygame.event.poll()
        if event.type == QUIT:
            break
        if event.type == KEYUP and event.key==32: # if the space bar was pushed
            if(on): # if currently running
                #prepare start_state for future use, save current time
                start_state[2] = time[2]
                start_state[1] = time[1]
                start_state[0] = time[0]
            else:
                #starting the timer, so set the tick count reference to the current tick count
                start_tick = pygame.time.get_ticks()
 
            on = not on #toggle on
 
        if(on):
            a = (pygame.time.get_ticks() - start_tick) # get the amount of ticks(miliseconds) that passed from when the stopwatch was last run
 
            time[2] = start_state[2]+ (a / 1000) % 60 #seconds
            time[1] = start_state[1]+((a / 1000) / 60 % 60) #minutes
            time[0] = start_state[0]+(a / 1000) / 3600 #hours
 
        draw()
 
        pygame.display.flip()
 
def draw():
    global surface,font
 
#render the time, by converting each array member to a string, and concating with ':' in between time components. render in black on a white background.
    tempsurface=font.render(str(time[0])+':'+str(time[1])+':'+str(time[2]),1,(0,0,0),(255,255,255))
 
    surface.fill((255,255,255)) #fill the screen with white, to erase the previous time
    surface.blit(tempsurface,(10,10)) # blit the temporary surface to the screen
 
if(__name__=='__main__'):
    main()

Check out the screenshot:

screen.PNG

And here’s the model that I used it for:

Hook

I’m happy to finally start this blog, hope I will manage to keep writing, and that people will actually read it some time in the future.

Ben.