`
文章列表
package com.wilson.jdk5current; import java.io.File; import java.io.FileFilter; import java.util.concurrent.BlockingQueue; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.atomic.Ato ...
CountDownLatch,一个同步辅助类,在完成一组正在其他线程中执行的操作之前,它允许一个或多个线程一直等待。 主要方法 public CountDownLatch(int count); public void countDown(); public void await() throws InterruptedException 构造方法参数指定了计数的次数 countDown方法,当前线程调用此方法,则计数减一 awaint方法,调用此方法会一直阻塞当前线程,直到计时器的值为0 public class CountDownLatchDemo { final st ...
public class MyThreadPrinter2 implements Runnable { private final String name; private final Object prev; private final Object self; private MyThreadPrinter2(String name, Object prev, Object self) { this.name = name; this.prev = prev; this.self ...
安装GEM Markdown是时下很流行的一种标记语言。 可以很简便的生成html代码,github的README就是用这种形式显示再代码目录的下面。 Ruby/Rails借助繁多的Gem,可以迅速的就做好markdown的支持,顺道包含对代码高亮的支持。 Gem太多,实现方法也太多。 下面就介绍一种比较迅速开发的办法。用了redcarpet和CodeRay两个Gem。 gem 'redcarpet' gem 'coderay' 打开app/helper/application_helper.rb, 添加下列代码。 def markdown(text) ...
cmd + option + L 显示行号 cmd + F 页面搜索文字 cmd + shift + F 项目搜索文字 cmd + G 下一个搜索文字 cmd + shift + G 上一个搜索文字 cmd + option + F 替换一个 cmd + ctrl + F 全部替换 cmd + S 保存 cmd + option + S 全部保存 cmd + shift + S 另存为。。。。 cmd + shift + ...
github完整项目 https://github.com/seyhunak/twitter-bootstrap-rails rails new demo --skip-bundle rails g scaffold Item title:string description:text --skip-stylesheets rake db:migrate gem "therubyracer" gem "less-rails" #Sprockets (what Rails 3.1 uses for its a ...
public class HttpDownloadUtility { private static final Logger logger = LoggerFactory.getLogger(HttpDownloadUtility.class); private static final int BUFFER_SIZE = 4096; private static final int END_OF_FILE = -1; public static boolean downloadFile(String fileURL, File saveDi ...
引用Selenium可以用来模拟浏览器页面点击,可以用来做页面功能测试,也可以用来做一些自动化脚本,它提供啦ruby版本实现,本文基于IE,当然它也支持其它主流浏览器 1. 安装selenium-webdriver gem install selenium-webdriver 2. 安装Internet Explorer Driver Server,解压出来的EXE添加到path路径上面 http://code.google.com/p/selenium/downloads/detail?name=IEDriverServer_Win32_2.33.0.zip 3. 简单的测试脚本(程序流 ...
引用本文是ehcache RMI集群的例子,导入附件中的java 项目到eclipse中,依次启动附件中的A.java,B.java,C.java, 就可以在eclipse的console中就可以看到3个cache的内容同步啦 1. ehcache 配置文件 <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ehcache.xsd"> <cacheManagerPeerProviderFact ...
引用Database testing Unit tests for the database layer can be extremely valuable when building enterprise applications, but are often abandoned because of their complexity. Unitils greatly reduces this complexity, making database testing easy and maintainable. The following sections describe the suppor ...
1. 新建国际化配置文件config\initializers\i18n.rb I18n.default_locale = 'en' LOCALES_DIRECTORY = "#{RAILS_ROOT}/config/locales/" LANGUAGES = { 'English' => 'en', "Espa\xc3\xb1ol" => 'es', "中文" => 'zh' } 2. 在视图页面中添加语言切换下拉框 <% form_tag '', :method => ...
1. 创建一个保存文件的表,然后rake db:migrate同步到数据库 class CreatePictures < ActiveRecord::Migration def self.up create_table :pictures do |t| t.string :comment t.string :name t.string :content_type # If using MySQL, blobs default to 64k, so we have to give # an explicit ...
1. config\environment.rb中添加smtp邮件配置,以163邮件服务器为例 Rails::Initializer.run do |config| 。。。 config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { :address => "smtp.163.com", #smtp邮件服务器 :port =>25,#端口 :domain => "www.163. ...
引用分页是web开发中常见的问题,基本解决思路是每次查询当页的数据,在java中我们需要利用一些持久化框架才能实现各种数据库的通用分页逻辑。 然而在rails中我们只需安装will_paginate插件,简单的非常 1 用gem安装will_paginate插件 gem install mislav-will_paginate -v2.3.2 --source http://gems.github.com 添加如下代码到config\environment.rb require 'will_paginate' 2 新建app\controllers\pager_controller.r ...

Ruby 代码块

 
引用Ruby代码块可以通过yield方法传递给被调用的方法 1 测试类 require 'book' require 'booklist' booklist = BookList.new() b1 = Book.new("iPod","123") b2 = Book.new("How Objects Work","2") booklist.add(b1) booklist[1]=b2 print booklist[0].title, "\n" print booklist[1] ...
Global site tag (gtag.js) - Google Analytics