Friday, December 1, 2017

Friday, November 17, 2017

CORS简介

CORS是一个W3C标准,全称是"跨域资源共享"(Cross-origin resource sharing)。

CORS只针对浏览器,因为浏览器安全性的考虑,会拒绝向不允许访问的资源网站发送请求。过程是
1. 某网站的Ajax代码尝试去访问其他网站的资源(html,图片),
2. 这时候浏览器会自动加入先发一个CORS请求
3. 服务器whitelist了这个请求,返回response包含允许allow-origin=该网站的header。如果服务器不允许,浏览器收到response不含origin信息就会停止发送真正的请求。
4. 其后,每一个请求都会自动加入allow-origin的header。

其实,这只是浏览器的限制,如果用fiddler或者postman,甚至HTTPclient的lib是不会有这些限制的。

HTTP方法包括GET, POST, PUT, DELETE, OPTIONS

CORS的Jersey(Restful web service in Java)实现
https://gist.github.com/yunspace/36b0546245c5348a34ed

ref:
http://www.ruanyifeng.com/blog/2016/04/cors.html

Sunday, July 16, 2017

MySQL难点


select ... for update将会锁住任何其他connection的select for update, update, insert。当然还要放入到transaction中。

CREATE DEFINER=`qfu`@`%` PROCEDURE `updateIndex`(IN batchNum INT)
BEGIN

  DROP TEMPORARY TABLE IF EXISTS temp;
  create temporary table temp(id int);
  START TRANSACTION;
  insert into temp
  select id from Dow_Jones_Index2 where isUpdated=0 limit batchNum for update;
  update Dow_Jones_Index2 set isUpdated=1 where id in (select id from temp);
  commit;
  select * from Dow_Jones_Index2 where id in (select id from temp);
  DROP TEMPORARY TABLE IF EXISTS temp;  
END

临时表生命期是session内,如果数据库连接断了,临时表也会消失。相当于mssql中的#temp

---
explain select * from Student where id=5;
可以解释是否用了index。
Using where: 没用到index
Using index: index含有所有信息不需要再查表。The difference is that "Using index" doesn't need a lookup from the index to the table, while "Using index condition" sometimes has to.
Using index condition: 需要再查表

clear cache for performance tuning (workbench)
RESET QUERY CACHE;

ref:
select for update

Saturday, June 24, 2017

Alexa Skill: Word Helper

Word Helper

{
  "intents": [
    {
      "intent": "AMAZON.HelpIntent"
    },
    {
      "intent": "AMAZON.StopIntent"
    },
    {
      "intent": "AMAZON.CancelIntent"
    },
    {
      "intent": "WordHelperAddIntent",
      "slots": [
        {
          "name": "Word",
          "type": "AMAZON.Food"
        }
      ]
    },
    {
      "intent": "WordHelperGetIntent"
    },
    {
      "intent": "WordHelperDeleteIntent",
      "slots": [
        {
          "name": "Word",
          "type": "AMAZON.Food"
        }
      ]
    }
  ]
}

WordHelperAddIntent add {Word}
WordHelperAddIntent put {Word}
WordHelperAddIntent save {Word}
WordHelperDeleteIntent remove {Word}
WordHelperDeleteIntent delete {Word}
WordHelperGetIntent tell me a word
WordHelperGetIntent  give me a word
WordHelperGetIntent tell me something
WordHelperGetIntent give me something

Lambda Test:
use Alexa Intent - GetNewFact


Skill Test:
add bacon
put scrambled egg
save chocolate cake
tell me a word
give me something
remove chocolate cake
delete lemon juice


Ref:
Create a skill steps
Example: Skill with Lambda
How to Config intent with parameter
Skill NodeJS lambda example
Skill NodeJS project example
Skill Java project example
Slot Type reference


https://stackoverflow.com/questions/41358552/how-to-get-the-account-info-of-the-user-when-the-user-uses-an-alexa-skill

Sunday, June 18, 2017

AWS Pipeline简介


CodeCommit: 代码repository。只要有代码commit就会触发pipeline
CodeBuild: 选用python:2.7.12来编译代码,Python需要写buildspec.yml (Python例子),target files表示要copy到目标机器的文件
CodeDeploy: 配置要deploy的目标机器,在目标机器安装CodeDeploy agent,以及触发初始run







































CodeDeploy official
CodeDeploy other

Thursday, June 15, 2017

Python常用library

Linux
sudo apt-get install python2.7


SQLAlchemy: python最流行的ORM工具
Logging: http://www.jianshu.com/p/feb86c06c4f4
YAML: http://www.ruanyifeng.com/blog/2016/07/yaml.html

__init__: 双下划线为保留函数
__name: 私有函数/属性

person_1.py:

class Person:

   def __init__(self):
       self.__name = 'haha'#私有属性
       self.age = 22

   def __get_name(self):##私有方法
       return self.__name

   def get_age(self):
       return self.age

person = Person()
print person.get_age()
print person.__get_name()

不带self就是与object无关
def read_tag(file_name, tag, freq_cutoff=-1, init_dict=True):

Dictionary.read_tag(file_name, 'dialogue', freq_cutoff=freq_cutoff)

带self就是与object相关
def add_word(self, word):

dictionary.add_word(token)

继承:
http://www.cnblogs.com/feeland/p/4419121.html



Python语法

Wednesday, June 7, 2017

Squid反向代理简介 - Linux



sudo su
yum update
yum upgrade
yum -y install squid

vi /etc/squid/squid.conf

http_access allow all

sudo service squid stop
sudo service squid start

https://www.youtube.com/watch?v=BkjKINJIHsk