instruction
stringlengths
21
27.8k
chosen
stringlengths
18
28.2k
rejected
stringlengths
18
33.6k
__index_level_0__
int64
0
50k
<p>Is it possible to call a constructor from another (within the same class, not from a subclass)? If yes how? And what could be the best way to call another constructor (if there are several ways to do it)?</p>
<p>Yes, it is possible:</p> <pre><code>public class Foo { private int x; public Foo() { this(1); } public Foo(int x) { this.x = x; } } </code></pre> <p>To chain to a particular superclass constructor instead of one in the same class, use <code>super</code> instead of <code>this</code>. Note that <strong>you can only chain to one constructor</strong>, and <strong>it has to be the first statement in your constructor body</strong>.</p> <p>See also <a href="https://stackoverflow.com/questions/284896">this related question</a>, which is about C# but where the same principles apply.</p>
<p>Originally from an anser by Mirko Klemm, slightly modified to address the question:</p> <p>Just for completeness: There is also the <a href="https://stackoverflow.com/questions/3987428/what-is-an-initialization-block">Instance initialization block</a> that gets executed always and before any other constructor is called. It consists simply of a block of statements "{ ... }" somewhere in the body of your class definition. You can even have more than one. You can't call them, but they're like "shared constructor" code if you want to reuse some code across constructors, similar to calling methods.</p> <p>So in your case</p> <pre><code>{ System.out.println("this is shared constructor code executed before the constructor"); field1 = 3; } </code></pre> <p>There is also a "static" version of this to initialize static members: "static { ... }"</p>
36,198
<p>A simple problem: If i use escape characters for a property such as</p> <pre><code>&lt;mx:Image id="img" toolTip="\\foo{\\bar}" </code></pre> <p>It wont validate toolTip and therefore not compile.</p> <p>What is the solution ?</p>
<p>You can use ActionScipt for example in a creationComplete event handler and assign you tooltip and you won't have the same constraints as in MXML.</p> <p>But you also can avoid these constraints in MXML by using CDATA:</p> <pre><code>&lt;mx:Image id="img" source="foo.jpg" width="50" height="50"&gt; &lt;mx:toolTip&gt; &lt;![CDATA[\foo{\bar} or any usually forbidden characters as &lt;, &gt;, &amp;, "'"...]]&gt; &lt;/mx:toolTip&gt;&lt;/mx:Image&gt; </code></pre>
<p>You can use HTML format for special chars.<code>&lt;mx:Image id="img" toolTip="&amp;#092;foo&amp;#123;&amp;#092;bar&amp;#125;"/&gt;</code></p>
42,497
<p>So I'm trying to get rid of my std::vector's by using boost::ptr_vector. Now I'm trying to remove an element from one, and have the removed element deleted as well. The most obvious thing to me was to do:</p> <pre><code>class A { int m; }; boost::ptr_vector&lt;A&gt; vec; A* a = new A; vec.push_back(a); vec.erase(a); </code></pre> <p>But this won't even compile (see below for the full error message). I've tried the erase/remove idiom like I would on a std::vector but all the algorithms of boost::ptr_vector turn out to be slightly different from those in std::vector.</p> <p>So my questions:</p> <ul> <li>How do I remove a pointer from a ptr_vector?</li> <li>Do I still need to manually delete() that element that I removed?</li> </ul> <p>Compiler error:</p> <pre><code>1&gt;------ Build started: Project: ptr_vector_test, Configuration: Debug Win32 ------ 1&gt;Compiling... 1&gt;ptr_vector_test.cpp 1&gt;c:\users\rvanhout\svn\trunk\thirdparty\boost\range\const_iterator.hpp(37) : error C2825: 'C': must be a class or namespace when followed by '::' 1&gt; c:\users\rvanhout\svn\trunk\thirdparty\boost\mpl\eval_if.hpp(63) : see reference to class template instantiation 'boost::range_const_iterator&lt;C&gt;' being compiled 1&gt; with 1&gt; [ 1&gt; C=A * 1&gt; ] 1&gt; c:\users\rvanhout\svn\trunk\thirdparty\boost\range\iterator.hpp(63) : see reference to class template instantiation 'boost::mpl::eval_if_c&lt;C,F1,F2&gt;' being compiled 1&gt; with 1&gt; [ 1&gt; C=true, 1&gt; F1=boost::range_const_iterator&lt;A *&gt;, 1&gt; F2=boost::range_mutable_iterator&lt;A *const &gt; 1&gt; ] 1&gt; c:\users\rvanhout\svn\trunk\thirdparty\boost\ptr_container\detail\reversible_ptr_container.hpp(506) : see reference to class template instantiation 'boost::range_iterator&lt;C&gt;' being compiled 1&gt; with 1&gt; [ 1&gt; C=A *const 1&gt; ] 1&gt; c:\tmp\ptr_vector_test\ptr_vector_test.cpp(21) : see reference to function template instantiation 'boost::void_ptr_iterator&lt;VoidIter,T&gt; boost::ptr_container_detail::reversible_ptr_container&lt;Config,CloneAllocator&gt;::erase&lt;A*&gt;(const Range &amp;)' being compiled 1&gt; with 1&gt; [ 1&gt; VoidIter=std::_Vector_iterator&lt;void *,std::allocator&lt;void *&gt;&gt;, 1&gt; T=A, 1&gt; Config=boost::ptr_container_detail::sequence_config&lt;A,std::vector&lt;void *,std::allocator&lt;void *&gt;&gt;&gt;, 1&gt; CloneAllocator=boost::heap_clone_allocator, 1&gt; Range=A * 1&gt; ] 1&gt;c:\users\rvanhout\svn\trunk\thirdparty\boost\range\const_iterator.hpp(37) : error C2039: 'const_iterator' : is not a member of '`global namespace'' 1&gt;c:\users\rvanhout\svn\trunk\thirdparty\boost\range\const_iterator.hpp(37) : error C2146: syntax error : missing ';' before identifier 'type' 1&gt;c:\users\rvanhout\svn\trunk\thirdparty\boost\range\const_iterator.hpp(37) : error C2208: 'boost::type' : no members defined using this type 1&gt;c:\users\rvanhout\svn\trunk\thirdparty\boost\range\const_iterator.hpp(37) : fatal error C1903: unable to recover from previous error(s); stopping compilation 1&gt;Build log was saved at "file://c:\tmp\ptr_vector_test\Debug\BuildLog.htm" 1&gt;ptr_vector_test - 5 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== </code></pre>
<p>Well you can do that with a std::vector either.</p> <p>In both cases erase takes an iterator as a parameter.<br> So before you can erase something from a vector (or a ptr_vector) you need to locate it.</p> <p>Also note that the ptr_vector treats its content as if you have stored an object not a pointer. So any searching is done via the object.</p> <p>So basically</p> <pre><code> std::vector&lt;A&gt; x; std::ptr_vector&lt;A&gt; y; // These two object should behave in exactly the same way. // The ONLY difference is inserting values which for y are pointers. // Y take ownership of the pointer and all subsequent acesses to the // members of y look like they are objects </code></pre> <p>Example:</p> <pre><code>#include &lt;boost/ptr_container/ptr_vector.hpp&gt; #include &lt;vector&gt; class A { int m; public: A(int x):m(x) {} bool operator==(A const&amp; rhs) {return m = rhs.m;} }; int main() { boost::ptr_vector&lt;A&gt; x; x.push_back(new A(1)); x.erase(std::find(x.begin(),x.end(),A(1))); std::vector&lt;A&gt; y; y.push_back(A(2)); y.erase(std::find(y.begin(),y.end(),A(2))); // To find an exact pointer don't modify the equality. // Use find_if and pass a predicate that tests for a pointer A* a = new A(3); boost:ptr_Vector&lt;A&gt; z; z.push_back(a); z.erase(std::find_if(y.begin(),y.end(),CheckPointerValue(a)); } struct CheckPointerValue { CheckPointerValue(A* a):anA(a) {} bool operator()(A const&amp; x) { return &amp;X == anA;} private: A* anA; }; </code></pre>
<p>You need to use the member erase_if method with a suitable predicate. There's no need to delete the pointer, the container has ownership.</p> <pre><code>struct delete_a { bool operator()(boost::ptr_vector&lt;A&gt;::value_type inA) { return inA == a; } } vec.erase_if(delete_a()); </code></pre> <p>(note this is just an example chosen for simplicity, for such situation in real code I suppose one would write a suitable bind/equal_to combo, or use lambda)</p> <p>Or, as an alternative, call release on the correct iterator, if you still want to use the object.</p>
46,418
<p>Let's say I click a button on a web page to initiate a submit request. Then I suddenly realize that some data I have provided is wrong and that if it gets submitted, then I will face unwanted consequences (something like a shopping request where I may be forced to pay up for this incorrect request).</p> <p>So I frantically click the Stop button not just once but many times (just in case).</p> <p>What happens in such a scenario? Does the browser just cancel the request without informing the server? If in case it does inform the server, does the server just kill the process or does it also do some rolling back of all actions done as part of this request?</p> <p>I code in Java. Does Java have any special feature that we can use to detect STOP requests and rollback whatever we did as part of this transaction?</p>
<p>A Web Page load from a browser is usually a 4 step process (not considering redirections):</p> <ol> <li>Browser sends HTTP Request, when the Server is available</li> <li>Server executes code (for dynamic pages)</li> <li>Server sends the HTTP Response (usually HTML)</li> <li>Browser renders HTML, and asks for other files (images, css, ...)</li> </ol> <p>The browser reaction to "Stop" depends on the step your request is at that time:</p> <ul> <li>If your server is slow or overloaded, and you hit "Stop" during step 1, nothing happens. The browser doesn't send the request.</li> <li>Most of the times, however, "Stop" will be hit on steps 2, 3 and 4, and in those steps your code is already executed, the browser simply stops waiting for the response (2), or receiving the response (3), or rendering the response (4).</li> </ul> <p>The HTTP call itself is always a 2 steps action (Request/Response), and there is no automatic way to rollback the execution from the client</p>
<p>Your submit in important scenarios should have two stages. Verify and submit. If the final submit goes though, you commit any tranactions. I cant think of any other way really to avoid that situation, other than allowing your user to undo his actions after a commit. for example The order example, after the order is done to allow your customers to change their mind and canel the order if it has not been shipped yet. Of course its extra code you need to write to suuport that.</p>
16,711
<p>According to what I have found so far, I can use the following code:</p> <pre> LocalSessionFactoryBean sessionFactory = (LocalSessionFactoryBean)super.getApplicationContext().getBean("&sessionFactory"); System.out.println(sessionFactory.getConfiguration().buildSettings().getJdbcBatchSize()); </pre> <p>but then I get a Hibernate Exception:</p> <blockquote> <p>org.hibernate.HibernateException: No local DataSource found for configuration - dataSource property must be set on LocalSessionFactoryBean</p> </blockquote> <p>Can somebody shed some light?</p>
<p>Try the following (I can't test it since I don't use Spring):</p> <pre><code>System.out.println(sessionFactory.getConfiguration().getProperty("hibernate.jdbc.batch_size")) </code></pre>
<p>On the versions of Hibernate that I've checked, getConfiguration is not a public method of SessionFactory. In a few desperate cases, I've cast a Session or SessionFactory into its underlying implementation to get at some values that weren't publicly available. In this case that would be:</p> <pre><code>((SessionFactoryImplementor)sessionFactory).getSettings().getJdbcBatchSize() </code></pre> <p>Of course, that's dangerous because it could break if they change the implementation. I usually only do this for optimizations that I can live without and then wrap the whole thing in a try/catch Throwable block just to make sure it won't hurt anything if it fails. A better idea might be to set the value yourself when you initialize Hibernate so you already know what it is from the beginning.</p>
13,150
<p>I have some code that generates image of a pie chart. It's a general purpose class, so any number of slices can be given as input. Now I have problem picking good colors for the slices. Is there some algorithm that is good at that?</p> <p>Colors need to follow some rules:</p> <ul> <li>they need to look nice</li> <li>adjacent colors should not be similar (blue next to green is a no-go)</li> <li>pie background color is white, so white is out of option</li> </ul> <p>Some algorithm manipulating with RGB values would be a preferred solution.</p>
<p>I solved it as follows:</p> <ol> <li>Choose a <strong>base color</strong>.</li> <li>Calculate its <strong>hue</strong> (<code>baseHue</code>).</li> <li>Create a color with the same saturation and luminosity, with its hue calculated as:<pre> hue = baseHue + ((240 / pieces) * piece % 240 </pre></li> </ol> <p>In C#:</p> <pre><code>int n = 12; Color baseColor = System.Drawing.ColorTranslator.FromHtml("#8A56E2"); double baseHue = (new HSLColor(baseColor)).Hue; List&lt;Color&gt; colors = new List&lt;Color&gt;(); colors.Add(baseColor); double step = (240.0 / (double)n); for (int i = 1; i &lt; n; ++i) { HSLColor nextColor = new HSLColor(baseColor); nextColor.Hue = (baseHue + step * ((double)i)) % 240.0; colors.Add((Color)nextColor); } string colors = string.Join(",", colors.Select(e =&gt; e.Name.Substring(2)).ToArray()); </code></pre> <p>I used the <a href="http://richnewman.wordpress.com/hslcolor-class/" rel="noreferrer">HSLColor class</a>. </p> <p>The <a href="http://chart.apis.google.com/chart?chs=400x225&amp;cht=p&amp;chco=8a56e2,cf56e2,e256ae,e25668,e28956,e2cf56,aee256,68e256,56e289,56e2cf,56aee2,5668e2&amp;chd=t:10,10,10,10,10,10,10,10,10,10,10,10" rel="noreferrer">Google Charts example</a> that uses 12 pieces and a base color of #8A56E2:</p> <p><img src="https://i.stack.imgur.com/DWsLK.png" alt="Chart Example"></p>
<p>I found this pseudocode formula that might help. You could start with a set to seed it.</p> <p>Colour Difference Formula</p> <p>The following is the formula suggested by the W3C to determine the difference between two colours.</p> <p>(maximum (Red value 1, Red value 2) - minimum (Red value 1, Red value 2)) + (maximum (Green value 1, Green value 2) - minimum (Green value 1, Green value 2)) + (maximum (Blue value 1, Blue value 2) - minimum (Blue value 1, Blue value 2))</p> <p>The difference between the background colour and the foreground colour should be greater than 500. </p> <p><a href="http://juicystudio.com/services/colourcontrast.php" rel="nofollow noreferrer">Here is the source</a></p>
29,316
<p>I have an existing bare git repository located in /home/myaccount/git/project. I am currently using it over ssh from my local machine without any problems. I want to add a second user on the server which only shall access to this git repository (maybe move the repo outside my account folder?). How? Using latest version of git and ubuntu on slicehost.</p> <p>I have this setup: user: sleepyhead user: developer1 group: git. both sleepyhead and developer1 are members of this group repository /home/sleepyhead/git/project1</p> <p>I want to: move repository to a proper place, either /home/git/project1 or /usr/local/git/project1. What is recommended? developer1 should permissions to read and write project1 with git. no other permissions should be given.</p> <p>I do not know how to properly set the permissions and to restrict developer1 to only have access using git to project1.</p>
<p>Have him create a ssh keypair and send you the public key.</p> <p>Add the public key to your <code>~/.ssh/authorized_keys</code> file, and add the <code>command="..."</code> option to limit it to the git-shell - see <a href="http://kitenet.net/~joey/blog/entry/locking_down_ssh_authorized_keys/" rel="noreferrer">this link</a> for an example.</p>
<p>You will also probably want to have both of those users in the same user group, and to make sure you have group-write privileges on the repository.</p>
47,029
<p>This is what I currently have:</p> <pre><code>CREATE OR REPLACE TRIGGER MYTRIGGER AFTER INSERT ON SOMETABLE FOR EACH ROW DECLARE v_emplid varchar2(10); BEGIN SELECT personnum into v_emplid FROM PERSON WHERE PERSONID = :new.EMPLOYEEID; dbms_output.put(v_emplid); /* INSERT INTO SOMEOTHERTABLE USING v_emplid and some of the other values from the trigger table*/ END MYTRIGGER; </code></pre> <p>DBA_ERRORS has this error: PL/SQL: ORA-00923: FROM keyword not found where expected</p>
<p>1) There must be something else to your example because that sure seems to work for me</p> <pre><code>SQL&gt; create table someTable( employeeid number ); Table created. SQL&gt; create table person( personid number, personnum varchar2(10) ); Table created. SQL&gt; ed Wrote file afiedt.buf 1 CREATE OR REPLACE TRIGGER MYTRIGGER 2 AFTER INSERT ON SOMETABLE 3 FOR EACH ROW 4 DECLARE 5 v_emplid varchar2(10); 6 BEGIN 7 SELECT personnum 8 into v_emplid 9 FROM PERSON 10 WHERE PERSONID = :new.EMPLOYEEID; 11 dbms_output.put(v_emplid); 12 /* INSERT INTO SOMEOTHERTABLE USING v_emplid and some of the other values from the trigger table*/ 13* END MYTRIGGER; 14 / Trigger created. SQL&gt; insert into person values( 1, '123' ); 1 row created. SQL&gt; insert into sometable values( 1 ); 1 row created. </code></pre> <p>2) You probably want to declare V_EMPLID as being of type Person.PersonNum%TYPE so that you can be certain that the data type is correct and so that if the data type of the table changes you won't need to change your code.</p> <p>3) I assume that you know that your trigger cannot query or update the table on which the trigger is defined (so no queries or inserts into someTable).</p>
<p>I would not use a select statment in a trigger ever. Insert into the table rather than a select into. Once the table already exists select into does not work in most databases.</p>
24,777
<p>This is something that's been bothering me a while and there just has to be a solution to this. Every time I call ShellExecute to open an external file (be it a document, executable or a URL) this causes a very long lockup in my program before ShellExecute spawns the new process and returns. Does anyone know how to solve or work around this?</p> <p>EDIT: And as the tags might indicate, this is on Win32 using C++.</p>
<p>I don't know what is causing it, but Mark Russinovich (of sysinternal's fame) has a really great blog where he explains how to debug these kinds of things. A good one to look at for you would be <a href="http://blogs.technet.com/markrussinovich/archive/2006/11/27/532465.aspx" rel="nofollow noreferrer">The Case of the Delayed Windows Vista File Open Dialogs</a>, where he debugged a similar issue using only process explorer (it turned out to be a problem accessing the domain). You can of course do similar things using a regular windows debugger.</p> <p>You problem is probably not the same as his, but using these techniques may help you get closer to the source of the problem. I suggest invoking the <code>CreateProcess</code> call and then capturing a few stack traces and seeing where it appears to be hung.</p> <p><a href="http://blogs.technet.com/markrussinovich/archive/2006/08/31/453100.aspx" rel="nofollow noreferrer">The Case of the Process Startup Delays</a> might be even more relevant for you.</p>
<p>I don't know what is causing it, but Mark Russinovich (of sysinternal's fame) has a really great blog where he explains how to debug these kinds of things. A good one to look at for you would be <a href="http://blogs.technet.com/markrussinovich/archive/2006/11/27/532465.aspx" rel="nofollow noreferrer">The Case of the Delayed Windows Vista File Open Dialogs</a>, where he debugged a similar issue using only process explorer (it turned out to be a problem accessing the domain). You can of course do similar things using a regular windows debugger.</p> <p>You problem is probably not the same as his, but using these techniques may help you get closer to the source of the problem. I suggest invoking the <code>CreateProcess</code> call and then capturing a few stack traces and seeing where it appears to be hung.</p> <p><a href="http://blogs.technet.com/markrussinovich/archive/2006/08/31/453100.aspx" rel="nofollow noreferrer">The Case of the Process Startup Delays</a> might be even more relevant for you.</p>
21,393
<p>Where is the setting in Visual Studio 2003 to set the include path for individual projects? I know about the VC Directories option in Tools>Options but that is machine specific and won't help when I hand this off to other developers. </p>
<p><img src="https://www.lemurproject.org/images/VS_Net_AdditionalIncludes.jpg" alt="alt text"></p>
<p>Strangely I don't see that option. I ended up opening the vcproj file in jedit and writing it in. </p> <p><a href="http://img88.imageshack.us/img88/1128/idontknowmanln2.jpg" rel="nofollow noreferrer">idontknow http://img88.imageshack.us/img88/1128/idontknowmanln2.jpg</a></p>
24,909
<p>I'm trying to get something very subtle to work, it looks pretty awful right now. I'm trying to paint the background of a TGroupBox which I have overloaded the paint function of so that the corners are show through to their parent object. I've got a bunch of nested group boxes that look very decent without XPThemes. </p> <p>Is there a way to paint part of a background transparent at runtime. I'm programming the form generator, not using Delphi design view.</p>
<p>I'm trying to duplicate this problem with the following steps:</p> <p>1 - Set theme to Windows XP default</p> <p>2 - Drop a TGroupBox on an empty form (align = alNone)</p> <p>3 - Drop two TGroupBoxes inside the first one, with align = alBottom and align = alClient</p> <p>But visually it looks just fine for me.</p> <p>Can you provide some more info on exactly how you've designed the form? Some code pasted from the .DFM would be fine.</p> <p>Here's the relevant part of my DFM:</p> <pre><code> object GroupBox1: TGroupBox Left = 64 Top = 56 Width = 481 Height = 361 Margins.Left = 10 Caption = 'GroupBox1' ParentBackground = False TabOrder = 0 object GroupBox2: TGroupBox Left = 2 Top = 254 Width = 477 Height = 105 Align = alBottom Caption = 'GroupBox2' TabOrder = 0 end object GroupBox3: TGroupBox Left = 2 Top = 15 Width = 477 Height = 239 Align = alClient Caption = 'GroupBox3' TabOrder = 1 end end </code></pre>
<p>Ha, that was lame, I just needed to not set <code>ParentBackground := false</code> in my constructor and paint the interior of the group box when appropriate. </p>
18,658
<p>I want to use this pure HTML/CSS template for my ASP.NET website:</p> <p><a href="http://sub3.tanguay.de" rel="nofollow noreferrer">http://sub3.tanguay.de</a></p> <p>I copy it inside my Default.aspx page, inside the FORM element, but the form messes up the layout:</p> <p><a href="http://sub2.tanguay.de" rel="nofollow noreferrer">http://sub2.tanguay.de</a> <br/> <strong>UPDATE: this now displays correctly, thanks to Devio.</strong></p> <p>I tried altering the style of the form tag but can't get it to stop affecting the layout, I tried:</p> <pre><code>style="margin: 0px; padding: 0px; display: inline; background-color: transparent;" </code></pre> <ul> <li>Is this a common issue when copying in layout templates into ASP.NET?</li> <li>Is there an easy work around, like some margin:-2px fix or something like that?</li> <li>I need to keep the form tag, of course, for the ASP.NET functionality.</li> </ul>
<p>1) try removing the background-color attribute from the form class:</p> <pre><code>form { margin:10px; padding: 0; border: 1px solid #f2f2f2; background-color: #FAFAFA; /* remove this */ } </code></pre> <p>2) you cannot nest forms, but the searchform is contained inside the ASP.Net form, and ASP.Net requires exactly one form tag per page.</p>
<p>1) try removing the background-color attribute from the form class:</p> <pre><code>form { margin:10px; padding: 0; border: 1px solid #f2f2f2; background-color: #FAFAFA; /* remove this */ } </code></pre> <p>2) you cannot nest forms, but the searchform is contained inside the ASP.Net form, and ASP.Net requires exactly one form tag per page.</p>
40,765
<p>I'm reading about wiring up the electronic components to my Prusa i3 using an Arduino Mega 2650 and Ramps 1.4.</p> <p>I have step sticks, a heated bed, and a <a href="http://rads.stackoverflow.com/amzn/click/B007KG0ZYI" rel="noreferrer">Switching Power Supply 12v Dc 30a 360w</a> (more details on that later when I can add which ones to the post).</p> <p>I've heard that if you wire it wrong and plug it in, you can do anything from starting a fire to burning out your boards.</p> <p>What are some tips of things to check before plugging it in? Are there any common mistakes that I can avoid?</p>
<ul> <li><p>Polarity matters, sometimes. Be especially mindful of the wires from your power supply to the board, as getting those the wrong way around will definitely cause damage. Heated beds and extruders are not polarity sensitive, and can go in either way. Fans are polarized, but will probably survive if you get them backwards - they just won't run. Stepper motors don't care about polarity, flipping the connector around just makes them run backwards.</p></li> <li><p>Take special care with endstops. The endstop connectors have 3 pins (VCC, 5V and signal), endstops with 2 pins are usually connect to GND and signal. Putting a 2-pin endstop across 5V and GND will destroy the 5V regulator.</p></li> <li><p>A common cause of damage is wires not being clamped in their respective terminals properly. The offending wire will arc, melting and destroying the connector. Tighten down screw terminals properly, use proper crimps if you have them. Soldering the ends of wires going into screw terminals is not encouraged, but if you do solder the ends then make sure to check after a while and tighten the screws again.</p></li> <li><p>Put the stepper drivers in the right way around.</p></li> <li><p>For things like the heated bed and wires going to your power supply, use sufficiently thick wires. Especially with the heated bed, a lot of current flows through the wires and flimsy wires will heat up and melt.</p></li> </ul>
<p>Adding to the other answers:</p> <ul> <li>ALWAYS power-off the printer completely and make sure it is not receiving any power from any source (could be receiving power from USB after you turned the power supply off).</li> <li>Avoid loose wires, and before powering the printer on make sure every wire is connected in the right place. Loose wires can cause damage even if not powered if they get under the PCBs, where they can cause shorts. I fried an Arduino Mega this way.</li> <li>Never mix between 12v and 5v supply/output wires. Connecting an output wire of the wrong voltage will usually cause damage only to the part receiving power, while connecting a supply wire of the wrong voltage can cause severe damage to many components at once.</li> <li>Keep all wires organised. That will help you understand which wire is connected to what quickly, and will help you do what is mentioned in #2 and #3.</li> </ul>
123
<p>This has always bugged me. When I ssh or telnet to a Unix server (whatever flavour) it always manages to guess correctly the terminal type I am logging in from and so the keyboard always acts 'normally' ... i.e. the backspace key works. </p> <p>But then when I have successfully logged in, it often guesses incorrectly the terminal type I am using and makes incorrect key mappings - especially for the backspace key, meaning I have to issue a:</p> <pre><code>stty erase ... </code></pre> <p>type command to fix it. </p> <p>Any Unix gurus out there know why this happens?</p>
<p>I think you mean backspace properly works when you are inputting your username and password, then it stops working after you've logged in. </p> <p>Most likely stty is being set to something else in ~/.profile or /etc/profile (or another script that executes on login). </p> <p>Find that file and comment the line.</p>
<p>What SSH/telnet software are you using? </p> <p>When logging in via SSH, username/password entry is usually handled by the client, so it may be irrelevant.</p> <p>My guess would be that the TERM environment variable is being set incorrectly by your terminal software, eg. set to "vt100" when terminal is set to behave like xterm, etc.</p>
38,676
<p>I have the following in a program (written in VB.NET):</p> <pre><code>Imports Microsoft.Office.Interop.Excel Public Class Form1 Dim eApp As New Excel.Application Dim w As Excel.Workbook w = eApp.Workbooks.Open( "path.xls", ReadOnly:=True) .. Processing Code .. //Attempts at killing the excel application w.Close() eApp.Workbooks.Close() eApp.Quit() End Class </code></pre> <p>When I run this a couple of times, I get a bunch of EXCEL.EXE instances in my task manager. How can I kill these processes in code? All of the ones in the code have been tried and did not work.</p>
<p>I had to do this a while back in NET 1.1, so please forgive the rust. </p> <p>On the eApp, there was a Hwind (a win32 window handle - <a href="http://msdn.microsoft.com/en-us/library/bb255823.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/bb255823.aspx</a> ) or similar object. I had to use that and a pInvoke (<a href="http://www.pinvoke.net/default.aspx/user32.GetWindowThreadProcessId" rel="nofollow noreferrer">http://www.pinvoke.net/default.aspx/user32.GetWindowThreadProcessId</a> ) to get the process id. With that I was able to do a Process.Kill() on the exe.</p> <p>There maybe a better way to do it now, but this should work. </p>
<p>I posted a solution to this a few days ago: <a href="https://stackoverflow.com/questions/51462/killing-excelexe-on-server#312513">Killing Excel.EXE on server</a></p> <p>Same method as StingyJack mentions; the only one I know to really work.</p>
41,667
<p>What are some toolkits for developing 2D games in Python? An option that I have heard of is Pygame, but is there anything that has more range to do more things? What are the good and bad parts about the modules?</p>
<p>I use <a href="http://www.pygame.org/news.html" rel="nofollow noreferrer">pygame</a> myself and it is very good. It has good documentation and tutorials, and is quite well designed. I've also heard wonderful reviews of <a href="http://www.pyglet.org/" rel="nofollow noreferrer">pyglet</a>.</p>
<p>I've only heard people talk about pygame. It has tons of followers &amp; plenty of functionality.</p> <p>Recently I saw <a href="https://rads.stackoverflow.com/amzn/click/com/1590598725" rel="nofollow noreferrer" rel="nofollow noreferrer">this book</a> at barnes &amp; noble which I might check out one day. It looked good.</p>
5,492
<p>I've tried printing in vase mode (or &quot;spiralise outer contour&quot; in Cura) and while the floor looks fine, the vertical sides look &quot;saggy&quot;</p> <p>I'm using a 0.4 mm nozzle, with eSUN PLA+ at 218 °C and a bed temp of 60 °C. This combination works fine for normal printing. Layer height is 0.28 mm (Low Quality mode in Cura) with a line width of 0.4 mm</p> <p><a href="https://i.stack.imgur.com/KVFyS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KVFyS.png" alt="enter image description here" /></a> <br> Image is backlit by a monitor to show the laciness in the walls.</p> <p><a href="https://i.stack.imgur.com/8EnEB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8EnEB.png" alt="enter image description here" /></a> <br></p> <p>The original model was a 1x1x6 Gridfinity bin that uses less plastic than the original. <br></p> <p><a href="https://thangs.com/designer/LittleHobbyShop/3d-model/%23gridfinity%20Vase%20Mode%20Single%20Box-65828" rel="nofollow noreferrer">https://thangs.com/designer/LittleHobbyShop/3d-model/%23gridfinity%20Vase%20Mode%20Single%20Box-65828</a></p> <hr /> <p>Is this insufficient cooling, or too fast a print speed letting the filament sag under gravity before it cools? Or is a 0.4 mm nozzle too small?</p> <p>This reminds me of brickwork where the mortar is too wet. The bits that work right look fine, but all four sides have bad parts.</p> <p>What's the trick to vase mode printing?</p>
<p>Presuming that you're talking about an 8 hour period, your printer should be designed to run for 8 hours continuous anyway, so nothing will happen regarding the bed or screen that wouldn't happen with a normal print.</p> <p>If the first few layers stick to the bed, it's likely that you're print will at least be partially completed. So even over night it won't be a full 8 hours of printing while failed. Maybe half that period.</p> <p>If the problem is bed adhesion, or anything that doesn't effect the filament being supplied to the nozzle, then your only problem will be wasted filament and disposing of the spaghetti. No harm will come to your printer.</p> <p>If the problem is a break in the filament or filament runout, or a blocked nozzle then you could have damage to the head of the nozzle from printing dry. If you're printing with PLA this isn't really something that you need to worry about too much as you can run a printer dry for several hours without any problems.</p> <p>If you're printing with ABS or something that needs a hotter head then you could cause damage to it if it's allowed to run dry for an entire night. But again this isn't really something that you need to worry about unless it's running dry for 4 or 6 hours.</p> <p>Simply checking in on it once in the night should be enough to prevent any problems.</p>
<p>There are software solutions like &quot;Spaghetti Detective&quot; (recently renamed to &quot;Obico&quot;) which can watch your print via a camera, and potentially stop the job if it looks bad.</p> <p>Most of the time my print failures come early, in the form of poor bed adhesion - watch the job start for a while before leaving it.</p> <p>I can also remote-check my cameras and stop the job if required, but that requires me to look.</p> <p>The second most common failure is lifting from the base at any time in the print, so you have to keep an eye on it.</p> <p>Filament feed issues are probably third on the common list of causes for problems, including running out.</p> <p>I also have occasional issues where my Pi running Octoprint just looses connection to the printer, and it freezes in place with the bed/nozzle heaters on. This is just a waste of power, so a future plan is to wire the printer through a relay allowing me to power it on/off from octoprint's web page.</p> <p>My longest print was ~30 hours - you have to learn to not touch it unless there's a good reason.</p> <p>Finally, try and maintain the environmental conditions to be fairly constant. I have an enclosure even when printing plain PLA, becuase my printer's location is in a garage, and opening the main door allows the air temp to drop quickly. This would upset a running print until I surrounded it.</p> <p>You can also make sure there's a smoke or heat detector in the room where the printer is, for added peace of mind.</p>
2,158
<p>In asp.net 3.5, I have a problem that if I upload my global.asax to the remote web server, the app starts looking for my local sql server and eventually times out. I use a different config file for the local and remote because of the sql server login. Local is windows auth and remote is sql server auth. However, none of that info is stored in global.asax. global.asax only has</p> <p>but once it is uploaded, something causes the remote to try finding the local web.config's sql server login. Deleting global.asax on the remote causes everything to work fine. </p> <p>Any ideas?</p>
<p>Dropping in the global.asax file that will cause the inherited class to be used, is there any code in the inherited class that could be causing changes? </p> <p>The .asax maybe blank but that doesn't mean the inherited class is.</p>
<p>Have you checked the class it's inheriting from? It looks to be inheriting from <strong>myapp.Global</strong></p>
41,071
<p>Whilst debugging my program in VS 2008 I have come across the following error:</p> <p>The CLR has been unable to transition from COM context 0x34fc1a0 to COM context 0x34fc258 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this </p> <p>It appears to be deadlocking even though the code only contains a simple C# timer: See Snippet Below:</p> <pre><code> private void RequestWork() { // The timer will be re-intialised if there are still no wating jobs in the database StopTimer(); // assign all the threads some work InitialiseTimer(); } /// &lt;summary&gt; /// Initialise a timer with a timer interval configured from app.config. Enable the timer and /// register an appropriate event handler /// &lt;/summary&gt; private void InitialiseTimer() { if (m_Timer == null) { // look up the default backoff time from the config string backOffInt = ConfigurationSettings.AppSettings["BackOffInterval"]; int backoffInterval = 1000; m_Timer = new System.Timers.Timer(); // set the timer interval to 5 seconds m_Timer.Interval = backoffInterval; m_Timer.Elapsed += new ElapsedEventHandler(m_Timer_Elapsed); } m_Timer.Enabled = true; } private void StopTimer() { if (m_Timer != null) { m_Timer.Enabled = false; } } void m_Timer_Elapsed(object p_Sender, ElapsedEventArgs p_E) { RequestWork(); } </code></pre> <p>As far as I know the timer should run, elapse and then initialise again, I can see no local reason for a deadlock.</p> <p>I am aware of how to turn this error msg off but feel that this is not a solution, instead it is masking the problem.</p>
<p>You can turn this off if you think you've definitely <em>not</em> got a deadlock situation:</p> <p>Debug->Exceptions->Managed Debug Assistants menu in Visual Studio and uncheck the ContextSwitchDeadlock</p>
<p>Couple thoughts/questions:</p> <p>1) The code snippet looks like your interval is every 1 second (not 5 as mentioned in the comments). 2) The big question is what is <code>RequestWork()</code> doing?</p> <p>Without knowing what <code>RequestWork()</code> is doing, we can't really comment on why you are seeing a ContextSwitchDeadlock.</p> <p>Somethings to think about with respect to this method a) how long does it take? b) is it accessing GUI elements?</p> <p>Some MSDN comments on Elapsed:</p> <blockquote> <p>If you use the Timer with a user interface element, such as a form or control, assign the form or control that contains the Timer to the SynchronizingObject property, so that the event is marshaled to the user interface thread.</p> </blockquote> <p>-and- </p> <blockquote> <p>The Elapsed event is raised on a ThreadPool thread. If processing of the Elapsed event lasts longer than Interval, the event might be raised again on another ThreadPool thread. Thus, the event handler should be reentrant.</p> </blockquote> <p>I'm thinking since you have a 1 second timer, you might want to look into what happens in RequestWork and see how long its taking.</p>
43,351
<p>we have SAP Business One - Fourth Shift Edition running here at a small manufacturing company. The consulting company that has come in to do the installation/implementation uses the "sa" id/pass to initially connect to the database to get the list of companies. From then on, I have to assume that its the sa id/pass that is being used to connect the client software to the database. Is this appropriate? I dont know where this data is being stored... as an ODBC connection? directly in the registry somewhere? Is it secure? Would it be better to set the users network ID in the database security and then use the "trusted connection" setting instead? Or do most people create a separate login in the database for each user and use that in the client settings?</p> <p>seems like the easiest way would be to add the users network login to the sql server security so they can use the "trusted connection"... but then wouldn't that allow ANY software to connect to the database from that machine?</p> <p>So anyways: what are the best-practices for setting this up?</p>
<p>That sa usage sounds like a recipe for disaster.</p> <p>In most security models I have seen, regardless of how you connect, the first lookup SPs, views or tables are read-accessible to all authenticated users. Even if the application has a dedicated logon, it's not sa.</p> <p>Without knowing more about SAPs limitations, I can't be sure, but we always tend to use Windows Authentication and Windows Active Directory Groups. Those groups are allowed in SQL Server roles. So all administration is done at the AD level. The DB is locked down according to those roles - even if an application has a SQL Server login or a domain login, it's going to be in one of the database roles we've created, named and granted rights appropriately.</p>
<p>That is very wrong, the sa account should not be used for general use.</p> <p>A separate ('application' specific) user account should be used so that:</p> <ul> <li>Security can be applied on a per user (application) level</li> <li>If anything goes wrong with the application (e.g. it locks the user account), just that one account is effected and it is easy to diagnose issues</li> </ul> <p>I also agree with Cade Roux's comments.</p>
47,118
<p>I'd like to add scrolling capability to a <code>javax.swing.JDesktopPane</code>. But wrapping in a <code>javax.swing.JScrollPane</code> does not produce the desired behavior.</p> <p><a href="http://www.google.com/search?q=scrollable+jdesktoppane" rel="nofollow noreferrer">Searching the web</a> shows that this has been an issue for quite some time. There are <a href="http://jscroll.sourceforge.net" rel="nofollow noreferrer">some</a> <a href="http://www.javaworld.com/javaworld/jw-11-2001/jw-1130-jscroll.html" rel="nofollow noreferrer">solutions</a> out there, but they seem to be pretty old, and I'm not not completely satisfied with them.</p> <p>What <strong>actively maintained</strong> solutions do you know?</p>
<p>I've used <a href="http://www.javaworld.com/javaworld/jw-11-2001/jw-1130-jscroll.html" rel="noreferrer" title="Scrollable JDesktopPane">JavaWorld's solution</a> by creating my own <code>JScrollableDesktopPane.</code> </p>
<p>I've found this : <a href="http://www.javaworld.com/javaworld/jw-11-2001/jw-1130-jscroll.html?page=1" rel="nofollow">http://www.javaworld.com/javaworld/jw-11-2001/jw-1130-jscroll.html?page=1</a></p> <p>It's a nice tutorial with lots of explanations and infos on Swing &amp; so, which permits to create a JscrollableDesktopPane with lots of stuff.</p> <p>You will need to modify a bit some parts of code to fulfill your requirements.</p> <p>Enjoy !</p>
17,915
<p>I'm trying to import an excel file in to a SQL Server 2000 database using DTS. This is nothing fancy, just a straight import. Where I work, we do this 1000 times a day. This procedure usually works without an issue but something must have changed in the file.</p> <p>I'm getting the below error:</p> <p><a href="http://www.understandingguitar.org/wp-content/uploads/2008/12/packageerror-screenshot-20081212.jpg" rel="nofollow noreferrer">Screen shot of Error http://www.understandingguitar.org/wp-content/uploads/2008/12/packageerror-screenshot-20081212.jpg</a></p> <p>I've checked to ensure that the column &quot;AssignmentID&quot; is stored as &quot;text&quot; in the excel sheet. I've also tried to change it to general. Exact same error regardless of setting. The field does contain numbers... I appreciate everyone's help on this!</p> <p>Regards, <br />Frank</p>
<p>I'm not sure what books are out there, but here is some required reading on how ItemsControls work:</p> <ul> <li><a href="http://drwpf.com/blog/ItemsControlSeries/tabid/59/Default.aspx" rel="nofollow noreferrer">Dr, WPF - Items Control A- Z</a></li> <li><a href="http://www.codeproject.com/KB/WPF/TreeViewWithViewModel.aspx" rel="nofollow noreferrer">Josh Smith - Tree View and the MVVM Pattern</a></li> </ul> <p>I think you need to realize that Menus and TreeViews are ItemsControls, but then again so are MenuItem, and TreeViewITem. By nature a TreeView item is not only an item in a parent TreeView, but it also is a TreeView/ItemsControl itself.</p>
<p>Here's a real world example of where this override is used in relation to a TreeView control: <a href="http://blogs.msdn.com/jpricket/archive/2008/08/05/wpf-a-stretching-treeview.aspx" rel="nofollow noreferrer">http://blogs.msdn.com/jpricket/archive/2008/08/05/wpf-a-stretching-treeview.aspx</a></p> <p>I hope this helps.</p>
47,526
<p>I have a <code>List&lt;int&gt;</code> and a <code>List&lt;customObject&gt;</code>. The customObject class has an ID property. How can I get a <code>List&lt;customObject&gt;</code> containing only the objects where the ID property is in the <code>List&lt;int&gt;</code> using LINQ?</p> <p><strong>Edit</strong>: I accepted Konrads answer because it is easier/more intuitive to read.</p>
<pre><code>var result = from o in objList where intList.Contains(o.ID) select o </code></pre>
<p>Please note that using the join instead of contains DOES NOT work when the count of items in the list exceeds 49! You will get the error: <code>Some part of your SQL statement is nested too deeply. Rewrite the query or break it up into smaller queries.</code></p>
5,861
<p>I need to be able to export Trac tickets from a report or custom query to Excel, including the ticket description. The catch is that the description must be formatted as defined by the wiki syntax rather than displaying the raw text.</p>
<p>you can just go to "View Tickets" and chose "Custom Query" there you select all the columns you want to see. There will not be a "Description" column, cause it could be wiki formatted, therefore it is available only as a "row" option. But you can still edit the query manually, and add a: &amp;col=description in it, so you will have the description "unformatted" as a table column.</p> <p>Than chose download as Comma Delimited Text, and open it in Excel ;-)</p> <p>HTH</p>
<p>I've had the same issue. I've tried ExcelExportPlugin, but it is not better than exporting in CSV. In particular, it doesn't format the "description".</p> <p>I've had better luck saving the whole HTML report, isolating the html table, and importing it as html file in Excel : It keeps well all the formatting.</p> <p>Hope this helps.</p>
49,301
<p>I am wondering how to get a process run at the command line to use less processing power. The problem I'm having is the the process is basically taking over the CPU and taking MySQL and the rest of the server with it. Everything is becoming very slow.</p> <p>I have used <code>nice</code> before but haven't had much luck with it. If it is the answer, how would you use it?</p> <p>I have also thought of putting in <code>sleep</code> commands, but it'll still be using up memory so it's not the best option.</p> <p>Is there another solution?</p> <p>It doesn't matter to me how long it runs for, within reason.</p> <p>If it makes a difference, the script is a PHP script, but I'm running it at the command line as it already takes 30+ minutes to run.</p> <p>Edit: the process is a migration script, so I really don't want to spend too much time optimizing it as it only needs to be run for testing purposes and once to go live. Just for testing, it keeps bring the server to pretty much a halt...and it's a shared server.</p>
<p>You should use nice with 19 "niceness" this makes the process very unlikely to run if there are other processes waiting for the cpu.</p> <pre><code> nice -n 19 &lt;command&gt; </code></pre> <p>Be sure that the program does not have busy waits and also check the I/O wait time.</p>
<p>Using CPU cycles alone shouldn't take over the rest of the system. You can show this by doing:</p> <pre><code>while true; do done </code></pre> <p>This is an infinite loop and will use as much of the CPU cycles it can get (stop it with ^C). You can use <code>top</code> to verify that it is doing its job. I am quite sure that this won't significantly affect the overall performance of your system to the point where MySQL dies.</p> <p>However, if your PHP script is allocating a lot of memory, that certainly <em>can</em> make a difference. Linux has a tendency to go around killing processes when the system starts to run out of memory.</p> <p>I would narrow down the problem and be sure of the cause, before looking for a solution.</p>
32,154
<p>I recently inherited a VBA macro that needs to have validation logic added to it. I need to be able to determine if any characters in a text based cell are non ASCII characters (i.e. have a binary value > 0x7F). The cells may contain some carriage control values (particularly linefeeds) that need to be retained (so the CLEAN function does not work for this validation). I have tried the IsText function, but found that it will interpret UTF-8 character sequences as valid text (which I don't want).</p> <p>I don't need to actually manipulate the string, I just want to display an error to the user that runs the macro to tell him that there are invalid (non-ASCII) characters in a specific cell.</p>
<p>The asc(character) command will convert a character to it's ASCII value. </p> <p>hex(asc(character)) will convert the character to it's HEX value.</p> <p>Once you've done that you can easily do some comparisons to determine if the data is bad and toss the errors if required.</p> <p>Here's some sample code: <a href="http://www.freevbcode.com/ShowCode.asp?ID=4486" rel="nofollow noreferrer">http://www.freevbcode.com/ShowCode.asp?ID=4486</a></p>
<pre><code>Function IsGoodAscii(aString as String) as Boolean Dim i as Long Dim iLim as Long i=1 iLim=Len(aString) While i&lt;=iLim If Asc(Mid(aString,i,1))&gt;127 then IsGoodAscii=False Exit Function EndIf i=i+1 Wend IsGoodAscii=True End Function </code></pre>
32,865
<p>In the C / Unix environment I work in, I see some developers using <code>__progname</code> instead of <code>argv[0]</code> for usage messages. Is there some advantage to this? What's the difference between <code>__progname</code> and <code>argv[0]</code>. Is it portable?</p>
<p><code>__progname</code> isn't standard and therefore not portable, prefer <code>argv[0]</code>. I suppose <code>__progname</code> could lookup a string resource to get the name which isn't dependent on the filename you ran it as. But <code>argv[0]</code> will give you the name they <em>actually</em> ran it as which I would find more useful.</p>
<p>If your program was run using, for instance, a symbolic link, argv[0] will contain the name of that link.</p> <p>I'm guessing that __progname will contain the name of the actual program file.</p> <p>In any case, argv[0] is defined by the C standard. __progname is not.</p>
34,486
<p>I'd like to track changes in inputs in a form via javascript. My intent is (but not limited) to</p> <ul> <li>enable "save" button only when something has changed</li> <li>alert if the user wants to close the page and something is not saved</li> </ul> <p>Ideas?</p>
<p>Loop through all the input elements, and put an <code>onchange</code> handler on each. When that fires, set a flag which lets you know the form has changed. A basic version of that would be very easy to set up, but wouldn't be smart enough to recognize if someone changed an input from "a" to "b" and then back to "a". If it were important to catch that case, then it'd still be possible, but would take a bit more work.</p> <p>Here's a basic example in jQuery:</p> <pre><code>$("#myForm") .on("input", function() { // do whatever you need to do when something's changed. // perhaps set up an onExit function on the window $('#saveButton').show(); }) ; </code></pre>
<p>Attach an event handler to each form input/select/textarea's onchange event. Setting a variable to tell you if you should enable the "save" button. Create an onunload hander that checks for a dirty form too, and when the form is submitted reset the variable:</p> <pre> window.onunload = checkUnsavedPage; var isDirty = false; var formElements = //Get a reference to all form elements for(var i = 0; len = formElements.length; i++) { //Add onchange event to each element to call formChanged() } function formChanged(event) { isDirty = false; document.getElementById("savebtn").disabled = ""; } function checkUnsavedPage() { if (isDirty) { var isSure = confirm("you sure?"); if (!isSure) { event.preventDefault(); } } } </pre>
23,582
<p>I have a basic cs-major understanding of multi-threading but have never had to do anything beyond simple timers in an application. Does anyone know of a good resource that will give me a tour how to work with multi-threaded applications, explaining the basics and maybe posing some of the more difficult stuff?</p>
<p>This is a great free resource by Joseph Albahari. <a href="http://www.albahari.com/threading/" rel="noreferrer">Threading in C#</a></p>
<p>One of the best resources I know on the subject is the "threading in C#" book: <a href="http://www.albahari.com/threading/" rel="nofollow noreferrer">http://www.albahari.com/threading/</a></p> <p>I has a great overview of all a .net developer need to understand in order to program multi threaded applications.</p>
7,243
<p>I have CruiseControl.NET Version 1.4 set up on my development server. Whenever a developer checks in code, it makes a compile. </p> <p>Now we're at a place where we can start giving our application to the testers. We'd like to use ClickOnce to distribute the application, with the idea being that when a tester goes to test the application, they have the latest build. </p> <p>I can't find a way to make that happen with CruiseControl.NET. We're using MSBUILD to perform the builds.</p>
<p>We've done this and can give you some pointers to start.</p> <p>2 things you should be aware of:</p> <ul> <li>MSBuild can generate the necessary deployment files for you.</li> <li>MSBuild won't deploy the files to the FTP or UNC share. You'll need a separate step for this.</li> </ul> <p>To use MSBuild to generate the ClickOnce manifests, here's the command you'll need to issue:</p> <pre><code>msbuild /target:publish /p:Configuration=Release /p:Platform=AnyCPU; "c:\yourProject.csproj" </code></pre> <p>That will tell MSBuild to build your project and generate ClickOnce deployment files inside the <em>bin\Release\YourProject.publish</em> directory.</p> <p>All that's left is to copy those files to the FTP/UNC share/wherever, and you're all set.</p> <p>You can tell CruiseControl.NET to build using those MSBuild parameters.</p> <p>You'll then need a CruiseControl.NET build task to take the generated deployment files and copy them to the FTP or UNC share. We use a custom little C# console program for this, but you could just as easily use a Powershell script.</p>
<p>You want to use the ClickOnce manifest generation tasks in msbuild. The process is a little long winded, so I am just going to point you to a couple of links. Here is the <a href="http://msdn.microsoft.com/en-us/library/6wc2ccdc.aspx" rel="nofollow noreferrer">reference on msdn</a> and a <a href="http://windowsclient.net/articles/ClickOnce_MsBuild.aspx" rel="nofollow noreferrer">sample article</a> to hopefully get you started.</p>
3,349
<p>I need to know how to iterate through records in CR2008 and when it reaches a record that is NOT NULL, record that in a variable.</p> <p>I have a formula called "frmAccum" that I drop in the details section and suppress it. I use this to gather information for each record that's processed. I also have a formula called frmReset where I rest the stringvar "person_name" to "" and I can drop that in a Group header to reset after a grouping.</p> <p>When it comes across a person_name field that is NOT NULL and is not empty, I want it to retain the name in a variable to be used in the report header.</p> <p>So something like this:</p> <pre><code>stringvar person_name; whileprintingrecords; If ({Command.personname} &lt;&gt; "") Then person_name := {Command.personname} </code></pre> <p>I can't get this combination to work. Any help is appreciated.</p>
<p><strong>Please don't do this.</strong> It's a really, really, really, really, really <em>bad idea</em>.</p> <p>Maybe not as bad as deleting files randomly, if the hard drive runs out of room - but just about as bad.</p>
<p>Mark's code is probably better, but here's mine...</p> <p>If you <strong>really</strong> want to do something like this, I'd use code something like this. Yes, you still have to manually call it, but your idea of indiscriminately retrying ALL excepting methods is a really, really bad idea.</p> <pre><code>public class TryAgain { public delegate void CodeToTryAgain (); public static void Repeat&lt;E&gt;(int count, CodeToTryAgain code) where E : Exception { while (count-- &gt; 0) { try { code(); return; } catch (E ex) { Console.WriteLine("Caught an {0} : {1}", typeof(E).Name, ex.Message); // ignoring it! } } } } </code></pre> <p>And then you'd call your failing method, <code>ThrowTwice</code>, or whatever you want to do, like this:</p> <pre><code>TryAgain.Repeat&lt;MyException&gt;(5, delegate() { ThrowTwice(); }); </code></pre> <p>In this example, the Repeat method will ignore all exceptions of type MyException, trying to call ThrowTwice up to 5 times...</p> <p>You can add your own sleeping and time-outs, and whatever.</p>
43,553
<p>Does anyone have experience using the URL Rewrite Module (see <a href="http://blogs.iis.net/bills/archive/2008/07/09/new-iis7-releases-url-rewrite-application-routing-and-load-balancing-and-powershell-cmd-lets.aspx" rel="nofollow noreferrer">here</a>)?</p> <p>Can it be used to do <a href="http://en.wikipedia.org/wiki/Reverse_proxy" rel="nofollow noreferrer">reverse proxy</a>?</p>
<p>If you have enough RAM, SQL will do an outstanding job determining what to load into RAM and what to seek on disk. </p> <p>This question is asked a lot and it reminds me of people trying to manually set which "core" their process will run on -- let the OS (or in this case the DB) do what it was designed for.</p> <p>If you want to verify that SQL is in fact reading your look-up data out of cache, then you can initiate a load test and use Sysinternals <a href="http://technet.microsoft.com/en-us/sysinternals/bb896642.aspx" rel="nofollow noreferrer">FileMon</a>, <a href="http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx" rel="nofollow noreferrer">Process Explorer</a> and <a href="http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx" rel="nofollow noreferrer">Process Monitor</a> to verify that the 1GB table is not being read from. For this reason, we sometimes put our "lookup" data onto a separate filegroup so that it is very easy to monitor when it is being accessed on disk.</p> <p>Hope this helps.</p>
<p><a href="http://msdn.microsoft.com/en-us/library/ms178015(SQL.90).aspx" rel="nofollow noreferrer">DBCC PINTABLE</a> will explicitly pin a table in core if you want to make sure it remains cached.</p>
6,455
<p>What is the proper way to modify environment variables like PATH in OS&nbsp;X?</p> <p>I've looked on Google a little bit and found three different files to edit:</p> <ul> <li>/etc/paths</li> <li>~/.profile</li> <li>~/.tcshrc</li> </ul> <p>I don't even have some of these files, and I'm pretty sure that <em>.tcshrc</em> is wrong, since OS&nbsp;X uses bash now. Where are these variables, especially PATH, defined?</p> <p>I'm running <a href="http://en.wikipedia.org/wiki/Mac_OS_X_Leopard" rel="noreferrer">OS&nbsp;X&nbsp;v10.5</a> (Leopard).</p>
<p>Bruno is right on track. I've done extensive research and if you want to set variables that are available in all GUI applications, your only option is <code>/etc/launchd.conf</code>.</p> <p>Please note that <a href="https://web.archive.org/web/20100212232552/https://www.digitaledgesw.com/node/31" rel="noreferrer">environment.plist does not work for applications launched via Spotlight. This is documented by Steve Sexton here</a>.</p> <ol> <li><p>Open a terminal prompt</p></li> <li><p>Type <code>sudo vi /etc/launchd.conf</code> (note: this file might not yet exist)</p></li> <li><p>Put contents like the following into the file</p> <pre class="lang-none prettyprint-override"><code># Set environment variables here so they are available globally to all apps # (and Terminal), including those launched via Spotlight. # # After editing this file run the following command from the terminal to update # environment variables globally without needing to reboot. # NOTE: You will still need to restart the relevant application (including # Terminal) to pick up the changes! # grep -E "^setenv" /etc/launchd.conf | xargs -t -L 1 launchctl # # See http://www.digitaledgesw.com/node/31 # and http://stackoverflow.com/questions/135688/setting-environment-variables-in-os-x/ # # Note that you must hardcode the paths below, don't use environment variables. # You also need to surround multiple values in quotes, see MAVEN_OPTS example below. # setenv JAVA_VERSION 1.6 setenv JAVA_HOME /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home setenv GROOVY_HOME /Applications/Dev/groovy setenv GRAILS_HOME /Applications/Dev/grails setenv NEXUS_HOME /Applications/Dev/nexus/nexus-webapp setenv JRUBY_HOME /Applications/Dev/jruby setenv ANT_HOME /Applications/Dev/apache-ant setenv ANT_OPTS -Xmx512M setenv MAVEN_OPTS "-Xmx1024M -XX:MaxPermSize=512m" setenv M2_HOME /Applications/Dev/apache-maven setenv JMETER_HOME /Applications/Dev/jakarta-jmeter </code></pre></li> <li><p>Save your changes in vi and reboot your Mac. Or use the <a href="http://linux.die.net/man/1/grep" rel="noreferrer"><code>grep</code></a>/<a href="https://linux.die.net/man/1/xargs" rel="noreferrer"><code>xargs</code></a> command which is shown in the code comment above.</p></li> <li><p>Prove that your variables are working by opening a Terminal window and typing <code>export</code> and you should see your new variables. These will also be available in IntelliJ IDEA and other GUI applications you launch via Spotlight.</p></li> </ol>
<p>For Bash, try adding your environment variables to the file <code>/etc/profile</code> to make them available for all users. No need to reboot, just start a new Terminal session.</p>
16,430
<p>My Ender 5 Plus (original) does not perform leveling.</p> <p>After the self-leveling command, the Z axis only descends. I have already exchanged the BLTouch three times, and the problem remains unchanged.</p> <p>I bought my E5P in December, in America, to bring it to Brazil, I had to completely dismantle it.</p> <p>Machine reassembled, I start work again, everything works very well. But, one day, I made the mistake of stopping an impression (due to problems with the appearance of the piece) and, before removing the piece from the bed, I pressed the HOME command, which caused the hotend/BLTouch to rest on the printed part, forcing the whole mechanism.</p> <p>Well, I changed the BLTouch and the problems really started.<br /> When I send the leveling command, the Z-axis behaves erratically, going down instead of returning to the beginning and, with each command, it goes down more and more.</p> <p>I changed the leveler again, the problem persisted, I disassembled piece by piece, wiped a general cleaning, applied a clean solution to contacts all over the electronics, reassembled, reinstalled the firmware (Version 1.71.0 KF), and everything went back to work.</p> <p>Yesterday, I sent a piece for printing (PLA nozzle 1.00 mm, layer 0.36 mm, speed 100 mm/s, infill 40 %), and left for my morning walk. When I returned, there was a huge ball of melted material, adhered to the hotend, again more problems. I disassembled the entire hotend, carried out the total cleaning, reassembled it, and let's go back to work.</p> <p>Leveling OK, there was a problem with the thermistor and the heating of the nozzle, I changed the thermistor and the heater cartridge (taking the opportunity, since several times the system had heating problems, when the temperature should be above 230 °C / 446 °F). Everything ready, come on...</p> <ul> <li>Leveling problem has returned.</li> <li>BLTouch exchange done, nothing done</li> <li>Loading the firmware again, nothing done</li> <li>Review of connections, nothing done</li> </ul> <p>The Z-axis continues to descend, not responding to commands, and in the Pronterface the message appears:</p> <pre><code>Error: STOP called because of BLTouch error - restart with M999 Error: STOP called because of BLTouch error - restart with M999 </code></pre> <p>I've already exchanged BLTouch 2 times and it didn't work out. I have 2 inductive levelers here, maybe the solution is to install them and forget the BLTouch, or do the leveling manually.</p> <p>Questions:</p> <ol> <li>Has anyone had this kind of problem with the printer? If so, what is the solution?</li> <li>removing the leveler and performing manual leveling, has anyone tried this? What changes in Marlin need to be made?</li> <li>Does the replacement of the BLTouch by an inductive sensor imply in what firmware changes? Is there a tutorial about it?</li> </ol> <p>I appreciate any help you can get from friends</p>
<p>I had the same problem with my Ender 5 Plus.</p> <p>There is a small set screw at the top of the BLTouch you will need to tighten this in to adjust the location of the sensor pin. Keep screwing it more and more until you see it initialize reliably that is it should move out and back twice to initialize.</p> <p>When the BLTouch initializes correctly then the leveling can be completed.</p>
<p>I had the same issue. The probe for the BL touch was just stuck.</p> <p>I manually pulled it out and tightened the screw and then the problem was fixed.</p>
1,930
<p>Is there a better way to do the following:</p> <pre><code>$array = array('test1', 'test2', 'test3', 'test4', 'test5'); // do a bunch of other stuff, probably a loop $array[] = 'test6'; end($array); echo key($array); // gives me 6 </code></pre> <p>This will give the key of the most recently add array element.</p> <p>Is there a better way to do this?</p>
<p>You could also do:</p> <pre><code>$end = end(array_keys($array)); </code></pre> <p>But I think your way makes it clear what you want to do, so you could whip something up like:</p> <pre><code>function array_last_key($array) { end($array); return key($array); } </code></pre> <p>That's about it.</p>
<p>There is no special function for this in PHP, so I think your way is the most efficent way of doing this. For readability you might want to put it in a function called something like array_last_key().</p>
26,556
<p>My client has a multi-page PDF file. They need it split by page. Does anyone know of a way to do this - preferably in C#.</p>
<p><a href="http://www.pdfsharp.com/" rel="noreferrer">PDFSharp</a> is an open source library which may be what you're after:</p> <blockquote> <p>Key Features</p> <ul> <li>Creates PDF documents on the fly from any .Net language</li> <li>Easy to understand object model to compose documents</li> <li>One source code for drawing on a PDF page as well as in a window or on the printer</li> <li>Modify, merge, and split existing PDF files</li> </ul> </blockquote> <p><a href="http://www.pdfsharp.com/PDFsharp/index.php?option=com_content&amp;task=view&amp;id=37&amp;Itemid=48" rel="noreferrer">This sample</a> shows how to convert a PDF document with n pages into n documents with one page each.</p>
<p>I did this using <a href="http://itextsharp.sourceforge.net" rel="nofollow noreferrer">ITextSharp</a> -- there are commercial options that may have a good API but this is open source and free, and not hard to use.</p> <p>Check out <a href="http://itextsharp.sourceforge.net/examples/Split.cs" rel="nofollow noreferrer">this code</a>, it's one of their code samples -- it's pretty good. It splits a PDF file into two files at the passed-in page number. You can modify it to loop and split page by page.</p>
14,845
<p>When I launch the "mvn install" command, maven sometimes tries to download dependencies that it has already downloaded. That's expected for SNAPSHOT but why does maven do that for other JARs?</p> <p>I know I can avoid that behavior by "-o" flag but I just wonder what the cause is.</p>
<p>I'd look for dependencies that don't have a specified version number. Maven will periodically check to make sure that it has the most up-to-date version of these artifacts.</p>
<p>The -o flag still wasn't working for me, but this did:</p> <pre><code>find ~/.m2/repository -name '_maven*' | xargs rm find ~/.m2/repository -name '*lastUpdated' | xargs rm </code></pre> <p>Which will delete all the .lastUpdated and _maven.repositories files in your local repo. I ran into this issue because we have a corporate Nexus repo that was unreachable, and I needed to do some work. Using Eclipse's Maven integration may have also contributed to this. </p>
15,408
<p>When using CDT I would like to have std::string show up in the 'variable' debug window with the string it contains. For instance if it is currently holding the word <em>"history"</em> I would like to see <strong>history</strong> in the debugger window labeled "variables". </p> <p>I think that there is a general way to have it drill down into objects but I can't put my finger on it. Does anyone out there know how to do this?</p> <p>This would also be useful for me to use when outputting just a single field from a complex object.</p> <p>Thanks, Bill</p>
<p>Displaying stl containers with eclipse/gdb was also a major pain for me for a long time.</p> <p>But now I've just discovered that the latest version of gdb with python enabled can help with that.</p> <p>It follows what I've done (using Ubuntu Linux 8.10):</p> <ul> <li>Install gdb version >= 6.8.50 (for instance <a href="http://packages.debian.org/experimental/i386/gdb/download" rel="nofollow noreferrer">from debian experimental</a>)</li> <li><p>Create a file named .gdbinit in your project root with the following content:</p> <p>python import gdb.libstdcxx.v6.printers</p></li> </ul> <p>Now the stl containers will be <strong>pretty printed</strong>.</p> <p>If you want to check if you already have a python enabled gdb (or if your new installation have worked):</p> <ul> <li>Start gdb from the console</li> <li><p>On the gdb prompt execute the following</p> <p>(gdb) python print 'Python enabled GDB is working!'</p></li> <li><p>If the above command produces what we are expecting then it is working.</p></li> </ul> <p>For more details check <a href="http://tromey.com/blog/?p=524" rel="nofollow noreferrer">this blog</a>.</p>
<p>The only way I have found is to use the GDB command line:</p> <ol> <li>In the <em>Debug</em> window, click on <em>gdb</em>. It's just below the stack trace.</li> <li>In the <em>Console</em> window, use the GDB <code>up</code> command to get to the stack frame you want</li> <li><p>Again in the <em>Console</em> window, use the <code>print</code> command to display the <code>std::string</code> variable:</p> <p>p mystring</p></li> </ol> <p>But that's a lot of trouble.</p> <p>Something I have noticed is that when I hover over the variable, the fields of the std::string actually are displayed, but it is truncated, so I do not see the most interesting part: the string value. Perhaps there is a way to increase the maximum length of the value displayed.</p>
37,826
<p>I am creating a script on the fly to ftp some files from a remote computer. I create a file which is then called from the command line with</p> <pre><code>ftp -s:filename proxy </code></pre> <p>where filename is the file I just created. The file has code similar to the following:</p> <pre><code>anonymous@ip address username prompt off binary cd c:\destination directory mget c:\source directory\*.* quit </code></pre> <p>That doesn't work. Neither does the following:</p> <pre><code>anonymous@ip address username prompt off binary cd c:\source directory mput c:\destination directory quit </code></pre> <p>Obviously, I'm not so good at ftp. How, in what order, where in my file do I specify the place where I want the files to be put (destination directory, and also from where the ftp process is running), and where I want the files to come from (ip address computer which has files I want). Do I need to set the directory before starting the ftp process?</p> <p>I'm running this in an SSIS package, and I'm not using the SSIS ftp task, because I don't want a failure if no files are found. If there's nothing there, that's cool. If there is something there, I want a copy.</p> <p>(It was working in my development area, and now, when I'm trying to get files from a server that I truely have no access to except ftp, I'm not getting anything. See <a href="https://stackoverflow.com/questions/140850/the-best-way-for-a-ssis-ftp-task-to-not-fail-when-there-are-no-files-to-copy">How to avoid SSIS FTP task from failing when there are no files to download?</a> for an earlier, related question.)</p> <p><strong>Update:</strong> Both of the answers below, listing lcd and cd, are correct. However, my example still failed, until I replaced the backslashes with forward slashes. In other words, my final, working result is as follows:</p> <pre><code>anonymous@ip address username prompt off binary lcd /destination directory cd /source directory mget *.* quit </code></pre>
<p>In most ftp clients you can set the working directory on the server with the command <strong>cd</strong>, and you set the working directory on the client with the command <strong>lcd</strong>.</p> <p>But it is not clear to me what you are trying to do.</p> <p>Are you trying to move or copy files that are on the ftp server to another location on the ftp server? As far as I know you cannot do that with ftp. If you wished to copy files from one folder on the ftp server to another, then I believe you would get a copy to the local system, and then reupload them to a new folder. If you wish to move files you can use the <strong>rename</strong> command.</p>
<p>In most ftp clients you can set the working directory on the server with the command <strong>cd</strong>, and you set the working directory on the client with the command <strong>lcd</strong>.</p> <p>But it is not clear to me what you are trying to do.</p> <p>Are you trying to move or copy files that are on the ftp server to another location on the ftp server? As far as I know you cannot do that with ftp. If you wished to copy files from one folder on the ftp server to another, then I believe you would get a copy to the local system, and then reupload them to a new folder. If you wish to move files you can use the <strong>rename</strong> command.</p>
46,671
<p>We run a medium-size site that gets a few hundred thousand pageviews a day. Up until last weekend we ran with a load usually below 0.2 on a virtual machine. The OS is Ubuntu.</p> <p>When deploying the latest version of our application, we also did an apt-get dist-upgrade before deploying. After we had deployed we noticed that the load on the CPU had spiked dramatically (sometimes reaching 10 and stopping to respond to page requests). </p> <p>We tried dumping a full minute of Xdebug profiling data from PHP, but looking through it revealed only a few somewhat slow parts, but nothing to explain the huge jump.</p> <p>We are now pretty sure that nothing in the new version of our website is triggering the problem, but we have no way to be sure. We have rolled back a lot of the changes, but the problem still persists.</p> <p>When look at processes, we see that single Apache processes use quite a bit of CPU over a longer period of time than strictly necessary. However, when using strace on the affected process, we never see anything but</p> <pre><code>accept(3, </code></pre> <p>and it hangs for a while before receiving a new connection, so we can't actually see what is causing the problem.</p> <p>The stack is PHP 5, Apache 2 (prefork), MySQL 5.1. Most things run through Memcached. We've tried APC and eAccelerator.</p> <p>So, what should be our next step? Are there any profiling methods we overlooked/don't know about?</p>
<p>The answer ended up being not-Apache related. As mentioned, we were on a virtual machine. Our user sessions are pretty big (think 500kB per active user), so we had a lot of disk IO. The disk was nearly full, meaning that Ubuntu spent a lot of time moving things around (or so we think). There was no easy way to extend the disk (because it was not set up properly for VMWare). This completely killed performance, and Apache and MySQL would occasionally use 100% CPU (for a very short time), and the system would be so slow to update the CPU usage meters that it seemed to be stuck there.</p> <p>We ended up setting up a new VM (which also gave us the opportunity to thoroughly document everything on the server). On the new VM we allocated plenty of disk space, and moved sessions into memory (using memcached). Our load dropped to 0.2 on off-peak use and around 1 near peak use (on a 2-CPU VM). Moving the sessions into memcached took a lot of disk IO away (we were constantly using about 2MB/s of disk IO, which is very bad).</p> <p>Conclusion; sometimes you just have to start over... :)</p>
<p>Another option that I can't assure you will do any good, but it's more than worth the effort. Is to read the detailed changelog for the new version, and review what might have changed that could remotely affect you. </p> <p>Going through the changelogs has saved me more than once. Especially when some config options have changed and when something got deprecated. Worst case is it'll give you some clues as to where to look next</p>
20,936
<p>My employer was recently acquired by a much larger company. In the process of sorting out all the legal details around our licenses for our development software, we have learned that the vendor of our IDE charges a "nominal" fee of 25% of the cost of a new license to transfer our existing licenses to the new corporate name.</p> <p>This struck me as absurd. I have not seen such a customer-unfriendly policy from any other vendor. Has anyone else seen this type of policy? Am I way off base in considering this unfriendly and abnormal?</p>
<p>Unfriendly? Yes. Abnormal? No. Its actually very common for tools with a hefty per-seat license fee to charge for a transfer after acquisition. I believe they do it because they can: the cost of transferring license is either overlooked during the M&amp;A due diligence or is considered inconsequential compared to the rest.</p> <p>The tool vendor justifies the fee because they now have one less potential customer, and the combined company will be paying a lower price per seat due to volume discounts.</p>
<p>I would have expected your new overlords to have been made aware of this as part of their takeover plans. Part of the process involves checking for exactly this kind of gotcha.</p> <p>Sounds like they chose to ignore the information or did not check it out.</p>
7,278
<p>Would you please help me in making a rollover effect using jquery, what i want to do is when someone hover over any of the menu items the text slide down and disappear and a picture slides from the top down to the center (e.g. you could see this effect here <a href="http://www.iviewcom.com/panda" rel="nofollow noreferrer">panda</a> as you can see the picture slide down from the top but the text does not slide down which is not what want).</p> <p>I know it can be easily done using flash but i don't want my menu in flash as that would be a bad practice. </p> <p>can you tell me what do i need to change in my menu HTML and what jquery functions should i use.</p> <p><strong>Thanks So much for your help</strong></p> <p>P.S. this my menu HTML and you can see my menu here </p> <pre><code>&lt;ul class="nav"&gt; &lt;li class="active first"&gt;&lt;a href="#" class="home"&gt;Home&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#" class="news"&gt;News&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#" class="offers"&gt;Special offers&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#" class="private"&gt;Private label&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#" class="locations"&gt;Locations&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#" class="about"&gt;About us&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#" class="jobs"&gt;Jobs&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#" class="contact"&gt;Contact us&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#" class="mm"&gt;Multimedia&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; </code></pre> <p>MENU: </p> <p><img src="https://i.stack.imgur.com/8ANuL.jpg" alt="alt text"></p>
<p>Instead of doing it for you, I'll offer some places to start looking.. </p> <p>Here is an example that could be easily modified to use 'rollover' instead of 'click': <a href="http://css-tricks.com/examples/MenuFader/" rel="noreferrer">http://css-tricks.com/examples/MenuFader/</a></p> <p>Details on how the above example was put together (the tutorial): <a href="http://css-tricks.com/learning-jquery-fading-menu-replacing-content/" rel="noreferrer">http://css-tricks.com/learning-jquery-fading-menu-replacing-content/</a></p> <p>I found this tutorial by searching on Google for "jquery effects examples": <a href="http://www.google.com/search?hl=en&amp;q=jquery+effects+examples&amp;btnG=Google+Search&amp;aq=f&amp;oq=" rel="noreferrer">http://www.google.com/search?hl=en&amp;q=jquery+effects+examples&amp;btnG=Google+Search&amp;aq=f&amp;oq=</a> and clicking on the first and second links.</p> <p>Good luck with your Jquery project. </p>
<p>First things first, you'll really want to give your independent anchor tags ids, as it will make accomplishing what you're wanting much easier.</p> <p>Look at the slideDown(), and slideToggle() functions, and it would basically require you setting up hidden divs and then on the mouseover event, you would slidetoggle your text out and the hidden image div in, and on mouseout do the opposite.</p> <p>Good luck, jQuery is a lot of fun to work with. Play with it and see what you can blow up!</p>
32,759
<p>This question has been asked in regards to 2005, but did not see anything with 2000. We have a new application that needs to run on 2005 or better but everything else we have is geared towards 2000. We could upgrade, but that is not within budget at this time. </p> <p>We were thinking we could run SQL Server 2008 Express on the same server as 2000 for the period of time it takes before we upgrade.</p> <p>Anyone do this? Have any issue? Ok to proceed?</p> <p>Thanks in advance</p>
<p>On our development server we have lots of versions installed eg: 2000, 2005 Express, 2005 standard, 2008 express we haven't had any major problems.</p> <p>You will need to install them as named instances when you go through the installation procedure, eg:</p> <p>MyServer\SQL2000 MyServer\SQL2005Express MyServer\SQL2005 etc</p> <p>I wouldn't advise running this many versions or instances on a production box but 2 instances until you upgrade your other applications to 2005 should be no problem.</p>
<p>I have a server that runs both sql2000 and 2005 and i have had not problems whatsoever - sql2005 is running a seperate instance.</p> <p>I see no problems with proceeding. The only issue i've had is 2005 express does not have DTS/SSIS so getting data in is cumbersome, but that has nothing to do with running both :-)</p>
36,709
<p>My question is pretty straightforward: You are an executable file that outputs "Access granted" or "Access denied" and evil persons try to understand your algorithm or patch your innards in order to make you say "Access granted" all the time. </p> <p>After this introduction, you might be heavily wondering what I am doing. Is he going to crack Diablo3 once it is out? I can pacify your worries, I am not one of those crackers. My goal are crackmes.</p> <p>Crackmes can be found on - for example - www.crackmes.de. A Crackme is a little executable that (most of the time) contains a little algorithm to verify a serial and output "Access granted" or "Access denied" depending on the serial. The goal is to make this executable output "Access granted" all the time. The methods you are allowed to use might be restricted by the author - no patching, no disassembling - or involve anything you can do with a binary, objdump and a hex editor. Cracking crackmes is one part of the fun, definately, however, as a programmer, I am wondering how you can create crackmes that are difficult.</p> <p>Basically, I think the crackme consists of two major parts: a certain serial verification and the surrounding code.</p> <p>Making the serial verification hard to track just using assembly is very possible, for example, I have the idea to take the serial as an input for a simulated microprocessor that must end up in a certain state in order to get the serial accepted. On the other hand, one might grow cheap and learn more about cryptographically strong ways to secure this part. Thus, making this hard enough to make the attacker try to patch the executable should not be tha t hard.</p> <p>However, the more difficult part is securing the binary. Let us assume a perfectly secure serial verification that cannot be reversed somehow (of course I know it can be reversed, in doubt, you rip parts out of the binary you try to crack and throw random serials at it until it accepts). How can we prevent an attacker from just overriding jumps in the binary in order to make our binary accept anything?</p> <p>I have been searching on this topic a bit, but most results on binary security, self verifying binaries and such things end up in articles that try to prevent attacks on an operating system using compromised binaries. by signing certain binaries and validate those signatures with the kernel.</p> <p>My thoughts currently consist of:</p> <ul> <li>checking explicit locations in the binary to be jumps.</li> <li>checksumming parts of the binary and compare checksums computed at runtime with those. </li> <li>have positive and negative runtime-checks for your functions in the code. With side-effects on the serial verification. :)</li> </ul> <p>Are you able to think of more ways to annoy a possible attacker longer? (of course, you cannot keep him away forever, somewhen, all checks will be broken, unless you managed to break a checksum-generator by being able to embed the correct checksum for a program in the program itself, hehe)</p>
<p>You're getting into "Anti-reversing techniques". And it's an art basically. Worse is that even if you stomp newbies, there are "anti-anti reversing plugins" for olly and IDA Pro that they can download and bypass much of your countermeasures.</p> <p>Counter measures include debugger detection by trap Debugger APIs, or detecting 'single stepping'. You can insert code that after detecting a debugger breakin, continues to function, but starts acting up at random times much later in the program. It's really a cat and mouse game and the crackers have a significant upper hand.</p> <p>Check out... <a href="http://www.openrce.org/reference_library/anti_reversing" rel="noreferrer">http://www.openrce.org/reference_library/anti_reversing</a> - Some of what's out there.</p> <p><a href="https://rads.stackoverflow.com/amzn/click/com/0764574817" rel="noreferrer" rel="nofollow noreferrer">http://www.amazon.com/Reversing-Secrets-Engineering-Eldad-Eilam/dp/0764574817/</a> - This book has a really good anti-reversing info and steps through the techniques. Great place to start if you're getting int reversing in general.</p>
<p>So, you want to write a program that accepts a key at the beginning and stores it in memory, subsequently retrieving it from disc. If it's the correct key, the software works. If it's the wrong key, the software crashes. The goal is that it's hard for pirates to generate a working key, and it's hard to patch the program to work with an unlicensed key.</p> <p>This can actually be achieved without special hardware. Consider our genetic code. It works based on the physics of this universe. We try to hack it, create drugs, etc., and we fail miserably, usually creating tons of undesirable side-effects, because we haven't yet fully reverse engineered the complex "world" in which the genetic "code" evolved to operate. Basically, if you're running everything on an common processor (a common "world"), which everyone has access to, then it's virtually impossible to write such a secure code, as demonstrated by current software being so easily cracked.</p> <p>To achieve security in software, you essentially would have to write your own sufficiently complex platform, which others would have to completely and thoroughly reverse engineer in order to modify the behavior of your code without unpredictable side effects. Once your platform is reverse engineered, however, you'd be back to square one.</p> <p>The catch is, your platform is probably going to run on common hardware, which makes your platform easier to reverse engineer, which in turn makes your code a bit easier to reverse engineer. Of course, that may just mean the bar is raised a bit for the level of complexity required of your platform to be sufficiently difficult to reverse engineer.</p> <p>What would a sufficiently complex software platform look like? For example, perhaps after every 6 addition operations, the 7th addition returns the result multiplied by PI divided by the square root of the log of the modulus 5 of the difference of the total number of subtract and multiply operations performed since system initialization. The platform would have to keep track of those numbers independently, as would the code itself, in order to decode correct results. So, your code would be written based on knowledge of the complex underlying behavior of a platform you engineered. Yes, it would eat processor cycles, but someone would have to reverse engineer that little surprise behavior and re-engineer it into any new code to have it behave properly. Furthermore, your own code would be difficult to change once written, because it would collapse into irreducible complexity, with each line depending on everything that happened prior. Of course, there would be much more complexity in a sufficiently secure platform, but the point is that someone would have reverse engineer your platform before they could reverse engineer and modify your code, without debilitating side-effects.</p>
12,517
<p>I'm involved in a project that is attempting to use the Eclipse RCP splash screen to gather user credentials, language, etc. If this screen loses focus, it is not available (under Windows at least) through the ALt-Tab functionality, and can only be found by minimizing all other windows and uncovering it. Any way of having this screen allow itself to be activated in this way? They're avoiding creating an intermediate screen, for reasons unknown at this point.</p>
<p>I think it might be time to examine those unknown reasons. Even eclipse doesn't use the splash screen in this way. If it needs to prompt for information, it opens a new dialog to ask for it.</p> <p>Good luck.</p> <p><strong>[Edit]</strong> I stand corrected. <a href="http://dev.eclipse.org/newslists/news.eclipse.platform.rcp/msg26519.html" rel="noreferrer">This thread</a> seems to have a solution to this. Good luck, I'm no SWT/RCP guru.</p>
<p>Create your own implementation of AbstractSplashHandler. When creating the shell, don't use the SWT.TOOL style. The shell will be accessible through the windows task bar.</p>
19,709
<p>Say if I had a table of books in a MySQL database and I wanted to search the 'title' field for keywords (input by the user in a search field); what's the best way of doing this in PHP? Is the MySQL <code>LIKE</code> command the most efficient way to search?</p>
<p>Yes, the most efficient way usually is searching in the database. To do that you have three alternatives:</p> <ul> <li><a href="http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html" rel="noreferrer">LIKE, ILIKE</a> to match exact substrings</li> <li><a href="http://dev.mysql.com/doc/refman/5.0/en/pattern-matching.html" rel="noreferrer">RLIKE</a> to match POSIX regexes</li> <li><a href="http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html" rel="noreferrer">FULLTEXT</a> indexes to match another three different kinds of search aimed at natural language processing</li> </ul> <p>So it depends on what will you be actually searching for to decide what would the best be. For book titles I'd offer a LIKE search for exact substring match, useful when people know the book they're looking for and also a FULLTEXT search to help find titles similar to a word or phrase. I'd give them different names on the interface of course, probably something like exact for the substring search and similar for the fulltext search.</p> <p>An example about fulltext: <a href="http://www.onlamp.com/pub/a/onlamp/2003/06/26/fulltext.html" rel="noreferrer">http://www.onlamp.com/pub/a/onlamp/2003/06/26/fulltext.html</a></p>
<p>You may also check soundex functions (soundex, sounds like) in mysql manual <a href="http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_soundex" rel="nofollow noreferrer">http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_soundex</a> Its functional to return these matches if for example strict checking (by LIKE or =) did not return any results.</p>
18,367
<p>I am pretty sure that sanding makes a lot of microplastics, so it would be nice to collect the dust, and melt it to got a blob of plastic again instead of millions of tiny particles. What is the best way for collecting it, do you use any dust extractor, or are there different techniques like sanding wet surfaces and filtering it from water?</p>
<p>I decided to collect the dust and treat both PLA and ABS with chemicals to completely break them down. That solves the issue and I won't rely on false hopes that somehow it does not end up in the environment.</p>
<p>As an environmental thing, micro plastics are an urgent problem for ocean life, it’s getting into the entire food chain. With that in mind dumping it down the drain would be the worst, city filtration systems can’t get the tiny bits of plastic before it drains into the ocean. Sanding outside is kind of bad. I sand stuff over a lined waste basket outside, which maybe catches 75% of the dust. Inside (or outside) with a vacuum running would be good, I think best would be a vacuum with disposable bags. Yes it is still micro plastics, but it ends up at the dump, where the soil is already poisoned, and hopefully nowhere near the ocean/waterways, and likely will stay there while it breaks down. PLA takes ~80 years, but ABS takes 1000 years.</p> <p>The idea of collecting the dust and fusing it sounds like it would be too much hassle to be feasible long term, it’s good, sustainable habits over years that add up.</p> <p>As a side note, card scraping is a nice way to smooth 3D prints, that doesn’t make fine dust.</p>
1,974
<p>I need help logging errors from T-SQL in SQL Server 2000. We need to log errors that we trap, but are having trouble getting the same information we would have had sitting in front of SQL Server Management Studio.</p> <p>I can get a message without any argument substitution like this:</p> <pre><code>SELECT MSG.description from master.dbo.sysmessages MSG INNER JOIN sys.syslanguages LANG ON MSG.msglangID=LANG.msglangid WHERE MSG.error=@err AND LANG.langid=@@LANGID </code></pre> <p>But I have not found any way of finding out the error arguments. I want to see:</p> <p>Constraint violation MYCONSTRAINT2 on table MYTABLE7</p> <p>not</p> <p>Constraint violation %s on table %s</p> <p>Googling has only turned up exotic schemes using DBCC OUTPUTBUFFER that require admin access and aren't appropriate for production code. How do I get an error message with argument replacement?</p>
<p>In .Net, retrieving error messages (and anything output from <em>print</em> or <em>raiserror</em>) from sql server is as simple as setting one property on your SqlConnection ( <em>.FireInfoMessageEventOnUserErrors = True</em>) and handling the connection's InfoMessage event. The data received by .Net matches what you get in the <em>Messages</em> window in the SQL Server Management Studio results grid.</p> <p>All the code goes in the function that handles the event, and you can abstract that so that all your connections point to the same method, so there's nothing else to change in the rest of the app aside from the two lines of code when you create new connections to set the property and event (<em>and you have that abstracted away so you only need to do it in one place, right?</em>)</p> <p>Here is a link to what I consider the <a href="http://www.sommarskog.se/error-handling-I.html" rel="nofollow noreferrer">definitive error guide for SQL Server</a>.<br> <a href="http://www.sommarskog.se/error-handling-I.html" rel="nofollow noreferrer">http://www.sommarskog.se/error-handling-I.html</a></p> <p>In certain circumstances SQL Server will continue processing even after an error. See the heading labeled <em><a href="http://www.sommarskog.se/error-handling-I.html#whathappens" rel="nofollow noreferrer">What Happens when an Error Occurs?</a></em> from the previous link.</p>
<p>Any chance you'll be upgrading to SQL2005 soon? If so, you could probably leverage their TRY/CATCH model to more easily accomplish what you're trying to do.</p> <p>The variables exposed in the catch can give you the object throwing the error, the line number, error message, severity, etc. From there, you can log it, send an email, etc.</p>
15,596
<p>In answering this question (<a href="https://stackoverflow.com/questions/352317/c-coding-question#352327">https://stackoverflow.com/questions/352317/c-coding-question#352327</a>), it got me wondering...</p> <p>Is there any danger in regarding a static class as being equivalent to a non-static class instatiation that implements the singleton pattern?</p>
<p>The only thing that seems immediately apparent to me is that a static class is basically just a collection of scoped functions (explicitly avoiding "methods" here) and a singleton is still something you can instantiate, even if you can only have 1. 1 > 0.</p> <p>You can pass a singleton as an argument to something that expects an object of a certain interface, you cannot pass a static class anywhere (except through some reflection trickery)</p>
<p>Not sure about C#, but in C++ a static Object will get initialized when it gets initialized, and you have no direct control over that (especially in multithreaded apps). So you need a function to call your object, not just call it directly (unless you want unportable code)</p>
45,877
<p>Ok, I'm developing an application that has been in pretty much continous development over the last 16 years, from C in DOS, through various flavours of C++ and now is largely based around C++ with MFC and StingRay GUIs and various other SDKs.</p> <p>While I use VS 2005 for the release builds, I still use MSVC 6 for much of the GUI building, simply because ClassWizard is so much quicker in this environment than the weak equivalent tools that followed. Note that I am using ClassWizard to automatically generate code for my own user defined types (see <a href="http://msdn.microsoft.com/en-us/library/57weza95%28VS.71%29.aspx" rel="nofollow noreferrer">Custom DDXs</a>) and I like to add a lot of member variables and methods in one go. Creating them one at a time as per later versions of Visual Studio for me is a big backward step. At the same time, working with multiple IDEs is also a pain.</p> <p>My question is in two parts;</p> <ol> <li><p>Is there any way of getting ClassWizard to work is VS 2005 or VS 2008? </p></li> <li><p>Is there any drop in replacement, or alternative IDE, that provides similar levels of productivty for old C++ hacks such as myself?</p></li> </ol>
<p>A follow up to those who are interested. ClassWizard may be re-introduced in VS2010, from Tarek Madkour [VC++ Team] </p> <blockquote> <p>'We are considering adding the Class Wizard back to VS10. We hope this will make DDX/DDV function creation more keyboard-centric just like it was in VC6. There are some schedule challenges that we will need to overcome to get the feature done, but I am optimistic that you will see it when we ship VS10.'</p> </blockquote> <p><a href="http://blogs.msdn.com/somasegar/archive/2008/11/21/c-enhancements-in-vs-2010.aspx" rel="nofollow noreferrer">Click here for the full discussion</a></p> <p>Edit: The <a href="http://download.microsoft.com/download/C/0/9/C0965791-049B-4200-9008-F07A783026F6/VisualStudio2010_ProductOverview.pdf" rel="nofollow noreferrer">release notes for VS2010</a> confirm that MFC Class Wizard is back. So contrary to popular belief, the guys at MS do listen to their users.</p> <blockquote> <p>Visual Studio 2010 provides a C++ IDE experience that includes the return of the MFC Class Wizard, the ability to view large source files through Source Outline, integrated quick searching to find information without the confusion of the current “Find In Files” method and an easily extensible IDE model through the new Managed Extensibility Framework (MEF).</p> </blockquote>
<p>I will suggest avoid code generation at all and use your favorite editor to manually create new code. If i understand correctly your are expert in this area and i sure you know that manually created code will be much cleaner and simpler then the generated one.<br> In additional the code generator is a nightmare for code reviews, it change zillions of places that should not be changed at all and it's really hard to concentrate to the meaningful changes.<br> IMHO. </p>
17,795
<p>I have the <a href="http://us.xyzprinting.com/us_en/Product/da-Vinci-1.0">XYZPrinting da-Vinci-1.0</a> with ABS filament. I am concerned about ventilation. If this is used inside, what safety precautions are necessary, which are recommended, and/or which are optional?</p>
<p>Yes... The issue with <em>all</em> 3d printing materials. Not just ABS, but worse with ABS is the fine air particulate and Ultra fine it creates during the 3d printing process. PLA is considered <em>safer</em> than ABS. But I fear people will use this as justification, it is like saying I only smoke one cig a day instead of two so I am safe and healthy. No it really should be taken seriously.</p> <p>There are a number of scientific papers and articles proving that this is an issue. Specifically that 3d printers release ultra fine particles into the air. Which can damage the lungs over time. I would STRONGLY advise not using a 3d printer around children, or at least putting it in the garage where you will not contaminate your homes air supply.</p> <p>I.E.</p> <ul> <li><a href="http://www.sciencedirect.com/science/article/pii/S1352231013005086" rel="nofollow noreferrer">http://www.sciencedirect.com/science/article/pii/S1352231013005086</a></li> <li><a href="http://built-envi.com/portfolio/ultrafine-particle-emissions-from-3d-printers/" rel="nofollow noreferrer">http://built-envi.com/portfolio/ultrafine-particle-emissions-from-3d-printers/</a></li> <li><a href="https://www.ncbi.nlm.nih.gov/pubmed/11139166" rel="nofollow noreferrer">https://www.ncbi.nlm.nih.gov/pubmed/11139166</a></li> <li><a href="http://www.3ders.org/articles/20160201-new-study-shows-health-hazards-of-3d-printing-suggests-pla-could-be-your-safest-bet.html" rel="nofollow noreferrer">http://www.3ders.org/articles/20160201-new-study-shows-health-hazards-of-3d-printing-suggests-pla-could-be-your-safest-bet.html</a></li> </ul> <p>Lot of these have some scary looking graphs. Note that I am being a bit sarcastic when I say "scary looking graphs" the take away is ABS has twice the Fine Partical emission as PLA. However should you be worried, is still up to debate. The idea is that FPE can maybe contribute to cancer or other illnesses. FPEs are thought to irritate the lungs. </p> <p>These graphs are of the ultra fine particle emissions. <a href="https://i.stack.imgur.com/kFA4o.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kFA4o.png" alt="enter image description here"></a></p> <p><a href="https://i.stack.imgur.com/tcg08.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tcg08.png" alt="enter image description here"></a></p> <p>as you can see PLA is MUCH safer in this regard.</p> <p>I cannot find the paper at the moment, but the recommendation is a full air cycle several times an hour. As someone that lives in a Cold state I personally just use PLA and am rolling the dice. </p> <p>There is <a href="https://3dprinting.stackexchange.com/questions/513/what-are-the-best-air-filtration-options-for-enclosures/3212#3212">another SO</a> where I cover my future plans for an air scrubber.</p> <p>I will note that other materials such as Polycarbonate should just be plain avoided.</p> <p>I also want to provide these links on WHY ultra fine particles are bad. In summary they really upset your lungs and are thought to cause lung cancer over time.</p> <p><a href="https://en.wikipedia.org/wiki/Ultrafine_particle" rel="nofollow noreferrer">Wikipedia on Ultra fine particulates.</a> <a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC1740105/pdf/v058p00211.pdf" rel="nofollow noreferrer">White paper on ultra fine particulates.</a></p>
<p>your fine at practical temperatures. source: <a href="https://en.wikipedia.org/wiki/Acrylonitrile_butadiene_styrene#Hazard_for_humans" rel="nofollow">https://en.wikipedia.org/wiki/Acrylonitrile_butadiene_styrene#Hazard_for_humans</a></p> <p>recommended would probably be set your controller to not go above 380c if your really worried. but it's not needed.</p>
328
<p>I just received my new Creality Ender 3. I was going through and checking/adjusting everything for alignment, and I noticed that when you &quot;auto home&quot; the print head, the nozzle stops off the front of the print bed by 5-10 mm.</p> <p>Is that normal?</p> <p>Is it perhaps by design to allow purging the nozzle without dumping on the bed?</p> <p>It doesn't appear that there is any way to adjust the Y stop switch without making modifications to it. It also didn't look like there was any easy way to move the bed either.</p>
<p>Yes, this is the &quot;intended&quot; behavior, as the home in relation to the physical limit position is not placed correctly about 7.5 mm into the bed in both X and Y.</p> <p>to correct this, please look at the <a href="https://3dprinting.stackexchange.com/questions/6399/recalibrating-home-position">Recalibrating Home-position</a> for the Ender3</p>
<p>It is intentional for the head to start slightly off the build plate. </p> <p>If it did start on the build plate you could crash the nozzle when the bed is not levelled. Note the level varies with temperature and build plate type. If you switch from PLA to ABS etc you should relevel the bed. </p> <p>Having just had the innaccurate z-end stop switch cause a deep gouge across my stock build plate, I strongly recommend getting an ABL (auto bed leveller). </p>
999
<p>I know that some big players have embraced it and are actually exposing some of their services in APP compliant way, already. However, I haven't found many other (smaller) players in this field. Do you know any web application/service that uses APP as its public API protocol? What is <em>your</em> own take on AtomPub? Do you have any practical experiences using it? What are its limitations and drawbacks? Do you prefer AtomPub as your REST style or do you have some other favourite one? And why?</p> <p>I know, these are many questions, not just one. The thing I'm interested here in is simple, though - how did the APP standard hit the market and particularly how does it seem with its adoption among web developers?</p>
<p>My own research so far:</p> <ul> <li><a href="http://codex.wordpress.org/AtomPub" rel="nofollow noreferrer">Wordpress</a> supports AtomPub as its API protocol since version 2.3 </li> <li><a href="http://code.google.com/apis/gdata/" rel="nofollow noreferrer">GData</a> is probably the biggest shot in the AtomPub field so far</li> <li><a href="http://habariproject.org" rel="nofollow noreferrer">Habari</a> - new promising blogging system promotes APP as one of its main features</li> <li><a href="http://www.codeplex.com/blogsvc" rel="nofollow noreferrer">BlogSvc.net</a> - an AtomPub server, blog engine for .NET platform, written in C#</li> <li><a href="http://jangle.org" rel="nofollow noreferrer">Jangle</a> - an open source project designed to facilitate API access to Library Systems</li> </ul>
<p>Last time I checked (2007 or so) Atompub was fairly complex to implement. While you can whip together something that emits valid Atom feeds during the lunch break, implementing AtomPub was a fairly big undertaking.</p> <p>That might have changed due to better libraries and tools but still it might be too complex to be implemented by smaller sides just because it's cool.</p> <p>And the lack of killer AtomPub client applications puts little or no pressure on server operators to offer an AtomPub interface.</p>
47,776
<p>I want to checkout, and then update as necessary, the <a href="http://code.djangoproject.com/" rel="nofollow noreferrer">Django Subversion trunk</a> on a Mac OS X Leopard 10.5.5 machine. </p> <p>I am only interested in having updated Django code on my Mac. I am not interested in contributing patches to the Django project. I do not need the Subversion history for the Django trunk.</p> <p>I plan to use Git as the DVCS/SCM for all of my personal projects.</p> <hr> <p><strong>What is the best practice for keeping my Mac updated with the latest Django trunk and why?</strong></p> <p>I am new to Git so understanding why you chose your option will be very helpful.</p> <p><p></p> <ol> <li><p>Use Subversion 1.4.4 installed on my Mac: svn co <a href="http://code.djangoproject.com/svn/django/trunk/" rel="nofollow noreferrer">http://code.djangoproject.com/svn/django/trunk/</a>. Essentially using Subversion to fetch Subversion repos and Git for my personal projects. </p></li> <li><p>Use Git SVN to fetch the <a href="http://code.djangoproject.com/svn/django/trunk/" rel="nofollow noreferrer">Django Subversion repo</a>. Instructions on how to do this for a Git newbie? </p></li> <li><p>Use Git to fetch a <a href="http://spinlock.ch/pub/git/?p=django/django.git;a=summary" rel="nofollow noreferrer">Git mirror of the Django repo</a>. I'm a little concerned that the mirror might go away in the future, but I'm willing to use it if it's the best option.</p></li> </ol>
<p>If you're not going to be making changes to the Django code, then there's no reason to import it into Git. Just use option 1.</p> <p>Using <code>git-svn</code> (either by running it yourself or by cloning somebody else's repository) is useful if you want to make local modifications to a project that uses Subversion (whether or not you send any of those modifications back to the project). But if you're not making any local modifications, then it's just needless complexity.</p>
<p>I agree with @cjm. If you just want a copy of the Django sources, use plain Subversion.</p> <p>My experience with git-svn is that it is most useful for people who prefer and are more familiar with Git who have to track a Subversion-repository, and not so useful to people who are know Subversion but are git-newbies wanting something better than Subversion. There are several limitations to git-svn stemming from the fact that Subversion has inferior merge tracking, and unless you have some substantial git experience those limitations will jump up and bite you at times.</p>
30,869
<p>I recently downloaded ndepend and ran an analysis on an open source project I participate in.</p> <p>I did not now where to look next - a bit of visual and information overload and it turned out I don't even know where to start.</p> <p>Can anyone suggest starting points?</p> <ul> <li>What information should I look for first?</li> <li>What points out problems in the code (in a BIG way)?</li> <li>What would the low hanging fruit that can immediately seen?</li> </ul>
<p>Scott Hanselman / Stuart Celarier / Patrick Cauldwell's <a href="http://www.hanselman.com/blog/EducatingProgrammersWithPlacematsNDependStaticAnalysisPoster.aspx" rel="noreferrer">poster</a> with ndepend metrics has some useful information on it. Rather than trying to break down all the heuristics being used I'd focus on only a few at a time starting with "zone of pain / zone of uselessness" and cyclomatic complexity. </p> <p>There is also a <a href="http://www.hanselman.com/blog/HanselminutesPodcast51StaticCodeAnalysisWithNDepend.aspx" rel="noreferrer">podcast</a> which covers some of the basics of the tool. </p> <p>Between that and running nDepend on a few different projects you may be able to start gathering useful data that you can make into insights.</p>
<p>Excellent pair of web casts (30 minute videos) where Patrick Smacchia and Filip Ekberg talk through some of the features of nDepend and how to use them:</p> <p><a href="http://codebetter.com/patricksmacchia/2012/10/31/two-screencasts-on-how-to-demystify-spaghetti-code/" rel="nofollow">http://codebetter.com/patricksmacchia/2012/10/31/two-screencasts-on-how-to-demystify-spaghetti-code/</a></p>
6,640
<p>I'm starting a new project; I wish to follow a DDD approach. We have talked to the business and achieved some insight into the domain in some detail (internet TV).</p> <p>The team is five strong and distributed. We have adopted the repository pattern for data-access. We are following a service-based approach overall; services are responsible for performing operations, and we will expose some operations via a REST API, and some via our own client applications.</p> <p>The people that do not have experience with ORMs (not that I have a massive amount either, at present) wish to model the entities without relationships between them, with the rationale that this forces the developers who use the Repositories to know precisely what effect they are having on the database. I am trying to point out that this will end up with a very chatty set of services, more code to maintain and test, and a domain model that fundamentally misses the point. I don't think this is a good approach, and neither do any of the people I've talked to about it.</p> <p>Their desire for the implementation of this approach is Linq2SQL under the repository-facade. This requires a second model, a mapping class/layer between it and the domain model, and much duplication in the repositories because it doesn't appear to be possible (that we've seen so far) to write a generic repository. It also isn't possible to map L2S entities that leverage inheritance (which means that EVERY entity must have properties for created-on, created-by, etc)</p> <p><strong>1st question:</strong> Can anyone offer me any advice about how to change their minds? I'm in the process of writing a side-project which uses NHibernate, which of course supports the DDD-approach well, on the basis that "Show me the code" is a powerful argument. </p> <p><strong>2nd question:</strong> What sorts of thing should I attempt to demonstrate in my NHibernate-using on-my-own-time side-project? I am new to it; one of their dislikes for NHibernate is the learning curve and the requirement for XML; my counter-argument is that it's a powerful tool, and Fluent NHibernate eliminates the need for XML. They still don't like it.</p>
<p>Have you looked at the concept of aggregate roots in DDD? Basically you only request aggregate roots out of repositories and the whole aggregate is loaded. The aggregate has everything it needs to do the required operation, so that would eliminate your concern of chattiness and would also address your team's concern of being explicit about what is loaded.</p> <p>In your side project, demonstrate a repository based on an aggregate root that loads the entire aggregate. This is fairly straight forward code and is very explicit in its intentions. Unfortunately you still have to ride the NHibernate learning curve, but there will be less "magic" going on if you use this approach.</p>
<p>It seems that your team are using the ORM just as a way of mapping the database to a set of concrete classes in order to make the code a bit nicer. If you think of creating a Domain Model instead and not just an abstracted database model then it would be apparent you should include relationships. How data is loaded behind the scenes is another matter.</p>
24,952
<p>Here is the situation: I have 2 pages.</p> <p>What I want is to have a number of text links(<code>&lt;a href=""&gt;</code>) on page 1 all directing to page 2, but I want each link to send a different value.</p> <p>On page 2 I want to show that value like this: </p> <blockquote> <p>Hello you clicked {value}</p> </blockquote> <p>Another point to take into account is that I can't use any php in this situation, just html.</p>
<p>Can you use any scripting? Something like Javascript. If you can, then pass the values along in the query string (just add a "?ValueName=Value") to the end of your links. Then on the target page retrieve the query string value. The following site shows how to parse it out: <a href="http://adamv.com/dev/javascript/querystring" rel="nofollow noreferrer">Parsing the Query String</a>.</p> <p>Here's the Javascript code you would need:</p> <pre><code>var qs = new Querystring(); var v1 = qs.get("ValueName") </code></pre> <p>From there you should be able to work with the passed value.</p>
<p>You might be able to accomplish this using HTML Anchors.</p> <p><a href="http://www.w3schools.com/HTML/html_links.asp" rel="nofollow noreferrer">http://www.w3schools.com/HTML/html_links.asp</a></p>
12,813
<p>What is the exact pixel size of one column when I used the columns attribute to determine a width of an ASP.NET textbox control?</p> <pre><code>&lt;asp:TextBox id="MyTextBox" runat="server" columns="10" /&gt; </code></pre>
<p>The Columns property is mapped to the size-attribute on the rendered input-tag. </p> <p>If size is 10, then the browser is supposed to render the input field in a size that would make 10 characters fit and be visible in the input field. But that only really works for monospace fonts, since in many other fonts "III" will not have the same pixel length as "MMM".</p> <p>So usually you are better of just using CSS-width as Ryan said.</p>
<p>@Ryan Smith: I used your suggestion and modified it to make it scalable to the user montior settings.</p> <pre><code>style="width: 100%" </code></pre>
47,176
<p>Env.: Vista SP1, SQL Server Express 2005</p> <p>I'm able to connect to my localhost SQL Server using SQL Server Management Studio, using Windows authentication and, to the best of my knowledge, all default parameters, including network protocol.</p> <p>Now I try to connect using sqlcmd.exe to no avail:</p> <pre><code>C:\Program Files\Microsoft SQL Server\90\Tools\Binn&gt;sqlcmd -S \\PCSERGEHOME\SQLE XPRESS HResult 0x57, Level 16, State 1 Named Pipes Provider: Invalid parameter(s) found [87]. Sqlcmd: Error: Microsoft SQL Native Client : An error has occurred while establi shing a connection to the server. When connecting to SQL Server 2005, this failu re may be caused by the fact that under the default settings SQL Server does not allow remote connections.. Sqlcmd: Error: Microsoft SQL Native Client : Login timeout expired. </code></pre> <p>I also tried to use -U PCSERGEHOME\Serge. I'm then prompted for my password but the result is the same.</p> <p>TIA for your help.</p>
<p>Lose the leading \\</p> <p>Actually, try .\XPRESS (period slash instance)</p>
<p>Try </p> <ul> <li>Disabling the firewall</li> <li>Using localhost instead</li> <li>Check the Server setup (in management studio) to make sure remote connections are enabled</li> <li>Check the settings in Surface Area configuration and make sure all the transports are enabled and remote connections are enabled</li> </ul>
36,412
<p>I have to do some work for college and my professor likes to torture us with Nassi-Shneiderman diagrams. </p> <p>Has anyone a good editor/graphcial tool to draw these? Requirements:</p> <ul> <li>cross platform (or able to run within wine)</li> <li>open source (or a least free to for private use)</li> </ul> <p>--</p> <p>After considering some editors, I ended up by using Strutorizer from <a href="http://structorizer.fisch.lu/" rel="nofollow noreferrer">http://structorizer.fisch.lu/</a></p> <p>It hasn't the best usability but it's good enough. And it's written in Java.</p>
<p>After considering some editors, I ended up by using Strutorizer from <a href="http://structorizer.fisch.lu/" rel="noreferrer">http://structorizer.fisch.lu/</a></p> <p>It hasn't the best usability but it's good enough. And it's written in Java.</p>
<p>Did you try 'Nessi'?</p> <p><a href="http://eii.ucv.cl/nessi/" rel="nofollow noreferrer">http://eii.ucv.cl/nessi/</a></p>
41,098
<p>Suppose I have one list:</p> <pre><code>IList&lt;int&gt; originalList = new List&lt;int&gt;(); originalList.add(1); originalList.add(5); originalList.add(10); </code></pre> <p>And another list... </p> <pre><code>IList&lt;int&gt; newList = new List&lt;int&gt;(); newList.add(1); newList.add(5); newList.add(7); newList.add(11); </code></pre> <p>How can I update originalList so that: </p> <ol> <li>If the int appears in newList, keep</li> <li>If the int does not appear in newList, remove</li> <li>Add any ints from newList into originalList that aren't there already</li> </ol> <p>Thus - making the contents of originalList:</p> <pre><code>{ 1, 5, 7, 11 } </code></pre> <p>The reason I'm asking is because I have an object with a collection of children. When the user updates this collection, instead of just deleting all children, then inserting their selections, I think it would be more efficient if I just acted on the children that were added or removed, rather than tearing down the whole collection, and inserting the newList children as if they are all new.</p> <p>EDIT - Sorry - I wrote a horrible title... I should have written 'least amount of code' instead of 'efficient'. I think that threw off alot of the answers I've gotten. They are all great... thank you!</p>
<pre><code>originalList = newList; </code></pre> <p>Or if you prefer them being distinct lists:</p> <pre><code>originalList = new List&lt;int&gt;(newList); </code></pre> <p>But, either way does what you want. By your rules, after updating, originalList will be identical to newList.</p> <p>UPDATE: I thank you all for the support of this answer, but after a closer reading of the question, I believe my other response (below) is the correct one.</p>
<p>My initial thought was that you could call originalList.AddRange(newList) and then remove the duplicates - but i'm not sure if that would be any more efficient than clearing the list and repopulating it.</p>
17,906
<p>I have a database of companies. My application receives data that references a company by name, but the name may not exactly match the value in the database. I need to match the incoming data to the company it refers to.</p> <p>For instance, my database might contain a company with name "A. B. Widgets &amp; Co Ltd." while my incoming data might reference "AB Widgets Limited", "A.B. Widgets and Co", or "A B Widgets".</p> <p>Some words in the company name (A B Widgets) are more important for matching than others (Co, Ltd, Inc, etc). It's important to avoid false matches.</p> <p>The number of companies is small enough that I can maintain a map of their names in memory, ie. I have the option of using Java rather than SQL to find the right name.</p> <p>How would you do this in Java?</p>
<p>You can use an <a href="http://en.wikipedia.org/wiki/Longest_common_subsequence_problem" rel="nofollow noreferrer">LCS</a> algorithm to score them.</p> <p>I do this in my <a href="http://github.com/dustin/photo" rel="nofollow noreferrer">photo album</a> to make it easy to email in photos and get them to fall into security categories properly.</p> <ul> <li><a href="http://github.com/dustin/photo/tree/master/src/java/net/spy/photo/util/LCS.java" rel="nofollow noreferrer">LCS code</a></li> <li><a href="http://github.com/dustin/photo/tree/master/src/java/net/spy/photo/mail/MailPoller.java#L255" rel="nofollow noreferrer">Example usage</a> (guessing a category based on what people entered)</li> </ul>
<p>Your database may suport the use of Regular Expressions (regex) - see below for some tutorials in Java - here's the link to the MySQL documentation (as an example):<br> <br> <a href="http://dev.mysql.com/doc/refman/5.0/en/regexp.html#operator_regexp" rel="nofollow noreferrer">http://dev.mysql.com/doc/refman/5.0/en/regexp.html#operator_regexp</a></p> <p>You would probably want to store in the database a fairly complex regular express statement for each company that encompassed the variations in spelling that you might anticipate - or the sub-elements of the company name that you would like to weight as being significant.</p> <p>You can also use the regex library in Java</p> <p>JDK 1.4.2<br> <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html" rel="nofollow noreferrer">http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html</a></p> <p>JDK 1.5.0<br> <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/regex/Matcher.html" rel="nofollow noreferrer">http://java.sun.com/j2se/1.5.0/docs/api/java/util/regex/Matcher.html</a></p> <p>Using Regular Expressions in Java<br> <a href="http://www.regular-expressions.info/java.html" rel="nofollow noreferrer">http://www.regular-expressions.info/java.html</a></p> <p>The Java Regex API Explained<br> <a href="http://www.sitepoint.com/article/java-regex-api-explained/" rel="nofollow noreferrer">http://www.sitepoint.com/article/java-regex-api-explained/</a></p> <p>You might also want to see if your database supports Soundex capabilities (for example, see the following link to MySQL)<br> <a href="http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_soundex" rel="nofollow noreferrer">http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_soundex</a></p>
41,764
<p>What delphi function asserts that an object is not nil?</p>
<p>Like knight_killer pointed out above, you use the <code>Assert()</code> function, asserting that <code>Assigned(obj)</code> is <code>true</code>. Of course, like in most compiled languages, assertions are <em>not</em> executed (or even included in the compiler output) unless you've specifically enabled them, so you should not rely on assertions for release mode builds.</p> <p>You can, of course, simply check against <code>nil</code>, a la <code>Assert(obj &lt;&gt; nil)</code>. However, <code>Assigned()</code> produces the exact same compiler output and has the added benefit that it works on pointers to class methods too (which are in reality a pair of pointers, one to the method, and the other one to the class instance), so using <code>Assigned()</code> is a good habit to pick up.</p>
<p>if Assigned(MyObject) then ...</p>
17,990
<p>With one worker, who can only perform one task at a time (but can switch between tasks instantly)</p> <p>Given a list of tasks,<br> -- defined as "n seconds, every m seconds" (eg, 5 seconds every 3600 seconds)</p> <p>How could I find the best starting times and count for each task?</p> <p>If every task were "1 second, every 60 seconds", each would have an unique starting second, and the count would be infinite (steady state).<br> If it was "1 second every 4 seconds" and "1 second every 3 seconds", the result would be: " 0, infinite and 3, 3 times" </p> <p>-- Hopefully simplest form </p> <p>If already I have a list of tasks, elaborated with "start second and number of times", what would a function that returns: {start, count} for an additional {n seconds every m seconds} task look like?</p> <p>-- (Slightly more complex form --<br> if instead of "n seconds every m seconds",<br> the tasks were defined as "n seconds every l..o seconds",<br> where I could pick a number m in the range l - o (but would have to commit to that m until the task was finished),<br> would that allow better worker utilization?<br> How would I choose the best 'm' ? </p>
<p>I think it depends on how you define 'best'. For instance, if you wanted tasks to run every m seconds "on average", there's an easy way to do it using the same sort of algorithm as the Bresenham method to draw lines (a task that's 'n seconds every m seconds' is much like scattering n vertical steps among m horizontal steps when drawing a line). Assign each task a counter and a step value (for "1 second every 3 seconds" the step would be 1/3). Then add the step to the counter every 'cycle' through. When a counter goes above zero that task should run (and subtract 1 from the counter). If you have several counters above zero, choose the largest one. That may give you a solution that is "good enough" for the slightly more complex form as well.</p> <p>The "1/4" and "1/3" example though sounds like you have a requirement to run the tasks "exactly" m seconds apart. Starting from a list and adding a new task to maximize the count is not a difficult search problem - but I do not think this is what you need. The A(1/4) B(1/4) C(1/2) example would give A B x x A B x x after adding A then B. Then C could not be added,</p> <p>I think there are obvious candidates for fitness functions - a table of n,m,start can have a fitness function which is the portion of the time where no more than one task is scheduled. GA/annealing would have a good chance of finding a steady state solution if one exists. But in cases like (1/4), (1/3) wwhere there appears to be no steady state solution, defining 'best' should also define your fitness function.</p>
<p>This type of problem is hard to solve, but relatively easy to optimize. Take a look at Simulated Annealing, Great Deluge, or Genetic Algorithms.</p>
26,479
<p>Is it possible to use the __unused attribute macro on Objective-C object method parameters? I've tried placing it in various positions around the parameter declaration but it either causes a compilation error or seems to be ignored (i.e., the compiler still generates unused parameter warnings when compiling with -Wall -Wextra).</p> <p>Has anyone been able to do use this? Is it just unsupported with Objective-C? For reference, I'm currently using Apple's build of GCC 4.0.1.</p>
<p>Okay, I found the answer... it appears to be a bug with the implementation of Apple's gcc 4.0. Using gcc 4.2 it works as expected and the proper placement is the following:</p> <pre><code>-(void)someMethod:(id) __unused someParam; </code></pre> <p>It's documented in the Objective-C release notes if anyone is interested: <a href="http://developer.apple.com/releasenotes/Cocoa/RN-ObjectiveC/index.html#//apple_ref/doc/uid/TP40004309-DontLinkElementID_6" rel="noreferrer">http://developer.apple.com/releasenotes/Cocoa/RN-ObjectiveC/index.html#//apple_ref/doc/uid/TP40004309-DontLinkElementID_6</a></p> <p>As a note, your answer will compile, Louis, but as I stated in my question it won't actually do anything or suppress the unused warning issued by the compiler.</p> <p>EDIT: I filed a bug report with apple for this <a href="http://rdar://6366051" rel="noreferrer">rdar://6366051</a>.</p>
<p>After fighting with the #pragma for a while, I discovered it's </p> <pre><code>+ (NSString*) runQuery:(id)query name:(NSString*)name options:(NSDictionary*)options { #pragma unused(name) ... } </code></pre>
36,266
<p>I've been given an early Christmas Present:<br> Permission to step out of the development cycle to <strong>reorganize</strong> and <strong>document</strong> our application.<br> I have complete freedom to restructure, refactor, and set up any amount of infrastructure I see fit.</p> <p>If you had <a href="http://en.wiktionary.org/wiki/carte_blanche" rel="nofollow noreferrer">carte blanche</a>, what's your "perfect" .NET development environment?</p> <p>About the application:<br> VB.NET client-server application. (Windows Forms front end, ASPX Webservices back end)<br> Currently using Visual Studio and SQL Server 2003 and... Visual SourceSafe.<br> <br></p> <p>I'd like to have some combination of: <br> * Better versioning. (leaning towards Subversion) <br> * Wiki or other system for bug tracking and documentation. (leaning towards <a href="http://Trac" rel="nofollow noreferrer">Trac</a> with Subversion) <br> * Simplified build process and daily builds (<a href="http://en.wikipedia.org/wiki/Visual_Build" rel="nofollow noreferrer">Visual Build</a>? <a href="http://en.wikipedia.org/wiki/CruiseControl" rel="nofollow noreferrer">CruiseControl.NET</a>?) <br> * Version control for the SQL Server database <br> * Upgrade to Visual Studio 2005 (or 2008)?</p> <p>... for a small team of 5 or so developers</p>
<p>I think you are all leaning in the right direction.</p> <p>Go with Visual Studio 2008. It's very stable with SP1, and you can target both version 2 and version 3 of the .NET framework.</p>
<p>We use SourceGear's Vault for version control and it works well for us as a small team.</p> <p>For project/bug/support tracking we use OnTime 2008 from AxoSoft. </p> <p>We also use ScrewTurn Wiki to document procedures and sample code/best practices.</p> <p>For our build process, we haven't fully automated into a daily process because we don't generally work that way. However, for the beta and release builds, I just use NAnt to do a complete build for me after I update version numbers manually (I do this for better looking version numbers for our support team).</p> <p>And definitely use Visual Studio 2008. The 2005 version really had a lot of issues on large VB projects (at least for us).</p>
43,299
<p>I have a really simple Java class that effectively decorates a Map with input validation, with the obvious void set() and String get() methods.</p> <p>I'd like to be able to effectively call those methods and handle return values and exceptions from outside the JVM, but still on the same machine <strong>Update: the caller I have in mind is not another JVM; thanks @Dave Ray</strong></p> <p>My implementation considerations are typical </p> <ul> <li>performance</li> <li>ease of implementation and maintenance (simplicity?)</li> <li>reliability</li> <li>flexibility (i.e. can I call from a remote machine, etc.)</li> </ul> <p>Is there a 'right way?' If not, what are my options, and what are the pro/cons for each?</p> <p>(Stuff people have actually done and can provide real-life feedback on would be great!)</p>
<p>Ok. Here's another try now that I know the client is not Java. Since you want out-of-process access and possibly remote machine access, I don't think JNI is what you want since that's strictly in-process (and a total hassle). Here are some other options:</p> <p><strong>Raw Sockets</strong> : just set up a listener socket in Java and accept connections. When you get a connection read the request and send back a response. Almost every language can use sockets so this is a pretty universal solution. However, you'll have to define your own marshalling scheme, parsing, etc.</p> <p><strong><a href="http://www.xmlrpc.com/" rel="nofollow noreferrer">XML-RPC</a></strong> : this isn't as hip these days, but it's simple and effective. There are <a href="http://ws.apache.org/xmlrpc/" rel="nofollow noreferrer">Java libraries</a> as well as libraries in most other languages.</p> <p><strong>CORBA</strong> : as mentioned above, CORBA is an option, but it's pretty complicated and experts are getting harder to come by.</p> <p><strong>Web Server</strong> : set up an embedded web server in your app and handle reqests. I've heard good things about <a href="http://www.mortbay.org/jetty/" rel="nofollow noreferrer">Jetty</a> or you can use the <a href="http://java.sun.com/javase/6/docs/jre/api/net/httpserver/spec/com/sun/net/httpserver/package-summary.html" rel="nofollow noreferrer">one provided with Java</a>. I've used the latter successfully to server KML files to Google Earth from a simulation written in Java. Most other languages have libraries for making HTTP requests. How you encode the data (XML, text, etc) is up to you.</p> <p><strong>Web Services</strong> : This would be more complicated I think, but you could use <a href="https://jax-ws.dev.java.net/" rel="nofollow noreferrer">JAX-WS</a> to expose you objects as web services. NetBeans has pretty nice tools for building Web Services, but this may be overkill.</p>
<p>JNI (Java Native Interface) allows access to java code from C or C++.</p>
48,150
<p>I've several textboxes. I would like to make the Enter button act as Tab. So that when I will be in one textbox, pressing Enter will move me to the next one. Could you please tell me how to implement this approach without adding any code inside textbox class (no override and so on if possible)?</p>
<p>Here is the code that I usually use. It must be on KeyDown event.</p> <pre><code>if (e.KeyData == Keys.Enter) { e.SuppressKeyPress = true; SelectNextControl(ActiveControl, true, true, true, true); } </code></pre> <p><strong>UPDATE</strong></p> <p>Other way is sending "TAB" key! And overriding the method make it so easier :)</p> <pre><code>protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { if (keyData == (Keys.Enter)) { SendKeys.Send("{TAB}"); } return base.ProcessCmdKey(ref msg, keyData); } </code></pre>
<p>Taking a wild guess:</p> <pre><code>// on enter event handler parentForm.GetNextControl().Focus(); </code></pre>
48,526
<p>Slashdot has a little widget that allows you to tweak your comment threshold to filter out down-modded comments. It will be in one place if you scroll to the top of the page, and as you scroll down, at some point, where its original home is about to scroll off the page, it will switch to fixed position, and stay on your screen. (To see an example, click <a href="http://news.slashdot.org/news/08/09/10/2257242.shtml" rel="nofollow noreferrer">here</a>.)</p> <p>My question is, how can I accomplish the same effect of having a menu be in one place when scrolled up, and switch to fixed position as the user scrolls down? I know this will involve a combination of CSS and javascript. I'm not necessarily looking for a full example of working code, but what steps will my code need to go through?</p>
<p>Okay, I figured it out. I will post it here in case it help anyone else. This solution uses prototype, and an internal library that gives me the registerEvent, getElementX and getElementY functions, which do what you would think.</p> <pre><code>var MenuManager = Class.create({ initialize: function initialize(menuElt) { this.menu = $(menuElt); this.homePosn = { x: getElementX(this.menu), y: getElementY(this.menu) }; registerEvent(document, 'scroll', this.handleScroll.bind(this)); this.handleScroll(); }, handleScroll: function handleScroll() { this.scrollOffset = document.viewport.getScrollOffsets().top; if (this.scrollOffset &gt; this.homePosn.y) { this.menu.style.position = 'fixed'; this.menu.style.top = 0; this.menu.style.left = this.homePosn.x; } else { this.menu.style.position = 'absolute'; this.menu.style.top = null; this.menu.style.left = null; } } }); </code></pre> <p>Just call the constructor with the id of your menu, and the class will take it from there.</p>
<p>For a demo but not based on the code above checkout:</p> <p><a href="https://stackoverflow.com/questions/2352896/fixing-tabs-to-the-top-of-the-page-but-underneath-the-header">fixed-floating-elements</a></p>
8,059
<p>I have two classes that each need an instance of each other to function. Ordinarily if an object needs another object to run, I like to pass it in the constructor. But I can't do that in this case, because one object has to be instantiated before the other, and so therefore the second object does not exist to be passed to the first object's constructor.</p> <p>I can resolve this by passing the first object to the second object's constructor, then calling a setter on the first object to pass the second object to it, but that seems a little clunky, and I'm wondering if there's a better way:</p> <pre><code>backend = new Backend(); panel = new Panel(backend); backend.setPanel(); </code></pre> <p>I've never put any study into MVC; I suppose I'm dealing with a model here (the Backend), and a view or a controller (the Panel). Any insights here I can gain from MVC?</p>
<p>It's time to take a look at MVC. :-) When you have a model-view-controller situation, the consensus is that the model shouldn't be aware of the view-controller (MVC often plays out as M-VC), but the view is invariably aware of the model.</p> <p>If the model needs to tell the view something, it does so by notifying its listeners, of which it may have multiples. Your view should be one of them.</p>
<pre><code>panel = new Panel(backend); </code></pre> <p>You do this in this routine something like</p> <pre><code> Public Sub Panel(ByVal BackEnd as BackEnd) Me.MyBackEnd = BackEnd BackEnd.MyPanel = Me End Sub </code></pre> <p>You don't need BackEnd.SetPanel</p> <p>It is better to use Proxies. A proxy links one object to another through raising a Event. The parent hands the child a proxy. When the child needs the parent it calls a GetRef method on the proxy. The proxy then raises a event which the parent uses to return itself to the proxy which then hands it to the child. </p> <p>The use of the Event/Delegate mechanism avoids any circular reference problems.</p> <p>So you have (assuming that the backend is the 'parent' here)</p> <pre><code> Public Sub Panel(ByVal BackEnd as BackEnd) Me.MyBackEnd = BackEnd.Proxy BackEnd.MyPanel = Me End Sub Public Property MyBackEnd() as BackEnd Set (ByVal Value as BackEnd) priBackEndProxy = BackEnd.Proxy End Set Get Return priBackEndProxy.GetRef End Get End Property </code></pre> <p>Here is a fuller discussion on the problem of circular references. Although it is focused on fixing it in Visual Basic 6.0.</p> <p><a href="https://stackoverflow.com/questions/264541/dynamic-memory-allocation-in-vb6">Dynamic Memory Allocation</a></p> <p>Also another solution is aggregating Panel and BackEnd into another object. This is common if both elements are UI Controls and need to behave in a coordinated manner.</p> <p>Finally as far as MVC goes I recommend using a a Model View Presenter approach instead.</p> <p>Basically you have your Form Implement a IPanelForm interface. It registers itself with a class called Panel which does all the UI logic. BackEnd should have events that Panel can hook into for when the model changes. Panel handles the event and updates the form through the IPanelForm interface.</p> <ol> <li><p>User clicks a button</p></li> <li><p>The form passes to Panel that the user clicked a button</p></li> <li><p>Panel handles the button and retrieves the data from the backend</p></li> <li><p>Panel formats the data.</p></li> <li><p>Panel uses IPanelForm Interface to show the data on the Form.</p></li> </ol>
48,584
<p>Is there a way to prematurely abort a transaction? Say, I have sent a command to the database which runs five minutes and after four, I want to abort it.</p> <p>Does JDBC define a way to send a "stop whatever you are doing on this connection" signal to the DB?</p>
<p>As mentioned by james, <a href="https://docs.oracle.com/javase/7/docs/api/java/sql/Statement.html#cancel()" rel="noreferrer">Statement.cancel()</a> will cancel the execution of a running Statement (select, update, etc). The JDBC docs specifically say that Statement.cancel() is safe to run from another thread and even suggests the usage of calling it in a timeout thread.</p> <p>After canceling the statement, you're still stuck with the job of rolling back the transaction. That is <em>not</em> documented as being safe to run from another thread. The <a href="https://docs.oracle.com/javase/7/docs/api/java/sql/Connection.html#rollback()" rel="noreferrer">Connection.rollback()</a> should happen in the main thread doing all the other JDBC calls. You can handle that after the canceled Statement.execute...() call completes with a JDBCException (due to the cancel).</p>
<p>No, you can't abort it using standard JDBC.</p> <p>You might try to check if your particular RDBMS define some extension to suppot it.</p>
37,837
<p>How do you schedule a task in Windows XP to run when you shutdown windows. Such that I want to run a simple command line program I wrote in c# everytime I shut down windows. There doesn't seem to be an option in scheduled tasks to perform this task when my computer shuts down.</p>
<p>Execute gpedit.msc (local Policies)</p> <p>Computer Configuration -> Windows settings -> Scripts -> Shutdown -> Properties -> Add</p>
<p>I had to also enable "Specify maximum wait time for group policy scripts" and "Display instructions in shutdown scripts as they run" to make it work for me as I explain <a href="https://stackoverflow.com/a/57472148/6329629">here</a>.</p>
12,712
<p>I have a Javascript that changes the host in links to match the current development/test server.</p> <p>Here's an example:</p> <pre><code>var ndomain = document.domain; var mydomain = 'www.foo.com'; var alink = document.getElementsByTagName('a'); for (var i = 0; i &lt; alink.length; i++) { if (alink[i].href.length &gt; 0){ if (alink[i].host.substr(0, mydomain.length) == mydomain){ alink[i].host = ndomain; } } } </code></pre> <p>This changes references to <em><a href="http://www.foo.com/page.html" rel="nofollow noreferrer">http://www.foo.com/page.html</a></em> to <em><a href="http://level1.test.foo.com/page.html" rel="nofollow noreferrer">http://level1.test.foo.com/page.html</a></em>.</p> <p>This works in every browser I've tested except Safari (Mac or Win). I've searched and searched for information as to why and the closest reason I've come up with is the "same-origin policy".</p> <p>Based upon my understanding of the same-origin policy, this should work because everything is under the <em>foo.com</em> domain. Could Safari be more strict in the fact that I'm going to a two level subdomain (e.g.<em>level1.test</em>)?</p> <p>Can someone advise as to why this process doesn't work in Safari or how I can get it to work in Safari?</p> <p>TIA!</p>
<p>There is no way that I know of to generate a .build file from an sln. There should be decent examples of .build files at <a href="http://nant.sourceforge.net" rel="nofollow noreferrer">http://nant.sourceforge.net</a>.</p> <p>That being said there are two ways to build a .sln file from NAnt.</p> <ul> <li>checkout nant.sourceforge.net or nant-contrib for built in or extended tasks to do this </li> <li>use an "exec" task to shell out msbuild.exe to build the sln.</li> </ul> <p>msbuild.exe has native support for sln files. You can build an sln file from the command line as follows:</p> <pre><code>msbuild.exe /p:Configuration=Debug /t:rebuild MySolution.sln </code></pre> <p>msbuild.exe can be found in your .NET Framework directory (e.g. C:\WINDOWS\Microsoft.NET\Framework\vX.XX.XXXX)</p>
<p>With nant you will have to use the EXEC command to shell out to msbuild for the solution files. </p> <p>Others have been experiencing the same issues.</p>
43,952
<p>All of a sudden I seem to be having a lot of issues with under extruding on my Ender 3. The bottom layer (of height 0.1&nbsp;mm) prints perfectly fine. This is done at 15&nbsp;mm/s speed. However, The moment the print moves to layer 2 and above (at the default speed of 60&nbsp;mm/s), I start hearing a lot of clicking noise on the extruder.</p> <p>So far I have tried the following</p> <ul> <li>Replace nozzle to eliminate clogs</li> <li>Cleaned the inside of the hot end assembly</li> <li>Calibrated extruder steps/mm</li> <li>Reduced the layer height from 0.3&nbsp;mm to 0.2&nbsp;mm</li> <li>Reduced feed rate to as low at 50&nbsp;%</li> <li>Cleaned the filament feeder assembly and verified that it is able to push the filament properly (Extruding when the print is not happening works just fine with no clicking)</li> </ul> <p>Even with all the above, the issue is still persisting. I am not what else could be causing this. </p> <p>I am printing with PLA at 200 C</p>
<p>Not allowed to comment, so have to answer:</p> <ol> <li><p>The temperature sensor is a thermally sensitive resistor. Unfortunately, the temperature is near the high limit of that sensor, and the manufacturing tolerances are very significant. That is why a temperature tower is important for each printer, as well as each filament. (I have 4 printers and each requires a different temperature for the same filament. My worst-case is out by 25 degrees! - it's the one I bought second-hand because the original purchaser couldn't get it to work. I could replace the NTC, but it is easier just to have settings to suit that printer.)</p></li> <li><p>Filament does change over time. Lots of theories about why, but the practical response is to tune settings to suit the filament. The alternative is to modify the filament (eg drying, adding oil to surface, etc.), but even with really old filament, I've found adjusting settings (in the slicer, like Cura) to be the most generally workable solution.</p></li> </ol> <p>Bottom line is to test, adjust settings and repeat until the system achieves the result you need. Treat most recommendations as serving suggestions, so use them as clues (but not rules) for the puzzles presented as 3D printing.</p>
<p>A temperature of 200&nbsp;&deg;C is fine. You probably have heat creep from a Bowden style extruder. The filament starts getting softer due to heat creeping up from the hot nozzle. Filament expands and clogs the tube causing gear clicking. Usually there is a heat sink at the the Bowden tube connection. You need to cool that immediately. Which is, to set your fan to 100&nbsp;% speed at layer height = 0. That should do the trick!</p>
1,580
<p>I'm interested to know the best / common way of storing a <code>this</code> pointer for use in the <code>WndProc</code>. I know of several approaches, but each as I understand it have their own drawbacks. My questions are:</p> <p>What different ways are there of producing this kind of code:</p> <pre><code>CWindow::WndProc(UINT msg, WPARAM wParam, LPARAM) { this-&gt;DoSomething(); } </code></pre> <p>I can think of Thunks, HashMaps, Thread Local Storage and the Window User Data struct.</p> <p>What are the pros / cons of each of these approaches?</p> <p>Points awarded for code examples and recommendations.</p> <p>This is purely for curiosities sake. After using MFC I've just been wondering how that works and then got to thinking about ATL etc.</p> <p><strong>Edit:</strong> What is the earliest place I can validly use the <code>HWND</code> in the window proc? It is documented as <code>WM_NCCREATE</code> - but if you actually experiment, that's <em>not</em> the first message to be sent to a window.</p> <p><strong>Edit:</strong> ATL uses a thunk for accessing the this pointer. MFC uses a hashtable lookup of <code>HWND</code>s.</p>
<p>In your constructor, call <strong>CreateWindowEx</strong> with "this" as the lpParam argument.</p> <p>Then, on WM_NCCREATE, call the following code:</p> <pre><code>SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR) ((CREATESTRUCT*)lParam)-&gt;lpCreateParams); SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER); </code></pre> <p>Then, at the top of your window procedure you could do the following:</p> <pre><code>MyWindowClass *wndptr = (MyWindowClass*) GetWindowLongPtr(hwnd, GWL_USERDATA); </code></pre> <p>Which allows you to do this:</p> <pre><code>wndptr-&gt;DoSomething(); </code></pre> <p>Of course, you could use the same technique to call something like your function above:</p> <pre><code>wndptr-&gt;WndProc(msg, wparam, lparam); </code></pre> <p>... which can then use its "this" pointer as expected.</p>
<p>In the past I've used the lpParam parameter of <code>CreateWindowEx</code>:</p> <blockquote> <p>lpParam [in, optional] Type: LPVOID</p> <p>Pointer to a value to be passed to the window through the CREATESTRUCT structure (lpCreateParams member) pointed to by the lParam param of the WM_CREATE message. This message is sent to the created window by this function before it returns. If an application calls CreateWindow to create a MDI client window, lpParam should point to a CLIENTCREATESTRUCT structure. If an MDI client window calls CreateWindow to create an MDI child window, lpParam should point to a MDICREATESTRUCT structure. lpParam may be NULL if no additional data is needed.</p> </blockquote> <p>The trick here is to have a <code>static</code> <code>std::map</code> of HWND to class instance pointers. Its possible that the <code>std::map::find</code> might be more performant than the <code>SetWindowLongPtr</code> method. Its certainly easier to write test code using this method though.</p> <p>Btw if you are using a win32 dialog then you'll need to use the <code>DialogBoxParam</code> function.</p>
14,340
<p>In ASP.NET MVC, I'm trying to create a link that includes an anchor tag (that is, directing the user to a page, and a specific section of the page).</p> <p>The URL I am trying to create should look like the following:</p> <pre><code>&lt;a href="/category/subcategory/1#section12"&gt;Title for a section on the page&lt;/a&gt; </code></pre> <p>My routing is set up with the standard: </p> <pre><code>routes.MapRoute("Default", "{controller}/{action}/{categoryid}"); </code></pre> <p>The action link syntax that I am using is: </p> <pre><code>&lt;%foreach (Category parent in ViewData.Model) { %&gt; &lt;h3&gt;&lt;%=parent.Name %&gt;&lt;/h3&gt; &lt;ul&gt; &lt;%foreach (Category child in parent.SubCategories) { %&gt; &lt;li&gt;&lt;%=Html.ActionLink&lt;CategoryController&gt;(x =&gt; x.Subcategory(parent.ID), child.Name) %&gt;&lt;/li&gt; &lt;%} %&gt; &lt;/ul&gt; &lt;%} %&gt; </code></pre> <p>My controller method is as follows:</p> <pre><code>public ActionResult Subcategory(int categoryID) { //return itemList return View(itemList); } </code></pre> <p>The above correctly returns a URL as follows:</p> <pre><code>&lt;a href="/category/subcategory/1"&gt;Title for a section on the page&lt;/a&gt; </code></pre> <p>I can't figure out how to add the <strong>#section12</strong> part. The "section" word is just the convention I am using to break up the page sections, and the 12 is the ID of the subcategory, i.e., child.ID.</p> <p>How can I do this?</p>
<p>I would probably build the link manually, like this:</p> <pre><code>&lt;a href="&lt;%=Url.Action("Subcategory", "Category", new { categoryID = parent.ID }) %&gt;#section12"&gt;link text&lt;/a&gt; </code></pre>
<p>My solution will work if you apply the ActionFilter to the Subcategory action method, as long as you always want to redirect the user to the same bookmark:</p> <p><a href="http://spikehd.blogspot.com/2012/01/mvc3-redirect-action-to-html-bookmark.html" rel="nofollow">http://spikehd.blogspot.com/2012/01/mvc3-redirect-action-to-html-bookmark.html</a></p> <p>It modifies the HTML buffer and outputs a small piece of javascript to instruct the browser to append the bookmark.</p> <p>You could modify the javascript to manually scroll, instead of using a bookmark in the URL, of course!</p> <p>Hope it helps :)</p>
34,594
<p>In Team Build 2008, the Drop Location for a build is no longer specified in the .proj file, and instead is stored in the database and maintained in the GUI tool.</p> <p>The GUI tool only accepts a network path as a drop location (i.e. \\server\share) and will not accept a local path.</p> <p>Our build server also hosts the dropped files, so it seems that forcing a file copy operation to go through the network share introduces a lot of lag time when copying a large number of files. I would like to override this feature so that I can specify a local directory for drop location, but I can't figure out how.</p>
<p>The connections only seem to stay in the pool and not being reused in case you get an exception, just like the example. If you increase the timeout the connection will be reused.</p> <p>A workaround to this problem is to clear the connection pool in case you get an exception like this:</p> <pre><code>using (SqlConnection con = new SqlConnection(connectionString)) { con.Open(); try { Console.WriteLine("Server is {0}", con.ServerVersion); Console.WriteLine("Clr is {0}", Environment.Version); for (int i = 0; i &lt; 5; i++) { using (SqlCommand cmd = con.CreateCommand()) { cmd.CommandText = "insert into TXTEST values ( " + i + " )"; cmd.ExecuteNonQuery(); } Console.WriteLine("Row inserted"); } Thread.Sleep(TimeSpan.FromSeconds(1)); } catch { SqlConnection.ClearPool(con); throw; } } </code></pre> <p>In most cases the transaction will complete within the timeout and everything will be fine and dandy. When the transaction <strong>actually do</strong> timeout you clear the pool in order to clean up the dirty connections that won't get reused. This will of course affect other connections in the pool that isn't affected by this problem.</p> <p>This is a ugly workaround but it seems to work.</p>
<p>For what it's worth, this issue was fixed in .Net 4.0.</p>
40,573
<p>Lot of googling did not help me! Are there any good dictionary web based available? </p> <p>I am looking for a site which can send me the meaning of words if we pass the word through query string!</p>
<p>I found you a <a href="http://words.bighugelabs.com/" rel="noreferrer">Big Huge Thesaurus</a> with a web API, and a dictionary at <a href="http://services.aonaware.com/DictService/" rel="noreferrer">Aonaware</a> that looks like it uses SOAP</p>
<p>There also exists the <a href="http://dict.org" rel="nofollow noreferrer">dict</a> protocol which has been around for a long time. One of the things I like about dict is the command-line query program that is available.</p> <p>I have also created a <a href="http://hewgill.com/dict/" rel="nofollow noreferrer">Wiktionary to dict gateway</a> which provides access to the Wiktionary database through the dict protocol.</p>
10,371
<p>I run php 5.2.6 as a cgi under lighttpd 1.4 and for some reason it's always running as root. All php-cgi processes in are owned by root and all files written to the file system are owned by root. </p> <p>I've tried setting the user in lighttpd as non privileged, and confirmed, it's running right it's just php that runs as root. </p> <p>How would I set php-cgi to run as a safer user?</p>
<ol> <li><p>Ensure :</p> <pre><code>server.username = "nonprivuser" server.groupname = "nonprivgroup" </code></pre></li> <li><p>stop lighttpd. </p></li> <li>check for existing php processes and kill them. </li> <li>start lighttpd</li> <li>check php processes are running as non priv</li> </ol> <p>if php is still running as root, then you possibly have a SETUID script somewhere loading them ( you really shouldn't, but its feasible )</p> <p>if this is the case, check the file 'bin-path' refers to doesn't have anything funky on it.</p>
<p>It is possible that you have a fastcgi process that was started on the server as root. If this is the case, then the fastcgi process will continue to run php processes called from lighttpd.</p> <p>I suggest killing the fastcgi processes on your server and restarting lighttpd.</p> <p>You might also want to take a look at any startup scripts that might launch the fastcgi daemon.</p>
20,867
<p>Is there such a thing as having the most prefered design pattern for building applications in TDD or the iterative mode?</p>
<p>I think the question could be rewritten so it makes more sense in these words:</p> <p><em>"Which architectural patterns and strategies are useful in order to achieve flexibility when using a Test-Driven and incremental development strategy?"</em></p> <p>My answer would be: patterns that help you decouple your clases and components, like:</p> <ul> <li><p><a href="http://martinfowler.com/articles/injection.html" rel="noreferrer">Inversion of Control and Dependency Injection</a> - Help you keep the dependencies between your classes and components detached from specific implementations that are resolved until runtime (or startup time) allowing both using stubs for not-yet implemented functionality and for unit tests.</p></li> <li><p><a href="http://en.wikipedia.org/wiki/Facade_pattern" rel="noreferrer">Facades</a> - Helps you isolate components providing well defined interfaces for interaction between them, reducing coupling.</p></li> <li><p>Factories and other <a href="http://en.wikipedia.org/wiki/Creational_pattern" rel="noreferrer">creational patterns</a> - They give you flexibility in the sections of your code responsible for instantiating objects.</p></li> </ul> <p>Also remember that one of the mantras of incremental and iterative development is <a href="http://www.artima.com/intv/simplestP.html" rel="noreferrer">'Do the simplest thing that could possibly work'</a>. Don't over-engineer.</p> <p>Does it makes sense according with what you asked?</p>
<p>Use a dynamic language like Python or Ruby to develop: You don't have to fight with many of the problems other languages have which are the reason for "design patterns" in the first place.</p> <p>Dynamic languages in combination with automated testing will give results really quick so you know which direction to take. If you realize then that you should use a static language for performance reasons or whatever you can translate the dynamic software you have already built.</p>
14,575
<p>I want to select a bunch of <code>span</code>s in a <code>div</code> whose CSS contains a particular background color. How do I achieve this?</p>
<p>if i understand the question correctly, the selector <code>[attribute=value]</code> <strong>will not work</strong> because <code>&lt;span&gt;</code> does not contain an attribute "background-color". you can test that out quickly to confirm it won't match anything:</p> <pre><code>$('#someDiv span[background-color]').size(); // returns 0 </code></pre> <p>given:</p> <pre><code>.one, .two { background-color: black; } .three { background-color: red; } </code></pre> <p>here's a snippet that <strong>will work</strong>:</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-js lang-js prettyprint-override"><code>$('div#someDiv span').filter(function() { var match = 'rgb(0, 0, 0)'; // match background-color: black /* true = keep this element in our wrapped set false = remove this element from our wrapped set */ return ( $(this).css('background-color') == match ); }).css('background-color', 'green'); // change background color of all black spans</code></pre> <pre class="snippet-code-css lang-css prettyprint-override"><code>.one, .two { background-color: black; } .three { background-color: red; }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.0/jquery.min.js"&gt;&lt;/script&gt; &lt;div id="someDiv"&gt; &lt;span class="one"&gt;test one&lt;/span&gt; &lt;span class="two"&gt;test two&lt;/span&gt; &lt;span class="three"&gt;test three&lt;/span&gt; &lt;/div&gt;</code></pre> </div> </div> </p>
<p>Use the attribute selector [attribute=value] to look for a certain attribute value.</p> <pre><code>#id_of_the_div span[background-color=rgb(255,255,255)] </code></pre>
35,735
<p>Looking for some direction here as I'm running into some migration problems.</p> <p>We have a legacy application. The 'infrastructure' is running just fine. Business logic and data access layers written in VB calling SQL Server for the database.</p> <p>I have a LOT of experience writing Winforms (desktop) application and have had no problems. However, the last time I wrote any ASP.NET stuff was in 1.1 (VS.NET 2003).</p> <p>Among other things, for ASP.NET 2.0 and up, the Grid layout is gone. It's not just a simple case of dropping controls on a form, aligning them, ordering them and working with the code-behind anymore.</p> <p>The new web-based application is starting out pretty simple. Just a common header (already made a user control for that) and footer with your typical CRUD functions in the middle. </p> <p>I tried being 'intuative' in using a master page with content place holders but I couldn't get the placeholders to "grow", to say nothing of not being able to put a text box where I wanted one. Oh, I found the option in VS2008 to allow absolute positioning but it only worked for SOME controls - others I had to manually edit the asp tags.</p> <p>Then I saw examples using div's and tried to implement them but I ended up with results that had objects writing on top of each other. The online help wasn't helpful to say the least.</p> <p>Does anyone know of a good book, website or tutorial that can give the basics of what I'm looking for? In practice, I'm looking to make simple pages where some objects may have to push others gurther down the y-axis (as in, several comments being made and that section would push the section listing the 'attachments' down further). I have no trouble when it comes to all the other aspects of this application. It just appears that my webforms skills are about 3-4 years out of date.</p> <p>This isn't going to be some fancy flash/silverlight application - just simple 'data maintenance' to get rid of some ugly and bug-prone processes involving reading common mailboxes and decoding Word files. The new goal is to have a nice weborm with proper validation.</p> <p>I guess what I'm looking for is a "Webforms for Winforms programmers" book or site.</p> <p>Help!</p> <p>Thanks in advance.</p>
<p>The best advice I've heard on learning to use html/css layout goes something like this:</p> <p>When building a new page, don't try to get all fancy up front. Start by building a very basic, text-only page. It should look like something from 1996- that brief period where everyone had just discovered the web but had not yet started using the <code>table</code> tag for layout- only no comic sans font. Don't use images at this point, unless the image is genuinely a part of the information being conveyed (as opposed to the window dressing to make it look pretty: you can add those later). There will likely be an <code>h1</code> at the top of the page, and give each sub heading an appropriate <code>hN</code>, but at this point there shouldn't be any layout information in the page at all. The only place you'll have a <code>table</code> tag is if you genuinely have tabular data to show. If it helps you write this code then you can wrap everything in old-fashioned <code>&lt;center&gt;</code> tags for now- just don't forget to remove them later.</p> <p>Now let's start tweaking the markup a little. Use things like <code>ul</code> (unordered list) for your <em>list</em> of navigation links and <code>label</code>/<code>legend</code> to identify and group your form areas. The general idea here is to have each element on the page encased in the most appropriate html tag, and to use the full set of available tags- each for it's designated purpose.</p> <p>At this point you have a page that is ideally suited for a screen reader or search engine. By building this page first, you have made SEO and accessibility compliance easy on yourself. Of course those aren't the only requirements, so we're not done yet.</p> <p>Now you need to identify the different sections of your page, from both the layout <em>and</em> logical perspectives. The page should largely already be divided logically, but you may find a few places where the normal tags don't cut it. You'll also want to group certain elements for layout reasons. Encase each of these areas with a <code>div</code> tag, and give the tag a class name that refers to the purpose for the tag: the group your are creating. This is just another case of using the a tag (the "division" tag) for it's intended purpose. Also, since elements can have more than one class, you may want to think about also grouping your classes logically. For example, you might want to have a separate class that distinguishes the site template from the rest of the page. </p> <p>By and large this should not have changed the appearance of the page, but now you have something where it should be very easy to start adding styles. At this point you can now start adding images and layout. The goal here, though, is to change the actual markup as little as possible. If you can manage it only add ids and classes, though you will likely need to add an additional span or div that you had not identified earlier, and sometimes you'll need an extra block level element to force a compatible layout across browsers.</p> <p>If things are done correctly, the result is a page that not only looks good, but is also easier to work with when testing across browsers, will naturally degrade well when a style or javascript feature isn't supported, and scores well for SEO and accessibility. This also makes it easier to have a developer build a simple page that provides a certain level of functionality, which they can this pass off to a separate designer to make it look good.</p>
<p>By the sounds of it, you're looking for a crash course in HTML ?</p> <p>the "Design Canvas" of an ASP.NET aspx Page &amp; ascx Control is just HTML tag markup.</p> <p>If you've no web design experience, I'd recommend starting somewhere like</p> <p><a href="http://www.w3schools.com/html/default.asp" rel="nofollow noreferrer">W3Schools</a></p>
35,070
<p>I will soon be working on AJAX driven web pages that have a lot of content generated from a Web Service (WCF).</p> <p>I've tested this sort of thing in the past (and found it easy) but not with this level of dynamic content.</p> <p>I'm developing in .NET 3.5 using Visual Studio 2008. I envisage this testing in:</p> <ol> <li>TestDriven.NET</li> <li>MBUnit (this is not <strong>Unit</strong> testing though)</li> <li>Some sort of automation tool to control browsers (Maybe Selenium, though it might be SWEA or Watin. I'm thinking IE,Firefox, and likely Opera and Safari.)</li> </ol> <p>In the past I've used delays when testing the browser. I don't particularly like doing that and it wastes time.</p> <p><strong>What experience and practice is there for doing things better</strong>, than using waits. Maybe introducing callbacks and a functional style of programming to run the tests in?</p> <hr> <p><strong>Notes 1. More detail after reviewing first 3 replies.</strong></p> <p>1) Thanks Alan, Eran and marxidad, your replies have set me on the track to getting my answer, hopefully without too much time spent.</p> <p>2) Another detail, I'm using <strong>jQuery</strong> to run the Ajax, so this is not built in Asp.NET AJAX.</p> <p>3) I found an article which <strong>illustrates the situation</strong> nicely. It's from <a href="http://adamesterline.com/2007/04/23/watin-watir-and-selenium-reviewed/" rel="nofollow noreferrer" title="WatiN, Watir, Selenium review">http://adamesterline.com/2007/04/23/watin-watir-and-selenium-reviewed/</a></p> <p>3.1) <strong>Selenium</strong> Sample (This and the next, WatiN, code sample do not show up in the original web page (on either IE or Firefox) so I've extracted them and listed them here.)</p> <pre><code>public void MinAndMaxPriceRestoredWhenOpenedAfterUsingBackButton(){ OpenBrowserTo("welcome/index.rails"); bot.Click("priceDT"); WaitForText("Price Range"); WaitForText("515 N. County Road"); bot.Select("MaxDropDownList", "$5,000,000"); WaitForText("Prewar 8 Off Fifth Avenue"); bot.Select("MinDropDownList", "$2,000,000"); WaitForText("of 86"); bot.Click("link=Prewar 8 Off Fifth Avenue"); WaitForText("Rarely available triple mint restoration"); bot.GoBack(); Thread.Sleep(20000); bot.Click("priceDT"); WaitForText("Price Range"); Assert.AreEqual("$5,000,000", bot.GetSelectedLabel("MaxDropDownList")); Assert.AreEqual("$2,000,000", bot.GetSelectedLabel("MinDropDownList"));} </code></pre> <p>3.2) <strong>WatiN</strong> sample</p> <pre><code>public void MinAndMaxPriceRestoredWhenOpenAfterUsingBackButton(){ OpenBrowserTo("welcome/index.rails"); ClickLink("Price"); SelectMaxPrice("$5,000,000"); SelectMinPrice("$2,000,000"); ClickLink("Prewar 8 Off Fifth Avenue"); GoBack(); ClickLink("Price"); Assert.AreEqual("$5,000,000", SelectedMaxPrice()); Assert.AreEqual("$2,000,000", SelectedMinPrice());} </code></pre> <p>3.3) If you look at these, apparently equivalent, samples you can see that the WatiN sample has <strong>abstracted away the waits</strong>.</p> <p>3.4) However it may be that WatiN needs <strong>additional support</strong> for values changed by Ajax calls as noted in <a href="http://watinandmore.blogspot.com/2008/01/using-watin-to-test-select-lists-in.html" rel="nofollow noreferrer" title="Using WatiN with Ajax">http://watinandmore.blogspot.com/2008/01/using-watin-to-test-select-lists-in.html</a>. In that article the page is given an additional field which can be used to synthesize a changed event, like so:</p> <pre><code>// Wait until the value of the watintoken attribute is changed ie.SelectList("countries").WaitUntil(!Find.By("watintoken",watintoken)); </code></pre> <p>4) Now what I'm after is a way to do something <strong>like what we see in the WatiN code without that synthesized event</strong>. It could be a way to directly hook into events, like changed events. I wouldn't have problems with callbacks either though that could change the way tests are coded. I also think we'll see alternate ways of writing tests as the implications of new features in C# 3, VB 9 and F# start to sink in (and wouldn't mind exploring that).</p> <p>5) marxidad, my source didn't have a sample from WebAii so I haven't got any comments on this, interesting looking, tool.</p> <hr> <p><strong>Notes 2. 2008-09-29. After some feedback independent of this page.</strong></p> <p>5) I attempted to get more complete source for the WatiN sample code above. Unfortunately it's no longer available, the link is dead. When doing that I noticed talk of a DSL, presumably a model that maps between the web page and the automation tool. I found no details on that.</p> <p>6) For the WebAii it was suggested code like this (it's not tested) would be used:</p> <pre><code>public void MinAndMaxPriceRestoredWhenOpenAfterUsingBackButton(){ ActiveBrowser.NavigateTo("welcome/index.rails"); Find.ByContent&lt;HtmlAnchor&gt;("Price").Click(); HtmlSelect maxPrice = Find.ById&lt;HtmlSelect&gt;("MaxDropDownList"); HtmlSelect minPrice = Find.ById&lt;HtmlSelect&gt;("MinDropDownList"); maxPrice.SelectByText("$5,000,000"); minPrice.SelectByText("$2,000,000"); Find.ByContent&lt;HtmlAnchor&gt;("Prewar 8 Off Fifth Avenue").Click(); ActiveBrowser.GoBack(); Find.ByContent&lt;HtmlAnchor&gt;("Price").Click(); maxPrice.AssertSelect().SelectedText("$5,000,000"); minPrice.AssertSelect().SelectedText("$2,000,000");} </code></pre> <p>6) From the code I can clearly avoid waits and delays, with some of the frameworks, but I will need to spend more time to see whether WatiN is right for me. </p>
<p>Most automation frameworks have some synchronizationfunctions built in. Selenium is no exception, and includes functionality like waitForText, waitForElementPresent,etc.</p> <p>I just realized that you mentioned "waits" above, which I interpreted as Sleeps (which aren't good in automation). Let me know if I misinterpreted, and I can talk more about wait* functions or alternatives.</p>
<p><a href="http://www.artoftest.com/Resources/WebAii/Documentation/topicsindex.aspx?topic=ajaxsupport" rel="nofollow noreferrer">WebAii</a> has a <strong>WaitForElement(s)</strong> method that lets you specify the parameters of the elements to wait for.</p>
16,586
<p>Is there any good reason to use C-strings in C++ nowadays? My textbook uses them in examples at some points, and I really feel like it would be easier just to use a std::string.</p>
<p>The only reasons I've had to use them is when interfacing with 3rd party libraries that use C style strings. There might also be esoteric situations where you would use C style strings for performance reasons, but more often than not, using methods on C++ strings is probably faster due to inlining and specialization, etc.</p> <p>You can use the <a href="http://en.cppreference.com/w/cpp/string/basic_string/c_str" rel="nofollow noreferrer"><code>c_str()</code></a> method in many cases when working with those sort of APIs, but you should be aware that the char * returned is const, and you should not modify the string via that pointer. In those sort of situations, you can still use a vector&lt;char&gt; instead, and at least get the benefit of easier memory management.</p>
<p>The usual reason to do it is that you enjoy writing buffer overflows in your string handling. Counted strings are so superior to terminated strings it's hard to see why the C designers ever used terminated strings. It was a bad decision then; it's a bad decision now.</p>
13,460
<p>What's are the best practices for versioning web sites?</p> <ul> <li>Which revision control systems are well suited for such a job?</li> <li>What special-purpose tools exist?</li> <li>What other questions should I be asking?</li> </ul>
<p>Firstly you can - and should - use a revision control system, most will handle binary files although unlike text files you can't merge two different set of changes so you may want to set the system up to lock these files whilst they are being changed (assuming that that's not the default mode of operation for you rcs in the first place).</p> <p>Where things get a bit more interesting for Websites is managing those files that are required for the site but don't actually form part of the site - the most obvious example being something like .psd files from which web graphics are produced but which don't get deployed.</p> <p>We therefore have a tree for each site which has two folders: assets and site. Assets are things that aren't in the site, and site is - well the site. </p> <p>What you have to watch with this is that designers tend to have their own "systems" for "versioning" graphic files (count the layers in the PSD). You don't need necessarily to stop them doing this but you do need to ensure that they commit each change too.</p> <p>Other questions? </p> <p>Deployment. We're still working on this one (-: But we're getting better (I'm happier now with what we do!)</p> <p>Murph</p>
<p>I use <a href="http://svnbook.red-bean.com/" rel="nofollow noreferrer">Subversion</a>. As an easy way to reference the website version (production, testing, development), I use a very simple trick. I add the revision number somewhere on the site (eg in the admin footer). Something like this:</p> <pre><code>&lt;?php print("$Revision: 1 $"); ?&gt; </code></pre> <p>Each time you checkout (development versions) or export (for production), the "1" will be replaced by the revision number in your repository, thus making it easy to setup the customer version on your test server, for example.</p>
5,781
<p>I’m building a system that generates “work items” that are queued up for back-end processing. I recently completed a system that had the same requirements and came up with an architecture that I don’t feel is optimal and was hoping for some advice for this new system.</p> <p>Work items are queued up centrally and need to be processed in an essentially FIFO order. If this were the only requirement, then I would probably favor an MSMQ or SQL Server Service Broker solution. However, in reality, I need to select work items in a modified FIFO order. A work item has several attributes, and they need to be assigned in FIFO order where certain combinations of attribute values exist.</p> <p>As an example, a work item may have the following attributes: Office, Priority, Group Number and Sequence Number (within group). When multiple items are queued for the same Group Number, they are guaranteed to be queued in Sequence Number order and will have the same priority. </p> <p>There are several back-end processes (currently implemented as Windows Services) that pull work times in modified FIFO order given certain configuration parameters for the given service. The service running Washington, DC is configured to process only work items for DC, while the service in NY may be configured to process both NY and DC items (mainly to increase overall throughput). In addition to this type of selectivity, higher priority items should be processed first, and items that contain the same “Group Number” must be processed in Sequence Number order. So if the NY service is working on a DC item in group 100 with sequence 1, I don’t want the DC service to pull off DC item in group 100 sequence 2 because sequence 1 is not yet complete. Items in other groups should remain eligible for processing.</p> <p>In the last system, I implemented the queues with SQL tables. I created stored procedures to submit items and, more importantly, to “assign” items to the Windows Services that were responsible for processing them. The assignment stored procedures contain the selection logic I described above. Each Windows Service would call the assignment stored procedure, passing it the parameters that were unique to that instance of the service (e.g. the eligible offices). This assignment stored procedure stamps the work item as assigned (in process) and when the work is complete, a final stored procedure is called to remove the item from the “queue” (table).</p> <p>This solution does have some advantages in that I can quickly examine the state of these “queues” by a simple SQL select statement. I’m also able to manipulate the queues easily (e.g. I can bump priorities with a simple SQL update statement). However, on the downside, I occasionally have to deal with deadlocks on these queue tables and have the burden of writing these stored procedures (which gets tedious after a while).</p> <p>Somehow I think that either MSMQ (with or without WCS) or Service Broker should be able to provide a more elegant solution. Rolling my own queuing/work-item-processing system just feels wrong. But as far as I know, these technologies don’t offer the flexibility that I need in the assignment process. I am hoping that I am wrong. Any advice would be welcome. </p>
<p>It seems to me that your concept of an atomic unit of work is a Group. So I would suggest that you only queue up a message that identified a Group Id, and then your worker will have to go to a table that maps Group Id to 1 or more Work Items.</p> <p>You can handle your other problems by using more than one queue - NY-High, NY-Low, DC-High, DC-Low, etc.</p> <p>In all honesty, though, I think you are better served to fix your deadlock issues in your current architecture. You should be reading the TOP 1 message from your queue table with Update Lock and Read Past hints, ordered by your priority logic and whatever filter criteria you want (Office/Location). Then you process your 1 message, change it's status or move it to another table. You should be able to call that stored procedure in parallel without a deadlock issue.</p>
<p>Queues are for FIFO order, not random access order. Even though you are saying that you want FIFO order, you want FIFO order with respect to a random set of variables, which is essentially random order. If you want to use queues, you need to be able to determine order before the message goes in the queue, not after it goes in.</p>
25,147
<p>I am trying to use cvs annotate. This is the what I run:</p> <pre><code>cvs -d /mycvs/cvsroot/ annotate "projects/dg/SomeClass.java" </code></pre> <p>However, I get the following error:</p> <pre><code>cvs annotate: failed to create lock directory for `/mycvs/cvsroot/projects/dg^M' (/mycvs/cvsroot/projects/dg^M/#cvs.lock): No such file or directory cvs annotate: failed to obtain dir lock in repository `/mycvs/cvsroot/projects/dg^M' cvs [annotate aborted]: read lock failed - giving up </code></pre> <p>What does this mean? How can I overcome this problem? Could it be related to the ^M character I see at the error message?</p> <p>When I use eclipse to do the annotation it works. I checked and the directory `/mycvs/cvsroot/projects/dg' exists. The error also occurs when I'm logged in as root, so probably it's not a permissions issue either.</p> <p>I am using CentOS</p>
<p>From your description, I would guess that you've got it right with the stray ^M. What OS are you using? If Windows, are you using cygwin? I see you're using direct filesystem access to the repository. Might you consider setting up a server access mechanism like pserver to see if that helps?</p>
<p>I too am experiencing this problem with cygwin. In fact, I am able to authenticate against a pserver using eclipse cvs tools. However, cygwin... not so much.</p> <p>Here are a couple of posts that might be related: <a href="http://www.sat-industry.net/forums/dreambox-development/19893-checkout-failed-create-lock-directory.html" rel="nofollow noreferrer">http://www.sat-industry.net/forums/dreambox-development/19893-checkout-failed-create-lock-directory.html</a></p> <p>summary: add an environment variable: CVS_RSH=ssh</p> <p><a href="http://www.mooreds.com/wordpress/archives/000234" rel="nofollow noreferrer">http://www.mooreds.com/wordpress/archives/000234</a> summary: you may have a config problem with the permissions of the CVS server.</p> <p>Neither of these worked for me btw. </p>
23,162
<p>This is something I've ignored for awhile, but it keeps cropping up, and occasionally, if the filament snags real good, it can mess up a great print half way through, etc.</p> <p>Basically I have my filament spools hanging on a PVC pipe mounted directly above the printer, and the printer just sucks it in from the spool, but occasionally it becomes knotted at the spool, or becomes otherwise tangled.</p> <p>I'm thinking even if I completely unwrapped and rewrapped all of my spools so there was no trace of a tangle, what's to stop it from happening again? -- What's a good strategy for managing this kind of issue?</p> <p><strong>Edit:</strong> From some of the answers below, it seems that maybe the travel of my X carriage back and forth could be why my spools keep getting tangled. -- It looks like many people have their spools at about 90 degrees from mine (rotated relative to the Z axis of the printer), so that the travel of the X carriage won't have that affect. -- Also guides, etc are probably a good idea.</p> <p>Here's my current setup for reference (filament removed): <a href="https://i.stack.imgur.com/lsCOe.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/lsCOe.jpg" alt="enter image description here"></a></p>
<p>I had the same problem with my FFC dual.</p> <p>Consider using some kind of retaing clip to hold the spool in place, so it doesn't move back and forth on the post. This <a href="https://web.archive.org/web/20170127154947if_/http://www.thingiverse.com/thing:923340" rel="nofollow noreferrer">spool holder</a> worked for me:</p> <p><a href="https://i.stack.imgur.com/PGssw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PGssw.png" alt="enter image description here" /></a></p> <p>Another thing that can help is to make sure you are pulling the filament from the middle of the spool. <a href="http://www.thingiverse.com/thing:409297" rel="nofollow noreferrer">This</a> worked for me:</p> <p><a href="https://i.stack.imgur.com/pQ5aD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pQ5aD.png" alt="enter image description here" /></a></p>
<p>I used this solution, it makes a lot of sense, because I store the filament back in a box and the tip endup getting knotted.</p> <p><div class="youtube-embed"><div> <iframe width="640px" height="395px" src="https://www.youtube.com/embed/lE9LchCtKL4?start=0"></iframe> </div></div></p>
397
<p>I've always wondered about when and where is the best time to cache a property value... Some of them seem pretty simple, like the one below...</p> <pre><code>public DateTime FirstRequest { get { if (this.m_FirstRequest == null) { this.m_FirstRequest = DateTime.Now; } return (DateTime)this.m_FirstRequest; } } private DateTime? m_FirstRequest; </code></pre> <p><strong>But what about some more complicated situations?</strong></p> <ol> <li>A value that comes from a database, but remains true after it's been selected.</li> <li>A value that is stored in a built-in cache and might expire from time to time.</li> <li>A value that has to be calculated first? </li> <li>A value that requires some time to initialize. 0.001s, 0.1s, 1s, <strong>5s</strong>???</li> <li>A value that is set, but something else may come and set it to null to flag that it should be repopulated.</li> <li><strong>???</strong> There seems to be limitless situations.</li> </ol> <p><strong>What do you think is the point that a property can no longer take care of itself and instead require something to populate its value?</strong></p> <hr> <p><strong>[EDIT]</strong></p> <p>I see suggestions that I'm optimizing too early, etc. But my question is for when it is time to optimize. Caching everything isn't what I'm asking, but when it is time to cache, whose responsibility should it be?</p>
<p>In general, you should get the code working first and then optimize later and then only do optimizations that profiling say will help you.</p>
<p>I think you need to turn your question the other way around lest you fall into a trap of optimizing too early.</p> <h3>When do you think is the point that a property no longer needs recalculating on every call and instead uses some form of caching?</h3> <p>The caching of a value is an optimization and should therefore not be done as the norm. There are some cases where it is clearly relevant to use this optimization but in most cases, you should implement the property to work correctly every time by doing the appropriate work to get the value and then look to optimize it once you've profiled and shown that optimization is required.</p> <p>Some reasons why caching is or is not a good idea: - Don't cache if the value is prone to frequent change - Do cache if it never changes and you are responsible for it never changing - Don't cache if you are not responsible for providing the value as you're then relying on someone else's implementation</p> <p>There are many other reasons for and against caching a value but there is certainly no hard and fast rule on when to cache and when not to cache - each case is different.</p> <h3>If you have to cache...</h3> <p>Assuming that you've determined some form of caching is the way to go, then how you perform that caching depends on what you are caching, why, and how the value is provided to you.</p> <p>For example, if it is a singleton object or a timestamp as in your example, a simple "is it set?" condition that sets the value once is a valid approach (that or create the instance during construction). However, if it's hitting a database and the database tells you when it changes, you could cache the value based on a dirty flag that gets dirtied whenever the database value says it has changed. Of course, if you have no notification of changes, then you may have to either refresh the value on every call, or introduce a minimum wait time between retrievals (accepting that the value may not always be exact, of course).</p> <p>Whatever the situation, you should always consider the pros and cons of each approach and consider the scenarios under which the value is referenced. Do the consumers always need the most recent value or can they cope with being slightly behind? Are you in control of the value's source? Does the source provide notification of changes (or can you make it provide such notifications)? What is the reliability of the source? There are many factors that can affect your approach.</p> <h3>Considering the scenarios you gave...</h3> <p>Again, assuming that caching is needed.</p> <ol> <li><p>A value that comes from a database, but remains true after it's been selected.<br/> If the database is guaranteed to retain that behavior, you can just poll the value the first time it is requested and cache it thereafter. If you can't guarantee the behavior of the database, you may want to be more careful. </p></li> <li><p>A value that is stored in a built-in cache and might expire from time to time.<br/> I would use a dirty flag approach where the cache is marked dirty from time to time to indicate that the cached value needs refreshing, assuming that you know when "time to time" is. If you don't, consider a timer that indicates the cache is dirty at regular intervals.</p></li> <li><p>A value that has to be calculated first?<br/> I would judge this based on the value. Even if you think caching is needed, the compiler may have optimised it already. However, assuming caching is needed, if the calculation is lengthy, it might be better during construction or via an interface such as <code>ISupportInitialize</code>.</p></li> <li><p>A value that requires some time to initialize. 0.001s, 0.1s, 1s, 5s???<br/> I'd have the property do no calculation for this and implement an event that indicates when the value changes (this is a useful approach in any situation where the value might change). Once the initialization is complete, the event fires, allowing consumers to get the value. You should also consider that this might not be suited for a property; instead, consider an asynchronous approach such as a method with a callback.</p></li> <li><p>A value that is set, but something else may come and set it to null to flag that it should be repopulated.<br/> This is just a special case of the dirty flag approach discussed in point 2.</p></li> </ol>
44,392
<p>Mobile Safari is a very capable browser, and it can handle my website as it is perfectly. However, there are a few elements on my page that could be optimized for browsing using this device; such as serving specific thumbnails that are smaller than the desktop counterparts to help fit more content into the screen.</p> <p>I would like to know how I can detect Mobile Safari (all versions, preferably) using PHP, so then I can serve a) a specific css file and b) different sized image thumbnails.</p>
<p>Compare the user agent string with the one of a Safari Mobile uses:</p> <p><a href="http://developer.apple.com/library/safari/#documentation/AppleApplications/Reference/SafariWebContent/OptimizingforSafarioniPhone/OptimizingforSafarioniPhone.html#//apple_ref/doc/uid/TP40006517-SW3" rel="nofollow noreferrer">Safari Mobile User Agent String</a></p>
<p>I have published a new mode to detect devices in any programming language (JSP, PHP, Perl, Python.....), it's called Apache Mobile Filter is an Apache module (<a href="http://modules.apache.org/search.php?id=1787" rel="nofollow noreferrer">http://modules.apache.org/search.php?id=1787</a>) that detect mobile device and also can adapt the images to the screen size of device.</p> <p>For more info: <a href="http://www.idelfuschini.it/it/apache-mobile-filter-v2x.html" rel="nofollow noreferrer">http://www.idelfuschini.it/it/apache-mobile-filter-v2x.html</a> </p>
22,601
<p>Is there any setting using which the iPhone keyboard won't appear for a particular textbox in web page? May be some css kind of setting?</p>
<p>you just make the input field as <strong>readonly="true"</strong>/ readonly mode so that keyboard wont appear!!</p>
<p>I don't think you'll be able to truly disable the keyboard just like you cannot truly disable the keyboard when you browse a webpage via a PC or Mac. One trick would be to add JavaScript to intercept the OnKeyPress (or OnKeyDown) event to intercept the key stroke and cancel it based on the User Agent. I haven't tried it against the iPhone specifically but it has worked for other applications when I want to restrict the type of input on an enabled text box (i.e. canceling alpha characters in a phone number field). Since the "OnKey" events are still valid on the iPhone (as determined by sites with autocomplete like Google), the method should work.</p>
40,981
<p>I'm using a local artifactory to proxy the request, but the build and test phases are still a bit slow. It's not the actual compile and tests that are slow, it's the "warmup" of the maven2 framework. Any ideas?</p>
<p>There are some possibilities to optimize some of the build tasks. For example the 'clean' task can be optimized from minutes to just milliseconds using simple trick - rename 'target' folder instead of delete.</p> <p>To get details how to do it refer to <a href="http://bosy.dailydev.org/2009/02/speed-up-your-maven-build-four-times.html" rel="noreferrer">Speed up Maven build</a>.</p>
<p>Initially, you should get a finer analysis on your build times using something like <a href="https://github.com/timgifford/maven-buildtime-extension" rel="nofollow">this</a> and identify the candidates that are taking the most time. </p> <p>Are tests spinning up a H2 database per test? Is the download of external jar files taking the time? This will guide where to focus your investigation. Just applying go-fast flags don't usually work as they would have already been included by default, and you don't want to be sacrificing your tests with skip flags.</p>
19,550
<p>Where can you get information on the ASP.NET State Service e.g. how it works, performance, behaviour characteristics etc. Have looked on internet but cant find in depth information or an article dedicated to the subject. Thanks</p>
<p>Programmatically, session state is nothing more than memory in the shape of a dictionary or hash table, e.g. key-value pairs, which can be set and read for the duration of a user's session.</p> <p>Check following links for more details: </p> <ul> <li>"<a href="http://msdn.microsoft.com/en-us/library/ms972429.aspx" rel="nofollow noreferrer">ASP.NET Session State</a>" on MSDN</li> <li>"<a href="http://msdn.microsoft.com/en-us/library/ms178581%28VS.80%29.aspx" rel="nofollow noreferrer">Session State Overview</a>" on MSDN</li> </ul>
<p>For SQL Server State Management remember that you don't call <code>Session["Key"]</code> in loops. (Try to avoid that) Because everytime it accesses the session then a roundtrip to sqlserver is made.</p>
45,464
<p>I saw a potential answer here but that was for YYYY-MM-DD: <a href="http://paulschreiber.com/blog/2007/03/02/javascript-date-validation/" rel="noreferrer">JavaScript date validation</a></p> <p>I modified the code code above for MM-DD-YYYY like so but I still can't get it to work:</p> <pre><code>String.prototype.isValidDate = function() { var IsoDateRe = new RegExp("^([0-9]{2})-([0-9]{2})-([0-9]{4})$"); var matches = IsoDateRe.exec(this); if (!matches) return false; var composedDate = new Date(matches[3], (matches[1] - 1), matches[2]); return ((composedDate.getMonth() == (matches[1] - 1)) &amp;&amp; (composedDate.getDate() == matches[2]) &amp;&amp; (composedDate.getFullYear() == matches[3])); } </code></pre> <p>How can I get the above code to work for MM-DD-YYYY and better yet MM/DD/YYYY?</p> <p>Thanks.</p>
<pre><code>function isValidDate(date) { var matches = /^(\d{1,2})[-\/](\d{1,2})[-\/](\d{4})$/.exec(date); if (matches == null) return false; var d = matches[2]; var m = matches[1] - 1; var y = matches[3]; var composedDate = new Date(y, m, d); return composedDate.getDate() == d &amp;&amp; composedDate.getMonth() == m &amp;&amp; composedDate.getFullYear() == y; } console.log(isValidDate('10-12-1961')); console.log(isValidDate('12/11/1961')); console.log(isValidDate('02-11-1961')); console.log(isValidDate('12/01/1961')); console.log(isValidDate('13-11-1961')); console.log(isValidDate('11-31-1961')); console.log(isValidDate('11-31-1061')); </code></pre> <p>It works. (Tested with Firebug, hence the console.log().)</p>
<pre><code>&lt;script language = "Javascript"&gt; // Declaring valid date character, minimum year and maximum year var dtCh= "/"; var minYear=1900; var maxYear=2100; function isInteger(s){ var i; for (i = 0; i &lt; s.length; i++){ // Check that current character is number. var c = s.charAt(i); if (((c &lt; "0") || (c &gt; "9"))) return false; } // All characters are numbers. return true; } function stripCharsInBag(s, bag){ var i; var returnString = ""; // Search through string's characters one by one. // If character is not in bag, append to returnString. for (i = 0; i &lt; s.length; i++){ var c = s.charAt(i); if (bag.indexOf(c) == -1) returnString += c; } return returnString; } function daysInFebruary (year){ // February has 29 days in any year evenly divisible by four, // EXCEPT for centurial years which are not also divisible by 400. return (((year % 4 == 0) &amp;&amp; ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 ); } function DaysArray(n) { for (var i = 1; i &lt;= n; i++) { this[i] = 31 if (i==4 || i==6 || i==9 || i==11) {this[i] = 30} if (i==2) {this[i] = 29} } return this } function isDate(dtStr){ var daysInMonth = DaysArray(12) var pos1=dtStr.indexOf(dtCh) var pos2=dtStr.indexOf(dtCh,pos1+1) var strDay=dtStr.substring(0,pos1) var strMonth=dtStr.substring(pos1+1,pos2) var strYear=dtStr.substring(pos2+1) strYr=strYear if (strDay.charAt(0)=="0" &amp;&amp; strDay.length&gt;1) strDay=strDay.substring(1) if (strMonth.charAt(0)=="0" &amp;&amp; strMonth.length&gt;1) strMonth=strMonth.substring(1) for (var i = 1; i &lt;= 3; i++) { if (strYr.charAt(0)=="0" &amp;&amp; strYr.length&gt;1) strYr=strYr.substring(1) } month=parseInt(strMonth) day=parseInt(strDay) year=parseInt(strYr) if (pos1==-1 || pos2==-1){ alert("The date format should be : dd/mm/yyyy") return false } if (strMonth.length&lt;1 || month&lt;1 || month&gt;12){ alert("Please enter a valid month") return false } if (strDay.length&lt;1 || day&lt;1 || day&gt;31 || (month==2 &amp;&amp; day&gt;daysInFebruary(year)) || day &gt; daysInMonth[month]){ alert("Please enter a valid day") return false } if (strYear.length != 4 || year==0 || year&lt;minYear || year&gt;maxYear){ alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear) return false } if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){ alert("Please enter a valid date") return false } return true } function ValidateForm(){ var dt=document.frmSample.txtDateenter code here if (isDate(dt.value)==false){ dt.focus() return false } return true } &lt;/script&gt; </code></pre>
34,863
<p>been searching for a quick example of sorting a IQueryable (Using Linq To SQL) using a Aggregate value.</p> <p>I basically need to calculate a few derived values (Percentage difference between two values etc) and sort the results by this.</p> <p>i.e.</p> <p>return rows.OrderBy(Function(s) CalcValue(s.Visitors, s.Clicks))</p> <p>I want to call an external function to calculate the Aggregate. Should this implement IComparer? or IComparable?</p> <p>thanks</p> <p>[EDIT] Have tried to use:</p> <pre><code>Public Class SortByCPC : Implements IComparer(Of Statistic) Public Function Compare(ByVal x As Statistic, ByVal y As Statistic) As Integer Implements System.Collections.Generic.IComparer(Of Statistic).Compare Dim xCPC = x.Earnings / x.Clicks Dim yCPC = y.Earnings / y.Clicks Return yCPC - xCPC End Function End Class </code></pre> <p>LINQ to SQL doesn't like me using IComparer</p>
<p>LINQ to SQL is never going to like you using your own methods within a query - it can't see inside them and work out what you want the SQL to look like. It can only see inside expression trees, built up from lambda expressions in the query.</p> <p>What you want is something like:</p> <pre><code>Dim stats = From x in db.Statistics Where (something, if you want filtering) Order By x.Earnings / x.Clicks; </code></pre> <p>If you really want to fetch all of the results and then order them, you need to indicate to LINQ that you're "done" with the IQueryable side of things - call <a href="http://msdn.microsoft.com/en-us/library/bb335435.aspx" rel="nofollow noreferrer">AsEnumerable()</a> and then you can do any remaining processing on the client. It's better to get the server to do as much as possible though.</p>
<p>My VB is pretty bad, but I think this is what it should look like. This assumes that CalcValues returns a double and the type of <code>rows</code> is RowClass. This example does not use the IComparer version of the OrderBy extension but relies on the fact the doubles are comparable already and returns the CalcValue (assumed as double) as the key.</p> <pre><code>Dim keySelector As Func(Of Double, RowClass) = _ Func( s As RowClass) CalcValue( s.Visitors, s.Clicks ) return rows.OrderBy( keySelector ) </code></pre> <p>Here are some links you might find useful.</p> <p><a href="http://msdn.microsoft.com/en-us/library/system.linq.queryable.orderby.aspx" rel="nofollow noreferrer">IQueryable.OrderBy</a> extension method</p> <p><a href="http://msdn.microsoft.com/en-us/magazine/cc163362.aspx" rel="nofollow noreferrer">Lambda expressions</a> for Visual Basic</p>
48,387
<p>Inspired by <a href="https://stackoverflow.com/questions/277106/looking-for-some-interesting-c-programming-problems">this question</a>, I wanted to try my hand at the latest <a href="http://domino.research.ibm.com/Comm/wwwr_ponder.nsf/Challenges/November2008.html" rel="nofollow noreferrer">ponder this challenge</a>, using F#</p> <p>My approach is probably completely off course, but in the course of solving this problem, I'm trying to get a list of all the permutations of the digits 0-9.</p> <p>I'm looking at solving it using a n-ary tree like so:</p> <pre><code>type Node = | Branch of (int * Node list) | Leaf of int </code></pre> <p>I'm quite pleased with myself, because I've managed to work out how to generate the tree that I want. </p> <p>My problem now is that I can't work out how to traverse this tree and extract the 'path' to each leaf as an int. Thing thing that is confusing me is that I need to match on individual Nodes, but my 'outer' function needs to take a Node list.</p> <p>My current attempt almost does the right thing, except that it returns me the sum of all the paths...</p> <pre><code>let test = Branch(3, [Branch(2, [Leaf(1)]);Branch(1, [Leaf(2)])]) let rec visitor lst acc = let inner n = match n with | Leaf(h) -&gt; acc * 10 + h | Branch(h, t) -&gt; visitor t (acc * 10 + h) List.map inner lst |&gt; List.sum visitor [test] 0 //-&gt; gives 633 (which is 321 + 312) </code></pre> <p>And I'm not even sure that this is tail-recursive.</p> <p>(You're quite welcome to propose another solution for finding permutations, but I'm still interested in the solution to this particular problem)</p> <p>EDIT: I've posted a generic permutations algorithm in F# <a href="https://stackoverflow.com/questions/286427/calculating-permutations-in-f">here</a>.</p>
<p>regarding your question about list traversal - you can start by writing a function that returns lists that represent the path - that's I think easier and it will be later easy to turn it into a function that returns a number.</p> <p>This one takes a list as the first argument (path so far) and a tree and returns a list> type - that is all the possible paths from the current branch.</p> <pre><code>let rec visitor lst tree = match tree with | Branch(n, sub) -&gt; List.collect (visitor (n::lst)) sub | Leaf(n) -&gt; [List.rev (n::lst)] // For example... &gt; let tr = Branch(1, [Leaf(3); Branch(2, [Leaf(4); Leaf(5)] )]);; &gt; visitor [] tr;; val it : int list list = [[1; 3]; [1; 2; 4]; [1; 2; 5]] </code></pre> <p>In the 'Leaf' case, we simply add the current number to the list and return the result as a list containing single list (we have to reverse it first, because we were adding numbers to the beginning). In the 'Branch' case, we add 'n' to the list and recursively call the visitor to process all the sub-nodes of the current branch. This returns a bunch of lists and we use 'map_concat' to turn them into a single list that contains all posble paths from the current branch.</p> <p>Now, you can rewrite this to return a list of integers:</p> <pre><code>let rec visitor2 lst tree = match tree with | Branch(n, sub) -&gt; List.collect (visitor2 (lst * 10 + n)) sub | Leaf(n) -&gt; [lst * 10 + n] // For example... &gt; visitor2 0 tr;; val it : int list = [13; 124; 125] </code></pre> <p>Instead of concatenating lists, we now calculate the number.</p>
<p>Regarding laziness - You can make this lazy by using F# "seq" type instead of "list" type. Here is an example:</p> <pre><code>let rec visitor2 lst tree = match tree with | Branch(n, sub) -&gt; Seq.map_concat (visitor2 (lst * 10 + n)) sub | Leaf(n) -&gt; seq { do printfn "--yielding: %d" (lst * 10 + n) yield lst * 10 + n };; </code></pre> <p>The "seq" thing is a sequence expression, which represents a lazy stream of values. I added "printfn" to the code, so we can track how things are executing:</p> <pre><code>&gt; visitor2 0 tr |&gt; Seq.take 2;; --yielding: 13 --yielding: 124 val it : seq&lt;int&gt; = seq [13; 124] </code></pre> <p>You can probably use something like Seq.first to find the first value which represents the result.</p>
35,958
<p>Programming in vim I often go search for something, yank it, then go back to where I was, insert it, modify it.</p> <p>The problem is that after I search and find, I need to MANUALLY find my way back to where I was.</p> <p>Is there an automatic way to go back to where I was when I initiated my last search?</p>
<p><kbd>Ctrl</kbd>+<kbd>O</kbd> takes me to the previous location. Don't know about location before the search.</p> <p>Edit: Also, <kbd>`</kbd><kbd>.</kbd> will take you to the last change you made.</p>
<p>The simplest way is to set a mark, with <code>m[letter]</code>, then go back to it with <code>'[letter]</code></p>
7,747
<p>I would appreciate your opinion/advice on the following</p> <p><strong>Scenario</strong> </p> <p>HTML has PDF file nick name, back end has URL for each nick. </p> <p>The link URL is always <code>download.php?what=%PDF_Nick%</code> to ensure download for JS disabled clients. </p> <p>For JS enabled clients I do JQuery AJAX call and rewrite link URL from <code>download.php?what=%PDF_Nick%</code> to <a href="http://examplesite.com/requestedPFF.pdf" rel="nofollow noreferrer">http://examplesite.com/requestedPFF.pdf</a> to activate download from the client. I set <code>"async: false"</code> to allow AJAX get new url.</p> <p><strong>Problem</strong></p> <p>AJAX returns valid script rewriting JS url variable, but <code>location.href</code> runs again to the initial url, creating extra back end call</p> <p>Do you think it's related to the bug ignoring <code>"async: false,"</code> definition or it's mistake I've made and missed to catch?</p> <p>Thank you in advance</p> <h1>HTML code</h1> <pre><code> &lt;a href="/download.php?what=PDF_A" onclick="javascript:download ('PDF_A')"&gt;Download&lt;/a&gt; </code></pre> <h1>JS code</h1> <pre><code>function download ( what ) { var url = "download.php?what="+what; $.ajax({ type: "GET", url: "download.php?ajax=true", data: "what=" + what async: false, dataType: "script" }); // if AJAX got the download URL I expect actual download to start: location.href = url; } </code></pre> <h1>Back end (download.php) code</h1> <pre><code>$myPDF = array(); $myPDF["PDF_A"] = "PDF_A.pdf"; .... $url = "http://examplesite.com/" . $myPDF["PDF_A"]; ... if ( $_GET["ajax"] === "true" ) { // overwrite JS url variable print('url = "'.$url.'";'); } else { header("Location: ". $url ); header("Connection: close"); } </code></pre>
<p>Is there a reason you disable the asynchronous nature of the AJAX request? it will lock the browser until the request is completed. You are better off using a callback instead:</p> <pre><code>$.ajax({ type: "GET", url: "download.php?ajax=true", data: "what=" + what, dataType: "script", success: function(msg) { location.href = url; } }); </code></pre>
<p>Is there a reason you disable the asynchronous nature of the AJAX request? it will lock the browser until the request is completed. You are better off using a callback instead:</p> <pre><code>$.ajax({ type: "GET", url: "download.php?ajax=true", data: "what=" + what, dataType: "script", success: function(msg) { location.href = url; } }); </code></pre>
45,974
<p>I'm trying to get the following SQL statement to work:</p> <pre><code>UPDATE myschema.tableA update_tableA SET field_id = ( SELECT src.field_id FROM myschema.srcTable src INNER JOIN myschema.tableB tableB ON update_tableA.id = tableB.id AND SDO_ANYINTERACT( tableB.shape, src.shape ) = 'TRUE' ); </code></pre> <p>When I run this statement, I get the following error:</p> <pre><code>ORA-00904: "UPDATE_TABLEA"."ID": invalid identifier </code></pre> <p>Can I not use a variable scoped outside of the nested select within the nested select? Any thoughts?</p> <p>P.S. The identifier is indeed valid in the database table. The problem appears to be scope, but I want to make sure that is indeed an issue.</p>
<p>I don't believe you can JOIN on a column (i.e. use it in the ON clause) that's not in one of the tables being joined. Additional predicates need to be in a WHERE clause.</p> <p>Try this:</p> <pre><code>UPDATE myschema.tableA update_tableA SET field_id = ( SELECT src.field_id FROM myschema.srcTable src INNER JOIN myschema.tableB tableB ON SDO_ANYINTERACT( tableB.shape, src.shape ) = 'TRUE' WHERE update_tableA.id = tableB.id ); </code></pre>
<p>Looking at the SQL above, here is what I am thinking</p> <p>1) myschema.tableA doesn't have ID column (it could be field_id) <br> 2) The SELECT doesn't seem to provide a join condition</p> <p><code> SELECT src.field_id FROM myschema.srcTable src INNER JOIN myschema.tableB tableB ON </code></p> <p>Where is the condition to JOIN src with tableB?</p>
37,136
<p>I'm wondering if there's such a thing as Django-like ease of web app development combined with good deployment, debugging and other tools? </p> <p>Django is a very productive framework for building content-heavy sites; the best I've tried and a breath of fresh air compared to some of the Java monstrosities out there. However it's written in Python which means there's little real support in the way of deployment/packaging, debugging, profilers and other tools that make building and maintaining applications much easier. </p> <p>Ruby has similar issues and although I do like Ruby <strong>much</strong> better than I like Python, I get the impression that Rails is roughly in the same boat at Django when it comes to managing/supporting the app. </p> <p>Has anyone here tried both Django and Grails (or other web frameworks) for non-trivial projects? How did they compare?</p>
<p>You asked for someone who used both Grails and Django. I've done work on both for big projects. Here's my Thoughts:</p> <p><strong>IDE's:</strong> Django works really well in Eclipse, Grails works really well in IntelliJ Idea.</p> <p><strong>Debugging:</strong> Practically the same (assuming you use IntelliJ for Grails, and Eclipse for Python). Step debugging, inspecting variables, etc... never need a print statement for either. Sometimes django error messages can be useless but Grails error messages are usually pretty lengthy and hard to parse through.</p> <p><strong>Time to run a unit test:</strong> django: 2 seconds. Grails: 20 seconds (the tests themselves both run in a fraction of a second, it's the part about loading the framework to run them that takes the rest... as you can see, Grails is frustratingly slow to load).</p> <p><strong>Deployment:</strong> Django: copy &amp; paste one file into an apache config, and to redeploy, just change the code and reload apache. Grails: create a .war file, deploy it on tomcat, rinse and repeat to redeploy.</p> <p><strong>Programming languages:</strong> Groovy is TOTALLY awesome. I love it, more so than Python. But I certainly have no complaints. </p> <p><strong>Plugins:</strong> Grails: lots of broken plugins (and can use every java lib ever). Django: a few stable plugins, but enough to do most of what you need.</p> <p><strong>Database:</strong> Django: schema migrations using South, and generally intuitive relations. Grails: no schema migrations, and by default it deletes the database on startup... WTF</p> <p><strong>Usage:</strong> Django: startups (especially in the Gov 2.0 space), independent web dev shops. Grails: enterprise</p> <p>Hope that helps!</p>
<p>cakephp.org</p> <p>Cakephp is really good, really close to ruby on rails (1.2). It is in php, works very well on shared hosts and is easy to implement. </p> <p>The only downside is that the documentation is somewhat lacking, but you quickly get it and quickly start doing cool stuff.</p> <p>I totally recommend cakephp.</p>
10,146