Skip to content

Instantly share code, notes, and snippets.

View dchentech's full-sized avatar
🎯
Focusing

David Chen dchentech

🎯
Focusing
View GitHub Profile
@dchentech
dchentech / statlysis.showterm
Last active January 1, 2016 16:19
用statlysis来对CodeGist进行每日统计分析访问,用 http://showterm.io 来录制的。
地址在 http://showterm.io/7881a7c028d436b077273
脚本如下:
# statlysis是一个数据引擎分析框架,核心是对ETL之后的单表数据做类似SQL中GroupBy和GroupConcat的工作,
# 就像操作ActiveRecord等ORM一样简单。项目地址在 http://github.com/mvj3/statlysis
# 在这个test/helper.rb被载入后我们已经导入数据和建立Model了,
# 所以下面我们就来开始试用statlysis吧。
@dchentech
dchentech / backbone_view_dynamic_render.js
Created February 28, 2014 04:06
Backbone View 随数据改变而render。
$(document).ready(function() {
var dom = $("<div>").attr('id', 'mvj3');
$("body").html(dom);
window.mvj3 = Backbone.View.extend({
initialize: function(opts) {
this.opts = opts;
return this;
},
tagName: "div",
render: function() {
(function () {
"use strict";
var copyOwnProperties = function (from, to) {
for (var propertyName in from) {
if (from.hasOwnProperty(propertyName)) {
to[propertyName] = from[propertyName];
}
}
};
@dchentech
dchentech / python_closure.py
Created April 28, 2014 08:51
python closure
def computer():
count = 5
def plus(num):
count += num
print count
return plus
plus = computer()
plus(3)
plus(5)
"""
@dchentech
dchentech / .gitignore
Last active January 24, 2018 12:22 — forked from miku/.gitignore
*gz
*.txt
@dchentech
dchentech / python_singleton.py
Created July 23, 2014 10:57
从Singleton实现看Python里的__new__和__init__区别。
from singleton import singleton
@singleton(True)
class hh(object):
cc = 0
def __init__(self):
hh.cc += 1
self.count = hh.cc
@dchentech
dchentech / slow.coffee
Last active August 29, 2015 14:08
Simulate slow cpu computing
_.each(Array(10), -> Array(Math.pow(10, 8)).join("=").length)
@dchentech
dchentech / lazy_load_reference.py
Created December 5, 2014 02:47
Lazy reference between tasks, include recursive references.
# Lazy reference between tasks, include recursive references.
# 1. `eval` version
def ref_tasks(*tasks):
def wrap(task1):
def _ref_task(self):
return eval(task1)
return _ref_task
@dchentech
dchentech / analysis_hg_day_commit_count.rb
Created December 19, 2014 06:50
用 Ruby 简单 统计 hg 每日 commit 量。
`hg log --template 'date: {date|isodate}\n' | grep 'date: '`.split("\n").map {|i1| i1[6..15] }.inject({}) {|d1, i1| d1[i1] ||= 0; d1[i1] += 1; d1 }.sort {|a, b| a[0] <=> b[0] }.each {|i| puts i.inspect };0
__END__
["2014-09-24", 4]
["2014-09-25", 8]
["2014-09-26", 6]
["2014-09-28", 10]
["2014-09-29", 14]
["2014-09-30", 3]
["2014-10-08", 14]
@dchentech
dchentech / overwrite_base.py
Created January 6, 2015 08:16
Overwrite base class's methods.
# -*- coding: utf-8 -*-
"""
Overwrite base class's methods.
"""
import unittest
class Base(object):