半城柳色半声笛

文章 评论 浏览 26

半城柳色半声笛 2024-12-13 14:59:54

您可以使用 ORDER BY IF 语句:

SELECT *
FROM table
ORDER BY IF(SORT = 0, 999999999, SORT)

或者可以使用 UNION ALL 语句来实现此目的:

(SELECT * FROM table WHERE sort > 0 ORDER BY sort)
UNION ALL
(SELECT * FROM table WHERE sort = 0)

You can use the ORDER BY IF statement:

SELECT *
FROM table
ORDER BY IF(SORT = 0, 999999999, SORT)

or you can use the UNION ALL statement to achieve this:

(SELECT * FROM table WHERE sort > 0 ORDER BY sort)
UNION ALL
(SELECT * FROM table WHERE sort = 0)

MySQL排序时如何排除某些值?

半城柳色半声笛 2024-12-13 12:50:58

不要引用文档。除此之外,您的尝试是正确的。 :contains() 选择器是您所需要的:

$(document).ready(function() {  
    if ($('#div1:contains("TriggerWord")').length > 0) {
        $('#div2').css('color', 'red');
    }
});

或简写形式:

$(function() {  
    if ($('#div1:contains("TriggerWord")').length > 0) {
        $('#div2').css('color', 'red');
    }
});

这是一个现场演示

Don't quote document. Other than that your attempt is correct. The :contains() selector is what you need:

$(document).ready(function() {  
    if ($('#div1:contains("TriggerWord")').length > 0) {
        $('#div2').css('color', 'red');
    }
});

or with the shorthand form:

$(function() {  
    if ($('#div1:contains("TriggerWord")').length > 0) {
        $('#div2').css('color', 'red');
    }
});

And here's a live demo.

jQuery - 如果 div2 包含某个文本单词,则将 CSS 应用于 div1?

半城柳色半声笛 2024-12-13 12:00:36

听起来至少有一个线程正在阻塞并且无法响应中断。也许在有问题的线程上使用 .getState() 可能会阐明这个问题。

http://download.oracle .com/javase/6/docs/api/java/lang/Thread.html#getState%28%29

Sounds like at least one thread is blocking and can't respond to an interrupt. Perhaps using .getState() on the thread in question may shed some light on the problem.

http://download.oracle.com/javase/6/docs/api/java/lang/Thread.html#getState%28%29

什么可能导致Java返回后继续运行

半城柳色半声笛 2024-12-13 11:43:06
var imgs = new Array();
$('img.grid').each(function(idx){
 var i = new Image();
 i.src = $(this).attr('src');
 imgs.push(i);
});
var imgs = new Array();
$('img.grid').each(function(idx){
 var i = new Image();
 i.src = $(this).attr('src');
 imgs.push(i);
});

使用 jquery 预加载具有特定类的图像

半城柳色半声笛 2024-12-13 11:00:42

http://jsfiddle.net/Rs4TA/1/

$('*:contains("Test")').html('<span>Test</span>'); 

如果您的“测试”是静态文本,可以用这种方式完成。

http://jsfiddle.net/Rs4TA/1/

$('*:contains("Test")').html('<span>Test</span>'); 

If your "test" is a static text, it could be done by this way.

jQuery 用条件包装一些字符串

半城柳色半声笛 2024-12-13 08:06:51

使用 NSInitationOperation 调用的方法只能采用单个参数,并且该参数必须是 Objective-C 对象(如 NSNumber),而不是普通的 C 类型(如 <代码> int )。

通常,要处理多个参数,您可以使用 NSDictionary 或 NSArray 来保存参数:

- (void)myMethod:(NSDictionary*)parameters 
{
    int a = [[parameters objectForKey:@"A"] intValue];
    int b = [[parameters objectForKey:@"B"] intValue];

    // do something with a and b
}


[[NSInvocationOperation alloc] 
    initWithTarget:self
          selector:@selector(myMethod:)
            object:[NSDictionary dictionaryWithObjectsAndKeys:
                     [NSNumber numberWithInt:123], @"A",
                     [NSNumber numberWithInt:456], @"B",
                     nil]];

或者,您可以使用 NSInitation 对象来调用您的方法。这允许任意数量和任意类型的参数,但通常将参数放入 NSDictionary 中比构造 NSInitation 对象要容易得多。

有关如何使用 NSInitation 的信息。

The method you invoke with NSInvocationOperation can only take a single parameter, and that parameter must be an Objective-C object (like NSNumber) and not a plain C type (like int).

Typically, to handle multiple parameters you use an NSDictionary or NSArray to hold the parameters:

- (void)myMethod:(NSDictionary*)parameters 
{
    int a = [[parameters objectForKey:@"A"] intValue];
    int b = [[parameters objectForKey:@"B"] intValue];

    // do something with a and b
}


[[NSInvocationOperation alloc] 
    initWithTarget:self
          selector:@selector(myMethod:)
            object:[NSDictionary dictionaryWithObjectsAndKeys:
                     [NSNumber numberWithInt:123], @"A",
                     [NSNumber numberWithInt:456], @"B",
                     nil]];

Alternatively, you can use an NSInvocation object to invoke your method. This allows any number and any type of parameters, but it's typically much easier to just put your parameters in an NSDictionary than to construct an NSInvocation object.

Information on how to use NSInvocation.

iphone @selector 有两个参数

半城柳色半声笛 2024-12-12 22:11:12

我认为你应该尝试使用 Rails.logger 而不是方法“puts”。

I think you should try to use Rails.logger instead of the method 'puts'.

为什么我无法在 Heroku 控制台中打印(“放置”)?

半城柳色半声笛 2024-12-12 15:56:51

上面提到的一些方法在处理数字或字符串等简单数据类型时效果很好,但当数组包含其他对象时,这些方法就会失败。当我们尝试将任何对象从一个数组传递到另一个数组时,它将作为引用而不是对象传递。

在您的 JavaScript 文件中添加以下代码:

Object.prototype.clone = function() {
    var newObj = (this instanceof Array) ? [] : {};
    for (i in this) {
        if (i == 'clone') 
            continue;
        if (this[i] && typeof this[i] == "object") {
            newObj[i] = this[i].clone();
        } 
        else 
            newObj[i] = this[i]
    } return newObj;
};

只需使用

var arr1 = ['val_1','val_2','val_3'];
var arr2 = arr1.clone()

它即可工作。

Some of mentioned methods work well when working with simple data types like number or string, but when the array contains other objects these methods fail. When we try to pass any object from one array to another it is passed as a reference, not the object.

Add the following code in your JavaScript file:

Object.prototype.clone = function() {
    var newObj = (this instanceof Array) ? [] : {};
    for (i in this) {
        if (i == 'clone') 
            continue;
        if (this[i] && typeof this[i] == "object") {
            newObj[i] = this[i].clone();
        } 
        else 
            newObj[i] = this[i]
    } return newObj;
};

And simply use

var arr1 = ['val_1','val_2','val_3'];
var arr2 = arr1.clone()

It will work.

按值复制数组

半城柳色半声笛 2024-12-12 12:11:24

在 Eclipse 中,为了让它满意,我必须通过 JPA 工具创建表。

右键单击项目> JPA工具>从实体生成表

我想您也可以关闭验证,但创建表似乎更有意义。

In Eclipse to make it happy I had to create the table via JPA Tools.

Right Click Project > JPA Tools > Generate Tables from Entities

I guess you could turn off validation too, but creating the table seems to make more sense.

Eclipse 中的 JPA 项目出现问题 - 注释为 @Entity 的类中出现错误:表“xxx”无法解决

半城柳色半声笛 2024-12-12 11:33:39

CSS3 有一个 text-align-last 属性发现有用的。另一方面,使用不同的 text-justify 方法 可能是首选。

CSS3 has a text-align-last property that you might find useful. On the other hand, using a different text-justify method might be preferred.

将文本对齐,最后一行左对齐

半城柳色半声笛 2024-12-12 11:25:25

any? 方法的行为类似于 collect,只不过它在其块第一次返回 true 时返回 true。在这里,它的作用类似于数组 [true, false] 上的循环:

  1. 该块首先在 password_is_ha1 设置为 true 的情况下运行。如果该块返回 trueany? 立即返回 true,并且由于这是 validate_digest_response 的最后一条语句,该方法作为一个整体返回 true

  2. 否则,该块将再次运行,并将 password_is_ha1 设置为 false。如果该块返回 trueany? 立即返回 true,并且由于这是 validate_digest_response 的最后一条语句,该方法作为一个整体返回 true

  3. 如果这两个运行都没有返回 true,则 any? 返回 false。由于这是 validate_digest_response 的最后一个语句,因此该方法作为一个整体返回 false

因此,该行的作用是首先假设它是散列密码并检查它是否有效,然后假设它是明文密码并检查它是否有效。另一种更详细的写法是:

   expected = expected_response(method, uri, credentials, password, true)
   return true if expected == credentials[:response]

   expected = expected_response(method, uri, credentials, password, false)
   return true if expected == credentials[:response]

   return false

The any? method acts like collect, except it returns true the first time its block returns true. Here, it acts like a loop over the array [true, false]:

  1. The block is first run with password_is_ha1 set to true. If the block returns true, any? immediately returns true, and since this is the last statement of validate_digest_response, the method as a whole returns true.

  2. Otherwise, the block is run again with password_is_ha1 set to false. If the block returns true, any? immediately returns true, and since this is the last statement of validate_digest_response, the method as a whole returns true.

  3. If neither of those runs returned true, any? returns false. Since this is the last statement of validate_digest_response, the method as a whole returns false.

Thus, the effect of that line is to first assume it's a hashed password and check if it's valid, then assume it's a plaintext password and check if it's valid. Another, more verbose, way to write it would have been:

   expected = expected_response(method, uri, credentials, password, true)
   return true if expected == credentials[:response]

   expected = expected_response(method, uri, credentials, password, false)
   return true if expected == credentials[:response]

   return false

将纯文本密码与authenticate_or_request_with_http_digest一起使用

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

您可以使用 Objective-C 运行时函数:

Method class_getClassMethod(Class aClass, SEL aSelector)
void method_getReturnType(Method method, char *dst, size_t dst_len)

Objective-C 运行时参考

首先,使用 class_getClassMethod 获取方法对象,

Method m = class_getClassMethod( [ SomeClass class ], @selector( someMethod ) );

然后使用method_getReturnType

char ret[ 256 ];
method_getReturnType( m, ret, 256 );
NSLog( @"Return type: %s", ret );

You can use the Objective-C runtime functions:

Method class_getClassMethod(Class aClass, SEL aSelector)
void method_getReturnType(Method method, char *dst, size_t dst_len)

Objective-C Runtime Reference

First of all, get the method object, using class_getClassMethod

Method m = class_getClassMethod( [ SomeClass class ], @selector( someMethod ) );

Then, asks for the return type using method_getReturnType:

char ret[ 256 ];
method_getReturnType( m, ret, 256 );
NSLog( @"Return type: %s", ret );

在 Objective C 中,如何通过反射找出方法的返回类型?

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

问题解决了。 Gitosis 无法处理 PuTTYgen 生成的 SSH1 密钥。使用 Git 通过控制台生成的 OpenSSH 密钥。查看 GitHub 的任何教程,了解有关如何操作的更多信息。

The problem was solved. Gitosis can't handle SSH1 keys generated by PuTTYgen. Use OpenSSH keys generated by Git via the console. Check out any tutorial for GitHub for more information on how to do it.

Windows 上的 Gitosis 和 TortoiseGit

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

将左侧容器设置为 100%,并将右边距设置为 100px。我原来的答案也说填充,但那是错误的。边距为浮动的右侧 div 创造了空间。百分比宽度允许左侧 div 动态调整大小。

Set the left container to 100% and give it a right margin of 100px. My original answer said padding too, but thats wrong. The margin creates room for the floating right div. The percent widh allows the left div to dynamically resize.

动态大小的并排浮动

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

根据您的文件和哈希表,您可以考虑各种优化:

  1. 您可以从哈希表键集合构建正则表达式,如下所示:

    $regexes = $r.keys | foreach {[System.Text.RegularExpressions.Regex]::Escape($_)}
    $regex = [regex]($r.Keys -join '|')    
    

    在执行此操作时,您不会迭代每个键,但现在您需要知道匹配哪个键才能获得替换。另一方面,进行字符串替换而不是正则表达式替换(或者更复杂的字符串拆分和连接过程)可能会更快。

  2. 在 Powershell 中,您可以调用 .NET Regex::Replace 函数:

    <块引用>

    字符串替换(字符串输入,System.Text.RegularExpressions.MatchEvaluator评估器)

    调用此方法,您可以使用脚本块定义一个 MatchEvaluator,如下所示:

    $callback = { $r[$args[0].Value] }
    

    在脚本块中,$args[0] 是一个 System.Text.RegularExpressions.Match,因此您可以使用其 Value 属性索引到 $r 哈希表。

  3. Get-Content 返回一个字符串数组,这对于 -replace 运算符来说很好,但也意味着运行额外的循环。 [System.IO.File]::ReadAllText 将返回单个字符串,因此正则表达式只需要解析一次。

    $file = [System.IO.File]::ReadAllText("C:\scripts\test.txt")
    
  4. 如果您使用Get-Content,要使用$regex.Replace(而不是-replace),您将需要一个循环:< /p>

    $file = $file | % { $regex.Replace($_, $callback) }
    

    因为我不是,所以我可以使用单个替换调用:

    $file = $regex.Replace($file, $callback)
    

因此完整的脚本:

$r = @{
    "dog" = "canine";
    "cat" = "feline";
    "eric" = "eric cartman"
}


$regexes = $r.keys | foreach {[System.Text.RegularExpressions.Regex]::Escape($_)}
$regex = [regex]($regexes -join '|')

$callback = { $r[$args[0].Value] }

$file = [System.IO.File]::ReadAllText("C:\scripts\test.txt")
$file = $regex.Replace($file, $callback)
Set-Content -Path C:\scripts\test.txt.out -Value $file

Depending on your file and hashtable, there are various optimizations you could consider:

  1. You may be able to build a regex from the hashtable key collection like so:

    $regexes = $r.keys | foreach {[System.Text.RegularExpressions.Regex]::Escape($_)}
    $regex = [regex]($r.Keys -join '|')    
    

    In doing this you wouldn't to iterate every key, but now you need to know which key you matched in order to get the replacement. On the other hand, it may be faster to do string replacement instead of regex replacement (or something more complex like a string split and join process).

  2. In Powershell you can call the .NET Regex::Replace function:

    string Replace(string input, System.Text.RegularExpressions.MatchEvaluator evaluator)

    Calling this method you can define a MatchEvaluator with a scriptblock like so:

    $callback = { $r[$args[0].Value] }
    

    In the scriptblock, $args[0] is a System.Text.RegularExpressions.Match, so you can use its Value property to index into the $r hashtable.

  3. Get-Content returns an array of strings which is fine for the -replace operator, but also implies an extra loop running. [System.IO.File]::ReadAllText will instead return a single string, so the regex only needs to be parsed once.

    $file = [System.IO.File]::ReadAllText("C:\scripts\test.txt")
    
  4. If you used Get-Content, to use $regex.Replace (instead of -replace) you would need a loop:

    $file = $file | % { $regex.Replace($_, $callback) }
    

    Since I am not I can use a single replace call:

    $file = $regex.Replace($file, $callback)
    

Thus the full script:

$r = @{
    "dog" = "canine";
    "cat" = "feline";
    "eric" = "eric cartman"
}


$regexes = $r.keys | foreach {[System.Text.RegularExpressions.Regex]::Escape($_)}
$regex = [regex]($regexes -join '|')

$callback = { $r[$args[0].Value] }

$file = [System.IO.File]::ReadAllText("C:\scripts\test.txt")
$file = $regex.Replace($file, $callback)
Set-Content -Path C:\scripts\test.txt.out -Value $file

Powershell:使用哈希表替换字符串

更多

推荐作者

lanyue

文章 0 评论 0

海螺姑娘

文章 0 评论 0

Demos

文章 0 评论 0

亢龙有悔

文章 0 评论 0

海未深

文章 0 评论 0

浅忆流年

文章 0 评论 0

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