Friday, November 06, 2009

 

Chit-chatting with dbus and the U1 SyncDaemon

I'm only putting this here because I don't know where else to put it:

Friday, October 02, 2009

 

Stupid python tricks - list of paths from a file

Take a long, repetitive list of Windows filenames, like C:\TEMP\blah.txt, and return the unique pathnames from this list:
#!/usr/bin/python

import re

results={}

f = open('filelist.txt','r')
for line in f:
    m=re.search(r"(.:\\\S+)",line)
    if m != None:
        path=m.group(0).rpartition('\\')
        results[path[0]]=True

pathlist=results.keys()
pathlist.sort()
for path in pathlist:
    print path

Tuesday, September 29, 2009

 

Using umdh to trace down Windows memory leaks

  1. Install Windbg
  2. set path="C:\Program Files\Debugging Tools for Windows (x64)";%path%
  3. enable sysmtem stack trace - gflags -r +ust
  4. md c:\websymbols
  5. set symbols path - set _NT_SYMBOL_PATH=SRV*c:\websymbols*http://msdl.microsoft.com/download/symbols;X:\Symbols\exe64ex
  6. snap process memory - umdh -p:pid -f:output-1-file
  7. snap process memory again - umdh -p:pid -f:output-2-file
  8. compare two memory snap - umdh output-1-file output-2-file  -f:cmp.txt
  9. cmp.txt should contain leak information.


Wednesday, September 09, 2009

 

bazaar and launchpad

Rockstar gave a TOTALLY AWESOME presentation during Ubuntu Developer Week on bzr and lp integration. The takeaway is this:

Bazaar can mirror a remote hosted repo into a local centralized branch. It then uses this central branch as the starting point for derived branches, even when hosted remotely. So instead of:

$ bzr branch lp:mago (downloads >1mb of crap)
$ bzr branch lp:~jtatum/mago/gconf (downloads >1mb of crap)

You do some config and:
$ bzr cbranch lp:mago (downloads >1mb of crap)
$ bzr cbranch lp:~jtatum/mago/gconf (downloads ~50kb of crap)

Magical!

~/.bazaar/bazaar.conf:
[ALIASES]
cbranch = cbranch --lightweight

~/.bazaar/locations.conf:
[/home/jtatum/Projects]
cbranch_target = /home/jtatum/Projects/repos
cbranch_target:policy = appendpath
[/home/jtatum/Projects/repos]
push_location = lp:~jtatum
push_location:policy = appendpath
public_branch = lp:~jtatum
public_branch:policy = appendpath

$ mkdir ~/Projects/repos/mago
$ cd ~/Projects/repos/mago
$ bzr init-repo --no-trees .
$ mkdir ~/Projects/mago
$ bzr cbranch lp:mago

Then, pull down a branch:

$ bzr cbranch lp:~who/mago/whatever

Or make a new one:

$ bzr cbranch mago myawesomecode

Push works magically thanks to the shorthand in location.conf. Neato!

Wednesday, August 26, 2009

 

Embrace and extend

There are a bunch of posts on the Internet about how ISA does not do transparent proxying. As I've always used the term, I mean using something like iptables to redirect web traffic to a proxy like squid, ninja style. When done correctly, computers require no extra configuration - the machine performing NAT silently rewrites the destination address to the proxy, the proxy uses request headers to determine the correct host.

Well, it seems ISA does support this. They call NAT clients without any additional proxy configuration SecureNAT clients, and according to this article, the firewall can be configured to redirect outbound web traffic to the IIS proxy. SecureNAT... Because it's magically better than regular NAT with transparent proxying, right?

In happier news, I started on a mago test suite for gcalctool. My branch is here. It's a work in progress but I am pretty happy with the results so far. I'm getting more and more certain about what goes where in the Mago testing paradigm. LDTP is dead simple, although the documentation is really a sore point. I definitely plan to contribute to the docs when I know what I'm doing.

TODO:
  • Readme
  • Math tests
  • Figure out the right place for init in a test suite

Monday, March 23, 2009

 

REST web service client in C#

I started writing a new web service at work. I've read a lot about REST and many of the principles resonated with me, so figured I'd give it a spin. It's amazing how little code there is out there. I found one very young view/controller framework for PHP. I found a couple of blog posts for C#.

This code will work with .NET 2.0. 3.5 and WCF may have some new methods for doing this, but it's shocking how little code there is out there for dealing with REST even today. Hopefully this helps someone. I'm putting it out as public domain but if you use it, it would be nice if you'd throw me a comment.

using System;

using System.Collections.Generic;

using System.Text;

using System.Net;

using System.IO;

using System.Web;

 

class Simple_REST

{

    public static string Get_URI(string uri)

    {

        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri);

        HttpWebResponse response = (HttpWebResponse)req.GetResponse();

        Stream responseStream = response.GetResponseStream();

        StreamReader reader = new StreamReader(responseStream);

 

        string responseString = reader.ReadToEnd();

 

        reader.Close();

        responseStream.Close();

        response.Close();

 

        return responseString;

    }

    public static string Post_URI(string uri, Dictionary<string, string> postDataDictionary)

    {

        string postData = "";

        foreach (KeyValuePair<string, string> kvp in postDataDictionary)

        {

            postData += string.Format("{0}={1}&", HttpUtility.UrlEncode(kvp.Key), HttpUtility.UrlEncode(kvp.Value));

        }

        postData = postData.Remove(postData.Length - 1); // remove the trailing ampersand

 

        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri);

        req.Method = "POST";

        byte[] postArray = Encoding.UTF8.GetBytes(postData);

        req.ContentType = "application/x-www-form-urlencoded";

        req.ContentLength = postArray.Length;

 

        Stream dataStream = req.GetRequestStream();

        dataStream.Write(postArray, 0, postArray.Length);

        dataStream.Close();

 

        HttpWebResponse response = (HttpWebResponse)req.GetResponse();

        Stream responseStream = response.GetResponseStream();

        StreamReader reader = new StreamReader(responseStream);

 

        string responseString = reader.ReadToEnd();

 

        reader.Close();

        responseStream.Close();

        response.Close();

 

        return responseString;

    }

}


Tuesday, November 25, 2008

 

Wordpress plugin: Get Post

I finished one of the small coding projects I was working on. Well, finished it enough for a release. The results are viewable here:

http://wordpress.org/extend/plugins/get-post/

Get Post is a plugin that adds a tag to wordpress: [get-post]. This tag allows you to display the latest post with a given tag in another post or a page.

Labels: , ,


This page is powered by Blogger. Isn't yours?