instruction
stringlengths 27
22.5k
| chosen
stringlengths 27
28.2k
| rejected
stringlengths 19
24.9k
| __index_level_0__
int64 0
10k
|
|---|---|---|---|
<p>I'm running PHP 5.2.3 on Windows 2000 Server with IIS 5. I'm trying
to get cURL working, so in my <strong>php.ini</strong> file, I have this line:</p>
<blockquote>
<p>extension_dir ="F:\PHP\ext"</p>
</blockquote>
<p>And later, I have:</p>
<blockquote>
<p>extension=php_curl.dll</p>
</blockquote>
<p>The file <strong>F:\PHP\ext\php_curl.dll</strong> exists, but when I try to run any PHP
script, I get this in the error log:</p>
<blockquote>
<p>PHP Warning: PHP Startup: Unable to load dynamic library 'F:\PHP\ext
\php_curl.dll' - The specified module could not be found.
in Unknown on line 0 </p>
</blockquote>
|
<p>Problem solved!</p>
<p>Although the error message said <strong>The specified module could not be found</strong>, this is a little misleading -- it's not that it couldn't find <code>php_curl.dll</code>, but rather it couldn't find a module that <code>php_curl.dll</code> required. The 2 DLLs it requires are <code>libeay32.dll</code> and <code>SSLeay32.dll</code>.</p>
<p>So, you have to put those 2 DLLs somewhere in your PATH (e.g., <code>C:\Windows\system32</code>). That's all there is to it.</p>
<p>However, even that did not work for me initially. So I downloaded the Windows zip of the latest version of PHP, which includes all the necessary DLLs. I didn't reinstall PHP, I just copied all of the DLLs in the "ext" folder to my PHP extensions folder (as specified in the <code>extension_dir</code> variable in <code>php.ini</code>), and I copied the versions of <code>libeay32.dll</code> and <code>SSLeay32.dll</code> from the PHP download into my System32 directory.</p>
<p>I also did an iisreset, but I don't know if that was necessary. </p>
|
<p>In your case just add "F:\PHP\ext" to Environment Variable "path".</p>
| 3,340
|
<p>I just got a new Ender3 version two for Christmas and was very excited to use it so I put it together and used the sample filament that came with the printer and everything worked okay for a bit.</p>
<p>That was until I switched something in the settings, or in Cura, or something happened, because the nozzle is too far away from the bed when printing. I will use the auto home feature to level my bed with a piece of paper and once I get that pretty close I try and start my print, and it starts a few millimetres further away from the bed than when levelling it.</p>
<p>Any ideas to solve this?</p>
|
<p>This is probably caused by too few top layers in combination with a too low infill percentage. Increase skin layers and increase infill percentage.</p>
<p>If you have multiple layers already (at least about 4 for 0.2 mm layer height, for smaller layer heights even more), you might be printing at a too high temperature and or too few part cooling percentage and a too low infill percentage.</p>
|
<p>To combat the bad top layers, I usually use usually 5 top layers for any model of layer height 0.1 to 0.3 mm. I generally don't print with less than 9 % infill for PLA, which I have found sufficient to support even complex geometry on top.</p>
<p>Also, I generally use a mixed setup of layers: the outermost layers I demand as concentric because this is the most beautiful setup, while the lower levels are Zig-Zag patterned, as this gives the best layer-to-wall connection.</p>
| 1,814
|
<p>I'm looking for a good way to perform multi-row inserts into an Oracle 9 database. The following works in MySQL but doesn't seem to be supported in Oracle.</p>
<pre><code>INSERT INTO TMP_DIM_EXCH_RT
(EXCH_WH_KEY,
EXCH_NAT_KEY,
EXCH_DATE, EXCH_RATE,
FROM_CURCY_CD,
TO_CURCY_CD,
EXCH_EFF_DATE,
EXCH_EFF_END_DATE,
EXCH_LAST_UPDATED_DATE)
VALUES
(1, 1, '28-AUG-2008', 109.49, 'USD', 'JPY', '28-AUG-2008', '28-AUG-2008', '28-AUG-2008'),
(2, 1, '28-AUG-2008', .54, 'USD', 'GBP', '28-AUG-2008', '28-AUG-2008', '28-AUG-2008'),
(3, 1, '28-AUG-2008', 1.05, 'USD', 'CAD', '28-AUG-2008', '28-AUG-2008', '28-AUG-2008'),
(4, 1, '28-AUG-2008', .68, 'USD', 'EUR', '28-AUG-2008', '28-AUG-2008', '28-AUG-2008'),
(5, 1, '28-AUG-2008', 1.16, 'USD', 'AUD', '28-AUG-2008', '28-AUG-2008', '28-AUG-2008'),
(6, 1, '28-AUG-2008', 7.81, 'USD', 'HKD', '28-AUG-2008', '28-AUG-2008', '28-AUG-2008');
</code></pre>
|
<p>This works in Oracle:</p>
<pre><code>insert into pager (PAG_ID,PAG_PARENT,PAG_NAME,PAG_ACTIVE)
select 8000,0,'Multi 8000',1 from dual
union all select 8001,0,'Multi 8001',1 from dual
</code></pre>
<p>The thing to remember here is to use the <code>from dual</code> statement.</p>
|
<p>Cursors may also be used, although it is inefficient.
The following stackoverflow post discusses the usage of cursors :</p>
<p><a href="https://stackoverflow.com/questions/11921889/insert-and-update-a-record-using-cursors-in-oracle">INSERT and UPDATE a record using cursors in oracle</a></p>
| 6,068
|
<p>I've built a custom machine based on the AM8 (Anet A8 upgrade). I've got an E3D V6 clone hotend in, seems like a decent clone. I've replaced the heat break, heat block, and nozzle several times but after a given period it seems like filament leaks up the heat break. The heat break and nozzle are "all-metal" titanium versions.</p>
<p>How I set it up: I insert the nozzle all the way into heat block, I unscrew it about 3/4 of a turn. I insert the heat break until it makes contact. I then tighten using pliers and spanner. I assemble onto the printer. I heat until 285 °C, give it a few minutes, tighten as much as I think I can before something would break. I let it cool down. I heat again to 285 °C, tighten again as much as I can. Cool down. Then ready for printing (mainly using PETG at 240 °C).</p>
<p>What am I doing wrong? What should I be doing differently?</p>
<p><a href="https://i.stack.imgur.com/3Nd9q.jpg" rel="nofollow noreferrer" title="Photo of hotend on 3D printer"><img src="https://i.stack.imgur.com/3Nd9q.jpg" alt="Photo of hotend on 3D printer" title="Photo of hotend on 3D printer" /></a></p>
|
<ol>
<li>Verification: When you tighten the nozzle against the heat break, the nozzle is not tightened completely against the heater block. If the nozzle tightens completely against the heater block, it will not finish tightening against the heat break.</li>
</ol>
<p>Note: the heat break is thin between the heater block and heat sink to minimize conduction of heat. Over-tightening the heat break into the heat sink with break the heat break.</p>
<ol start="2">
<li><p>Verification: your heat break is all metal (no Teflon tube in the filament path). If it's not all metal, 285 °C may be damaging the Teflon tube. If not all metal, tighten the nozzle to the heat break at 250 °C, which is the limiting temperature for an extuder that isn't all metal.</p>
</li>
<li><p>The titanium heat break has higher thermal resistance, which helps to isolate the heat break from the heater block. However, higher thermal resistance is a disadvantage for the nozzle, where you want the heat. For non-abrasive filaments, such as PETG, a brass nozzle is easier to get a good seal as well was better heat conduction. PETG is particularly sensitive to jamming from not adequately heating up when printing too fast. While the nozzle heats the filament, the filament cools the tip. Thus, you will need to print slower with a titanium nozzle.</p>
</li>
<li><p>From the information so far, it appears to be difficulty get a seal between to titanium pieces. It seams like they could use a different titanium alloy. Titanium glasses frames are flexible, not brittle. However, brittle alloys are usually harder, but the heat break doesn't need to be hard like the nozzle. Of course, brass is easier to get a seal because it actually deforms to fit shape of heat break.</p>
</li>
</ol>
|
<ol>
<li>Verification: When you tighten the nozzle against the heat break, the nozzle is not tightened completely against the heater block. If the nozzle tightens completely against the heater block, it will not finish tightening against the heat break.</li>
</ol>
<p>Note: the heat break is thin between the heater block and heat sink to minimize conduction of heat. Over-tightening the heat break into the heat sink with break the heat break.</p>
<ol start="2">
<li><p>Verification: your heat break is all metal (no Teflon tube in the filament path). If it's not all metal, 285 °C may be damaging the Teflon tube. If not all metal, tighten the nozzle to the heat break at 250 °C, which is the limiting temperature for an extuder that isn't all metal.</p>
</li>
<li><p>The titanium heat break has higher thermal resistance, which helps to isolate the heat break from the heater block. However, higher thermal resistance is a disadvantage for the nozzle, where you want the heat. For non-abrasive filaments, such as PETG, a brass nozzle is easier to get a good seal as well was better heat conduction. PETG is particularly sensitive to jamming from not adequately heating up when printing too fast. While the nozzle heats the filament, the filament cools the tip. Thus, you will need to print slower with a titanium nozzle.</p>
</li>
<li><p>From the information so far, it appears to be difficulty get a seal between to titanium pieces. It seams like they could use a different titanium alloy. Titanium glasses frames are flexible, not brittle. However, brittle alloys are usually harder, but the heat break doesn't need to be hard like the nozzle. Of course, brass is easier to get a seal because it actually deforms to fit shape of heat break.</p>
</li>
</ol>
| 1,966
|
<p>I have imported the <code>kernel32</code> library. So, I have the <code>createMutex</code> function available but I am not quite sure of the various parameters and return values.</p>
<p>This is classic Visual Basic, not Visual Basic.NET but I can probably work with either language in the form of an answer.</p>
|
<p>The VB code looks something like this:</p>
<pre><code>hMutex = CreateMutex(ByVal 0&, 1, ByVal 0&)
</code></pre>
<p>The first parameter is a pointer to an <code>SECURITY_ATTRIBUTES</code> structure. If you don't know what it is, you don't need it. Pass NULL (0).</p>
<p>The second parameter is <code>TRUE</code> (non-zero, or 1) if the calling thread should take ownership of the mutex. <code>FALSE</code> otherwise.</p>
<p>The third parameter is the mutex name and may be NULL (0), as shown. If you need a named mutex, pass the name (anything unique) in. Not sure whether the <code>VB</code> wrapper marshals the length-prefixed <code>VB</code> string type (<code>BSTR</code>) over to a null-terminated Ascii/Unicode string if not, you'll need to do that and numerous examples are out there.</p>
<p>Good luck!</p>
|
<p>Well, based on the <a href="http://msdn.microsoft.com/en-us/library/ms682411(VS.85).aspx" rel="nofollow noreferrer">documentation</a> it looks like:</p>
<ol>
<li>Security attributes (can pass null)</li>
<li>Whether it's initially owned (can pass false)</li>
<li>The name of it</li>
</ol>
<p>HTH</p>
| 2,338
|
<p>Is there any way to create a virtual drive in "(My) Computer" and manipulate it, somewhat like JungleDisk does it?</p>
<p>It probably does something like:</p>
<pre><code>override OnRead(object sender, Event e) {
ShowFilesFromAmazon();
}
</code></pre>
<p>Are there any API:s for this? Maybe to write to an XML-file or a database, instead of a real drive.</p>
<hr>
<p>The <a href="http://dokan-dev.net/en/" rel="noreferrer">Dokan Library</a> seems to be the answer that mostly corresponds with my question, even though <a href="http://msdn.microsoft.com/en-us/library/system.io.isolatedstorage.aspx" rel="noreferrer">System.IO.IsolatedStorage</a> seems to be the most standardized and most Microsoft-environment adapted.</p>
|
<p>You can use the <a href="https://dokan-dev.github.io/" rel="nofollow noreferrer">Dokan library</a> to create a virtual drive. There is a .Net wrapper for interfacing with C#.</p>
|
<p>Yes, use the classes in <a href="http://msdn.microsoft.com/en-us/library/system.io.isolatedstorage.aspx" rel="nofollow noreferrer">System.IO.IsolatedStorage</a></p>
| 8,104
|
<p>I start using the visual studio c++ express 2008 at home but there is no ATL in it.<br>
How can I add ATL to visual studio c++ express 2008? </p>
|
<p>ATL 7.1 is now part of the <a href="http://www.microsoft.com/whdc/DevTools/WDK/WDKpkg.mspx" rel="noreferrer">Windows Driver Kit</a>. </p>
|
<p>You'll need to download the platform SDK and muck around with some dependencies to get ATL.</p>
<p>There might be some more "unsavory" ways to get MFC ;) if you catch my drift. Also many institutions have educational VS licenses which are free.</p>
| 9,720
|
<p>Why do we have two standard filament sizes, 1.75 mm and 3 mm? Does it really make a difference when printing? Or is the 1.75 mm just for smaller printers?</p>
<p>In what situations should I be using 1.75 mm?</p>
<p>When should I be using 3 mm?</p>
|
<p>There's no appreciable difference. Just use the filament that fits your particular printer.</p>
<p>If you don't yet have a printer, then I'd get one that uses 1.75 mm filament:</p>
<ul>
<li><p>1.75 mm is increasingly becoming the "standard", thus being easier to get. Some filaments are not available as 3 mm.</p></li>
<li><p>1.75 mm filament allows for finer control, because feeding in 1 mm of filament corresponds to less plastic extruded.</p></li>
<li><p>1.75 mm filament requires less force to extrude. Compressing 1.75 mm down to 0.3 mm takes less force than doing the same to 3 mm filament.</p></li>
</ul>
<p>However, the advantages are fairly minor. I don't see any reason to replace a functioning 3 mm extruder with a 1.75 mm one (yet).</p>
|
<p>One thing I haven't seen anyone mention yet is the issue of the size vis-a-vis time of the final print. 3 mm filament allows the printer to spit out a <strong><em>lot</em></strong> of plastic at once, letting you build must taller prints much faster. Larger filament can also provide a much wider base for the next layer to rest on; smaller filament needs to print multiple times side-by-side to get the same width.</p>
<p>Of course the fineness of the layers will suffer, but you can go about twice as high in one pass compared to when you use the smaller filament. On the flip side, the smaller filament will more easily print extremely fine layers than the bigger filament. So it's a trade off.</p>
<p>Consider the printers building items feet or tens of feet in height. They use "filaments" that are measured in centimeters or decimeter a instead of millimeters.</p>
| 144
|
<p>Suppose I have some code that would, in theory, compile against <em>any</em> version of the .net framework. Think "Hello World", if you like. </p>
<p>If I actually compile the code, though, I'll get an executable that runs against one <em>particular</em> version. </p>
<p>Is there any way to arrange things so that the compiled exe will just run against whatever version it finds? I strongly suspect that the answer is no, but I'd be happy to be proven wrong...</p>
<hr>
<p>Edit: Well, I'll go to the foot of our stairs. I had no idea that later frameworks would happily run exe's compiled under earlier versions. Thanks for all the responses!</p>
|
<p>Im not sure if this is correct, but i'd try to compile it for the lowest version, the higher versions should be able to run the lower versions exe's.</p>
|
<p>Along side multi targeting, the frameworks are backwards compatible, so something compiled to 1.0 will run on 1.1 and 2. Somthing compiled on 1.1 will run on 2 ... etc.</p>
| 6,556
|
<p>I'm a longtime Java programmer working on a PHP project, and I'm trying to get PHPUnit up and working. When unit testing in Java, it's common to put test case classes and regular classes into separate directories, like this -</p>
<pre><code>/src
MyClass.java
/test
MyClassTest.java
</code></pre>
<p>and so on.</p>
<p>When unit testing with PHPUnit, is it common to follow the same directory structure, or is there a better way to lay out test classes? So far, the only way I can get the "include("MyClass.php")" statement to work correctly is to include the test class in the same directory, but I don't want to include the test classes when I push to production.</p>
|
<p>I think it's a good idea to keep your files separate. I normally use a folder structure like this:</p>
<pre><code>/myapp/src/ <- my classes
/myapp/tests/ <- my tests for the classes
/myapp/public/ <- document root
</code></pre>
<p>In your case, for including the class in your test file, why not just pass the the whole path to the include method?</p>
<pre><code>include('/path/to/myapp/src/MyClass.php');
</code></pre>
<p>or </p>
<pre><code>include('../src/MyClass.php');
</code></pre>
|
<p>I put my test cases next the the source in a file with the same name but a .phpt extension. The deployment script simply filters out *.phpt when they push to production.</p>
| 9,135
|
<p>I am a <code>C/C++</code> programmer professionally, but I've created a couple of personal web sites using <code>PHP and MySQL</code>. </p>
<p>They're pretty basic, and I'd like to jazz them up using <code>Ajax</code>, but I've never done any Ajax. I've done all the development so far manually, i.e. no IDE or anything like that.</p>
<p><strong>Does anyone have suggestions on Ajax development environments that can help me?</strong></p>
<p>Shareware or freeware would be preferable as I'd find it hard to justify spending more than a minimal amount of money on this...</p>
|
<p>As T.O. says, try Aptana. There's a very good free version, and they really push the AJAX. They even have Jaxer, an "AJAX Server" that they're working on. If nothing else, the plugins are great, and, other than a few quirks, I really like working in it.</p>
|
<p>First off, make sure you understand the basics of the HTTP protocol. Then learn how the javascript httpXmlRequest function works. Once you've covered those, pick an Ajax library - prototype is good.</p>
<p>Then look at a few examples, and follow the API.</p>
<p>Job done.</p>
<p>I seriously have no idea how they manage to write entire books on this subject.</p>
<p>Edit: Why vote me down? Learning the basics first, leads to a much better understanding of the way it works. And yes, I believe Jeff should learn C too ;-P</p>
| 4,316
|
<p>I know this is not programming directly, but it's regarding a development workstation I'm setting up.</p>
<p>I've got a Windows Server 2003 machine that needs to be on two LAN segments at the same time. One of them is a 10.17.x.x LAN and the other is 10.16.x.x</p>
<p>The problem is that I don't want to be using up the bandwidth on the 10.16.x.x network for internet traffic, etc (this network is basically only for internal stuff, though it does have internet access) so I would like the system to use the 10.17.x.x connection for anything that is external to the LAN (and for anything on 10.17.x.x of course, and to only use the 10.16.x.x connection for things that are on <em>that</em> specific LAN.</p>
<p>I've tried looking into the windows "route" command but it's fairly confusing and won't seem to let me delete routes tha tI believe are interfering with what I want it to do. Is there a better way of doing this? Any good software for segmenting your LAN access?</p>
|
<p>I'm no network expert but I have fiddled with the route command a number of times...</p>
<pre><code>route add 0.0.0.0 MASK 0.0.0.0 <address of gateway on 10.17.x.x net>
</code></pre>
<p>Will route all default traffic through the 10.17.x.x gateway, if you find that it still routes through the other interface, you should make sure that the new rule has a lower metric than the existing routes. Do this by adding METRIC 1 for example to the end of the line above.</p>
<p>You could also adjust the metric in the Advanced TCP/IP Settings window of the 10.17.x.x interface, unticking the Automatic Metric checkbox and setting the value to something low, like 1 or 2.</p>
|
<p>If you don't move your network cables around and can assign yourself a static IP address on the 10.16.x.x network, you can refrain from assigning a gateway address on that network. If there is no gateway, internet packets will not be routed on that interface.</p>
<p>If you use DHCP, static record to recognize your MAC address and not provide a gateway IP address.</p>
<p>As for using advanced windows routing, the route you are looking for is the 0.0.0.0 route (default route). The important number is the metric value, which is the cost for the route, where the lower metric tends to be used first. You can set the metric at the interface level directly in the GUI.</p>
<p><a href="https://web.archive.org/web/1/http://articles.techrepublic%2ecom%2ecom/i/tr/cms/contentPics/tcpip-F.gif" rel="nofollow noreferrer">https://web.archive.org/web/1/http://articles.techrepublic%2ecom%2ecom/i/tr/cms/contentPics/tcpip-F.gif</a></p>
<p>I believe if you set the interface metric to a high value on the 10.16.x.x interface, it will not be used as a gateway.</p>
<p>Personally I use the method where I refrain from defining a gateway IP.</p>
| 3,837
|
<p>I'm thinking about building my own 3D printer/Laser Engraver/CNC. Since all use a standard Cartesian axis I wanted to be able to swap out tool heads depending on the purpose. I have everything thought out except the coding aspect of the project.</p>
<p>I currently own a 3D printer and am familiar with some of the coding aspects, gcode, stepper motor moment, axis zeroing, etc; but if I am to build a 3 axis system how do you go about coding it? Are there programs that automatically calibrate all the motors? Can I take existing 3D printer programs and adjust the stepper motor values and build plate area? or do I have to code a new printing program from scratch that can read gcode? For simplicity lets just talk about the printing aspect of the build as I realize that CNC's and laser engravers work on different vector systems. Thanks :)</p>
|
<p>The foundation of any 3D printer is the controller and the firmware. Many devices are based on Arduino type controllers, with stepper motor driver boards either integrated or added as a plug-in component.</p>
<p>Some manufacturers will use in-house or outside resources and develop their own boards and firmware.</p>
<p>You can search for 3D printer controllers and get a pretty comprehensive list of the various devices available for purchase. Smoothieboard is one device, Raspberry Pi and Arduino as noted above, and others.</p>
<p>There can be found varying "flavors" of firmware to load onto these controllers as well.</p>
<p>The field is exhaustive.</p>
<p>To address your focus regarding the printing aspect, that's one stepper motor per print head/nozzle (usually) and involves calibrating the amount of filament dispensed from the nozzle per unit steps, or more easily understood, amount of steps per unit of filament movement. My stepper motor for the extruder has a planetary gear and moves 100 mm of filament for about 5000 steps.</p>
<p>All of the parameters you've noted are integrated with the firmware. Motor calibration requires movement per step or steps per millimeter to be entered, unless you purchase a turnkey system with the values loaded.</p>
<p>You can adjust many of the parameters from the slicing software, but it's more practical to determine the calibration settings, enter that information into your slicer and proceed with model management.</p>
<p>Look into instructables for others' build projects to see what they've accomplished and the steps involved in such a build. This can give you a starting point for your efforts.</p>
|
<p>this is an extension to fred_dot_u answer.
As I am in the process of building my own printer, I decided to use RAMPS Arduino shield for electronics and Marlin firmware + Arduino mega2560 as a logic controller. </p>
<p>As above are battle-tested, I don't need to discover wheel again, but rather focus on the mechanics.
The RAMPS mainboard will provide you with the ability to connect 5 steppers and 3 PWM regulated devices (that can be heat-bed, nozzle and fan or combination) and there is still possibility to connect more as a bunch of IO pins are ready to alocate. </p>
<p>MarlinFirmware is avalible on github, so you can download it and then provide all mechanical parameters that are needed to properly drive your printer -so that is:</p>
<ol>
<li>Mainboard type</li>
<li>type coreXY, XZ ....</li>
<li>bed size (x,y)</li>
<li>gantry size (z)</li>
<li>steps / mm for steppers</li>
<li>thermal protection parameters </li>
<li>LCD display (if in use)</li>
</ol>
<p>The main benefit of using Marlin for me is that printer configuration is extremely customizable.</p>
| 884
|
<p>Dictionaries unlike lists are not ordered (and do not have the 'sort' attribute). Therefore, you can not rely on getting the items in the same order when first added. </p>
<p>What is the easiest way to loop through a dictionary containing strings as the key value and retrieving them in ascending order by key?</p>
<p>For example, you had this:</p>
<pre><code>d = {'b' : 'this is b', 'a': 'this is a' , 'c' : 'this is c'}
</code></pre>
<p>I want to print the associated values in the following sequence sorted by key:</p>
<pre><code>this is a
this is b
this is c
</code></pre>
|
<p>Do you mean that you need the values sorted by the value of the key?
In that case, this should do it:</p>
<pre><code>for key in sorted(d):
print d[key]
</code></pre>
<p><strong>EDIT:</strong> changed to use sorted(d) instead of sorted(d.keys()), thanks <a href="https://stackoverflow.com/users/1694/eli-courtwright">Eli</a>!</p>
|
<pre><code>>>> d = {'b' : 'this is b', 'a': 'this is a' , 'c' : 'this is c'}
>>> for k,v in sorted(d.items()):
... print v, k
...
this is a a
this is b b
this is c c
</code></pre>
| 7,891
|
<p>I'm looking for the best method to parse various XML documents using a Java application. I'm currently doing this with SAX and a custom content handler and it works great - zippy and stable. </p>
<p>I've decided to explore the option having the same program, that currently recieves a single format XML document, receive two additional XML document formats, with various XML element changes. I was hoping to just swap out the ContentHandler with an appropriate one based on the first "startElement" in the document... but, uh-duh, the ContentHandler is set and <strong>then</strong> the document is parsed!</p>
<pre><code>... constructor ...
{
SAXParserFactory spf = SAXParserFactory.newInstance();
try {
SAXParser sp = spf.newSAXParser();
parser = sp.getXMLReader();
parser.setErrorHandler(new MyErrorHandler());
} catch (Exception e) {}
... parse StringBuffer ...
try {
parser.setContentHandler(pP);
parser.parse(new InputSource(new StringReader(xml.toString())));
return true;
} catch (IOException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
}
...
</code></pre>
<p>So, it doesn't appear that I can do this in the way I initially thought I could.</p>
<p>That being said, am I looking at this entirely wrong? What is the best method to parse multiple, discrete XML documents with the same XML handling code? <a href="https://stackoverflow.com/questions/23106/best-method-to-parse-various-custom-xml-documents-in-java">I tried to ask in a more general post earlier... but, I think I was being too vague</a>. For speed and efficiency purposes I never really looked at DOM because these XML documents are fairly large and the system receives about 1200 every few minutes. It's just a one way send of information</p>
<p>To make this question too long and add to my confusion; following is a mockup of some various XML documents that I would like to have a single SAX, StAX, or ?? parser cleanly deal with. </p>
<p>products.xml:</p>
<pre><code><products>
<product>
<id>1</id>
<name>Foo</name>
<product>
<id>2</id>
<name>bar</name>
</product>
</products>
</code></pre>
<p>stores.xml:</p>
<pre><code><stores>
<store>
<id>1</id>
<name>S1A</name>
<location>CA</location>
</store>
<store>
<id>2</id>
<name>A1S</name>
<location>NY</location>
</store>
</stores>
</code></pre>
<p>managers.xml:</p>
<pre><code><managers>
<manager>
<id>1</id>
<name>Fen</name>
<store>1</store>
</manager>
<manager>
<id>2</id>
<name>Diz</name>
<store>2</store>
</manager>
</managers>
</code></pre>
|
<p>As I understand it, the problem is that you don't know what format the document is prior to parsing. You could use a delegate pattern. I'm assuming you're not validating against a DTD/XSD/etcetera and that it is OK for the DefaultHandler to have state.</p>
<pre><code>public class DelegatingHandler extends DefaultHandler {
private Map<String, DefaultHandler> saxHandlers;
private DefaultHandler delegate = null;
public DelegatingHandler(Map<String, DefaultHandler> delegates) {
saxHandlers = delegates;
}
@Override
public void startElement(String uri, String localName, String name,
Attributes attributes) throws SAXException {
if(delegate == null) {
delegate = saxHandlers.get(name);
}
delegate.startElement(uri, localName, name, attributes);
}
@Override
public void endElement(String uri, String localName, String name)
throws SAXException {
delegate.endElement(uri, localName, name);
}
//etcetera...
</code></pre>
|
<p>If you want more dynamic handling, Stax approach would probably work better than Sax.
That's quite low-level, still; if you want simpler approach, XStream and JAXB are my favorites. But they do require quite rigid objects to map to.</p>
| 5,050
|
<p>How much database performance overhead is involved with using C# and LINQ compared to custom optimized queries loaded with mostly low-level C, both with a SQL Server 2008 backend?</p>
<p>I'm specifically thinking here of a case where you have a fairly data-intensive program and will be doing a data refresh or update at least once per screen and will have 50-100 simultaneous users.</p>
|
<p>As Daniel McPherson said, this is caused when SSPs are deleted but the associated
job are not and attempt to communicate with the deleted database.<br><br>If the SSP
database has been deleted or a problem occurred when deleting an SSP, the job may
not be deleted. When the job attempts to run, it will fail since the database no
longer exists.</p>
<p>Follow the steps Daniel mentioned:<br>
1. Go to SQL Server Management Studio <br>
2. Disable the job called SSPNAME_JobDeleteExpiredSessions, right click and choose Disable Job.</p>
|
<p>Have you tried removing the SSP using the command line? I found this worked once when we had a broken an SSP and just wanted to get rid of it.</p>
<p>The command is:</p>
<pre><code>stsadm.exe -o deletessp -title <sspname> [-deletedatabases]
</code></pre>
<p>The <code>deletedatbases</code> switch is optional.</p>
<hr>
<p>Also, check in Central Administration under Job Definitions and Job Schedules to ensure no SSP related jobs are still running</p>
| 2,676
|
<p>This is from an example accompanying the agsXMPP .Net assembly. I've read up on delegates, but am not sure how that fits in with this line of code (which waits for the logon to occur, and then sends a message. I guess what I'm looking for is an understanding of why <code>delegate(0)</code> accomplishes this, in the kind of simple terms I can understand.</p>
<pre><code>xmpp.OnLogin += delegate(object o) {
xmpp.Send(new Message(new Jid(JID_RECEIVER),
MessageType.chat,
"Hello, how are you?"));
};
</code></pre>
|
<p>It's exactly the same as</p>
<pre><code>xmpp.OnLogin += EventHandler(MyMethod);
</code></pre>
<p>Where MyMethod is</p>
<pre><code>public void MyMethod(object o)
{
xmpp.Send(new Message(new Jid(JID_RECEIVER), MessageType.chat, "Hello, how are you?"));
}
</code></pre>
|
<p>That is creating an anonymous function. This feature was introduced in C# 2.0</p>
| 9,865
|
<p>What is reflection, and why is it useful?</p>
<p>I'm particularly interested in Java, but I assume the principles are the same in any language.</p>
|
<p>The name reflection is used to describe code which is able to inspect other code in the same system (or itself).</p>
<p>For example, say you have an object of an unknown type in Java, and you would like to call a 'doSomething' method on it if one exists. Java's static typing system isn't really designed to support this unless the object conforms to a known interface, but using reflection, your code can look at the object and find out if it has a method called 'doSomething' and then call it if you want to.</p>
<p>So, to give you a code example of this in Java (imagine the object in question is foo) :</p>
<pre><code>Method method = foo.getClass().getMethod("doSomething", null);
method.invoke(foo, null);
</code></pre>
<p>One very common use case in Java is the usage with annotations. JUnit 4, for example, will use reflection to look through your classes for methods tagged with the @Test annotation, and will then call them when running the unit test.</p>
<p>There are some good reflection examples to get you started at <a href="http://docs.oracle.com/javase/tutorial/reflect/index.html" rel="noreferrer">http://docs.oracle.com/javase/tutorial/reflect/index.html</a></p>
<p>And finally, yes, the concepts are pretty much similar in other statically typed languages which support reflection (like C#). In dynamically typed languages, the use case described above is less necessary (since the compiler will allow any method to be called on any object, failing at runtime if it does not exist), but the second case of looking for methods which are marked or work in a certain way is still common.</p>
<p><strong>Update from a comment:</strong></p>
<blockquote>
<p>The ability to inspect the code in the system and see object types is
not reflection, but rather Type Introspection. Reflection is then the
ability to make modifications at runtime by making use of
introspection. The distinction is necessary here as some languages
support introspection, but do not support reflection. One such example
is C++</p>
</blockquote>
|
<p><strong>IMPORTANT</strong></p>
<p>Starting from Java 9 you can no longer use reflection, unless the package-info.java <strong>opens</strong> the module to reflection access.</p>
<p>By default, "reflection" access is denied to all packages in the module.</p>
<p>See <a href="https://www.oracle.com/corporate/features/understanding-java-9-modules.html" rel="nofollow noreferrer">Understanding Java 9 Modules</a></p>
| 5,840
|
<p>I'm a Java-developer toying with Ruby, and loving it. I have understood that because of Ruby's metaprogramming facilities my unit-tests become much cleaner and I don't need nasty mocking frameworks. I have a class which needs the <code>File</code> class's services and in my test I don't want to touch my real filesystem. In Java I would use some virtual file system for easier "seams" to pass fake-objects in but in Ruby that's obviously overkill. What I come up seems already really nice compared to the Java-world. In my class under test I have an optional constructor parameter: </p>
<pre><code>def initialize(file_class=File)
</code></pre>
<p>When I need to open files within my class, I can then do this:</p>
<pre><code>@file_class.open(filename)
</code></pre>
<p>And the call goes to either the real File-class, or in case of my unit-test, it goes to a fake-class which doesn't touch the filesystem. I know there must be a better way to do this with metaprogramming?</p>
|
<p>Mocha (<a href="http://mocha.rubyforge.org/" rel="noreferrer">http://mocha.rubyforge.org/</a>) is a very good mocking library for ruby. Depending on what you're actually wanting to test (i.e. if you want to just fake out the File.new call to avoid the file system dependency or if you want to verify that the correct arguments are passed into File.new) you could do something like this:</p>
<pre>
<code>
require 'mocha'
mock_file_obj = mock("My Mock File") do
stubs(:some_instance_method).returns("foo")
end
File.stubs(:new).with(is_a(String)).returns(mock_file_obj)
</code>
</pre>
|
<p>In the case you've outlined, I'd suggest that what you're doing seems fine. I know that it's a technique that James Mead (the author of Mocha) has advocated. There's no need to do metaprogramming just for the sake of it. <a href="http://www.floehopper.org/articles/2007/11/29/mock-object-injection" rel="nofollow noreferrer">Here's what James has to say about it</a> (and a long list of other techniques you could try)</p>
| 9,785
|
<p>I'm trying to create a standard way of rolling out web applications for our company. Currently we do it with zip files, vbscript/javascript, and manual some steps. </p>
<p>For thick client installs we generate MSI installers using Wise/Wix. We don't create installers currently for websites as in general they are just xcopy deploy. However we have some config files that need to be changed, verify that certain handlers are registered in IIS... The list goes on.</p>
<p>Do most people use MSI installers for web applications as well, or some other tool/scripting language?</p>
|
<p>I recently spent a few days working on automating deployments at my company. </p>
<p>We use a combination of CruiseControl, NAnt, MSBuild to generate a release version of the app. Then a separate script uses MSDeploy and XCopy to backup the live site and transfer the new files over. </p>
<p>Our solution is briefly described in an answer to this question <a href="https://stackoverflow.com/questions/45783/automate-deployment-for-web-applications">Automate Deployment for Web Applications?</a></p>
|
<p>You may want to look at:</p>
<ol>
<li><a href="https://stackoverflow.com/questions/55323/aspnet-web-application-build-output-how-do-i-include-all-deployment-files">How do I get a deployable output from a build script with ASP.NET</a></li>
<li><a href="https://stackoverflow.com/questions/57762/step-by-step-aspnet-automated-builddeploy#59274">Step by Step ASP.NET Automated Build/Deploy</a></li>
</ol>
<p>We use MSI to create basic installers for our web projects too, often using the Web Setup Projects in VS and sometimes completely custom installers. You may also want to look at <a href="http://blogs.iis.net/msdeploy/" rel="nofollow noreferrer">MSDeploy</a>.</p>
| 8,381
|
<p>I have an Adventurer 3 printer from Flashforge and every time I unclog it, it gets clogged up again. I’ve done about 6 or 7 prints with it. So after I unclog it, I load the filament and it comes out of the nozzle like it should but once I start a 3D print, it’s clogged again. The process of what I do to unclog it is by heating the nozzle up and then shove a small metal rod down the nozzle to push out the clogged filament. I do this several times until its all gone. I’ve read up on what I can do to prevent it but it doesn’t seem to work. What should I do? <img src="https://i.stack.imgur.com/WT9Cg.jpg" alt="enter image description here"><img src="https://i.stack.imgur.com/1zjzA.jpg" alt="enter image description here"></p>
|
<p>I can see from the photo that filament melted and frozen thicker inside extruder. This is the problem and not the clogged extruder. This thick part produce a lot of friction and actually diameter grow until the print finally will stuck. Basically I had the same problem and I could guess that you are also using Bowden setup. The length of this built thicker part is actually corresponded to your retraction length setting in your slicer (the default value in Cura is unreasonably big like 6.5 millimetres). I solved the same problem by decreasing retraction settings to about 2-3 mm. Just try it and I am sure you will not have this problem again.</p>
|
<p>The Flashforge documentation is not much help, so unless there's a way for you to connect with their user community (because, maybe what you're dealing with is a known issue related to firmware or the machine itself) or Flashforge's customer service folks, you've got some fun detective work ahead of you. Seriously--you will enjoy solving this!</p>
<p>So: It will help to teach yourself the ABC's of clog symptoms, so you can see what the cause(s) <em>could</em> and <em>couldn't</em> be, in your situation. This is <a href="https://rigid.ink/blogs/news/clogged-extruder-nozzle-what-causes-it-how-to-avoid-it-and-how-to-fix-it" rel="nofollow noreferrer">not a bad starter guide</a>, and there are lots of others. You say you've "read up" on preventive measures--that's great! When your original post says, "but it doesn’t seem to work," please understand, though, that we who read don't yet know what "it" <em>means</em>, in this case. Clarity & details are you friends here. </p>
| 1,024
|
<p>What are the "magic numbers" people refer to regarding print resolution on the Monoprice Select Mini?</p>
|
<p>The "magic numbers" are optimal values that work particularly well for the layer height. Michael O'Brien derived these numbers by reverse engineering the <a href="https://hackaday.io/project/12696-monoprice-select-mini-electro-mechanical-upgrades/log/44772-x-y-z-a-motors-stepper-driver-investigation" rel="noreferrer">mechanics of the Z-axis stepper motor</a>.</p>
<p>Using these values as your layer height will generally improve your print quality over using round layer heights such as 0.15, 0.2, or 0.25 by eliminating quantization errors.</p>
<p>To see an example of this, print a copy of <a href="http://www.thingiverse.com/thing:763622" rel="noreferrer">3DBenchy</a> at 0.15 and 0.175. On the 0.15, you will see some wavy patterns on the curved bow portion compared to the 0.175. This is the result of inexact rounding.</p>
<pre><code>Layer Height (mm)
0.04375 (results may vary)*
0.0875
0.13125
0.175
0.21875
0.2625
0.30625
</code></pre>
|
<p>Though this approach is logical on paper, in the real world it doesnt work as well. Even if you do choose a magic number for the layer height, you cant gurentee that your print head, once homed at the beginning of a print, is using a full step of the motor. Its more common to be on a half step than a full step with a motor</p>
| 576
|
<p>I am in the middle of reading the excellent <a href="https://rads.stackoverflow.com/amzn/click/com/0132350882" rel="noreferrer" rel="nofollow noreferrer">Clean Code</a></p>
<p>One discussion is regarding passing nulls into a method.</p>
<pre><code>public class MetricsCalculator {
public double xProjection(Point p1, Point p2) {
return (p2.x - p1.x) * 1.5;
}
}
...
calculator.xProjection(null, new Point(12,13));
</code></pre>
<p>It represents different ways of handling this:</p>
<pre><code>public double xProjection(Point p1, Point p2) {
if (p1 == null || p2 == null) {
throw new IllegalArgumentException("Invalid argument for xProjection");
}
return (p2.x - p1.x) * 1.5;
}
public double xProjection(Point p1, Point p2) {
assert p1 != null : "p1 should not be null";
assert p2 != null : "p2 should not be null";
return (p2.x - p1.x) * 1.5;
}
</code></pre>
<p>I prefer the <a href="http://java.sun.com/j2se/1.4.2/docs/guide/lang/assert.html" rel="noreferrer">assertions</a> approach, but I don't like the fact that assertions are turned off by default.</p>
<p>The book finally states:</p>
<blockquote>
<p>In most programming languages there is no good way to deal with a null that is passed by a caller accidentally. Because this is the case, the rational approach is to forbid passing null by default.</p>
</blockquote>
<p>It doesn't really go into how you would enforce this restriction?</p>
<p>Do any of you have strong opinions either way.</p>
|
<p>General rule is if your method doesn't expect <code>null</code> arguments then you should throw <a href="http://msdn.microsoft.com/en-us/library/system.argumentnullexception.aspx" rel="nofollow noreferrer">System.ArgumentNullException</a>. Throwing proper <code>Exception</code> not only protects you from resource corruption and other bad things but serves as a guide for users of your code saving time spent debugging your code.</p>
<p>Also read an article on <a href="http://en.wikipedia.org/wiki/Defensive_programming" rel="nofollow noreferrer">Defensive programming</a></p>
|
<p>Thwrowing C# <code>ArgumentException</code>, or Java <code>IllegalArgumentException</code> right at the beginning of the method looks to me as the clearest of solutions. </p>
<p>One should always be careful with Runtime Exceptions - exceptions that are not declared on the method signature. Since the compiler doesn't enforce you to catch these it's really easy to forget about them. Make sure you have some kind of a "catch all" exception handling to prevent the software to halt abruptly. That's the most important part of your user experience.</p>
| 5,220
|
<p>I need to get the first and last day of a month in the format YYYY-MM-DD given only the month and year. Is there a good, easy way to do this?</p>
|
<pre><code>$first = date('Y-m-d', mktime(0, 0, 0, $month, 1, $year));
$last = date('Y-m-t', mktime(0, 0, 0, $month, 1, $year));
</code></pre>
<p>See <a href="http://ie2.php.net/date" rel="noreferrer">date()</a> in PHP documentation.</p>
|
<p>By the way @ZombieSheep solution </p>
<pre><code>date ('Y-m-d', mktime(0,0,0,$MM + 1,-1,$YYYY));
</code></pre>
<p>does not work it should be </p>
<pre><code>date ('Y-m-d', mktime(0,0,0,$MM + 1,0,$YYYY)); // Day zero instead of -1
</code></pre>
<p>Of course @Michał Słaby's accepted solution is the simplest.</p>
| 6,520
|
<p>I have a Team Foundation Server 2008 Installation and a separate machine with the Team Build service.</p>
<p>I can create team builds and trigger them manually in Visual Studio or via the command line (where they complete successfully). However check ins to the source tree do not cause a build to trigger despite the option to build every check in being ticked on the build definition. <strong>Update: To be clear I had a fully working build definition with the CI option enabled.</strong></p>
<p>The source tree is configured is a pretty straight forward manner with code either under a <em>Main</em> folder or under a <em>Branch\branchName</em> folder. Each branch of code (including main) has a standard Team Build definition relating to the solution file contained within. The only thing that is slightly changed from default settings is that the build server working folder; i.e. for main this is <em>Server:"$\main" Local:"c:\build\main"</em> due to path length. </p>
<p>The only thing I've been able to guess at (possible red herring) is that there might be some oddity with the developer workspaces. Currently each developer maps Server:"$\" to local:"c:\tfs\" so that there is only one workspace for all branches. This is mainly to avoid re-mapping problems that some of the developers had previously gotten themselves into. But I can't see how this would affect CI.</p>
<p><strong>UPDATE: Ifound the answer indirectly; please read below</strong></p>
|
<p>Ok I have found the answer myself after several dead ends. In the end I fixed this unintentionally while fixing another issue. Basically we had just turned on the automatic execution of unit tests for our builds. The test would run sucessfully but then immediately the build would bomb out with a message saying it was unable to report to the build drop folder. </p>
<p>What was happening was that while the Build service runs under one account and has a set of rights; some of the functionality is actually driven through the TFSService account. fter wading a heap of permissions I had my tests being reported. Then I noticed that builds had started to trigger on check-ins; I can't tell you exactly which permission fixed this but hopefully this answer will at least set people down the right path.</p>
<p>One other note a few of the builds started failing due to conflicting workspace mappings - this was a separate issue that I resolved by deleting some obsolete workspaces using the Attrice Sidekicks for Team Foundation tool.</p>
<p>Hope this helps somebody else.</p>
|
<p>Select your team project from team explorer, then right click on the Builds folder. Select a new build definition and then select the trigger tab. Move the radio button to "Build each check-in (more builds)"</p>
<p>More info can be found here</p>
<p><a href="http://msdn.microsoft.com/en-us/library/ms181716.aspx" rel="nofollow noreferrer">MSDN How to: Create a Build Definition</a></p>
| 6,543
|
<p><a href="http://www.realtimesoft.com/ultramon/" rel="noreferrer">Ultramon</a> is a great program for dual monitors (stretching screen across monitors), but I was wondering if there is any way do to something in Visual Studio like have one tab of code open on one monitor and a second tab of code open on the second monitor with only one instance of Visual Studio running?</p>
<p>Or are there any other suggestions on getting most bang for buck on dual monitors and Visual Studio?</p>
|
<p>Personally, I have my windows set up so that one my main monitor, I have the main visual studio monitor, so therefore my code window, maximized, with only the toolbox docked, on the left. This means the code window takes up as much space as possible, while keeping the left hand edge of the code close to the middle of the screen, where my eyes naturally look. My main monitor is a wide screen, so I find that gives me more than enough room for my code.</p>
<p>My secondary monitor has a second window, which contains the tool windows that I use. So I have solution explorer, error list, task list (//todo: comments), output window, find results etc. all taking up as much space as they like on my secondary monitor.</p>
<p>When debugging, the solution explorer moves the main monitor, and the watch, autos and locals windows take its place.</p>
<p>I find this gives me a very large area to write code, and really helps usage of all of those additional windows, by giving them more real estate than they'd usually have.</p>
<p><strong>Update:</strong> In response to everyone talking about using the second monitor for documentation or running the app, I wholeheartedly agree, and forgot to mention how I do that. I use <a href="http://www.abstractpath.com/powermenu/" rel="noreferrer">PowerMenu</a> alot to acheive this. Basically I can right-click on any window and set Always On Top. So while i'm debugging, i want to see my output window, but then if I have to refer to some documentation, I just flick to Mozilla (on the second monitor), set it on top, and go back to visual studio. I find this lets me manage the tool windows without having to either shuffle them around a lot, or take up valuable space in the code window.</p>
|
<p>You could try right-clicking a file in solution explorer, Open With, and then go find devenv.exe. That will open it up in a new instance of VS. Plus, it saves devenv as one of your default options in the future, so you don't have to go hunting around for devenv all the time. Not beautiful, but an option.</p>
| 2,863
|
<p>I'm looking into sending regular automated text-messages to a list of subscribed users. Having played with Windows Mobile devices, I could easily implement this using the compact .Net framework + a device hooked up to usb and send the messages through this. I would like to explore other solutions like having a server or something similar to do this. I just have no idea what is involved in such a system.</p>
|
<p>It really all depends on how many text messages you intend to send and how critical it is that the message arrives on time (and, actually arrives).</p>
<h2>SMS Aggregators</h2>
<p>For larger volume and good reliability, you will want to go with an SMS aggregator. These aggregators have web service API's (or SMPP) that you can use to send your message and find out whether your message was delivered over time. Some examples of aggregators with whom I have experience are Air2Web, mBlox, etc.</p>
<p>The nice thing about working with an aggregator is that they can guide you through what it takes to send effective messages. For example, if you want your own, distinct, shortcode they can navigate the process with the carriers to secure that shortcode.</p>
<p>They can also make sure that you are in compliance with any rules regarding using SMS. Carriers will flat shut you off if you don't respect the use of SMS and only use SMS within the bounds of what you agreed to when you started to use the aggregator. If you overstep your bounds, they have the aggregator relationships to prevent any service interruptions.</p>
<p>You'll pay per message and may have a baseline service fee. All if this is determined by your volume.</p>
<h2>SMTP to SMS</h2>
<p>If you want an unreliable, low-rent solution to a low number of known addresses, you can use an SMTP to SMS solution. In this case you simply find out the mobile provider for the recipient and use their mobile provider's e-mail scheme to send the message. An example of this is 7705551212@cellcompany.com.</p>
<p>In this scenario, you send the message and it is gone and you hope that it gets there. You really don't know if it is making it. Also, some providers limit how messages come in via their SMTP to SMS gateway to limit SMS spam.</p>
<p>But, that scenario is the very easiest to use from virtually any programming language. There are a million C# examples of how to send e-mail and this way would be no different.</p>
<p>This is the most cost-effective solution (i.e. free) until you get a large volume of messages. When you start doing too much of this, the carriers might step in when they find that you are sending a ton of messages through their SMTP to SMS gateway.</p>
<h2>Effective Texting</h2>
<p>In many cases you have to make sure that recipients have properly opted-in to your service. This is only a big deal if your texts are going to a really large population.</p>
<p>You'll want to remember that text messages are short (keep it to less than 140 to 160 characters). When you program things you'll want to bake that in or you might accidentally send multipart messages.</p>
<p>Don't forget that you will want to make sure that your recipients realize they might have to pay for the incoming text messages. In a world of unlimited text plans this is less and less of a concern.</p>
|
<p>Another technology to send sms messages is text2land.com text to speech technology to send sms messages to landline phones.</p>
| 7,638
|
<p><code>System.Data.SqlClient.SqlException: Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection will be closed.</code></p>
<p>Anybody ever get this error and/or have any idea on it's cause and/or solution?</p>
<p><a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=125227&SiteID=1" rel="nofollow noreferrer">This link may have relevant information.</a></p>
<p><strong>Update</strong></p>
<p>The connection string is <code>=.\SQLEXPRESS;AttachDbFilename=C:\temp\HelloWorldTest.mdf;Integrated Security=True</code></p>
<p>The suggested <code>User Instance=false</code> worked.</p>
|
<p>Here is the answer to your problem:</p>
<p>Very often old user instance creates some temp files that prevent a new SQL Express user instance to be created. When those files are deleted everything start working properly.</p>
<p>First of all confirm that user instances are enabled by running the following SQL in SQL Server Management Studio:</p>
<pre><code>exec sp_configure 'user instances enabled', 1.
GO
Reconfigure
</code></pre>
<p>After running the query restart your SQL Server instance. Now delete the following folder:</p>
<p><code>C:\Documents and Settings\{YOUR_USERNAME}\Local Settings\Application Data\Microsoft\Microsoft SQL Server Data\{SQL_INSTANCE_NAME}</code></p>
<p>Make sure that you replace <code>{YOUR_USERNAME}</code> and <code>{SQL_INSTANCE_NAME}</code> with the appropriate names.</p>
<p>Source: <a href="http://aspdotnetfaq.com/Faq/fix-error-Failed-to-generate-a-user-instance-of-SQL-Server-due-to-a-failure-in-starting-the-process-for-the-user-instance.aspx" rel="noreferrer">Fix error "Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance." </a></p>
|
<p>I started getting this error this morning in a test deployment environment. I was using SQL Server Express 2008 and the error I was getting was</p>
<p>"Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection will be closed."</p>
<p>Unsure about what caused it, I followed the instructions in this post and in other post about deleting the "C:\Users\UserName\AppData\Local\Microsoft\Microsoft SQL Server Data\SQLEXPRESS" directory, but to no avail.</p>
<p>What did the trick for me was to change the connection string from</p>
<p>"Data Source=.\SQLExpress;Initial Catalog=<strong>DBFilePath</strong>;Integrated Security=SSPI;MultipleActiveResultSets=true"</p>
<p>to</p>
<p>"Data Source=.\SQLExpress;Initial Catalog=<strong>DBName</strong>;Integrated Security=SSPI;MultipleActiveResultSets=true"</p>
| 3,500
|
<p>We get a large amount of data from our clients in pdf files in varying formats [layout-wise], these files are typically report output, and are typically properly annotated [they don't usually need OCR], but not formatted well enough that simply copying several hundred pages of text out of acrobat is not going to work.</p>
<p>The best approach I've found so far is to write a script to parse the nearly-valid xml output (the comments are invalid and many characters are escaped in varying ways, é becomes [[[e9]]]é, $ becomes \$, % becomes \%...) of the command-line pdftoipe utility (to convert pdf files for a program called <a href="http://tclab.kaist.ac.kr/ipe/" rel="nofollow noreferrer">ipe</a>), which gives me text elements with their positions on each page [see sample below], which works well enough for reports where the same values are on the same place on every page I care about, but would require extra scripting effort for importing matrix [cross-tab] pdf files. pdftoipe is not at all intended for this, and at best can be compiled manually using cygwin for windows.</p>
<p>Are there libraries that make this easy from some scripting language I can tolerate? A graphical tool would be awesome too. And a pony. </p>
<p>pdftoipe output of <a href="http://brunndahl.navarro.se/sida_002/?CoMeT_function=get_file&id=9_1" rel="nofollow noreferrer" title="sample pdf file">this sample</a> looks like this:</p>
<pre><code><ipe creator="pdftoipe 2006/10/09"><info media="0 0 612 792"/>
<-- Page: 1 1 -->
<page gridsize="8">
<path fill="1 1 1" fillrule="wind">
64.8 144 m
486 144 l
486 727.2 l
64.8 727.2 l
64.8 144 l
h
</path>
<path fill="1 1 1" fillrule="wind">
64.8 144 m
486 144 l
486 727.2 l
64.8 727.2 l
64.8 144 l
h
</path>
<path fill="1 1 1" fillrule="wind">
64.8 144 m
486 144 l
486 727.2 l
64.8 727.2 l
64.8 144 l
h
</path>
<text stroke="1 0 0" pos="0 0" size="18" transformable="yes" matrix="1 0 0 1 181.8 707.88">This is a sample PDF fil</text>
<text stroke="1 0 0" pos="0 0" size="18" transformable="yes" matrix="1 0 0 1 356.28 707.88">e.</text>
<text stroke="1 0 0" pos="0 0" size="18" transformable="yes" matrix="1 0 0 1 368.76 707.88"> </text>
<text stroke="0 0 0" pos="0 0" size="12.6" transformable="yes" matrix="1 0 0 1 67.32 692.4"> </text>
<text stroke="0 0 0" pos="0 0" size="12.6" transformable="yes" matrix="1 0 0 1 67.32 677.88"> </text>
<text stroke="0 0 0" pos="0 0" size="12.6" transformable="yes" matrix="1 0 0 1 67.32 663.36"> </text>
<text stroke="0 0 0" pos="0 0" size="12.6" transformable="yes" matrix="1 0 0 1 67.32 648.84"> </text>
<text stroke="0 0 0" pos="0 0" size="12.6" transformable="yes" matrix="1 0 0 1 67.32 634.32"> </text>
<text stroke="0 0 0" pos="0 0" size="12.6" transformable="yes" matrix="1 0 0 1 67.32 619.8"> </text>
<text stroke="0 0 0" pos="0 0" size="12.6" transformable="yes" matrix="1 0 0 1 67.32 605.28"> </text>
<text stroke="0 0 0" pos="0 0" size="12.6" transformable="yes" matrix="1 0 0 1 67.32 590.76"> </text>
<text stroke="0 0 0" pos="0 0" size="12.6" transformable="yes" matrix="1 0 0 1 67.32 576.24"> </text>
<text stroke="0 0 0" pos="0 0" size="12.6" transformable="yes" matrix="1 0 0 1 67.32 561.72"> </text>
<text stroke="0 0 0" pos="0 0" size="12.6" transformable="yes" matrix="1 0 0 1 67.32 547.2"> </text>
<text stroke="0 0 0" pos="0 0" size="12.6" transformable="yes" matrix="1 0 0 1 67.32 532.68"> </text>
<text stroke="0 0 0" pos="0 0" size="12.6" transformable="yes" matrix="1 0 0 1 67.32 518.16"> </text>
<text stroke="0 0 0" pos="0 0" size="12.6" transformable="yes" matrix="1 0 0 1 67.32 503.64"> </text>
<text stroke="0 0 0" pos="0 0" size="12.6" transformable="yes" matrix="1 0 0 1 67.32 489.12"> </text>
<text stroke="0 0 0" pos="0 0" size="12.6" transformable="yes" matrix="1 0 0 1 67.32 474.6"> </text>
<text stroke="0 0 1" pos="0 0" size="16.2" transformable="yes" matrix="1 0 0 1 67.32 456.24">If you can read this</text>
<text stroke="0 0 1" pos="0 0" size="16.2" transformable="yes" matrix="1 0 0 1 214.92 456.24">,</text>
<text stroke="0 0 1" pos="0 0" size="16.2" transformable="yes" matrix="1 0 0 1 219.48 456.24"> you already have A</text>
<text stroke="0 0 1" pos="0 0" size="16.2" transformable="yes" matrix="1 0 0 1 370.8 456.24">dobe Acrobat </text>
<text stroke="0 0 1" pos="0 0" size="16.2" transformable="yes" matrix="1 0 0 1 67.32 437.64">Reader i</text>
<text stroke="0 0 1" pos="0 0" size="16.2" transformable="yes" matrix="1 0 0 1 131.28 437.64">n</text>
<text stroke="0 0 1" pos="0 0" size="16.2" transformable="yes" matrix="1 0 0 1 141.12 437.64">stalled on your computer.</text>
<text stroke="0 0 0" pos="0 0" size="16.2" transformable="yes" matrix="1 0 0 1 337.92 437.64"> </text>
<text stroke="0 0.502 0" pos="0 0" size="12.6" transformable="yes" matrix="1 0 0 1 342.48 437.64"> </text>
<image width="800" height="600" rect="-92.04 800.64 374.4 449.76" ColorSpace="DeviceRGB" BitsPerComponent="8" Filter="DCTDecode" length="369925">
feedcafebabe...
</image>
</page>
</ipe>
</code></pre>
|
<p>We use <a href="http://www.foolabs.com/xpdf/about.html" rel="nofollow noreferrer">Xpdf</a> in one of our applications. Its a c++ library which is primarily used for pdf rendering, although it does have a text extractor which could be useful for this project.</p>
|
<p>Have you looked at Aspose? We're using it for an ASP.net app and I've seen some examples of vbscript using it as well. It's not particularly expensive either.</p>
<p><a href="http://www.aspose.com/" rel="nofollow noreferrer">http://www.aspose.com/</a></p>
| 4,517
|
<p>I am attempting to POST against a vendor's server using PHP 5.2 with cURL. I'm reading in an XML document to post against their server and then reading in a response:</p>
<pre><code>$request = trim(file_get_contents('test.xml'));
$curlHandle = curl_init($servletURL);
curl_setopt($curlHandle, CURLOPT_POST, TRUE);
curl_setopt($curlHandle, CURLOPT_POSTFIELDS, array('XML'=>$request));
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curlHandle, CURLOPT_HEADER, FALSE); # Have also tried leaving this out
$response = curl_exec($curlHandle);
</code></pre>
<p>That code, in an of itself, works OK, but the other server returns a response from it's XML parser stating:</p>
<blockquote>
<p>Content not allowed in prolog</p>
</blockquote>
<p>I looked that error up and this is normally caused by whitespace before the XML, but I made sure that the XML file itself has no whitespace and the trim() should clear that up anyway. I did a TCPDump on the connection while I ran the code and this is what is sent out:</p>
<pre><code>POST {serverURL} HTTP/1.1
Host: {ip of server}:8080
Accept: */*
Content-Length: 921
Expect: 100-continue
Content-Type: multipart/form-data; boundry:---------------------------01e7cda3896f
---------------------------01e7cda3896f
Content-Disposition: form-data; name="XML"
[SNIP - the XML was displayed]
---------------------------01e7cda3896f--
</code></pre>
<p>Before and after the [SNIP] line there is visible whitespace when I replay the session in Ethereal. Is this what is causing the problem and, if so, how can I remove it, or am I looking too far and this may be an issue with the server I'm posting against?</p>
|
<p>It turns out it's an encoding issue. The app apparently needs the XML in www-form-urlencoded instead of form-data so I had to change:</p>
<pre><code># This sets the encoding to multipart/form-data
curl_setopt($curlHandle, CURLOPT_POSTFIELDS, array('XML'=>$request));
</code></pre>
<p>to</p>
<pre><code># This sets it to application/x-www-form-urlencoded
curl_setopt($curlHandle, CURLOPT_POSTFIELDS, 'XML=' . urlencode($request));
</code></pre>
|
<p>I did a <code>wc -m test.xml</code> and came back with 743 characters in the XML file and the <code>var_dump</code> on <code>$request</code> comes back with 742 characters so something is getting stripped with <code>trim()</code> (I assume).</p>
<p>I did a:</p>
<pre><code>print "=====" . $request . "=====";
</code></pre>
<p>and the start and end of the XML butts right up against the ===== with no white space.</p>
| 3,876
|
<p>I am trying to grab the capital letters of a couple of words and wrap them in span tags. I am using <a href="http://php.net/manual/en/function.preg-replace.php" rel="noreferrer">preg_replace</a> for extract and wrapping purposes, but it's not outputting anything.</p>
<pre><code>preg_replace("/[A-Z]/", "<span class=\"initial\">$1</span>", $str)
</code></pre>
|
<p>You need to put the pattern in parentheses <code>/([A-Z])/</code>, like this:</p>
<pre><code>preg_replace("/([A-Z])/", "<span class=\"initial\">$1</span>", $str)
</code></pre>
|
<p>From the <a href="http://us.php.net/manual/en/function.preg-replace.php" rel="noreferrer">preg_replace documentation</a> on php.net:</p>
<blockquote>
<p><em>replacement</em> may contain references of
the form \n or (since PHP 4.0.4) $n,
with the latter form being the
preferred one. Every such reference
will be replaced by the text captured
by the n'th parenthesized pattern.</p>
</blockquote>
<p>See Flubba's example.</p>
| 2,405
|
<p>I have an ext combobox which uses a store to suggest values to a user as they type. </p>
<p>An example of which can be found here: <a href="http://extjs.com/deploy/ext/examples/form/combos.html" rel="nofollow noreferrer">combobox example</a></p>
<p>Is there a way of making it so the <strong>suggested text list</strong> is rendered to an element in the DOM. Please note I do not mean the "applyTo" config option, as this would render the whole control, including the textbox to the DOM element.</p>
|
<p>You can use plugin for this, since you can call or even override private methods from within the plugin:</p>
<pre><code>var suggested_text_plugin = {
init: function(o) {
o.onTypeAhead = function() {
// Original code from the sources goes here:
if(this.store.getCount() > 0){
var r = this.store.getAt(0);
var newValue = r.data[this.displayField];
var len = newValue.length;
var selStart = this.getRawValue().length;
if(selStart != len){
this.setRawValue(newValue);
this.selectText(selStart, newValue.length);
}
}
// Your code to display newValue in DOM
......myDom.getEl().update(newValue);
};
}
};
// in combobox code:
var cb = new Ext.form.ComboBox({
....
plugins: suggested_text_plugin,
....
});
</code></pre>
<p>I think it's even possible to create a whole chain of methods, calling original method before or after yours, but I haven't tried this yet.</p>
<p>Also, please don't push me hard for using non-standard plugin definition and invocation methodics (undocumented). It's just my way of seeing things.</p>
<p>EDIT:</p>
<p>I think the method chain could be implemented something like that (untested):</p>
<pre><code>....
o.origTypeAhead = new Function(this.onTypeAhead.toSource());
// or just
o.origTypeAhead = this.onTypeAhead;
....
o.onTypeAhead = function() {
// Call original
this.origTypeAhead();
// Display value into your DOM element
...myDom....
};
</code></pre>
|
<p>So clarify, you want the selected text to render somewhere besides directly below the text input. Correct?</p>
<p>ComboBox is just a composite of <a href="http://extjs.com/deploy/dev/docs/?class=Ext.DataView" rel="nofollow noreferrer">Ext.DataView</a>, a text input, and an optional trigger button. There isn't an official option for what you want and hacking it to make it do what you want would be really painful. So, the easiest course of action (other than finding and using some other library with a component that does exactly what you want) is to build your own with the components above:</p>
<ol>
<li>Create a text box. You can use an <a href="http://extjs.com/deploy/dev/docs/?class=Ext.form.TextField" rel="nofollow noreferrer">Ext.form.TextField</a> if you want, and observe the keyup event.</li>
<li>Create a DataView bound to your store, rendering to whatever DOM element you want. Depending on what you want, listen to the 'selectionchange' event and take whatever action you need to in response to the selection. e.g., setValue on an Ext.form.Hidden (or plain HTML input type="hidden" element).</li>
<li>In your keyup event listener, call the store's filter method (see <a href="http://extjs.com/deploy/dev/docs/?class=Ext.data.Store" rel="nofollow noreferrer">doc</a>), passing the field name and the value from the text field. e.g., store.filter('name',new RegEx(value+'.*'))</li>
</ol>
<p>It's a little more work, but it's a lot shorter than writing your own component from scratch or hacking the ComboBox to behave like you want.</p>
| 9,993
|
<p>Unchecked exceptions are alright if you want to handle every failure the same way, for example by logging it and skipping to the next request, displaying a message to the user and handling the next event, etc. If this is my use case, all I have to do is catch some general exception type at a high level in my system, and handle everything the same way.</p>
<p>But I want to recover from specific problems, and I'm not sure the best way to approach it with unchecked exceptions. Here is a concrete example.</p>
<p>Suppose I have a web application, built using Struts2 and Hibernate. If an exception bubbles up to my "action", I log it, and display a pretty apology to the user. But one of the functions of my web application is creating new user accounts, that require a unique user name. If a user picks a name that already exists, Hibernate throws an <code>org.hibernate.exception.ConstraintViolationException</code> (an unchecked exception) down in the guts of my system. I'd really like to recover from this particular problem by asking the user to choose another user name, rather than giving them the same "we logged your problem but for now you're hosed" message.</p>
<p>Here are a few points to consider:</p>
<ol>
<li>There a lot of people creating accounts simultaneously. I don't want to lock the whole user table between a "SELECT" to see if the name exists and an "INSERT" if it doesn't. In the case of relational databases, there might be some tricks to work around this, but what I'm really interested in is the general case where pre-checking for an exception won't work because of a fundamental race condition. Same thing could apply to looking for a file on the file system, etc.</li>
<li>Given my CTO's propensity for drive-by management induced by reading technology columns in "Inc.", I need a layer of indirection around the persistence mechanism so that I can throw out Hibernate and use Kodo, or whatever, without changing anything except the lowest layer of persistence code. As a matter of fact, there are several such layers of abstraction in my system. How can I prevent them from leaking in spite of unchecked exceptions?</li>
<li>One of the declaimed weaknesses of checked exceptions is having to "handle" them in every call on the stack—either by declaring that a calling method throws them, or by catching them and handling them. Handling them often means wrapping them in another checked exception of a type appropriate to the level of abstraction. So, for example, in checked-exception land, a file-system–based implementation of my UserRegistry might catch <code>IOException</code>, while a database implementation would catch <code>SQLException</code>, but both would throw a <code>UserNotFoundException</code> that hides the underlying implementation. How do I take advantage of unchecked exceptions, sparing myself of the burden of this wrapping at each layer, without leaking implementation details?</li>
</ol>
|
<p>IMO, wrapping exceptions (checked or otherwise) has several benefits that are worth the cost:</p>
<p>1) It encourages you to think about the failure modes for the code you write. Basically, you have to consider the exceptions that the code you call may throw, and in turn you'll consider the exceptions you'll throw for the code that calls yours.</p>
<p>2) It gives you the opportunity to add additional debugging information into the exception chain. For instance, if you have a method that throws an exception on a duplicate username, you might wrap that exception with one that includes additional information about the circumstances of the failure (for example, the IP of the request that provided the dupe username) that wasn't available to the lower-level code. The cookie trail of exceptions may help you debug a complex problem (it certainly has for me).</p>
<p>3) It lets you become implementation-independent from the lower level code. If you're wrapping exceptions and need to swap out Hibernate for some other ORM, you only have to change your Hibernate-handling code. All the other layers of code will still be successfully using the wrapped exceptions and will interpret them in the same way, even though the underlying circumstances have changed. Note that this applies even if Hibernate changes in some way (ex: they switch exceptions in a new version); it's not just for wholesale technology replacement.</p>
<p>4) It encourages you use different classes of exceptions to represent different situations. For example, you may have a DuplicateUsernameException when the user tries to reuse a username, and a DatabaseFailureException when you can't check for dupe usernames due to a broken DB connection. This, in turn, lets you answer your question ("how do I recover?") in flexible and powerful ways. If you get a DuplicateUsernameException, you may decide to suggest a different username to the user. If you get a DatabaseFailureException, you may let it bubble up to the point where it displays a "down for maintenance" page to the user and send off a notification email to you. Once you have custom exceptions, you have customizeable responses -- and that's a good thing.</p>
|
<p>You can catch unchecked exceptions without needing to wrap them. For example, the following is valid Java.</p>
<pre><code>try {
throw new IllegalArgumentException();
} catch (Exception e) {
System.out.println("boom");
}
</code></pre>
<p>So in your action/controller you can have a try-catch block around the logic where the Hibernate call is made. Depending on the exception you can render specific error messages. </p>
<p>But I guess in your today it could be Hibernate, and tomorrow SleepLongerDuringWinter framework. In this case you need to pretend to have your own little ORM framework that wraps around the third party framework. This will allow you to wrap any framework specific exceptions into more meaningful and/or checked exceptions that you know how to make better sense of. </p>
| 5,359
|
<p>I had problems with print bed adhesion when using white PLA (Arctic White) but no problems when using other colors. So I tried to print three bottom layers with transparent PLA and all other layers with white PLA. I did not change any setting and printed both tries one after another using the same .stl file.</p>
<p>There was some warping of the printed ring too. No problems when using transparent plus white PLA.</p>
<p><a href="https://i.stack.imgur.com/FngJU.jpg" rel="nofollow noreferrer" title="Photo of two printed rings"><img src="https://i.stack.imgur.com/FngJU.jpg" alt="Photo of two printed rings" title="Photo of two printed rings" /></a></p>
<p>Right: white PLA only, left: transparent PLA bottom layers plus white PLA above. View of the bottom sides.</p>
<p>Has anyone experienced similar problems?</p>
|
<p>Same G-code slice? The main cause of warping is temperature. If this is kept as a control variable and you have these results, it may be because of a different temperature the filament requires. Check the filament specs and adjust the bed/nozzle temperature to make the temperature difference smaller.</p>
<p>Edit: Another reason it might be needing different temperatures is because of absorbing moisture.</p>
|
<p>Problem was displaced by a factory reset of the 3D printer FlashForge Adventurer 3.</p>
<p><a href="https://i.stack.imgur.com/jxS9X.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jxS9X.jpg" alt="Photo of two versions" /></a></p>
<p>Right: white PLA only, left: transparent PLA bottom layers plus white PLA above. View of the bottom sides. No difference of print bed adhesion now.</p>
<p>The reason of the problem was not found, but print bed adhesion is good after the factory reset for both white and transparent PLA.</p>
| 2,047
|
<p>Suppose I have two applications written in C#. The first is a third party application that raises an event called "OnEmailSent".</p>
<p>The second is a custom app that I've written that I would like to somehow subscribe to the "OnEmailSent" even of the first application.</p>
<p>Is there any way that I could somehow attach the second application to an instance of the first application to listen for "OnEmailSent" event?</p>
<hr>
<p>So for further clarification, my specific scenario is that we have a custom third party application written in c# that raises an "OnEmailSent" event. We can see the event exists using reflector.</p>
<p>What we want to do is have some other actions take place when this component sends an email.</p>
<p>The most efficient way we can think of would be to be able to use some form of IPC as anders has suggested and listen for the OnEmailSent event being raised by the third party component.</p>
<p>Because the component is written in C# we are toying with the idea of writing another C# application that can attach itself to the executing process and when it detect the OnEmailSent event has been raise it will execute it's own event handling code.</p>
<hr>
<p>I might be missing something, but from what I understand of how remoting works is that there would need to be a server defining some sort of contract that the client can subscribe to.</p>
<p>I was more thinking about a scenario where someone has written a standalone application like outlook for example, that exposes events that I would like to subscribe to from another application.</p>
<p>I guess the scenario I'm thinking of is the .net debugger and how it can attach to executing assemblies to inspect the code whilst it's running.</p>
|
<p>In order for two applications (separate processes) to exchange events, they must agree on how these events are communicated. There are many different ways of doing this, and exactly which method to use may depend on architecture and context. The general term for this kind of information exchange between processes is <a href="http://en.wikipedia.org/wiki/Inter-process_communication" rel="noreferrer">Inter-process Communication (IPC)</a>. There exists many standard ways of doing IPC, the most common being files, pipes, (network) sockets, <a href="http://en.wikipedia.org/wiki/Remote_procedure_call" rel="noreferrer">remote procedure calls (RPC)</a> and shared memory. On Windows it's also common to use <a href="http://msdn.microsoft.com/en-us/library/aa931932.aspx" rel="noreferrer">window messages</a>.</p>
<p>I am not sure how this works for .NET/C# applications on Windows, but in native Win32 applications you can <a href="http://msdn.microsoft.com/en-us/library/ms644990.aspx" rel="noreferrer">hook on to the message loop of external processes and "spy" on the messages they are sending</a>. If your program generates a message event when the desired function is called, this could be a way to detect it.</p>
<p>If you are implementing both applications yourself you can chose to use any IPC method you prefer. Network sockets and higher-level socket-based protocols like HTTP, XML-RPC and SOAP are very popular these days, as they allow you do run the applications on different physical machines as well (given that they are connected via a network).</p>
|
<p>What's the nature of that OnEmailSent event from that third party application? I mean, how do you know the application is triggering such an event?</p>
<p>If <em>you</em> are planning on doing interprocess communication, the first question you should ask yourself is: Is it really necessary?</p>
<p>Without questioning your motives, if you really need to do interprocess communication, you will need some sort of mechanism. The list is long, very long. From simple WM_DATA messages to custom TCP protocols to very complex Web services requiring additional infrastructures.</p>
<p>This brings the question, what is it you are trying to do exactly? What is this third party application you have no control over?</p>
<p>Also, the debugger has a very invasive way of debugging processes. Don't expect that to be the standard interprocess mechanism used by all other applications. As a matter of fact, it isn't.</p>
| 3,847
|
<p>I am getting the following error trying to read from a socket. I'm doing a <code>readInt()</code> on that <code>InputStream</code>, and I am getting this error. Perusing the documentation this suggests that the client part of the connection closed the connection. In this scenario, I am the server.</p>
<p>I have access to the client log files and it is not closing the connection, and in fact its log files suggest I am closing the connection. So does anybody have an idea why this is happening? What else to check for? Does this arise when there are local resources that are perhaps reaching thresholds?</p>
<hr>
<p>I do note that I have the following line:</p>
<pre><code>socket.setSoTimeout(10000);
</code></pre>
<p>just prior to the <code>readInt()</code>. There is a reason for this (long story), but just curious, are there circumstances under which this might lead to the indicated error? I have the server running in my IDE, and I happened to leave my IDE stuck on a breakpoint, and I then noticed the exact same errors begin appearing in my own logs in my IDE.</p>
<p>Anyway, just mentioning it, hopefully not a red herring. :-(</p>
|
<p>There are several possible causes.</p>
<ol>
<li><p>The other end has deliberately reset the connection, in a way which I will not document here. It is rare, and generally incorrect, for application software to do this, but it is not unknown for commercial software.</p></li>
<li><p>More commonly, it is caused by writing to a connection that the other end has already closed normally. In other words an application protocol error.</p></li>
<li><p>It can also be caused by closing a socket when there is unread data in the socket receive buffer.</p></li>
<li><p>In Windows, 'software caused connection abort', which is not the same as 'connection reset', is caused by network problems sending from your end. There's a Microsoft knowledge base article about this.</p></li>
</ol>
|
<p>In my experience, I often encounter the following situations;</p>
<ol>
<li><p>If you work in a corporate company, contact the network and security team. Because in requests made to external services, it may be necessary to <strong>give permission for the relevant endpoint.</strong></p></li>
<li><p>Another issue is that the <strong>SSL certificate may have expired</strong> on the server where your application is running.</p></li>
</ol>
| 8,844
|
<p>I'm looking for some software that allows me to control a server based application, that is, there are bunch of interdependent processes that I'd like to be able to start up, shut down and monitor in a controller manner.</p>
<p>I've come across programs like Autosys, but that's expensive and very much over the top for what I want. I've also seen <a href="http://appctl.sourceforge.net/" rel="nofollow noreferrer">AppCtl</a>, but that seems not to handle dependencies. Maybe it would be possible to repurpose the init scripts?</p>
<p>Oh, and as an added complication it should be able to run on a Solaris 10 or Linux box without installing any new binaries. On the boxes I've seen recently, that means shell scripts and Perl but not Python.</p>
<p>Do any such programs exist or do I need to dust off my copy of Programming Perl?</p>
|
<p>Try Supervise, which is what qmail uses to keep track of it's services/startup applications:</p>
<p><a href="http://cr.yp.to/daemontools/supervise.html" rel="nofollow noreferrer">http://cr.yp.to/daemontools/supervise.html</a></p>
|
<p>Solaris-only as far as I know, but wouldn't Solaris 10's <a href="http://www.sun.com/bigadmin/content/selfheal/smf-quickstart.jsp" rel="nofollow noreferrer">SMF</a> do what you want?</p>
| 5,871
|
<p>I am looking for a way to interact with a standalone full version of Windows Media Player.<br>
Mostly I need to know the Path of the currently played track.</p>
<p>The iTunes SDK makes this really easy but unfortunately there really isn't any way to do it with Windows Media Player, at least not in .Net(C#) without any heavy use of pinvoke, which I am not really comfortable with.</p>
<p>Thanks</p>
<p>Just to clearify: I don't want to embedded a new instance of Windows Media Player in my app, but instead control/read the "real" full version of Windows Media Player, started seperatly by the user</p>
|
<p>I had this <a href="https://social.msdn.microsoft.com/Forums/vstudio/en-US/dbd43d7e-f3a6-4087-be06-df17e76b635d/windows-media-player-remoting-in-c?forum=clr" rel="nofollow noreferrer">https://social.msdn.microsoft.com/Forums/vstudio/en-US/dbd43d7e-f3a6-4087-be06-df17e76b635d/windows-media-player-remoting-in-c?forum=clr</a> in my bookmarks but have NOT tested it in anyway. Just a pointer in the right direction. It's nothing official and will require a bit of digging, but you should get a fairly simple wrapper (which will still use PInvoke under the hood - but you won't see it) around Windows Media Player.</p>
<p>Hope that helps.</p>
<p>Oh, I misunderstood. I thought you were talking about controlling the currently running Windows Media Player instance. If you are hosting Windows Media Player yourself then WMPLib is certainly the better solution.</p>
|
<p>The best info I have seen on interacting with Windows Media Player is this <a href="http://blogs.msdn.com/toub/archive/2007/09/22/fun-with-dvr-ms.aspx" rel="nofollow noreferrer">article</a> written by Stephen Toub.</p>
<p>He lists a whole load of different ways to play dvr-ms files (doesn't really matter what format they are for this though). The bit that is possibly of interest to you is about using a Media Player ActiveX Control, which you can add to the visual Studio toolbox by right-clicking and adding the Windows Media Player ActiveX COM Control. You can then embed the player into your app, and access various properties of Media Player, like the url:</p>
<pre><code>WMPplayer.URL = stringPathToFile;
</code></pre>
<p>This solution is possibly not what you want because it's starting a new instance of Media Player (as far as I know), however it might point you in the right direction.</p>
| 8,042
|
<p>I have a link on a long HTML page. When I click it, I wish a <code>div</code> on another part of the page to be visible in the window by scrolling into view.</p>
<p>A bit like <code>EnsureVisible</code> in other languages.</p>
<p>I've checked out <code>scrollTop</code> and <code>scrollTo</code> but they seem like red herrings.</p>
<p>Can anyone help?</p>
|
<p>old question, but if anyone finds this through google (as I did) and who does not want to use anchors or jquery; there's a builtin javascriptfunction to 'jump' to an element;</p>
<pre><code>document.getElementById('youridhere').scrollIntoView();
</code></pre>
<p>and what's even better; according to the great compatibility-tables on quirksmode, this is <a href="http://www.quirksmode.org/dom/w3c_cssom.html#t23" rel="noreferrer">supported by all major browsers</a>!</p>
|
<p>Correct me if I'm wrong but I'm reading the question again and again and still think that Angus McCoteup was asking how to set an element to be position: fixed. </p>
<p>Angus McCoteup, check out <a href="http://www.cssplay.co.uk/layouts/fixed.html" rel="nofollow noreferrer">http://www.cssplay.co.uk/layouts/fixed.html</a> - if you want your DIV to behave like a menu there, have a look at a CSS there</p>
| 9,368
|
<p>I read somewhere once that the modulus operator is inefficient on small embedded devices like 8 bit micro-controllers that do not have integer division instruction. Perhaps someone can confirm this but I thought the difference is 5-10 time slower than with an integer division operation.</p>
<p>Is there another way to do this other than keeping a counter variable and manually overflowing to 0 at the mod point?<p></p>
<pre><code>const int FIZZ = 6;
for(int x = 0; x < MAXCOUNT; x++)
{
if(!(x % FIZZ)) print("Fizz\n"); // slow on some systems
}
</code></pre>
<p>vs:</p>
<p>The way I am currently doing it:</p>
<pre><code>const int FIZZ = 6;
int fizzcount = 1;
for(int x = 1; x < MAXCOUNT; x++)
{
if(fizzcount >= FIZZ)
{
print("Fizz\n");
fizzcount = 0;
}
}
</code></pre>
|
<p>Ah, the joys of bitwise arithmetic. A side effect of many division routines is the modulus - so in few cases should division actually be faster than modulus. I'm interested to see the source you got this information from. Processors with multipliers have interesting division routines using the multiplier, but you can get from division result to modulus with just another two steps (multiply and subtract) so it's still comparable. If the processor has a built in division routine you'll likely see it also provides the remainder.</p>
<p>Still, there is a small branch of number theory devoted to <a href="http://en.wikibooks.org/wiki/Discrete_mathematics/Modular_arithmetic" rel="noreferrer">Modular Arithmetic</a> which requires study if you really want to understand how to optimize a modulus operation. Modular arithmatic, for instance, is very handy for generating <a href="http://www.math.utah.edu/~carlson/mathcircles/magic.pdf" rel="noreferrer">magic squares</a>.</p>
<p>So, in that vein, here's a <a href="http://piclist.org/techref/postbot.asp?by=time&id=piclist/2006/08/03/065022a" rel="noreferrer">very low level look</a> at the math of modulus for an example of x, which should show you how simple it can be compared to division:</p>
<hr>
<p>Maybe a better way to think about the problem is in terms of number
bases and modulo arithmetic. For example, your goal is to compute DOW
mod 7 where DOW is the 16-bit representation of the day of the
week. You can write this as:</p>
<pre><code> DOW = DOW_HI*256 + DOW_LO
DOW%7 = (DOW_HI*256 + DOW_LO) % 7
= ((DOW_HI*256)%7 + (DOW_LO % 7)) %7
= ((DOW_HI%7 * 256%7) + (DOW_LO%7)) %7
= ((DOW_HI%7 * 4) + (DOW_LO%7)) %7
</code></pre>
<p>Expressed in this manner, you can separately compute the modulo 7
result for the high and low bytes. Multiply the result for the high by
4 and add it to the low and then finally compute result modulo 7.</p>
<p>Computing the mod 7 result of an 8-bit number can be performed in a
similar fashion. You can write an 8-bit number in octal like so:</p>
<pre><code> X = a*64 + b*8 + c
</code></pre>
<p>Where a, b, and c are 3-bit numbers.</p>
<pre><code> X%7 = ((a%7)*(64%7) + (b%7)*(8%7) + c%7) % 7
= (a%7 + b%7 + c%7) % 7
= (a + b + c) % 7
</code></pre>
<p>since <code>64%7 = 8%7 = 1</code></p>
<p>Of course, a, b, and c are</p>
<pre><code> c = X & 7
b = (X>>3) & 7
a = (X>>6) & 7 // (actually, a is only 2-bits).
</code></pre>
<p>The largest possible value for <code>a+b+c</code> is <code>7+7+3 = 17</code>. So, you'll need
one more octal step. The complete (untested) C version could be
written like:</p>
<pre><code>unsigned char Mod7Byte(unsigned char X)
{
X = (X&7) + ((X>>3)&7) + (X>>6);
X = (X&7) + (X>>3);
return X==7 ? 0 : X;
}
</code></pre>
<p>I spent a few moments writing a PIC version. The actual implementation
is slightly different than described above</p>
<pre><code>Mod7Byte:
movwf temp1 ;
andlw 7 ;W=c
movwf temp2 ;temp2=c
rlncf temp1,F ;
swapf temp1,W ;W= a*8+b
andlw 0x1F
addwf temp2,W ;W= a*8+b+c
movwf temp2 ;temp2 is now a 6-bit number
andlw 0x38 ;get the high 3 bits == a'
xorwf temp2,F ;temp2 now has the 3 low bits == b'
rlncf WREG,F ;shift the high bits right 4
swapf WREG,F ;
addwf temp2,W ;W = a' + b'
; at this point, W is between 0 and 10
addlw -7
bc Mod7Byte_L2
Mod7Byte_L1:
addlw 7
Mod7Byte_L2:
return
</code></pre>
<p>Here's a liitle routine to test the algorithm</p>
<pre><code> clrf x
clrf count
TestLoop:
movf x,W
RCALL Mod7Byte
cpfseq count
bra fail
incf count,W
xorlw 7
skpz
xorlw 7
movwf count
incfsz x,F
bra TestLoop
passed:
</code></pre>
<p>Finally, for the 16-bit result (which I have not tested), you could
write:</p>
<pre><code>uint16 Mod7Word(uint16 X)
{
return Mod7Byte(Mod7Byte(X & 0xff) + Mod7Byte(X>>8)*4);
}
</code></pre>
<p>Scott</p>
<hr>
|
<p>The print statement will take orders of magnitude longer than even the slowest implementation of the modulus operator. So basically the comment "slow on some systems" should be "slow on all systems".</p>
<p>Also, the two code snippets provided don't do the same thing. In the second one, the line</p>
<pre>if(fizzcount >= FIZZ)</pre>
<p>is always false so "FIZZ\n" is never printed.</p>
| 7,041
|
<p>I would like to be able to display some dynamic text at the mouse
cursor location in a win32 app, for instance to give an X,Y coordinate that
would move with the cursor as though attached. I can do this during a
mousemove event using a TextOut() call for the window at the mouse
coordinates and invalidate a rectange around a stored last cursor position
to clear up the previous output. However this can suffer from flickering and
cause problems with other things being drawn in a window such as tracker
boxes. Is there a better way to do this, perhaps using the existing cursor
drawing/invalidating mechanism ? </p>
|
<p>You can do this via ToolTips - check out <a href="http://msdn.microsoft.com/en-us/library/6b4cb3a5(VS.80).aspx" rel="nofollow noreferrer">CToolTipCtrl</a>.</p>
<p>If you want flicker free tracking ToolTips then you will need to derive your own classes from CToolTipCtrl that use the <a href="http://msdn.microsoft.com/en-us/library/bb760421(VS.85).aspx" rel="nofollow noreferrer">trackActivate</a> messages.</p>
|
<p>You can overwrite OnSetCursor to get a dynamic mouse cursor. I just found a German tutorial.</p>
<p><a href="https://web.archive.org/web/20050320074845/http://www.cpp-tutor.de/mfc/mfc/kap7/tut/tut4.htm" rel="nofollow noreferrer">German tutorial</a></p>
<p><a href="http://translate.google.com/translate?hl=de&sl=de&tl=en&u=https%3A%2F%2Fweb.archive.org%2Fweb%2F20050320074845%2Fhttp%3A%2F%2Fwww.cpp-tutor.de%2Fmfc%2Fmfc%2Fkap7%2Ftut%2Ftut4.htm&sandbox=1" rel="nofollow noreferrer">English translated tutorial</a></p>
| 8,890
|
<p>I am trying to figure out what exactly is Appdomain recycling?
When a aspx page is requested for the first time from a DotNet application, i understand that an appdomain for that app is created, and required assemblies are loaded into that appdomain, and the request will be served.
Now, if the web.config file or the contents of the bin folder, etc are modified, the appdomain will be "recycled".
My question is, at the end of the recycling process, will the appdomain be loaded with assemblies and ready to serve the next request? or a page has to be requested to trigger the assemblies to load?.</p>
|
<p>Well, I think the thread was getting smoothly to a final conclusion, but in the end, it was otherwise.</p>
<p>I'll try to answer the question based on my understanding and leveraging what i've just read about in other web sites.</p>
<p>First of all, I myself try to avoid the term recycle other than for Application Pools since this may render someone confused. Now, getting to process, pools and AppDomain, I see the picture as follows:</p>
<p>An Application Pool is, in short, a region of memory that is maintained up and running by a process called W3WP.exe, aka Worker Process. Recycling an Application Pool means bringing that process down, eliminating it from memory and then originating a brand new Worker Process, with a newly assigned process ID.</p>
<p>Regarding Application Domains, I see it as subsets of memory regions, within the aforementioned region that plays the role of a container. In other words, the process in memory, W3WP.exe in this case, is a macro memory region for applications that stores subset regions, called Application Domains. Having said that, one process in memory may store different Application Domains, one for each application that is assigned to run within a given Application Pool.</p>
<p>When it comes to recycling, as I initially told, it's something that I myself reserve only for Application Pools. For AppDomains, I prefer using the term 'restart', in order to avoid misconception. Based on this, restarting a AppDomain means starting over a given application with the newly added settings, such as refreshing the existing configuration. That happens within the boundaries of that sub-region of memory, called AppDomain, that ultimately lies within the process associated with a respective Application Pool. Those new settings may come from files such as </p>
<p>web.config,
machine.config,
global.asax,
Bin directory,
App_Code,</p>
<p>and there may be others.</p>
<p>AppDomain are isolated from each other, that makes total sense. If not so, if changes to a web.config, let's say, of application 1, requited recycle of the pool, all other applications assigned to that pool would get restarted, what was definitely not desired by Microsoft and by anyone else.</p>
<p>Summarizing my point, </p>
<ul>
<li>Process (W3WP.exe)
<ul>
<li>AppDomain 1</li>
<li>AppDomain 2</li>
<li>AppDomain 3</li>
<li>AppDomain n</li>
</ul></li>
</ul>
<p>n = the number of assigned applications to the Application Pool managed by the given W3WP.exe</p>
<ul>
<li>Processes are memory regions isolated from one another</li>
<li>AppDomains are sub-memory regions isolated from one another, within the same process</li>
<li>Global IIS settings changes may require Application Pool recycle (killing and starting a new Worker Process, W3WP.exe)</li>
<li>Application-wide settings changes AppDomains concerns, and they may get restarted after changes in some specific files such as the ones outline above</li>
</ul>
<p>For further information, I recommend:</p>
<p><a href="http://blogs.msdn.com/b/david.wang/archive/2006/03/12/thoughts-on-iis-configuration-changes-and-when-it-takes-effect.aspx" rel="noreferrer">http://blogs.msdn.com/b/david.wang/archive/2006/03/12/thoughts-on-iis-configuration-changes-and-when-it-takes-effect.aspx</a></p>
<p><a href="https://stackoverflow.com/questions/302110/what-causes-an-application-pool-in-iis-to-recycle">What causes an application pool in IIS to recycle?</a></p>
<p><a href="http://blogs.msdn.com/b/tess/archive/2006/08/02/asp-net-case-study-lost-session-variables-and-appdomain-recycles.aspx" rel="noreferrer">http://blogs.msdn.com/b/tess/archive/2006/08/02/asp-net-case-study-lost-session-variables-and-appdomain-recycles.aspx</a></p>
<p>Regards from Brazil!</p>
|
<p>If your pages are "updatable," they must be compiled before use. That means, yes, on first request the assemblies are loaded, compiled, and made ready for accessing. Whenever these files are changed (even some virus software can trigger this by changing the modified date of the files!), the appdomain gets recycled.</p>
<p>You can configure your web application to not be updatable. Everything gets compiled into DLLs, and you won't see any .ASPX or .CS files in the virtual directory. It makes your code harder to update (need to put some additional text on your webpage? Recompile time!), but it increases the availability of your web app. </p>
<p>However, this still won't prevent your web app from being recycled if any of the files are altered. For example, if you edit web.config, your appdomain will recycle even if its compiled.</p>
| 5,830
|
<p>I am working on a small intranet site for a small company, where user should be able to post. I have imagined a very simple authentication mechanism where people just enter their email address, and gets sent a unique login url, that sets a cookie that will always identify them for future requests.</p>
<p>In my template setup, I have base.html, and the other pages extend this. I want to show logged in or register button in the base.html, but how can I ensure that the necessary variables are always a part of the context? It seems that each view just sets up the context as they like, and there is no global context population. Is there a way of doing this without including the user in each context creation?</p>
<p>Or will I have to make my own custom shortcuts to setup the context properly?</p>
|
<p>There is <strong>no need</strong> to write a context processor for the user object if you already have the <a href="https://docs.djangoproject.com/en/dev/topics/auth/default/#authentication-data-in-templates" rel="noreferrer"><code>"django.core.context_processors.auth"</code></a> in <a href="https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-TEMPLATE_CONTEXT_PROCESSORS" rel="noreferrer"><code>TEMPLATE_CONTEXT_PROCESSORS</code></a> <strong>and</strong> if you're using <a href="https://docs.djangoproject.com/en/dev/ref/templates/api/#subclassing-context-requestcontext" rel="noreferrer"><code>RequestContext</code></a> in your views. </p>
<p>if you are using django 1.4 or latest the module has been moved to <code>django.contrib.auth.context_processors.auth</code></p>
|
<p>Use context_processors. <a href="https://docs.djangoproject.com/en/2.2/ref/settings/#std:setting-TEMPLATES-OPTIONS" rel="nofollow noreferrer">https://docs.djangoproject.com/en/2.2/ref/settings/#std:setting-TEMPLATES-OPTIONS</a></p>
<blockquote>
<p>settings.py</p>
</blockquote>
<pre><code>'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'myapp.functions.test'
],
},
</code></pre>
<blockquote>
<p>myapp/functions.py</p>
</blockquote>
<pre><code>def test(request):
return {'misc': 'misc'}
</code></pre>
| 6,286
|
<p>Using reflection, I need to investigate a user DLL and create an object of a class in it.</p>
<p>What is the simple way of doing it?</p>
|
<p>Try <a href="http://msdn.microsoft.com/en-us/library/system.activator.createinstance.aspx" rel="noreferrer">Activator.CreateInstance</a>. </p>
|
<p>You can create an instance of a class from a Type object using Activator.CreateInstance, to get all types in a dll you can use Assembly.GetTypes</p>
| 7,718
|
<p>Is there a function like <code>document.getElementById("FirstDiv").clear()</code>?</p>
|
<p>To answer the original question - there are various ways to do this, but the following would be the simplest.</p>
<p>If you already have a handle to the child node that you want to remove, i.e. you have a JavaScript variable that holds a reference to it:</p>
<pre><code>myChildNode.parentNode.removeChild(myChildNode);
</code></pre>
<p>Obviously, if you are not using one of the numerous libraries that already do this, you would want to create a function to abstract this out:</p>
<pre><code>function removeElement(node) {
node.parentNode.removeChild(node);
}
</code></pre>
<hr>
<p>EDIT: As has been mentioned by others: if you have any event handlers wired up to the node you are removing, you will want to make sure you disconnect those before the last reference to the node being removed goes out of scope, lest poor implementations of the JavaScript interpreter leak memory.</p>
|
<p>You should be able to use the .RemoveNode method of the node or the .RemoveChild method of the parent node.</p>
| 3,470
|
<p>I would like to know how can i escape a # in velocity. Backslash seems to escape it but it prints itself as well</p>
<p>This: </p>
<pre><code>\#\#
</code></pre>
<p>prints: </p>
<pre><code>\#\#
</code></pre>
<p>I would like: </p>
<pre><code>##
</code></pre>
|
<p>If you don't want to bother with the EscapeTool, you can do this:</p>
<pre><code>#set( $H = '#' )
$H$H
</code></pre>
|
<p>The set technique is a good way to get around any characters you need escaping, like if you want to have $name followed by "_lastname" then you can do:</p>
<pre><code>set ($n = '_lastname)
</code></pre>
<p>and have this in your template: </p>
<pre><code>$name$n
</code></pre>
<p>and it's all good.</p>
| 7,729
|
<p>What is the best way to use SQL Server 2008 as a development database, but ensure that the database is compatible with SQL Server 2005?</p>
|
<p>This can be done via SQL Enterprise Manager or like this: </p>
<pre><code>ALTER DATABASE <database>
SET COMPATIBILITY_LEVEL = { 80 | 90 | 100 }
</code></pre>
<p>Use 90 for 2005 compatibility. </p>
<p>This replaces the functionality used for previous releases, the stored procedure <em>sp_dbcmptlevel</em>.</p>
|
<p>Don't forget that there are also behavioral differences between the two versions, and something on 2008 may perform differently (and insufficiently) than 2005 all other things equal - this will obviously depend on a lot of factors about your data and application.</p>
<p>You're better off developing against the lowest common denominator and testing against the newer versions.</p>
| 2,907
|
<p>I was curious about how other people use the <strong>this</strong> keyword. I tend to use it in constructors, but I may also use it throughout the class in other methods. Some examples:</p>
<p>In a constructor:</p>
<pre><code>public Light(Vector v)
{
this.dir = new Vector(v);
}
</code></pre>
<p>Elsewhere</p>
<pre><code>public void SomeMethod()
{
Vector vec = new Vector();
double d = (vec * vec) - (this.radius * this.radius);
}
</code></pre>
|
<p>There are several usages of <a href="http://msdn.microsoft.com/en-us/library/dk1507sz.aspx" rel="noreferrer">this</a> keyword in C#.</p>
<ol>
<li><a href="http://msdn.microsoft.com/en-us/library/vstudio/dk1507sz%28v=vs.100%29.aspx" rel="noreferrer">To qualify members hidden by similar name</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/vstudio/dk1507sz%28v=vs.100%29.aspx" rel="noreferrer">To have an object pass itself as a parameter to other methods</a></li>
<li>To have an object return itself from a method</li>
<li><a href="http://msdn.microsoft.com/en-us/library/6x16t2tx.aspx" rel="noreferrer">To declare indexers</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/bb383977.aspx" rel="noreferrer">To declare extension methods</a></li>
<li><a href="http://www.codeproject.com/Articles/7011/An-Intro-to-Constructors-in-C%29" rel="noreferrer">To pass parameters between constructors</a></li>
<li><a href="https://stackoverflow.com/questions/194484/whats-the-strangest-corner-case-youve-seen-in-c-or-net/1800162#1800162">To internally reassign value type (struct) value</a>.</li>
<li>To invoke an extension method on the current instance</li>
<li>To cast itself to another type</li>
<li><a href="https://stackoverflow.com/questions/1814953/c-sharp-constructor-chaining-how-to-do-it">To chain constructors defined in the same class</a></li>
</ol>
<p>You can avoid the first usage by not having member and local variables with the same name in scope, for example by following common naming conventions and using properties (Pascal case) instead of fields (camel case) to avoid colliding with local variables (also camel case). In C# 3.0 fields can be converted to properties easily by using <a href="https://msdn.microsoft.com/en-us/library/bb384054.aspx" rel="noreferrer">auto-implemented properties</a>.</p>
|
<p>Never. Ever. If you have variable shadowing, your naming conventions are on crack. I mean, really, no distinguishing naming for member variables? <em>Facepalm</em></p>
| 4,325
|
<p>I need to specify a date value in a sybase where clause. For example:</p>
<pre><code>select *
from data
where dateVal < [THE DATE]
</code></pre>
|
<p>Use the convert function, for example:</p>
<pre><code>select * from data
where dateVal < convert(datetime, '01/01/2008', 103)
</code></pre>
<p>Where the convert style (103) determines the date format to use.</p>
|
<p>102 is the rule of thumb,
convert (varchar, creat_tms, 102) > '2011'</p>
| 8,018
|
<p>Python gives us the ability to create 'private' methods and variables within a class by prepending double underscores to the name, like this: <code>__myPrivateMethod()</code>. How, then, can one explain this</p>
<pre><code>>>>> class MyClass:
... def myPublicMethod(self):
... print 'public method'
... def __myPrivateMethod(self):
... print 'this is private!!'
...
>>> obj = MyClass()
>>> obj.myPublicMethod()
public method
>>> obj.__myPrivateMethod()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: MyClass instance has no attribute '__myPrivateMethod'
>>> dir(obj)
['_MyClass__myPrivateMethod', '__doc__', '__module__', 'myPublicMethod']
>>> obj._MyClass__myPrivateMethod()
this is private!!
</code></pre>
<p>What's the deal?!</p>
<p>I'll explain this a little for those who didn't quite get that.</p>
<pre><code>>>> class MyClass:
... def myPublicMethod(self):
... print 'public method'
... def __myPrivateMethod(self):
... print 'this is private!!'
...
>>> obj = MyClass()
</code></pre>
<p>I create a class with a public method and a private method and instantiate it.</p>
<p>Next, I call its public method.</p>
<pre><code>>>> obj.myPublicMethod()
public method
</code></pre>
<p>Next, I try and call its private method.</p>
<pre><code>>>> obj.__myPrivateMethod()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: MyClass instance has no attribute '__myPrivateMethod'
</code></pre>
<p>Everything looks good here; we're unable to call it. It is, in fact, 'private'. Well, actually it isn't. Running <code>dir()</code> on the object reveals a new magical method that Python creates magically for all of your 'private' methods.</p>
<pre><code>>>> dir(obj)
['_MyClass__myPrivateMethod', '__doc__', '__module__', 'myPublicMethod']
</code></pre>
<p>This new method's name is always an underscore, followed by the class name, followed by the method name.</p>
<pre><code>>>> obj._MyClass__myPrivateMethod()
this is private!!
</code></pre>
<p>So much for encapsulation, eh?</p>
<p>In any case, I'd always heard Python doesn't support encapsulation, so why even try? What gives?</p>
|
<p>The name scrambling is used to ensure that subclasses don't accidentally override the private methods and attributes of their superclasses. It's not designed to prevent deliberate access from outside.</p>
<p>For example:</p>
<pre><code>>>> class Foo(object):
... def __init__(self):
... self.__baz = 42
... def foo(self):
... print self.__baz
...
>>> class Bar(Foo):
... def __init__(self):
... super(Bar, self).__init__()
... self.__baz = 21
... def bar(self):
... print self.__baz
...
>>> x = Bar()
>>> x.foo()
42
>>> x.bar()
21
>>> print x.__dict__
{'_Bar__baz': 21, '_Foo__baz': 42}
</code></pre>
<p>Of course, it breaks down if two different classes have the same name.</p>
|
<blockquote>
<p>Why are Python's 'private' methods not actually private?</p>
</blockquote>
<p>As I understand it, they <em>can't</em> be private. How could privacy be enforced?</p>
<p>The obvious answer is "private members can only be accessed through <code>self</code>", but that wouldn't work - <code>self</code> is not special in Python. It is nothing more than a commonly-used name for the first parameter of a function.</p>
| 9,594
|
<p>I'm near the end of the build of a i3 MK2 clone and have run into a problem with the Z-axis motors. Specifically, the Z-axis will move down (and trigger the endstop) but it will only make a quick noise if I try to move it up.</p>
<p><code>M119</code> shows all endstops open. Min software stops are currently disabled, as I try to set the printer up. Using Marlin 1.1.3 with a RAMPS 1.4. Both motors turn and I've even uncoupled the entire X-axis carriage.</p>
<p>Additional test: reversed the z-axis motor wires and they only go up. Inverted the motor direction in software and they also only go up.</p>
<p>Any advice? I've definitely done a few searches but haven't solved the problem.</p>
<p><code>Config.h</code> is as follows (clipped due to posting restrictions):</p>
<pre><code>//===========================================================================
//============================== Endstop Settings ===========================
//===========================================================================
// @section homing
// Specify here all the endstop connectors that are connected to any endstop or probe.
// Almost all printers will be using one per axis. Probes will use one or more of the
// extra connectors. Leave undefined any used for non-endstop and non-probe purposes.
#define USE_XMIN_PLUG
#define USE_YMIN_PLUG
#define USE_ZMIN_PLUG
//#define USE_XMAX_PLUG
//#define USE_YMAX_PLUG
//#define USE_ZMAX_PLUG
// coarse Endstop Settings
//#define ENDSTOPPULLUPS // Comment this out (using // at the start of the line) to disable the endstop pullup resistors
#if DISABLED(ENDSTOPPULLUPS)
// fine endstop settings: Individual pullups. will be ignored if ENDSTOPPULLUPS is defined
//#define ENDSTOPPULLUP_XMAX
//#define ENDSTOPPULLUP_YMAX
//#define ENDSTOPPULLUP_ZMAX
//#define ENDSTOPPULLUP_XMIN
//#define ENDSTOPPULLUP_YMIN
//#define ENDSTOPPULLUP_ZMIN
//#define ENDSTOPPULLUP_ZMIN_PROBE
#endif
// Mechanical endstop with COM to ground and NC to Signal uses "false" here (most common setup).
#define X_MIN_ENDSTOP_INVERTING true // set to true to invert the logic of the endstop.
#define Y_MIN_ENDSTOP_INVERTING true // set to true to invert the logic of the endstop.
#define Z_MIN_ENDSTOP_INVERTING true // set to true to invert the logic of the endstop.
#define X_MAX_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop.
#define Y_MAX_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop.
#define Z_MAX_ENDSTOP_INVERTING false // set to true to invert the logic of the endstop.
#define Z_MIN_PROBE_ENDSTOP_INVERTING true // set to true to invert the logic of the probe.
// Enable this feature if all enabled endstop pins are interrupt-capable.
// This will remove the need to poll the interrupt pins, saving many CPU cycles.
//#define ENDSTOP_INTERRUPTS_FEATURE
//=============================================================================
//============================== Movement Settings ============================
//=============================================================================
// @section motion
/**
* Default Settings
*
* These settings can be reset by M502
*
* Note that if EEPROM is enabled, saved values will override these.
*/
/**
* With this option each E stepper can have its own factors for the
* following movement settings. If fewer factors are given than the
* total number of extruders, the last value applies to the rest.
*/
//#define DISTINCT_E_FACTORS
/**
* Default Axis Steps Per Unit (steps/mm)
* Override with M92
* X, Y, Z, E0 [, E1[, E2[, E3[, E4]]]]
*/
#define DEFAULT_AXIS_STEPS_PER_UNIT { 100, 100, 4000, 120 }
/**
* Default Max Feed Rate (mm/s)
* Override with M203
* X, Y, Z, E0 [, E1[, E2[, E3[, E4]]]]
*/
#define DEFAULT_MAX_FEEDRATE { 200, 200, 3, 25 }
/**
* Default Max Acceleration (change/s) change = mm/s
* (Maximum start speed for accelerated moves)
* Override with M201
* X, Y, Z, E0 [, E1[, E2[, E3[, E4]]]]
*/
#define DEFAULT_MAX_ACCELERATION { 3000, 3000, 100, 10000 }
/**
* Default Acceleration (change/s) change = mm/s
* Override with M204
*
* M204 P Acceleration
* M204 R Retract Acceleration
* M204 T Travel Acceleration
*/
#define DEFAULT_ACCELERATION 3000 // X, Y, Z and E acceleration for printing moves
#define DEFAULT_RETRACT_ACCELERATION 3000 // E acceleration for retracts
#define DEFAULT_TRAVEL_ACCELERATION 3000 // X, Y, Z acceleration for travel (non printing) moves
/**
* Default Jerk (mm/s)
* Override with M205 X Y Z E
*
* "Jerk" specifies the minimum speed change that requires acceleration.
* When changing speed and direction, if the difference is less than the
* value set here, it may happen instantaneously.
*/
#define DEFAULT_XJERK 10.0
#define DEFAULT_YJERK 10.0
#define DEFAULT_ZJERK 0.4
#define DEFAULT_EJERK 2.0
//===========================================================================
//============================= Z Probe Options =============================
//===========================================================================
// @section probes
//
// See http://marlinfw.org/configuration/probes.html
//
/**
* Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN
*
* Enable this option for a probe connected to the Z Min endstop pin.
*/
#define Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN
/**
* Z_MIN_PROBE_ENDSTOP
*
* Enable this option for a probe connected to any pin except Z-Min.
* (By default Marlin assumes the Z-Max endstop pin.)
* To use a custom Z Probe pin, set Z_MIN_PROBE_PIN below.
*
* - The simplest option is to use a free endstop connector.
* - Use 5V for powered (usually inductive) sensors.
*
* - RAMPS 1.3/1.4 boards may use the 5V, GND, and Aux4->D32 pin:
* - For simple switches connect...
* - normally-closed switches to GND and D32.
* - normally-open switches to 5V and D32.
*
* WARNING: Setting the wrong pin may have unexpected and potentially
* disastrous consequences. Use with caution and do your homework.
*
*/
//#define Z_MIN_PROBE_ENDSTOP
//#define Z_MIN_PROBE_PIN Z_MAX_PIN
/**
* Probe Type
*
* Allen Key Probes, Servo Probes, Z-Sled Probes, FIX_MOUNTED_PROBE, etc.
* You must activate one of these to use Auto Bed Leveling below.
*/
/**
* The "Manual Probe" provides a means to do "Auto" Bed Leveling without a probe.
* Use G29 repeatedly, adjusting the Z height at each point with movement commands
* or (with LCD_BED_LEVELING) the LCD controller.
*/
//#define PROBE_MANUALLY
/**
* A Fix-Mounted Probe either doesn't deploy or needs manual deployment.
* (e.g., an inductive probe or a nozzle-based probe-switch.)
*/
#define FIX_MOUNTED_PROBE
/**
* Z Servo Probe, such as an endstop switch on a rotating arm.
*/
//#define Z_ENDSTOP_SERVO_NR 0 // Defaults to SERVO 0 connector.
//#define Z_SERVO_ANGLES {70,0} // Z Servo Deploy and Stow angles
/**
* The BLTouch probe uses a Hall effect sensor and emulates a servo.
*/
//#define BLTOUCH
#if ENABLED(BLTOUCH)
//#define BLTOUCH_DELAY 375 // (ms) Enable and increase if needed
#endif
/**
* Enable if probing seems unreliable. Heaters and/or fans - consistent with the
* options selected below - will be disabled during probing so as to minimize
* potential EM interference by quieting/silencing the source of the 'noise' (the change
* in current flowing through the wires). This is likely most useful to users of the
* BLTouch probe, but may also help those with inductive or other probe types.
*/
//#define PROBING_HEATERS_OFF // Turn heaters off when probing
//#define PROBING_FANS_OFF // Turn fans off when probing
// A probe that is deployed and stowed with a solenoid pin (SOL1_PIN)
//#define SOLENOID_PROBE
// A sled-mounted probe like those designed by Charles Bell.
//#define Z_PROBE_SLED
//#define SLED_DOCKING_OFFSET 5 // The extra distance the X axis must travel to pickup the sled. 0 should be fine but you can push it further if you'd like.
//
// For Z_PROBE_ALLEN_KEY see the Delta example configurations.
//
/**
* Z Probe to nozzle (X,Y) offset, relative to (0, 0).
* X and Y offsets must be integers.
*
* In the following example the X and Y offsets are both positive:
* #define X_PROBE_OFFSET_FROM_EXTRUDER 10
* #define Y_PROBE_OFFSET_FROM_EXTRUDER 10
*
* +-- BACK ---+
* | |
* L | (+) P | R <-- probe (20,20)
* E | | I
* F | (-) N (+) | G <-- nozzle (10,10)
* T | | H
* | (-) | T
* | |
* O-- FRONT --+
* (0,0)
*/
#define X_PROBE_OFFSET_FROM_EXTRUDER 22 // X offset: -left +right [of the nozzle]
#define Y_PROBE_OFFSET_FROM_EXTRUDER 12 // Y offset: -front +behind [the nozzle]
#define Z_PROBE_OFFSET_FROM_EXTRUDER 0 // Z offset: -below +above [the nozzle]
// X and Y axis travel speed (mm/m) between probes
#define XY_PROBE_SPEED 8000
// Speed for the first approach when double-probing (with PROBE_DOUBLE_TOUCH)
#define Z_PROBE_SPEED_FAST HOMING_FEEDRATE_Z
// Speed for the "accurate" probe of each point
#define Z_PROBE_SPEED_SLOW (Z_PROBE_SPEED_FAST / 2)
// Use double touch for probing
//#define PROBE_DOUBLE_TOUCH
/**
* Z probes require clearance when deploying, stowing, and moving between
* probe points to avoid hitting the bed and other hardware.
* Servo-mounted probes require extra space for the arm to rotate.
* Inductive probes need space to keep from triggering early.
*
* Use these settings to specify the distance (mm) to raise the probe (or
* lower the bed). The values set here apply over and above any (negative)
* probe Z Offset set with Z_PROBE_OFFSET_FROM_EXTRUDER, M851, or the LCD.
* Only integer values >= 1 are valid here.
*
* Example: `M851 Z-5` with a CLEARANCE of 4 => 9mm from bed to nozzle.
* But: `M851 Z+1` with a CLEARANCE of 2 => 2mm from bed to nozzle.
*/
#define Z_CLEARANCE_DEPLOY_PROBE 10 // Z Clearance for Deploy/Stow
#define Z_CLEARANCE_BETWEEN_PROBES 5 // Z Clearance between probe points
// For M851 give a range for adjusting the Z probe offset
#define Z_PROBE_OFFSET_RANGE_MIN -20
#define Z_PROBE_OFFSET_RANGE_MAX 20
// Enable the M48 repeatability test to test probe accuracy
//#define Z_MIN_PROBE_REPEATABILITY_TEST
// For Inverting Stepper Enable Pins (Active Low) use 0, Non Inverting (Active High) use 1
// :{ 0:'Low', 1:'High' }
#define X_ENABLE_ON 0
#define Y_ENABLE_ON 0
#define Z_ENABLE_ON 0
#define E_ENABLE_ON 0 // For all extruders
// Disables axis stepper immediately when it's not being used.
// WARNING: When motors turn off there is a chance of losing position accuracy!
#define DISABLE_X false
#define DISABLE_Y false
#define DISABLE_Z false
// Warn on display about possibly reduced accuracy
//#define DISABLE_REDUCED_ACCURACY_WARNING
// @section extruder
#define DISABLE_E false // For all extruders
#define DISABLE_INACTIVE_EXTRUDER true // Keep only the active extruder enabled.
// @section machine
// Invert the stepper direction. Change (or reverse the motor connector) if an axis goes the wrong way.
#define INVERT_X_DIR false
#define INVERT_Y_DIR false
#define INVERT_Z_DIR false
// Enable this option for Toshiba stepper drivers
//#define CONFIG_STEPPERS_TOSHIBA
// @section extruder
// For direct drive extruder v9 set to true, for geared extruder set to false.
#define INVERT_E0_DIR false
#define INVERT_E1_DIR false
#define INVERT_E2_DIR false
#define INVERT_E3_DIR false
#define INVERT_E4_DIR false
// @section homing
//#define Z_HOMING_HEIGHT 4 // (in mm) Minimal z height before homing (G28) for Z clearance above the bed, clamps, ...
// Be sure you have this distance over your Z_MAX_POS in case.
// Direction of endstops when homing; 1=MAX, -1=MIN
// :[-1,1]
#define X_HOME_DIR -1
#define Y_HOME_DIR -1
#define Z_HOME_DIR -1
// @section machine
// Travel limits after homing (units are in mm)
#define X_MIN_POS 0
#define Y_MIN_POS 0
#define Z_MIN_POS 0
#define X_MAX_POS 230
#define Y_MAX_POS 200
#define Z_MAX_POS 200
// If enabled, axes won't move below MIN_POS in response to movement commands.
//#define MIN_SOFTWARE_ENDSTOPS
// If enabled, axes won't move above MAX_POS in response to movement commands.
//#define MAX_SOFTWARE_ENDSTOPS
/**
* Filament Runout Sensor
* A mechanical or opto endstop is used to check for the presence of filament.
*
* RAMPS-based boards use SERVO3_PIN.
* For other boards you may need to define FIL_RUNOUT_PIN.
* By default the firmware assumes HIGH = has filament, LOW = ran out
*/
//#define FILAMENT_RUNOUT_SENSOR
#if ENABLED(FILAMENT_RUNOUT_SENSOR)
#define FIL_RUNOUT_INVERTING false // set to true to invert the logic of the sensor.
#define ENDSTOPPULLUP_FIL_RUNOUT // Uncomment to use internal pullup for filament runout pins if the sensor is defined.
#define FILAMENT_RUNOUT_SCRIPT "M600"
#endif
</code></pre>
|
<p>UPDATE: Turns out to have been a faulty RAMPS. Replaced the card and made NO changes; z-axis is now behaving properly. Thank you all.</p>
|
<p>This sounds similar to <a href="https://3dprinting.stackexchange.com/questions/4158/prusa-i3-z-axis-only-goes-down-even-on-up-command">Prusa i3 Z axis only goes down (even on up command)</a> and <a href="https://3dprinting.stackexchange.com/questions/4090/my-prusa-i3s-z-axis-will-only-go-up">My Prusa i3's z-axis will only go up</a>. Please check the answers to those questions.</p>
<p>The usual cause of your problem is that you need to:</p>
<ul>
<li>install/configure the end stops, and;</li>
<li>home the Z-axis.</li>
</ul>
<p>You say that you have already installed ad configured the end stops. Have you homed it yet, though?</p>
<p>However, check your wiring first as it could just be a simple case of a loose or misplaced connection.</p>
<p>Also, something else to consider, if your stepper is making a grunting noise, and trying to move but can not, then maybe your stepper driver is <em>not supplying enough current</em>, or maybe <em>too much</em>. See <a href="https://3dprinting.stackexchange.com/questions/3134/extruder-stepper-motor-problem-what-can-be-wrong/3136#3136">my answer</a> to <a href="https://3dprinting.stackexchange.com/questions/3134/extruder-stepper-motor-problem-what-can-be-wrong/">Extruder stepper motor problem, what can be wrong?</a>. Yes, the answer is for an extruder, but all steppers drivers can suffer the same mis-configuration.</p>
| 621
|
<p>For example, I issued an ALTER TABLE statement to create an index on a MEDIUMTEXT field in an InnoDB table that has 134k rows where the size of the index was 255 bytes and the average size of the data in the field is 30k. This command has been running for the last 15 minutes or so (and is the only thing running on the database). Is there any way for me to determine if it is going to finish in closer to 5 minutes, 5 hours, or 5 days?</p>
|
<p>I was able to perform these 2 queries and figure out how many rows remain to be moved.</p>
<pre><code>select count(*) from `myoriginalrable`;
select count(*) from `#sql-1e8_11ae5`;
</code></pre>
<p>this was WAY more helpful than comparing the file size on disk, because changing from myisam to innodb etc changes the row size.</p>
|
<p><a href="http://www.percona.com/software/percona-server" rel="nofollow">Percona Server</a>, which is a branched version of MySQL with some enhancements, has this feature.</p>
<p>You can observe extra columns in SHOW PROCESSLIST for ROWS_SENT and ROWS_EXAMINED. For example, if your table has 1000000 rows, and you see ROWS_EXAMINED of 650000, then it's 65% finished.</p>
<p>See <a href="http://www.percona.com/doc/percona-server/5.6/diagnostics/process_list.html" rel="nofollow">http://www.percona.com/doc/percona-server/5.6/diagnostics/process_list.html</a></p>
| 6,502
|
<p>First off, this question is ripped out from <a href="https://stackoverflow.com/questions/56215/interesting-interview-questions#56291">this</a> question. I did it because I think this part is bigger than a sub-part of a longer question. If it offends, please pardon me.</p>
<p>Assume that you have a algorithm that generates randomness. Now how do you test it?
Or to be more direct - Assume you have an algorithm that shuffles a deck of cards, how do you test that it's a perfectly random algorithm?</p>
<p>To add some theory to the problem -
A deck of cards can be shuffled in 52! (52 factorial) different ways. Take a deck of cards, shuffle it by hand and write down the order of all cards. What is the probability that you would have gotten exactly that shuffle? Answer: 1 / 52!.</p>
<p>What is the chance that you, after shuffling, will get A, K, Q, J ... of each suit in a sequence? Answer 1 / 52!</p>
<p>So, just shuffling once and looking at the result will give you absolutely no information about your shuffling algorithms randomness. Twice and you have more information, Three even more...</p>
<p>How would you black box test a shuffling algorithm for randomness?</p>
|
<p>Statistics. The de facto standard for testing RNGs is the <a href="https://web.archive.org/web/20150103230339/http://stat.fsu.edu/pub/diehard/" rel="nofollow noreferrer">Diehard suite</a> (originally available at <a href="http://stat.fsu.edu/pub/diehard" rel="nofollow noreferrer">http://stat.fsu.edu/pub/diehard</a>). Alternatively, the <a href="ftp://ftp.fourmilab.ch/web/random/index.html" rel="nofollow noreferrer">Ent program</a> provides tests that are simpler to interpret but less comprehensive.</p>
<p>As for shuffling algorithms, use a well-known algorithm such as <a href="http://en.wikipedia.org/wiki/Knuth_shuffle" rel="nofollow noreferrer">Fisher-Yates</a> (a.k.a "Knuth Shuffle"). The shuffle will be uniformly random so long as the underlying RNG is uniformly random. If you are using Java, this algorithm is available in the standard library (see <a href="http://java.sun.com/javase/6/docs/api/java/util/Collections.html#shuffle(java.util.List)" rel="nofollow noreferrer">Collections.shuffle</a>).</p>
<p>It probably doesn't matter for most applications, but be aware that most RNGs do not provide sufficient degrees of freedom to produce every possible permutation of a 52-card deck (explained <a href="http://blog.uncommons.org/2008/04/10/a-java-programmers-guide-to-random-numbers-part-3-seeding/" rel="nofollow noreferrer">here</a>).</p>
|
<p>Pondering it myself, what I would do is something like:</p>
<p>Setup (Pseudo code)</p>
<pre><code>// A card has a Number 0-51 and a position 0-51
int[][] StatMatrix = new int[52][52]; // Assume all are set to 0 as starting values
ShuffleCards();
ForEach (card in Cards) {
StatMatrix[Card.Position][Card.Number]++;
}
</code></pre>
<p>This gives us a matrix 52x52 indicating how many times a card has ended up at a certain position. Repeat this a large number of times (I would start with 1000, but people better at statistics than me may give a better number).</p>
<p>Analyze the matrix</p>
<p>If we have perfect randomness and perform the shuffle an infinite number of times then for each card and for each position the number of times the card ended up in that position is the same as for any other card. Saying the same thing in a different way:</p>
<pre><code>statMatrix[position][card] / numberOfShuffle = 1/52.
</code></pre>
<p>So I would calculate how far from that number we are.</p>
| 8,033
|
<p>If I create an index on columns (A, B, C), in that order, my understanding is that the database will be able to use it even if I search only on (A), or (A and B), or (A and B and C), but not if I search only on (B), or (C), or (B and C). Is this correct?</p>
|
<p>There are actually three index-based access methods that Oracle can use when a predicate is placed on a non-leading column of an index.</p>
<p>i) Index skip-scan: <a href="http://download.oracle.com/docs/cd/B19306_01/server.102/b14211/optimops.htm#PFGRF10105" rel="noreferrer">http://download.oracle.com/docs/cd/B19306_01/server.102/b14211/optimops.htm#PFGRF10105</a></p>
<p>ii) Fast full index scan: <a href="http://download.oracle.com/docs/cd/B19306_01/server.102/b14211/optimops.htm#i52044" rel="noreferrer">http://download.oracle.com/docs/cd/B19306_01/server.102/b14211/optimops.htm#i52044</a></p>
<p>iii) Index full scan: <a href="http://download.oracle.com/docs/cd/B19306_01/server.102/b14211/optimops.htm#i82107" rel="noreferrer">http://download.oracle.com/docs/cd/B19306_01/server.102/b14211/optimops.htm#i82107</a></p>
<p>I've most often seen the fast full index scan "in the wild", but all are possible.</p>
|
<p>That is not correct. Always best to come up with a test case that represents your data and see for yourself. If you want to really understand the Oracle SQL Optimizer google Jonathan Lewis, read his books, read his blog, check out his website, the guy is amazing, and he always generates test cases.</p>
<pre><code>create table mytab nologging as (
select mod(rownum, 3) x, rownum y, mod(rownum, 3) z from all_objects, (select 'x' from user_tables where rownum < 4)
);
create index i on mytab (x, y, z);
exec dbms_stats.gather_table_stats(ownname=>'DBADMIN',tabname=>'MYTAB', cascade=>true);
set autot trace exp
select * from mytab where y=5000;
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=1 Card=1 Bytes=10)
1 0 INDEX (SKIP SCAN) OF 'I' (INDEX) (Cost=1 Card=1 Bytes=10)
</code></pre>
| 8,231
|
<p>Lots of people talk about writing tests for their code before they start writing their code. This practice is generally known as Test Driven Development or TDD for short. What benefits do I gain from writing software this way? How do I get started with this practice?</p>
|
<p>There are a lot of benefits:</p>
<ul>
<li>You get immediate feedback on if your code is working, so you can find bugs faster</li>
<li>By seeing the test go from red to green, you know that you have both a working regression test, and working code</li>
<li>You gain confidence to refactor existing code, which means you can clean up code without worrying what it might break</li>
<li>At the end you have a suite of regression tests that can be run during automated builds to give you greater confidence that your codebase is solid</li>
</ul>
<p>The best way to start is to just start. There is a great <a href="https://rads.stackoverflow.com/amzn/click/com/0321146530" rel="noreferrer" rel="nofollow noreferrer">book by Kent Beck</a> all about Test Driven Development. Just start with new code, don't worry about old code... whenever you feel you need to refactor some code, write a test for the existing functionality, then refactor it and make sure the tests stay green. Also, read <a href="http://devver.wordpress.com/2008/07/07/tips-for-unit-testing/" rel="noreferrer">this great article</a>.</p>
|
<p>In my opinion, the single greatest thing is that it clearly allows you to see if your code does what it is supposed to. This may seem obvious, but it is super easy to run astray of your original goals, as I have found out in the past :p</p>
| 2,630
|
<p>Is it possible to compile and run OpenGL programs from under Cygwin? If yes, how?</p>
|
<p>It is possible to compile and run OpenGL programs under Cygwin. I illustrate the basic steps here:</p>
<ol>
<li><p>I assume you know OpenGL programming. If not, get the <a href="http://www.opengl-redbook.com/" rel="noreferrer">Red Book</a> (<em>The OpenGL Programming Guide</em>). It is mandatory reading for OpenGL anyway.</p></li>
<li><p>I assume you have Cygwin installed. If not, visit <a href="http://www.cygwin.com/" rel="noreferrer">cygwin.com</a> and install it.</p></li>
<li><p>To compile and run OpenGL programs, you need the Cygwin package named <strong>opengl</strong>. In the Cygwin installer, it can be found under the <em>Graphics section</em>. Please install this package.</p></li>
<li><p>Write a simple OpenGL program, say <em>ogl.c</em>.</p></li>
<li><p>Compile the program using the flags <strong>-lglut32 -lglu32 -lopengl32</strong>. (This links your program with the GLUT, GLU and OpenGL libraries. An OpenGL program might typically use functions from all the 3 of them.) For example:</p>
<blockquote>
<p>$ gcc ogl.c -lglut32 -lglu32 -lopengl32</p>
</blockquote></li>
<li><p>Run the program. It's as simple as that!</p></li>
</ol>
|
<p>I remember doing this once with some success, a few years ago, basically trying to cross compile a small Linux OpenGL C++ program. I do recall problems with Windows OpenGL drivers being behind the times (due to MS's focus on DirectX). I had NVidia OpenGL and DirectX drivers installed on my Windows system, but cygwin/g++ seemed to want to only use the Microsoft OpenGL DLLs, many years old, which do not have the latest support for all the ARB extensions, like shader programs, etc. YMMV.</p>
| 3,510
|
<p>I stumbled over this passage in the <a href="http://www.djangoproject.com/documentation/tutorial01/" rel="noreferrer">Django tutorial</a>:</p>
<blockquote>
<p>Django models have a default <strong>str</strong>() method that calls <strong>unicode</strong>() and converts the result to a UTF-8 bytestring. This means that unicode(p) will return a Unicode string, and str(p) will return a normal string, with characters encoded as UTF-8.</p>
</blockquote>
<p>Now, I'm confused because afaik Unicode is not any particular representation, so what is a "Unicode string" in Python? Does that mean UCS-2? Googling turned up <a href="http://www.reportlab.com/i18n/python_unicode_tutorial.html" rel="noreferrer">this "Python Unicode Tutorial"</a> which boldly states</p>
<blockquote>
<p>Unicode is a two-byte encoding which covers all of the world's common writing systems.</p>
</blockquote>
<p>which is plain wrong, or is it? I have been confused many times by character set and encoding issues, but here I'm quite sure that the documentation I'm reading is confused. Does anybody know what's going on in Python when it gives me a "Unicode string"?</p>
|
<blockquote>
<p>what is a "Unicode string" in Python? Does that mean UCS-2?</p>
</blockquote>
<p>Unicode strings in Python are stored internally either as UCS-2 (fixed-length 16-bit representation, almost the same as UTF-16) or UCS-4/UTF-32 (fixed-length 32-bit representation). It's a compile-time option; on Windows it's always UTF-16 whilst many Linux distributions set UTF-32 (‘wide mode’) for their versions of Python.</p>
<p>You are generally not supposed to care: you will see Unicode code-points as single elements in your strings and you won't know whether they're stored as two or four bytes. If you're in a UTF-16 build and you need to handle characters outside the Basic Multilingual Plane you'll be Doing It Wrong, but that's still very rare, and users who really need the extra characters should be compiling wide builds.</p>
<blockquote>
<p>plain wrong, or is it?</p>
</blockquote>
<p>Yes, it's quite wrong. To be fair I think that tutorial is rather old; it probably pre-dates wide Unicode strings, if not Unicode 3.1 (the version that introduced characters outside the Basic Multilingual Plane).</p>
<p>There is an additional source of confusion stemming from Windows's habit of using the term “Unicode” to mean, specifically, the UTF-16LE encoding that NT uses internally. People from Microsoftland may often copy this somewhat misleading habit.</p>
|
<p>From <a href="http://en.wikipedia.org/wiki/UTF-8" rel="nofollow noreferrer">Wikipedia on UTF-8</a>: </p>
<blockquote>
UTF-8 (8-bit UCS/Unicode Transformation Format) is a <strong>variable-length character encoding for Unicode. It is able to represent any character in the Unicode standard</strong>, yet the initial encoding of byte codes and character assignments for UTF-8 is backwards compatible with ASCII. For these reasons, it is steadily becoming the preferred encoding for e-mail, web pages[1], and other places where characters are stored or streamed.
</blockquote>
<p>So, it's anywhere between one and four bytes depending on which character you wish to represent within the realm of Unicode.</p>
<p><a href="http://en.wikipedia.org/wiki/Unicode" rel="nofollow noreferrer">From Wikipedia on Unicode:</a></p>
<blockquote>
In computing, Unicode is an industry standard allowing computers to consistently represent and manipulate text expressed in <strong>most of the world's writing systems</strong>.
</blockquote>
<p>So it's able to represent most (but not all) of the world's writing systems. </p>
<p>I hope this helps :)</p>
| 4,215
|
<p>I have been playing around with the bed for a while and I still can't get the first layer to stick properly. I think I am getting the bed leveled good, I use the paper method. But yet I find myself with the filament lifting off and getting pulled away with the nozzle or some balling in rare situations. </p>
<p>I use masking tape, which I found for $3 at Dollar general. I heard something about shine being a factor, but why is that important? And is more expensive masking tape worth it? I don't want to buy it because I would hate for it to tear when I take off a print. </p>
<p>I also use some glue stick, which seems to sometimes not help, almost like it doesn't allow the filament to stick. I don't think I was adding too much, maybe I was. But is glue stick needed? Does it really make that much of a difference?</p>
<p>So other than that I don't know what to try. I can't get the first layer to work properly. Maybe it is my speed, what is a good speed to print at for the first layer, I am doing 60 mm/s, just like the rest of my print. </p>
<p>Any advice from there with first layers would be great. I am tired of wasting time and filament over failed first layers. But when I do get the first layer done, the second+ layers all work fine, no issues. </p>
<p>Here are the specs of my printer, that should be helpful for people:</p>
<ul>
<li>Printer --> Anet A6</li>
<li>Print area --> 220 x 220 mm</li>
<li>Heated bed? --> Yes</li>
<li>Bed temp --> 50°C</li>
<li>I use masking tape on bed</li>
<li>nozzle dia. --> 0.4mm</li>
<li>Nozzle temp --> 210°C</li>
<li>Print speed --> 60 mm</li>
<li>Material of choice --> PLA</li>
<li>Fan is on after 3 layers</li>
</ul>
<p>I think that covers everything, Let me know if I need to add anything else.</p>
|
<p>Masking tape (and blue painter's tape) is coated with a wax-based release agent in order to prevent the tape sticking to itself on the roll. This release agent must be removed with an organic solvent in order to obtain good adhesion. Isopropyl (rubbing) alcohol is good for this. Acetone will also work, but it is a much stronger solvent (which is not necessarily a good thing).</p>
<p>For blue painter's tape, rub freshly applied tape with solvent until the blue dye starts coming off. Then give it a quick wipe between prints to remove any fingerprints, etc.</p>
|
<p>I'll go out on a limb and suggest that, while your bed may be well-levelled, the Z-axis zero might be off. A difference of 10-20 microns can be the difference between strong adhesion to the bed/tape and having your print float away. If your first layer doesn't get "squashed flat" a bit by the nozzle, your extruder head is slightly higher than optimal.</p>
| 800
|
<p>What I'm doing is I have a full-screen form, with no title bar, and consequently lacks the minimize/maximize/close buttons found in the upper-right hand corner. I'm wanting to replace that functionality with a keyboard short-cut and a context menu item, but I can't seem to find an event to trigger to minimize the form.</p>
|
<pre><code>private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
if(e.KeyChar == 'm')
this.WindowState = FormWindowState.Minimized;
}
</code></pre>
|
<pre><code>this.MdiParent.WindowState = FormWindowState.Minimized;
</code></pre>
| 9,475
|
<p>I was hoping someone could help me out with a problem I'm having using the java search function in Eclipse on a particular project.</p>
<p>When using the java search on one particular project, I get an error message saying <code>Class file name must end with .class</code> (see stack trace below). This does not seem to be happening on all projects, just one particular one, so perhaps there's something I should try to get rebuilt?</p>
<p>I have already tried <code>Project -> Clean</code>... and Closing Eclipse, deleting all the built class files and restarting Eclipse to no avail.</p>
<p>The only reference I've been able to find on Google for the problem is at <a href="http://www.crazysquirrel.com/computing/java/eclipse/error-during-java-search.jspx" rel="noreferrer">http://www.crazysquirrel.com/computing/java/eclipse/error-during-java-search.jspx</a>, but unfortunately his solution (closing, deleting class files, restarting) did not work for me.</p>
<p>If anyone can suggest something to try, or there's any more info I can gather which might help track it's down, I'd greatly appreciate the pointers.</p>
<pre><code>Version: 3.4.0
Build id: I20080617-2000
</code></pre>
<p>Also just found this thread - <a href="http://www.myeclipseide.com/PNphpBB2-viewtopic-t-20067.html" rel="noreferrer">http://www.myeclipseide.com/PNphpBB2-viewtopic-t-20067.html</a> - which indicates the same problem may occur when the project name contains a period. Unfortunately, that's not the case in my setup, so I'm still stuck.</p>
<pre><code>Caused by: java.lang.IllegalArgumentException: Class file name must end with .class
at org.eclipse.jdt.internal.core.PackageFragment.getClassFile(PackageFragment.java:182)
at org.eclipse.jdt.internal.core.util.HandleFactory.createOpenable(HandleFactory.java:109)
at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1177)
at org.eclipse.jdt.internal.core.search.JavaSearchParticipant.locateMatches(JavaSearchParticipant.java:94)
at org.eclipse.jdt.internal.core.search.BasicSearchEngine.findMatches(BasicSearchEngine.java:223)
at org.eclipse.jdt.internal.core.search.BasicSearchEngine.search(BasicSearchEngine.java:506)
at org.eclipse.jdt.core.search.SearchEngine.search(SearchEngine.java:551)
at org.eclipse.jdt.internal.corext.refactoring.RefactoringSearchEngine.internalSearch(RefactoringSearchEngine.java:142)
at org.eclipse.jdt.internal.corext.refactoring.RefactoringSearchEngine.search(RefactoringSearchEngine.java:129)
at org.eclipse.jdt.internal.corext.refactoring.rename.RenameTypeProcessor.initializeReferences(RenameTypeProcessor.java:594)
at org.eclipse.jdt.internal.corext.refactoring.rename.RenameTypeProcessor.doCheckFinalConditions(RenameTypeProcessor.java:522)
at org.eclipse.jdt.internal.corext.refactoring.rename.JavaRenameProcessor.checkFinalConditions(JavaRenameProcessor.java:45)
at org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring.checkFinalConditions(ProcessorBasedRefactoring.java:225)
at org.eclipse.ltk.core.refactoring.Refactoring.checkAllConditions(Refactoring.java:160)
at org.eclipse.jdt.internal.ui.refactoring.RefactoringExecutionHelper$Operation.run(RefactoringExecutionHelper.java:77)
at org.eclipse.jdt.internal.core.BatchOperation.executeOperation(BatchOperation.java:39)
at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:709)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1800)
at org.eclipse.jdt.core.JavaCore.run(JavaCore.java:4650)
at org.eclipse.jdt.internal.ui.actions.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:92)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
</code></pre>
<p>Thanks McDowell, closing and opening the project seems to have fixed it (at least for now).</p>
|
<p>Two more general-purpose mechanisms for fixing some of Eclipse's idiosyncrasies:</p>
<ul>
<li>Close and open the project</li>
<li>Delete the project (but not from disk!) and reimport it as an existing project</li>
</ul>
<p>Failing that, <a href="https://bugs.eclipse.org/bugs/buglist.cgi?query_format=specific&order=relevance+desc&bug_status=__all__&product=JDT&content=Class+file+name+must+end+with+.class" rel="noreferrer">bugs.eclipse.org</a> might provide the answer.</p>
<p>If the workspace is caching something broken, you may be able to delete it by poking around in <strong>workspace/.metadata/.plugins</strong>. Most of that stuff is fairly transient (though backup and watch for deleted preferences).</p>
|
<p>Closing the projects didn't do the trick for me. I started eclipse with the -clean flag and that worked for some reason.</p>
| 2,852
|
<p>I'm about to deploy a mediumsized site powered by Django. I have a dedicated Ubuntu Server. </p>
<p>I'm really confused over which serversoftware to use. So i thought to myself: why not ask stackoverflow.</p>
<p>What i'm looking for is:</p>
<ul>
<li>Easy to set up</li>
<li>Fast and easy on resources</li>
<li>Can serve mediafiles</li>
<li>Able to serve multiple djangosites on same server</li>
<li>I would rather not install PHP or anything else that sucks resources, and for which I have no use for.</li>
</ul>
<p>I have heard of mod_wsgi and mod_python on Apache, nginx and lighty. Which are the pros and cons of these and have i missed someone?</p>
<p><strong>@Barry</strong>: Somehow i feel like Apache is to bloated for me. What about the alternatives?</p>
<p><strong>@BrianLy</strong>: Ok I'll check out mod_wsgi some more. But why do i need Apache if i serve static files with lighty? I have also managed to serve the django app itself with lighty. Is that bad in anyway? Sorry for beeing so stupid :-)</p>
<p><strong>UPDATE</strong>: What about lighty and nginx - which are the uses-cases when these are the perfect choice?</p>
|
<p>Since I was looking for some more in-depth answers, I decided to research the issue myself in depth. Please let me know if I've misunderstood anything.</p>
<p>Some general recommendation are to use a separate webserver for handling media. By separate, I mean a webserver which is not running Django. This server can be for instance:</p>
<ul>
<li>Lighttpd (Lighty)</li>
<li>Nginx (EngineX)</li>
<li>Or some other light-weight server</li>
</ul>
<p>Then, for Django, you can go down different paths. You can either:</p>
<ul>
<li><p>Serve Django via <strong>Apache</strong> and:</p>
<ul>
<li><p><strong>mod_python</strong></p>
<p>This is the stable and recommended/well documented way. Cons: uses a lot of memory.</p></li>
<li><p><strong>mod_wsgi</strong></p>
<p>From what I understand, mod_wsgi is a newer alternative. It appears to be faster and easier on resources.</p></li>
<li><p><strong>mod_fastcgi</strong></p>
<p>When using FastCGI you are delegating the serving of Django to another process. Since mod_python includes a python interpreter in every request it uses a lot of memory. This is a way to bypass that problem. Also there is some security concerns.</p>
<p>What you do is that you start your Django FastCGI server in a separate process and then configures apache via rewrites to call this process when needed.</p></li>
</ul></li>
</ul>
<p>Or you can:</p>
<ul>
<li><p>Serve Django <strong>without using Apache</strong> but with another server that supports FastCGI natively:</p>
<p>(The documentation mentions that you can do this if you don't have any Apache specific needs. I guess the reason must be to save memory.)</p>
<ul>
<li><strong>Lighttpd</strong></li>
</ul>
<p>This is the server that runs Youtube. It seems fast and easy to use, however i've seen reports on memoryleaks.</p>
<ul>
<li><strong>nginx</strong></li>
</ul>
<p>I've seen benchmarks claiming that this server is even faster than lighttpd. It's mostly documented in Russian though.</p></li>
</ul>
<p>Another thing, due to limitations in Python your server should be running in forked mode, not threaded.</p>
<p>So this is my current research, but I want more opinions and experiences.</p>
|
<p>If you're using lighthttpd, you can also use FastCGI for serving Django. I'm not sure how the speed compares to mod_wsgi, but if memory serves correctly, you get a couple of the benefits that you would get with mod_wsgi that you wouldn't get with mod_python. The main one being that you can give each application its own process (which is really helpful for keeping memory of different apps separated as well as for taking advantage of multi-core computers.</p>
<p>Edit: Just to add in regards to your update about nginix, if memory serves correctly again, nginix uses "greenlets" to handle concurrency. This means that you may need to be a little bit more careful to make sure that one app doesn't eat up all the server's time.</p>
| 4,562
|
<p>I've got a sign up form that requires the user to enter their email and password, both are in two separate text boxes. I want to provide a button that the user can click so that the password (which is masked) will appear in a popup when the user clicks the button.</p>
<p>Currently my JavaScript code for this is as follows:</p>
<pre><code> function toggleShowPassword() {
var button = $get('PASSWORD_TEXTBOX_ID');
var password;
if (button)
{
password = button.value;
alert(password);
button.value = password;
}
}
</code></pre>
<p>The problem is that every time the user clicks the button, the password is cleared in both Firefox and IE. I want them to be able to see their password in clear text to verify without having to retype their password.</p>
<p>My questions are:</p>
<ol>
<li><p>Why does the password field keep getting reset with each button click?</p></li>
<li><p>How can I make it so the password field is NOT cleared once the user has seen his/her password in clear text?</p></li>
</ol>
|
<p>I did a quick example up of a working version:</p>
<pre><code><html>
<head>
<script type="text/javascript" src="prototype.js"></script>
<script type="text/javascript">
function toggleShowPassword() {
var textBox = $('PasswordText');
if (textBox)
{
alert(textBox.value);
}
}
</script>
</head>
<body>
<input type="password" id="PasswordText" /><input type="button" onclick="toggleShowPassword();" value="Show Password" />
</body>
</html>
</code></pre>
<p>The key is that the input is of type button and not submit. I used the <a href="http://prototypejs.org/" rel="nofollow noreferrer">prototype</a> library for retrieving the element by ID.</p>
|
<p>You do not need to do <code>button.value = password;</code> since reading the value does not change it. I'm not sure why it's being cleared, maybe JavaScript does not allow password field values to be modified.</p>
| 6,618
|
<p>I’m in the process of installing a BLTouch on a Velleman Vertex K8400. The board doesn’t have a dedicated servo pin, so I’ll assign one. No problem there.</p>
<p>The board only has a Z-min pin, so it’s my understanding that I’m supposed to unplug my Z-min cable and plug the BLTouch into the Z-min port.</p>
<p>My question is: "Can't I assign another unused pin as a Z-max, plug the BLTouch into that, adjust the firmware, and leave the existing Z-min sensor plugged in?"</p>
<p>Upon further review, I probably shouldn't have said Z-max, and will be more specific.</p>
<p>This is a Mega 2560 board with 2 available PWM pins. Anything wrong with this setup?</p>
<p>Pins.h:</p>
<pre>
#define SERVO_0_PIN 15 //PH3 (PWM)
#define Z_MIN_PROBE_PIN 16 //PH4 (PWM)
</pre>
<p>Configuration.h:</p>
<pre>
=======Z Probe Option=======
#define Z_MIN_PROBE_ENDSTOP
#define BLTOUCH
</pre>
<p>I want be able to keep my Z-min sensor plugged in as a backup to prevent a bed crash just in case the BL touch doesn't trigger. From what I see this should work as long as I make sure the BLTouch triggers before the Z-min. Any issues that anyone can see?</p>
|
<p><strong><em>Note</strong>: The question has changed after posting this answer. This answer answered the previous question, but is now out-of-date with respect to how the question has changed; I'll update it later, as it is possible what is asked now.</em></p>
<hr>
<p>You can change the Z-min and the Z-max pin assignment in Marlin Firmware in the <code>pins_<boardname>.h</code> file, you basically exchange the Z-min and the Z-max. Note that the switch connected to the old Z-min port now becomes a Z-max sensor if you enable that in the firmware; you should therefore remove it (the actual switch) from the minimum Z position.</p>
<hr>
<p>To enable a BLTouch sensor you require 2 pins free on the microprocessor. One registers the signal of the trigger, the other triggers the servo to stow/deploy the sensor.</p>
<p>You can connect the white/black to the Z-min signal (Z-min pin) and ground of the Z-min connector (or if pins are swapped in the firmware to the Z-max). The other wires need to be connected to +5 V (red), ground (brown) and orange/yellow to a free analog pin (PWM pin):</p>
<blockquote>
<p><a href="https://www.indiegogo.com/projects/bltouch-auto-bed-leveling-sensor-for-3d-printers#/" rel="nofollow noreferrer">BLTouch can be operated in the following condition.</a><br>
- One I/O for control (PWM or Software PWM)<br>
- One I/O for Zmin (Z Probe)<br>
- GND and +5 V power</p>
</blockquote>
<p>The PWM pin should be defined in your <code>pins_<boardname>.h</code> file, e.g.:</p>
<pre><code>#define SERVO0_PIN 5 // RUMBA board
</code></pre>
<p>or</p>
<pre><code>#define SERVO0_PIN 27 // ANET board
</code></pre>
<p>The Z-max signal pin is no PWM pin for the servo.</p>
|
<p><strong><em>Note</strong>: The question has changed after posting this answer. This answer answered the previous question, but is now out-of-date with respect to how the question has changed; I'll update it later, as it is possible what is asked now.</em></p>
<hr>
<p>You can change the Z-min and the Z-max pin assignment in Marlin Firmware in the <code>pins_<boardname>.h</code> file, you basically exchange the Z-min and the Z-max. Note that the switch connected to the old Z-min port now becomes a Z-max sensor if you enable that in the firmware; you should therefore remove it (the actual switch) from the minimum Z position.</p>
<hr>
<p>To enable a BLTouch sensor you require 2 pins free on the microprocessor. One registers the signal of the trigger, the other triggers the servo to stow/deploy the sensor.</p>
<p>You can connect the white/black to the Z-min signal (Z-min pin) and ground of the Z-min connector (or if pins are swapped in the firmware to the Z-max). The other wires need to be connected to +5 V (red), ground (brown) and orange/yellow to a free analog pin (PWM pin):</p>
<blockquote>
<p><a href="https://www.indiegogo.com/projects/bltouch-auto-bed-leveling-sensor-for-3d-printers#/" rel="nofollow noreferrer">BLTouch can be operated in the following condition.</a><br>
- One I/O for control (PWM or Software PWM)<br>
- One I/O for Zmin (Z Probe)<br>
- GND and +5 V power</p>
</blockquote>
<p>The PWM pin should be defined in your <code>pins_<boardname>.h</code> file, e.g.:</p>
<pre><code>#define SERVO0_PIN 5 // RUMBA board
</code></pre>
<p>or</p>
<pre><code>#define SERVO0_PIN 27 // ANET board
</code></pre>
<p>The Z-max signal pin is no PWM pin for the servo.</p>
| 1,304
|
<p>Here is the scenario that I have. I have a cvs repository in one location (A) and I want to replicate it and keep it in sync with a repository in another location(B). This would be a single directional sync from A to B. What is the best way to do this? If it is not really feasible in CVS then which source code control system would you recommend to accomplish this? Thanks</p>
|
<p>When using CVS, I don't know any tools to do that other than files syncing. You can achieve that using tools like <code>rsync</code> (Unix) or <code>xcopy</code>/<code>robocopy</code> (Windows).</p>
<p>If you plan on migrating to Subversion, it provides a tool called svnsync that allows to sync a repository from another one.</p>
|
<p>The Best (and perhaps costliest) way is <a href="http://www-01.ibm.com/software/awdtools/clearcase/multisite/" rel="nofollow noreferrer">Clearcase Multisite</a></p>
<p>But if you are looking for opensource, <a href="http://git.or.cz/" rel="nofollow noreferrer">Git</a> is becoming quickly replacing svn everywhere.. </p>
| 3,681
|
<p>Supposing you have a form that collects and submits sensitive information and you want to ensure it is never accessed via insecure (non-HTTPS) means, how might you best go about enforcing that policy?</p>
|
<p>If you're running Apache, you can put a <code>RewriteRule</code> in your <code>.htaccess</code>, like so:</p>
<pre><code>RewriteCond %{HTTPS} "off"
RewriteRule /mypage.html https://example.com/mypage.html
</code></pre>
|
<p>Take a look at this: <a href="http://www.dotnetmonster.com/Uwe/Forum.aspx/asp-net/75369/Enforcing-https" rel="nofollow noreferrer">http://www.dotnetmonster.com/Uwe/Forum.aspx/asp-net/75369/Enforcing-https</a></p>
<p>Edit: This shows solutions from an IIS point of view, but you should be able to configure about any web server for this.</p>
| 7,871
|
<p>I've got a bracelet concept that I've sketched up as a flat design. I'm trying to found a route by which I can extrude this into a 3d object (depth map?), curve it into a bracelet, then ultimately create a STL file out of it. I'm having trouble finding a way to do this that allows me to "warp" the flat object into a bracelet before I try to print. </p>
<p>Is there a recommend technique for this? I'm not worried about representation of the picture; it's effectively meant to be an 'etched' pattern.</p>
|
<p>This may not be your cuppa tea, but if you're willing to learn to use <a href="http://www.openscad.org/" rel="nofollow noreferrer">OpenSCAD</a> or already know how, there's a <a href="https://www.thingiverse.com/thing:1668883/" rel="nofollow noreferrer">Thingiverse</a> post that appears to directly address your objective.</p>
<p>Correction, this particular post on Thingiverse consists of a series of Python files, of which I have zero experience/qualifications. It may still be of value, if you are Python capable.</p>
<p><a href="https://i.stack.imgur.com/i9Fkh.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/i9Fkh.jpg" alt="santa on a mug"></a></p>
<p>Another resource that is strictly OpenSCAD is from Eric Buijs, a rather talented 3D design person. His YouTube channel has a number of useful tutorials for both OpenSCAD and Solvespace. <a href="https://www.youtube.com/watch?v=PNcGNqMUl5I" rel="nofollow noreferrer">This video</a> in particular describes applying a flat object to a curved one using OpenSCAD, resulting in a lithophane.</p>
<p><a href="https://i.stack.imgur.com/MbyOa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MbyOa.png" alt="curved lithophane"></a></p>
<p>As I created this answer, I did not re-watch the 12+ minute video, but I recall how he explains clearly how the program dissects the surface into a number of flat panels and then superimposes the image on each segment. From this presentation, I suspect one could expand to a full cylinder.</p>
|
<p>This is the best and simplest way I've found to transform a flat design into a 3D object that you can then save as an STL file: <a href="https://www.youtube.com/watch?v=ows2QTiMRPg" rel="nofollow noreferrer">Blender-Converting 2D Image to 3D Object</a></p>
<p>This solution requires you to use <a href="https://www.blender.org/" rel="nofollow noreferrer">Blender</a> and <a href="https://inkscape.org/" rel="nofollow noreferrer">Inkscape</a>, both softwares are open-source and available for free at this time.</p>
<p>As suggested below by @Greenonline, I will provide a step by step in case the video is removed from Youtube. I'm sorry that I cannot provide screenshots at the moment, but I'm on a trip and writing from an old laptop that cannot run either Blender or Inkscape.</p>
<ol>
<li><p>Load your image in Inkscape.</p>
<ul>
<li>Format is unimportant as long as Inkscape can read it. It works with black and white and color images, but please note that color information won't be sent to Blender in the end, you'll have to add color materials yourself once the picture has been converted to a 3D object.</li>
</ul></li>
<li><p>Select the image or the portion of it that you want to turn into a 3D object.</p>
<ul>
<li>For some unknown reason, Inkscape doesn't automatically select the image you loaded into it, so you have to do it manually. When the image is selected, it will be surrounded by a dotted line and you'll see arrows appear on the sides and corners.</li>
</ul></li>
<li><p>Go to Path > Trace Bitmap, or use Shift+Alt+B, and a pop-up window will appear. Keep the default settings, just make sure that the 'Remove background' option, located at the bottom of the window, is checked, then click OK.</p>
<ul>
<li>You can see the result of the operation in the 'Preview' window. If the 'Preview' is empty, just click on the 'Update' button located below 'Preview'. If it is still empty after you clicked on 'Update', then you haven't selected your picture as indicated in Step 2!</li>
</ul></li>
<li><p>Got to File > Save As and save your file as 'Plain svg'.</p>
<ul>
<li>Saving as 'Inkscape svg' should work as well, but it's always best to use the standard format.</li>
</ul></li>
</ol>
<p>And you're done with Inkscape, time to switch to Blender.</p>
<ol start="5">
<li><p>Go to File > Import > Scalable Vector Graphics (.svg) and import the picture you just created in Inkscape.</p>
<ul>
<li>If you do not see Scalable Vector Graphics (.svg) in the list of importable files, it means the add-on hasn't been activated. You can do it by going to File > User Preferences > Add-ons then typing 'svg' in the search field will bring up the relevant add-on (Import-Export: Scalable Vector Graphics (SVG) format). Clicking the checkbox next to it's name will automatically activate it. </li>
<li>The picture will usually appear very small in Blender. Press 5 on the numeric keyboard to home onto it, then you can stretch it to the desired size by using the relevant tools in Blender. </li>
<li>It might be a good idea to move the object center into the middle of the geometry, although, from personal experience, you can do it after it becomes 3D without too much trouble.</li>
</ul></li>
<li><p>Your picture has been loaded in Blender as a Curve object. Go to the 'Curve' tab and in the 'Geometry' sub-menu you can use the 'Extrude' slider to give depth to your picture.</p></li>
<li><p>Finally, once you've extruded your curve to your satisfaction, go to Object > Convert To > Mesh from Curve/Meta/Surf/Text, or use Alt+C, and voila, you're done!</p></li>
</ol>
<p>You know have a nice 3D object made of polygons that you can modify at your leisure using Blender's tools.</p>
| 1,031
|
<p>I read everywhere that business logic belongs in the models and not in controller but where is the limit?
I am toying with a personnal accounting application. </p>
<pre><code>Account
Entry
Operation
</code></pre>
<p>When creating an operation it is only valid if the corresponding entries are created and linked to accounts so that the operation is balanced for exemple buy a 6-pack :</p>
<pre><code>o=Operation.new({:description=>"b33r", :user=>current_user, :date=>"2008/09/15"})
o.entries.build({:account_id=>1, :amount=>15})
o.valid? #=>false
o.entries.build({:account_id=>2, :amount=>-15})
o.valid? #=>true
</code></pre>
<p>Now the form shown to the user in the case of <em>basic operations</em> is simplified to hide away the entries details, the accounts are selected among 5 default by the kind of operation requested by the user (intialise account -> equity to accout, spend assets->expenses, earn revenues->assets, borrow liabilities->assets, pay debt assets->liabilities ...) I want the entries created from default values.</p>
<p>I also want to be able to create more complex operations (more than 2 entries). For this second use case I will have a different form where the additional complexity is exposed.This second use case prevents me from including a debit and credit field on the Operation and getting rid of the Entry link. </p>
<p>Which is the best form ? Using the above code in a SimpleOperationController as I do for the moment, or defining a new method on the Operation class so I can call Operation.new_simple_operation(params[:operation])</p>
<p>Isn't it breaking the separation of concerns to actually create and manipulate Entry objects from the Operation class ?</p>
<p>I am not looking for advice on my twisted accounting principles :)</p>
<p>edit -- It seems I didn't express myself too clearly.
I am not so concerned about the validation. I am more concerned about where the creation logic code should go : </p>
<p>assuming the operation on the controller is called spend, when using spend, the params hash would contain : amount, date, description. Debit and credit accounts would be derived from the action which is called, but then I have to create all the objects. Would it be better to have </p>
<pre><code>#error and transaction handling is left out for the sake of clarity
def spend
amount=params[:operation].delete(:amount)#remove non existent Operation attribute
op=Operation.new(params[:operation])
#select accounts in some way
...
#build entries
op.entries.build(...)
op.entries.build(...)
op.save
end
</code></pre>
<p>or to create a method on Operation that would make the above look like </p>
<pre><code>def spend
op=Operation.new_simple_operation(params)
op.save
end
</code></pre>
<p>this definitely give a much thinner controller and a fatter model, but then the model will create and store instances of other models which is where my problem is.</p>
|
<blockquote>
<p>but then the model will create and store instances of other models which is where my problem is.</p>
</blockquote>
<p>What is wrong with this? </p>
<p>If your 'business logic' states that an Operation must have a valid set of Entries, then surely there is nothing wrong for the Operation class to know about, and deal with your Entry objects.</p>
<p>You'll only get problems if you take this too far, and have your models manipulating things they <em>don't</em> need to know about, like an EntryHtmlFormBuilder or whatever :-)</p>
|
<p>It's easier to think in terms of each entity validating itself, and entities which depend on one another delegating their state to the state of their associated entries. In your case, for instance:</p>
<pre><code>class Operation < ActiveRecord::Base
has_many :entries
validates_associated :entries
end
</code></pre>
<p>validates_associated will check whether each associated entity is valid (in this case, all entries should if the operation is to be valid).</p>
<p>It is very tempting to try to validate entire hierarchies of models as a whole, but as you said, the place where that would be most easily done is the controller, which should act more as a router of requests and responses than in dealing with business logic.</p>
| 8,974
|
<p>How can I do this fast?</p>
<p>Sure I can do this:</p>
<pre><code>static bool ByteArrayCompare(byte[] a1, byte[] a2)
{
if (a1.Length != a2.Length)
return false;
for (int i=0; i<a1.Length; i++)
if (a1[i]!=a2[i])
return false;
return true;
}
</code></pre>
<p>But I'm looking for either a <a href="https://en.wikipedia.org/wiki/Standard_Libraries_%28CLI%29#Base_Class_Library" rel="noreferrer">BCL</a> function or some highly optimized proven way to do this.</p>
<pre><code>java.util.Arrays.equals((sbyte[])(Array)a1, (sbyte[])(Array)a2);
</code></pre>
<p>works nicely, but it doesn't look like that would work for x64.</p>
<p>Note my super-fast answer <a href="https://stackoverflow.com/a/8808245/4489">here</a>.</p>
|
<p>You can use <a href="http://msdn.microsoft.com/en-us/library/bb348567.aspx" rel="noreferrer">Enumerable.SequenceEqual</a> method.</p>
<pre><code>using System;
using System.Linq;
...
var a1 = new int[] { 1, 2, 3};
var a2 = new int[] { 1, 2, 3};
var a3 = new int[] { 1, 2, 4};
var x = a1.SequenceEqual(a2); // true
var y = a1.SequenceEqual(a3); // false
</code></pre>
<p>If you can't use .NET 3.5 for some reason, your method is OK.<br>
Compiler\run-time environment will optimize your loop so you don't need to worry about performance. </p>
|
<p>If you are looking for a very fast byte array equality comparer, I suggest you take a look at this STSdb Labs article: <a href="http://stsdb.com/forum/stsdb-4-x/sts-labs/466-byte-array-equality-comparer.html#post1249" rel="nofollow">Byte array equality comparer.</a> It features some of the fastest implementations for byte[] array equality comparing, which are presented, performance tested and summarized.</p>
<p>You can also focus on these implementations:</p>
<p><a href="http://svn.stsdb.com:221/svn/STSdb/STSdb4/STSdb4/General/Comparers/BigEndianByteArrayComparer.cs" rel="nofollow">BigEndianByteArrayComparer</a> - fast byte[] array comparer from left to right (BigEndian)
<a href="http://svn.stsdb.com:221/svn/STSdb/STSdb4/STSdb4/General/Comparers/BigEndianByteArrayComparer.cs" rel="nofollow">BigEndianByteArrayEqualityComparer</a> - - fast byte[] equality comparer from left to right (BigEndian)
<a href="http://svn.stsdb.com:221/svn/STSdb/STSdb4/STSdb4/General/Comparers/BigEndianByteArrayEqualityComparer.cs" rel="nofollow">LittleEndianByteArrayComparer</a> - fast byte[] array comparer from right to left (LittleEndian)
<a href="http://svn.stsdb.com:221/svn/STSdb/STSdb4/STSdb4/General/Comparers/LittleEndianByteArrayEqualityComparer.cs" rel="nofollow">LittleEndianByteArrayEqualityComparer</a> - fast byte[] equality comparer from right to left (LittleEndian)</p>
| 6,488
|
<p>I have an existing J2EE enterprise application to which I need to add auditing, i.e. be able to record CRUD operations on several important domain types (Employee, AdministratorRights, etc.).</p>
<p>The application has a standard n-tier architecture:</p>
<ul>
<li>Web interface</li>
<li>Business operations encapsulated within a mixture of stateless session beans and transactional POJOs (using Spring)</li>
<li>persistence is a mixture of direct JDBC (from within the business layer) and EJB 2.x BMP entity beans (I know, I know)</li>
</ul>
<p>My question is: are there any standard patterns or (better still) frameworks/libraries specifically for adding auditing as a cross-cutting concern? I know AOP can be used to implement cross-cutting concerns in general; I want to know if there's something specifically aimed at auditing.</p>
|
<p>Maybe you should have a look at <a href="http://audit4j.org/" rel="noreferrer">Audit4j</a> that provides auditing of business functionality and has several options for configuration.
Another framework is <a href="http://javers.org/" rel="noreferrer">JaVers</a> that focues more on auditing low-level modification on persistence layer, which might match your case a bit better.</p>
<p>Both framework provide audit-specific functionalities that goes beyond plain AOP/Interceptors.</p>
|
<p>Try an <a href="http://en.wikipedia.org/wiki/Aspect-oriented_programming" rel="nofollow noreferrer">Aspect Oriented</a> programming framework.</p>
<p>From Wikipedia "Aspect-oriented programming (AOP) is a programming paradigm that increases modularity by allowing the separation of cross-cutting concerns".</p>
| 9,428
|
<p>I think most people here understand the importance of fully automated builds.</p>
<p>The problem is one of our project is now using an integrated Visual Studio Setup project (vdproj) and has recently been ported to Visual Studio 2008. Unfortunatly, those won't build in MSBuild and calling devenv.exe /build on 2008 just crashes, apparently it does that on all multi core computer (!!!). So now I have the choice to either rollback to .Net 2.0 and 2005 or simply ditch Visual Studio deployement, but first, I'd like a second opinion.</p>
<p>Anyone knows of another automated way to build a .vdproj that will not require us to open the IDE and click on stuff?</p>
<hr>
<p>WiX was what I had in mind when saying we would ditch vdproj. Do you have any experience with it, good things, caveat?</p>
|
<p>The low cost solution is to switch to using ClickOnce, which you can automate using MSBuild. But if you still need to create a Windows Installer package, you will need to convert your project to WiX (pretty straight foward) and build that with your solution. </p>
<p>This will get you started:
<a href="http://msdn.microsoft.com/en-us/magazine/cc163456.aspx" rel="noreferrer">Automate Releases With MSBuild And Windows Installer XML</a></p>
|
<p>I had the same requirement and ended up using what is suggested in these two links</p>
<p><a href="http://geekswithblogs.net/davewill/archive/2009/03/02/129787.aspx" rel="nofollow noreferrer">David Williams Blog</a></p>
<p><a href="http://msdn.microsoft.com/en-us/library/ms404859.aspx" rel="nofollow noreferrer">MSDN article</a></p>
<p>Basically, since Team Build, by itself, will not build the setup projects for you, this approach has you add a new build step after the regular build is complete. This step fires off a second build by launching the devenv.exe. The IDE will build your setup files. The extra build is a bit costly but we only needed it for builds that were going to be pushed out. The Daily build at most would need this customization our CI build does not need to build setup files each time.</p>
<p>After that you execute some Copy commands, once again build steps that show up in your Team System build results, to move the setup files to a network share etc.</p>
<p>It feels a bit like a kluge at first, but it does work, it is also a full-fledged part of the automated build in Team System so it worked for my Continuous Integration goals.</p>
| 2,591
|
<p>I maintain a Java Swing application.</p>
<p>For backwards compatibility with java 5 (for Apple machines), we maintain two codebases, 1 using features from Java 6, another without those features.</p>
<p>The code is largely the same, except for 3-4 classes that uses Java 6 features.</p>
<p>I wish to just maintain 1 codebase. Is there a way during compilation, to get the Java 5 compiler to 'ignore' some parts of my code?</p>
<p>I do not wish to simply comment/uncomment parts of my code, depending on the version of my java compiler.</p>
|
<p>Assuming that the classes have similar functionality with 1.5 vs. 6.0 differences in implementation you could merge them into one class. Then, without editing the source to comment/uncomment, you can rely on the optimization that the compiler always do. If an if expression is always false, the code in the if statement will not be included in the compilation.</p>
<p>You can make a static variable in one of your classes to determine which version you want to run:</p>
<pre><code>public static final boolean COMPILED_IN_JAVA_6 = false;
</code></pre>
<p>And then have the affected classes check that static variable and put the different sections of code in a simple if statement</p>
<pre><code>if (VersionUtil.COMPILED_IN_JAVA_6) {
// Java 6 stuff goes here
} else {
// Java 1.5 stuff goes here
}
</code></pre>
<p>Then when you want to compile the other version you just have to change that one variable and recompile. It might make the java file larger but it will consolidate your code and eliminate any code duplication that you have. Your editor may complain about unreachable code or whatever but the compiler should blissfully ignore it.</p>
|
<p>There is no pre-compiler in Java. Thus, no way to do a #ifdef like in C.
Build scripts would be the best way.</p>
| 9,986
|
<p>I'm looking for a way of getting a <strong>concurrent collection</strong> in <strong>C#</strong> or at least a collection which supports a <strong>concurrent enumerator</strong>. Right now I'm getting an <code>InvalidOperationException</code> when the collection over which I'm iterating changes. </p>
<p>I could just deep copy the collection and work with a private copy but I'm wondering if there is perhaps a better way</p>
<p>Code snippet:</p>
<pre class="lang-cs prettyprint-override"><code>foreach (String s in (List<String>) callingForm.Invoke(callingForm.delegateGetKillStrings))
{
//do some jazz
}
</code></pre>
<p>--edit--</p>
<p>I took the answer but also found that I needed to ensure that the code which was writing to the collection needed to attempt to get a lock as well.</p>
<pre class="lang-cs prettyprint-override"><code>private void addKillString(String s)
{
lock (killStrings)
{
killStrings.Add(s);
}
}
</code></pre>
|
<p>Other than doing a deep-copy your best bet might be to lock the collection:</p>
<pre><code> List<string> theList = (List<String> )callingForm.Invoke(callingForm.delegateGetKillStrings);
lock(theList.SyncRoot) {
foreach(string s in theList) {
// Do some Jazz
}
}
</code></pre>
|
<p>If you want to use the FCL collections, then locking is the only way to support iteration / modification from multiple threads that may overlap.</p>
<p>Be careful what you use as your lock object, though. Using SyncRoot is only a good idea if the collection itself is a private member of the class that uses it. If the collection is protected or public, then a client of your class can take its own lock on your SyncRoot, potentially deadlocking with code in your class. </p>
<p>If you are interested in taking a look at a 3rd-party collection library, I recommend the excellent <a href="http://www.itu.dk/research/c5/" rel="nofollow noreferrer">C5 Generic Collection Library</a>. They have a family of tree-based collections that can easily and safely be modified and iterated at the same time without locking - see sections 8.10 and 9.11 of their (excellent) documentation for details.</p>
| 5,970
|
<p>I have a VB6 program that someone recently helped me convert to VB.NET</p>
<p>In the program, when saving files, I stamp them with the date which I was getting by calling the Today() function. </p>
<p>When I try to run the new VB.NET code in Vista it throws a permission exception for the Today() . If I run Visual Studio Express (this is the 2008 Express version) in Admin mode, then the problem doesn't occur, but clearly I want to end up with a stand-alone program which runs for all users without fancy permissions.</p>
<p>So how can a normal VB.NET program in Vista get today's date?</p>
|
<p>Use <code>DateTime.Now</code> or <code>DateTime.Today</code>. These are entirely managed and shouldn't throw security exceptions.</p>
<p>The old VB6 functions, such as <code>Len()</code>, <code>Left()</code>, <code>Right()</code>, <code>OpenFile()</code>, <code>FreeFile()</code> are all present in the .NET Framework in the Microsoft.VisualBasic DLL. To maintain backwards compatibility, they all call the old functions in unmanaged code. Unmanaged code requires special security permissions because it can be dangerous.</p>
<p>Whenever possible, try and use the newer .NET functions. They are usually much faster (File IO using Streams for instance) and safer.</p>
|
<p>When I try the following statement:</p>
<pre><code>Dim result As String = Today()
</code></pre>
<p>It gives me today's date, as I'd expect, and I'm running VB2005 on Vista. Can you modify the question with the version of VB you're using? Also, can you try the following statement instead of <code>Today()</code> to see it works for you without the exception?</p>
<pre><code>Dim result As String = Now()
</code></pre>
| 9,003
|
<p>So I'm running PPP under linux with a cellular modem. The program I'm writing needs to know if the link is active before sending any data.</p>
<p>What are my options to check</p>
<ul>
<li>if the link is available</li>
<li>if it routes to a server I control (it doesn't go to the internet as I said earlier)</li>
</ul>
<p>Also, what is the best way to restart it - I'd like to have program control over when it starts and stops, so I assume an init.d isn't appropriate. Using <code>system()</code> doesn't seem to give a PID, are there other options besides <code>fork()</code> and the gaggle of <code>exec??()</code> calls?</p>
<p>C on Linux on ARM (custom distribution using buildroot).</p>
|
<p>You can use the <code>ip-up</code> script functionality of pppd to have it execute a program when the IP interface is up and ready. Details are in the <a href="http://ppp.samba.org/pppd.html" rel="nofollow noreferrer">pppd(8) man page</a> - search for "ip-up".</p>
<p>To restart pppd, use the <code>linkname</code> parameter to set a known pidfile name (<code>/var/run/ppp-name.pid</code>). Also use the <code>persist</code> option. When you want to restart pppd, send the <code>SIGHUP</code> signal. Again, this is described in the man page.</p>
|
<p>You could parse <code>/proc/net/route</code>.</p>
| 7,434
|
<p>I find myself writing delegates occasionally for really simple functions (take no arguments and return void for example) and am wondering if anyone knows someplace that has compiled a list of all the predefined delegates already available in the .NET framework so I can reuse them?</p>
<p>To be clear I am looking for something like this:</p>
<ul>
<li>void System.AsyncCallback(System.IAsyncResult)</li>
<li>int System.Comparison(T x, T y)</li>
<li>void System.IO.ErrorEventHandler(object, System.Io.ErrorEventArgs)</li>
</ul>
<p>and so on</p>
<p>If not, sounds like a good idea for a blog article.</p>
|
<p>Just look in the msdn database for (T) delegate.</p>
<p>Here you got a direct link: <a href="http://social.msdn.microsoft.com/Search/en-us/?Query=(T)%20delegate" rel="noreferrer">List of delegates</a></p>
<p>That should get you started.</p>
|
<p>In .NET 2.0 and later, use EventHandler if you have no arguments at all, and EventHandler<T> if you want to provide some custom data (you will need to derive a class from EventArgs with your additional data in it). If you have no EventArgs to use, pass EventArgs.Empty.</p>
<p>Because EventArgs is a reference type, all instances of EventHandler<T> use the same JITted code.</p>
| 9,163
|
<p>When using <a href="http://jquery.com/" rel="nofollow noreferrer">jQuery</a>'s <a href="http://docs.jquery.com/Ajax/jQuery.ajax#options" rel="nofollow noreferrer">ajax method</a> to submit form data, what is the best way to handle errors?
This is an example of what a call might look like:</p>
<pre><code>$.ajax({
url: "userCreation.ashx",
data: { u:userName, p:password, e:email },
type: "POST",
beforeSend: function(){disableSubmitButton();},
complete: function(){enableSubmitButton();},
error: function(xhr, statusText, errorThrown){
// Work out what the error was and display the appropriate message
},
success: function(data){
displayUserCreatedMessage();
refreshUserList();
}
});
</code></pre>
<p>The request might fail for a number of reasons, such as duplicate user name, duplicate email address etc, and the ashx is written to throw an exception when this happens.</p>
<p>My problem seems to be that by throwing an exception the ashx causes the <code>statusText</code> and <code>errorThrown</code> to be <strong>undefined</strong>.</p>
<p>I can get to the <code>XMLHttpRequest.responseText</code> which contains the HTML that makes up the standard .net error page.</p>
<p>I am finding the page title in the responseText and using the title to work out which error was thrown. Although I have a suspicion that this will fall apart when I enable custom error handling pages.</p>
<p>Should I be throwing the errors in the ashx, or should I be returning a status code as part of the data returned by the call to <code>userCreation.ashx</code>, then using this to decide what action to take?<br>
How do you handle these situations?</p>
|
<blockquote>
<p>Should I be throwing the errors in the
ashx, or should I be returning a
status code as part of the data
returned by the call to
userCreation.ashx, then using this to
decide what action to take? How do you
handle these situations?</p>
</blockquote>
<p>Personally, if possible, I would prefer to handle this on the server side and work up a message to the user there. This works very well in a scenario where you only want to display a message to the user telling them what happened (validation message, essentially).</p>
<p>However, if you want to perform an action based on what happened on the server, you may want to use a status code and write some javascript to perform various actions based on that status code.</p>
|
<p>Now I have a problem as to which answer to accept.</p>
<p>Further thought on the problem brings me to the conclusion that I was incorrectly throwing exceptions. Duplicate user names, email addresses etc are expected issues during a sign up process and are therefore not exceptions, but simply errors. In which case I probably shouldn't be throwing exceptions, but returning error codes.</p>
<p>Which leads me to think that <a href="https://stackoverflow.com/users/326/irobinson">irobinson's</a> approach should be the one to take in this case, especially since the form is only a small part of the UI being displayed. I have now implemented this solution and I am returning xml containing a status and an optional message that is to be displayed. I can then use jQuery to parse it and take the appropriate action: -</p>
<pre><code>success: function(data){
var created = $("result", data).attr("success");
if (created == "OK"){
resetNewUserForm();
listUsers('');
} else {
var errorMessage = $("result", data).attr("message");
$("#newUserErrorMessage").text(errorMessage).show();
}
enableNewUserForm();
}
</code></pre>
<p>However <a href="https://stackoverflow.com/users/1414/travis">travis'</a> answer is very detailed and would be perfect during debugging or if I wanted to display an exception message to the user. I am definitely not receiving JSON back, so it is probably down to one of those attributes that travis has listed, as I don't have them in my code.</p>
<p>(I am going to accept irobinson's answer, but upvote travis' answer. It just feels strange to be accepting an answer that doesn't have the most votes.)</p>
| 4,813
|
<p>I want to print out a flat object without any support structure straight onto the build plate of my ender 5. It's going to be PLA and I need it to be thin enough to still be flexible.</p>
<p>I don't have a picture available, but imagine that I wanted to print out the Coke Cola and then wrap it around a bland soda can, so that the logo is raised up slightly?</p>
<p>Alternatively, what is the best layer height to use, and how many layers should I use?</p>
|
<p>With PLA you can just heat it to curve around the object. I've done this with up to 2mm. Real easy with 1mm.</p>
<p>I haven't tried thicker but assume it would work ok.</p>
<p>You'd have to glue it though to make it stick. My attempts were just to shape the prints, I didn't want them sticking so I shaped them around a glass bottle.</p>
<p>If you want it flexible in it's own right, then I suggest 2 * 0.2mm layers. I have a large 2 layer print in front of me that bends easily.</p>
<p><a href="https://i.stack.imgur.com/xFUUn.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xFUUn.jpg" alt="2 layers" /></a></p>
<p>This can be rolled up into a tube, but as soon as you let go it will return to flat.</p>
<p>1 layer is even more flexible but tears along the lines with a bit of effort. So if you want it really flexible I suggest you print 1 layer at slightly lower than normal nozzle height to really get the lines melded together. Or a bit hotter than normal.</p>
|
<p><strong>1 layer, of whatever thickness your device can print.</strong></p>
<p>I did something like this to print letters for a flat sign. The letters were 1mm thick and didn't bend, but I'd accidentally printed quite a lot of brim lines which were a single layer thick, and they'd merged into each other.</p>
<p>The brim worked superbly as a "net" to hold the letters in place, so in theory you could print as little as one layer thick.</p>
<ul>
<li>Nozzle height will have to be exactly right to merge the lines together. There are no lines crossing-over on the next layer to help bond them all together.</li>
<li>Let the print bed cool to ambient before removing it from the bed, to help keep the lines connected. Could take an hour or so.</li>
<li>Use a wide flat scraper to pull job off bed - you might want to design in a "tab" that can be damaged while getting the tool started, and trimmed of later.</li>
</ul>
| 2,129
|
<p>Using VBA, how can I:</p>
<ol>
<li>test whether a file exists, and if so,</li>
<li>delete it?</li>
</ol>
|
<p>1.) Check <a href="http://www.tek-tips.com/faqs.cfm?fid=1936" rel="noreferrer">here</a>. Basically do this:</p>
<pre><code>Function FileExists(ByVal FileToTest As String) As Boolean
FileExists = (Dir(FileToTest) <> "")
End Function
</code></pre>
<p>I'll leave it to you to figure out the various error handling needed but these are among the error handling things I'd be considering:</p>
<ul>
<li>Check for an empty string being passed.</li>
<li>Check for a string containing characters illegal in a file name/path</li>
</ul>
<p>2.) How To Delete a File. Look at <a href="http://word.mvps.org/faqs/macrosvba/DeleteFiles.htm" rel="noreferrer">this.</a> Basically use the Kill command but you need to allow for the possibility of a file being read-only. Here's a function for you:</p>
<pre><code>Sub DeleteFile(ByVal FileToDelete As String)
If FileExists(FileToDelete) Then 'See above
' First remove readonly attribute, if set
SetAttr FileToDelete, vbNormal
' Then delete the file
Kill FileToDelete
End If
End Sub
</code></pre>
<p>Again, I'll leave the error handling to you and again these are the things I'd consider:</p>
<ul>
<li><p>Should this behave differently for a directory vs. a file? Should a user have to explicitly have to indicate they want to delete a directory?</p></li>
<li><p>Do you want the code to automatically reset the read-only attribute or should the user be given some sort of indication that the read-only attribute is set? </p></li>
</ul>
<hr>
<p>EDIT: Marking this answer as community wiki so anyone can modify it if need be.</p>
|
<p>A shorter version of the first solution that worked for me:</p>
<pre><code>Sub DeleteFile(ByVal FileToDelete As String)
If (Dir(FileToDelete) <> "") Then
' First remove readonly attribute, if set
SetAttr FileToDelete, vbNormal
' Then delete the file
Kill FileToDelete
End If
End Sub
</code></pre>
| 9,340
|
<blockquote>
<p><strong>Possible Duplicate:</strong><br>
<a href="https://stackoverflow.com/questions/8127/pre-build-task-deleting-the-working-copy-in-cruisecontrol-net">Pre-build task - deleting the working copy in CruiseControl.NET</a> </p>
</blockquote>
<p>I would like to delete my working directory during the cruisecontrol build process...I'm sure this is easy, but I have been unable to find an example of it...</p>
<p>If you know how to create a directory, that would be useful as well.</p>
<p>Thanks.</p>
|
<p>One of two ways.</p>
<ol>
<li>If you're already using an MSBuild file or something similar, add the action to the MSBuild file.</li>
<li>Instead of directly executing some command, create a batch file that executes that command and then deletes the directory, and have CCnet call that batch file instead.</li>
</ol>
|
<p>My guess is that you want to delete the working directory <em>before</em> CruiseControl.NET gets the latest code from source control. If this is the case, then the only way to accomplish this is to write a custom source control provider for CruiseControl.NET that first deletes the working directory and then gets the latest code. Have a look at CruiseControl.NET's source code for examples of how to write a source control provider.</p>
<p>If you want to delete the working directory <em>after</em> the latest code is retrieved from source control, then you can use CruiseControl.NET's <a href="http://confluence.public.thoughtworks.org/display/CCNET/Executable+Task" rel="nofollow noreferrer">executable task</a> by running "cmd /c del directoryname".</p>
| 4,659
|
<p>I've started to add the time taken to render a page to the footer of our internal web applications. Currently it appears like this</p>
<blockquote>
<p>Rendered in 0.062 seconds</p>
</blockquote>
<p>Occasionally I get rendered times like this</p>
<blockquote>
<p>Rendered in 0.000 seconds</p>
</blockquote>
<p>Currently it's only meant to be a guide for users to judge whether a page is quick to load or not, allowing them to quickly inform us if a page is taking 17 seconds rather than the usual 0.5. My question is what format should the time be in? At which point should I switch to a statement such as</p>
<blockquote>
<p>Rendered in less than a second</p>
</blockquote>
<p>I like seeing the tenths of a second but the second example above is of no use to anyone, in fact it just highlights the limits of the calculation I use to find the render time. I'd rather not let the users see that at all! Any answers welcome, including whether anything should be included on the page.</p>
|
<p>"Rendered instantly" sounds way better than "Rendered in less than a second".</p>
|
<p>I think I over-emphasized it was for the users.</p>
<p>I know by using in trace in the web.config I can get accurate information on page render times along with times for accessing the database.</p>
<p>We have in the past had problems with applications running too slowly over the network although it's now fixed I'm adding the label to new applications so that users are aware it is something we are taking seriously and it's a very simple indicator for the developers.</p>
<p>Taking all that into account I like "Rendered Instantly" and write a lot of sense so I'll accept both your answer and kokos'. </p>
<p>Thanks</p>
| 3,006
|
<p>I have a new German RepRap NEO 3D printer, and when I try heating the Extruder to 215°C with Repetier-Host Mac 1.0.1, it always stops at 130°C - does anybody have an idea what could be the reason?</p>
|
<p>A few possiblitites.</p>
<p>You wire is too small. If your wire is HOT that is a fire hazard.</p>
<p>Your thermistor is bad. Check with a high temp heat probe or try replacing thermistor.</p>
<p>Your heating element is bad (rare).</p>
<p>Last it could be a limit in your firmware. But that would surprise me.</p>
<p>Any chance you have the bed and the hotend reversed? If you had the Bed as Hotend, then it would max out around 100. This last one I would say is most likely..</p>
|
<p>The most likely problem is that your thermistor is either broken or not screwed in correctly. If this is not the case you should either check look through your firmware for issues, or buy a new heater cartridge and thermistor.</p>
| 362
|
<p>How can I center a model at the middle of the printing area of the printer when creating a g-code with CuraEngine. </p>
<p>Are there any parameters I can add to <code>ultimaker2.def.json</code> to achieve this?
Thanks.</p>
|
<p>Found a solution.
This need to be applied under <code>"settings"</code></p>
<pre><code>"command_line_settings": {
"label": "Command Line Settings",
"description": "Settings which are only used if CuraEngine isn't called from the Cura frontend.",
"type": "category",
"enabled": true,
"children": {
"center_object": {
"description": "Whether to center the object on the middle of the build platform (0,0), instead of using the coordinate system in which the object was saved.",
"type": "bool",
"label": "Center object",
"default_value": true,
"enabled": true
}
}
}
</code></pre>
|
<p>If this is over the commandline tool "CuraEngine", then you will have to read the sourcecode. According to the <a href="https://ultimaker.com/en/community/4337-doc-of-curaengine" rel="nofollow noreferrer">Author</a>, 'Nope. Only documentation there is in the code, readme and my head.' (cringe!).</p>
<p>If you're talking of the GUI program, then right click and click "Center". But this requires GUI usage. Not so nice if you want to automate using curaengine as your slicer.</p>
| 708
|
<p>I do not have a clear understanding of what causes resin prints to become brittle. Firstly, it appears excessive cold (in the 40s or even 30s, I am in New England) may be a factor. What else can cause brittleness in resin prints? Is there a difference between resin types?</p>
|
<p>With the information provided my thought is that your layers are underexposed for their thickness. Each layer is just barely bonding to the layer above it. After being pulled on by layers below eventually one of the layers fails. This is especially likely to happen on a thin part of the print any may need more support if it is followed by wider layers. But I would suggest trying to increase your exposure time first.</p>
<p>option two: it could be your FEP if that has seen too much use it may be time to replace it.</p>
<p><a href="https://ameralabs.com/blog/key-things-calibrating-resin-3d-printer/" rel="nofollow noreferrer">calibrating a resin 3D printer</a></p>
|
<p><a href="https://3dprinting.stackexchange.com/a/14947/8884">Besides the options of underexposure or bad FEP film</a>, there's also the option of the print being in a bad orientation for printing. Often, the quality gets better if you tilt the model some degrees. You do have to clean up some places, but the stresses from pulling free of the FEP get distributed more evenly and are lower, resulting in generally better prints.</p>
<p>Other factors that can impact the print quality is the resin's viscosity: the more viscous, the more likely resin can't flow in enough. Resin's viscosity is antiproportional to the room temperature - the hotter the room, the less viscous the resin.</p>
| 1,781
|
<p>In a project I am interfacing between C++ and a C library that uses stdbool.h defined as such.</p>
<pre><code>#ifndef _STDBOOL_H
#define _STDBOOL_H
/* C99 Boolean types for compilers without C99 support */
/* http://www.opengroup.org/onlinepubs/009695399/basedefs/stdbool.h.html */
#if !defined(__cplusplus)
#if !defined(__GNUC__)
/* _Bool builtin type is included in GCC */
typedef enum { _Bool_must_promote_to_int = -1, false = 0, true = 1 } _Bool;
#endif
#define bool _Bool
#define true 1
#define false 0
#define __bool_true_false_are_defined 1
#endif
#endif
</code></pre>
<p>Some structures have <code>bool</code> members. So if I have one of these structures defined as local variables within a C++ function and pass it to a C function the sizes are inconsistent between C++ and C as bool is one bye in C++ and 4 in C.</p>
<p>Does anyone have any advice to how to overcome this without resorting to my current solution which is</p>
<pre><code>//#define bool _Bool
#define bool unsigned char
</code></pre>
<p>Which is against the C99 standard for <a href="http://www.opengroup.org/onlinepubs/000095399/basedefs/stdbool.h.html" rel="noreferrer">stdbool.h</a></p>
|
<p>I found the answer to my own question by finding a more compatible implementation of <code>stdbool.h</code> that is compliant with the C99 standard.</p>
<pre><code>#ifndef _STDBOOL_H
#define _STDBOOL_H
#include <stdint.h>
/* C99 Boolean types for compilers without C99 support */
/* http://www.opengroup.org/onlinepubs/009695399/basedefs/stdbool.h.html */
#if !defined(__cplusplus)
#if !defined(__GNUC__)
/* _Bool builtin type is included in GCC */
/* ISO C Standard: 5.2.5 An object declared as
type _Bool is large enough to store
the values 0 and 1. */
/* We choose 8 bit to match C++ */
/* It must also promote to integer */
typedef int8_t _Bool;
#endif
/* ISO C Standard: 7.16 Boolean type */
#define bool _Bool
#define true 1
#define false 0
#define __bool_true_false_are_defined 1
#endif
#endif
</code></pre>
<p>This is taken from the <a href="http://sourceforge.net/projects/adacl" rel="nofollow noreferrer">Ada Class Library</a> project.</p>
|
<p>Logically, you are not able to share source code between C and C++ with conflicting declarations for bool and have them link to each other.</p>
<p>The only way you can share code and link is via an intermediary datastructure. Unfortunately, from what I understand, you can't modify the code that defines the interface between your C++ program and C library. If you could, I'd suggest using something like:</p>
<pre><code>union boolean {
bool value_cpp;
int value_c;
};
</code></pre>
<p>// padding may be necessary depending on <a href="http://en.wikipedia.org/wiki/Endianness" rel="nofollow noreferrer">endianness</a> </p>
<p>The effect of which will be to make the datatype the same width in both languages; conversion to the native data type will need to be performed at both ends. Swap the use of bool for boolean in the library function definition, fiddle code in the library to convert, and you're done.</p>
<p>So, what you're going to have to do instead is create a <a href="http://en.wikipedia.org/wiki/Shim_(computing)" rel="nofollow noreferrer">shim</a> between the C++ program and the C library.</p>
<p>You have:</p>
<pre><code>extern "C" bool library_func_1(int i, char c, bool b);
</code></pre>
<p>And you need to create:</p>
<pre><code>bool library_func_1_cpp(int i, char c, bool b)
{
int result = library_func_1(i, c, static_cast<int>(b));
return (result==true);
}
</code></pre>
<p>And now call library_func_1_cpp instead.</p>
| 4,511
|
<p>I am attempting to write a basic slicer for some objects I am working with. I need to write a custom slicer as the objects are not polygonal based (they are implicit objects) and therefore cannot be plugged into slic3r. I can easily obtain the perimeter/shell of the objects I am working with and have a few successful prints. What I am having trouble with is how to add infill. I think the biggest hurdle is simply my inability to frame the question properly. How do current software tackle this problem?</p>
<p>I don't know of my current approach is feasible but if I have a collection of vectors that represent the path around the outside of the object and a collection of vectors that represent an arbitrarily large infill pattern is there a way to union the two paths together to from an outer path (the object shell) and an inner path that is the infill pattern cut out in the shape of the object?</p>
<p>EDIT:</p>
<p>Sorry for the lack of clarification. So lets say I cut out the infill pattern to match the inside of the object. How do I then intelligently connect all the broken infill segments together to form an efficient path that doesn't cross gaps or mess the object up in any way? </p>
|
<p>The answer to this is pretty much basic algebra: The software tackles the problem by using a set of functions that generate the infill pattern for ALL the build volume, then discard anything outside the shells. Which is determined by algebra:</p>
<h1>Basics</h1>
<h3>Outline Function</h3>
<p>Assume the outline of the body is a function <span class="math-container">$O(l)$</span> that has a parameter <span class="math-container">$l$</span> for its length. This function can be calculated into XY coordinates, giving us <span class="math-container">$y\mapsto O^{xy}(x)$</span>, that is parameterized after <span class="math-container">$x$</span>, and should give us the values of <span class="math-container">$y$</span> for a closed function <span class="math-container">$O(l)$</span>.</p>
<h3>Infill Functions</h3>
<p>Now, let's generate a function for infill pattern. Let's make it easy for us and use a diagonals pattern: <span class="math-container">$I_n(x)=x+n\times d$</span>
where <span class="math-container">$d$</span> is a fixed parameter for "distance to last line" and <span class="math-container">$n\in\mathbb Z$</span> is the number of the line with 0 passing the origin.</p>
<h3>Comparation: Outline=Infill</h3>
<p>Now basic algebra! Let the computer solve for each <span class="math-container">$n$</span> the term <span class="math-container">$O(x)=I_n(x)$</span>. The result should be (in the best case) paired points, all on the linear function <span class="math-container">$I_n(x)$</span>. Sort these points by their correlating <span class="math-container">$n$</span> value first, then the <span class="math-container">$x$</span> values.</p>
<h1>Dealing with the results</h1>
<p>Let's assume we have some banana shape and our solutions for n=0 are like this: <span class="math-container">$P_{i=1 \to 4}=\{\{1,1\},\{2,2\},\{3,3\},\{4,4\}\}$</span></p>
<h2>Modeling starter</h2>
<p>On the most simple cases, we hope to only have paired results - the outline is closed and thus each line passing it has to <em>cut</em> it in multiples of two. Because we don't allow geometry to be below <span class="math-container">$\{0,0\}$</span>, the line in this example will pass into the body at the first solution of these points and pass out of it at the second and so on. Generally: It moves in at odd and exits at even i. So our infill lines in the example need to connect <span class="math-container">$\{1,1\} \to \{2,2\}$</span> and <span class="math-container">$\{3,3\} \to \{4,4\}$</span>.</p>
<h1>Enhancing the Modeling</h1>
<h2>checking for tangents</h2>
<p>Now, we might have an odd number of points that solve O(x)=I<sub>n</sub>(x) for a given n. Let's assume <span class="math-container">$P_{i=1 \to 5}=\{1,1\},\{2,2\},\{3,3\},\{4,4\},\{5,5\}$</span>.</p>
<p>Now we need to be careful as one of these points is guaranteed to be a point in which <span class="math-container">$I_n(x)$</span> is a tangent at of <span class="math-container">$O(x)$</span>. So, we need to know the first differential of <span class="math-container">$O(x)$</span> in the points, which is the tangent at <span class="math-container">$O(x)$</span>. But we don't need to solve <em>all</em> the points: We know the first should enter and the last exit the body, so we need (for most cases) to only solve this for the points <span class="math-container">$P_i$</span> with <span class="math-container">$i=2 \to i_{max-1}$</span>. When <span class="math-container">$O'(x)=I_n(x)$</span>, we got a tangent and remove this point from the list of points to connect with infill lines.</p>
<p>Because we could have several tangents in a set of points, this check has to be done for all sets of points to eliminate these points.</p>
<p>Also, I used the "usually" there by intent: there are cases where the first or last point is a tangent, and because it is easier to cose, we should run the elimination process over all <span class="math-container">$P_1 \to P_{max}$</span>!</p>
<p>The new, reduced set of points will be a paired list: <span class="math-container">$Q_{i=1 \to 4}=\{1,1\},\{2,2\},\{4,4\},\{5,5\}$</span>. The Infil connects <span class="math-container">$Q_1 \to Q_2$</span> and <span class="math-container">$Q_3\to Q_4$</span>.</p>
<h2>Turning Points into vectors</h2>
<p>Now, we have our points <span class="math-container">$Q_1$</span> and <span class="math-container">$Q_2$</span> (or any other pair of <span class="math-container">$n \land n+1$</span>, where n is an element of the odd numbers), both on <span class="math-container">$I_{n=0}(x)$</span>. How to connect? Easy! <span class="math-container">$I{n=0}$</span> is a function, most likely a linear one. Along this line has to be our connecting line from <span class="math-container">$Q_1\to Q_2$</span>, so the movement we have to plot is the function of our pattern between the points. For a simple, linear pattern this would be:</p>
<p><span class="math-container">$L_1=\frac{I(x)}{|I(x)|} \times |\vec{Q_2}-\vec{Q_1}|+\vec{Q1}$</span></p>
<h1>Optimisation</h1>
<h2>Sorting properly</h2>
<p>Now, we have a set of Lines <span class="math-container">$L_n$</span>, where, as established in the last paragraph, n is an odd number declaring it has the lower-end <span class="math-container">$Q_n$</span>, and the upper-end <span class="math-container">$Q_{n+1}$</span>. How do we sort these lines smartly so we have the least movement? Let's take a look at our lists:</p>
<ul>
<li>The list of P<sub>i</sub>, which contains all tangential points and end points. Not very helpful.</li>
<li>The reduced list of <span class="math-container">$Q_{n}$</span>, which contains all the start and end points; it is <em>sorted</em> in a way that odd numbers are starts, and even ends.</li>
<li>The list of <span class="math-container">$L_n$</span> with i always being an odd number, that contains the movement paths (=lines) from each <span class="math-container">$Q_{n}$</span> to its corresponding <span class="math-container">$Q_{n+1}$</span></li>
</ul>
<h3>Shortest movement between prints?</h3>
<p>Now, let's do some math again: What is the closest <span class="math-container">$Q_{a}$</span> to the <span class="math-container">$Q_{n+1}$</span> we did end at after doing the <span class="math-container">$L_n$</span> movement? Well, first of all, we need to make sure we don't get back to already moved paths so let's make a new list <span class="math-container">$R_{i}$</span>, which contains all the <span class="math-container">$Q_{i}$</span> we have not yet moved to.</p>
<p>So what is the closest <span class="math-container">$R_{i}$</span> to the end point of the path <span class="math-container">$L_e$</span> we just moved? Well, easy! Solve <span class="math-container">$min|R_i-L_e|$</span> with i being all the odd numbers in the list of <span class="math-container">$R_{i}$</span> and <span class="math-container">$L_e$</span> the point where the printhead was sent to at the end of the last movement</p>
<h3>fewest direction changes?</h3>
<p>Always moving just the shortest distance might create a large number of direction changes. So it might be a good idea to keep the point-lists sorted by the parameter n of the function <span class="math-container">$l_n(x)$</span> that created the points in the first place, and run down that list from minimum n that generated points (which can be below 0) to the maximum n that generated points.</p>
<h3>optimizing direction changes & movement paths</h3>
<p>Now, we have 2 approaches that pretty much only follow the pattern. However, we might make our average movement paths more efficient by using a simple trick:</p>
<p>Up to now, all our line functions <span class="math-container">$l_n(x)$</span> had the same vector and just a different starting point to one another. So all the starts were on one side of the body, all the ends on the opposite. With a very simple trick on the infill function we can generate a group of functions that alternate the sides of the end-points between each line, jsut by adding an inverse element:</p>
<p><span class="math-container">$L_n(x)=-1^n\times l_n(x)$</span></p>
<p>Now, after all the movements with the same <span class="math-container">$n$</span> are done, check for the closest starting point (which should be on the same side, but is not necessary the neighboring line), and go down that line fully, eradicating these points from the list of remaining points <span class="math-container">$R_{i}$</span>. Once back on the side we <em>started</em> first at, we look for the closest unused point again, run down that line, rinse and repeat.</p>
|
<p>simple answer is math but you know that for sure</p>
<p>more descriptive answer (but still simple and with no math) is more or less as follows</p>
<ul>
<li>slice an object with a plane to form (calculate) outline perimeter</li>
<li>create a grid of infill according to your needs (ie: lines, grids or honeycombs)</li>
<li>calculate where outline cuts your grid of infill</li>
<li>abandon all what is outside</li>
<li>sort cut points in some order ("some" is definitely the hardest task)</li>
<li>join points according to your sort</li>
</ul>
<p>and voila ;)</p>
<p>of course there is many details not mentioned in such description as distance between perimeter and infill, layer thickness and many others
this is just very naive and silly description but it's just to direct you where to go further</p>
<p>generally there is great library which you could give a try</p>
<p><a href="https://sourceforge.net/projects/jsclipper/" rel="nofollow noreferrer">https://sourceforge.net/projects/jsclipper/</a></p>
<p><strong>edit</strong></p>
<p>simple sort (counter)clockwise could be like this</p>
<ul>
<li>set center point of the object (perimeter)</li>
<li>start from 1200 hour and calculate module and angle of each cut-point</li>
<li>sort them by angle</li>
</ul>
<p>it's still very simple and it's working only for convex set</p>
| 1,029
|
<p>I always run into the same problem when creating web pages. When I add a font that is larger then about 16-18px it looks terrible. Its jagged, and pixelated. I have tried using different fonts and weights, however I haven't had much luck there. </p>
<p>Note: Its only in windows that it is like this. Mainly in Opera and FF also in IE7 but not quite as bad. In Linux the font looks good. I haven't looked at a Mac.</p>
<p>What do you guys do to fix this? if anything. I noticed that the titles here on SO are also pretty jagged but they are just small enough not to look bad. </p>
|
<p>There is nothing you can do to force the user to change the way that their operating system renders fonts. If it is that big a deal to you then you can replace the large headings with images, this allows you to control exactly how the font is rendered (and ensures that the heading looks exactly as you wish, even if the user doesnt have your suggested font installed). </p>
<p>If you do this make sure that you provide an alternative text representation for those who do not see images. I tend to use CSS to show a background image, and hide the contents of the heading. Like this.</p>
<pre><code><style>
h1
{
height: 32px;
width: 100px;
background: url("path/to/image")
}
h1 span
{
display: none;
}
</style>
<h1>
<span>
Heading Text
<span>
</h1>
</code></pre>
<p>To be honest this does seem like overkill if it is on all large text. And be aware that it will increase the amount of data that your clients need to download. However for a large heading this method can lead to something that looks nicer than OS rendered text.</p>
|
<p>Enabling anti-aliasing should solve the display problem. </p>
| 5,400
|
<p>I'm just designing the schema for a database table which will hold details of email attachments - their size in bytes, filename and content-type (i.e. "image/jpg", "audio/mp3", etc).</p>
<p>Does anybody know the maximum length that I can expect a content-type to be?</p>
|
<p>I hope I havn't misread, but it looks like the length is max 127/127 or <strong>255 total</strong>.</p>
<p><a href="http://www.ietf.org/rfc/rfc4288.txt?number=4288" rel="noreferrer">RFC 4288</a> has a reference in 4.2 (page 6):</p>
<pre><code>Type and subtype names MUST conform to the following ABNF:
type-name = reg-name
subtype-name = reg-name
reg-name = 1*127reg-name-chars
reg-name-chars = ALPHA / DIGIT / "!" /
"#" / "$" / "&" / "." /
"+" / "-" / "^" / "_"
</code></pre>
<p>It is not clear to me if the +suffix can add past the 127, but it appears not.</p>
|
<p>We run an SaaS system that allows users to upload files. We'd originally designed it to store MIME Types up to 50 characters. In the last several days we've seen several attempts to upload 71-bytes types. So, we're changing to 250. 100 seemed "good" but it's only a few more than the max we're seeing now. 500 seems silly, so 250 is the selected one.</p>
| 4,024
|
<p>Let's say you have a variable in a makefile fragment like the following:</p>
<pre><code>MY_LIST=a b c d
</code></pre>
<p>How do I then reverse the order of that list? I need:</p>
<pre><code>$(warning MY_LIST=${MY_LIST})
</code></pre>
<p>to show</p>
<pre><code>MY_LIST=d c b a
</code></pre>
<p>Edit: the real problem is that </p>
<pre><code>ld -r some_object.o ${MY_LIST}
</code></pre>
<p>produces an <code>a.out</code> with undefined symbols because the items in <code>MY_LIST</code> are actually archives, but in the wrong order. If the order of <code>MY_LIST</code> is reversed, it will link correctly (I think). If you know a smarter way to get the link order right, clue me in.</p>
|
<p>A solution in pure GNU make:</p>
<blockquote>
<p>default: all</p>
<p>foo = please reverse me</p>
<p>reverse = $(if $(1),$(call
reverse,$(wordlist 2,$(words
$(1)),$(1)))) $(firstword $(1))</p>
<p>all : @echo $(call reverse,$(foo))</p>
</blockquote>
<p>Gives:</p>
<blockquote>
<p>$ make</p>
<p>me reverse please</p>
</blockquote>
|
<p>Playing off of both <a href="https://stackoverflow.com/a/52722/309233">Ben Collins'</a> and <a href="https://stackoverflow.com/a/52697/309233">elmarco's</a> answers, here's a punt to bash which handles whitespace "properly"<sup>1</sup></p>
<pre><code>reverse = $(shell printf "%s\n" $(strip $1) | tac)
</code></pre>
<p>which does the right thing, thanks to <code>$(shell)</code> automatically cleaning whitespace and <code>printf</code> automatically formatting each word in its arg list:</p>
<pre><code>$(info [ $(call reverse, one two three four ) ] )
</code></pre>
<p>yields:</p>
<pre><code>[ four three two one ]
</code></pre>
<p><sup>1</sup>...according to my limited test case (i.e., the <code>$(info ...)</code> line, above).</p>
| 7,592
|
<p>If I had 20 directories under trunk/ with lots of files in each and only needed 3 of those directories, would it be possible to do a Subversion checkout with only those 3 directories under trunk?</p>
|
<p>Indeed, thanks to the comments to my post here, it looks like <a href="http://svnbook.red-bean.com/en/1.8/svn.advanced.sparsedirs.html" rel="noreferrer">sparse directories</a> are the way to go. I believe the following should do it:</p>
<pre><code>svn checkout --depth empty http://svnserver/trunk/proj
svn update --set-depth infinity proj/foo
svn update --set-depth infinity proj/bar
svn update --set-depth infinity proj/baz
</code></pre>
<p>Alternatively, <code>--depth immediates</code> instead of <code>empty</code> checks out files and directories in <code>trunk/proj</code> without their contents. That way you can see which directories exist in the repository.</p>
<hr>
<p>As mentioned in @zigdon's answer, you can also do a non-recursive checkout. This is an older and less flexible way to achieve a similar effect:</p>
<pre><code>svn checkout --non-recursive http://svnserver/trunk/proj
svn update trunk/foo
svn update trunk/bar
svn update trunk/baz
</code></pre>
|
<p>Not in any especially useful way, no. You can check out subtrees (as in Bobby Jack's suggestion), but then you lose the ability to update/commit them atomically; to do that, they need to be placed under their common parent, and as soon as you check out the common parent, you'll download everything under that parent. Non-recursive isn't a good option, because you want updates and commits to be recursive.</p>
| 7,375
|
<p>Is it possible to have XML-embedded JavaScript executed to assist in client-side (browser-based) XSL transformations? How is it done and how official is it?</p>
<p>Microsoft's XML DOM objects allow this on the server-side (i.e. in ASP/ASP.NET).</p>
<p><strong>Clarification:</strong> I do not mean HTML DOM scripting performed <em>after</em> the document is transformed, nor do I mean XSL transformations <em>initiated</em> by JavaScript in the browser (e.g. what the W3Schools page shows). I am referring to actual script blocks located within the XSL during the transformation.</p>
|
<p>To embed JavaScript for the aid of transformation you can use <xsl:script>, but <a href="http://www.topxml.com/xsl/tutorials/intro/xsl10.asp" rel="nofollow noreferrer">it is limited</a> to Microsoft's XML objects implementation. Here's an <a href="https://oxampleski.googlecode.com/svn/trunk/XSL" rel="nofollow noreferrer">example</a>:</p>
<p><strong>scripted.xml</strong>:</p>
<pre><code><?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="scripted.xsl"?>
<data a="v">
ding dong
</data>
</code></pre>
<p><strong>scripted.xsl</strong>:</p>
<pre><code><?xml version="1.0" encoding="ISO-8859-1"?>
<html xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:script implements-prefix="local" language="JScript"><![CDATA[
function Title()
{
return "Scripted";
}
function Body(text)
{
return "/" + text + "/";
}
]]></xsl:script>
<head>
<title><xsl:eval>Title()</xsl:eval></title>
</head>
<body>
<xsl:for-each select="/data"><xsl:eval>Body(nodeTypedValue)</xsl:eval></xsl:for-each>
</body>
</html>
</code></pre>
<p>The result in Internet Explorer (or if you just use MSXML from COM/.NET) is:</p>
<pre><code><html>
<head>
<title>Scripted</titlte>
</head>
<body>
/ding dong/
</body>
</html>
</code></pre>
<p>It doesn't appear to support the usual XSL template constructs and adding the root node causes MSXML to go into some sort of standards mode where it won't work.</p>
<p>I'm not sure if there's any equivalent functionality in standard XSL, but I can dream.</p>
|
<p>Yes. It's browser dependant but you can use Javascript. There is a small but practical tutorial on w3schools.com. It's part of the XSLT tutorial.</p>
<p>The page:</p>
<p><a href="http://www.w3schools.com/xsl/xsl_client.asp" rel="nofollow noreferrer">http://www.w3schools.com/xsl/xsl_client.asp</a></p>
<p>The XSLT tutorial:</p>
<p><a href="http://www.w3schools.com/xsl/default.asp" rel="nofollow noreferrer">http://www.w3schools.com/xsl/default.asp</a></p>
<p>That site will be more helpful than myself. Good luck!</p>
| 9,166
|
<p>I am extending the bed of my TronXY X3 FDM RepRap printer.</p>
<p>I am extending the bed from 220 mm x 220 mm to 220 mm x 300 mm. For now, I will keep the existing bed and add and aluminum sheet on top. That leaves 40mm on front and back of the original bed.</p>
<p>Right now I only plan on running PLA; but, I do plan on heating the bed.</p>
<p>How thick does the aluminum sheet need to be?</p>
|
<p>Main factors that control the process of the print bed selection are</p>
<ul>
<li>weight: too thick plate increases inertial force, limiting maximum acceleration/jerk (decreased print speed)</li>
<li>stiffness: too thin plate will warp when heated or bend during calibration (decreased print quality/printer reliability)</li>
</ul>
<p>For table sizes around 400x400mm I would think of 4mm plate, but it still can warp if heated unevenly.</p>
<p>Sometimes it makes sense to use a sandwich-type table: lower level is MDF, cork panel for heat insulation and thin (1.5-2mm) aluminum heated bed on top.</p>
|
<p>I highly recommend aluminium tooling plates. They have a +/- 0.1 mm flatness tolerance on 1 meter. It's alloy 5083 offers a great stability. You can purchase such for example at aluminyumburada, which offers <a href="https://www.aluminyumburada.com/aluminum-cut-to-size" rel="nofollow noreferrer">custom cut piecees.</a>. They have a minimum thickness of 5 mm, though the prices get lower the thicker the piece is.</p>
| 662
|
<p>So I started using Cura a few weeks ago, and when I print it goes to 204 Celsius instead of 200. It doesn't really affect my print quality but I just want to know if there's a fix for it. My printer is a Da Vinci Jr 1.0.</p>
|
<p>Its mainly due to the regulation loop of the PID Regulator implemented in the Firmware of the Da vinci jr. The P-Factor is a little bit too high. This is the reason why the temperature "overshoots". Because the Printerhead and Nozzle has some volume which is heated up. It takes time to cool down after it has detected an overshoot. </p>
<p>here you can find additional informations about it: <a href="https://innovativecontrols.com/blog/basics-tuning-pid-loops" rel="nofollow noreferrer">https://innovativecontrols.com/blog/basics-tuning-pid-loops</a></p>
|
<p>That's called PID overshoot. All control loops have varying types of outliers like this. Sometimes, you can't overshoot, sometimes you cant undershoot. But it's a remnant of the math. </p>
<p>The solution here, is to <a href="http://reprap.org/wiki/PID_Tuning" rel="nofollow noreferrer">PID Tune</a>. Once you get an established Kp Ki and Kd constants, then you can either save it to eeprom or you can recompile your firmware with this change.</p>
<p>It's pretty common, especially if you have different hotends without known profiles. PID tuning also works on heated beds as well. But usually those use what's called <a href="http://reprap.org/wiki/ExtruderIO#Bang-bang_control" rel="nofollow noreferrer">Bang-bang</a>.</p>
| 709
|
<p>Even though Silverlight2 is still in it's infancy, can anyone recommend a book to get started with? One that has more of a developer focus than a designer one? </p>
|
<p>I have this one pre-ordered: "Programming Silverlight 2"
by Jesse Liberty and Tim Heuer. The authors are both employed by Microsoft working on Silverlight 2, and their blogs are great, so I expect the book (to be released after RTM) to be up to date.</p>
|
<p>I'm currently working my way through <a href="https://rads.stackoverflow.com/amzn/click/com/073562528X" rel="nofollow noreferrer" rel="nofollow noreferrer">Introducing Microsoft Silverlight 2</a>, so far so good. </p>
<p>It's a typical Microsoft book serving up the <strong>koolaid</strong>, but gives a good introduction. I saw the guy speak at one of the local .NET User Groups in the Metro Detroit area and was impressed.</p>
<p><a href="http://ecx.images-amazon.com/images/I/51YD6H7PQyL._SL500_BO2,204,203,200_PIsitb-dp-500-arrow,TopRight,45,-64_OU01_AA240_SH20_.jpg" rel="nofollow noreferrer">alt text http://ecx.images-amazon.com/images/I/51YD6H7PQyL._SL500_BO2,204,203,200_PIsitb-dp-500-arrow,TopRight,45,-64_OU01_AA240_SH20_.jpg</a></p>
| 8,585
|
<p>I am about to start a new project and would like to document its development in a very simple blog.</p>
<p>My requirements are:</p>
<ul>
<li>self-hosted on my Gentoo-based LAMP stack (that seems to rule out blogger)</li>
<li>Integration in a django based website (as in www.myproject.com/about, www.myproject.com/blog etc rather than www.myproject.com and a totally different site at blog.myproject.com)</li>
<li>very little or no learning curve <i>that's specific to the blog engine</i> (don't want to learn an API just to blog, but having to get deeper into Django to be able to roll my own would be OK) According to the answers so far, there is a chance that this excludes Wordpress</li>
</ul>
<p>Should I</p>
<p>a) install blog engine X (please specify X)</p>
<p>b) use django to hand-roll a way to post new entries and a page on my website to display the posts in descending chronological order</p>
|
<p><strong>If you're the perfectionist kind, roll your own</strong>.</p>
<ul>
<li>It isn't that hard</li>
<li>You learn something useful</li>
<li>You'll get <em>exactly</em> what you want and need</li>
</ul>
<p>Be warned that you may run into a quagmire fighting comment spam, fixing security holes, etc. But it'll probably be a fun project.</p>
<p><strong>If you are the practical type and ready to face some integration pain</strong>, use an existing engine like <a href="http://vss.73rus.com/wadcomblog/" rel="noreferrer">WadcomBlog</a> (Python) or <a href="http://pyblosxom.sourceforge.net/" rel="noreferrer">PyBlosxom</a>, or something completely different like MovableType or WordPress.</p>
<p>Here's a simple <a href="http://www.rossp.org/blog/2006/jun/08/django-blog-redux/" rel="noreferrer">Django blog example</a> to get you started.</p>
<p>Some pros and cons of rolling your blog engine <a href="http://haacked.com/archive/2006/10/06/Rolling_Your_Own_Blog_Engine.aspx" rel="noreferrer">this article</a> by Phil Haack.</p>
<p>Jeff Croft apparently <a href="http://jeffcroft.com/blog/2006/may/02/django-non-programmers/" rel="noreferrer">rolled his own</a> as well.</p>
|
<p>I Haven't tried it myself yet (other than the demo), but I've bookmarked <a href="http://chyrp.net" rel="nofollow noreferrer">Chyrp</a> so that if I ever need to set up a quick & simple blog (kind of like you're describing) I could try this. So check it out, might be a good option for you.</p>
| 7,435
|
<p>At work we have an application to play 2K (2048*1556px) OpenEXR film sequences. It works well.. apart from when sequences that are over 3GB (quite common), then it has to unload old frames from memory, despite the fact all machines have 8-16GB of memory (which is addressable via the linux BIGMEM stuff).</p>
<p>The frames have to he cached into memory to play back in realtime. The OS is a several-year old 32-bit Fedora Distro (not possible to upgradable to 64bit, for the foreseeable future). The per-process limitation is 3GB per process.</p>
<p>Basically, is it possible to cache more than 3GB of data in memory, somehow? My initial idea was to spread the data between multiple processes, but I've no idea if this is possible..</p>
|
<p>How about creating a RAM drive and loading the file into that ... assuming the RAM drive supports the BIGMEM stuff for you.</p>
<p>You could use multiple processes: each process loads a view of the file as a shared memory segment, and the player process then maps the segments in turn as needed.</p>
|
<p>@dbr said:</p>
<blockquote>
<p>There is a review machine with an absurd fiber-channel-RAID-array that can play 2K files direct from the array easily. The issue is with the artist-workstations, so it wouldn't be one $4000 RAID array, it'd be hundreds..</p>
</blockquote>
<p>Well, if you can accept a limit of ~30GB, then maybe a single 36GB SSD drive would be enough? Those go for ~US$1k each I think, and the data rates might be enough. That very well maybe cheaper than a pure RAM approach. There are smaller sizes available, too. If ~60GB is enough you could probably get away with a JBOD array of 2 for double the cost, and skip the RAID controller. Be sure only to look at the higher end SSD options--the low end is filled with glorified memory sticks. :P</p>
| 6,298
|
<p>After attending a recent Alt.NET group on IoC, I got to thinking about the tools available and how they might work. <code>StructureMap</code> in particular uses both attributes and bootstrapper concepts to map requests for <code>IThing</code> to <code>ConcreteThing</code>. Attributes automatically throw up flags for me that either reflection or IL injection is going on. Does anyone know exactly how this works (for <code>StructureMap</code> or other IoC tools) and what the associated overhead might be either at run-time or compile-time?</p>
|
<p>I can't say much for other IoC toolkits but I use Spring.Net and have found that there is a one off initial performance penalty at startup. Once the container has been configured the application runs unaffected.</p>
|
<p>They major problem is that code becomes hard to understand. It might become <em>pure magical</em> if one overuse IoC. Another problem is performance. In most cases performance lost is not noticeable. But when you start creating most of your objects via IoC container, it can suddenly drop below ocean level.</p>
| 8,243
|
<p>I have a column of data that contains a percentage range as a string that I'd like to convert to a number so I can do easy comparisons.</p>
<p>Possible values in the string:</p>
<pre><code>'<5%'
'5-10%'
'10-15%'
...
'95-100%'
</code></pre>
<p>I'd like to convert this in my select where clause to just the first number, 5, 10, 15, etc. so that I can compare that value to a passed in "at least this" value.</p>
<p>I've tried a bunch of variations on substring, charindex, convert, and replace, but I still can't seem to get something that works in all combinations.</p>
<p>Any ideas?</p>
|
<p>Try this,</p>
<pre><code>SELECT substring(replace(interest , '<',''), patindex('%[0-9]%',replace(interest , '<','')), patindex('%[^0-9]%',replace(interest, '<',''))-1) FROM table1
</code></pre>
<p>Tested at my end and it works, it's only my first try so you might be able to optimise it.</p>
|
<p>You can convert char data to other types of char (convert char(10) to varchar(10)), but you won't be able to convert character data to integer data from within SQL.</p>
| 3,898
|
<p>Say I have a site on <a href="http://example.com" rel="noreferrer">http://example.com</a>. I would really like allowing bots to see the home page, but any other page need to blocked as it is pointless to spider. In other words</p>
<p><a href="http://example.com" rel="noreferrer">http://example.com</a> & <a href="http://example.com/" rel="noreferrer">http://example.com/</a> should be allowed, but
<a href="http://example.com/anything" rel="noreferrer">http://example.com/anything</a> and <a href="http://example.com/someendpoint.aspx" rel="noreferrer">http://example.com/someendpoint.aspx</a> should be blocked.</p>
<p>Further it would be great if I can allow certain query strings to passthrough to the home page:
<a href="http://example.com?okparam=true" rel="noreferrer">http://example.com?okparam=true</a> </p>
<p>but not
<a href="http://example.com?anythingbutokparam=true" rel="noreferrer">http://example.com?anythingbutokparam=true</a></p>
|
<p>So after some research, here is what I found - a solution acceptable by the major search providers: <a href="http://www.google.com/support/webmasters/bin/answer.py?answer=40367" rel="noreferrer">google</a> , <a href="http://help.yahoo.com/l/us/yahoo/search/webcrawler/slurp-02.html" rel="noreferrer">yahoo</a> & msn (I could on find a validator here) :</p>
<pre><code>User-Agent: *
Disallow: /*
Allow: /?okparam=
Allow: /$
</code></pre>
<p>The trick is using the $ to mark the end of URL.</p>
|
<p>Basic robots.txt:</p>
<pre><code>Disallow: /subdir/
</code></pre>
<p>I don't think that you can create an expression saying 'everything but the root', you have to fill in all sub directories.</p>
<p>The query string limitation is also not possible from robots.txt. You have to do it in the background code (the processing part), or maybe with server rewrite-rules.</p>
| 6,503
|
<p>I have a History Table in SQL Server that basically tracks an item through a process. The item has some fixed fields that don't change throughout the process, but has a few other fields including status and Id which increment as the steps of the process increase.</p>
<p>Basically I want to retrieve the last step for each item given a Batch Reference. So if I do a </p>
<pre><code>Select * from HistoryTable where BatchRef = @BatchRef
</code></pre>
<p>It will return all the steps for all the items in the batch - eg</p>
<pre>
<b>Id Status BatchRef ItemCount</b>
1 1 Batch001 100
1 2 Batch001 110
2 1 Batch001 60
2 2 Batch001 100
</pre>
<p>But what I really want is:</p>
<pre>
<b>Id Status BatchRef ItemCount</b>
1 2 Batch001 110
2 2 Batch001 100
</pre>
<p>Edit: Appologies - can't seem to get the TABLE tags to work with Markdown - followed the help to the letter, and looks fine in the preview</p>
|
<p>It's kind of hard to make sense of your table design - I think SO ate your delimiters.</p>
<p>The basic way of handling this is to GROUP BY your fixed fields, and select a MAX (or MIN) for some unqiue value (a datetime usually works well). In your case, I <em>think</em> that the GROUP BY would be BatchRef and ItemCount, and Id will be your unique column.</p>
<p>Then, join back to the table to get all columns. Something like:</p>
<pre><code>SELECT *
FROM HistoryTable
JOIN (
SELECT
MAX(Id) as Id.
BatchRef,
ItemCount
FROM HsitoryTable
WHERE
BacthRef = @batchRef
GROUP BY
BatchRef,
ItemCount
) as Latest ON
HistoryTable.Id = Latest.Id
</code></pre>
|
<p>It's a bit hard to decypher your data the way WMD has formatted it, but you can pull of the sort of trick you need with common table expressions on SQL 2005:</p>
<pre><code>with LastBatches as (
select Batch, max(Id)
from HistoryTable
group by Batch
)
select *
from HistoryTable h
join LastBatches b on b.Batch = h.Batch and b.Id = h.Id
</code></pre>
<p>Or a subquery (assuming the group by in the subquery works - off the top of my head I don't recall):</p>
<pre><code>select *
from HistoryTable h
join (
select Batch, max(Id)
from HistoryTable
group by Batch
) b on b.Batch = h.Batch and b.Id = h.Id
</code></pre>
<p>Edit: I was assuming you wanted the last item for <em>every</em> batch. If you just need it for the one batch then the other answers (doing a top 1 and ordering descending) are the way to go.</p>
| 4,967
|
<p>I flatter myself that I'm a good programmer, and can get away with graphic design. But something I'm incapable of doing is coming up with good names - and it seems neither are the people I work with. We're now in the slightly ludicrous situation that the product we've been working on for a couple of years is being installed to customers, is well received and is making money - but doesn't yet have a name.</p>
<p>We're too small a company to have anything like a proper marketing division to do this thing. So how have people tended to choose names, logos and branding?</p>
|
<p>When it's for something that "matters", I plop down the $50 and have the folks at PickyDomains.com help out. That also results in a name that's available as a .com.</p>
<p>For guidelines, here's an extract from my own guide on naming open source projects:</p>
<ol>
<li>If the name you're thinking of is directly pulled from a scifi or fantasy source, don't bother. These sources are WAY overrepresented as naming sources in software. Not only are your chances of coming up with something original pretty small, most of the names of characters and places in scifi are trademarked and you run the risk of being sued.</li>
<li>If the name you're thinking of comes straight from Greek, Roman or Norse mythology, try again. We've got more than enough mail related software called variations of "Mercury".</li>
<li>Run your proposed name through Google. The fewer results you get the better. If you get down to no results, you're there.</li>
<li>Don't try to get a unique name by just slightly misspelling something. Calling your new Windows filesystem program Phat32 is just going to end up with users getting frustrated looking at the results of "fat32" in a search engine.</li>
<li>If your name couldn't be said on TV in the 50s or 60s, you're probably on the wrong track. This is particularly true if you would like anyone to use your product in a work environment. No one is going to recommend a product to their co-workers if they can get sued for sexual harassment just for uttering its name.</li>
<li>If your product name can't be pronounced at all, you'll get no word of mouth benefit at all. Similarly, if no one knows how to pronounce it, they will not be very likely to try to say it out loud to ask questions about it, etc. How do YOU say MySQL? PostgreSQL? GNU? Almost all spoken languages on Earth are based on consonant/vowel syllables of some sort. Alternating between consonants and vowels is a pretty good way to ensure that someone can pronounce it.</li>
<li>The shorter the better.</li>
<li>See if the .com domain is available. If it's not, it's a pretty good indicator that someone has already thought of it and is using it or closer to using it than you are. Do this even if you don't intend to use the domain.</li>
<li>Don't build inherent limitations on your product into the name. Calling your product LinProduct or WinProduct precludes you from ever releasing any sort of cross-platform edition.</li>
<li>Don't use your own name for open source products. If the project lives on beyond your involvement, the project will either have to be renamed or your name may be used in ways you didn't intend.</li>
</ol>
|
<p>Names -- you can try yourselves or ask friends/customers about what they are thinking about when listen/use your product (I don't know correct English word for that -- if two things have something in common they are associated?).</p>
<p>Or, depends on what kind of product is it, ask someone with unlimited imagination -- kids are very good at it.</p>
<p>Logos and branding -- you need professionals.</p>
<p>And of course you need layer :).</p>
| 4,234
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.