Skip to content

Instantly share code, notes, and snippets.

View liwh's full-sized avatar
🎯
Focusing

robie lee liwh

🎯
Focusing
View GitHub Profile

Routes

小心地使用 Match(Rails 3 已实现)

Rails 3 提供了 match 方法供我们自定义 routes,然而我们要小心使用它以避免“跨站脚本攻击”(XSS Attack)。比如像这样的 routes:

注:(r3 代表 Rails 3,r4 代表 Rails 4)

# routes.rb
useradd nagios
mkdir -p /opt/install_file
cd /opt/install_file
scp 10.103.13.148:/opt/install_file/nagios-plugins-1.5.tar.gz /opt/install_file
scp 10.103.13.148:/opt/install_file/nrpe-2.15.tar.gz /opt/install_file
tar xvfz nagios-plugins-1.5.tar.gz
cd nagios-plugins-1.5
./configure --prefix=/opt/nagios
make && make install
chown nagios.nagios /opt/nagios

Fibur

Fibur is a library that allows concurrency during Ruby I/O operations without needing to make use of callback systems. Traditionally in Ruby, to achieve concurrency during blocking I/O operations, programmers would make use of Fibers and callbacks. Fibur eliminates the need for wrapping your I/O calls with Fibers and a callback. It allows you to write your blocking I/O calls the way you normally would, and still have concurrent execution during those I/O calls.

Example

Say you have a method that fetches data from a network resource:

2091039935
99669999996669999996699666699666999966699666699
99699999999699999999699666699669966996699666699
99669999999999999996699666699699666699699666699
99666699999999999966666999966699666699699666699
99666666999999996666666699666699666699699666699
99666666669999666666666699666669966996699666699
99666666666996666666666699666666999966669999996
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from util import api, settings
from v3._base import CachedPlusHandler, BaseHandler, UserClient
import json
import logging
import urllib2
from service import service_ugc, service_user, service_connection
from service.connection import ttypes
@liwh
liwh / gist:3726374
Created September 15, 2012 04:48
error trace
[E 120915 12:47:46 web:1085] Uncaught exception GET /v1/videos/append?vids=XNDUwNTc4MDI0,XNDUwNTc3MTY4,XNDM2MTg1MDY4,XMzg5NTg4ODYw&size_set=4 (127.0.0.1)
HTTPRequest(protocol='http', host='localhost:11535', method='GET', uri='/v1/videos/append?vids=XNDUwNTc4MDI0,XNDUwNTc3MTY4,XNDM2MTg1MDY4,XMzg5NTg4ODYw&size_set=4', version='HTTP/1.1', remote_ip='127.0.0.1', body='', headers={'Host': 'localhost:11535', 'User-Agent': 'Python-urllib/2.7', 'Connection': 'close', 'Accept-Encoding': 'identity'})
Traceback (most recent call last):
File "/opt/python2.7/lib/python2.7/site-packages/tornado-2.4-py2.7.egg/tornado/web.py", line 1021, in _stack_context_handle_exception
raise_exc_info((type, value, traceback))
File "/opt/python2.7/lib/python2.7/site-packages/tornado-2.4-py2.7.egg/tornado/web.py", line 1139, in wrapper
return method(self, *args, **kwargs)
File "/opt/paike/gof/modules/video/v1/video_info.py", line 133, in get
self.async_send_request('video', context, 'video.a
@liwh
liwh / gist:3058684
Created July 6, 2012 07:31
update mongodb
db.paike_video.update({"$or" : [{"loc.0": {"$gt": 180} },{"loc.0":{"$lt":-180}},{"loc.1":{"$lt": -90}},{"loc.1":{"$gt":90}}]},{"$set":{"loc":[0,0]}},false,true)
#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
CLIEXEC=/usr/local/bin/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
@liwh
liwh / lbs api.md
Created June 25, 2012 08:44
lbs api.md

###需求

  • 根据经纬度查询附近位置的中文描述
  • 保存视频ID以及该视频经纬度,和其位置的描述
  • 根据视频ID可以查询视频的经纬度,以及所处地方的描述
  • 根据视频ID可以查询视频的经纬度,以及所处地方的描述(批量接口)
  • 根据视频ID或经纬度查询附近的视频 ###接口定义
根据视频ID或经纬度查询附近的视频