Skip to content

Instantly share code, notes, and snippets.

<html>
<head>
<title>Contact us</title>
</head>
<body>
<h1>Contact us</h1>
{% if errors %}
<ul>
{% for error in errors %}
<li>{{ error }}</li>
from django.shortcuts import render_to_response
from django.core.mail import send_mail
from django.http import HttpResponseRedirect
from django.template import RequestContext
def contact(req):
errors = []
if req.method == 'POST':
if not req.POST.get('subject'):
errors.append('Enter a subject')
grep -r somethingtosearch ./
grep -r somethingtosearch ./
unzip myfile.zip
ls -t
//reversedly,most recent at bottom
ls -tr
//在当前目录创建文件夹dir1,并且在dir1文件夹内创建文件夹dir2
mkdir -p dir1/dir2
@dingzhihu
dingzhihu / gist:2791881
Created May 26, 2012 03:02
Maven-Assembly-Plugin
<project>
[...]
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
@dingzhihu
dingzhihu / my_layout.xml
Created July 6, 2012 14:35
设置Button的点击效果为40%透明
<?xml version="1.0" encoding="utf-8"?>
<Button xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/selector"
android:padding="10dp"
android:text="@string/hello" />
@dingzhihu
dingzhihu / snippets.py
Created July 14, 2012 08:39
python snippets
##string
ustring = u'A unicode \u018e string \xf1'
s = unistring.encode('utf-8')
t = unicode(s, 'utf-8')
##list
strs = ['ccc', 'aaaa', 'd', 'bb']
print sorted(strs, key=len) ## ['d', 'bb', 'ccc', 'aaaa']
##tuple