instruction
stringlengths 21
27.8k
| chosen
stringlengths 18
28.2k
| rejected
stringlengths 18
33.6k
| __index_level_0__
int64 0
50k
|
|---|---|---|---|
<p>The kind of simulation game that I have in mind is the kind where you have things to build in various locations and workers/transporters that connect such locations.</p>
<p>Something more like the Settlers series.</p>
<p>Let's assume I don't want any graphics at the moment, <strong>that</strong> I think I can manage.</p>
<p>So my doubts are the following:</p>
<ol>
<li>Should every entity be a class and each one have a thread?</li>
<li>Should entities be grouped in lists inside classes and each one have a thread?</li>
</ol>
<p>If one takes implementation 1, it's going to be very hard to run on low spec machines and does not scale well for large numbers.</p>
<p>If one takes implementation 2, it's going to be better in terms of resources but then...</p>
<p>How should I group the entities?</p>
<ol>
<li>Have a class for houses in general and have an Interface List to manage that?</li>
<li>Have a class for specific groups of houses and have an Object List to manage that?</li>
</ol>
<p>and what about threads?</p>
<ol>
<li>Should I have the simplistic main game loop?</li>
<li>Should I have a thread for each class group?</li>
<li>How do workers/transporters fit in the picture?</li>
</ol>
|
<p>The normal approach does not use threading at all, but rather implements entities as state-machines. Then your mainloop looks like this:</p>
<pre><code> while( 1 )
{
foreach( entity in entlist )
{
entity->update();
}
render();
}
</code></pre>
|
<p>I would avoid making a separate class for each entity because then you'll have situations where you're either repeating code for shared capabilities, or you'll have a funky inheritance tree.</p>
<p>I'd argue that what you want is a single class and objects with functionality composed onto it. I saw an article on a blog talking about this very concept in an RTS...wait, I think it was a tour of <a href="http://blog.cumps.be/design-patterns-decorator-pattern/" rel="nofollow noreferrer">design patterns that someone was writing</a>.</p>
<p>Use the Visitor pattern spawning a thread on each object's DoEvents (for lack of a better word) method to tell each object to do what it's going to do during this given loop. Sync the threads at the end of your loop because you don't want to have some objects with complex logic still doing its thing from ten loops back when in reality it was destroyed five loops ago.</p>
| 19,389
|
<p>I'd like to find all the types inheriting from a base/interface. Anyone have a good method to do this? Ideas?</p>
<p>I know this is a strange request but its something I'm playing with none-the-less.</p>
|
<p>Use Assembly.GetTypes() to get all the types, and Type.IsAssignableFrom() to check for inheritance. Let me know if you need code - and also whether or not you're using .NET 3.5. (A lot of reflection tasks like this are simpler with LINQ to Objects.)</p>
<p>EDIT: As requested, here's an example - it finds everything in <code>mscorlib</code> which implements <code>IEnumerable</code>. Note that life is somewhat harder when the base type is generic...</p>
<pre><code>using System;
using System.Collections;
using System.Linq;
using System.Reflection;
class Test
{
static void Main()
{
Assembly assembly = typeof(string).Assembly;
Type target = typeof(IEnumerable);
var types = assembly.GetTypes()
.Where(type => target.IsAssignableFrom(type));
foreach (Type type in types)
{
Console.WriteLine(type.Name);
}
}
}
</code></pre>
|
<p>Or for subclasses of a base class:</p>
<pre><code>var a = Assembly.Load("My.Assembly");
foreach (var t in a.GetTypes().Where(t => t.IsSubClassOf(typeof(MyType)))
{
// there you have it
}
</code></pre>
| 39,822
|
<p>Are C# enums typesafe?</p>
<p>If not what are the implications? </p>
|
<p>To give a slightly different answer... while the values are type-safe from the casting perspective, they are still unchecked once they have been cast - i.e.</p>
<pre><code>enum Foo { A = 1, B = 2, C = 3 }
static void Main()
{
Foo foo = (Foo)500; // works fine
Console.WriteLine(foo); // also fine - shows 500
}
</code></pre>
<p>For this reason, you should take care to check the values - for example with a <code>default</code> in a <code>switch</code> that throws an exception.</p>
<p><strike>You can also check the (for non-<code>[Flags]</code> values) via:</p>
<pre><code>bool isValid = Enum.IsDefined(typeof(Foo), foo);
</code></pre>
<p></strike></p>
|
<p>Yes.</p>
<p>C#: enum types:</p>
<p>-A type-safe enumeration of named values.</p>
<p>-Prevents programming errors</p>
<p>-User can control underlying type (defaults to int)</p>
<p>-Also can control underlying values</p>
| 25,567
|
<p>I want to make a really simple iphone app: one screen with a single button... when the button is tapped a new screen appears. That's it. No animations, nothing,</p>
<p>I've tried endlessly to make the NavBar sample project do this... and it works but only if I use a UINavigationController with a table that I can tap etc. I've tried all the skeleton projects in XCode too.</p>
<p>I thought I was done when I did this:</p>
<pre><code>[[self navigationController] presentModalViewController:myViewController animated:YES];
</code></pre>
<p>But I couldn't do it without the UINavigationController. I just want a simple example.</p>
<p>Thanks so much!</p>
|
<p>One way you could do this is to create a new UIView and then when the button is pressed add that new UIVIew as a subview, therefore making it what you see.</p>
<p>If you make the new view its own subclass of UIView you would do something like this.</p>
<pre><code>LoginView *login = [[LoginView alloc] initWithFrame: rect];
[mainView addSubview: login];
</code></pre>
|
<p>The correct way to do this is set up your project with a <code>UINavigationController</code>. In your root view controller, add your button in the view controllers's view. Then in <code>viewDidLoad</code>, register for <code>UIControlEventTouchUpInside</code> events from you button. Then, in your event callback, call:</p>
<pre><code>[self.navigationController pushViewController:[[[SecondViewControllerClass alloc] initWithNib:nibName bundle:nil] autorelease]];
</code></pre>
<p>What kdbdallas suggested will work, but you won't get the nice sliding effects, nor will the navigation bar automatically change and provide your users with a back button.</p>
| 29,494
|
<p>I'm trying to write a small app that monitors how much power is left in a notebook battery and I'd like to know which Win32 function I could use to accomplish that.</p>
|
<p>For Vista and up you can use <a href="http://msdn.microsoft.com/en-us/library/aa373196(VS.85).aspx" rel="noreferrer">RegisterPowerSettingNotification</a></p>
<p>For earlier functions see the <a href="http://msdn.microsoft.com/en-us/library/aa373163(VS.85).aspx" rel="noreferrer">Power Management Functions</a> in this section of the MSDN page "Power Management Functions: Windows Server 2003 and Earlier"</p>
<p>You can see example code of the Vista method on <a href="http://www.codeproject.com/KB/vista/VGPowerMonitor.aspx" rel="noreferrer">codeproject</a>. </p>
|
<p>There is a very detailed article in the following link, as well as a n example project (tested working on Win8.1): <a href="http://www.codeproject.com/Articles/15829/Vista-Goodies-in-C-Monitoring-the-Computer-s-Power" rel="nofollow">http://www.codeproject.com/Articles/15829/Vista-Goodies-in-C-Monitoring-the-Computer-s-Power</a></p>
| 28,896
|
<p>What is the difference in displaying xml data using html browser such as firefox,internet exporer,netscape navigator etc. in terms of how text, images etc are display on a computer screen?</p>
|
<p>The question is a little bit confusing, since XML is a base technology, it does not define how to represent anything so the question itself hasn't a lot of sense. </p>
<p>A plain xml file will be displayed as a collapsable tree of text data since any xml file is just a structured text file that follows some basic and simple rules (such as tag syntax, special chars, etc.).</p>
<p>As divo said if you define a stylesheet inside xml what IExplorer will render will be the result of applying that stylesheet. That applies to both CSS stylesheets and XSLT transformation stylesheets.</p>
<p>Moreover if your xml is actually xhtml it will be rendered as a normal HTML page. That is because IExplorer supports XHTML specification which is a standard defined by means of XML syntax.</p>
|
<p>some specialties of Internet Explorer (in contrast to simple text editors) is that you should be aware of are e.g. that white space is removed and empty tags are replaced by single elements ( becomes ).</p>
<p>IE also will execute any XSL stylesheet included in your XML.</p>
| 42,216
|
<p>I have the following requirements:</p>
<p>I need a api that works on CE (x86) + .NET Compact Framework to play videos (Similar to CorePlayer API... Just free)?</p>
<p>Is their anything else available or must I use CorePlayer?</p>
|
<p>You could use the MediaPlayer with COM interop. Have a look at <a href="http://www.eggheadcafe.com/software/aspnet/30991558/windows-media-player-for.aspx" rel="nofollow noreferrer">this</a> and <a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=64938&SiteID=1" rel="nofollow noreferrer">this</a>.</p>
<p>Also, Media Player may not be installed in your device.</p>
|
<p>DirectShow?
Check out <a href="http://www.geekpage.jp/en/programming/directshow/renderfile.php" rel="nofollow noreferrer">this page</a> for a starting point.
Provided that DirectShow is present on your CE, which I don't know...</p>
<p><strong>EDIT</strong>: Since you can use DirectShow, I'd like to add a bit.</p>
<p>As <em>ctacke</em> notes, it can be a lot of work if you do everything manually, but it's pretty straightforward if you can use <code>IGraphBuilder</code> (see the sample I linked above).</p>
<p>I don't know much about DirectShow versions, but the one included with Windows Mobile 6.0 lacks a splitter for MPEG audio. It means, e.g., that out of the box it won't play .mp3 files unless you wrap them in RIFF headers.</p>
| 42,855
|
<p>I am looking for a concise way to check a value to see if it is nil or zero. Currently I am doing something like:</p>
<pre><code>if (!val || val == 0)
# Is nil or zero
end
</code></pre>
<p>But this seems very clumsy.</p>
|
<p>Objects have a <a href="http://ruby-doc.org/core/Object.html#method-i-nil-3F" rel="noreferrer"><em>nil?</em> method</a>.</p>
<pre><code>if val.nil? || val == 0
[do something]
end
</code></pre>
<p>Or, for just one instruction:</p>
<pre><code>[do something] if val.nil? || val == 0
</code></pre>
|
<pre><code>val ||= 0
if val == 0
# do something here
end
</code></pre>
| 25,711
|
<p>Are there any libraries out there that do this? Playing around with Common Lisp it seems like this would be one of the most useful things to lower barrier of entry for newcomers. ASDF seems mostly designed for deployment, not for rapid prototyping and development. Following threads on comp.lang.lisp it seems like people agree that CL's package system is powerful, but lacks the ease of something like Python's dead simple module system. It is FAIL in the sense that it's designed for power not usability.</p>
<p>Glad to know if I'm wrong. If I'm right, I'm stunned that noone has tried to build a Python module-like system on top of ASDF.</p>
|
<p><a href="http://xach.livejournal.com/278047.html" rel="noreferrer">Zach Beane wrote</a> how he nowadays starts new Common Lisp projects by using Quicklisp and Quickproject. This might be along the lines you want.</p>
|
<blockquote>
<p>it's designed for power not usability</p>
</blockquote>
<p>that's how most Lisp gurus like it.</p>
| 34,000
|
<p>What's a quick and easy way to view and edit ID3 tags (artist, album, etc.) using C#?</p>
|
<p>Thirding <a href="https://github.com/mono/taglib-sharp" rel="noreferrer">TagLib Sharp</a>.</p>
<pre><code>TagLib.File f = TagLib.File.Create(path);
f.Tag.Album = "New Album Title";
f.Save();
</code></pre>
|
<p>I wrapped mp3 decoder library and made it available for .net developers. You can find it here:</p>
<p><a href="http://sourceforge.net/projects/mpg123net/" rel="nofollow noreferrer">http://sourceforge.net/projects/mpg123net/</a></p>
<p>Included are the samples to convert mp3 file to PCM, and read ID3 tags.</p>
| 9,378
|
<p>I'm working on a .net post-commit hook to feed data into OnTime via their Soap SDK. My hook works on Windows fine, but on our production RHEL4 subversion server, it won't work when called from a shell script.</p>
<pre>
#!/bin/sh
/usr/bin/mono $1/hooks/post-commit.exe "$@"
</pre>
<p>When I execute it with parameters from the command line, it works properly. When executed via the shell script, I get the following error: (looks like there is some problem with the process execution of SVN that I use to get the log data for the revision):</p>
<pre>
Unhandled Exception: System.InvalidOperationException: The process must exit before getting the requested information.
at System.Diagnostics.Process.get_ExitCode () [0x0003f] in /tmp/monobuild/build/BUILD/mono-1.9.1/mcs/class/System/System.Diagnostics/Process.cs:149
at (wrapper remoting-invoke-with-check) System.Diagnostics.Process:get_ExitCode ()
at SVNLib.SVN.Execute (System.String sCMD, System.String sParams, System.String sComment, System.String sUserPwd, SVNLib.SVNCallback callback) [0x00000]
at SVNLib.SVN.Log (System.String sUrl, Int32 nRevLow, Int32 nRevHigh, SVNLib.SVNCallback callback) [0x00000]
at SVNLib.SVN.LogAsString (System.String sUrl, Int32 nRevLow, Int32 nRevHigh) [0x00000]
at SVNCommit2OnTime.Program.Main (System.String[] args) [0x00000]
</pre>
<p>I've tried using <code>mkbundle</code> and <code>mkbundle2</code> to make a stand alone that could be named <code>post-commit</code>, but I get a different error message:</p>
<pre>
Unhandled Exception: System.ArgumentNullException: Argument cannot be null.
Parameter name: Value cannot be null.
at System.Guid.CheckNull (System.Object o) [0x00000]
at System.Guid..ctor (System.String g) [0x00000]
at SVNCommit2OnTime.Program.Main (System.String[] args) [0x00000]
</pre>
<p>Any ideas why it might be failing from a shell script or what might be wrong with the bundled version?</p>
<p><b>Edit:</b> <a href="https://stackoverflow.com/questions/54503/problem-with-net-app-under-linux-doesnt-work-from-shell-script#54537">@Herms</a>, I've already tried it with an echo, and it looks right. As for the <code>$1/hooks/post-commit.exe</code>, I've tried the script with and without a full path to the .net assembly with the same results.</p>
<p><b>Edit:</b> <a href="https://stackoverflow.com/questions/54503/problem-with-net-app-under-linux-doesnt-work-from-shell-script#54545">@Leon</a>, I've tried both <code>$1 $2</code> and <code>"$@"</code> with the same results. It is a subversion post commit hook, and it takes two parameters, so those need to be passed along to the .net assembly. The <code>"$@"</code> was what was recommended at the mono site for calling a .net assembly from a shell script. The shell script <i>is</i> executing the .net assembly and with the correct parameters, but it is throwing an exception that does not get thrown when run directly from the command line.</p>
<p><b>Edit:</b> <a href="https://stackoverflow.com/questions/54503/problem-with-net-app-under-linux-doesnt-work-from-shell-script#54568">@Vinko</a>, I don't see any differences in the environment other than things like <code>BASH_LINENO</code> and <code>BASH_SOURCE</code></p>
<p><b>Edit:</b> <a href="https://stackoverflow.com/questions/54503/problem-with-net-app-under-linux-doesnt-work-from-shell-script#54818">@Luke</a>, I tired it, but that makes no difference either. I first noticed the problem when testing from TortoiseSVN on my machine (when it runs as a sub-process of the subversion daemon), but also found that I get the same results when executing the script from the hooks directory (i.e. <code>./post-commit REPOS REV</code>, where <code>post-commit</code> is the above sh script. Doing <code>mono post-commit.exe REPOS REV</code> works fine. The main problem is that to execute, I need to have something of the name <code>post-commit</code> so that it will be called. But it does not work from a shell script, and as noted above, the <code>mkbundle</code> is not working with a different problem.</p>
|
<p>It is normal for some processes to hang around for a while after they close their stdout (ie. you get an end-of-file reading from them). You need to call <code>proc.WaitForExit()</code> after reading all the data but before checking ExitCode.</p>
|
<p>Just a random thought that might help with debugging. Try changing your shell script to:</p>
<pre><code>#!/bin/sh
echo /usr/bin/mono $1/hooks/post-commit.exe "$@"
</code></pre>
<p>Check and see if the line it prints matches the command you're expecting it to run. It's possible your command line argument handling in the shell script isn't doing what you want it to do.</p>
<p>I don't know what your input to the script is expected to be, but the $1 before the path looks a bit out of place to me.</p>
| 7,811
|
<p>What are some good solutions for handling automatic web based software updates for windows forms projects? I am aware of microsoft one-click, but am not interested in it at this time.</p>
|
<p>ClickOnce is good for cookie cutter stuff, but has some limitations around security (i.e. can't create a desktop icon, no access to COM, etc)</p>
<p>Assuming you are using MSI to install your application. Use WIX (<a href="http://wix.sourceforge.net/" rel="nofollow noreferrer">http://wix.sourceforge.net/</a>) to create a patch (.msp). You will want to look into Least Privileged User Account (LUA) Patching for Vista as UAC will screw you if you don't.</p>
<p>Then your application does the follows:</p>
<ol>
<li>Check for a new version via HTTP</li>
<li>Download the MSP (be careful of where you DL it to in Vista because of UAC) </li>
<li>Start a Shim exe that</li>
<li>waits for your app to close</li>
<li>launches the msp (in non-interactive mode)</li>
<li>restarts your app</li>
</ol>
<p>This can all happen automatically behind the scenes with zero user interaction on both XP and Vista.</p>
<p>A good place to start with this, and with WIX in general is:</p>
<p><a href="http://www.tramontana.co.hu/wix/index.php" rel="nofollow noreferrer">http://www.tramontana.co.hu/wix/index.php</a>
(Lesson 4 is on Updates)</p>
|
<p>but <a href="http://msdn.microsoft.com/en-us/library/t71a733d(VS.80).aspx" rel="nofollow noreferrer">ClickOnce</a> is the best you can have and you can select if users need to download the new version, use the old ones, go back versions, etc...</p>
<p>you can always built your own solution, check the version number of a XML setting file in some web address, if it is newer than the current one, alter user to download the new version for example...</p>
| 25,220
|
<p>I want a table <a href="http://joomlicious.com/mootable/" rel="nofollow noreferrer">similar to this one</a>, but where the user can adjust the height of the table as well as sort it. How can I do this?</p>
|
<p>I found the good one here
<a href="http://groups.google.com/group/flexigrid/?pli=1" rel="nofollow noreferrer">http://groups.google.com/group/flexigrid/?pli=1</a></p>
|
<p><a href="http://demos111.mootools.net/Resizable" rel="nofollow noreferrer">http://demos111.mootools.net/Resizable</a></p>
| 45,454
|
<p>I'm retrieving a gzipped web page via curl, but when I output the retrieved content to the browser I just get the raw gzipped data. How can I decode the data in PHP?</p>
<p>One method I found was to write the content to a tmp file and then ...</p>
<pre><code>$f = gzopen($filename,"r");
$content = gzread($filename,250000);
gzclose($f);
</code></pre>
<p>.... but man, there's got to be a better way.</p>
<p>Edit: This isn't a file, but a gzipped html page returned by a web server.</p>
|
<p>I use curl and:</p>
<pre><code>curl_setopt($ch, CURLOPT_ENCODING , "gzip");
</code></pre>
|
<p>Versatile GUNZIP function:</p>
<pre>
function gunzip($zipped) {
$offset = 0;
if (substr($zipped,0,2) == "\x1f\x8b")
$offset = 2;
if (substr($zipped,$offset,1) == "\x08") {
# file_put_contents("tmp.gz", substr($zipped, $offset - 2));
return gzinflate(substr($zipped, $offset + 8));
}
return "Unknown Format";
}
</pre>
<p>Example of integrating function with CURL:</p>
<pre>
$headers_enabled = 1;
curl_setopt($c, CURLOPT_HEADER, $headers_enabled)
$ret = curl_exec($c);
if ($headers_enabled) {
# file_put_contents("preungzip.html", $ret);
$sections = explode("\x0d\x0a\x0d\x0a", $ret, 2);
while (!strncmp($sections[1], 'HTTP/', 5)) {
$sections = explode("\x0d\x0a\x0d\x0a", $sections[1], 2);
}
$headers = $sections[0];
$data = $sections[1];
if (preg_match('/^Content-Encoding: gzip/mi', $headers)) {
printf("gzip header found\n");
return gunzip($data);
}
}
return $ret;
</pre>
| 40,029
|
<p>My problem is that I set some breakpoints in my code and some of them aren't working. In some places it complains about "Unresolved Breakpoint". </p>
<p>Does anyone have any clue why this is happening? I am using gdb, by the way.</p>
<p>EDIT: Yes, of course is compiled with debug information. It only happens at some classes or points in the code. And I am pretty sure that that part of the code is reached because I can reach it stepping</p>
<p>EDIT: The solution from Richard doesn't work; thanks anyway. I am compiling in Debug, without any optimization.</p>
|
<p>Could it be that you are trying to set breakpoints in a shared library that has not been loaded yet. That won't work until the library has loaded. Newer gdb allow to set deferred breakpoints, but that may not (yet) be supported by CDT. A workaround is to set a breakpoint in a place that is available from the beginning that will be reached when the shared library in question is already loaded. Then set the other breakpoint in the shared library. Now it should work. It's a bit more tedious, but usually works.</p>
<p>From the <a href="http://sources.redhat.com/gdb/current/onlinedocs/gdb_6.html" rel="noreferrer">GDB documentation</a>:</p>
<blockquote>
<p>For a pending breakpoint whose address is not yet known, this field will contain 'PENDING'. Such breakpoint won't fire until a shared library that has the symbol or line referred by breakpoint is loaded.</p>
</blockquote>
|
<p>I have found that using F8 (resume) doesn't stop at my breakpoints. But, if I have Stop On Startup : main set then then step over my code (F5/F6) then my breakpoints are hit. I don't have any special compiler options other than -g or -g3. Hope that help...</p>
| 24,994
|
<p>Are there any libraries or guides for how to read and parse binary data in C?</p>
<p>I am looking at some functionality that will receive TCP packets on a network socket and then parse that binary data according to a specification, turning the information into a more useable form by the code.</p>
<p>Are there any libraries out there that do this, or even a primer on performing this type of thing?</p>
|
<p>The standard way to do this in C/C++ is really casting to structs as 'gwaredd' suggested</p>
<p>It is not as unsafe as one would think. You first cast to the struct that you expected, as in his/her example, <strong>then</strong> you test that struct for validity. You have to test for max/min values, termination sequences, etc.</p>
<p>What ever platform you are on you must read <a href="https://rads.stackoverflow.com/amzn/click/com/0131411551" rel="nofollow noreferrer" rel="nofollow noreferrer">Unix Network Programming, Volume 1: The Sockets Networking API</a>. Buy it, borrow it, steal it ( the victim will understand, it's like stealing food or something... ), but do read it.</p>
<p>After reading the Stevens, most of this will make a lot more sense.</p>
|
<p>I'm not really understand what kind of library you are looking for ? Generic library that will take any binary input and will parse it to unknown format?
I'm not sure there is such library can ever exist in any language.
I think you need elaborate your question a little bit. </p>
<p><strong>Edit</strong>:<br>
Ok, so after reading <a href="https://stackoverflow.com/questions/321423/parsing-binary-data-in-c#321482">Jon's</a> answer seems there is a library, well kind of library it's more like code generation tool. But as many stated just casting the data to the appropriate data structure, with appropriate carefulness i.e using packed structures and taking care of endian issues you are good. Using such tool with C it's just an overkill. </p>
| 41,604
|
<p>When restoring a SQL Server Database, I notice that there are 3 different Recovery States to choose from:</p>
<ul>
<li>Restore with Recovery</li>
<li>Restore with No Recovery</li>
<li>Restore with Standby</li>
</ul>
<p>I've always left it at it's default value, but what do they all mean?</p>
<p>(Preferably in layman's terms)</p>
|
<p>GateKiller,</p>
<p>In simple terms (and not a copy-paste out of the SQLBOL) so you can understand the concepts:</p>
<p>RESTORE WITH RECOVERY uses the backup media file (eg. fulldata.bak) to restore the database to back to the time that backup file was created. This is great if you want to go back in time to restore the database to an earlier state - like when developing a system.</p>
<p>If you want to restore the database TO THE VERY LATEST DATA, (i.e. like if your doing a system Disaster Recovery and you cannot lose any data) then you want to restore that backup AND THEN all the transaction logs created since that backup. This is when you use RESTORE NORECOVERY. It will allow you to restore the later transaction logs right up to the point of failure (as long as you have them).</p>
<p>RECOVERY WITH STANDBY is the ability to restore the database up to a parital date (like NORECOVERY above) but to allow the database still to be used READONLY. New transaction logs can still be applied to the database to keep it up to date (a standby server). Use this when it would take too long to restore a full database in order to Return To Operations the system. (ie. if you have a multi TB database that would take 16 hours to restore, but could receive transaction log updates every 15 minutes).</p>
<p>This is a bit like a mirror server - but without having "every single transaction" send to the backup server in real time.</p>
|
<p>From Books On line, i think it is pretty clear after you read it</p>
<p><strong>NORECOVERY</strong></p>
<p>Instructs the restore operation to not roll back any uncommitted transactions. Either the NORECOVERY or STANDBY option must be specified if another transaction log has to be applied. If neither NORECOVERY, RECOVERY, or STANDBY is specified, RECOVERY is the default.</p>
<p>SQL Server requires that the WITH NORECOVERY option be used on all but the final RESTORE statement when restoring a database backup and multiple transaction logs, or when multiple RESTORE statements are needed (for example, a full database backup followed by a differential database backup).</p>
<p>Note When specifying the NORECOVERY option, the database is not usable in this intermediate, nonrecovered state.</p>
<p>When used with a file or filegroup restore operation, NORECOVERY forces the database to remain in the restoring state after the restore operation. This is useful in either of these situations: </p>
<p>A restore script is being run and the log is always being applied.</p>
<p>A sequence of file restores is used and the database is not intended to be usable between two of the restore operations. </p>
<p><strong>RECOVERY</strong></p>
<p>Instructs the restore operation to roll back any uncommitted transactions. After the recovery process, the database is ready for use.</p>
<p>If subsequent RESTORE operations (RESTORE LOG, or RESTORE DATABASE from differential) are planned, NORECOVERY or STANDBY should be specified instead.</p>
<p>If neither NORECOVERY, RECOVERY, or STANDBY is specified, RECOVERY is the default. When restoring backup sets from an earlier version of SQL Server, a database upgrade may be required. This upgrade is performed automatically when WITH RECOVERY is specified. For more information, see Transaction Log Backups .</p>
<p><strong>STANDBY</strong> = undo_file_name</p>
<p>Specifies the undo file name so the recovery effects can be undone. The size required for the undo file depends on the volume of undo actions resulting from uncommitted transactions. If neither NORECOVERY, RECOVERY, or STANDBY is specified, RECOVERY is the default.</p>
<p>STANDBY allows a database to be brought up for read-only access between transaction log restores and can be used with either warm standby server situations or special recovery situations in which it is useful to inspect the database between log restores.</p>
<p>If the specified undo file name does not exist, SQL Server creates it. If the file does exist, SQL Server overwrites it.</p>
<p>The same undo file can be used for consecutive restores of the same database. For more information, see Using Standby Servers. </p>
<p>Important If free disk space is exhausted on the drive containing the specified undo file name, the restore operation stops.</p>
<p>STANDBY is not allowed when a database upgrade is necessary.</p>
| 2,951
|
<p>Which one do you prefer to store text in your database? The original casing of the data, or some kind of normalization. Also, should I enforce this with triggers? or should I preprocess input data with client code?</p>
<p>I ask you, because I'm not sure about if there is any difference, besides additional processing time to display data (capitalization of names, for example).</p>
|
<p>Store in original case, unless there is a reason to do otherwise. The time spent to upper or lower case the data is likely very small, and you never know when you'll want the real, original data back in the future.</p>
|
<p>I wouldn't worry about it, just format it how you need it to be used on output.</p>
| 37,134
|
<p>Is it possible to reorder an already generated PDF file programmatically, and using as little resources as possible, as this will need to be ran on ~8000 PDFs every month or so?</p>
<p>We are currently using iTextSharp to merge the PDF’s in to larger PDF’s, but iTextsharp’s Documentation does not really explain much.</p>
|
<p><a href="http://en.wikipedia.org/wiki/Multivariate_testing" rel="nofollow noreferrer">Multivariate testing</a> and reporting is a great way to actually measure these kind of things. </p>
<p>It allows you to test what combination of page elements has the greatest conversion rate, providing continual improvement on your site design and usability.</p>
<p><a href="http://www.google.com/websiteoptimizer" rel="nofollow noreferrer">Google Web Optimiser</a> has support for this.</p>
|
<p>The first way can be fully subjective or partly quantified: user complaints and positive feedbacks. The problem with this is that you may have some strong biases when it comes to filter those feedbacks, so you better make as quantitative as possible. Having some ticketing system to file every report from the users and gathering statistics about each version of the interface might be useful. Just get your statistics right.</p>
<p>The second way is to measure the difference in a questionnaire taken about the interface by end-users. Answers to each question should be a set of discrete values and then again you can gather statistics for each version of the interface.</p>
<p>The latter way may be much harder to setup (designing a questionnaire and possibly the controlled environment for it as well as the guidelines to interpret the results is a craft by itself) but the former makes it unpleasantly easy to mess up with the measurements. For example, you have to consider the fact that the number of tickets you get for each version is dependent on the time it is used, and that all time ranges are not equal (e.g. a whole class of critical issues may never be discovered before the third or fourth week of usage, or users might tend not to file tickets the first days of use, even if they find issues, etc.).</p>
| 18,893
|
<p>Trying to build a dashboard using Oracle's Brio. I have to access 6 different databases to grab the same type of data, aggregate it and display it. Except that when I do it, Brio grabs the data from the first source just fine. When I grab the data from the second data source, Brio replaces the original data with the second set. So I am not able to aggregate the data. Can anyone help me figure out how I can do this in Brio please?</p>
|
<pre><code>bool isSubset = !t2.Except(t1).Any();
</code></pre>
|
<p>Try this</p>
<pre><code>static bool IsSubSet<A>(A[] set, A[] toCheck) {
return set.Length == (toCheck.Intersect(set)).Count();
}
</code></pre>
<p>The idea here is that Intersect will only return the values that are in both Arrays. At this point if the length of the resulting set is the same as the original set, then all elements in "set" are also in "check" and therefore "set" is a subset of "toCheck"</p>
<p>Note: My solution does not work if "set" has duplicates. I'm not changing it because I don't want to steal other people's votes.</p>
<p>Hint: I voted for Cameron's answer. </p>
| 43,159
|
<p>I have two projects in CPP. One defines a function which I'd like to invoke from the other.
I added a reference to the first project.
I still get the message of "identifier not found".
Assuming that the CPP file in the first project doesn't have a header, how do I make the second project know about its functions?</p>
|
<p>If the first project doesn't have a header and you don't want to add one, then use the <code>extern</code> keyword to declare a prototype for the function you want to call in the second project source:</p>
<pre><code>extern function_in_first_project(int args_go_here);
</code></pre>
<p>Make 100% sure that the function declaration (including argument list and calling convention) matches that of the actual function or you'll run into further problems.</p>
<p>This may not be the only thing you have to do to make your project link, depending on how you've got your projects set up.</p>
|
<p>you could probably just add this to the top of the .cpp file of the second project:</p>
<pre><code>#include "first_project_header_file.h"
</code></pre>
| 26,408
|
<p>A client of our has recently upgraded a ASP.NET 1.1 web application to ASP.NET that uses COM+ transaction processing and received the following exception while trying to process a transaction:</p>
<blockquote>
<p>Exception Type:
System.Transactions.TransactionManagerCommunicationException<br />
Message: Communication with the
underlying transaction manager has
failed.</p>
<p>Inner Exception Type:
System.Runtime.InteropServices.COMException
ErrorCode: -2147467259<br />
Message: Error
HRESULT E_FAIL has been returned from
a call to a COM component.</p>
</blockquote>
<p>Here are the following settings on MSDTC Security Settings:</p>
<blockquote>
<p>-- Network DTC Access<br />
-- Allow Inbound<br />
-- Allow Outbound<br />
-- Incoming Caller Authenication Required</p>
</blockquote>
<p>A Windows XP SP3 workstation is trying to establish a connection to a Windows Server 2003 machine.</p>
<p>Has anyone else experienced this error and know how to resolve it.</p>
|
<p>You'll need to have network DTC access enabled on both your XP workstation and your windows 2003 machine. Also, if your application is only published internally, you can turn off incoming caller authentication and set it to "no authentication".</p>
|
<p>In case you need help finding the MSDTC settings mentioned in the other answers (like I did), the following link explains how to configure MSDTC on server 2003.</p>
<p><a href="http://itknowledgeexchange.techtarget.com/sql-server/how-to-configure-dtc-on-windows-2003/" rel="nofollow">http://itknowledgeexchange.techtarget.com/sql-server/how-to-configure-dtc-on-windows-2003/</a></p>
| 24,680
|
<p>I've got a code that lists the running application on a win32 box, and then displays theirs icons.</p>
<p>So far so good, I get the hwnd of the app, then call for GetClassLong(hwnd,GCL_HICONSM), and everything's fine.</p>
<p>But the case of a java apps is a pain to deal with, as the process answering to my calls is javaw.exe, and not the shiny-pimpy java application, who's got a so beautiful icon...</p>
<p>I gave a shot at GetWindowThreadProcessId also, but alas, it's the PID of javaw that's returned...</p>
<p>There's a way to do this though, as the task manager (alt+tab) displays the good icon.</p>
|
<p>Mmm, it can be done, because <a href="http://www.teamcti.com/pview/prcview.htm" rel="nofollow noreferrer" title="Process Viewer">Process Viewer</a> has a Show Applications button which does that (even if the main view shows the Java's icon). Alas this freeware isn't open source, so it won't tell its secret... :-(</p>
<p>Sysinternals' ProcMon doesn't do that, alas.</p>
<p>I will dig a bit more... :-)</p>
<p>[EDIT] Both a MS KB article and a <a href="http://www.codeproject.com/KB/dotnet/AltTab.aspx" rel="nofollow noreferrer" title="Selecting Running Application">Code Project</a> article recommend using WM_QUERYDRAGICON if GCL_HICON fails...</p>
|
<p>Mmm, it can be done, because <a href="http://www.teamcti.com/pview/prcview.htm" rel="nofollow noreferrer" title="Process Viewer">Process Viewer</a> has a Show Applications button which does that (even if the main view shows the Java's icon). Alas this freeware isn't open source, so it won't tell its secret... :-(</p>
<p>Sysinternals' ProcMon doesn't do that, alas.</p>
<p>I will dig a bit more... :-)</p>
<p>[EDIT] Both a MS KB article and a <a href="http://www.codeproject.com/KB/dotnet/AltTab.aspx" rel="nofollow noreferrer" title="Selecting Running Application">Code Project</a> article recommend using WM_QUERYDRAGICON if GCL_HICON fails...</p>
| 26,079
|
<p>Hypothetical situation:</p>
<p>Suppose I ran a hosting firm where I hosted subdomains for people. You could sign up and give me a few bucks a month, and I'd give you yourname.mycompany.com.</p>
<p>Now, say I wanted mail.*.mycompany.com to point to one server and www.*.mycompany.com to point to another.</p>
<p>Is this possible? The RFC seems to think not, <a href="http://en.wikipedia.org/wiki/Wildcard_DNS_record" rel="nofollow noreferrer">Wikipedia</a> seems to think not, but what's stopping a DNS server from having enough logic to return the right thing?</p>
<p>And if so, are there DNS hosting providers that will do this for me so I don't have to run my own DNS?</p>
|
<p>A horizontal swipe on a table row is already a standard UI behavior that causes that row to be deleted. Don't go changing standard UI paradigms -- it confuses users and makes them dislike your app.</p>
|
<p>Just call a touch cancel method there check the swipe is occured ir not with touch points.Then do your functionality</p>
| 44,565
|
<p>I use Visual Studio's "Code Snippet" feature pretty heavily while editing c# code. I always wished I could use them while typing out my aspx markup. </p>
<p>Is there a way to enable code snippet use in an aspx file editor window?</p>
<p>Are there any third party tools that perform this?</p>
<p>If you're familiar with code snippet definitions, this is exactly the type of thing I want to do:</p>
<pre><code><asp:TextBox ID="$var$TextBox" Text="$text$" OnClick="$var$_Click" runat="server" />
</code></pre>
<p><em>I could activate the snippet, tab twice, and move on!</em></p>
|
<p>Perhaps you might think of trying <a href="http://devexpress.com/coderush" rel="nofollow noreferrer">Coderush</a> which has a lot more to offer than the basic snippets found in VS. It's template facility can operate in vb, cs, aspx, html, xml and sql files.</p>
|
<p>@Rory-Becker Coderush is exactly what I've been looking for!!</p>
<p>I had previously posted that Coderush costs $99, but it costs $249.</p>
<p>@harriyott </p>
<p>Codesmith has something called Active Snippets. It only comes with the professional version, which costs $399</p>
<p><a href="http://www.codesmithtools.com/features/comparison.aspx" rel="nofollow noreferrer">http://www.codesmithtools.com/features/comparison.aspx</a></p>
| 25,189
|
<p>For example, if I have a page located in Views/Home/Index.aspx and a JavaScript file located in Views/Home/Index.js, how do you reference this on the aspx page?</p>
<p>The example below doesn't work even though the compiler says the path is correct</p>
<pre><code><script src="Index.js" type="text/javascript"></script>
</code></pre>
<p>The exact same issue has been posted here in more detail:
<a href="http://forums.asp.net/p/1319380/2619991.aspx" rel="nofollow noreferrer">http://forums.asp.net/p/1319380/2619991.aspx</a></p>
<p>If this is not currently possible, will it be in the future? If not, how is everyone managing their javascript resources for large Asp.net MVC projects? Do you just create a folder structure in the Content folder that mirrors your View folder structure? YUCK!</p>
|
<p>You can use the VirtualPathUtility.ToAbsolute method like below to convert the app relative url of the .js file to an absolute one that can be written to the page:</p>
<pre><code><script type="text/javascript" src="<%=VirtualPathUtility.ToAbsolute("~/Views/Home/Index.js") %>"></script>
</code></pre>
|
<p>If you re-route your pages to a custom RouteHandler, you can check for existence of files before handling the RequestContext to the MvcHandler class.</p>
<p>Example (not complete):</p>
<pre><code>public class RouteHandler : IRouteHandler
{
public IHttpHandler
GetHttpHandler(RequestContext requestContext)
{
var request = requestContext.HttpContext.Request;
// Here you should probably make the 'Views' directory appear in the correct place.
var path = request.MapPath(request.Path);
if(File.Exists(path)) {
// This is internal, you probably should make your own version.
return new StaticFileHandler(requestContext);
}
else {
return new MvcHandler(requestContext);
}
}
}
</code></pre>
| 10,457
|
<p>I refactored a slow section of an application we inherited from another company to use an inner join instead of a subquery like:</p>
<pre><code>WHERE id IN (SELECT id FROM ...)
</code></pre>
<p><strong>The refactored query runs about 100x faster.</strong> (~50 seconds to ~0.3) I expected an improvement, but can anyone explain why it was so drastic? The columns used in the where clause were all indexed. Does SQL execute the query in the where clause once per row or something?</p>
<p><strong>Update</strong> - Explain results:</p>
<p>The difference is in the second part of the "where id in ()" query - </p>
<pre><code>2 DEPENDENT SUBQUERY submission_tags ref st_tag_id st_tag_id 4 const 2966 Using where
</code></pre>
<p>vs 1 indexed row with the join:</p>
<pre><code> SIMPLE s eq_ref PRIMARY PRIMARY 4 newsladder_production.st.submission_id 1 Using index
</code></pre>
|
<p>A "correlated subquery" (i.e., one in which the where condition depends on values obtained from the rows of the containing query) will execute once for each row. A non-correlated subquery (one in which the where condition is independent of the containing query) will execute once at the beginning. The SQL engine makes this distinction automatically.</p>
<p>But, yeah, explain-plan will give you the dirty details.</p>
|
<p>With a subquery, you have to re-execute the 2nd SELECT for each result, and each execution typically returns 1 row. </p>
<p>With a join, the 2nd SELECT returns a lot more rows, but you only have to execute it once. The advantage is that now you can join on the results, and joining relations is what a database is supposed to be good at. For example, maybe the optimizer can spot how to take better advantage of an index now.</p>
| 17,064
|
<p>I am trying to pass a member function within a class to a function that takes a member function class pointer. The problem I am having is that I am not sure how to properly do this within the class using the this pointer. Does anyone have suggestions?</p>
<p>Here is a copy of the class that is passing the member function:</p>
<pre><code>class testMenu : public MenuScreen{
public:
bool draw;
MenuButton<testMenu> x;
testMenu():MenuScreen("testMenu"){
x.SetButton(100,100,TEXT("buttonNormal.png"),TEXT("buttonHover.png"),TEXT("buttonPressed.png"),100,40,&this->test2);
draw = false;
}
void test2(){
draw = true;
}
};
</code></pre>
<p>The function x.SetButton(...) is contained in another class, where "object" is a template.</p>
<pre><code>void SetButton(int xPos, int yPos, LPCWSTR normalFilePath, LPCWSTR hoverFilePath, LPCWSTR pressedFilePath, int Width, int Height, void (object::*ButtonFunc)()) {
BUTTON::SetButton(xPos, yPos, normalFilePath, hoverFilePath, pressedFilePath, Width, Height);
this->ButtonFunc = &ButtonFunc;
}
</code></pre>
<p>If anyone has any advice on how I can properly send this function so that I can use it later.</p>
|
<p>To call a member function by pointer, you need two things: A pointer to the object and a pointer to the function. You need both in <code>MenuButton::SetButton()</code></p>
<pre><code>template <class object>
void MenuButton::SetButton(int xPos, int yPos, LPCWSTR normalFilePath,
LPCWSTR hoverFilePath, LPCWSTR pressedFilePath,
int Width, int Height, object *ButtonObj, void (object::*ButtonFunc)())
{
BUTTON::SetButton(xPos, yPos, normalFilePath, hoverFilePath, pressedFilePath, Width, Height);
this->ButtonObj = ButtonObj;
this->ButtonFunc = ButtonFunc;
}
</code></pre>
<p>Then you can invoke the function using both pointers:</p>
<pre><code>((ButtonObj)->*(ButtonFunc))();
</code></pre>
<p>Don't forget to pass the pointer to your object to <code>MenuButton::SetButton()</code>:</p>
<pre><code>testMenu::testMenu()
:MenuScreen("testMenu")
{
x.SetButton(100,100,TEXT("buttonNormal.png"), TEXT("buttonHover.png"),
TEXT("buttonPressed.png"), 100, 40, this, test2);
draw = false;
}
</code></pre>
|
<p>In the rare case that you happen to be developing with Borland C++Builder and don't mind writing code specific to that development environment (that is, code that won't work with other C++ compilers), you can use the __closure keyword. I found a <a href="http://www.drbob42.com/cbuilder/lstfnd15.htm" rel="nofollow noreferrer">small article about C++Builder closures</a>. They're intended primarily for use with Borland VCL.</p>
| 15,825
|
<p>I am trying to automate functional testing of a server using a realistic frequency distribution of requests. (sort of load testing, sort of simulation)</p>
<p>I've chosen the <a href="http://en.wikipedia.org/wiki/Weibull_distribution" rel="nofollow noreferrer">Weibull</a> distribution as it "sort of" matches the distribution I've observed (ramps up quickly, drops off quickly but not instantly)</p>
<p>I use this distribution to generate the number of requests that should be sent each day between a given start and end date</p>
<p>I've hacked together an algorithm in Python that sort of works but it feels kludgy:</p>
<pre><code>how_many_days = (end_date - start_date).days
freqs = defaultdict(int)
for x in xrange(how_many_responses):
freqs[int(how_many_days * weibullvariate(0.5, 2))] += 1
timeline = []
day = start_date
for i,freq in sorted(freqs.iteritems()):
timeline.append((day, freq))
day += timedelta(days=1)
return timeline
</code></pre>
<p>What better ways are there to do this? </p>
|
<p>This is quick and probably not that accurate, but if you calculate the PDF yourself, then at least you make it easier to lay several smaller/larger ones on a single timeline. <code>dev</code> is the std deviation in the Guassian noise, which controls the roughness. Note that this is <em>not</em> the 'right' way to generate what you want, but it's easy.</p>
<pre><code>import math
from datetime import datetime, timedelta, date
from random import gauss
how_many_responses = 1000
start_date = date(2008, 5, 1)
end_date = date(2008, 6, 1)
num_days = (end_date - start_date).days + 1
timeline = [start_date + timedelta(i) for i in xrange(num_days)]
def weibull(x, k, l):
return (k / l) * (x / l)**(k-1) * math.e**(-(x/l)**k)
dev = 0.1
samples = [i * 1.25/(num_days-1) for i in range(num_days)]
probs = [weibull(i, 2, 0.5) for i in samples]
noise = [gauss(0, dev) for i in samples]
simdata = [max(0., e + n) for (e, n) in zip(probs, noise)]
events = [int(p * (how_many_responses / sum(probs))) for p in simdata]
histogram = zip(timeline, events)
print '\n'.join((d.strftime('%Y-%m-%d ') + "*" * c) for d,c in histogram)
</code></pre>
|
<p>Instead of giving the number of requests as a fixed value, why not use a scaling factor instead? At the moment, you're treating requests as a limited quantity, and randomising the days on which those requests fall. It would seem more reasonable to treat your requests-per-day as independent.</p>
<pre><code>from datetime import *
from random import *
timeline = []
scaling = 10
start_date = date(2008, 5, 1)
end_date = date(2008, 6, 1)
num_days = (end_date - start_date).days + 1
days = [start_date + timedelta(i) for i in range(num_days)]
requests = [int(scaling * weibullvariate(0.5, 2)) for i in range(num_days)]
timeline = zip(days, requests)
timeline
</code></pre>
| 7,732
|
<p>I know nothing about 3D printing and I was wondering if it is a good candidate for what I want to make.</p>
<p>I want to make a custom game cartridge which looks like this:
<a href="https://i.stack.imgur.com/k0RpQ.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/k0RpQ.jpg" alt="enter image description here"></a> </p>
<p>Basically it's like a SD card in a custom shell. Now I can produce the inside as a thin PCB (0.6mm-1mm). But I was wondering what the best (and cheapest) way to prototype (and maybe make a small run production) the outer shell would be. The entire cart is about 2mm thick, so each half of the shell would be at most ~0.6mm thick.</p>
<p>Is this something I can do with a typical 3D printer? How would I "attach" the two halves together?</p>
|
<p>Typically, for FDM, the resolution is different for height compared with the x-y plane.</p>
<p>In x-y, you will be constrained by the nozzle diameter (0.4mm is common), which effectively quantises your wall thickness (0.4, 0.8, 1.2 etc). These walls can be placed with maybe 0.05mm precision.</p>
<p>In Z, the constraint is to be less than the nozzle, so 0.12 or 0.2 mm is common.</p>
<p>So you can easily make a half which is around 1mm thick, with a 0.3mm high wall. You would want the majority of the wall width to be 0.8 or 1.2 mm at least, but you could probably arrange an overlap between the two parts to allow some tolerance and increase the glueing area.</p>
<p>A flat print of only a single layer is possible, but it won't be as accurately dimensioned (due to bed-leveling accuracy). A single layer with a wall would work, but might be too flexible.</p>
|
<p>With the experience I have with my 3d printer you can make (almost) everything you can draw with it.</p>
<p>0.6mm parts can be 3d printed but will not be very strong though.</p>
<p>For joining the 2 halves when they are so thin, I think the best solution is to glue them together. With the things I make for myself I mostly use small screws or small nuts and bolts but with 0.6mm parts I guess this wil not be possible.</p>
| 639
|
<p>When is white space not important in Python?</p>
<p>It seems to be ignored inside a list, for example:</p>
<pre><code>for x in range(5):
list += [x, 1
,2,3,
4,5]
</code></pre>
|
<p>White space is only important for indentation of statements. You have a single statement across several lines, and only the indentation of the beginning of the statement on the first line is significant. See <em><a href="http://www.secnetix.de/~olli/Python/block_indentation.hawk" rel="nofollow noreferrer">Python: Myths about Indentation</a></em> for more information.</p>
|
<p>Your question is really about when Python implicitly joins lines of code.</p>
<p>Python will implicitly join lines that are contained within (parentheses), {braces}, and [brackets], as in your example code. You can also explicitly join lines with a backslash (\) at the end of a line.</p>
<p>More here on <a href="http://docs.python.org/reference/lexical_analysis.html#implicit-line-joining" rel="nofollow noreferrer">implicit line continuation</a>: </p>
<p>Mr. Gamble's answer is correct for indentation.</p>
| 48,621
|
<p>I am trying to install a Windows service using InstallUtil.exe and am getting the error message</p>
<blockquote>
<p>System.BadImageFormatException: Could not load file or assembly '<code>{xxx.exe}</code>' or one of its dependencies. An attempt was made to load a program with an incorrect format.</p>
</blockquote>
<p>What gives?</p>
<hr>
<p>EDIT: (Not by OP) Full message extracted from dup getting way more hits [for googleability]:</p>
<blockquote>
<p>C:\Windows\Microsoft.NET\Framework64\v4.0.30319>InstallUtil.exe C:\xxx.exe
Microsoft (R) .NET Framework Installation utility Version 4.0.30319.1
Copyright (c) Microsoft Corporation. All rights reserved.</p>
<p>Exception occurred while initializing the installation:
System.BadImageFormatException: Could not load file or assembly 'file:///C:\xxx.exe' or one of its dependencies. An attempt was made to load a program with an incorrect format..</p>
</blockquote>
|
<p>Some more detail for completeness in case it helps someone...</p>
<p>Note that the most common reason for this exception these days is attempting to load a 32 bit-specific (<code>/platform:x86</code>) DLL into a process that is 64 bit or vice versa (viz. load a 64 bit-specific (<code>/platform:x64</code>) DLL into a process that is 32 bit). If your <code>platform</code> is non-specific (<code>/platform:AnyCpu</code>), this won't arise (assuming no referenced dependencies are of the wrong bitness).</p>
<p>In other words, running:</p>
<blockquote>
<p>%windir%\Microsoft.NET\Framework\v2.0.50727\installutil.exe </p>
</blockquote>
<p>or:</p>
<blockquote>
<p>%windir%\Microsoft.NET\Framework<strong>64</strong>\v2.0.50727\installutil.exe </p>
</blockquote>
<p>will not work (substitute in other framework versions: <code>v1.1.4322</code> (32-bit only, so this issue doesn't arise) and <code>v4.0.30319</code> as desired in the above).</p>
<p>Obviously, as covered in the other answer, one will also need the .NET version number of the <code>installutil</code> you are running to be >= (preferably =) that of the EXE/DLL file you are running the installer of.</p>
<p>Finally, note that <a href="http://blogs.msdn.com/rmbyers/archive/2009/06/8/anycpu-exes-are-usually-more-trouble-then-they-re-worth.aspx" rel="noreferrer">in Visual Studio 2010, the tooling will default to generating x86 binaries</a> (<a href="https://connect.microsoft.com/VisualStudio/feedback/details/455333/platform-target-is-defaulting-to-x86-rather-than-any-cpu" rel="noreferrer">rather than <em>Any CPU</em> as previously</a>).</p>
<p><a href="http://msdn.microsoft.com/en-us/library/system.badimageformatexception.aspx" rel="noreferrer">Complete details of System.BadImageFormatException</a> (saying the only cause is mismatched bittedness is really a gross oversimplification!).</p>
<p>Another reason for a <code>BadImageFormatException</code> under an <strong>x64</strong> installer is that <a href="http://msdn.microsoft.com/en-us/library/kz0ke5xt.aspx" rel="noreferrer">in Visual Studio 2010, the default <code>.vdproj</code> Install Project type generates a 32-bit <code>InstallUtilLib</code> shim, <strong>even on an x64 system</strong></a> (Search for "64-bit managed custom actions throw a System.BadImageFormatException exception" on the page).</p>
|
<p>I had the same issue. I using the standard command for execution. It was calling the X64 ro run against X86 tests. I needed to specify the X86 and not the X64 version of the nunit-runner.</p>
| 41,819
|
<p>I'm currently writing a simple .sh script to parse an Exim log file for strings matching " o' ". Currently, when viewing output.txt, all that is there is a 0 printed on every line(606 lines). I'm guessing my logic is wrong, as awk does not throw any errors.</p>
<p>Here is my code(updated for concatenation and counter issues). Edit: I've adopted some new code from dmckee's answer that I'm now working with over the old code in favor of simplicity.</p>
<pre><code>awk '/o'\''/ {
line = "> ";
for(i = 20; i <= 33; i++) {
line = line " " $i;
}
print line;
}' /var/log/exim/main.log > output.txt
</code></pre>
<p>Any ideas? </p>
<p>EDIT: For clarity's sake, I'm grepping for "o'" in email addresses, because ' is an illegal character in email addresses(and in our databases, appears only with o'-prefixed names).</p>
<p>EDIT 2: As per commentary request, here is a sanitized sample of some desired output:</p>
<pre><code>[xxx.xxx.xxx.xxx] kathleen.o'toole@domain.com <kathleen.o'toole@domain.com> routing defer (-51): retry time not reached
[xxx.xxx.xxx.xxx] julie.o'brien@domain.com <julie.o'brien@domain.com> routing defer (-51): retry time not reached
[xxx.xxx.xxx.xxx] james.o'dell@domain.com <james.o'dell@domain.com> routing defer (-51): retry time not reached
[xxx.xxx.xxx.xxx] daniel_o'leary@domain.com <aniel_o'leary@domain.com> routing defer (-51): retry time not reached
</code></pre>
<p>The reason I'm starting at 20 in my loop is because everything before the 20th field is just standard log information that isn't needed for my purposes here. All I need is everything from the IP and beyond for this solution(the messages for each 550 error are different for each mail server in use out there. I'm compiling a list of common ones)</p>
|
<p>There is no real need for the grep here. Let awk select the matching lines for you (and fixing your concatenation bug as per ΤΖΩΤΖΙΟΥ):</p>
<pre><code>awk '/o'\''/ {
line = "> ";
for(i = 20; i <= 33; i++) {
line = line " " $i;
}
print line;
}' /var/log/exim/main.log > output.txt
</code></pre>
<p>Of course, you end up needing some weird escaping if you do it at the promp like above. It is cleaner in a script...</p>
<hr>
<p>Edit: On the first pass I missed the += problem...</p>
<p>Also assuming that the line you gave above is partial, as it has only 13ish fields (by default fields are white space delimited). </p>
|
<p>"'" is not illegal in local parts. From <a href="http://www.ietf.org/rfc/rfc2821.txt" rel="nofollow noreferrer">RFC2821</a>, section 4.1.2:</p>
<pre><code>Local-part = Dot-string / Quoted-string
Dot-string = Atom *("." Atom)
Atom = 1*atext
</code></pre>
<p>2821 further references <a href="http://www.ietf.org/rfc/rfc2822.txt" rel="nofollow noreferrer">RFC2822</a> for non-locally-defined elements, so:</p>
<pre><code>atext = ALPHA / DIGIT / ; Any character except controls,
"!" / "#" / ; SP, and specials.
"$" / "%" / ; Used for atoms
"&" / "'" /
"*" / "+" /
"-" / "/" /
"=" / "?" /
"^" / "_" /
"`" / "{" /
"|" / "}" /
"~"
</code></pre>
<p>In other words, "'" is a perfectly legal unquoted characted to have in an email localpart. Now, it may not be legal <strong>at your site</strong>, but that's not what you said.</p>
<p>Sorry for not staying directly on topic, but I wanted to correct your assertion.</p>
| 19,283
|
<p>I have an ASP.NET 2.0 [no ajax...yet] web site that will be deployed in compiled form on multiple customer sites. Typically the site will be intranet only. Some customers trust all of their people and don't care about limiting access to the site and/or page functions, others trust no one and want only certain people and/or groups to be able to view certain pages, click certain buttons, et al.</p>
<p>i could do some home-grown solution, possibly drive the access permissions from a database table, but before i go down that road i thought i'd ask in SO: what is a good solution for this situation? preferably one that can be controlled completedly in the web.config file and/or database, since rebuilding the web site is not possible (for the client, and i don't want to have to do it for them over and over). Active Directory integration would be a bonus, but not a requirement (unless that's just easier).</p>
<p>as a starting point, i'm thinking that each page/function point in the site be given an identity and associated with a permission group...</p>
<p>EDIT: web.config authorization section to allow/deny access by role and user is good, but that is only half of the problem - the other half is controlling access to the individual methods (buttons, whatever) on each page. For example, some users can view whatchamacallits while others are allowed to edit, create, delete, or disable/enable them. All of these buttons/links/actions are on the view page...</p>
<p>[ideally i would make the disabled buttons invisible, but that is not important here]</p>
<p>EDIT: some good suggestions so far, but no complete solution yet - still leaning towards a database-driven solution...</p>
<ul>
<li>security permission demand attributes will throw exceptions when buttons are clicked, which is not a friendly thing to do; i'd much rather hide buttons that the user is not allowed to use</li>
<li>the LoginView control is also interesting, but would require replicating most of the page content several times (once for each role) and may not handle the case where a user is in more than one role - i cannot assume that the roles are hierarchical since they will be defined by the customer</li>
</ul>
<p>EDIT: platform is Win2K/XP, Sql Server 2005, ASP.NET 2.0, not using AJAX</p>
|
<p>I prefer to grant access rights to AD groups rather than specific users. I find it's much more flexible.</p>
<p>I don't know much about your application, but you might want to look at the authorization tag in the web.config file:</p>
<pre><code><authorization>
<!--
<deny users="?" />
<allow users="[comma separated list of users]"
roles="[comma separated list of roles]"/>
<deny users="[comma separated list of users]"
roles="[comma separated list of roles]"/>
-->
</authorization>
</code></pre>
<p>You can separate web.config files each directory within your web application, and you can nest directories. Each web.config file can have it's own authorization section. If you put different pages in each directory you can effectively tightly manage security by allowing a specific role in each web.config, and denying everything else. Then you can manage members of each role in active directory. I've found this to be an affective solution because it makes good use of Microsoft's Active Directory and ASP.NET security framework without writing your own custom stuff, and if you use roles, it's possible to offload the management of role membership to someone who doesn't ever have to touch the web.config file they just need to know how to use the AD management console.</p>
|
<p>i think i'm going to have to combine AD authorization with 'features and permissions' tables in the database in order to get the fine-grained control that we need -</p>
<ul>
<li>use the web.config file to allow only authorized users (via AD groups) to visit the web site</li>
<li>make a 'features' table listing each page and feature that can be affected, e.g. page 1 edit button, page 2 delete button, page 3 detail grid, etc.</li>
<li>make a 'permissions' table specfying a feature and an AD group that is allowed to use the feature</li>
<li>alter the site pages to check feature-permissions on page-load (or prerender, as appropriate) to disable/hide forbidden features as appropriate</li>
</ul>
<p>examples: </p>
<ul>
<li>Administrators can use all features of the site</li>
<li>Developers can use all features of the site</li>
<li>Managers can view all pages, but can only add and edit information, no deletions</li>
<li>Supervisors can view summaries for all departments, but see and edit details only for their own department (there is an AD group for each department and dept-supervisor)</li>
<li>Staff can view details only for their department</li>
<li>etc.</li>
</ul>
<p>The final solution reduced the notion of 'feature' to a binary can-use or cannot-use decision, and added a 'permissive/not-permissive' flag to each feature. This allows features that most everyone can use to be defined as 'permissive', and then the permissions table only has to record the groups that are denied permission to use that feature. For a feature defined as not-permissive, by default no one can use the feature and you have to create permission table entries for the groups that are allowed to use the feature. This seems to give a best-of-both-worlds solution in that it reduces the number of permission records required for each feature.</p>
| 21,244
|
<p>Is it possible to have two virtual directories under the same website in IIS but have the virtual directories be using different versions of the .net framework?</p>
<p>For example, under the default website, can I have one virtual directory targeting the 2.0 framework and a second virtual directory targeting the 1.1 framework?</p>
<p>This is for IIS 6, thanks!</p>
|
<p>You are not saying which version of IIS you are using, but for 6.0 and up, just assign them to different application pools, and set the pools to use the right version of .Net.</p>
|
<p>It depends if you mark them as "applications". Application virtual directories can use different framework. Make sure you associate them to different application pools. Never mix two .NET framework versions in one application pool.</p>
<p><em>One important note:</em> if you create a virtual directory as an application, you don't share session state and other application related objects. Also Server.MapPath("~") and other ServerURL related methods an properties will point to the physical directory of the virtual directory and not to the main root.</p>
| 36,089
|
<p>I work on a large Visual C++ (MFC) project in VS.NET 2005.</p>
<p>I have noticed strange behavior in Visual C++ 2005. Often, I will change one line of code in a .CPP file but many .CPP files will compile as a result of this. I have never seen this until VS.NET 2005. Theortically, changing a line of code in a .CPP file should simply require recompilation of that .CPP file and re-linking of the PE file.</p>
<p>What am I not understanding about the build process.</p>
|
<p>I found <a href="http://untidy.net/blog/2006/07/10/vs-always-builds/" rel="nofollow noreferrer">this link</a> helpful when solving a similar problem, was under pressure at the time, I tried a few things and the issue went away, for the life of me I don't know (or can't remember) which - if any - helped.</p>
<p>Hope this helps</p>
|
<p>This is a strange bug in the VS2005 dependency behavior. To find out one suggestion would be to take the following steps:</p>
<ol>
<li><p>Go to <strong>Tools</strong> <strong>-> Options ->
Projects and Solutions -> Build and
Run -> MSBuild Project Build output
Verbosity</strong> and select <strong>Detailed</strong></p></li>
<li><p>Compile your project.</p></li>
</ol>
<p>This will give you a detailed output of the build which <strong>"may"</strong> help you arrive at a solution to your problem.</p>
| 6,706
|
<p>I have an asp.net application directory, and I want to use anonymous authentication in the Directory Sercurity tab.</p>
<p>If I use the pre-Windows 2000 style DOMAIN\USERNAME for the username, everything is fine.</p>
<p>If I use the AD-style (UPN) usename@domain.local, then I get a 401.1 failed login.</p>
<p>I've tried a number of variations, but can't get it to work. If I select the user from the Browse box, the AD name comes up in the box, but the pre-Windows 2000 name is filled-in. Likewise for SQL Server 2005.</p>
<p>It seems that the UPN isn't 'real', is this right? Given that it's not required and doesn't have to be unique; it seems very odd.</p>
<p>Am I correct, in that this is not supported? Would IIS 7 make any difference?</p>
<p>I wish to do this, because the limit of 20 characters for the pre-Windows 2000 username is insufficient for the role-based security I wish to apply for different webservices (the application directories) coming off this website.</p>
|
<p>UPN suffixes should work, althouh there is a bug which occurs when there is a service pack difference between the IIS box and the domain controller. There is a patch for it. This <a href="http://forums.iis.net/p/1149978/1872165.aspx" rel="nofollow noreferrer">link</a> discusses the issue in detail.</p>
|
<p><strong>Update 1:</strong>
I have tried it on Windows 2003 sp 2. In the login "directory security" I have checked the enable anonymous access check box ( and only this box ) and put ausername@mydomain.com and the ausername password. The site is plain asp.net without sql backend.</p>
<p>Are you able to login to the server with the usename@domain.local ?
Can you test this on different domain? It may be some wired dns resolution problem.</p>
<p><strong>Update 0:</strong> </p>
<p>I tested it on iis 6 and the username@domain.com combination works fine on my machine.</p>
<p>About the "realnes" of the names. No name is "real" the actual account is just a GUID. The names are just for convenience. </p>
| 45,559
|
<p>I know this is not programming directly, but it's regarding a development workstation I'm setting up.</p>
<p>I've got a Windows Server 2003 machine that needs to be on two LAN segments at the same time. One of them is a 10.17.x.x LAN and the other is 10.16.x.x</p>
<p>The problem is that I don't want to be using up the bandwidth on the 10.16.x.x network for internet traffic, etc (this network is basically only for internal stuff, though it does have internet access) so I would like the system to use the 10.17.x.x connection for anything that is external to the LAN (and for anything on 10.17.x.x of course, and to only use the 10.16.x.x connection for things that are on <em>that</em> specific LAN.</p>
<p>I've tried looking into the windows "route" command but it's fairly confusing and won't seem to let me delete routes tha tI believe are interfering with what I want it to do. Is there a better way of doing this? Any good software for segmenting your LAN access?</p>
|
<p>I'm no network expert but I have fiddled with the route command a number of times...</p>
<pre><code>route add 0.0.0.0 MASK 0.0.0.0 <address of gateway on 10.17.x.x net>
</code></pre>
<p>Will route all default traffic through the 10.17.x.x gateway, if you find that it still routes through the other interface, you should make sure that the new rule has a lower metric than the existing routes. Do this by adding METRIC 1 for example to the end of the line above.</p>
<p>You could also adjust the metric in the Advanced TCP/IP Settings window of the 10.17.x.x interface, unticking the Automatic Metric checkbox and setting the value to something low, like 1 or 2.</p>
|
<p>If you don't move your network cables around and can assign yourself a static IP address on the 10.16.x.x network, you can refrain from assigning a gateway address on that network. If there is no gateway, internet packets will not be routed on that interface.</p>
<p>If you use DHCP, static record to recognize your MAC address and not provide a gateway IP address.</p>
<p>As for using advanced windows routing, the route you are looking for is the 0.0.0.0 route (default route). The important number is the metric value, which is the cost for the route, where the lower metric tends to be used first. You can set the metric at the interface level directly in the GUI.</p>
<p><a href="https://web.archive.org/web/1/http://articles.techrepublic%2ecom%2ecom/i/tr/cms/contentPics/tcpip-F.gif" rel="nofollow noreferrer">https://web.archive.org/web/1/http://articles.techrepublic%2ecom%2ecom/i/tr/cms/contentPics/tcpip-F.gif</a></p>
<p>I believe if you set the interface metric to a high value on the 10.16.x.x interface, it will not be used as a gateway.</p>
<p>Personally I use the method where I refrain from defining a gateway IP.</p>
| 3,837
|
<p>I know that using continuous integration improves the quality of my code base, and speeds up releases, but what is the best way to convince clients that they want it on their next project?</p>
|
<p>Say exactly what you've said in the question:</p>
<ul>
<li>Speeding up releases = earlier market penetration = more money</li>
<li>Improving code quality = less time fixing bugs = less cost</li>
</ul>
<p>So long as you can help them set it up reasonably quickly and cheaply, I can't see why it would be a problem.</p>
|
<p>You have made some assertions. If you want to sell the idea to you clients you are going to have to answer the questions:</p>
<ul>
<li><p>How does it improve your code quality?</p>
<p>Compilation/build issues are identified on a regular basis. And if used in conjunction with automated integration and unit tests you will be able to identify bugs on a regular basis.</p></li>
<li><p>How does it speed up you releases?</p>
<p>If you automate the build and deployment process you eliminate the downtime required from the development team to ship a new build for testing.</p>
<p>You have a history of successful builds to fall back on if you run out of time and are prepared to ship with incomplete features,</p></li>
</ul>
| 40,892
|
<p>I'm a Mac user and I've decided to learn Emacs. I've <a href="http://steve.yegge.googlepages.com/effective-emacs" rel="noreferrer">read</a> that to reduce hand strain and improve accuracy the <kbd>CTRL</kbd> and <kbd>CAPS LOCK</kbd> keys should be swapped. How do I do this in Leopard?</p>
<p>Also, in Terminal I have to use the <kbd>ESC</kbd> key to invoke meta. Is there any way to get the alt/option key to invoke meta instead?</p>
<p><strong>update:</strong> While the control key is much easier to hit now, the meta key is also used often enough that its position on my MacBook and Apple Keyboard also deserves attention. In fact, I find that the control key is actually easier to hit, so I've remapped my control key to act as a meta key. Does anyone have a better/more standard solution?</p>
|
<p><strong>Swapping CTRL and CAPS LOCK</strong></p>
<ol>
<li>Go into <em>System Preferences</em></li>
<li>Enter the <em>Keyboard & Mouse</em> preference pane</li>
<li>In the <em>Keyboard</em> tab, click <em>Modifier Keys...</em></li>
<li>Swap the actions for <em>Caps Lock</em> and <em>Control</em>.</li>
</ol>
<p><img src="https://i.stack.imgur.com/G8MFP.png" alt="alt text"></p>
<p><strong>Using ALT/OPTION as META</strong></p>
<ol>
<li>In the menu bar, click <em>Terminal</em></li>
<li>Click <em>Preferences...</em></li>
<li>Under the <em>Settings</em> tab, go to the <em>Keyboard</em> tab</li>
<li>Check the box labeled <em>Use option as meta key</em></li>
</ol>
<p><img src="https://i.stack.imgur.com/F7vfP.png" alt="alt text"></p>
<p><strong>That's it! You should be well on your way to becoming an Emacs master!</strong></p>
|
<p>I've created a fairly comprehensive set of bindings <a href="https://github.com/cohenaarone/mac_osx_emacs_keybindings" rel="nofollow noreferrer">here</a> for use <em>outside</em> of Terminal.</p>
<p>Personally, I can't use the mac laptop keyboard due to the absence of the right control key. </p>
<p>Instead, I have been using the <a href="https://rads.stackoverflow.com/amzn/click/com/B000A6PPOK" rel="nofollow noreferrer" rel="nofollow noreferrer">Microsoft Natural Ergonomic Keyboard 4000</a> for over 7 years: it's got really fat, well-positioned Ctrl and Alt keys, and after <a href="http://www.microsoft.com/hardware/en-us/p/natural-ergonomic-keyboard-4000#support" rel="nofollow noreferrer">downloading its drivers</a> the "Start" and "Application" keys are trivially remapped to the Mac Cmd key, which is also fat and easily depressed.</p>
<p>To avoid emacs ergonomic concerns I've trained myself to use Ctrl, Alt, and Cmd the same way we use Shift - depressing them with the hand opposite the one typing the actual key. (That is, I just leave Caps Lock as is.)</p>
| 19,697
|
<p>Can we have a SQL query which will basically help in viewing table and index sizes in SQl Server.</p>
<p>How SQL server maintains memory usage for tables/indexes?</p>
|
<p>The <code>exec sp_spaceused</code> without parameter shows the summary for the whole database. The foreachtable solution generates one result set per table - which SSMS might not be able to handle if you have too many tables.</p>
<p>I created a <a href="http://devio.wordpress.com/2007/10/11/how-much-space-do-my-sql-server-tables-use/" rel="noreferrer">script</a> which collects the table infos via <code>sp_spaceused</code> and displays a summary in a single record set, sorted by size.</p>
<pre><code>create table #t
(
name nvarchar(128),
rows varchar(50),
reserved varchar(50),
data varchar(50),
index_size varchar(50),
unused varchar(50)
)
declare @id nvarchar(128)
declare c cursor for
select '[' + sc.name + '].[' + s.name + ']' FROM sysobjects s INNER JOIN sys.schemas sc ON s.uid = sc.schema_id where s.xtype='U'
open c
fetch c into @id
while @@fetch_status = 0 begin
insert into #t
exec sp_spaceused @id
fetch c into @id
end
close c
deallocate c
select * from #t
order by convert(int, substring(data, 1, len(data)-3)) desc
drop table #t
</code></pre>
|
<p>There is an extended stored procedure <code>sp_spaceused</code> that gets this information out. It's fairly convoluted to do it from the data dictionary, but <a href="http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=61762" rel="nofollow noreferrer">This link</a> fans out to a script that does it. <a href="https://stackoverflow.com/questions/177550/estimate-sql-server-index-sizes#177585">This stackoverflow question</a> has some fan-out to information on the underlying data structures that you can use to construct estimates of table and index sizes for capcity planning.</p>
| 40,912
|
<p>I'm really interested to hear what you think about Model-driven Software Development for Java and/or .NET.</p>
<p>Does it save time? Does it improve quality?</p>
|
<p>I am using MDSD in a project with IBM Rational Rhapsody for C++. The model is pretty close to UML, so there we do not really have a Domain-Specific-Language. But still I would claim to use MDSD. From my experience, there are many benefits with MDSD:</p>
<p>a) Using MDSD helps to bring a SW architecture to a sophisticated level. You always work on a very abstract level, thinking about the big picture. Cowboy coding software usually lacks a good architecture, because a developer is stuck in details. With MDSD, I see a tendency in my work, to solve problems with adequate sized classes, nice patterns, or simply better code.</p>
<p>b) Big picture documentation of the SW tends to be better with MDSD. Of course, there are tools that automatically generate a class diagram out of your code. But these diagrams consists of 1000 classes and you do not see the aspect of interest. With MDSD, you specifically draw one aspect of the system, and the very same diagram is also used to generate a part of your code.</p>
<p>c) Modelling helps to deal with an inherent system complexity. I would say, some systems are just too complex to be built without support from computer-aided design. Nobody would design a CPU without the help of huge SW tools. Use SW to help you write even more complex SW.</p>
<p>d) Using MDSD helps to adhere to coding style guidelines. There is no better way to get coherent code style than letting the code be generated by a rule set.</p>
<p>There are of course also some downsides of MDSD:
d) If you have a model, you want every line of code to come from that model. And it may be difficult to include external libraries to a project. So either you live with the fact, that your system is based on external components or you reinvent the wheel to get it into your model.</p>
<p>e) Modelling tools might suffer from problems using versioning tools. Source code is usually simpler to merge than a model diagram. This forces a team to move from the copy-edit-merge to a lock-edit-merge workflow.</p>
|
<p>MDA usually make difficult to integrate the business rules inside the server side layer, as the model view mapping is handled by generated code and functional hooks are provided as event responders. </p>
<p>Still I've not seen a MDA tool as powerful as Forté (or UDS, now dead) + Express were. I imagine that a MDA with the Forté capabilities plus better pattern to achieve an independent service layer (as ActiveRecord, or EntityTransactionManager patterns) would be a killer app for whatever platform.</p>
<p>The problem with actual application aiming at the three tiered MDA approach is that those are terribly difficult to set up and adapt to specific requirements. Just think of ABAP and SAP rates</p>
| 9,626
|
<p>Is there a better way I can fill out a spread sheet on a web server (using asp.net) than using interop?</p>
<p>EDIT: I wasn't very clear as to what I require:</p>
<p>I have a template that I must use that is provided by our customer. In the template are some macros that are password protected that I do not have access to so I cannot generate the excel file. I am stuck updating a 2003 excel file.</p>
|
<p>Office 2007 documents (Word, PowerPoint and Excel) are based on the OpenXML Formats. They are just zip files with a bunch of XML and binary parts (think files) inside. You can open them with the Packaging API (System.IO.Packaging in WindowsBase.dll) and manipulate them with any of the XML classes in the Framework.</p>
<p>Check out OpenXMLDeveloper.org for details.</p>
|
<p>YES.</p>
<p>If you have an existing spread sheet, and you want to add data to it based on user input where either one sheet is shared by every user or even one user periodically updates his own sheet, then you are going about it the wrong way. Excel can't handle concurrency or the interop load in a web situation. The only place you need interop is when you have to open existing spreadsheets that are out of your control.</p>
<p>Instead, save the user input to a real database and only generate an excel document as needed. See the question linked below for help generating the excel document: there are several options that require no interop at all, including html tables, xml, openxml csv, or 3rd party component, and most of those support formatting, formulas, etc.<br>
<a href="https://stackoverflow.com/questions/150339/generating-an-excel-file-in-aspnet">Generating an Excel file in ASP.NET</a></p>
<p><strong>Update</strong><br>
If you need to execute macros, then you likely need excel interop. However, this just <em>won't work well</em> in web site. I suggest you go back to the customer and ask them to be more open with you about the requirements for the sheet.</p>
| 33,438
|
<p>I knew stackoverflow would help me for other than know what is the "favorite programming cartoon" :P </p>
<p>This was the accepted answer by:
<a href="https://stackoverflow.com/questions/185327/oracle-joins-left-outer-right-etc-s#185439">Bill Karwin</a></p>
<p>Thanks to all for the help ( I would like to double vote you all ) </p>
<p>My query ended up like this ( this is the real one ) </p>
<pre><code>SELECT
accepted.folio,
COALESCE( inprog.activityin, accepted.activityin ) as activityin,
inprog.participantin,
accepted.completiondate
FROM performance accepted
LEFT OUTER JOIN performance inprog
ON( accepted.folio = inprog.folio
AND inprog.ACTIVITYIN
IN ( 4, 435 ) -- both are ids for inprogress
AND inprog.PARTICIPANTIN != 1 ) -- Ignore the "bot" participant
LEFT OUTER JOIN performance closed
ON( accepted.folio = closed.folio
AND closed.ACTIVITYIN IN ( 10,436, 4, 430 ) ) -- all these are closed or cancelled
WHERE accepted.ACTIVITYIN IN ( 3, 429 ) --- both are id for new
AND accepted.folio IS NOT NULL
AND closed.folio IS NULL;
</code></pre>
<p>Now I just have to join with the other tables for a human readable report.</p>
<p><hr>
<strong>ORIGINAL POST</strong></p>
<p>Hello. </p>
<p>I'm struggling for about 6 hrs. now with a DB query ( my long time nemesis ) </p>
<p>I have a data table with some fields like:</p>
<pre><code>table performance(
identifier varchar,
activity number,
participant number,
closedate date,
)
</code></pre>
<p>It is used to keep track of the history of ticket</p>
<p><strong>Identifier</strong>: is a customer id like ( NAF0000001 ) </p>
<p><strong>activity</strong>: is a fk of where the ticket is ( new, in_progress, rejected, closed, etc )</p>
<p><strong>participant</strong>: is a fk of who is attending at that point the ticket</p>
<p><strong>closedate</strong>: is the date when that activity finished.</p>
<p><strong>EDIT:</strong> I should have said "completiondate" rather than closedate. This is the date when the activity was completed, not necessary when the ticket was closed.</p>
<p>For instance a typical history may be like this:</p>
<pre>
identifier|activity|participant|closedate
-------------------------------------------
NA00000001| 1| 1|2008/10/08 15:00|
-------------------------------------------
NA00000001| 2| 2|2008/10/08 15:20|
-------------------------------------------
NA00000001| 3| 2|2008/10/08 15:40|
-------------------------------------------
NA00000001| 4| 4|2008/10/08 17:05|
-------------------------------------------
</pre>
<p>And participant 1=jonh, 2=scott, 3=mike, 4=rob</p>
<p>and activties 1=new, 2=inprogress, 3=waitingforapproval, 4=closed</p>
<p>etc. And tens of other irrelevant info.</p>
<p>Well my problem is the following.</p>
<p>I have managed to create a query where I can know when a ticket was opened and closed</p>
<p>it is like this:</p>
<pre><code> select
a.identifier,
a.participant,
a.closedate as start,
b.closedate as finish
from
performance a,
performance b
where
a.activity = 1 -- new
and b.activity = 4 -- closed
and a.identifier = b.identifier
</code></pre>
<p>But I can't know what tickets are <strong>not</strong> closed and who is attending them.</p>
<p>So far I have something like this:</p>
<pre><code> select
a.identifier,
a.participant,
a.closedate as start
from
performance a
where
a.activity = 1 -- new
and a.identifier not in ( select identifier from performance where activity = 4 ) --closed
</code></pre>
<p>That is give me all the ones who have an start ( new = 1 ) but are not closed ( closed = 4 ) </p>
<p>But the big problem here is that it prints the participant who opened the ticket, but I need the participant who is attending it. So I add the "inprogress" activity to the query.</p>
<pre><code> select
a.identifier,
a.participant,
a.closedate as start
from
performance a,
performance b
where
a.activity = 1 -- new
and a.identifier not in ( select identifier from performance where activity = 4 ) --closed
and b.identifier = a.identifier
and b.activity = 2 -- inprogress..
</code></pre>
<p>But not all the rows that are in "new" are "inprogress" and with that query I drop all of them.</p>
<p>What I need is to show all the "inprogress" participant and if the ticket is not "inprogress", it will show as empty.</p>
<p>Somthing like</p>
<pre>
identifier|activity|participant|closedate
-------------------------------------------
NA00000002| 1| |2008/10/08 15:00|
-------------------------------------------
NA00000003| 1| |2008/10/08 15:20|
-------------------------------------------
NA00000004| 1| |2008/10/08 15:40|
-------------------------------------------
NA00000005| 2| 4|2008/10/08 15:40|
-------------------------------------------
NA00000006| 2| 4|2008/10/08 15:40|
</pre>
<p>In this case</p>
<p>NA002, NA003 and NA004 are in "new", so no participant is shown</p>
<p>While</p>
<p>NA005 and NA006 are being "inprgress (act = 2 )" and they are being attended by rob ( participant 4 ) </p>
<p>So I remember there was this thing called left outer join or something like that but I never ever understand it. What I would like to know is how can I fetch the identifiers that are "inprogress" and "new" and that are not closed.</p>
<p>Probably taking a little rest would help me to clear my mind. If anyone knows how to do it I'll appreciate it.</p>
<p>By the way I've tried:</p>
<pre><code> select
a.identifier,
a.participant,
a.closedate as start
from
performance a
left outer join
performance b
on
b.identifier = a.identifier
where
a.activity = 1 -- new
and a.identifier not in ( select identifier from performance where activity = 4 ) --closed
and b.activity = 2 -- inprogress..
</code></pre>
<p>But gives me the same result as the previous ( drop the only in "new" records )</p>
|
<p>Try something like this (I haven't tested it):</p>
<pre><code>SELECT p_new.identifier, COALESCE(p_inprog.activity, p_new.activity) AS activity,
p_inprog.participant, COALESCE(p_inprog.closedate, p_new.closedate) AS closedate
FROM performance p_new
LEFT OUTER JOIN performance p_inprog
ON (p_new.identifier = p_inprog.identifier AND p_inprog.activity = 2)
LEFT OUTER JOIN performance p_closed
ON (p_new.identifier = p_closed.identifier AND p_closed.activity = 4)
WHERE p_new.activity = 1
AND p_closed.identifier IS NULL;
</code></pre>
<p>I think people believe outer joins are harder than they really are. For example:</p>
<pre><code>A LEFT OUTER JOIN B ON (...condition...)
</code></pre>
<p>This returns all rows from A, whether or not there are any matching rows in B. If no rows in B match, treat all columns B.* as NULL in the result set for that row of A. The join condition can be an expression that the row in B must satisfy, or else it isn't included in the join. So, more rows in A will be solo.</p>
|
<p>Firstly, you may have a design issue if you can have a customer with multiple tickets open at the same time. You should ideally have a ticket_id, and then you can perform Andy's query by using ticket_id instead of identifier.</p>
| 22,412
|
<p>I'm looking for an alternative to <a href="http://www.jsfmatrix.net/" rel="nofollow noreferrer">www.jsfmatrix.net</a> to get a better idea of what JSF libraries are out there and to avoid having to write my own grid/table components. Or are these 27 the best the world has to offer (really only 3 are worth their salt.)</p>
|
<p>have you looked at RichFaces? It comes with a lot really cool rich UI stuff. </p>
|
<p>I'll second RichFaces, but also point out IceFaces (which isn't free, but is also very nice).</p>
| 12,912
|
<p>I have created a reference to an IIS hosted WCF service in my ASP.NET website project on my local workstation through the "Add Service Reference" option in Visual Studio 2008. I was able to execute the service from my local workstation.</p>
<p>When I move the ASP.NET web site using the "Copy Web Site" feature in Visual Studio 2008 to the development server and browse to the page consuming the service, I get the following error:</p>
<blockquote>
<p>Reference.svcmap: Specified argument
was out of the range of valid values.</p>
</blockquote>
<p>Has anyone experienced this same error and know how to resolve it?</p>
<p><b>EDIT:</b> My development server is Win2k3 with IIS 6</p>
|
<p>@Sixto Saez: I was able to use the following resource similar to the one you provided to generate a proxy class using the ServiceModel Metadata Utility Tool (svcutil.exe).</p>
<p>Here is the exact command line:</p>
<pre><code>svcutil /t:code http://<service_url> /out:<file_name>.cs /config:<file_name>.config
</code></pre>
<p><a href="http://chakkaradeep.wordpress.com/2008/08/07/generating-wcf-proxy-using-svcutilexe/" rel="nofollow noreferrer">Here</a> is the reference I found that suggested using the method.</p>
<p>Also, I was able to consume the service by creating a reference using the Visual Studio 2008 "Add Web Reference" command. It generates code based on .NET Framework 2.0 Web Services technology.</p>
|
<p>Unforunately, the WCF service web site and I can not use the svcutil solution (Unless you know of a way how...). Do you deploy you service or your web site with the service reference using Visual Studio 2008 publish web site feature?</p>
| 35,301
|
<p>You can embed the <a href="http://ipython.scipy.org/" rel="noreferrer">IPython</a> shell inside of your application so that it launches the shell in the foreground. Is there a way to embed a telnet server in a python app so that you can telnet to a certain port and launch a remote IPython shell? </p>
<p>Any tips for redirecting the input/output streams for IPython or how to hook it up to a telnet server library or recommendations for other libraries that could be used to implement this are much appreciated. </p>
|
<p>Python includes a <a href="http://www.python.org/doc/lib/module-telnetlib.html" rel="nofollow noreferrer">telnet client</a>, but not a telnet server. You can implement a telnet server using <a href="http://twistedmatrix.com" rel="nofollow noreferrer">Twisted</a>. <a href="http://twistedmatrix.com/pipermail/twisted-python/2004-August/008335.html" rel="nofollow noreferrer">Here's an example</a>. As for hooking these things together, that's up to you.</p>
|
<p>I think you should base your server class on the <a href="http://www.python.org/doc/lib/module-SocketServer.html" rel="nofollow noreferrer"><code>SocketServer</code></a> class from the standard library. You'll need to write a <code>RequestHandler</code> to read and echo input but a lot of the heavy lifting is already done for you.</p>
<p>You can use the <a href="http://docs.python.org/lib/node632.html" rel="nofollow noreferrer"><code>ThreadingMixIn</code></a> to make the server multi-threaded very easily. </p>
| 7,054
|
<p>Does a free .NET library exist with which I can upload a file to a SFTP (SSH FTP) server, which throws exceptions on problems with the upload and allows the monitoring of its progress?</p>
|
<p>Maybe you can script/control <a href="http://winscp.net/" rel="noreferrer">winscp</a>?</p>
<p><strong>Update:</strong> winscp now has <a href="https://winscp.net/eng/docs/library" rel="noreferrer" title="a .NET library">a .NET library</a> available as a <a href="https://winscp.net/eng/docs/library_install#nuget" rel="noreferrer" title="nuget pacakge">nuget package</a> that supports SFTP, SCP, and FTPS</p>
|
<p>Unfortunately, it's not in the .NET Framework itself. My wish is that you could integrate with FileZilla, but I don't think it exposes an interface. They do have scripting I think, but it won't be as clean obviously.</p>
<p>I've used CuteFTP in a project which does SFTP. It exposes a COM component which I created a .NET wrapper around. The catch, you'll find, is permissions. It runs beautifully under the Windows credentials which installed CuteFTP, but running under other credentials requires permissions to be set in DCOM.</p>
| 11,196
|
<p>I have a Rails 2.0.2 application running with a postgresql db. The machine will receive data on a TCP port. I already have coded a working ruby multithreaded tcp server to receive the requests, but I need this code to run alongside my Rails app.</p>
<p>So I guess I need to know how to span a new process inside Rails, or how to create a worker thread that will run my threaded tcp server loop. My ruby tcp server could have access to ActiveRecord, but it's not necessary (I can always create an http request, posting the received data to the original Rails server)</p>
|
<p>Why complicate things? Just run the applications -- your TCP server and the Rails application -- side by side.</p>
<p>Either pull the model tier (and ActiveRecord) into your TCP server (svn::externals or Piston might work well for that) and let the communication between the two applications happen through the database, or let the Rails application be the "master" and communicate with it via HTTP as you suggest.</p>
<p>To turn a Ruby application into a Windows service, see the <code>win32-service</code> gem available from the <code>win32utils</code> project: <a href="http://rubyforge.org/projects/win32utils/" rel="nofollow noreferrer">http://rubyforge.org/projects/win32utils/</a></p>
|
<p>I need the tcp server to run as a service on a Windows 2003 server. I use the mongrel_service to load Rails as a service, and I do not know of a way to do the same for pure ruby code. If I could get my tcp server started when the computer boots, I will look into your solution (which seems pretty good nevertheless). </p>
| 15,790
|
<p>At work we write a small to moderate amount of scripts to aid us in normal development. We have some people that are more comfortable in python, some in perl, some in php, etc...</p>
<p>Sometimes I think it is best to let people work in a language they are most comfortable with. This can mean that sometimes people can do a better job on a script (as they know more tricks in one language). It can also lead to less development time per script.</p>
<p>Other times I think that we would benefit the most from standardizing so that there might be more shared libraries and so that we don't get into the situation of "I can't work on that script because I don't know python".</p>
<p>Do you think that we should standardize or let people choose for each script they write?</p>
|
<p>I would be inclined to let people choose, <em>and</em> hire people who are comfortable at learning new things. Gaining basic fluency with almost any language should be easy enough for a good developer. And for small scripts where the original author isn't far away, it's even easier.</p>
<p>The second part of the above is the hard part, of course. But you'll end up with a more flexible, more knowledgeable team.</p>
|
<p>No. </p>
<p>Your dev environment is hopefully a living entity that changes and is cultivated. New abilities (scripting languages) should be able to be accommodated, and older places that haven't been visited for years will someday get obviated by tools, or revisited from time to time and an evaluation will take place. Hopefully the dev scripts are a minor amount of development and automation. Chances are the team will drift towards a set of standards (ant, python, etc).</p>
| 28,167
|
<p>When do you start to consider a code base to be getting too large and unwieldy? </p>
|
<p>When it's over 100 lines. Joke. This is probably the hardest question to answer, because it's very individual.</p>
<p>But if you structure the application well and use different layers for i.e. interfaces, data, services and front-end you will automaticly get a nice "base"-structure. Then you can dividie each layer into different classes and then inside the classes you point out the appropriet methods for the class.</p>
<p>However, there's not an "x amount of lines per method is bad" but think of it more like this, if there is possibility of replication, split it from the current peice and make it re-usable.</p>
<p>Re-using code is the basics of all good structure.</p>
<p>And splitting up into different layers will help the base to become more and more flexible and modular.</p>
|
<p>If over years of development different people code change requests and bug fixes you will sooner or later get parts of code with duplicated functionality, very similar classes, some spaghetti etc.
This is mostly due to the fact that a fix is needed fast and the "new guy" doesn't know the code base. So he happily codes away something which is already there.</p>
<p>But if you have automatic checks in place checking the style, unit test code coverage and similar you can avoid some of it.</p>
| 43,813
|
<p>I'm trying to learn scheme via SICP. Exercise 1.3 reads as follow: Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers. Please comment on how I can improve my solution.</p>
<pre><code>(define (big x y)
(if (> x y) x y))
(define (p a b c)
(cond ((> a b) (+ (square a) (square (big b c))))
(else (+ (square b) (square (big a c))))))
</code></pre>
|
<p>Using only the concepts presented at that point of the book, I would do it:</p>
<pre><code>(define (square x) (* x x))
(define (sum-of-squares x y) (+ (square x) (square y)))
(define (min x y) (if (< x y) x y))
(define (max x y) (if (> x y) x y))
(define (sum-squares-2-biggest x y z)
(sum-of-squares (max x y) (max z (min x y))))
</code></pre>
|
<p>I've had a go:</p>
<pre><code>(define (procedure a b c)
(let ((y (sort (list a b c) >)) (square (lambda (x) (* x x))))
(+ (square (first y)) (square(second y)))))
</code></pre>
| 19,544
|
<p>I'm trying to locate an open source business rules engine that has a decent interface for building the rules.</p>
<p>OR at least one that works well on the .Net platform and has been updated sometime in the past 12 months. </p>
<p>Thanks,</p>
|
<p>NxBRE is one option. </p>
<p><a href="http://sourceforge.net/projects/nxbre/#item3rd-5" rel="noreferrer">http://sourceforge.net/projects/nxbre/#item3rd-5</a></p>
|
<p>I'm going to throw one more piece of software I ran across: <a href="http://ncalc.codeplex.com/" rel="nofollow">ncalc</a>.</p>
<p>It's not exactly a "rules" engine; but it does do dynamic calculations where you can give it the expression to evaluate and all of the variables necessary. This was pretty much exactly all I needed for the app I was working on.</p>
<p>For a simple engine it works just fine. As far as an interface, it wasn't that complicated to build a few pages to let people type in the expressions.</p>
<p>For more complicated things, NxBRE is a better option; as @Kevin Dente answered above.</p>
| 4,187
|
<p>I am fascinated by the performance of applications such as "Rollercoaster Tycoon" and "The Sims" and FPS games. I would like to know more about the basic application architecture. (Not so concerned with the UI - I assume MVC/MVP piriciples apply here. Nor am I concerned with the math and physics at this point.)</p>
<p>My main question deals with the tens or hundreds of individual objects in the simulation (people, vehicles, items, etc.) that all move, make decisions, and raise & respond to events - seeming all a the same time, and how they are designed for such good performance.</p>
<p><strong>Q: Primarily, are these objects being processed in a giant loop, one at a time - or is each object processing in it's own thread</strong>? How many threads are practical in a simulation like this? (Ballpark figure of course, 10, 100, 1000)</p>
<p>I'm not looking to write a game, I just want the design theory because I'm wondering if such design can apply to other applications where several decisions are being made seemingly at the same time.</p>
|
<p>There are two basic ways of doing this kind of simulation <a href="http://en.wikipedia.org/wiki/Agent_based_model" rel="noreferrer">Agent Based</a> and <a href="http://en.wikipedia.org/wiki/System_dynamics" rel="noreferrer">System Dynamics</a>. In and agent based simulation each entity in the game would be represented by an instance of a class with properties and behaviors, all the interactions between the entities would have to be explicitly defined and when you want these entities to interact a function gets called the properties of the interacting entities gets changed. </p>
<p>System Dynamics is completely different, it only deals with sums and totals, there is no representation of a single entity in the system. The easiest example of that is the Predator and Prey model.</p>
<p>Both of these have advantages and disadvantages, the System Dynamics approach scales better to large number of entitities while keeping runtime short. While there are multiple formulas that you have to calculate, the time to calculate is independent of the values in the formula. But there is no way to look at an individual entity in this approach. The Agent based approach lets you put entities in specific locations and lets you interact with specific entities in your simulation. </p>
<p>FSMs and <a href="http://en.wikipedia.org/wiki/Category:Cellular_automata" rel="noreferrer">Celular automata</a> are other ways in how to simulate systems in a game. E.g. in the agent based approach you might model the behavior of one agent with a FSM. <a href="http://www.donhopkins.com/drupal/node/141" rel="noreferrer">Simcity</a> used Celular automata to do some of the simulation work.</p>
<p>In general you will probably not have one big huge model that does everything but multiple systems that do specific tasks, some of these will not need to be updated very often e.g. something that determines the weather, others might need constant updates. Even if you put them in separate threads you will want to pause or start them when you need them. You might want to split work over multiple frames, e.g. calculate only updates on a certain number of agents.</p>
|
<p>@Cody Brocious</p>
<p>This <a href="http://www.codeproject.com/KB/linq/linq-to-life.aspx" rel="nofollow noreferrer">CodeProject</a> uses Linq to demonstrate this practice. (Linq to Life)</p>
| 16,662
|
<p>I have a web service class that the rest of the framework depends on to grab its data, but the web service class needs to have different method attributes depending on what environment it's in. For instance...</p>
<pre><code>[SoapDocumentMethodAttribute("https://example",...)]
public string Test()
{
//doSomething
}
</code></pre>
<p>See that "<a href="https://example" rel="nofollow noreferrer">https://example</a>"? That needs to change depending on the environment. AFAIK you can't make that string dynamic for runtime, it has to be compiled that way. So I'm trying to get it so that I have multiple CS files for this web service that have the different attribute URLs hardcoded in them, and MSBuild swaps them on precompile. So I'd have a base "Service.cs" for testing, "Service.cs.production" for the production environment, and so on.</p>
<ul>
<li>Is this the best way to do this, or am I missing something where I can have one CS that handles the environment on its own?</li>
<li>To preserve having the same class name and IntelliSense not thinking things are ambiguous, I'm mucking up the file extensions ("Service.cs" versus "Service.cs.production"). Is that the only way to do it?</li>
<li>Considering all the above is OK, and I'm compiling against a "Production" configuration, can it compile Service.cs.production <strong>instead of</strong> Service.cs and everything goes hunky-dorey?</li>
</ul>
<p>Thanks!</p>
|
<p>Could you use conditional comments?</p>
<pre><code>#if TESTING
[SoapDocumentMethodAttribute(something)]
#else
[SoapDocumentMethodAttribute(someotherthing)]
#endif
</code></pre>
<p>For your test configuration you would define the constant:</p>
<pre><code><DefineConstants>TESTING</DefineConstants>
</code></pre>
|
<p>In conjunction with Defining constants, and using #if directives,</p>
<p>You can also write a custom build task -> Target BeforeBuild, then using the Engine.GlobalEngine.GetLoadedProject("projpath") in to Project object.</p>
<p>Now you can manipulate the properties on the Project object however you want for different environments.</p>
<p>Consider adding Platforms in the configuration, for different environments if you want to.</p>
<p>This may not be the answer you are looking for, but something to consider when you want to fork build based on project environments.</p>
| 37,871
|
<p>The company I work for writes a lot smallish Perl and Bash scripts to massage data into something usable for our software. These scripts, like any code, can change. I provided them CVS because of the file versioning rather than repository versioning. Anyway, I am thinking out a deploy tool to get the scripts from development to production. The production server will have it's own simple versioning system in that if one of the scripts' md5 sum does not match the one in a database it will not run the script and email the appropriate parties. </p>
<p>I want to force the programmers to deploy the most current CVS version of the script. If it is not the most current it should die with a message telling them they have to check in their version first. I realize there might be cases where you need to deploy an old file. Those would be exceptions and could be handled as such.</p>
<p>What's the best to do this? Is it just as simple as doing a 'cvs diff' ? </p>
|
<p>if you going to write some kind of distribution script it should be relatively simple </p>
<p>1) The script should be committed in your cvs repository </p>
<p>2) I advice to call the script from your makefile (or any build system you use)
something like this </p>
<pre><code>make dist
</code></pre>
<p>and the dist rule will call your script.<br>
3) script will perform </p>
<pre><code> cvs up -An
</code></pre>
<p>and analyze the output to look for M or C or A or R status
by redirecting the output to grep for example. </p>
<pre><code>grep -c ^[MCAR]
</code></pre>
<p>if count > 0 you got a problem. </p>
<p>4) if one of above found fail the build script </p>
<p>5) if not create the tar or any other form of distribution you are using</p>
<p>To deploy older version you can make an -A as a parameter by default set to -A and overridden for example by shell variable to be for example -r tag-3.14.4 . </p>
|
<p>I worked on an internal tool that did deployments.
It was designed for the enterprise (and to meet SOX regulations), and so it relied on approvals to deploy code.</p>
<p>Because of this, we deployed the version of code the developer specified in the request, not the latest version. The reason is that a developer may need to make changes, place into test, meanwhile other changes take place. These newer changes have not gone through the test (QA) phases, but the developers original version has, so we would deploy that version.</p>
<p>All that to say, I would design it in such a way that a version number could be specified, and if no version number then push the latest.</p>
| 32,469
|
<p>I really love the way Ajax makes a web app perform more like a desktop app, but I'm worried about the hits on a high volume site. I'm developing a database app right now that's intranet based, that no more then 2-4 people are going to be accessing at one time. I'm Ajaxing the hell out of it, but it got me to wondering, how much Ajax is too much?</p>
<p>At what point does the volume of hits, outweigh the benefits seen by using Ajax? It doesn't really seem like it would, versus a whole page refresh, since you are, in theory, only updating the parts that need updating. </p>
<p>I'm curious if any of you have used Ajax on high volume sites and in what capacity did you use it? Does it create scaling issues?</p>
|
<p>On my current project, we do use Ajax and we have had scaling problems. Since my current project is a J2EE site that does timekeeping for the employees of a large urban city, we've found that it's best if the browser side can cache data that won't change for the duration of a user session. Fortunately we're moving to a model where we have a single admin process the timekeeping for as many employees as possible. This would be akin to how an ERP application might work (or an email application). Consequently our business need is that the browser-side can hold a lot of data, but we don't expect the volume of hits to be a serious problem. So we've kept an XML data island on the browser-side. In addition, we load data only on an as-needed basis.</p>
<p>I highly recommend the book <em>Ajax Design Patterns</em> or their <a href="http://ajaxpatterns.org/" rel="nofollow noreferrer">site</a>.</p>
|
<p>The most common scaling issue of ajax apps is when they are to set up to check back with the server to see if the content got updated in the meantime without the need for user actively requesting it. 5 clients checking every 10 seconds is not 5000 clients checking every 10 sec.</p>
| 42,741
|
<p>The terms are used all over the place, and I don't know of crisp definitions. I'm pretty sure I know what a data mart is. And I've created reporting cubes with tools like Business Objects and Cognos.</p>
<p>I've also had folks tell me that a datamart is more than just a collection of cubes.</p>
<p>I've also had people tell me that a datamart is a reporting cube, nothing more.</p>
<p>What are the distinctions you understand?</p>
|
<p><a href="http://en.wikipedia.org/wiki/Olap_cube" rel="nofollow noreferrer">Cube</a> can (and arguably should) mean something quite specific - OLAP artifacts presented through an <a href="http://en.wikipedia.org/wiki/MOLAP" rel="nofollow noreferrer">OLAP server</a> such as <a href="https://learn.microsoft.com/en-us/sql/analysis-services/analysis-services?view=sql-server-2017" rel="nofollow noreferrer">MS Analysis Services</a> or Oracle (nee Hyperion) <a href="https://www.oracle.com/technetwork/middleware/essbase/overview/index.html" rel="nofollow noreferrer">Essbase</a>. However, it also gets used much more loosely. OLAP cubes of this sort use cube-aware query tools which use a different API to a standard relational database. Typically OLAP servers maintain their own optimised data structures (known as <a href="http://en.wikipedia.org/wiki/MOLAP" rel="nofollow noreferrer">MOLAP</a>), although they can be implemented as a front-end to a relational data source (known as <a href="http://en.wikipedia.org/wiki/ROLAP" rel="nofollow noreferrer">ROLAP</a>) or in various hybrid modes (known as <a href="http://en.wikipedia.org/wiki/HOLAP" rel="nofollow noreferrer">HOLAP</a>)</p>
<p>I try to be specific and use 'cube' specifically to refer to cubes on OLAP servers such as SSAS. </p>
<p><a href="https://www.sap.com/products/bi-platform.html" rel="nofollow noreferrer">Business Objects</a> works by querying data through one or more sources (which could be relational databases, OLAP cubes, or flat files) and creating an in-memory data structure called a <a href="http://business-objects-xi.blogspot.com/2013/10/what-is-micro-cube-in-sap-business.html" rel="nofollow noreferrer">MicroCube</a> which it uses to support interactive slice-and-dice activities. Analysis Services and MSQuery can make a <a href="https://support.office.com/en-us/article/work-with-offline-cube-files-a1014690-efb7-480d-b717-308a39063235" rel="nofollow noreferrer">cube (.cub) file</a> which can be opened by the AS client software or Excel and sliced-and-diced in a similar manner. IIRC Recent versions of Business Objects can also open .cub files. </p>
<p>To be pedantic I think Business Objects sits in a 'semi-structured reporting' space somewhere between a true OLAP system such as ProClarity and ad-hoc reporting tool such as <a href="http://msdn.microsoft.com/en-us/library/ms155933.aspx" rel="nofollow noreferrer">Report Builder</a>, <a href="https://en.wikipedia.org/wiki/Oracle_Discoverer" rel="nofollow noreferrer">Oracle Discoverer</a> or <a href="https://en.wikipedia.org/wiki/Brio_Technology" rel="nofollow noreferrer">Brio</a>. Round trips to the Query Panel make it somewhat clunky as a pure stream-of-thought OLAP tool but it does offer a level of interactivity that traditional reports don't. I see the sweet spot of Business Objects as sitting in two places: ad-hoc reporting by staff not necessarily familiar with SQL and provding a scheduled report delivered in an interactive format that allows some drill-down into the data.</p>
<p><a href="http://en.wikipedia.org/wiki/Datamart" rel="nofollow noreferrer">'Data Mart'</a> is also a fairly loosely used term and can mean any user-facing data access medium for a data warehouse system. The definition may or may not include the reporting tools and metadata layers, reporting layer tables or other items such as Cubes or other analytic systems.</p>
<p>I tend to think of a data mart as the database from which the reporting is done, particularly if it is a readily definable subsystem of the overall data warehouse architecture. However it is quite reasonable to think of it as the user facing reporting layer, particularly if there are ad-hoc reporting tools such as Business Objects or OLAP systems that allow end-users to get at the data directly.</p>
|
<p>To me, a datamart is just place where data gets dumped in a relatively flat, unusable format.</p>
<p>Cube is taking that data and making it dance.</p>
| 47,101
|
<p>For my school work, I do a lot of switching computers (from labs to my laptop to the library). I'd kind of like to put this code under some kind of version control. Of course the problem is that I can't always install additional software on the computers I use. Is there any kind of version control system that I can keep on a thumb drive? I have a 2GB drive to put this on, but I can get a bigger one if necessary.</p>
<p>The projects I'm doing aren't especially big FYI.</p>
<p><strong>EDIT:</strong> This needs to work under windows.</p>
<p><strong>EDIT II:</strong> Bazaar ended up being what I chose. It's even better if you go with TortoiseBzr.</p>
|
<p>You could use <a href="http://www.portablepython.com/" rel="noreferrer">Portable Python</a> and <a href="http://bazaar-vcs.org/" rel="noreferrer">Bazaar</a> (Bazaar is a Python app). I like to use Bazaar for my own personal projects because of its extreme simplicity. Plus, it can be portable because Python can be portable. You will just need to install it's dependencies in your Portable Python installation as well.</p>
|
<p>bitnami stack subversion it's easy to install.
You can try to install so too xampp with portableapps.com and subversion.</p>
| 12,331
|
<p>I've the following rewrite rule in .htaccess:</p>
<pre><code>RewriteRule ^groups/([^/\.]+)/?$ groupdetail.php?gname=$1 [L,NC]
</code></pre>
<p>This takes something like www.example.com/groups/groupname and calls www.example/groupdetail.php?gname=groupname. And it works just fine.</p>
<p>But all the relative links on groupdetail.php use groups/ as the relative path, and I don't want them to. How do I avoid this?</p>
<p>For example, when a user clicks on a link <code><a href="link.php"></code> on groupdetail.php?gname=groupname, he's taken to www.example/groups/link.php. I want to take the user to www.example.com/link.php.</p>
<p>Obviously, I want to URL to the user to look like "www.example.com/groups/groupname" so I don't want to use [R]/redirect.</p>
|
<p>If like me you had hundreds of relative links in the page, insert a <code><base href=""></code> in the <code><head></code> with an absolute path (could use relative too). You'll need to also make the path to .js files in the <code><head></code> absolute because IE and firefox deal with the base href differently. I agree it is an annoying issue.</p>
|
<p>Hop's answer is correct. The browser sees <strong><code>www.example.com/groups/groupname</code></strong> as the address, so considers that <strong><code>/groups</code></strong> is the current directory. So, any links like <strong><code><a href=link.php></code></strong> are assumed to be in the <strong><code>/groups</code></strong> folder.</p>
<p>When the user moves his mouse over the link, he'll see <strong><code>www.example.com/groups/link.php</code></strong> as the link address.</p>
<p>The solution is to use absolute links -- just add a slash before the href:</p>
<p><strong><code><a href=/link.php></code></strong></p>
<p>The user will then see <strong><code>www.example.com/link.php</code></strong> as the url.</p>
<p>That said, it seems from your question that you are using relative links on purpose... do you have a reason not to use absolute links?</p>
| 17,440
|
<p>I am building a WPF application. Inside that application I am using the XmlReader class to parse several local XML files. The code I have written <strong>works perfectly</strong> during debugging, but fails once I publish the application and install it.</p>
<p>I have the XML documents as CONTENT in build action, and I have them set to COPY ALWAYS.I can confirm that the XML documents are being deployed in my build and are in tact in the application folder once installed.</p>
<p>What further confuses me is that I am using the same XmlReader code to parse RSS feeds from external websites in this application without problem. It only fails on the local XML documents.</p>
<p>Does anyone know why my XmlReader would fail to parse local XML documents once the application is published?</p>
<p>Here is a small snippet of my XmlReader code for referance:</p>
<pre><code>XmlReaderSettings settings = new XmlReaderSettings();
settings.IgnoreComments = true;
settings.IgnoreProcessingInstructions = true;
settings.IgnoreWhitespace = true;
try
{
settingsReader = XmlReader.Create("Resources/data/TriviaQuestions.xml", settings);
nodeNum = 0;
while (settingsReader.Read())
{
switch (settingsReader.NodeType)
{
case XmlNodeType.Element:
if (settingsReader.HasAttributes)
{
for (int i = 0; i < settingsReader.AttributeCount; i++)
{
settingsReader.MoveToAttribute(i);
_feeds[nodeNum] = settingsReader.Value.ToString();
}
settingsReader.MoveToContent(); // Moves the reader back to the element node.
}
break;
case XmlNodeType.Text:
_questions[nodeNum] = settingsReader.Value;
nodeNum++;
break;
}
}
settingsReader.Close();
}
catch
{
}
</code></pre>
<p>Here is my XML</p>
<pre><code><?xml version="1.0" encoding="utf-8" ?>
<Questions>
<Question feed="http://entertainment.msn.com/rss/topboxoffice/">What movie has the top box office sales in the US right now?</Question>
<Question feed="http://entertainment.msn.com/rss/topdvdrentals/">What is the top DVD rental in the US this week?</Question>
<Question feed="http://entertainment.msn.com/rss/topalbums/">Which of the following albums is currently topping the charts?</Question>
</Questions>
</code></pre>
|
<p>By your publish description I assume you are using clickonce to install the application.</p>
<p>Clickonce has different default behavior for xml files - it assumes they are data files and places them in a different install location from your other files.</p>
<p>Please double check that your xml files really are being installed where you think they are. </p>
<p>In the publish settings you can change the setting for each xml file from data file to include. Your other files will already be set to include.</p>
<p>Note that the publish settings are independent of the build settings for the file.</p>
|
<p>Consider using IsolatedStorage to store your settings rather than in a relative Resources directory. This will give you a known location for different install scenarios (e.g., ClickOnce installs).</p>
| 32,011
|
<p>I need a method to return a random string in the format:</p>
<p>Letter Number Letter Number Letter Number</p>
|
<p>Assuming you don't need it to be threadsafe:</p>
<pre><code>private static readonly Random rng = new Random();
private static RandomChar(string domain)
{
int selection = rng.Next(domain.Length);
return domain[selection];
}
private static char RandomDigit()
{
return RandomChar("0123456789");
}
private static char RandomLetter()
{
return RandomChar("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
}
public static char RandomStringInSpecialFormat()
{
char[] text = new char[6];
char[0] = RandomLetter();
char[1] = RandomDigit();
char[2] = RandomLetter();
char[3] = RandomDigit();
char[4] = RandomLetter();
char[5] = RandomDigit();
return new string(text);
}
</code></pre>
<p>(You could use a 3-iteration loop in RandomStringInSpecialFormat, but it doesn't have much benefit.)</p>
<p>If you need it to be thread-safe, you'll need some way of making sure you don't access the Random from multiple threads at the same time. The simplest way to do this (in my view) is to use <a href="http://www.yoda.arachsys.com/csharp/miscutil/usage/staticrandom.html" rel="noreferrer">StaticRandom</a> from <a href="http://pobox.com/~skeet/csharp/miscutil" rel="noreferrer">MiscUtil</a>.</p>
|
<p>Then just use the Random.NextBytes function together with Encoding.ASCII.GetString() to generate Characters.</p>
<p>Or, alternatively, generate a String or char Array (string[]) and use Random.Next(0,array.Length) to get an index to it.</p>
<p>Use a StringBuilder and Random.Next(0,9) to generate numbers and then generate your string by adding a number, a character, a numer etc...</p>
<p><a href="http://msdn.microsoft.com/en-us/library/system.random_members.aspx" rel="nofollow noreferrer">Random Members</a></p>
| 39,808
|
<p>I tried using the IHttpModule and managed to convert the urls just fine,
but all of my images returned path error (all going through the new url directory).</p>
<p>whats the solution?</p>
|
<p>You need to make sure that you use the "~/" path notation on your images and make sure that they are all server controls with runat='server'. Otherwise the images urls won't get rewritten.</p>
<p>For example if you have a page that gets rewritten from:</p>
<p>/Item/Bicycle.aspx</p>
<p>to </p>
<p>/Item.aspx?id=1234</p>
<p>Then what will happen is that an image reference like this:</p>
<pre><code><img src='images/something.gif' />
</code></pre>
<p>will break. So instead you have to do something like this:</p>
<pre><code><asp:image imageurl='~/images/something.gif' runat='server' id='img1'/>
</code></pre>
<p>Alternatively you can use absolute paths for your images. Or you can push as much as possible into your .css files.</p>
|
<p>You can try using a URL rewriter such as <a href="http://cheeso.members.winisp.net/IIRF.aspx" rel="nofollow noreferrer">IIRF</a>.</p>
<p>With IIRF you can use regular expressions to parse the incoming URL as you wish, then send it to the right place.</p>
<p>They have examples built in on how to do all that in the IIRF download.</p>
| 35,212
|
<p>I've got a backup made using the regular SQL Server 2005 backup command. Is there a way to restore just a single table, not the whole DB?</p>
|
<p>Restore the whole database to another machine (or temporary database), then copy the table seems like the easiest to me.</p>
|
<p>Detach the current database then restore the database with the date of the tbl you need to a new location (make a sub folder) to put it in keep it separate from your production databases, then restore the database to that sub folder, when completed find the tbl you need and script it to a create script file save to a file, your done with the database delete it then reattached the original one, now scroll down to the tbl you want to restore and script it to a create file (this is a backup only) now delete the tbl, make sure your database is selected and the active one next load the the scripted file you just created with the other database in the query analyzer and run it, it should report successful now check to see if your tbl has been replaced. your done</p>
| 38,055
|
<p>I'd like to add some pie, bar and scatter charts to my Ruby on Rails web application. I want want them to be atractive, easy to add and not introduce much overhead. </p>
<p>What charting solution would you recommend?<br>
What are its drawbacks (requires Javascript, Flash, expensive, etc)?</p>
|
<p><a href="http://code.google.com/apis/chart/" rel="noreferrer">Google Charts</a> is an excellent choice if you don't want to use Flash. It's pretty easy to use on its own, but for Rails, it's even easier with the <a href="http://badpopcorn.com/blog/2008/09/08/rails-google-charts-gchartrb/" rel="noreferrer">gchartrb</a> gem. An example:</p>
<pre><code>GoogleChart::PieChart.new('320x200', "Things I Like To Eat", false) do |pc|
pc.data "Broccoli", 30
pc.data "Pizza", 20
pc.data "PB&J", 40
pc.data "Turnips", 10
puts pc.to_url
end
</code></pre>
|
<p>We do this by shelling out to gnuplot to generate the charts as PNGs server-side. It's a bit old-school and the charts aren't interactive but it works and is cacheable.</p>
<p>(The other reason we do this is so we can put exactly the same chart in the PDF version of the report).</p>
| 11,313
|
<p>This is something that comes up so often I almost stopped thinking about it but I'm almost certain that I'm not doing this the best way.</p>
<p>The question: Suppose you have the following table</p>
<pre><code>CREATE TABLE TEST_TABLE
(
ID INTEGER,
TEST_VALUE NUMBER,
UPDATED DATE,
FOREIGN_KEY INTEGER
);
</code></pre>
<p>What is the best way to select the TEST_VALUE associated with the most recently updated row where FOREIGN_KEY = 10?</p>
<p><strong>EDIT:</strong> Let's make this more interesting as the answers below simply go with my method of sorting and then selecting the top row. Not bad but for large returns the order by would kill performance. So bonus points: how to do it in a scalable manner (ie without the unnecessary order by).</p>
|
<p>Analytic functions are your friends</p>
<pre><code>SQL> select * from test_table;
ID TEST_VALUE UPDATED FOREIGN_KEY
---------- ---------- --------- -----------
1 10 12-NOV-08 10
2 20 11-NOV-08 10
SQL> ed
Wrote file afiedt.buf
1* select * from test_table
SQL> ed
Wrote file afiedt.buf
1 select max( test_value ) keep (dense_rank last order by updated)
2 from test_table
3* where foreign_key = 10
SQL> /
MAX(TEST_VALUE)KEEP(DENSE_RANKLASTORDERBYUPDATED)
-------------------------------------------------
10
</code></pre>
<p>You can also extend that to get the information for the entire row</p>
<pre><code>SQL> ed
Wrote file afiedt.buf
1 select max( id ) keep (dense_rank last order by updated) id,
2 max( test_value ) keep (dense_rank last order by updated) test_value
,
3 max( updated) keep (dense_rank last order by updated) updated
4 from test_table
5* where foreign_key = 10
SQL> /
ID TEST_VALUE UPDATED
---------- ---------- ---------
1 10 12-NOV-08
</code></pre>
<p>And analytic approaches are generally pretty darned efficient.</p>
<p>I should also point out that analytic functions are relatively new, so if you are on something earlier than 9.0.1, this may not work. That's not a huge population any more, but there are always a few folks stuck on old versions.</p>
|
<pre><code>select test_value
from
(
select test_value
from test_table
where foreign_key=10
order by updated desc
)
where rownum = 1
</code></pre>
<p>Oracle is smart enough to realize it only needs a single row from the inner select and it will do this efficiently.</p>
| 36,240
|
<p>This is really two questions, but they are so similar, and to keep it simple, I figured I'd just roll them together:</p>
<ul>
<li><p><strong>Firstly</strong>: Given an established Java project, what are some decent ways to speed it up beyond just plain in-code optimization?</p></li>
<li><p><strong>Secondly</strong>: When writing a program from scratch in Java, what are some good ways to greatly improve performance?</p></li>
</ul>
<p><strong>Please stay away from general optimization techniques unless they are <em>Java specific</em>.</strong></p>
<p>I asked this about <a href="https://stackoverflow.com/questions/172720/speeding-up-python">Python</a> and <a href="https://stackoverflow.com/questions/177122/speeding-up-perl">Perl</a> earlier. For Java I'm wondering what good tips/tricks are out there to improve performance and if there are any particularly good Java profilers.</p>
|
<p>Firstly : by code optimization, I would assume that you've done the right algorithms and right implementation of algorithms. In which case, you would use the profiler and look at how often your garbage collector(GC) is collecting garbage and how much time it is using for doing that. Then you start working on the GC options -- but beware you can get into trouble if you don't know what you're doing.<br>
I assume that you're using java 5/6. In which case, I'd go through the java 5 tuning guide at <a href="http://java.sun.com/docs/hotspot/gc5.0/gc_tuning_5.html" rel="noreferrer">http://java.sun.com/docs/hotspot/gc5.0/gc_tuning_5.html</a>. There is also a very very good newletter on java performance called <a href="http://www.javaperformancetuning.com/" rel="noreferrer">http://www.javaperformancetuning.com/</a> to which you can subscribe.</p>
<p>Other than that, look at how many try/catch blocks you can eliminate. See if you can eliminate unnecessary throwing of Exceptions.</p>
<p>Use Caches where you can BUT don't over do it.</p>
<p>Read Effective Java, 1st and/or 2nd Edition</p>
<p>Profilers : I use yourkit. It's pretty good for java 1.5 and above. You can get a personal license. Other profilers are also good as well.</p>
<p>Just like you have unit and integration tests, it does NOt hurt to have some performance tests that you run as part of your CONTINUOUS INTEGRATION(CI) builds. This way you know when you regressed, especially if you are using a good CI build server.</p>
|
<p>Here is an (older) document by Peter Sestoft which is worth reading: <a href="http://www.dina.kvl.dk/~sestoft/papers/performance.pdf" rel="nofollow noreferrer">Performance in java</a>. Some of the advice is probably not true anymore since Java got a lot better with the later versions in optimizations. But there are still a good set of gems in there to utilize and try when the profiler has found something you can't do any other way (ie, change algorithmically).</p>
| 21,687
|
<p>I’ve got a brand new Django project. I’ve added one minimal view function to <code>views.py</code>, and one URL pattern to <code>urls.py</code>, passing the view by function reference instead of a string:</p>
<pre><code># urls.py
# -------
# coding=utf-8
from django.conf.urls.defaults import *
from myapp import views
urlpatterns = patterns('',
url(r'^myview/$', views.myview),
)
# views.py
----------
# coding=utf-8
from django.http import HttpResponse
def myview(request):
return HttpResponse('MYVIEW LOL', content_type="text/plain")
</code></pre>
<p>I’m trying to use <code>reverse()</code> to get the URL, by passing it a function reference. But I’m not getting a match, despite confirming that the view function I’m passing to reverse is the exact same view function I put in the URL pattern:</p>
<pre><code>>>> from django.core.urlresolvers import reverse
>>> import urls
>>> from myapp import views
>>> urls.urlpatterns[0].callback is views.myview
True
>>> reverse(views.myview)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Library/Python/2.5/site-packages/django/core/urlresolvers.py", line 254, in reverse
*args, **kwargs)))
File "/Library/Python/2.5/site-packages/django/core/urlresolvers.py", line 243, in reverse
"arguments '%s' not found." % (lookup_view, args, kwargs))
NoReverseMatch: Reverse for '<function myview at 0x6fe6b0>' with arguments '()' and keyword arguments '{}' not found.
</code></pre>
<p>As far as I can tell from the documentation, function references should be fine in both the URL pattern and <code>reverse()</code>.</p>
<ul>
<li><a href="http://docs.djangoproject.com/en/dev/topics/http/urls/#passing-callable-objects-instead-of-strings" rel="noreferrer">URL patterns with function references</a></li>
<li><a href="http://docs.djangoproject.com/en/dev/topics/http/urls/?from=olddocs#reverse" rel="noreferrer"><code>reverse</code> with function references</a></li>
</ul>
<p>I’m using the Django trunk, revision 9092.</p>
|
<p>Got it!! The problem is that some of the imports are of <code>myproject.myapp.views</code>, and some are just of <code>myapp.views</code>. This is confusing the Python module system enough that it no longer detects the functions as the same object. This is because your main <code>settings.py</code> probably has a line like:</p>
<pre><code>ROOT_URLCONF = `myproject.urls`
</code></pre>
<p>To solve this, try using the full import in your shell session:</p>
<pre><code>>>> from django.core.urlresolvers import reverse
>>> from myproject.myapp import views
>>> reverse(views.myview)
'/myview/'
</code></pre>
<p>Here's a log of the debugging session, for any interested future readers:</p>
<pre><code>>>> from django.core import urlresolvers
>>> from myapp import myview
>>> urlresolvers.get_resolver (None).reverse_dict
{None: ([(u'myview/', [])], 'myview/$'), <function myview at 0x845d17c>: ([(u'myview/', [])], 'myview/$')}
>>> v1 = urlresolvers.get_resolver (None).reverse_dict.items ()[1][0]
>>> reverse(v1)
'/myview/'
>>> v1 is myview
False
>>> v1.__module__
'testproject.myapp.views'
>>> myview.__module__
'myapp.views'
</code></pre>
<p>What happens if you change the URL match to be <code>r'^myview/$'</code>?</p>
<hr>
<p>Have you tried it with the view name? Something like <code>reverse ('myapp.myview')</code>?</p>
<p>Is <code>urls.py</code> the root URLconf, or in the <code>myapp</code> application? There needs to be a full path from the root to a view for it to be resolved. If that's <code>myproject/myapp/urls.py</code>, then in <code>myproject/urls.py</code> you'll need code like this:</p>
<pre><code>from django.conf.urls.defaults import patterns
urlpatterns = patterns ('',
(r'^/', 'myapp.urls'),
)
</code></pre>
|
<p>If your two code pastes are complete, then it doesn't look like the second, which makes the actual call to reverse(), ever imports the urls module and therefor if the url mapping is ever actually achieved.</p>
| 17,643
|
<p>I have a huge file that I must parse line by line. Speed is of the essence. </p>
<p>Example of a line:</p>
<blockquote>
<pre><code>Token-1 Here-is-the-Next-Token Last-Token-on-Line
^ ^
Current Position
Position after GetToken
</code></pre>
</blockquote>
<p>GetToken is called, returning "Here-is-the-Next-Token" and sets the CurrentPosition to the position of the last character of the token so that it is ready for the next call to GetToken. Tokens are separated by one or more spaces.</p>
<p>Assume the file is already in a StringList in memory. It fits in memory easily, say 200 MB.</p>
<p>I am worried only about the execution time for the parsing. What code will produce the absolute fastest execution in Delphi (Pascal)?</p>
|
<ul>
<li>Use PChar incrementing for speed of processing</li>
<li>If some tokens are not needed, only copy token data on demand</li>
<li>Copy PChar to local variable when actually scanning through characters</li>
<li>Keep source data in a single buffer unless you must handle line by line, and even then, consider handling line processing as a separate token in the lexer recognizer</li>
<li>Consider processing a byte array buffer that has come straight from the file, if you definitely know the encoding; if using Delphi 2009, use PAnsiChar instead of PChar, unless of course you know the encoding is UTF16-LE.</li>
<li>If you know that the only whitespace is going to be #32 (ASCII space), or a similarly limited set of characters, there may be some clever bit manipulation hacks that can let you process 4 bytes at a time using Integer scanning. I wouldn't expect big wins here though, and the code will be as clear as mud.</li>
</ul>
<p>Here's a sample lexer that should be pretty efficient, but it assumes that all source data is in a single string. Reworking it to handle buffers is moderately tricky due to very long tokens.</p>
<pre><code>type
TLexer = class
private
FData: string;
FTokenStart: PChar;
FCurrPos: PChar;
function GetCurrentToken: string;
public
constructor Create(const AData: string);
function GetNextToken: Boolean;
property CurrentToken: string read GetCurrentToken;
end;
{ TLexer }
constructor TLexer.Create(const AData: string);
begin
FData := AData;
FCurrPos := PChar(FData);
end;
function TLexer.GetCurrentToken: string;
begin
SetString(Result, FTokenStart, FCurrPos - FTokenStart);
end;
function TLexer.GetNextToken: Boolean;
var
cp: PChar;
begin
cp := FCurrPos; // copy to local to permit register allocation
// skip whitespace; this test could be converted to an unsigned int
// subtraction and compare for only a single branch
while (cp^ > #0) and (cp^ <= #32) do
Inc(cp);
// using null terminater for end of file
Result := cp^ <> #0;
if Result then
begin
FTokenStart := cp;
Inc(cp);
while cp^ > #32 do
Inc(cp);
end;
FCurrPos := cp;
end;
</code></pre>
|
<p>Rolling your own is the fastest way for sure. For more on this topic, you could see <a href="http://synedit.sourceforge.net/" rel="nofollow noreferrer">Synedit's source code</a> which contains lexers (called highlighters in the project's context) for about any language on the market. I suggest you take one of those lexers as a base and modify for your own usage.</p>
| 36,617
|
<p>If I generate an exception on my own, I can include any info into the exception: a number of code line and name of source file. Something like this:</p>
<pre><code>throw std::exception("myFile.cpp:255");
</code></pre>
<p>But what's with unhandled exceptions or with exceptions that were not generated by me?</p>
|
<p>It seems everyone is trying to improve your code to throw exceptions in your code, and no one is attempting the actual question you asked.</p>
<p>Which is because it can't be done. If the code that's throwing the exception is only presented in binary form (e.g. in a LIB or DLL file), then the line number is gone, and there's no way to connect the object to to a line in the source code.</p>
|
<p>Apart from using a custom class with a macro, as suggested by Frank Krueger, for your own exceptions, you might be interested in taking a look at the structured exception handling mechanism (you're programming under windows, right?)<br>
Check <a href="http://msdn.microsoft.com/en-us/library/ms680657%28VS.85%29.aspx" rel="nofollow noreferrer">Structured Exception Handling on MSDN</a></p>
| 45,386
|
<p>I'm using PIL (Python Imaging Library). I'd like to draw transparent polygons. It seems that specifying a fill color that includes alpha level does not work. Are their workarounds?</p>
<p>If it can't be done using PIL I'm willing to use something else.</p>
<p>If there is more than one solution, then performance should be factored in. The drawing needs to be as fast as possible.</p>
|
<p>This is for Pillow, a more maintained fork of PIL. <a href="http://pillow.readthedocs.org/" rel="noreferrer">http://pillow.readthedocs.org/</a></p>
<p>If you want to draw polygons that are transparent, relative to each other, the base Image has to be of type RGB, not RGBA, and the ImageDraw has to be of type RGBA. Example:</p>
<pre><code>from PIL import Image, ImageDraw
img = Image.new('RGB', (100, 100))
drw = ImageDraw.Draw(img, 'RGBA')
drw.polygon(xy=[(50, 0), (100, 100), (0, 100)], fill=(255, 0, 0, 125))
drw.polygon(xy=[(50, 100), (100, 0), (0, 0)], fill=(0, 255, 0, 125))
del drw
img.save('out.png', 'PNG')
</code></pre>
<p>This will draw two triangles overlapping with their two colors blending. This a lot faster than having to composite multiple 'layers' for each polygon.</p>
|
<p>I had to draw an outside polygon with an outline, and subtract inner polygons (a common operation in GIS). Works like a charm using color <code>(255,255,255,0)</code>.</p>
<pre><code>image = Image.new("RGBA", (100,100))
drawing = ImageDraw.Draw(i)
for index, p in enumerate(polygons):
if index == 0:
options = { 'fill': "#AA5544",
'outline': "#993300"}
else:
options = {'fill': (255,255,255,0)}
drawing.polygon( p, **options )
buf= StringIO.StringIO()
i.save(buf, format= 'PNG')
# do something with buf
</code></pre>
| 46,924
|
<p>I have a really simple ASP.NET web application and a web setup project that deploys the project output and content files to a virtual directory in IIS.</p>
<p>What I want is for the MSI to automatically disable Anonymouse Access for that virtual folder in IIS. </p>
<p>I suspect it can probably be done by writing some code in a custom action DLL, that would be acceptable, but is there any way to do it within the the settings of the web setup project?</p>
|
<p><a href="http://www.microsoft.com/technet/security/guidance/identitymanagement/idmanage/P3ASPD_6.mspx?mfr=true" rel="nofollow noreferrer">Taken from technet</a></p>
<blockquote>
<p>The property for anonymous access is
unfortunately not available through
Web setup projects. For this reason,
you must:</p>
<ol>
<li><p>Write a custom installer to enable or disable anonymous access.</p></li>
<li><p>Pass the necessary parameters from the setup wizard to the installer at
run time.</p></li>
</ol>
</blockquote>
|
<pre><code><configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<authentication mode="Forms">
<forms loginUrl="SignIn.aspx" defaultUrl="Welcome.aspx" protection="All">
<credentials passwordFormat="Clear">
<user name="lee" password="lee12345"/>
<user name="add" password="add12345"/>
</credentials>
</forms>
</authentication>
<authorization>
<deny users="?" /> //deny acces to anonymous users
</authorization>
</system.web>
</configuration>
</code></pre>
| 38,199
|
<p>Please, I am new to webparts and I need help!!</p>
<p>I have a custom web part that I created. I added MS Ajax to it using an UpdatePanel which works fine. I add all my controls to the CreateChildControls method. As soon as I add a UpdateProgress control my page breaks with the following error:</p>
<p>Script controls may not be registered before PreRender</p>
<p>I do not use the OnPreRender event as what other posts suggest. Please, if anyone can give me advice it will be very much appreciated.</p>
<p>Thanks</p>
|
<p>I encountered similar problem before, try to call EnsureChildControls method inside your on init method override. It should be called by system automatically, but sharepoint likes to forget about it from time to time.</p>
<p>Like this:</p>
<pre><code> protected override void OnInit(EventArgs e)
{
base.OnInit(e);
EnsureChildControls();
}
</code></pre>
|
<p>You might have forgotten to call the base method of an overrided event, which is not necessarily the OnPreRender event.</p>
<p>Check if the OnInit or OnLoad events are calling their base.On[...] method, e.g.:</p>
<pre><code>protected override void OnLoad(EventArgs eventArgs)
{
base.OnLoad(eventArgs);
// your code...
}
</code></pre>
| 41,824
|
<p>I'm having difficulty searching for this. How would I define an element in an XML schema file for XML that looks like this:</p>
<pre><code><option value="test">sometext</option>
</code></pre>
<p>I can't figure out how to define an element that is of type <code>xs:string</code> and also has an attribute. </p>
<p>Here's what I've got so far:</p>
<pre><code><xs:element name="option">
<xs:complexType>
<xs:attribute name="value" type="xs:string" />
</xs:complexType>
</xs:element>
</code></pre>
|
<p>Try</p>
<pre><code> <xs:element name="option" type="AttrElement" />
<xs:complexType name="AttrElement">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="value" type="xs:string">
</xs:attribute>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</code></pre>
|
<p>I know it is not the same, but it works for me:</p>
<pre><code><xsd:element name="option">
<xsd:complexType mixed="true">
<xsd:attribute name="value" use="optional" type="xsd:string"/>
</xsd:complexType>
</xsd:element>
</code></pre>
| 49,298
|
<p>I'm using .NET to make an application with a drawing surface, similar to Visio. The UI connects two objects on the screen with Graphics.DrawLine. This simple implementation works fine, but as the surface gets more complex, I need a more robust way to represent the objects. One of these robust requirements is determining the intersection point for two lines so I can indicate separation via some kind of graphic.</p>
<p>So my question is, can anyone suggest a way to do this? Perhaps with a different technique (maybe GraphViz) or an algorithm?</p>
|
<p>The representation of lines by y = mx + c is problematic for computer graphics, because vertical lines require m to be infinite.</p>
<p>Furthermore, lines in computer graphics have a start and end point, unlike mathematical lines which are infinite in extent. One is usually only interested in a crossing of lines if the crossing point lies on both the line segments in question.</p>
<p>If you have two line segments, one from vectors x1 to x1+v1, and one from vectors x2 to x2+v2, then define:</p>
<pre><code>a = (v2.v2 v1.(x2-x1) - v1.v2 v2.(x2-x1)) / ((v1.v1)(v2.v2) - (v1.v2)^2)
b = (v1.v2 v1.(x2-x1) - v1.v1 v2.(x2-x1)) / ((v1.v1)(v2.v2) - (v1.v2)^2)
</code></pre>
<p>where for the vectors p=(px,py), q=(qx,qy), p.q is the dot product (px * qx + py * qy). First check if (v1.v1)(v2.v2) = (v1.v2)^2 - if so, the lines are parallel and do not cross.</p>
<p>If they are not parallel, then if 0<=a<=1 and 0<=b<=1, the intersection point lies on both of the line segments, and is given by the point</p>
<pre><code>x1 + a * v1
</code></pre>
<p><strong>Edit</strong> The derivation of the equations for a and b is as follows. The intersection point satisfies the vector equation</p>
<pre><code>x1 + a*v1 = x2 + b*v2
</code></pre>
<p>By taking the dot product of this equation with <code>v1</code>, and with <code>v2</code>, we get two equations:</p>
<pre><code>v1.v1*a - v2.v1*b = v1.(x2-x1)
v1.v2*a - v2.v2*b = v2.(x2-x1)
</code></pre>
<p>which form two linear equations for a and b. Solving this system (by multiplying the first equation by v2.v2 and the second by v1.v1 and subtracting, or otherwise) gives the equations for a and b. </p>
|
<p>You can ask Dr. Math, see <a href="https://web.archive.org/web/20180211083203/http://mathforum.org/library/drmath/view/53254.html" rel="nofollow noreferrer">this link</a>.</p>
| 18,544
|
<p>What is the best way to add "copy to clipboard" functionality to a ListView control in WPF?</p>
<p>I tried adding an ApplicationCommands.Copy to either the ListView ContextMenu or the ListViewItem ContextMenu, but the command remains disabled.</p>
<p>Thanks,
Peter</p>
<p>Here is an xaml sample of one of my attempts...</p>
<pre><code> <Window.Resources>
<ContextMenu x:Key="SharedInstanceContextMenu" x:Shared="True">
<MenuItem Header="Copy" Command="ApplicationCommands.Copy"/>
</ContextMenu>
</Window.Resources>
<ListBox Margin="12,233,225,68" Name="listBox1" >
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=UpToSourceCategoryByCategoryId.Category}" ContextMenu="{DynamicResource ResourceKey=SharedInstanceContextMenu}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</code></pre>
<p>How should I set the CommandTarget in this case?</p>
<p>Thanks,Peter</p>
|
<p>It looks like you need a CommandBinding.</p>
<p>Here is how I would probably go about doing what you trying to do.</p>
<pre><code><Window.CommandBindings>
<CommandBinding
Command="ApplicationCommands.Copy"
Executed="CopyCommandHandler"
CanExecute="CanCopyExecuteHandler" />
</Window.CommandBindings>
<Window.Resources>
<ContextMenu x:Key="SharedInstanceContextMenu">
<MenuItem Header="Copy" Command="ApplicationCommands.Copy"/>
</ContextMenu>
<Style x:Key="MyItemContainerStyle" TargetType="{x:Type ListBoxItem}">
<Setter Property="ContextMenu" Value="{StaticResource SharedInstanceContextMenu}" />
</Style>
</Window.Resources>
<ListBox ItemContainerStyle="{StaticResource MyItemContainerStyle}">
<ListBoxItem>One</ListBoxItem>
<ListBoxItem>Two</ListBoxItem>
<ListBoxItem>Three</ListBoxItem>
<ListBoxItem>Four</ListBoxItem>
</ListBox>
</code></pre>
|
<p>It is also possible to achieve this functionality via an attached property, as I described it on my <a href="http://jannsblog.wordpress.com/2009/03/10/copy-a-listview%E2%80%99s-items-to-the-clipboard/" rel="nofollow noreferrer">blog</a>. The idea is to register the ApplicationCommands.Copy command with the ListView and, when the command is executed, read the values from the data bindings.</p>
<p>You'll find a downloadable sample on the blog entry, too.</p>
| 32,961
|
<p><code>GNU sed version 4.1.5</code> seems to fail with International chars. Here is my input file:</p>
<pre><code>Gras Och Stenar Trad - From Moja to Minneapolis DVD [G2007DVD] 7812 | X
<br>
Gras Och Stenar Trad - From Möja to Minneapolis DVD [G2007DVD] 7812 | Y
</code></pre>
<p>(Note the umlaut in the second line.)</p>
<p>And when I do</p>
<pre><code>sed 's/.*| //' < in
</code></pre>
<p>I would expect to see only the <code>X</code> and <code>Y</code>, as I've asked to remove ALL chars up to the <code>'|'</code> and space beyond it. Instead, I get:</p>
<pre><code>X<br>
Gras Och Stenar Trad - From M? Y
</code></pre>
<p>I know I can use tr to remove the International chars. first, but is there a way to just use sed?</p>
|
<p>I think the error occurs if the input encoding of the file is different from the preferred encoding of your environment. </p>
<p>Example: <code>in</code> is UTF-8</p>
<pre><code>$ LANG=de_DE.UTF-8 sed 's/.*| //' < in
X
Y
$ LANG=de_DE.iso88591 sed 's/.*| //' < in
X
Y
</code></pre>
<p>UTF-8 can safely be interpreted as ISO-8859-1, you'll get strange characters but apart from that everything is fine.</p>
<p>Example: <code>in</code> is ISO-8859-1</p>
<pre><code>$ LANG=de_DE.UTF-8 sed 's/.*| //' < in
X
Gras Och Stenar Trad - From MöY
$ LANG=de_DE.iso88591 sed 's/.*| //' < in
X
Y
</code></pre>
<p>ISO-8859-1 cannot be interpreted as UTF-8, decoding the input file fails. The strange match is probably due to the fact that sed tries to recover rather than fail completely.</p>
<p>The answer is based on Debian Lenny/Sid and sed 4.1.5.</p>
|
<p><code>sed</code> is not very well setup for non-ASCII text. However you can use (almost) the same code in <code>perl</code> and get the result you want:</p>
<pre><code>perl -pe 's/.*\| //' x
</code></pre>
| 9,295
|
<p>When iterating over elements of a vector it is preferred to use iterators instead of an index (see <a href="https://stackoverflow.com/questions/131241/why-use-iterators-instead-of-array-indices">Why use iterators instead of array indices?</a>). </p>
<pre><code>std::vector<T> vec;
std::vector<T>::iterator it;
for ( it = vec.begin(); it != vec.end(); ++it )
{
// do work
}
</code></pre>
<p>However, it can be necessary to use the index in the body of the loop. Which of the following would be preferable in that case, considering performance and flexibility/extensibility?</p>
<ol>
<li>Revert to the indexed loop<pre>
std::vector vec;
size_t i;
for ( i = 0; i < vec.size(); ++i )
{
// use i
}
</pre></li>
<li>Calculate offset<pre>
std::vector vec;
std::vector::iterator it;
for ( it = vec.begin(); it != vec.end(); ++it )
{
size_t i = it - vec.begin();
// use i
}
</pre></li>
<li>Use std::distance <pre>
std::vector vec;
std::vector::iterator it;
for ( it = vec.begin(); it != vec.end(); ++it )
{
size_t i = std::distance( vec.begin(), it );
// use i
}
</pre></li>
</ol>
|
<p>If you're planning on using exclusively a vector, you may want to switch back to the indexed loop, since it conveys your intent more clearly than iterator-loop. However, if evolution of your program in the future may lead to a change of container, you should stick to the iterators and use std::distance, which is guaranteed to work with all standard iterators.</p>
|
<p>I would always tend towards keeping with iterators for future development reasons.</p>
<p>In the above example, if you perhaps decided to swap out std::vector for std::set (maybe you needed a unique collection of elements), using iterators and distance() would continue to work.</p>
<p>I pretty sure that any performance issues would be optimized to the point of it being negligible. </p>
| 16,044
|
<p>I haven't found an answer elsewhere and this doesn't appear to have been asked yet on SO.</p>
<p>When creating an event binding in wxPython, is it possible to pass additional arguments to the event? For example, this is the normal way:</p>
<pre><code>b = wx.Button(self, 10, "Default Button", (20, 20))
self.Bind(wx.EVT_BUTTON, self.OnClick, b)
def OnClick(self, event):
self.log.write("Click! (%d)\n" % event.GetId())
</code></pre>
<p>But is it possible to have another argument passed to the method? Such that the method can tell if more than one widget is calling it but still return the same value? </p>
<p>It would greatly reduce copy & pasting the same code but with different callers.</p>
|
<p>You can always use a lambda or another function to wrap up your method and pass another argument, not WX specific.</p>
<pre><code>b = wx.Button(self, 10, "Default Button", (20, 20))
self.Bind(wx.EVT_BUTTON, lambda event: self.OnClick(event, 'somevalue'), b)
def OnClick(self, event, somearg):
self.log.write("Click! (%d)\n" % event.GetId())
</code></pre>
<p>If you're out to reduce the amount of code to type, you might also try a little automatism like:</p>
<pre><code>class foo(whateverwxobject):
def better_bind(self, type, instance, handler, *args, **kwargs):
self.Bind(type, lambda event: handler(event, *args, **kwargs), instance)
def __init__(self):
self.better_bind(wx.EVT_BUTTON, b, self.OnClick, 'somevalue')
</code></pre>
|
<p>The nicest way would be to make a generator of event handlers, e.g.:</p>
<pre><code>def getOnClick(self, additionalArgument):
def OnClick(event):
self.log.write("Click! (%d), arg: %s\n"
% (event.GetId(), additionalArgument))
return OnClick
</code></pre>
<p>Now you bind it with:</p>
<pre><code>b = wx.Button(self, 10, "Default Button", (20, 20))
b.Bind(wx.EVT_BUTTON, self.getOnClick('my additional data'))
</code></pre>
| 20,928
|
<p>I'm trying to make a simple blackjack program. Sadly, I'm having problems right off the bat with generating a deck of cards.</p>
<pre><code>#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<char> deck;
char suit[] = {'h','d','c','s'};
char card[] = {'2','3','4','5','6','7','8','9','10','J','Q','K','A'};
for (int j=0; j<13; j++) {
for (int i=0; i<4; i++) {
deck.push_back(card[j] suit[i]);
}
}
return 0;
}
</code></pre>
<p>I know my problem begins with me trying to assign the value '10' to a char. Obviously I couldn't get this to compile but I'm sure when I try to assign the card values to the vector deck I'll also get an error since I used variable type 'char'. Knowing what kind of variable type to use seems to be killing me. Also, would 'deck.push_back(card[j] suit[i]);' be the correct code to combine the card and suit, or do you have to put something between card[j] and suit[i]? I'd appreciate it if any of you could lead me in the right direction. Also as a little side note, this is part of a homework assignment so please don't just give me entire blocks of code. Thanks for your help.</p>
|
<p>Try to create class of Card with suit and card as a member and set it as a type of vector. Like</p>
<pre><code>public class Card {
public:
Card(char suit, char card);
char suit, card;
};
int main() {
vector<Card> deck;
char suit[] = {'h','d','c','s'};
char card[] = {'2','3','4','5','6','7','8','9','T','J','Q','K','A'};
for (int j=0; j<13; j++) {
for (int i=0; i<4; i++) {
deck.push_back(new Card(card[j],suit[i]));
}
}
return 0;
}
</code></pre>
<p>also using enums instead of chars in suit and card would make it clearer.</p>
|
<p>I would go with Ross's suggestion to use integers. Most card games will involve some bits of math so that's a better representation.</p>
<p>Convert to 'A' or 'ACE' etc. on output.</p>
| 29,014
|
<p>This may be a long shot, but I was wondering if the signals seen across a stepper motor's windings could indicate whether the stepper was being told to move over some short time period. This is in particular for the stepper used on extruders.</p>
<p>I've read that PWM in used in stepper drivers and controls current patterns to move the motor. And that a current must also be maintained through the windings if the motor is to hold its position. So it would seem that there is always a pulsing waveform across the windings whenever the stepper is energized, correct? When the motor is holding its position, is there anything distinctive about the waveform?</p>
<p>This is for a filament sensor I'd like to make. The sensor would be located at the extruder motor. It would monitor movement/flow of the solid filament. A lack of filament flow could be because of filament runout, tangled or caught filament, or non-extruding travel moves. I'd like to be able to tell the first two causes from the last one (when it's not supposed to be extruding for some hundreds of milliseconds or so). It would also be nice to tell 'no directed movement' from 'very slow movement' which would happen with small nozzles, slow speed or other slow extrusion situations.</p>
<p>I watched the waveforms with an oscilloscope while printing, but travel moves were quick and relatively rare, so I couldn't definitely see if there was something I could use during those times. Could I just filter the pulse waveform (what corner frequency?) to get an approximation of the current waveform going through the coils -- on the idea that the waveform should resemble a DC level during non-extruding but still energized times. Perhaps another low-pass filtering of that DC level, or a high-pass of the waveform to indicate directed extrusion? Using DSP on a micro, of course.</p>
<p>Are there any experts here on the subject of low-level stepper motor control?</p>
|
<blockquote>
<p>So it would seem that there is always a pulsing waveform across the windings whenever the stepper is energized, correct?</p>
</blockquote>
<p>Correct.</p>
<blockquote>
<p>When the motor is holding its position, is there anything distinctive about the waveform?</p>
</blockquote>
<p><a href="https://www.youtube.com/watch?v=Phds2oFOIYg" rel="nofollow noreferrer">Yes there is</a>. This video contains a short example of what the current waveforms would look like.</p>
<p>If I understand you correctly: You want to detect filament events based by doing current sensing on the phases of the stepper motor. The simple of it is that, if the motor is not turning then the <a href="https://en.wikipedia.org/wiki/Counter-electromotive_force" rel="nofollow noreferrer">Back ElectroMotive Force</a> will be zero. As the speed increases the BEMF goes up, which causes the current levels to go down. Is this how stall detection in some driver systems work.</p>
<p>You may be able to determine if what you want to do is even practical by studying the fundamentals of stepper motor driving; both <a href="https://www.arrow.com/en/research-and-events/articles/voltage-versus-current-mode-control-in-stepper-motors" rel="nofollow noreferrer">voltage mode and current mode</a>.</p>
<p>Apart from that it may be just as practical to use a <a href="https://en.wikipedia.org/wiki/Rotary_encoder" rel="nofollow noreferrer">rotary encoder</a> upstream of the extruder motor to detect the filament movement, or lack thereof.</p>
<p>In your case detecting if the filament is present but not moving calls for stall detection. If the PWM pulse occurs but the rate at which the voltage increased (the slope) did not change, then there was no BEMF event. The lack of such an event would indicate that the rotor did not move. If there is no filament to push, then when the rotor moves it will <em>ring</em> (overshoot it's target position and fluctuate back and forth until it settles into the electrical position that the controller intended), because the mechanical load has changed.</p>
<p>For a NEMA17 stepper, these would be very small change in a very brief event. I would start with installing <a href="https://www.sparkfun.com/products/14544" rel="nofollow noreferrer">current sensors</a> on both phases, and then doing some signal processing on top of that. </p>
|
<p>There is nothing you can do to monitor the extruder stepper motor to assure that filament is being fed when it should be fed. A common condition is where the filament binds but the extruder stepper continues to move as commanded. The drive pully strips the dents it presses in the filament, and grinds down the filament. The extruder still steps, and the filament does not.</p>
<p>You can reduce this for particular filaments by increasing the pressure on the filament by the drive pully, but the optimum pressure varies with the filament. For instance, I've found that PET needs a lesser pressure than PLA.</p>
<p>@User77232 suggests using a separate rotary encoder to detect the motion of the filament through a different sensor. This may be better, since you can detect a filament jam with extruder motion. If you are using a PTFE tube to deliver filament to the extruder, the encoder can be mounted at the other end of the tube. You may need to make allowance for some compression and stretch of the filament in the tube, which could delay detecting "lack of movement".</p>
<p>I had hoped that the Triaminic TMC2100 chips (spec <a href="https://www.trinamic.com/fileadmin/assets/Products/ICs_Documents/TMC2100_datasheet_Rev1.09.pdf" rel="nofollow noreferrer">here</a>) would provide detection of drive torque by watching the back EMF, but reading the spec didn't look helpful. There was an old patent (that should be long expired) that detected the current needed to move a stepper motor to achieve faster acceleration and quieter operation, but I didn't find on the Triaminic driver a useful torque limit signal. If one could detect the torque required, one could set a peek torque value that is lower than the initial filament strip torque.</p>
<p>Perhaps one could mount the extruder stepper motor with a compliant mount, perhaps something like a TPU or rubber material, and use a strain gauge to measure the stretch of the mount.</p>
| 1,270
|
<p>example:</p>
<p>I want to see if <code>array[5]</code> holds a value or is empty.</p>
|
<p>Elements in primitive arrays can't be empty. They'll always get initialized to something (usually <code>0</code> for <code>int</code> arrays, but depends on how you declare the array).</p>
<p>If you declare the array like so (for example):</p>
<pre><code>int [] myArray ;
myArray = new int[7] ;
</code></pre>
<p>then all of the elements will default to <code>0</code>.</p>
<p>An alternative syntax for declaring arrays is</p>
<pre><code>int[] myArray = { 12, 7, 32, 15, 113, 0, 7 };
</code></pre>
<p>where the initial values for an array (of size seven in this case) are given in the curly braces <code>{}</code>.</p>
|
<p>Create a constant to define the empty value, eg:</p>
<pre><code>private static final int EMPTY = -1;
</code></pre>
<p>then create the array like this:</p>
<pre><code>int[] myArray = new int[size];
Arrays.fill(myArray, EMPTY);
</code></pre>
<p>then to check if an element is 'empty', do this:</p>
<pre><code>if (myArray[i] == EMPTY)
{
//element i is empty
}
</code></pre>
| 36,358
|
<p>I want to build a dynamic floating window with close button at corner. Is it possible, and also i want to add some content dynamically into that window. </p>
<p>Please help me.. It should be in javascript.. Better without AJAX..</p>
<p>Thanks in Advance</p>
|
<p>jQuery UI has an awesome floating window. What's cool about the jQuery UI version is that you can also package it with the UI theme manager, which means less time styling.</p>
<p>Check it out here : <a href="https://jqueryui.com/resources/demos/dialog/modal-form.html" rel="nofollow noreferrer" title="jQuery UI Modal">jQuery UI Dialog examples</a></p>
<p>All it takes is creating a container (probably a div), and one line of code. Something like this:</p>
<pre><code><div id="example">I'm in a dialog!</div>
$("#example").dialog();
</code></pre>
<p>Here's the documentation: <a href="https://jqueryui.com/dialog/" rel="nofollow noreferrer">jQuery UI Dialog documentation</a></p>
|
<p>Well at the most basic just create a div and inject content by setting innerHTML to an HTML string. Positioning it can be tricky since you have to worry about scrolling and different browsers have different means of controlling this. You may also want to position relative to some originating element in the page which you can do by digging the element and it's position out of the event object your javascript function receives when the originating element is clicked.</p>
<p>Google hover popup - first link is <a href="http://www.calcaria.net/javascript/2006/09/javascript-hover-over-html-popup.html" rel="nofollow noreferrer">http://www.calcaria.net/javascript/2006/09/javascript-hover-over-html-popup.html</a></p>
| 49,831
|
<p>When I try to install a new instance of SQL Server 2008 Express on a development machine with SQL 2005 Express already up and running, the install validation fails because the "SQL 2005 Express tools" are installed and I'm told to remove them.</p>
<p><strong>What exactly does that mean?</strong> </p>
<p>After reading this article:</p>
<p><a href="http://www.asql.biz/Articoli/SQLX08/Art1_5.aspx" rel="noreferrer">http://www.asql.biz/Articoli/SQLX08/Art1_5.aspx</a> </p>
<p>I uninstalled the 2005 version of the SQL Management Studio but received the same error from the 2008 installer during my follow-up attempt.</p>
<p><strong>Updates</strong></p>
<p>1) Uninstalled the SQL 2005 Management Studio only. Received the same error from the 2008 install.</p>
<p>2) Removed all SQL 2005 common components. Received the same error from the 2008 install.</p>
<p>3) Installed the shared components from the SQL 2008 installation program. Received the same error from the 2008 install when trying to install the new SQL 2008 instance.</p>
<p>4) Uninstalled SQL 2008 components, rebooted, re-installed SQL 2005 Management Studio from installation media, rebooted, un-installed SQL 2005 Workstation Components from Control Panel, re-booted.</p>
<p>Installation of SQL 2008 is now proceeding as it should.</p>
<p>Seems likely that if I'd re-booted after update 2 above things would have gone more smoothly. :-(</p>
|
<p>Although you should have no problem running a 2005 instance of the database engine beside a 2008 instance, The tools are installed into a shared directory, so you can't have two versions of the tools installed. Fortunately, the 2008 tools are backwards-compatible. As we speak, I'm using SSMS 2008 and Profiler 2008 to manage my 2005 Express instances. Works great.</p>
<p>Before installing the 2008 tools, you need to remove any and all "shared" components from 2005. Try going to your Add/Remove programs control panel, find Microsoft SQL Server 2005, and click "Change." Then choose "Workstation Components" and remove everything there (this will not remove your database engine).</p>
<p>I believe the 2008 installer also has an option to upgrade shared components only. You might try that. Good luck!</p>
|
<p>Just Remove the the Workstation Components from Add/Remove Programs - SQL Server 2005.
Removing Workstation Components, SQL Server 2008 installation goes well.</p>
| 21,190
|
<p>From my understanding of FFF 3D printing, the glass state is usually used to heat the bed for better first layer adhesion. Other than that, does the extruder keep ex:PLA in a glass state for any reason?</p>
<p>Is the transition of the filament straight from solid to liquid for extrusion without any real regard for the glass state?</p>
|
<p><em>Note that the extruder feeds filament it doesn't heat anything, you don't want heat in the extruder. The hot end is the part that adds heat well over the glass temperature.</em></p>
<p>The <a href="https://en.m.wikipedia.org/wiki/Glass_transition" rel="nofollow noreferrer">glass transition temperature</a>, the temperature where the material transitions from a brittle "glassy" state into a viscous or rubbery state, is always lower than the melting temperature. This temperature is of importance for adhesion to the bed; in a rubbery state the stresses are much lower than in a brittle state.</p>
<blockquote>
<p>Is a thermoplastic's glass state relevant for 3D printing extrusion?</p>
</blockquote>
<ul>
<li><p>No, the glass transition temperature is not directly important for the extrusion, the extrusion temperature (where the filament is fluid enough for deposition and adhesion) is much higher than the glass temperature.</p>
</li>
<li><p>Yes, the glass transition temperature may play a role in the hot end in case of heat creeping up the cold end (usually some kind of radiator or heat dissipating element; usually connected through the heat-break), but not necessarily in melting the filament for extrusion. Heat creeping up with excessive retraction may cause filament to (partially or fully) clog and as such influence the extrusion.</p>
</li>
</ul>
|
<p>The transition from solid to liquid is the important part.</p>
<p>The bed is heated for adhesion and kept heated for the same reason, but the extruder is a lot hotter and just performs the task of solid to liquid, the fans and ambient temperature cool it to solid.</p>
<p>Once a layer is solid it will heat up again when the next layer goes on it both from heat radiating from the nozzle and the liquid plastic going on it. This should give better layer adhesion.</p>
| 2,220
|
<p>How would you lay out the directory structure for a large C# solution, consisting of perhaps 20 to 30 projects, mostly C# but some C++? Where do you put external dependencies? When creating a branch in source control, do you branch absolutely everything? Do you override the defaults for where built files go?</p>
|
<p>Take a look at the <a href="http://www.codeplex.com/treesurgeon" rel="nofollow noreferrer">Tree Surgeon</a> CodePlex project.</p>
|
<p>Take a look at the <a href="http://www.codeplex.com/treesurgeon" rel="nofollow noreferrer">Tree Surgeon</a> CodePlex project.</p>
| 35,463
|
<p>I have built a 3D printer out of parts from my tip, a ramps board, arduino mega, and a hot end. However, after doing a test extrusion some plastic was spewed out and then the print jammed un-expectantly and my homemade extruder no longer had the strength to push the filament. </p>
<p>I took the filament out and what I found was that the filament going into the extruder had formed a cylinder at the end. Then after pushing the filament through by hand to eliminate the possibility of my weak extruder, I found that the filament was expanding coming out of the filament, and then cooling down unable to go through. I cut the filament, removing the bloated end, pushed it back into the extruder and then again after 30 seconds the same problem occurred.
After researching, I came to the conclusion that maybe there is a gap allowing filament to go out of the heating area, expand and then cool down, or even my wooden direct to bowden adapter is stopping the filament cooling causing it to clog. However I am not sure.</p>
<p>I am becoming frustrated as I am doing this for a school project, I only have two weeks left to finish and everything seems to be failing. Any help would be much appreciated. </p>
<p>For reference this is my hotend: <a href="https://www.amazon.co.uk/gp/product/B074DRLGW9/ref=oh_aui_detailpage_o03_s00?ie=UTF8&psc=1." rel="noreferrer">link to amazon</a>
I brought the cheapest one available on amazon, so it has no fan and no way to connect a bowden tube. I have created a basic adapter between the thread and a bowden tube holder, out of wood. It's not good but it does the job.</p>
<p>Here is a picture of my hot end and what the filament looks like after I removed it. There appears to be a spiral shape on some of them.</p>
<p><a href="https://i.stack.imgur.com/kNKgu.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/kNKgu.jpg" alt="enter image description here"></a>
<a href="https://i.stack.imgur.com/iXpBG.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/iXpBG.jpg" alt="enter image description here"></a></p>
|
<p>You are suffering from what is called "heat creep". Molten filament is creeping up the heat break and into the bowden tube, where it is causing a jam. You need to install a proper radiator block that is cooled by a fan, not just a lump of wood as a "cold end". The cold end is not just a connector, its primary purpose is to act as a cooler. A hot end on its own is not enough. You also need a cold end. Here is my extruder disassembled (fan omitted). The radiator block is the red item.</p>
<p><a href="https://i.stack.imgur.com/ngeW7.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/ngeW7.jpg" alt="enter image description here"></a></p>
|
<p>Hello it's seems that your hotend's barrel get's too hot when your ar printing, have you try to make a heat sink on the barrell, with some washers and nuts? That worked for me, like this<a href="https://i.stack.imgur.com/bmfpm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bmfpm.png" alt="enter image description here"></a></p>
<p>I Took that idea from this video <a href="https://www.youtube.com/watch?v=UvICpdVONXM" rel="nofollow noreferrer">https://www.youtube.com/watch?v=UvICpdVONXM</a> </p>
<p>Also make sure that the hotend's aluminum block is properly insulated, you could do this with some Kapton Tape.</p>
| 733
|
<p>I'm starting to learn ruby. I'm also a day-to-day C++ dev.
For C++ projects I usually go with following dir structure</p>
<pre><code>/
-/bin <- built binaries
-/build <- build time temporary object (eg. .obj, cmake intermediates)
-/doc <- manuals and/or Doxygen docs
-/src
--/module-1
--/module-2
-- non module specific sources, like main.cpp
- IDE project files (.sln), etc.
</code></pre>
<p>What dir layout for Ruby (non-Rails, non-Merb) would you suggest to keep it clean, simple and maintainable?</p>
|
<p>Bundler includes the necessary infrastructure to generate a gem:</p>
<pre><code>$ bundle gem --coc --mit --test=minitest --exe spider
Creating gem 'spider'...
MIT License enabled in config
Code of conduct enabled in config
create spider/Gemfile
create spider/lib/spider.rb
create spider/lib/spider/version.rb
create spider/spider.gemspec
create spider/Rakefile
create spider/README.md
create spider/bin/console
create spider/bin/setup
create spider/.gitignore
create spider/.travis.yml
create spider/test/test_helper.rb
create spider/test/spider_test.rb
create spider/LICENSE.txt
create spider/CODE_OF_CONDUCT.md
create spider/exe/spider
Initializing git repo in /Users/francois/Projects/spider
Gem 'spider' was successfully created. For more information on making a RubyGem visit https://bundler.io/guides/creating_gem.html
</code></pre>
<p>Then, in lib/, you create modules as needed:</p>
<pre><code>lib/
spider/
base.rb
crawler/
base.rb
spider.rb
require "spider/base"
require "crawler/base"
</code></pre>
<p>Read the manual page for <a href="https://bundler.io/man/bundle-gem.1.html" rel="nofollow noreferrer">bundle gem</a> for details on the <code>--coc</code>, <code>--exe</code> and <code>--mit</code> options.</p>
|
<p>I would stick to something similar to what you are familiar with: there's no point being a stranger in your own project directory. :-)</p>
<p>Typical things I always have are lib|src, bin, test.</p>
<p>(I dislike these monster generators: the first thing I want to do with a new project is get some code down, not write a README, docs, etc.!)</p>
| 8,028
|
<p>I have a service app that creates AppDomain's during the course of its use for long running tasks. I've been tracking these by storing them in a Hashtable with a unique ID.</p>
<p>After a task is completed the service app then unloads the AppDomain allocated to that task and then it's removed it from the appdomain Hashtable.</p>
<p>Purely from a sanity checking point of view, is there a way I can query the CLR to see what app domains are still loaded by the creating app domain (i.e. so I can compare the tracking Hashtable against what the CLR actually sees)?</p>
|
<p>I found the bug. The line</p>
<pre><code>d1 = create_task(:parent_id => @root.id, :sort_order => 2)
</code></pre>
<p>creates d1. This calls the <code>before_save</code> callback, which in turn calls <code>self.children</code>. As Orion pointed out, this caches the children of d1.</p>
<p>However, at this point, d1 doesn't have any children yet. So d1's cache of children is empty.</p>
<p>Thus, when I try to destroy d1, the program tries to destroy d1's children. It encounters the cache, finds that it is empty, and a result doesn't destroy d2, d3, and d4.</p>
<p>I solved this by changing the task creations like this:</p>
<pre><code>@root.children << (d1 = new_task(:sort_order => 2))
@root.save!
</code></pre>
<p>This worked so I'm ok with it :) I think it is also possible to fix this by either reloading d1 (<code>d1.reload</code>) or self.children (<code>self.children(true)</code>) although I didn't try any of these solutions.</p>
|
<p><code>children</code> <a href="http://github.com/rails/acts_as_tree/tree/master/lib/active_record/acts/tree.rb#L47" rel="nofollow noreferrer">is a simple has_many association</a></p>
<p>This means, when you call <code>.children</code>, it will load them from the database (if not already present). It will then cache them.</p>
<p>I was going to say that your second 'test' will actually be looking at the cached values not the real database, but that shouldn't happen as you are just using <code>Task.count</code> rather than <code>d1.children.count</code>. Hrm</p>
<p>Have you looked at the logs? They will show you the SQL which is being executed. You may see a mysql error in there which will tell you what's going on</p>
| 20,679
|
<p>I want to make an MVC route for a list of news, which can be served in several formats.</p>
<ul>
<li>news -> (X)HTML</li>
<li>news.rss -> RSS</li>
<li>news.atom -> ATOM</li>
</ul>
<p>Is it possible to do this (the more general "optional extension" situation crops up in several places in my planned design) with one route? Or do I need to make two routes like this:</p>
<pre><code>routes.MapRoute("News-ImplicitFormat",
"news",
new { controller = "News", action = "Browse", format = "" });
routes.MapRoute("News-ExplicitFormat",
"news.{format}"
new { controller = "News", action = "Browse" });
</code></pre>
<p>It seems like it would be useful to have the routing system support something like:</p>
<pre><code>routes.MapRoute("News",
"news(.{format})?",
new { controller = "News", action = "Browse" });
</code></pre>
|
<p>I made a method to support adding pairs like this as follows:</p>
<pre><code>public static void MapRouteWithOptionalFormat(this RouteCollection routes,
string name,
string url,
object defaults)
{
Route implicitRoute = routes.MapRoute(name + "-ImplicitFormat",
url,
defaults);
implicitRoute.Defaults.Add("format", string.Empty);
Route explicitRoute = routes.MapRoute(name + "-ExplicitFormat",
url + ".{format}",
defaults);
}
</code></pre>
|
<p>You can look into using constraints to make this work with normal routes.</p>
<p>UPDATE: actually, I misread the question. The other answer is the correct thing to do for now. Or create a custom route. We're looking at the idea of optional segments as a possible future feature.</p>
| 31,928
|
<p>What's the best algorithm for comparing two arrays to see if they have the same members?</p>
<p>Assume there are no duplicates, the members can be in any order, and that neither is sorted.</p>
<pre><code>compare(
[a, b, c, d],
[b, a, d, c]
) ==> true
compare(
[a, b, e],
[a, b, c]
) ==> false
compare(
[a, b, c],
[a, b]
) ==> false
</code></pre>
|
<p>Obvious answers would be:</p>
<ol>
<li>Sort both lists, then check each
element to see if they're identical</li>
<li>Add the items from one array to a
hashtable, then iterate through the
other array, checking that each item
is in the hash </li>
<li>nickf's iterative search algorithm</li>
</ol>
<p>Which one you'd use would depend on whether you can sort the lists first, and whether you have a good hash algorithm handy.</p>
|
<p>The best I can think of is O(n^2), I guess.</p>
<pre><code>function compare($foo, $bar) {
if (count($foo) != count($bar)) return false;
foreach ($foo as $f) {
foreach ($bar as $b) {
if ($f == $b) {
// $f exists in $bar, skip to the next $foo
continue 2;
}
}
return false;
}
return true;
}
</code></pre>
| 30,457
|
<p>I've been working with Swing for a while now but the whole model/structure of <code>JFrame</code>s, <code>paint()</code>, <code>super</code>, etc is all murky in my mind.
I need a clear explanation or link that will explain how the whole GUI system is organized.</p>
|
<p>The same happened to me. Actually to this day I don't quite get 100% how all it works.</p>
<p>Swing is a very flexible framework - perhaps too flexible. With flexibility comes a lot of abstraction and with abstraction comes confusion. :)</p>
<p>I've found the following articles worth reading. They helped me to better understand the big picture of Swing.</p>
<ul>
<li><a href="http://www.oracle.com/technetwork/java/architecture-142923.html" rel="nofollow noreferrer">A Swing Architecture Overview</a></li>
<li><p><a href="https://web.archive.org/web/20110815102419/http://java.sun.com/products/jfc/tsc/articles/architecture/ui_install/index.html" rel="nofollow noreferrer">The process of installing a UI delegate</a>, which is just this image:</p>
<p><a href="https://web.archive.org/web/20110815102419/http://java.sun.com/products/jfc/tsc/articles/architecture/ui_install/index.html" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mvJiZ.png" alt="The process of installing a UI delegate"></a></p></li>
</ul>
<p>They explain quite well how the model and the delegate work. It always drives me mad when I see those <code>JLabel</code>, <code>LabelUI</code>, <code>ui.update</code>, etc.</p>
|
<p><a href="http://filthyrichclients.org/" rel="nofollow noreferrer">Filthy Rich Clients</a> by Chet Haase and Romain Guy is a great book about Java UI. It covers some more advanced stuff too, but introduction and few first chapters explain fundamental things well.</p>
| 48,365
|
<p>I work on an application that uses DCOM to communicate between what are essentially several peers; in the course of normal use, instances on separate machines serve a variety of objects to one another. Historically, for this to work we have used some magic incantations, chief among which is that on every machine the user must log into an account of the same name (note that these are local accounts; there is no domain available). Obviously, this is an aspect of our user experience that could be improved.</p>
<p>I would like to better understand how DCOM authentication works, but I am having difficulty assembling the whole story from the MSDN documentation for <a href="http://msdn.microsoft.com/en-us/library/ms693736.aspx" rel="nofollow noreferrer">CoInitializeSecurity()</a>, <a href="http://msdn.microsoft.com/en-us/library/ms692692.aspx" rel="nofollow noreferrer">CoSetProxyBlanket()</a>, and the like. Are there any thorough explanations available of how, exactly, DCOM operations are accepted or denied? Books, journals, web, any format is fine.</p>
|
<p><em>Programming Windows Security</em> by Keith Brown includes a thorough discussion of DCOM security. I can highly recommend this book.</p>
|
<p>You could also try to round up a copy of <em>Inside Distributed COM</em> by Guy and Henry Eddon (Microsoft Press) - It is out of print but amazon shows a number of used copies for sale:</p>
<p><a href="https://rads.stackoverflow.com/amzn/click/com/157231849X" rel="nofollow noreferrer" rel="nofollow noreferrer">http://www.amazon.com/Inside-Distributed-Com-Mps-Eddon/dp/157231849X/ref=sr_1_5?ie=UTF8&s=books&qid=1231968553&sr=8-5</a></p>
| 7,229
|
<p>I have a DAV server (Oracle Portal in this case). If I open word and then enter the DAV URL of a document, I'm correctly prompted for username/password and the document is checked out. I can edit it and just click Save to save it back to the server. So far, so good.</p>
<p>What I need is a link on a web page that will open the document for editing in Word. If I just use the same URL as I use in the File Open dialog in Word, I get a read-only copy, and the File Save dialog suggests to save it locally. </p>
<p>Is there a way to open a document for DAV editing directly from a hyperlink? </p>
|
<p>According to <a href="http://www.gossamer-threads.com/lists/zope/dev/217568?page=last" rel="nofollow noreferrer">this thread</a>, you should be able to get DAV supported by adding special headers to your response so that word knows that it is editable via DAV.</p>
|
<p>No. The dav protocol uses standard HTTP transactions, and unless the client is aware of the support for DAV, it won't know to use it.</p>
<p>Word is likely not DAV aware, and you're relying on people mounting DAV devices as a mounted network drive. </p>
<p>IE: As far as words concerned, its just like any other URL.</p>
<p>( Unless there is a way to tell word its specifically on a DAVFS system, via a url with a different protocol specifier, for example davfs://www.google.com/ if davfs happened to be a registered protocol that your client recognised, this of course makes too much sense, and for that reason alone, you are unlikely to find it supported in windows ) </p>
| 35,064
|
<p>I have read in some of the ClickOnce posts that ClickOnce does not allow you to create a desktop icon for you application. Is there any way around this?</p>
|
<p>In Visual Studio 2005, <a href="http://en.wikipedia.org/wiki/ClickOnce" rel="noreferrer">ClickOnce</a> does not have the ability to create a desktop icon, but it is now available in Visual Studio 2008 SP1. In Visual Studio 2005, you can use the following code to create a desktop icon for you when the application starts.</p>
<p>I have used this code over several projects for a couple of months now without any problem. I must say that all my applications have been deployed over an intranet in a controlled environment. Also, the icon is not removed when the application is uninstalled. This code creates a shortcut to the shortcut on the start menu that ClickOnce creates.</p>
<pre><code>private void CreateDesktopIcon()
{
ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;
if (ad.IsFirstRun)
{
Assembly assembly = Assembly.GetEntryAssembly();
string company = string.Empty;
string description = string.Empty;
if (Attribute.IsDefined(assembly, typeof(AssemblyCompanyAttribute)))
{
AssemblyCompanyAttribute ascompany =
(AssemblyCompanyAttribute)Attribute.GetCustomAttribute(
assembly, typeof(AssemblyCompanyAttribute));
company = ascompany.Company;
}
if (Attribute.IsDefined(assembly, typeof(AssemblyDescriptionAttribute)))
{
AssemblyDescriptionAttribute asdescription =
(AssemblyDescriptionAttribute)Attribute.GetCustomAttribute(
assembly, typeof(AssemblyDescriptionAttribute));
description = asdescription.Description;
}
if (!string.IsNullOrEmpty(company))
{
string desktopPath = string.Empty;
desktopPath = string.Concat(
Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
"\\",
description,
".appref-ms");
string shortcutName = string.Empty;
shortcutName = string.Concat(
Environment.GetFolderPath(Environment.SpecialFolder.Programs),
"\\",
company,
"\\",
description,
".appref-ms");
System.IO.File.Copy(shortcutName, desktopPath, true);
}
}
}
}
</code></pre>
|
<p>The desktop icon can be a shortcut to the <code>.application</code> file. Install this as one of the first things your application does.</p>
| 18,355
|
<p>I get obsessed with the best names for arrays and variables that I use, I'll look up words in the thesaurus, dictionary, etc..</p>
<p>So I'm trying to name this array / structure:</p>
<pre><code>$nameMe = array(
'392' => TRUE,
'234' => TRUE,
'754' => TRUE,
'464' => TRUE,
);
</code></pre>
<p>and it's used to check if that id has a certain property, like so</p>
<pre><code>if(isset($name[$id])) {
doSomething();
}
</code></pre>
<p>Problem being I'm getting really long variable names like</p>
<pre><code>$propertyNameArrayIdIndexed
</code></pre>
<p>Any ideas for how I can better name this particular function of array? or better names in general</p>
|
<pre><code>$hasProperty[$id]
</code></pre>
<p>or</p>
<pre><code>$isSomething[$id]
</code></pre>
<p>What is the property exactly?</p>
<pre><code>$isOdd[$id]
$isWriteable[$id]
$hasAssociatedFile[$id]
</code></pre>
|
<p>propertyNameable, IspropertyNameable.</p>
| 24,884
|
<p>How would I compile the latest version of GTK# for Windows without using cygwin?</p>
<p>Any and All help would be appreciated.</p>
|
<p>Well, if you have to have a more recent version, Medsphere provide a <a href="http://medsphere.org/projects/gtksharp/wiki" rel="nofollow noreferrer">newer version</a>, and <a href="http://medsphere.org/projects/gtksharp/wiki/CompilingGtkSharpOnCygwin" rel="nofollow noreferrer">building instructions</a> and there is a <a href="http://www.mail-archive.com/gtk-sharp-list@lists.ximian.com/msg03432.html" rel="nofollow noreferrer">load of information here</a>.</p>
<p>Sounds like some people have built 2.12</p>
|
<p>Why would you need Cygwin to compile C# code?</p>
| 32,724
|
<p>So I have an object which has some fields, doesn't really matter what.
I have a generic list of these objects.</p>
<pre><code>List<MyObject> myObjects = new List<MyObject>();
myObjects.Add(myObject1);
myObjects.Add(myObject2);
myObjects.Add(myObject3);
</code></pre>
<p>So I want to remove objects from my list based on some criteria.
For instance, <code>myObject.X >= 10.</code>
I would like to use the <code>RemoveAll(Predicate<T> match)</code> method for to do this.</p>
<p>I know I can define a delegate which can be passed into RemoveAll, but I would like to know how to define this inline with an anonymous delegate, instead of creating a bunch of delegate functions which are only used in once place.</p>
|
<p>There's two options, an explicit delegate or a delegate disguised as a lamba construct:</p>
<p>explicit delegate</p>
<pre><code>myObjects.RemoveAll(delegate (MyObject m) { return m.X >= 10; });
</code></pre>
<p>lambda</p>
<pre><code>myObjects.RemoveAll(m => m.X >= 10);
</code></pre>
<hr />
<p>Performance wise both are equal. As a matter of fact, both language constructs generate the same IL when compiled. This is because C# 3.0 is basically an extension on C# 2.0, so it compiles to C# 2.0 constructs</p>
|
<p>Predicate is a delegate which takes an param and returns a boolean.</p>
<p>We can do the same in following ways</p>
<p>1) <strong>Using inline Lambda expression</strong></p>
<pre><code>RemoveAll(p=> p.x > 2);
</code></pre>
<p>2) <strong>Using anonymous function</strong></p>
<pre><code>RemoveAll(delegate(myObject obj){
return obj.x >=10;
})
</code></pre>
<p>3) <strong>Using Predicate delegate</strong></p>
<pre><code>Predicate<myObject> matches = new Predicate<myObject>(IsEmployeeIsValid);
RemoveAll(matches);
Predicate<Foo> matches = delegate(Foo o){ return o.X >= 20; });
RemoveAll(matches);
</code></pre>
<p>3) <strong>Declaring a delegate explicitily and pointing to a function</strong></p>
<pre><code>public delegate bool IsInValidEmployee (Employee emp);
IsInValidEmployee invalidEmployeeDelegate = new IsInValidEmployee(IsEmployeeInValid);
myObjects.RemoveAll(myObject=>invalidEmployeeDelegate(myObject);
</code></pre>
<p>// Actual function</p>
<pre><code>public static bool IsEmployeeInValid(Employee emp)
{
if (emp.Id > 0 )
return true;
else
return false;
}
</code></pre>
| 8,366
|
<p>Would there a more elegant way of writing the following syntax? </p>
<pre><code> Thread t0 = new Thread(new ParameterizedThreadStart(doWork));
t0.Start('someVal');
t0.Join();
Thread t1 = new Thread(new ParameterizedThreadStart(doWork));
t1.Start('someDiffVal');
t1.Join();
</code></pre>
<p>Presuming we want to pass 20 different values, what would the best way of setting this up be? Looping through and joining at the end?</p>
<p>If a new thread isn't instantiated (like below), it errors that the thread can't be restarted. For example:</p>
<pre><code> Thread t1 = new Thread(new ParameterizedThreadStart(doWork));
t1.Start('someVal');
t1.Start('someDiffVal');
</code></pre>
|
<p>Why would you start a thread and then join against it immediately?</p>
<p>I'd normally do something like this:</p>
<pre><code>List<Thread> threads = new List<Thread>();
foreach (string item in items)
{
string copy = item; // Important due to variable capture
ThreadStart ts = () => DoWork(copy); // Strongly typed :)
Thread t = new Thread(ts);
t.Start();
threads.Add(t);
}
foreach (Thread t in threads)
{
t.Join();
}
</code></pre>
|
<p>Why not have your parameters be part of the class, make them properties, and have the get/set methods lock around them? If you have enough parameters, make the parameter object itself a property of the object, and then lock that parameter block. As in:</p>
<pre><code>class GonnaDoSomeThreading {
private Object mBlockLock = new Object();
private MyParameterBlock mBlock;
public MyParameterBlock Block {
get {
MyParameterBlock tmp;
lock (mBlockLock){
tmp = new MyParameterBlock(mBlock); //or some other cloning
}
return tmp; //use a tmp in order to make sure that modifications done
//do not modify the block directly, but that modifications must
//be 'committed' through the set function
}
set { lock (mBlockLock){ mBlock = value; } }
}
}
</code></pre>
<p>And then do your thread pool as already suggested. That way, you've got locks around the data access, so that if all of your threads need it, they can wait on one another.</p>
<p>If you're doing this for something like image processing (where a lot of parallel objects can be done at once), then it might be better to break up your data into individualized chunks. IE, say you want to run some convolution over a largish image, and so want to break it up into two halves. Then, you can have a 'Fragmentimage' function which creates the image blocks that you're going to work on individually, and then a 'MergeFragments' function call to join all the results. So your fragment could look like:</p>
<pre><code>class ThreadWorkFragment {
<image type, like ushort>[] mDataArray;
bool mDone;
}
</code></pre>
<p>Put a lock around that fragment (ie, a list of objects and fragments, with each having a lock and so forth), so that when the thread accesses it's fragment, it can eventually state that it's 'done', release the lock, and then you can have a final merge function which just waits for those done booleans to be flagged. That way, if one of the threads dies before setting done, and you know the thread's dead, then you also know that the thread didn't finish its work and you need to do some error recovery; if you just wait for a join to happen, the thread could still have messed up its fragment.</p>
<p>But there's a lot of those kinds of specific ideas to implement, based on the problem you're trying to solve.</p>
| 31,823
|
<p>I understand there is a HTTP response header directive to disable page caching:</p>
<pre><code>Cache-Control:no-cache
</code></pre>
<p>I can modify the header by "hand":</p>
<pre><code> <%response.addHeader("Cache-Control","no-cache");%>
</code></pre>
<p>But is there a "nice" way to make the JSP interpreter return this header line in the server response?</p>
<p>(I checked the <%@page ...%> directive. It seems there is nothing like that.)</p>
|
<p>Also add </p>
<pre>
response.addHeader("Expires","-1");
response.addHeader("Pragma","no-cache");
</pre>
<p>to your headers and give that a shot. </p>
|
<p>If you were using a servlet, then I believe what you posted in the question would be the correct approach. I'm not aware of any way to do this in the JSP.</p>
| 19,584
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.