Skip to content

Instantly share code, notes, and snippets.

View lovemyliwu's full-sized avatar
😍
feel free

Smite Chow lovemyliwu

😍
feel free
View GitHub Profile
@lovemyliwu
lovemyliwu / obj_ext.js
Created November 19, 2015 10:26
JavaScript Object Extend
Object.deepExtend = function(destination, source) {
for (var property in source) {
if (source[property] && source[property].constructor &&
source[property].constructor === Object) {
destination[property] = destination[property] || {};
arguments.callee(destination[property], source[property]);
} else {
destination[property] = source[property];
}
}
def assertDictLoop(expected, test_data):
self.assertListEqual(sorted(expected.keys()), sorted(test_data.keys()))
for key in expected.keys():
expected_value = expected[key]
test_value = test_data[key]
if type(expected_value) == dict:
assertDictLoop(expected_value, test_value)
elif type(expected_value) == list:
self.assertListEqual(sorted(expected_value), sorted(test_value))
else:
@lovemyliwu
lovemyliwu / youku_jsapi_patch
Created December 18, 2015 10:17
Patch for Youku jsapi
if (!YKP.isSupportFlash) {
// patch for direct url
var oldSelectDirectUrl = YoukuPlayerSelect.prototype.selectDirectUrl;
YoukuPlayerSelect.prototype.selectDirectUrl = function () {
var oldStart = BuildVideoInfo.start;
BuildVideoInfo.start = function (vid, password, vtype, callback) {
var originCallBack = callback,
patchCallBack = function (v, videoInfo) {
@lovemyliwu
lovemyliwu / 数据挖掘及应用测验(一)代码版答案.js
Created March 26, 2016 06:02
数据挖掘及应用测验(一)代码版答案.js
var list = [10,12,14,15,17,18,18,23,25,25,25,25,26,26,33,37,37,39,39,39,39,40,40,43,45,51,80];
console.log('currently compute base on the list:' + list);
list = list.sort();
var length = list.length;
console.log('list length:' + length);
var itemCounts = {}, sum = 0, zongsu = [];
for (var idx=0; idx < length; idx ++) {
// 基尼指数
/*
>基尼指数度量的是数据集的不纯度,变量x,取值有n种,每一种概率Pi,那么X的基尼指数Gini(x)=1-∑Pi^2
>分类系统中类别就是变量,那么分类系统的基尼指数就是上面的Gini(x),Pi就是每种类别出现的概率
>特征T有n种取值,当T取Ti的值时,分类系统的基尼指数表示为Gini(x|T=Ti)=1-∑Pi^2,Pi是使用Ti过滤出的分类子集中类别取值的概率
>特征T在分类系统中总的基尼指数Gini(x|T)=Pi*Gini(x|T=Ti),Pi是Ti的取值概率
*/
var getGiniIndex = function (list) {
@lovemyliwu
lovemyliwu / auto-shell-at-boot.md
Last active June 19, 2016 03:08
Mac 开机自启动脚本 Ubuntu 开机自启动脚本

Ubuntu

sudo vi /etc/rc.local

cd some-where-your-shell-folder
./your-shell
cd -

mac

>sudo vi /Library/LaunchDaemons/com.go.agent.plist

@lovemyliwu
lovemyliwu / debug_angular.md
Created August 25, 2016 01:44
how to debug angular in chrome console
$injector = angular.injector(['accountsApp']);
$injector.invoke(['djangoUrl',function(djangoUrl){window.djangoUrl=djangoUrl;}])
window.djangoUrl
window.djangoUrl.reverse
scope = angular.element($0).scope();
@lovemyliwu
lovemyliwu / angular-promise-implement.js
Created August 28, 2016 09:46
Angular Promise Example and UT
require('1.3.0/angular.min.js');
require('1.3.0/angular-ivpusic-cookie.min.js');
require('django-angular/django-angular.min.js');
(function (angular) {
var app = angular.module('present-ylly-api-token', ['ipCookie', 'djng.urls']);
app.factory('present-token-interceptor', ['$injector', '$q', function ($injector, $q) {
var interceptor = {
getAuthorizationHeader: function () {
@lovemyliwu
lovemyliwu / list_all_new_variable_window.js
Created January 19, 2017 04:16
列出window对象新增的属性
// 准备一份干净的window对象属性列表,例如新打开一个tab,在console里运行如下命令
originItems = Object.keys(window);
// 在你想分析的页面的console里同样取得包含新增属性的window对象属性列表
completeItems = Object.keys(window);
// 过滤出来

###前置知识

会一门基本的命令式编程语言(vb/c/c++/java/js等)或了解基本的编程概念(变量,函数,类等)

###目标

熟悉并能使用Python做一些实际的事情, 一共有三个部分的培训, 每个部分培训时长应在3个小时内,讲演结合.结束之后留有课后作业, 完成课后作业视为达成目标.

online python REPL:https://repl.it/languages/python