小编Pur*_*ret的帖子

BASH - 使用正则表达式查找和过滤查找特定文件夹

我有一个文件夹,其中包含许多带有子文件夹 (/...) 的文件夹,其结构如下:

_30_photos/combined
_30_photos/singles
_47_foo.bar
_47_foo.bar/combined
_47_foo.bar/singles
_50_foobar
Run Code Online (Sandbox Code Playgroud)

使用命令将显示find . -type d -print | grep '_[0-9]*_'结构为** 的所有文件夹。但是我生成了一个仅捕获 */combined 文件夹的正则表达式: _[0-9]*_[a-z.]+/combined但是当我将它插入到 find 命令中时,不会打印任何内容。

下一步是为每个组合文件夹(在我的硬盘上的某处)创建一个文件夹,并将组合文件夹的内容复制到新文件夹中。新文件夹名称应与子文件夹的父名称相同,例如 _47_foo.bar。搜索后可以使用 xargs 命令来实现吗?

regex bash

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

IE 8及更低版本的渐变支持

我为朋友正在制作的页面找到了一个很棒的CSS 渐变代码生成器,但是下面有一些评论让我担心:

/* For Internet Explorer 5.5 - 7 */
        filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#cccccc, endColorstr=#ffffff);
        /* For Internet Explorer 8 */
        -ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#cccccc, endColorstr=#ffffff)";    
        background-color: #CCC;
Run Code Online (Sandbox Code Playgroud)

并作出回应:

我强烈建议不要这些!它们的行为不同,受到限制,性能受损,并且可能导致布局问题.简单地说,因为IE不支持渐变(以及许多其他CSS功能本身,没有过滤器),要么使用图像获得相同的效果(背景图像),要么让客户说服IE用户获得较少的体验(严重关心渐变) vs疯狂的'设计师'之外的单色?)因为他们的浏览器与我们开发人员想要的不匹配.它被称为优雅降级,IE不应该是任何例外.

所以我不知道的是:我是否应该建议他们不使用这些代码?是否让IE使用此代码无用/无望?

css internet-explorer gradient

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

使用字符串正则表达式或不使用字符串的正则表达式?

我已经开始.match(Regex)在我的java程序中使用该方法,但是现在我只是使用一个字符串(String regexString = new String("[^a-zA-Z0-9][^a-zA-Z0-9]*");这是我到目前为止所作的一个例子).但我知道我可以使用一个真正的正则表达式(Regex pattern = new Regex() & the Pattern class然后编译它(?)一些如何).

在Java中使用Regex作为类而不仅仅是字符串是否有优势?我已经习惯于编写脚本,而正则表达式只是松散意义上的"字符串",并且没有能力/需要一个单独的类,所以我很难看到这里有一个.

java regex string

6
推荐指数
1
解决办法
169
查看次数

结合Java策略模式中的策略

以下示例无耻地从java.dzone.com中删除,并根据我的需要进行了修改:

我们的界面:

public interface CompressionStrategy
{
  public void compressFiles(ArrayList<File> files);
}
Run Code Online (Sandbox Code Playgroud)

我们的第一次实施

public class GZipCompressionStrategy implements CompressionStrategy
{

   public File compressFiles(ArrayList<File> files)
   {
     //using GZIP approach
     return archive;
   }

}
Run Code Online (Sandbox Code Playgroud)

第二次实施:

public class TarCompressionStrategy implements CompressionStrategy
{

   public File compressFiles(ArrayList<File> files)
   {
     //using TAR approach
     return archive;
   }

}
Run Code Online (Sandbox Code Playgroud)

这是给出的用途:

public class CompressionContext
{
   private CompressionStrategy strategy;   

   //this can be set at runtime by the application preferences
   public void setCompressionStrategy(CompressionStrategy strategy) 
   {
       this.strategy = strategy;  
   }

  //use the …
Run Code Online (Sandbox Code Playgroud)

java design-patterns strategy-pattern

6
推荐指数
1
解决办法
3338
查看次数

AngularJS JSON漏洞防护如何工作?

angular网站建议为JSON添加前缀)]}'\n,以防止它们被称为JSONP:

JSON漏洞允许第三方网站在某些情况下将您的JSON资源URL转换为JSONP请求.为了解决这个问题,您的服务器可以使用以下字符串")]}',\n"为所有JSON请求添加前缀.Angular会在将前缀作为JSON处理之前自动删除前缀.

但引用的文章没有提到这些结束括号,并且感觉这很容易解决(因为我的JSONView chrome插件已被修补以去除它们.为什么这不适用于'攻击者'? ).

相反,本文建议将JSON包装为对象:

{"d": ["Philha", "my-confession-to-crimes", 7423.42]}
Run Code Online (Sandbox Code Playgroud)

以某种方式保护你.

为什么AngularJS喜欢这种(奇数)保护,它有效吗?我不确定如何测试这个.

javascript security json angularjs

6
推荐指数
1
解决办法
1842
查看次数

如何用PEG语法描述函数参数

我还在和Qt的qmake模糊语法作斗争.

现在我找不到一种方法来描述可以包含括号的函数参数(例如regex):

functionName(arg1, "arg2", ^(arg3)+$)
Run Code Online (Sandbox Code Playgroud)

我试图像这样描述函数调用:

FunctionCall = Identifier space* "(" space* FunctionArgumentList? space* ")" space* eol*

FunctionArgumentList = FunctionArgumentString ((space* "," space* FunctionArgumentString)* / (blank* FunctionArgumentString)*)
FunctionArgumentString = ReplaceFunctionCall / TestFunctionCall / EnquotedString / RegularFunctionArgumentString
RegularFunctionArgumentString = RegularFunctionArgumentStringChar+
RegularFunctionArgumentStringChar = !(")" / blank / "," / quote / doublequote) SourceCharacter
SourceCharacter <- [\u0000-\uFFFC]
Run Code Online (Sandbox Code Playgroud)

如何在这种语法中添加对嵌入式括号的支持而不使用引号/双引号?如何区分函数参数和函数关闭中的括号?

有效函数调用示例:

contains(CMAKE_INSTALL_LIBS_DIR, ^(/usr)?/lib(64)?.*)
Run Code Online (Sandbox Code Playgroud)

javascript grammar parsing peg pegjs

6
推荐指数
1
解决办法
279
查看次数

如何避免 TS 三斜杠指令中丑陋的导入

我有一个嵌套的订单结构。如果我现在使用三斜杠指令,我有一个很长的数据路径,具体取决于文件,如下所示:

/// <reference path="../../../../global.d.ts" />
Run Code Online (Sandbox Code Playgroud)

我现在问自己的问题是有办法阻止它这样做吗?

types typescript

6
推荐指数
1
解决办法
2023
查看次数

为 React 生成 useState 的 VSCode 用户片段?

我正在尝试创建一个 VS 代码用户片段 useState()

目前我有

  "use state": {
    "prefix": "us",
    "body": [
      "const [$1, set${1/(.*)/${1:/upcase}/}] = useState($2);",
      "$3"
    ],
    "description": "creates use state"
  },
Run Code Online (Sandbox Code Playgroud)

当我在 $1(位置 1)输入 'foo' 时,我得到:

const [foo, setFOO] as useState()
Run Code Online (Sandbox Code Playgroud)

但是我想得到:

const [foo, setFoo] as useState()
Run Code Online (Sandbox Code Playgroud)

如何更改我的代码段以这种方式工作?

reactjs visual-studio-code vscode-snippets react-hooks

6
推荐指数
1
解决办法
888
查看次数

使用AngularJS创建cookie

我尝试使用以下代码设置Cookie:

angular.module('myApp').controller('myController', ['$scope', '$http','$cookies', function ($scope, $http, $cookies) {

    $scope.setMyCookie = function () {
        $cookies.put('Mykey', 'MyValue');    
    };
    $scope.setMyCookie();
}]);
Run Code Online (Sandbox Code Playgroud)

我更新到角度cookie的版本1.3.14,我知道有一个重大变化,但我现在应该怎么写上面的代码?

运行上面的代码我收到此错误: Error: $cookies.put is not a function


更新:我必须在2个文件中执行此操作:

var app = angular.module('myApp', ['ngRoute']);

app.config(['$routeProvider', '$httpProvider', function ($routeProvider, $httpProvider) {

}]);

angular.module('myApp', ['ngCookies']).controller('cookiesExample', ['$cookies', function ($cookies) {
    // Retrieving a cookie
    var favoriteCookie = $cookies.myFavorite;
    // Setting a cookie
    $cookies.myFavorite = 'oatmeal';
}]);
Run Code Online (Sandbox Code Playgroud)

cookies setcookie angularjs angular-cookies

5
推荐指数
1
解决办法
3万
查看次数

使用 eslint no-restricted-syntax 防止 screen.findByX 不等待?

这篇中等文章向我展示了如何防止await前面的属性:

"no-restricted-syntax": [
  "error",
  {
    "message": "promise.then is unnecessary when using async/await",
    "selector": "AwaitExpression[argument.callee.property.name=\" then\"]"
  }
]
Run Code Online (Sandbox Code Playgroud)

但我想要相反,我想限制这些:

expect(screen.findByRole(...))....;
screen.findByRole(...);
Run Code Online (Sandbox Code Playgroud)

但允许这些:

expect(await screen.findByRole(...))....;
await screen.findByRole(...);
Run Code Online (Sandbox Code Playgroud)

我在测试文件的覆盖下尝试了这个:

expect(screen.findByRole(...))....;
screen.findByRole(...);
Run Code Online (Sandbox Code Playgroud)

但现在每一行都显示该错误。我也尝试将其放在*前面,希望它允许任何内容(*除非是后面跟着我禁止的语法表达式),但没有骰子。

我怎样才能做到这一点?

javascript abstract-syntax-tree eslint

5
推荐指数
1
解决办法
197
查看次数