##基本信息
- 开来超 男 山东菏泽 1989年1月生
- 苏州科技学院 本科 教育心理学
- 手机 13738091353
- E-mail: klc1989110@gmail.com
- QQ:383245294
- 现居杭州,准备去上海
##教育经历
##基本信息
##教育经历
god使用ruby写的监控框架,优点是配置文件也是用ruby代码。 | |
[官网](http://godrb.com/) | |
简单使用: | |
simple.rb | |
```ruby | |
loop do | |
puts "hello" | |
sleep 5 | |
end | |
``` |
#Rails中打造用户认证系统
相信很多人都知道或者用过Devise这个gem,它在github上有将近1w3的star。但是它十分庞大和复杂,代码很难读懂,据说想学习Rails源码的话可以先看Devise的源码。使用Devise最大的问题就是定制比较困难,需要搜索文档后覆盖一些方法,但是却不知道原理。
其实实现用户认证并不复杂,完全可以从头写一个,没必要使用gem来实现。Rails的ActiveModel里面有SecurePassword,用它可以很容易的实现认证功能。本文使用Rails的SecurePassword 一步步完善用户认证系统。
##Model
首先使用 $rails g model users email:string password_digest:string
新建一个User model,有email和password_digest两个字段。其中password_digest很重要的,是存放加密后的密码的字段。
接下来需要在 User 中调用 has_secure_password 方法。
require 'redis' | |
class Connpool | |
DEFAULTS = { size: 5 } | |
def initialize(options = {}, &block) | |
raise ArgumentError, 'Conn pool requires a block' unless block | |
options = DEFAULTS.merge(options) | |
@size = options.fetch(:size) | |
@available = Queue.new |
#simple delegate, can not use in production | |
class Module | |
def delegate(*methods) | |
options = methods.pop | |
unless options.is_a?(Hash) && to = options[:to] | |
raise ArgumentError, "Delegation need a target.Supply an options with a :to key as the last argument(e.g. delegate :hello, to: :greet" | |
end | |
to = to.to_s | |
file, line = caller(1,1).first.split(':') |
;see http://www.yinwang.org/blog-cn/2012/08/01/interpreter | |
; Clojure 实现的一个简单解释器,是dynamic scope 的 | |
(def env0 {}) | |
(defn ext-env [x v env] | |
(assoc env x v)) | |
(defn lookup | |
"" | |
[x env] |