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 Sharepoint Server 2007 Statemachine Workflow. Until now i have a few states and an custom Association/InitiationForm which i created with InfoPath 2007. At the moment i have a Problem with Modification forms. The modification link in the state page of my workflow is shown and leads on click to my InfoPath form. If i click the "Submit" button the form is closed. Everything works fine. Now i tried to add a second ModificationForm to my workflow. So i created a new InfoPath form and added it in the same way to the workflow as the first one. The workflow has no errors in the building or deploying-process. But if i now try to click the second Modification link in the state page the form is not shown. Instead of my form the text: "The form has been closed." is shown.</p> <p>I looked in the central administration and the InfoPath form is know under "Manage form templates". I gave every Modification in the Workflow.xml his own Guid. I used the following ModificationUrl: ModificationUrl="_layouts/ModWrkflIP.aspx"</p> <p>Does anybody know step by step how to use two or more ModificationForms in my workflow?</p> <p>Thank you in advance. </p>
<p>Thank you very much. I found the following Error Message in the Logfile:</p> <p>"Form load failed with a validation error"</p> <p>I searched in the web for solutions for this problem and fount this site:</p> <p><a href="http://social.msdn.microsoft.com/forums/en-US/sharepointworkflow/thread/83264f93-ebe3-49ec-bd6b-95ee02df4d8a/" rel="nofollow noreferrer">http://social.msdn.microsoft.com/forums/en-US/sharepointworkflow/thread/83264f93-ebe3-49ec-bd6b-95ee02df4d8a/</a></p> <p>I had two sceme files and i just schould use one for both forms. So i had to use the same data source. That was all. Thank you for the hint.</p>
<p>Look in your ULS logs for the error message. It will be listed there 100%. The category is "Forms Services" - the logs are located under the 12 hive in LOGS\</p>
15,566
<p>I have to put an excel file online on a web server (Apache) with some basic password protection (basic http auth). User, however, should be able to open the file from within excel and save their changes back to the server. </p> <p>Is there any simple and effective solution for it? I am not very experienced with webdav.</p>
<p>Maybe use <a href="http://docs.google.com/" rel="nofollow noreferrer">Google Docs</a> to share the document. That would be as turn-key as it gets. :)</p>
<p>Webdav can do this. Might be a hassle to set it up.</p>
18,725
<p>We are designing a survey application with the following features</p> <ol> <li>The users will be able to select questions from a set of predefined questions.</li> <li>Each question has a question type defined which dictates the type of answer (multiple choice, DB look up, free text etc) </li> <li>The user can create a hierarchy of sections with multiple questions with in each section.</li> <li>The responses of the survey will be stored to an SQL server database.</li> </ol> <p>There is also a requirement to generate an output document from each survey response.</p> <p>We are planning to implement this application using ASP.net.</p> <p>I am looking for suggestions which will help us reduce the development effort. Is there any commercial/open source application which we can customize for our needs? is there any ready-made components which helps creation of dynamic ASP.net pages? I am only interested in application which i can host locally, as this has to be integrated to an existing application.</p>
<p>This may not be an exact fit, but worth looking at: <a href="http://www.surveymonkey.com/" rel="nofollow noreferrer">Surveymonkey</a>.</p>
<p><a href="http://www.nsurvey.org/" rel="nofollow noreferrer">NSurvey</a> used to exist for this, but I think they've gone solely commercial. If you can dig up the last open source release, it might be a good starting point.</p> <p>Otherwise, don't build it. Subscribe to <a href="http://wufoo.com" rel="nofollow noreferrer">Wufoo</a></p>
21,173
<p>The MSDN states that the method returns</p> <blockquote> <p>true if the method is successfully queued; NotSupportedException is thrown if the work item is not queued.</p> </blockquote> <p>For testing purposes how to get the method to return <code>false</code>? Or it is just a "suboptimal" class design?</p>
<p>In looking at the source code in Reflector, it seems the only part of the code that could return "false" is a call to the following:</p> <pre><code>[MethodImpl(MethodImplOptions.InternalCall)] private static extern bool AdjustThreadsInPool(uint QueueLength); </code></pre>
<p>This is probably a case of "reserved for future use". You may want to treat it as failure, but it'll be hard to test.</p> <p>I pretty much treat this method as a void/Sub.</p>
18,160
<p>What is the return value of the <code>WaitForObject()</code> function?</p> <p>I do not mean the type of return value (int).</p> <p>What does it return if the event is signalled and what does it return if the event is not signalled?</p>
<p>There is no <code>WaitForObject</code> function. I assume that you mean either <code>WaitForSingleObject</code> or <code>WaitForMultipleObjects</code>.</p> <p><code>WaitForSingleObject</code> will return <code>WAIT_TIMEOUT</code>, <code>WAIT_OBJECT_0</code> or <code>WAIT_ERROR</code>. <code>WaitForMultipleObjects</code> will return <code>WAIT_TIMEOUT</code>, <code>WAIT_OBJECT_0 + n</code> (where n is the index to the object in the array) or <code>WAIT_ERROR</code>.</p>
<p>This question isn't C++. C++ has no API called <code>WaitForObject</code>. The Windows API has a function called <code>WaitForSingleObject</code> and another called <code>WaitForMultipleObjects</code>.</p> <p>These functions return -1 on failure, 0 if the first object in the array is signalled, and a number &gt;= 0x80 if the wait times out or is abandoned. (0x80 if abandoned, 0x102 if there is a timeout).</p>
25,613
<p>How do I find the name of the namespace or module 'Foo' in the filter below?</p> <pre><code>class ApplicationController &lt; ActionController::Base def get_module_name @module_name = ??? end end class Foo::BarController &lt; ApplicationController before_filter :get_module_name end </code></pre>
<p>None of these solutions consider a constant with multiple parent modules. For instance:</p> <pre><code>A::B::C </code></pre> <p>As of Rails 3.2.x you can simply:</p> <pre><code>"A::B::C".deconstantize #=&gt; "A::B" </code></pre> <p>As of Rails 3.1.x you can:</p> <pre><code>constant_name = "A::B::C" constant_name.gsub( "::#{constant_name.demodulize}", '' ) </code></pre> <p>This is because #demodulize is the opposite of #deconstantize:</p> <pre><code>"A::B::C".demodulize #=&gt; "C" </code></pre> <p>If you really need to do this manually, try this:</p> <pre><code>constant_name = "A::B::C" constant_name.split( '::' )[0,constant_name.split( '::' ).length-1] </code></pre>
<p>I don't think there is a <em>cleaner</em> way, and I've seen this somewhere else</p> <pre><code>class ApplicationController &lt; ActionController::Base def get_module_name @module_name = self.class.name.split("::").first end end </code></pre>
16,144
<p>What is the best method to parse multiple, discrete, custom XML documents with Java?</p>
<p>I would use <a href="http://jcp.org/en/jsr/detail?id=173" rel="noreferrer">Stax</a> to parse XML, it's fast and easy to use. I've been using it on my last project to parse XML files up to 24MB. There's a nice introduction on <a href="http://today.java.net/pub/a/today/2006/07/20/introduction-to-stax.html" rel="noreferrer">java.net</a>, which tells you everything you need to know to get started.</p>
<p>Below is the code of extracting some value value using <a href="http://vtd-xml.sf.net" rel="nofollow">vtd-xml</a>.</p> <pre><code>import com.ximpleware.*; public class extractValue{ public static void main(String s[]) throws VTDException, IOException{ VTDGen vg = new VTDGen(); if (!vg.parseFile("input.xml", false)); VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("/aa/bb[name='k1']/value"); int i=0; while ((i=ap.evalXPath())!=-1){ System.out.println(" value ===&gt;"+vn.toString(i)); } } } </code></pre>
4,311
<p>After "check-in" of a <code>.docx</code> file to <code>SharePoint</code> and editing it the <code>RevNum</code> property is set to <code>2</code>.</p> <p>This does not make sense, can someone explain why this is?</p>
<p>Well, first of all, you're wasting memory with the new <code>HashMap</code> creation call. Your second line completely disregards the reference to this created hashmap, making it then available to the garbage collector. So, don't do that, use:</p> <pre><code>private Map&lt;String, String&gt; someMap = (HashMap&lt;String, String&gt;)getApplicationContext().getBean("someMap"); </code></pre> <p>Secondly, the compiler is complaining that you cast the object to a <code>HashMap</code> without checking if it is a <code>HashMap</code>. But, even if you were to do:</p> <pre><code>if(getApplicationContext().getBean("someMap") instanceof HashMap) { private Map&lt;String, String&gt; someMap = (HashMap&lt;String, String&gt;)getApplicationContext().getBean("someMap"); } </code></pre> <p>You would probably still get this warning. The problem is, <code>getBean</code> returns <code>Object</code>, so it is unknown what the type is. Converting it to <code>HashMap</code> directly would not cause the problem with the second case (and perhaps there would not be a warning in the first case, I'm not sure how pedantic the Java compiler is with warnings for Java 5). However, you are converting it to a <code>HashMap&lt;String, String&gt;</code>.</p> <p>HashMaps are really maps that take an object as a key and have an object as a value, <code>HashMap&lt;Object, Object&gt;</code> if you will. Thus, there is no guarantee that when you get your bean that it can be represented as a <code>HashMap&lt;String, String&gt;</code> because you could have <code>HashMap&lt;Date, Calendar&gt;</code> because the non-generic representation that is returned can have any objects.</p> <p>If the code compiles, and you can execute <code>String value = map.get("thisString");</code> without any errors, don't worry about this warning. But if the map isn't completely of string keys to string values, you will get a <code>ClassCastException</code> at runtime, because the generics cannot block this from happening in this case.</p>
<p>Another solution, if you find yourself casting the same object a lot and you don't want to litter your code with <code>@SupressWarnings("unchecked")</code>, would be to create a method with the annotation. This way you're centralizing the cast, and hopefully reducing the possibility for error.</p> <pre><code>@SuppressWarnings("unchecked") public static List&lt;String&gt; getFooStrings(Map&lt;String, List&lt;String&gt;&gt; ctx) { return (List&lt;String&gt;) ctx.get("foos"); } </code></pre>
32,835
<p>I have a spreadsheet with a dataset of a number of transactions, each of which is composed of substeps, each of which has the time that it occurred. There can be a variable number and order of steps.</p> <p>I'd like to find the duration of each transaction. If I can do this in Excel then great, as it's already in that format. If there isn't a straight-forward way to do this in Excel, I'll load it into a database and do the analysis with SQL. If there is an Excel way round this it'll save a few hours setup though :)</p> <p>A simplified example of my data is as follows:</p> <p>TransID, Substep, Time<br> 1, step A, 15:00:00<br> 1, step B, 15:01:00<br> 1, step C, 15:02:00<br> 2, step B, 15:03:00<br> 2, step C, 15:04:00<br> 2, step E, 15:05:00<br> 2, step F, 15:06:00<br> 3, step C, 15:07:00<br> 3, step D, 15:08:00<br> etc.</p> <p>I'd like to produce a result set as follows:</p> <p>TransID, Duration<br> 1, 00:02:00<br> 2, 00:03:00<br> 3, 00:01:00<br> etc.</p> <p>My initial try was with an extra column with a formula subtracting end time from start time, but without a repeating number of steps, or the same start and end steps I'm having difficulty seeing how this formula would work.</p> <p>I've also tried creating a pivot table based on this data with ID as the rows and Time as the data. I can change the field settings on the time data to return grouped values such as count or max, but am struggling to see how this can be setup to show max(time) - min(time) for each ID, hence why I'm thinking about heading to SQL. If anyone can point out anything obvious I'm missing though, I'd be very grateful.</p> <p>As suggested by Hobbo, I've now used a pivot table with TransID as the rows and twice added Time as the data. After setting the field settings on the Time to Max on the first and Min on the second, a formula can be added just outside the pivot table to calculate the differences. One thing I'd been overlooking here is that the same value can be added to the data section more than once!</p> <p>A follow-on problem was that the formula I add is of the form =GETPIVOTDATA("Max of Time",$A$4,"ID",1)-GETPIVOTDATA("Min of Time",$A$4,"ID",1), whici doesn't then increment when copying and pasting. Solutions to this are to either use the pivot table toolbar to turn off GETPIVOTDATA formulae, or rather than clicking on the pivot table when selecting cells in the formula, type the cell references instead (e.g. =H4-G4)</p>
<p>You were on the right lines with pivot tables. Drag in TransID as a row field then drag in two copies of Time as data fields in the pivot table; right click on each and specify Min as the summarization function for one and Max for the other. To the right of the pivot table add a formula to calculate the difference.</p> <p><a href="http://img296.imageshack.us/img296/5866/pivottableey5.jpg" rel="nofollow noreferrer">alt text http://img296.imageshack.us/img296/5866/pivottableey5.jpg</a></p> <p>"Looks good, the only problem I have is that the formula I add is of the the form =GETPIVOTDATA("Max of Time, $A$4, "ID", 1) - GETPIVOTDATA("Max of Time, $A$4, "ID", 1). When I copy that to the cells below, the 1 doesn't update to 2, 3 etc so they all show the same time. – Kris Coverdale "</p> <p>Use this button on the pivot table toolbar to switch GETPIVOTDATA formulae off.</p> <p><a href="http://img117.imageshack.us/img117/9937/pivottabletoolbarjn3.jpg" rel="nofollow noreferrer">alt text http://img117.imageshack.us/img117/9937/pivottabletoolbarjn3.jpg</a></p>
<p>Sometimes it is possible to do something once in Excel far more easily than it is to do something repeatably.</p> <p>Assuming you are just trying to get the answer once or twice, and then throw away the spreadsheet (as opposed to run it every night, or give it to someone else to run), here's how I would do it.</p> <p>I assume your raw data is in columns A, B and C, with headings in row 1, and data starting in row 2.</p> <p>Sort the table by TransId as your primary key, and Time as your secondary, both ascending. (The following won't work if this isn't done.)</p> <p>Add a new column, D, titled Duration with a formula that like this (Excel formulae haven't formatting or comments; I have added those to help explain, but they need to be stripped out):</p> <pre><code>=IF(B2=B3, // if this row's TransId is the same as the next one "", // leave this field blank C3- // else find the difference between the last timestamp and... VLOOKUP( // look for the first value A2, // matching this TransId A:C, // within the entire table, 3) // Return the value in the third column - i.e. timestamp ) </code></pre> <p>Now the data you want is in column D, but not in the format you want.</p> <p>Select Columns A-D and copy them. Use Paste Special to copy the <em>values</em> only into a new worksheet. </p> <p>Delete column B and column C in the new worksheet, so all is left is TransID and Duration. </p> <p>Sort by Duration, to bring all the rows with values next to each other. </p> <p>Sort only the rows with values by TransId. </p> <p>Voila, and there is your solution! Hope you don't need to repeat this!</p> <p>p.s. This is untested</p>
43,038
<pre><code>const static int foo = 42; </code></pre> <p>I saw this in some code here on StackOverflow and I couldn't figure out what it does. Then I saw some confused answers on other forums. My best guess is that it's used in C to hide the constant <code>foo</code> from other modules. Is this correct? If so, why would anyone use it in a C++ context where you can just make it <code>private</code>?</p>
<p>It has uses in both C and C++.</p> <p>As you guessed, the <code>static</code> part limits its scope to that <a href="https://stackoverflow.com/questions/1106149/what-is-a-translation-unit-in-c">compilation unit</a>. It also provides for static initialization. <code>const</code> just tells the compiler to not let anybody modify it. This variable is either put in the data or bss segment depending on the architecture, and might be in memory marked read-only.</p> <p>All that is how C treats these variables (or how C++ treats namespace variables). In C++, a member marked <code>static</code> is shared by all instances of a given class. Whether it's private or not doesn't affect the fact that one variable is shared by multiple instances. Having <code>const</code> on there will warn you if any code would try to modify that.</p> <p>If it was strictly private, then each instance of the class would get its own version (optimizer notwithstanding).</p>
<p>Making it private would still mean it appears in the header. I tend to use "the weakest" way that works. See this classic article by Scott Meyers: <a href="http://www.ddj.com/cpp/184401197" rel="nofollow noreferrer">http://www.ddj.com/cpp/184401197</a> (it's about functions, but can be applied here as well).</p>
21,374
<p>I have created a report in MS Access report and write some VBA code to retrive data and show the report in MS-Word format. But while generate the report on runtime, the report first show or flash the report design view for few seconds and the report will get generated. </p> <p>I would like to find a solution to avoid this flashing of design view while generate the report. Is it possible in this MS-Access or VBA coding. ??</p> <p>I am posting the lines which i used to call the access report from access form code.</p> <p>DoCmd.OpenReport rst![Argument], acPreview</p> <p>this will generate the report but the design screen is flashing for few seconds while execution. </p> <p>And there is no VBA code has been written in the access report.</p> <p>The actual running is, i have prepare the data in a temp access table and generate the report from the table. </p> <p>The problem here is, while launching the report in preview mode the design screen of the report shows of some few seconds. This looks bad from the users side. </p>
<p>It seems you are opening the report in design view in order to change some property. It may be possible to avoid this, but you would need to post the code that opens the report to say for sure.</p>
<p>How are you exporting the report to MS-Word? What's the code?</p> <p>Have you tried the same thing with a simple report (with a table data source) instead of using VBA code? Maybe the VBA is taking so long to run that it's holding the Report open in design mode long enough to be perceptible.</p>
32,666
<p>I tried this step:</p> <p>Select the menu options "Project > New Build Phase > New Run Script Build Phase", and enter the following script (don't forget to replace /Users/youruser/bin by the correct path to gen_entitlements.py) :</p> <pre><code>export CODESIGN_ALLOCATE=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate if [ "${PLATFORM_NAME}" == "iphoneos" ]; then /Users/youruser/bin/gen_entitlements.py "my.company.${PROJECT_NAME}" "${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/${PROJECT_NAME}.xcent"; codesign -f -s "iPhone developer" --resource-rules "${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/ResourceRules.plist" \ --entitlements "${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/${PROJECT_NAME}.xcent" "${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/" fi </code></pre> <p>(from <a href="http://www.246tnt.com/iPhone/#xcode" rel="noreferrer">link</a>)</p> <p>Now I want to remove this script from my project. How do I remove the "Run Script Build Phase" build phase from Xcode?</p>
<p>Select the Run Script phase in your target and delete it.</p> <p><img src="https://i.stack.imgur.com/pQ9uu.png" alt="Delete"></p>
<ol> <li>In the Project Navigator go to the upper left hand corner and select the blue icon</li> </ol> <p><a href="https://i.stack.imgur.com/PGLfm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PGLfm.png" alt="enter image description here"></a></p> <ol start="2"> <li>In the top center of the screen select <code>Build Phases</code></li> </ol> <p><a href="https://i.stack.imgur.com/BVCzX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BVCzX.png" alt="enter image description here"></a></p> <ol start="3"> <li>When you see the <code>Run Script</code> that you want to delete look all the way on the right hand corner of it and you'll see an <code>X</code></li> </ol> <p><a href="https://i.stack.imgur.com/0Wtqi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0Wtqi.png" alt="enter image description here"></a></p> <ol start="4"> <li>Press the <code>X</code> and you'll see a menu appear asking if you want to delete it</li> </ol> <p><a href="https://i.stack.imgur.com/IkSX6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IkSX6.png" alt="enter image description here"></a></p> <ol start="5"> <li>Choose <code>Delete</code></li> </ol>
31,502
<p>I would like to be able to monitor my major system health indicators from inside our Java-based system. Major points of interest include CPU temperature, motherboard temperature, fan speed, etc. </p> <p>Is there a package available that:</p> <ol> <li>Makes this sort of data available to Java?</li> <li>Works on Windows or Linux or both?</li> <li>Is open / free / cheap?</li> </ol>
<p>The closest thing you'll find is the Hyperic Sigar library:</p> <p><a href="http://www.hyperic.com/products/sigar.html" rel="noreferrer">http://www.hyperic.com/products/sigar.html</a></p> <p>It doesn't get down to temperatures AFAIK but does show you a number of native stats like CPU, memory, disk I/O, network I/O, etc. It's ported to most of the architectures people are deploying Java on today. License is GPL although I think you can buy commercial licenses as well.</p> <p>We use Sigar with Terracotta for cluster monitoring and have been very happy with it.</p>
<p>A few months ago I looked for such a library and I found nothing interesting. It is not impossible to create one, so I would recommend doing so. You'll probably need to access native libraries, to do that use <a href="https://github.com/twall/jna" rel="nofollow noreferrer">JNA</a> (it's easier than JNI). Start by adding support for a few things on one platform, then start adding support for other features and platforms.</p> <p>The share it with us! People will starts using it, maybe even help with development and soon you'll have a fully featured system monitoring library for Java.</p>
14,260
<p>I'm new to this SCM, but since SVN is gaining popularity I was going to give it a try.</p> <p>Things I noticed:</p> <ol> <li>SVN is only the backbone of the SCM, no front-end?</li> <li>Why is there several versions of Windows Binaries? Tigris? SlikSVN? VisualSVN?</li> <li>Do I need a Web Server like Apache in order to use SVN?</li> <li>There's dozens of front-end, Tortoise, WinSVN, etc... Which one is recommended?</li> </ol> <p>The whole thing is rather confusing and I got no idea where to start. I'm using Delphi and would like to use it to store my source files.</p> <p>Update 1: Seems I got it working using the "file:///" protocol, thanks. Now, how do I configure it as a server with client PCs.</p>
<p><a href="http://blog.excastle.com/2007/04/09/subversion-in-delphis-tools-menu/" rel="nofollow noreferrer">Here's a great guide</a> for integrating TortoiseSVN with Delphi's "Tools" menu.</p> <p>This site shows how to add the following into the IDE:</p> <ol> <li><p><code>svn Commit</code>: Opens the TortoiseSVN commit window.</p></li> <li><p><code>svn Diff</code>: Shows diffs for the file currently being edited. (If you've configured an external diff viewer like Beyond Compare, this will use it.)</p></li> <li><p><code>svn Modifications</code>: Opens the TortoiseSVN modifications window, which shows a list of all modified files.</p></li> <li><code>svn Update</code>: Updates your working copy with the latest changes from the repository.</li> </ol> <p><a href="http://hallvards.blogspot.com/2007/04/subversion-in-delphis-tools-menu.html" rel="nofollow noreferrer">If you don't have Ruby installed (as the guide suggests using), simply replace it with a simple online batch file instead</a>:</p> <pre><code>"c:/program files/tortoisesvn/bin/tortoiseproc.exe" /command:%1 /path:%2 /notempfile </code></pre> <p>Then create the Tools items with:</p> <p>Program: <code>c:\windows\system32\cmd.exe</code></p> <p>Parameters: <code>/C C:\SvnPas\Utils\Batch\SvnCmd.Bat diff $EDNAME $SAVEALL</code></p>
<p>Set up svn on a windows or linux box somewhere and enable the SVN: protocol. This pretty simple to install and configure. The documentation is pretty clear.</p> <p>Then use TortoiseSVN to check in/update your code. It's really easy to use.</p> <p>1) SVN is only the backbone of the SCM, no front-end? It's command line. You can use it as a command line tool, but Tortoise is the way forward if you use windows.</p> <p>2) Why is there several versions of Windows Binaries? Tigris? SlikSVN? VisualSVN?</p> <p>Different binaries for different OS's.</p> <p>3) Do I need a Web Server like Apache in order to use SVN?</p> <p>No.</p> <p>4) There's dozens of front-end, Tortoise, WinSVN, etc... Which one is recommended?</p> <p>TortoiseSVN if you use windows.</p>
48,404
<p>Right now, I am trying to create a plug-in of Eclipse which depends on other jar; therefore, I created a plug-in base on the jar and deployed it under my Eclipses' plugin foler. It works well when I start it from my working environment via an Eclipse. However, as soon as I have exported it into a jar and have deployed into Eclipse, it not work any more as it couldn't find out the dependent jar. What happened and how to solve the issue? Does anyone know that? please save me.</p>
<p>The MANIFEST.MF has a Tab called "Dependencies" in which alle plugins should placed the current plugin depends on. At runtime you have to place the "dependencies" plugins in the same folder as the one you want to start or you want to work with.</p> <p>When a plugin has jars it should use, you have to put the jars to the "Runtime" Classpath Entry and you should add the jar to the "Build" Binary Build entry.</p>
<p>The working behavior out of Eclipse is normal, since the dependent jar is in the classpath of the project.</p> <p>Have you had a look at the plugin folder you deployed? I suspect, that the dependency isn't contained in the plugin folder.</p>
43,186
<p>After selecting "Safe Remove" option in windows system tray, is there any way that I can re-detect my Flash by a code, without plug it out and again inserting it to the computer USB port?</p>
<p>You can look at re-scanning the system for devices. Test this with Microsoft's <a href="http://support.microsoft.com/kb/311272" rel="nofollow noreferrer">devcon</a> tool (this demonstrates SetupAPI and CfgMgr32 functionality). The source code for the tool is available in the <a href="http://www.microsoft.com/whdc/devtools/ddk/default.mspx" rel="nofollow noreferrer">Windows DDK</a>.</p>
<p>The program "USB Safely Remove" do that and more. But is shareware.</p>
44,746
<p>Sounds easy, but I can't find where this built in class and others exists in the documentation. I use functions but want to know what there is on the OO side.</p>
<p>It's not a URL or anything, but you can get a fair idea using Reflection:</p> <pre><code>Reflection::export(new ReflectionClass('DateTime')); Class [ class DateTime ] { - Constants [11] { Constant [ string ATOM ] { Y-m-d\TH:i:sP } Constant [ string COOKIE ] { l, d-M-y H:i:s T } Constant [ string ISO8601 ] { Y-m-d\TH:i:sO } Constant [ string RFC822 ] { D, d M y H:i:s O } Constant [ string RFC850 ] { l, d-M-y H:i:s T } Constant [ string RFC1036 ] { D, d M y H:i:s O } Constant [ string RFC1123 ] { D, d M Y H:i:s O } Constant [ string RFC2822 ] { D, d M Y H:i:s O } Constant [ string RFC3339 ] { Y-m-d\TH:i:sP } Constant [ string RSS ] { D, d M Y H:i:s O } Constant [ string W3C ] { Y-m-d\TH:i:sP } } - Static properties [0] { } - Static methods [0] { } - Properties [0] { } - Methods [9] { Method [ public method __construct ] { } Method [ public method format ] { } Method [ public method modify ] { } Method [ public method getTimezone ] { } Method [ public method setTimezone ] { } Method [ public method getOffset ] { } Method [ public method setTime ] { } Method [ public method setDate ] { } Method [ public method setISODate ] { } } } </code></pre> <p>Not perfect, as there are no arguments, but a starting point at least. They should make this easier to find out, I agree!</p>
<p>There is a list of new classes in PHP 5.2.0 here:</p> <p><a href="http://www.php.net/manual/en/migration52.classes.php" rel="nofollow noreferrer">http://www.php.net/manual/en/migration52.classes.php</a></p> <p>..which links to the new DateTime class info here:</p> <p><a href="http://www.php.net/manual/en/ref.datetime.php" rel="nofollow noreferrer">http://www.php.net/manual/en/ref.datetime.php</a></p>
40,872
<p>I imagine there are many of you out there who have developed an application online which automates a lot of processes and saves people at your company time and money.</p> <p>The question is, what are your experiences with developing that application, having it all set in place, then "spicing" it up with some Ajax, so it makes for a better user experience?</p> <p>Also, what libraries would you suggest using when adding Ajax to an already-developed web application?</p> <p>Lastly, what are some common processes you see in web applications that Ajax does well with? For example, auto-populating the search box as you type.</p>
<p>My preferred way of building Ajax-enabled applications is to build it the old-fashioned way where every button, link, etc. posts to the server, and then hijack all those button, link, etc. clicks to the Ajax functionality.</p> <p>This ensures that my app is down-browser compatible, which is good.</p>
<p>If you are using ASP.NET to write your applications, adding AJAX using ASP.NET AJAX is very straightforward and in many places will not require you to change any code at all except add two controls to the pages you want to modify.</p> <p>This works using partial page loads. The controls you have to add (off the top off my head) are called something like</p> <pre><code>&lt;asp:ScriptManager </code></pre> <p>and</p> <pre><code>&lt;asp:UpdatePanel </code></pre>
25,801
<p>I created an ASMX file with a code behind file. It's working fine, but it is outputting XML.</p> <p>However, I need it to output JSON. The ResponseFormat configuration doesn't seem to work. My code-behind is:</p> <pre><code>[System.Web.Script.Services.ScriptService] public class _default : System.Web.Services.WebService { [WebMethod] [ScriptMethod(UseHttpGet = true,ResponseFormat = ResponseFormat.Json)] public string[] UserDetails() { return new string[] { "abc", "def" }; } } </code></pre>
<p>From <a href="http://forums.asp.net/p/1327142/2652827.aspx" rel="noreferrer">WebService returns XML even when ResponseFormat set to JSON</a>:</p> <blockquote> <p>Make sure that the request is a POST request, not a GET. Scott Guthrie has a <a href="http://weblogs.asp.net/scottgu/archive/2007/04/04/json-hijacking-and-how-asp-net-ajax-1-0-mitigates-these-attacks.aspx" rel="noreferrer">post explaining why</a>.</p> <p>Though it's written specifically for jQuery, this may also be useful to you:<br /> <a href="http://web.archive.org/web/20160424034823/http://encosia.com/using-jquery-to-consume-aspnet-json-web-services" rel="noreferrer">Using jQuery to Consume ASP.NET JSON Web Services</a></p> </blockquote>
<p>Are you calling the web service from client script or on the server side?</p> <p>You may find sending a content type header to the server will help, e.g. </p> <p>'application/json; charset=utf-8'</p> <p>On the client side, I use prototype client side library and there is a contentType parameter when making an Ajax call where you can specify this. I think jQuery has a getJSON method.</p>
25,968
<p>I've done most of my work on VisualStudio and don't have much experience with gcc or g++. When I tried to compile a (ex. aprogram.cpp) this morning on my pc using cygwin, I got (aprogram.exe) when I tried to compile the same thing on my Ubuntu box I got (aprogram) w/o any extension. I am just wondering if someone be kind enough to tell me why. This question is just out of curiosity. :)</p> <p>Thanks in advance!</p> <p>EDIT: (from Jimmy's comment) g++ under Cygwin defaults to .exe </p>
<p>It's just a naming convention. On Unix/Linux, executables don't have an extension, just an executable bit.</p>
<p>ls /bin There are lot's of programs and all of them without extension :)</p> <p>ls -l /bin you will see that all of them has +x flag to mark them as an executable.</p>
46,925
<p>How do I write a cpp macro which expands to include newlines?</p>
<p>I am working on a large project that involves a lot of preprocessor macro functions to synthesize any code that cannot be replaced by templates. Believe me, I am familiar with all sorts of template tricks, but as long as there is no standardized, type safe metaprogramming language that can directly create code, we will have to stick with good old preprocessor and its cumbersome macros to solve some problems that would require to write ten times more code without. Some of the macros span many lines and they are very hard to read in preprocessed code. Therefore, I thought of a solution to that problem and what I came up with is the following:</p> <p>Let's say we have a C/C++ macro that spans multiple lines, e.g. in a file named <em>MyMacro.hpp</em></p> <pre><code>// Content of MyMacro.hpp #include "MultilineMacroDebugging.hpp" #define PRINT_VARIABLE(S) \ __NL__ std::cout &lt;&lt; #S &lt;&lt; ": " &lt;&lt; S &lt;&lt; std::endl; \ __NL__ /* more lines if necessary */ \ __NL__ /* even more lines */ </code></pre> <p>In every file where I defined such a macro, I include another file <em>MultilineMacroDebugging.hpp</em> that contains the following:</p> <pre><code>// Content of MultilineMacroDebugging.hpp #ifndef HAVE_MULTILINE_DEBUGGING #define __NL__ #endif </code></pre> <p>This defines an empty macro <code>__NL__</code>, which makes the <code>__NL__</code> definitions disappear during preprocessing. The macro can then be used somewhere, e.g. in a file named <em>MyImplementation.cpp</em>.</p> <pre><code>// Content of MyImplementation.cpp // Uncomment the following line to enable macro debugging //#define HAVE_MULTILINE_DEBUGGING #include "MyMacro.hpp" int a = 10; PRINT_VARIABLE(a) </code></pre> <p>If I need to debug the <code>PRINT_VARIABLE</code> macro, I just uncomment the line that defines the macro <code>HAVE_MULTILINE_DEBUGGING</code> in <em>MyImplementation.cpp</em>. The resulting code does of course not compile, as the <code>__NL__</code> macro results undefined, which causes it to remain in the compiled code, but it can, however, be preprocessed.</p> <p>The crucial step is now to replace the <code>__NL__</code> string in the preprocessor output by newlines using your favorite text editor and, voila, you end up with a readable representation of the result of the replaced macro after preprocessing which resembles exactly what the compiler would see, except for the artificially introduced newlines.</p>
<p>Use <code>\</code>, like so:</p> <pre><code>#define my_multiline_macro(a, b, c) \ if (a) { \ b += c; \ } </code></pre>
12,425
<p>I use a axis to auto-generate webservice artifacts which I then convert into objects used within our application. Is there a sensible pattern for doing this ? We have written transform methods to output our objects from the axis created objects, at other times we have written an intermediate set of transformer classes that transform the axis objects to our application objects? Is there a common way of approaching this?</p>
<p>If I understand correctly, you want to use Axis WSDL2Java feature to generate code from a WSDL and then map that to your existing application object model. In that case, you might want to consider to use Axis with <a href="http://jibx.sourceforge.net/" rel="nofollow noreferrer">JiBX</a> binding.</p>
<p>We have run into similar issues in the past. Recently, for a complex web service that we had Axis generate artifacts for, we wound up with 157 Java classes with names like "MaintainOffersRequestTypeReqReqDataMaintEnhancementCancellationReason".</p> <p>We wound up writing classes that transform these Axis-generated objects into business objects, similar to your last idea. I don't know if it's the best way, but it's certainly a workable solution.</p>
29,774
<p>Let's say we have <code>0.33</code>, we need to output <code>1/3</code>. <br /> If we have <code>0.4</code>, we need to output <code>2/5</code>.</p> <p>The idea is to make it human-readable to make the user understand "<strong>x parts out of y</strong>" as a better way of understanding data.</p> <p>I know that percentages is a good substitute but I was wondering if there was a simple way to do this?</p>
<p>I have found David Eppstein's <a href="http://www.ics.uci.edu/%7Eeppstein/numth/frap.c" rel="nofollow noreferrer">find rational approximation to given real number</a> C code to be exactly what you are asking for. Its based on the theory of continued fractions and very fast and fairly compact.</p> <p>I have used versions of this customized for specific numerator and denominator limits.</p> <pre class="lang-c prettyprint-override"><code>/* ** find rational approximation to given real number ** David Eppstein / UC Irvine / 8 Aug 1993 ** ** With corrections from Arno Formella, May 2008 ** ** usage: a.out r d ** r is real number to approx ** d is the maximum denominator allowed ** ** based on the theory of continued fractions ** if x = a1 + 1/(a2 + 1/(a3 + 1/(a4 + ...))) ** then best approximation is found by truncating this series ** (with some adjustments in the last term). ** ** Note the fraction can be recovered as the first column of the matrix ** ( a1 1 ) ( a2 1 ) ( a3 1 ) ... ** ( 1 0 ) ( 1 0 ) ( 1 0 ) ** Instead of keeping the sequence of continued fraction terms, ** we just keep the last partial product of these matrices. */ #include &lt;stdio.h&gt; main(ac, av) int ac; char ** av; { double atof(); int atoi(); void exit(); long m[2][2]; double x, startx; long maxden; long ai; /* read command line arguments */ if (ac != 3) { fprintf(stderr, &quot;usage: %s r d\n&quot;,av[0]); // AF: argument missing exit(1); } startx = x = atof(av[1]); maxden = atoi(av[2]); /* initialize matrix */ m[0][0] = m[1][1] = 1; m[0][1] = m[1][0] = 0; /* loop finding terms until denom gets too big */ while (m[1][0] * ( ai = (long)x ) + m[1][1] &lt;= maxden) { long t; t = m[0][0] * ai + m[0][1]; m[0][1] = m[0][0]; m[0][0] = t; t = m[1][0] * ai + m[1][1]; m[1][1] = m[1][0]; m[1][0] = t; if(x==(double)ai) break; // AF: division by zero x = 1/(x - (double) ai); if(x&gt;(double)0x7FFFFFFF) break; // AF: representation failure } /* now remaining x is between 0 and 1/ai */ /* approx as either 0 or 1/m where m is max that will fit in maxden */ /* first try zero */ printf(&quot;%ld/%ld, error = %e\n&quot;, m[0][0], m[1][0], startx - ((double) m[0][0] / (double) m[1][0])); /* now try other possibility */ ai = (maxden - m[1][1]) / m[1][0]; m[0][0] = m[0][0] * ai + m[0][1]; m[1][0] = m[1][0] * ai + m[1][1]; printf(&quot;%ld/%ld, error = %e\n&quot;, m[0][0], m[1][0], startx - ((double) m[0][0] / (double) m[1][0])); } </code></pre>
<p>As many people have stated you really can't convert a floating point back to a fraction (unless its extremely exact like .25). Of course you could create some type of look up for a large array of fractions and use some sort of fuzzy logic to produce the result you are looking for. Again this wouldn't be exact though and you would need to define a lower bounds of how large your want the denominator to go.</p> <p>.32 &lt; x &lt; .34 = 1/3 or something like that.</p>
12,126
<p>My question is, which version-naming scheme should be used for what type of project.</p> <p>Very common is major.minor.fix, but even this can lead to 4 number (i.e. Firefox 2.0.0.16). Some have a model that odd numbers indicate developer-versions and even numbers stable releases. And all sorts of additions can enter the mix, like -dev3, -rc1, SP2 etc.</p> <p>Exists reasons to prefer one scheme over another and should different type of projects (i.e. Open Source vs. Closed Source) have different version naming schemes?</p>
<p>There are <strong>two</strong> good answers for this (plus a lot of personal preferences; see gizmo's comment on religious wars).</p> <p>For <strong>public</strong> applications, the standard <code>Major.Minor.Revision.Build</code> works best IMO - public users can easily tell what version of the program they have and, to some degree, how far out of date their version is.</p> <p>For <strong>in house</strong> applications, where the users never asked for the application, the deployment is handled by IT, and users will be calling the help desk, I found the <code>Year.Month.Day.Build</code> to work better in a lot of situations. This version number can thus be decoded to provide more useful information to the help desk than the public versioning number scheme.</p> <p>However at the end of the day I would make one recommendation above all else - <strong>use a system you can keep consistent</strong>. If there is a system that you can setup/script your compiler to automatically use everytime, <em>use that</em>.</p> <p>The worst thing that can happen is you releasing binaries with the same version number as the previous ones - I've recently been dealing with automated network error reports (someone elses application), and came to the conclusion that the Year.Month.Day.Build version numbers shown in the core dumps where not even remotely up to date with the application itself (the application itself used a splash screen with the real numbers - which of course where not drawn from the binary as one might assume). The result is I have no way of knowing if crash dumps are coming from a 2 year old binary (what the version number indicates) or a 2 month old binary, and thus no way of getting the right source code (no source control either!)</p>
<p>The difference between a close and open-source version number policy can also come from a <strong>commercial aspect</strong>, when the major version can reflect the year of the release for instance.</p>
14,809
<p>I'm building a <a href="https://en.wikipedia.org/wiki/Windows_Forms" rel="nofollow noreferrer">Windows Forms</a> form in C# with various elements in a panel that starts out either invisible, disabled, or set to null (labels, combo boxes, grids, etc.). As the user goes through and makes choices, these elements are populated, selected, etc.</p> <p>The idea is to upload files, read them, and process entries to a database. Once the processing for this directory has completed, I'd like to be able to have the user select another directory without exiting and restarting the Windows Forms application, by pressing a button that becomes visible when the process has completed.</p> <p>Is there an easy call to reset the application (or the panel that contains the elements), similar to when a webform is refreshed, or do I have to write a function that &quot;resets&quot; all of those elements one at a time?</p> <hr/> <p>As the result of a development meeting, my project has changed direction. I thank the two of you who helped with answers, and am going to close the question.</p>
<p>Simply remove the panel from the form and create the new one.</p> <p>Sample:</p> <pre><code>Panel CreatePanelWithDynamicControls() { Panel ret = new Panel(); ret.Dock = DockStyle.Fill; // Some logic, which initializes content of panel return ret; } void InitializeDynamicControls() { this.Controls.Clear(); Panel pnl = this.CreatePanelWithDynamiControls(); this.Controls.Add(pnl); } void Form1_Load(object sender, EventArgs e) { if (!this.DesignMode) { this.InitializeDynamicControls(); } } // I don't know exactly, on which situation // do you want reset controls void SomeEvent(object sender, EventArgs e) { this.InitializeDynamicControls(); } </code></pre>
<p>You could try calling this.InitializeComponent(), which may do the trick. Alternately, if your application has a 'Directory Select' form and a 'Process Files' form, you could have the Directory Select form do a "new" on the Process Files form, which should return it to its original state (not while its open, though).</p>
43,814
<p>I'd like to be able to run my aliases from my .bashrc in the "Run Application" dialog that comes up when you hit Alt+F2 in Ubuntu/Gnome.</p> <p>Does anyone know how to do this?</p>
<p><a href="http://www.freedesktop.org/wiki/Specifications" rel="nofollow noreferrer">http://www.freedesktop.org/wiki/Specifications</a> is probably a good place to start. I find these quite hard to follow most of the time, but sometimes you can figure it out. Specifically, the "Desktop Entry Specification".</p> <p>Also, I don't think you'll be able to use any aliases from <code>.bashrc</code>, at least not without writing some kind of wrapper script. I think it needs to be an executable file. Of course, you could just use the good old symlinks- to- same + what's- my- name trick...</p> <p>(Which, for reference, goes like this:</p> <ol> <li>Make a script which uses its own name as a parameter.</li> <li>Make symlinks to said script using the parameter values as the link names.)</li> </ol> <hr> <h1>Investigating...</h1> <p>Some casual investigation reveals that creating these is fairly simple if you use Nautilus, (at least the version I have):</p> <ol> <li>Bring up the context menu for some random file, and use "Open With"->"Open with Other Application".</li> <li>Unfold the "Use a custom command" and type in something like: <ol> <li><code>xterm -e 'bash -c "unzip -l %f; sleep 5"'</code></li> </ol></li> <li>This results in <ol> <li>the command being run (so don't type <code>rm -rf</code>)</li> <li>a file in <code>~/.local/share/applications/</code> called <code>xterm-usercreated.desktop</code></li> </ol></li> </ol> <p>Here at least, I get the follow file:</p> <pre><code>[Desktop Entry] Encoding=UTF-8 Name=xterm MimeType=application/zip; Exec=xterm -e 'bash -c "unzip -l %f; sleep 5"' %f Type=Application Terminal=false NoDisplay=true </code></pre> <p>4: Looking at the system xterm .desktop I find this:</p> <pre><code>[Desktop Entry] Type=Application Encoding=UTF-8 Name=XTerm GenericName= Comment=XTerm: terminal emulator for X Icon=/usr/share/pixmaps/xterm-color_32x32.xpm Exec=xterm Terminal=false Categories=X-Debian-Applications-Terminal-Emulators; </code></pre> <p>5: Editing the .usercreated.desktop file to this:</p> <pre><code>[Desktop Entry] Type=Application Encoding=UTF-8 Name=xtermz Exec=xterm -e 'bash -c "unzip -l %f; sleep 5"' %f Terminal=false Categories=X-Local-WTF </code></pre> <p>6: Run xdg-desktop-menu forceupdate --mode user</p> <p>7: "xtermz" now shows up in the list... Success!</p> <p>8: Yuck! This also makes it appear in the main menu, under "Other". Weird!</p> <hr> <h2>Some notes:</h2> <ul> <li>In my Debian/testing, <code>xdg-desktop-menu</code> and friends (notably <code>xdg-icon-resource</code>) live in the <code>xdg-utils</code> package.</li> <li>You should be able to create a <code>.desktop</code> file from scratch.</li> <li>You should be able to install the <code>.desktop</code> file using <code>xdg-desktop-menu install</code> blah blah</li> </ul>
<p>Instead of using alt-f2 to run commands outside the terminal, I use gnome-do instead; it is much more convenient &amp; flexible (once it's set up). You're still not going to be able to run shell "aliases", but you can configure gnome-do to use the "files and folders" plugin, and then any "*.desktop" applications you like to execute will be available for running, opening, etc. You can also have shell scripts executed in the same way. </p>
22,712
<p>I have a friend that has a little bit of a holiday coming up and they want ideas on what they should do during the holiday, I plan to suggest programming to them, what are the pros and cons that I need to mention?</p> <p>I'll add to the list below as people reply, I apologise if I duplicate any entries.</p> <p><strong>Pros I have so far</strong></p> <ol> <li>Minimal money requirement (they already have a computer)</li> <li>Will help them to think in new ways</li> <li>(Rob Cooper) Great challenge, every day really is a fresh challenge in some way, shape or form. Not many jobs can truly offer that.</li> <li>(Rob Cooper) I like the way it makes me think.. I look at EVERYTHING more logically as my skills improve.. This helps with general living as well as programming.</li> <li>(Rob Cooper) Money is/can be pretty good.</li> <li>(Rob Cooper) Its a pretty portable trade.. With collaboration tech as it is, you can pretty much work anywhere in the world so long as you have an Internet connection.</li> <li>(Rob Cooper) It's an exciting industry to work in, theres massive amounts of tech to work and play with!</li> <li>(Quarrelsome) Jetpacks. Programming is Technology and the more time we spend with technology the closer we get to having Jetpacks. (<em>Teifion: This is a really cool analogy!</em>)</li> <li>(Saj) Profitable way of Exercising Brain Muscles.</li> <li>(Saj) It makes you look brilliant to some audience.</li> <li>(Saj) Makes you tech-smart.</li> <li>(Saj) Makes you eligible to the future world.</li> <li>(Saj) It's easy, fun, not in a math way..</li> <li>(kiwiBastard) If the person likes problem solving then programming is no better example.</li> <li>(kiwiBastard) Brilliant sense of achivement when you can interact with something you have designed and coded</li> <li>(kiwiBastard) Great way to meet chicks/chaps - erm, maybe not that one (<em>Teifion: I dunno where you do programming but I want to come visit some time</em>)</li> <li>(epatel) Learning how to program is like learning spell casting at Hogwarts . The computer will be your servant forever...</li> </ol> <p><strong>Cons I have so far</strong></p> <ol> <li>Can be frustrating when it's not working</li> <li>Not physical exercise</li> <li>(Rob Cooper) There are a lot of people doing it just for the money. They have no love for the craft and just appear lazy, annoying and sometimes it can really grind my gears seeing an industry and workforce I enjoy so much being diluted with crap. Which can often reflect badly on all of us.</li> <li>(Rob Cooper) Not so sure about the initial cost.. Yeah you can get started with Java or something at low cost, but for me, locally, the vast demand is for .NET developers, which can be costly getting up and running with. However, this is rapidly/has not becoming the case with the amount of work put in by MS with releasing pretty damn good Express editions of their main development product line.</li> <li>(Rob Cooper) Its a lifelong career.. I truly feel you never really become a "master" by nature of the industry, you stop for 1-2 years. You're behind the times.. Some people do not like the pace.</li> <li>(Rob Cooper) Some geeks can be hard to work with.. While I think the general geek movement is really changing for the better, you will always have the classic "I am more intelligent than you" geeks that can really just be a pain in the ass for all!</li> <li>(Saj) Can cause virtual damage.</li> <li>(Saj) Can make one throw their computer away.</li> <li>(Saj) Can make one only virtually available to the world.</li> </ol>
<h2>I do it for the ladies :D</h2> <p>Seriously though, for me</p> <h3>Pro's</h3> <ul> <li>Great challenge, every day really is a fresh challenge in some way, shape or form. Not many jobs can truly offer that.</li> <li>I like the way it makes me think.. I look at EVERYTHING more logically as my skills improve.. This helps with general living as well as programming.</li> <li>Money is/can be pretty good.</li> <li>Its a pretty portable trade.. With collaboration tech as it is, you can pretty much work anywhere in the world so long as you have an Internet connection.</li> <li>It's an exciting industry to work in, theres massive amounts of tech to work and play with!</li> </ul> <h3>Cons (some of these can easily be Pro's too)</h3> <ul> <li>There are a lot of people doing it <em>just</em> for the money. They have no love for the <strong>craft</strong> and just appear lazy, annoying and sometimes it can really grind my gears seeing an industry and workforce I enjoy so much being diluted with crap. Which can often reflect badly on all of us.</li> <li>Not so sure about the initial cost.. Yeah you can get started with Java or something at low cost, but for me, locally, the vast demand is for .NET developers, which can be costly getting up and running with. However, this is rapidly/has not becoming the case with the amount of work put in by MS with releasing pretty damn good Express editions of their main development product line.</li> <li>Its a lifelong career.. I truly feel you never really become a &quot;master&quot; by nature of the industry, you stop for 1-2 years. You're behind the times.. Some people do not like the pace.</li> <li>Some geeks can be hard to work with.. While I think the general geek movement is really changing for the better, you will <em>always</em> have the classic &quot;I am more intelligent than you&quot; geeks that can really just be a pain in the ass for all!</li> </ul>
<p>You could tell him how into programmers girls are.. you know, lie.</p>
3,205
<p>Imagine I have the following:</p> <pre><code>inFile = "/adda/adas/sdas/hello.txt" # that instruction give me hello.txt Name = inFile.name.split("/") [-1] # that one give me the name I want - just hello Name1 = Name.split(".") [0] </code></pre> <p>Is there any chance to simplify that doing the same job in just one expression?</p>
<p>You can get what you want platform independently by using <a href="http://docs.python.org/library/os.path.html#os.path.basename" rel="nofollow noreferrer">os.path.basename</a> to get the last part of a path and then use <a href="http://docs.python.org/library/os.path.html#os.path.splitext" rel="nofollow noreferrer">os.path.splitext</a> to get the filename without extension.</p> <pre><code>from os.path import basename, splitext pathname = "/adda/adas/sdas/hello.txt" name, extension = splitext(basename(pathname)) print name # --&gt; "hello" </code></pre> <p>Using <a href="http://docs.python.org/library/os.path.html#os.path.basename" rel="nofollow noreferrer">os.path.basename</a> and <a href="http://docs.python.org/library/os.path.html#os.path.splitext" rel="nofollow noreferrer">os.path.splitext</a> instead of str.split, or re.split is more proper (and therefore received more points then any other answer) because it does not break down on other <a href="http://en.wikipedia.org/wiki/Path_(computing)#Representations_of_paths_by_operating_system_and_shell" rel="nofollow noreferrer">platforms that use different path separators (you would be surprised how varried this can be)</a>.</p> <p>It also carries most points because it answers your question for "one line" precisely and is aesthetically more pleasing then your example (even though that is debatable as are all questions of taste) </p>
<p>I'm pretty sure some Regex-Ninja*, would give you a more or less sane way to do that (or as I now see others have posted: ways to write two expressions on one line...)</p> <p>But I'm wondering why you want to do split it with just one expression? For such a simple split, it's probably faster to do two than to create some advanced either-or logic. If you split twice it's safer too: </p> <p>I guess you want to separate the path, the file name and the file extension, if you split on '/' first you know the filename should be in the last array index, then you can try to split just the last index to see if you can find the file extension or not. Then you don't need to care if ther is dots in the path names.</p> <p>*(Any <em>sane</em> users of regular expressions, should not be offended. ;)</p>
41,972
<p>How do I get the directory where the rakefile.rb is located?</p> <p>I want to use this as my root directory to locate everything off.</p>
<p>use <code>__FILE__</code> to get the file name then you can get the directory from there:</p> <p>in <code>test.rb</code></p> <pre><code>puts __FILE__ </code></pre> <p>output:</p> <pre><code>/users/foo/test.rb </code></pre> <p><code>__FILE__</code> resolves to the full path of the file it is in. </p> <p>Use this to get the dir name:</p> <pre><code>File.dirname(__FILE__) </code></pre>
<p>If this is a RoR app your Rakefile.rb should be in your RAILS_ROOT directory. So in any script you can specify file location like </p> <pre><code> config.load_paths += %W( #{RAILS_ROOT}/extras ) </code></pre>
29,274
<p>I'm trying to extend some "base" classes in Python:</p> <pre><code>class xlist (list): def len(self): return len(self) def add(self, *args): self.extend(args) return None class xint (int): def add(self, value): self += value return self x = xlist([1,2,3]) print x.len() ## &gt;&gt;&gt; 3 ok print x ## &gt;&gt;&gt; [1,2,3] ok x.add (4, 5, 6) print x ## &gt;&gt;&gt; [1,2,3,4,5,6] ok x = xint(10) print x ## &gt;&gt;&gt; 10 ok x.add (2) print x ## &gt;&gt;&gt; 10 # Not ok (#1) print type(x) ## &gt;&gt;&gt; &lt;class '__main__.xint'&gt; ok x += 5 print type(x) ## &gt;&gt;&gt; &lt;type 'int'&gt; # Not ok (#2) </code></pre> <p>It works fine in the <em>list</em> case because the <em>append</em> method modifies the object "in place", without returning it. But in the <em>int</em> case, the <em>add</em> method doesn't modify the value of the external <em>x</em> variable. I suppose that's fine in the sense that <em>self</em> is a local variable in the <em>add</em> method of the class, but this is preventing me from modifying the initial value assigned to the instance of the class.</p> <p>Is it possible to extend a class this way or should I define a class property with the base type and map all the needed methods to this property?</p>
<p>Your two <code>xint</code> examples don't work for two different reasons.</p> <p>The first doesn't work because <code>self += value</code> is equivalent to <code>self = self + value</code> which just reassigns the local variable <code>self</code> to a different object (an integer) but doesn't change the original object. You can't really get this </p> <pre><code>&gt;&gt;&gt; x = xint(10) &gt;&gt;&gt; x.add(2) </code></pre> <p>to work with a subclass of <code>int</code> since integers are <a href="http://docs.python.org/ref/objects.html" rel="noreferrer">immutable</a>.</p> <p>To get the second one to work you can define an <a href="http://docs.python.org/ref/numeric-types.html" rel="noreferrer"><code>__add__</code> method</a>, like so:</p> <pre><code>class xint(int): def __add__(self, value): return xint(int.__add__(self, value)) &gt;&gt;&gt; x = xint(10) &gt;&gt;&gt; type(x) &lt;class '__main__.xint'&gt; &gt;&gt;&gt; x += 3 &gt;&gt;&gt; x 13 &gt;&gt;&gt; type(x) &lt;class '__main__.xint'&gt; </code></pre>
<p>Ints are immutable and you can't modify them in place, so you should go with option #2 (because option #1 is impossible without some trickery).</p>
5,363
<p>I feel like I have a very basic/stupid question, yet I never saw/read/heard anything in this direction.</p> <p>Say I have a table <em>users(userId, name)</em> and a table <em>preferences(id, userId, language)</em>. The example is trivial but could be extended to a situation with multi-level relations and way more tables..<br> When my UI requests to delete a user I first want to show a warning stating that also its preferences will be deleted. If at some point the database gets extended with more tables and relationships, but the software isn't adapted accordingly (the client didn't update) a generic message should be shown.</p> <p>How can I implement this? The UI cannot know about the whole data structure and should not be bothered to walk down all the relations to manually delete all the depending records. </p> <p>I would think this would be with constraints.<br> The constraint would be <em>no action</em> at first so the constraint will throw an error that can be caught by the UI. After the UI receives a confirmation, the constraint should become a <em>cascade</em>.</p> <p>Somehow I'm feeling like I'm getting this all wrong..</p>
<p>What I would do is this:</p> <ol> <li>The constraint is CASCADE</li> <li>The application checks if preferences exist.</li> <li>If they do, show the warning.</li> <li>If no preferences exist, or the warning is accepted, delete the client.</li> </ol> <p>Changing database relationships on the fly is not going to be a good idea!!</p> <p>Cheers,</p> <p>RB.</p>
<p>If you are worried about the user not realising the full impact of their delete, you might want to consider not actually deleting the data - instead you could simply set a flag on a column called say "<code>marked_for_deletion</code>". (the entries could then be deleted a safe time later)<br> The downside is that you need to remember to filter out the marked rows in other queries. This can be mitigated by creating a view on the table with the marked rows filtered out, and then always using the view in your queries.</p>
10,728
<p>How would you programmacially abbreviate <code>XHTML</code> to an arbitrary number of words without leaving unclosed or corrupted tags?</p> <p>i.e.</p> <pre><code>&lt;p&gt; Proin tristique dapibus neque. Nam eget purus sit amet leo tincidunt accumsan. &lt;/p&gt; &lt;p&gt; Proin semper, orci at mattis blandit, augue justo blandit nulla. &lt;span&gt;Quisque ante congue justo&lt;/span&gt;, ultrices aliquet, mattis eget, hendrerit, &lt;em&gt;justo&lt;/em&gt;. &lt;/p&gt; </code></pre> <p>Abbreviated to 25 words would be:</p> <pre><code>&lt;p&gt; Proin tristique dapibus neque. Nam eget purus sit amet leo tincidunt accumsan. &lt;/p&gt; &lt;p&gt; Proin semper, orci at mattis blandit, augue justo blandit nulla. &lt;span&gt;Quisque ante congue...&lt;/span&gt; &lt;/p&gt; </code></pre>
<p>Here's what I did:</p> <pre><code>&lt;link rel="Stylesheet" type="text/css" href="Stylesheet.css" id="style" runat="server" visible="false" /&gt; </code></pre> <p>It fools Visual Studio into thinking you've added a stylesheet to the page but it doesn't get rendered.</p> <hr> <p>Here's an even more concise way to do this with multiple references;</p> <pre><code>&lt;% if (false) { %&gt; &lt;link rel="Stylesheet" type="text/css" href="Stylesheet.css" /&gt; &lt;script type="text/javascript" src="js/jquery-1.2.6.js" /&gt; &lt;% } %&gt; </code></pre> <p>As seen in <a href="http://haacked.com/archive/2008/11/21/combining-jquery-form-validation-and-ajax-submission-with-asp.net.aspx" rel="noreferrer">this blog post</a> from Phil Haack.</p>
<p>You Can use <code>CSS</code> direct in <code>userControl</code>.</p> <p>Use this in <code>UserControl</code>:</p> <pre><code> &lt;head&gt; &lt;title&gt;&lt;/title&gt; &lt;style type="text/css"&gt; .wrapper { margin: 0 auto -142px; /* the bottom margin is the negative value of the footer's height */ } &lt;/style&gt; &lt;/head&gt; </code></pre> <p>This will work.</p>
5,460
<p>Is there an API call in .NET or a native DLL that I can use to create similar behaviour as Windows Live Messenger when a response comes from someone I chat with?</p>
<p>FlashWindowEx is the way to go. See <a href="http://msdn.microsoft.com/en-us/library/ms679347%28VS.85%29.aspx" rel="noreferrer">here for MSDN documentation</a></p> <pre><code>[DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] static extern bool FlashWindowEx(ref FLASHWINFO pwfi); [StructLayout(LayoutKind.Sequential)] public struct FLASHWINFO { public UInt32 cbSize; public IntPtr hwnd; public UInt32 dwFlags; public UInt32 uCount; public UInt32 dwTimeout; } public const UInt32 FLASHW_ALL = 3; </code></pre> <p>Calling the Function:</p> <pre><code>FLASHWINFO fInfo = new FLASHWINFO(); fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo)); fInfo.hwnd = hWnd; fInfo.dwFlags = FLASHW_ALL; fInfo.uCount = UInt32.MaxValue; fInfo.dwTimeout = 0; FlashWindowEx(ref fInfo); </code></pre> <p>This was shamelessly plugged from <a href="http://pinvoke.net/default.aspx/user32/FlashWindowEx.html" rel="noreferrer">Pinvoke.net</a></p>
<p>I believe you're looking for <a href="http://msdn.microsoft.com/en-us/library/ms633539.aspx" rel="nofollow noreferrer"><code>SetForegroundWindow</code></a>.</p>
9,885
<p>I'm trying to add an header file to dev-C++ but when I compile it it doesn't work. Here are my exact steps (for my example, I'm trying to get mysql.h to work):</p> <ol> <li>copy "mysql.h" into c:\dev-c++\includes</li> <li>check that in dev-C++ tools > compiler options > directories > c includes and c++ includes have the path to "c:\dev-c++\includes"</li> <li>include #include at the top of my file</li> <li>compiled</li> </ol> <p>This is what the dev-C++ compiler told me:</p> <pre><code>13 C:\Documents and Settings\Steve\Desktop\server code\setup1\main.c `mysql' undeclared (first use in this function) </code></pre> <p>As well as other errors due to not locating the header file</p> <p>Are the steps I've outlined correct? Or is there something else I need to do to get the header files to compile.</p> <p>P.S. I tried doing the same with VS2008 (put mysql.h in the vs2008 include folder, etc) but still have the same error. I would like to stick with Dev-c++ if possible.</p>
<p>Dev-C++ is a port of GCC, so try this page: <a href="http://gcc.gnu.org/onlinedocs/cpp/Search-Path.html#Search-Path" rel="nofollow noreferrer">http://gcc.gnu.org/onlinedocs/cpp/Search-Path.html</a>. </p> <p>Note that you probably have to tinkle with the Makefile.</p>
<p>On the left side, right click the Project and choose "Add to Project", and then select the header file.</p>
32,171
<p>I spent the last days trying to make the best gears I could but they are not "smooth" nor good. I searched at thingverse with "gear" but I see no set of gears. I would like someone to point me a good set of gears (with 5, 10, 15... teeth for example) so I can use this STL file with Google Sketchup.</p> <p>Do you guys know any good matching gears that I could print?</p> <p>I will be using this gear in a fast spinning matching so it would be nice these gears to be well designed to support some fast moving.</p> <p>Also, I think in my case I would like to use gears with this shape (the white gear). Any idea why is this gear design better than the usual? <a href="https://i.stack.imgur.com/7mHxj.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7mHxj.jpg" alt="enter image description here"></a></p>
<p>This type of gear is known as a "herringbone" gear. A traditional straight-cut gear is strong, but can cause more vibration as each tooth engages and disengages. A helical gear (slanted tooth) reduces that vibration as the tooth engagement is more uniform. However the angle of the teeth causes a sideways force that may be undesired. A herringbone tooth design effectively cancels the sideways forces but gets the uniform tooth engagement.</p> <p>A search for "herringbone" on Thingiverse comes up with many gears of this type.</p> <p>Regarding the quality, if you are not happy with the results of your own design, that's OK - gears are shockingly complex, and people make careers of gear design! However, if you have a good CAD model that just isn't printing well, it's not likely a bad STL.</p> <p>An STL from a different source is likely to have similar quality with the same slicer/printer setup. You might be able to improve print quality of your design by changing settings on your slicer or adjusting your printer. I'd suggest asking a question with your current setup and specific print quality issues.</p>
<p>As for high speed gear ideas why don't you design your own if there aren't any good ones. I will admit sometimes there will be surprising lack of content in some areas and I dont know what you expect, sometimes you do have to do some things your self to bridge the gaps. Maybe try looking into automobile transmission or even jet engines which use two shafts for high speed compressor and low speed fans. Jet engines spin pretty fast over 35k RPM. They may end up using a planetary gear I would think, the forces are well balanced. But you haven't said the purpose of this gear, is it power transmission on separate parallel axis? Speed reduction/change? In engineering, structurally things which use pointy edges can perform poorly under stress, the stress is highly focused geometrically. Instead if manufacturing constraints and design volume allows it, rounded, chamfered, or filleted edges reduce high stress points. Also adding material distributes loads where possible. Smaller teeth may increase vibration frequency but reduce amplitude. Ideally you would want to minimize the relative velocities of the contacting surfaces to reduce waisted force from friction converting to heat. Also heat can reduce strength and increase wear, decreasing life span of the gear.</p>
558
<p>While Scrum is easy in theory and hard in practice, I wanted to hear your definition of Done; i.e. what are the gates (unit test, code coverage > 80%, code reviews, load tests, perf.test, functional tests, etc.) your product has to go through before you can label the product "Done"</p>
<p>I'd say it is up to your team to decide. Talk with the product owner. Ideally done would be when a story is in Production and being used. However, there is a time gap between when a story is development complete and in Live. Makes it hard to track how long a story took to develop.</p> <p>In my team, our definition of done is, when the developer completes a story,and does a "show and tell" to the rest of the team(testers, product owner), and if everyone is happy it goes into the subversion trunk. </p> <p>Further testing is done off a automated build from trunk.</p>
<p>Everything that will make your "stabilization period" (ie work required between the code freeze and the release to the client) shorter.</p>
20,520
<p>So I have an Oracle instance, and I know it's running on this system, I've su'd to the oracle user, and I'm trying to connect using "/ as sysdba". However, when I do connect, it says the instance is idle. I know the database is up and opened, because my application's talking to it. My paths (ORACLE_HOME, etc.) might be incorrect: any idea which incorrect setting might result in this?</p> <pre><code>% sqlplus "/ as sysdba" SQL*Plus: Release 10.2.0.3.0 - Production on Mon Dec 8 09:23:22 2008 Copyright (c) 1982, 2006, Oracle. All Rights Reserved. Connected to an idle instance. 09:23:22 SQL&gt; Disconnected % ps -ef | grep smon oracle 6961 1 0 Nov 05 ? 1:24 ora_smon_ORA003 % </code></pre>
<p>make sure you have your ORACLE_HOME setup exactly the same as when the server was started, I've seen this problem with oracle 9.2.0.5.0 on solaris, </p> <pre><code>ORACLE_HOME=/opt/oracle ORACLE_HOME=/opt/oracle/ </code></pre> <p>is two different things, and will result in issues connecting locally.</p>
<p>The problem can be if the session could not be opened due to extremally busy database. in this case connection using any user even dummy one</p> <p>sqlplus dummy/dummy</p> <p>would give you actual problem but not idle instance.</p>
45,529
<p>We've been using the 32bit linux version of the <a href="http://wrapper.tanukisoftware.org/" rel="nofollow noreferrer">JavaServiceWrapper</a> for quite a while now and it's working perfectly. We are now considering also using it on 64bit linux systems. There are downloads for 64bit binaries on the website, but looking into Makefile for the 64bit version I found the following comment, though: # This makefile is in progess. It builds, but the resulting libwrapper.so does not yet work. # If you know how to fix it then please help out.</p> <p>Can anyone confirm, that this comment is just outdated and the resulting wrapper will work without flaws?</p>
<p>I've had it running in production on 64-bit red hat without any trouble for the last year or so. </p>
<p>Take a look at <a href="http://yajsw.sourceforge.net/" rel="nofollow">http://yajsw.sourceforge.net/</a>. </p> <p>It's free and rather compatible reimplementation of TanukiSoftware Java Service Wrapper featuring free 64-bit support.</p>
4,719
<p>I've create a WinForms control that inherits from System.Windows.Forms.UserControl...I've got some custom events on the control that I would like the consumer of my control to be able to see. I'm unable to actually get my events to show up in the Events tab of the Properties window during design time. This means the only way to assign the events is to programmatically write </p> <pre><code>myUserControl.MyCustomEvent += new MyUserControl.MyCustomEventHandler(EventHandlerFunction); </code></pre> <p>this is fine for me I guess but when someone else comes to use my UserControl they are not going to know that these events exist (unless they read the library doco...yeah right). I know the event will show up using Intellisense but it would be great if it could show in the properties window too.</p>
<p>Make sure your events are exposed as public. For example...</p> <pre><code>[Browsable(true)] public event EventHandler MyCustomEvent; </code></pre>
<p>A solution using delegate. For example i used for a custom ListView which handle item added event : Declare your delegate :</p> <pre><code> public delegate void ItemAddedHandler(object sender, ItemEventArgs e) </code></pre> <p>then declare the event which use the delegate :</p> <pre><code> [Browsable(true)] public event ItemAddedHandler ItemAdded; </code></pre> <p>Note : ItemEventArgs is a custom EventArgs</p> <p>Hope can help you, works fine for me</p>
17,258
<p>I am just looking at the using statement, I have always known what it does but until now not tried using it, I have come up with the below code:</p> <pre><code> using (SqlCommand cmd = new SqlCommand(reportDataSource, new SqlConnection(Settings.Default.qlsdat_extensionsConnectionString))) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@Year", SqlDbType.Char, 4).Value = year; cmd.Parameters.Add("@startDate", SqlDbType.DateTime).Value = start; cmd.Parameters.Add("@endDate", SqlDbType.DateTime).Value = end; cmd.Connection.Open(); DataSet dset = new DataSet(); new SqlDataAdapter(cmd).Fill(dset); this.gridDataSource.DataSource = dset.Tables[0]; } </code></pre> <p>This seems to work but is there any point in this since as far as I can tell I would still need to enclose this in a try catch block to catch unforseen errors e.g. sql server down. Am I missing something?</p> <p>As far as I can currently see it just stops me closing and disposing of cmd but there will be more lines of code due to the try catch still being needed.</p>
<p>When doing IO work I code to <em>expect</em> an exception.</p> <pre><code>SqlConnection conn = null; SqlCommand cmd = null; try { conn = new SqlConnection(Settings.Default.qlsdat_extensionsConnectionString) cmd = new SqlCommand(reportDataSource, conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@Year", SqlDbType.Char, 4).Value = year; cmd.Parameters.Add("@startDate", SqlDbType.DateTime).Value = start; cmd.Parameters.Add("@endDate", SqlDbType.DateTime).Value = end; conn.Open(); //opens connection DataSet dset = new DataSet(); new SqlDataAdapter(cmd).Fill(dset); this.gridDataSource.DataSource = dset.Tables[0]; } catch(Exception ex) { Logger.Log(ex); throw; } finally { if(conn != null) conn.Dispose(); if(cmd != null) cmd.Dispose(); } </code></pre> <p><strong>Edit:</strong> To be explicit, I avoid the <em>using</em> block here because I believe it to be important to log in situations like this. Experience has taught me that you never know what kind of weird exception might pop up. Logging in this situation might help you detect a deadlock, or find where a schema change is impacting a little used and little tested part of you code base, or any number of other problems.</p> <p><strong>Edit 2:</strong> One can argue that a using block could wrap a try/catch in this situation, and this is completely valid and functionally equivalent. This really boils down to preference. Do you want to avoid the extra nesting at the cost of handling your own disposal? Or do you incur the extra nesting to have auto-disposal. I feel that the former is cleaner so I do it that way. However, I don't rewrite the latter if I find it in the code base in which I am working.</p> <p><strong>Edit 3:</strong> I really, really wish MS had created a more explicit version of using() that made it more intuitive what was really happening and given more flexibility in this case. Consider the following, imaginary code:</p> <pre><code>SqlConnection conn = null; SqlCommand cmd = null; using(conn = new SqlConnection(Settings.Default.qlsdat_extensionsConnectionString), cmd = new SqlCommand(reportDataSource, conn) { conn = new SqlConnection(Settings.Default.qlsdat_extensionsConnectionString); cmd = new SqlCommand(reportDataSource, conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@Year", SqlDbType.Char, 4).Value = year; cmd.Parameters.Add("@startDate", SqlDbType.DateTime).Value = start; cmd.Parameters.Add("@endDate", SqlDbType.DateTime).Value = end; cmd.Open(); DataSet dset = new DataSet(); new SqlDataAdapter(cmd).Fill(dset); this.gridDataSource.DataSource = dset.Tables[0]; } catch(Exception ex) { Logger.Log(ex); throw; } </code></pre> <p>A using statement just creates a try/finally with Dispose() calls in the finally. Why not give the developer a unified way of doing disposal and exception handling?</p>
<p>If the caller of your function is responsible for dealing with any exceptions the using statement is a nice way of ensuring resources are cleaned up no matter the outcome. </p> <p>It allows you to place exception handling code at layer/assembly boundaries and helps prevent other functions becoming too cluttered.</p> <p>Of course, it really depends on the types of exceptions thrown by your code. Sometimes you should use try-catch-finally rather than a using statement. My habit is to always start with a using statement for IDisposables (or have classes that contain IDisposables also implement the interface) and add try-catch-finally as needed.</p>
30,941
<p>I have an abstract base class called Shape from which both Circle and Rectangle are derived, but when I execute the following code in VS 2005 I get the error Debug assertion failed. At the same time I have not overloaded == operator in any class</p> <p>Expression:Vector iterator not dereferencable, what is the reason for this.</p> <pre><code> vector&lt;Shape*&gt; s1; s1.push_back(new Circle(point(1,2),3)); s1.push_back(new Circle(point(4,3),5)); s1.push_back(new Rectangle(point(1,1),4,5)); vector&lt;Shape*&gt; s2(s1); reverse(s1.begin(),s1.end()); (*find(s1.begin(),s1.end(),new Circle(point(1,2),3)))-&gt;move(point(10,20)); </code></pre>
<p>Simple :</p> <ul> <li>find fails since your newly created Circle can't be found in the vector with comparing Shape *</li> <li>a failed find returns the end iterator which is not deferencable as caught by a Debug assertion</li> </ul> <p>For it to work like you want, you do need to compare Shape, not Shape*</p> <p>As pointed out in other answers, <a href="http://www.boost.org/doc/libs/1_37_0/libs/ptr_container/doc/ptr_vector.html" rel="noreferrer">boost::ptr_vector</a> is an easy way to achieve this.</p>
<p>This is a good reason to use boost::ptr_vector.</p> <p>It not only handles the fact that your objects need to be destroyed.<br> xtofl@: You forgot the virtual destructor.</p> <p>But it also makes the members look like objects by returning references rather than pointers. This allows you to use the standard algorithms much more naturally rather than playing around with pointers in your 'equal' function (which is very un C++ like).</p> <pre><code>#include &lt;boost/ptr_container/ptr_vector.hpp&gt; #include &lt;iostream&gt; class Shape { public: ~Shape() {} bool operator==(Shape const&amp; rhs) const { if (typeid(*this) != typeid(rhs)) { return false; } return this-&gt;isEqual(rhs); } private: virtual bool isEqual(Shape const&amp; rhs) const = 0; }; class Circle: public Shape { public: Circle(int r) :radius(r) {} private: virtual bool isEqual(Shape const&amp; r) const { Circle const&amp; rhs = dynamic_cast&lt;Circle const&amp;&gt;(r); return radius == rhs.radius; } int radius; }; class Rectangle: public Shape { public: Rectangle(int h,int w) :height(h) ,width(w) {} private: virtual bool isEqual(Shape const&amp; r) const { Rectangle const&amp; rhs = dynamic_cast&lt;Rectangle const&amp;&gt;(r); return (height == rhs.height) &amp;&amp; (width == rhs.width); } int height; int width; }; int main() { boost::ptr_vector&lt;Shape&gt; data; data.push_back(new Circle(5)); data.push_back(new Circle(6)); data.push_back(new Rectangle(7,4)); boost::ptr_vector&lt;Shape&gt;::iterator f; f = find(data.begin(),data.end(),Circle(6)); std::cout &lt;&lt; "Find(" &lt;&lt; (f - data.begin() ) &lt;&lt; ")" &lt;&lt; std::endl; } </code></pre>
38,756
<p>Has anyone come up with a good way of performing full text searches (<code>FREETEXT() CONTAINS()</code>) for any number of arbitrary keywords using standard LinqToSql query syntax?</p> <p>I'd obviously like to avoid having to use a Stored Proc or have to generate a Dynamic SQL calls.</p> <p>Obviously I could just pump the search string in on a parameter to a SPROC that uses FREETEXT() or CONTAINS(), but I was hoping to be more creative with the search and build up queries like:</p> <p>"pepperoni pizza" and burger, not "apple pie".</p> <p>Crazy I know - but wouldn't it be neat to be able to do this directly from LinqToSql? Any tips on how to achieve this would be much appreciated.</p> <p>Update: I think I may be on to something <a href="http://tomasp.net/blog/linq-expand-update.aspx" rel="nofollow noreferrer">here</a>...</p> <p>Also: I rolled back the change made to my question title because it actually changed the meaning of what I was asking. I <em>know</em> that full text search is not supported in LinqToSql - I would have asked that question if I wanted to know that. Instead - I have updated my title to appease the edit-happy-trigger-fingered masses.</p>
<p>Unfortunately LINQ to SQL does not support Full Text Search. </p> <p>There are a bunch of products out there that I think could: Lucene.NET, NHibernate Search comes to mind. LINQ for NHibernate combined with NHibernate Search would probably give that functionality, but both are still way deep in beta.</p>
<p>Unfortunately LINQ to SQL does not support Full Text Search. </p> <p>There are a bunch of products out there that I think could: Lucene.NET, NHibernate Search comes to mind. LINQ for NHibernate combined with NHibernate Search would probably give that functionality, but both are still way deep in beta.</p>
9,326
<p>I have been trying to include a file in a included file e.g</p> <p><strong>main.cpp file</strong></p> <pre><code>#include &lt;includedfile.cpp&gt; int main(){ cout&lt;&lt;name&lt;&lt;endl; } </code></pre> <p><strong>includedfile.cpp</strong></p> <pre><code>#include &lt;iostream&gt; using namespace std; string name; name = "jim"; </code></pre> <p>this code does not work, the debuger says that name is not defined.</p>
<p>You cannot have statements exist outside of a method!</p> <pre><code>name = "jim"; // This is outside of any method, so it is an error. </code></pre> <p>You could refactor your code so the variable declaration is also an initial assignment, which should be valid (my C++ is a bit rusty, so I might be wrong on this point).</p> <pre><code>string name = "jim"; </code></pre>
<p>You have to have a very good reason to include a .cpp file, however. It happens, but it's rare! What exactly are you trying to achieve? Or are you just experimenting?</p>
33,634
<p>I have Oracle SQL Developer already installed and am able to connect to and query Oracle databases.</p> <p>Using Help -> Check for Updates I was able to install the Oracle MySQL Browser extension but there are no connection options for MySQL databases.</p>
<p>Under Tools > Preferences > Databases there is a third party JDBC driver path that must be setup. Once the driver path is setup a separate 'MySQL' tab should appear on the New Connections dialog.</p> <p>Note: This is the same jdbc connector that is available as a JAR download from the MySQL website.</p>
<p>You may find the following relevant as well:</p> <p><a href="https://stackoverflow.com/questions/23797585/oracle-sql-developer-connection-to-microsoft-sql-server/26598722#26598722">Oracle SQL Developer connection to Microsoft SQL Server</a></p> <p>In my case I had to place the <code>ntlmauth.dll</code> in the sql-developer application directory itself (i.e. sql-developer\jdk\jre\bin). Why this location over the system jre/bin I have no idea. But it worked. </p>
11,517
<p>When I first started using revision control systems like <a href="http://en.wikipedia.org/wiki/Concurrent_Versions_System" rel="nofollow noreferrer">CVS</a> and <a href="http://en.wikipedia.org/wiki/Apache_Subversion" rel="nofollow noreferrer">SVN</a>, I didn't really understand the concepts of the "trunk", branching, merging and tagging. I'm now starting to understand these concepts, and really get the importance and power behind them.</p> <p>So, I'm starting to do it properly. Or so I think... This is what I understand so far: The latest release/stable version of your code should sit in /trunk/ while beta versions or bleeding edge versions sit inside the /branches/ directory as different directories for each beta release, and then merged into the trunk when you release.</p> <p>Is this too simplistic a view on things? What repository layouts do you guys recommend? If it makes a difference, I'm using Subversion.</p>
<p>See these two questions on SO for more information:</p> <ul> <li><a href="https://stackoverflow.com/questions/16142/what-does-branch-tag-and-trunk-really-mean">What does branch, tag and trunk really mean?</a></li> <li><a href="https://stackoverflow.com/questions/15621/subversion-question">Subversion question</a></li> </ul>
<p>Eric has an excellent series of articles on Source Control use and organisational best practices. <a href="http://www.ericsink.com/scm/scm_branches.html" rel="nofollow noreferrer">Chapter 7 deals with branches</a> (and yes, it recommends the /trunk/ and /branches/ directories you suggest).</p>
3,833
<p>I need to send packets from one host to another over a <strong>potentially lossy</strong> network. In order to minimize packet latency, I'm not considering TCP/IP. But, I wish to maximize the throughput uisng UDP. What should be the optimal size of UDP packet to use?</p> <p>Here are some of my considerations:</p> <ul> <li><p>The MTU size of the switches in the network is 1500. If I use a large packet, for example 8192, this will cause fragmentation. Loss of one fragment will result in the loss of the entire packet, right?</p></li> <li><p>If I use smaller packets, I'll incur the overhead of the UDP and IP header</p></li> <li><p>If I use a really large packet, what is the largest that I can use? I read that the largest datagram size is 65507. What is the buffer size I should use to allow me to send such sizes? Would that help to bump up my throughput?</p></li> <li><p>What are the typical maximum datagram size supported by the common OSes (eg. Windows, Linux, etc.)?</p></li> </ul> <p>Updated:</p> <p>Some of the receivers of the data are embedded systems for which TCP/IP stack is not implemented.</p> <p>I know that this place is filled with people who are very adament about using what's available. But I hope to have better answers than just focusing on MTU alone.</p>
<p>The best way to find the ideal datagram size is to do exactly what TCP itself does to find the ideal packet size: <a href="http://en.wikipedia.org/wiki/Path_MTU_discovery" rel="noreferrer">Path MTU discovery</a>.</p> <p>TCP also has a widely used option where both sides tell the other what their MSS (basically, MTU minus headers) is.</p>
<p>Even though the MTU at the switch is 1500, you can have situations (like tunneling through a VPN) that wrap a few extra headers around the packet- you may do better to reduce them slightly, and go at 1450 or so.</p> <p>Can you simulate the network and test performance with different packet sizes?</p>
34,804
<p>I have an application that I'm trying to debug a crash in. However, it is difficult to detect the problem for a few reasons:</p> <ul> <li>The crash happens at shutdown, meaning the offending code isn't on the stack</li> <li>The crash only happens in release builds, meaning symbols aren't available</li> </ul> <p>By crash, I mean the following exception:</p> <pre><code>0xC0000005: Access violation reading location 0x00000000. </code></pre> <p><strong>What strategy would you use to diagnose this problem?</strong></p> <p>What I have done so far is remove as much code from my program until I get the bare minimum that will cause the crash. It seems to be happening in code that is statically linked to the project, so that doesn't help, either.</p>
<p>You can make the symbol files even for the release build. Do that, run your program, attach the debugger, close it, and see the cause of the crash in the debugger.</p>
<p>You seem to have something reading a null pointer - never good.</p> <p>I'm not sure what platform you are on. Under Linux, you could consider using <code>valgrind</code>.</p> <p>What is different about your release builds from your debug builds apart from the presence or absence of the debug information?</p> <p>Can you built the statically linked code with debugging information in it? Can you obtain a debug build of the statically linked code?</p>
49,734
<p>I am refactoring some CSS on a website. I have been working on, and noticed the absence of traditional HTML IDs in the code. </p> <p>There is heavy use of <code>CssClass='&amp;hellip;'</code>, or sometimes just <code>class='&amp;hellip;'</code>, but I can't seem to find a way to say id='&hellip;' and not have it swapped out by the server.</p> <p>Here is an example:</p> <pre><code>&lt;span id='position_title' runat='server'&gt;Manager&lt;/span&gt; </code></pre> <p>When the response comes back from the server, I get:</p> <pre><code>&lt;span id='$aspnet$crap$here$position_title'&gt;Manager&lt;/span&gt;</code></pre> <p>Any help here?</p>
<p>The 'crap' placed in front of the id is related to the container(s) of the control and there is no way (as far as I know) to prevent this behavior, other than not putting it in any container. </p> <p>If you need to refer to the id in script, you can use the ClientID of the control, like so:</p> <pre><code>&lt;script type="text/javascript"&gt; var theSpan = document.getElementById('&lt;%= position_title.ClientID %&gt;'); &lt;/script&gt; </code></pre>
<p>.Net will always replace your id values with some mangled (every so slightly predictable, but still don't count on it) value. Do you really NEED to have that id runat=server? If you don't put in runat=server, then it won't mangle it...</p> <p>ADDED: Like leddt said, you can reference the span (or any runat=server with an id) by using ClientID, but I don't think that works in CSS.</p> <p>But I think that you have a larger problem if your CSS is using ID based selectors. You can't re-use an ID. You can't have multiple items on the same page with the same ID. .Net will complain about that.</p> <p>So, with that in mind, is your job of refactoring the CSS getting to be a bit larger in scope?</p>
9,076
<p>I have this:</p> <pre><code>public string Log { get { return log; } protected set { if (log != value) { MarkModified(PropertyNames.Log, log); log = value; } } } </code></pre> <p>And my utility class for databinding does this:</p> <pre><code>PropertyInfo pi = ReflectionHelper.GetPropertyInfo(boundObjectType, sourceProperty); if (!pi.CanWrite) SetReadOnlyCharacteristics(boundEditor); </code></pre> <p>But PropertyInfo.CanWrite does not care whether the set is publicly accessible, only that it exists.</p> <p>How can I determine if there's a <strong>public</strong> set, not just <strong>any</strong> set?</p>
<p>You need to use the <a href="http://msdn.microsoft.com/en-us/library/system.reflection.bindingflags.aspx" rel="nofollow noreferrer">BindingFlags</a>. Something like </p> <pre><code>PropertyInfo property = type.GetProperty("MyProperty", BindingFlags.Public | BindingFlags.SetProperty | BindingFlags.Instance); </code></pre>
<p>Inside your ReflectionHelper.GetPropertyInfo(), you presumably to a boundObjectType.GetType().GetProperties(), where the BindingFlags parameter apparently includes BindingFlags.NonPublic. You want to specify just BindingFlags.Public</p>
22,747
<p>I am interested in calling <a href="http://sourceforge.net/projects/sox" rel="nofollow noreferrer">SoX</a>, an open source console application, from another Windows GUI program (written in Delphi naturally). Instead of dealing with scraping and hiding the console window, I would like to just convert the application to a DLL that I can call from my application. </p> <p>Before I start down this path I am curious how much work I should expect to be in for? Are we talking a major undertaking, or is there a straight forward solution? I know some C, but am by no means an expert. </p> <p>I am not expecting SoX specific details, just EXE console application conversion to DLL in general. If someone is familiar with SoX though, even better.</p>
<p>For the specific topic of turning a console executable into a library by modifying the C source code, it depends on how the command-line application is factored. If it's written in such a way that I/O is funneled through a small set of functions or even better function pointers, then obviously it will be trivial.</p> <p>If it's all done with printf, scanf and friends, then you'll probably be best off by finding / creating an include file that all the source files include and adding a macro that redirects printf/scanf and friends to your own functions that are written so as to be amenable to DLL implementation. Things like printf can be built from vsnprintf (use the n-version for safety), so you don't need to reimplement the whole C RTL I/O subsystem. However, there is no vsscanf, but there are third-party implementations on the web.</p> <p>If the code is using fprintf, fscanf, etc. to enable indirection between files and the console, you're still out of luck. The FILE structure is opaque, and unlike Pascal text files, a portable text file driver cannot be implemented. It might still be possible if you spelunk in your specific C RTL, but you'd be better advised going down the macro route and reimplementing your own renamed FILE type.</p> <p>Finally, the "popen()" approach is possible in Delphi and made somewhat easier in Delphi 2009 with the TTextReader and TTextWriter classes. Combine these with TFileStream wrapped around pipes, and specify pipes for standard input, standard output and standard error in the new process and STARTF_USESTDHANDLES, etc., and it will work. If you don't feel like writing your own, there are third-party equivalents / samples on the web for Delphi too. <a href="http://www.delphidabbler.com/software?id=consoleapp&amp;mid=3.2" rel="nofollow noreferrer">Here's one.</a></p>
<p>You don't mention what your toolchain is, but if you configure gcc in Windows, you can use the normal config;make;make install to just compile sox. In the process, it will create a dll file, and the console app. Or, you can just specify the make target to only make the dll. This will compile a windows native library that only depends on the MS C runtime dll, and you can use this in your own app.</p>
15,933
<p><code>select max(DELIVERY_TIMESTAMP) from DOCUMENTS;</code> will return the time that the latest document was delivered. How do I return <strong>the other columns</strong> for the latest document? For example I want <code>DOC_NAME</code> for the document that was most recently delivered?</p> <p>I'm not sure how to form the <code>WHERE</code> clause.</p>
<p>You have a few options</p> <pre><code>SELECT DOC_NAME FROM DOCUMENTS WHERE DELIVERY_TIMESTAMP IN ( SELECT MAX(DELIVERY_TIMESTAMP) FROM DOCUMENTS ) </code></pre> <p>Or with joins</p> <pre><code>SELECT DOC_NAME FROM DOCUMENTS INNER JOIN ( SELECT MAX(DELIVERY_TIMESTAMP) AS MAX_DELIVERY_TIMESTAMP FROM DOCUMENTS ) AS M ON M.MAX_DELIVERY_TIMESTAMP = DOCUMENTS.DELIVERY_TIMESTAMP </code></pre> <p>It gets more complicated if there are duplicates in a timestamp or you need multiple columns in your "max" criteria (because <code>MAX()</code> is only over the one column for all rows)</p> <p>This is where the <code>JOIN</code> option is the only option available, because a construction like this is not available (say multiple orders with identical timestamp):</p> <pre><code>SELECT DOC_NAME FROM DOCUMENTS WHERE (DELIVERY_TIMESTAMP, ORDERID) IN ( SELECT TOP 1 DELIVERY_TIMESTAMP, ORDERID FROM DOCUMENTS ORDER BY DELIVERY_TIMESTAMP DESC, ORDERID DESC ) </code></pre> <p>Where you in fact, would need to do:</p> <pre><code>SELECT DOC_NAME FROM DOCUMENTS INNER JOIN ( SELECT TOP 1 DELIVERY_TIMESTAMP, ORDERID FROM DOCUMENTS ORDER BY DELIVERY_TIMESTAMP DESC, ORDERID DESC ) AS M ON M.DELIVERY_TIMESTAMP = DOCUMENTS.DELIVERY_TIMESTAMP AND M.ORDERID = DOCUMENTS.ORDERID </code></pre>
<pre><code>Select Max(DELIVERY_TIMESTAMP), Doc_Name From TableName Group By Doc_Name </code></pre> <p>That should do it, unless I missed something in the question.</p>
31,667
<p>i m developing a little tool on my Pocket PC using WM6 SDK but i would like to implement a finger friendly user interface (iphone-like). So i m looking for a free .NET framework that offers the possibility to easily integrate a finger friendly interface for Windows Mobile 6 Pro .</p> <p>Any ideas ?</p> <p>EDIT : Finger friendly means big icons, big buttons , scrollable screens with a simple touch of the thumb... Because the Winforms in Compact framework are made for the stylus, not fingers !!</p>
<p>I know of no such interface API.</p> <p>I would code such an interface from scratch, overriding Paint and mouse events. If you need more fancy drawing tools that compact framework provides, you should look for pinvoke to access GDI+.</p>
<p>I'm not entirely sure what you're asking here... Windows Mobile 6.0 Pro <em>is</em> touch-screen enabled, so you should simply have to create your project targeting the Windows Mobile 6.0 Pro (note, however, that your application will not be compatible with Windows Mobile 6.0 Standard devices).</p>
15,570
<p>I would like to have something like this:</p> <pre><code>class Foo { private: int bar; public: void setBar(int bar); int getBar() const; } class MyDialog : public CDialogImpl&lt;MyDialog&gt; { BEGIN_MODEL_MAPPING() MAP_INT_EDITOR(m_editBar, m_model, getBar, setBar); END_MODEL_MAPPING() // other methods and message map private: Foo * m_model; CEdit m_editBar; } </code></pre> <p>Also it would be great if I could provide my custom validations:</p> <pre><code>MAP_VALIDATED_INT_EDITOR(m_editBar, m_model, getBar, setBar, validateBar) ... bool validateBar (int value) { // custom validation } </code></pre> <p>Have anybody seen something like this?</p> <p>P.S. I don't like DDX because it's old and it's not flexible, and I cannot use getters and setters.</p>
<p>The DDX map is just a series of <code>if</code> statements, so you can easily write your own DDX macro.</p> <pre><code>#define DDX_MAP_VALIDATED_INT_EDITOR(control, variable, getter, setter, validator)\ if(nCtlID==control.GetDlgCtrlID())\ {\ if(bSaveAndValidate)\ {\ int const value=control.GetDlgItemInt();\ if(validator(value))\ {\ variable-&gt;setter(value);\ }\ else\ {\ return false;\ }\ }\ else\ {\ control.SetDlgItemInt(variable-&gt;getter());\ }\ } </code></pre> <p>This is untested, but should work as per your example, if you put it in the DDX map. It should give you the idea. Of course you could extract this into a function, which is what the standard DDX macros do: they just do the outer <code>if</code> and then call a function. This would allow you to overload the function for different types of the <code>variable</code> (e.g. pointer vs reference/value)</p>
<p>The <a href="http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaBindings/CocoaBindings.html" rel="nofollow noreferrer">Cocoa Bindings</a> provide exactly what you want, but they are only available in the Mac / Objective-C word. <a href="http://www.mail-archive.com/help-gnustep@gnu.org/msg01423.html" rel="nofollow noreferrer">GNUstep</a> is a free version of it, but it's still Objective-C, not C++.</p> <p>However, it might be a good inspiration for an own framework, or a good starting point for further research.</p>
14,155
<p><a href="https://3dprinting.stackexchange.com/a/4642/233">This post</a> has been up for 4-5 days now. I flagged it originally when it was first posted and that flag aged away, I have now flagged it again and it's still here. We have one <a href="https://3dprinting.stackexchange.com/users/1263/szymon-b%C4%99czkowski">user</a> that shares part of the posters name but I am unsure if they are connected in any way or if that name references the linked user. </p> <p>Do we need more moderators to handle this? What is the process for having these removed? </p>
<p>The post has now been deleted and the user destroyed due to spam, so thank you for bringing this up.</p> <p>It either must have come up after I cleaned out the inbox or I must have overlooked it.</p> <p>Yes, we do need another moderator. I would have loved to be at a point by now that we could have had elections as part of a fully public SE site, but we've still got a few hurdles to overcome as a community.</p> <p>I'll double check what the options are for bringing on new moderators at this stage and post back to Meta.</p>
<p>Seeing as I'm 20 days late to this question, you probably understand that I'm not very active at the moment myself. (At least, I'm inactive for longer periods of time.) With Ryan gone for almost a year now, that often leaves @tbm0115 as the only moderator on this site.</p> <p>In other words, we could do with another moderator or a change of moderators (Ryan and perhaps me also).</p> <p>On the plus side, we are getting more and more users, which makes the community handle a lot of cases by itself.</p>
45
<p>How does TCP/IP report errors when packet delivery fails permanently? All Socket.write() APIs I've seen simply pass bytes to the underlying TCP/IP output buffer and transfer the data asynchronously. How then is TCP/IP supposed to notify the developer if packet delivery fails permanently (i.e. the destination host is no longer reachable)?</p> <p>Any protocol that requires the sender to wait for confirmation from the remote end will get an error message. But what happens for protocols where a sender doesn't have to read any bytes from the destination? Does TCP/IP just fail silently? Perhaps Socket.close() will return an error? Does the TCP/IP specification say anything about this?</p>
<p>TCP/IP is a reliable byte stream protocol. All your bytes will get to the receiver or you'll get an error indication.</p> <p>The error indication will come in the form of a closed socket. Regardless of what the communication pattern (who does the sending), if the bytes can't be delivered, the socket will close.</p> <p>So the question is, how do you see the socket close? If you're never reading, you'd eventually get an error trying to write to the closed socket (with ECONNRESET errno, I think).</p> <p>If you have a need to sleep or wait for input on another file handle, you might want to do your waiting in a select() call where you include the socket in the list of sources you're waiting on (even if you never expect to receive anything). If the select() indicates that the socket is ready for a read call, you may get a -1 return (with ECONNRESET, I think). An EOF would indicate an orderly close (other side did a shutdown() or close().</p> <p>How to distinguish this error close from a clean close (other program exiting, for example)? The errno values may be enough to distinguish error from orderly close.</p> <p>If you want an unambiguous indication of a problem, you'll probably need to build some sort of application level protocol above the socket layer. For example, a short "ack" message sent by the receiver back to the sender. Then the violation of that higher level application protocol (sender didn't see an ack) would be a confirmation that it was an error close vs a clean close.</p>
<p>In C, if you write to a socket that has failed with send(), you will get back the number of bytes that were sent. If this does not match the number of bytes you meant to send, then you have a problem. But also, when you write to a failed socket, you get SIGPIPE back. Before you start socket handling, you need to have a signal handler in place that will alert you when you get SIGPIPE.</p> <p>If you are reading from a socket, you really should wrap it with an alarm so you can timeout. Like "alarm(timeout_val); recv(); alarm(0)". Check the return code of recv, and if it's 0, that indicates that the connection has been closed. A negative return result indicates a read failure and you need to check errno.</p>
21,878
<p>We have a client (who has a client, who has a client) who is driving us mad with change requests to a code base (in PHP). Our first response was to just work in a main trunk in SVN, but the client often comes back and requests that a certain change needs to get pushed to the live servers ASAP. On the other hand, other changes get reduced in priority suddenly, which originally came grouped with other changes (seemingly).</p> <p>We are thinking of using a branch for <strong>every change request.</strong> Is this mad? What other solutions might work?</p> <p>Thanks!</p> <p><strong>Edit</strong>: This is a really hard question to choose the correct answer for. Thanks to everybody for your great answers.</p> <p><strong>Edit</strong>: I know that the best answer I chose was not particularly popular. I too wanted to find a technical solution to this problem. But now I think that if the client wants software with features that can be deployed in a modular fashion... this problem should <strong>not</strong> be solved in our use of the version control system. It would have to be designed into the software. </p> <p><strong>Edit</strong>: Now it's almost a month later and my coworker/client has convinced me that multiple branches is the way to go. This is not just due to the client's insanity, but also based on our need to be able to determine if a feature is "ready to go" or "needs more work" or whatever. I don't have the SVN with me, but we merge using the advice from the SVN Cookbook: you merge the branch <strong>from</strong> the revision it was branched to the head revision.</p> <p>Also, using this system, we merge all branches at some point and that becomes the new QA and then live build. Then we branch from that.</p> <p><strong>Last Edit (Perhaps):</strong> Months later, this system is still working out for us. We create branches for every ticket and rarely have problems. On the other hand, we do try to keep things separate as far as what people are working on...</p> <p><strong>Two Years Later:</strong> We use GIT now, and now this system is actually quite reasonable.</p>
<p>Perhaps Subversion here is not the best tool for the job. Although creating all these branches is cheap in SVN, re-merging them can become time-consuming and painfull.</p> <p>If you have a look at GIT instead of SVN, you will find a version control system which is more powerfull at merging in general. Added to that, it has the specific feature of "cherry picking". That is, single commits can be easily "picked" from one development tree and added to another (the live branch). Also, it is easy and convenient in GIT to merge several commits into one single one (you can even add to a specific commit from another tree).</p> <p>So building up single-feature commits and then cherry-picking them could be the solution for you.</p>
<p>When doing lot of rapid changes in the "live" branch of a project, you need to have a solid code review process to reduce the chance of breaking it. The code review must be done before doing the check-in; and keep away the core development from that branch.</p> <p>Once the change is approved, you can check-in the change (and/or merge from you working branch) and create a new "tag" once it's done.</p>
37,876
<p><a href="http://www.php.net/features.safe-mode" rel="noreferrer">open_basedir</a> limits the files that can be opened by PHP within a directory-tree.</p> <p>I am storing several class libraries and configuration files outside of my web root directory. This way the web server does not make them publicly accessible. However when I try to include them from my application I get an open_basedir restriction error like this:</p> <blockquote> <p>Warning: realpath() [function.realpath]: open_basedir restriction in effect. File(/var/www/vhosts/domain.tld/zend/application) is not within the allowed path(s): (/var/www/vhosts/domain.tld/httpdocs:/tmp) in /var/www/vhosts/domain.tld/httpdocs/index.php on line 5</p> </blockquote> <p>My web root is here:</p> <pre><code>/var/www/vhosts/domain.tld/httpdocs </code></pre> <p>My libraries and configuration directory are here:</p> <pre><code>/var/www/vhosts/domain.tld/zend </code></pre> <p>What would be the best workaround to relax the open_basedir restriction so that the the directory tree under the domain folder becomes available to my application? I have a number of domains that I want to do this with, and I'm also obviously wary of creating security vulnerabilities.</p> <p>Note: I am using CentOS, Apache, Plesk, and I have root ssh access to the server. And though this doesn't apply to Zend Framework directly, I am using it in this instance. So here is the inclusion from Zend's bootstrap:</p> <pre><code>define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../zend/application/')); set_include_path(APPLICATION_PATH . '/../zend/library' . PATH_SEPARATOR . get_include_path()); </code></pre>
<p>You can also do this easily on a per-directory basis using the Apache (assuming this is your web server) configuration file (e.g. httpd.conf)</p> <pre><code>&lt;Directory /var/www/vhosts/domain.tld/httpdocs&gt; php_admin_value open_basedir "/var/www/vhosts/domain.tld/httpdocs:/var/www/vhosts/domain.tld/zend" &lt;/Directory&gt; </code></pre> <p>you can also completely remove the restriction with</p> <pre><code>&lt;Directory /var/www/vhosts/domain.tld/httpdocs&gt; php_admin_value open_basedir none &lt;/Directory&gt; </code></pre>
<p>In Parallels Plesk Panel (e.g. 1and1) you can do it in the PHP panel settings:</p> <p><img src="https://i.stack.imgur.com/gcRFS.png" alt="enter image description here"></p> <p>here:</p> <p><img src="https://i.stack.imgur.com/c2AJK.png" alt="enter image description here"></p>
27,639
<p>I understand the following elements :</p> <ul> <li>there is some sort of crawling (configured in central administration)</li> <li>when the crawling is done, there is a slight delay, after which you can have your search results displayed.</li> </ul> <p>But, in a document library with publishing enabled, documents that are not published don't appear in search results. Is that normal ?</p>
<p>All contents are crawled using the default content access account. Most of the time, this is a dedicated account, and SharePoint give it "Full Read" permissions. </p> <p>Unfortunately, non approved items are not visible for "read users". So it will index the latest published version.</p> <p>However, you can't really give more permissions to this user. If you do so, it will always index unpublished item, without indexing the latest publish version. So user without approvers permissions won't be able to search those items.</p>
<p>I have had similar search issues, I assigned a domain service account to the content access account and resolved the items that serach could not find, I think it is due to users administrating a page and taking away all rights. </p>
35,921
<p>Say I have a table called myTable. What is the SQL command to return all of the field names of this table? If the answer is database specific then I need SQL Server right now but would be interested in seeing the solution for other database systems as well.</p>
<p>MySQL 3 and 4 (and 5):</p> <pre><code>desc tablename </code></pre> <p>which is an alias for</p> <pre><code>show fields from tablename </code></pre> <p>SQL Server (from 2000) and MySQL 5:</p> <pre><code>select COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = 'tablename' </code></pre> <p>Completing the answer: like people below have said, in SQL Server you can also use the stored procedure <code>sp_help</code></p> <pre><code>exec sp_help 'tablename' </code></pre>
<p>MySQL</p> <pre><code>describe tablename </code></pre>
12,580
<p>I lost my installation of Dave Gillespie's calc.el by reinstalling Cygwin. It is not included with the default Cygwin install of Emacs. Who is considered the master maintainer these days? Is version 2.02f still most current?</p>
<p>In the Emacs CVS tree. See <a href="http://www.gnu.org/software/emacs/calc.html" rel="nofollow noreferrer">the calc page</a> and the <a href="http://savannah.gnu.org/projects/emacs/" rel="nofollow noreferrer">Emacs project page</a>. The root of the calc subtree is <a href="http://cvs.savannah.gnu.org/viewvc/emacs/lisp/calc/?root=emacs" rel="nofollow noreferrer">here</a> and you can get the latest version by typing</p> <pre><code>cvs -d:pserver:anonymous@cvs.sv.gnu.org:/sources/emacs co emacs/lisp/calc </code></pre>
<p>Thanks to Jouni making it clear that GNU does maintain Emacs Calc, I have figured out that there is a Cygwin install of Emacs that does include Calc. The necessary step is forcing Cygwin Setup to install Emacs 22.1-3 instead of the default 21.2-13. I have sent a report to the cygwin@cygwin.com mailing list to get this repaired.</p>
39,657
<p>Any sugestions?</p> <p>Currently I'm using Squirell but it consumes quiet a bit of memory... I just use the sql client to run some queries and get the result but i absolutely need auto-complete of tables, columns, etc</p>
<p>RedGate who makes SQLCompare has a tool called SQL Prompt that provides:</p> <ul> <li>Intelligent code completion for fast, accurate script building </li> <li>Script layout for easy code readability </li> <li>Cross-database and linked-server query support </li> <li>Integrates with SSMS, SSMS Express, Query Analyzer and Visual Studio </li> <li>Keyword formatting, code snippet integration, column picker and many more features </li> </ul> <p>I have only tried the 14-day free trial and it was really nice to use. I mostly work in Query Analyser and it worked great there. </p> <p><a href="http://www.red-gate.com/products/SQL_Prompt/index.htm" rel="nofollow noreferrer">http://www.red-gate.com/products/SQL_Prompt/index.htm</a></p> <p>Nice demonstration video : <a href="http://www.red-gate.com/products/SQL_Prompt/video.htm" rel="nofollow noreferrer">http://www.red-gate.com/products/SQL_Prompt/video.htm</a></p>
<p>RedGate who makes SQLCompare has a tool called SQL Prompt that provides:</p> <ul> <li>Intelligent code completion for fast, accurate script building </li> <li>Script layout for easy code readability </li> <li>Cross-database and linked-server query support </li> <li>Integrates with SSMS, SSMS Express, Query Analyzer and Visual Studio </li> <li>Keyword formatting, code snippet integration, column picker and many more features </li> </ul> <p>I have only tried the 14-day free trial and it was really nice to use. I mostly work in Query Analyser and it worked great there. </p> <p><a href="http://www.red-gate.com/products/SQL_Prompt/index.htm" rel="nofollow noreferrer">http://www.red-gate.com/products/SQL_Prompt/index.htm</a></p> <p>Nice demonstration video : <a href="http://www.red-gate.com/products/SQL_Prompt/video.htm" rel="nofollow noreferrer">http://www.red-gate.com/products/SQL_Prompt/video.htm</a></p>
47,146
<p>is there an easy way of importing data from a mysql/odbc datasource into an excel spreadsheet? </p> <p>The user should be able to select some values from drop downs (e..g date range, branch name etc.) and the values from the dropdown should be used to populate (prepared) SQL statements. The results should be displayed in the Excel file. </p> <p>Ideally there would be a "save snapshot" menu item that would convert the dynamic excel file (with sql statements saved) as a static excel file thus reducing the exposure of internals (e.g. sql) to external ressources.</p> <p>Thanks</p>
<p>You can download an <a href="http://dev.mysql.com/downloads/connector/odbc/5.1.html" rel="nofollow noreferrer">ODBC driver for MySQL</a>, create a data source, and use <a href="http://office.microsoft.com/en-us/excel/HA100996641033.aspx" rel="nofollow noreferrer">MS Query</a> to create a custom SQL query that you can add to Excel via the Data menu.</p>
<p><a href="http://sqlexcel.net/" rel="nofollow noreferrer">http://sqlexcel.net/</a></p>
48,280
<p>I have data from MySQL showing all organisations a customer got, with all details of employess in each organisation. I want to list each organisation name only once i.e. in a single cell ( row span) and all employees in that organisation against this name like:</p> <pre><code>Org1 Emp1 Name, Emp1 Phone, Emp1 Address Emp2 Name, Emp2 Phone, Emp2 Address Org2 Emp1 Name, Emp1 Phone, Emp1 Address Emp2 Name, Emp2 Phone, Emp2 Address </code></pre> <p>How do I display this data because the number of employess for each organisation is not known in advanced, so I do'nt about setting value of rowspan. Similarly how do I start a row for other organisation? Do I have to write two queries?</p> <p>Many Thanks.</p>
<p>Classic.</p> <p>Workaround: only display the name if different than the previous one. You can even not bother about the rowspan (you keep an empty cell).</p> <pre><code>$currentOrg = ''; while ($row = mysql_fetch_object($query)) { if ($row-&gt;org != $currentOrg) { echo "$row-&gt;org". } $currentorg = $row-&gt;org; } </code></pre> <p>Not the most beautiful but so simple.</p>
<p>To make a correct <code>rowspan</code>, you need to know the number in advance.</p> <p>That leaves you with:</p> <ul> <li>iterating the query result twice, counting the values until they change</li> <li>asking the DB server for the count</li> </ul> <p>Personally, I would go with method number two. DB servers are quite efficient with counting rows, this will probably be a lot faster when there are many rows to display.</p>
26,936
<p>I am developing a web app that will be hit frequently by mobile browsers. I am wondering if there is a way to get enough information from the browser request to lookup position data (triangulation or GPS) <strong>Not from the request directly, of course.</strong> A colleague suggested there some carriers supply a unique identifier in the request header that can be sent to a web service exposed by said provider that will return position data if the customer has enabled that. Can anyone point me in the right direction for this or any other method for gleaning position data, even very approximate. Obviously this is app candy, e.g. if the data is not available the app doesn't really care...</p> <p>Or perhaps a web service by carrier that will provide triangulated data by IP?</p>
<p>Google has <a href="http://code.google.com/apis/ajax/documentation/#ClientLocation" rel="noreferrer">ClientLocation</a> as part of their AJAX APIs. You'll need to load Google's AJAX API (requires an API key) and it'll try to resolve the user's location data for you.</p>
<p>I know that some providers in Japan have a tracking service for location of cellphones. I also know that the information is not public. I think you need to have a very good reason before the provider gives that information free as it is in my opinion sensitive personal data. Of course they will give the information to police officers but not to the general public.</p>
12,335
<p>I need to store products for an e-commerce solution in a database. Each product should have descriptive information, such as name, description etc.</p> <p>I need any product to be localized to x number of languages.</p> <p>What I've done so far, is to make any column that should be localized and <code>nvarchar(MAX)</code> and then i store an XML string like this:</p> <pre><code>&lt;cultures&gt; &lt;culture code="en-us"&gt;Super fast laptop&lt;/culture&gt; &lt;culture code="da-dk"&gt;Super hurtig bærbar&lt;/culture&gt; &lt;/cultures&gt; </code></pre> <p>And when I load it from the database, into my business logic objects, I parse the XML string to a <code>Dictionary&lt;string, string&gt;</code> where the key is the culture/language code.</p> <p>So when I want to display the name of a product, I do this:</p> <pre><code>lblName.Text = product.Name["en-us"]; </code></pre> <p>Does anyone have a better solution?</p>
<p>You should store the current language somewhere (in a <a href="http://www.yoda.arachsys.com/csharp/singleton.html" rel="nofollow noreferrer">singleton</a>, for instance) and in the product.Name property use the language setting to get the correct string. This way you only have to write the language specific code once for each field rather than thinking about languages everywhere the field is used. </p> <p>For example, assuming your singleton is defined in the Localizer class that stores an enum corresponding to the current language:</p> <pre><code>public class Product { private idType id; public string Name { get { return Localizer.Instance.GetLocalString(id, "Name"); } } } </code></pre> <p>Where GetLocalString looks something like:</p> <pre><code> public string GetLocalString(idType objectId, string fieldName) { switch (_currentLanguage) { case Language.English: // db access code to retrieve your string, may need to include the table // the object is in (e.g. "Products" "Orders" etc.) db.GetValue(objectId, fieldName, "en-us"); break; } } </code></pre>
<p>This is basically the approach we took with Microsoft Commerce Server 2002. Yeah indexed views will help your performance.</p>
4,818
<p>I am retrieving Japanese characters from a data source and I want to return this data to Excel in an XLOPER. I am using a Japanese version of Excel 2003 (hence XLOPERs and not XLOPER12s).</p> <pre><code>wchar_t* pszW = OLE2W(bstrResult); //I have the data I am trying to copy in a CComBSTR ULONG ulSize = ::WideCharToMultiByte( CP_THREAD_ACP, 0, pszW, -1, NULL, 0, NULL, NULL ); if ( ulSize ) { char* tmp = new char[ulSize + 1]; tmp[ulSize]='\0'; ::WideCharToMultiByte( CP_THREAD_ACP, 0, pszW, -1, LPSTR( tmp ), ulSize, NULL, NULL ); pszReturn = tmp; } wchar_t* pwszOut = new wchar_t[bstrResult.Length () + 1]; //now turn it back to test that that the correct code page was used. For debugging purposes only! ::MultiByteToWideChar (CP_THREAD_ACP,0, LPSTR(pszReturn),-1,pwszOut,bstrResult.Length () + 1); //pwszOut and bstrResult look the same in the debugger delete [] pwszOut; </code></pre> <p>The parameter pszReturn is assigned to an XLOPER. The problem I have is that “アフリカの女王” is displayed as “ƒAƒtƒŠƒJ‚Ì—‰¤” in Excel.</p> <p>Manually setting the code page to 932 yields the same results as CP_THREAD_ACP so I think that that part is correct.</p> <p>Any help would be greatly appreciated.</p>
<p><strong><em>User Error!</em></strong></p> <p>The above code is good. The problem is that Excel was using the wrong code page. I hadn't set the language for non-unicode programs to Japanese in Control Panel.</p> <p>The code now works for the English version of Excel too.</p> <p>That was a day and a half well spent...</p>
<p>A char* is a sequence of bytes, interpreted using the current charset. To be precose, that is the charset used by the party doing the interpretation. In this case, Execl is receiving a charset that <em>should</em> be interpreted using codepage 932, but instead Excel is using another codepage.</p> <p>The solution, as always is Unicode, in Excel represented by XLOPER12</p>
49,007
<p>I've used the <a href="http://msdn.microsoft.com/en-us/library/8bch7bkk.aspx" rel="nofollow noreferrer"><code>setargv.obj</code> linking for Expanding Wildcard Arguments</a> in the past for a number of C and C++ apps, but I can't find any similar mention for .net applications.</p> <p><strong>Is there a standard way to have your app's command line parameters automatically wildcard expanded?</strong> (i.e. expand <code>*.doc</code> from one entry in args parameter to all that match that wildcard).</p> <p>P.S. I've hacked something together with <code>Directory.GetFiles()</code> for my current little project, but it does not cover wildcards with paths (yet), and it would be nice to do it without custom code.</p> <p><strong>Update:</strong> here is my rough hack, for illustration. It needs to split the parameters for the path and name for the <code>GetFiles()</code>, but this is a general idea. Linking <code>setargv.obj</code> into a C or C++ app would basically do all the wildcard expansion, leaving the user to only iterate over the argv array.</p> <pre class="lang-cs prettyprint-override"><code>public static void Main(string[] args) { foreach (string argString in args) { // Split into path and wildcard int lastBackslashPos = argString.LastIndexOf('\\') + 1; path = argString.Substring(0, lastBackslashPos); filenameOnly = argString.Substring(lastBackslashPos, argString.Length - lastBackslashPos); string[] fileList = System.IO.Directory.GetFiles(path, filenameOnly); foreach (string fileName in fileList) { // do things for each file } } } </code></pre>
<p>Here us my rough hack. I'd love for it to be recursive. And having experienced the shortcoming of Windows wildcards I might decide to use regular expressions rather than letting GetFiles() do it for me.</p> <pre><code>using System.IO; public static string[] ExpandFilePaths(string[] args) { var fileList = new List&lt;string&gt;(); foreach (var arg in args) { var substitutedArg = System.Environment.ExpandEnvironmentVariables(arg); var dirPart = Path.GetDirectoryName(substitutedArg); if (dirPart.Length == 0) dirPart = "."; var filePart = Path.GetFileName(substitutedArg); foreach (var filepath in Directory.GetFiles(dirPart, filePart)) fileList.Add(filepath); } return fileList.ToArray(); } </code></pre>
<p>I'm not sure exactly what you're after... but if I get where you're going with the Directory.GetFiles() "hack" you mentioned, then something like this might work:</p> <pre><code>var Dirs = Directory.GetDirectories(@"C:\Windows", "sys*", SearchOption.TopDirectoryOnly).ToList(); var Files = new List&lt;String&gt;(); Dirs.ForEach(dirName =&gt; Files.AddRange(Directory.GetFiles(dirName, "*.sys", SearchOption.AllDirectories))); </code></pre> <p>The wildcard option on the GetDirectories call will allow you to grab all the directories contained in the Windows folder [directly] that match the pattern "sys*".</p> <p>You can then iterate over those folders grabbing all the files that match the pattern "*.sys".</p> <p>Is that the kind of thing you're looking for? To automatically expand the args, you'd have to extract the wildcards in some kind of meaningful manner and apply them to that model...</p> <p>For instance:</p> <p>RunMyApp "C:\Windows\Sys*\ *.sys"</p> <p>You'd pull out the string C:\Windows - probably with a regular expression, find the lowest level directory that doesn't contain a wildcard and apply it to the GetDirectories method, attaching the wildcarded string as the search parameter.</p> <p>Then if your end of string (in this case *.sys) as the search pattern for Directory.GetFiles.</p> <p>If you wanted to get more complicated and do something like:</p> <pre><code>C:\Windows\*\Sys*\*.sys </code></pre> <p>You would use the SearchOptions to set this behaviour:</p> <pre><code>Directory.GetDirectories(@"C:\Windows", "sys*", SearchOptions.AllDirectories) </code></pre> <p>This would grab all directories that matched the sys* wildcard in the Windows directory and all directories below it.</p> <p>If you wanted to get much more complicated than that, then I'm not sure how you would do that... for instance, say you wanted folders that are contained by folders directly inside the Windows directory - I have no idea how you would go about something like that I'm afraid...I don't imagine exporting the entire tree structure to XML and using XPath to do it would be so efficient - the XPath would be fabulously simple for parsing out using wildcards - but converting to XML wouldn't be so efficient...</p>
49,986
<p>I am looking for a way to display a modal window in WPF the same way as a window in Cocoa can be displayed as a sheet, i.e. it slides down from the titlebar in front of the main parent window.</p> <p>My guess is that this would be accomplished by having the modal window as a user control which is loaded into a panel when displayed, and that this panel is the one which would be animated somehow from the titlebar.</p> <p>Any ideas on how to do this?</p> <p><em>P.S: <a href="http://cocoadevcentral.com/articles/000014.php" rel="nofollow noreferrer">Here</a> is a brief description of the NSWindow/sheet in case you don't what it is</em>.</p>
<p>Don't. It's not the expected user experience on Windows. Use modal dialogs or in-window navigation instead.</p>
<p>Thanks for the answers guys.</p> <p>My main objective for this was to have a shared window for the two windows, but I do not want to make it break any expected UX either so I'll take your answers into consideration and try to make up another idea for this.</p>
26,480
<p>I just want to see what files were modded/added/deleted between 2 arbitrary revisions. How do I do this?</p> <p>Can I do this in tortoise as well?</p>
<pre><code>svn log -v -rX:Y . </code></pre> <p>The -v for "verbose" switch will give you detailed output on which files were affected on that revision.</p> <p>Note that "." assumes you are currently in a working copy directory, but you can also use a URL such as "<a href="http://svn.myawesomesoftwareproject.com/trunk/lib/foo.c" rel="noreferrer">http://svn.myawesomesoftwareproject.com/trunk/lib/foo.c</a>".</p> <p>This information can be found by typing "svn help log", or by reading the <a href="http://svnbook.red-bean.com/" rel="noreferrer">SVN Book</a>, available free online. Don't forget to <strong>R</strong>ead <strong>T</strong>he <strong>F</strong>riendly <strong>M</strong>anual!</p>
<p>This worked for me on windows</p> <ol> <li>Go to your folder where you have the repository,</li> <li>right click and select SVN Show log,</li> <li>In the dialog box there is a "Show Range" button, click it and fill <em>Start Revision</em> = {your revision} and <em>End Revision</em> = {your revision}</li> <li>Select the Start and Date range as per your need</li> </ol> <p>Note: {your revision}=provide the revision number for atleast one of your file changes. All files associated with that revision should get listed.</p>
20,212
<p>What is the scope of Runtime Callable Wrapper (RCW), when referencing unmanaged COM objects? According to the docs:</p> <blockquote> <p>The runtime creates exactly one RCW for each COM object, regardless of the number of references that exist on that object.</p> </blockquote> <p>If I had to "guess" - this explanation should mean "one per process", but is it really? Any additional documentation will be very welcome.</p> <p>My application runs in its own application domain (it is Outlook addin), and I would like to know what happens if I use Marshal.ReleaseComObject(x) in a loop until it's count reaches 0 (as recommended). Will it release references from other addins (running in other application domain in the same Outlook process)?</p> <p>EDIT: Perfect - now the confusion is even bigger. Based on the 2 answers (from Lette and Ilya) we have 2 different answers. The official <a href="http://msdn.microsoft.com/en-us/library/8bwh56xe(VS.80).aspx" rel="nofollow noreferrer">MSDN doc</a> says per process (for ver. 2.0+), but it is missing this sentence for <a href="http://msdn.microsoft.com/en-us/library/8bwh56xe(VS.71).aspx" rel="nofollow noreferrer">ver. 1.1 of the doc</a>.</p> <p>In the same time, in Mason Bendixen's article, it says it's per appdomain.</p> <p>As his article is old (April 2007), I have send him an email asking for clarification, but if someone else has to add something, please do.</p> <p>Thanks</p>
<blockquote> <p>In managed, we have a per app domain cache mapping canonical IUnknowns back to RCWs. When an IUnknown enters the system (through a marshal call, through activation, as a return parameter from a method call, etc.), we check the cache to see if an RCW already exists for the COM object. If a mapping exists, a reference to the existing RCW is returned. Otherwise a new RCW is created and a cache mapping is added.</p> </blockquote> <p>from <a href="http://blogs.msdn.com/mbend/" rel="nofollow noreferrer">Mason's Blog</a></p>
<p>According to the same docs:</p> <blockquote> <p>The runtime maintains a single RCW <strong>per process</strong> for each object.</p> </blockquote> <p>I think we can safely assume that <em>object</em> = <em>instance</em>, so if the addins/AppDomains doesn't hold references to the same instance, the call to <code>ReleaseComObject</code> won't release references to instances created elsewhere.</p> <p>Edit: The wording of the docs may be wrong, <a href="https://stackoverflow.com/questions/159313/runtime-callable-wrapper-rcw-scope-process-or-application-domain#170360">as stated elsewhere</a>. If so, since your add-in is running in a separate AppDomain, you're in luck. Even if the different add-ins reference the same instance (e.g. a Message object in Outlook), <code>ReleaseComObject</code> called in your AppDomain will not cause RCWs in other AppDomains to lose the reference to that instance. </p>
19,273
<p>I'd like to extract the text from an HTML file using Python. I want essentially the same output I would get if I copied the text from a browser and pasted it into notepad. </p> <p>I'd like something more robust than using regular expressions that may fail on poorly formed HTML. I've seen many people recommend Beautiful Soup, but I've had a few problems using it. For one, it picked up unwanted text, such as JavaScript source. Also, it did not interpret HTML entities. For example, I would expect &amp;#39; in HTML source to be converted to an apostrophe in text, just as if I'd pasted the browser content into notepad.</p> <p><strong>Update</strong> <code>html2text</code> looks promising. It handles HTML entities correctly and ignores JavaScript. However, it does not exactly produce plain text; it produces markdown that would then have to be turned into plain text. It comes with no examples or documentation, but the code looks clean.</p> <hr> <p>Related questions:</p> <ul> <li><a href="https://stackoverflow.com/questions/37486/filter-out-html-tags-and-resolve-entities-in-python">Filter out HTML tags and resolve entities in python</a></li> <li><a href="https://stackoverflow.com/questions/57708/convert-xmlhtml-entities-into-unicode-string-in-python">Convert XML/HTML Entities into Unicode String in Python</a></li> </ul>
<p><a href="https://github.com/Alir3z4/html2text" rel="noreferrer">html2text</a> is a Python program that does a pretty good job at this.</p>
<p>I am achieving it something like this. </p> <pre><code>&gt;&gt;&gt; import requests &gt;&gt;&gt; url = "http://news.bbc.co.uk/2/hi/health/2284783.stm" &gt;&gt;&gt; res = requests.get(url) &gt;&gt;&gt; text = res.text </code></pre>
42,546
<p>I'm currently developing a PHP application that's using an Access database as a backend. Not by choice you understand... the database is what the client used originally and using it is part of the requirements.<br><br> One of the problems with this database is that the column names have the most insane naming convention you could possibly imagine. Uppercase, lowercase, underscores, spaces and the plain insane. For example the column "gender" holds a date. And so does column "User2". There's a lot more but you get the idea.<br><br> Faced with this I decided to create an array to map the database columns to PHP variables so we can isolate the code from the madness. However my colleague believes that I'm over-complicating things and we should use the database's column names for the corresponding PHP variables so we don't need to go through the mapping array to find what goes where.<br><br> So my question is this... am I doing the right thing or am I complicating things?</p>
<p>Absolutely you are on the right track. If you don't abstract away the madness you will eventually succumb to the madness yourself.</p> <p>Your colleague has a valid point though, so I suggest you also code an easy way to determine the data to column mapping in PHP. </p> <p>This isn't about keeping it simple, it's about retrofitting a solid foundation to build upon.</p> <p>The thing that would worry me is that this kind of random design often hides certain business rules, things like "...if the gender is a date then they must have purchased a widget at some point therefore they can't be allowed to fribbish the lubdub... " - crazy I know but more common than it should be.</p>
<p>Use a ORM, you will be changing the db soon...</p>
41,896
<p>Let me explain: this is path to this folder: > <code>www.my_site.com/images</code></p> <p>And images are created by <code>user_id</code>, and for example, images of <code>user_id = 27</code> are, <code>27_1.jpg</code>, <code>27_2.jpg</code>, <code>27_3.jpg</code>! How to list and print images which start with <code>27_%.jpg</code>? I hope You have understood me! PS. I am totally beginmer in ASP.NET (VB) and please give me detailed information</p> <p>Here starts my loop</p> <pre><code>while dbread.Read() 'and then id user_id dbread('user_id') </code></pre> <p>NEXT???</p> <hr> <p>I nedd to create XML, till now I created like this:</p> <p>act.WriteLine("") act.WriteLine("<a href="http://www.my_site.com/images/" rel="nofollow noreferrer">http://www.my_site.com/images/</a>"&amp;dbread("user_id")&amp;"_1.jpg") act.WriteLine("")</p> <p>But this is not answer because I need to create this nodes how many images of this user exist?</p> <p>In database doesn't exist list of this images so that is reason why I must count them in folder. (this is not my site exacly, but I need to create XMl on this site)</p> <p>Do you understand me?</p>
<p>Environment variables are inherited by processes in Unix. The files in /etc/profile.d are only executed (in the current shell, not in a subshell) when you log in. Just changing the value there and then restarting a process will not update the environment. </p> <p>Possible Fixes:</p> <ul> <li>log out/log in, then start apache</li> <li>source the file: <code># . /etc/profile.d/foo.sh</code>, then restart apache</li> <li>source the file in the apache init script</li> </ul> <p>You also need to make sure that <code>/etc/profile.d/</code> is sourced when Apache is started by <code>init</code> rather than yourself. </p> <p>The best fix might also depend on the distribution you are using, because they use different schemes for configuration.</p>
<p>You can use <a href="http://httpd.apache.org/docs/2.2/mod/mod_env.html#setenv" rel="nofollow noreferrer">SetEnv</a> in your config files (/etc/httpd/conf.d/*.conf, .htaccess ...). Additionally you should be able to define them in /etc/sysconfig/httpd (on RPM-based distribs) and <em>export</em> them (note: not tested).</p> <p>Note: it wouldn't surprise me if some distributions tried quite hard to hide as much as possible, as far as system config is concerned, from a publically accessible service such as Apache. And if they don't, they might start doing this in a future version. Hence I advise you to do this explicitly. If you need to share such a setting between Apache and your shells, you could try sourcing <em>/etc/profile.d/yourprofile.sh</em> from <em>/etc/sysconfig/httpd</em></p>
13,946
<p>WPF doesn't provide the ability to have a window that allows resize but doesn't have maximize or minimize buttons. I'd like to able to make such a window so I can have resizable dialog boxes.</p> <p>I'm aware the solution will mean using pinvoke but I'm not sure what to call and how. A search of pinvoke.net didn't turn up any thing that jumped out at me as what I needed, mainly I'm sure because Windows Forms does provide the <code>CanMinimize</code> and <code>CanMaximize</code> properties on its windows.</p> <p>Could someone point me towards or provide code (C# preferred) on how to do this?</p>
<p>I've stolen some code I found on the MSDN forums and made an extension method on the Window class, like this:</p> <pre><code>internal static class WindowExtensions { // from winuser.h private const int GWL_STYLE = -16, WS_MAXIMIZEBOX = 0x10000, WS_MINIMIZEBOX = 0x20000; [DllImport("user32.dll")] extern private static int GetWindowLong(IntPtr hwnd, int index); [DllImport("user32.dll")] extern private static int SetWindowLong(IntPtr hwnd, int index, int value); internal static void HideMinimizeAndMaximizeButtons(this Window window) { IntPtr hwnd = new System.Windows.Interop.WindowInteropHelper(window).Handle; var currentStyle = GetWindowLong(hwnd, GWL_STYLE); SetWindowLong(hwnd, GWL_STYLE, (currentStyle &amp; ~WS_MAXIMIZEBOX &amp; ~WS_MINIMIZEBOX)); } } </code></pre> <p>The only other thing to remember is that for some reason this doesn't work from a window's constructor. I got around that by chucking this into the constructor:</p> <pre><code>this.SourceInitialized += (x, y) =&gt; { this.HideMinimizeAndMaximizeButtons(); }; </code></pre> <p>Hope this helps!</p>
<p>Just use</p> <pre><code>WindowStyle=&quot;ToolWindow&quot; </code></pre> <p>It hides the maximize and minimize buttons, but the window can still be resized by dragging the window borders and minimize using the hide button in the bottom right corner of the taskbar.</p> <p><a href="https://learn.microsoft.com/en-us/dotnet/api/system.windows.window.windowstyle?view=windowsdesktop-6.0" rel="nofollow noreferrer">https://learn.microsoft.com/en-us/dotnet/api/system.windows.window.windowstyle?view=windowsdesktop-6.0</a></p>
44,106
<p>Here's the code that I'm attempting to do:</p> <pre><code>public IList&lt;IOperator&gt; GetAll() { using (var c = new MyDataContext()) { return c.Operators.ToList(); } } </code></pre> <p>Operator implements IOperator, but I'm getting the following compilation error:</p> <pre><code>Cannot implicitly convert type 'System.Collections.Generic.List&lt;MyProject.Core.Operator&gt;' to 'System.Collections.Generic.IList&lt;MyProject.Core.Model.IOperator&gt;'. An explicit conversion exists (are you missing a cast?) </code></pre> <p>How do I cast this to get what I need?</p>
<p>Try the <code>Cast&lt;&gt;()</code> method:</p> <pre><code>return c.Operators.Cast&lt;IOperator&gt;().ToList(); </code></pre>
<p>Edit: Actually,</p> <p>return (List&lt; IOperator >)c.Operators.ToList();</p> <p>would <em>not</em> do the trick. Sorry</p>
16,246
<p>From <a href="http://en.wikipedia.org/wiki/AJAX" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/AJAX</a>, I get a fairly good grasp of what AJAX is. However, it looks like in order to learn it, I'd have to delve into multiple technologies at the same time to get any benefit out of it. So two questions:</p> <ul> <li>What are resources that can help me understand/use AJAX?</li> <li>What sort of website would benefit from AJAX?</li> </ul>
<p>If you aren't interested in the nitty gritty, you could use a higher-level library like <a href="http://jquery.com/" rel="nofollow noreferrer">JQuery</a> or <a href="http://www.prototypejs.org/" rel="nofollow noreferrer">Prototype</a> to create the underlying Javascript for you. The main benefit is a vastly more responsive user interface for web-based applications.</p>
<p>The Mozilla <a href="http://developer.mozilla.org/En/AJAX" rel="nofollow noreferrer">documentation</a> is good. Sites that benefit from it the most are ones that behave almost like a desktop application and need high interactivity. You can usually improve usability on almost any site by using it, however.</p>
12,853
<p><em>Problem:</em> There are a bunch of .lnk files on the C drive that point to the J: drive, but the J: drive is gone, and the P: drive has replaced it. Various tricks have been done to get the .lnk files to still work anyway, but it's getting annoying, and it's time to just fix the things.</p> <p>Using Ruby, Python, WSH.JScript or Perl, can you iterate through an entire directory tree of .lnk files and change them so they point to p:/* instead of j:/*? How would you go about it?</p> <p><em>Note:</em> This is not a total unknown to me, but I ask the question anyway because the API for managing .lnk files in the ways I've found so far seem too cumbersome to be the best known way of doing this. This is one of those desparate "there's got to be a better way" type questions.</p>
<p>In the WindowsNT Resource Kit there's a command line utility called Shortcut.exe that I'm reliably informed will run under XP/2000/2003 as well. You can use a variety of command line switches to modify existing LNK files to point to new shortcuts.</p> <p>I found information about it here: <a href="http://www.ss64.com/nt/shortcut.html" rel="nofollow noreferrer">http://www.ss64.com/nt/shortcut.html</a></p> <p>I daresay it can't be too hard to hunt down the WindowsNT Resource Kit on the Microsoft Website and extract it. It's a command line utility, so you should be able to batch it to loop through all the LNK files and modify them so they're correct.</p>
<p>We found this VB Script which works fine.</p> <p><a href="http://www.enterpriseitplanet.com/resources/scripts_win/article.php/3081941" rel="nofollow noreferrer">http://www.enterpriseitplanet.com/resources/scripts_win/article.php/3081941</a></p> <p>Some warnings:</p> <p>Careful! It runs from the root of the drive. If you test it on your own machine, you risk remapping all your Windows shortcuts - eg. those on your Start Menu! We edited the script slightly to get a bit more control (within the Main() method):</p> <pre><code> dim onlyFolder Set onlyFolder =fso.GetFolder("C:\") SearchFolder onlyFolder ' for each aDrive in fso.Drives ' if aDrive.DriveType = 2 then ' SearchFolder aDrive.RootFolder ' end if ' next </code></pre> <p>The fixlinks.ini file doesn't like empty lines, it has to be an even number of lines.</p> <p>It runs in the background and may pop up permission errors for difficult directories. It's difficult to tell when it has finished, except for the confirmation window at the end. Probably best to keep an eye on it in Process Explorer, and run it from a command shell as Administrator on Vista/etc.</p> <p>Other than that, worked great!</p>
44,529
<p>Before I write my own I will ask all y'all.</p> <p>I'm looking for a C++ class that is almost exactly like a STL vector but stores data into an array on the stack. Some kind of STL allocator class would work also, but I am trying to avoid any kind of heap, even static allocated per-thread heaps (although one of those is my second choice). The stack is just more efficient.</p> <p>It needs to be almost a drop in replacement for current code that uses a vector.</p> <p>For what I was about to write myself I was thinking of something like this:</p> <pre><code>char buffer[4096]; stack_vector&lt;match_item&gt; matches(buffer, sizeof(buffer)); </code></pre> <p>Or the class could have buffer space allocated internally. Then it would look like:</p> <pre><code>stack_vector&lt;match_item, 256&gt; matches; </code></pre> <p>I was thinking it would throw std::bad_alloc if it runs out of space, although that should not ever happen.</p> <p><strong>Update</strong></p> <p>Using Chromium's stack_container.h works great! </p> <p>The reason I hadn't thought of doing it this way myself is that I have always overlooked the allocator object parameter to the STL collection constructors. I have used the template parameter a few times to do static pools but I'd never seen code or written any that actually used the object parameter. I learned something new. Very cool!</p> <p>The code is a bit messy and for some reason GCC forced me to declare the allocator as an actual item instead of constructing it into vector's allocator parameter. It went from something like this:</p> <pre><code>typedef std::pair&lt; const char *, const char * &gt; comp_list_item; typedef std::vector&lt; comp_list_item &gt; comp_list_type; comp_list_type match_list; match_list.reserve(32); </code></pre> <p>To this:</p> <pre><code>static const size_t comp_list_alloc_size = 128; typedef std::pair&lt; const char *, const char * &gt; comp_list_item; typedef StackAllocator&lt; comp_list_item, comp_list_alloc_size &gt; comp_list_alloc_type; typedef std::vector&lt; comp_list_item, comp_list_alloc_type &gt; comp_list_type; comp_list_alloc_type::Source match_list_buffer; comp_list_alloc_type match_list_alloc( &amp;match_list_buffer ); comp_list_type match_list( match_list_alloc ); match_list.reserve( comp_list_alloc_size ); </code></pre> <p>And I have to repeat that whenever I declare a new one. But it works just like I wanted.</p> <p>I noticed that stack_container.h has a StackVector defined and I tried using it. But it doesn't inherit from vector or define the same methods so it wasn't a drop-in replacement. I didn't want to rewrite all the code using the vector so I gave up on it.</p>
<p>You don't have to write a completely new container class. You can stick with your STL containers, but change the second parameter of for example <code>std::vector</code> to give it your custom allocator which allocates from a stack-buffer. The chromium authors wrote an allocator just for this:</p> <p><a href="https://chromium.googlesource.com/chromium/chromium/+/master/base/stack_container.h" rel="noreferrer">https://chromium.googlesource.com/chromium/chromium/+/master/base/stack_container.h</a></p> <p>It works by allocating a buffer where you say how big it is. You create the container and call <code>container.reserve(buffer_size);</code>. If you overflow that size, the allocator will automatically get elements from the heap (since it is derived from <code>std::allocator</code>, it will in that case just use the facilities of the standard allocator). I haven't tried it, but it looks like it's from google so i think it's worth a try. </p> <p>Usage is like this:</p> <pre><code>StackVector&lt;int, 128&gt; s; s-&gt;push_back(42); // overloaded operator-&gt; s-&gt;push_back(43); // to get the real std::vector. StackVector&lt;int, 128&gt;::ContainerType &amp; v = s.container(); std::cout &lt;&lt; v[0] &lt;&lt; " " &lt;&lt; v[1] &lt;&lt; std::endl; </code></pre>
<p>Boost have this. Its called <a href="http://www.boost.org/doc/libs/1_60_0/doc/html/container/non_standard_containers.html#container.non_standard_containers.small_vector" rel="nofollow">small_vector</a></p> <blockquote> <p>small_vector is a vector-like container optimized for the case when it contains few elements. It contains some preallocated elements in-place, which allows it to avoid the use of dynamic storage allocation when the actual number of elements is below that preallocated threshold. small_vector is inspired by LLVM's SmallVector container. Unlike static_vector, small_vector's capacity can grow beyond the initial preallocated capacity.</p> <p>small_vector is convertible to small_vector_base, a type that is independent from the preallocated element count, allowing client code that does not need to be templated on that N argument. small_vector inherits all vector's member functions so it supports all standard features like emplacement, stateful allocators, etc.</p> </blockquote>
46,174
<p>What is the difference, what is the official terms, are any terms obsolete in ASP.NET 3.5?</p>
<p><strong>UserControl</strong>: A custom control, ending in .ascx, that is composed of other web controls. Its almost like a small version of an aspx webpage. It consists of a UI (the ascx) and codebehind. Cannot be reused in other projects by referencing a DLL.</p> <p><strong>WebControl</strong>: A control hosted on a webpage or in a UserControl. It consists of one or more classes, working in tandem, and is hosted on an aspx page or in a UserControl. WebControls don't have a UI "page" and must render their content directly. They can be reused in other applications by referencing their DLLs.</p> <p><strong>RenderedControl</strong>: Does not exist. May be synonymous to WebControl. Might indicate the control is written directly to the HttpResponse rather than rendered to an aspx page.</p> <p><strong><a href="http://msdn.microsoft.com/en-us/library/aa479016.aspx" rel="noreferrer">CompositeControl</a></strong>: Inbetween UserControls and WebControls. They code like UserControls, as they are composed of other controls. There is not any graphical UI for control compositing, and support for UI editing of CompositeControls must be coded by the control designer. Compositing is done in the codebehind. CompositeControls can be reused in other projects like WebControls. </p>
<p>Since I don't have enough reputation yet to comment, I'll add this as an answer, but it refers to Will's answer above.</p> <p>From the <a href="http://msdn.microsoft.com/en-us/library/aa479016.aspx" rel="nofollow noreferrer">link</a> you included:</p> <blockquote> <p>Composite controls are the right tool to architect complex components in which multiple child controls are aggregated and interact among themselves and with the outside world. Rendered controls are just right for read-only aggregation of controls in which the output doesn't include interactive elements such as drop-down or text boxes.</p> </blockquote> <p>I believe the documentation is refering to UserControls that have been created by overriding the Render method as Rendered Controls. Thus, it is not a separate type as the question implies, but a way of implementing a UserControl; a pattern.</p>
9,653
<p>In C#, if I want to deterministically clean up non-managed resources, I can use the "using" keyword. But for multiple dependent objects, this ends up nesting further and further:</p> <pre><code>using (FileStream fs = new FileStream("c:\file.txt", FileMode.Open)) { using (BufferedStream bs = new BufferedStream(fs)) { using (StreamReader sr = new StreamReader(bs)) { // use sr, and have everything cleaned up when done. } } } </code></pre> <p>In C++, I'm used to being able to use destructors to do it like this:</p> <pre><code>{ FileStream fs("c:\file.txt", FileMode.Open); BufferedStream bs(fs); StreamReader sr(bs); // use sr, and have everything cleaned up when done. } </code></pre> <p>Is there a better way in C# to do this? Or am I stuck with the multiple levels of nesting?</p>
<p>You don't have to nest with multiple usings:</p> <pre><code>using (FileStream fs = new FileStream("c:\file.txt", FileMode.Open)) using (BufferedStream bs = new BufferedStream(fs)) using (StreamReader sr = new StreamReader(bs)) { // all three get disposed when you're done } </code></pre>
<p>The using statement is syntactic sugar that converts to:</p> <pre><code> try { obj declaration ... } finally { obj.Dispose(); } </code></pre> <p>You can explicitly call Dispose on your objects, but it won't be as safe, since if one of them throws an exception, the resources won't be freed properly.</p>
10,136
<p>I have thus far avoided the nightmare that is testing multi-threaded code since it just seems like too much of a minefield. I'd like to ask how people have gone about testing code that relies on threads for successful execution, or just how people have gone about testing those kinds of issues that only show up when two threads interact in a given manner?</p> <p>This seems like a really key problem for programmers today, it would be useful to pool our knowledge on this one imho.</p>
<p>Look, there's no easy way to do this. I'm working on a project that is inherently multithreaded. Events come in from the operating system and I have to process them concurrently.</p> <p>The simplest way to deal with testing complex, multithreaded application code is this: If it's too complex to test, you're doing it wrong. If you have a single instance that has multiple threads acting upon it, and you can't test situations where these threads step all over each other, then your design needs to be redone. It's both as simple and as complex as this.</p> <p>There are many ways to program for multithreading that avoids threads running through instances at the same time. The simplest is to make all your objects immutable. Of course, that's not usually possible. So you have to identify those places in your design where threads interact with the same instance and reduce the number of those places. By doing this, you isolate a few classes where multithreading actually occurs, reducing the overall complexity of testing your system.</p> <p>But you have to realize that even by doing this, you still can't test every situation where two threads step on each other. To do that, you'd have to run two threads concurrently in the same test, then control exactly what lines they are executing at any given moment. The best you can do is simulate this situation. But this might require you to code specifically for testing, and that's at best a half step towards a true solution.</p> <p>Probably the best way to test code for threading issues is through static analysis of the code. If your threaded code doesn't follow a finite set of thread safe patterns, then you might have a problem. I believe Code Analysis in VS does contain some knowledge of threading, but probably not much.</p> <p>Look, as things stand currently (and probably will stand for a good time to come), the best way to test multithreaded apps is to reduce the complexity of threaded code as much as possible. Minimize areas where threads interact, test as best as possible, and use code analysis to identify danger areas.</p>
<p>(if possible) don't use threads, use actors / active objects. Easy to test.</p>
3,326
<p>Has anybody managed to get the Android Emulator working behind a proxy that requires authentication?</p> <p>I've tried setting the -http-proxy argument to</p> <pre><code>http://DOMAIN/USERNAME:PASSWORD@IP:PORT </code></pre> <p>but am having no success.</p> <p>I've tried following the docs to no avail. I've also tried the <code>-verbose-proxy</code> setting but this no longer seems to exist.</p> <p>Any pointers?</p>
<p>I Managed to do it in the Adndroid 2.2 Emulator.</p> <pre><code>Go to "Settings" -&gt; "Wireless &amp; Networks" -&gt; "Mobile Networks" -&gt; "Access Point Names" -&gt; "Telkila" </code></pre> <p>Over there set the proxy host name in the property "Proxy" and the Proxy port in the property "Port"</p>
<p>I had the same problem when i use the following command:</p> <pre><code>emulator-x86.exe -http-proxy domain\user:password@proxyIP:port -avd MyAVD </code></pre> <p>I got the proxy authentication error.</p> <p>Finally, I had to bypass the proxy NTLM authentication by using the Cntlm here:</p> <p><a href="http://sourceforge.net/projects/cntlm/" rel="nofollow">http://sourceforge.net/projects/cntlm/</a></p> <p>And then after simply configuring the cntlm.ini, I use the following command instead:</p> <pre><code>emulator-x86.exe -http-proxy 127.0.0.1:3128 -avd MyAVD </code></pre> <p>and it works :)</p>
4,804
<p>I usually never see test for new in C++ and I was wondering why.</p> <p><code>Foo *f = new Foo;</code></p> <p><code>// f is assumed as allocated, why usually, nobody test the return of new?</code></p>
<p>As per the current standard, <em>new</em> never returns <em>NULL</em>, it throws a std::bad_alloc instead. If you don't want new to throw(as per the old standard) but rather return NULL you should call it by postfixing it with "<em>(std::nothrow)</em>". i.e.</p> <pre><code>Foo* foo = new (std::nothrow) Foo; </code></pre> <p>Of course, if you have a very old or possibly broken toolchain it might not follow the standard.</p>
<p>Usually no one tests the return of new in new code because Visual Studio now throws the way the standard says.</p> <p>In old code if a hack has been done to avoid throwing then you'd still better test.</p>
29,608
<p>I have been reading the <a href="http://msdn.microsoft.com/en-us/library/ms997565.aspx" rel="nofollow noreferrer">MSDN</a> documentation on subclassing and I have been successful in handling events in a subclass</p> <p>My issue is with passing messages back to the original WndProc.</p> <p>As an example, if I have a window, with a sub-classed groupbox control and a button as a child of that groupbox, I want to handle the button event in the original window procedure, not the subclassed groupbox procedure.</p> <p>Essentially, I want an empty subclass procedure:</p> <pre><code>LRESULT FAR PASCAL SubClassFunc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { return CallWindowProc(oldProc, hwnd, uMsg, wParam, lParam); } </code></pre> <p>Where oldProc is:</p> <pre><code>FARPROC oldProc = (FARPROC)SetClassLong(group_box, GCL_WDPROC, (DWORD)SubCLassFunc); </code></pre> <p>And where the window and groupbox and button are:</p> <pre><code>HWND window = CreateWindowEx( WS_EX_WINDOWEDGE, appname, TEXT("Subclass Test"), WS_VISIBLE |WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 300, 400, NULL, NULL, hInstance, 0); HWND group_box = CreateWindowEx( 0, TEXT("BUTTON"), TEXT("Group Box"), WS_CHILD | WS_VISIBLE | BS_GROUPBOX, 8, 8, 275, 350, window, NULL, hInstance, 0); HWND push_button = CreateWindowEx( 0, TEXT("BUTTON"), TEXT("Push Button"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_VCENTER, 50, 100, 100, 25, group_box, (HMENU)PUSH_BUTTON, hInstance, 0); </code></pre> <p>I can handle the button events in the SubClassFunc, but what I want to do is pass them back to the window WndProc. It seems that CallWindowProc isn't doing this, or I may be totally wrong in how CallWindowProc works.</p>
<p>The button notifications are sent to the button's parent, which is the group box. Because you've subclassed the group box, your <code>SubClassFunc</code> receives these messages, which then passes them to the group box's original window procedure using <code>CallWindowProc</code>.</p> <p>If you want the button notifications to go to the parent window (i.e, <code>window</code> in your code), you could either set the button's parent to <code>window</code> instead of <code>group_box</code>, or use <code>PostMessage</code> from within <code>SubClassFunc</code> to post the message (<code>WM_COMMAND</code> or <code>WM_NOTIFY</code> as appropriate) to <code>window</code>.</p> <p>Also, I see that you're using <code>SetClassLong</code> to set the window procedure. What this does is replace the window procedure for the entire <code>BUTTON</code> class, but only for windows that are subsequently created. Any <code>BUTTON</code> windows created before calling <code>SetClassLong</code> will not be subclassed. You may want to consider using <code>SetWindowLong</code> instead, to subclass individual windows rather than the entire class. </p> <p>Edit: The group box's original window procedure doesn't send <code>WM_COMMAND</code> messages to its parent. This is explained in Charles Petzold's <a href="http://www.charlespetzold.com/pw5/" rel="nofollow noreferrer">Programming Windows</a> book:</p> <blockquote> <p>The group box, which has the <code>BS_GROUPBOX</code> style, is an oddity in the button class. It neither processes mouse or keyboard input, nor sends <code>WM_COMMAND</code> messages to its parent.</p> </blockquote> <p>You should find that button notifications don't get through to <code>window</code> even if you don't subclass the group box.</p> <p>I hope this helps!</p>
<p>I suspect if you remove the subclass all together the button events will still not reach the original window procedure as you expect.</p> <p>Since you have an subclass procedure doing nothing more than calling <strong>CallWindowProc</strong> the window is effectively not subclasses.</p> <p>My suggestion would be to use the <strong>Spy++</strong> tool to see which window is getting the button event messages.</p> <p>One of the more difficult aspects of Win32 programming is determining which window gets which message and <strong>Spy++</strong> is invaluable when it comes to figuring out this information.</p>
27,606
<p>The Emacs cperl-mode seems to get confused less than perl-mode, but the Skittles effect makes the thing unusable for me. Does anyone have or know of an example of a .emacs block that causes cperl-mode to use the colorization from perl-mode, ideally in a form readable enough that I can go back and turn back on the default colors one element at a time until I reach something I'm comfortable with?</p> <p>In particular there is a hideously shade of light green used for some builtins that I find quite unreadable, and I prefer my variables to not have the leading <code>$</code> and <code>$$</code> and such tinted red along with the variable name. Most of the rest are merely distracting.</p>
<p>Press M-x customize-group RET cperl-faces RET and change coloring to your liking.</p>
<p>You can change the <a href="http://www.emacswiki.org/emacs/ColorTheme" rel="nofollow noreferrer">color theme</a> if you don't like the particular default colors.</p>
34,040
<p>I have a large set of files, some of which contain special characters in the filename (e.g. ä,ö,%, and others). I'd like a script file to iterate over these files and rename them removing the special characters. I don't really mind what it does, but it could replace them with underscores for example e.g.</p> <p>Störung%20.doc would be renamed to St_rung_20.doc</p> <p>In order of preference:</p> <ol> <li>A Windiws batch file</li> <li>A Windows script file to run with cscript (vbs)</li> <li>A third party piece of software that can be run from the command-line (i.e. no user interaction required)</li> <li>Another language script file, for which I'd have to install an additional script engine</li> </ol> <p>Background: I'm trying to encrypt these file with GnuPG on Windows but it doesn't seem to handle special characters in filenames with the --encrypt-files option.</p>
<p>Have you tried setting cmd.exe into another codepage before you feed the file names to gnupg? Issue <code>chcp 65001</code> to set cmd.exe to Unicode beforehand and try again.</p> <p>If that fails, the following VBScript would do it:</p> <pre class="lang-vb prettyprint-override"><code>Option Explicit Dim fso: Set fso = CreateObject("Scripting.FileSystemObject") Dim invalidChars: Set invalidChars = New RegExp ' put all characters that you want to strip inside the brackets invalidChars.Pattern = "[äöüß&amp;%]" invalidChars.IgnoreCase = True invalidChars.Global = True If WScript.Arguments.Unnamed.Count = 0 Then WScript.Echo "Please give folder name as argument 1." WScript.Quit 1 End If Recurse fso.GetFolder(WScript.Arguments.Unnamed(0)) Sub Recurse(f) Dim item For Each item In f.SubFolders Recurse item Sanitize item Next For Each item In f.Files Sanitize item Next End Sub Sub Sanitize(folderOrFile) Dim newName: newName = invalidChars.Replace(folderOrFile.Name, "_") If folderOrFile.Name = newName Then Exit Sub WScript.Echo folderOrFile.Name, " -&gt; ", newName folderOrFile.Name = newName End Sub </code></pre> <p>call it like this:</p> <pre><code>cscript replace.vbs "c:\path\to\my\files" </code></pre> <p>You can also drag&amp;drop a folder onto it in Windows Explorer.</p>
<p>I'm using this batch to rename folders and seems to work fine so far... In my case codepage is 1252, yours might be different.</p> <pre><code>mode con codepage select=1252 @echo off Setlocal enabledelayedexpansion ::folder only (/D option) for /R /D %%d in (*) do ( set an=%%~nd set bn=!an:.=_! set cn=!bn:-=_! set dn=!cn: =_! set en=!dn:Á=A! set fn=!en:É=E! set gn=!fn:Í=I! set hn=!gn:Ó=O! set in=!hn:Ú=U! set jn=!in:Ü=U! set kn=!jn:á=a! set ln=!kn:é=e! set mn=!ln:í=i! set nn=!mn:ó=o! set on=!nn:ú=u! set pn=!on:ü=u! set qn=!pn:Ñ=N! set zn=!on:ñ=n! set ax=%%~xd set bx=!ax:.=_! set cx=!bx:-=_! set dx=!cx: =_! set bx=!ax:.=_! set cx=!bx:-=_! set dx=!cx: =_! set ex=!dx:Á=A! set fx=!ex:É=E! set gx=!fx:Í=I! set hx=!gx:Ó=O! set ix=!hx:Ú=U! set jx=!ix:Ü=U! set kx=!jx:á=a! set lx=!kx:é=e! set mx=!lx:í=i! set nx=!mx:ó=o! set ox=!nx:ú=u! set px=!ox:ü=u! set qx=!px:Ñ=N! set zx=!ox:ñ=n! if [!an!]==[] (set zn=) if [!ax!]==[] (set zx=) set newname=!zn!!zx! if /i not [%%~nd%%~xd]==[!newname!] rename "%%d" !newname! ) endlocal pause </code></pre>
32,698
<p>Has anyone here given the <a href="http://www.fandev.org" rel="nofollow noreferrer">Fantom programming language</a> a whirl? (pun intended).</p> <p>My first impression:</p> <ul> <li>I like the ability to have the code run on either the .NET or Java VM.</li> <li>The syntax is nice and clean and does not try anything fancy.</li> <li>I have a belief that "the library is the language" and the developers of Fan <a href="http://fandev.org/doc/docIntro/WhyFan.html" rel="nofollow noreferrer">believe that their USP is their APIs</a>:</li> </ul> <blockquote> <p>But getting a language to run on both Java and .NET is the easy part - in fact there are many solutions to this problem. The hard part is getting portable APIs. Fan provides a set of APIs which abstract away the Java and .NET APIs. We actually consider this one of Fan's primary benefits, because it gives us a chance to develop a suite of system APIs that are elegant and easy to use compared to the Java and .NET counter parts.</p> </blockquote> <p>Any other thoughts, first impressions, pros and cons?</p>
<p>It looks very inspired by Ruby. It says that it's RESTful but I don't see how exactly. Compare with <a href="http://en.wikipedia.org/wiki/Boo_(programming_language)" rel="nofollow noreferrer">boo</a>, which is more mature yet similar in many ways (its syntax is Python inspired, though).</p> <p>The design decisions to keep generics and namespaces very limited are questionable.</p>
<p>This is very interesting.</p> <p>Java (or C#) was created in order to eliminate Platform dependency by creating a JVM (or CLR) that will compile the code into a specific machine code at run time.</p> <p>Now , There is a languege which is <strong>Virtual Machine independent</strong>? umm .... what the hell?!?!</p> <p>Again , this is a very interesting topic , That might be the future...:) going to one universal single languege</p>
16,162
<p>I got ahead of myself and downloaded and installed the OSX Python 2.6 package from www.python.org/download/ on my OSX 10.5.5 Intel Mac and installed the full package contents. Only after this did I come across <a href="http://wiki.python.org/moin/MacPython/Leopard" rel="nofollow noreferrer">http://wiki.python.org/moin/MacPython/Leopard</a> stating that you should do a partial install of the package to avoid interfering with the system install.</p> <p>I'm afraid I've already overwritten the system framework through that installer and I remember reading somewhere after discovering this that I'd lose certain elements included in the OSX system install and not Python distributions.</p> <p>Is there any way to reverse this or restore anything I may have lost? What exactly have I lost and is it going to be a problem? </p>
<p>You may have overwritten the system framework but it is more likely that you just overwrote the symlinks in <code>/usr/bin</code> to point to the new version. Try going to <code>/usr/bin</code> and seeing (with something like <code>ls -alsh</code>) where the <code>python</code> symlink points to. It may be <code>python2.6</code> or <code>3.0</code>, which is in turn a ln to <code>/System/Library/Frameworks/Python.framework/Versions ...</code> etc. First try resetting the python symlink to the stable or expected version, ie, <code>sudo ln -s /usr/bin/python2.5 python</code> (from the <code>/usr/bin</code> dir.)</p>
<p>Restore from a recent Time Machine backup or somehow from DVD?</p>
40,156
<p>Is there a way to create a Zip archive that contains multiple files, when the files are currently in memory? The files I want to save are really just text only and are stored in a string class in my application. But I would like to save multiple files in a single self-contained archive. They can all be in the root of the archive.</p> <p>It would be nice to be able to do this using SharpZipLib.</p>
<p>Use <code>ZipEntry</code> and <code>PutNextEntry()</code> for this. The following shows how to do it for a file, but for an in-memory object just use a MemoryStream</p> <pre><code>FileStream fZip = File.Create(compressedOutputFile); ZipOutputStream zipOStream = new ZipOutputStream(fZip); foreach (FileInfo fi in allfiles) { ZipEntry entry = new ZipEntry((fi.Name)); zipOStream.PutNextEntry(entry); FileStream fs = File.OpenRead(fi.FullName); try { byte[] transferBuffer[1024]; do { bytesRead = fs.Read(transferBuffer, 0, transferBuffer.Length); zipOStream.Write(transferBuffer, 0, bytesRead); } while (bytesRead &gt; 0); } finally { fs.Close(); } } zipOStream.Finish(); zipOStream.Close(); </code></pre>
<p>Use a <a href="http://msdn.microsoft.com/en-us/library/system.io.stringreader.aspx" rel="nofollow noreferrer">StringReader</a> to read from your string objects and expose them as Stream s.</p> <p>That should make it easy to feed them to your zip-building code.</p>
34,841
<p>Given a handle of type <code>HWND</code> is it possible to confirm that the handle represents a real window?</p>
<p>There is a function <code>IsWindow</code> which does exactly what you asked for.</p> <pre><code>BOOL isRealHandle = IsWindow(unknwodnHandle); </code></pre> <p>Look at <a href="http://msdn.microsoft.com/en-us/library/ms633528(VS.85).aspx" rel="nofollow noreferrer">this link</a> for more information.</p>
<p>Generally no. By the time you've got confirmation that a Window is valid another process/thread my come along and remove it for you.</p>
3,105
<p>In XAML I can declare a DataTemplate so that the template is used whenever a specific type is displayed. For example, this DataTemplate will use a TextBlock to display the name of a customer:</p> <pre><code>&lt;DataTemplate DataType="{x:Type my:Customer}"&gt; &lt;TextBlock Text="{Binding Name}" /&gt; &lt;/DataTemplate&gt; </code></pre> <p>I'm wondering if it's possible to define a DataTemplate that will be used any time an IList&lt;Customer&gt; is displayed. So if a ContentControl's Content is, say, an ObservableCollection&lt;Customer&gt; it would use that template.</p> <p>Is it possible to declare a generic type like IList in XAML using the {x:Type} Markup Extension?</p>
<p>Not out of the box, no; but there are enterprising developers out there who have done so.</p> <p>Mike Hillberg at Microsoft played with it in <a href="https://learn.microsoft.com/en-us/archive/blogs/mikehillberg/limited-generics-support-in-xaml" rel="nofollow noreferrer">this post</a>, for example. Google has others of course.</p>
<p>Quite defeats the purpose of a generic, but you could define a class that derives from the generic like so, with the sole purpose of being able to use that type in XAML.</p> <pre><code>public class MyType : List&lt;int&gt; { } </code></pre> <p>And use it in xaml e.g. like</p> <pre><code>&lt;DataTemplate DataType={x:Type myNamespace:MyType}&gt; </code></pre>
22,413
<p>When I adjust the probe offset to get the proper layer height and adhesion, one side is set right but the other doesn't work. If I decrease the probe offset (say -1.100 to -1.050) the right side seems to print better; if I increase the probe offset (-1.050 to -1.125) the left side will adhere to the plate properly.</p> <p>Before I added the BLTouch and upgraded the firmware to Marlin 1.1.9 I was able to print a perimeter square (with a little manual adjustment).</p> <p>My Printer is the Ender 3 and I am using a <a href="https://www.amazon.co.uk/Comgrow-Glass-Creality-Printer-Ender-3/dp/B07DSC9TJQ" rel="nofollow noreferrer">glass bed</a> and the model is this <a href="https://www.thingiverse.com/thing:2280529/" rel="nofollow noreferrer">centre crosshair</a></p> <p><a href="https://i.stack.imgur.com/xVVfi.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xVVfi.jpg" alt="enter image description here"></a> <a href="https://i.stack.imgur.com/pBFny.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pBFny.jpg" alt="enter image description here"></a> <a href="https://i.stack.imgur.com/Y0usO.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Y0usO.jpg" alt="enter image description here"></a> <a href="https://i.stack.imgur.com/JECOP.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JECOP.jpg" alt="enter image description here"></a></p>
<p>I have had exactly the same experiences as you did with a inductive sensor on a Prusa i3 clone. It looks as though the bed leveling is not executed, or the level/mesh tilted. Please do note that automatic bed leveling is <strong><em>not magic</em></strong>, you still need to provide a <strong><em>build platform as level (and flat) as possible</em></strong>. A slate of glass is a good build platform surface as the glass production process ensures that the glass is very flat and easy to level.</p> <p>What I did to solve the problem is that I re-leveled the bed and send the <a href="https://reprap.org/wiki/G-code#M420:_Leveling_On.2FOff.2FFade_.28Marlin.29" rel="nofollow noreferrer"><code>M420 S1</code></a> command over USB to the printer to enable bed leveling as I was under the impression that it did not use the grid obtained with <code>G29</code>.</p> <p>On my CoreXY I also use a touch sensor (3DTouch, which is a BLTouch clone) like you do, even with that sensor I sometimes see that the automatic level is uneven (one side of the skirt has very thin/see through deposition, while the other side appears normal), this is most probably caused by the sensor accuracy (or an obstruction under the probe needle). There is a way to increase the probing accuracy by using double probing where the second probe is advancing slower to the build platform as can be seen in the Marlin Configuration.h file:</p> <pre><code>// Feedrate (mm/m) for the first approach when double-probing (MULTIPLE_PROBING == 2) #define Z_PROBE_SPEED_FAST HOMING_FEEDRATE_Z // Feedrate (mm/m) for the "accurate" probe of each point #define Z_PROBE_SPEED_SLOW (Z_PROBE_SPEED_FAST / 2) </code></pre> <p>For double probing you require to set:</p> <pre><code>// The number of probes to perform at each point. // Set to 2 for a fast/slow probe, using the second probe result. // Set to 3 or more for slow probes, averaging the results. #define MULTIPLE_PROBING 2 </code></pre> <hr> <p><em>Side note:<br> From an earlier posting it appears that you are using the <code>#define Z_PROBE_OFFSET_FROM_EXTRUDER</code> in the configuration file to set the offset. It is much more convenient to set that through the <a href="http://marlinfw.org/docs/features/lcd_menu.html" rel="nofollow noreferrer">LCD menu</a> (<code>Bed Leveling</code> -> <code>Z Probe Offset: -–-</code>) or send the <code>M851 Zx.xx</code> directly over USB or load through a .gcode file from SD card to prevent numerous flashing the firmware with alternative parameters. Make sure that you enable:</em></p> <pre><code>#define EEPROM_SETTINGS // Enable for M500 and M501 commands </code></pre> <p><em>in the Configuration.h file and execute <code>M500</code> to store the new setting set by <code>M851</code>.</em></p>
<p>From the looks of your test print, this is unlikely all or only due to levelling unless the glass plate is abnormally uneven. You may have to check your extrusion (speed, temp, feed) parameters and/or adhesion (clean with aceton and/or prepare with hairspray or glue stck)</p>
1,088
<p>I want to put "random" output from my result set (about 1.5 mil rows) in a file in a sorted manner. I know i can use sort by command in my query but that command is "expensive". Can you tell me is there any algorithm for writing result set rows in a file so the content would be sorted in the end and can i gain in performance with this? I'm using java 1.6, and query has multiple joins.</p>
<p>Define an index for the sort criteria in your table, then you can use the order by clause without problems and write the file as it comes from the resultset.</p> <p>If your query has multiple joins, create the proper indexes for the joins and for the sort criteria. You can sort the data on your program but you'd be wasting time. That time will be a lot more valuable when employed learning how to properly tune/use your database rather than reinventing sorting algorithms already present in the database engine.</p> <p>Grab your database's profiler and check the query's execution plan.</p>
<p>If you're reading from a database, getting sorted output shouldn't be so 'expensive' if you have appropriate indexes.</p> <p>But, sometimes with complex queries it's very hard for the SQL optimiser to apply indexes. In that case, the DB simply accumulates the results in a temporary table and sorts it for you, transparently.</p> <p>It's very unlikely that you could match the level of optimisations put into your DB engine; but if your problem arises because you're doing some postprocessing of the data that negates any sorting done by the DB, then you have no alternative other than sorting it yourself.</p> <p>Again, the easiest would be to use the DB: simply write to a temporary table with an appropriate index and dump from there.</p> <p>If you're certain that the data will always fit in RAM, you can sort it in memory. It's the only case in which you <em>might</em> be able to beat the DB engine, just because you know you won't need HD access.</p> <p>But that's a lot of 'ifs'. Better stay with your DB</p>
21,993
<p>Is there a good way to debug errors in the Visual Studio Designer?</p> <p>In our project we have tons of UserControls and many complex forms. For the complex ones, the Designer often throws various exceptions which doesn't help much, and I was wondering if there's some nice way to figure out what has gone wrong.</p> <p>The language is C#, and we're using Visual Studio 2005.</p>
<p>I've been able to debug some control designer issues by running a second instance of VS, then from your first VS instance do a "Debug -> Attach to Process" and pick "devenv".</p> <p>The first VS instance is where you'll set your breakpoints. Use the second instance to load up the designer to cause the "designer" code to run.</p>
<p>Each one is different and they can sometimes be obscure. As a first step, I would do the following: </p> <ul> <li>Use source control and save often. When a designer error occurs, get a list of all changes to the affected controls that have occurred recently and test each one until you find the culprit</li> <li>Be sure to check out the initialization routines of the controls involved. Very often these errors will occur because of some error or bad dependency that is called through the default constructor for a control (an error that may only manifest itself in VS)</li> </ul>
6,074
<p>I'm trying to implement Drag &amp; Drop functionality with source being a TreeView control. When I initiate a drag on a node, I'm getting:</p> <p><em>Invalid FORMATETC structure (Exception from HRESULT: 0x80040064 (DV_E_FORMATETC))</em></p> <p>The ItemDrag handler (where the exception takes place), looks like:</p> <pre><code>private void treeView_ItemDrag(object sender, System.Windows.Forms.ItemDragEventArgs e) { this.DoDragDrop(e.Item, DragDropEffects.Move); } </code></pre> <p>Does anyone know the root cause of this and how to remedy it? (.NET 2.0, Windows XP SP2)</p>
<p>In case it helps anyone else - I encountered this problem with the WPF TreeView (not Windows Forms as listed in the question) and the solution was simply to make sure to mark the event as handled in the drop event handler.</p> <pre><code> private void OnDrop(object sender, DragEventArgs e) { // Other logic... e.Handled = true; } </code></pre>
<p><strong><code>FORMATETC</code></strong> is a type of application clipboard, for lack of a better term. In order to pull off some of the visual tricks of draging around the tree node, it has to be copied into this clipboard with its source description. The source control loads its info into the <code>FORMATETC</code> clipboard and sends it to the target object. It looks like the error occurs on the drop and not on the drag. The <code>DV</code> in <code>DV_E_FORMATETC</code> typically indicates the error occurrs on the drop step.<br> The destination doesn't look like it likes what you are droping on it. The clipboard may be corrupt or the drop destination may not be configured to understand it. </p> <p>I recommend you try one of two things. </p> <ol> <li>Remove the original tree structure and destination. Dump your dlls. Close everything. Open up and put the treeview and destination back on the form. It may have just been poorly formed and not fully populating the <code>FORMATETC</code> structure.</li> <li>Try putting another treeview and droping to that. If you are droping to another tree and it works you know your oranges to oranges work and it isn't the treeview. It may be the destination if it is a grid or listview. You may need to change those structures to be able to receive the drop.</li> </ol> <p>Not that it helps but the structure is something like this: </p> <pre><code>typedef struct tagFORMATETC { CLIPFORMAT cfFormat; DVTARGETDEVICE *ptd; DWORD dwAspect; LONG lindex; DWORD tymed; } FORMATETC, *LPFORMATETC; </code></pre>
7,310
<p>Is there another way to render graphics in C# beyond <a href="https://en.wikipedia.org/wiki/Graphics_Device_Interface#Windows_XP" rel="nofollow noreferrer">GDI+</a> and <a href="http://en.wikipedia.org/wiki/Microsoft_XNA" rel="nofollow noreferrer">XNA</a>? </p> <p>(For the development of a tile map editor.)</p>
<p><a href="http://cs-sdl.sourceforge.net/" rel="nofollow noreferrer">SDL.NET</a> is the solution I've come to love. If you need 3D on top of it, you can use Tao.OpenGL to render inside it. It's fast, industry standard (<a href="http://en.wikipedia.org/wiki/Simple_DirectMedia_Layer" rel="nofollow noreferrer">SDL</a>, that is), and cross-platform.</p>
<p>You could try looking into WPF, using Visual Studio and/or Expression Blend. I'm not sure how sophisticated you're trying to get, but it should be able to handle a simple editor. Check out this <a href="http://msdn.microsoft.com/en-us/library/ms742562.aspx" rel="nofollow noreferrer">MSDN Article</a> for more info.</p>
8,261
<p>So what's the best way to create new tables in a Sqlite database in Rails 2. I have created the database using rake db:migrate command. So should I write individual sql scripts to create a database or use rake somehow. I don't need scaffolding.</p>
<p>Basically use migrations.</p> <p>Some useful help on how to use migrations is available at <a href="http://wiki.rubyonrails.org/rails/pages/understandingmigrations" rel="nofollow noreferrer">http://wiki.rubyonrails.org/rails/pages/understandingmigrations</a> and <a href="http://wiki.rubyonrails.org/rails/pages/UsingMigrations" rel="nofollow noreferrer">http://wiki.rubyonrails.org/rails/pages/UsingMigrations</a>. A good cheatsheet that I use is also available at <a href="http://dizzy.co.uk/ruby_on_rails/cheatsheets/rails-migrations" rel="nofollow noreferrer">http://dizzy.co.uk/ruby_on_rails/cheatsheets/rails-migrations</a>.</p> <p>Basically migrations use ruby code to create your database tables for you. It is far easier (in my opinion at least) to use nice ruby code to do this rather than SQL DDL - it also does various things automatically for you (like adding <code>id</code> fields to all your tables as rails requires). You can then use rake tasks to actually apply the migrations to your database. The other major advantage that migrations give you is that they are reverseable - so your database is versioned and you can easily jump from one version to another.</p>
<p>If you are not using scaffolding then you should use <code>script/generate migration</code> to create a migration file for each table. There is no need to use sql scripts. After creating some migrations you can apply them to your database using rake db:migrate.</p>
24,410
<p>I cannot correctly position the div <code>form</code> in my layout.</p> <p>By looking at my div placement and css below, does anyone have an idea what I could be doing wrong?</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>#floorplans { float: left; height: 165px; width: 203px; border-right: 1px solid #FFFFFF; border-bottom: 1px solid #FFFFFF; position: relative; background: #FFFFFF url(https://lorempixel.com/320/170/) no-repeat; padding-top: 14px; padding-left: 20px; display: block; color: #000000; line-height: 1.5em; padding-right: 10px; } #development { float: left; height: 165px; width: 204px; border-right: 1px solid #FFFFFF; border-bottom: 1px solid #FFFFFF; position: relative; background: #FFFFFF url(https://lorempixel.com/204/165/) no-repeat; padding-top: 14px; padding-left: 20px; display: block; color: #000000; line-height: 1.5em; padding-right: 10px; } #projects { background: #FFFFFF url(https://lorempixel.com/153/127/) no-repeat; height: 127px; width: 153px; text-align: left; padding-left: 300px; color: #333333; padding-top: 25px; display: block; float: left; position: relative; line-height: 1.5em; font-size: 10px; padding-right: 15px; clear: left; } #form { background: #990000 url(https://lorempixel.com/450/309/) no-repeat; float: left; height: 309px; width: 450px; position: relative; padding-top: 20px; padding-left: 30px; padding-right: 30px; color: #FFFFFF; }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div id="wrapper"&gt; &lt;div id="logo"&gt;&lt;/div&gt; &lt;div id="topnav"&gt;&lt;/div&gt; &lt;div id="nav"&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="#"&gt;link&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;link2&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;link3&lt;/a&gt;&lt;/li&gt; &lt;li id="last"&gt;&lt;a href="#"&gt;link4&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;div id="gallery"&gt;&lt;/div&gt; &lt;div id="floorplans"&gt;&lt;/div&gt; &lt;div id="development"&gt;&lt;/div&gt; &lt;div id="projects"&gt;&lt;/div&gt; &lt;div id="form"&gt; &lt;div&gt; &lt;/div&gt; &lt;div id="footer"&gt;&lt;/div&gt; &lt;/div&gt;</code></pre> </div> </div> </p> <p>You'll notice the div <code>form</code> is dropping down. What should I do to get things to line up? Should I rework the placement of the divs?</p>
<p>The form <code>div</code>'s top is in line with the top of the <code>div</code> that precedes it. The <code>clear:left;</code> on <code>#projects</code> moves <code>#projects</code> to the next line (good), along with the following content (bad). Try a negative top margin, or consider restructuring your HTML to put <code>#form</code> before <code>#projects</code>.</p> <p>Adding the following should work:</p> <pre><code>#form { margin-top:-180px; } #projects { border-right: 1px solid #FFFFFF; } </code></pre>
<p>Because you have two blocks (FLOORPLANS and DEVELOPMENT INFO) each with a border, they're now too wide to sit next to the form block. Test this by removing one or both borders and seeing if the form then pops back up there.</p> <p>Note, negative margin often has issues in IE6, be sure and check any solution against that.</p>
27,518
<p>Say I have three files (template_*.txt):</p> <ul> <li>template_x.txt</li> <li>template_y.txt</li> <li>template_z.txt</li> </ul> <p>I want to copy them to three new files (foo_*.txt). </p> <ul> <li>foo_x.txt </li> <li>foo_y.txt </li> <li>foo_z.txt</li> </ul> <p>Is there some simple way to do that with one command, e.g. </p> <p><code>cp --enableAwesomeness template_*.txt foo_*.txt</code></p>
<pre> for f in template_*.txt; do cp $f foo_${f#template_}; done </pre>
<p>Yet another way to do it:</p> <pre><code>$ ls template_*.txt | sed -e 's/^template\(.*\)$/cp template\1 foo\1/' | ksh -sx </code></pre> <p>I've always been impressed with the ImageMagick <a href="http://www.imagemagick.org/script/convert.php" rel="nofollow noreferrer">convert</a> program that does what you expect with image formats:</p> <pre><code>$ convert rose.jpg rose.png </code></pre> <p>It has a sister program that allows batch conversions:</p> <pre><code>$ mogrify -format png *.jpg </code></pre> <p>Obviously these are limited to image conversions, but they have interesting command line interfaces.</p>
4,598
<p>We @ <a href="http://www.medicware.com.br" rel="nofollow noreferrer">medicware.com.br</a> are thinking about making our <strong>web application offline-capable</strong> with <a href="http://gears.google.com/" rel="nofollow noreferrer">Gears</a>. Our main goal is to <strong>keep basic functionality running</strong> when the internet <strong>connection goes down</strong>.</p> <p>So, I'd like to hear <strong>success stories</strong>, <strong>tips</strong> and <strong>resources</strong> about yours real experiences in that field (related to <a href="http://gears.google.com/" rel="nofollow noreferrer">Gears</a> or not).</p>
<p><a href="http://www.rememberthemilk.com" rel="nofollow noreferrer">Remember the Milk</a> has done a nice job of using Gears -- you might see what you can find out about their implementation. I'd start at <a href="http://code.google.com/apis/gears/articles/take_app_offline.html" rel="nofollow noreferrer">http://code.google.com/apis/gears/articles/take_app_offline.html</a>.</p>
<p>I've had good experiences with Adobe Air. It's not gears and it was nothing more than a look to see how it worked, but it was so simple that i'd think it would be easy to port any large scale application over. </p>
22,982