instruction
stringlengths 21
27.8k
| chosen
stringlengths 18
28.2k
| rejected
stringlengths 18
33.6k
| __index_level_0__
int64 0
50k
|
|---|---|---|---|
<p>Where may one find references on implementing an algorithm for calculating a "dirty rectangle" for minimizing frame buffer updates? A display model that permits arbitrary edits and computes the minimal set of "bit blit" operations required to update the display.</p>
|
<p>To build the smallest rectangle that contains all the areas that need to be repainted:</p>
<ul>
<li>Start with a blank area (perhaps a rectangle set to 0,0,0,0 - something you can detect as 'no update required')</li>
</ul>
<p>For each dirty area added:</p>
<ul>
<li>Normalize the new area (i.e. ensure that left is less than right, top less than bottom)</li>
<li>If the dirty rectangle is currently empty, set it to the supplied area</li>
<li>Otherwise, set the left and top co-ordinates of the dirty rectangle to the smallest of {dirty,new}, and the right and bottom co-ordinates to the largest of {dirty,new}.</li>
</ul>
<p>Windows, at least, maintains an <em>update region</em> of the changes that it's been informed of, and any repainting that needs to be done due to the window being obscured and revealed. A <em>region</em> is an object that is made up of many possibly discontinuous rectangles, polygons and ellipses. You tell Windows about a part of the screen that needs to be repainted by calling InvalidateRect - there is also an InvalidateRgn function for more complicated areas. If you choose to do some painting before the next WM_PAINT message arrives, and you want to exclude that from the dirty area, there are ValidateRect and ValidateRgn functions.</p>
<p>When you start painting with BeginPaint, you supply a PAINTSTRUCT that Windows fills with information about what needs to be painted. One of the members is the smallest rectangle that contains the invalid region. You can get the region itself using GetUpdateRgn (you must call this before BeginPaint, because BeginPaint marks the whole window as valid) if you want to minimize drawing when there are multiple small invalid areas.</p>
<p>I would assume that, as minimizing drawing was important on the Mac and on X when those environments were originally written, there are equivalent mechanisms for maintaining an update region.</p>
|
<p>To build the smallest rectangle that contains all the areas that need to be repainted:</p>
<ul>
<li>Start with a blank area (perhaps a rectangle set to 0,0,0,0 - something you can detect as 'no update required')</li>
</ul>
<p>For each dirty area added:</p>
<ul>
<li>Normalize the new area (i.e. ensure that left is less than right, top less than bottom)</li>
<li>If the dirty rectangle is currently empty, set it to the supplied area</li>
<li>Otherwise, set the left and top co-ordinates of the dirty rectangle to the smallest of {dirty,new}, and the right and bottom co-ordinates to the largest of {dirty,new}.</li>
</ul>
<p>Windows, at least, maintains an <em>update region</em> of the changes that it's been informed of, and any repainting that needs to be done due to the window being obscured and revealed. A <em>region</em> is an object that is made up of many possibly discontinuous rectangles, polygons and ellipses. You tell Windows about a part of the screen that needs to be repainted by calling InvalidateRect - there is also an InvalidateRgn function for more complicated areas. If you choose to do some painting before the next WM_PAINT message arrives, and you want to exclude that from the dirty area, there are ValidateRect and ValidateRgn functions.</p>
<p>When you start painting with BeginPaint, you supply a PAINTSTRUCT that Windows fills with information about what needs to be painted. One of the members is the smallest rectangle that contains the invalid region. You can get the region itself using GetUpdateRgn (you must call this before BeginPaint, because BeginPaint marks the whole window as valid) if you want to minimize drawing when there are multiple small invalid areas.</p>
<p>I would assume that, as minimizing drawing was important on the Mac and on X when those environments were originally written, there are equivalent mechanisms for maintaining an update region.</p>
| 10,229
|
<p>How do I convert a datetime field in Grails to just date, with out capturing the time? I need to do this for comparison with system date. </p>
<pre><code>class Trip
{
String name
String city
Date startDate
Date endDate
String purpose
String notes
static constraints = {
name(maxLength: 50, blank: false)
startDate(validator: {return (it >= new Date())}) // This won't work as it compares the time as well
city(maxLength: 30, blank: false)
}
}
</code></pre>
|
<p>There's [unfortunately] not an "out-of-the box" method for performing this operation in <code>Grails|Groovy|Java</code>.</p>
<p>Somebody <strong>always</strong> throws in <a href="http://joda-time.sourceforge.net/" rel="noreferrer">Joda-Time</a> any time a <code>java.util.Date</code> or <code>java.util.Calendar</code> question is raised, but including yet another library is not always an option.</p>
<p>Most recently, for a similar problem, we created a <code>DateTimeUtil</code> class with <code>static</code> methods and something like the following to get a <code>Date</code> only:</p>
<pre><code>class DateTimeUtil {
// ...
public static Date getToday() {
return setMidnight(new Date())
}
public static Date getTomorrow() {
return (getToday() + 1) as Date
}
public static Date setMidnight(Date theDate) {
Calendar cal = Calendar.getInstance()
cal.setTime(theDate)
cal.set(Calendar.HOUR_OF_DAY, 0)
cal.set(Calendar.MINUTE, 0)
cal.set(Calendar.SECOND, 0)
cal.set(Calendar.MILLISECOND, 0)
cal.getTime()
}
//...
}
</code></pre>
<p>Then, in the validator, you can use</p>
<pre><code>startDate(validator: {return (it.after(DateTimeUtil.today))}) //Groovy-ism - today implicitly invokes `getToday()`
</code></pre>
|
<p>Maybe </p>
<pre><code>startDate(validator: {d = new Date(); return (it..d) >= 0})
</code></pre>
| 45,450
|
<p>How can I programmatically lock/unlock, or otherwise prevent/enable editing, a source file on Linux using C++.</p>
<p>I want to be able to lock source file so that if I open it in an editor it will not allow me to save back to the same source file.</p>
<p>I am thinking of maybe changing the permissions to read-only (and change it back to read-write later): how do I do that from C++?</p>
|
<p>Try man fchmod:</p>
<pre>
NAME
chmod, fchmod - change permissions of a file
SYNOPSIS
#include <sys/types.h>
#include <sys/stat.h>
int chmod(const char *path, mode_t mode);
int fchmod(int fildes, mode_t mode);
</pre>
|
<p>Why aren't you using a source code management tool like CVS or Subversion? CVS does nice locking (so does Subversion). More importantly, you have the history of changes. Better still (with CVS anyway) you have to make the step of doing a "checkout" to make the file writeable. </p>
| 21,403
|
<p>I have developed in C++ many years ago, but these days I am primarily a Java software engineer. Given I own an iPhone, am ready to spring for a MacBook next month, and am generally interested in getting started with Mac OS developmentmt (using Objective C), I thought I would just put this question out there: What Next?</p>
<p>More specifically, what books should I pick up, and are there any web resources that some folks could point me to? Some books that I am planning to purchase:</p>
<ul>
<li><a href="https://rads.stackoverflow.com/amzn/click/com/0321566157" rel="noreferrer" rel="nofollow noreferrer">Programming in Objective-C 2.0</a></li>
<li><a href="https://rads.stackoverflow.com/amzn/click/com/0321503619" rel="noreferrer" rel="nofollow noreferrer">Cocoa(R) Programming for Mac OS X (3rd Edition)</a></li>
</ul>
<p>Anyone familiar with these titles? Finally, I would be very interested in a summary of what I should be prepared to expect, once I embark on this journey. As someone that develops in Java using IntelliJ IDEA, what are some key differences I will notice as I move over to writing ObjectiveC code in Xcode? What's the differences between Mac OS desktop development and iPhone development? Being used to Java garbage collection, what should I know about ObjectiveC garbage collection / memory management. Any other language specific issues that anyone would like to point out? How about building UIs? Is it closer to Swing, building Visual C++ resource files that code interacts with, or is it more like some of the borland IDEs that will generate code for guis?</p>
|
<p>Having purchased both of the books in your question, I recommend Cocoa Programming for Mac OS X as a quick way to learn the language and the Cocoa framework, and is probably the fastest way to start producing real applications in Cocoa. I highly recommend it. Programming in Objective-C 2.0 is a great reference book, but if you already know C, there's no much it's going to teach you that you can't pick up from the other book. However, if you ever need to a list of all the reserved keywords in Objective-C, that's the book to go to.</p>
<p>All of the user interface can be generated progmatically, but you'll find it much easier to use Interface Builder, which comes with XCode, to lay out the user interface. You'll end up with a lot less code. With bindings, you can even eliminate code which isn't directly related to laying out the interface. The details are in the Cocoa Programming for Mac OS X book.</p>
<p>The one big thing I miss from Java is the collection API. In Cocoa, you just get NSSet, NSArray, and NSDictionary, and there's no analog to the Comparable interface. These classes are also immutable, but have mutable versions such as NSMutableArray.</p>
<p>I actually haven't played with the Garbage Collection in Objective-C 2.0. In previous versions of Objective-C, memory management was handled by the retain, release, and autorelease methods. Objects were created with a retain count of 1. Retaining incremented that count, releasing decremented it, and autoreleasing objects is a little more complicated. Again, the Cocoa Programming book explains it well. Garbage collection is an option, and if it's turned on, the retain, release and autorelease methods do nothing. However, if you are writing a library or framework to be used by others, you should program it as if garbage collection is turned off. That way applications can use it whether or not they have garbage collection turned on.</p>
<p>As for Web resources, <a href="http://cocoadevcentral.com/" rel="noreferrer">http://cocoadevcentral.com/</a> is a great site with beginner tutorials. The CocoaDev Wiki at <a href="http://www.cocoadev.com/" rel="noreferrer">http://www.cocoadev.com/</a> contains detailed information on a lot of topics, and you can usually find some useful information and people on the cocoa-dev mailing list <a href="http://lists.apple.com/mailman/listinfo/cocoa-dev" rel="noreferrer">http://lists.apple.com/mailman/listinfo/cocoa-dev</a></p>
<p>iPhone development is a little different, and the details are restricted by an NDA. However, if you get approved by Apple to get access to the iPhone developer center, Apple has provided some great video overviews of the differences, which point you to the documentation you need to make the jump from Mac OS X to iPhone OS X programming.</p>
|
<p>Another option for you is jaiPhon, which allows you to write java apps that get translated into iPhone-speak at build time.</p>
<p>I don't know if it's availanle yet, or if it's commercial-ware or whatever, but it's interesting none the less.</p>
<p><a href="http://www.jaiphon.com/" rel="nofollow noreferrer">http://www.jaiphon.com/</a></p>
| 16,363
|
<p>I am implementing a class to compare directory trees (in C#). At first I implemented the actual comparison in the class's constructor. Like this:</p>
<pre><code>DirectoryComparer c = new DirectoryComparer("C:\\Dir1", "C:\\Dir2");
</code></pre>
<p>But it doesn't feel "right" to do a possible lengthy operation in the constructor. An alternative way is to make the constructor private and add a static method like this:</p>
<pre><code>DirectoryComparer c = DirectoryComparer.Compare("C:\\Dir1", "C:\\Dir2");
</code></pre>
<p>What do you think? Do you expect a constructor to be "quick"? Is the second example better or is it just complicating the usage of the class?</p>
<p><strong>BTW:</strong> </p>
<p>I wont mark any answer as accepted because I don't think there is a correct answer, just preference and taste.</p>
<p><strong>Edit:</strong></p>
<p>Just to clarify my example a little. I'm not only insterested if the directories differs, I'm also interested in how they differ (which files). So a simple int return value wont be enough. The answer by cdragon76.myopenid.com actually is pretty close to what I want (+1 to you).</p>
|
<p>I would think a combination of the two is the "right" choice, as I would expect the Compare method to return the comparison result, not the comparer itself.</p>
<pre><code>DirectoryComparer c = new DirectoryComparer();
int equality = c.Compare("C:\\Dir1", "C:\\Dir2");
</code></pre>
<p>...and as Dana mentions, there is an <a href="http://msdn.microsoft.com/en-us/library/8ehhxeaf.aspx" rel="nofollow noreferrer">IComparer</a> interface in .Net that reflects this pattern.</p>
<p>The <a href="http://msdn.microsoft.com/en-us/library/xh5ks3b3.aspx" rel="nofollow noreferrer">IComparer.Compare</a> method returns an int since the use of IComparer classes is primarily with sorting. The general pattern though fits the problem of the question in that:</p>
<ol>
<li>Constructor initializes an instance with (optionally) "configuring" parameters</li>
<li>Compare method takes two "data" parameters, compares them and returns a "result"</li>
</ol>
<p>Now, the result can be an int, a bool, a collection of diffs. Whatever fits the need.</p>
|
<p>If you are working with C#, you could use extension methods to create a method for comparing 2 directories that you would attach to the build in DirectoryClass, so it would look some thing like:</p>
<pre><code>Directory dir1 = new Directory("C:\.....");
Directory dir2 = new Directory("D:\.....");
DirectoryCompare c = dir1.CompareTo(dir2);
</code></pre>
<p>This would be much clearer implementation.
More on extension methods <a href="http://www.developer.com/net/csharp/article.php/3592216" rel="nofollow noreferrer">here</a>.</p>
| 33,936
|
<p>I know you can use the <code><jsp:useBean></code> tag to instantiate objects within JSPs without resorting to scriptlet code. However I'd like to instantiate an Integer who value is the result of an EL expression, something like:</p>
<pre><code><jsp:useBean id="total" class="java.lang.Integer">
<jsp:setProperty name="amount" value="${param1 + param2}"/>
</jsp:useBean>
</code></pre>
<p>Of course this won't work because Integer objects don't have a property named 'amount', the only way their value can be set is via a constructor parameter (i.e. Integer objects are immutable). Is there any way to instantiate such an object and set it's value without using scriptlet code?</p>
<p>Thanks,
Don</p>
|
<p><strong><code><c:set var="amount" value="${param1 + param2}" scope="page" /></code></strong></p>
|
<p>If you have a bean, can you just update the bean with param1 and 2? Create a method, setAmount(param1, param2), and set it before you use getAmount(), which is what the bean is going to call.</p>
| 45,705
|
<p>I am connecting to CRM with the intention of retrieving a list of picklist values. On my development machine I am working under my own login name and all works fine. On the test server, the code executes under the NETWORK SERVICE account. When it connects to the CRM web service everything is great. When it connects to the metadata service I get 401 Unauthorised messages.</p>
<p>This is the first time I have used the metadata service so I am hoping someone can tell me why I get the error. The connection is configured using the code below and the failure happens when you try to retrieve the picklist data.</p>
<pre><code>CrmAuthenticationToken token = new CrmAuthenticationToken();
token.OrganizationName = config.AppSettings.Settings["CrmTargetOrganisation"].Value;
token.AuthenticationType = 0;
MetadataService service = new MetadataService();
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
service.Url = config.AppSettings.Settings["CrmMetadataServiceUrl"].Value;
service.CrmAuthenticationTokenValue = token;
service.UnsafeAuthenticatedConnectionSharing = true;
</code></pre>
|
<p>I suspect it might be a Kerberos / delegation issue, to make sure it is try replacing DefaultCredentials with
new System.Security.Net.NetworkCredentials("username","password","domain");</p>
<p>See if that still gives you a 401.</p>
<p>This is the quick way I normally try to see if it is kerbos/security related. </p>
<p>I need a bit more information about your environment to make any other intelligent comments. </p>
<p>Hope it helps.</p>
|
<p>In my case (yes, we still use CRM 4), the website in IIS wasn't bound to the hostname being used to access the metadata service on port 5555.</p>
| 24,990
|
<p>I build and maintain a set of Flash components that is distributed to publishers and allows them to integrate with our system. Currently the component has no UI and simply contains compiled code for querying our system servers, parsing the response, and modifying the params sent in the query. There's an As2 version and AS3 versions for both Flex and CS3. Our typical workflow is like this:</p>
<p>1.) load the component
2.) set parameters on the component
3.) tell the component to query our system
4.) wait for an event saying the response has been received and parsed
5.) call methods on the component for retrieving and using parsed data </p>
<p>We've been talking a lot lately about automating the testing of these components, and there seems to be a lot of buzz around frameworks like AsUnit and FlexUnit. However, I've never been able to grasp how I might effectively use of one of these. The examples and tutorials always skimp on real-world examples and instead provide multiple classes and excessive code for testing whether an example function returns num1+num2. </p>
<p>The only thing I can guess is that these testing frameworks are intended to be implemented from the start, with planning for the test suite, test runner, and test cases built in at the start of development. </p>
<p>An automated test of our component would have to make sure properties were properly set, those properties were sent in the request to our system, the response received was correct considering the parameters sent, the parsed data includes correct information, and no errors, bad responses, or infinite parsing loops are caused. </p>
<p>my question is, is there any way to automate testing of an existing, widely distributed, established Flash component without completely reworking it to fit into a testing framework? Or am I misunderstanding the test frameworks and this is already possible? </p>
<p><strong>UPDATE</strong>: Thanks for the responses. I have started to integrate my component with AsUnit and think I have a pretty good understanding of how it can help me. However, the AS2 AsUnit does not support asynchronous test cases, and I'm having a hard time finding an AS2 unit test framework that does. Asynchronous testing is REALLY important to this project. Does anyone have any recommendations for a different framework? Thanks! </p>
|
<p>We're using FlexUnit on our project and I'm pretty happy with it. Assuming your project was designed with a fairly loose degree of coupling, you shouldn't need to change much at all (if anything) in order to test your code. If you're already using an MVC framework like <a href="http://opensource.adobe.com/wiki/display/cairngorm/Cairngorm" rel="nofollow noreferrer">Cairngorm</a> or <a href="http://puremvc.org/" rel="nofollow noreferrer">PureMVC</a>, FlexUnit should integrate pretty painlessly.</p>
<p>I will say however that my experience with Flash/Flex unit testing is not nearly as positive as it has been with other languages such as Ruby or .NET for three reasons. First being that such a high degree of actionscript code is UI related, and this sort of code is difficult if not impossible to test. Another reason is that the test runner doesn't lend itself well to being plugged into a continuous integration environment such as <a href="http://confluence.public.thoughtworks.org/display/CCNET/Welcome+to+CruiseControl.NET" rel="nofollow noreferrer">CruiseControl.NET</a> or <a href="http://cruisecontrolrb.thoughtworks.com/" rel="nofollow noreferrer">CruiseControl.rb</a> since it requires a human to run it and click buttons. Lastly, a huge benefit of unit testing is usually that you can run it alongside a coverage analysis tool such as <a href="http://www.ncover.com/" rel="nofollow noreferrer">NCover</a> or <a href="http://rubyforge.org/projects/rcov/" rel="nofollow noreferrer">rcov</a>. Flash/Flex doesn't lend itself to this sort of analysis with out a modified compiler such as <a href="http://code.google.com/p/flexcover/" rel="nofollow noreferrer">Flexcover</a>.</p>
|
<p>While I never had the chance to work with a unit tester in actionscript, at work we created a framework which:</p>
<ol>
<li>compiled the script(s) inside a test application, in our case with flex</li>
<li>set up a timer (watchdog) application, in case of loop failure</li>
<li>ran the application which, in turn:
<ul>
<li>connected to a PHP backend to get a test case</li>
<li>fed the test to the component</li>
<li>read the results and sent them back</li>
</ul></li>
<li>the watchdog would kick in and kill the application on whichever happened first:
<ul>
<li>timer ran out (reasonable timeout)</li>
<li>application sent back the results</li>
</ul></li>
<li>if there were other tests to run, goto 2.</li>
</ol>
<p>Definitely not elegant, but did the job (this was with AS1 scripts)</p>
| 27,025
|
<p>We have a database that many persons have to have access to. I am looking for a way that will allow us to get notification whenever "alter" occurs on this database, so other parties can be aware of it. Please advise.</p>
|
<p>You can create TRIGGERs to catch a number of database events...</p>
<p><a href="http://www.psoug.org/reference/ddl_trigger.html" rel="nofollow noreferrer">http://www.psoug.org/reference/ddl_trigger.html</a></p>
<p>...including before/after an ALTER on a schema.</p>
|
<p>ALTER what ?</p>
<p>ALTER SESSION may be a very common command (especially ALTER SESSION SET NLS_DATE_FORMAT or CURRENT_SCHEMA).</p>
<p>More commonly you'd be want to track ALTER schema_object, maybe ALTER SYSTEM and ALTER DATABASE</p>
| 32,639
|
<p>About two months ago, I added a heated bed to my custom 3D printer in order to print larger ABS parts for my research project. The heated bed (the PCB kind) was not new, but taken from an old printer I had built, but took apart. The bed worked well for a few weeks, but after one print finished, the glass bed above the heater PCB had shattered into several pieces (represented by bed 1 in the image below) and the nozzle was below the level of the bed (I believed it had lowered into the glass causing the breakage. I haven't determined what caused this motion, but it hasn't happened since). Notably, this print was using the heated bed at 90 °C. I chalked this up to a freak accident, and since it did not happen again, just replaced the glass and kept printing.</p>
<p>However, as soon as the heated bed was activated after the replacement, a small crack appeared on the glass and continued to lengthen as time progressed. I took off the glass as soon as possible and prevented it from fully breaking (see bed 2 in the image below. This bed was smaller as I didn't have access to a large enough piece of glass at the time).</p>
<p>At this point, I figured something more than an impact caused the glass to shatter. Since both cracks occurred when the bed was heating or cooling, I figured that thermal shock could potentially be the source of the cracking, and a quick google reinforced this idea. Due to the nature of both cracks (not being straight shards but meandering around the build plate and propagating slowly), they both appeared to have been caused, or at least propagated, by thermal effects.</p>
<p>To try to avoid future cracking, I took care in assembling the third bed. The heater PCB was attached tightly to the glass with Kapton tape and a thin layer of thermal paste was added as an interface layer to try to get an even contact and heat distribution throughout the glass plate. I made sure that the cardboard shims (which press the glass into the clips) were not too compressed, thinking that pressure in the middle of the glass plate from the shims may have accentuated the cracking by putting the top of the glass under tension.</p>
<p>But after a few cycles with this new bed, the same problem appeared (bed 3 below). This time, the cracking was as severe as the first case, but no impact occurred and I was not touching the bed. The bed was heating up to temperature (90 °C) when the cracking occurred. The strangest part is, the file set to print was one I had already printed successfully on the newest bed.</p>
<p>At this point I am at a loss and don't know what to do next. I don't want to make another bed just to have it crack in a few prints, but I need the bed in the near future. Any suggestions to mitigate this problem would be greatly appreciated.</p>
<p><a href="https://i.stack.imgur.com/QRWws.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QRWws.jpg" alt="The three shattered build plates" /></a></p>
<p><strong>Update (currently fixed)</strong></p>
<p>I have replaced the bed with a borosilicate glass sheet, switched the heater to a stick-on 120V silicone heater (the same size as the bed), and added a PEI sheet on top. After about 2 months, it is working great and no cracks have formed. My best guess is that it was a combination of poor glass, possibly with small fractures on the edges already since I cut it myself, and the heater which was too small for the bed. Thanks for the suggestions!</p>
|
<p>The problem is in the design of your bed. Let's start from the basic setup of a glass bed:</p>
<p>The heater element is usually mounted to a metal carrier, which is both spreading the thermal energy over the bed, but also is the structural element that is leveled against the carriage. Atop that comes the glass print surface.</p>
<p>Now, once the heater element is turned on, the aluminium starts to expand and evens the distribution to the glass. As the glass has a much lower thermal expansion coefficient, it doesn't expand as fast. Because of this, the glass surface should <strong>never</strong> be glued to the bed or heater but held in position to the metal bed with a clip. This way the thermal and mechanical stress on the glass sheet is mitigated: The metal bed evens the heat transfer and the clip can move its position on the glass.</p>
|
<p>I would be careful before trying another glass just hoping it will go better, since you haven't found the issue.</p>
<p>I have a PCB heated bed in direct contact (PCB copper traces on top) a 2 mm glass (plain float glass, not hardened and not borosilicate). It never broke and I've been using it intensely for the last few months. My heated bed is very flat (even if it bends with the heat) and also clean: no residues which can push against the glass. Clean yours properly!</p>
<p>Also, how powerful is your heated bed? mine is about 120 W for 12x12 cm. If yours is too powerful, maybe you could slow down the heating by reducing the maximum duty cycle (you need maybe to recompile Marlin) or by increasing the temperature 10 °C at time. </p>
<p>I also see that you use mirrors, maybe recovered from other applications. I bought the glass new, which is very cheap but it is also guaranteed defect free. Maybe yours had issues already.</p>
| 1,672
|
<p>I have found an interesting issue in windows which allows me to cause the Windows clock (but not the hardware clocks) to run fast - as much as 8 seconds every minute. I am doing some background research to work out how Windows calculates and updates it's internal time (not how it syncs with an NTP servers). Any information anyone has or any documents you can point me to would be greatly appreciated!</p>
<p>Also, if anyone knows how _ftime works please let me know.</p>
|
<p><a href="http://msdn.microsoft.com/en-us/library/ms724961(VS.85).aspx" rel="nofollow noreferrer">This MSDN article</a> gives a very brief description of how the system time is handled: "When the system first starts, it sets the system time to a value based on the real-time clock of the computer and then regularly updates the time." Another interesting function is <a href="http://msdn.microsoft.com/en-us/library/ms724394.aspx" rel="nofollow noreferrer">GetSystemTimeAdjustment</a>, which has this to say:</p>
<blockquote>
<p>A value of TRUE [for lpTimeAdjustmentDisabled] indicates that periodic time adjustment is disabled. At each clock interrupt, the system merely adds the interval between clock interrupts to the time-of-day clock. The system is free, however, to adjust its time-of-day clock using other techniques. Such other techniques may cause the time-of-day clock to noticeably jump when adjustments are made.</p>
</blockquote>
<p>Finally, in regard to _ftime, it appears to be implemented using <a href="http://msdn.microsoft.com/en-us/library/ms724397(VS.85).aspx" rel="nofollow noreferrer">GetSystemTimeAsFileTime</a>. So it would wrap directly onto the same built-in time facilities as would be used everywhere else.</p>
|
<p>_ftime doesn't use at all GetSystemTimeAsFileTime.
Just read the source code.</p>
| 26,134
|
<p>In the tradition of <a href="https://stackoverflow.com/questions/309492/user-defined-functions-sql-server-2005-flagged-incorrectly-as-non-deterministic">this question</a> and in light of <a href="http://msdn.microsoft.com/en-us/library/ms178091(SQL.90).aspx" rel="nofollow noreferrer">the documentation</a>, how does one make this function deterministic:</p>
<pre><code>ALTER FUNCTION [udf_DateTimeFromDataDtID]
(
@DATA_DT_ID int -- In form YYYYMMDD
)
RETURNS datetime
WITH SCHEMABINDING
AS
BEGIN
RETURN CONVERT(datetime, CONVERT(varchar, @DATA_DT_ID))
END
</code></pre>
<p>Or this one (because of the string/date literals - and yes, I've also tried '1900-01-01'):</p>
<pre><code>ALTER FUNCTION udf_CappedDate
(
@DateTimeIn datetime
)
RETURNS datetime
WITH SCHEMABINDING
AS
BEGIN
IF @DateTimeIn < '1/1/1900'
RETURN '1/1/1900'
ELSE IF @DateTimeIn > '1/1/2100'
RETURN '1/1/2100'
RETURN @DateTimeIn
END
</code></pre>
|
<p>BOL says that <code>CONVERT</code> <em>is</em> deterministic with datetimes if the <em>style</em> parameter is specified. So if you change the first UDF to:</p>
<pre><code>RETURN CONVERT(datetime, CONVERT(varchar, @DATA_DT_ID), 112)
</code></pre>
<p>Then it <em>should</em> be deterministic, if I understand the docs correctly.</p>
<p>Presumably, the same trick could be used in your second UDF:</p>
<pre><code>IF @DateTimeIn < CONVERT(datetime, '1/1/1900', 101)
RETURN CONVERT(datetime, '1/1/1900', 101)
</code></pre>
<p>I <strong><em>really</em></strong> wish there were a way to specify datetime literals in T-SQL.</p>
<p><strong>EDIT</strong>:</p>
<p>As pointed out by Arvo in the comments (<strong>thank you</strong>, Arvo), the ODBC timestamp literal format can be used (even when using OLE DB) so the second function above could be better written as:</p>
<pre><code>IF @DateTimeIn < {d '1900-01-01'}
RETURN {d '1900-01-01'}
...etc.
</code></pre>
<p>and the conversion to datetime is done at compile time instead of execution time. Note that the format of the date has to be very specific (see <a href="http://msdn.microsoft.com/en-us/library/ms187819.aspx" rel="noreferrer">Arvo's link to the datetime data type</a>):</p>
<blockquote>
<p> d yyyy-mm-dd<br>
t hh:mm:ss[.fff]<br>
ts yyyy-mm-dd hh:mm:ss[.fff]</p>
</blockquote>
|
<p>From the articles you linked:</p>
<blockquote>
<p>To be deterministic, the style parameter must be a constant. Additionally, styles less than or equal to 100 are nondeterministic, except for styles 20 and 21. Styles greater than 100 are deterministic, except for styles 106, 107, 109 and 113.</p>
</blockquote>
<p>You need to use a style parameter in your conversions to datetime.</p>
<p>For example:</p>
<pre><code>CONVERT(datetime, '2008-01-01', 121)
</code></pre>
<p>Except don't use 121...</p>
| 39,954
|
<p>For whatever reason, our company has a coding guideline that states:</p>
<p><code>Each class shall have it's own header and implementation file.</code></p>
<p>So if we wrote a class called <code>MyString</code> we would need an associated <strong>MyStringh.h</strong> and <strong>MyString.cxx</strong>.</p>
<p>Does anyone else do this? Has anyone seen any compiling performance repercussions as a result? Does 5000 classes in 10000 files compile just as quickly as 5000 classes in 2500 files? If not, is the difference noticeable?</p>
<p>[We code C++ and use GCC 3.4.4 as our everyday compiler]</p>
|
<p>The term here is <strong>translation unit</strong> and you really want to (if possible) have one class per translation unit ie, one class implementation per .cpp file, with a corresponding .h file of the same name.</p>
<p>It's usually more efficient (from a compile/link) standpoint to do things this way, especially if you're doing things like incremental link and so forth. The idea being, translation units are isolated such that, when one translation unit changes, you don't have to rebuild a lot of stuff, as you would have to if you started lumping many abstractions into a single translation unit.</p>
<p>Also you'll find many errors/diagnostics are reported via file name ("Error in Myclass.cpp, line 22") and it helps if there's a one-to-one correspondence between files and classes. (Or I suppose you could call it a 2 to 1 correspondence).</p>
|
<p>I'm surprised that almost everyone is in favor of having one file per class. The problem with that is that in the age of 'refactoring' one may have a hard time keeping the file and class names in synch. Everytime you change a class name, you then have to change the file name too, which means that you have to also make a change everywhere the file is included. </p>
<p>I personally group related classes into a single files and then give such a file a meaningful name that won't have to change even if a class name changes. Having fewer files also makes scrolling through a file tree easier.
I use Visual Studio on Windows and Eclipse CDT on Linux, and both have shortcut keys that take you straight to a class declaration, so finding a class declaration is easy and quick. </p>
<p>Having said that, I think once a project is completed, or its structure has 'solidified', and name changes become rare, it may make sense to have one class per file. I wish there was a tool that could extract classes and place them in distinct .h and .cpp files. But I don't see this as essential.</p>
<p>The choice also depends on the type of project one works on. In my opinion the issue doesn't deserve a black and white answer since either choice has pros and cons. </p>
| 4,780
|
<p>I have sproc 'up_selfassessform_view' which has the following parameters:</p>
<pre><code>in ai_eqidentkey SYSKEY
in ai_acidentkey SYSKEY
out as_eqcomments TEXT_STRING
out as_acexplanation TEXT_STRING
</code></pre>
<p> - which are domain objects - SYSKEY is 'integer' and TEXT_STRING is 'long varchar'.</p>
<p>I can call the sproc fine from iSQL using the following code:</p>
<pre><code>create variable @eqcomments TEXT_STRING;
create variable @acexamples TEXT_STRING;
call up_selfassessform_view (75000146, 3, @eqcomments, @acexamples);
select @eqcomments, @acexamples;
</code></pre>
<p> - which returns the correct values from the DB (so I know the SPROC is good).</p>
<p>I have configured the out param in ADO.NET like so (which has worked up until now for 'integer', 'timestamp', 'varchar(255)', etc):</p>
<pre><code>SAParameter as_acexplanation = cmd.CreateParameter();
as_acexplanation.Direction = ParameterDirection.Output;
as_acexplanation.ParameterName = "as_acexplanation";
as_acexplanation.SADbType = SADbType.LongVarchar;
cmd.Parameters.Add(as_acexplanation);
</code></pre>
<p>When I run the following code:</p>
<pre><code>SADataReader reader = cmd.ExecuteReader();
</code></pre>
<p>I receive the following error:</p>
<pre><code>Parameter[2]: the Size property has an invalid size of 0.
</code></pre>
<p>Which (I suppose) makes sense...</p>
<p>But the thing is, I don't know the size of the field (it's just "long varchar" it doesn't have a predetermined length - unlike varchar(XXX)).</p>
<p>Anyhow, just for fun, I add the following:</p>
<pre><code>as_acexplanation.Size = 1000;
</code></pre>
<p>and the above error goes away, but now when I call:</p>
<pre><code>as_acexplanation.Value
</code></pre>
<p>i get back a string of length = 1000 which is just '\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0...' (\0 repeated 1000 times).</p>
<p>So I'm really really stuck... Any help one this one would be much appreciated.</p>
<p>Cheers! ;)</p>
<p>Tod T.</p>
|
<p>Minix 3 is a new version; LINUX was prompted on the original Minix.</p>
<p>Minix is really best suited to small systems of embedded systems. If you have an old x86 PC around it should run minix handily, giving you an environment very much like what we called "an amazing workstation" in the mid-80's. </p>
<p>I loved programming in that environment; I'd say go for it, but remember that it is an experimenal environment, not what you want for your day-to-day system.</p>
|
<p>Coded round robin scheduler and such with nano, SSH connection can be used to code in new fashion platforms and send back the files. Minix is a great way to learn basics about Operating Systems. </p>
| 39,108
|
<p>I start using the visual studio c++ express 2008 at home but there is no ATL in it.<br>
How can I add ATL to visual studio c++ express 2008? </p>
|
<p>ATL 7.1 is now part of the <a href="http://www.microsoft.com/whdc/DevTools/WDK/WDKpkg.mspx" rel="noreferrer">Windows Driver Kit</a>. </p>
|
<p>You'll need to download the platform SDK and muck around with some dependencies to get ATL.</p>
<p>There might be some more "unsavory" ways to get MFC ;) if you catch my drift. Also many institutions have educational VS licenses which are free.</p>
| 9,720
|
<p>What's the most efficient way to convert the output of this function from a varbinary() to a a varchar()?</p>
|
<p>How about this:</p>
<pre><code>master.sys.fn_varbintohexstr(@binvalue)
</code></pre>
|
<p>CONVERT(varchar, @binary)</p>
| 9,909
|
<p>I like Django, but for a particular application I would like to use only parts of it, but I'm not familiar enough with how Django works on the inside, so maybe someone can point me into the right direction as to what I have to check out.</p>
<p>Specifically, I <i>want to use</i>:</p>
<ul>
<li>The models and database abstraction</li>
<li>The <a href="http://docs.djangoproject.com/en/dev/topics/cache/#the-low-level-cache-api" rel="noreferrer">caching API</a>, although I want to avoid database lookups by caching, not HTML generation, and since the caching framework in Django is intended for the latter, I'm not sure yet whether that's really appropriate.</li>
</ul>
<p>I would <i>not use</i>:</p>
<ul>
<li>Templating</li>
<li>urlconfigs</li>
</ul>
<p>Or, more exactly, I'm neither using HTTP nor HTML. So basically, I have a different input / output chain than usual.</p>
<p>Can this work?</p>
<p>My personal killer feature in Django is the Object / database mapping that I can do with the models, so if there's another technology (doesn't have to be Python, I'm in the design phase and I'm pretty agnostic about languages and platforms) that gives me the same abilities, that would be great, too.</p>
|
<p>I myself use Django for its object/db mapping without using its urlconfigs. Simply create a file called <code>djangosettings.py</code> and insert the necessary configuration, for example:</p>
<pre><code>DATABASE_ENGINE = 'oracle'
DATABASE_HOST = 'localhost'
DATABASE_NAME = 'ORCL'
DATABASE_USER = 'scott'
DATABASE_PASSWORD = 'tiger'
</code></pre>
<p>Then in your regular Python code, do</p>
<pre><code>import os
os.environ["DJANGO_SETTINGS_MODULE"] = "djangosettings"
</code></pre>
<p>before you import any Django modules. This will let you use Django's object/db mappings without actually having a Django project, so you can use it for standalone scripts or other web applications or whatever you want.</p>
<p>As for caching, if you don't want to use Django then you should probably decide what you are using and go from there. I recommend using CherryPy, which doesn't use Django-style regular expression URL mapping, but instead automatically maps URLs to functions based on the function names. There's an example right at the top of the CherryPy home page: <a href="http://cherrypy.org/" rel="noreferrer">http://cherrypy.org/</a></p>
<p>CherryPy has its own caching system, so you can accomplish exactly the same thing as what Django does but without needing to use Django's urlconfig system.</p>
|
<p>I've shared an example of solution, which prevents Python Path manipulation inside code:</p>
<p><a href="https://github.com/askalyuk/django-orm-standalone" rel="nofollow">https://github.com/askalyuk/django-orm-standalone</a></p>
<p>It contains a standalone data access package, a separated simple Django site and a unit test.</p>
| 38,872
|
<p>I'm writing a Spring web application that requires users to login. My company has an Active Directory server that I'd like to make use of for this purpose. However, I'm having trouble using Spring Security to connect to the server.</p>
<p>I'm using Spring 2.5.5 and Spring Security 2.0.3, along with Java 1.6.</p>
<p>If I change the LDAP URL to the wrong IP address, it doesn't throw an exception or anything, so I'm wondering if it's even <em>trying</em> to connect to the server to begin with.</p>
<p>Although the web application starts up just fine, any information I enter into the login page is rejected. I had previously used an InMemoryDaoImpl, which worked fine, so the rest of my application seems to be configured correctly.</p>
<p>Here are my security-related beans:</p>
<pre><code> <beans:bean id="ldapAuthProvider" class="org.springframework.security.providers.ldap.LdapAuthenticationProvider">
<beans:constructor-arg>
<beans:bean class="org.springframework.security.providers.ldap.authenticator.BindAuthenticator">
<beans:constructor-arg ref="initialDirContextFactory" />
<beans:property name="userDnPatterns">
<beans:list>
<beans:value>CN={0},OU=SBSUsers,OU=Users,OU=MyBusiness,DC=Acme,DC=com</beans:value>
</beans:list>
</beans:property>
</beans:bean>
</beans:constructor-arg>
</beans:bean>
<beans:bean id="userDetailsService" class="org.springframework.security.userdetails.ldap.LdapUserDetailsManager">
<beans:constructor-arg ref="initialDirContextFactory" />
</beans:bean>
<beans:bean id="initialDirContextFactory" class="org.springframework.security.ldap.DefaultInitialDirContextFactory">
<beans:constructor-arg value="ldap://192.168.123.456:389/DC=Acme,DC=com" />
</beans:bean>
</code></pre>
|
<p>I had the same banging-my-head-against-the-wall experience you did, and ended up writing a custom authentication provider that does an LDAP query against the Active Directory server.</p>
<p>So my security-related beans are:</p>
<pre><code><beans:bean id="contextSource"
class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
<beans:constructor-arg value="ldap://hostname.queso.com:389/" />
</beans:bean>
<beans:bean id="ldapAuthenticationProvider"
class="org.queso.ad.service.authentication.LdapAuthenticationProvider">
<beans:property name="authenticator" ref="ldapAuthenticator" />
<custom-authentication-provider />
</beans:bean>
<beans:bean id="ldapAuthenticator"
class="org.queso.ad.service.authentication.LdapAuthenticatorImpl">
<beans:property name="contextFactory" ref="contextSource" />
<beans:property name="principalPrefix" value="QUESO\" />
</beans:bean>
</code></pre>
<p>Then the LdapAuthenticationProvider class:</p>
<pre><code>/**
* Custom Spring Security authentication provider which tries to bind to an LDAP server with
* the passed-in credentials; of note, when used with the custom {@link LdapAuthenticatorImpl},
* does <strong>not</strong> require an LDAP username and password for initial binding.
*
* @author Jason
*/
public class LdapAuthenticationProvider implements AuthenticationProvider {
private LdapAuthenticator authenticator;
public Authentication authenticate(Authentication auth) throws AuthenticationException {
// Authenticate, using the passed-in credentials.
DirContextOperations authAdapter = authenticator.authenticate(auth);
// Creating an LdapAuthenticationToken (rather than using the existing Authentication
// object) allows us to add the already-created LDAP context for our app to use later.
LdapAuthenticationToken ldapAuth = new LdapAuthenticationToken(auth, "ROLE_USER");
InitialLdapContext ldapContext = (InitialLdapContext) authAdapter
.getObjectAttribute("ldapContext");
if (ldapContext != null) {
ldapAuth.setContext(ldapContext);
}
return ldapAuth;
}
public boolean supports(Class clazz) {
return (UsernamePasswordAuthenticationToken.class.isAssignableFrom(clazz));
}
public LdapAuthenticator getAuthenticator() {
return authenticator;
}
public void setAuthenticator(LdapAuthenticator authenticator) {
this.authenticator = authenticator;
}
}
</code></pre>
<p>Then the LdapAuthenticatorImpl class:</p>
<pre><code>/**
* Custom Spring Security LDAP authenticator which tries to bind to an LDAP server using the
* passed-in credentials; does <strong>not</strong> require "master" credentials for an
* initial bind prior to searching for the passed-in username.
*
* @author Jason
*/
public class LdapAuthenticatorImpl implements LdapAuthenticator {
private DefaultSpringSecurityContextSource contextFactory;
private String principalPrefix = "";
public DirContextOperations authenticate(Authentication authentication) {
// Grab the username and password out of the authentication object.
String principal = principalPrefix + authentication.getName();
String password = "";
if (authentication.getCredentials() != null) {
password = authentication.getCredentials().toString();
}
// If we have a valid username and password, try to authenticate.
if (!("".equals(principal.trim())) && !("".equals(password.trim()))) {
InitialLdapContext ldapContext = (InitialLdapContext) contextFactory
.getReadWriteContext(principal, password);
// We need to pass the context back out, so that the auth provider can add it to the
// Authentication object.
DirContextOperations authAdapter = new DirContextAdapter();
authAdapter.addAttributeValue("ldapContext", ldapContext);
return authAdapter;
} else {
throw new BadCredentialsException("Blank username and/or password!");
}
}
/**
* Since the InitialLdapContext that's stored as a property of an LdapAuthenticationToken is
* transient (because it isn't Serializable), we need some way to recreate the
* InitialLdapContext if it's null (e.g., if the LdapAuthenticationToken has been serialized
* and deserialized). This is that mechanism.
*
* @param authenticator
* the LdapAuthenticator instance from your application's context
* @param auth
* the LdapAuthenticationToken in which to recreate the InitialLdapContext
* @return
*/
static public InitialLdapContext recreateLdapContext(LdapAuthenticator authenticator,
LdapAuthenticationToken auth) {
DirContextOperations authAdapter = authenticator.authenticate(auth);
InitialLdapContext context = (InitialLdapContext) authAdapter
.getObjectAttribute("ldapContext");
auth.setContext(context);
return context;
}
public DefaultSpringSecurityContextSource getContextFactory() {
return contextFactory;
}
/**
* Set the context factory to use for generating a new LDAP context.
*
* @param contextFactory
*/
public void setContextFactory(DefaultSpringSecurityContextSource contextFactory) {
this.contextFactory = contextFactory;
}
public String getPrincipalPrefix() {
return principalPrefix;
}
/**
* Set the string to be prepended to all principal names prior to attempting authentication
* against the LDAP server. (For example, if the Active Directory wants the domain-name-plus
* backslash prepended, use this.)
*
* @param principalPrefix
*/
public void setPrincipalPrefix(String principalPrefix) {
if (principalPrefix != null) {
this.principalPrefix = principalPrefix;
} else {
this.principalPrefix = "";
}
}
}
</code></pre>
<p>And finally, the LdapAuthenticationToken class:</p>
<pre><code>/**
* <p>
* Authentication token to use when an app needs further access to the LDAP context used to
* authenticate the user.
* </p>
*
* <p>
* When this is the Authentication object stored in the Spring Security context, an application
* can retrieve the current LDAP context thusly:
* </p>
*
* <pre>
* LdapAuthenticationToken ldapAuth = (LdapAuthenticationToken) SecurityContextHolder
* .getContext().getAuthentication();
* InitialLdapContext ldapContext = ldapAuth.getContext();
* </pre>
*
* @author Jason
*
*/
public class LdapAuthenticationToken extends AbstractAuthenticationToken {
private static final long serialVersionUID = -5040340622950665401L;
private Authentication auth;
transient private InitialLdapContext context;
private List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
/**
* Construct a new LdapAuthenticationToken, using an existing Authentication object and
* granting all users a default authority.
*
* @param auth
* @param defaultAuthority
*/
public LdapAuthenticationToken(Authentication auth, GrantedAuthority defaultAuthority) {
this.auth = auth;
if (auth.getAuthorities() != null) {
this.authorities.addAll(Arrays.asList(auth.getAuthorities()));
}
if (defaultAuthority != null) {
this.authorities.add(defaultAuthority);
}
super.setAuthenticated(true);
}
/**
* Construct a new LdapAuthenticationToken, using an existing Authentication object and
* granting all users a default authority.
*
* @param auth
* @param defaultAuthority
*/
public LdapAuthenticationToken(Authentication auth, String defaultAuthority) {
this(auth, new GrantedAuthorityImpl(defaultAuthority));
}
public GrantedAuthority[] getAuthorities() {
GrantedAuthority[] authoritiesArray = this.authorities.toArray(new GrantedAuthority[0]);
return authoritiesArray;
}
public void addAuthority(GrantedAuthority authority) {
this.authorities.add(authority);
}
public Object getCredentials() {
return auth.getCredentials();
}
public Object getPrincipal() {
return auth.getPrincipal();
}
/**
* Retrieve the LDAP context attached to this user's authentication object.
*
* @return the LDAP context
*/
public InitialLdapContext getContext() {
return context;
}
/**
* Attach an LDAP context to this user's authentication object.
*
* @param context
* the LDAP context
*/
public void setContext(InitialLdapContext context) {
this.context = context;
}
}
</code></pre>
<p>You'll notice that there are a few bits in there that you might not need.</p>
<p>For example, my app needed to retain the successfully-logged-in LDAP context for further use by the user once logged in -- the app's purpose is to let users log in via their AD credentials and then perform further AD-related functions. So because of that, I have a custom authentication token, LdapAuthenticationToken, that I pass around (rather than Spring's default Authentication token) which allows me to attach the LDAP context. In LdapAuthenticationProvider.authenticate(), I create that token and pass it back out; in LdapAuthenticatorImpl.authenticate(), I attach the logged-in context to the return object so that it can be added to the user's Spring authentication object.</p>
<p>Also, in LdapAuthenticationProvider.authenticate(), I assign all logged-in users the ROLE_USER role -- that's what lets me then test for that role in my intercept-url elements. You'll want to make this match whatever role you want to test for, or even assign roles based on Active Directory groups or whatever.</p>
<p>Finally, and a corollary to that, the way I implemented LdapAuthenticationProvider.authenticate() gives all users with valid AD accounts the same ROLE_USER role. Obviously, in that method, you can perform further tests on the user (i.e., is the user in a specific AD group?) and assign roles that way, or even test for some condition before even granting the user access at <em>all</em>.</p>
|
<p>LDAP authentication without SSL is not safe anyone can see the user credential when those are transffered to LDAP server. I suggest using LDAPS:\ protocol for authentication. It doesn't require any major change on spring part but you may ran with some issues related to certificates. See <a href="http://javarevisited.blogspot.com/2011/11/ldap-authentication-active-directory.html" rel="nofollow">LDAP Active Directory authentication in Spring with SSL</a> for more details</p>
| 11,019
|
<p>Coming from a java background, one of the things I am used to is telling the JVM what the maximum heap size should be. If the running program tries to swallow more than is allowed, and the garbage collector cannot free any more resources, then OutOfMemoryError is thrown and it all goes bang. So setting the maximum heap size is important in Java.</p>
<p><strong>Does this apply in .net?</strong> Can you set the heap size limits? Does the CLR just keep growing its heap until it reaches the machine's physical limits? Or is it not an issue in .net for some subtle reason that my Java blinkers stop me from seeing?</p>
|
<p>You can't set max heap size in .Net unless you host the CLR yourself in a process. </p>
<p>Edit:
To control the memory allocations of CLR including the max heap size, you need to use the hosting api to host the clr and specifically use the "Memory manager interfaces", some starter info can be found here <a href="http://msdn.microsoft.com/en-us/magazine/cc163567.aspx" rel="noreferrer">MSDN Magazine, column CLR Inside Out : CLR Hosting APIs</a></p>
<p>Edit: to answer you question, why would you want to control the memory allocation or specifically max heap size, you usually don't want to, but <strong>if</strong> you're writing an application that is like SQL Server or IIS or some real time application then you'd have a pretty good reason to have control over memory and specifically, avoid paging, otherwise the CLR itself and the OS already do a pretty good job for you, and what is left is to ensure your that application uses minimum resources for things to work well.</p>
|
<p>As far as I've found, there is no simple way to <a href="http://bytes.com/groups/net-c/683386-how-set-max-heap-size-c" rel="noreferrer">control the size of the heap</a> of a .Net app using the CLR.</p>
<p>The link above only half answers the question. When I've researched this same issue, the response is "The heap grows to use all available memory" as if that is the only reason you'd want to control the max heap size.</p>
<p>On (typically Java) server environments, you don't want a badly behaving app to hog memory at the expense of other hosted apps. A simple solution is to limit the amount of memory that the app can use for it's heap. This is accomplished with Java's -Xmx argument so you can guarantee the app won't use more than what is planned, e.g. -Xmx256M. Since allocating memory on the heap during initialization can slow the apps startup, Java uses the -Xms arg to allow apps that do alot of object creation during initialization to start out with a large block of heap instead of the JVM contantly resizing the heap as it goes.</p>
<p>.Net's CLR does not have this ability. I suspect it is because .Net's CLR is not a virtual machine. The CLR happens to be an API (quite comprehensive, I might add) which serves as an adapter to native .dlls which equate to an approach much more like an executable when it comes to memory management.</p>
<p>I've asked this question about SharePoint development and did hear that it might be possible to control the heapsize through the use of IIS modules called Web Apps whereby you can tell IIS to limit the memory of a given web app. I wonder if this is because IIS has customized routines which replace/override new()/malloc()/etc and thus can provide this type of control to client apps. That means that standalone .Net apps are out of luck unless you want to write a custom memory manager in C++ and create an interface for .Net</p>
| 38,664
|
<p>I'm currently working on a JavaScript tool that, during the course of its execution, will ultimately traverse each node in the DOM. Because this has potential to be a very expensive task, I'd like to benchmark the performance of this script.</p>
<p>What's the best, free tool for benchmarking a script such as this across the major browsers? Ideally, I'd like the tool (or set of tools, even):</p>
<ul>
<li>
**To generate some form of report based on the results of the test.** It can be as simple as a table showing execution times, or as complex as generating some form of a chart. Either way is fine.
</li>
<li>
**To be free.** it's not that I don't believe in paying for software, it's just that I don't have a major need for a tool like this in my typical day-to-day tasks.
</li>
</ul>
<p>If possible, I'd also like the tool to generate varying levels of complex pages so that I can stress test a set of DOMs. This isn't a necessity - if I need to do so, I can write one myself; however, I'd figure I'd poll the community first to see if something already exists.</p>
|
<p><strong><a href="http://getfirebug.com" rel="noreferrer">Firebug</a></strong> does include JS profiling, and it is probably the best out there. While I've had problems with Firebug's debugger, its profiler is currently top-of-the-line. <strong><a href="http://www.mozilla.org/projects/venkman/" rel="noreferrer">Venkman</a></strong> is also an older JS debugger/profiler for Firefox, just in case you run into Firebug issues.</p>
<p>Using these tools should get you just about all the profiling you need across all browsers even though you'll only be monitoring Firefox. If you truly need to get down to dirty details of IE profiling and the like, there are a number of tools online that inject profiling calls into your javascript to help monitor all profiler-lacking browsers....but even to a JS performance nazi like me, this seems unnecessary.</p>
<p><strong><em>Note:</em></strong> A new, very promising IE8 JS profiler has recently been announced: <a href="http://blogs.msdn.com/ie/archive/2008/09/11/introducing-the-ie8-developer-tools-jscript-profiler.aspx" rel="noreferrer">http://blogs.msdn.com/ie/archive/2008/09/11/introducing-the-ie8-developer-tools-jscript-profiler.aspx</a>.</p>
|
<p>Jeff posted <a href="http://www.codinghorror.com/blog/archives/001023.html" rel="nofollow noreferrer">The great browser javascript shutdown</a></p>
<p><a href="http://www2.webkit.org/perf/sunspider-0.9/sunspider.html" rel="nofollow noreferrer"><H2>SunSpider JavaScript Benchmark</H2></a></p>
<p>But i wonder where the download link is ;)</p>
| 7,734
|
<p>I have Apache 2 running on a VPS server (running Debian). I recently changed the timezone on the server (using dpkg-reconfigure tzdata) from America/New_York to America/Los_Angeles to match my move across country. I have also rebooted the virtual machine since making the change.</p>
<p>However, the Apache processes seem to flitter between timezones. See this snippet from the access_log:</p>
<pre><code>127.0.0.1 - - [02/Oct/2008:23:01:13 -0700] "GET /favicon.ico HTTP/1.0" 301 - "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.3) Gecko/2008092414 Firefox/3.0.3"
127.0.0.1 - - [03/Oct/2008:02:01:25 -0400] "GET /tag/wikipedia/?page=1 HTTP/1.0" 200 5984 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
127.0.0.1 - - [03/Oct/2008:02:01:36 -0400] "GET /index.atom HTTP/1.0" 200 7648 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.2) Gecko/2008091618 Firefox/3.0.2"
127.0.0.1 - - [03/Oct/2008:02:01:45 -0400] "GET /tag/moblog/ HTTP/1.0" 200 6563 "-" "msnbot/1.1 (+http://search.msn.com/msnbot.htm)"
127.0.0.1 - - [02/Oct/2008:23:01:46 -0700] "GET /tag/opensource/ HTTP/1.0" 200 5954 "-" "msnbot/1.1 (+http://search.msn.com/msnbot.htm)"
127.0.0.1 - - [03/Oct/2008:02:01:56 -0400] "GET /tag/dopplr/ HTTP/1.0" 200 3407 "-" "msnbot/1.1 (+http://search.msn.com/msnbot.htm)"
</code></pre>
<p>It jumps from 23:01 to 02:01 and back. Any idea how I can keep it consistent?</p>
|
<p>As it turns out, I had two Django projects running on this Apache instance, one of which I had fixed to point to America/Los_Angeles, but the other I had left behind. Depending on which app was accessed first when a new Apache process was created, it would muck up the time zone!</p>
|
<p>Possibly some of the Apache worker processes were started before you changes the timezone, and some afterwards. Have you completely stopped and re-started Apache since changing the system timezone setting?</p>
| 20,034
|
<p>Here is the directory structure</p>
<pre><code>/domain.com
/public_html
/functions
/image
/mobile
/www
</code></pre>
<p>the /domain.com/public_html/www folder has a file index.php
the default web directory is /user/public_html/www
in the index file is an include that includes the functions with
include"../functions/function.inc"
this works without problem
when I want to link to a picture in the image folder I don't get any results
for example </p>
<pre><code><img src="../image/graphic/logo.gif" alt="alt text"/>
</code></pre>
<p>Does anybody has any idea why the link to the image does not work and how to link correctly to the image file ?</p>
<p>I tried <code><img src="<?php echo $_SERVER['PHP_SELF']; ?>../image/graphic/logo.gif" alt="alt text"/></code></p>
<p>but that gives me the same result
when I build a link around the image to get to the properties I get this as path
<a href="http://domain.com/image/pc/tattoo_small/small_2008_10_22_001.JPG" rel="noreferrer">http://domain.com/image/pc/tattoo_small/small_2008_10_22_001.JPG</a>
the path should be
<a href="http://domain.com/public_html/image/pc/tattoo_small/small_2008_10_22_001.JPG" rel="noreferrer">http://domain.com/public_html/image/pc/tattoo_small/small_2008_10_22_001.JPG</a>
when I try to browse directly to this url
<a href="http://domain.com/public_html/image/pc/tattoo_small/small_2008_10_22_001.JPG" rel="noreferrer">http://domain.com/public_html/image/pc/tattoo_small/small_2008_10_22_001.JPG</a>
I get an 404 file not found error
because the default web directory is
/domain.com/public_html/www
I tried
<a href="http://domain.com/../image/pc/tattoo_small/small_2008_10_22_001.JPG" rel="noreferrer">http://domain.com/../image/pc/tattoo_small/small_2008_10_22_001.JPG</a>
to get to the image folder but that does not help neither.</p>
<p>Anybody any ideas or is it impossible to html link to graphical files outside the default web directory ?</p>
<p>thanks for reading this far</p>
<p>Thanks for the answers so far.
I will try to solve my problem with one of the recommended solutions and report my working solution back here.
I wanted to have the image folder at the same level as the www and mobile folder because some of the images used for the pc (www) version and the mobile version are the same.
Of course it is easier to just get an image folder in the www and in the mobile folder and I think that is what I am going to do.</p>
<p>thank you everybody for the advice. The main reason why I am not going to work with a script is that a script will be a difficult solution to an easy problem and also because I don't really see how you can wrap your image in a css class and how to provide alt text for an image.</p>
|
<p>It is not possible to directly access files outside of the webroot; this is a builtin security restriction that is there for good reason.</p>
<p>It is however possible to use a PHP-script to serve these images for you. This way you can call an image like:</p>
<pre><code>/image.php?file=myfile.jpg
</code></pre>
<p>and use <a href="http://php.net/manual/en/function.file-get-contents.php" rel="noreferrer">file_get_contents()</a> to get the file contents and print them to your browser. You should also send the headers to the client, in this case using PHP's <a href="http://php.net/header" rel="noreferrer">header()</a> function. A short example:</p>
<pre><code><?php
$file = basename(urldecode($_GET['file']));
$fileDir = '/path/to/files/';
if (file_exists($fileDir . $file))
{
// Note: You should probably do some more checks
// on the filetype, size, etc.
$contents = file_get_contents($fileDir . $file);
// Note: You should probably implement some kind
// of check on filetype
header('Content-type: image/jpeg');
echo $contents;
}
?>
</code></pre>
<p>Using a script to this has some more advantages:</p>
<ul>
<li>You can track your downloads and implement a counter, for example</li>
<li>You can restrict files to authenticated users</li>
<li>... etc</li>
</ul>
|
<p>You can either make a link to the image directory inside the public___html, move the image directory to public_html or, if you have a particular liking towards convoluted solutions, you can write a script that reads the image file and outputs it to the user (Of course, unless you make a whitelist of all the images, you might have a potential security problem in your hands).</p>
| 32,252
|
<p>I'm interested in creating a game that uses fractal maps for more realistic geography. However, the only fractal map programs I have found are Windows-only, for example <a href="http://www.nbos.com/products/mapper/mapper.htm" rel="nofollow noreferrer">Fractal Mapper</a>. Needless to say, they are also not open-sourced.</p>
<p>Are there any open-sourced fractal map creators available, preferably in Python or C/C++? Ideally I would like something that can be "plugged into" a program, rather then being standalone.</p>
|
<p><a href="http://www.bottlenose.demon.co.uk/share/fracplanet/" rel="noreferrer">Fracplanet</a> may be of use.</p>
|
<p>If you want truely realistic geography, you could use NASA's <a href="http://www2.jpl.nasa.gov/srtm/" rel="nofollow noreferrer">SRTM</a> dataset, perhaps combined with <a href="http://www.openstreetmap.org" rel="nofollow noreferrer">OpenStreetMap</a> features. :-)</p>
| 19,023
|
<p>Is there any easy way to retrieve table creation DDL from Microsoft Access (2007) or do I have to code it myself using VBA to read the table structure? </p>
<p>I have about 30 tables that we are porting to Oracle and it would make life easier if we could create the tables from the Access definitions.</p>
|
<p>Thanks for the other suggestions. While I was waiting I wrote some VBA code to do it. It's not perfect, but did the job for me.</p>
<pre><code>Option Compare Database
Public Function TableCreateDDL(TableDef As TableDef) As String
Dim fldDef As Field
Dim FieldIndex As Integer
Dim fldName As String, fldDataInfo As String
Dim DDL As String
Dim TableName As String
TableName = TableDef.Name
TableName = Replace(TableName, " ", "_")
DDL = "create table " & TableName & "(" & vbCrLf
With TableDef
For FieldIndex = 0 To .Fields.Count - 1
Set fldDef = .Fields(FieldIndex)
With fldDef
fldName = .Name
fldName = Replace(fldName, " ", "_")
Select Case .Type
Case dbBoolean
fldDataInfo = "nvarchar2"
Case dbByte
fldDataInfo = "number"
Case dbInteger
fldDataInfo = "number"
Case dbLong
fldDataInfo = "number"
Case dbCurrency
fldDataInfo = "number"
Case dbSingle
fldDataInfo = "number"
Case dbDouble
fldDataInfo = "number"
Case dbDate
fldDataInfo = "date"
Case dbText
fldDataInfo = "nvarchar2(" & Format$(.Size) & ")"
Case dbLongBinary
fldDataInfo = "****"
Case dbMemo
fldDataInfo = "****"
Case dbGUID
fldDataInfo = "nvarchar2(16)"
End Select
End With
If FieldIndex > 0 Then
DDL = DDL & ", " & vbCrLf
End If
DDL = DDL & " " & fldName & " " & fldDataInfo
Next FieldIndex
End With
DDL = DDL & ");"
TableCreateDDL = DDL
End Function
Sub ExportAllTableCreateDDL()
Dim lTbl As Long
Dim dBase As Database
Dim Handle As Integer
Set dBase = CurrentDb
Handle = FreeFile
Open "c:\export\TableCreateDDL.txt" For Output Access Write As #Handle
For lTbl = 0 To dBase.TableDefs.Count - 1
'If the table name is a temporary or system table then ignore it
If Left(dBase.TableDefs(lTbl).Name, 1) = "~" Or _
Left(dBase.TableDefs(lTbl).Name, 4) = "MSYS" Then
'~ indicates a temporary table
'MSYS indicates a system level table
Else
Print #Handle, TableCreateDDL(dBase.TableDefs(lTbl))
End If
Next lTbl
Close Handle
Set dBase = Nothing
End Sub
</code></pre>
<p>I never claimed to be VB programmer.</p>
|
<p>A bit late to the party, but I use RazorSQL to generate DDL for Access databases.</p>
| 20,830
|
<p>I'm working on a project with will be buried in soil. It's an enclosure for a sensor that will be potted inside the 3D printed part. What filament will give me the longest life in soil? </p>
<p>ETA: burial will be permanent, and I'd like it to last at least five years.</p>
<p>ETA: The printed part will provide mechanical support for the sensor, so it needs to retain most of its mechanical properties.</p>
|
<p>I would recommend PETG - only because it is structurally similar to the plastic used in the bottles that last forever, and most PETG is food grade - implying that its chemical stability should be reasonably good...</p>
|
<p>If TPU ends up not being rigid enough for you:
I've had good enough luck with ABS coated in automotive RTV.</p>
<p>Thing with ABS though is that it's a special (not so)"solid" that gets softer as it gets hotter. My use had water in it when warm so wasn't too much of an issue, and it never experienced freezing temperatures.</p>
<p>Also it hasn't been 5 years yet. ~2 years and counting.</p>
| 1,649
|
<p>For my Ender 3 Pro I bought this touch sensor set <a href="https://tr.aliexpress.com/item/4001209045993.html?spm=a2g0s.9042311.0.0.68ea4c4d3CjwfW" rel="nofollow noreferrer">Chinese clone BLTouch set</a> and changed the printer's firmware to the latest TH3D firmware (first I tried with Creality's original BLTouch firmware but after 4 hours, I never managed to set a correct Z offset, I believe there is a bug or this BLTouch clone isn't compatible with Creality firmware).</p>
<p>After installing TH3D, found the right Z offset, when I print items like <a href="https://www.thingiverse.com/thing:3476490" rel="nofollow noreferrer">this one</a> which stays at the center everything just perfect it sticks well, no strings, strong lines.</p>
<p>But if I try to print something <a href="https://www.thingiverse.com/thing:2973856" rel="nofollow noreferrer">like this</a> which is using almost all the printing table from corner to corner (I need to rotate the print 45° to fit onto the build platform), it's good on center or near to center but not sticking on the corners and first lines are sticking to nozzle (because at the far corners, the nozzle is too far or too close) and makes a mess.</p>
<p>I powered off the printer and adjusted the good old way (with a paper) and re-setted the Z offset accordingly but the result is the same.</p>
<p>According to my research some peoples advised you need to add <code>G29</code> after <code>G28</code> to your G-code to get proper solution, I added the code in Cura. When I try adding <code>G29</code>, the printer starts leveling after starting printing, but the "not sticking problem at the corners" still continues.</p>
<p>I tried with both magnetic bed & glass bed, but nothing helped. I was using 200 °C for the nozzle and 60nbsp;°C for the bed, printing speed is 50nbsp;mm/s with Standart quality 0.2nbsp;mm, retraction enabled, mostly using 10nbsp;% infill on my models.</p>
<p>I thougt maybe filament causes this problem, changed filament to another roll but not helped, I also have an Ender 3 V2 (no BLTouch) and tried same model, same filament, same settings on V2 printed perfectly.</p>
<p>This is how my bed looks like according to OctoPrint bed visualizer plugin;</p>
<p><a href="https://i.stack.imgur.com/u8YQH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/u8YQH.png" alt="enter image description here" /></a></p>
<p>I've watched many tutorial videos and some said you need to adjust your bed with spirit level to make sure it's flat, I even did that and it is just perfectly flat.</p>
<p>I've installed the BLTouch clone 1 week ago and I'm struggling with this problem since then, I believe I'm missing something very obvious or making a realy simple mistake because many people use touch sensors and they are all happy with auto bed leveling.</p>
|
<p>Following <a href="https://3dprinting.stackexchange.com/a/14765/5740">Nathan's</a> answer, I've solved my problem with Nathan's suggestions and the method in <a href="https://www.youtube.com/watch?v=W8ouBPnRV4s&ab_channel=cheule" rel="nofollow noreferrer">this video</a>.</p>
<p>What I did?</p>
<ol>
<li>Flashed Creality's original BLTouch firmware to printer</li>
<li>Heated up bed to 60 °C</li>
<li>Leveled bed the old fashion way first, but with slight resistance (you don't have to level perfectly)</li>
<li>Followed the youtube method to find proper Z offset</li>
<li>Opened Cura, Settings->Printer->Manage Printers: and added <code>G29; ABL</code> after <code>G28</code>
<a href="https://i.stack.imgur.com/dpOtR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dpOtR.png" alt="enter image description here" /></a></li>
</ol>
<p>Voilâ, now your printer prints perfectly! Enjoying the relieving after 1 week of struggling.</p>
|
<p>I would suggest you read <a href="https://www.reddit.com/r/ender3/comments/jdd2nf/for_some_reason_my_bltouch_isnt_working_quite_as/g9amvfn/?context=3" rel="nofollow noreferrer">this</a>, even tho it's a different mainboard it may help.</p>
<p>Next to that you should level the bed the old fashion way first with a paper on the 4 outer corners, it is essential that you do this because ABL can only compensate so much when printing. After that set the Z-offset using a paper and run some bed adhesion test prints and use babysteps.</p>
<p>Level and probe your bed with it being heated up to 60 °C for PLA and 80 °C for PETG, the thermal expansion of the bed can easily mess up the probe data you already have!</p>
<p>Also make sure your ABL functions as Z-endstop; it solved all the issues for me.</p>
<hr />
<p><em>If you ever want to upgrade your mainboard for some reason I can highly recommend the SKR mini E3 V2 it has great support for additional sensors.</em></p>
| 1,773
|
<p>AFAIK, you never need to specify the protocol in an onclick:</p>
<p><code>onclick="javascript:myFunction()"</code> <strong>Bad</strong></p>
<p><code>onclick="myFunction()"</code> <strong>Good</strong></p>
<p>Today I noticed in <a href="http://web.archive.org/web/20080428095515/http://www.google.com/support/analytics/bin/answer.py?answer=55527" rel="noreferrer">this article</a> on Google Anallytics that <em>they</em> are using it:</p>
<pre><code><a href="http://www.example.com" onClick="javascript: pageTracker._trackPageview('/outgoing/example.com');">
</code></pre>
<p>Is this example just plain wrong, or is there ever a reason to specify <code>javascript:</code> in anything other than a <code>href</code>?</p>
|
<p>Some of the responses here claim that the "javascript:" prefix is a "leftover from the old days", implying that it's intentionally, specially handled by the browsers for backwards compatibility. Is there solid evidence that this is the case (has anyone checked source code)?</p>
<pre><code><span onclick="javascript:alert(42)">Test</span>
</code></pre>
<p>To me, this just reads as:</p>
<pre><code>javascript:
alert(42);
</code></pre>
<p>Meaning, that "javascript:" is just a label and has no effect. This works, too:</p>
<pre><code><span onclick="foobar:alert(42)">Test</span>
</code></pre>
<p><strong>Update:</strong></p>
<p>I did a little experiment and it turns out that, yes, "javascript:" is handled specially by IE, but definitely not so by Firefox, Safari, Opera or Chrome:</p>
<pre><code><span onclick="javascript:while (true) { alert('once'); break javascript; }">Test</span>
</code></pre>
<p>On non-IE, this will just alert "once", once and then break out of the loop. On IE, I get a "Label not found" error. The following works fine in all browsers:</p>
<pre><code><span onclick="foo:while (true) { alert('once'); break foo; }">Test</span>
</code></pre>
<p><strong>Update 2:</strong></p>
<p>I just realized the link <a href="http://crisp.tweakblogs.net/blog/the-useless-javascript-pseudo-protocol.html" rel="noreferrer">http://crisp.tweakblogs.net/blog/the-useless-javascript-pseudo-protocol.html</a> in one of the answers above pretty much talks about the same thing.</p>
|
<p>It's good practice for your maintenance programmer. The compiler knows the difference, but that young, just-out-of-college web developer may not.</p>
| 48,645
|
<p>What is the difference between web reference and service reference in WCF?
Which is preferable in WCF?</p>
|
<p>The low-level answer here is that a Web Reference will create a client proxy class that allows your code to talk to a Web Service that is described via WSDL and communicates via SOAP or HTTP GET (other posters indicate that it is only ASMX, but Web References can also talk to Java-based Web Services or Python-based or Ruby so long as they all talk WSDL and conform to the WS-I interoperability standard).</p>
<p>A Service Reference will create a client proxy class that communicates with a WCF-based service : regardless of whether that WCF service is a Web Service or not.</p>
|
<p>Service references deal with endpoints and bindings, which are completely configurable. They let you point your client proxy to a WCF via any transport protocol (HTTP, TCP, Shared Memory, etc)</p>
<p>They are designed to work with WCF.</p>
<p>If you use a WebProxy, you are pretty much binding yourself to using WCF over HTTP</p>
| 39,733
|
<p>I'm trying to build a C# console application to automate grabbing certain files from our website, mostly to save myself clicks and - frankly - just to have done it. But I've hit a snag that for which I've been unable to find a working solution.</p>
<p>The website I'm trying to which I'm trying to connect uses ASP.Net forms authorization, and I cannot figure out how to authenticate myself with it. This application is a complete hack so I can hard code my username and password or any other needed auth info, and the solution itself doesn't need to be something that is viable enough to release to general users. In other words, if the only possible solution is a hack, I'm fine with that.</p>
<p>Basically, I'm trying to use HttpWebRequest to pull the site that has the list of files, iterating through that list and then downloading what I need. So the actual work on the site is fairly trivial once I can get the website to consider me authorized.</p>
|
<pre><code><?php
/*
Resizes an image and converts it to PNG returning the PNG data as a string
*/
function imageToPng($srcFile, $maxSize = 100) {
list($width_orig, $height_orig, $type) = getimagesize($srcFile);
// Get the aspect ratio
$ratio_orig = $width_orig / $height_orig;
$width = $maxSize;
$height = $maxSize;
// resize to height (orig is portrait)
if ($ratio_orig < 1) {
$width = $height * $ratio_orig;
}
// resize to width (orig is landscape)
else {
$height = $width / $ratio_orig;
}
// Temporarily increase the memory limit to allow for larger images
ini_set('memory_limit', '32M');
switch ($type)
{
case IMAGETYPE_GIF:
$image = imagecreatefromgif($srcFile);
break;
case IMAGETYPE_JPEG:
$image = imagecreatefromjpeg($srcFile);
break;
case IMAGETYPE_PNG:
$image = imagecreatefrompng($srcFile);
break;
default:
throw new Exception('Unrecognized image type ' . $type);
}
// create a new blank image
$newImage = imagecreatetruecolor($width, $height);
// Copy the old image to the new image
imagecopyresampled($newImage, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
// Output to a temp file
$destFile = tempnam();
imagepng($newImage, $destFile);
// Free memory
imagedestroy($newImage);
if ( is_file($destFile) ) {
$f = fopen($destFile, 'rb');
$data = fread($f);
fclose($f);
// Remove the tempfile
unlink($destFile);
return $data;
}
throw new Exception('Image conversion failed.');
}
</code></pre>
|
<p><a href="http://www.phpit.net/article/image-manipulation-php-gd-part2/" rel="nofollow noreferrer">This article</a> seems like it would fit what you want. You'll need to change the saving imagejpeg() function to imagepng() and have it save the file to a string rather than output it to the page, but other than that it should be easy copy/paste into your existing code.</p>
| 4,225
|
<p>I'd like something like a generic, re-usable <code>getPosition()</code> method that will tell me the number of bytes read from the starting point of the stream. Ideally, I would prefer this to work with all InputStreams, so that I don't have to wrap each and every one of them as I get them from disparate sources.</p>
<p>Does such a beast exist? If not, can anyone recommend an existing implementation of a counting <code>InputStream</code>?</p>
|
<p>Take a look at <a href="http://commons.apache.org/io/apidocs/org/apache/commons/io/input/CountingInputStream.html" rel="noreferrer">CountingInputStream</a> in the Commons IO package. They have a pretty good collection of other useful InputStream variants as well.</p>
|
<p>No. <code>InputStream</code> is intended to handle potentially infinite amounts of data, so a counter would get in the way. In addition to wrapping them all, you might be able to do something with aspects.</p>
| 29,745
|
<p>Python has this wonderful way of handling string substitutions using dictionaries:</p>
<pre><code>>>> 'The %(site)s site %(adj)s because it %(adj)s' % {'site':'Stackoverflow', 'adj':'rocks'}
'The Stackoverflow site rocks because it rocks'
</code></pre>
<p>I love this because you can specify a value once in the dictionary and then replace it all over the place in the string.</p>
<p>I've tried to achieve something similar in PHP using various string replace functions but everything I've come up with feels awkward.</p>
<p>Does anybody have a nice clean way to do this kind of string substitution in PHP?</p>
<p><strong><em>Edit</em></strong><br>
Here's the code from the sprintf page that I liked best. </p>
<pre><code><?php
function sprintf3($str, $vars, $char = '%')
{
$tmp = array();
foreach($vars as $k => $v)
{
$tmp[$char . $k . $char] = $v;
}
return str_replace(array_keys($tmp), array_values($tmp), $str);
}
echo sprintf3( 'The %site% site %adj% because it %adj%', array('site'=>'Stackoverflow', 'adj'=>'rocks'));
?>
</code></pre>
|
<pre><code>function subst($str, $dict){
return preg_replace(array_map(create_function('$a', 'return "/%\\($a\\)s/";'), array_keys($dict)), array_values($dict), $str);
}
</code></pre>
<p>You call it like so:</p>
<pre><code>echo subst('The %(site)s site %(adj)s because it %(adj)s', array('site'=>'Stackoverflow', 'adj'=>'rocks'));
</code></pre>
|
<p>Some of the user-contributed notes and functions in <a href="http://us3.php.net/sprintf" rel="nofollow noreferrer">PHP's documentation for sprintf</a> come quite close.</p>
<p>Note: search the page for "sprintf2".</p>
| 4,781
|
<p>Recently (in 2017) there was <a href="https://m.box.com/shared_item/https%3A%2F%2Fumich.box.com%2Fs%2Fn9cvs27ckehdr64gzv5igtmboykymgk6" rel="nofollow noreferrer">a paper</a> that got some publicity by researchers who are using a B spline algorithm to reduce vibrations in 3D printers. But before them, a B Spline implementation seems to have been first been made open-source by an alias named DeepSoic <a href="https://hackaday.io/project/7045-splinetravel" rel="nofollow noreferrer">here</a>. I would like to be able to print faster using the method described in the <a href="https://3dprint.com/195734/um-update-algorithm/" rel="nofollow noreferrer">research paper</a>, through post-processing G-code. I'm pretty sure these two sources use basically the same technique but I could be misunderstanding things.</p>
<p>Basically instead of stopping and starting for travel moves, speed changes are done in a curvy fashion, so the head never stops and the printer never shakes. This makes the print smoother and also faster. I think printing 10 times faster is something that is really awesome once you try it. Laser cutting relies on cubic splines for a different reason; to create curves in space. But it seems like these techniques are doing something unique to to 3D printing -- using them to adjust head acceleration/de-acceleration to create smoother movement arcs of the print head. Since laser cutters have a constant head movement, this technique wouldn't help them much.</p>
<p>The downside seems to be that it makes way more G-code commands, overloading the USB port, since it's sending all the points on a curve so quickly. I'm assuming a smart person today would really only use it through an SD card (which has disadvantages) or if they bought a 3D printer with a free Wi-Fi module thrown in (which also has disadvantages). Maybe a high baud rate helps.</p>
<p>I was wondering if there are any more established ways to use this obviously extremely important and beneficial and simple algorithm. Initially I was thinking that this is obviously something that should be added as a checkbox in a slicer, and not something to be implemented in Marlin. But after writing this post I realized that a Marlin implementation would allow you to use this technique over USB, but only if the slicer steedleaders are also using its special G-codes for this optimization. I don't care if it's a post-processing technique like the research paper's or a special Marlin-friendly version, I just want to use this technique even if I have to use this Huawei Wi-Fi module.</p>
<p>Basically I would like to know the best way to get started using this technique through a slicer or other software.</p>
<hr />
<p>I think there is a miscommunication between users of CNC laser cutters and users of 3D printers. In laser cutting the arcs are used to define the path of the cut, which would be equivalent to filament extrusion. In laser cutting, the motion of the laser itself is constant. But in 3D printing, arcs can be used to smooth the speed of the printhead as it moves across the perimeter, and then to infill. It is using arcs for controlling the head well which isn't a problem in laser cutting. Since it's about the head movement, and not the model itself, I don't see how the STL file really matters.</p>
<p>It's really about using an arc to set head speed (a first derivative of position). Not anything about the shape of the model (which would just be position). At least that's my interpretation.</p>
<p>The Wi-Fi module is interesting because it receives an IP address from my router, then my router stops listing it as a connected device. But it still connected, because I can access it wirelessly. I am going to look into it more once I can fix some other problems with this dual-head. But so far there's a reason to think it might be backdoored.</p>
|
<p><em>I would have liked to answer linking to credible official sources, but I cannot add references either on direct B-spline printing. So I'm writing down my thoughts. I've familiarized myself in B-splines to understand what they are and read into the 2 references given by the OP.</em></p>
<hr />
<p>Basically, the printer software only allows printing of straight lines. Yes I know we can give orders to the printer to print a curve (using <code>G2</code> or <code>G3</code>), but these eventually will be converted to printing straight lines. There is no ready made printer firmware available to print cubic curves directly to my knowledge. If it would be possible, these curves should eventually be translated into smaller straight lines by the firmware of timed stepper rotational output. These extra calculations would demand a considerable effort of the printer board processor, most probably far more an 8-bit processor would be able to handle.</p>
<p>Comparing the <a href="https://m.box.com/shared_item/https%3A%2F%2Fumich.box.com%2Fs%2Fn9cvs27ckehdr64gzv5igtmboykymgk6" rel="nofollow noreferrer">paper released in 2017</a> to the <a href="https://hackaday.io/project/7045-splinetravel" rel="nofollow noreferrer">G-code pre-processing software</a> reveals that although both seem to refer to B-spline techniques, they are implemented differently. For example, the pre-processing software aims to reduce the linear travel moves by replacing these with B-spline curves (and not affect the actual print object), while the paper focuses on the optimization of the actual printing curves being optimized by B-spline curves (also using a pre-processor). Both eventually would need to create a multitude of small straight lines to have the printer be able to actually print the object as there is no 3D printing firmware solution to print curves. Do note that the method in the paper has been <a href="https://3dprint.com/195734/um-update-algorithm/" rel="nofollow noreferrer">questioned by the RepRap community</a>, which demonstrated that they could print the same object way faster than the B-spline optimized example. Furthermore, do note that the Marlin community is probably moving in that direction as can be seen from e.g. <a href="https://github.com/MarlinFirmware/Marlin/issues/8308" rel="nofollow noreferrer">this feature request</a> and <a href="http://marlinfw.org/meta/gcode/" rel="nofollow noreferrer">this G-code meta overview</a>; G-code instruction <code>G5</code>.</p>
<p>So, both methods rely on pre-processing G-codes by identification of sliced coordinate (print) moves, translation into Bézier/B-spline curves for (print) moves, which eventually are translated into normal <code>G0/G1</code> (print) moves. It does not appear that the Marlin community/developers are aiming to implement Bézier or B-spline curves soon. This implies that if you want to pursuit printing B-splines, you need to make your own pre-processor, or dive into Marlin C++ development; an 8-bit based printer board would not be sufficient indeed like the OP mentioned, up-scaling to 32-bit or interfacing with USB might be the only solution.</p>
|
<p>In more practical terms, you could design the part so that the corners are rounded (also known as fillets). This will help keep the print head moving and would prevent the sudden stop and start effect that causes "jerking". Further 8 bit controllers tend to get saturated when reading large amounts of g-code from the sd card or the serial port. Upgrading to a 32 bit controller will prevent that kind of jerking.</p>
<p>Both of these methods pale in comparison to just speeding up the print. Upgrading the hardware to be faster (various methods exist) would yield more of a reduced time than trying to optimize the g-code (in my humble opinion). Delta printers have the potential to be the fastest type of FDM printer, assuming that you could get the filament to melt fast enough.</p>
| 1,401
|
<p>I want to add some <a href="http://en.wikipedia.org/wiki/Ajax_%28programming%29" rel="noreferrer">Ajax</a>-niceness to my Django-coded website. </p>
<p>In my Django code, I use the <code>@login_required</code> decorator from <code>django.contrib.auth.decorators</code> to mark which view requires authentication. The default behavior when a not authenticated user clicks it is to redirect him/her to login page, and then pass the target page. </p>
<p>What I saw on some sites, and really liked, is that when user clicks a link leading to a place restricted to logged-only users, instead of getting redirected to a login page, he/she gets a popup window (via JavaScript) asking him/her to log in or register. There's no redirection part, so no need for a user to use the "back" key if he/she decides he/she really doesn't like the website enough to waste the time registering.</p>
<p>So, the qestion is: how would you manage the task of automatically marking some links as "restricted" so JavaScript can handle their <code>onclick</code> event and display a "please log in" popup? </p>
|
<p>I am facing the same issue, and, like you, I would like a simple decorator to wrap around a Django ajax view in order to handle authentication in the same way that I have other views. One approach that seems promising to me is to use such a decorator in conjunction with JavaScript that looks for a certain value in the response.</p>
<p>Here is <s>first</s> revised draft of the decorator:</p>
<pre><code>from functools import wraps
def ajax_login_required(view_func):
@wraps(view_func)
def wrapper(request, *args, **kwargs):
if request.user.is_authenticated():
return view_func(request, *args, **kwargs)
json = simplejson.dumps({ 'not_authenticated': True })
return HttpResponse(json, mimetype='application/json')
return wrapper
</code></pre>
<p>Here is the view:</p>
<pre><code>@ajax_login_required
def ajax_update_module(request, module_slug, action):
# Etc ...
return HttpResponse(json, mimetype='application/json')
</code></pre>
<p>And here is the JavaScript (jQuery):</p>
<pre><code>$.post('/restricted-url/', data, function(json) {
if (json.not_authenticated) {
alert('Not authorized.'); // Or something in a message DIV
return;
}
// Etc ...
});
</code></pre>
<hr>
<p><strong>EDIT</strong>: I've attempted to use <code>functools.wraps</code>, as suggested. I have not actually used this decorator in working code, so beware of possible bugs.</p>
|
<p>Here is proposed version of the decorator with wrap.__doc__ , wrap.__name__</p>
<pre><code>from functools import wraps
def ajax_login_required(function):
def wrap(request, *args, **kwargs):
if request.user.is_authenticated():
return function(request, *args, **kwargs)
json = simplejson.dumps({ 'not_authenticated': True })
return HttpResponse(json, mimetype='application/json')
wrap.__doc__ = function.__doc__
wrap.__name__ = function.__name__
return wrap
</code></pre>
| 40,332
|
<p>In my ASP.NET User Control I'm adding some JavaScript to the <code>window.onload</code> event:</p>
<pre><code>if (!Page.ClientScript.IsStartupScriptRegistered(this.GetType(), onloadScriptName))
Page.ClientScript.RegisterStartupScript(this.GetType(), onloadScriptName,
"window.onload = function() {myFunction();};", true);
</code></pre>
<p>My problem is, if there is already something in the <code>onload</code> event, than this overwrites it. How would I go about allowing two user controls to each execute JavaScript in the <code>onload</code> event?</p>
<p><strong>Edit:</strong> Thanks for the info on third party libraries. I'll keep them in mind. </p>
|
<p>Most of the "solutions" suggested are Microsoft-specific, or require bloated libraries. Here's one good way. This works with W3C-compliant browsers and with Microsoft IE.</p>
<pre><code>if (window.addEventListener) // W3C standard
{
window.addEventListener('load', myFunction, false); // NB **not** 'onload'
}
else if (window.attachEvent) // Microsoft
{
window.attachEvent('onload', myFunction);
}
</code></pre>
|
<p>I don't know a lot about ASP.NET, but why not write a custom function for the onload event that in turn calls both functions for you? If you've got two functions, call them both from a third script which you register for the event.</p>
| 3,085
|
<p>If I have several <code>Section</code> elements in an XML document, what XQuery do I use to get a list of all the <code>name</code> values?</p>
<pre><code><Section name="New Clients" filePath="XNEWCUST.TXT" skipSection="False">
</code></pre>
|
<p>In XPath 2.0 (which is a subset of XQuery) one would use the following expression to get a sequence of all string values of the "name" attributes of the "Section" elements:</p>
<pre class="lang-xquery prettyprint-override"><code>for $attr in //Section/@name
return string($attr)
</code></pre>
<p>Do note that using the "//" abbreviation is typically a bad practice as this may require a whole (subtree) to be traversed. In any case where the structure of the document is known a more specific XPath expression (such as one using specific location steps) should be preferred.</p>
|
<pre><code> /Section/@name
</code></pre>
| 41,997
|
<p>In Python properties are used instead of the Java-style getters, setters. So one rarely sees get... or set.. methods in the public interfaces of classes.</p>
<p>But in cases were a property is not appropriate one might still end up with methods that behave like getters or setters. Now my questions: Should these method names start with <code>get_</code> / <code>set_</code>? Or is this unpythonic vebosity since it is often obvious what is meant (and one can still use the docstring to clarify non-obvious situations)?</p>
<p>This might be a matter of personal taste, but I would be interested in what the majority thinks about this? What would you prefer as an API user?</p>
<p>Example: Say we have an object representing multiple cities. One might have a method <code>get_city_by_postalcode(postalcode)</code> or one could use the shorter name <code>city_by_postalcode</code>. I tend towards the later.</p>
|
<p>I think shorter is better, so I tend to prefer the later. But what's important is to consistent with your project: don't mix the two methods. If you jump into someone else's project, keep what the other developers chose initially.</p>
|
<p>If I have to use a getter/setter, I like it this way:</p>
<p>Suppose you have a variable self._x. Then x() would return the value of self._x, and setX(x) would set the value of self._x</p>
| 49,024
|
<p>Is there a generic way, without creating and managing your own CLR host, to take over locating and loading a type if that type is not found?</p>
<p><strong>The following is just an example. In your rush to be the first answer, don't suggest the new add-in framework or the MEF as a solution to my question.</strong></p>
<p>An example would be a sample with add-ins. Your app reads a file in that lists the types to use for a particular function. The app attempts to instantiate those types. If they aren't already currently loaded in the appdomain, the method fails. I'm looking for an event I can handle or a component I can provide my own implementation for that will allow me to gracefully handle these situations and provide additional logic for loading these assemblies.</p>
<hr>
<p>As far as I can tell (unless somebody has an example that works) none of the so-far mentioned AppDomain events fire when a type isn't found.</p>
<hr>
<p>Wait, apparently <a href="http://msdn.microsoft.com/en-us/library/system.appdomain.typeresolve.aspx" rel="nofollow noreferrer">this is working</a>! Not sure what I did wrong before, but this event fires good and well.</p>
|
<p>There are events on the <a href="http://msdn.microsoft.com/en-us/library/system.appdomain_events.aspx" rel="nofollow noreferrer">AppDomain</a> that you can use.</p>
<p>You would want <a href="http://msdn.microsoft.com/en-us/library/system.appdomain.typeresolve.aspx" rel="nofollow noreferrer">TypeResolve</a> event, and possibly the <a href="http://msdn.microsoft.com/en-us/library/system.appdomain.assemblyresolve.aspx" rel="nofollow noreferrer">AssemblyResolve</a> event.</p>
<p>Also, you can read more about how the <a href="http://msdn.microsoft.com/en-us/library/yx7xezcf.aspx" rel="nofollow noreferrer">.net runtime resolves assemblies</a>, so it's possible you could define this information in the probing section.</p>
|
<p>Isn't that possible just by using AppDomain events?</p>
| 14,905
|
<p><a href="http://en.wikipedia.org/wiki/SHA-1" rel="noreferrer">SHA Hash functions</a></p>
|
<pre><code>require 'digest/sha1'
Digest::SHA1.hexdigest 'foo'
</code></pre>
|
<p>Where 'serialize' is some user function defined elsewhere.</p>
<pre><code> def generateKey(data)
return Digest::SHA1.hexdigest ("#{serialize(data)}")
end
</code></pre>
| 5,473
|
<p>I am using Cura for slicing, and OctoPrint for the actual printing.</p>
<p>On small pieces with roughly one square cm of surface area prints over about 6 mm have a risk of coming off at 60 °C.</p>
<p>In fact, I have had to use 71 °C so it stick properly. However, I don't want the print bed that hot all the time. I would like to try a different number of layers at different bed temperatures till I get it right.</p>
<p>Gradually, over the course of 1-3 mm, for the bed temperature to decrease back to 60 °C to save on electricity. Possibly even 50 °C as the layers get higher.</p>
<p>Cura only support the initial layer having a different temperature and that isn't enough.</p>
<p>Apparently you can have custom user events with <a href="https://docs.octoprint.org/en/latest/events/index.html" rel="nofollow noreferrer">OctoPrint</a>, one of them being <strong>ZChange</strong> which is great.</p>
<pre><code>{__currentZ}: the current Z position of the head if known, -1 if not available
</code></pre>
<p>I need on the ZChange event to check the <code>__currentZ</code> and execute an<code>M140</code> with a temperature varying with layer height. Normally I would use a simple <code>if</code> command or etc., but how do I implement this here.</p>
<p>However, its seems you can execute a command or a G-code.</p>
<p>I can't seem to find any examples where I can test the Z height in layers or mm and execute a different temperature for different layers.</p>
<p>An additional problem is the increased temps cause the model to melt so that the opening is smaller nearest to the glass than most of the rest of the model.</p>
<p>I am height of the raft, which helps, but I am hoping for a compromise. </p>
<p>The print bed shouldn't need to be 70 °C for the whole vertical height of the model.</p>
<p>Any suggestions?</p>
|
<p><strong>The actual problem you are facing is bed adhesion</strong>, the proposed solution (in your question) shouldn't be the preferred solution to get your parts to stick to the plate/glass as plastic shrinks as it cools down. Note that a 5 °C temperature drop after the first layer usually isn't a problem, but larger temperature differences or shutting off the heat completely will cause your parts to come off the glass.</p>
<p>Note that PLA requires a temperature of about 60 °C (for adhesion as this is close to the glass temperature where the plastic is soft; however, note that PLA can be printed on cold bed surfaces on suitable bed surfaces). The slate of glass is an insulator, so it is perfectly possible that you need to set the bed at a higher temperature to get 60 °C at the surface of the glass plate. When the lower layer deforms the bed temperature is too high.</p>
<p>As you are using Cura, there is a plugin available called TweakAtZ, nowadays this is a default plugin. How to use this is described in <a href="/a/7346/">this anser</a> (on question <a href="/q/7345">"How does one use a heat tower?"</a>); instead of changing the hotend temperature you will need to modify the bed temperature instead (using <code>M140</code>).</p>
<p><strong>To solve the actual problem</strong>, you need to prepare the glass by cleaning it properly, use a level bed with a correct initial nozzle to bed distance for <code>Z=0</code> (usually thickness of a plain paper sheet A4/Letter) and an adhesive like hairspray, glue stick or a dedicated adhesion spray like 3DLAC or Dimafix. I'm using 3DLAC for several years (for PLA and PETG; Dimafix is supposed to be more sticky at higher temperatures, so for ABS for instance) and never had any problems with adhesion on properly levelled beds. See <a href="/a/4045">this answer</a> for another user's experience.</p>
<p>An OctoPrint solution using event as you suggest is not recommended. This is the config.yaml, e.i. the configuration of the print server, not a print instance option file. Furthermore, there are yet no plugins that can handle additional code when the head reaches a certain (layer)height. This is pretty tricky if you use Z position detection when the head also can hop, such code should be inserted by the slicer instead.</p>
<hr>
<p><em>Related to your question are the answers on question: <a href="/q/10683">"Why keep the bed heated after initial layer(s) with PLA (or PETG)?"</a>.</em></p>
|
<ul>
<li>You can manually edit the file. Look for the line that has the Z height of your choice, and insert the temp change g-code right above it.</li>
<li>Upgrade to a real slicer like Simplify3D with has an options to set a heater temp at different layers.</li>
<li>Preheat the bed before you print, then print with a bed temp set lower than the temp you preheated at. This will give the illusion of a temp change.</li>
</ul>
<p><em>(I for one turn off my bed after the first layer, when I'm printing PLA. I also don't have proper cooling (at this time), my environment is humid (59.9%) and the ambient air temp is 31C.) - just for context</em></p>
| 1,549
|
<p>I am hitting some performance bottlenecks with my C# client inserting bulk data into a SQL Server 2005 database and I'm looking for ways in which to speed up the process.</p>
<p>I am already using the SqlClient.SqlBulkCopy (which is based on TDS) to speed up the data transfer across the wire which helped a lot, but I'm still looking for more.</p>
<p>I have a simple table that looks like this: </p>
<pre><code> CREATE TABLE [BulkData](
[ContainerId] [int] NOT NULL,
[BinId] [smallint] NOT NULL,
[Sequence] [smallint] NOT NULL,
[ItemId] [int] NOT NULL,
[Left] [smallint] NOT NULL,
[Top] [smallint] NOT NULL,
[Right] [smallint] NOT NULL,
[Bottom] [smallint] NOT NULL,
CONSTRAINT [PKBulkData] PRIMARY KEY CLUSTERED
(
[ContainerIdId] ASC,
[BinId] ASC,
[Sequence] ASC
))
</code></pre>
<p>I'm inserting data in chunks that average about 300 rows where ContainerId and BinId are constant in each chunk and the Sequence value is 0-n and the values are pre-sorted based on the primary key. </p>
<p>The %Disk time performance counter spends a lot of time at 100% so it is clear that disk IO is the main issue but the speeds I'm getting are several orders of magnitude below a raw file copy.</p>
<p>Does it help any if I:</p>
<ol>
<li>Drop the Primary key while I am doing the inserting and recreate it later</li>
<li>Do inserts into a temporary table with the same schema and periodically transfer them into the main table to keep the size of the table where insertions are happening small</li>
<li>Anything else?</li>
</ol>
<p>--
Based on the responses I have gotten, let me clarify a little bit:</p>
<p>Portman: I'm using a clustered index because when the data is all imported I will need to access data sequentially in that order. I don't particularly need the index to be there while importing the data. Is there any advantage to having a nonclustered PK index while doing the inserts as opposed to dropping the constraint entirely for import?</p>
<p>Chopeen: The data is being generated remotely on many other machines (my SQL server can only handle about 10 currently, but I would love to be able to add more). It's not practical to run the entire process on the local machine because it would then have to process 50 times as much input data to generate the output.</p>
<p>Jason: I am not doing any concurrent queries against the table during the import process, I will try dropping the primary key and see if that helps.</p>
|
<p>Here's how you can disable/enable indexes in SQL Server:</p>
<pre><code>--Disable Index ALTER INDEX [IX_Users_UserID] SalesDB.Users DISABLE
GO
--Enable Index ALTER INDEX [IX_Users_UserID] SalesDB.Users REBUILD</code></pre>
<p>Here are some resources to help you find a solution:</p>
<p><a href="http://weblogs.sqlteam.com/mladenp/archive/2006/07/17/10634.aspx" rel="noreferrer">Some bulk loading speed comparisons</a></p>
<p><a href="http://www.sqlteam.com/article/use-sqlbulkcopy-to-quickly-load-data-from-your-client-to-sql-server" rel="noreferrer">Use SqlBulkCopy to Quickly Load Data from your Client to SQL Server</a></p>
<p><a href="http://msdn.microsoft.com/en-us/library/aa178096(SQL.80).aspx" rel="noreferrer">Optimizing Bulk Copy Performance</a></p>
<p>Definitely look into NOCHECK and TABLOCK options:</p>
<p><a href="http://msdn.microsoft.com/en-us/library/ms187373.aspx" rel="noreferrer">Table Hints (Transact-SQL)</a></p>
<p><a href="http://msdn.microsoft.com/en-us/library/ms174335.aspx" rel="noreferrer">INSERT (Transact-SQL)</a></p>
|
<p>Yes your ideas will help.<br>
Lean on option 1 if there are no reads happening while your loading.<br>
Lean on option 2 if you destination table is being queried during your processing.</p>
<p>@Andrew<br>
Question. Your inserting in chunks of 300. What is the total amount your inserting? SQL server should be able to handle 300 plain old inserts very fast.</p>
| 4,394
|
<p>How do I set the initial width of a QDockWidget?</p>
<p>I have implemented the sizeHint function but what next?</p>
|
<p>The documentation for <code>QDockWidget</code> says:</p>
<blockquote>
A QDockWidget acts as a wrapper for its child widget, set with setWidget(). Custom size hints, minimum and maximum sizes and size policies should be <b>implemented in the child widget</b>. QDockWidget will respect them, adjusting its own constraints to include the frame and title. <b>Size constraints should not be set on the QDockWidget itself</b>, because they change depending on wether it is docked; a docked QDockWidget has no frame and a smaller title bar.
</blockquote>
<p>So the size hint is taken from whatever you put in the dock widget. Have you tried setting the size of the <code>QDockWidget</code>'s child?</p>
<p>But, I agree with Marius, the best thing to do is probably to use <code>QSettings</code> to save and restore the widths of all the dock windows when the application starts. Have a look at <code>QMainWindow::saveState</code> Apart from getting the data from <code>saveState</code> rather than from individual functions my save function looks very similar to the one given by Marius.</p>
|
<p>If you want it to have the same width as the same last time the program was running, you should look into settings. The Qt 4.4 documentation has an example on how to use settings <a href="http://doc.trolltech.com/4.4/mainwindows-application.html" rel="noreferrer">here</a>.</p>
<p>This is how I have done it:</p>
<pre><code>void Applicotion::readSettings() {
QSettings settings("Company Name", "Application Name");
settings.beginGroup("LibraryDock");
libraryDock->setFloating(settings.value("docked").toBool());
libraryDock->resize(settings.value("size", QSize(1, 1)).toSize());
libraryDock->move(settings.value("pos", QPoint(200, 200)).toPoint());
addDockWidget((Qt::DockWidgetArea)settings.value("dockarea", Qt::RightDockWidgetArea).toInt(), libraryDock);
settings.endGroup();
}
void Applicotion::writeSettings() {
QSettings settings("Company Name", "Application Name");
settings.beginGroup("LibraryDock");
settings.setValue("dockarea", dockWidgetArea(libraryDock));
settings.setValue("docked", libraryDock->isFloating());
settings.setValue("size", libraryDock->size());
settings.setValue("pos", libraryDock->pos());
settings.endGroup();
</code></pre>
<p>}</p>
| 23,192
|
<p>Many times I've seen links like these in HTML pages:</p>
<pre><code><a href='#' onclick='someFunc(3.1415926); return false;'>Click here !</a>
</code></pre>
<p>What's the effect of the <code>return false</code> in there?</p>
<p>Also, I don't usually see that in buttons.</p>
<p>Is this specified anywhere? In some spec in w3.org?</p>
|
<p>The return value of an event handler determines whether or not the default browser behaviour should take place as well. In the case of clicking on links, this would be following the link, but the difference is most noticeable in form submit handlers, where you can cancel a form submission if the user has made a mistake entering the information.</p>
<p>I don't believe there is a W3C specification for this. All the ancient JavaScript interfaces like this have been given the nickname "DOM 0", and are mostly unspecified. You may have some luck reading old Netscape 2 documentation.</p>
<p>The modern way of achieving this effect is to call <code>event.preventDefault()</code>, and this is specified in <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-flow-cancelation" rel="noreferrer">the DOM 2 Events specification</a>.</p>
|
<p>When using forms,we can use 'return false' to prevent submitting.</p>
<pre><code>function checkForm() {
// return true to submit, return false to prevent submitting
}
<form onsubmit="return checkForm()">
...
</form>
</code></pre>
| 15,675
|
<p>Quick question: Would it be a good or a bad idea to implement my domain-driven design style repositories as singletons? Why?</p>
<p>Or should I maybe use a dependency injector container to manage my repositories and decide if they are singletons or not?</p>
<p>I'm still reading <em>DDD Quickly</em>, and would like to see some good repository examples.</p>
|
<p>I've seen a couple of ways to do this.</p>
<p>The most common way is to use dependency injection to inject the repositories into the objects that use them. Usually these are presenter or controller classes but in some cases the model calls into the repository. Usually it's better if you avoid this. If you can use a di-container to do this then go for it.</p>
<p>You can also make the repositories implement the singleton pattern. I'd try to avoid this because singletons usually use static methods. This can make testing the code that calls into the singletons more difficult. If you have to do things this way then make sure you separate out the code that calls the singleton and use "manual" dependency injection to inject the singletons into the classes that call them. This gets rid of some of the tight coupling you'd otherwise get.</p>
<p>I've seen some examples where the repositories never get called. When someone navigates the object graph in the model and requests an object that isnt loaded the model just raises an event and the repository reacts to this event. This way there are no calls into the repository and it's completely decoupled from the model. I havn't used this architecture myself but it seems very clean.</p>
|
<p>I am not sure about this and I have the same problem. I think that you should make a repository a singleton when the objects that it works with are used often. And that it shouldn't be made a singleton if you use objects that it works with rarely, because the repository would take a lot of memory for objects and maybe it would be called only once and never again during usage of the application.
As I said, this may not be correct thinking.</p>
| 41,948
|
<p>I'm attempting to eliminate leading any leading zeroes in my date when I run the get-date cmdlet by trying: </p>
<pre><code>$filedate = get-date -uformat "%m-%d-%Y"
$filedate = $filedate.ToString().Replace("0", "")
</code></pre>
<p>this returns "01-04-2008"</p>
<p>I want to the output to be "1-4-2008"</p>
<p>any ideas on another way of doing this?</p>
<p>thanks in advance</p>
|
<pre><code>$filedate = get-date -format "M-d-yyyy"
</code></pre>
|
<p>use format string like : </p>
<pre><code>get-date -format yyyy/M/d
</code></pre>
<p>or</p>
<p>get-date.tostring(yyyy/M/d)</p>
| 44,386
|
<p>I've attempted just about everything to get our ClickOnce VB.NET app to run under Terminal Services as a RemoteApp. I have a batch file that runs the .application file for the app.</p>
<p><strong>This works fine via RDP desktop session on the terminal server</strong>. As a TS RemoteApp, however, well... not so much.</p>
<p>I get a quick flash of command prompt (the batch file) on the client system and then... nothing...</p>
<p>Same goes for having it point to the .application file directly (without using a batch file) or even copying the publication locally and having it point to that.</p>
<p>I found a <a href="http://social.technet.microsoft.com/forums/en-US/winserverTS/thread/0226cf94-133c-4b22-9800-942e7d091c71/" rel="nofollow noreferrer">technet.microsoft.com</a> discussion about a similar issue, but there's no resolution to it listed.</p>
<p><strong>For anyone who has run into this before and got it working, what did you have to do?</strong></p>
<p>We currently use RemoteApp's for everything else on that server, so I'm hoping to stick with that if possible.</p>
<p>The current workaround is to build and run an MSI-based installer for the app on our terminal server whenever we publish via OneClick out to the network, but this can be quite a pain at times and is easy to forget to do.</p>
<p>Since the app works fine via Terminal Services when run in full desktop mode but not during RemoteApp, I don't think it's anything specific to Terminal Server permissions so much as ClickOnce requiring something that isn't available when running as a RemoteApp.</p>
|
<p>The Key to getting it to work is to use Windows Explorer "C:\windows\explorer.exe". This process is the base process when you login to a full session.</p>
<p>If you setup the RemoteApp to use Windows Explorer and the command line argument of the path to the .application file for the ClickOnce application then it will work when launched as a remote application. Windows Explorer will flash for a second when it starts, but it will disappear then the ClickOnce application will launch.</p>
|
<p>Try using RegMon and FileMon when starting the app - You may be able to track it down to a file and/or registry permission issue.</p>
| 13,164
|
<p>I have a simple row that I edit using LINQ. It has about 30 columns, including a primary key numeric sequence.</p>
<p>When an UPDATE is performed through LINQ, the UPDATE statement includes all the columns of the table (for concurrency checking). </p>
<p>I'm wondering how inefficient this is - if not negligibiel. Since there is an index on the primary key I assume that column is being used for the initial row search and then the other fields are being checked in addition. I wouldn't have thought this would take more than a negligible amount of time.</p>
<p>The reason I ask is that I've seen this UPDATE take over a second in some cases, which just doesnt seem right. There may be other long running operations things going on but it made me curious as to whether or not I should be worried.</p>
<p>I know I can set 'UpdateCheck' to never for all the other fields, but this is a pain. </p>
<p>Is there a way to turn off 'Update Check' for a single SubmitChanges(), or do I have to do it by changing 'UpdateCheck' for every field.</p>
<p>Any advice would be appreciated.</p>
<p>Here is the SQL update :</p>
<pre><code>exec sp_executesql N'UPDATE [dbo].[SiteVisit]
SET [TotalTimeOnSite] = @p12, [ContentActivatedTime] = @p13
WHERE ([SiteVisitId] = @p0) AND ([SiteUserId] IS NULL) AND ([ClientGUID] = @p1) AND ([ServerGUID] IS NULL) AND ([UserGUID] = @p2) AND ([SiteId] = @p3) AND ([EntryURL] = @p4) AND ([CampaignId] = @p5) AND ([Date] = @p6) AND ([Cookie] IS NULL) AND ([UserAgent] = @p7) AND ([Platform] IS NULL) AND ([Referer] = @p8) AND ([KnownRefererId] = @p9) AND ([FlashVersion] IS NULL) AND ([SiteURL] IS NULL) AND ([Email] IS NULL) AND ([FlexSWZVersion] IS NULL) AND ([HostAddress] IS NULL) AND ([HostName] IS NULL) AND ([InitialStageSize] IS NULL) AND ([OrderId] IS NULL) AND ([ScreenResolution] IS NULL) AND ([TotalTimeOnSite] IS NULL) AND ([CumulativeVisitCount] = @p10) AND ([ContentActivatedTime] IS NULL) AND ([ContentCompleteTime] IS NULL) AND ([MasterVersion] = @p11) AND ([VisitedHome] IS NULL) AND ([VisitedStore] IS NULL) AND ([VisitedVideoDemos] IS NULL) AND ([VisitedProducts] IS NULL) AND ([VisitedAdvantages] IS NULL) AND ([VisitedGallery] IS NULL) AND ([VisitedTestimonials] IS NULL) AND ([VisitedEvolution] IS NULL) AND ([VisitedFAQ] IS NULL)',N'@p0 int,@p1 uniqueidentifier,@p2 uniqueidentifier,@p3 int,@p4 varchar(46),@p5 varchar(3),@p6 datetime,@p7 varchar(164),@p8 varchar(36),@p9 int,@p10 int,@p11 int,@p12 int,@p13 int',@p0=1009772,@p1='039A0614-31EE-4DD9-9E1A-8A0F947E1719',@p2='C83C0E68-142A-47CB-B7F9-BAF462E79429',@p3=1,@p4='http://www.example.com/default.aspx?c=183',@p5='183',@p6='2008-11-30 18:22:59:047',@p7='Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; SIMBAR={85B62341-3F6B-4645-A473-53A2D2BB66DC}; FunWebProducts; .NET CLR 1.1.4322; InfoPath.1; .NET CLR 2.0.50727)',@p8='http://apps.facebook.com/inthemafia/',@p9=1,@p10=1,@p11=30,@p12=6,@p13=6
</code></pre>
|
<p>We ran into this early on Stack Overflow. Every LINQ to SQL update verifies that the underlying fields haven't changed before writing an update. In other words, every update is "update the record <em>only if</em> this field equals, and this field equals, and this field equals"..</p>
<p>We decided most of the time we didn't care about pessimistic updates, and the only field that the update needs to check is the Id field.</p>
<p>So, what we did was set <strong><code>UpdateCheck="never"</code></strong> for every field except the Id in the dbml mapping file, like so:</p>
<pre><code><Type Name="Badge">
<Column Name="Id" Type="System.Int32" DbType="Int NOT NULL IDENTITY"
IsPrimaryKey="true" IsDbGenerated="true" CanBeNull="false" />
<Column Name="Class" Type="System.Byte" DbType="TinyInt NOT NULL"
CanBeNull="false" UpdateCheck="Never" />
<Column Name="Name" Type="System.String" DbType="VarChar(50) NOT NULL"
CanBeNull="false" UpdateCheck="Never" />
</code></pre>
<p>I don't know if there is a way to do this programmatically or on the fly.</p>
|
<p>If you can modify the schema add a column of type rowversion. The latest LINQ to SQL sets the update check to Never for all columns. If you have a timestamp, it will use that as an optimistic lock check, and the system bumps it every time there is an update. </p>
<p>NOTE: this used to be the Timestamp data type as defined by SQL '92, but the implemented it without any time information so it was not compatible with any other standard system. Maybe that was intentional, who knows. </p>
| 42,759
|
<p>I am currently working on parts for a custom prosthesis.</p>
<p>My main concern at the moment is to find biocompatible materials that can be 3D printed from a UP or a Reprap.
The piece would need to be in contact with the skin for extended periods of time, probably around 17 hours a day on average.</p>
<p>The main concerns I have are:</p>
<ul>
<li>Skin reactions caused by prolonged contact</li>
<li>Skin reactions and bruising caused by friction</li>
<li>Degradation of the materials due to prolonged exposure to skin secretions and sweat</li>
<li>Risks of toxicity in the compounds generated by the aforementioned material degradation</li>
</ul>
<p><strong>Which materials can you recommend?</strong> </p>
<p><strong>Any extensive data (from testing) would be greatly appreciated.</strong></p>
|
<p>There are printers designed for medical use, and the manufacturers supply them with varying levels of <a href="http://www.medicalplasticsnews.com/opinion/passing-the-test_1/" rel="nofollow">certification and testing</a>, however I've not seen a filament manufacturer certify their material as bio-compatible separate from the printer. The printing process changes the material slightly in the best case (and significantly with poor temperature control or badly set parameters), so even if bio-compatible filament were found, the resulting product might not achieve the same level of bio-compatibility.</p>
<p>If your intent is to use hobbyist level machine for medical purposes, you might simply want to use an interface, such as a sock or a molded/cast polymer that you know to be bio-compatible between the printed part and the skin.</p>
|
<p>If you want to know something about what you are questioning, it is interesting to you to read <a href="http://e-nable.org/resources/prosthetics-students-consultation/" rel="nofollow noreferrer">http://e-nable.org/resources/prosthetics-students-consultation/</a></p>
<p>That's a link with complementary information how to print 3D as a volunteer.</p>
<p>I know that is not enough information about products, but I believe Nylon is the best recommend because it is what generally printers are using, though.</p>
<p>This website supports information with Dr. Chang by the e-mail eagle01@rocketmail.com</p>
<p>but there insnt information about the components used in the prosthetics, but I know that Nylon is the best suited to it nowadays. </p>
<p>If you prefer there is a site with makers loging information about PETG:
<a href="https://www.matterhackers.com/news/how-to-succeed-when-printing-with-petg-filament" rel="nofollow noreferrer">https://www.matterhackers.com/news/how-to-succeed-when-printing-with-petg-filament</a></p>
| 117
|
<p>I have a BSTR object that I would like to convert to copy to a wchar__t object. The tricky thing is the length of the BSTR object could be anywhere from a few kilobytes to a few hundred kilobytes. Is there an efficient way of copying the data across? I know I could just declare a wchar_t array and alway allocate the maximum possible data it would ever need to hold. However, this would mean allocating hundreds of kilobytes of data for something that potentially might only require a few kilobytes. Any suggestions?</p>
|
<p>BSTR objects contain a length prefix, so finding out the length is cheap. Find out the length, allocate a new array big enough to hold the result, process into that, and remember to free it when you're done.</p>
|
<p>Use ATL, and CStringT then you can just use the assignment operator. Or you can use the USES_CONVERSION macros, these use heap alloc, so you will be sure that you won't leak memory.</p>
| 9,754
|
<p>I was wondering if adding (an) extra fan(s) (not connected to the printer, but blowing on the print area) could improve the quality of PLA based prints(printing at 210 C). The printer already has a built in fan with a fan shroud that directs air to the hotend, but is it beneficial to add an extra fan in order to get better results on overhangs, fine details, etc, or does extra cooling negatively/not affect print quality? </p>
|
<blockquote>
<p>The printer already has a built in fan with a fan shroud that directs air to the hotend</p>
</blockquote>
<p><strong>Unless your printer is defective, it may look like so, but the airflow should really be directed towards the print, not the hot-end</strong>. Cooling the hot-end will at best just waste energy, requiring extra heat to keep it hot, at worst affect your print quality negatively.</p>
<blockquote>
<p>is it beneficial to add an extra fan in order to get better results on overhangs?</p>
</blockquote>
<p>The issue with external fans, not connected to the printer, is that you can't properly direct their ariflow, so:</p>
<ul>
<li>you <em>will</em> direct some of it on the hot-end itself (see above on why that's not good)</li>
<li>you will potentially cool your print unevenly, which - depending from how much, how fast, and what type of filament you are using - may warp your prints</li>
</ul>
<p>That said, depending from a number of factors, including your ability to position the fans appropriately, <strong>you <em>may</em> gain some benefit from them (I saw people doing this to help with PETG stringing), but I would recommend instead to upgrade the part fan of your printer (e.g.: larger diameter, higher RPM) and your duct (better focus on the extruded filament)</strong>, as these upgrades will have no drawbacks and will perform consistently on each part of the print.</p>
<p>For most common printer, there are printable mods that allow to do both, often available off thingiverse or on dedicated user community forums.</p>
|
<p>Fan blow at hot end is necessary because hotend needs cooling.</p>
<p>For PLA it will yield better result with a seperate controllable fan direct airflow across the print head, but just like everything with 3D printing, you will need to test out every possible configuration to get the best for your setup.</p>
| 819
|
<p>Some friends and colleagues of mine have a little running contest to find or write the longest class/variable/property/method names possible. Keep in mind, we try to be good boys and girls and keep the naming intelligible and concise, while still explaining what the thing does via its name.</p>
<p>Sometimes it just doesn't happen though. Have you run in to this? I'd just like to see what's out there. (Maybe my friends and I aren't as crazy as we think)</p>
<p>Note: I'm not looking for <strong>bad</strong> naming. That's already <a href="https://stackoverflow.com/questions/143701/what-is-the-worst-classvariablefunction-name-you-have-ever-encountered">here</a>. I'm looking for <strong>good</strong> naming that just got a little long.</p>
|
<p>This isn't a class name but an enum, but it's a lot longer:</p>
<pre><code>VirtualMachineDeviceRuntimeInfoVirtualEthernetCardRuntimeStateVmDirectPathGen2InactiveReasonOther
</code></pre>
<p>from the VMware vSphere API. Google for it and you'll find the online documentation.</p>
|
<p>get the <code>js</code> items that will be retrieved and if page should display recommendations.</p>
| 26,070
|
<p>i m trying to design a mmo game using python...</p>
<p>I have evaluated stackless and since it is not the general python and it is a fork, i dont want to use it</p>
<p>I am trying to chose between
pysage
candygram
dramatis
and
parley</p>
<p>any one try any of these libraries?</p>
<p>Thanks a lot for your responses</p>
|
<p>I would go for <a href="http://code.google.com/p/pysage/" rel="nofollow noreferrer">pysage</a>.</p>
<p>It has the highest level of abstraction and a lightweight messaging API which will give you lots of flexibility. I would imagine when designing an MMO you will want as much flexibility as possible.</p>
<p>It also takes a page from Erlang's Actor model which is really solid.</p>
<p>That's great you are trying to build an MMO via python! It has great OpenGL bindings when you want to add graphics which is great!</p>
<p>Hope that helps.</p>
|
<p>I tried to write an MMO in Python, it was horrible. Now I have switched to Erlang and its lightyears ahead of other languages in terms of developing server software. You can check my project at: <a href="http://www.next-gen.cc" rel="nofollow noreferrer">http://www.next-gen.cc</a>.</p>
<p>Btw writing the client graphics in OpenGL is a huge task, you probably want something like Ogre3d (there are python bindings).</p>
| 40,221
|
<p>I am looking for a .net templating engine - something simple, lightweight, stable with not too many dependencies. All I need it for at the moment is creating templated plain text and html emails. Can anyone give me a good recommendation?</p>
<p>If it helps at all - something like Java's <a href="http://freemarker.sourceforge.net/" rel="noreferrer">Freemarker</a> or <a href="http://velocity.apache.org/" rel="noreferrer">Velocity</a> libraries.</p>
<p>[UPDATE]
Thanks for the answers so far - much appreciated. I am really intested in recommendations or war stories from when you have used these libraries. Seems to be the best way to make a decision without trying each in turn.</p>
|
<p>Here's a couple more:</p>
<ul>
<li><a href="http://code.google.com/p/nhaml/" rel="noreferrer">NHaml</a></li>
<li><a href="http://sparkviewengine.com/" rel="noreferrer">Spark</a></li>
<li><a href="http://docs.castleproject.org/MonoRail.Brail.ashx" rel="noreferrer">Brail</a> (can be used <a href="https://github.com/castleproject/MonoRail/blob/master/MR2/src/Castle.MonoRail.Views.Brail/StandaloneBooViewEngine.cs" rel="noreferrer">standalone</a>)</li>
</ul>
<p>About NVelocity, it has been forked by the Castle guys, it's being developed <a href="https://github.com/castleproject/MonoRail/tree/master/MR2/NVelocity" rel="noreferrer">here</a></p>
<p>For emails, I've never needed more than NVelocity.</p>
|
<p>Have you seen NVelocity, a .NET port of Velocity?
<a href="http://nvelocity.sourceforge.net/" rel="nofollow noreferrer">http://nvelocity.sourceforge.net/</a></p>
| 44,173
|
<p>How can I compile a .cs file into a DLL?</p>
<p>My project name is WA. In my <code>bin</code> folder after the compilation, I found:</p>
<ul>
<li><code>WA.exe</code></li>
<li><code>WA.vshost.exe</code></li>
<li><code>WA.pdb</code></li>
</ul>
|
<p>You have to compile it:</p>
<pre><code>csc /t:library source.cs -> source.dll
</code></pre>
|
<p>Its automatically created for you when you run a build in visual studio. Check the bin folder in your project folder.</p>
| 42,806
|
<p>For features comparison of Web Canoo Web Functional Test and Selenium software, it would be good have an assessment, in terms of integration to Java platform applications, speed, how quick is it to deploy Tests, execute, and analyze results, JavaScript support etc.
I am using Canoo project, it is pretty good. </p>
<p>Tatyana</p>
|
<p>So I initially pursued Canoo as a direction for functional tests.
I ended up choosing Selenium as we saw that running selenium in browser
was a better fit for us than Canoo which uses HTTPUnit to run tests.</p>
<p>If you are running tests at build time with selenium you will need to
have the browser
software you wish to use on the build server. It is not possible for
us to test IE on our build
server for example....So we only run the tests in Firefox.</p>
<p>The killer feature for us was the Selenium IDE. We have folks using
the selenium IDE
who are not really developers which is a great help. The development team
works with them to make sure the tests are running properly.</p>
<p>Canoo has its own advantages that, A rather biased blog entry is here:
<a href="http://mguillem.wordpress.com/2007/10/29/webtest-vs-selenium-webtest-wins-13-5/" rel="nofollow noreferrer">http://mguillem.wordpress.com/2007/10/29/webtest-vs-selenium-webtest-wins-13-5/</a></p>
<p>Note that in spite of all those things I still prefer Selenium...</p>
|
<p>Canoo webtest reports are very rich in features, not sure if selenium has such in-built reporting capability or if Selenium + TestNG gives the equivalent.</p>
<p>Canoo scripting is much simpler and easy..</p>
| 32,620
|
<p>Do we need mold release agent in 3D printing mold? If it is not used, what effect will it have on the product?</p>
|
<p>It seems I misread your question. </p>
<h2>3D Printed Mold</h2>
<p>You were asking about (or the question now states) use of a mold release compound to prevent a molded part from sticking to a 3d print mold.</p>
<p>Yes. It is always beneficial for the molded part to not stick to the mold. Easy separation and part removal is important for the life of the mold and for the surface finish of the part.</p>
<p>There are two molding situations that seem important. </p>
<h2>Flexible Mold or Object</h2>
<p>In the first, either the part of the mold is elastic, so the actual sliding of one surface on the other isn't important. Here, a mold release agent would help by preventing the cast object from binding to the mold material.</p>
<h2>Stiff Mold and Object</h2>
<p>The second case is where both the mold and the object are stiff, and the object must slide out of the mold. Here the layer lines should be considered, since there may, locally, be reverse draft angles where the larger part can not slip past an obstructing filament line. Using a process that doesn't leave filament lines, or using the thinnest possible filament layers, or smoothing the mold internal surfaces, or possibly filling the spaces between the ridges with another material may eliminate the problem. A "mold release agent" would still be used to reduce the attachment of the object to the mold, although one may be able to use ample release agent both to fill the groves in the mold and prevent adhesion.</p>
|
<p>Welcome to the 3D Printing Stack Exchange site.</p>
<h2>Used in Casting</h2>
<p>A mold release agent is commonly used when a part is cast. The release agent is placed on the inside of the mold before the liquid object is added. As the object becomes solid, the release agent prevents the object from adhering to the mold. As a result, the objects are easier to pop out of the mold, and in some processes, the mold can be reused.</p>
<h2>3D Printing is Different</h2>
<p>A mold release agent is used to allow the desired part to be separated from the mold. In FDM (thin plastic extrusions bonding together into objects) 3D printing, the object is surrounded by air, except for the bottom where the object contacts the print bed.</p>
<h2>Bed Adhesion</h2>
<p>For most materials, getting the bottom of the object to stick firmly enough is the problem faced, rather than making it easy to remove. In many cases, a compound is placed on the top of the bed to help the plastic stick to the bed. It is a "mode adhesion agent" rather than a release agent.</p>
<p>For some combinations of materials, the bed material and the plastic have a particularly strong adhesion, such that it can be difficult to remove the object without damaging the bed surface. Notably, this occurs with a PEI bed and PETG plastic. In this and similar cases, the mold adhesion agents can be used on the bed. This slightly separates the plastic from the bed material, and we can avoid bed damage.</p>
<h2>Internal Adhesion</h2>
<p>With multimaterial printers becoming more common, there are cases where two parts which might touch and stich during printing should be isolated during the printing process. A second (or third) material can be used to isolate the parts. If the isolation material is sufficiently different from the desired objects, it can be removed by a solvent.</p>
<p>This approach is limited to cases where the objects should be separated by at least one printer thickness of the soluble material.</p>
| 1,459
|
<p>I query all security groups in a specific domain using </p>
<pre><code>PrincipalSearchResult<Principal> results = ps.FindAll();
</code></pre>
<p>where ps is a PrincipalSearcher.</p>
<p>I then need to iterate the result (casting it to a GroupPrincipal first ) and locate the ones that contains a specific string in the notes field.</p>
<p>But the Notes field from AD is appearently not a public field in the GroupPrincipal class, doh.
What am I doing wrong ?</p>
<p>Update:
I have given up on this one. It seems like there is no way to access that pesky Notes field.</p>
|
<p>You can access the 'notes' field of a directory entry as such:</p>
<pre><code>// Get the underlying directory entry from the principal
System.DirectoryServices.DirectoryEntry UnderlyingDirectoryObject =
PrincipalInstance.GetUnderlyingObject() as System.DirectoryServices.DirectoryEntry;
// Read the content of the 'notes' property (It's actually called info in the AD schema)
string NotesPropertyContent = UnderlyingDirectoryObject.Properties["info"].Value;
// Set the content of the 'notes' field (It's actually called info in the AD schema)
UnderlyingDirectoryObject.Properties["info"].Value = "Some Text"
// Commit changes to the directory entry
UserDirectoryEntry.CommitChanges();
</code></pre>
<p>Took a little bit of hunting - I had assumed the notes property was indeed called 'notes', ADSIEdit to the rescue!</p>
|
<p>For anybody using the "info" attribute:note that it will throw an exception if using an empty string or null value.</p>
| 41,925
|
<p>I wish to set a usererror string before leaving a function, depending on the return code and variable in the function.</p>
<p>I currently have:</p>
<pre><code>Dim RetVal as RetType
try
...
if ... then
RetVal = RetType.FailedParse
end try
endif
...
finally
select case RetVal
case ...
UserStr = ...
end select
end try
return RetVal
</code></pre>
<p>Is it possible to use return RetType.FailedParse, then access this in the finally block?</p>
|
<p>The only real way of doing this in C# would be to declare a variable at the start of the method to hold the value - i.e.</p>
<pre><code>SomeType result = default(SomeType); // for "definite assignment"
try {
// ...
return result;
}
finally {
// inspect "result"
}
</code></pre>
<p>In VB, you <em>might</em> be able to access the result directly - since IIRC it kinda works like the above (with the method name as "result") anyway. Caveat: I'm <strong>really</strong> not a VB person...</p>
|
<p>Declare the variable out of the try block, and check in the finally block if it has been set.</p>
| 39,194
|
<p>I really want to get the google Calendar Api up an running. I found a <a href="http://www.ibm.com/developerworks/library/x-googleclndr/" rel="nofollow noreferrer">great article</a> about how to get started. I downloaded the Zend GData classes. I have php 5 running on my dev box and all the exetensions should be loading.</p>
<p>I cant get openssl running and recieve the following error when I try to run any of the example page which should connect to my Google Calendar.</p>
<pre><code>Uncaught exception 'Zend_Gdata_App_HttpException' with message 'Unable to Connect to ssl://www.google.com:443. Error #24063472: Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?'
</code></pre>
<p>I have looked in many places to try to get OpenSSL running on my machine and installed. </p>
<p>Does anyone know of a simple failsafe tutorial to get this combination up and running?</p>
|
<p>I think this use of SSL is part of the Zend GData library so I assume it is correct. I think not having OpenSSL correctly installed is my main issue.</p>
|
<p>Could you have mistyped the PROTOCOL in the URL? It should be HTTPS, not "SSL". For example, , not SSL://www.google.com:443. Can you double check this in your example client and make sure it is HTTPS, not SSL.</p>
| 10,192
|
<p>I have a data set that is organized in the following manner:</p>
<pre><code>Timestamp|A0001|A0002|A0003|A0004|B0001|B0002|B0003|B0004 ...
---------+-----+-----+-----+-----+-----+-----+-----+-----
2008-1-1 | 1 | 2 | 10 | 6 | 20 | 35 | 300 | 8
2008-1-2 | 5 | 2 | 9 | 3 | 50 | 38 | 290 | 2
2008-1-4 | 7 | 7 | 11 | 0 | 30 | 87 | 350 | 0
2008-1-5 | 1 | 9 | 1 | 0 | 25 | 100 | 10 | 0
...
</code></pre>
<p>Where A0001 is Value A of item #1 and B0001 is Value B of item #1. There can be over 60 different items in a table, and each item has an A value column and a B value column, meaning a total of over 120 columns in the table.</p>
<p>Where I want to get to is a 3 column result (Item index, A Value, B Value) that sums the A and B values for each item:</p>
<pre><code>Index | A Value | B Value
------+---------+--------
0001 | 14 | 125
0002 | 20 | 260
0003 | 31 | 950
0004 | 9 | 10
....
</code></pre>
<p>As I am going from columns to rows I would expect a pivot in the solution, but I am not sure of how to flesh it out. Part of the issue is how to strip out the A's and B's to form the values for the Index column. The other part is that I have never had to use a Pivot before, so I am stumbling over the basic syntax as well.</p>
<p>I think that ultimately I need to have a multi step solution that first builds the summations as:</p>
<pre><code>ColName | Value
--------+------
A0001 | 14
A0002 | 20
A0003 | 31
A0004 | 9
B0001 | 125
B0002 | 260
B0003 | 950
B0004 | 10
</code></pre>
<p>Then modify the ColName data to strip out the index:</p>
<pre><code>ColName | Value | Index | Aspect
--------+-------+-------+-------
A0001 | 14 | 0001 | A
A0002 | 20 | 0002 | A
A0003 | 31 | 0003 | A
A0004 | 9 | 0004 | A
B0001 | 125 | 0001 | B
B0002 | 260 | 0002 | B
B0003 | 950 | 0003 | B
B0004 | 10 | 0004 | B
</code></pre>
<p>Finally self join to move the B values up next to the A Values.</p>
<p>This seems to be a long winded process to get what I want. So I am after advice as to whether I am headed down the right path, or is there another approach that I have over looked that will make my life so much easier.</p>
<p>Note 1) The solution has to be in T-SQL on MSSQL 2005.</p>
<p>Note 2) The format of the table cannot be changed.</p>
<p><strong>Edit</strong> Another method I have thought about uses UNIONs and individual SUM()s on each column:</p>
<pre><code>SELECT '0001' as Index, SUM(A0001) as A, SUM(B0001) as B FROM TABLE
UNION
SELECT '0002' as Index, SUM(A0002) as A, SUM(B0002) as B FROM TABLE
UNION
SELECT '0003' as Index, SUM(A0003) as A, SUM(B0003) as B FROM TABLE
UNION
SELECT '0004' as Index, SUM(A0004) as A, SUM(B0004) as B FROM TABLE
UNION
...
</code></pre>
<p>But this approach really doesn't look very nice either</p>
<p><strong>EDIT</strong> So far there are 2 great responses. But I would like to add two more conditions to the query :-) </p>
<p>1) I need to select the rows based on a range of timestamps (minv < timestamp < maxv). </p>
<p>2) I also need to conditionally select rows on a UDF that processes the timestamp</p>
<p>Using Brettski's table names, would the above translate to:</p>
<pre><code>...
(SELECT A0001, A0002, A0003, B0001, B0002, B0003
FROM ptest
WHERE timestamp>minv AND timestamp<maxv AND fn(timestamp)=fnv) p
unpivot
(val for item in (A0001, A0002, A0003, B0001, B0002, B0003)) as unpvt
...
</code></pre>
<p>Given that I have conditionally add the fn() requirement, I think that I also need to go down the dynamic SQL path as proposed by Jonathon. Especially as I have to build the same query for 12 different tables - all of the same style.</p>
|
<p>Same kinda answer here, that was fun:</p>
<pre><code>-- Get column names from system table
DECLARE @phCols NVARCHAR(2000)
SELECT @phCols = COALESCE(@phCols + ',[' + name + ']', '[' + name + ']')
FROM syscolumns WHERE id = (select id from sysobjects where name = 'Test' and type='U')
-- Get rid of the column we don't want
SELECT @phCols = REPLACE(@phCols, '[Timestamp],', '')
-- Query & sum using the dynamic column names
DECLARE @exec nvarchar(2000)
SELECT @exec =
'
select
SUBSTRING([Value], 2, LEN([Value]) - 1) as [Index],
SUM(CASE WHEN (LEFT([Value], 1) = ''A'') THEN Cols ELSE 0 END) as AValue,
SUM(CASE WHEN (LEFT([Value], 1) = ''B'') THEN Cols ELSE 0 END) as BValue
FROM
(
select *
from (select ' + @phCols + ' from Test) as t
unpivot (Cols FOR [Value] in (' + @phCols + ')) as p
) _temp
GROUP BY SUBSTRING([Value], 2, LEN([Value]) - 1)
'
EXECUTE(@exec)
</code></pre>
<p>You don't need to hard code column names in this one.</p>
|
<p>OK, I have come up with one solution which should get you started. It will probably take some time to put together, but will perform well. It would be nice if we didn't have to list out all the columns by name.</p>
<p>Basically this is using UNPIVOT and placing that product into a temp table, then querying it into your final data set. I named my table ptest when I put this together, this is the one with all of the A0001, etc columns.</p>
<pre><code>-- Create the temp table
CREATE TABLE #s (item nvarchar(10), val int)
-- Insert UNPIVOT product into the temp table
INSERT INTO #s (item, val)
SELECT item, val
FROM
(SELECT A0001, A0002, A0003, B0001, B0002, B0003
FROM ptest) p
unpivot
(val for item in (A0001, A0002, A0003, B0001, B0002, B0003)) as unpvt
-- Query the temp table to get final data set
SELECT RIGHT(item, 4) as item1,
Sum(CASE WHEN LEFT(item, 1) = 'A' THEN val ELSE 0 END) as A,
Sum(CASE WHEN LEFT(item, 1) = 'B' THEN val ELSE 0 END) as B
from #s
GROUP BY RIGHT(item, 4)
-- Delete temp table
drop table #s
</code></pre>
<p>By the way, thanks for the question, this was the first time I got to use UNPIVOT. Always wanted to, just never had a need.</p>
| 39,800
|
<p>Is there anyplace where one can download a virtual machine containing a working install of some Linux distro with Globus Toolkit and some development tools (Java) for testing purposes? A real deployment of a grid is more complicated but I just need something portable, for development.</p>
|
<p>I am not sure whether I understood your intentions correctly, but let's see if this one helps.</p>
<pre><code>public class TypedProperty<T> : Property where T : IConvertible
{
public T TypedValue
{
get { return (T)Convert.ChangeType(base.Value, typeof(T)); }
set { base.Value = value.ToString();}
}
}
</code></pre>
|
<pre><code>public class TypedProperty<T> : Property
{
public T TypedValue
{
get { return (T)(object)base.Value; }
set { base.Value = value.ToString();}
}
}
</code></pre>
<p>I using converting via an object. It is a little bit simpler.</p>
| 3,008
|
<p>I am facing a problem with my 3D print. Whenever I am printing any object, the print from the top is shifting to the right hand side - it is symmetric at the bottom but not at the top. </p>
<p>Checkout the photo below:</p>
<p><a href="https://i.stack.imgur.com/uocCD.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uocCD.jpg" alt="101hero print"></a></p>
|
<p>You appear to have a couple of issues here, </p>
<p>First off your nozzle appears to be a bit hot for your filament (you can see this be the drooping and sagginess of the layers on the outer shell)</p>
<p>Second issue is it appears as though your belts are loose. You can tell if your belts are loose if your parts seem to be shifted in one way. </p>
<p>Third issue (maybe). You may want to try slowing down your nozzle speed slightly. The faster the extruder moves, the more inertia that is generated which in effect makes your belt act as a spring and will cause it to bounce along the axis while it's printing. Slowing it down will result in your belt acting more like a rigid member and help to clean up the outer layers of your print. Also, it's easier on your belts. The downside is that your parts will take a bit longer to print. In my experience, parts that look great but take a bit longer are well worth the wait.</p>
|
<p>Make sure you are using cura 15.02.1, also download the configuration file from the 101hero website, and upload it to cura using the" open profile" button. Make sure your extruder temp is set to 198. I use a 113% flow rate on my 101hero.</p>
| 560
|
<p>In what areas of programming would I use state machines ? Why ? How could I implement one ?</p>
<p><strong>EDIT:</strong> please provide a practical example , if it's not too much to ask .</p>
|
<h2>In what areas of programming would I use a state machine?</h2>
<p>Use a state machine to represent a (real or logical) object that can exist in a limited number of conditions ("<em>states</em>") and progresses from one state to the next according to a fixed set of rules.</p>
<h2>Why would I use a state machine?</h2>
<p>A state machine is often a <em>very</em> compact way to represent a set of complex rules and conditions, and to process various inputs. You'll see state machines in embedded devices that have limited memory. Implemented well, a state machine is self-documenting because each logical state represents a physical condition. A state machine can be embodied in a <em>tiny</em> amount of code in comparison to its procedural equivalent and runs extremely efficiently. Moreover, the rules that govern state changes can often be stored as data in a table, providing a compact representation that can be easily maintained.</p>
<h2>How can I implement one?</h2>
<p>Trivial example:</p>
<pre><code>enum states { // Define the states in the state machine.
NO_PIZZA, // Exit state machine.
COUNT_PEOPLE, // Ask user for # of people.
COUNT_SLICES, // Ask user for # slices.
SERVE_PIZZA, // Validate and serve.
EAT_PIZZA // Task is complete.
} STATE;
STATE state = COUNT_PEOPLE;
int nPeople, nSlices, nSlicesPerPerson;
// Serve slices of pizza to people, so that each person gets
/// the same number of slices.
while (state != NO_PIZZA) {
switch (state) {
case COUNT_PEOPLE:
if (promptForPeople(&nPeople)) // If input is valid..
state = COUNT_SLICES; // .. go to next state..
break; // .. else remain in this state.
case COUNT_SLICES:
if (promptForSlices(&nSlices))
state = SERVE_PIZZA;
break;
case SERVE_PIZZA:
if (nSlices % nPeople != 0) // Can't divide the pizza evenly.
{
getMorePizzaOrFriends(); // Do something about it.
state = COUNT_PEOPLE; // Start over.
}
else
{
nSlicesPerPerson = nSlices/nPeople;
state = EAT_PIZZA;
}
break;
case EAT_PIZZA:
// etc...
state = NO_PIZZA; // Exit the state machine.
break;
} // switch
} // while
</code></pre>
<p></p>
<p><strong>Notes:</strong></p>
<ul>
<li><p>The example uses a <code>switch()</code> with explicit <code>case</code>/<code>break</code> states for simplicity. In practice, a <code>case</code> will often "fall through" to the next state.</p></li>
<li><p>For ease of maintaining a large state machine, the work done in each <code>case</code> can be encapsulated in a "worker" function. Get any input at the top of the <code>while()</code>, pass it to the worker function, and check the return value of the worker to compute the next state.</p></li>
<li><p>For compactness, the entire <code>switch()</code> can be replaced with an array of function pointers. Each state is embodied by a function whose return value is a pointer to the next state. <em>Warning:</em> This can either simplify the state machine or render it totally unmaintainable, so consider the implementation carefully!</p></li>
<li><p>An embedded device may be implemented as a state machine that exits only on a catastrophic error, after which it performs a hard reset and re-enters the state machine.</p></li>
</ul>
|
<p>State driven code is a good way to implement certain types of logic (parsers being an example). It can be done in several ways, for example:</p>
<ul>
<li><p>State driving which bit of code is actually being executed at a given point (i.e. the state is implicit in the piece of code you are writing). <a href="http://en.wikipedia.org/wiki/Recursive_descent_parser" rel="nofollow noreferrer">Recursive descent parsers</a> are a good example of this type of code.</p></li>
<li><p>State driving what to do in a conditional such as a switch statement.</p></li>
<li><p>Explicit state machines such as those generated by parser generating tools such as <a href="http://en.wikipedia.org/wiki/Lex_programming_tool" rel="nofollow noreferrer">Lex</a> and <a href="http://en.wikipedia.org/wiki/Yacc" rel="nofollow noreferrer">Yacc</a>.</p></li>
</ul>
<p>Not all state driven code is used for parsing. A general state machine generator is <a href="http://smc.sourceforge.net/" rel="nofollow noreferrer">smc</a>. It inhales a definition of a state machine (in its language) and it will spit out code for the state machine in a variety of languages.</p>
| 31,917
|
<p>How can I make Emacs show blank spaces (like a space, a tab, a line-jump, etc). Many other editors like Kate and Eclipse have this feature and I find it very useful to see when code is indent-broken because of mix of spaces and tabs (particularly Python).</p>
|
<p><a href="https://www.emacswiki.org/emacs/WhiteSpace" rel="noreferrer">WhiteSpace</a> mode is an Emacs minor mode for visualizing all white space characters in the current buffer. It can be activated with <code>M-x whitespace-mode</code>.</p>
<p>Here is a screenshot of WhiteSpace in action taken directly from the Emacs wiki,</p>
<p><a href="https://i.stack.imgur.com/M45cG.png" rel="noreferrer"><img src="https://i.stack.imgur.com/M45cG.png" alt="whitespace mode in action"></a></p>
<p>Note: WhiteSpaceMode has now replaced BlankMode</p>
|
<p>indent-broken? - never use tabs in your code - disk space is cheap these days.</p>
<p>Put <code>(setq-default indent-tabs-mode nil)</code> in your .emacs file. Get used to typing <code>C-x h M-x untabify</code> to untabify the entire buffer. To search for tabs type <code>C-s C-i</code>. If you have obscure control characters in your buffers you can see them with <code>M-x hexl-mode</code>.</p>
<p>Also <code>C-x h M-x indent-region</code> will indent the entire buffer. Some modes like vhdl-mode have a beautify region command.</p>
| 37,494
|
<p>I've always wanted to be able to get a reasonably elegant way of getting vimdiff to work with a CVS controlled file. I've found numerous (somewhat hacky) scripts around the internet (best example <a href="http://www.vim.org/tips/tip.php?tip_id=390" rel="noreferrer">here</a>) that basically check out the file you are editing from CVS to a temp file, and vimdiff the two. None of these take into account branches, and always assume you're working from MAIN, which for me is completely useless. </p>
<p>So, my question is this: has anyone out there found a decent solution for this that does more than this script?</p>
<p>Or failing that, does anyone have any ideas of how they would implement this, or suggestions for what features you would consider vital for something that does this? My intention is that, if no one can suggest an already built solution to either use or build from, we start building one from here. </p>
|
<p>I've been working on a similar script here: <a href="http://github.com/ghewgill/vim-scmdiff" rel="nofollow noreferrer">http://github.com/ghewgill/vim-scmdiff</a> (in fact, they may have the same ancestry). I haven't used scmdiff with cvs, but it should do a diff against the branch you have checked out. You can also specify that you want to diff against a particular revision (with :D <em>revision</em>). Hopefully this helps, and feel free to contribute if you've got improvements!</p>
|
<p>You could change the call to <code>cvs</code> to take branches into account. That shouldn't be to hard. It bit harder would to change the whole function and make the branch your working a variable (argument, session, global or otherwise).</p>
| 4,580
|
<h2>Repetitive Dates:</h2>
<p>Billing cycles come in a lot of different formats, for example: "the first of the month", "third Friday of the month", or "first weekday on or after 21st day after the 13th of the month" (thanks visa!). My goal is to be able to represent these different billing cycles in one easily parsed database text field. </p>
|
<p>You forgot weekend processing. If my bill is due on a Sunday, I want it to show up on Friday. That kind of thing. I think there are three possibilities:</p>
<ol>
<li>Always before the weekend</li>
<li>Always after the weekend</li>
<li>If it's Saturday, Friday, and if it's Sunday, Monday</li>
</ol>
|
<p>You forgot weekend processing. If my bill is due on a Sunday, I want it to show up on Friday. That kind of thing. I think there are three possibilities:</p>
<ol>
<li>Always before the weekend</li>
<li>Always after the weekend</li>
<li>If it's Saturday, Friday, and if it's Sunday, Monday</li>
</ol>
| 46,636
|
<p>I'm trying to handle Winsock_Connect event (Actually I need it in Excel macro) using the following code:</p>
<pre><code>Dim Winsock1 As Winsock 'Object type definition
Sub Init()
Set Winsock1 = CreateObject("MSWinsock.Winsock") 'Object initialization
Winsock1.RemoteHost = "MyHost"
Winsock1.RemotePort = "22"
Winsock1.Connect
Do While (Winsock1.State <> sckConnected)
Sleep 200
Loop
End Sub
'Callback handler
Private Sub Winsock1_Connect()
MsgBox "Winsock1::Connect"
End Sub
</code></pre>
<p>But it never goes to Winsock1_Connect subroutine although Winsock1.State is "Connected".
I want to use standard MS library because I don't have administrative rights on my PC and I'm not able to register some custom libraries.
Can anybody tell me, where I'm wrong?</p>
|
<p>Are you stuck using MSWinsock?<br>
<a href="http://www.ostrosoft.com/oswinsck/oswinsck_reference.aspx" rel="nofollow noreferrer">Here</a> is a site/tutorial using a custom winsock object.</p>
<p>Also... You need to declare Winsock1 <strong>WithEvents</strong> within a "Class" module:</p>
<pre><code>Private WithEvents Winsock1 As Winsock
</code></pre>
<p>And finally, make sure you reference the winsock ocx control.<br>
Tools -> References -> Browse -> %SYSEM%\MSWINSCK.OCX</p>
|
<p>Documentation about <strong>Winsock Control</strong>: <br/>
<a href="http://msdn.microsoft.com/en-us/library/aa228119%28v=vs.60%29.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/aa228119%28v=vs.60%29.aspx</a> <br/>
Example here: <br/>
<a href="http://support.microsoft.com/kb/163999/en-us" rel="nofollow">http://support.microsoft.com/kb/163999/en-us</a> <br/></p>
<p>My short example with event handling in VBscript:</p>
<pre class="lang-vbs prettyprint-override"><code>Dim sock
Set sock = WScript.CreateObject("MSWinsock.Winsock","sock_")
sock.RemoteHost = "www.yandex.com"
sock.RemotePort = "80"
sock.Connect
Dim received
received = 0
Sub sock_Connect()
WScript.Echo "[sock] Connection Successful!"
sock.SendData "GET / HTTP/1.1"& vbCrLf & "Host: " & sock.RemoteHost & vbCrLf & vbCrLf
End Sub
Sub sock_Close()
WScript.Echo "[sock] Connection closed!"
End Sub
Sub sock_DataArrival(Byval b)
Dim data
sock.GetData data, vbString
received = received + b
WScript.Echo "---------------------------------------"
WScript.Echo " Bytes received: " & b & " ( Total: " & received & " )"
WScript.Echo "---------------------------------------"
WScript.Echo data
End Sub
'Wait for server close connection
Do While sock.State <> 8
rem WScript.Echo sock.State
WScript.Sleep 1000
Loop
</code></pre>
<p>Output will be:</p>
<p><code>cscript /nologo sockhttp.vbs</code></p>
<pre><code>[sock] Connection Successful!
-------------------------------
Bytes received: 1376 ( Total: 1376 )
-------------------------------
HTTP/1.1 200 Ok
Date: Mon, 08 Dec 2014 15:41:36 GMT
Content-Type: text/html; charset=UTF-8
Cache-Control: no-cache,no-store,max-age=0,must-revalidate
Expires: Mon, 08 Dec 2014 15:41:36 GMT
...
</code></pre>
| 15,313
|
<p>is there a way to have a mysql select statement return fully qualified column names like "table.field" without using AS for every single field?</p>
<p>like so:</p>
<pre><code>SELECT *
FROM table1
LEFT JOIN table2 on table1.f_ID = table2.ID
</code></pre>
<p>and the result would be:
"table1.ID", "table1.name", "table2.ID", "table2.name", ...</p>
|
<p>Not really. You could write some dynamic SQL to accomplish this, but it wouldn't be simple. If you really want the dynamic SQL, let me know and I could try to whip something up.</p>
|
<pre><code>select table1.* , table1='<======'
table2.* , table2='<======'
from table1
left join table2 on table1.f_ID = table2.ID
</code></pre>
| 33,666
|
<p>This query works great:</p>
<pre><code>var pageObject = (from op in db.ObjectPermissions
join pg in db.Pages on op.ObjectPermissionName equals page.PageName
where pg.PageID == page.PageID
select op)
.SingleOrDefault();
</code></pre>
<p>I get a new type with my 'op' fields. Now I want to retrieve my 'pg' fields as well, but</p>
<pre><code>select op, pg).SingleOrDefault();
</code></pre>
<p>doesn't work.</p>
<p>How can I select everything from both tables so that they appear in my new pageObject type?</p>
|
<p>You can use anonymous types for this, i.e.:</p>
<pre><code>var pageObject = (from op in db.ObjectPermissions
join pg in db.Pages on op.ObjectPermissionName equals page.PageName
where pg.PageID == page.PageID
select new { pg, op }).SingleOrDefault();
</code></pre>
<p>This will make pageObject into an IEnumerable of an anonymous type so AFAIK you won't be able to pass it around to other methods, however if you're simply obtaining data to play with in the method you're currently in it's perfectly fine. You can also name properties in your anonymous type, i.e.:-</p>
<pre><code>var pageObject = (from op in db.ObjectPermissions
join pg in db.Pages on op.ObjectPermissionName equals page.PageName
where pg.PageID == page.PageID
select new
{
PermissionName = pg,
ObjectPermission = op
}).SingleOrDefault();
</code></pre>
<p>This will enable you to say:-</p>
<pre><code>if (pageObject.PermissionName.FooBar == "golden goose") Application.Exit();
</code></pre>
<p>For example :-)</p>
|
<p>change </p>
<pre><code>select op)
</code></pre>
<p>to</p>
<pre><code>select new { op, pg })
</code></pre>
| 5,237
|
<p>I have to write a component that re-creates SQL Server tables (structure and data) in an Oracle database. This component also has to take new data entered into the Oracle database and copy it back into SQL Server.</p>
<p>Translating the data types from SQL Server to Oracle is not a problem. However, a critical difference between Oracle and SQL Server is causing a major headache. SQL Server considers a blank string ("") to be different from a <code>NULL</code> value, so a <code>char</code> column can be defined as <code>NOT NULL</code> and yet still include blank strings in the data.</p>
<p>Oracle considers a blank string to be the same as a <code>NULL</code> value, so if a <code>char</code> column is defined as <code>NOT NULL</code>, you cannot insert a blank string. This is causing my component to break whenever a <code>NOT NULL</code> char column contains a blank string in the original SQL Server data.</p>
<p>So far my solution has been to not use <code>NOT NULL</code> in any of my mirror Oracle table definitions, but I need a more robust solution. This has to be a code solution, so the answer can't be "use so-and-so's SQL2Oracle product".</p>
<p>How would you solve this problem?</p>
<p>Edit: here is the only solution I've come up with so far, and it may help to illustrate the problem. Because Oracle doesn't allow "" in a NOT NULL column, my component could intercept any such value coming from SQL Server and replace it with "@" (just for example).</p>
<p>When I add a new record to my Oracle table, my code has to write "@" if I really want to insert a "", and when my code copies the new row back to SQL Server, it has to intercept the "@" and instead write "".</p>
<p>I'm hoping there's a more elegant way.</p>
<p>Edit 2: Is it possible that there's a simpler solution, like some setting in Oracle that gets it to treat blank strings the same as all the other major database? And would this setting also be available in Oracle Lite?</p>
|
<p>I don't see an easy solution for this. </p>
<p>Maybe you can store your values as one or more blanks <code>-> ' '</code>, which aren't NULLS in Oracle, or keep track of this special case through extra fields/tables, and an adapter layer.</p>
|
<p>I've written an explanation on how Oracle handles null values on my blog a while ago. Check it here: <a href="http://www.psinke.nl/blog/hello-world/" rel="nofollow">http://www.psinke.nl/blog/hello-world/</a> and let me know if you have any more questions.
If you have data from a source with empty values and you must convert to an Oracle database where columns are NOT NULL, there are 2 things you can do:</p>
<ul>
<li>remove the not null constraint from the Oracle column</li>
<li>Check for each individual column if it's acceptable to place a ' ' or 0 or dummy date in the column in order to be able to save your data.</li>
</ul>
| 19,444
|
<p>Suppose I have the following directory layout in a Maven project:</p>
<pre><code>src/
|-- main
| |-- bin
| | |-- run.cmd
| | `-- run.sh
| |-- etc
| | |-- common-spring.xml
| | |-- log4j.xml
| | `-- xml-spring.xml
| `-- java
| `-- com
...
</code></pre>
<p>I would like to build a zip file that, when unzipped, produces something like this:</p>
<pre><code>assembly
|-- bin
| |-- run.cmd
| `-- run.sh
|-- etc
| |-- common-spring.xml
| |-- log4j.xml
| `-- xml-spring.xml
`-- lib
|-- dependency1.jar
|-- dependency2.jar
...
</code></pre>
<p>where `run.xx' are executable shell scripts that will call my main application and <em>put all dependencies on the classpath</em>.</p>
<p>Is this possible with some of the `official' Maven plugins, e.g. maven-assembly-plugin?</p>
|
<p>I use the <a href="http://mojo.codehaus.org/appassembler/appassembler-maven-plugin/" rel="noreferrer">AppAssembler plugin</a> to get something similar. Example:</p>
<pre><code>...
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>appassembler-maven-plugin</artifactId>
<configuration>
<programs>
<program>
<mainClass>com.acme.MainClass</mainClass>
<name>app</name>
</program>
</programs>
</configuration>
</plugin>
</plugins>
</code></pre>
<p></p>
|
<p>The appassembler generates the 'run.xx' files for you.</p>
<p>If you have already created the shell scripts yourself you can use the maven-assembly-plugin to create the zip file.
To gather the dependencies you can use maven-dependency-plugin.</p>
| 35,941
|
<p>I would like to create a case or a box which has two holes for incoming and exiting water. I want the box to be opened and closed. Therefore it is good to be something like a treasure box.</p>
<p>Is there a way to design the lid of the box to prevent water from leaking around the areas where the box and the lid are meeting without using glue?</p>
<p><a href="https://i.stack.imgur.com/HYo0p.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HYo0p.png" alt="enter image description here" /></a></p>
|
<p>"Completely" is always relative, but for water at the pressures involved it's probably achievable. Normally you need some sort of <em>gasket</em> (material that can bend/compress to slight imperfections in the mating surfaces), and a means of holding the two surfaces tight against the gasket, to get such a seal.</p>
<p>With 3D printing, it's plausible that the print itself could be sufficiently non-rigid to achieve this, if you have a way of keeping the lid and box pressed tightly against each other - bolts through the lid, clips around the edges, etc. But it's unlikely to work well.</p>
<p>I would either print I suitable gasket in TPU, or cut one from some suitable material if you don't have the capability to print with TPU. Either way you still need to design your box and lid so that they're pressed tightly against the gasket.</p>
<p>One possible frame challenge would be doing a round box instead, with a circular threaded lid. It's likely that you could achieve a decent seal for your purposes without any gasket just by tightening the threads, and if not, you still have a really good setup for use with an added gasket.</p>
|
<p>I know this sounds obvious, but given the box has holes in the top – does it only need to be watertight when it's the right way up? If not, you could just do something like:</p>
<p><a href="https://i.stack.imgur.com/JXft9.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JXft9.jpg" alt="enter image description here" /></a></p>
<p>Assuming that won't work, I think a really good seal would be hard with just something like PLA, because the printing texture alone means there will always be tiny gaps between the mating surfaces. In some cases, those grooves will actually act as capillaries (if you've ever tried to use a sharpie marker on a print, you can imagine what I mean).</p>
<p>If the lid fits snugly, then just lining it with something like plumber's thread tape would probably do a good job.</p>
<p>If it needs to work straight out of the printer, then I would try something like this (obviously I've exaggerated the detail):</p>
<p><a href="https://i.stack.imgur.com/P5Fuc.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/P5Fuc.jpg" alt="enter image description here" /></a></p>
<p>The idea being something like the plastic seal you see on some types of refrigerator door, which has a thin wall with a free edge that allows it to flex.</p>
<p>NB in all these cases, sharp corners will cause problems – it will be easier to get a seal if you put a radius (say, 5mm) on the vertical edges of the box.</p>
| 1,764
|
<p>Imagine the radio of a car, does the electro magnetic fields through which the car goes through, have interference in the processing? It's easy to understand that a strong field can corrupt data. But what about the data under processment? Can it also be changed?</p>
<p>If so how could you protect your code against this? (without electrial protections just code ones)</p>
|
<p>For the most robust mission critical systems you use multiple processors and compare results. This is what we did with aircraft auto pilot (autolanding). We had three autopilots, one flying the aircraft and two check that one. If any one of the three disagreed, it was shut down.</p>
|
<p>I doubt you can.</p>
<p>Code that is changed won't run, so likely your program(s) will crash if you have this problem.</p>
<p>This is a hardware problem.</p>
| 25,525
|
<p>I have a WPF app which snaps to screen edges (I just set the .Top or .Left of the window if you're within 20 pixels of the screen edge), but I recently added some code <a href="http://blogs.msdn.com/wpfsdk/archive/2008/09/08/custom-window-chrome-in-wpf.aspx" rel="noreferrer">provided by the WPF SDK Team</a> to "mess" with the window chrome, and although it's working great (<a href="http://huddledmasses.org/images/PoshConsole/NewLook_Aero.png" rel="noreferrer">screenshot</a>), it's causing the "snapto" to move the window unexpectedly (e.g.: it jumps to the left when it should be snapping straight down to the bottom)</p>
<p>I've narrowed it down to their handling of the WM_NCCALCSIZE ... which is really odd because they basically don't do anything, they just say they handle it, and return 0. </p>
<p>According to the documentation of WM_NCCALCSIZE, this should just result in the whole window being treated as client (having no non-client edge), but somehow it also means that whenever my snap-to code moves the window down to the bottom of the screen, it also moves left about 134 pixels ... (moving to the other edges has similar side effects) and as long as I hold the mouse to drag it, it flickers back and forth from where it's supposed to be. If I comment the WM_NCCALCSIZE handling out, the snap-to works the way it should (but the form doesn't look right).</p>
<p>I've tried everything I can thing of in the WM_NCCALCSIZE handler, but I can't stop it from jumping left ... and of course, WM_NCCALCSIZE only gets called when the window size changes, so I don't understand how it causes this in the first place! </p>
<p>P.S. If you want to actually see the code, it's already <a href="http://www.codeplex.com/PoshConsole/SourceControl/DirectoryView.aspx?SourcePath=%24%2fPoshConsole%2ftrunk&changeSetId=25220" rel="noreferrer">on CodePlex</a>, in two files, look for <a href="http://www.codeplex.com/PoshConsole/SourceControl/FileView.aspx?itemId=359235&changeSetId=25220" rel="noreferrer">_HandleNCCalcSize</a> and <a href="http://www.codeplex.com/PoshConsole/SourceControl/FileView.aspx?itemId=3029&changeSetId=25220" rel="noreferrer">OnWindowLocationChanged</a></p>
|
<p>The reason this happens is that handling the <code>WM_NCCALCSIZE</code> changes the overall size of the window ... but if you're moving the window, changing your position during <code>WM_MOVE</code> or <code>WM_WINDOWPOSCHANGED</code> (which corresponds to the WPF <code>WindowPositionChanged</code> event) causes another <code>WM_NCCALCSIZE</code> message ...</p>
<p>Making changes during <code>WM_NCCALCSIZE</code> (even just asserting that you handled the message) causes another call to <code>WM_MOVE</code> ... which puts you into a loop where the "FROM" part of the positionchanged message stays the same (making the window "jump" from where it started to the position you adjust it to during <code>WM_MOVE</code> over and over as it changes back after <code>WM_NCCALCSIZE</code>).</p>
<h2>The Correct Way</h2>
<p>What you have to do is to obey Raymond Chen and <a href="https://web.archive.org/web/20080219212741/http://blogs.msdn.com/oldnewthing/archive/2008/01/16/7123299.aspx" rel="nofollow noreferrer">handle <code>WM_WINDOWPOSCHANGING</code> instead</a>. It happens <strong>before</strong> these other messages, and that way they do not interfere with each other!</p>
|
<p>The wParam always seems to be TRUE (1) and lParam is a NCCALCSIZE_PARAMS ... </p>
<p>The intent is to do exactly what you said: to force the whole window to be "client" and then use the Vista DWM apis to extend the frame into the client area. I just don't see why it's moving so far to the left...</p>
<p>If I trace or breakpoint the HandleNCCalcSize method, when I resize the window (while it's on the edge so the snap-to fires), the NCCalcSize gets called twice: once where it should be, and then off to the left, where it ends up.</p>
| 23,477
|
<pre><code><input type="submit"/>
<style>
input {
background: url(tick.png) bottom left no-repeat;
padding-left: 18px;
}
</style>
</code></pre>
<p>But the bevel goes away, how can I add an icon to submit button and keep the bevel?<br>
Edit: I want it to look like the browser default.</p>
|
<p>Using <.input type="submit" /> with a background will look different depending on what browser / OS you're on.</p>
<p>If you want to keep the browser styles, you could use the button element, which allows HTML inside the tag:</p>
<pre><code><button type="submit"><img src="image.gif" /> Text</button>
or
<button type="submit"><span class="icon"></span> Text</button>
</code></pre>
|
<p>Use border. For example:</p>
<pre><code>INPUT.button {
BORDER-RIGHT: #999999 1px solid;
BORDER-TOP: #999999 1px solid;
FONT-SIZE: 11px;
BACKGROUND: url(tick.png) bottom left no-repeat;
BORDER-LEFT: #999999 1px solid;
CURSOR: pointer;
COLOR: #333333;
BORDER-BOTTOM: #999999 1px solid
}
<input type="submit" class="button" />
</code></pre>
| 28,423
|
<p>I am writing an iPhone application and need to essentially implement something equivalent to the 'eyedropper' tool in photoshop, where you can touch a point on the image and capture the RGB values for the pixel in question to determine and match its color. Getting the UIImage is the easy part, but is there a way to convert the UIImage data into a bitmap representation in which I could extract this information for a given pixel? A working code sample would be most appreciated, and note that I am not concerned with the alpha value.</p>
|
<h2>A little more detail...</h2>
<p>I posted earlier this evening with a consolidation and small addition to what had been said on this page - that can be found at the bottom of this post. I am editing the post at this point, however, to post what I propose is (at least for my requirements, which include modifying pixel data) a better method, as it provides writable data (whereas, as I understand it, the method provided by previous posts and at the bottom of this post provides a read-only reference to data). </p>
<p>Method 1: Writable Pixel Information</p>
<ol>
<li><p>I defined constants</p>
<pre><code>#define RGBA 4
#define RGBA_8_BIT 8
</code></pre></li>
<li><p>In my UIImage subclass I declared instance variables:</p>
<pre><code>size_t bytesPerRow;
size_t byteCount;
size_t pixelCount;
CGContextRef context;
CGColorSpaceRef colorSpace;
UInt8 *pixelByteData;
// A pointer to an array of RGBA bytes in memory
RPVW_RGBAPixel *pixelData;
</code></pre></li>
<li><p>The pixel struct (with alpha in this version)</p>
<pre><code>typedef struct RGBAPixel {
byte red;
byte green;
byte blue;
byte alpha;
} RGBAPixel;
</code></pre></li>
<li><p>Bitmap function (returns pre-calculated RGBA; divide RGB by A to get unmodified RGB):</p>
<pre><code>-(RGBAPixel*) bitmap {
NSLog( @"Returning bitmap representation of UIImage." );
// 8 bits each of red, green, blue, and alpha.
[self setBytesPerRow:self.size.width * RGBA];
[self setByteCount:bytesPerRow * self.size.height];
[self setPixelCount:self.size.width * self.size.height];
// Create RGB color space
[self setColorSpace:CGColorSpaceCreateDeviceRGB()];
if (!colorSpace)
{
NSLog(@"Error allocating color space.");
return nil;
}
[self setPixelData:malloc(byteCount)];
if (!pixelData)
{
NSLog(@"Error allocating bitmap memory. Releasing color space.");
CGColorSpaceRelease(colorSpace);
return nil;
}
// Create the bitmap context.
// Pre-multiplied RGBA, 8-bits per component.
// The source image format will be converted to the format specified here by CGBitmapContextCreate.
[self setContext:CGBitmapContextCreate(
(void*)pixelData,
self.size.width,
self.size.height,
RGBA_8_BIT,
bytesPerRow,
colorSpace,
kCGImageAlphaPremultipliedLast
)];
// Make sure we have our context
if (!context) {
free(pixelData);
NSLog(@"Context not created!");
}
// Draw the image to the bitmap context.
// The memory allocated for the context for rendering will then contain the raw image pixelData in the specified color space.
CGRect rect = { { 0 , 0 }, { self.size.width, self.size.height } };
CGContextDrawImage( context, rect, self.CGImage );
// Now we can get a pointer to the image pixelData associated with the bitmap context.
pixelData = (RGBAPixel*) CGBitmapContextGetData(context);
return pixelData;
}
</code></pre></li>
</ol>
<hr>
<h2>Read-Only Data (Previous information) - method 2:</h2>
<hr>
<p>Step 1. I declared a type for byte:</p>
<pre><code> typedef unsigned char byte;
</code></pre>
<p>Step 2. I declared a struct to correspond to a pixel: </p>
<pre><code> typedef struct RGBPixel{
byte red;
byte green;
byte blue;
}
RGBPixel;
</code></pre>
<p>Step 3. I subclassed UIImageView and declared (with corresponding synthesized properties):</p>
<pre><code>// Reference to Quartz CGImage for receiver (self)
CFDataRef bitmapData;
// Buffer holding raw pixel data copied from Quartz CGImage held in receiver (self)
UInt8* pixelByteData;
// A pointer to the first pixel element in an array
RGBPixel* pixelData;
</code></pre>
<p>Step 4. Subclass code I put in a method named bitmap (to return the bitmap pixel data):</p>
<pre><code>//Get the bitmap data from the receiver's CGImage (see UIImage docs)
[self setBitmapData: CGDataProviderCopyData(CGImageGetDataProvider([self CGImage]))];
//Create a buffer to store bitmap data (unitialized memory as long as the data)
[self setPixelBitData:malloc(CFDataGetLength(bitmapData))];
//Copy image data into allocated buffer
CFDataGetBytes(bitmapData,CFRangeMake(0,CFDataGetLength(bitmapData)),pixelByteData);
//Cast a pointer to the first element of pixelByteData
//Essentially what we're doing is making a second pointer that divides the byteData's units differently - instead of dividing each unit as 1 byte we will divide each unit as 3 bytes (1 pixel).
pixelData = (RGBPixel*) pixelByteData;
//Now you can access pixels by index: pixelData[ index ]
NSLog(@"Pixel data one red (%i), green (%i), blue (%i).", pixelData[0].red, pixelData[0].green, pixelData[0].blue);
//You can determine the desired index by multiplying row * column.
return pixelData;
</code></pre>
<p>Step 5. I made an accessor method:</p>
<pre><code>-(RGBPixel*)pixelDataForRow:(int)row column:(int)column{
//Return a pointer to the pixel data
return &pixelData[row * column];
}
</code></pre>
|
<p>To do something similar in my application, I created a small off-screen CGImageContext, and then rendered the UIImage into it. This allowed me a fast way to extract a number of pixels at once. This means that you can set up the target bitmap in a format you find easy to parse, and let CoreGraphics do the hard work of converting between color models or bitmap formats.</p>
| 17,399
|
<p>I've been using WWF for a while as part of an internal call center application (ASP.NET), and while learning it was a good practice in understanding how a state machine based workflow system <em>should</em> work, I am definitely not in love with WWF itself. In my opinion it is:</p>
<ol>
<li>Overly complex, especially for use within web apps (all that threaded runtime stuff)</li>
<li>Immature (ever worked with that horrible designer?)</li>
<li>Anemic in its current feature set</li>
</ol>
<p>Does anyone have a suggestion for a better .NET based workflow framework? Specifically, I am looking for the following features:</p>
<ol>
<li>State machine based (mapping states to available actions)</li>
<li>A focus on user permissions (controlling who has access to what actions)</li>
<li>The ability to run workflows as timed background tasks (for example, to send out reminders for items that have been sitting in a certain state for x days)</li>
</ol>
<p>That's really all I need. I don't need to be able to "drag and drop" any activities or visually design the flow. I am perfectly comfortable writing actual code once a particular action is triggered.</p>
|
<p>You could try <a href="http://www.thefreakparade.com/2008/05/simplestatemachine-codeplex-project/" rel="noreferrer">Simple State Machine</a>. You would have to implement access control and background timers yourself, but that shouldn't be a big deal. SSM was also built out of frustration with WF. <a href="http://www.codeplex.com/Project/ProjectDirectory.aspx?ProjectSearchText=%22state%20machine%22" rel="noreferrer">There are some other state machine implementations on Codeplex</a> as well. If one of them doesn't fit he bill out of the box, they are open source and should get you close enough. </p>
<p>I wholeheartedly agree with you about state machines in WF - they aren't testable, are too complicated, the threading model is peculiar and hard to follow, and I'm not sure a visual designer could have been more poorly conceived for designing state machines graphically. I think this may be because the state machine concept feels tacked onto the WF runtime, which was designed for sequential state machines, something WF does a much better job with, in my opinion. The problem is that state machines are really not the same animal as a sequential work flow, and should have been given a first class implementation of their own, because the warping of WF to make it seem to support them turned out to be more or less unsupportable, if not actually unusable.</p>
|
<p>Do you have the option to consider BizTalk Server?</p>
| 3,974
|
<p>I'm looking for a open source .Net HTTP proxy library. Basically I want to develop something like Fiddler (so much lighter with less features).</p>
|
<p>I've used the Mentalis Proxy at work:
<a href="http://www.mentalis.org/soft/projects/proxy/" rel="nofollow noreferrer">http://www.mentalis.org/soft/projects/proxy/</a></p>
<p>It's not been touched for a while so there may be a few bugs.</p>
<p>Licence details are here: <a href="http://www.mentalis.org/site/license.qpx" rel="nofollow noreferrer">http://www.mentalis.org/site/license.qpx</a></p>
|
<p>There is <a href="http://urlrewriter.sourceforge.net/" rel="nofollow noreferrer">URLRewriter.NET</a>, a free open-source component for IIS/ASP.NET.</p>
<p>As the name suggests, it's an URL rewriting component, but it has <strong>also proxying capabilities</strong>. With a simple line like this in the configuration file</p>
<pre><code>RewriteRule ^(.*) http://www.testsiteXY.com$1 [P]
</code></pre>
<p>you could easily use it as proxy.</p>
| 40,101
|
<p>I am building a 3D printer from scratch, the bed will only move on Z and the head will stay at the top of the printer and move X and Y.</p>
<p>How do I modify the Marlin firmware to have the bed lower as it prints instead of lift like most printers.</p>
|
<p>You can control in Marlin what the direction of the stepper motor is, e.g. my Hypercube CoreXY printer (which has a similar setup like you described) has the following set (in the Marlin <a href="https://github.com/MarlinFirmware/Marlin/blob/2.0.x/Marlin/Configuration.h" rel="nofollow noreferrer"><code>Configuration.h</code></a> file) to ensure the platform raises when it has to decrease height:</p>
<pre><code>// Invert the stepper direction. Change (or reverse the motor connector)
// if an axis goes the wrong way.
#define INVERT_Z_DIR true
</code></pre>
<p>Furthermore, it matters where the Z endstop is located, e.g. using a bed probe sensor or a min Z endstop, you need to home towards a decreasing height (in the direction of your probe/endstop):</p>
<pre><code>// Direction of endstops when homing; 1=MAX, -1=MIN
#define Z_HOME_DIR -1
</code></pre>
<p>Don't forget to set a max Z height that falls within the printer volume, e.g.:</p>
<pre><code>#define Z_MAX_POS 345
</code></pre>
<p>If the bed is heavy, you should also prevent the steppers to lose power when not being used, so at least set Z to <code>false</code>:</p>
<pre><code>// Disables axis stepper immediately when it's not being used.
// WARNING: When motors turn off there is a chance of losing position accuracy!
#define DISABLE_Z false
</code></pre>
|
<p>To understand normal commands from a basic printer slicer, all movement commands in g-code are written to be away from the base layer as positive. Note that <em>technically</em> a "lower the bed" printer does violate Orthonormal coordinates unless you either swap X and Y while retaining 0 in the front-left corner or put 0 in the front-right corner, going left for +X (e.g. inverting that motor axis too) and back for -Y.</p>
<h1>Hardware</h1>
<p>To <em>invert</em> the movement direction of an axis without rewriting the firmware there are two main ways, from mos invasive to easiest:</p>
<ul>
<li>Mount the actuator "upside-down" as that flips the rotational normal vector.</li>
<li>use a left-hand-threaded rod and nut. This does not flip rotation but how rotation affects the bed.</li>
<li>alter the stepper cables by "crossing" one of the phases leads. The motor rotates reversed to its commands now.</li>
</ul>
<p><a href="https://i.stack.imgur.com/miZU6.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/miZU6.jpg" alt="enter image description here" /></a></p>
<h1>Firmware</h1>
<p>In Marlin, you can also just flip the direction of the motor via <code>configuration.h</code> by altering the line from <code>false</code> to <code>true</code>:</p>
<pre><code>#define INVERT_Z_DIR true
</code></pre>
| 1,886
|
<p>I'm a student about to start my exam project, where I will be responsible for the server implementation of an online game targeting the flash player.
I have a hard time to decide wether i should write my own lightweight server in Erlang or use the open source Red5. </p>
<p>My experience is that java-developers tend to overcomplexify things making the APIs difficult to work with, is this true for Red5? And how does it perform under the heavy load that comes with synchronizing a game?</p>
<p>Maybe my own Erlang server will be easier to work with and distribute on several machines?</p>
<p>So the question is should i write my own Erlang flash server or use the existing Red5?</p>
<p>Edit: I think i need to decide what my goals are: to just set up an online game or learn how to implement a multiuser server from scratch.</p>
|
<p>I'd say use Red5 if you are ok with programming java - it might feel trivial to implement your own server but I'd guess you probably will find out that there are some more things to it than you are thinking of now.</p>
<p>However, if you want to program in erlang and think you'll have loads of fun developing your own server by all means go for it!</p>
<p>Is also depends on the goal of your project - do you have to demonstrate you can get an online game going (go for Red5), or do you have to demonstrate you can program a distributed multiuser game server? (go for your own project progammed in Erlang)</p>
<p>BTW: I'm using <a href="http://www.smartfoxserver.com/" rel="nofollow noreferrer">http://www.smartfoxserver.com/</a> for one of my current projects</p>
|
<p>If you go to <a href="http://www.stripclubcity.com/" rel="nofollow noreferrer">http://www.stripclubcity.com/</a> or more specifically <a href="http://www.stripclubcity.com/new-jersey-strip-clubs" rel="nofollow noreferrer">http://www.stripclubcity.com/new-jersey-strip-clubs</a> they are using Red5 to stream their cams. I think I read that it's so much easier to use Red5 than it is to write your own AMF... Why reinvent the wheel?</p>
| 48,971
|
<p>Can ANTLR output C# using StringTemplate or any text I want it to like Yacc/Bison or does it only output to java? From the examples I've looked at it appears to be a very java centric tool.</p>
|
<p>The ANTLR IDE has option by which you can switch between Java and C# code generation.</p>
<p>Better, consult this article (the Specifying Code Generation section):</p>
<p><a href="http://www.antlr2.org/doc/csharp-runtime.html" rel="nofollow noreferrer">http://www.antlr2.org/doc/csharp-runtime.html</a></p>
|
<p>You can download the latest source code as a tar file from <a href="http://antlr.org/download/antlr-3.0.1.tar.gz" rel="nofollow noreferrer">here</a>. The C# runtime (binary) is also available directly, <a href="http://antlr.org/download/DOT-NET-runtime.zip" rel="nofollow noreferrer">here</a>.</p>
<p>Which solution are you looking for?</p>
| 9,204
|
<p><strong>UPDATE</strong> - A comprehensive comparison, updated as of February 2015, can be found here:</p>
<h1><a href="https://stackoverflow.com/questions/200284/what-are-alternatives-to-extjs/2144878#2144878">Alternatives to Ext JS</a></h1>
<hr />
<p><em>2008 question</em>:</p>
<p>There are a number of great and not so-great Javascript GUI frameworks out there. I've looked at some (only superficially). And I can't make my mind about any of them</p>
<p><strong>Scroll to the end of this question to see what others say</strong></p>
<ul>
<li><p><a href="http://www.sencha.com/" rel="noreferrer">Ext.js</a> The obvious choice by many since it's one of the most known frameworks.<br />
<em>Advantages:</em> Looks <a href="http://extjs.com/products/extjs/" rel="noreferrer">awesome</a>, large community, lots of extensions/plugins, GPL'ed<br />
<em>Disadvanatges:</em> Inability to use third-party extensions with commercial license (and some of those extensions have killer features)</p>
</li>
<li><p><a href="http://backbase.com/" rel="noreferrer">Backbase</a> Relatively less known. A curious mix of XML and Javascript that is reminiscent of XUL. However, it's already cross-browser<br />
<em>Advantages:</em> Looks <a href="http://demo.backbase.com/explorer/index.html#%7Cexamples/welcome.xml" rel="noreferrer">good</a>, very extensible, allows easy incorporation of <a href="http://bdn.backbase.com/blog/rus/advanced-3d-animations-and-transitions" rel="noreferrer">some really neat stuff</a><br />
<em>Disadvantages:</em> Pricing is steep and CPU-bound (though free to use on up to 2 CPUs), forums are slow to respond (though commercial support is supposedly fast)</p>
</li>
<li><p><a href="http://qooxdoo.org/" rel="noreferrer">qooxdoo</a> Also very popular.<br />
<em>Advantages:</em> <em>Please, fill in</em><br />
<em>Disadvantages:</em> Code is slighly messy (based on hearsay)</p>
</li>
<li><p><a href="http://developer.yahoo.com/yui" rel="noreferrer">YUI</a> <em>Fill in description</em><br />
<em>Advantages:</em> Well organized code
<em>Disadvantages:</em> <em>Many widgets still in beta</em></p>
</li>
<li><p><a href="http://dojotoolkit.org/" rel="noreferrer">Dojo</a> <em>Fill in description</em><br />
<em>Advantages:</em> Incremental loading of classes<br />
<em>Disadvantages:</em> MIght feel bloated</p>
</li>
<li><p><a href="http://ui.jquery.com/" rel="noreferrer">jQuery UI</a><br />
<em>Advantages:</em> Widgets not dependent on each other<br />
<em>Disadvantages:</em> In an early stage of development, very few widgets<br />
<em>Possible tendency towards wider acception:</em> jQuery to be shipped with ASP.NET MVC</p>
</li>
</ul>
<hr />
<p>What say you? What do you use and why? What would you rather use and why? In any kind of project</p>
<hr />
<p>To be updated with your input...</p>
<blockquote>
<p>See this <a href="https://stackoverflow.com/questions/218699/your-choice-of-cross-browser-javascript-gui#218764">excellent comment</a> from Sergey Ilinsky which explains very nicely which framework you should choose when you want to just pimp up your page, build an application with a rich frontend (with several choices, no less)</p>
<p>An interesting comment in another thread compares jQuery, Dojo, Prototype, Mootools, <a href="http://www.sproutcore.com/" rel="noreferrer">Sproutcore</a> and <a href="http://cappuccino.org/" rel="noreferrer">Cappuccino</a> <em>(the question was removed)</em>.</p>
</blockquote>
|
<p>When considering a JavaScript library/framework for usage you should first define on your goals. I used to separate all JavaScript libraries/frameworks into three categories by their purpose and architecture:</p>
<ol>
<li><p>I want to <strong>pimp up my page</strong> with some really "cool" features. Go for <em>JavaScript library</em>.</p>
<ul>
<li>jQuery</li>
<li>ZenoUI</li>
<li>old: Prototype, Mootools</li>
</ul></li>
<li><p>I want to <strong>build an application</strong> with a rich front-end. I like defining UI with JavaScript and I do not mind much using custom APIs of these libraries for coding my application logic. Go for JavaScript <em>post-library/pre-framework</em>.</p>
<ul>
<li><a href="/questions/tagged/extjs" class="post-tag" title="show questions tagged 'extjs'" rel="tag">extjs</a></li>
<li><a href="/questions/tagged/kendo" class="post-tag" title="show questions tagged 'kendo'" rel="tag">kendo</a></li>
<li>DHTMLX</li>
<li>Dojo</li>
<li>YUI</li>
<li>Qooxdoo</li>
<li>jQuery UI</li>
<li><a href="http://www.bindows.net/" rel="nofollow noreferrer">Bindows</a> - generates the exact look of Windows</li>
<li>Spry (raw, suffers severely of memory leaks)</li>
</ul></li>
<li><p>I want to <strong>build an application</strong> with a rich front-end. I like defining UI in XML and I would like to code my application logic against standard APIs and make use of other developer-facing standard-based technologies. Go for <em>JavaScript framework</em>.</p>
<ul>
<li><a href="http://sproutcore.com/about/" rel="nofollow noreferrer">Sproutcore</a></li>
<li>Backbase</li>
<li>Ample SDK</li>
</ul></li>
</ol>
<h3>For a more detailed comparison, see the <a href="https://stackoverflow.com/a/2144878/1269037">alternatives to ExtJS</a>.</h3>
|
<p><a href="http://rialto.improve-technologies.com" rel="nofollow noreferrer">Rialto</a> (Rich Internet Application Toolkit) is ajax-based cross browser javascript widgets library. Because it is technology agnostic it can be encapsulated in JSP, JSF, .Net, Python or PHP graphic components. The purpose of Rialto is to ease the access to rich internet application development to corporate developers. Ideally a Rialto developer have neither need to write or understand DHTML, Ajax or DOM code.</p>
<p>The target of Rialto is corporate web applications and not internet web sites. </p>
| 26,910
|
<blockquote>
<p><strong>Possible Duplicate:</strong><br>
<a href="https://stackoverflow.com/questions/65820/unit-testing-c-code">Unit Testing C Code</a> </p>
</blockquote>
<p>I've seen a few questions specific to C++, but I'm really curious about C. I'm trying to add a standard unit test framework into our build environment. My primary goals are to encourage our developers to write unit tests, and to standardize those test so others can run them. Ideally I'd like to run the unit tests as part of our nightly build.</p>
<p>We started some work with CUnit, which worked except that everything ran in one thread and any memory faults caused the unit tests to stop running, which was rather annoying. I also found it incredibly difficult to write the tests, but that might just be unit testing for you.</p>
<p>Does anybody know of good alternatives? Has anybody had any experience with the C++ Unit Testers with C-only code?</p>
|
<p>I write embedded software using C and I decided to write my own framework. It's very simple and written for MS Visual Studio. It's easily ported to other platforms. </p>
<p><a href="http://code.google.com/p/cunitwin32/" rel="nofollow noreferrer">http://code.google.com/p/cunitwin32/</a></p>
<p>If you're targeting linux I think Check might suite your needs.</p>
|
<blockquote>
<p>We started some work with CUnit, which worked except that everything ran in one thread and any memory faults caused the unit tests to stop running, which was rather annoying. </p>
</blockquote>
<p>There one C unit testing framework that forks and executes each test cases in a separate process so that all the tests are executed even in the presence of tests that core dump :
<a href="http://sourceforge.net/projects/check/" rel="nofollow noreferrer">Check</a> </p>
<p>However, I'm afraid of the performance penalty all these forks bring (and to be honest, I didn't give it a try). But I won't live long with any single test core dumping : I usually fix it immediately. </p>
<p>One trick to prevent the unit tests to core is the <strong><a href="http://xunitpatterns.com/Guard%20Assertion.html" rel="nofollow noreferrer">assertion guard</a></strong>, for instance: use an assertion to prevent using a NULL pointer (example with <a href="http://www.jera.com/techinfo/jtns/jtn002.html" rel="nofollow noreferrer">minunit</a>). </p>
<pre><code>void test_function_returning_a_pointer(void)
{
struct_t *theStruct = function_returning_a_pointer();
MU_ASSERT(theStruct != NULL);
//--- now you can use the pointer
MU_ASSERT(theStruct->field1 == 0);
return MU_PASSED;
}
</code></pre>
<p>By the way, I'm not aware of any C++ unit test framework that won't crash in case of segmentation violation.</p>
<blockquote>
<p>I also found it incredibly difficult to write the tests, but that might just be unit testing for you.</p>
</blockquote>
<p>Could you elaborate on your difficulties ? Are you trying to put legacy code under tests ?</p>
| 21,351
|
<p>I'm making a simple extra java app launcher for Eclipse 3.2 (JBuilder 2007-8) for internal use.</p>
<p>So I looked up all the documentations related, including this one <a href="http://www.eclipse.org/articles/Article-Launch-Framework/launch.html" rel="nofollow noreferrer" title="The Launching Framework">The Launching Framework from eclipse.org</a> and have managed to make everything else working with the exception of the launch shortcut. </p>
<p><img src="https://i.stack.imgur.com/8I8zw.jpg" alt="alt text"></p>
<p>This is the part of my plugin.xml. </p>
<pre><code> <extension
point="org.eclipse.debug.ui.launchShortcuts">
<shortcut
category="mycompany.javalaunchext.launchConfig"
class="mycompany.javalaunchext.LaunchShortcut"
description="launchshortcutsdescription"
icon="icons/k2mountain.png"
id="mycompany.javalaunchext.launchShortcut"
label="Java Application Ext."
modes="run, debug">
<perspective
id="org.eclipse.jdt.ui.JavaPerspective">
</perspective>
<perspective
id="org.eclipse.jdt.ui.JavaHierarchyPerspective">
</perspective>
<perspective
id="org.eclipse.jdt.ui.JavaBrowsingPerspective">
</perspective>
<perspective
id="org.eclipse.debug.ui.DebugPerspective">
</perspective>
</shortcut>
</code></pre>
<p></p>
<p>The configuration name in the category section is correct and the class in the class section, i believe, is correctly implemented. (basically copied from org.eclipse.jdt.debug.ui.launchConfigurations.JavaApplicationLaunchShortcut)</p>
<hr>
<p>I'm really not sure if I'm supposed to write a follow-up here but let me clarify my question more.
I've extended org.eclipse.jdt.debug.ui.launchConfigurations.JavaLaunchShortcut.
Plus, I've added my own logger to constructors and methods, but the class seems like it's never even instantiating.</p>
|
<p>I had to add <code>contextualLaunch</code> under <code>org.eclipse.debug.ui.launchShortcuts</code>.</p>
<p>The old way seems like it's deprecated a long ago.</p>
<p>For other people who are working on the same subject,
you might want to extend <code>org.eclipse.ui.commands</code> and bindings, too.</p>
<p>I cannot choose this answer but this is the answer that I (the questioner) was looking for.</p>
|
<p>You class should implement ILaunchShortcut.
Check out the <a href="http://help.eclipse.org/help32/nftopic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/debug/ui/ILaunchShortcut.html" rel="nofollow noreferrer">Javadoc</a>. </p>
<p>What exception are you getting? Check the error log.</p>
| 4,573
|
<p>This is my code:</p>
<pre class="lang-hs prettyprint-override"><code>type HoraAtendimento = (String, Int, Int)
htmlHAtendimento :: [HoraAtendimento] -> Html
htmlHAtendimento [] = toHtml ""
htmlHAtendimento ((da,hia,hfa):[]) = toHtml da +++ "feira "
+++
show hia +++ "h - " +++ show hfa +++ "h"
htmlHAtendimento ((da,hia,hfa):r) = toHtml da +++ "feira "
+++
show hia +++ "h - " +++ show hfa +++ "h, "
+++
htmlHAtendimento r
</code></pre>
<p>I'm looking for a way to use the map function and get rid of this recursive function. Is that possible and if so, how do I do it?</p>
|
<p>Look at the type of <code>map</code>. It is <code>(a -> b) -> [a] -> [b]</code>. That doesn't look like your type, which is [a] -> b. That's not a map, that's a fold.</p>
<p>The higher-order function you want to look at is <code>foldr</code>. See <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v%3Afoldr" rel="noreferrer">Hoogle</a>.</p>
<p>Something like...</p>
<pre><code>htmlHAtendimento :: [HoraAtendimento] -> Html
htmlHAtendimento [] = toHtml ""
htmlHAtendimento l = foldr1 (+++) $ intersperse ", " $ map f l
where f (da, hia, hfa) = toHtml da
+++ "feira "
+++ show hia
+++ "h - "
+++ show hfa
+++ "h"
</code></pre>
<p>I don't know if that's correct, but that's in the right direction.</p>
|
<p>You want to fold over a nonempty list. This code might do the trick:</p>
<pre><code>type HoraAtendimento = (String, Int, Int)
htmlHAtendimento :: [HoraAtendimento] -> Html
htmlHAtendimento [] = toHtml ""
htmlHAtendimento l = foldl1 (+++) $ map convert l
where convert (da,hia,hfa) = toHtml da +++ "feira " +++
show hia +++ "h - " +++ show hfa +++ "h"
</code></pre>
| 49,334
|
<p>This is an extension of my <a href="https://stackoverflow.com/questions/205923">earlier XSS question</a>.</p>
<p>Assuming that there isn't a Regex strong enough to guarantee XSS saftey for user entered URLs I'm looking at using a redirect.</p>
<p>(Although if you do have one please add it under the other question)</p>
<p>We have user input web addresses, so:</p>
<blockquote>
<p>stackoverflow.com</p>
</blockquote>
<p>They want a link to appear for other users, so:</p>
<pre><code><a href="http://stackoverflow.com">stackoverflow.com</a>
</code></pre>
<p>To reduce the risk of hacking I'm planning to use a warning page, so the link becomes:</p>
<pre><code><a href="leavingSite.aspx?linkid=1234" target="_blank">stackoverflow.com</a>
</code></pre>
<p>Then on that page there will be a warning message and a plain link to the original link:</p>
<pre><code><a href="javascript:alert('oh noes! xss!');">Following this link at your own risk!</a>
</code></pre>
<p>As we use a lot of Ajax I want to make that leaving-site page a walled garden of sorts, ideally by essentially logging the user out in that page only. I want them to stay logged in on the original page.</p>
<p>Then if someone does get past the santisation Regex they can't access anything as the duped user.</p>
<p>Anyone know how to do this? Is it possible to log out one window/tab without logging them all out? We support IE & FX, but ideally a solution would work in Opera/Chrome/Safari too.</p>
|
<p>It's not possible to log someone out in just one tab / window.</p>
|
<p>restrict cookies to www.example.com and have the forwarding page at links.example.com</p>
| 26,049
|
<p>I am building an application where most of the HTML is built using javascript. The DOM structure is built using some JSON data structures that are sent from the server, and then the client-side code builds a UI for that data. </p>
<p>My current approach is to walk the JSON data structures, and call script.aculo.us's Builder.node method to build the DOM structure, and then append it to some element that is actually in the HTML sent from the server. Along the way, I am registering event listeners to the various elements that need them. This allows for a good amount of flexibility, and allows for a very dynamic interface.</p>
<p>However, I feel that it is not very sustainable, since the view logic (ie, the DOM structure) is so tightly coupled to the code that walks the data, and the event handlers, and the data that is kept in memory to maintain the state, and is able to communicate those changes back to the server.</p>
<p>Are there any template-like solutions that will allow me to divorce the DOM structure from the code that drives the app? Currently, my only library dependencies are prototype.js and script.aculo.us, so I would like to avoid introducing any large libraries, but any suggestions are welcome.</p>
<p>Thanks!</p>
<p>EDIT: For some reason, <a href="https://stackoverflow.com/questions/128949/what-good-template-language-is-supported-in-javascript">What good template language is supported in Javascript?</a> didn't show up in the little search results when I was typing this question. It does, however, show up in the "Related" sidebar here.</p>
<p>I will read through some of the suggestions there, and if I find a solution, I will close this question. Otherwise, I will clarify this question with reasons why those solutions won't work for me.</p>
|
<p>There are some template solutions out there, but they aren't doing much more than you're doing already. jQuery has been doing some <a href="http://ejohn.org/blog/javascript-micro-templating/" rel="nofollow noreferrer"><strong>work along these lines</strong></a>, and some jQuery <a href="http://plugins.jquery.com/project/jTemplates" rel="nofollow noreferrer"><strong>plugins</strong></a> have emerged as solutions. Prototype.js and others have solutions as well.</p>
<p><strong>Some options include:</strong></p>
<ul>
<li><a href="http://www.prototypejs.org/api/template" rel="nofollow noreferrer"><strong>Prototype Templates</strong></a></li>
<li><a href="http://ajax-pages.sourceforge.net/" rel="nofollow noreferrer"><strong>Ajax Pages</strong></a></li>
</ul>
<p>In general, <a href="http://extjs.com/" rel="nofollow noreferrer"><strong>Ext js</strong></a> has some pretty <strong>wild and tricked out</strong> stuff, including some <a href="http://extjs.com/deploy/dev/examples/core/templates.html" rel="nofollow noreferrer"><strong>templates</strong></a>, but you'd be adding <strong>yet another library</strong>. So many libraries are getting tossed around these days, and it's often so much simpler to implement a <strong>light and simple</strong> custom solution. Try creating some DOM objects on your own. If you've got JSON data, parse it into memory and run it through a function. It's actually a blast, and a lot of people are doing it.</p>
<p><strong>Sidenote:</strong>
What you're doing may be quite <strong>sustainable</strong> and <strong>maintainable</strong>. Keep in mind that when you send a page of HTML, the browser is putting a <strong>DOM structure into memory</strong> in roughly the same way that your javascript does. I don't particularly recommend any of these solutions. It sounds like you've made a nice little system for your specific needs, and I'd generally say that <strong>refining your design</strong> will be at least as valuable as moving to somebody else's pattern, with the added benefit of being able to <strong>create some of your own dependencies</strong>.</p>
<p><strong>Sidenote:</strong>
It's <strong>generally</strong> not advisable to <strong>generate the entire DOM</strong> on the client, at least not for many markets. Sometimes it's an A-OK solution, as it may be in your case, but it's worth a note of caution to the audience at large that this style of development is not always the best road to travel.</p>
|
<p>You can have a look to soma-template, the syntax is quite lightweight.</p>
<p>Pure DOM manipulation, a lot of features, natural syntax, fully extensible with other libraries such as underscore.string, function calls with parameters, helpers, watchers. Capability to update only some nodes if needed, templates inside the DOM itself.</p>
<p><a href="http://soundstep.github.com/soma-template/" rel="nofollow">http://soundstep.github.com/soma-template/</a></p>
| 24,728
|
<p>What's the best available online resource.</p>
|
<p>I have only played with the Mobile Framework briefly but a good start would be <a href="http://msdn.microsoft.com/en-us/windowsmobile/default.aspx" rel="nofollow noreferrer">Windows Mobile Developer Center</a></p>
<p>Also it is worth looking at some example open source projects on <a href="http://www.codeplex.com/Project/ProjectDirectory.aspx?TagName=windows%20mobile" rel="nofollow noreferrer">CodePlex</a>.
Microsoft on every training event is encouraging people to use it, and from my experience you can find some interesting projects there at least in standard .Net. I suppose the same applies to Mobile</p>
|
<p>I've just got a new smart phone, (WinMo 6 Pro) and looking at developing for it. Unfortunately there really seems a lack of clear concise guides/documentation/tutorials/books for native Window Mobile development.</p>
<p>Currently the best resource I've found is MSDN, pity it I find it so painful to trawl through.</p>
<p>I can now see why Palm had such an active Dev community, good references, some free tools and simple code/APIs.</p>
| 20,055
|
<p>I am currently using the following command to upload my site content:</p>
<pre><code>scp -r web/* user@site.com:site.com/
</code></pre>
<p>This works great except that the .htaccess file is not sent. Presumably, this is because it's hidden.</p>
<p>I have tried adding a second line to send the file explicitely:</p>
<pre><code>scp -r web/.htaccess user@site.com:site.com/.htaccess
</code></pre>
<p>This works great except now I have to enter my password twice.</p>
<p>Any thoughts on how to make this deploy with only 1 or 0 entries of my password?</p>
|
<p>Just combine the two commands:</p>
<pre><code>scp -r web/* web/.htaccess user@site.com:site.com/
</code></pre>
<p>If you want 0 entries of your password you can set up <a href="http://sial.org/howto/openssh/publickey-auth/" rel="noreferrer">public key authentication</a> for ssh/scp.</p>
|
<p>A word of caution - don't attempt to match dotted files (like <code>.htaccess</code>) with <code>.*</code> - this inconveniently also matches <code>..</code>, and would result in copying all the files on the path to the root directory. I did this once (with <code>rm</code>, no less!) and I had to rebuild the server because I'd messed with <code>/var</code>.</p>
<p>@jwmittag:</p>
<p>I just did a test on Ubuntu and <code>.*</code> matches when I use <code>cp</code>. Here's an example:</p>
<pre><code>root@krash:/# mkdir a
root@krash:/# mkdir b
root@krash:/# mkdir a/c
root@krash:/# touch a/d
root@krash:/# touch a/c/e
root@krash:/# cp -r a/c/.* b
cp: will not create hard link `b/c' to directory `b/.'
root@krash:/# ls b
d e
</code></pre>
<p>If <code>.*</code> did not match <code>..</code>, then <code>d</code> shouldn't be in <code>b</code>.</p>
| 5,389
|
<p>I'm working on a project using 3D printed parts, everything is working very nicely except for one part that needs a 3 mm x 1.2 mm diameter rod. I can print with PLA/PLA+ but such a thin object doesn't seem viable for 3D printing. Is it still possible or am I better off using a 1.2 mm metal dowel?</p>
<p>The bigger part (5 mm x 7 mm diameter) near the back isn't an issue, it's the small rod that I can't seem to print correctly</p>
<p><a href="https://i.stack.imgur.com/JGkft.png" rel="nofollow noreferrer" title="Part"><img src="https://i.stack.imgur.com/JGkft.png" alt="Part" title="Part" /></a></p>
|
<p>It would be impossible to print this standing with the rod straight up, and even if you got it to print the part would be very weak due to the thin cross-section of the rod aligning with the layers.</p>
<p>The only way to print this part and get a usable result is to print it in the orientation shown in the picture, with the rod part being horizontal. Because the layers will now have a much larger cross-sectional area, this not only makes the print much stronger but also prevents issues with the plastic not cooling off sufficiently between layers. Though this will still be a tricky print, because now you'll need lots of support material.</p>
<p>Using a metal rod is probably the better option. Another option is printing the rod lying flat on the bed, and gluing it in place later. This would avoid the issue with support material.</p>
|
<p>If you insist on printing it entirely, I would suggest cutting the model in two halves through the centerline, printing them flat and gluing both parts together after printing. This will make sure the axial direction of the rod is in the XY plane, and doesn't require support.</p>
<p>However, the beauty of 3D printing is that it can be easily combined with other materials and techniques. In this case, you are far better off by printing the big cylinder with a hole in it and glueing a metal rod in. It is less trouble, stronger and possibly more functional since it will have a much better surface finish.</p>
| 2,098
|
<p>As much as i like the eclipse diff/merge perspective, when dealing with large projects and multiple branches that need to be merged occasionally there's one feature missing:</p>
<p>Is there any way to set the eclipse diff to ignore the CVS tags like <em>$Author:$</em>, <em>$Revision:$</em> and so on?</p>
<p>Since these tags are different in all the branches, a "compare to another branch" always results in a few hundred files showing up with differing tags but no apparent differences in the code. (of course tags differ only after fixing a bug in a few hundred files in branch and head. but that happens a lot where i'm working. no comments on that please.)</p>
|
<p>This seems to be a <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=36436" rel="noreferrer">known bug</a>.</p>
|
<p>On the other hand, using keyword expansion with your SCM might be considered outdated procedure. <a href="http://wordaligned.org/articles/keyword-substitution-just-say-no" rel="nofollow noreferrer">here</a> are some compelling arguments.</p>
| 26,845
|
<p>I'm thinking about using BlogEngine.NET to launch my blog. I'm a C# programmer and was wondering was BlogEngine.NET has in the belly.</p>
<p>Does it scale well? Is it caching properly? Is it memory intensive? Can you easily add/remove functionality?</p>
<p>I also accept any hosting recommendation :)</p>
|
<p>I'm running BlogEngine.Net. I don't know about scaling because my weblog isn't that popular (yet). I'm very happy with it.
I tried subtext before and I had some stability problems with it, it logged exceptions that I found hard to debug. I got an error exporting the database to BlogML and it messed up the order of my blogposts. BlogEngine.Net seems a lot more stable.</p>
<p>I'm running on a virtualized server hosted by a friend of mine. I have seen no performance issues but that might be because of the massive 15 visitors per day peak load. I've have some trouble where Live Writer posts blog entries twice, but I suspect this is Live Writer's fault.</p>
<p>I really like the extension model and the way you can drag and drop extensions on the design of your blog. There aren't much themes that support this yet but I created my own look and feel by changing the standard theme in about three hours.</p>
|
<p>It runs well for us. I did see very rare situations where memory skyrocketed when we were getting a DDOS (appeared to be some kind of a memory leak) but in general, it works fine. We don't run the most popular blog, but we did get good amounts of traffic for some of our posts. </p>
<p>We wrote our own plugin for our purposes, as well. </p>
<p>(<a href="http://blog.lavablast.com" rel="nofollow noreferrer">http://blog.lavablast.com</a>) </p>
| 27,323
|
<p>My wife wants me to use an FFM 3d printer to make custom stamps for her to use on paper (scrap books, letters, etc.). She is convinced, however, that they will be too rigid to make good stamps. A quick google search showed ones made from <a href="https://3dprint.com/110918/3d-printed-stamp-collection/" rel="noreferrer">PLA</a> and <a href="http://www.thingiverse.com/thing:3669" rel="noreferrer">ABS</a>. Logically, though, a TPU or similar would address her concerns. A good quality stamp needs to hold ink and make good, even contact with the paper. It would probably need to be able to be sanded or smoothed in some way.</p>
<p>I am supposed to receive my printer next week or so and am trying to get some filaments, STL files, and accessories I will need ready in advance so I can rapidly learn how to use it.</p>
|
<p>I see three options...</p>
<p><strong>1. Print with a flexible filament:</strong></p>
<ul>
<li>Many options: TPU as you pointed out, the flexible PLA that Tom mentioned, and others. Here's an article with a few options from <a href="https://3dprintingindustry.com/news/which-flexible-3d-printing-filament-should-you-choose-61961/" rel="noreferrer">Matter Hackers</a></li>
<li>I'd suggest printing the stamp side down so you get a nice flat stamp with no post processing. For any wide gaps, mind your bridging...use fillets or chamfers so the "roof" of the gap is an upside down V or U shape.</li>
</ul>
<p><strong>2. Print with any hard filament, but use a rubber mat under the paper.</strong></p>
<ul>
<li>The idea here is to use a semi-flexible surface under the paper to help get uniform contact pressure between the paper and the hard stamp. As long as your stamp holds ink, this should work okay.</li>
</ul>
<p><strong>3. Print your stamp shape, then use it to make a rubber stamp.</strong></p>
<ul>
<li>Making a model and then copying it with your desired non-printable material is a common manufacturing technique that can be used in many situations. Use of molds for casting and related processes can really expand your possibilities. Check out <a href="https://www.smooth-on.com/" rel="noreferrer">Smooth On</a>. They have several rubber and flexible compounds that you could use for stamps.</li>
</ul>
|
<p>Recently I've experimented with printing some <a href="http://rads.stackoverflow.com/amzn/click/B00TOOBPNO" rel="nofollow">Nylon 618 filament</a> after <a href="http://www.matterhackers.com/articles/printing-with-nylon" rel="nofollow">reading stuff online</a> about it. I'm using a Craftbot original with the stock hotend, keeping the Nylon dry in a ziploc bag. It prints really well, just tricky to get it to stick to the bed (I'm still working on that), but otherwise it's great.</p>
<p>Once printed, the main difference from PLA prints is the nylon remains more flexible. If you bend a thin nylon print, it tends to just spring back to the shape that came off the printer. That's very different from my PLA prints, which will either stay bent or break apart.</p>
<p>I believe that nylon would be a good material for you to try for stamps, because of this flexibility and shape-preserving quality. The comments show some other materials to try, but I'm limiting my answer here to my own personal experience.</p>
| 389
|
<p>In JavaScript, you can use <a href="http://peter.michaux.ca/article/3556" rel="noreferrer">Lazy Function Definitions</a> to optimize the 2nd - Nth call to a function by performing the <strong>expensive</strong> one-time operations only on the first call to the function.</p>
<p>I'd like to do the same sort of thing in PHP 5, but redefining a function is not allowed, nor is overloading a function.</p>
<p>Effectively what I'd like to do is like the following, only optimized so the 2nd - Nth calls (say 25-100) don't need to re-check if they are the first call.</p>
<pre><code>$called = false;
function foo($param_1){
global $called;
if($called == false){
doExpensiveStuff($param_1);
$called = true;
}
echo '<b>'.$param_1.'</b>';
}
</code></pre>
<p>PS I've thought about using an include_once() or require_once() as the first line in the function to execute the external code just once, but I've heard that these too are expensive.</p>
<p>Any Ideas? or is there a better way to tackle this?</p>
|
<p>Use a local static var:</p>
<pre><code>function foo() {
static $called = false;
if ($called == false) {
$called = true;
expensive_stuff();
}
}
</code></pre>
<p>Avoid using a global for this. It clutters the global namespace and makes the function less encapsulated. If other places besides the innards of the function need to know if it's been called, then it'd be worth it to put this function inside a class like Alan Storm indicated.</p>
|
<p>If you do wind up finding that an extra boolean test is going to be too expensive, you can set a variable to the name of a function and call it:</p>
<pre><code>$func = "foo";
function foo()
{
global $func;
$func = "bar";
echo "expensive stuff";
};
function bar()
{
echo "do nothing, i guess";
};
for($i=0; $i<5; $i++)
{
$func();
}
</code></pre>
<p>Give that a shot</p>
| 14,453
|
<p>Is there a preferred way to handle animation when using Flex -- For instance, if I want to render a ball and bounce it around the screen?</p>
|
<p>I prefer to use a tweening library for things like this. Check these out:</p>
<p><a href="http://www.google.com/url?sa=t&source=web&ct=res&cd=1&url=http%3A%2F%2Fcode.google.com%2Fp%2Ftweener%2F&ei=X4nOSIPJAaioesqPveAI&usg=AFQjCNH06RZesH0SEvPCYbJ-J0OMFd7GGQ&sig2=Ki_WXXUX1aHzahMMMSctIw" rel="nofollow noreferrer">Tweener</a></p>
<p><a href="http://www.google.com/url?sa=t&source=web&ct=res&cd=1&url=http%3A%2F%2Fblog.greensock.com%2Ftweenmaxas3%2F&ei=jInOSK2QC6jeeu3z-eEI&usg=AFQjCNFfJ41rVV8JX7vg8VfC2vRwuwzAkQ&sig2=sCb4Kj8LvIXZj9Wt9iLZ9g" rel="nofollow noreferrer">TweenLite / TweenMax</a></p>
<p><a href="http://code.google.com/p/kitchensynclib/" rel="nofollow noreferrer">KitchenSync</a></p>
<p>I've had good luck actually using the first two, and have read great things about the last one.</p>
|
<p>You can use mx.effects.AnimateProperty even though your target is not a UIComponent. </p>
<p>If the tween you want to acheive is a simple one (Move, Resize, Fade etc) this saves you writing the boiler plate code that mx.effects.Tween requires.</p>
| 8,936
|
<p>.NET developers out there! Need your opinion here!</p>
<p>I am now using <a href="http://www.wholetomato.com" rel="noreferrer">Visual Assist X</a>, a decent piece of software, indeed. But the .NET bloggers seem to prefer <a href="http://www.jetbrains.com/resharper" rel="noreferrer">Resharper</a> more. I might want to consider a switch over, but before that I want your guys opinion first.</p>
|
<p>Resharper is much better for C# code (and supposedly VB.Net, but I haven't tried that).
Unfortunately there is no support for C/C++, so if you need that, you might want to keep Visual Assist around. </p>
<p>They don't coexist very well, unfortunately, so you may need to unload one, then load the other, when switching between C/C++ and C#.</p>
<p>To see the magic of Resharper, I would recommend watching the <a href="http://www.jetbrains.com/resharper/demos/presentation/codingSession/CodingSession.wmv" rel="noreferrer">"Resharper Jedi" video</a>.</p>
|
<p>I know you only asked for a comparison of Resharper vs. Visual Assist but if you are doing .NET development you may also want to consider <a href="http://devexpress.com/Products/Visual_Studio_Add-in/Refactoring/" rel="nofollow noreferrer">"Refactor! Pro"</a>. </p>
<p>I remember using VA years ago when doing Visual C++ development (and earlier than that the infamous CodeWiz) but with .NET development I get the impression that the majority of developers seem to use either ReSharper or Refactor!. </p>
<p>Refactor! also integrates with a code-generation tool called "CodeRush" and I've seen them both used very effectively together with Testdriven.Net (check out the <a href="http://www.summerofnhibernate.com/" rel="nofollow noreferrer">Summer of NHibernate</a> screencasts). </p>
<p>Personally I use Resharper and I am very pleased with how much it has increased my productivity but I'm sure you'll get equal benefit with Refactor!.</p>
| 17,911
|
<p>I'm trying to print <a href="https://www.thingiverse.com/thing:4461654" rel="nofollow noreferrer">a gear for a robovac deal</a>.</p>
<p>The issue I'm having is with gaps between the walls of the top part of the gear. It needs to have the corners filled to provide stability or else the tabs easily snap. I've tried adjusting the nozzle size, line width, filter gaps and print thin walls but seems to slice with variations on the same issue. Is this a Cura issue? Is there anyway to slice and print this to fill those gaps?</p>
<p><a href="https://i.stack.imgur.com/0g7zy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0g7zy.png" alt="gear with gaps between walls" /></a></p>
|
<p>The problem isn't Cura, rather its the precision of the 3D model. If parts of the model is smaller than the line width the model cannot be printed. A solution to this would be to increase the thickness of the cylinder, decrease the size of the square or reduce the line width to allow that region to be properly fabricated, another solution would be to decrease the line width (line width option) however, keep in mind that you should not reduce the line width beyond the nozzle hole size (nozzle hole > line width). As mentioned before, if the model requires sections that are smaller than the line width, Cura will ignore it. From the image you provided it would seem that the corners are extremely close to the wall of the cylinder which prevents Cura from making a extrusion path, the reason of which I explained above.</p>
|
<p>You can fix it by changing <strong>Experimental</strong> > <strong>Slicing Tolerance</strong> > <strong>Exclusive</strong></p>
<p><a href="https://i.stack.imgur.com/htVjk.jpg" rel="nofollow noreferrer" title="Cura screenshot of a model with the Slicing tolerance set to Middle"><img src="https://i.stack.imgur.com/htVjk.jpg" alt="Cura screenshot of a model with the Slicing tolerance set to Middle" title="Cura screenshot of a model with the Slicing tolerance set to Middle" /></a></p>
<p><a href="https://i.stack.imgur.com/JGAoE.jpg" rel="nofollow noreferrer" title="Cura screenshot of a model with the Slicing tolerance set to Exclusive"><img src="https://i.stack.imgur.com/JGAoE.jpg" alt="Cura screenshot of a model with the Slicing tolerance set to Exclusive" title="Cura screenshot of a model with the Slicing tolerance set to Exclusive" /></a></p>
| 1,802
|
<p>I have an Excel macro that deletes a sheet, copies another sheet and renames it to the same name of the deleted sheet. This works fine when run from Excel, but when I run it by calling the macro from Python I get the following error message:</p>
<blockquote>
<p>Run-time error '1004' - Cannot rename a sheet to the same name as
another sheet, a referenced object library or a workbook referenced by
VisualBasic.</p>
</blockquote>
<p>The macro has code like the following:</p>
<pre><code>Sheets("CC").Delete
ActiveWindow.View = xlPageBreakPreview
Sheets("FY").Copy After:=Sheets(Sheets.Count)
Sheets(Sheets.Count).Name = "CC"
</code></pre>
<p>and the debugger highlights the error on the last line where the sheet is renamed. I've also tried putting these calls directly in python but get the same error message.</p>
<p>Any suggestions are much appreciated!</p>
<p>Thanks.</p>
|
<p>I ran the code inside Excel VBA.<br>
I am guessing that the following line is failing.<br></p>
<p><code>
Sheets("CC").Delete
</code></p>
<p>And that is the reason, you can't give the new sheet same name as existing (non-deleted) sheet.<br> </p>
<p>Put <code> Application.DisplayAlerts = False </code> before <code> Sheets("CC").Delete </code> and <br> <code> Application.DisplayAlerts = True </code> once you are finished with the code.</p>
<p>I haven't used python but it seems the library is swallowing that error for you and letting you go ahead to the next statement.</p>
<p>Hope that helps.</p>
|
<p>Behind the scenes, VB and VBA are maintaining references to COM objects for the application, worksheets etc. This is why you have the globals 'Application', 'Worksheets' etc. It is possible that VBA is still holding a reference to the worksheet, so Excel hasn't tidied it up properly.</p>
<p>Try not using these implicit globals and referencing the items in the object model explicitly. Alternatively you could do it directly in Python.</p>
<p>Here's a python script that will do something like what you want:</p>
<pre><code>import win32com.client
xl = win32com.client.Dispatch ('Excel.Application')
xl.Visible = True
wb = xl.Workbooks.Add()
wb.Worksheets[0].Delete()
wb.Worksheets.Add()
wb.Worksheets[0].Name = 'Sheet1'
</code></pre>
| 36,820
|
<p>I am working on a process to allow people to upload PDF files and manage the document (page order) via a web based interface.</p>
<p>The pages of the PDF file need to be cropped to a particular size for printing and currently we run them through a Photoshop action that takes care of this.</p>
<p>What I want to do is upload the PDF files to a dedicated server for performing the desired process (photoshop action, convert, send images back to web server).</p>
<p>What are some good ways to perform the functions, but sending updates to the webserver to allow for process tracking/progress bars to keep the user informed on how long their files are taking to process.</p>
<p>Additionally what are some good techniques for queueing/tracking jobs/processes in general (with an emphasis on web based technologies)?</p>
|
<p>For your second question: you need the <a href="http://everything2.com/index.pl?node_id=859282" rel="noreferrer">Douglas-Peucker Generalization Algorithm</a></p>
|
<p>I don't know much aobut KML, but I think the usual solution to question #2 involves iterating over the points, and deleting any line segments under a certain size. This will cause some "unfortunate" effects in some cases, but it's relatively fast and easy to do.</p>
| 23,454
|
<p>This is a winforms application.</p>
<p>In windows, I want the user to click and button, and then a popup should make the user select the path of where they want to save the file.</p>
|
<p>You want the <a href="http://msdn.microsoft.com/en-us/library/system.io.file.writealltext.aspx" rel="noreferrer">WriteAllText</a> function.</p>
<pre><code>using (SaveFileDialog dialog = new SaveFileDialog()) {
if (dialog.ShowDialog(this) == DialogResult.OK) {
File.WriteAllText(dialog.FileName, yourStringBuilder.ToString());
}
}
</code></pre>
|
<p><code>StringBuilder.ToString()</code> can be passed to the <code>TextStream.Write()</code> method after creating the file.</p>
<p>Using the <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.savefiledialog(VS.80).aspx" rel="nofollow noreferrer">SaveFileDialog class</a>, you can let the user select path and file name - in a standard way. Detailed examples in the <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.filedialog(VS.80).aspx" rel="nofollow noreferrer">doc</a>.</p>
| 28,573
|
<p>I have two custom controls that are analogous to a node and the control that draws links between nodes. </p>
<p>I would like to have both controls written as much in xaml as possible. The link stores both nodes as dependency properties, and I use databinding to move the line between the nodes whenever the nodes move.</p>
<p>It would be great to be able to change some other value of the line, for instance the stroke width, depending on the distance between the two nodes. So the property needs to update when either node moves, and I can't quite get my head around how that would work.</p>
<p>Anyone got any ideas?</p>
|
<p>you can try doing something like that:</p>
<ol>
<li>as in previous post define a width, stroke (whatever you need) property on your link class</li>
<li>define a multibinding applied to that property, passing your two nodes to the binding
it should look like:</li>
</ol>
<blockquote>
<p><Multibinding Converter="{StaticResource converter}"><br>
<Binding Path="Node1" RelativeSource|Source.../><br>
<Binding Path="Node2" ... /><br>
</Multibinding></p>
</blockquote>
<ol start="3">
<li><p>Implement interface IMultiValueConverter, which will basically calculate how the stroke should look like based on the distance between nodes. </p></li>
<li><p>in xaml create instance of your converter, and add it to your multibinding's Converter property. </p></li>
</ol>
<p>the advantage of this solution is, that you have pretty clear class model and each class does simple tasks. moreover, later on, you can configure your converter class to support extra cases without touching node class which stays simple and is designed simply for displaying nodes.</p>
<p>in general, whenever you have to map multiple property values to one other property, you'll have to use multibinding and converter.</p>
|
<p>You could define a property StrokeWidth in your link class that gets calculated every time the nodes move and then bind the appropriate style property to it.</p>
<p>I suppose you could also try to do something with DataTriggers, but they need specific values to work with - you can't use any kind of expressions. This would make it difficult to have the solution scale well to a wide array of distances between the nodes.</p>
| 13,454
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.