Skip to content

Instantly share code, notes, and snippets.

@HellMagic
HellMagic / awesome-nginx.conf
Last active August 29, 2015 14:27 — forked from vjt/awesome-nginx.conf
*AWESOME* nginx configuration for Ruby/Rack web applications
#
# mmm m m mmm mmm mmm mmmmm mmm
# " # "m m m" #" # # " #" "# # # # #" #
# m"""# #m#m# #"""" """m # # # # # #""""
# "mm"# # # "#mm" "mmm" "#m#" # # # "#mm"
#
# nginx configuration For Ruby/Rack web applications
#
# Cooked up with style, care and a bit of *secret*
# nerdy spice. :-)
@HellMagic
HellMagic / mongo用法实例.js
Created February 25, 2016 06:52
mongo用法实例!!!
关于$in操作符的使用,官方有这么描述:
The $in operator selects the documents where the value of a field equals any value in the specified array.注意这里提到"any
value",即如果有document为{qty:[5, 10, 15]},使用db.test.find({qty: {"$in": [10, 1, 3]}})也能找到此document,因为此document的
qty数组对应的值中有一个10在提供的[10, 1, 3]数组中。
示例:db.inventory.find( { qty: { $in: [ 5, 15 ] } } ),等价于 db.invertory.find({"$or":[{qty: 5}, {qty: 15}]}),只不过
当前$or的条件作用的field是同一个field--qty--所以可以使用$in来替代。
$elemMatch的使用
示例:db.scores.find({ results: { $elemMatch: { $gte: 80, $lt: 85 } } })
@HellMagic
HellMagic / mongo注意事项
Created February 27, 2016 08:33
##mongo注意事项
1.快速理解记忆各种操作符,怎么高效地查阅文档。
比较操作符:
op.$gt
op.$gte
op.$lt
op.$lte
op.$eq
op.$ne
op.$in
op.$nin
@HellMagic
HellMagic / immutable-Snippet.js
Last active March 23, 2016 08:20
临时收集的一些Immutable库的高级使用例子,需要整理一下~
var list = Immutable.fromJS([
{id:'A', label: 'A', checked: true},
{id:'B',label: 'B'},
{id:'C',label: 'C',
children: [
{id:'C-A',label: 'C-A'},
{id:'C-B',label: 'C-B', checked: true},
{id:'C-C',label: 'C-C',
children: [
{id:'C-C-A',label: 'C-C-A'},
@HellMagic
HellMagic / Session机制.md
Created March 31, 2016 02:41
理解Session机制

cookie 和 session

众所周知,HTTP 是一个无状态协议,所以客户端每次发出请求时,下一次请求无法得知上一次请求所包含的状态数据,如何能把一个用户的状态数据关联起来呢?

比如在淘宝的某个页面中,你进行了登陆操作。当你跳转到商品页时,服务端如何知道你是已经登陆的状态?

cookie

首先产生了 cookie 这门技术来解决这个问题,cookie 是 http 协议的一部分,它的处理分为如下几步:

@HellMagic
HellMagic / react-note.js
Created April 14, 2016 03:44
关于react的一些snippet
在react-router中获取context.router:
es5:
var someComponent = React.createClass({
getInitialState: function() {
var router = this.context.router;
}
})
但是在es6中:
class SomeConponent extends React.Component {
constructor(props, context) {
@HellMagic
HellMagic / 0_reuse_code.js
Created June 5, 2016 11:05
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@HellMagic
HellMagic / 如何使用tar.txt
Created July 5, 2016 11:20
简单实用压缩
tar在linux上是常用的打包、压缩、加压缩工具,他的参数很多,折里仅仅列举常用的压缩与解压缩参数
参数:
-c :create 建立压缩档案的参数;
-x : 解压缩压缩档案的参数;
-z : 是否需要用gzip压缩;
快捷键:
ctrl + shift + up/down == 选择列
cmd + shift + space == 选择一个scope
ctrl + m == 移动到匹配的括号或引号