find

Lua - get indexOf string

巧了我就是萌 提交于 2019-12-21 12:37:55
问题 I am stuck with a problem in Lua to check whether the string value is not presented in another string. That's how I likely will do it in Javascript: 'my string'.indexOf('no-cache') === -1 // true but in Lua I'm trying to use string module which gives me unexpected response: string.find('my string', 'no-cache') -- nil, that's fine but.. string.find('no-cache', 'no-cache') -- nil.. that's weird string.find('no-cache', 'no') -- 1, 2 here it's right.. strange.. 回答1: As has already been mentioned,

Merits of std::find

北战南征 提交于 2019-12-21 12:37:09
问题 Is there any advantage to using C++11's std::find over a container's find method? In the case of std::vector (which does not have a find method) does std::find use some smart algorithm or the naive way of simply iterating over every element? In the case of std::map it seems you need to pass along an std::pair , which is the value_type of an std::map . This does not seem very useful as usually you'd want to find for either a key or a mapped element. What about other containers like std::list

Linux: Find a List of Files in a Dictionary recursively

耗尽温柔 提交于 2019-12-21 05:47:15
问题 I have a Textfile with one Filename per row: Interpret 1 - Song 1.mp3 Interpret 2 - Song 2.mp3 ... (About 200 Filenames) Now I want to search a Folder recursivly for this Filenames to get the full path for each Filename in Filenames.txt. How to do this? :) (Purpose: Copied files to my MP3-Player but some of them are broken and i want to recopy them all without spending hours of researching them out of my music folder) 回答1: The easiest way may be the following: cat orig_filenames.txt | while

Adding find condition to all Active Record Models in Rails

萝らか妹 提交于 2019-12-21 04:55:08
问题 Is there anyway to add a find condition to all Active record models? that is I would like this query ExampleModel.find :all, :conditions=> ["status = ?", "active"] to behave the same way as ExampleModel.find :all in every model Thanks!! 回答1: You could use default_scope: class ExampleModel < ActiveRecord::Base default_scope :conditions => ["status = ?", "active"] end If you want to use this in all your models, you can either subclass ActiveRecord::Base and derive from that in all your models

Swift Cannot invoke 'find' with an argument list of type '([Score], Score)' where Score is a struct

狂风中的少年 提交于 2019-12-21 04:50:42
问题 While find(["a", "b"], "c") works with no problems, I get an error when trying to find the index of a structure inside an array of structures: struct Score { //... } var scores: [Score] = //... var score: Score = //... find(self.scores, score) // Error: Cannot invoke 'find' with an argument list of type '([Score], Score)' I though it could be a problem with structures that can't be compared to each other by default. But changing Score s definition to class gives me the same error. 回答1: EDIT:

Can 'find' or any other tool search for files breadth-first?

守給你的承諾、 提交于 2019-12-21 03:10:58
问题 Sometimes I know a file is not so deep away, but a very dense sub-directory does not allow me to find the files I want easily. Can find (or any other tool) look for files using breadth-first search? 回答1: Yes, sort of. You can use the -depth option to make it process a directory's contents before the directory itself. You can also use the -maxdepth option to limit how many directories down it will drill. 回答2: Horrible hack, won't work with -0 or any actions other than -print , inefficient, etc

C# find exact-match in string

杀马特。学长 韩版系。学妹 提交于 2019-12-20 19:38:26
问题 How can I search for an exact match in a string? For example, If I had a string with this text: label label: labels And I search for label, I only want to get the first match, not the other two. I tried the Contains and IndexOf method, but they also give me the 2nd and 3rd matches. 回答1: You can use a regular expression like this: bool contains = Regex.IsMatch("Hello1 Hello2", @"(^|\s)Hello(\s|$)"); // yields false bool contains = Regex.IsMatch("Hello1 Hello", @"(^|\s)Hello(\s|$)"); // yields

md5 all files in a directory tree

时光毁灭记忆、已成空白 提交于 2019-12-20 17:49:12
问题 I have a a directory with a structure like so: . ├── Test.txt ├── Test1 │ ├── Test1.txt │ ├── Test1_copy.txt │ └── Test1a │ ├── Test1a.txt │ └── Test1a_copy.txt └── Test2 ├── Test2.txt ├── Test2_copy.txt └── Test2a ├── Test2a.txt └── Test2a_copy.txt I would like to create a bash script that makes a md5 checksum of every file in this directory. I want to be able to type the script name in the CLI and then the path to the directory I want to hash and have it work. I'm sure there are many ways

find files not in a list

不羁岁月 提交于 2019-12-20 11:35:39
问题 I have a list of files in file.lst . Now I want to find all files in a directory dir which are older than 7 days, except those in the file.lst file. How can I either modify the find command or remove all entries in file.lst from the result? Example: file.lst : a b c Execute: find -mtime +7 -print > found.lst found.lst : a d e so what I expect is: d e 回答1: Pipe your find command through grep -Fxvf : find -mtime +7 -print | grep -Fxvf file.lst What the flags mean: -F, --fixed-strings Interpret

How to sort the results of find (including nested directories) alphabetically in bash

喜夏-厌秋 提交于 2019-12-20 10:58:28
问题 I have a list of directories based on the results of running the "find" command in bash. As an example, the result of find are the files: test/a/file test/b/file test/file test/z/file I want to sort the output so it appears as: test/file test/a/file test/b/file test/z/file Is there any way to sort the results within the find command, or by piping the results into sort? 回答1: If you have the GNU version of find, try this: find test -type f -printf '%h\0%d\0%p\n' | sort -t '\0' -n | awk -F '\0'