instruction stringlengths 21 27.8k | chosen stringlengths 18 28.2k | rejected stringlengths 18 33.6k | __index_level_0__ int64 0 50k |
|---|---|---|---|
<p>I am having two separate issues. One is specific to this particular model, the other is on all my prints, but more pronounced on 90° vertical walls.</p>
<p>The first issue is a localized area of under extrusion only in one area of the print. This issue is specific to this model. The second issue is evenly spaced hor... | <p>The horizontal bands are 5mm apart, which is a common pitch for the screws often used for the Z axis.</p>
<p>I would look for something that binds, moves, slips, or touches once per screw revolution. The movement repeats along the screw, so if it is a screw defect I would look for a scratch or bump that affects the... | <p>Try setting the z-seam to <em>random</em> in your slicer. In Slic3r it is <em>Seam position</em> under <em>Advanced</em> near the bottom of the <em>Layer and perimeters</em> page of the <em>Print Settings</em>.</p>
| 2,068 |
<p>I'm using <a href="http://www.codeproject.com/KB/cs/lotusnoteintegrator.aspx" rel="nofollow noreferrer">Interop.Domino.dll</a> to retrieve E-mails from a Lotus "Database" (Term used loosely). I'm having some difficulty in retrieving certain fields and wonder how to do this properly. I've been using <code>NotesDocume... | <p>Hah, got it!</p>
<pre><code>Object[] ni = (Object[])nDoc.Items;
string names_values = "";
for (int x = 0; x < ni.Length; x++)
{
NotesItem item = (NotesItem)ni[x];
if (!string.IsNullOrEmpty(item.Name)) names_values += x.ToString() + ": " + item.Name + "\t\t" + item.Text + "\r\n";
}
</code></pre>
<p>This returned... | <p>It may not work depending on how your environment is set up, but the easiest way to deal with mail in domino is to leave them as MIME and get at the values via the NotesMIMEEntity and NotesMIMEHeader. This will only work if the mail came in from the web rather than native Notes and the environment has been set up t... | 39,419 |
<p>I'm looking to create a dashboard type gui for a web application. I'm looking for the user to be able to drag and drop different elements (probably either image buttons, anchor tags, or maybe just divs) to different (defined) places and be able to save their setup (in a cookie or on the server). I'm working with c... | <p>I have been looking at this kind of functionality myself recently and have decided on using jQuery with the help of <a href="http://ui.jquery.com/" rel="noreferrer">jQuery UI</a>. I came across a large amount of information that also suggested <a href="http://developer.yahoo.com/yui/" rel="noreferrer">Yahoo UI</a> (... | <p>I used the Microsoft ASP.Net Ajax and AjaxControlToolkit to do something like this. They have a ResizeableControl and a DragPanel. I used these, then hosted an IFrame inside the panel to display the content.</p>
<p>Worked pretty well.</p>
<hr>
<p>This site:</p>
<p><a href="http://www.asp.net/learn/videos/defau... | 3,694 |
<p>At work, we have a testing tool that is used to send queries to a data source. The tool takes in input as XML files. The XML files were simple and easy to parse as long as the data structures we tried to represent were one layer deep. But now these data structures are more complex and representing them in XML is get... | <p><a href="http://www.yaml.org" rel="nofollow noreferrer">YAML</a> may be what you're looking for.</p>
| <p>You might consider using Lua (or another scripting language). You get a nice data structure syntax (roughly on par with JSON), with the full power of a programming language. Thus you have variables (you can build up your data structures piece by piece, symbolically declare recurring values, etc.), loops (test data i... | 25,300 |
<p>I had recently purchased an ender 3 and after setting it up and plugging it in, I received an electrical shock from the power supply. I live in the UK and so I was provided an EU to UK adapter which I used and I set the voltage to 230 V.</p>
<p>Does anyone know why I was shocked and if there is any solution? W... | <p>You need to take particular care when using plug adaptors - they are not always made to a high standard, and it is possible that the earth connection is not present. If you suspect that the earth connection won't allow a 13 A fuse to blow, it would be good to destroy the adaptor.</p>
<p>A simple cable (without adap... | <p>Sorry for leaving this so late, I completely forgot about my account until I went through some old emails. In terms of the PSU shock issue, it was fixed through a replacement 13 A cable from an old monitor (so @Green Online and @Sean Houlihane's response worked best I think).</p>
| 1,023 |
<ol>
<li><p>Is it possible to 3D print multiple 0.1 mm high layers with a 0.4 mm diameter nozzle in FDM while ensuring fidelity to the set layer height? The raster width is set at 0.4 mm and I am not touching that. The part thickness is 3 mm, so 30 layers of 0.1 mm have to be deposited for the completion of the print j... | <ol>
<li><p>Yes, absolutely. I believe the original sample file that came with the Ender 3 (0.4 mm nozzle) was sliced for 0.1 mm layer height. As long as your printer can get decently precise Z positioning at 0.1 mm increments, it should be able to do it.</p>
</li>
<li><p>I've never used smaller nozzles but they pose c... | <p>The <a href="https://blog.prusaprinters.org/everything-about-nozzles-with-a-different-diameter_8344/" rel="nofollow noreferrer">general consensus for nozzle diameter versus layer height</a> is to limit the layer thickness to eighty percent of the nozzle diameter. For a 0.4 mm nozzle, one usually limits the layer to ... | 2,118 |
<p>I am trying to change the rows output by PHP in a table to links. I have added the a href tags to the example below, however it results in an unexpected <code>T_VARIABLE</code>. I have tried it without the extra quotes, but this displays a blank table. I am not sure what the flaw in the logic is.</p>
<pre><code>whi... | <p><a href="http://www.faqs.org/rfcs/rfc1867.html" rel="noreferrer">http://www.faqs.org/rfcs/rfc1867.html</a></p>
<p><em>HTTP clients are
encouraged to supply content-length for overall file input so that a
busy server could detect if the proposed file data is too large to be
processed reasonably</em></p>
<p... | <ol>
<li><p>I'm not sure, but you should not really trust anything sent in the header, as it could be faked by the user.</p></li>
<li><p>It depends on how the server works. For example in PHP your script will not run until the file upload is complete, so this wouldn't be possible.</p></li>
</ol>
| 35,499 |
<p>I have a new database table I need to create...<br>
It logically contains an <code>ID</code>, a <code>name</code>, and a <code>"value"</code>.<br>
That value field could be either numeric or a character string in nature. </p>
<p>I don't think I want to just make the field a <code>varchar</code>, because I also wan... | <p>Your issue with mixing data may be how Sql 2005 sorts text data. It's not a 'natural' sort.</p>
<p>If you have a varchar field and you do:</p>
<pre><code>where value > '20.5'
</code></pre>
<p>Values like "5" will be in your result (as in a character based sort "5" comes after "20.5")</p>
<p>You're going to be... | <p>If you want to store numeric and string values in the same column, I am not sure you can avoid doing a lot of casts and converts when using that column as a query filter. </p>
| 5,462 |
<p>To my amazement I just discovered that the C99 stdint.h is missing from MS Visual Studio 2003 upwards. I'm sure they have their reasons, but does anyone know where I can download a copy? Without this header I have no definitions for useful types such as uint32_t, etc.</p>
| <p>Turns out you can download a MS version of this header from:</p>
<p><a href="https://github.com/mattn/gntp-send/blob/master/include/msinttypes/stdint.h" rel="nofollow noreferrer">https://github.com/mattn/gntp-send/blob/master/include/msinttypes/stdint.h</a></p>
<p>A portable one can be found here:</p>
<p><a href="ht... | <p>Another portable solution:</p>
<p>POSH: The Portable Open Source Harness </p>
<p>"POSH is a simple, portable, easy-to-use, easy-to-integrate, flexible, open source "harness" designed to make writing cross-platform libraries and applications significantly less tedious to create and port."</p>
<p><a href="http://po... | 15,359 |
<p>I want to create a file on the webserver dynamically in PHP.</p>
<p>First I create a directory to store the file. THIS WORKS</p>
<pre><code>// create the users directory and index page
$dirToCreate = "..".$_SESSION['s_USER_URL'];
mkdir($dirToCreate, 0777, TRUE); // create the directory for the user
</code></pre>
... | <p>First you do :</p>
<pre><code>$dirToCreate = "..".$_SESSION['s_USER_URL'];
</code></pre>
<p>But the filename you try to write to is not prefixed with the '..', so try changing</p>
<pre><code>$ourFileName = $_SESSION['s_USER_URL']."/"."index.php";
</code></pre>
<p>to</p>
<pre><code>$ourFileName = '..' . $_SESSI... | <p>It could be a result of one of your php ini settings, or possibly an apache security setting. </p>
<p>Try creating the dir as only rwxr-x--- and see how that goes. </p>
<p>I recall a shared hosting setup where "safemode" was compiled in and this behaviour tended to occur, basically, if the files/dirs were writa... | 36,315 |
<p>We have some SQL server reporting services reports. I didn't write then but I have to take care of them.</p>
<p>These reports fire when opened in the browser, and with the default parameters (search terms and restrictions are blank) they retrieve a lot of data, which is slow. The client would prefer that the report... | <p>I found that I had to set at least one of the report parameters to not have a default to keep the report from autorunning.</p>
<p>I had to use this configuration (notice that all 3 of the parameters I left without defaults accept Nulls so the users can just click the Null checkboxes):</p>
<p>[screenshots missing]<... | <p>I added this in my query:</p>
<blockquote>
<p>where 'Start' = @Start</p>
</blockquote>
<p>and made a parameter with only available value 'Start'. The report is waiting for input.</p>
| 35,048 |
<p>I have a Windows Forms (.NET) application that can have multiple documents open simultaneously.</p>
<p>It would be convenient to have each document (form) running its own event loop. With brief experimentation, starting several event loops in their own STA threads seems to work. Is there any reason why this is a ba... | <p>I think it's perfectly fine do create multiple message loops on different threads. The only thing to watch out for is when dealing with 3rd party UI toolkits, they sometimes store handles as static (instead of ThreadStatic) members and if you have multiple UI threads in your application, it will have problems (in m... | <p>Just be careful with accessing the GUI elements from the threads.</p>
| 30,873 |
<p>I was recently diagnosed with a cascading dissociative disorder that causes retrograde amnesia in addition to an existing case of possible anterograde amnesia. Many people have tried to remind me of how great a programmer I was before -- Right now I get the concepts and the idioms, but I want to teach myself whether... | <p><a href="http://www.haskell.org/" rel="nofollow noreferrer">Haskell</a> currently has a large following and a growing base of <a href="http://hackage.haskell.org/packages/hackage.html" rel="nofollow noreferrer">libraries and applications</a>. It's also used for education and research. I find it a very nice language ... | <p>I have no personal experience with Clojure, but i really recommend <a href="http://msdn.microsoft.com/en-us/fsharp/default.aspx" rel="nofollow noreferrer">F#</a>. It's quite a powerful language in the style of <a href="http://en.wikipedia.org/wiki/OCaml" rel="nofollow noreferrer">OCaml</a>. I really like it because ... | 36,101 |
<p>I have two insert statements, almost exactly the same, which run in two different schemas on the same Oracle instance. What the insert statement looks like doesn't matter - I'm looking for a troubleshooting strategy here.</p>
<p>Both schemas have 99% the same structure. A few columns have slightly different names, ... | <p>Use the <a href="http://docs.oracle.com/cd/B19306_01/server.102/b14211/sqltrace.htm#g33356" rel="nofollow noreferrer">SQL Trace facility and TKPROF</a>.</p>
| <p><strong><em>analyzing the oI also highly recommend the book Optimizing Oracle Performance, which discusses similar tools for tracing execution and utput.</em></strong></p>
| 12,962 |
<p>I'm working on a VB6 application and I would like to send a Type as a reference and store it in another form. Is this possible?</p>
<p>Sending it is no problem, I just use the <code>ByRef</code> keyword:</p>
<pre><code>public Sub SetStopToEdit(ByRef currentStop As StopType)
</code></pre>
<p>But when I try to use ... | <p>You need to refactor it into a class.</p>
| <p>The confusion here is that a StopType is not a reference like an object, but behaves more like an in built type such as LONG. When you do:</p>
<p>stopToEdit = currentStop</p>
<p>You are only taking a copy of currentStop. If you subsequently change stopToEdit, you'll need to copy it back:</p>
<p>currentStop = stop... | 15,414 |
<p>Windows has a feature that allows an administrator to perform auto-logon whenever it is started. How can this feature be activated?</p>
| <p>Based on the advice, moved the answer to the answers section:</p>
<p>There are tools out there that give you a GUI for setting this easily, but you can also do it relatively easily by editing the registry.</p>
<p>Under the following registry key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winl... | <p>If you don't want to store the clear-text password in the registry, use this method:</p>
<ul>
<li>Start -> Run</li>
<li>enter "control userpasswords2"</li>
<li>disable checkbox "Users must enter a user name and password to use this computer"</li>
<li>click "OK"</li>
<li>enter a valid user name and password that is ... | 6,109 |
<p>Does anybody have useful example of <code>this</code> assignment inside a C# method? I have been asked for it once during job interview, and I am still interested in answer myself. </p>
| <p>The other answers are incorrect when they say you cannot assign to 'this'. True, you can't for a class type, but you <em>can</em> for a struct type:</p>
<pre><code>public struct MyValueType
{
public int Id;
public void Swap(ref MyValueType other)
{
MyValueType temp = this;
this = other;... | <p>You cannot overwrite "this". It points to the current object instance.</p>
| 9,524 |
<p>Is there any good way to convert strings like "xlSum", "xlAverage", and "xlCount" into the value they have under Microsoft.Office.Interop.Excel.XlConsolidationFunction?</p>
<p>I guess reflection would be slow (if its possible). There are about 10 of these constant values. I was trying to avoid a large switch statem... | <p>This is an enum so you should be able to use</p>
<pre><code>using Microsoft.Office.Interop.Excel;
XlConslidationFunction func = (XlConsolidationFunction)
Enum.Parse( typeof(XlConsolidationFunction),
stringVal );
</code></pre>
| <p>Instead of switch you can always use a <code>Dictionary<string, ...></code> and fill it once when the application starts</p>
| 40,754 |
<p>I am trying to run xcopy that copies files excluding .obj, etc.
What I am seeing is that Microsoft.Practices.ObjectBuilder.dll is not copied when my excludes.txt file contains .obj as an extension. When .obj is removed, I Microsoft.Practices.ObjectBuilder.dll is copied correctly. This does not happen to other dlls t... | <p>I guess because the substring .obj is found in the name Microsoft.Practices**.Obj**ectBuilder.dll and since windows is not case sensitive, it will exclude it.</p>
| <p>The answer is what you could obtain by typing:</p>
<pre><code>xcopy /?
</code></pre>
<p>Namely:</p>
<blockquote>
<p>/EXCLUDE:file1[+file2][+file3]...<br>
Specifies a list of files containing strings. Each string
should be in a separate line in the files. When any of the
... | 24,133 |
<p>I would like to have all developers on my team to use the same rules for formatting several types of code (ASPX, CSS, JavaScript, C#). Can I have visual studio look to a common place for these rules?</p>
<p>I would like to not rely on export/import settings as that brings many settings along. I (for example) don'... | <p><a href="http://stylecop.codeplex.com/" rel="nofollow noreferrer">StyleCop</a>, originally called <a href="http://code.msdn.microsoft.com/sourceanalysis" rel="nofollow noreferrer">"Source Analysis"</a> is the best choice for C#. The first version was rather inflexible, but after recognizing the value that it provid... | <p><strong>Code Review.</strong></p>
| 6,082 |
<p>in windows I am able to use winmerge as the external diff tool for hg using <i>mercurial.ini</i>,etc.
<br>
Using some options switch that you can find in web(I think it's a japanese website)
Anyway, here
for example:</p>
<pre>hg winmerge -r1 -r2</pre>
<p>will list file(s) change(s) between rev1 and rev2 in winme... | <p>Beyond-Compare-3 is an amazing tool.
I recommend a few tweaks to the setup:</p>
<pre><code>[extensions]
extdiff =
[extdiff]
cmd.bcomp = C:\Program Files\Beyond Compare 3\BCompare.exe
opts.bcomp = /leftreadonly
[merge-tools]
bcomp.executable = C:\Program Files\Beyond Compare 3\BComp
bcomp.args = /leftreadonly /cen... | <p>If you are having trouble getting your configuration to parse correctly please note that any space for any variable or section name will cause the configuration to parse incorrectly. I kept copying and pasting different configures and continued to get errors. It just ended up that spaces were added before many of th... | 41,879 |
<p>I need a combobox in an Windows MFC application that has a search feature. It should work so that if you start typing something that matches one or more items in the list, the combobox should drop-down and display those items. Kinda like popular ajax-based search boxes on the web</p>
<p>Do you
- know of any control... | <p>Provide a handler for the <code>CBN_EDITCHANGE</code> event, your handler willö be called every time the user changes the text in the edit field.</p>
<p>In this Handler, call the <code>CComboBox::FindString()</code> method to see if the typed text exists in any of your combobox entries. If it does, call <code>CComb... | <p>It's a Win32 api FAQ.
See Adv. Win32 api ng news://194.177.96.26/comp.os.ms-windows.programmer.win32
(you don't need at all CBN_EDITCHANGE. It's automatic with api)</p>
| 44,702 |
<p>I've searched around a bit in the small amount of iPhone/iPod Touch development information available and couldn't find anything for or against. Can an application find out information about currently playing song on iPhone/iPod Touch? Since the music can continue to play while you are in 3rd party applications, i... | <p>This is static scoping. Statements within a function are scoped within that function.</p>
<p>Javascript has a quirky behavior, however, which is that without the <strong>var</strong> keyword, you've implied a <strong>global variable</strong>. That's what you're seeing in your test. Your "d" variable is ... | <p>...</p>
<pre><code>function a() {
function b() {
alert('boo')
}
var c = 'Bound to local call object.'
d = 'Bound to global object.'
}
</code></pre>
<p>without being preceded by <em>var</em>, d is global. Do this to made d private:</p>
<pre><code>function a() {
function b() {
alert('boo'... | 29,133 |
<p>About a half dozen times now, I’ve been doing a regular chore in Visual Studio – either running a unit test or simply compiling, updating something from SVN or whatever, and visual studio just disappears… it shuts down and goes away instantly… it is fine when I restart it, and I don’t see the problem again for a whi... | <p>All of the devs on my team see this problem quite often. It isn't AnkhSVN because we don't use it. I believe it is C++ intellisense, but that is just a feeling. Sometimes it happens when we are not doing anything. We will go for coffee, come back and it is just gone.</p>
<p>It never happens to me on smaller project... | <p>Definitely an addin. I experienced a similar issue, but it would bluescreen my machine. After uninstalling the plugin( it was SlickEdit Gadgets), I never experienced the issue again. Try uninstalling plugins. Or updating ankhSVN. </p>
| 38,838 |
<p>I'm working on an embedded processor (400 MHz Intel PXA255 XScale), and I thought I saw one case where there wasn't enough memory to satisfy a 'new' operation. The program didn't crash, so I assumed other threads had freed their memory and it was just a transient thing. This is some pretty critical code, so exiting... | <p>You are trying to solve a global problem through local reasoning. The global problem is that the entire device has a limited amount of RAM (and possibly backing store) for the operating system and all of the applications. To make sure this amount of RAM is not exceeded, you have a few options:</p>
<ul>
<li><p>Eac... | <p>Surely it would depend on whether you have a reasonable expectation of memory becoming available in the 100 (millisecond?) sleep? Certainly, you should limit the number of times it attempts.</p>
<p>To me something doesn't smell right here. Hmmm...</p>
<p>Embedded systems typically need to be extremely determinis... | 47,942 |
<p>So I have action_mailer_optional_tls (<a href="http://svn.douglasfshearer.com/rails/plugins/action_mailer_optional_tls" rel="nofollow noreferrer">http://svn.douglasfshearer.com/rails/plugins/action_mailer_optional_tls</a>)
and this in my enviroment.rb</p>
<pre><code>ActionMailer::Base.server_settings = {
:tls =&g... | <p>I can't verify that this works right now, but you should try just modifying these settings on the fly. i.e. set the username / password from the users account right before sending an email. You could even setup a before filter on your controller to load that info.</p>
<pre><code>before_filter :load_email_setting... | <p>If you want to use a different email address for the replies from the target receivers,
you could specify Reply-To: otheremail@example.com for the SMTP protocol and still using the existing account of google smtp service.</p>
<p>However you need to go to Gmail settings to add otheremail@example.com to the list of ... | 30,006 |
<p>I have a class which has a private member <code>$content</code>. This is wrapped by a get-method:</p>
<pre><code>class ContentHolder
{
private $content;
public function __construct()
{
$this->content = "";
}
public function getContent()
{
return $this->content;
}
}... | <p>I just tried your code and <code>$foo['c']</code> is not a reference to <code>$content</code>. (Assigning a new value to <code>$foo['c']</code> does not affect <code>$content</code>.)</p>
<p>By default all PHP functions/methods pass arguments by value and return by value. To return by reference you would need to us... | <p>In PHP, you don't say: "<code>$foo = new array();</code>"
Instead, you simply say: "<code>$foo = array();</code>"</p>
<p>I ran your code (PHP 5.2.6) and it seems to work fine. I tested it by dumping the array:</p>
<pre><code>var_dump($foo);
</code></pre>
<p>This outputs:</p>
<pre><code>array(1) {
["c"]=>
... | 38,497 |
<p>Am I the only person who has the need to view multiple directories at once (usually on the same remote server, but sometimes other ones too)? Disconnecting and reconnecting is driving me crazy.</p>
<p>Preferably a free tool, but I'm getting to the stage where I'll try anything!</p>
<p>Can you have multiple FireFTP... | <p><strong>FireFTP</strong> in Firefox does the job nicely. I've been using it about 2 hours and it's fast on the way to consigning FileZilla to the bin!</p>
| <p><a href="http://filezilla-project.org/" rel="nofollow noreferrer">FileZilla</a>
is my favourite FTP client.</p>
| 13,582 |
<p>I just assembled Ender 3 and noticed that the X-axis movement doesn't correspond to the commands. When I make it move 1 mm with the encoder it moves 16 mm. Everything is in the "out of the box" configuration.</p>
<p>The current steps/mm for the X-axis read (from the display) 80 steps/mm.</p>
<p>Am I suppos... | <p>Direct Drive v.s. Bowden has no relation to the maximum print temperature. What determines the maximum print temperature is the design of the hotend itself. There are "all-metal" designs, where the PTFE tube (Bowden or not) stops in the cold zone and the heatbreak and all other components that get hot are ... | <p>Bowden tubes extending to the nozzle to make a seal will damage the Teflon (PTFE) tube if exceeding 250°C for an extended time. An all-metal hotend for a Bowden would have either the nozzle sealed against the heatbreak or an integrated nozzle and heatbreak. Then the Bowden tube would attach with a minimum gape wi... | 1,960 |
<p>Here is the scenario. 2 web servers in two separate locations having two mysql databases with identical tables. The data within the tables is also expected to be identical in real time. </p>
<p>Here is the problem. if a user in either location simultaneously enters a new record into identical tables, as illustrated... | <p>There isn't much performance to be gained from replicating your database on two masters. However, there is a nifty bit of failover if you code your application correct.</p>
<p>Master-Master setup is essentially the same as the Slave-Master setup but has both Slaves started and an important change to your config fil... | <p>The only way to ensure your tables are synchronized is to setup a 2-ways replication between databases.</p>
<p>But, MySQL only permits one-way replication, so you can't simply resolve your problem in this configuration.</p>
<p>To be clear, you can "setup" a 2-ways replication but MySQL AB <a href="http://dev.mysq... | 42,201 |
<p>I need to compare the integer part of two doubles for inequality and I'm currently doing this:</p>
<pre><code>int iA = (int)dA;
int iB = (int)dB;
if( iA != iB )
{
...
}
</code></pre>
<p>but I wonder if there's a better approach than this.</p>
<p>Thanks.</p>
<p>If I used Math.Truncate() instead of a cast to ... | <p>Use Math.Truncate() i.e. </p>
<pre><code>if (Math.Truncate(x) == Math.Truncate(y))
</code></pre>
<p>[Edit] Realized that if you are comparing integer parts of doubles, casting to int values first runs the risk of overflows should your doubles be outside the range that could be represented as int.</p>
<p>Truncate ... | <p>Personally, I try to avoid creating extra variables unless I need them.</p>
<pre><code>if ( (int)dA != (int)dB ) {
...
}
</code></pre>
<p>As code evolves over time, having extra variables hanging around for no purpose leads to confusion. Of course, if you need those variables, that's another issue :)</p>
<p>... | 29,245 |
<p>We have a set of applications that basically display a bunch of bitmaps and text, then allow user to press "buttons" (certain bitmaps) that cause actions to occur.</p>
<p>We currently have these implemented using DirectX and a bunch of code to place the bitmaps and handle the button-presses. But we'd like to have ... | <p>Maybe the way to go is something like <a href="http://clutter-project.org/" rel="nofollow noreferrer">Clutter</a> or <a href="http://www.allegro.cc/" rel="nofollow noreferrer">Allegro</a>. If you check in this <a href="http://arstechnica.com/news.ars/post/20080604-hands-on-with-the-ubuntu-netbook-remix.html" rel="no... | <p>You could try <a href="http://www.wxwidgets.org/" rel="nofollow noreferrer">wxWidgets</a> (it has wxBitmapButton) or try to implement your own solution using <a href="http://www.libsdl.org/" rel="nofollow noreferrer">SDL</a> for all of the graphics.</p>
| 4,393 |
<p>I have two system calls GetSystemTime() and GetThreadTimes() that I need to calculate the CPU utilization by a given Win32 thread.</p>
<p>For the sake of accuracy, I need to ensure that both GetSystemTime() and GetThreadTimes() are executed atomically; i.e. there should be no context switch in between a call to Get... | <p>Your best bet would be assigning computing thread a realtime priority. Realtime threads only get preempted by other realtime threads (or ones boosted to realtime priority).</p>
| <p>Sadly there is no way. In between two system calls in Win32 there is no way to prevent your process/thread from being context switched out. Otherwise it would be trivial for someone to implement a process that locked down the system by refusing to every get switched out. </p>
| 36,704 |
<p>What are current practices for enabling developers to build systems that contain private data? Can anyone point to a "best practices" guide for that sort of thing?</p>
<p>We have a Catch-22 here in that developers need to write applications that go against systems that have data that is considered "private." The IT... | <p>My view of the world may be different, as I'm based in the UK, but for the past 20-odd years, I've worked primarily in the public sector on systems handling sensitive data.
The rules are **completely** cut-and-dried. No production data is allowed on the development estate.</p>
<p>As a fundamental principle, we do n... | <p>I don't have any best practices paper or anything. But I would think that if you're developing out of an environment that is <em>as protected</em> as the environment that hosts the data in production, there wouldn't be a lot of argument to be made against it.</p>
<p>That is, if your production database is in a dat... | 10,180 |
<p>How would you go about retrieving the @@IDENTITY value for each row when the SQLDataAdapater.Update is executed on a table?</p>
<p>eg. Is it possible to modify/intercept the InsertCommand, generated by the SQLCommandBuilder, to say add an output parameter, and then retrieve its value in the da.RowUpdated event???</... | <p>I found the answer to this today when converting my own database from SQL 2005 to SQL 2008.</p>
<p>Pass <code>""</code> for your search term and change the @search_term = <code>''</code> test to be <code>@search_term = '""'</code>
SQL server will ignore the double quotes and not throw an error.</p>
<p>For example,... | <p>I found that using "a" as the default works if SQL-Server is <a href="https://learn.microsoft.com/en-us/sql/database-engine/configure-windows/transform-noise-words-server-configuration-option?view=sql-server-ver15" rel="nofollow noreferrer">configured to ignore "noise words".</a></p>
<pre><code>S... | 23,020 |
<p>I am aware of the responses at
<a href="https://stackoverflow.com/questions/49002/prefer-composition-over-inheritance">Prefer composition over inheritance</a>
and am aware of the merits of composition over inheritance.</p>
<p>But there are cases where inheritance does have a good role to play. It's the incorrect... | <p><em>Preferring</em> composition isn't the same as mandating it in every situation. To add to your UI example, I'd say that both Java and .NET benefit from using an inheritance hierarchy for streams.</p>
<p>I suggest you have a look at the inheritance tree for Windows Presentation Foundation though - that's a relati... | <p>when all the tasks are in same roles ,inherience is more better .</p>
| 47,464 |
<p>I created a Rails application normally. Then created the scaffold for an event class. Then tried the following code. When run it complains about a InvalidAuthenticityToken when the destroy method is executed. How do I authenticate to avoid this response?</p>
<pre><code>require 'rubygems'
require 'activeresource'
c... | <p>So I'm not sure <a href="https://stackoverflow.com/a/150763">Matt Rogish's answer</a> is going to help 100%.</p>
<p>The problem is that MySQL* has a mutex (mutually exclusive lock) around opening and closing tables, so that basically means that if a table is in the process of being closed/deleted, <em>no</em> other... | <p>By default, all innodb databases in a given mysql server installation use the same physical pool of data files, so conceivably "drop database A" could affect database B. Since "drop database" is likely to involve heavy reorgainsing of the innodb data files, it's conceivable that it's a blocking operation, either b... | 18,085 |
<p>Title is the entire question. Can someone give me a reason why this happens?</p>
| <p>Yes - because it does begin with the empty string. Indeed, the empty string logically occurs between every pair of characters.</p>
<p>Put it this way: what definition of "starts with" could you give that would preclude this? Here's a simple definition of "starts with" that doesn't:</p>
<p>"x starts with y if the f... | <p>Because a string begins well with "nothing".</p>
| 17,544 |
<p>I want to load a desktop application, via reflection, as a Control inside another application.</p>
<p>The application I'm reflecting is a legacy one - I can't make changes to it.</p>
<p>I can dynamically access the Form, but can't load it as a Control.</p>
<p>In .Net Form expands on Control, and I can assign the ... | <p>Yes, this works just fine. I'm working on a .NET app right now that loads forms into a panel on a host form.</p>
<p>The relevant snippet:</p>
<pre><code>// setup the new form
form.TopLevel = false;
form.FormBorderStyle = FormBorderStyle.None;
form.Dock = DockStyle.Fill;
form.Show ( );
// add to the panel's list o... | <p>You should be able to add the form to the controls collection of your parent form...</p>
<p>See here:
<a href="http://vbcity.com/forums/topic.asp?tid=30539" rel="nofollow noreferrer"><a href="http://vbcity.com/forums/topic.asp?tid=30539" rel="nofollow noreferrer">http://vbcity.com/forums/topic.asp?tid=30539</a></a... | 7,445 |
<p>The question is pretty self-explanatory. I'm looking for a PostgreSQL equivalent to the <a href="http://www.sqlite.org/cvstrac/wiki?p=DateAndTimeFunctions" rel="nofollow noreferrer">SQLite datetime function</a>.</p>
| <pre><code>postgres=# select to_char(now(),'YYYY-mm-dd HH:MM:ss');
to_char
---------------------
2008-09-24 02:09:20
(1 row)
postgres=# select to_char(now(),'YYYY-mm-dd HH24:MM:ss');
to_char
---------------------
2008-09-24 14:09:20
(1 row)
</code></pre>
| <p>I think this is what your're searching for:</p>
<p>timestamp [ (p) ] [ without time zone ]
or
timestamp [ (p) ] with time zone</p>
<p>otherwise have a look @
<a href="http://www.postgresql.org/docs/8.1/interactive/datatype-datetime.html" rel="nofollow noreferrer">http://www.postgresql.org/docs/8.1/interactive/d... | 15,441 |
<p>I use .NET XML technologies quite extensively on my work. One of the things the I like very much is the XSLT engine, more precisely the extensibility of it. However there one little piece which keeps being a source of annoyance. Nothing major or something we can't live with but it is preventing us from producing the... | <p>Use this code:</p>
<pre class="lang-cs prettyprint-override"><code>using (var writer = XmlWriter.Create("file.xml"))
{
const string Ns = "http://bladibla";
const string Prefix = "abx";
writer.WriteStartDocument();
writer.WriteStartElement("root");
// set root namespace
writer.WriteAttri... | <p>I'm not sure this is what you're looking for, but you can use this kind of code when you start writing to the Xml stream:</p>
<pre><code>myWriter.WriteAttributeString("xmlns", "abx", null, "http://bladibla");
</code></pre>
<p>The XmlWriter should remember it and not rewrite it anymore. It may not be 100% bulletpro... | 4,631 |
<p>Does anyone know whether the iPhone supports or will soon support the <a href="http://dev.w3.org/geo/api/spec-source.html" rel="noreferrer">W3C Geolocation specification</a>?</p>
<p>I'm looking to build an app for mobile users, but rather than spend the time developing apps for every different platform (iPhone, And... | <p>This code worked for me -- on the iPhone web browser <strong>Safari</strong> <em>and</em> as an added bonus it even worked with <strong>FireFox 3.5</strong> on my laptop! The Geolocation API Specification is part of the W3 Consortium’s standards <strong>But be warned: it hasn’t been finalized as yet.</strong></p>
<... | <p>Currently, it's not possible to obtain an iPhone's GPS position using just JavaScript APIs. There's been talk that this would be nice, but of course Apple won't comment on future improvements in public.</p>
| 27,320 |
<p>I'm trying to create a WPF application where I can drag an image around.</p>
<p>Currently I have an image placed in the center of the window, and I'm thinking of using the three mouseevents MouseDown, MouseMove and MouseUp to calculate the new position when dragging the image.</p>
<p>Are there any other good ideas... | <p>ok, here's an attached property "behaviour" that you can use to make any element draggable provided it's on a canvas:</p>
<pre><code>public class DraggableExtender : DependencyObject
{
// This is the dependency property we're exposing - we'll
// access this as DraggableExtender.CanDrag="true"/"false"
p... | <p>The solution that deepcode.co.uk provided is ok; however, I missed some functonalities when imlementing it, therefore I'm expanding on his solution.</p>
<p>When there are 2 or more elements within the canvas, it is necessary to also set:</p>
<pre><code> private void Element_PreviewMouseDown(object sender, Mouse... | 37,557 |
<p>I know that you cannot return anonymous types from methods but I am wondering how the Select extension method returns an anonymous type. Is it just a compiler trick?</p>
<p>Edit</p>
<p>Suppose L is a List. How does this work?</p>
<pre><code>L.Select(s => new { Name = s })
</code></pre>
<p>The return type is I... | <p>The type is actually defined by <em>the caller</em>, so it's in the scope of the calling function - neatly avoiding the issue of "returning" an anonymous type.</p>
<p>This is accomplished by generic type inference. The signature for <a href="http://msdn.microsoft.com/en-us/library/bb548891.aspx" rel="noreferrer">Se... | <p>The return type of Select is generic, and it is inferred from the lambda provided in most situations.</p>
<p>For example:</p>
<pre><code>List<int> list = new List<int<();
var val = list.Select(x => new {value = x, mod = x % 10});
</code></pre>
<p>The return value of the select is based on the anon... | 42,339 |
<p>I'm a big fan of <a href="http://www.simpletest.org/" rel="noreferrer">simpletest</a> because it's what I know. It has excellent support for mocking and web-testing. </p>
<p>But I'm always scared of stagnating so any compelling arguments to switch would be appreciated.</p>
| <p>I don't think either is going away anytime soon. Simpletest is maintained by a small, but involved group of people.</p>
<p>PHPUnit seems to have a bigger userbase, which may count as an argument for switching. I'm quite happy with Simpletest though.</p>
| <p>I just answered <a href="https://stackoverflow.com/questions/282150/how-do-i-write-unit-tests-in-php">a similar question</a> and added that there's <a href="http://qa.php.net/write-test.php" rel="nofollow noreferrer">phpt</a>. phpt also integrates into PHPUnit.</p>
| 35,340 |
<p>I've got some (C#) code that relies on today's date to correctly calculate things in the future. If I use today's date in the testing, I have to repeat the calculation in the test, which doesn't feel right. What's the best way to set the date to a known value within the test so that I can test that the result is a k... | <p>My preference is to have classes that use time actually rely on an interface, such as</p>
<pre><code>interface IClock
{
DateTime Now { get; }
}
</code></pre>
<p>With a concrete implementation</p>
<pre><code>class SystemClock: IClock
{
DateTime Now { get { return DateTime.Now; } }
}
</code></pre>
<p>The... | <p>Have you considered using conditional compilation to control what happens during debug/deployment?</p>
<p>e.g.</p>
<pre><code>DateTime date;
#if DEBUG
date = new DateTime(2008, 09, 04);
#else
date = DateTime.Now;
#endif
</code></pre>
<p>Failing that, you want to expose the property so you can manipulate it, this... | 6,528 |
<p>If I open a file using urllib2, like so:</p>
<pre><code>remotefile = urllib2.urlopen('http://example.com/somefile.zip')
</code></pre>
<p>Is there an easy way to get the file name other then parsing the original URL?</p>
<p>EDIT: changed openfile to urlopen... not sure how that happened.</p>
<p>EDIT2: I ended up ... | <p>Did you mean <a href="http://www.python.org/doc/2.5.2/lib/module-urllib2.html#l2h-3928" rel="noreferrer">urllib2.urlopen</a>?</p>
<p>You could potentially lift the <em>intended</em> filename <em>if</em> the server was sending a Content-Disposition header by checking <code>remotefile.info()['Content-Disposition']</c... | <pre><code>import os,urllib2
resp = urllib2.urlopen('http://www.example.com/index.html')
my_url = resp.geturl()
os.path.split(my_url)[1]
# 'index.html'
</code></pre>
<p>This is not openfile, but maybe still helps :)</p>
| 19,715 |
<p>What's the best way to asynchronously load an BitmapImage in C# using WPF? </p>
| <p>I was just looking into this and had to throw in my two cents, though a few years after the original post (just in case any one else comes looking for this same thing I was looking into). </p>
<p>I have an <strong>Image</strong> control that needs to have it's image loaded in the background using a <strong>Stream</... | <p>Use or extend System.ComponentModel.BackgroundWorker:<br>
<a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx</a></p>
<p>Personally, I find this to be the easiest w... | 5,736 |
<p>I'm at a location where I don't have easy access to toothed belts for my printer (a <a href="https://reprap.org/wiki/Wallace" rel="nofollow noreferrer">RepRap Wallace</a>). While trying to look for some solution, I saw some talk of using fishing line as a belt, along with a log of admonitions of <code>Don't</code>.<... | <p>I’m going to recommend not using a fishing line with knots. Probably the biggest problem you’ll have using the fishing line with knots is if the knots are not perfectly spaced, movement along the X or Y axis is not going to be consistent. This could result in weird deformations in your print.</p>
<p>Depending on ... | <p>If you are using fishing line, it would perhaps work to wrap the line around the pully and fastening it to the pully (both ends), so that the line wraps around the pully. One side would play out from the pully while the other was wrapping around it.</p>
<p>By attaching the ends of the line to the pully, there will... | 1,071 |
<p>I am performing a find and replace on the line feed character (<code>&#10;</code>) and replacing it with the paragraph close and paragraph open tags using the following code:</p>
<pre><code><xsl:template match="/STORIES/STORY">
<component>
<xsl:if test="boolean(ARTICLEBODY)">
... | <p><code>disable-output-escaping</code> isn't evil in itself, but there are only few cases where you should use it and this isn't one of them. In XSLT you work with trees, not markup string. Here's an XSTL 1.0 solution:</p>
<pre><code><xsl:template match="/STORIES/STORY">
<component>
<xsl:if test=... | <p>Given the XPath functions that you're calling which I don't remember having the luxury of in my MSXSL work, it looks like you're using an XPath 2-compatible processor. </p>
<p>If that's the case, doesn't XPath 2 have a replace(string, pattern, replacement) function that takes a regex as a second parameter? </p>
<... | 5,130 |
<p>I have an aspx page which will upload images to server harddisk from client pc</p>
<p>But now i need to change my program in such a way that it would allow me to resize the image while uploading.</p>
<p>Does anyone has any idea on this ? I couldnt not find such properties/methods with Input file server control</p>... | <p>Once the file has been saved to the server you can use code like this to resize. This code will take care of length/width ratio on the resize.</p>
<pre><code>public static Bitmap CreateThumbnail(string lcFilename, int lnWidth, int lnHeight)
{
System.Drawing.Bitmap bmpOut = null;
try
{
Bitmap ... | <pre><code>private void ResizeImage(FileUpload fileUpload)
{
// First we check to see if the user has selected a file
if (fileUpload.HasFile)
{
// Find the fileUpload control
string filename = fileUpload.FileName;
// Check if the directory we want the image uploaded to actually exis... | 31,739 |
<p>We use Subversion as our source control system and store the VisualStudio project files (vcproj) in the source control system as is normal I think. With Subversion we don't use any form of file locking, so if two developers are working on the same project at the same time and both add files to the project, or change... | <p>I've found that option 2 (edit the files by hand) generally works fairly well, as long as you're using a good diff tool (I use <a href="http://www.winmerge.org/" rel="nofollow noreferrer">WinMerge</a>). The main problem I've run into is that Visual Studio will sometimes reorder the file. But, if you have a good di... | <p>We use a diff tool (<a href="http://www.winmerge.org/" rel="nofollow noreferrer">WinMerge</a>) to merge changes. The project files are (for the most part) really straight-forward XML. The key here, though, is that there never should be any surprises when merging, because good communication is part of the bed-rock of... | 20,145 |
<p>I come from the Microsoft world (and I come in peace). I want to rapidly prototype a web app and if it works out, take it live - and I don't want to use ASP.Net.</p>
<p>I am not sure which web application toolkit to use though. Should I use GWT, DOJO...other recommendations? I am open to any server-side language b... | <p>If you're open to doing Java, GWT is the way to go. It allows you to have a relatively uniform codebase across client-server, and to only use one language on both.</p>
<p>There are some limitations to doing very off-the-beaten-path AJAXy things (which GWT makes difficult, but not impossible), but it doesn't sound l... | <p>Personally, I would avoid server-side frameworks that try to embed or hide the client-side framework. I'm sure that GWT is great for getting something going quickly, and is probably fine for certain kinds of applications, but you'll probably run into lots of problems "on the edges" for more complex applications. D... | 13,366 |
<p>I'm needing to cache some data using <strong>System.Web.Caching.Cache</strong>. Not sure if it matters, but the data does not come from a database, but a plethora of custom objects.</p>
<p>The ASP.NET MVC is fairly new to me and I'm wondering where it makes sense for this caching to occur?</p>
<h3>Model or Controlle... | <p>I think it ultimately depends on <em>what</em> you are caching. If you want to cache the result of rendered pages, that is tightly coupled to the Http nature of the request, and would suggest a ActionFilter level caching mechanism.</p>
<p>If, on the other hand, you want to cache the data that drives the pages them... | <p>I think the caching should somehow be related to the model. I think the controller shouldn't care more about the data. The controller responsibility is to map the data - regardless where it come from - to the views.</p>
<p>Try also to think why you need to cache? do you want to save processing, data transmission or... | 29,102 |
<p>I have a Monoprice MP10 Mini, a cut-down Creality CR-10 with lobotomized firmware. Heated bed.</p>
<p>I'm trying to do PLA prints, but have been unable to find a usable temperature.</p>
<p>If I set the temperatures (either nozzle or bed) too low, the initial raft layers don't stick, the print shrivels up, and the ... | <p>Try bed at 50°C and hotend at 215°C, these are safe values.</p>
<p>Enable retraction in the slicer, to avoid/reduce oozing during long moves, but with Bowden setups finding a good value is trickier. Try with 6 mm.</p>
<p>Set the first layer height properly, but do it AFTER the bed has been heated for 5-10 minutes.... | <p>As @Fernando Balthazar had suggested, the z-offset was wrong. I needed to bring the nozzle and the bed closer together. The printer's default is -0.50 mm, I had to change to -0.78 mm or so to get it to stick. But then I need to reduce set it back to -0.50 or -0.40 during the print to avoid the nozzle banging into th... | 1,656 |
<p>I know that if you have a loop that modifies the count of the items in the loop, using the NSEnumerator on a set is the best way to make sure your code blows up, however I would like to understand the performance tradeoffs between the NSEnumerator class and just an old school for loop</p>
| <p>Using the new <code>for (... in ...)</code> syntax in Objective-C 2.0 is generally the fastest way to iterate over a collection because it can maintain a buffer on the stack and get batches of items into it.</p>
<p>Using <code>NSEnumerator</code> is generally the slowest way because it often copies the collection b... | <p>They are very similar. With Objective-C 2.0 most enumerations now default to <code>NSFastEnumeration</code> which creates a buffer of the addresses to each object in the collection that it can then deliver. The one step that you save over the classic for loop is not having to call <code>objectAtIndex:i</code> each t... | 5,297 |
<p>Below is the code of a simple html with a table layout.
In FF it's looking as I think it should look like,
in IE7 it doesn't. what am I doing wrong?<br><br>
And how can I fix it?</p>
<pre><code><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<TITLE>t... | <p>I assume you are complaining about the minimal height of the middle row (the one containing only rowspanned cells), and the enlarged height of the adjacent rows to compensate, leaving gaps between the divs.</p>
<p>IE cannot calculate optimal row heights when the row contains only rowspanned cells. The usual solutio... | <p>You should definitely go with CSS. Tables should NEVER be used for layout.</p>
| 23,995 |
<p>I require a tree / directed acyclic graph implementation something like this:</p>
<pre><code>public class TreeNode<K, V> {
private K key; // 'key' for this node, always present
private V value; // 'value' for this node, doesn't have to be set
private TreeNode<K, V> parent;
private Set&l... | <p>There doesn't seem to be anything of the kind. I asked <a href="https://stackoverflow.com/questions/66893/tree-data-structure-in-c">a similar question</a> last week and ended up implementing my own tree. My implementation was very similar to what you're proposing:</p>
<pre><code>public class TreeNode<T>
{
... | <p>If you're looking for additional graph capabilities, <a href="https://jdigraph.dev.java.net/" rel="nofollow noreferrer">JDigraph</a>'s <a href="https://jdigraph.dev.java.net/nonav/api/net/walend/digraph/Digraph.html" rel="nofollow noreferrer">Digraph</a> class should fit the bill. </p>
| 17,439 |
<p>In PHP, replace one URL with another within a string e.g. </p>
<pre><code>New post on the site <a href="http://stackoverflow.com/xyz1">http://stackoverflow.com/xyz1</a></p>
</code></pre>
<p>becomes:</p>
<pre><code>New post on the site <a href="http://yahoo.com/abc1">http://yahoo.com/abc1&l... | <pre><code>function replace_url($text, $newurl) {
$text = preg_replace('@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@', $newurl, $text);
return $text;
}
</code></pre>
<p>Should work.
Regex stolen from <a href="http://snipplr.com/view/2371/regex-regular-expression-to-match-a-url/" rel="nofollow norefer... | <p>Try this:</p>
<pre><code>preg_replace('#(https?://)(www\.)?stackoverflow.com\b#', '\1\2yahoo.com', $text);
</code></pre>
<p>If you want to change the path after the url, add another group and use <code>preg_replace_callabck</code>. More information in the PHP documentation.</p>
| 14,374 |
<p>I've seen some developers put instance variable declarations at the end of classes though I mostly see them placed at the top. The only reasons I can think of for doing this are stylistic preference or maybe it somehow makes them easier to work with in an IDE. Is there a more legitimate reason for choosing this st... | <p>Because of "Program to an 'interface', not an 'implementation'." (Gang of Four 1995:18) (<a href="http://en.wikipedia.org/wiki/Design_Patterns#Introduction.2C_Chapter_1" rel="noreferrer">http://en.wikipedia.org/wiki/Design_Patterns#Introduction.2C_Chapter_1</a>), some people prefer to declare instance variables at t... | <p>Most instance variables are <code>private</code>, so I tend to put them at the bottom because I declare members in order of decreasing visibility. If I declared them in order of <em>increasing</em> visibility they would be at the top, which is also reasonable.</p>
<p>What I don't like is having private fields foll... | 26,894 |
<p>I'm using QT's QGLFramebufferObject for off-screen rendering.<br>
After rendering to the buffer I read the result using glReadPixels()<br>
The problem is that sometimes the background color I read is just 0 (transparent black) and sometimes it is 0xFF000000 (opaque black)<br>
This seem to be related to the time the ... | <p>Do you set up the correct clear color (glClearColor) and actually do a clear (glClear)? Are you making sure that your color write (glColorMask) mask is fully enabled (it also affects clears). Next you can check if QT sets up some weird pixel copy transfer (other than the default, see glPixelStore, glPixelTransfer an... | <p>Mystery solved<br>
It seems that the clear color I give to the GLWidget is 0 and the default clear color is 0xff000000. Depending on when I initialize the framebuffer object, it receives the GLWidget's current clear color.</p>
| 34,568 |
<p>I'm trying to map a joined-subclass scenario using Fluent NHibernate.
I have a class Entity defined in the namespace Core, and a class
SubClass : Entity in the namespace SomeModule</p>
<p>Now I obviously don't want class Entity to know about its derived
types, the SomeModules namespace references Core - not the oth... | <p>I think the API has changed since this question was asked, but this works for me:</p>
<pre><code>public class SomeSubclassMap : SubclassMap<SomeSubclass> {
public SomeSubclassMap()
{
KeyColumn("SomeKeyColumnID");
Map(x => x.SomeSubClassProperty);
...
}
}
</code></pre>
<... | <p>Hello did some thing like it a few days ago.</p>
<pre><code>public class EntityMap : ClassMap<Entity> {
public EntityMap() {
Id(x => x.Id)
JoinedSubClass<SubClass>("SubClassId", sub => {
sub.Map(x => x.Name);
sub.Map(x => x.SomeProperty);
});
}
}
</code>... | 41,094 |
<p>I'm updating some of our legacy C++ code to use the "MFC feature pack" that Microsoft released for Visual Studio 2008. We've used the new classes to derive our application from CFrameWndEx, and are applying the Office 2007 styles to give our application a more modern appearance. This gives us gradient filled window ... | <p>Have you looked in the MFC source code, which you'll find in something like</p>
<p>C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\src\mfc</p>
| <p>Have you tried: <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=19E3BF38-434B-4DDD-9592-3749F6647105&displaylang=en" rel="nofollow noreferrer">2007 Office System Document: UI Style Guide for Solutions and Add Ins</a>
?</p>
| 3,026 |
<p>How to intercept dll method calls?</p>
<ul>
<li>What are the techniques available for it?</li>
<li>Can it be done only in C/C++?</li>
<li>How to intercept method calls from all running processes to a given dll?</li>
<li>How to intercept method calls from a given processes to a given dll?</li>
</ul>
| <p>There are two standard ways I can think of for doing this</p>
<ul>
<li><p>DLL import table hook.<br>
For this you need to parse the PE Header of the DLL, find the import table and write the address of your own function instead of what is already written there. You can save the address of the original function to be... | <p>On Linux, this can be done with the LD_PRELOAD environment variable. Set this variable to point at a shared library that contains a symbol you'd like to override, then launch your app.</p>
| 27,157 |
<p>We have 18 databases that should have identical schemas, but don't. In certain scenarios, a table was added to one, but not the rest. Or, certain stored procedures were required in a handful of databases, but not the others. Or, our DBA forgot to run a script to add views on all of the databases.</p>
<p>What is ... | <p>For legacy fixes/cleanup, there are tools, like <a href="http://www.red-gate.com/products/SQL_Compare/index.htm?gclid=CMvQrZjZ5ZUCFQZqswodnQ8Tfg" rel="nofollow noreferrer">SQLCompare</a>, that can generate scripts to sync databases.</p>
<p>For .NET shops running SQL Server, there is also the <a href="http://msdn.mi... | <p>We have got a tool called DB Schema Difftective that can compare and sync database schemas. With our other tool, DB MultiRun you can easily deploy generated (sync) scripts to multiple db servers (project based).</p>
| 11,942 |
<p>What I would like is a method to convert a double to a string which rounds using the half-up method - i.e. if the decimal to be rounded is 5, it always rounds up to the next number. This is the standard method of rounding most people expect in most situations.</p>
<p>I also would like only significant digits to be ... | <p>Use <a href="http://docs.oracle.com/javase/8/docs/api/java/text/DecimalFormat.html#setRoundingMode(java.math.RoundingMode)" rel="noreferrer"><code>setRoundingMode</code></a>, set the <a href="http://docs.oracle.com/javase/8/docs/api/java/math/RoundingMode.html" rel="noreferrer"><code>RoundingMode</code></a> explicit... | <p>If you Consider 5 or n number of decimal.
May be this answer solve your prob.</p>
<pre><code> double a = 123.00449;
double roundOff1 = Math.round(a*10000)/10000.00;
double roundOff2 = Math.round(roundOff1*1000)/1000.00;
double roundOff = Math.round(roundOff2*100)/100.00;
System.out.println("resu... | 18,563 |
<p>In what scenarios is it better to use a <code>struct</code> vs a <code>class</code> in C++?</p>
| <p>The differences between a <code>class</code> and a <code>struct</code> in C++ are:</p>
<ul>
<li><code>struct</code> members and base classes/structs are <code>public</code> by default.</li>
<li><code>class</code> members and base classes/structs are <code>private</code> by default.</li>
</ul>
<p>Both classes and st... | <p>I never use "struct" in C++. </p>
<p>I can't ever imagine a scenario where you would use a struct when you want private members, unless you're willfully trying to be confusing. </p>
<p>It seems that using structs is more of a syntactic indication of how the data will be used, but I'd rather just make a class and t... | 7,821 |
<p>I have a main frame with a splitter. On the left I have my (imaginatively named) CAppView_Leftand on the right I have CAppView_Right_1and CAppView_Right_2. Through the following code I initialise the two primary views correctly:</p>
<pre><code>if (!m_wndSplitter.CreateStatic(this, 1, 2))
{
TRACE0("Failed to Cre... | <p>There is a CodeProject article that should help you achieve what you want:</p>
<p><a href="http://www.codeproject.com/KB/splitter/usefulsplitter.aspx" rel="nofollow noreferrer">http://www.codeproject.com/KB/splitter/usefulsplitter.aspx</a></p>
<p>I have replaced views in a splitter before, so if the above doesn't ... | <p>You can't create a second right hand view because your </p>
<pre><code>m_wndSplitter.CreateStatic(this, 1, 2)
</code></pre>
<p>has only created two columns. You could change this to </p>
<pre><code>m_wndSplitter.CreateStatic(this, 1, 3)
</code></pre>
<p>and change your second right view to</p>
<pre><code>if (... | 24,104 |
<p>What is the most reliable and secure way to determine what page either sent, or called (via AJAX), the current page. I don't want to use the <code>$_SERVER['HTTP_REFERER']</code>, because of the (lack of) reliability, and I need the page being called to only come from requests originating on my site.<br /><br />
E... | <p>The REFERER is sent by the client's browser as part of the HTTP protocol, and is therefore unreliable indeed. It might not be there, it might be forged, you just can't trust it if it's for security reasons.</p>
<p>If you want to verify if a request is coming from your site, well you can't, but you can verify the us... | <p>There is no reliable way to check this. It's really under client's hand to tell you where it came from. You could imagine to use cookie or sessions informations put only on some pages of your website, but doing so your would break user experience with bookmarks.</p>
| 20,042 |
<p>I am using an ASP page where I have to read a CSV file and insert it into DB table "Employee". I am creating an object of TestReader. How can I write a loop to execute up to the number of rows/records of the CSV file which is being read?</p>
| <p>Do not try to parse the file yourself, you'll just give yourself a headache. There's quite a bit more to it than splitting on newline and commas. </p>
<p>You can use OLEDB to open up the file in a recordset and read it just as you would a db table. Something like this:</p>
<pre><code>Dim strConn, conn, rs
strC... | <p>Why not just insert the CSV? For example:</p>
<pre><code>SELECT * INTO MyTable FROM OPENDATASOURCE('Microsoft.JET.OLEDB.4.0',
'Data Source=F:\MyDirectory;Extended Properties="text;HDR=No"')...
[MyCsvFile#csv]
</code></pre>
<p>From: <a href="http://coding.derkeiler.com/Archive/Delphi/borland.public.delphi.databas... | 26,265 |
<p>As users, we love the power of Greasemonkey. As developers, it can complicate things.</p>
<p>Some <a href="http://dean.edwards.name/weblog/2005/03/ungreased/" rel="nofollow noreferrer">people</a> advocate defensively disabling user scripts; others are willing to die to defend them.</p>
<p>Is there a middle ground?... | <p>Any control you think you have over which user agents your site visitors use is illusory. However, the vast majority will be using vanilla IE/Firefox/Safari. But, if you've a site where the audience has adopted a Greasemonkey script en masse, then treat that as a strong vote from your users that the site needs to c... | <p>We've got accept the reality of our platform: once your website is in the (computer) memory of the viewer, they're able to do whatever they want with it, without your permission. Popular sites that try to dictate their own viewing terms to their audience often suffer immediate and angry backlash - instead of trying ... | 20,692 |
<p>I have a WCF service up and running and am able to communicate between the service and a .Net 2.0 Client using basicHttpBinding. </p>
<p>I now need to lock down the WCF service so that it can only be called by authenticated clients.</p>
<p>I have control over the clients that will be calling my service. The clien... | <p>You can configure a WCF endpoint to use <strong>2-way SSL authentication</strong>. That means that you can require clients to present an X.509 certificate that confirms their identity whenever they make a request to the service.<br /><br/>
On the server side of things, you can use one of the built-in validation sche... | <p>Using SSL certificate is the only option for .NET 2.0 client accessing WCF service as basicHttpBinding provides no security. By using SSL, you are securing the whole transport channel.</p>
<p>Check the link <a href="http://www.codeplex.com/WCFSecurityGuide/Release/ProjectReleases.aspx?ReleaseId=15892" rel="nofollow... | 28,769 |
<p>Is it generally better to run functions on the webserver, or in the database?</p>
<p>Example:</p>
<pre><code>INSERT INTO example (hash) VALUE (MD5('hello'))
</code></pre>
<p>or</p>
<pre><code>INSERT INTO example (hash) VALUE ('5d41402abc4b2a76b9719d911017c592')
</code></pre>
<p>Ok so that's a really trivial exa... | <p>I try to think of the database as the place to persist stuff only, and put all abstraction code elsewhere. Database expressions are complex enough already without adding functions to them.</p>
<p>Also, the query optimizer will trip over any expressions with functions if you should ever end up wanting to do somethin... | <p>I think most of the time, you're going to want to leave the data manipulation to the webserver but, if you want to process databases with regards to tables, relations, etc., then go for the DB.</p>
<p>I'm personally lobbying my company to upgrade our MySQL server to 5.0 so that I can start taking advantage of proce... | 31,951 |
<p>If a user select all items in a .NET 2.0 ListView, the ListView will fire a <strong>SelectedIndexChanged</strong> event for every item, rather than firing an event to indicate that the <em>selection</em> has changed.</p>
<p>If the user then clicks to select just one item in the list, the ListView will fire a <stron... | <p>Good solution from Ian. I took that and made it into a reusable class, making sure to dispose of the timer properly. I also reduced the interval to get a more responsive app. This control also doublebuffers to reduce flicker.</p>
<pre><code> public class DoublebufferedListView : System.Windows.Forms.ListView
{
... | <p>I would either try tying the postback to a button to allow the user to submit their changes and unhook the event handler.</p>
| 11,232 |
<p>I'd like to talk about site building a little bit. We have now been in public Beta for almost a year now and I feel that we've learned a lot about what audience we have here on Stack Exchange. However, we've got a little ways to go before we can make it out of Beta.</p>
<h1>The Stats</h1>
<ul>
<li><em>Questions pe... | <p>Well we need to attract more members! Personally I know a lot of people that can help us attract more. Myself I run a facebook group with 6k members called 3d printing hobbyists. That said I am also friends with the admins of the other and larger groups. </p>
<p>If I had some good promo material I could probably ge... | <p>Well we need to attract more members! Personally I know a lot of people that can help us attract more. Myself I run a facebook group with 6k members called 3d printing hobbyists. That said I am also friends with the admins of the other and larger groups. </p>
<p>If I had some good promo material I could probably ge... | 37 |
<p>I'm lead to believe that quick sort should be faster than insertion sort on a medium size unorderd int array. I've implemented both algorithms in java and I notice quicksort is significantly slower then insertion sorrt. </p>
<p>I have a theory: quiksort is being slower because it's recursive and the call it's mak... | <p>You may be interested in these <a href="http://www.sorting-algorithms.com/" rel="nofollow noreferrer">Sorting Algorithm Animations</a>. </p>
| <p>The fastest implementations of quicksort use looping instead of recursion. Recursion typically isn't very fast.</p>
| 47,248 |
<pre><code>today1 = new Date();
today2 = Date.parse("2008-28-10");
</code></pre>
<p>To compare the time (millisecond) values of these I have to do the following, because today2 is just a number.</p>
<pre><code>if (today1.getTime() == today2)
</code></pre>
<p>Why is this?</p>
| <p>To answer the question in the title: Because they decided so when creating the JavaScript language. Probably because Java's <code>java.util.Date</code> parse function was doing the same thing, and they wanted to mimic its behavior to make the language feel more familiar.</p>
<p>To answer the question in the text...... | <p>What Data.parse is returning is a NaN. Which fundementally is an indefinite number. This is what most implementations return when its unable to convert the string to a date. Some implementations do not cope with anything but an <a href="https://www.rfc-editor.org/rfc/rfc1123" rel="nofollow noreferrer">RFC 1123</a> ... | 30,041 |
<p>Where would i go to look for algorithms that take a 2d grid of values that are either 0 or 1 as input and then identifies all possible non-overlapping rectangles in it?</p>
<p>In a more practical explanation: I am drawing a grid that is represented by a number of squares, and i wish to find a way to combine as many... | <p>I've done something similar for a quick-and-dirty voxel visualization of 3d boxes with OpenGL. </p>
<p>I started from the top left box and stored the empty/filled flag. Then I tried to expand the rectangle to the right until I hit a box with a different flag. I did the same in the down direction.</p>
<p>Draw the r... | <p>So you are looking for the rectangular boundary of the 'ON' squares?<br>
Do you want the inner or outer bound?<br>
ie. Must the boundary only have 'ON' squares or do you want the rectangle to contain all the 'ON' squares in a group?</p>
| 32,071 |
<p>Can someone recommend a secure FTP implementation that works well on Windows Server 2000? I'm uploading files into virtual directories and web applications under IIS and the existing provider, obviously, isn't secure or encrypted.</p>
| <p>Did you try filezilla server? <a href="http://filezilla-project.org/" rel="nofollow noreferrer">http://filezilla-project.org/</a></p>
<p>It supports FTP over SSL/TLS</p>
<p>Check out -
<a href="http://wiki.filezilla-project.org/FileZilla_FTP_Server" rel="nofollow noreferrer">http://wiki.filezilla-project.org/FileZ... | <p><a href="http://www.serv-u.com/" rel="nofollow noreferrer">http://www.serv-u.com/</a></p>
<p>Is good. They support both ftp/ssl and Sftp.</p>
| 32,868 |
<p>I'd like to read whole content of a text file to a <code>std::string</code> object with c++. </p>
<p>With Python, I can write:</p>
<pre><code>text = open("text.txt", "rt").read()
</code></pre>
<p>It is very simple and elegant. I hate ugly stuff, so I'd like to know - what is the most elegant way to read a text fi... | <p>There are many ways, you pick which is the most elegant for you.</p>
<p>Reading into char*:</p>
<pre><code>ifstream file ("file.txt", ios::in|ios::binary|ios::ate);
if (file.is_open())
{
file.seekg(0, ios::end);
size = file.tellg();
char *contents = new char [size];
file.seekg (0, ios::beg);
fi... | <p>I like Milan's char* way, but with std::string.</p>
<pre><code>
#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>
using namespace std;
string& getfile(const string& filename, string& buffer) {
ifstream in(filename.c_str(), ios_base::binary | ios_base::ate);
... | 23,726 |
<p>I have an MS SQL database and have a <code>varchar</code> field that I would like to do queries like <code>where name like '%searchTerm%'</code>. But right now it is too slow, even with SQL enterprise's full text indexing. </p>
<p>Can someone explain how <code>Lucene .Net</code> might help my situation? How do... | <p>I saw this guy (Michael Neel) present on Lucene at a user group meeting - effectively, you build index files (using Lucene) and they have pointers to whatever you want (database rows, whatever)</p>
<p><a href="http://code.google.com/p/vinull/source/browse/#svn/Examples/LuceneSearch" rel="noreferrer">http://code.goo... | <p>This <a href="http://blog.scalingweb.com/2007/11/03/full-text-search-for-database-using-lucene-search-engine/" rel="nofollow noreferrer">article</a> (strangely enough it's on the top of the Google search results :) has a fairly good description of how the Lucene search could be optimised.</p>
<p>Properly configured... | 18,492 |
<p>We have some integer arithmetic which for historical reasons has to work the same on PHP as it does in a few statically typed languages. Since we last upgraded PHP the behavior for overflowing integers has changed. Basically we are using following formula:</p>
<pre><code>function f($x1, $x2, $x3, $x4)
{
return... | <p>So I solved the problem, and discovered a lot about PHP (at least in the way it handles Integer overflow). </p>
<p>1) It completely depended on a cross between which platform the machine was running on, which version of PHP, whether or not it had Suhosin Hardened PHP running, and how many bits it was compiled for ... | <p>Check your version number of PHP - I believe it is possible you will get different results with different versions of PHP that may have differing support for long integers. I believe that there was a bug with long integers in at last one of the PHP 5 versions.</p>
<p>In version PHP 5.2.0 - the answer is EXACTLY th... | 38,577 |
<p>I have a stored procedure that has a optional parameter, <code>@UserID VARCHAR(50)</code>. The thing is, there are two ways to work with it:</p>
<ol>
<li>Give it a default value of <code>NULL</code>, the have an <code>IF...ELSE</code> clause, that performs two different <code>SELECT</code> queries, one with <code>'... | <p>What I typically do is something like</p>
<pre><code>WHERE ( @UserID IS NULL OR UserID = @UserID )
</code></pre>
<p>And why isn't it indexed? It's generally good form to index FKs, since you often join on them...</p>
<p>If you're worried about query plan storage, simply do:
CREATE PROCEDURE ... WITH RECOMPILE</p>... | <p>I would sort-of go with option 1, but actually have two stored procedures. One would get all the users and one would get a specific user. I think this is clearer than passing in a NULL. This is a scenario where you do want two different SQL statements because you're asking for different things (all rows vs one ro... | 33,435 |
<p>I have a .NET class library containing a class with a method that performs some lengthy operation. When a client calls this method it should perform the lengthy operation on a new thread in order to avoid blocking the caller. But once the method finishes it should execute some code on the main thread. In a WinForms ... | <p>I found a simple solution to the problem :</p>
<p>My COM object is declared like this:</p>
<pre><code>public class Runner
{
public void Run(string executable, object processExitHandler)
{
ThreadPool.QueueUserWorkItem(state =>
{
var p = new Process()
{
... | <p>A thread cannot just execute stuff on another thread. The closest you can get is to put a delegate on a queue for the other thread to execute, but that assumes that the other thread is cooperating about this.</p>
<p>In a WinForms application, the main loop looks for such queued messages on each loop iteration.</p>
... | 33,927 |
<p>Is there a free XML formatting (indent) tool available where I can past an XML string and have it formatted so I can read the XML document correctly?</p>
<p>Thanks</p>
<p>Edit ~ I am using XML Notepad on Windows XP.</p>
| <p>I believe that <a href="http://notepad-plus.sourceforge.net/" rel="noreferrer">Notepad++</a> has this feature.</p>
<p><strong>Edit (for newer versions)</strong><br>
Install the "XML Tools" plugin (Menu Plugins, Plugin Manager)<br>
Then run: Menu Plugins, Xml Tools, Pretty Print (XML only - with line breaks)</p>
<p... | <p>Not directly an answer, but good to know nevertheless: After indenting, please make sure that the parser(s) and application(s) which will subsequently process the formatted XML will not yield different results. <a href="http://xml.silmaril.ie/whitespace.html" rel="nofollow noreferrer">White space is often significan... | 23,546 |
<p>I am using Log4Net with the AdoNetAppender to log messages from a simple systray application into a SQL Server 2005 database.</p>
<p>I want to log the machine name along with the log message because this application will be running on multiple machines and I need to know on which one the message originated.</p>
<p... | <p>You can use the pre-populated property <code>log4net:HostName</code>, for example:</p>
<pre><code><conversionPattern value="%property{log4net:HostName}" />
</code></pre>
<p>This way you don't need to populate the MDC.</p>
| <p>you can create a parameter similar to the following:</p>
<pre><code><parameter>
<parameterName value="@machine" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%X{machine}" />
</layout>
&... | 19,689 |
<p>I have build server inside our domain (and it needs to be because it also talks to other boxes in the domain), and a webserver that is in the DMZ.</p>
<p>As part of our build scripts, I would like to deploy websites to the webserver in the DMZ, using the Nant copy task. The problem is, that Nant is invoked from Te... | <p>A couple options might be:</p>
<ol>
<li>Use the <a href="http://www.jetbrains.net/confluence/display/TCD4/Simple+Command+Runner" rel="nofollow noreferrer">Simple Command Runner</a> to exec out to something like <a href="http://technet.microsoft.com/en-us/library/bb490994.aspx" rel="nofollow noreferrer">runas</a>, s... | <p>you could use powershell remoting to pull releases from the build server. The server would be less vulnerable than if you were to use a push release like a file copy.</p>
<p>I'm doing this with a custom app that logs into teamcity and downloads artifacts and then deploys using powershell locally.</p>
| 44,823 |
<p>I am trying to open a report in Crystal Report 11 Designer (product version 11.5.8.826), but it seems to freeze up. This report use to work fine, but today the client could not load the report.</p>
<p>I also tried to open the report on another developer's workstation, with the same result.</p>
<p>Has this happened... | <p>We found the answer. We used a program called Wireshark (www.wireshark.org).</p>
<p>We closed down every app, and just ran the wireshark and tried to open the report in the crystal designer.</p>
<p>Then found that it was trying to access the printer spooler service on a box we used, but changed recently to another... | <p>try this "C# code":</p>
<pre><code>ReportDocument rpDoc = new ReportDocument()
rpDoc.Load(Server.MapPath(@"reportname.rpt"));
</code></pre>
<p>hope it helps</p>
| 24,071 |
<p>I need something like i6comp but for list of reg changes rather than list of files.</p>
<p>Does such a thing exist?</p>
<p>EDIT:I know there are ways to do monitor changes to the ergistry but are there ways to do it by examining the setup files? </p>
| <p><a href="http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx" rel="nofollow noreferrer">Process Monitor</a></p>
| <ol>
<li>Export the registry.
<ul>
<li>Run installer.</li>
<li>Export the registry to a different file</li>
<li>Compare the two files with your favorite comparison program.</li>
</ul></li>
</ol>
| 19,994 |
<p>I am having the worst luck with this. We bought a template to update our own website (don't have enough time to start our own from scratch!) but when I make simple changes in the Flash CS4 native file and re-export the swf, it doesn't work correctly!</p>
<p>I am wondering if anyone has run across the same problems ... | <p>Look at the <code>optionsExample.html</code> in your WMD distribution. There's an option to send the result to the server as Markdown.</p>
| <p>I have just know <a href="http://milianw.de/projects/markdownify/" rel="nofollow">Markdownify</a> (formerly html2text.php) that "writes texts in Markdown and save them in HTML. You won’t need a copy of the original Markdown input, since Markdownify can convert the saved HTML back to Markdown. And because page impres... | 29,111 |
<p>Say that I write an article or document about a certain topic, but the content is meant for readers with certain prior knowledge about the topic. To help people who don't have the "required" background information, I would like to add a note to the top of the page with an explanation and possibly a link to some refe... | <p>You can build that portion of the content dynamically using Javascript. </p>
<p>For example:</p>
<pre><code><html>
<body>
<div id="dynContent">
</div>
Rest of the content here.
</body>
<script language='javascript' type='text/javascript'>
var dyn = document.getElementBy... | <p>I just came to think of something. I guess I could render the note with JavaScript once the page is loaded?</p>
| 17,113 |
<p>I need to get substed drive letter in Perl. Could anyone kindly help me?
$ENV{SYSTEMDRIVE} does not work; it gives me real logical drive letter, not the substed one.</p>
| <pre><code> perl -e 'use Cwd; print( substr(getcwd(),10,1 )) ' # prints 10th char.
</code></pre>
| <p>If you want to do it yourself, you could capture the output of the subst command and process it, since it outputs all current substituted drives.</p>
<pre><code>SUBST [drive1: [drive2:]path]
SUBST drive1: /D
drive1: Specifies a virtual drive to which you want to assign a path.
[drive2:]path Specifie... | 47,988 |
<p>Name of the option tells something but what Visual Studio/compiler really do and what are the real consequences?</p>
<p>Edit: If you search google you can find <a href="http://msdn.microsoft.com/en-us/library/k1ack8f1.aspx" rel="noreferrer">this address</a>, but that is not really I am looking for. I wonder the rea... | <p>Without optimizations the compiler produces very dumb code - each command is compiled in a very straightforward manner, so that it does the intended thing. The Debug builds have optimizations disabled by default, because without the optimizations the produced executable matches the source code in a straightforward m... | <p>The short answer is: use -Ox and let the compiler do its job.</p>
<p>The long answer: the effect of different kind of optimizations is impossible to predict accurately. Sometimes optimizing for fast code will actually yield smaller code than when optimizing for size. If you really want to get the last 0.01% of perf... | 13,902 |
<p>I was told this a few times in this very site, but I wanted to make sure this is really the case.</p>
<p>I was expecting to be able to sprinkle NSLog function calls throughout my code, and that Xcode/gcc would automatically strip those calls out when building my Release/Distribution builds.</p>
<p>Should I avoid u... | <p>Preprocessor macros are indeed great for debugging. There's nothing wrong with NSLog(), but it's simple to define your own logging function with better functionality. Here's the one I use, it includes the file name and line number to make it easier to track down log statements.</p>
<pre><code>#define DEBUG_MODE
#i... | <p>I would highly recommend using TestFlight for logging (free). Their method will override NSLog (using a macro) and allow you to turn on/off logging to their server, Apple System log and STDERR log, for all your existing calls to NSLog. The nice thing about this is you can still review your log messages for apps depl... | 38,555 |
<p>I am a bit new to Perl, but here is what I want to do: </p>
<pre><code>my @array2d;
while(<FILE>){
push(@array2d[$i], $_);
}
</code></pre>
<p>It doesn't compile since <code>@array2d[$i]</code> is not an array but a scalar value.</p>
<p>How should I declare @array2d as an array of array?</p>
<p>Of course,... | <p>To make an array of arrays, or more accurately an array of arrayrefs, try something like this: </p>
<pre><code>my @array = ();
foreach my $i ( 0 .. 10 ) {
foreach my $j ( 0 .. 10 ) {
push @{ $array[$i] }, $j;
}
}
</code></pre>
<p>It pushes the value onto a dereferenced arrayref for you. You should be abl... | <p>Another simple way is to use a hash table and use the two array indices to make a hash key:</p>
<pre><code>$two_dimensional_array{"$i $j"} = $val;
</code></pre>
| 40,984 |
<p>I'm trying to emulate the file upload code from the grails website, and I'm running into some problems. I'm using the same code as found <a href="http://grails.org/Controllers+-+File+Uploads" rel="nofollow noreferrer">here</a>. Here is my code:</p>
<pre><code> <g:form action="upload" method="post" enctype="... | <p>Problem solved!</p>
<p>I was using the example code for uploading files to Grails differently than the original author probably intended. The problem is that when the <em>upload</em> method of the controller was called, it was sometimes for the original render of the Upload page. The request in that method was wa... | <p>make sure you update the html (your gsp with the form to upload from) to have the <strong>enctype</strong> as they show:</p>
<pre><code><g:form action="upload" method="post" enctype="multipart/form-data">
</code></pre>
<p>Hope that is helpful, seems too obvious but it's my first thought after seeing your err... | 25,267 |
<p>OK, say that my application is emitting (x86) instructions into memory, making the page executable, etc. Is there a way of altering the method stub of an un-JITted method to point to my emitted instruction stream?</p>
<p>E.g.:</p>
<p>Suppose I have created an x86 instruction stream in memory, which does something ... | <p>Yes, you can do it!</p>
<p>Hook the getJit method of mscorjit. And you will be asked every time if any method require jitting. You can pass whatever you want.</p>
<p>Some .NET protectors works like this.</p>
| <p>In addition to being able to use ICorProfiler and rewriting your method before it jits, you could use <a href="http://blogs.msdn.com/jmstall/archive/2004/10/22/246151.aspx" rel="nofollow noreferrer">ICorDebug</a> (MDBG has managed interfaced). Set a breakpoint, when the breakpoint hits set the next statement to you... | 28,513 |
<p>A friend came across a quadratic Bézier curve function in his codebase that used a gigantic rats nest of a switch table to perform the computation. He challenged me to find a single, short expression that would allow him to replace the gigantic block of code.</p>
<p>In attempting to satisfy two different curiositie... | <p>b2 isn't recursive, so no need for [let rec b2 n =]. Since n never changes, no need to have it as argument to b2i, just use n from the enclosing scope. Your inner function should depend on p0, p1 and p2, but I see it depending on -10., n**2 and 10. The function also has the form of a map from [ 0.0; 1.0; 2.0; ...... | <p>I have two suggestions:</p>
<p>You should call <code>List.rev</code> after <code>b2i</code> returns so ocaml can exploit it's tail-recursion optimizations. I am not sure how well OCaml will deal with the current implementation, <code>List.rev</code> is tail-recursive though. You'll notice that in <a href="http://cam... | 17,492 |
<p>Having been a hobbyist programmer for 3 years (mainly Python and C) and never having written an application longer than 500 lines of code, I find myself faced with two choices :</p>
<p>(1) Learn the essentials of data structures and algorithm design so I can become a l33t computer scientist.</p>
<p>(2) Learn Qt, w... | <p>This could be considered heresy, but the vast majority of application code does not require much understanding of algorithms and data structures. Most languages provide libraries which contain collection classes, searching and sorting algorithms, etc. You generally don't need to understand the theory behind how thes... | <p>Moving from 500 loc to a real (eve if small) application it's not that easy.
As Don was pointing out, you'll need to learn a lot of things about code (flexibility, reuse, etc), you need to learn some very basic of configuration management as well (visual source safe, svn?)</p>
<p>But the main issue is that you need... | 49,104 |
<p>It feels like my print is almost there, I spent a long time fine tuning the calibration with a fantastic set of G-code files from <a href="https://www.youtube.com/watch?v=_EfWVUJjBdA" rel="nofollow noreferrer">Chuck Hellebuyck</a>.</p>
<p>I am using an Ender 3, on which I have modified the heatbed to carry a glass ... | <p>Based on the pictures, this looks like the bed wasn't clean enough, thus why it didn't adhere correctly in some spots. The lifted corner is the worst, but I can see a couple more spots where the PLA didn't stick well enough, though the brim prevented it to completely lift off the bed.</p>
<p>I would advise you to n... | <p>I work with a glass surface on my machine and use a drop of superglue to attach the
corners after the first layer is complete. The biggest contributors to not sticking are :</p>
<ol>
<li>Bed not level.</li>
<li>Temperature of filament not hot enough.</li>
<li>First layer print speed is too fast.</li>
<li>Heated Be... | 1,159 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.