Skip to content

Instantly share code, notes, and snippets.

@garylgh
garylgh / inDirection
Last active December 31, 2015 07:48
进入盒子的方向
function (ev, obj) {
var w = obj.offsetWidth,
h = obj.offsetHeight,
x = (ev.pageX - obj.offsetLeft - (w / 2) * (w > h ? (h / w) : 1)),
y = (ev.pageY - obj.offsetTop - (h / 2) * (h > w ? (w / h) : 1)),
d = Math.round( Math.atan2(y, x) / 1.57079633 + 5 ) % 4;
return d;
};
if (!window.localStorage) {
Object.defineProperty(window, "localStorage", new (function () {
var aKeys = [], oStorage = {};
Object.defineProperty(oStorage, "getItem", {
value: function (sKey) { return sKey ? this[sKey] : null; },
writable: false,
configurable: false,
enumerable: false
});
Object.defineProperty(oStorage, "key", {
@garylgh
garylgh / function.js
Created November 6, 2015 07:59
javascript
(function() { //去除字符串首尾空白
if (typeof String.trim == "undefined") {
String.prototype.trim = function() {
return this.replace(/(^\s*)|(\s*$)/g, "")
}
}
if (!Function.bind) {
Function.prototype.bind = function(obj) {
var _func = this;
console.log(_func);
$(document).bind("keydown", disableF5);
function disableF5(e) {
if ((e.which || e.keyCode) == 116) {
if(confirm("Are you sure you want to continue? You will loose some of the filled information!")){
return true;
}
else{
e.preventDefault();
}
// ----------------------------------------------------------
// A short snippet for detecting versions of IE in JavaScript
// without resorting to user-agent sniffing
// ----------------------------------------------------------
// If you're not in IE (or IE version is less than 5) then:
// ie === undefined
// If you're in IE (>=5) then you can determine which version:
// ie === 7; // IE7
// Thus, to detect IE:
// if (ie) {}
@garylgh
garylgh / bezier.js
Created October 15, 2015 09:46 — forked from LiuJi-Jim/bezier.js
De Casteljau Bezier
function DeCasteljauBezier(points, density, step){
//if (points.length < 3) return null;
console.time('bezier');
var ps = points.map(function(p){
return {
x: p.x,
y: p.y
};
}),
results = [],
$.datepicker.formatDate('yy-mm-dd', new Date())
@garylgh
garylgh / gist:15daa564d1b897d31572
Created September 12, 2014 07:34
maven archetype create
mvn archetype:create-from-project
cd target/generated-sources/archetype/
mvn install
mvn archetype:generate -DarchetypeCatalog=local
<distributionManagement>
<repository>
<id>209-release</id>
<name>209-release</name>
<url>http://192.168.163.209/nexus/content/repositories/releases/</url>
</repository>
@garylgh
garylgh / gist:53b41eef44cd967990b0
Last active August 29, 2015 14:06
tomcat-vm-config
JAVA_OPTS="-Xms512m -Xmx1024m -XX:PermSize=256M -XX:MaxPermSize=512M -Djava.awt.headless=true"
final Random r = new SecureRandom();
byte[] salt = new byte[32];
r.nextBytes(salt);
String encodedSalt = Base64.encodeBase64String(salt);