半城柳色半声笛

文章 评论 浏览 26

半城柳色半声笛 2024-12-20 08:48:33

感谢克里斯蒂安,我解决了这个问题。不过,我不确定这是最干净的解决方案。

我创建了一个名为 resetneeded 的布尔值。

在点击按钮代码中,我这样做:

btnVolgende.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
如果(需要重置){
光标 = (光标) WoordData.fetchset(kernset);
需要重置=假;
}
开始管理光标(光标);
tvFlitswoord.setText(cursor.getString(0));
光标.moveToNext();
if (cursor.isAfterLast()){
光标.moveToFirst();
}}

然后,在 onStart() 中,我将布尔值 resetneeded 设置为 true

// 编辑 - 第二个解决方案

最后,我决定使用 ArrayList 将单词传递到 TextView(并使用按钮循环浏览它)。 ArrayList 似乎更容易处理并且不那么脆弱。

代码:

    public void onStart(){
    super.onStart();    
    getPrefs();
    wordlistarray.clear();
    cursor = (Cursor) WoordData.fetchset(kernset);       
    cursor.moveToFirst();
    while(!cursor.isAfterLast()) {

        String wordtoadd = cursor.getString(0);
        wordlistarray.add(wordtoadd);
        cursor.moveToNext();
    }       

            for(int i = 0; i < wordlistarray.size();
                    i++){ Log.d("word in array", "" + wordlistarray.get(i)); }

Thanks to Christian, I solved it. I'm not sure this is the cleanest solution, though..

I created a boolean called resetneeded.

In the clickbutton code I do :

btnVolgende.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (resetneeded) {
cursor = (Cursor) WoordData.fetchset(kernset);
resetneeded = false;
}
startManagingCursor(cursor);
tvFlitswoord.setText(cursor.getString(0));
cursor.moveToNext();
if (cursor.isAfterLast()){
cursor.moveToFirst();
}}
}

And then, in the onStart(), I set the boolean resetneeded to true.

// EDIT - 2nd Solution

In the end, I decided to use an ArrayList for passing the words to the TextView (and cycling through it with the button). An ArrayList seems easier to handle and less fragile..

The code :

    public void onStart(){
    super.onStart();    
    getPrefs();
    wordlistarray.clear();
    cursor = (Cursor) WoordData.fetchset(kernset);       
    cursor.moveToFirst();
    while(!cursor.isAfterLast()) {

        String wordtoadd = cursor.getString(0);
        wordlistarray.add(wordtoadd);
        cursor.moveToNext();
    }       

            for(int i = 0; i < wordlistarray.size();
                    i++){ Log.d("word in array", "" + wordlistarray.get(i)); }

查询更改后刷新光标 - onStart()?

半城柳色半声笛 2024-12-20 08:45:34

有一种方法可以解决这个问题。两种实现都包含纯 python“WichmannHill”PRNG。
它速度较慢,但​​在 Jython 和 CPython 中给出相同的结果。

在我的代码中我替换

random.seed(1)
uuid += random.choice(hexdigits)

rand = random.WichmannHill(1)
uuid += rand.choice(hexdigits)

There is a way around this. Both implementations include the pure-python "WichmannHill" PRNG.
It's slower but it gives the same results in both Jython and CPython.

In my code I replaced

random.seed(1)
uuid += random.choice(hexdigits)

with

rand = random.WichmannHill(1)
uuid += rand.choice(hexdigits)

Jython 随机模块产生与 cpython 不同的结果

半城柳色半声笛 2024-12-20 03:17:41

只要标头注释被唯一分隔(即没有其他标头注释以 // ---------- 开头),并且替换文本是常量,以下 awk 脚本应该做你需要的事情:

BEGIN { normal = 1 }

/\/\/ ----------/ {
    if (normal) {
        normal = 0;
        print "// **********";
        print "// some replacement";
        print "// text";
        print "// that could have any";
        print "// format";
        print "// **********";
    } else {
        normal = 1;
        next;
    }
}

{
    if (normal) print;
}

这会打印它看到的所有内容,直到遇到段落分隔符。当它看到第一个段落时,它会打印出替换段落。在看到第二段分隔符之前,它不会打印任何内容。当它看到第二个段落分隔符时,它将再次开始正常打印下一行。

虽然从技术上讲您可以从命令行执行此操作,但您可能会遇到棘手的 shell 引用问题,尤其是当替换文本包含单引号时。将脚本放入文件中可能会更容易。只需将 #!/usr/bin/awk -f (或 awk 返回的任何路径 )放在顶部即可。

编辑

要在 awk 中匹配多行,您需要使用 getline。也许是这样的:

/\/\/ ----------/ {
    lines[0] = "// header";
    lines[1] = "// comment";
    lines[2] = "// to be replaced";
    lines[3] = "// ----------";

    linesRead = $0 "\n";
    for (i = 0; i < 4; i++) {
         getline line;
         linesRead = linesRead line;
         if (line != lines[i]) {
             print linesRead; # print partial matches
             next;
         }
    }

    # print the replacement paragraph here
    next;
}

As long as the header comments are delimited uniquely (i.e., no other header comment starts with // ----------), and the replacement text is constant, the following awk script should do what you need:

BEGIN { normal = 1 }

/\/\/ ----------/ {
    if (normal) {
        normal = 0;
        print "// **********";
        print "// some replacement";
        print "// text";
        print "// that could have any";
        print "// format";
        print "// **********";
    } else {
        normal = 1;
        next;
    }
}

{
    if (normal) print;
}

This prints everything it sees until it runs into the paragraph delimiter. When it sees the first one, it prints out the replacement paragraph. Until it sees the 2nd paragraph delimiter, it will print nothing. When it sees the 2nd paragraph delimiter, it will start printing lines normally again with the next line.

While you can technically do this from the command line, you may run into tricky shell quoting issues, especially if the replacement text has any single quotes. It may be easier to put the script in a file. Just put #!/usr/bin/awk -f (or whatever path which awk returns) at the top.

EDIT

To match multiple lines in awk, you'll need to use getline. Perhaps something like this:

/\/\/ ----------/ {
    lines[0] = "// header";
    lines[1] = "// comment";
    lines[2] = "// to be replaced";
    lines[3] = "// ----------";

    linesRead = $0 "\n";
    for (i = 0; i < 4; i++) {
         getline line;
         linesRead = linesRead line;
         if (line != lines[i]) {
             print linesRead; # print partial matches
             next;
         }
    }

    # print the replacement paragraph here
    next;
}

将整个段落替换为 Linux 命令行中的另一个段落

半城柳色半声笛 2024-12-20 01:08:50

正如@MilacH 指出的,实现中存在错误。如果 statusCode >返回 400 并抛出 IOException,因为拦截器未调用 errorHandler。该异常可以被忽略,然后在处理程序方法中再次捕获。

package net.sprd.fulfillment.common;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.ClientHttpResponse;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import static java.nio.charset.StandardCharsets.UTF_8;

public class LoggingRequestInterceptor implements ClientHttpRequestInterceptor {

    final static Logger log = LoggerFactory.getLogger(LoggingRequestInterceptor.class);

    @SuppressWarnings("HardcodedLineSeparator")
    public static final char LINE_BREAK = '\n';

    @Override
    public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
        try {
            traceRequest(request, body);
        } catch (Exception e) {
            log.warn("Exception in LoggingRequestInterceptor while tracing request", e);
        }

        ClientHttpResponse response = execution.execute(request, body);

        try {
            traceResponse(response);
        } catch (IOException e) {
            // ignore the exception here, as it will be handled by the error handler of the restTemplate
            log.warn("Exception in LoggingRequestInterceptor", e);
        }
        return response;
    }

    private void traceRequest(HttpRequest request, byte[] body) {
        log.info("===========================request begin================================================");
        log.info("URI         : {}", request.getURI());
        log.info("Method      : {}", request.getMethod());
        log.info("Headers     : {}", request.getHeaders());
        log.info("Request body: {}", new String(body, UTF_8));
        log.info("==========================request end================================================");
    }

    private void traceResponse(ClientHttpResponse response) throws IOException {
        StringBuilder inputStringBuilder = new StringBuilder();
        try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getBody(), UTF_8))) {
            String line = bufferedReader.readLine();
            while (line != null) {
                inputStringBuilder.append(line);
                inputStringBuilder.append(LINE_BREAK);
                line = bufferedReader.readLine();
            }
        }

        log.info("============================response begin==========================================");
        log.info("Status code  : {}", response.getStatusCode());
        log.info("Status text  : {}", response.getStatusText());
        log.info("Headers      : {}", response.getHeaders());
        log.info("Response body: {}", inputStringBuilder);
        log.info("=======================response end=================================================");
    }

}

As @MilacH pointed out, there is an error in the implementation. If an statusCode > 400 is returned a IOException is thrown, as the errorHandler is not invoked, from interceptors. The exception can be ignored and is then caught again in the handler method.

package net.sprd.fulfillment.common;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.ClientHttpResponse;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import static java.nio.charset.StandardCharsets.UTF_8;

public class LoggingRequestInterceptor implements ClientHttpRequestInterceptor {

    final static Logger log = LoggerFactory.getLogger(LoggingRequestInterceptor.class);

    @SuppressWarnings("HardcodedLineSeparator")
    public static final char LINE_BREAK = '\n';

    @Override
    public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
        try {
            traceRequest(request, body);
        } catch (Exception e) {
            log.warn("Exception in LoggingRequestInterceptor while tracing request", e);
        }

        ClientHttpResponse response = execution.execute(request, body);

        try {
            traceResponse(response);
        } catch (IOException e) {
            // ignore the exception here, as it will be handled by the error handler of the restTemplate
            log.warn("Exception in LoggingRequestInterceptor", e);
        }
        return response;
    }

    private void traceRequest(HttpRequest request, byte[] body) {
        log.info("===========================request begin================================================");
        log.info("URI         : {}", request.getURI());
        log.info("Method      : {}", request.getMethod());
        log.info("Headers     : {}", request.getHeaders());
        log.info("Request body: {}", new String(body, UTF_8));
        log.info("==========================request end================================================");
    }

    private void traceResponse(ClientHttpResponse response) throws IOException {
        StringBuilder inputStringBuilder = new StringBuilder();
        try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getBody(), UTF_8))) {
            String line = bufferedReader.readLine();
            while (line != null) {
                inputStringBuilder.append(line);
                inputStringBuilder.append(LINE_BREAK);
                line = bufferedReader.readLine();
            }
        }

        log.info("============================response begin==========================================");
        log.info("Status code  : {}", response.getStatusCode());
        log.info("Status text  : {}", response.getStatusText());
        log.info("Headers      : {}", response.getHeaders());
        log.info("Response body: {}", inputStringBuilder);
        log.info("=======================response end=================================================");
    }

}

Spring RestTemplate - 如何启用请求/响应的完整调试/日志记录?

半城柳色半声笛 2024-12-19 20:20:40

好吧,所以我使用了以下丑陋的代码:

uploader.bind('Refresh', function(up) {
    $('#'+up.settings.container + ' > div').css('left',0);
    $('#'+up.settings.container + ' > div').css('top',0);
    $('#'+up.settings.container + ' > div').css('width','100%');
    $('#'+up.settings.container + ' > div').css('height','100%');
    $('#'+up.settings.container + ' > form').css('left',0);
    $('#'+up.settings.container + ' > form').css('top',0);
    $('#'+up.settings.container + ' > form').css('width','100%');
    $('#'+up.settings.container + ' > form').css('height','100%');
    $('#'+up.settings.container + ' > div').children().css('left',0);
    $('#'+up.settings.container + ' > div').children().css('top',0);
    $('#'+up.settings.container + ' > div').children().css('width','100%');
    $('#'+up.settings.container + ' > div').children().css('height','100%');
    $('#'+up.settings.container + ' > div').children().css('font-size','20px');// default is 999px, which breaks everything in firefox
})

耶!它适用于 flash、htm5、htm4 runimes,并在 Chrome、Firefox、IE7、IE9 上进行了测试。垫片终于就位了。

Ok, so I went with the following ugly code:

uploader.bind('Refresh', function(up) {
    $('#'+up.settings.container + ' > div').css('left',0);
    $('#'+up.settings.container + ' > div').css('top',0);
    $('#'+up.settings.container + ' > div').css('width','100%');
    $('#'+up.settings.container + ' > div').css('height','100%');
    $('#'+up.settings.container + ' > form').css('left',0);
    $('#'+up.settings.container + ' > form').css('top',0);
    $('#'+up.settings.container + ' > form').css('width','100%');
    $('#'+up.settings.container + ' > form').css('height','100%');
    $('#'+up.settings.container + ' > div').children().css('left',0);
    $('#'+up.settings.container + ' > div').children().css('top',0);
    $('#'+up.settings.container + ' > div').children().css('width','100%');
    $('#'+up.settings.container + ' > div').children().css('height','100%');
    $('#'+up.settings.container + ' > div').children().css('font-size','20px');// default is 999px, which breaks everything in firefox
})

And yay! it works for flash, htm5, htm4 runimes, tested all on Chrome, Firefox, IE7, IE9. The shim is in place, finally.

Chrome中的plupload定位问题

半城柳色半声笛 2024-12-19 18:23:51

在主线程中使用它: while(!executor.isTermminate());
从执行程序服务启动所有线程后放置这行代码。这只会在执行器启动的所有线程完成后才启动主线程。确保调用 executor.shutdown();在上述循环之前。

Use this in your main thread: while(!executor.isTerminated());
Put this line of code after starting all the threads from executor service. This will only start the main thread after all the threads started by executors are finished. Make sure to call executor.shutdown(); before the above loop.

等待所有线程完成java中的工作

半城柳色半声笛 2024-12-19 09:47:07

对于“必须以数字开头”部分,我认为您需要一个自定义规则。

对于“如果另一个字段不为空则为必需”部分,您可以使用 依赖表达式 来决定验证器运行时是否需要:

将它们放在一起,您将得到如下所示的内容:

<form>
    <input name="first">
    <input name="second">
</form>
$.validator.addMethod("startsWithNum", function(input, element) {
    // First char must be digit if not empty
    return ! input || input.match(/^[0-9]/);
}, "This field must start with a number");

$('form').validate({
    rules: {
        first: {required : true},
        second: {
            "startsWithNum" : true,
            required: function() {
                // required if <input name="first"> is not empty
                return $('[name="first"]').val() !== '';
            }
        }
    }
});

演示:http://jsfiddle.net/qCELA/2/


我需要在表单中输入一个内容。如果用户将其留空,则不适用任何规则。否则,该单个输入字段必须以数字开头。

如果您只有一个输入字段,则自定义规则即可:

$('form').validate({
    rules: {
        second: {"startsWithNum" : true}
    }
});

演示:http://jsfiddle.net/ qCELA/3/

For the "must start with a number" part, I think you'll need a custom rule.

For the "required if another field is not empty" part, you can use a dependency expression to decide if it's required when the validator runs:

Put them together and you'll have something like this:

<form>
    <input name="first">
    <input name="second">
</form>
$.validator.addMethod("startsWithNum", function(input, element) {
    // First char must be digit if not empty
    return ! input || input.match(/^[0-9]/);
}, "This field must start with a number");

$('form').validate({
    rules: {
        first: {required : true},
        second: {
            "startsWithNum" : true,
            required: function() {
                // required if <input name="first"> is not empty
                return $('[name="first"]').val() !== '';
            }
        }
    }
});

Demo: http://jsfiddle.net/qCELA/2/


There is only a single input in the form I need to make. If the user left it blank, then no rules apply. Otherwise, that single input field must start with a number.

If you only have one input field, the custom rule is all you need:

$('form').validate({
    rules: {
        second: {"startsWithNum" : true}
    }
});

Demo: http://jsfiddle.net/qCELA/3/

jquery验证条件语句?

半城柳色半声笛 2024-12-19 04:20:52

通过 这篇文章 有一个非常简单的方法,那就是使用 .animate 代替 .delay

Via this post there's a very simple approach, which is to use .animate in place of .delay

jQuery延迟() - 如何停止它?

半城柳色半声笛 2024-12-18 18:32:50

使用以下代码禁用与后台的交互

//Ignore interaction for background activities
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];

现在,如果您想启用交互,请使用以下代码片段

if ([[UIApplication sharedApplication] isIgnoringInteractionEvents]) {

    // Start interaction with application
    [[UIApplication sharedApplication] endIgnoringInteractionEvents];
}

Use following code for disabling interaction with background

//Ignore interaction for background activities
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];

Now if you want to enable the interaction use following snippet

if ([[UIApplication sharedApplication] isIgnoringInteractionEvents]) {

    // Start interaction with application
    [[UIApplication sharedApplication] endIgnoringInteractionEvents];
}

禁用屏幕上当前视图的用户交互

半城柳色半声笛 2024-12-18 14:17:48

为什么不使用通用集合而不是 ArrayList?

声明

 List<SPListItem> arlist = new List<SPListItem>();

执行此操作

foreach (SPListItem Item in gItems) {
arlist.Add(Item);
}

而不是arlist.Add(gItems);

最后,当您完成循环所有子站点并添加所有事件后,像这样排序

arlist.OrderBy((x) => x.Item("EventDate"));

不要忘记添加命名空间system.collections。通用的。

Why not use a generic collection instead of ArrayList?

declaration

 List<SPListItem> arlist = new List<SPListItem>();

do this

foreach (SPListItem Item in gItems) {
arlist.Add(Item);
}

instead ofarlist.Add(gItems);

Finally when you are done looping through all the sub sites and adding all the events, sort like this

arlist.OrderBy((x) => x.Item("EventDate"));

Do not forget to add the namespace system.collections.generic.

sharepoint组合多个日历spquery arraylist排序

半城柳色半声笛 2024-12-18 13:48:21

两种可能的方式。首先,使用 def 和函数,我认为这是一个更好的抽象。

class C {
  def immutableMapFactory[A,B]: ((A,B)*) => Map[A,B] = scala.collection.immutable.Map.apply _
}

class TestableC extends C {
  override def immutableMapFactory[A,B] = scala.collection.immutable.ListMap.apply _
}

其次,使用 val 和结构类型:

class C {
  val immutableMapFactory: { def apply[A,B](t: (A,B)*): Map[A,B] } = scala.collection.immutable.Map
}

class TestableC extends C {
  override val immutableMapFactory: { def apply[A,B](t: (A,B)*): Map[A,B] } = scala.collection.immutable.ListMap
}

Two possible ways. First, using def and functions, which I think is a better abstraction.

class C {
  def immutableMapFactory[A,B]: ((A,B)*) => Map[A,B] = scala.collection.immutable.Map.apply _
}

class TestableC extends C {
  override def immutableMapFactory[A,B] = scala.collection.immutable.ListMap.apply _
}

Second, using val, and structural types:

class C {
  val immutableMapFactory: { def apply[A,B](t: (A,B)*): Map[A,B] } = scala.collection.immutable.Map
}

class TestableC extends C {
  override val immutableMapFactory: { def apply[A,B](t: (A,B)*): Map[A,B] } = scala.collection.immutable.ListMap
}

如何使用伴随工厂对象作为策略?

半城柳色半声笛 2024-12-18 12:32:32

tail -f /path/to/apachelogs

然后刷新你的页面&查看日志,PHP 会在那里吐出错误。

tail -f /path/to/apache logs

Then refresh your page & watch logs, PHP will spit its errors there.

如果 MySQL 中的行数

半城柳色半声笛 2024-12-18 07:00:41

即使存在事先未知的嵌套,也可以使用 XPath 表达式,例如:

(//*[local-name()='root' and namespace-uri()='DK'])[$k]

其中 $k 可以用正整数替换。

请注意

  1. 上面表达式中的括号是必需的。

  2. XPath 中的索引是从 1 开始的,而不是像 C# 或 C++ 中那样从 0 开始。

Even if there is nestedness that isn't known in advance, one can use an XPath expression like:

(//*[local-name()='root' and namespace-uri()='DK'])[$k]

where $k can be substituted with a positive integer.

Do note:

  1. The brackets in the above expression are necessary.

  2. Indexing in XPath is 1 - based, not 0 -based as in C# or C++.

在 XPath 表达式中使用整数变量 Java 从具有名称空间的重复节点中提取信息

半城柳色半声笛 2024-12-18 04:55:24

正如你所说,我曾在 Xilinx 使用 VHDL 并完成过电路设计。您可以使用 vhdl 和汇编来为许多不同的项目进行编码,例如在英特尔 8088 等微处理器后面编写代码或使用两台计算机之间的 RS232 端口运行客户端服务器简单程序等。您可以用它做一百万件事,但是唯一的限制是语言本身(VHDL)通常被设计用来模拟、编码和测试硬件及其功能。用于模拟而不是真正为其他任何内容编写代码,我建议您尝试可用于更好项目的其他语言。

I have worked with VHDL in Xilinx and done electrical circuit design as you have said. You can use vhdl and assembly to code for numerous different projects such as writing the code behind a microprocessor such as intel 8088 or running a client server simple program using the RS232 port between two computers etc. Probably a million things you can do with it but the only limitations are that generally the language itself (VHDL) was designed to emulate and code and test hardware and its functioning. Meant for simulation and not really to code for anything else, I suggest you try other languages that can be used for better projects.

除了电路设计之外,VHDL 还能做什么?

半城柳色半声笛 2024-12-18 04:30:53

=> 部分是一个 lambda 表达式。 lambda 表达式可以转换为委托< em>表达式树。它就像 C# 2 中引入的匿名方法的更好版本。

Where 方法是 LINQ 的一部分。在这种情况下,您可能指的是 LINQ to Objects 版本,Enumerable.Where - 但并不完全清楚,因为我们不知道所涉及的类型。我强烈建议您从书籍或优秀教程中开始学习 LINQ - 这并不是那种可以从 Stack Overflow 等问答网站轻松学习的主题。

您的错误可能是由于以下三个问题之一造成的:

  • 您可能没有使用 .NET 3.5,这是 LINQ 的先决条件,除非您使用第三方库(例如 LINQBridge)。
  • 您的代码中可能没有 using System.Linq; 指令
  • PSMemberInfoCollection 可能无法实现通用 IEnumerable 接口。我们无法从您所呈现的内容中真正分辨出那部分。

如果您能给我们提供更多信息,我们也许能够提供更多帮助。

The => part is a lambda expression. A lambda expression can be converted into a delegate or an expression tree. It's like a better version of anonymous methods which were introduced in C# 2.

The Where method is part of LINQ. In this case you probably mean the LINQ to Objects version, Enumerable.Where - but it's not entirely clear as we don't know about the types involved. I strongly recommend that you start learning LINQ from a book or good tutorial - it isn't really the kind of topic which can be learned easily from a Q&A site such as Stack Overflow.

Your error is probably due to one of three problems:

  • You may not be using .NET 3.5, which is a pre-requisite for LINQ unless you use a third party library such as LINQBridge.
  • You may not have a using directive of using System.Linq; in your code
  • PSMemberInfoCollection may not implement the generic IEnumerable<T> interface. We can't really tell that part from what you've presented.

If you can give us more information, we may be able to help more.

C# 语法问题

更多

推荐作者

fangs

文章 0 评论 0

朱染

文章 0 评论 0

zhangcx

文章 0 评论 0

Willy

文章 0 评论 0

taohaoge

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文