#32 转载:SQL 注入一点小心得

2013-11-10

好久没写技术博客,最近研究产品关于用户体验方面较多,加上项目突然比较多,设计原型、跟进开发、设计师等工作着实没时间写博客。
接下来技术上主要 php 深入学习和 mysql 优化。这两天看了关于 sql 注入方面的知识,拿出来分享一下 :)

#29 转载:如何掌握程序语言

2013-10-22

学习程序语言是每个程序员的必经之路。可是这个世界上有太多的程序语言,每一种都号称具有最新的“特性”。所以程序员的苦恼就在于总是需要学习各种稀奇古怪的语言,而且必须紧跟“潮流”,否则就怕被时代所淘汰。
作为一个程序语言的研究者,我深深的知道这种心理产生的根源。程序语言里面其实有着非常简单,永恒不变的原理。看到了它们,就可以在很短的时间之内就能学会并且开始使用任何新的语言,而不是花费很多功夫去学习一个又一个的语言。

#28 转载:脚下的流沙

2013-10-17

这么多年来,一直是我脚下的流沙裹着我四处漂泊,它也不淹没我,它只是时不时提醒我,你没有别的选择,否则你就被风吹走了。我就这么浑浑噩噩地度过了我所有热血的岁月,被裹到东,被裹到西,连我曾经所鄙视的种子都不如。

#27 Tornado 1,2,3

2013-10-13

Tornado web server 是使用 Python 编写出來的一个极轻量级、高可伸缩性和非阻塞 IO 的 Web 服务器软件,著名的 Friendfeed 网站就是使用它搭建的。

Tornado 跟其他主流的 Web 服务器框架(主要是 Python 框架)不同是采用 epoll 非阻塞 IO,响应快速,可处理数千并发连接,特别适用用于实时的 Web 服务。

要使用它,必须按照以下套件:

1)Python(建议使用 Python 2.5 / Python 2.6)
2)Simplejson(建议使用 simplejson 2.0.9)
3)cURL(建议使用 curl 7.19.7 或以上版本)
4)Pycurl(建议使用 pycurl 7.16.2.1)
5)Tornado Web Server(这才是主角,版本就照官網上最新的安裝吧)

一个最简单的服务:

import tornado.ioloop
import tornado.web

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, world")

application = tornado.web.Application([
    (r"/", MainHandler),
])

if __name__ == "__main__":
    application.listen(8888)
    tornado.ioloop.IOLoop.instance().start()

在 Tornado 中运行 Django

#!/usr/bin/env python
# *-* encoding: utf-8 *-*

import os
import sys
import tornado.web
from tornado import autoreload
from tornado.wsgi import WSGIContainer
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
from tornado.web import url
from django.conf import settings
from django.core.handlers.wsgi import WSGIHandler

if not os.path.dirname(__file__) in sys.path[:1]:
    sys.path.insert(0, os.path.dirname(__file__))

os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

class Application(tornado.web.Application):
    def __init__(self):
        handlers = [
            url(r"/static/(.+)", tornado.web.StaticFileHandler, dict(path=settings.MEDIA_ROOT), name='static_path'),
            url(r"/media/(.+)", tornado.web.StaticFileHandler, dict(path=settings.MEDIA_ROOT), name='media_path'),
        ]
        handlers.append(('.*', tornado.web.FallbackHandler, dict(fallback=WSGIContainer(WSGIHandler()))))

tornado.web.Application.__init__(self, handlers)
http_server = HTTPServer(Application())
http_server.listen(8080)
loop = IOLoop.instance()
autoreload.start(loop) #自动加载修改过的代码
loop.start()

#26 HTTP 状态码

2013-10-01

状态码

Informational responses (100–199)

信息

  • 100 Continue
  • 101 Switching Protocol
  • 102 Processing
  • 103 Early Hints

Successful responses (200–299)

成功

  • 200 OK
  • 201 Created
  • 202 Accepted
  • 203 Non-Authoritative Information
  • 204 No Content
  • 205 Reset Content
  • 206 Partial Content
  • 207 Multi-Status
  • 208 Already Reported
  • 226 IM Used

Redirects (300–399)

重定向

  • 300 Multiple Choice
  • 301 Moved Permanently
  • 302 Found
  • 303 See Other
  • 304 Not Modified
  • 307 Temporary Redirect
  • 308 Permanent Redirect

Client errors (400–499)

客户端错误

  • 400 Bad Request
  • 401 Unauthorized
  • 402 Payment Required
  • 403 Forbidden
  • 404 Not Found
  • 405 Method Not Allowed
  • 406 Not Acceptable
  • 407 Proxy Authentication Required
  • 408 Request Timeout
  • 409 Conflict
  • 410 Gone
  • 411 Length Required
  • 412 Precondition Failed
  • 413 Payload Too Large
  • 414 URI Too Long
  • 415 Unsupported Media Type
  • 416 Range Not Satisfiable
  • 417 Expectation Failed
  • 418 I'm a teapot
  • 421 Misdirected Request
  • 422 Unprocessable Entity
  • 423 Locked
  • 424 Failed Dependency
  • 425 Too Early
  • 426 Upgrade Required
  • 428 Precondition Required
  • 429 Too Many Requests
  • 431 Request Header Fields Too Large
  • 451 Unavailable For Legal Reasons

Server errors (500–599)

服务器错误

  • 500 Internal Server Error
  • 501 Not Implemented
  • 502 Bad Gateway
  • 503 Service Unavailable
  • 504 Gateway Timeout
  • 505 HTTP Version Not Supported
  • 506 Variant Also Negotiates
  • 507 Insufficient Storage
  • 508 Loop Detected
  • 510 Not Extended
  • 511 Network Authentication Required

JSON

{
    "100": "Continue",
    "101": "Switching Protocol",
    "102": "Processing",
    "103": "Early Hints",
    "200": "OK",
    "201": "Created",
    "202": "Accepted",
    "203": "Non-Authoritative Information",
    "204": "No Content",
    "205": "Reset Content",
    "206": "Partial Content",
    "207": "Multi-Status",
    "208": "Already Reported",
    "226": "IM Used",
    "300": "Multiple Choice",
    "301": "Moved Permanently",
    "302": "Found",
    "303": "See Other",
    "304": "Not Modified",
    "307": "Temporary Redirect",
    "308": "Permanent Redirect",
    "400": "Bad Request",
    "401": "Unauthorized",
    "402": "Payment Required",
    "403": "Forbidden",
    "404": "Not Found",
    "405": "Method Not Allowed",
    "406": "Not Acceptable",
    "407": "Proxy Authentication Required",
    "408": "Request Timeout",
    "409": "Conflict",
    "410": "Gone",
    "411": "Length Required",
    "412": "Precondition Failed",
    "413": "Payload Too Large",
    "414": "URI Too Long",
    "415": "Unsupported Media Type",
    "416": "Range Not Satisfiable",
    "417": "Expectation Failed",
    "418": "I'm a teapot",
    "421": "Misdirected Request",
    "422": "Unprocessable Entity",
    "423": "Locked",
    "424": "Failed Dependency",
    "425": "Too Early",
    "426": "Upgrade Required",
    "428": "Precondition Required",
    "429": "Too Many Requests",
    "431": "Request Header Fields Too Large",
    "451": "Unavailable For Legal Reasons",
    "500": "Internal Server Error",
    "501": "Not Implemented",
    "502": "Bad Gateway",
    "503": "Service Unavailable",
    "504": "Gateway Timeout",
    "505": "HTTP Version Not Supported",
    "506": "Variant Also Negotiates",
    "507": "Insufficient Storage",
    "508": "Loop Detected",
    "510": "Not Extended",
    "511": "Network Authentication Required"
}

参考资料与拓展阅读

#25 SEO:sitemap 和 robots.txt

2013-09-30

给本站加上了 sitemap.xmlrobots.txt

SEO 常用工具中有两个:站点地图(sitemap)和爬虫协议禁止抓取文件(robots.txt)。

请原谅我用一个这么长的名字来称呼 robots.txt

站点地图

  1. UTF-8 编码
  2. 单个文件大小不能超过 50MB,其中 URL 数量不能超过 50 万,如果超出限制可以创建多个 sitemap,然后通过 sitemap 索引文件将其连接。
  3. 遵守 XML 规范,需要对 & 符号 (&)、单引号 (')、双引号 (")、小于号 (<) 和大于号 (>) 进行实体符号转义。很重要!

结构类似:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    <url>
        <loc>http://www.example.com/aaa</loc>
        <lastmod>2005-01-01</lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.8</priority>
    </url>
    <url>
        <loc>http://www.example.com/bbb</loc>
        <lastmod>2005-01-01</lastmod>
        <changefreq>weekly</changefreq>
        <priority>0.7</priority>
    </url>
    <url>
        <loc>http://www.example.com/ccc</loc>
        <lastmod>2005-01-01</lastmod>
        <changefreq>daily</changefreq>
        <priority>0.7</priority>
    </url>
</urlset>

PS: XML 也可以使用样式,本站就有个简单的样式,可以打开 sitemap 页面看看。
就是在 urlset 前加了个样式表:<?xml-stylesheet type="text/xsl" href="sitemap.xsl"?> 样式表连接

爬虫协议

告诉爬虫不要采集指定的路径。

不过这个其实谈不上协议,只是行业内的一个约定而已,大厂家尚且不一定严格遵守(百度诉360违反Robots协议案开庭 百度索赔1亿元)。

其他 SEO 工具或方法

反链

以下内容来自:维基百科 - 反向链接

反向链接是指A站通过域名或锚文本指向B站,从而使网站权重得到提升。

增加反向链接方法

在论坛签名内加上网站名,发言时就会带上网站链接
创建博客,在更新的文章内加上网址
到各个相关门户投稿,并加上网站链接
购买链接,这种方法不太稳定,不建议采用
在别人博客留言
和其他网站交换友情链接

反向链接作用

对于SEO而言,反向链接能够使网站获得好的排名,所以,反向链接的好坏直接影响网站的整体权重和流量。

参考