Posts filed under 'programming'

Tagging using the Flickr API

My goal for the day was to geotag the mongage images I uploaded last week. Luckily each image title contains the latitude and longitude of the camera so I extracted the data from the title and added it back in the image tags.

Here is what I did:

  1. Got a Flickr API key and authentication code from the Flickr services website.
  2. Installed Beej’s Python Flickr API.
    1. Downloaded and extracted archive.
    2. Called python setup.py build.
    3. Called python setup.py install.
    4. Edited flickrapi.py to properly call firefox from the Windows command line (added double quotes around the URL in validateFrob).
  3. Wrote a python script to extract the title, parse it, and upload the new tags (I started with the test script Beej provides).
    1. It took a while to realize I needed to include both the method and auth_token parameters for the photo.setLocation and photo.addTags methods.

Add comment June 11, 2007

and relax

The semester is over for me. I spent the last few weeks working on projects and papers but they are done. I still haven’t shaken the stress — or maybe it is just allergies — but my office is clean and I am ready for new projects.

I am currently working on a coding standards document (about which, incidentally, Joel Spolsky just published an article). It is a topic that many have opinions about… but I am only hoping to get a reasonable standard in place for our group so that it can improve over time.

Add comment May 12, 2005

asp.net yuckiness

I just spent two hours yesterday trying to debug an annoying problem with deleting records from an ADO.NET DataSet. I found the solution on jon(e)sie.net. Also, do you think VisualStudio.NET could be any worse for creating HTML pages? It is removing end tags left and right and making it hard for me to create valid HTML pages. As much as I dislike using Dreamweaver… Macromedia figured this out years ago. Hopefully the next version of VS.NET will fix this problem.

Add comment February 9, 2005

quickies

  • Yesterday was quite a long day… but it ended well.

    The end result was the following line of code int exitValue = ((byte) p.exitValue()) & 0xFF; instead of int exitValue = p.exitValue();.

  • If you want to do spell checking using PHP and Aspell you should check out this code and tell me what you think.

    My plan is to make this work via Javascript to enable spell checking of htdig search queries.

Add comment May 21, 2004

snippet : find all email addresses in a text file using python

import sys
import re

thefile = open(sys.argv[1])

emailRegex = """[a-zA-Z0-9_\-\.]+@""" # id
emailRegex += """(?:""" # choose one of the following
emailRegex += """(?:\[?(?:[0-9]{1,3}\.){1,3}[0-9]{1,3}\]?)""" # IP address
emailRegex += """|"""
emailRegex += """(?:(?:[a-zA-Z0-9\-]+\.)+[a-zA-Z]{2,4})""" #domain name
emailRegex += """)"""

for line in thefile:
for address in re.findall(emailRegex, line):
print address
thefile.close()

Add comment March 4, 2004

A speedy algorithm for testing membership in nested ldap groups.

I just spent the better part of the day devising a speedy algorithm for testing if a given user is a member of an LDAP group.

All algorithms that I found while looking around the web looked something like this:

isMember parentGroup, user:
groupQueue.Enqueue parentGroup
while groupQueue is not empty:
currentGroup = groupQueue.Dequeue
if user is in currentGroup:
return true
else:
groupQueue.Enqueue all nested groups of currentGroup
end while
return false

I implemented that solution in C# using System.DirectoryServices and found it to be too slow (taking about 40 seconds to perform a membership test for the highest level group if the result was false). The slowness is the result of the network calls required by ‘all nested groups of currentGroup’ and ‘user is in currentGroup’.

Here is the new algorithm that is much faster (approx .1 seconds regardless of user or group).

isMember parentGroup, user:
// convert users memberships into a filter
SearchFilter = buildGroupSearchFilter(get all users groups)

// perform a subtree search starting from the parentGroup
return null != parentGroup.FindOne(SearchFilter)

buildGroupSearchFilter listOfGroups
filter = “(|”
foreach group in listOfGroups:
filter += “(distinguishedName=” + group + “)”
filter += “)”
return filter
My guess is that this is pretty standard but not posted on the web. It is about time someone did!

update: I thought about it last night and realized that in the above code the definition of the parent is based on a subtree within LDAP. This is not usual definition of parent/child membership for LDAP security. Here is a rough sketch of my newest algorithm which traverses the memberof properties and uses the correct definition:

* get all group the user is an immediate “memberof”
* get the “memberof” property for all the groups you have seen but not expanded (gotten the “memberof” property).
* if no new groups were discovered in the previous step return all the groups that you have seen; otherwise repeat previous step.

If the second step is performed in batches the above algorithm is very fast(approx .07 seconds)… otherwise, if a separate query is issued for each group, it takes 2-5 seconds. Batches can be done in similar fashion to the second algorithm above.

update: I just uploaded source code that implements checking group membership in ActiveDirectory as described in the update above. It is not complete but should be enough to get you started… please let me know if it has any errors.

4 comments January 15, 2004

my first sql server trigger

This took me surprisingly long to figure out…

First create two tables for the test:

CREATE TABLE TriggerTestOne (
  Name varchar 50,
  AdditionalField varchar 50
)


CREATE TABLE TriggerTestTwo (
  Name varchar 50,
  LogEntry varchar 256,
  Action varchar 100
)

Then create the following trigger:

CREATE TRIGGER TestLog ON TriggerTestOne
FOR UPDATE
AS
if update(AdditionalField)
  insert into
    TriggerTestTwo (Action, Name, LogEntry)
    select 'remove', del.Name , del.AdditionalField from deleted del
  insert into
    TriggerTestTwo (Action, Name, LogEntry)
    select 'added', ins.Name , ins.AdditionalField from inserted ins

This will log all values changes in the AdditionalField column in TriggerTestOne into TriggerTestTwo.

The tricky part for me was trying to dig through the manuals to discover the delelted and inserted tables.

2 comments November 17, 2003

in-code documentation for .Net

Add comment October 3, 2003

word death

Some words are just really cool. I really like the word booyah!. I don’t think it is used often enough amongst my co-workers. I plan on changing this so that booyah knowledge does not die forever.

The best part of the word booyah is that you can say it while you are writing code or playing ultimate frisbee.

For example:

* If you just finished debugging some really sick code you could shout “Booyah”! And your cube neighbors would know that you just kicked some ass.

* Imagine that you just made a really good catch… you could turn to your defender and shout “Booyah, I just caught the frisbee!”. Then everyone on the field would know that you mean business.

6 comments September 26, 2003

C# LDAP multi-NT-domain lookup code

Here is a little bit of C# code I wrote that allows LDAP authentication to take place without providing a fully qualified user name… this may be highly implementation specific but I thought someone could use it.

It first maps an unqualified NT username to a fully-qualified NT username (by connecting anonymously to an ActiveDirectory global catalog). It then extracts the distinguished name of the user and parses it to extract the correct domain. This domain is then concatenated with the domain and an authentication request is issued.

update: I have since discovered that there a few bugs in the code… But, I have a new and improved version that I will upload if there is enough demand.

3 comments June 11, 2003

Previous Posts


About me

Hello, I'm Nathan Jacobs and you are looking at my blog. I am a doctoral candidate in Computer Science at Washington University in St. Louis focusing on Computer Vision. My research is in algorithms to improve the ability of computer to reason about the natural world. I also really like to make attractive and informative visualizations of complex data.

I currently update my flickr site much more frequently than this blog.

RSS twitter

Category Cloud

computer vision friend information retrieval information technology knowledge management landscaping machine learning math mozilla noise personal programming research site admin social software teaching travel ultimate frisbee usability web standards

friend

links

papers

Top Posts

Flickr Photos

Smooth

View from Mill Club 405

View from Mill Club 405

Rainbow Sunrise

Why can't I turn left?

More Photos