Skip to content

Instantly share code, notes, and snippets.

View lpgray's full-sized avatar
🎯
Focusing

zhangyang lpgray

🎯
Focusing
View GitHub Profile
@lpgray
lpgray / ES5 Newnewss
Last active May 25, 2016 15:34 — forked from sym3tri/ES5 Newnewss
New features of ES5 summarized
- Trailing commas are ok
- No reserved words for property names
- NaN, Infinity, undefined : are all constants
- parseInt() defaults to radix 10
- /regexp/ produces new reg ex object every time
- JSON.parse(), JSON.stringify()
- Function.prototype.bind
- String.prototype.trim
- Array.prototype.every, filter, forEach, indexOf, lastIndexOf, map, reduce, reduceRight, some,
- Date.now()
@lpgray
lpgray / XComponent.js
Last active May 7, 2016 04:17
JS Component Template for Global Pattern
/*
* XComponent
*
* 组件描述写在此处
*/
;(function(root){
'use strict';
var RootClass = function(option){
@lpgray
lpgray / mobile-browser-detector
Last active August 29, 2015 14:19
detect a mobile device browser
var isMobile = {
Android: function() {
return navigator.userAgent.match(/Android/i);
},
BlackBerry: function() {
return navigator.userAgent.match(/BlackBerry/i);
},
iOS: function() {
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
},
// 获得url参数
var QueryString = (function() {
// This function is anonymous, is executed immediately and
// the return value is assigned to QueryString!
var quertString = {};
var query = window.location.search.substring(1);
var vars = query.split('&');
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split('=');
// If first entry with this name
@lpgray
lpgray / BindEvent4DomList
Created January 7, 2014 03:28
[JavaScript] - bind event handler for a dom list.
// bind event handler for a dom list.
XICI.Event.addEvent(gas[i],"click",(function(i){
return function(){
var _option = gas[i].getAttribute('node-type');
var _title = gas[i].innerText || gas[i].getAttribute("title") || gas[i].getAttribute("alt") || "";
var _option3 = _title + "|" + gas[i].getAttribute("href");
_gaq.push(['_trackEvent',option1, _option, _option3]);
}
})(i));
@lpgray
lpgray / ScrollTop
Last active September 14, 2017 09:33
[JavaScript] scrollTop 兼容性写法
scrolltop = (((t = document.documentElement) || (t = document.body.parentNode)) typeof t.scrollTop == ‘number’ ? t : document.body).scrollTop
@lpgray
lpgray / GetGpsDistance
Last active January 1, 2016 00:38
[Java] - get the distance between two gps location point.
public static double getDistance(double wd1, double jd1, double wd2, double jd2) {
double x, y, out;
double PI = 3.14159265;
double R = 6.371229 * 1e6;
x = (jd2 - jd1) * PI * R * Math.cos(((wd1 + wd2) / 2) * PI / 180) / 180;
y = (wd2 - wd1) * PI * R / 180;
out = Math.hypot(x, y);
out = out / 1000;
return out;