小编tok*_*khi的帖子

PG ::错误:错误:新编码(UTF8)不兼容

postgresql-9.2.4从源代码安装,现在在执行时使用rails app:

rake db:create 命令我得到:

$ bin/rake db:create RAILS_ENV="test"
PG::Error: ERROR:  new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII)
HINT:  Use the same encoding as in the template database, or use template0 as template.
: CREATE DATABASE "verticals_test" ENCODING = 'unicode'
/home/vagrant/my-project/.gems/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/postgresql_adapter.rb:652:in `exec
....
bin/rake:16:in `load'
bin/rake:16:in `<main>'
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "database"=>"my_db", "host"=>"localhost", "pool"=>5, "username"=>"my_user", "password"=>"my_password"}
Run Code Online (Sandbox Code Playgroud)

任何的想法?

ruby postgresql ruby-on-rails

77
推荐指数
5
解决办法
4万
查看次数

不使用缓存的卷曲命令

有没有办法告诉curl命令不要使用服务器端缓存?例如; 我有这个curl命令:

curl -v www.example.com

我怎么能请求curl发送一个不使用缓存的新请求?

注意:我在终端中寻找可执行命令.

linux bash memcached curl caching

58
推荐指数
3
解决办法
7万
查看次数

删除文件扩展名的最佳方法

删除文件扩展名的最短方法是什么?这是我试过的:

file = "/home/usr/my_file.xml"
file = File.basename(file)
file.slice! File.extname(file)   #=> my_file
Run Code Online (Sandbox Code Playgroud)

ruby filenames file-extension

28
推荐指数
1
解决办法
2万
查看次数

Java - 如何检测IP版本

Client通过以下方法获取IP地址:

public static String getClientIpAddr(HttpServletRequest request) {  
    String ip = request.getHeader("X-Forwarded-For");  
    ...
    return ip
} 
Run Code Online (Sandbox Code Playgroud)

现在我想检测它是一个IPV4还是一个IPV6.

java network-programming servlets

15
推荐指数
3
解决办法
1万
查看次数

org.json.simple.JSONArray无法强制转换为org.json.simple.JSONObject

我正在尝试解析json文件:

{"units":[{"id":42,               
   "title":"Hello World",          
    "position":1,
    "v_id":9,
    "sites":[[{"id":316,
      "article":42,
      "clip":133904
        }],
       {"length":5}]

   }, ..]}
Run Code Online (Sandbox Code Playgroud)

这是我尝试过的:

Object obj = null;
JSONParser parser = new JSONParser();
Object unitsObj = parser.parse(new FileReader("file.json");
JSONObject unitsJson = (JSONObject) unitsObj;

JSONArray units = (JSONArray) unitsJson.get("units");
Iterator<String> unitsIterator = units.iterator();
while(unitsIterator.hasNext()){         
    Object uJson = unitsIterator.next();
    JSONObject uj = (JSONObject) uJson;
    obj =  parser.parse(uj.get("sites").toString());
    JSONArray jsonSites = (JSONArray)  obj;

    for(int i=0;i<jsonSites.size();i++){
     JSONObject site = (JSONObject)jsonSites.get(i); // Exception happens here.
     System.out.println(site.get("article");
    }
}
Run Code Online (Sandbox Code Playgroud)

当我尝试解析内部时json array,代码不起作用,所以我得到:

Exception …
Run Code Online (Sandbox Code Playgroud)

java json

12
推荐指数
2
解决办法
10万
查看次数

为什么foo不再为零 - 或者在函数内起作用

为什么在下面的代码片段foo取代了它的定义?

def foo
  def foo
    1
  end
end
Run Code Online (Sandbox Code Playgroud)

这是第一次foo没有

foo
=> nil

foo.foo
=> 1
Run Code Online (Sandbox Code Playgroud)

现在,如果我foo再次打电话:

foo
=> 1
Run Code Online (Sandbox Code Playgroud)

你可以看到foo不再是零了.谁可以给我解释一下这个?谢谢.

ruby

11
推荐指数
1
解决办法
129
查看次数

无法通过测试用例访问src/main/resources中的文件

我有一个file.datsrc/main/resources.

当我尝试通过jar文件测试加载此文件的类时,测试失败,因为它无法在path(I/O Exception)中找到该文件.我通过测试获得的路径是:

/home/usr/workspace/project/target/test-classes/file.dat

但文件不存在于target/test-classes任何想法?

java junit unit-testing

11
推荐指数
2
解决办法
2万
查看次数

taglibs和变量声明在源页面的顶部生成空行

我已经variables在我的jsp页面中声明了一些taglib,如下所示:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<c:set var="site" scope="session" value="${site}"/>
<c:set var="thumb" scope="session" value="${thumbnail}"/>
<c:set var="geoCode" scope="session" value="${geoCode}"/>
...
<fmt:setLocale value="${local}" />
<fmt:setBundle basename="MessagesBundle" />
<!DOCTYPE html>
<head>
    <meta charset="utf-8">
...
Run Code Online (Sandbox Code Playgroud)

当我运行应用程序然后查看源代码时,我在源页面顶部看到空白的新行:

.







<!DOCTYPE html>
<head>
    <meta charset="utf-8">
Run Code Online (Sandbox Code Playgroud)

我只是放了一个dot来展示空行.关于如何删除这些空行的任何想法?

java jsp servlets jstl taglib

11
推荐指数
1
解决办法
3963
查看次数

maven无法传输工件,未经授权,ReasonPhrase:未经授权

我在pom.xml文件中添加了以下依赖项:

<dependency>
  <groupId>org.tuckey</groupId>
  <artifactId>urlrewritefilter</artifactId>
  <version>4.0.4</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

我有很多maven依赖项,但当我添加上面的一个时,我得到:

Failed to read artifact descriptor for org.tuckey:urlrewritefilter:jar:4.0.4: Could not transfer artifact org.tuckey:urlrewritefilter:pom:4.0.4 from/to central (http://app1.stage.server.net/artifactory/libs-release): Not authorized, ReasonPhrase:Unauthorized. -> [Help 1]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
Run Code Online (Sandbox Code Playgroud)

这是settings.xml文件的外观:

..
  <servers>
    <server>
      <username>user</username>
      <id>central</id>
      <password>my-password</password>
    </server>
    <server>
      <username>user</username>
      <id>snapshots</id>
      <password>my-password</password>
    </server>
  </servers>
  <profiles>
    ...
  </profiles>
  <activeProfiles>
    <activeProfile>artifactory</activeProfile>
  </activeProfiles>
..
Run Code Online (Sandbox Code Playgroud)

任何帮助?TNX.

java maven

9
推荐指数
1
解决办法
3万
查看次数

何时使用`method_missing`

在下面的代码中,方法roar没有在类中定义Lion,但仍然可以使用method_missing.

class Lion
  def method_missing(name, *args)
    puts "Lion will #{name}: #{args[0]}"
  end
end

lion = Lion.new
lion.roar("ROAR!!!") # => Lion will roar: ROAR!!!
Run Code Online (Sandbox Code Playgroud)

在哪些情况下我应该如何使用它method_missing?使用安全吗?

ruby metaprogramming

8
推荐指数
2
解决办法
5601
查看次数