instruction
stringlengths
0
30k
For non-sorted the best choice, more than nine times out of ten, will be: ArrayList, HashMap, HashSet. Vector and Hashtable are synchronised and therefore might be a bit slower. It's rare that you would want synchronised implementations, and when you do their interfaces are not sufficiently rich for thier synchronisation to be useful. In the case of Map, ConcurrentMap adds extra operations to make the interface useful. ConcurrentHashMap is a good implementation of ConcurrentMap. LinkedList is almost never a good idea. Even if you are doing a lot of insertions and removal, if you are using an index to indicate position then that requires iterating through the list to find the correct node. ArrayList is almost always faster. For Map and Set, the hash variants will be faster than tree/sorted. Hash algortihms tend to have O(1) performance, whereas trees will be O(log n).
How can you databind a single object in .NET ?
|.net|data-binding|
I would like to use a component that exposes the datasource property, but instead of supplying the datasource with whole list of objects, I would like to use only simple object. Is there any way to do this ? The mentioned component is DevExpress.XtraDataLayout.DataLayoutControl - this is fairly irrelevant to the question though.
In ASP.NET2.0 you can use the generic collections to make this single object a list of only one object in it that you can databind to any server control using the objectdatasource, e.g. List<clsScannedDriverLicense> DriverLicenses = new List<clsScannedDriverLicense>(); //this creates a generic collection for you that you can return from //your BLL to the ObjectDataSource DriverLicenses.Add(TheOneObjectThatYouHaveofType_c lsDriverLicense); Then your ObjectDataSource would look like that: <asp:ObjectDataSource ID="odsDL" runat="server" SelectMethod="OrdersByCustomer" TypeName="YourBLL.UtiltiesClassName" DataObjectTypeName="clsScannedDriverLicense"> </asp:ObjectDataSource> [Source][1] [1]: http://www.velocityreviews.com/forums/t122605-can-you-still-databind-to-a-single-object-in-asp-net-20.html
I believe I understand the problem. The exception is being caught, the issue is confusion over the debugger's behavior and differences in the debugger settings among each person trying to repro it. In the 3rd case from your repro I believe you are getting the following message: "NoViableAltException was unhandled by user code" and a callstack that looks like this: <pre> [External Code] > TestAntlr-3.1.exe!TimeDefLexer.mTokens() Line 852 + 0xe bytes C# [External Code] TestAntlr-3.1.exe!TimeDefParser.prog() Line 141 + 0x14 bytes C# TestAntlr-3.1.exe!TestAntlr_3._1.Program.ParseTest(string Text = "foobar;") Line 49 + 0x9 bytes C# TestAntlr-3.1.exe!TestAntlr_3._1.Program.Main(string[] args = {string[0x00000000]}) Line 30 + 0xb bytes C# [External Code] </pre> If you right click in the callstack window and run turn on show external code you see this: <pre> Antlr3.Runtime.dll!Antlr.Runtime.DFA.NoViableAlt(int s = 0x00000000, Antlr.Runtime.IIntStream input = {Antlr.Runtime.ANTLRStringStream}) + 0x80 bytes Antlr3.Runtime.dll!Antlr.Runtime.DFA.Predict(Antlr.Runtime.IIntStream input = {Antlr.Runtime.ANTLRStringStream}) + 0x21e bytes > TestAntlr-3.1.exe!TimeDefLexer.mTokens() Line 852 + 0xe bytes C# Antlr3.Runtime.dll!Antlr.Runtime.Lexer.NextToken() + 0xc4 bytes Antlr3.Runtime.dll!Antlr.Runtime.CommonTokenStream.FillBuffer() + 0x147 bytes Antlr3.Runtime.dll!Antlr.Runtime.CommonTokenStream.LT(int k = 0x00000001) + 0x2d bytes TestAntlr-3.1.exe!TimeDefParser.prog() Line 141 + 0x14 bytes C# TestAntlr-3.1.exe!TestAntlr_3._1.Program.ParseTest(string Text = "foobar;") Line 49 + 0x9 bytes C# TestAntlr-3.1.exe!TestAntlr_3._1.Program.Main(string[] args = {string[0x00000000]}) Line 30 + 0xb bytes C# [Native to Managed Transition] [Managed to Native Transition] mscorlib.dll!System.AppDomain.ExecuteAssembly(string assemblyFile, System.Security.Policy.Evidence assemblySecurity, string[] args) + 0x39 bytes Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() + 0x2b bytes mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(object state) + 0x3b bytes mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x81 bytes mscorlib.dll!System.Threading.ThreadHelper.ThreadStart() + 0x40 bytes </pre> The debugger's message is telling you that an exception originating outside your code (from NoViableAlt) is going through code you own in TestAntlr-3.1.exe!TimeDefLexer.mTokens() without being handled. The wording is confusing, but it does not mean the exception is uncaught. The debugger is letting you know that code you own mTokens()" needs to be robust against this exception being thrown through it. Things to play with to see how this looks for those who didn't repro the problem: - Go to Tools/Options/Debugging and turn off "Enable Just My code (Managed only)". or option. - Go to Debugger/Exceptions and turn off "User-unhandled" for Common-Language Runtime Exceptions.
Why is .NET exception not caught by try/catch block?
|c#|.net|exception|
I'm working on a project using the [ANTLR][1] parser library for C#. I've built a grammar to parse some text and it works well. However, when the parser comes across an illegal or unexpected token, it throws one of many exceptions. The problem is that in some cases (not all) that my try/catch block won't catch it and instead stops execution as an unhandled exception. The issue for me is that I can't replicate this issue anywhere else but in my full code. The call stack shows that the exception definitely occurs within my try/catch(Exception) block. The only thing I can think of is that there are a few ANTLR assembly calls that occur between my code and the code throwing the exception and this library does not have debugging enabled, so I can't step through it. I wonder if non-debuggable assemblies inhibit exception bubbling? The call stack looks like this; external assembly calls are in Antlr.Runtime: Expl.Itinerary.dll!TimeDefLexer.mTokens() Line 1213 C# Antlr3.Runtime.dll!Antlr.Runtime.Lexer.NextToken() + 0xfc bytes Antlr3.Runtime.dll!Antlr.Runtime.CommonTokenStream.FillBuffer() + 0x22c bytes Antlr3.Runtime.dll!Antlr.Runtime.CommonTokenStream.LT(int k = 1) + 0x68 bytes Expl.Itinerary.dll!TimeDefParser.prog() Line 109 + 0x17 bytes C# Expl.Itinerary.dll!Expl.Itinerary.TDLParser.Parse(string Text = "", Expl.Itinerary.IItinerary Itinerary = {Expl.Itinerary.MemoryItinerary}) Line 17 + 0xa bytes C# The code snippet from the bottom-most call in Parse() looks like: try { // Execution stopped at parser.prog() TimeDefParser.prog_return prog_ret = parser.prog(); return prog_ret == null ? null : prog_ret.value; } catch (Exception ex) { throw new ParserException(ex.Message, ex); } To me, a catch (Exception) clause should've captured any exception whatsoever. Is there any reason why it wouldn't? **Update:** I traced through the external assembly with Reflector and found no evidence of threading whatsoever. The assembly seems to just be a runtime utility class for ANTLR's generated code. The exception thrown is from the TimeDefLexer.mTokens() method and its type is NoViableAltException, which derives from RecognitionException -> Exception. This exception is thrown when the lexer cannot understand the next token in the stream; in other words, invalid input. This exception is SUPPOSED to happen, however it should've been caught by my try/catch block. Also, the rethrowing of ParserException is really irrelevant to this situation. That is a layer of abstraction that takes any exception during parse and convert to my own ParserException. The exception handling problem I'm experiencing is never reaching that line of code. In fact, I commented out the "throw new ParserException" portion and still received the same result. One more thing, I modified the original try/catch block in question to instead catch NoViableAltException, eliminating any inheritance confusion. I still received the same result. Someone once suggested that sometimes VS is overactive on catching handled exceptions when in debug mode, but this issue also happens in release mode. Man, I'm still stumped! I hadn't mentioned it before, but I'm running VS 2008 and all my code is 3.5. The external assembly is 2.0. Also, some of my code subclasses a class in the 2.0 assembly. Could a version mismatch cause this issue? **Update 2:** I was able to eliminate the .NET version conflict by porting relevant portions of my .NET 3.5 code to a .NET 2.0 project and replicate the same scenario. I was able to replicate the same unhandled exception when running consistently in .NET 2.0. I learned that ANTLR has recently released 3.1. So, I upgraded from 3.0.1 and retried. It turns out the generated code is a little refactored, but the same unhandled exception occurs in my test cases. [1]: http://antlr.org
What kind of technologies are available for sending text messages?
|c#|mobile|messaging|
I'm looking into sending regular automated text-messages to a list of subscribed users. Having played with Windows Mobile devices, I could easily implement this using the compact .Net framework + a device hooked up to usb and send the messages through this. I would like to explore other solutions like having a server or something similar to do this. I just have no idea what is involved in such a system.
How can I modify a Work Item type to include additional information in TFS?
|teamfoundationserver|workitem|
TFS2008. I'd like to track task points on a Task work item, but there isn't anywhere (other than the description) to record this. I'd like to add a dropdown with 0, 1, 2, 3, 5, 8, etc, so these task points can be exported in reports.
|workitem|tfs|
|tfs|visual-studio-team-system|workitem|
[Chaco](http://code.enthought.com/chaco/) from [enthought](http://www.enthought.com/) is another option
agree with all the above, but also: when you decide that you want to optimize: 1. Fix algorithmic aspects before syntax (for example don't do lookups in large arrays) 2. Make sure that you prove that your change really did improve things, measure everything 3. Comment your optimization so the next guy seeing that function doesn't simplify it back to where you started from 4. Can you precompute results or move the computation to where it can be done more effectively (like a db) in effect, keep readability as long as you can - finding the obscure bug in optimized code is much harder and annoying than in the simple obvious code
You can usually get an account with an sms service provider and send messages using an API (SOAP, resful http, smpp ....) A google search for sms service provider yeilds many results with varying costs. Here is an informative article [How to Choose an SMS Service Provider](http://www.developershome.com/sms/howToChooseSMSGateway.asp)
You could always try a third-party gateway service for this. Somebody like [clickatell](http://www.clickatell.com) provide a number of services and APIs to make this work in a variety of countries. This isn't an ad! I only used their services for a technology pilot. There are quite a few of these around.
How Did You Decide Between WISA and LAMP?
|architecture|web-application|lamp|platform|wisa|
Did you ever have to choose between WISA or LAMP at the beginning of a web project? While pros and cons are littered around the net, it would be helpful to know about your real experience in coming up w/ criteria, evaluating, deciding, and reflecting upon your decision to go w/ either platform.
|architecture|web-applications|lamp|platform|wisa|
The switch statement is not the same thing as a big if-else statement. Each case must be unique and evaluated statically. The switch statement does a constant time branch regardless of how many cases you have. The if-else statement evaluates each condition until it finds one that is true.
> The switch statement is not the same > thing as a big if-else statement. > Each case must be unique and evaluated > statically. The switch statement does > a constant time branch regardless of > how many cases you have. The if-else > statement evaluates each condition > until it finds one that is true. Edit: The above is my original post which sparked some debate ... because its wrong. The C# switch statement is not always a constant time branch. In some cases the compiler will use a CIL switch statement which is indeed a constant time branch using a jump table. However, in sparse cases as pointed out by [Ivan Hamilton][1] the compiler may generate something else entirely. This is actually quite easy to verify by writing various C# switch statements, some sparse, some dense, and looking at the resulting CIL with the ildasm.exe tool. Very good discussion! [1]: http://stackoverflow.com/questions/44905/c-switch-statement-limitations-why#48259
Theoretically there are useful [Big-Oh][1] tradeoffs, but in practice these almost never matter. In real-world benchmarks, `ArrayList` out-performs `LinkedList` even with big lists and with operations like "lots of insertions near the front." Academics ignore the fact that real algorithms have constant factors that can overwhelm the asymptotic curve. For example, linked-lists require an additional object allocation for every node, meaning slower to create a node and vastly worse memory-access characteristics. My rule is: 1. Always start with ArrayList and HashSet and HashMap (i.e. not LinkedList or TreeMap). 2. Type declarations should always be an interface (i.e. List, Set, Map) so if a profiler or code review proves otherwise you can change the implementation without breaking anything. [1]: http://en.wikipedia.org/wiki/Big_O_notation
@[Brian Ensink][1] Brian, You're confusing the C# switch statement with the CIL switch instruction. The CIL switch is a jump table, that requires an index into a set of jump addresses. This is only useful if the C# switch's cases are adjacement: case 3: blah; break; case 4: blah; break; case 5: blah; break; But of little use if they aren't: case 10: blah; break; case 200: blah; break; case 3000: blah; break; (You'd need a table ~3000 entries in size, with only 3 slots used) With non-adjacement expressions, the compiler may start to perform linear if-else-if-else checks. With larger non-adjacement expression sets, the compiler may start with a binary tree search, and finally if-else-if-else the last few items. With expression sets containing clumps of adjacement items, the compiler may binary tree search, and finally a CIL switch. This is full of "mays" & "mights", and it is dependent on the compiler (may differ with Mono or Rotor). I replicated your results on my machine using adjacent cases: > total time to execute a 10 way switch, 10000 iterations (ms) : 25.1383 > approximate time per 10 way switch (ms) : 0.00251383 > > total time to execute a 50 way switch, 10000 iterations (ms) : 26.593 > approximate time per 50 way switch (ms) : 0.0026593 > > total time to execute a 5000 way switch, 10000 iterations (ms) : 23.7094 > approximate time per 5000 way switch (ms) : 0.00237094 > > total time to execute a 50000 way switch, 10000 iterations (ms) : 20.0933 > approximate time per 50000 way switch (ms) : 0.00200933 Then I also did using non-adjacent case expressions: > total time to execute a 10 way switch, 10000 iterations (ms) : 19.6189 > approximate time per 10 way switch (ms) : 0.00196189 > > total time to execute a 500 way switch, 10000 iterations (ms) : 19.1664 > approximate time per 500 way switch (ms) : 0.00191664 > > total time to execute a 5000 way switch, 10000 iterations (ms) : 19.5871 > approximate time per 5000 way switch (ms) : 0.00195871 > > A non-adjacent 50,000 case switch statement would not compile. > "An expression is too long or complex to compile near 'ConsoleApplication1.Program.Main(string[])' What's funny here, is that the binary tree search appears a little (probably not statistically) quicker than the CIL switch instruction. Brian, you've used the word "**constant**", which has a very definite meaning from a computational complexity theory perspective. While the simplistic adjacement integer example may produce CIL that is considered O(1) (constant), a sparse example is O(log n) (logarithmic), clustered examples lie somewhere in between,and small examples are O(n) (linear). This doesn't even address the String situation, in which a static Generic.Dictionary<string,int32> may be created, and will suffer definite overhead on first use. Performance here, will be dependant on the performance of Generic.Dictionary. If you check the [C# Language Specification][2] (not the CIL spec) you'll find "15.7.2 The switch statement", makes no mention of "constant time" or the underlying implementation even uses the CIL switch instruction (be very careful of assuming such things). At the end of the day, a C# switch against an integer expression on a modern system is a sub-microsecond operation, and not normally worth worrying about. Not only that, it's not relevant to the question asked - but I do love the words "conclusively" & "empirical" being bandied about. At least it's not both completely off track and completely wrong like the [second highest rated answer][3]. [1]: http://stackoverflow.com/questions/44905/c-switch-statement-limitations-why#48060 [2]: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-334.pdf [3]: http://stackoverflow.com/questions/44905/c-switch-statement-limitations-why#44918
@[Brian Ensink][1] Brian, You're confusing the C# switch statement with the CIL switch instruction. The CIL switch is a jump table, that requires an index into a set of jump addresses. This is only useful if the C# switch's cases are adjacent: case 3: blah; break; case 4: blah; break; case 5: blah; break; But of little use if they aren't: case 10: blah; break; case 200: blah; break; case 3000: blah; break; (You'd need a table ~3000 entries in size, with only 3 slots used) With non- adjacent expressions, the compiler may start to perform linear if-else-if-else checks. With larger non- adjacent expression sets, the compiler may start with a binary tree search, and finally if-else-if-else the last few items. With expression sets containing clumps of adjacent items, the compiler may binary tree search, and finally a CIL switch. This is full of "mays" & "mights", and it is dependent on the compiler (may differ with Mono or Rotor). I replicated your results on my machine using adjacent cases: > total time to execute a 10 way switch, 10000 iterations (ms) : 25.1383 > approximate time per 10 way switch (ms) : 0.00251383 > > total time to execute a 50 way switch, 10000 iterations (ms) : 26.593 > approximate time per 50 way switch (ms) : 0.0026593 > > total time to execute a 5000 way switch, 10000 iterations (ms) : 23.7094 > approximate time per 5000 way switch (ms) : 0.00237094 > > total time to execute a 50000 way switch, 10000 iterations (ms) : 20.0933 > approximate time per 50000 way switch (ms) : 0.00200933 Then I also did using non-adjacent case expressions: > total time to execute a 10 way switch, 10000 iterations (ms) : 19.6189 > approximate time per 10 way switch (ms) : 0.00196189 > > total time to execute a 500 way switch, 10000 iterations (ms) : 19.1664 > approximate time per 500 way switch (ms) : 0.00191664 > > total time to execute a 5000 way switch, 10000 iterations (ms) : 19.5871 > approximate time per 5000 way switch (ms) : 0.00195871 > > A non-adjacent 50,000 case switch statement would not compile. > "An expression is too long or complex to compile near 'ConsoleApplication1.Program.Main(string[])' What's funny here, is that the binary tree search appears a little (probably not statistically) quicker than the CIL switch instruction. Brian, you've used the word "**constant**", which has a very definite meaning from a computational complexity theory perspective. While the simplistic adjacent integer example may produce CIL that is considered O(1) (constant), a sparse example is O(log n) (logarithmic), clustered examples lie somewhere in between, and small examples are O(n) (linear). This doesn't even address the String situation, in which a static Generic.Dictionary<string,int32> may be created, and will suffer definite overhead on first use. Performance here, will be dependant on the performance of Generic.Dictionary. If you check the [C# Language Specification][2] (not the CIL spec) you'll find "15.7.2 The switch statement", makes no mention of "constant time" or the underlying implementation even uses the CIL switch instruction (be very careful of assuming such things). At the end of the day, a C# switch against an integer expression on a modern system is a sub-microsecond operation, and not normally worth worrying about. Not only that, it's not relevant to the question asked - but I do love the words "conclusively" & "empirical" being bandied about. At least it's not both completely off track and completely wrong like the [second highest rated answer][3]. Edit: Of course these times will depend on machines and conditions. I wouldn’t pay attention to these timing tests, the microsecond durations we’re talking about are dwarfed by any “real” code being run (and you must include some “real code” otherwise the compiler will optimise the branch away), or jitter in the system. My answers are based on using [IL DASM][4] to examine the CIL created by the C# compiler. Of course, this isn’t final, as the actual instructions the CPU runs are then created by the JIT. Personally, I have checked the final CPU instructions actually executed on my x386 machine, and can confirm a simple adjacent switch doing something like: jmp ds:300025F0[eax*4] Where a binary tree search is full of: cmp ebx, 79Eh jg 3000352B cmp ebx, 654h jg 300032BB … cmp ebx, 0F82h jz 30005EEE [1]: http://stackoverflow.com/questions/44905/c-switch-statement-limitations-why#48060 [2]: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-334.pdf [3]: http://stackoverflow.com/questions/44905/c-switch-statement-limitations-why#44918 [4]: http://msdn.microsoft.com/en-us/library/f7dy01k1(VS.80).aspx
Call Visitors web stat program from PHP
|statistics|cgi|analytics|visitors|php-safe-mode|
I've been looking into different web statistics programs for my site, and one promising one is [Visitors][1]. Unfortunately, it's a C program and I don't know how to call it from the web server. I've tried using PHP's [shell_exec][2], but my web host ([NFSN][3]) has PHP's [safe mode][4] on and it's giving me an error message. Is there a way to execute the program within safe mode? If not, can it work with CGI? If so, how? (I've never used CGI before) [1]: http://www.hping.org/visitors/ [2]: http://us.php.net/manual/en/function.shell-exec.php [3]: https://www.nearlyfreespeech.net/ [4]: http://us2.php.net/features.safe-mode
Visitors looks like a log analyzer and report generator. Its probably best setup as a chron job to create static HTML pages once a day or so. If you don't have shell access to your hosting account, or some sort of control panel that lets you setup up chron jobs, you'll be out of luck.
I'm working on a project using the [ANTLR][1] parser library for C#. I've built a grammar to parse some text and it works well. However, when the parser comes across an illegal or unexpected token, it throws one of many exceptions. The problem is that in some cases (not all) that my try/catch block won't catch it and instead stops execution as an unhandled exception. The issue for me is that I can't replicate this issue anywhere else but in my full code. The call stack shows that the exception definitely occurs within my try/catch(Exception) block. The only thing I can think of is that there are a few ANTLR assembly calls that occur between my code and the code throwing the exception and this library does not have debugging enabled, so I can't step through it. I wonder if non-debuggable assemblies inhibit exception bubbling? The call stack looks like this; external assembly calls are in Antlr.Runtime: Expl.Itinerary.dll!TimeDefLexer.mTokens() Line 1213 C# Antlr3.Runtime.dll!Antlr.Runtime.Lexer.NextToken() + 0xfc bytes Antlr3.Runtime.dll!Antlr.Runtime.CommonTokenStream.FillBuffer() + 0x22c bytes Antlr3.Runtime.dll!Antlr.Runtime.CommonTokenStream.LT(int k = 1) + 0x68 bytes Expl.Itinerary.dll!TimeDefParser.prog() Line 109 + 0x17 bytes C# Expl.Itinerary.dll!Expl.Itinerary.TDLParser.Parse(string Text = "", Expl.Itinerary.IItinerary Itinerary = {Expl.Itinerary.MemoryItinerary}) Line 17 + 0xa bytes C# The code snippet from the bottom-most call in Parse() looks like: try { // Execution stopped at parser.prog() TimeDefParser.prog_return prog_ret = parser.prog(); return prog_ret == null ? null : prog_ret.value; } catch (Exception ex) { throw new ParserException(ex.Message, ex); } To me, a catch (Exception) clause should've captured any exception whatsoever. Is there any reason why it wouldn't? **Update:** I traced through the external assembly with Reflector and found no evidence of threading whatsoever. The assembly seems to just be a runtime utility class for ANTLR's generated code. The exception thrown is from the TimeDefLexer.mTokens() method and its type is NoViableAltException, which derives from RecognitionException -> Exception. This exception is thrown when the lexer cannot understand the next token in the stream; in other words, invalid input. This exception is SUPPOSED to happen, however it should've been caught by my try/catch block. Also, the rethrowing of ParserException is really irrelevant to this situation. That is a layer of abstraction that takes any exception during parse and convert to my own ParserException. The exception handling problem I'm experiencing is never reaching that line of code. In fact, I commented out the "throw new ParserException" portion and still received the same result. One more thing, I modified the original try/catch block in question to instead catch NoViableAltException, eliminating any inheritance confusion. I still received the same result. Someone once suggested that sometimes VS is overactive on catching handled exceptions when in debug mode, but this issue also happens in release mode. Man, I'm still stumped! I hadn't mentioned it before, but I'm running VS 2008 and all my code is 3.5. The external assembly is 2.0. Also, some of my code subclasses a class in the 2.0 assembly. Could a version mismatch cause this issue? **Update 2:** I was able to eliminate the .NET version conflict by porting relevant portions of my .NET 3.5 code to a .NET 2.0 project and replicate the same scenario. I was able to replicate the same unhandled exception when running consistently in .NET 2.0. I learned that ANTLR has recently released 3.1. So, I upgraded from 3.0.1 and retried. It turns out the generated code is a little refactored, but the same unhandled exception occurs in my test cases. **Update 3:** I've replicated this scenario in a [simplified VS 2008 project][2]. Feel free to download and inspect the project for yourself. I've applied all the great suggestions, but have not been able to overcome this obstacle yet. If you can find a workaround, please do share your findings. Thanks again! [1]: http://antlr.org [2]: http://www.explodingcoder.com/cms/files/TestAntlr-3.1.zip
I'm working on a project using the [ANTLR][1] parser library for C#. I've built a grammar to parse some text and it works well. However, when the parser comes across an illegal or unexpected token, it throws one of many exceptions. The problem is that in some cases (not all) that my try/catch block won't catch it and instead stops execution as an unhandled exception. The issue for me is that I can't replicate this issue anywhere else but in my full code. The call stack shows that the exception definitely occurs within my try/catch(Exception) block. The only thing I can think of is that there are a few ANTLR assembly calls that occur between my code and the code throwing the exception and this library does not have debugging enabled, so I can't step through it. I wonder if non-debuggable assemblies inhibit exception bubbling? The call stack looks like this; external assembly calls are in Antlr.Runtime: <pre> Expl.Itinerary.dll!TimeDefLexer.mTokens() Line 1213 C# Antlr3.Runtime.dll!Antlr.Runtime.Lexer.NextToken() + 0xfc bytes Antlr3.Runtime.dll!Antlr.Runtime.CommonTokenStream.FillBuffer() + 0x22c bytes Antlr3.Runtime.dll!Antlr.Runtime.CommonTokenStream.LT(int k = 1) + 0x68 bytes Expl.Itinerary.dll!TimeDefParser.prog() Line 109 + 0x17 bytes C# Expl.Itinerary.dll!Expl.Itinerary.TDLParser.Parse(string Text = "", Expl.Itinerary.IItinerary Itinerary = {Expl.Itinerary.MemoryItinerary}) Line 17 + 0xa bytes C# </pre> The code snippet from the bottom-most call in Parse() looks like: try { // Execution stopped at parser.prog() TimeDefParser.prog_return prog_ret = parser.prog(); return prog_ret == null ? null : prog_ret.value; } catch (Exception ex) { throw new ParserException(ex.Message, ex); } To me, a catch (Exception) clause should've captured any exception whatsoever. Is there any reason why it wouldn't? **Update:** I traced through the external assembly with Reflector and found no evidence of threading whatsoever. The assembly seems to just be a runtime utility class for ANTLR's generated code. The exception thrown is from the TimeDefLexer.mTokens() method and its type is NoViableAltException, which derives from RecognitionException -> Exception. This exception is thrown when the lexer cannot understand the next token in the stream; in other words, invalid input. This exception is SUPPOSED to happen, however it should've been caught by my try/catch block. Also, the rethrowing of ParserException is really irrelevant to this situation. That is a layer of abstraction that takes any exception during parse and convert to my own ParserException. The exception handling problem I'm experiencing is never reaching that line of code. In fact, I commented out the "throw new ParserException" portion and still received the same result. One more thing, I modified the original try/catch block in question to instead catch NoViableAltException, eliminating any inheritance confusion. I still received the same result. Someone once suggested that sometimes VS is overactive on catching handled exceptions when in debug mode, but this issue also happens in release mode. Man, I'm still stumped! I hadn't mentioned it before, but I'm running VS 2008 and all my code is 3.5. The external assembly is 2.0. Also, some of my code subclasses a class in the 2.0 assembly. Could a version mismatch cause this issue? **Update 2:** I was able to eliminate the .NET version conflict by porting relevant portions of my .NET 3.5 code to a .NET 2.0 project and replicate the same scenario. I was able to replicate the same unhandled exception when running consistently in .NET 2.0. I learned that ANTLR has recently released 3.1. So, I upgraded from 3.0.1 and retried. It turns out the generated code is a little refactored, but the same unhandled exception occurs in my test cases. **Update 3:** I've replicated this scenario in a [simplified VS 2008 project][2]. Feel free to download and inspect the project for yourself. I've applied all the great suggestions, but have not been able to overcome this obstacle yet. If you can find a workaround, please do share your findings. Thanks again! [1]: http://antlr.org [2]: http://www.explodingcoder.com/cms/files/TestAntlr-3.1.zip
I'm working on a project using the [ANTLR][1] parser library for C#. I've built a grammar to parse some text and it works well. However, when the parser comes across an illegal or unexpected token, it throws one of many exceptions. The problem is that in some cases (not all) that my try/catch block won't catch it and instead stops execution as an unhandled exception. The issue for me is that I can't replicate this issue anywhere else but in my full code. The call stack shows that the exception definitely occurs within my try/catch(Exception) block. The only thing I can think of is that there are a few ANTLR assembly calls that occur between my code and the code throwing the exception and this library does not have debugging enabled, so I can't step through it. I wonder if non-debuggable assemblies inhibit exception bubbling? The call stack looks like this; external assembly calls are in Antlr.Runtime: Expl.Itinerary.dll!TimeDefLexer.mTokens() Line 1213 C# Antlr3.Runtime.dll!Antlr.Runtime.Lexer.NextToken() + 0xfc bytes Antlr3.Runtime.dll!Antlr.Runtime.CommonTokenStream.FillBuffer() + 0x22c bytes Antlr3.Runtime.dll!Antlr.Runtime.CommonTokenStream.LT(int k = 1) + 0x68 bytes Expl.Itinerary.dll!TimeDefParser.prog() Line 109 + 0x17 bytes C# Expl.Itinerary.dll!Expl.Itinerary.TDLParser.Parse(string Text = "", Expl.Itinerary.IItinerary Itinerary = {Expl.Itinerary.MemoryItinerary}) Line 17 + 0xa bytes C# The code snippet from the bottom-most call in Parse() looks like: try { // Execution stopped at parser.prog() TimeDefParser.prog_return prog_ret = parser.prog(); return prog_ret == null ? null : prog_ret.value; } catch (Exception ex) { throw new ParserException(ex.Message, ex); } To me, a catch (Exception) clause should've captured any exception whatsoever. Is there any reason why it wouldn't? [1]: http://antlr.org
I'm working on a project using the [ANTLR][1] parser library for C#. I've built a grammar to parse some text and it works well. However, when the parser comes across an illegal or unexpected token, it throws one of many exceptions. The problem is that in some cases (not all) that my try/catch block won't catch it and instead stops execution as an unhandled exception. The issue for me is that I can't replicate this issue anywhere else but in my full code. The call stack shows that the exception definitely occurs within my try/catch(Exception) block. The only thing I can think of is that there are a few ANTLR assembly calls that occur between my code and the code throwing the exception and this library does not have debugging enabled, so I can't step through it. I wonder if non-debuggable assemblies inhibit exception bubbling? The call stack looks like this; external assembly calls are in Antlr.Runtime: Expl.Itinerary.dll!TimeDefLexer.mTokens() Line 1213 C# Antlr3.Runtime.dll!Antlr.Runtime.Lexer.NextToken() + 0xfc bytes Antlr3.Runtime.dll!Antlr.Runtime.CommonTokenStream.FillBuffer() + 0x22c bytes Antlr3.Runtime.dll!Antlr.Runtime.CommonTokenStream.LT(int k = 1) + 0x68 bytes Expl.Itinerary.dll!TimeDefParser.prog() Line 109 + 0x17 bytes C# Expl.Itinerary.dll!Expl.Itinerary.TDLParser.Parse(string Text = "", Expl.Itinerary.IItinerary Itinerary = {Expl.Itinerary.MemoryItinerary}) Line 17 + 0xa bytes C# The code snippet from the bottom-most call in Parse() looks like: try { // Execution stopped at parser.prog() TimeDefParser.prog_return prog_ret = parser.prog(); return prog_ret == null ? null : prog_ret.value; } catch (Exception ex) { throw new ParserException(ex.Message, ex); } To me, a catch (Exception) clause should've captured any exception whatsoever. Is there any reason why it wouldn't? **Update:** I traced through the external assembly with Reflector and found no evidence of threading whatsoever. The assembly seems to just be a runtime utility class for ANTLR's generated code. The exception thrown is from the TimeDefLexer.mTokens() method and its type is NoViableAltException, which derives from RecognitionException -> Exception. This exception is thrown when the lexer cannot understand the next token in the stream; in other words, invalid input. This exception is SUPPOSED to happen, however it should've been caught by my try/catch block. Also, the rethrowing of ParserException is really irrelevant to this situation. That is a layer of abstraction that takes any exception during parse and convert to my own ParserException. The exception handling problem I'm experiencing is never reaching that line of code. In fact, I commented out the catch(Exception) { throw new ParserException } handler and still received the same result. One more thing, I modified the original try/catch block in question to instead catch NoViableAltException, eliminating any inheritance confusion. I still received the same result. Someone once suggested that sometimes VS is overactive on catching handled exceptions when in debug mode, but this issue also happens in release mode. Man, I'm still stumped! I hadn't mentioned it before, but I'm running VS 2008 and all my code is 3.5. The external assembly is 2.0. [1]: http://antlr.org
Take a look here [http://windowsclient.net/][1] and here [Windows Presentation Foundation (WPF)][2] Basically WPF is created to make windows form easier to design because of the use of XAML, designers can work on the design and programmers on the underlying code [1]: http://windowsclient.net/ [2]: http://msdn.microsoft.com/en-us/netframework/aa663326.aspx
WPF is the Windows Presentation Foundation. It is Microsoft's newest API for building applications with User Interfaces (UIs), working for both standalone and web-based applications. Unsurprisingly, there is a very detailed but not all that helpful [Windows Presentation Foundation page at Wikipedia][1]. The [WPF Getting Started Page][2] at the Microsoft MSDN site is probably a better place to start. [1]: http://en.wikipedia.org/wiki/Windows_Presentation_Foundation [2]: http://msdn.microsoft.com/en-us/library/ms742119.aspx
There are a large number of ways to store data - even "relational databse" covers a range of alternatives from a simple library of code that manipulates a local file (or files) as if it were a relational database on a single user basis, through file based systems than can handle multiple-users to a generous selection of serious "server" based systems. We use XML files a lot - you get well structured data, nice tools for querying same the ability to do edits if appropriate, something that's human readable and you don't then have to worry about the db engine working (or the workings of the db engine). This works well for stuff that's essentially read only (in our case more often than not generated from a db elsewhere) and also for single user systems where you can just load the data in and save it out as required - but you're creating opportunities for problems if you want multi-user editing - at least of a single file. For us that's about it - we're either going to use something that will do SQL (MS offer a set of tools that run from a .DLL to do single user stuff all the way through to enterprise server and they all speak the same SQL (with limitations at the lower end)) or we're going to use XML as a format because (for us) the verbosity is seldom an issue. We don't currently have to manipulate binary data in our apps so that question doesn't arise. Murph
Try Prevayler: [http://www.prevayler.org/wiki/][1] [1]: http://www.prevayler.org/wiki/
Try Prevayler: [http://www.prevayler.org/wiki/][1] [1]: http://www.prevayler.org/wiki/ Prevayler is alternative to RDBMS. In the site have more info.
WPF is the next frontier with Windows UIs. - Built on top of DirectX, it opens up hardware acceleration support for your .Net 3.0+ user-interfaces. - Emphasis on Vector Graphics - UIs scale and render better - Composable UIs. You could nest animated buttons in combo boxes.. the world's your oyster. - Is a rewrite with only minimal core components written in unmanaged code VS GDI-User Dll based Winforms approach which is a thin managed layer over largely unmanaged code. - Declarative approach to UI programming, User Interfaces are largely specified in a XML variant called XAML (eXtensible Application markup language) pronounced Zammel. This opens up WPF to designer folks who can specialized tools to craft UIs that the developers can then code up. No translation losses between wireframes to final product. - MS 'allegedly' will not provide any future updates to Winforms. Heavily invested in WPF as the way forward - Oh yeah, before I forget. Works best on Vista :) You can get either Adam Nathan's WPF Unleashed Book or Chris Sells Programming WPF .. those seem to be the way to go. I just read the first chapter of Adam's (Lead for WPF at MS) book. Hence the WPF praise fountains :)
Error 1012 is rather generically ERROR_CANT_READ. See this [Microsoft list][1], but it also implies it refers to the registry. You could try running SysInternals [Process Monitor][2] to look for failing file/registry operations by the process. [1]: http://msdn.microsoft.com/en-us/library/ms681383(VS.85).aspx [2]: http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx
That explains the problem I had with my app--it was a Rails app, which also has 404 pages with red applied to some of the styles. Makes a whole lot more sense now than it did back then. Too bad you can't accept your own answer!
Why don't you do something like 1stChar + (10 x 2ndChar) + 100 x (3rdChar) ...., where you use the simple integer value of each character, i.e. a = 1, b = 2 etc, or just the integer value if it's not a letter. This will give a unique value for each string, even for 2 strings that are just the same letters in a different order. Of course if gets more complicated if you need to worry about Unicode rather than just ASCII and the numbers could get large if you need to use long string. Are the standard Java string comparison functions definitely not efficient enough?
How long are the strings? If they are very short, then a unique ID can be generated by considering the characters as digits in base 36 (26 + 10) that form a *n*-digits number where *n* is the length of the string. On the other hand, if the strings are short enough to allow this, direct comparison won't be an issue anyway. Otherwise you'll have to generate a collision-free hash and this can only be done when the complete problem space is known in advance (i.e. if you know all strings that can possibly occur). You will want to have a look at [perfect hashing](http://en.wikipedia.org/wiki/Perfect_hashing), although the only feasible algorithm to find a perfect hash function that I know is probabilistic so collisions are still theoretically possible. There might be other ways to find such a function. Knuth called this a “rather amusing … puzzle” in TAoCP but he doesn't give an algorithm either. In general, you give way too few information to find an algorithm that doesn't require probing the whole problem space in some manner. This does invariably mean that the problem has exponential running time but could be solved using machine-learning heuristics. I'm not sure if this is advisable in your case.
Perhaps: String y = "oiu291981u39u192u3198u389u28u389u"; BigInteger bi = new BigInteger(y, 36); System.out.println(bi);
I'm not sure if this is exactly what you're looking for, but there is a method in NSString that will sanitize a URL: [stringByAddingPercentEscapesUsingEncoding:][1] [1]: http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/doc/uid/20000154-BCIBFDCB
Routing does not distinguish between URLs ending with a / and URLs that don't end in /.
A few questions in the beginning: 1. Did you test that simple string comparison is too slow? 1. How the comparison looks like ('ABC' == 'abc' or 'ABC' != 'abc')? 1. How many string do you have to compare? 1. How many comparison do you have to do? 1. How your strings look like (the length, letter case)? As far as I remember String in Java is an object and two identical strings point to the same object. So, maybe it would be enough to compare objects (probably string comparison is already implemented in this way). If it doesn't help you can try to use Pascal implementation of string object when first element is length and if your strings have various length this should save some CPU time.
If I get it right, you (should) have 2 models. A Route model, and a Stop model. Here's how I would define these models: class Route < ActiveRecord::Base has_and_belongs_to_many :stops belongs_to :stop, :foreign_key => 'destination_id' end class Stop < ActiveRecorde::Base has_and_belongs_to_many :routes end And here's how I would set up my tables: create_table :routes do |t| t.integer :destination_id # Any other information you want to store about routes end create_table :stops do |t| # Any other information you want to store about stops end create_table :routes_stops, :primary_key => [:route_id, :stop_id] do |t| t.integer :route_id t.integer :stop_id end Finally, here's the code I'd use: # First, find all the relevant routes, just for caching. Route.find(numbers) r = Route.find(number) r.destination_id = destination r.stops << stop This should use only a few SQL queries.
Inline CSS only for clarity here. Use a real stylesheet. <!-- First, your background image is a DIV with a background image style applied, not a IMG tag. --> <div style="background-image:(url=YourBackgroundImage);"> <!-- Second, create a placeholder div to assist in positioning the other images. This is relative to the background div. --> <div style="position: relative; left: 0; top: 0;"> <!-- Now you can place your IMG tags, and position them relative To the container we just made --> <img src="YourForegroundImage" style="position: relative; top: 0; left: 0;"/> </div> </div>
(this is what finally got everything to work for me) Make sure EVERY socket that the socket in A connects to has socket.SetSocketOption(SocketOptionLevel.Socket(/IP),SocketOptionName.ReuseAddress, true); set upon being initiated.
(this is what finally got everything to work for me) Make sure EVERY socket that the socket in A connects to has socket.SetSocketOption(SocketOptionLevel.Socket,SocketOptionName.ReuseAddress, true); set upon being initiated.
@buti-oxa: Not to be pedantic, but your code is invalid. The HTML `width` and `height` attributes do not allow for units; you're likely thinking of the CSS `width:` and `height:` properties. You should also provide a content-type (`text/css`; see Espo's code) with the `<style>` tag. <style type="text/css"> .containerdiv { float: left; position: relative; } .cornerimage { position: absolute; top: 0; right: 0; } </style> <div class="containerdiv"> <img border="0" src="http://www.gravatar.com/avatar/" alt="" width="100" height="100"> <img class="cornerimage" border="0" src="http://www.gravatar.com/avatar/" alt="" width="40" height="40"> <div> Leaving `px;` in the `width` and `height` attributes might cause a rendering engine to balk.
I'll second the vote for SQLite. I'm not sure what you're trying to accomplish but if you're doing any sort of local storage with syncing SQLite is a good choice. It has very widespread adoption and a lot of community support.
We use [jtcron][1] for our scheduled background tasks. It works well, and if you understand cron it should make sense to you. [1]: http://www.jarretttaylor.com/java/jt-cron.html
I'm working on a project using the [ANTLR][1] parser library for C#. I've built a grammar to parse some text and it works well. However, when the parser comes across an illegal or unexpected token, it throws one of many exceptions. The problem is that in some cases (not all) that my try/catch block won't catch it and instead stops execution as an unhandled exception. The issue for me is that I can't replicate this issue anywhere else but in my full code. The call stack shows that the exception definitely occurs within my try/catch(Exception) block. The only thing I can think of is that there are a few ANTLR assembly calls that occur between my code and the code throwing the exception and this library does not have debugging enabled, so I can't step through it. I wonder if non-debuggable assemblies inhibit exception bubbling? The call stack looks like this; external assembly calls are in Antlr.Runtime: Expl.Itinerary.dll!TimeDefLexer.mTokens() Line 1213 C# Antlr3.Runtime.dll!Antlr.Runtime.Lexer.NextToken() + 0xfc bytes Antlr3.Runtime.dll!Antlr.Runtime.CommonTokenStream.FillBuffer() + 0x22c bytes Antlr3.Runtime.dll!Antlr.Runtime.CommonTokenStream.LT(int k = 1) + 0x68 bytes Expl.Itinerary.dll!TimeDefParser.prog() Line 109 + 0x17 bytes C# Expl.Itinerary.dll!Expl.Itinerary.TDLParser.Parse(string Text = "", Expl.Itinerary.IItinerary Itinerary = {Expl.Itinerary.MemoryItinerary}) Line 17 + 0xa bytes C# The code snippet from the bottom-most call in Parse() looks like: try { // Execution stopped at parser.prog() TimeDefParser.prog_return prog_ret = parser.prog(); return prog_ret == null ? null : prog_ret.value; } catch (Exception ex) { throw new ParserException(ex.Message, ex); } To me, a catch (Exception) clause should've captured any exception whatsoever. Is there any reason why it wouldn't? **Update:** I traced through the external assembly with Reflector and found no evidence of threading whatsoever. The assembly seems to just be a runtime utility class for ANTLR's generated code. The exception thrown is from the TimeDefLexer.mTokens() method and its type is NoViableAltException, which derives from RecognitionException -> Exception. This exception is thrown when the lexer cannot understand the next token in the stream; in other words, invalid input. This exception is SUPPOSED to happen, however it should've been caught by my try/catch block. Also, the rethrowing of ParserException is really irrelevant to this situation. That is a layer of abstraction that takes any exception during parse and convert to my own ParserException. The exception handling problem I'm experiencing is never reaching that line of code. In fact, I commented out the "throw new ParserException" portion and still received the same result. One more thing, I modified the original try/catch block in question to instead catch NoViableAltException, eliminating any inheritance confusion. I still received the same result. Someone once suggested that sometimes VS is overactive on catching handled exceptions when in debug mode, but this issue also happens in release mode. Man, I'm still stumped! I hadn't mentioned it before, but I'm running VS 2008 and all my code is 3.5. The external assembly is 2.0. [1]: http://antlr.org
I'm working on a project using the [ANTLR][1] parser library for C#. I've built a grammar to parse some text and it works well. However, when the parser comes across an illegal or unexpected token, it throws one of many exceptions. The problem is that in some cases (not all) that my try/catch block won't catch it and instead stops execution as an unhandled exception. The issue for me is that I can't replicate this issue anywhere else but in my full code. The call stack shows that the exception definitely occurs within my try/catch(Exception) block. The only thing I can think of is that there are a few ANTLR assembly calls that occur between my code and the code throwing the exception and this library does not have debugging enabled, so I can't step through it. I wonder if non-debuggable assemblies inhibit exception bubbling? The call stack looks like this; external assembly calls are in Antlr.Runtime: Expl.Itinerary.dll!TimeDefLexer.mTokens() Line 1213 C# Antlr3.Runtime.dll!Antlr.Runtime.Lexer.NextToken() + 0xfc bytes Antlr3.Runtime.dll!Antlr.Runtime.CommonTokenStream.FillBuffer() + 0x22c bytes Antlr3.Runtime.dll!Antlr.Runtime.CommonTokenStream.LT(int k = 1) + 0x68 bytes Expl.Itinerary.dll!TimeDefParser.prog() Line 109 + 0x17 bytes C# Expl.Itinerary.dll!Expl.Itinerary.TDLParser.Parse(string Text = "", Expl.Itinerary.IItinerary Itinerary = {Expl.Itinerary.MemoryItinerary}) Line 17 + 0xa bytes C# The code snippet from the bottom-most call in Parse() looks like: try { // Execution stopped at parser.prog() TimeDefParser.prog_return prog_ret = parser.prog(); return prog_ret == null ? null : prog_ret.value; } catch (Exception ex) { throw new ParserException(ex.Message, ex); } To me, a catch (Exception) clause should've captured any exception whatsoever. Is there any reason why it wouldn't? **Update:** I traced through the external assembly with Reflector and found no evidence of threading whatsoever. The assembly seems to just be a runtime utility class for ANTLR's generated code. The exception thrown is from the TimeDefLexer.mTokens() method and its type is NoViableAltException, which derives from RecognitionException -> Exception. This exception is thrown when the lexer cannot understand the next token in the stream; in other words, invalid input. This exception is SUPPOSED to happen, however it should've been caught by my try/catch block. Also, the rethrowing of ParserException is really irrelevant to this situation. That is a layer of abstraction that takes any exception during parse and convert to my own ParserException. The exception handling problem I'm experiencing is never reaching that line of code. In fact, I commented out the "throw new ParserException" portion and still received the same result. One more thing, I modified the original try/catch block in question to instead catch NoViableAltException, eliminating any inheritance confusion. I still received the same result. Someone once suggested that sometimes VS is overactive on catching handled exceptions when in debug mode, but this issue also happens in release mode. Man, I'm still stumped! I hadn't mentioned it before, but I'm running VS 2008 and all my code is 3.5. The external assembly is 2.0. Also, some of my code subclasses a class in the 2.0 assembly. Could a version mismatch cause this issue? [1]: http://antlr.org
The question is how to generate a temporary file **name**. Neither mkstemp nor tmpfile provide the caller with a name, they return a file descriptor or file handle, respectively.
WebForms can live with MVC controllers in the same app. By default, routing does not route requests for files that exist on disk. So you could start rewriting small parts of your site at a time to use the MVC pattern, and leave the rest of it using WebForms.
I wouldn't do it myself, because to me it muddies what a particular method does, and the method-chaining is of limited use to me over doing it longhand. It isn't going to send me into a quivering ball of rage and psychosis, though, which is always a good thing. :') I wouldn't be concerned about performance; just ask Knuth.
ASP.Net MVC route mapping
|asp.net-mvc|
I'm new to MVC (and ASP.Net routing). I'm trying to map *.aspx to a controller called "PageController". routes.MapRoute( "Page", "{name}.aspx", new { controller = "Page", action = "Index", id = "" } ); Wouldn't the code above map *.aspx to "PageController"? When I run this and type in any .aspx page I get the following error: > The controller for path '/Page.aspx' could not be found or it does not implement the IController interface. Parameter name: controllerType Is there something I'm not doing here?
|asp.net|asp.net-mvc|routes|
Where can I find a good ASP.NET MVC sample?
|c#|asp.net-mvc|
I have been using Castle MonoRail for the last two years, but in a new job I am going to be the one to bring in ASP.NET MVC with me. I understand the basics of views, actions and the like. I just need a good sample for someone with MVC experience. Any good links besides Scott's Northwind traders sample?
|c#|asp.net|asp.net-mvc|
A delegate is a named type that defines a particular kind of method. Just as a class definition lays out all the members for the give kind of object it defines, so does the delegate lay out the method signature for the kind of method it defines. Based on this statement, a delegate is a function pointer and it defines what that function looks like. A great example for a real world application of a delegate is the [Predicate<T>][1]. In the example from the link, you will notice that [Array.Find][2] takes the array to search and then a predicate to handle the criteria of what to find. In this case it passes a method ProductGT10 which matches the Predicate signature. [1]: http://msdn.microsoft.com/en-us/library/bfcke1bz.aspx [2]: http://msdn.microsoft.com/en-us/library/d9hy2xwa.aspx
>A delegate is a named type that defines a particular kind of method. Just as a class definition lays out all the members for the given kind of object it defines, the delegate lays out the method signature for the kind of method it defines. Based on this statement, a delegate is a function pointer and it defines what that function looks like. A great example for a real world application of a delegate is the [Predicate<T>][1]. In the example from the link, you will notice that [Array.Find][2] takes the array to search and then a predicate to handle the criteria of what to find. In this case it passes a method ProductGT10 which matches the Predicate signature. [1]: http://msdn.microsoft.com/en-us/library/bfcke1bz.aspx [2]: http://msdn.microsoft.com/en-us/library/d9hy2xwa.aspx
PHP preg functions needs your regex to be wrapped with a delimiter character, which can be any character. You can't use this delimiter character without escaping inside the regex. This should work (here the delimiter character is /): preg_match('/\d{4}-\d{2}-\d{2} \d{2}:\d{2}\d{2}/', '2008-09-01 12:35:45'); // or this, to allow matching 0:00:00 time too. preg_match('/\d{4}-\d{2}-\d{2} \d{1,2}:\d{2}\d{2}/', '2008-09-01 12:35:45'); If you need to match lines that contain only datetime, add ^ and $ at the beginning and end of the regex. preg_match('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}\d{2}$/', '2008-09-01 12:35:45'); [Link to PHP Manual's preg_match()][1] [1]: http://www.php.net/preg-match
Is the new Windows Gui system. I don't believe its aim is to make development easier per se but more to address fundamental issues with WinForm, such as transparency and scaling, neither of which WinForm can effectively address. Furthermore it seeks to address the "one resolution only" paradigm of WinForm by mapping sizes to real-pixel sizes and making flow layout easier and more fundamental. It's also based on an XML derivative making it easier to change the UI and forcing a separation of the UI and the core code (although technically you can still badly hack it together in this manner). This separation also drives a desire to be able to divide the work into two camps, the designers taking charge of the XAML and layout and the programmers taking care of developing the objects used in the XAML.
It's strange to need to layout one control within another. You might be solving an upstream problem wrong. Are you able to split the label into two labels with the updown between and maybe rely on a Windows Forms TableLayout panel? If it's essential to try to position based on font sizes, you could use [Graphics.MeasureString][1]("String before updown", myLabel.Font) [1]: http://msdn.microsoft.com/en-us/library/6xe5hazb.aspx
It's strange to need to layout one control within another. You might be solving an upstream problem wrong. Are you able to split the label into two labels with the updown between and maybe rely on a Windows Forms TableLayout panel? If it's essential to try to position based on font sizes, you could use [Graphics.MeasureString][1]("String before updown", myLabel.Font) If what you're after is font-dependent control positioning, you should probably retitle the question. [1]: http://msdn.microsoft.com/en-us/library/6xe5hazb.aspx
It's strange to need to layout one control within another. You might be solving an upstream problem wrong. Are you able to split the label into two labels with the updown between and maybe rely on a Windows Forms TableLayout panel? If it's essential to try to position based on font sizes, you could use [Graphics.MeasureString][1]("String before updown", myLabel.Font) If what you're after is font-dependent control positioning, you should probably retitle the question. <hr> [edit] You can handle the click event of the "second half" part of the label and change the checkbox state on that event. The whole thing seems like a hack though. What is the problem being solved by this weird control layout? Why do you need an up-down in the middle of a label? [1]: http://msdn.microsoft.com/en-us/library/6xe5hazb.aspx
Check out [GigaSpaces][1]. It's a quite successful Jini/Javaspaces implementation. I think that despit the great Jini model, it is stuck with Java. Web-services is more appealing because it's works with standarized protocols. [1]: http://www.gigaspaces.com
Check out [GigaSpaces][1]. It's a quite successful Jini/Javaspaces implementation. I think Jini has a great model, but it is stuck with Java. Web-services is more appealing because it works with standarized protocols, even though Jini service discovery is more natural. [1]: http://www.gigaspaces.com
You probably want to set an isolation level for the entire transaction rather than using _with (rowlock)_ on specific tables. Look at this page: [http://msdn.microsoft.com/en-us/library/ms173763.aspx][1] Specifically, search within it for 'row lock', and I think you'll find that READ COMMITTED or REPEATABLE READ are what you want. READ COMMITTED is the SQL Server default. If READ COMMITTED doesn't seem strong enough to you, then go for REPEATABLE READ. [1]: http://msdn.microsoft.com/en-us/library/ms173763.aspx
You probably want to set an isolation level for the entire transaction rather than using _with (rowlock)_ on specific tables. Look at this page: [http://msdn.microsoft.com/en-us/library/ms173763.aspx][1] Specifically, search within it for 'row lock', and I think you'll find that READ COMMITTED or REPEATABLE READ are what you want. READ COMMITTED is the SQL Server default. If READ COMMITTED doesn't seem strong enough to you, then go for REPEATABLE READ. **Update:** After reading one of your follow up posts, you definitely want repeatable read. That will hold the lock until you either commit or rollback the transaction. [1]: http://msdn.microsoft.com/en-us/library/ms173763.aspx
Are all of the resources that you're linking to in the <head> present at the locations where your page is seeking them (verify this by actually checking it). I've also had an issue when checking an app in Safari where I was attempting to pull a file that wasn't there and I had very similar output to yours (red links). EDIT: Adding Chan-Chan's find to the answer, since it explains it so well: > k, found it. > > If any of your stylesheets is missing > or pathed incorrectly, it throws a > 404. If your 404 page has inline styles, they get respected via the > "alternate sheets" rule in webkit. > > Thus, the red links on the "yellow > screen of death" are causing my > problem in overlap.
Are all of the resources that you're linking to in the <head> present at the locations where your page is seeking them (verify this by actually checking it). I've also had an issue when checking an app in Safari where I was attempting to pull a file that wasn't there and I had very similar output to yours (red links). EDIT: Adding ChanChan's find to the answer, since it explains it so well: > k, found it. > > If any of your stylesheets is missing > or pathed incorrectly, it throws a > 404. If your 404 page has inline styles, they get respected via the > "alternate sheets" rule in webkit. > > Thus, the red links on the "yellow > screen of death" are causing my > problem in overlap.
`require` will load a file. If that file contains any class/module definitions, then your other code will now be able to use them. If the file just contains code which is not in any modules, it will get run as if it were in the same place as your 'require' call (like PHP include) `include` is to do with modules. It takes all the methods in the module, and adds them to your class. Like this: class Orig end Orig.new.first_method # no such method module MyModule def first_method end end class Orig include MyModule end Orig.new.first_method # will now run first_method as it's been added. There's also `extend` which works like include does, but instead of adding the methods as _instance_ methods, adds them as _class_ methods, like this: Note above, how when I wanted to access first_method, I created a new object of `Orig` class. That's what I mean by instance method. class SecondClass extend MyModule end SecondClass.first_method # will call first_method Note that in this example I'm not making any new objects, just calling the method directly on the class, as if it had been defined as `self.first_method` all along. So there you go :-)
In Linux, you can accomplish this by printing \b and/or \r to stderr. You might need to experiment to find the right combination of things in Windows.
(In this example, I am assuming port 2222 will go to your internal host. $externalip and $internalip are the ip addresses or hostnames of the visible and internal machine, respectively.) You have a couple of options, depending on how permanent you want the proxying to be: - Some sort of TCP proxy. On Linux, the basic idea is that <i>before</i> the incoming packet is processed, you want to <i>change its destination</i>&mdash;i.e. prerouting destination NAT: `iptables -t nat -A PREROUTING -p tcp -i eth0 -d $externalip --dport 2222 --sport 1024:65535 -j DNAT --to $internalip:22` - Using SSH to establish temporary port forwarding. From here, you have two options again: - Transparent proxy, where the client thinks that your visible host (on port 2222) is just a normal SSH server and doesn't realize that it is passing through. While you lose some fine-grained control, you get convenience (especially if you want to use SSH to forward VNC or X11 all the way to the inner host). - From the internal machine: `ssh -g -R 2222:localhost:22 $externalip` - Then from the outside world: `ssh -p 2222 $externalip` Notice that the "internal" and "external" machines do not have to be on the same LAN. You can port forward all the way around the world this way&mdash;in fact I do this almost every day (on port 80) to get around the Internet censorship where I live. - Forcing login to the external machine first. This is true "forwarding," not "proxying"; but the basic idea is this: You force people to log in to the external machine (so you control on who can log in and when, and you get logs of the activity), and from there they can SSH through to the inside. It sounds like a chore, but if you <i>set up simple shell scripts on the external machine with the names of your internal hosts, coupled with password-less SSH keypairs</i> then it is very straightforward for a user to log in. So: - On the external machine, you make a simple script, `/usr/local/bin/internalhost` which simply runs `ssh $internalip` - From the outside world, users do: `ssh $externalip internalhost` and once they log in to the first machine, they are immediately forwarded through to the internal one. Another advantage to this approach is that people don't get key management problems, since running two SSH services on one IP address will make the SSH client angry. FYI, if you want to SSH to a server and you do not want to worry about keys, do this ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no I have an alias in my shell called "nossh", so I can just do `nossh somehost` and it will ignore all key errors. Just understand that you are ignoring security information when you do this, so there is a theoretical risk. Much of this information is from a talk I gave at Barcamp Bangkok all about fancy SSH tricks. You can see [my slides](http://www.proven-corporation.com/static/ssh/), but I recommend the [text version](http://www.proven-corporation.com/static/ssh/ssh.txt) as the S5 slides are kind of buggy. Check out the section called "Forward Anything: Simple Port Forwarding" for info. There is also information on creating a SOCKS5 proxy with OpenSSH. Yes, you can do that. OpenSSH is awesome like that. (Finally, if you are doing a lot of traversing into the internal network, consider setting up a VPN. It sounds scary, but OpenVPN is quite simple and runs on all OSes. I would say it's overkill just for SSH; but once you start port-forwarding through your port-forwards to get VNC, HTTP, or other stuff happening; or if you have lots of internal hosts to worry about, it can be simpler and more maintainable.)
|sharepoint|transaction|design0patterns|
|sharepoint|design-patterns|transactions|
Do you know any patterns for GUI programming? (Not patterns on designing GUIs)
|user-interface|designpatterns|
I'm looking for patterns that concern coding parts of a GUI. **Not** as global as **MVC**, that I'm quite familiar with, but patterns and good ideas and best practices concerning single controls and inputs. Let say I want to make a control that display some objects that may overlap. Now if I click on an object, I need to find out what to do (Just finding the object I can do in several ways, such as an quad-tree and Z-order, thats not the problem). And also I might hold down a modifier key, or some object is active from the beginning, making the selection or whatever a bit more complicated. Should I have an object instance representing a screen object, handle the user-action when clicked, or a master class. etc.. What kind of patterns or solutions are there for problems like this?
|user-interface|design-patterns|
Can you really build a fast word processor with GoF Design Patterns?
|java|performance|ide|designpatterns|text-processing|
The Gang of Four's [Design Patterns](http://en.wikipedia.org/wiki/Design_Patterns) uses a word processor as an example for at least a few of their patterns, particularly Composite and Flyweight. Other than by using C or C++, could you really use those patterns and the object-oriented overhead they entail to write a high-performing fully featured word processor? I know that Eclipse is written in Java but I haven't used it much so I don't know if it's all that fast or as polished as something like Visual Studio, which has a C++ based text editing system.
|java|performance|ide|design-patterns|text-processing|
Singletons: good design or a crutch?
|language-agnostic|designpatterns|singleton|