Skip to content

Instantly share code, notes, and snippets.

View fwon's full-sized avatar
🎯
Focusing

Feng Wang fwon

🎯
Focusing
View GitHub Profile
@fwon
fwon / isType
Last active August 29, 2015 14:03
function isType(type) {
return function(obj) {
return Object.prototype.toString.call(obj) === "[object " + type + "]"
}
}
var isObject = isType("Object")
var isString = isType("String")
var isArray = Array.isArray || isType("Array")
var isFunction = isType("Function")
// While you can edit this file, it's best to put your changes in
// "User/Preferences.sublime-settings", which overrides the settings in here.
//
// Settings may also be placed in file type specific options files, for
// example, in Packages/Python/Python.sublime-settings for python files.
{
// Sets the colors used within the text area
"color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme",
// Note that the font_face and font_size are overriden in the platform
{
"auto_complete": true,
"auto_complete_commit_on_tab": false,
"auto_complete_delay": 50,
"auto_complete_selector": "source - comment",
"auto_complete_size_limit": 4194304,
"auto_complete_triggers":
[
{
"characters": "<",
7 组导航快捷键
使用下列快捷键方便在文字中快速定位:
跳至行首 – Control+A
跳至行尾 – Control+E
跳至下一行 – Control+N
跳至上一行 – Control+P
删除上一个单词 – Control+W
删除当前光标位置到行首的文字 – Control+U
删除当前光标位置到行尾的文字 – Control+K
@fwon
fwon / noConflict
Last active August 29, 2015 14:04
jQuery noConflict
// Map over jQuery in case of overwrite
_jQuery = window.jQuery,
// Map over the $ in case of overwrite
_$ = window.$, //前面有引入其他库时,为它的$,没有引入时,则为undefined
noConflict: function( deep ) {
if ( window.$ === jQuery ) {
window.$ = _$;
}
@fwon
fwon / module.js
Created August 24, 2014 08:00
类库开发--兼容多种模块的代码
兼容多种模块规范代码(Node, AMD, CMD以及常见浏览器环境):
;(function(name, definition) {
//检测上下文环境是否为AMD或CMD
var hasDefine = typeof define === 'function',
//检测上下文环境是否为Node
hasExports = typeof module !== 'undefined' && module.exports;
if (hasDefine) {
//AMD环境或CMD环境
//父进程和子进程同时开启
//parent.js
var cp = require('child_process');
var child1 = cp.fork('child.js');
var child2 = cp.fork('child.js');
//open up the server object and send the handle
var server = require('net').createServer();
server.on('connection', function(socket) {
socket.end('handled by parent\n');
// Node.js请求 CSRF防范
var generateRandom = function(len) {
return crypto.randomBytes(Math.ceil(len * 3 / 4))
.toString('base64')
.slice(0, len);
};
// 为每个请求的用户,在Session中赋予一个随即值
<form id="test" method="POST" action="http://domain_a.com/guestbook">
@fwon
fwon / guifan.text
Created August 29, 2014 13:37
scrat 解决的主要问题
规范
开发规范
模块化开发,js模块化,css模块化,像nodejs一样编码
组件化开发,js、css、handlebars维护在一起
部署规范
采用nodejs后端,基本部署规范应该参考 express 项目部署
按版本号做非覆盖式发布
公共模块可发布给第三方共享
框架
js模块化框架,支持请求合并,按需加载等性能优化点
@fwon
fwon / middle.html
Created September 1, 2014 03:06
垂直居中
<div style="display:table-cell; vertical-align:middle"><img></div>