About neohope

一直在努力,还没想过要放弃...

mongrel.rb

使用Redmin1.3.2时,用命令行可以启动,但使用mongrel_service-0.4.0启动后会发生重定向
只需要将mongrel.rb拷贝到redmine-1.3.2\config\initializers下面就好了

mongrel.rb

if ['2.3.8', '2.3.9', '2.3.10', '2.3.11', '2.3.14'].include?(Rails.version) && Gem.available?('mongrel', '~>1.1.5') && self.class.const_defined?(:Mongrel)
  
  # Pulled right from latest rack. Old looked like this in 1.1.0 version.
  #
  # def [](k)
  # super(@names[k] ||= @names[k.downcase])
  # end
  #
  module Rack
    module Utils
      class HeaderHash < Hash
        def [](k)
          super(@names[k]) if @names[k]
          super(@names[k.downcase])
        end
      end
    end
  end
  
  # Code pulled from the ticket above.
  #
  class Mongrel::CGIWrapper
    def header_with_rails_fix(options = 'text/html')
      @head['cookie'] = options.delete('cookie').flatten.map { |v| v.sub(/^\n/,'') } if options.class != String and options['cookie']
      header_without_rails_fix(options)
    end
    alias_method_chain :header, :rails_fix
  end
  
  # Pulled right from 2.3.8 ActionPack. Simple diff was
  #
  # if headers.include?('Set-Cookie')
  # headers['cookie'] = headers.delete('Set-Cookie').split("\n")
  # end
  #
  # to
  #
  # if headers['Set-Cookie']
  # headers['cookie'] = headers.delete('Set-Cookie').split("\n")
  # end
  #
  module ActionController
    class CGIHandler
      def self.dispatch_cgi(app, cgi, out = $stdout)
        env = cgi.__send__(:env_table)
        env.delete "HTTP_CONTENT_LENGTH"
        cgi.stdinput.extend ProperStream
        env["SCRIPT_NAME"] = "" if env["SCRIPT_NAME"] == "/"
        env.update({
          "rack.version" => [0,1],
          "rack.input" => cgi.stdinput,
          "rack.errors" => $stderr,
          "rack.multithread" => false,
          "rack.multiprocess" => true,
          "rack.run_once" => false,
          "rack.url_scheme" => ["yes", "on", "1"].include?(env["HTTPS"]) ? "https" : "http"
        })
        env["QUERY_STRING"] ||= ""
        env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
        env["REQUEST_PATH"] ||= "/"
        env.delete "PATH_INFO" if env["PATH_INFO"] == ""
        status, headers, body = app.call(env)
        begin
          out.binmode if out.respond_to?(:binmode)
          out.sync = false if out.respond_to?(:sync=)
          headers['Status'] = status.to_s
          if headers['Set-Cookie']
            headers['cookie'] = headers.delete('Set-Cookie').split("\n")
          end
          out.write(cgi.header(headers))
          body.each { |part|
            out.write part
            out.flush if out.respond_to?(:flush)
          }
        ensure
          body.close if body.respond_to?(:close)
        end
      end
    end
  end
end

SQL查询100到200行

--SQL Server
--top
select top 100 * from table
where id is not in(select top 100 id from table)
--row_number()
select r.*, row_number() over(order by id desc) as r from table where r>100 and r<=200


--MySQL
--limit
select * from  table limit 100,200;


--Oracle
--rownum
select * from (select rownum r,t.* from table t) where r>100 and r<=200;

SQL获取自增字段的值

数据插入后,如何获取自增字段的数值呢?可以用下面的方法
(建议进行事务控制)

--SQL Server
--当前会话,当前作用域
select SCOPE_IDENTITY() as id
--当前会话,不限定作用域
select @@identity as id
--指定表,不限定会话和作用域
select IDENT_CURRENT ('table_name')


--MySQL
--当前会话
SELECT LAST_INSERT_ID();
select @@IDENTITY as id


--Oracle
--当前会话
select seq_name.currval from dual

搭建Redmine

1.下载Ruby1.87及DevKit,解压,并将两个bin目录加入到PATH
http://rubyinstaller.org/downloads/

2.下载RubyGems 1.3.7,并安装

ruby setup.rb

3.安装gem
1)安装Rails 2.3.14

gem install rails -v=2.3.14 --include-dependencies

2)安装rake

gem install rake --include-dependencies

3)安装rack

gem install rack

4)安装mysql插件

gem install mysql

5)安装rdoc

gem install rdoc

6)安装i18n

gem install i18n

如果网速很差,可以把gem下载到本地后再安装,比如:

gem install i18n -l

4.配置数据库
1)拷贝dll
将mysql安装目录下的libmysql.dll拷贝到ruby路径
如果你的libmysql.dll版本高于5.1.3的话请用这个
http://instantrails.rubyforge.org/svn/trunk/InstantRails-win/InstantRails/mysql/bin/libmySQL.dll

2)配置数据库
下载并解压redmine-1.3.2
拷贝database.yml.example为database.yml,将production小节配置好

3)创建数据库

rake generate_session_store
rake db:migrate RAILS_ENV="production"

5.测试

ruby script/server -e production
#访问http://localhost:3000/
#用户名:admin
#密码:admin

6.配置email
拷贝configuration.yml.example为configuration.yml,
修改smtp配置,重启服务器即可

7.安装服务
1)安装gem

gem install mongrel_service

2)安装服务

mongrel_rails service::install -N Redmine -c D:\Ruby\redmine-1.3.2 -p 3000 -e production

3)设置服务依赖

sc config Redmine depend= MySQL start= auto

4)将mongrel.rb拷贝到redmin/config/initializers
mongrel.rb在github上有很多版本,但要自己改一下代码,来适应自己的rails版本

搭建Mantis

1.安装apache 2.2.x

2.配置apache端口
httpd.conf

Listen 8000

3.安装php5
需要模块:MySQL,SMTP,GD2

4.配置php
httpd.conf

AddType application/x-httpd-php .php .phtml .php3 .php4

5.解压mantis

6.配置mantis虚拟目录
httpd.conf

Alias /Mantis D:/mantisbt

<Directory "D:/mantisbt"]
        Options Indexes
        AllowOverride None
        Order allow,deny
        Allow from all
</Directory>

DirectoryIndex index.html index.php index.perl

7.安装mysql

8.新建用户,数据库,并为用户分配权限

9.首次访问mantis,按提示安装数据库,主要端口及大小写
http://127.0.0.1:8000/Mantis/login_page.php

10.首次登陆mantis,修改超级用户密码
http://127.0.0.1:8000/Mantis/login_page.php
用户名:administrator
密码:root

11.设置mantis语言
config_defaults_inc.php

$g_default_language  = 'chinese_simplified';

12.配置mantis邮件
config_defaults_inc.php

$g_smtp_host = "smtp服务器地址";
$g_smtp_username = '用户名';
$g_smtp_password = '密码';

13.配置mantis文件上传
config_defaults_inc.php

$g_allow_file_upload	= ON;
$g_file_upload_method	= DISK;

14.配置mantis图形插件,这里很麻烦,大体步骤如下
1)安装mantis报表插件
2)安装JpGraph,配置路径及字体,但插件配置中没有simsun字体
3)修改mantis代码,全局搜素,在出现verasans的地方,相应增加simsun,好像是三处
4)修改JpGraph,在处理simsun字体的时候,不用做转码,直接返回就好啦
5)去插件管理的地方,选择simsun
6)刷新即可

hl7 v2在socket通讯中应该注意的问题

1.hl7 v2在socket通讯时,是需要有起始及结束字符的
起始字符为0x0b
结束字符为0x1c 0x0d

2.正确处理换行
要将\r\n改为\r(0x0d)
单独的\n也替换为\r(0x0d)

3.同一socket收发信息,可以用msgid作为区分

4.因为utf-8的通用性及其编码规则比较适合网络传输,所以可以采用utf-8编码

Maven常用参数

1.常用命令参数
进行编译

mvn compile

进行打包

#测试并打包
mvn package
#直接打包,不进行测试
mvn package -DskipTests=true
#打Jar包
mvn jar:jar
#打War包
mvn war:war
#打War包但不执行最后的压缩
mvn war:exploded

进行测试

#编译单元测试
mvn test-compile
#编译并允许单元测试
mvn test

安装到本地repository

mvn install
mvn install -DskipTests=true
mvn install -DskipTests=true --fail-at-end
#安装jar包到本地仓库
mvn install:install-file -DgroupId=groupId -DartifactId=artifactId -Dversion=1.0.0 -Dpackaging=jar -Dfile=xxx.jar

安装到远程repository

mvn deploy

进行清理

mvn clean

生成网站

#生成网站
mvn site
#生成网站并发布
mvn site-deploy

打包源码包

#打包源码
mvn source:jar
#下载项目源码
mvn dependency:sources -DdownloadSources=true -DdownloadJavadocs=true

打包测试源码包

mvn source:test-jar

拷贝依赖到target目录

#拷贝依赖
mvn dependency:copy-dependencies
#依赖分析
mvn dependency:analyze
mvn dependency:tree

生成ecplise项目

mvn eclipse:eclipse

生成ecplise项目

mvn idea:idea

生成文档

#单模块项目生成文档
mvn javadoc:javadoc
#多模块项目生成文档
mvn javadoc:aggregate

创建Jar项目

mvn archetype:create -DgroupId=gourpid -DartifactId=artifactId

创建War项目

mvn archetype:create -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-webapp -DgroupId=gourpid  -DartifactId=artifactId

2.settings.xml

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"]

<localRepository>X:/Maven/repository</localRepository>

<servers>
<server>
<id>neo-public</id>
<username>username</username>
<password>password</password>
</server>
<server>
<id>neo-releases</id>
<username>username</username>
<password>password</password>
</server>
<server>
<id>neo-snapshots</id>
<username>username</username>
<password>password</password>
</server>
</servers>

<mirrors>
<mirror>
<id>neo-public</id>
<name>Neohope Nexux Public Mirror</name>
<url>http://192.168.xxx.xxx:8081/nexus/content/groups/public</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>

<profiles>
<profile>
<id>myprofile</id>
<repositories>
<repository>
<id>neo-public</id>
<name>Neohope Nexux Public Mirror</name>
<url>http://192.168.xxx.xxx:8081/nexus/content/groups/public</url>
</repository>
</repositories>
</profile>
</profiles>

<activeProfiles>
<activeProfile>myprofile</activeProfile>
</activeProfiles>

</settings>

3.pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"]
<modelVersion>4.0.0</modelVersion>

<groupId>com.neohope.xxx</groupId>
<artifactId>xxx-xxx</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>

<name>xxx-xxx</name>
<url>http://neohope.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<nexus.url>http://192.168.xxx.xxx:8081</nexus.url>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>neo-releases</id>
<name>Internal Releases</name>
<url>${nexus.url}/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<id>neo-snapshots</id>
<name>Internal Snapshots</name>
<url>${nexus.url}/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
</project>

Maven Lifecycles

Maven有三大生命周期
default:默认生命周期,用于软件构建
clean:用于项目清理
site:用于生成项目网站

1、default

<phases>
  <phase>validate</phase>
  <phase>initialize</phase>
  <phase>generate-sources</phase>
  <phase>process-sources</phase>
  <phase>generate-resources</phase>
  <phase>process-resources</phase>
  <phase>compile</phase>
  <phase>process-classes</phase>
  <phase>generate-test-sources</phase>
  <phase>process-test-sources</phase>
  <phase>generate-test-resources</phase>
  <phase>process-test-resources</phase>
  <phase>test-compile</phase>
  <phase>process-test-classes</phase>
  <phase>test</phase>
  <phase>prepare-package</phase>
  <phase>package</phase>
  <phase>pre-integration-test</phase>
  <phase>integration-test</phase>
  <phase>post-integration-test</phase>
  <phase>verify</phase>
  <phase>install</phase>
  <phase>deploy</phase>
</phases>

2、clean

<phases>
  <phase>pre-clean</phase>
  <phase>clean</phase>
  <phase>post-clean</phase>
</phases>
<default-phases>
  <clean>
    org.apache.maven.plugins:maven-clean-plugin:2.5:clean
  </clean>
</default-phases>

3、site

<phases>
  <phase>pre-site</phase>
  <phase>site</phase>
  <phase>post-site</phase>
  <phase>site-deploy</phase>
</phases>
<default-phases>
  <site>
    org.apache.maven.plugins:maven-site-plugin:3.3:site
  </site>
  <site-deploy>
    org.apache.maven.plugins:maven-site-plugin:3.3:deploy
  </site-deploy>
</default-phases>

Windows下以兼容模式启动EXE

有两种常用的方式,可以让Windows可以以兼容模式启动EXE程序。

方法1、修改注册表,永久模式(右键-》属性-》兼容模式,也是通过修改注册表达到兼容模式启动EXE的)
A、以WINXPSP3兼容模式,注册表命令行

reg.exe Add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /v "PATH_TO_EXE" /d "WINXPSP3"

B、以WINXPSP3兼容模式,注册表文件

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers]
"PATH_TO_EXE"="WINXPSP3"

方法2、设置环境变量,单次运行

#注意:__COMPAT_LAYER前面是两个下划线
#两个LayerName之间用空格隔开
#!表示不可以使用该兼容模式
set __COMPAT_LAYER=[!]LayerName1 [LayerName2 ...]

#用WinXPsp3兼容模式启动程序
set __COMPAT_LAYER=WINXPSP3

#用WinXPsp3兼容模式启动程序,并禁用主题
set __COMPAT_LAYER=WINXPSP3 DISABLETHEMES

#以管理员身份、用WinXPsp3兼容模式启动程序,并禁用主题
set __COMPAT_LAYER=WINXPSP3 DISABLETHEMES RUNASADMIN

#禁用兼容模式
set __COMPAT_LAYER=

可用的设置选项有:

LayerName 含义
兼容模式(Compatibility Modes)
WIN95 Windows 95
WIN98 Windows 98
WIN4SP5 Windows NT 4.0 SP5
WIN2000 Windows 2000
WINXPSP2 Windows XP SP2
WINXPSP3 Windows XP SP3
VISTARTM Vista
VISTASP1 Vista SP1
VISTASP2 Vista SP2
WIN7RTM Windows 7
WINSRV03SP1 Windows Server 2003 SP1
WINSRV08SP1 Windows Server 2008 SP1
显示设置(Display Settings)
DISABLETHEMES 禁用主题
640X480 以640×480分辨率进行
HIGHDPIAWARE 高DPI设置时,禁用显示缩放
256COLOR 以256色运行
DISABLEDWM 禁用桌面组合
权限设置(Privilege Level)
RUNASADMIN 管理员权限运行EXE
RUNASINVOKER 以调用者权限运行EXE
RUNASHIGHEST 以用户最高权限运行EXE
Win8
ELEVATECREATEPROCESS 子进程将获取一个UAC提升权限对话框
PINDLL DLL内存常驻
DISABLEUSERCALLBACKEXCEPTION 禁用用户回调异常
VIRTUALIZEDELETE 该模式拦截受保护文件上的删除操作,防止应用由于未处理删除操作中的异常而失败
WRPMITIGATION 当应用尝试写入、修改或删除Windows受保护文件或注册表项时,该模式返回成功(实际上没有完成该操作)
DXMAXIMIZEDWINDOWEDMODE 该模式标识进入全屏模式的应用并指将这些应用重定向到最大化Window模式