Showing posts with label script. Show all posts
Showing posts with label script. Show all posts

Tuesday, December 19, 2006

When debugging firefox bookmark javascript, I found myself always concatenate multiple line javascript code into one line.

Here is the shell script to redirect it to a local file, where the "notepad" kicks in and automatically load it.
js_merger.py bookmark.js  bookmark.txt  notepad bookmark.txt

And here is the code to automatically do this:
import sys
if len(sys.argv)!=2:
print "Usage: js_merger.py {file.js}"
else:
l = open(sys.argv[1]).readlines()
print "javascript:(function(){" + ' '.join([i.strip() for i in l]) + "})();"


Wednesday, December 13, 2006

"""

Synchronize FireFox 2.0 and Microsoft Dictionaries
Author: Alex Dong
Email: $ python -c "'YWxleC5kb25nQGdtYWlsLmNvbQ==\n'.decode('base64')
Blog: http://thetruelight.blogspot.com/
License: GPL
ReadMe:
Please change the 'word_dict_path' and 'ff_dict_path' to point
them to your local directories.
"""

word_dict_path = 'c:/Documents and Settings/adong/Application Data/Microsoft/Proof/custom.dic'
ff_dict_path = 'C:/Documents and Settings/adong/Application Data/Mozilla/Firefox/Profiles/yl9sxfvv.default/persdict.dat'
wd = open(word_dict_path).readlines()
fd = open(ff_dict_path).readlines()

def merge(a, b):
c = [i for i in a]
for i in b:
if c.count(i)==0: c.append(i)
return c

l = merge(wd, fd)
l.sort()

def update(f, l):
fp = open(f, 'w')
fp.writelines(l)
fp.close()
update(word_dict_path, l)
update(ff_dict_path, l)

print "Updated %d entries"%((len(l)-len(wd)) + (len(l)-len(fd)))