小编Jam*_*uth的帖子

在CSS中嵌套@media规则

各种浏览器的支持似乎有所不同.

检查链接

Firefox:黑色,带白色文字.

Opera,Chrome,IE9:蓝色与黑色文本.

哪个是正确的,我将如何使其保持一致?

代码

@media screen and (min-width: 480px) {

    body{
        background-color:#6aa6cc;
        color:#000;    
    }

    @media screen and (min-width: 768px) {

        body{
            background-color:#000;
            color:#fff;    
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

有趣的是,似乎在条件内嵌套媒体查询@import似乎有效.

例如:

的index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>Media test</title>
    <link rel="stylesheet" type="text/css" href="importer.css" />
</head>
<body>
    <h1>Why is this not consistent.</h1>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

importer.css

@import url(media.css) screen and (min-width: 480px);
Run Code Online (Sandbox Code Playgroud)

media.css

body {
    background-color: #6aa6cc;
    color: #000;
}

@media screen and (min-width:768px) {
    body …
Run Code Online (Sandbox Code Playgroud)

css css3 media-queries

61
推荐指数
1
解决办法
4万
查看次数

将resize算法拆分为两遍

我编写了以下调整大小算法,可以正确地向上或向下缩放图像.虽然由于每个循环上的权重数组的内部迭代,但它太慢了.

我相当肯定我应该能够将算法分成两个通道,就像你使用两次通过高斯模糊一样,这将极大地降低操作复杂性并加快性能.不幸的是我无法让它发挥作用.有人能帮忙吗?

Parallel.For(
    startY,
    endY,
    y =>
    {
        if (y >= targetY && y < targetBottom)
        {
            Weight[] verticalValues = this.verticalWeights[y].Values;

            for (int x = startX; x < endX; x++)
            {
                Weight[] horizontalValues = this.horizontalWeights[x].Values;

                // Destination color components
                Color destination = new Color();

                // This is where there is too much operation complexity.
                foreach (Weight yw in verticalValues)
                {
                    int originY = yw.Index;

                    foreach (Weight xw in horizontalValues)
                    {
                        int originX = xw.Index;
                        Color sourceColor = Color.Expand(source[originX, originY]);
                        float …
Run Code Online (Sandbox Code Playgroud)

c# algorithm image-processing imageprocessor

26
推荐指数
1
解决办法
680
查看次数

基于密钥的异步锁定

我试图弄清楚,已经提出了与我的ImageProcessor库的问题在这里添加项目到缓存中,当在那里我得到间歇性文件访问错误.

System.IO.IOException:进程无法访问文件'D:\ home\site\wwwroot\app_data\cache\0\6\5\f\2\7\065f27fc2c8e843443d210a1e84d1ea28bbab6c4.webp',因为它正被另一个进程使用.

我编写了一个类,用于基于散列网址生成的密钥执行异步锁定,但似乎我在实现中遗漏了一些东西.

我的锁类

public sealed class AsyncDuplicateLock
{
    /// <summary>
    /// The collection of semaphore slims.
    /// </summary>
    private static readonly ConcurrentDictionary<object, SemaphoreSlim> SemaphoreSlims
                            = new ConcurrentDictionary<object, SemaphoreSlim>();

    /// <summary>
    /// Locks against the given key.
    /// </summary>
    /// <param name="key">
    /// The key that identifies the current object.
    /// </param>
    /// <returns>
    /// The disposable <see cref="Task"/>.
    /// </returns>
    public IDisposable Lock(object key)
    {
        DisposableScope releaser = new DisposableScope(
        key,
        s =>
        {
            SemaphoreSlim locker; …
Run Code Online (Sandbox Code Playgroud)

c# multithreading locking async-await imageprocessor

17
推荐指数
2
解决办法
4809
查看次数

将lambda表达式转换为用于缓存的唯一键

我已经看过类似这个问题的其他问题,但我找不到任何可行的答案.

我一直在使用以下代码生成唯一键,用于将我的linq查询的结果存储到缓存中.

    string key = ((LambdaExpression)expression).Body.ToString();

    foreach (ParameterExpression param in expression.Parameters)
    {
        string name = param.Name;
        string typeName = param.Type.Name;

        key = key.Replace(name + ".", typeName + ".");
    }

    return key;
Run Code Online (Sandbox Code Playgroud)

它似乎适用于包含整数或布尔值的简单查询,但是当我的查询包含嵌套的常量表达式时,例如

// Get all the crops on a farm where the slug matches the given slug.
(x => x.Crops.Any(y => slug == y.Slug) && x.Deleted == false)
Run Code Online (Sandbox Code Playgroud)

返回的密钥是:

(True AndAlso(Farm.Crops.Any(y =>(value(OzFarmGuide.Controllers.FarmController + <> c__DisplayClassd).slug == y.Slug))AndAlso(Farm.Deleted == False)))

正如您所看到的,我传递的任何裁剪名称都会给出相同的关键结果.有没有办法可以提取给定参数的值,以便我可以区分我的查询?

还转换y为说出正确的类型名称会很好.....

c# linq caching linq-expressions

10
推荐指数
1
解决办法
3617
查看次数

没有查询字符串MVC的RedirectToAction

我的mvc应用程序中有一些代码可以执行重定向.

return RedirectToAction("Details", new { slug = viewModel.Farm.Slug });
Run Code Online (Sandbox Code Playgroud)

这个重定向到网址

/Farm/Details?slug=the-farm-name
Run Code Online (Sandbox Code Playgroud)

我想要它做的是这个

/Farm/Details/the-farm-name
Run Code Online (Sandbox Code Playgroud)

有一个简单的方法吗?

asp.net-mvc

9
推荐指数
1
解决办法
4671
查看次数

使用javascript数组跳过take方法

有没有方法可以跳过特定数量的对象并从javascript中的数组中获取一定数量的对象?

基本上我正在寻找的模式就是这个.

假设我有一个包含8个对象的数组.

第一循环:

从数组返回索引0到3的对象.

第二循环:

从数组返回索引4到7的对象.

第三循环:

回到开头,所以再次返回0到3的对象.

广告无限.....

如果可能的话,我很乐意看到一个基于jquery的解决方案,但我也非常喜欢原始的javascript实现,因为我渴望学习.

干杯.

javascript jquery

9
推荐指数
3
解决办法
2万
查看次数

如何测试虚拟目录的用户权限?

在HttpModule中,在url重写之后,我正在使用以下方法测试对应用程序中的虚拟路径的用户权限:

// Since we are now rewriting the path we need to check again that the 
// current user has access to the rewritten path.
// Get the user for the current request
// If the user is anonymous or authentication doesn't work for this suffix 
// avoid a NullReferenceException in the UrlAuthorizationModule by creating 
// a generic identity.
string virtualCachedPath = cache.GetVirtualCachedPath();

IPrincipal user = context.User ?? new GenericPrincipal(
     new GenericIdentity(string.Empty, string.Empty), new string[0]);

// Do we have permission …
Run Code Online (Sandbox Code Playgroud)

c# security iis virtual-directory

9
推荐指数
1
解决办法
712
查看次数

jquery defer和使用getScript的promise

我一直在调查jQuery中的新(ish)延迟对象,我在这里偶然发现了这个网站的文章.

在本文中有一些代码用于缓存脚本,因此不会多次请求它们.

    var cachedScriptPromises = {};

    $.cachedGetScript = function( url, callback ) {
        if ( !cachedScriptPromises[ url ] ) {
            cachedScriptPromises[ url ] = $.Deferred(function( defer ) {
                $.getScript( url ).then( defer.resolve, defer.reject );
            }).promise();
        }
        return cachedScriptPromises[ url ].done( callback );
    };

// You would then call it like thus.
$.cachedGetScript( url ).then( successCallback, errorCallback );
Run Code Online (Sandbox Code Playgroud)

这对我来说是一种确保您的脚本只有在您$.getScript()成功的情况下才能执行的方法.

至于我的实验已经消失了,即使我提供了一个不正确的URL,也不会调用错误回调.

我错过了一些明显的或者代码示例错了吗?

注意:我在网站上问过这个问题,但评论系统不起作用.:-S

jquery jquery-deferred

8
推荐指数
1
解决办法
3364
查看次数

在Javascript中用正则表达式替换管道和逗号

我坐在这里手里拿着"好零件",但我仍然没有更聪明.

任何人都可以为我敲一个正则表达式,这将允许我替换"|"的任何实例 和","来自一个字符串.

另外,有人能指出我学习正则表达式的非常好的资源方向,特别是在javascript中(它们是一种特殊的味道吗?)在我的知识中它确实是一个弱点.

干杯.

javascript regex

8
推荐指数
2
解决办法
2万
查看次数

获取委托事件绑定的根元素 - jQuery

采用以下代码:

    // Bind the click event to the thumbnails.
    $("ul.hpList").on("click", "a.hpThumb", function (event) {

        event.preventDefault();

        var $this = $(this),

        // Surely there has to be a smarter way to do this.
            $hpList = $this.parents("ul.hpList");

        changeItem($this, $hpList);

    });
Run Code Online (Sandbox Code Playgroud)

如何更好地识别事件绑定的根祖先元素.我觉得搜索DOM很糟糕.

jquery

8
推荐指数
1
解决办法
3653
查看次数