Skip to content

Instantly share code, notes, and snippets.

@wuchengwei
wuchengwei / gist:7fc521afab1ddfc4186d615ca7df8ca1
Last active January 16, 2019 03:33
判断一个平面多边形顶点列表方向是顺时针还是逆时针
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
@wuchengwei
wuchengwei / reset.css
Created November 8, 2018 01:50
Reset CSS
/* 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,
@wuchengwei
wuchengwei / traverse directory and shasum
Created September 9, 2016 04:47
traverse directory and shasum
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);
@wuchengwei
wuchengwei / dataURL to blob and blob to dataURL
Last active November 8, 2024 03:55
dataURL to blob and blob to dataURL
//**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});
}
@wuchengwei
wuchengwei / dingtalk-stylish.css
Created July 17, 2015 06:08
dingtalk stylish css
#layout-main{
left:0;
top:0;
margin:0;
border-radius:0;
box-shadow:none;
display:flex;
width:100%;
height:100%;
flex-flow: column nowrap;
@wuchengwei
wuchengwei / readJsonFileAsync.js
Created May 2, 2012 02:50
NodeJS - Read in a json file asynchronously
/*
* @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);
@wuchengwei
wuchengwei / NodeJS - Http Post.js
Created December 26, 2011 08:34
NodeJS - Http Post
//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;