Skip to content

Instantly share code, notes, and snippets.

@zhasm
zhasm / len.py
Created May 5, 2011 00:26
Get the length of the given string, which can be ascii string or unicode or both
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
#author: rex
#blog: http://iregex.org
#filename len.py
#created: 2011-04-29 15:18
import sys
@zhasm
zhasm / unshortenurl.py
Created May 23, 2011 07:37
unshorten shorten URLs
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
#author: rex
#blog: http://iregex.org
@zhasm
zhasm / bash_profile.sh
Created May 26, 2011 03:38
common alias
#!/bin/bash
export EDITOR='/usr/bin/vim'
export PS1="\[\e[36;1m\]\u\[\e[0m\]@\[\e[32;1m\]\h\[\e[0m\]:\[\e[31;1m\]\w\[\e[0m\]\n$"
alias a=alias
a grep="grep --color=auto -s"
#ls
@zhasm
zhasm / o.py
Created July 22, 2011 11:02
open for ubuntu
#!/usr/bin/env python
import gnomevfs
import sys
import commands
import os
try:
filename=os.path.abspath(sys.argv[1])
except Exception, e:
@zhasm
zhasm / gist:1324035
Created October 29, 2011 03:17
attachment mailer, send attachment via localhost/gmail
#!/usr/bin/env python
"""attachment mailer, send attachment via localhost/gmail"""
import os
import re
import sys
import smtplib
# For guessing MIME type based on file name extension
import mimetypes
@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 / bash_functions.sh
Created February 29, 2012 06:10
bash_functions
#!/bin/bash
function psg()
{
/bin/ps aux | grep -v 'grep' |grep -i $1
}
function len()
{
string=$1
@zhasm
zhasm / bash_aliases.sh
Created February 29, 2012 06:11
bash_aliases
#converting utilities
alias b2u='iconv -f big5 -t utf-8'
alias g2u='iconv -f gbk -t utf-8'
alias sec='date "+%s"'
alias now='date "+%Y-%m-%d %H:%M"'
#show image resolution
alias resolution='identify $1 |awk '\''{print $3}'\'''
#count freqency
alias count='sort | uniq -c| sort -nr'
@zhasm
zhasm / auto_date.sh
Created March 3, 2012 12:59
auto classify images by reading exif date infor
#!/bin/bash
function getMonth(){
img="$1"
date=`identify -format "%[EXIF:DateTime]" $img |awk -F: '{print $1$2}'`
echo $date
}
mkdir -p misc
for i in `ls *jpg |head -n 1000`
@zhasm
zhasm / encode.py
Created March 5, 2012 00:33
display encoding
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
def encode(c):
"""show the other repr of unicode str c"""
ens=['utf-8', 'gbk', 'big5']
print "Unicode:\t%s" % (repr(c))
for en in ens:
try: