Production Debugging talk at Code Camp Philly

Thanks to everyone who attended my talk on Production Debugging. You can now download my slides and code samples from the talk. I have listed some questions and answers from the talk at the bottom.

Where can I get Reflector?

It is a free download on Red Gate's site. You don't have to buy the Visual Studio in­te­gra­tion. When it starts up you are asked for the version of .NET to use. I always select the latest version as .NET backwards com­pat­i­bil­i­ty is good. Of course this can be changed later.

How do you stop someone from de­com­pil­ing your code with Reflector?

The truth is that you cannot stop a determined hacker from getting at your code. Your best option is to make it harder by using an ob­fus­ca­tion tool such as PreEmptive Dot­fus­ca­tor, Red Gate Smar­tAssem­bly, Remotesoft Salamander, Xheo Code Protection, or one of the many other .NET ob­fus­ca­tors.

You should be aware that ob­fus­ca­tors can make your life more difficult. One way they make code harder to read in Reflector is through method renaming. This can result in the stack traces from the obfuscated code being out of sync with your code.

Can I use ELMAH with Windows apps?

Not easily. ELMAH relies on various features of ASP.NET to do a lot of it's work. Some people have make their own mod­i­fi­ca­tions, but it not something that a beginning developer might want to attempt.

I wrote a sample ages ago called BugBack that works for WinForms. It is old and in need of some love but it is a starting point. If you want an off the shelf solution you should look at Red Gate Smar­tAssem­bly.

Tagged with asp-net, codecamp, debugging, fiddler, http, philadelphia, presentation, sharepoint and talk.

Multiple Monitor/Screen Information Example

Microsoft made it very simple to get in­for­ma­tion about the displays available to Windows with the Screen class in Windows Forms. Using this class you can identify the primary screen, and get properties like size from any display device.

Screenshot of monitor/display information sample. Try it with multiple=

For anyone developing an ap­pli­ca­tion which supports multiple monitors the Screen.Bounds property may be useful in finding screen offsets. If you have multiple monitors attached try the Get Current Screen Info button on your secondary display.

Download the C# sample code and binaries to explore further. Like all good API examples I have omitted error handling ;)

Tagged with multiple-monitors, windows and winforms.

Looking forward to PyCon 2010!

On Thursday I'm making the yearly pilgrimage to PyCon in Atlanta. This will be my third year and I'm sure it'll be better than ever.

For me the real highlights of this conference are the legendary open space sessions. The level of in­ter­ac­tion and learning at these really sets it apart from other con­fer­ences. Last year I attended a number of crackers including one on Cassandra and big data scal­a­bil­i­ty with Jonathan Ellis. It's great to see that Jonathan is delivering a scheduled talk on database scal­a­bil­i­ty, and I'm sure there will be a fair number of open space sessions dedicated to NoSQL databases.

Looking at the 2010 schedule these are my other top picks:

  1. Deployment, de­vel­op­ment, packaging, and a little bit of the cloud (Ian Bicking)
  2. Powerful Pythonic Patterns (Alex Martelli)
  3. Un­der­stand­ing the Python GIL (David Beazley)
  4. Mastering Team Play: Four powerful examples of composing Python tools (Raymond Hettinger)
  5. Unladen Swallow: fewer coconuts, faster Python (Collin Winter)

I'll have my camera with me again this year so watch out for pics under the pycon and pycon2010 tags on Flickr.

Tagged with atlanta, pycon and python.

Twitter to blog script

Twitter logoBased on an example provided with the Twitter library for Python I cobbled together the following script to add my latest tweets to this site. It's called from a cron job that I run on an occasional basis. My script linkifies hashtags and @username tokens in tweets so that you can see search results or user in­for­ma­tion.

Why did I not use one of the WordPress widgets? Well writing scripts like this is fun, and some widgets don't seem to play too well with my Thesis theme. One thing to note is that getting the shell script setup under some cron con­fig­u­ra­tions can take a while if you aren't using it on a regular basis. It's operation is also different between Ubuntu Server and Joyent's Ac­cel­er­a­tor platform.

Up next: a similar script to process my latest bookmarks on Delicious.com.

Main script (tweets.py)

#!/usr/bin/python

import codecs, re, getopt, sys, twitter

TEMPLATE = """
<li>
  <span class="twitter-text">%s</span>
  <span class="twitter-relative-created-at"><a href="http://twitter.com/%s/statuses/%s">Posted %s</a></span>
</li>
"""

def Usage():
  print 'Usage: %s [options] twitterid' % __file__
  print
  print '  This script fetches a users latest twitter update and stores'
  print '  the result in a file as an XHTML fragment'
  print
  print '  Options:'
  print '    --help -h : print this help'
  print '    --output : the output file [default: stdout]'


def FetchTwitter(user, output):
  assert user
  statuses = twitter.Api().GetUserTimeline(user=user, count=7)

  xhtml = []
  for status in statuses:
      status.text = Linkify(status.text)
      xhtml.append(TEMPLATE % (status.text, status.user.screen_name, status.id, status.relative_created_at))

  if output:
    Save(''.join(xhtml), output)
  else:
    print ''.join(xhtml)

def Linkify(tweet):
    tweet = re.sub(r'(\A|\s)@(\w+)', r'\1@\2', tweet)
    return re.sub(r'(\A|\s)#(\w+)', r'\1#\2', tweet)

def Save(xhtml, output):
  out = codecs.open(output, mode='w', encoding='utf-8',
                    errors='xmlcharrefreplace')
  out.write(xhtml)
  out.close()

def main():
  try:
    opts, args = getopt.gnu_getopt(sys.argv[1:], 'ho', ['help', 'output='])
  except getopt.GetoptError:
    Usage()
    sys.exit(2)
  try:
    user = args[0]
  except:
    Usage()
    sys.exit(2)
  output = None
  for o, a in opts:
    if o in ("-h", "--help"):
      Usage()
      sys.exit(2)
    if o in ("-o", "--output"):
      output = a
  FetchTwitter(user, output)

if __name__ == "__main__":
  main()

Shell script executed as cron job (tweets.sh)

/usr/bin/python /path/to/tweets.py brianly --output /path/to/output/twittertimeline.htm

Tagged with cron, python, scripting and twitter.

« Older Posts Newer Posts »