Skip to content

Instantly share code, notes, and snippets.

@lgr
lgr / attributed_dict.py
Created October 25, 2012 10:19
A dictionary which keys can be accessed and added as object attributes.
class AttributedDict(dict):
"""
A class extending the standard dict so that its keys can be accessed
as an object attributes (as long as the are strings).
Notice: this class is not pickable, so for example an attempt to save
its instance in Django session causes an error.
"""
__getattr__ = dict.__getitem__
@kellyredding
kellyredding / run.rb
Created May 16, 2012 17:54
Pull Gmail labels via IMAP using Gmail IMAP extensions
require 'net/imap'
# Net::IMAP raises a parse error exception when fetching attributes it doesn't
# recognize. Here I patch an instance of Net::IMAP's `msg_att` method to
# recognize the Gmail IMAP extended attributes
# Refer to:
# * https://developers.google.com/google-apps/gmail/imap_extensions#access_to_gmail_labels_x-gm-labels
# * http://blog.wojt.eu/post/13496746332/retrieving-gmail-thread-ids-with-ruby