Skip to content

Instantly share code, notes, and snippets.

@pylemon
pylemon / 0_reuse_code.js
Created September 29, 2016 08:08
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@pylemon
pylemon / test
Created August 30, 2016 07:41
Title
/v2/post_check
=============
```json
{
"try_split": false,
"kind": "1000",
"group_order": false,
"line_items": [{
"quote_line_item_id": "147183895782223",
"quantity": 1
@pylemon
pylemon / EmacsKeyBinding.dict
Created December 29, 2015 08:14 — forked from jwreagor/EmacsKeyBinding.dict
Global Emacs Key Bindings for OS X
{
/* Keybindings for emacs emulation. Compiled by Jacob Rus.
*
* This is a pretty good set, especially considering that many emacs bindings
* such as C-o, C-a, C-e, C-k, C-y, C-v, C-f, C-b, C-p, C-n, C-t, and
* perhaps a few more, are already built into the system.
*
* BEWARE:
* This file uses the Option key as a meta key. This has the side-effect
* of overriding Mac OS keybindings for the option key, which generally
@pylemon
pylemon / gosched.go
Last active August 29, 2015 14:16
demo for gosched and gorouting
package main
import (
"fmt"
"runtime"
)
func say(s string) {
for i := 0; i < 2; i++ {
runtime.Gosched()
@pylemon
pylemon / distance.go
Last active August 29, 2015 14:14
compare the distance calculate between django geo and go.geo.
package main
import (
"fmt"
"github.com/paulmach/go.geo"
)
func main() {
// django.geo: 1143 m (result from django geo)
// go.geo: 1142.81 m (Mercator.Project + DistanceFrom)
var times = function() {
var timing = performance.timing;
var loadTime = timing.loadEventEnd - timing.navigationStart;//过早获取时,loadEventEnd有时会是0
if(loadTime <= 0) {
// 未加载完,延迟200ms后继续times方法,直到成功
setTimeout(function(){
times();
}, 200);
return;
}
# coding: utf-8
"""
这是一个装饰器 可以检测函数调用中的各种性能参数
使用方法: @iprofile("cumulative", 20)
"""
import cProfile
import pstats
import StringIO
import functools
@pylemon
pylemon / html5_number_field_fixes.js
Last active August 29, 2015 13:57 — forked from aaronsnoswell/gist:3786176
让html5 number 字段显示的 placeholder 可以为非数字
// jQuery version
$("input[type='number']").each(function(i, el) {
el.type = "text";
el.onfocus = function(){this.type="number";};
el.onblur = function(){this.type="text";};
});
// Stand-alone version
(function(){ var elms = document.querySelectorAll("input"), i=elms.length;
while(i--) {
import logging
logging.basicConfig(filename='testlogging.log', level=logging.DEBUG)
logger = logging.getLogger(__name__)
def foo():
try:
some_code()
except Exception:
logger.info('hihi', exc_info=True)
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from random import SystemRandom
import sys
import re
system_random = SystemRandom()
def base36_to_int(s):