Skip to content

Instantly share code, notes, and snippets.

@zhasm
zhasm / p_99.js
Last active December 29, 2015 05:29
parse 99 只含有数字的参数,数值可能从 -99 到 99 之间变换,如何用正则匹配到整个字符串,从而完成在字符串末尾加上一个“度”字呢
###
#所需的函数:
p_99, 使用js 内置的parseInt,做比较;
re_99,使用正则式做匹配测试。
如果只想匹配 2 位的数字,忽略1位的数字,将 [0-9]{1,2} 改为 [0-9]{2} 即可。
###
p_99 = (degree) ->
@zhasm
zhasm / djcmd.sh
Last active December 20, 2015 10:59
snippet bash function to make new command in django apps.
function djcmd () {
if [[ "$#" -lt 1 ]]
then
echo "Usage: $FUNCNAME <must_args> [optional_args]"
return
else
mkdir -p management/commands
touch management/__init__.py
touch management/commands/__init__.py
touch management/commands/_private.py
@zhasm
zhasm / unzipgbk.py
Last active December 20, 2015 07:59
unzip gbk zipfile into utf8 files
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
#
# Author: Rex Zhang
# Create Time: 2013-07-28 12:32
# File name: unzipgbk.py
"""
./unzipgbk
@zhasm
zhasm / makecoffee.py
Last active December 19, 2015 08:29
自动发现和编译coffeeb?文件。自动清除错误编译的文件。 原理:检测所有当前目录下的coffee、coffeeb文件,生成 Makefile,然后运行make。 约定coffeeb是以bare模式编译的coffee文件。 执行:python makecoffee.py
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
#
# Author: Rex Zhang
# Create Time: 2013-07-04 16:14
# File name: makecoffee.py
import os
import re
import logging
@zhasm
zhasm / att.py
Last active December 18, 2015 10:49
send attachment under commandline. using standard libs from python, and gen raw mail then send with `sendmail -t`
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
#
# Author: Rex Zhang
# Create Time: 2013-06-13 10:54
# File name: att.py
from hashlib import md5
import argparse
@zhasm
zhasm / no_cache.py
Created May 17, 2013 06:55
django no cache decorator.
def no_cache():
def decorator(f):
def wrapper(*args, **kwargs):
response = f(*args, **kwargs)
response['Last-Modified'] = time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime())
response['Expires'] = 'Wed, 11 Jan 1984 05:00:00 GMT'
response['Cache-Control'] = 'no-cache, must-revalidate, max-age=0'
response['Pragma'] = 'no-cache'
return response
return wrapper
@zhasm
zhasm / xladd.py
Last active December 17, 2015 06:48
迅雷任务添加。 * 自动添加字符串中的可下载链接,例如 ed2k, magnet, thunder。 * 自动解析verycd 链接; * 支持递归解析(不常用) 需要 安装 requests 库。(sudo pip install requests; 或 sudo easy_install requests) 默认的 离线迅雷代码库 在XL_PATH='python $HOME/git/lx/lixian_cli.py' 。如果跟你的路径不一样,请修改该变量。
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
#
# Author: Rex Zhang
# Create Time: 2013-01-29 11:50
# File name: xladd.py
"""
usage:
xladd "string that contains downloadable resources, like ed2k, magnet, thunder."
@zhasm
zhasm / dateDiff.coffee
Last active December 15, 2015 17:39
date diff
#!/usr/bin/env coffee -bc $0
class DateDiff
constructor: (dateStr='') ->
try
[year, month, date, hour, min] = dateStr.match(///^(\d{4})
-(\d{2})
-(\d{2})
\s
(\d{2})
@zhasm
zhasm / font awesome @firefox.py
Last active December 15, 2015 04:59
font awesome 在firefox 下不能正常显示。搜索到基于 apache .htaccess 的解决方案(http://is.gd/3UrgIp),于是写出对应的django 解决方案。
#urls.py
url(r'^media/font/(?P<font>.*(?:eot|ttf|oft|woff))$', views.font, name='font'),
#views
import os
from django.conf import settings
def font(request, font):
font_fn = os.path.abspath(os.path.join(settings.MEDIA_ROOT, 'font/%s' % font))
@zhasm
zhasm / iMessage.sh
Created February 22, 2013 11:27
send text msg to iPhone via Messages.app under bash commandline
#!/bin/bash
exec osascript <<EOF
set peopleICareAbout to {"MyFullName"}
tell application "Messages"
repeat with myBuddy in buddies
if full name of myBuddy is in peopleICareAbout then
send "$*" to myBuddy
end if
end repeat