灯角

文章 0 评论 0 浏览 23

灯角 2024-10-14 09:31:38

86400-(EventTimeStamp) 作为 new_users

86400-(EventTimeStamp) as new_users

MySQL 查询 - 查找“新”每日用户数

灯角 2024-10-14 07:00:12

ROWGUIDCOLUMN 主要用于需要将多个卫星数据库表的内容组合到一个中央数据库中的复制场景。

将 ROWGUIDCOLUMN 添加到正在复制的表中可确保复制引擎可以使用 ROWGUIDCOLUMN 字段来区分具有相同主键值的记录。

由于此功能主要用于确保顺利复制,因此您应避免使用此列作为主键。您的主键应该是一个逻辑业务实体,该实体在您的控制之下,并且不会影响您选择的数据库引擎的特定功能的操作特征。

The ROWGUIDCOLUMN is used primarily in replication scenarios where you need to combine the contents of several satelite databases' tables into one central DB.

Adding a ROWGUIDCOLUMN to the tables being replicated ensures that the replication engine can use the ROWGUIDCOLUMN field to differentiate between records with the same primary key values.

Because this is a feature primarily used to ensure smooth replication, you should avoid using this column as your primary key. Your primary key should be a logical business entity that is under your control and which doesn't affect the operational characteristics of specific features of your chosen DB engine.

MS SQL Server 行 GUID 列

灯角 2024-10-14 05:45:14

您可以使用以下查询代替 Account.where(:admin => false).count

Account.select(:id).where(:admin => false).count

只需选择一列,而不是选择全部。它生成以下查询,并且比前一个查询更快:

SELECT COUNT("accounts"."id") FROM "accounts" where admin = false

You can use following query instead of Account.where(:admin => false).count

Account.select(:id).where(:admin => false).count

Just select one column, instead of selecting all. It generates the following query and it is faster than the previous one:

SELECT COUNT("accounts"."id") FROM "accounts" where admin = false

在 Rails 中进行计数的正确方法是什么?

灯角 2024-10-14 04:23:12

自定义 Bean 工厂是一个具有创建 Bean 方法的类。有两种“风格”

a) 静态创建方法

SomeBean x = SomeBeanFactory.createSomeBean();

b) 实例创建方法

SomeBeanFactory sbf = new SomeBeanFactory();
SomeBean x = sbf.createSomeBean();

如果创建和设置 bean 需要一些棘手的逻辑(例如某些属性的初始值取决于外部配置文件),您将创建一个 bean 工厂。 bean 工厂类允许您集中有关如何创建如此棘手的 bean 的“知识”。其他类只是调用 create 方法,而不用担心如何正确创建这样的 bean。

A custom bean factory is a class that has a method that creates a bean. There are two "flavours"

a) static create method

SomeBean x = SomeBeanFactory.createSomeBean();

b) instance create method

SomeBeanFactory sbf = new SomeBeanFactory();
SomeBean x = sbf.createSomeBean();

You would create a bean factory if creating and setting up your bean requires some tricky logic, like for example initial value of certain properties depend on external configuration file. A bean factory class allows you to centralize "knowledge" about how to create such a tricky bean. Other classes just call create method without worying how to correctly create such bean.

Dozer BeanFactory:如何实现?

灯角 2024-10-13 18:29:28

您可以在 anddev.org 上找到一些线索。基本思想是扩展默认主题并在您的活动中使用它。特别是,您需要扩展 Theme.Dialog 样式。

You have some clues on anddev.org. The basic idea is to extend the default theme and use it in your activity. In particular, you will need to extend the Theme.Dialog style.

如何改变对话框的颜色

灯角 2024-10-13 18:03:18

正如 Dave Webb 的 freezeset 的替代方案一样,为什么不执行如下所示的 SymDict:

class SymDict(dict):
    def __getitem__(self, key):
        return dict.__getitem__(self, key if key[0] < key[1] else (key[1],key[0]))

    def __setitem__(self, key, value):
        dict.__setitem__(self, key if key[0] < key[1] else (key[1],key[0]), value)

从快速测试来看,这比使用 freezeset 获取和设置项目的速度快 10% 以上。无论如何,只是另一个想法。然而,它的适应性不如 freezeset,因为它实际上只设置为与长度为 2 的元组一起使用。据我从 OP 中可以看出,这似乎不是问题。

Just as an alternative to Dave Webb's frozenset, why not do a SymDict like the following:

class SymDict(dict):
    def __getitem__(self, key):
        return dict.__getitem__(self, key if key[0] < key[1] else (key[1],key[0]))

    def __setitem__(self, key, value):
        dict.__setitem__(self, key if key[0] < key[1] else (key[1],key[0]), value)

From a quick test, this is more than 10% faster for getting and setting items than using a frozenset. Anyway, just another idea. However, it is less adaptable than the frozenset as it is really only set up to be used with tuples of length 2. As far as I can tell from the OP, that doesn't seem to be an issue here.

对称字典,其中 d[a][b] == d[b][a]

灯角 2024-10-13 11:51:23

把丑陋写一次,然后隐藏起来

def check_all_present(hash, keys)
  current_hash = hash
  keys.each do |key|
    return false unless current_hash[key]
    current_hash = current_hash[key]
  end
  true
end

Write the ugliness once, then hide it

def check_all_present(hash, keys)
  current_hash = hash
  keys.each do |key|
    return false unless current_hash[key]
    current_hash = current_hash[key]
  end
  true
end

如何避免嵌套哈希中缺少元素的 NoMethodError,而不需要重复的 nil 检查?

灯角 2024-10-13 11:39:56

在这种情况下,端口模式负责。您在等待模式(默认情况下处于打开状态)中使用缓冲 I/O。

在http中,当您读取所有服务器字节后,客户端负责关闭端口。

由于您基本上直接使用 TCP,使用插入端口,因此您还负责检测请求的结束并在足够的字节到达时关闭端口。这只能在进行低级 tcp 乐趣时在 /lines 或 /no-wait 中完成。

阅读和信息的东西?为你做。

而 [data: copy port][append out data]

直到发生超时(REBOL 中默认为 30 秒)才会终止。

另外,您的请求似乎有错误...

试试这个:

port: open/lines tcp://cdimage.ubuntu.com:80
insert port {HEAD /daily/current/natty-alternate-i386.iso HTTP/1.0
Accept: */*
Connection: close
User-Agent: REBOL View 2.7.7.3.1
Host: cdimage.ubuntu.com
}
out: form copy port
block: parse out none ;rejoin [": ^/"]
probe select block "Content-Length:"

在这里添加 /lines 似乎会阻止等待。它可能与http方案如何处理打开时的线路模式有关。

在文档中查找 REBOL 端口模式,并在网上对其进行了很好的解释。

如果您使用了trace/net,您就会意识到所有数据包都已收到,并且解释器仍在等待。顺便说一句,您的代码实际上在我的测试中返回了错误 400。

the port modes are responsible in this case. you where using buffered I/O with the wait mode (which is on by default).

in http, the client is responsible closing of the port when you've read all the server bytes.

since you are basically using tcp directly, using insert port, you are responsible for also detecting the end of the request and closing the port when sufficient bytes have arrived. this can only be done in /lines or /no-wait when doing low-level tcp fun.

Something that read and info? do for you.

while [data: copy port][append out data]

doesn't terminate until a timeout occurs (which is 30 seconds by default in REBOL).

also, your request seems to be in error...

try this:

port: open/lines tcp://cdimage.ubuntu.com:80
insert port {HEAD /daily/current/natty-alternate-i386.iso HTTP/1.0
Accept: */*
Connection: close
User-Agent: REBOL View 2.7.7.3.1
Host: cdimage.ubuntu.com
}
out: form copy port
block: parse out none ;rejoin [": ^/"]
probe select block "Content-Length:"

here it seems that adding /lines will prevent the wait. its probably related to how the http scheme handles the line mode on open.

look around for REBOL port modes within the documentation and on the net its well explained all over the place.

if you had used trace/net on, you'd realized that all the packets where received and that the interpreter was just still waiting. btw your code actually returned an error 400 in my tests.

为什么 Rebol Raw Http Head Request 获取远程文件大小与信息相比非常慢?功能

灯角 2024-10-13 11:07:29

一个简单的实验将回答这个问题:

if( foo != null ) {
   alert('foo not null');
}

上面的例子在许多浏览器中都会产生一个 JavaScript 错误:“ReferenceError:找不到变量:foo”。这是因为我们使用了一个先前未在当前作用域中声明为参数或 var 的变量。

另一方面,typeof 运算符对尚未定义的变量进行显式调整——它返回'undefined',因此:

if( typeof foo != 'undefined') {
    alert('foo is not defined');
}

按预期工作。

所以答案是“不”——它们不是同一件事——尽管在某些 javascript 环境中它们的行为方式可能相同,在其他环境中你的第二种形式会当 foo 未定义时产生错误。

A simple experiment will answer this question:

if( foo != null ) {
   alert('foo not null');
}

the above example yields a javascript error in many browsers: "ReferenceError: Can't find variable: foo". This is because we've used a variable that has not been previously declared as an argument or var in current scope.

the typeof operator, on the other hand, makes an explicit accommodation for variables that haven't been defined -- it returns 'undefined', so:

if( typeof foo != 'undefined') {
    alert('foo is not defined');
}

works as expected.

So the answer is "no" -- they are not the same thing -- though in some javascript environments they may behave the same way, in other environments your second form will produce errors when foo is not defined.

检查 JavaScript 中是否为 null/未定义

灯角 2024-10-13 10:07:52

删除从应用程序目标导入“xmlversion.h”、“tree.h”、“xmlIO.h”的头文件。
在我的一个项目中,我使用 MGTwitterEngine 库。在将库与我的应用程序集成时,我遇到了同样的问题。然后我阅读了以下链接,它帮助我解决了问题
http://aralbalkan.com/3133

Remove the header file(s) which is importing "xmlversion.h", "tree.h", "xmlIO.h" from your application target.
In one of my project, I am using MGTwitterEngine libray. I was facing the same problem while inegrating the library with my application. Then I read following link which helped me to solve the problem
http://aralbalkan.com/3133

将 Twitter API 集成到 iPhone 应用程序中会出现错误

灯角 2024-10-13 10:02:38
>cat test.txt
 <getTheIP ConnectType='INFO' Host='machine_num_1' VirtualIp='12.34.3.9'/>
 <getTheIP ConnectFour='INFO' Host='machine_num_41' VirtualIp='12.34.3.9'/>
 <getTheIP ConnectThree='INFO' Host='machine_num_31' VirtualIp='12.34.3.9'/>
 <getTheIP ConnectType='INFO' Host='machine_num_21' VirtualIp='12.34.3.9'/>

>perl -lpe "if (/ConnectType/ && /'machine_num_1'/) {s/(\d{1,3}\.){3}\d{1,3}/3.4.5.6/};" test.txt
 <getTheIP ConnectType='INFO' Host='machine_num_1' VirtualIp='3.4.5.6'/>
 <getTheIP ConnectFour='INFO' Host='machine_num_41' VirtualIp='12.34.3.9'/>
 <getTheIP ConnectThree='INFO' Host='machine_num_31' VirtualIp='12.34.3.9'/>
 <getTheIP ConnectType='INFO' Host='machine_num_21' VirtualIp='12.34.3.9'/>
>cat test.txt
 <getTheIP ConnectType='INFO' Host='machine_num_1' VirtualIp='12.34.3.9'/>
 <getTheIP ConnectFour='INFO' Host='machine_num_41' VirtualIp='12.34.3.9'/>
 <getTheIP ConnectThree='INFO' Host='machine_num_31' VirtualIp='12.34.3.9'/>
 <getTheIP ConnectType='INFO' Host='machine_num_21' VirtualIp='12.34.3.9'/>

>perl -lpe "if (/ConnectType/ && /'machine_num_1'/) {s/(\d{1,3}\.){3}\d{1,3}/3.4.5.6/};" test.txt
 <getTheIP ConnectType='INFO' Host='machine_num_1' VirtualIp='3.4.5.6'/>
 <getTheIP ConnectFour='INFO' Host='machine_num_41' VirtualIp='12.34.3.9'/>
 <getTheIP ConnectThree='INFO' Host='machine_num_31' VirtualIp='12.34.3.9'/>
 <getTheIP ConnectType='INFO' Host='machine_num_21' VirtualIp='12.34.3.9'/>

Perl +仅当匹配行中的两个单词时,一行才更改字符串

灯角 2024-10-13 09:48:37

这是一个单行程序,它通过管道传输网站的输出并使用 grep 和 lynx 删除导航元素!您可以将 lynx 替换为 cat FileA,将unknown-elements.txt 替换为 FileB。

lynx -dump -accept_all_cookies -nolist -width 1000 https://stackoverflow.com/ | grep -Fxvf unwanted-elements.txt

Here is a one liner that pipes the output of a website and removes the navigation elements using grep and lynx! you can replace lynx with cat FileA and unwanted-elements.txt with FileB.

lynx -dump -accept_all_cookies -nolist -width 1000 https://stackoverflow.com/ | grep -Fxvf unwanted-elements.txt

如何从另一个文件A中删除文件B上出现的行?

灯角 2024-10-13 07:39:43

假设两个表中的 Symbol 都是数字,您需要在 LIKE 子句中将 ti 转换为 varchar。
ON n.Symbol LIKE cast(p.SYMBOL as varchar) + '%'; 应该可以工作。

Assuming Symbol is numeric in both tables, you need to cast ti to varchar in the LIKE clausule.
ON n.Symbol LIKE cast(p.SYMBOL as varchar) + '%'; should work.

sql函数的问题

灯角 2024-10-13 04:37:38

WebClient 确实在 UI 线程上返回,所以是的,您的解析将阻塞 UI。出于性能原因,它是 建议您改用HttpWebRequest

使用 HttpWebReques ,您的事件将在后台线程上触发,以便您可以执行所需的所有处理,但是您会遇到将结果封送回 UI 线程以便您可以更新 UI 的问题(否则你会看到跨线程违规异常)。您可以使用 Dispatcher 通过如下方法将结果封送回 UI:

private void UpdateUI(Results results)
{
    if (!Deployment.Current.Dispatcher.CheckAccess())
        Deployment.Current.Dispatcher.BeginInvoke(() => UpdateUI(results));
    else
    {
        //Update the UI
    {
}

WebClient does indeed return on the UI thread so yes your parsing will be blocking the UI. For perf reasons it is recommended that you use HttpWebRequest instead.

With HttpWebRequest your event will fire on the background thread so you can do all the processing you need, however you then have the problem of marshaling the results back to the UI thread so that you can update the UI (otherwise you will see cross thread violation exceptions). You can use the Dispatcher to marshal the results back to the UI with a method like the following:

private void UpdateUI(Results results)
{
    if (!Deployment.Current.Dispatcher.CheckAccess())
        Deployment.Current.Dispatcher.BeginInvoke(() => UpdateUI(results));
    else
    {
        //Update the UI
    {
}

使用 WebClient 的 Silverlight 后台线程

灯角 2024-10-13 04:20:30

为什么它不应该工作?它将 %to_hex(*pstr >> 4)to_hex(*pstr & 15) 设置为由pbuf。等效代码可能如下:

else {
  *pbuf = '%';
  *(pbuf + 1) = to_hex(*pstr >> 4);
  *(pbuf + 2) = to_hex(*pstr & 15);
  pbuf += 3;
}

Why it shouldn't work? It sets %, to_hex(*pstr >> 4), to_hex(*pstr & 15) to sequential memory block addressed by pbuf. The equivalent code may be the following:

else {
  *pbuf = '%';
  *(pbuf + 1) = to_hex(*pstr >> 4);
  *(pbuf + 2) = to_hex(*pstr & 15);
  pbuf += 3;
}

什么是逗号分隔的一组作业?

更多

推荐作者

泪是无色的血

文章 0 评论 0

yriii2

文章 0 评论 0

1649543945

文章 0 评论 0

g红火

文章 0 评论 0

嘿哥们儿

文章 0 评论 0

旧城烟雨

文章 0 评论 0

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