Skip to content

Instantly share code, notes, and snippets.

@liyanage
liyanage / email-test.py
Created November 18, 2012 02:00
Python email sending example
#!/usr/bin/env python
import email.mime.text
import email.header
import smtplib
email.Charset.add_charset('utf-8', email.Charset.QP, email.Charset.QP, 'utf-8')
me = u'Foo Bar <test@example.com>'
you = me
@liyanage
liyanage / gist:4102191
Created November 18, 2012 00:54
Example for a mini web app that keeps its state in a custom class instance
#!/usr/bin/env python
# Example for a mini web app that keeps its state in a custom class instance
import bottle
class Foo:
def main(self, value=0):
self.sum += value
@liyanage
liyanage / gist:4069272
Created November 14, 2012 00:03
Python cmd.Cmd completion workaround
# OS X-specific fix based on http://bugs.python.org/issue9033
readline.parse_and_bind('bind {} rl_complete'.format('^I'))
@liyanage
liyanage / AppDelegate.h
Created September 23, 2012 22:26
retain/autorelease demo
//
// AppDelegate.h
// ThreadTest
//
// Created by Marc Liyanage on 9/23/12.
//
#import <Cocoa/Cocoa.h>
@interface AppDelegate : NSObject <NSApplicationDelegate> {
@liyanage
liyanage / .gitconfig
Created August 16, 2010 17:51
.gitconfig
[core]
excludesfile = /Users/liyanage/.gitignore.global
[log]
date = local
[user]
name = Marc Liyanage
email = foo@example.com
[github]
user = liyanage
token = xxxxx
// CFLAGS='-std=c99 -arch x86_64' make cachetest && ./cachetest
#include <stdio.h>
#include <time.h>
void a();
void b();
int main() {
// CFLAGS='-arch i386' make blockstest && ./blockstest
#include <stdio.h>
#include <Block.h>
int main() {
int(^foo)() = ^() {
return 1+1;
// LDFLAGS='-framework Foundation' make test2 && ./test2
#import <Foundation/Foundation.h>
@interface Foo : NSObject {
NSString *bar;
}
@property (retain) NSString *bar;
// LDFLAGS='-framework Foundation' make archivertest
#import <Foundation/Foundation.h>
typedef enum Foo {
Foo1 = 0UL,
Foo2 = 1,
Foo3 = 2
} FooType;