Wednesday, August 27. 2008Why I Don't Like gitI've got some code checked out with git-svn, and I'd like to do two things: pull in new revisions and push up my local revisions. Pretty simple, brainless, thing, right? But we're dealing with git, so of course not
# Fortunately I'm smart enough to remember that when you
# want to push changes to SVN, you've obviously got to use:
$ git-svn dcommit
...
$
# Hurra! It worked! (at least I think...)
# Now for the next feat, pulling in more revisions...
$ git svn
...
fetch Download new revisions from SVN
...
# Phew! That looks like exactly what I need... Maybe it's not so tricky after all!
$ git svn fetch
A basie/a3c/admin.py
r13 = 45f5309121a77f33f8bd87009671727c0e2dc4a5 (zuze)
# Sweet! Now I can take a look at what has been changed
$ cat basie/a3c/admin.py
cat: basie/a3c/admin.py: No such file or directory
# Hu? I thought I just fetched it...
# Crap, right! I'm NOT supposed to use fetch, I'm supposed to use 'rebase'
# (not, of course, that I understand why "pulling in new revisions from SVN
# is equivilent to a mung-your-history-rebase... But that's ok, I guess)
$ git svn rebase
...
$ cat basie/a3c/admin.py
cat: basie/a3c/admin.py: No such file or directory
# Blast. That didn't work either.
# Right, that's because 'fetch' updates the git repository but not the
# working tree... Alright, let's try an update
$ git up
git: 'up' is not a git-command. See 'git --help'.
# Crap, right, git is too cool to have 'update'... I think I need reset
$ git reset
docs/cmdline.wiki: needs update
# hhmm... Why is it telling me that the files I edited need update?
# And how on earth do I update them?
# I give up
I guess I'll go back to Bazaar... It may be slow as molasses on a cold day, but at least it is simple enough that mere mortals can use it without resorting to Google. Thursday, May 29. 2008Python Brain-TeaserI'm working on pulling some functionality out of one object and putting it in another, and I came across this interesting problem: class Foo:
me = "foo"
class Bar:
me = "bar"
def get_me(self):
return self.me
Foo.get_me = Bar.get_me
x = Foo()
print x.get_me() What does this print? And, next question, why is that? After lunch I'll post my thoughts Continue reading "Python Brain-Teaser" Saturday, May 17. 2008SSH Connection SharingThis tip was originally posted to the python-dev mailing list, so I can't take one scrap of credit for it. Basically, since OpenSSH4, there has been an option to share connections -- that is, once you've opened one connection to a host, every subsequent connection is tunneled through the same channel, completely removing the overhead of authentication! It's quite simple, just add this to
There can be problems if your machine crashes and that file is left lying around... So adding this to your crontab will fix that:
Next time: tab completion with scp! Tuesday, May 6. 2008SVK + Unicode == :(I was not impressed when I tried to check out a UTF-8 encoded file with SVK, then got the helpful message
I was even less impressed when I searched Google for svk unicode and this blog was the first hit. Fortunately my Google-foo is high today, and I was able to find a page that gives a solution: Making sure that your locale is set to something similar to On Debian, here's how I do it:
And, of course, it may be good to put those two Oh, but wait!
It still doesn't work! It turns out that, for what ever reason, something was upset. Eventually I got it working by deleting the offending directory, then using
Hurra! Thursday, May 1. 2008Encoding and Decoding Text in Python (or: "I didn't ask you to use the 'ascii' codec!")When dealing with Unicode in Python, it doesn't take long to get the dreaded You never see it coming. It doesn't make any sense. You didn't even ask for So what's the deal? I'm glad you asked. I will demonstrate:
If you guessed that Now, if we want to do anything useful with this data, it needs to be decoded:
We have just taken an encoded hunk of data and decoded it to get a useful hunk of data.
Now we can take that useful hunk of data (the English in 7-bit ASCII), do something useful with it (in this case, replace 'world' with 'Marguerite'), and finally encode the data. So how does all this relate back to Unicode and ascii error messages? I have used base64 encoded data here, but the same concept applies when dealing with Unicode data:
(of course, in the Real World, you've got to figure out which encoding was used on the data (UTF-8, Latin1, etc)... But that's a topic for another post.) Ok, back to the I know what you're saying, "but I never asked Python to decode anything! I'm just trying to turn it into unicode!"
Two questions arise here: First, "Where is the 'ascii' coming from?" Second, "How do I make it work?" To answer the first question, it's important to think about what's happening when the call to So how can you make it work? Tell
(now, as I mentioned before, figuring out which encoding to use is another huge problem... But I'll leave that for another day) Another problem I run into quite often is this:
And, by now, the cause of this should be painfully obvious: I've given Python an encoded string, so I should be decoding it, not encoding it again. But why the confusing error message? Well, I'm not entirely sure, but my guess is that the UTF-8 encoder expects a Is there any end to this insanity?!Yes! Python 3000 will have two distinct classes: one for strings, one for hunks of data. Whenever data is read, it will come in as a "hunk of data". It will have to be explicitly decoded to a string before it can be used as such. Hopefully that will make life a little bit less painful. See also:Wednesday, April 16. 2008Another reason I like SVKI got a fairly significant patch to DrProject today. I wanted to show it to the other developers so they could give it a look over. How'd I do it?
$ patch -p0 < patch
... check that it works ...
# Create a new branch for the patch
$ svk cp //drp/trunk //drp/branches/patch -m "Created branch for patch"
# Do an in-place switch of my repository (which takes about 2 seconds,
# versus the minute or two it would take to check the entire tree out)
$ svk switch //drp/branches/patch
# Because switch doesn't revert modified files, the changes are still here,
# ready to be checked in
$ svk ci -m "Checking in patched code"
Now they can use DrProject's fancy online changeset viewer, checkout the code for themselves, use Now that rocks SO much more than mailing around Friday, April 11. 2008SSH and HTTPS on the same port?!A friend of mine was over the other night, and we were talking about how much we like running SSH on port 443. It gets you around all but the most insane firewalls, and to anyone but the keenest of observers it just looks like HTTPS traffic. But running SSH over port 443 makes it particularly difficult to run a secure web server as well. So what can be done? Well, it turns out that when an SSH client initiates a connection, it waits for the server to send a banner ( Knowing this, it didn't take long to formulate a plan: write a little program which will listen on 443. When it gets a connection, it figures out if the remote end is trying to speak SSH or HTTPS, makes the appropriate connection on the local end, the passes the data between the two. It only took a couple of hours to write a small proof-of-concept... And, believe it or not, it even works! Disclaimer: this particular implementation is not quite suitable for any real use. Anyway, this may not be the most efficient way of doing things... But that's no matter. It's still neat Code: sstp.py Friday, April 4. 2008How SVK has made my life happySVK, despite some of it's shortcomings, has proved worthy of my use in the last couple of days. Here is a quick script which shows how I've been using it, and how it's rocked the pants off of SVN: red = commands with SVN
# Mirror the DrP repository to //dpr
$ # No equivilent
$ svk mirror https://drproject.org/drproject/DrProject/ //drp/
# Create the tags branch
$ svn cp https://drproject.org/drproject/DrProject/tunk \
https://drproject.org/drproject/DrProject/branches/tags
$ svk cp //drp/trunk //drp/branches/tags
# Check out the branch
$ svn co https://drproject.org/drproject/DrProject/branches/tags Tags
$ svk co //drp/branches/tags Tags
# Some changes are made to the tags branch
# Checkin those changes
$ svn ci -m "Made some changes to tags branch"
$ svk ci -m "Made some changes to tags branch"
# In this case, SVK is not being used in decentralized
# mode, so the changes will be pushed upstream to the
# SVN repository, just like the svn commit does.
# Changes have also been made to trunk.
# Time to merge those changes in.
# First, a merge with SVN:
$ svn log --stop-on-copy
# Look for either the last revision which trunk was merged
# You can't always use the base revision, otherwise conflicts
# may ensue.
$ svn merge -r $REV:HEAD https://drproject.org/drproject/DrProject/tunk .
# Hope that there are no trivial conflicts to sort out,
# then test and commit the merge.
$ svn ci -m "Merged trunk into tags."
# And now, exactly the same operation with SVK:
$ svk pull
# ... changes are merged ...
$
I don't think I need to say any more (Yes, I realize that there are tools like svnmerge.py which make SVN merges less painful... But that's one extra command to run. And you've still got those stinking .svn directories everywhere.) Continue reading "How SVK has made my life happy" Sunday, March 16. 2008Conditionally Sourcing vimrc filesI'm sitting in a tutorial at PyCon1 on hacking the Python core. One of the things that was mentioned is Python's coding standards, and their supporting Vim scripts. I've got no complaints with them -- I just don't want to use them all the time. So I've added this bit of code to
In short, if it looks like I'm in the Python-trunk directory, it sources their vimrc 1: Blog posts to come... I promise! Friday, February 8. 2008Reverting Changes in SVN (or: it's not as easy as svn up -r)If there is one thing that I've found universally confusing about version control systems, it's how to revert back to a previous revision, then move on from there. Conventional wisdom would dictate that So, besides The trick is that you can
[wolever@thebes] ~/test_dr/All svn diff -r 2:1
Index: stuff
===================================================================
--- stuff (revision 2)
+++ stuff (revision 1)
@@ -1,4 +1,3 @@
Let us endeavor so to live that when we come to die even the undertaker will be
sorry.
-- Mark Twain, "Pudd'nhead Wilson's Calendar"
-Increased knowledge will help you now. Have mate's phone bugged.
Index: docs.html
Which means that merge will work both ways as well: [wolever@thebes] ~/test_dr/All svn merge -r 2:1 stuff U stuff [wolever@thebes] ~/test_dr/All svn ci -m "reverted changes" stuff [wolever@thebes] ~/test_dr/All svn diff -r 1:3 stuff [wolever@thebes] ~/test_dr/All Of course, this will also work with the myriad of other version control tools out there. In fact, if you're still using SVN, reverting old changes is probably the least of your problems... At least compared to, say, merging different branches ^_^ But that's a post for another day -- I need to stop writing about merging and actually get on with, err, doing it... Saturday, December 15. 2007How I keep all my config files under version controlAh, a Saturday morning that I should spend studying for my exam on Wednesday... What better thing to do than get all my important config files under version control? Executive summaryTo get all my config files under version control, I:
So, the problem: I use three machines on a regular basis (my laptop, my server, my computer at work). I want to keep all my important config files in sync (ie: Bazaar and Vim). I'd also like to keep them under version control (version control is a good thing, right?) Can both happen at once? Well, with the magic of The first step was to collect everything into one place. I moved the files I'm going to care about (in this case, The next step was replacing the old config files with links to the new (versioned) ones. That was nothing a simple shell script couldn't solve, though (take a look at install_links.sh if you're interested in now it works). Beautiful. Everything is versioned, I've just got to distribute it. Bazaar (and just about every other distributed VCS out there) has some wonderful facilities to push/pull it's repositories. All it took was a quick $ ssh wolever.net $ cd .config $ bzr co . $ ./install_links Finally, I put a link to the repository in a web-facing directory (http://wolever.net/~wolever/conf) so I could grab it from my work machine using And that's all there is to it Friday, November 2. 2007College Puzzle Challenge 2007 Pre-Event Puzzles #3Following College Puzzle Challenge 2007 Pre-Event Puzzles #2, it is time for puzzle #3, Rotation Schedule. This was a fun little puzzle with codes on codes that reminded us of a problem from 2006 IPSC Contest called Matrioska (which are those Russian doll things that fit inside each other). The IPSC problem involved decoding the first puzzle or program who's output was another puzzle itself. This Puzzle Challenge one starts off with a page of Pigpen cipher symbols. Decoding these symbols gives the following sequence of letters: ROTTHR EEURWD WHGQLQ HWBFOR FNZLVH STVQJQ HNECYS USLZEI 'ROT THREE ... <gibberish>' Now ROT-13 refers to a Caeser Cipher with a shift of 13, so ROT-3 is a shift of three letters instead. Since we are decoding, we actually want to undo the rotation which is done by rotating forward by 23 (which is 26 letters - 3). David found a simple online shifter here (although it is a very easy task in nearly any programming language) which we used. Deciphering the remaining letters in the string we end up with: ****** **ROTA TEDNIN ETYCLO CKWISE PQSNGN EKBZVP RPIWBF This time the clue is 'ROTATED NINETY CLOCKWISE ... <gibberish>'. At this point David started looking into trying things like ROT-(90 modulo 26), and I decided the clue referred to geometry and tried to figure out ways of rotating the pigpen symbols. ****** ****** ****** ****** ****** ROTNIN EMDYUR LRCXDB Similar to before, 'ROT NINE ... <gibberish>'. Undoing the ROT-9 we end up with: ****** ****** ****** ****** ****** ****** *DUPLI CITOUS My final answer: DUPLICITOUS This is enough procrastinating for one day... Ted, out. College Puzzle Challenge 2007 Pre-Event Puzzles #2Continuing the post College Puzzle Challenge 2007 Pre-Event Puzzles #1, I'd like to briefly describe our answer to the second puzzle, A Heartbreaking Work of Lyrical Genius. This puzzle took us the longest time to do, but I think most of that was due to the fact I did the research wrong (yep, my fault this time). The first difference we noticed we looked at this puzzle was there was no intro paragraph full of clues this time. Just a list of lyrics. We quickly recognized these were real songs and went to find what they were. Unfortunately I managed to swap a few of the band names and song names (I blame confusing lyrics websites). After a few days of getting nowhere, we discovered the errors and corrected them. Now with the correct list and a fresh look we noticed a pattern in the song list.
Scar Tissue - Red Hot Chili Peppers
Lose Yourself - Eminem
Freebird - Lynard Skynard
React - Erick Sermon
The Adventure - Angels and Airwaves
Truely Madly Deeply - Savage Garden
Dirty Little Girl - Elton John
Lights and Sounds - Yellowcard
Blue - Eiffel 65
Skater Boy - Avril Lavigne
Losing My Religion - R.E.M.
Beach Side Property - Modest Mouse
Like Satellites - Over It
Blasphemous Rumours - Depeche Mode
Head Club - Taking Back Sunday
Wild West Hero - Electric Light Orchestra
Living in the Roses - New Model Army
Much better. RELEASE YEAR MOD TEN. Our first explicit clue. From here on it was straight forward. Look up the release years on songs using Wikipedia and Last.FM and taking the last digit from the year (year mod 10), we get a new number for each line. Number n meant use the n-th word from the given lyrics to form a new phrase. We had to fudge the release years a bit to make sense but we ended up with 'I WAS A MEMBER OF THE POLICE AND I WROTE AND SANG THE HIT SONG DESERT ROSE'. An issue that bugged Dave while we struggled with the wrong clues was that there were only 16 words at the bottom but 17 songs. In the end, it seemed this was just a mistake as the word that slipped through was 'I' and was probably accidentally forgotten. More searching resulted in finding that the artist was Sting. Another problem solved. These problems are addicted and frustrating at times, but looking back this one wasn't too difficult if we had gotten the research right at first. My final answer: STING College Puzzle Challenge 2007 Pre-Event Puzzles #1![]() Puzzle Challenge 2007 Logo Well, the College Puzzle Challenge hosted by Microsoft is coming up again and David, Pete, Greg, and I are signed up as a team. We were at the event last year for the first and didn't do as well as we hoped (we were in the middle of the pack overall) and we plan to change that this year. There are a few practice problems that go up before the contests starts and we've been working through them. So far we have 3/3 "solved" and are waiting for the last two to go up. These are my answers to the puzzles with help from the others. These aren't necessarily correct and I'll link to the official solutions when they come up but I thought I'd put these up anyways. The first practice puzzle, Symphony No. 31, Op. 66 was full of little clues on how to proceed. Reading through the description a few times I noticed the letters I, S, and O in bold in the name 'Interdepartmental System Operations'. ISO.. due to the fact that computers have taken over my brain, the first thing that came to mind was ISO standardizations, but hey, I'm crazy, it is probably something else. None the less, I look for the numbers on the page 31 66 1 and search for a standard with those numbers, and sure enough, ISO 3166-1 is the standardization of country codes. By looking at the music notes in the puzzle, it is quickly apparent that they are in pairs and music notes have letters... two-letter country codes anyone? Decoding this we wind up with a list of countries:
These countries are loosely clustered by location so I try to plot them on a map and connect the lines, ending up with this : ![]() Countries mapped out.
My final answer: MALI Thursday, October 11. 2007Secure RSS with DrProjectSituation: DrProject has a very useful timeline feature, which shows all the activity (tickets opened/closed, source control checkins, wiki edits, etc) relating to a project. To make things even better, there is also an option to export this feed as RSS (now, [this is also slightly broken][960], but that's another story). Problem: If students are using DrProject to manage a marked project, there should be no way that students in one group can see the timeline another group. From the web interface, this is handled by the standard authentication mechanism... But there is no standard mechanism for authenticating RSS feeds. And, even if there was, students should not be giving their CDF passwords to online news reading services (both because the service might do Something Bad with it and because people should not be in the habit of giving out their credentials). Current solution: Turn off RSS. That's a really crappy solution. What can be done? Well, Andrew Louis and I were talking about it yesterday, and we were discussing a few of the different mechanisms used by similar web pages. Flickr, for instance, assigns each user an arbitrary ID. After they register a name, there is no way to see this ID. If you manage to find a person's ID (either before they register a name or through some other means), there is nothing stopping your from taking a look at any of their feeds (take a look at the photos from my contacts!). Ok, so that's a pretty crummy solution. Facebook is a bit more interesting. It assigns each feed a random ID. To view a feed, you need to know both the user's ID (easy to get) and the random ID (hard to get): But this isn't quite good enough. If someone gets hold of the secret key, it's all over. So what can we do? Well, else can we use to tell the difference between you and me? What about the headers our newsreaders send? The IP block our request originates from? How frequently we check the feed? Ok, so it might be tricky to implement a frequency-checking heuristic... But it would be easy to say "hhmm... Last time you checked this feed, you used Google Reader. But this time your User-agent tells me that you are curl. Something's up!" When a user wants to read an RSS feed, they are given a URL with a unique key. The first time that feed is accessed, the User-agent string (and possibly other headers) are recorded. On subsequent requests, the values are compared and if there is a significant change (for some value of "significant") [edit] and the old key will be invalidated. The legitimate user will be asked to re-validate the next time they download the feed.[/edit] This will not make attacks impossible, but will certainly frustrate them, because the attacker must get the headers right on the first try. [edit] If they get it wrong, they will have to wait for the legitimate user to get a new key, find that key, then try again. [/edit] Problems:
So, any comments? Postscript 0: What about OpenID?It looks really neat. In theory, it would solve this problem. In practice, though, there are two issues:
(Page 1 of 3, totaling 31 entries)
» next page
|
QuicksearchLinks
CategoriesSyndicate This Blog |
