instruction
stringlengths
27
22.5k
chosen
stringlengths
27
28.2k
rejected
stringlengths
19
24.9k
__index_level_0__
int64
0
10k
<p>We use QuickBooks for financial management, and feed it from a variety of sources. I now need to hook it up to BizTalk, and I'd hate to reinvent the wheel. I've done searches, and as far as I can tell there's no QuickBooks adapter for BizTalk. Does anyone know of anything that'll do the job, preferably something that doesn't suck? </p> <hr> <p>Doesn't the QB SDK require that Quickbooks be running on the client machine? Is there any way around it?</p>
<p>Quickbooks talks .NET quite easily. You'll need the QuickBooks SDK 7.0 and a copy of Visual Studio.NET, but after that it's very easy to do anything with Quickbooks. </p> <pre><code>Imports QBFC7Lib Sub AttachToDB() If isAttachedtoQB Then Exit Sub Lasterror = "Unknown QuickBooks Error" Try QbSession = New QBSessionManager QbSession.OpenConnection("", "Your Company Name") QbSession.BeginSession("", ENOpenMode.omDontCare) MsgReq = QbSession.CreateMsgSetRequest("UK", 6, 0) MsgReq.Attributes.OnError = ENRqOnError.roeStop Lasterror = "" isAttachedtoQB = True Catch e As Exception If Not QbSession Is Nothing Then QbSession.CloseConnection() QbSession = Nothing End If isAttachedtoQB = False Lasterror = "QuickBooks Connection Error. - " + e.Message + "." End Try End Sub </code></pre> <p>See <a href="http://developer.intuit.com/" rel="nofollow noreferrer">http://developer.intuit.com/</a> for more information. </p>
<p>Unfortunately it does. It also asks you to authorise any application you've built. (at least once.) </p> <p>I don't know any way around it. </p>
6,765
<p>There are thousands of <code>vi</code> tutorials on the web, most of them generically listing all the commands. There are even videos on youtube which show basic functionality.</p> <p>But does anyone know of a vi tutorial which focuses on the <strong>needs of programmers</strong>? </p> <p>For example when I program in <strong>Perl</strong> with <code>vi</code>, moving to the "next paragraph" is meaningless.</p> <p>I want to know which commands seasoned vi users combine to e.g:</p> <ul> <li>copy everything inside of parentheses</li> <li>copy a function</li> <li>copy and paste a variable (e.g. 2yw)</li> <li>etc.</li> </ul> <p>I am sure there are lots of functions using multiple-file capability, and the maps, macros, reading in of files for template code, regular expression search, jumping to functions, perhaps minimal code completion, or other features that emulate what programmers have gotten used to in Visual Studio and Eclipse, etc. </p>
<p>A nice collection of <a href="http://rayninfo.co.uk/vimtips.html" rel="noreferrer">vimtips</a>.</p> <p>And the best Vim <a href="http://www.cheat-sheets.org/saved-copy/vimqrc.pdf" rel="noreferrer">cheatsheet</a> around.</p>
<p>I just ended up reading the vim manual a few times, over the years, picking up useful features on each iteration.</p> <p>One thing that really made vim work for me as a perl IDE was starting to use tags, as explained here: <a href="http://www.vim.org/tips/tip.php?tip_id=94" rel="nofollow noreferrer">http://www.vim.org/tips/tip.php?tip_id=94</a>. Using the pltags script that ships with vim, you can jump around between modules to find your functions, methods, etc.</p>
6,935
<p>What would be the best way to fill a C# struct from a byte[] array where the data was from a C/C++ struct? The C struct would look something like this (my C is very rusty):</p> <pre><code>typedef OldStuff { CHAR Name[8]; UInt32 User; CHAR Location[8]; UInt32 TimeStamp; UInt32 Sequence; CHAR Tracking[16]; CHAR Filler[12]; } </code></pre> <p>And would fill something like this:</p> <pre><code>[StructLayout(LayoutKind.Explicit, Size = 56, Pack = 1)] public struct NewStuff { [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8)] [FieldOffset(0)] public string Name; [MarshalAs(UnmanagedType.U4)] [FieldOffset(8)] public uint User; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8)] [FieldOffset(12)] public string Location; [MarshalAs(UnmanagedType.U4)] [FieldOffset(20)] public uint TimeStamp; [MarshalAs(UnmanagedType.U4)] [FieldOffset(24)] public uint Sequence; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)] [FieldOffset(28)] public string Tracking; } </code></pre> <p>What is best way to copy <code>OldStuff</code> to <code>NewStuff</code>, if <code>OldStuff</code> was passed as byte[] array?</p> <p>I'm currently doing something like the following, but it feels kind of clunky.</p> <pre><code>GCHandle handle; NewStuff MyStuff; int BufferSize = Marshal.SizeOf(typeof(NewStuff)); byte[] buff = new byte[BufferSize]; Array.Copy(SomeByteArray, 0, buff, 0, BufferSize); handle = GCHandle.Alloc(buff, GCHandleType.Pinned); MyStuff = (NewStuff)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(NewStuff)); handle.Free(); </code></pre> <p>Is there better way to accomplish this?</p> <hr> <p>Would using the <code>BinaryReader</code> class offer any performance gains over pinning the memory and using <code>Marshal.PtrStructure</code>?</p>
<p>From what I can see in that context, you don't need to copy <code>SomeByteArray</code> into a buffer. You simply need to get the handle from <code>SomeByteArray</code>, pin it, copy the <code>IntPtr</code> data using <code>PtrToStructure</code> and then release. No need for a copy.</p> <p>That would be:</p> <pre><code>NewStuff ByteArrayToNewStuff(byte[] bytes) { GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned); try { NewStuff stuff = (NewStuff)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(NewStuff)); } finally { handle.Free(); } return stuff; } </code></pre> <p>Generic version:</p> <pre><code>T ByteArrayToStructure&lt;T&gt;(byte[] bytes) where T: struct { T stuff; GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned); try { stuff = (T)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(T)); } finally { handle.Free(); } return stuff; } </code></pre> <p>Simpler version (requires <code>unsafe</code> switch):</p> <pre><code>unsafe T ByteArrayToStructure&lt;T&gt;(byte[] bytes) where T : struct { fixed (byte* ptr = &amp;bytes[0]) { return (T)Marshal.PtrToStructure((IntPtr)ptr, typeof(T)); } } </code></pre>
<p>If you have a byte[] you should be able to use the BinaryReader class and set values on NewStuff using the available ReadX methods.</p>
2,500
<p>I have to write an applet that brings up a password dialog. The problem is that dialog is set to be always on top but when user clicks on IE window dialog gets hidden behind IE window nevertheless. And since dialog is modal and holds <strong>all</strong> IE threads IE pane does not refresh and dialog window is still painted on top of IE (but not refreshed). This behaviour confuses users (they <em>see</em> dialog on top of IE but it looks like it has hanged since it is not refreshe). </p> <p>So I need a way to keep that dialog on top of everything. But any other solution to this problem would be nice. </p> <p>Here's the code:</p> <pre><code> PassDialog dialog = new PassDialog(parent); /* do some non gui related initialization */ dialog.pack(); dialog.setLocationRelativeTo(null); dialog.setAlwaysOnTop(true); dialog.setVisible(true); </code></pre> <p>Resolution: As @shemnon noted I should make a window instead of (null, Frame, Applet) parent of modal dialog. So good way to initlialize parent was: </p> <pre><code>parent = javax.swing.SwingUtilities.getWindowAncestor(theApplet); </code></pre>
<p>What argument are you using for the parent?</p> <p>You may have better luck if you use the parent of the Applet.</p> <pre><code>javax.swing.SwingUtilities.getWindowAncestor(theApplet) </code></pre> <p>Using the getWindowAncestor will skip the applet parents (getRoot(component) will return applets). In at least some versions of Java there was a Frame that was equivalent to the IE window. YMMV.</p>
<p>You might try launching a modal from JavaScript using the JavaScript integration (see <a href="http://www.raditha.com/java/mayscript.php" rel="nofollow noreferrer">http://www.raditha.com/java/mayscript.php</a> for an example). </p> <p>The JavaScript you would need would be something like:</p> <pre><code>function getPassword() { return prompt("Enter Password"); } </code></pre> <p>And the Java would be:</p> <pre><code>password = jso.call("getPassword", new String[0]); </code></pre> <p>Unfortunately that means giving up all hope of having a nice looking modal. Good luck!</p>
9,862
<p>Now that <code>LINQ</code> to <code>SQL</code> is a little more mature, I'd like to know of any techniques people are using to create an <strong>n-tiered solution</strong> using the technology, because it does not seem that obvious to me.</p>
<p>LINQ to SQL doesn't really have a n-tier story that I've seen, since the objects that it creates are created in the class with the rest of it, you don't really have an assembly that you can nicely reference through something like Web Services, etc.</p> <p>The only way I'd really consider it is using the datacontext to fetch data, then fill an intermediary data model, passing that through, and referencing it on both sides, and using that in your client side - then passing them back and pushing the data back into a new Datacontext or intellgently updating rows after you refetch them.</p> <p>That's if I'm understanding what you're trying to get at :\</p> <p>I asked ScottGu the same question on his blog when I first started looking at it - but I haven't seen a single scenario or app in the wild that uses LINQ to SQL in this way. Websites like Rob Connery's Storefront are closer to the provider.</p>
<blockquote> <p>Seriously speaking, LINQ to SQL had it's support for n-tier architecture see DataContext.Update method</p> </blockquote> <p>Some of what I've read suggests that the business logic wraps the DataContext - in other words you wrap the update in the way that you suggest. </p> <p>The way i traditionally write business objects i usually encapsulate the "Load methods" in the BO as well; so I might have a method named LoadEmployeesAndManagers that returns a list of employees and their immediate managers (this is a contrived example) . Maybe its just me, but in my front end I'd rather see e.LoadEmployeesAndManagers() than some long LINQ statement. </p> <p>Anyway, using LINQ it would probably look something like this (not checked for syntax correctness):</p> <pre><code>var emps = from e in Employees join m in Employees on e.ManagerEmpID equals m.EmpID select new { e, m.FullName }; </code></pre> <p>Now if I understand things correctly, if I put this in say a class library and call it from my front end, the only way I can return this is as an IEnumerable, so I lose my strong typed goodness. The only way I'd be able to return a strongly typed object would be to create my own Employees class (plus a string field for manager name) and fill it from the results of my LINQ to SQL statement and then return that. But this seems counter intuitive... what exactly did LINQ to SQL buy me if I have to do all that?</p> <p>I think that I might be looking at things the wrong way; any enlightenment would be appreciated.</p>
5,888
<p>Of course I am aware of Ajax, but the problem with Ajax is that the browser should poll the server frequently to find whether there is new data. This increases server load.</p> <p>Is there any better method (even using Ajax) other than polling the server frequently?</p>
<p>Yes, what you're looking for is COMET <a href="http://en.wikipedia.org/wiki/Comet_(programming)" rel="noreferrer">http://en.wikipedia.org/wiki/Comet_(programming)</a>. Other good Google terms to search for are AJAX-push and reverse-ajax.</p>
<p>You can also look into <a href="http://www.pushlets.com/" rel="nofollow noreferrer">Java Pushlets</a> if you are using jsp pages.</p>
4,033
<p>Where can I find a guide for integrating JavaScript and JMS (Java Messaging Service)?</p> <p>I would like a best practice or established technology that allows me to directly or indirectly receive messages from a topic and update a site based on the message. I was thinking of creating two components, a servlet for the Web module, and an MDB (Message-Driven Bean) for the EJB module. The web client will comsume messages from the JMS topic, and the MDB will handle the onMessage.</p> <p>Does this sound correct? Have you seen any examples?</p> <p>Edit: I am using ActiveMQ for the JMS.</p>
<p>I think <a href="http://activemq.apache.org/ajax.html" rel="nofollow noreferrer">this</a> is your answer. Looks like it is baked in to ActiveMQ. I tried the examples and they seem to work.</p> <p><a href="http://activemq.apache.org/ajax.html" rel="nofollow noreferrer">http://activemq.apache.org/ajax.html</a></p>
<p>You'll find some references to the Dojo/Bayeux approach here<br> <a href="http://www.pathf.com/blogs/2006/08/bayeux_a_json_p/" rel="nofollow noreferrer">http://www.pathf.com/blogs/2006/08/bayeux_a_json_p/</a></p> <p>If you're using WebSphere 6.0 or higher then the Web 2.0 Feature Pack includes an implementation.</p>
9,239
<p>I have the next function:</p> <pre><code>function setImagesWidth(id,width) { var images = document.getElementById(id).getElementsByTagName("img"); for(var i = 0; i &lt; images.length;i++) { // If the real width is bigger than width parameter images[i].style.width=width; //} } } </code></pre> <p>I would like to set the css width attribute of all my img tags to a particular value only when the image real width is bigger than the attribute value. If it is possible, i would like a solution which does not use any particular framework. </p> <hr> <p><code>images[i].offsetWidth</code> returns 111 for an image of 109px width. Is this because 1px each side border? </p>
<p>Here is, hopefully, enough sample code to give you what you want:</p> <pre><code>var myImage = document.getElementById("myImagesId"); var imageWidth = myImage.offsetWidth; var imageHeight = myImage.offsetHeight; </code></pre> <p>That should give you the numbers you need to derive the solution you want. I think you can write the rest of the code yourself. :)</p> <hr> <p>EDIT: Here, I couldn't help myself - is this what you are after?</p> <pre><code>function setImagesWidth(id,width) { var images = document.getElementById(id).getElementsByTagName("img"); for(var i = 0; i &lt; images.length;i++) { if(images[i].offsetWidth &gt; width) { images[i].style.width= (width + "px"); } } } </code></pre>
<p>Careful, it looks like you might rather want <code>clientWidth</code>:</p> <p><a href="http://developer.mozilla.org/en/Determining_the_dimensions_of_elements" rel="nofollow noreferrer">http://developer.mozilla.org/en/Determining_the_dimensions_of_elements</a></p>
6,376
<p>I am consistently getting these strings in the overhangs on models that folks say they are printing without supports. Can anyone tell me what is causing them and what I can do to fix them?</p> <p>I've attached a picture mid-way during a <a href="https://www.thingiverse.com/thing:3232347" rel="nofollow noreferrer">BB-8</a> print. I'm using PLA at 75&nbsp;% speed.</p> <p><a href="https://i.stack.imgur.com/irMSz.jpg" rel="nofollow noreferrer" title="Stringing on overhangs"><img src="https://i.stack.imgur.com/irMSz.jpg" alt="Stringing on overhangs" title="Stringing on overhangs"></a></p>
<p>While this looks a lot like stringing, it's not what I would call stringing. I usually reserve that term for material that should never have left the nozzle to begin with, due to insufficient or missing retraction or excessive compression of the filament between the extruder and the nozzle. The "strings" you've shown look like desired wall extrusions that did not adhere to the adjacent walls in the same layer or to the previous layer.</p> <p>This is common when printing concave perimeters that are overhanging, due to a combination of minimal-to-no contact with previous layer and acceleration of the nozzle away from the previous wall in the current layer. Sometimes under-extrusion can also be a factor.</p> <p>You can often mitigate this by:</p> <ul> <li><p>using thinner layers (for the whole print, or "adaptive layer height" that will dynamically adjust as needed). For a given wall slope (fixed rise over run), this will reduce the "rise", and thereby place the walls of the next layer such that they overlap more with the previous layer. Sometimes this makes the difference as to whether they overlap <em>at all</em>.</p></li> <li><p>increasing hotend temperature. This will improve bonding with adjacent wall and with previous layer, if there's any contact with it.</p></li> <li><p>decreasing print speed, especially for outer walls. This will reduce the effect of the nozzle pulling the wall away from the adjacent wall it's supposed to bond to, and will also deliver more heat to the adjacent wall and previous layer wall you want to bond to.</p></li> </ul> <p>All three of these will also help if under-extrusion is part of the underlying cause.</p> <p>If you can't get any of this to work, using supports is always an option, but spherical (as opposed to flattened) domes generally "shouldn't" need support to print.</p>
<p>You did print overhangs without supports. I have printed a Thermal Detonator for StarWars day (May the 4th be with you!), which is pretty much an empty pair of domes. To ensure that the upper layers stay up, I have activated support starting at 40°, and it came out perfectly fine. Without support, the lines would have had nothing to hang on and sag down like in your print.</p>
1,300
<p>Here's a wierd one. I'm reusing a code base that unfortunately must not be updated. This code makes a call to <code>HttpContext.Current.Request.QueryString</code>. Ideally, I need to push a value into this collection with every request that is made. Is this possible - perhaps in an HTTP Module?</p>
<p>Without using reflection, the simplest way to do it would be to use the RewritePath function on the current HttpContext object in order to modify the querystring. </p> <p>Using an <a href="http://msdn.microsoft.com/en-us/library/system.web.ihttpmodule.aspx" rel="noreferrer">IHttpModule</a>, it might look something like:</p> <pre><code>context.RewritePath(context.Request.Path, context.Request.PathInfo, newQueryStringHere!); </code></pre> <p>Hope this helps!</p>
<p>Ditto Espo's answer and I would like to add that usually in medium trust (specific to many shared hostings) you will not have access to reflection so ... RewritePath will remain your probably only choice.</p>
5,458
<p>I have two elements:</p> <pre><code>&lt;input a&gt; &lt;input b onclick="..."&gt; </code></pre> <p>When b is clicked, I want to access a and manipulate some of its data. A does not have a globally unique name, so <code>document.getElementsByName</code> is out. Looking into the event object, I thought <code>event.target.parentNode</code> would have some function like <code>getElementsByName</code>, but this does not seem to be the case with &lt;td&gt;s. Is there any simple way to do this?</p>
<p>If <code>a</code> and <code>b</code> are next to each other and have the same parent, you can use the <code>prevSibling</code> property of <code>b</code> to find <code>a</code>.</p>
<p>Leave your plain vanilla JavaScript behind. Get JQuery--it will save you a ton of time.</p> <p><a href="http://docs.jquery.com/Selectors" rel="nofollow noreferrer">http://docs.jquery.com/Selectors</a></p>
7,668
<p>Simple question, but one that I've been curious about...is there a functional difference between the following two commands?</p> <pre><code>String::class String.class </code></pre> <p>They both do what I expect -- that is to say they return <code>Class</code> -- but what is the difference between using the <code>::</code> and the <code>.</code>?</p> <p>I notice that on those classes that have constants defined, IRB's auto-completion will return the constants as available options when you press tab after <code>::</code> but not after <code>.</code>, but I don't know what the reason for this is...</p>
<p>The <code>.</code> operator basically says "send this message to the object". In your example it is calling that particular member. The <code>::</code> operator "drills down" to the scope defined to the left of the operator, and then calls the member defined on the right side of operator.</p> <p>When you use <code>::</code> you have to be referencing members that are defined. When using <code>.</code> you are simply sending a message to the object. Because that message could be anything, auto-completion does not work for <code>.</code> while it does for <code>::</code>.</p>
<p>Actually, auto-completion does work for <code>.</code>. The completion options are found by calling <code>#methods</code> on the object. You can see this for yourself by overriding <code>Object.methods</code>:</p> <pre><code>&gt;&gt; def Object.methods; ["foo", "bar"]; end =&gt; nil &gt;&gt; Object.[TAB] Object.foo Object.bar &gt;&gt; Object. </code></pre> <p>Note that this only works when the expression to the left of the <code>.</code> is a literal. Otherwise, getting the object to call <code>#methods</code> on would involve evaluating the left-hand side, which could have side-effects. You can see this for yourself as well:</p> <pre><code>[continuing from above...] &gt;&gt; def Object.baz; Object; end =&gt; nil &gt;&gt; Object.baz.[TAB] Display all 1022 possibilities? (y or n) </code></pre> <p>We add a method <code>#baz</code> to <code>Object</code> which returns <code>Object</code> itself. Then we auto-complete to get the methods we can call on <code>Object.baz</code>. If IRB called <code>Object.baz.methods</code>, it would get the same thing as <code>Object.methods</code>. Instead, IRB has 1022 suggestions. I'm not sure where they come from, but it's clearly a generic list which isn't actually based on context.</p> <p>The <code>::</code> operator is (also) used for getting a module's constants, while <code>.</code> is not. That's why <code>HTTP</code> will show up in the completion for <code>Net::</code>, but not for <code>Net.</code>. <code>Net.HTTP</code> isn't correct, but <code>Net::HTTP</code> is.</p>
6,473
<p>I'm trying to make the case for click-once and smart client development but my network support team wants to keep with web development for everything.</p> <p>What is the best way to convince them that click-once and smart client development have a place in the business?</p>
<p>We use ClickOnce where I work; in terms of comparison to a web release I would base the case around the need for providing users with a rich client app, otherwise it might well actually be better to use web applications.</p> <p>In terms of releasing a rich client app ClickOnce is fantastic; you can set it up to enforce updates on startup thus enforcing a version throughout the network. You can make the case that ClickOnce gives you the same benefit of having a single deployment point that web deployment possesses.</p> <p>Personally I've found ClickOnce to be unbelievably useful. If you're developing rich client .net apps (in Windows, though let's face it the vast majority of real .net development <em>is</em> in Windows) and want to deploy it across a network nothing else compares.</p>
<p>They have a place in the Windows environment but not in any other environment and so if you intend on writing applications for external clients, then your probably best sticking with Web based development.</p> <p>I heard this "Write Once, Run Many" before from Microsoft when Asp.net 1.1 was released, it never happened in practice.</p>
5,887
<p>I've switched over to a Mac recently and, although things have been going quite well, the very different text-editing behaviours across applications is driving me insane.</p> <p><kbd>Home</kbd>, <kbd>End</kbd>, <kbd>Page Up</kbd>, <kbd>Page Down</kbd>, <kbd>Apple-arrow</kbd>, <kbd>Ctrl-arrow</kbd>, <kbd>alt-arrow</kbd> etc. quite often do different things depending on the application.</p> <p>Is there a way to standardise this behaviour?</p>
<p>There are standards, but they are not based around what you're used to from windows. It drove me mad until I got over myself and decided to learn what the actual standards were. Since then I've been sold.</p> <p>The ones I use:</p> <ul> <li><kbd>Command</kbd>-<kbd>Left</kbd>/<kbd>Right</kbd> - Jump to start/end of line <ul> <li>Can also do this with <kbd>ctrl</kbd>-<kbd>a</kbd>/<kbd>e</kbd> which is great if you're used to ssh</li> </ul></li> <li><p><kbd>Command</kbd>-<kbd>Up</kbd>/<kbd>Down</kbd> - Jump to top/bottom of text field or document</p></li> <li><p><kbd>Option</kbd>-<kbd>Left</kbd>/<kbd>Right</kbd> - Jump to start/end of word or previous/next word</p></li> </ul> <p>These basically replace <kbd>home</kbd>/<kbd>end</kbd>/<kbd>pgup</kbd>/<kbd>pgdown</kbd>, and <kbd>ctrl</kbd>-<kbd>left</kbd>/<kbd>right</kbd> from the windows world.</p> <p>I find this to be a massive win due to the fact I have a macbook pro and almost no laptops have proper <kbd>home</kbd>/<kbd>end</kbd>/<kbd>pgup</kbd>/<kbd>pgdown</kbd> keys - not needing them in OSX is a godsend</p> <p><a href="http://www.hcs.harvard.edu/~jrus/Site/System%20Bindings.html" rel="nofollow noreferrer">Here's a big list of the rest of them</a></p>
<p>And what's funny (and frustrating!) is that the Microsoft <strong>OS X</strong> apps (e.g. Entourage) use the <strong>Windows</strong> standards.</p> <p>I develop on WinXP during the day but have an iMac at home, so it's confusing enough trying to switch modes between work and home. But then I have to remember if I'm writing an e-mail in Entourage, I need to revert back to Windows mode.</p> <p>I can't think of any good reason why MS wouldn't follow the OS X keyboard standards...</p>
5,413
<p>I know in ASP.NET I can get an item from a DropDownList by using</p> <pre><code>DropDownList1.Items.FindByText </code></pre> <p>Is there a similar method I can use in WPF for a ComboBox?</p> <p>Here's the scenario.</p> <p>I have a table called RestrictionFormat that contains a column called RestrictionType, the type is a foreign key to a table that stores these values.</p> <p>In my editor application I'm writing, when the user selects the RestrictionFormat from a ComboBox (this works fine), I'm pulling up the details for editing. I'm using a second ComboBox to make sure the user only selects one RestrictionType when editing. I already have the second combobox bound property from the RestrictionType table, but I need to change the selected index on it to match the value specified in the record.</p> <hr> <p>Here's the scenario.</p> <p>I have a table called RestrictionFormat that contains a column called RestrictionType, the type is a foreign key to a table that stores these values.</p> <p>In my editor application I'm writing, when the user selects the RestrictionFormat from a ComboBox (this works fine), I'm pulling up the details for editing. I'm using a second ComboBox to make sure the user only selects one RestrictionType when editing. I already have the second combobox bound property from the RestrictionType table, but I need to change the selected index on it to match the value specified in the record.</p> <p>Does this make sense?</p>
<p>Can you use ItemContainerGenerator?</p> <p>ItemContainerGenerator contains a ContainerFromItem method that takes an object parameter. If you have a reference to the full object that your comboBox contains (or a way to reconstruct it), you can use the following:</p> <pre><code>ComboBoxItem item = (ComboBoxItem)myComboBox.ItemContainerGenerator.ContainerFromItem(myObject); </code></pre>
<p>You can retrieve combobox items in two ways:</p> <p>By item:</p> <pre><code>ComboBoxItem item = (ComboBoxItem) control.ItemContainerGenerator.ContainerFromItem(control.SelectedItem); </code></pre> <p>By index:</p> <pre><code>ComboBoxItem item = (ComboBoxItem) control.ItemContainerGenerator.ContainerFromIndex(1); </code></pre>
6,260
<p>I am making a bed for my 3D printer. I have bought a silicon heater (31x31 cm) and I want to glue it to my custom aluminum bed. The tape that it had from factory was bad, so I removed it. I want to glue it to the aluminum and I don't know what type of adhesive to use, I was thinking gasket glue with silicon, but I think that it will have bad thermal conductivity. I found <a href="https://www.annapol.eu/product_info.php?products_id=137997&amp;language=en" rel="nofollow noreferrer">this product, a silicon based, heat transferring paste</a>, but I think that it will not stick good. What is a good adhesive for this purpose?</p>
<p>Heat Transfer PAste will not work as a gluing agent. What you need is a high-temperature glue that bonds Aluminium and a silicone rubber. The benchmark temperature that the glue needs to withstand is about 100 °C or approximately 200 °F.</p> <p><a href="https://www.mcmaster.com/glue/for-use-on%7Ealuminum/for-joining%7Erubber/" rel="nofollow noreferrer">McMaster-Carr</a> allowed me to search for glue-properties and suggests among others contact adhesives, which are cans or tubes with a very viscous glue. You let that pre-cure on the items and then push the two together, resulting in very strong bonds. One of the items they suggest is <a href="https://www.3m.com/3M/en_US/company-us/all-3m-products/%7E/3M-Plastic-Adhesive-2262/?N=5002385%203293193728&amp;rt=rud" rel="nofollow noreferrer">3M 2262</a> for which McMaster-Carr lists 230 °F as the max temperature, so just in the <em>safe</em> range. However, a 32 oz. can for almost 100 $ is surely overkill, the <a href="https://multimedia.3m.com/mws/media/1015904O/3m-industrial-adhesives-and-tapes.pdf" rel="nofollow noreferrer">3M manufacturer catalog</a> lists only 1 qt and 5 gal as the available packaging sizes, so, unless you build printers for a living or know someone who uses this industrially, this is not an option.</p> <p>The same catalog also lists the <a href="https://www.3m.com/3M/en_US/company-us/all-3m-products/%7E/3M-Double-Coated-Tape-9496LE/?N=5002385%203293242019&amp;rt=rud" rel="nofollow noreferrer">&quot;3M™ 200MP&amp; 300LSE&quot;</a> series with temperatures of 148 °C (300 °F) to 204 °C (400 °F). That is enough to print anything on. And it's the same glue that' used on my Build-Tak replacement surfaces to stick them to the Aluminium bed, so it could be suitable for gluing the heater to the bed on the other side too. However, I wish you good luck to find a reseller that sells you a fitting amount. Industrial packaging is available, but you'll need to find a reseller that offers a somewhat fitting size for you - I have seen Amazon listings for both types in sizes that have only small waste for most common heaters.</p> <p><a href="https://i.stack.imgur.com/t3S0H.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/t3S0H.png" alt="enter image description here" /></a></p> <hr /> <p>I am not affiliated with 3M or McMaster-Carr, but I have very good experience with 300LSE.</p>
<p>Heat Transfer PAste will not work as a gluing agent. What you need is a high-temperature glue that bonds Aluminium and a silicone rubber. The benchmark temperature that the glue needs to withstand is about 100 °C or approximately 200 °F.</p> <p><a href="https://www.mcmaster.com/glue/for-use-on%7Ealuminum/for-joining%7Erubber/" rel="nofollow noreferrer">McMaster-Carr</a> allowed me to search for glue-properties and suggests among others contact adhesives, which are cans or tubes with a very viscous glue. You let that pre-cure on the items and then push the two together, resulting in very strong bonds. One of the items they suggest is <a href="https://www.3m.com/3M/en_US/company-us/all-3m-products/%7E/3M-Plastic-Adhesive-2262/?N=5002385%203293193728&amp;rt=rud" rel="nofollow noreferrer">3M 2262</a> for which McMaster-Carr lists 230 °F as the max temperature, so just in the <em>safe</em> range. However, a 32 oz. can for almost 100 $ is surely overkill, the <a href="https://multimedia.3m.com/mws/media/1015904O/3m-industrial-adhesives-and-tapes.pdf" rel="nofollow noreferrer">3M manufacturer catalog</a> lists only 1 qt and 5 gal as the available packaging sizes, so, unless you build printers for a living or know someone who uses this industrially, this is not an option.</p> <p>The same catalog also lists the <a href="https://www.3m.com/3M/en_US/company-us/all-3m-products/%7E/3M-Double-Coated-Tape-9496LE/?N=5002385%203293242019&amp;rt=rud" rel="nofollow noreferrer">&quot;3M™ 200MP&amp; 300LSE&quot;</a> series with temperatures of 148 °C (300 °F) to 204 °C (400 °F). That is enough to print anything on. And it's the same glue that' used on my Build-Tak replacement surfaces to stick them to the Aluminium bed, so it could be suitable for gluing the heater to the bed on the other side too. However, I wish you good luck to find a reseller that sells you a fitting amount. Industrial packaging is available, but you'll need to find a reseller that offers a somewhat fitting size for you - I have seen Amazon listings for both types in sizes that have only small waste for most common heaters.</p> <p><a href="https://i.stack.imgur.com/t3S0H.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/t3S0H.png" alt="enter image description here" /></a></p> <hr /> <p>I am not affiliated with 3M or McMaster-Carr, but I have very good experience with 300LSE.</p>
1,790
<p>When a previous Vim session crashed, you are greeted with the "Swap file ... already exists!" for each and every file that was open in the previous session.</p> <p>Can you make this Vim recovery prompt smarter? (Without switching off recovery!) Specifically, I'm thinking of:</p> <ul> <li>If the swapped version does not contain unsaved changes and the editing process is no longer running, can you make Vim automatically delete the swap file?</li> <li>Can you automate the suggested process of saving the recovered file under a new name, merging it with file on disk and then deleting the old swap file, so that minimal interaction is required? Especially when the swap version and the disk version are the same, everything should be automatic.</li> </ul> <p>I discovered the <code>SwapExists</code> autocommand but I don't know if it can help with these tasks.</p>
<p>I have vim store my swap files in a single local directory, by having this in my .vimrc:</p> <pre><code>set directory=~/.vim/swap,. </code></pre> <p>Among other benefits, this makes the swap files easy to find all at once. Now when my laptop loses power or whatever and I start back up with a bunch of swap files laying around, I just run my <code>cleanswap</code> script:</p> <pre><code>TMPDIR=$(mktemp -d) || exit 1 RECTXT="$TMPDIR/vim.recovery.$USER.txt" RECFN="$TMPDIR/vim.recovery.$USER.fn" trap 'rm -f "$RECTXT" "$RECFN"; rmdir "$TMPDIR"' 0 1 2 3 15 for q in ~/.vim/swap/.*sw? ~/.vim/swap/*; do [[ -f $q ]] || continue rm -f "$RECTXT" "$RECFN" vim -X -r "$q" \ -c "w! $RECTXT" \ -c "let fn=expand('%')" \ -c "new $RECFN" \ -c "exec setline( 1, fn )" \ -c w\! \ -c "qa" if [[ ! -f $RECFN ]]; then echo "nothing to recover from $q" rm -f "$q" continue fi CRNT="$(cat $RECFN)" if diff --strip-trailing-cr --brief "$CRNT" "$RECTXT"; then echo "removing redundant $q" echo " for $CRNT" rm -f "$q" else echo $q contains changes vim -n -d "$CRNT" "$RECTXT" rm -i "$q" || exit fi done </code></pre> <p>This will remove any swap files that are up-to-date with the real files. Any that don't match are brought up in a vimdiff window so I can merge in my unsaved changes.</p> <p>--Chouser</p>
<p>I prefer to not set my VIM working directory in the .vimrc. Here's a modification of chouser's script that copies the swap files to the swap path on demand checking for duplicates and then reconciles them. This was written rushed, make sure to evaluate it before putting it to practical use.</p> <pre><code>#!/bin/bash if [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then echo "Moves VIM swap files under &lt;base-path&gt; to ~/.vim/swap and reconciles differences" echo "usage: $0 &lt;base-path&gt;" exit 0 fi if [ -z "$1" ] || [ ! -d "$1" ]; then echo "directory path not provided or invalid, see $0 -h" exit 1 fi echo looking for duplicate file names in hierarchy swaps="$(find $1 -name '.*.swp' | while read file; do echo $(basename $file); done | sort | uniq -c | egrep -v "^[[:space:]]*1")" if [ -z "$swaps" ]; then echo no duplicates found files=$(find $1 -name '.*.swp') if [ ! -d ~/.vim/swap ]; then mkdir ~/.vim/swap; fi echo "moving files to swap space ~./vim/swap" mv $files ~/.vim/swap echo "executing reconciliation" TMPDIR=$(mktemp -d) || exit 1 RECTXT="$TMPDIR/vim.recovery.$USER.txt" RECFN="$TMPDIR/vim.recovery.$USER.fn" trap 'rm -f "$RECTXT" "$RECFN"; rmdir "$TMPDIR"' 0 1 2 3 15 for q in ~/.vim/swap/.*sw? ~/.vim/swap/*; do [[ -f $q ]] || continue rm -f "$RECTXT" "$RECFN" vim -X -r "$q" \ -c "w! $RECTXT" \ -c "let fn=expand('%')" \ -c "new $RECFN" \ -c "exec setline( 1, fn )" \ -c w\! \ -c "qa" if [[ ! -f $RECFN ]]; then echo "nothing to recover from $q" rm -f "$q" continue fi CRNT="$(cat $RECFN)" if diff --strip-trailing-cr --brief "$CRNT" "$RECTXT"; then echo "removing redundant $q" echo " for $CRNT" rm -f "$q" else echo $q contains changes vim -n -d "$CRNT" "$RECTXT" rm -i "$q" || exit fi done else echo duplicates found, please address their swap reconciliation manually: find $1 -name '.*.swp' | while read file; do echo $(basename $file); done | sort | uniq -c | egrep '^[[:space:]]*[2-9][0-9]*.*' fi </code></pre>
8,864
<p>I think I might be missing something here. Here is the relevant part of the trigger:</p> <pre><code> CURSOR columnNames (inTableName IN VARCHAR2) IS SELECT COLUMN_NAME FROM USER_TAB_COLUMNS WHERE TABLE_NAME = inTableName; /* Removed for brevity */ OPEN columnNames('TEMP'); </code></pre> <p>And here is the error message that I'm getting back,</p> <pre> 27/20 PLS-00306: wrong number or types of arguments in call to 'COLUMNNAMES' 27/2 PL/SQL: Statement ignored </pre> <p>If I am understanding the documentation correctly, that should work, but since it is not I must be doing something wrong. Any ideas?</p> <hr /> <p>@<a href="https://stackoverflow.com/questions/43832/pls-00306-error-on-call-to-cursor#43859">Matthew</a> - I appreciate the help, but the reason that I am confused is because this bit of code isn't working for me and is raising the errors referenced. We have other triggers in the database with code almost exactly the as that so I'm not sure if it is something that I did wrong, or something with how I am trying to store the trigger, etc.</p> <hr /> <p>@<a href="https://stackoverflow.com/questions/43832/pls-00306-error-on-call-to-cursor#43859">Matthew</a> - Well, now I get to feel embarrassed. I did a copy/paste of the code that you provided into a new trigger and it worked fine. So I went back into the original trigger and tried it and received the error message again, except this time I started to delete stuff out of the trigger and after getting rid of this line,</p> <pre><code>FOR columnName IN columnNames LOOP </code></pre> <p>Things saved fine. So it turns out that where I thought the error was, wasn't actually were the error was.</p>
<p>To clarify the cause of the issue. As you state </p> <p><strong>OPEN columnNames('TEMP');</strong> </p> <p>worked while </p> <p><strong>FOR columnName IN columnNames LOOP</strong></p> <p>did not. The FOR statement would work fine if it also included the parameter like so:</p> <p><strong>FOR columnName IN columnNames('TEMP') LOOP</strong></p> <p>You don't show the code where you fetch the rows so I can't tell your purpose, but where I work OPEN is commonly used to fetch the first row (in this case, the first column name of the given table) while the FOR is used to iterate through all returned rows.</p> <p>@Rob's comment. I'm not allowed to comment so updating here instead. The missing parameter is what I describe above. You added a response stating you simply deleted the FOR loop. It did not look like you, at the time, understood why deleting it made a difference. Which is why I attempted to explain since, depending on your need, the FOR loop might be a better solution.</p>
<p>Works fine for me.</p> <pre><code>create or replace procedure so_test_procedure as CURSOR columnNames (inTableName IN VARCHAR2) IS SELECT COLUMN_NAME FROM USER_TAB_COLUMNS WHERE TABLE_NAME = inTableName; BEGIN OPEN columnNames('TEMP'); CLOSE columnNames; END; procedure so_test_procedure Compiled. execute so_test_procedure(); anonymous block completed </code></pre>
6,546
<p>What's the best way to convert a string to an enumeration value in C#?</p> <p>I have an HTML select tag containing the values of an enumeration. When the page is posted, I want to pick up the value (which will be in the form of a string) and convert it to the corresponding enumeration value.</p> <p>In an ideal world, I could do something like this:</p> <pre><code>StatusEnum MyStatus = StatusEnum.Parse(&quot;Active&quot;); </code></pre> <p>but that isn't a valid code.</p>
<p>In .NET Core and .NET Framework ≥4.0 <a href="https://msdn.microsoft.com/en-us/library/dd783499%28v=vs.110%29.aspx" rel="noreferrer">there is a generic parse method</a>:</p> <pre><code>Enum.TryParse(&quot;Active&quot;, out StatusEnum myStatus); </code></pre> <p>This also includes C#7's new inline <code>out</code> variables, so this does the try-parse, conversion to the explicit enum type and initialises+populates the <code>myStatus</code> variable.</p> <p>If you have access to C#7 and the latest .NET this is the best way.</p> <h2>Original Answer</h2> <p>In .NET it's rather ugly (until 4 or above):</p> <pre><code>StatusEnum MyStatus = (StatusEnum) Enum.Parse(typeof(StatusEnum), &quot;Active&quot;, true); </code></pre> <p>I tend to simplify this with:</p> <pre><code>public static T ParseEnum&lt;T&gt;(string value) { return (T) Enum.Parse(typeof(T), value, true); } </code></pre> <p>Then I can do:</p> <pre><code>StatusEnum MyStatus = EnumUtil.ParseEnum&lt;StatusEnum&gt;(&quot;Active&quot;); </code></pre> <p>One option suggested in the comments is to add an extension, which is simple enough:</p> <pre><code>public static T ToEnum&lt;T&gt;(this string value) { return (T) Enum.Parse(typeof(T), value, true); } StatusEnum MyStatus = &quot;Active&quot;.ToEnum&lt;StatusEnum&gt;(); </code></pre> <p>Finally, you may want to have a default enum to use if the string cannot be parsed:</p> <pre><code>public static T ToEnum&lt;T&gt;(this string value, T defaultValue) { if (string.IsNullOrEmpty(value)) { return defaultValue; } T result; return Enum.TryParse&lt;T&gt;(value, true, out result) ? result : defaultValue; } </code></pre> <p>Which makes this the call:</p> <pre><code>StatusEnum MyStatus = &quot;Active&quot;.ToEnum(StatusEnum.None); </code></pre> <p>However, I would be careful adding an extension method like this to <code>string</code> as (without namespace control) it will appear on all instances of <code>string</code> whether they hold an enum or not (so <code>1234.ToString().ToEnum(StatusEnum.None)</code> would be valid but nonsensical) . It's often be best to avoid cluttering Microsoft's core classes with extra methods that only apply in very specific contexts unless your entire development team has a very good understanding of what those extensions do.</p>
<p>First of all, you need to decorate your enum, like this:</p> <pre><code> public enum Store : short { [Description(&quot;Rio Big Store&quot;)] Rio = 1 } </code></pre> <p>in .net 5, i create this extension method:</p> <pre><code>//The class also needs to be static, ok? public static string GetDescription(this System.Enum enumValue) { FieldInfo fi = enumValue.GetType().GetField(enumValue.ToString()); DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes( typeof(DescriptionAttribute), false); if (attributes != null &amp;&amp; attributes.Length &gt; 0) return attributes[0].Description; else return enumValue.ToString(); } </code></pre> <p>now you have an extension methods to use in any Enums</p> <p>Like this:</p> <pre><code>var Desc = Store.Rio.GetDescription(); //Store is your Enum </code></pre>
3,682
<p>I'm attaching a picture to show my issue. I'm hoping might be an easy settings fix, or at least maybe someone has a couple suggestions I can try. I'm using an Ender 3, and the program Cura. The print on the left was printed with the opening facing up. The print on the right with the hole facing down. The support leaves a rough surface. Any suggestions for support settings would be appreciated. <a href="https://i.stack.imgur.com/AnkLP.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AnkLP.jpg" alt="enter image description here" /></a></p>
<p>There's only so much you can do about this without a multi-material printer that can utilize dissolvable material or material that doesn't bond to the print material, and print the supports at zero distance from the model. So expect it to be ugly. But not quite that ugly.</p> <p>Slicers, including Cura, have options to control the Z distance between the support material and your model, among other things. Reducing this will make it harder to remove the supports, but will give a better bottom surface. It only really works on whole-layer granularity in Cura (while some other slicers let you do arbitrary distances), and really should always be equal to one layer. A distance of two or more layers will give really bad results, which might be what you're seeing.</p> <p>Also, Cura has an option called &quot;support interface&quot;, which you want on. This prints a flat top surface on top of the support, below your print, so that all the lines of the print have something they're resting on. Without this, the bottom surface over the support will sag down between the lines of the support and look very bad - or, if it's a small detail, it might sink entirely between lines of the support and effectively not be supported at all!</p> <p>Finally, one hack you can try if you don't have a multi-material printer but want to try printing supports at zero distance from your model: set support Z distance to zero and use a slicer plugin to pause-at-height just past the top surface of the support. Then, when the printer pauses, paint a release agent that won't bond to the print material on top of the support. Reportedly Sharpie permanent markers work as such a release agent, but I haven't tried this, and there are probably better choices.</p>
<p>You cannot print into the air (hot filament will sag when not supported). Do remember that even with support enabled, you are printing into air. This is because there is always a gap between the print object and the support structure, the option is called <code>Z distance</code>. If there wasn't a gap, the print object will fuse to the support structure. You may want to increase fan cooling or decrease the Z distance between support and print object to get better print results, but, print orientation is also important, sometimes placing an object under an angle works. In the example you provided, it is clear that it is better printed upright (unless there is a recess at the other side).</p> <p>From experience, to increase the surface above the support structure, having the option <code>Enable support interface</code> enabled will add a dense surface on top of the support structure. This surface, in conjunction with the correct gap and cooling when dialed in correctly will provide better surfaces above support structures.</p> <hr /> <p><a href="https://support.ultimaker.com/hc/en-us/articles/360012612779-Support-settings" rel="nofollow noreferrer"><strong>Z distance</strong> <em>(in Ultimaker Cura)</em></a></p> <p><em>This refers to the distance from the top and bottom of the support structure relative to the model. This setting is divided into the top distance and bottom distance. The top distance defines the distance between the top of the support and bottom of the model and the bottom distance refers to the distance between the bottom of the support and top part of the model.</em></p> <p><a href="https://i.stack.imgur.com/KMUX6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KMUX6.png" alt="enter image description here" /></a></p> <p><em>A small distance between the support structure and parts of the model is necessary in order to remove the supports easily after the model has been printed. A low value creates a smoother surface, but can also make it more difficult to remove the support properly.</em></p>
2,197
<p>I have an object graph serialized to xaml. A rough sample of what it looks like is:</p> <pre><code>&lt;MyObject xmlns.... &gt; &lt;MyObject.TheCollection&gt; &lt;PolymorphicObjectOne .../&gt; &lt;HiImPolymorphic ... /&gt; &lt;/MyObject.TheCollection&gt; &lt;/MyObject&gt; </code></pre> <p>I want to use Linq to XML in order to extract the serialized objects within the TheCollection.</p> <p><strong>Note</strong>: <code>MyObject</code> may be named differently at runtime; I'm interested in any object that implements the same interface, which has a public collection called <code>TheCollection</code> that contains types of <code>IPolymorphicLol</code>.</p> <p>The only things I know at runtime are the depth at which I will find the collection and that the collection element is named ``*.TheCollection`. Everything else will change.</p> <p>The xml will be retrieved from a database using Linq; if I could combine both queries so instead of getting the entire serialized graph and then extracting the collection objects I would just get back the collection that would be sweet.</p>
<p>I am using the <code>GacInstall</code> to publish my assemblies, however once installed into the gac, I sometimes delete my ‘temporary’ copy of the assemblies.</p> <p>And then, if I ever wanted to uninstall the assemblies from the gac I do not have the files at the original path. This is causing a problem since I cannot seem to get the <code>GacRemove</code> method to uninstall the assemblies unless I keep the original files.</p> <p>Conclusion: Yes, you need to specify the path to the original DLL. (And try to not move/delete it later). If you delete it, try to copy the file from the GAC to your original path and you should be able to uninstall it using <code>GacRemove</code>.</p>
<p>I am not exactly sure about it but I believe GacRemove should do the same thing as gacutil /u. So, it should be the path of your DLL. However it doesn't have to be the same DLL file. Copy of the original should suffice since what counts is the uniqueID of the DLL.</p>
6,773
<p>I'm currently attempting to make a repstrap using paper printed parts, like this guy : <a href="http://www.mariolukas.de/2012/05/repstrap-3d-drucker-aus-computerschrott-teil-1/" rel="nofollow noreferrer">http://www.mariolukas.de/2012/05/repstrap-3d-drucker-aus-computerschrott-teil-1/</a> I replaced the DC motor in a paper printer carriage assembly</p> <p>with a stepper motor (NEMA17). But there was not enough space to fit the axis of the nema 17 at the exact spot of the older DC motor axis, in short, the axis are not in the same place. The question is : if the axis is not in the exact same spot, will it affect the movement of the carriage or not at all ?<a href="https://i.stack.imgur.com/8A21q.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8A21q.png" alt="new and old belt driven axis"></a></p> <p>I supposed it would but i'm not sure since the carriage is limited in movement by the rails and that we still move the belt around.</p>
<p>Axis should definitely be at proper position. Otherwise you will get at least 2 issues.</p> <ol> <li>Carriage will be pulled up which will cause stresses on rollers or slides and it will stress your belt</li> <li>The way the carriage will go will change but because carriage itself is fixed then it will change the speed</li> </ol> <p>3D printing is a precise process. Both issues will have impact on printouts and all your printouts will have broken dimension in the axis in which carriage moves.</p> <p>Have a look on the picture (it is big to show details)</p> <p><a href="https://i.stack.imgur.com/maQ3j.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/maQ3j.png" alt="enter image description here"></a></p> <p><strong>fig A</strong> shows a situation where carriage is far from the axis</p> <p>In such situation the distance between vertical line of black cross and pink circle is almost unnoticable so both - the force and the distance (so speed) change are very small.</p> <p><strong>fig B</strong> shows a situation where carriage is relatively close to the axis</p> <p>Then both - the force and the distance change is noticable </p>
<p>A rotation of the stepper motor 90 degrees clockwise or counter-clockwise would move it more to the center. You would only need lengthen or shorten the belt.</p>
365
<p>I have seen <a href="https://stackoverflow.com/questions/4046/can-someone-give-me-a-working-example-of-a-buildxml-for-an-ear-that-deploys-in">this question</a> about deploying to WebSphere using the WAS ant tasks.</p> <p>Is there a simpler way to do this? In the past I have deployed to Tomcat by dropping a war file into a directory. I was hoping there would be a similar mechanism for WebSphere that doesn't involve calling the IBM libraries or rely on RAD to be installed on your workstation.</p>
<p>There is the concept of <a href="http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/index.jsp?topic=/com.ibm.etools.wrd.freeform.doc/topics/cwrdrapid.html" rel="nofollow noreferrer">WebSphere Rapid Deployment</a>. It's supposed to be the same experience as what you describe for Tomcat.</p>
<p>WAS does provide a client jar containing some custom ant tasks. However they seem to be extremely bugy and dont work with remote servers.</p> <p><a href="http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/index.jsp?topic=/com.ibm.websphere.javadoc.doc/public_html/api/com/ibm/websphere/ant/tasks/InstallApplication.html" rel="nofollow noreferrer">IBM ANT TASK Javadoc</a></p> <p>Netbeans also has support for was 6 and 6.1 but this again is still quite buggy, however it can be useful for generating some the bindings files etc.</p>
8,150
<p>I have some HTML that is generated via a Rich Text Editor outside of my Flex application but would like to display it inside Flex. </p> <p>The HTML is simple HTML tags, things like styles, anchors, and possibly image tags, is there a control that would let me render this HTML in flex or am I going to have to roll up my sleeves and roll my own?</p> <p>Any ideas appreciated...Thanks.</p>
<p>If the HTML is <em>really</em> simple, you can display it in a normal label or textarea component, If it is more complex, I'll quote what I answered <a href="https://stackoverflow.com/questions/22909/is-there-some-way-to-show-html-content-inside-flash">in this question</a>. The discussion there also has a little more info.</p> <blockquote> <p>If it is complex HTML and Javascript, one possible way is <a href="http://drumbeatinsight.com/htmlcomponent" rel="nofollow noreferrer">HTMLComponent</a>, a method that uses an iframe over your flash to make it appear like the HTML is in your app. There are a few downsides to this method however - most of them described in detail <a href="http://www.deitte.com/archives/2008/07/dont_use_iframe.htm" rel="nofollow noreferrer">at Deitte.com</a>.</p> <p>If this can move offline, you could use Air (it has an mx:HTML component built in). <a href="http://www.deitte.com/archives/2008/07/an_air_version.htm" rel="nofollow noreferrer">Deitte.com</a> has a detail of this technique as well.</p> </blockquote>
<p>@mmattax</p> <p>Indeed you can display images in a TextArea component. The approach <a href="http://aralbalkan.com/239" rel="nofollow noreferrer">is not entirely without problems though</a>...</p>
7,384
<p>Is there a simple way in .NET to quickly get the current protocol, host, and port? For example, if I'm on the following URL:</p> <p><code>http://www.mywebsite.com:80/pages/page1.aspx</code></p> <p>I need to return:</p> <p><code>http://www.mywebsite.com:80</code></p> <p>I know I can use <code>Request.Url.AbsoluteUri</code> to get the complete URL, and I know I can use <code>Request.Url.Authority</code> to get the host and port, but I'm not sure of the best way to get the protocol without parsing out the URL string.</p> <p>Any suggestions?</p>
<p>The following (C#) code should do the trick</p> <pre><code>Uri uri = new Uri("http://www.mywebsite.com:80/pages/page1.aspx"); string requested = uri.Scheme + Uri.SchemeDelimiter + uri.Host + ":" + uri.Port; </code></pre>
<p>In my case</p> <pre><code>Uri uri = new Uri(&quot;http://www.mywebsite.com:80/pages/page1.aspx&quot;); string requested = uri.Scheme + Uri.SchemeDelimiter + uri.Authority; </code></pre> <p>works to get</p> <p><a href="https://www.mywebsite.com:80" rel="nofollow noreferrer">https://www.mywebsite.com:80</a></p>
4,176
<p>I'd like my program to be able to email me error reports. How can I do this without hard-coding a username/password/SMTP server/etc. into the code? (Doing so would allow users to decompile the program and take over this email account.)</p> <p>I've been told you could do some stuff with telneting to port 25, but I'm very fuzzy on the details. Most of the code snippets on Google assume you have a preexisting account, which doesn't work in this situation.</p> <p>I am using .NET v3.5 (C# in particular), but I would imagine the ideas are similar enough in most languages. As long as you realize I'm doing this for an offline app, and don't supply me with PHP code or something, we should be fine.</p>
<p>As long as your account is on gmail.com, set up <strong>gmail-smtp-in.l.google.com</strong> as the outgoing SMTP-server in your program. You do not need to provide a password to send email to gmail-accounts when using that server.</p>
<pre><code>MailMessage msg = new MailMessage("someone@foo.com", "someoneelse@bar.com"); msg.Subject = "Check it out!"; msg.Body = "Visit stackoverflow.com!"; SmtpClient client = new SmtpClient("some.smtp.server", 25); client.Send(msg); </code></pre>
4,981
<p>I'm working on an internal project for my company, and part of the project is to be able to parse various "Tasks" from an XML file into a collection of tasks to be ran later.</p> <p>Because each type of Task has a multitude of different associated fields, I decided it would be best to represent each type of Task with a seperate class.</p> <p>To do this, I constructed an abstract base class:</p> <pre><code>public abstract class Task { public enum TaskType { // Types of Tasks } public abstract TaskType Type { get; } public abstract LoadFromXml(XmlElement task); public abstract XmlElement CreateXml(XmlDocument currentDoc); } </code></pre> <p>Each task inherited from this base class, and included the code necessary to create itself from the passed in XmlElement, as well as serialize itself back out to an XmlElement.</p> <p>A basic example:</p> <pre><code>public class MergeTask : Task { public override TaskType Type { get { return TaskType.Merge; } } // Lots of Properties / Methods for this Task public MergeTask (XmlElement elem) { this.LoadFromXml(elem); } public override LoadFromXml(XmlElement task) { // Populates this Task from the Xml. } public override XmlElement CreateXml(XmlDocument currentDoc) { // Serializes this class back to xml. } } </code></pre> <p>The parser would then use code similar to this to create a task collection:</p> <pre><code>XmlNode taskNode = parent.SelectNode("tasks"); TaskFactory tf = new TaskFactory(); foreach (XmlNode task in taskNode.ChildNodes) { // Since XmlComments etc will show up if (task is XmlElement) { tasks.Add(tf.CreateTask(task as XmlElement)); } } </code></pre> <p>All of this works wonderfully, and allows me to pass tasks around using the base class, while retaining the structure of having individual classes for each task.</p> <p>However, I am not happy with my code for TaskFactory.CreateTask. This method accepts an XmlElement, and then returns an instance of the appropriate Task class:</p> <pre><code>public Task CreateTask(XmlElement elem) { if (elem != null) { switch(elem.Name) { case "merge": return new MergeTask(elem); default: throw new ArgumentException("Invalid Task"); } } } </code></pre> <p>Because I have to parse the XMLElement, I'm using a huge (10-15 cases in the real code) switch to pick which child class to instantiate. I'm hoping there is some sort of polymorphic trick I can do here to clean up this method.</p> <p>Any advice?</p>
<p>I use reflection to do this. You can make a factory that basically expands without you having to add any extra code.</p> <p>make sure you have "using System.Reflection", place the following code in your instantiation method.</p> <pre><code>public Task CreateTask(XmlElement elem) { if (elem != null) { try { Assembly a = typeof(Task).Assembly string type = string.Format("{0}.{1}Task",typeof(Task).Namespace,elem.Name); //this is only here, so that if that type doesn't exist, this method //throws an exception Type t = a.GetType(type, true, true); return a.CreateInstance(type, true) as Task; } catch(System.Exception) { throw new ArgumentException("Invalid Task"); } } } </code></pre> <p>Another observation, is that you can make this method, a static and hang it off of the Task class, so that you don't have to new up the TaskFactory, and also you get to save yourself a moving piece to maintain.</p>
<p>@ChanChan</p> <p>I like the idea of reflection, yet at the same time I've always been shy to use reflection. It's always struck me as a "hack" to work around something that should be easier. I did consider that approach, and then figured a switch statement would be faster for the same amount of code smell.</p> <p>You did get me thinking, I don't think the Type enum is needed, because I can always do something like this:</p> <pre><code>if (CurrentTask is MergeTask) { // Do Something Specific to MergeTask } </code></pre> <p>Perhaps I should crack open my GoF Design Patterns book again, but I really thought there was a way to polymorphically instantiate the right class.</p>
4,696
<p>I have a (HIC) version of the Prusa i3. I have recently installed the E3D v6 hotend and titan extruder. After fixing some other issues, I noticed that there is no filament being extruded. In addition, the gear looked like it was going in the wrong direction. How can I fix this?</p>
<p>You can either flip the connector for the motor around (i.e. plug it in backwards) or (if you are using Marlin firmware) look for the following line in configuration.h: (using the Arduino editor open the Marlin file For your 3D Printer, one of the tabs is labelled "configuration.h" click on that tab to bring it to the front for editing. use the Edit, Find and put E0 in the find box, click find. When you find the line below</p> <pre><code>#define INVERT_E0_DIR false </code></pre> <p>change <code>false</code> to <code>true</code> (or vice-versa). Note that if you go for the connector-flipping route, make sure that you only do this when the printer is turned off.</p>
<p>Reverse the plug for the motor on the board. Or do firmware. Doesn't matter. *** assuming you have ramps and a standard stepper.. </p>
320
<p>Just as the title says. I feel like I have tried everything. I am compiling the firmware for Marlin on a Megatronics board from RepRap. That shouldn't be relevant, because I have validated that it is a firmware issue (and not a pin assignment/hardware issue).</p> <p>When I turn it on, the Y-axis is active and just constantly holding. The stepper driver on Y-axis gets pretty warm constantly holding (as does the stepper motor).</p> <p>When I swap the pin assignments for Y and X then the physical Y-axis moves fine when I manually change the X-axis so I know all the hardware and pin assignments are correct.</p> <p>All the endstops are correctly reporting open (Z is BLTouch but that is also working).</p> <p>Relevant software endstops are currently disabled, and default homing position is set to 50 to make sure it doesn't think it is at the bounds on boot.</p> <p>I have a test firmware that checks all the endstops, temperature, and servos, and all servos work fine. As a sanity check, pin assignments match what is in the pins file.</p> <p>Does anyone have any idea of what in the latest Marlin firmware would cause a software condition to just hold the y axis and not move? I should note that when I try to manually move it in Repetier-Host it shows that it is moving. When I try to give the home command, no movement on the Y but Repetier changes from red to black indicating it received confirmation of homing.</p> <p>I am completely out of ideas at this point.</p>
<p>I did a simple search at <a href="http://www.huski.ai" rel="nofollow noreferrer">www.huski.ai</a>, and found 11 trademarks with the mark word &quot;FabLab&quot;.</p> <p><a href="https://i.stack.imgur.com/PXPXU.png" rel="nofollow noreferrer" title="Screenshot of search"><img src="https://i.stack.imgur.com/PXPXU.png" alt="Screenshot of search" title="Screenshot of search" /></a></p> <p>As you can see, most of them are abandoned, but there are 3 alive ones by a company called JO-ANN STORES, INC. Their categories are something like &quot;paper goods&quot;, &quot;fabrics&quot;, or &quot;furnitures&quot;, etc. So I think there's still room for you to register it under electronics.</p>
<p>Sorry, I needed to learn to use the site. This site shows Fablab as a word mark, the same way it shows Apple: <a href="https://www.trademarkengine.com/free-trademark-search/trademark-search" rel="nofollow noreferrer">https://www.trademarkengine.com/free-trademark-search/trademark-search</a></p>
1,868
<p>I am new to 3D printing and have an Ender 5 Pro.</p> <p>I have manually leveled the bed by setting the nozzle gap to 0.1 mm (via feeler gauges) and then printing a calibration print and manually adjusting the bed height as it prints. I can get perfect calibration prints using both a glass bed and a PEI bed, printing with a bed temp of 75 °C and a nozzle temp of 210 °C:</p> <p><a href="https://i.stack.imgur.com/rPi1S.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rPi1S.jpg" alt="enter image description here" /></a></p> <p>I’m now trying various other prints without success, as the print doesn’t adhere. See this example of a 1 mm thick bookmark, which I am printing with a brim to try and help :</p> <p><a href="https://i.stack.imgur.com/G4sDz.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/G4sDz.jpg" alt="enter image description here" /></a></p> <p>I’m not sure what the experts here can ascertain from this failed print without all the slicing parameters. I’m a bit suspicious that the print appears to clump and I’m wondering if the soft extruded material is sticking to the PLA already laid down and if so, if I can address that?</p> <p>I actually seemed to have more success with the original flexible bed with several successful prints.</p> <p>The G-code for the calibration target: <a href="https://pastebin.com/Brc8R8Cs" rel="nofollow noreferrer">https://pastebin.com/Brc8R8Cs</a></p> <p>and for the bookmark: <a href="https://pastebin.com/9AXaqiMw" rel="nofollow noreferrer">https://pastebin.com/9AXaqiMw</a></p> <p>I had to remove a lot of the G-code for the bookmark due to its size, so hopefully I've left the important stuff in.</p> <p>I started printing by loading the models in CURA, slicing and exporting to an SD card. I didn't;t create a new project for each print and it took me a while to realise I was losing the slicing parameters I'd used each time, making it difficult or impossible to go back and just change one set of parms. I'm now creating a separate project, so hopefully from now on I can just tweak one or 2 parms.</p>
<p>Well I got a perfect print as follows:</p> <ol> <li>Loaded the .stl file.</li> <li>Set Cura to use the 'Good' profile downloaded from CHEPCLUB (recommended by a friend).</li> <li>Used <strike>Pritt-stick</strike> Scotch (glue stick) on the bed.</li> </ol> <p>I was quite loath to use glue stick, as I thought heated beds etc didn't need it, but if that's what it takes then...</p> <p>I even bought an enclosure a few days ago as the room the printer was in if fairly cool.</p> <p>I'll try the exact same print without the glue and see if that works but at least I know know that I can get a perfect print and that a good calibration print isn't the be-all and end-all.</p>
<p>For a good adhesion the print bed should be free of any oil or fat. Wipe the print bed with pure alcohol just befor the start of printing.</p>
2,040
<p>I bought a few new nozzles expecting them to come with that little tube that comes out of the nozzle. They didn't come with them after all, so I tried to reuse the tube I originally had in the printer. Turns out my old tube is 4mm OD and 2mm ID, but the new nozzles have 2mm holes for the tube to go in. I use 1.75mm filament, so it seems like to be able to fit the filament through the tube would be impossible barring a tube with an 0.125mm wall. </p> <p>My question is, can I put the tube outside of the nozzle? That is, not stuck in the hole for the nozzle. In theory, the tube would still direct the filament into the right place. It looks like that might be the point of these new nozzles, since it seems so unlikely that someone would be able to stick a filament tube in the nozzle. </p> <p>If not, where can I find the tubes I need? I've looked in a few different places and I can't find it. Or are the nozzles useless, and should I return them? Thanks for the help. </p>
<p>To answer your question directly, the PTFE tube (or a separate thin walled PTFE tube for the bottom part of the heatbreak) <em>generally</em> always is outside the nozzle, so yes (unless you have an all-metal hotend, then there is no PTFE tube up to the nozzle). But as read from your question, your setup has the tube included inside the nozzle (this is described in more detail below). However, you can change the nozzle for one that does not have the PTFE tube go into the nozzle but rest against the nozzle provided you can find the correct sized nozzle/tread for it.</p> <p>The nozzles your printer uses are non standard nozzles that are featured on a few printer designs. It is called an "MK10" nozzle, but there is <a href="https://3dprinting.stackexchange.com/a/7366/5740">no such thing as a standard "MK10" nozzle</a>. Different designs of the "MK10" nozzle exist. Originally, the "MK nozzles" are the creation of Makerbot; an excellent post found in <a href="https://groups.google.com/forum/m/#!topic/wanhao-printer-3d/TEdslEknny4" rel="nofollow noreferrer">this thread</a> (all credits for the MK history go to user "<em>vermon</em>") discuss the development over time of the "MK" nozzles. An answer based on this posting is found <a href="https://3dprinting.stackexchange.com/a/5437/5740">here</a>.</p> <p>The nozzle your printer has is slightly larger than normal nozzles. The CEO of ToyBuilder labs explains the difference between an "MK10" and an MK8 in <a href="https://www.youtube.com/watch?v=UnI0aeTw9iA" rel="nofollow noreferrer">this video</a>. Take care of the thread size of such nozzles, the "MK10" uses M7 threads, while M6 is more common!</p> <p><a href="https://i.stack.imgur.com/Ah8Od.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ah8Od.png" alt="&quot;MK10&quot; vs. MK8 nozzle"></a></p> <p>As explained in <a href="https://3dprinting.stackexchange.com/a/7498/5740">this answer</a>, the use of the PTFE tube inside the nozzle is questionable. The heating zone in effect is reduced to the tip of the nozzle. The heat transfer from heating element, to heater block to nozzle is only possible because of the enlarged design and the flange that give extra surface area for heat conduction to take place. It is not expected that such nozzles are able to print optimally at high speeds.</p>
<p>Yes, you can use a direct drive hotend with a bowden tube, but it won't just plug together. You just need a way to secure the end of the bowden tube to be centered above and as close the the hotend mouth as possible. In a pinch, you can spin a 4mm nut onto the tube and secure it down against the hotend mount with zipties, otherwise I would print a nice bracket.</p> <p>It may be more prone to jam on filament swaps than a proper bowden configured hotend but it will work fine in normal use.</p> <p>Edit, I was under the impression you were speaking of the bowden tube between the extruder and the hotend, not the liner inside of the hotend.</p>
1,104
<p>We all know T-SQL's string manipulation capabilities sometimes leaves much to be desired...</p> <p>I have a numeric field that needs to be output in T-SQL as a right-aligned text column. Example:</p> <pre><code>Value ---------- 143.55 3532.13 1.75 </code></pre> <p>How would you go about that? A good solution ought to be clear and compact, but remember there is such a thing as "too clever".</p> <p>I agree this is the wrong place to do this, but sometimes we're stuck by forces outside our control.</p> <p>Thank you.</p>
<p>The <a href="http://msdn.microsoft.com/en-us/library/ms189527.aspx" rel="noreferrer">STR function</a> has an optional length argument as well as a number-of-decimals one.</p> <pre><code>SELECT STR(123.45, 6, 1) ------ 123.5 (1 row(s) affected) </code></pre>
<p>If you MUST do this in SQL you can use the folowing code (This code assumes that you have no numerics that are bigger than 40 chars):</p> <pre><code>SELECT REPLICATE(' ', 40 - LEN(CAST(numColumn as varchar(40)))) + CAST(numColumn AS varchar(40)) FROM YourTable </code></pre>
8,112
<p>A database application that I'm currently working on, stores all sorts of settings in the database. Most of those settings are there to customize certain business rules, but there's also some other stuff in there.</p> <p>The app contains objects that specifically do a certain task, e.g., a certain complicated calculation. Those non-UI objects are unit-tested, but also need access to lots of those global settings. The way we've implemented this right now, is by giving the objects properties that are filled by the Application Controller at runtime. When testing, we create the objects in the test and fill in values for testing (not from the database).</p> <p>This works better, in any case much better than having all those objects need some global <em>Settings</em> object --- that of course effectively makes unit testing impossible :) Disadvantage can be that you sometimes need to set a dozen of properties, or that you need to let those properties 'percolate' into sub-objects.</p> <p><strong>So the general question is</strong>: how do you provide access to global application settings in your projects, without the need for global variables, while still being able to unit test your code? This must be a problem that's been solved 100's of times...</p> <p>(Note: I'm not too much of an experienced programmer, as you'll have noticed; but I love to learn! And of course, I've already done research into this topic, but I'm really looking for some first-hand experiences)</p>
<p>You could use Martin Fowlers ServiceLocator pattern. In php it could look like this:</p> <pre><code>class ServiceLocator { private static $soleInstance; private $globalSettings; public static function load($locator) { self::$soleInstance = $locator; } public static function globalSettings() { if (!isset(self::$soleInstance-&gt;globalSettings)) { self::$soleInstance-&gt;setGlobalSettings(new GlobalSettings()); } return self::$soleInstance-&gt;globalSettings; } } </code></pre> <p>Your production code then initializes the service locator like this:</p> <pre><code>ServiceLocator::load(new ServiceLocator()); </code></pre> <p>In your test-code, you insert your mock-settings like this:</p> <pre><code>ServiceLocator s = new ServiceLocator(); s-&gt;setGlobalSettings(new MockGlobalSettings()); ServiceLocator::load(s); </code></pre> <p>It's a repository for singletons that can be exchanged for testing purposes.</p>
<p>Usually this is handled by an ini file or XML configuration file. Then you just have a class that reads the setting when neeed.</p> <p>.NET has this built in with the ConfigurationManager classes, but it's quite easy to implement, just read text files, or load XML into DOM or parse them by hand in code.</p> <p>Having config files in the database is ok, but it does tie you to the database, and creates an extra dependancy for your app that ini/xml files solve.</p>
3,322
<p>I'm having a little trouble figuring out exactly how const applies in a specific case. Here's the code I have:</p> <pre><code>struct Widget { Widget():x(0), y(0), z(0){} int x, y, z; }; struct WidgetHolder //Just a simple struct to hold four Widgets. { WidgetHolder(Widget a, Widget b, Widget c, Widget d): A(a), B(b), C(c), D(d){} Widget&amp; A; Widget&amp; B; Widget&amp; C; Widget&amp; D; }; class Test //This class uses four widgets internally, and must provide access to them externally. { public: const WidgetHolder AccessWidgets() const { //This should return our four widgets, but I don't want anyone messing with them. return WidgetHolder(A, B, C, D); } WidgetHolder AccessWidgets() { //This should return our four widgets, I don't care if they get changed. return WidgetHolder(A, B, C, D); } private: Widget A, B, C, D; }; int main() { const Test unchangeable; unchangeable.AccessWidgets().A.x = 1; //Why does this compile, shouldn't the Widget&amp; be const? } </code></pre> <p>Basically, I have a class called test. It uses four widgets internally, and I need it to return these, but if test was declared const, I want the widgets returned const also.</p> <p>Can someone explain to me why the code in main() compiles?</p> <p>Thank you very much.</p>
<p>This compiles because although the WidgetHolder is a const object, this const-ness does not automatically apply to objects pointed to (referenced by) the WidgetHolder. Think of it at a machine level - if the WidgetHolder object itself were held in read-only memory, you could still write to things that were pointed to by the WidgetHolder.</p> <p>The problem appears to lie in this line:</p> <pre><code>WidgetHolder(Widget a, Widget b, Widget c, Widget d): A(a), B(b), C(c), D(d){} </code></pre> <p>As Frank mentioned, your references inside the WidgetHolder class are going to hold invalid references after the constructor returns. Therefore, you should change this to:</p> <pre><code>WidgetHolder(Widget &amp;a, Widget &amp;b, Widget &amp;c, Widget &amp;d): A(a), B(b), C(c), D(d){} </code></pre> <p>After you do that, it won't compile, and I leave it as an exercise for the reader to work out the rest of the solution.</p>
<p>EDIT: he deleted his answer, making me look a bit foolish :)</p> <p>The answer by Flame is dangerously wrong. His WidgetHolder takes a reference to a value object in the constructor. As soon as the constructor returns, that passed-by-value object will be destroyed and so you'll hold a reference to a destroyed object.</p> <p>A very simple sample app using his code clearly shows this:</p> <pre><code>#include &lt;iostream&gt; class Widget { int x; public: Widget(int inX) : x(inX){} ~Widget() { std::cout &lt;&lt; "widget " &lt;&lt; static_cast&lt; void*&gt;(this) &lt;&lt; " destroyed" &lt;&lt; std::endl; } }; struct WidgetHolder { Widget&amp; A; public: WidgetHolder(Widget a): A(a) {} const Widget&amp; a() const { std::cout &lt;&lt; "widget " &lt;&lt; static_cast&lt; void*&gt;(&amp;A) &lt;&lt; " used" &lt;&lt; std::endl; return A; } }; int main(char** argv, int argc) { Widget test(7); WidgetHolder holder(test); Widget const &amp; test2 = holder.a(); return 0; } </code></pre> <p>The output would be something like </p> <pre> widget 0xbffff7f8 destroyed widget 0xbffff7f8 used widget 0xbffff7f4 destroyed </pre> <p>To avoid this the WidgetHolder constructor should take references to the variables it wants to store as references.</p> <pre> struct WidgetHolder { Widget& A; public: WidgetHolder(Widget & a): A(a) {} /* ... */ }; </pre>
8,155
<p>As I get more and more namespaces in my solution, the list of using statements at the top of my files grows longer and longer. This is especially the case in my unit tests where for each component that might be called I need to include the using for the interface, the IoC container, and the concrete type. </p> <p>With upward of 17 lines of usings in my integration test files its just getting downright messy. Does anyone know if theres a way to define a macro for my base using statements? Any other solutions?</p>
<p>Some people enjoy hiding the usings in a <code>#region</code>. Otherwise, I think you're out of luck. Unless you want to put the namespace on all your referents.</p>
<p>Resharper - the add-in for Visual Studio - has a feature that strips unsued Using's from a file, but I don't know anything that does quite what you describe.</p>
8,757
<p>I made a tea bowl, but it leaked when making it in PLA...</p> <p>What are the key points to keep in mind when designing and printing an object that is intended to hold water using an FDM printer? </p>
<p>I've found that a double-walled base seems to give better results than trying to make the base very thick. Any imperfections in the print, or cracking caused by removing the print can lead to leaks - but if there is layer/infill/layer, the result seems to turn out better for me.</p> <p>Vase mode can be effective (although won't be easy to combine with the above unless you slice your model in several parts), and I've had success whilst using 100% vase mode for vases to hold water. This demonstrates that a single wall thickness is sufficient to achieve a watertight print.</p>
<p>When designing the object, you should make sure your object is completely enclosed (obviously). When printing, try increasing the print temperature so that the layers stick to each other well. The most important thing is the print temperature, because if the layers don't adhere to each other well, you will get a leak. The wall thickness of the object can be thin, as long as it isn't so thin that it has too little strength to hold anything. </p> <p>Some tips:</p> <ul> <li>Printing in vase mode can save loads of time, otherwise the printer wastes time doing each layer separately. </li> <li>Your nozzle should be 0.4&nbsp;mm and up, otherwise the print will take forever.</li> </ul>
677
<p>I'm working on some code that uses the System.Diagnostics.Trace class and I'm wondering how to monitor what is written via calls to Trace.WriteLine() both when running in debug mode in Visual Studio and when running outside the debugger.</p>
<p>Try <a href="http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx" rel="nofollow noreferrer">Debug View</a>. It works quite nicely.</p>
<p>I use a simple little program called '<a href="http://www.baremetalsoft.com/baretail/" rel="nofollow noreferrer">BareTail</a>' which displays plain text files, updating it's display as the file gets written to and follows (or wraps) to the bottom of the file.</p> <p>When running outside the debugger you'll need to attach a file-writer to write out the trace information, which you can do by <a href="http://www.thescarms.com/dotnet/DebugTrace.aspx" rel="nofollow noreferrer">adding a few lines to the .exe.config file</a></p> <p>Hope that Helps ;o)</p>
7,846
<p>I am using 2 extruders. Is it possible to use them both at the same time. Now I can use one at a time but not both at the same time. Is there a gcode that supports this action?</p>
<p>To print with 2 extruders simultaneously you need a firmware that supports that. Luckily, there is a firmware called Sailfish that is able to do that. The feature you are looking for is called <code>Ditto</code> printing.</p> <p>Sailfish firmware is found <a href="http://www.sailfishfirmware.com" rel="nofollow noreferrer">here</a></p>
<p>If you want a ditto printing is not mandatory to have a specific firmware (or g-code), you only need to add extruder to your end effector and - because of electrical power requirements - add further stepper driver for further stepper motor. Please note that the maximum footprint of your printed object is less than the extruders distance, for obvious physical reasons, therefore is not that common to see, the typical dual extruder goal is to use different filament/color. Of course, you have to achieve a notable calibration skill, and of course you have to modify the electronics of your printer (but this can be done quite easily, you only have to share the enable/step/dir signals with all the stepper driver). This has been already done with the <a href="https://www.youtube.com/watch?time_continue=5&amp;v=DeVeyUas5vU" rel="nofollow noreferrer">MPCNC project</a>.</p> <p>Otherwise, if you want something more flexible, there are commercial printers with independent extruder. <a href="https://www.lpfrg.com/en/benefits-of-independent-dual-extruders/" rel="nofollow noreferrer">This one, for example</a></p> <p>Edit: i can't comment your answer yet, but can you describe your current 3d printer setup? Because if you have the two hot ends that are only few mm apart it makes little sense to ditto-print something.</p>
912
<p>I'm currently in the process of fine-tuning my cheap CTC i3 clone. I'm using Cura 3.1 for slicing.</p> <p>After calibrating the extruder steps, I wanted to optimize the line width and flow compensation parameters. I am using a 0.4 mm nozzle and therefore set the line width parameter to 0.4 mm in Cura. I then printed a cube with 0% infill, 1 wall line and no top layers (basically an open cube with 4 bottom layers). The wall width I measured on the printed result is 0.52 mm. To correct for the difference I set the flow compensation to 80% and repeated the print. The wall width I got from this was 0.45 mm, which is much better than before. There is only one problem: the parallel lines in the four bottom layers do not touch, so the print is not watertight. Up to now I assumed that Cura would calculate the distance between the lines from the line width setting. So with 0.45 mm lines and line width set to 0.4 mm there should even be some overlap.</p> <p>Why am I seeing this effect? Am I getting something fundamentally wrong here?</p>
<p>That is very bizarre. Since GCODE describe each movement of the printing head (so, the printer does not get to decide anything in terms of printing strategy, it just executes), I can only see three possibilities that would explain what's going on.</p> <p><strong>The print is being scaled up at printer level</strong>. This could for example be due to your firmware having your steppers improperly calibrated and moving them too much for a given unit of measure (say you say 1mm, they move 1.5mm instead). This is easy to check: if this is the case, your cube will be scaled up (so - using the example above - if your cube is 10x10x10 it will come out 15x15x15).</p> <p><strong>You are printing with a raft</strong>. Then there is no problem with your set-up, the first layer(s) of a raft are not solid, but intentionally "grated". Check your settings to verify.</p> <p><strong>Cura is producing the "wrong" gcode</strong>. This could be <em>really wrong</em> (as in "you found a bug", in which case you should report it on their github), or just <em>look wrong</em> (as in "you found a weird combination of setting producing that gcode", in which case you should reset the settings to their default and see the problem disappear). Either way, if the gcode is "wrong", you should notice the gaps in the gcode preview mode in Cura.</p>
<p>Cura does not adjust line width to account for lower flow (aka extrusion multiplier), they are independent settings. Therefore, if you have to reduce extrusion to get the correct wall thickness, then as you said, the lines may not be close enough together to fuse properly and you'll have a weak part. Try reducing the line width. First though, I would take the below troubleshooting steps:</p> <ol> <li><a href="https://www.3dmakerengineering.com/blogs/3d-printing/estep-calibration" rel="nofollow noreferrer">Calibrate e-steps in firmware</a></li> <li><a href="https://filaments.ca/blogs/3d-printing/how-to-measure-3d-filament-diameter" rel="nofollow noreferrer">Calibrate the actual diameter of the filament you're using</a></li> <li><a href="https://3dprintbeginner.com/flow-rate-calibration/" rel="nofollow noreferrer">Calibrate flow for the correct wall thickness</a></li> <li><a href="https://www.3dprintbeast.com/cura-nozzle-size-line-width/#:%7E:text=For%20setting%20line%20width%20on,by%20using%20the%20search%20box." rel="nofollow noreferrer">Adjust line width in Cura if needed to get proper fusing</a></li> </ol> <p>Lastly you might want to check for a partial nozzle clog which can cause under-extrusion, though that is usually not consistent</p>
826
<p>So I'm working on a Rails app to get the feeling for the whole thing. I've got a <code>Product</code> model that's a standard ActiveRecord model. However, I also want to get some additional product info from Amazon ECS. So my complete model gets some of its info from the database and some from the web service. My question is, should I:</p> <ol> <li><p>Make two models a Product and a ProductAWS, and then tie them together at the controller level.</p></li> <li><p>Have the Product ActiveRecord model contain a ProductAWS object that does all the AWS stuff?</p></li> <li><p>Just add all the AWS functionality to my Product model.</p></li> <li><p>???</p></li> </ol>
<p>As with most things: it depends. Each of your ideas have merit. If it were me, I'd start out this way: </p> <pre><code> class Product &lt; ActiveRecord::Base has_one :aws_item end class AWSItem belongs_to :product end </code></pre> <p>The key questions you want to ask yourself are: </p> <p><strong>Are you only going to be offering AWS ECS items, or will you have other products?</strong> If you'll have products that have nothing to do with Amazon, don't care about ASIN, etc, then a has_one could be the way to go. Or, even better, a polymorphic relationship to a :vendable interface so you can later plug in different extension types. </p> <p><strong>Is it just behavior that is different, or is the data going to be largely different too?</strong> Because you might want to consider: </p> <blockquote> <pre><code>class Product &lt; ActiveRecord::Base end class AWSItem &lt; Product def do_amazon_stuff ... end end </code></pre> </blockquote> <p><strong>How do you want the system to perform when Amazon ECS isn't available?</strong> Should it throw exceptions? Or should you rely on a local cached version of the catalog?</p> <blockquote> <pre><code>class Product &lt; ActiveRecord::Base end class ItemFetcher &lt; BackgrounDRb::Rails def do_work # .... Make a cached copy of your ECS catalog here. # Copy the Amazon stuff into your local model end end </code></pre> </blockquote> <p>Walk through these questions slowly and the answer will become clearer. If it doesn't, start prototyping it out. Good luck!</p>
<p>You can use the <code>composed_of</code> relationship in ActiveRecord. You make a regular class with all the attributes that you manage through AWS and specify that your Product-class is composed_of this class. ActiveRecord will handle the delegation of the mapped attributes to and from this class.</p> <p>See <a href="http://api.rubyonrails.org/classes/ActiveRecord/Aggregations/ClassMethods.html#M001265" rel="nofollow noreferrer">the documentation of composed_of</a></p>
9,578
<p>Is there a simple way to cache <code>MySQL queries</code> in <code>PHP</code> or failing that, is there a small class set that someone has written and made available that will do it? I can cache a whole page but that won't work as some data changes but some do not, I want to cache the part that does not.</p>
<p>This is a great overview of how to cache queries in MySQL:</p> <ul> <li><a href="http://www.petefreitag.com/item/390.cfm" rel="noreferrer">The MySQL Query Cache</a></li> </ul>
<p>I would recommend the whole page caching route. If some of the data changes, simply place tokens/placeholders in place of the dynamic data. Cache the entire page with those tokens in place, then post process the tokens for the cached data for the tokens. Thus you now have a cached page that contains dynamic content.</p>
5,784
<p>I am using a perl script to POST to Google Appengine application. I post a text file containing some XML using the -F option.</p> <p><a href="http://www.cpan.org/authors/id/E/EL/ELIJAH/bget-1.1" rel="nofollow noreferrer">http://www.cpan.org/authors/id/E/EL/ELIJAH/bget-1.1</a></p> <p>There is a version 1.2, already tested and get the same issue. The post looks something like this.</p> <pre><code>Host: foo.appspot.com User-Agent: lwp-request/1.38 Content-Type: text/plain Content-Length: 202 &lt;XML&gt; &lt;BLAH&gt;Hello World&lt;/BLAH&gt; &lt;/XML&gt; </code></pre> <p>I have modified the example so the 202 isn't right, don't worry about that. On to the problem. The Content-Length matches the number of bytes on the file, however unless I manually increase the Content-Length it does not send all of the file, a few bytes get truncated. The number of bytes truncated is not the same for files of different sizes. I used the -r option on the script and I can see what it is sending and it is sending all of the file, but Google Appengine self.request.body shows that not everything is received. I think the solution is to get the right number for Content-Length and apparently it isn't as simple as number of bytes on the file or the perl script is mangling it somehow.</p> <p>Update: Thanks to Erickson for the right answer. I used printf to append characters to the end of the file and it always truncated exactly the number of lines in the file. I suppose I could figure out what is being added by iterating through every character on the server side but not worth it. This wasn't even answered over on the google groups set up for app engine!</p>
<p>Is the number of extra bytes you need equal to the number of lines in the file? I ask because perhaps its possible that somehow carriage-returns are being introduced but not counted.</p>
<p>How are you getting the number of bytes? .. By looking at the size of the file on the filesystem?</p> <p>You can use "-s" to get the size of the file.</p> <p>Or, if you want to do more, you may use <a href="http://search.cpan.org/~rgarcia/perl-5.10.0/lib/File/stat.pm" rel="nofollow noreferrer">File::Stat</a></p>
6,852
<p>Are there any good recommendations anyone can provide for a good Javascript editor on Windows? </p> <p>I currently use combinations of FireBug and TextPad but would hate to miss out on the party if there are better options out there. </p> <p>Thanks.</p>
<p>I know <a href="https://stackoverflow.com/questions/26897/recommendations-for-javascript-editor-on-windows#26905">jsight</a> already mentioned this, but <a href="http://aptana.com/" rel="nofollow noreferrer"><strong>Aptana Studio</strong></a> really is a great, free editor for JavaScript if you find yourself doing a lot of work with it - it has great support for most of the well-known libraries. If it were not for the fact that I work with C# in addition to JavaScript, I would use Aptana for all of my work.</p>
<p><a href="http://editra.org/index.php" rel="nofollow noreferrer">Editra</a> may be worth a look, the code colouring isn't bad, and I believe it has plugins to enable script execution.. Although I have <strong>not</strong> used this myself.</p>
4,656
<p>In <code>C</code> can I <strong>pass a multidimensional array</strong> to a function <strong>as a single argument</strong> when I don't know what the dimensions of the array are going to be?</p> <p>Besides, my multidimensional array may contain types other than strings.</p>
<p>You can do this with any data type. Simply make it a pointer-to-pointer:</p> <pre><code>typedef struct { int myint; char* mystring; } data; data** array; </code></pre> <p>But don't forget you still have to malloc the variable, and it does get a bit complex:</p> <pre><code>//initialize int x,y,w,h; w = 10; //width of array h = 20; //height of array //malloc the 'y' dimension array = malloc(sizeof(data*) * h); //iterate over 'y' dimension for(y=0;y&lt;h;y++){ //malloc the 'x' dimension array[y] = malloc(sizeof(data) * w); //iterate over the 'x' dimension for(x=0;x&lt;w;x++){ //malloc the string in the data structure array[y][x].mystring = malloc(50); //50 chars //initialize array[y][x].myint = 6; strcpy(array[y][x].mystring, "w00t"); } } </code></pre> <p>The code to deallocate the structure looks similar - don't forget to call free() on everything you malloced! (Also, in robust applications you should <a href="http://www.google.com/search?q=check+malloc+return" rel="noreferrer">check the return of malloc()</a>.)</p> <p>Now let's say you want to pass this to a function. You can still use the double pointer, because you probably want to do manipulations on the data structure, not the pointer to pointers of data structures:</p> <pre><code>int whatsMyInt(data** arrayPtr, int x, int y){ return arrayPtr[y][x].myint; } </code></pre> <p>Call this function with:</p> <pre><code>printf("My int is %d.\n", whatsMyInt(array, 2, 4)); </code></pre> <p>Output:</p> <pre><code>My int is 6. </code></pre>
<pre><code>int matmax(int **p, int dim) // p- matrix , dim- dimension of the matrix { return p[0][0]; } int main() { int *u[5]; // will be a 5x5 matrix for(int i = 0; i &lt; 5; i++) u[i] = new int[5]; u[0][0] = 1; // initialize u[0][0] - not mandatory // put data in u[][] printf("%d", matmax(u, 0)); //call to function getche(); // just to see the result } </code></pre>
2,606
<p><a href="http://en.wikipedia.org/wiki/SHA-1" rel="noreferrer">SHA Hash functions</a></p>
<pre><code>require 'digest/sha1' Digest::SHA1.hexdigest 'foo' </code></pre>
<p>Where 'serialize' is some user function defined elsewhere.</p> <pre><code> def generateKey(data) return Digest::SHA1.hexdigest ("#{serialize(data)}") end </code></pre>
5,473
<p>I would like to use a component that exposes the datasource property, but instead of supplying the datasource with whole list of objects, I would like to use only simple object. Is there any way to do this ?</p> <p>The mentioned component is DevExpress.XtraDataLayout.DataLayoutControl - this is fairly irrelevant to the question though.</p>
<p>Databinding expects an IEnumerable object, because it enumorates over it just like a foreach loop does.</p> <p>So to do this, just wrap your single object in an IEnumerable.</p> <p>Even this would work:</p> <pre><code>DataBindObject.DataSource = new List&lt;YourObject&gt;().Add(YourObjectInstance); </code></pre>
<p>Using this in my formView:</p> <pre><code>databoundControl.DataSource = new [] { singleObject }; databoundControl.DataBind(); </code></pre>
7,099
<p>I'm trying to replace each <code>,</code> in the current file by a new line:</p> <pre><code>:%s/,/\n/g </code></pre> <p>But it inserts what looks like a <code>^@</code> instead of an actual newline. The file is not in DOS mode or anything.</p> <p>What should I do?</p> <p>If you are curious, like me, check the question <em><a href="https://stackoverflow.com/questions/71417/why-is-r-a-newline-for-vim">Why is \r a newline for Vim?</a></em> as well.</p>
<h2>Use <code>\r</code> instead of <code>\n</code>.</h2> <p>Substituting by <code>\n</code> inserts a null character into the text. To get a newline, use <code>\r</code>. When <em>searching</em> for a newline, you’d still use <code>\n</code>, however. This asymmetry is due to the fact that <code>\n</code> and <code>\r</code> <a href="http://vim.wikia.com/wiki/Search_and_replace" rel="noreferrer">do slightly different things</a>:</p> <p><code>\n</code> matches an end of line (newline), whereas <code>\r</code> matches a carriage return. On the other hand, in substitutions <code>\n</code> inserts a null character whereas <code>\r</code> inserts a newline (more precisely, it’s treated as the input <kbd>CR</kbd>). Here’s a small, non-interactive example to illustrate this, using the Vim command line feature (in other words, you can copy and paste the following into a terminal to run it). <code>xxd</code> shows a hexdump of the resulting file.</p> <pre><code>echo bar &gt; test (echo 'Before:'; xxd test) &gt; output.txt vim test '+s/b/\n/' '+s/a/\r/' +wq (echo 'After:'; xxd test) &gt;&gt; output.txt more output.txt </code></pre> <pre><code>Before: 0000000: 6261 720a bar. After: 0000000: 000a 720a ..r. </code></pre> <p>In other words, <code>\n</code> has inserted the byte 0x00 into the text; <code>\r</code> has inserted the byte 0x0a.</p>
<p>in vim editor the following command successfully replaced \n with new line</p> <pre><code>:%s/\\n/\r/g </code></pre>
9,681
<p>I have long since forgotten the password for the root user on one of my boxes. Is there a way I can change it without having to log in to the instance, or will I have to reinstall?</p>
<p><strong>Step 1</strong></p> <p>Stop database:</p> <pre><code>shell&gt; /etc/init.d/mysql stop </code></pre> <p><strong>Step 2</strong></p> <p>Restart database</p> <ul> <li>without password autentification</li> <li>without connection to the network</li> </ul> <p>Access to database is only possible through it's sock file '/var/lib/mysql/mysql.sock'.</p> <pre><code>shell&gt; mysqld --user=mysql --pid-file=/var/lib/mysql/mysqld.pid \ --socket=/var/lib/mysql/mysql.sock --datadir=/var/lib/mysql \ --skip-grant-tables --skip-networking &amp; </code></pre> <p><strong>Step 3</strong></p> <p>Connect to the database and change password:</p> <pre><code>shell&gt; mysql --database mysql --socket=/var/lib/mysql/mysql.sock </code></pre> <p>If you want to, show all users:</p> <pre><code>mysql&gt; select User, password from user; </code></pre> <p>Set new password:</p> <pre><code>mysql&gt; update user set password=password('NEW PASS') WHERE User='USERNAME'; </code></pre> <p>Leave database connection:</p> <pre><code>mysql&gt; exit </code></pre> <p><strong>Step 4</strong></p> <p>Restart database server "normally".</p> <pre><code>shell&gt; kill `cat /var/lib/mysql/mysqld.pid` shell&gt; /etc/init.d/mysql start </code></pre>
<p>If you are running an Ubuntu server (possibly also Debian?) you can easily reset. </p> <p>If you are on 12.04:</p> <pre><code>sudo dpkg-reconfigure mysql-server-5.5 </code></pre> <p>If you are on 10.04:</p> <pre><code>sudo dpkg-reconfigure mysql-server-5.1 </code></pre> <p>If you are not sure which mysql-server version is installed you can try: </p> <pre><code>dpkg --get-selections | grep mysql-server </code></pre> <p>See for more info:</p> <p><a href="https://help.ubuntu.com/12.04/serverguide/mysql.html" rel="nofollow">https://help.ubuntu.com/12.04/serverguide/mysql.html</a> <a href="https://help.ubuntu.com/10.04/serverguide/mysql.html" rel="nofollow">https://help.ubuntu.com/10.04/serverguide/mysql.html</a></p>
7,696
<p>After multiple jams from bulging filaments on two spools I'm getting frustrated. One, right before a job was done.</p> <p>Is there something I can do to prevent these bulges in filaments from ruining jobs?</p> <p>What can I do to prevent this from happening in the future before it's a disaster?</p> <p>He's a picture of one I found using google.</p> <p><a href="https://i.stack.imgur.com/6UvLW.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6UvLW.jpg" alt="enter image description here"></a></p>
<p>How to catch <em>and</em> fix these on the fly? That would be difficult..</p> <p>But this is an issue you really should not have.</p> <p><a href="https://3dprinting.stackexchange.com/q/84/47">Could it be an issue with filament storage?</a></p> <p>Or is it coming from the manufacturer with these bulges? If so, I would try contacting ( you may have gotten a bad batch? ), or finding a new retailer if this happens often.</p> <p>I have gone through a lot of pounds of both ABS and PLA and never come across this. </p>
<p><strong>Bottom line: <em>The easiest way to prevent this is to avoid cheap filament.</em></strong></p> <p>You can get mid-grade filament for a few dollars more than the ultra cheap stuff. </p> <p>In other words I tried out some 10$ stuff from ebay, and while it might print for a little while it notoriously clogged in any prints greater than 1hr. </p> <p>20-25$ is the going rate for mid-grade filament on amazon and check the reviews I've had good consistency there. </p>
137
<p>Is it worth learning the convention or is it a bane to readability and maintainability?</p>
<p>Considering that most people that use <em>Hungarian Notation</em> is following the misunderstood version of it, I'd say it's pretty pointless.</p> <p>If you want to use the original definition of it, it might make more sense, but other than that it is mostly syntactic sugar.</p> <p>If you read the <a href="http://en.wikipedia.org/wiki/Hungarian_notation" rel="noreferrer">Wikipedia article</a> on the subject, you'll find two conflicting notations, <em>Systems Hungarian Notation</em> and <em>Apps Hungarian Notation</em>.</p> <p>The original, good, definition is the <em>Apps Hungarian Notation</em>, but most people use the <em>Systems Hungarian Notation</em>.</p> <p>As an example of the two, consider prefixing variables with l for length, a for area and v for volume.</p> <p>With such notation, the following expression makes sense:</p> <pre><code>int vBox = aBottom * lVerticalSide; </code></pre> <p>but this doesn't:</p> <pre><code>int aBottom = lSide1; </code></pre> <p>If you're mixing the prefixes, they're to be considered part of the equation, and volume = area * length is fine for a box, but copying a length value into an area variable should raise some red flags.</p> <p>Unfortunately, the other notation is less useful, where people prefix the variable names with the type of the value, like this:</p> <pre><code>int iLength; int iVolume; int iArea; </code></pre> <p>some people use n for number, or i for integer, f for float, s for string etc.</p> <p>The original prefix was meant to be used to spot problems in equations, but has somehow devolved into making the code slightly easier to read since you don't have to go look for the variable declaration. With todays smart editors where you can simply hover over any variable to find the full type, and not just an abbreviation for it, this type of hungarian notation has lost a lot of its meaning.</p> <p>But, you should make up your own mind. All I can say is that I don't use either.</p> <hr> <p><strong>Edit</strong> Just to add a short notice, while I don't use <em>Hungarian Notation</em>, I do use a prefix, and it's the underscore. I prefix all private fields of classes with a _ and otherwise spell their names as I would a property, titlecase with the first letter uppercase.</p>
<p>I've been working for IBM for the past 6 months and I haven't seen it anywhere (thank god because I hate it.) I see either camelCase or c_style.</p> <pre><code>thisMethodIsPrettyCool() this_method_is_pretty_cool() </code></pre>
2,734
<p>We get the following error;</p> <pre><code>The request was aborted: Could not create SSL/TLS secure channel </code></pre> <p>while using a <code>WebRequest</code> object to make an <code>HTTPS</code> request. The funny thing is that this only happens after a while, and is temporarily fixed when the application is restarted, which suggests that something is being filled to capacity or something. </p> <p>Has anyone seen this kind of thing before?</p>
<p>I seem to recall having this problem last year. I suspect that you aren't closing your WebRequest objects properly, which is why after a certain amount of use it won't allow you to create any new connections.</p>
<p>It looks like it may be a Conenction: Keep-alive thing: <a href="http://blogs.x2line.com/al/archive/2005/01/04/759.aspx#780" rel="nofollow noreferrer">http://blogs.x2line.com/al/archive/2005/01/04/759.aspx#780</a></p>
6,365
<p>The problem: I have a class which contains a template method <code>execute</code> which calls another method <code>_execute</code>. Subclasses are supposed to overwrite <code>_execute</code> to implement some specific functionality. This functionality should be documented in the docstring of <code>_execute</code>. Advanced users can create their own subclasses to extend the library. However, another user dealing with such a subclass should only use <code>execute</code>, so he won't see the correct docstring if he uses <code>help(execute)</code>.</p> <p>Therefore it would be nice to modify the base class in such a way that in a subclass the docstring of <code>execute</code> is automatically replaced with that of <code>_execute</code>. Any ideas how this might be done?</p> <p>I was thinking of metaclasses to do this, to make this completely transparent to the user.</p>
<p>Well, if you don't mind copying the original method in the subclass, you can use the following technique.</p> <pre><code>import new def copyfunc(func): return new.function(func.func_code, func.func_globals, func.func_name, func.func_defaults, func.func_closure) class Metaclass(type): def __new__(meta, name, bases, attrs): for key in attrs.keys(): if key[0] == '_': skey = key[1:] for base in bases: original = getattr(base, skey, None) if original is not None: copy = copyfunc(original) copy.__doc__ = attrs[key].__doc__ attrs[skey] = copy break return type.__new__(meta, name, bases, attrs) class Class(object): __metaclass__ = Metaclass def execute(self): '''original doc-string''' return self._execute() class Subclass(Class): def _execute(self): '''sub-class doc-string''' pass </code></pre>
<p>Well the doc-string is stored in <code>__doc__</code> so it wouldn't be too hard to re-assign it based on the doc-string of <code>_execute</code> after the fact.</p> <p>Basically:</p> <p><code></p> <pre> class MyClass(object): def execute(self): '''original doc-string''' self._execute() class SubClass(MyClass): def _execute(self): '''sub-class doc-string''' pass # re-assign doc-string of execute def execute(self,*args,**kw): return MyClass.execute(*args,**kw) execute.__doc__=_execute.__doc__ </pre> <p></code></p> <p>Execute has to be re-declared to that the doc string gets attached to the version of execute for the <code>SubClass</code> and not for <code>MyClass</code> (which would otherwise interfere with other sub-classes).</p> <p>That's not a very tidy way of doing it, but from the POV of the user of a library it should give the desired result. You could then wrap this up in a meta-class to make it easier for people who are sub-classing.</p>
9,737
<p>I see a lot of talk on here about functional languages and stuff. Why would you use one over a "traditional" language? What do they do better? What are they worse at? What's the ideal functional programming application?</p>
<p>Functional languages use a different paradigm than imperative and object-oriented languages. They use side-effect-free functions as a basic building block in the language. This enables lots of things and makes a lot of things more difficult (or in most cases different from what people are used to).</p> <p>One of the biggest advantages with functional programming is that the order of execution of side-effect-free functions is not important. For example, in Erlang this is used to enable concurrency in a very transparent way. And because functions in functional languages behave very similar to mathematical functions it's easy to translate those into functional languages. In some cases, this can make code more readable.</p> <p>Traditionally, one of the big disadvantages of functional programming was also the lack of side effects. It's very difficult to write useful software without IO, but IO is hard to implement without side effects in functions. So most people never got more out of functional programming than calculating a single output from a single input. In modern mixed-paradigm languages like F# or Scala this is easier.</p> <p>Lots of modern languages have elements from functional programming languages. C# 3.0 has a lot functional programming features and you can do functional programming in Python too. I think the reasons for the popularity of functional programming is mostly because of two reasons: Concurrency is getting to be a real problem in normal programming because we're getting more and more multiprocessor computers; and the languages are getting more accessible.</p>
<p>I don't think that functional languages will solve anything, and that this is just a hype that management is trying to sell, remember the only truth:</p> <p>There is no silver bullet.</p> <p>All the rest, is bullshit, also they've said that OO would solve our problems, that Web Services would solve our problems, that Xml would solve our problems, but in the end the above truth applied, and everything went down. Also, twenty years from now on, who says that we will be using binary computers at all? Why not quantic computers? No one can predict the future, at least not on this planet. (That is the second truth)</p>
5,710
<p>Lucene has quite poor support for Russian language.</p> <p>RussianAnalyzer (part of lucene-contrib) is of very low quality.</p> <p>RussianStemmer module for Snowball is even worse. It does not recognize Russian text in Unicode strings, apparently assuming that some bizarre mix of Unicode and KOI8-R must be used instead.</p> <p>Do you know any better solutions?</p>
<p>If all else fails, use <a href="http://www.sphinxsearch.com/" rel="nofollow noreferrer">Sphinx</a></p>
<p>That's the beauty of open source. You have the source code, so if the current implementations don't work for you, you can always create your own or even better, extend the existing ones. A good start would be the "Lucene in Action" book.</p>
8,934
<p>I added a custom boot screen to marlin by adding <code>_Bootscreen.h</code> to the project root folder and it works fine. The problem is that the custom screen shows quickly and disappear then the marlin boot screen is then displayed for a longer time. I want to remove the marlin boot screen.</p> <p>I dug around in the source code and found a <code>void lcd_bootscreen</code> function in the <code>ultralcd_impl_HD44780.h</code> header. This seems to be the function that is loading the marlin's boot screen due to the comments in the code. I added <code>return;</code> to the <strong>first line</strong> of code in this function but the marlin's boot screen is still loading. </p> <p>How can I remove the marlin boot screen. How can make my custom boot screen wait for more time?</p> <p>The marlin version is 1.1.8.</p>
<p>So after some search:</p> <ol> <li><p>You can't (at least should not) remove the marlin bootscreen according to this issue <a href="https://github.com/MarlinFirmware/Marlin/issues/8186" rel="nofollow noreferrer">SHOW_CUSTOM_BOOTSCREEN hides Marlin logo</a>, quote:</p> <blockquote> <p>We wanted an additional logo - not a replacement of the Marlin logo.</p> </blockquote></li> <li><p>According to the <a href="https://github.com/MarlinFirmware/Marlin/blob/1.1.x/Marlin/ultralcd_impl_DOGM.h#L282-L306" rel="nofollow noreferrer">code here</a> there's a constant CUSTOM_BOOTSCREEN_TIMEOUT taking the default value of 2500 which is 2.5 seconds but you can redefine it in your _Boostrap.h file.</p> <p>This constant is only available for DOGM lcd screens which is chosen by the code here in <a href="https://github.com/MarlinFirmware/Marlin/blob/1.1.x/Marlin/ultralcd.cpp#L95-L100" rel="nofollow noreferrer">ultralcd.cpp</a> and whitout more details on your machine it's hard to tell from <a href="https://github.com/MarlinFirmware/Marlin/blob/1.1.x/Marlin/Conditionals_LCD.h" rel="nofollow noreferrer">Conditionals_LCD.h</a> which will be used.</p></li> </ol>
<p>So after some search:</p> <ol> <li><p>You can't (at least should not) remove the marlin bootscreen according to this issue <a href="https://github.com/MarlinFirmware/Marlin/issues/8186" rel="nofollow noreferrer">SHOW_CUSTOM_BOOTSCREEN hides Marlin logo</a>, quote:</p> <blockquote> <p>We wanted an additional logo - not a replacement of the Marlin logo.</p> </blockquote></li> <li><p>According to the <a href="https://github.com/MarlinFirmware/Marlin/blob/1.1.x/Marlin/ultralcd_impl_DOGM.h#L282-L306" rel="nofollow noreferrer">code here</a> there's a constant CUSTOM_BOOTSCREEN_TIMEOUT taking the default value of 2500 which is 2.5 seconds but you can redefine it in your _Boostrap.h file.</p> <p>This constant is only available for DOGM lcd screens which is chosen by the code here in <a href="https://github.com/MarlinFirmware/Marlin/blob/1.1.x/Marlin/ultralcd.cpp#L95-L100" rel="nofollow noreferrer">ultralcd.cpp</a> and whitout more details on your machine it's hard to tell from <a href="https://github.com/MarlinFirmware/Marlin/blob/1.1.x/Marlin/Conditionals_LCD.h" rel="nofollow noreferrer">Conditionals_LCD.h</a> which will be used.</p></li> </ol>
777
<p>I'm looking for a way to slice up a 3D model and then get the profiles of each individual layer. I need to 2D print the different layers (with the layer height that I define) for a Styrofoam craft.</p> <p>Thank you very much!</p>
<p>I'm a fan of OpenSCAD and have used the method suggested in the first answer. For non-OpenSCAD users, another option exists, which I've also used.</p> <p>PrusaSlicer is a free 3D printer slicing program. One can configure layer heights as desired for the material thickness, even though it's not likely one will find a printer with such values, except perhaps concrete 3D printers!</p> <p>Once configured and sliced, the exported file (configured for a Prusa SL1 printer) is renamed to .ZIP and the files within extracted. The files of note are going to be PNG format, one file per layer.</p> <p>The settings within the slicer software have to be &quot;adjusted&quot; for your creation.</p> <p>In Print Settings tab, change the layer height to match your material thickness. Also in the Print Settings tab, turn off supports and turn off pad (left column selections).</p> <p>In Material Settings tab, change the Initial layer height to match your overall layer thickness. Unchanged, it remains the default 0.05 mm, unlikely to match your building material.</p> <p>On the Printer Settings tab, change the bed shape to match your objective plus a bit of spacing around the item. Change the max height appropriately.</p> <p>Set the Display Width parameters to match your output. Excessively large values will result in small model segments in a large blank area. Set pixel values to desired resolution of the output image file. For example, 200 is equivalent to a typical inkjet printer resolution.</p> <p>I performed all of the above steps for a simple cube, exported the file to the default .SL1 extension, renamed it to .ZIP and extracted to a folder. The folder contained a number of support files for the MSLA printer, but also a full list of the layer .PNG files. Depending on your system settings, you may be able to change the extension in the Save dialog to .ZIP.</p> <p>If PNG is not a suitable format, one can convert them to SVG using Inkscape bitmap trace or similar software.</p> <p>I recommend to create a model with some form of registration incorporated to the design. One can create and subtract a pair of cylinders, for example, that travels through each layer, allowing insertion of a dowel to more easily stack the slices for assembly.</p> <p>One can add primitives within the slicer, but they fall to the bed and also cannot be subtracted, at least so far as my limited research has shown. I've used Fusion 360 and Meshmixer to create such modifications.</p> <p>Another aspect of the slicer is the ability to hollow the model, which would provide for some interesting constructions as well as possibly easier alignment.</p> <p>This should be a .GIF animation of the results of my testing on Astronaut Phil A Ment, 1 millimeter layer height:</p> <p><a href="https://i.stack.imgur.com/ES8A3.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ES8A3.gif" alt="astronaut slicing animation" /></a></p> <p>stltopng conversion of original STL file of Phil:</p> <p><a href="https://i.stack.imgur.com/of3mZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/of3mZ.png" alt="phil a ment model" /></a></p>
<p>With OpenSCAD, you can <code>import</code> the STL file and apply <code>projection</code> with <code>cut=true</code> at successive Z-axis <code>translate</code> operations, and write out the result as SVG. This can all be automated from the command line to product a series of SVG files for your layers to &quot;2D print&quot;.</p>
2,150
<p>After upgrading to the latest version of TortoiseSVN (1.5.2.13595), it's context menu is no longer available.</p> <p>When attempting to run it manually, I get this error:</p> <pre><code>The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log for more detail </code></pre> <p>The application log shows this</p> <pre><code>Activation context generation failed for "C:\Program Files\TortoiseSVN\bin\TortoiseSVN.dll". Dependent Assembly Microsoft.VC90.CRT,processorArchitecture="x86",publicKeyToken="1fc8b3b9a1e18e3b",type="win32",version="9.0.30411.0" could not be found. Please use sxstrace.exe for detailed diagnosis. </code></pre>
<p>I remembered I'd seen this thing before just after posting to SO</p> <p>It seems that later versions of TortoiseSVN are built with Visual Studio 2008 SP1 (hence the 9.0.30411.0 build number)</p> <p>Installing the <a href="http://www.microsoft.com/downloads/details.aspx?familyid=A5C84275-3B97-4AB7-A40D-3802B2AF5FC2&amp;displaylang=en" rel="noreferrer">VC2008 SP1 Redistributable</a> fixes it</p>
<p>Confirmed working on windows 7 x64.</p>
3,955
<p>Is there a performance hit if we use a loop instead of recursion or vice versa in algorithms where both can serve the same purpose? Eg: Check if the given string is a palindrome. I have seen many programmers using recursion as a means to show off when a simple iteration algorithm can fit the bill. Does the compiler play a vital role in deciding what to use?</p>
<p>It is possible that recursion will be more expensive, depending on if the recursive function is <a href="http://en.wikipedia.org/wiki/Tail_recursion" rel="noreferrer">tail recursive</a> (the last line is recursive call). Tail recursion <em>should</em> be recognized by the compiler and optimized to its iterative counterpart (while maintaining the concise, clear implementation you have in your code).</p> <p>I would write the algorithm in the way that makes the most sense and is the clearest for the poor sucker (be it yourself or someone else) that has to maintain the code in a few months or years. If you run into performance issues, then profile your code, and then and only then look into optimizing by moving over to an iterative implementation. You may want to look into <a href="http://en.wikipedia.org/wiki/Memoization" rel="noreferrer">memoization</a> and <a href="http://en.wikipedia.org/wiki/Dynamic_programming" rel="noreferrer">dynamic programming</a>.</p>
<p>I'm going to answer your question by designing a Haskell data structure by "induction", which is a sort of "dual" to recursion. And then I will show how this duality leads to nice things.</p> <p>We introduce a type for a simple tree:</p> <pre><code>data Tree a = Branch (Tree a) (Tree a) | Leaf a deriving (Eq) </code></pre> <p>We can read this definition as saying "A tree is a Branch (which contains two trees) or is a leaf (which contains a data value)". So the leaf is a sort of minimal case. If a tree isn't a leaf, then it must be a compound tree containing two trees. These are the only cases.</p> <p>Let's make a tree:</p> <pre><code>example :: Tree Int example = Branch (Leaf 1) (Branch (Leaf 2) (Leaf 3)) </code></pre> <p>Now, let's suppose we want to add 1 to each value in the tree. We can do this by calling:</p> <pre><code>addOne :: Tree Int -&gt; Tree Int addOne (Branch a b) = Branch (addOne a) (addOne b) addOne (Leaf a) = Leaf (a + 1) </code></pre> <p>First, notice that this is in fact a recursive definition. It takes the data constructors Branch and Leaf as cases (and since Leaf is minimal and these are the only possible cases), we are sure that the function will terminate.</p> <p>What would it take to write addOne in an iterative style? What will looping into an arbitrary number of branches look like?</p> <p>Also, this kind of recursion can often be factored out, in terms of a "functor". We can make Trees into Functors by defining:</p> <pre><code>instance Functor Tree where fmap f (Leaf a) = Leaf (f a) fmap f (Branch a b) = Branch (fmap f a) (fmap f b) </code></pre> <p>and defining:</p> <pre><code>addOne' = fmap (+1) </code></pre> <p>We can factor out other recursion schemes, such as the catamorphism (or fold) for an algebraic data type. Using a catamorphism, we can write:</p> <pre><code>addOne'' = cata go where go (Leaf a) = Leaf (a + 1) go (Branch a b) = Branch a b </code></pre>
9,783
<p>I am thinking to use closed-loop stepper motors to prevent step loss and make the machine more accurate. What options (preferably low cost) are there for:</p> <p><code>stepper motor + driver + encoder + microcontoller</code></p> <p>Is building it from scratch worth it? E.g. Arduino Mega 2560 + RAMPS 1.4/1.5/1.6 + stepper motors (e.g. NEMA17) + drivers (e.g. A4988, DRV8825) + encoders (e.g. AS5047P, AS5047D, AS5048A, TLE5012B) + microcontrollers (e.g. STM32).</p>
<p>A number of options exist, but keep in mind that cost will be a limiting factor.</p> <p><em>(Small sidenote: cost depends on persective, financial cost does not equal mental cost. The tradeoff between buy or make depends also on your willingness to persist when things don't work right away.)</em></p> <p><strong>Before you start:</strong> make sure that your printer has enough space to accomodate bigger motors.</p> <p><strong>So, what options are there?</strong> </p> <ol> <li><p>Change your current configuration. If you are losing steps, it could very well be that it can be fixed in firmware.</p> <ul> <li>Pro: No budget and nothing to lose.</li> <li>Con: No shiny closed loop system. (Is that bad though?) Possibly need to configure and compile your own firmware.</li> </ul></li> <li><p>MacGyver / DIY solution based on low lever components</p> <ul> <li>Pro: Probably as cheap as you'll get depending on how you choose your components. Might be an interesting learning experience, not to mention the satisfaction afterwards. This could be the smallest build size you'll see in all the options.</li> <li>Con: You'll need a decent amount of engineering and debugging. Might be tricky to mount the encoders. </li> </ul></li> <li><p>Same as 1, but now consider using of the shelf stepper motors <a href="https://www.omc-stepperonline.com/stepper-motor-w-encoder?mfp=161-motor-nema-size[Nema%2017]" rel="nofollow noreferrer">with integrated encoders</a>.</p> <ul> <li>Pro: Most robust option on a budget in my opinion due to the single mechanical piece (motor + encoder).</li> <li>Con: Integrated encoders have a considerable cost and are large compared to their vanila versions.</li> </ul></li> <li><p>Go for <a href="https://www.omc-stepperonline.com/closed-loop-stepper-kit" rel="nofollow noreferrer">off the shelf motor+encoder and drivers</a>.</p> <ul> <li>Pro: No need to worry about driver configurations too much. Just plug in the numbers or set the dip switches. Very conveinient solution. Pretty much plug and play.</li> <li>Con: This will already be challenging on a budget. Making a wrong mix and match might lead to unpredictable results such as drives going in overcurrent. (Which, believe me, is very frustrating for your application!)</li> </ul></li> <li><p>If we are allowed to consider servo motors: <a href="https://www.teknic.com/products/clearpath-brushless-dc-servo-motors/clearpath-sd-stepper-replacement/" rel="nofollow noreferrer">ClearPath-SD series</a> (Or any alternative for that matter!) <em>I'm just including this for completeness.</em></p> <ul> <li>Pro: Performance wise a clear winner on pretty much any relevant level.</li> <li>Con: You'll need a big budget!</li> </ul></li> </ol> <p><strong>Bottomline</strong>: You'll probably want to give the first option a go before spending money. Next stop, you might want to take the second option (you already did research on different specific low level components), and if you have time to spare I'd go with that as well. If you are also on a budget timewise, I'd definively suggest to take the third option with existing driver boards.</p> <p>The other options are more cost heavy and become real options in produciton environments, where downtime is also costsing money.</p> <p>As to the microcontroller, take whatever you have available. Just know that more computational power will allow you to output steps faster and will allow for smoother movements. Lot's to talk about there as well!</p>
<p>So, I am one of those who has implemented this on my big scale heavily modified cr-10 S5. </p> <p>Why?</p> <p>Well with bigger prints, the risk of crashing into itself because of a small blob is very real. Possibly ruining a 100$ worth of filament and missing deadlines. (We are using this professionally.) Blobs will happen, especially if you run low cost filaments and PETG, which is the only sane option for functional bigger prints from a cost perspective. We are using the BTT system S42B on all axis and it works well. A blob is now just a small distraction which can be polished away but the remaining print is still dimensionally correct.</p> <p>However, it is not a trivial task to actually implement. To make this work one needs a printer main board allowing for external stepper drivers, like SKR E3 DIP,SKR V1.4,SKR V1.4 Turbo and so on. Also there one needs to tune the PID:s for the system in use which is not super simple.</p> <p>If you are truly an expert and do big prints, I really think this is a must have upgrade. On the other hand if one are only printing smaller parts on a hobby scale this will not be a worth while upgrade. I am not talking about the money involved, the pcbs are just 14$/pcs but the work needed with new cabling pid-tuning marlin-digging and so on. For us it is just amazing to not have 30% failures any more, du to the inevitable blobs sometimes appearing in bigger prints.</p>
1,598
<p>I have a Java application that launches another java application. The launcher has a watchdog timer and receives periodic notifications from the second VM. However, if no notifications are received then the second virtual machine should be killed and the launcher will perform some additional clean-up activities.</p> <p>The question is, is there any way to do this using only java? so far I have to use some native methods to perform this operation and it is somehow ugly.</p> <p>Thanks!</p>
<p>I may be missing something but can't you call the <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Process.html#destroy()" rel="noreferrer"><code>destroy()</code></a> method on the <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Process.html" rel="noreferrer"><code>Process</code></a> object returned by <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Runtime.html#exec(java.lang.String)" rel="noreferrer"><code>Runtime.exec()</code></a>?</p>
<p>You should be able to do that <code>java.lang.Runtime.exec</code> and shell commands.</p>
8,919
<p>Given:</p> <pre><code>e = 'a' + 'b' + 'c' + 'd' </code></pre> <p>How do I write the above in two lines?</p> <pre><code>e = 'a' + 'b' + 'c' + 'd' </code></pre>
<p>What is the line? You can just have arguments on the next line without any problems:</p> <pre><code>a = dostuff(blahblah1, blahblah2, blahblah3, blahblah4, blahblah5, blahblah6, blahblah7) </code></pre> <p>Otherwise you can do something like this:</p> <pre><code>if (a == True and b == False): </code></pre> <p>or with explicit line break:</p> <pre><code>if a == True and \ b == False: </code></pre> <p>Check the <a href="http://www.python.org/dev/peps/pep-0008/" rel="noreferrer">style guide</a> for more information.</p> <p>Using parentheses, your example can be written over multiple lines:</p> <pre><code>a = ('1' + '2' + '3' + '4' + '5') </code></pre> <p>The same effect can be obtained using explicit line break:</p> <pre><code>a = '1' + '2' + '3' + \ '4' + '5' </code></pre> <p>Note that the style guide says that using the implicit continuation with parentheses is preferred, but in this particular case just adding parentheses around your expression is probably the wrong way to go.</p>
<p>Taken from The Hitchhiker's Guide to Python (<a href="https://docs.python-guide.org/writing/style/#line-continuations" rel="nofollow noreferrer">Line Continuation</a>):</p> <blockquote> <p>When a logical line of code is longer than the accepted limit, you need to split it over multiple physical lines. The Python interpreter will join consecutive lines if the last character of the line is a backslash. This is helpful in some cases, but should usually be avoided because of its fragility: a white space added to the end of the line, after the backslash, will break the code and may have unexpected results.</p> <p><strong>A better solution is to use parentheses around your elements.</strong> Left with an unclosed parenthesis on an end-of-line the Python interpreter will join the next line until the parentheses are closed. The same behaviour holds for curly and square braces.</p> <p><strong>However</strong>, more often than not, having to split a long logical line is a sign that you are trying to do too many things at the same time, which may hinder readability.</p> </blockquote> <p>Having that said, here's an example considering multiple imports (when exceeding <a href="https://www.python.org/dev/peps/pep-0008/#maximum-line-length" rel="nofollow noreferrer">line limits, defined on PEP-8</a>), also applied to strings in general:</p> <pre><code>from app import ( app, abort, make_response, redirect, render_template, request, session ) </code></pre>
7,660
<p>I ordered an <a href="http://rads.stackoverflow.com/amzn/click/B007KG0ZYI" rel="nofollow">OEM Power Supply</a> and I intend to hook up with <a href="http://rads.stackoverflow.com/amzn/click/B00511QVVK" rel="nofollow">this rocker switch</a> I believe it's like the one specified in the <a href="http://reprap.org/wiki/Power_Supply#OEM_type_PSU" rel="nofollow">Power Supply Documentation</a> which reads:</p> <blockquote> <p>In the US, IEC320 C14 plug connections are common, but use your preferred standard.</p> </blockquote> <p>I've also seen where this was attached in <a href="http://www.thingiverse.com/thing:31659" rel="nofollow">this thingiverse project</a>.</p> <p>Inside the switch I've also added an F4AL250V fuse. </p> <p>Now what's confusing me is, that the <a href="http://rads.stackoverflow.com/amzn/click/B00511QVVK" rel="nofollow">this rocker switch</a> on the back reads 10A 250V~ so I'm wondering if it's safe to use.</p> <p>The switch will be connected to the house mains via a plug and wired just like in the <a href="http://www.thingiverse.com/thing:31659" rel="nofollow">this thingiverse project</a>, so it can be the input into my <a href="http://rads.stackoverflow.com/amzn/click/B007KG0ZYI" rel="nofollow">OEM Power Supply</a> via the black (hot - L), white (Common - N) and Green (Ground) wires. </p> <p>For the connecting wires I stripped a black PC Tower wire to get at the black, white, and ground wires inside it.</p> <p><a href="http://reprap.org/wiki/Power_Supply#OEM_type_PSU" rel="nofollow">http://reprap.org/wiki/Power_Supply#OEM_type_PSU</a></p>
<p>According to the RepRap.org <a href="http://reprap.org/wiki/G-code" rel="nofollow noreferrer">list of G-Code commands</a>, see <strong><a href="http://reprap.org/wiki/G-code#G0_.26_G1:_Move" rel="nofollow noreferrer">G0 &amp; G1: Move</a></strong>:</p> <blockquote> <p>The <code>Ennn</code> command is <em>The amount to extrude between the starting point and ending point</em>. </p> </blockquote> <p>However, according to <strike><a href="https://github.com/daid/Cura/issues/385" rel="nofollow noreferrer">this</a></strike> a discussion, that is now deleted from GitHub, about the Cura slicing engine:</p> <p>The <strong>E</strong> values are in <em>absolute mode</em>, so perhaps the firmware is attempting to move the stepper motor to the absolute position (which is almost 50% through your print). This may lead to clogging or skipping depending on how hot your extruder is at that point.</p> <p>As a last resort, you can perform a Boolean subtract on your model of the section that's already printed and re-slice the model to print the remaining bit. Then glue, or ABS weld, the remaining piece to the main print. I've done this in the past, it's not super glamorous, but it gets the job done if the part doesn't require a lot of structural integrity.</p> <p><strong>I was incorrect with the following statements with regard to the Cura slicing engine:</strong> </p> <p><s>It's been a while since I've looked at 3D printer G-Code, but from what I remember, <strong>E</strong> values can be the bane of any manually written G-Code. Usually the slicing engine generates the <strong>E</strong> value as an incremental step value throughout the G-Code (at least this was true for Skeinforge and early MakerWare, please verify this). So, if the value is incremental and depending on the controller, this value could be lost or corrupt if a new print is initialized.</p> <p>I would hope, that if you're using a slicing engine's <em>custom G-Code</em> input, that the software would be able to compensate situations like this and reformat your provided G-Code to match the value of <strong>E</strong> or any similar command.</s></p>
<p>Is the hotend temperature set correctly? If you only preheat the hotend but then turn it off, it will behave exactly as you described (while you're above <code>EXTRUDE_MINTEMP</code> it will behave normally, but once the temperature drops too low it will continue doing the XYZ-moves, but stop extruding). Perhaps you need to add a <code>M109</code> command to set the temperature properly.</p> <p><a href="https://3dprinting.stackexchange.com/questions/850/no-extrusion-when-trying-to-resume-failed-print-with-manually-edited-gcode/851#851">In his answer</a>, tbm0115 mentions absolute and relative coordinates. Whether absolute or relative coordinates are used is set using the <code>G90</code>/<code>G91</code> commands and will always be the same for all axes (XYZ and E). He also mentions that:</p> <blockquote> <p>so perhaps the firmware is attempting to move the stepper motor to the absolute position (which is almost 50% thru your print). This may lead to clogging or skipping depending on how hot your extruder is at that point.</p> </blockquote> <p>This shouldn't happen, as extremely long extrude moves are ignored by Marlin. When the printer encounters</p> <pre><code>G1 F3600 X210.390 Y105.771 E4104.65185 </code></pre> <p>it performs only the XYZ-part of the move, but doesn't move the extruder (assuming the printer was reset and the current extruder position is 0). However, it does update the internal value for the extruder position, so the next move happens normally. Perhaps missing the initial extrude segment isn't a big deal, but if you want the print to resume perfectly where you left off, you should add a <code>G92</code> command to the beginning to initialize the extruder position correctly, for example:</p> <pre><code>G92 E4104.4 </code></pre> <p>(but the exact value depends on the last extruder position in the previous layer).</p>
233
<p>We are getting new dev machines and moving up to Vista 64 Ultimate to take advantage of our 8gb ram. Our manager wants us to do all dev in 32bit virtual machines to make sure there will be no problems with our code moving into production. </p> <p>Is there any way to guarantee the resultant programs will work on 32bit os's? I don't mind using virtual machines, but I don't like how they force you back into a "Single" monitor type view. I like moving my VS toolbars off to my other monitor.</p> <p>EDIT: We are using Visual Studio 2005 and 2008, VB.NET and/or C#</p> <p>EDIT: Using Harpreet's <a href="https://stackoverflow.com/questions/30543/is-code-written-in-vista-64-compatible-on-32-bit-os#30643">answer</a>, these are the steps I used to set my Visual Studio IDE to compile x86 / 32bit:</p> <ol> <li>Click Build and open Configuration Manager</li> <li>Select Active Solution Platform drop down list</li> <li>Select x86 if it is in the list and skip to step 5, if not Select <code>&lt;New...</code>></li> <li>In the New Solution Platform dialog, select x86 and press OK</li> <li>Verify the selected platform for all of your projects is x86</li> <li>Click Close.</li> </ol> <p>Enjoy. </p> <p>Thank you, Keith</p>
<p>I do development on 64 bit machines for 32 bit Windows. It's not a problem. You should make sure that your projects are set to compile in x86 mode in order to be conservative. You'll want to go through each project in the solution and double check this. You could also use the AnyCPU setting but that's a little riskier since it will run differently on your dev machine than a 32 bit machine. You want to avoid the 64bit mode, of course. </p> <p>The problems I've run into are drivers that don't work when the app is compiled for 64 bit (explicitly 64 bit or AnyCPU compiled and running on 64 bit Windows). Those problems are completely avoidable by sticking with x86 compilation. That should reveal all flaws on your dev machines.</p> <p>Ideally, you could set up a build and test environment that could be executed against frequently on a 32 bit machine. That should reassure your management and let you avoid the VM as your desktop.</p>
<p>yeah, like adam was saying. There's 3 options: MSIL (default), x64, and x86. You can target x64 and it will generate dll's specifically for 64-bit systems, or you can do x86 which will run on 32-bit and 64-bit, but will have the same restrictions as 32-bit on a 64-bit system.</p> <p>MSIL will basically let the JITer issue the platform specific instruction (at a slight performance penalty compared to a native image)</p> <p><strong>EDIT</strong>: no language, so i'm talking about .net framework languages like vb.net and c#, c++ is a completely different animal.</p>
5,043
<p>I need to learn ADO.NET to build applications based on MS Office. I have read a good deal about ADO.NET in the MSDN Library, but everything seems rather messy to me.</p> <p>What are the basics one must figure out when using ADO.NET? I think a few key words will suffice to let me organize my learning.</p>
<p>There are three key components (assuming ur using SQL server):</p> <ul> <li><code>SQLConnection</code></li> <li><code>SqlCommand</code></li> <li><code>SqlDataReader</code></li> </ul> <p>(if you're using something else, replace <code>Sql</code> with "Something", like <code>MySqlConnection</code>, <code>OracleCommand</code>)</p> <p>Everything else is just built on top of that.</p> <p><strong>Example 1:</strong></p> <pre><code>using (SqlConnection connection = new SqlConnection("CONNECTION STRING")) using (SqlCommand command = new SqlCommand()) { command.commandText = "SELECT Name FROM Users WHERE Status = @OnlineStatus"; command.Connection = connection; command.Parameters.Add("@OnlineStatus", SqlDbType.Int).Value = 1; //replace with enum connection.Open(); using (SqlDataReader dr = command.ExecuteReader)) { List&lt;string&gt; onlineUsers = new List&lt;string&gt;(); while (dr.Read()) { onlineUsers.Add(dr.GetString(0)); } } } </code></pre> <p><strong>Example 2:</strong></p> <pre><code>using (SqlConnection connection = new SqlConnection("CONNECTION STRING")) using (SqlCommand command = new SqlCommand()) { command.commandText = "DELETE FROM Users where Email = @Email"; command.Connection = connection; command.Parameters.Add("@Email", SqlDbType.VarChar, 100).Value = "user@host.com"; connection.Open(); command.ExecuteNonQuery(); } </code></pre>
<p>Another way of getting a command object is to call <code>connection.CreateCommand()</code>. </p> <p>That way you shouldn't have to set the <code>Connection</code> property on the command object. </p>
2,618
<p>I see there was already a meta question regarding this but it was back during the private beta. The site is now in the public beta and still not very healthy with only 2.1 questions per day and a very low 219 visits per day compared to the recommended 1,500...</p> <p>I'm not sure what happens once the beta ends but only 14 days remain and from what I've seen the numbers have not improved much at all since I've been a member here. I've thought about going to other areas and "advertising" the site but most places where one could attract members (reprap.org, various subreddits, groups on Facebook) are areas I feel we may be in competition with and it would not put the site in good standing if we were to do so.</p> <p>I don't really know what the value here is over other forums other than the site being owned by a neutral party. The forums at reprap.org would probably be the closest thing to this site seeing as how they have no real ties to any one printer/design/company and moderation is quite lax as in you can post nearly anything 3D printing related and not encounter any trouble. The problem I believe is the site is trying to compete with other forums, one of which has been "the" forum pretty much since printing began and the main domain holds the majority of the information about home 3D printing.</p> <p>I guess being new here I don't really understand the value in the site over the others or if there really is any other than being just another bank of information.</p> <p>Currently, there hasn't been a new question in 2 days...</p>
<p>Tag excerpts should at least try and give a concise definition as to the subject, and provided any usage guidance <em>if necessary.</em></p> <p>Therefore, you need to make sure to address a set of key points:</p> <ul> <li>Is the tag name ambiguous? Will an amateur be able to understand the subject without having to research it? For example, what on earth is <a href="https://3dprinting.stackexchange.com/questions/tagged/abs" class="post-tag" title="show questions tagged &#39;abs&#39;" rel="tag">abs</a>?</li> <li>Can the word have multiple meanings? If yes, you need to be specific as to which meaning you want. For example, <a href="https://3dprinting.stackexchange.com/questions/tagged/health" class="post-tag" title="show questions tagged &#39;health&#39;" rel="tag">health</a> vs <a href="https://3dprinting.stackexchange.com/questions/tagged/safety" class="post-tag" title="show questions tagged &#39;safety&#39;" rel="tag">safety</a></li> <li>Are their cases when the tag should not be used?</li> <li>Likewise, are their cases when the tag should be used?</li> <li>Is the existing excerpt empty? Something is usually better than nothing.</li> </ul> <p>In general, excerpts should provide at least some guidance, even if it may appear to be ridiculously basic. Therefore, interpretation of the rejection reason is critical:</p> <blockquote> <p>Tag excerpts amounting to, "[tag] is for questions about [tag]" are pointless and usually rejected. Excerpts should describe why and when a tag would be used.</p> </blockquote> <p>That's like saying, <em>[abs]: For questions about [abs] filaments.</em> That should probably be rejected.</p> <p>This is better: <em>[abs]: For questions about [abs] filaments - filaments that are used with blah blah printers, and are not toxic for use.</em></p> <p>Or even better: <em>[abs]: For questions about [abs] filaments - filaments that are used with blah blah printers, and are not toxic for use. Not to be confused with [pla] filaments. Do not use this tag if your question does not concern this filament specifically.</em></p> <p>Obviously, I have no idea if abs is even a thing. Anyways, I hope this helps :)</p>
<p>For reference, I would like to propose a copy-paste solution for tags.</p> <p><strong>Usage Guidance</strong></p> <p><code>For questions regarding {insert list of applicable topics} of {Tag Name}.</code></p> <p><strong>Details</strong></p> <pre><code>{Tag name, unabbreviated}: {Definition} Examples: - What is {blah blah blah}? - Where can I find {blah blah blah}? - Why does {blah blah blah}? - How do I {blah blah blah}? </code></pre>
23
<p>Is it possible to deploy a native Delphi application with ClickOnce without a stub C# exe that would be used to launch the Delphi application?</p> <p>The same question applies to VB6, C++ and other native Windows applications.</p>
<p>Personally, I build my own mechanism to kick off self update process when my application timestamp is out of sync with the server. Not too difficult, but it's not a simple task.</p> <p>By the way, for Delphi you can use some thirdparty help:</p> <p><a href="http://www.tmssoftware.com/site/wupdate.asp" rel="nofollow noreferrer">http://www.tmssoftware.com/site/wupdate.asp</a></p> <p>UPDATED:</p> <p>For my implementation:</p> <p>MyApp.EXE will run in 3 different modes</p> <ol> <li><p>MyApp.EXE without any argument. This will start the application typically.</p> <p>1.1 The very first thing it does is to validate its own file-time with the server.</p> <p>1.2 If update is required then it will download the updated file to the file named "MyApp-YYYY-MM-DD-HH-MM-SS.exe"</p> <p>1.3 Then it invoke "MyApp-YYYY-MM-DD-HH-MM-SS.exe" with command argument </p> <pre><code>MyApp-YYYY-MM-DD-HH-MM-SS.exe --update MyApp.EXE </code></pre> <p>1.4 Terminate this application.</p> <p>1.5 If there is no update required then the application will start normally from 1.1</p></li> <li><p>MyApp.EXE --update "FILENAME".</p> <p>2.1 Try copying itself to "FILENAME" every 100ms until success.</p> <p>2.2 Invoke "FILENAME" when it success</p> <p>2.3 Invoke "FILNAME --delete MyApp-YYYY-MM-DD-HH-MM-SS.exe" to delete itself.</p> <p>2.4 Terminate</p></li> <li><p>MyApp.EXE --delete "FILENAME"</p> <p>3.1 Try deleting the file "FILENAME" every 500ms until success.</p> <p>3.2 Terminate</p></li> </ol> <p>I've already been using this scheme for my application for 7 years and it works well. It could be quite painful to debug when things goes wrong since the steps involve many processes. I suggest you make a lot of trace logging to allow simpler trouble-shooting.</p> <p>Good Luck</p>
<p>I'm not 100% sure if this can be accomplished without the stub, but this article may provide some insight:</p> <p><a href="http://blogs.msdn.com/g/archive/2008/06/06/sample-demonstrating-clickonce-deployment-of-com-component-implemented-in-managed-assembly-without-using-gac-or-registry-and-without-requiring-admin-rights.aspx" rel="nofollow noreferrer">How To: ClickOnce deployment for unmanaged app with COM component in managed assembly </a></p>
7,489
<p>I actually have an answer to my question but it is not parallelized so I am interested in ways to improve the algorithm. Anyway it might be useful as-is for some people.</p> <pre><code>int Until = 20000000; BitArray PrimeBits = new BitArray(Until, true); /* * Sieve of Eratosthenes * PrimeBits is a simple BitArray where all bit is an integer * and we mark composite numbers as false */ PrimeBits.Set(0, false); // You don't actually need this, just PrimeBits.Set(1, false); // remindig you that 2 is the smallest prime for (int P = 2; P &lt; (int)Math.Sqrt(Until) + 1; P++) if (PrimeBits.Get(P)) // These are going to be the multiples of P if it is a prime for (int PMultiply = P * 2; PMultiply &lt; Until; PMultiply += P) PrimeBits.Set(PMultiply, false); // We use this to store the actual prime numbers List&lt;int&gt; Primes = new List&lt;int&gt;(); for (int i = 2; i &lt; Until; i++) if (PrimeBits.Get(i)) Primes.Add(i); </code></pre> <p>Maybe I could use multiple <code>BitArray</code>s and <a href="http://msdn.microsoft.com/en-us/library/system.collections.bitarray.and.aspx" rel="noreferrer">BitArray.And()</a> them together?</p>
<p>You might save some time by cross-referencing your bit array with a doubly-linked list, so you can more quickly advance to the next prime.</p> <p>Also, in eliminating later composites once you hit a new prime p for the first time - the first composite multiple of p remaining will be p*p, since everything before that has already been eliminated. In fact, you only need to multiply p by all the remaining potential primes that are left after it in the list, stopping as soon as your product is out of range (larger than Until).</p> <p>There are also some good probabilistic algorithms out there, such as the Miller-Rabin test. <a href="http://en.wikipedia.org/wiki/Primality_test" rel="noreferrer">The wikipedia page</a> is a good introduction.</p>
<pre><code> void PrimeNumber(long number) { bool IsprimeNumber = true; long value = Convert.ToInt32(Math.Sqrt(number)); if (number % 2 == 0) { IsprimeNumber = false; MessageBox.Show("No It is not a Prime NUmber"); return; } for (long i = 3; i &lt;= value; i=i+2) { if (number % i == 0) { MessageBox.Show("It is divisible by" + i); IsprimeNumber = false; break; } } if (IsprimeNumber) { MessageBox.Show("Yes Prime NUmber"); } else { MessageBox.Show("No It is not a Prime NUmber"); } } </code></pre>
5,073
<p>Is there a C# equivalent for the VB.NET <code>FormatNumber</code> function? </p> <p>I.e.:</p> <pre><code>JSArrayString += "^" + (String)FormatNumber(inv.RRP * oCountry.ExchangeRate, 2); </code></pre>
<p>In both C# and VB.NET you can use either the <a href="http://www.java2s.com/Code/CSharp/Development-Class/UseToStringtoformatvalues.htm" rel="nofollow noreferrer">.ToString()</a> function or the <a href="http://www.java2s.com/Code/CSharp/Development-Class/UseStringFormattoformatavalue.htm" rel="nofollow noreferrer">String.Format()</a> method to format the text. </p> <p>Using the .ToString() method your example could be written as:</p> <pre><code>JSArrayString += "^" + (inv.RRP * oCountry.ExchangeRate).ToString("#0.00") </code></pre> <p>Alternatively using the String.Format() it could written as:</p> <pre><code>JSArrayString = String.Format("{0}^{1:#0.00}",JSArrayString,(inv.RRP * oCountry.ExchangeRate)) </code></pre> <p>In both of the above cases I have used custom formatting for the currency with # representing an optional place holder and 0 representing a 0 or value if one exists. </p> <p>Other formatting characters can be used to help with formatting such as D2 for 2 decimal places or C to display as currency. In this case you would not want to use the C formatter as this would have inserted the currency symbol and further separators which were not required.</p> <p>See "<a href="http://idunno.org/archive/2004/14/01/122.aspx" rel="nofollow noreferrer">String.Format("{0}", "formatting string"};</a>" or "<a href="http://www.csharp-examples.net/string-format-int/" rel="nofollow noreferrer">String Format for Int</a>" for more information and examples on how to use String.Format and the different formatting options.</p>
<p>While I would recommend using ToString in this case, always keep in mind you can use ANY VB.Net function or class from C# just by referencing Microsoft.VisalBasic.dll.</p>
7,205
<p>I have a long 8&nbsp;mm smooth steel rod of about 55&nbsp;cm long. This rods bend easily due to the length. If I replace them with 8mm solid carbon fiber rods, will the bending reduce? Will the bearings wear off the carbon fiber rod? I couldn't find too much information about this.</p>
<p>Steel is the best material for a linear rod when you have a fixed cross-section. It will have the least flex of any rod (aside from some exotic metals) of the same size. </p> <p>Carbon fiber's material properties might seem superior at first sight, but the stiffness is very anisotropic -- it's very stiff along the grain and not very stiff across the grain. So multi-axis stresses like bending aren't necessarily going to perform up to the theoretical specs. Carbon fiber has exceptional stiffness-to-weight ratio, but the stiffness-per-area isn't necessarily superior in this application. </p> <p>People do occasionally use carbon fiber for linear rods/rails, but only in much larger sizes than 8&nbsp;mm. Think >25&nbsp;mm. </p> <p>And that's really the problem here. 8&nbsp;mm diameter at 550&nbsp;mm long is well outside what's reasonable for bending stiffness. Bending deflection increases with the CUBE of length, and this is simply far too long for the size of rod. The general rule of thumb for precision motion applications is length &lt; 25*diameter. That's a conservative rule, but it's the right ballpark. You really shouldn't be going over 200-250&nbsp;mm or so with an 8&nbsp;mm rod. </p>
<p>I agree that steel is the best material for rails but the info provided on carbon fiber is just wrong.</p> <p>When making a carbon fiber part, whether a tube or any other shape, you lay the fabric in the orientation you need for the direction of the forces. If multi-directional strength and stiffness is needed then the fibers are laid in multiple directions. Nobody who knows what they are doing lays all the cf in one direction...</p> <p>In general, carbon fiber is stronger than steel by both the strength to weight ratio and by volume. I say "in general" because parts need to be designed in the right way. A poorly designed carbon fiber part or a low quality steel can easily be weak. </p> <p>There is a great video on YouTube showing a strength and stiffness comparison of a carbon fiber drive shaft vs the same part made in steel. The steel drive shaft bent and snapped with 3 times less force while the cf drive shaft had no visible bending until it snapped.</p> <p>The main reason why steel is a better linear rail material is surface hardness. Linear rails have bearings traveling up and down continuously. The rails need to be hardened to prevent them wearing out too quickly. The surface hardness (how easy it is to scratch or penetrate) of cf is far lower than steel. There is no comparison.</p> <p>Cf is great material for the frame but not the rails. For stiffer rails, I suggest buying some square THK rails. 15mm the rails will be plenty stiff enough for most 3d printers.</p>
242
<p>I would like to start tagging my deployed binaries with the latest SVN revision number.</p> <p>However, because SVN is file-based and not directory/project-based, I need to scan through all the directory's and subdirectory's files in order to determine the highest revision number.</p> <p>Using <code>svn info</code> on the root doesn't work (it just reports the version of that directory, not files in subdirectories):</p> <p>I was wondering if there is a shortcut using the <code>svn</code> command to do this. Otherwise, can anyone suggest a simple script that is network-efficient (I would prefer if it didn't hit the remote server at all)?</p> <p>I also understand that one alternative approach is to keep a <em>version file</em> with the <code>svn:keywords</code>. This works (I've used it on other projects), but I get tired of dealing with making sure the file is dirty and dealing with the inevitable merge conflicts.</p> <p><strong>Answer</strong> I see my problem lied with not doing a proper <code>svn up</code> before calling <code>svn info</code> in the root directory:</p> <pre><code>$ svn info Path: . ... Last Changed Author: fak Last Changed Rev: 713 Last Changed Date: 2008-08-29 00:40:53 +0300 (Fri, 29 Aug 2008) $ svn up At revision 721. $ svn info Path: . ... Revision: 721 Last Changed Author: reuben Last Changed Rev: 721 Last Changed Date: 2008-08-31 22:55:22 +0300 (Sun, 31 Aug 2008) </code></pre>
<p>One way. When you check out the code, look at the last line of svn output:</p> <pre><code>$ svn up ...stuff... Updated to revision 66593. </code></pre> <p>A more direct way:</p> <pre><code>$ svn info Path: . URL: https://svn.example.com/svn/myproject/trunk Repository Root: https://svn.example.com/svn/ Repository UUID: d2a7a951-c712-0410-832a-9abccabd3052 Revision: 66593 Node Kind: directory Schedule: normal Last Changed Author: bnguyen Last Changed Rev: 66591 Last Changed Date: 2008-09-11 18:25:27 +1000 (Thu, 11 Sep 2008) </code></pre>
<p>This is ridiculous but <code>svn info</code> or <code>svnversion</code> wont take into consideration subdirectories; it's a feature called working 'Mixed Revisions' - I call it torture. I just needed to find the latest 'revision' of the live codebase and the hacked way below worked for me - it might take a while to run:</p> <pre><code>repo_root# find ./ | xargs -l svn info | grep 'Revision: ' | sort ... Revision: 86 Revision: 86 Revision: 89 Revision: 90 root@fairware:/home/stage_vancity# </code></pre>
8,011
<p>I have my nozzle close to the substrate that I am printing on, so that a piece of paper can just about slide underneath it freely, without catching.</p> <p>Is this the right way to do it?</p>
<p>Traditionally, using a piece of paper (about 0.004" thick) gets you close to your appropriate standoff. However, if you adjust your layer thickness, your standoff should reflect this. Ideally, you will set your standoff <strong>roughly</strong> with a piece of paper or other type of shim stock, then "fine-tune" the standoff during a benchmark print.</p> <p>If I'm remembering correctly, the ideal standoff is 1/2 to 2/3 your desired layer height.</p>
<p>Using a piece of paper won't guarantee you get exactly the "correct" height (because different papers have different thicknesses, and it's hard to determine exactly when it no longer catches on the nozzle) but it gets the bed level and the distance will be close to correct.</p> <p>You can then further adjust the height by observing the first layer and making adjustments based on whether you see the first layer being squished down enough or too much. The babystepping feature (if enabled) is very useful for this.</p>
405
<pre><code>&lt;xsl:for-each select="./node [position() &amp;lt;= (count(*) div 2)]"&gt; &lt;li&gt;foo&lt;/li&gt; &lt;/xsl:for-each&gt; &lt;xsl:for-each select="./node [count(*) div 2 &amp;lt; position()]"&gt; &lt;li&gt;bar&lt;/li&gt; &lt;/xsl:for-each&gt; </code></pre> <p>My list has 12 nodes, but the second list is always 8 and the first is always 4. What's wrong with my selects?</p>
<p>When you do <code>count(*)</code>, the current node is the <code>node</code> element being processed. You want either <code>count(current()/node)</code> or <code>last()</code> (preferable), or just calculate the midpoint to a variable for better performance and clearer code:</p> <pre><code>&lt;xsl:variable name="nodes" select="node"/&gt; &lt;xsl:variable name="mid" select="count($nodes) div 2"/&gt; &lt;xsl:for-each select="$nodes[position() &amp;lt;= $mid]"&gt; &lt;li&gt;foo&lt;/li&gt; &lt;/xsl:for-each&gt; &lt;xsl:for-each select="$nodes[$mid &amp;lt; position()]"&gt; &lt;li&gt;bar&lt;/li&gt; &lt;/xsl:for-each&gt; </code></pre>
<p>I'm not at all sure, but it seems to me that <code>count(*)</code> is not doing what you think it is. That counts the number of children of the current node, not the size of the current node list. Could you print it out to check that it's 8 or 9 instead of 12?</p> <p>Use <code>last()</code> to get the context size.</p>
5,425
<p>I have 2 hosts and I would like to point a subdomain on host one to a subdomain on host two:</p> <pre><code>subdomain.hostone.com --&gt; subdomain.hosttwo.com </code></pre> <p>I added a CNAME record to host one that points to subdomain.hosttwo.com but all I get is a '<strong>400 Bad Request</strong>' Error.</p> <p>Can anyone see what I'm doing wrong?</p>
<p>Try changing it to "subdomain -> subdomain.hosttwo.com"</p> <p>The <code>CNAME</code> is an alias for a certain domain, so when you go to the control panel for hostone.com, you shouldn't have to enter the whole name into the <code>CNAME</code> alias.</p> <p>As far as the error you are getting, can you log onto subdomain.hostwo.com and check the logs?</p>
<p>It's probably best/easiest to set up a <a href="http://www.webconfs.com/how-to-redirect-a-webpage.php" rel="nofollow noreferrer">301 redirect</a>. No DNS hacking required.</p>
3,699
<p>I have a 3D printed object that I'd like to print on. Adhesive stickers are an option, but as the surface is rounded it's difficult to get a good film to stick well. </p> <p>Is there any system to print on a 3D object (e.g. ink jet). I need at least 300dpi. Black in the first instance, but color would be nice for future projects. </p>
<p>Rather than post a series of links for various services and vendors, consider to use as a search term "hydrographic film at home" to find results to suit your purpose. The first search results I found excluded "at home" and indicated it was not suited for home/hobbyist use, but the modification resulted in vendors supportive of home users.</p> <p>In advanced circumstances, the image printed on the film is topographically matched to the model to which it is to be applied. For home users, I suspect that is somewhat out of reach. Most of the products aimed at the home user are patterns or solid colors, although with care, one could combine films in sequential applications.</p> <p>Effectively, the process involves a colored film floating on a water filled container. Certain products are applied to the film and to the prepared model to ensure bonding. Additional processes are required to protect the graphic-coated model after removal from the bath/container.</p> <p>As with the other responses, it's not likely one will achieve 300 dpi resolution without resorting to the topographically matched commercial methods.</p>
<p>There are printer types that can print images into the material as it's being printed. SLA and SLS type printers are capable of this but I believe Polyjet printers are the best suited.</p> <p>At 300 dpi though you might be pushing the edge of what is capable. to get that fine of detail your best option may be to look into getting a vinyl wrap for your part that is applied after it's printed. If you've seen cars with really high detail images on them, a vinyl wrap is typically how they're done.</p> <h3>Note</h3> <p>I should state that the SLA and SLS embedded images are still in the R&amp;D phases and being experimented with. Possible now, but not in production phase. The SLS version essentially ran another print head over that worked similar to an ink jet before sintering the layers. The SLA version I saw worked somewhat similarly, but had some 'unique' clearing processes.</p>
582
<p>I have a website that plays mp3s in a flash player. If a user clicks 'play' the flash player automatically downloads an mp3 and starts playing it. </p> <p>Is there an easy way to track how many times a particular song clip (or any binary file) has been downloaded?</p> <hr> <blockquote> <p>Is the play link a link to the actual mp3 file or to some javascript code that pops up a player?</p> <p>If the latter, you can easily add your own logging code in there to track the number of hits to it.</p> <p>If the former, you'll need something that can track the web server log itself and make that distinction. My hosting plan comes with Webalizer, which does this nicely.</p> </blockquote> <p>It's a javascript code so that answers that. </p> <p>However, it would be nice to know how to track downloads using the other method (without switching hosts).</p>
<p>The funny thing is I wrote a php media gallery for all my musics 2 days ago. I had a similar problem. I'm using <a href="http://musicplayer.sourceforge.net/" rel="nofollow noreferrer">http://musicplayer.sourceforge.net/</a> for the player. And the playlist is built via php. All music requests go to a script called xfer.php?file=WHATEVER</p> <pre><code>$filename = base64_url_decode($_REQUEST['file']); header(&quot;Cache-Control: public&quot;); header('Content-disposition: attachment; filename='.basename($filename)); header(&quot;Content-Transfer-Encoding: binary&quot;); header('Content-Length: '. filesize($filename)); // Put either file counting code here, either a db or static files // readfile($filename); //and spit the user the file function base64_url_decode($input) { return base64_decode(strtr($input, '-_,', '+/=')); } </code></pre> <p>And when you call files use something like:</p> <pre><code>function base64_url_encode($input) { return strtr(base64_encode($input), '+/=', '-_,'); } </code></pre> <p><a href="http://us.php.net/manual/en/function.base64-encode.php" rel="nofollow noreferrer">http://us.php.net/manual/en/function.base64-encode.php</a></p> <p>If you are using some JavaScript or a flash player (JW player for example) that requires the actual link of an mp3 file or whatever, you can append the text &quot;&amp;type=.mp3&quot; so the final link becomes something like: &quot;www.example.com/xfer.php?file=34842ffjfjxfh&amp;type=.mp3&quot;. That way it looks like it ends with an mp3 extension without affecting the file link.</p>
<p>Is there a database for your music library? If there is any server code that runs when downloading the mp3 then you can add extra code there to increment the play count. You could also have javascript make a second request to increment the play count, but this could lead to people/robots falsely incrementing counts.</p> <p>I used to work for an internet-radio site and we used separate tables to track the time every song was played. Our streams were powered by a perl script running icecast, so we triggered a database request every time a new track started playing. Then to compute the play count we would run a query to count how many times a song's id was in the play log.</p>
2,261
<p>I was testing on a customer's box this afternoon which has Windows Vista (He had home, but I am testing on a Business Edition with same results).</p> <p>We make use of a .DLL that gets the Hardware ID of the computer. It's usage is very simple and the sample program I have created works. The Dll is <a href="http://www.azsdk.com/hardwareid.html" rel="nofollow noreferrer">This from AzSdk</a>. In fact, this works perfectly under Windows XP. However, for some strange reason, inside our project (way bigger), we get this exception: </p> <pre><code>Exception Type: System.DllNotFoundException Exception Message: Unable to load DLL 'HardwareID.dll': Invalid access to memory location. (Exception from HRESULT: 0x800703E6) Exception Target Site: GetHardwareID </code></pre> <p>I don't know what can be causing the problem, since I have full control over the folder. The project is a c#.net Windows Forms application and everything works fine, except the call for the external library. </p> <p>I am declaring it like this: (note: it's <em>not</em> a COM library and it doesn't need to be registered).</p> <pre><code>[DllImport("HardwareID.dll")] public static extern String GetHardwareID(bool HDD, bool NIC, bool CPU, bool BIOS, string sRegistrationCode); </code></pre> <p>And then the calling code is quite simple:</p> <pre><code>private void button1_Click(object sender, EventArgs e) { textBox1.Text = GetHardwareID(cb_HDD.Checked, cb_NIC.Checked, cb_CPU.Checked, cb_BIOS.Checked, "*Registration Code*"); } </code></pre> <p>When you create a sample application, it works, but inside my projectit doesn't. Under XP works fine. Any ideas about what should I do in Vista to make this work? As I've said, the folder and its sub-folders have Full Control for "Everybody". </p> <p><strong>UPDATE:</strong> I do not have Vista SP 1 installed. </p> <p><strong>UPDATE 2:</strong> I have installed Vista SP1 and now, with UAC disabled, not even the simple sample works!!! :( Damn Vista.</p>
<p>@<a href="https://stackoverflow.com/questions/29284/windows-vista-unable-to-load-dll-xdll-invalid-access-to-memory-location-dllnotf#29400">Martín</a></p> <p>The reason you were not getting the UAC prompt is because UAC can only change how a process is <strong>started</strong>, once the process is running it must stay at the same elevation level. The UAC will prompt will happen if:</p> <ul> <li>Vista thinks it's an installer (<a href="http://msdn.microsoft.com/en-us/library/aa905330.aspx#wvduac_topic3" rel="nofollow noreferrer">lots of rules here</a>, the simplest one is if it's called "setup.exe"), </li> <li>If it's flagged as "Run as Administrator" (you can edit this by changing the properties of the shortcut or the exe), or </li> <li>If the exe contains a manifest requesting admin privileges.</li> </ul> <p>The first two options are workarounds for 'legacy' applications that were around before UAC, the correct way to do it for new applications is to <a href="http://msdn.microsoft.com/en-us/library/bb756929.aspx" rel="nofollow noreferrer">embed a manifest resource</a> asking for the privileges that you need.</p> <p>Some program, such as <a href="http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx" rel="nofollow noreferrer">Process Explorer</a> appear to elevate a running process (when you choose "Show details for all process" in the file menu in this case) but what they really do is start a new instance, and it's that new instance that gets elevated - not the one that was originally running. This is the recommend way of doing it if only some parts of your application need elevation (e.g. a special 'admin options' dialog).</p>
<p>Have you made a support request to the vendor? Perhaps there's something about the MacBook Pro hardware that prevents the product from working.</p>
4,893
<p>When using Slic3r I noticed that <code>Slice now</code> and <code>Export G-Code</code> do different things. While <code>Slice now</code> is nice, it does not show any tool paths etc. </p> <p>Is there an actual way to generate and visualize the G-code in Slic3r without saving the exported G-Code first? When aligning seams etc., it is quite annoying to always save the file to see a difference because <code>Slice now</code> seems to make little difference.</p>
<p>Using Repetier Host V2.1.2 and slicing with Slic3r (or with CuraEngine), there is an "edit Gcode" button under the Print Preview tab. It is located at the top right of the screen. With that button you can access, examine and change the Gcode of the project you are working on.</p>
<p>After you use the Slice Now button (and the slicing progress bar shows completed), select the preview tab. To the right of the window you will see a pair of vertical sliders. Each slider changes the start and finish locations for the filament layers.</p> <p>You can slide the left one to the bottom, which will "empty" the virtual print bed. Each movement upward will display a succeeding layer, showing the placement of the filament. This ostensibly will present to you alignment information as well as unexpected holes or other failure points.</p> <p>I don't know of any slicer that lacks a preview. That doesn't mean one does not exist, but why would such a useful feature be omitted?</p>
943
<p>Say you want a simple maze on an N by M grid, with one path through, and a good number of dead ends, but that looks "right" (i.e. like someone made it by hand without too many little tiny dead ends and all that). Is there a known way to do this?</p>
<p>From <a href="http://www.astrolog.org/labyrnth/algrithm.htm" rel="noreferrer">http://www.astrolog.org/labyrnth/algrithm.htm</a></p> <blockquote> <p>Recursive backtracker: This is somewhat related to the recursive backtracker solving method described below, and requires stack up to the size of the Maze. When carving, be as greedy as possible, and always carve into an unmade section if one is next to the current cell. Each time you move to a new cell, push the former cell on the stack. If there are no unmade cells next to the current position, pop the stack to the previous position. The Maze is done when you pop everything off the stack. This algorithm results in Mazes with about as high a "river" factor as possible, with fewer but longer dead ends, and usually a very long and twisty solution. It runs quite fast, although Prim's algorithm is a bit faster. Recursive backtracking doesn't work as a wall adder, because doing so tends to result in a solution path that follows the outside edge, where the entire interior of the Maze is attached to the boundary by a single stem. </p> </blockquote> <p>They produce only 10% dead ends</p> <p><img src="https://i.stack.imgur.com/vWo6P.gif"></p> <p>is an example of a maze generated by that method.</p>
<p>Here's the DFS algorithm written as pseudocode: </p> <p>create a CellStack (LIFO) to hold a list of cell locations<br> set TotalCells = number of cells in grid<br> choose a cell at random and call it CurrentCell<br> set VisitedCells = 1 </p> <p>while VisitedCells &lt; TotalCells find all neighbors of CurrentCell with all walls intact<br> if one or more found choose one at random<br> knock down the wall between it and CurrentCell<br> push CurrentCell location on the CellStack<br> make the new cell CurrentCell<br> add 1 to VisitedCells else pop the most recent cell entry off the CellStack<br> make it CurrentCell endIf endWhile </p>
5,940
<p>I'm working on a big .NET 1.1 project, and there exists a wish to upgrade this, majorily to be able to use better tools like Visual Studio 2008, but also because of the new features and smaller amount of bugs in the .NET 2.0 framework.</p> <p>The project consist for the bigger part of VB.NET, but there are also parts in C#. It is a Windows Forms application, using various third party controls. Using .NET remoting the rich client talks to a server process which interfaces with a MSSQL 2000 database.</p> <p>What kind of issues can we expect in case we decide to perform the upgrade?</p>
<p>We're looking at doing the same migration right now Tobi. First, you can get a good idea of what to expect by making a copy of your project (or a portion of it) and give it a "dry run" through the .NET 2.0 compiler. My experience with this was that the 2.0 compiler gives more warnings about bad programming practices that the 1.1 compiler let slide. The compiler will warn you about implicit casts, "ambiguous" return paths (a code path where a function doesn't return a value), and some other minor things.</p> <p>Here's a few links that you might find helpful: <a href="http://msdn.microsoft.com/en-us/library/ms994381.aspx" rel="noreferrer">.NET Framework Compatability</a></p> <p><a href="http://go.microsoft.com/fwlink/?linkid=51223" rel="noreferrer">Word Document of Breaking changes in .NET Framework 2.0</a></p>
<p>You probably won't have any <strong>breaking</strong> issues, though you may get some deprecated method warnings. The compiler should generally tell you what the replacement is though. I know that some of the System.Configuration things were updated.</p>
8,167
<p>What is the difference between the <code>EXISTS</code> and <code>IN</code> clause in SQL?</p> <p>When should we use <code>EXISTS</code>, and when should we use <code>IN</code>?</p>
<p>The <code>exists</code> keyword can be used in that way, but really it's intended as a way to avoid counting:</p> <pre class="lang-sql prettyprint-override"><code>--this statement needs to check the entire table select count(*) from [table] where ... --this statement is true as soon as one match is found exists ( select * from [table] where ... ) </code></pre> <p>This is most useful where you have <code>if</code> conditional statements, as <code>exists</code> can be a lot quicker than <code>count</code>.</p> <p>The <code>in</code> is best used where you have a static list to pass:</p> <pre class="lang-sql prettyprint-override"><code> select * from [table] where [field] in (1, 2, 3) </code></pre> <p>When you have a table in an <code>in</code> statement it makes more sense to use a <code>join</code>, but mostly it shouldn't matter. The query optimiser should return the same plan either way. In some implementations (mostly older, such as Microsoft SQL Server 2000) <code>in</code> queries will always get a <a href="https://technet.microsoft.com/en-us/library/ms191318(v=sql.105).aspx" rel="noreferrer">nested join</a> plan, while <code>join</code> queries will use nested, <a href="https://technet.microsoft.com/en-us/library/ms190967(v=sql.105).aspx" rel="noreferrer">merge</a> or <a href="https://technet.microsoft.com/en-us/library/ms189313(v=sql.105).aspx" rel="noreferrer">hash</a> as appropriate. More modern implementations are smarter and can adjust the plan even when <code>in</code> is used.</p>
<p>If you are using the IN operator, the SQL engine will scan all records fetched from the inner query. On the other hand if we are using EXISTS, the SQL engine will stop the scanning process as soon as it found a match. </p>
4,456
<p>My current place of employment is currently in a transition, new ownership has taken over, things are finally getting standardized and proper guidelines are being enforced. </p> <p>But we are still using VSS, there really isn't any reason for using it other then that's what whats initially setup. We don't use Visual Studio, or any tool really that specifically requires it. </p> <p>What would be the absolute best argument I can bring up to help convince them that going to something like Subversion would be a much better solution, in the long run.</p>
<p>VSS totally relies on the clients to manage the database. If a client drops connection in the middle of a write over the network at just the wrong time, your file is trashed on the server. Not just the tip, but all the history. Hope you have a good backup. I've been through it. It's bad news.</p> <p>VSS usage over VPN or other remote connections is abysmal. It's using SMB to transfer the data, and you have to retrieve the file and all of its deltas just to get the tip. Nasty.</p> <p>I've seen VSS start to act up at 1GB of data. Database errors, etc. MS (somewhere in a FAQ or KB) says that 2GB is really the max safe limit. There are no good management tools (the clients run the asylum), so you don't really get any warning about this.</p> <p><em>Anything</em> with a server process to provide some level of transactions and integrity control is a superior solution.</p>
<p>Even if it ain't broke, there's a potential benefit to migrating from VSS. First and most trivially, you won't have to buy new VSS licenses. Second, there are many examples of deficiencies in the VSS product (some also acknowledged by MS). The learning curve for SVN is at least as low as for VSS, and if you have devs happier with their source control system, they're more likely to use it early and often. That will translate to lots less risk for your company, and that's a good benefit.</p>
6,636
<p>We're having problem with a huge number of legacy stored procedures at work. Do you guys recommend any tool the can help better understand those procedures? Some kind of reverse engineering that indentifies inter-procedure dependencies and/or procedure vs. tables dependencies. Can be a free or commercial tool.</p> <p>Thanks!</p>
<p>Redgate has a rather expensive product called <a href="http://www.red-gate.com/products/SQL_Dependency_Tracker/" rel="nofollow noreferrer">SQL Dependency Tracker</a> that seems to fulfill the requirements.</p>
<p>The single best tool for reverse engineering is by APEX. Its amazing. It can even trace into .NET assemblies and tell you where the procs are used. Its by far the deepest product of its kind. RedGate has great other tools but not in this case. </p>
9,533
<p>I want to allow my users to embed their own Flash animations in their posts. Usually the actual file is hosted on some free image hosting site. I wouldn't actually load the flash unless the user clicked a button to play (so that nothing auto-plays on page load). I know people can make some really annoying crap in flash, but I can't find any information about potential <em>serious</em> damage a flash app could cause to the viewer.</p> <p>Is it unsafe to embed just any flash file from the internets? If so, how can I let users embed innocent animations but still keep out the harmful apps?</p> <p>edit:</p> <p>From what I can gather, the most obvious threat is for actionscript to redirect you to a malicious site.</p> <p>Adobe <a href="http://www.adobe.com/devnet/flashplayer/articles/secure_swf_apps_04.html" rel="nofollow noreferrer">says</a> you can set <strong>allowScriptAccess=never</strong> and <strong>allowNetworking=none</strong> and the swf should have no access to anything outside of itself. <strong>Will this solve all my problems?</strong></p>
<p>Flash has some neat security measures in place. Allowing users to upload swf's to your site and embedding them is unsafe, you're basically setting yourself up for an XSS attack.</p> <p>However, allowing them to hotlink should not be a problem. The swf will be locked to the domain that is hosting it and is not allowed calling url's outside of that space. </p> <p>It will still be open to "evil links" (i'm sure theres a proper word for them), and by that I mean having regular links to yoursite.com/admin/deleteallpages.php which it tries to load "as" you. It will not however be able to use this data in any way, it'll basically be the same as a normal link, and I'd guess modern cms' are protected from that type of attacks.</p> <p>You could get the same protection by hosting your flashes on a different subdomain, since flash considers this the same as a completely different domain.</p>
<p>Yes, it's unsafe.</p> <p>There's no easy way of allowing it. You could have a domain whitelist that allowed YouTube, Hulu, etc. through, but whitelisting is inherently painstaking - you'd be constantly updating.</p>
6,561
<p>When I first started using revision control systems like <a href="http://en.wikipedia.org/wiki/Concurrent_Versions_System" rel="nofollow noreferrer">CVS</a> and <a href="http://en.wikipedia.org/wiki/Apache_Subversion" rel="nofollow noreferrer">SVN</a>, I didn't really understand the concepts of the "trunk", branching, merging and tagging. I'm now starting to understand these concepts, and really get the importance and power behind them.</p> <p>So, I'm starting to do it properly. Or so I think... This is what I understand so far: The latest release/stable version of your code should sit in /trunk/ while beta versions or bleeding edge versions sit inside the /branches/ directory as different directories for each beta release, and then merged into the trunk when you release.</p> <p>Is this too simplistic a view on things? What repository layouts do you guys recommend? If it makes a difference, I'm using Subversion.</p>
<p>See these two questions on SO for more information:</p> <ul> <li><a href="https://stackoverflow.com/questions/16142/what-does-branch-tag-and-trunk-really-mean">What does branch, tag and trunk really mean?</a></li> <li><a href="https://stackoverflow.com/questions/15621/subversion-question">Subversion question</a></li> </ul>
<p>Eric has an excellent series of articles on Source Control use and organisational best practices. <a href="http://www.ericsink.com/scm/scm_branches.html" rel="nofollow noreferrer">Chapter 7 deals with branches</a> (and yes, it recommends the /trunk/ and /branches/ directories you suggest).</p>
3,833
<p>This is about practicality. I'm hearing that people are using their BLTouch not to adjust the Z offset, but as the limit switch for the machine! Why is this so? What are the pros and cons of using a BLTouch (or any touch sensor for that matter) in lieu of a physical limit switch?</p> <p>(NB: I'm looking for objective reasons, where no other solution will do as opposed to personal preference reasons where people just like to use it).</p>
<p>Touch sensors (or inductive or capacitive sensors) are generally used to probe the bed to determine the bed shape. For metallic beds that are not perfectly straight this works excellent. But, if your bed is straight and level (e.g. when you are using a straight slate of glass), you do not need to probe the surface as it is level. Instead you can use the probe to determine the Z level. <br><br></p> <p><strong>Pros</strong> for a limit lever switch are:</p> <ul> <li>simple and cheap mechanical switch</li> <li>no firmware changes necessary</li> <li>no or few soldering</li> <li>already present on most bought printers <br><br></li> </ul> <p><strong>Cons</strong> for a limit lever switch are:</p> <ul> <li>needs fine adjustments counter part to work optimally</li> <li>something can get in between the lever and counter part</li> <li>it doesn't look cool <br><br></li> </ul> <p><strong>Pros</strong> for a more sophisticated sensor:</p> <ul> <li>it can help with adhesion if the bed surface is deformed or dented</li> <li>it looks cool</li> <li>everybody is using it so it must be good <br><br></li> </ul> <p><strong>Cons</strong> for a more sophisticated sensor:</p> <ul> <li>expensive and complicated sensor</li> <li>requires firmware changes (e.g. sensor offset value)</li> <li>requires soldering, or connecting more cables</li> <li>inductive and capacitive sensor work usually better at a higher voltage</li> <li>higher chance of malfunctioning (more parts and electronics)</li> </ul>
<p>One other way a bed sensor may be preferable over a common limit switch: it automatically adjusts when you change out the build surface.</p> <p>Most glass build surfaces are anywhere from three to five millimeters thick, while the surface they replace (texture coated or uncoated fiberglass/resin, magnetic sheet, etc.) are around one to 1.5 mm thick -- that's a enough change in build surface height to be near the limits of the bed adjustment on my Ender 3, for instance.</p> <p>There are ways to work around this, for instance with spacers that clip onto the bottom of the X gantry to trigger the Z-stop at a higher position -- but if you forget to install the spacer on a build surface change, you may end up scratching the coating on your glass bed (probably a bad thing) by dragging the nozzle across it, as well as potentially damaging the nozzle (cheap, but takes time to replace once you figure out why your prints are suddenly failing). If you're using a bed sensor in place of a limit switch, this oversight can't happen, because the Z homing will automatically detect where to stop regardless what you've mounted on the bed.</p>
1,487
<p>I have the following tables, the <code>groups</code> table which contains hierarchically ordered groups and <code>group_member</code> which stores which groups a user belongs to. </p> <pre><code>groups --------- id parent_id name group_member --------- id group_id user_id ID PARENT_ID NAME --------------------------- 1 NULL Cerebra 2 1 CATS 3 2 CATS 2.0 4 1 Cerepedia 5 4 Cerepedia 2.0 6 1 CMS ID GROUP_ID USER_ID --------------------------- 1 1 3 2 1 4 3 1 5 4 2 7 5 2 6 6 4 6 7 5 12 8 4 9 9 1 10 </code></pre> <p>I want to retrieve the visible groups for a given user. That it is to say groups a user belongs to and children of these groups. For example, with the above data: </p> <pre><code>USER VISIBLE_GROUPS 9 4, 5 3 1,2,4,5,6 12 5 </code></pre> <p>I am getting these values using recursion and several database queries. But I would like to know if it is possible to do this with a single SQL query to improve my app performance. I am using MySQL. </p>
<p>Two things come to mind:</p> <p><strong>1 -</strong> You can repeatedly outer-join the table to itself to recursively walk up your tree, as in:</p> <pre><code>SELECT * FROM MY_GROUPS MG1 ,MY_GROUPS MG2 ,MY_GROUPS MG3 ,MY_GROUPS MG4 ,MY_GROUPS MG5 ,MY_GROUP_MEMBERS MGM WHERE MG1.PARENT_ID = MG2.UNIQID (+) AND MG1.UNIQID = MGM.GROUP_ID (+) AND MG2.PARENT_ID = MG3.UNIQID (+) AND MG3.PARENT_ID = MG4.UNIQID (+) AND MG4.PARENT_ID = MG5.UNIQID (+) AND MGM.USER_ID = 9 </code></pre> <p>That's gonna give you results like this:</p> <pre><code>UNIQID PARENT_ID NAME UNIQID_1 PARENT_ID_1 NAME_1 UNIQID_2 PARENT_ID_2 NAME_2 UNIQID_3 PARENT_ID_3 NAME_3 UNIQID_4 PARENT_ID_4 NAME_4 UNIQID_5 GROUP_ID USER_ID 4 2 Cerepedia 2 1 CATS 1 null Cerebra null null null null null null 8 4 9 </code></pre> <p>The limit here is that you must add a new join for each "level" you want to walk up the tree. If your tree has less than, say, 20 levels, then you could probably get away with it by creating a view that showed 20 levels from every user.</p> <p><strong>2 -</strong> The only other approach that I know of is to create a recursive database function, and call that from code. You'll still have some lookup overhead that way (i.e., your # of queries will still be equal to the # of levels you are walking on the tree), but overall it should be faster since it's all taking place within the database.</p> <p>I'm not sure about MySql, but in Oracle, such a function would be similar to this one (you'll have to change the table and field names; I'm just copying something I did in the past):</p> <pre><code>CREATE OR REPLACE FUNCTION GoUpLevel(WO_ID INTEGER, UPLEVEL INTEGER) RETURN INTEGER IS BEGIN DECLARE iResult INTEGER; iParent INTEGER; BEGIN IF UPLEVEL &lt;= 0 THEN iResult := WO_ID; ELSE SELECT PARENT_ID INTO iParent FROM WOTREE WHERE ID = WO_ID; iResult := GoUpLevel(iParent,UPLEVEL-1); --recursive END; RETURN iResult; EXCEPTION WHEN NO_DATA_FOUND THEN RETURN NULL; END; END GoUpLevel; / </code></pre>
<p><del>There's no way to do this in the SQL standard, but you can usually find vendor-specific extensions, e.g., <code>CONNECT BY</code> in Oracle.</del></p> <p>UPDATE: As the comments point out, this was added in SQL 99.</p>
8,417
<p>This is something I've pseudo-solved many times and have never quite found a solution for.</p> <p>The problem is to come up with a way to generate <code>N</code> colors, that are as distinguishable as possible where <code>N</code> is a parameter.</p>
<p>My first thought on this is "how to generate N vectors in a space that maximize distance from each other."</p> <p>You can see that the RGB (or any other scale you use that forms a basis in color space) are just vectors. Take a look at <a href="http://mathworld.wolfram.com/topics/RandomPointPicking.html" rel="noreferrer">Random Point Picking</a>. Once you have a set of vectors that are maximized apart, you can save them in a hash table or something for later, and just perform random rotations on them to get all the colors you desire that are maximally apart from each other!</p> <p>Thinking about this problem more, it would be better to map the colors in a linear manner, possibly (0,0,0) → (255,255,255) lexicographically, and then distribute them evenly.</p> <p>I really don't know how well this will work, but it should since, let us say:</p> <pre><code>n = 10 </code></pre> <p>we know we have 16777216 colors (256^3).</p> <p>We can use <a href="https://stackoverflow.com/questions/561/using-combinations-of-sets-as-test-data#794">Buckles Algorithm 515</a> to find the lexicographically indexed color.<img src="https://i.stack.imgur.com/gEuCs.gif" alt="\frac {\binom {256^3} {3}} {n} * i">. You'll probably have to edit the algorithm to avoid overflow and probably add some minor speed improvements.</p>
<p>I've read somewhere the human eye can't distinguish between less than 4 values apart. so This is something to keep in mind. The following algorithm does not compensate for this.</p> <p>I'm not sure this is exactly what you want, but this is one way to randomly generate non-repeating color values:</p> <p>(beware, inconsistent pseudo-code ahead)</p> <pre><code>//colors entered as 0-255 [R, G, B] colors = []; //holds final colors to be used rand = new Random(); //assumes n is less than 16,777,216 randomGen(int n){ while (len(colors) &lt; n){ //generate a random number between 0,255 for each color newRed = rand.next(256); newGreen = rand.next(256); newBlue = rand.next(256); temp = [newRed, newGreen, newBlue]; //only adds new colors to the array if temp not in colors { colors.append(temp); } } } </code></pre> <p>One way you could optimize this for better visibility would be to compare the distance between each new color and all the colors in the array:</p> <pre><code>for item in color{ itemSq = (item[0]^2 + item[1]^2 + item[2]^2])^(.5); tempSq = (temp[0]^2 + temp[1]^2 + temp[2]^2])^(.5); dist = itemSq - tempSq; dist = abs(dist); } //NUMBER can be your chosen distance apart. if dist &lt; NUMBER and temp not in colors { colors.append(temp); } </code></pre> <p>But this approach would significantly slow down your algorithm.</p> <p>Another way would be to scrap the randomness and systematically go through every 4 values and add a color to an array in the above example.</p>
2,268
<p>Looking for a good approach to keep track of a Breadth-First traversal between two nodes, without knowing anything about the graph. Versus Depth-First (where you can throw away the path if it doesn't pan out) you may have quite a few "open" possibilities during the traversal.</p>
<p>The naive approach is to build a tree with the source node as the root and all its connections as its children. Depending on the amount of space you have, you might need to eliminate cycles as you go. You can do that with a bitmap where each bit corresponds to a distinct node in the graph. When you reach the target node, you can follow the parent links back to the root and that is your path. Since you are going breadth first, you are assured that it is a shortest path even if you don't eliminate cycles.</p>
<p>If you are using .NET 3.5 consider using the <a href="http://msdn.microsoft.com/en-us/library/bb359438.aspx" rel="nofollow noreferrer">Hashset</a> to prevent duplicate nodes from being expanded, this happens when there is cycles in your graph. If you have any knowledge about the contents of the graph consider implementing an <a href="http://en.wikipedia.org/wiki/A*_search_algorithm" rel="nofollow noreferrer">A* search</a> to reduce the number of nodes that are expanded. Good luck and I hope it works out for you. </p> <p>If you are still a fan of treeware there are many excellent books on the topic of graphs and graph search such as Artificial Intelligence: A Modern Approach by Peter Norvig and Stuart Russell.</p> <p>The links in my response appear to have a bug they are Hashset: <a href="http://msdn.com/en-us/library/bb359438.aspx" rel="nofollow noreferrer">http://msdn.com/en-us/library/bb359438.aspx</a> and A* search: <a href="http://en.wikipedia.org/wiki/A*_search_algorithm" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/A*_search_algorithm</a></p>
8,170
<p>I've been seeing the 330 m and 110 m length estimates for 1.75 and 3.0 mm spools (of PLA, presumably). But a moment's thought staring at that will raise an obvious question.</p> <p>Using πr², we get the area of the filament in square millimeters (rounding to two decimal points)</p> <p>For 1.75 it's 2.41 mm²</p> <p>For 3.00 it's 7.07 mm²</p> <p>Then taking the ratio and multiplying:</p> <p>(2.41/7.07) * 330 m = 112 m which is close enough to 110 m.</p> <p>BUT as all makers of filament and makers of extruders know, 3.00 mm is just a rounding off of the real dimension, which is 2.85 mm. Now do that:</p> <p>For 2.85 it's 6.38 mm²</p> <p>and:</p> <p>(2.41/6.38) * 330 m = 125 m which is at least 120 m.</p> <p>So, whoever calculated the approximation of 110 m did the calculation based on the rounded rather than actual dimension. What am I missing here?</p> <p>My point is not that the 330 and 110 would be inaccurate given the dimensions of 1.75 and 3.00. Rather, my point is that the 3.00 mm diameter is not what is really so; it's actually 2.85 mm and therefore the answer is longer than 110 m.</p>
<p>Let's go about this scientific:</p> <p>$A_r=\pi{r}^{2}=\pi{\frac{d}{2}}^{2}$</p> <p>As a result the crossections are $A_{3}=7.06858\text{mm}^2=0.0707\text{cm}^2$, $A_{2.85}=6.3794\text{mm}^2=0.0638\text{cm}^2$ and $A_{1.75}=2.40528\text{mm}^2=0.024\text{cm}^2$.</p> <p>Volume of a cylinder is $V_{A_d,l}=\times {A_d} {l}$. Turned around to get a length from Volume and Area we get $l=\frac {V_m}{A_d}$, but what is V?</p> <p>We know the density of comercial PLA is about $\rho=1.25 \frac{\text g}{\text{cm}^3}$, and we know $m=\times V \rho$. So: $V_m=\frac{m}{\rho}=\frac{1000}{1.25}\text{cm}^3=800\text{cm}^3$.</p> <p>Taking this Volume and using the $l=\frac {V_m}{A_d}$ we get:</p> <p>$l_{d=1.75}=33333.33\frac{\text{cm}}{\text{kg}}=333.33\frac{\text{m}}{\text{kg}}$</p> <p>$l_{d=2.85}=12539.18\frac{\text{cm}}{\text{kg}}=125.39\frac{\text{m}}{\text{kg}}$</p> <p>$l_{d=3}=11315.41\frac{\text{cm}}{\text{kg}}=113.15\frac{\text{m}}{\text{kg}}$</p> <p>If the filament is more on the dense side $(\rho&gt;1.25\frac{\text g}{\text{cm}^3})$, then it will have a smaller volume and thus be shorter than this estimate.</p> <p>To show this better, a graph: This is the length of a filament spool in dependancy of the density. The values were calculated for the usual diameters with their closest neighbors rounded to 0.1 as absolute diameters and run over a broad range of densities commonly used in plastics - 0.7 g/cm³ to 2 g/cm³.</p> <p><a href="https://i.stack.imgur.com/Jydly.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Jydly.png" alt="length of filament depending on diameter and density"></a></p>
<p>Let's go about this scientific:</p> <p>$A_r=\pi{r}^{2}=\pi{\frac{d}{2}}^{2}$</p> <p>As a result the crossections are $A_{3}=7.06858\text{mm}^2=0.0707\text{cm}^2$, $A_{2.85}=6.3794\text{mm}^2=0.0638\text{cm}^2$ and $A_{1.75}=2.40528\text{mm}^2=0.024\text{cm}^2$.</p> <p>Volume of a cylinder is $V_{A_d,l}=\times {A_d} {l}$. Turned around to get a length from Volume and Area we get $l=\frac {V_m}{A_d}$, but what is V?</p> <p>We know the density of comercial PLA is about $\rho=1.25 \frac{\text g}{\text{cm}^3}$, and we know $m=\times V \rho$. So: $V_m=\frac{m}{\rho}=\frac{1000}{1.25}\text{cm}^3=800\text{cm}^3$.</p> <p>Taking this Volume and using the $l=\frac {V_m}{A_d}$ we get:</p> <p>$l_{d=1.75}=33333.33\frac{\text{cm}}{\text{kg}}=333.33\frac{\text{m}}{\text{kg}}$</p> <p>$l_{d=2.85}=12539.18\frac{\text{cm}}{\text{kg}}=125.39\frac{\text{m}}{\text{kg}}$</p> <p>$l_{d=3}=11315.41\frac{\text{cm}}{\text{kg}}=113.15\frac{\text{m}}{\text{kg}}$</p> <p>If the filament is more on the dense side $(\rho&gt;1.25\frac{\text g}{\text{cm}^3})$, then it will have a smaller volume and thus be shorter than this estimate.</p> <p>To show this better, a graph: This is the length of a filament spool in dependancy of the density. The values were calculated for the usual diameters with their closest neighbors rounded to 0.1 as absolute diameters and run over a broad range of densities commonly used in plastics - 0.7 g/cm³ to 2 g/cm³.</p> <p><a href="https://i.stack.imgur.com/Jydly.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Jydly.png" alt="length of filament depending on diameter and density"></a></p>
986
<p>How would you determine the column name (e.g. "AQ" or "BH") of the nth column in Excel?</p> <p>Edit: A language-agnostic algorithm to determine this is the main goal here.</p>
<p>I once wrote this function to perform that exact task:</p> <pre><code>public static string Column(int column) { column--; if (column &gt;= 0 &amp;&amp; column &lt; 26) return ((char)('A' + column)).ToString(); else if (column &gt; 25) return Column(column / 26) + Column(column % 26 + 1); else throw new Exception("Invalid Column #" + (column + 1).ToString()); } </code></pre>
<p>I currently use this, but I have a feeling that it can be optimized.</p> <pre><code>private String GetNthExcelColName(int n) { String firstLetter = ""; //if number is under 26, it has a single letter name // otherwise, it is 'A' for 27-52, 'B' for 53-78, etc if(n &gt; 26) { //the Converts to double and back to int are just so Floor() can be used Double value = Convert.ToDouble((n-1) / 26); int firstLetterVal = Convert.ToInt32(Math.Floor(value))-1; firstLetter = Convert.ToChar(firstLetterValue + 65).ToString(); } //second letter repeats int secondLetterValue = (n-1) % 26; String secondLetter = Convert.ToChar(secondLetterValue+65).ToString(); return firstLetter + secondLetter; } </code></pre>
4,275
<p>At what level of complexity is it mandatory to switch to an existing framework for web development?</p> <p>What measurement of complexity is practical for web development? Code length? Feature list? Database Size?</p>
<p>If you work on several different sites then by using a common framework across all of them you can spend time working on the code rather than trying to remember what is located where and why.</p> <p>I'd always use a framework of some sort, even if it's your own, as the uniformity will help you structure your project. Unless it's a one page static HTML project.</p> <p>There is no mandatory limit however.</p>
<p>All factors matter. You should measure how much time you can save using 3rd party framework and compare it to the risks of using other's code</p>
9,385
<p>I have a solution with multiple project. I am trying to optimize AssemblyInfo.cs files by linking one solution wide assembly info file. What are the best practices for doing this? Which attributes should be in solution wide file and which are project/assembly specific?</p> <hr> <p><em>Edit: If you are interested there is a follow up question <a href="https://stackoverflow.com/questions/64602/what-are-differences-between-assemblyversion-assemblyfileversion-and-assemblyin">What are differences between AssemblyVersion, AssemblyFileVersion and AssemblyInformationalVersion?</a></em></p>
<p>We're using a global file called GlobalAssemblyInfo.cs and a local one called AssemblyInfo.cs. The global file contains the following attributes:</p> <pre><code> [assembly: AssemblyProduct("Your Product Name")] [assembly: AssemblyCompany("Your Company")] [assembly: AssemblyCopyright("Copyright © 2008 ...")] [assembly: AssemblyTrademark("Your Trademark - if applicable")] #if DEBUG [assembly: AssemblyConfiguration("Debug")] #else [assembly: AssemblyConfiguration("Release")] #endif [assembly: AssemblyVersion("This is set by build process")] [assembly: AssemblyFileVersion("This is set by build process")] </code></pre> <p>The local AssemblyInfo.cs contains the following attributes:</p> <pre><code> [assembly: AssemblyTitle("Your assembly title")] [assembly: AssemblyDescription("Your assembly description")] [assembly: AssemblyCulture("The culture - if not neutral")] [assembly: ComVisible(true/false)] // unique id per assembly [assembly: Guid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")] </code></pre> <p>You can add the GlobalAssemblyInfo.cs using the following procedure:</p> <ul> <li>Select <strong>Add/Existing Item...</strong> in the context menu of the project</li> <li>Select GlobalAssemblyInfo.cs</li> <li>Expand the Add-Button by clicking on that little down-arrow on the right hand</li> <li>Select "Add As Link" in the buttons drop down list</li> </ul>
<p>Using a single AseemblyInfo.cs file for multiple projects is not recommended. The AssemblyInfo file includes information that might be relevant only for that specific assembly. The two most obvious pieces of information are the <code>AssemblyTitle</code> and <code>AssemblyVersion</code>.</p> <p>A better solution might be to use <code>targets</code> file, which are handled by the MSBuild, in order to "inject" assembly attributes to more than one project.</p>
8,774
<p>Scenario: You have an ASP.Net webpage that should display the next image in a series of images. If 1.jpg is currently loaded, the refresh should load 2.jpg.<br> Assuming I would use this code, where do you get the current images name.</p> <pre><code>string currImage = MainPic.ImageUrl.Replace(".jpg", ""); currImage = currImage.Replace("~/Images/", ""); int num = (Convert.ToInt32(currImage) + 1) % 3; MainPic.ImageUrl = "~/Images/" + num.ToString() + ".jpg"; </code></pre> <p>The problem with the above code is that the webpage used is the default site with the image set to 1.jpg, so the loaded image is always 2.jpg.<br> So in the process of loading the page, is it possible to pull the last image used from the pages properties?</p>
<pre><code>int num = 1; if(Session["ImageNumber"] != null) { num = Convert.ToInt32(Session["ImageNumber"]) + 1; } Session["ImageNumber"] = num; </code></pre>
<p>You'll have to hide the last value in a HiddenField or ViewState or somewhere like that...</p>
6,655
<p>Ive been experimenting will multiple color filament but the colors a more or less blended. Is there are filament that goes from one color directly to another without having transition color ex. red to green immediately.</p> <p>I've been tinkering with <a href="https://www.filamenthub.com" rel="nofollow noreferrer">Filament Hub Filament</a> and it is very good (some of the best I've ever used) however I've had to essentially melt strands of one filament to the next and this is unsustainable.</p> <p>Anyone know any filaments or methods to have an immediate color change</p>
<p>It takes at least a few cm of extrusion to purge the old color before switching to a new one due to mixing in the melt zone, and possibly much more depending on the particular pigments. If the old color is something bright like red and the new one is white or something close, it can even take many tens of cm before you get a clean new color.</p> <p>Multi-color extrusion setups either use separate hotends per color or fancy retraction setups where each color can be retracted separately, along with purge towers. You cannot get a clean color switch in the print just by having one in the input filament, and this is probably why all the mixed color filament that's sold is blended - so customers don't get disappointed when it doesn't work like you expect.</p>
<p>When calling for a <strong>manual</strong> color change, Marlin is set up to allow to extrude extra filament. This is to ensure that the new filament is in the hotend, but it also allows to &quot;purge&quot; the old color from the hotend by extruding till no mixed color comes out anymore.</p>
1,917
<p>As someone who hasn't used either technology on real-world projects I wonder if anyone knows how these two complement each other and how much their functionalities overlap?</p>
<p>LINQ to SQL forces you to use the table-per-class pattern. The benefits of using this pattern are that it's quick and easy to implement and it takes very little effort to get your domain running based on an existing database structure. For simple applications, this is perfectly acceptable (and oftentimes even preferable), but for more complex applications devs will often suggest using a <a href="http://en.wikipedia.org/wiki/Domain_driven_design" rel="noreferrer">domain driven design</a> pattern instead (which is what NHibernate facilitates).</p> <p>The problem with the table-per-class pattern is that your database structure has a direct influence over your domain design. For instance, let's say you have a Customers table with the following columns to hold a customer's primary address information:</p> <ul> <li>StreetAddress</li> <li>City</li> <li>State</li> <li>Zip</li> </ul> <p>Now, let's say you want to add columns for the customer's mailing address as well so you add in the following columns to the Customers table:</p> <ul> <li>MailingStreetAddress</li> <li>MailingCity</li> <li>MailingState</li> <li>MailingZip</li> </ul> <p>Using LINQ to SQL, the Customer object in your domain would now have properties for each of these eight columns. But if you were following a domain driven design pattern, you would probably have created an Address class and had your Customer class hold two Address properties, one for the mailing address and one for their current address.</p> <p>That's a simple example, but it demonstrates how the table-per-class pattern can lead to a somewhat smelly domain. In the end, it's up to you. Again, for simple apps that just need basic CRUD (create, read, update, delete) functionality, LINQ to SQL is ideal because of simplicity. But personally I like using NHibernate because it facilitates a cleaner domain.</p> <p>Edit: @lomaxx - Yes, the example I used was simplistic and could have been optimized to work well with LINQ to SQL. I wanted to keep it as basic as possible to drive home the point. The point remains though that there are several scenarios where having your database structure determine your domain structure would be a bad idea, or at least lead to suboptimal OO design.</p>
<p>Or you could use the Castle ActiveRecords project. I've been using that for a short time to ramp up some new code for a legacy project. It uses NHibernate and works on the active record pattern (surprising given its name I know). I haven't tried, but I assume that once you've used it, if you feel the need to drop to NHibernate support directly, it wouldn't be too much to do so for part or all of your project. </p>
4,661
<p>We have a few very large Excel workbooks (dozens of tabs, over a MB each, very complex calculations) with many dozens, perhaps hundreds of formulas that use the dreaded INDIRECT function. These formulas are spread out throughout the workbook, and target several tables of data to look-up for values.</p> <p>Now I need to move the ranges of data that are targeted by these formulas to a different location in the same workbook.</p> <p>(The reason is not particularly relevant, but interesting on its own. We need to run these things in Excel Calculation Services and the latency hit of loading each of the rather large tables one at a time proved to be unacceptably high. We are moving the tables in a contiguous range so we can load them all in one shot.)</p> <p><strong>Is there any way to locate all the INDIRECT formulas that currently refer to the tables we want to move?</strong></p> <p>I don't need to do this on-line. I'll happily take something that takes 4 hours to run as long as it is reliable.</p> <p>Be aware that the .Precedent, .Dependent, etc methods only track direct formulas.</p> <p>(Also, rewriting the spreadsheets in <em>whatever</em> is not an option for us).</p> <p>Thanks!</p>
<p>You could iterate over the entire Workbook using vba (i've included the code from @PabloG and @euro-micelli ):</p> <pre><code>Sub iterateOverWorkbook() For Each i In ThisWorkbook.Worksheets Set rRng = i.UsedRange For Each j In rRng If (Not IsEmpty(j)) Then If (j.HasFormula) Then If InStr(oCell.Formula, "INDIRECT") Then j.Value = Replace(j.Formula, "INDIRECT(D4)", "INDIRECT(C4)") End If End If End If Next j Next i End Sub </code></pre> <p>This example substitues every occurrence of "indirect(D4)" with "indirect(C4)". You can easily swap the replace-function with something more sophisticated, if you have more complicated indirect-functions. Performance is not that bad, even for bigger Workbooks.</p>
<p>You can use something like this in VBA:</p> <pre><code>Sub ListIndirectRef() Dim rRng As Range Dim oSh As Worksheet Dim oCell As Range For Each oSh In ThisWorkbook.Worksheets Set rRng = oSh.UsedRange For Each oCell In rRng If InStr(oCell.Formula, "INDIRECT") Then Debug.Print oCell.Address, oCell.Formula End If Next Next End Sub </code></pre> <p>Instead of Debug.Print you can add code to suit your taste</p>
5,474
<p>I want to print a lemon squeezer and I would prefer to use PET-G. I don't know if it is safe to use, because lemons contain lots of citric acid. Does it dissolve PETG? I haven't found an answer anywhere on the Internet. There are generally few things that dissolve PETG. These are aromatic compounds like toluene, phenol etc.</p> <p>I know my model will be food safe, as PETG is food safe, I'm using one without a dye and my nozzle is made out of steel, not brass. I think bacteria growth inside little gaps/between layers is impossible, because the citric acid is quite strong and will kill nearly all of the germs.</p>
<p>According to <a href="http://kmac-plastics.net/data/chemical/petg-chemical.htm#.XV7Vokd7m4o" rel="nofollow noreferrer">kmac-plastics</a>, PETG is stable at temperatures below 50°C specifically for citric acid (also acetic acid) and others on the linked list. It is also safe with diesel oil and many alcohols. The list is illuminating with respect to the variation of tested compounds.</p>
<p>The PETG is food safe (plastic water bottles are made of them), however the colour additives may not be a) stable, or b) food safe. If you are going to make a lemon squeezer then I would suggest that you use a virgin material that is just pet-g with no additives.</p> <p>However, you could only ever use it one. Any food particles that get stuck in between the fine layers of the printed part, will cause bacterial growth. If the walls are porous then the juice can get inside of the part and create a breathing ground.</p>
1,444
<p>I have a 3D printer at home, the Colido Compact, and for some reason when I 3D print big flat surfaces a really weird thing happens. I'm using some PLA from Colido too I think</p> <p><a href="https://i.stack.imgur.com/QOMPF.jpg" rel="nofollow noreferrer" title="Weeeird surface artefacts"><img src="https://i.stack.imgur.com/QOMPF.jpg" alt="Weeeird surface artefacts" title="Weeeird surface artefacts"></a></p> <p>It almost seems as if the bottom layer does perfectly but when it starts printing out the top surface this happens, because the one on the bottom left is in two parts because the upper part is the bottom one and that one is perfectly flat, then I took them apart and the weird thing just stayed with the top part... and also on the weird warps there are bits of brown goo or something? I don't know it looks as if the filament was burned... It only appears on pretty big surfaces because smaller ones don't seem to have the problem.</p> <p>Anyone knows what is happening?</p>
<p>The oozing is due to hot-end getting hot before the bed leveling procedure: if you move the hot-end warm up command <strong>after</strong> the <code>G29</code> line you avoid that oozing</p> <pre><code>; Ender 3 Custom Start G-code M104 S{material_print_temperature_layer_0} ; Set Extruder temperature M140 S{material_bed_temperature_layer_0} ; Set Heat Bed temperature G28 ; Home all axes G29 ; BLTOUCH Mesh Generation M190 S{material_bed_temperature_layer_0} ; Wait for Heat Bed temperature M109 S{material_print_temperature_layer_0} ; Wait for Extruder temperature G1 F1800 E-3 ; Retract filament 3 mm to prevent oozing G92 E0 ; Reset Extruder G1 Z5.0 F3000 ; Move Z Axis up little to prevent scratching of Heat Bed G1 X0.1 Y20 Z0.3 F5000.0 ; Move to start position G1 X0.1 Y200.0 Z0.3 F1500.0 E15 ; Draw the first line G1 X0.4 Y200.0 Z0.3 F5000.0 ; Move to side a little G1 X0.4 Y20 Z0.3 F1500.0 E30 ; Draw the second line G92 E0 ; Reset Extruder G1 Z5.0 F3000 ; Move Z Axis up little to prevent scratching of Heat Bed </code></pre> <p>The above code will activate the heating elements but starts homing and leveling procedure without waiting for the elements to get up to temperature. Only after the bed leveling is finished the printer will pause and wait for the heating elements reach the desired temperature.</p> <p>This will prevent oozing on a cold start, but you will still be affected if you start a print right after another print, when the hot-end is still close to melting temperature.</p> <p>If you prefer to avoid that condition you might want to also move the <code>M104</code> and <code>M140</code> commands after the <code>G29</code> bed leveling command.</p>
<p>The best solution would be to heat the bed, but not the nozzle at startup. If you level with a cold bed, your ABL mesh is going to be off, since the aluminum heated bed plate expands considerably once the heat is applied. </p> <p>You could also issue a retract command before leveling, and then add a counteracting filament feed command after ABL is complete. I have no idea how that code would look though. Just my 2 cents.</p>
1,142
<p>I just got <a href="http://smile.amazon.com/Stronghero3D-Printing-Filaments-Accuracy-0-05mm/dp/B07HDZ9K22/" rel="noreferrer">my first spool of PETG</a> and tried to calibrate an Ultimaker Cura profile for it on my Ender 3 today with limited success. </p> <p>I've had severe issues with the filament not sticking to the build surface, instead balling up around the edges of the nozzle tip. (<em>rather like <a href="https://3dprinting.stackexchange.com/questions/722/petg-collecting-on-the-extruder">this post</a></em>) Sometimes it sticks alright, but that happens properly > 50 % of the time. I've never seen this behavior with my PLA materials.</p> <p>So far, I've only been trying to print <a href="https://www.thingiverse.com/thing:37869" rel="noreferrer">this calibration part</a>.</p> <p><strong>Relevant Profile Params:</strong> (<em>let me know if I need to post more, I think these are the relevant ones</em>)</p> <ul> <li>Layer Height: 0.2 mm</li> <li>Temp <ul> <li>Nozzle: 240 &deg;C</li> <li>Bed: 60 &deg;C</li> </ul></li> <li>Print Speed: 60 mm/s (<em>more specific params left to auto calculation</em>)</li> <li>Travel Speed: 300 mm/s (<em>max</em>)</li> <li>Cooling fan <ul> <li>Initial: 0 %</li> <li>Fan Speed: 100 %</li> </ul></li> <li>Retraction <ul> <li>Distance: 5 mm</li> <li>Speed: 50 mm/s</li> </ul></li> <li>Skirt min length: 250 mm</li> </ul> <p>I was initially going by advice from <a href="https://www.youtube.com/watch?v=8_adY2K-YIc" rel="noreferrer">Thomas Sanlanderer's video on PETG</a>, starting with 230 &deg;C/70 &deg;C, but when that really didn't work, I then tried the advice of a Reddit user (<em>can't relocate thread</em>) that said to try a lower bed temp. I then experimented with different bed temps in the 50's to mixed avail. Most other threads are talking about PETG + glass, which seems to work well with a PVA glue stick surface finish.</p> <p>I'm getting a glass build surface soon (<em>as soon as GearBest can ship it from across the pond</em>), and I hear that will help, but in the meantime, I want to find a way to make it work with the fake Buildtak. What can I do to try to make this work better? My thinking is that the issue is with the bed config (<em>temp, surface, etc.</em>) and not with the nozzle temp, but I could be wrong.</p>
<p>I have printed kilometers of PETG and found the sweet-spot for my brand to be 240 &deg;C for the hotend and 70 &deg;C for the build plate (for my Ultimaker 3 that is, the extruder temp is 5 &deg;C higher for my home build HyperCube Evolution). The reason for the 70 &deg;C is that the glass temperature of PETG is around 70 &deg;C. The PETG is flexible at that temperature such that there are no stresses because of shrinkage causing the PETG to keep attached to the heat bed surface (aluminium, glass, Buildtak, etc.). A little PVA based glue (stick) or spray (hair or specific print sprays) can even further improve the adhesion. A slow first layer also helps adhering better.</p> <p>Note that the hotend temperature should be calibrated to the speed you are printing. If you print faster, a higher hotend tempearture is required. To determine the sweet spot for your filament you can print typical calibration towers that can be found on e.g. <a href="https://www.thingiverse.com/search?q=temperature%20tower&amp;dwh=125bba06b7b88c7" rel="nofollow noreferrer">Thingiverse</a>. Note that you need to manually change the G-code file after slicing of the tower or use plugins of your slicer to change the temperature at a certain level.</p> <p>Furthermore, PETG does not like to be cooled by the print fan, so keep cooling fan rpm low to prevent layers not to bond (else you get a sort of string cheese print).</p> <hr> <p>Edit:</p> <p>I use parametric stair case style calibration prints that include the slicer print settings that are to determine the best settings for temperature, print cooling, layer size and print speed.</p> <p><a href="https://i.stack.imgur.com/ERWy6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ERWy6.png" alt="Heat tower front view"></a><a href="https://i.stack.imgur.com/wYWOC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wYWOC.png" alt="Heat tower backside view"></a></p>
<p>Thanks to the magic of r/3Dprinting, I have a solution. <a href="https://www.reddit.com/r/3Dprinting/comments/9ltni1/petg_filament_doesnt_stick_reliably_to_ender_3/e79nq20" rel="nofollow noreferrer">u/Lhelge helped me out with a tip</a>:</p> <blockquote> <p>I would suggest a higher bed temperature. I print PETG at 80°-95° for the first layer depending on which printer. Then I go down a bit for the second layer.</p> </blockquote> <p>I then started out by trying a 250 °C/80 °C temperature config and sure enough, it worked great. I managed to tune my profile down to 250 °C/70 °C and up from 50 mm/s to 70 mm/s.</p>
1,056
<p>What is the difference between a <a href="http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.group.aspx" rel="nofollow noreferrer">Group</a> and a <a href="http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.match.aspx" rel="nofollow noreferrer">Match</a> in .NET's RegEx?</p>
<p>A <a href="http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.match.aspx" rel="noreferrer">Match</a> is an object that indicates a particular regular expression matched (a portion of) the target text. A <a href="http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.group.aspx" rel="noreferrer">Group</a> indicates a portion of a match, if the original regular expression contained group markers (basically a pattern in parentheses). For example, with the following code:</p> <pre><code>string text = "One car red car blue car"; string pat = @"(\w+)\s+(car)"; Match m = r.Match(text); </code></pre> <p><code>m</code> would be match object that contains two groups - group 1, from <code>(\w+)</code>, and that captured "One", and group 2 (from <code>(car)</code>) that matched, well, "car".</p>
<p>A Match is a part of a string that matches the regular expression, and there could therefore be multiple matches within a string.</p> <p>Inside a Match you can define groups, either anonymous or named, to make it easier to split up a match. A simple example is to create a regex to search for URLs, and then use groups inside to find the protocol (http), domain (www.web.com), path (/lol/cats.html) and arguments and what not. </p> <pre><code>// Example I made up on the spot, probably doesn't work very well "(?&lt;protocol&gt;\w+)://(?&lt;domain&gt;[^/]+)(?&lt;path&gt;/[^?])" </code></pre> <p>A single pattern can be found multiple times inside a string, as I said, so if you use Regex.Matches(string text) you will get back multiple matches, each consisting of zero, one or more groups.</p> <p>Those named groups can be found by either indexing by number, or with a string. The example above can be used like this:</p> <pre><code>Match match = pattern.Match(urls); if (!match.Success) continue; string protocol = match.Groups["protocol"].Value; string domain = match.Groups[1].Value; </code></pre> <p>To make things even more interesting, one group could be matched multiple times, but then I recommend start reading the <a href="http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.group.captures.aspx" rel="nofollow noreferrer">documentation</a>.</p> <p>You can also use groups to generate back references, and to do partial search and replace, but read more of that on <a href="http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.matchcollection.aspx" rel="nofollow noreferrer">MSDN</a>.</p>
4,875