Skip to content

Instantly share code, notes, and snippets.

View kehr's full-sized avatar
😃
Working

kehr

😃
Working
View GitHub Profile
@kehr
kehr / isElementInViewport.js
Created January 4, 2018 04:59 — forked from davidtheclark/isElementInViewport.js
JavaScript: Is element in viewport?
/*
No jQuery necessary.
Thanks to Dan's StackOverflow answer for this:
http://stackoverflow.com/questions/123999/how-to-tell-if-a-dom-element-is-visible-in-the-current-viewport
*/
function isElementInViewport(el) {
var rect = el.getBoundingClientRect();
return (
rect.top >= 0 &&
@kehr
kehr / img-compress.js
Created June 28, 2017 03:22
nodejs 压缩本地图片,转换为 base64。
const fs = require('fs');
const Canvas = require('canvas');
function compress(buff) {
// 将文件绘制成图片对象
let image = new Canvas.Image;
image.src = buff;
// 获取原始图片宽高
let drawWidth=image.width;
import tasks
import logging
import tornado.web
import functools
import threading
from tornado import gen
from tornado.concurrent import Future
from tornado.web import asynchronous
@kehr
kehr / urllib_delete.py
Created January 17, 2017 07:02
urllib2 send DELETE, PUT request
import urllib2
request = urllib2.Request(uri, data=data)
request.get_method = lambda: 'PUT' # or 'DELETE'
response = urllib2.urlopen(request)
@kehr
kehr / getUrlSearchKey.js
Created October 15, 2015 07:10
Get the search key of url
var getSearchKey = function(key){
if (!location.search) return null;
var list = location.search.split("?")[1].split("&");
for (var i=0; i < list.length; ++i){
if (!list[i]) continue;
var dict = list[i].split("=");
if (key == dict[0]){
return dict[1]
}
}
@kehr
kehr / time-convert.py
Created July 17, 2015 02:19
把秒转化成hms格式。
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@File Name: time.py
@Author: kehr
@Mail: kehr.china@gmail.com
@Created Time: 日, 07/12/2015, 01时27分08秒
@Copyright: GPL 2.0
@Description:
"""
@kehr
kehr / MySQLDecorator.py
Created June 28, 2015 08:02
This is a MySQL decorator
import umysql
from functools import wraps
class Configuraion:
def __init__(self, env):
if env == "Prod":
self.host = "coolshell.cn"
self.port = 3306
self.db = "coolshell"
self.user = "coolshell"
@kehr
kehr / unzip.sh
Created October 14, 2014 03:58
解压当前目录下的所有 zip 文件,以 .zip 前的名称命名。
# unzip zip file of current directory
for i in `ls`
do
name=`echo $i | awk -F'.' '{print $1}'`
unzip $i -d $name
done