This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://stackoverflow.com/a/1165943 | |
Some of the suggested methods will fail in the case of a non-convex polygon, such as a crescent. Here's a simple one that will work with non-convex polygons (it'll even work with a self-intersecting polygon like a figure-eight, telling you whether it's mostly clockwise). | |
Sum over the edges, (x2 − x1)(y2 + y1). If the result is positive the curve is clockwise, if it's negative the curve is counter-clockwise. (The result is twice the enclosed area, with a +/- convention.) | |
point[0] = (5,0) edge[0]: (6-5)(4+0) = 4 | |
point[1] = (6,4) edge[1]: (4-6)(5+4) = -18 | |
point[2] = (4,5) edge[2]: (1-4)(5+5) = -30 | |
point[3] = (1,5) edge[3]: (1-1)(0+5) = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* http://meyerweb.com/eric/tools/css/reset/ | |
v2.0 | 20110126 | |
License: none (public domain) | |
*/ | |
html, body, div, span, applet, object, iframe, | |
h1, h2, h3, h4, h5, h6, p, blockquote, pre, | |
a, abbr, acronym, address, big, cite, code, | |
del, dfn, em, img, ins, kbd, q, s, samp, | |
small, strike, strong, sub, sup, tt, var, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var path = require('path'); | |
var crypto = require('crypto'); | |
function walk(dir, done) { | |
var results = []; | |
fs.readdir(dir, function(err, list) { | |
if (err) return done(err); | |
var pending = list.length; | |
if (!pending) return done(null, results); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//**dataURL to blob** | |
function dataURLtoBlob(dataurl) { | |
var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1], | |
bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n); | |
while(n--){ | |
u8arr[n] = bstr.charCodeAt(n); | |
} | |
return new Blob([u8arr], {type:mime}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#layout-main{ | |
left:0; | |
top:0; | |
margin:0; | |
border-radius:0; | |
box-shadow:none; | |
display:flex; | |
width:100%; | |
height:100%; | |
flex-flow: column nowrap; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* @param {String} filepath | |
* @param {function} callback function(err, data){} | |
*/ | |
function readJsonFileAsync(filepath, callback) { | |
var fs = require('fs'); | |
fs.readFile(filepath, 'utf-8', function(err, data) { | |
if (err) { callback(err, null); } | |
else { | |
result = JSON.parse(data); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//doHttpPost('localhost', 8000, '/TestPost', 'string' , 'TestTestTestTest', false); | |
//doHttpPost('localhost', 8000, '/TestPost', 'file' , '/Users/chengwei/Downloads/grid1.png', true); | |
function doHttpPost(_host, _port, _path, name, value, isFile, fileEncoding) { | |
var http = require('http'), | |
fs = require('fs'), | |
path = require('path'), | |
boundary = Math.random(), | |
postData, postOptions, postRequest; |