走过海棠暮

文章 0 评论 0 浏览 24

走过海棠暮 2024-12-18 19:47:18

您不应该依赖计时器的间隔正好 10 毫秒。如果您将每个计时器滴答视为刷新屏幕计时器的请求,但从系统时钟或类似的东西中获取测量,那就更好了。

然后,无论机器(和 JS 实现)有多慢或多忙,您总是会看到一个准确的计时器1 - 只是更新频率较低的计时器。


1 当然,这只会与系统时钟一样准确。如果 Javascript 可以访问高性能计时器,例如 .NET 的 Stopwatch 类或 Java 的 System.nanoTime()方法,这样会更好用。

You shouldn't be relying on the interval of the timer being exactly 10ms. It would be better if you viewed each timer tick as a request to refresh the on-screen timer, but take the measurements from the system clock or something like that.

Then however slow or busy the machine (and JS implementation) is, you'll always see an accurate timer1 - just one which updates less often.


1 This will only be as accurate as the system clock, of course. If Javascript has access to a high-performance timer like .NET's Stopwatch class or Java's System.nanoTime() method, that would be better to use.

Firefox 10ms 间隔

走过海棠暮 2024-12-18 18:47:26

以下是我在使用 mongo3.x 时的使用方式:

假设您希望结果如下所示: {"data": [{"key":"v1"}, {"key":"v1"} , {"key":"v1"}] }

[step1]: 使用 Java Map 创建 json 对象,该对象映射到数组内的元素;也就是[]里面的{}

[step1 Ans]: Map m1,m2,m3 = new HashMap(); m1.put("key", "v1"); m2.put("密钥", "v1"); m3.put("key", "v1");

[步骤2]:使用Java List将所有Java Map添加到一个元素中。

[step2 Ans]: List list = new ArrayList();列表.add(m1);列表.add(m2); list.add(m3);

[step3]: 将 Java 列表添加到 mongo

[step3 Ans]: Document dc = new Document("key", list);

Here is how i use it when using mongo3.x:

suppose you want the result to be like this: {"data": [{"key":"v1"}, {"key":"v1"}, {"key":"v1"}] }

[step1]: use Java Map to create json object which maps to the elements inside the array; that is, the {} inside []

[step1 Ans]: Map m1,m2,m3 = new HashMap(); m1.put("key", "v1"); m2.put("key", "v1"); m3.put("key", "v1");

[step2]: use Java List to add all Java Map into one element.

[step2 Ans]: List list = new ArrayList(); list.add(m1); list.add(m2); list.add(m3);

[step3]: add Java list into mongo

[step3 Ans]: Document dc = new Document("key", list);

在 MongoDB 中的对象中插入数组

走过海棠暮 2024-12-18 18:00:32

您只需传输 10k 字节即可执行测试。您正在做的很多事情都会产生开销,而如此小的数据集可能会因这种开销而产生偏差。 (例如创建套接字、分配内存等)您应该创建并传输更大的数据集(数十MB+),以便更现实地了解正在发生的情况。这样做将使开销成为数据传输过程中较小、不太重要的部分。

您还应该多次执行此测试(> 10)并取平均值,因为您的计算机将在不同的随机时间点承受来自服务、网络传输等的负载,并且这些负载将影响您的传输速率。通过 10 次以上的迭代,您还可以删除任何异常缓慢的运行时间,例如 > 2 个标准差。

You're only transferring 10k bytes to perform your test. There is overhead to a lot of what you're doing and such a small set of data may be getting skewed by this overhead. (e.g. creating sockets, allocating memory etc.) You should create and transfer a much larger set of data (dozens of MBs+) to get a more realistic idea of what's going on. Doing this will make the overhead a smaller, less significant part of the data transfer process.

You should also perform this test a number of times (> 10) and take the average because your computer will be under loads from services, network transfers etc. at different, random points in time and these loads will affect your transfer rate. With 10+ iterations you could also drop any run times that are unusually slow, such as > 2 standard deviations.

电脑上socket的速度是120MB/s,正常吗?

走过海棠暮 2024-12-18 15:54:17

最快的方法是使用操作系统的网络功能:socket()setsockopt()connect()listen( )send()recv() 等等。

它们在几个操作系统上存在细微的差异。

为了解决这个问题,在几个库中都有它们的包装器,例如在 Qt 中(至少是 IIRC)。我认为如果你使用它们,任何事情都不会明显减慢......

The fastest way would be to use the OS's networking functions: socket(), setsockopt(), connect(), listen(), send(), recv() etc. etc.

There are subtle differences between them on several OS's.

To cope with this, there are wrappers around them in several libraries, e.g. in Qt (at least, IIRC). I don't think anything will noticeably slow down if you use them...

C网络编程?

走过海棠暮 2024-12-18 09:45:55
$manu_name = mysql_real_escape_string($_POST['manu_name']);
$query = "SELECT p2.prod_type, p2.prod_id, p2.prod_coupon_img
FROM products p2 
WHERE p2.id IN (
  SELECT Min(p.id)
  FROM products p 
  INNER JOIN manu m ON (m.manu_id = p.manu_id)
  WHERE m.manu_name = '$manu_name'
  GROUP BY prod_coupon_img) ";
$manu_name = mysql_real_escape_string($_POST['manu_name']);
$query = "SELECT p2.prod_type, p2.prod_id, p2.prod_coupon_img
FROM products p2 
WHERE p2.id IN (
  SELECT Min(p.id)
  FROM products p 
  INNER JOIN manu m ON (m.manu_id = p.manu_id)
  WHERE m.manu_name = '$manu_name'
  GROUP BY prod_coupon_img) ";

混合 2 个查询来显示独特的优惠券 PHP/MySql

走过海棠暮 2024-12-18 06:18:29

您需要反射。这是我的完整示例。

A 类

 package a;
    public class A {
        String info;
        public String getInfo() {
            System.out.println("A getInfo");
            return info;
        }
        public void setInfo(String info) {
            this.info = info;
        }
    }

B 类

package a;
public class B {
    String info;
    public String getInfo() {
        System.out.println("B getInfo");
        return info;
    }
    public void setInfo(String info) {
        this.info = info;
    }
}

测试类

package a;
import java.lang.reflect.Method;
public class TestAB {
    public static void main(String[] args) {
        A a= new A();
        doSth(a);
    }
    private static void doSth(Object obj) {
        Class c = obj.getClass();
        Method m;
        try {
            m = c.getMethod("getInfo", new Class[] { });
            String result = (String) m.invoke(obj);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

请参阅这一行:

Class c = obj.getClass();

>m = c.getMethod("getInfo", new Class[] { });

String result = (String) m.invoke(obj);

没有 if 语句

You need reflection. here is my complete example.

Class A

 package a;
    public class A {
        String info;
        public String getInfo() {
            System.out.println("A getInfo");
            return info;
        }
        public void setInfo(String info) {
            this.info = info;
        }
    }

Class B

package a;
public class B {
    String info;
    public String getInfo() {
        System.out.println("B getInfo");
        return info;
    }
    public void setInfo(String info) {
        this.info = info;
    }
}

Test Class

package a;
import java.lang.reflect.Method;
public class TestAB {
    public static void main(String[] args) {
        A a= new A();
        doSth(a);
    }
    private static void doSth(Object obj) {
        Class c = obj.getClass();
        Method m;
        try {
            m = c.getMethod("getInfo", new Class[] { });
            String result = (String) m.invoke(obj);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

See this line :

Class c = obj.getClass();

and

m = c.getMethod("getInfo", new Class[] { });

and

String result = (String) m.invoke(obj);

There is no if statements

Java 并避免对具有类似方法的对象使用 if 语句

走过海棠暮 2024-12-17 23:55:58

根据您的代码(请参阅下面的注释),您的登录链接似乎具有 class="login_link" 并且您的登录弹出窗口启动代码是 $("#loginpopup").dialog() ;。要在单击链接时打开该弹出窗口,您需要:

$('a.login_link').click(function(e){
   e.preventDefault();
   $("#loginpopup").dialog();
});

学习参考:jQuery 类选择器, jQuery .click() 方法

仅供参考: 它会有助于实际在中包含相关代码的示例您的问题(a.login_link $("#loginpopup").dialog(); 在这个特定的例子)。否则,您的问题对于浏览 StackOverflow 寻找答案的其他人来说基本上没有任何价值。

仅供参考 2: 您用 // 注释注释掉了大量行。您可以使用 /*my comment*/ 进行多行注释。

Based on your code (see note below), it appears that your login links have class="login_link" and your login popup launch code is $("#loginpopup").dialog();. To make that popup open when the links are clicked, you need:

$('a.login_link').click(function(e){
   e.preventDefault();
   $("#loginpopup").dialog();
});

References for learning: jQuery Class Selector, jQuery .click() method

FYI: It would be helpful to actually include an example of the relevant code in your question (a.login_link and $("#loginpopup").dialog(); in this specific example). Otherwise, your question essentially has no value to other people browsing StackOverflow looking for answers.

FYI 2: You have tons of lines commented out with // comments. You can use /*my comment*/ for multiline comments.

如何使 jQuery 弹出对话框在“登录链接”上弹出点击次数

走过海棠暮 2024-12-17 23:51:12

如果您想通过菜单执行此操作,则为:

Edit / IntelliSense / Refresh Local Cache

使用键盘,则为:
CTRL-SHIFT-R

If you want to do it via the menus, it's:

Edit / IntelliSense / Refresh Local Cache

Using the keyboard, it's:
CTRL-SHIFT-R

SQL 服务器。如何刷新智能感知?

走过海棠暮 2024-12-17 20:44:20

sscanf() 可能有效...

int y, m, d, h;
int seconds;
char val[] = "P5Y2M10DT15H";
if(sscanf(val, "P%dY%dM%dDT%dH", &y, &m, &d, &h) != 4) /* error */;
seconds = y*3162240 + m*<WHATEVER> + d*24*3600 + h*3600;

sscanf() may work ...

int y, m, d, h;
int seconds;
char val[] = "P5Y2M10DT15H";
if(sscanf(val, "P%dY%dM%dDT%dH", &y, &m, &d, &h) != 4) /* error */;
seconds = y*3162240 + m*<WHATEVER> + d*24*3600 + h*3600;

如何解析 xml 日期和时间并将其转换为秒

走过海棠暮 2024-12-17 13:21:25

首先,您的方法签名不正确。你不需要“低”。您应该将数组/列表作为输入并返回最大的元素。然而,您可能会发现您需要一个需要额外参数的辅助方法。

当接近递归并且您陷入困境时,通常最好首先确定您的基本情况,然后再处理递归情况。

您的基本情况是您知道答案的最简单情况。在这个问题中,如果列表的大小为 1,您立即知道最大的元素是什么 - 您只需返回唯一的元素。您可能还需要考虑列表为空的情况。

那么,您的递归情况是每当您的列表大小大于 1 时。在您的递归情况下,您想要尝试“分解一部分”,然后将其余部分发送到递归调用。在这种情况下,您可以查看列表中的第一个元素,并将其与列表其余部分的递归调用所获得的结果进行比较。

First, your method signature is incorrect. You do not need a 'low'. You should take an array/list as input and return the largest element. You may find however that you want a secondary method that requires extra arguments.

When approaching recursion and you're stuck, it's often best to identify your base case(s) first, then deal with your recursive case(s) next.

Your base case is the simplest case in which you know the answer. In this problem, you know what the largest element is right away if the size of your list is 1 - you just return the only element. You may want to think about the case where your list is empty as well.

Your recursive case then, is whenever your list has size greater than 1. In your recursive case, you want to try and 'break a piece off' and then send the rest to a recursive call. In this case, you can look at the first element in the list, and compare it to the result you get from a recursive call on the rest of the list.

将getLargest重写为Java中的递归方法

走过海棠暮 2024-12-17 11:08:47

从 SDK 1.5.5 更新开始,该示例已过时。

现在它应该看起来或多或少像这样:

package main

import (
    "fmt"
    "http"
    "template"
)

func init() {
    http.HandleFunc("/", root)
    http.HandleFunc("/sign", sign)
}

func root(w http.ResponseWriter, r *http.Request) {
    fmt.Fprint(w, guestbookForm)
}

const guestbookForm = `
<html>
 <body>
  <form action="/sign" method="post">
    <div><textarea name="content" rows="3" cols="60"></textarea></div>
    <div><input type="submit" value="Sign Guestbook"></div>
  </form>
 </body>
</html>
`

func sign(w http.ResponseWriter, r *http.Request) {
    err := signTemplate.Execute(w, r.FormValue("content"))
    if err != nil {
        http.Error(w, err.String(), http.StatusInternalServerError)
    }
}

var signTemplate = template.Must(template.New("SignIn").Parse(signTemplateHTML))

const signTemplateHTML = `
<html>
 <body>
  <p>You wrote:</p>
  <pre>{{.|html}}</pre>
 </body>
</html>`

注意调用初始化 var signTemplate 和signTemplateHTML 变量中的模板参数的区别,{{.|html}} 而不是{@|html}

The sample is outdated starting with the SDK 1.5.5 update.

Now it should look more or less like this:

package main

import (
    "fmt"
    "http"
    "template"
)

func init() {
    http.HandleFunc("/", root)
    http.HandleFunc("/sign", sign)
}

func root(w http.ResponseWriter, r *http.Request) {
    fmt.Fprint(w, guestbookForm)
}

const guestbookForm = `
<html>
 <body>
  <form action="/sign" method="post">
    <div><textarea name="content" rows="3" cols="60"></textarea></div>
    <div><input type="submit" value="Sign Guestbook"></div>
  </form>
 </body>
</html>
`

func sign(w http.ResponseWriter, r *http.Request) {
    err := signTemplate.Execute(w, r.FormValue("content"))
    if err != nil {
        http.Error(w, err.String(), http.StatusInternalServerError)
    }
}

var signTemplate = template.Must(template.New("SignIn").Parse(signTemplateHTML))

const signTemplateHTML = `
<html>
 <body>
  <p>You wrote:</p>
  <pre>{{.|html}}</pre>
 </body>
</html>`

Notice the difference in call initializing var signTemplate and the template parameter in the signTemplateHTML variable, {{.|html}} instead of {@|html}.

Appengine Go开发服务器找不到模板包

走过海棠暮 2024-12-16 19:24:34

尝试将重复函数与否定运算符“!”结合使用。

示例:

wdups <- rep(1:5,5)
wodups <- wdups[which(!duplicated(wdups))]

希望有帮助。

Try using the duplicated function in combination with the negation operator "!".

Example:

wdups <- rep(1:5,5)
wodups <- wdups[which(!duplicated(wdups))]

Hope that helps.

列出 R 向量中的不同值

走过海棠暮 2024-12-16 15:47:27
WHERE fixture_date < NOW();

这就是你要去的目的?时间戳可以像任何其他数据类型一样进行比较。

WHERE fixture_date < NOW();

That what you're going for? timestamps can be compared like any other data type.

时间戳早于现在?

走过海棠暮 2024-12-16 14:25:08

是的,这是可能的:

ContentPanelCanvas.Children.Clear();

这将清空画布。

Yes, it is possible:

ContentPanelCanvas.Children.Clear();

This will empty the canvas.

wp7清晰画布值

走过海棠暮 2024-12-16 13:42:37

尽管它完成了它的工作,但您的方法基本上否定了正确的 PKI 的目的。如果您盲目信任任何自签名证书,那么使用 TLS 根本没有任何意义 - 任何人都可以创建可通过您的 TrustManager 的自签名证书。

因此,如果您想要安全,那么您应该首先找出您的客户端应用程序将与哪些服务器通信,然后获取链接到这些服务的 TLS 服务器证书(在您的场景中,每个它们是自签名的,因此您无需关心中间证书)。

现在,使用这些证书,您创建一个 JKS“信任存储”文件并将证书放入其中 - 这是您要信任的证书集,未包含在此文件中的证书将被拒绝。要创建 JKS 文件,您可以使用 Java 的 keytool 命令,或者您可以使用 KeyStore API 以编程方式执行此操作。

最后,您将创建供 HttpClient 使用的 SSLContext,并使用如下创建的 TrustManagerinit 它:

KeyStore ks = KeyStore.getInstance("JKS");
ks.load(fin, pwd);
TrustManagerFactory tmf = TrustManagerFactory.getInstance("PKIX");
tmf.init(ks);

其中fin是您的“信任存储”的InputStreampwd是您用于加密它的密码。默认的 TrustManager 实现让您只需要使用一组受信任的证书,其余的都会为您处理。

Although it does its job, your approach basically denies the purpose of a proper PKI. If you blindly trust any self-signed certificate, then there is no point in using TLS at all - anyone can create a self-signed certificate that would pass your TrustManager.

So, if you want to be secure, then you should first find out which servers your client application will be communicating with and then get the TLS server certificates that are linked to those services (in your scenario each of them is self-signed, so you don't need to care about intermediate certificates).

Now, using these certificates, you create a JKS "trust store" file and put the certificates in it - this is the set of certificates you are going to trust, certificates not contained in this file will be rejected. To create a JKS file you can either use Java's keytool command or you can do it programmatically using the KeyStore API.

Finally you would create the SSLContext to be used by your HttpClient and init it with a TrustManager created like this:

KeyStore ks = KeyStore.getInstance("JKS");
ks.load(fin, pwd);
TrustManagerFactory tmf = TrustManagerFactory.getInstance("PKIX");
tmf.init(ks);

where fin is the InputStream of your "trust store" and pwd the password you used to encrypt it. The default TrustManager implementation this gives you needs only the set of trusted certificates to work with, the rest is taken care of for you.

这是接受自签名证书的有效方法吗?

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