Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/python
"""
Connect to an IMAP4 server with Twisted.
---------------------------------------
Run like so:
$ python twisted_imap4_example.py
This example is slightly Gmail specific,
in that SSL is required, and the correct
server name and ports are set for Gmail.
@zhasm
zhasm / rename
Created November 5, 2010 02:00
rename files by using perl regex.
#!/usr/bin/perl -w
#
# This script was developed by Robin Barker ([email protected]),
# from Larry Wall's original script eg/rename from the perl source.
#
# This script is free software; you can redistribute it and/or modify it
# under the same terms as Perl itself.
#
# Larry(?)'s RCS header:
# RCSfile: rename,v Revision: 4.1 Date: 92/08/07 17:20:30
@zhasm
zhasm / uploading
Created November 6, 2010 05:21
uploading
#!/usr/bin/env python
"""Simple HTTP Server With Upload.
This module builds on BaseHTTPServer by implementing the standard GET
and HEAD requests in a fairly straightforward manner.
"""
@zhasm
zhasm / gist:707753
Created November 20, 2010 10:45
hello world.
#import <Foundation/Foundation.h>
int main(int argc, const char *argv[])
{
//comment added.
NSLog(@"Hello, Objective-C!");
return (0);
}//main
@zhasm
zhasm / sqlite3.py
Created December 19, 2010 01:36
python sqlite
import os
import re
import glob
def initdb(base=os.getcwd(), ext="*.db3"):
'''get db file list,
use current directory as base,
and db3 as extention
'''
try:
@zhasm
zhasm / timezone_gmt8.py
Created December 19, 2010 01:50
set timezone to china gmt+8
import time
import os
os.environ['TZ']='Asia/Shanghai'
time.tzset()
@zhasm
zhasm / unique.array.js
Created December 21, 2010 01:53
add unique function to Array
//add unique function to Array
Array.prototype.unique = function() {
var o = {}, i, l = this.length, r = [];
for(i=0; i<l;i++) o[this[i]] = this[i];
for(i in o) r.push(o[i]);
return r;
};
//usage:
// a = "a a bb";
// a =a.split(" ");
@zhasm
zhasm / django.file.upload.py
Created December 23, 2010 08:48
uploading files within django framework
from django.conf.urls.defaults import *
from django.http import HttpResponse
'''
if required, please add the last 2 lines to settings.py:
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
# 'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
@zhasm
zhasm / table.html
Created December 24, 2010 01:53
cell that spans two columns
<html>
<body>
<h4>Cell that spans two columns:</h4>
<table border="1">
<tr>
<th>Name</th>
<th colspan="2">Telephone</th>
</tr>
<tr>
@zhasm
zhasm / escape_html.py
Created December 27, 2010 06:49
escape html tag
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
#author: rex
#blog: http://iregex.org
#filename dictregex.py
#created: 2010-12-27 14:27
import re