小编Ion*_*zău的帖子

Ruby On Rails form_for Checkbox太小了

我在格式化checkbox表单时遇到问题.

它目前在我的形式看起来非常小,我不知道如何使它更大.

代码如下:

<%= f.label :email %>   <%= f.email_field :email %>

<%= f.label :password %>   <%= f.password_field :password %>

<%= f.label :remember_me %>     <%= f.check_box :remember_me %>
Run Code Online (Sandbox Code Playgroud)

也许这是我可以用CSS解决的问题,但目前我的其他领域没有使用任何..

只是一些信息,我正在使用twitter bootstrap,所以任何解决方案都可以使用.

css ruby ruby-on-rails form-for twitter-bootstrap

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

sprintf预先添加了额外的字符

我决定编写一个二进制转换器,代码小而简单,它需要一个整数,并且应该输出一个带有结果二进制字符串的char*.

这里的问题似乎是最后一个sprintf似乎总是加倍最后一个前置字符.

例如,如果答案是1001001,它将打印11001001,或者如果它应该是-10,则打印-10,后者特别奇怪,因为它甚至不在循环中.

#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>

void bin_string( char** buffer ,int num ){

    bool neg = false;

    if ( num < 0 ){
        neg = true;
        num = ~num+1;
    }

    if( num == 0 )
        sprintf( *buffer, "%d", 0 );

    while( num > 0 ){

        int rem = num%2;

        sprintf( *buffer, "%d%s", rem, *buffer );

        printf("iteration: %s rem: %d\n", *buffer, rem );
        num = num/2;
    }

    if( neg )
        sprintf( *buffer, "-%s", *buffer );
}

int main( …
Run Code Online (Sandbox Code Playgroud)

c

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

使用wget将下载的文件名设置在不同的目录中

我需要使用下载一个zip文件wget.要在当前目录中下载,我在命令行中运行:

 $ wget https://github.com/.../[myfile].zip
Run Code Online (Sandbox Code Playgroud)

要在另一个不同的目录中下载它,我添加-P <Path of download directory>:

$ wget -P [download directory path] https://github.com/.../[myFile].zip
Run Code Online (Sandbox Code Playgroud)

我想更改以将文件下载到文件[download path directory]名中[myFileName].我怎样才能做到这一点?

我已经尝试过了:

$ wget -P [download directory path] --output-document=[filename.zip] 
https://github.com/.../[myZipFile].zip
Run Code Online (Sandbox Code Playgroud)

这会将文件下载到当前目录中,文件名由我选择.

Finnaly我将使用它将其用于NodeJS项目spawn.

目前我有这个:

var downloader = spawn("wget", ["-P", zipFile, appUrl]);
Run Code Online (Sandbox Code Playgroud)

javascript command-line wget node.js

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

线程Java代码问题

我是初学者,开始学习java编程.

我写了一个程序来尝试线程化.在一个类中,我编写了一个程序来显示从1到100的数字,在另一个类中显示从999到100的数字.现在在主要的我已经为类(r1,r2)创建了一个对象引用并创建了一个线程的对象并传递(我的类的r1,r2-对象引用)它们作为参数.现在我得到的输出并不像预期的那样我觉得我的第二个线程没有被执行.我不确定我的逻辑或程序是否有任何问题.任何帮助/建议将不胜感激.我的代码在下面供参考.

第1类:

public class Run implements Runnable {

@Override
public void run() {

    for (int i = 0; i < 100; i++) {
        try {

            Thread.sleep(200);
        } catch (InterruptedException ex) {
            Logger.getLogger(Run.class.getName()).log(Level.SEVERE, "...", ex);
        }
        System.out.println(i);
    }
}
}
Run Code Online (Sandbox Code Playgroud)

第2类:公共类Run2扩展Thread {

public void run2() {

    for(int i=999;i>0;i--){
        try {

            Thread.sleep(500);
        } catch (InterruptedException ex) {
            Logger.getLogger(Run2.class.getName()).log(Level.SEVERE, "....", ex);
        }
        System.out.println(i);


    }

}
} 
Run Code Online (Sandbox Code Playgroud)

主要课程:

public class Threading {

/**
 * @param args the command line arguments
 */
public static …
Run Code Online (Sandbox Code Playgroud)

java multithreading

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

为什么我的div不会消失

我正在尝试使用Jquery.UI库,问题是,jqueryui.com上给出的示例是当你传递效果类型时,我想加载淡出

JSFiddle就在这里

http://jsfiddle.net/L3pMG/2/

我的代码

<div id="effect">
    <h3>Hide</h3>
    <p>Etiam libero neque, luctus a, eleifend nec, semper at, lorem. Sed pede. Nulla lorem metus, adipiscing ut, luctus sed, hendrerit vitae, mi.</p>
</div>

<script>
  $( document ).ready(function() {
         $( "#effect" ).hide( "blind", 1000, callback );
  });
</script>
Run Code Online (Sandbox Code Playgroud)

html jquery jquery-ui

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

清除NodeJS流中的所有行

process.stdout.clearLine()删除最新行.如何删除所有行stdout

var out = process.stdout;
out.write("1\n"); // prints `1` and new line
out.write("2");   // prints `2`

setTimeout(function () {
    process.stdout.clearLine(); // clears the latest line (`2`)
    out.cursorTo(0);            // moves the cursor at the beginning of line
    out.write("3");             // prints `3`
    out.write("\n4");           // prints new line and `4`
    console.log();
}, 1000);
Run Code Online (Sandbox Code Playgroud)

输出是:

1
3
4
Run Code Online (Sandbox Code Playgroud)

我想删除所有行stdout而不是最新行,因此输出将是:

3
4
Run Code Online (Sandbox Code Playgroud)

stream node.js

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

在 VIM 中打开下一个文件

我在目录中有以下文件:

" ============================================================================
" Netrw Directory Listing                                        (netrw v149) 
"   /home/.../content
"   Sorted by      name
"   Sort sequence: [\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$...
"   Quick Help: <F1>:help  -:go up dir  D:delete  R:rename  s:sort-by  x:exec
" ============================================================================
../
./
.swo
1
10-1
10-2
10-3
10-4
10-5
10-6
2
3
4
5
6
7
8-1
8-2
8-3
9-1
9-2
9-3
9-4
9-5
Run Code Online (Sandbox Code Playgroud)

10-2缓冲开了,我怎么能打开要编辑的下一个文件(10-3)?

回去怎么办?

现在我这样做:Ex,然后转到下一个文件。

vim buffer

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

当原型包含一个对象时,访问"this"值?

我有一个这样的:

 function Foo() {
   this._current = -1;
 }
 Foo.prototype.history = {};
 Foo.prototype.history.back = function () {
   if (this._current === undefined) {
     return alert("this._current is undefined");
   }
   --this._current; // `this` is the history object
 };
Run Code Online (Sandbox Code Playgroud)

如何Fooback方法中访问实例?

我解决的问题是做这样的事情:

var f = new Foo();
f.history.back = f.history.back.bind(f);
Run Code Online (Sandbox Code Playgroud)

更好的解决方案吗?对每个Foo实例都这样做对我来说听起来不太好.


这是一个例子:

function Foo() {
  this._current = -1;
}
Foo.prototype.history = {};
Foo.prototype.history.back = function() {
  if (this._current === undefined) {
    return alert("this._current is undefined");
  } …
Run Code Online (Sandbox Code Playgroud)

javascript prototype object

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

在Fortran中生成进程

如何在Fortran中启动子进程(例如执行shell命令)?

在Node.js的,我们可以使用spawnexec启动子进程:

var proc = require("child_process").spawn("ls", ["-l"]);
proc.stdout.on("data", function (chunk) {
  console.log(chunk);
});

// or

var proc = require("child_process").exec("ls -l"], function (err, stdout, stderr) {
   ...
});
Run Code Online (Sandbox Code Playgroud)

上面的两个例子都运行ls -l(列出文件和目录).如何在Fortran中实现同样的目标?

fortran spawn child-process node.js

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

来自 Google Cloud 存储桶的图像不会立即更新

更新 Google Cloud 存储桶中的图片时,即使图片更新成功,该 url 也会在一段时间内(几分钟,例如 5 分钟左右)提供旧版本。

我们使用的链接如下所示:

https://storage.googleapis.com/<bucket-name>/path/to/images/1.jpg
Run Code Online (Sandbox Code Playgroud)

更新图像的代码的相关部分是:

var storageFile = bucket.file(imageToUpdatePath);
var storageFileStream = storageFile.createWriteStream({
  metadata: {
    contentType: req.file.mimetype
  }
});

storageFileStream.on('error', function(err) {
   ...
});

storageFileStream.on('finish', function() {
  // cloudFile.makePublic after the upload has finished, because otherwise the file is only accessible to the owner:
  storageFile.makePublic(function(err, data) {
    //if(err)
    //console.log(err);
    if (err) {
      return res.render("error", {
        err: err
      });
    }
    ...
  });
});
fs.createReadStream(filePath).pipe(storageFileStream);
Run Code Online (Sandbox Code Playgroud)

这看起来像是 Google Cloud 端的缓存问题。怎么解决呢?更新后如何在请求的url获取更新后的图像?

在 Google Cloud 管理员中,新图像确实正确显示。

javascript caching node.js google-cloud-storage

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