instruction
stringlengths
21
27.8k
chosen
stringlengths
18
28.2k
rejected
stringlengths
18
33.6k
__index_level_0__
int64
0
50k
<p>I am working on a proposal for my company into purchasing some load testing software. I have to give 2 choices. One of my choices I am proposing is HP(Mecurary) Loadrunner. Is there another program out there that is comparible with Loadrunner? We are looking at using the software to test the performance of the following. </p> <p>C# .NET Template</p> <p>Microsoft® .NET 2.0, 3.0</p> <p>Microsoft® SQL Server Informix</p> <p>Web (HTTP/HTML)</p> <p>Web Services</p> <p>Web and Multimedia</p> <p>Wireless Application Protocol (WAP)</p> <p>Domain Name System (DNS)</p> <p>Microsoft® Exchange (MAPI)</p>
<p>OpenSourceTesting.com has a <a href="http://www.opensourcetesting.org/performance.php" rel="nofollow noreferrer">list of OSS performance tools</a>.</p> <p>The Software Testing FAQ also has a <a href="http://www.testingfaqs.org/t-load.html" rel="nofollow noreferrer">list of commercial and OSS performance testing tools</a>.</p> <p>Since it looks like you're on a Windows platform, you can also use the following tools:</p> <ul> <li>Visual Studio <a href="http://msdn.microsoft.com/en-us/library/aa287410.aspx" rel="nofollow noreferrer">Application Center Test</a> (Enterprise Editions only?)</li> <li>Microsoft <a href="http://www.microsoft.com/downloads/details.aspx?familyid=e2c0585a-062a-439e-a67d-75a89aa36495&amp;displaylang=en" rel="nofollow noreferrer">Web Application Stress</a> tool (aka WAS, aka "Homer"; predecessor to Application Center Test)</li> </ul> <p>There are a lot of options out there, but it seems like you have a good handle on your requirements. I recommend doing a trade study of your top choices, using weighted criteria and a rank of how each product scores (sort of like a custom "Consumer Reports" style comparison). This will help you reduce any preconceived notions towards or against a product, and also gives your management a sound empirical reason as to why you choose the tool you did. This can go a long way in justifying the cost for a big ticket item.</p> <p>Also, for the commercial tools, the vendors will often come on site and set up a demo system to test your code. We did this a few years back with Mercury, Rational and NuMega. It really helped cut through the presentation B.S. and see exactly how the products could be used with our apps.</p>
<p>TestComplete from Automated QA is also very well respected:</p> <p><a href="http://www.automatedqa.com" rel="nofollow noreferrer">http://www.automatedqa.com</a></p> <p>The product is comprehensive and you can script it in a variety of languages including C#. I'd try the 30-day trial and how it compares to LoadRunner for your specific requirements.</p>
46,540
<p>I need to select data when a page is viewed and update the 'views' column is there a way to do this in one query, or do I have to use to distinct queries?</p>
<p>If you do not want/need to use a transaction, you could create a stored procedure that first updates the view count and then selects the values and return them to the user.</p>
<p>PostgreSQL's <a href="http://www.postgresql.org/docs/8.3/static/sql-update.html" rel="nofollow noreferrer">UPDATE</a> statement has the RETURNING clause that will return a result set like a SELECT statement:</p> <pre><code>UPDATE mytable SET views = 5 WHERE id = 16 RETURNING id, views, othercolumn; </code></pre> <p>I'm pretty sure this is not standard though. I don't know if any other databases implement it.</p> <p>Edit: I just noticed that your question has the "MySQL" tag. Maybe you should mention it in the question itself. It's a good generic database question though - I would like to see how to do it in other databases.</p>
6,525
<p>I think there are a lot of people out there unaware of RFC's (Request for Comments). I know what they are at a logical level, but can anybody give a good description for a new developer? Also, sharing some resources on how to use and read them would be nice. </p>
<p>The term comes from the days of ARPANET, the predecessor to the internet, where the researchers would basically just throw ideas out there to, well, make a request for comments from the other researchers on the project. They could be about pretty much anything and were not very formal at the time. If you go read them, it’s pretty comical how informal they were.</p> <p>Now, there are more standards about what goes in RFC's and you can't get an RFC published until you have met strict guidelines and have done extensive research. They are pretty much reserved for well researched network standards that have been approved by the IETF.</p>
<p>It's a Request For Comments. That title is a little misleading though, as it's often used as a name for standards, mostly those by the IETF. See <a href="http://en.wikipedia.org/wiki/Request_for_Comments" rel="nofollow noreferrer">Wikipedia</a></p>
18,565
<p>I have a Java method which starts up a Process with ProcessBuilder, and pipes its output into a byte array, and then returns its byte array when the process is finished.</p> <p>Pseudo-code:</p> <pre><code>ProcessBuilder b = new ProcessBuilder("my.exe") Process p = b.start(); ... // get output from process, close process </code></pre> <p>What would be the best way to go about unit testing this method? I haven't found a way to mock ProcessBuilder (it's final), even with the incredibly awesome <a href="http://jmockit.org" rel="noreferrer">JMockit</a>, it gives me a NoClassDefFoundError:</p> <pre><code>java.lang.NoClassDefFoundError: test/MockProcessBuilder at java.lang.ProcessBuilder.&lt;init&gt;(ProcessBuilder.java) at mypackage.MyProcess.start(ReportReaderWrapperImpl.java:97) at test.MyProcessTest.testStart(ReportReaderWrapperImplTest.java:28) </code></pre> <p>Any thoughts?</p> <hr> <p><strong>Answer</strong> - As Olaf recommended, I ended up refactoring those lines to an interface</p> <pre><code>Process start(String param) throws IOException; </code></pre> <p>I now pass an instance of this interface into the class I wanted to test (in its constructor), normally using a default implementation with the original lines. When I want to test I simply use a mock implementation of the interface. Works like a charm, though I do wonder if I'm over-interfacing here...</p>
<p>Shield yourself from the classes to be mocked. Create an interface either for doing what you really want (e.g. hiding the fact that external processes are involved at all) or only for Process and ProcessBuilder. </p> <p>You don't want to test, that ProcessBuilder and Process work, only that you can work with their output. When you create an interface one trivial implementation (that can be inspected easily) delegates to ProcessBuilder and Process, another implementation mocks this behaviour. Later on you might even have another implementation that does what you need without starting another process.</p>
<p>With newer releases of JMockit (0.98+) you should be able to easily mock JRE classes like Process and ProcessBuilder. So, no need to create interfaces just for testing...</p> <p>Full example (using JMockit 1.16):</p> <pre><code>public class MyProcessTest { public static class MyProcess { public byte[] run() throws IOException, InterruptedException { Process process = new ProcessBuilder("my.exe").start(); process.waitFor(); // Simplified example solution: InputStream processOutput = process.getInputStream(); byte[] output = new byte[8192]; int bytesRead = processOutput.read(output); return Arrays.copyOf(output, bytesRead); } } @Test public void runProcessReadingItsOutput(@Mocked final ProcessBuilder pb) throws Exception { byte[] expectedOutput = "mocked output".getBytes(); final InputStream output = new ByteArrayInputStream(expectedOutput); new Expectations() {{ pb.start().getInputStream(); result = output; }}; byte[] processOutput = new MyProcess().run(); assertArrayEquals(expectedOutput, processOutput); } } </code></pre>
25,444
<p>I have an IIS located on serverA</p> <p>I have userA at locationA who has opened a content management system site, hosted on serverA.</p> <p>One of the features of the system is that it allows the user to move a file to LocationB, all within the same network. Now when this move occurs and due to bandwidth restrictions, would this file move from LocationA to serverA to LocationB or is there a way for me to move the file from LocationA to LocationB without going through serverA, i.e using local memory on serverA</p> <p>I am not using BITS at the moment.</p>
<p>To follow up on Ian's suggestion of posting direct to server2, you're going to need some sort of webserver (prob IIS, but you could custom write one, that just accepts the CMS form submission and puts files where they need to go)</p>
<p>That's entirely going to depend on how the CMS works - if it does an <code>scp</code> in the background, then the answer is yes - it skips the local machine. </p> <p>If it uses http to transfer it to the user's machine then back out, the answer is "no".</p>
38,266
<p>I want pass values between web user controls without writing any code to the main page which user controls are put on. I do something like that but after doing that I need to click double to pass the value.</p> <p>The example of what I've done :</p> <p><strong><em>Department User Control (Code-Behind)</em></strong> </p> <pre><code> protected void Page_Load(object sender, EventArgs e) { int productId = ProductUserControl.selectedProductId; ... doing some bind work with productId } </code></pre> <p><strong><em>Product User Control</em></strong></p> <pre><code> public static int selectedProductId; protected void Page_Load(object sender, EventArgs e) { } protected void lvDepartments_ItemCommand(object sender, ListViewCommandEventArgs e) { if (e.CommandName == "selectDepartment") { selectedProductId = int.Parse(e.CommandArgument); } } </code></pre> <p>Thanks in advance...</p>
<p>In your Department User Control you are trying to get the value of selectedProductId before it is set in the Product User Control. That's why you don't get the value you expect until you postback twice.</p> <p>You'll need to get it after the Product User Control sets it in the ItemCommand event. Perhaps placing the Department User Control code in the Page_LoadCompleted... though I'm not sure if that will work either.</p> <p>Another way to do it is to have Product User Control set a public property in Department User Control instead of having Department User Control try to read a property in Product User Control.</p> <p>The issue seems to be a Page Lifecycle issue. <a href="http://www.robincurry.org/blog/content/binary/o_aspNet_Page_LifeCycle.jpg" rel="nofollow noreferrer">http://www.robincurry.org/blog/content/binary/o_aspNet_Page_LifeCycle.jpg</a></p> <p>I'm sure there's a better way than that as well.</p>
<p>Try using delegates to achieve this more cleanly, example <a href="http://www.dotnetfunda.com/articles/article201.aspx" rel="nofollow noreferrer">here</a></p>
49,264
<p>It says in <a href="http://www.ibm.com/developerworks/java/library/j-jtp04223.html" rel="nofollow noreferrer">this article</a> that: </p> <blockquote> <p>Making a class final because it is immutable is a good reason to do so.</p> </blockquote> <p>I'm a bit puzzled by this... I understand that immutability is a good thing from the POV of thread-safety and simplicity, but it seems that these concerns are somewhat orthogonal to extensibility. So, why is immutability a good reason for making a class final?</p>
<p>The explanation for this is given in the book 'Effective Java'</p> <p>Consider <code>BigDecimal</code> and <code>BigInteger</code> classes in Java .</p> <p>It was not widely understood that immutable classes had to be effectively final when <code>BigInteger</code> and <code>BigDecimal</code> were written, so all of their methods may be overridden. Unfortunately, this could not be corrected after the fact while preserving backward compatibility.</p> <p><strong>If you write a class whose security depends on the immutability of a BigInteger or BigDecimal argument from an un-trusted client, you must check to see that the argument is a “real” BigInteger or BigDecimal, rather than an instance of an un trusted subclass. If it is the latter, you must defensively copy it under the assumption that it might be mutable.</strong></p> <pre><code> public static BigInteger safeInstance(BigInteger val) { if (val.getClass() != BigInteger.class) return new BigInteger(val.toByteArray()); return val; } </code></pre> <p>If you allow sub classing, it might break the "purity" of the immutable object.</p>
<p>Its a good idea to make a class immutable for performance reasons too. Take Integer.valueOf for example. When you call this static method it does not have to return a new Integer instance. It can return a previously created instance safe in the knowledge that when it passed you a reference to that instance last time you didn't modify it (I guess this is also good reasoning from a security reason perspective too).</p> <p>I agree with the standpoint taken in Effective Java on these matters -that you should either design your classes for extensibility or make them non-extensible. If its your intention to make something extensible perhaps consider an interface or abstract class.</p> <p>Also, you don't have to make the class final. You can make the constructors private.</p>
17,620
<p>I need to define a calculated member in MDX (this is SAS OLAP, but I'd appreciate answers from people who work with different OLAP implementations anyway).</p> <p>The new measure's value should be calculated from an existing measure by applying an additional filter condition. I suppose it will be clearer with an example:</p> <ul> <li>Existing measure: "Total traffic"</li> <li>Existing dimension: "Direction" ("In" or "Out")</li> <li>I need to create a calculated member "Incoming traffic", which equals "Total traffic" with an additional filter (Direction = "In")</li> </ul> <p>The problem is that I don't know MDX and I'm on a very tight schedule (so sorry for a newbie question). The best I could come up with is:</p> <pre><code>([Measures].[Total traffic], [Direction].[(All)].[In]) </code></pre> <p>Which almost works, except for cells with specific direction:</p> <p><img src="https://i.stack.imgur.com/z3BxZ.png" alt="example"></p> <p>So it looks like the "intrinsic" filter on Direction is overridden with my own filter). I need an intersection of the "intrinsic" filter and my own. My gut feeling was that it has to do with Intersecting <code>[Direction].[(All)].[In]</code> with the intrinsic coords of the cell being evaluated, but it's hard to know what I need without first reading up on the subject :)</p> <p><strong>[update]</strong> I ended up with </p> <pre><code>IIF([Direction].currentMember = [Direction].[(All)].[Out], 0, ([Measures].[Total traffic], [Direction].[(All)].[In]) ) </code></pre> <p>..but at least in SAS OLAP this causes extra queries to be performed (to calculate the value for [in]) to the underlying data set, so I didn't use it in the end.</p>
<p>To begin with, you can define a new calculated measure in your MDX, and tell it to use the value of another measure, but with a filter applied:</p> <pre><code>WITH MEMBER [Measures].[Incoming Traffic] AS '([Measures].[Total traffic], [Direction].[(All)].[In])' </code></pre> <p>Whenever you show the new measure on a report, it will behave as if it has a filter of 'Direction > In' on it, regardless of whether the Direction dimension is used at all.</p> <p>But in your case, you WANT the Direction dimension to take precendence when used....so things get a little messy. You will have to detect if this dimension is in use, and act accordingly:</p> <pre><code>WITH MEMBER [Measures].[Incoming Traffic] AS 'IIF([Direction].currentMember = [Direction].[(All)].[Out], ([Measures].[Total traffic]), ([Measures].[Total traffic], [Directon].[(All)].[In]) )' </code></pre> <p>To see if the Dimension is in use, we check if the current cell is using OUT. If so we can return Total Traffic as it is. If not, we can tell it to use IN in our tuple.</p>
<p>I think you should put a column in your Total Traffic fact table for IN/OUT indication &amp; create a Dim table for the IN &amp; Out values. You can then analyse your data based on IN &amp; Out.</p>
24,021
<p>I am using a piece of html something like the following:-</p> <pre><code>&lt;a class="somePseudoClass" title="Blablabla"&gt;Something&lt;/a&gt; </code></pre> <p>and I have the following css in an imported file.</p> <pre><code>a.somePseudoClass:hover {color: #000000; text-decoration: underline;} </code></pre> <p>This works perfectly in Firefox 2.0 but in IE6 the underline fails to show.</p> <p>Does anyone know of a workaround?</p>
<p>Looks like you need a href attribute to make it work...</p> <pre><code>a.somePseudoClass {text-decoration: none;} a.somePseudoClass:hover {color: #000000; text-decoration: underline;} &lt;a class="somePseudoClass" title="Blablabla" href="#" onclick="return false;"&gt;Something&lt;/a&gt; </code></pre>
<p>this should work, but it depends on what other CSS declarations you have (before and after it)</p>
41,515
<p>I have a SVN structure like this:</p> <pre><code>/Projects /Project1 /Project2 /someFolder /Project3 /Project4 </code></pre> <p>I would like to move all the projects into the /Projects folder, which means I want to move Projects 3 and 4 from /someFolder into the /projects folder.</p> <p>The caveat: I'd like to keep the full history. I assume that every client would have to check out the stuff from the new location again, which is fine, but I still wonder what the simplest approach is to move directories without completely destroying the history?</p> <p>Subversion 1.5 if that matters.</p>
<pre><code>svn help rename </code></pre> <p>Moving/renaming in subversion keeps history intact.</p>
<p>As far as I know, only Bazaar allow to keep history on directories, espacially when talking about moving directories. SVN allows you to keep history when moving files, but not directories.</p>
13,396
<p>I've got to get a quick and dirty configuration editor up and running. The flow goes something like this:</p> <p>configuration (POCOs on server) are serialized to XML.<br> The XML is well formed at this point. The configuration is sent to the web server in XElements.<br> On the web server, the XML (Yes, ALL OF IT) is dumped into a textarea for editing.<br> The user edits the XML directly in the webpage and clicks Submit.<br> In the response, I retrieve the altered text of the XML configuration. At this point, ALL escapes have been reverted by the process of displaying them in a webpage.<br> I attempt to load the string into an XML object (XmlElement, XElement, whatever). KABOOM.</p> <p>The problem is that serialization escapes attribute strings, but this is lost in translation along the way. </p> <p>For example, let's say I have an object that has a regex. Here's the configuration as it comes to the web server:</p> <pre><code>&lt;Configuration&gt; &lt;Validator Expression="[^&amp;lt;]" /&gt; &lt;/Configuration&gt; </code></pre> <p>So, I put this into a textarea, where it looks like this to the user:</p> <pre><code>&lt;Configuration&gt; &lt;Validator Expression="[^&lt;]" /&gt; &lt;/Configuration&gt; </code></pre> <p>So the user makes a slight modification and submits the changes back. On the web server, the response string looks like:</p> <pre><code>&lt;Configuration&gt; &lt;Validator Expression="[^&lt;]" /&gt; &lt;Validator Expression="[^&amp;]" /&gt; &lt;/Configuration&gt; </code></pre> <p>So, the user added another validator thingie, and now BOTH have attributes with illegal characters. If I try to load this into any XML object, it throws an exception because &lt; and &amp; are not valid within a text string. I CANNOT CANNOT CANNOT CANNOT use any kind of encoding function, as it encodes the entire bloody thing:</p> <p>var result = Server.HttpEncode(editedConfig);</p> <p>results in </p> <pre><code>&amp;lt;Configuration&amp;gt; &amp;lt;Validator Expression="[^&amp;lt;]" /&amp;gt; &amp;lt;Validator Expression="[^&amp;amp;]" /&amp;gt; &amp;lt;/Configuration&amp;gt; </code></pre> <p>This is NOT valid XML. If I try to load this into an XML element of any kind I will be hit by a falling anvil. I don't like falling anvils. </p> <p>SO, the question remains... Is the ONLY way I can get this string XML ready for parsing into an XML object is by using regex replaces? Is there any way to "turn off constraints" when I load? How do you get around this???</p> <hr> <p>One last response and then wiki-izing this, as I don't think there is a valid answer.</p> <p>The XML I place in the textarea IS valid, escaped XML. The process of 1) putting it in the text area 2) sending it to the client 3) displaying it to the client 4) submitting the form it's in 5) sending it back to the server and 6) retrieving the value from the form REMOVES ANY AND ALL ESCAPES. </p> <p>Let me say this again: I'M not un-escaping ANYTHING. Just displaying it in the browser does this!</p> <p>Things to mull over: Is there a way to prevent this un-escaping from happening in the first place? Is there a way to take almost-valid XML and "clean" it in a safe manner?</p> <hr> <p>This question now has a bounty on it. To collect the bounty, you demonstrate how to edit VALID XML in a browser window WITHOUT a 3rd party/open source tool that doesn't require me to use regex to escape attribute values manually, that doesn't require users to escape their attributes, and that doesn't fail when roundtripping (&amp;amp;amp;amp;amp;etc;)</p>
<p>Erm … <em>How</em> do you serialize? Usually, the XML serializer should never produce invalid XML.</p> <p>/EDIT in response to your update: Do <strong>not</strong> display invalid XML to your user to edit! Instead, display the properly escaped XML in the TextBox. Repairing broken XML isn't fun and I actually see no reason not to display/edit the XML in a valid, escaped form.</p> <p>Again I could ask: <em>how</em> do you display the XML in the TextBox? You seem to intentionally unescape the XML at some point.</p> <p>/EDIT in response to your latest comment: Well yes, obviously, since the it can contain HTML. You need to escape your XML properly before writing it out into an HTML page. With that, I mean the <em>whole</em> XML. So this:</p> <pre><code>&lt;foo mean-attribute="&amp;lt;"&gt; </code></pre> <p>becomes this:</p> <pre><code>&amp;lt;foo mean-attribute="&amp;amp;&amp;lt;"&amp;gt; </code></pre>
<p>This special character - "&lt;" - should have replaced with other characters so that your XML will be valid. Check this link for XML special characters:</p> <p><a href="http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references</a></p> <p>Try also to encode your TextBlock content before sending it to the deserializer:</p> <pre><code>HttpServerUtility utility = new HttpServerUtility(); string encodedText = utility.HtmlEncode(text); </code></pre>
30,291
<p>I am writing a custom maven2 MOJO. I need to access the runtime configuration of another plugin, from this MOJO.</p> <p>What is the best way to do this?</p>
<p>Using properties is certainly one way to go, however not ideal. It still requires a user to define the ${propertyName} in multiple places throughout the pom. I want to allow my plugin to work with no modifications to the user's pom, other than the plugin definition itself.</p> <p>I don't see accessing the runtime properties of another MOJO as too tight coupling. If the other MOJO is defined anywhere in the build hierarchy, I want my MOJO to respect the same configuration.</p> <p>My current solution is:</p> <pre><code>private Plugin lookupPlugin(String key) { List plugins = getProject().getBuildPlugins(); for (Iterator iterator = plugins.iterator(); iterator.hasNext();) { Plugin plugin = (Plugin) iterator.next(); if(key.equalsIgnoreCase(plugin.getKey())) { return plugin; } } return null; } /** * Extracts nested values from the given config object into a List. * * @param childname the name of the first subelement that contains the list * @param config the actual config object */ private List extractNestedStrings(String childname, Xpp3Dom config) { final Xpp3Dom subelement = config.getChild(childname); if (subelement != null) { List result = new LinkedList(); final Xpp3Dom[] children = subelement.getChildren(); for (int i = 0; i &lt; children.length; i++) { final Xpp3Dom child = children[i]; result.add(child.getValue()); } getLog().info("Extracted strings: " + result); return result; } return null; } </code></pre> <p>This has worked for the few small builds I've tested with. Including a multi-module build.</p>
<p>I'm not sure how you would do that exactly, but it seems to me that this might not be the best design decision. If at all possible you should aim to decouple your Mojo from any other plugins out there.</p> <p>Instead I would recommend using custom properties to factor out any duplication in the configuration of separate plugins.</p> <p>You can set a custom property "foo" in your pom by using the properties section:</p> <pre><code>&lt;project&gt; ... &lt;properties&gt; &lt;foo&gt;value&lt;/foo&gt; &lt;/properties&gt; ... &lt;/project&gt; </code></pre> <p>The property foo is now accessible anywhere in the pom by using the dollar sign + curly brace notation:</p> <pre><code>&lt;somePluginProperty&gt;${foo}&lt;/somePluginProperty&gt; </code></pre>
15,240
<p>I'm not talking about a pointer to an instance, I want a pointer to a class itself.</p>
<p>In C++, classes are not "<a href="http://en.wikipedia.org/wiki/First-class_object" rel="nofollow noreferrer">first class objects</a>". The closest you can get is a pointer to its <code>type_info</code> instance.</p>
<p>Depending upon how you want to think about pointers, you can have a "pointer" to a class, if by pointer you mean some integral value. Boost allows you to register types and assign a unique integer for every type that you register. If the types you are registering are all classes then you can look up at run-time the code necessary to create an object of the type you want, as long as you have the value of the type you want. But in general, classes aren't first class objects in the language and the best you can hope for is to simulate the behavior you want to have.</p>
36,314
<p>In my php web app, suppose I want to go the extra mile and in addition to going gang-busters and being anal-retentive about sanitizing my inputs, I also want to ensure that no JavaScript is being output in strings I am inserting into html templates. </p> <p>Is there a standard way to make sure I don't put JavaScript in the generated html content?</p>
<p>If you aren't opposed to external dependencies, the <a href="http://htmlpurifier.org/" rel="nofollow noreferrer">HTML Purifier library</a> is a pretty good filter for a majority of XSS attacks.</p>
<p>not exactly a standard way; because what if you were doing: <code>&lt;img src="${path}"&gt;</code>, and <code>${path}</code> expanded to <code>http://p0wned.com/jpg.jpg" /&gt;&lt;script src="p0wned.com/js.js"/&gt;</code></p> <p>Anyway I like this regular expression:</p> <pre><code>#from http://www.perlmonks.org/?node_id=161281 sub untag { local $_ = $_[0] || $_; # ALGORITHM: # find &lt; , # comment &lt;!-- ... --&gt;, # or comment &lt;? ... ?&gt; , # or one of the start tags which require correspond # end tag plus all to end tag # or if \s or =" # then skip to next " # else [^&gt;] # &gt; s{ &lt; # open tag (?: # open group (A) (!--) | # comment (1) or (\?) | # another comment (2) or (?i: # open group (B) for /i ( TITLE | # one of start tags SCRIPT | # for which APPLET | # must be skipped OBJECT | # all content STYLE # to correspond ) # end tag (3) ) | # close group (B), or ([!/A-Za-z]) # one of these chars, remember in (4) ) # close group (A) (?(4) # if previous case is (4) (?: # open group (C) (?! # and next is not : (D) [\s=] # \s or "=" ["`'] # with open quotes ) # close (D) [^&gt;] | # and not close tag or [\s=] # \s or "=" with `[^`]*` | # something in quotes ` or [\s=] # \s or "=" with '[^']*' | # something in quotes ' or [\s=] # \s or "=" with "[^"]*" # something in quotes " )* # repeat (C) 0 or more times | # else (if previous case is not (4)) .*? # minimum of any chars ) # end if previous char is (4) (?(1) # if comment (1) (?&lt;=--) # wait for "--" ) # end if comment (1) (?(2) # if another comment (2) (?&lt;=\?) # wait for "?" ) # end if another comment (2) (?(3) # if one of tags-containers (3) &lt;/ # wait for end (?i:\3) # of this tag (?:\s[^&gt;]*)? # skip junk to "&gt;" ) # end if (3) &gt; # tag closed }{}gsx; # STRIP THIS TAG return $_ ? $_ : ""; } </code></pre>
18,843
<p>I'm painfully new to PHP, and was trying to set up phpBB on my local site. I have a stock debian install of apache2 and php5. The phpBB installer ran fine, connected to the database and created all its tables with no problem. But when I tried to open the login page, I got a 0-byte response.</p> <p>A little digging showed that it was never making it past the call to mysql_pconnect(). The php binary just quits without error or message. Nothing at all. I tried running the following code:</p> <pre><code>&lt;?php $id = @mysql_pconnect('localhost','myusername', 'mypassword', true); print "id=".$id."\n"; ?&gt; </code></pre> <p>and the "id=" string never prints. It just does nothing. I don't know where to look to see what error happened, or what is going on at all. All i've installed is "mysql" using pear... perhaps I'm missing something else?</p> <p>This has got to be a path problem somewhere. The mysql extension is built nicely at</p> <pre><code>/usr/lib/php5/20060613+lfs/mysql.so </code></pre> <p><strong>Answer:</strong></p> <p>jishi: informed me that the "@" operator suppresses output, including error messages (@echo off, anyone?)</p> <p>tomhaigh: extensions must be explicitly enabled in php.ini file. After adding the line "extension=mysql.so" to php.ini, the following code runs fine:</p> <pre><code>% cat d.php &lt;?php ini_set('display_errors', true); error_reporting(E_ALL | E_NOTICE); $id = mysql_pconnect('localhost','myusername', 'mypassword', true); print "id=".$id."\n"; ?&gt; % php -c /etc/php5/apache2/php.ini d.php id=Resource id #4 </code></pre> <p>JOY!</p>
<p>Just noted that you're using a @ in front of mysql_pconnect(). That suppresses all errors, which in this case is a pretty bad idea. Remove that and you would probably see the output. </p> <p>Otherwise:</p> <p>Check your php.ini, should be in /etc/php5/apache2/php.ini for debian.</p> <p>Check for a line called display_errors, set that to true if you want error-output in your browser (not recommended for a production-system, but is useful during debugging and development).</p> <p>Specify log_errors on for apache to log your errors to apaches error logfile, which by default in debian would be (unless other error-file is specified for the phpBB-site):</p> <p>/var/log/apache2/error.log</p>
<p>I sometimes have PHP going down a 'black hole' when it finds a function that it can't find.</p> <p>Can you verify that the mysql extension is installed correctly?</p> <p>You can do this by creating a php page like this:</p> <pre><code>&lt;?php phpinfo(); ?&gt; </code></pre> <p>Saving it in your webroot, and then accessing it. It should contain all the information about what your server is currently running in terms of PHP modules.</p>
35,149
<p>I'm setting up a server which is on a network behind a firewall and I want programs on this computer to be able to use sendmail to send emails to any email address. We have an SMTP server running on this network (let's call it mailrelay.example.com) which is how we're supposed to get outgoing emails through the firewall.</p> <p>So how do I configure sendmail to send all mail through mailrelay.example.com? Googling hasn't given me the answer yet, and has only revealed that sendmail configuration is extremely complex and annoying.</p>
<p>@eli: modifying sendmail.cf directly is not usually recommended, since it is generated by the macro compiler. </p> <p>Edit /etc/mail/sendmail.mc to include the line:</p> <pre><code> define(`SMART_HOST',`mailrelay.example.com')dnl </code></pre> <p>After changing the sendmail.mc macro configuration file, it must be recompiled to produce the sendmail configuration file.</p> <pre><code> # m4 /etc/mail/sendmail.mc &gt; /etc/sendmail.cf </code></pre> <p>And restart the sendmail service (Linux):</p> <pre><code> # /etc/init.d/sendmail restart </code></pre> <p>As well as setting the smarthost, you might want to also disable name resolution configuration and possibly shift your sendmail to non-standard port, or disable daemon mode.</p> <h1>Disable Name Resolution</h1> <p>Servers that are within fire-walled networks or using Network Address Translation (NAT) may not have DNS or NIS services available. This creates a problem for sendmail, since it will use DNS by default, and if it is not available you will see messages like this in mailq:</p> <pre><code> host map: lookup (mydomain.com): deferred) </code></pre> <p>Unless you are prepared to setup an appropriate DNS or NIS service that sendmail can use, in this situation you will typically configure name resolution to be done using the /etc/hosts file. This is done by enabling a 'service.switch' file and specifying resolution by file, as follows:</p> <p>1: Enable service.switch for sendmail Edit /etc/mail/sendmail.mc to include the lines:</p> <pre><code> define(`confSERVICE_SWITCH_FILE',`/etc/mail/service.switch')dnl </code></pre> <p>2: Configure service.switch for files Create or modify /etc/mail/service.switch to refer only to /etc/hosts for name resolution:</p> <pre><code> # cat /etc/mail/service.switch hosts files </code></pre> <p>3: Recompile sendmail.mc and restart sendmail for this setting to take effect.</p> <h1>Shift sendmail to non-standard port, or disable daemon mode</h1> <p>By default, sendmail will listen on port 25. You may want to change this port or disable the sendmail daemon mode altogether for various reasons: - if there is a security policy prohibiting the use of well-known ports - if another SMTP product/process is to be running on the same host on the standard port - if you don't want to accept mail via smtp at all, just send it using sendmail</p> <p>1: To shift sendmail to use non-standard port. Edit /etc/mail/sendmail.mc and modify the "Port" setting in the line:</p> <pre><code> DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA') </code></pre> <p>For example, to get sendmail to use port 125:</p> <pre><code> DAEMON_OPTIONS(`Port=125,Addr=127.0.0.1, Name=MTA') </code></pre> <p>This will require sendmail.mc to be recompiled and sendmail to be restarted.</p> <p>2: Alternatively, to disable sendmail daemon mode altogether (Linux) Edit /etc/sysconfig/sendmail and modify the "DAEMON" setting to:</p> <pre><code> DAEMON=no </code></pre> <p>This change will require sendmail to be restarted.</p>
<p>@Espo: Thanks for the great advice on where to start. Your link would have been better if I had been configuring sendmail for its first use instead of taking an existing configuration and making this small change. However, once I knew to look for stuff on "SmartHost", I found an easier way.</p> <p>All I had to do was edit my /etc/mail/sendmail.cf file to change</p> <pre><code>DS </code></pre> <p>to</p> <pre><code>DSmailrelay.example.com </code></pre> <p>then restart sendmail and it worked.</p>
6,559
<p>Does anyone have any experience with running C++ applications that use the boost libraries on uclibc-based systems? Is it even possible? Which C++ standard library would you use? Is uclibc++ usable with boost?</p>
<p>We use Boost together with GCC 2.95.3, libstdc++ and STLport on an ARMv4 platform running uClinux. Some parts of Boost are not compatible with GCC 2.x but the ones that are works well in our particular case. The libraries that we use the most are <em>date_time</em>, <em>bind</em>, <em>function</em>, <em>tuple</em> and <em>thread</em>.</p> <p>Some of the libraries we had issues with were <em>lambda</em>, <em>shared_pointer</em> and <em>format</em>. These issues were most likely caused by our version of GCC since it has problems when you have too many includes or deep levels of template structures.</p> <p>If possible I would recommend you to run the boost test suite with your particular toolchain to ensure compatibility. At the very least you could compile a native toolchain in order to ensure that your library versions are compatible.</p> <p>We have not used uClibc++ because that is not what our toolchain provider recommends so I cannot comment on that particular combination.</p>
<p>I have not tried but I don't know anything about uclibc that would prevent Boost from working.</p> <p>Try it and see what happens, I would say.</p>
39,893
<p>This is a very specific question regarding <strong>MySQL</strong> as implemented in <strong>WordPress</strong>.</p> <p>I'm trying to develop a plugin that will show (select) posts that have specific '<strong>tags</strong>' and belong to specific '<strong>categories</strong>' (both multiple)</p> <p>I was told it's impossible because of the way categories and tags are stored:</p> <ol> <li><code>wp_posts</code> contains a list of posts, each post have an &quot;ID&quot;</li> <li><code>wp_terms</code> contains a list of terms (both categories and tags). Each term has a TERM_ID</li> <li><code>wp_term_taxonomy</code> has a list of terms with their TERM_IDs and has a Taxonomy definition for each one of those (either a Category or a Tag)</li> <li><code>wp_term_relationships</code> has associations between terms and posts</li> </ol> <p>How can I join the tables to get all posts with tags &quot;Nuclear&quot; <strong>and</strong> &quot;Deals&quot; that also belong to the category &quot;Category1&quot;?</p>
<p>I misunderstood you. I thought you wanted Nuclear or Deals. The below should give you only Nuclear and Deals.</p> <pre><code>select p.* from wp_posts p, wp_terms t, wp_term_taxonomy tt, wp_term_relationship tr, wp_terms t2, wp_term_taxonomy tt2, wp_term_relationship tr2 wp_terms t2, wp_term_taxonomy tt2, wp_term_relationship tr2 where p.id = tr.object_id and t.term_id = tt.term_id and tr.term_taxonomy_id = tt.term_taxonomy_id and p.id = tr2.object_id and t2.term_id = tt2.term_id and tr2.term_taxonomy_id = tt2.term_taxonomy_id and p.id = tr3.object_id and t3.term_id = tt3.term_id and tr3.term_taxonomy_id = tt3.term_taxonomy_id and (tt.taxonomy = 'category' and tt.term_id = t.term_id and t.name = 'Category1') and (tt2.taxonomy = 'post_tag' and tt2.term_id = t2.term_id and t2.name = 'Nuclear') and (tt3.taxonomy = 'post_tag' and tt3.term_id = t3.term_id and t3.name = 'Deals') </code></pre>
<p>Thanks @Eric it works! Just a few code corrections for future reference:</p> <ul> <li>the first select statements misses a coma after wp_term_relationship tr2</li> <li>In the same select statemt the following must be change:</li> </ul> <pre><code>wp_terms t2, wp_term_taxonomy tt2, wp_term_relationship tr2</code></pre> <p>should be</p> <pre><code>wp_terms t3, wp_term_taxonomy tt3, wp_term_relationship tr3</code></pre>
4,783
<p>I 'd like to use Criteria for my SQL query. I have 3 tables "home", "person" and a third table "liveIn" for correspondance between home and person.</p> <p>My sql query is "select home.id from home, person, liveIn where home.country = 'Japan' and person.id = '15' and liveIn.Homeid = home.id and liveIn.PersonId = person.id"</p> <p>A little help anybody ?</p>
<p>Typically, my process runs something like this:</p> <ul> <li>I usually start with a logical model - a bastardised UML if you like - so I can visualise the key entities and relationships in my system. </li> <li>Then I think about a the underlying datamodel (thinking through potential issues around data consumption patterns, performance and so on)</li> <li>Then I choose an appropriate data access architecture</li> <li>Then I start coding the data layer and business objects (with any redesign of the logical model as required)</li> </ul> <p>I dont think there is too much point 'over-designing' at the logical stage because requirements change as the project progresses, both from a business and technical / design perspective, in ways you can't always anticipate in advance.</p>
<p>I never really bothered about UML (not "real" UML anyway). When I start a project, I'm interested in a few things:</p> <ol> <li>How will my software be used (and by whom)</li> <li>What does the software need to do</li> <li>How do the different features/components fit together</li> </ol> <p>For 1, you can use UML Use Case diagrams. I normally use my own pseudo use case diagrams. From this you map out who will use your software and in what ways. Different users will use the software in different ways. This is useful because it a) helps you determine who your target users are and b) helps you determine what features are required for 2. Also, if you know who will use your software and how, you can tune it specifically for these users.</p> <p>For 2, I normally just make a big list. Sometimes it is useful to split the list into categories and/or priorities. This often becomes my "TODO" list then.</p> <p>For 3, I draw something resembling UML class diagrams, except without the UML annotations. Basically each class/module/component gets its own box and they are linked together with lines. This shows me what components will exist in the system and how they are related/communicate etc. I probably draw it different for every project and some get more detail than others, depending on what I feel I need at the time.</p> <p>After this, I like to prototype core concepts by writing simple throwaway mockups/prototypes. This will give me some ideas as to how it will work, how to implement it and how not to implement it (often I do the prototype "the wrong way", which I wouldn't have known if I hadn't written one). The important thing here is that the code is NOT used in the real version.</p>
41,473
<p>I have some char() fields in a DBF table that were left encrypted by a past developer in the project. </p> <p>However, I know the plaintext result of the decryption of several records. How can I determine the function/algorithm/scheme to decrypt the original data? These are some sample fields:</p> <p>For cryptext:</p> <pre><code>b5 01 02 c1 e3 0d 0a </code></pre> <p>plaintext should be:</p> <pre><code>3543921 or 3.543.921 </code></pre> <p>And for cryptext:</p> <pre><code>41 c3 c5 07 17 0d 0a </code></pre> <p>plaintext should be</p> <pre><code>1851154 or 1.851.154 </code></pre> <p>I believe <code>0d 0a</code> is just padding. Was from data gathered in win-1252 encoding (dunno if matters)</p> <p><strong>EDIT:</strong> It's for the sake of curiosity and learning. I want to be able to undestand the encryption used(seems a simple one, although is binary data) to recover the value of the fields for the tuples whose plaintext I don't know.</p> <p><strong>EDIT 2:</strong> Added a couple samples.</p>
<p>There is no easy way in general case. This question is too general. Try posting these plain + encrypted strings.</p> <p>EDIT: </p> <ul> <li>for the sake of learning you can read this article : <a href="http://en.wikipedia.org/wiki/Cryptography" rel="nofollow noreferrer">Cryptography on Wikipedia</a></li> <li><p>if you really beleive the encryption is simple - check if it's a byte (or word) level XOR - see the following pseudocode</p> <pre><code>for (i in originalString) { newString[i] = originalString[i] ^ CRYPT_BYTE; } </code></pre></li> </ul>
<p>I think it's a misconception that XOR is an easily decryptable scheme. The theoretically strongest form of encryption is a one-time pad: simply a string of predetermined bits which you xor your plaintext with...</p> <p>Finite XORs, on the other hand...</p>
28,668
<p>I'm trying to do query result pagination with hibernate and displaytag, and Hibernate <code>DetachedCriteria</code> objects are doing their best to stand in the way. Let me explain...</p> <p>The easiest way to do pagination with displaytag seems to be implementing the <code>PaginatedList</code> interface that has, among others, the following methods:</p> <pre><code>/* Gets the total number of results. */ int getFullListSize(); /* Gets the current page of results. */ List getList(); /* Gets the page size. */ int getObjectsPerPage(); /* Gets the current page number. */ int getPageNumber(); /* Get the sorting column and direction */ String getSortCriterion(); SortOrderEnum getSortDirection(); </code></pre> <p>I'm thinking of throwing my PaginatedList implementation a Criteria object and let it work along theese lines...</p> <pre><code>getFullListSize() { criteria.setProjection(Projections.rowCount()); return ((Long) criteria.uniqueResult()).intValue(); } getList() { if (getSortDirection() == SortOrderEnum.ASCENDING) { criteria.addOrder(Order.asc(getSortCriterion()); } else if (getSortDirection() == SortOrderEnum.DECENDING) { criteria.addOrder(Order.desc(getSortCriterion()); } return criteria.list((getPageNumber() - 1) * getObjectsPerPage(), getObjectsPerPage()); } </code></pre> <p>But this doesn't work, because the <code>addOrder()</code> or the <code>setProjection()</code> calls modify the criteria object rendering it in-usable for the successive calls. I'm not entirely sure of the order of the calls, but the db throws an error on <code>getFullListSize()</code> trying to do a "<code>select count(*) ... order by ...</code>" which is obviously wrong.</p> <p>I think I could fix this by creating an object of my own to keep track of query conditions and rebuilding the Criteria object for each call, but that feels like reinventing yet another wheel. Is there a smarter way, possibly copying the Criteria initially passed in and working on that copy?</p> <p><strong><em>Update</em></strong>: It looks like <code>getList</code> is called first, and <code>getFullListSize</code> is called multiple times after, so, as soon as there's an ordering passed in, <code>getFullListSize</code> will fail. It would make sense to hit the db only once (in <code>getList</code> I'd say) and cache the results, with no need to copy/reset the <code>Criteria</code> object, but still...</p> <p><strong><em>Update (again)</em></strong>: Forget about that, once I've done the <code>count</code> I can't do the <code>select</code>, and vice versa. I really need two distinct <code>Criteria</code> objects.</p>
<pre><code>Criteria.setProjection(null); Criteria.setResultTransformer(Criteria.ROOT_ENTITY); </code></pre> <p>Will effectively "reset" the criteria between the rowCount projection and execution of the criteria itself.</p> <p>I would make sure your Order hasn't been added before doing the rowCount, it'll slow things down. My implementation of PaginatedList ALWAYS runs a count query before looking for results, so ordering isn't an issue.</p>
<pre><code>public static DetachedCriteria Clone(this DetachedCriteria criteria) { var dummy = criteria.ToByteArray(); return dummy.FromByteArray&lt;DetachedCriteria&gt;(); } </code></pre>
48,179
<p>Given a table or a temp table, I'd like to run a procedure that will output a SQL script (i.e. a bunch of INSERT statements) that would populate the table. Is this possible in MS SQL Server 2000?</p>
<p>Something along the lines of</p> <blockquote> <pre><code>function(table) { for(var i=0;i&lt;table.rows.length;i++) { newcell = table.rows[i].cells[0].cloneNode(true); table.rows[i].appendChild(newcell); } } </code></pre> </blockquote>
<p>Something along the lines of</p> <blockquote> <pre><code>function(table) { for(var i=0;i&lt;table.rows.length;i++) { newcell = table.rows[i].cells[0].cloneNode(true); table.rows[i].appendChild(newcell); } } </code></pre> </blockquote>
20,362
<p>I have an Image control with it's source bound to a property on an object(string url to an image). After making a service call, i update the data object with a new URL. The exception is thrown after it leaves my code, after invoking the PropertyChanged event.</p> <p>The data structure and the service logic are all done in a core dll that has no knowledge of the UI. How do I sync up with the UI thread when i cant access a Dispatcher? </p> <p>PS: Accessing Application.Current.RootVisual in order to get at a Dispatcher is not a solution because the root visual is on a different thread(causing the exact exception i need to prevent). </p> <p>PPS: This only is a problem with the image control, binding to any other ui element, the cross thread issue is handled for you.</p>
<pre><code>System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =&gt; {...}); </code></pre> <p>Also look <a href="https://stackoverflow.com/questions/1924408/invalid-cross-thread-access-issue/1925827#1925827">here.</a></p>
<p>The property getter for RootVisual on the Application class has a thread check which causes that exception. I got around this by storing the root visual's dispatcher in my own property in my App.xaml.cs:</p> <pre><code>public static Dispatcher RootVisualDispatcher { get; set; } private void Application_Startup(object sender, StartupEventArgs e) { this.RootVisual = new Page(); RootVisualDispatcher = RootVisual.Dispatcher; } </code></pre> <p>If you then call BeginInvoke on App.RootVisualDispatcher rather than Application.Current.RootVisual.Dispatcher you shouldn't get this exception.</p>
6,915
<p>How can you do a streaming read on a large XML file that contains a xs:sequence just below root element, without loading the whole file into a XDocument instance in memory?</p>
<p>Going with a SAX-style element parser and the <a href="http://msdn.microsoft.com/en-us/library/system.xml.xmltextreader.aspx" rel="noreferrer">XmlTextReader</a> class created with <a href="http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.create.aspx" rel="noreferrer">XmlReader.Create</a> would be a good idea, yes. Here's a slightly-modified code example from <a href="http://www.codeguru.com/csharp/csharp/cs_data/xml/article.php/c4221/" rel="noreferrer">CodeGuru</a>:</p> <pre><code>void ParseURL(string strUrl) { try { using (var reader = XmlReader.Create(strUrl)) { while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: var attributes = new Hashtable(); var strURI = reader.NamespaceURI; var strName = reader.Name; if (reader.HasAttributes) { for (int i = 0; i &lt; reader.AttributeCount; i++) { reader.MoveToAttribute(i); attributes.Add(reader.Name,reader.Value); } } StartElement(strURI,strName,strName,attributes); break; // //you can handle other cases here // //case XmlNodeType.EndElement: // Todo //case XmlNodeType.Text: // Todo default: break; } } } catch (XmlException e) { Console.WriteLine("error occured: " + e.Message); } } } } </code></pre>
<p>I think it's not possible if you want to use object model (i.e. XElement\XDocument) to query XML. Obviously, you can't build XML objects tree without reading enough data. However you can use <a href="http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx" rel="nofollow noreferrer">XmlReader</a> class.</p> <blockquote> <p>The XmlReader class reads XML data from a stream or file. It provides non-cached, forward-only, read-only access to XML data.</p> </blockquote>
6,736
<p>Why does the C++ STL not provide any "tree" containers, and what's the best thing to use instead?</p> <p>I want to store a hierarchy of objects as a tree, rather than use a tree as a performance enhancement...</p>
<p>There are two reasons you could want to use a tree:</p> <p>You want to mirror the problem using a tree-like structure:<br> For this we have <a href="https://www.boost.org/doc/libs/1_70_0/libs/graph/doc/index.html" rel="noreferrer">boost graph library</a></p> <p>Or you want a container that has tree like access characteristics For this we have</p> <ul> <li><a href="https://en.cppreference.com/w/cpp/container/map" rel="noreferrer"><code>std::map</code></a> (and <a href="https://en.cppreference.com/w/cpp/container/multimap" rel="noreferrer"><code>std::multimap</code></a>)</li> <li><a href="https://en.cppreference.com/w/cpp/container/set" rel="noreferrer"><code>std::set</code></a> (and <a href="https://en.cppreference.com/w/cpp/container/multiset" rel="noreferrer"><code>std::multiset</code></a>)</li> </ul> <p>Basically the characteristics of these two containers is such that they practically have to be implemented using trees (though this is not actually a requirement).</p> <p>See also this question: <a href="https://stackoverflow.com/questions/181630/whats-a-good-and-stable-c-tree-implementation">C tree Implementation</a></p>
<p>All STL containers can be used with iterators. You can't have an iterator an a tree, because you don't have ''one right'' way do go through the tree.</p>
25,232
<p>Anyone getting this error when using the new free chart controls MS bought from Dundas?</p> <p>"Error executing child request for ChartImg.axd"</p> <p>On the MSDN forum they suggested it was my web.config: <a href="http://social.msdn.microsoft.com/Forums/en-US/MSWinWebChart/thread/1dc4b352-c9a5-49dc-8f35-9b176509faa1/" rel="noreferrer">MSDN forum post</a></p> <p>So far that hasn't fixed the problem though. Any other ideas?</p>
<p>I encountered the same problem: the chart would work on one page but not on the next. Turns out if the chart is initialized for the first time in a POST (i.e. a postback) the error is thrown because the handler is configured incorrectly. To fix the issue modify the httpHandler configuration that user LaptopHeaven referred to in this topic by adding the POST verb:</p> <pre class="lang-xml prettyprint-override"><code>&lt;add path="ChartImg.axd" verb="GET,HEAD,POST" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false" /&gt; </code></pre> <p>I've written a more thorough explanation of why this error occurs in the MSDN forum post that Scott Anderson referred to in his opening post of this topic. </p>
<p>Just wanted to point out that it is also a permission problem with the image not found error.</p> <p>Set the "Allow modify" permissions on your image folder (per default it is "C:\TempImageFiles" for the account under which your website is running.</p> <p>Problem disappears.</p>
38,900
<p>I have analyzed a hibernate generated oracle database and discovered that a delete of a row from a single table will spawn the firing of 1200+ triggers in order to delete the related rows in child tables. The triggers are all auto-generated the same - an automatic delete of a child row without checking for existence first. As it is impossible to predict which child tables will actually have related rows, I think a viable solution to preventing the firing of the cascaded delete down a deeply branched completely empty limb, would be to check for the existence of a related row before attempting to delete. In other dbms', I could simply state " if exists....." before deleting. Is there a comparable way to do this in oracle?</p>
<p>If possible, modify and setup your DB tables appropriately. - Involve a DBA if you have one at your disposal.</p> <p>You need to use <a href="http://www.techonthenet.com/oracle/foreign_keys/foreign_delete.php" rel="nofollow noreferrer">Foreign Key constraints and cascade deletes</a>. This eliminates the need for triggers, etc...</p>
<p>You can query the special dba_objects table: </p> <pre><code>DECLARE X NUMBER; BEGIN SELECT COUNT(*) INTO X FROM DBA_OBJECTS WHERE OBJECT_TYPE = 'TRIGGER' AND OBJECT_NAME = 'YOUR_TRIGGER_NAME_HERE'; IF X = 0 THEN --Trigger doesn't exist, OK to delete... END IF; END; </code></pre>
48,841
<p>I have a WSI installer package that I'm using to install my application. The application itself can be run by a normal user, but I have a configuration app that should only be run by a system administrator. Thus, I don't want it to appear in the Start Menu for all users, just for the administrator.</p> <p>Is there any way to tell Windows Installer to create some shortcuts for all users, and others for administrator only?</p>
<p>since I doubt that you will know the name of every admin and there is no start folder for just admins, then I think a better solution would be for you to have the configuration app check to see if the user running it is an admin then exit gracefully if it is not.</p> <p>EDIT:</p> <p>Perhaps I should explain further why I think adding the shortcut for just admins is a case of solving the wrong problem. Here are some scenarios that I think will illustrate the pitfalls:</p> <p>1) What if you look in the local admins group and add the shortcut for every user listed. Now a week later I am added to the local admins. I don't have the shortcut.</p> <p>2) Often escpecially in an enterprise, individuals are not listed in the local admins, groups are. You could in theory: Query AD to find the members of each group (let's not even consider nested groups here) then add the proper folders under Documents and settings for each of those users even though they may or may not ever log onto this machine. Even if you did, if that group member ship changes, then some admin could log on and not have the shortcut.</p> <p>3) Let's say that you add it for every admin. What happens when my admin rights are taken away? I'll still have the shortcut.</p> <p>It is possible to get around some of these issues by having your MSI install a script that tests to see if the current user is an admin and if they are the script puts the shortcut in start for them. Then register the script as an Active Setup item. Then whenever a new admin logs on they would get the shortcut. This would not however remove the shortcut if they lost their admin privileges. </p> <p>Regardless of all of this if I understand the situation, then there is nothing preventing any user admin or not from going to whatever the shortcut points to and running it.</p> <p>So, again I will say that adding the shortcut only for admins is solving the wrong problem. The right problem to solve is to make it so that you have to be an admin to run the config utility.</p>
<p>I would make a separate MSI for the configuration app and condition its launch sequence to require admin rights. Then you can install the application per user, or better yet update your configuration application to refuse to run at all as a regular user.</p>
12,268
<p>currently I have the following code:</p> <pre><code>String select = qry.substring("select ".length(),qry2.indexOf(" from ")); String[] attrs = select.split(","); </code></pre> <p>which works for the most parts but fails if given the following:</p> <pre><code>qry = "select a,b,c,DATETOSTRING(date_attr_name,'mm/dd/yyyy') from tbl_a"; </code></pre> <p>what I'm looking for is the regex to feed to String.split() which will hande that situation, and for that matter any other special cases you might be able to think of that I'm missing.</p>
<pre><code>[^,]+\([^\)]+\)|[^,]+, </code></pre> <p>Should do it nicely provided you always add a final ',' to your select string:</p> <pre><code>a,b,c,DATETOSTRING(date_attr_name,'mm/dd/yyyy'),f,gg,dr(tt,t,),fff </code></pre> <p>would fail to split the last 'fff' attributes, but:</p> <pre><code>a,b,c,DATETOSTRING(date_attr_name,'mm/dd/yyyy'),f,gg,dr(tt,t,),fff, </code></pre> <p>would captures it. So a little pre-processing would smooth things out.</p> <p><strong>Caveat</strong>: this does not take into account expression within expression </p> <pre><code>EXP(arg1, EXP2(ARG11,ARG22), ARG2) </code></pre> <p>Tell me if that can happen in the queries you have to process.</p> <p><strong>Caveat bis</strong>: since this needs a true regexp and not a simple separator expected by split(), you must use a Matcher, based on the pattern <code>[^,]+\([^\)]+\)|[^,]),</code>, and iterate on Matcher.find() to fill the array of attributes <code>attrs</code>.</p> <p>In short, with split() function, there is no single simple separator that might do the trick.</p>
<p>You probably would have better luck with a <a href="http://www.gibello.com/code/zql/" rel="nofollow noreferrer">SQL parser</a>.</p>
35,319
<p>I have a (potentially dumb) question about the C++ STL. When I make a container (vector, set, map, etc), is it allocated on the stack or on the heap? If I make a set and put 5 million strings, will I have to worry about a stack overflow?</p>
<p>STL classes by default allocate their internal buffers from the heap, although these classes also allow custom allocators that allow a user to specify an alternate location to allocate from - e.g. a shared memory pool.</p>
<p>The container itself is allocated where you decide (it can be the stack, the heap, an object's member, etc) but the memory it uses is, by default, as others described, taken on the Free Store (managed through new and delete) which is not the same as the heap (managed through malloc/free).</p> <p><a href="http://www.parashift.com/c++-faq-lite/freestore-mgmt.html#faq-16.3" rel="nofollow noreferrer">Don't mix the two!</a></p>
5,335
<p>For the past 2 years-(ish) I've been using <a href="http://maven.apache.org" rel="nofollow noreferrer">Maven2</a> for my build/continuous integration solution. I used <a href="http://ant.apache.org" rel="nofollow noreferrer">Ant</a> a bit before that but really didn't get a lot of experience with it. Now I've taken a new job and the team I'm on now uses Ant. </p> <p>What I'm wondering about is this:</p> <p>In Maven we had directory conventions for seperating our java source and files and java test files (<a href="http://junit.org" rel="nofollow noreferrer">JUnit</a> tests). It looked like this:</p> <pre><code>Project- -src/main/java -src/test/java </code></pre> <p>This way your tests are separate from your source/production code and won't be built/deployed as such.</p> <p>Going over the Ant documentation I don't really see any convention for this. Am I missing something? Is there a similar convention in Ant?</p>
<p>My experience with ant -- which is our primary build tool for Java source, so make of this what you will -- is that there are no such <em>formal</em> conventions. Many source projects I've seen organize things in a similar manner; JBoss uses &lt;module&gt;/src/main for sources, etc... Ant just uses whatever conventions you want, which makes it an ideal tool to integrate into a larger project building framework.</p> <p>At any rate, the Maven conventions work just fine for Ant, so if you've already got them in place, just re-use the same structures. Not only is it easier for you to keep track of where things are, when you use a familiar structure, but if you ever decide to mavenize the project, you'll already be set.</p>
<p>An older resource but fine in my opinion are <a href="http://www.onjava.com/pub/a/onjava/2003/12/17/ant_bestpractices.html" rel="nofollow noreferrer">ant-best-practices</a>.</p>
24,619
<p>I have created a mutli-column combobox in VB.net 2008 using windows forms 2.0. I am having trouble accessing data once selected to use in the remainder of the form. There does not seem to be a selected event to use in conjunction with the winform 2.0 combobox.</p> <p>Does anyone have any experience using winforms 2.0? Also I guess a better question would be: is there a site with a break down of windows forms 2.0? As so far nothing seems to be that detailed including MSDN.</p>
<p>It may not be the only place, but <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.utilities.sputility.getserverrelativeurlfromprefixedurl.aspx" rel="nofollow noreferrer">SPUtility.GetServerRelativeUrlFromPrefixedUrl()</a> will parse URLs with ~site and ~sitecollection. MOSS also provides <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.publishing.webcontrols.spurlexpressionbuilder.aspx" rel="nofollow noreferrer">SPUrlExpressionBuilder</a> for declarative use:</p> <pre><code>&lt;link runat="server" rel="stylesheet" type="text/css" href="&lt;% $SPUrl:~SiteCollection/Style Library/MyStyles/style.css %&gt;" /&gt; </code></pre>
<p>I don't know for sure - but I'd bet that code is buried in one of the SharePoint HTTPModules or HTTPHandlers that run for every request.</p>
43,838
<p>Our company uses an app that was originally ColdFusion + Access later converted to classic ASP + MS Sql for task/time tracking called the request system. It's broken down by department, so there's one for MIS, marketing, logistics, etc. The problem comes in when (mainly managers) are using more than one at a time, with 2 browser windows open. The request system uses session variables, a lot of session variables, "session" is referenced 2300 times in the application. When 2 are open at once as you can imagine this causes all sorts of anomalies from the variables getting mixed up.</p> <p>There's a 3 year old MIS request in the system to "fix" this and it's been worked on by 3 developers, and now it's my turn to take a shot at it. I was wondering if anyone else has had to work on a project like this, and if there was some sort of hack to try and mitigate some of the problems. I was thinking of maybe calling something in global.asa to load misc. session variables from the querystring. The problem is, there's all sorts of this going on:</p> <pre><code>If (Session("Application") &lt;&gt; Request("App")) and Request("App") &lt;&gt; "" THEN Session("Application") = Request("App") End If </code></pre> <p>Looking at the functions in include files, you'll have a function with 4 parameters, that makes references to 6 different session variables. So you get the idea, this is going to be painful.</p> <p>Has anyone had to do anything like this in the past? Any hacks you found useful?</p>
<p>refactor the code away from the direct Session("whatever") interface:</p> <ol> <li>create an API for session access and replace all existing use of Session with it (it can be a session 'class/object' or just an include-file)</li> <li>mangle the passed-in names for session variables with something that will make them unique per domain according to your needs (department or whatever)</li> <li>test carefully</li> </ol> <p>then rewrite the whole thing later in a modern web language, and/or find another job before they ask you to perform <em>another</em> miracle ;-)</p>
<p>My manager (who's a business guy, not a code guy), is infatuated with this system. He's in no rush to rewrite it. If I did rewrite this the only session variables used would be login-related. I'm more concerned with fast than right unfortunately :(</p>
35,243
<p>I am getting a <code>NoClassDefFoundError</code> when I run my Java application. What is typically the cause of this?</p>
<p>While it's possible that this is due to a classpath mismatch between compile-time and run-time, it's not necessarily true.</p> <p>It is important to keep two or three different exceptions straight in our head in this case:</p> <ol> <li><p><strong><code>java.lang.ClassNotFoundException</code></strong> This exception indicates that the class was not found on the classpath. This indicates that we were trying to load the class definition, and the class did not exist on the classpath.</p></li> <li><p><strong><code>java.lang.NoClassDefFoundError</code></strong> This exception indicates that the JVM looked in its internal class definition data structure for the definition of a class and did not find it. This is different than saying that it could not be loaded from the classpath. Usually this indicates that we previously attempted to load a class from the classpath, but it failed for some reason - now we're trying to use the class again (and thus need to load it, since it failed last time), but we're not even going to try to load it, because we failed loading it earlier (and reasonably suspect that we would fail again). The earlier failure could be a ClassNotFoundException or an ExceptionInInitializerError (indicating a failure in the static initialization block) or any number of other problems. The point is, a NoClassDefFoundError is not necessarily a classpath problem.</p></li> </ol>
<p>I got this message after removing two files from the SRC library, and when I brought them back I kept seeing this error message.</p> <p>My solution was: Restart Eclipse. Since then I haven't seen this message again :-)</p>
5,466
<p>I recently had to take a quick look at Adobe InDesign server. In this enviroment you write your interactions with the servers libs via JavaSscript. </p> <p>This got me thinking, how could I use the Javascript language within a C# application so that I could expose set bits of functionality of my API/framework and allow others to write small plugins with JavaScript. </p> <p>As JS is a pretty popular language so I would have thought that I wouldnt have to go writing my own impterpretor or anything, but I could be wrong. Any ideas where I would start with something like this?</p> <p>Cheers, Chris. </p>
<p>Check this question:</p> <p><a href="https://stackoverflow.com/questions/356948/referencing-googles-v8-engine-from-a-net-app">Referencing Google’s V8 engine from a .NET app</a></p> <p>This article might be interesting:</p> <p><a href="http://www.west-wind.com/WebLog/posts/10688.aspx" rel="nofollow noreferrer">Evaluating JavaScript code from C#</a> (using MS JScript engine)</p>
<p>Try Javascript .NET:</p> <p><a href="http://javascriptdotnet.codeplex.com/" rel="nofollow noreferrer">http://javascriptdotnet.codeplex.com/</a></p> <p>It implements Google V8. You can compile and run Javascript directly from .NET code with it, and supply CLI objects to be used by the Javascript code as well. And V8 is probably the best engine ever created in terms of performance, it generates native code from Javascript.</p>
47,871
<p>I'm trying to create a horizontal 100% stacked bar graph using HTML and CSS. I'd like to create the bars using <code>DIVs</code> with background colors and percentage widths depending on the values I want to graph. I also want to have a grid lines to mark an arbitrary position along the graph.</p> <p>In my experimentation, I've already gotten the bars to stack horizontally by assigning the CSS property <code>float: left</code>. However, I'd like to avoid that, as it really seems to mess with the layout in confusing ways. Also, the grid lines don't seem to work very well when the bars are floated.</p> <p>I think that CSS positioning should be able to handle this, but I don't yet know how to do it. I want to be able to specify the position of several elements relative to the top-left corner of their container. I run into this sort of issue regularly (even outside of this particular graph project), so I'd like a method that's:</p> <ol> <li>Cross-browser (ideally without too many browser hacks)</li> <li>Runs in Quirks mode</li> <li>As clear/clean as possible, to facilitate customizations</li> <li>Done without JavaScript if possible.</li> </ol>
<p>You are right that CSS positioning is the way to go. Here's a quick run down:</p> <p><code>position: relative</code> will layout an element relative to <em>itself.</em> In other words, the elements is laid out in normal flow, then it is removed from normal flow and offset by whatever values you have specified (top, right, bottom, left). It's important to note that because it's removed from flow, other elements around it will not shift with it (use negative margins instead if you want this behaviour).</p> <p>However, you're most likely interested in <code>position: absolute</code> which will position an element relative to a container. By default, the container is the browser window, but if a parent element either has <code>position: relative</code> or <code>position: absolute</code> set on it, then it will act as the parent for positioning coordinates for its children.</p> <p>To demonstrate:</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-css lang-css prettyprint-override"><code>#container { position: relative; border: 1px solid red; height: 100px; } #box { position: absolute; top: 50px; left: 20px; }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div id="container"&gt; &lt;div id="box"&gt;absolute&lt;/div&gt; &lt;/div&gt;</code></pre> </div> </div> </p> <p>In that example, the top left corner of <code>#box</code> would be 100px down and 50px left of the top left corner of <code>#container</code>. If <code>#container</code> did not have <code>position: relative</code> set, the coordinates of <code>#box</code> would be relative to the top left corner of the browser view port.</p>
<p>If you need to position an element relative to its containing element first you need to add <code>position: relative</code> <strong>to the container element</strong>. The child element you want to position relatively to the parent <strong>has to have</strong> <code>position: absolute</code>. The way that absolute positioning works is that <strong>it is done relative to the first relatively (or absolutely) positioned parent element</strong>. In case there is <strong>no relatively</strong> positioned parent, the element will be positioned relative to the <strong>root element</strong> (directly to the HTML element).</p> <p>So if you want to position your child element to the top left of the parent container, you should do this:</p> <pre><code>.parent { position: relative; } .child { position: absolute; top: 0; left: 0; } </code></pre> <p>You will benefit greatly from reading <a href="https://kolosek.com/css-position-relative-vs-position-absolute/" rel="nofollow noreferrer">this article</a>. Hope this helps!</p>
13,053
<p><strong>Disclaimer:</strong> I am not a professional 3D printer, so I'm not really familiar with how 3D printing works.</p> <p>I was thinking about trying to make a real life model of the atomic orbitals, to clearly see how the orbitals are really shaped. I thought about trying to 3D print a block, made up of colored transparent "ink", in such a way that the darkness of the color at a point in the block should be proportional to the ψ<sup>2</sup> value (probability of the electron cloud). This would print a block in which high density areas are darker than light intensity areas.</p> <p>My question is, would it be possible to design an algorithm to print a specific darkness of ink at a specific location based on the computed value of ψ<sup>2</sup>, which is obtained by solving Schrödinger's Equation. Also, would it be possible to have this fullfilled at a reasonable price to be afforded by a regular customer, such as an engineering employee?</p>
<p><strong>problem definition</strong></p> <p>I'm not quite sure if it's really question for this group. Looks like the problem itself is more for programming or physics group. Having requested calculations (electron cloud shape) resolved, there will be something to print but...</p> <p><strong>printing probability cloud</strong></p> <p>at first, please take a look for example <a href="http://3dprintingfromscratch.com/common/types-of-3d-printers-or-3d-printing-technologies-overview/" rel="nofollow noreferrer">here</a></p> <p>it's a review of 3d printing technologies. i think you should have clear picture if your idea is feasible or not.</p> <p>IMO it's not with todays technologies. in general (and deadly simlified) we have 3 main printing technics</p> <ul> <li>out of solid (or semi-solid) filaments - can be colorful and semi-transparent but it's not homogenous in terms of your needs</li> <li>out of solid powders - can be colorful but it cannot be transparent</li> <li>out of liquids - can be really transparent and color but unfortunately not colorful</li> </ul> <p>i'd say rendering but not printing is what you really need</p>
<p>I suggest you look into Polysher: <a href="http://www.polymaker.com/shop/polysmoothpolysher/" rel="nofollow noreferrer">http://www.polymaker.com/shop/polysmoothpolysher/</a> and e3D cyclops extruder <a href="https://e3d-online.com/Cyclops" rel="nofollow noreferrer">https://e3d-online.com/Cyclops</a> you can make gradients of color.</p> <p>But there might even be a smarter way to do alpha transparency than 100% infill with a transparent material:</p> <p>1) making a lattice of opaque material nodes (where bigger or closer together nodes mean more probability), and using air as the transparent medium</p> <p>2) dunking the 1) in resin</p> <p>3) making the afore-mentioned lattice with a partially transparent material and dunking it in a resin of the same refractive index as the transparent material.</p>
723
<p>I am trying to learn CodeIgniter to use for a shopping site, but I am not having luck with the official doc. Does anyone know of anything that will help?</p>
<p>re: CSS.</p> <p>I've got my CSS a separate folder at the root. (same place as 'index.php') ... /content/css/main.css</p> <p>Called as:</p> <pre><code>&lt;link href="&lt;?=base_url();?&gt;content/css/main.css" rel="stylesheet" type="text/css" /&gt; </code></pre>
<p>Just found a pretty good series on the basics of it: </p> <p><a href="http://capsizedesigns.com/blog/2008/05/getting-started-with-codeigniter-part-1/" rel="nofollow noreferrer">http://capsizedesigns.com/blog/2008/05/getting-started-with-codeigniter-part-1/</a> <a href="http://capsizedesigns.com/blog/2008/05/getting-started-with-codeigniter-part-2/" rel="nofollow noreferrer">http://capsizedesigns.com/blog/2008/05/getting-started-with-codeigniter-part-2/</a> <a href="http://capsizedesigns.com/blog/2008/05/getting-started-with-codeigniter-part-3/" rel="nofollow noreferrer">http://capsizedesigns.com/blog/2008/05/getting-started-with-codeigniter-part-3/</a></p>
21,317
<p>How can I turn off certificate revocation for a WCF service's client? The client proxy was generated by wsdl.exe and inherits SoapHttpClientProtocol.</p>
<p>I think you're looking for <code>ServicePointManager.ServerCertificateValidationCallback</code>:</p> <blockquote> <p><a href="http://msdn.microsoft.com/en-gb/library/system.net.servicepointmanager.servercertificatevalidationcallback.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-gb/library/system.net.servicepointmanager.servercertificatevalidationcallback.aspx</a></p> </blockquote> <p>Which takes a <code>RemoteCertificateValidationCallback</code> Delegate:</p> <blockquote> <p><a href="http://msdn.microsoft.com/en-gb/library/system.net.security.remotecertificatevalidationcallback.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-gb/library/system.net.security.remotecertificatevalidationcallback.aspx</a></p> </blockquote> <p>I've never dealt with a revoked certificate before (I have hand to handle other issues such as expired SSL's), but I'm guessing you'd just do something like:</p> <pre><code>class Program { static void Main(string[] args) { ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(ValidateCertificate); // Do WCF calls... } public static bool ValidateCertificate(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors sslPolicyErrors) { if(sslPolicyErrors == SslPolicyErrors.RemoteCertificateChainErrors) { foreach(X509ChainStatus chainStatus in chain.ChainStatus) { if(chainStatus.Status == X509ChainStatusFlags.Revoked) { return true; } } } /* WARNING! You should perform other cert validation checks here and not blindly override your cert validation by returning true. Otherwise the secure channel between your client and service may not be secure. */ return false; } } </code></pre>
<p>You can set certificate validation and revocation options in the config file for your application:</p> <p><a href="http://www.request-response.com/blog/PermaLink,guid,e9bb929b-d0b4-4626-b302-1d2715fc344a.aspx" rel="nofollow noreferrer">http://www.request-response.com/blog/PermaLink,guid,e9bb929b-d0b4-4626-b302-1d2715fc344a.aspx</a></p>
24,979
<p>What is difference between <code>Server.Transfer</code> and <code>Response.Redirect</code>?</p> <ul> <li>What are advantages and disadvantages of each?</li> <li>When is one appropriate over the other?</li> <li>When is one not appropriate?</li> </ul>
<p><code>Response.Redirect</code> simply sends a message <a href="http://en.wikipedia.org/wiki/HTTP_302" rel="noreferrer">(HTTP 302)</a> down to the browser.</p> <p><code>Server.Transfer</code> happens without the browser knowing anything, the browser request a page, but the server returns the content of another. </p>
<p><strong>Response.Redirect</strong> Response.Redirect() will send you to a new page, update the address bar and add it to the Browser History. On your browser you can click back. It redirects the request to some plain HTML pages on our server or to some other web server. It causes additional roundtrips to the server on each request. It doesn’t preserve Query String and Form Variables from the original request. It enables to see the new redirected URL where it is redirected in the browser (and be able to bookmark it if it’s necessary). Response. Redirect simply sends a message down to the (HTTP 302) browser.</p> <p><strong>Server.Transfer</strong> Server.Transfer() does not change the address bar, we cannot hit back.One should use Server.Transfer() when he/she doesn’t want the user to see where he is going. Sometime on a "loading" type page. It transfers current page request to another .aspx page on the same server. It preserves server resources and avoids the unnecessary roundtrips to the server. It preserves Query String and Form Variables (optionally). It doesn’t show the real URL where it redirects the request in the users Web Browser. Server.Transfer happens without the browser knowing anything, the browser request a page, but the server returns the content of another.</p>
27,749
<p>My model is a keycap for mechanical keyboards. There is the cap itself, and a stem with a hole in the form of a cross, which fits the switches themselves.</p> <p><a href="https://i.stack.imgur.com/r0Xxb.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/r0Xxb.jpg" alt="Print at bottom, the other caps are reference"></a></p> <p><a href="https://i.stack.imgur.com/DkBxu.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DkBxu.jpg" alt="Bottom view"></a></p> <p>I print in the same position as it is intended to be used, top up. This means that the stem and the cap are not connected until quite a few print layers.</p> <p>To prevent the stem from falling off during the print (it has a small footprint), I created connectors in the first layers, to hold it in place. <a href="https://i.stack.imgur.com/MXDEn.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MXDEn.jpg" alt="enter image description here"></a></p> <p>The issue: it seems like all my prints have a rotation of the stem, compared to the cap. It probably rather is the cross-shaped hole, or its walls, that are not completely symmetrical. I do not think it is only the edges against the printing bed that are the cause, since I have trimmed them with a scalpel. The rotation is always in the same direction.</p> <p>The twist is detectable when watching the keycap with the switch, and more so with keycaps on switches on a keyboard plate (you can see that the edges of the caps do not align. They do in my CAD program): <a href="https://i.stack.imgur.com/0aJ5S.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0aJ5S.jpg" alt="Bottom view with switch"></a> <a href="https://i.stack.imgur.com/nvUvU.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nvUvU.jpg" alt="enter image description here"></a></p> <p>I use Cura as my slicer, layer height 0.06 mm, and ABS. I attempted a slow print (30 mm/s), which didn't help.</p> <p>The first work-around that comes to mind is to measure the twist and compensate for that in my model. But I believe that since the problem is in the printing process, the problem would best be solved in the slicer.</p> <p>What could possibly be the issue? Is there an option is Cura to compensate for this? Short of the work-around mentioned above, what are other steps I should look into?</p>
<h2>This looks like a shift rather than a twist.</h2> <p>Looking closely at the "+" opening, it doesn't look as much twisted as it looks as if the top and bottom halves are sheared, with the top half shifted slightly right and the bottom shifted slightly left. The horizontal part of the plus seems aligned on the left and right halves.</p> <p>When you press-fit the keycaps, you will "average" the displacement forces and the keycap will twist.</p> <p>I am suspicious of a backlash problem in the X axis (left to right). Perhaps the belt isn't tight enough, or some part shifts differently. It could be in the rails, the belt, a loose drive pulley, the hot end being slightly loose on the carriage, or any uncontrolled movement. It could be a high-friction x-axis which causes spring wind-up in the drive system.</p> <p>I recommend carefully examining the printer for any excess friction or movement, and taking action to fix that first before tweaking the model to compensate for what can not be fixed.</p> <h2>If it is a twist, use more cooling.</h2> <p>If the photos have misled me, and the vertical "+" shaft if actually twisting, you may need to use higher cooling. The drag of the filament as the head traces the perimeter can create a torque on the shaft, and if the plastic is not sufficiently cooled it could be dragged around. I consider this more of a theoretical problem than a real one, and have not yet seen it in practice.</p> <h2>This is a beautiful design</h2> <p>This is a wonderful application of 3D printing. With a multi-material printer it would be tempting to label the keys similar to old-style multi-shot keycaps.</p>
<p>Another possibility is that those connectors you put in are pulling the cross-pattern off-center. Is there enough height that you could specify supports in that area instead? If so I'd recommend a brim "everywhere" to help stabilize the supports under the centerpost. </p> <p>If there is sufficient clearance in the mechanism itself, consider expanding the diameter of the post (not the cross itself) to increase stability as the print is in progress. </p>
1,597
<p>I was listening to <a href="http://itc.conversationsnetwork.org/shows/detail3798.html" rel="nofollow noreferrer">a podcast</a>. Where they talked about principles Toyota was using:</p> <blockquote> <p>Never do anything until you are ready to use it.</p> </blockquote> <p>I think this tells us to look in other places, to learn what other practices have been known for years.</p>
<p>It <em>may</em> apply to software construction, but I am not sure it <em>does</em> apply</p> <p>If we consider the five elements in a "<a href="http://malvasiabianca.org/archives/2008/05/the-toyota-way-and-nemawashi/" rel="nofollow noreferrer">toyota-way of decision making</a>", based on the principle that "how you arrive at the decision is just as important as the quality of the decision":</p> <p>[mode humour ON]</p> <ul> <li><p>Finding out what is really going on, including genchi gembutsu. </p> <blockquote> <p>Except that sometime, one does finally understand what is going on when the client explain to us at the end of the project;) <img src="https://i.stack.imgur.com/V6AjD.gif" alt="PM_Build_Swing"></p> </blockquote></li> <li><p>Understanding underlying causes that explain surface appearances—asking “Why?” five times.</p> <blockquote> <p>Sure but the client is not available enough during the project ;)</p> </blockquote></li> <li><p>Broadly considering alternative solutions and developing a detailed rationale for the preferred solution.</p> <blockquote> <p>Too late, the programmers are already coding like madmen :)</p> </blockquote></li> <li><p>Building consensus within the team, including Toyota employees and outside partners.</p> <blockquote> <p>Oops that programmer is already re-writing the authentification system even though the old one was working fine</p> </blockquote></li> <li><p>Using very efficient communication vehicles to do one through four, preferably one side of one sheet of paper.</p> <blockquote> <p>Did you hear "death by powerpoint" ? This is not always our strong suit ;) <img src="https://i.stack.imgur.com/M5XAQ.jpg" alt="Death by PowerPoint"></p> </blockquote></li> </ul> <p>[mode humour OFF]</p> <p>Seriously, as stated by the previous answers, the Agile philosophy does address some of the core tenants of this Toyota principle.</p> <p>And it may be a little richer that just "You Ain't Gonna Need It", as described in the book "<a href="http://malvasiabianca.org/archives/2008/05/the-toyota-way-and-nemawashi/" rel="nofollow noreferrer">The Toyota way</a>"</p>
<p>It is a good agile practice to think just like that. There is also something called Test-Driven-Development, that helps you get software without bugs (almost), but also have that side effect that NOTHING is implemented that you don't use.</p> <p>A example is you're own collection class. If you only are needing a Add method, and a ToArray method, then why use the time to implement the Remove and Count methods?</p> <p>So yep. Follow that principle :)</p>
13,602
<p>Working on a new back end system for my company, and one of their requests is for a window to become locked down and for the user to be sent to the login screen if they leave it idle for to long.</p> <p>I figure I'd do this with JavaScript by attaching listeners to clicks, mouse moves and key-ups but I worry about messing with other scripts.</p> <p>Any suggestions? ­­­­­­­­­­­­­­­­­­­­­­­­­­</p>
<p>If you are wondering why you should use windbg over Visual Studio, then you need to read <a href="https://rads.stackoverflow.com/amzn/click/com/0321374460" rel="noreferrer" rel="nofollow noreferrer">Advanced Windows Debugging</a>. Any time you need to debug a truly ugly problem windbg has better technology to do it with than Visual Studio. Windbg has a more powerful scripting language and allows you to write DLLs to automate difficult problems. It will install gflags.exe, which gives you better control over the heap for debugging memory overwrites. </p> <p>You don't actually need to run the install, you can just copy the files over and be ready to go. Also it installs adsplus.vb, so you can take mini-dumps of running processes. It is also very easy to setup to perform remote debugging. There is nothing better than being able to debug a problem from your own desk instead of fighting the 15" monitor that flickers on a test PC. </p> <p>For day to day code writing I use Visual Studio, but once you need to start debugging problems from other computers or find yourself in a very ugly situation, windbg is the only way to go. Spending some time learning windbg is a great investment. Also if you look at crash dumps there are two great resources, <a href="http://www.dumpanalysis.org/blog" rel="noreferrer">http://www.dumpanalysis.org/blog</a> and <a href="http://blogs.msdn.com/ntdebugging/default.aspx" rel="noreferrer">http://blogs.msdn.com/ntdebugging/default.aspx</a> that do all their debugging using windbg. </p>
<p>I always liked the watch and trace feature: 'wt' -> It prints to the output window all the function calls as they happen. That was pretty cool stuff!</p>
13,074
<p>I have a .NET WinForms textbox for a phone number field. After allowing free-form text, I'd like to format the text as a "more readable" phone number after the user leaves the textbox. (Outlook has this feature for phone fields when you create/edit a contact)</p> <ul> <li>1234567 becomes 123-4567</li> <li>1234567890 becomes (123) 456-7890</li> <li>(123)456.7890 becomes (123) 456-7890</li> <li>123.4567x123 becomes 123-4567 x123</li> <li>etc</li> </ul>
<p>A fairly simple-minded approach would be to use a regular expression. Depending on which type of phone numbers you're accepting, you could write a regular expression that looks for the digits (for US-only, you know there can be 7 or 10 total - maybe with a leading '1') and potential separators between them (period, dash, parens, spaces, etc.).</p> <p>Once you run the match against the regex, you'll need to write the logic to determine what you actually got and format it from there.</p> <p>EDIT: Just wanted to add a very basic example (by no means is this going to work for all of the examples you posted above). Geoff's suggestion of stripping non-numeric characters might help out a bit depending on how you write your regex.</p> <pre><code>Regex regex = new Regex(@"(?&lt;areaCode&gt;([\d]{3}))?[\s.-]?(?&lt;leadingThree&gt;([\d]{3}))[\s.-]?(?&lt;lastFour&gt;([\d]{4}))[x]?(?&lt;extension&gt;[\d]{1,})?"); string phoneNumber = "701 123-4567x324"; Match phoneNumberMatch = regex.Match(phoneNumber); if(phoneNumberMatch.Success) { if (phoneNumberMatch.Groups["areaCode"].Success) { Console.WriteLine(phoneNumberMatch.Groups["areaCode"].Value); } if (phoneNumberMatch.Groups["leadingThree"].Success) { Console.WriteLine(phoneNumberMatch.Groups["leadingThree"].Value); } if (phoneNumberMatch.Groups["lastFour"].Success) { Console.WriteLine(phoneNumberMatch.Groups["lastFour"].Value); } if (phoneNumberMatch.Groups["extension"].Success) { Console.WriteLine(phoneNumberMatch.Groups["extension"].Value); } } </code></pre>
<p>I don't know of any way other than doing it yourself by possibly making some masks and checking which one it matches and doing each mask on a case by case basis. Don't think it'd be too hard, just time consuming.</p>
22,912
<p>I'm pretty keen to develop my first Ruby app, as my company has finally blessed its use internally.</p> <p>In everything I've read about Ruby up to v1.8, there is never anything positive said about performance, but I've found nothing about version 1.9. The last figures I saw about 1.8 had it drastically slower than just about everything out there, so I'm hoping this was addressed in 1.9.</p> <p>Has performance drastically improved? Are there some concrete things that can be done with Ruby apps (or things to avoid) to keep performance at the best possible level?</p>
<p>There are some benchmarks of 1.8 vs 1.9 at <a href="http://www.rubychan.de/share/yarv_speedups.html" rel="nofollow noreferrer">http://www.rubychan.de/share/yarv_speedups.html</a>. Overall, it looks like 1.9 is a lot faster in most cases.</p>
<p>I'd second the recommendation of the use of Passenger - it makes deployment and management of Rails applications trivial</p>
4,551
<p>I have a Visual Studio Solution. Currently, it is an empty solution (=no projects) and I have added a few solution folders.</p> <p>Solution Folders only seem to be "virtual folders", because they are not really created in the Filesystem and files inside solution folders are just sitting in the same folder as the .sln file.</p> <p>Is there a setting that i've overlooked that tells Visual Studio to treat Solution Folders as "real" folders, that is to create them in the file system and move files into it when I move them inside the solution into one of those folders?</p> <p><strong>Edit:</strong> Thanks. Going to make a suggestion for VS2010 then :)</p>
<p>No special setting. I don't think it's supported.</p> <p>You can create real folders in a "project" within the solution, but not in the solution itself.</p>
<p>The folder created underneath the solution will be virtual as said. Maybe this might be called a workaround but you can physically create the folder on disk either before or when you add new item/project and Robert should be a sibling of your dad.</p> <p>ps- on closer look maybe i should explain "bob's your uncle" means your fine/sorted.</p>
33,511
<p>I'm drawing old school (unthemed - themed radios are a whole other problem) radio buttons myself using DrawFrameControl:</p> <pre><code>DrawFrameControl(dc, &amp;rectRadio, DFC_BUTTON, isChecked() ? DFCS_BUTTONRADIO | DFCS_CHECKED : DFCS_BUTTONRADIO); </code></pre> <p>I've never been able to figure out a sure fire way to figure out what to pass for the RECT. I've been using a 12x12 rectangle but I'de like Windows to tell me the size of a radio button.</p> <p>DrawFrameControl seems to scale the radio button to fit the rect I pass so I have to be close to the "right" size of the radio looks off from other (non-owner drawn) radios on the screen.</p> <p>Anyone know how to do this? </p>
<p>It has been a while since I worked on this, so what I am describing is what I did, and not necessarily a direct answer to the question.</p> <p>I happen to use bit maps 13 x 13 rather than 12 x 12. The bitmap part of the check box seems to be passed in the WM_DRAWITEM. However, I had also set up WM_MEASUREITEM and fed it the same values, so my answer may well be "Begging the question" in the correct philosophical sense.</p> <pre> case WM_MEASUREITEM: lpmis = (LPMEASUREITEMSTRUCT) lParam; lpmis->itemHeight = 13; lpmis->itemWidth = 13; break; case WM_DRAWITEM: lpdis = (LPDRAWITEMSTRUCT) lParam; hdcMem = CreateCompatibleDC(lpdis->hDC); if (lpdis->itemState & ODS_CHECKED) // if selected { SelectObject(hdcMem, hbmChecked); } else { if (lpdis->itemState & ODS_GRAYED) { SelectObject(hdcMem, hbmDefault); } else { SelectObject(hdcMem, hbmUnChecked); } } StretchBlt( lpdis->hDC, // destination DC lpdis->rcItem.left, // x upper left lpdis->rcItem.top, // y upper left // The next two lines specify the width and // height. lpdis->rcItem.right - lpdis->rcItem.left, lpdis->rcItem.bottom - lpdis->rcItem.top, hdcMem, // source device context 0, 0, // x and y upper left 13, // source bitmap width 13, // source bitmap height SRCCOPY); // raster operation DeleteDC(hdcMem); return TRUE; </pre> <p>This seems to work well for both Win2000 and XP, though I have nbo idea what Vista might do.</p> <p>It might be worth an experiment to see what leaving out WM_MEASUREITEM does, though I usually discover with old code that I usually had perfectly good reason for doing something that looks redundant.</p>
<p>It has been a while since I worked on this, so what I am describing is what I did, and not necessarily a direct answer to the question.</p> <p>I happen to use bit maps 13 x 13 rather than 12 x 12. The bitmap part of the check box seems to be passed in the WM_DRAWITEM. However, I had also set up WM_MEASUREITEM and fed it the same values, so my answer may well be "Begging the question" in the correct philosophical sense.</p> <pre> case WM_MEASUREITEM: lpmis = (LPMEASUREITEMSTRUCT) lParam; lpmis->itemHeight = 13; lpmis->itemWidth = 13; break; case WM_DRAWITEM: lpdis = (LPDRAWITEMSTRUCT) lParam; hdcMem = CreateCompatibleDC(lpdis->hDC); if (lpdis->itemState & ODS_CHECKED) // if selected { SelectObject(hdcMem, hbmChecked); } else { if (lpdis->itemState & ODS_GRAYED) { SelectObject(hdcMem, hbmDefault); } else { SelectObject(hdcMem, hbmUnChecked); } } StretchBlt( lpdis->hDC, // destination DC lpdis->rcItem.left, // x upper left lpdis->rcItem.top, // y upper left // The next two lines specify the width and // height. lpdis->rcItem.right - lpdis->rcItem.left, lpdis->rcItem.bottom - lpdis->rcItem.top, hdcMem, // source device context 0, 0, // x and y upper left 13, // source bitmap width 13, // source bitmap height SRCCOPY); // raster operation DeleteDC(hdcMem); return TRUE; </pre> <p>This seems to work well for both Win2000 and XP, though I have nbo idea what Vista might do.</p> <p>It might be worth an experiment to see what leaving out WM_MEASUREITEM does, though I usually discover with old code that I usually had perfectly good reason for doing something that looks redundant.</p>
8,703
<p>I am using an ancient version of Oracle (8.something) and my ADO.NET application needs to do some fairly large transactions. Large enough to not fin in our small rollback segments. Now we have a large rollback segment as well but it is not used by default.</p> <p>Oracle has a command to select the rollback segment to be used (<code>SET TRANSACTION USE ROLLBACK SEGMENT MY_ROLLBACK_SEGMENT</code>) but it needs to be the first command issued in the transaction. Unfortunately, it seems that ADO.NET issues some other commands at the beginning of a transaction since issuing this command right after .BeginTransaction() throws an error about SET TRANSACTION not being the first command.</p> <p>I am sure I am not the only one who faced this issue. How do you solve it or how would you get around it?</p> <p>Thanks</p>
<p>If this is a 'one-off' requirement then one solution is to put the other rollback segments offline while you run your transactions then put them online when you've finished;</p> <pre><code>ALTER ROLLBACK SEGMENT &lt;name&gt; OFFLINE; ALTER ROLLBACK SEGMENT &lt;name&gt; ONLINE; </code></pre> <p>Otherwise make all the rollback segments the same size.</p>
<p>I have absolutely no way of testing this, but you could try issuing a save point before your set transaction statement, e.g.</p> <blockquote> <p>SAVEPOINT use_big_rbs;</p> <p>SET TRANSACTION USE ROLLBACK SEGMENT big_rbs;</p> <p>UPDATE ...</p> <p>...</p> </blockquote>
36,616
<p>I'm trying to make a data bound column invisible after data binding, because it won't exist before data binding. However, the DataGrid.Columns collection indicates a count of 0, making it seem as if the automatically generated columns don't belong to the collection.</p> <p>How can I make a column that is automatically generated during binding invisible?</p>
<p>You have to add code to the line item rendering code and set the visibility of that column to false. Even though its bound, the event will be fired for each record and you can manipulate the output.</p>
<p>The only way to do this I know of since it's created on the fly is to hide the cell, here's an example you can adapt:</p> <pre><code>protected void GridView_RowCreated(object sender, GridViewRowEventArgs e) { e.Row.Cells[1].Visible = false; } </code></pre>
11,748
<p>What steps do I need to take to get HTML documentation automatically building via the build step in Visual Studio? I have all the comments in place and the comments.xml file being generated, and Sandcastle installed. I just need to know what to add to the post-build step in order to generate the docs.</p>
<p>Some changes have been made since this question was asked. Sandcastle no longer includes <code>SandcastleBuilderConsole.exe</code>. Instead it uses plain old <code>MSBuild.exe</code>.</p> <p>To integrate this with visual studio here is what I did:</p> <p>Place this in your Post-build event:</p> <pre><code>IF "$(ConfigurationName)"=="Release" Goto Exit "$(SystemRoot)\microsoft.net\framework64\v4.0.30319\msbuild.exe" /p:CleanIntermediates=True /p:Configuration=Release "$(SolutionDir)ProjectName\doc\DocumentationProjectName.shfbproj" :Exit </code></pre> <p>This will cause visual studio to build your documentation, only when you build in "Release" mode. That way you aren't waiting forever when you build in "Debug" mode during development.</p> <p>A couple notes:</p> <ul> <li><p>My system is 64-bit, if yours is not then replace <code>framework64</code> with <code>framework</code> in the path to <code>msbuild.exe</code>.</p></li> <li><p>The way I have it setup is to document each project in my solution individually. If you have a "Sandcastle Help File Builder" project file which includes several projects together, then you probably want to get rid of <code>ProjectName\</code> and move <code>doc</code> into the solution directory. In this case you will want to only put the Post-build event commands on the project that is built LAST in your solution. If you put it in the Post-build event for every project then you will be rebuilding your documentation for each project that is built. Needless to say, you'll be sitting there a while. Personally I prefer to document each project individually, but that's just me.</p></li> </ul> <p><strong>Installing Sandcastle and "Sandcastle Help File Builder".</strong></p> <p>If you don't know how to get Sandcastle and "Sandcastle Help File Builder" setup correctly, then follow these steps:</p> <ol> <li><p>Download and install Sandcastle from <a href="http://sandcastle.codeplex.com/" rel="noreferrer">http://sandcastle.codeplex.com/</a> (if you have a 64 bit system, you will need to add an environment variable. The instructions are <a href="http://sandcastle.codeplex.com/wikipage?title=How%20to:%20Install%20Sandcastle&amp;referringTitle=Introduction" rel="noreferrer">here</a>.</p></li> <li><p>Download and install "Sandcastle Help File Builder" from <a href="http://shfb.codeplex.com/" rel="noreferrer">http://shfb.codeplex.com/</a> (ignore warnings about MSHelp2 if you get any. You won't be needing it.)</p></li> <li><p>Once you have those installed then use "Sandcastle Help File Builder" to create a new documentation project. When it asks you where to save the file, save it in the documentation folder you have in your solution/project. <a href="http://www.chevtek.com/Temp/NewProject.jpg" rel="noreferrer">http://www.chevtek.com/Temp/NewProject.jpg</a></p></li> <li><p>After creating a new project you'll need to choose which kind of documentation you want to create. A compiled windows help file, a website, or both. <a href="http://www.chevtek.com/Temp/DocumentationType.jpg" rel="noreferrer">http://www.chevtek.com/Temp/DocumentationType.jpg</a></p></li> <li><p>If you saved the SHFB project file in the directory where you want your documentation to be generated then you can skip this step. But if you want the generated documentation to be placed elsewhere then you need to adjust the output path. <a href="http://www.chevtek.com/Temp/OutputPath.jpg" rel="noreferrer">http://www.chevtek.com/Temp/OutputPath.jpg</a> NOTE: One thing to keep in mind about the output path (which frustrated me for an hour) is that when you have website checked as the type of documentation you want, it will overwrite content in its output path. What they neglect to tell you is that SHFB purposely restricted certain folders from being included as part of the output path. Desktop is one such folder. Your output path cannot be on the desktop, not even a sub-folder of desktop. It can't by My Documents either, but it CAN be a subfolder of my documents. If you get errors when building your documentation, try changing the output path and see if that fixes it. See <a href="http://shfb.codeplex.com/discussions/226668?ProjectName=shfb" rel="noreferrer">http://shfb.codeplex.com/discussions/226668?ProjectName=shfb</a> for details on this.</p></li> <li><p>Finally, you will need to add a reference to the project you want to document. If you are doing individual projects like I do, then for each SHFB project file you create, you will reference the corresponding .CSPROJ file. If you have one SHFB project for your entire solution, then you would find the .SLN file for your solution. (sandcastle also works if you reference the compiled DLLs, but since you're integrating it with Visual Studio I find it makes more sense to reference the project/solution files instead. This may also mean that it really doesn't matter which project you do the post-build event on since it's referencing the code instead of the DLLs, but it's better to be safe and put it on the last project that's built) <a href="http://www.chevtek.com/Temp/AddSource.jpg" rel="noreferrer">http://www.chevtek.com/Temp/AddSource.jpg</a></p></li> <li><p>Save the project and you can close "Sandcastle Help File Builder". Now all is setup. Just be sure to put the documentation project file in the appropriate folder that the batch commands point to in the Post-build event.</p></li> </ol> <p>I hope my short tutorial helps you out! It was very hard for me to find any decent tutorials showing me how to use sandcastle, let alone how to integrate it with visual studio. Hopefully future google searches will turn up this question.</p>
<p>I must admit that I find the current version of Sandcastle a bit lacking; for large projects it is quite slow, and it isn't easy to integrate (since it is still early).</p> <p>For regular use, I actually find it easier just to point reflector at a folder with the dll and xml files - IIRC, it will load the xml file(s) as you navigate around.</p> <p>Plus I almost always have reflector open anyway...</p> <p>[edit] checked, and yes - xml comments show in the disassembler panel</p>
26,018
<p>I'm trying to increase the timeout on all sessions. The site is hosted with Godaddy, and it is written in Flash (client side of course) and asp.net on the backend. I've added this to my web.config, </p> <pre><code>&lt;sessionState timeout="720"&gt; &lt;/sessionState&gt; </code></pre> <p>Is that really all that I need to do? I'd prefer to not let sessions expire ever, but I'm sure that the server needs to reclaim that memory at some point...I'm not storing anything in the session, really, just using it to track users' progress through the site, and if a user is logged in or not.</p> <p>Thanks for any pointers...all the documentation seems deceptively simple, and it kind of makes me nervous...</p>
<p>Yup! As in; Yes, that's the only thing you need to do...</p> <p>To get "never ending timeouts" you'd have to create a background HTTP request (which will transmit the session cookie) back to the server every 719 minute though. Though theoretically then you'd also have to have "Out of Process" sessions using e.g. some sort of database or something...</p> <p>Or you could roll your own session handler, I think APS.NET have support for this through using some sort of adapter pattern or something, but I am not sure. Then you could have a "truly" never ending session...</p>
<p>If you are using Forms Authentication you will also need to set the Forms Authentication Timeout in your web.config</p> <p>Example:</p> <pre><code>&lt;authentication mode="Forms"&gt; &lt;forms name=".ASPXAUTH" loginUrl="/Home/Default.aspx" defaultUrl="/Dashboard/Default.aspx" protection="All" timeout="30" slidingExpiration="true" /&gt; &lt;/authentication&gt; </code></pre>
40,822
<p>So our web server apps need to connect to the database, and some other apps have startup scripts that execute at boot time.</p> <p>What's the best way to store the name/password for these applications, in terms of</p> <ul> <li>security, e.g. perhaps we don't want sysadmins to know the database password</li> <li>maintainability, e.g. making the configuration easy to change when the password changes, etc.</li> </ul> <p>both windows and linux solutions appreciated!</p>
<p>The best way to secure your password is to stop using one. Use a trusted connection: <a href="http://msdn.microsoft.com/en-us/library/ms998292.aspx" rel="nofollow noreferrer">How To: Connect to SQL Server Using Windows Authentication in ASP.NET 2.0</a>. Then you have nothing to hide - publish your web.config and source to the world, they still can't hit your database.</p> <p>If that won't work for you, use the built in <a href="http://msdn.microsoft.com/en-us/magazine/cc163614.aspx" rel="nofollow noreferrer">configuration encryption system in ASP.NET</a>.</p>
<p>You can bake a symmetric encryption key into your binary, and have that binary read an encrypted username/password from a file on disk when it starts up. </p> <p>However, this is not really much more than obfuscation, since your code is likely to be stored in some source repository somewhere. </p> <p>I would suggest that you would be better served to control access to your servers both physically and over the network using a firewall and a private network bubble, and store the passwords in the clear (or base-64 encoded) on disk with permissions locked down to the run user for your web app.</p> <p>You can also lock down the database server to only accept connections from your web app machines by IP.</p> <p>Ultimately, your problem is that the key (your DB username/password pair) needs to be available for programmatic, unattended use by your web apps.</p>
3,191
<p>After being troubled by <a href="http://blogs.cozi.com/tech/2008/03/transparent-png.html" rel="noreferrer">an issue</a> that I simply did not have the knowledge to debug, I've just decided that I <em>have</em> to learn how to use Windbg. My only problem: I have no clue where to start :-( I'm not really a WinApi-Guy, having use languages that abstract the Windows Api away from me usually.</p> <p>So I just wonder: What is the best souce (Book, Website) to learn Windbg for someone who knows programming but not much about the inner depths of Windows? (And yes, I do read oldnewthing every day :))</p>
<p>For a book, try</p> <p><a href="https://rads.stackoverflow.com/amzn/click/com/0321374460" rel="nofollow noreferrer" rel="nofollow noreferrer">Advanced Windows Debugging (Addison-Wesley Microsoft Technology Series)</a></p> <p><a href="https://i.stack.imgur.com/27qDU.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/27qDU.jpg" alt="Advanced Windows Debugging"></a><br> <sub>(source: <a href="http://knowfree.net/wp-content/uploads/2008/02/032137446001l.jpg" rel="nofollow noreferrer">knowfree.net</a>)</sub> </p> <p>Also, for a great reference sheet, see</p> <p><a href="http://windbg.info/doc/1-common-cmds.html" rel="nofollow noreferrer">Common WinDbg Commands (Thematically Grouped)</a> by Robert Kuster.</p>
<p><a href="https://rads.stackoverflow.com/amzn/click/com/0735622027" rel="nofollow noreferrer" rel="nofollow noreferrer">Debugging .NEt Applications</a> has a chapter on how to use WinDbg</p>
16,746
<p>I´ve been using my Ender 3 Pro for almost 1 year now. Always using the provided SD card. For a couple of days, the printed does not read any new file that I load to the SD card, but it does with the older files (and it then prints correctly as well).</p> <p>I tried deleting some old files that I don't need, I tried turning it on with the SD card, I tried inserting the card after turning the printer on. It's always the same.</p> <p>I am using another SD card and it works properly.</p> <p>Any idea?</p>
<p>I think I found the problem. I think there was some crosstalk between the BLTouch wires and the other wires it was tied together leading to the hotend. When I moved the BLTouch wires away from the others the problem went away.</p> <p>I will be added a sheild to the cable in the future like in this <a href="https://www.youtube.com/watch?v=jkcrRCxPlZM&amp;ab_channel=509Drone" rel="nofollow noreferrer">youtube video</a></p>
<p>The OP already found the problem and <a href="/a/16632/">answered</a> the question hinting to shielding of the cable. If this is the actual problem, of fiddling with the cables might have caused this, an alternative solution is presented as I've experienced similar behavior.</p> <p>If one side of the bed is higher than the rest, even when rotating the glass bed, you might experience that the nozzle carriage is tilting on that side. E.g. when using a Bowden extruder assembly, a too short Bowden tube (or cables in a non-Bowden setup) the tube (or cables) pull at the carriage causing it to lift at the furthest points from the extruder; this tilting can cause the nozzle to go up a few tenths of a millimeter.</p>
1,969
<p>In javascript, I've got a block of HTML like this:</p> <pre><code>&lt;h2&gt;{title}&lt;/h2&gt; &lt;p&gt;&lt;a href="{url}"&gt;{content}&lt;/a&gt;&lt;/p&gt; </code></pre> <p>And I'm trying use regex "match" to spit out an array of all the {item}'s. So my output should look like:</p> <pre><code>['title', 'url', 'content'] </code></pre> <p>I've gotten as far as:</p> <pre><code>var pattern = new RegExp("\{[a-zA-Z]+\}+"); var match = pattern.exec("{Sample} bob {text}"); </code></pre> <p>But it's only returning the first tag. </p> <p>This is just beyond my regex skills. Can anyone help?</p> <p>Cheers!</p>
<p>You need to create a pattern with the global flag:</p> <pre><code>var pattern = new RegExp("\{[a-zA-Z]+\}", "g"); </code></pre> <p>or:</p> <pre><code>var pattern = /\{[a-zA-Z]+\}/g; </code></pre> <p>Then you can call the match() method on your string to get a list of matches:</p> <pre><code>var matches = "{Sample} bob {text}".match(pattern); </code></pre>
<p>I got off path by using <code>exec</code> for testing.</p>
37,881
<p>What are you guys using as reporting engine in .net, <strong>with end user designing capabilities</strong>?</p> <p>I tried DevExpress XtraReports, but i am not able to successfully achieve consistent results. (for example, i try to display a detailreport of sold machines for a certain contact -> first field works fine, other fields don't; no data in them. no matter what i do) That kind of inexplicable behavior is not really tolerated in an enterprise environment, so i'm curious what the other solutions are...</p> <p>Update: It should be noted that the emphasis is on the end user designer part here. The customer should be able to modify the layout and fields (within limits) of the reports, without extensive IT knowledge.</p>
<p>SQL server Reporting services for any dynamic reports generated or Report builder for adhoc reports.</p>
<p>Please take a look at <a href="http://www.windwardstudios.com/" rel="nofollow noreferrer">Windward Reports</a>. With Windward you design the reports in Microsoft Word, Excel, or PowerPoint - so no learning curve for your end users. (Disclaimier - I'm the CTO at Windward.)</p> <p>As to your issue of not getting data back in some fields, that is more likely an issue with the selects you have crafted - I have not heard of any reporting system dropping data and DevExpress in particular writes solid code.</p>
38,262
<p>I'm creating a table that looks something like this.</p> <pre><code>CREATE TABLE packages ( productCode char(2) , name nvarchar(100) , ... ) </code></pre> <p>How do I make sure the productCode is always one of two values <code>XJ</code> or <code>XD</code>?</p>
<pre><code>ALTER TABLE packages ADD CONSTRAINT constraintname CHECK (productCode in ('XJ', 'XD')) </code></pre>
<p>In this case it sounds like the valueset for ProductCode is pretty limited and that you don't expects it to grow in a foreseeable future, so I tend to agree with checkconstraint answers. However in most cases I would implement the foreign key solution as suggested by Mr. Grant as my customers has a nasty habit of changing their mind ( and the requirements as well ) about once a day. In that situation it is my expirence that the FK version is easier to maintain.</p>
28,570
<p>I've got a nice little class built that acts as a cache. Each item has an expiration TimeSpan or DateTime. Each time an attempt to access an item in the cache is made, the item's expiration is checked, and if it's expired, the item is removed from the cache and nothing is returned.</p> <p>That's great for objects that are accessed frequently, but if an item is put in the cache and never accessed again, it's never removed, even though it's expired.</p> <p>What's a good methodology for expiring such items from the cache?</p> <p>Should I have a background thread infinitely enumerating every item in the cache to check if it's expired?</p>
<p>The best code is no code. Use the ASP.NET cache instead. You can reference it as System.Web.HttpRuntime.Cache in any application, not just web applications.</p>
<p>You can implement an LRU (Least Recently Used) strategy, keep your items sorted by access time, when a new item is inserted into the cache <strong>and</strong> the cache is full you evicted the item that is last in that list. See <a href="http://en.wikipedia.org/wiki/Cache_algorithms" rel="nofollow noreferrer">Cache algorithms</a> at Wikipedia. </p> <p>If you want to expire immediately, i would still only do that when things are accessed. I.e. when the cache object is accessed and it's time has expired refetch it. </p>
17,094
<p>This is a contrived example, but lets say I have declared objects:</p> <pre><code>CustomObj fooObj; CustomObj barObj; CustomObj bazObj; </code></pre> <p>And I have an string array:</p> <pre><code>string[] stringarray = new string[] {"foo","bar","baz"}; </code></pre> <p>How can I programmatically access and instantiate those objects using the string array, iterating using something like a foreach:</p> <pre><code>foreach (string i in stringarray) { `i`Obj = new CustomObj(i); } </code></pre> <p>Hope the idea I'm trying to get across is clear. Is this possible in C#?</p>
<p>You need to be clear in your mind about the difference between an object and a variable. Objects themselves don't have names. Variable names are decided at compile-time. You can't access variables via an execution-time-determined name except via reflection.</p> <p>It sounds like you <em>really</em> just want a <code>Dictionary&lt;string, CustomObj&gt;</code>:</p> <pre><code>Dictionary&lt;string, CustomObj&gt; map = new Dictionary&lt;string, CustomObj&gt;(); foreach (string name in stringArray) { map[name] = new CustomObj(name); } </code></pre> <p>You can then access the objects using the indexer to the dictionary.</p> <p>If you're really trying to set the values of variables based on their name at execution time, you'll have to use reflection (see <a href="http://msdn.microsoft.com/en-us/library/system.type.getfield.aspx" rel="noreferrer">Type.GetField</a>). Note that this won't work for local variables.</p>
<p>This is possible using reflection if the variables are class member variables, but it's hideously slow for anything more than very specialized applications. I think if you detail what you're trying to do, we can better offer suggestions. There's very rarely a case where you should access a variable like you're doing.</p>
40,497
<p>The SQL Server Express 2008 setup allow you to assign different user account for each service. </p> <p>For a development environment, would you use a domain user, local user, NT Authority\NETWORK SERCVICE, NT Authority\Local System or some other account and why? </p>
<p><strong>Local System</strong> is not recommended, it is an administrator equivalent account and thus can lead to questionable coding that takes advantage of administrator privileges which would not be allowed in a production system since security conscious Admins/DBA's really don't like to run services as admin.</p> <p>Depending on if the server instance will need to access other domain resources or not should determine which type of low privilege account it should run under. </p> <p>If it does not need to access any (non-anonymous) domain resources than I normally create a unique local, low privilege account for it to run under in order to gain the additional security benefit of not having multiple services running in the same identity context. <a href="http://msdn.microsoft.com/en-us/library/ms143504%28v=sql.105%29.aspx" rel="noreferrer">Be aware that the Local Service account is not supported for the SQL Server or SQL Server Agent services.</a> </p> <p>If it does need to access non-anonymous domain resources then you have three options: </p> <ol> <li>Run as <strong><a href="http://msdn.microsoft.com/en-us/library/ms143504%28v=sql.105%29.aspx" rel="noreferrer">Network Service</a></strong> which is also a low privilege account but one that retains the computers network credentials. </li> <li>Run under a Local Service Account</li> <li>Run under a custom domain account with low local privileges. One advantage to running under the developers account is that it is easier to attach debuggers to processes in your own identity without compromising security so debugging is easier (since non-Admin accounts do not have the privilege to attach a debugger to another identities process by default). A disadvantage to using another domain account is the overhead of managing those accounts, especially since each service for each developer should ideally have unique credentials so you do not have any leaks if a developer were to leave.</li> </ol> <p>Most of what I tend to do does not require the service to access domain resources so I tend to use unique local low privilege accounts that I manage. I also run exclusively as a non-admin user (and have done so under XP SP2, Server 2003, Vista and Server 2008 with no major problems) so when I have cases where I need the service to access domain resources then I have no worries about using my own domain credentials (plus that way I don't have to worry the network admins about creating/maintaining a bunch of non-production domain identities).</p>
<p>Whatever it wants to use as default. Changing that is just asking for trouble later.</p>
8,915
<p>This snippet of Perl code in my program is giving the wrong result.</p> <pre><code>$condition ? $a = 2 : $a = 3 ; print $a; </code></pre> <p>No matter what the value of <code>$condition</code> is, the output is always 3, how come?</p>
<p>This is explained in the Perl <a href="http://perldoc.perl.org/perlop.html#Conditional-Operator" rel="noreferrer">documentation</a>.</p> <p>Because of Perl operator precedence the statement is being parsed as</p> <pre><code>($condition ? $a= 2 : $a ) = 3 ; </code></pre> <p>Because the ?: operator produces an assignable result, 3 is assigned to the result of the condition.</p> <p>When $condition is true this means ($a=2)=3 giving $a=3</p> <p>When $condition is false this means ($a)=3 giving $a=3</p> <p>The correct way to write this is</p> <pre><code>$a = ( $condition ? 2 : 3 ); print $a; </code></pre> <p>We got bitten by this at work, so I am posting here hoping others will find it useful.</p>
<p>One suggestion to Tithonium's answer above:</p> <p>If you are want to assign different values to the same variable, this might be better (the copy-book way): </p> <p>$a = ($condition) ? 2 : 3;</p>
3,047
<p>For example:</p> <pre><code>int a = 12; cout &lt;&lt; typeof(a) &lt;&lt; endl; </code></pre> <p>Expected output:</p> <pre><code>int </code></pre>
<p>C++11 update to a very old question: Print variable type in C++.</p> <p>The accepted (and good) answer is to use <code>typeid(a).name()</code>, where <code>a</code> is a variable name.</p> <p>Now in C++11 we have <code>decltype(x)</code>, which can turn an expression into a type. And <code>decltype()</code> comes with its own set of very interesting rules. For example <code>decltype(a)</code> and <code>decltype((a))</code> will generally be different types (and for good and understandable reasons once those reasons are exposed).</p> <p>Will our trusty <code>typeid(a).name()</code> help us explore this brave new world?</p> <p>No.</p> <p>But the tool that will is not that complicated. And it is that tool which I am using as an answer to this question. I will compare and contrast this new tool to <code>typeid(a).name()</code>. And this new tool is actually built on top of <code>typeid(a).name()</code>.</p> <p><strong>The fundamental issue:</strong></p> <pre><code>typeid(a).name() </code></pre> <p>throws away cv-qualifiers, references, and lvalue/rvalue-ness. For example:</p> <pre><code>const int ci = 0; std::cout &lt;&lt; typeid(ci).name() &lt;&lt; '\n'; </code></pre> <p>For me outputs:</p> <pre><code>i </code></pre> <p>and I'm guessing on MSVC outputs:</p> <pre><code>int </code></pre> <p>I.e. the <code>const</code> is gone. This is not a QOI (Quality Of Implementation) issue. The standard mandates this behavior.</p> <p>What I'm recommending below is:</p> <pre><code>template &lt;typename T&gt; std::string type_name(); </code></pre> <p>which would be used like this:</p> <pre><code>const int ci = 0; std::cout &lt;&lt; type_name&lt;decltype(ci)&gt;() &lt;&lt; '\n'; </code></pre> <p>and for me outputs:</p> <pre><code>int const </code></pre> <p><code>&lt;disclaimer&gt;</code> I have not tested this on MSVC. <code>&lt;/disclaimer&gt;</code> But I welcome feedback from those who do.</p> <p><strong>The C++11 Solution</strong></p> <p>I am using <code>__cxa_demangle</code> for non-MSVC platforms as recommend by <a href="https://stackoverflow.com/users/487362/ipapadop">ipapadop</a> in his answer to demangle types. But on MSVC I'm trusting <code>typeid</code> to demangle names (untested). And this core is wrapped around some simple testing that detects, restores and reports cv-qualifiers and references to the input type.</p> <pre><code>#include &lt;type_traits&gt; #include &lt;typeinfo&gt; #ifndef _MSC_VER # include &lt;cxxabi.h&gt; #endif #include &lt;memory&gt; #include &lt;string&gt; #include &lt;cstdlib&gt; template &lt;class T&gt; std::string type_name() { typedef typename std::remove_reference&lt;T&gt;::type TR; std::unique_ptr&lt;char, void(*)(void*)&gt; own ( #ifndef _MSC_VER abi::__cxa_demangle(typeid(TR).name(), nullptr, nullptr, nullptr), #else nullptr, #endif std::free ); std::string r = own != nullptr ? own.get() : typeid(TR).name(); if (std::is_const&lt;TR&gt;::value) r += &quot; const&quot;; if (std::is_volatile&lt;TR&gt;::value) r += &quot; volatile&quot;; if (std::is_lvalue_reference&lt;T&gt;::value) r += &quot;&amp;&quot;; else if (std::is_rvalue_reference&lt;T&gt;::value) r += &quot;&amp;&amp;&quot;; return r; } </code></pre> <p><strong>The Results</strong></p> <p>With this solution I can do this:</p> <pre><code>int&amp; foo_lref(); int&amp;&amp; foo_rref(); int foo_value(); int main() { int i = 0; const int ci = 0; std::cout &lt;&lt; &quot;decltype(i) is &quot; &lt;&lt; type_name&lt;decltype(i)&gt;() &lt;&lt; '\n'; std::cout &lt;&lt; &quot;decltype((i)) is &quot; &lt;&lt; type_name&lt;decltype((i))&gt;() &lt;&lt; '\n'; std::cout &lt;&lt; &quot;decltype(ci) is &quot; &lt;&lt; type_name&lt;decltype(ci)&gt;() &lt;&lt; '\n'; std::cout &lt;&lt; &quot;decltype((ci)) is &quot; &lt;&lt; type_name&lt;decltype((ci))&gt;() &lt;&lt; '\n'; std::cout &lt;&lt; &quot;decltype(static_cast&lt;int&amp;&gt;(i)) is &quot; &lt;&lt; type_name&lt;decltype(static_cast&lt;int&amp;&gt;(i))&gt;() &lt;&lt; '\n'; std::cout &lt;&lt; &quot;decltype(static_cast&lt;int&amp;&amp;&gt;(i)) is &quot; &lt;&lt; type_name&lt;decltype(static_cast&lt;int&amp;&amp;&gt;(i))&gt;() &lt;&lt; '\n'; std::cout &lt;&lt; &quot;decltype(static_cast&lt;int&gt;(i)) is &quot; &lt;&lt; type_name&lt;decltype(static_cast&lt;int&gt;(i))&gt;() &lt;&lt; '\n'; std::cout &lt;&lt; &quot;decltype(foo_lref()) is &quot; &lt;&lt; type_name&lt;decltype(foo_lref())&gt;() &lt;&lt; '\n'; std::cout &lt;&lt; &quot;decltype(foo_rref()) is &quot; &lt;&lt; type_name&lt;decltype(foo_rref())&gt;() &lt;&lt; '\n'; std::cout &lt;&lt; &quot;decltype(foo_value()) is &quot; &lt;&lt; type_name&lt;decltype(foo_value())&gt;() &lt;&lt; '\n'; } </code></pre> <p>and the output is:</p> <pre><code>decltype(i) is int decltype((i)) is int&amp; decltype(ci) is int const decltype((ci)) is int const&amp; decltype(static_cast&lt;int&amp;&gt;(i)) is int&amp; decltype(static_cast&lt;int&amp;&amp;&gt;(i)) is int&amp;&amp; decltype(static_cast&lt;int&gt;(i)) is int decltype(foo_lref()) is int&amp; decltype(foo_rref()) is int&amp;&amp; decltype(foo_value()) is int </code></pre> <p>Note (for example) the difference between <code>decltype(i)</code> and <code>decltype((i))</code>. The former is the type of the <em>declaration</em> of <code>i</code>. The latter is the &quot;type&quot; of the <em>expression</em> <code>i</code>. (expressions never have reference type, but as a convention <code>decltype</code> represents lvalue expressions with lvalue references).</p> <p>Thus this tool is an excellent vehicle just to learn about <code>decltype</code>, in addition to exploring and debugging your own code.</p> <p>In contrast, if I were to build this just on <code>typeid(a).name()</code>, without adding back lost cv-qualifiers or references, the output would be:</p> <pre><code>decltype(i) is int decltype((i)) is int decltype(ci) is int decltype((ci)) is int decltype(static_cast&lt;int&amp;&gt;(i)) is int decltype(static_cast&lt;int&amp;&amp;&gt;(i)) is int decltype(static_cast&lt;int&gt;(i)) is int decltype(foo_lref()) is int decltype(foo_rref()) is int decltype(foo_value()) is int </code></pre> <p>I.e. Every reference and cv-qualifier is stripped off.</p> <p><strong>C++14 Update</strong></p> <p>Just when you think you've got a solution to a problem nailed, someone always comes out of nowhere and shows you a much better way. :-)</p> <p><a href="https://stackoverflow.com/a/35943472/576911">This answer</a> from <a href="https://stackoverflow.com/users/2969631/jamboree">Jamboree</a> shows how to get the type name in C++14 at compile time. It is a brilliant solution for a couple reasons:</p> <ol> <li>It's at compile time!</li> <li>You get the compiler itself to do the job instead of a library (even a std::lib). This means more accurate results for the latest language features (like lambdas).</li> </ol> <p><a href="https://stackoverflow.com/users/2969631/jamboree">Jamboree's</a> <a href="https://stackoverflow.com/a/35943472/576911">answer</a> doesn't quite lay everything out for VS, and I'm tweaking his code a little bit. But since this answer gets a lot of views, take some time to go over there and upvote his answer, without which, this update would never have happened.</p> <pre><code>#include &lt;cstddef&gt; #include &lt;stdexcept&gt; #include &lt;cstring&gt; #include &lt;ostream&gt; #ifndef _MSC_VER # if __cplusplus &lt; 201103 # define CONSTEXPR11_TN # define CONSTEXPR14_TN # define NOEXCEPT_TN # elif __cplusplus &lt; 201402 # define CONSTEXPR11_TN constexpr # define CONSTEXPR14_TN # define NOEXCEPT_TN noexcept # else # define CONSTEXPR11_TN constexpr # define CONSTEXPR14_TN constexpr # define NOEXCEPT_TN noexcept # endif #else // _MSC_VER # if _MSC_VER &lt; 1900 # define CONSTEXPR11_TN # define CONSTEXPR14_TN # define NOEXCEPT_TN # elif _MSC_VER &lt; 2000 # define CONSTEXPR11_TN constexpr # define CONSTEXPR14_TN # define NOEXCEPT_TN noexcept # else # define CONSTEXPR11_TN constexpr # define CONSTEXPR14_TN constexpr # define NOEXCEPT_TN noexcept # endif #endif // _MSC_VER class static_string { const char* const p_; const std::size_t sz_; public: typedef const char* const_iterator; template &lt;std::size_t N&gt; CONSTEXPR11_TN static_string(const char(&amp;a)[N]) NOEXCEPT_TN : p_(a) , sz_(N-1) {} CONSTEXPR11_TN static_string(const char* p, std::size_t N) NOEXCEPT_TN : p_(p) , sz_(N) {} CONSTEXPR11_TN const char* data() const NOEXCEPT_TN {return p_;} CONSTEXPR11_TN std::size_t size() const NOEXCEPT_TN {return sz_;} CONSTEXPR11_TN const_iterator begin() const NOEXCEPT_TN {return p_;} CONSTEXPR11_TN const_iterator end() const NOEXCEPT_TN {return p_ + sz_;} CONSTEXPR11_TN char operator[](std::size_t n) const { return n &lt; sz_ ? p_[n] : throw std::out_of_range(&quot;static_string&quot;); } }; inline std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, static_string const&amp; s) { return os.write(s.data(), s.size()); } template &lt;class T&gt; CONSTEXPR14_TN static_string type_name() { #ifdef __clang__ static_string p = __PRETTY_FUNCTION__; return static_string(p.data() + 31, p.size() - 31 - 1); #elif defined(__GNUC__) static_string p = __PRETTY_FUNCTION__; # if __cplusplus &lt; 201402 return static_string(p.data() + 36, p.size() - 36 - 1); # else return static_string(p.data() + 46, p.size() - 46 - 1); # endif #elif defined(_MSC_VER) static_string p = __FUNCSIG__; return static_string(p.data() + 38, p.size() - 38 - 7); #endif } </code></pre> <p>This code will auto-backoff on the <code>constexpr</code> if you're still stuck in ancient C++11. And if you're painting on the cave wall with C++98/03, the <code>noexcept</code> is sacrificed as well.</p> <p><strong>C++17 Update</strong></p> <p>In the comments below <a href="https://stackoverflow.com/users/3624760/lyberta">Lyberta</a> points out that the new <code>std::string_view</code> can replace <code>static_string</code>:</p> <pre><code>template &lt;class T&gt; constexpr std::string_view type_name() { using namespace std; #ifdef __clang__ string_view p = __PRETTY_FUNCTION__; return string_view(p.data() + 34, p.size() - 34 - 1); #elif defined(__GNUC__) string_view p = __PRETTY_FUNCTION__; # if __cplusplus &lt; 201402 return string_view(p.data() + 36, p.size() - 36 - 1); # else return string_view(p.data() + 49, p.find(';', 49) - 49); # endif #elif defined(_MSC_VER) string_view p = __FUNCSIG__; return string_view(p.data() + 84, p.size() - 84 - 7); #endif } </code></pre> <p>I've updated the constants for VS thanks to the very nice detective work by Jive Dadson in the comments below.</p> <h2>Update:</h2> <p>Be sure to check out <a href="https://stackoverflow.com/a/56766138/576911">this</a> rewrite or <a href="https://stackoverflow.com/a/64490578/576911">this</a> rewrite below which eliminate the unreadable magic numbers in my latest formulation.</p>
<p>Consider this code:</p> <pre><code>#include &lt;iostream&gt; int main() { int a = 2; // Declare type &quot;int&quot; std::string b = &quot;Hi&quot;; // Declare type &quot;string&quot; long double c = 3438; // Declare type &quot;long double&quot; if(typeid(a) == typeid(int)) { std::cout&lt;&lt;&quot;int\n&quot;; } if(typeid(b) == typeid(std::string)) { std::cout&lt;&lt;&quot;string\n&quot;; } if(typeid(c) == typeid(long double)) { std::cout&lt;&lt;&quot;long double&quot;; } return 0; } </code></pre> <p>I believe you want the whole word (rather than only printing the short form of <code>int</code> (which is <code>i</code>), you want <code>int</code>), that is why I did the <code>if</code>.</p> <p>For some of the variables (<code>string</code>,<code>long double</code> etc... which do not print the expected result comparing their short forms), you need to compare the result of applying the <code>typeid</code> operator with the <code>typeid</code> of a specific type.</p> <p>From cppreference:</p> <blockquote> <p>Returns an implementation defined null-terminated character string containing the name of the type. No guarantees are given; in particular, the returned string can be identical for several types and change between invocations of the same program.</p> </blockquote> <hr> <p>IMO, Python is better than C++ in this case. Python has built-in <code>type</code> function to directly access the data type of the variable.</p>
10,757
<p>I know how they are different syntactically, and that C++ uses new, and C uses malloc. But how do they work, in a high-level explanation?</p> <p>See <a href="https://stackoverflow.com/questions/240212/what-is-the-difference-between-newdelete-and-mallocfree#240308">What is the difference between new/delete and malloc/free?</a></p>
<p>I'm just going to direct you to this answer: <a href="https://stackoverflow.com/questions/240212/what-is-the-difference-between-newdelete-and-mallocfree#240308">What is the difference between new/delete and malloc/free?</a> . Martin provided an excellent overview. Quick overview on how they <em>work</em> (without diving into how you could overload them as member functions):</p> <h2>new-expression and allocation</h2> <ol> <li>The code contains a new-expression supplying the type-id. </li> <li>The compiler will look into whether the type overloads the operator new with an allocation function. </li> <li>If it finds an overload of an operator new allocation function, that one is called using the arguments given to new and sizeof(TypeId) as its first argument:</li> </ol> <p>Sample:</p> <pre><code>new (a, b, c) TypeId; // the function called by the compiler has to have the following signature: operator new(std::size_t size, TypeOfA a, TypeOfB b, TypeOf C c); </code></pre> <ol> <li>if operator new fails to allocate storage, it can call <code>new_handler</code>, and hope it makes place. If there still is not enough place, new has to throw <code>std::bad_alloc</code> or derived from it. An allocator that has <code>throw()</code> (no-throw guarantee), it shall return a null-pointer in that case. </li> <li>The C++ runtime environment will create an object of the type given by the type-id in the memory returned by the allocation function. </li> </ol> <p>There are a few special allocation functions given special names:</p> <ul> <li><code>no-throw</code> new. That takes a <code>nothrow_t</code> as second argument. A new-expression of the form like the following will call an allocation function taking only std::size_t and nothrow_t:</li> </ul> <p>Example:</p> <pre><code>new (std::nothrow) TypeId; </code></pre> <ul> <li><code>placement new</code>. That takes a void* pointer as first argument, and instead of returning a newly allocated memory address, it returns that argument. It is used to create an object at a given address. Standard containers use that to preallocate space, but only create objects when needed, later.</li> </ul> <p>Code:</p> <pre><code>// the following function is defined implicitly in the standard library void * operator(std::size_t size, void * ptr) throw() { return ptr; } </code></pre> <p>If the allocation function returns storage, and the the constructor of the object created by the runtime throws, then the operator delete is called automatically. In case a form of new was used that takes additional parameters, like </p> <pre><code>new (a, b, c) TypeId; </code></pre> <p>Then the operator delete that takes those parameters is called. That operator delete version is only called if the deletion is done because the constructor of the object did throw. If you call delete yourself, then the compiler will use the normal operator delete function taking only a <code>void*</code> pointer:</p> <pre><code>int * a = new int; =&gt; void * operator new(std::size_t size) throw(std::bad_alloc); delete a; =&gt; void operator delete(void * ptr) throw(); TypeWhosCtorThrows * a = new ("argument") TypeWhosCtorThrows; =&gt; void * operator new(std::size_t size, char const* arg1) throw(std::bad_alloc); =&gt; void operator delete(void * ptr, char const* arg1) throw(); TypeWhosCtorDoesntThrow * a = new ("argument") TypeWhosCtorDoesntThrow; =&gt; void * operator new(std::size_t size, char const* arg1) throw(std::bad_alloc); delete a; =&gt; void operator delete(void * ptr) throw(); </code></pre> <h2>new-expression and arrays</h2> <p>If you do </p> <pre><code>new (possible_arguments) TypeId[N]; </code></pre> <p>The compiler is using the <code>operator new[]</code> functions instead of plain <code>operator new</code>. The operator can be passed a first argument not exactly <code>sizeof(TypeId)*N</code>: The compiler could add some space to store the number of objects created (necassary to be able to call destructors). The Standard puts it this way:</p> <ul> <li><code>new T[5]</code> results in a call of operator <code>new[](sizeof(T)*5+x)</code>, and</li> <li><code>new(2,f) T[5]</code> results in a call of operator <code>new[](sizeof(T)*5+y,2,f)</code>.</li> </ul>
<p>"new" does a lot more than malloc. malloc simply allocates the memory - it doesn't even zero it for you. new initialises objects, calls contructors etc. I would suspect that in most implementations new is little more than a thin wrapper around malloc for basic types.</p>
47,764
<p>I have this code</p> <pre><code>&lt;?php session_start(); if (isset($_GET["cmd"])) $cmd = $_GET["cmd"]; else die("You should have a 'cmd' parameter in your URL"); $pk = $_GET["pk"]; $con = mysql_connect("localhost","root","geheim"); if(!$con) { die('Connection failed because of' .mysql_error()); } mysql_select_db("ebay",$con); if($cmd=="GetAuctionData") { echo "&lt;table border='1' width='100%'&gt; &lt;tr&gt; &lt;th&gt;Username&lt;/th&gt; &lt;th&gt;Start Date&lt;/th&gt; &lt;th&gt;Description&lt;/th&gt; &lt;/tr&gt;"; $sql="SELECT * FROM Auctions WHERE ARTICLE_NO ='$pk'"; $result = mysql_query($sql); while ($row = mysql_fetch_array($result)) { echo "&lt;tr&gt; &lt;td&gt;".$row['USERNAME']."&lt;/td&gt; &lt;td&gt;".$row['ARTICLE_NO']."&lt;/td&gt; &lt;td&gt;".$row['ARTICLE_NAME']."&lt;/td&gt; &lt;td&gt;".$row['SUBTITLE']."&lt;/td&gt; &lt;td&gt;".$row['CURRENT_BID']."&lt;/td&gt; &lt;td&gt;".$row['START_PRICE']."&lt;/td&gt; &lt;td&gt;".$row['BID_COUNT']."&lt;/td&gt; &lt;td&gt;".$row['QUANT_TOTAL']."&lt;/td&gt; &lt;td&gt;".$row['QUANT_SOLD']."&lt;/td&gt; &lt;td&gt;".$row['ACCESSSTARTS']."&lt;/td&gt; &lt;td&gt;".$row['ACCESSENDS']."&lt;/td&gt; &lt;td&gt;".$row['ACCESSORIGIN_END']."&lt;/td&gt; &lt;td&gt;".$row['USERNAME']."&lt;/td&gt; &lt;td&gt;".$row['BEST_BIDDER_ID']."&lt;/td&gt; &lt;td&gt;".$row['FINISHED']."&lt;/td&gt; &lt;td&gt;".$row['WATCH']."&lt;/td&gt; &lt;td&gt;".$row['BUYITNOW_PRICE']."&lt;/td&gt; &lt;td&gt;".$row['PIC_URL']."&lt;/td&gt; &lt;td&gt;".$row['PRIVATE_AUCTION']."&lt;/td&gt; &lt;td&gt;".$row['AUCTION_TYPE']."&lt;/td&gt; &lt;td&gt;".$row['ACCESSINSERT_DATE']."&lt;/td&gt; &lt;td&gt;".$row['ACCESSUPDATE_DATE']."&lt;/td&gt; &lt;td&gt;".$row['CAT_1_ID']."&lt;/td&gt; &lt;td&gt;".$row['CAT_2_ID']."&lt;/td&gt; &lt;td&gt;".$row['ARTICLE_DESC']."&lt;/td&gt; &lt;td&gt;".$row['COUNTRYCODE']."&lt;/td&gt; &lt;td&gt;".$row['LOCATION']."&lt;/td&gt; &lt;td&gt;".$row['CONDITIONS']."&lt;/td&gt; &lt;td&gt;".$row['REVISED']."&lt;/td&gt; &lt;td&gt;".$row['PAYPAL_ACCEPT']."&lt;/td&gt; &lt;td&gt;".$row['PRE_TERMINATED']."&lt;/td&gt; &lt;td&gt;".$row['SHIPPING_TO']."&lt;/td&gt; &lt;td&gt;".$row['FEE_INSERTION']."&lt;/td&gt; &lt;td&gt;".$row['FEE_FINAL']."&lt;/td&gt; &lt;td&gt;".$row['FEE_LISTING']."&lt;/td&gt; &lt;td&gt;".$row['PIC_XXL']."&lt;/td&gt; &lt;td&gt;".$row['PIC_DIASHOW']."&lt;/td&gt; &lt;td&gt;".$row['PIC_COUNT']."&lt;/td&gt; &lt;td&gt;".$row['ITEM_SITE_ID']."&lt;/td&gt; &lt;td&gt;".$row['STARTS']."&lt;/td&gt; &lt;td&gt;".$row['ENDS']."&lt;/td&gt; &lt;td&gt;".$row['ORIGIN_END']."&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;"; } echo "&lt;/table&gt;"; echo "&lt;img src=".$row['PIC_URL']."&gt;"; } mysql_close($con); ?&gt; </code></pre> <p>Here is the generated html:</p> <pre><code>&lt;table border='1' width='100%'&gt; &lt;tr&gt; &lt;th&gt;Username&lt;/th&gt; &lt;th&gt;Start Date&lt;/th&gt; &lt;th&gt;Description&lt;/th&gt; &lt;/tr&gt;&lt;tr&gt; &lt;td&gt;fashionticker1&lt;/td&gt; &lt;td&gt;220288560247&lt;/td&gt; &lt;td&gt;Ed Hardy Herren Shirt Rock &amp; Roll Weiss XXL Neu &amp; OVP&lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt;0.00&lt;/td&gt; &lt;td&gt;49.00&lt;/td&gt; &lt;td&gt;0&lt;/td&gt; &lt;td&gt;1&lt;/td&gt; &lt;td&gt;0&lt;/td&gt; &lt;td&gt;1.10.2008 16:22:09&lt;/td&gt; &lt;td&gt;6.10.2008 16:22:09&lt;/td&gt; &lt;td&gt;6.10.2008 16:22:09&lt;/td&gt; &lt;td&gt;fashionticker1&lt;/td&gt; &lt;td&gt;0&lt;/td&gt; &lt;td&gt;1&lt;/td&gt; &lt;td&gt;0&lt;/td&gt; &lt;td&gt;59.00&lt;/td&gt; &lt;td&gt;http://storage.supremeauction.com/flash/ebay2/10/49/76/10497654/13895964e.jpg&lt;/td&gt; &lt;td&gt;0&lt;/td&gt; &lt;td&gt;1&lt;/td&gt; &lt;td&gt;6.10.2008 16:21:47&lt;/td&gt; &lt;td&gt;6.10.2008 16:28:31&lt;/td&gt; &lt;td&gt;32315&lt;/td&gt; &lt;td&gt;0&lt;/td&gt; &lt;td&gt;&lt;!-- +++++++++++++++++++++++++ Bitte ändern Sie im eigenen Interesse nichts an diesem Code! ++++++++++++++++++++++++ --&gt; &lt;!-- +++++++++++++++++++++++++ Das kann massive Fehldarstellungen ihrer Auktion zur Folge haben! +++++++++++++++++++ --&gt; &lt;!-- +++++++++++++++++++++++++ ++++++++++++++++++++++++++ Ihr Supreme Team +++++++++++++++++++++++++++++++++++++++++ --&gt; &lt;/td&gt; &lt;td&gt; &lt;br&gt; &lt;br&gt; &lt;style ty&lt;/td&gt; &lt;td&gt;float: right; &lt;/td&gt; &lt;td&gt;margin: 0px; &lt;/td&gt; &lt;td&gt;0&lt;/td&gt; &lt;td&gt;0&lt;/td&gt; &lt;td&gt;0&lt;/td&gt; &lt;td&gt;padding:5px; &lt;/td&gt; &lt;td&gt;0.00&lt;/td&gt; &lt;td&gt;0.00&lt;/td&gt; &lt;td&gt;0.00&lt;/td&gt; &lt;td&gt;0&lt;/td&gt; &lt;td&gt;0&lt;/td&gt; &lt;td&gt;font-size: 12px; &lt;/td&gt; &lt;td&gt;color: #333333; } #h&lt;/td&gt; &lt;td&gt;0000-00-00 00:00:00&lt;/td&gt; &lt;td&gt;0000-00-00 00:00:00&lt;/td&gt; &lt;td&gt;0000-00-00 00:00:00&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;img src=&gt; </code></pre> <p>Whatever I do, I can not get an image to display, and when PIC_URL is empty, it only displays a placeholder image above the table, and I want it below.</p>
<p>It should be:</p> <pre><code>echo "&lt;img src=\"".$row['PIC_URL']."\"&gt;"; </code></pre>
<pre><code>while ($row = mysql_fetch_array($result)) { *snip* } echo "&lt;/table&gt;"; echo "&lt;img src=".$row['PIC_URL']."&gt;"; </code></pre> <p>Because the loop finished, $row is false. You need to change it to something like.</p> <pre><code>while ($row = mysql_fetch_array($result)) { *snip* $lastImg = $row['PIC_URL']; } echo "&lt;/table&gt;"; echo "&lt;img src=\"$lastImg\"&gt;"; </code></pre> <p>Im starting to doubt you have a valid PIC_URL returned by yer database query. You should try this, see if you get any valid pictures from the url's, and especially if the last url in the list is valid.</p> <pre><code>while ($row = mysql_fetch_array($result)) { *snip* $images[] = $row['PIC_URL']; } echo "&lt;/table&gt;"; ?&gt;&lt;p&gt;Are these valid urls you can open in yer browser?&lt;/p&gt;&lt;pre&gt;&lt;?php print_r($images); ?&gt;&lt;/pre&gt;&lt;?php </code></pre>
42,218
<p><strong>JavaFX</strong> is now out, and there are promises that Swing will improve along with JavaFX. Gone will be the days of ugly default UI, and at long last we can create engaging applications that are comparable to <strong>Flash, Air, and Silverlight</strong> in terms of quality.</p> <ol> <li><p>Will this mean that <strong>Java Applets</strong> that hail from 1990's are dead and not worth going back to? </p></li> <li><p>Same with <strong>Java Desktop</strong>: What will be compelling for us Java Developers to use it rather than JavaFX?</p></li> </ol>
<p>In my opinion Java Applets have been dead for years. I wrote some in the late 90s - a Tetris game during an internship to demonstrate on a 40MHz ARM Acorn Set Top Box for example. Of course I bet there are some casual game sites that have tonnes of them still, and thus it will remain supported, but active development will/has dropped off.</p> <p>Java Web Start is a handy technology in my opinion. That will still work with JavaFX, it's just another library for that system.</p> <p>JavaFX will give Java opportunities beyond technical tools (like SQL Developer), in-house business applications and server applications (where it excels). I think it's one of those libraries that is worth learning for any Java developer, if they can get the time. There's no arguing that user interface libraries for Java have been sorely lacking, or overly complex, for many a year.</p> <p>However there's a lot of competition out there, and it is very new (which means the development tool support is very raw, compared to Flash and Silverlight). Also people don't like downloading massive runtime environments, although broadband makes it less painful than 5 years ago for many!</p>
<p>I agree with the others, Java Applets already died. JavaFX could possibly fill that void. However, I just don't see it replacing Java Desktop any time soon. It's the same thing as saying web apps will replace all desktop apps. Some people do believe that, and I agree that web apps will grow in popularity, however, desktop apps will continue to have a place for quite awhile.</p>
49,445
<p>I found an article on getting active tcp/udp connections on a machine.</p> <p><a href="http://www.codeproject.com/KB/IP/iphlpapi.aspx" rel="nofollow noreferrer">http://www.codeproject.com/KB/IP/iphlpapi.aspx</a></p> <p>My issue however is I need to be able to determine active connections remotely - to see if a particular port is running or listening without tampering with the machine.</p> <p>Is this possible?</p> <p>Doesn't seem like it natively, otherwise it could pose a security issue. The alternative would be to query a remoting service which could then make the necessary calls on the local machine.</p> <p>Any thoughts?</p>
<p>There is no way to know which ports are open without the remote computer knowing it. But you can determine the information without the program running on the port knowing it (i.e. without interfering with the program).</p> <p><strong>Use SYN scanning:</strong></p> <p>To establish a connection, TCP uses a three-way handshake. This can be exploited to find out if a port is open or not without the program knowing.</p> <p>The handshake works as follows:</p> <ol> <li>The client performs an active open by sending a SYN to the server. </li> <li>The server replies with a SYN-ACK.</li> <li>Normally, the client sends an ACK back to the server. But this step is skipped.</li> </ol> <blockquote> <p>SYN scan is the most popular form of TCP scanning. Rather than use the operating system's network functions, the port scanner generates raw IP packets itself, and monitors for responses. This scan type is also known as "half-open scanning", because it never actually opens a full TCP connection. The port scanner generates a SYN packet. If the target port is open, it will respond with a SYN-ACK packet. The scanner host responds with a RST packet, closing the connection before the handshake is completed.</p> <p>The use of raw networking has several advantages, giving the scanner full control of the packets sent and the timeout for responses, and allowing detailed reporting of the responses. There is debate over which scan is less intrusive on the target host. SYN scan has the advantage that the individual services never actually receive a connection while some services can be crashed with a connect scan. However, the RST during the handshake can cause problems for some network stacks, particularly simple devices like printers. There are no conclusive arguments either way.</p> </blockquote> <p><a href="http://en.wikipedia.org/wiki/Port_scanner" rel="nofollow noreferrer">Source Wikipedia</a></p> <p>As is mentioned below, I think <a href="http://nmap.org/" rel="nofollow noreferrer">nmap</a> can do SYN scanning. </p> <p><strong>Using sockets for TCP port scanning:</strong></p> <p>One way to determine which ports are open is to open a socket to that port. Or to a different port which finds out the information for you like you mentioned. </p> <p>For example from command prompt or a terminal: </p> <pre><code>telnet google.com 80 </code></pre> <p><strong>UDP Port scanning:</strong></p> <p>if a UDP packet is sent to a port that is not open, the system will respond with an ICMP port unreachable message. You can use this method to determine if a port is open or close. But the receiving program will know. </p>
<p><a href="https://stackoverflow.com/questions/124638/checking-ip-port-state-remotely#124643">neouser99</a> (et al) has suggested <a href="http://nmap.org/" rel="nofollow noreferrer">NMAP</a>. NMAP is very good if all you're trying to do is to detect ports that are open on the remote machine.</p> <p>But from the sounds of your question you're actually trying to determine what ports are both open <em>and</em> connected on your remote machine. If you're after a general monitoring solution, including the connected ports, then you could install an snmp server on your remote machine. There are two <a href="http://en.wikipedia.org/wiki/Management_information_base" rel="nofollow noreferrer">MIBs</a> that let you check for port status which are <a href="https://www.rfc-editor.org/rfc/rfc4022" rel="nofollow noreferrer">TCP-MIB</a>::tcpConnectionTable and <a href="https://www.rfc-editor.org/rfc/rfc4113" rel="nofollow noreferrer">UDP-MIB</a>::udpEndpointTable.</p> <p>The daemon (server) supplied in <a href="http://www.net-snmp.org/" rel="nofollow noreferrer">net-snmp</a> has most likely got support for these mibs.</p>
15,160
<p>I tried using the Microsoft ReportingControls but found them overly cumbersome, with too little documentation. I'd like a simple control that would convert a GridView control into a PDF document. I've started looking into PDFSHarp and am running into dead ends with documentation. Same thing with iTextSharp. I'm willing to dig into them further if they have worked for others in the past.</p>
<p>You could iterate over the data in your gridview and write it to a PDF table using iTextSharp. Have a look here: <a href="http://www.codeproject.com/KB/cs/iTextSharpPdfTables.aspx" rel="nofollow noreferrer">http://www.codeproject.com/KB/cs/iTextSharpPdfTables.aspx</a></p> <p>I also recommend getting the book <a href="http://www.manning.com/lowagie" rel="nofollow noreferrer">iText In Action</a>.</p>
<p>I can recommend the ceTe DynamicPDF product if you just need to create PDF files. It is well documented and pretty easy to use. The only caveat that I would have is that your reports will all be built in Code. If you plan on adding a lot of reports then you might want to explore an alternative like Telerik's new reporting tool (which will export to PDF).</p> <p>Well, make that two caveats: DynamicPDF is a bit expensive if you are just doing the one GridView export.</p>
23,448
<p>1) user A goes to the site, creates an account, and logs in 2) user b goes to the site. Rather than having to log in, user b enters as though user b is user a. User b gets access to all of user a's data and can brows the site as user a.</p> <p>Note: user b does not log in. User b just hits the site, and the site returns as if user b is already logged in as user a.</p> <p>Note 2: user a and user b are on distinct computers. Also, static variables are not involved in the code.</p> <p>Setup: IIS 6 .Net 2.0 OutputCache off for the pages in the site</p>
<p>Check that you are not storing any data in static (c#) or Shared (VB) variables.</p>
<p>From research by other team members:</p> <blockquote> <p>Even though the authentication cookie may be in images from the portal, an authentication cookie with a ticket for David should never have been sent to Todd's browser. Also if images are cached somwhere somehow such that different users get other user's auth cookies then I assume this problem would happen fairly often and should be repeatable. However I am wondering if this is a load balanced system and if so does the load balancer cache anything?</p> </blockquote> <p>Based on the known issue of users sharing sessions as a result of output caching with ASP.NET, IIS 6.0, and Windows 2003 Server, the problem may only be repeatable 1 out of 100,000 requests (see the 'Sessions and Output Caching' section of this article) <a href="http://msdn.microsoft.com/en-us/magazine/cc163577.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/magazine/cc163577.aspx</a></p>
32,894
<p>Is it possible to write a user interface in Java for an application written in C#?</p> <p>I am working on a user interface of a project that is written in C#, but I have no experience with C# and I am an avid Java user. Is it possible to build the user interface in Java using Java's Swing and AWT libraries that operates an application primarily written in C#.</p> <p>If this sounds like a really stupid question, I apologize in advance.</p>
<p>You might be able to leverage some of the interoperability features that are integrated into Mono 2.0 </p> <p><a href="http://www.mono-project.com/Main_Page" rel="nofollow noreferrer">http://www.mono-project.com/Main_Page</a></p> <p>JNBridge is another possible interoperability solution:</p> <p><a href="http://www.jnbridge.com/" rel="nofollow noreferrer">http://www.jnbridge.com/</a></p> <p>However, a more optimal approach might be to expose your .NET code as Services - and then access them from the Java client (or through a light-weight ESB).</p> <p>Of course, time, budget, resources are constraints you'll have to consider.</p>
<p>We did this recently and went the route of using a low level socket connection, but pushing xml through it. C# was the server side, and we used the Microsoft 'xsd' tool to generate the XSD schema for the objects and then used JAXB on the java side to generate java code to parse and hold the same objects.</p> <p>As Barry mentions most of the work/problems was around the socket connection - but that depends on how comfortable you are with that.</p>
40,425
<p>I may just be missing this functionality, but does anyone know if there is a widget available:</p> <p>I need to list the subject for all the entries that are associated with a given tag.</p> <p>For example: I have 5 articles tagged with "Tutorial", I'd like to see a list as follows:</p> <ul> <li>Tutorial 1: Installing the app</li> <li>Tutorial 2: Customizing</li> <li>Tutorial 3: Advanced edits</li> <li>Tutorial 4: User managment</li> </ul> <p>Does functionality like this exists in wordpress allready?</p>
<p>I don't think this is a concern.</p> <p>Yes, the mythical "somebody" can replace the implementation of MD5 with something insecure. But in order to do that, the mythical somebody must actually be able to get his code into the Ruby process. And if he can do that, then he presumably could also inject his code into a Java process and e.g. rewrite the bytecode for the MD5 operation. Or just intercept the keypresses and not actually bother with fiddling with the cryptography code at all.</p> <p>One of the typical concerns is: I'm writing this awesome library, which is supposed to be used like so:</p> <pre><code>require 'awesome' # Do something awesome. </code></pre> <p>But what if someone uses it like so:</p> <pre><code>require 'evil_cracker_lib_from_russian_pr0n_site' # Overrides crypto functions and sends all data to mafia require 'awesome' # Now everything is insecure because awesome lib uses # cracker lib instead of builtin </code></pre> <p>And the simple solution is: don't do that! Educate your users that they shouldn't run untrusted code they downloaded from obscure sources in their security critical applications. And if they do, they probably deserve it.</p> <p>To come back to your Java example: it's true that in Java you can make your crypto code <code>private</code> and <code>final</code> and what not. However, someone can <em>still</em> replace your crypto implementation! In fact, someone actually did: many open-source Java implementations use OpenSSL to implement their cryptographic routines. And, as you probably know, Debian shipped with a broken, insecure version of OpenSSL for years. So, all Java programs running on Debian for the past couple of years actually <em>did</em> run with insecure crypto!</p>
<p>If someone monkeypatched an object or a module, then you need to look at 2 cases: He added a new method. If he is the only one adding this meyhod (which is very likely), then no problems arise. If he is not the only one, you need to see if both methods do the same and tell the library developer about this severe problem.</p> <p>If they change a method, you should start to research why the method was changed. Did they change it due to some edge case behaviour or did they actually fix a bug? especially in the latter case, the monkeypatch is a god thing, because it fixes a bug in many places.</p> <p>Besides that, you are using a very dynamic language with the assumption that programmers use this freedom in a sane way. The only way to remove this assumption is not to use a dynamic language. </p>
5,225
<p>How do I add a "last" class on the last <code>&lt;li&gt;</code> within a Views-generated list?</p>
<p>You could use the <strong>last-child</strong> pseudo-class on the li element to achieve this</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;style type="text/css"&gt; ul li:last-child { font-weight:bold } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;ul&gt; &lt;li&gt;IE&lt;/li&gt; &lt;li&gt;Firefox&lt;/li&gt; &lt;li&gt;Safari&lt;/li&gt; &lt;/ul&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>There is also a first-child pseudo class available.</p> <p>I am not sure the last-child element works in IE though.</p>
<p>Does jquery come bundled with drupal, if so you could use </p> <pre><code>$('ul&gt;li:last').addClass('last'); </code></pre> <p>to achieve this</p>
13,881
<p>This may be too generic a question as is but... I am stumped by trying to move through the directories from within a shell script. I'm not a *nix power user, but I am comfortable working through the command line for most tasks. I'd like to call a script that can move 'me' to a directory instead of just the script process similar to the following:</p> <pre><code>prompt:&gt; goto lit </code></pre> <p>where <code>goto</code> is an alias -> <code>goto='./goscript'</code><br> and<br> <code>goscript</code> has some simple code in such as:</p> <pre><code>cd /path to work dirs/lit/user dir </code></pre> <p>(assuming each user has a directory inside /lit)</p> <p>I've avoided this issue myself by setting my personal alias' to move to the desired directory, run a script, then return to the original directory. This question was brought to me by a co-worker who uses a similar method, but wanted to make the process more generic so we don't need to create every single alias we need. I thought this would be an easy problem to solve, but I'm stumped as I don't really have a great deal of shell scripting experience ...as of yet. </p>
<p>You can create a function that is called goto (or whatever) and make sure it is defined in your .bashrc (or you can "source" it from your current shell):</p> <pre><code>function goto { # the "$USER" part will expand to the current username # the "$1" will expand to the first argument to the function ("goto xyz" =&gt; $1 is "xyz") cd /some-path/lit/$USER/$1 } </code></pre> <p>Put this in ~/.bashrc or in a separate file and call "source the-file" from your prompt then you can call the function just like any other program:</p> <pre><code>prompt&gt; goto folder cd /some-path/lit/your-user/folder </code></pre>
<p>You can't use cd in a bash script. You could alias the cd and path though.</p> <pre><code>alias goto='cd /path_to_work/usr/dir' </code></pre> <p>UPDATE: you would put that line in your .bashrc file and then do</p> <pre><code>source ~/.bashrc </code></pre> <p>to create the alias.</p>
36,694
<p>How to create a database using T SQL script on a specified location? Let's say, I want to create a SQL server database on <code>D:\temp\dbFolder</code>. How to do this?</p>
<p>When you create the new database you specify the location. For example:</p> <pre><code>USE [master] GO CREATE DATABASE [AdventureWorks] ON PRIMARY ( NAME = N'AdventureWorks_Data', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\AdventureWorks_Data.mdf' , SIZE = 167872KB , MAXSIZE = UNLIMITED, FILEGROWTH = 16384KB ) LOG ON ( NAME = N'AdventureWorks_Log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\AdventureWorks_Log.ldf' , SIZE = 2048KB , MAXSIZE = 2048GB , FILEGROWTH = 16384KB ) GO </code></pre>
<p>See this link : <a href="http://technet.microsoft.com/en-us/library/ms176061.aspx" rel="nofollow">CREATE DATABASE (Transact-SQL)</a></p> <pre><code>CREATE DATABASE [ADestinyDb] CONTAINMENT = NONE ON PRIMARY ( NAME = N'ADestinyDb', FILENAME = N'D:\temp\dbFolder\ADestinyDb.mdf' , SIZE = 3136 KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024 KB ) LOG ON ( NAME = N'ADestinyDb_log', FILENAME = N'D:\temp\dbFolder\_log.ldf' , SIZE = 832KB , MAXSIZE = 2048 GB , FILEGROWTH = 10 %) </code></pre>
14,706
<p>I started with <a href="http://code.google.com/p/jetlang/" rel="nofollow noreferrer">jetlang</a> and the basic samples are pretty clear. What I didn't found is a good sample for using the PoolFiber. Anybody played around with that already? I read also the retlang samples but it seems little bit different there.</p> <p>Thanks for sharing your thoughts!</p> <p>Okami</p>
<p>Using a PoolFiber and ThreadFiber are nearly the same. The only difference is that the thread pool needs to initialized and used for creating each PoolFiber.</p> <pre><code>// create java thread pool. ExecutorService pool = Executors.newCachedThreadPool(); //initialize factory with backing pool PoolFiberFactory fiberFactory = new PoolFiberFactory(pool); Fiber fiber = fiberFactory.create(); fiber.start(); //use fiber for normal publishing and subscribing. </code></pre>
<p>Here it is on Github.</p> <p><a href="https://github.com/jetlang/jetlang/blob/readme/src/test/java/org/jetlang/examples/BasicExamples.java" rel="nofollow">https://github.com/jetlang/jetlang/blob/readme/src/test/java/org/jetlang/examples/BasicExamples.java</a></p> <p>Here's the mvn site <a href="http://jetlang.github.io/jetlang/" rel="nofollow">http://jetlang.github.io/jetlang/</a></p>
36,474
<p>I have more than one OpenID as I have tried out numerous. As people take up OpenID different suppliers are going to emerge I may want to switch provinders. As all IDs are me, and all are authenticated against the same email address, shouldn't I be able to log into stack overflow with any of them and be able to hit the same account?</p>
<p>I think each site that implements OpenID would have to build their software to allow multiple entries for your OpenID credentials. However, just because a site doesn't allow you to create multiple entries doesn't mean you can't swap out OpenID suppliers.</p> <h2>How to turn your blog into an OpenID</h2> <p>STEP 1: Get an OpenID. There a lots of servers and services out there you can use. I use <a href="http://www.myopenid.com" rel="nofollow noreferrer">http://www.myopenid.com</a></p> <p>STEP 2: Add these two lines to your blog's main template in-between the <code>&lt;HEAD&gt;&lt;/HEAD&gt;</code> tags at the top of your template. Most all blog engines support editing your template so this should be an easy and very possible thing to do.</p> <p>Example:</p> <pre> &lt;link rel="openid.server" href="http://www.myopenid.com/server" /&gt; &lt;link rel="openid.delegate" href=http://YOURUSERNAME.myopenid.com/ /&gt; </pre> <p>This will let you use your domain/blog as your OpenID.</p> <p>Credits to <a href="http://www.hanselman.com/blog/TheWeeklySourceCode25OpenIDEdition.aspx" rel="nofollow noreferrer">Scott Hanselman</a> and <a href="http://simonwillison.net/2006/Dec/19/openid/" rel="nofollow noreferrer">Simon Willison</a> for these simple instructions.</p> <h2>Switch Your Supplier</h2> <p>Now that your OpenID points to your blog, you can update your link rel href's to point to a new supplier and all the places that you've tied your blog's OpenID will use the new supplier.</p>
<p>Doesn't using multiple open-id providers sort of undermine the point of open id?</p>
2,666
<p>To save some typing and clarify my code, is there a standard version of the following method?</p> <pre><code>public static boolean bothNullOrEqual(Object x, Object y) { return ( x == null ? y == null : x.equals(y) ); } </code></pre>
<p>With Java 7 you can now directly do a null safe equals:</p> <p><a href="http://docs.oracle.com/javase/7/docs/api/java/util/Objects.html" rel="noreferrer">Objects.equals(x, y)</a></p> <p>(The Jakarta Commons library ObjectUtils.equals() has become obsolete with Java 7)</p>
<p>If you are using &lt;1.7 but have Guava available: <a href="http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/base/Objects.html#equal(java.lang.Object,%20java.lang.Object)" rel="noreferrer"><code>Objects.equal(x, y)</code></a></p>
22,357
<p>Let's say I create a website like StackOverFlow and decide to use OpenID. What's to prevent me, or anyone else for that matter, from phishing the ID's? That is, how can you truly know that any website is using OpenID and not pretending to? And how do you protect myself against this?</p> <p>Expanding on this, let's say one site did compromise your openID credentials, couldn't they use it on every other site using openID (a global password hack)? Wouldn't then the security of your openID then only be as strong as the weakest website/provider? </p>
<p>All you enter is the ID, no password. The ID is public, therefore "phishing" it is not a security hole. Some providers even use the same ID for all users, for instance the ID for a google account is always <code>https://www.google.com/accounts/o8/id</code>. See the <a href="http://en.wikipedia.org/wiki/OpenID#Logging_in" rel="nofollow noreferrer">Wikipedia article</a> for a more detailed explanation.</p>
<p>Funny story. I found an exploit on SO that allowed me to change someone's profile entirely. If Jeff'd been using email+password, I could have owned his account, but because SO uses OpenID, there was nothing to do but change his Gavitar to something funny.</p> <p>The bug in question was reported, fixed, and I'm still waiting on my Hacker badge. :P</p>
41,193
<p>Searching for some sample code for converting a point in WGS84 coordinate system to a map position in Google Maps (pixel position), also supporting zoom levels. </p> <p>If the codes is well commented, then it can also be in some other language.</p> <p>You can also point me to a open source Java project :)</p> <p>Some resources found:</p> <p><a href="http://trac.openlayers.org/browser/trunk/openlayers/lib/OpenLayers/Layer" rel="nofollow noreferrer">OpenLayer</a> implementation. </p> <p><a href="http://josm.openstreetmap.de/browser/trunk/src/org/openstreetmap/josm/data/projection" rel="nofollow noreferrer">JOSM</a> project</p> <p>Excellent <a href="https://github.com/OSUCartography/JMapProjLib" rel="nofollow noreferrer">Java Map Projection Library </a> from JH LABS. This is a pure java PROJ.4 port. Does projection from WGS84 to meters. From there it's quite straightforward to convert meters to tile pixels.</p>
<p><a href="http://web.archive.org/web/20110809084551/http://mapki.com/wiki/Tile_utility_code_in_Java" rel="nofollow noreferrer">Tile utility code in Java</a> on mapki.com (great resource for google map developers)</p>
<p>Someone took the javascript code from Google Maps and ported it to python: <a href="http://code.google.com/p/gheat/source/browse/trunk/__/lib/python/gmerc.py" rel="nofollow noreferrer">gmerc.py</a></p> <p>I've used this and it works great.</p>
2,922
<p>What are the best practices in setting up a new instance of TFS 2008 Workgroup edition? </p> <p>Specifically, the constraints are as follows:</p> <ul> <li>Must install on an existing Windows Server 2008 64 bit</li> <li>TFS application layer is 32 bit only</li> </ul> <p>Should I install SQL Server 2008, Sharepoint and the app layer in a virtual instance of Windows Server 2008 or 2003(I am already running Hyper-V) or split the layers with a database on the host OS and the app layer in a virtual machine?</p> <p>Edit: Apparently, splitting the layers is <a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3501572&amp;SiteID=1" rel="nofollow noreferrer">not</a> recommended </p>
<p>This is my recipe for installing TFS 2008 SP1. </p> <p>There is no domain controller in this scenario, we are only a couple of users. If I was to do it again, I would consider changing our environement to use a active directory domain.</p> <ul> <li>Host Server running Windows Server 2008 with 8GB RAM and quad processor</li> <li>Fresh install of Windows Server 2008 32bit in a VM under Hyper-V</li> <li>Install Application Server role with IIS</li> <li>Install SQL Server 2008 Standard edition <ul> <li>Use a user account for Reporting Services and Analysis Services</li> </ul></li> <li><a href="http://www.woodwardweb.com/vsts/000444.html" rel="nofollow noreferrer">Create a slipstreamed image of TFS 2008 with SP1</a> and install TFS</li> <li>Install VSTS 2008</li> <li>Install Team System Explorer</li> <li>Install VSTS 2008 SP1</li> <li>Install TFS Web Access Power tool</li> </ul> <p>After installing everything, reports were not generated. Found <a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=317697&amp;SiteID=1" rel="nofollow noreferrer">this forum post </a> that helped resolve the problem.</p> <ul> <li>Open <a href="http://localhost:8080/Warehouse/v1.0/warehousecontroller.asmx" rel="nofollow noreferrer">p://localhost:8080/Warehouse/v1.0/warehousecontroller.asmx</a></li> <li>Run the webservice (see above link for details), it will take a little while, the tfsWarehouse will be rebuilt</li> </ul> <p>It is very important to do things in order, download the installation guide and follow it to the letter. I forgot to install the Team System Explorer until after installing SP1 and ventured into all sorts of problems. Installing SP1 once more fixed that.</p>
<p>I just upgraded our team to TFS 2008, from TFS 2005. The hardest part was upgrading SharePoint 2.0 to 3.0, so I would make sure to do that first, if you have not already installed TFS 2008. We had a couple of other difficulties, but they were all either related to the SharePoint upgrade, or to the fact that we were using an aftermarket Policy package - Scrum for TeamSystem. We are on SQL Server 2005, so I cannot address SQL Server 2008. As for splitting the layers, we did not do this either, as we are running on Windows Server 2003 and everything ran under the host OS.</p>
5,254
<p>I start a .Net server side program on my local workstation, but soon it throws a security exception. I searched the web for answers, but no quick fix was found / worked. I just want to run my program. How do I get rid of the exception? I fully trust the program, because its mine.</p> <p>Edit: Oh, yes, I do run the program from a mapped folder that is mapped to my own local drive for the sake of clarity of folder structures. Thanks for the answers, I try tomorrow to run it directly from my drive.</p> <p>Edit: When I use directly my drive, it works.</p>
<p><a href="http://blogs.msdn.com/shawnfa/archive/2008/05/12/fulltrust-on-the-localintranet.aspx" rel="nofollow noreferrer">.NET 3.5 SP1 has better support for running applications on the local intranet.</a> </p> <p>If you can't target 3.5 SP1, you can map the share you're running the application from to a local drive and <a href="http://blogs.msdn.com/shawnfa/archive/2004/12/30/344554.aspx" rel="nofollow noreferrer">use CasPol to set that mapped drive to a fully trusted location.</a></p>
<p>As a temporary measure, you can type...</p> <pre><code>caspol -s off </code></pre> <p>...and all .NET Code Access Security is suspended (until you hit &lt; enter >).</p>
24,079
<p>In a progression of languages, I have been learning C and C++. Now I would like to learn C#. I know there are some drastic differences between them - such as the removal of pointers and garbage collection. However, I don't know many of the differences between the two.</p> <p>What are the major differences that a C++ programmer would need to know when moving to C#? (For example, what can I use instead of STL, syntactic differences between them, or anything else that might be considered important.)</p>
<p><a href="https://msdn.microsoft.com/en-us/library/yyaad03b(v=vs.90).aspx?f=255&amp;MSPPError=-2147217396" rel="noreferrer">C# for C++ Developers</a> is a great place to start. It is a table that lists the most important comparisons between the two languages.</p> <p>Once you have explored some of these differences, you might choose a self-contained project you have written in the past in C++, and re-write it in C#. In your first pass, you will probably just end up translating directly across, using the same design and algorithms. As you become more comfortable with C#, you will recognize ways to take advantage of language features only available in C#, as well as the incredibly versatile .NET Framework.</p>
<p>Look at the Generic collections and LINQ (all the related technology to LINQ) for STL like functionality.</p> <p>The number one thing to note is that ~/Destructor is c++ is nothing like the ~/finalizer in c# -- See IDisposable/using.</p>
34,925
<p>I need the name of the current logged in user in my <strong>Air/Flex</strong> application. The application will only be deployed on Windows machines. I think I could attain this by regexing the User directory, but am open to other ways.</p>
<p>Also I would try:</p> <pre><code>File.userDirectory.name </code></pre> <p>But I don't have Air installed so I can't really test this...</p>
<p>Update way later: there's actually a built in function to get the current user. I think it's in nativeApplication.</p>
2,376
<p>This confusion arises as most people are trained to evaluate arithmetic expressions as per <a href="http://en.wikipedia.org/wiki/PEMDAS#Mnemonics" rel="nofollow noreferrer">PEDMAS or BODMAS rule</a> whereas arithmetic expressions in programming languages like C# do not work in the same way.</p> <p>What are your takes on it?</p>
<p><em>Precedence</em> rules specify priority of operators (which operators will be evaluated first, e.g. multiplication has higher precedence than addition, PEMDAS). </p> <p>The <em>associativity</em> rules tell how the operators of same precedence are grouped. Arithmetic operators are left-associative, but the assignment is right associative (e.g. a = b = c will be evaluated as b = c, a = b). </p> <p>The <em>order</em> is a result of applying the <em>precedence</em> and <em>associativity</em> rules and tells how the expression will be evaluated - which operators will be evaluated firs, which later, which at the end. The actual order can be changed by using <em>braces</em> (braces are also operator with the highest precedence). </p> <p>The <em>precedence</em> and <em>associativity</em> of operators in a programming language can be found in its language manual or specification. </p>
<p>I am not sure there really is a difference. The traditional BODMAS (brackets, orders, division, multiplication, addition, subtraction) or PEDMAS (parentheses, exponents, division, multiplication, addition, subtraction) are just subsets of all the possible operations and denote the order that such operations should be applied in. I don't know of any language in which the BODMAS/PEDMAS rules are violated, but each language typically adds various other operators - such as ++, --, = etc.</p> <p>I always keep a list of operator precedence close to hand in case of confusion. However when in doubt it is usually worth using some parentheses to make the meaning clear. Just be aware that parentheses do not have the highest precedence - see <a href="http://msdn.microsoft.com/en-us/library/126fe14k.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/126fe14k.aspx</a> for an example in C++.</p>
9,621
<p>On Linux/GCC I can use the -rpath flag to change an executables search path for shared libraries without tempering with environment variables.</p> <p>Can this also be accomplished on Windows? As far as I know, dlls are always searched in the executable's directory and in PATH. </p> <p>My scenario: I would like to put shared libraries into locations according to their properties (32/64bit/Debug/Release) without taking care of unique names. On Linux, this is easily be done via rpath, but I haven't found any way doing this on Windows yet.</p> <p>Thanks for any hints!</p>
<p>Sadly there is no direct analogue to RPATH. There are a number of alternative possibilities, each of them most likely undesirable to you in its own special way.</p> <p>Given that you need a different exe for each build flavor anyway to avoid runtime library clashes, as you might guess the easiest thing to do is to put each exe in the same folder as each set of DLLs.</p> <p>As you also mentioned, the most universal method is to change the PATH variable by using a batch file to bootstrap the exe.</p> <p>You could instead change the current working directory before running the program to the desired DLL folder.</p> <p>You can use the function <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms686203%28v=vs.85%29.aspx" rel="noreferrer">SetDllDirectory</a> or <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/hh310513%28v=vs.85%29.aspx" rel="noreferrer">AddDllDirectory</a> inside your exe. This is probably the closest to an RPATH, but only works on WinXP SP1 or later.</p> <p>If you're willing to alter the file name of each exe flavor, you can use the "App Paths" registry key. Each exe would need a unique filename.</p>
<p>The search order for DLLs in Windows is described on <a href="http://msdn.microsoft.com/en-us/library/ms682586%28VS.85%29.aspx" rel="noreferrer">this page</a> on MSDN. If you're using <a href="http://msdn.microsoft.com/en-us/library/ms686944%28VS.85%29.aspx" rel="noreferrer">run-time dynamic linking</a>, you can specify the folder when you call <code>LoadLibrary</code>.</p>
13,328
<h2>Update</h2> <p>I am making this a community wiki, for three reasons:</p> <ul> <li>I don't feel like I got a definitive answer, but</li> <li>I have long since stopped needing an answer, because I rolled my own accordion function</li> <li>this question gets tons of views, so clearly lots of people are still interested</li> </ul> <p>So if anybody wants to change/clarify this question and make it a definitive guide, be my guest.</p> <hr> <p>I'm working on a page using jQuery's <a href="http://docs.jquery.com/UI/Accordion" rel="noreferrer">accordion UI element</a>. I modeled my HTML on that example, except that inside the <code>&lt;li&gt;</code> elements, I have some unordered lists of links. Like this:</p> <pre><code> $(document).ready(function() { $(".ui-accordion-container").accordion( {active: "a.default", alwaysOpen: true, autoHeight: false} ); }); &lt;ul class="ui-accordion-container"&gt; &lt;li&gt; &lt;!-- Start accordion section --&gt; &lt;a href='#' class="accordion-label"&gt;A Group of Links&lt;/a&gt; &lt;ul class="linklist"&gt; &lt;li&gt;&lt;a href="http://example.com"&gt;Example Link&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="http://example.com"&gt;Example Link&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;!--and of course there's another group --&gt; </code></pre> <h3>Problem: IE Animation stinks</h3> <p>Although IE7 animates the documentation's example accordion menu just fine, it has problems with mine. Specifically, one accordion menu on the page moves jerkily and has flashes of content. <strong>I know that it's not a CSS issue because the same thing happens if I don't include my CSS files.</strong></p> <p>The other accordion menu on the page opens the first section you click and, after that, won't open any of them.</p> <p>Both of these problems are IE-specific, and both go away if I use the option <code>animated: false</code>. But I'd like to keep the default <code>slide</code> animation, since it helps the user understand what the menu is doing.</p> <p>Is there another way?</p>
<p>I feel your pain! I recently went through a ridiculous troubleshoot where I tore everything out of the master page and page layout block by block (this was actually in SharePoint), continuously slimming down the page.</p> <p>The end result ended up being <strong>not having a doc type</strong> for the html document (some developer had removed it). The lack of a doctype meant that IE 7 was running in quirks mode and the inline CSS emitted by the JQuery Accordion was behaving funky.</p> <p>Consider adding:</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; </code></pre> <p>At the top of your masterpage or html document (if there's not already a doctype defined).</p> <p>There's actually a whole site dedicated to Quirks Mode behavior. You can check out an article about <a href="http://www.quirksmode.org/css/quirksmode.html" rel="noreferrer">Quirks Mode here</a>. I <a href="http://blog.tylerholmes.com/2009/01/troubleshooting-jquery-accordion.html" rel="noreferrer">wrote a post</a> which has a little more surrounding information on the troubleshoot.</p>
<p>In options you should set:</p> <pre><code> navigation: true </code></pre>
43,066
<p>I mean, can you use couchDB for:</p> <ul> <li>CRUD of items, users</li> <li>bids and auctions resolutions</li> <li>bidirectional califications</li> <li>forum</li> <li>items comparison</li> </ul>
<p>You could try to use CouchDB for an application - as to whether you would be successful is another question. </p> <p>Something on the scale of eBay will have special requirements that are not representative of a typical application, If you are building a small auction site then perhaps CouchDB would suffice. A document-oriented database like CouchDB may not be so hot when you have to deal with transactional/records-based data like that associated with auctions.</p>
<p>I would look to see how Amazon uses SimpleDB internally (or do they?). Might have some clues as to right ways to use a document-based database.</p>
36,511
<p>For example:</p> <pre><code>from datetime import &lt;c-x&gt;&lt;c-o&gt;{list of modules inside datetime package} </code></pre>
<p>THe other option is when you create the project simply uncheck the default box for "create directory for solution"</p>
<p>I couldn't find a solution file for my project. I was able to run the project on one machine without a .sln in the project. The reason it worked on the machine I created it on was that that I keep my VS projects under C:\Dev\Projects but Visual Studio kept its .sln file c:\users\xyz\documents\VisualStudio2015\projects directory. When I moved the files to a new computer the .sln wasn't in the same directory. I just found the project set up in the old computer in the c:\users\xyz\documents\VisualStudio2015\projects directory and moved that to my new computer. I believe I could have avoided this by changing the Tools->Options->Projects and Solutions section</p>
26,274
<p>So I have a script that I want to run as root, without hangup and nicely. What order should I put the commands in?</p> <p>sudo nohup nice foo.bash &amp;</p> <p>or</p> <p>nohup nice sudo foo.bash &amp;</p> <p>etc.</p> <p>I suspect it doesn't matter but would like some insight from those who <strong>really</strong> know.</p>
<p>If negative niceness is desired, I would do: sudo nohup nice command because according to `info coreutils' nohup should <em>preceed</em> nice. If I want a negative nice value, sudo must come before, since only root is able to use negative nice values.</p> <p>If positive niceness is desired, I would do simply: nohup nice sudo command This ensures that nohup and nice are not run with root privileges.</p>
<p>I guess all of them do an exec* syscall to pass the ball to the next one, so, whatever the order, it won't leave any hanging processes.</p> <p>I'd say that nohup should be last so that the two other don't clober the signal handler. (I'm sure nice does not play with signals, but sudo does.)</p> <p>Then, sudo and nice, it all depends on which way you want to alter the scheduling priority with nice.</p> <ul> <li>If you want to raise the priority (that is, give a negative value to nice) do sudo before.</li> <li>If you want to lower the priority (give nice a positive value) do it before sudo, as you don't need root privileges.</li> </ul>
45,607
<p>Say I have a <code>Textbox</code> nested within a <code>TabControl</code>. </p> <p>When the form loads, I would like to focus on that <code>Textbox</code> (by default the focus is set to the <code>TabControl</code>).</p> <p>Simply calling <code>textbox1.focus()</code> in the <code>Load</code> event of the form does not appear to work. </p> <p>I have been able to focus it by doing the following:</p> <pre><code> private void frmMainLoad(object sender, EventArgs e) { foreach (TabPage tab in this.tabControl1.TabPages) { this.tabControl1.SelectedTab = tab; } } </code></pre> <p><strong>My question is:</strong></p> <p>Is there a more elegant way to do this?</p>
<p>The following is the solution:</p> <pre><code>private void frmMainLoad(object sender, EventArgs e) { ActiveControl = textBox1; } </code></pre> <p>The better question would however be why... I'm not entirely sure what the answer to that one is.</p> <p>Edit: I suspect it is something to do with the fact that both the form, and the TabControl are containers, but I'm not sure.</p>
<pre><code> private void ChildForm1_Load(object sender, EventArgs e) { ActiveControl = txt_fname; } </code></pre> <p>i use this code it works fine on win tab control or dotnetbar supertab contrl</p>
7,116
<p>What is the main difference between <code>StringBuffer</code> and <code>StringBuilder</code>? Is there any performance issues when deciding on any one of these?</p>
<p><a href="http://docs.oracle.com/javase/8/docs/api/java/lang/StringBuffer.html" rel="noreferrer"><code>StringBuffer</code></a> is synchronized, <a href="http://docs.oracle.com/javase/8/docs/api/java/lang/StringBuilder.html" rel="noreferrer"><code>StringBuilder</code></a> is not.</p>
<p>Every method present in StringBuffer is Synchronized. hence at a time only one thread is allowed to operate StringBuffer object. It Increases waiting time of a Thread and Creates Performance problems to overcome this problem SUN People intoduced StringBuilder in 1.5 version.</p>
46,279
<p>We use Log4j (and Commons Logging) to log our error messages. Now we want to set up an additional log appender that outputs fatal errors to syslog, but without the exceptionally long Java stacktraces (those will still be available in the full log file).</p> <p>How would one configure this (using log4j.xml)? Is there a filter available to ignore the stack traces?</p>
<p>Edit after reading some more of the source:</p> <p>You still need to subclass PatternLayout, but the method you want to override is ignoresThrowable(): it should return false, which will prevent the appender from writing the Throwable (it assumes that the layout has done so already).</p> <p>No way to specify this in the configuration: PatternLayout has a hardcoded "return true".</p>
<p>If you can change the source code, then another option is available for consideration.</p> <p>In my applications, I always and only log FATAL messages from my applications entry point (e.g., "main()"), since I only know that they are fatal if I am about to exit the application because of them.</p> <p>Therefore, in this one place (or handful if you have multiple application entry points), instantiate a Log4j Logger with a special class or MDC of "syslog" or similar. Upon catching a soon-to-be-FATAL error, log it in the usual way (for your other log files and such), but also invoke the fatal() method on this new "syslog" Logger with only the precise message that you want (such as only the exception class and message but without the stack trace). Then configure Log4j to direct only this "syslog" class or MDC to a newly-configured Appender that targets the SysLog.</p> <p>Ta-dum!</p>
45,350
<p>The problem is not about randomness itself (we have rand), but in cryptographically secure PRNG. What can be used on Linux, or ideally POSIX? Does NSS have something useful?</p> <p><strong>Clarification</strong>: I know about /dev/random, but it may run out of entropy pool. And I'm not sure whether /dev/urandom is guaranteed to be cryptographically secure.</p>
<p>Use <code>/dev/random</code> (requires user input, eg mouse movements) or <code>/dev/urandom</code>. The latter has an entropy pool and doesn't require any user input unless the pool is empty.</p> <p>You can read from the pool like this:</p> <pre><code>char buf[100]; FILE *fp; if (fp = fopen("/dev/urandom", "r")) { fread(&amp;buf, sizeof(char), 100, fp); fclose(fp); } </code></pre> <p>Or something like that.</p>
<p>The <code>/dev/random</code> device is intended to be a source of cryptographically secure bits.</p>
14,621
<p>I'm trying to install some Ruby Gems so I can use Ruby to notify me when I get twitter messages. However, after doing a <code>gem update --system</code>, I now get a zlib error every time I try and do a <code>gem install</code> of anything. below is the console output I get when trying to install ruby gems. (along with the output from <code>gem environment</code>).</p> <pre><code>C:\data\ruby&gt;gem install twitter ERROR: While executing gem ... (Zlib::BufError) buffer error C:\data\ruby&gt;gem update --system Updating RubyGems ERROR: While executing gem ... (Zlib::BufError) buffer error C:\data\ruby&gt;gem environment RubyGems Environment: - RUBYGEMS VERSION: 1.2.0 - RUBY VERSION: 1.8.6 (2007-03-13 patchlevel 0) [i386-mswin32] - INSTALLATION DIRECTORY: c:/ruby/lib/ruby/gems/1.8 - RUBY EXECUTABLE: c:/ruby/bin/ruby.exe - EXECUTABLE DIRECTORY: c:/ruby/bin - RUBYGEMS PLATFORMS: - ruby - x86-mswin32-60 - GEM PATHS: - c:/ruby/lib/ruby/gems/1.8 - GEM CONFIGURATION: - :update_sources =&gt; true - :verbose =&gt; true - :benchmark =&gt; false - :backtrace =&gt; false - :bulk_threshold =&gt; 1000 - REMOTE SOURCES: - http://gems.rubyforge.org/ </code></pre>
<p>I just started getting this tonight as well. Googling turned up a bunch of suggestions that didn't deliver results</p> <pre><code>gem update --system </code></pre> <p>and some paste in code from jamis that is supposed to replace a function in package.rb but the original it is supposed to replace is nowhere to be found.</p> <p>Reinstalling rubygems didn't help. I'm reinstalling ruby right now.........and it is fixed. Pain though.</p>
<p>Try updating <a href="http://gnuwin32.sourceforge.net/packages/zlib.htm" rel="nofollow noreferrer">ZLib</a> before you do anything else. I had a similar problem on OS X and updating <a href="http://search.cpan.org/~pmqs/IO-Compress-2.020/lib/Compress/Zlib.pm" rel="nofollow noreferrer">Compress::Zlib</a> (a Perl interface to ZLib) cured it - so I think an old version of <a href="http://www.zlib.net/" rel="nofollow noreferrer">ZLib</a> (is now 1.2.3) may be where your problem lies...</p>
4,791
<p>Can a flash front end talk to a .net backend?</p>
<p>Yes.</p> <p>We use <a href="http://www.adobe.com/products/flex/" rel="nofollow noreferrer">Adobe Flex</a> to talk to .Net XML web services.</p> <p>Be careful with complex serialised .Net types (for instance DataSets) - ActionScript can't handle them. </p> <p>Instead produce simple XML with primitive types.</p> <p>See also: <a href="https://stackoverflow.com/questions/44817">Flex and ADO.NET Data Services...anyone done it?</a></p> <pre><code>&lt;mx:WebService id="myDataService" showBusyCursor="true"&gt; &lt;mx:operation name="WebMethodName" resultFormat="object" result="functionFiredOnComplete();"&gt;&lt;/mx:operation&gt; &lt;/mx:WebService&gt; public function load():void { myDataService.loadWSDL( "web method's wsdl" ); myDataService.WebMethodName.send( params ); } public function functionFiredOnComplete():void { // get data var myData:Object = myDataService.WebMethodName.lastResult; ... </code></pre>
<p>My older brother and I developed several methods for Flash/.Net communication. I've seen web services mentioned above (which is a great way of doing it), but we also used simple .aspx pages and had stuff passed via querystring (poor man's way of doing things), using Flashvars to get data TO Flash, but my favorite - Using .Net and a repeater control to build xml files which were then consumed by Flash. We created some pretty cool stuff doing that!</p>
28,458
<p>I created a new project in Materialise Magics, added a few parts (different STLs), moved them around in certain positions and now I want to export this project into another STL, containing my recent work.</p> <p>The export menu seems to be all grey, like this function is not available. Do I have to do some repairing first or something similar? Or Magics needs other software in order to export a Magics Project to a STL file?</p>
<p>Yes. Look up Arduino Ramps 1.4</p> <p><a href="http://reprap.org/wiki/RAMPS_1.4" rel="noreferrer">http://reprap.org/wiki/RAMPS_1.4</a></p> <p>Following the programing is all done for you in the firmware. That said you can edit it. Just open the firmware files -- it is compiled when you upload them. Generally however one usually sticks to the preferences header alone..</p> <p><a href="http://reprap.org/wiki/List_of_Firmware" rel="noreferrer">http://reprap.org/wiki/List_of_Firmware</a></p> <p>Over all you are trying to reinvent the wheel. When I started 5-6 years ago it was barely a thing. Now you buy a proven kit and get to the printing. That said if you are truly interested in designing check out. </p> <p><a href="https://www.facebook.com/groups/cncbuilddesign/" rel="noreferrer">https://www.facebook.com/groups/cncbuilddesign/</a></p> <p>If you want help on picking a kit. Or what I really think you are looking for. A good place to start. This is one of the larger 3d printing groups. Full disclosure I run this one, but at 6k members I don't recruit. </p> <p><a href="https://www.facebook.com/groups/3DPrinterHobbyists/" rel="noreferrer">https://www.facebook.com/groups/3DPrinterHobbyists/</a></p> <p>I got my start in reprap IRC</p> <p><a href="http://reprap.org/wiki/IRC" rel="noreferrer">http://reprap.org/wiki/IRC</a></p> <p>Be aware there are trolls that now camp the IRC looking to sell you a printer. I would not engage with them, their printers are usually overpriced and sub par. </p> <p>Best of luck.</p> <p>Most of all I think you need to know it's Reprap all the way. Reprap forums, Reprap printers, Reprap kits, Reprap community. All the commercial printers started off the reprap project. Even if you buy a makerbot (don't) it's Reprap in it's roots.</p> <p><a href="https://vimeo.com/5202148" rel="noreferrer">https://vimeo.com/5202148</a></p>
<p>While Star Wind's answer is best as far as addressing what was not asked, but was probably the intent of the question, for educational purposes:</p> <p>To control the printer you need an microcontroller (most popular are Arduino) which will interface with the motor drivers. Microcontrollers cannot output the current needed to control the motors, so motor drivers (such as this <a href="https://www.pololu.com/product/1182" rel="noreferrer">https://www.pololu.com/product/1182</a> ) are easy ways to control a stepper motor with higher current (and usually voltage). You can build your own if you are particularlly adventurous, they are essentially two H-bridge circuits.</p> <p>The Arduino programming environment has a library for controlling stepper motors through a driver built in, you just tell it which pin to send the pulses to, and how fast, and a separate pin tells it to spin clockwise or counterclockwise. </p> <p>For a 3D printer you need at least four motors working in unison, one for the X, Y, Z axis, and one for the extruder (E axis). </p> <p>The existing programs that 3D printers use (Marlin, Sprinter, Teacup, etc) are all doing these simple steps at their core, but have implemented libraries of G-code that the printer uses to make control the stepper motors in unison to make the correct shape. Slicing programs such as Cura or Slic3r take in the 3D model and output the Gcode that the microcontroller is programmed to understand. </p>
331
<p>I have a strange phenomenon while continuously instantiating a com-wrapper and then letting the GC collect it (not forced).</p> <p>I'm testing this on .net cf on WinCE x86. Monitoring the performance with .net Compact framework remote monitor. Native memory is tracked with Windows CE Remote performance monitor from the platform builder toolkit.</p> <p>During the first 1000 created instances every counter in perfmon seems ok: </p> <ul><li>GC heap goes up and down but the average remains the same</li> <li>Pinned objects is 0</li> <li>native memory keeps the same average</li> <li>...</li></ul> <p>However, after those 1000 (approximately) the Pinned object counter goes up and never goes down in count ever again. The memory usage stays the same however.</p> <p>I don't know what conclusion to pull from this information... Is this a bug in the counters, is this a bug in my software?</p> <p>[EDIT]</p> <p>I do notice that the Pinned objects counter starts to go up as soon the total bytes in use after GC stabilises as does the Objects not moved by compactor counter.</p> <p><a href="http://files.stormenet.be/gc_pinnedobj.jpg" rel="nofollow noreferrer">The graphic of the counters http://files.stormenet.be/gc_pinnedobj.jpg</a></p> <p>[/EDIT]</p> <p>Here's the involved code:</p> <pre><code> private void pButton6_Click(object sender, EventArgs e) { if (_running) { _running = false; return; } _loopcount = 0; _running = true; Thread d = new Thread(new ThreadStart(LoopRun)); d.Start(); } private void LoopRun() { while (_running) { CreateInstances(); _loopcount++; RefreshLabel(); } } void CreateInstances() { List&lt;Ppb.Drawing.Image&gt; list = new List&lt;Ppb.Drawing.Image&gt;(); for (int i = 0; i &lt; 10; i++) { Ppb.Drawing.Image g = resourcesObj.someBitmap; list.Add(g); } } </code></pre> <p>The Image object contains an AlphaImage:</p> <pre><code> public sealed class AlphaImage : IDisposable { IImage _image; Size _size; IntPtr _bufferPtr; public static AlphaImage CreateFromBuffer(byte[] buffer, long size) { AlphaImage instance = new AlphaImage(); IImage img; instance._bufferPtr = Marshal.AllocHGlobal((int)size); Marshal.Copy(buffer, 0, instance._bufferPtr, (int)size); GetIImagingFactory().CreateImageFromBuffer(instance._bufferPtr, (uint)size, BufferDisposalFlag.BufferDisposalFlagGlobalFree, out img); instance.SetImage(img); return instance; } void SetImage(IImage image) { _image = image; ImageInfo imgInfo; _image.GetImageInfo(out imgInfo); _size = new Size((int)imgInfo.Width, (int)imgInfo.Height); } ~AlphaImage() { Dispose(); } #region IDisposable Members public void Dispose() { Marshal.FinalReleaseComObject(_image); } } </code></pre>
<p>I doubt it's a bug in RPM. What we don't have here is any insight into the Ppb.Drawing stuff. The place I see for a potential problem is the GetIImagingFactory call. What does it do? It's probably just a singleton getter, but it's something I'd chase.</p> <p>I also see an AllochHGlobal, but nowhere do I see that allocation getting freed. For now that's where I'd focus.</p>
<p>Well, there's a bug in your code in that you're creating a lot of IDisposable instances and never calling Dispose on them. I'd hope that the finalizers would eventually kick in, but they shouldn't really be necessary. In your production code, do you dispose of everything appropriately - and if not, is there some reason why you can't?</p> <p>If you put some logging in the AlphaImage finalizer (detecting AppDomain unloading and application shutdown and not logging in those cases!) does it show the finalizer being called?</p> <p>EDIT: One potential problem which probably <em>isn't</em> biting you, but may be worth fixing anyway - if the call to CreateImageFromBuffer fails for whatever reason, you still own the memory created by AllocHGlobal, and that will currently be leaked. I suspect that's not the problem or it would be blowing up more spectacularly, but it's worth thinking about.</p>
48,937
<p>I am looking for a way to mount\unmount a USB flash drive using VBScript. This is the closest I was able to get.</p> <pre><code>Sub EjectDrive(strDrive) On Error Resume Next CONST SSF_DRIVES = 17 Set objShell = CreateObject("Shell.Application") Set objDrive = objShell.Namespace(SSF_DRIVES).ParseName(strDrive) objDrive.InvokeVerb "E&amp;ject" End Sub </code></pre>
<p>This will work on Windows Server 2003, but not NT/2000/XP/Vista unfortunately.</p> <pre><code>strComputer = "." Set objWMIService = GetObject("winmgmts:" _ &amp; "{impersonationLevel=impersonate}!\\" &amp; strComputer &amp; "\root\cimv2") Set colItems = objWMIService.ExecQuery _ ("Select * From Win32_Volume Where Name = 'E:\\'") For Each objItem in colItems objItem.Dismount(True, True) Next </code></pre> <p>From <a href="http://www.microsoft.com/technet/scriptcenter/scripts/storage/disks/drives/stdvvb07.mspx?mfr=true" rel="nofollow noreferrer">Dismount a Volume</a>.</p>
<p>You can popup the eject dialog by using something like this. I am not sure if it possible to unmount a specific device.</p> <pre><code>Set WshShell = WScript.CreateObject("WScript.Shell") intReturn = WshShell.Run("RunDll32.exe shell32.dll,Control_RunDLL hotplug.dll", 1, TRUE) </code></pre>
37,921
<p>I'm currently using <a href="http://www.usysware.com/dpack/" rel="noreferrer">DPack</a> as this adds a "Collapse All Projects" option to the Solution node in Solution Explorer. It works pretty well but can take a while to execute and doesn't always collapse everything fully.</p> <p>Are there any better alternatives? Preferably free and easy to install/setup. There are lots out there but which work best and don't have any bugs or performance issues.</p>
<p>For VS2005, I've been using <a href="http://weblogs.asp.net/gmilano/archive/2006/10/17/Easily-Add-a-string-resource-with-CoolCommands.aspx" rel="noreferrer">CoolCommands 4.0</a>. The feature description is more complete for the <a href="http://weblogs.asp.net/gmilano/archive/2006/05/10/446010.aspx" rel="noreferrer">older 3.0 version</a>. Version 3 had an .msi installer. Version 4 is a <a href="http://download.deklarit.com/files/gmilano/coolcommands40.zip" rel="noreferrer">.zip file</a> (which was easier for my environment anyway).</p> <p>My favorite features (a subset of the complete list):</p> <ul> <li>From the Solution explorer: <ul> <li>Collapse All Projects</li> <li>Open containing folder (Project/file level only)</li> </ul></li> <li>From the filename tabs above the editor <ul> <li>Locate in Solution Explorer</li> </ul></li> <li>From the context menu in the editor <ul> <li>Demo Font</li> </ul></li> </ul>
<p><a href="http://visualstudiogallery.msdn.microsoft.com/e5f41ad9-4edc-4912-bca3-91147db95b99/" rel="nofollow">PowerCommands for Visual Studio</a> will work for both VS2008 and VS2010. It is the Microsoft-enabled way to do this quickly.</p>
10,868
<p>Before, I have found the "Cost" in the execution plan to be a good indicator of relative execution time. Why is this case different? Am I a fool for thinking the execution plan has relevance? What specifically can I try to improve v_test performance?</p> <p>Thank you.</p> <p>Using Oracle 10g I have a simple query view defined below</p> <pre><code> create or replace view v_test as select distinct u.bo_id as bo_id, upper(trim(d.dept_id)) as dept_id from cust_bo_users u join cust_bo_roles r on u.role_name=r.role_name join cust_dept_roll_up_tbl d on (r.region is null or trim(r.region)=trim(d.chrgback_reg)) and (r.prod_id is null or trim(r.prod_id)=trim(d.prod_id)) and (r.div_id is null or trim(r.div_id)=trim(d.div_id )) and (r.clus_id is null or trim(r.clus_id )=trim( d.clus_id)) and (r.prod_ln_id is null or trim(r.prod_ln_id)=trim(d.prod_ln_id)) and (r.dept_id is null or trim(r.dept_id)=trim(d.dept_id)) </code></pre> <p>defined to replace the following view</p> <pre><code> create or replace view v_bo_secured_detail select distinct Q.BO_ID, Q.DEPT_ID from (select U.BO_ID BO_ID, UPPER(trim(D.DEPT_ID)) DEPT_ID from CUST_BO_USERS U, CUST_BO_ROLES R, CUST_DEPT_ROLL_UP_TBL D where U.ROLE_NAME = R.ROLE_NAME and R.ROLE_LEVEL = 'REGION' and trim(R.REGION) = UPPER(trim(D.CHRGBACK_REG)) union all select U.BO_ID BO_ID, UPPER(trim(D.DEPT_ID)) DEPT_ID from CUST_BO_USERS U, CUST_BO_ROLES R, CUST_DEPT_ROLL_UP_TBL D where U.ROLE_NAME = R.ROLE_NAME and R.ROLE_LEVEL = 'RG_PROD' and trim(R.REGION) = UPPER(trim(D.CHRGBACK_REG)) and trim(R.PROD_ID) = UPPER(trim(D.PROD_ID)) union all select U.BO_ID BO_ID, UPPER(trim(D.DEPT_ID)) DEPT_ID from CUST_BO_USERS U, CUST_BO_ROLES R, CUST_DEPT_ROLL_UP_TBL D where U.ROLE_NAME = R.ROLE_NAME and R.ROLE_LEVEL = 'PROD' and trim(R.PROD_ID) = UPPER(trim(D.PROD_ID)) union all select U.BO_ID BO_ID, UPPER(trim(D.DEPT_ID)) DEPT_ID from CUST_BO_USERS U, CUST_BO_ROLES R, CUST_DEPT_ROLL_UP_TBL D where U.ROLE_NAME = R.ROLE_NAME and R.ROLE_LEVEL = 'DIV' and trim(R.DIV_ID) = UPPER(trim(D.DIV_ID)) union all select U.BO_ID BO_ID, UPPER(trim(D.DEPT_ID)) DEPT_ID from CUST_BO_USERS U, CUST_BO_ROLES R, CUST_DEPT_ROLL_UP_TBL D where U.ROLE_NAME = R.ROLE_NAME and R.ROLE_LEVEL = 'RG_DIV' and trim(R.REGION) = UPPER(trim(D.CHRGBACK_REG)) and trim(R.DIV_ID) = UPPER(trim(D.DIV_ID)) union all select U.BO_ID BO_ID, UPPER(trim(D.DEPT_ID)) DEPT_ID from CUST_BO_USERS U, CUST_BO_ROLES R, CUST_DEPT_ROLL_UP_TBL D where U.ROLE_NAME = R.ROLE_NAME and R.ROLE_LEVEL = 'CLUS' and trim(R.CLUS_ID) = UPPER(trim(D.CLUS_ID)) union all select U.BO_ID BO_ID, UPPER(trim(D.DEPT_ID)) DEPT_ID from CUST_BO_USERS U, CUST_BO_ROLES R, CUST_DEPT_ROLL_UP_TBL D where U.ROLE_NAME = R.ROLE_NAME and R.ROLE_LEVEL = 'RG_CLUS' and trim(R.REGION) = UPPER(trim(D.CHRGBACK_REG)) and trim(R.CLUS_ID) = UPPER(trim(D.CLUS_ID)) union all select U.BO_ID BO_ID, UPPER(trim(D.DEPT_ID)) DEPT_ID from CUST_BO_USERS U, CUST_BO_ROLES R, CUST_DEPT_ROLL_UP_TBL D where U.ROLE_NAME = R.ROLE_NAME and R.ROLE_LEVEL = 'PROD_LN' and trim(R.PROD_LN_ID) = UPPER(trim(D.PROD_LN_ID)) union all select U.BO_ID BO_ID, UPPER(trim(R.DEPT_ID)) DEPT_ID from CUST_BO_USERS U, CUST_BO_ROLES R where U.ROLE_NAME = R.ROLE_NAME and R.ROLE_LEVEL = 'DEPT') Q </code></pre> <p>with the goal of removing the dependency on the ROLE_LEVEL column.</p> <p>The execution plan for v_test is significantly lower than v_bo_secured_detail for simple</p> <pre><code>select * from &lt;view&gt; where bo_id='value' </code></pre> <p>queries. And is significantly lower when used in a real world query</p> <pre><code> select CT_REPORT.RPT_KEY, CT_REPORT_ENTRY.RPE_KEY, CT_REPORT_ENTRY.CUSTOM16, Exp_Sub_Type.value, min(CT_REPORT_PAYMENT_CONF.PAY_DATE), CT_REPORT.PAID_DATE from CT_REPORT, &lt;VIEW&gt; SD, CT_REPORT_ENTRY, CT_LIST_ITEM_LANG Exp_Sub_Type, CT_REPORT_PAYMENT_CONF, CT_STATUS_LANG Payment_Status where (CT_REPORT_ENTRY.RPT_KEY = CT_REPORT.RPT_KEY) and (Payment_Status.STAT_KEY = CT_REPORT.PAY_KEY) and (Exp_Sub_Type.LI_KEY = CT_REPORT_ENTRY.CUSTOM9 and Exp_Sub_Type.LANG_CODE = 'en') and (CT_REPORT.RPT_KEY = CT_REPORT_PAYMENT_CONF.RPT_KEY) and (SD.BO_ID = 'JZHU9') and (SD.DEPT_ID = UPPER(CT_REPORT_ENTRY.CUSTOM5)) and (Payment_Status.name = 'Payment Confirmed' and (Payment_Status.LANG_CODE = 'en') and CT_REPORT.PAID_DATE &gt; to_date('01/01/2008', 'mm/dd/yyyy') and Exp_Sub_Type.value != 'Korea') group by CT_REPORT.RPT_KEY, CT_REPORT_ENTRY.RPE_KEY, CT_REPORT_ENTRY.CUSTOM16, Exp_Sub_Type.value, CT_REPORT.PAID_DATE </code></pre> <p>The execution times are WILDLY different. The v_test view taking 15 hours, and the v_bo_secured_detail taking a few seconds.</p> <hr> <p><strong>Thank you all who responded</strong></p> <p>This is one to remember for me. The places where the theory and mathematics of the expressions meets the reality of hardware based execution. Ouch.</p>
<p>As <a href="http://download.oracle.com/docs/cd/A87860_01/doc/server.817/a76965/c20a_opt.htm#16287" rel="nofollow noreferrer">the Oracle documentation says</a>, the cost is the estimated cost relative to a particular execution plan. When you tweak the query, the particular execution plan that costs are calculated relative to can change. Sometimes dramatically.</p> <p>The problem with v_test's performance is that Oracle can think of no way to execute it other than performing a nested loop, for each cust_bo_roles, scan all of cust_dept_roll_up_tbl to find a match. If the table are of size n and m, this takes n*m time, which is slow for large tables. By contrast v_bo_secured_detail is set up so that it is a series of queries, each of which can be done through some other mechanism. (Oracle has a number it may use, including using an index, building a hash on the fly, or sorting the datasets and merging them. These operations are all O(n*log(n)) or better.) A small series of fast queries is fast.</p> <p>As painful as it is, if you want this query to be fast then you need to break it out like the previous query did.</p>
<p>Have you gathered optimiser stats on all the underlying tables? Without them the optimiser's estimates may be wildly out of kilter with reality.</p>
12,806
<p>I've seen various options for URL rewriting here on Stack Overflow, and other places on the web, but was curious to see if there were other options.</p>
<p>This is speculation, as Cookies and URL Rewriting are the big two, but technologically, I think it'd be possible to:</p> <ul> <li>do some massive hackery with javascript that captures all links and submits a form with information.</li> <li>track the session on the server based on IP</li> </ul> <p>Both have their downsides and holes obviously.</p>
<p>Session variables? At work, we are not allowed to use non session-cookies without a load of permissions.</p>
31,169