instruction
stringlengths 21
27.8k
| chosen
stringlengths 18
28.2k
| rejected
stringlengths 18
33.6k
| __index_level_0__
int64 0
50k
|
|---|---|---|---|
<p>Im in the situation that I often send small codesnippets and xml-snippets to coworkers and partners via my outlook.
Has anyone got a good idea or tool that I can use to have my pastes syntaxhighlighted before I paste them into an email.</p>
<p>I was thinking of an intermediate paste to "$fancytool" and then I would have something to copy that will htmlified so I can copy paste it into the "compose email" window.</p>
<p><em>Edit-More-info:</em></p>
<p>Im pasting from windows within a VMWare virtual Machine, it might be eclipse, xmlspy, logfiles and other programs</p>
<p><em>Even-more-info:</em></p>
<p>I've seen <a href="http://vim.wikia.com/wiki/Pasting_code_with_syntax_coloring_in_emails" rel="noreferrer">this link</a> how to do it from Vim. Unfortunately it seldom from vim im copying Code, and my email machine hasnt got any vim. The vmware machines has gvim, but I was hoping for an easier way that pasting to vim, saving to file, opening in internetexplorer and then copy/paste</p>
|
<p>Late but I can give an answer that works.
You need 2 things</p>
<ol>
<li>putty</li>
<li>access to some Unix server (With vim)</li>
</ol>
<p>In putty options, Under window → selection , turn the check box on for </p>
<p><code>Paste in to clipboard in RTF as well as plain text</code>.</p>
<p>Log on to the server using putty.
start vim by typing vim
Paste your text (for example XML ) in to vim.
enter command mode (of vim by pressing <kbd>ESC</kbd>) and type
<code>:set syn=xml</code>.</p>
<p>Syntax highlighting kicks in.
Copy the text using mouse and paste it into your email.</p>
|
<p>If you're on Windows, Visual Studio does this automatically. At least it does for me, using Visual Studio 2005 on XP and copy/pasting to both MS Word and Lotus Notes</p>
| 27,917
|
<p>I am trying to make one field in a datagrid editable with a numeric stepper. My current attempts look like they are working, but the dataProvider is not actually being changed.</p>
<p>Based on what I have read in a billion different places, the syntax should be </p>
<pre>< mx:DataGridColumn dataField="a" itemRenderer="mx.controls.NumericStepper" rendererIsEditor="true" editorDataField="value" / > </pre>
<p>I have tried several variations on this theme, and nothing seems to work. What am I missing?</p>
|
<p>You need to select only the item's row for removal. I'm not sure how you have it set up, but if the image element is inside the row you could use:</p>
<pre><code> $("img.delete").click(function() {
var row = $(this).parents('tr:first');
...
success: function(){
$(row).remove(); //Remove the row containing the image element
...
}
...
});
</code></pre>
|
<p>If it is the html id-attribute you want, then that would work. Why don't you try it?</p>
<p>EDIT: It might be just row.attr('id'); It have slipped from my mind, havn't ben using jQuery for sometime :)</p>
| 49,121
|
<p>I'm trying to find a way to get the open tasks in C#. I've been searching on google and can only find how to get a list of the <strong>processes</strong>. I want the only the tasks that would show up on the taskbar.</p>
<p>Also, along with that, it would be cool if I could get the process the task is associated with. And if possible get the thumbnail images that Vista uses for the ALT-TAB menu, like in this image:</p>
<p><a href="https://i.stack.imgur.com/CcPQP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CcPQP.png" alt="alt-tab"></a></p>
<p>I assume that I will have to use pinvokes because it really doesn't look like there are any libraries to do this already. Any ideas?</p>
|
<p>This article should pretty much tell you exactly what to do, it shows how to build your own task switch and includes the code needed to enumerate all windows and determine if they are "tasks" and it shows you how to use PrintWindow api to get the previews on XP.</p>
<p><a href="http://msdn.microsoft.com/en-us/library/ms997649.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ms997649.aspx</a></p>
<p>Also, here is <a href="http://blogs.msdn.com/oldnewthing/archive/2007/10/08/5351207.aspx" rel="nofollow noreferrer">a blog post</a> that talks about the algorithm used to determine what shows up in the Alt+Tab view. Basically you need to check the WS_EX_APPWINDOW and WS_EX_TOOLWINDOW along with if the window has an owner.</p>
|
<p>@abelenky17</p>
<p>I suspect that this will not cover all cases, for example there are processes who have several top level windows (that all appear in the task manager).
Consider for example: FireFox, Windows Explorer, IE, etc... those applications can have multiple windows on the desktop.
Also, it will not handle Terminal Sessions scenario's properly (because you enumerate all the processes running in the system).</p>
<p>@Dan C.</p>
<p>Doing something like this:</p>
<pre><code>p.ProcessName != "explorer"
</code></pre>
<p>seems ok to you? It smells, bad.</p>
| 39,999
|
<p>I get an error everytime I upload my webapp to the provider. Because of the customErrors mode, all I see is the default "Runtime error" message, instructing me to turn off customErrors to view more about the error.</p>
<p>Exasperated, I've set my web.config to look like this:</p>
<pre><code><?xml version="1.0"?>
<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>
</code></pre>
<p>And still, all I get is the stupid remote errors page with no useful info on it.
What else can I do to turn customErrors OFF ?!</p>
|
<p>This has been driving me insane for the past few days and couldn't get around it but have finally figured it out:</p>
<p>In my machine.config file I had an entry under <code><system.web></code>:</p>
<pre><code><deployment retail="true" />
</code></pre>
<p>This seems to override any other customError settings that you have specified in a web.config file, so setting the above entry to:</p>
<pre><code><deployment retail="false" />
</code></pre>
<p>now means that I can once again see the detailed error messages that I need to.</p>
<p>The <code>machine.config</code> is located at</p>
<p><strong>32-bit</strong></p>
<pre><code>%windir%\Microsoft.NET\Framework\[version]\config\machine.config
</code></pre>
<p><strong>64-bit</strong></p>
<pre><code>%windir%\Microsoft.NET\Framework64\[version]\config\machine.config
</code></pre>
<p>Hope that helps someone out there and saves a few hours of hair-pulling.</p>
|
<p>It may not be IIS!</p>
<p>I went through all of the answers on this page, as well as several more. None of them solved our issue, BUT they are good things to check and WILL cause problems. SO check those first. If you're still pulling your hair out, and you're using PHP, check your PHP settings.</p>
<p>What fixed it for me was to edit our php.ini file and specify:</p>
<pre><code>display_errors: On
</code></pre>
<p>I also set:</p>
<pre><code>display_startup_errors: On
</code></pre>
<p>just for good measure.</p>
<p>That fixed the problem, and our real issue turned out to be a missed comma that was missed during dev to stage migration.</p>
<p>I realize this page was linked to asp.net, which we were ALSO using, and this is not an asp.net issue, but when you search for these errors, this page comes up and has some good info for fixing most common problems; just not our specific issue. The config changes did fix it, and then we could concentrate on our asp.net files!</p>
| 12,715
|
<p>Ran into this problem today, posting in case someone else has the same issue.</p>
<pre><code>var execBtn = document.createElement('input');
execBtn.setAttribute("type", "button");
execBtn.setAttribute("id", "execBtn");
execBtn.setAttribute("value", "Execute");
execBtn.setAttribute("onclick", "runCommand();");
</code></pre>
<p>Turns out to get IE to run an onclick on a dynamically generated element, we can't use setAttribute. Instead, we need to set the onclick property on the object with an anonymous function wrapping the code we want to run.</p>
<pre><code>execBtn.onclick = function() { runCommand() };
</code></pre>
<p><strong>BAD IDEAS:</strong></p>
<p>You can do </p>
<pre><code>execBtn.setAttribute("onclick", function() { runCommand() });
</code></pre>
<p>but it will break in IE in non-standards mode according to @scunliffe.</p>
<p>You can't do this at all </p>
<pre><code>execBtn.setAttribute("onclick", runCommand() );
</code></pre>
<p>because it executes immediately, and sets the result of runCommand() to be the onClick attribute value, nor can you do</p>
<pre><code>execBtn.setAttribute("onclick", runCommand);
</code></pre>
|
<p>to make this work in both FF and IE you must write both ways:</p>
<pre><code>
button_element.setAttribute('onclick','doSomething();'); // for FF
button_element.onclick = function() {doSomething();}; // for IE
</code></pre>
<p>thanks to <a href="http://mcarthurgfx.com/blog/article/assigning-onclick-with-new-element-breaks-in-ie" rel="noreferrer">this post</a>.</p>
<p><strong>UPDATE</strong>:
This is to demonstrate that sometimes it <em>is</em> necessary to use setAttribute! This method works if you need to take the original onclick attribute from the HTML and add it to the onclick event, so that it doesn't get overridden:</p>
<pre><code>// get old onclick attribute
var onclick = button_element.getAttribute("onclick");
// if onclick is not a function, it's not IE7, so use setAttribute
if(typeof(onclick) != "function") {
button_element.setAttribute('onclick','doSomething();' + onclick); // for FF,IE8,Chrome
// if onclick is a function, use the IE7 method and call onclick() in the anonymous function
} else {
button_element.onclick = function() {
doSomething();
onclick();
}; // for IE7
}
</code></pre>
|
<p>Did you try:</p>
<pre>
execBtn.setAttribute("onclick", function() { runCommand() });
</pre>
| 12,127
|
<p>I have a linq query and I am trying to put that in to a serializable object for a distributed caching (Velocity) but its failing due to a LINQ-to-SQL lazy list</p>
<p>like so</p>
<pre><code> return from b in _datacontext.MemberBlogs
let cats = GetBlogCategories(b.MemberBlogID)
select new MemberBlogs
{
MemberBlogID = b.MemberBlogID,
MemberID = b.MemberID,
BlogTitle = b.BlogTitle,
BlogURL = b.BlogURL,
BlogUsername = b.BlogUsername,
BlogPassword = b.BlogPassword,
Categories = new LazyList<MemberBlogCategories>(cats)
};
</code></pre>
<p>LazyList is the same class Rob Conery uses in his MVC storefront...</p>
<p>all three classes are marked serializable (MemberBlogs,MemberBlogCategories,LazyList... any ideas?</p>
|
<p>If you are putting it in a distributed cache you will need to avoid the LazyList altogether. You can then call .ToList() around the whole LINQ statement as in:</p>
<pre><code>(from x select new MemberBlogs).ToList()
</code></pre>
<p>This should then be cachable because it forces the queries to be evaluated.</p>
|
<p>I know this is an old post but I had the same issue as I wanted to execute my LazyList and put them into the AppFabric Cache. I ended up putting some custom serialization logic into the LazyList type.</p>
<p>The first part now looks like this:</p>
<pre><code> public class LazyList<T> : IList<T>, ISerializable
{
public LazyList()
{
this.query = new List<T>().AsQueryable();
}
public LazyList(SerializationInfo info, StreamingContext context)
{
try {
this.inner = (List<T>)info.GetValue("InnerList", typeof(List<T>));
}
catch (Exception ex)
{
this.inner = null;
}
}
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
if (this.inner != null)
info.AddValue("InnerList", this.inner.ToList());
}
public LazyList(IQueryable<T> query)
{
this.query = query;
}
public LazyList(List<T> l)
{
inner = l;
}
}
</code></pre>
| 33,409
|
<p>Is there any possibility that GetPropInfo returns nil even if the given class is declared with correct {$METHODINFO} directives.</p>
<pre><code> type
...
...
{$METHODINFO ON}
TMyClass = class
private
fField: integer;
published
property Field: integer read fField write fField;
end;
{$METHODINFO OFF}
...
...
procedure TestRTTI;
begin
assert(assigned(GetPropInfo(TMyClass, 'Field')), 'WTF! No RTTI found!');
end;
</code></pre>
|
<p>Gotcha! It seems the problem is hidden at the forward declaration that I overlooked. Didn't know that sneaky feature. </p>
<p>It seems the compiler considers only the first declaration of the class to generate RTTI or not so if you have a forward declaration like this... </p>
<pre><code> type
TMyClass = class;
...
...
{$METHODINFO ON}
TMyClass = class
private
fField: integer;
published
property Field: integer read fField write fField;
end;
{$METHODINFO OFF}
...
...
procedure TestRTTI;
begin
assert(assigned(GetPropInfo(TMyClass, 'Field')), 'WTF! No RTTI found!');
end;
</code></pre>
<p>... You will get the assertion error. So, for getting the RTTI right, one needs to turn the {$METHODINFO} directive on for the forward declaration, as seen here....</p>
<pre><code> type
{$METHODINFO ON}
TMyClass = class;
{$METHODINFO OFF}
...
...
TMyClass = class
private
fField: integer;
published
property Field: integer read fField write fField;
end;
...
</code></pre>
|
<p>I am glad that you have found a solution. It is the same thing with <code>$TypeInfo</code> directive. Delphi 7 help says:</p>
<blockquote>
<p>Note that if a class is forward declared, the first declaration of the class must be declared with the <code>$M</code> switch.</p>
</blockquote>
<p>P.S.: <code>$M+/- = $TypeInfo On/Off</code></p>
| 44,043
|
<p>How can I detect the current text formatting at the cursor position in a WPF RichTextBox?</p>
|
<p>The author of this thread also asked about TextDecorations where you did not provide sample code and its different to use. I post this as a <strong>further solution</strong>:</p>
<pre><code>var obj = _myText.GetPropertyValue(Inline.TextDecorationsProperty);
if (obj == DependencyProperty.UnsetValue)
IsTextUnderline = false;// mixed formatting
if (obj is TextDecorationCollection)
{
var objProper = obj as TextDecorationCollection;
if (objProper.Count > 0)
IsTextUnderline = true; // all underlined
else
IsTextUnderline = false; // nothing underlined
}
</code></pre>
|
<p>Try the code below where rtb is the RichTextBox:</p>
<pre><code>TextRange tr = new TextRange(rtb.Selection.Start, rtb.Selection.End);
object oFont = tr.GetPropertyValue(Run.FontFamilyProperty);
</code></pre>
| 24,752
|
<p>I am developing an <strong>Isolated Shell</strong> that caters to "<strong>designers/special content creators</strong>" performing specific tasks, using the Shell. As they operate on files, they need to be able to use TFS for source control. This is mainly due to the fact that Developers will also operate on the same files from TFS but using Visual studio 2008.</p>
<p>After looking and searching I still could not find Team Explorer to be available to Shell.
Asking on MSDN forums, lead me to the answer that "this is not supported yet in the Isolated Shell". Well, then the whole point of giving away a shell is not justified, if you want to use a source control system for your files. The idea is not to recreate everything and develop tool windows etc using the TFS provider API.</p>
<p>The <a href="http://nayyeri.net/blog/professional-visual-studio-extensibility-finally-released/" rel="nofollow noreferrer">Visual Studio Extensibility book by Keyven Nayyeri</a> has an example, which only goes so far into this problem of adding a sc provider.</p>
<p>Has anyone worked on developing <strong>Visual Studio 2008 Isolated Shell</strong> applications/environment? Please provide comments, questions - anything that you have to share apart from the following threads, which I've already participated in.</p>
<p>Threads from MSDN forums:</p>
<ul>
<li><a href="http://forums.msdn.microsoft.com/en-US/vsx/thread/34347f72-853a-43cb-ba9e-9d6df718ca13/" rel="nofollow noreferrer">Team Explorer for Isolated Shell</a> </li>
<li><a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3382221&SiteID=1" rel="nofollow noreferrer">Is it possible to use Team Explorer in VS Shell Isolated?</a></li>
</ul>
<hr>
<p>Thanks for your answer. Yes you are right, we will acquire CALs for users without having to buy them Visual Studio, that's the direction we will be taking.</p>
<p>But I am yet to figure out how to make Team Explorer available to such users, inside Shell. So I am looking to find out the technical details of how that can be done.</p>
<p>I mean, I have a user, he installs my VS Shell application, he has no VStudio Team system on his machine. Now if I acquire CAL for TFS and install Team Explorer, do you think it will be automatically available in the VS Shell app?</p>
<p>Any ideas? have you worked on making this happen?</p>
<p>Thanks</p>
|
<p>It sounds like you are trying to allow the "special content creators" save files in TFS Source Control without having to buy them a license to a Visual Studio Team Edition -- correct me if I'm wrong.</p>
<p>If that's the case, unfortunately I believe that you can't quite do that. Your users still need a Client Access License ("CAL") to access TFS.</p>
<p>I think that you can acquire just CALs for your users without having to buy Visual Studio for them (I presume for less than a full blown Visual Studio would cost). At that point, you can just distribute to them the Team Explorer, which is a VS shell with nothing but TFS access components. That is available in your TFS server media.</p>
<p>I found this via Google. You might want to review it to decide your best options:</p>
<p><a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=ce194742-a6e8-4126-aa30-5c4e969af2a3&DisplayLang=en" rel="nofollow noreferrer">Visual Studio Team System 2008 Licensing White Paper</a></p>
<p>The only exception to the CAL rules I'm aware of is access to Work Items. Assuming properly licensed servers, anyone in your organization can create new Work Items or view and update existing ones <em>created by them</em>, using the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=faed8359-f54d-480e-8a86-f154d3dea07e&displaylang=en" rel="nofollow noreferrer">Work Item Web Access</a> component.</p>
|
<p>It sounds like you are trying to allow the "special content creators" save files in TFS Source Control without having to buy them a license to a Visual Studio Team Edition -- correct me if I'm wrong.</p>
<p>If that's the case, unfortunately I believe that you can't quite do that. Your users still need a Client Access License ("CAL") to access TFS.</p>
<p>I think that you can acquire just CALs for your users without having to buy Visual Studio for them (I presume for less than a full blown Visual Studio would cost). At that point, you can just distribute to them the Team Explorer, which is a VS shell with nothing but TFS access components. That is available in your TFS server media.</p>
<p>I found this via Google. You might want to review it to decide your best options:</p>
<p><a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=ce194742-a6e8-4126-aa30-5c4e969af2a3&DisplayLang=en" rel="nofollow noreferrer">Visual Studio Team System 2008 Licensing White Paper</a></p>
<p>The only exception to the CAL rules I'm aware of is access to Work Items. Assuming properly licensed servers, anyone in your organization can create new Work Items or view and update existing ones <em>created by them</em>, using the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=faed8359-f54d-480e-8a86-f154d3dea07e&displaylang=en" rel="nofollow noreferrer">Work Item Web Access</a> component.</p>
| 4,156
|
<p>I am building a ASP.NET website, and when I click the START DEBUGGING icon, it runs Internet Explorer as the account that I ran Visual Studio with. </p>
<p>I would like to run IE as a different user when debugging.</p>
|
<p>You can use the runas command to run IE as a different user for running your app. Later attach to the asp.net worker process when you want to debug.</p>
<p>If you want to just change the credentials for Integrated Authentication, try the setting in the update below.</p>
<p><strong>Update</strong>: If you want IE to prompt for a user name and password, try this setting:</p>
<p>For IE 7, set this option for your zone:</p>
<p>Tools> Internet Options > Security > custom level (for your zone)> User Authentication> Logon > prompt for user name and password</p>
|
<p>@Gulzar is on to something, except that as long as you start the debugger (it will fire up the browser, that's ok, just don't close it), then start up IE (or Firefox) using runas as another user and point it to the localhost URL shown in the debugger-started browser, you should be able to interact with the application using the other ID. And the debugger should work as expected.</p>
| 31,405
|
<p>Why don't we get compile errors on inline code errors in asp.net mvc views f.eks</p>
<pre><code><h1><%= ViewData.Model.Title.Tostrig() %></h1>
</code></pre>
<p>The code above will build just fine. Wrong spelling in webform controls will give you an error so I can't see why this isn't supported in asp.net mvc</p>
<p>EDIT:
Luckily there seem to be a fix included in the first RC for asp.net mvc
<a href="http://weblogs.asp.net/scottgu/archive/2008/12/19/asp-net-mvc-design-gallery-and-upcoming-view-improvements-with-the-asp-net-mvc-release-candidate.aspx" rel="nofollow noreferrer">http://weblogs.asp.net/scottgu/archive/2008/12/19/asp-net-mvc-design-gallery-and-upcoming-view-improvements-with-the-asp-net-mvc-release-candidate.aspx</a></p>
|
<p>The ASPX files in both ASP.NET and ASP.NET MVC are not compiled from the Visual Studio IDE. This is often the cause for "false positives" as you have pointed out. </p>
<p>I often add the <a href="http://msdn.microsoft.com/en-us/library/ms229863(VS.80).aspx" rel="nofollow noreferrer">aspnet_compiler</a> as a post build action to find those errors. You will add some time to your build process, but in exchange for the wait you should be able to spot these errors more easily.</p>
|
<p>You can see </p>
<p><a href="http://odetocode.com/blogs/scott/archive/2006/10/17/8190.aspx" rel="nofollow noreferrer">http://odetocode.com/blogs/scott/archive/2006/10/17/8190.aspx</a></p>
| 45,257
|
<p>I have a xml build of</p>
<pre><code><elig>
<subscriber code="1234"/>
<date to="12/30/2004"
from="12/31/2004"/>
<person name="bob"
ID="654321"/>
<dog type="labrador"
color="white"/>
<location name="hawaii"
islandCode="01"/>
</subscriber>
</elig>
</code></pre>
<p>In XSL I have:</p>
<pre><code><xsl:template match="subscriber">
<xsl:for-each select="date">
<xsl:apply-templates match="person" />
<xsl:apply-templates match="location" />
<xsl:apply-templates match="dog" />
</xsl:for-each>
</xsl:template>
</code></pre>
<p>The problem I have is that I need the location block in between the person and the dog block. I have tried ../ and it does not work. I simplified this majorly but the point comes across. I can't seem to remember what I need to place in front of location to get it to work. Thanks.</p>
|
<p>First of all your XML is still not well-formed and I actually cannot catch why you're looping over the <code><date/></code> tags - there is only one <code><date/></code> tag inside <code><subscriber/></code> (assuming that the first <code><subscriber/></code> should not be self-closed).</p>
<p>When using XPath you alway have to think about the context in which the XPatch is called. The following should do it (when my assumption about your data structure is correct):</p>
<pre><code><xsl:template match="subscriber">
<xsl:for-each select="date">
<!-- from here on we're in the context of the date-tag -->
<xsl:apply-templates match="../person" />
<xsl:apply-templates match="../location" />
<xsl:apply-templates match="../dog" />
</xsl:for-each>
</xsl:template>
</code></pre>
|
<p>In this case, isn't it more logical to move the apply-template calls outside the for-each loop? Since the person, location and dog elements are children of the subscriber, they should be processed within the scope of the subscriber, instead of in the scope of the date.</p>
<p>I.e.:</p>
<pre><code><xsl:template match="subscriber">
<xsl:for-each select="date">
<!-- Perform the processing of the date tags here-->
</xsl:for-each>
<xsl:apply-templates match="person" />
<xsl:apply-templates match="location" />
<xsl:apply-templates match="dog" />
</xsl:template>
</code></pre>
| 33,320
|
<p>I'd like to make a click event fire on an <code><input type="file"></code> tag programmatically.</p>
<p>Just calling click() doesn't seem to do anything or at least it doesn't pop up a file selection dialog.</p>
<p>I've been experimenting with capturing events using listeners and redirecting the event, but I haven't been able to get that to actually perform the event like someone clicked on it.</p>
|
<p>I have been searching for solution to this whole day. And these are the conclusions that I have made:</p>
<ol>
<li>For the security reasons Opera and Firefox don't allow to trigger file input.</li>
<li>The only convenient alternative is to create a "hidden" file input (using opacity, not "hidden" or "display: none"!) and afterwards create the button "below" it. In this way the button is seen but on user click it actually activates the file input.</li>
</ol>
<p>Hope this helps! :)</p>
<pre><code><div style="display: block; width: 100px; height: 20px; overflow: hidden;">
<button style="width: 110px; height: 30px; position: relative; top: -5px; left: -5px;"><a href="javascript: void(0)">Upload File</a></button>
<input type="file" id="upload_input" name="upload" style="font-size: 50px; width: 120px; opacity: 0; filter:alpha(opacity=0); position: relative; top: -40px;; left: -20px" />
</div>
</code></pre>
|
<p>You can use</p>
<pre><code><button id="file">select file</button>
<input type="file" name="file" id="file_input" style="display:none;">
<script>
$('#file').click(function() {
$('#file_input').focus().trigger('click');
});
</script>
</code></pre>
| 25,859
|
<p>I'm auditing our existing web application, which makes heavy use of <a href="http://www.w3schools.com/HTML/html_frames.asp" rel="nofollow noreferrer">HTML frames</a>. I would like to download all of the HTML in each frame, is there a method of doing this with <a href="http://www.gnu.org/software/wget/" rel="nofollow noreferrer">wget</a> or a little bit of scripting?</p>
|
<p>as an addition to Steve's answer:</p>
<p>Span to any host—‘-H’</p>
<p>The ‘-H’ option turns on host spanning, thus allowing Wget's recursive run to visit any host referenced by a link. Unless sufficient recursion-limiting criteria are applied depth, these foreign hosts will typically link to yet more hosts, and so on until Wget ends up sucking up much more data than you have intended. </p>
<p>Limit spanning to certain domains—‘-D’</p>
<p>The ‘-D’ option allows you to specify the domains that will be followed, thus limiting the recursion only to the hosts that belong to these domains. Obviously, this makes sense only in conjunction with ‘-H’. </p>
<p>A typical example would be downloading the contents of ‘www.server.com’, but allowing downloads from ‘images.server.com’, etc.:</p>
<pre><code> wget -rH -Dserver.com http://www.server.com/
</code></pre>
<p>You can specify more than one address by separating them with a comma, </p>
<p>e.g. ‘-Ddomain1.com,domain2.com’. </p>
<p>taken from: <a href="http://www.gnu.org/software/wget/manual/html_node/Spanning-Hosts.html#Spanning-Hosts" rel="noreferrer">wget manual</a></p>
|
<pre><code>wget --recursive --domains=www.mysite.com http://www.mysite.com
</code></pre>
<p>Which indicates a recursive crawl should also traverse into frames and iframes. Be careful to limit the scope of recursion only to your web site since you probably don't want to crawl the whole web.</p>
| 14,230
|
<p>So I'm teaching myself Ruby on Rails, with a PHP background. I've written a sloppy, proof-of-concept PHP application called "<a href="http://rezich.com/storybored" rel="nofollow noreferrer">2NDP.</a>" I want to re-create this in Ruby on Rails (but more basic, more clean, and with a better interface), so I can learn some of the basics.</p>
<p>2NDP is a website where you can basically write your own "Choose-Your-Own-Adventure" books, but collaboratively, with other people. The way I made this work with PHP/MySQL is, I had a table of stories and a table of pages. The pages would belong to stories (obviously), but each page would have references to up to four other pages by having four separate columns, one for each possible page ID that could be referenced.</p>
<p>So right now in my RoR application, I have "stories" that have "pages" that are associated with them. I need a way to get the pages to reference each other, but the possibility of more than one reference per page (one page may reference up to four other pages).</p>
<p>I really like the "references" thing that RoR has, but is there any way to gracefully implement this sort of system? Keep in mind that my only RoR experience is walking through four tutorials, and I'm trying to re-apply what I've learned with a "real-life application."</p>
|
<p>Rather then having four seperate columns, a separate joining table might be more appropriate. For example:</p>
<p>Pages -> LinkedPages -> Pages</p>
<p>Then you can create a <a href="http://wiki.rubyonrails.org/rails/pages/Beginner+Howto+on+has_many+:through" rel="nofollow noreferrer">has_many through</a> relationship.</p>
<pre><code>class Pages < ActiveRecord::Base
has_many :linked_pages
has_many :pages, :through => :linked_pages
end
class LinkedPages < ActiveRecord::Base
belongs_to :pages, :class_name => "Pages", :foreign_key => "page_id"
belongs_to :linked_pages, :class_name => "Pages", :foreign_key => "linked_id"
end
</code></pre>
<p>Then when using your Page object you can simply say:</p>
<pre><code>my_page.pages
</code></pre>
|
<p>Hates_, that was helpful, but if anyone needs a more in-depth explanation about this sort of thing, <a href="http://blog.hasmanythrough.com/2007/10/30/self-referential-has-many-through" rel="nofollow noreferrer">read about it here</a>.</p>
| 46,246
|
<p>As the title already states, I'm trying to declare a nested function and return a pointer to that function. I want this function 'not' to return a new function pointer which will return the negation of whatever the original function was.</p>
<p>Here is what I have:</p>
<pre><code>someType not( someType original ) {
int isNot( ListEntry* entry ) {
return !original( entry );
}
someType resultFunc = calloc( 1024, 1 );
memcpy( resultFunc, &isNot, 1024 );
return resultFunc;
}
</code></pre>
<p>someType is defined as:</p>
<pre><code>typedef int(*someType)(ListEntry* entry)
</code></pre>
|
<p>Steve, you have a completely wrong mental model of what is a C function. </p>
<pre><code>someType resultFunc = calloc( 1024, 1 );
memcpy( resultFunc, &isNot, 1024 );
</code></pre>
<p>From your code fragment, I can surmise that you think that you can copy function's compiled code into a block of memory, and then reuse it. This kind of thing smells of Lisp, except even in lisp you don't do it that way.</p>
<p>In fact, when you say "&isNot", you get a pointer to function. Copying the memory that pointer points at is counterproductive - the memory was initialized when you loaded your executable into memory, and it's not changing. In any case, writing someFunc() would cause a core dump, as the heap memory behing someFunc cannot be executed - this protects you from all sorts of viruses.</p>
<p>You seem to expect an implementation of closures in C. That implementation is simply not there. Unlike Lisp or Perl or Ruby, C cannot preserve elements of a stack frame once you exited that frame. Even is nested functions are permitted in some compilers, I am sure that you cannot refer to non-global variables from inside those functions. The closes thing to closures is indeed C++ object that stores the state and implements operator(), but it's a completely different approach, and you'd still have to do things manually.</p>
<p>Update: <a href="http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Nested-Functions.html#Nested-Functions" rel="noreferrer">here</a> is the relevant portion of GCC documentation. Look for "But this technique works only so long as the containing function (hack, in this example) does not exit."</p>
|
<p>I'm using GCC.</p>
<p>You can turn on nested functions by using the flag:</p>
<pre><code>-fnested-functions
</code></pre>
<p>when you compile.</p>
| 6,174
|
<p>How can I restart(recycle) IIS Application Pool from C# (.net 2)?</p>
<p>Appreciate if you post sample code?</p>
|
<p>If you're on <strong>IIS7</strong> then this will do it if it is stopped. I assume you can adjust for restarting without having to be shown.</p>
<pre><code>// Gets the application pool collection from the server.
[ModuleServiceMethod(PassThrough = true)]
public ArrayList GetApplicationPoolCollection()
{
// Use an ArrayList to transfer objects to the client.
ArrayList arrayOfApplicationBags = new ArrayList();
ServerManager serverManager = new ServerManager();
ApplicationPoolCollection applicationPoolCollection = serverManager.ApplicationPools;
foreach (ApplicationPool applicationPool in applicationPoolCollection)
{
PropertyBag applicationPoolBag = new PropertyBag();
applicationPoolBag[ServerManagerDemoGlobals.ApplicationPoolArray] = applicationPool;
arrayOfApplicationBags.Add(applicationPoolBag);
// If the applicationPool is stopped, restart it.
if (applicationPool.State == ObjectState.Stopped)
{
applicationPool.Start();
}
}
// CommitChanges to persist the changes to the ApplicationHost.config.
serverManager.CommitChanges();
return arrayOfApplicationBags;
}
</code></pre>
<p>If you're on <strong>IIS6</strong> I'm not so sure, but you could try getting the web.config and editing the modified date or something. Once an edit is made to the web.config then the application will restart.</p>
|
<p>Another option:</p>
<pre><code>System.Web.Hosting.HostingEnvironment.InitiateShutdown();
</code></pre>
<p>Seems better than <code>UploadAppDomain</code> which "terminates" the app while the former waits for stuff to finish its work.</p>
| 31,089
|
<p>I have a program I've written in VB.NET 2005, it saves statistics in an XML file. </p>
<p>I use this program on multiple computers. I'd like to set up a webserver where I can upload my XML file, or just the data, and add it to the server ignoring duplicate entries already on the server. </p>
<p>What do I need for to learn for this? SQL? </p>
<p>Any ideas would be appriecated!</p>
|
<p>I did something like this a long time ago to send back HFNetChk XML reports from around the world back to a central server.</p>
<p>I set up a service endpoint on the server (webservice, TCP, whatever fits your req's), and had the client app send the finished XML back to the central server when it was done with its processing. The webserver would send back a "data received OK" message to let the client know it could move on, and then the server would go about processing the data, and entering it from the XML into a SQL database.</p>
<p><strong>So, to answer your question,</strong> learn how to create a WCF service (aim for webservices for now - ASMX is ok if WCF seems to be too much for now), and learn how to parse the incoming XML and insert it into meaningful SQL tables.</p>
<p>/fark can be useful</p>
|
<p>I'll second the recommendation for WCF/asmx services. As for how you store the data it really depends on what you want to do with it, you could leave them as XML or if you want reporting on them, just load them to SQL Server. </p>
| 21,142
|
<p>So I'm programming along in a nice, up to date, object oriented fashion. I regularly make use of the various aspects of OOP that PHP implements but I am wondering when might I need to use closures. Any experts out there that can shed some light on when it would be useful to implement closures?</p>
|
<p>PHP will support closures natively in 5.3. A closure is good when you want a local function that's only used for some small, specific purpose. The <a href="http://wiki.php.net/rfc/closures" rel="nofollow noreferrer">RFC for closures</a> gives a good example:</p>
<pre><code>function replace_spaces ($text) {
$replacement = function ($matches) {
return str_replace ($matches[1], ' ', '&nbsp;').' ';
};
return preg_replace_callback ('/( +) /', $replacement, $text);
}
</code></pre>
<p>This lets you define the <code>replacement</code> function locally inside <code>replace_spaces()</code>, so that it's not:<br />
<strong>1)</strong> cluttering up the global namespace<br />
<strong>2)</strong> making people three years down the line wonder why there's a function defined globally that's only used inside one other function</p>
<p>It keeps things organized. Notice how the function itself has no name, it's simply defined and assigned as a reference to <code>$replacement</code>.</p>
<p>But remember, you have to wait for PHP 5.3 :)</p>
|
<p><strong>Here are examples for closures in php</strong></p>
<pre><code>// Author: HishamDalal@gamil.com
// Publish on: 2017-08-28
class users
{
private $users = null;
private $i = 5;
function __construct(){
// Get users from database
$this->users = array('a', 'b', 'c', 'd', 'e', 'f');
}
function displayUsers($callback){
for($n=0; $n<=$this->i; $n++){
echo $callback($this->users[$n], $n);
}
}
function showUsers($callback){
return $callback($this->users);
}
function getUserByID($id, $callback){
$user = isset($this->users[$id]) ? $this->users[$id] : null;
return $callback($user);
}
}
$u = new users();
$u->displayUsers(function($username, $userID){
echo "$userID -> $username<br>";
});
$u->showUsers(function($users){
foreach($users as $user){
echo strtoupper($user).' ';
}
});
$x = $u->getUserByID(2, function($user){
return "<h1>$user</h1>";
});
echo ($x);
</code></pre>
<p><strong>Output:</strong></p>
<pre><code>0 -> a
1 -> b
2 -> c
3 -> d
4 -> e
5 -> f
A B C D E F
c
</code></pre>
| 17,663
|
<p>I have the SOAP request in an XML file. I want to post the request to the web service in .net
How to implement?</p>
|
<pre class="lang-cs prettyprint-override"><code>var uri = new Uri("http://localhost/SOAP/SOAPSMS.asmx/add");
var req = (HttpWebRequest) WebRequest.CreateDefault(uri);
req.ContentType = "text/xml; charset=utf-8";
req.Method = "POST";
req.Accept = "text/xml";
req.Headers.Add("SOAPAction", "http://localhost/SOAP/SOAPSMS.asmx/add");
var strSoapMessage = @"<?xml version='1.0' encoding='utf-8'?>
<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
<soap:Body><add xmlns='http://tempuri.org/'><a>23</a><b>5</b></soap:Body>
</soap:Envelope>";
using (var stream = new StreamWriter(req.GetRequestStream(), Encoding.UTF8))
stream.Write(strSoapMessage);
</code></pre>
|
<p>You need to post the data over HTTP. Use the <a href="http://msdn.microsoft.com/en-us/library/debx8sh9.aspx" rel="nofollow noreferrer">WebRequest class</a> to post the data. You will need to send other data with the post request to ensure you have a valid SOAP envelope. Read the <a href="http://www.w3.org/TR/soap/" rel="nofollow noreferrer">SOAP spec</a> for all of the details.</p>
| 36,520
|
<p>I want to create a right click context menu for my textboxes to provide the typical copy/paste functionality. Any ideas on how to go about this?</p>
|
<p>Looks like this is a <a href="http://www.wintellect.com/cs/blogs/sporter/archive/2007/12/09/right-click-event-in-silverlight-1-1-2-0.aspx" rel="nofollow noreferrer">way to do this here</a>, <a href="http://blogs.microsoft.co.il/blogs/justinangel/archive/2007/10/22/question-from-silverlight-forums-custom-context-menu-and-mouse-right-click-event.aspx" rel="nofollow noreferrer">another example here</a>, and the <a href="http://blogs.microsoft.co.il/blogs/alex_golesh/archive/2008/02/07/how-to-handle-rightclick-mouse-event-in-silverlight.aspx" rel="nofollow noreferrer">most recent one here</a>. Using these methods you should be able to show your own context menu. Once you have that you'll need access to the clipboard and there is an <a href="http://www.jeff.wilcox.name/2008/05/21/clipboard-access/" rel="nofollow noreferrer">example of this here</a>.</p>
<p>Good luck!</p>
|
<p>The demo in this open source project does just that while supporting nested menus:</p>
<p><a href="http://sl4popupmenu.codeplex.com/" rel="nofollow noreferrer">http://sl4popupmenu.codeplex.com/</a></p>
| 39,063
|
<p>Does anyone know of a good tool to generate the WSDL for a service contract written in C# (i.e. set of methods that are tagged as "[OperationContract]" using WCF)? All the tools I've found work the other way around: create code stubs from a WSDL. I don't want to have to hand-jam a WSDL file. I've found tools for php and J2EE, but not C#. Thanks!</p>
|
<p>Easiest thing to do is host the service with a base address setup, and then just hit it from a browser with "?wsdl" appended to the end. </p>
<p>Here's an example of a service configuration with a base address specified. Note this goes in the <code><configuration><services></code> element in your config:</p>
<pre><code> <service name="MyServiceName" behaviorConfiguration="MyServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:9000/MyService"/>
</baseAddresses>
</host>
<endpoint address="net.tcp://localhost:9001/MyService"
binding="netTcpBinding"
contract="IMyService"
bindingConfiguration="MyServiceBinding"/>
</service>
</code></pre>
<p>Once you get it hosted, just go to <code>http://localhost:9000/MyService?wsdl</code> to see the WSDL definition.</p>
|
<p>Two ways:</p>
<p>a) <strong>Download wsdl file and do below steps</strong>:</p>
<p>i) Open visual studio command prompt as an administrator.</p>
<p>ii) Type below command:</p>
<p>wsdl.exe [path To Your WSDL File]</p>
<p>b) <strong>With endpoint</strong>:</p>
<p>i) Open Visual studio command prompt as an administrator.</p>
<p>ii) type below command:
wsdl.exe <a href="http://localhost:9000/MyService" rel="nofollow noreferrer">http://localhost:9000/MyService</a></p>
| 11,885
|
<p>I work on a medium sized development team that maintains a 8+ years old web application written in Java 1.4.</p>
<p>For new development I always try to convince people to adhere to newer standards and best practices, That goes from simple things like using new naming standards like HtmlImplementation over HTMLImplementation, to things like why it's better to code against an interface versus coding against concrete classes, favor immutability or object composition a over class inheritance.</p>
<p>I have found this rather <a href="https://stackoverflow.com/questions/82672/best-practices-online-resources">generic link in Stackoverflow</a>, which is not Java-oriented nor complete.</p>
<p>I always try to explain the rationale behind my arguments, and always suggest people buy the latest edition of Effective Java, but it's not every developer that takes my word without questioning (which is a good thing). </p>
<p>When that happens, they often ask me for pointers where they could read further about that specific good practice and sometimes I fail to quickly find pointers about that.</p>
<p>Do you have any links to online material I could gather in a "collection" of Best Practices reference, in a way I can always look that up and suggest the "further reading" to my teammates?</p>
|
<p>I really don't think there's anything in the same league as Effective Java. The cost of buying a book is much smaller than the developer time spent reading it (or other material anyway) - so I would strongly recommend going for EJ rather than trying to find anything similar.</p>
<p>There may be an online version of Effective Java - I'm not sure.</p>
<p>I know this probably isn't the advice you wanted to get, but I'm that passionate about the quality of Effective Java :)</p>
|
<p>I use Sun's <a href="http://java.sun.com/reference/blueprints/" rel="nofollow noreferrer">Java BluePrints</a> as a source of best practices. The code samples serve as a "do it like this" standards document. The naming conventions and project conventions are must-reads. </p>
<p>There's some design-pattern stuff there, also, but more importantly, it's a complete "do it like this" set of examples.</p>
| 33,225
|
<p>I am looking for a small wiki engine that is easy to embed into an existing PHP application. Or perhaps a set of libraries to handle all the typical wiki functions.</p>
<p>Currently I am using <a href="http://erfurtwiki.sourceforge.net/" rel="noreferrer">ErfurtWiki</a>, but it is starting to show its age. It hasn't been updated since 2005, and several of the pages on sourceforge appear to have been <a href="http://erfurtwiki.sourceforge.net/MailingList" rel="noreferrer">hacked</a>.</p>
<p>I will be including it with a GPLv2 application so a GPL compatible license is important.</p>
<p>Edit:</p>
<p>To update, mostly I am just looking for text formatting/parser functionality. I want to deal with the storage, security, rev history, etc on my own.</p>
|
<p>I highly recommend <a href="http://www.mediawiki.org/wiki/MediaWiki" rel="noreferrer">MediaWiki</a>, the wiki engine that runs wikipedia.</p>
<p>EDIT: As per your comment, MediaWiki is highly embeddable. I've integrated it in numerous projects over the years.</p>
|
<p>I like DokuWiki, but pmWiki might be better for you. Here's a list of all the PHP wikis: <a href="http://www.wikimatrix.org/search.php?sid=183" rel="nofollow noreferrer">http://www.wikimatrix.org/search.php?sid=183</a></p>
| 43,915
|
<p>I'm using jquery ajax to post updates back to my server. I'm concerned about making sure I have put in place appropriate measures so that only my AJAX calls can post data.</p>
<p>My stack is PHP on Apache against a MySQL backend.</p>
<p>Advice greatly appreciated!</p>
|
<p>Any request that the AJAX calls in your pages can make can also be made by someone outside of the application. If done right, you will not be able to tell if they were made as part of an AJAX call from your webapp or by hand/other means.</p>
<p>There are two scenarios I can think of which you might be talking about when you say you want to make sure that only your AJAX calls can post data: either you don't want a malicious user to be able to post data that interferes with another user's data or you actually want to restrict the posts to being in the "flow" of a multi-request operation. </p>
<p>If you are concerned with the first case (someone posting malicious data to/as another user) the solution is the same whether you are using AJAX or not -- you just have to authenticate the user through whatever means is necessary -- usually via session cookie.</p>
<p>If you are concerned with the second case, then you are going to have to do something like issue a unique token at each step of the process, and store the expected token on the server side. Then when a request is made, check that there is a corresponding entry on the server side for the action that is being taken and that the expected tokens match and that that token has not been used yet. If there is no, you reject the request, if there is, then you mark that token as used and process the request.</p>
<p>If what you are concerned about is something other than one of these two scenarios then the answer will depend on more specifics than you have provided.</p>
|
<p>Use sessions to ensure that any Ajax posts are done in an authenticated context. Think of your Ajax code as just another client to your server, it becomes easier to tackle authentication issues that way.</p>
| 5,932
|
<p>Pretty much as the question asks. Answers preferably in pseudo code and referenced. The correct answer should value speed over simplicity.</p>
|
<p>See <a href="http://www.softsurfer.com/Archive/algorithm_0105/algorithm_0105.htm" rel="nofollow noreferrer">Intersections of Rays, Segments, Planes and Triangles in 3D</a>. You can find ways to triangulate polygons.</p>
<p>If you really need ray/polygon intersection, it's on 16.9 of <a href="http://www.realtimerendering.com/" rel="nofollow noreferrer">Real-Time Rendering</a> (13.8 for 2nd ed).</p>
<blockquote>
<p>We first compute the intersection
between the ray and [the plane of the
ploygon] <code>pie_p</code>, which is easily done
by replacing <code>x</code> by the ray.</p>
</blockquote>
<pre><code> n_p DOT (o + td) + d_p = 0 <=> t = (-d_p - n_p DOT o) / (n_p DOT d)
</code></pre>
<blockquote>
<p>If the denominator <code>|n_p DOT d| < epsilon</code>, where <code>epsilon</code> is very small
number, then the ray is considered
parallel to the polygon plane and no
intersection occurs. Otherwise, the
intersection point, <code>p</code>, of the ray and
the polygon plane is computed: <code>p = o + td</code>. Thereafter, the problem of
deciding whether <code>p</code> is inside the
polygon is reduced from three to two
dimentions...</p>
</blockquote>
<p>See the book for more details.</p>
|
<pre><code>function Collision(PlaneOrigin,PlaneDirection,RayOrigin,RayDirection)
return RayOrigin-RayDirection*Dot(PlaneDirection,RayOrigin-PlaneOrigin)/Dot(PlaneDirection,RayDirection)
end
</code></pre>
<p>(PlaneDirection is the unit vector which is perpendicular to the plane)</p>
| 40,256
|
<p>Is there a built-in way to know if a given session variable is a serialized object? Say I retrieve a value like $_SESSION['foo'], but I don't know if it was originally a string or if it is a serialized object. Is there some way to check, or once serialized does PHP just see a string as a string as a string? </p>
|
<p>It's a pretty common misconception that you have to manually serialize objects before putting them in session. That is not the case. You can simply assign an object instance to a slot in <code>$_SESSION</code>, and PHP will automagically serialize and unserialize it for you, between requests.</p>
|
<p>A string is a string is a string. I think the best you'll be able to do is just try to unserialize it, and if it works, it works. If it doesn't, it doesn't.</p>
<p>The only other option would be to use a regex to see if it "looks" like a serialized object. Just running <code>unserialize()</code> on it might be easier though.</p>
| 34,096
|
<p>I'm working on a system were a user can edit existing objects ("Filter" domain objects to be exact) through a GUI. As a UI hint, we only want to enable the save button if the user really modified something to the object. I was wondering if anyone had any experience with this problem and what the best way would be to approach this.</p>
<p>I was thinking about adding an isDirty() flag to the domain object. When a user starts editing a Filter, I would then make a copy, pass it to the GUI and let the user make modifications to the copy. A binding on the isDirty() flag would then enabled/disable the save button. On saving, the differences would then be merged into the original object and persisted.</p>
<p>Additionaly, I was thinking what would happen if a user undos the changes he made to an object. The isDirty() flag should then return false. So I guess the only way to achieve this is to keep the original value of each property inside the domain object.</p>
<p>Any ideas?</p>
|
<p>Correct!</p>
<p>Additionally,you can expose two methods:
BeginEdit - In this method, your mark your IsDirty Flag to True. Meaning you are doing modification. Call this method when you are about to make modifications</p>
<p>CancelEdit - In this method, reset the IsDirty Flag to False. Meaning you have arborted the edit process and reverted back to the original state. Call this method when cancelling any modifications made.</p>
<p>And once any modifications are persisted, you also reset the IsDirty Flag to False.</p>
<p>I hope this helps.</p>
|
<p>If you have a set of objects which are being edited then you'll probably need something more than a boolean flag for isDirty(). This problem is not dissimilar to reference counting, i.e. increment a dirty count on edit and decrement on undo. If you are supporting undo I suspect you are going to wind up with some pretty hairy logic. I would keep it out of your domain objects.</p>
| 24,520
|
<p>We manufacture artificial corals for aquarium decorations.</p>
<p>We are trying to use 3D scanning and printing to duplicate live corals. Please see attached photos, left is 3D printed model, right is coral molded using resin.</p>
<p>The problem is lacking detail, the real corals have pores (tiny holes).</p>
<p>Can anybody please help to add pores to the 3D printed corals? Maybe using Blender 3D software?</p>
<p><a href="https://i.stack.imgur.com/6o2mq.jpg" rel="nofollow noreferrer" title="3D printed coral is lacking pores (tiny holes)"><img src="https://i.stack.imgur.com/6o2mq.jpg" alt="3D printed coral (left) vs resin molded coral (right)" title="3D printed coral is lacking pores (tiny holes)"></a></p>
<p><a href="https://i.stack.imgur.com/RxHVE.jpg" rel="nofollow noreferrer" title="3D printed coral (left) vs resin molded coral (right)"><img src="https://i.stack.imgur.com/RxHVE.jpg" alt="3D printed coral is lacking pores (tiny holes)" title="3D printed coral (left) vs resin molded coral (right)"></a></p>
|
<p>First thing to check it's, What printer are you using? is FDM or SLA/SLS? Technology used is the great bottleneck to achieve the results that you want to. </p>
<p>Also, going cheap in 3D printing it's a way to get bad results. A good setup it's really important to get a great XY and Z resolution. </p>
<p>FDM it's not able to achieve the same resolution as SLS/SLA has, but it's cheaper.</p>
<p>If you using FDM try reducing wall speed, that will increase the detail level. Using a smaller nozzle and lower layer settings will increase it as well.</p>
<p>EDIT: Also, you need to check in the 3D model how the model is. If the details that you're looking for are not there, there is nothing else to do but start doing it by hand.</p>
|
<p>Perhaps with the scanned data you could import it into some sort of 3D modeling application such as Blender and add the pores either manually or with a modifier. See <a href="https://docs.blender.org/manual/ko/dev/modeling/modifiers/index.html" rel="nofollow noreferrer">Blender - modifiers</a>.</p>
| 681
|
<p>I have two scripts that often need to be run with the same parameter:</p>
<pre><code>$ populate.ksh 9241 && check.ksh 9241
</code></pre>
<p>When I need to change the parameter (<strong>9241</strong> in this example), I can go back and edit the line in history. But since I need to change the number in two places, I sometimes make a typo. I'd like to be able to change the parameter just once to change it in both places.</p>
|
<p>In bash:</p>
<pre><code>!!:gs/9241/9243/
</code></pre>
<p>Yes, it uses <code>gs///</code>, not <code>s///g</code>. :-)</p>
<p>(zigdon's answer uses the last command starting with <code>pop</code>, such as <code>populate.sh</code>. My answer uses the last command, full stop. Choose which works for you.)</p>
|
<p>One solution is to simply create a wrapper script (<em>populate_check.ksh</em>) that calls the scripts in turn:</p>
<pre><code>r=$1
populate.ksh $r && check.ksh $r
</code></pre>
<p>Or for multiple parameters:</p>
<pre><code>for r; do
populate.ksh $r && check.ksh $r
done
</code></pre>
<p>For tasks that are more transient, you can also parametrize the command so that it's easier to edit in history:</p>
<pre><code>$ r=9241; populate.ksh $r && check.ksh $r
</code></pre>
<p>Or to do several at once:</p>
<pre><code>$ for r in 9241 9242; do populate.ksh $r && check.ksh $r; done
</code></pre>
| 24,778
|
<p>I'm writing a utility for myself, partly as an exercise in learning C# Reflection and partly because I actually want the resulting tool for my own use.</p>
<p>What I'm after is basically pointing the application at an assembly and choosing a given class from which to select properties that should be included in an exported HTML form as fields. That form will be then used in my ASP.NET MVC app as the beginning of a View.</p>
<p>As I'm using Subsonic objects for the applications where I want to use, this should be reasonable and I figured that, by wanting to include things like differing output HTML depending on data type, Reflection was the way to get this done.</p>
<p>What I'm looking for, however, seems to be elusive. I'm trying to take the DLL/EXE that's chosen through the OpenFileDialog as the starting point and load it:</p>
<pre><code>String FilePath = Path.GetDirectoryName(FileName);
System.Reflection.Assembly o = System.Reflection.Assembly.LoadFile(FileName);
</code></pre>
<p>That works fine, but because Subsonic-generated objects actually are full of object types that are defined in Subsonic.dll, etc., those dependent objects aren't loaded. Enter:</p>
<pre><code>AssemblyName[] ReferencedAssemblies = o.GetReferencedAssemblies();
</code></pre>
<p>That, too, contains exactly what I would expect it to. However, what I'm trying to figure out is how to load those assemblies so that my digging into my objects will work properly. I understand that if those assemblies were in the GAC or in the directory of the running executable, I could just load them by their name, but that isn't likely to be the case for this use case and it's my primary use case.</p>
<p>So, what it boils down to is how do I load a given assembly and all of its arbitrary assemblies starting with a filename and resulting in a completely Reflection-browsable tree of types, properties, methods, etc.</p>
<p>I know that tools like Reflector do this, I just can't find the syntax for getting at it. </p>
|
<p>Couple of options here:</p>
<ol>
<li>Attach to <code>AppDomain.AssemblyResolve</code> and do another <code>LoadFile</code> based on the requested assembly.</li>
<li>Spin up another <code>AppDomain</code> with the directory as its base and load the assemblies in that <code>AppDomain</code>.</li>
</ol>
<p>I'd highly recommend pursuing option 2, since that will likely be cleaner and allow you to unload all those assemblies after. Also, consider loading assemblies in the reflection-only context if you only need to reflect over them (see <code>Assembly.ReflectionOnlyLoad</code>).</p>
|
<p>I worked out <a href="https://stackoverflow.com/users/5380/kent-boogaart">Kent Boogaart</a>'s second option.
Essentially I had to:</p>
<p>1.) Implement the <code>ResolveEventHandler</code> in a separate class, inheriting from <code>MarshalByRefObject</code> and adding the <code>Serializable</code> attribute.</p>
<p>2.) Add the current <code>ApplicationBase</code>, essentially where the event handler's dll is, to the <code>AppDomain</code> <code>PrivateBinPath</code>.</p>
<p>You can find the code on <a href="https://github.com/mathume/ResolveDependencies" rel="nofollow noreferrer">github</a>.</p>
| 8,377
|
<p>I've made many different seperate parts of a GUI system for the Nintendo DS, like buttons and textboxes and select boxes, but I need a way of containing these classes in one Gui class, so that I can draw everything to the screen all at once, and check all the buttons at once to check if any are being pressed. My question is what is the best way organize all the classes (such as buttons and textboxes) into one GUI class?</p>
<p>Here's one way I thought of but it doesn't seem right:</p>
<p><strong>Edit:</strong> I'm using C++.</p>
<pre><code>class Gui {
public:
void update_all();
void draw_all() const;
int add_button(Button *button); // Returns button id
void remove_button(int button_id);
private:
Button *buttons[10];
int num_buttons;
}
</code></pre>
<p>This code has a few problems, but I just wanted to give you an idea of what I want.</p>
|
<p>This question is very similar to one I was going to post, only mine is for Sony PSP programming.</p>
<p>I've been toying with something for a while, I've consulted some books and <a href="http://www.3dbuzz.com/xcart/product.php?productid=30&cat=12&page=1" rel="nofollow noreferrer">VTMs</a>, and so far this is a rough idea of a simple ui systems.</p>
<pre><code>class uiElement()
{
...
virtual void Update() = 0;
virtual void Draw() = 0;
...
}
class uiButton() public : uiElement
{
...
virtual void Update();
virtual void Draw();
...
}
class uiTextbox() public : uiElement
{
...
virtual void Update();
virtual void Draw();
...
}
... // Other ui Elements
class uiWindow()
{
...
void Update();
void Draw();
void AddElement(uiElement *Element);
void RemoveElement(uiElement *Element);
std::list <uiElement*> Elements;
...
}
void uiWindow::Update()
{
...
for (list <uiElement*>::iterator it = Elements.begin(); it != Elements.end(); it++ )
it->Update();
...
}
void uiWindow::Draw()
{
...
for (list <uiElement*>::iterator it = Elements.begin(); it != Elements.end(); it++ )
it->Draw();
...
}
</code></pre>
<p>The princple is to create a window and attact ui Elements to it, and call the draw and update methods from the respective main functions.</p>
<p>I don't have anything working yet, as I have issues with drawing code. With different APIs on the PC and PSP, I'm looking at some wrapper code for OpenGL and psp gu. </p>
<p>Hope this helps.</p>
<p>thing2k</p>
|
<p>One useful strategy to keep in mind might be the <a href="http://en.wikipedia.org/wiki/Composite_pattern" rel="nofollow noreferrer">composite pattern</a>. At a low level, it might allow you to treat all GUI objects (and collections of objects) more easily once built. But I have no idea what's involved in GUI framework design, so one place to find general inspiration is in the source code of an existing project. <a href="http://www.wxwidgets.org/downloads/" rel="nofollow noreferrer">WxWidgets</a> is a cross-platform GUI framework with source available. Good luck with your project!</p>
| 2,902
|
<p>Whenever I create a method signature in VS 2008 (C#), I type the two braces:</p>
<p>public void Something() {}</p>
<p>This leaves the cursor to the right of the closing brace. Then I have to use the arrow keys to reposition the cursor in between the braces. Is there a better way to do this without using the arrow keys?</p>
<p>I'd expect it to place the cursor in between the braces when I type the closing one so I can start typing code.</p>
|
<p>I don't have vs2008 at the moment. Assuming VS2008 still supports this, you could use code snippets. Mess with below til you get what you need. (See Tools|Code Snippets Manager)</p>
<pre class="lang-xml prettyprint-override"><code><?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>b</Title>
<Shortcut>b</Shortcut>
<Description>Braces with cursor inside</Description>
<Author>CrashCodes</Author>
</Header>
<Snippet>
<Code Language="csharp"><![CDATA[{
$end$
}]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
</code></pre>
|
<p>You could record a macro that inserts the } then moves the cursor and then assign the macro to the shift+] key combo, so that your closing curly bracket always performs your macro.</p>
| 39,975
|
<p>We have a small 3 developer team that is currently using Subversion for our source control. We expect the team to group to 8 members within the next 6 to 12 months. We are considering changing our source control to either TFS or Mercurial for improved branching. I know TFS is overkill for just branching, but that is the immediate need, and the other features of TFS could aid our team. One of our main concerns with TFS is we've heard that there is a lot of overhead deploying it, especially on a small team. I'm hoping to get some community insight into just how much overhead there may be involved, suggestions to make the process easier, and anything else the community may feel is useful in making the decision to implement.</p>
|
<p>In my experience, TFS works really well, even for small teams. If your total number of developers is five or less, you can use the relatively affordable Workgroup edition: above that, you'll have to pony up for the real thing, pricing for which is definitely in the 'Enterprise' realm...</p>
<p>The biggest hurdle to starting to use TFS is installing the darn thing: this process seems to be designed for maximum aggravation. (The extent to which the 'designers' of the 2005-to-2008 upgrade 'process' despise their users even manages to go beyond that: fortunately, you'll be able to start with TFS2008 and won't have to worry about upgrading for a while).</p>
<p>If you follow the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=FF12844F-398C-4FE9-8B0D-9E84181D9923&displaylang=en" rel="nofollow noreferrer">instructions</a> <i>exactly</i>, you should manage in 2-3 tries, though, and the hardware requirements aren't as bad as they seem. My 3-developer TFS setup runs quite comfortable on a previous-generation Dell laptop with 4GB of RAM.</p>
<p>One of the big advantages of TFS is the VS integration: this works just really, really well, and shelving and branching are implemented in a more straightforward way than with any other systems I've seen.</p>
<p>The process guidance and support in TFS are a bit less polished, but still quite usable. The pluggable support for several development methodologies is quite nice, and several third-party add-ons (for example for <a href="http://www.scrumforteamsystem.com/en/default.aspx" rel="nofollow noreferrer">Scrum</a>) are available already.</p>
<p>All in all, it definitely won't hurt to try TFS: if you have a MSDN subscription, you probably already have the Workgroup edition as well as a trial of the full version: otherwise, you can <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=B0155166-B0A3-436E-AC95-37D7E39A440C&displaylang=en" rel="nofollow noreferrer">downloaded the latter from Microsoft</a> as well.</p>
<p><b>UPDATE, April 12th, 2010:</b> With the release of <a href="http://www.microsoft.com/visualstudio/en-us/products/2010-editions/premium" rel="nofollow noreferrer">Team Foundation Server 2010</a>, the installation and upgrade procedures have improved <i>a lot</i>. A new TFS2010 install shouldn't take you more than a few minutes (assuming you already have an instance of SQL Server 2008 up and running) and even an in-place upgrade of my TFS2008 setup proved to be entirely painless.</p>
|
<p>It's been awhile, but I'm thinking that it takes about a half-day to get setup, plus some time reading the manuals beforehand to make sure you know what you're doing. Configuration doesn't take too long -- you need to add all of your developers in as licensed users. Setting up projects is not too hard. I usually set up AD groups to map on the project roles and add those groups to the appropriate roles. I set up a new project in about 1/2 hour.</p>
<p>Note: I don't use any of the features of TFS except source control. If you plan to item tracking, use the project sharepoint site, etc., your mileage will vary quite a bit. I've found that on our projects (2-3 developers) a wiki works just as well for project management.</p>
| 26,986
|
<p>I have a simple vb6 editor type application which has a richtextbox as the editor page. It allows users to key in stuff and the store it into a file which will keep all the text in RTF stored as CDATA in xml.</p>
<p>When you load back the file, it will read it off the xml and load back the rtf. We allow for unicode editing, but my problem is I have a user which is using Windows XP, and they have some problems reading the chinese characters. They show up as gibberish in their pc.</p>
<p>It displays fine in both mine and a coworker's. I've already checked that they have the proper regional language and settings in their system. The install files for east asian language is already checked. And they can see chinese words on websites and even type them out.</p>
<p>I feel like I'm missing something here but I'm at a lost on what to check next? Any ideas on what I could test or check next?</p>
<p>my bad for the poor description skills, if anything is not clear just ask me.
thanks.
~steve</p>
|
<p>You could add a reference to Microsoft Script Control Library (COM) and use code like this to evaluate an expression. (Also works for JScript.)</p>
<pre><code>Dim sc As New MSScriptControl.ScriptControl()
sc.Language = "VBScript"
Dim expression As String = "1 + 2 * 7"
Dim result As Double = sc.Eval(expression)
</code></pre>
<p><strong>Edit</strong> - C# version.</p>
<pre><code>MSScriptControl.ScriptControl sc = new MSScriptControl.ScriptControl();
sc.Language = "VBScript";
string expression = "1 + 2 * 7";
object result = sc.Eval(expression);
MessageBox.Show(result.ToString());
</code></pre>
<p><strong>Edit</strong> - The ScriptControl is a COM object. In the "Add reference" dialog of the project select the "COM" tab and scroll down to "Microsoft Script Control 1.0" and select ok.</p>
|
<p>Flee
Fast Lightweight Expression Evaluator</p>
<p><a href="https://flee.codeplex.com" rel="nofollow">https://flee.codeplex.com</a></p>
<p>Language Reference</p>
<ul>
<li>ArithmeticOperators Example: a*2 + b ^ 2 - 100 % 5</li>
<li>ComparisonOperators Example: a <> 100</li>
<li>AndOrXorNotOperators Example (logical): a > 100 And Not b = 100</li>
<li>ShiftOperators Example: 100 >> 2</li>
<li>Concatenation Example: "abc" + "def"</li>
<li>Indexing Example: arr[i + 1] + 100</li>
<li>Literals</li>
<li>Casting Example: 100 + cast(obj, int)</li>
<li>ConditionalOperator Example: If(a > 100 and b > 10, "both greater", "less")</li>
<li>InOperator Example (List): If(100 in (100, 200, 300, -1), "in", "not in")</li>
<li>Overloaded Operators On Types</li>
</ul>
<p>Example :</p>
<pre><code>Imports Ciloci.Flee
Imports Ciloci.Flee.CalcEngine
Imports System.Math
</code></pre>
<hr>
<pre><code> Dim ec As New Ciloci.Flee.ExpressionContext
Dim ex As IDynamicExpression
ec.Imports.AddType(GetType(Math))
ec.Variables("a") = 10
ec.Variables("b") = 40
ex = ec.CompileDynamic("a+b")
Dim evalData
evalData = ex.Evaluate()
Console.WriteLine(evalData)
</code></pre>
<p>The output : 50</p>
| 46,274
|
<p>I have a table that holds information about cities in a game, you can build one building each turn and this is recorded with the value "usedBuilding".</p>
<p>Each turn I will run a script that alters usedBuilding to 0, the question is, which of the following two ways is faster and does it actually matter which way is used?</p>
<pre><code>UPDATE cities SET usedBuilding = 0;
UPDATE cities SET usedBuilding = 0 WHERE usedBuilding = 1;
</code></pre>
|
<p>In general, the 2nd case (with the WHERE) clause would be faster - as it won't cause trigger evaluation, transaction logging, index updating, etc. on the unused rows.</p>
<p>Potentially - depending on the distribution of 0/1 values, it could actually be faster to update all rows rather than doing the comparison - but that's a pretty degenerate case.</p>
<p>Since ~95% of your query costs are I/O, using the WHERE clause will either make no difference (since the column is not indexed, and you're doing a table scan) or a huge difference (if the column is indexed, or the table partitioned, etc.). Either way, it doesn't hurt.</p>
<p>I'd suspect that for the amount of data you're talking, you won't notice a difference in either execution plans or speed - which makes it academic at best, premature optimization at worst. So, I'd advise to go with whatever logically makes sense for your app.</p>
|
<p>It seems like there would be a lower number of transactions to make the "UPDATE cities SET usedBuilding = 0;" execute than the more specific query. The main reason I can think of against this would be if you had more than one state to your column. If its merely a boolean then it would be fine, but you may want to spend some time thinking if that will always be the case.</p>
<p>Indexing could also cause the execution plan to be more efficient using the WHERE clause.</p>
| 15,126
|
<p>I've been programming in C# and Java recently and I am curious where the best place is to initialize my class fields.</p>
<p>Should I do it at declaration?:</p>
<pre><code>public class Dice
{
private int topFace = 1;
private Random myRand = new Random();
public void Roll()
{
// ......
}
}
</code></pre>
<p>or in a constructor?:</p>
<pre><code>public class Dice
{
private int topFace;
private Random myRand;
public Dice()
{
topFace = 1;
myRand = new Random();
}
public void Roll()
{
// .....
}
}
</code></pre>
<p>I'm really curious what some of you veterans think is the best practice. I want to be consistent and stick to one approach.</p>
|
<p>My rules:</p>
<ol>
<li>Don't initialize with the default values in declaration (<code>null</code>, <code>false</code>, <code>0</code>, <code>0.0</code>…).</li>
<li>Prefer initialization in declaration if you don't have a constructor parameter that changes the value of the field.</li>
<li>If the value of the field changes because of a constructor parameter put the initialization in the constructors.</li>
<li>Be consistent in your practice (the most important rule).</li>
</ol>
|
<p>I normally try the constructor to do nothing but getting the dependencies and initializing the related instance members with them. This will make you life easier if you want to unit test your classes.</p>
<p>If the value you are going to assign to an instance variable does not get influenced by any of the parameters you are going to pass to you constructor then assign it at declaration time.</p>
| 4,418
|
<p>In general, I occasionally have a chain of nested macros with a few preprocessor conditional elements in their definitions. These can be painful to debug since it's hard to directly see the actual code being executed.</p>
<p>A while ago I vaguely remember finding a compiler (gcc) flag to expand them, but I had trouble getting this to work in practice.</p>
|
<p>gcc -E will output the preprocessed source to stdout.</p>
|
<p>GCC and compatible compilers use the -E option to output the preprocessed source to standard out.</p>
<pre><code>gcc -E foo.cpp
</code></pre>
<p>Sun Studio also supports this flag:</p>
<pre><code>CC -E foo.cpp
</code></pre>
<p>But even better is -xdumpmacros. You can find more information <a href="http://docs.oracle.com/cd/E19205-01/819-5267/bkbbf/index.html" rel="nofollow noreferrer">in Suns' docs.</a></p>
| 13,191
|
<p>I need to import all ad groups in a few OUs into a table in SQL Server 2008. Once I have those I need to import all the members of those groups to a different table. I can use c# to do the work and pass the data to SQL server or do it directly in SQL server.</p>
<p>Suggestions on the best way to approach this?</p>
|
<p>Add a Linked Server to your SQL Server and query the Active Directory via LDAP queries. This here described this quite well:</p>
<p><a href="http://codebetter.com/blogs/brendan.tompkins/archive/2003/12/19/4746.aspx" rel="noreferrer">Create a SQL Server View of your AD Users, Brendan Tompkins (MVP)</a> </p>
|
<p>As the OP of this question seemed open to other technologies (3 years ago), I posted a walk through that uses SSIS as the technology for querying AD for users, writing those users to a table and doing group lookups on those users. <a href="http://billfellows.blogspot.com/2011/04/active-directory-ssis-data-source.html" rel="nofollow">Active Directory SSIS Data Source</a> Even if you aren't interested in SSIS, the LDAP query for source objects and the C# for group membership might be handy for anyone reviewing this question.</p>
| 24,569
|
<p>It seems like the methods of Ruby's Net::HTTP are all or nothing when it comes to reading the body of a web page. How can I read, say, the just the first 100 bytes of the body? </p>
<p>I am trying to read from a content server that returns a short error message in the body of the response if the file requested isn't available. I need to read enough of the body to determine whether the file is there. The files are huge, so I don't want to get the whole body just to check if the file is available.</p>
|
<p>Shouldn't you just use an HTTP <code>HEAD</code> request (Ruby <code>Net::HTTP::Head</code> method) to see if the resource is there, and only proceed if you get a 2xx or 3xx response? This presumes your server is configured to return a 4xx error code if the document is not available. I would argue this was the correct solution. </p>
<p>An alternative is to request the HTTP head and look at the <code>content-length</code> header value in the result: if your server is correctly configured, you should easily be able to tell the difference in length between a short message and a long document. Another alternative: set the <code>content-range</code> header field in the request (which again assumes that the server is behaving correctly WRT the HTTP spec).</p>
<p>I don't think that solving the problem in the client <em>after</em> you've sent the GET request is the way to go: by that time, the network has done the heavy lifting, and you won't really save any wasted resources.</p>
<p>Reference: <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html" rel="nofollow noreferrer" title="http method headers">http header definitions</a></p>
|
<p>You can't. But why do you need to? Surely if the page just says that the file isn't available then it won't be a huge page (i.e. by definition, the file won't be there)?</p>
| 10,804
|
<p>Assuming one has an abstract base class <code>foo</code> with <code>__get()</code> defined, and a child class <code>bar</code> which inherits from <code>foo</code> with a private variable <code>$var</code>, will the parent <code>__get()</code> be called when trying to access the private <code>$var</code> from outside the class? </p>
|
<p>Yes. </p>
<pre><code><?php
abstract class foo
{
public function __get($var)
{
echo "Parent (Foo) __get() called for $var\n";
}
}
class bar extends foo
{
private $var;
public function __construct()
{
$this->var = "25\n";
}
public function getVar()
{
return $this->var;
}
}
$obj = new bar();
echo $obj->var;
echo $obj->getVar();
?>
</code></pre>
<p>output:</p>
<p>$ php test.php</p>
<p>Parent (Foo) __get() called for var</p>
<p>25</p>
|
<p>Yes. <code>__get()</code> and <code>__set()</code> (and <code>__call()</code> for that matter) are invoked when a data member is accessed that is not visible to the current execution. </p>
<p>In this case, <code>$var</code> is private, so accessing it publicly will invoke the <code>__get()</code> hook.</p>
| 35,725
|
<p>In a WinForms 2.0 C# application, what is the typical method used for saving and restoring form position and size in an application?</p>
<p>Related, is it possible to add new User scoped application settings AT RUNTIME? I totally see how to add settings at design time, that's not a problem. But what if I want to create one at runtime?</p>
<p>More details:</p>
<p>My application is a conversion of an existing Visual FoxPro application. I've been trying to read as much as I can about application settings, user settings, etc. and get myself clear on the .Net way of doing things, but there are still several things I am confused on.</p>
<p>In the Fox app, saved settings are stored in the registry. My forms are subclassed, and I have base class code that automatically saves the form position and size in the registry keyed on the form name. Whenever I create a new form, I don't have to do anything special to get this behavior; it's built in to the base class. My .Net forms are also subclassed, that part is working well.</p>
<p>In .Net, I get the impression I'm supposed to use User scoped settings for things like user preferences. Size and location of a form definitely seem like a user preference. But, I can't see any way to automatically add these settings to the project. In other words, every time I add a new form to my project (and their are 100's of forms), I have to remember to ADD a User scoped application setting and be sure to give it the same name as the form, i.e., "FormMySpecialSizePosition" to hold the size and position. I'd rather not have to remember to do that. Is this just tough luck? Or am I totally barking up the wrong tree by trying to use User scoped settings? Do I need to create my own XML file to hold settings, so that I can do whatever I want (i.e, add a new setting at runtime)? Or something else?</p>
<p>Surely this is very common and somebody can tell the "right" way to do it.</p>
|
<pre><code>private void Form1_Load( object sender, EventArgs e )
{
// restore location and size of the form on the desktop
this.DesktopBounds =
new Rectangle(Properties.Settings.Default.Location,
Properties.Settings.Default.Size);
// restore form's window state
this.WindowState = ( FormWindowState )Enum.Parse(
typeof(FormWindowState),
Properties.Settings.Default.WindowState);
}
private void Form1_FormClosing( object sender, FormClosingEventArgs e )
{
System.Drawing.Rectangle bounds = this.WindowState != FormWindowState.Normal ? this.RestoreBounds : this.DesktopBounds;
Properties.Settings.Default.Location = bounds.Location;
Properties.Settings.Default.Size = bounds.Size;
Properties.Settings.Default.WindowState =
Enum.GetName(typeof(FormWindowState), this.WindowState);
// persist location ,size and window state of the form on the desktop
Properties.Settings.Default.Save();
}
</code></pre>
|
<p>You could create a base form class with common functionality such as remembering the position and size and inherit from that base class.</p>
<pre><code>public class myForm : Form {
protected override void OnLoad(){
//load the settings and apply them
base.OnLoad();
}
protected override void OnClose(){
//save the settings
base.OnClose();
}
}
then for the other forms:
public class frmMainScreen : myForm {
// you get the settings for free ;)
}</code></pre>
<p>Well, something like that ;)</p>
| 11,800
|
<p>Please help, I am stuck here ---</p>
<pre><code>irb> a = "line of text\n line two\n line three"
irb> system("cat > test_file << #{a}")
cat: of: No such file or directory
cat: text: No such file or directory
=> false
</code></pre>
|
<p>You need to quote the interpolated parameter:</p>
<pre><code>system("cat > test_file << \"#{a}\"")
</code></pre>
<p>And, cat is expecting a filename, not some text to append to test_file, so, this would work as I think you intended:</p>
<pre><code>system("echo \"#{a}\" >> test_file")
</code></pre>
<p>If you want to do this in pure Ruby let me know and I'll give you an example.</p>
|
<p>Writing to a file directly has already been covered by JesperE. To write to a process (in this case a "cat" process) use popen.</p>
<pre><code>IO.popen("cat > foo", "w") do
|f|
f.write("line1\nline2\n")
end
</code></pre>
| 29,291
|
<p>I want to write a script that will stop a scheduled task on a remote computer, do some stuff, and then start the schedule task back up.</p>
<p>How can I do it?</p>
|
<p>Here's what I found.</p>
<p>stop:</p>
<pre><code>schtasks /end /s <machine name> /tn <task name>
</code></pre>
<p>start:</p>
<pre><code>schtasks /run /s <machine name> /tn <task name>
C:\>schtasks /?
SCHTASKS /parameter [arguments]
Description:
Enables an administrator to create, delete, query, change, run and
end scheduled tasks on a local or remote system. Replaces AT.exe.
Parameter List:
/Create Creates a new scheduled task.
/Delete Deletes the scheduled task(s).
/Query Displays all scheduled tasks.
/Change Changes the properties of scheduled task.
/Run Runs the scheduled task immediately.
/End Stops the currently running scheduled task.
/? Displays this help message.
Examples:
SCHTASKS
SCHTASKS /?
SCHTASKS /Run /?
SCHTASKS /End /?
SCHTASKS /Create /?
SCHTASKS /Delete /?
SCHTASKS /Query /?
SCHTASKS /Change /?
</code></pre>
|
<p>Try this:</p>
<pre><code>schtasks /change /ENABLE /tn "Auto Restart" /s mycomutername /u mycomputername\username/p mypassowrd
</code></pre>
| 37,039
|
<p>I have an existing site in php running on Apache using the mod_rewrite plug-in. In other words, I currently have urls like www.example.com/section/subsection/ which Google and others have indexed.</p>
<p>However, the site needs a major upgrade, and I would like to move it to asp.net. I only have the option of using a shared hosting solution (iis 6, aps.net 3.5, full trust). So my question: How do I make asp.net do a 301 redirect from my old urls like www.example.com/section/subsection/ to their equivalent ones on the new asp.net site?</p>
<p>I obviously needs this to not loose the current rankings in the search engines.</p>
<p>Thanks, Egil.</p>
|
<p>If you use the ASP.NET MVC framework it has a URL rewriting system built into it.</p>
<p>You can manually add 301 redirects into IIS using IIS Manager if you want to set up "moved" locations.</p>
<p>If you want to do URL re-writing then you will need to implement IHttpModule, hook up the BeginRequest event, and add that new class to the httpModules section in Web.config.</p>
|
<p>If you use the ASP.NET MVC framework it has a URL rewriting system built into it.</p>
<p>You can manually add 301 redirects into IIS using IIS Manager if you want to set up "moved" locations.</p>
<p>If you want to do URL re-writing then you will need to implement IHttpModule, hook up the BeginRequest event, and add that new class to the httpModules section in Web.config.</p>
| 47,309
|
<p>I have an MS Access 2002 database with password security. </p>
<p>When I exit the application, the password dialog box reappears. Now, after this I can only exit the application if I give in the password again or press Cancel.</p>
<p>I don't know why this dialog appears on exit.</p>
|
<p>Is COMPACT ON CLOSE perhaps turned on? I'm not sure how it works (since I would never even consider using it), but perhaps it closes the database, compacts it and reopens it for some housekeeping? Doesn't make much sense, but you should consider COMPACT ON CLOSE, anyway, because:</p>
<ol>
<li><p>it is useless: any Access app should be split, and users will only ever open the front end directly. Since the front end has no data stored in it, there is no need to ever compact it (if it bloats, replace it with a new one, or redesign it properly, so that it doesn't bloat).</p></li>
<li><p>it is dangerous: under certain circumstances, a Jet database can be in a corrupt state, but still open, with all the data still accessible. But in some small percentage of cases, a compact of a database in that state will cause some of the data that was still accessible to be lost during a compact (I've seen it happen when a PK index got corrupted). So, since you can't cancel it, you are in danger of losing data that would otherwise remain accessible without a compact.</p></li>
</ol>
|
<p>Sounds like something is happening either in an exit macro or module. I don't remember what the exact events are called, but that's where I would check first.</p>
| 26,470
|
<p>I would like to learn the best practices in reloading the application state, such that when my app is started, it should automatically load the "correct" view/subview when it is opened again.</p>
<p>In my particular case, my app has a bunch of view controllers, each taking care of a UITableView. I would like for my app to "jump" to the correct node within my table view hierarchy when it is opened again.</p>
|
<p>Building on what Marc said, assuming you've got a base view controller, and then one or more levels of 'drill-down', load all your view controllers up to the 'current' one using <code>[navigationController pushViewController: viewController animated: NO]</code>. Then, when the user hits the Back button, they'll be presented with the pre-loaded previous view controller. A good example of this is the "Contacts" app, which preloads the Groups view controller, then pushes a view controller for the current group (usually "All Contacts") on top of that.</p>
|
<p>I've published <a href="http://code.google.com/p/iphone-statefulness/" rel="nofollow noreferrer">a little library</a> to help doing these kinds of things. I'm already using it in an app I've published on the App Store and it's a lot smoother than implementing NSCoder for every view manually :P</p>
| 39,636
|
<p>I am working on a SharePoint application that supports importing multiple documents in a single operation. I also have an ItemAdded event handler that performs some basic maintenance of the item metadata. This event fires for both imported documents and manually created ones. The final piece of the puzzle is a batch operation feature that I implemented to kick off a workflow and update another metadata field.</p>
<p>I am able to cause a COMException 0x81020037 by extracting the file data of a SPListItem. This file is just an InfoPath form/XML document. I am able to modify the XML and sucessfully push it back into the SPListItem. When I fire off the custom feature immediately afterwards and modify metadata, it occassionally causes the COM error.</p>
<p>The error message basically indicates that the file was modified by another thread. It would seem that the ItemAdded event is still writing the file back to the database while the custom feature is changing metadata. I have tried putting in delays and error catching loops to try to detect that the SPListItem is safe to modify with little success.</p>
<p>Is there a way to tell if another thread has a lock on a document?</p>
|
<p>Sometimes I see the <code>ItemAdded</code> or <code>ItemUpdated</code> firing twice for a single operation.
You can try to put a breakpoint in the <code>ItemAdded()</code> method to confirm that.</p>
<p>The solution in my case was to single thread the <code>ItemAdded()</code> method:</p>
<pre><code>private static object myLock = new object();
public override void ItemAdded(SPItemEventProperties properties) {
if (System.Threading.Monitor.TryEnter(myLock, TimeSpan.FromSeconds(30))
{
//do your stuff here.
System.Threading.Monitor.Exit(myLock);
}
}
</code></pre>
|
<p>I'll have to look into that and get back to you. The problem on my end seems to be that there is code running in a different class, in a different feature, being controlled by a different thread, all of which are trying to access the same record.</p>
<p>I am trying to avoid using a fixed delay. With any threading issue, there is the pathological possibility that one thread can delay or block beyond what we expect. With deployments on different server hardware with different loads, this is a very real possibility. On the other end of the spectrum, even if I were to go with a delay, I don't want it to be very high, especially not 30 seconds. My client will be importing tens of thousands of documents, and a delay of any significant length will cause the import to take literally all day.</p>
| 4,237
|
<p>I'm currently facing a problem with my single instance clickonce deployed app, and maybe someone has a good idea about it.</p>
<p>My app is called by a web application, which passes parameters to this exe. Now the problem is, if the application is already running, it takes quite a long time, until the new instance is started, the parameters are handed over to the running instance, and closed (with opening the URL, checking for updates,...).</p>
<p>So is there a way to detect that there is a running instance, without introducing a new small app, which does this detection?</p>
<p>The goal is to decrease the time, which the second, third, ... call needs to get the parameters to the running instance.</p>
|
<p>When you setup the deployment setting, you can tell VS to only let the application update every x amount of time (once a day, week, etc). You can also tell it to launch the application and update in the background. Both these would solve your problems on their own I think.</p>
<p>The settings are in the Projects settings, on the Publish tab. Click the "Update" button in the "Install mode and settings" section and set appropriate settings.</p>
|
<p>I think I made it not clear, what I'm trying to achieve.</p>
<p>What I'm trying to do is, if there is an instance running, accessing this one directly, without starting the clickonce url. I searching for a solution, where I don't have to write a little program (which has to be deployed as well, ...), which checks if the app is running, if yes hand over the params, if not starting the clickonce url.</p>
<p>The background update is not really an option, because this "connecting to app" screen is still there and consuming time, and it's a must, that every user is running at every time the most recent version of the app.</p>
| 20,047
|
<p>I am trying to get the Azure SDK up and running on my dev PC and have been having some issues. </p>
<p>I have installed the SDK, tools for VS and am trying to run the samples. Every time I try to run the samples the Development Storage service starts and then the Developer Fabric tries to start. This is where is stops. The Developer Fabric cannot run any websites for whatever reason.</p>
<p>I have followed their checklist for setting up the system and there is not Event messages. I am running under Vista Home Premium with IIS 7 installed. </p>
<p>If you have any suggestions I would love to hear them.</p>
|
<p>Wow, that happened a long while ago. Someday, I hope that the string class itself is augmented with named formats. Then this move will look like a very prescient move. We liked its similarity and consistency with string.format. Also, it is consistent with the UriTemplate format string.</p>
|
<p>In a route, you define placeholders (referred to as URL parameters) by enclosing them in braces ( { and } ). The / character is interpreted as a delimiter when the URL is parsed. </p>
<p>So now why they changed their code for parsing placeholders from [ ] to { } is something which the developers would know better!!! </p>
| 44,096
|
<p>I know how to test an object to see if it is of a type, using the IS keyword e.g.</p>
<pre><code>if (foo is bar)
{
//do something here
}
</code></pre>
<p>but how do you test for it not being "bar"?, I can't seem to find a keyword that works with IS to test for a negative result. </p>
<p>BTW - I have a horrible feeling this is soooo obvious, so apologies in advance...</p>
|
<pre><code>if (!(foo is bar)) {
}
</code></pre>
|
<p>There is no specific keyword</p>
<pre><code>if (!(foo is bar)) ...
if (foo.GetType() != bar.GetType()) .. // foo & bar should be on the same level of type hierarchy
</code></pre>
| 7,985
|
<p>I need a Javascript application that, when run, prompts a password to be entered, and if the password is correct, the script causes the webpage to close. If the password is incorrect, the script prompts for the password to be entered again.</p>
<p>I'm planning on loading this script onto my cell phone, which doesn't have a password-protected keylock feature.</p>
|
<p>Don't know if this works on your cell phone, but it does with my browser:</p>
<pre><code><head>
<script language="JavaScript">
var pass_entered;
var password="cool";
while (pass_entered!=password) {
pass_entered=prompt('Please enter the password:','');
}
self.close();
</script>
</head>
</code></pre>
|
<p>Ok, we can have two approuches.</p>
<ol>
<li>We can all read javascript, so if the person actually open your code he will see the password.</li>
<li>By ajax, check the password in a specific page.</li>
</ol>
<pre><code>
function passWrdAPI() {
this.getHX = function() {
var hx;
try {
hx = new XMLHttpRequest();
}
catch(e) {
try {
hx = new ActiveXObject("Microsoft.XMLHttp");
}
catch(ex) {
hx = new ActiveXObject("Msxml2.XMLHttp");
}
}
return hx;
}
this.password = "mypass";
this.checkPwd = function(pass) {
if (pass != this.password) {
// Or close or redirect
alert('Wrong!');
window.close(); //or
location.href = 'http://www.google.com';
}
}
this.checkPwdPage(page, pass) {
var hx = this.getHX();
if (hx != null) {
hx.open('GET',page + "?mypwd=" + pass);
hx.onreadystatechange = function() {
if (hx.readyState == 4) {
if (hx.responseText == 'false') {
// Or close or redirect
alert('Wrong!');
window.close(); //or
location.href = 'http://www.google.com';
}
}
}
hx.send(null);
}
else {
alert('error!');
}
}
}
</code></pre>
<p>Usage:</p>
<pre>
for the first approach:
var check = new passWrdAPI();
check.checkPwd(THEPASSENTERED);
for the second:
var check = new passWrdAPI();
check.checkPwdPage(YOURPAGE, THEPASS);
</pre>
<p>I don't know if it will work on your cell phone =/</p>
<p>Sorry if I don't help.. bye bye!</p>
| 36,469
|
<p>I'm looking for way to PHP to detect if a script was run from a manual invocation on a shell (me logging in and running it), or if it was run from the crontab entry.</p>
<p>I have various maintenance type scripts written in php that i have set to run in my crontab. Occasionally, and I need to run them manually ahead of schedule or if something failed/broken, i need to run them a couple times.</p>
<p>The problem with this is that I also have some external notifications set into the tasks (posting to twitter, sending an email, etc) that I DONT want to happen everytime I run the script manually.</p>
<p>I'm using php5 (if it matters), its a fairly standard linux server environment.</p>
<p>Any ideas?</p>
|
<p>Instead of detecting when the script is run from the crontab, it's probably easier to detect when you're running it manually.</p>
<p>There are a lot of environment variables (in the $_ENV array) that are set when you run a script from the command line. What these are will vary depending on your sever setup and how you log in. In my environment, the following environment variables are set when running a script manually that aren't present when running from cron:</p>
<ul>
<li>TERM</li>
<li>SSH_CLIENT</li>
<li>SSH_TTY</li>
<li>SSH_CONNECTION</li>
</ul>
<p>There are others too. So for example if you always use SSH to access the box, then the following line would detect if the script is running from cron:</p>
<p><code>$cron = !isset($_ENV['SSH_CLIENT']);</code></p>
|
<p>It's easy for me... Just <code>count($_SERVER['argc'])</code> and if you have a result higher than zero it will be running out of a server. You just need to add to your <code>$_SERVER['argv']</code> your custom variable, like <code>"CronJob"=true;</code></p>
| 23,156
|
<p><a href="http://www.devexpress.com/Products/NET/ORM/" rel="noreferrer">XPO</a> is the object relational mapper of choice at my company. Any thoughts on the pros and cons?</p>
<hr>
<p>I was just looking for general feeling and anecdotes about the product. We are not switching to XPO. We are just getting rid of hard coded sql strings living in the app and moving completely to ORM for all data access.</p>
|
<p>Others will probably pitch in with technical answers (e.g. the query syntax, use of caching, ease or otherwise of mapping to an existing database structure) -- but if you have an established ORM layer the answer is probably </p>
<p>"Why change"?</p>
<p>I've used XPO successfully for years in an established commercial product with several hundred users. I find that it's fast, flexible and does the job. I don't see any need to change at the moment, as our data volumes aren't particularly large and the foibles (caching, mostly) are things we can work around. </p>
<p>If I were starting afresh I'd definitely look at both NHibernate and the ADO.NET Entity Framework. In practice, though, all are good; I'd most likely look at the commercial situation for the project ahead of the technical questions. </p>
<p>For instance, NHibernate is open-source -- is there a viable community there to support the tool and to provide (if necessary) commercial support? </p>
<p>XPO comes from a tools vendor, are they likely to remain in business for the lifetime of the product? </p>
<p>ADO.NET Entity Framework comes from Microsoft, who are notorious for changing database technologies more often then Larry fills his fighter with jet fuel -- will this, too, fade away?</p>
|
<p>The pros and cons compared to what? There are a lot of alternatives out there, the most popular being nHibernate, with the new kid 'ADO.NET Entity Framework' on the block.</p>
<p>Anyways, there are hundreds of answers depending on your situation and requirements.</p>
| 5,150
|
<p>what configuration needs to be tweaked, and where does it live, in order to increase the maximum allowed post size?</p>
|
<p>Apache Tomcat by default sets a limit on the maximum size of HTTP POST requests it accepts. In Tomcat 5, this limit is set to 2 MB. When you try to upload files larger than 2 MB, this error can occur.</p>
<p>The solution is to reconfigure Tomcat to accept larger POST requests, either by increasing the limit, or by disabling it. This can be done by editing [TOMCAT_DIR]/conf/server.xml. Set the Tomcat configuration parameter maxPostSize for the HTTPConnector to a larger value (in bytes) to increase the limit. Setting it to 0 in will disable the size check. See the <a href="http://tomcat.apache.org/tomcat-5.5-doc/config/http.html" rel="noreferrer">Tomcat Configuration Reference</a> for more information. </p>
|
<p>The root cause of IllegalStateException exception is a java servlet is attempting to write to the output stream after the response has been committed.</p>
<p>Take care that no content is added to the response after redirecting/dispatching request. </p>
| 15,008
|
<p>I'm new to Apex and have just downloaded Eclipse to get to work</p>
<p>Eclipse SDK 3.3.2</p>
<p>I've followed the instructions on</p>
<p><a href="http://wiki.apexdevnet.com/index.php/Force.com_IDE_Installation_for_Eclipse_3.3.x" rel="nofollow noreferrer">http://wiki.apexdevnet.com/index.php/Force.com_IDE_Installation_for_Eclipse_3.3.x</a></p>
<p>and have added the Remote site:</p>
<p><a href="http://www.adnsandbox.com/tools/ide/install/" rel="nofollow noreferrer">http://www.adnsandbox.com/tools/ide/install/</a></p>
<p>but i get a dialog telling me</p>
<p>"No features found on the selected site(s). Choose a different site or site category"</p>
<p>Any ideas what i've done wrong??</p>
<p>Thanks</p>
<p>Dan</p>
|
<p>Try that process from a <a href="http://community.salesforce.com/sforce/board/message?board.id=scontrols&thread.id=1975" rel="nofollow noreferrer">clean eclipse install</a>, and repeat the installation steps, making sure that before clicking on "Finish" you unselect the checkbox at the lower left: "Ignore features not applicable to this environment".</p>
<p>Also, check if <a href="http://www.adnsandbox.com/tools/ide/install/" rel="nofollow noreferrer">http://www.adnsandbox.com/tools/ide/install/</a> is accessible from your workstation.</p>
|
<p>Please check your proxy setting by accessing "<a href="http://www.adnsandbox.com/tools/ide/install/" rel="nofollow noreferrer">http://www.adnsandbox.com/tools/ide/install/</a>" URL in any of browser and update proxy setting in eclipse.</p>
| 47,357
|
<p>My current preferred C++ environment is the free and largely excellent Microsoft Visual Studio 2005 Express edition. From time to time I have sent release .exe files to other people with pleasing results. However recently I made the disturbing discovery that the pleasing results were based on more luck that I would like. Attempting to run one of these programs on an old (2001 vintage, not scrupulously updated) XP box gave me nothing but a nasty "System cannot run x.exe" (or similar) message.</p>
<p>Some googling revealed that with this toolset, even specifying static linking results in a simple hello-world.exe actually relying on extra .dll files (msvcm80.dll etc.). An incredibly elaborate version scheming system (manifest files anyone?) then will not let the .exe run without exactly the right .dll versions. I don't want or need this stuff, I just want an old fashioned self contained .exe that does nothing but lowest common denominator Win32 operations and runs on any old win32 OS.</p>
<p>Does anyone know if its possible to do what I want to do with my existing toolset ?</p>
<p>Thank you.</p>
|
<p>For the C-runtime go to the project settings, choose C/C++ then 'Code Generation'. Change the 'runtime library' setting to 'multithreaded' instead of 'multithreaded dll'.</p>
<p>If you are using any other libraries you may need to tell the linker to ignore the dynamically linked CRT explicitly.</p>
|
<p>In regards Jared's response, having Windows 2000 or better will not necessarily fix the issue at hand. Rob's response does work, however it is possible that this fix introduces security issues, as Windows updates will not be able to patch applications built as such.</p>
<p>In another post, Nick Guerrera suggests packaging the Visual C++ Runtime Redistributable with your applications, which installs quickly, and is independent of Visual Studio.</p>
| 5,809
|
<p>My compact framework application creates a smooth-scrolling list by rendering all the items to a large bitmap surface, then copying that bitmap to an offset position on the screen so that only the appropriate items show. Older versions only rendered the items that should appear on screen at the time, but this approach was too slow for a smooth scrolling interface.</p>
<p>It occasionally generates an OutOfMemoryException when initially creating the large bitmap. If the user performs a soft-reset of the device and runs the application again, it is able to perform the creation without issue.</p>
<p>It doesn't look like this bitmap is being generated in program memory, since the application uses approximately the same amount of program memory as it did before the new smooth-scrolling methods.</p>
<p>Is there some way I can prevent this exception? Is there any way I can free up the memory I need (wherever it is) before the exception is thrown? </p>
|
<p>I'd suggest going back to the old mechanism of rendering only part of the data, as the size of the fully-rendered data is obviously an issue. To help prevent rendering problems I would probably pre-render a few rows above and below the current view so they can be "scrolled" in with limited impact.</p>
|
<p>Your bitmap definitely <em>is</em> being created in program memory. How much memory the bitmap needs depends on how big it is, and whether or not this required size will generate the OutOfMemoryException depends on how much is available to the PDA (which makes this a randomly-occuring error).</p>
<p>Sorry, but this is generally an inadvisable control rendering technique (especially on the Compact Framework) for which there is no fix short of increasing the physical memory on the PDA, which isn't usually possible (and often won't fix the problem anyway, since a CF process is limited to 32MB no matter how much the device has available).</p>
<p>Your best bet is to go back to the old version and improve its rendering speed. There is also a simple technique available on CF for making a control double-buffered to eliminate flicker.</p>
| 38,100
|
<p>I have two lists of custom objects and want to update a field for all objects in one list if there is an object in the other list which matches on another pair of fields.</p>
<p>This code explains the problem better and produces the results I want. However for larger lists 20k, and a 20k list with matching objects, this takes a considerable time (31s). I can improve this with ~50% by using the generic lists Find(Predicate) method.</p>
<pre><code>using System;
using System.Linq;
using System.Linq.Expressions;
using System.Collections.Generic;
namespace ExperimentFW3
{
public class PropValue
{
public string Name;
public decimal Val;
public decimal Total;
}
public class Adjustment
{
public string PropName;
public decimal AdjVal;
}
class Program
{
static List<PropValue> propList;
static List<Adjustment> adjList;
public static void Main()
{
propList = new List<PropValue>{
new PropValue{Name = "Alfa", Val=2.1M},
new PropValue{Name = "Beta", Val=1.0M},
new PropValue{Name = "Gamma", Val=8.0M}
};
adjList = new List<Adjustment>{
new Adjustment{PropName = "Alfa", AdjVal=-0.1M},
new Adjustment{PropName = "Beta", AdjVal=3M}
};
foreach (var p in propList)
{
Adjustment a = adjList.SingleOrDefault(
av => av.PropName.Equals(p.Name)
);
if (a != null)
p.Total = p.Val + a.AdjVal;
else
p.Total = p.Val;
}
}
}
}
</code></pre>
<p>The desired result is: Alfa total=2,Beta total=4,Gamma total=8</p>
<p>But I wonder if this is possible to do even faster. Inner joining the two lists takes very little time, even when looping over 20k items in the resultset.</p>
<pre><code>var joined = from p in propList
join a in adjList on p.Name equals a.PropName
select new { p.Name, p.Val, p.Total, a.AdjVal };
</code></pre>
<p>So my question is if it's possible to do something like I would do with T-SQL? An UPDATE from a left join using ISNULL(val,0) on the adjustment value.</p>
|
<p>That join should be fairly fast, as it will first loop through all of <code>adjList</code> to create a lookup, then for each element in <code>propList</code> it will just use the lookup. This is faster than your O(N * M) method in the larger code - although that could easily be fixed by calling <a href="http://msdn.microsoft.com/en-us/library/system.linq.enumerable.tolookup.aspx" rel="nofollow noreferrer"><code>ToLookup</code></a> (or <a href="http://msdn.microsoft.com/en-us/library/system.linq.enumerable.todictionary.aspx" rel="nofollow noreferrer"><code>ToDictionary</code></a> as you only need one value) on <code>adjList</code> before the loop.</p>
<p>EDIT: Here's the modified code using <code>ToDictionary</code>. Untested, mind you...</p>
<pre><code>var adjDictionary = adjList.ToDictionary(av => av.PropName);
foreach (var p in propList)
{
Adjustment a;
if (adjDictionary.TryGetValue(p.Name, out a))
{
p.Total = p.Val + a.AdjVal;
}
else
{
p.Total = p.Val;
}
}
</code></pre>
|
<p>If adjList might have duplicate names, you should group the items before pushing to dictionary.</p>
<pre><code>Dictionary<string, decimal> adjDictionary = adjList
.GroupBy(a => a.PropName)
.ToDictionary(g => g.Key, g => g.Sum(a => a.AdjVal))
propList.ForEach(p =>
{
decimal a;
adjDictionary.TryGetValue(p.Name, out a);
p.Total = p.Val + a;
});
</code></pre>
| 34,166
|
<p>For those who had developed applications with D,</p>
<ul>
<li>which libraries did you use to build your application?</li>
<li>those libraries were good documented?</li>
<li>did you use Tango?</li>
<li>do you feel that D is ready to build big applications?</li>
<li>which IDE did you use? Descent maybe?</li>
</ul>
|
<p>Note that any C library can be used with D, as D fully supports the C ABI. D has some limited support for C++ libraries, though not C++ template libraries.</p>
|
<p>Code blocks seems to <a href="http://blog.fedora-fr.org/bioinfornatics/post/Code%3A%3ABlocks-and-D-programming" rel="nofollow noreferrer">support D</a>.</p>
| 36,803
|
<p>In my models, there are lots of attributes and methods that perform some calculation based on the model instance's attributes. I've been having the methods return nil if the attributes that the calculations depend on are nil. As a consequence of this design decision, I'm doing a lot of nil checks before displaying these values in my views. </p>
<p>I thought about having these methods return zero instead of nil when they don't have enough information, but I chose nil because zero is a valid computation result and nil implies that there was not enough information.</p>
<p>Should I return 0 instead of nil? Is there any other pattern that I could use to avoid doing a bunch of nil checks in my views? </p>
|
<p>I tend to think you are doing things right if your problem is choosing whether to display, or not display, the results of a calculation. If it would make no sense to display any value, then nil is perfectly reasonable.</p>
<p>If, however, your business logic is resulting in you getting into a state where much of the view will be habitually blank, then you probably should refactor such that your program loses its leaky abstractions.</p>
<p>Consider, for example, an application which starts by tracking recipes for <code>Food</code>. Then, as requirements morph, we get the notion of pies needing to display different information than burgers. Rather than having a <code>calculate_deliciousness_of_pie_or_nil_for_burger</code> method, and then checking for nil in the view, I'd break that into a pie view for pies and a burger view for burgers. This might (probably would) require rethinking my object abstractions.</p>
|
<p>I attack this problem using two approaches.</p>
<p>I try to move more demanding checks into the model. For instance, method <code>Apartment#address_visible?(current_user)</code> makes it much more cleaner.</p>
<p>Since Rails 2.3 there is also <code>#try</code> method that calls a method only if it is already defined. It can be easily included into your project using chris' <a href="http://ozmm.org/posts/try.html" rel="nofollow noreferrer">example</a>. This is for the most simple cases.</p>
| 35,897
|
<p>I don't understand it. </p>
<p>The ids of html elements in the master page are changed by the same id but with a prefix and it's breaking the css design.</p>
<p>In the master page I have:</p>
<pre><code><div id="container" runat="server">
<asp:ContentPlaceHolder ...
...
</code></pre>
<p>The above code is rendered</p>
<pre><code><div id="ctl00_ctloo_container">
...
</code></pre>
<p>And the CSS styles are gone obviously.</p>
<p>How do I stop it?</p>
<p>Thanks!</p>
|
<p>WebForms should only rewrite the ID's of server controls (like <code><asp:ContentPlaceHolder /></code>, not ordinary HTML element like <code><div id="container"></code> without <code>runat="server"</code></p>
<p>You cannot prevent the framework from rewriting ID's on server controls. You can use class names instead, though.</p>
|
<p>I do not need the runat="server" tag and have removed it. Don't know why it was there ... Ids are not changed now. Thanks</p>
| 24,421
|
<p>Cura is slicing my object (a gear with text) with a partial top layer, and I believe it has to do with layer height and rounding issues. I have been able to solve this at specific heights 10-14mm using a layer height of 0.25 mm, however other heights will cause this issue to arise again. There must be a solution to this that doesn't require the user to constantly be adjusting layer height and object height in order to resolve what I perceive to be a rounding issue. </p>
<p>Here is the model:
<a href="https://filebin.ca/3f2g2s0dklzR/hackEly_v1.0_joined_text_2.stl" rel="nofollow noreferrer">https://filebin.ca/3f2g2s0dklzR/hackEly_v1.0_joined_text_2.stl</a></p>
<p>Here are my settings:
<a href="https://i.stack.imgur.com/EBRnV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EBRnV.png" alt="Settings 1"></a>
<a href="https://i.stack.imgur.com/7oZZY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7oZZY.png" alt="Settings 2"></a></p>
<p>Here is the model at a height of 10 mm:
Note the diagonal line, this is the line between two layers.
<a href="https://i.stack.imgur.com/hz3gz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hz3gz.png" alt="Object 10mm"></a></p>
<p>Here is the model at a height of 13 mm:
Note the diagonal line again, and how it is farther to the right than the 10mm height view.
<a href="https://i.stack.imgur.com/8SLTX.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8SLTX.jpg" alt="enter image description here"></a></p>
<p>I don't believe that this is not a non-manifold issue. I have also tested this using a gear without text.</p>
<p>Like I mentioned, I can get rid of that layer division at certain layer heights and object heights (e.g. 0.25mm layer height), but I would like to find out how to get rid of this issue <em>regardless of object/layer height</em>. Thank you for your help.</p>
|
<p>Your model isn't perfect. I took it into Windows 10 3D Builder for simplicity. I kept clicking the "Mirror" function and noticed as it basically flipped there is some slight movement. I measured some points from bottom to top and noticed some differences. </p>
<p>Try to take your model into some software to fix/flatten it. Or recreate it making sure its perfectly flat on both sides. It is definitely not your Cura software.</p>
|
<p>Even though you've selected an answer, here's another viewpoint. Ignoring the brim that I've added by default via my slicer, you can see the first few layers are not complete. This indicates a model that's a fraction of a degree off-plane. </p>
<p><a href="https://i.stack.imgur.com/2VRCT.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2VRCT.jpg" alt="slanted model image"></a></p>
<p>Any number of methods can be used to correct this. Meshmixer has a great "align" function in the edit menu which will drop it on the bed. My slicer, S3D will work in that respect with "Place surface on bed" or some such terms.</p>
<p>The image below represents the result of using Align in Meshmixer, Inspector (repair all) and export. The STL file imported to S3D presented exactly the same image on the first layer as in the image above. When I used "Place surface on bed and selected the horizontal cross-member as the reference surface, the first layer result is this:</p>
<p><a href="https://i.stack.imgur.com/goSvf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/goSvf.png" alt="first layer after repair"></a></p>
<p>The slicer completed the imaging with this result, clearly with no diagonal artifacts:</p>
<p><a href="https://i.stack.imgur.com/kAlU3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kAlU3.png" alt="last layer"></a></p>
| 711
|
<p>I just installed the first release candidate of Python 3.0 and got this error after typing:</p>
<pre><code>>>> help('modules foo')
</code></pre>
<pre>[...]
LookupError: unknown encoding: uft-8</pre>
<p>Notice that it says <strong>uft</strong>-8 and not <strong>utf</strong>-8</p>
<p>Is this a py3k specific bug or a misconfiguration on my part? I do not have any other versions of Python installed on this French locale Windows XP SP3 machine.</p>
<p><strong>Edit</strong></p>
<p>A <a href="http://bugs.python.org/issue4135?@ok_message=msg%2074871%20created%3Cbr%3Eissue%204135%20created&@template=item" rel="nofollow noreferrer">bug</a> has been filled by <a href="https://stackoverflow.com/users/22899/alex-coventry">Alex Coventry</a> on October 16th.</p>
|
<p>It's not a typo, it's a deliberate error in a test module.</p>
<pre><code>met% pwd
/home/coventry/src/Python-3.0rc1
met% rgrep uft-8 .
./Lib/test/bad_coding.py:# -*- coding: uft-8 -*-
./py3k/Lib/test/bad_coding.py:# -*- coding: uft-8 -*-
</code></pre>
<p>Removing this module causes the <code>help</code> command to fall over in a different way.</p>
<p>It is a bug, however. Someone should file a report.</p>
|
<p>Looks like a typo in a config file somewhere, whether in the Py3k package or on your machine. You might try installing the stable final Python 2.6 (which supports 3.0 syntax changes with imports from <code>__future__</code>), and if that works you should probably file a bug report.</p>
| 25,813
|
<p>I lost my MySQL username and password. How do I retrieve it?</p>
|
<blockquote>
<p>Stop the MySQL process.</p>
<p>Start the MySQL process with the --skip-grant-tables option.</p>
<p>Start the MySQL console client with the -u root option.</p>
</blockquote>
<p>List all the users;</p>
<pre><code>SELECT * FROM mysql.user;
</code></pre>
<p>Reset password;</p>
<pre><code>UPDATE mysql.user SET Password=PASSWORD('[password]') WHERE User='[username]';
</code></pre>
<hr />
<p>But <strong>DO NOT FORGET</strong> to</p>
<blockquote>
<p>Stop the MySQL process</p>
<p>Start the MySQL Process normally (i.e. without the --skip-grant-tables option)</p>
</blockquote>
<p>when you are finished. Otherwise, your database's security could be compromised.</p>
|
<p>Although a strict, logical, computer science'ish interpretation of the op's question would be to require <strong>both</strong> "How do I retrieve my MySQL username" <strong>and</strong> "password" - I thought It might be useful to someone to also address the <strong>OR</strong> interpretation. In other words ...</p>
<p>1) How do I retrieve my MySQL username?</p>
<p><strong>OR</strong></p>
<p>2) password</p>
<p>This latter condition seems to have been amply addressed already so I won't bother with it. The following is a solution for the case "How do i retreive my MySQL username" alone. HIH.</p>
<p>To find your mysql username run the following commands from the mysql shell ...</p>
<p>SELECT User FROM mysql.user;</p>
<p>it will print a table of all mysql users.</p>
| 2,639
|
<p>I am working on a project to redesign/ redo an application. The problem is that the old application was written in ASP.net 1.0 and the database is pretty large over 100 tables and 300 odd views.The database handles roles and membership in a very shoddy way. It involves a simple workflow too. The app is pain when it comes to maintainence. I have around 3-4 months to redo the software. </p>
<p>The DB design is not to my liking but looking at timeframe migrating data and DB redesign may make the project go off track.</p>
<p>Anyone ran into this situation before?? Any one has any pointers for me as to how to go about this project?? </p>
<p>I would love to get the software up to speed with .NET 3.5 . I am not sure if App redesign would be meaningful without considering the DB</p>
<p>Problem with system: 1. Maintainence and scalability issues. 2. Poor DB design specially in case of user management, the app depends heavily on users and roles etc.</p>
|
<p>Database redesign is a huge effort. If you or someone on your team is not an expert in database design and ETL, you could end up with a worse mess than you have now. </p>
<p>However, is it possible to perhaps fix just the one or two worst parts of the database and thus achieve an improvement overall? Look at the worst performing queries to see what is really wrong (not just from your personal perspective of what you dislike but what really isn't working well now). Maybe something less than a total redesign could give you a major performance boost.</p>
<p>If the reason you dislike the database is that it is not truly relational, it is possible you could compromise by putting in relational tables with new names, moving the data and dropping the old tables, and creating views with the old table names that are structured like the current design. (Do not do without a current datbase backup first!!!!) That way you can start to change code to the new more effective design but the stuff you don't get changed will still work until you get to it.</p>
|
<p>If you don't want to do the database redesign, you could always restructure your user experience(UI). Use an good pattern if you choose to work with webforms then my advise is to use Model View Presenter-pattern or if you know a lot of javascript and html and you don't like the webforms model use the new ASP.NET MVC.</p>
<p>But before you are going to restructe your application you must understand your design pattern you choose. </p>
<p>I'll hope you could do something with this info.</p>
| 47,473
|
<p>It's been a while since I've programmed a GUI program, so this may end up being super simple, but I can't find the solution anywhere online. </p>
<p>Basically my problem is that when I maximize my program, all the things inside of the window (buttons, textboxes, etc.) stay in the same position in the window, which results in a large blank area near the bottom and right side. </p>
<p>Is there a way of making the the elements in the program to stretch to scale?</p>
|
<p>You want to check and properly set the Anchor and Dock properties on each control in the Form. The Anchor property on a control tells which sides of the form (top, bottom, left, right) the control is 'anchored' to. When the form is resized, the distance between the control and its anchors will stay the same. This lets you make a control stay in the bottom right corner for example.</p>
<p>The Dock property instructs the control to fill the entire parent form or to fill one side of it (again top, bottom, left or right).</p>
|
<p>Look at the Dynamic Layout: Anchoring and Docking sample at <a href="http://msdn.microsoft.com/en-us/library/aa289756(VS.71).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/aa289756(VS.71).aspx</a></p>
<p>It's in VB, but the concepts and the propeties/methods you need are the same in C#.</p>
| 18,642
|
<p>I create an <code>NSURLRequest</code> to post my data in the iPhone application to a server to proceed the PHP script. My PHP script is look like this.</p>
<pre><code><?php
$name = $_POST['name'];
$email = $_POST['email'];
$link = mysql_connect("localhost", "fffasfdas","Nfdsafafs") or die ("Unable to connect to database.");
mysql_select_db("muradsbi_mydatabase") or die ("Unable to select database.");
$sqlstatement= "INSERT INTO dbname (name,email) VALUES ('$name','$email')";
$newquery = mysql_query($sqlstatement, $link);
echo 'thanks for your register';
?>
</code></pre>
<p>and my <code>NSURLRequst</code> is created like below.</p>
<pre><code>NSString *myRequestString = @"&name=Hello%20World&email=Ohai2u";
NSData *myRequestData = [NSData dataWithBytes: [myRequestString UTF8String] length: [myRequestString length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString: @"http://www.google.com/"]];
[request setHTTPMethod: @"POST"];
[request setHTTPBody: myRequestData];
NSData *returnData = [NSURLConnection sendSynchronousRequest: request returningResponse: nil error: nil];
</code></pre>
<p>However, this site is unable to get the data from this application and save it to the database, but I know it was connected succussfully because my application is able to get the response data from the server. I don't know whether my variable name is declared in the wrong way or others issues. How can I fix it?</p>
|
<p>You should remove the leading <code>&</code> in <code>myRequestString</code> and the problem is likely that the correct <code>content-type</code> header is not being sent. Try adding a call to</p>
<pre><code>[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
</code></pre>
<p>You should also not pass <code>nil</code> for error, so you can see what the client thinks is going on.</p>
<p>Unrelated, but your PHP code is open to <a href="http://en.wikipedia.org/wiki/SQL_injection" rel="noreferrer">SQL injection attacks</a>.</p>
|
<p>try this</p>
<pre><code>NSString *name = [[NSString alloc]initWith String: @"Hello World"];
NSString *email = [[NSString alloc]initWith String: @"Ohai2u"];
NSString *urlString = [NSString stringWithFormat:@"http://somedomain.com/sendMail.php?name=%@&email=%@",
[name stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
[email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSURL *url = [[NSURL alloc] initWithString:urlString];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
NSData *urlData;
NSURLResponse *response;
urlData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:nil];
[url release];
</code></pre>
<p>just dont forget to <strong>release</strong> the strings</p>
<p>set the headers in the PHP script</p>
| 42,761
|
<p>On various pages throughout my PHP web site and in various nested directories I want to include a specific file at a path relative to the root.</p>
<p>What single command can I put on both of these pages...</p>
<pre>http://www.example.com/pageone.php</pre>
<pre>http://www.example.com/somedirectory/pagetwo.php</pre>
<p>...to include this page:</p>
<pre>http://www.example.com/includes/analytics.php</pre>
<p>This does not work:</p>
<pre><code><?php include('/includes/analytics.php'); ?>
</code></pre>
<p>Does it matter that this is hosted in IIS on Windows?</p>
|
<p>You can just use <code>include $_SERVER['DOCUMENT_ROOT'] . "/includes/analytics.php";</code></p>
|
<p>The tilde is interpreted as a special character by the shell, so using it inside PHP code won't work regardless of OS.</p>
<p>If you're trying to access something relative to a user home directory you could try <code>getenv()</code> - I'm pretty sure Windows sets an environment variable equivalent to <code>$HOME</code>.</p>
| 44,858
|
<p>We're currently using Mantis as our bugtracker, and we're pretty much sick and tired with it. The developers want more SVN integration, the customers want an easier system to work with.</p>
<p>As such, we're looking for a new bugtracker and at the moment we're looking at Redmine. However, in its default setup it doesn't match our desired workflow, or at least not much better than Mantis does.</p>
<p>We have the following workflow, and would like a bugtracker to match it. </p>
<ul>
<li>A bug is reported (often by the customer), and is considered 'new'.
These bugs are regularly reviewed and either acknowledged (it's a bug) or marked as a feature (customer often needs to pay) and delayed until the financial part has been worked out.</li>
<li>The bugs are then assigned and handled by a developer</li>
<li>when finished, it's marked as 'ready-for-review' (by another developer)</li>
<li>when reviewed it's marked as 'reviewed'</li>
<li>when marked as 'reviewed', the original developer places the new code at the staging environment and marks the bug as 'ready-to-be-tested' (by the bug-reporter)</li>
<li>bug-reporter marks the bug as 'resolved'</li>
<li>when placed on production, bug-reporter closes the bug</li>
</ul>
<p>Of course, feedback is often required especially during the early stages. We're looking for a way to distinguish between who is required to take the next step, and who the bug is assigned to (developer). We also want the customer to do so using a simple gui - asking them to change the assignee from their own account to the developer, or even more difficult: a 3rd party (think: design agency) has just too much to ask using the regular gui's.
The gui should show them what to do and which options there are - not search for them.</p>
<p>Does anyone have any experience with a bugtracker that works this way? Is our workflow really wack? How do you make sure everyone involved understands where the bug stands, and who is required to take which step?</p>
|
<p>Last year we had the same problem, and we figured out that the best solution for us was <a href="http://www.atlassian.com/software/jira/" rel="nofollow noreferrer">Jira</a>.
With respect our workflow is more robust and complicated than yours.</p>
|
<p>I've been using Trac for a small personal project, and at work we used Bugzilla for this.</p>
<p>The workflow you described also sounds like how Red Hat utilizes Bugzilla.</p>
| 38,200
|
<p>I've done some research and I can't really find a preferred way to do updating of form controls from a worker thread in C#. I know about the BackgroundWorker component, but what is the best way to do it without using the BackgroundWorker component?</p>
|
<p>There's a general rule of thumb that says don't update the UI from any thread other than the UI thread itself. Using the features of the BackgroundWorker is a good idea, but you don't want to and something is happening on a different thread, you should do an "Invoke" or BeginInvoke to force the delegate to execute the method on the UI thread.</p>
<p>Edit: Jon B made this good point in the comments:</p>
<blockquote>
<p>Keep in mind that Invoke() is
synchronous and BeginInvoke() is
asynchronous. If you use Invoke(), you
have to be careful not to cause a
deadlock. I would recommend
BeginInvoke() unless you really need
the call to be synchronous.</p>
</blockquote>
<p>Some simple example code:</p>
<pre><code>// Updates the textbox text.
private void UpdateText(string text)
{
// Set the textbox text.
m_TextBox.Text = text;
}
public delegate void UpdateTextCallback(string text);
// Then from your thread you can call this...
m_TextBox.Invoke(new UpdateTextCallback(this.UpdateText),
new object[]{"Text generated on non-UI thread."});
</code></pre>
<p>The code above is from a FAQ about it <a href="http://blogs.msdn.com/csharpfaq/archive/2004/03/17/91685.aspx" rel="noreferrer">here</a> and a longer more involved one <a href="http://weblogs.asp.net/justin_rogers/articles/126345.aspx" rel="noreferrer">here</a>.</p>
|
<p>There's a discussion related to this <a href="https://stackoverflow.com/questions/6184/how-do-i-make-event-callbacks-into-my-win-forms-thread-safe#6189">here</a> and one <a href="https://stackoverflow.com/questions/120540/how-to-update-components-in-different-threads-net-cf">here</a>.</p>
<p>Essentially, you use Invoke to accomplish it.</p>
<p>Best of luck!</p>
| 25,351
|
<p>I have a directory with 500,000 files in it. I would like to access them as quickly as possible. The algorithm requires me to repeatedly open and close them (can't have 500,000 file open simultaneously).</p>
<p>How can I do that efficiently? I had originally thought that I could cache the inodes and open the files that way, but *nix doesn't provide a way to open files by inode (security or some such).</p>
<p>The other option is to just not worry about it and hope the FS does good job on file look up in a directory. If that is the best option, which FS's would work best. Do certain filename patterns look up faster than others? eg 01234.txt vs foo.txt</p>
<p>BTW this is all on Linux.</p>
|
<p>Assuming your file system is <a href="http://en.wikipedia.org/wiki/Ext3" rel="nofollow noreferrer">ext3</a>, your directory is indexed with a hashed B-Tree if dir_index is enabled. That's going to give you as much a boost as anything you could code into your app.</p>
<p>If the directory is indexed, your file naming scheme shouldn't matter.</p>
<p><a href="http://lonesysadmin.net/2007/08/17/use-dir_index-for-your-new-ext3-filesystems/" rel="nofollow noreferrer">http://lonesysadmin.net/2007/08/17/use-dir_index-for-your-new-ext3-filesystems/</a></p>
|
<p>Another question is how much data is in the files? Is an SQL back end an option? </p>
| 39,986
|
<p>I have an website. When the user is logged the session details will loaded.
When the user logged out the session details will abandoned. (Log out by clicking the logout menu)
when the user simply closes the browser then how to destroy the session.</p>
<p>In the next time its get logging with the same session data. I need to avoid this.</p>
|
<p>As part of your handling of the logout, call Session.Clear() to clear the key/value pairs:</p>
<p><a href="http://msdn.microsoft.com/en-us/library/system.web.sessionstate.httpsessionstate.clear.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/system.web.sessionstate.httpsessionstate.clear.aspx</a></p>
|
<p>You could configure your sessions to time out quicker.</p>
<p>In web.config: </p>
<pre><code>< sessionState ... timeout="5" />
</code></pre>
| 35,961
|
<p>Here's the scenario. I'm debugging my own app (C/C++) which is using some library developed by another team in the company. An assertion fails when my code generates some edge case. Its a pain because the assertion is not formulated correctly so the library function is working OK but I get all these interruptions where I just have to continue (lots as its in a loop) so I can get to the stuff I'm actually interested in. I have to use the debug version of the library when debugging for other reasons. The other team wont fix this till next release (hey, it works on our machine).</p>
<p>Can I tell the debugger to ignore the breakpoints asserted by this section of code (i.e. can it auto-continue for me).</p>
|
<p>If the code is triggering breakpoints on its own (by __debugbreak or int 3), you cannot use conditional breakpoints, as the breakpoints are not know to Visual Studio at all. However, you may be able to disable any such breakpoints you are not interested in by modifying the code from the debugger. Probably not what you want, because you need to repeat this in each debugging session, however still may be better than nothing. For more information read <a href="https://stackoverflow.com/questions/115237/how-to-disable-a-programmatical-breakpoint-assert">How to disable a programmatical breakpoint / assert?</a>.</p>
|
<p>You can use conditional breakpoints. Some links:</p>
<p><a href="http://support.microsoft.com/kb/308469" rel="nofollow noreferrer">http://support.microsoft.com/kb/308469</a><br>
<a href="http://dotnettipoftheday.org/tips/conditional_breakpoint.aspx" rel="nofollow noreferrer">http://dotnettipoftheday.org/tips/conditional_breakpoint.aspx</a></p>
| 39,231
|
<p>Is there a best practice when it comes to setting client side "onclick" events when using ASP.Net controls? Simply adding the onclick attribute results in a Visual Studio warning that onclick is not a valid attribute of that control. Adding it during the Page_Load event through codebehind works, but is less clear than I'd like.</p>
<p>Are these the only two choices? Is there a right way to do this that I'm missing?</p>
<p>Thanks!
Eric Sipple</p>
|
<p><code>**</code><em>just a pre-note on the answer: HTML validation in VS is often BS. It complains about stuff that works IRL, even if that stuff is bad practice. But sometimes you gotta bend the rules to get stuff done.</em></p>
<p>Every ASP.NET page (2.0 and greater) comes with a <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.aspx" rel="nofollow noreferrer">ClientScriptManager</a>. You use this to register javascript from server side code. You can pass in javascript that registers events on controls after the page has loaded, when the HTML controls on the page are all present in the DOM.</p>
<p>It presents a single, unified place on pages to dynamically add javascript, which isn't a bad thing. It is, however, awfully ugly. </p>
<p>In this time of the death of the ASP.NET server control model, you might want to set events the way they will be in the future of ASP.NET MVC. Grab a copy of <a href="http://jquery.com" rel="nofollow noreferrer">jQuery</a> and add it to your website. You can then easily register your events thusly:</p>
<pre><code> <html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("controlId").bind("click", function(e) { /* do your best here! */ });
});
</script>
</head>
<!-- etc -->
</html>
</code></pre>
|
<p>Fix grammatical or spelling errors.</p>
<p>Clarify meaning without changing it.</p>
<p>Correct minor mistakes.</p>
<p>Add related resources or links.</p>
<p>Always respect the original author.</p>
| 22,066
|
<p>Just recently started having issues with an SQL Server Agent Job that contains an SSIS package to extract production data and summarize it into a separate reporting database. </p>
<p>I <em>think</em> that some of the Alerts/Notifications settings I tried playing with caused the problem as the job had been running to completion unattended for the previous two weeks.</p>
<p>So... Where's a good place to start reading up on SQL Agent Alerts and Notifications? <br />I want to enable some sort of alert/notification so that I'm always informed: </p>
<ol>
<li>That the job completes successfully (as a check to ensure that it's always executed), or </li>
<li>That the job ran into some sort of error, which should include enough info (such as error number) that I can diagnose the cause of the error</li>
</ol>
<p>As always, any help will be greatly appreciated!</p>
|
<p><a href="http://msdn.microsoft.com/en-us/library/ms130214(SQL.90).aspx" rel="nofollow noreferrer">Books Online</a> is probably a good place to start (or at least I like it and generally find it useful).</p>
<p>SQLMenace and bofe made some good points. Here's my additional two cents:</p>
<p>I'd recommend <a href="http://msdn.microsoft.com/en-us/library/ms188298(SQL.90).aspx" rel="nofollow noreferrer">configuring Database Mail</a> rather than SQL Mail (i.e. SMTP vs. MAPI, which I think is deprecated anyway). Once you get the mail profile configured, you'll have to also configure the SQL agent to use that mail profile (which is just a page of settings for the agent properties), or else your SSIS job notifications won't actually get sent, even though you can successfully send a test email from Management Studio.</p>
<p>I don't use alerts as often as job notifications, so the only tricky thing I can recall about them is that if you're raising an error and you want the alert to email you when that happens, you have to make sure that the raised error gets written to the log. I think that just boils down to "RAISERROR ... WITH LOG"; here's the <a href="http://msdn.microsoft.com/en-us/library/ms178592.aspx" rel="nofollow noreferrer">BOL link</a> for the syntax details. </p>
|
<p>You'll want to have "When the job completes" marked in your notifications page on the job's properties.</p>
<p>Just go to that dropdown and switch it to job completion instead of failure (which is on the screenshot).</p>
<p><img src="https://i.stack.imgur.com/HGlQh.png" alt="Job_Properties_Notification"></p>
<p>You'll also want to make sure that your server has e-mail configured. I think it's under SQL Surface Area Configuration for Features.</p>
| 4,227
|
<p>What are the options? How popular are they? Do these IDEs give similar/better functionality compared to visual studio?</p>
|
<p>Yes - you can try using SharpDevelop:</p>
<p><a href="http://www.icsharpcode.net/OpenSource/SD/" rel="nofollow noreferrer">http://www.icsharpcode.net/OpenSource/SD/</a></p>
<p>Or you can just use notepad, or notepad++</p>
<p><a href="http://notepad-plus.sourceforge.net/" rel="nofollow noreferrer">http://notepad-plus.sourceforge.net/</a></p>
<p>Then compile on the command line.</p>
<p><strong>Edit</strong>: If you're looking for a free solution - try Visual Studio C# Express Edition:</p>
<p><a href="http://www.microsoft.com/express/vcsharp/" rel="nofollow noreferrer">http://www.microsoft.com/express/vcsharp/</a></p>
|
<p>Check out the mono project. <a href="http://www.mono-project.com/" rel="nofollow noreferrer">http://www.mono-project.com/</a><br>
It's the '.NET for linux' project.<br>
They also have an ide based on eclipse as part of the whole thing. Never used it before but I've used eclipse for java and some php work, and eclipse is pretty good</p>
<p><strong>Edit</strong>: the ide is called MonoDevelop. Seen at <a href="http://www.monodevelop.com/" rel="nofollow noreferrer">http://www.monodevelop.com/</a></p>
| 6,028
|
<p>I am trying to print an item with a rectangular grid (using PLA on Ultimaker 2+):</p>
<p><a href="https://i.stack.imgur.com/RHcqX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RHcqX.png" alt="item with a grid"></a></p>
<p>Holes are 4x4 mm, distance between holes (wall thickness): 1mm. I am printing with 0.4 mm nozzle.</p>
<p>Unfortunately, Ultimaker Cura generates G-code which prints each rectangle on its own and in a quite a bad way:</p>
<p><a href="https://i.stack.imgur.com/I7nE6.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/I7nE6.gif" alt="print preview"></a></p>
<p>The printer head tries to draw a rectangle, then moves in the direction opposite to a last laid line, which with not perfect adhesion of single line messes up the print pretty badly: it often picks up last rectangle side and drags it.</p>
<p>Any way to change the way Ultimaker Cura approaches to lay out the grid? I would imagine that long lines that are connected to other lines would adhere to bed much better than individual squares, but I don't see any options that would allow to alter it.</p>
|
<p>Slicers never create a grid by crossing the already printed lines - they print perimeters and thicken them into a shell. So if the picture that is to be printed is a #, it does not lay down first the || and then the = crossing over it, it lays down an inner square and then builds the rest to get to the shape. This operation rule is held for <em>shells</em>, but not for <em>infill</em> patterns.</p>
<p>As you describe the printer picking up the printed, you have adhesion problems and your first layer might be not level or too thick. </p>
<p>You might also want to enable "print thin walls" and use 2 or 3 perimeters.</p>
|
<ol>
<li>Use the latest stable Cura 3.6.0</li>
<li>Ensure that the setting "Wall Line Count" > 1, recommended value is 3-4</li>
<li>Uncheck the setting flag "Outer Before Inner Walls"</li>
</ol>
| 1,167
|
<p>I keep finding that if I have nested divs inside each other, and one of the inner ones is floated, the outer one won't expand around it.</p>
<p>Example:</p>
<pre><code><div style='background-color:red; '>
asdfasdf
<div style='float:left; background-color:blue; width:400px; height:400px;'>
asdfasdfasdfasdfasdfasdfasdf<br />
asdfasdfasdfasdfasdfasdfasdf<br />
asdfasdfasdfasdfasdfasdfasdf<br />
asdfasdfasdfasdfasdfasdfasdf<br />
asdfasdfasdfasdfasdfasdfasdf<br />
asdfasdfasdfasdfasdfasdfasdf<br />
asdfasdfasdfasdfasdfasdfasdf<br />
asdfasdfasdfasdfasdfasdfasdf<br />
asdfasdfasdfasdfasdfasdfasdf<br />
asdfasdfasdfasdfasdfasdfasdf<br />
asdfasdfasdfasdfasdfasdfasdf<br />
</div>
asdfasdf
</div>
</code></pre>
<p>What do I need to do to the outer div to make it cover the inner one? IE: Put it's border/background color all the way around it?</p>
<p>Also, is there a general principle I am bumping up against here? If so, what should I look up to get a solid understanding of what it is?</p>
<p>Thanks!</p>
<p><strong>Edit</strong></p>
<p>Hi All, </p>
<p>Thanks for the answers, semantically correct and no, and for the links.</p>
<p>Though I will end up using overflow in the final work, I will leave Ant P's answer as accepted, as it was the first one that really worked, and got me out of a short term jam, even though it offends semantic sensibilities.</p>
<p>As a long-time html hack trying to move to decent css layouts, I can certainly understand, and sympathize with, using semantically incorrect hack that gets the job done, though I am sure he will change that habit after this =o)</p>
|
<p>You can do it strictly with CSS using <strong>overflow:hidden</strong></p>
<pre><code><div style='background-color:red;overflow:hidden;'>
...
</div>
</code></pre>
|
<p>This article about <a href="http://natbat.net/2008/Sep/28/css-systems/" rel="nofollow noreferrer">CSS systems</a> is definitely worth a read. As Darko Z said it is staggering to see the semantically incorrect answer given by Ant P. </p>
| 43,605
|
<p>I'm trying to get a JEditorPane to highlight the full width of a displayed line. All the examples I've tried only highlight the textual content. For example if I have content such as this:</p>
<pre><code> ---------------------------------
|Here is some text |
|some more text |
---------------------------------
</code></pre>
<p>within a JEditorPane represented by the box above, then highlighting the first row highlights only the 'Here is some text' (represented between [ and ] below).</p>
<pre><code> ---------------------------------
[Here is some text] |
|some more text |
---------------------------------
</code></pre>
<p>I would like it to highlight the full width of the JEditorPane like the following:</p>
<pre><code> ---------------------------------
[Here is some text ]
|some more text |
---------------------------------
</code></pre>
<p>Is there a way to do this?</p>
|
<p>This seems not too complicated. I would make that a little <a href="https://stackoverflow.com/questions/172184"><strong>code-challenge</strong></a>.</p>
<p>Just create your own custom Highlighter, extending DefaultHighlighter.</p>
<p>Override the <code>paint()</code> method, and simply leave unchanged the width of the rectangle paint: it will be the width of the panel.</p>
<p>You will find in <strong><a href="http://snippets.dzone.com/posts/show/6688" rel="nofollow noreferrer">DZone Snippets a complete example</a></strong>: copy it and run it. Tell me if this is what you are after. It includes the <code>textPane.setSelectionColor(new Color(1.0f, 1.0f, 1.0f, 0.0f));</code> addition you mention in your answer.</p>
<p><a href="http://www.freeimagehosting.net/uploads/94a3a990e4.png" rel="nofollow noreferrer">alt text http://www.freeimagehosting.net/uploads/94a3a990e4.png</a></p>
|
<p>To prevent selection highlighting from interfering with VonC's solution I added the following line to the TextHighlight constructor (essentially making the selection highlight invisible):</p>
<pre><code>textPane.setSelectionColor(new Color(1.0f, 1.0f, 1.0f, 0.0f));
</code></pre>
| 46,041
|
<p>This is for .NET. IgnoreCase is set and MultiLine is NOT set.</p>
<p>Usually I'm decent at regex, maybe I'm running low on caffeine...</p>
<p>Users are allowed to enter HTML-encoded entities (<lt;, <amp;, etc.), and to use the following HTML tags:</p>
<pre><code>u, i, b, h3, h4, br, a, img
</code></pre>
<p>Self-closing <br/> and <img/> are allowed, with or without the extra space, but are not required.</p>
<p>I want to:</p>
<ol>
<li>Strip all starting and ending HTML tags other than those listed above. </li>
<li>Remove attributes from the remaining tags, <em>except</em> anchors can have an href.</li>
</ol>
<p>My search pattern (replaced with an empty string) so far:</p>
<pre><code><(?!i|b|h3|h4|a|img|/i|/b|/h3|/h4|/a|/img)[^>]+>
</code></pre>
<p>This <em>seems</em> to be stripping all but the start and end tags I want, but there are three problems:</p>
<ol>
<li>Having to include the end tag version of each allowed tag is ugly.</li>
<li>The attributes survive. Can this happen in a single replacement?</li>
<li>Tags <em>starting with</em> the allowed tag names slip through. E.g., "<abbrev>" and "<iframe>".</li>
</ol>
<p>The following suggested pattern does not strip out tags that have no attributes.</p>
<pre><code></?(?!i|b|h3|h4|a|img)\b[^>]*>
</code></pre>
<p>As mentioned below, ">" is legal in an attribute value, but it's safe to say I won't support that. Also, there will be no CDATA blocks, etc. to worry about. Just a little HTML.</p>
<p>Loophole's answer is the best one so far, thanks! Here's his pattern (hoping the PRE works better for me):</p>
<pre><code>static string SanitizeHtml(string html)
{
string acceptable = "script|link|title";
string stringPattern = @"</?(?(?=" + acceptable + @")notag|[a-zA-Z0-9]+)(?:\s[a-zA-Z0-9\-]+=?(?:([""']?).*?\1?)?)*\s*/?>";
return Regex.Replace(html, stringPattern, "sausage");
}
</code></pre>
<p>Some small tweaks I think could still be made to this answer:</p>
<ol>
<li><p>I think this could be modified to capture simple HTML comments (those that do not themselves contain tags) by adding "!--" to the "acceptable" variable and making a small change to the end of the expression to allow for an optional trailing "\s--".</p></li>
<li><p>I think this would break if there are multiple whitespace characters between attributes (example: heavily-formatted HTML with line breaks and tabs between attributes).</p></li>
</ol>
<p><strong>Edit 2009-07-23:</strong> Here's the final solution I went with (in VB.NET):</p>
<pre><code> Dim AcceptableTags As String = "i|b|u|sup|sub|ol|ul|li|br|h2|h3|h4|h5|span|div|p|a|img|blockquote"
Dim WhiteListPattern As String = "</?(?(?=" & AcceptableTags & _
")notag|[a-zA-Z0-9]+)(?:\s[a-zA-Z0-9\-]+=?(?:([""']?).*?\1?)?)*\s*/?>"
html = Regex.Replace(html, WhiteListPattern, "", RegExOptions.Compiled)
</code></pre>
<p>The caveat is that the HREF attribute of A tags still gets scrubbed, which is not ideal.</p>
|
<p>Here's a function I wrote for this task:</p>
<pre><code>static string SanitizeHtml(string html)
{
string acceptable = "script|link|title";
string stringPattern = @"</?(?(?=" + acceptable + @")notag|[a-zA-Z0-9]+)(?:\s[a-zA-Z0-9\-]+=?(?:(["",']?).*?\1?)?)*\s*/?>";
return Regex.Replace(html, stringPattern, "sausage");
}
</code></pre>
<p>Edit: For some reason I posted a correction to my previous answer as a separate answer, so I am consolidating them here.</p>
<p>I will explain the regex a bit, because it is a little long.</p>
<p>The first part matches an open bracket and 0 or 1 slashes (in case it's a close tag).</p>
<p>Next you see an if-then construct with a look ahead. (?(?=SomeTag)then|else) I am checking to see if the next part of the string is one of the acceptable tags. You can see that I concatenate the regex string with the acceptable variable, which is the acceptable tag names seperated by a verticle bar so that any of the terms will match. If it is a match, you can see I put in the word "notag" because no tag would match that and if it is acceptable I want to leave it alone. Otherwise I move on to the else part, where i match any tag name [a-z,A-Z,0-9]+</p>
<p>Next, I want to match 0 or more attributes, which I assume are in the form attribute="value". so now I group this part representing an attribute but I use the ?: to prevent this group from being captured for speed: (?:\s[a-z,A-Z,0-9,-]+=?(?:(["",']?).<em>?\1?))</em></p>
<p>Here I begin with the whitespace character that would be between the tag and attribute names, then match an attribute name: [a-z,A-Z,0-9,-]+</p>
<p>next I match an equals sign, and then either quote. I group the quote so it will be captured, and I can do a backreference later \1 to match the same type of quote. In between these two quotes, you can see I use the period to match anything, however I use the lazy version *? instead of the greedy version * so that it will only match up to the next quote that would end this value.</p>
<p>next we put a * after closing the groups with parenthesis so that it will match multiple attirbute/value combinations (or none). Last we match some whitespace with \s, and 0 or 1 ending slashes in the tag for xml style self closing tags.</p>
<p>You can see I'm replacing the tags with sausage, because I'm hungry, but you could replace them with empty string too to just clear them out.</p>
|
<p>I think i originally intended to make the values optional, but didn't follow through, as I can see that I added a <code>?</code> after the equals sign and grouped the value portion of the match. Let's add a <code>?</code> after that group (marked with a carot) to make it optional in the match as well. I'm not at my compiler right now, but see if this works:</p>
<pre><code>@"</?(?(?=" + acceptable + @")notag|[a-z,A-Z,0-9]+)(?:\s[a-z,A-Z,0-9,\-]+=?(?:(["",']?).*?\1?)?)*\s*/?>";
^
</code></pre>
| 39,500
|
<p>Is there a way to persist an enum to the DB using NHibernate? That is have a table of both the code and the name of each value in the enum.</p>
<p>I want to keep the enum without an entity, but still have a foreign key (the int representation of the enum) from all other referencing entities to the enum's table.</p>
|
<p>Why are you guys over complicating this? It is really simple.</p>
<p>The mapping looks like this:</p>
<pre><code><property name="OrganizationType"></property>
</code></pre>
<p>The model property looks like this:</p>
<pre><code>public virtual OrganizationTypes OrganizationType { get; set; }
</code></pre>
<p>The Enum looks like this:</p>
<pre><code>public enum OrganizationTypes
{
NonProfit = 1,
ForProfit = 2
}
</code></pre>
<p>NHibernate will automatically figure it all out. Why type more than you need????</p>
|
<p>Try using a stategy pattern. Uou can then put logic into your inner classes. I use this quite alot espically when there is logic that should be contained in the "enum". For example the code below has the abstract IsReadyForSubmission() which is then implemented in each of the nested subclasses (only one shown). HTH</p>
<pre><code>[Serializable]
public abstract partial class TimesheetStatus : IHasIdentity<int>
{
public static readonly TimesheetStatus NotEntered = new NotEnteredTimesheetStatus();
public static readonly TimesheetStatus Draft = new DraftTimesheetStatus();
public static readonly TimesheetStatus Submitted = new SubmittedTimesheetStatus();
//etc
public abstract int Id { get; protected set; }
public abstract string Description { get; protected set; }
public abstract bool IsReadyForSubmission();
protected class NotEnteredTimesheetStatus: TimesheetStatus
{
private const string DESCRIPTION = "NotEntered";
private const int ID = 0;
public override int Id
{
get { return ID; }
protected set { if (value != ID)throw new InvalidOperationException("ID for NotEnteredTimesheetStatus must be " + ID); }
}
public override string Description
{
get { return DESCRIPTION; }
protected set { if (value != DESCRIPTION)throw new InvalidOperationException("The description for NotEnteredTimesheetStatus must be " + DESCRIPTION); }
}
public override bool IsReadyForSubmission()
{
return false;
}
}
//etc
}
</code></pre>
| 32,063
|
<p>I have created some extra functionality on my Linq-to-SQL classes to make things easier as I develop my applications. For example I have defined a property that retrieves active contracts from a list of contracts. However if I try to use this property in a lambda expression or in general in a query it either throws an exception that there is no SQL statement matching that property or it generates one query per item (= a lot of roundtrips to the server).</p>
<p>The queries themselves are not overly complex f.ex:</p>
<pre><code>var activeContracts = customer.Contracts.Where(w => w.ContractEndDate == null);
</code></pre>
<p>Whereas I would like it to read as:</p>
<pre><code>var activeContracts = customer.ActiveContracts;
</code></pre>
<p>The main reason for me doing this is because it will minimize logical errors on my part and if I in the future want to change what defines an active contract I don't have to redo a lot of code.</p>
<p>Is there a way to specify on a property what SQL it should genereate. Or is there a way to make sure it is usable in a query like below?</p>
<pre><code>var singleContractCustomers = db.Customers.Where(w => w.ActiveContracts.Count() == 1);
</code></pre>
|
<p>When accessed individually, I suspect that having a query that returns IQueryable would work - however, I expect that when this is part of a larger Expression, the expression interpreter will complain (which seems like what you are describing).</p>
<p>However, I suspect that you might be able to break it down a bit. Try adding (to customer):</p>
<pre><code> public static Expression<Func<Customer, bool>> HasActiveContract
{
get { return cust => cust.Contracts.Count() == 1; }
}
</code></pre>
<p>Then you should be able to use:</p>
<pre><code> var filtered = db.Customers.Where(Customer.HasActiveContract);
</code></pre>
<p>Obviously it is hard to run it (from here) to see what TSQL it comes up with, but I'd be surprised if that does roundtrips; I would expect that to do the COUNT() in the TSQL. As a topmost query, you should also be able to wrap this:</p>
<pre><code> public IQueryable<Customer> CustomersWithActiveContract
{
get { return Customers.Where(Customer.HasActiveContract); }
}
</code></pre>
<p>Does any of that work?</p>
|
<p>That worked like a charm. The SQL statment generated by <strong>CustomersWithActiveContracts</strong> looked fine to me.</p>
<pre><code>{SELECT [t0].[CustomerID], [t0].[cFirstName], [t0].[cLastName]
FROM [dbo].[Customers] AS [t0]
WHERE ((
SELECT COUNT(*)
FROM [dbo].[Contracts] AS [t1]
WHERE (([t1].[ContractEndDate] > @p0) OR ([t1].[ContractEndDate] IS NULL)) AND ([t1].[cId] = [t0].[cId])
)) > @p1
}
</code></pre>
<p>It should also mean that it's possible to build on this query without it generating more trips to the database.</p>
| 23,119
|
<p>I keep finding files which show a size of 10kb but a size on disk on 10gb. Trying to figure out how this is done, anyone have any ideas?</p>
|
<p>You can make sparse files on NTFS, as well as on any real filesystem. :-)</p>
<p>Seek to (10 GB - 10 kB), write 10 kB of data. There, you have a so-called 10 GB file, which in reality is only 10 kB big. :-)</p>
|
<p>I'm not sure about your case (or it might be a mistake in your question) but when you create a NTFS sparse file it will show different sizes for these fields.</p>
<p>When I create a 10MB sparse file and fill it with 1MB of data windows explorer will show:
<br />
<br />
Size: 10MB
<br />
Size on disk: 1MB</p>
<p>But in your case its the opposite. (or a mistake.)</p>
| 40,618
|
<p>I'm having a problem, creating a fixed-size overall panel for a touchscreen GUI application that has to take up the entire screen. In a nutshell, the touchscreen is 800 x 600 pixels, and therefore I want the main GUI panel to be that size.</p>
<p>When I start a new GUI project in NetBeans, I set the properties of the main panel for min/max/preferred size to 800 x 600, and the panel within the 'Design' view changes size. However, when I launch the app, it is resized to the original default size.</p>
<p>Adding this code after initComponents() does not help:</p>
<pre><code>this.mainPanel.setSize(new Dimension(800,600));
this.mainPanel.setMaximumSize(new Dimension(800,600));
this.mainPanel.setMinimumSize(new Dimension(800,600));
this.mainPanel.repaint();
</code></pre>
<p>I've peeked into all of the resource files and cannot seem to find values that would override these (which seems somewhat impossible anyway, given that I'm setting them after initComponents() does its work). I'm using the FreeDesign layout, because I wanted complete control over where I put things.</p>
<p>I suspect the layout manager is resizing things based upon how many widgets I have on the screen, because different prototyped screens come in at differing sizes. </p>
<p>Help is appreciated!</p>
|
<p>Have you tried <a href="http://java.sun.com/docs/books/tutorial/extra/fullscreen/index.html" rel="nofollow noreferrer">java full screen mode</a>?</p>
|
<p>I use this method to complete the task, not sure if its the best and you need to wait calling it until the frame is actually on the screen. </p>
<pre><code>protected void growBig()
{
int screenWidth = java.awt.Toolkit.getDefaultToolkit().getScreenSize().width;
int screenHeight = java.awt.Toolkit.getDefaultToolkit().getScreenSize().height;
Rectangle rectangle = getFrame().getBounds();
rectangle.setSize(screenWidth, screenHeight);
getFrame().setBounds(0, 0, screenWidth, screenHeight);
getFrame().setSize(screenWidth, screenHeight);
getFrame().doLayout();
getFrame().validate();
updateUI();
}
</code></pre>
| 30,891
|
<p>this is the scenario:
multiple web systems (mostly lampp/wampp) exist, most of them with separate login information, (some share it). We're considering the benefits/disadvantages of unifying them somehow, or at least making handling the user administration parts easier.</p>
<p>Due to the nature of some systems (its a mixed bag of custom OSS systems,internally developed software and 3rd party commercial software) we can't unify all login-screens into a single screen.</p>
<p>A idea passed around is a sort of login master brain were we can control all user name creation,permissions,inactivation, etc. This will still make people have to manually log in into every system, but at least it'll make the administrative load of user management easier.</p>
<p>Are there any known solutions to this kind of problem that involves (necesarily, it could be considered) changing the least amount of code/systems possible?</p>
<p><strong>Edit:</strong> <strong>OpenID doesnt work for us</strong> since we have different login needs and some systems we cant directly control how they handle the login process (but we can control the users/passwords).</p>
|
<p>What we did was to centralise all login details in one repository (Active Directory for us), then wrote a c# library to authenticate with wrappers for all the languages we programmed in (PHP, C, .NET, etc). and then just wrote some glue code in the appropriate place for each application. Aside from our in-house apps, we successfully logged into Mediawiki, Subversion, ActiveCollab and Apache this way.</p>
<p>It does involve writing a reasonable amount of code, but not ridiculous amounts, and it will work for the future as well. I can't see a practical solution which would be easier than this. </p>
<p>Reading your question I note that this is more-or-less what you're thinking anyway, but it will work!</p>
|
<p>A lot of people seem to like OpenID for this sort of thing. I'm not sure on it's intranet capabilities though.</p>
<p>Another idea is using your "brain" system to pass authenticated username to the sister/brother applications as a form post, then handle authentication on that system and create their security tickets with what was sent.</p>
<p>Hope you find what you're looking for!</p>
<p>Cheers!</p>
| 30,160
|
<p>I'm running Thunderbird on Windows. I often receive .ics (iCal) attachments - invitations to meetings. Currently I save the attachment to my desktop, open Google Calendar, choose 'Add>Import Calendar', browse to the .ics file, and return to the calendar.</p>
<p>Is there any tool that can speed this up... e.g. I forward the email to a special email address and it automatically parses and adds the event to my google calendar?</p>
|
<p><strong><a href="http://bfish.xaedalus.net/?p=239" rel="nofollow noreferrer">Lightning</a></strong> gives you a plug-in way for Thunderbird to sync with Google Calendar, works both directions. I've used it without any issues, hopefully it will do what you're after.</p>
|
<p><a href="http://www.califyapp.com" rel="nofollow">Calify</a> does just that.<br>
It can open *.ics files in various web calendars, including Google Calendar.</p>
| 12,705
|
<p>I'm working on our back-end encoder service which does an awful lot of video transcoding, and a very small amount of joining of video files. </p>
<p>The transcoding is done using the On2 Flix engine for Windows which works very well, but unfortunately it isn't able to join files (at least as far as I can ascertain - neither the help nor the support are very informative). I'm happy with this for now.</p>
<p>The joining, at the moment, is done using the LEADTOOLS Multimedia software which is, franky, dreadful. It's single threaded and requires STA as it uses a message pump which isn't exactly desirable for a server application. In addition the installation overwrites all our working codecs with a load of its own eval ones, and there is no way to avoid this.</p>
<p>Ideally I'm looking for an API to replace the LEADTOOLs Multimedia one, which can join 3GP and/or MP4 files. Cost isn't too much of a problem. Does anybody have any recommendations?</p>
<p>I know the ideal solution is to write our own tool here, but we're intending to do this in WMF and haven't quite transitioned to Win2008 yet so we need a temporary solution for a couple of months.</p>
<p><strong>Update:</strong></p>
<p>I should point out that encoding is by no means my area of expertise, and I've never had much dealing with unmanaged code being relatively new to the industry (7 years). I also don't have very much time because my day job is dev lead of the services-tier/encoder team which consists of just me and one other person, so we simply don't have a lot of time to spend on the encoder. </p>
<p>Something like the Flix engine where a lot of the underlying complexity is already handled is more what I'm looking for than low-level APIs that have to be called differently depending on input/output file types etc. </p>
<p>If you do have any recommendations, it would be really useful if you could point me at some docs for how they are used etc.</p>
|
<p>FFMPEG's libavcodec and libavformat are your friend. They're extremely versatile and support more than basically anything else, and are effectively the cross-platform standard for multimedia support and manipulation.</p>
<p>You could also try MP4box's library, GPAC, which is an MP4-specific library that is much more powerful than FFMPEG's APIs, but is (given the name) only useful for handling MP4 and 3GP files.</p>
<p>Also, if you're using Flix for transcoding, have you considered upgrading to something more modern? FLV1 and VP6 are rather crappy formats for Flash video; now that Flash supports H.264, there's really no reason to continue using such outdated (and, in the case of VP6, expensive) formats.</p>
|
<p>For x264: you can simply call the executable itself, or you can include the library itself and call it through its API (encoder_open, etc). With .NET its likely more difficult; being a C program, its API is built around C, though I know both C and C++ programs on Windows and Linux have been built that call the API.</p>
<p>There's no real advantage to one over the other for a simple program: either way, x264 only takes a single type of input (raw YV12 video) and spits out a single type of output (H.264 elementary streams, or in the case of the CLI app, it can also mux MP4 and Matroska).</p>
<p>If you need an all-in-one solution, ffmpeg can do the job, as it can automatically handle decoding and pass on the encoding to libx264. If you need more specific assistance, drop by #x264 on Freenode IRC.</p>
| 25,503
|
<p>What's the difference between these two?
Which is better/faster/reliable?</p>
|
<p>SCGI is a language-neutral means of connecting a front-end web server and a web application. WSGI is a Python-specific interface standard for web applications.</p>
<p>Though they both have roots in CGI, they're rather different in scope and you could indeed quite reasonably use both at once, for example having a mod_scgi on the webserver talk to a WSGI app run as an SCGI server. There are multiple library implementations that will run WSGI applications as SCGI servers for you (eg. wsgitools, cherrypy).</p>
<p>They are both 'reliable', in as much as you can consider a specification reliable as opposed to a particular implementation. These days you would probably write your application as a WSGI callable, and consider the question of deployment separately.</p>
<p>Maybe an Apache+mod_wsgi (embedded) interface might be a <em>bit</em> faster than an Apache+mod_scgi+(SCGI wrapper lib), but in all likelihood it's not going to be <em>hugely</em> different. More valuable is the ability to run the application on a variety of servers, platforms and connection standards.</p>
|
<p>They are both specifications for plugging a web application into a web server. One glaring difference is that WSGI comes from the Python world, and I believe there are no non-python implementations.</p>
<p><strong>Specifications are generally not comparable based on better/faster/reliable.</strong> </p>
<p>Only their implementations are comparable, and I am sure you will find good implementations of both specifications.</p>
<p>Perhaps <a href="http://en.wikipedia.org/wiki/SCGI" rel="noreferrer">read</a> and <a href="http://en.wikipedia.org/wiki/WSGI" rel="noreferrer">read</a>.</p>
| 32,128
|
<p>Consider the following code:</p>
<pre><code>void Handler(object o, EventArgs e)
{
// I swear o is a string
string s = (string)o; // 1
//-OR-
string s = o as string; // 2
// -OR-
string s = o.ToString(); // 3
}
</code></pre>
<p>What is the difference between the three types of casting (okay, the 3rd one is not a casting, but you get the intent). Which one should be preferred?</p>
|
<pre><code>string s = (string)o; // 1
</code></pre>
<p>Throws <a href="https://msdn.microsoft.com/en-us/library/system.invalidcastexception" rel="noreferrer">InvalidCastException</a> if <code>o</code> is not a <code>string</code>. Otherwise, assigns <code>o</code> to <code>s</code>, even if <code>o</code> is <code>null</code>.</p>
<pre><code>string s = o as string; // 2
</code></pre>
<p>Assigns <code>null</code> to <code>s</code> if <code>o</code> is not a <code>string</code> or if <code>o</code> is <code>null</code>. For this reason, you cannot use it with value types (the operator could never return <code>null</code> in that case). Otherwise, assigns <code>o</code> to <code>s</code>.</p>
<pre><code>string s = o.ToString(); // 3
</code></pre>
<p>Causes a <a href="https://msdn.microsoft.com/en-us/library/system.nullreferenceexception" rel="noreferrer">NullReferenceException</a> if <code>o</code> is <code>null</code>. Assigns whatever <code>o.ToString()</code> returns to <code>s</code>, no matter what type <code>o</code> is.</p>
<hr>
<p>Use 1 for most conversions - it's simple and straightforward. I tend to almost never use 2 since if something is not the right type, I usually expect an exception to occur. I have only seen a need for this return-null type of functionality with badly designed libraries which use error codes (e.g. return null = error, instead of using exceptions).</p>
<p>3 is not a cast and is just a method invocation. Use it for when you need the string representation of a non-string object.</p>
|
<p>When trying to get the string representation of anything (of any type) that could potentially be null, I prefer the below line of code. It's compact, it invokes ToString(), and it correctly handles nulls. If o is null, s will contain String.Empty.</p>
<pre><code>String s = String.Concat(o);
</code></pre>
| 16,061
|
<p>I have a project containing at least one DLL along with the executable output. I have added a Deployment Project to this solution, which asked me for a name and working directory upon creation like all projects.</p>
<p>I named this "MyProduc_Installer" and have been able to modify all aspects of the installation process except for changing the name of the installer itself. Throughout the install process, the user sees messages like "Welcome to the MyProduct_Installer Installer." Even in the Add/Remove Programs list, this is the application's ill conceived title.</p>
<p>How do I change this setting? I have tried right click/properties, as well as all the View options. I couldn't find anything in the assembly information for the executable project, or solution properties.</p>
<p>I have tried right-clicking on the project in the Explorer to change the properties, but here is what I see:</p>
<p><img src="https://sites.google.com/site/sizerfx/Home/properties.png?attredirects=0" alt="alt text"></p>
<p>There is no setting here to change the project title.</p>
|
<p>If you haven't found the answer to this yet, here is the answer.</p>
<p>Visual Studio has 2 sets of properties for Projects -
1 which you can accesss by selecting the Project in Solution Explorer and then right clicking and selecting 'Properties'. </p>
<p>2nd set of properties is in the 'Properies' window which shows up below the Solution explorer. This is the same property window which is displayed for any of the Form property settings or any other control settings.</p>
<p>The 'Product Name' and other project properties for 'Setup' project can be found in the second property window.</p>
<p>Hope this helps.</p>
<p>AC</p>
|
<p>I happened across this post, where I was having trouble renaming the Product as well.. In regards to using Click Once Publishing.</p>
<p>Since updating all the old names I couldn't get the Publishing to correct itself.
It was found notepading the project file <strong>xyz.vbproj</strong> in my case and updating the <code><ProductName>xyz wrong name</ProductName></code> element that was still wrong.</p>
<p>It was the only place I could find to update it, since the publishing or any property window didn't expose this.</p>
| 16,418
|
<p>This is the text from MSDN comment: "According to the book ATL Internals (2ed) the use of attributes is deprecated and should not be used in new ATL projects."</p>
<p>But WHY?!! </p>
|
<p>In ATL these attributes were a compiler trick. They were not a core part of the platform like attributes in C#. They were also more confusing to debug than macros's and the method of dumping generated attribute code was a hassle.</p>
<p>I suspect another issue is likely to have been C++ compiler compatibility and standards-adherence. Attributes didn't make for more beautiful C++ code, and perhaps this syntax may be used in a future version of a real C++ standard.</p>
|
<p>Appendix D of the book goes into this.</p>
<p>Attributed ATL requires compiler extensions, and the problems encountered include</p>
<ul>
<li>debugging either code generated by the attribute or the interaction between the attribute and your code</li>
<li>no control over the code generated</li>
<li>bugs, especially around connection points</li>
</ul>
| 7,303
|
<p><strong>A Little Background Information</strong>:<br>
I've been looking at a few PHP framework recently, and it came down to two. The Zend Framework or CodeIgniter. </p>
<p>I prefer CodeIgniter, because of its simple design. It's very bare bone, and it is just kept simple. The thing I don't like though is the weak template system. The template system is important for me, because I will be working with another designer. Being able to give him a good template system is a big plus.</p>
<p>Zend was the second choice, because of the better template system that is built in. Zend is a different beast though compared to CodeIgniter. It emphasis "loose coupling between modules", but is a bigger framework. I don't like to feel like I have many things running under the hood that I never use. That is unnecessary overhead in my opinion, so I thought about putting a template system into CodeIgniter: Smarty.</p>
<p><strong>Question(s)</strong>: How easy/hard is the process to integrate Smarty into CodeIgniter? From my initial scan of the CodeIgniter documentation, I can see that the layout of the framework is easy enough to understand, and I anticipate no problems. I want to know if anyone has used it before, and therefore are aware of any "gotchas" you my have experienced that is going to make this harder than it should be or impossible to pull off. I also want to know if this is a good thing to do at all. Is the template system in CodeIgniter enough for normal use? Are there any other template modules that are good for CodeIgniter aside from Smarty? I better off with Zend Framework? Is any wheel being invented here?</p>
|
<p>Slightly OT, hope you don't mind...</p>
<p>I'm a Zend Framework user and I think it's worth saying that the loose coupling means you don't need to include any files you're not actively using. Hopefully this negates your concern about unnecessary overhead.</p>
<p>With the layouts stuff added in a recent release of ZF, its templating is really hard to fault... and it's completely pluggable as Favio mentions. The more I use ZF, the more I like it; they do things the way I would do them!</p>
|
<p>Check out this <a href="http://codeigniter.com/forums/viewthread/94035/" rel="nofollow noreferrer">custom CodeIgniter templating library</a>. I've already used it on several projects and it is easy to use. I know this post is late but it's worth checking out.</p>
| 6,229
|
<p>I have a ASP.NET application running on a remote web server and I just started getting this error:</p>
<pre><code>Method not found: 'Void System.Collections.Generic.ICollection`1..ctor()'.
</code></pre>
<p>I disassembled the code in the DLL and it seems like the compiler is incorrectly optimizing the code. (Note that Set is a class that implements a set of unique objects. It inherits from IEnumerable.) This line:</p>
<pre><code>Set<int> set = new Set<int>();
</code></pre>
<p>Is compiled into this line:</p>
<pre><code>Set<int> set = (Set<int>) new ICollection<CalendarModule>();
</code></pre>
<p>The CalendarModule class is a totally unrelated class!! Has anyone ever noticed .NET incorrectly compiling code like this before?</p>
<p><strong>Update #1:</strong> This problem seems to be introduced by Microsoft's <a href="http://research.microsoft.com/~mbarnett/ILMerge.aspx" rel="nofollow noreferrer">ILMerge</a> tool. We are currently investigating how to overcome it.</p>
<p><strong>Update #2:</strong> We found two ways to solve this problem so far. We don't quite understand what the underlying problem is, but both of these fix it:</p>
<ol>
<li><p>Turn off optimization.</p></li>
<li><p>Merge the assemblie with ILMerge on a different machine.</p></li>
</ol>
<p>So we are left wondering if the build machine is misconfigured somehow (which is strange considering that we have been using the machine to build releases for over a year now) or if it is some other problem.</p>
|
<p>Ahh, ILMerge - that extra info in your question really helps with your problem. While I wouldn't ever expect the .net compiler to fail in this way I would expect to occasionally see this sort of thing with ILMerge (given what it's doing).</p>
<p>My guess is that two of your assemblies are using the same optimisation 'trick', and once merged you get the conflict.</p>
<p>Have you raised the bug with Microsoft?</p>
<p>A workaround in the meantime is to recompile the assemblies from source as a single assembly, saving the need for ILMerge. As the csproj files are just XML lists they're basically easy to merge, and you could automate that as an extra MSBuild step.</p>
|
<p>Was code recently deployed to that server? Could someone have pushed a build without your knowledge? Can you go to source control, pull the latest, and duplicate the issue?</p>
<p>At this point, with the given information, I doubt it's the compiler. </p>
| 15,025
|
<blockquote>
<p><strong>Possible Duplicate:</strong><br>
<a href="https://stackoverflow.com/questions/557081/how-do-i-get-the-hmodule-for-the-currently-executing-code">How do I get the HMODULE for the currently executing code?</a> </p>
</blockquote>
<p>I'm trying to find a resource in my own module. If this module is an executable, that's trivial - <code>GetModuleHandle(NULL)</code> returns the handle of the "main" module.</p>
<p>My module, however, is a DLL that is loaded by another executable. So <code>GetModuleHandle(NULL)</code> will return the module handle to that executable, which is obviously not what I want.</p>
<p>Is there any way to determine the module handle of the module that contains the currently running code? Using the DLL's name in a call to <code>GetModuleHandle()</code> seems like a hack to me (and is not easily maintainable in case the code in question is transplanted into a different DLL).</p>
|
<p>Store the module handle away when it is given to you in DllMain and then use it later when you actually need it. A lot of frameworks (e.g., MFC) do this automatically.</p>
|
<p>As has been already stated this can be done by saving the module handle passed in to the DllMain function.</p>
<p>But there are other reasons why you should save the handle. </p>
<p>For example if you decide to bind resources to the DLL using the resource linker, you will need this module handle to get at these resources via the <strong>LoadResource</strong> function API.</p>
| 14,554
|
<p>FORTRAN provides several functions to convert a double precision number to an integral value. The method used for truncation/rounding differs. I am converting complex scientific algorithms which use these.</p>
<p>According to FORTRAN documentation:<br>
<b>aint(x)</b> returns the integral value between x and 0, nearest x.<br>
<b>anint(x)</b> returns the nearest integral value to x, except halfway cases are
rounded to the integral value larger in magnitude.<br>
<b>nint(x)</b> converts x into int format rounding to the nearest int value, except
halfway cases are rounded to the int value larger in magnitude.</p>
<p><b>Does anyone have an implementation of these in C#?</b>
It might be tricky getting it right.</p>
<p>(int)x appears to match aint()<br>
Convert.ToInt32(x) does not match any of the above.<br>
Trunc(x) does not match any of the above.<br>
Round(x) might match anint or nint. <br></p>
<p>The difference between anint and nint seems to be the return type, where anint returns a double precision value but nint returns an integer. Both are used (acutal sample):<br>
DOUBLE PRECISION A, B, C, D, E, F, G<br>
... values set here ...<br>
F = ANINT(A-B) + ANINT(C-D) + ANINT(B+D-E)<br>
G = NINT(F) + 1D0;<br>
Perhaps a FORTRAN expert could help clarify why the author chose to use both (I am assuming it was intentional).</p>
|
<p>From your definitions of the calls, <strong><code>nint</code></strong> and <strong><code>anint</code></strong> are provided by <code>Math.Round</code> using <code>MidpointRounding.AwayFromZero</code>.</p>
<p>For <strong><code>aint</code></strong>, an explicit cast from <code>double</code> to <code>int</code> will achieve that result.</p>
|
<p>I have an implementation of the function anint, follow the code:</p>
<pre><code>double anint(double x)
{
int a;
double y;
a = (int)x; //a=9
if (10 * x - 10 * (double)a >= 5)
{
a = a + 1;
}
y = (double)a;
return y;
}
</code></pre>
| 30,694
|
<p>Has anyone any reources for learning how to implement SVG with php/mysql (and possibly with php-gtk)? I am thinking of making a top-down garden designer, with drag and drop predefined elements (such as trees/bushes) and definable areas of planting (circles/squares). Gardeners could then track over time how well planting did in a certain area.</p>
<p>I don´t really want to get into flash... </p>
|
<p>You can also change the column name by using:</p>
<pre><code>myDataGrid.Columns[0].HeaderText = "My Header"
</code></pre>
<p>but the <code>myDataGrid</code> will need to have been bound to a <code>DataSource</code>.</p>
|
<p>Try this</p>
<pre><code>myDataGrid.Columns[0].HeaderText = "My Header"
myDataGrid.Bind() ;
</code></pre>
| 15,288
|
<p>Earlier versions of the Notes client would automatically turn a <em>sent</em> URL into a clickable link for the recipient (regardless of mail client) but with 6.5 (and presumably later) this no longer happens; that is, the URL is sent as plain text. The Notes UI allows it to be done via the Create->Hotspot->Link Hotspot menu but this gets tedious.</p>
<p>I'm looking for a way to create a Link Hotspot in LotusScript. My research to date leads me to believe that this isn't possible but there may be a hack of some kind.</p>
|
<p>The automatic conversion of urls into clickable links is a user preference.</p>
<p>In 6.5 it is set via File/Preferences/User Preferences/Basics. In 8 it is set via File/Prefences/Basic Notes Client Config.</p>
<p>I don't think you can create a url link hotspot explicitly using lotusscript. You can create a doc link, but there is no obvious way to turn it into a url link.</p>
<p>You could try an approach where the form is set to render passthrough html on the client and then construct the relevant html for a link.</p>
<p>Update in response to comment.</p>
<p>The scenario is that we want to to control what a user receiving mail sees. We have a few cases we should think about.</p>
<ol>
<li>The recipient is using Notes and received the mail directly via notes to notes routing.</li>
<li>The recipient is out on the internet using any client and allows email in a rich format.</li>
<li>The recipient is out on the internet using any client and only allows email in plain text.</li>
</ol>
<p>In the first case the user will see links if they turn on the option for that. You could also create pass-through html in the rich text and that will render on the Notes client assuming the form option is set in the design. If it's straight email and you don't really need any other rich Notes features you could also construct a MIME message.</p>
<p>In the next two cases you just want to send properly formatted MIME messages. In the first of those cases the user will accept rich formatting and therefore you can construct the message as simple html and include links that way. In the second case the user will not, and you have to make do with plain text. Luckily most mail clients will automatically turn urls received in plain text messages into links for you. This may be an option as in the Notes client.</p>
<p>It is best practice when sending rich mail content to also include a MIME section for plain text. That way you don't need to care what version the user prefers.</p>
|
<p>You need to cheat and create a MIME entry to get your links. Going that route you also can take the opportunity to make it look really nice. The sample code is on <a href="https://stackoverflow.com/questions/686384/sending-formatted-lotus-notes-rich-text-email-from-excel-vba" title="Sample Code">this site</a></p>
| 42,021
|
<p>I'm trying to resize dynamically a <code>CMFCPropertySheet</code> to add a custom control at the bottom of each page.</p>
<p>As all Property Pages are not of the same height, I have a mechanism to increase the size if necessary.
For this, I have overridden the <code>OnActivatePage</code> method and by using <code>SetWindowPos</code>, I can resize the sheet, first, then the tab control, then the page and finally I can move the OK/Cancel/Help buttons.</p>
<p>It works fine with <code>PropSheetLook_OutlookBar</code> and <code>PropSheetLook_Tabs</code> styles but not with <code>PropSheetLook_OneNoteTabs</code> style. The page (or the tab) is not correctly resized (the lighter grey color of the page does not fill the sheet.</p>
<p>OneNote style <a href="http://www.freeimagehosting.net/uploads/th.ec91600664.jpg" rel="nofollow noreferrer">OneNote http://www.freeimagehosting.net/uploads/th.ec91600664.jpg</a></p>
<p>Outlook style <a href="http://www.freeimagehosting.net/uploads/th.319b6938ab.jpg" rel="nofollow noreferrer">Outlook http://www.freeimagehosting.net/uploads/th.319b6938ab.jpg</a></p>
<p>Any idea? A MFC Feature Pack bug?</p>
|
<p>You can run the tests from the command-line, but it requires that the Test Edition of Visual Studio be installed on your build server:</p>
<p><a href="http://devlicio.us/blogs/derik_whittaker/archive/2008/09/25/clean-build-server-with-mstest-fail.aspx" rel="nofollow noreferrer"><a href="http://devlicio.us/blogs/derik_whittaker/archive/2008/09/25/clean-build-server-with-mstest-fail.aspx" rel="nofollow noreferrer">http://devlicio.us/blogs/derik_whittaker/archive/2008/09/25/clean-build-server-with-mstest-fail.aspx</a></a></p>
<p><a href="http://aspadvice.com/blogs/ssmith/archive/2008/03/18/Continuous-Integration-Setup-with-MSTest.aspx" rel="nofollow noreferrer"><a href="http://aspadvice.com/blogs/ssmith/archive/2008/03/18/Continuous-Integration-Setup-with-MSTest.aspx" rel="nofollow noreferrer">http://aspadvice.com/blogs/ssmith/archive/2008/03/18/Continuous-Integration-Setup-with-MSTest.aspx</a></a></p>
<p>This person is doing MSTest with CC.NET, so it might be helpful:</p>
<p><a href="http://testearly.findtechblogs.com/default.asp?item=630602" rel="nofollow noreferrer"><a href="http://testearly.findtechblogs.com/default.asp?item=630602" rel="nofollow noreferrer">http://testearly.findtechblogs.com/default.asp?item=630602</a></a></p>
<p>In general, this is a main reason why many people choose something like <a href="http://www.nunit.org" rel="nofollow noreferrer">NUnit</a>, <a href="http://www.codeplex.com/xunit" rel="nofollow noreferrer">xUnit.NET</a> or <a href="http://www.mbunit.com/" rel="nofollow noreferrer">MbUnit</a> over MSTest.</p>
|
<p>If you use MSTEST You will have to put that edition on the build server. To cut a long story short youd be better off changing the testing framework the developer is using from MStest to Nunit.
Its a much lighter solution.</p>
| 49,561
|
<p>I have used something like the following to compose policies for my application:</p>
<p>The policy classes look like this:</p>
<pre><code>struct Policy {
static void init();
static void cleanup();
//...
};
template <class CarT, class CdrT>
struct Cons {
static void init() {
CarT::init();
CdrT::init();
}
static void cleanup() {
CdrT::cleanup();
CarT::cleanup();
}
//...
};
</code></pre>
<p>To compose policies:</p>
<pre><code>typedef Cons<Policy1, Cons<Policy2, Cons<Policy3, Policy4> > > MyPolicy;
</code></pre>
<p>To use MyPolicy:</p>
<pre><code>init_with<MyPolicy>(...);
//...
cleanup_with<MyPolicy>(...);
</code></pre>
<p>where they'd call:</p>
<pre><code>MyPolicy::init_options(); // calls Policy1 to 4's init in order
</code></pre>
<p>and</p>
<pre><code>MyPolicy::cleanup(); // calls Policy1 to 4's cleanup in reverse order
</code></pre>
<p>Essentially, Cons constructs a type list here. It's pretty straight forward. However the typedef cons line is kinda ugly. It'll be ideal to have policy combiner that can do this:</p>
<pre><code>typedef CombinePolicy<Policy1, Policy2, Policy3, Policy4> MyPolicy;
</code></pre>
<p>Since we can have arbitrary number of policies, the CombinePolicy would need variadic template support in C++0x, which is only available experimentally in cutting edge compilers. However, it seems that boost:mpl library solved/worked around the problem by using a bunch preprocessing tricks. I <em>guess</em> I could use something like:</p>
<pre><code>typedef mpl::list<Policy, Policy2, Policy3, Policy4> Policies;
</code></pre>
<p>and then calls:</p>
<pre><code>init_with<Policies>(...);
</code></pre>
<p>which would then use:</p>
<pre><code>typedef iter_fold<Policies, begin<Policies>::type,
some_magic_lambda_expression>::type MyPolicy;
</code></pre>
<p>Obviously, I have a little trouble figuring out <em>some_magic_lambda_expression</em> here. I'm sure it's quite trivial for mpl experts here.</p>
<p>Thanks in advance.</p>
|
<p>Since no one answered the question satisfactorily, I spent sometime digging into the boost::mpl source. Man, it's not pretty with layers of macros and hundreds of lines of specialization classes. I now have more appreciation for the authors of the boost libraries to make meta programming easier and more portable for us. Hopefully C++0x will make library writers' life easier as well.</p>
<p>Anyway, the solution turns out to be simple and elegant.</p>
<p>First iter_fold is not what I want, as I couldn't figure out how to specify an iterator that can be deferenced to a null type. So I fiddled around with fold and find the following:</p>
<pre><code>typedef fold<Policies, Null, Cons<_1, _2> >::type MyPolicy;
</code></pre>
<p>In order for this to work, I need to provide the Null type and a specialization for Cons:</p>
<pre><code>struct Null { };
template<class PolicyT>
struct Cons<Null, PolicyT> {
static void init() { PolicyT::init(); }
static void cleanup() { PolicyT::cleanup(); }
};
</code></pre>
|
<p>I think your problem is rather runtime invocation than metafunctions, because you want to call the init functions on the actual runtime objects.</p>
<p>You could try the runtime algorithms of mpl,
like : </p>
<pre><code>for_each<Policies>(InitPolicy());
</code></pre>
<p>with </p>
<pre><code>struct InitPolicy() {
template<class Policy>
void operator() (Policy& p) { p.init_options(); }
};
</code></pre>
| 32,028
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.