Skip to content

Instantly share code, notes, and snippets.

@zhasm
zhasm / rebuild_db.py
Created June 21, 2012 13:15
rebuild_db.py
#!/usr/bin/env python
# -*- coding: iso-8859-1
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
@zhasm
zhasm / functions
Created September 20, 2012 17:01
forwarding one email box to another.
#!/bin/bash
CMD='cd /home/rexzhang/git/imap-forward; /home/rexzhang/local/bin/python fwd.py --log_to_stderr --log_file_prefix=/home/rexzhang/log/fwd.log'
export PATH=$PATH:/home/rexzhang/local/bin/
alias e='emacsclient -t -a ""'
logger ()
{
time=`TZ="Asia/Shanghai" date +"%Y-%m-%d %T"`;
echo "[$time] $*"
}
@zhasm
zhasm / gist:4038348
Created November 8, 2012 11:46
Emacs Command Summary

Emacs Command Summary

Emacs command summary, Thu Jul 25. link

Key
Key Cmd
@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 (Robin.Barker@npl.co.uk),
# 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
# 批量删除饭否消息之#bash#脚本。不解释。
# 将其追加到 .bashrc/.bash_profile 文件,
# 修改ID/PASSWORD
# 刷新 profile 文件
# 执行 rmmsg 即可删除所有所有消息。
# Not for FreeBSD.
function rmmsg()
{
id='fanfouname'
@zhasm
zhasm / antispam.py
Created November 3, 2011 14:19
get unread Gmails, print the Subject, From, To, Message-ID, without modifying the gmails' flags.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re
import imaplib2 as imaplib
from email import Header
from email.parser import Parser
##USER CONFIG
HOST = 'imap.gmail.com'
@zhasm
zhasm / regex.js
Created December 30, 2010 02:01
regular expression snippets in javascript
//if match
if (subject.match(/abc/)) {
// Successful match
} else {
// Match attempt failed
}
//get all match
result = subject.match(/regex/g);
@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 / btree.c
Created April 6, 2019 13:33
draw binary ascii in c
#include <stdio.h>
// http://web.archive.org/web/20071224095835/http://www.openasthra.com/wp-content/uploads/2007/12/binary_trees1.c
typedef struct Tree Tree;
struct Tree
{
Tree * left, * right;
int element;
};
@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',