pattern-matching

Performance impact of empty LIKE in a prepared statement

落爺英雄遲暮 提交于 2019-12-14 02:37:58
问题 I have set a GiST pg_trgm index on the name column of the files table. The simplified query of the prepared statement looks like this: SELECT * FROM files WHERE name LIKE $1; The $1 param will be composed of % + user query + % . Since the input might also be an empty string this might result in %% . Does an "empty" LIKE ( %% ) result in performance degradation? Should I build a new query in that case, or does it not matter? 回答1: Postgres 9.2 or later is generally smart enough to realize that

Type to capture either integer, float or a string value and then do pattern matching in Scala

不打扰是莪最后的温柔 提交于 2019-12-14 02:11:16
问题 In Ocaml it is possible to define something like this: type univ = I of int | F of float | S of string ;; In order to create objects with like this: let pol_list = [I 3; F 4.3; S "potato"; I 4];; And then do pattern matching to extract a certain property (Either value or length depending on the case) like this: let get_value val = match val with | I v -> v | F v -> (int_of_float v) | S s -> (String.length s) How would this be done in Scala? If not possible, is there another similar

What is the difference between % and * in a makefile

[亡魂溺海] 提交于 2019-12-14 00:48:00
问题 The GNU make manual does not excel at explaining this part, I could not find the explanation or I could not infer the information elsewhere. I realize % is a kind of wildcard, but what is the difference between % and * in the context of targets , dependencies and commands ? Where can I use it and does it have the same meaning everywhere? target: dependencies ... commands 回答1: The wildcard character * is used to simply generate a list of matching files in the current directory. The pattern

How to list lex/yacc or flex/bison patterns?

久未见 提交于 2019-12-13 23:56:41
问题 I would like to extract all patterns from a flex/bison file to look at them altogether. I am not interested in the rules applying to the patterns for now. Surely someone has written a flex/bison file for this already? :) 回答1: If you give it the -v command-line option, bison will output a nicely formatted version of the grammar (and all the states) to a file with extension .output . You can specify the precise file name to write to with --report-file=PATH and a list of things to report on with

awk to compare two file by identifier & output in a specific format

╄→гoц情女王★ 提交于 2019-12-13 23:44:52
问题 I have 2 large files i need to compare all pipe delimited file 1 a||d||f||a 1||2||3||4 file 2 a||d||f||a 1||1||3||4 1||2||r||f Now I want to compare the files & print accordingly such as if any update found in file 2 will be printed as updated_value#oldvalue & any new line added to file 2 will also be updated accordingly. So the desired output is: (only the updated & new data) 1||1#2||3||4 1||2||r||f what I have tried so far is to get the separated changed values: awk -F '[||]+' 'NR==FNR{for

How do you sum the individual elements of a pair in a list?

邮差的信 提交于 2019-12-13 20:28:02
问题 Im trying to take the first and second element of the pair from a list so they can be summed. Here is my code, I am not sure why it is giving an error func :: [(Double,Double)] -> (Double,Double) func [(x, y)] = map fst (x,y) 回答1: First, let's take your current, non-working definition: func :: [(Double,Double)] -> (Double,Double) func [(x, y)] = map fst (x,y) This has several things wrong with it: Your pattern match [(x, y)] only matches a list with exactly one element. Any list with 2 or

Create new column from an existing column with pattern matching in R

时光怂恿深爱的人放手 提交于 2019-12-13 19:49:32
问题 I'm trying to add a new column based on another using pattern matching. I've read this post, but not getting the desired output. I want to create a new column (SubOrder) based on the GreatGroup column. I have tried the following: SubOrder <- rep(NA_character_, length(myData)) SubOrder[grepl("udults", myData, ignore.case = TRUE)] <- "Udults" SubOrder[grepl("aquults", myData, ignore.case = TRUE)] <- "Aquults" SubOrder[grepl("aqualfs", myData, ignore.case = TRUE)] <- "aqualfs" SubOrder[grepl(

Regex C# - how to match methods and properties names of a class

孤街浪徒 提交于 2019-12-13 18:17:52
问题 I want to match methods name (with parameters) and properties name. I dont want to include accessors in match. For example i got this kind of class: public class test { public static string NA = "n/a"; public static DateTime DateParser(string dateToBeParsed) { DateTime returnValue = new DateTime(); DateTime.TryParse(dateToBeParsed, GetCulture(), System.Globalization.DateTimeStyles.AssumeLocal , out returnValue); return returnValue; } } For class name I'm using this kind of regex: (?<=class\s)

Comparing two JPEG IMAGES and displaying differences

∥☆過路亽.° 提交于 2019-12-13 16:57:25
问题 Images are of the same object taken at different time intervals. Software solutions - to be implemented in hardware. High rate of performance most important in hardware implementation 回答1: I believe Perceptual Diff does what you want... http://pdiff.sourceforge.net/ 回答2: Despite the fact the question seems to be after hardware and some kind of technique rather than a tool, for the sake of posterity it's worth mentioning that you can do this with Beyond Compare plugins. Not free but worth the

Pattern matching in `Alternative`

China☆狼群 提交于 2019-12-13 16:49:03
问题 I have a function that pattern matches on its arguments to produce a computation in StateT () Maybe () . This computation can fail when run, in which case I want the current pattern match branch to fail, so to speak. I highly doubt it's possible to have something like compute :: Int -> StateT () Maybe Int compute = return f :: Maybe Int -> Maybe Int -> StateT () Maybe () f (Just n1) (Just n2) = do m <- compute (n1 + n2) guard (m == 42) f (Just n) _ = do m <- compute n guard (m == 42) f _