language-agnostic

Merge several regexes to a single one

≯℡__Kan透↙ 提交于 2019-12-30 08:32:09
问题 I have several regexes (actually several thousands), and I must check if one string matches any of these regexes. It is not very efficient, so I would like to merge all these regexes as a single regex. For example, if a have these regexes: 'foo *bar' 'foo *zip' 'zap *bar' I would like to obtain something like 'foo *(bar|zip)|zap *bar'. Is there some algorithm, library or tool to do this? 回答1: You can just concatenate the regexes using or ( | ) (and anchors for the beginning/end of string).

Merge several regexes to a single one

守給你的承諾、 提交于 2019-12-30 08:31:49
问题 I have several regexes (actually several thousands), and I must check if one string matches any of these regexes. It is not very efficient, so I would like to merge all these regexes as a single regex. For example, if a have these regexes: 'foo *bar' 'foo *zip' 'zap *bar' I would like to obtain something like 'foo *(bar|zip)|zap *bar'. Is there some algorithm, library or tool to do this? 回答1: You can just concatenate the regexes using or ( | ) (and anchors for the beginning/end of string).

Why must UI elements always be created/updated from the UI thread?

扶醉桌前 提交于 2019-12-30 08:29:15
问题 Why must UI elements always be created/updated from the UI thread? In (almost?) all programming languages UI elements may be safely accessed/modified only from the UI thread. I understand that it's a standard concurrent access and synchronization problem, but is it really necessary? Is this behaviour imposed by the programming languages or by the operating system? Are there any programming languages where this situation is different? 回答1: It's imposed by the graphics framework - which is

Function name for creating something if it's not there yet

前提是你 提交于 2019-12-30 06:43:21
问题 From time to time I write a function that just creates something if it's not there yet and otherwise does nothing. Names like CreateFooIfNecessary() or EnsureThereIsAFoo() do work but they feel a bit clumsy. One could also say GetFoo() but that name doesn't really imply that foo may be created first and it only works if the function returns a handle/pointer/reference to foo . Can those of you more familiar with the English language come up with a better way to name these functions? 回答1: How

Is regex case insensitivity slower?

我的梦境 提交于 2019-12-30 05:48:17
问题 Source RegexOptions.IgnoreCase is more expensive than I would have thought (eg, should be barely measurable) Assuming that this applies to PHP, Python, Perl, Ruby etc as well as C# (which is what I assume Jeff was using), how much of a slowdown is it and will I incur a similar penalty with /[a-zA-z]/ as I will with /[a-z]/i ? 回答1: Yes, [A-Za-z] will be much faster than setting the RegexOptions.IgnoreCase , largely because of Unicode strings. But it's also much more limiting -- [A-Za-z] does

Single thread to multi-threaded application

怎甘沉沦 提交于 2019-12-30 05:29:29
问题 When we should use threads in our application. In other words, when should I convert a single threaded application to multi-threaded application. Being a developer, I think the task which is preventing to your application to run smoothly. That task can be handled by a thread. Like we are the getting GPS data Continuously. I think, there are other more reasons to create thread in your application. Please share your opinion. Thanks. 回答1: Reasons I can think of off the top of my head ( and I'm

calculating parameters for defining subsections of quadratic bezier curves

最后都变了- 提交于 2019-12-30 05:12:06
问题 I have a quadratic bezier curve described as (startX, startY) to (anchorX, anchorY) and using a control point (controlX, controlY). I have two questions: (1) I want to determine y points on that curve based on an x point. (2) Then, given a line-segment on my bezier (defined by two intermediary points on my bezier curve (startX', startY', anchorX', anchorY')), I want to know the control point for that line-segment so that it overlaps the original bezier exactly. Why? I want this information

What is the difference between object and instance?

一个人想着一个人 提交于 2019-12-30 05:04:41
问题 I'd like to know the difference between object and instance of class. I feel both are same, but why do we call with two names. Can anybody explain with real life example? 回答1: They are the same thing in most object-oriented languages. "Instance of a class" is just how the term "object" is defined. 回答2: Just for the sake of completeness: In prototype-based programming languages, no distinctions between classes and instances/objects are drawn . Let's step back if you're asking this question

algorithm for getting time zone from geo coordinates

旧巷老猫 提交于 2019-12-30 04:23:05
问题 I want to write app where user can point any place on map (not only cities) and get timezone in that place. What data structure (app will not have Internet connectivity) and algorithm should I use? Where I can obtain needed data (I wont more accuracy then divining map into 24 rectangles)? I will write my app in Java ME. 回答1: Given that time zones are based on political entities rather than simply a physical lat/lon computation, I would create a data structure that mapped polygons over lat/lon

Is hard-coding literals ever acceptable?

霸气de小男生 提交于 2019-12-30 03:59:09
问题 The code base I'm currently working on is littered with hard-coded values. I view all hard coded values as a code smell and I try to eliminate them where possible...however there are some cases that I am unsure about. Here are two examples that I can think of that make me wonder what the best practice is: 1. MyTextBox.Text = someCondition ? "Yes" : "No" 2. double myPercentage = myValue / 100; In the first case, is the best thing to do to create a class that allows me to do MyHelper.Yes and