Skip to content

Instantly share code, notes, and snippets.

View yeyuguo's full-sized avatar
🎯
Focusing

Struggling Youth yeyuguo

🎯
Focusing
  • ...
  • China-BeiJing(Now)
View GitHub Profile
@yeyuguo
yeyuguo / 很好的JS面试题目.js
Created March 30, 2017 02:45
便于理解 js 的原型继承和 属性使用 // 正确答案 :2 4 1 1 2 3 3
function Foo() {
getName = function () {
alert (1);
};
return this;
}
Foo.getName = function () {
alert (2);
};
Foo.prototype.getName = function () {
@yeyuguo
yeyuguo / 每次做都必错题.js
Created March 30, 2017 07:46
每次做都必错题
var name = "The Window";
  var object = {
    name : "My Object",
    getNameFunc : function(){
      return function(){
        return this.name;
     };
    }
};
alert(object.getNameFunc()());
@yeyuguo
yeyuguo / shouldComponentUpdate.js
Created April 5, 2017 02:11
react 组件是否应该更新
import { is, fromJS} from 'immutable';
function shouldComponentUpdate(nextProps, nextState) {
return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state),fromJS(nextState))
}
@yeyuguo
yeyuguo / server.js
Created April 7, 2017 08:00
饿了吗反向代理获取数据,API的具体方式在 : https://github.com/yeyuguo/vue2-elm.git
// var config = require('./config/proxyConfig')
var config = {
dev: {
env: {
NODE_ENV: '"development"'
},
host: '0.0.0.0',
port: 8088,
assetsSubDirectory: 'static',
assetsPublicPath: '/',
@yeyuguo
yeyuguo / action.js
Last active April 8, 2017 09:03
react-redux的应用
export const testAction = (data) => {
return {
type: 'testAction',
// testValue: [4, 3, 2, 1]
testValue: data
}
}
@yeyuguo
yeyuguo / bad.js
Created April 8, 2017 09:04 — forked from evantahler/bad.js
pg-action.js
exports.randomRow = {
name: 'randomFirstName',
description: 'I will return a random first name from the users table',
outputExample: {},
run: function(api, data, next){
pg.connect(api.config.pg.url, function(error, client, done){
if(error){ return next(error); }
var query = 'select * from usersorer by random() limit 1';
client.query(query, function(error, results){
本文曾在“架构师之路”上发布过,近期支援Qcon-AS大会,在微信群里分享了该话题,故对原文进行重新整理与发布。
一、秒杀业务为什么难做
1)im系统,例如qq或者微博,每个人都读自己的数据(好友列表、群列表、个人信息);
2)微博系统,每个人读你关注的人的数据,一个人读多个人的数据;
3)秒杀系统,库存只有一份,所有人会在集中的时间读和写这些数据,多个人读一个数据。
例如:小米手机每周二的秒杀,可能手机只有1万部,但瞬时进入的流量可能是几百几千万。
又例如:12306抢票,票是有限的,库存一份,瞬时流量非常多,都读相同的库存。读写冲突,锁非常严重,这是秒杀业务难的地方。那我们怎么优化秒杀业务的架构呢?
本文曾在“架构师之路”上发布过,近期支援Qcon-AS大会,在微信群里分享了该话题,故对原文进行重新整理与发布。
一、秒杀业务为什么难做
1)im系统,例如qq或者微博,每个人都读自己的数据(好友列表、群列表、个人信息);
2)微博系统,每个人读你关注的人的数据,一个人读多个人的数据;
3)秒杀系统,库存只有一份,所有人会在集中的时间读和写这些数据,多个人读一个数据。
例如:小米手机每周二的秒杀,可能手机只有1万部,但瞬时进入的流量可能是几百几千万。
又例如:12306抢票,票是有限的,库存一份,瞬时流量非常多,都读相同的库存。读写冲突,锁非常严重,这是秒杀业务难的地方。那我们怎么优化秒杀业务的架构呢?
@yeyuguo
yeyuguo / call 、apply 的区别 和 参数省略问题.js
Last active July 19, 2017 06:52
构造函数、原型、原型继承、各种JS demo
window.a = "window.a"
function A(){
this.a = "A().a"
}
function B(){
console.log(' * * * start B() * * * ')
A.call(this)
}
function C(){
console.log(' * * * start C() * * * ')
@yeyuguo
yeyuguo / quickSort.js
Created July 3, 2017 06:38
快速排序算法
// 快速遍历
times = 0
function quickSort(array) {
function sort(prev, numsize) {
var nonius = prev;
var j = numsize - 1;
var flag = array[prev];
if ((numsize - prev) > 1) {
while (nonius < j) {