vkill'blog

“技术本身没有太多价值,掌握了新的思考方式才是真的收获”
Pages: 1/34 First page 1 2 3 4 5 6 7 8 9 10 Next page Final page [ View by Articles | List ]
每次查api都在线,比较慢,所以生成下,离线来看,效果还好

First

gem i RedCloth
gem i sdoc


Then

git clone git://github.com/rails/rails.git
cd rails
git checkout origin/3-1-stable -b 3-1-stable


generate rails api rdoc

rake rdoc
#注:如果出现错误 undefined local variable or method `basedir' for #<RDoc::Generator::SDoc
#解决办法 注释 rails/Rakefile 中的 rdoc.options << '-g'
open doc/rdoc/index.html



sdoc -N rails
#注:这个会生成所有文件的 rdoc,导航看起来有点乱感觉
open doc/index.html


generate guides html

cd railties
rake generate_guides #or ruby guides/rails_guides.rb
open guides/output/index.html



后记:
rbuy 1.9.2 的 rdoc,可以到这里下载 http://railsapi.com/
类别:ruby & rails | Tags: , | 0 条评论, 1284 次阅读
Dec
5
2011
写gem的时候常需要定义一些configuration,这个configuration是可以让用户自己重定义的,方法很多,这里说的是用 Struct ,这样的代码是最少的,很值得用
例子如下,lib/my_gem.rb

#encoding: utf-8
module MyGem
  Configuration = Struct.new(:a, :b, :c).new(3,nil,4)
  def self.configure
    yield Configuration
  end
end
p MyGem::Configuration.a
MyGem.configure do |config|
  config.a = 2
  config.b = 3
end
MyGem::Configuration.each_pair {|k,v| puts("#{k}" => "#{v}")}

类别:ruby & rails | Tags: , , | 0 条评论, 1142 次阅读
Nov
14
2011
一、查看上网卡信息

[root@vkill-arch ~]# pacman -S usbutils

插入上网卡前后比对,我的信息如下

[root@vkill-arch ~]# lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 003: ID 04fc:2801 Sunplus Technology Co., Ltd
Bus 001 Device 004: ID 20b9:1682  
Bus 002 Device 003: ID 192f:0916 Avago Technologies, Pte.


[root@vkill-arch ~]# lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 003: ID 04fc:2801 Sunplus Technology Co., Ltd
Bus 001 Device 005: ID 05c6:1000 Qualcomm, Inc. Mass Storage Device
Bus 002 Device 003: ID 192f:0916 Avago Technologies, Pte.

可以看出 Bus 001 Device 005: ID 05c6:1000 Qualcomm, Inc. Mass Storage Device 这个就是上网卡的信息了
看到上网卡的 idVendor 05c6 和 idProduct 1000,格式是 idVendor:idProduct

二、把上网卡从cd-rom设备转换到modem设备

[root@vkill-arch ~]# pacman -S usb_modeswitch

安装好后到/etc/usb_modeswitch.d/目录运行 #head -n 2 * 就可以看到当前版本usb_modeswitch支持的3g上网卡的型号了

[root@vkill-arch ~]# usb_modeswitch -c /etc/usb_modeswitch.setup

试试成功不,如果不成功,那么试试这个

[root@vkill-arch ~]# usb_modeswitch -v 05c6 -p 1000 -M 5553424312345678000000000000061b000000020000000000000000000000 -R 1
[root@vkill-arch ~]# modprobe usbserial vendor=0x05c6 product=0x1000
[root@vkill-arch ~]# ls /dev/tty*

看能不能看的到ttyUSB0这些,如果有则继续,如果无请另寻它法

三、开始拨号

[root@vkill-arch ~]# pacman -S wvdial


[root@vkill-arch ~]# wvdialconf
会自动生成 /etc/wvdial.conf
再添加下面几行进去(电信cdma的例子,电话号码:#777 用户名:ctnet@mycdma.cn(或是card) 密码: vnet.mobi (或是card))
Phone = #777
Username = ctnet@mycdma.cn
Password = vnet.mobi
Stupid Mode = 1


[root@vkill-arch ~]# wvdial


参考资料:
http://www.linuxsir.org/bbs/showthread.php?t=352115
http://groups.google.com/group/hzlug/browse_thread/thread/95a3b678673f3d8e
https://wiki.archlinux.org/index.php/USB_3G_Modem
https://wiki.archlinux.org/index.php/Wvdial
类别:linux system | Tags: , , , , | 0 条评论, 1381 次阅读
Nov
3
2011
rails_kindeditor 见这里 https://github.com/Macrow/rails_kindeditor,使用很方便
但是在后台使用的时候每次上传图片就会 session 丢失
看了 post 的参数发现是没有提交 authenticity_token
网上没找到解决方案,没法,只有改js源码了

kindeditor/kindeditor-init.js 是这里定义的 uploadJson: "/kindeditor/upload" ,也就是上传的地址,本想在后面加 ?authenticity_token=xxxx 这样的
但是后面的 kindeditor/plugins/image/image.js 里这样使用了 url : uploadJson + '?dir=image' ,
那么只有改 kindeditor/plugins/image/image.js 了,改成下面这样就ok了

#kindeditor/plugins/image/image.js
url : uploadJson + '?dir=image' + "&" + encodeURIComponent($("[name='csrf-param']").attr("content")) + "=" + encodeURIComponent($("[name='csrf-token']").attr("content")),


ok,就这样解决就好,rails_kindeditor 这个定义 uploadJson 不怎么好,要是定义成 uploadJson: "/kindeditor/upload?" ,image.js 中这样使用 url : uploadJson + '&dir=image' ,这样就好扩展多了
类别:ruby & rails | Tags: , , , , , , , | 1 条评论, 2338 次阅读
Sep
19
2011
比如我们登录成功的时候要执行一些 background jobs,那这里可能就会用 resque,那么有个问题就是登录成功后如何得知那些 background jobs 的状态呢? resque-status 这个gem就可以搞定了

先看下面的代码

require 'rubygems'
require 'pry'
require 'resque'

Resque.redis = 'localhost:6379'
Resque.redis.namespace = "resque:vkill.net"

require 'resque/job_with_status'
Resque::Status.expire_in = (24 * 60 * 60)

class SleepJob < Resque::JobWithStatus
  def perform
    total = options['length'].to_i || 1000
    num = 0
    while num < total
      at(num, total, "At #{num} of #{total}")
      sleep(1)
      num += 1
    end
    completed
  end
end

job_id = SleepJob.create(:length => 100)
status = Resque::Status.get(job_id)
binding.pry

=begin

[root@vkill-arch ~]# ruby resque-status_demo.rb

From: resque-status_demo.rb @ line 27 in Object#N/A:

    22:   end
    23: end
    24:
    25: job_id = SleepJob.create(:length => 100)
    26: status = Resque::Status.get(job_id)
=> 27: binding.pry
    28:
pry(main)> job_id
=> "60c3b710bdba012e7b916c55f9208b32"
pry(main)> Resque::Status.status_ids
=> ["60c3b710bdba012e7b916c55f9208b32",
"61858fb0bdb9012e7b906c55f9208b32",
"3b377730bdb9012e7b8f6c55f9208b32"]

=end



通过上面代码就可以理出思路, 登录成功后 执行 job,并把 job_id 存储在服务器端,然后把 job_id 返回给浏览器,浏览器就可以ajax 循环请求服务器来得知backgroud jobs 的执行情况了
类别:ruby & rails | Tags: , , , , | 0 条评论, 1554 次阅读
Sep
10
2011
django 的 request.POST 这些不能直接来添加,可以copy 后 edit 然后再 replace 就ok了,这里要注意的是 request.REQUEST 不能这样改,下面是我写的实例方法来改的代码


    def update_request_GET(self, data={}):
        if  self.request.method in ("GET"):
            new_PARAMS = self.request.GET.copy()
        else:
            new_PARAMS = self.request.POST.copy()
        for k,v in data.items():
            new_PARAMS[k] = v
        if  self.request.method in ("GET"):
            self.request.GET = new_PARAMS
        else:
            self.request.POST = new_PARAMS
        self.request.PARAMS = new_PARAMS
        return self.request

    def update_request_POST(self, data={}):
        return self.update_request_GET(data)

    def update_request_META(self, data={}):
        new_META = self.request.META.copy()
        for k,v in data.items():
            new_META[k] = v
        self.request.META = new_META
        return self.request
类别:python & django | Tags: , , , | 0 条评论, 1868 次阅读
Aug
26
2011
Pages: 1/34 First page 1 2 3 4 5 6 7 8 9 10 Next page Final page [ View by Articles | List ]