This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Browser: firefox | |
<img id=“blah” src=“#” /><br> <%= file_field_tag ‘image’, :onchange => “readURL(this)” %> | |
<script type=“text/javascript”> | |
function readURL(input) { | |
if (input.files && input.files[0]) { | |
var reader = new FileReader(); | |
reader.onload = function (e) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set guifont=menlo:h13 | |
set bsdir=buffer | |
set enc=utf-8 | |
set fenc=utf-8 | |
set fencs=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936 | |
syntax on | |
set number | |
set hlsearch | |
set history=200 | |
set tabstop=2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
初级 | |
i: insert模式,按esc返回normal模式 | |
x: 删除当前光标所在的一个字符 | |
s: 删除当前光标所在的一个字符并且变成insert模式 | |
:w: 保存 | |
:q: 退出 | |
hjkl: 光标上下左右的移动 | |
dd: 删除当前行 | |
yy: 复制当前行 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# encoding: utf-8 | |
require 'qiniu-rs' | |
AK = "access_key" | |
SK = "secret_key " | |
bucket_name = "七牛空间名称" | |
backup_file = "待上传文件(绝对路径)" | |
Qiniu::RS.establish_connection!({ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
使用rails搭建个人网站,功能杂,一不小心router代码就写的杂乱无章,想要优化router代码就要好好学习rails的router. | |
## 简单路由 | |
网址url是如何指向到我们想让它去的代码块中,router就是用来干这个的,比如router中这样写: | |
~~~~ ruby | |
get '/members/:id', to: 'members#show' | |
~~~~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
有时由于一些原因需要限制url链接中传过来的参数符合我们定制的规则,对参数的限制在路由配置时使用**constraints**关键定。 | |
例如限制参数id的值以A开头,应该这样写: | |
~~~~ ruby | |
get 'photos/:id', to: 'photos#show', constraints: { id: /[A-Z]\d{5}/ } | |
#等同于 | |
get 'photos/:id', to: 'photos#show', id: /[A-Z]\d{5}/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 概念 | |
### Rack | |
1. A Rack application is an Ruby object (not a class) that responds to **call**. It takes exactly one argument, the environment and returns an Array of exactly three values: **The status**, **the headers**, and **the body**. | |
2. Rack is a framework to roll your own ruby framework. | |
3. Rack provides an interface between different web servers and your framework/application. Making it very simple for your framework/application to be compatible with any webserver that supports Rack – Phusion Passenger, Litespeed, Mongrel, Thin, Ebb, Webrick to name a few. | |
4. Rack cuts your chase. You get request, response, cookies, params & sessions for free. | |
5. Makes it possible to use multiple frameworks for the same application, provided there is no class collision. Rails and sinatra integration is a good example of this. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rack provides a minimal, modular and adaptable interface for developing web applications in Ruby. By wrapping HTTP requests and responses in the simplest way possible, it unifies and distills the API for web servers, web frameworks, and software in between (the so-called middleware) into a single method call. | |
The exact details of this are described in the Rack specification, which all Rack applications should conform to. | |
## Supported web servers | |
The included handlers connect all kinds of web servers to Rack: | |
1. Mongrel | |
2. EventedMongrel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Rack | |
A Quick Introduction to Rack | |
http://rubylearning.com/blog/a-quick-introduction-to-rack/ | |
Ruby on Rack #1 - Hello Rack! | |
http://m.onkey.org/ruby-on-rack-1-hello-rack |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Rack介绍 | |
Rack为使用Ruby开发web应用提供了一个最小的模块化和可修改的接口。用可能最简单的方式来包装HTTP请求和响应,它为web 服务器,web框架和中间件的API进行了统一并提纯到了单一的方法调用。 | |
一个`Rack app`的Ruby对象被调用,参数env包括一个环境变量和请求参数的散列,代码块的返回值由带有三个元素的数组组成: HTTP状态码、响应头和响应体 | |
### HTTP | |
> 超文本转移协议 (HTTP-Hypertext transfer protocol) 是一种详细规定了浏览器和万维网服务器之间互相通信的规则,通过因特网传送万维网文档的数据传送协议。 |
OlderNewer