waiting for the worker processes to finish serving current requests
1
sudo nginx -s quit 或 sudo kill -s QUIT 1628(进程编号)
without waiting for the worker processes to finish serving current requests
1
sudo nginx -s stop
重启
更改配置文件之后需要重启
1
sudo nginx -s reload
Once the master process receives the signal to reload configuration, it checks the syntax validity of the new configuration file and tries to apply the configuration provided in it. If this is a success, the master process starts new worker processes and sends messages to old worker processes, requesting them to shut down. Otherwise, the master process rolls back the changes and continues to work with the old configuration. Old worker processes, receiving a command to shut down, stop accepting new connections and continue to service current requests until all such requests are serviced. After that, the old worker processes exit.
export default class A extends React.Component{ static __IS_A = true; // 添加一个静态变量,作为标记 ... render(){ ... } }
B.jsx
1 2 3 4 5 6 7 8 9 10 11 12 13
export default class B extends React.Component{ render(){ const {children} = this.props; let hasA = false; React.Children.map(children, item => { // 从type中获取静态变量,作为判断依据 if(item && item.type && item.type.__IS_A) hasA = true; }); return ( <div>{children}</div> ); } }
C.jsx
1 2 3 4 5 6 7 8 9 10 11 12 13
import A from 'path/to/A'; import B from 'path/to/B'; export default class C extends React.Component{ render(){ return ( <B> <A/> <span>...</span> ... </B> ); } }
/** 调用说明: array: 数据源数组。必选。 sum: 相加的和。必选。 tolerance: 容差。如果不指定此参数,则相加的和必须等于sum参数,指定此参数可以使结果在容差范围内浮动。可选。 targetCount: 操作数数量。如果不指定此参数,则结果包含所有可能的情况,指定此参数可以筛选出固定数量的数相加,假如指定为3,那么结果只包含三个数相加的情况。可选。 返回值:返回的是数组套数组结构,内层数组中的元素是操作数,外层数组中的元素是所有可能的结果。 */ functiongetCombBySum(array,sum,tolerance,targetCount){ var util = { /* get combination from array arr: target array num: combination item length return: one array that contain combination arrays */ getCombination: function(arr, num) { var r=[]; (functionf(t,a,n) { if (n==0) { return r.push(t); } for (var i=0,l=a.length; i<=l-n; i++) { f(t.concat(a[i]), a.slice(i+1), n-1); } })([],arr,num); return r; }, //take array index to a array getArrayIndex: function(array) { var i = 0, r = []; for(i = 0;i<array.length;i++){ r.push(i); }
return r; } },logic = { //sort the array,then get what's we need init: function(array,sum) { //clone array var _array = array.concat(), r = [], i = 0; //sort by asc _array.sort(function(a,b){ return a - b; }); //get all number when it's less than or equal sum for(i = 0;i<_array.length;i++){ if(_array[i]<=sum){ r.push(_array[i]); }else{ break; } }
return r; }, //important function core: function(array,sum,arrayIndex,count,r){ var i = 0, k = 0, combArray = [], _sum = 0, _cca = [], _cache = [];
Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.
// 五个属性 // source global ignoreCase multiLine lastIndex
// 两个方法 // test // exec var pattern = /Java/g; var text = 'JavaScript is more fun than Java!'; var result; while((result = pattern.exec(text)) !== null){ console.log("Matched '" + result[0] + "'" + " at Position " + result.index + "; next search begins at " + pattern.lastIndex); }
html { font-size: @baseFont; //默认当做320px宽度的屏幕来处理 }
@bps:400px, 414px, 480px; // 支持其他分辨率,在这里追加即可
.loop(@i: 1) when (@i <= length(@bps)) { //注意less数组是从1开始的 @bp: extract(@bps, @i); @font:@bp/@baseWidth*@baseFont; @media only screen and (min-width: @bp){ html { font-size: @font!important; } } .loop((@i + 1)); }; .loop;
转换成css为:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
html { font-size: 20px; } @media only screen and (min-width: 400px) { html { font-size: 21.33333333px!important; } } @media only screen and (min-width: 414px) { html { font-size: 22.08px!important; } } @media only screen and (min-width: 480px) { html { font-size: 25.6px!important; } }
注:less 转换方法 sudo npm install less -glessc styles.less
/** * 根据给定时间,获取给定时间当前周,前一周,后一周的所有日期 * @param date * @returns {{activeDates: Array, prevDates: Array, nextDates: Array}} */ functiongetWeekDateRange(date) { var activeDates = []; var prevDates = []; var nextDates = []; var nowTime = date.getTime(); var day = date.getDay(); var oneDayLong = 24 * 60 * 60 * 1000;
for (var i = -7; i < 14; i++) { var dateTiem = nowTime + (i - day) * oneDayLong; var d = newDate(dateTiem); if (i < 0) { prevDates.push(d); } elseif (i < 7) { activeDates.push(d); } else { nextDates.push(d); }
/** * Copyright 2016 Facebook, Inc. * * You are hereby granted a non-exclusive, worldwide, royalty-free license to * use, copy, modify, and distribute this software in source code or binary * form for use in connection with the web services and APIs provided by * Facebook. * * As with any software that integrates with the Facebook platform, your use * of this software is subject to the Facebook Developer Principles and * Policies [http://developers.facebook.com/policy/]. This copyright notice * shall be included in all copies or substantial portions of the software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE * * @providesModule F8StyleSheet * @flow */
let nodes = []; if (parentNode) { nodes.push(parentNode); } else { // 获取所有的顶级节点 for (let i = 0; i < rows.length; i++) { let row = rows[i]; if (!hasParent(rows, row.parentKey)) { nodes.push(row); } } }
// 存放要处理的节点 let toDo = nodes.map((v) => v);
while (toDo.length) { // 处理一个,头部弹出一个。 let node = toDo.shift(); // 获取子节点。 for (let i = 0; i < rows.length; i++) { let row = rows[i]; if (row.parentKey === node.key) { let child = row; let parentKeys = [node.key]; if (node.parentKeys) { parentKeys = node.parentKeys.concat(node.key); } child.parentKeys = parentKeys; let parentText = [node.text]; if (node.parentText) { parentText = node.parentText.concat(node.text); } child.parentText = parentText;
var a1 = localStorage["a"];//获取a的值 var a2 = localStorage.a;//获取a的值 var b = localStorage.getItem("b");//获取b的值 ``` ### 清除方法 ```js localStorage.removeItem("c");//清除c的值 localStorage.clear();//全部清除 ``` ### 遍历本地存储 这里会把所有的存储都遍历出来,无论是你用的,还是其他程序用的。key最好有个前缀,不容易重复的前缀,这样能区分开数据到底是什么类型 ```js var storage = window.localStorage; //类数组对象 for(var i = 0; i < storage.length; i++){ //key(i)获得相应的键,再用getItem()方法获得对应的值 var key = storage.key(i); var value = storage.getItem(key); }
// Add events on buttons modal.find('.modal-button').each(function (index, el) { $(el).on('click', function (e) { if (params.buttons[index].close !== false) closeModal(modal); if (params.buttons[index].onClick) params.buttons[index].onClick(modal, e); if (params.onClick) params.onClick(modal, index); }); }); openModal(modal); return modal; }
functionopenModal(modal) { modal = $(modal); var isModal = modal.hasClass('modal'); if ($('.modal.modal-in:not(.modal-out)').length && isModal) { modalStack.push(function () { openModal(modal); }); return; } // do nothing if this modal already shown if (true === modal.data('f7-modal-shown')) { return; } modal.data('f7-modal-shown', true); modal.trigger('close', function () { modal.removeData('f7-modal-shown'); }); if (isModal) { modal.show(); modal.css({ marginTop: -Math.round(modal.outerHeight() / 2) + 'px' }); }
if ($('.modal-overlay').length === 0) { $('body').append('<div class="modal-overlay"></div>'); } var overlay = $('.modal-overlay'); //Make sure that styles are applied, trigger relayout; var clientLeft = modal[0].clientLeft;//这个不能删,删了actions动画没了. // Trugger open event modal.trigger('open'); // Classes for transition in overlay.addClass('modal-overlay-visible'); modal.removeClass('modal-out').addClass('modal-in').transitionEnd(function (e) { if (modal.hasClass('modal-out')) modal.trigger('closed'); else modal.trigger('opened'); }); returntrue; }
functioncloseModal(modal) { modal = $(modal || '.modal-in'); if (typeof modal !== 'undefined' && modal.length === 0) { return; } var isModal = modal.hasClass('modal'); var overlay = $('.modal-overlay'); if (overlay && overlay.length > 0) { overlay.removeClass('modal-overlay-visible'); } modal.trigger('close'); modal.removeClass('modal-in').addClass('modal-out').transitionEnd(function (e) { if (modal.hasClass('modal-out')) modal.trigger('closed'); else modal.trigger('opened'); modal.remove(); }); if (isModal) { modalStackClearQueue(); } returntrue; }
functionmodalStackClearQueue() { if (modalStack.length) { (modalStack.shift())(); } }
var modalTitle = '提示'; var modalButtonOk = '确定'; var modalButtonCancel = '取消'; var modalPreloaderTitle = '加载中'; $.extend({ alert: function (text, title, callbackOk) { if (typeof title === 'function') { callbackOk = arguments[1]; title = undefined; } return modal({ text: text || '', title: typeof title === 'undefined' ? modalTitle : title, buttons: [ {text: modalButtonOk, bold: true, onClick: callbackOk} ] }); }, confirm: function (text, title, callbackOk, callbackCancel) { if (typeof title === 'function') { callbackCancel = arguments[2]; callbackOk = arguments[1]; title = undefined; } return modal({ text: text || '', title: typeof title === 'undefined' ? modalTitle : title, buttons: [ {text: modalButtonCancel, onClick: callbackCancel}, {text: modalButtonOk, bold: true, onClick: callbackOk} ] }); }, showPreloader: function (title) { return modal({ title: title || modalPreloaderTitle, text: '<div class="preloader"></div>', cssClass: 'modal-preloader' }); }, hidePreloader: function () { closeModal('.modal.modal-in'); }, showIndicator: function () { //$('body').append('<div class="preloader-indicator-overlay"></div><div class="preloader-indicator-modal"><span class="preloader preloader-white"></span></div>'); //去掉全屏透明遮盖层 $('body').append('<div class="preloader-indicator-modal"><span class="preloader preloader-white"></span></div>'); }, hideIndicator: function () { $('.preloader-indicator-overlay, .preloader-indicator-modal').remove(); }, toast: function (text, closeCallBack) { var m = modal({ title: '', text: text }); if (closeCallBack) { m.on("close", closeCallBack); } setTimeout(function () { closeModal(); }, 1500); return modal }, actions: function (params) { var modal, groupSelector, buttonSelector;
params = params || [];
if (params.length > 0 && !$.isArray(params[0])) { params = [params]; } var modalHTML;
var buttonsHTML = ''; for (var i = 0; i < params.length; i++) { for (var j = 0; j < params[i].length; j++) { if (j === 0) buttonsHTML += '<div class="actions-modal-group">'; var button = params[i][j]; var buttonClass = button.label ? 'actions-modal-label' : 'actions-modal-button'; if (button.bold) buttonClass += ' actions-modal-button-bold'; if (button.color) buttonClass += ' color-' + button.color; if (button.bg) buttonClass += ' bg-' + button.bg; if (button.disabled) buttonClass += ' disabled'; buttonsHTML += '<div class="' + buttonClass + '">' + button.text + '</div>'; if (j === params[i].length - 1) buttonsHTML += '</div>'; } } modalHTML = '<div class="actions-modal">' + buttonsHTML + '</div>'; _modalTemplateTempDiv.innerHTML = modalHTML; modal = $(_modalTemplateTempDiv).children(); $('body').append(modal[0]); groupSelector = '.actions-modal-group'; buttonSelector = '.actions-modal-button';
var groups = modal.find(groupSelector); groups.each(function (index, el) { var groupIndex = index; $(el).children().each(function (index, el) { var buttonIndex = index; var buttonParams = params[groupIndex][buttonIndex]; var clickTarget; if ($(el).is(buttonSelector)) clickTarget = $(el); if ($(el).find(buttonSelector).length > 0) clickTarget = $(el).find(buttonSelector);
if (clickTarget) { clickTarget.on('click', function (e) { if (buttonParams.close !== false) closeModal(modal); if (buttonParams.onClick) buttonParams.onClick(modal, e); }); } }); }); openModal(modal); return modal; }, closeModal: closeModal }); })(jQuery, window, document);
console.log('hello'.green); // outputs green text console.log('i like cake and pies'.underline.red) // outputs red underlined text console.log('inverse the color'.inverse); // inverses the color console.log('OMG Rainbows!'.rainbow); // rainbow console.log('Run the trap'.trap); // Drops the bass
不扩展String.prototype
1 2 3 4 5 6 7
var colors = require('colors/safe');
console.log(colors.green('hello')); // outputs green text console.log(colors.red.underline('i like cake and pies')) // outputs red underlined text console.log(colors.inverse('inverse the color')); // inverses the color console.log(colors.rainbow('OMG Rainbows!')); // rainbow console.log(colors.trap('Run the trap')); // Drops the bass
This module creates a middleware that records the response time for requests in HTTP servers. The “response time” is defined here as the elapsed time from when a request enters this middleware to when the headers are written out to the client.
with self._default_db.create_connection() as connection: update_sql = "update sequences set next_id = last_insert_id(next_id+step) where name=%s and name_space=%s" select_sql = "select last_insert_id()-step as start_id, step from sequences " +\ "where name=%s and name_space=%s" result = connection.execute(update_sql, name, name_space) if result.rowcount == 0: raise exc.ArgumentError("sequence is not exist namespace:%r name:%r" % (name_space, name)) entity = connection.execute(select_sql, name, name_space).first() return entity[0], entity[1]
if __name__ == "__main__": DatabaseBuilder.run_mode = 'test' for i in range(0, 100000):
Autobinding: When creating callbacks in JavaScript, you usually need to explicitly bind a method to its instance such that the value of this is correct. With React, every method is automatically bound to its component instance. React caches the bound method such that it’s extremely CPU and memory efficient. It’s also less typing!
lorem ...will produce: Lorem ipsum dolor sit amet, consectetur adipisicing elit. Alias et nemo repudiandae. Esse ex molestias numquam, possimus quaerat quas sint tempora? Asperiores dicta ducimus facilis impedit neque ratione ut vel!
lorem10 //生成10个单词 ...will produce: Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dolore, totam.
p*4>lorem ...will produce: <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Qui dicta minus molestiae vel beatae natus eveniet ratione temporibus aperiam harum alias officiis assumenda officia quibusdam deleniti eos cupiditate dolore doloribus!</p> <p>Ad dolore dignissimos asperiores dicta facere optio quod commodi nam tempore recusandae. Rerum sed nulla eum vero expedita ex delectus voluptates rem at neque quos facere sequi unde optio aliquam!</p> <p>Tenetur quod quidem in voluptatem corporis dolorum dicta sit pariatur porro quaerat autem ipsam odit quam beatae tempora quibusdam illum! Modi velit odio nam nulla unde amet odit pariatur at!</p> <p>Consequatur rerum amet fuga expedita sunt et tempora saepe? Iusto nihil explicabo perferendis quos provident delectus ducimus necessitatibus reiciendis optio tempora unde earum doloremque commodi laudantium ad nulla vel odio?</p>
ul.generic-list>lorem10.item*4 //10是只每行10个单词 ...will produce: <ul class="generic-list"> <li class="item">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nam vero.</li> <li class="item">Laboriosam quaerat sapiente minima nam minus similique illum architecto et!</li> <li class="item">Incidunt vitae quae facere ducimus nostrum aliquid dolorum veritatis dicta!</li> <li class="item">Tenetur laborum quod cum excepturi recusandae porro sint quas soluta!</li> </ul>
SuperAnger http://visionmedia.github.io/superagent/ Super Agent is light-weight progressive ajax API crafted for flexibility, readability, and a low learning curve after being frustrated with many of the existing request APIs. It also works with Node.js!