instruction
stringlengths 27
22.5k
| chosen
stringlengths 27
28.2k
| rejected
stringlengths 19
24.9k
| __index_level_0__
int64 0
10k
|
|---|---|---|---|
<p>For many years I have used two great tools <a href="http://www.compuware.com/products/devpartner/visualc.htm" rel="noreferrer">BoundsChecker</a> & <a href="http://www-01.ibm.com/software/awdtools/purify/win/" rel="noreferrer">Purify</a>, but the developers of these applications have let me down, they no longer put effort into maintaining them or developing them. We have corporate accounts with both companies, and they both tell me that they have no intention of producing versions to support 64 bit applications.</p>
<p>Can anyone recommend either open source or commercial alternatives that support 64 bit native C++/MFC applications?</p>
|
<p>Viva64 (<a href="http://www.viva64.com/viva64-tool/" rel="noreferrer">http://www.viva64.com/viva64-tool/</a>) tool provides detection of errors typical of 64-bit Windows applications. Viva64 is a lint-like static analyzer of C/C++ code. Viva64 integrates into Visual Studio 2005/2008 environment and provides user-friendly interface to test your software projects.</p>
|
<p>I've used bounds checking and other dynamic analysis tools, and while the architectures are different it's the code that you're checking - in theory you could run bounds checking on any backend and the result would be the same - the code either steps outside its bounds or it does not.</p>
<p>The only complications are addressing more than 4GB of memory space, dealing with pieces of code you can't cross-compile to a 32-bit architecture (64 bit object files for which you have no source, etc), and general 64 bit migration issues (platform specific code such as checking for 0xFFFFFFFF instead of -1)</p>
<p>What other problems are you running into doing bounds checking on your program? Are you unable to compile a 32 bit version?</p>
<p>It's not your ideal solution, certainly, and one should always check the code they're going to run, but in this case you might not have a choice, unless you want to do your own bounds checking (which is a good idea in any case...).</p>
<p>-Adam</p>
| 7,225
|
<p>I absolutely need to use an IoC container for decoupling dependencies in an ever increasingly complex system of enterprise services. The issue I am facing is one related to configuration (a.k.a. registration). We currently have 4 different environments -- development to production and in between. These environments have numerous configurations that slightly vary from environment to environment; however, in all cases that <em>I can currently think of</em>, dependencies between components do not differ from environment to environment, though I could have missed something and/or this could obviously change. </p>
<p>So, the ultimate question is, does anybody have a similar experience using an IoC framework? Or, can anybody recommend one framework over another that would provide flexible registration be it through some sort of convention or simplified configuration information? Would I still be able to benefit from a fluent interface or am I stuck with XML -- I'd like to avoid XML-hell.</p>
<p><strong>Edit:</strong> This is a .Net environment and I have been looking at Windsor, Ninject and Autofac. They all seem to now support both methods of registration (fluent and XML), though Autofac's support for lambda expressions seems to be a little different than the others. Anybody use that in a similar multi-deployment environment?</p>
|
<p>I use <a href="http://www.ninject.org/" rel="nofollow noreferrer">Ninject</a>. I like the fact that I don't have to use Xml to configure the dependencies. I can just use straight up C# code. There are <a href="http://kohari.org/2008/06/08/attributes-we-dont-need-no-stinkin-attributes/" rel="nofollow noreferrer">multiple ways</a> of doing it also. I know other libraries have that feature, but Ninject offers fast instantiation, it is pretty lightweight, it has conditional binding, supports compact framework, and it supports Silverlight, 2.0. I also use a wrapper on top of it, in case I do switch it out for another framework in the future. You should definitely try Ninject when deciding on a framework.</p>
|
<p>I'm not sure whether it will suit your particular case, you didn't mention what platform you're working in, but I've had great success with <a href="http://www.castleproject.org/container/index.html" rel="nofollow noreferrer">Castle Windsor's IOC framework</a>. The dependencies are setup in the config file (it's a .NET framework)</p>
| 6,701
|
<p>I want to convert a number that is in <a href="https://en.wikipedia.org/wiki/Netscape_Portable_Runtime#Time" rel="nofollow noreferrer">PRTime</a> format (a 64-bit integer representing the number of microseconds since midnight (00:00:00) 1 January 1970 Coordinated Universal Time (UTC)) to a <code>DateTime</code>.</p>
<p>Note that this is slightly different than the usual "number of milliseconds since 1/1/1970".</p>
|
<pre><code>Dim prTimeInMillis As UInt64
prTimeInMillis = prTime/1000
Dim prDateTime As New DateTime(1970, 1, 1)
prDateTime = prDateTime.AddMilliseconds(prTimeInMillis)
</code></pre>
|
<p>DateTime has a constructor that takes Ticks (which are 100 nanoseconds).</p>
<p>So take your prTime, multiply it by 10 and add it to the number of ticks representing the Epoch time and you have your conversion.</p>
<pre><code>private static DateTime epoch = new DateTime(1970, 1, 1);
private static DateTime ConvertPrTime(long time)
{
return new DateTime(epoch.Ticks + (time*10), DateTimeKind.Utc);
}
</code></pre>
| 8,060
|
<p>Hello is there a way to prevent bend on print with M3D printer? </p>
<p><a href="https://i.stack.imgur.com/j2IRe.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/j2IRe.jpg" alt="enter image description here"></a></p>
|
<p>You can to print a brim, a thin layer on the bottom connected to the model. This will help hold it in place. Since it is thin (one or two layers) it will not warp itself.</p>
<p>The brim is not the same thing as a raft. A raft is under the model. The brim is on the same layer as the models bottom layer but outside the model. It looks something like this:</p>
<p><a href="https://i.stack.imgur.com/0PvWl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0PvWl.png" alt="brim"></a></p>
<p>I assume that you use a heated bed if you have one?</p>
<p>Also, it is imperative that you get a good first layer. Calibrate your machine carefully.</p>
|
<p>Try using an adhesive before you print. This could be <a href="http://airwolf3d.com/shop/wolfbite-prevents-3d-printed-parts-from-warping" rel="nofollow noreferrer">http://airwolf3d.com/shop/wolfbite-prevents-3d-printed-parts-from-warping</a> ... What is the temperature of the room you are printing in like?</p>
| 469
|
<p>Sometimes I need to quickly extract some arbitrary data from XML files to put into a CSV format. What's your best practices for doing this in the Unix terminal? I would love some code examples, so for instance how can I get the following problem solved?</p>
<p>Example XML input:</p>
<pre class="lang-html prettyprint-override"><code><root>
<myel name="Foo" />
<myel name="Bar" />
</root>
</code></pre>
<p>My desired CSV output:</p>
<pre><code>Foo,
Bar,
</code></pre>
|
<p>If you just want the name attributes of any element, here is a quick but incomplete solution.</p>
<p>(Your example text is in the file <em>example</em>)</p>
<blockquote>
<p>grep "name" example | cut -d"\"" -f2,2
| xargs -I{} echo "{},"</p>
</blockquote>
|
<p><a href="https://mikefarah.gitbook.io/yq/" rel="nofollow noreferrer">yq</a> can be used for XML parsing.</p>
<p>It is a lightweight and portable command-line YAML processor and can also deal with XML.
The syntax is similar to <a href="https://stedolan.github.io/jq/" rel="nofollow noreferrer">jq</a></p>
<p><strong>Input</strong></p>
<pre><code><root>
<myel name="Foo" />
<myel name="Bar">
<mysubel>stairway to heaven</mysubel>
</myel>
</root>
</code></pre>
<p><strong>usage example 1</strong></p>
<p><code>yq e '.root.myel.0.+name' $INPUT</code> (version >= 4.30: <code>yq e '.root.myel.0.+@name' $INPUT</code>)</p>
<pre><code>Foo
</code></pre>
<p><strong>usage example 2</strong></p>
<p><code>yq</code> has a nice builtin feature to make XML easily grep-able</p>
<p><code>yq --input-format xml --output-format props $INPUT</code></p>
<pre><code>root.myel.0.+name = Foo
root.myel.1.+name = Bar
root.myel.1.mysubel = stairway to heaven
</code></pre>
<p><strong>usage example 3</strong></p>
<p><code>yq</code> can also convert an XML input into JSON or YAML</p>
<p><code>yq --input-format xml --output-format json $INPUT</code></p>
<pre class="lang-json prettyprint-override"><code>{
"root": {
"myel": [
{
"+name": "Foo"
},
{
"+name": "Bar",
"mysubel": "stairway to heaven"
}
]
}
}
</code></pre>
<p><code>yq --input-format xml $FILE</code> (<code>YAML</code> is the default format)</p>
<pre class="lang-yaml prettyprint-override"><code>root:
myel:
- +name: Foo
- +name: Bar
mysubel: stairway to heaven
</code></pre>
| 4,867
|
<p>I understand how I can change the <code>dns</code> settings for my domains by editing my bind configs, when I run my own name-servers. I know that I can define the name-servers with my registrar via their online control panels. But I have no idea how that part works...</p>
<p>How does my registrar store the data about the name-servers? Is it something clever, like them having the authority to store NS records in the root name-servers?</p>
<p>I'm confused by this part, can anyone explain?</p>
|
<p>The registrar is responsible for setting the Root DNS entry that says, "When someone asks for stackoverflow.com, tell them that the authoritative DNS is xxx.xxx.xxx.xxx". They have an interface that allows them to make changes to the records they own.</p>
<p>Then the requester must go to the authoritative DNS (Which is the one you specified to your registrar was your DNS) to find the IP for stackoverflow.com, any subdomain of it, email server, and other DNS records pertaining to that domain.</p>
<p>-Adam</p>
|
<p>Sorry I can't help toooooo much, but go to <a href="http://twit.tv" rel="nofollow noreferrer">http://twit.tv</a>, and find the Security Now podcast - they did one a couple of weeks ago on DNS - get the first one. It has a good explanation of how it works etc (which may help).</p>
<p>The second one on that site is about how it's been "hacked" - the first one is the how it works.</p>
<p>To kinda answer it:</p>
<p>The "root servers" (for .com for eg) hold a record for stackoverflow.com. But they can't hold all the details, so they have an NS record (name server record) saying "if you want more info, go look over there". So your machine asks that target machine (ns1.stackoverflow.com) for www.stackoverflow.com, and gets back the A record (IP address), or MX (mail etc)</p>
<p>So, your domain register will store it in a database or whatever they chose, and when you do an update, they SOMEHOW (I dont know, but I guess it's published by NIC, but they DO have to pay to be a registrar, and be checked out etc) push that change to the (cluster of) root name servers. They would then push the changes for your domain (eg where www goes, where your mail goes etc) to their local server, which actually serves the domain info.</p>
<p>Hope that makes SOME sense :)</p>
<blockquote>
<p>Does this tell me that the
stackoverflow.com nameservers have
been stored in the .com name servers?</p>
</blockquote>
<p>Yes and no.</p>
<p>Its like you going calling directory assistance for everything ending in .com. You ask for stackoverflow - they tell you "if you want SO, call this number, and they can tell you how to get Jeff (www), Joel (mail), etc.".</p>
<p>The root server is the first directory assistance. Your register's name server is the one on the end of the second call (assuming you called it :) ) </p>
| 6,839
|
<p>I have a list of integers, <code>List<Integer></code> and I'd like to convert all the integer objects into Strings, thus finishing up with a new <code>List<String></code>.</p>
<p>Naturally, I could create a new <code>List<String></code> and loop through the list calling <code>String.valueOf()</code> for each integer, but I was wondering if there was a better (read: <em>more automatic</em>) way of doing it?</p>
|
<p>As far as I know, iterate and instantiate is the only way to do this. Something like (for others potential help, since I'm sure you know how to do this):</p>
<pre><code>List<Integer> oldList = ...
/* Specify the size of the list up front to prevent resizing. */
List<String> newList = new ArrayList<>(oldList.size());
for (Integer myInt : oldList) {
newList.add(String.valueOf(myInt));
}
</code></pre>
|
<p>I just wanted to chime in with an object oriented solution to the problem.</p>
<p>If you model domain objects, then the solution is in the domain objects. The domain here is a List of integers for which we want string values.</p>
<p>The easiest way would be to not convert the list at all.</p>
<p>That being said, in order to convert without converting, change the original list of Integer to List of Value, where Value looks something like this...</p>
<pre><code>class Value {
Integer value;
public Integer getInt()
{
return value;
}
public String getString()
{
return String.valueOf(value);
}
}
</code></pre>
<p>This will be faster and take up less memory than copying the List.</p>
| 3,908
|
<p>I'm new in the 3D priting and I bought a BIQU B1 printer :-)</p>
<p>I printed the Pokemon with the white filament that come as a sample with the printer (PLA) and after that I bought the Inland PLA+ and PETG+ from Microcenter.
The first thing that my son asked me to print is the toaster.
Well, I tried to print three times with the PETG+ filament and always I end up after one or two layers with oozie everywhere and I had to stop printing.
I replaced the filament with the PLA+ and now it's printing correctly (It's 91% complete right now :-) )</p>
<p>So, I set the correct temperator for both filaments:</p>
<ul>
<li>PLA+ 205/60</li>
<li>PETG+ 230/70</li>
</ul>
<p>I'm thinking that for this type of object (torture toaster) it doesn't work with PETG because of the complexity.</p>
<p>Is that correct? If not, what I could be doing wrong with PETG+ filament?</p>
|
<blockquote>
<p>What is this called</p>
</blockquote>
<p>This is called <strong>warping</strong>.</p>
<p>Warping of prints occurs frequently when you use a filament that shrinks. If the model would shrink uniformly, it will become smaller, like in a scaled version (unfortunately, the print is attached somewhere, which causes stresses in the first layers). But, if (due to the geometry of the print) some part of the model shrinks more, the model warps. It could then bend upwards from the build plate, deform at higher layers or sometimes even crack (e.g. in between layers).</p>
<blockquote>
<p>and how do I avoid it?</p>
</blockquote>
<ul>
<li>A high(er) build plate temperature</li>
<li>Not use a filament that is prone to shrink, e.g. ABS is frequently replaced by PETG/NGEN/some other Co-polymer nowadays</li>
<li>Decent adhesion by using everything you can image to get the filament to stick to the build platform:
<ul>
<li>A rough build plate surface, like e.g. BuildTak or equivalent</li>
<li>An adhesive like glue stick or specific sprays like Dimafix or equivalent</li>
<li>A slurry of ABS and acetone</li>
</ul>
</li>
<li>Use an enclosure to raise the temperature of the build volume</li>
<li>If an enclosure is impossible, use a draft shied (basically a multi layer skirt which creates a sort of a mini enclosure)</li>
<li>Use a raft</li>
<li>Don't use part fan cooling</li>
</ul>
|
<p>You are getting warping. It's unusual in this case, as your overall model is relatively low profile. It's the taller stuff that likes to warp.</p>
<p>Consider to edit your post to include the layer heights and also the filament type and filament and bed temperatures. My first instinct is that your bed temperature is too low. There's little harm to be had by raising the temperature by ten degrees or so. Also if your slicer arbitrarily reduces the bed temperature after the first layers, disable that feature. There's no sense to set a good adhesion temperature on a print and later reduce it, yet I've seen slicer results that do just that.</p>
<p>Too cold filament by a substantial amount can also reduce the adhesion in combination with a too low bed temperature.</p>
<p>If you still run into adhesion problems, the Elmer's Purple Glue Stick works wonders.</p>
<p>With the new information comes new responses:</p>
<p>For ABS, 80 °C is on the low end for the bed, but may work. The extruder temp is really low for ABS. I run 250 °C for ABS. Also ensure some form of enclosure, even a cardboard box will help. I've accidentally fed ABS into a PLA profile. The results were surprisingly good, although warping was prevalent and some underextrusion was evident.</p>
<p>If you have a glass bed, you will very much want to use glue stick, as a release agent, not as an adhesive. ABS sticks really well to clean glass, well enough that it will pull fragments of glass from the surface!</p>
| 2,206
|
<p>I've been looking for a <em>simple</em> Java algorithm to generate a pseudo-random alpha-numeric string. In my situation it would be used as a unique session/key identifier that would "likely" be unique over <code>500K+</code> generation (my needs don't really require anything much more sophisticated). </p>
<p>Ideally, I would be able to specify a length depending on my uniqueness needs. For example, a generated string of length 12 might look something like <code>"AEYGF7K0DM1X"</code>. </p>
|
<h2>Algorithm</h2>
<p>To generate a random string, concatenate characters drawn randomly from the set of acceptable symbols until the string reaches the desired length.</p>
<h2>Implementation</h2>
<p>Here's some fairly simple and very flexible code for generating random identifiers. <em>Read the information that follows</em> for important application notes.</p>
<pre><code>public class RandomString {
/**
* Generate a random string.
*/
public String nextString() {
for (int idx = 0; idx < buf.length; ++idx)
buf[idx] = symbols[random.nextInt(symbols.length)];
return new String(buf);
}
public static final String upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
public static final String lower = upper.toLowerCase(Locale.ROOT);
public static final String digits = "0123456789";
public static final String alphanum = upper + lower + digits;
private final Random random;
private final char[] symbols;
private final char[] buf;
public RandomString(int length, Random random, String symbols) {
if (length < 1) throw new IllegalArgumentException();
if (symbols.length() < 2) throw new IllegalArgumentException();
this.random = Objects.requireNonNull(random);
this.symbols = symbols.toCharArray();
this.buf = new char[length];
}
/**
* Create an alphanumeric string generator.
*/
public RandomString(int length, Random random) {
this(length, random, alphanum);
}
/**
* Create an alphanumeric strings from a secure generator.
*/
public RandomString(int length) {
this(length, new SecureRandom());
}
/**
* Create session identifiers.
*/
public RandomString() {
this(21);
}
}
</code></pre>
<h2>Usage examples</h2>
<p>Create an insecure generator for 8-character identifiers:</p>
<pre><code>RandomString gen = new RandomString(8, ThreadLocalRandom.current());
</code></pre>
<p>Create a secure generator for session identifiers:</p>
<pre><code>RandomString session = new RandomString();
</code></pre>
<p>Create a generator with easy-to-read codes for printing. The strings are longer than full alphanumeric strings to compensate for using fewer symbols:</p>
<pre><code>String easy = RandomString.digits + "ACEFGHJKLMNPQRUVWXYabcdefhijkprstuvwx";
RandomString tickets = new RandomString(23, new SecureRandom(), easy);
</code></pre>
<h2>Use as session identifiers</h2>
<p>Generating session identifiers that are likely to be unique is not good enough, or you could just use a simple counter. Attackers hijack sessions when predictable identifiers are used.</p>
<p>There is tension between length and security. Shorter identifiers are easier to guess, because there are fewer possibilities. But longer identifiers consume more storage and bandwidth. A larger set of symbols helps, but might cause encoding problems if identifiers are included in URLs or re-entered by hand.</p>
<p>The underlying source of randomness, or entropy, for session identifiers should come from a random number generator designed for cryptography. However, initializing these generators can sometimes be computationally expensive or slow, so effort should be made to re-use them when possible.</p>
<h2>Use as object identifiers</h2>
<p>Not every application requires security. Random assignment can be an efficient way for multiple entities to generate identifiers in a shared space without any coordination or partitioning. Coordination can be slow, especially in a clustered or distributed environment, and splitting up a space causes problems when entities end up with shares that are too small or too big.</p>
<p>Identifiers generated without taking measures to make them unpredictable should be protected by other means if an attacker might be able to view and manipulate them, as happens in most web applications. There should be a separate authorization system that protects objects whose identifier can be guessed by an attacker without access permission.</p>
<p>Care must be also be taken to use identifiers that are long enough to make collisions unlikely given the anticipated total number of identifiers. This is referred to as "the birthday paradox." <a href="https://en.wikipedia.org/wiki/Birthday_problem#Square_approximation" rel="noreferrer">The probability of a collision,</a> <em>p</em>, is approximately n<sup>2</sup>/(2q<sup>x</sup>), where <em>n</em> is the number of identifiers actually generated, <em>q</em> is the number of distinct symbols in the alphabet, and <em>x</em> is the length of the identifiers. This should be a very small number, like 2<sup>‑50</sup> or less.</p>
<p>Working this out shows that the chance of collision among 500k 15-character identifiers is about 2<sup>‑52</sup>, which is probably less likely than undetected errors from cosmic rays, etc.</p>
<h2>Comparison with UUIDs</h2>
<p>According to their specification, <a href="https://www.rfc-editor.org/rfc/rfc4122#section-6" rel="noreferrer">UUIDs</a> are not designed to be unpredictable, and <em>should not</em> be used as session identifiers.</p>
<p>UUIDs in their standard format take a lot of space: 36 characters for only 122 bits of entropy. (Not all bits of a "random" UUID are selected randomly.) A randomly chosen alphanumeric string packs more entropy in just 21 characters.</p>
<p>UUIDs are not flexible; they have a standardized structure and layout. This is their chief virtue as well as their main weakness. When collaborating with an outside party, the standardization offered by UUIDs may be helpful. For purely internal use, they can be inefficient.</p>
|
<p>Yet another solution...</p>
<pre><code>public static String generatePassword(int passwordLength) {
int asciiFirst = 33;
int asciiLast = 126;
Integer[] exceptions = { 34, 39, 96 };
List<Integer> exceptionsList = Arrays.asList(exceptions);
SecureRandom random = new SecureRandom();
StringBuilder builder = new StringBuilder();
for (int i=0; i<passwordLength; i++) {
int charIndex;
do {
charIndex = random.nextInt(asciiLast - asciiFirst + 1) + asciiFirst;
}
while (exceptionsList.contains(charIndex));
builder.append((char) charIndex);
}
return builder.toString();
}
</code></pre>
| 6,239
|
<p>I lost my MySQL username and password. How do I retrieve it?</p>
|
<blockquote>
<p>Stop the MySQL process.</p>
<p>Start the MySQL process with the --skip-grant-tables option.</p>
<p>Start the MySQL console client with the -u root option.</p>
</blockquote>
<p>List all the users;</p>
<pre><code>SELECT * FROM mysql.user;
</code></pre>
<p>Reset password;</p>
<pre><code>UPDATE mysql.user SET Password=PASSWORD('[password]') WHERE User='[username]';
</code></pre>
<hr />
<p>But <strong>DO NOT FORGET</strong> to</p>
<blockquote>
<p>Stop the MySQL process</p>
<p>Start the MySQL Process normally (i.e. without the --skip-grant-tables option)</p>
</blockquote>
<p>when you are finished. Otherwise, your database's security could be compromised.</p>
|
<p>Although a strict, logical, computer science'ish interpretation of the op's question would be to require <strong>both</strong> "How do I retrieve my MySQL username" <strong>and</strong> "password" - I thought It might be useful to someone to also address the <strong>OR</strong> interpretation. In other words ...</p>
<p>1) How do I retrieve my MySQL username?</p>
<p><strong>OR</strong></p>
<p>2) password</p>
<p>This latter condition seems to have been amply addressed already so I won't bother with it. The following is a solution for the case "How do i retreive my MySQL username" alone. HIH.</p>
<p>To find your mysql username run the following commands from the mysql shell ...</p>
<p>SELECT User FROM mysql.user;</p>
<p>it will print a table of all mysql users.</p>
| 2,639
|
<p>I'm using Windows and I'm trying to get ANT to work.</p>
<p>When I do an ant build from the command line, I get:
<code>C:\dev\Projects\springapp\${%ANT_HOME%}\lib not found.</code></p>
<p>I look into the <code>build.xml</code> file and I find:
<code>appserver.home=${user.home}/apache-tomcat-6.0.14</code> (which I just copied and pasted straight from a tutorial)</p>
<p>I changed it to:</p>
<p><code>appserver.home="C:\Program Files\Apache Software Foundation\Tomcat 6.0"</code></p>
<p>but now I get:</p>
<p><code>C:\dev\Projects\springapp\"C:Program FilesApache Software FoundationTomcat 6.0"\lib not found.</code></p>
<p>It seems like the white space in Program Files and Tomcat 6.0 are causing the build to fail. How do you deal with these in xml files without re-creating the directory with a path with no white space?</p>
|
<p>Change it to </p>
<pre><code>appserver.home="C:\\Program Files\\Apache Software Foundation\\Tomcat 6.0"
</code></pre>
|
<p>In addition to escaping the windows directory separator also make sure that all paths that you type in should be with correct capitalisation, Windows is not case sensitive but case presrving, while Ant is case sensitive.</p>
| 7,913
|
<p>OK, I know there have already been questions about <a href="https://stackoverflow.com/questions/4303/why-should-i-practice-test-driven-development-and-how-should-i-start">getting started with TDD</a>.. However, I guess I kind of know the general concensus is to <em>just do it</em> , However, I seem to have the following problems getting my head into the game:</p>
<ul>
<li>When working with collections, do will still test for obvious add/remove/inserts successful, even when based on Generics etc where we kind of "know" its going to work?</li>
<li>Some tests seem to take forever to implement.. Such as when working with string output, is there a "better" way to go about this sort of thing? (e.g. test the object model before parsing, break parsing down into small ops and test there) In my mind you should always test the "end result" but that can vary wildly and be tedious to set up.</li>
<li>I don't have a testing framework to use (work wont pay for one) so I can "practice" more. Are there any good ones that are free for commercial use? (at the moment I am using good 'ol <em>Debug.Assert</em> :)</li>
<li>Probably the biggest.. Sometimes I don't know what to expect <em>NOT</em> to happen.. I mean, you get your green light but I am always concerned that I may be missing a test.. Do you dig deeper to try and break the code, or leave it be and wait for it all fall over later (which will cost more)..</li>
</ul>
<p>So basically what I am looking for here is not a " <em>just do it</em> " but more " <em>I did this, had problems with this, solved them by this</em> ".. The <strong>personal</strong> experience :)</p>
|
<p>First, it is alright and normal to feel frustrated when you first start trying to use TDD in your coding style. Just don't get discouraged and quit, you will need to give it some time. It is a major paradigm shift in how we think about solving a problem in code. I like to think of it like when we switched from procedural to object oriented programming.</p>
<p>Secondly, I feel that test driven development is first and foremost a design activity that is used to flesh out the design of a component by creating a test that first describes the API it is going to expose and how you are going to consume it's functionality. The test will help shape and mold the System Under Test until you have been able to encapsulate enough functionality to satisfy whatever tasks you happen to be working on.</p>
<p>Taking the above paragraph in mind, let's look at your questions:</p>
<ol>
<li>If I am using a collection in my system under test, then I will setup an expectation to make sure that the code was called to insert the item and then assert the count of the collection. I don't necessarily test the Add method on my internal list. I just make sure it was called when the method that adds the item is called. I do this by adding a mocking framework into the mix, with my testing framework.</li>
<li>Testing strings as output can be tedious. You cannot account for every outcome. You can only test what you expect based on the functionality of the system under test. You should always break your tests down to the smallest element that it is testing. Which means you will have a lot of tests, but tests that are small and fast and only test what they should, nothing else.</li>
<li>There are a lot of open source testing frameworks to choose from. I am not going to argue which is best. Just find one you like and start using it.
<ul>
<li><a href="http://www.mbunit.com/" rel="nofollow noreferrer">MbUnit</a></li>
<li><a href="http://www.nunit.org/index.php" rel="nofollow noreferrer">nUnit</a></li>
<li><a href="http://www.codeplex.com/xunit" rel="nofollow noreferrer">xUnit</a></li>
</ul></li>
<li>All you can do is setup your tests to account for what you want to happen. If a scenario comes up that introduces a bug in your functionality, at least you have a test around the functionality to add that scenario into the test and then change your functionality until the test passes. One way to find where we may have missed a test is to use <a href="http://www.ncover.com/" rel="nofollow noreferrer">code coverage</a>.</li>
</ol>
<p>I introduced you to the mocking term in the answer for question one. When you introduce mocking into your arsenal for TDD, it dramatically makes testing easier to abstract away the parts that are not part of the system under test. Here are some resources on the mocking frameworks out there are:</p>
<ul>
<li><a href="http://code.google.com/p/moq/" rel="nofollow noreferrer">Moq</a>: Open Source</li>
<li><a href="http://www.ayende.com/projects/rhino-mocks.aspx" rel="nofollow noreferrer">RhinoMocks</a>: Open Source</li>
<li><a href="http://www.typemock.com/" rel="nofollow noreferrer">TypeMock</a>: Commercial Product</li>
<li><a href="http://nsubstitute.github.com/" rel="nofollow noreferrer">NSubstitute</a>: Open Source</li>
</ul>
<p>One way to help in using TDD, besides reading about the process, is to watch people do it. I recommend in watching the screen casts by JP Boodhoo on <a href="http://www.dnrtv.com/archives.aspx" rel="nofollow noreferrer">DNRTV</a>. Check these out:</p>
<ul>
<li><a href="http://www.dnrtv.com/default.aspx?showNum=10" rel="nofollow noreferrer">Jean Paul Boodhoo on Test Driven Development Part 1</a></li>
<li><a href="http://www.dnrtv.com/default.aspx?showNum=11" rel="nofollow noreferrer">Jean Paul Boodhoo on Test Driven Development Part 2</a></li>
<li><a href="http://www.dnrtv.com/default.aspx?showNum=63" rel="nofollow noreferrer">Jean Paul Boodhoo on Demystifying Design Patterns Part 1</a></li>
<li><a href="http://www.dnrtv.com/default.aspx?showNum=65" rel="nofollow noreferrer">Jean Paul Boodhoo on Demystifying Design Patterns Part 2</a></li>
<li><a href="http://www.dnrtv.com/default.aspx?showNum=68" rel="nofollow noreferrer">Jean Paul Boodhoo on Demystifying Design Patterns Part 3</a></li>
<li><a href="http://www.dnrtv.com/default.aspx?showNum=71" rel="nofollow noreferrer">Jean Paul Boodhoo on Demystifying Design Patterns Part 4</a></li>
<li><a href="http://www.dnrtv.com/default.aspx?showNum=92" rel="nofollow noreferrer">Jean Paul Boodhoo on Demystifying Design Patterns Part 5</a></li>
</ul>
<p>OK, these will help you see how the terms I introduced are used. It will also introduce another tool called <a href="http://www.jetbrains.com/resharper/" rel="nofollow noreferrer">Resharper</a> and how it can facilitate the TDD process. I couldn't recommend this tool enough when doing TDD. Seems like you are learning the process and you are just finding some of the problems that have already been solved with using other tools.</p>
<p>I think I would be doing an injustice to the community, if I didn't update this by adding Kent Beck's new series on <a href="http://www.pragprog.com/screencasts/v-kbtdd/test-driven-development" rel="nofollow noreferrer">Test Driven Development on Pragmatic Programmer</a>.</p>
|
<p>I am no expert at TDD, by any means, but here is my view:</p>
<ul>
<li>If it is completely trivial (getters/setters etc) do not test it, unless you don't have confidence in the code for some reason.</li>
<li>If it is a quite simple, but non-trivial method, test it. The test is probably easy to write anyway.</li>
<li>When it comes to what to expect not to happen, I would say that if a certain potential problem is the responsibility of the class you are testing, you need to test that it handles it correctly. If it is not the current class' responsibility, don't test it.</li>
</ul>
<p>The xUnit testing frameworks are often free to use, so if you are a .Net guy, check out NUnit, and if Java is your thing check out JUnit.</p>
| 4,462
|
<p>I'm looking for a way to give out preview or demo versions of our software to our customers as easy as possible.</p>
<p>The software we are currently developing is a pretty big project. It consists of a client environment, an application server, various databases, web services host etc.
The project is developed incrementally and we want to ship the bits in intervals of one to two months. The first deliveries will not be used in production. They have the puropse of a demo to encourage the customers to give feedback.</p>
<p>We don't want to put burden on the customers to install and configure the system. All in all we are looking for a way to ease the deployment, installation and configuration pain.</p>
<p>What I thought of was to use a virtualizing technique to preinstall and preconfigure a virtual machine with all components that are neccessary. Our customers just have to mount the virtual image and run the application.</p>
<p>I would like to hear from folks who use this technique. I suppose there are some difficulties as well. Especially, what about licensing issues with the installed OS?
Perhaps it is possible to have the virtual machine expire after a certain period of time.</p>
<p>Any experiences out there?</p>
|
<p>Since you're looking at an entire application stack, you'll need to virtualize the entire server to provide your customers with a realistic demo experience. Thinstall is great for single apps, but not an entire stack....</p>
<p>Microsoft have licensing schemes for this type of situation, since it's only been used for demonstration purposes and not production use a TechNet subscription might just cover you. Give your local Microsoft licensing centre a call to discuss, unlike the offshore support teams they're really helpful and friendly. </p>
<p>For running the 'stack' with the least overhead for your clients, I suggest using VMware. The customers can download the free VMware player, load up the machines (or multiple machines) and get a feel for the system... Microsoft Virtual PC or Virtual Server is going to be a bit more intrusive and not quite the "plug n play" solution that you're looking for. </p>
<p>If you're only looking to ship the application, consider either thinstall or providing Citrix / Terminal services access - customers can remotely login to your own (test) machines and run what they need. </p>
<p>Personally if it's doable, a standalone system would be best - tell your customers install vmware player, then run this app... which launches the various parts of your application stack (maybe off of a DVD) and you've got a fully self contained demo for the marketing guys to pimp out :)</p>
|
<blockquote>
<p>Thinstall is great for single apps, but not an entire stack....</p>
</blockquote>
<p>I didn't try it yet, but with the new version of thinstall you are able to let different thinstalled application communicate.
But I guess you're right a vm-ware image would be easier</p>
| 4,955
|
<p>The CodePlex team has a <a href="https://rads.stackoverflow.com/amzn/click/com/0767907698" rel="noreferrer" rel="nofollow noreferrer">Slack</a> time policy, and it's worked out very well for them.</p>
<ul>
<li>Jim Newkirk and myself used it to work on the <a href="http://www.codeplex.com/xunit" rel="noreferrer">xUnit.net</a> project.</li>
<li>Jonathan Wanagel used it to work on <a href="http://www.codeplex.com/SvnBridge" rel="noreferrer">SvnBridge</a>.</li>
<li>Scott Densmore and myself used it to work on an <a href="http://www.codeplex.com/ObjectBuilder" rel="noreferrer">ObjectBuilder 2.0</a> prototype.</li>
</ul>
<p>For others, it was a great time to explore things that were technically not on the schedule, but could eventually end up being of great use to the rest of the team. I'm so convinced of the value of this that if I'm ever running a team again, I'm going to make it part of the team culture.</p>
<p>Have you had a formalized Slack policy on your team? How did it work out?</p>
<p><strong>Edited:</strong> I just realized I didn't define Slack. For those who haven't read the book, Slack is what Google's "20% time" is: you're given some slice of your day/week/month/year on which to work on things that are not necessarily directly related to your day-to-day job, but might have an indirect benefit (obviously if you work on stuff that's totally not useful for your job or your company, your manager probably won't think very well of the way you spent the time :-p).</p>
|
<p>I just want to mention Google's policy on the subject.<br>
20% of the day should be used for private projects and research. </p>
<p>I think it is time for managers to face the fact that most good developers are a bit lazy. If they weren't, we wouldn't have concepts like code reuse.<br>
If this laziness can be focused into a creative force, and the developers can read up on technical issues and experiment with architecture and language features, I am certain that the end result will be better code and a more satisfied developer. </p>
<p>So, if you are a manager: Let your developers slack of now and then. Encourage them to hold small seminars with the team to discuss new ways of doing stuff. </p>
<p>If you are a developer: Read, learn and love your craft. You have one of the best jobs in the world, as long as you are willing to put some time into learning the best ways to do your job.</p>
|
<p>I've never worked anywhere that had a formalized policy, but practically every manager I've ever had has allowed me to spend some time on things that weren't directly related to the current project or fighting a fire.</p>
<p>I think the key is to talk about the things you'd like to try. Most managers want their teams to do something cool, something extraordinary, so if you can convince them that you might deliver something, you might get the chance. Or they might let you do it just to keep you happy.</p>
<p>Now that I'm a contractor rather than an employee, I don't get paid to do fun stuff, but I generally only work 30-35 hours per week, so I still have time to learn and to play.</p>
| 3,434
|
<p>We have a junior programmer that simply doesn't write enough tests.<br>
I have to nag him every two hours, "have you written tests?"<br>
We've tried:</p>
<ul>
<li>Showing that the design becomes simpler</li>
<li>Showing it prevents defects</li>
<li>Making it an ego thing saying only bad programmers don't</li>
<li>This weekend 2 team members had to come to work because his code had a NULL reference and he didn't test it</li>
</ul>
<p>My work requires top quality stable code, and usually everyone 'gets it' and there's no need to push tests through. We know we can make him write tests, but we all know the useful tests are those written when you're into it.</p>
<p>Do you know of more motivations?</p>
|
<p>This is one of <em>the hardest things</em> to do. Getting your people to <em>get it</em>.</p>
<p>Sometimes one of the best ways to help junior level programmers 'get it' and learn the right techniques from the seniors is to do a bit of pair programming.</p>
<p>Try this: on an upcoming project, pair the junior guy up with yourself or another senior programmer. They should work together, taking turns "driving" (being the one typing at they keyboard) and "coaching" (looking over the shoulder of the driver and pointing out suggestions, mistakes, etc as they go). It may seem like a waste of resources, but you will find:</p>
<ol>
<li>That these guys together can produce code plenty fast and of higher quality.</li>
<li>If your junior guy learns enough to "get it" with a senior guy directing him along the right path (eg. "Ok, now before we continue, lets write at test for this function.") It will be well worth the resources you commit to it.</li>
</ol>
<p>Maybe also have someone in your group give the <a href="http://www.masukomi.org/talks/unit_testing/index.html#1" rel="noreferrer">Unit Testing 101</a> presentation by Kate Rhodes, I think its a great way to get people excited about testing, if delivered well.</p>
<p>Another thing you can do is have your Jr. Devs practice the <a href="http://butunclebob.com/ArticleS.UncleBob.TheBowlingGameKata" rel="noreferrer">Bowling Game Kata</a> which will help them learn Test Driven Development. It is in java, but could easily be adapted to any language.</p>
|
<p>Based on your comment, "Showing that the design becomes simpler" I'm assuming you guys practice TDD. Doing a code review after the fact is not going to work. The whole thing about TDD is that it's a design and not a testing philosophy. If he didn't write the tests as part of the design, you aren't going to get a lot of benefit from writing tests after the fact - especially from a junior developer. He'll end up missing a whole lot of corner cases and his code will still be crappy.</p>
<p>Your best bet is to have a <strong>very</strong> patient senior developer to sit with him and do some pair programming. And just keep at it until he learns. Or doesn't learn, in which case you need to reassign him to a task he is better suited to because you will just end up frustrating your real developers.</p>
<p>Not everyone has the same level of talent and/or motivation. Development teams, even agile ones, are made up of people on the "A-Team" and people on "B-Team". A-Team members are the one who architect the solution, write all the non-trivial production code, and communicate with the business owners - all the work that requires thinking outside the box. The B-Team handle things like configuration management, writing scripts, fixing lame bugs, and doing maintenance work - all the work that has strict procedures that have small consequences for failure. </p>
| 2,888
|
<p>How do you perform a CROSS JOIN with LINQ to SQL?</p>
|
<p>A cross-join is simply the Cartesian product of two sets. There's no explicit join operator for it.</p>
<pre>
var combo = from p in people
from c in cars
select new
{
p.Name,
c.Make,
c.Model,
c.Colour
};
</pre>
|
<p>Extension Method:</p>
<pre><code>public static IEnumerable<Tuple<T1, T2>> CrossJoin<T1, T2>(this IEnumerable<T1> sequence1, IEnumerable<T2> sequence2)
{
return sequence1.SelectMany(t1 => sequence2.Select(t2 => Tuple.Create(t1, t2)));
}
</code></pre>
<p>And use like:</p>
<pre><code>vals1.CrossJoin(vals2)
</code></pre>
| 8,049
|
<p>I want to define something like this in <em>php</em>:</p>
<pre><code>$EL = "\n<br />\n";
</code></pre>
<p>and then use that variable as an "endline" marker all over my site, like this:</p>
<pre><code>echo "Blah blah blah{$EL}";
</code></pre>
<p>How do I define $EL once (in only 1 file), include it on every page on my site, and <em>not</em> have to reference it using the (strangely backwards) <code>global $EL;</code> statement in every page function?</p>
|
<p>Most PHP sites should have a file (I call it a header) that you include on every single page of the site. If you put that first line of code in the header file, then include it like this on every page:</p>
<pre><code> include 'header.php';
</code></pre>
<p>you won't have to use the global keyword or anything, the second line of code you wrote should work.</p>
<p>Edit: Oh sorry, that won't work inside functions... now I see your problem.</p>
<p>Edit #2: Ok, take my original advice with the header, but use a <a href="http://php.net/define" rel="noreferrer">define()</a> rather than a variable. Those work inside functions after being included.</p>
|
<p>IIRC a common solution is a plain file that contains your declarations, that you include in every source file, something like '<em>constants.inc.php</em>'. There you can define a bunch of application-wide variables that are then imported in every file.</p>
<p>Still, you have to provide the include directive in <strong>every</strong> single source file you use. I even saw some projects using this technique to provide localizations for several languages. I'd prefer the gettext way, but maybe this variant is easier to work with for the average user.</p>
<p><strong>edit</strong> For your problem I recomment the use of <strong>$GLOBALS[]</strong>, see <a href="http://php.net/manual/en/language.variables.scope.php" rel="nofollow noreferrer">Example #2</a> for details.</p>
<p>If that's still not applicable, I'd try to digg down PHP5 objects and create a static Singleton that provides needed static constants (<a href="http://www.developer.com/lang/php/article.php/3345121" rel="nofollow noreferrer">http://www.developer.com/lang/php/article.php/3345121</a>)</p>
| 3,405
|
<p>earlier today someone asked about free/cheap component libraries for winforms. I'm interested in the same thing, but for asp.net. There are some great commercial libraries like Telerik and DevExpress, but are there any great free/cheap alternatives?</p>
|
<p>I am not sure what you constitute as cheap, but the Peter Blum ASP.NET controls are a good buy.</p>
<p><a href="http://www.peterblum.com/Home.aspx" rel="nofollow noreferrer">peterblum.com</a></p>
|
<p>Try this free custom web controls : <a href="http://www.eworldui.net/" rel="nofollow noreferrer">Excentrics World .NET</a></p>
| 8,458
|
<p>We have the standard Subversion trunk/branches/tags layout. We have several branches for medium- and long-term projects, but none so far for a release. This is approaching fast.</p>
<p>Should we:</p>
<ol>
<li>Mix release branches and project branches together?</li>
<li>Create a releases folder? If so, is there a better name than releases?</li>
<li>Create a projects folder and move the current branches there? If so, is there a better name than projects? I've seen "sandbox" and "spike" in other repositories.</li>
<li>Something else altogether?</li>
</ol>
|
<p>I recommend the following layout, for two reasons:
- all stuff related to a given project is within the same part of the tree; makes
it easier for people to grasp
- permissions handling may be easier this way</p>
<p>And by the way: It's a good idea with few repositories, instead of many, because change history normally is better preserved that way (change history is gone if you move files between repositories, unless you take special and somewhat complicated action). In most setups, there should only be two repositories: the main repository, and a sandbox repository for people experimenting with Subversion.</p>
<pre><code>project1
trunk
branches
1.0
1.1
joes-experimental-feature-branch
tags
1.0.0
1.0.1
1.0.2
project2
trunk
branches
1.0
1.1
tags
1.0.0
1.0.1
1.0.2
</code></pre>
|
<p>Releases is the same as tags... Have you got multiple projects inside your trunk? In that case, I would copy the same folders inside tags</p>
<p>So</p>
<pre><code>trunk
fooapp
stuff...
barapp
stuff...
tags
fooapp
1.0.0
1.0.1
barapp
1.0.0
</code></pre>
| 7,188
|
<p>First off, this is a question about a desktop application using Windows Forms, not an <a href="http://en.wikipedia.org/wiki/ASP.NET" rel="nofollow noreferrer">ASP.NET</a> question.</p>
<p>I need to interact with controls on other forms. I am trying to access the controls by using, for example, the following...</p>
<pre><code>otherForm.Controls["nameOfControl"].Visible = false;
</code></pre>
<p>It doesn't work the way I would expect. I end up with an exception thrown from <code>Main</code>. However, if I make the controls <code>public</code> instead of <code>private</code>, I can then access them directly, as so...</p>
<pre><code>otherForm.nameOfControl.Visible = false;
</code></pre>
<p>But is that the best way to do it? Is making the controls <code>public</code> on the other form considered "best practice"? Is there a "better" way to access controls on another form?</p>
<p><strong>Further Explanation:</strong></p>
<p>This is actually a sort of follow-up to another question I asked, <em><a href="https://stackoverflow.com/questions/3725/best-method-for-creating-a-tree-view-preferences-dialog-type-of-interface-in-c">Best method for creating a “tree-view preferences dialog” type of interface in C#?</a></em>. The answer I got was great and solved many, many organizational problems I was having in terms of keeping the UI straight and easy to work with both in run-time and design-time. However, it did bring up this one niggling issue of easily controlling other aspects of the interface.</p>
<p>Basically, I have a root form that instantiates a lot of other forms that sit in a panel on the root form. So, for instance, a radio button on one of those sub-forms might need to alter the state of a status strip icon on the main, root form. In that case, I need the sub-form to talk to the control in the status strip of the parent (root) form. (I hope that makes sense, not in a "who's on first" kind of way.)</p>
|
<p>Instead of making the control public, you can create a property that controls its visibility:</p>
<pre><code>public bool ControlIsVisible
{
get { return control.Visible; }
set { control.Visible = value; }
}
</code></pre>
<p>This creates a proper accessor to that control that won't expose the control's whole set of properties.</p>
|
<p>Do your child forms really need to be Forms? Could they be user controls instead? This way, they could easily raise events for the main form to handle and you could better encapsulate their logic into a single class (at least, logically, they are after all classes already).</p>
<p>@Lars: You are right here. This was something I did in my very beginning days and have not had to do it since, that is why I first suggested raising an event, but my other method would really break any semblance of encapsulation.</p>
<p>@Rob: Yup, sounds about right :). 0/2 on this one...</p>
| 3,001
|
<p>I have a web application that sometimes just hangs over heavy load. To make it come back I have to kill the "dllhost.exe" process. <strong>Does someone know what to do?</strong></p>
<p>This is an Classic ASP (VBScript) app with lots of COM+ objects.</p>
<p>The server has the following configuration:</p>
<ul>
<li>Intel Core 2 Duo 2.2 GHz / 4 GB RAM</li>
<li>Windows Server 2003 Web Edition SP2</li>
<li>IIS 6.0</li>
</ul>
<p>There is some errors in the event log related to the COM objects. But why errors in the COM objects would crash the whole server?</p>
<p>The COM objects are PowerBuilder objects deployed as COM objects.</p>
<p>Is IIS 7.0 (much) more stable than IIS 6.0?</p>
|
<p>Sounds like dodgy COM objects causing the problem .. do you load them into the "Application", if you do then are they threadsafe; or are they used and discarded on each request?</p>
<p>Yes, recycling every few hours would help 'hide' the problem, but they ought to be debugged and fixed properly ... have you tried divide/conquer to discover which COM object is the problem ... I can imagine this is tricky on a production environment so you need to set up some heavy automated tests to reproduce the problem locally then you can do something about it.</p>
|
<p>There is probably some errors in your eventlog under the Application and System categories. Try to find the origin of these errors or post them here we'll see what we can do :)</p>
<p>Edit :
@Daniel Silveira
A memory leak is probable. What COM+ object do you use? I had some issues with Excel with an application I support.</p>
| 3,970
|
<p>I am trying to print a tank to be used with my RC engine. The material that I have to use needs to have the following properties:</p>
<ul>
<li>It needs to be possible to seal the final print so that it is not leaking any fluid</li>
<li>It needs to resist methanol, nitromethane (a solvent like Acetone) and lubricating oil at room temperature. It can get discolored or have other changes from the fuel, but it must not be able to compromise the sealing.</li>
</ul>
<p>I first - foolishly - just printed it with ABS as I do for every fluid container as I can nicely seal it with Acetone. After almost being done with it a friend told me to check the chemical resistance of ABS and as you might guess methanol and nitromethane completely desintegrate it, almost like acetone itself, so that was a waste of time/material.</p>
<p>Next I considered using Nylon. It shows exactly the chemical resistance against all the fuel components I need, however I could not find any (easily available) option to seal the print after printing and after printing a small test container and pouring in some water it leaks after half a minute, so unless I find a way to seal the Nylon containers interior this is also not an option.</p>
<p>I checked various epoxies but the few that I checked all showed poor resistance against methanol/nitromethane.</p>
<p>What I could not test yet but seems like an option is using HDPE. I am using PET bottles to transport the fuel sometimes so it definitely is both resistant and - in theory - watertight, however I am not sure how I can seal an HDPE print, so I am not sure about my first requirement with HDPE. <strong>EDIT</strong>: I found that <a href="https://en.wikipedia.org/wiki/Limonene" rel="nofollow noreferrer">Limonene</a> dissolves HDPE and is relatively harmless and easily obtainable. Maybe it can be used to seal the HDPE print surface?</p>
<p>Hence my question: Is there a material that can be printed on a regular desktop printer (heated bed, nozzle up to 255°C) that satisfies both my requirements above or am I "doomed" to buy a moulded plastic fuel tank?</p>
|
<p>Most commercial blow-molded fuel tanks for model airplane fuel (methanol or ethanol, nitromethane or nitroethane, and some combination of castor, mineral, or synthetic lubricating oil) are made from HDPE. This material isn't commonly seen as filament, in my limited experience, but it ought to be possible to arrive at settings that will give a liquid tight tank without further sealing if you can find some. As you note, limonene might be used to smooth/seal HDPE prints, but likely won't be necessary if your settings are right.</p>
<p>You might want to test PETG filament for its resistance to your fuel mix(es) -- this material <em>is</em> available as filament, prints with settings little different from generic PLA (in my experience, higher nozzle and bed temperature, and a little more bed clearance for the first layer), with good layer adhesion and, with a good print, is liquid-tight as printed. It's not particularly flexible (as is the case with HDPE), but since you can customize the shape of your fuel tank, it may work for you -- or it may be more flexible in vase mode, as PLA is.</p>
<p>Sealing PETG may be as simple as baking it (similar to "heat treating" PLA to increase print strength, albeit again at a higher temperature) -- this partial remelting will ensure that layers are adhered throughout the print, which (presuming you have avoided under-extruded areas) should be all that's needed to make a printed tank liquid tight.</p>
|
<p>As a supplement to the answer (doesn't fit well in the comments). This site <a href="https://www.filamentive.com/chemical-resistance-of-3d-printing-filament/" rel="nofollow noreferrer">https://www.filamentive.com/chemical-resistance-of-3d-printing-filament/</a> lists PETG has have a very high restance to alcohol, a high resitance to fuel</p>
<blockquote>
<p><strong>Is PETG UV Resistant?</strong></p>
</blockquote>
<blockquote>
<p>In the long run, it is now a well-known fact that it will almost always come out on top when it comes to objects and builds that have to be resistant to ultraviolet (UV) radiation. I.e., UV resistant. This is why it is ideal for objects that have to be kept under the harsh mid-summer sun. This is because UV radiation has minimal effect on it as compared to PLA and ABS.
--
From <a href="https://makershop.co/petg-uv-resistance/" rel="nofollow noreferrer">https://makershop.co/petg-uv-resistance/</a></p>
</blockquote>
| 1,948
|
<p>Why are pointers such a leading factor of confusion for many new, and even old, college level students in C or C++? Are there any tools or thought processes that helped you understand how pointers work at the variable, function, and beyond level?</p>
<p>What are some good practice things that can be done to bring somebody to the level of, "Ah-hah, I got it," without getting them bogged down in the overall concept? Basically, drill like scenarios.</p>
|
<p>Pointers is a concept that for many can be confusing at first, in particular when it comes to copying pointer values around and still referencing the same memory block.</p>
<p>I've found that the best analogy is to consider the pointer as a piece of paper with a house address on it, and the memory block it references as the actual house. All sorts of operations can thus be easily explained.</p>
<p>I've added some Delphi code down below, and some comments where appropriate. I chose Delphi since my other main programming language, C#, does not exhibit things like memory leaks in the same way.</p>
<p>If you only wish to learn the high-level concept of pointers, then you should ignore the parts labelled "Memory layout" in the explanation below. They are intended to give examples of what memory could look like after operations, but they are more low-level in nature. However, in order to accurately explain how buffer overruns really work, it was important that I added these diagrams.</p>
<p><em>Disclaimer: For all intents and purposes, this explanation and the example memory
layouts are vastly simplified. There's more overhead and a lot more details you would
need to know if you need to deal with memory on a low-level basis. However, for the
intents of explaining memory and pointers, it is accurate enough.</em></p>
<hr>
<p>Let's assume the THouse class used below looks like this:</p>
<pre><code>type
THouse = class
private
FName : array[0..9] of Char;
public
constructor Create(name: PChar);
end;
</code></pre>
<p>When you initialize the house object, the name given to the constructor is copied into the private field FName. There is a reason it is defined as a fixed-size array.</p>
<p>In memory, there will be some overhead associated with the house allocation, I'll illustrate this below like this:</p>
<pre>
---[ttttNNNNNNNNNN]---
^ ^
| |
| +- the FName array
|
+- overhead
</pre>
<p>The "tttt" area is overhead, there will typically be more of this for various types of runtimes and languages, like 8 or 12 bytes. It is imperative that whatever values are stored in this area never gets changed by anything other than the memory allocator or the core system routines, or you risk crashing the program.</p>
<hr>
<p><strong>Allocate memory</strong></p>
<p>Get an entrepreneur to build your house, and give you the address to the house. In contrast to the real world, memory allocation cannot be told where to allocate, but will find a suitable spot with enough room, and report back the address to the allocated memory.</p>
<p>In other words, the entrepreneur will choose the spot.</p>
<pre><code>THouse.Create('My house');
</code></pre>
<p>Memory layout:</p>
<pre>
---[ttttNNNNNNNNNN]---
1234My house
</pre>
<hr>
<p><strong>Keep a variable with the address</strong></p>
<p>Write the address to your new house down on a piece of paper. This paper will serve as your reference to your house. Without this piece of paper, you're lost, and cannot find the house, unless you're already in it.</p>
<pre><code>var
h: THouse;
begin
h := THouse.Create('My house');
...
</code></pre>
<p>Memory layout:</p>
<pre>
h
v
---[ttttNNNNNNNNNN]---
1234My house
</pre>
<hr>
<p><strong>Copy pointer value</strong> </p>
<p>Just write the address on a new piece of paper. You now have two pieces of paper that will get you to the same house, not two separate houses. Any attempts to follow the address from one paper and rearrange the furniture at that house will make it seem that <em>the other house</em> has been modified in the same manner, unless you can explicitly detect that it's actually just one house.</p>
<p><em>Note</em> This is usually the concept that I have the most problem explaining to people, two pointers does not mean two objects or memory blocks.</p>
<pre><code>var
h1, h2: THouse;
begin
h1 := THouse.Create('My house');
h2 := h1; // copies the address, not the house
...
</code></pre>
<pre>
h1
v
---[ttttNNNNNNNNNN]---
1234My house
^
h2
</pre>
<hr>
<p><strong>Freeing the memory</strong> </p>
<p>Demolish the house. You can then later on reuse the paper for a new address if you so wish, or clear it to forget the address to the house that no longer exists.</p>
<pre><code>var
h: THouse;
begin
h := THouse.Create('My house');
...
h.Free;
h := nil;
</code></pre>
<p>Here I first construct the house, and get hold of its address. Then I do something to the house (use it, the ... code, left as an exercise for the reader), and then I free it. Lastly I clear the address from my variable.</p>
<p>Memory layout:</p>
<pre>
h <--+
v +- before free
---[ttttNNNNNNNNNN]--- |
1234My house <--+
h (now points nowhere) <--+
+- after free
---------------------- | (note, memory might still
xx34My house <--+ contain some data)
</pre>
<hr>
<p><strong>Dangling pointers</strong></p>
<p>You tell your entrepreneur to destroy the house, but you forget to erase the address from your piece of paper. When later on you look at the piece of paper, you've forgotten that the house is no longer there, and goes to visit it, with failed results (see also the part about an invalid reference below).</p>
<pre><code>var
h: THouse;
begin
h := THouse.Create('My house');
...
h.Free;
... // forgot to clear h here
h.OpenFrontDoor; // will most likely fail
</code></pre>
<p>Using <code>h</code> after the call to <code>.Free</code> <em>might</em> work, but that is just pure luck. Most likely it will fail, at a customers place, in the middle of a critical operation.</p>
<pre>
h <--+
v +- before free
---[ttttNNNNNNNNNN]--- |
1234My house <--+
h <--+
v +- after free
---------------------- |
xx34My house <--+
</pre>
<p>As you can see, h still points to the remnants of the data in memory, but
since it might not be complete, using it as before might fail.</p>
<hr>
<p><strong>Memory leak</strong> </p>
<p>You lose the piece of paper and cannot find the house. The house is still standing somewhere though, and when you later on want to construct a new house, you cannot reuse that spot.</p>
<pre><code>var
h: THouse;
begin
h := THouse.Create('My house');
h := THouse.Create('My house'); // uh-oh, what happened to our first house?
...
h.Free;
h := nil;
</code></pre>
<p>Here we overwrote the contents of the <code>h</code> variable with the address of a new house, but the old one is still standing... somewhere. After this code, there is no way to reach that house, and it will be left standing. In other words, the allocated memory will stay allocated until the application closes, at which point the operating system will tear it down.</p>
<p>Memory layout after first allocation:</p>
<pre>
h
v
---[ttttNNNNNNNNNN]---
1234My house
</pre>
<p>Memory layout after second allocation:</p>
<pre>
h
v
---[ttttNNNNNNNNNN]---[ttttNNNNNNNNNN]
1234My house 5678My house
</pre>
<p>A more common way to get this method is just to forget to free something, instead of overwriting it as above. In Delphi terms, this will occur with the following method:</p>
<pre><code>procedure OpenTheFrontDoorOfANewHouse;
var
h: THouse;
begin
h := THouse.Create('My house');
h.OpenFrontDoor;
// uh-oh, no .Free here, where does the address go?
end;
</code></pre>
<p>After this method has executed, there's no place in our variables that the address to the house exists, but the house is still out there.</p>
<p>Memory layout:</p>
<pre>
h <--+
v +- before losing pointer
---[ttttNNNNNNNNNN]--- |
1234My house <--+
h (now points nowhere) <--+
+- after losing pointer
---[ttttNNNNNNNNNN]--- |
1234My house <--+
</pre>
<p>As you can see, the old data is left intact in memory, and will not
be reused by the memory allocator. The allocator keeps track of which
areas of memory has been used, and will not reuse them unless you
free it.</p>
<hr>
<p><strong>Freeing the memory but keeping a (now invalid) reference</strong> </p>
<p>Demolish the house, erase one of the pieces of paper but you also have another piece of paper with the old address on it, when you go to the address, you won't find a house, but you might find something that resembles the ruins of one.</p>
<p>Perhaps you will even find a house, but it is not the house you were originally given the address to, and thus any attempts to use it as though it belongs to you might fail horribly.</p>
<p>Sometimes you might even find that a neighbouring address has a rather big house set up on it that occupies three address (Main Street 1-3), and your address goes to the middle of the house. Any attempts to treat that part of the large 3-address house as a single small house might also fail horribly.</p>
<pre><code>var
h1, h2: THouse;
begin
h1 := THouse.Create('My house');
h2 := h1; // copies the address, not the house
...
h1.Free;
h1 := nil;
h2.OpenFrontDoor; // uh-oh, what happened to our house?
</code></pre>
<p>Here the house was torn down, through the reference in <code>h1</code>, and while <code>h1</code> was cleared as well, <code>h2</code> still has the old, out-of-date, address. Access to the house that is no longer standing might or might not work.</p>
<p>This is a variation of the dangling pointer above. See its memory layout.</p>
<hr>
<p><strong>Buffer overrun</strong> </p>
<p>You move more stuff into the house than you can possibly fit, spilling into the neighbours house or yard. When the owner of that neighbouring house later on comes home, he'll find all sorts of things he'll consider his own.</p>
<p>This is the reason I chose a fixed-size array. To set the stage, assume that
the second house we allocate will, for some reason, be placed before the
first one in memory. In other words, the second house will have a lower
address than the first one. Also, they're allocated right next to each other.</p>
<p>Thus, this code:</p>
<pre><code>var
h1, h2: THouse;
begin
h1 := THouse.Create('My house');
h2 := THouse.Create('My other house somewhere');
^-----------------------^
longer than 10 characters
0123456789 <-- 10 characters
</code></pre>
<p>Memory layout after first allocation:</p>
<pre>
h1
v
-----------------------[ttttNNNNNNNNNN]
5678My house
</pre>
<p>Memory layout after second allocation:</p>
<pre>
h2 h1
v v
---[ttttNNNNNNNNNN]----[ttttNNNNNNNNNN]
1234My other house somewhereouse
^---+--^
|
+- overwritten
</pre>
<p>The part that will most often cause crash is when you overwrite important parts
of the data you stored that really should not be randomly changed. For instance
it might not be a problem that parts of the name of the h1-house was changed,
in terms of crashing the program, but overwriting the overhead of the
object will most likely crash when you try to use the broken object,
as will overwriting links that is stored to
other objects in the object.</p>
<hr>
<p><strong>Linked lists</strong> </p>
<p>When you follow an address on a piece of paper, you get to a house, and at that house there is another piece of paper with a new address on it, for the next house in the chain, and so on.</p>
<pre><code>var
h1, h2: THouse;
begin
h1 := THouse.Create('Home');
h2 := THouse.Create('Cabin');
h1.NextHouse := h2;
</code></pre>
<p>Here we create a link from our home house to our cabin. We can follow the chain until a house has no <code>NextHouse</code> reference, which means it's the last one. To visit all our houses, we could use the following code:</p>
<pre><code>var
h1, h2: THouse;
h: THouse;
begin
h1 := THouse.Create('Home');
h2 := THouse.Create('Cabin');
h1.NextHouse := h2;
...
h := h1;
while h <> nil do
begin
h.LockAllDoors;
h.CloseAllWindows;
h := h.NextHouse;
end;
</code></pre>
<p>Memory layout (added NextHouse as a link in the object, noted with
the four LLLL's in the below diagram):</p>
<pre>
h1 h2
v v
---[ttttNNNNNNNNNNLLLL]----[ttttNNNNNNNNNNLLLL]
1234Home + 5678Cabin +
| ^ |
+--------+ * (no link)
</pre>
<hr>
<p><strong>In basic terms, what is a memory address?</strong></p>
<p>A memory address is in basic terms just a number. If you think of memory
as a big array of bytes, the very first byte has the address 0, the next one
the address 1 and so on upwards. This is simplified, but good enough.</p>
<p>So this memory layout:</p>
<pre>
h1 h2
v v
---[ttttNNNNNNNNNN]---[ttttNNNNNNNNNN]
1234My house 5678My house
</pre>
<p>Might have these two address (the leftmost - is address 0):</p>
<ul>
<li>h1 = 4</li>
<li>h2 = 23</li>
</ul>
<p>Which means that our linked list above might actuall look like this:</p>
<pre>
h1 (=4) h2 (=28)
v v
---[ttttNNNNNNNNNNLLLL]----[ttttNNNNNNNNNNLLLL]
1234Home 0028 5678Cabin 0000
| ^ |
+--------+ * (no link)
</pre>
<p>It is typical to store an address that "points nowhere" as a zero-address.</p>
<hr>
<p><strong>In basic terms, what is a pointer?</strong></p>
<p>A pointer is just a variable holding a memory address. You can typically ask the programming
language to give you its number, but most programming languages and runtimes tries to
hide the fact that there is a number beneath, just because the number itself does not
really hold any meaning to you. It is best to think of a pointer as a black box, ie.
you don't really know or care about how it is actually implemented, just as long as it
works.</p>
|
<p>I don't see what is so confusing about pointers. They point to a location in memory, that is it stores the memory address. In C/C++ you can specify the type the pointer points to. For example:</p>
<pre><code>int* my_int_pointer;
</code></pre>
<p>Says that my_int_pointer contains the address to a location that contains an int.</p>
<p>The problem with pointers is that they point to a location in memory, so it is easy to trail off into some location you should not be in. As proof look at the numerous security holes in C/C++ applications from buffer overflow (incrementing the pointer past the allocated boundary).</p>
| 2,758
|
<p>How would you create a database in Microsoft Access that is searchable only by certain fields and controlled by only a few (necessary) text boxes and check boxes on a form so it is easy to use - no difficult queries?</p>
<p>Example:
You have several text boxes and several corresponding check boxes on a form, and when the check box next to the text box is checked, the text box is enabled and you can then search by what is entered into said text box</p>
<p>(Actually I already know this, just playing stackoverflow jeopardy, where I ask a question I know the answer just to increase the world's coding knowledge! answer coming in about 5 mins)</p>
|
<p>My own solution is to add a "filter" control in the header part of the form for each of the columns I want to be able to filter on (usually all ...). Each time such a "filter" control is updated, a procedure will run to update the active filter of the form, using the "BuildCriteria" function available in Access VBA.</p>
<p>Thus, When I type "<code>*cable*</code>" in the "filter" at the top of the Purchase Order Description column, the "WHERE PODescription IS LIKE "<code>*cable*</code>" is automatically added to the MyForm.filter property ....</p>
<p>Some would object that filtering record source made of multiple underlying tables can become very tricky. That's right. So the best solution is according to me to always (I mean it!) use a flat table or a view ("SELECT" query in Access) as a record source for a form. This will make your life a lot easier!</p>
<p>Once you're convinced of this, you can even think of a small module that will automate the addition of "filter" controls and related procedures to your forms. You'll be on the right way for a real user-friendly client interface. </p>
|
<p>For a question that vague, all that I can answer is open MS Access, and click the mouse a few times.</p>
<p>On second thought:<br>
Use the "WhereCondition" argument of the "OpenForm" method</p>
| 9,811
|
<p>I got an Anycubic Predator last month, and after resolving a few mechanical problems, I was able to get it printing decently well. The only significant modification I've made so far is a set of 8-diode TL Smoothers, and I'm now mostly operating it via Octoprint.</p>
<p>However, during the last few prints, I've noticed the temperature dropping midway through the print. It warms up and cools down fine, but for some reason it's not able to sustain the temperature throughout the print.</p>
<p><a href="https://i.stack.imgur.com/HoRn1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HoRn1.png" alt="temp graph"></a><br>
In this case, the print started out at the correct temperature (200 °C), held that temp for around 2 hours, then it dropped to a lower temp (174 °C). It eventually went back up to the target temp, then dropped again 5 minutes later. I tried manually adjusting it to see if that could fix it, but no luck.</p>
<p>After this print completed, I restarted it to show how it is easily able to reach the target temp and hold it at the <em>start</em> of the print:</p>
<p><a href="https://i.stack.imgur.com/cmQlC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cmQlC.png" alt="temp graph 2"></a></p>
<p>Any tips on diagnosing and resolving this issue?</p>
|
<h2>Safety First</h2>
<p>Let's look at the graphs. First: you should swap firmware for one that has <a href="https://3dprinting.stackexchange.com/questions/8466/what-is-thermal-runaway-protection">Thermal Runaway</a>, as, as it is, running about 15 minutes with 28 K less than the printer is ordered to work at is a clear indication that there is no Thermal runaway protection in place - it should have tripped over that long ago! But there is more!</p>
<h2>Problem</h2>
<p>But this graph and the lack of Thermal Runaway Protection also are typical for printers that have a design flaw: If the airflow from the part cooling fans or the coldend-cooling fan (that's the fan that always runs) brushes over the heater block, it cools it. This limits the achievable temperature.</p>
<p>Luckily, such is easily remedied in one of several ways:</p>
<ul>
<li>Changing the airducts for ones that does not hit the heater block</li>
<li>Adding a silicone sock around the heater block</li>
<li>Kapton-tape and ceramic wool can be used to make a heater-sock too</li>
<li>Adding an air-shield in the shape of a bit of tinfoil can redirect the airflow away from the heater block, but make positively sure it is mounted Fire-Safe and can't be lost into the print!</li>
</ul>
|
<p>The rise times are quicker than the fall times, which is not what I expected. Maybe a fan is turning on and off, but I'd expect to see the heater struggling to heat up. On both graphs, the rise times look like good heating and not much interference. </p>
<p>It seems to me that power to the hotend is the problem, but what can cause a drop in power but not to zero (as in the first graph)? Assuming that the file and the software are OK, then it's hardware: the MOSFET and the subsequent tracks and connections become the most likely suspects. So, I'd check all the connections between hotend and control board, even undoing and reconnecting. If you have a logging voltmeter, you could try that to see if the heater voltage changes when it shouldn't. If you have an oscilloscope, see the input pulses into the MOSFET to see if changes happen at the same time you see something weird with temperatures. MOSFETs can fail in peculiar ways, so consider replacement - it's not the cost of the MOSFET that's the issue; it's all the fiddling around to actually do it.</p>
| 1,560
|
<p>Does Python have a unit testing framework compatible with the standard xUnit style of test framework? If so, what is it, where is it, and is it any good?</p>
|
<p>Python has several testing frameworks, including <code>unittest</code>, <code>doctest</code>, and <code>nose</code>. The most xUnit-like is <code>unittest</code>, which is documented on Python.org.</p>
<ul>
<li><a href="https://docs.python.org/3/library/unittest.html" rel="nofollow noreferrer"><code>unittest</code> documentation</a></li>
<li><a href="https://docs.python.org/3/library/doctest.html" rel="nofollow noreferrer"><code>doctest</code> documentation</a></li>
</ul>
|
<p>There is also <a href="http://pyunit.sourceforge.net/" rel="nofollow noreferrer">PyUnit</a> which might be what you're looking for.</p>
| 5,726
|
<p>How to get a file's creation date or file size, for example this Hello.jpg at <a href="http://www.mywebsite.com/now/Hello.jpg(note" rel="nofollow noreferrer">http://www.mywebsite.com/now/Hello.jpg(note</a>: This URL does not exist)? The purpose of this question is to make my application re-download the files from the any website when it has detected that the website has an updated version of the files and the files in my local folder are out of date. Any ideas?</p>
|
<p>If you use the HEAD request it will send the headers for the resource, there you can check the cache control headers which will tell you if the resource has been modified, last modification time, size (content-length) and date. </p>
<pre><code>$ telnet www.google.com 80
Trying 216.239.59.103...
Connected to www.l.google.com.
Escape character is '^]'.
HEAD /intl/en_ALL/images/logo.gif HTTP/1.0
HTTP/1.0 200 OK
Content-Type: image/gif
Last-Modified: Wed, 07 Jun 2006 19:38:24 GMT
Expires: Sun, 17 Jan 2038 19:14:07 GMT
Cache-Control: public
Date: Tue, 16 Sep 2008 09:45:42 GMT
Server: gws
Content-Length: 8558
Connection: Close
Connection closed by foreign host.
</code></pre>
<p>Note that you'll probably have to decorate this basic and easy approach with many heuristics depending on the craziness of each webserver's admin, as each can send whatever headers they like. If they do not provide caching headers (Last-Modified, Expires, Cache-Control) nor Content-Length nor etag, you'd be stuck with redownloading it to test.</p>
|
<p>The webserver might send a last-modified and/or etag header for that purpose.
And you might send an if-modified-since header in your request.</p>
<p>see <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html" rel="nofollow noreferrer">http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html</a>
sections 14.19, 14.25 and 14.29</p>
| 9,627
|
<p>What is your favorite technique for launching a windbg user-mode remote debugging session?
Why is do you prefer this technique over other techniques? (pros/cons)</p>
<p>There are at least four different ways to do user-mode remote debug using windbg, as documented in the "Remote Debugging" section of the debugging tools for windows help file.</p>
<ol>
<li>run app on target then attach to it from the host windbg</li>
<li>have the host windbg use remote.exe to launch the app on the target</li>
<li>have the "smart client" host windbg launch the app on the target via a process server that is running on the target</li>
<li>run a windbg instance on the target machine using the option "-server" to automatically start a server, then connect to the server from a 2nd machine.</li>
</ol>
|
<p>There is no "the best" solution. Each of the possibilities has advantages and disadvantages and it's good to understand all of them. It depends on several factors like:</p>
<ul>
<li>where are the symbols located</li>
<li>which PC has access to the Internet to download the OS symbols</li>
<li>what amount of data may you copy to the server (clients often accept better if it's just a single Exe)</li>
<li>what's the bandwidth between client and server</li>
<li>do you need other commands that just CDB/WinDbg, e.g. access to CMD, then consider remote.exe</li>
<li>who's available on the server side, a debugging expert whom you can easily tell a lot of cryptic commands or a normal user who barely knows how to start a command prompt</li>
<li>are both sides in a private network, so you need a "man in the middle" server to be able to access each other (or port forwarding as an alternative, which IT guys don't want and it may take days to get it set up)</li>
</ul>
<p>From those 4 options, don't forget that clients often want to see exactly what you do, so they require an RDP session, Teamviewer or similar. That's something they understand.</p>
|
<p>Option 1 is my favourite because it is the simplest. I get to launch the app in the normal way without worry about getting WinDbg to set the right working directory, pass any command line arguments, etc.</p>
<p>Fortunately I've not run into any cases where this hasn't worked!</p>
| 7,620
|
<p>How do I call a function, using a string with the function's name? For example:</p>
<pre><code>import foo
func_name = "bar"
call(foo, func_name) # calls foo.bar()
</code></pre>
|
<p>Given a module <code>foo</code> with method <code>bar</code>:</p>
<pre><code>import foo
bar = getattr(foo, 'bar')
result = bar()
</code></pre>
<p><a href="https://docs.python.org/library/functions.html#getattr" rel="noreferrer"><code>getattr</code></a> can similarly be used on class instance bound methods, module-level methods, class methods... the list goes on.</p>
|
<p>This is a simple answer, this will allow you to clear the screen for example. There are two examples below, with eval and exec, that will print 0 at the top after cleaning (if you're using Windows, change <code>clear</code> to <code>cls</code>, Linux and Mac users leave as is for example) or just execute it, respectively.</p>
<pre><code>eval("os.system(\"clear\")")
exec("os.system(\"clear\")")
</code></pre>
| 2,522
|
<p>I have a webapp development problem that I've developed one solution for, but am trying to find other ideas that might get around some performance issues I'm seeing.</p>
<p>problem statement: </p>
<ul>
<li>a user enters several keywords/tokens</li>
<li>the application searches for matches to the tokens</li>
<li>need one result for each token
<ul>
<li>ie, if an entry has 3 tokens, i need the entry id 3 times</li>
</ul></li>
<li>rank the results
<ul>
<li>assign X points for token match</li>
<li>sort the entry ids based on points</li>
<li>if point values are the same, use date to sort results</li>
</ul></li>
</ul>
<p>What I want to be able to do, but have not figured out, is to send 1 query that returns something akin to the results of an in(), but returns a duplicate entry id for each token matches for each entry id checked.</p>
<p>Is there a better way to do this than what I'm doing, of using multiple, individual queries running one query per token? If so, what's the easiest way to implement those?</p>
<p><strong>edit</strong><br>
I've already tokenized the entries, so, for example, "see spot run" has an entry id of 1, and three tokens, 'see', 'spot', 'run', and those are in a separate token table, with entry ids relevant to them so the table might look like this:</p>
<pre><code>'see', 1
'spot', 1
'run', 1
'run', 2
'spot', 3
</code></pre>
|
<p>you could achive this in one query using 'UNION ALL' in MySQL.</p>
<p>Just loop through the tokens in PHP creating a UNION ALL for each token:</p>
<p>e.g if the tokens are 'x', 'y' and 'z' your query may look something like this</p>
<pre><code>SELECT * FROM `entries`
WHERE token like "%x%" union all
SELECT * FROM `entries`
WHERE token like "%y%" union all
SELECT * FROM `entries`
WHERE token like "%z%" ORDER BY score ect...
</code></pre>
<p>The order clause should operate on the entire result set as one, which is what you need.</p>
<p>In terms of performance it won't be all that fast (I'm guessing), however with databases the main overhead in terms of speed is often sending the query to the database engine from PHP and receiving the results. With this technique this only happens once instead of once per token, so performance will increase, I just don't know if it'll be enough.</p>
|
<p>You'll probably get much better performance if you used a data structure designed for search tasks rather than a database. For example, you might try looking at building an <a href="http://en.wikipedia.org/wiki/Inverted_index" rel="nofollow noreferrer">inverted index</a>. Rather than writing it youself, however, you might also want to look into something like <a href="http://en.wikipedia.org/wiki/Lucene" rel="nofollow noreferrer">Lucene</a> which does most of the work for you.</p>
| 7,002
|
<p>Is there any way to change Firefox system icon (the one on the left top of the window)? </p>
<p>Precision : I want to change the icon of a bundled version of Firefox with apache/php and my application. So manual operation on each computer is not a solution.
I try Resource Hacker and it's the good solution. The add ons one is good too.</p>
|
<p>Resource hacker does the job of swapping application icons in Windows (up to XP, not tested with Vista yet).</p>
<p>Available at:
<a href="http://www.angusj.com/resourcehacker/" rel="nofollow noreferrer">http://www.angusj.com/resourcehacker/</a></p>
|
<p>I think you mean the system icon, not the site icon as someone else thought. On a Mac, you can hold-Click -> Get Info on Firefox.app, then drag or paste an image on top of the icon.</p>
<p>I'm not sure about Windows, but I think you may need to compile from source to change it.</p>
| 8,966
|
<p>We are currently looking to adopt some type of "standard" developer framework and have looked into using the Enterprise Library. Would you recommend using these blocks as the foundation for software development, or should we do something <em>home grown</em>?</p>
|
<p>Like all good answers to architecture and programming questions, the answer is "it depends".</p>
<p>It depends on how unique your data access and object design needs are. It may also depend on how you plan on supporting your application in the long term. Finally, it greatly depends on the skill level of your developers.</p>
<p>There isn't a one-size-fits-all answer to this question, but generally, if your main focus is on cranking out software that provides some business value, pick out an existing framework and run with it. Don't spend your cycles building something that won't immediately drive business profits (i.e. increases revenues and/or decreases costs).</p>
<p>For example, one of my organization's projects is core to the operations of the company, needs to be developed and deployed as soon as possible, and will have a long life. For these reasons, we picked CSLA with some help from Enterprise Library. We could have picked other frameworks, but the important thing is that we picked a framework that seemed like it would fit well with our application and our developer skillset and we ran with it.</p>
<p>It gave us a good headstart and a community from which we can get support. We immediately started with functionality that provided business value and were not banging our heads against the wall trying to build a framework.</p>
<p>We are also in the position where we can hire people in the future who have most likely had exposure to our framework, giving them a really good headstart. This should reduce long-term support costs.</p>
<p>Are there things we don't use and overhead that we may not need? Perhaps. But, I'll trade that all day long for delivering business value in code early and often.</p>
|
<p>It really depends on what you need to do. Generally speaking, the bigger the niche is that your company is in, the better chance that you'll find a framework to properly support you. For smaller niches, you'll more than likely need to roll your own.</p>
<p>The company I work for has several apps all geared twoards estimating the building materials for given buildings. Since this is a pretty specific thing, and we have about 8 apps that are similar, we decided to roll our own and bring in 3rd party libraries when necessary (No sense re-inventing the wheel for some of the stuff)</p>
<p>Your millage may vary of course.</p>
| 7,647
|
<p>I'm currently working on putting together a fairly simple ORM tool to serve as a framework for various web projects for a client. Most of the projects are internal and will not require massive amounts of concurrency and all will go against SQL Server. I've suggested that they go with ORM tools like SubSonic, NHibernate, and a number of other open source projects out there, but for maintainability and flexibility reasons they want to create something custom. So my question is this: What are some features that I should make sure to include in this ORM tool? BTW, I'll be using MyGeneration to do the code generation templates.</p>
|
<p>For the love of all that's holy (and the women and the children), do everything possible to convince them not to go with a custom O/RM solution. Why are people wanting to re-invent the wheel when there are perfectly-good, open-source wheels already in existence?!?!</p>
|
<p>No-one has mentioned it yet; but go with <a href="http://www.llblgen.com/" rel="nofollow noreferrer">LLBLGen</a>. You may customise the template as you like, and you may also, obviously, write your own custom code in the generated classes. Buy it. You will never look back, and you will be saying "Thank you silky!" when it consistently works beautifully. (I didn't write it, but I love it). If it doesn't work out for you, you may also say "Damn you silky!". But that's unlikely, however I do offer it as an option.</p>
<p>The only bad thing I noticed about LLBLGen has been the support for switching between Databases/servers on the fly. It doesn't support a feature that I'd like; namely the ability to detect that a given entity you retrieved doesn't "exist" in a new database that you've switched to. But this is a rare case.</p>
<p>I suggest LLBLGen, because I was in the process of writing my own OR/M when I came across it. Never looked back.</p>
| 7,316
|
<p>How can you find out what are the long running queries are on Informix database server? I have a query that is using up the CPU and want to find out what the query is.</p>
|
<p>If the query is currently running watch the <strong>onstat -g act -r 1</strong> output and look for items with an <strong><em>rstcb</em></strong> that is not 0</p>
<pre><code>Running threads:
tid tcb rstcb prty status vp-class name
106 c0000000d4860950 0 2 running 107soc soctcppoll
107 c0000000d4881950 0 2 running 108soc soctcppoll
564457 c0000000d7f28250 c0000000d7afcf20 2 running 1cpu CDRD_10
</code></pre>
<p>In this example the third row is what is currently running. If you have multiple rows with non-zero rstcb values then watch for a bit looking for the one that is always or almost always there. That is most likely the session that your looking for.</p>
<p><strong>c0000000d7afcf20</strong> is the address that we're interested in for this example.</p>
<p>Use <strong>onstat -u | grep c0000000d7afcf20</strong> to find the session</p>
<pre><code>c0000000d7afcf20 Y--P--- 22887 informix - c0000000d5b0abd0 0 5 14060 3811
</code></pre>
<p>This gives you the session id which in our example is <strong>22887</strong>. Use <strong>onstat -g ses 22887</strong>
to list info about that session. In my example it's a system session so there's nothing to see in the onstat -g ses output.</p>
|
<pre><code>SELECT ELAPSED_TIME_MIN,SUBSTR(AUTHID,1,10) AS AUTH_ID,
AGENT_ID, APPL_STATUS,SUBSTR(STMT_TEXT,1,20) AS SQL_TEXT
FROM SYSIBMADM.LONG_RUNNING_SQL
WHERE ELAPSED_TIME_MIN > 0
ORDER BY ELAPSED_TIME_MIN DESC
</code></pre>
<p>Credit: <a href="http://it.toolbox.com/blogs/db2luw/sql-to-view-long-running-queries-13577" rel="nofollow noreferrer">SQL to View Long Running Queries </a></p>
| 7,426
|
<p>Is there some way I can use URLs like: </p>
<p><em><a href="http://www.blog.com/team-spirit/" rel="nofollow noreferrer">http://www.blog.com/team-spirit/</a></em></p>
<p>instead of</p>
<p><em><a href="http://www.blog.com/?p=122" rel="nofollow noreferrer">http://www.blog.com/?p=122</a></em></p>
<p>in a Windows hosted PHP server?</p>
|
<p>This is how I did it with WordPress on IIS 6.0</p>
<p><a href="http://www.coderjournal.com/2008/02/url-rewriter-reverse-proxy-iis-wordpress/" rel="nofollow noreferrer">http://www.coderjournal.com/2008/02/url-rewriter-reverse-proxy-iis-wordpress/</a></p>
<p>However it all depends on what version of IIS you are using. If you are lucky enough to use IIS 7.0 you don't really have to worry about pretty urls because everything is supported out of the box. However if you are using IIS 6.0 you are going to have to use a rewriter and some rules to force the IISness out of IIS.</p>
|
<p>We use the free version of <a href="http://www.isapirewrite.com/" rel="nofollow noreferrer">ISAPI_Rewrite</a>. It uses similar syntax to mod_rewrite, so if you're familiar with that you may have an easier time getting started.</p>
<p>There used to be a (syntax-compatible) port of mod_rewrite for IIS, but I can't find it now.</p>
| 5,252
|
<p>I know that the .NET framework looks for referenced DLLs in several locations</p>
<ul>
<li>Global assembly cache (GAC)</li>
<li>Any private paths added to the AppDomain</li>
<li>The current directory of the executing assembly</li>
</ul>
<p>What order are those locations searched? Is the search for a DLL ceased if a match is found or does it continue through all locations (and if so, how are conflicts resolved)?</p>
<p><em>Also, please confirm or deny those locations and provide any other locations I have failed to mention.</em></p>
|
<p>Assembly loading is a rather elaborate process which depends on lots of different factors like configuration files, publisher policies, appdomain settings, CLR hosts, partial or full assembly names, etc.</p>
<p>The simple version is that the GAC is first, then the private paths. %PATH% is never used.</p>
<p>It is best to use <a href="https://learn.microsoft.com/en-us/dotnet/framework/tools/fuslogvw-exe-assembly-binding-log-viewer" rel="nofollow noreferrer">Assembly Binding Log Viewer (Fuslogvw.exe)</a> to debug any assembly loading problems.</p>
<p><strong>EDIT</strong>
<a href="https://learn.microsoft.com/en-us/dotnet/framework/deployment/how-the-runtime-locates-assemblies" rel="nofollow noreferrer">How the Runtime Locates Assemblies</a> explains the process in more detail.</p>
|
<blockquote>
<p>No longer is the current directory searched first when loading DLLs! This change was also made in Windows XP SP1. The default behavior now is to look in all the system locations first, then the current directory, and finally any user-defined paths.</p>
</blockquote>
<p>(ref. <a href="http://weblogs.asp.net/pwilson/archive/2003/06/24/9214.aspx" rel="nofollow noreferrer">http://weblogs.asp.net/pwilson/archive/2003/06/24/9214.aspx</a>)</p>
<p>The default search order, which can be changed by the application, is also described on MSDN: <a href="https://learn.microsoft.com/en-gb/windows/win32/dlls/dynamic-link-library-search-order" rel="nofollow noreferrer">Dynamic-Link Library Search Order</a>.</p>
| 7,261
|
<p>I'd like to hear from people who are using distributed version control (aka distributed revision control, decentralized version control) and how they are finding it. What are you using, Mercurial, Darcs, Git, Bazaar? Are you still using it? If you've used client/server rcs in the past, are you finding it better, worse or just different? What could you tell me that would get me to jump on the bandwagon? Or jump off for that matter, I'd be interested to hear from people with negative experiences as well. </p>
<p>I'm currently looking at replacing our current source control system (Subversion) which is the impetus for this question.</p>
<p>I'd be especially interested in anyone who's used it with co-workers in other countries, where your machines may not be on at the same time, and your connection is very slow.</p>
<p>If you're not sure what distributed version control is, here are a couple articles:</p>
<p><a href="http://betterexplained.com/articles/intro-to-distributed-version-control-illustrated/" rel="nofollow noreferrer">Intro to Distributed Version Control</a></p>
<p><a href="http://en.wikipedia.org/wiki/Distributed_revision_control" rel="nofollow noreferrer">Wikipedia Entry</a></p>
|
<p>I've been using Mercurial both at work and in my own personal projects, and I am really happy with it. The advantages I see are:</p>
<ol>
<li><strong>Local version control.</strong> Sometimes I'm working on something, and I want to keep a version history on it, but I'm not ready to push it to the central repositories. With distributed VCS, I can just commit to my local repo until it's ready, without branching. That way, if other people make changes that I need, I can still get them and integrate them into my code. When I'm ready, I push it out to the servers.</li>
<li><strong>Fewer merge conflicts.</strong> They still happen, but they seem to be less frequent, and are less of a risk, because all the code is checked in to my local repo, so even if I botch the merge, I can always back up and do it again.</li>
<li><strong>Separate repos as branches.</strong> If I have a couple development vectors running at the same time, I can just make several clones of my repo and develop each feature independently. That way, if something gets scrapped or slipped, I don't have to pull pieces out. When they're ready to go, I just merge them together.</li>
<li><strong>Speed.</strong> Mercurial is much faster to work with, mostly because most of your common operations are local.</li>
</ol>
<p>Of course, like any new system, there was some pain during the transition. You have to think about version control differently than you did when you were using SVN, but overall I think it's very much worth it.</p>
|
<blockquote>
<p>Using Subversion</p>
</blockquote>
<p>Subversion isn't distributed, so that makes me think I need a wikipedia link in case people aren't sure what I'm talking about :)</p>
| 4,647
|
<p>I'm a student in software engineering in Montreal. For the last 3 years I've had a few interships (once per year). The first two (in the same company) were mostly sysadmin jobs, but I did get to do a few Perl programs (mostly log file analysing and statistics generation).</p>
<p>My other intership was in the IT security field. I did a huge CGI Perl script to analyse time spent by users on the Internet.</p>
<p>The thing is, what I really want to do is programming, but my interships were mostly sysadmins jobs with some programming (due to my previous experience with Linux and UNIX). </p>
<p>I have another internship this winter, however I would like it to be in the OO programming field, and SW engineering. </p>
<p>I have a background in system administration but I know OO quite well, due to my college courses and projects (C++, Java, VB.NET, ASP.NET, but not C# unfortunately :( ). </p>
<p>My question is this : how can compete, in interviews, having no previous work experience in the OO field (though I build some projects in Java, Swing, etc., and am learning JSP right now), with other students with OO experience in previous interships?</p>
<p>What should be my "selling points" ? I consider myself quite a good programmer, but my previous interviews didn't turn out well due to my lack of experience. In fact, I got an intership last winter in system administration, since, well... that's my background!</p>
<p>Any tips on how to convince a potential employer that I am the perfect candidate despite my lack of professional experience (but lots of personal knowledge (and interest)) ?</p>
<p>Thank you,</p>
<p>Guillaume.</p>
<p>[EDIT]</p>
<p>Thank you all for your support!</p>
<p>I'm not out of school yet ; I am still a full-time student! My university program is a cooperative one : I have to get 3 internships to get my diploma.</p>
<p>Let my explain briefly my background : this winter will be my 4th internship.</p>
<p>My first two were while I studied in CÉGEP, Quebec's post-high-school but pre-university schools.</p>
<p>The first one was pratically given to me by CÉGEP : a employer called in, searching for someone knowledgeable in Linux system administration. I fitted the job perfectly since I was the only student who knew Linux outside of school. My interview wasn't even a real one, since all the details had been discussed between my school and the employer : I knew that I was hired even before doing the interview.</p>
<p>The second one was in the same company, one year later, since I liked my first one very much.</p>
<p>Then I arrived at my university, where every student is required to have 3 internships to get his (or her) diploma. Having no real experience in computer science interviews (since my first internships were "given" to me), I did a few screw-ups when doing interviews for OO jobs. I finally managed to get an interview for a security / sysadmin / Perl programming job at Bombardier Aerospace. </p>
<p>My internship went well, but now I want a real software development job. All the people I know had one last winter, which mean I am disadvantaged in terms of experience.</p>
<p>However, I DO have programming experience. All my internship required me to do a substancial amount of programming, especially in Perl. My Perl skills are quite good, and I got to develop some nice tools for both companies I worked in. I solved real problems not seen in school (like how to parse efficiently 5 GB log files while keeping memory usage as low as possible).</p>
<p>Obviously, I can easily get an internship this winter if I apply on jobs in the sysadmin domain or Linux world. There are a few of them available each year and I've got a lot of experience in the field, but as stated previously, I would like my next internship to be in SW development.</p>
<p>I am currently working on a personal project in Java, which is a small UML class editor. So I get to deal with the Swing framework, listeners, MVC architecture, etc. This is not as big as what is being done in the "real world", but it a fun project and I am having a lot of fun doing it, and if I can get it quite advance in the next month, I will probably put in on SourceForge. In the same time I am learning JSP.</p>
<p>As for OO open source project, this is something I should be looking into. I probably won't have time for it right now, one month away from my first interviews, being a full-time student, but I am not putting this option away.</p>
<p>Anyway, thank you!</p>
|
<p>no offense, but from your description it would appear that you're not really qualified for a 'real' OO programming job. Academic classes are a good introduction to a language but no substitute for solving real problems with fluctuating deadlines, finicky users, cholicky managers, et al ;-)</p>
<p>this leaves three options:</p>
<ol>
<li><p>join an open-source project that uses OO and a language you know, and contribute to it significantly. This will provide an analogue of real programming experience [but not real job experience] and <em>may</em> help you get a programming job in another year or two</p></li>
<li><p>or, apply for an entry-level OO programming job and impress the heck out of the interviewer with your communication skills, contagious enthusiasm, eagerness to learn, commitment to the customer/user/whatever, etc. In other words, present and sell yourself truthfully but as the 'complete package' needing only the opportunity to explode.</p>
<ul>
<li>Don't be discouraged if you get turned down a lot</li>
<li>don't apply for jobs you don't really want</li>
<li>expect to stay in the job for at least a year if not two or three, to really learn how to program in a non-academic environment</li>
</ul></li>
<li><p>start your own business as a consultant, programmer, freelance, and/or develop products, and learn at your own pace. This is risky when out of school, less risky when in school, and if you happen on an unoccupied niche can be quite lucrative</p></li>
</ol>
|
<p>Contribute patches to some <a href="http://search.cpan.org" rel="nofollow noreferrer">CPAN</a> distribution. This will show that you: 1) use CPAN - managers love peoples that can write code faster 2) can read and modify someones code.</p>
<p>Study <a href="http://search.cpan.org/dist/Moose" rel="nofollow noreferrer">Moose</a>/<a href="http://search.cpan.org/dist/Mouse" rel="nofollow noreferrer">Mouse</a> - it is modern OO system for Perl, it is much better that old OO system that was copied from Python.</p>
| 9,404
|
<p>Has anyone encountered this oddity?</p>
<p>I'm checking for the existence of a number of directories in one of my unit tests. <code>is_dir</code> is reporting true (1) in spite of the folder not existing at the time it is called. The code looks like this (with a few extraneous intermediate vars to ease debugging):</p>
<pre><code>foreach($userfolders as $uf) {
$uf = sprintf($uf, $user_id);
$uf = ltrim($uf,'/');
$path = trim($base . '/' . $uf);
$res = is_dir($path); //returns false except last time returns 1
$this->assertFalse($res, $path);
}
</code></pre>
<p>The machine running Ubuntu Linux 8.04 with PHP Version 5.2.4-2ubuntu5.3</p>
<p>Things I have checked:</p>
<pre><code> - Paths are full paths
- The same thing happens on two separate machines (both running Ubuntu)
- I have stepped through line by line in a debugger
- Paths genuinely don't exist at the point where is_dir is called
- While the code is paused on this line, I can actually drop to a shell and run
</code></pre>
<p>the interactive PHP interpreter and get the correct result
- The paths are all WELL under 256 chars
- I can't imagine a permissions problem as the folder doesn't exist! The parent folder can't be causing permissions problems as the other folders in the loop are correctly reported as missing.</p>
<p>Comments on the PHP docs point to the odd issue with <code>is_dir</code> but not this particular one.</p>
<p>I'm not posting this as a "please help me fix" but in the hope that somebody encountering the same thing can search here and <em>hopefully</em> an answer from somebody else who has seen this!</p>
|
<p>I don't think this would cause your problem, but $path does have the trailing slash, correct?</p>
|
<pre><code>$path = trim($base . '/' . $uf);
</code></pre>
<p>That could be causing it. I'm assuming $base is some sort of root folder you are searching, so if $uf is something like '', '.', or '../' that could return true. We would have to see what values you are using in your foreach to know anything further.</p>
<p>[EDIT]</p>
<p>Doing some more looking the above code works fine on OpenBSD 4.3 with PHP 5.2. </p>
| 7,597
|
<p>I thought I am not bad at Google, but simply I am unable to find a G-code for doing circular motion for nozzle cleaning. It is possible to write a simple circular motion in G-code?</p>
|
<p>To draw a circle, you need to approximate the circle as a sufficient number of line segments. This requires computing or using a table of sine and cosine values for each angle step. Then you just emit a sequence of <code>G1</code> commands.</p>
<p>Some printer firmware also supports arc drawing commands you could use instead in principle, but support is not widespread, and the quality of the results varies enough that I would not recommend trying to do it this way.</p>
|
<p>While many 3D printers support using G2 and G3 for circles and arcs, most people are not used to them because the STL files consist entirely of flat triangles (straight lines).</p>
<p>If you want a simple 2D circle, see the following for help:</p>
<p><a href="https://marlinfw.org/docs/gcode/G002-G003.html" rel="nofollow noreferrer">https://marlinfw.org/docs/gcode/G002-G003.html</a></p>
<p><a href="https://makezine.com/2016/10/24/get-to-know-your-cnc-how-to-read-g-code/" rel="nofollow noreferrer">https://makezine.com/2016/10/24/get-to-know-your-cnc-how-to-read-g-code/</a></p>
<p><a href="https://reprap.org/wiki/G-code#G2_.26_G3:_Controlled_Arc_Move" rel="nofollow noreferrer">https://reprap.org/wiki/G-code#G2_.26_G3:_Controlled_Arc_Move</a></p>
<p>Note: it can take a while to get used to the I and J parameters.</p>
| 2,056
|
<p>While cross-site scripting is generally regarded as negative, I've run into several situations where it's necessary.</p>
<p>I was recently working within the confines of a very limiting content management system. I needed to include database code within the page, but the hosting server didn't have anything usable available. I set up a couple bare-bones scripts on my own server, originally thinking that I could use AJAX to import the contents of my scripts directly into the template of the CMS (thus retaining dynamic images, menu items, CSS, etc.). I was wrong.</p>
<p>Due to the limitations of <code>XMLHttpRequest</code> objects, it's not possible to grab content from a different domain. So I thought <em>iFrame</em> - even though I'm not a fan of frames, I thought that I could create a frame that matched the width and height of the content so that it would appear native. Again, I was blocked by cross-site scripting "protections." While I could indeed load a remote file into the <em>iFrame</em>, I couldn't execute JavaScript to modify its size on either the host page or inside the loaded page.</p>
<p>In this particular scenario, I wasn't able to point a subdomain to my server. <strong>I also couldn't create a script on the CMS server that could proxy content from my server, so my last thought was to use a remote JavaScript.</strong></p>
<p>A remote JavaScript works. It breaks when the user has JavaScript disabled, which is a downside; but it works. The "problem" I was having with using a remote JavaScript was that I had to use the JS function <code>document.write()</code> to output any content. Any output that isn't JS causes script errors. In addition to using <code>document.write()</code> for every line, you also have to ensure that the content is escaped - or else you end up with more script errors.</p>
<p>My solution was as follows:</p>
<p>My script received a GET parameter ("page") and then looked for the file (<code>{$page}.php</code>), and read the contents into a variable. However, I had to use awkward buffering techniques in order to actually execute the included scripts (for things like database interaction) then strip the final content of all line break characters (<code>\n</code>) followed by escaping all required characters. The end result is that my original script (which outputs JavaScript) accesses seemingly "standard" scripts on my server and converts their standard output to JavaScript for displaying within the CMS template.</p>
<p>While this solution works, it seems like there may be a better way to accomplish the same thing. What is the best way to make cross-site scripting work specifically for the purpose of including content from a completely different domain?</p>
|
<p>You've got three choices:</p>
<ol>
<li>Create a <a href="http://developer.yahoo.com/javascript/howto-proxy.html" rel="noreferrer">server side proxy script</a>.</li>
<li><p>Create a remote script to read in remote dynamic HTML. Use a library like <a href="http://www.jquery.com" rel="noreferrer">jQuery</a> to make this easier. You can use the <a href="http://docs.jquery.com/Ajax/load" rel="noreferrer">load function</a> to inject HTML where needed. <strong>EDIT</strong> What I originally meant for example # 2 was utilizing <a href="http://en.wikipedia.org/wiki/JSON#JSONP" rel="noreferrer">JSONP</a>, which requires the server side script to recognize the "callback=?" param.</p></li>
<li><p>Use a <a href="http://www.adobe.com/devnet/flash/articles/external_interface.html" rel="noreferrer">client side Flash proxy</a> and setup a <a href="http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_14213" rel="noreferrer">crossdomain.xml</a> file on your server's web root.</p></li>
</ol>
|
<p>I've come across that <a href="http://developer.yahoo.com/javascript/howto-proxy.html" rel="nofollow noreferrer">YDN server side proxy script</a> before. It says it's built to work with Yahoo's Search APIs. </p>
<p>Will it work with any domain, if you simply trim the Yahoo API code out? Or do you need to replace it with the domain you want it to work with?</p>
| 7,588
|
<p>I have modified my Prusa i3 MK2 printer so that the existing extruder motor has now been attached to a 5mm lead screw with a 1mm pitch. What is the easiest way to control the extruding of the printer now.</p>
<p>For example is it possible to change the settings in slic3er at all for the extruder? or would I have to download and edit the marlin firmware?</p>
|
<p>The firmware of the printer reads the g-code, in this instance, for z-axis movement. The g-code provides only (primarily) millimeters of movement and direction, along with speed.</p>
<p>The firmware reads those figures, figuratively speaking, and knows from the values stored in the firmware, how many steps to rotate the motor, in what direction and at what rate.</p>
<p>I suppose if you were a glutton for punishment, you could write some code to convert the existing measurements to ones that are adjusted for the new screw, but that's just crazy. Imagine that your new screw provides for 3.729 times the movement that the old screw did per unit of rotation. You'd have to find all the z-movements in the code and apply that factor to those numbers. I suspect rounding errors might make for a less-than-satisfactory print.</p>
<p>As you've mentioned in your question about editing the firmware, one may expect that you have an idea what is involved. If not, that may be the topic of another post.</p>
|
<p>You can set the 'steps per mm' for the extruder (and the other axes) by sending GCODE to the printer, and store this in the internal memory. Re-flashing the firmware only affects the 'factory reset' configuration of the printer parameters.</p>
<p>To see how to calibrate your extruder, you're probably best looking for videos since although the process is just a few GCODE commands, the whole process is not easy to understand.</p>
| 835
|
<p>Can't get to my site. Apache gives the following error message: </p>
<blockquote>
<p>[Fri Sep 05 08:47:42 2008] [error] (OS 10060)A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. : proxy: HTTP: attempt to connect to 10.10.10.1:80 (10.10.10.1) failed</p>
</blockquote>
|
<p>Can you connect to the proxied host (10.10.10.1) directly? Is it functioning normally?</p>
|
<p><a href="http://www.checkupdown.com/status/E503.html" rel="nofollow noreferrer">http://www.checkupdown.com/status/E503.html</a></p>
<blockquote>
<p>Your Web server is effectively 'closed for repair'. It is still functioning minimally because it can at least respond with a 503 status code, but full service is impossible i.e. your Web site is simply unavailable. There are a myriad possible reasons for this, but generally it is because of some human intervention by the operators of your Web server machine. You can usually expect that someone is working on the problem, and normal service will resume as soon as possible.</p>
</blockquote>
<p>You need to restart the webserver then figure out why it shut it self down.</p>
| 6,774
|
<p><code>celsius = (5.0/9.0) * (fahr-32.0);</code></p>
<p>Is it just a development choice that the C developers decided upon or is there a reason to this? I believe a float is smaller than a double, so it might be to prevent overflows caused by not knowing what decimal format to use. Is that the reason, or am I overlooking something?</p>
|
<pre><code>celsius = (5.0/9.0) * (fahr-32.0);
</code></pre>
<p>In this expression, <code>5.0</code>, <code>9.0</code>, and <code>32.0</code> are <code>double</code>s. That's the default type for a floating-point constant - if you wanted them to be <code>float</code>s, then you would use the <code>F</code> suffix:</p>
<pre><code>celsius = (5.0F/9.0F) * (fahr-32.0F);
</code></pre>
<p>Note that if <code>fahr</code> was a <code>double</code>, then the result of this last expression would <em>still</em> be a <code>double</code>: as Vaibhav noted, types are promoted in such a way as to avoid potentially losing precision.</p>
|
<p>Floating point constants should have the available highest precision. The result can be assigned to a float without undue trouble.</p>
| 5,912
|
<p>Have been trying out the new Dynamic Data site create tool that shipped with .NET 3.5. The tool uses LINQ Datasources to get the data from the database using a .dmbl context file for a reference. I am interseted in customizing a data grid but I need to show data from more than one table. Does anyone know how to do this using the LINQ Datasource object?</p>
|
<p>If the tables are connected by a foreign key, you can easily reference both tables as they will be joined by linq automatically (you can see easily if you look in your dbml and there is an arrow connecting the tables) - if not, see if you can add one.</p>
<p>To do that, you can just use something like this:</p>
<pre><code><%# Bind("unit1.unit_name") %>
</code></pre>
<p>Where in the table, 'unit' has a foreign key that references another table and you pull that 'unit's property of 'unit_name'</p>
<p>I hope that makes sense.</p>
|
<p>You cannot put more than one object/datasource on a datagrid. You will have to build a single ConceptObject that combines the exposed properties of the part Entities. Try to use DB -> L2S Entities -> ConceptObject. You must be very contrived if the DB model matches the ConceptObject field-for-field.</p>
| 9,175
|
<p>The current system that I am working on makes use of Castle Activerecord to provide ORM (Object Relational Mapping) between the Domain objects and the database. This is all well and good and at most times actually works well!</p>
<p>The problem comes about with Castle Activerecords support for asynchronous execution, well, more specifically the SessionScope that manages the session that objects belong to. Long story short, bad stuff happens!</p>
<p>We are therefore looking for a way to easily convert (think automagically) from the Domain objects (who know that a DB exists and care) to the DTO object (who know nothing about the DB and care not for sessions, mapping attributes or all thing ORM).</p>
<p>Does anyone have suggestions on doing this. For the start I am looking for a basic One to One mapping of object. Domain object <strong>Person</strong> will be mapped to say <strong>PersonDTO</strong>. I do not want to do this manually since it is a waste.</p>
<p>Obviously reflection comes to mind, but I am hoping with some of the better IT knowledge floating around this site that <em>"cooler"</em> will be suggested.</p>
<p>Oh, I am working in C#, the ORM objects as said before a mapped with Castle ActiveRecord.</p>
<hr>
<h2>Example code:</h2>
<p>By @ajmastrean's request I have <a href="http://www.fryhard.com/downloads/stackoverflow/ActiveRecordAsync.zip" rel="noreferrer">linked</a> to an example that I have (badly) mocked together. The example has a <strong>capture form</strong>, capture form <strong>controller</strong>, <strong>domain</strong> objects, activerecord <strong>repository</strong> and an <strong>async</strong> helper. It is slightly big (3MB) because I included the ActiveRecored dll's needed to get it running. You will need to create a database called <em>ActiveRecordAsync</em> on your local machine or just change the .config file.</p>
<p>Basic details of example:</p>
<p><strong>The Capture Form</strong></p>
<p>The capture form has a reference to the contoller</p>
<pre><code>private CompanyCaptureController MyController { get; set; }
</code></pre>
<p>On initialise of the form it calls MyController.Load()
private void InitForm ()
{
MyController = new CompanyCaptureController(this);
MyController.Load();
}
This will return back to a method called LoadComplete()</p>
<pre><code>public void LoadCompleted (Company loadCompany)
{
_context.Post(delegate
{
CurrentItem = loadCompany;
bindingSource.DataSource = CurrentItem;
bindingSource.ResetCurrentItem();
//TOTO: This line will thow the exception since the session scope used to fetch loadCompany is now gone.
grdEmployees.DataSource = loadCompany.Employees;
}, null);
}
}
</code></pre>
<p>this is where the <em>"bad stuff"</em> occurs, since we are using the child list of Company that is set as Lazy load.</p>
<p><strong>The Controller</strong></p>
<p>The controller has a Load method that was called from the form, it then calls the Asyc helper to asynchronously call the LoadCompany method and then return to the Capture form's LoadComplete method.</p>
<pre><code>public void Load ()
{
new AsyncListLoad<Company>().BeginLoad(LoadCompany, Form.LoadCompleted);
}
</code></pre>
<p>The LoadCompany() method simply makes use of the Repository to find a know company.</p>
<pre><code>public Company LoadCompany()
{
return ActiveRecordRepository<Company>.Find(Setup.company.Identifier);
}
</code></pre>
<p>The rest of the example is rather generic, it has two domain classes which inherit from a base class, a setup file to instert some data and the repository to provide the <strong>ActiveRecordMediator</strong> abilities.</p>
|
<p>I solved a problem very similar to this where I copied the data out of a lot of older web service contracts into WCF data contracts. I created a number of methods that had signatures like this:</p>
<pre><code>public static T ChangeType<S, T>(this S source) where T : class, new()
</code></pre>
<p>The first time this method (or any of the other overloads) executes for two types, it looks at the properties of each type, and decides which ones exist in both based on name and type. It takes this 'member intersection' and uses the DynamicMethod class to emil the IL to copy the source type to the target type, then it caches the resulting delegate in a threadsafe static dictionary.</p>
<p>Once the delegate is created, it's obscenely fast and I have provided other overloads to pass in a delegate to copy over properties that don't match the intersection criteria:</p>
<pre><code>public static T ChangeType<S, T>(this S source, Action<S, T> additionalOperations) where T : class, new()
</code></pre>
<p>... so you could do this for your Person to PersonDTO example:</p>
<pre><code>Person p = new Person( /* set whatever */);
PersonDTO = p.ChangeType<Person, PersonDTO>();
</code></pre>
<p>And any properties on both Person and PersonDTO (again, that have the same name and type) would be copied by a runtime emitted method and any subsequent calls would not have to be emitted, but would reuse the same emitted code <em>for those types in that order</em> (i.e. copying PersonDTO to Person would also incur a hit to emit the code).</p>
<p>It's too much code to post, but if you are interested I will make the effort to upload a sample to SkyDrive and post the link here.</p>
<p>Richard</p>
|
<p>My apologies for not really putting the details in here, but a basic OO approach would be to make the DTO a member of the ActiveRecord class and have the ActiveRecord delegate the accessors and mutators to the DTO. You could use code generation or refactoring tools to build the DTO classes pretty quickly from the AcitveRecord classes. </p>
| 6,296
|
<p>It is slow to load anything other than a small project. It is slow to quit; it can sometimes take minutes. It can be slow to open new files. The record macro feature used to be useful. It is now so slow to start up it's almost always quicker to do it manually!</p>
<hr>
<blockquote>
<p>More info would be helpful. How big are your solutions? What platform are you on. What 3rd party plugins are you running? What else is running on your pc? </p>
</blockquote>
<p>3.2GHz P4 Hyperthreaded, 2GB RAM. Running Outlook, Perforce, IE7, directory browsers. Usually have 1-3 instances of VS running. It's much slower than VC6, say. It seems to take a long time to load projects and close down. I'm interested in if people know reasons why this happens, because of the way VS is written. Is it using .net internally and GC slows it down?</p>
|
<p>it might be that you have a plugin that is misbehaving. Try the <a href="http://msdn.microsoft.com/en-us/library/xee0c8y7(VS.80).aspx" rel="nofollow noreferrer">safemode</a> switch to see if this improves performance </p>
|
<p>here's ya problem:</p>
<blockquote>
<p>3.2GHz P4 Hyperthreaded, 2GB RAM</p>
</blockquote>
<p>Hypertheaded means "doesn't actually have two CPU's, but it fakes it". If you have a process with just one thread running, then you get bad performance. It was a good short-term measure, but compared to having two REAL CPU's, it's a slow hack.</p>
<p>2GB of RAM would be an issue too, based on what you said you run. If you have a basic 5400RPM disk, then it's going to make it all worse.</p>
<p>I'd recommend, based on what you posted:</p>
<ul>
<li>A good core2 machine, maybe a quad if you have the budget.</li>
<li>3GB of ram if you are running a 32bit OS, 4+GB if you are running x64. 4GB means you waste 1GB under 32bit.</li>
<li>Get 7200RPM disks, or better. If you can, RAID0 them (stripe) or RAID0+1 (stripe+mirror) if you can get 4 drives (stripe == split content over the two disks, so you can read from both at the same time. stripe+mirror == the safe version of striping, so your code is on TWO disks at all times) </li>
</ul>
<p>I have a 2.0ghz Core2 (so roughly 3-4x the performance of your P4, if you count 2 CPU's(cores) to be 2x) with 2GB, and the most I can run well is 2 instances of VS.NET 2008. This is normal - nothing wrong with VS.NET, it's just a huge app.</p>
<p>More RAM. More CPU. More Screen. More. More. More :)</p>
| 6,513
|
<p>I have an Asset object that has a property AssignedSoftware, which is a collection. </p>
<p>I want to make sure that the same piece of Software is not assigned to an Asset more than once. In Add method I check to see if the Software already exist, and if it does, I want to throw an exception. </p>
<p>Is there a standard .NET exception that I should be throwing? Or does best practices dictate I create my own custom exception?</p>
|
<p>From the Class Library design guidelines for errors (<a href="http://msdn.microsoft.com/en-us/library/8ey5ey87(VS.71).aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/8ey5ey87(VS.71).aspx</a>):</p>
<blockquote>
<p>In most cases, use the predefined exception types. Only define new exception types for programmatic scenarios, where you expect users of your class library to catch exceptions of this new type and perform a programmatic action based on the exception type itself. This is in lieu of parsing the exception string, which would negatively impact performance and maintenance.</p>
<p>...</p>
<p>Throw an ArgumentException or create an exception derived from this class if invalid parameters are passed or detected.</p>
<p>Throw the InvalidOperationException exception if a call to a property set accessor or method is not appropriate given the object's current state.</p>
</blockquote>
<p>This seems like an "Object state invalid" scenario to me, so I'd pick InvalidOperationException over ArgumentException: The parameters are valid, but not at this point in the objects life.</p>
|
<p>Well, if you really want an collection with unique items, you might want to take a look at the <a href="http://msdn.microsoft.com/en-us/library/bb359438.aspx" rel="nofollow noreferrer">HashSet object</a> (available in C# 3.0).</p>
<p>Otherwise, there are two approaches that you can take:</p>
<ul>
<li>Create a custom exception for your operation, just as you had stated</li>
<li>Implement an Add() method that returns a boolean result: true if the item is added and false if the item already has a duplicate in the collection</li>
</ul>
<p>Either approach can be considered best practice, just as long as you are consistent in its use.</p>
| 7,840
|
<p>I have a Mini Kossel and I am going through calibration.</p>
<p>I can home carriages and find the bed with paper-test getting some Z value with <code>M114</code>. Then I run the effector almost full height <strong>up and then down</strong> - and now <strong>Z value for the bed is greater</strong>!</p>
<p>If I repeat the process I get greater and greater values in paper-test. It seems that travel per step is different moving in different directions.</p>
<p>How can I fix that? I am using RAMPS 1.4 with Marlin firmware.</p>
<p>UPDATE:</p>
<p>Z values near bed after subsequent runs of five passes of <code>G1 X100 G1 X10</code></p>
<pre><code>100% speed: 0.1 0.3 0.5 0.7 1.0
20% speed: 0.1 0.4 0.9 1.4 4.6 6.6
300% speed: 0.0 0.7 1.0 1.3
</code></pre>
|
<p>After some more testing I checked that the problem shows up only on Z tower and is not related with current. Examining the tower I found very dumb mistake. Pulley on the motor didn't have a setscrew! Don't know how could I missed that. The fact that it could somehow run is even more amazing. Thanks @tom-van-der-zanden and @darthpixel for help. It is for sure that such synchronization failure could have been caused by current shortage as well.</p>
<p>UPDATE:</p>
<p>Oh! Y tower pulley doesn't have setscrew as well! But it was running smoothly and in sync with X (which has that screw). Amazing. - UPDATE2. Not really. After closer look only Z tower misses the screw, which explains all.</p>
<p>UPDATE3:</p>
<p>After setting a srew into pulley the problem is completely gone!)</p>
|
<p>According to discussions in comments, I'm pretty sure the problem lies in too low current. </p>
<p>Please review <a href="https://3dprinting.stackexchange.com/questions/1480/how-do-you-make-sure-you-have-the-right-voltage-on-the-timpots-on-a-a4988-steppe/1483#1483">this answer</a> to <a href="https://3dprinting.stackexchange.com/questions/1480/how-do-you-make-sure-you-have-the-right-voltage-on-the-timpots-on-a-a4988-steppe/">How do you make sure you have the right voltage on the trimpots on a A4988 stepper driver?</a>.</p>
<p><strong>Why it happens?</strong></p>
<p>If there is not enough current then motors can omit some steps as the stress is not equal while going up and down. Sometimes inertia can have higher influence than friction.</p>
<p>Additionally because the resistance/stress/friction on towers is different for sure then there are some issues in centering hotend.</p>
<p>So friction/inertia/assembly inaccuracy and current settings inaccuracy can cause such effects. If you are "on the edge" your printer may work well one day but the other day it can fail positioning. </p>
<p>Please refer to post mentioned above. Perform calibration and temperature test (finger test could be ok). I hope you'll manage the issue.</p>
| 371
|
<p>In coding a traditional MVC application, what is the best practice for coding server-side form validations? Does the code belong in the controller, or the model layer? And why?</p>
|
<p>From Wikipedia:</p>
<blockquote>
<p><a href="http://en.wikipedia.org/wiki/Model_View_Controller" rel="nofollow noreferrer">Model-view-controller</a> (MVC) is an architectural pattern used in software engineering. Successful use of the pattern isolates business logic from user interface considerations, resulting in an application where it is easier to modify either the visual appearance of the application or the underlying business rules without affecting the other. In MVC, the model represents the information (the data) of the application and the business rules used to manipulate the data; the view corresponds to elements of the user interface such as text, checkbox items, and so forth; and the controller manages details involving the communication to the model of user actions such as keystrokes and mouse movements.</p>
</blockquote>
<p>Thus, model - it holds the application and the business rules.</p>
|
<p>My experience with MVC thus far consists of entirely rails.</p>
<p>Rails does it's validation 100% in the Model.<br>
For the most part this works very well. I'd say 9 out of 10 times it's all you need.</p>
<p>There are some areas however where what you're submitting from a form doesn't match up with your model properly. There may be some additional filtering/rearranging or so on.</p>
<p>The best way to solve these situations I've found is to create faux-model objects, which basically act like Model objects but map 1-to-1 with the form data. These faux-model objects don't actually save anything, they're just a bucket for the data with validations attached.<br>
An example of such a thing (in rails) is <a href="http://www.realityforge.org/articles/2005/12/02/validations-for-non-activerecord-model-objects" rel="nofollow noreferrer">ActiveForm</a></p>
<p>Once the data gets into those (and is valid) it's usually a pretty simple step to transfer it directly across to your actual models.</p>
| 4,530
|
<p>I have a table in an access table which contains Product entries, one of the columns has a jpg image stored as an OLE Object. I am trying to import this table to MySQL but nothing seems to work. I have tried the MySQL migration tool but that has a known issue with Access and OLE Objects. (The issue being it doesnt work and leaves the fields blank) I also tried the suggestion on <a href="http://www.plus2net.com/sql_tutorial/access_to_mysql.php" rel="nofollow noreferrer">this site</a>
and while the data is imported it seems as though the image is getting corrupted in the transfer. When i try to preview the image i just get a binary view, if i save it on disk as a jpg image and try to open it i get an error stating the image is corrupt.</p>
<p>The images in Access are fine and can be previewed. Access is storing the data as an OLE Object and when i import it to MySql it is saved in a MediumBlob field.</p>
<p>Has anyone had this issue before and how did they resolve it ?</p>
|
<p>Ok so in the interests of airing my dirty code in public here what i came up with.<br>
Note : this is a hack designed to be used once and then thrown away.</p>
<p>This Method takes in a datarowview containing 1 row of data from the access table. The Images are wrapped in OLE serialization, im not entirely familiar with how this works but its how Microsoft apps allow any object to be embedded into something else. (eg images into Excel Cells). I needed to remove the serialization junk around the image so i loaded the entire field as a Byte array and searched through it for 3 concurrent entries (FF D8 FF) which represent the beginning of the image data within the field.</p>
<pre><code> Private Function GetImageFromRow(ByRef row As DataRowView, ByVal columnName As String) As Bitmap
Dim oImage As Bitmap = New Bitmap("c:\default.jpg")
Try
If Not IsDBNull(row(columnName)) Then
If row(columnName) IsNot Nothing Then
Dim mStream As New System.IO.MemoryStream(CType(row(columnName), Byte()))
If mStream.Length > 0 Then
Dim b(Convert.ToInt32(mStream.Length - 1)) As Byte
mStream.Read(b, 0, Convert.ToInt32(mStream.Length - 1))
Dim position As Integer = 0
For index As Integer = 0 To b.Length - 3
If b(index) = &HFF And b(index + 1) = &HD8 And b(index + 2) = &HFF Then
position = index
Exit For
End If
Next
If position > 0 Then
Dim jpgStream As New System.IO.MemoryStream(b, position, b.Length - position)
oImage = New Bitmap(jpgStream)
End If
End If
End If
End If
Catch ex As Exception
Throw New ApplicationException(ex.Message, ex)
End Try
Return oImage
End Function
</code></pre>
<p>Then its a matter of pulling out this data into a bitmap. So for each row in the access table i extract the bitmap and then update the corresponding MySQL entry.<br>
It worked fine but im guessing i could have removed the serialisation stuff in a better way, perhaps theres an API to do it.</p>
|
<p>There's also <a href="https://github.com/shamrin/olefield" rel="nofollow">olefield</a> - Python module to extract data out of OLE object fields in Access. I successfully extracted BMP files with it. It could probably work with jpeg images, but I haven't tried it.</p>
| 6,293
|
<p>Recently our site has been deluged with the resurgence of the <a href="https://en.wikipedia.org/wiki/Asprox_botnet" rel="noreferrer">Asprox botnet</a> <a href="http://en.wikipedia.org/wiki/SQL_injection" rel="noreferrer">SQL injection</a> attack. Without going into details, the attack attempts to execute SQL code by encoding the <a href="http://en.wikipedia.org/wiki/Transact-SQL" rel="noreferrer">T-SQL</a> commands in an ASCII encoded BINARY string. It looks something like this:</p>
<pre><code>DECLARE%20@S%20NVARCHAR(4000);SET%20@S=CAST(0x44004500...06F007200%20AS%20NVARCHAR(4000));EXEC(@S);--
</code></pre>
<p>I was able to decode this in SQL, but I was a little wary of doing this since I didn't know exactly what was happening at the time.</p>
<p>I tried to write a simple decode tool, so I could decode this type of text without even touching <a href="http://en.wikipedia.org/wiki/Microsoft_SQL_Server" rel="noreferrer">SQL Server</a>. The main part I need to be decoded is:</p>
<pre><code>CAST(0x44004500...06F007200 AS
NVARCHAR(4000))
</code></pre>
<p>I've tried all of the following commands with no luck:</p>
<pre><code>txtDecodedText.Text =
System.Web.HttpUtility.UrlDecode(txtURLText.Text);
txtDecodedText.Text =
Encoding.ASCII.GetString(Encoding.ASCII.GetBytes(txtURLText.Text));
txtDecodedText.Text =
Encoding.Unicode.GetString(Encoding.Unicode.GetBytes(txtURLText.Text));
txtDecodedText.Text =
Encoding.ASCII.GetString(Encoding.Unicode.GetBytes(txtURLText.Text));
txtDecodedText.Text =
Encoding.Unicode.GetString(Convert.FromBase64String(txtURLText.Text));
</code></pre>
<p>What is the proper way to translate this encoding without using SQL Server? Is it possible? I'll take VB.NET code since I'm familiar with that too.</p>
<hr>
<p>Okay, I'm sure I'm missing something here, so here's where I'm at.</p>
<p>Since my input is a basic string, I started with just a snippet of the encoded portion - 4445434C41 (which translates to DECLA) - and the first attempt was to do this...</p>
<pre><code>txtDecodedText.Text = Encoding.UTF8.GetString(Encoding.UTF8.GetBytes(txtURL.Text));
</code></pre>
<p>...and all it did was return the exact same thing that I put in since it converted each character into is a byte.</p>
<p>I realized that I need to parse every two characters into a byte manually since I don't know of any methods yet that will do that, so now my little decoder looks something like this:</p>
<pre><code>while (!boolIsDone)
{
bytURLChar = byte.Parse(txtURLText.Text.Substring(intParseIndex, 2));
bytURL[intURLIndex] = bytURLChar;
intParseIndex += 2;
intURLIndex++;
if (txtURLText.Text.Length - intParseIndex < 2)
{
boolIsDone = true;
}
}
txtDecodedText.Text = Encoding.UTF8.GetString(bytURL);
</code></pre>
<p>Things look good for the first couple of pairs, but then the loop balks when it gets to the "4C" pair and says that the string is in the incorrect format.</p>
<p>Interestingly enough, when I step through the debugger and to the GetString method on the byte array that I was able to parse up to that point, I get ",-+" as the result.</p>
<p>How do I figure out what I'm missing - do I need to do a "direct cast" for each byte instead of attempting to parse it?</p>
|
<p>I went back to Michael's post, did some more poking and realized that I did need to do a double conversion, and eventually worked out this little nugget:</p>
<pre><code>Convert.ToString(Convert.ToChar(Int32.Parse(EncodedString.Substring(intParseIndex, 2), System.Globalization.NumberStyles.HexNumber)));
</code></pre>
<p>From there I simply made a loop to go through all the characters 2 by 2 and get them "hexified" and then translated to a string.</p>
<p>To Nick, and anybody else interested, I went ahead and <a href="http://www.codeplex.com/urldecoder" rel="nofollow noreferrer">posted my little application</a> over in <a href="http://en.wikipedia.org/wiki/CodePlex" rel="nofollow noreferrer">CodePlex</a>. Feel free to use/modify as you need.</p>
|
<p>Try removing the <code>0x</code> first and then call <code>Encoding.UTF8.GetString</code>. I think that may work.</p>
<p>Essentially: 0x44004500</p>
<p>Remove the 0x, and then always two bytes are one character:</p>
<pre><code>44 00 = D
45 00 = E
6F 00 = o
72 00 = r
</code></pre>
<p>So it's definitely a Unicode/UTF format with two bytes/character.</p>
| 2,256
|
<p>I've been using <a href="https://web.archive.org/web/20200229173754/http://tortoisesvn.tigris.org/" rel="noreferrer">TortoiseSVN </a> in a Windows environment for quite some time. It seems very feature-complete and nicely integrated into the Windows shell, and more importantly, it's fairly painless to teach to colleagues with little or no experience with source control. <strong>However</strong>, since we have moved to Windows Vista 64bit, Tortoise has been very buggy and has seemed to cause lots of explorer.exe abnormalities and crashes. This has happened both with older versions of the software and the latest version (1.5.1 build 13563).</p>
<p>I was curious if anyone has suggestions for other Subversion clients that will run on Windows (specifically Vista 64bit). Developers here use a variety of text editors so using Visual Studio or Dreamweaver for SVN is not ideal.</p>
<p>I have heard great things about <a href="http://www.zennaware.com/cornerstone/" rel="noreferrer">Cornerstone</a>, and would love something similar for Windows if it exists.</p>
<hr>
<p>I'm correlating the Vista/explorer problems with Tortoise because they normally occur when I'm using the functionality in Tortoise. Sometimes bringing up the "merge" screen will cause the GUI to start acting very strange and eventually hang or crash.</p>
<p>I did not see 1.5.2 -- I'm installing now, maybe that will fix some of my issues.</p>
|
<p>I have been using the 64Bit version of TortoiseSVN for ages and I have never had issues with it on Windows 64Bit or Vista 64Bit. I am currently not aware of any other similiar SVN clients that do work on Vista. Is it possible the problem could lie within the configuration of TortoiseSVN or even the installation of Vista? Is the problem occurring on Vista native or SP 1?</p>
|
<p>I'll second Diago's answer. I use TortoiseSVN on Vista x64 pretty heavily.</p>
<p>I did upgrade directly from an older version to 1.5.2 though, and never used 1.5.1. Have you tried 1.5.2?</p>
| 2,255
|
<p>When I try to precompile a *.pc file that contains a #warning directive I recieve the following error:</p>
<blockquote>
<p>PCC-S-02014, Encountered the symbol "warning" when expecting one of the following: (bla bla bla).</p>
</blockquote>
<p>Can I somehow convince Pro*C to ignore the thing if it doesn't know what to do with it? I can't remove the <code>#warning</code> directive as it's used in a header file that I can't change and must include.</p>
|
<p>According to the <em>Pro*C/C++ Programmer's Guide</em> (chapter 5 "Advanced Topics"), Pro*C silently ignores a number of preprocessor directives including #error and #pragma, but sadly not #warning. Since your warning directives are included in a header file, you might be able to use the ORA_PROC macro:</p>
<pre><code>#ifndef ORA_PROC
#include <irrelevant.h>
#endif
</code></pre>
<p>For some reason, Pro*C errors out if you try to hide a straight #warning that way, however. </p>
|
<p>Remove below two lines from /usr/include/standards.h</p>
<h1>warning The -qdfp option is required to process DFP code in headers.</h1>
<h1>else</h1>
| 3,549
|
<p>I'm developing a website. I'm using a single-page web-app style, so all of the different parts of the site are AJAX'd into index.php. When a user logs in and tells Firefox to remember his username and password, all input boxes on the site get auto-filled with that username and password. This is a problem on the form to change a password. How can i prevent Firefox from automatically filling out these fields? I already tried giving them different names and ids.</p>
<p>Edit: <a href="https://stackoverflow.com/questions/32369/disable-browser-save-password-functionality">Someone has already asked this</a>. Thanks Joel Coohorn.</p>
|
<p>From Mozilla's documentation </p>
<pre><code><form name="form1" id="form1" method="post" autocomplete="off"
action="http://www.example.com/form.cgi">
[...]
</form>
</code></pre>
<p><a href="http://developer.mozilla.org/en/How_to_Turn_Off_Form_Autocompletion" rel="noreferrer">http://developer.mozilla.org/en/How_to_Turn_Off_Form_Autocompletion</a></p>
|
<p>are all your input boxes set to type=password? That would do it. One of the things you can do, and I'm not at all sure that this is the best answer is to leave input box as an input type and just use javascript and onkeydown event to place stars in the input box instead of having the browser render it. Firefox won't pre-fill that.</p>
<p>As an aside, I have had to work on single-page web-apps and I absolutely hate it. Why would you want to take away the user's ability to bookmark pages? To use the back button?</p>
| 7,307
|
<p>Tomcat fails to start even if i remove all my applications from the WEBAPPS directory leaving everything just like after the OS installation.</p>
<p>The log (catalina.out) says:</p>
<pre><code>Using CATALINA_BASE: /usr/share/tomcat5
Using CATALINA_HOME: /usr/share/tomcat5
Using CATALINA_TMPDIR: /usr/share/tomcat5/temp
Using JRE_HOME:
Created MBeanServer with ID: -dpv07y:fl4s82vl.0:hydrogenium.timberlinecolorado.com:1
java.lang.NoClassDefFoundError: org.apache.catalina.core.StandardService
at java.lang.Class.initializeClass(libgcj.so.7rh)
at java.lang.Class.initializeClass(libgcj.so.7rh)
at java.lang.Class.initializeClass(libgcj.so.7rh)
at java.lang.Class.newInstance(libgcj.so.7rh)
at org.apache.catalina.startup.Bootstrap.init(bootstrap.jar.so)
at org.apache.catalina.startup.Bootstrap.main(bootstrap.jar.so)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.modeler.Registry not found in org.apache.catalina.loader.StandardClassLoader{urls=[file:/var/lib/tomcat5/server/classes/,file:/usr/share/java/tomcat5/catalina-cluster-5.5.23.jar,file:/usr/share/java/tomcat5/catalina-storeconfig-5.5.23.jar,file:/usr/share/java/tomcat5/catalina-optional-5.5.23.jar,file:/usr/share/java/tomcat5/tomcat-coyote-5.5.23.jar,file:/usr/share/java/tomcat5/tomcat-jkstatus-ant-5.5.23.jar,file:/usr/share/java/tomcat5/tomcat-ajp-5.5.23.jar,file:/usr/share/java/tomcat5/servlets-default-5.5.23.jar,file:/usr/share/java/tomcat5/servlets-invoker-5.5.23.jar,file:/usr/share/java/tomcat5/catalina-ant-jmx-5.5.23.jar,file:/usr/share/java/tomcat5/tomcat-http-5.5.23.jar,file:/usr/share/java/tomcat5/tomcat-util-5.5.23.jar,file:/usr/share/java/tomcat5/tomcat-apr-5.5.23.jar,file:/usr/share/eclipse/plugins/org.eclipse.jdt.core_3.2.1.v_677_R32x.jar,file:/usr/share/java/tomcat5/servlets-webdav-5.5.23.jar,file:/usr/share/java/tomcat5/catalina-5.5.23.jar], parent=org.apache.catalina.loader.StandardClassLoader{urls=[file:/var/lib/tomcat5/common/classes/,file:/var/lib/tomcat5/common/i18n/tomcat-i18n-ja.jar,file:/var/lib/tomcat5/common/i18n/tomcat-i18n-fr.jar,file:/var/lib/tomcat5/common/i18n/tomcat-i18n-en.jar,file:/var/lib/tomcat5/common/i18n/tomcat-i18n-es.jar,file:/usr/share/java/tomcat5/naming-resources-5.5.23.jar,file:/usr/share/eclipse/plugins/org.eclipse.jdt.core_3.2.1.v_677_R32x.jar,file:/usr/share/java/tomcat5/naming-factory-5.5.23.jar], parent=gnu.gcj.runtime.SystemClassLoader{urls=[file:/usr/lib/jvm/java/lib/tools.jar,file:/usr/share/tomcat5/bin/bootstrap.jar,file:/usr/share/tomcat5/bin/commons-logging-api.jar,file:/usr/share/java/mx4j/mx4j-impl.jar,file:/usr/share/java/mx4j/mx4j-jmx.jar], parent=gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}}}
at java.net.URLClassLoader.findClass(libgcj.so.7rh)
at java.lang.ClassLoader.loadClass(libgcj.so.7rh)
at java.lang.ClassLoader.loadClass(libgcj.so.7rh)
at java.lang.Class.initializeClass(libgcj.so.7rh)
...5 more
</code></pre>
|
<p>Seems like you've implemented a JMX service and tried to install it on your server.xml file but forgot to add the apache commons modeler jar to the server/lib directory (therefore the <code>ClassNotFoundException</code> for <code>org.apache.commons.modeler.Registry</code>). Check your server.xml file for anything you might have added, and try to add the proper jar file to your server classpath.</p>
|
<p>This screams class path issue, to me. Where exactly is your tomcat installed? (Give us command line printouts of where the home directory is.) Also, how are you starting it?</p>
| 8,788
|
<p>What are the differences, and pros & cons, between 3D printers with varying layouts for moving head vs. moving build plate?</p>
<p>Example layouts would include:</p>
<ul>
<li>X Head; YZ Bed; </li>
<li>XY Head; Z Bed; </li>
<li>XYZ Head; </li>
<li>etc.</li>
</ul>
<p>In particular, what are their respective strengths, weaknesses, specializations, maintenance considerations, etc.?</p>
|
<p>Without going into too much detail, since this is a very exhaustive topic, I'll write some pro's of each down from the top of my head:</p>
<p>Cartesian XZ hotend, Y bed (eg. Prusa Mendel):</p>
<ul>
<li>easy to build (relatively)</li>
<li>easy to maintain</li>
<li>easy to modify</li>
<li>understandable kinematics</li>
<li>with the right frame, no x-y-z orthogonality (90 degree angles) needs to be adjusted</li>
<li>affordable</li>
<li>bad for timelapse recordings</li>
<li>print quality will theoretically always be inferior at the same speeds and accelerations to kinematics that have less mass to move (heavy printbeds will lead to ghosting)</li>
<li>z-wobble is only existent in this approach</li>
<li>big build-plates are no option for this design (last feasible size might be 20x30 cm)</li>
</ul>
<p>Cartesian XY hotend, Z bed (core-XY, sparkcube, Ultimaker, Makerbot)</p>
<ul>
<li>less mass to be moved -> faster print speeds possible</li>
<li>almost no size limitaions</li>
<li>construction is easy to enclose in most models due to the cubic frame</li>
<li>looks almost always professional</li>
<li>enclosure can be hard to modify due to constraints in space</li>
</ul>
<p>XYZ hotend (Delta bots)</p>
<ul>
<li>master of circles</li>
<li>less mass to be moved -> faster print speeds possible</li>
<li>impressive to watch</li>
<li>more load on the processing unit due to more complicated kinematics (32 bit needed for fast print speeds and responsive control with display)</li>
<li>kinematics not easily understandable</li>
<li>error-cause search can be very complicated</li>
<li>more accurate in the center than on the outer limits due to the kinematic approach</li>
</ul>
<p>The list is for sure not complete, and as a major disclaimer: print quality will always, with every approach, depend more on the setup and calibration of the printer than on the model. There are people around that produce great prints from an acrylic frame cartesian printer and lots of people that produce mediocre results with expensive printers in fancy designs.</p>
<p>I will add some links to the list items when I find the time, for now you have to believe me. I am highly appreciating corrections and additions!</p>
|
<p>I think this is simple, breaking it into simple parts... It is much easier to calibrate a machine where each axis does one thing. For instance, the Ultimaker; one of the few XY-on-the-same-axis printers... It has such a crazy complicated pulley system. If one thing gets out of whack, everything will start binding. Thankfully this doesn't happen as they did a good job, but it comes at a price. All the double pulleys and double rods - that costs money.</p>
<p>However if you break it into smaller bits then less will go wrong. </p>
<p>When I upgraded my MendelMax 1.5 to use a PBC linear solid slide for the X axis, it instantly solved all my issues with the rods binding (two rods into one big slide).</p>
<p>To quote my coworker,</p>
<blockquote>
<p>It's like balancing a stool. Is it easier to balance a 4 legged stool or a 3?</p>
</blockquote>
<p>Following from that, there is probably a good hour's worth of mechanical engineering information that can be said in regards to the linear motion itself. I would rather calibrate one axis at at time, and not worry about weird behavior caused by a XYZ head.</p>
| 319
|
<p>Is there a programmatic way to build <em>htpasswd</em> files, without depending on OS specific functions (i.e. <code>exec()</code>, <code>passthru()</code>)?</p>
|
<p>.httpasswd files are just text files with a specific format depending on the hash function specified. If you are using MD5 they look like this:</p>
<pre><code>foo:$apr1$y1cXxW5l$3vapv2yyCXaYz8zGoXj241
</code></pre>
<p>That's the login, a colon, ,$apr1$, the salt and 1000 times md5 encoded as base64. If you select SHA1 they look like this:</p>
<pre><code>foo:{SHA}BW6v589SIg3i3zaEW47RcMZ+I+M=
</code></pre>
<p>That's the login, a colon, the string {SHA} and the SHA1 hash encoded with base64.</p>
<p>If your language has an implementation of either MD5 or SHA1 and base64 you can just create the file like this:</p>
<pre><code><?php
$login = 'foo';
$pass = 'pass';
$hash = base64_encode(sha1($pass, true));
$contents = $login . ':{SHA}' . $hash;
file_put_contents('.htpasswd', $contents);
?>
</code></pre>
<p>Here's more information on the format:</p>
<p><a href="http://httpd.apache.org/docs/2.2/misc/password_encryptions.html" rel="noreferrer">http://httpd.apache.org/docs/2.2/misc/password_encryptions.html</a></p>
|
<p><a href="http://trac.edgewall.org" rel="nofollow noreferrer">Trac</a> ships with a Python replacement for htpasswd, which I'm sure you could port to your language of choice: <a href="http://trac.edgewall.org/browser/trunk/contrib/htpasswd.py" rel="nofollow noreferrer">htpasswd.py</a>.</p>
| 6,111
|
<p>When sockets are created or files are opened/created in C, is the file descriptor that's assigned to the socket/file guaranteed to be the lowest-valued descriptor available? What does the C spec say about file descriptor assignment in this regard, if anything?</p>
|
<p>It's not guaranteed to be the lowest, and is implementation dependent <em>(1)</em>. In general, however, the routine that assigns open file descriptors uses a method that gives you the first open on. It could be that immediately after several lower ones free, leaving you with a higher descriptor than you might expect though.</p>
<p>The only reason I can think of to know this, though, is for the select function, which is sped up if you pass it the highest file descriptor you need to check for.</p>
<p><em>(1)</em> Note that those implementations that follow the IEEE standard do guarantee the lowest unused descriptor for files, but this may not apply to sockets. Not every implementation follows the IEEE standard for open(), so if you're writing portable software it is best not to depend on it.</p>
|
<p>Steve M is right; C has no notion of sockets, and its file I/O functions use a [pointer to a] FILE object, not a descriptor.</p>
| 7,479
|
<p>I need to display an error message on rejecting a drop in my application.</p>
<p>I tried this in the <code>OnDrop()</code> but then the source application hangs until my message box is dismissed.</p>
<p>How can I do that?</p>
|
<p>You can always call PostMessage with a private message in the WM_APP range and in the message handler show the error.</p>
<p>That way you show the error after the drag and drop operation is really over and there is no danger of messing up anything.</p>
|
<p>You're right. But all the data I need to report in the message box is in the OnDrop.</p>
| 7,164
|
<p>We were offered to <a href="https://3dprinting.meta.stackexchange.com/questions/314/can-we-get-mathjax-enabled">get MathJax enabled</a>.</p>
<p>Now, we need to decide on which character to have text between them parsed into MathJax! So please either add your suggestion or cast your vote!</p>
|
<p>Let's stay with the classic $.</p>
<p>Example: \$\$\frac{1 \times 2}{2} = 1\$\$</p>
<hr>
<p><em>Now that MathJax is enabled, it renders to:
$$\frac{1 \times 2}{2} = 1$$</em></p>
|
<p>An alternative character could be the Tilde <code>~</code>.</p>
| 59
|
<p>I have a console app that needs to display the state of items, but rather than having text scroll by like mad I'd rather see the current status keep showing up on the same lines. For the sake of example:</p>
<blockquote>
<p><code>Running... nn% complete</code><br>
<code>Buffer size: bbbb bytes</code></p>
</blockquote>
<p>should be the output, where 'nn' is the current percentage complete, and 'bbbb' is a buffer size, updated periodically on the same lines of the console.</p>
<p>The first approach I took simply printed the correct number of backspaces to the console before printing the new state, but this has an obnoxious flicker that I want to get rid of. I also want to stick to either standard library or MS-provided functionality (VC 8) so as not to introduce another dependency for this one simple need.</p>
|
<p>You can use <a href="http://msdn.microsoft.com/en-us/library/ms686025.aspx" rel="noreferrer">SetConsoleCursorPosition</a>. You'll need to call <a href="http://msdn.microsoft.com/en-us/library/ms683231.aspx" rel="noreferrer">GetStdHandle</a> to get a handle to the output buffer.</p>
|
<p>In Linux, you can accomplish this by printing \b and/or \r to stderr. You might need to experiment to find the right combination of things in Windows.</p>
| 6,713
|
<p>For a science project, I'm 3D-printing some custom pipes and tubes to regulate the flow of gas (a combination of ethyl alcohol and water vapor) through an apparatus. They need to be pretty small, as the entire experiment is designed on a small scale. I'd also like the use a little filament as possible.</p>
<p>How thin can I make the walls of these pipes and tubes before either they collapse or gas leaks out? I know that's possibly an engineering issue, but I'd also need to take resolution into consideration. Ideally, the pipes would be about two centimeters in diameter, possibly a little larger or a little smaller in some parts. I'd most likely use ABS, but PLA is my backup in case there's some unforeseen reaction between the gas and the pipes.</p>
<p>The printer I'm using is an FDM printer, a version of the MakerBot Replicator.</p>
|
<p>The thinnest wall your printer can print is determined by its nozzle size, and will be a little thicker than that nozzle size.</p>
<p>A great challenge when dealing with thin, hollow cylinders is that the cross-section has very little surface area and it can delaminate easily, especially if the tube is long.</p>
<p>You could try printing the tube with a very thick extrusion with, and using only a single perimeter. That would give better gas-tightness and layer adhesion than two, thinner perimeters, but it may turn out too fragile for your application. In that case, you'll need to print additional perimeters. Sticking to thicker extrusion widths would still be beneficial.</p>
<p>At a two centimeter diameter I'd say the single perimeter has a decent chance of working if you handle them gingerly.</p>
|
<p>This is difficult to give a definitive answer, but I have some thoughts.</p>
<p>For a vertical wall, the minimum thickness is determined by your nozzle size, typically 0.4mm. If you are able to print entirely in a vertical orientation (a pipe standing on end), you may consider using "vase mode" with no top or bottom to print. This can help simplify the CAD modeling, as you don't have to model the hollow interior and wall thickness.</p>
<p>For a horizontal wall, in theory this could be a single layer height, about 0.1mm depending on the printer and settings. Realistically, you will probably need 2 to 4 layers to get something "solid". However, this is not likely to have good results for a hollow pipe due to performance of the printer in bridging and overhangs. A thin, round pipe laying on its side is not likely to be successfully printable.</p>
<p>For printing in a horizontal orientation, I'd recommend a non-circular shape; the specific shape would depend on your overall design and goals. A "teardrop" or "flat teardrop shape can help with horizontal holes through parts.</p>
<p>Also, rather than individual pipes, perhaps you could design a block with hollow passages. This could allow thicker walls, make it much stronger, reduce assembly needs, allow for extremely complex routing and internal connections, and may even allow for functional parts like valves or sensors to be installed.</p>
<p>Finally, I would not expect an FDM-printed part to be airtight. There will most likely be some small gaps between layers and where layers start and stop. As an example, I tried making an ice mold, but almost all the water seeped through before it froze.</p>
<p>Another poster recommended an acetone vapor bath, which should help seal any pores. This only works with ABS. Another idea might be to coat the inner surfaces of the pipes with a resin that can seal everything up.</p>
| 135
|
<p>This is a question I asked on another forum which received some decent answers, but I wanted to see if anyone here has more insight.</p>
<p>The problem is that you have one of your pages in a web application timing out when it gets to a stored procedure call, so you use Sql Profiler, or your application trace logs, to find the query and you paste it into management studio to figure our why it's running slow. But you run it from there and it just blazes along, returning in less than a second each time.</p>
<p>My particular case was using ASP.NET 2.0 and Sql Server 2005, but I think the problem could apply to any RDBMS system.</p>
|
<p>This is what I've learned so far from my research.</p>
<p>.NET sends in connection settings that are not the same as what you get when you log in to management studio. Here is what you see if you sniff the connection with Sql Profiler:</p>
<pre><code>-- network protocol: TCP/IP
set quoted_identifier off
set arithabort off
set numeric_roundabort off
set ansi_warnings on
set ansi_padding on
set ansi_nulls off
set concat_null_yields_null on
set cursor_close_on_commit off
set implicit_transactions off
set language us_english
set dateformat mdy
set datefirst 7
set transaction isolation level read committed
</code></pre>
<p>I am now pasting those setting in above every query that I run when logged in to sql server, to make sure the settings are the same.</p>
<p>For this case, I tried each setting individually, after disconnecting and reconnecting, and found that changing arithabort from off to on reduced the problem query from 90 seconds to 1 second.</p>
<p>The most probable explanation is related to parameter sniffing, which is a technique Sql Server uses to pick what it thinks is the most effective query plan. When you change one of the connection settings, the query optimizer might choose a different plan, and in this case, it apparently chose a bad one.</p>
<p>But I'm not totally convinced of this. I have tried comparing the actual query plans after changing this setting and I have yet to see the diff show any changes.</p>
<p>Is there something else about the arithabort setting that might cause a query to run slowly in some cases?</p>
<p>The solution seemed simple: Just put set arithabort on into the top of the stored procedure. But this could lead to the opposite problem: change the query parameters and suddenly it runs faster with 'off' than 'on'. </p>
<p>For the time being I am running the procedure 'with recompile' to make sure the plan gets regenerated each time. It's Ok for this particular report, since it takes maybe a second to recompile, and this isn't too noticeable on a report that takes 1-10 seconds to return (it's a monster).</p>
<p>But it's not an option for other queries that run much more frequently and need to return as quickly as possible, in just a few milliseconds.</p>
|
<p>Try changing the SelectCommand timeout value:</p>
<pre><code>DataAdapter.SelectCommand.CommandTimeout = 120;
</code></pre>
| 3,127
|
<p><strong>Update:</strong> Check out this follow-up question: <a href="https://stackoverflow.com/questions/134581/gem-update-on-windows-is-it-broken"><strong>Gem Update on Windows - is it broken?</strong></a></p>
<hr>
<p>On Windows, when I do this:</p>
<pre><code>gem install sqlite3-ruby
</code></pre>
<p>I get the following error:</p>
<pre><code>Building native extensions. This could take a while...
ERROR: Error installing sqlite3-ruby:
ERROR: Failed to build gem native extension.
c:/ruby/bin/ruby.exe extconf.rb install sqlite3-ruby --platform Win32
checking for fdatasync() in rt.lib... no
checking for sqlite3.h... no
nmake
'nmake' is not recognized as an internal or external command,
operable program or batch file.
Gem files will remain installed in c:/ruby/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.4 for inspection.
Results logged to c:/ruby/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.4/ext/sqlite3_api/gem_make.out
</code></pre>
<p><strong>Same thing happens with the hpricot gem</strong>. I seem to remember these gems installed just fine on < 1.0 gems, but now I'm on 1.2.0, things have gone screwy.</p>
<p>I have also tried this:</p>
<pre><code>gem install sqlite3-ruby --platform Win32
</code></pre>
<p>Needless to say, this doesn't work either (same error)</p>
<p>Does anyone know what is going on here and how to fix this?</p>
<hr>
<p><strong>Update:</strong> Check out this follow-up question: <a href="https://stackoverflow.com/questions/134581/gem-update-on-windows-is-it-broken"><strong>Gem Update on Windows - is it broken?</strong></a></p>
|
<p>As Nathan suggests, this does appear to be related to the fact that the latest versions of the sqlite3-ruby and hpricot gems don't appear to have Windows versions. Here's what to do when faced with this situation (note, the name of the gem is automatically wildcarded, so you can type just <em>sql</em> and get a list of all gems beginning with <em>sql</em>):</p>
<pre><code>$ gem list --remote --all sqlite
*** REMOTE GEMS ***
sqlite (2.0.1, 2.0.0, 1.3.1, 1.3.0, 1.2.9.1, 1.2.0, 1.1.3, 1.1.2, 1.1.1, 1.1)
sqlite-ruby (2.2.3, 2.2.2, 2.2.1, 2.2.0, 2.1.0, 2.0.3, 2.0.2)
sqlite3-ruby (1.2.4, 1.2.3, 1.2.2, 1.2.1, 1.2.0, 1.1.0, 1.0.1, 1.0.0, 0.9.0, 0.6.0, 0.5.0)
</code></pre>
<p>Then you can choose the version you would like to install:</p>
<pre><code>gem install sqlite3-ruby -v 1.2.3
</code></pre>
<p>To successfully install hpricot, I did this:</p>
<pre><code>gem install hpricot -v 0.6
</code></pre>
<p>Annoyingly, doing a <strong><code>gem update</code></strong> tries to update the gems to their latest, broken-on-Windows, versions. When the update routine encounters an error, it ditches you out of the whole process. There's a (hacky) solution to this problem <strong><a href="https://stackoverflow.com/questions/134581/gem-update-on-windows-is-it-broken">here</a></strong>.</p>
<p><strong>So, is this issue a bug in gems? Should gems not automatically detect the platform and install the latest compatible version?</strong></p>
|
<p>I also ran into this problem. It's worth knowing that the difference between 1.2.3 and 1.2.4 is not significant. Here are the 1.2.4. release notes:</p>
<blockquote>
<p><strong>Release Name: 1.2.4</strong></p>
<p>Notes: This release only updates the
generated C file to reflect the
compatibility changes that were made
to the SWIG file. Binary builds (e.g.,
Windows) are not affected, and need no
update. In general, you will not need
this update unless you are using a
version of Ruby prior to 1.8.6.
(source: <a href="http://rubyforge.org/frs/shownotes.php?release_id=25302" rel="nofollow noreferrer" title="rubforge release notes on 1.2.4">1.2.4. release notes</a>)</p>
</blockquote>
<p>Hope that helps others!</p>
| 6,537
|
<p>How do I convert the value of a PHP variable to string?</p>
<p>I was looking for something better than concatenating with an empty string:</p>
<pre><code>$myText = $myVar . '';
</code></pre>
<p>Like the <code>ToString()</code> method in Java or .NET.</p>
|
<p>You can use the <a href="http://us3.php.net/manual/en/language.types.type-juggling.php" rel="noreferrer">casting operators</a>:</p>
<pre><code>$myText = (string)$myVar;
</code></pre>
<p>There are more details for string casting and conversion in the <a href="http://us3.php.net/manual/en/language.types.string.php#language.types.string.casting" rel="noreferrer">Strings section</a> of the PHP manual, including special handling for booleans and nulls.</p>
|
<p>I use <a href="https://github.com/lingtalfi/VariableToString" rel="nofollow noreferrer">variableToString</a>. It handles every PHP type and is flexible (you can extend it if you want).</p>
| 4,775
|
<p>When a script is saved as a bundle, it can use the <code>localized string</code> command to find the appropriate string, e.g. in <code>Contents/Resources/English.lproj/Localizable.strings</code>. If this is a format string, what is the best way to fill in the placeholders? In other words, what is the AppleScript equivalent of <code>+[NSString stringWithFormat:]</code>?</p>
<p>One idea I had was to use <code>do shell script</code> with <code>printf(1)</code>. Is there a better way?</p>
|
<p><a href="https://developer.apple.com/library/content/releasenotes/AppleScript/RN-AppleScript/RN-10_10/RN-10_10.html" rel="nofollow noreferrer">Since OS X 10.10</a>, it’s been possible for any AppleScript script to use Objective-C. There are a few ways to call Objective-C methods from within AppleScript, as detailed in <a href="https://developer.apple.com/library/content/documentation/LanguagesUtilities/Conceptual/MacAutomationScriptingGuide/AppendixA-AppleScriptObjCQuickTranslationGuide.html" rel="nofollow noreferrer">this translation guide</a>. An Objective-C developer like me would gravitate toward this syntax, which interpolates the method's parameters with their values:</p>
<pre><code>use framework "Foundation"
tell the current application's NSWorkspace's sharedWorkspace to openFile:"/Users/me/Desktop/filter.png" withApplication:"Preview"
</code></pre>
<p>Result:</p>
<pre><code>true
</code></pre>
<p><code>+[NSString stringWithFormat:]</code> is a tricky case. It takes a vararg list as its first parameter, so you need some way to force both the format string and its arguments into the same method parameter. The following results in an error, because AppleScript ends up passing a single NSArray into the parameter that expects, conceptually, a C array of NSStrings:</p>
<pre><code>use framework "Foundation"
the current application's NSString's stringWithFormat:{"%lu documents", 8}
</code></pre>
<p>Result:</p>
<pre><code>error "-[__NSArrayM length]: unrecognized selector sent to instance 0x7fd8d59f3bf0" number -10000
</code></pre>
<p>Instead, you have to use an alternative syntax that looks more like an AppleScript handler call than an Objective-C message. You also need to coerce the return value (an NSString object) into a <code>text</code>:</p>
<pre><code>use framework "Foundation"
the current application's NSString's stringWithFormat_("%lu documents", 8) as text
</code></pre>
<p>Result:</p>
<pre><code>"2087 documents"
</code></pre>
<p>The “with parameters” syntax that @nlanza mentions points to the fact that AppleScript is using something akin to <a href="https://developer.apple.com/reference/foundation/nsinvocation" rel="nofollow noreferrer">NSInvocation</a> under the hood. In Objective-C, NSInvocation allows you to send a message to an object, along with an array of parameter values, without necessarily matching each value to a particular parameter. (See <a href="http://theocacao.com/document.page/264" rel="nofollow noreferrer">this article</a> for some examples of using NSInvocation directly.)</p>
|
<p>As ugly as it is, calling out to <code>printf(1)</code> is the common solution.</p>
<p>A cleaner, though somewhat more complex, solution is to use AppleScript Studio, which allows you to call into Objective-C objects/classes from your AppleScript code with the <code>call method</code> syntax documented <a href="http://developer.apple.com/documentation/AppleScript/Conceptual/StudioBuildingApps/chapter04/chapter_4_section_2.html#//apple_ref/doc/uid/20001251-TPXREF175" rel="nofollow noreferrer">here</a>.</p>
<p>With that, you'd be able to use something like this:</p>
<pre><code>call method "stringWithFormat:" of class "NSString" with parameters {formatString, arguments}
</code></pre>
<p>The downside of this, of course, is that you need to write an AppleScript Studio app instead of just writing a simple script. You do get a good bit more flexibility in general with Studio apps, though, so it's not all together a terrible route to go.</p>
| 8,963
|
<p>On linux, it's possible to create a tun interface using a tun driver which provides a "network interface psuedo-device" that can be treated as a regular network interface. Is there a way to do this programmatically on windows? Is there a way to do this without writing my own driver? </p>
|
<p>You can do this on XP with the <a href="https://web.archive.org/web/20150217152013/http://support.microsoft.com/kb/839013" rel="nofollow noreferrer">Microsoft Loopback Adapter</a> which is a driver for a virtual network card.</p>
<p>On newer Windows version: <a href="https://support.microsoft.com/en-gb/help/2777200/installing-the-microsoft-loopback-adapter-in-windows-8-and-windows-ser" rel="nofollow noreferrer">Installing the Microsoft Loopback Adapter in Windows 8 and Windows Server 2012</a></p>
|
<p>In the Singularity project, Microsoft research communicates with the singularity VM through a "loopback" adapter. Maybe that'd help? </p>
<p>Running it is easy so it may be something fun to do anyway. :)</p>
<p><a href="http://research.microsoft.com/os/Singularity/" rel="nofollow noreferrer">http://research.microsoft.com/os/Singularity/</a> </p>
| 7,015
|
<p>I am attempting to set an asp.net textbox to a SQL 2005 money data type field, the initial result displayed to the user is 40.0000 instead of 40.00.
In my asp.net textbox control I would like to only display the first 2 numbers after the decimal point e.g. 40.00</p>
<p>What would be the best way to do this?
My code is below:</p>
<pre><code>this.txtPayment.Text = dr["Payment"].ToString();
</code></pre>
|
<pre><code>this.txtPayment.Text = string.Format("{0:c}", dr[Payment"].ToString());
</code></pre>
|
<p>Use the <em>ToString</em> method with "c" to format it as currency.</p>
<pre><code>this.txtPayment.Text = dr["Payment"].ToString("c");
</code></pre>
<p><a href="http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx" rel="nofollow noreferrer">Standard Numeric Format Strings</a></p>
| 5,951
|
<p>I'm writing an app that will need to make use of <code>Timer</code>s, but potentially very many of them. How scalable is the <code>System.Threading.Timer</code> class? The documentation merely say it's "lightweight", but doesn't explain further. Do these timers get sucked into a single thread (or very small threadpool) that processes all the callbacks on behalf of a <code>Timer</code>, or does each <code>Timer</code> have its own thread? </p>
<p>I guess another way to rephrase the question is: How is <code>System.Threading.Timer</code> implemented?</p>
|
<p>I say this in response to a lot of questions: Don't forget that the (managed) source code to the framework is available. You can use this tool to get it all: <a href="http://www.codeplex.com/NetMassDownloader" rel="noreferrer">http://www.codeplex.com/NetMassDownloader</a></p>
<p>Unfortunately, in this specific case, a lot of the implementation is in native code, so you don't get to look at it...</p>
<p>They definitely use pool threads rather than a thread-per-timer, though.</p>
<p>The standard way to implement a big collection of timers (which is how the kernel does it internally, and I would suspect is indirectly how your big collection of Timers ends up) is to maintain the list sorted by time-until-expiry - so the system only ever has to worry about checking the next timer which is going to expire, not the whole list.</p>
<p>Roughly, this gives O(log n) for starting a timer and O(1) for processing running timers.</p>
<p>Edit: Just been looking in Jeff Richter's book. He says (of Threading.Timer) that it uses a single thread for all Timer objects, this thread knows when the next timer (i.e. as above) is due and calls ThreadPool.QueueUserWorkItem for the callbacks as appropriate. This has the effect that if you don't finish servicing one callback on a timer before the next is due, that your callback will reenter on another pool thread. So in summary I doubt you'll see a big problem with having lots of timers, but you might suffer thread pool exhaustion if large numbers of them are firing at the same timer and/or their callbacks are slow-running.</p>
|
<p>^^ as DannySmurf says : Consolidate them. Create a timer service and ask that for the timers. It will only need to keep 1 active timer (for the next due call) and a history of all the timer requests and recalculate this on AddTimer() / RemoveTimer().</p>
| 5,154
|
<p>I'm working on a windows forms application (C#) where a user is entering data in a form. At any point while editing the data in the form the user can click one of the buttons on the form to perform certain actions. By default the focus goes to the clicked button so the user has to click back on to the control they want to edit in order to continue modifying the data on the form. What I need to be able to do is return the focus to the last edited control after the button click event has been processed. Here's a sample screenshot that illustrates what I'm talking about:</p>
<p><img src="https://lh6.ggpht.com/joe.r.barone/SLs4KZMBqfI/AAAAAAAABNw/P6xtqhCo8Y4/s800/SampleApp1.jpg" alt="Sample App Screen Shot"></p>
<p>The user can be entering data in textbox1, textbox2, textbox3, etc and click the button. I need the button to return the focus back to the control that most recently had the focus before the button was clicked.</p>
<p>I'm wondering if anyone has a better way of implementing this functionality than what I've come up with. Here's what I'm doing right now:</p>
<pre><code> public partial class Form1 : Form
{
Control _lastEnteredControl;
private void textBox_Enter(object sender, EventArgs e)
{
_lastEnteredControl = (Control)sender;
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("Do something here");
_lastEnteredControl.Focus();
}
}
</code></pre>
<p>So basically what we have here is a class variable that points to the last entered control. Each textbox on the form is setup so the textBox_Enter method is fired when the control receives the focus. Then, when the button is clicked focus is returned to the control that had the focus before the button was clicked. Anybody have any more elegant solutions for this?</p>
|
<p>For a bit of 'simplicity' maybe try.</p>
<pre><code>public Form1()
{
InitializeComponent();
foreach (Control ctrl in Controls)
{
if (ctrl is TextBox)
{
ctrl.Enter += delegate(object sender, EventArgs e)
{
_lastEnteredControl = (Control)sender;
};
}
}
}
</code></pre>
<p>then you don't have to worry about decorating each textbox manually (or forgetting about one too).</p>
|
<p>Your implementation looks good enough -- what I do want to know is why you want to do this in the first place? Won't it be preferrable for the focus to cycle back to the first entry? Is the data in the last text box so malleable that once they click the button it is "remembered"? Or do you have some sort of operation that the button does to that specifici text box data -- in that case shouldn't the focus go to a subsequent control instead?</p>
<p>I'm interested in finding out why you want to do this in the first place.</p>
| 5,797
|
<p>Ok, do you do <code>Business.Name</code> or <code>Business.BusinessName</code>
<code>SubCategory.ID</code> or <code>SubCategory.SubCategoryID</code></p>
<p>What about in your database?</p>
<p>Why?</p>
<p>I'm torn with both. Would love there to be a "right answer"</p>
|
<p>The only "right" answer is to be consistent. Decide upfront which one you will be using in a project, and stick to it.</p>
|
<p>For very common properties like "Name" and "ID", the convention I have used is to not put the entity name in the field. For more unusual properties, I do put the entity name.</p>
<p>This is a naming convention decision, but I have not regretted projects where this is the convention, if you put the name of the entity for each ID, it ends up seeming to be too verbose.</p>
| 6,626
|
<p>I would like to sort an array in ascending order using <code>C/C++</code>. The outcome is an array containing element indexes. Each index is corespondent to the element location in the sorted array.</p>
<p><strong>Example</strong></p>
<pre><code>Input: 1, 3, 4, 9, 6
Output: 1, 2, 3, 5, 4
</code></pre>
<p><strong>Edit:</strong> I am using shell sort procedure. The duplicate value indexes are arbitrarily chosen based on which duplicate values are first in the original array.</p>
<h3>Update:</h3>
<p>Despite my best efforts, I haven't been able to implement a sorting algorithm for an array of pointers. The current example won't compile.</p>
<p>Could someone please tell me what's wrong?</p>
<p>I'd very much appreciate some help!</p>
<pre><code>void SortArray(int ** pArray, int ArrayLength)
{
int i, j, flag = 1; // set flag to 1 to begin initial pass
int * temp; // holding variable orig with no *
for (i = 1; (i <= ArrayLength) && flag; i++)
{
flag = 0;
for (j = 0; j < (ArrayLength - 1); j++)
{
if (*pArray[j + 1] > *pArray[j]) // ascending order simply changes to <
{
&temp = &pArray[j]; // swap elements
&pArray[j] = &pArray[j + 1]; //the problem lies somewhere in here
&pArray[j + 1] = &temp;
flag = 1; // indicates that a swap occurred.
}
}
}
};
</code></pre>
|
<p>Since you're using C++, I would do it something like this. The <code>SortIntPointers</code> function can be any sort algorithm, the important part is that it sorts the array of pointers based on the <code>int</code> that they are pointing to. Once that is done, you can go through the array of pointers and assign their sorted index which will end up in the original position in the original array.</p>
<pre><code>int* intArray; // set somewhere else
int arrayLen; // set somewhere else
int** pintArray = new int*[arrayLen];
for(int i = 0; i < arrayLen; ++i)
{
pintArray[i] = &intArray[i];
}
// This function sorts the pointers according to the values they
// point to. In effect, it sorts intArray without losing the positional
// information.
SortIntPointers(pintArray, arrayLen);
// Dereference the pointers and assign their sorted position.
for(int i = 0; i < arrayLen; ++i)
{
*pintArray[i] = i;
}
</code></pre>
<p>Hopefully that's clear enough.</p>
|
<p>Well, there's a trival n^2 solution.</p>
<p>In python:</p>
<pre><code>newArray = sorted(oldArray)
blankArray = [0] * len(oldArray)
for i in xrange(len(newArray)):
dex = oldArray.index(newArray[i])
blankArray[dex] = i
</code></pre>
<p>Depending on how large your list is, this may work. If your list is very long, you'll need to do some strange parallel array sorting, which doesn't look like much fun and is a quick way to introduce extra bugs in your code.</p>
<p>Also note that the above code assumes unique values in oldArray. If that's not the case, you'll need to do some post processing to solve tied values.</p>
| 3,441
|
<p>I found a story about someone <a href="http://www.fablabamersfoort.nl/en/node/534">3D-printing equipment for their Lego minifig</a>, using an Ultimaker. (Article is in Dutch, but accompanied by photographs).</p>
<p>I noticed that what they made weren't the actual connecting bricks, but the tools used by the minifig. And that even so, some filing and a dremel were needed afterwards to make them fit properly.</p>
<p>I'm told that to make something connect properly with real Lego, the machine needs to be tuned very precisely. </p>
<p>So, what resolution is needed to print bricks that will connect with normal Lego bricks?</p>
|
<p>It's really more about calibration than resolution -- a poorly calibrated printer will have dimension errors that prevent mating with true LEGO bricks or other printed bricks. </p>
<p>Also, "resolution" is an incredibly loaded term for 3d printers, because it can mean a lot of different things. But we don't need to get into that right now. There are really two big things to worry about: layer height and extrusion width.</p>
<p>Layer heights of 0.1mm or 0.2mm should be fine. Coarser layers may run into surface finish issues that make the bricks difficult to put together or take apart. There probably isn't much reason to go finer than 0.1mm for this application. Almost all FFF printers can do 0.1mm layer heights as long as it is reasonably well-tuned.</p>
<p><strong>Any typical household FFF printer with a "normal" nozzle size can print fine enough for the bricks to work. It just needs to be tuned well.</strong> The smallest "must have" feature in a standard lego brick is the 1.6mm thick wall around the sides. The typical minimum printable feature size for an FFF printer is 2x the extrusion width, because the slicer will place a path on the inside edge of the shape and the outside edge of the shape. (Some slicers will allow single-extrusion features, but this is not generally recommended because it makes weak parts.) </p>
<p>So, how wide is the extrusion width? It's adjustable, and different slicers auto-recommend different values, but as a safe rule of thumb it needs to be between 1x and 2x your nozzle size. There are some volume calculation quirks in different slicers that may encourage larger or smaller sizes, so sometimes people recommend [extrusion width = nozzle size + layer height] particularly with Slic3r. This is very system-specific. </p>
<p>Assuming you have the most common stock nozzle with a 0.4mm orifice, and also set the extrusion width to 0.4mm, the slicer should put four strands in the walls of the LEGO brick. That's good. </p>
<p>Where it gets tricky is if you have an extrusion width that does not evenly divide into 1.6mm. Say you are printing with an extrusion width of 0.6mm. There is enough room in the wall of the part to place two full 0.6mm perimeter strands... but then a gap 0.4mm wide will be left in the center. You can't put another 0.6mm strand into that 0.4mm gap. Different slicers handle this different ways. Some will leave an empty space between the walls, and you get a very weak print. Some will mash an excessive amount of plastic into the gap, causing poor print quality as excess material builds up more and more on each layer. Some will push a smaller-than-commanded strand to try to properly fill the volume. </p>
<p>So, the general advice with small features is to make sure your extrusion width goes into the part's minimum thickness a reasonable number of times.</p>
<ul>
<li>[Feature size / extrusion width < 2] is BAD </li>
<li>[Feature size / extrusion width = 2] is GOOD </li>
<li>[2 < Feature size / extrusion width < 3] is BAD </li>
<li>[Feature size / extrusion width > 3] is GOOD</li>
</ul>
<p>Although these will vary somewhat by slicer -- older slicers like Skeinforge tend to have more issues with this than newer slicers. What you should do in practice is check your slicer's print previewer to see whether it is leaving a gap between the strands. Then adjust extrusion width and perimeter/shell count to try to get an intelligent output. There's some trial and error involved.</p>
|
<p>I have notes about printing Lego bricks here:</p>
<blockquote>
<p><a href="https://www.thingiverse.com/thing:3424550" rel="nofollow noreferrer">https://www.thingiverse.com/thing:3424550</a></p>
</blockquote>
<p>The upshot is, you want to align the wall thickness of your brick model edges to match an exact multiple of nozzle thickness of your printer. This is more important than using an STL file that exactly matches real Lego dimensions, because your slicer and printer are unlikely to be able to match those dimensions anyway. And because of that, you'll need other adjustments to the bricks to help them fit well with each other and with real Legos.</p>
<p>Additionally, while it is well-understand that Lego bricks use a 1.6mm "Lego Unit" for their standard edge thickness, it's less-well understand how they use an additional .1mm "Play Factor" to help bricks to fit together better. Based on my tests, this play factor is removed from <em>both sides</em> of an edge, such that a standard Lego edge wall should be 1.4mm thick. </p>
<p>Put this all together, and I've found you want to aim for 1.2mm edges when using a .4mm nozzle, and 1.5mm edges when using .5mm nozzle. </p>
<p>Alternatively, a .4mm nozzle can do real 1.4mm Lego edges by only using 1 line for the outer walls, and filling in the remaining .6mm of thickness. Personally, I <em>never</em> want to use just 1 line for a wall, and 1.5x the nozzle diameter is also the bare minimum I'd trust for filling in to work well, making this plan a challenge, too.</p>
<p>The thingiverse piece I linked to is actually a customizable brick <em>generator</em>, that will let you make fine adjustments and help you create brick STL models based on your printer, your slicer and settings, and your material, that will print well and fit with other bricks.</p>
| 159
|
<p>I'm quite new to 3D CAD and printing.
I own a Dremel 3D45 and I use FreeCad / Ultimaker Cura as softwares.</p>
<p>My question is pretty simple.
Say you have to make one object with a pin and another with a hole. They should be coupled together. Of course if you set the diameters of the pin and the hole equal the won't fit!</p>
<p>Right now I'm setting the hole larger of 0.2 mm and the pin smaller of 0.2 mm. This allow a quite good coupling (not so hard but with some resistance).</p>
<p>I guess this tolerance (0.4 mm in my example) depends on a lot of variables: 3D printer settings, material, etc... so it may change using different setup.</p>
<p>How to correctly handle this?</p>
<p>Should I add a variable in my CAD spreadsheet and use it to change the nominal diameter of the coupling items?</p>
<p>I don't think so, but anyway: is there a settings in Ultimaker Cura that allow to compensate an hole or a pin by a specified amount?</p>
<p>Any other suggestion is gladly accepted.</p>
|
<blockquote>
<p>I guess this tolerance (0.4 mm in my example) depends on a lot of variables: 3D printer settings, material, etc... so it may change using different setup.</p>
</blockquote>
<p>Tolerances required <strong>depend on the geometry you're printing</strong>. A hole that is horizontal, vertical, or diagonal will need different tolerance (as I found out in a project that used the same steel dowel pins in three different orientations). And, vertical holes and pins are different from flat-sided shapes: the plastic will be pulled toward the center of a curve, so diameters come out small (and more so for holes since there's no material further inward to resist the movement).</p>
<p>That said, I think you can expect that the distortions of printing are fairly consistent, if your printer is functioning well. I have a Prusa i3 MK3S, and I have printed many parts other people have designed, and <em>when</em> those parts have been designed carefully, I almost always get very good fits between parts. So, my experience suggests that models do not necessarily need tuning for specific printers.</p>
<blockquote>
<p>Should I add a variable in my CAD spreadsheet and use it to change the nominal diameter of the coupling items?</p>
</blockquote>
<p>Yes. If nothing else, this allows you to define how the two parts <em>should</em> fit together separately for the printing error. Use separate numbers for different shapes/fits, so that you can adjust one without messing up another.</p>
|
<blockquote>
<p>I guess this tolerance (0.4 mm in my example) depends on a lot of variables: 3D printer settings, material, etc... so it may change using different setup.</p>
</blockquote>
<p>Yes, this is true, you need to find out for yourself on your rig. Fine tune the printer. Note that filament also shrinks, although some less than others.</p>
<p>Once you figured it out, you can address the tolerance in the CAD design. E.g. I used to print with a material that has a lot of shrinkage, once you established the level of shrinkage, I scaled the complete model accordingly.</p>
| 2,182
|
<p>I have a large database of normalized order data that is becoming very slow to query for reporting. Many of the queries that I use in reports join five or six tables and are having to examine tens or hundreds of thousands of lines.</p>
<p>There are lots of queries and most have been optimized as much as possible to reduce server load and increase speed. I think it's time to start keeping a copy of the data in a denormalized format.</p>
<p>Any ideas on an approach? Should I start with a couple of my worst queries and go from there?</p>
|
<p>I know more about mssql that mysql, but I don't think the number of joins or number of rows you are talking about should cause you too many problems with the correct indexes in place. Have you analyzed the query plan to see if you are missing any?</p>
<p><a href="http://dev.mysql.com/doc/refman/5.0/en/explain.html" rel="noreferrer">http://dev.mysql.com/doc/refman/5.0/en/explain.html</a></p>
<p>That being said, once you are satisifed with your indexes and have exhausted all other avenues, de-normalization might be the right answer. If you just have one or two queries that are problems, a manual approach is probably appropriate, whereas some sort of data warehousing tool might be better for creating a platform to develop data cubes.</p>
<p>Here's a site I found that touches on the subject:</p>
<p><a href="http://www.meansandends.com/mysql-data-warehouse/?link_body%2Fbody=%7Bincl%3AAggregation%7D" rel="noreferrer">http://www.meansandends.com/mysql-data-warehouse/?link_body%2Fbody=%7Bincl%3AAggregation%7D</a></p>
<p>Here's a simple technique that you can use to keep denormalizing queries simple, if you're just doing a few at a time (and I'm not replacing your OLTP tables, just creating a new one for reporting purposes). Let's say you have this query in your application:</p>
<pre><code>select a.name, b.address from tbla a
join tblb b on b.fk_a_id = a.id where a.id=1
</code></pre>
<p>You could create a denormalized table and populate with almost the same query:</p>
<pre><code>create table tbl_ab (a_id, a_name, b_address);
-- (types elided)
</code></pre>
<p>Notice the underscores match the table aliases you use</p>
<pre><code>insert tbl_ab select a.id, a.name, b.address from tbla a
join tblb b on b.fk_a_id = a.id
-- no where clause because you want everything
</code></pre>
<p>Then to fix your app to use the new denormalized table, switch the dots for underscores. </p>
<pre><code>select a_name as name, b_address as address
from tbl_ab where a_id = 1;
</code></pre>
<p>For huge queries this can save a lot of time and makes it clear where the data came from, and you can re-use the queries you already have.</p>
<p>Remember, I'm only advocating this as the last resort. I bet there's a few indexes that would help you. And when you de-normalize, don't forget to account for the extra space on your disks, and figure out when you will run the query to populate the new tables. This should probably be at night, or whenever activity is low. And the data in that table, of course, will never exactly be up to date.</p>
<p>[Yet another edit] Don't forget that the new tables you create need to be indexed too! The good part is that you can index to your heart's content and not worry about update lock contention, since aside from your bulk insert the table will only see selects.</p>
|
<p>You might also want to consider selecting into a temporary table and then performing queries on that temporary table. This would avoid the need to rejoin your tables for every single query you issue (assuming that you can use the temporary table for numerous queries, of course). This basically gives you denormalized data, but if you are only doing select calls, there's no concern about data consistency.</p>
| 3,396
|
<p>We're working on a Log Viewer. The use will have the option to filter by user, severity, etc. In the Sql days I'd add to the query string, but I want to do it with Linq. How can I conditionally add where-clauses?</p>
|
<p>if you want to only filter if certain criteria is passed, do something like this</p>
<pre><code>var logs = from log in context.Logs
select log;
if (filterBySeverity)
logs = logs.Where(p => p.Severity == severity);
if (filterByUser)
logs = logs.Where(p => p.User == user);
</code></pre>
<p>Doing so this way will allow your Expression tree to be exactly what you want. That way the SQL created will be exactly what you need and nothing less.</p>
|
<p>Just use C#'s && operator:</p>
<pre><code>var items = dc.Users.Where(l => l.Date == DateTime.Today && l.Severity == "Critical")
</code></pre>
<p>Edit: Ah, need to read more carefully. You wanted to know how to <em>conditionally</em> add additional clauses. In that case, I have no idea. :) What I'd probably do is just prepare several queries, and execute the right one, depending on what I ended up needing.</p>
| 3,235
|
<p>In a web application, is it acceptable to use HTML in your code (non-scripted languages, Java, .NET)?</p>
<p>There are two major sub questions:</p>
<ol>
<li>Should you use code to print HTML, or otherwise directly create HTML that is displayed?</li>
<li>Should you mix code within your HTML pages?</li>
</ol>
|
<p>Generally, it's better to keep presentation (HTML) separate from logic ("back-end" code). Your code is decoupled and easier to maintain this way.</p>
|
<p>Its fugly, and not type safe. But people do it without consequence. I'd prefer using a DOM or, at a minimum, classes designed to write HTML using type safe semantics. Also, its not all that good to mix UI with logic...</p>
| 9,035
|
<p>Looking for something to smooth out a PLA print. Would Mod Podge be a good solution? Will it stick? </p>
|
<p>From what I've read about Mod Podge, it is an adhesive with a vinyl acetate base. As such it is similar to both PVA (used for wash-away support) and ordinary white glue. One of the more common references to the product refers to it not being water proof, although the outdoor version of the product presents as being water-resistant.</p>
<p>As part of the research for this answer, I found references to overly-thick coats becoming milky. This follows a reference to applying thin multiple coats and allowing proper cure time between coats. That proper cure time is listed as 28 days. </p>
<p>Another set of posts suggest to cure the MP more rapidly than 28 days, one can heat the item in an oven to 175°F (80°C) which should not cause the PLA to melt, but may allow for sagging of unsupported parts. Testing is recommended.</p>
<p>MP is an adhesive, is known to stick to non-porous surfaces and would be no more harmful than glue stick for a PLA (or ABS) model.</p>
<p>Durability is uncertain. If you intend to paint the item after sealing/smoothing, you'll gain durability and water resistance.</p>
|
<p>I have used Ponal Express, a woodglue, as a smoothing layer inbetween a somewhat sanded PLA and an acrylic paint. It had a good result to get it almost perfectly smooth. It stuck quite well, no problem with it getting off under painting. DO note though, that sanding the glue layer can tear of larger pieces of the film, so do only apply the glue as the last layer.</p>
<p>Now, ModPodge is pretty much made from PVA or wood glue. The same thing I used, pretty much. So yes, it will work.</p>
| 1,567
|
<p>What resources or methods would OpenSCAD users suggest to piece together disparate STL files?</p>
<p>I'd like to take an existing STL model-library of STL parts (head, torso, arms, legs) and make it a Thingiverse OpenSTL maker, similar to the castle generator and/or the puzzle generators available.</p>
<p>This way, users can generate a custom model using the designated parameters and download the model for printing.</p>
|
<p>Cura prior to version 2.5 does not take G-code as an input. I'm not sure what you mean by "print only using Cura." Don't you have a SD slot on your control board? For that matter, why can't you drive the USB port from Slic3r? </p>
<p>Remember: G-code is the equivalent of "compiled code," the raw commands which drive the printer, while STL or OBJ, etc., are the "source code," which you edit to get the shape you want.</p>
<p>I've looked at a few apps which will render a 3D image on your computer from G-code, but I don't know off-hand of one which will "decompile" into a STL or mesh file.</p>
|
<p>Cura prior to version 2.5 does not take G-code as an input. I'm not sure what you mean by "print only using Cura." Don't you have a SD slot on your control board? For that matter, why can't you drive the USB port from Slic3r? </p>
<p>Remember: G-code is the equivalent of "compiled code," the raw commands which drive the printer, while STL or OBJ, etc., are the "source code," which you edit to get the shape you want.</p>
<p>I've looked at a few apps which will render a 3D image on your computer from G-code, but I don't know off-hand of one which will "decompile" into a STL or mesh file.</p>
| 449
|
<p>I am using jQuery and trying to find a cross browser way to get the pixel coordinates of the caret in <code><textarea></code>s and <code>input</code> boxes such that I can place an absolutely positioned div around this location.</p>
<p>Is there some jQuery plugin? Or JavaScript snippet to do just that?</p>
|
<p>I've looked for a textarea caret coordinates plugin for <a href="https://github.com/mizzao/meteor-autocomplete" rel="noreferrer">meteor-autocomplete</a>, so I've evaluated all the 8 plugins on GitHub. The winner is, by far, <a href="https://github.com/component/textarea-caret-position" rel="noreferrer">textarea-caret-position</a> from <strong>Component</strong>.</p>
<h2>Features</h2>
<ul>
<li>pixel precision</li>
<li>no dependencies whatsoever</li>
<li>browser compatibility: Chrome, Safari, Firefox (despite <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=753662" rel="noreferrer">two</a> <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=984275" rel="noreferrer">bugs</a> it has), IE9+; may work but not tested in Opera, IE8 or older</li>
<li>supports any font family and size, as well as text-transforms</li>
<li>the text area can have arbitrary padding or borders</li>
<li>not confused by horizontal or vertical scrollbars in the textarea</li>
<li>supports hard returns, tabs (except on IE) and consecutive spaces in the text</li>
<li>correct position on lines longer than the columns in the text area</li>
<li>no <a href="https://github.com/component/textarea-caret-position/blob/06d2197f85f96405b43724e56dc56f220c0092a5/test/position_off_after_wrapping_with_whitespace_before_EOL.gif" rel="noreferrer">"ghost" position in the empty space</a> at the end of a line when wrapping long words</li>
</ul>
<h3>Here's a demo - <a href="http://jsfiddle.net/dandv/aFPA7/" rel="noreferrer">http://jsfiddle.net/dandv/aFPA7/</a></h3>
<p><img src="https://i.stack.imgur.com/LJiUS.png" alt="enter image description here"></p>
<h2>How it works</h2>
<p>A mirror <code><div></code> is created off-screen and styled exactly like the <code><textarea></code>. Then, the text of the textarea up to the caret is copied into the div and a <code><span></code> is inserted right after it. Then, the text content of the span is set to the remainder of the text in the textarea, in order to faithfully reproduce the wrapping in the faux div.</p>
<p>This is the only method guaranteed to handle all the edge cases pertaining to wrapping long lines. It's also used by GitHub to determine the position of its <strong>@</strong> user dropdown.</p>
|
<p>Note: this answer describes how to get the <strong>character co-ordinates</strong> of the text-cursor/caret. To find the pixel-co-ordinates, you'll need to extend this further.</p>
<p>The first thing to remember is that the cursor can be in three states</p>
<ul>
<li>a regular insertion cursor at a specific position</li>
<li>a text selection that has a certain bounded area</li>
<li>not active: textarea does not have focus. Has not been used.</li>
</ul>
<p>The IE model uses the Object <a href="http://msdn.microsoft.com/en-us/library/ms535869(VS.85).aspx" rel="nofollow noreferrer">document.selection</a>, from this we can get a <a href="http://msdn.microsoft.com/en-us/library/ms535872(VS.85).aspx" rel="nofollow noreferrer">TextRange</a> object which gives us access to the selection and thus the cursor position(s).</p>
<p>The FF model/Opera uses the handy variables [input].selectionStart and selectionEnd.</p>
<p>Both models represent a regular ative cursor as a zero-width selection, with the left bound being the cursor position.</p>
<p>If the input field does not have focus, you may find that neither is set.
I have had good success with the following code to insert a piece of text at the current cursor location, also replacing the current selection, if present.
Depending on the exact browser, YMMV.</p>
<pre><code>function insertAtCursor(myField, myValue) {
/* selecion model - ie */
if (document.selection) {
myField.focus();
sel = document.selection.createRange();
sel.text = myValue;
}
/* field.selectionstart/end firefox */
else if (myField.selectionStart || myField.selectionStart == '0' ) {
var startPos = myField.selectionStart;
var endPos = myField.selectionEnd;
myField.value = myField.value.substring(0, startPos)
+ myValue
+ myField.value.substring(endPos, myField.value.length);
myField.selectionStart = startPos + myValue.length;
myField.selectionEnd = startPos + myValue.length;
myField.focus();
}
// cursor not active/present
else {
myField.value += myValue;
}
</code></pre>
<p>Bug Note: links are not being correctly marked up in the top para.</p>
<p>Selection object: <a href="http://msdn.microsoft.com/en-us/library/ms535869(VS.85).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ms535869(VS.85).aspx</a><br>
TextRange object: <a href="http://msdn.microsoft.com/en-us/library/ms535872(VS.85).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ms535872(VS.85).aspx</a></p>
| 4,946
|
<p>I am running a MakerBot Replicator 2. During the print, the printer just stops executing and I am running out of ways to troubleshoot.</p>
<p>After restarting, I can load and extrude filament.</p>
<p>I have replaced the SD card, and even borrowed one from another working replicator, and the freeze still occurs.</p>
<p>Likewise, I've regenerated the x3g file, and that did not work.</p>
<p>The panel does not freeze, I can cancel the print during the freeze.</p>
<p>I've made sure Z pause is off. It tends freezes randomly on the first layer.</p>
<p>In general, it looks as though the print is "in progress" but not making progress (Timer ticks up, % completed does not)</p>
<p>Does anyone have any idea as to what could be causing the problem?</p>
|
<p>There are a few options. First your board could be overheating etc. That is harder to verify without some overpriced replacements. So to start lets take everything apart (photo and labeling is Strongly recommended). Then simply put it back together. Hopefully it is just a loose connection.</p>
|
<p>Seems like others have had similar issues: <a href="https://www.thingiverse.com/groups/engineering/topic:3849" rel="nofollow noreferrer">https://www.thingiverse.com/groups/engineering/topic:3849</a>. Their issue was a bit more mechanical than firmware, though. I hope this helps!</p>
<p>You might also want to check the software you're using to slice the file. Sometimes the software doesn't slice the file properly, which causes problems mid-print.</p>
| 474
|
<p>What tools, preferably open source, are recommended for driving an automated test suite on a FLEX based web application? The same tool also having built in capabilities to drive Web Services would be nice.</p>
|
<p>Adobe distributes a test framework themselves: <a href="http://opensource.adobe.com/wiki/display/flexunit/FlexUnit" rel="noreferrer">FlexUnit</a>.</p>
|
<p>My preferred tool is Selenium Remote Control. There is a plug-in I discovered a few months ago:</p>
<p><a href="http://code.google.com/p/flash-selenium/" rel="nofollow noreferrer">http://code.google.com/p/flash-selenium/</a></p>
<p>This required 'hooks' to be written on the server side (ActionScript/Flex). Once they were added, I was able to do some browser testing using Selenium RC.</p>
| 9,807
|
<p>Is there a mod_rewrite equivalent for IIS 7.0 that's </p>
<p>a) more or less complete </p>
<p>b) suitable for a production environment, i.e. battle-tested/dependable/secure</p>
<p>Do you have an experience-based recommendation?</p>
|
<p>Check out the <a href="http://www.iis.net/downloads/microsoft/url-rewrite" rel="noreferrer">URL Rewrite Module for IIS 7</a> created by Microsoft</p>
|
<p><a href="http://www.isapirewrite.com/" rel="nofollow noreferrer">ISAPI Rewrite</a> is suitable for IIS 5 or 6. There's a Lite version available for free, or you can pay for the full version to get more features, such as proxying capabilities. It's been a while since I've used it, but it worked fine at the time.</p>
| 8,590
|
<p>I have the FlashForge Dreamer NX which prints with good quality on small models. However, when the model is taller than 2 cm or 2.5 cm (around 0.8 or 1 inch), it really loses quality.</p>
<p>Here there is a picture so you can understand what I mean. Which setting do I have to change? Have a look the the base is very acceptable, but then, the printing is not acceptable.</p>
<p><a href="https://i.stack.imgur.com/c5gTf.jpg" rel="nofollow noreferrer" title="Printed model losing quality the higher up it is printed"><img src="https://i.stack.imgur.com/c5gTf.jpg" alt="Printed model losing quality the higher up it is printed" title="Printed model losing quality the higher up it is printed" /></a></p>
<p>I'm using FlashPrint 5, but I can switch to any other app if it is needed.</p>
<p><strong>UPDATE</strong></p>
<p>I'm using PLA 1.75. Here are my settings.</p>
<p><a href="https://i.stack.imgur.com/YVjEL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YVjEL.png" alt="enter image description here" /></a>
<a href="https://i.stack.imgur.com/mmYy4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mmYy4.png" alt="enter image description here" /></a>
<a href="https://i.stack.imgur.com/9ptVP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9ptVP.png" alt="enter image description here" /></a>
<a href="https://i.stack.imgur.com/b1T6J.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/b1T6J.png" alt="enter image description here" /></a>
<a href="https://i.stack.imgur.com/Kq4zf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Kq4zf.png" alt="enter image description here" /></a>
<a href="https://i.stack.imgur.com/3vgya.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3vgya.png" alt="enter image description here" /></a>
<a href="https://i.stack.imgur.com/5V4ZK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5V4ZK.png" alt="enter image description here" /></a>
<a href="https://i.stack.imgur.com/AmB3T.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AmB3T.png" alt="enter image description here" /></a>
<a href="https://i.stack.imgur.com/lJUpe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lJUpe.png" alt="enter image description here" /></a>
<a href="https://i.stack.imgur.com/RcWm9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RcWm9.png" alt="enter image description here" /></a>
<a href="https://i.stack.imgur.com/Z2lVV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Z2lVV.png" alt="enter image description here" /></a>
<a href="https://i.stack.imgur.com/EXTue.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EXTue.png" alt="enter image description here" /></a>
<a href="https://i.stack.imgur.com/J16mV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/J16mV.png" alt="enter image description here" /></a>
<a href="https://i.stack.imgur.com/sd9bA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sd9bA.png" alt="enter image description here" /></a>
<a href="https://i.stack.imgur.com/sK0GL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sK0GL.png" alt="enter image description here" /></a>
<a href="https://i.stack.imgur.com/g6jC6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/g6jC6.png" alt="enter image description here" /></a>
<a href="https://i.stack.imgur.com/b7liI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/b7liI.png" alt="enter image description here" /></a></p>
|
<p>The cause of the meshing is under-extrusion. When under-extrusion happens, several problems can cause this. E.g. heat creep (probably not the issue here because heat creep is usually not recoverable, but not unimaginable since this is an enclosed printer, you could try printing at a lower temperature and look into less aggressive retraction settings), or an extrusion problem.</p>
<p>Since this is an intermittent, recurring defect, this could typically be a result of spool entanglement or any other defect in the extrusion path. Once the entanglement or friction on the spool has resolved itself, the print continues as if nothing happened.</p>
<p>You should print again and look at what happens. Also pay attention to the extruder, it may be skipping steps or hasn't got enough force to push the filament through.</p>
<p>Check the extrusion of filament also by disconnecting the extruder and manually feeding the filament through a hot nozzle. It should be easy to push the filament through the nozzle at temperature. If not, try cleaning the nozzle doing a cold/atomic pull (feed filament hot, cut the power to the hotend, wait until the temperature drops considerably and suddenly pull out the filament, preferably with nylon or cleaning filament or any other high temperature filament).</p>
|
<p>That looks horribly familiar; I call it meshing.</p>
<p>It's underextrusion, which can be caused by lots of things.</p>
<p>I cleaned, then replaced the hot end, Bowden tube, and both couplers trying to solve the problem, but then the Z axis was binding. Tried a couple things for that, what seems to have worked was loosening a couple of screws flanking the Z screw. Prints are still coming out a little short, so I think I'll have to shim the Z screw brace.</p>
| 2,012
|
<p>Is there a method (other than trial and error) I can use to find unused image files? How about CSS declarations for ID's and Classes that don't even exist in the site?</p>
<p>It seems like there might be a way to write a script that scans the site, profile it, and see which images and styles are never loaded.</p>
|
<p>You don't have to pay any web service or search for an addon, you already have this in Google Chrome under F12 <code>(Inspector)->Audits->Remove unused CSS rules</code></p>
<p>Screenshot:<img src="https://i.stack.imgur.com/Soozt.png" alt="Screenshot"></p>
<p><strong>Update: 30 Jun, 2017</strong></p>
<p>Now Chrome 59 provides <strong>CSS and JS code coverage</strong>. See <a href="https://developers.google.com/web/updates/2017/04/devtools-release-notes#coverage" rel="noreferrer">https://developers.google.com/web/updates/2017/04/devtools-release-notes#coverage</a></p>
<p><a href="https://i.stack.imgur.com/eBWA1.png" rel="noreferrer"><img src="https://i.stack.imgur.com/eBWA1.png" alt="enter image description here"></a></p>
|
<p>This little tool gives you a list of the css rules in use by some html.</p>
<p>Here it is on <a href="http://codepen.io/tmorrow-hyphensolutions/pen/GprdRQ" rel="nofollow">Code Pen</a></p>
<p>Click on <kbd>Run code snippet</kbd>, then click on <kbd>Full page</kbd> to get in to it. Then follow the instructions in the snippet. You can run it full page to see it work with your html / css.</p>
<p>But it's easier just to bookmark my code pen as a tool.</p>
<p><div class="snippet" data-lang="js" data-hide="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>/* CSS CLEANER INSTRUCTIONS
1. Paste your HTML into the HTML window
2. Paste your CSS into the CSS window
5. The web page result now ends with a list of just the CSS used by your HTML!
*/
function cssRecursive(e) {
var cssList = css(e);
for (var i = 0; i < e.children.length; ++i) {
var childElement = e.children[i];
cssList = union(cssList, cssRecursive(childElement));
}
return cssList;
}
function css(a) {
var sheets = document.styleSheets,
o = [];
a.matches = a.matches || a.webkitMatchesSelector || a.mozMatchesSelector || a.msMatchesSelector || a.oMatchesSelector;
for (var i in sheets) {
var rules = sheets[i].rules || sheets[i].cssRules;
for (var r in rules) {
if (a.matches(rules[r].selectorText)) {
o.push(rules[r].cssText);
}
}
}
return o;
}
function union(x, y) {
return unique(x.concat(y));
};
function unique(x) {
return x.filter(function(elem, index) {
return x.indexOf(elem) == index;
});
};
document.write("<br/><hr/><code style='background-color:white; color:black;'>");
var allCss = cssRecursive(document.body);
for (var i = 0; i < allCss.length; ++i) {
var cssRule = allCss[i];
document.write(cssRule + "<br/>");
}
document.write("</code>");</code></pre>
</div>
</div>
</p>
| 5,326
|
<p>I am printing small mechanical pieces in ABS:</p>
<ul>
<li>100 ºC bed temperature</li>
<li>70 ºC Room temperature</li>
<li>250 ºC nozzle temperature</li>
<li>0.4 mm nozzle, at 0.15 mm per layer.</li>
<li>100.8 % scale to compensate ABS dimensional innacuracy.</li>
</ul>
<p>The first layer is printed correctly, but later, corners warp and first 10 mm get deformed (See images).</p>
<p><a href="https://i.stack.imgur.com/5QsSPm.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5QsSPm.jpg" alt="enter image description here" /></a></p>
<p><a href="https://i.stack.imgur.com/Nsummm.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Nsummm.jpg" alt="enter image description here" /></a></p>
<p>How do I solve this? Unfortunately, I cannot increase room temperature over 70 ºC</p>
<p>Here is a picture while printing, we can see that the edges get warped even far over the first layer. (Sorry, the picture quality is not so good):</p>
<p><a href="https://i.stack.imgur.com/dWjCG.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dWjCG.jpg" alt="enter image description here" /></a></p>
|
<p>The up-curling of overhangs is frequently seen when printing PLA or PETG when the just deposited layer hasn't been cooled enough. The residual heat will allow the curling as the plastic has not been fully set (above the so called glass temperature) because of insufficient part cooling.</p>
<p>Knowing that ABS doesn't need much cooling (to improve the inter-layer bonding), you most probably will not require full power of the fan (depending on the cooling power of the fan). You do need a little cooling though, but not for the first (few) layer(s), so keep the fan off at the first layer. Be sure it is up to speed at the layer you require the cooling as the first few percentage of the fan is generally not enough to rotate the fan. E.g. my fans start spinning at about 20-25 %.</p>
|
<p>We usually stick the masking tape on the printer's bottom plate, so that the model is formed on the side of the masking tape which without glue, which looks good.
When there is no masking tape, we sometimes manually adjust the height of the bottom plate to make the nozzle appress to the bottom plate when printing the first layer. At this time, the melted material can hardly flow out. The strong pressure will adhere the material tightly to the bottom plate, which can effectively solve this problem. However, this may damage the extruder motor.</p>
| 1,719
|
<p>Exceptions in C++ don't need to be caught (no compile time errors) by the calling function. So it's up to developer's judgment whether to catch them using try/catch (unlike in Java).</p>
<p>Is there a way one can ensure that the exceptions thrown are always caught using try/catch by the calling function?</p>
|
<p>No.</p>
<p>See <a href="http://www.gotw.ca/publications/mill22.htm" rel="noreferrer">A Pragmatic Look at Exception Specifications</a> for reasons why not. </p>
<p>The only way you can "help" this is to document the exceptions your function can throw, say as a comment in the header file declaring it. This is not enforced by the compiler or anything. Use code reviews for that purpose.</p>
|
<p>Or you could start throwing critical exceptions. Surely, an access violation exception will <em>catch</em> your users' attention.</p>
| 2,353
|
<p>Is there a simple way, in a pretty standard UNIX environment with bash, to run a command to delete all but the most recent X files from a directory?</p>
<p>To give a bit more of a concrete example, imagine some cron job writing out a file (say, a log file or a tar-ed up backup) to a directory every hour. I'd like a way to have another cron job running which would remove the oldest files in that directory until there are less than, say, 5.</p>
<p>And just to be clear, there's only one file present, it should never be deleted.</p>
|
<p>The problems with the existing answers:</p>
<ul>
<li>inability to handle filenames with embedded spaces or newlines.
<ul>
<li>in the case of solutions that invoke <code>rm</code> directly on an unquoted command substitution (<code>rm `...`</code>), there's an added risk of unintended globbing.</li>
</ul>
</li>
<li>inability to distinguish between files and directories (i.e., if <em>directories</em> happened to be among the 5 most recently modified filesystem items, you'd effectively retain <em>fewer</em> than 5 files, and applying <code>rm</code> to directories will fail).</li>
</ul>
<p><a href="https://stackoverflow.com/a/299911/45375">wnoise's answer</a> addresses these issues, but the solution is <em>GNU</em>-specific (and quite complex).</p>
<p>Here's a pragmatic, <strong>POSIX-compliant solution</strong> that comes with only <strong>one caveat</strong>: it cannot handle filenames with embedded <em>newlines</em> - but I don't consider that a real-world concern for most people.</p>
<p><sup>For the record, here's the explanation for why it's generally not a good idea to parse <code>ls</code> output: <a href="http://mywiki.wooledge.org/ParsingLs" rel="noreferrer">http://mywiki.wooledge.org/ParsingLs</a></sup></p>
<pre><code>ls -tp | grep -v '/$' | tail -n +6 | xargs -I {} rm -- {}
</code></pre>
<p><sup>Note: This command operates in the <strong><em>current</em> directory</strong>; to <strong>target a directory <em>explicitly</em>, use a subshell (<code>(...)</code>) with <code>cd</code></strong>:<br />
<code>(cd /path/to && ls -tp | grep -v '/$' | tail -n +6 | xargs -I {} rm -- {})</code><br />
The same <strong>applies analogously to the commands below</strong>.</sup></p>
<p>The above is <strong>inefficient</strong>, because <code>xargs</code> has to invoke <code>rm</code> separately <em>for each filename</em>.<br />
However, your platform's specific <code>xargs</code> implementation may allow you to solve this problem:</p>
<hr />
<p>A solution that <strong>works with <em>GNU</em> <code>xargs</code></strong> is to use <strong><code>-d '\n'</code></strong>, which makes <code>xargs</code> consider each input line a separate argument, yet passes as many arguments as will fit on a command line <em>at once</em>:</p>
<pre><code>ls -tp | grep -v '/$' | tail -n +6 | xargs -d '\n' -r rm --
</code></pre>
<p><sup>Note: Option <code>-r</code> (<code>--no-run-if-empty</code>) ensures that <code>rm</code> is not invoked if there's <em>no input</em>.</sup></p>
<p>A solution that <strong>works with <em>both</em> <em>GNU</em> <code>xargs</code> <em>and</em> <em>BSD</em> <code>xargs</code></strong> (including on <strong>macOS</strong>) - though technically still <em>not</em> POSIX-compliant - is to use <strong><code>-0</code></strong> to handle <code>NUL</code>-separated input, after first translating newlines to <code>NUL</code> (<code>0x0</code>) chars., which also passes (typically) all filenames <em>at once</em>:</p>
<pre><code>ls -tp | grep -v '/$' | tail -n +6 | tr '\n' '\0' | xargs -0 rm --
</code></pre>
<p><strong>Explanation:</strong></p>
<ul>
<li><p><code>ls -tp</code> prints the names of filesystem items sorted by how recently they were modified , in descending order (most recently modified items first) (<code>-t</code>), with directories printed with a trailing <code>/</code> to mark them as such (<code>-p</code>).</p>
<ul>
<li>Note: It is the fact that <code>ls -tp</code> always outputs file / directory <em>names</em> only, not full paths, that necessitates the subshell approach mentioned above for targeting a directory other than the current one (<code>(cd /path/to && ls -tp ...)</code>).</li>
</ul>
</li>
<li><p><code>grep -v '/$'</code> then weeds out directories from the resulting listing, by omitting (<code>-v</code>) lines that have a trailing <code>/</code> (<code>/$</code>).</p>
<ul>
<li><em>Caveat</em>: Since a <em>symlink that points to a directory</em> is technically not itself a directory, such symlinks will <em>not</em> be excluded.</li>
</ul>
</li>
<li><p><code>tail -n +6</code> skips the first <em>5</em> entries in the listing, in effect returning all <em>but</em> the 5 most recently modified files, if any.<br />
Note that in order to exclude <code>N</code> files, <code>N+1</code> must be passed to <code>tail -n +</code>.</p>
</li>
<li><p><code>xargs -I {} rm -- {}</code> (and its variations) then invokes on <code>rm</code> on all these files; if there are no matches at all, <code>xargs</code> won't do anything.</p>
<ul>
<li><code>xargs -I {} rm -- {}</code> defines placeholder <code>{}</code> that represents each input line <em>as a whole</em>, so <code>rm</code> is then invoked once for each input line, but with filenames with embedded spaces handled correctly.</li>
<li><code>--</code> in all cases ensures that any filenames that happen to start with <code>-</code> aren't mistaken for <em>options</em> by <code>rm</code>.</li>
</ul>
</li>
</ul>
<hr />
<p>A <strong>variation</strong> on the original problem, <strong>in case the matching files need to be processed <em>individually</em> or <em>collected in a shell array</em></strong>:</p>
<pre><code># One by one, in a shell loop (POSIX-compliant):
ls -tp | grep -v '/$' | tail -n +6 | while IFS= read -r f; do echo "$f"; done
# One by one, but using a Bash process substitution (<(...),
# so that the variables inside the `while` loop remain in scope:
while IFS= read -r f; do echo "$f"; done < <(ls -tp | grep -v '/$' | tail -n +6)
# Collecting the matches in a Bash *array*:
IFS=$'\n' read -d '' -ra files < <(ls -tp | grep -v '/$' | tail -n +6)
printf '%s\n' "${files[@]}" # print array elements
</code></pre>
|
<pre><code>leaveCount=5
fileCount=$(ls -1 *.log | wc -l)
tailCount=$((fileCount - leaveCount))
# avoid negative tail argument
[[ $tailCount < 0 ]] && tailCount=0
ls -t *.log | tail -$tailCount | xargs rm -f
</code></pre>
| 4,538
|
<p>I have been using Castle MonoRail for the last two years, but in a new job I am going to be the one to bring in ASP.NET MVC with me. <br /></p>
<p>I understand the basics of views, actions and the like. <br />I just need a good sample for someone with MVC experience. <br />
Any good links besides Scott's Northwind traders sample?</p>
|
<p><a href="http://code.google.com/p/codecampserver/" rel="noreferrer">CodeCampServer</a> - Built with ASP.NET MVC, pretty light and small project. No cruft at all.</p>
<p>@lomaxx - Just FYI, most of what Troy Goode wrote is now part of <a href="http://weblogs.asp.net/scottgu/archive/2008/07/14/asp-net-mvc-preview-4-release-part-1.aspx" rel="noreferrer">ASP.NET MVC as of Preview 4</a>.</p>
|
<p>Check out some of these:</p>
<ul>
<li><a href="http://www.codeplex.com/mvcpress" rel="nofollow noreferrer">MVCPress/Blog</a></li>
<li><a href="http://www.codeplex.com/CarTrackr/Release/ProjectReleases.aspx?ReleaseId=18356" rel="nofollow noreferrer">CarTrackr</a></li>
<li><a href="http://haacked.com/archive/2008/11/07/haackoverflow-vs-stackoverflow.aspx" rel="nofollow noreferrer">HaackOverflow</a> by Phil Haack</li>
<li><a href="http://weblogs.asp.net/stephenwalther/archive/2008/09/05/asp-net-mvc-application-building-forums-1-create-the-perfect-application.aspx" rel="nofollow noreferrer">Forums</a> by Stephen Walther</li>
</ul>
| 5,133
|
<p>Marlin has a <a href="http://marlinfw.org/tools/lin_advance/k-factor.html" rel="nofollow noreferrer">Linear Advance calibration pattern generator</a>, but I find it's hard to use because:</p>
<ul>
<li>It only prints the initial layer on the bed, where bed irregularities interfere with accurate reading of it.</li>
<li>It doesn't do proper retraction and priming, so a mess of strings and underextruded initial segments/non-adhesion mess up the results.</li>
<li>It's hard to visually evaluate.</li>
<li>Getting a very wide range of K values involves multiple runs.</li>
<li>It's hard to clean up.</li>
</ul>
<p>Is there a better procedure for calibration of K value for linear advance?</p>
|
<p>I measured mine with a thread gauge and it says the pitch is <strong>0.7 mm</strong>.</p>
<p>So, as the stock adjustment wheels have 14 bumps around their circumference, turning by one of those is an adjustment of exactly 0.05 mm (assuming no backlash).</p>
<p>I can't speak for anyone else's, but due to the availability of replacement height adjustment wheels which don't specify alternative thread pitches, I <em>guess</em> that's the only one in use. I encourage you to verify my finding before relying on it.</p>
|
<p>I don't know what the value is, but there are a few ways to find out. It is very hard to measure this with a caliper, but it can be done, mark the upper and bottom of e.g. 10 windings and measure this with a caliper. Alternatively measure how much the screw drops after 10 full turns. </p>
<p>There are special tools that give you the answer directly, they cost a few Euros/bucks but can be very handy; a thread gauge, just place the 0.5 mm and the 0.7 mm beside the screw and you will instantly see which is the correct one.</p>
<p><a href="https://i.stack.imgur.com/UYqFm.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UYqFm.jpg" alt="enter image description here"></a></p>
<p><em>I bought mine at a typical Chinese vendor site.</em></p>
| 1,572
|
<p>I'm having trouble getting a rotary encoder to work properly with AVR micro controllers. The encoder is a mechanical <a href="http://no.farnell.com/1520815/passives/product.us0?sku=alps-ec12d1524401" rel="noreferrer">ALPS encoder</a>, and I'm using <a href="http://www.atmel.com/dyn/resources/prod_documents/doc2545.pdf" rel="noreferrer">Atmega168</a>.</p>
<p><strong>Clarification</strong></p>
<p>I have tried using an External Interrupt to listen to the pins, but it seems like it is too slow. When Pin A goes high, the interrupt procedure starts and then checks if Pin B is high. The idea is that if Pin B is high the moment Pin A went high, then it is rotating counter clock-wise. If Pin B is low, then it is rotating clock-wise. But it seems like the AVR takes too long to check Pin B, so it is always read as high. </p>
<p>I've also tried to create a program that simply blocks until Pin B or Pin A changes. But it might be that there is too much noise when the encoder is rotated, because this does not work either. My last attempt was to have a timer which stores the last 8 values in a buffer and checks if it is going from low to high. This did not work either.</p>
<p>I have tried scoping the encoder, and it seems to use between 2 and 4ms from the first Pin changes till the other Pin changes.</p>
|
<p>I have a webpage about <a href="http://www.ubasics.com/adam/electronics/doc/rotryenc.shtml" rel="nofollow noreferrer">rotary encoders and how to use them</a>, which you might find useful.</p>
<p>Unfortunately without more information I can't troubleshoot your particular problem. </p>
<p>Which microcontroller pins are connected to the encoder, and what is the code you're currently using to decode the pulses?</p>
<p>Ok, you're dealing with a few different issues, the first issue is that this is a mechanical encoder, so you have to deal with switch noise (bounce, chatter). The <a href="http://www.farnell.com/datasheets/103465.pdf" rel="nofollow noreferrer">data sheet</a> indicates that it may take up to 3mS for the parts to stop bouncing and creating false outputs.</p>
<p>You need to create a debounce routine. The simplest of which is to continuously check to see if A goes high. If it does, start a timer and check it again in 3 ms. If it's still high, then you can check B - if it's not high then you ignore the spurious pulse and continue looking for A high. When you check B, you look at it, start a timer for 3 ms, and then look at B again. If it was the same both times, then you can use that value - if it changes within 3 ms then you have to do it again (read B, wait 3 ms, then read it again and see if it matches).</p>
<p>The atmega is fast enough that you shouldn't have to worry about these checks going slowly, unless you're also running a slow clock speed.</p>
<p>Once you deal with the mechanical noise, then you want to look at a proper gray code routine - the algorithm you're following won't work unless you also decrement if A is high when B goes low. Generally people store the last value of the two inputs, and then compare it to the new value of the two inputs and use a small function to increment or decrement based on that. (Check out the heading "high resolution reading" on the website I mentioned above for the table). I combine the two readings into a four bit number and use a simple array to tell me whether I increment or decrement the counter, but there are solutions that are even more advanced, and optimize for code size, speed, or ease of code maintenance.</p>
|
<p>What exactly are you having problems with? I assume you've been able to hook the pins of the encoder to your PIC as per the technical specifications linked on the Farnell page you gave, so is the problem with reading the data? Do you not get any data from the encoder? Do you not know how to interpret the data you're getting back?</p>
| 5,512
|
<p>What recommendations can you give for a system which must do the following:</p>
<p>Load Plugins (and eventually execute them) but have 2 methods of loading these plugins:</p>
<ul>
<li>Load only authorized plugins
(developed by the owner of the
software) </li>
<li>Load all plugins</li>
</ul>
<p>And we need to be reasonably secure that the authorized plugins are the real deal (unmodified). However all plugins must be in seperate assemblies. I've been looking at using strong named assemblies for the plugins, with the public key stored in the loader application, but to me this seems too easy to modify the public key within the loader application (if the user was so inclined) regardless of any obfuscation of the loader application. Any more secure ideas?</p>
|
<p>This is all described in <a href="http://livedocs.adobe.com/flex/3/progAS_flex3.pdf" rel="nofollow noreferrer">The Adobe Flex 3 Programming ActionScript 3 PDF</a> on page 550 (Chapter 27: Flash Player Security / Cross-scripting):</p>
<blockquote>
<p>If two SWF files written with ActionScript 3.0 are served from different domains—for example, <a href="http://siteA.com/swfA.swf" rel="nofollow noreferrer">http://siteA.com/swfA.swf</a> and <a href="http://siteB.com/swfB.swf" rel="nofollow noreferrer">http://siteB.com/swfB.swf</a>—then, by default, Flash Player does not allow swfA.swf to script swfB.swf, nor swfB.swf to script swfA.swf. A SWF file gives permission to SWF files from other domains by calling Security.allowDomain(). By calling Security.allowDomain("siteA.com"), swfB.swf gives SWF files from siteA.com permission to script it.</p>
</blockquote>
<p>It goes on in some more detail, with diagrams and all.</p>
|
<p>Mayhaps <a href="http://livedocs.adobe.com/flex/15/flex_docs_en/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Flex_Documentation&file=00001750.htm" rel="nofollow noreferrer" title="Flex Documentation: System.Security.allowDomain">System.Security.allowDomain</a> is what you need?</p>
| 3,512
|
<p>If I'm adding a column to a table in Microsoft SQL Server, can I control where the column is displayed logically in queries?</p>
<p>I don't want to mess with the physical layout of columns on disk, but I would like to logically group columns together when possible so that tools like SQL Server Management Studio list the contents of the table in a convenient way.</p>
<p>I know that I can do this through SQL Management Studio by going into their "design" mode for tables and dragging the order of columns around, but I'd like to be able to do it in raw SQL so that I can perform the ordering scripted from the command line.</p>
|
<p>You can not do this programatically (in a safe way that is) without creating a new table. </p>
<p>What Enterprise Manager does when you commit a reordering is to create a new table, move the data and then delete the old table and rename the new table to the existing name. </p>
<p>If you want your columns in a particular order/grouping without altering their physical order, you can create a view which can be whatever you desire.</p>
|
<p>It can be done using SQL, by modifying the system tables directly. For example, look here:</p>
<p><a href="http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=58912" rel="nofollow noreferrer">Alter table - Add new column in between</a></p>
<p>However, I would not recommend playing with system tables, unless it's absolutely necessary.</p>
| 2,394
|
<p>I just saw <a href="http://www.codeplex.com/CloneDetectiveVS" rel="nofollow noreferrer">Clone Detective</a> linked on YCombinator news, and the idea heavily appeals to me. It seems like it would be useful for many languages, not just C#, but I haven't seen anything similar elsewhere.</p>
<p>Edit: For those who don't want to follow the link, Clone Detective scans the codebase for duplicate code that may warrant refactoring to minimize duplication.</p>
|
<p>I don't think this is a concern.</p>
<p>Yes, the mythical "somebody" can replace the implementation of MD5 with something insecure. But in order to do that, the mythical somebody must actually be able to get his code into the Ruby process. And if he can do that, then he presumably could also inject his code into a Java process and e.g. rewrite the bytecode for the MD5 operation. Or just intercept the keypresses and not actually bother with fiddling with the cryptography code at all.</p>
<p>One of the typical concerns is: I'm writing this awesome library, which is supposed to be used like so:</p>
<pre><code>require 'awesome'
# Do something awesome.
</code></pre>
<p>But what if someone uses it like so:</p>
<pre><code>require 'evil_cracker_lib_from_russian_pr0n_site'
# Overrides crypto functions and sends all data to mafia
require 'awesome'
# Now everything is insecure because awesome lib uses
# cracker lib instead of builtin
</code></pre>
<p>And the simple solution is: don't do that! Educate your users that they shouldn't run untrusted code they downloaded from obscure sources in their security critical applications. And if they do, they probably deserve it.</p>
<p>To come back to your Java example: it's true that in Java you can make your crypto code <code>private</code> and <code>final</code> and what not. However, someone can <em>still</em> replace your crypto implementation! In fact, someone actually did: many open-source Java implementations use OpenSSL to implement their cryptographic routines. And, as you probably know, Debian shipped with a broken, insecure version of OpenSSL for years. So, all Java programs running on Debian for the past couple of years actually <em>did</em> run with insecure crypto!</p>
|
<p>If someone monkeypatched an object or a module, then you need to look at 2 cases: He added a new method. If he is the only one adding this meyhod (which is very likely), then no problems arise. If he is not the only one, you need to see if both methods do the same and tell the library developer about this severe problem.</p>
<p>If they change a method, you should start to research why the method was changed. Did they change it due to some edge case behaviour or did they actually fix a bug? especially in the latter case, the monkeypatch is a god thing, because it fixes a bug in many places.</p>
<p>Besides that, you are using a very dynamic language with the assumption that programmers use this freedom in a sane way. The only way to remove this assumption is not to use a dynamic language. </p>
| 5,224
|
<p><a href="https://i.stack.imgur.com/rtG5C.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rtG5C.jpg" alt="enter image description here"></a>
<a href="https://i.stack.imgur.com/i1oaO.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/i1oaO.jpg" alt="enter image description here"></a></p>
<p>I'm getting some slight pooling on the end of straight lines on my Ender-3</p>
<p>Is this due to over extruding? Or some other issue?</p>
|
<p>In Ultimaker Cura you can select only one of the the build plate adhesion options skirt, brim or raft. You cannot select multiple options. </p>
<p>There is no option available in Ultimaker Cura to increase the outline count of the raft bed adhesion structure. Basically the raft exists of a line support structure as can be seen in the figure below.
<a href="https://i.stack.imgur.com/33dg0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/33dg0.png" alt="Ultimaker raft support structure layout"></a>
The line around the lines should be considered "the skirt", so if the nozzle is not properly primed (not sufficient molten filament available), you need to properly prime the nozzle prior to printing.</p>
<p>To prime the nozzle, you need to add some extrusion of filament in your start G-code.</p>
<p>Personally, I like the style of Ultimaker where prior to printing, a puddle of filament is deposited priming the nozzle adequately. Basically you need to move to a position where you like to deposit filament:</p>
<pre><code> G1 X10 Y10 Z2
</code></pre>
<p>Then you need to extrude material</p>
<pre><code> G1 F125
G1 E10
G1 Z3 E5
</code></pre>
<p>After that you can even <a href="/a/6356/5740">wipe</a> the nozzle.</p>
<p>Another option (that requires some copy/pasting from your side and would not be a recommended practice) that is possible is slicing the model with a skirt (with a sufficient distance to stay away from the raft position) instead of a raft and look at the generated G-code and copy the skirt deposition codes into the raft G-code file. You do need to take care of the proper length of the extruder when the skirt followed by the raft, so you need to use <code>G92 Exx.xx</code> where xx.xx is the actual length of the filament start for the raft. </p>
|
<p>It's not necessarily the case that the apparent underextrusion of a small portion of your raft is the root cause. ABS is notorious for shrinkage and peeling. As a start, you should have a full enclosure so as to maintain a warm environment while printing. </p>
<p>It's also quite possible that your bed is slightly off-level or a few microns low for the first layer, either of which can cause adhesion problems. </p>
<p>Yes, it's pretty much trivial to add a few lines of gcode to extrude prior to the "official" raft -- or you could just toss a fake small object into your slicer to extend the raft over both the real and the fake parts. </p>
<p>FWIW, with a little care I've found a wide brim outperforms a raft for almost anything I print</p>
| 1,084
|
<p>In my web app, I submit some form fields with jQuery's <code>$.getJSON()</code> method. I am having some problems with the encoding. The character-set of my app is <code>charset=ISO-8859-1</code>, but I think these fields are submitted with <code>UTF-8</code>. </p>
<p>How I can set encoding used in <code>$.getJSON</code> calls? </p>
|
<p>I think that you'll probably have to use <a href="http://docs.jquery.com/Ajax/jQuery.ajax#options" rel="noreferrer"><code>$.ajax()</code></a> if you want to change the encoding, see the <code>contentType</code> param below (the <code>success</code> and <code>error</code> callbacks assume you have <code><div id="success"></div></code> and <code><div id="error"></div></code> in the html):</p>
<pre><code>$.ajax({
type: "POST",
url: "SomePage.aspx/GetSomeObjects",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: "{id: '" + someId + "'}",
success: function(json) {
$("#success").html("json.length=" + json.length);
itemAddCallback(json);
},
error: function (xhr, textStatus, errorThrown) {
$("#error").html(xhr.responseText);
}
});
</code></pre>
<p>I actually just had to do this about an hour ago, what a coincidence!</p>
|
<p>Use this function to regain the utf-8 characters</p>
<pre><code>function decode_utf8(s) {
return decodeURIComponent(escape(s));
}
</code></pre>
<p>Example:
var new_Str=decode_utf8(str);</p>
| 4,617
|
<p>I am getting the below error and call stack at the same time everyday after several hours of application use. Can anyone shed some light on what is happening?</p>
<pre><code>System.InvalidOperationException: BufferedGraphicsContext cannot be disposed of because a buffer operation is currently in progress.
at System.Drawing.BufferedGraphicsContext.Dispose(Boolean disposing)
at System.Drawing.BufferedGraphicsContext.Dispose()
at System.Drawing.BufferedGraphicsContext.AllocBufferInTempManager(Graphics targetGraphics, IntPtr targetDC, Rectangle targetRectangle)
at System.Drawing.BufferedGraphicsContext.Allocate(IntPtr targetDC, Rectangle targetRectangle)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ToolStrip.WndProc(Message& m)
at System.Windows.Forms.MenuStrip.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
</code></pre>
|
<p>There is a very long MSDN forums discussion of this error <a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=200483&SiteID=1" rel="nofollow noreferrer">here</a>. In most cases the error is apparently associated with either:</p>
<ol>
<li>An underlying OutOfMemory problem, which manifests as the BufferedGraphicsContext exception, possibly due to a framework bug.</li>
<li>A GDI object leak (creating GDI objects and not disposing them).</li>
</ol>
<p>I recall seeing this error myself a year or so ago, and it was definitely associated with a memory problem that made our app fill up all available VM after a long run, so #1 agrees with what I have observed.</p>
|
<p>a shot in the dark - are you painting from multiple threads? If you are doing painting related work, do it on the GUI thread or synchronize your code carefully.</p>
| 8,216
|
<p>How can I go about storing a vb.net user defined object in a sql database. I am not trying to replicate the properties with columns. I mean something along the lines of converting or encoding my object to a byte array and then storing that in a field in the db. Like when you store an instance of an object in session, but I need the info to persist past the current session. </p>
<hr>
<p>@Orion Edwards</p>
<blockquote>
<p>It's not a matter of stances. It's because one day, you will change your code. Then you will try de-serialize the old object, and YOUR PROGRAM WILL CRASH.</p>
</blockquote>
<p>My Program will not "CRASH", it will throw an exception. Lucky for me .net has a whole set of classes dedicated for such an occasion. At which time I will refresh my stale data and put it back in the db. That is the point of this one field (or stance, as the case may be).</p>
|
<p>You can use <a href="http://msdn.microsoft.com/en-us/library/ms973893.aspx" rel="nofollow noreferrer">serialization</a> - it allows you to store your object at least in 3 forms: binary (suitable for BLOBs), XML (take advantage of MSSQL's XML data type) or just plain text (store in varchar or text column) </p>
|
<p>@aku, lomaxx and bdukes - your solutions are what I was looking for. </p>
<p>@1800 INFORMATION - while i appreciate your stance on the matter, this is a special case of data that I get from a webservice that gets refreshed only about once a month. I dont need the data persisted in db form because thats what the webservice is for. Below is the code I finally got to work. </p>
<p>Serialize</p>
<pre><code> #'res is my object to serialize
Dim xml_serializer As System.Xml.Serialization.XmlSerializer
Dim string_writer As New System.IO.StringWriter()
xml_serializer = New System.Xml.Serialization.XmlSerializer(res.GetType)
xml_serializer.Serialize(string_writer, res)
</code></pre>
<p>Deserialize</p>
<pre><code> #'string_writer and xml_serializer from above
Dim serialization As String = string_writer.ToString
Dim string_reader As System.IO.StringReader
string_reader = New System.IO.StringReader(serialization)
Dim res2 As testsedie.EligibilityResponse
res2 = xml_serializer.Deserialize(string_reader)
</code></pre>
| 6,216
|
<p>It may not be best practice but are there ways of removing unsused classes from a third party's jar files. Something that looks at the way in which my classes are using the library and does some kind of coverage analysis, then spits out another jar with all of the untouched classes removed.</p>
<p>Obviously there are issues with this. Specifically, the usage scenario I put it though may not use all classes all the time.</p>
<p>But neglecting these problems, can it be done in principle?</p>
|
<p>There is a way.</p>
<p>The JarJar project does this AFAIR. The first goal of the JarJar project is to allow one to embed third party libraries in your own jar, changing the package structure if necessary. Doing so it can strip out the classes that are not needed.</p>
<p>Check it out at <a href="http://code.google.com/p/jarjar/" rel="noreferrer">http://code.google.com/p/jarjar/</a>.</p>
<p>Here is a link about shrinking jars: <a href="http://sixlegs.com/blog/java/jarjar-keep.html" rel="noreferrer">http://sixlegs.com/blog/java/jarjar-keep.html</a></p>
|
<p>jar is just a zip file, so I guess you can. If you could get to the source, it's cleaner. Maybe try disassembling the class?</p>
| 5,921
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.