Instantly share code, notes, and snippets.

View series promises
// need lodash
const seriesPromise = promises => {
let promisesResults = [];
const tmpPromises = promises.concat(() => {
return Promise.resolve(promisesResults)
});
return _.tail(tmpPromises).reduce((cPromise, nPromise) => {
return cPromise.then(data => {
promisesResults.push(data);
return nPromise();
View gist:658b06e67c4f8af29cc53797f4a9fec4
function generationGrid() {
var size = 500, step = 50;
var geometry = new THREE.Geometry();
for (var i = - size; i <= size; i += step) {
geometry.vertices.push(new THREE.Vector3( - size, 0, i));
geometry.vertices.push(new THREE.Vector3(size, 0, i));
geometry.vertices.push(new THREE.Vector3(i, 0, -size));
geometry.vertices.push(new THREE.Vector3(i, 0, size));
}
View less
.desktop-and-old-ie(@rules) {
@media screen and (min-width: 1200) { @rules(); }
html.lt-ie9 & { @rules(); }
}
header {
background-color: blue;
.desktop-and-old-ie({
background-color: red;
View gist:7684b3c11eacaceedf86
var lastPostionY = 0;
var lastPostionX = 0;
var currentPositionY = 0;
var currentPositionX = 0;
var turntableCircleLeft = $('.turntable_circle').offset().left;
var turntableCircleHalfWidth = $('.turntable_circle').width() / 2;
var turntableCircleTop = $('.turntable_circle').offset().top;
var turntableCircleHalfHeight = $('.turntable_circle').height() / 2;
View gist:e7a8e63164045d77034f
$('#circle').on('touchstart',function(event){
//需要先判断点击了哪个扇区的位置
var x = event.originalEvent.touches[0].pageX - $('#circle')[0].getBoundingClientRect().left - 200;
var y = event.originalEvent.touches[0].pageY - $('#circle')[0].getBoundingClientRect().top - 200;
var anglePosition = Math.atan2(y,x);
var angle = 90 - anglePosition * (180/Math.PI);
View gist:8305f3c6e670535cf75f
function createXAxisCategories(){
//计算出弧
var canvas = $('#risk_report_polar_outside')[0];
var context = canvas.getContext('2d');
var width = canvas.width / 2;
var height = canvas.height / 2;
var radius = 230;
for(var i=0;i<categories.length;i++){
View gist:ca1e482a2f8ad84ffdcd
var foreignObject = document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject' );
var body = document.createElement( 'body' ); // you cannot create bodies with .apend("<body />") for some reason
$(foreignObject).attr("x", 0).attr("y", 0).attr("width", 100).attr("height", 100).append(body);
$(body).append("<div>real auto</div>");
$("#group").append(foreignObject);
View uilabelheight
/*//创建一个UILabel
var articleLabel:UILabel = UILabel(frame: CGRectMake(20.0, 100.0, self.view.frame.width - 40.0, 0.0));
//设置AttributedText
var attributeString:NSMutableAttributedString = NSMutableAttributedString(string: self.article!);
var style:NSMutableParagraphStyle = NSMutableParagraphStyle();
style.lineSpacing = 5.0;
attributeString.addAttribute(NSParagraphStyleAttributeName, value: style, range: NSMakeRange(0, attributeString.length));
articleLabel.attributedText = attributeString;
View Javascript Singleton
var Singleton = (function () {
var instance;
function createInstance() {
var object = new Object("I am the instance");
return object;
}
return {
getInstance: function () {