Skip to content

Instantly share code, notes, and snippets.

View tonnylitao's full-sized avatar
🎯
Focusing

Tonny tonnylitao

🎯
Focusing
View GitHub Profile
@tonnylitao
tonnylitao / ImportFromApi
Last active August 29, 2015 13:57
CoreData Entity ImportFromApi, before import(Find-or-Create), we delete local not exist data first.
//
// NSManagedObject+ImportFromApi.m
// ThermometerBLE
//
// Created by Tonny on 3/4/14.
// Copyright (c) 2014 Doouya. All rights reserved.
//
#import "NSManagedObject+ImportFromApi.h"
#import "CommunityHeader.h"
#!/bin/sh
#------------------------------------------------------
prework(){
# Select the git format you want to use
GITFORMAT='%h'
echo "----------------------------------------------------"
# Enter a closing message
@tonnylitao
tonnylitao / gist:4e5c7d424161c4c8434f
Created October 5, 2014 11:29
Underscore.js 1.7.0
// Underscore.js 1.7.0
// http://underscorejs.org
// (c) 2009-2014 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
// Underscore may be freely distributed under the MIT license.
@tonnylitao
tonnylitao / gist:dc7931b3f722be65b6fe
Last active August 29, 2015 14:07
js库常见的闭包封装
(function() {
//匿名函数
//通常js对象调用已存在函数:obj.func(),若方法不存在,又不想重复定义该方法,可以使用call或apply借用
//obj2借用obj1的bar方法
//var obj1 = {}; obj1.bar = function(){...}
//var obj2 = {}; obj.bar.call(obj1);
//用call借用匿名函数,此处this可不传,参数为null或undefined时会自动指向全局对象
var root = this; //创建root局部变量,若在浏览器环境就是Window,若是Node环境就是node对象{exports:.. require:.. global:.. }
@tonnylitao
tonnylitao / gist:7da4c992e76c12431d17
Last active August 29, 2015 14:07
_命名冲突解决方案
//若你在导入undersocre之前已经使用了全局变量_表示laylow,为防止冲突,需要暂存起来
//今后你只能var laylow = _.noConflict()来表示laylow,而_表示undersocre
var previousUnderscore = root._;
@tonnylitao
tonnylitao / gist:b7414eb9c1c5b8a5c5c3
Last active August 29, 2015 14:07
使用局部变量优化性能
//作为工具类库,这3个prototype在很多地方都会用到,索性来个局部变量减少向上索取工作量。
//在underscore-min.js文件中,是这样的r=Array.prototype,e=Object.prototype,u=Function.prototype,48KB压缩成16KB
var ArrayProto = Array.prototype, ObjProto = Object.prototype, FuncProto = Function.prototype;
// 同理 局部快速索引
var
push = ArrayProto.push,
slice = ArrayProto.slice,
@tonnylitao
tonnylitao / gist:487236e819477a2e61eb
Last active August 29, 2015 14:07
浏览器兼容性之原生方法
var
nativeIsArray = Array.isArray,
nativeKeys = Object.keys,
nativeBind = FuncProto.bind;
// Baseline setup
// --------------
// Collection Functions
// --------------------
// Array Functions
// ---------------
// Function (ahem) Functions
// ------------------
// Object Functions
// ----------------
(function(){
var questURL = 'http://uni.priget.com/s/app/quest/enemy_encount_exec.php?guid=ON&qid=00000';
var battleURL = 'http://uni.priget.com/s/app/quest/enemy_battle_exec.php?guid=ON';
var battleDta = 'battle=戦闘&qid=00000';
var trainingURL = 'http://uni.priget.com/s/app/training/training_solo_exec.php?GUID=ON';
function xhrStart(method,url,data,requestHeader,callback){
var xhr = new XMLHttpRequest();
xhr.onload = function(){