Skip to content

Instantly share code, notes, and snippets.

View wonderbeyond's full-sized avatar
🎯
Focusing

Wonder wonderbeyond

🎯
Focusing
View GitHub Profile
@wonderbeyond
wonderbeyond / limit_access_by_ip.py
Last active December 16, 2015 22:39
A django view decorator that limits access in specified IP areas.
from django.http import HttpResponse, HttpResponseForbidden
from django.conf import settings
from functools import wraps
from django.utils.decorators import available_attrs
from utils import ip_in_expected_networks
def limit_access_by_ip(allowed_ips=settings.INTERNAL_IPS):
'''Decorator to limit access in specified IP areas.'''
def decorator(view_func):
@wraps(view_func, assigned=available_attrs(view_func))
@wonderbeyond
wonderbeyond / goTop.js
Last active December 16, 2015 23:50
平滑滚动到页面顶部的javascript函数 -- http://www.neoease.com/javascript-go-top/
/**
* 回到页面顶部
* @param acceleration 加速度
* @param time 时间间隔 (毫秒)
**/
function goTop(acceleration, time) {
acceleration = acceleration || 0.1;
time = time || 16;
var x1 = 0;
@wonderbeyond
wonderbeyond / shake.js
Created May 4, 2013 09:31
shake a DOM element
function shake(e, oncomplete, distance, time) {
// Handle arguments
if (typeof e === "string") e = document.getElementById(e);
if (!time) time = 500;
if (!distance) distance = 5;
var originalStyle = e.style.cssText; // Save the original style of e
e.style.position = "relative"; // Make e relatively positioned
var start = (new Date()).getTime(); // Note the animation start time
animate(); // Start the animation
// This function checks the elapsed time and updates the position of e.
@wonderbeyond
wonderbeyond / django_validatecode.py
Created May 4, 2013 09:43
A django view to deal with validate code
#coding=utf-8
from django.http import HttpResponse
import md5
import cStringIO
import Image, ImageDraw, ImageFont, random
from datetime import datetime
from os import path
def get_validatecode_img(request):
IMG_W = 100
IMG_H = 35
@wonderbeyond
wonderbeyond / jquery.validation.example.js
Created May 14, 2013 13:17
jquery.validation usage
$(document).ready(function(){
$('#change_email_form').validate({
rules: {
email1: {required:true, email:true},
email2: {required:true, email:true, equalto:"#id_email1"},
},
messages: {
email2: {
equalto: '两次输入邮箱地址不一致'
}
def jsonp(f):
"""Wrap a json response in a callback, and set the mimetype (Content-Type) header accordingly
(will wrap in text/javascript if there is a callback). If the "callback" or "jsonp" paramters
are provided, will wrap the json output in callback({thejson})
Usage:
@jsonp
def my_json_view(request):
d = { 'key': 'value' }
@wonderbeyond
wonderbeyond / special_chars.txt
Last active September 7, 2018 05:58
特殊字符搜集
✔ ×
› ‹
» «
← → ↩ ↪ ↘ ↙ ⇛ ⇚ #for i in range(8600, 8700): print unichr(i)
⊕ ⌚
≥ ≤
❤ ❥ ✾ ❣ ❖ ❢ ❦ ❧ ⥀ ⥁ ❍ ⥉ ✩ ✪ ✫ ✬ ✭ ✮ ✯ ✰ ✱ ✲ ✳ ✴ ✵ ✶ ✷ ✸ ✻ ✽ ✾ ✿ ❀ ❁ ❂ #for i in range(10000, 10100): print unichr(i)
🦄
@wonderbeyond
wonderbeyond / capital_money.js
Last active December 21, 2015 00:38
大写金额算法 - 转换数字金额为大写汉字格式
#!/usr/bin/env node
function capital_money(value) {
function get_tidy_value(value) {
var s_value = value.toFixed(2);
if(s_value.indexOf('.') >= 0) {
var int_part = s_value.split('.')[0];
var float_part = s_value.split('.')[1];
} else {
var int_part = s_value;
@wonderbeyond
wonderbeyond / logic_rogue_problem.py
Last active August 29, 2015 14:05
Rider and Rogue logic problem
#!/usr/bin/python
# coding=utf-8
'''
一个岛上居住着两类人——骑士和流氓。骑士说的都是真话,而流氓总是说谎。
现在碰到了岛上的两个人A和B,如果A说“B是骑士”,B说“我们两人不是一类人”。
请判断A、B两人到底是骑士还是流氓。
'''
class Speaker(object):
'''说话人, 可能是A, 也可能是B'''
/* 基础highcharts选项, 适用于每日行情数据
*/
var baseHighChartOpts = {
chart: {
zoomType: $(window).width() >= 800? 'x': null, //针对宽度大于800的窗口启用x轴缩放
height: 320
},
title: {
text: null