`
fireflyman
  • 浏览: 113155 次
  • 性别: Icon_minigender_1
  • 来自: 火星
社区版块
存档分类
最新评论
收藏列表
标题 标签 来源
从数组取随机数 ruby Ruby实现,从数组中随机取数!
class Array
  def random(weights)
    weights ||= [1.0] * length
    total = weights.inject(0.0) {|sum, w| sum + w}
    point = rand * total

    zip(weights).sort{|a, b| a[1] <=> b[1]}.each do |element, weight|
      return element if weight >= point
      point -= weight
    end
  end
end
eventmachine helloworld ruby hello EventMachine
#!/usr/bin/env ruby
require 'rubygems'
require 'eventmachine'
EM.run do
  EM::PeriodicTimer.new(1) do
    puts Time.now
  end
end

文本框 js 控制文本框内文字
<script type="text/javascript">
  function clearText(theField)
  {
    if (theField.defaultValue == theField.value)
      theField.value = '';
  }

  function addText(theField)
  {
    if (theField.value == '')
      theField.value = theField .defaultValue;
  }
</script>
<input type="text" name="name" onblur="addText(this);" onfocus="clearText(this)" value="请输入关键字..." /> 
paperclip+id_partition rails_plugins 用paperclip中的id_partition代替id
  has_attached_file :picture, :styles => {:medium => "480x360>", :thumb => "120x90>", :original =>"480x360>"},
    :path => ":rails_root/public/uploads/:class/:id_partition/:style/picture.:extension",
    :url => "/uploads/:class/:id_partition/:style/picture.:extension"
tiny_mce详细配置 rails_plugins ror(rails)中使用tinymce过程详解及问题解答_20090707更新
  uses_tiny_mce( :options => {
      :theme => 'advanced',  # 皮肤
      :language => 'zh',  # 中文界面
      :convert_urls => false, # 不转换路径,否则在插入图片或头像时,会转成相对路径,容易导致路径错乱。
      :theme_advanced_toolbar_location => "top",  # 工具条在上面
      :theme_advanced_toolbar_align => "left",
      :theme_advanced_resizing => true,  # 似乎不好使
      :theme_advanced_resize_horizontal => false,
      :paste_auto_cleanup_on_paste => true,
      # 工具条上的按钮布局
      :theme_advanced_buttons1 => %w{formatselect fontselect fontsizeselect forecolor backcolor bold italic underline strikethrough sub sup removeformat},
      :theme_advanced_buttons2 => %w{undo redo cut copy paste separator justifyleft justifycenter justifyright separator indent outdent separator bullist numlist separator link unlink image media emotions separator table separator fullscreen},
      :theme_advanced_buttons3 => [],
      # 字体列表中显示的字体
      :theme_advanced_fonts => %w{宋体=宋体;黑体=黑体;仿宋=仿宋;楷体=楷体;隶书=隶书;幼圆=幼圆;Andale Mono=andale mono,times;Arial=arial,helvetica,sans-serif;Arial Black=arial black,avant garde;Book Antiqua=book antiqua,palatino;Comic Sans MS=comic sans ms,sans-serif;Courier New=courier new,courier;Georgia=georgia,palatino;Helvetica=helvetica;Impact=impact,chicago;Symbol=symbol;Tahoma=tahoma,arial,helvetica,sans-serif;Terminal=terminal,monaco;Times New Roman=times new roman,times;Trebuchet MS=trebuchet ms,geneva;Verdana=verdana,geneva;Webdings=webdings;Wingdings=wingdings,zapf dingbats}, # 字体
      # :force_br_newlines => true, # 此选项强制编辑器将段落符号(P)替换成换行符(BR)。不建议用:ff下不好使,用了此选项后,输入内容的居中、清单或编号都被破坏。
      :plugins => %w{contextmenu paste media emotions table fullscreen}},
    :only => [:new, :edit, :show, :index, :create, :update])  # tiny_mce考虑的非常贴心,这里是限定哪些action中起用
Global site tag (gtag.js) - Google Analytics