Wide Blog Theme

Python and PDF xref check

Grab the xref table from a PDF file, save it to a text file. Use it as input to find all the objects in a PDF.

#!/usr/bin/env python __author__ = 'Meaux' __version__ = '0.1' __date__ = '2009/08/19' import fileinput import re f = open('duckypdf', 'rb') fx = open('xreflist.txt') objectlist = [] for line in fx:     l = line         f.seek(int(line), 0)     pf = open('working_out.txt', 'w')     objItem = f.read(10) + " " + line + "\n"     objectlist.append(objItem) for objItem in objectlist:        pf.write(objItem)

First attempts with Python

Script to rip through a PDF file to see if the objects match the object references and pop out the number of the object(s) that have no match:

#!/usr/bin/env python __author__ = 'Meaux' __version__ = '0.1' __date__ = '2009/08/19' import fileinput import re objectlist = [] subNumObjList = [] subRList = [] f = open('ducky.pdf', 'rb') pf = open('listObjects_out_bad_750_350_X2.txt', 'w') for line in f:     reObjItems = re.compile(r"[0-9]*\s\d\s\obj")     result = reObjItems.finditer(line)     for item in result:         objString = item.group(0)         objString = re.findall(r"(\d+)\s*0", objString)         subNumObjList.append(int(objString[0])) f.seek(0) subNumObjList.append(999999) subRList.append(99999999) for rLine in f:                  reRItems = re.compile(r"[0-9]*\s\d\s\R")     rResult = reRItems.finditer(rLine)         for rItem in rResult:         rString = rItem.group(0)         rString = re.findall(r"(\d+)\s*0", rString)         subRList.append(int(rString[0]))       print subRList print subNumObjList d = {} for x in subRList:     d[x] = 0         for x in subNumObjList:         if d.has_key(x):             del d[x]             #print d.keys() print d           f.close()

Flash demo of work I’ve done

A previous employer created a flash demo of a web site I created for them. It is a database driven HR site with CRM capabilities. Every customer wanted a customized view to show their employees so the web pages are all dynamically generated (C#/.NET) from a database with their data and view permissions based on roles.
Solverdemo

tetris math

I’ve started creating a C# tetris game with a math quiz variant. You let the bricks fall just like ordinary tetris, but each has a number. Depending on the level, you may have to add, subtract, multiply, divide the numbers on the bricks. Like tetris, the blocks fall, and if you complete a row across, the numbers show and you gain points by completing a mathematical operation on that row. If you give a wrong answer, the row doesn’t disappear. Here is a similar concept: education-oriented tetris

Here is my “square” type so far. Now I have to figure out how to randomly assign them numbers to be used in the math question, draw the number on it with a font. I am using GDI+ library - more research on it necessary to get it done…
(more…)

t-sql search and replace on text columns

I needed to replace the email address across several tables and rows. It was buried in various strings and mostly in columns of type text. The t-sql replace function doesn’t work on text columns. The script found in this link didn’t work for me because it only finds the first occurrence of the substring (sqlteam search and replace using cursor).
(more…)

Wide Blog Theme