instruction
stringlengths
21
27.8k
chosen
stringlengths
18
28.2k
rejected
stringlengths
18
33.6k
__index_level_0__
int64
0
50k
<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/334879/how-do-i-get-the-application-exit-code-from-a-windows-command-line">How do I get the application exit code from a Windows command line?</a> </p> </blockquote> <p>In Unix/bash, I can simply say:</p> <blockquote> <p>$ echo $?</p> </blockquote> <p>to find out the return/exit code of a program, both from interactive and non-interactive shells.</p> <p>Now, how can I do the equivalent in Windows/cmd.exe? </p>
<p>Use "errorlevel", like this:</p> <pre><code>IF ERRORLEVEL 1 GOTO ERROR </code></pre> <p>The errorlevel command is a little peculiar; it returns true if the return code was equal to or <strong>higher</strong> than the specified errorlevel. You can also write</p> <pre><code>IF %ERRORLEVEL% NEQ 0 GOTO ERROR </code></pre> <p><a href="http://www.robvanderwoude.com/errorlevel.html" rel="noreferrer">This page</a> is a good overview of how to use errorlevels in .bat files.</p>
<p>check for the ERRORLEVEL</p>
34,988
<p>Like most developers I have grown to love dual monitors. I won't go into all the reasons for their goodness; just take it as a given.</p> <p>However, they are not perfect. You can never seem to line them up "just right". You always end up with the monitors at slight funny angles. And of course the bezel always gets in the way. And this is with identical monitors. The problem is much worse with different monitors -- VMWare's multi monitor feature won't even work with monitors of differnt resolutions.</p> <p>When you use multiple monnitors, one of them becomes your primary monitor of focus. Your focus may flip from one monitor to the other, but at any point in time you are usually focusing on only one monitor. There are exceptions to this (WinDiff, Excel), but this is generally the case. I suggest that having a single large monitor with all the benefits of multiple smaller monitors would be a better solution.</p> <p>Wide screen monitors are fantastic, but it is hard to use all the space efficiently. If you are writing code you are generally working on the left-hand side of the window. If you maximize an editor on a wide-screen monitor the right-hand side of the window will be a sea of white. Programs like WinSplit Revolution will help to organise your windows, but this is really just addressing the symptom, not the problem. Even with WinSplit Revolution, when you maximise a window it will take up the whole screen. You can't lock a window into a specific section of the screen.</p> <p>This is where virtual monitors comes in. </p> <p>What would be really nice is a video driver that sits on top of the existing driver, but allows a single monitor to be virtualised into multiple monitors. Control Panel would see your single physical monitor as two or more virtual monitors. The software could even support a virtual bezel to emphasise what is happening, or you could opt for seamless mode. Programs like WinSplit Revolution and UltraMon would still work. This virtual video driver would allow you to slice &amp; dice your physical monitor into as many virtual monitors as you want. </p> <p>Does anybody know if such software exists? If not, are there any budding Windows display driver guru's out there willing to take up the challenge?</p> <p>I am not after the myriad of virtual desktop/window manager programs that are available. I get frustrated with these programs. They seem good at first but they usually have some strange behaviour and don't work well with other programs (such as WinSplit Revolution). </p> <p>I want the real thing!</p>
<p>can <a href="http://jgpaiva.donationcoders.com/gridmove.html" rel="noreferrer">gridmove</a> be of any assistance?</p> <p>very handy tool on larger screens...</p>
<p>What about just using virtual desktops? You can spread your windows around among multiple workspaces. Something like <a href="http://virt-dimension.sourceforge.net/" rel="nofollow noreferrer">Virtual Dimension</a> should give you most of that functionality. I use virtual desktops all the time on Linux, and it's the next best thing to multiple monitors.</p>
46,183
<p>In my <a href="https://stackoverflow.com/questions/222442/sql-server-running-large-script-files">eternal</a> <a href="https://stackoverflow.com/questions/224830/how-do-i-set-a-sql-server-scripts-timeout-from-within-the-script">saga</a> to insert 1.4 million rows of data from a SQL script, I've written a basic WinForms app that takes each line of the script and executes it individually.</p> <p>However, because the original script contained</p> <pre><code>SET IDENTITY_INSERT [Table] OFF </code></pre> <p>and SET is a session-wide command, this setting is getting lost on every SQL call, meaning that each line is failing. Is there a way to set IDENTITY_INSERT off for the whole table, database-wide just so I can make these individual calls without them failing? Or perhaps I can tell it to ignore the identity specification by appending a command to each line?</p>
<p><a href="http://msdn.microsoft.com/en-us/library/ms188365.aspx" rel="noreferrer">BULK INSERT</a> won't work for you? Or the SQL Server Import/Export Wizard (<a href="http://www.databasejournal.com/features/mssql/article.php/3580216" rel="noreferrer">here</a> or <a href="http://technet.microsoft.com/en-us/library/ms141209.aspx" rel="noreferrer">here</a>)? I know import/export can turn off identity insert for the whole import. I'm reasonably certain you can do it just prior to BULK INSERT</p>
<p>I believe that IDENTITY INSERT can only be overridden one table at a time, per session.</p> <p>You will have to maybe batch up 2 or 300 insert statements at a time and precede each batch with the ident insert. </p> <p>so the app will execute a block like this....</p> <pre><code>SET IDENTITY_INSERT [Table] OFF; INSERT INTO TABLE VALUES (1, 'a'); INSERT INTO TABLE VALUES (2, 'b'); INSERT INTO TABLE VALUES (3, 'c'); INSERT INTO TABLE VALUES (4, 'd'); INSERT INTO TABLE VALUES (5, 'e'); SET IDENTITY_INSERT [Table] ON; </code></pre>
28,526
<ol> <li>Is there a way that I can select a bunch of rows or cells from a SilverLight DataGrid and Copy them for pasting into e.g. excel?</li> </ol> <p>The DataGrid doesn't seem to have this functionality built in!</p> <p>Thanks a lot </p>
<p>Silverlight 4 is great, Ctrl-A a datagrid, copy and paste it into Excel.</p> <p>You can even customize what gets copied using ClipboardContentBinding, which is quite useful if you are using a TemplateColumn.</p>
<p>Silverlight uses a vector rendering system. The text is not the same as text in Notepad- it's being rendered as a vector image. You can't highlight text in Silverlight or Flash.</p> <p>If you're writing the app, offer a "download Excel file" button that redirects to an Excel file generator.</p>
39,100
<p>Im trying to add a third party framework in Xcode but I'm getting an error that it can't be found</p> <blockquote> <p>error: MKAbeFook/MKAbeFook.h: No Such File or Directory</p> </blockquote> <p>I've added it in the Linked Frameworks group and added it to the Target for this project. I've also added it to a new Copy Files build phase for that target.</p> <p>Basically I've followed the instructions here: <a href="http://pointlesscrap.net/mkabefook/desktop/gettingstarted" rel="nofollow noreferrer">http://pointlesscrap.net/mkabefook/desktop/gettingstarted</a></p> <p>Any ideas where I'm going wrong?</p>
<p>Best way to diagnose this is to post the compiler invocation line, not just the error (you can just drag and drop the line from the Build Results window that says "Compiling foo.m"). My expectation is that you don't have a Frameworks Search Path set up for the location of the framework. Xcode usually adds that manually when you add the framework, but if you put it in certain kinds of places, or added it in certain ways, you need to manually point your target's Framework Search Paths at its directory.</p>
<p>Perhaps the author mistook MKFaceBook for MKAbeFook?</p> <p>EDIT: Never mind, it looks like that is actully the name of the framework.</p>
49,761
<p>To quote wikipedia:</p> <blockquote> <p>Scrum is facilitated by a ScrumMaster, whose primary job is to remove impediments to the ability of the team to deliver the sprint goal. The ScrumMaster is not the leader of the team (as they are self-organizing) but acts as a buffer between the team and any distracting influences. The ScrumMaster ensures that the Scrum process is used as intended. The ScrumMaster is the enforcer of rules."</p> </blockquote> <p>Working on this basis, and the fact that most businesses are running 2-3 projects at a time, what actual work tasks does a SM do to fill a full time job? Or, is it not a full time job and that individual do other things such as development, sales etc?</p> <p>Do any SM's out there have anything to share?</p>
<p>Unfortunately we don't have the luxury of having dedicated scrum masters. I am also a team leader and senior developer which more than fills the day.</p>
<p>A Scrum Master role implemented correctly, is invaluable to the Project and should not be look upon as a Part time role. The most important aspect of the role is to act as an obstacle remover for any queries raised in the Scrum meetings by the Development Teams. A Technical Scrum Master (which is what most SMs tend to be) should not be a Developer on the team, but should be able to advise on design and solutions (an extension to pair programming if you will). </p> <p>They are responsible for updating the ProductBackLog (stories should be created by the business), SprintBackLog and BurnLog and for liasing with the business and IT Management on progress. They also manage a SpikeLog for any items that require investigation that may evolve into Stories (again driven by the business).</p>
15,557
<p>There is a groupwall of which I want to download and store all messages in a db. In the documentation I cannot find a good way to do it. Did I miss something? What's the good way to do this?</p>
<p>As I need the subscript, I cannot avoid the custom formatting. What I found out to be an ugly, but obviously possible solution is the following:</p> <pre><code>&lt;MenuItem&gt; &lt;MenuItem.Header&gt; &lt;StackPanel Orientation="Horizontal"&gt; &lt;AccessText&gt;_O&lt;/AccessText&gt; &lt;TextBlock&gt; &lt;Span BaselineAlignment="Subscript" FontSize="8"&gt;2&lt;/Span&gt;-Genion &lt;/TextBlock&gt; &lt;/StackPanel&gt; &lt;/MenuItem.Header&gt; &lt;/MenuItem&gt; </code></pre>
<p>Do you even need to use an AccessKey at all? Assuming that you didn't need/want the custom styling of the MenuItem header text, you could get the same affect by doing the following:</p> <pre><code>&lt;MenuItem HeaderText="_02" /&gt; </code></pre> <p>Would just putting an underscore before the 0 work? Although I seem to recall that one difference between TextBlock and Label is that TextBlock doesn't support access keys, but Label does. If that's the case, maybe use a Label instead of a TextBlock in your menu item?</p>
41,458
<p>For our application, we keep large amounts of data indexed by three integer columns (source, type and time). Loading significant chunks of that data can take some time and we have implemented various measures to reduce the amount of data that has to be searched and loaded for larger queries, such as storing larger granularities for queries that don't require a high resolution (time-wise).</p> <p>When searching for data in our backup archives, where the data is stored in bzipped text files, but has basically the same structure, I noticed that it is significantly faster to untar to stdout and pipe it through grep than to untar it to disk and grep the files. In fact, the untar-to-pipe was even noticeably faster than just grepping the uncompressed files (i. e. discounting the untar-to-disk).</p> <p>This made me wonder if the performance impact of disk I/O is actually much heavier than I thought. So here's my question:</p> <p><i>Do you think putting the data of multiple rows into a (compressed) blob field of a single row and search for single rows on the fly during extraction could be faster than searching for the same rows via the table index?</i></p> <p>For example, instead of having this table</p> <pre><code>CREATE TABLE data ( `source` INT, `type` INT, `timestamp` INT, `value` DOUBLE); </code></pre> <p>I would have</p> <pre><code>CREATE TABLE quickdata ( `source` INT, `type` INT, `day` INT, `dayvalues` BLOB ); </code></pre> <p>with approximately 100-300 rows in data for each row in quickdata and searching for the desired timestamps on the fly during decompression and decoding of the blob field.</p> <p>Does this make sense to you? What parameters should I investigate? What strings might be attached? What DB features (any DBMS) exist to achieve similar effects?</p>
<blockquote> <p>This made me wonder if the performance impact of disk I/O is actually much heavier than I thought.</p> </blockquote> <p>Definitely. If you have to go to disk, the performance hit is many orders of magnitude greater than memory. This reminds me of the classic Jim Gray paper, <a href="http://research.microsoft.com/research/pubs/view.aspx?tr_id=655" rel="nofollow noreferrer">Distributed Computing Economics</a>:</p> <blockquote> <p>Computing economics are changing. Today there is rough price parity between (1) one database access, (2) ten bytes of network traffic, (3) 100,000 instructions, (4) 10 bytes of disk storage, and (5) a megabyte of disk bandwidth. This has implications for how one structures Internet-scale distributed computing: one puts computing as close to the data as possible in order to avoid expensive network traffic. </p> </blockquote> <p>The question, then, is how much data do you have and how much memory can you afford?</p> <p>And if the database gets <em>really</em> big -- as in nobody could ever afford that much memory, even in 20 years -- you need clever distributed database systems like Google's <a href="http://research.google.com/archive/bigtable.html" rel="nofollow noreferrer">BigTable</a> or <a href="http://hadoop.apache.org/core/" rel="nofollow noreferrer">Hadoop</a>.</p>
<p>I made a similar discovery when working within Python on a database: the cost of accessing a disk is very, very high. It turned out to be much faster (ie nearly two orders of magnitude) to request a whole chunk of data and iterate through it in python than it was to create seven queries that were narrower. (One per day in question for the data)</p> <p>It blew out even further when I was getting hourly data. 24x7 lots of queries it lots!</p>
4,561
<p>I have a server access log, with timestamps of each http request, I'd like to obtain a count of the number of requests at each second. Using <code>sed</code>, and <code>cut -c</code>, so far I've managed to cut the file down to just the timestamps, such as:</p> <blockquote> <p>22-Sep-2008 20:00:21 +0000<br> 22-Sep-2008 20:00:22 +0000<br> 22-Sep-2008 20:00:22 +0000<br> 22-Sep-2008 20:00:22 +0000<br> 22-Sep-2008 20:00:24 +0000<br> 22-Sep-2008 20:00:24 +0000</p> </blockquote> <p>What I'd love to get is the number of times each unique timestamp appears in the file. For example, with the above example, I'd like to get output that looks like:</p> <blockquote> <p>22-Sep-2008 20:00:21 +0000: 1<br> 22-Sep-2008 20:00:22 +0000: 3<br> 22-Sep-2008 20:00:24 +0000: 2</p> </blockquote> <p>I've used <code>sort -u</code> to filter the list of timestamps down to a list of unique tokens, hoping that I could use grep like</p> <pre><code>grep -c -f &lt;file containing patterns&gt; &lt;file&gt; </code></pre> <p>but this just produces a single line of a grand total of matching lines.</p> <p>I know this can be done in a single line, stringing a few utilities together ... but I can't think of which. Anyone know?</p>
<p>I think you're looking for</p> <pre><code>uniq --count </code></pre> <blockquote> <p>-c, --count prefix lines by the number of occurrences</p> </blockquote>
<p>maybe use xargs? Can't put it all together in my head on the spot here, but use xargs on your sort -u so that for each unique second you can grep the original file and do a wc -l to get the number. </p>
15,618
<p>We have a multi-tiered/hierarchical YUI menu activated via a YUI menu button. Everything in this menu works pretty well. If you mouseover a menu item with a submenu, the submenu appears as expected. You can select an item from this submenu just fine. </p> <p>The problem, however, is that you can also click on the parent items of this menu which closes the entire menu. In fact, I want the opposite. I'd like a click of a parent menu item leave the top level menu open and open the submenu (i.e. I want a click to be identical to a mouseover event in terms of functionality).</p> <p>Side note: This isn't an issue on a typical web browser (e.g. Firefox) where the click event doesn't matter because you can't have a click without a mouseover. This is an issue on the iPhone which doesn't have a mouseover event.</p> <p>I've been playing with the autosubmenudisplay properties and keepopen properties, hoping I can just handle the parent item click events to do what I want but, so far, I've been unsuccessful. If I set autosubmenudisplay to false, I can't figure out how to get the submenus to display manually. The keepopen property doesn't seem to work rather I set it on the menu or submenus.</p> <p>Is there a way to get the behavior I want so our iPhone users are happy?</p>
<p>Todd Kloots, author of the YUI Button and Menu widgets here. Took at look at your request. Unfortunately the current version YUI Button and Menu aren't designed to support the type of interaction you are looking to create. Feel free to file a feature request via SourceForge and I'll try to work on this for a future version of YUI.</p> <ul> <li>Todd</li> </ul>
<p>It's not exactly what you asked for, but have you looked at <a href="http://code.google.com/p/iui/" rel="nofollow noreferrer">iUI</a>? You may be able to pick up some tricks from the implementation.</p>
28,953
<p>(best in your own eyes) Most features? Coolest Features? Slickest Design?</p> <p><a href="http://www.centreon.com/" rel="nofollow noreferrer">Centreon</a>?</p> <p><a href="http://www.nagvis.org/" rel="nofollow noreferrer">NagVis</a>?</p> <p>Other?</p>
<p>Centreon is the best ! We use it in our company. Have a look at FAN(Fully automated Nagios) ! best best best.. and don't forget to use the lm_sensors for linux and Notify By Jabber plugin if you use Jabber and linux servers in your company and google talk ;-)</p>
<p>NagVis seems to be better even if only from purely aesthetic prospective. But then for me it's one of the key elements. Maybe if you would ask more specific question (what criteria do you use to define <em>best</em>) it could be easier to answer you question.</p>
12,687
<p>How to find and remove unused Delphi runtime packages from a project that uses packages?</p> <p>I have a Delphi project that is made up of several packages, in the requires part of the packages there are several Borland/3rd party packages listed (rtl.dcp, vcl.dcp ect) I know I need most of them, but there are ones I know I don't need that have crept in there over time, maybe a component used them once but then that component was removed, or maybe it was from me testing code.</p> <p>How do I find out which are needed and which are not? and if they are not needed will they still need to be distributed with the final application or have any impact on the size/ memory requirement of the app?</p> <p>I am trying to make it all as streamline as possible.</p>
<p>If you specify a package to be used as runime package, all the packages that package requires need to be deployed as runtime package as well. Delphi's compiler automatically checks if this is the case. So you don't need to explicitly require rtl.dcp, as long as you require one of your other packages that does. This means you could only specify the runtime packages you are sure of you need and the rest will be added by the compiler. Then you only need to check what packages you need to deploy in the end.</p>
<p>I was getting a compile error for a package that I didn't have implicitly called and couldn't figure out how to get rid of. I asked my guru and got the following solution which worked well.</p> <p>"You can delete the .dproj and open the app (via RAD) using the .dpr file. Do a build and save. Then you should have a .dproj with references to what packages YOU have loaded in Delphi." (instead of what it remembers from previous builds)</p>
40,471
<p>How would I have a <a href="http://en.wikipedia.org/wiki/JavaScript" rel="noreferrer">JavaScript</a> action that may have some effects on the current page but would also change the URL in the browser so if the user hits reload or bookmark, then the new URL is used? </p> <p>It would also be nice if the back button would reload the original URL.</p> <p>I am trying to record JavaScript state in the URL.</p>
<p>If you want it to work in browsers that don't support <code>history.pushState</code> and <code>history.popState</code> yet, the "old" way is to set the fragment identifier, which won't cause a page reload.</p> <p>The basic idea is to set the <code>window.location.hash</code> property to a value that contains whatever state information you need, then either use the <a href="https://developer.mozilla.org/en/DOM/window.onhashchange" rel="noreferrer">window.onhashchange event</a>, or for older browsers that don't support <code>onhashchange</code> (IE &lt; 8, Firefox &lt; 3.6), periodically check to see if the hash has changed (using <code>setInterval</code> for example) and update the page. You will also need to check the hash value on page load to set up the initial content.</p> <p>If you're using jQuery there's a <a href="http://benalman.com/projects/jquery-hashchange-plugin/" rel="noreferrer">hashchange plugin</a> that will use whichever method the browser supports. I'm sure there are plugins for other libraries as well.</p> <p>One thing to be careful of is colliding with ids on the page, because the browser will scroll to any element with a matching id.</p>
<p>I've had success with:</p> <pre><code>location.hash="myValue"; </code></pre> <p>It just adds <code>#myValue</code> to the current URL. If you need to trigger an event on page Load, you can use the same <code>location.hash</code> to check for the relevant value. Just remember to remove the <code>#</code> from the value returned by <code>location.hash</code> e.g.</p> <pre><code>var articleId = window.location.hash.replace("#",""); </code></pre>
16,514
<h2>General</h2> <ul> <li>Follow the same standards for all tests.</li> <li>Be clear about what each test state is.</li> <li>Be specific about the expected behavior.</li> </ul> <h2>Examples</h2> <p>1) MethodName_StateUnderTest_ExpectedBehavior</p> <pre><code>Public void Sum_NegativeNumberAs1stParam_ExceptionThrown() Public void Sum_NegativeNumberAs2ndParam_ExceptionThrown () Public void Sum_simpleValues_Calculated () </code></pre> <p>Source: <a href="http://osherove.com/blog/2005/4/3/naming-standards-for-unit-tests.html" rel="noreferrer">Naming standards for Unit Tests</a></p> <p>2) Separating Each Word By Underscore</p> <pre><code>Public void Sum_Negative_Number_As_1st_Param_Exception_Thrown() Public void Sum_Negative_Number_As_2nd_Param_Exception_Thrown () Public void Sum_Simple_Values_Calculated () </code></pre> <h2>Other</h2> <ul> <li>End method names with <em>Test</em></li> <li>Start method names with class name</li> </ul>
<p>I am pretty much with you on this one man. The naming conventions you have used are:</p> <ul> <li>Clear about what each test state is.</li> <li>Specific about the expected behaviour.</li> </ul> <p>What more do you need from a test name?</p> <p>Contrary to <a href="https://stackoverflow.com/questions/96297/naming-conventions-for-unit-tests#96476">Ray's answer</a> I don't think the <em>Test</em> prefix is necessary. It's test code, we know that. If you need to do this to identify the code, then you have bigger problems, <strong>your test code should not be mixed up with your production code.</strong></p> <p>As for length and use of underscore, its <strong>test code</strong>, who the hell cares? Only you and your team will see it, so long as it is readable, and clear about what the test is doing, carry on! :)</p> <p>That said, I am still quite new to testing and <a href="http://cantgrokwontgrok.blogspot.com/2008/09/tdd-getting-started-with-test-driven.html" rel="noreferrer">blogging my adventures with it</a> :)</p>
<p>As long as you follow a single practice, it doesn't really matter. Generally, I write a single unit test for a method that covers all the variations for a method (I have simple methods;) and then write more complex sets of tests for methods that require it. My naming structure is thus usually test (a holdover from JUnit 3).</p>
12,191
<p>I have a simple app that uses an SQL Express 2005 database. When the user closes the app, I want to give the option to back up the database by making a copy in another directory. However, when I try to do it, I get "The process cannot access the file '...\Pricing.MDF' because it is being used by another process." I closed the connection, disposed the connection, set it to nothing, and GC.Collect(), but it makes no difference. My connection string is "Data Source=.\SQLEXPRESS2005;AttachDbFilename=|DataDirectory|\Pricing.mdf;Integrated Security=True; User Instance=True" and I just keep using the same connection throughout. I didn't see where I could detach the database to counter the attach in the connection string.</p> <p>1 - How do I RELEASE the thing? 2 - Is there a better way than just copying the database? The app is for my husband only, so I will be able to handle it if he actually does need to restore from backup.</p> <p>Thanks!</p>
<p>You don't want to copy the mdf directly because SQL keeps most of the changes in the transaction log, take a look at the modified time after running some queries, it doesn't write directly to the file. I noticed this while setting up an rsync job.</p> <p>Having SQL generate the backup is much safer and more desirable, single-user or multi-user. You can provide a link to a function calling the T-SQL which you can completely automate as far as source db and destination folder:</p> <pre><code>BACKUP DATABASE [mydatabasename] TO DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\Scheduled Task Backups\mydatabasename-backup' WITH NOFORMAT, NOINIT, NAME = N'mydatabasename-Full Data </code></pre> <p>SQL 2005 had introduced another T-SQL syntax to do this, for the life of me I can't find it. But there are ways to do it through M$$SQL without having the full blown database server.</p>
<p>There's an example in <a href="http://forums.microsoft.com/msdn/showpost.aspx?postid=487021&amp;siteid=1" rel="nofollow noreferrer">this post</a> that shows how to back up a SQL Express database within a program.</p>
41,307
<p>I am looking for the cleanest way. I am tempted to use delegates not sure though.</p>
<p>Are you after something like this?</p> <pre><code>class A { public int Value; public int Add(int a) { return a + Value; } public int Mul(int a) { return a * Value; } } class Program { static void Main( string[] args ) { A a = new A(); a.Value = 10; Func&lt;int, int&gt; f; f = a.Add; Console.WriteLine("Add: {0}", f(5)); f = a.Mul; Console.WriteLine("Mul: {0}", f(5)); } } </code></pre> <p>If you need the object it's called on to be unbound, like C++ member function pointers, I'm not sure that C# supports that. You can always use a lambda or delegate, though:</p> <pre><code>Func&lt;A,int,int&gt; f = delegate( A o, int i ) { return o.Add( i ); }; Console.WriteLine( "Add: {0}", f( a, 5 ) ); f = ( A o, int i ) =&gt; o.Mul( i ); Console.WriteLine( "Mul: {0}", f( a, 5 ) ); </code></pre>
<p>You might need to add more details. Delegates are a good option option, as is reflection if you only have the method name, not an actual pointer to it.</p>
27,623
<p>I need to create a site map/list, but I need the link-name to show up as well.</p> <p>What I mean by that is given, say, www.google.com, I need the following list to be created.</p> <pre><code>Google - www.google.com Images - http://images.google.com/imghp?hl=en&amp;tab=wi ... My Account - http://images.google.com/imghp?hl=en&amp;tab=wi Personal Information Edit - https://www.google.com/accounts/EditUserInfo ... My Products - https://www.google.com/accounts/EditServices ... Privacy - http://www.google.com/intl/en/privacy.html ... </code></pre> <p>The list needs to be bound to a domain, say us.example.com.</p> <p>I have tried a depth first search using a python script, with Beautiful Soup to parse the links. This was unsuccessful.</p> <p>Anybody have any ideas on how they would do it? </p>
<p>Use SQL Server Profiler - it can connect to Analysis Services... When you create a trace make sure you click "Show All Events" and capture the "Execute MDX" events.</p>
<p>I remember doing something along these lines a few years ago. I am not sure that Analysis Services will actually log the MDX it uses, but it does log something. I believe you can right-click the server properties in AS, and there is a tab to tell it a file to log queries to. </p> <p>(Sorry I cant be more specific, it was a fair while ago, and I havent got AS in front of me nowadays!)</p>
39,286
<p>We have YouTube videos on a site and want to detect if it is likely that they will not be able to view them due to (mostly likely) company policy or otherwise.</p> <p>We have two sites:</p> <p>1) Flex / Flash 2) HTML</p> <p>I think with Flex I can attempt to download <a href="http://youtube.com/crossdomain.xml" rel="noreferrer">http://youtube.com/crossdomain.xml</a> and if it is valid XML assume the site is available</p> <p>But with HTML I don't know how to do it. I can't even think of a 'nice hack'.</p>
<p>I like lacker's solution, but yes, it creates a <a href="http://en.wikipedia.org/wiki/Race_condition" rel="noreferrer" title="Race Condition on Wikipedia">race condition</a>. This will work and won't create a race contition:</p> <pre><code>var image = new Image(); image.onload = function(){ // The user can access youtube }; image.onerror = function(){ // The user can't access youtube }; image.src = "http://youtube.com/favicon.ico"; </code></pre>
<p>This worked for me... Its also my first post, hope it helps some one too.</p> <pre><code>&lt;?php $v = file_get_contents("https://www.youtube.com/iframe_api"); //Tie counts to a variable $test = substr_count($v, 'loading'); if ($test &gt; 0) { ?&gt; &lt;iframe&gt;YOUTUBE VIDEO GOES HERE&lt;/iframe&gt; &lt;?php } else { echo "&lt;br/&gt; no connection"; } ?&gt; </code></pre>
36,333
<p>I've been trying to submit a form with the FormPanel using the Action class Ext defaults to. However, I'd like it to consider the response as a script, not JSON-encoded.</p> <p>Has anyone had any experience on this?</p>
<p>The best plan would be to create a custom action by extending <code>Ext.form.Action</code>.</p> <p>You can then <code>eval</code> the <code>response</code> object or the <code>result</code> object in the <code>success</code> callback of your custom action.</p> <p>Your custom action can be called from <code>Ext.form.BasicForm</code> in the usual way.</p>
<p>using <code>Form.getForm().submit()</code> as your action response call works great and will automatically submit your form values to your backend as well as any custom values you would want to supply. On the return response you are passed a response object, which could be anything you want. So you could easily eval the return in the success handler.<br /><br /> There are also overrides to add this functionality into a normal <code>Ext.ajax.request</code> seen <a href="http://extjs.com/forum/showthread.php?t=17691" rel="nofollow noreferrer">here</a>. There also exists <code>Ext.data.ScriptTagProxy</code> which does the same thing but for cross domain script tags.</p>
18,284
<p><strong>I am very, very new to MYSQL.I tried to create a table named "option".</strong> <strong>My SQL Query is :</strong></p> <p>create table option( </p> <p>id int not null primary key auto_increment,</p> <p>choice varchar(30)</p> <p>)</p> <p><strong>While executing this query it shows the following error</strong></p> <p>Error Code : 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'option( id int not null primary key auto_increment, choice varchar(30) )' at line 1 (0 ms taken)</p> <p><strong>If I try with the table name as "choice" it is working.</strong></p> <p><strong>can we have the table name as "option" in mysql?</strong> </p> <p>thanks</p>
<p>Pick a different name (one that isn't a reserved word in your RDBMS) and save yourself and whoever else might work on it many headaches. </p>
<p><strong>option</strong> is a <a href="http://dev.mysql.com/doc/mysqld-version-reference/en/mysqld-version-reference-reservedwords-5-0.html" rel="nofollow noreferrer">reserved word</a> in MySQL. Save yourself a world of pain and use <strong>choice</strong> for your table name.</p>
42,482
<p>Is there any point to freeing memory in an atexit() function?</p> <p>I have a global variable that gets malloc'ed after startup. I could write an atexit() function to free it, but isn't the system going to reclaim all that memory when the program exits anyway?</p> <p>Is there any benefit to being tidy and actively cleaning it up myself?</p>
<p>Not in C - it's like rearranging the deck chairs while the ship sinks around you.</p> <p>In C++ the answer is different, because objects can delete temporary files and so forth in their destructors, so you need to make sure those get called.</p>
<p>not freeing memory before process termination isn't a memory leak. it's a memory leak when you lose a handle to it. but memory is not the only type of resource, and other resources persist across processes (like window handles and file handles), so you do need to 'free' those.</p>
28,602
<p>Is it possble to have something like this in ASP.NET MVC...</p> <pre><code>[Authorize] [AcceptVerbs(HttpVerbs.Get)] public string AddData(string Issues, string LabelGUID) { return "Authorized"; } [AcceptVerbs(HttpVerbs.Get)] public string AddData() { return "Not Authorized"; } </code></pre> <p>So if the user is not logged in, it defaults to the un-Authorized action.</p>
<p>Yes, its possible. You would need to create your own <code>ControllerActionInvoker</code> and override the <code>FindActionMethod</code> member. I'd let the base class do it's work and then check to see if the method it returns satisfies your criteria and if not, return a better match.</p> <p>I'm doing something like this to allow my Controllers to have a "Default Action" and it works well. Check out MvcContrib and their implementation of their ActionInvoker for a really nice example.</p>
<p>I don't believe so. The controller action with the best parameter match will get selected and then the attributes will be applied.</p> <p>You could use</p> <pre><code>if (Request.IsAuthenticated) { return "Authorized"; } else { return "Not Authorized"; } </code></pre> <p>Under the hood [Authorize] is essentially doing the same thing</p> <pre><code>protected virtual bool AuthorizeCore(IPrincipal user) { if (user == null) { throw new ArgumentNullException("user"); } if (!user.Identity.IsAuthenticated) { return false; } ...snip... } </code></pre>
42,701
<p>Quick thing: Please tell me if I misuse any of the terminology</p> <p>On a replicator+, I have been printing successfully for a while, when suddenly the raft started to warp. I was doing a bunch of models that covered the whole tray, so I shrunk to just a small area, but It still warped I read up on how to fix, but most covered how to fix warping in the model itself, not the rafting. Some said to lower the temp, would that work? smart extruder at default settings, 215 C. The printer does not have a heated base, nor have I treated it with anything, and I am using it with the stock program (makerbot print). Otherwise, I am using it as it came out of the box.</p> <p><a href="https://i.stack.imgur.com/1k0PE.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1k0PE.jpg" alt="bad"></a></p>
<p>I'm not sure I am reading your post correctly, but if you are doing a batch of small prints, I would recommend to <strong>space them enough so as each of them has its own mini-raft, rather than all of them sharing the same large one</strong>.</p> <p>If you are using cura, you can tweak how much the raft goes past the footprint of the part. Unless you are printing <em>very</em> small parts, you don't need that to be a lot.</p> <p>In general, <strong>you should think to a raft as a print in and by itself: the larger it is, the more prone to warping,</strong> although the way filament is layered with gaps makes the raft bend and warp a lot less than a regular print of the same size.</p>
<p>Lowering the raft temp to 200 degrees C should help. You should also apply hairspray and purple gluestick to your entire printed to help with raft adhesion to the bed.</p>
821
<p>I am forced to use VSS at work, but use SVN for a personal repository. What is the best way to sync between VSS and sync?</p>
<p>To get rid of the manual merge step, I could use a separate svn branch (svn://branches/VSS) as follows:</p> <ol> <li>Create a working copy of svn://branches/VSS</li> <li>Do a VSS Get Latest on this working copy</li> <li>svn commit</li> <li>svn merge from svn://trunk</li> <li>svn commit</li> <li>Do a VSS diff and checkout all files (without overwriting) with differences</li> <li>Check in those files</li> <li>reintegrate svn://branches/VSS into svn://trunk</li> </ol>
<p>What I have done in the past is as follows:</p> <ol> <li>Make sure all my changes are committed to svn://trunk</li> <li>Do a get latest from VSS into my working copy.</li> <li>Manually merge the changes in my working copy.</li> <li>Commit the merged code into the svn://trunk</li> <li>Do a VSS diff and checkout any files with differences (without overwriting files)</li> <li>Check in those files.</li> </ol>
8,156
<p>In C and C++ a variable can be marked as <a href="http://en.wikipedia.org/wiki/Volatile_variable" rel="noreferrer"><strong>volatile</strong></a>, which means the compiler will not optimize it because it may be modified external to the declaring object. Is there an equivalent in Delphi programming? If not a keyword, maybe a work around?</p> <p>My thought was to use <strong>Absolute</strong>, but I wasn't sure, and that may introduce other side effects.</p>
<p>Short answer: no.</p> <p>However, I am not aware of any situation in which the conservative approach of the compiler will change the number of reads or writes if you follow this approach:</p> <p>When reading a cross-thread visible location, save its value to a local before doing any further manipulation; similarly, restrict writes to a single assignment.</p> <p>The Delphi compiler does not perform common subexpression elimination (CSE) on non-local location expressions when there are calls to non-inlined methods between the expressions, as the compiler doesn't do interprocedural optimization and thus it would not be correct even for single-threaded code.</p> <p>So, you may want to use InterlockedExchange() to do your reads and writes to force this; additionally, this will cause a full memory barrier, so the processor won't reorder reads and writes either.</p>
<p>Use dynamically allocated pointers?</p> <pre><code>var MyVarPtr: ^integer; begin New(MyVarPtr); MyVarPtr^ := 5; ... </code></pre> <p>This should keep the compiler from using a register for the integer value (but it might still use one for the address). I am not sure how that compares to volatile, though.</p>
28,726
<p>We all know that commenting our code is an important part of coding style for making our code understandable to the next person who comes along, or even ourselves in 6 months or so.</p> <p>However, sometimes a comment just doesn't cut the mustard. I'm not talking about obvious jokes or vented frustraton, I'm talking about comments that appear to be making an attempt at explanation, but do it so poorly they might as well not be there. Comments that are <strong>too short</strong>, are <strong>too cryptic</strong>, or are <strong>just plain wrong</strong>. </p> <p>As a cautonary tale, could you share something you've seen that was really just <strong>that bad</strong>, and if it's not obvious, show the code it was referring to and point out what's wrong with it? What <strong>should</strong> have gone in there instead?</p> <p>See also: </p> <ul> <li><a href="https://stackoverflow.com/questions/163600/when-not-to-comment-code">When NOT to comment your code</a></li> <li><a href="https://stackoverflow.com/questions/121945/how-do-you-like-your-comments-best-practices">How do you like your comments? (Best Practices)</a></li> <li><a href="https://stackoverflow.com/questions/184618/what-is-the-best-comment-in-source-code-you-have-ever-encountered">What is the best comment in source code you have ever encountered?</a></li> </ul>
<p>Just the typical Comp Sci 101 type comments:</p> <pre><code>$i = 0; //set i to 0 $i++; //use sneaky trick to add 1 to i! if ($i==$j) { // I made sure to use == rather than = here to avoid a bug </code></pre> <p>That sort of thing.</p>
<p>I thought this was about the worst comment on a SO post, and was disappointed to find otherwise.</p>
17,320
<p>Very simply put, I have the following code snippet:</p> <pre><code>FILE* test = fopen("C:\\core.u", "w"); printf("Filepointer at: %d\n", ftell(test)); fwrite(data, size, 1, test); printf("Written: %d bytes.\n", size); fseek(test, 0, SEEK_END); printf("Filepointer is now at %d.\n", ftell(test)); fclose(test); </code></pre> <p>and it outputs:</p> <pre><code>Filepointer at: 0 Written: 73105 bytes. Filepointer is now at 74160. </code></pre> <p>Why is that? Why does the number of bytes written not match the file pointer?</p>
<p>Since you're opening the file in text mode, it will convert end-of-line markers, such as LF, into CR/LF.</p> <p>This is likely if you're running on Windows (and you probably are, given that your file name starts with <code>"c:\"</code>).</p> <p>If you open the file in <code>"wb"</code> mode, I suspect you'll find the numbers are identical:</p> <pre><code>FILE* test = fopen("C:\\core.u", "wb"); </code></pre> <p>The C99 standard has this to say in <code>7.19.5.3 The fopen function</code>:</p> <blockquote> <p>The argument mode points to a string. If the string is one of the following, the file is open in the indicated mode. Otherwise, the behaviour is undefined.</p> <p><code>r</code> open text file for reading<br> <code>w</code> truncate to zero length or create text file for writing<br> <code>a</code> append; open or create text file for writing at end-of-file<br> <code>rb</code> open binary file for reading<br> <code>wb</code> truncate to zero length or create binary file for writing<br> <code>ab</code> append; open or create binary file for writing at end-of-file<br> <code>r+</code> open text file for update (reading and writing)<br> <code>w+</code> truncate to zero length or create text file for update<br> <code>a+</code> append; open or create text file for update, writing at end-of-file<br> <code>r+b</code> or <code>rb+</code> open binary file for update (reading and writing)<br> <code>w+b</code> or <code>wb+</code> truncate to zero length or create binary file for update<br> <code>a+b</code> or <code>ab+</code> append; open or create binary file for update, writing at end-of-file</p> </blockquote> <p>You can see they distinguish between <code>w</code> and <code>wb</code>. I don't believe an implementation is <em>required</em> to treat the two differently but it's usually safer to use binary mode for binary data.</p>
<p>what does fwrite return? normally the return value should be the number of bytes written. Also, what does the ftell() answer with right before the fseek?</p> <p>It might help to know what operating system, C compiler version and C library.</p>
17,485
<p>In my child window I have </p> <pre><code>$('#opfile').addOption("someval",sometext"); </code></pre> <p>Problem is #opfile is an a parent window I cant get it to communicate</p> <p>I tried</p> <p>window.opener.$('#opfile').addOption("someval",sometext");</p> <p>but no luck any ideas?</p> <p>Update</p> <p>Embarssing but I got the above to work might have been caching something</p> <p>Thanks for the suggestions</p>
<p>This may be helpful.</p> <p><a href="http://www.sfpeter.com/2008/03/13/communication-between-browser-windows-with-jquery-my-new-plugin/" rel="nofollow noreferrer">Communication between browser windows</a></p> <p>Though this is not directly related to the select box example, but the concepts may be applied here.</p> <p>I'll watch this space, if anyone has a better solution.</p>
<p>try this by changing array in options</p> <p>window.opener.document.getElementById("opfile").options[0] = new Option("someval",sometext");</p>
44,207
<p>I am thinking about a DB Design Problem.</p> <p>For example, I am designing this stackoverflow website where I have a list of Questions.</p> <p>Each Question contains certain meta data that will probably not change. Each Question also contains certain data that will be consistently changing (Recently Viewed Date, Total Views...etc)</p> <p>Would it be better to have a Main Table for reading the constant meta data and doing a join and also keeping the changing values in a different table?</p> <p>OR</p> <p>Would it be better to keep everything all in one table.</p> <p>I am not sure if this is the case, but when updating, does the ROW lock?</p>
<p>When designing a database structure, it's best to <a href="http://en.wikipedia.org/wiki/Database_normalization" rel="nofollow noreferrer">normalize</a> first and change for performance after you've profiled and benchmarked your queries. Normalization aims to prevent data-duplication, increase integrity and define the correct relationships between your data.</p> <p>Bear in mind that performing the join comes at a cost as well, so it's hard to say if your idea would help any. Proper indexing with a normalized structure would be much more helpful.</p> <p>And regarding row-level locks, that depends on the storage engine - some use row-level locking and some use table-locks.</p>
<p>You should have the two table separated out as you might want to record the history of the question. The main Question table is indexed by question ID then the Status table is indexed by query ID and date/time stamp and contains a row for each time the status changes.</p> <p>Don't know that the updates are really significant unless you were using pessimistic locking where the row would be locked for a period of time.</p>
48,283
<p>I want to insert something into a STL list in C++, but I only have a reverse iterator. What is the usual way to accomplish this?</p> <p>This works: (of course it does)</p> <pre><code>std::list&lt;int&gt; l; std::list&lt;int&gt;::iterator forward = l.begin(); l.insert(forward, 5); </code></pre> <p>This doesn't work: (what should I do instead?)</p> <pre><code>std::list&lt;int&gt; l; std::list&lt;int&gt;::reverse_iterator reverse = l.rbegin(); l.insert(reverse, 10); </code></pre>
<p><code>l.insert(reverse.base(), 10);</code> will insert '10' at the end, given your definition of the 'reverse' iterator. Actually, <code>l.rbegin().base() == l.end()</code>. </p>
<p>Just in case it is helpful, as this it the first hit on a search, here is a working example of using <code>rbegin</code>. This should be faster than using <code>std::stringstream</code> or <code>sprint</code>. I defiantly call a member <code>fmt_currency</code> many thousands of times in some print jobs. The <code>std::isalnum</code> is for handling a minus sign.</p> <pre><code>std::wstring fmt_long(long val) {//for now, no options? Just insert commas std::wstring str(std::to_wstring(val)); std::size_t pos{ 0 }; for (auto r = rbegin(str) + 1; r != str.rend() &amp;&amp; std::isalnum(*r); ++r) { if (!(++pos % 3)) { r = std::make_reverse_iterator(str.insert(r.base(), L',')); } } return str; } </code></pre>
38,551
<p>When launching a process from Java, both stderr and stdout can block on output if I don't read from the pipes. Currently I have a thread that pro-actively reads from one and the main thread blocks on the other.</p> <p>Is there an easy way to join the two streams or otherwise cause the subprocess to continue while not losing the data in stderr? </p>
<p>Set the redirectErrorStream property on ProcessBuilder to send stderr output to stdout:</p> <pre><code>ProcessBuilder builder = new ProcessBuilder(command); builder.redirectErrorStream(true); </code></pre> <p>You should then create a thread to deal with the process stream, something like the following:</p> <pre><code>Process p = builder.start(); InputHandler outHandler = new InputHandler(p.getInputStream()); </code></pre> <p>Where InputHandler is defined as:</p> <pre><code>private static class InputHandler extends Thread { private final InputStream is; private final ByteArrayOutputStream os; public InputHandler(InputStream input) { this.is = input; this.os = new ByteArrayOutputStream(); } public void run() { try { int c; while ((c = is.read()) != -1) { os.write(c); } } catch (Throwable t) { throw new IllegalStateException(t); } } public String getOutput() { try { os.flush(); } catch (Throwable t) { throw new IllegalStateException(t); } return os.toString(); } } </code></pre> <p>Alternatively, just create two InputHandlers for the InputStream and ErrorStream. Knowing that the program will block if you don't read them is 90% of the battle :)</p>
<p>Just have two threads, one reading from stdout, one from stderr?</p>
8,946
<p>Method chaining is the only way I know to build fluent interfaces.</p> <p>Here's an example in C#:</p> <pre><code>John john = new JohnBuilder() .AddSmartCode(&quot;c#&quot;) .WithfluentInterface(&quot;Please&quot;) .ButHow(&quot;Dunno&quot;); Assert.IsNotNull(john); [Test] public void Should_Assign_Due_Date_With_7DayTermsVia_Invoice_Builder() { DateTime now = DateTime.Now; IInvoice invoice = new InvoiceBuilder() .IssuedOn(now) .WithInvoiceNumber(40) .WithPaymentTerms(PaymentTerms.SevenDays) .Generate(); Assert.IsTrue(invoice.DateDue == now.AddDays(7)); } </code></pre> <p>So how do others create fluent interfaces. How do you create it? What language/platform/technology is needed?</p>
<p>You can create a fluent interface in any version of .NET or any other language that is Object Oriented. All you need to do is create an object whose methods always return the object itself.</p> <p>For example in C#:</p> <pre><code>public class JohnBuilder { public JohnBuilder AddSmartCode(string s) { // do something return this; } public JohnBuilder WithfluentInterface(string s) { // do something return this; } public JohnBuilder ButHow(string s) { // do something return this; } } </code></pre> <p>Usage:</p> <pre><code>John = new JohnBuilder() .AddSmartCode("c#") .WithfluentInterface("Please") .ButHow("Dunno"); </code></pre>
<p>Dynamic keyword in C# 4.0 will make it possible to write dynamic style builders. Take a look at following <a href="http://www.nikhilk.net/CSharp-Dynamic-Programming-JSON.aspx" rel="nofollow noreferrer">article</a> about JSON object construction.</p>
37,441
<p>I thought I am not bad at Google, but simply I am unable to find a G-code for doing circular motion for nozzle cleaning. It is possible to write a simple circular motion in G-code?</p>
<p>To draw a circle, you need to approximate the circle as a sufficient number of line segments. This requires computing or using a table of sine and cosine values for each angle step. Then you just emit a sequence of <code>G1</code> commands.</p> <p>Some printer firmware also supports arc drawing commands you could use instead in principle, but support is not widespread, and the quality of the results varies enough that I would not recommend trying to do it this way.</p>
<p>While many 3D printers support using G2 and G3 for circles and arcs, most people are not used to them because the STL files consist entirely of flat triangles (straight lines).</p> <p>If you want a simple 2D circle, see the following for help:</p> <p><a href="https://marlinfw.org/docs/gcode/G002-G003.html" rel="nofollow noreferrer">https://marlinfw.org/docs/gcode/G002-G003.html</a></p> <p><a href="https://makezine.com/2016/10/24/get-to-know-your-cnc-how-to-read-g-code/" rel="nofollow noreferrer">https://makezine.com/2016/10/24/get-to-know-your-cnc-how-to-read-g-code/</a></p> <p><a href="https://reprap.org/wiki/G-code#G2_.26_G3:_Controlled_Arc_Move" rel="nofollow noreferrer">https://reprap.org/wiki/G-code#G2_.26_G3:_Controlled_Arc_Move</a></p> <p>Note: it can take a while to get used to the I and J parameters.</p>
2,056
<p>Is it possible (and if yes, how) to bypass DNS when doing a HTTP request ?</p> <p>I want to hit directly a front-end with an HTTP request, without getting through NLB but with the correct host header. As I have the IP of my server, I just need to bypass the DNS.</p> <p>I tried to use WebRequest, replacing the URL with the IP and setting the Host header, but this header is protected.</p> <p>How can I do that ? Do I need to create the HTTP request myself ?</p> <p>Note: editing host file is not an option</p>
<p>At the time this question was asked this was not possible to do with the WebRequest class. However following a Microsoft Connect issue raised as a result of this question, Microsoft Added the Host property to the HttpWebRequest class in .Net version 4.0. As such if you are using .net 4.0 or later you can achieve what you want with this code.</p> <pre><code>HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://127.0.0.1"); Request.Host = "www.example.com" </code></pre> <p>Prior to version 4 of .Net the only real option is to open a Socket and do the HTTP request yourself or find a 3rd Party component that has more functionality.</p>
<p>I had a similar problem myself, but managed to get around it using sockets (As mentioned by Martin Brown. Here is my answer: <a href="https://stackoverflow.com/questions/359041/request-web-page-in-c-spoofing-the-host#359299" title="My Answer">https://stackoverflow.com/questions/359041/request-web-page-in-c-spoofing-the-host#359299</a></p>
41,838
<p>I've been printing PLA on a Pegasus 12" for 2 years. Print quality has been great but in the last few months the quality of the prints has deteriorated. After looking into it, it seems when the head moves away from the spool and puts the filament in tension (and pulls on the spool) the extruder cog slips on the filament. That results in traces where no plastic gets extruded the furthest away the head moves from the spool (the spool is on the left in the picture below):</p> <p><a href="https://i.stack.imgur.com/0W9DA.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0W9DA.jpg" alt="See diagonal traces where plastic didn&#39;t extrude"></a></p> <p>The cog slipping can be seen between 0:22 and 0:27 on the video below: the cog on the right spins continuously but the ball bearing on the left stops spinning for 5 seconds. <a href="https://photos.app.goo.gl/cTfySUgXDy1XKXGv8" rel="nofollow noreferrer">https://photos.app.goo.gl/cTfySUgXDy1XKXGv8</a></p> <p>The end result is a part with multiple gaps, especially on the side farthest away from the spool.</p> <p><a href="https://i.stack.imgur.com/lX4eJ.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lX4eJ.jpg" alt="enter image description here"></a></p> <p>I've cleaned the teeth of the cog (removed plastic dust) to improve traction but that didn't solve the problem. I've also tried to clean up the extruder by inserting a wire from the hot end side, no improvement in print quality.</p> <p>Any ideas on how to fix that slipping problem?</p> <h1><strong>Edit with solution:</strong></h1> <p>To complement Oscar's answer below, here is what I've done that fixed the problem: it turns out the issue was coming from a lack of friction on the filament. To increase the friction, I've slipped a pair of 0.25mm thick pieces of plastic sheet between the bearing axis and the mount. See pic below.</p> <p><a href="https://i.stack.imgur.com/CXw36.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CXw36.jpg" alt="enter image description here"></a></p> <p>That increased the force on the filament enough to fully solve the slippage problem. The print quality is perfect now (see pic below).</p> <p><a href="https://i.stack.imgur.com/KqbYo.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KqbYo.jpg" alt="enter image description here"></a></p> <p>The plastic sheet trick is just a short term fix. I'm going to try swapping the drive gear for a slightly thicker one and contact MakerFarm to see if there is any long term modification they recommend.</p>
<p>The soldering in the Tevo components is very low quality as I replaced/resoldered most of the end-stops.</p> <p>As the gantry goes down - please ensure that the cable is not pulled over (no contact) and there is contact on the edge of the acrylic and the end-stop, also the small acrylic switch holder could bend/slip a bit. Finally, the sensor connection to the main board could be dragged by wires that are connected to the hot-end.</p> <p>To validate micro-switch behavior - lift the Z-axis (about 100mm), then set <code>home position</code> and manually trigger the end-stop switch. That shall lift the Z-axis, so then trigger again to see if that works. You will still have a plenty of time to stop the printer if the switch does not work.</p> <p>If that works, then the reason could be in slipping edge of the black acrylic plate and the micro-switch. Also validate the mechanical connection (if there is a loosening screw (the small on the switch plate)).</p>
<p>I'm not familiar with your particular model, so this may not be directly applicable.</p> <p>For many printer models, a swing thru thingiverse.com will find you a replacement z-stop switch mount that uses a threaded screw to set the z-height at which the microswitch fires. It may well be that you simply need to offset that height by a few mm to get your first layer to mate well with the print bed. </p> <p>Here are three examples, albeit for various models. <a href="https://www.thingiverse.com/thing:12488" rel="nofollow noreferrer">12488</a> , <a href="https://www.thingiverse.com/thing:1829747" rel="nofollow noreferrer">1829747</a> ,<br> <a href="https://www.thingiverse.com/thing:2856144" rel="nofollow noreferrer">2856144</a></p>
1,065
<p>I was wondering what is the best data structure to deal with a lot of moving objects(spheres, triangles, boxes, points, etc)? I'm trying to answer two questions, Nearest Neighbor and Collsion detection.</p> <p>I do realize that traditionally, data structures like R trees are used for nearest neighbor queries and Oct/Kd/BSP are used for collision detection problems dealing with static objects, or with very few moving objects.</p> <p>I'm just hoping that there is something else out there that is better.</p> <p>I appreciate all the help.</p>
<ol> <li><p>You can partition the scene in an octree and utilize scene coherence. Your moving object that you are testing is going to be in a specific node of the tree for a specific amount of frames depending on its speed. This means you can assume it will be in the node and therefore quickly cut out a lot of objects that are not in the node. Of course the tricky bit is when your object is close to the edge of your partition, you would have to make sure you update which node the object is in.</p></li> <li><p>A moving object has a direction and a speed. You can easily divide the scene in two sections by using a perpendicular division from your objects direction of movement. Any object on the wrong side of this division do not need to be checked. Of course compensate for the other object's velocity. So if the other object is reasonable slow, you can easily cut it out from further checks.</p></li> <li><p>Always simplify whatever shape you are testing with something like an axis aligned bounding box. An initial collision test </p></li> <li><p>You can take the distance between your object and another moving object plus the velocities. If the other moving object is moving in the same general direction at a faster velocity, you can eliminate it from your check.</p></li> <li><p>There are many other optimizations depending on the object's shape. Circles or squares or more complex shapes all have specific optimizations you can do while moving. </p></li> <li><p>Assuming some objects do stop or can stop moving, you can keep track of objects that stop. these objects can than be treated like static objects and therefore the checks are faster and you can apply all the static optimization techniques to them.</p></li> <li><p>I know of more but can't think of any off the top of my head. Haven't done this in a while.</p></li> </ol> <p>Now of course this depends on how you are doing the collision detection. Are you incrementally updating the object's position based on velocity and checking as though it is static. Or are you compensating for velocity by extruding the shape and figuring out initial collision points. The former needs a small step for fast moving object. The latter is more complicated and costly but gives better results. Also if you are going to have rotating objects then things get a little more tricky. </p>
<p>sweep and prune broad phase + gjk narrow phase</p>
29,167
<p>Depends on your experience could you recommend something? I've use <a href="http://izpack.org/" rel="noreferrer">izpack</a>, and it's very nice tool, is there any other, better tool? </p>
<p>In MS Windows <a href="http://nsis.sourceforge.net/Main_Page" rel="noreferrer">NSIS</a> is great and it's free &amp; OSS</p> <p>Ref: <a href="http://nsis.sourceforge.net/Java_Launcher_with_automatic_JRE_installation" rel="noreferrer">Java Launcher with automatic JRE installation</a></p>
<p>We are using IZPack for quit a while and are very satisfied. You can build installers for nearly all platforms and it integrates well with your build tools like maven.</p>
20,893
<pre><code>devenv mysolution.sln /build "Release|Win32" /project myproject </code></pre> <p>When building from the command line, it seems I have the option of doing a <code>/build</code> or <code>/rebuild</code>, but no way of saying I want to do "project only" (i.e. not build or rebuild the specified project's dependencies as well). Does anyone know of a way?</p>
<p>Depending on the structure of your build system, this may be what you're looking for:</p> <pre><code>msbuild /p:BuildProjectReferences=false project.proj </code></pre>
<p>Thanks for the answers. I see from a bit of looking into <code>msbuild</code> that it can deal with a <code>.sln</code> file rather than a <code>.vcproj</code>; can this be accomplished that way instead of having to know the location of the <code>.vcproj</code>?</p> <p>Let me take a step back. We have a big solution file and I want a script to do this:</p> <ol> <li>Do a <code>/build</code> on the whole solution.<br> (Sometimes some projects fail because <code>devenv</code> doesn't do quite as much building as necessary for the amount of change since the last build.)</li> <li>For each project that fails, do a <code>/rebuild</code> on it. </li> </ol> <p>When I get to step 2 all I know is the solution filename and the names (not filenames) of the projects that failed. I could easily <code>grep</code>/<code>awk</code>/whatever the <code>.sln</code> file to map from one to the other, but I'm curious if <code>msbuild</code> offers a way to do it directly.</p> <p>(Ideally I could give <code>msbuild</code> the <code>.sln</code> and the names of <em>all</em> the projects to rebuild in a single command line, as it's a large file and takes a while to load. If that's not possible then the option of manually finding all the project filenames is probably better as loading the solution file every time would be most inefficient.)</p>
15,038
<p>Anyone working on the Android ('gPhone') have or know of a place where I can find a good ORM tool for it? The code is written in Java, and the database is SQLite. What I would like to find is a tool that given the object definition, can auto-generate the tables and the CRUD functions (that would be awesome), or, barring that, a tool that can take the table definition, the object definition, and auto-generate the CRUD functionality. The rub is that all of this must happen within the Android framework, which has its own conventions as to how database access works.</p>
<p>Thought I'd just add my $0.02 here about my <a href="http://ormlite.com/" rel="nofollow noreferrer">ORMLite package</a>.</p> <p>It is a lightweight replacement to Hibernate and uses native Android OS database calls to support SQLite on Android. It also supports many other database types using JDBC on other architectures. We have an <a href="https://groups.google.com/forum/?fromgroups#!forum/ormlite-android" rel="nofollow noreferrer">Android mailing list</a> for ORMLite questions.</p>
<p>Had negative experience with db4o (v. 8): indexing didn't work properly (exception etc.). So I didn't managed how to avoid creating duplicates in foreign tables when having object in object structure. More detailed explanation in my <a href="https://stackoverflow.com/questions/7402127/restrict-child-duplicates-on-creating-object-in-db4o">question</a>. Hope one day it would be better.</p>
48,556
<p>I have tried following guides like <a href="http://docs.djangoproject.com/en/dev/howto/deployment/modpython/" rel="nofollow noreferrer">this one</a> but it just didnt work for me.</p> <p><strong>So my question is this:</strong> What is a good guide for deploying Django, and how do you deploy your Django.</p> <p>I keep hearing that capastrano is pretty nifty to use, but i have no idea as to how to work it or what it does (apart from automation of deploying code), or even if i want/need to use it or not.</p>
<p><code>mod_wsgi</code> in combination with a <code>virtualenv</code> for all the dependencies, a mercurial checkout into the virtualenv and a <code>fabric</code> recipe to check out the changes on the server.</p> <p>I wrote an article about my usual workflow: <a href="http://lucumr.pocoo.org/2008/7/17/deploying-python-web-applications/" rel="nofollow noreferrer">Deploying Python Web Applications</a>. Hope that helps.</p>
<p>The easiest way would be to use one of the sites on <a href="http://djangofriendly.com/hosts/" rel="nofollow noreferrer">http://djangofriendly.com/hosts/</a> that will provide the hosting and set up for you, but even if you're wanting to roll your own it will allow you to see what set up other sites are using.</p>
13,930
<p>I have a UIImageView and the objective is to scale it down proportionally by giving it either a height or width. </p> <pre><code>UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://farm4.static.flickr.com/3092/2915896504_a88b69c9de.jpg"]]]; UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; //Add image view [self.view addSubview:imageView]; //set contentMode to scale aspect to fit imageView.contentMode = UIViewContentModeScaleAspectFit; //change width of frame CGRect frame = imageView.frame; frame.size.width = 100; imageView.frame = frame; </code></pre> <p>The image did get resized but the position is not at the top left. What is the best approach to scaling image/imageView and how do I correct the position?</p>
<p>Fixed easily, once I found the documentation!</p> <pre><code> imageView.contentMode = .scaleAspectFit </code></pre>
<p>Here is how you can scale it easily.</p> <p>This works in 2.x with the Simulator and the iPhone.</p> <pre><code>UIImage *thumbnail = [originalImage _imageScaledToSize:CGSizeMake(40.0, 40.0) interpolationQuality:1]; </code></pre>
22,459
<p>I was noticing on a print I had just done that the quality was not up to typical snuff. I had just started using a roll of PLA filament that I had been keeping on a shelf without a wrapper for a couple months. How long can you store filament before it gets too hydrated from the air to print? I expected more than a couple months but perhaps I am wrong?</p>
<p>In <strong>theory</strong>, most filaments don't go bad within a year. However, praxis shows, that averse conditions can impact the filaments over time and age them to unusability.</p> <p>Among the damaging factors is heat, but most filaments also are hygroscopic and absorb water to some small degree, or even heavily like Nylon.</p> <p>As a result, it always a good idea to at least try to store filament dry. To enforce this, some use racks in a well-heated room, others are blessed with very dry weather overall. And on some locations, like the coast, you might even be forced to use dryboxes for each and every filament to try to slow the degradation of steady hot humid air leaching out the additions from the filament.</p> <p>Dryboxes can keep the filament reasonably isolated from the surrounding air and so prevent moisture interacting with them to some degree. It is also a good idea to store them out of direct sunlight, as UV light might destroy color and/or the plastic. More information on why to use them is for example at <a href="https://3dprinting.stackexchange.com/questions/6982/which-filaments-actually-do-need-to-be-stored-in-a-drybox?">this question</a></p> <p>A couple construction videos using an IKEA box and a bit of foam were offered by <a href="https://www.youtube.com/watch?v=OY5n9q-wS7k" rel="nofollow noreferrer">Tom (Thomas Sanladerer)</a> and <a href="https://www.youtube.com/watch?v=WEFtUKGAd7k" rel="nofollow noreferrer">CNC Kitchen (Stefan Hermann)</a> in 2017.</p> <p>But fear not: most filaments - PLA included - can be freshened up again if the damage is not to prolonged! Baking them at a low temperature or storing them in a dehumidifier has worked in some climates. For PLA, keep the temperature at below 80°C. A couple of hours should get some the moisture that has seeped in out again. The Quality might not get back to that of fresh filament in all cases, but you might at least regain reasonable to good printability.</p> <p><a href="https://3dsolved.com/filaments-and-moisture-absorption/" rel="nofollow noreferrer">Also note, that different filaments are differently affected.</a> ABS for example is a little less hygroscopic than PLA, while HIPS is one of the least hygroscopic filaments available.</p>
<p>To answer your question: it depends on the relative humidity. Generally, a few weeks in a semi-arid environment. But, it'll still print really well. If you're looking for really tight filament diameter tolerances, a week or even less could change the diameter .001 or more if there is moisture in the air. I've used PLA that has been exposed to air for a few months and it's been fine, but with small issues.</p> <p>If the filament has absorbed too much moisture, you'll typically hear popping coming from the hot extruder as the water is burned off at the nozzle. Sometimes steam comes out of the nozzle when printing as well with "wet" filament. Usually, you can still get great results even if it has absorbed moisture. If the filament diameter has been affected significantly, (if it jams, or the water keeps the plastic too cool when it's coming off the nozzle) you can dry it out in an oven for a few hours like @trish suggested. I keep my filaments in a plastic bag with desiccant inside a big storage bin. Probably overkill but my water softener is in the same room and introduces moisture to the air, and my a/c blows right at the setup.</p> <p>Dust is probably worse because it can accumulate much faster and cause jams.</p> <p>source and reading</p> <p><a href="https://www.fusion3design.com/the-importance-of-properly-storing-your-3d-printing-filament/" rel="nofollow noreferrer">https://www.fusion3design.com/the-importance-of-properly-storing-your-3d-printing-filament/</a></p>
1,103
<p>Is there any way to Write files to App_Data under medium trust hack?</p> <p>Im sure I've heard about some hack, is that true?</p>
<p>I don't think you are able to create new files, but you should be able to write to existing files in the App_Data folder. But I have honestly never experienced any problems with Medium Trust and writing to the App_Data folder. Are you sure it has the necessary permissions needed for writing files to the hard drive?</p>
<p>I don't think you are able to create new files, but you should be able to write to existing files in the App_Data folder. But I have honestly never experienced any problems with Medium Trust and writing to the App_Data folder. Are you sure it has the necessary permissions needed for writing files to the hard drive?</p>
5,245
<p>We're having a bit of fun here at work. It all started with one of the guys setting up a Hackintosh and we were wondering whether it was faster than a Windows Box of (nearly) same specs that we have. So we decided to write a little test for it. Just a simple Prime number calculator. It's written in Java and tells us the time it takes to calculate the first n Prime numbers.</p> <p>Optimised version below - now takes ~6.6secs</p> <pre><code>public class Primes { public static void main(String[] args) { int topPrime = 150000; int current = 2; int count = 0; int lastPrime = 2; long start = System.currentTimeMillis(); while (count &lt; topPrime) { boolean prime = true; int top = (int)Math.sqrt(current) + 1; for (int i = 2; i &lt; top; i++) { if (current % i == 0) { prime = false; break; } } if (prime) { count++; lastPrime = current; } if (current == 2) { current++; } else { current = current + 2; } } System.out.println("Last prime = " + lastPrime); System.out.println("Total time = " + (double)(System.currentTimeMillis() - start) / 1000); } } </code></pre> <p>We've pretty much lost the plot of the whole Hackintosh vs PC thing and are just having some fun with optimising it. First attempt with no optimisations (the above code has a couple) ran around 52.6min to find the first 150000 prime numbers. This optimisation is running around 47.2mins.</p> <p>If you want to have a go and post your results, then stick em up.</p> <p>Specs for the PC I'm running it on are Pentium D 2.8GHz, 2GB RAM, running Ubuntu 8.04.</p> <p><strong>Best Optimisation so far has been the square root of current, first mentioned by Jason Z.</strong></p>
<p>Well I see a couple of quick optimizations that can be done. First you don't have to try each number up to half of the current number.</p> <p>Instead you only have try up to the square root of the current number.</p> <p>And the other optimization was what BP said with a twist: Instead of</p> <pre><code>int count = 0; ... for (int i = 2; i &lt; top; i++) ... if (current == 2) current++; else current += 2; </code></pre> <p>use</p> <pre><code>int count = 1; ... for (int i = 3; i &lt; top; i += 2) ... current += 2; </code></pre> <p>This should speed things up quite a lot.</p> <p><strong>Edit:</strong><br> More optimization courtesy of Joe Pineda:<br> Remove the variable "top". </p> <pre><code>int count = 1; ... for (int i = 3; i*i &lt;= current; i += 2) ... current += 2; </code></pre> <p>If this optimization indeed increases speed is up to java.<br> Calculating the square root takes a lot of time compared to multiplying two numbers. However since we move the multiplication into the for loop this is done every single loop. So this COULD slow things down depending on how fast the square root algorithm in java is.</p>
<p>C#</p> <p>Enhancement to <a href="https://stackoverflow.com/questions/288200/prime-number-calculation-fun#288339">Aistina's code</a>:</p> <p>This makes use of the fact that all primes greater than 3 are of the form 6n + 1 or 6n - 1.</p> <p>This was about a 4-5% speed increase over incrementing by 1 for every pass through the loop.</p> <pre><code>class Program { static void Main(string[] args) { DateTime start = DateTime.Now; int count = 2; //once 2 and 3 int i = 5; while (count &lt; 150000) { if (IsPrime(i)) { count++; } i += 2; if (IsPrime(i)) { count++; } i += 4; } DateTime end = DateTime.Now; Console.WriteLine("Total time taken: " + (end - start).TotalSeconds.ToString() + " seconds"); Console.ReadLine(); } static bool IsPrime(int n) { //if (n &lt; 4) //return true; //if (n % 2 == 0) //return false; int s = (int)Math.Sqrt(n); for (int i = 2; i &lt;= s; i++) if (n % i == 0) return false; return true; } } </code></pre>
36,680
<p>I have an ASP.NET webforms application (3.5 SP1) that I'm working on, and attempting to enable gzip fpr HTML and CSS that comes down the pipe. I'm using <a href="http://www.stardeveloper.com/articles/display.html?article=2007110401&amp;page=1" rel="nofollow noreferrer">this implementation</a> (and tried a few others that hook into Application_BeginRequest), and it seems to be corrupting the external CSS file that the pages use, but intermittently...suddenly all styles will disappear on a page refresh, stay that way for awhile, and then suddenly start working again.</p> <p>Both IE7 and FF3 exhibit this behavior. When viewing the CSS using the web developer toolbar, it returns jibberish. The cache-control header is coming through as "private," but I don't know enough to figure out if that's a contributing factor or not.</p> <p>Also, this is running on the ASP.NET Development Server. Maybe it'd be fine with IIS, but I'm developing on XP and it'd be IIS5.</p>
<p>Is it only CSS files that get corrupted? Do JS files (or any other static text files) come through ok?</p> <p>Also can you duplicate the behavior if you browse directly to the CSS file?</p> <p>I've only enabled compression on Windows 2003 server's IIS using this approach:</p> <ol> <li>IIS → Web Sites → Properties → Service tab, check both boxes</li> <li>IIS → Web Service Extensions → Right click, Add New<pre> Name Http Compression Required Files %systemroot%\system32\inetsrv\gzip.dll </pre></li> <li>IIS → Right click top node, Internet Information Services, check <em>Enable Direct Metabase Edit</em></li> <li>Backup and Edit <code>%systemroot%\system32\inetsrv\MetaBase.xml</code> <ol> <li>Find <code>Location ="/LM/W3SVC/Filters/Compression/gzip"</code> <ul> <li>Add <code>png</code>, <code>css</code>, <code>js</code> and any other static file extensions to <code>HcFileExtensions</code></li> <li>Add <code>aspx</code> and any other executable extensions to <code>HcScriptFileExtensions</code></li> <li>Save </li> </ul></li> </ol></li> <li>Restart IIS (run <code>iisreset</code>) </li> </ol> <p>If you have a Windows 2003/2008 server to play with you could try that approach.</p>
<p>If you will be deploying on IIS 6 or IIS 7, just use the built-in IIS compression. We're using it on production sites for compressing HTML, CSS, and JavaScript with no errors. It also caches the compressed version on the server, so the compression hit is only taken once.</p>
4,255
<p>Are there any good professional associations for IT Managers that I could join and network with other managers to share ideas and information?</p>
<p><a href="http://www.computer.org/portal/site/ieeecs/index.jsp" rel="noreferrer">The IEEE Computer Society</a> and the <a href="http://www.aitp.org/" rel="noreferrer">Association of Information Technology Professionals</a>. Michigan has a few <a href="http://www.aitp.org/organization/chapters/chapters.jsp#Michigan" rel="noreferrer">chapters</a> in the AITP.</p>
<p><a href="http://www.linkedin.com/" rel="nofollow noreferrer">Linked</a> in have groups for informal networks.</p> <p>For something more serious or accredited: in Ireland there is the ICT, I'm sure there's something similar in Michigan or at the federal level in the US. Maybe like the ACM mentioned by Paul C.</p>
31,127
<p>How to run NAnt scripts in command line and get the timings of each task on the log file?</p> <pre><code>using nant &lt;record&gt; task or NAnt -buildfile:testscript.build testnanttarget </code></pre> <p>This produces console output but I can't see any timing information.</p> <p>All I want each log message prefixed with datatime.</p>
<p>You can use the <a href="http://nant.sourceforge.net/release/0.85-rc3/help/tasks/tstamp.html" rel="noreferrer">tstamp task</a> to display the current date/time. Just include it everywhere where you want timing information. It will not prefix each line with a timestamp, but at least you can time some strategic points.</p> <pre><code>&lt;tstamp /&gt; </code></pre>
<p>Here is a sample of tstamp</p> <p></p> <pre><code> &lt;echo&gt; ----------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------- TASK : INITIALIZE ----------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------- &lt;/echo&gt; &lt;loadtasks assembly="nantcontrib-0.85/bin/NAnt.Contrib.Tasks.dll" /&gt; &lt;!-- http://www.basilv.com/psd/blog/2007/how-to-add-logging-to-ant-builds --&gt; &lt;tstamp&gt; &lt;formatter property="timestamp" pattern="yyMMdd_HHmm"/&gt; &lt;/tstamp&gt; &lt;property name="build.log.filename" value="build_${timestamp}.log"/&gt; &lt;echo message="build.log.filename: ${build.log.filename}" /&gt; &lt;record name="${build.log.dir}/${build.log.filename}" action="Start" level="Verbose"/&gt; &lt;echo message="Build logged to ${build.log.filename}"/&gt; &lt;echo message="Build Start at: ${datetime::now()}" /&gt; &lt;/target&gt; </code></pre>
42,612
<p>How long can I expect a client/server TCP connection to last in the wild?</p> <p>I want it to stay permanently connected, but things happen, so the client will have to reconnect. At what point do I say that there's a problem in the code rather than there's a problem with some external equipment?</p>
<p>I agree with Zan Lynx. There's no guarantee, but you can keep a connection alive almost indefinitely by sending data over it, assuming there are no connectivity or bandwidth issues.</p> <p>Generally I've gone for the application level keep-alive approach, although this has usually because it's been in the client spec so I've had to do it. But just send some short piece of data every minute or two, to which you expect some sort of acknowledgement.</p> <p>Whether you count one failure to acknowledge as the connection having failed is up to you. Generally this is what I have done in the past, although there was a case I had wait for three failed responses in a row to drop the connection because the app at the other end of the connection was extremely flaky about responding to "are you there?" requests.</p> <p>If the connection fails, which at some point it probably will, even with machines on the same network, then just try to reestablish it. If that fails a set number of times then you have a problem. If your connection persistently fails after it's been connected for a while then again, you have a problem. Most likely in both cases it's probably some network issue, rather than your code, or maybe a problem with the TCP/IP stack on your machine (has been known: I encountered issues with this on an old version of QNX--it'd just randomly fall over). Having said that you might have a software problem, and the only way to know for sure is often to attach a debugger, or to get some logging in there. E.g. if you can always connect successfully, but after a time you stop getting ACKs, even after reconnect, then maybe your server is deadlocking, or getting stuck in a loop or something.</p> <p>What's really useful is to set up a series of long-running tests under a variety of load conditions, from just sending the keep alive are you there?/ack requests and responses, to absolutely battering the server. This will generally give you more confidence about your software components, and can be really useful in shaking out some really weird problems which won't necessarily cause a problem with your connection, although they might result in problems with the transactions taking place. For example, I was once writing a telecoms application server that provided services such as number translation, and we'd just leave it running for days at a time. The thing was that when Saturday came round, for the whole day, it would reject every call request that came in, which amounted to millions of calls, and we had no idea why. It turned out to be because of a single typo in some date conversion code that only caused a problem on Saturdays.</p> <p>Hope that helps.</p>
<p>Pick a value. One drop every hour is probably fine. Ten unexpected connection drops in 5 minutes probably indicates a problem.</p> <p>TCP connections will generally last about two hours without any traffic. Either end can send keep-alive packets, which are, I think, just an ACK on the last received packet. This can usually be set per socket or by default on every TCP connection.</p> <p>An application level keep-alive is also possible. For a telnet style protocol like FTP, SMTP, POP or IMAP something like sending return, newline and getting back a command prompt.</p>
19,194
<p>I'm looking for a little help on programmatically passing parameters to a SSRS report via VB.NET and ASP.NET. This seems like it should be a relatively simple thing to do, but I haven't had much luck finding help on this.</p> <p>Does anyone have any suggestions on where to go to get help with this, or perhaps even some sample code?</p> <p>Thanks.</p>
<p>You can do the following,: (it works both on local reports as in Full Blown SSRS reports. but in full mode, use the appropriate class, the parameter part remains the same)</p> <pre><code>LocalReport myReport = new LocalReport(); myReport.ReportPath = Server.MapPath("~/Path/To/Report.rdlc"); ReportParameter myParam = new ReportParameter("ParamName", "ParamValue"); myReport.SetParameters(new ReportParameter[] { myParam }); // more code here to render report </code></pre>
<p>It's been a while since I did this code, but it may help: Your web project has to be a Web Site, and not a project of type "ASP.Net Web Application", or you won't be able to add the reference mentioned below. Right click on the project and add an ASP.Net folder - App_WebReferences. You'll have to specify the server where your SRS is; choose the .asmx. Once it's added, the folder under that level is called RSService, and under that are 2 things: reportservice.discomap &amp; .wsdl. In my VB, I do Imports RSService and Imports System.Web.Services.Protocols, then...</p> <pre><code>Dim MyRS As New ReportingService </code></pre> <p>The reporting service is on a different server than the webserver the app is on, so I can't do the following: <code>MyRS.Credentials = System.Net.CredentialCache.DefaultCredentials</code></p> <p>Instead: <code>MyRS.Credentials = New System.Net.NetworkCredential(rs1, rs2, rs3)</code>, where the rs1/2/3 are the login to SRS box, password to SRS box, &amp; domain name". (These are encrypted in my web.config.)</p> <p>Then, a mass-paste:</p> <pre><code>MyRS.Credentials = New System.Net.NetworkCredential(rs1, rs2, rs3) Dim ReportByteArray As Byte() = Nothing Dim ReportPath As String = "/SRSSiteSubFolder/ReportNameWithoutRDLExtension" Dim ReportFormat As String = "PDF" Dim HistoryID As String = Nothing Dim DevInfo As String = "&lt;DeviceInfo&gt;&lt;Toolbar&gt;False&lt;/Toolbar&gt;&lt;/DeviceInfo&gt;" 'Dim x As ReportParameter - not necessary Dim ReportParams(0) As ParameterValue ReportParams(0) = New ParameterValue() ReportParams(0).Name = "TheParamName" ReportParams(0).Value = WhateverValue Dim Credentials As DataSourceCredentials() = Nothing Dim ShowHideToggle As String = Nothing Dim Encoding As String Dim MimeType As String Dim ReportHistoryParameters As ParameterValue() = Nothing Dim Warnings As Warning() = Nothing Dim StreamIDs As String() = Nothing 'Dim sh As New SessionHeader() - not necessary ''MyRS.SessionHeaderValue = sh - not necessary ReportByteArray = MyRS.Render(ReportPath, ReportFormat, HistoryID, DevInfo, ReportParams, Credentials, _ ShowHideToggle, Encoding, MimeType, ReportHistoryParameters, Warnings, StreamIDs) '(Yay! That line was giving "HTTP error 401 - Unauthorized", until I set the credentials ' as above, as explained by http://www.odetocode.com/Articles/216.aspx.) 'Write the contents of the report to a PDF file: Dim fs As FileStream = File.Create(FullReportPath, ReportByteArray.Length) fs.Write(ReportByteArray, 0, ReportByteArray.Length) fs.Close() Call EmailTheReport(FullReportPath) If IO.File.Exists(FullReportPath) Then IO.File.Delete(FullReportPath) End If </code></pre>
48,147
<p>I'm working with a SQL Server 2000 database that likely has a few dozen tables that are no longer accessed. I'd like to clear out the data that we no longer need to be maintaining, but I'm not sure how to identify which tables to remove.</p> <p>The database is shared by several different applications, so I can't be 100% confident that reviewing these will give me a complete list of the objects that are used.</p> <p>What I'd like to do, if it's possible, is to get a list of tables that haven't been accessed at all for some period of time. No reads, no writes. How should I approach this?</p>
<p>MSSQL2000 won't give you that kind of information. But a way you can identify what tables ARE used (and then deduce which ones are not) is to use the SQL Profiler, to save all the queries that go to a certain database. Configure the profiler to record the results to a new table, and then check the queries saved there to find all the tables (and views, sps, etc) that are used by your applications. </p> <p>Another way I think you might check if there's any "writes" is to add a new timestamp column to every table, and a trigger that updates that column every time there's an update or an insert. But keep in mind that if your apps do queries of the type </p> <pre><code>select * from ... </code></pre> <p>then they will receive a new column and that might cause you some problems. </p>
<p>If you have lastupdate columns you can check for the writes, there is really no easy way to check for reads. You could run profiler, save the trace to a table and check in there</p> <p>What I usually do is rename the table by prefixing it with an underscrore, when people start to scream I just rename it back</p>
5,552
<p>I have a multi-core server hosting my asp.net solution. In the past with dual-core, etc. you had to modify your app to NOT use in-proc session state, etc. Is this still the case if its a dual core?</p> <p>Also, does server cache play a part in this? I have had no issues with session, but when i try to clear the cache from code, it does not work, i have to do an iis reset to clear the cache. -- however, it does work locallay (i have a duo core) but not on the server (intel pentium D)</p> <p>Thank you.</p>
<p>In Process != In Processor. </p> <p>You should have no problem (except for the ones that session brings) using the in process model on a multi proc machine, because the process (aspnet_wp.exe or w3wp.exe) is able to execute on any or all of the processors. </p> <p><a href="http://msdn.microsoft.com/en-us/library/system.web.caching.cache_members.aspx" rel="nofollow noreferrer">The Http Cache?</a> should have items added and removed by key value. </p>
<p>you need to use an out of process cache client such as microsofts velocity which can handle both cache and session out of process. This will also scale out if you end up with more than one server.</p>
41,059
<p>I am writing a UDF for Excel 2007 which I want to pass a table to, and then reference parts of that table in the UDF. So, for instance my table called "Stock" may look something like this:</p> <blockquote> <p>Name &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Cost &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Items in Stock</p> <p>Teddy Bear &nbsp;&nbsp;&nbsp;£10&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;10</p> <p>Lollipops &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;20p&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1000</p> </blockquote> <p>I have a UDF which I want to calculate the total cost of all the items left in stock (the actual example is much more complex which can't really be done without very complex formula)</p> <p>Ideally the syntax of for the UDF would look something like</p> <pre><code>TOTALPRICE(Stock) </code></pre> <p>Which from what I can work out would mean the UDF would have the signature</p> <pre><code>Function TOTALPRICE(table As Range) As Variant </code></pre> <p>What I am having trouble with is how to reference the columns of the table and iterate through them. Ideally I'd like to be able to do it referencing the column headers (so something like table[Cost]).</p>
<p>This is very basic (no pun intended) but it will do what you describe. For larger tables it may become slow as under the hood it's going back and forth between the macro function and the worksheet, and that kind of activity adds up.</p> <p>It assumes that you have one row of headers and one column of names (hence the For loop variables starting from 2).</p> <p>There are all kinds of things that might be necessary - we can save those for another question or another round on this one.</p> <p>Note that the function returns a "Variant", btw...</p> <pre><code>Public Function TotalPrice(table As Range) As Variant Dim row As Long, col As Long Dim total As Double For row = 2 To table.Rows.Count For col = 2 To table.Columns.Count TotalPrice = TotalPrice + table.Cells(row, col) * table.Cells(row, col + 1) Next Next End Function </code></pre>
<p>Note: I dont have Excel 2007 and I am trying to write this using MSDN doc on the web.<br> Looks like the range will have ListColumns collection</p> <p>So, the syntax could be table.ListColumns("Cost").<br> Does this work?</p>
23,179
<p>I'm writing tests for a business method that invokes some DAO classes to perform operations over a database.</p> <p>This method, firstly retrieves a JDBC connection from a DataSource object, The same connection is passed to all DAO instances, so I can use it to control the transaction. So, if everything works properly, I must invoke commit() over the connection object.</p> <p>I would like to test if the commit() is invoked, so I've thought to create an expectation (I'm using JMock) that checks that. But since the Connection class isn't a direct neighbour from my Business class, I don't know how to do this.</p> <p>Someone knows how to overcome this? There is some JMock facility for this, or some alternative design that allows to overcome this?</p> <p>Thanks</p>
<p>You need to mock <code>DataSource</code> <em>and</em> <code>Connection</code> so that your mock <code>DataSource</code> returns your mock <code>Connection</code>. And yes, this kind of thing ends up becoming a real pain...</p>
<p>Make the bussines class retrieve the local variables from a global/static object factory. That way you could put the factory in test mode and make it return mock objects instead of real ones. </p> <p>That should make it. </p>
28,900
<p>The VS Database Project does not seem to have the "Show All Files" option in the Solution Explorer. Does anyone know of a way to turn the option on in VS?</p> <p>The "Show All Files" option on the solution explorer actually does two things. With the option selected, VS shows "hidden/nested" files within the project AND it shows files within the directory of the project that are not currently part of the project. (It shows the latter with a ghosted icon.)</p> <p>While DB projects may not have nested or hidden files within the project, there is no other way that I know of to have the solution explorer show files within the directory that are not part of the project.</p> <p>Also, while this action occurs within the solution explorer, it is actually a project issue.</p>
<p>The correct answer to this issue is:-</p> <p>You must have the Database Project root node selected in the Solution Explorer. </p> <p>Selecting any other node in the Solution Explorer other than the Database Project root node will cause the "Show All Files" button to become hidden.</p>
<p>it is by design. Some project types just don't allow you to. You might be able to go into the sln file in notepad and try something, but it might just screw up your solution.</p>
17,000
<p>Is there a way to use a Graphics object's 'setClip()' method to clip using a Line-ish shape? Right now I'm trying to use a Polygon shape but I'm having problems simulating the "width" of the line. I basically draw the line, and when I reach the end, I redraw it but this time subtract the line width from y-coordinate:</p> <pre><code>Polygon poly = new Polygon(); for(int i = 0; i &lt; points.length; i++) poly.addPoint(points.[i].x, points.[i].y); // Retrace line to add 'width' for(int i = points.length - 1; i &gt;=0; i--) poly.addPoint(points[i].x, points[i].y - lineHeight); </code></pre> <p>It almost works but the width of the line varies based upon its slope. </p> <p>I can't use the BrushStroke and drawLine() methods because the line can change color once it passes some arbitrary reference line. Is there some implementation of Shape that I overlooked, or an easy one I can create, that will let me do this more easily?</p>
<p>If there is a better way, I've never run across it. The best I can think of is to use some trigonometry to make the line width more consistent.</p>
<p>Maybe you could use a Stroke.createClippedShape to do this? (May need to use an Area to add subtract the stroked shape from/to your original shape depending on what exactly you are trying to do.</p>
21,214
<p>It is generally accepted that the use of cursors in stored procedures should be avoided where possible (replaced with set based logic etc). If you take the cases where you need to iterate over some data, and can do in a read only manner, are fast forward (read only forward) cursor more or less inefficient than say while loops? From my investigations it looks as though the cursor option is generally faster and uses less reads and cpu time. I haven't done any extensive testing, but is this what others find? Do cursors of this type (fast forward) carry additional overhead or resource that could be expensive that I don't know about.</p> <p>Is all the talk about not using cursors really about avoiding the use of cursors when set-based approaches are available, and the use of updatable cursors etc.</p>
<p>While a fast forward cursor does have some optimizations in Sql Server 2005, it is <em>not</em> true that they are anywhere close to a set based query in terms of performance. There are very few situations where cursor logic cannot be replaced by a set-based query. Cursors will always be inherently slower, due in part to the fact that you have to keep interrupting the execution in order to fill your local variables.</p> <p>Here are few references, which would only be the tip of the iceberg if you research this issue: </p> <p><a href="http://www.code-magazine.com/Article.aspx?quickid=060113" rel="nofollow noreferrer">http://www.code-magazine.com/Article.aspx?quickid=060113</a></p> <p><a href="http://dataeducation.com/re-inventing-the-recursive-cte/" rel="nofollow noreferrer">http://dataeducation.com/re-inventing-the-recursive-cte/</a></p>
<p>The 'Best Practice' of avoiding cursors in SQL Server dates back to SQL Server 2000 and earlier versions. The rewrite of the engine in SQL 2005 addressed most of the issues related to the problems of cursors, particularly with the introduction of the fast forward option. Cursors are not neccessarily worse than set-based and are used extensively and successfully in Oracle PL/SQL (LOOP).</p> <p>The 'generally accepted' that you refer to <strong>was</strong> valid, but is now outdated and incorrect - go on the assumption that fast forward cursors behave as advertised and perform. Do some tests and research, basing your findings on SQL2005 and later</p>
5,765
<p>We are in the process of upgrading our projects from C# 2.0 / VS2005 to C# 3.0 / VS2008. As part of the upgrade, we are adding some items to our coding standards document.</p> <p>How would (or did) you change your coding standards document when upgrading from C# 2.0 / VS2005 to C# 3.0 / VS2008?</p>
<p>You could/should give advice about:</p> <ul> <li>When to use query expressions vs dot notation</li> <li>Any restrictions on the use of lambda expressions (e.g. "don't modify captured variables). (This could also apply to anonymous methods in C# 2 of course.)</li> <li>When to write extension methods</li> <li>When to use implicitly typed variables (<code>var</code>)</li> </ul> <p>The last two of these cause some controversy, particularly <code>var</code>.</p> <p>If your conventions give any design guidelines, I'd suggest that you also advise programmers to consider using delegates for specialisation where previously they might have used inheritance or interfaces. A good example of this is sorting - it's easier (and more readable) to use a projection to specify a sort order than to write an implementation of <code>IComparer&lt;T&gt;</code>.</p>
<p>My standards for new features for 2008:</p> <ul> <li>Use var sparingly only with anonymous types.</li> <li>Encourage use of lambda expressions over delegates.</li> <li>Only use extension methods when you don't have control of the source code</li> </ul>
44,154
<p>I miss it so much (used it a lot in C#). can you do it in C++?</p>
<p>Yes, you can. See <a href="http://msdn.microsoft.com/en-us/library/b6xkz944(VS.80).aspx" rel="noreferrer">here</a>.</p> <pre><code>#pragma region Region_Name //Your content. #pragma endregion Region_Name </code></pre>
<p>The Visual assist add-in for VC supports regions for c++. Don't know if 2008 has build in regions for C++ though. </p>
17,815
<p>The number of products out there right now still seems to be slim.</p>
<p><a href="http://www.sqlis.com/post/Row-Number-Transformation.aspx" rel="nofollow noreferrer">Konesans Row Number Transformation</a></p>
<p>I've had good success using <a href="http://www.sqlbi.com/Projects/TableDifference/tabid/74/language/en-US/Default.aspx" rel="nofollow noreferrer">TableDifference</a> for data warehousing scenarios.</p>
33,829
<p>I noticed methods marked optional in several protocols defined in the iPhone SDK, such as the <code>UIActionSheetDelegate</code> protocol for example.</p> <p>How can I define a protocol of my own, and set a few of the methods as optional?</p>
<p>From the Apple page on "<a href="https://developer.apple.com/library/ios/documentation/cocoa/conceptual/ProgrammingWithObjectiveC/WorkingwithProtocols/WorkingwithProtocols.html" rel="noreferrer">Formal Protocols</a>":</p> <blockquote> <p>Optional Protocol methods can be marked as optional using the @optional keyword. Corresponding to the @optional modal keyword, there is a @required keyword to formally denote the semantics of the default behavior. You can use @optional and @required to partition your protocol into sections as you see fit. If you do not specify any keyword, the default is @required.</p> </blockquote> <pre><code>@protocol MyProtocol - (void)requiredMethod; @optional - (void)anOptionalMethod; - (void)anotherOptionalMethod; @required - (void)anotherRequiredMethod; @end </code></pre>
<p>Protocols act the same as abstract classes, so the @optional keyword defines those methods that are optional for implementation.</p> <p>So, in the code, someMethod1, someMethod2 and someMethod4 are required methods (must be implemented). someMethod3 is optional - if we didn't implement this method, the compiler will not throw any warnings. </p> <pre><code>@protocol myPrtocol&lt;NSObject&gt; -(void)someMethod1:(id)someArgument; -(void)someMethod2:(id)someArugument; @optional -(void)someMethod3:(id)someArgument; @required //by default -(void)someMethod4:(id)someArgument; @end // sampleClass.m @interface sampleClass : someSuperClass &lt;myProtocol&gt; //... @end </code></pre>
41,746
<p>I will have around 200,000 images as part of my website. Each image will be stored 3 times: full size, thumbnail, larger thumbnail. Full size images are around 50Kb to 500Kb.</p> <p>Normal tech: Linux, Apache, MySQL, PHP on a VPS.</p> <p>What is the optimum way to store these for fast retrieval and display via a browser??</p> <p>Should I store everything in a single folder? Should I store the full size images in 1 folder, the thumbails in another etc? Should I store the images in folders of 1000, and keep an index to which folder the image is in?</p> <p>Thanks for any advice. Albert.</p>
<p>I'd use a split directory structure, three or four levels deep, the idea being split all the files evenly across many directories, to enable mainly easy maintenance and fast access.</p> <p>How to do it? There are various alternatives:</p> <ul> <li>Taking the first characters of the images names</li> <li>Taking the first characters of a hash of the name</li> <li>Taking the last numbers of the seconds since 1970 of the date the picture was added</li> <li>Taking the last characters of the images' id in a database (if that exists)</li> </ul> <p>Let's suppose we have IMG8993_full.jpg, IMG8993_thumb.jpg, IMG8993_smallthumb.jpg</p> <p>Then we could have, for example:</p> <pre><code>/images/I/M/G/8/IMG8993: IMG8993_full.jpg IMG8993_thumb.jpg IMG8993_smallthumb.jpg </code></pre>
<p>Depends on how you're indexing them, for how to retrieve them.</p> <p>There's nothing particularly against storing them all in a single folder, but it becomes difficult to manage. If you're storing them by filename, and the filenames are reasonably normally distributed, you might want to have subfolders separated by first letter of the name, etc. If you're indexing by date added, you may want to segregate them by that.</p> <p>As far as I know, there's no "faster" or "slower" way to store the images for browser retrieval.</p>
40,721
<p>I'm wondering what the best way is to have a "if all else fails catch it".</p> <p>I mean, you're handling as much exceptions as possible in your application, but still there are bound to be bugs, so I need to have something that catches all unhandled exceptions so I can collect information and store them in a database or submit them to a web service.</p> <p>Does the AppDomain.CurrentDomain.UnhandledException event capture everything? Even if the application is multithreaded?</p> <p>Side note: Windows Vista exposes native API functions that allow any application to recover itself after a crash... can't think of the name now... but I'd rather not use it, as many of our users are still using Windows XP.</p>
<p>I have just played with AppDomain's UnhandledException behavior, (this is the last stage the unhandled exception is registered at)</p> <p>Yes, after processing the event handlers your application will be terminated and the nasty "... program stopped working dialog" shown.</p> <p>:) You <em>still</em> can avoid that.</p> <p>Check out:</p> <pre><code>class Program { void Run() { AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); Console.WriteLine("Press enter to exit."); do { (new Thread(delegate() { throw new ArgumentException("ha-ha"); })).Start(); } while (Console.ReadLine().Trim().ToLowerInvariant() == "x"); Console.WriteLine("last good-bye"); } int r = 0; void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { Interlocked.Increment(ref r); Console.WriteLine("handled. {0}", r); Console.WriteLine("Terminating " + e.IsTerminating.ToString()); Thread.CurrentThread.IsBackground = true; Thread.CurrentThread.Name = "Dead thread"; while (true) Thread.Sleep(TimeSpan.FromHours(1)); //Process.GetCurrentProcess().Kill(); } static void Main(string[] args) { Console.WriteLine("..."); (new Program()).Run(); } } </code></pre> <p><strong>P.S.</strong> Do handle the unhandled for Application.ThreadException (WinForms) or DispatcherUnhandledException (WPF) at the higher level.</p>
<p>I am using the following approach, which works and reduces greatly the amount of code ( yet I am not sure if there is a better way or what the pitfalls of it might be. Whenever you call: I quess the quys giving minuses would be polite enough to clarify their actions ; )</p> <pre><code>try { CallTheCodeThatMightThrowException() } catch (Exception ex) { System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace (); Utils.ErrorHandler.Trap ( ref objUser, st, ex ); } //eof catch </code></pre> <p>And here is the ErrorHandler code : Just to make clear- : objUser - is the object modelling the appusers ( you might get info such as domain name , department , region etc. for logging purposes ILog logger - is the logging object - e.g. the one performing the logging activities StackTrace st - the StackTrace object giving you debugging info for your app</p> <pre><code>using System; using log4net; //or another logging platform namespace GenApp.Utils { public class ErrorHandler { public static void Trap ( Bo.User objUser, ILog logger, System.Diagnostics.StackTrace st, Exception ex ) { if (ex is NullReferenceException) { //do stuff for this ex type } //eof if if (ex is System.InvalidOperationException) { //do stuff for this ex type } //eof if if (ex is System.IndexOutOfRangeException) { //do stuff for this ex type } //eof if if (ex is System.Data.SqlClient.SqlException) { //do stuff for this ex type } //eof if if (ex is System.FormatException) { //do stuff for this ex type } //eof if if (ex is Exception) { //do stuff for this ex type } //eof catch } //eof method }//eof class } //eof namesp </code></pre>
27,036
<p>If I update an Assembly that holds a workflow, I have to restart the appropriate Windows Process to pick up the new Assemblies.</p> <p>For Web parts &amp; stuff, this is just the IIS Application Pool in question (iisapp /r), and for Timer Jobs it is OWSTIMER.exe (net stop/start SPTimerV3)</p> <p>But who runs the workflows? Are they ran within IIS' Application Pool and are restarted when I restart the Application Pool with iisapp /r? If yes, which AppPool to restart, if I have one for the Site (:80) and one for the Central Admin (:49173)?</p> <p><strong>Edit:</strong> Following the answers, I've managed to attach the debugger to the server, and at least Workflows that are Scope="Site" in the feature.xml indeed run in the w3wp.exe of the Application Pool. I have not tested farm-level workflows though.</p>
<p>The hierarchy is like this:</p> <ul> <li>Application Pool</li> <li>Web Application</li> <li>Site Collection</li> <li>Site</li> </ul> <p>The workflows for a certain SharePoint web application run in the worker process set up for the application pool that is hosting that particular web application. </p> <p>Central Administration has typically has its own AppPool, so in your case you need to restart the AppPool for the Site (:80).</p>
<p>Sharepoint workflows runs on <strong>OWSTIMER</strong> process</p>
48,577
<p>I have not been able to print smooth and round shapes using Cura 3.3.1 (or earlier) without bumps. I think they are seams? The filament is PLA.</p> <p>Combing is enabled, which I thought makes it so that the nozzle travels over already printed areas, instead of flying over the air...<em>right</em>?</p> <p>I have been able to keep the seems hidden for the most part when there are sharp corners. <em>Sometimes</em> cura hides the seems properly...sometimes it doesn't. </p> <p>Here is an example shape I have tried printing with several different settings:</p> <p><a href="https://i.stack.imgur.com/NrinP.png" rel="noreferrer"><img src="https://i.stack.imgur.com/NrinP.png" alt="Cura printed object"></a></p> <p>The object above was printed using "random" seam corner preference. If I had chosen "sharpest corner", the bumps would all just stack up in one place, but still stick out.</p> <p><a href="https://i.stack.imgur.com/NuTiI.png" rel="noreferrer"><img src="https://i.stack.imgur.com/NuTiI.png" alt="Cura shape"></a></p> <p><a href="https://i.stack.imgur.com/JPmd3.png" rel="noreferrer"><img src="https://i.stack.imgur.com/JPmd3.png" alt="Cura settings 1"></a> <a href="https://i.stack.imgur.com/a5T3w.png" rel="noreferrer"><img src="https://i.stack.imgur.com/a5T3w.png" alt="Cura settings 2"></a></p> <p><a href="https://i.stack.imgur.com/ygxYP.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ygxYP.png" alt="Cura Settings 3"></a> <a href="https://i.stack.imgur.com/Jvuy1.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Jvuy1.png" alt="Cura settings 4"></a></p> <p>Just look at the travel lines below! Why is it jumping all over the place?</p> <p><a href="https://i.stack.imgur.com/73rsT.png" rel="noreferrer"><img src="https://i.stack.imgur.com/73rsT.png" alt="Cura travel lines"></a></p> <p><a href="https://i.stack.imgur.com/gu0TJ.png" rel="noreferrer"><img src="https://i.stack.imgur.com/gu0TJ.png" alt="Cura travel lines single layer"></a></p> <p>I have tried "Avoid printed parts when traveling" enabled and disabled, doesn't seem to make much difference.</p> <p>I feel that there should be a configuration that results in the nozzle not jumping through the air like that, but I can't find it. Perhaps that's not related to the bumps?</p> <p>The printer is a MonoPrice Mini Delta.</p>
<p>Following on from Toon's answer, here is a run down of <a href="https://www.youtube.com/channel/UCb8Rde3uRL1ohROUVg46h1A" rel="nofollow noreferrer">Thomas Sanladerer</a>'s excellent video: <a href="https://www.youtube.com/watch?v=Mbn1ckR86Z8" rel="nofollow noreferrer">3D printing guides: Calibration and why you might be doing it wrong</a>.</p> <p><em>However, this may not be a definitive answer to the actual question about warts and bumps...</em></p> <hr> <p><strong><a href="https://www.youtube.com/watch?v=Mbn1ckR86Z8&amp;t=8" rel="nofollow noreferrer">0:08 - A step back</a></strong></p> <p>Back in time - when the RepRap project (and the hobby grade 3D printing market) was new territory - it was seen to be a <em>doable</em> technology, with no restrictions imposed by patents. The new printers created and developed included Darwin, Sells Mendel and Prusa Mendel. These often produced unusable parts.</p> <p>However, impromptu solutions, or kludges led to poor quality fixes giving poor quality prints, by today's standards. However, people (today) believe that because they worked back then,. that they must still be valid solutions today. However this is not necessarily the case. </p> <p>The common misconception is that it is necessary to calibrate the esteps per mm for all axes other than extruder - adjusting the x, y and z esteps per mm until the 10&nbsp;mm cube measures exactly 10x10x10&nbsp;mm, even if that means squeezing the callipers.</p> <hr> <blockquote> <p><strong><a href="https://www.youtube.com/watch?v=Mbn1ckR86Z8&amp;t=85" rel="nofollow noreferrer">1:25 - Car analogy</a></strong></p> <p>You find that your car pulls to the left, when going in a straight line, so you adjust the steering. However, then in hard corners and the rain the car handles poorly. </p> <p>Upon closer inspection, it then turns out that the car had a flat tyre. You wouldn't compensate for having a flat tyre by adjusting the steering, now would you?</p> </blockquote> <hr> <p>In order to get that 10 mm cube precise, it is usual to calibrate for the filament diameter, and extrusion multiplier (most straightforward option), but some printers aren't even that precise in the first place.</p> <p>Mechanical, ripple, slaw, blacklash, can throw you off by 0.1 mm. Compensation for this 0.1 mm is certainly possible and achievable. However, then for a larger print, say 100&nbsp;mm, then these <em>overcompensation</em> will become more evident, and you will be one entire milimeter off the desired dimensions.</p> <p>So, use the ideal calculated esteps per mm. Timing belts and threaded rods are made to tight tolerances. therefore the worst case of ideal step per mm setting is an inaccuracy of 0.5%.</p> <p>So, to find the ideal calculated steps use <a href="http://prusaprinters.org/calculator/" rel="nofollow noreferrer">Prusa's calculator</a> which is very good indeed. </p> <p>If you are not using belts, or very large printer, then it is worth recalibrating the steps per mm for x and y, as 0.5% will make a noticeable difference in larger parts.</p> <p>Use the files and instructions for these <strong>Calibration sticks</strong> on <a href="https://www.youmagine.com/designs/calibration-sticks" rel="nofollow noreferrer">Youmagine</a>, for proper recalibrating without results slewed by the extrusion multiplier being off by a bit.</p> <p><strong><a href="https://www.youtube.com/watch?v=Mbn1ckR86Z8&amp;t=225" rel="nofollow noreferrer">3:45 - So what do I need to do?</a></strong></p> <p>What do you need to empirically calibrate your printer? In actual fact, not all that much:</p> <ul> <li>extruder steps per mm setting</li> <li><p>extrusion multiplier (see video link - <a href="https://www.youtube.com/watch?v=YUPfBJz3I6Y" rel="nofollow noreferrer">Extruder calibration</a>)</p></li> <li><p>print speed, jerk and acceleration settings - These depend upon how much quality you want to sacrifice for increased speed.</p> <p>Pro-tip: <em>slow your printing down</em>. For example, try printing at half speed. Quality <em>may</em> be improved, and even if it isn't you will be able to observe more clearly what is happening, and going wrong. (see video link - <a href="https://www.youtube.com/watch?v=7HsIZuj9vOs" rel="nofollow noreferrer">Super Fast Guide:Tuning Speeds</a>)</p></li> </ul> <p><strong><a href="https://www.youtube.com/watch?v=Mbn1ckR86Z8&amp;t=270" rel="nofollow noreferrer">4:30 - Other than that?</a></strong></p> <p>There is not much else needs calibrating, per se.</p> <p>With regards to slicer software, there are only a certain range of settings make sense, but this isn't printer calibration. You simply learn the slicer software and, with familiarity, see how far you can go.</p> <p>These days any well maintained and well built and solid printer will produce good prints.</p> <p>Most slicers give you decent prints without tweaking or calibrating, other than the basic settings about your printer and deciding how the part should be printed.</p> <p>What about print temp and retract settings? Well, just use the default settings, or settings which depend upon the type of filament. So, no calibration is required there, as it is a property of the filament.</p> <p><strong><a href="https://www.youtube.com/watch?v=Mbn1ckR86Z8&amp;t=324" rel="nofollow noreferrer">5:24 - Summing up</a></strong></p> <p>Don't try to calibrate everything</p> <p>The technology, in particular the software, i.e. slicers, is still developing and improving. Slic3r's prototpye beta (in Nov 2014) has added compensation for fitting errors(?) without messing other things up, which is essentially what the cube calibration tries to do, but in the correct way.</p>
<p>Have you correctly calibrated your steps per mm a.k.a. esteps? Tom made a great video about it:</p> <p><a href="https://www.youtube.com/watch?v=Mbn1ckR86Z8" rel="nofollow noreferrer">3D printing guides: Calibration and why you might be doing it wrong</a></p>
902
<p>What's the easiest way to get the data for a single table, delete a single table or break up the whole dump file into files each containing individual tables? I usually end up doing a lot of vi regex munging, but I bet there are easier ways to do these things with awk/perl, etc. The first page of Google results brings back a bunch of non-working perl scripts.</p>
<p>When I need to pull a single table from an sql dump, I use a combination of grep, head and tail.</p> <p>Eg:</p> <pre><code>grep -n "CREATE TABLE" dump.sql </code></pre> <p>This then gives you the line numbers for each one, so if your table is on line 200 and the one after is on line 269, I do:</p> <pre><code>head -n 268 dump.sql &gt; tophalf.sql tail -n 69 tophalf.sql &gt; yourtable.sql </code></pre> <p>I would imagine you could extend upon those principles to knock up a script that would split the whole thing down into one file per table.</p> <p>Anyone want a go doing it here?</p> <p>Another bit that might help start a bash loop going:</p> <pre><code>grep -n "CREATE TABLE " dump.sql | tr ':`(' ' ' | awk '{print $1, $4}' </code></pre> <p>That gives you a nice list of line numbers and table names like:</p> <pre><code>200 FooTable 269 BarTable </code></pre>
<p>I am a bit late on that one, but if it can help anyone, I had to split a huge SQL dump file in order to import the data to another Mysql server. what I ended up doing was splitting the dump file using the system command. </p> <p><strong>split -l 1000 import.sql splited_file</strong></p> <p>The above will split the sql file every 1000 lines.</p> <p>Hope this helps someone</p>
36,121
<p>We have several websites on different domains and I'd like to be able to track users' movements on these sites.</p> <ul> <li>Obviously cookies are not feasable, because they don't cross domain borders. </li> <li>I could look at a combination of IP address and User Agent, but there are some cases where that does not work.</li> <li>I don't want to use flash or other plugins.</li> </ul> <p>Any ideas? Or am I doomed to rely on the IP/User_Agent combination?</p>
<p>You can designate one domain or subdomain to tracking and have it serve a 1x1 pixel image which you include in all pages you would like to track. Serve a cookie with the image, look at the tracking domain's server logs, voilà.</p>
<p>You do not give any context to your situation -just the basic problem. So it is difficult to give an answer that clearly fits. However, here are some techniques/mechanisms for passing information from one page to another, regardless of what domain is involved.</p> <ul> <li>include hyperlink to a 1x1 pixel transparent gif image (sometimes called a "beacon")</li> <li>rely on referrer information in HTTP request headers to identify page hyperlink is on</li> <li>include extra parameters in hyperlinks to other site - assuming you run both sites</li> <li>buy services of a company like <a href="http://en.wikipedia.org/wiki/Akamai_Technologies" rel="nofollow noreferrer">Akamai</a> to do user tracking for you</li> <li>possibly use cross domain cookie mechanism in the future if standard is ever approved</li> </ul> <p>Which techniques really come down to whether you can place software on all of the sites (servers) that the user will visit where you have interest - or you cannot place your software on all of them.</p>
26,607
<p>My problem:</p> <p>I'm looking for a way to represent a person's name and address as an encoded id. The id should contain only alpha-numeric characters, be collision-proof, and be represented in a smallest number of characters possible. My first thought was to simply use a cryptographic hash function like MD5 or SHA1, but this seems like overkill (security isn't important - doesn't need to be one-way) and I'd prefer to find something that would produce a shorter id. Does anyone know of an existing algorithm that fits this problem?</p> <p>In other words, what is the best way to implement the following function so that the return value is the same consistently for the same input, collisions are unlikely, and ids are less than 20 characters?</p> <pre><code>&gt;&gt;&gt; make_fake_id(fname = 'Oscar', lname = 'Grouch', stnum = '1', stname = 'Sesame', zip = '12345') N1743123734 </code></pre> <p>Application Context (for those that are interested):</p> <p>This will be used for a <a href="http://en.wikipedia.org/wiki/Record_linkage_problem" rel="nofollow noreferrer">record linkage app</a>. Given an input name and address we search a very large database for the best match and return the database id and other data (how we do this is not important here). If there isn't a match I need to generate this psuedo/generated/derived id from the search input (entity's name and address data). Every search record should result in an output record with either a real (the actual database id resulting from a match/link) or this generated psuedo/generated/derived id. The psuedo id will be prefixed with a character (e.g. N) to differentiate it from a real id.</p>
<p>I know you said no to MD5 and SHA1, but I think you should consider them anyway. As well as being well studied hashing algorithms, the length gives you more protection against possible collisions. No hash is collision-proof, but the cryptographic ones generally are less collision-prone than something you couuld come up with yourself.</p>
<p>Well, if there's more than one person at the same address with the same name, you're toast here, (w/o adding code to detect this and add a discriminator of some kind).</p> <p>but assuming that issue is not, then the street address and zip code portion of the full addresss is sufficient to guaranteee uniqueness there, so adding enough data from the name should take care of the issue... </p> <p>Do you have access to a database, or other persistence mechanism, where you could generate and maintain key values for each address? Then keep the address and individual entities in two keyed dictionary structures, where the key is autogenerated for each new distinct address, person encountered... and then use the autogenerated alpha-numeric key... </p> <pre><code>You could use AAAAA01 for first person at first address, AAAAA02 for second person at first address, AAAAB07 for the seventh resident at the second adresss, etc. </code></pre> <p>If you donlt have any way to generate and maintain these entity-Key mappings then you need to use the full street address/Zip and fullNAme, or a hash value of the same, although the Hash value approach has a smnall chance of generating duplicates... </p>
42,978
<p>I keep hearing from associates about grid computing which, from what I can gather, is highly distributed stuff along the lines of SETI@Home.</p> <p>Is anyone working on these sort of systems for business use? My interest is in figuring out if there's a commercial reason for starting software development in this field.</p>
<p>Grid computing is really only needed if you have a lot of WORK that needs to be done, like folding proteins, otherwise a simple server farm will likely be plenty.</p>
<p>Obviously Google are major users of Grid Computing; all their search service relies on it, and many others.</p> <p>Engines such as BigTable are based on using lots of nodes for storage and computation. These are commercially very useful because they're a good alternative to a small number of big servers, providing better redundancy and cost effective scaling.</p> <p>The downside is that the software is fiendishly difficult to write, but Google seem to manage that one ok :)</p> <p>So anything which requires big storage and/or lots of computation.</p>
13,261
<p>Currently my workflow with Emacs when I am coding in C or C++ involves three windows. The largest on the right contains the file I am working with. The left is split into two, the bottom being a shell which I use to type in compile or make commands, and the top is often some sort of documentation or README file that I want to consult while I am working. Now I know there are some pretty expert Emacs users out there, and I am curious what other Emacs functionally is useful if the intention is to use it as a complete IDE. Specifically, most IDEs usually fulfill these functions is some form or another:</p> <ul> <li>Source code editor</li> <li>Compiler</li> <li>Debugging</li> <li>Documentation Lookup</li> <li>Version Control</li> <li>OO features like class lookup and object inspector </li> </ul> <p>For a few of these, it's pretty obvious how Emacs can fit these functions, but what about the rest? Also, if a specific language must be focused on, I'd say it should be C++. </p> <p><strong>Edit:</strong> One user pointed out that I should have been more specific when I said 'what about the rest'. Mostly I was curious about efficient version control, as well as documentation lookup. For example, in SLIME it is fairly easy to do a quick hyperspec lookup on a Lisp function. Is there a quick way to look up something in C++ STL documentation (if I forgot the exact syntax of <a href="http://www.sgi.com/tech/stl/hash_map.html" rel="noreferrer">hash_map</a>, for example)?</p>
<p>You'll have to be specific as to what you mean by "the rest". Except for the object inspector (that I"m aware of), emacs does all the above quite easily:</p> <ul> <li>editor (obvious)</li> <li>compiler - just run <code>M-x compile</code> and enter your compile command. From there on, you can just <code>M-x compile</code> and use the default. Emacs will capture C/C++ compiler errors (works best with GCC) and help you navigate to lines with warnings or errors.</li> <li>Debugging - similarly, when you want to debug, type <code>M-x gdb</code> and it will create a gdb buffer with special bindings</li> <li>Documentation Lookup - emacs has excellent CScope bindings for code navigation. For other documentation: Emacs also has a manpage reader, and for everything else, there's the web and books.</li> <li>version control - there are lots of Emacs bindings for various VCS backends (CVS, SCCS, RCS, SVN, GIT all come to mind)</li> </ul> <p>Edit: I realize my answer about documentation lookup really pertained to code navigation. Here's some more to-the-point info: </p> <ul> <li><a href="http://www.delorie.com/gnu/docs/emacs/emacs_289.html" rel="noreferrer">Looking up manpages, info manuals, and Elisp documentation from within emacs</a></li> <li><a href="https://bitbucket.org/jonwaltman/pydoc-info" rel="noreferrer">Looking up Python documentation from within Emacs</a>. </li> </ul> <p>Google searching will no doubt reveal further examples.</p> <p>As the second link shows, looking up functions (and whatever) in other documentation can be done, even if not supported out of the box.</p>
<p>In the Unix or X windows style, I don't know that there is an integrated IDE that works for everything. </p> <p>For interacting with debuggers, just one component of an IDE, consider <a href="https://github.com/realgud" rel="nofollow noreferrer">realgud</a>. The other thing it has that I find useful are parsers for location messages, so that if you have a call stack trace and want to edit at a particular place in the callstack, this front-end interface will can do that. </p> <p>By far this program could use improvement. But then it could also use people working on it to improve it. </p> <p>Disclaimer: I work on realgud</p>
8,889
<p>Does anyone know how SQL Server determines the order triggers (of same type, i.e. before triggers) are executed. And is there any way of changing this so that I can specify the order I want. If not, why not.</p> <p>Thanks.</p>
<p>If you're at the point of worrying about trigger orders then you really should take a step backwards and consider what you are trying to do and if there is there a better way of doing it. The fact that this isn't an easy thing to change should be telling you something.</p> <p>Triggers always look like a really neat solution, and in the right place they are highly valuable, <strong>but</strong> the price is high, and it's really easy to create debugging nightmares with them. I've lost many hours in the past trying to debug some obscure database behavior only to find that the cause is burrowed away in an overlooked trigger.</p>
<p>Use this system stored procedure:</p> <pre><code>sp_settriggerorder[@triggername = ] 'triggername', [@order = ] 'value', [@stmttype = ] 'statement_type' </code></pre>
11,975
<p>In our Flex AIR app, we have the problem that our main app window is fairly narrow. This means Alert dialog boxes are chopped on both side, while the right click menu is cropped. How can we get these windows to not get cropped by our main window?</p>
<p>Turn your main AIR window into an invisible transparent window and make your app's primary working window a child of the invisible one. Then when you AIR app starts, make the invisible window the size that encompasses the desktop. You'll then be able to position as many windows and dialogs as you want on this desktop area without worrying about them getting clipped as is happening to you now.</p> <p>If you want to support multiple screen displays - such that your visible app window can be drug around from display to display, then make your invisible window the size of the entire graphics coordinate system such that it encompasses any and all display screens.</p> <p>Once you go with the invisible window approach, you'll be able to achieve windowing behaviors that are like that of native applications.</p>
<p>With flex applications running inside of the flash player, windows cannot be shown outside of the stage. So the only way to make this work would be to make your app larger. </p> <p>You could though use the flex/ajax bridge and call a javascript alert box instead, they would not be bound by the stage. But it would not be skinned like the rest of the application though and would take some more work to get hooked in, especially if you are listening for the user to click the okay button...</p>
40,700
<p>Hello again ladies and gents!</p> <p>OK, following on from my other question on <a href="https://stackoverflow.com/questions/6681/aspnet-web-service-results-proxy-classes-and-type-conversion">ASP.NET Web Service Results, Proxy Classes and Type Conversion</a>. I've come to a part in my project where I need to get my thinking cap on.</p> <p>Basically, we have a large, complex custom object that needs to be returned from a Web Service and consumed in the client application.</p> <p>Now, based on the previous discussion, we know this is going to then take the form of the proxy class(es) as the return type. To overcome this, we need to basically copy the properties from one to the other.</p> <p>In this case, that is something that I would really, really, <em>really!</em> like to avoid!</p> <p>So, it got me thinking, <strong>how else could we do this?</strong></p> <p>My current thoughts are to enable the object for complete serialization to XML and then return the XML as a string from the Web Service. We then de-serialize at the client. This will mean a fair bit of attribute decorating, but at least the code at both endpoints will be light, namely by just using the .NET XML Serializer.</p> <h2>What are your thoughts on this?</h2>
<p>The .Net XML (de)serialisation is pretty nicely implemented. At first thought, I don't think this is a bad idea at all.</p> <p>If the two applications import the same C# class(es) definition(s), then this is a relatively nice way of getting copy-constructor behaviour for free. If the class structure changes, then everything will work when both sides get the new class definition, without needing to make any additional changes on the web-service consumption/construction side.</p> <p>There's a slight overhead in marshalling and demarshalling the XML, but that is probably dwarved by the overhead of the remote web service call. .Net XML serialisation is well understood by most programmers and should produce an easy to maintain solution.</p>
<p>I had some great answers on a very similar topic yesterday that might be useful for you:</p> <p><a href="https://stackoverflow.com/questions/16529/communication-between-javascript-and-the-server">Communication between javascript and the server</a></p>
3,831
<p>I really want to write .NET apps that run on any platform (PC, Linux and Mac). I am not really concerned about UI capabilities because these are mostly background services. I have heard of MONO and that it allows you to write .NET apps that run on Mac and Linux, but I want to be able to write a single app that when compiled for Windows will run as a Service, and when compiled for Linux will run as whatever the UNIX equivalent is. I also would like to be able to store things in the registry and have that work. Is there any way to write truly OS agnostic code like this? ...and DON'T say I should make it run on the web! :)</p>
<p>Yes, Mono has the windows service stuff ported to Linux, but you are going to have to think of a better way to store configuration settings than Registry... Using XML files for instance would be cross platform.</p> <p>You should also check out mono's wiki on how to develop portable applications <a href="http://www.mono-project.com/Guidelines:Application_Portability" rel="noreferrer">here</a>.</p>
<p>Short answer: no. You could create an application which will run on both Windows and Linux. But there are platform-specific features and right now Mono could not automatically 'translate' those for you. A Windows Service is a good example of that.</p>
13,434
<p>I'm working with a VB Script file written by someone else that uses Windows Management Instrumentation (WMI) calls to check on the status of several Windows Services. This script runs every few minutes on set schedule. I need to upgrade/replace the .exe for those services.</p> <p>I stop the VB Script, stop the services, and uninstall the services so they no longer appear in the Services panel (services.msc). Unfortunately, WMI (wmiprvse.exe) still has a handle on the service .exe files. I can release the handle by rebooting the system, but I want to avoid that if at all possible so this can be a completely scripted/automated upgrade.</p> <p>Is there a way I can force WMI to release it's handle on the .exe? Please keep in mind I'm new to working with WMI.</p>
<p>I'm also looking for a solution to this problem. Would also like to understand why wmiprsve has handles on some of my service executables but not on others.</p> <p>The workaround I'm using is to kill the wmiprvse process. You can use the SysInternals command line tools (pslist, pskill) to automate getting the process id and performing the kill.</p>
<p>You can simply restart the WMI service (winmgmt) to force it to release your files. If your service isn't registered when WMI starts it won't put a lock on the files.</p> <p>Stop service, uninstall service, restart WMI, replace files, start service.</p>
38,817
<p><strong>Problem solved:</strong> Thanks guys, see my answer below.</p> <p>I have a website running in Tomcat 5.5 hooked up to a MySQL5 database using Hibernate3.</p> <p>One record simply refuses to keep any changes performed on it. If I change the record programmatically, the values revert back to what they were previously. </p> <p>If I manually modify the record in the database, the values will revert (seemingly once the webapp accesses them).</p> <p>I have tried stopping Tomcat and changing the values manually then starting Tomcat again. Checking the database, the values remain changed after Tomcat has started the webapp but will revert back again once I load the site.</p> <p>I have also tried deleting the Tomcat work folder for the webapp and the .ser cache file.</p> <p>I have also checked the code for the values that are being reverted to and cannot find them. </p> <p>I have only noticed it on this one particular record.</p> <p><strong>Edit:</strong> I've just had a look at the SQL output from Hibernate using hibernate.show_sql=true. There is an update query logged for the table my row is in. Does anyone know how to resolve the ? for the columns to actual values?</p>
<p>You could temporarily enable the mysql query logging and see exactly what sql statement altered the value. Since you say it changes immediately after the server starts you should be able to figure out the statement pretty quickly.</p> <p><a href="http://dev.mysql.com/doc/refman/5.0/en/query-log.html" rel="nofollow noreferrer">http://dev.mysql.com/doc/refman/5.0/en/query-log.html</a></p>
<p>It's getting close to halloween, so you have to expect this sort of thing (plus it was just a full moon), but I'd keep looking for the culprit in the web application ... it HAS to be there. A couple values I'd immediately search for in the webapp source code:</p> <ul> <li>The id of the record being changed.</li> <li>The value that's being written into the record.</li> </ul> <p>Good luck ... these can be real bears to find!</p>
25,381
<p>Eclipse issues warnings when a <code>serialVersionUID</code> is missing. </p> <blockquote> <p>The serializable class Foo does not declare a static final serialVersionUID field of type long</p> </blockquote> <p>What is <code>serialVersionUID</code> and why is it important? Please show an example where missing <code>serialVersionUID</code> will cause a problem.</p>
<p>The docs for <a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/io/Serializable.html" rel="noreferrer"><code>java.io.Serializable</code></a> are probably about as good an explanation as you'll get:</p> <blockquote> <p>The serialization runtime associates with each serializable class a version number, called a <code>serialVersionUID</code>, which is used during deserialization to verify that the sender and receiver of a serialized object have loaded classes for that object that are compatible with respect to serialization. If the receiver has loaded a class for the object that has a different <code>serialVersionUID</code> than that of the corresponding sender's class, then deserialization will result in an <a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/io/InvalidClassException.html" rel="noreferrer"><code>InvalidClassException</code></a>. A serializable class can declare its own <code>serialVersionUID</code> explicitly by declaring a field named <code>serialVersionUID</code> that must be static, final, and of type <code>long</code>:</p> </blockquote> <blockquote> <pre><code>ANY-ACCESS-MODIFIER static final long serialVersionUID = 42L; </code></pre> </blockquote> <blockquote> <p>If a serializable class does not explicitly declare a <code>serialVersionUID</code>, then the serialization runtime will calculate a default <code>serialVersionUID</code> value for that class based on various aspects of the class, as described in the Java(TM) Object Serialization Specification. However, it is <em>strongly recommended</em> that all serializable classes explicitly declare <code>serialVersionUID</code> values, since the default <code>serialVersionUID</code> computation is highly sensitive to class details that may vary depending on compiler implementations, and can thus result in unexpected <code>InvalidClassExceptions</code> during deserialization. Therefore, to guarantee a consistent <code>serialVersionUID</code> value across different java compiler implementations, a serializable class must declare an explicit <code>serialVersionUID</code> value. It is also strongly advised that explicit <code>serialVersionUID</code> declarations use the private modifier where possible, since such declarations apply only to the immediately declaring class — <code>serialVersionUID</code> fields are not useful as inherited members.</p> </blockquote>
<p>A Simple Explanation:</p> <ol> <li><p>Are you serializing data?</p> <p>Serialization is basically writing class data to a file/stream/etc. De-serialization is reading that data back to a class. </p></li> <li><p>Do you intend to go into production?</p> <p>If you are just testing something with unimportant/fake data, then don't worry about it (unless you are testing serialization directly). </p></li> <li><p>Is this the first version?</p> <p>If so, set <code>serialVersionUID=1L</code>. </p></li> <li><p>Is this the second, third, etc. prod version?</p> <p>Now you need to worry about <code>serialVersionUID</code>, and should look into it in depth.</p></li> </ol> <p>Basically, if you don't update the version correctly when you update a class you need to write/read, you will get an error when you try to read old data.</p>
36,302
<p>Well I am querying my DB, a table called bookBilling, to get a value under the column of billingID. </p> <p>In my first query I get the customer ID from a table based on what value the cookie holds. In my second query I take that custID value and am looking to get the billingID associated with it.</p> <pre><code>query = "SELECT custID FROM bookSession WHERE session='"&amp;theCookie&amp;"'" '--Connect to DB' Set objConn = ConnectDB() '--Query to DB' Set objRS = objConn.Execute(query) custID = objRS.Fields("custID") query = "SELECT billingID FROM bookBilling WHERE custID="&amp;custID&amp;"" objConn.Execute(query) </code></pre> <p>Here is where it becomes an issue. I tried using this to obtain the value:</p> <pre><code>billingID = objRS.Fields("billingID") </code></pre> <p>When that didn't work I printed the query to my browser to make sure it worked and it came back good, I checked it in SQL Server Management Studio to make sure. After that I decided to play with it a bit and found that using "0" as the reference works since it is the first item in my table. </p> <pre><code>billingID = objRS.Fields(0) </code></pre> <p>So that worked, I know my table column header is correct I have looked at it and used it in other queries before. Does anyone know why this might happen? Is it a result of not clearing my connection or closing it afterward?</p> <p>Thanks</p>
<p>Hey, is it a typo that you don't have this?</p> <blockquote> <p>query = &quot;SELECT billingID FROM bookBilling WHERE custID=&quot;&amp;custID&amp;&quot;&quot;</p> <p><em><strong>objRS =</strong></em> objConn.Execute(query)</p> </blockquote> <p>To reload the recordset with the data and definition of the second query.....</p> <p>Just a thought, try Setting/Instantiating the ObjRS to a Recordset first, then apply the query.execute to it after, rather than the initial all in one with the first CustId query</p>
<pre><code>query = "SELECT billingID FROM bookBilling WHERE custID="&amp;custID&amp;"" objConn.Execute(query) </code></pre> <p>You're not opening a resordset for that second query. And, not sure if that has any influence at all, but I never name my queries identical. To be sure I guess.</p> <p>Edit, well that's kind of what the people above me said, I'm a Slowpoke.</p>
46,893
<p>With ViEmu you really need to unbind a lot of resharpers keybindings to make it work well.</p> <p>Does anyone have what they think is a good set of keybindings that work well for resharper when using ViEmu?</p> <p>What I'm doing at the moment using the Visual Studio bindings from Resharper. Toasting all the conflicting ones with ViEmu, and then just driving the rest through the menu modifiers ( Alt-R keyboard shortcut for the menu item ). I also do the same with Visual Assist shortcuts ( for C++ )</p> <p>if anyones got any tips and tricks for ViEmu / Resharper or Visual Assist working together well I'd most apprciate it!</p>
<p>You can also create mappings in ViEmu that will call the VS and R# actions. For example, I have these lines in my _viemurc file for commenting and uncommenting a selection:</p> <pre><code>map &lt;C-S-c&gt; gS:vsc Edit.CommentSelection&lt;CR&gt; map &lt;C-A-c&gt; gS:vsc Edit.UncommentSelection&lt;CR&gt; </code></pre> <p>The :vsc is for "visual studio command," and then you enter the exact text of the command, as it appears in the commands list when you go to Tool>Options>Keyboard</p> <p>I don't use any of the R# ones in this way, but it does work, as with:</p> <pre><code>map &lt;C-S-A-f&gt; gS:vsc ReSharper.FindUsages&lt;CR&gt; </code></pre>
<p>I use both plugins, but I really prefer the power of the Vi input model that ViEmu gives. I really don't miss so much the Resharper keybindings...</p>
11,295
<p>I've just started skimming 'Debugging MS .Net 2.0 Applications' by John Robbins, and have become confused by his evangelism for Debug.Assert(...).</p> <p>He points out that well-implemented Asserts store the state, somewhat, of an error condition, e.g.:</p> <pre><code>Debug.Assert(i &gt; 3, "i &gt; 3", "This means I got a bad parameter"); </code></pre> <p>Now, personally, it seems crazy to me that he so loves restating his test without an actual sensible 'business logic' comment, perhaps "i &lt;= 3 must never happen because of the flobittyjam widgitification process".</p> <p>So, I think I get Asserts as a kind-of low-level "Let's protect my assumptions" kind of thing... assuming that one feels this is a test one only needs to do in debug - i.e. you are protecting yourself against colleague and future programmers, and hoping that they actually test things.</p> <p>But what I don't get is, he then goes on to say that you should use assertions in addition to normal error handling; now what I envisage is something like this:</p> <pre><code>Debug.Assert(i &gt; 3, "i must be greater than 3 because of the flibbity widgit status"); if (i &lt;= 3) { throw new ArgumentOutOfRangeException("i", "i must be &gt; 3 because... i=" + i.ToString()); } </code></pre> <p>What have I gained by the Debug.Assert repetition of the error condition test? I think I'd get it if we were talking about debug-only double-checking of a very important calculation...</p> <pre><code>double interestAmount = loan.GetInterest(); Debug.Assert(debugInterestDoubleCheck(loan) == interestAmount, "Mismatch on interest calc"); </code></pre> <p>...but I don't get it for parameter tests which are surely worth checking (in both DEBUG and Release builds)... or not. What am I missing?</p>
<p>Assertions are not for parameter checking. Parameter checking should always be done (and precisely according to what pre-conditions are specified in your documentation and/or specification), and the <code>ArgumentOutOfRangeException</code> thrown as necessary.</p> <p>Assertions are for testing for "impossible" situations, i.e., things that you (in your program logic) <em>assume</em> are true. The assertions are there to tell you if these assumptions are broken for any reason.</p> <p>Hope this helps!</p>
<p>Here is by 2 cents.</p> <p>I think that the best way is to use both assertions and exceptions. The main differences between the two methods, imho, if that Assert statements can be removed easily from the application text (defines, conditional attributes...), while Exception thrown are dependent (tipically) by a conditional code which is harder to remove (multine section with preprocessor conditionals).</p> <p>Every application exception shall be handled correctly, while assertions shall be satisfied only during the algorithm developement and testing.</p> <p>If you pass an null object reference as routine parameter, and you use this value, you get a null pointer exception. Indeed: why you should write an assertion? It's a waste of time in this case. But what about private class members used in class routines? When these value are set somewhere, is better to check with an assertion if a null value is set. That's only because when you use the member, you get a null pointer exception but you don't know how the value was set. This cause a restart of the program breaking on all entry point use to set the private member.</p> <p>Exception are more usefull, but they can be (imho) very heavy to manage and there is the possibility to use too much exceptions. And they requires additional check, maybe undesired to optimize the code. Personally I use exceptions only whenever the code requires a deep catch control (catch statements are very low in the call stack) or whenever the function parameters are not hardcoded in the code.</p>
8,636
<h2>Short version</h2> <p>How do i use an API call when i cannot guarantee that the window handle will remain valid? </p> <p>i can guarantee that i'm holding a reference to my form (so the form is not being disposed). That doesn't guarantee that the form's <strong>handle</strong> will stay valid all that time. </p> <p><em>How can a form's window handle become invalid even though the form is not diposed</em>? </p> <p>Because the form's underlying Windows window was destroyed and recreated. </p> <h2>Long Version</h2> <p>i want to P/Invoke an API that requires a hwnd (a handle to a window). Some examples of API calls that requie an hWnd are:</p> <p><a href="http://msdn.microsoft.com/en-us/library/ms787175(VS.85).aspx" rel="nofollow noreferrer">IVMRWindowlessControl::SetVideoClippingWindow</a></p> <pre><code> HRESULT SetVideoClippingWindow( HWND hwnd ); </code></pre> <p><a href="http://msdn.microsoft.com/en-us/library/ms644950.aspx" rel="nofollow noreferrer">SendMessage</a></p> <pre><code>SendMessage( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam ); </code></pre> <p><a href="http://msdn.microsoft.com/en-us/library/ms649052.aspx" rel="nofollow noreferrer">SetClipboardViewer</a></p> <pre><code>HWND SetClipboardViewer( HWND hWndNewViewer ); </code></pre> <p><a href="http://msdn.microsoft.com/en-us/library/ms644906.aspx" rel="nofollow noreferrer">SetTimer</a></p> <pre><code>UINT_PTR SetTimer( HWND hWnd, UINT_PTR nIDEvent, UINT uElapse, TIMERPROC lpTimerFunc ); </code></pre> <p><a href="http://msdn.microsoft.com/en-us/library/bb775262(VS.85).aspx" rel="nofollow noreferrer">IProgressDialog::StartProgressDialog</a></p> <pre><code>HRESULT StartProgressDialog( HWND hwndParent, IUnknown *punkEnableModless, DWORD dwFlags, LPCVOID pvReserved ); </code></pre> <p><a href="http://msdn.microsoft.com/en-us/library/bb762159(VS.85).aspx" rel="nofollow noreferrer">Shell_NotifyIcon</a></p> <pre><code>BOOL Shell_NotifyIcon( DWORD dwMessage, PNOTIFYICONDATA lpdata //&lt;--hWnd in there ); </code></pre> <p><a href="http://msdn.microsoft.com/en-us/library/ms632669.aspx" rel="nofollow noreferrer">AnimateWindow</a></p> <pre><code>BOOL AnimateWindow( HWND hwnd, DWORD dwTime, DWORD dwFlags ); </code></pre> <p><strong>Note:</strong> Some of these API calls have managed equivalents, some do not - but that fact is irrelavent for my question.</p> <h2>Explanation</h2> <p>i can call one of these API functions, which requires long term window handle, e.g.:</p> <pre><code>private void TellTheGuyToDoTheThing() { SendMessage(this.Handle, WM_MyCustomMessage, paramOneForTheThing, paramTwoForTheThing); } </code></pre> <p>It has been suggested that the above call to SendMessage is dangerous because of the unmanaged use of a window handle. They suggest that you wrap the hwnd in a HandleRef object:</p> <pre><code>private void TellTheGuyToDoTheThing() { SendMessage(new HandleRef(this, this.Handle), WM_MyCustomMessage, paramOneForTheThing, paramTwoForTheThing); </code></pre> <p>This way: the window handle is guaranteed to stay valid during the call to SendMessage. But it doesn't always work out that way. The following API call requires long-term access to a window handle:</p> <pre><code>private void RegisterWithTheThing() { this.nextClipboardViewerInChain = SetClipboardViewer( new HandleRef(this, this.Handle)); } </code></pre> <p>Even though i wrapped the handle in a HandleRef, it is still possible (in the subsequest seconds, minutes, hours, days, weeks, months, or years) for the form's window handle to become invalid. This happens when the form's underlying Windows window is destroyed and a new one created. This, despite the fact that i protected the form's handle in a HandleRef.</p> <p>i can name <em>one</em> way in which a form's handle becomes invalid:</p> <pre><code>this.RightToLeft = RightToLeft.Yes; </code></pre> <p>The form's window is re-created and old hwnd is now invalid.</p> <p>So the question is: How to use an API call that requires a window handle?</p> <h2>Cannot be done?</h2> <p>i anticipate the answer: <em>you cannot do this. There is nothing that can be done to protect the form's handle to ensure it is valid as long as you need to keep the handle.</em></p> <p>This then means that i need to know when the handle is being destroyed, so i can tell Windows to let it go, e.g.:</p> <pre><code>protected override void TheHandleIsAboutToBeDestroyed() { ChangeClipboardChain(this.Handle, this.nextClipboardViewerInChain); } </code></pre> <p>and then be told when the new handle is created:</p> <pre><code>protected override void TheHandleWasJustCreated() { RegisterTheThing(); } </code></pre> <p>Except no such ancestor methods exist.</p> <p><strong>Alternate question:</strong> Are there methods i can override so i know when a window's handle is about to be destroyed, and when it has just been creatd?</p> <p>Having to break the .NET WinForms encapsulation of re-creating handles is ugly, but is it the only way?</p> <hr> <h2>Update One</h2> <p>Handling the <strong>Close</strong>/<strong>OnClose</strong> event of a form is insufficient, the same goes for</p> <ul> <li>handling IDisposable</li> <li>GC pinning the form</li> </ul> <p>since i can make the form's underlying window handle invalid without closing or disposing form. e.g:</p> <pre><code>private void InvalidThisFormsWindowHandleForFun() { this.RightToLeft = RightToLeft.Yes; } </code></pre> <p><strong>Note:</strong> You <em>destroy</em> a Windows window handle, you don't dispose of it. Objects in .NET are the things that get disposed of; which, if it's a Form object, will most likely involve <em>destroying</em> the Windows window handle.</p> <p>Windows is a product by Microsoft.</p> <p>A window is a thing with a message loop and can sometimes show stuff on screen.</p> <hr> <h2>Update Two</h2> <p><a href="https://stackoverflow.com/questions/359763/net-winforms-how-to-use-an-api-call-that-requires-a-window-handle#360023">me.yahoo.com/a/BrYwg</a> had a good suggestion for the use of a <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.nativewindow.aspx" rel="nofollow noreferrer">NativeWindow</a> object to act as a listener for items that require an hWnd which are used to listen for messages. This can be used to solve some issues, like:</p> <ul> <li>SetClipboardViewer</li> <li>SetTimer</li> <li>IProgressDialgo::StartProgressDialog</li> <li>Shell_NotifyIcon</li> </ul> <p>but doesn't work for</p> <ul> <li>AnimateWindow</li> <li>SendMessage</li> <li>IVMRWindowlessControl::SetVideoClippingWindow</li> </ul>
<p>Have you looked at the functionality in the NativeWindow class?</p>
<p>I think that the form's OnClose function (or related event) should be overriden.</p> <p>Alternative - each form implements IDisposable - why don't you add code to the Dispose method of the form that belong to that handle.</p>
46,936
<p>I have stumbled across something truly puzzling regarding <code>System.getProperty("os.name")</code>. According to <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6220825" rel="nofollow noreferrer">a Java bug on the matter</a> and <a href="http://java.sun.com/j2se/1.5.0/ReleaseNotes.html#150_10" rel="nofollow noreferrer">the Java 5 release notes</a> (search for "os.name"), there was a bug in Java with early "longhorn" versions of Vista that should have been fixed in v5 release 10.</p> <p>However on my Vista SP1 box - using both v5 release 15 and v6 release 6 - <code>System.getProperty("os.name")</code> returns "Windows XP". Further <code>System.getProperty("os.version")</code> returns "5.1". I cannot find anything relating to this issue via Google though. This makes me wonder whether it is something odd with my Vista setup. I have tried calling the GetVersionEx() API function from a test C program and it returns major version 6, minor 0 (as I'd expect for a Vista install).</p> <p>Has anyone else encountered this problem, know of a fix or have any suggestions of how I might work around it without using JNI?</p>
<p>It might be that Java runs in XP compatibility mode. In that case, Vista will fake the windows version number, making Java believe that it runs on XP. Check the compatibility tab of the executable.</p>
<p>The actual windows version number of Windows 2000 was 5.0. Windows XP was 5.1. Vista is supposedly 6.0, so your test program is functioning correctly. It sounds to me like Java is definitely getting this wrong.</p> <p>You might have to rely on a JNI to get the right answer. I sort of assume that you've already asked yourself why you might need to vary the behavior of your program based on whether you're using XP or Vista.</p>
34,507
<p>I can set the PHP include path in the <code>php.ini</code>:</p> <pre><code>include_path = /path/to/site/includes/ </code></pre> <p>But then other websites are affected so that is no good.</p> <p>I can set the PHP include in the start of every file:</p> <pre><code>$path = '/path/to/site/includes/'; set_include_path(get_include_path() . PATH_SEPARATOR . $path); </code></pre> <p>But that seems like bad practice and clutters things up. </p> <p>So I can make an include of that and then include it into every file:</p> <pre><code>include 'includes/config.php'; </code></pre> <p>or</p> <pre><code>include '../includes/config.php'; </code></pre> <p>This is what I'm doing right now, but the include path of <code>config.php</code> will change depending on what is including it. </p> <p>Is there a better way? Does it matter?</p>
<p>If you're using apache as a webserver you can override (if you allow it) settings using <em>.htaccess</em> files. See <a href="http://us2.php.net/configuration.changes" rel="nofollow noreferrer">the PHP manual</a> for details.</p> <p>Basically you put a file called <em>.htaccess</em> in your website root, which contains some PHP <code>ini</code> values. Provided you configured Apache to allow overrides, this site will use all values in your PHP config, + the values you specify in the <em>.htaccess</em> file.</p> <blockquote> <p>Can be used only with <code>PHP_INI_ALL</code> and <code>PHP_INI_PERDIR</code> type directives</p> </blockquote> <p>as stated in the page I linked. If you click through to the full listing, you see that the include path is a <code>PHP_INI_ALL</code> directive.</p>
<p>You can set <code>include_path</code> in your php.ini file too. I'm a perl guy, so I expect to be able to load includes and have <code>include</code> do the right thing. I have all my includes in a specific directory, which is added to <code>include_path</code>. I can do things like </p> <pre><code>require_once "ClassName.php"; </code></pre> <p>I don't need to worry about relative paths or locations of files.</p> <p>I've also written my own <code>CustomRequire</code> to do things like</p> <pre><code>function CustomRequire ($file) { if(defined('MYINCLUDEPATH')) { require_once MYINCLUDEPATH . "/$file"; } else { require_once $file; } } </code></pre> <p>That way I can change how I do includes at a later date. Of course, you still need to find a way to include your include code :)</p>
4,427
<p>Where I work, people don't like to write specs. (Boy, does anyone?) So they don't do it, unless forced by their bosses. If they are forced to write them, they make them as short as possible. (By the way, <em>they</em> also includes <em>me</em>.)</p> <p>This results in specifications like</p> <ul> <li>This software logs the time between event A and B to the event log</li> <li>Name and path of parameter X are set in a configuration file in ini format.</li> <li>The software is active without a user needing to log on to the computer (implementation as a Windows service)</li> </ul> <p>This example is taken from a very small project, and it worked out pretty well, But I don't think that it will suffice for anything more complex. I did not specify OS/hardware requirements because this is in-house development and we have company or department standards covering those. </p> <p>So my question is: <em>What do you consider the absolute minimum level of detail in a functional specification for any non-trivial software?</em></p>
<p>I don't think that you can do exactly what you are asking. When MVC invokes an action it looks for parameters in routes, request params and the query string. It's always looking to match the parameter name. </p> <p>Perhaps good old query string will meet your needs.</p> <pre><code>~/mycontroller/myaction/?foobar=123 </code></pre> <p>will pass 123 to this action:</p> <pre><code>public ActionResult MyAction(int? foobar) </code></pre>
<p>Although you still can't use the <code>FromUri</code> attribute, you can however use the <code>Route</code> attribute, like so</p> <pre><code>[Route("~/Policy/PriorAddressDelete/{sequence}")] public ActionResult PriorAddressDelete(int sequence) { Policy.RemoveScheduledPriorAddressItem(sequence); return RedirectToAction("Information", new { id = Policy.Id }); } </code></pre> <p>Technically this adds a new route, but at least it doesn't clutter up your <code>routeconfig</code>. It puts the route definition right by where it's used, which I like (less hunting things down).</p> <p>Remember, in order to use attribute routing, this must be in your routeconfig file <strong>above</strong> your defined routes:</p> <pre><code>routes.MapMvcAttributeRoutes(); </code></pre>
44,691
<p>I want to put my master pages in a central library so I can use them in several projects without having the maintanance nightmare. Everything is refactored in a generic and central way, they are all in a "shared" namespace. But if put them in a seperate project, I can't reference them</p>
<p>I don't believe you can put that actual .master pages in an external library. You can place your own customer MasterPage-derived class in the library, and have your client apps derive from that, but I don't think that's what your intent is, since you're tagged with asp.net-mvc (implying very narrow views without much logic, and probably no code-behinds). </p> <p>As far as I'm aware, there isn't a way to reference a master (nor, for that matter, an ASPX or ASCX) from an external library. Wish I had better news for you. (And I actually hope I'm wrong; I hope someone else here has figured out a technique for this, as I'd like to use that kind of thing myself on occasion.)</p>
<p>Just for reference's sake, I'll put Phil's mail here too:</p> <blockquote> <p>Sorry for the late response. You could try using a VirtualPathProvider, but this would require full trust. Other than that, I don't know of any way to do this.</p> <p>Phil</p> </blockquote> <p>so there you go.</p>
25,125
<p>I'm using C# &amp; .NEt 3.5. What is the difference between the OptionA and OptionB ?</p> <pre><code>class MyClass { private object m_Locker = new object(); private Dicionary&lt;string, object&gt; m_Hash = new Dictionary&lt;string, object&gt;(); public void OptionA() { lock(m_Locker){ // Do something with the dictionary } } public void OptionB() { lock(m_Hash){ // Do something with the dictionary } } } </code></pre> <p>I'm starting to dabble in threading (primarly for creating a cache for a multi-threaded app, NOT using the HttpCache class, since it's not attached to a web site), and I see the OptionA syntax in a lot of the examples I see online, but I don't understand what, if any, reason that is done over OptionB.</p>
<p>Option B uses the object to be protected to create a critical section. In some cases, this more clearly communicates the intent. If used consistently, it guarantees only one critical section for the protected object will be active at a time:</p> <pre><code>lock (m_Hash) { // Across all threads, I can be in one and only one of these two blocks // Do something with the dictionary } lock (m_Hash) { // Across all threads, I can be in one and only one of these two blocks // Do something with the dictionary } </code></pre> <p>Option A is less restrictive. It uses a secondary object to create a critical section for the object to be protected. If multiple secondary objects are used, it's possible to have more than one critical section for the protected object active at a time.</p> <pre><code>private object m_LockerA = new object(); private object m_LockerB = new object(); lock (m_LockerA) { // It's possible this block is active in one thread // while the block below is active in another // Do something with the dictionary } lock (m_LockerB) { // It's possible this block is active in one thread // while the block above is active in another // Do something with the dictionary } </code></pre> <p>Option A is equivalent to Option B if you use only one secondary object. As far as reading code, Option B's intent is clearer. If you're protecting more than one object, Option B isn't really an option.</p>
<p>Locking the object that you're using is simply a matter of convenience. An external lock object <em>can</em> make things simpler, and is also needed if the shared resource is private, like with a collection (in which case you use the <code>ICollection.SyncRoot</code> object). </p>
28,560
<p>I need to scan uploaded files for viruses on a Linux server, but I'm not sure how to go about it.</p> <p>What are my options, if any? I'm also interested in how the scanners perform when multiple users send multiple files at the same time.</p>
<p>I would have a look at <a href="http://www.clamav.net/" rel="noreferrer">Clam AntiVirus</a>. It provides a <code>clamscan</code> program that can scan a given file and return a pass/fail indication. It's free and automatically updates its database regularly.</p> <p>As for integrating such a product into your file upload process, that would be specific to whatever file upload process you actually use.</p>
<p>You should try to find an anti-virus vendor that has a public API for it's scanner. That way you can programmatically scan a file. It will make it much easier in the long run than trying to mess with other processes via your upload script.</p>
18,325
<p>I just asked <a href="https://stackoverflow.com/questions/201686/linq-to-sql-select-optimization">this question</a>. Which lead me to a new question :)</p> <p>Up until this point, I have used the following pattern of selecting stuff with Linq to SQL, with the purpose of being able to handle 0 "rows" returned by the query:</p> <pre><code>var person = (from p in [DataContextObject].Persons where p.PersonsID == 1 select new p).FirstOrDefault(); if (person == null) { // handle 0 "rows" returned. } </code></pre> <p>But I can't use <code>FirstOrDefault()</code> when I do:</p> <pre><code>var person = from p in [DataContextObject].Persons where p.PersonsID == 1 select new { p.PersonsID, p.PersonsAdress, p.PersonsZipcode }; // Under the hood, this pattern generates a query which selects specific // columns which will be faster than selecting all columns as the above // snippet of code does. This results in a performance-boost on large tables. </code></pre> <p>How do I check for 0 "rows" returned by the query, using the second pattern? <br /> <br /> <br /> <br /> <strong>UPDATE:</strong></p> <p>I think my build fails because I am trying to assign the result of the query to a variable (<code>this._user</code>) declared with the type of <code>[DataContext].User</code>.</p> <pre><code>this._user = (from u in [DataContextObject].Users where u.UsersID == [Int32] select new { u.UsersID }).FirstOrDefault(); </code></pre> <p><em>Compilation error: Cannot implicitly convert type "AnonymousType#1" to "[DataContext].User".</em></p> <p>Any thoughts on how I can get around this? Would I have to make my own object?</p>
<p>Why can you keep doing the samething? Is it giving you an error?</p> <pre><code>var person = (from p in [DataContextObject].Persons where p.PersonsID == 1 select new { p.PersonsID, p.PersonsAdress, p.PersonsZipcode }).FirstOrDefault(); if (person == null) { // handle 0 "rows" returned. } </code></pre> <p>It is still a reference object just like you actual object, it is just anonymous so you don't know the actual type before the code is compiled.</p>
<p>You can still use <code>FirstOrDefault</code>. Just have </p> <pre><code>var PersonFields = (...).FirstOrDefault() </code></pre> <p>PersonFields will be be null or an object with those properties you created.</p>
24,656
<p>I have a problem and i would like to learn the correct way to solve this. </p> <p>I have a Data Objeckt</p> <pre><code>class LinkHolder { public string Text; public string Link; } </code></pre> <p>I would like to present to the user a RadioButton list that uses the LinkHolder.Text value as descriptive text. Then on the postback, i would like to do a </p> <pre><code>Server.Transfer( LinkHolder.Link ) </code></pre> <p>on the corresponding Link.</p> <p>I am unsure what is the best/most correct way to do this. Any hints would be appreciated.</p>
<p>You need to set DataTextField and DataValueField on your RadioButtonList. Then the correct values should show up. </p> <p>You can try to cast the selectedItem into a LinkHolder.</p>
<p>Your method should work. I think you should use accessors in your class though</p> <pre><code>class LinkHolder { public string Text { get; set;} public string Link { get; set;} } </code></pre> <p>Bind your RadioButtonList to a f.ex. <code>List&lt;LinkHolder&gt;</code></p> <p>Why would you use a radiobuttonlist instead of just listing out your Links as Hyperlinks instead of having to use Server.Transfer?</p>
44,168
<p>I often use Dictionary in C#2.0 with the first key as string that was containing a unique identifier.</p> <p>I am learning C#3.0+ and it seems that I can now simply use a List and simply do LINQ on that object to get the specific object (with the .where()).</p> <p>So, if I understand well, the Dictionary class has lost its purpose?</p>
<p>no, a dictionary is still more efficient for getting things back out given a key.</p> <p>a list you still have to iterate through the list to find what you want. A dictionary does a lookup.</p>
<p>IMHO the Dictionary approach will be MUCH faster than LINQ, so if you have an array with a lot of items, you should rather use Dictionary.</p>
30,382
<p>I am curious about what tools are used to build the next version of themselves.</p> <p>For example, Delphi has long claimed that "<a href="http://en.wikipedia.org/wiki/Borland_Delphi#Products_developed_with_Delphi" rel="nofollow noreferrer">Delphi is written in Delphi</a>".</p> <p>I assume Visual Studio is written using Visual Studio.</p> <p>What are some other examples of tools that written in themselves?</p>
<p>Interestingly, the VB.NET &amp; C# compilers themselves are written in unmanaged C++ (leading to the C++ team's T-Shirt: "My compiler compiled yours"). The C# team hopes to have a fully managed-C# hosted C# compiler for VS2010.</p>
<p><a href="http://maven.apache.org/" rel="nofollow noreferrer">Maven2</a> is built using Maven2. Ok, it's not built (i.e. <em>written</em>) using itself, as it is a tool to build (i.e. <em>compile</em>) project, but it is using its own code to compile...</p>
32,304
<p>Can someone tell me how to get path geometry from a WPF FlowDocument object? Please note that I do <strong>not</strong> want to use <code>FormattedText</code>. Thanks.</p>
<p>A <code>FlowDocument</code> can be viewed in any number of ways, but a <code>Path</code> is a fixed shape. I think maybe you really want some simplified, visual-only form of a <code>FlowDocument</code>'s contents.</p> <p>In that case you might try converting the <code>FlowDocument</code> to an XPS <code>FixedDocument</code> - the <code>FixedPage</code>s have <code>Canvas</code>es containing a bunch of <code>Path</code>s and <code>Glyph</code>s.</p>
<p>Can you use </p> <blockquote> <p>ChildVisual = VisualTreeHelper.GetChild(Visual yourVisual)</p> </blockquote> <p>Dunno if you can take a Visual and turn it into a path geometry.. </p>
9,139
<p>Java supplies standard User Interface guidelines for applications built using Java Swing. The basic guidelines are good, but I really feel the look and feel is really boring and outdated. </p> <p>Is anyone aware of a publicly available Java User Interface Guide that has better look &amp; feel guidelines than the Sun provided guidelines?</p>
<p>Along the line of Chii's answer, I would recommend taking a look at the <a href="http://msdn.microsoft.com/en-us/library/aa511258.aspx" rel="nofollow noreferrer" title="Windows Vista User Experience Guidelines">Windows Vista User Experience Guidelines</a> for general tips on making user interfaces.</p> <p>Although the name ("Windows Vista User Experience Guidelines") and source (Microsoft) may suggest that it only contains Windows-centric tips and advice, it does offer good general tips and directions that can be used when designing interfaces for non-Windows applications as well. </p> <p>The <a href="http://msdn.microsoft.com/en-us/library/aa511328.aspx" rel="nofollow noreferrer">Design Principles</a> sections address some points to keep in mind when designing an effective user interface. For example, bullet three of <a href="http://msdn.microsoft.com/en-us/library/aa511335.aspx" rel="nofollow noreferrer">How to Design a Great User Experience</a> says:</p> <blockquote> <p><strong>Don't be all things to all people</strong> Your program is going to be more successful by delighting its target users than attempting to satisfy everyone.</p> </blockquote> <p>These are the kinds of tips that apply to designing user interfaces on any platform. Of course, there are also Windows-specific guidelines as well.</p> <p>I believe one of the biggest reasons why look and feel of Swing applications seems "boring" and "outdated" is due to the platform-independent nature of Java. In order for the graphical user interfaces to work on several different platforms, Java needs to have facilities to adapt the user interface to the different host operating systems.</p> <p>For example, various platforms have various sizes for windows, buttons, and other visual components, so absolute positioning does not work too well. To combat that problem, Swing uses <a href="http://java.sun.com/docs/books/tutorial/uiswing/layout/using.html" rel="nofollow noreferrer" title="Using Layout Managers">Layout Managers</a> which (generally) use relative positioning to place the visual components on the screen.</p> <p>Despite these "limitations" of building graphical user interfaces for Java, I think that using tips from guidelines that are provided by non-Sun sources and non-Java-specific sources can still be a good source of information in designing and implementing an user interface that is effective. After all, designing an user interface is less about programming languages and more about human-machine interaction.</p>
<p>I don't think there are any other complete guidelines. But if you are not talking about the spacing/positioning of components (I don't think that part of Look And Feel Design Guidelines is outdated), but only about the look and feel good starting points are singlabx / swingx:</p> <p><a href="http://swinglabs.org" rel="nofollow noreferrer">http://swinglabs.org</a></p> <p><a href="http://swinglabs.org/docs/presentations/2007/DesktopMatters/FilthyRichClients.pdf" rel="nofollow noreferrer">http://swinglabs.org/docs/presentations/2007/DesktopMatters/FilthyRichClients.pdf</a></p> <p><a href="http://parleys.com/display/PARLEYS/Home#slide=1;talk=7643;title=Filthy%20Rich%20Clients" rel="nofollow noreferrer">http://parleys.com/display/PARLEYS/Home#slide=1;talk=7643;title=Filthy%20Rich%20Clients</a></p> <p>and JGoodies:</p> <p><a href="http://www.jgoodies.com/articles/index.html" rel="nofollow noreferrer">http://www.jgoodies.com/articles/index.html</a></p> <p><a href="http://www.jgoodies.com/articles/efficient%20swing%20design.pdf" rel="nofollow noreferrer">http://www.jgoodies.com/articles/efficient%20swing%20design.pdf</a></p>
13,855
README.md exists but content is empty. Use the Edit dataset card button to edit it.
Downloads last month
8
Edit dataset card