标签: wrapper

用 python 封装 bash 脚本

我刚刚找到了这个很棒的 wget 包装器,我想使用 subprocess 模块将其重写为 python 脚本。然而,事实证明这很棘手,给了我各种各样的错误。

download()
{
    local url=$1
    echo -n "    "
    wget --progress=dot $url 2>&1 | grep --line-buffered "%" | \
    sed -u -e "s,\.,,g" | awk '{printf("\b\b\b\b%4s", $2)}'

    echo -ne "\b\b\b\b"
    echo " DONE"
}
Run Code Online (Sandbox Code Playgroud)

然后可以这样调用:

file="patch-2.6.37.gz"
echo -n "Downloading $file:"
download "http://www.kernel.org/pub/linux/kernel/v2.6/$file"
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

来源: http: //fitnr.com/showing-file-download-progress-using-wget.html

python bash shell subprocess wrapper

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

How to check Boolean for null?

I want to add a null check to my ternary operator which checks on a Boolean isValue:

public String getValue() {
    return isValue ? "T" : "F";
}
Run Code Online (Sandbox Code Playgroud)

My task is:

What if the Boolean(object) return null? Add a boolean check and return "" (empty String in case if its null).

Note that isValue is a Boolean, not boolean.

java ternary-operator wrapper null-check

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

整数类不充当引用类型

整数不充当引用类型。例如下面的代码会产生意外的结果


    class Playground {
            public static void main(String[ ] args) {
                Integer i = 10;
                Integer num = i;
                i--;
                System.out.println("i = " + i);
                System.out.println("num = " + num);
            }
    }

Run Code Online (Sandbox Code Playgroud)

输出:

i = 9
num = 10
Run Code Online (Sandbox Code Playgroud)

我预计“num”也为 9,因为整数“num”引用整数“i”。此处的减法操作发生在 num 引用的同一对象上,但看起来“-”运算符正在覆盖某些行为并创建一个新的 Integer 对象。这里到底发生了什么?还有哪些其他类有类似的行为?

java integer reference wrapper

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

为什么将 <img> 放入容器中(例如 <div>)?

我刚刚学习编码,一直在到处寻找这个问题的答案,但由于某种原因找不到任何东西。

我注意到将图像放入容器或包装器中似乎是常见的做法。例如,而只是有:

<img src="url"/>
Run Code Online (Sandbox Code Playgroud)

每个人似乎都同意它需要这样:

<div class="container">
<img=src"url"/>
</div>
Run Code Online (Sandbox Code Playgroud)

以这种方式将 img 包裹在 div 内的目的是什么?它似乎与“响应式设计”有关,但我不能100%确定。是否只是为了让我们有一些相对于图像大小的东西,而不是使用像CSS中图像选择器上的像素这样的确定大小?当我写这篇文章时,我思考得越多,它似乎就越是正确的答案,但我不确定这个答案是否还缺少其他东西。

任何见解将不胜感激。谢谢。

html css containers image wrapper

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

用jquery包含wrapp元素?

我有一些

HTML

<input type="checkbox">
Run Code Online (Sandbox Code Playgroud)

我需要使用复选框获取所有元素,并将它们包装起来,使得最终的html得到这样的结果

<label class="checkbox"><input type="checkbox"><i></i></label>
Run Code Online (Sandbox Code Playgroud)

这只能用Jquery吗?

jquery wrapper

-2
推荐指数
1
解决办法
40
查看次数

如何安全记忆?

我想实际使用这个包装器,但问题是我不知道它是否非常安全.

我有一个关于使用几个简单的问题malloc(),calloc()realloc().这是我到目前为止所拥有的:

string.h中

typedef struct str str; // pointer for encapsulation
Run Code Online (Sandbox Code Playgroud)

string.c

struct str
{
    char *buf;
    size_t len;
}
Run Code Online (Sandbox Code Playgroud)

说我有一个辅助功能,只是这样做:

    str *NEW_STRING()
    {
        str *temp = calloc(1, sizeof (struct str));
        temp->len = 0;
        temp->buf = (char *) malloc(1);
        return temp;
    }
Run Code Online (Sandbox Code Playgroud)

这样安全吗?如果是,如果我这样做会发生什么:

str *A_STRING = NEW_STRING();
A_STRING = NEW_STRING();
Run Code Online (Sandbox Code Playgroud)

它会调用malloc和calloc两次,那是不是很糟糕?初始化器会更好吗?

void str_init(str *A_STRING)
{
    if (A_STRING)
    {
        free(A_STRING);
    }

    if (A_STRING->buf)
    {
        free(A_STRING->buf);
    }

    A_STRING = calloc(1, sizeof (struct str));
    A_STRING->buf = (char …
Run Code Online (Sandbox Code Playgroud)

c string wrapper

-3
推荐指数
1
解决办法
217
查看次数