|
Ideally you'd just set the regex to non-greedy, but if you can't do that, do (\[[^\]]*\]). That is, an opening square bracket, followed by zero or more not-a-closing-square-brackets, followed by a closing square bracket.
|
# ? Feb 12, 2011 05:09 |
|
|
# ? May 30, 2024 23:44 |
SnakePlissken posted:(\[.*\]) is greedy, gets all hits at once. And (\[.*\])? doesn't work. All the quick documentation I've found say to use a ? after, and it's not working. I think what you're looking for would be the expression .*?, with *? being the non-greedy zero-or-more. Alternatively, make a negative character class: (\[[^\]]*\]) "A [, followed by a number of characters that are not ], followed by a ]." (fe: drat beaten)
|
|
# ? Feb 12, 2011 05:18 |
|
Sneftel posted:Ideally you'd just set the regex to non-greedy, but if you can't do that, do (\[[^\]]*\]). That is, an opening square bracket, followed by zero or more not-a-closing-square-brackets, followed by a closing square bracket. By George, that did it! I came close to pulling hair on this one the other night, so thanks!
|
# ? Feb 12, 2011 05:21 |
|
nielsm posted:I think what you're looking for would be the expression .*?, with *? being the non-greedy zero-or-more. Thanks to you too! Your answer is instructive.
|
# ? Feb 12, 2011 05:28 |
|
I'm trying to brush up on C# efficiency/optimisation in certain situations, but struggling to find a definitive answer for one particular scenario. Let's say you have a method which takes a paramlist of any type: code:
code:
Option 1: code:
code:
Thanks, and sorry if this was a bit long. rolleyes fucked around with this message at 14:20 on Feb 13, 2011 |
# ? Feb 13, 2011 14:18 |
|
rolleyes posted:Thanks, and sorry if this was a bit long. The compiler will most likely have to do automatic boxing around the int in order to be able to call GetType() on it. ints are primitive in .NET, so it will be boxed to the Integer class.
|
# ? Feb 13, 2011 15:49 |
|
Milotic posted:The compiler will most likely have to do automatic boxing around the int in order to be able to call GetType() on it. ints are primitive in .NET, so it will be boxed to the Integer class. Unless I'm confusing myself with terminology, aren't ints in an object[] array boxed already? If the compiler needs to unbox the ints to do GetType() then that answer my question, as that's a cast (i.e. (int)o). If that's true then there is no ideal solution; option 1 uses one cast but leaves you with nullable ints, while option 2 preserves non-nullable ints but uses two casts. rolleyes fucked around with this message at 16:08 on Feb 13, 2011 |
# ? Feb 13, 2011 16:05 |
|
rolleyes posted:So my question is, how many casts are involved in option 2? Obviously there's the explicit one inside the if block, but is the if expression really doing casts behind the scenes to perform the comparison? I believe you'll get two casts in both cases, but what you could try is: code:
|
# ? Feb 13, 2011 18:38 |
|
ninjeff posted:I believe you'll get two casts in both cases, but what you could try is: Hmm, interesting. First I forgot System.Linq, but after sorting that out I get "foreach statement cannot operate on variables of type 'method group' because 'method group' does not contain a public definition for 'GetEnumerator'". Also, could you expand on why you think option 1 would produce two casts? The "as" operator is a single cast according to MSDN.
|
# ? Feb 13, 2011 19:10 |
|
It's a method, you need () after OfType<int> Also, why are you worrying so much about the number of casts that your application is performing? Is it a design or performance issue?
|
# ? Feb 13, 2011 20:12 |
|
rolleyes posted:Hmm, interesting. First I forgot System.Linq, but after sorting that out I get "foreach statement cannot operate on variables of type 'method group' because 'method group' does not contain a public definition for 'GetEnumerator'". quote:Also, could you expand on why you think option 1 would produce two casts? The "as" operator is a single cast according to MSDN.
|
# ? Feb 14, 2011 04:39 |
|
Doh, I should have spotted the missing parentheses myself! That does now compile. Orzo: I don't have an application as such, I'm just trying to expand my optimisation knowledge a bit and hit this question while doing so. I know casts are expensive so it makes sense to reduce them especially when they're in a loop, and I was wondering what the 'ideal' solution to this particular scenario is; assuming ninjeff's method is just one cast then that appears to be it. In short, just curiosity.
|
# ? Feb 14, 2011 06:33 |
|
I have a program that creates graphs which runs from the command line. The commandcode:
Is there a way to do this? I am using Win7 if that makes a difference.
|
# ? Feb 15, 2011 05:17 |
|
I hope I'm asking in the right place. This is the first website I've ever worked on: http://mizsweetgurl.aisites.com/redoabout.html Some links refuse to point to the correct location. For instance, the about link on that page doesn't point to http://mizsweetgurl.aisites.com/redoabout.html, instead it points to http://mizsweetgurl.aisites.com/redo%20about.html. I think the space then fucks up the link and males them not work. I'm using Adobe Dreamweaver. What am I doing wrong here? I went back through every page on Dreamweaver and made sure it said in the source that all the links pointed to the correct destination.
|
# ? Feb 15, 2011 05:47 |
Jose Cuervo posted:I have a program that creates graphs which runs from the command line. The command Windows NT batch files can do crazy stuff with horrible syntax. makegraphs.bat (or just enter it in a cmd window) code:
pre:graph1 arg1 arg2 graph2 arg3 arg4 graph3 arg5 arg6
|
|
# ? Feb 15, 2011 14:11 |
|
The batch files idea worked perfectly. I now just have to double click the batch file and I have 30 different graphs 10 seconds later. Thank you.
|
# ? Feb 15, 2011 19:57 |
|
I'm back with my casts again, because I got around to adding some benchmarks. The results are not quite what was expected. I've timed all 3 options using a stopwatch instance (we'll call ninjeff's method "Option 3") iterating over a 1,000 element array where the odd numbers are ints and the even numbers are strings. The only work being done is to pull out the ints from the array and add each one to a running total in the foreach loop. The output consistently gives results like this: Option 1 took 00:00:00.0002734 Option 2 took 00:00:00.0000430 Option 3 took 00:00:00.0048696 Option 1: I thought this would be quicker as it only uses one cast, but it's in 2nd place. Option 2: I wasn't sure about this one as I wasn't certain if it used one cast or two. From these results I'm guessing o.GetType().Equals(typeof(int)) doesn't involve a cast, and maybe the performance gain is from using normal non-nullable ints. Option 3: LINQ appears to ruin performance as this is two orders of magnitude slower than Option 2. The more you know! rolleyes fucked around with this message at 11:10 on Feb 17, 2011 |
# ? Feb 17, 2011 11:08 |
|
rolleyes posted:Option 1 took 00:00:00.0002734 These aren't reliable, you need more data and more data sets.
|
# ? Feb 17, 2011 12:06 |
|
baquerd posted:These aren't reliable, you need more data and more data sets. Fair point. I haven't changed the composition but I've increased the size of the array to 10,000, and I'm also now running each option 10,000 times and taking the average: Option 1 avg/10,000: 00:00:00.0004072 Option 2 avg/10,000: 00:00:00.0000723 Option 3 avg/10,000: 00:00:00.0002582 So Option 1 and Option 3 have traded places and the difference between is much reduced, but Option 2 still wins by a wide margin. edit: Just tried it with the composition changed so the first 5,000 items in the array are ints and the second 5,000 are strings. No appreciable difference in the results. rolleyes fucked around with this message at 13:23 on Feb 17, 2011 |
# ? Feb 17, 2011 13:18 |
|
rolleyes posted:Fair point. I haven't changed the composition but I've increased the size of the array to 10,000, and I'm also now running each option 10,000 times and taking the average: What about very large Strings? What about a million very large Strings? What if you run a program in the background too? What if you There are a great many considerations for profiling, and "ran a few tests, looks good" doesn't meet very robust standards. That said, your result is correct that number 2 is going to be vastly more efficient.
|
# ? Feb 17, 2011 13:29 |
|
If this was something which was actually going into a performance sensitive environment then I'd agree with you, but as mentioned above this is just my own little curiosity project. In this particular setup the length of the string shouldn't matter as the strings are skipped - the only processing (other than the "are you an int?" test) happens on the ints.
|
# ? Feb 17, 2011 14:22 |
|
I'm writing a ParseKit grammar (looks like Extended Backus-Naur Form), but I'm having problems with this production:code:
This naturally wreaks havoc on my state if one of the partials come before the full assembly. I've sorta fixed it by updating my entry production to match & discard brackets and wrapping the string I want to parse in the same brackets, but this seems like a giant hack. Any suggestions? Carthag Tuek fucked around with this message at 20:33 on Feb 17, 2011 |
# ? Feb 17, 2011 20:19 |
|
I'm not familiar with ParseKit but that production looks really ambiguous to me. Is this parser going to find longest match? Because if not then given the inputcode:
|
# ? Feb 17, 2011 20:25 |
|
Yeah that's the problem exactly. For reference, my grammar is basically the GEDCOM grammar reformatted to ParseKit:code:
Edit: Btw, Gedcom is a horrible horrible broken standard, but as it's de facto there's not much to do at the moment. Carthag Tuek fucked around with this message at 20:42 on Feb 17, 2011 |
# ? Feb 17, 2011 20:38 |
|
Yeesh, genealogy. What about something like this:code:
quote:Examples:
|
# ? Feb 17, 2011 21:15 |
|
That's basically the same thing as far as I can see. It's still ambiguous which part of DATE_PERIOD_FROM will trigger. Just to be sure, I tried it in the grammar, and I got the same error again. Thanks though. I'll try and gently caress around with it some more tomorrow, but as long as the bracket hack works, it's good enough I guess.
|
# ? Feb 17, 2011 21:48 |
|
Ah, yup. Durrrrrr. Um...maybe you can list the longest production first in your grammar?
|
# ? Feb 17, 2011 21:53 |
|
Doesn't appear to work, and frankly I'm tired of grammars & parsing. I've been working on the drat thing since last night. Only reason I'm using a grammar at all is because the dates are so complex. The full lines I tokenize with two regular expressions (plus a third to capture nonstanrd tags) and it's working just fine. Carthag Tuek fucked around with this message at 22:27 on Feb 17, 2011 |
# ? Feb 17, 2011 22:23 |
|
i need to learn Tcl/Tk for some scripting at work. anyone have any recommended books/websites?
|
# ? Feb 17, 2011 23:47 |
|
Geno posted:i need to learn Tcl/Tk for some scripting at work. anyone have any recommended books/websites? monster.com? Effective Tcl/Tk is a good guide for people who are already programmers. O'Reilly has a good Tcl/Tk reference, but it's not good for learning.
|
# ? Feb 18, 2011 00:08 |
|
This is probably a stupid question but I've searched online and not turned up anything conclusive. I do all my work in formal methods these days so whenever I run into a real programming problem I usually can't remember what to do. I'm making a little toy program that has a few AI controlled objects move around on a map (so they need to detect collisions and whatnot). The objects need to know the shape of the map class, but the map in turn would have to know the shape of the object class (so that it can provide some method to detect if there is an object blocking a map tile, for instance). Now that's pretty straight forward, but my problem is it is a circular dependency. From what I can gather, non-braindead GC can handle circular references just fine, and non-braindead compilers can handle bidirectional or circular dependencies. Assuming that last part is true (and correct me if I'm wrong) is it still morally wrong set up classes like this? The only alternate structure that occurs to me is to have some intermediary that has both the map and object information, but then if objects are given their own opportunity to act, they have to call the intermediary which brings the circular dependency back.
|
# ? Feb 18, 2011 12:18 |
|
Seashell Salesman posted:is it still morally wrong set up classes [with a circular dependency]? What's the problem you're trying to solve here? It sounds like you're looking for a problem where there isn't one. Do you have a scenario in mind where your circular dependency causes problems? With garbage collectors that can't detect cycles, you often find weak references. Normally references are strong, meaning they prevent the GC from collecting the referred-to object. A weak reference allows collection to happen. Basically the GC will collect objects that have zero strong references to them, regardless of how many weak references there are. So your map object might have a strong reference to the other objects, but the other objects just have a weak reference back to the map. For compilers, you'll see forward declarations that say "there is some class named map, but don't worry about it right now". This is common in C thanks to splitting the interface (header file) and implementation combined with a stupid preprocessor that would otherwise get in a loop, even though the compiler can figure it out just fine. Maybe you know all this already and I'm wasting your time, but I figured we could start there. And for what it's worth, morality has nothing to do with it!
|
# ? Feb 18, 2011 13:18 |
|
pokeyman posted:What's the problem you're trying to solve here? It sounds like you're looking for a problem where there isn't one. Do you have a scenario in mind where your circular dependency causes problems? It's relieving to hear I'm mostly right not to worry about (those particular) implementation issues My problem is more or less "is this a coherent structure and is this terrible style for maintenance/reasoning about execution"
|
# ? Feb 18, 2011 13:29 |
|
XPath/Nokogiri question. I just started using Ruby and Nokogiri to extract some information from HTML files. Here's a simplified version of the information I am trying to extract: <td id="j_id785:resultTable:1:j_id834">Name 1</td> <td id="j_id785:resultTable:2:j_id834">Name 2</td> <td id="j_id785:resultTable:3:j_id834">Name 3</td> ... I am using doc.search('//td[@id="j_id785:resultTable:1:j_id834"]') to extract Name 1. I'm a real newbie with regards to Nokogiri. Is there some sort of wildcard I can use so that it matches something like j_id785:resultTable:*:j_id834?
|
# ? Feb 18, 2011 21:17 |
|
You might be able to work something with starts-with() or contains() -- like the below (untested): //td[starts-with(@id,'j_id785:resultTable')]
|
# ? Feb 18, 2011 21:41 |
|
I have a question about asking questions: I'm looking for help with artificial neural networks. Does this count as programming and is this a good forum? Or is there a better place to post?
|
# ? Feb 19, 2011 07:34 |
|
Fire away and see what happens!
|
# ? Feb 19, 2011 11:19 |
|
Yeah it does and yeah this is a pretty good forum to ask.
|
# ? Feb 19, 2011 11:34 |
|
Here's hoping someone might be able to help my with a little vbscript issue I'm having, keep in mind I'm relatively new to vbscript but have done programming in the past. The vbscript is being used within SecureCRT 5.2.1 Here's the code section: code:
I've attempted to use an InputBox as well but am running into the same problem. Is it possible to either change what the code uses as the cancel (ie. not make it a null)? Or is it possible in a text input box to remove the cancel button altogether?
|
# ? Feb 21, 2011 01:57 |
|
|
# ? May 30, 2024 23:44 |
|
would you mind taking a look, please? this is the error I get. http://i51.tinypic.com/156uuis.png code:
|
# ? Feb 21, 2011 03:41 |