instruction
stringlengths
27
22.5k
chosen
stringlengths
27
28.2k
rejected
stringlengths
19
24.9k
__index_level_0__
int64
0
10k
<p>The print is a collapsible sword I'm using as a test. Everything seems fine on the outside, but inside it seems the segment parts of the sword inside the hilt are fusing together at the seam lines causing them to stick together.</p> <p><strong>Model</strong>: <a href="https://thangs.com/designer/3dprintingworld/3d-model/Collapsing%20Katana-22696" rel="nofollow noreferrer">https://thangs.com/designer/3dprintingworld/3d-model/Collapsing%20Katana-22696</a></p> <p><strong>Finished Print</strong> (looks fine) <a href="https://i.stack.imgur.com/DZa3o.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DZa3o.jpg" alt="enter image description here" /></a></p> <p><strong>Concentric blade pieces</strong> (fuse marks that I sheared off and broke to get out) <a href="https://i.stack.imgur.com/peViY.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/peViY.jpg" alt="enter image description here" /></a></p> <p><strong>Seams on exterior of hilt look great</strong> <a href="https://i.stack.imgur.com/2dxXC.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2dxXC.jpg" alt="enter image description here" /></a></p> <p><strong>Print settings/info</strong></p> <p><strong>Printer</strong>: Prusa MK3S+</p> <p><strong>Slicer</strong>: PrusaSlicer 2.5.0a3</p> <p><strong>Settings preset</strong>: 0.15 mm QUALITY</p> <p><strong>Filament</strong>: Prusa PLA</p> <p><strong>Nozzle temp</strong>: 205 °C (default is 215 °C, but lower eases stringing and has never been a problem for many past prints)</p> <p><strong>Nozzle size</strong>: 0.4 mm</p> <p><strong>Full config</strong>: <a href="https://pastebin.com/ECa6KkYK" rel="nofollow noreferrer">https://pastebin.com/ECa6KkYK</a></p>
<p>After some trial and error I found that the issue was stringing due to excess moisture in the filament from being stored outside of a sealed low-humidity container for long periods.</p> <p>After placing it in a heated dehydrator for 2 days, my next print had low stringing and did not bond interlaced parts together significantly.</p>
<p>You did well to decrease the temperature. You could go even lower to 200°C As you noticed, You really have a little bit of stringing between the elements. That's what binds the parts together. Many times when you print only a single part this will be no problem. With many nested parts, you retraction really has to be set to optimal values.</p> <p>Try increasing the retraction distance in the slicer.</p>
2,178
<p>I have created a database model in Visio Professional (2003). I know that the Enterprise version has the ability to create a DB in SQL Server based on the data in Visio. I do not have the option to install Enterprise. Aside from going through the entire thing one table and relationship at a time and creating the whole database from scratch, by hand, can anyone recommend any tool/utility/method for converting the visio database model into a SQL Script that can be used to create a new DB in SQL Server?</p>
<p>I have not done this, but here it goes.</p> <ol> <li>Convert Visio file to Visio XML format.</li> <li>Use <a href="http://dia-installer.de/index_en.html" rel="nofollow noreferrer">Dia for Windows</a> and <a href="http://www.redferni.uklinux.net/dia/vdx/" rel="nofollow noreferrer">Dia VDX plug-in</a> to convert Visio XML into Dia.</li> <li>Use <a href="http://tedia2sql.tigris.org/" rel="nofollow noreferrer">tedia2sql</a> to generate SQL.</li> </ol>
<p>If you can somehow obtain the type library from the enterprise version you can use VBA to get out the definitions. Secondhand enterprise architect versions of VS 2002 and VS 2003 can be brought from ebay for a few hundred dollars.</p>
5,847
<p>I added a custom install action to my installer to add one of my installation directories to the System PATH environment variable. After I run the installer, the PATH variable reflects the changes (when I access it through the Control Panel::System applet), but when I start a new command shell, the PATH variable does not reflect the changes. Is there something I'm failing to do, that causes this?</p>
<p>I think this depends on how you are starting the new Command shell. For example, when you change the PATH environment variable under System properties, the change isn't reflected until you open a new Command prompt. I think when you launch a new "cmd" process (from the Run dialog for example), you get a fresh copy of all environment variables, but if you launch the command prompt a different way then you do not.</p> <p>For something done thru a script like that, you may need to restart before you notice the change.</p>
<p>How are you adding the environment variable?</p> <p>Without using any external tools, you can <a href="http://www.windowsnetworking.com/kbase/WindowsTips/WindowsNT/AdminTips/Miscellaneous/SetEnvManipulateNTEnvironmentalVariables.html" rel="nofollow noreferrer">add it to the registry</a>. Then, your test of opening a new command window will reflect your change.</p>
6,152
<p>What are some of the ways? What frameworks can you use?</p>
<p>Here's a project which does this: <a href="http://tsqlunit.sourceforge.net/" rel="nofollow noreferrer">http://tsqlunit.sourceforge.net/</a></p> <p>Also, Visual Studio Team System for DBA has built-in support for unit testing of Databases.</p>
<p><a href="http://tst.codeplex.com/" rel="nofollow noreferrer">T.S.T. the T-SQL Test Tool</a></p> <blockquote> <p>TST is a tool that simplifies the task of writing and running test automation for code written in T-SQL. At the heart of the TST tool is the TST database. This database contains a series of stored procedures that are exposed as a test API. Part of this API is similar with those found in Unit Testing libraries familiar to programmers in C# or Java.</p> </blockquote>
7,702
<p>I'm in the process of building a 3D printer and have all the stepper motors wired up and the controller connected to the computer running pronterface.</p> <p>I can move each axis and also send g-code to the printer.</p> <p>Now <strong>how can I define the current position to be the 0/0/0 position?</strong> I'd like to move the printer into a position where I think should be the zero position and define it as such in pronterface somehow.</p>
<blockquote> <p>G92 X0 Y0 Z0</p> </blockquote> <p>tells the printer that the current position is (0,0,0).</p>
<p>There's a handy list of G0-codes at <a href="http://reprap.org/wiki/G-code" rel="nofollow">http://reprap.org/wiki/G-code</a> -- though the list is too big to be convenient for finding a code if you're not already sure what it's called... :(</p>
158
<p>I would like to write small console based applications on Windows Mobile. What console applications might I use?</p>
<p>it may be useful to know that when you use printf from a standard windows mobile application, the output will end up in the kernel log of the device.</p> <p>This has several drawbacks: * Access to the kernellog is manufacturer+device dependent. * The length of the string you can print is limited to 255 characters.</p> <p>if you run your tool in the visualstudio environment in the debugger, you will get the output of the printf's in your log window.</p>
<p>There is no command prompt style console on Windows Mobile. If you're really after a command prompt, check out www.pocketdos.com for a high level of dos application compatibility. If you're more interested in writing small applications for Windows Mobile, C# or VB.Net are your best choices. On small mobile devices like this, command prompts are significantly harder for users to interact with compared to GUI based applications.</p>
9,962
<p>I am trying out FirePHP.</p> <p>I installed it and restarted Firefox, enabled Firebug for my localhost, moved the demo <code>oo.php</code> file that comes with the download into an IIS virtual directory, changed the include path, removed the <code>apache_request_headers()</code> call since I am running IIS, and the only output I see is</p> <blockquote> <p>Notice: Undefined offset: 1 in C:\Documents and Settings\georgem\My Documents\projects\auctronic\FirePHPCore\FirePHP.class.php on line 167 <br/> Hello World</p> </blockquote> <p>Nothing appears in the Firebug console. </p> <p>Am I missing something?</p> <p><strong>EDIT:</strong> Noticed it said that output buffering has to be enabled so I added a call to <a href="http://php.net/manual/en/function.ob-start.php" rel="nofollow noreferrer"><code>ob_start()</code></a> at the top of the file...same results.</p>
<p>I believe FirePHP required you install a Firefox extension (in addition to Firebug) that watches for the HTTP headers and puts them in the console. </p> <p>If that isn't the problem then I'd recommend grabbing a copy of <a href="http://www.charlesproxy.com/" rel="noreferrer">Charles</a>. It will let you view the headers of the HTTP response. The FirePHP output should be visible there. If it's not then the problem is in your server set up.</p>
<p>I had the same issue and it turned out that the 'Net' tab of firebug wasn't enabled caused firephp to not show anything in the console. Enabled Net tab and voila!</p>
9,437
<p>So I'm embarking on an <code>ASP.NET MVC</code> project and while the experience has been a good one overall, I'm not quite as pleased with the spaghetti mess that my controllers have become. I've looked around online (CodeCampServer, etc...) and they all seem to suffer the same issue wherein controller methods violate SRP (single responsibility principle) pretty consistently - such as a controller method that simply renders the view if the request is a <code>GET</code> but updates the <code>model</code> if it's a <code>POST</code>. Now I've got controller methods responsible for multiple logical routes throughout the application - say it checks for which <code>button</code> was clicked on the form and acts accordingly. I could redirect each button click to a different form action using JavaScript, but something doesn't feel right there either... The other big issue is the proliferation of magic <code>strings - ViewData["foo"] = blah;</code> Long story short, how do you guys <code>structure</code> your <code>controller</code> logic? One giant model object per view? Lots of little <code>controller methods</code> and <code>JavaScript</code> is the router? My goal is maintainable code - as features get piled on I'm starting to slide down that slippery slope...</p>
<p>ASP.NET Preview 5 (available on <a href="http://www.codeplex.com/aspnet" rel="noreferrer">CodePlex</a>) has an answer for this: the [AcceptVerbs] attribute. Phil Haack has a <a href="http://haacked.com/archive/2008/08/29/how-a-method-becomes-an-action.aspx" rel="noreferrer">blog post</a> discussion how it's used.</p> <p>As for the view data magic key question, it's an interesting problem. If you think of a view as being a bunch of semi-independent components (especially in light of the new partial view support), then making a strongly-typed model becomes less ideal, as the several pieces of the view should be relatively independent of one another.</p>
<p>How are different people handling this issue? I know that i just spent a couple hours reviewing the jumble inside of the model folder. I'm finding creating folders is helpful in reducing the visual clutter, using matching namespaces helps alot too.</p> <p>But my controllers are monoliths at the moment. the trouble is that i've been focused on learning to this point in the project (still lots to sort out as well).</p> <p>I'm getting a good handle on MVC now, so it is time to review the complexity and consider modifying the controllers up into better named and cleaner functions.</p> <p>Are other people breaking their controllers up into sub controllers? (If there is such a thing)</p>
5,689
<p>I'd like to customize and modify some parts on Thingiverse, beyond just simple scaling for 3D printing.</p> <p>I've been looking for some tools that convert the STL files into something that is easily edited, but so far all that I've found are really buggy and crash frequently as soon as one loads a reasonably complex model.</p> <p>Are there any free open source software tools that people can recommend that handle STL importing and editing? If not FOSS, what about just "free or nearly free for hobbyists, ed, non-commercial?</p>
<p>If you want to do basic edits to an STL, a program such as <a href="http://www.meshmixer.com/" rel="noreferrer">MeshMixer</a> might be right for your. It offers the ability to combine and subtract models, add custom supports, and similar, in a fairly straight forward manner.</p> <p>An alternative that allows your to do complex editing of STLs would be <a href="http://www.autodesk.com/products/fusion-360/overview" rel="noreferrer">Autodesk Fusion 360</a>. Here you can import STLs into meshes, which you then may convert into solids for further editing. It is more work to use, but a very flexible solution; you can i.e choose to only convert certain faces to solid, or use the mesh as a reference point for other designs. </p> <p>As far as I know, neither of these are FOSS (free and open source), but both are free for non-commercial use.</p>
<p>If you want a WYSIWYG-style editor and are not content with OpenSCAD, I found 123D Design (Autodesk, definitively not FOSS but free for hobbyists) to have (on a Mac) a compromise between power and ease of use that most appealed to me.</p> <p>If you insist on FOSS probably Blender comes closest, but I found it to be too idiosyncratic in interface and tools to be usable. </p>
177
<p>Why can I not see an <strong>option</strong> for copying database objects when I <code>right click &gt; tasks</code> on my database? </p>
<p>MS Sql Server Express doesn't come with SSIS which is what you will need to import/export objects out of your database.</p> <p>You can also manually script this process. One way is to use BCP (<a href="http://msdn.microsoft.com/en-us/library/ms162802.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ms162802.aspx</a>)</p>
<p>Have a look at Red Gate <a href="http://www.red-gate.com/products/SQL_Compare/index.htm" rel="nofollow noreferrer">SQL Compare</a> and <a href="http://www.red-gate.com/products/SQL_Data_Compare/index.htm" rel="nofollow noreferrer">SQL Data Compare</a>.</p> <p>You can download the trial and use them to build a script that will dump your objects to a .sql file.</p>
9,668
<p>I'm trying out the following query:</p> <pre><code>SELECT A,B,C FROM table WHERE field LIKE 'query%' UNION SELECT A,B,C FROM table WHERE field LIKE '%query' UNION SELECT A,B,C FROM table WHERE field LIKE '%query%' GROUP BY B ORDER BY B ASC LIMIT 5 </code></pre> <p>That's three queries stuck together, kinda sorta. However, the result set that comes back reflects results from query #3 before the results from query #1 which is undesired.</p> <p>Is there any way to prioritize these so that results come as all for query #1, then all for query #2 then all for query #3? I don't want to do this in PHP just yet (not to mention having to control for results that showed up in the first query not to show in the second and so forth).</p>
<p>Maybe you should try including a fourth column, stating the table it came from, and then order and group by it:</p> <pre><code>SELECT A,B,C, "query 1" as origin FROM table WHERE field LIKE 'query%' UNION SELECT A,B,C, "query 2" as origin FROM table WHERE field LIKE '%query' UNION SELECT A,B,C, "query 3" as origin FROM table WHERE field LIKE '%query%' GROUP BY origin, B ORDER BY origin, B ASC LIMIT 5 </code></pre>
<p>If there isn't a sort that makes sense to order them you desire, don't union the results together - just return 3 separate recordsets, and deal with them accordingly in your data tier.</p>
2,588
<p>Using TortoiseSVN against VisualSVN I delete a source file that I should not have deleted. Now this isn't a train smash because I can get the file back from the daily backup. However I would like to undelete it from SVN (VisualSVN) so that I can get the history back. However I can't work out how to do that.</p> <p>Anybody know how to undelete a file from VisualSVN either using the VisualSVN interface or the latest version of TortoiseSVN?</p>
<p>What you have to do is the following:</p> <ol> <li>Right click on the folder where you think it is.</li> <li>Choose Show Log under TortioseSVN</li> <li>Find the checkin that the file was deleted in</li> <li>Go down the list and find the file</li> <li>Select Revert changes for this version to undelete.</li> </ol>
<p>Did you only delete it locally, or did you commit the deletion? In the latter case, try checking out the previous revision.</p>
3,477
<p>For a school project, my teacher gave me a brand new Longer 3D printer to create parts with. After one good job, the printer cannot get past the raft creation without air printing. The thickness of the printed filament tapers down until no filament is coming out. I do not believe there is a jam in the hot end because if I remove the filament and cut off about 4 inches, the printer extrudes as normal.</p> <p>I am using 1.75 mm PLA on a Longer 3D LK4.</p> <p>When the problem occurs, the extruder continues as normal but prints out very little filament. The extruder drive gear also ticks backward as if it cannot supply enough force to move the filament forward.</p> <p>I have tried decreasing the speed, increasing the temperature, turning off retractions, but none of those options seemed to have any effect on the problem.</p> <p>If videos or pictures could be helpful let me know what to include.</p> <p>My working idea of what's wrong is that heat creep is causing the filament inside of the heat sink to soften causing the filament to thicken and Jam. I could be wrong.</p> <p><a href="https://i.stack.imgur.com/T7Rxz.jpg" rel="nofollow noreferrer" title="Failed Raft"><img src="https://i.stack.imgur.com/T7Rxz.jpg" alt="Failed Raft" title="Failed Raft" /></a></p> <p>Figure one highlighting how the filament thins over the course of the raft creation until no more filament is extruded.</p> <p><a href="https://i.stack.imgur.com/7UhUH.jpg" rel="nofollow noreferrer" title="Thickened Filament"><img src="https://i.stack.imgur.com/7UhUH.jpg" alt="Thickened Filament" title="Thickened Filament" /></a></p> <p>Figure two showing how random parts of the filament is thicker than others. The thickness is noticeable and once I cut this section off, filament flows freely through the Bowden tube without friction. With this section, the filament is difficult to remove and requires more force.</p> <p>I have tried:</p> <ul> <li>increasing the interface thickness to 0.4 from 0.27 mm and from 0.4 to 1.0 mm</li> <li>increasing the print speed from 50 mm/s to 90 mm/s allowing the printer to cool off. decreasing the temperature to 190 °C</li> </ul> <p>During the print, I have noticed that the heat sink is hot to the touch during the raft creation but cools off once the fan starts spinning.</p> <p>The fan does not spin at all during the creation of the raft. But spins at full speed once the actual print has begun. Longer does not have a setting inside their software to change this.</p> <p>I have gotten a few really small prints to work with print surfaces smaller than 2 cm wide</p> <p>The prints themselves turn out great if they get past the raft stage (only for small prints). This additionally leads me to believe that heat creep is the problem and that the fan not being on is the cause.</p> <p>Let me know if you have any ideas.</p>
<p>If you use a build surface such as PEI, acetone frosts your surface, leaving a white film appearance. If you have no additional surface on a glass or metal bed, it is incomplete cleaning. If incomplete cleaning, you could try isopropyl alcohol (IPA) immediately after acetone, followed immediately by a water based cleaner or DI/distilled water. (IPA dissolves acetone and water dissolves IPA. Once the film dries the next step may not work.)</p> <p>You can't clean off a frosted surface. The black surface of the hot bed in images of the CR-10S Pro appears to indicate that the steel bed has a build surface with a plastic material such as PEI. Reviews of the build surface being difficult to remove prints also implies a plastic build surface on the steel. Thus, it appears that the white film after cleaning with acetone is actually a frosted surface.</p> <p>If you use an Elmer's washable glue stick or one with PWP, it will form a barrier between your print and the build surface, that not only will protect your build surface, but will make it easier to clean your build surface with IPA or water based cleaners.</p>
<p>If you use a build surface such as PEI, acetone frosts your surface, leaving a white film appearance. If you have no additional surface on a glass or metal bed, it is incomplete cleaning. If incomplete cleaning, you could try isopropyl alcohol (IPA) immediately after acetone, followed immediately by a water based cleaner or DI/distilled water. (IPA dissolves acetone and water dissolves IPA. Once the film dries the next step may not work.)</p> <p>You can't clean off a frosted surface. The black surface of the hot bed in images of the CR-10S Pro appears to indicate that the steel bed has a build surface with a plastic material such as PEI. Reviews of the build surface being difficult to remove prints also implies a plastic build surface on the steel. Thus, it appears that the white film after cleaning with acetone is actually a frosted surface.</p> <p>If you use an Elmer's washable glue stick or one with PWP, it will form a barrier between your print and the build surface, that not only will protect your build surface, but will make it easier to clean your build surface with IPA or water based cleaners.</p>
1,871
<p>I have a Java application which I want to shutdown 'nicely' when the user selects Start->Shutdown. I've tried using JVM shutdown listeners via Runtime.addShutdownHook(...) but this doesn't work as I can't use any UI elements from it.</p> <p>I've also tried using the exit handler on my main application UI window but it has no way to pause or halt shutdown as far as I can tell. How can I handle shutdown nicely?</p>
<p>You can make shortcut to:</p> <pre><code>msiexec /uninstall [path to msi or product code] </code></pre>
<p>Visual Studio 2013 allows you to create an Uninstall shortcut in the shortcut design page if you use the Installshield Add-on.</p>
8,695
<p>How many rows should be in the (main) buffer of a virtual Listview control?</p> <p>I am witting an application in pure 'c' to the Win32 API. There is an ODBC connection to a database which will retrieve the items (actually rows). </p> <p>The MSDN sample code implies a fixed size buffer of 30 for the end cache (Which would almost certainly not be optimal). I think the end cache and the main cache should be the same size.</p> <p>My thinking is that the buffer should be more than the maximum number of items that could be displayed by the list view at one time. I guess this could be re-calculated each time the Listivew was resized?</p> <p>Or, is it just better to go with a large fixed value. If so what is that value?</p>
<p>Use the ListView_ApproximateViewRect (or the LVM_APPROXIMATEVIEWRECT message) to get the view rect height.</p> <p>Use the ListView_GetItemRect (or the LVM_GETITEMRECT message) to get the height of an item.</p> <p>Divide the view rect height by the height of an item to get the number of items that can fit in your view. Do this calculation on each size event.</p> <p>Then create your buffer accordingly. </p>
<p>@Brian R. Bondy Thanks for the explicit help for how to do get the number of items. In fact I was all ready working my way to understanding that it could be done (for list or report view) with ListView_GetCountPerPage, and I would use you way to get it for for the others, though I don't need the ListView_ApproximateViewRect since I will all ready know the new size of the ListView.</p> <p>@Lars Truijens I am already using the LVN_ODCACHEHINT and had though about using that to set the buffer size, however I need to read to the end of the SQL data to find the last item to get the number of rows returned from ODBC. Since that would be the best time to fill the 'end cache' I think I have to set up the number of items (and therefore fill the buffer) before we get a call to LVN_ODCACHEHIN.</p> <p>I guess my real question is one of optimization for which I think Brian hinted at the answer. The amount of overhead in trashing your buffer and reallocating memory is smaller than the overhead of going out to the network and doing an ODBC read, some make the buffer fairly small and change it often rather.</p> <p>Is this right?</p> <p>I have done a little more playing around, and it seems that think that LVN_ODCACHEHINT generally fills the main buffer correctly, and only misses if a row (in report mode) is partially visible.</p> <p>So I think the answer for the size of the cache is: The total number of displayed items, plus one row of displayed items (since in the icons views you have multiple items per row).</p> <p>You would then re-read the cache with each WM_SIZE and LVN_ODCACHEHINT if either had a different begin and end item number.</p>
6,940
<p>I have a Prusa i3 that homes properly when you use the menu. After adjusting the bed and homing several times, it keeps the head at a reliable distance. However, when I try to print from an SD card, the printer buries the hot end in the heat bed.</p> <p>What needs to be adjusted to fix this issue?</p> <p>G-code from one of the 2 files</p> <pre><code>M190 S50.000000 M109 S200.000000 ;Sliced at: Mon 13-06-2016 15:39:25 ;Basic settings: Layer height: 0.2 Walls: 1.2 Fill: 20 ;Print time: 3 hours 47 minutes ;Filament used: 11.435m 34.0g ;Filament cost: None ;M190 S50 ;Uncomment to add your own bed temperature line ;M109 S200 ;Uncomment to add your own temperature line G21 ;metric values G90 ;absolute positioning M82 ;set extruder to absolute mode M107 ;start with the fan off G28 X0 Y0 ;move X/Y to min endstops G28 Z0 ;move Z to min endstops G1 Z15.0 F3000 ;move the platform down 15mm G92 E0 ;zero the extruded length G1 F200 E3 ;extrude 3mm of feed stock G92 E0 ;zero the extruded length again G1 F3000 ;Put printing message on LCD screen M117 Printing... ;Layer count: 446 ;LAYER:0 M107 ;LAYER:1 M106 S127 G1 F2400 E-4.50000 G0 F3000 X81.474 Y58.603 Z0.300 ;TYPE:WALL-INNER G1 F2400 E0.00000 G1 F2220 X83.063 Y56.456 E0.06663 G1 X84.277 Y55.080 E0.11240 G1 X84.836 Y54.444 E0.13353 G1 X85.799 Y53.476 E0.16759 G1 X86.755 Y52.587 E0.20015 G1 X87.179 Y52.244 E0.21376 G1 X88.836 Y50.911 E0.26680 G1 X89.285 Y50.610 E0.28029 </code></pre>
<p>The correlation between the endstop switch -- or sensor -- and the surface of the bed is not known <em>a priori</em> . In your case, there are two possibilities. I'd say the more likely is that your g-code generator is not setting the Z-height offset from the bed correctly. The other is that your bed is tilted, so proper Z-home at one corner does not match the entire bed.</p> <p>Try this: first manually move the extruder head to all four corners and adjust the bed screws until the separation is identical at all times. Then let your gcode start up -- and don't worry if the extruder depresses the bed during homing, as that doesn't matter. See where the extruder is once the print starts. Adjust the endstop switch up or down to compensate until the print head <strong>when printing</strong> is just off the surface and the first layer adheres well. </p> <p>If all that doesn't work, then you may have the wrong printer profile settings in your slicing softwqre. </p>
<p>I had the same issue: Z-axis correctly homing manually but not when printing.</p> <p>What worked for me is disabling the following line in the Marlin configuration file:</p> <pre><code>#define Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN </code></pre>
523
<p>Why don't 3D printer heads use ceramic inner walls? PTFE tubes melt with high enough temperatures and all metal ends risk jamming as heat makes its way up the head.</p>
<p>It <em>can</em> be done cheaply, as two different users have proven, see </p> <ul> <li><a href="https://reprap.org/forum/read.php?1,538786" rel="nofollow noreferrer">A practical 10 Cents Ceramic tube hotend</a>, and;</li> <li><a href="https://reprap.org/forum/read.php?70,172916" rel="nofollow noreferrer">Hotend with ceramic parts</a>. </li> </ul> <p>However, as Paulster2 states in his answer, there are some technical issues with using it, which make it rather problematic. Apparently, in comparison with PTFE, the thermal conductivity of the ceramic in spark plugs is too high, to use (according to <code>nophead</code> - a user on the reprap forums), and there are friction/clogging issues, unless the inner diameter is very well polished.</p> <hr> <h3>Synopsis of reference</h3> <p>The RepRap user, <code>hp_</code>, encountered the issues above when attempting a design - from <a href="https://3dobjectifying.blogspot.com/2012/12/ceramic-hotend-part-1.html" rel="nofollow noreferrer">Ceramic Hotend - Part 1</a></p> <blockquote> <p><strong>Research</strong></p> <p>As far as I know there are no ceramic hotends out there, I know nophead has tried some spark-plugs for nozzle holders but found them not suitable(thermal conductivity is pretty high). I wanted to give it a go, confident enough (I hoped), that it would work :)</p> <p>So in my case, a hotend exists out of 2 main parts, a nozzle holder and a nozzle.</p> <ul> <li><p>The nozzle is the easy part it would stay brass.</p></li> <li><p>The nozzle holder is the interesting part, here is what I've come-up with</p></li> </ul> <p>total length should be in the range of 35-40mm, see my first sketch below:</p> <p><a href="https://i.stack.imgur.com/bWtva.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bWtva.png" alt="enter image description here"></a></p> <p>here are many types of ceramic out there, ie. 95% AI2O3, 99% AI2O3, Zirconia (see material properties sheet Link)</p> <p>95% AI2O3 is easy to buy but after a few tests the conclusion was its to brittle for my taste, second material to try is Zirconia. </p> <p>I've found a few Chinese ceramic manufactures. Only draw back I had to order 10 pieces for the first batch.. on something that has never been tested, well I'd give it a shot.... and ordered the parts.</p> </blockquote> <p>but the clogging issue mentioned above was encountered:</p> <blockquote> <p>...after the first layer, it just stopped extruding.. ugh!!! what could be wrong????</p> <p>Possible root causes - Friction coefficient? Meaning after awhile the friction between PLA and the Ceramic became so high it would just jam the nozzle holder.</p> <ul> <li><p>Stickiness? Could it be that after awhile PLA would just stick to the Ceramic and would jam because of this?</p></li> <li><p>PLA thermal expansion( nozzle holder barrel is to small?) so the inner diameter of this nozzle holder is 3.2mm, could it be that the 3.0mm filament would expand so much because of the heat, that it would start to jam the nozzle holder?</p></li> <li><p>Connection between nozzle and nozzle holder is insufficient cause the Jam??</p></li> </ul> </blockquote> <p>The user was forced to return to using PTFE.</p> <p>From <a href="https://3dobjectifying.blogspot.com/2013/03/ceramic-hotend-part-2.html" rel="nofollow noreferrer">Ceramic hotend part-2</a>, after some rework done by the Chinese manufacturer, the new hotends worked correctly:</p> <blockquote> <p>Awhile ago i stared working on the ceramic hotend and found out the first version wouldn't work for 3.0mm fillament,</p> <p>after some discussion with my chinese counterpart :) i got a new version of the ceramic piece.</p> <p>They polished the inside very deep and precise. and i gave it another go.</p> </blockquote> <p>and </p> <blockquote> <p>some more tinkering with the hotend and a new nozzle design, with a smaller Inner diameter, and its longer </p> </blockquote> <p>Apart from that the details are a little sparse.</p> <hr> <h3>Additional information</h3> <p>From <a href="https://reprap.org/forum/read.php?1,295259" rel="nofollow noreferrer">J-head with ceramic body instead of PEEK</a>, specifically <a href="https://reprap.org/forum/read.php?1,295259,301258#msg-301258" rel="nofollow noreferrer">this post</a>:</p> <blockquote> <blockquote> <p>Just to be clear, it's Ceramic Zirconium.</p> <p>My concern was that Zirconium becomes brittle when it is exposed to heat for consecutive long periods of time. I would stay with PEEK.</p> </blockquote> <p>MgO or Yttria stabilized grades of Zirconium are very stable.</p> <p>Pure ZrO2 is known to crack, so additives are used to stabilize it.</p> <p><strong>Key Properties of Zirconium Oxide</strong></p> <ul> <li><em>Use temperatures up to 2400°C</em></li> <li>High density</li> <li>Low thermal conductivity (20% that of alumina)</li> <li>Chemical inertness</li> <li>Resistance to molten metals</li> <li>Ionic electrical conduction</li> <li>Wear resistance</li> <li><em>High fracture toughness</em></li> <li>High hardness</li> </ul> <p><strong>Typical Uses of ZrO2</strong></p> <ul> <li>Precision ball valve balls and seats</li> <li>High density ball and pebble mill grinding media</li> <li>Rollers and guides for metal tube forming</li> <li>Thread and wire guides</li> <li><em>Hot metal extrusion dies</em></li> <li>Deep well down-hole valves and seats -Powder compacting dies</li> <li>Marine pump seals and shaft guides</li> <li>Oxygen sensors</li> <li>High temperature induction furnace susceptors</li> <li>Fuel cell membranes</li> <li><em>Electric furnace heaters over 2000°C in oxidizing atmospheres</em></li> </ul> <p><strong>Zirconium oxide</strong></p> <p>Zirconium oxide is used due to its polymorphism. It exists in three phases: monoclinic, tetragonal, and cubic. Cooling to the monoclinic phase after sintering causes a large volume change, which often causes stress fractures in pure zirconia. <em>Additives such as magnesium, calcium and yttrium are utilized in the manufacture of the knife material to stabilize the high-temperature phases and minimize this volume change</em>. The highest strength and toughness is produced by the addition of 3 mol% yttrium oxide yielding partially stabilized zirconia. This material consists of a mixture of tetragonal and cubic phases with a bending strength of nearly 1200 MPa. Small cracks allow phase transformations to occur, which essentially close the cracks and prevent catastrophic failure, resulting in a relatively tough ceramic material, sometimes known as TTZ (transformation toughened zirconia). </p> <p>Zirconium dioxide is one of the most studied ceramic materials. <em>Pure ZrO2</em> has a monoclinic crystal structure at room temperature and transitions to tetragonal and cubic at increasing temperatures. The volume expansion caused by the cubic to tetragonal to monoclinic transformation induces very large stresses, and will cause pure ZrO2 to crack upon cooling from high temperatures. Several different oxides are added to zirconia to stabilize the tetragonal and/or cubic phases: magnesium oxide (MgO), yttrium oxide, (Y2O3), calcium oxide (CaO), and cerium(III) oxide (Ce2O3), amongst others.</p> <p>In the late 1980s, ceramic engineers learned to stabilize the tetragonal form at room temperature by adding small amounts (3–8 mass%) of calcium and later yttrium or cerium. Although stabilized at room temperature, the tetragonal form is “metastable,” meaning that trapped energy exists within the material to drive it back to the monoclinic state. The highly localized stress ahead of a propagating crack is sufficient to trigger grains of ceramic to transform in the vicinity of that crack tip. In this case, the 4.4% volume increase becomes beneficial, essentially squeezing the crack closed (i.e., transformation decreases the local stress intensity).</p> </blockquote> <p>and the <a href="https://reprap.org/forum/read.php?1,295259,301259#msg-301259" rel="nofollow noreferrer">following post</a></p> <blockquote> <p><strong>Thermal conductivity:</strong></p> <ul> <li>Diamond thermal conductivity: 1000 W/(m·K).</li> <li>Copper thermal conductivity: 385 to 401 W/(m·K).</li> <li>Aluminum: 205 W/(m·K).</li> <li><p>Stainless steel 16 W/(m·K).</p></li> <li><p>Granite: 1.7 to 4 W/(m·K).</p></li> <li>Zirconia has a typical thermal conductivity of 1.7 to 2.2 W/(m·K).</li> <li>Porcelain has a typical thermal conductivity of 1.5 to 5 W/(m·K).</li> <li>Glass thermal conductivity: 1.05 W/(m·K).</li> </ul> </blockquote> <h3>Rulon</h3> <p>As an aside, again from <a href="https://reprap.org/forum/read.php?1,295259" rel="nofollow noreferrer">J-head with ceramic body instead of PEEK</a>, specifically <a href="https://reprap.org/forum/read.php?1,295259,301193#msg-301193" rel="nofollow noreferrer">this post</a>:</p> <blockquote> <p>Rulon was one material we used. I think it is a glass filled ptfe. The mechanical strength is far better than solid ptfe and it is easy to machine. There are many grades but Rulon AR for example will withstand 288 deg C.</p> </blockquote> <p>but there are inconsistencies in quality</p> <blockquote> <p>Rulon i looked at a while ago, there are plenty of options with it, however the cost of some of these materials can be incredibly high, and in some cases availability is a serious problem, and the difference country to country is borderline criminal in some cases</p> </blockquote>
<p>Because PTFE doesn't transmit heat very well? The whole idea when using a PTFE tube (and this is just my understanding ... which could be wrong), is for the tubing not to transmit heat, therefore allowing the filament to pass through it without melting or at the very least, collecting a lot of heat along the way (which helps prevent jams). PTFE does a pretty good job of standing up to heat while accomplishing the task at hand. Ceramic does an <em>excellent</em> job of standing up to heat. The problem is, it will pass the heat along to the filament, most likely melting it, thus causing it to deform and jam before it gets to the hot end. This would then become a maintenance nightmare.</p>
1,454
<p>can anyone explain in the simplest terms please what is the difference between a point cloud and a voxel mesh?</p>
<p>A point cloud is often derived by sampling. Each point represents an observation. Sometimes, a point cloud is turned into a surface by fitting triangles to the points in the form of an STL file.</p> <p>A raster is a 2D grid of pixels. It divides the area of an image into constant-sized little squares. Each of these squares has a value.</p> <p>A 3D raster is made of voxels. It divides 3-space into constant-sized little cubes. Each of these cubes has a value.</p> <p>Pixels and voxels are rendering techniques. A point cloud is a sampling technique.</p> <p>The Wikipedia article, <a href="https://en.wikipedia.org/wiki/Voxel" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Voxel</a>, is helpful.</p> <p>In a real system the pixels may not be square or the voxels not strictly cubic, but in every system I've worked with, they do form a regular tiling of the plane for pixels, and fill 3d space for voxels.</p>
<p>I believe a point cloud is just a collection of points, while voxels - "3D pixels" - define location and a cube area. They seem to be pretty equivalent mathematically.</p>
678
<p>How can I use XPath to select an XML-node based on its content? </p> <p>If I e.g. have the following xml and I want to select the &lt;author&gt;-node that contains Ritchie to get the author's full name:</p> <pre><code>&lt;books&gt; &lt;book isbn='0131103628'&gt; &lt;title&gt;The C Programming Language&lt;/title&gt; &lt;authors&gt; &lt;author&gt;Ritchie, Dennis M.&lt;/author&gt; &lt;author&gt;Kernighan, Brian W.&lt;/author&gt; &lt;/authors&gt; &lt;/book&gt; &lt;book isbn='1590593898'&gt; &lt;title&gt;Joel on Software&lt;/title&gt; &lt;authors&gt; &lt;author&gt;Spolsky, Joel&lt;/author&gt; &lt;/authors&gt; &lt;/book&gt; &lt;/books&gt; </code></pre>
<pre><code>/books/book/authors/author[contains(., 'Ritchie')] </code></pre> <p>or</p> <pre><code>//author[contains(., 'Ritchie')] </code></pre>
<p>The XPath for this is: </p> <pre><code>/books/book/authors/author[contains(., 'Ritchie')] </code></pre> <p>In C# the following code would return "Ritchie, Dennis M.":</p> <pre><code>xmlDoc.SelectSingleNode("/books/book/authors/author[contains(., 'Ritchie')]").InnerText; </code></pre>
4,986
<p>Can anyone recommend a good repository viewer for Git, similar to gitk, that works on Mac OS X Leopard? (I'm not saying gitk doesn't work)</p> <p>Of course I would like a native Mac application, but as I haven't found any, what are the best options to gitk?</p> <p>I know about gitview, but I'm looking forward to evaluate as many alternatives as possible.</p> <p><a href="http://sourceforge.net/projects/gitview" rel="noreferrer">http://sourceforge.net/projects/gitview</a></p>
<p>There's also <a href="http://www.gitx.org" rel="noreferrer">gitx</a>, it's progressing well and under active development (multiple commits per day).</p>
<p>You should checkout Sprout (formerly GitMac). <a href="http://sproutmacapp.com" rel="nofollow">http://sproutmacapp.com</a> it focuses on making Git easy, and browsing and committing changes in your projects</p> <p><a href="http://sproutmacapp.com" rel="nofollow">http://sproutmacapp.com</a> </p>
4,954
<p>I need to call into a Win32 API to get a series of strings, and I would like to return an array of those strings to JavaScript. This is for script that runs on local machine for administration scripts, not for the web browser.</p> <p>My IDL file for the COM object has the interface that I am calling into as:</p> <pre> HRESULT GetArrayOfStrings([out, retval] SAFEARRAY(BSTR) * rgBstrStringArray); </pre> <p>The function returns correctly, but the strings are getting 'lost' when they are being assigned to a variable in JavaScript.</p> <p>The question is: What is the proper way to get the array of strings returned to a JavaScript variable? ­­­­­­­­­­­­­­­­­­­­­­­­</p>
<p>If i recall correctly, you'll need to wrap the <code>SAFEARRAY</code> in a <code>VARIANT</code> in order for it to get through, and then use a <a href="http://msdn.microsoft.com/en-us/library/y39d47w8(VS.85).aspx" rel="noreferrer">VBArray object</a> to unpack it on the JS side of things:</p> <pre><code>HRESULT GetArrayOfStrings(/*[out, retval]*/ VARIANT* pvarBstrStringArray) { // ... _variant_t ret; ret.vt = VT_ARRAY|VT_VARIANT; ret.parray = rgBstrStringArray; *pvarBstrStringArray = ret.Detach(); return S_OK; } </code></pre> <p>then</p> <pre><code>var jsFriendlyStrings = new VBArray( axOb.GetArrayOfStrings() ).toArray(); </code></pre>
<p><a href="https://stackoverflow.com/questions/45169/how-do-i-return-an-array-of-strings-from-an-activex-object-to-jscript#45211">Shog9</a> is correct. COM scripting requires that all outputs be VARIANTS. </p> <p>In fact, it also requires that all the <strong>INPUTs</strong> be VARIANTS as well -- see the nasty details of IDispatch in your favorite help file. It's only thought the magic of the Dual Interface implementation by ATL and similar layers (which most likely is what you are using) that you don't have to worry about that. The input VARIANTs passed by the calling code are converted to match your method signature before your actual method is called.</p>
6,698
<p>How do I get the history of commits that have been made to the repository for a particular user? </p> <p>I am able to access CVS either through the command line or TortioseCVS, so a solution using either method is sufficient.</p>
<pre><code>cvs history -u username </code></pre> <p>gives a history of changes the user has made</p>
<p>Or try this one:</p> <pre><code>cvs history -x AMR -D "your-desired-date" </code></pre> <p>Example </p> <pre><code>cvs history -x AMR -D "2012-04-12" </code></pre>
8,139
<p>The <strong><a href="http://msdn.microsoft.com/en-us/library/4wyz8787(VS.80).aspx" rel="noreferrer">TRACE macro</a></strong> can be used to output diagnostic messages to the debugger when the code is compiled in <strong>Debug</strong> mode. I need the same messages while in <strong>Release</strong> mode. Is there a way to achieve this?</p> <p>(Please do <strong>not</strong> waste your time discussing why I should not be using TRACE in Release mode :-)</p>
<p>Actually, the TRACE macro is a lot more flexible than OutputDebugString. It takes a printf() style format string and parameter list whereas OutputDebugString just takes a single string. In order to implement the full TRACE functionality in release mode you need to do something like this:</p> <pre><code>void trace(const char* format, ...) { char buffer[1000]; va_list argptr; va_start(argptr, format); wvsprintf(buffer, format, argptr); va_end(argptr); OutputDebugString(buffer); } </code></pre>
<p>In MFC, TRACE is defined as ATLTRACE. And in release mode that is defined as:</p> <pre><code>#define ATLTRACE __noop </code></pre> <p>So, using the out-the-box TRACE from MFC, you won't actually be able to read any TRACE text, because it won't even be written out. You could write your own TRACE function instead, then re-define the TRACE macro. You could do something like this:</p> <pre><code>void MyTrace(const CString&amp; text) { ::OutputDebugString(text); // Outputs to console, same as regular TRACE // TODO: Do whatever output you need here. Write to event log / write to text file / write to pipe etc. } </code></pre>
4,727
<p>I have a custom SharePoint application page deployed to the _layouts folder. It's a custom "new form" for a custom content type. During my interactions with this page, I will need to add an item to my list. When the page first loads, I can use SPContext.Current.List to see the current list I'm working with. But after I fill in my form and the form posts back onto itself and IsPostBack is true, then SPContext.Current.List is null so I can't find the list that I need to add my stuff into.</p> <p>Is this expected?</p> <p>How should I retain some info about my context list across the postback? Should I just populate some asp:hidden control with my list's guid and then just pull it back from that on the postback? That seems safe, I guess.</p> <p>FWIW, this is the MOSS 2007 Standard version.</p>
<p>Generally speaking I try and copy whatever approach the product group has taken when looking to add functionality of my own. In this case they add their own edit/view/add pages via the list definition itself.</p> <p>I built a solution that also needed its own custom "New" form, not open source unfortunately, though if you are interested you can download it, its called "Tagged Links" (Social Bookmarking for SharePoint) and you can find some links on my blog.</p> <p>To give you a few hints and tips, the following should set you off in the right direction:</p> <ol> <li>Created a new list definition.</li> <li>Created a new Content Type In the content type you can define your own "FormTemplates" that references a Rendering Template which determine what gets displayed in the "Middle" bit of those forms.</li> <li>Copied the standard Rendering Template, but then made the changes to it that I needed. </li> <li>Wrapped it all up in a solution, and deployed.</li> </ol> <p>My Rendering Template actually included an overridden "Save" Button where I did a lot of the extra work I needed to do during the save.</p> <p>Anyway, it is a little too much work in my opinion but, I think, it most closely matches the standard approach taken by the product developers. Let me know if you need more detail and I will see if I can put together a step-by-step blog post, but hopefully this gets you off on the right direction.</p>
<p>I'm not using a custom "new form", so this might not apply. I added an event receiver to my custom content type and then do my custom code in the ItemAdded or ItemAdding events. This code fires when the event is added to a list. You can use the event receiver properties to get to the parent List, Web, and Site.</p>
4,869
<p>I wondered if anyone had successfully managed, or knew how to automate the Safari web browser on the Windows platform.</p> <p>Ideally I would like to automate Safari in a similar way to using <a href="http://msdn.microsoft.com/en-us/library/aa741317.aspx" rel="nofollow noreferrer">mshtml</a> for Internet Explorer. Failing that a way to inject JavaScript into the running process would also be fine. I've used the JavaScript injection method to automate Firefox via the <a href="http://www.croczilla.com/jssh" rel="nofollow noreferrer">jssh</a> plug-in.</p> <p>I'm looking to automate the browser using .Net to enhance an existing automation framework <a href="http://watin.sourceforge.net/" rel="nofollow noreferrer">WatiN</a></p> <p><strong>Edit</strong>: Whilst I think selenium might be a great choice for automating Safari in certain scenarios, I would like to use a solution that does not require installing software on the server i.e. Selenium Core or an intermediate proxy server in the case of Selenium Remote Control.</p> <p><strong>Update: 23-03-2009</strong>: Whilst I've not yet found a way to automate Safari, I have found a way to automate Webkit inside of Chrome. If you run Chrome using the --remote-shell-port=9999 command line switches (ref: <a href="http://www.ericdlarson.com/misc/chrome_command_line_flags.html" rel="nofollow noreferrer">http://www.ericdlarson.com/misc/chrome_command_line_flags.html</a>) you can send javascript to the browser.</p> <p>Once connected to the remote debug seesion</p> <ul> <li>Send <strong>debug()</strong> to attach to the current tab</li> <li>Send any javascript command using <strong>print</strong>, i.e. print document.window.location.href</li> </ul> <p>We've used this method to add <a href="http://watin.svn.sourceforge.net/viewvc/watin/trunk/src/Core/Native/Chrome/" rel="nofollow noreferrer">Chrome support to WatiN</a></p>
<p>you might check my post here where I am using the method described above to automate Chrome in C#</p> <p><a href="http://markcz.wordpress.com/2012/02/18/automating-chrome-browser-from-csharp/" rel="nofollow">http://markcz.wordpress.com/2012/02/18/automating-chrome-browser-from-csharp/</a></p> <p>Martin</p>
<p><a href="http://selenium.openqa.org/" rel="nofollow noreferrer">Selenium</a> has been very useful for me for compatibility testing.</p>
8,553
<p>I've seen a few attempted SQL injection attacks on one of my web sites. It comes in the form of a query string that includes the "cast" keyword and a bunch of hex characters which when "decoded" are an injection of banner adverts into the DB.</p> <p>My solution is to scan the full URL (and params) and search for the presence of "cast(0x" and if it's there to redirect to a static page.</p> <p>How do you check your URL's for SQL Injection attacks?</p>
<p>I don't.</p> <p>Instead, I use parametrized SQL Queries and rely on the database to clean my input.</p> <p>I know, this is a novel concept to PHP developers and MySQL users, but people using real databases have been doing it this way for years.</p> <p>For Example (Using C#)</p> <pre><code>// Bad! SqlCommand foo = new SqlCommand("SELECT FOO FROM BAR WHERE LOL='" + Request.QueryString["LOL"] + "'"); //Good! Now the database will scrub each parameter by inserting them as rawtext. SqlCommand foo = new SqlCommany("SELECT FOO FROM BAR WHERE LOL = @LOL"); foo.Parameters.AddWithValue("@LOL",Request.QueryString["LOL"]); </code></pre>
<p>Thanks for the answers and links. Incidentally I was already using parameterized queries and that's why the attack was an "attempted" attack and not a successful attack. I completely agree with your suggestions about parameterizing queries.</p> <p>The MSDN posted link mentions "constraining the input" as part of the approach which is part of my current strategy. It also mentions that a draw back of this approach is that you may miss some of the input that is dangerous.</p> <p>The suggested solutions so far are valid, important and part of the defense against SQL Injection Attacks. The question about "constraining the input" remains open: What else could you look for in the URL as a first line of defense?</p>
6,380
<p>How can I stop Visual Studio (both 2005 and 2008) from crashing (sometimes) when I select the "Close All But This" option?This does not happen all the time either.</p>
<p>First, check <a href="http://www.windowsupdate.com" rel="nofollow noreferrer">Windows Update</a> and make sure both VS environments are up to date.</p> <p>If that doesn't help, uninstall them both completely, reinstall only 2005, update and test it. If 2005 doesn't crash, install 2008, update and test them both. Don't install any add-ons you may have been using until you've reinstalled and tested both editions of VS. </p> <p>If one or the other does crash, you should try <a href="http://blogs.msdn.com/astebner/articles/451329.aspx" rel="nofollow noreferrer">filing a bug against Visual Studio</a>.</p> <p>If they didn't crash, install any add-ons that you use one at a time and continue to test both editions after each one. (This will take ages, but that's how it has to be) When they start crashing, remove the offending add-on, and file a bug with the add-on developer. (be sure to tell them what other add-ons you're using, in case it only happens when 2 conflicting add-ons are installed.)</p>
<p>Another alternative:</p> <ol> <li>Study for 10 years to become a really good programmer</li> <li>Apply for (and get) a job at Microsoft in the Visual Studio team</li> <li>Fix the bug</li> </ol>
9,435
<p>We have a codebase that is several years old, and all the original developers are long gone. It uses many, many threads, but with no apparent design or common architectural principles. Every developer had his own style of multithreaded programming, so some threads communicate with one another using queues, some lock data with mutexes, some lock with semaphores, some use operating-system IPC mechanisms for intra-process communications. There is no design documentation, and comments are sparse. It's a mess, and it seems that whenever we try to refactor the code or add new functionality, we introduce deadlocks or other problems.</p> <p>So, does anyone know of any tools or techniques that would help to analyze and document all the interactions between threads? FWIW, the codebase is C++ on Linux, but I'd be interested to hear about tools for other environments.</p> <hr> <h2>Update</h2> <p>I appreciate the responses received so far, but I was hoping for something more sophisticated or systematic than advice that is essentially "add log messages, figure out what's going on, and fix it." There are lots of tools out there for analyzing and documenting control-flow in single-threaded programs; is there nothing available for multi-threaded programs?</p> <hr> <p>See also <a href="https://stackoverflow.com/questions/619677/debugging-multithreaded-applications">Debugging multithreaded applications</a></p>
<p>Invest in a copy of Intel's <a href="http://www.intel.com/cd/software/products/asmo-na/eng/239144.htm" rel="nofollow noreferrer">VTune</a> and its thread profiling tools. It will give you both a system and a source level view of the thread behaviour. It's certainly not going to autodocument the thing for you, but should be a real help in at least visualising what is happening in different circumstances.</p> <p>I think there is a trial version that you can download, so may be worth giving that a go. I've only used the Windows version, but looking at the VTune webpage it also has a Linux version.</p>
<p>One thing to keep in mind with using log4net or similar tool is that they change the timing of the application and can often hide the underlying race conditions. We had some poorly written code to debug and introduced logging and this actually removed race conditions and deadlocks (or greatly reduced their frequency).</p>
3,123
<p>What would be the easiest way to detach a specific JPA Entity Bean that was acquired through an EntityManager. Alternatively, could I have a query return detached objects in the first place so they would essentially act as 'read only'?</p> <p>The reason why I want to do this is becuase I want to modify the data within the bean - with in my application only, but not ever have it persisted to the database. In my program, I eventually have to call flush() on the EntityManager, which would persist all changes from attached entities to the underyling database, but I want to exclude specific objects.</p>
<p>(may be too late to answer, but can be useful for others)</p> <p>I'm developing my first system with JPA right now. Unfortunately I'm faced with this problem when this system is almost complete.</p> <p>Simply put. Use Hibernate, or wait for JPA 2.0.</p> <p>In Hibernate, you can use 'session.evict(object)' to remove one object from session. In <a href="http://jcp.org/en/jsr/detail?id=317" rel="noreferrer">JPA 2.0, <strike>in draft right now</strike>,</a> there is the 'EntityManager.detach(object)' method to detach one object from persistence context.</p>
<p>I think you can also use method EntityManager.refresh(Object o) if primary key of the entity has not been changed. This method will restore original state of the entity.</p>
5,138
<p>I'm looking for a simple solution for a yes/no dialog to use in a Java ME midlet. I'd like to use it like this but other ways are okey.</p> <pre><code>if (YesNoDialog.ask("Are you sure?") == true) { // yes was chosen } else { // no was chosen } </code></pre>
<p>You need an <a href="http://java.sun.com/javame/reference/apis/jsr118/javax/microedition/lcdui/Alert.html" rel="nofollow noreferrer">Alert</a>:</p> <blockquote> <p>An alert is a screen that shows data to the user and waits for a certain period of time before proceeding to the next Displayable. An alert can contain a text string and an image. The intended use of Alert is to inform the user about errors and other exceptional conditions.</p> </blockquote> <p>With 2 <a href="http://java.sun.com/javame/reference/apis/jsr118/javax/microedition/lcdui/Command.html" rel="nofollow noreferrer">commands</a> ("Yes"/"No" in your case):</p> <blockquote> <p>If there are two or more Commands present on the Alert, it is automatically turned into a modal Alert, and the timeout value is always FOREVER. The Alert remains on the display until a Command is invoked.</p> </blockquote> <p>These are built-in classes supported in MIDP 1.0 and higher. Also your code snippet will never work. Such an API would need to block the calling thread awaiting for the user to select and answer. This goes exactly in the opposite direction of the UI interaction model of MIDP, which is based in callbacks and delegation. You need to provide your own class, implementing <a href="http://java.sun.com/javame/reference/apis/jsr118/javax/microedition/lcdui/CommandListener.html" rel="nofollow noreferrer">CommandListener</a>, and prepare your code for asynchronous execution.</p> <p>Here is an (untested!) example class based on Alert:</p> <pre><code>public class MyPrompter implements CommandListener { private Alert yesNoAlert; private Command softKey1; private Command softKey2; private boolean status; public MyPrompter() { yesNoAlert = new Alert("Attention"); yesNoAlert.setString("Are you sure?"); softKey1 = new Command("No", Command.BACK, 1); softKey2 = new Command("Yes", Command.OK, 1); yesNoAlert.addCommand(softKey1); yesNoAlert.addCommand(softKey2); yesNoAlert.setCommandListener(this); status = false; } public Displayable getDisplayable() { return yesNoAlert; } public boolean getStatus() { return status; } public void commandAction(Command c, Displayable d) { status = c.getCommandType() == Command.OK; // maybe do other stuff here. remember this is asynchronous } }; </code></pre> <p>To use it (again, untested and on top of my head):</p> <pre><code>MyPrompter prompt = new MyPrompter(); Display.getDisplay(YOUR_MIDLET_INSTANCE).setCurrent(prompt.getDisplayable()); </code></pre> <p>This code will make the prompt the current displayed form in your app, but it <em>won't block your thread</em> like in the example you posted. You need to continue running and wait for a commandAction invocation.</p>
<p>I dont have programed in Java ME, but i found in it's reference for optional packages the <a href="http://java.sun.com/javame/reference/apis/jsr209/" rel="nofollow noreferrer">Advanced Graphics and User Interface API</a>, and it's used like the Java SE API to create these dialogs with the <a href="http://java.sun.com/javame/reference/apis/jsr209/javax/swing/JOptionPane.html" rel="nofollow noreferrer">JOptionPane Class</a></p> <blockquote> <p><code>int JOptionPane.showConfirmDialog(java.awt.Component parentComponent, java.lang.Object &gt;message, java.lang.String title, int optionType)</code></p> </blockquote> <p>Return could be <code>JOptionPane.YES_OPTION</code>, <code>JOptionPane.NO_OPTION</code>, <code>JOptionPane.CANCEL_OPTION</code>...</p>
8,108
<p>I'm attempting to use an existing CAS server to authenticate login for a Perl CGI web script and am using the <a href="http://search.cpan.org/dist/AuthCAS" rel="nofollow noreferrer">AuthCAS</a> Perl module (v 1.3.1). I can connect to the CAS server to get the service ticket but when I try to connect to validate the ticket my script returns with the following error from the <a href="http://search.cpan.org/dist/IO-Socket-SSL" rel="nofollow noreferrer">IO::Socket::SSL</a> module:</p> <pre><code> 500 Can't connect to [CAS Server]:443 (Bad hostname '[CAS Server]') ([CAS Server] substituted for real server name) </code></pre> <p>Symptoms/Tests:</p> <ol> <li>If I type the generated URL for the authentication into the web browser's location bar it returns just fine with the expected XML snippet. So it is not a bad host name.</li> <li>If I generate a script without using the AuthCAS module but using the IO::Socket::SSL module directly to query the CAS server for validation on the generated service ticket the Perl script will run fine from the command line but not in the browser.</li> <li>If I add the AuthCAS module into the script in item 2, the script no longer works on the command line and still doesn't work in the browser.</li> </ol> <p>Here is the bare-bones script that produces the error:</p> <pre><code>#!/usr/bin/perl use strict; use warnings; use CGI; use AuthCAS; use CGI::Carp qw( fatalsToBrowser ); my $id = $ENV{QUERY_STRING}; my $q = new CGI; my $target = "http://localhost/cgi-bin/testCAS.cgi"; my $cas = new AuthCAS(casUrl =&gt; 'https://cas_server/cas'); if ($id eq ""){ my $login_url = $cas-&gt;getServerLoginURL($target); printf "Location: $login_url\n\n"; exit 0; } else { print $q-&gt;header(); print "CAS TEST&lt;br&gt;\n"; ## When coming back from the CAS server a ticket is provided in the QUERY_STRING print "QUERY_STRING = " . $id . "&lt;/br&gt;\n"; ## $ST should contain the received Service Ticket my $ST = $q-&gt;param('ticket'); my $user = $cas-&gt;validateST($target, $ST); #### This is what fails printf "Error: %s\n", &amp;AuthCAS::get_errors() unless (defined $user); } </code></pre> <p>Any ideas on where the conflict might be?</p> <hr> <p>The error is coming from the line directly above the snippet Cebjyre quoted namely</p> <pre><code>$ssl_socket = new IO::Socket::SSL(%ssl_options); </code></pre> <p>namely the socket creation. All of the input parameters are correct. I had edited the module to put in debug statements and print out all the parameters just before that call and they are all fine. Looks like I'm going to have to dive deeper into the IO::Socket::SSL module.</p>
<p>As usually happens when I post questions like this, I found the problem. It turns out the <a href="http://search.cpan.org/dist/Crypt-SSLeay" rel="nofollow noreferrer">Crypt::SSLeay</a> module was not installed or at least not up to date. Of course the error messages didn't give me any clues. Updating it and all the problems go away and things are working fine now.</p>
<p>Well, from the <a href="http://search.cpan.org/src/OSALAUN/AuthCAS-1.3.1/lib/AuthCAS.pm" rel="nofollow noreferrer">module source</a> it looks like that IO::Socket error is coming from get_https2</p> <pre><code>[...] unless ($ssl_socket) { $errors = sprintf "error %s unable to connect https://%s:%s/\n",&amp;IO::Socket::SSL::errstr,$host,$port; return undef; } [...] </code></pre> <p>which is called by callCAS, which is called by validateST.</p> <p>One option is to temporarily edit the module file to put some debug statements in if you can, but if I had to guess, I'd say the casUrl you are supplying isn't matching up to the _parse_url regex properly - maybe you have three slashes after the https?</p>
4,645
<p>I'm printing flat objects (like rectangular) with PLA on a glass bed and 70 celcius degrees (also tried 75 celcius too, 65 celcius and lower ends with adhesion problem in general). Also I use brims too. Most of the time, after a while it shrinks and warps (when print continues).</p> <p>Room temperature is steady, there is no airflow to cool down things..</p> <p>I tried to slow down to 20mm/sec. I tried to increase heat for first layer... Nothing helps. </p> <p>I am suspicious about moisture of the filaments. Can it be related?</p>
<p>Warping is caused by the plastic shrinking as it cools and inadequate bed adhesion is usually the what lets it warp. Either cleaning your print surface very thoroughly with rubbing alcohol or using something like a glue stick on your print bed will mitigate that warping enough that you won't suffer problems with your print. Printing too hot can also be a problem because the plastic will need to even cool more after it is extruded and could possibly lead to more stresses buildup in the plastic.</p> <p>The dimensional stability of PLA really depends on the quality of the plastic. Storage conditions come into play as well, but it is mostly the quality of the material you need to worry about; I have some cheaper PLA that has gotten brittle due to having absorbed moisture despite being in a (albeit somewhat loosely closed) package with desiccants, and I also have a different brand of PLA that is of much higher quality that I just leave out in the open; this PLA doesn't exibit signs of moisture damage. Higher quality filaments are designed to resist moisture better and be more stable in terms of dimensions. With the cheaper brand of PLA, I have also experienced warping, but that is not due to moisture in the filament; that was actually from a new roll.</p> <p>When a filament absorbs too much moisture, it can become brittle but still print. Excessive moisture will cause any water in the filament to vaporize when passing through the hotend and form bubbles that will ruin the finish quality of a print. You'll know if filament is excessively wet because you will hear quiet and sharp snapping sounds as the result of the bubbles that are formed in the plastic popping. You will also be able to see steam if you examine your hotend with a bright light as it is extruding.</p> <p>I'd suggest trying a different brand of filament if possible, cleaning the print surface / adding glue, or at the very least, a new roll of filament.</p> <p><em>(When using a glue stick to increase first layer adhesion, it could be worth noting something unusual I found; adding glue to the build plate of a Prusa i3 MK3S actually reduces bed adhesion in my experience. It might be worth playing around to see if super clean works for you, or if super sticky does. The build plate is coated in a very finely textured PEI if that is some information that could help your case.)</em> </p>
<p>PLA doesn't usually have water absorption issues. It usually prints just fine ... Maker's Muse did a video using 7yo PLA filament (IIRC) which had been stored in the open. Printed without issues. Not saying all PLA's are going to work as well, but I don't think it's a place I'd be looking first for an issue. Moisture in the filaments usually exhibits itself as popping and spitting as the filament is extruded leaving blank spaces in your print.</p>
1,568
<p>The following shell script takes a list of arguments, turns Unix paths into WINE/Windows paths and invokes the given executable under WINE.</p> <pre><code>#! /bin/sh if [ "${1+set}" != "set" ] then echo "Usage; winewrap EXEC [ARGS...]" exit 1 fi EXEC="$1" shift ARGS="" for p in "$@"; do if [ -e "$p" ] then p=$(winepath -w $p) fi ARGS="$ARGS '$p'" done CMD="wine '$EXEC' $ARGS" echo $CMD $CMD </code></pre> <p>However, there's something wrong with the quotation of command-line arguments.</p> <pre><code>$ winewrap '/home/chris/.wine/drive_c/Program Files/Microsoft Research/Z3-1.3.6/bin/z3.exe' -smt /tmp/smtlib3cee8b.smt Executing: wine '/home/chris/.wine/drive_c/Program Files/Microsoft Research/Z3-1.3.6/bin/z3.exe' '-smt' 'Z: mp\smtlib3cee8b.smt' wine: cannot find ''/home/chris/.wine/drive_c/Program' </code></pre> <p>Note that:</p> <ol> <li>The path to the executable is being chopped off at the first space, even though it is single-quoted.</li> <li>The literal "\t" in the last path is being transformed into a tab character.</li> </ol> <p>Obviously, the quotations aren't being parsed the way I intended by the shell. How can I avoid these errors?</p> <p>EDIT: The "\t" is being expanded through two levels of indirection: first, <code>"$p"</code> (and/or <code>"$ARGS"</code>) is being expanded into <code>Z:\tmp\smtlib3cee8b.smt</code>; then, <code>\t</code> is being expanded into the tab character. This is (seemingly) equivalent to</p> <pre><code>Y='y\ty' Z="z${Y}z" echo $Z </code></pre> <p>which yields </p> <pre><code>zy\tyz </code></pre> <p>and <em>not</em></p> <pre><code>zy yz </code></pre> <p>UPDATE: <code>eval "$CMD"</code> does the trick. The "<code>\t</code>" problem seems to be echo's fault: "If the first operand is -n, or if any of the operands contain a backslash ( '\' ) character, the results are implementation-defined." (<a href="http://www.opengroup.org/onlinepubs/009695399/utilities/echo.html" rel="nofollow noreferrer">POSIX specification of <code>echo</code></a>)</p>
<p>I you do want to have the assignment to CMD you should use </p> <p><code>eval $CMD</code> </p> <p>instead of just <code>$CMD</code> in the last line of your script. This should solve your problem with spaces in the paths, I don't know what to do about the "\t" problem.</p>
<p>You can try preceeding the spaces with \ like so:</p> <pre><code>/home/chris/.wine/drive_c/Program Files/Microsoft\ Research/Z3-1.3.6/bin/z3.exe </code></pre> <p>You can also do the same with your \t problem - replace it with \\t.</p>
5,678
<p>I'm using the After Effects CS3 Javascript API to dynamically create and change text layers in a composition.</p> <p>Or at least I'm trying to because I can't seem to find the right property to change to alter the actual text of the TextLayer object.</p>
<p>Hmm, must read docs harder next time.</p> <pre><code>var theComposition = app.project.item(1); var theTextLayer = theComposition.layers[1]; theTextLayer.property("Source Text").setValue("This text is from code"); </code></pre>
<p>I wrote a simple function for myself to change properties. Here it is:</p> <pre><code>function change_prop(prop, name, value){ var doc = prop.value; doc[name] = value; prop.setValue(doc); return prop; } </code></pre> <p>Example use:</p> <pre><code>// Changing source text change_prop(text_layer.property("Source Text"), "text", "That's the source text"); // Changing font size change_prop(text_layer.property("ADBE Text Properties").property("ADBE Text Document"), "fontSize", 10) </code></pre>
9,483
<p>I'd like to check if the user input is an email address in JavaScript, before sending it to a server or attempting to send an email to it, to prevent the most basic mistyping. How could I achieve this?</p>
<p>Using <a href="http://en.wikipedia.org/wiki/Regular_expression" rel="noreferrer">regular expressions</a> is probably the best way. You can see a bunch of tests <a href="http://jsfiddle.net/ghvj4gy9/embedded/result,js/" rel="noreferrer">here</a> (taken from <a href="https://cs.chromium.org/chromium/src/third_party/blink/web_tests/fast/forms/resources/ValidityState-typeMismatch-email.js?q=ValidityState-typeMismatch-email.js&amp;sq=package:chromium&amp;dr" rel="noreferrer">chromium</a>)</p> <pre class="lang-js prettyprint-override"><code>const validateEmail = (email) =&gt; { return String(email) .toLowerCase() .match( /^(([^&lt;&gt;()[\]\\.,;:\s@&quot;]+(\.[^&lt;&gt;()[\]\\.,;:\s@&quot;]+)*)|(&quot;.+&quot;))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ ); }; </code></pre> <p>Here's the example of a regular expression that accepts unicode:</p> <pre class="lang-js prettyprint-override"><code>const re = /^(([^&lt;&gt;()[\]\.,;:\s@\&quot;]+(\.[^&lt;&gt;()[\]\.,;:\s@\&quot;]+)*)|(\&quot;.+\&quot;))@(([^&lt;&gt;()[\]\.,;:\s@\&quot;]+\.)+[^&lt;&gt;()[\]\.,;:\s@\&quot;]{2,})$/i; </code></pre> <p>But keep in mind that one should not rely only upon JavaScript validation. JavaScript can easily be disabled. This should be validated on the server side as well.</p> <p>Here's an example of the above in action:</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>const validateEmail = (email) =&gt; { return email.match( /^(([^&lt;&gt;()[\]\\.,;:\s@\"]+(\.[^&lt;&gt;()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ ); }; const validate = () =&gt; { const $result = $('#result'); const email = $('#email').val(); $result.text(''); if (validateEmail(email)) { $result.text(email + ' is valid :)'); $result.css('color', 'green'); } else { $result.text(email + ' is not valid :('); $result.css('color', 'red'); } return false; } $('#email').on('input', validate);</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt; &lt;label for="email"&gt;Enter an email address: &lt;/label&gt; &lt;input id="email" /&gt; &lt;h2 id="result"&gt;&lt;/h2&gt;</code></pre> </div> </div> </p>
<p>One of my coworker shared this regex with me. I like it a lot.</p> <pre><code>function isValidEmailAddress (email) { var validEmail = false; if (email) { email = email.trim().toLowerCase(); var pattern = /^[\w-']+(\.[\w-']+)*@([a-zA-Z0-9]+[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*?\.[a-zA-Z]{2,6}|(\d{1,3}\.){3}\d{1,3})(:\d{4})?$/; validEmail = pattern.exec(email); } return validEmail; } if (typeof String.prototype.trim !== 'function') { String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); }; } </code></pre>
6,822
<p>I'm trying to understand how namespaces work in XML. When I have an element like foo:bar, the attributes will often not have namespaces on them. But sometimes they will. Are the attribute in the namespace of the element, even when the default namespace has been declared? Looking over the xsd for xhtml it seems the attributes are part of the schema and should be in the namespace for xhtml, but they are never presented that way...</p>
<p>Most of the time, attributes will not be in any namespace. The <a href="http://www.w3.org/TR/REC-xml-names/#defaulting" rel="noreferrer">namespace spec</a> says (<em>emphasis</em> mine):</p> <blockquote> <p>A default namespace declaration applies to all unprefixed <em>element</em> names within its scope. Default namespace declarations do <em>not</em> apply directly to <em>attribute</em> names; the interpretation of unprefixed attributes is determined by the element on which they appear.</p> </blockquote> <p>There's a reason that most XML vocabularies use non-namespaced attributes:<br> When your elements have a namespace and those elements have attributes, then there can be no confusion: the attributes belong to your element, which belongs to your namespace. Adding a namespace prefix to the attributes would just make everything more verbose.</p> <p>So why do namespaced attributes exist?<br> Because some vocabularies do useful work with mostly attributes, and can do this when mixed in with other vocabularies. The best known example is <a href="http://en.wikipedia.org/wiki/XLink" rel="noreferrer">XLink</a>.</p> <p>Lastly, W3C XML Schema has an all too easy way (<code>&lt;schema attributeFormDefault="qualified"&gt;</code>) of declaring your attributes as being in a namespace, forcing you to prefix them in your documents, <em>even</em> when you use a default namespace.</p>
<p>Read up at <a href="http://www.w3.org/TR/REC-xml-names/#scoping" rel="nofollow noreferrer">6.1 Namespace Scoping</a> and <a href="http://www.w3.org/TR/REC-xml-names/#defaulting" rel="nofollow noreferrer">6.2 Namespace Defaulting</a> on w3c.</p> <p>Basically:</p> <blockquote> <p>The scope of a namespace declaration declaring a prefix extends from the beginning of the start-tag in which it appears to the end of the corresponding end-tag</p> </blockquote> <p>However, the text here doesn't seem to explain if means a is foo:a or the default namespace in the context. I would assume that it does not refer to foo:a, but rather the documents default namespace a. Considering this quote at least:</p> <blockquote> <p>Such a namespace declaration applies to all element and attribute names within its scope whose prefix matches that specified in the declaration. </p> </blockquote> <p>Ie. the namespace "foo:" only applies to elements prefixed with foo:</p>
6,287
<pre><code>&lt;servlet&gt; &lt;servlet-name&gt;myservlet&lt;/servlet-name&gt; &lt;servlet-class&gt;workflow.WDispatcher&lt;/servlet-class&gt; &lt;load-on-startup&gt;2&lt;/load-on-startup&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;myservlet&lt;/servlet-name&gt; &lt;url-pattern&gt;*NEXTEVENT*&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; </code></pre> <p>Above is the snippet from Tomcat's <code>web.xml</code>. The URL pattern <code>*NEXTEVENT*</code> on start up throws</p> <blockquote> <p>java.lang.IllegalArgumentException: Invalid &lt;url-pattern> in servlet mapping</p> </blockquote> <p>It will be greatly appreciated if someone can hint at the error. ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­</p>
<pre><code>&lt;url-pattern&gt;*NEXTEVENT*&lt;/url-pattern&gt; </code></pre> <p>The URL pattern is not valid. It can either end in an asterisk or start with one (to denote a file extension mapping).</p> <p>The url-pattern specification:</p> <blockquote> <ul> <li>A string beginning with a ‘/’ character and ending with a ‘/*’ suffix is used for path mapping.</li> <li>A string beginning with a ‘*.’ prefix is used as an extension mapping.</li> <li>A string containing only the ’/’ character indicates the "default" servlet of the application. In this case the servlet path is the request URI minus the context path and the path info is null.</li> <li>All other strings are used for exact matches only.</li> </ul> </blockquote> <p>See section 12.2 of the <a href="https://jcp.org/aboutJava/communityprocess/final/jsr340/index.html" rel="noreferrer">Java Servlet Specification</a> Version 3.1 for more details.</p>
<p>A workaround that can achieve that is to add a servlet filter to do URL re-writes e.g. re-write <em>NEXTEVENT</em> to /NEXTEVENT/<em>(the one before the NEXTEVENT)/</em>(the one after NEXTEVENT) or something similar.</p>
4,629
<p>Is there ever a circumstance in which I would not want to use the <a href="http://msdn.microsoft.com/en-us/library/cb8x3kfz.aspx" rel="noreferrer"><code>AndAlso</code></a> operator rather than the <a href="http://msdn.microsoft.com/en-us/library/sdbcfyzh.aspx" rel="noreferrer"><code>And</code></a> operator? &hellip;or in which I would not want to use the <a href="http://msdn.microsoft.com/en-us/library/ea1sssb2.aspx" rel="noreferrer"><code>OrElse</code></a> operator rather than the <a href="http://msdn.microsoft.com/en-us/library/06s37a7f.aspx" rel="noreferrer"><code>Or</code></a> operator?</p>
<p>From <a href="http://msdn.microsoft.com/en-us/library/wz3k228a.aspx" rel="noreferrer">MSDN</a>:</p> <p><strong>Short-Circuiting Trade-Offs</strong></p> <p><em>Short-circuiting can improve performance by not evaluating an expression that cannot alter the result of the logical operation. However, if that expression performs additional actions, short-circuiting skips those actions. For example, if the expression includes a call to a Function procedure, that procedure is not called if the expression is short-circuited, and any additional code contained in the Function does not run. If your program logic depends on any of that additional code, you should probably avoid short-circuiting operators.</em> </p>
<p>They are completely different functionalities in VB.net and both have their use cases (though for the most common use both will work)</p> <p><code>AndAlso</code> and <code>OrElse</code> are <strong>conditional</strong> operators, they return a true or false boolean value and only evaluate what they need to until they reach the result that cannot be altered (false for AndAlso, true for OrElse). These are the equivalent of <code>&amp;&amp;</code> and <code>||</code> in languages like C# and Java.</p> <p><code>And</code> and <code>Or</code> are <strong>bitwise</strong> operators, they combine the bits of whatever is passed to them into a result, and since those bits can always be altered by further evaluation, need to evaluate everything. These are the equivalent of <code>&amp;</code> and <code>|</code> in languages like C# and Java.</p> <p>Most of the time, when you're looking at an and/or operation, you want conditional results. Bitwise operations will produce a value that is truthy or falsey and will (usually) match the true or false results from proper conditional operators, they will just take a bit longer on average since they evaluate everything.</p> <p>Bitwise operators are meant to be used when you care about the specific bits in a value, often used for storing settings or permissions in as compact a way as possible, and for reading and applying them as fast as possible. For example the read/write/execute permissions on files in Unix based systems use bit flags this way:</p> <blockquote> <p>0b001 - execute permission<br /> 0b010 - write permission<br /> 0b100 - read permission</p> </blockquote> <p>so, in decimal, a value of 7 can do all three, a value of 4 can only read, 6 can read and write, etc. If someone is trying to write to a file it checks their permissions by using <code>And 0b010</code> and gets a truthy or falsy result based on the bit in that position. To update the value to let users execute a file, you would use <code>Or 0b001</code> on their current permissions and store the result.</p> <p>The difference comes here:</p> <blockquote> <p>0b001 (truthy) And 0b010 (truthy) = 0b000 (falsy) <br /> 0b001 (truthy) AndAlso 0b010 (truthy) = True</p> </blockquote>
7,872
<p>How do I find out which process is listening on a TCP or UDP port on Windows?</p>
<h1><a href="https://en.wikipedia.org/wiki/PowerShell" rel="noreferrer">PowerShell</a></h1> <h2>TCP</h2> <pre><code>Get-Process -Id (Get-NetTCPConnection -LocalPort YourPortNumberHere).OwningProcess </code></pre> <h2>UDP</h2> <pre><code>Get-Process -Id (Get-NetUDPEndpoint -LocalPort YourPortNumberHere).OwningProcess </code></pre> <h1><a href="https://en.wikipedia.org/wiki/Cmd.exe" rel="noreferrer">cmd</a></h1> <pre><code> netstat -a -b </code></pre> <p>(Add <strong>-n</strong> to stop it trying to resolve hostnames, which will make it a lot faster.)</p> <p>Note Dane's recommendation for <a href="http://technet.microsoft.com/en-us/sysinternals/bb897437.aspx" rel="noreferrer">TCPView</a>. It looks very useful!</p> <p><strong>-a</strong> Displays all connections and listening ports.</p> <p><strong>-b</strong> Displays the executable involved in creating each connection or listening port. In some cases well-known executables host multiple independent components, and in these cases the sequence of components involved in creating the connection or listening port is displayed. In this case the executable name is in [] at the bottom, on top is the component it called, and so forth until TCP/IP was reached. Note that this option can be time-consuming and will fail unless you have sufficient permissions.</p> <p><strong>-n</strong> Displays addresses and port numbers in numerical form.</p> <p><strong>-o</strong> Displays the owning process ID associated with each connection.</p>
<p>For Windows, if you want to find stuff listening or connected to port 1234, execute the following at the cmd prompt: </p> <pre><code>netstat -na | find "1234" </code></pre>
7,056
<p>I've built and done some simple tests on a TEVO Tarantula but I've noticed some pretty dramatic under extrusions. </p> <p>My equipment:</p> <ul> <li>TEVO Tarantula;</li> <li>Jim Brown's easy config fork of Marlin;</li> <li>Titan extruder (came with printer).</li> </ul> <p>I've updated the firmware with the 400 steps as advised and calibrated the extrusion with the 100&nbsp;mm method:</p> <ul> <li>When I run the calibration with the Titan extruder, <em>only</em> the 400 steps is fine and works as expected;</li> <li>When I connect the Bowden tube to the hotend and calibrate (at 200, 225 and 250°C), I see only ~50&nbsp;mm of extrusion. </li> </ul> <p>I've disassemble the hot end, changed filament and I can't see any signs of blockage. The Bowden tube in the hotend is not showing any signs of melting etc. and it is pushed all the way down to the hotend, as per the instructions. </p> <p>So, what's going with this?</p>
<p>It is definitively possible to do what you want, but your questions are samewhat problematic:</p> <blockquote> <p>So, I need to know if it's possible to print that cylinder hard enough to work as an axis.</p> </blockquote> <p>"hard enough" is a mysterious quantity. What is the intended application? The load of the axis, the rotation speed, the medium in which the part will be in, its operating temperature... they all affect the answer.</p> <blockquote> <p>And what should be the gap size between the cylinder and the counter part's hole to rotate properly?</p> </blockquote> <p>Reading at the question and the comments, I think you may have the wrong representation model in your mind. There are four different concepts at work here:</p> <ul> <li><em>Accuracy</em> is the maximum dimensional variation between parts. </li> <li><em>Tolerance</em> is the amount of random deviation or variation permitted for a given dimension.</li> <li><em>Allowance</em> is a planned difference between a nominal or reference value and an exact value.</li> <li><em>Clearance</em> is the intentional space between two parts.</li> </ul> <p>So: what you want to achieve for the object to rotate is to have at least some <em>clearance</em> once you have the parts printed. Therefore, you want to design your part with an <em>allowance</em> which is at least as much as the <em>accuracy</em>.</p> <p>Note that a machine cannot produce parts with a tighter tolerance than its accuracy. So you must design your part with a <em>tolerance</em> equal or greater than your printer <em>accuracy</em>.</p> <p>The correct number will therefore be entirely dependant from the specific printer you will be using. You can find out the specific <em>accuracy</em> of a printer by printing a <a href="https://www.thingiverse.com/search?q=Tolerance%20test&amp;sa=&amp;dwh=815ab32c4d0733c" rel="noreferrer">tolerance test</a> (I know, I know... why isn't it called "accuracy test"?)</p> <p>See this <a href="https://3dprinting.stackexchange.com/a/5187/9134">unrelated answer</a> - from wich I took the above definitions - for learning more about the above and a concrete example.</p> <blockquote> <p>If it's is like 0.05mm, can I print that level of detail with a 3D printer too?</p> </blockquote> <p>I hope it is now clear why this question makes no sense: <em>clearance</em> is a variable which depends from <em>accuracy</em> (and the application), not the other way around.</p> <blockquote> <p>I can't add so much gap because I have really limited space</p> </blockquote> <p>This comment too is incorrect: the "gap" (clearance) can be very very small. You have to have the correct <em>allowance</em> in your design, and allowance will <em>not</em> intrinsically make a part larger.</p> <blockquote> <p>What hardware and material should I use to do this?</p> </blockquote> <p>Again: this is entirely dependent from your application (load, operating temperature, orientation, speed...)</p> <p>A consumer-grade FDM printer (easy accessible, cheap and cheap to operate) will allow you to print a rotating part, a SLA/DLP printer (less common, toxic resins, more expensive to operate) will allow to print the same part with different materials and tighter tolerances...</p> <blockquote> <p>I don't worry about breaking, but it cannot be flexible</p> </blockquote> <p>Again: without an explanaton of the intended use (or the numbers associated to it) it's impossible to answer this comment conclusively. Resins tend to harden to more rigid solids, but you have thrown around tolerances as small as 0.05mm in your writing, and over 12mm of axis, that is a deviation of less than 0.5% from "perfectly straight". I'm hard pressed to think you will find a printable material with such a rigidity.</p>
<p>It is considered good practice to limit your post to one question at a time. The question about hardware and material is too broad to be a good question and I will set that aside.</p> <p>Equally unfortunate, your drawing is ambiguous. I suppose if English is not your native language, I'm not helping things either.</p> <p>The drawing has some errors that make it challenging to be certain of a correct answer, but I can provide you with some useful information as a direct result of a test print created today.</p> <p>The test print for my printer creates a series of spool shapes within retainer shapes. More complex than a simply cylinder making the test that much more difficult.</p> <p>My printer is able to print without problem parts that are 1.0 mm apart, 0.8 mm apart and 0.6 mm apart. The test failed at the 0.4 mm spacing and the 0.3 mm spacing, telling me that I need to perform some tuning.</p> <p>Your question asks about 0.05 mm spacing. I think you will not find an FDM printer that will manage such separation without bonding together the individual components. FDM printers use filament.</p> <p>You may also not find that an SLA or DLP printer can provide such tight tolerances. It is the most likely source of a success, however. I have only minimal exposure to tolerance in this type of printer. SLA/DLP printers use lasers/light and liquid resin. They can accomplish 0.05 mm layer thickness, even as small as 0.025 mm layers, but I do not know the figures for horizontal precision/accuracy/tolerance.</p> <p>SLS printers use a nylon powder and a laser to fuse the powder together to form the model. My SLS printer uses 0.050 mm powder. To accomplish the separation you require would mean a single layer of powder will separate the individual segments of the model. This is not practical for this type of printer.</p> <p>Your best bet would be to consult with a 3D printing service that uses SLA printers. SLA is likely to be more precise than DLP due to the method of exposing the resin, although that is not a universal truth.</p>
855
<p>I am having this problem with my printer. It doesn't print smooth circular objects. The objects are typically "ribbed" or ridged... never smooth. I am not sure how to fix this.</p> <p>I have tried fixing it in Meshmixer, I've tried <em>Sli3r</em> (I normally use <em>Cura</em> 2.7). I've tried turning down acceleration as low as it will go (500 in my printer's case), tried slowing down the actual print and travel speeds. Short of just replacing the dang thing (not an option at all), I have no idea what to do... I'm at a total loss for words here.</p> <p>My printer is a TronXY P802MA. Auto Level, runs <em>Marlin</em> firmware. I use Octoprint as my print server. The picture shows the odd texture. It's at the bottom of this particular model. For some reason, within the pictured model, the problem isn't reproduced in the partial spheres.</p> <p><a href="https://i.stack.imgur.com/WKe5A.jpg" rel="nofollow noreferrer" title="Unwanted texture"><img src="https://i.stack.imgur.com/WKe5A.jpg" alt="Unwanted texture" title="Unwanted texture"></a></p>
<p>Any deviation from smoothness is caused by irregularity in the material feed, the motion, or both. In this case, I would suggest both.</p> <p>The problem is that current 3D printer control firmware (If someone has a counter-example in the hobbiest space, please add it) prints in linear segments. This starts as @senthil-j-prakash shows in the conversion of the CAD object to an STL file. STL files are made of triangles, which are linear structures. There is no curvature in a triangle, only straight edges and flat faces. Making the triangles as small as possible helps, but it exacerbates the next problem.</p> <p>The second problem is that each line segment is passed as a separate command to the control firmware. No matter if this is stored on an SD card, or transmitted through USB from the PC to the control firmware, each command defines a short, linear movement. In an ideal world, the printer would precisely reproduce each of this short, linear motions, which would flow smoothly from one to the next.</p> <p>Unfortunately, the "flowing smoothly" part is difficult to implement, and in some cases isn't actually what you want. If the angle between segments is sharp enough, you don't want to round the corner. When printing approximations to circles, however, one could move continuously, if the commands were sent enough ahead to analyze, and the firmware were clever enough to combine two segments into one smooth, curving motion.</p> <p>This computation is very difficult to perform on an 8-bit microcontroller, and historically has not been done.</p> <p>I am using a 32-bit ARM microcontroller and the RepRap firmware, which also does not smoothly merge motion between two low-angle linear motions into one smoother motion.</p> <p>But, it's not just merging two into one. One must merge a long series of short, linear moves into a long sequence of curved moves. We could be doing motion planning based on splines rather than segments.</p> <p>But then, we need to cap how much the control processor may change the path because the slicing software needs to predict very closely where each extruded element will lie. Adjacent elements (additional perimeters and infill) must be placed to touch those elements for bonding and strength. if the control processor has moved an element too far, it could either not connect with, or interfere with, an element that is placed later.</p> <p>But, enough of that rant about the technical difficulties.</p> <p>For your particular machine, it is likely to be moving in fits and starts because of the short, linear commands. Anything you do that improves the print quality will help with the ribs, and make them look more like facets.</p> <p>Check the belt tension, the backlash, and the stiffness of the whole machine. Try using slower speed and acceleration settings. If you are printing from a PC through USB or the network, try printing from an SD card. (If printing from an SD card, try printing over USB or the network).</p> <p>Good luck, and keep printing! Tell others of your experiences.</p>
<p>Did you try to use different infill? Denser or less dense?</p> <p>You can also try to reduce overlapping infil with outlines.</p> <p>Try to set 2 or 3 outer perimeters / outlines.</p>
688
<p>We have our own ORM we use here, and provide strongly typed wrappers for all of our db tables. We also allow weakly typed ad-hoc SQL to be executed, but these queries still go through the same class for getting values out of a data reader.</p> <p>In tweaking that class to work with Oracle, we've come across an interesting question. Is it better to use DBNull.Value, or null? Are there any benefits to using DBNull.Value? It seems more "correct" to use null, since we've separated ourselves from the DB world, but there are implications (you can't just blindly <code>ToString()</code> when a value is null for example) so its definitely something we need to make a conscious decision about.</p>
<p>I find it better to use null, instead of DB null.</p> <p>The reason is because, as you said, you're separating yourself from the DB world.</p> <p>It is generally good practice to check reference types to ensure they aren't null anyway. You're going to be checking for null for things other than DB data, and I find it is best to keep consistency across the system, and use null, not <code>DBNull</code>.</p> <p>In the long run, architecturally I find it to be the better solution.</p>
<p>Use <code>DBNull</code>.<br> We encouintered some sort of problems when using null.<br> If I recall correctly you cannot INSERT a null value to a field, only DBNull.<br> Could be Oracle related only, sorry, I do not know the details anymore.</p>
3,390
<p>I'm trying to unit test a custom ConfigurationSection I've written, and I'd like to load some arbitrary configuration XML into a <a href="http://msdn.microsoft.com/en-us/library/system.configuration.configuration.aspx" rel="noreferrer">System.Configuration.Configuration</a> for each test (rather than put the test configuration xml in the Tests.dll.config file. That is, I'd like to do something like this:</p> <pre><code>Configuration testConfig = new Configuration("&lt;?xml version=\"1.0\"?&gt;&lt;configuration&gt;...&lt;/configuration&gt;"); MyCustomConfigSection section = testConfig.GetSection("mycustomconfigsection"); Assert.That(section != null); </code></pre> <p>However, it looks like <a href="http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.aspx" rel="noreferrer">ConfigurationManager</a> will only give you Configuration instances that are associated with an EXE file or a machine config. Is there a way to load arbitrary XML into a Configuration instance?</p>
<p>There is actually a way I've discovered....</p> <p>You need to define a new class inheriting from your original configuration section as follows:</p> <pre><code>public class MyXmlCustomConfigSection : MyCustomConfigSection { public MyXmlCustomConfigSection (string configXml) { XmlTextReader reader = new XmlTextReader(new StringReader(configXml)); DeserializeSection(reader); } } </code></pre> <p><br/> You can then instantiate your ConfigurationSection object as follows:</p> <pre><code>string configXml = "&lt;?xml version=\"1.0\"?&gt;&lt;configuration&gt;...&lt;/configuration&gt;"; MyCustomConfigSection config = new MyXmlCustomConfigSection(configXml); </code></pre> <p>Hope it helps someone :-)</p>
<p>Looking at the members of the class, I'd say the answer is probably no*. I'm not sure why you'd want to do this anyway, rather than create your own XML configuration file.</p> <p>*That's no, excluding messy reflection hacks</p>
4,132
<p>I'm using Pylons (a python framework) to serve a simple web application, but it seems to die from time to time, with this in the error log: <code>(2006, 'MySQL server has gone away')</code></p> <p>I did a bit of checking, and saw that this was because the connections to MySQL were not being renewed. This shouldn't be a problem though, because the <code>sqlalchemy.pool_recycle</code> in the config file should automatically keep it alive. The default was <code>3600</code>, but I dialed it back to <code>1800</code> because of this problem. It helped a bit, but <code>3600</code> <em>should</em> be fine according to the docs. The errors still happen semi-regularly. I don't want to lower it too much though and DOS my own database :).</p> <p>Maybe something in my MySQL config is goofy? Not sure where to look exactly.</p> <p>Other relevant details:</p> <pre><code> Python 2.5 Pylons: 0.9.6.2 (w/ sql_alchemy) MySQL: 5.0.51 </code></pre>
<p>I think I fixed it. It's turns out I had a simple config error. My ini file read:</p> <pre><code>sqlalchemy.default.url = [connection string here] sqlalchemy.pool_recycle = 1800 </code></pre> <p>The problem is that my <code>environment.py</code> file declared that the engine would only map keys with the prefix: <code>sqlalchemy.default</code> so <code>pool_recycle</code> was ignored.</p> <p>The solution is to simply change the second line in the ini to:</p> <pre><code>sqlalchemy.default.pool_recycle = 1800 </code></pre>
<p>You might want to check MySQL's timeout variables:</p> <pre><code>show variables like '%timeout%'; </code></pre> <p>You're probably interested in <code>wait_timeout</code> (less likely but possible: <code>interactive_timeout</code>). On Debian and Ubuntu, the defaults are 28800 (MySQL kills connections after 8 hours), but maybe the default for your platform is different or whoever administrates the server has configured things differently.</p> <p>AFAICT, <code>pool_recycle</code> doesn't actually keep the connections alive, it expires them on its own before MySQL kills them. I'm not familiar with pylons, but if causing the connections to intermittently do a <code>SELECT 1;</code> is an option, that will keep them alive at the cost of basically no server load and minimal network traffic. One final thought: are you somehow managing to use a connection that pylons thinks it has expired?</p>
2,965
<p>The Compact Framework doesn't support Assembly.GetEntryAssembly to determine the launching .exe. So is there another way to get the name of the executing .exe?</p> <p>EDIT: I found the answer on Peter Foot's blog: <a href="http://peterfoot.net/default.aspx" rel="nofollow noreferrer">http://peterfoot.net/default.aspx</a> Here is the code:</p> <pre><code>byte[] buffer = new byte[MAX_PATH * 2]; int chars = GetModuleFileName(IntPtr.Zero, buffer, MAX_PATH); if (chars &gt; 0) { string assemblyPath = System.Text.Encoding.Unicode.GetString(buffer, 0, chars * 2); } [DllImport("coredll.dll", SetLastError = true)] private static extern int GetModuleFileName(IntPtr hModule, byte[] lpFilename, int nSize); </code></pre>
<p>I am not sure whether it works from managed code (or even the compact framework), but in Win32 you can call GetModuleFileName to find the running exe file.</p> <p><a href="http://msdn.microsoft.com/en-us/library/ms683197(VS.85).aspx" rel="nofollow noreferrer">MSDN: GetModuleFileName</a></p>
<p>In managed code, i think you can use this: <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.application.executablepath.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/system.windows.forms.application.executablepath.aspx</a></p> <p>Application.ExecutablePath</p>
4,554
<p>Is it possible to use a flash document embedded in HTML as a link?</p> <p>I tried just wrapping the <code>object</code> element with an <code>a</code> like this:</p> <pre><code>&lt;a href="http://whatever.com"&gt; &lt;object ...&gt; &lt;embed ... /&gt; &lt;/object&gt; &lt;/a&gt; </code></pre> <p>In Internet Explorer, that made it show the location in the status bar like a link, but it doesn't do anything.</p> <p>I just have the .swf file, so I can't add a click handler in ActionScript.</p>
<p>Though the object really should respond to being wrapped in an a href tag, you could open the swf in vim and just throw in an <code>_root.onPress=function(){getURL("http://yes.no/");};</code> or if it's AS3, something like <code>_root.addEventHandler(MouseEvent.PRESS, function (e:event) {getURL("http://yes.no/");});</code> But if editing the swf is your route, you'd likely have more success with <a href="http://www.buraks.com/uae/1.html" rel="nofollow noreferrer">a tool for the purpose</a>.</p>
<p>As an addition to dlamblin's answer it is often best to use the clickTAG technique to open URLS from a flash movie.</p> <p>More information can be found here:</p> <p><a href="http://www.adobe.com/resources/richmedia/tracking/designers_guide/" rel="nofollow noreferrer">http://www.adobe.com/resources/richmedia/tracking/designers_guide/</a></p> <p>The advantage of using the clickTAG technique is that you can set the URL to jump to in the HTML page.</p> <p>This means that you can set the flash movie to link to different places without modifying the flash file (beyond adding the initial clickTAG code). You can use link tracking on the URL as well.</p>
5,350
<p>I have a site I made really fast that uses floats to display different sections of content. The floated content and the content that has an additional margin both appear fine in FF/IE, but on safari one of the divs is completely hidden. I've tried switching to <code>padding</code> and <code>position:relative</code>, but nothing has worked for me. If I take out the code to display it to the right it shows up again but under the floated content.</p> <p>The main section of css that seems to be causing the problem is:</p> <pre class="lang-css prettyprint-override"><code>#settings{ float:left; } #right_content{ margin-top:20px; margin-left:440px; width:400px; } </code></pre> <p>This gives me the same result whether I specify a size to the #settings div or not. Any ideas would be appreciated.</p> <p>The site is available at: <a href="http://frickinsweet.com/tools/Theme.mvc.aspx" rel="nofollow noreferrer">http://frickinsweet.com/tools/Theme.mvc.aspx</a> to see the source code.</p>
<p>I believe the error lies in the mark up that the color picker is generating. I saved the page and removed that code for the color picker and it renders fine in IE/FF/SF. </p>
<p>Sorry I should have mentioned that as well. I tried floating that content right and additionally tried floating it left and setting the position with the thinking that both divs would start out at left:0 where setting the margin of the right would move it over.</p> <p>Thanks</p>
7,300
<p>How do I determine the (local-) path for the "Program Files" directory on a remote computer? There does not appear to any version of SHGetFolderPath (or related function) that takes the name of a remote computer as a parameter.</p> <p>I guess I could try to query HKLM\Software\Microsoft\Windows\CurrentVersion\ProgramFilesDir using remote-registry, but I was hoping there would be "documented" way of doing it.</p>
<p>Those are all slightly different, and generally have an acceptable usage.</p> <ul> <li><code>var.</code><a href="http://msdn.microsoft.com/en-us/library/system.object.tostring.aspx" rel="noreferrer"><code>ToString</code></a><code>()</code> is going to give you the string representation of an object, regardless of what type it is. Use this if <code>var</code> is not a string already.</li> <li><a href="http://msdn.microsoft.com/en-us/library/0zk841e9.aspx" rel="noreferrer"><code>CStr</code></a><code>(var)</code> is the VB string cast operator. I'm not a VB guy, so I would suggest avoiding it, but it's not really going to hurt anything. I think it is basically the same as <code>CType</code>.</li> <li><a href="http://msdn.microsoft.com/en-us/library/4x2877xb.aspx" rel="noreferrer"><code>CType</code></a><code>(var, String)</code> will convert the given type into a string, using any provided conversion operators.</li> <li><a href="http://msdn.microsoft.com/en-us/library/7k6y2h6x.aspx" rel="noreferrer"><code>DirectCast</code></a><code>(var, String)</code> is used to up-cast an object into a string. If you know that an object variable is, in fact, a string, use this. This is the same as <code>(string)var</code> in C#.</li> <li><a href="http://msdn.microsoft.com/en-us/library/zyy863x8.aspx" rel="noreferrer"><code>TryCast</code></a> (as mentioned by @<a href="https://stackoverflow.com/questions/40764/how-should-i-cast-in-vbnet#40771">NotMyself</a>) is like <code>DirectCast</code>, but it will return <code>Nothing</code> if the variable can't be converted into a string, rather than throwing an exception. This is the same as <code>var as string</code> in C#. The <code>TryCast</code> page on MSDN has a good comparison, too.</li> </ul>
<p>At one time, I remember seeing the MSDN library state to use CStr() because it was faster. I do not know if this is true though.</p>
6,204
<p>My company has a number of relatively small Access databases (2-5MB) that control our user assisted design tools. Naturally these databases evolve over time as data bugs are found and fixed and as the schema changes to support new features in the tools. Can anyone recommend a database diff tool to compare both the data and schema from one version of the database to the next? Any suggestions will be appreciated: free, open source, or commercial.</p>
<p>I use Red Gate Sql Compare for comparing schemas. It also has an interesting feature that allows you to save a snapshot of the schema which you can then use in later diffs. for example compare the schema of today with the schema of a month ago.</p>
<p>We never actually purchased it as we ended up using SQL Server 2005, but DBDiff seemed to do the trick: <a href="http://www.dkgas.com/downdbdiff.cgi" rel="nofollow noreferrer">http://www.dkgas.com/downdbdiff.cgi</a></p> <p>It works with any ODBC compatible DB.</p>
4,801
<p>So I'm been pounding on this problem all day. I've got a LinqDataSource that points to my model and a GridView that consumes it. When I attempt to do an update on the GridView, it does not update the underlying data source. I thought it might have to do with the LinqDataSource, so I added a SqlDataSource and the same thing happens. The aspx is as follows (the code-behind page is empty):</p> <pre><code> &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Data Source=devsql32;Initial Catalog=Steam;Persist Security Info=True;" ProviderName="System.Data.SqlClient" SelectCommand="SELECT [LangID], [Code], [Name] FROM [Languages]" UpdateCommand="UPDATE [Languages] SET [Code]=@Code WHERE [LangID]=@LangId"&gt; &lt;/asp:SqlDataSource&gt; &lt;asp:GridView ID="_languageGridView" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="LangId" DataSourceID="SqlDataSource1"&gt; &lt;Columns&gt; &lt;asp:CommandField ShowDeleteButton="True" ShowEditButton="True" /&gt; &lt;asp:BoundField DataField="LangId" HeaderText="Id" ReadOnly="True" /&gt; &lt;asp:BoundField DataField="Code" HeaderText="Code" /&gt; &lt;asp:BoundField DataField="Name" HeaderText="Name" /&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; &lt;asp:LinqDataSource ID="_languageDataSource" ContextTypeName="GeneseeSurvey.SteamDatabaseDataContext" runat="server" TableName="Languages" EnableInsert="True" EnableUpdate="true" EnableDelete="true"&gt; &lt;/asp:LinqDataSource&gt; </code></pre> <p>What in the world am I missing here? This problem is driving me insane.</p>
<p>You are missing the &lt;UpdateParameters&gt; sections of your DataSources.</p> <p><a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.linqdatasource.updateparameters.aspx" rel="nofollow noreferrer">LinqDataSource.UpdateParameters</a></p> <p><a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.updateparameters.aspx" rel="nofollow noreferrer">SqlDataSource.UpdateParameters</a></p>
<p>This is a total shot in the dark since I haven't used ASP at all.</p> <p>I've been just learning XAML and WPF, which appears to be very similar to what you've posted above and I know that for some UI controls you need to specify the binding mode to two-way in order to get updates in both directions.</p>
7,587
<p>In other words, is this Singleton implementation thread safe:</p> <pre><code>public class Singleton { private static Singleton instance; private Singleton() { } static Singleton() { instance = new Singleton(); } public static Singleton Instance { get { return instance; } } } </code></pre>
<p>Static constructors are guaranteed to be run only once per application domain, before any instances of a class are created or any static members are accessed. <a href="https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/static-constructors" rel="noreferrer">https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/static-constructors</a></p> <p>The implementation shown is thread safe for the initial construction, that is, no locking or null testing is required for constructing the Singleton object. However, this does not mean that any use of the instance will be synchronised. There are a variety of ways that this can be done; I've shown one below.</p> <pre><code>public class Singleton { private static Singleton instance; // Added a static mutex for synchronising use of instance. private static System.Threading.Mutex mutex; private Singleton() { } static Singleton() { instance = new Singleton(); mutex = new System.Threading.Mutex(); } public static Singleton Acquire() { mutex.WaitOne(); return instance; } // Each call to Acquire() requires a call to Release() public static void Release() { mutex.ReleaseMutex(); } } </code></pre>
<p>The static constructor is locked. While the type initializer is running, any other thread which attempts to access the class in such a way that would trigger the type initializer will block.</p> <p>However, the thread which is running the type initializer can access uninitialized static members. So be sure not to call <code>Monitor.Enter()</code> (<code>lock(){}</code>) or <code>ManualResetEventSlim.Wait()</code> from a type initializer if it is run from a UI thread—those are <a href="https://learn.microsoft.com/en-us/dotnet/standard/threading/managed-and-unmanaged-threading-in-windows#blocking-issues" rel="nofollow noreferrer">“interruptible” waits which result in the event loop running</a>, executing arbitrary other parts of your program while your type initializer is still unfinished.</p> <blockquote> <p>It is preferable for you to use managed blocking rather than unmanaged blocking. <a href="https://learn.microsoft.com/en-us/dotnet/api/system.threading.waithandle.waitone" rel="nofollow noreferrer"><code>WaitHandle.WaitOne</code></a>, <a href="https://learn.microsoft.com/en-us/dotnet/api/system.threading.waithandle.waitany" rel="nofollow noreferrer"><code>WaitHandle.WaitAny</code></a>, <a href="https://learn.microsoft.com/en-us/dotnet/api/system.threading.waithandle.waitall" rel="nofollow noreferrer"><code>WaitHandle.WaitAll</code></a>, <a href="https://learn.microsoft.com/en-us/dotnet/api/system.threading.monitor.enter" rel="nofollow noreferrer"><code>Monitor.Enter</code></a>, <a href="https://learn.microsoft.com/en-us/dotnet/api/system.threading.monitor.tryenter" rel="nofollow noreferrer"><code>Monitor.TryEnter</code></a>, <a href="https://learn.microsoft.com/en-us/dotnet/api/system.threading.thread.join" rel="nofollow noreferrer"><code>Thread.Join</code></a>, <a href="https://learn.microsoft.com/en-us/dotnet/api/system.gc.waitforpendingfinalizers" rel="nofollow noreferrer"><code>GC.WaitForPendingFinalizers</code></a>, and so on are all responsive to <a href="https://learn.microsoft.com/en-us/dotnet/api/system.threading.thread.interrupt" rel="nofollow noreferrer"><code>Thread.Interrupt</code></a> and to <a href="https://learn.microsoft.com/en-us/dotnet/api/system.threading.thread.abort" rel="nofollow noreferrer"><code>Thread.Abort</code></a>. Also, if your thread is in a single-threaded apartment, all these managed blocking operations will correctly pump messages in your apartment while your thread is blocked:</p> </blockquote>
2,874
<p>I have a Flex <code>ComboBox</code> that gets populated by a <code>dataprovider</code> all is well...</p> <p>I would now like to add a default " -- select a item --" option at the 0 index, how can I do this and still use a <code>dataprovider</code>? I have not seen any examples of such, but I can't imagine this being hard...</p>
<p>If you don't need the default item to be selectable you can use the <code>prompt</code> property of <code>ComboBox</code> and set the <code>selectedIndex</code> to -1. That will show the string you set <code>propmt</code> to as the selected value until the user chooses another. It will not appear in the list of options, however.</p>
<p>This can be used following code for selected default value of combobox</p> <pre><code>var index:String = "foo"; for(var objIndex:int = 0; objIndex &lt; comboBox.dataProvider.length; objIndex++) { if(comboBox.dataProvider[objIndex].label == index) { comboBox.selectedIndex = objIndex; break; } } &lt;mx:ComboBox id="comboBox" dataProvider="{_pageIndexArray}" /&gt; </code></pre>
5,566
<p>I have been trying to find a really fast way to parse yyyy-mm-dd [hh:mm:ss] into a Date object. Here are the 3 ways I have tried doing it and the times it takes each method to parse 50,000 date time strings.</p> <p>Does anyone know any faster ways of doing this or tips to speed up the methods?</p> <pre><code>castMethod1 takes 3673 ms castMethod2 takes 3812 ms castMethod3 takes 3931 ms </code></pre> <p>Code:</p> <pre><code>private function castMethod1(dateString:String):Date { if ( dateString == null ) { return null; } var year:int = int(dateString.substr(0,4)); var month:int = int(dateString.substr(5,2))-1; var day:int = int(dateString.substr(8,2)); if ( year == 0 &amp;&amp; month == 0 &amp;&amp; day == 0 ) { return null; } if ( dateString.length == 10 ) { return new Date(year, month, day); } var hour:int = int(dateString.substr(11,2)); var minute:int = int(dateString.substr(14,2)); var second:int = int(dateString.substr(17,2)); return new Date(year, month, day, hour, minute, second); } </code></pre> <p>-</p> <pre><code>private function castMethod2(dateString:String):Date { if ( dateString == null ) { return null; } if ( dateString.indexOf("0000-00-00") != -1 ) { return null; } dateString = dateString.split("-").join("/"); return new Date(Date.parse( dateString )); } </code></pre> <p>-</p> <pre><code>private function castMethod3(dateString:String):Date { if ( dateString == null ) { return null; } var mainParts:Array = dateString.split(" "); var dateParts:Array = mainParts[0].split("-"); if ( Number(dateParts[0])+Number(dateParts[1])+Number(dateParts[2]) == 0 ) { return null; } return new Date( Date.parse( dateParts.join("/")+(mainParts[1]?" "+mainParts[1]:" ") ) ); } </code></pre> <hr> <p>No, Date.parse will not handle dashes by default. And I need to return null for date time strings like <code>"0000-00-00"</code>.</p>
<p>I've been using the following snipplet to parse UTC date strings:</p> <pre><code>private function parseUTCDate( str : String ) : Date { var matches : Array = str.match(/(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)Z/); var d : Date = new Date(); d.setUTCFullYear(int(matches[1]), int(matches[2]) - 1, int(matches[3])); d.setUTCHours(int(matches[4]), int(matches[5]), int(matches[6]), 0); return d; } </code></pre> <p>Just remove the time part and it should work fine for your needs:</p> <pre><code>private function parseDate( str : String ) : Date { var matches : Array = str.match(/(\d\d\d\d)-(\d\d)-(\d\d)/); var d : Date = new Date(); d.setUTCFullYear(int(matches[1]), int(matches[2]) - 1, int(matches[3])); return d; } </code></pre> <p><strike>No idea about the speed, I haven't been worried about that in my applications.</strike> 50K iterations in significantly less than a second on my machine.</p>
<p>Here is my implementation. Give this a try.</p> <pre><code>public static function dateToUtcTime(date:Date):String { var tmp:Array = new Array(); var char:String; var output:String = ''; // create format YYMMDDhhmmssZ // ensure 2 digits are used for each format entry, so 0x00 suffuxed at each byte tmp.push(date.secondsUTC); tmp.push(date.minutesUTC); tmp.push(date.hoursUTC); tmp.push(date.getUTCDate()); tmp.push(date.getUTCMonth() + 1); // months 0-11 tmp.push(date.getUTCFullYear() % 100); for(var i:int=0; i &lt; 6/* 7 items pushed*/; ++i) { char = String(tmp.pop()); trace("char: " + char); if(char.length &lt; 2) output += "0"; output += char; } output += 'Z'; return output; } </code></pre>
2,534
<p>Is there any easy/general way to clean an XML based data source prior to using it in an XmlReader so that I can gracefully consume XML data that is non-conformant to the hexadecimal character restrictions placed on XML?</p> <p>Note: </p> <ul> <li>The solution needs to handle XML data sources that use character encodings other than UTF-8, e.g. by specifying the character encoding at the XML document declaration. Not mangling the character encoding of the source while stripping invalid hexadecimal characters has been a major sticking point.</li> <li>The removal of invalid hexadecimal characters should only remove hexadecimal encoded values, as you can often find href values in data that happens to contains a string that would be a string match for a hexadecimal character.</li> </ul> <p><em>Background:</em></p> <p>I need to consume an XML-based data source that conforms to a specific format (think Atom or RSS feeds), but want to be able to consume data sources that have been published which contain invalid hexadecimal characters per the XML specification.</p> <p>In .NET if you have a Stream that represents the XML data source, and then attempt to parse it using an XmlReader and/or XPathDocument, an exception is raised due to the inclusion of invalid hexadecimal characters in the XML data. My current attempt to resolve this issue is to parse the Stream as a string and use a regular expression to remove and/or replace the invalid hexadecimal characters, but I am looking for a more performant solution.</p>
<p>It <strong>may not be perfect</strong> (emphasis added since people missing this disclaimer), but what I've done in that case is below. You can adjust to use with a stream.</p> <pre><code>/// &lt;summary&gt; /// Removes control characters and other non-UTF-8 characters /// &lt;/summary&gt; /// &lt;param name="inString"&gt;The string to process&lt;/param&gt; /// &lt;returns&gt;A string with no control characters or entities above 0x00FD&lt;/returns&gt; public static string RemoveTroublesomeCharacters(string inString) { if (inString == null) return null; StringBuilder newString = new StringBuilder(); char ch; for (int i = 0; i &lt; inString.Length; i++) { ch = inString[i]; // remove any characters outside the valid UTF-8 range as well as all control characters // except tabs and new lines //if ((ch &lt; 0x00FD &amp;&amp; ch &gt; 0x001F) || ch == '\t' || ch == '\n' || ch == '\r') //if using .NET version prior to 4, use above logic if (XmlConvert.IsXmlChar(ch)) //this method is new in .NET 4 { newString.Append(ch); } } return newString.ToString(); } </code></pre>
<pre><code>private static String removeNonUtf8CompliantCharacters( final String inString ) { if (null == inString ) return null; byte[] byteArr = inString.getBytes(); for ( int i=0; i &lt; byteArr.length; i++ ) { byte ch= byteArr[i]; // remove any characters outside the valid UTF-8 range as well as all control characters // except tabs and new lines if ( !( (ch &gt; 31 &amp;&amp; ch &lt; 253 ) || ch == '\t' || ch == '\n' || ch == '\r') ) { byteArr[i]=' '; } } return new String( byteArr ); } </code></pre>
4,109
<p>I would like to debug an embedded system containing gdb remotely using some kind of gui (ie like ddd). The embedded system does not have the sources or build symbols. However my local x windows box has. However the execution must happen on the embedded system. How can I from my development box drive gdb remotely with some gui ? </p> <p>leds and jtag are not an option. </p>
<p>I think, gdbserver could help you.</p>
<p>On Remote target:</p> <pre><code>target&gt; gdbserver localhost:1234 &lt;application&gt; </code></pre> <p>On Host (build machine):</p> <pre><code>host&gt; gdb &lt;application&gt; </code></pre> <p>Note that the on target may be stripped off from the symbols. But host may have all the symbols.</p> <pre><code>gdb&gt; set &lt;path-to-libs-search&gt; gdb&gt; target remote &lt;target-ip&gt;:1234 gdb&gt; break main gdb&gt; cont </code></pre> <p>If this works, get some GDB gui on the host machine and try to replicate the same settings. (I have used SlickEdit and eclipse for this purpose).</p>
9,672
<p>I am looking for easy steps that are simple and effective in making a web application more secure.</p> <p>What are your top tips for secure web applications, and what kind of attack will they stop?</p>
<p>Microsoft Technet has en excellent article:</p> <p><a href="http://technet.microsoft.com/en-us/library/cc512638.aspx" rel="nofollow noreferrer">Ten Tips for Designing, Building, and Deploying More Secure Web Applications</a></p> <p>Here are the topics for the tips answered in that article:</p> <ol> <li>Never Directly Trust User Input</li> <li>Services Should Have Neither System nor Administrator Access</li> <li>Follow SQL Server Best Practices</li> <li>Protect the Assets</li> <li>Include Auditing, Logging, and Reporting Features</li> <li>Analyze the Source Code</li> <li>Deploy Components Using Defense in Depth</li> <li>Turn Off In-Depth Error Messages for End Users</li> <li>Know the <a href="http://technet.microsoft.com/nb-no/library/cc722488(en-us).aspx" rel="nofollow noreferrer">10 Laws of Security Administration</a></li> <li>Have a Security Incident Response Plan</li> </ol>
<p>Set the secure flag on cookies for SSL applications. Otherwise there is always a highjacking attack that is <em>much</em> easier to conduct than breaking the crypto. This is the essence of CVE-2002-1152.</p>
6,953
<p>What is the maximum size for a MySQL table? Is it 2 million at 50GB? 5 million at 80GB?</p> <p>At the higher end of the size scale, do I need to think about compressing the data? Or perhaps splitting the table if it grew too big?</p>
<p>I once worked with a very large (Terabyte+) MySQL database. The largest table we had was literally over a billion rows. </p> <p>It worked. MySQL processed the data correctly most of the time. It was extremely unwieldy though. </p> <p>Just backing up and storing the data was a challenge. It would take days to restore the table if we needed to.</p> <p>We had numerous tables in the 10-100 million row range. Any significant joins to the tables were too time consuming and would take forever. So we wrote stored procedures to 'walk' the tables and process joins against ranges of 'id's. In this way we'd process the data 10-100,000 rows at a time (Join against id's 1-100,000 then 100,001-200,000, etc). This was significantly faster than joining against the entire table.</p> <p>Using indexes on very large tables that aren't based on the primary key is also much more difficult. Mysql stores indexes in two pieces -- it stores indexes (other than the primary index) as indexes to the primary key values. So indexed lookups are done in two parts: First MySQL goes to an index and pulls from it the primary key values that it needs to find, then it does a second lookup on the primary key index to find where those values are. </p> <p>The net of this is that for very large tables (1-200 Million plus rows) indexing against tables is more restrictive. You need fewer, simpler indexes. And doing even simple select statements that are not directly on an index may never come back. Where clauses <em>must</em> hit indexes or forget about it.</p> <p>But all that being said, things did actually work. We were able to use MySQL with these very large tables and do calculations and get answers that were correct.</p>
<p>About your first question, the effective maximum size for the <em>database</em> is usually determined by operating system, specifically the file size MySQL Server will be able to create, not by MySQL Server itself. Those limits play a big role in <em>table</em> size limits. And MyISAM works differently from InnoDB. So any tables will be dependent on those limits.</p> <p>If you use InnoDB you will have more options on manipulating table sizes, resizing the tablespace is an option in this case, so if you plan to resize it, this is the way to go. Give a look at <a href="http://dev.mysql.com/doc/refman/5.0/en/full-table.html" rel="nofollow noreferrer">The table is full</a> error page.</p> <p>I am not sure the real record quantity of each table given all necessary information (OS, Table type, Columns, data type and size of each and etc...) And I am not sure if this info is easy to calculate, but I've seen simple table with around 1bi records in a couple cases and MySQL didn't gave up.</p>
7,110
<p>I have a filename in a format like:</p> <blockquote> <p><code>system-source-yyyymmdd.dat</code></p> </blockquote> <p>I'd like to be able to parse out the different bits of the filename using the "-" as a delimiter.</p>
<p>You can use the <a href="http://en.wikipedia.org/wiki/Cut_(Unix)" rel="noreferrer">cut command</a> to get at each of the 3 'fields', e.g.:</p> <pre><code>$ echo "system-source-yyyymmdd.dat" | cut -d'-' -f2 source </code></pre> <p>"-d" specifies the delimiter, "-f" specifies the number of the field you require</p>
<p>The simplest (and IMO best way) to do this is simply to use <code>read</code>:</p> <pre><code>$ IFS=-. read system source date ext &lt;&lt; EOF &gt; foo-bar-yyyymmdd.dat &gt; EOF $ echo $system foo $ echo $source $date $ext bar yyyymmdd dat </code></pre> <p>There are many variations on that theme, many of which are shell dependent:</p> <p><code>bash$ IFS=-. read system source date ext &lt;&lt;&lt; foo-bar-yyyymmdd.dat</code></p> <pre><code>echo "$name" | { IFS=-. read system source date ext echo In all shells, the variables are set here...; } echo but only in some shells do they retain their value here </code></pre>
7,194
<p>So they say PLA is biodegradable. But I still don't know how much biodegradable.</p> <p>I live in a flat and we have composting trash can in the courtyard. However if I throw PLA in there and it does not decompose, neighbors are gonna be pissed since many of them are intending to use the soil for their balcony flowers.</p> <p>So can I really compost PLA, or does "biodegradable" just mean it falls apart <em>eventually</em>, eg. in years? And <strong>if</strong> it decomposes, is it safe to use for plants?</p>
<p>This question has been asked on just about every forum out there. Here's one example from <a href="https://www.filabot.com/blogs/news/57233604-the-misleading-biodegradability-of-pla" rel="nofollow noreferrer">filabot.com</a> .</p> <blockquote> <p>The reality however, is that this process will take several hundred years in a typical landfill. To biodegrade, PLA requires a laundry list of conditions to effectively break down. Specifically - oxygen, a temperature of 140+ degrees <em>[Fahrenheit -- ed note]</em>, and a 2/3 cocktail of organic substrate. Collectively, these are absent in any scenario outside of industrial composting facilities.</p> </blockquote> <p>I found similar comments -- tho' with perhaps slightly lower temperatures elsewhere.</p>
<p>PLA products will take up to 6 months to degrade in commercial composting facility. In home composting facility, it may take longer time.</p> <p>Source: <a href="http://www.biogreenchoice.com/category_s/1866.htm" rel="nofollow noreferrer">http://www.biogreenchoice.com/category_s/1866.htm</a></p>
524
<p>Courses for people who are being introduced to programming very often include a code project, which I think is a nice way to learn. However, such projects often feel too artificial, and are thus not very rewarding to work on.</p> <p>What are your ideas of rewarding code projects? (Preferably easy to begin, and extendable at will for the more advanced!).</p> <p>Edit:</p> <p>@Mark: thanks for the link, though I'm more interested in projects for people who are completely new to programming (the link seems to refer more to people who are already proficient in at least one language, and trying to learn a new one -the typical SO audience I'd say :) -).</p> <p>@Kevin, Vaibhav, gary: I was thinking of people who are learning programming through one language, so at the beginning of the course some don't know anything about control structures (and even less about any kind of syntax). However, I was thinking in quite a large project (typically in the 1k-10k lines of code range, possibly in groups of 2 or 3 students). This is what was done at my school for the complete beginners, and it sure seemed to work for them... except that most of them found their projects quite boring to work on!</p>
<p>As has been stated a few times, what you are trying to teach the beginner is very important to the project.</p> <p>My advice to you for planning something like this:</p> <p>1) Avoid making a computer game</p> <p>A computer game, while fun to build, doesn't reward the programmer with results early on (it's very complex). You want to concentrate on small but useful application programs, such as a <a href="http://www.stromcode.com/2008/03/01/cwin32-tutorials/" rel="nofollow noreferrer">Port Scanner</a>. The example there is a little complex, but it's one of the best learning projects I've seen on the web.</p> <p>2) Teach graphics early</p> <p>It's rewarding to see the fruits of your labors early on, and it motivates you to go further. Whether you're using WinForms, MFC or the Win32 API, OpenGL or DirectX, teach it early.</p> <p>3) Many small lessons with in depth information</p> <p>This principle is followed by the above linked Port Scanner project, and it works well. Teach each part thoroughly, and give time for the beginner to absorb the lesson. I think that <a href="http://zophusx.byethost11.com" rel="nofollow noreferrer">ZophusX</a> had a good format for giving the information. It's too bad he's mostly abandoned his site.</p> <p>4) It takes time</p> <p>Don't rush things. Nobody becomes a stellar programmer in a few weeks. Try and make the lessons simple, but engaging, and keep building from your previous lessons.</p> <p>5) Get feedback early and often</p> <p>You might think a project is incredibly interesting, or a particular lesson or such, but you aren't the one learning. Your student(s) will greatly appreciate it when you ask them early on how things are going, and what they'd like to know more about. Be flexible enough that you can accomodate some of those requests.</p> <p>6) Have fun teaching</p> <p>Have fun. Passion is contagious, and if your student(s) see how much you enjoy the subject matter, some of that enthusiasm will rub off on them as well.</p> <p>I hope that helps!</p>
<p>It really depends on what you're trying to teach the beginner. If you're trying to teach syntax, then simple "Hello World" programs and ones that spit out every odd number between 1 and 100 are fine to get them started. If you're trying to teach data structures, then maybe something like a 20 questions game or some simple sorting program. If you're trying to teach recursion, then maybe a breadth first search program. If you're trying to teach database manipulation, then something like a order tracking system would be appropriate.</p>
4,635
<p>I'm working on a spec for a piece of software for my company and as part of the auditing system I think it would be neat if there was a way to grab the current Active Directory user.</p> <p>Hopefully something like:</p> <pre><code>Dim strUser as String strUser = ActiveDirectory.User() MsgBox "Welcome back, " &amp; strUser </code></pre>
<p><a href="http://bytes.com/forum/thread717576.html" rel="nofollow noreferrer">Try this article</a> - I have some code at work that will erm, work if this doesn't...</p> <p>Relevant quote:</p> <blockquote> <pre class="lang-vba prettyprint-override"><code>Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" _ (ByVal IpBuffer As String, nSize As Long) As Long Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" _ (ByVal lpBuffer As String, nSize As Long) As Long Function ThisUserName() As String Dim LngBufLen As Long Dim strUser As String strUser = String$(15, " ") LngBufLen = 15 If GetUserName(strUser, LngBufLen) = 1 Then ThisUserName = Left(strUser, LngBufLen - 1) Else ThisUserName = "Unknown" End If End Function Function ThisComputerID() As String Dim LngBufLen As Long Dim strUser As String strUser = String$(15, " ") LngBufLen = 15 If GetComputerName(strUser, LngBufLen) = 1 Then ThisComputerID = Left(strUser, LngBufLen) Else ThisComputerID = 0 End If End Function </code></pre> </blockquote>
<p>Depending on environment variables to remain valid is a bad idea, since they can easily be changed within a user session.</p>
3,054
<p>I'm reading some MPEG Transport Stream protocol over UDP and it has some funky bitfields in it (length 13 for example). I'm using the "struct" library to do the broad unpacking, but is there a simple way to say "Grab the next 13 bits" rather than have to hand-tweak the bit manipulation? I'd like something like the way C does bit fields (without having to revert to C).</p> <p>Suggestions?</p>
<p>The <a href="https://github.com/scott-griffiths/bitstring" rel="nofollow noreferrer">bitstring</a> module is designed to address just this problem. It will let you read, modify and construct data using bits as the basic building blocks. The latest versions are for Python 2.6 or later (including Python 3) but version 1.0 supported Python 2.4 and 2.5 as well.</p> <p>A relevant example for you might be this, which strips out all the null packets from a transport stream (and quite possibly uses your 13 bit field?):</p> <pre><code>from bitstring import Bits, BitStream # Opening from a file means that it won't be all read into memory s = Bits(filename='test.ts') outfile = open('test_nonull.ts', 'wb') # Cut the stream into 188 byte packets for packet in s.cut(188*8): # Take a 13 bit slice and interpret as an unsigned integer PID = packet[11:24].uint # Write out the packet if the PID doesn't indicate a 'null' packet if PID != 8191: # The 'bytes' property converts back to a string. outfile.write(packet.bytes) </code></pre> <p>Here's another example including reading from bitstreams: </p> <pre><code># You can create from hex, binary, integers, strings, floats, files... # This has a hex code followed by two 12 bit integers s = BitStream('0x000001b3, uint:12=352, uint:12=288') # Append some other bits s += '0b11001, 0xff, int:5=-3' # read back as 32 bits of hex, then two 12 bit unsigned integers start_code, width, height = s.readlist('hex:32, 2*uint:12') # Skip some bits then peek at next bit value s.pos += 4 if s.peek(1): flags = s.read(9) </code></pre> <p>You can use standard slice notation to slice, delete, reverse, overwrite, etc. at the bit level, and there are bit level find, replace, split etc. functions. Different endiannesses are also supported.</p> <pre><code># Replace every '1' bit by 3 bits s.replace('0b1', '0b001') # Find all occurrences of a bit sequence bitposlist = list(s.findall('0b01000')) # Reverse bits in place s.reverse() </code></pre> <p>The full documentation is <a href="https://bitstring.readthedocs.io/en/latest/" rel="nofollow noreferrer">here</a>.</p>
<p>It's an often-asked question. There's an <a href="http://code.activestate.com/recipes/113799/" rel="noreferrer">ASPN Cookbook</a> entry on it that has served me in the past.</p> <p>And there is an <a href="http://wiki.python.org/moin/BitManipulation" rel="noreferrer">extensive page of requirements one person would like to see from a module doing this.</a></p>
6,078
<p>I finally manage to setup the ABL on my Prusa. I run G28 to home all axes (for z I use the same probe used for ABL). Then I run G29 E ( I use E because otherwise for some reason I have not understood yet, Z does not lift during probings) probing 4 points on the corners of the bed.</p> <p>finally I get the map of the bed:</p> <pre><code>Bed Level Correction Matrix: +0.999999 +0.000000 +0.001233 -0.000005 +0.999992 +0.003905 -0.001233 -0.003905 +0.999992 </code></pre> <p>and after that, the print starts. The first layer looks perfect however I have not seen Z moving a single step along the printing.</p> <p>Any hint about what to check? Is the obtained map indicating that the bed is already too leveled to act on any compensation?</p> <p><strong>UPDATE</strong> I printed a 180 mm diamater cylinder and the Z axis is not compensating the 1mm difference from edge to edge of the bed.</p>
<p>I found the issue. As I mentioned in my question UPDATE, trying to print something that cover the full bed, the ABL was not working. The issue was the Gcode I added after the G29. In fact for some reason I added a G28 X0 after the G29 and that basically cancel the data acquired in the G29. I learned something new, do not use G28 after G29!</p> <p>Now it is working nicely.</p>
<p>I believe that the matrix is shown transposed from how it should be, but that doesn't affect the answer. The compensated Z position is derived from the original <code>(X,Y,Z)</code> position by multiplying the corresponding vector with that matrix. This means that the new Z position would be</p> <pre><code>Z' = 0.999992Z - 0.001233X - 0.003905Y </code></pre> <p>If you have a 200 x 200 printbed, a diagonal move from one corner to the other would correspond to a 1mm change in Z-height. This should be noticeable, but if perhaps you're printing something quite small you might not notice it.</p> <p>Though, if your first layer is perfect, I would see no reason to mess with it.</p>
423
<p>What are some of the best or most popular rule engines? I haven't settled on a programming language, so tell me the rule engine and what programming languages it supports.</p>
<p>I am one of the authors of Drools, I will avoid pimping my wares. </p> <p>But some other options are Jess (not open source) but uses the clips syntax (which we also support a subset of) - which is kinda a lisp dialect. </p> <p>It really depends what you want it for, Haley have strong Natural language tech (and they recently aquired RuleBurst - who has also interesting natural language tech which could deal with word documents with embedded rules - eg legal documentation). RuleBurst was able to target .Net runtimes as well (there is a Drools.net "port" available as well - I haven't seen what it has been up to lately, alas, not enough time). Ok I will put my pimp bling away now... sorry about that. </p>
<p>WF is available already in .net 3.0. It is a bit buggy though on the Designer-side in Visual Studio and can get quite messy. I use it on Sharepoint (where WF is pretty much your only option anyway) and overall I am quite satisfied with it, even though the learning curve is rather steep.</p> <p><a href="http://www.apress.com/book/view/1590597184" rel="nofollow noreferrer">Foundations of WF</a> is a good book to start with it, as they implement a complete solution from beginning to the end and explain the concepts behind it.</p>
2,833
<p>The situation: I have a pieceofcrapuous laptop. One of the things that make it pieceofcrapuous is that the battery is dead, and the power cable pulls out of the back with little effort.</p> <p>I recently received a non-pieceofcrapuous laptop, and I am in the process of copying everything from old to new. I'm trying to xcopy c:*.* from the old machine to an external hard drive, but because the cord pulls out so frequently, the xcopy is interrupted fairly often.</p> <p>What I need is a switch in XCopy that will copy eveything except for files that already exist in the destination folder -- the exact opposite of the behavior of the /U switch. </p> <p>Does anyone know of a way to do this? </p>
<p>I find RoboCopy is a good alternative to xcopy. It supports high latency connections much better and supports resuming a copy.</p> <h3>References</h3> <p><a href="http://en.wikipedia.org/wiki/Robocopy" rel="noreferrer">Wikipedia - robocopy</a></p> <h3>Downloads</h3> <p><strong>Edit</strong> Robocopy was introduced as a standard feature of Windows Vista and Windows Server 2008.</p> <ul> <li><p>Robocopy is shipped as part of the Windows Server 2003 resource kit and can be download from the <a href="http://www.microsoft.com/downloads/details.aspx?familyid=9d467a69-57ff-4ae7-96ee-b18c4790cffd&amp;displaylang=en" rel="noreferrer">Microsoft download site</a>.</p></li> <li><p>A very simple GUI has also been release for RoboCopy on technet <a href="http://technet.microsoft.com/en-us/magazine/cc160891.aspx" rel="noreferrer">http://technet.microsoft.com/en-us/magazine/cc160891.aspx</a></p></li> </ul>
<p>I would suggest using <a href="http://optics.ph.unimelb.edu.au/help/rsync/rsync_pc1.html" rel="nofollow noreferrer">rsync</a>, several ports are available, but <a href="http://www.itefix.no/i2/node/10650" rel="nofollow noreferrer">cwrsync</a> seems to work nicely on Windows.</p>
8,312
<p>So when my Prusa I3 is heating up, a small bit of filament is coming out of the nozzle, forming a small string at.</p> <p>When the printing starts, this results in a small plastic ball on the bed, impacting the overall printing process.</p> <p>How can I avoid this?</p>
<p>On my Kossel Mini I programmed it to go to the edge of the bed and purge a small amount of filament which creates a dot. I purge enough to get the dot to stick to the bed and then go on with printing, when the head moves the dot stays attached and usually pulls excess material off the nozzle. This can be added to the "Starting G-Code" section of your slicer.</p>
<p>I just go and pull it off the print head with pliers when it's about to start and sometimes shortly after it starts printing, but its probably not the safest way to deal with the problem. Printing a skirt, brim, or raft should help to fix the problem.</p>
574
<p>We have a service that has some settings that are supported only over net.tcp. What's the best way to add another endpoint? Do I need to create an entire new host?</p>
<p>A service may have multiple endpoints within a single host, but every endpoint must have a unique combination of address, binding and contract. For an IIS-hosted service (that is, an .SVC file), just set the address of the endpoint to a <strong>relative</strong> URI and make sure that your Visual Studio or wsdl.exe generated client specifies the endpoint's name in its constructor.</p> <p>See also the MSDN article <em><a href="http://msdn.microsoft.com/en-us/library/ms751515.aspx" rel="nofollow noreferrer">Multiple Endpoints</a></em>.</p>
<p>You will need to create an entire new host if you are currently using IIS as your host - IIS only supports HTTP and not TCP bindings. If however you are using WAS or a windows service, then you'll be able to get away with simply creating a new net.tcp endpoint.</p>
6,836
<p>I'd like to provide some way of creating dynamically loadable plugins in my software. Typical way to do this is using the <a href="http://msdn.microsoft.com/en-us/library/ms684175(VS.85).aspx" rel="noreferrer">LoadLibrary</a> WinAPI function to load a dll and calling <a href="http://msdn.microsoft.com/en-us/library/ms683212(VS.85).aspx" rel="noreferrer">GetProcAddress</a> to get an pointer to a function inside that dll.</p> <p>My question is how do I dynamically load a plugin in C#/.Net application?</p>
<p>The following code snippet (C#) constructs an instance of any concrete classes derived from <code>Base</code> found in class libraries (*.dll) in the application path and stores them in a list.</p> <pre><code>using System.IO; using System.Reflection; List&lt;Base&gt; objects = new List&lt;Base&gt;(); DirectoryInfo dir = new DirectoryInfo(Application.StartupPath); foreach (FileInfo file in dir.GetFiles("*.dll")) { Assembly assembly = Assembly.LoadFrom(file.FullName); foreach (Type type in assembly.GetTypes()) { if (type.IsSubclassOf(typeof(Base)) &amp;&amp; type.IsAbstract == false) { Base b = type.InvokeMember(null, BindingFlags.CreateInstance, null, null, null) as Base; objects.Add(b); } } } </code></pre> <p><strong>Edit:</strong> The classes referred to by <a href="https://stackoverflow.com/questions/14278/how-to-load-plugins-in-net#14305">Matt</a> are probably a better option in .NET 3.5.</p>
<p>This is my implementation, Inspired in <a href="https://www.codeproject.com/Tips/546639/How-to-create-an-easy-plugin-system-in-Csharp" rel="nofollow noreferrer">this code</a> avoiding to iterate over all assemblies and all types (or at least filtering with linQ). I just load the library and try to load the class which implemets a common shared interface. Simple and fast :)</p> <p>Just declare an interface in a separated library and reference it in both, your system and your plugin:</p> <pre><code>public interface IYourInterface { Task YourMethod(); } </code></pre> <p>In your plugin library, declare a class which implements IYourInterface</p> <pre><code>public class YourClass: IYourInterface { async Task IYourInterface.YourMethod() { //..... } } </code></pre> <p>In your system, declare this method</p> <pre><code>using System; using System.Collections; using System.Collections.Generic; using System.Linq.Expressions; using System.Reflection; using System.Linq; public abstract class ReflectionTool&lt;TSource&gt; where TSource : class { public static TSource LoadInstanceFromLibrary(string libraryPath) { TSource pluginclass = null; if (!System.IO.File.Exists(libraryPath)) throw new Exception($"Library '{libraryPath}' not found"); else { Assembly.LoadFrom(libraryPath); var fileName = System.IO.Path.GetFileName(libraryPath).Replace(".dll", ""); var assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(c =&gt; c.FullName.StartsWith(fileName)); var type = assembly.GetTypes().FirstOrDefault(c =&gt; c.GetInterface(typeof(TSource).FullName) != null); try { pluginclass = Activator.CreateInstance(type) as TSource; } catch (Exception ex) { LogError("", ex); throw; } } return pluginclass; } } </code></pre> <p>And call it like this way:</p> <pre><code>IYourInterface instance = ReflectionTool&lt;IYourInterface&gt;.LoadInstanceFromLibrary("c:\pathToYourLibrary.dll"); </code></pre>
3,504
<p>I am now in the process of planning the deployment of a SharePoint solution into a production environment.<br> I have read about some tools that promise an easy way to automate this process, but nothing that seems to fit my scenario.</p> <p>In the testing phase I have used SharePoint Designer to copy site content between the different development and testing servers, but this process is manual and it seems a bit unnecessary.</p> <p>The site is made up of SharePoint web part pages with custom web parts, and a lot of Reporting Services report definitions.</p> <p>So, is there any good advice out there in this vast land of geeks on how to most efficiently create and deploy a SharePoint site for a multiple deployment scenario?</p> <p><strong>Edit</strong><br> Just to clarify. I need to deploy several "SharePoint Sites" into an existing site collection. Since SharePoint likes to have its sites in the SharePoint content database, just putting the files into IIS is not an option at this time.</p>
<p>I would also suggest checking out the SharePoint Content Deployment Wizard by Chris O'Brien. <a href="http://www.codeplex.com/SPDeploymentWizard" rel="nofollow noreferrer">http://www.codeplex.com/SPDeploymentWizard</a> </p> <p>Should help smooth the process you describe, and it's a nice tool for your kitbag regardless</p>
<p>We have a BizTalk 2006 with Web Application and Several WebServices that need to go from Dev to UAT to Live.</p> <p>We use MSBuild right from within VS to build, run tests, dependent on test result, complie, zip and ship to servers.</p> <p>Small MSBuild script on server to unzip, move the files, install clean web app, unlist biztalk bits, install new biztalk bits, re enlist and then start the stuff.</p> <p>MSBuild is hugh and more people need to use it as it there now right in the platform =></p> <p>Use <a href="http://msdn.microsoft.com/en-us/library/0k6kkbsd.aspx" rel="nofollow noreferrer"> MSBuild</a></p>
3,093
<p>Inspired by <a href="https://devblogs.microsoft.com/oldnewthing/20080902-00/?p=21003" rel="noreferrer">Raymond Chen's post</a>, say you have a 4x4 two dimensional array, write a function that rotates it 90 degrees. Raymond links to a solution in pseudo code, but I'd like to see some real world stuff.</p> <pre><code>[1][2][3][4] [5][6][7][8] [9][0][1][2] [3][4][5][6] </code></pre> <p>Becomes:</p> <pre><code>[3][9][5][1] [4][0][6][2] [5][1][7][3] [6][2][8][4] </code></pre> <p><strong>Update</strong>: Nick's answer is the most straightforward, but is there a way to do it better than n^2? What if the matrix was 10000x10000?</p>
<p><strong>O(n^2) time and O(1) space algorithm</strong> ( without any workarounds and hanky-panky stuff! )</p> <p><strong>Rotate by +90:</strong></p> <ol> <li>Transpose</li> <li>Reverse each row</li> </ol> <p><strong>Rotate by -90:</strong></p> <p><em>Method 1 :</em></p> <ol> <li>Transpose</li> <li>Reverse each column</li> </ol> <p><em>Method 2 :</em></p> <ol> <li>Reverse each row</li> <li>Transpose</li> </ol> <p><strong>Rotate by +180:</strong></p> <p><em>Method 1</em>: Rotate by +90 twice</p> <p><em>Method 2</em>: Reverse each row and then reverse each column (Transpose)</p> <p><strong>Rotate by -180:</strong></p> <p><em>Method 1</em>: Rotate by -90 twice</p> <p><em>Method 2</em>: Reverse each column and then reverse each row</p> <p><em>Method 3</em>: Rotate by +180 as they are same</p>
<p>The O(1) memory algorithm:</p> <ol> <li><p>rotate the outer-most data, then you can get below result:</p> <pre><code>[3][9][5][1] [4][6][7][2] [5][0][1][3] [6][2][8][4] </code></pre></li> </ol> <p>To do this rotation, we know </p> <pre><code> dest[j][n-1-i] = src[i][j] </code></pre> <p>Observe below: a(0,0) -> a(0,3) a(0,3) -> a(3,3) a(3,3) -> a(3,0) a(3,0) -> a(0,0)</p> <p>Therefore it's a circle, you can rotate N elements in one loop. Do this N-1 loop then you can rotate the outer-most elements.</p> <ol> <li>Now you can the inner is a same question for 2X2. </li> </ol> <p>Therefore we can conclude it like below:</p> <pre><code>function rotate(array, N) { Rotate outer-most data rotate a new array with N-2 or you can do the similar action following step1 } </code></pre>
6,405
<p>When is this called? More specifically, I have a control I'm creating - how can I release handles when the window is closed. In normal win32 I'd do it during <code>wm_close</code> - is <code>DestroyHandle</code> the .net equivalent?</p> <hr> <p>I don't want to destroy the window handle myself - my control is listening for events on another object and when my control is destroyed, I want to stop listening to those events. Eg:</p> <pre><code>void Dispose(bool disposing) { otherObject.Event -= myEventHandler; } </code></pre>
<p>Normally <code>DestroyHandle</code> is being called in <code>Dispose</code> method. So you need to make sure that all controls are disposed to avoid resource leaks.</p>
<p>Normally <code>DestroyHandle</code> is being called in <code>Dispose</code> method. So you need to make sure that all controls are disposed to avoid resource leaks.</p>
6,506
<p>I have a Monoprice MP10 with magnetic flexible paper coated build plate and I have just tried printing bed level test which is, of necessity, very thin on the build plate.</p> <p>Watching the item print, I saw that the bed level was obviously way way off at the back left corner and down the left side. I was printing with PLA. There was no point in letting the print continue so I stopped it, let the build plate cool down and tried to remove the print.</p> <p>The bottom line and right hand side came off cleanly but the top left corner and all down the left side stuck firmly. As it was so thin a layer there is no chance of getting something underneath an edge without damaging the paper surface. I tried acetone but this had no effect other than turning the surface white and thin cracks appearing in the paper surface. Wiped down with alcohol which toned down the white but was no help in getting the thin layer of PLA off.</p> <p>I tried reheating surface, no joy. Does anyone have a foolproof way of getting this off as soap and water don't work either?</p>
<p>In my experience with the Creality magnetic textured build surface, it's easier to remove a thin print while the surface is still pretty warm -- probably between 35 °C and 40 °C -- as opposed to fully cooled to room temperature.</p> <p>If the print is <em>very</em> thin, however (as when the nozzle is much too close to the build surface) printing over it may be the only sensible option. In fact, if the print residue is too thin to get a scraper under, it likely won't show in another print with the same color/type filament, so you can just ignore it unless you're changing color or material.</p> <p>BTW, don't use acetone. For <em>anything</em>, unless nothing else will do the job. Too flammable, too toxic, and it dissolves stuff you don't want to dissolve (but won't do anything notable to PLA, which is why you can't do acetone vapor smoothing with PLA).</p>
<p>You could try freezing your bed with cooling spray around the print and then wait some seconds and try peel it off.</p> <p>I had the problem once on my PEI sheet and it did help. I used this spray: <a href="https://www.distrelec.ch/de/kuehlmittel-spray-prefix-prefix-200-suffix-suffix-ml-kontakt-chemie-freeze-75-200-ml-ml/p/30025851?channel=b2c&amp;price_gs=17.51202&amp;source=googleps&amp;ext_cid=shgooaqchde-na&amp;gclid=EAIaIQobChMIyuGr5Ojy6wIVkuntCh2nawCXEAQYASABEgKQ5vD_BwE" rel="nofollow noreferrer">Spray</a></p> <p>But make sure you don't break any electric parts on your printer.</p>
1,742
<p>For classes that have a long list of setters that are used frequently, I found this way very useful (although I have recently read about the <a href="http://en.wikipedia.org/wiki/Builder_pattern" rel="noreferrer">Builder pattern</a> in <em>Effective Java</em> that is kinda the same).</p> <p>Basically, all setter methods return the object itself so then you can use code like this:</p> <pre><code>myClass .setInt(1) .setString(&quot;test&quot;) .setBoolean(true); </code></pre> <p>Setters simply return this in the end:</p> <pre><code>public MyClass setInt(int anInt) { // [snip] return this; } </code></pre> <p>What is your opinion? What are the pros and cons? Does this have any impact on performance?</p> <p>Also referred to as the <a href="http://www.cs.technion.ac.il/users/yechiel/c++-faq/named-parameter-idiom.html" rel="noreferrer">named parameter idiom</a> in c++.</p>
<p>@pek<br/> Chained invocation is one of proposals for Java 7. It says that if a method return type is void, it should implicitly return <strong>this</strong>. If you're interested in this topic, there is a bunch of links and a simple example on <a href="http://tech.puredanger.com/java7#chained" rel="noreferrer">Alex Miller's Java 7 page</a>.</p>
<p>I agree with @Bernard that method chaining like this muddles the purpose of the setters. Instead I would suggest that if you are always creating chains of setters like this that you create a custom Constructor for your class so instead of</p> <pre><code> MyClass .setInt(1) .setString("test") .setBoolean(true) ; </code></pre> <p>You do</p> <pre><code>new MyClass(1,"test",true); </code></pre> <p>This makes it more readable and you can use this to make your class immutable if you chose to.</p>
5,155
<p><a href="http://www.google.com/search?q=how%20to%20mock%20sealed%20class" rel="noreferrer">Mocking sealed classes</a> can be quite a pain. I currently favor an <a href="http://en.wikipedia.org/wiki/Adapter_pattern" rel="noreferrer">Adapter pattern</a> to handle this, but something about just keeps feels weird. </p> <p><strong>So, What is the best way you mock sealed classes?</strong></p> <p><em>Java answers are more than welcome</em>. In fact, I would anticipate that the Java community has been dealing with this longer and has a great deal to offer.</p> <p>But here are some of the .NET opinions:</p> <ul> <li><a href="http://haacked.com/archive/2007/08/19/why-duck-typing-matters-to-c-developers.aspx" rel="noreferrer">Why Duck Typing Matters for C# Develoepers</a> </li> <li><a href="http://cs.rthand.com/blogs/blog_with_righthand/archive/2008/07/22/Creating-wrappers-for-sealed-and-other-types-for-mocking.aspx" rel="noreferrer">Creating wrappers for sealed and other types for mocking</a></li> <li><a href="http://weblogs.asp.net/cibrax/archive/2008/05/16/unit-tests-for-wcf.aspx" rel="noreferrer">Unit tests for WCF (and Moq)</a></li> </ul>
<p>My general rule of thumb is that objects that I need to mock should have a common interface too. I think this is right design-wise and makes tests a lot easier (and is usually what you get if you do TDD). More about this can be read in the Google Testing Blog <a href="http://googletesting.blogspot.com/2008/08/by-miko-hevery-so-you-decided-to.html" rel="noreferrer">latest post</a> (See point 9).</p> <p>Also, I've been working mainly in Java in the past 4 years and I can say that I can count on one hand the number of times I've created a final (sealed) class. Another rule here is I should always have a good reason to seal a class, as opposed to sealing it by default.</p>
<p>Is there a way to implement a sealed class from an interface... and mock the interface instead?</p> <p>Something in me feels that having sealed classes is wrong in the first place, but that's just me :)</p>
2,822
<p>From what I can gather, there are three categories:</p> <ol> <li>Never use <code>GET</code> and use <code>POST</code></li> <li>Never use <code>POST</code> and use <code>GET</code></li> <li>It doesn't matter which one you use.</li> </ol> <p>Am I correct in assuming those three cases? If so, what are some examples from each case?</p>
<p>Use <code>POST</code> for destructive actions such as creation (I'm aware of the irony), editing, and deletion, because you can't hit a <code>POST</code> action in the address bar of your browser. Use <code>GET</code> when it's safe to allow a person to call an action. So a URL like:</p> <pre><code>http://myblog.org/admin/posts/delete/357 </code></pre> <p>Should bring you to a confirmation page, rather than simply deleting the item. It's far easier to avoid accidents this way.</p> <p><code>POST</code> is also more secure than <code>GET</code>, because you aren't sticking information into a URL. And so using <code>GET</code> as the <code>method</code> for an HTML form that collects a password or other sensitive information is not the best idea.</p> <p>One final note: <code>POST</code> can transmit a larger amount of information than <code>GET</code>. 'POST' has no size restrictions for transmitted data, whilst 'GET' is limited to 2048 characters.</p>
<p>Gorgapor, <code>mod_rewrite</code> still often utilizes <code>GET</code>. It just allows to translate a friendlier URL into a URL with a <code>GET</code> query string.</p>
6,876
<p>I have a large table with 1 million+ records. Unfortunately, the person who created the table decided to put dates in a <code>varchar(50)</code> field.</p> <p>I need to do a simple date comparison -</p> <pre><code>datediff(dd, convert(datetime, lastUpdate, 100), getDate()) &lt; 31 </code></pre> <p>But it fails on the <code>convert()</code>:</p> <pre><code>Conversion failed when converting datetime from character string. </code></pre> <p>Apparently there is something in that field it doesn't like, and since there are so many records, I can't tell just by looking at it. How can I properly sanitize the entire date field so it does not fail on the <code>convert()</code>? Here is what I have now:</p> <pre><code>select count(*) from MyTable where isdate(lastUpdate) &gt; 0 and datediff(dd, convert(datetime, lastUpdate, 100), getDate()) &lt; 31 </code></pre> <hr> <p><a href="https://stackoverflow.com/questions/28110/ms-sql-datetime-conversion-failure#28209">@SQLMenace</a></p> <p>I'm not concerned about performance in this case. This is going to be a one time query. Changing the table to a datetime field is not an option.</p> <p><a href="https://stackoverflow.com/questions/28110/ms-sql-datetime-conversion-failure#28139">@Jon Limjap</a></p> <p>I've tried adding the third argument, and it makes no difference.</p> <hr> <p><a href="https://stackoverflow.com/questions/28110/ms-sql-datetime-conversion-failure#28209">@SQLMenace</a></p> <blockquote> <p>The problem is most likely how the data is stored, there are only two safe formats; ISO YYYYMMDD; ISO 8601 yyyy-mm-dd Thh:mm:ss:mmm (no spaces)</p> </blockquote> <p>Wouldn't the <code>isdate()</code> check take care of this?</p> <p>I don't have a need for 100% accuracy. I just want to get most of the records that are from the last 30 days.</p> <hr> <p><a href="https://stackoverflow.com/questions/28110/ms-sql-datetime-conversion-failure#28209">@SQLMenace</a></p> <pre><code>select isdate('20080131') -- returns 1 select isdate('01312008') -- returns 0 </code></pre> <hr> <p><a href="https://stackoverflow.com/questions/28110/ms-sql-datetime-conversion-failure#28209">@Brian Schkerke</a></p> <blockquote> <p>Place the CASE and ISDATE inside the CONVERT() function.</p> </blockquote> <p>Thanks! That did it.</p>
<p>Place the <code>CASE</code> and <code>ISDATE</code> inside the <code>CONVERT()</code> function.</p> <pre class="lang-sql prettyprint-override"><code>SELECT COUNT(*) FROM MyTable WHERE DATEDIFF(dd, CONVERT(DATETIME, CASE IsDate(lastUpdate) WHEN 1 THEN lastUpdate ELSE '12-30-1899' END), GetDate()) &lt; 31 </code></pre> <p>Replace <code>'12-30-1899'</code> with the default date of your choice.</p>
<p>I would suggest cleaning up the mess and changing the column to a datetime because doing stuff like this</p> <pre><code>WHERE datediff(dd, convert(datetime, lastUpdate), getDate()) &lt; 31 </code></pre> <p>cannot use an index and it will be many times slower than if you had a datetime colum,n and did</p> <pre><code>where lastUpdate &gt; getDate() -31 </code></pre> <p>You also need to take into account hours and seconds of course</p>
4,776
<p>I've been trying to understand how Ruby blocks work, and to do that I've been trying to implement them in C.</p> <p>One easy way to implement closures is to pass a <code>void*</code> to the enclosing stack to the closure/function but Ruby blocks also seem to handle returns and break statements from the scope that uses the block.</p> <pre><code>loop do break i if (i &gt;= 4000) i *= 2 end </code></pre> <p>I think one of the closures proposals for Java works like this also.</p> <p>So, how would you implement Ruby-blocks/Java-closures in C?</p>
<p>The concept of closures requires the concept of contexts. C's context is based on the stack and the registers of the CPU, so to create a block/closure, you need to be able to manipulate the stack pointer in a correct (and reentrant) way, and store/restore registers as needed.</p> <p>The way this is done by interpreters or virtual machines is to have a <code>context</code> structure or something similar, and not use the stack and registers directly. This structure keeps track of a stack and optionally some registers, if you're designing a register based VM. At least, that's the simplest way to do it (though slightly less performant than actually mapping things correctly).</p>
<p>There's a good set of slides on Ruby Blocks as part of the "Rails with Passion" course:</p> <p><a href="http://www.javapassion.com/rubyonrails/ruby_blocks.pdf" rel="nofollow noreferrer">Ruby_Blocks.pdf</a></p> <p>This covers representing a block, how they get passed arguments and executed, and even further into things like Proc objects. It's very clearly explained.</p> <p>It might then be of interest to look at how the JRuby guys handled these in their parsing to Java. Take a look at the source at <a href="http://svn.codehaus.org/jruby/" rel="nofollow noreferrer">codehaus</a>.</p>
4,022
<p>In the past we declared properties like this:</p> <pre><code>public class MyClass { private int _age; public int Age { get{ return _age; } set{ _age = value; } } } </code></pre> <p>Now we can do:</p> <pre><code>public class MyClass { public int Age {get; set;} } </code></pre> <p>My question is, how can I access the private variable that is created automatically using this notation? </p> <p>I would rather access the private variable and not the public accessor 'Age'. Is there a default notation to access the private variable, or it is just not possible?</p>
<p>The aim of the new automatic properties is to reduce the amount of boilerplate code you need to write when you just have a simple property that doesn't need any special logic in the get or the set. </p> <p>If you want to access the private member that these properties use, that's usually for a few reasons:</p> <ul> <li>You need to more than just a simple get/set - in this case, you should just avoid using automatic properties for this member.</li> <li>You want to avoid the performance hit of going through the get or set and just use the member directly - in this case, I'd be surprised if there really was a performance hit. The simple get/set members are very very easy to inline, and in my (admittedly limited) testing I haven't found a difference between using the automatic properties and accessing the member directly. </li> <li><p>You only want to have public read access (i.e. just a 'get') and the class write to the member directly - in this case, you can use a private set in your automatic property. i.e.</p> <pre><code>public class MyClass { public int Age {get; private set;} }</code></pre></li> </ul> <p>This usually covers most the reasons for wanting to directly get to the backing field used by the automatic properties.</p>
<p>You can't, it's a language feature as opposed to a IDE feature. To be honest i'd prefer then IDE to add the private variable in for you. I agree that it is slightly weird for the class to internally have to use the public entry point to access its own variables. Hence I don't use this new feature that much myself.</p>
8,672
<p>I am new to any scripting language. But, still I worked on scripting a bit like tailoring other scripts to work for my purpose. For me, what is the best online resource to learn Perl?</p>
<p>If you already know a bit of perl, <a href="http://www.perlmonks.org/" rel="noreferrer">PerlMonks</a> is a great online resource. You can ask questions in their <a href="http://www.perlmonks.org/?node=Seekers%20of%20Perl%20Wisdom" rel="noreferrer">Seekers of Perl Wisdom</a> section and the answers are often of very high quality. Many people who keep up with the latest developments in Perl hang out there.</p> <p>As an added bonus, if you ask a clear question, many times the people there take the time to look at the underlying problem and will point out alternate approaches rather than simply taking your question at face value.</p>
<p>If you are a beginner, I would suggest you take a look at the cookbook provided by PLEAC. You can find it at <a href="http://pleac.sf.net" rel="nofollow noreferrer">http://pleac.sf.net</a>. There you can find cookbooks for most languages.</p>
9,599
<p>The exact error is as follows</p> <blockquote> <p>Could not load file or assembly 'Microsoft.SqlServer.Replication, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. An attempt was made to load a program with an incorrect format.</p> </blockquote> <p>I've recently started working on this project again after a two month move to another project. It worked perfectly before, and I've double checked all the references.</p>
<p>The <a href="https://stackoverflow.com/a/41451/148412">answer by baldy</a> below is correct, but you may also need to enable 32-bit applications in your AppPool. </p> <p>Source: <a href="http://www.alexjamesbrown.com/uncategorized/could-not-load-file-or-assembly-chilkatdotnet2-or-one-of-its-dependencies-an-attempt-was-made-to-load-a-program-with-an-incorrect-format/" rel="noreferrer">http://www.alexjamesbrown.com/uncategorized/could-not-load-file-or-assembly-chilkatdotnet2-or-one-of-its-dependencies-an-attempt-was-made-to-load-a-program-with-an-incorrect-format/</a></p> <p>Whilst setting up an application to run on my local machine (running Vista 64bit) I encountered this error:</p> <blockquote> <p>Could not load file or assembly <code>ChilkatDotNet2</code> or one of its dependencies. An attempt was made to load a program with an incorrect format.</p> </blockquote> <p>Obviously, the application uses <a href="http://www.chilkatsoft.com/" rel="noreferrer">ChilKat components</a>, but it would seem that the version we are using, is only the 32bit version.</p> <p>To resolve this error, I set my app pool in IIS to allow 32bit applications. Open up IIS Manager, right click on the app pool, and select Advanced Settings (See below)</p> <p><img src="https://i.stack.imgur.com/LQkqf.jpg" alt="enter image description here"></p> <p>Then set "Enable 32-bit Applications" to True.</p> <p><img src="https://i.stack.imgur.com/7ltqt.jpg" alt="enter image description here"></p> <p>All done!</p>
<p>in windows form application I do this, Right-click on Project->Properties->Build->Check Prefer 32-bit checkbox. Thanks all</p>
6,274
<p>Can someone please tell me how to submit an HTML form when the return key is pressed and if there are no buttons in the form? <strong>The submit button is not there</strong>. I am using a custom div instead of that.</p>
<p>To submit the form when the enter key is pressed create a javascript function along these lines.</p> <pre><code>function checkSubmit(e) { if(e &amp;&amp; e.keyCode == 13) { document.forms[0].submit(); } } </code></pre> <p>Then add the event to whatever scope you need eg on the div tag:</p> <p><code>&lt;div onKeyPress="return checkSubmit(event)"/&gt;</code></p> <p>This is also the default behaviour of Internet Explorer 7 anyway though (probably earlier versions as well).</p>
<p>Similar to Chris Marasti-Georg's example, instead using inline javascript. Essentially add onkeypress to the fields you want the enter key to work with. This example acts on the password field.</p> <pre><code>&lt;html&gt; &lt;head&gt;&lt;title&gt;title&lt;/title&gt;&lt;/head&gt; &lt;body&gt; &lt;form action="" method="get"&gt; Name: &lt;input type="text" name="name"/&gt;&lt;br/&gt; Pwd: &lt;input type="password" name="password" onkeypress="if(event.keyCode==13) {javascript:form.submit();}" /&gt;&lt;br/&gt; &lt;input type="submit" onClick="javascript:form.submit();"/&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
4,977
<p>I need to read from Outlook .MSG file in .NET <em>without</em> using COM API for Outlook (cos it will not be installed on the machines that my app will run). Are there any free 3rd party libraries to do that? I want to extract From, To, CC and BCC fields. Sent/Receive date fields would be good if they are also stored in MSG files.</p>
<p><strong>Update:</strong> I have found a 3rd party COM library called <a href="http://www.dimastr.com/redemption/" rel="noreferrer">Outlook Redemption</a> which is working fine for me at the moment. If you use it via COM-Interop in .NET, don't forget to release every COM object after you are done with it, otherwise your application crashes randomly.</p>
<p>If you open the .MSG file in a text editor, i believe you will find that the information you are after is stored as plain text inside the file. (It is on all the messages i have checked at least)</p> <p>It would be pretty easy to write some code to parse the file looking for lines beginning with "From:" or "To:" etc. and then extracting the information you need.</p> <p>If you need the body of the email as well, that may be a bit more complicated.</p>
3,669
<p>I was trying to get my head around XAML and thought that I would try writing some code. </p> <p>Trying to add a grid with 6 by 6 column definitions then add a text block into one of the grid cells. I don't seem to be able to reference the cell that I want. There is no method on the grid that I can add the text block too. There is only grid.children.add(object), no Cell definition.</p> <p>XAML:</p> <pre><code>&lt;Page x:Class="WPF_Tester.Page1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Page1" Loaded="Page_Loaded"&gt; &lt;/Page&gt; </code></pre> <p>C#:</p> <pre><code>private void Page_Loaded(object sender, RoutedEventArgs e) { //create the structure Grid g = new Grid(); g.ShowGridLines = true; g.Visibility = Visibility.Visible; //add columns for (int i = 0; i &lt; 6; ++i) { ColumnDefinition cd = new ColumnDefinition(); cd.Name = "Column" + i.ToString(); g.ColumnDefinitions.Add(cd); } //add rows for (int i = 0; i &lt; 6; ++i) { RowDefinition rd = new RowDefinition(); rd.Name = "Row" + i.ToString(); g.RowDefinitions.Add(rd); } TextBlock tb = new TextBlock(); tb.Text = "Hello World"; g.Children.Add(tb); } </code></pre> <p><strong>Update</strong></p> <p>Here is the spooky bit:</p> <ul> <li><p>Using VS2008 Pro on XP</p></li> <li><p>WPFbrowser Project Template (3.5 verified)</p></li> </ul> <p>I don't get the methods in autocomplete.</p>
<p>WPF makes use of a funky thing called <a href="http://msdn.microsoft.com/en-us/library/ms749011.aspx" rel="noreferrer">attached properties</a>. So in your XAML you might write this:</p> <pre><code>&lt;TextBlock Grid.Row="0" Grid.Column="0" /&gt; </code></pre> <p>And this will effectively move the TextBlock into cell (0,0) of your grid.</p> <p>In code this looks a little strange. I believe it'd be something like:</p> <pre><code>g.Children.Add(tb); Grid.SetRow(tb, 0); Grid.SetColumn(tb, 0); </code></pre> <p>Have a look at that link above - attached properties make things really easy to do in XAML perhaps at the expense of intuitive-looking code.</p>
<p>The cell location is an attached property - the value belongs to the TextBlock rather than Grid. However, since the property itself belongs to Grid, you need to use either the property definition field or the provided static functions.</p> <pre><code>TextBlock tb = new TextBlock(); // // Locate tb in the second row, third column. // Row and column indices are zero-indexed, so this // equates to row 1, column 2. // Grid.SetRow(tb, 1); Grid.SetColumn(tb, 2); </code></pre>
2,913
<p>I have some code that creates a fairly large xml DOM and writes it off to a file (up to 50-100MB) . It basically creates the DOM and then calls a toString on it and writes it out with ofstream. Is there a way to get streaming output of the generated dom so that it doesn't create the whole structure in memory all at once and then copy it, etc? I will not modify any node after i create it so it can write it out and free up the memory right away. I could write my own xml class that does the xml construction but ... i don't think that's a good idea since i'll probably miss something when it comes down to escaping etc.</p>
<p>Ok, turns out libxml2 has a streaming API:</p> <p><a href="http://xmlsoft.org/examples/testWriter.c" rel="nofollow noreferrer">http://xmlsoft.org/examples/testWriter.c</a></p> <p>It's a little old style (very C-ish) but you can write your wrapper around it.</p>
<p>Look under keyword "C++ XML writer;" XML writers generate XML to file without building the entire DOM in memory so they don't need to use very much memory at all. You didn't mention platform, but Microsoft XmlLite has IXmlWriter.</p>
7,304
<p>I know that just using <code>rand()</code> is predictable, if you know what you're doing, and have access to the server.</p> <p>I have a project that is <strong>highly</strong> dependent upon choosing a random number that is as unpredictable as possible. So I'm looking for suggestions, either other built-in functions or user functions, that can generate a <em>better</em> random number.</p> <p>I used this to do a little test:</p> <pre><code>$i = 0; while($i &lt; 10000){ $rand = rand(0, 100); if(!isset($array[$rand])){ $array[$rand] = 1; } else { $array[$rand]++; } sort($array); $i++; } </code></pre> <p>I found the results to be evenly distributed, and there is an odd pattern to the number of times each number is generated.</p>
<p>Adding, multiplying, or truncating a poor random source will give you a poor random result. See <a href="http://random.org/randomness/" rel="noreferrer">Introduction to Randomness and Random Numbers</a> for an explanation.</p> <p>You're right about PHP rand() function. See the second figure on <a href="http://random.org/analysis/" rel="noreferrer">Statistical Analysis</a> for a striking illustration. (The first figure is striking, but it's been drawn by Scott Adams, not plotted with rand()).</p> <p>One solution is to use a true random generator such as <a href="http://random.org/integers/" rel="noreferrer">random.org</a>. Another, if you're on Linux/BSD/etc. is to use <a href="http://en.wikipedia.org/wiki/Urandom" rel="noreferrer">/dev/random</a>. If the randomness is mission critical, you will have to use a <a href="http://en.wikipedia.org/wiki/Hardware_random_number_generator" rel="noreferrer">hardware random generator</a>.</p>
<p>Variation on @KG, using the milliseconds since EPOCH as the seed for rand?</p>
2,748
<p>Given a large set of data, I was able to create a 3D graph in Microsoft Excel. How can I create a STL file similar to this graph to create a physical model of this graph? <a href="https://i.stack.imgur.com/xvJhX.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/xvJhX.jpg" alt="enter image description here"></a></p>
<p>Before worrying too much about the hydrophilic properties of PLA, it might be worthwhile to test a fitting.</p> <p>First, print a fitting and see that the freshly made print is strong enough to carry the pressure of the water, and the compression force of hose clamp you may need to connect the stiff irrigation hose to the printed fitting. </p> <p>Second, soak the printed fitting in water for month or two, perhaps at an elevated temperature to match the higher ground temperature in the summer. You could put the part in a closed mason jar and leave it in the sun. You might add a little salt and fertilizer to the water to simulate ground conditions.</p> <p>After this aging process, you could test to see if it withstands the pressure of the domestic water system.</p> <p>You might also measure the ground temperatures where you intend to use the fittings. I find that PLA has no structural strength above about 150 degrees Fahrenheit (65 degrees Centigrade), and the inability to resist slow plastic may start at an even lower temperature. [For example, I print structural PLA parts with negative clearances and then dip them in 160 degree F water to soften them.]</p> <p>If the printed fittings are strong enough but suffer from water absorption, I would either print them of ABS or coat them with an ABS coating. To make the coating, dissolve ABS in acetone until it is the consistency of thick cream, dip your fitting in the mixture, and allow them to dry. It will take longer than you think it should to dry, and the solution will take more ABS plastic than you might expect.</p> <p>ABS is not generally considered to be "food safe", but this isn't a potable water system. The FDA lists ABS as conditionally food safe, and I would be comfortable using it to irrigate my lawn and vegetables.</p>
<p>PLA will biodegrade over time. ABS would last longer, and stand up to higher temps.</p>
888
<p>We're a .NET team which uses the Oracle DB for a lot of reasons that I won't get into. But deployment has been a bitch. We are manually keeping track of all the changes to the schema in each version, by keeping a record of all the scripts that we run during development. </p> <p>Now, if a developer forgets to check-in his script to the source control after he ran it - which is not that rare - at the end of the iteration we get a great big headache.</p> <p>I hear that SQL Compare by Red-Gate might solve these kind of issues, but it only has SQL Server support. Anybody knows of a similar tool for Oracle? I've been unable to find one.</p>
<p>Red Gate Schema Compare for Oracle has now been released!</p> <p><a href="http://www.red-gate.com/products/schema_compare_for_oracle/index.htm" rel="nofollow noreferrer">http://www.red-gate.com/products/schema_compare_for_oracle/index.htm</a></p> <p>There is a 28-day fully functional free trial. Please give it a go and let us know your feedback!</p>
<p>There are various tools out there that you can use, I haven't used any of them myself though so I've got no comments to make about them, but another "trick" that you can use is to create a trigger on DDL events, so you can basically capture (to a table, or log file or whatver) any changes done between deployments.</p> <p><a href="http://www.psoug.org/reference/ddl_trigger.html" rel="nofollow noreferrer">DDL Triggers</a></p>
6,958
<p>I noticed that my version of Ultimaker Cura was out of date, so I tried to go to <a href="https://ultimaker.com" rel="nofollow noreferrer">their website</a> and download a new version. For whatever reason, I could not get the <a href="https://ultimaker.com/en/products/ultimaker-cura-software/download-request/191" rel="nofollow noreferrer">download link</a> to work properly in Firefox with a slew of security extensions. </p> <p>Where are reputable mirrors for Cura?</p> <p>Download.Cnet.com and Sourceforge <a href="https://duckduckgo.com/?q=download%20cura&amp;t=ffsb&amp;ia=web" rel="nofollow noreferrer">came up as sources</a>, but years ago they both <a href="http://insecure.org/news/download-com-fiasco.html" rel="nofollow noreferrer">went to the darkside</a> (SourceForge: <a href="https://www.howtogeek.com/218764/warning-don%E2%80%99t-download-software-from-sourceforge-if-you-can-help-it/" rel="nofollow noreferrer">HowToGeek</a>, <a href="https://thecomputerpeeps.com/2013/08/sourceforge-malware/" rel="nofollow noreferrer">thecomputerpeeps</a>). I don't see anything else that looks even remotely reputable in the search results.</p> <p>I did some analysis, and it appears that the drop down and form don't work correctly if you select "I don't want to share any personal information", leading me to think this is web page bug.</p>
<p>The answer to your question is: <strong>&quot;From the application developer itself!&quot;</strong>.</p> <p>Below is the explanation how you can (directly) download Ultimaker Cura from the most reputable source: Ultimaker.com</p> <hr /> <h2>Regular download</h2> <p>When clicking the <a href="http://ultimaker.com/en/products/ultimaker-cura-software/list" rel="noreferrer">link to download</a> of the Cura application download button from the <a href="https://ultimaker.com/en/products/ultimaker-cura-software" rel="noreferrer">Ultimaker website</a> you are presented with a pop-up GUI that asks you if you want to share where you are using the program for. When you select the required field and press download, the download starts. If this doesn't work, a direct download approach can be used.</p> <h2>Direct download</h2> <p>If the regular download method fails, or you do not get the pop-up GUI, you can use the direct link for Ultimaker Cura from the developer's website:</p> <p><a href="https://download.ultimaker.com/cura/Ultimaker_Cura-4.1.0-win64.exe" rel="noreferrer">https://download.ultimaker.com/cura/Ultimaker_Cura-4.1.0-win64.exe</a></p> <p><strike>This link can be found at the download directory at the website:</p> <p><a href="https://download.ultimaker.com/current/" rel="noreferrer">https://download.ultimaker.com/current/</a></p> <p>This web directory overview also shows all previous releases and installers for other platforms.</p> <p>As of version 3.6.0, the download does not appear to be in the list, this link will show an overview: <a href="https://ultimaker.com/en/products/ultimaker-cura-software/list" rel="noreferrer">https://ultimaker.com/en/products/ultimaker-cura-software/list</a> Do note that the latter link will show the pop-up.</strike></p> <p><em>As of version 4.1, the web directory overview link will serve a 404.</em></p> <h3>Github</h3> <p>The Ultimaker Cura Project has a Github, where they offer the current and previous editions under:</p> <p><a href="https://github.com/Ultimaker/Cura/tags" rel="noreferrer">https://github.com/Ultimaker/Cura/tags</a></p>
<p>Cura is a software tool developed by Ultimaker for 3D printers. There is a downloadable page for this tool: <a href="https://ultimaker.com/en/products/ultimaker-cura-software/list" rel="nofollow noreferrer">https://ultimaker.com/en/products/ultimaker-cura-software/list</a>. There is no restriction to download it.</p> <p>I'm using Firefox on all my PC's and it can be downloaded with no problems, even if I'm using Windows XP, the main PC works at full speed with 3D models.</p>
966
<p>(I'm using Visual C++ 2008) I've always heard that main() is <em>required</em> to return an integer, but here I didn't put in <code>return 0;</code> and and it compiled with 0 errors and 0 warnings! In the debug window it says the program has exited with code 0. If this function is named anything other than main(), the compiler complains saying 'blah' must return a value. Sticking a <code>return;</code> also causes the error to appear. But leaving it out completely, it compiles just fine.</p> <pre><code>#include &lt;iostream&gt; using namespace std; int main() { cout &lt;&lt; "Hey look I'm supposed to return an int but I'm not gonna!\n"; } </code></pre> <p>Could this be a bug in VC++?</p>
<blockquote> <h1>3.6.1 Main function</h1> <p>....</p> <p>2 An implementation shall not predefine the <code>main</code> function. This function shall not be overloaded. It shall have a return type of type <code>int</code>, but otherwise its type is implementation-defined. All implementations shall allow both of the following definitions of main:</p> <pre><code>int main() { /* ... */ } </code></pre> <p>and</p> <pre><code>int main(int argc, char* argv[]) { /* ... */ } </code></pre> <p>.... and it continues to add ...</p> <p>5 A <code>return</code> statement in <code>main</code> has the effect of leaving the main function (destroying any objects with automatic storage duration) and calling <code>exit</code> with the return value as the argument. <strong>If control reaches the end of <code>main</code> without encountering a return statement, the effect is that of executing return 0</strong>;</p> </blockquote> <p>attempting to find an online copy of the C++ standard so I could quote this passage <a href="http://zamanbakshifirst.blogspot.com/2006/11/c-c-main-should-return-void.html" rel="noreferrer">I found a blog post that quotes all the right bits better than I could.</a></p>
<p>I'm pretty sure VC++ just inserts a return 0 if you don't include one in main functions. The same thing can happen with functions too, but in those cases at least you'll get a warning.</p>
4,222
<p>Ok, I have a strange exception thrown from my code that's been bothering me for ages.</p> <pre><code>System.Net.Sockets.SocketException: A blocking operation was interrupted by a call to WSACancelBlockingCall at System.Net.Sockets.Socket.Accept() at System.Net.Sockets.TcpListener.AcceptTcpClient() </code></pre> <p>MSDN isn't terribly helpful on this : <a href="http://msdn.microsoft.com/en-us/library/ms741547(VS.85).aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/ms741547(VS.85).aspx</a> and I don't even know how to begin troubleshooting this one. It's only thrown 4 or 5 times a day, and never in our test environment. Only in production sites, and on ALL production sites. </p> <p>I've found plenty of posts asking about this exception, but no actual definitive answers on what is causing it, and how to handle or prevent it.</p> <p>The code runs in a separate background thread, the method starts :</p> <pre><code>public virtual void Startup() { TcpListener serverSocket= new TcpListener(new IPEndPoint(bindAddress, port)); serverSocket.Start(); </code></pre> <p>then I run a loop putting all new connections as jobs in a separate thread pool. It gets more complicated because of the app architecture, but basically:</p> <pre><code> while (( socket = serverSocket.AcceptTcpClient()) !=null) //Funny exception here { connectionHandler = new ConnectionHandler(socket, mappingStrategy); pool.AddJob(connectionHandler); } } </code></pre> <p>From there, the <code>pool</code> has it's own threads that take care of each job in it's own thread, separately.</p> <p>My understanding is that AcceptTcpClient() is a blocking call, and that somehow winsock is telling the thread to stop blocking and continue execution.. but why? And what am I supposed to do? Just catch the exception and ignore it? </p> <hr> <p>Well, I do think some other thread is closing the socket, but it's certainly not from my code. What I would like to know is: is this socket closed by the connecting client (on the other side of the socket) or is it closed by my server. Because as it is at this moment, whenever this exception occurs, it shutsdown my listening port, effectively closing my service. If this is done from a remote location, then it's a major problem. </p> <p>Alternatively, could this be simply the IIS server shutting down my application, and thus cancelling all my background threads and blocking methods?</p>
<p>Is it possible that the serverSocket is being closed from another thread? That will cause this exception.</p>
<p>More recently I saw this exception when using HttpWebRequest to PUT a large file and the Timeout period was passed.</p> <p>Using the following code as long as your upload time > 3 seconds it will cause this error as far as I could see.</p> <pre><code>string path = "Reasonably large file.dat"; int bufferSize = 1024; byte[] buffer = new byte[bufferSize]; System.Net.HttpWebRequest req = (HttpWebRequest)System.Net.HttpWebRequest.Create("Some URL"); req.Method = "PUT"; req.Timeout = 3000; //3 seconds, small timeout to demonstrate long length = new System.IO.FileInfo(path).Length; using (FileStream input = File.OpenRead(path)) { using (Stream output = req.GetRequestStream()) { long remaining = length; int bytesRead = 0; while ((bytesRead = input.Read(buffer, 0, (int)Math.Min(remaining, (decimal)bufferSize))) &gt; 0) { output.Write(buffer, 0, bytesRead); remaining -= bytesRead; } output.Close(); } input.Close(); } </code></pre>
5,181
<p>I would like to ask this in more of a general sense than anything, just for people to make note.</p> <p>I am printing out things for people and some files have some edges hanging out the side. I always worry, since it is printing in mid air, that it would screw up the print. But I was able to go, maybe 1mm(I am not to good with metric when it comes to guessing). My question is, how far at 90* from a wall can a printer pull off before it is necessary to have support? This would help me when slicing up files. </p>
<p>If I understand correctly, your question is specifically for <strong>overhangs at 90°</strong> (so an horizontal plane that has no support under it.</p> <p>The first to notice is that <strong>you can only pull this off if the extrusion happens perpendicular to the surface from which the overhang is coming off</strong> (the closest to 90° the better) as effectively what is happening is that you are building a cantilever structure as you extrude.</p> <p>If you think about it in terms of a <em>cantilever structure</em> you will quickly realise that the stiffer the structure, the furthest you can go without it drooping. The main parameters you can tweak to increase the stiffness are:</p> <ul> <li><strong>Cooling</strong>. The cooler the plastic, the stiffer it is, so crank the cooling part fan up to 100%!</li> <li><strong>Speed</strong>. Plastic need time to cool off, so the slower you print (within reasonable limits), the more time you will allow for plastic to cool under the fan. On my rig I seem to get the best result between 15 and 20mm/s, but your mileage may vary, obviously.</li> <li><strong>Layer height</strong>. The thicker the layer, the more weight it will bear before drooping, so higher layers work best. A slicer that is very convenient to use for prints that have a couple of overhangs like these is <a href="https://www.prusa3d.com/slic3r-prusa-edition/" rel="nofollow noreferrer">slic3r PE</a>, as you can vary the height of the layers at specific points in the print.</li> <li><strong>Material</strong>. Some materials are more rigid than others. PLA is probably the one that works best for overhangs. PETG and Nylon are somewhat more problematic, and flexible filaments are the ones being more difficult to use.</li> </ul> <p><strong>For bridges</strong> (unsupported filament extruded between two supported structures) the considerations are identical but for speed: in my experience having the <strong>speed not too low</strong> helps the nozzle keep tension in the extruded filament by "pulling" it and keeping it horizontal. But again: each printer, firmware and slicer is different, and you should experiment yourself to see what works for you.</p> <p>To sum this up: <strong>"how far you can go before needing support" is a question that cannot be answered with a fixed number</strong> as the answer depends from a lot of factors that vary from printer to printer and material to material. Without mentioning: how many defects you are happy to tolerate before calling the print a failure.</p>
<p>To add to what mac described, there are small detail effects which sometimes change the behaviour of an overhang (and not necessarily in a predictable manner).</p> <p>Concave overhangs might sag (rather than turn out like a bridge). Convex overhangs might pull tight. Cooling plastic tends to shrink,so might sag less.</p> <p>I'm often surprised how well overhangs turn out, but equally often see failures which I don't anticipate.</p>
803
<p>I am using <a href="http://code.google.com/p/js2-mode/" rel="noreferrer">js2-mode</a> to edit Javascript in Emacs, but I can't seem to get it to stop using tabs instead of spaces for indentation. My other modes work fine, just having issues w/ js2.</p>
<p>Do you have</p> <pre> (setq-default indent-tabs-mode nil) </pre> <p>in your .emacs? It works fine for me in emacs 23.0.60.1 when I do that. js2-mode uses the standard emacs function indent-to, which respects indent-tabs-mode, to do its indenting.</p>
<p>Add this to your <code>.emacs</code> file somewhere after you load js2 mode:</p> <pre><code>(setq js2-mode-hook '(lambda () (progn (set-variable 'indent-tabs-mode nil)))) </code></pre>
6,786
<p>I picked up some no-name &quot;silk&quot; PLA in a multi color pack as part of a project where I needed some additional distinct colors and structural properties didn't matter, but now I'm playing with the excess I'm not using for that, and its behavior is really weird. On overhangs with detail on the downward-facing surface it's like everything flowed/melted together rather than retaining the extruded shape. And on vertical surfaces where one would expect to see layer lines, the lines are present and can be felt and slightly seen, but don't seem to contibute to the sheen/reflective properties like how they would in normal PLA or other materials. Together these observations make me suspect there's an additive that melts to a state where it flows much more than the base PLA at PLA printing temperatures, coalescing into more of a uniform smooth surface.</p> <p>What are the likely additives in &quot;silk PLA&quot; filaments, and what printing/mechanical properties should we expect from them?</p> <p>Some further observations: pushing it out of the hotend by hand, it has <em>a lot</em> of die swell, almost up to the original 1.75 mm diameter, and if tension is released it tries to retreat back into the nozzle. This suggests to me there might be some sort of foaming type additive involved, and also explains the behavior on overhangs.</p>
<p>It has additives to the PLA to change its characteristics.</p> <blockquote> <p>Typically, “silk” filaments are enhanced PLA filaments, owing their glossy result to various additives. As such, they tend to show most of the same pros and cons of PLA filament. In the case where silk filaments have a different base, these would be expected to have similar properties to the base material. For this article, we’ll focus mostly on PLA-based silk filaments.</p> </blockquote> <p>-- <a href="https://all3dp.com/2/silk-3d-printing-filament-brands-compared/" rel="nofollow noreferrer">Silk PLA Filament: Best Brands</a></p> <p>The article goes on to say that this does modify how the material prints and thus may need different parameters on your printer from normal PLA. You can get silk PLA in different brands. There doesn't seem to be a standard composition, so each brand may behave differently.</p>
<p>It has additives to the PLA to change its characteristics.</p> <blockquote> <p>Typically, “silk” filaments are enhanced PLA filaments, owing their glossy result to various additives. As such, they tend to show most of the same pros and cons of PLA filament. In the case where silk filaments have a different base, these would be expected to have similar properties to the base material. For this article, we’ll focus mostly on PLA-based silk filaments.</p> </blockquote> <p>-- <a href="https://all3dp.com/2/silk-3d-printing-filament-brands-compared/" rel="nofollow noreferrer">Silk PLA Filament: Best Brands</a></p> <p>The article goes on to say that this does modify how the material prints and thus may need different parameters on your printer from normal PLA. You can get silk PLA in different brands. There doesn't seem to be a standard composition, so each brand may behave differently.</p>
1,942
<p>My university is part of MSDNAA, so I downloaded it a while back, but I just got around to installing it. I guess part of it replaces FrontPage for web editing, and there appears to be a video editor and a vector graphics editor, but I don't think I've even scratched the surface of what it is and what it can do. Could someone enlighten me, especially since I haven't found an "Expression Studio for Dummies" type website.</p>
<p>Expression Studio is basically a design studio. It consists of a bunch of design software that Microsoft has bought for the most part. The audience is designers, not developers. The gist of the software is that Expression Blend enables designers and programmers to work seamlessly together in letting the designer create the graphical user interface.</p> <p>In a normal workflow, the designer would deliver a mockup which the developer would have to implement. Using Expression Blend in combination with WPF, this is no longer necessary. The graphical UI made by the designer is functional. All the developer has to do is write the code for the function behind the design.</p> <p>This in itself is great because developers invariably fail to implement the design as thought out by the designer. Technical limitations, lack of communication … whatever the reason. UIs never look like them mockup done up front.</p> <p>Expression Design is basically a vector drawing program that can be used to design smaller components that are then used within Expression Blend as parts of the UI. For example, graphical buttons could be designed that way. It can also be used as a vanilla drawing program. I did the graphics in my thesis using Expression Design.</p>
<p>The <a href="http://www.microsoft.com/expression/" rel="nofollow noreferrer">Expression site</a> is the first place to start. These are tools that bridge the developer/designer gap for building rich internet applications with Silverlight and WPF. They compete with Adobe Studio products.</p> <p>Whilst Visual Studio is good for working with code, it has some weaknesses when it comes to dealing with XAML. In many cases a designer will build something visually different from a Windows application and Expression Blend allows them this freedom. It ties in Visual Studio for the C#/VB coding and debugging part of development.</p>
4,846
<p>I need to find out how to format numbers as strings. My code is here:</p> <pre><code>return str(hours)+":"+str(minutes)+":"+str(seconds)+" "+ampm </code></pre> <p>Hours and minutes are integers, and seconds is a float. the str() function will convert all of these numbers to the tenths (0.1) place. So instead of my string outputting "5:30:59.07 pm", it would display something like "5.0:30.0:59.1 pm".</p> <p>Bottom line, what library / function do I need to do this for me?</p>
<p>Starting with Python 3.6, formatting in Python can be done using <a href="https://docs.python.org/3/whatsnew/3.6.html#whatsnew36-pep498" rel="noreferrer">formatted string literals</a> or <em>f-strings</em>:</p> <pre><code>hours, minutes, seconds = 6, 56, 33 f'{hours:02}:{minutes:02}:{seconds:02} {"pm" if hours &gt; 12 else "am"}' </code></pre> <p>or the <a href="https://docs.python.org/library/stdtypes.html#str.format" rel="noreferrer"><code>str.format</code></a> function starting with 2.7:</p> <pre><code>"{:02}:{:02}:{:02} {}".format(hours, minutes, seconds, "pm" if hours &gt; 12 else "am") </code></pre> <p>or the <a href="https://docs.python.org/library/stdtypes.html#printf-style-string-formatting" rel="noreferrer">string formatting <code>%</code> operator</a> for even older versions of Python, but see the note in the docs:</p> <pre><code>"%02d:%02d:%02d" % (hours, minutes, seconds) </code></pre> <p>And for your specific case of formatting time, there’s <a href="https://docs.python.org/library/time.html#time.strftime" rel="noreferrer"><code>time.strftime</code></a>:</p> <pre><code>import time t = (0, 0, 0, hours, minutes, seconds, 0, 0, 0) time.strftime('%I:%M:%S %p', t) </code></pre>
<p><em>str()</em> in python on an integer will <strong>not</strong> print any decimal places.</p> <p>If you have a float that you want to ignore the decimal part, then you can use str(int(floatValue)).</p> <p>Perhaps the following code will demonstrate:</p> <pre><code>&gt;&gt;&gt; str(5) '5' &gt;&gt;&gt; int(8.7) 8 </code></pre>
4,266
<p>I have a Ruby on Rails Website that makes HTTP calls to an external Web Service.</p> <p>About once a day I get a SystemExit (stacktrace below) error email where a call to the service has failed. If I then try the exact same query on my site moments later it works fine. It's been happening since the site went live and I've had no luck tracking down what causes it.</p> <p>Ruby is version 1.8.6 and rails is version 1.2.6.</p> <p>Anyone else have this problem?</p> <p>This is the error and stacktrace.</p> <blockquote> <p>A SystemExit occurred /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.6/lib/fcgi_handler.rb:116:in exit' /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.6/lib/fcgi_handler.rb:116:in exit_now_handler' /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/inflector.rb:250:in to_proc' /usr/local/lib/ruby/1.8/net/protocol.rb:133:in call' /usr/local/lib/ruby/1.8/net/protocol.rb:133:in sysread' /usr/local/lib/ruby/1.8/net/protocol.rb:133:in rbuf_fill' /usr/local/lib/ruby/1.8/timeout.rb:56:in timeout' /usr/local/lib/ruby/1.8/timeout.rb:76:in timeout' /usr/local/lib/ruby/1.8/net/protocol.rb:132:in rbuf_fill' /usr/local/lib/ruby/1.8/net/protocol.rb:116:in readuntil' /usr/local/lib/ruby/1.8/net/protocol.rb:126:in readline' /usr/local/lib/ruby/1.8/net/http.rb:2017:in read_status_line' /usr/local/lib/ruby/1.8/net/http.rb:2006:in read_new' /usr/local/lib/ruby/1.8/net/http.rb:1047:in request' /usr/local/lib/ruby/1.8/net/http.rb:945:in request_get' /usr/local/lib/ruby/1.8/net/http.rb:380:in get_response' /usr/local/lib/ruby/1.8/net/http.rb:543:in start' /usr/local/lib/ruby/1.8/net/http.rb:379:in get_response'</p> </blockquote>
<p>Using fcgi with Ruby is known to be very buggy. </p> <p>Practically everybody has moved to <a href="http://mongrel.rubyforge.org/" rel="noreferrer">Mongrel</a> for this reason, and I recommend you do the same.</p>
<p>I would also take a look at <a href="http://modrails.com/" rel="nofollow noreferrer">Passenger</a>. It's a lot easier to get going than the traditional solution of Apache/nginx + Mongrel.</p>
2,294
<p><a href="https://3dprinting.stackexchange.com/a/2820/5782">In this answer</a> user <a href="https://3dprinting.stackexchange.com/users/4345/barafu-albino">Barafu</a> says,</p> <blockquote> <p>Yet I manage to keep my tolerances +- 0.05 mm which is enough for everything but miniature printing.</p> </blockquote> <p>I have asked for clarification on that answer regarding what is meant by "miniature printing" but in the meantime, I want to ask the general question.</p> <p>What impact does dimensional accuracy of filament have on final print quality, and why? Does it vary between different filament types? </p>
<p>Dimensional accuracy is not as important as dimensional uniformity. I can print with undersized (or oversized) filament, adjusting the flow appropriately, provided the filament has a consistent diameter. When creating filament in-house, without expensive equipment, it is difficult to maintain the same diameter throughout the entire extrusion. It is likely this extrusion diameter (when creating filament, rather than the output of the actual print head) to which Barafu is referring when he mentions his tolerances: +/- 0.05&nbsp;mm <em>in diameter</em>. Which is reasonable.</p> <p>The "miniature printing" comment likely refers to printing miniature models for tabletop gaming.</p> <p>If the source filament becomes wider than expected, the output will have overflow, or more material than desired will be deposited, and this will certainly affect the quality of the piece.</p>
<p>Put it simply: they say 1.75&nbsp;mm with a &plusmn; error of 0.05&nbsp;mm. Which means your flow may vary &plusmn;2.9&nbsp;% while you are printing creating blobs and such. </p> <p>The smaller the filament tolerance, the more expensive the production costs.</p>
500
<p>Struts 1.3 application. Main website is NOT served by struts/Java. I need to forward the result of a struts action to a page in the website, that is outside of the struts context. Currently, I forward to a JSP in context and use a meta-refresh to forward to the real location. That seems kinda sucky. Is there a better way?</p>
<p>You can't "forward", in the strict sense. Just call <code>sendRedirect()</code> on the <code>HttpServletResponse</code> object in your <code>Action</code> class's <code>execute()</code> method and then, <code>return null</code>.</p> <p>Alternately, either call <code>setModule()</code> on the <code>ActionForward</code> object (that you are going to return) or set the path to an absolute URI.</p>
<p>I ended up doing response.sendRedirect().</p>
8,939
<p>I know that tables are for tabular data, but it's so tempting to use them for layout. I can handle DIV's to get a three column layout, but when you got 4 nested DIV's, it get tricky. </p> <p>Is there a tutorial/reference out there to persuade me to use DIV's for layout?</p> <p>I want to use DIV's, but I refuse to spend an hour to position my DIV/SPAN where I want it.</p> <p>@GaryF: <a href="http://www.blueprintcss.org/" rel="noreferrer">Blueprint CSS</a> has to be the CSS's best kept secret.</p> <p>Great tool - <a href="http://kematzy.com/blueprint-generator/" rel="noreferrer">Blueprint Grid CSS Generator</a>.</p>
<p>There's the <a href="http://developer.yahoo.com/yui/grids/" rel="nofollow noreferrer">Yahoo Grid CSS</a> which can do all sorts of things. </p> <p>But remember: <strong>CSS IS NOT A RELIGION</strong>. If you save hours by using tables instead of css, do so. </p> <p>One of the corner cases I could never make my mind up about is forms. I'd love to do it in css, but it's just so much more complicated than tables. </p> <p>You could even argue that forms are tables, in that they have headers (labels) and data (input fields). </p>
<p>This may be unhelpful but I somehow don't understand all these problems related to CSS. If a newspaper designer would try to embed a movie in the ad page, everybody would agree that he's a bit crazy. But still those same people pine after three-column layouts in HTML. HTML is just not apt to handle this kind of layout well at the moment. Furthermore, multi-column layouts are generally not really well-suited for reading on computer monitors. Aren't there enough viable alternatives?</p> <p>And by the way, even tables don't offer a good way of implementing a fluent column layout so this is no reason at all to resort to such hacks. Assuming a halfway modern browser (i.e. > MSIE 6), tables don't offer any advantages over clean HTML + CSS that I know of.</p>
8,640
<p>I am trying to link two fields of a given table to the same field in another table. I have done this before so I can't work out what is wrong this time.</p> <p>Anyway:</p> <pre><code>Table1 - Id (Primary) - FK-Table2a (Nullable, foreign key relationship in DB to Table2.Id) - FK-Table2b (Nullable, foreign key relationship in DB to Table2.Id) Table2 - Id (Primary) </code></pre> <p>The association works for FK-Table2a but not FK-Table2b. In fact, when I load into LINQ to SQL, it shows Table2.Id as associated to Table1.Id. If I try and change this, or add a new association for FK-Table2b to Table2.Id it says: "Properties do not have matching types".</p> <p>This also works in other projects - maybe I should just copy over the .dbml?</p> <p>Any ideas?</p>
<p>No idea on the cause, but I just reconstructed my .dbml from scratch and it fixed itself. Oh for a "refresh" feature...</p>
<p>I had the same problem. This error appeared when I tried to link different types of fields, or when I tryied to drag-and-drop table to .dbml space, but .dbml already had contained linked tables with different types of linked fields.</p>
6,686