Annoying @smarx

Steve Marx posted – http://blog.smarx.com/posts/annoy-smarx-com-letting-the-internet-choose-my-wallpaper , I needed to get my mind off clear present boredom. Gnutools (http://gnuwin32.sourceforge.net/packages.html) helped a lot.

To annoy @smarx – I needed to get all the “references” to the image so that I could do a simple get on them.  I followed following

Get the url content.

1. curl -o http://bit.ly/aENgVz > page2.txt

Get all https references

2. grep -o “[']https://[^[:space:]]*['$]” page2.txt > links2.txt

Remove all references to quotes

3. sed s/’//g links2.txt > links3.txt

Remove non essential urls

4.find “SetWallpaper” links3.txt > cleaned.txt

Just get them all

5. wget – wget –no-check-certificate -i cleaned.txt

Another idea was to really annoy smarx by creating vsts webscript  which I could keep executing till cows came home.

The only challenge that I saw was VSTS was doing request for ticket from servicebus etc…which I thought was not really required in this case.

WebTestRequest request5 = new WebTestRequest("https://urs.microsoft.com/urs.asmx");
request5.ThinkTime = 12;
request5.Method = "POST";
request5.Headers.Add(new WebTestRequestHeader("SOAPAction", "\"http://Microsoft.STS.STSWeb/RepLookup\""));
request5.QueryStringParameters.Add("MSURS-Client-Key", "WY4Moa9cz7fn1iOp5HVkPQ%3d%3d", false, false);
request5.QueryStringParameters.Add("MSURS-Patented-Lock", "N2kJLJI9LH4%3d", false, false);
StringHttpBody request5Body = new StringHttpBody();
request5Body.ContentType = "text/xml; charset=utf-8";
request5Body.InsertByteOrderMark = false;
request5Body.BodyString = @"<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soapenc=""http://schemas.xmlsoap.org/soap/encoding/""><soap:Body><RepLookup xmlns=""http://Microsoft.STS.STSWeb/""><G>{2CEDBFBC-DBA8-43AA-B1FD-CC8E6316E3E2}</G><O>{6C2BDA4A-56C4-4105-9634-3EEB51D49562}</O><P>{AAE07637-72AE-4759-AA9C-128BA0B99828}</P><D>8.0.6001.9</D><C>8.00.6001.18669</C><S>6.1.7600.0.0</S><I>8.0.7600.16385</I><L>en-US</L><R xmlns:q1=""http://Microsoft.STS.STSWeb/"" soapenc:arrayType=""q1:Rq[1]""><Rq><T>URL</T><R>https://annoysmarx.servicebus.windows.net/annoysmarx/setwallpaper?id=fc8a2ecf-d0be-4257-83fd-ae4ffe14064d</R><O>POST</O><W>FRAME</W></Rq></R></RepLookup></soap:Body></soap:Envelope>";
request5.Body = request5Body;
yield return request5;

Now to the F#’s famous |> operator, that should be quick.

Chrome extension on lazy evening

With Deepak’s instigation finally I moved one of my greasemonkey scrips to Chrome as an extension. This will be the trial period for chrome through the new year eve as earlier experience was not very great on memory footprint.

Pros of chrome extension

1. Setup – The extension setup is a breeze, create a directory, add manifest and supporting html/js/image files. Point Chrome to it and you are done. Firefox and other browsers require an explicit restart. Chrome also integrates all the “configuration” information of extension in one place, making it simpler for developer to “get it” compared to multiple file approach of Firefox.

2. Control over “interaction” – Chrome uses HTML 5 localstorage for storage. Very explicit declarative interaction with browser sandbox is defined. Communication between frames in Chrome is using a new feature of HTML5 called postMessage. One thing I needed was “way to look into localstorage contents”-I ended up using cmdline – but a debugging box on right would be neat.

3. Sandbox restrictions are explicit but little rough and would prefer more declarative approach of what is possible and not a good practice.

4. Automatic configurable updates vs update on restart for FF is neat but imho way too hacky.

Cons of Chrome Extension  -

1.  Deeper interaction apart from adding buttons to toolbar(browser interaction), greasemonkey’ish stuff(page actions) and themes is really “terse”.

2.  My “expand-text-when-rolled-over” jquery code refused to work in popup.html.Images of  png format refused to animate in popup.html

Conclusion – good 2 hours spent. Mozilla’s Jetpack is on horizon so keep options open :) .  Speed Tracer is a good thing to have on chrome. FF’s AdblockPlus and FireGestures are way ahead at present for chrome counterparts. Way to backup/restore associated extension is again something which Chrome needs to get right(I have not had time to look into associated google group postings to verify).

Update – (29/12/2009) – Chrome extension store is less organized than FF and also less “open” like Apple ‘s infamous app store’s challenges for developers.

Update-(30-12-2009)-Chrome browser throws up errors while parsing rss from http://news.ycombinator.com/rss

RSS-interpretation error for chrome resulting in head tag getting modified

I bypassed the simple code(string.find(“something).each..) and had to go “find”+”addToArray”+”retrieve it later” way.

Reddit on other hand is providing valid rss.

Just a reader, no comments/login etc

02/01/2010-Once posted this query to chrome-extensions group – one gentleman – phistuck helped me verify that it is the problem of feed from ycombinator, which is resulting in the problem I am seeing. (head tag getting modified). He also shared a tip to look @ headers and raw response – A look at chrome://net-internals/view-cache/http://news.ycombinator.com/rss after visiting http://news.ycombinator.com/rss proved the fact that ycombinator is providing bad response.

Batteries included has strong resonance

Gems of Python

Requirement – Find out immediately if the files are different and then point out the differences.

Solution – use – filecmp.cmp and then  difflib.ndiff. This is great for small size file.

a. filecmp.cmp(file1,file2,shallow=False))

b.
x = file1.readlines(); file1.close()
z = file2.readlines(); file2.close()

for line in difflib.ndiff(x,z):
if line.startswith(“+”) or line.startswith(“-”):
print(line)
2. Returning of multiple pieces of information.

Solution – use the return intuitively.

return 1, numfiles, thequeue  # just magic.

so at other side

status, numfilesprocessed,listprocessedfiles = funcname(params)

does the work.

3. Requirement : Working over two ordered lists

Solution – Use Zip.

for r, s in zip (vernaqueue,engqueue):
if False ==  (filecmp.cmp(r,s,shallow=False)):
fcompare(r, s,exfile)

4. Requirement – get list of lowercased complete filenames  of particular kind in a simple way

Solution : Sheer magic of list comprehension then move on to generators

extlist        = [".mdb"]

location     = “some directory”

filelist        = (os.path.normcase(f) for f in os.listdir(location)) # map functionality

filelist        = (os.path.join(location,f) for f in filelist if os.path.splitext(f)[1] in extlist)