Skip to content

Instantly share code, notes, and snippets.

View jay16's full-sized avatar

俊杰.li jay16

View GitHub Profile
@jay16
jay16 / redis-backup.sh
Created October 8, 2016 13:56 — forked from acenqiu/redis-backup.sh
redis rdb backup script
#!/bin/bash
#
## redis backup script
## usage
## redis-backup.sh port backup.dir
port=${1:-6379}
backup_dir=${2:-"/data/backup/redis"}
cli="/usr/local/bin/redis-cli -p $port"
require './application'
namespace :routes do
task :show do
endpoints = {}
if Sinatra::Application.descendants.any?
#Classic application structure
applications = Sinatra::Application.descendants
applications.each do |app|
@jay16
jay16 / mkgitignore
Last active August 29, 2015 14:21 — forked from wusuopu/mkgitignore
#!/bin/bash
if [[ $@ != "" ]]; then
if [[ $2 != "" ]]; then
curl http://www.gitignore.io/api/$1 -o $2
else
curl http://www.gitignore.io/api/$1
fi
else
echo 创建gitignore文件
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
# 有关 Fiber 的解释: (按照数据流的方向分为两部分)
# 在 `主线程' 中使用 resume 方法来启动(或继续执行)一个 `纤程'.
# 1. 第一次调用 fiber.resume, 会启动一个纤程,
# 如果 resume 调用时提供了实参, 会作为代码块形参传入代码块.
# 2. 如果非第一次调用 fiber.resume, 即, `恢复' 一个纤程, 会做两件事:
# - 从上次离开纤程的那个位置(调用 Fiber.yield 离开纤程的那个位置), 恢复纤程的执行.
#!/usr/bin/env ruby
# List all keys stored in memcache.
# Credit to Graham King at http://www.darkcoding.net/software/memcached-list-all-keys/ for the original article on how to get the data from memcache in the first place.
require 'net/telnet'
headings = %w(id expires bytes cache_key)
rows = []
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@jay16
jay16 / goto-test.rb
Last active August 29, 2015 14:06 — forked from alexbevi/goto-test.rb
require 'goto'
def test
frame_start
label(:start) { goto :b }
label(:a) { print "world!\n"; goto :c }
label(:b) { print "hello "; goto :a }
@jay16
jay16 / gist:280b67d7cbd8603806b7
Last active April 12, 2016 23:26 — forked from anonymous/gist:c6b2b4c7f9673c60108c
qlikview marco export EXCEL
Sub ExcelPrint
Call exportToExcel_ALL()
End Sub
Public Function exportToExcel_ALL()
Dim aryExport(14,3)
aryExport(0,0) = "CH57"
aryExport(0,1) = "直营业绩周报表"
aryExport(0,2) = "A1"
aryExport(0,3) = "data"

最近在看Sinatra 1.3.5的源码。在Sinatra::Helpers模块中看到一个名为uri的方法,用来将一个相对路径转换为绝对路径。在该函数的代码中看到分别针对request.script_name和request.path_info进行了处理。但是并不清楚这两个参数的区别,于是做了一些reseach。

二者在RFC3875中有如下定义:

4.1.13. SCRIPT_NAME

The SCRIPT_NAME variable MUST be set to a URI path (not URL-encoded) which could identify the CGI script (rather than the script's output). The syntax is the same as for PATH_INFO (section 4.1.5) >

#!/usr/bin/env ruby
# Libraries:::::::::::::::::::::::::::::::::::::::::::::::::::::::
require 'rubygems'
require 'sinatra/base'
require 'slim'
require 'sass'
require 'coffee-script'
# Application:::::::::::::::::::::::::::::::::::::::::::::::::::