instruction stringlengths 21 27.8k | chosen stringlengths 18 28.2k | rejected stringlengths 18 33.6k | __index_level_0__ int64 0 50k |
|---|---|---|---|
<p>I need to design a SOAP api (my first one!). What are the best practices regarding errors returned to the caller.</p>
<p>Assuming an api as follow</p>
<pre><code>[WebMethod]
public List<someClass> GetList(String param1)
{
}
</code></pre>
<p>Should I</p>
<ul>
<li>Throw an exception. Let the SOAP infrastruct... | <p>Probably the most appropriate SOA pattern to follow would be a Fault Contract, which is essentially a Data Contract that is wrapped in the SOAPException.</p>
<p>I am posting examples in .NET, since it looks like that is what you are using (and that is what I know :) )</p>
<p>In WCF, you can define a DataContract, ... | <p>I can't give you specifies for .net (which seems to be what you're asking), but SOAP provides a mechanism for expressing strongly-typed exceptions. The SOAP fault element can have an optional FaultDetail sub-element, and this can contain arbitrary XML documents, such as your GetListError. These document types should... | 39,966 |
<p>I'm a longtime Java programmer working on a PHP project, and I'm trying to get PHPUnit up and working. When unit testing in Java, it's common to put test case classes and regular classes into separate directories, like this -</p>
<pre><code>/src
MyClass.java
/test
MyClassTest.java
</code></pre>
<p>and so... | <p>I think it's a good idea to keep your files separate. I normally use a folder structure like this:</p>
<pre><code>/myapp/src/ <- my classes
/myapp/tests/ <- my tests for the classes
/myapp/public/ <- document root
</code></pre>
<p>In your case, for including the class in your test file, ... | <p>I put my test cases next the the source in a file with the same name but a .phpt extension. The deployment script simply filters out *.phpt when they push to production.</p>
| 9,135 |
<p>I am working on writing a Highly Available agent for JBoss Application Server to run on Solaris Open HA Cluster. As I don't know much of the JBoss AS, can someone please tell me how can I probe the status of the application server?</p>
<p>I want to know the health of the application server, for example whether it i... | <p>Out of the box, JBoss has a JMX console that provides information about the modules loaded into the micro-kernel and the services that are running. This application is usually available at <a href="http://hostname:8080/jmx-console" rel="nofollow noreferrer">http://hostname:8080/jmx-console</a>, and you could concei... | <p>Thanks for the answer. </p>
<p>One way to check for the status of the JBOSS server would be to probe the JBOSS port (it can be port of any essential service, eg. like JNDI service) with a TCP socket request. If port is busy means JBOSS is up else otherwise.</p>
<p>This, I figured out, is more programmable way of c... | 24,459 |
<p>Part of my application maps resources stored in a number of locations onto web URLs like this:</p>
<pre><code>http://servername/files/path/to/my/resource/
</code></pre>
<p>The resources location is modelled after file paths and as a result there can be an unlimited level of nesting. Is it possible to construct an ... | <p>A route like</p>
<pre><code>"Files/{*path}"
</code></pre>
<p>will get the path as a single string. The <code>*</code> designates it as a wildcard mapping and it will consume the whole URL after <code>"Files/"</code>.</p>
| <p>For more information on ASP.NET's Routing feature, please see MSDN:</p>
<p><a href="http://msdn.microsoft.com/en-us/library/cc668201.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/cc668201.aspx</a></p>
<p>And for the "catch-all" parameters you want to use, see the section under "Handling a... | 41,858 |
<p>Requirements:</p>
<ul>
<li>free, preferably open-source</li>
<li>implemented in one of the .NET managed langs</li>
</ul>
<p>Google found these:</p>
<ul>
<li><a href="http://www.codeproject.com/KB/recipes/diffengine.aspx" rel="noreferrer">A Generic, Reusable Diff
Algorithm</a> on codeproject</li>
<li><a href="http... | <p>You can grab <a href="https://stackoverflow.com/questions/848246/how-can-i-use-javascript-within-an-excel-macro">the COM component that uses Google's Diff/Patch/Match</a>. It works from .NET. </p>
<p><strong>Update, 2010 Oct 17</strong>: The <a href="http://code.google.com/p/google-diff-match-patch/" rel="noreferr... | <p>GitSharp includes a diff engine based on meyers diff. Take a look at the demo which implements a simple wpf diff viewer based on the Diff.Sections collection: <a href="http://www.eqqon.com/index.php/GitSharp#GitSharp.Demo" rel="noreferrer">http://www.eqqon.com/index.php/GitSharp#GitSharp.Demo</a></p>
| 16,745 |
<p>I'm thinking of starting a wiki, probably on a low cost LAMP hosting account. I'd like the option of exporting my content later in case I want to run it on <code>IIS/ASP.NET</code> down the line. I know in the weblog world, there's an open standard called BlogML which will let you export your blog content to an <str... | <p>The correct answer is ... "it depends".</p>
<p>It depends on which wiki you're using or planning to use. I've used various over the years <a href="http://moinmo.in/" rel="noreferrer">MoinMoin</a> was ok, used files rather than database, <a href="https://help.ubuntu.com/" rel="noreferrer">Ubuntu</a> seem to like it... | <p>I haven't heard of WikiML.</p>
<p>I think your biggest obstacle is gonna be converting one wiki markup to another. For example, some wikis use markdown (which is what Stack Overflow uses), others use another markup syntax (e.g. BBCode, ...), etc.. The bottom line is - assuming the contents are databased it's not im... | 5,980 |
<p>I want to use the <a href="http://nltk.sourceforge.net/index.php/Main_Page" rel="noreferrer">nltk</a> libraries in c++. </p>
<p>Is there a glue language/mechanism I can use to do this? </p>
<p>Reason:
I havent done any serious programming in c++ for a while and want to revise NLP concepts at the same time.</p>
<... | <p>You can also try the <a href="http://www.boost.org/doc/libs/1_37_0/libs/python/doc/index.html" rel="noreferrer">Boost.Python</a> library; which has <a href="http://www.boost.org/doc/libs/1_37_0/libs/python/doc/v2/callbacks.html" rel="noreferrer">this capability</a>. This library is mainly used to expose C++ to Pytho... | <p>I haven't tried directly calling Python functions from C++, but here are some alternative ideas...</p>
<p>Generally, it's easier to call C++ code from a high-level language like Python than the other way around. If you're interested in this approach, then you could create a C++ codebase and access it from Python. ... | 38,004 |
<p>So I have a small C# app that needs to periodically check the contents of directories on multiple machines on the network. I thought I could just read \hostname\C$ as a directory path, but with the normal Directory class there doesn't seem to be a way to authenticate against the other servers so you can access the ... | <p>From <a href="http://bytes.com/forum/thread689145.html" rel="nofollow noreferrer">http://bytes.com/forum/thread689145.html</a>:</p>
<blockquote>
<p>All processes run in the context of a
logged-in user account. If you want to
open a file on another computer, your
application must be running in the
context of a user t... | <p>Are you looking for a way to set the current user at run-time?</p>
<p>If not, as long as the user running the process has access to those machines, this will work for you:</p>
<pre><code>DirectoryInfo di = new DirectoryInfo(@"\\machineName\c$\temp");
FileInfo[] files = di.GetFiles();
foreach (FileInfo f in files... | 16,954 |
<p>I have a string. I need to replace all instances of a given array of strings from this original string - how would I do that?</p>
<p>Currently I am using...</p>
<pre><code>var inputString = "this is my original string.";
var replacement = "";
var pattern = string.Join("|", arrayOfStringsToRemove);
Regex.Replace(i... | <p>Build the pattern using Regex.Escape:</p>
<pre><code>StringBuilder pattern = new StringBuilder();
foreach (string s in arrayOfStringsToRemove)
{
pattern.Append("(");
pattern.Append(Regex.Escape(s));
pattern.Append(")|");
}
Regex.Replace(inputString, pattern.ToString(0, pattern.Length - 1), // remove tra... | <p>You need to escape special characters with a backslash</p>
<pre><code>\
</code></pre>
<p>Sometimes you may need to use two backslashes</p>
<pre><code>\\
</code></pre>
| 46,803 |
<p>I have a Prusa i3 MK3 or maybe it was upgraded to a i3 MK3S.</p>
<p>How can I figure out?</p>
<p>The <a href="https://shop.prusa3d.com/en/original-prusa-i3-mk3s/1390-original-prusa-i3-mk3-to-mk3s-upgrade-kit.html" rel="nofollow noreferrer">description of the upgrade kit</a> talks about</p>
<ul>
<li>the SuperPINDA (h... | <p><a href="https://i.stack.imgur.com/1ldX4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1ldX4.png" alt="Left right" /></a></p>
<p><a href="https://i.stack.imgur.com/TtrmF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TtrmF.png" alt="Filament sensors" /></a></p>
<p>The MK3 has... | <p>On the LCD, the MK3 will show <strong>Original Prusa MK3 OK</strong>, while the MK3S/+ will show <strong>Original Prusa MK3S OK</strong></p>
| 1,985 |
<p>If something goes wrong in a WCF REST call, such as the requested resource is not found, how can I play with the HTTP response code (setting it to something like HTTP 404, for example) in my OperationContract method?</p>
| <p>There is a <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.web.weboperationcontext.aspx" rel="noreferrer"><code>WebOperationContext</code></a> that you can access and it has a <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.web.weboperationcontext.outgoingresponse.aspx" rel=... | <p>This did not work for me for WCF Data Services. Instead, you can use DataServiceException in case of Data Services. Found the following post useful.
<a href="http://social.msdn.microsoft.com/Forums/en/adodotnetdataservices/thread/f0cbab98-fcd7-4248-af81-5f74b019d8de" rel="nofollow">http://social.msdn.microsoft.com/F... | 16,951 |
<p>So I was reading these Asp.Net <a href="http://www.hanselman.com/blog/ASPNETInterviewQuestions.aspx" rel="nofollow noreferrer">interview questions</a> at Scott Hanselman's blog and I came across this question. Can anyone shed some light of what he's talking about.</p>
| <pre><code><asp:LinkButton ID="lbEdit" CssClass="button"
OnClientClick="javascript:alert('do something')"
onclick="OnEdit" runat="server">Edit</asp:LinkButton>
</code></pre>
<p>The <code>OnClientClick</code> attribute means you can add some JavaSc... | <p>I think what he's asking here is how you wire up javascript functions to work hand in hand with your ASP.NET postback functionality.</p>
<p>i.e. How can I trigger a control's event using my own JavaScript?</p>
<p>The ASP.NET class library contains a <code>ClientScript</code> class - Found in the <code>System.Web.UI.... | 12,513 |
<p>Is their a way to use a non-member non-friend function on an object using the same "dot" notation as member functions?</p>
<p>Can I pull a (any) member out of a class, and have users use it in the same way they always have?</p>
<p>Longer Explanation:</p>
<p><a href="http://www.ddj.com/cpp/184401197" rel="nofollow... | <p>Yes, it means that part of the interface of an object is composed of non member functions.</p>
<p>And you're right about the fact it involves the use of the following notation, for an object of class T:</p>
<pre><code>void T::doSomething(int value) ; // method
void doSomething(T & t, int value) ; // non-memb... | <p>Yes, they should be either global or namespace-scoped.
Non-member non-friend functions look much prettier in C# where they do use dot notation (they are called <a href="http://en.wikipedia.org/wiki/Extension_method" rel="nofollow noreferrer">extension methods</a>).</p>
| 43,068 |
<p>Is there a way to make sure a (large, 300K) background picture is always displayed first BEFORE any other content is shown on the page?</p>
<p>On the server we have access to PHP.</p>
| <p>All the html content is served and parsed before it even starts to fetch the image, so you have a problem before you start. </p>
<p>You could circumvent this by programmatically hiding the content, and then triggering a "show" of it when the image is loaded. </p>
<p>ie: </p>
<pre><code><html>
<body>... | <p>I think the only way you'll be able to do this is with javascript - Send the user HTML that only contains your background image and some javascript that either waits for a certain amount of time before displaying the rest of the content or uses AJAX to retrieve the rest of the content (essentially the same thing).</... | 24,484 |
<p>I was trying to use the slime-connect function to get access to a remote server with sbcl. I followed all the steps from the slime.mov movie from <a href="http://www.guba.com/watch/30000548671" rel="noreferrer">Marco Baringer,</a> but I got stuck when creating the ssh connection for slime. This is after already star... | <p>I don't know, but you can try to connect to swank on remote machine locally. </p>
<pre><code>ssh user@server.com
telnet 127.0.0.1:4005
</code></pre>
<p>May be there you will find errors. Also you can try localhost:4005 instead of 127.0.0.1 and check if localhost interface is properly configured.</p>
| <p>For me the problem was that the <code>slime</code> (v2.22) function from Emacs started with additional argument <code>from-emacs t</code> which <code>swank-loader.lisp</code> didn't support (v2.22). </p>
<p>What worked for me is editing of <code>slime-v2.22/swank-loader.lisp:init</code> to accept one new argument <... | 48,731 |
<p>I`ve read that columns that are chosen for indices should discriminate well among the rows, i.e. index columns should not contain a large number of rows with the same value. This would suggest that booleans or an enum such as gender would be a bad choice for an index. </p>
<p>But say I want to find users by gender ... | <p>Indexing a low-cardinality column to improve search performance is common in my world. Oracle supports a "bitmapped index" which is designed for these situations. See <a href="http://www.dba-oracle.com/art_9i_indexing.htm" rel="nofollow noreferrer">this article</a> for a short overview. </p>
<p>Most of my experienc... | <p>This is a case where I would let the server statistics inform me of when to create the index. Unless you know that this query is going to predominate or that running such a query would not meet your performance goals a priori, then creating the index prematurely may just cost you performance rather than increase it... | 39,098 |
<p>What is the best compression algorithm that allows random reads/writes in a file?</p>
<p>I know that any adaptive compression algorithms would be out of the question.</p>
<p>And I know huffman encoding would be out of the question.</p>
<p>Does anyone have a better compression algorithm that would allow random rea... | <p>I am stunned at the number of responses that imply that such a thing is impossible.</p>
<p>Have these people never heard of "compressed file systems",
which have been around since before Microsoft was sued in 1993 by Stac Electronics over compressed file system technology?</p>
<p>I hear that <a href="http://en.wik... | <p>I don't know of any compression algorithm that allows random reads, never mind random writes. If you need that sort of ability, your best bet would be to compress the file in chunks rather than as a whole. </p>
<p>e.g.<br>We'll look at the read-only case first. Let's say you break up your file into 8K chunks. You c... | 29,261 |
<p>We are developing a web application which is available in 3 languages. </p>
<p>There are these key-value pairs to translate everything. At this moment we use Excel (key, german, french, english) for this. But this does not work well ... if there is more than 1 person editing this file, you have no chance to automat... | <p>Why not use <a href="http://www.gnu.org/software/gettext/" rel="nofollow noreferrer">gettext</a> and manage separate .po files? See that <a href="http://mel.melaxis.com/devblog/2005/08/06/localizing-php-web-sites-using-gettext/" rel="nofollow noreferrer">blog entry</a>.</p>
| <p>Good Question.
There are some "Best Practice" depending on what you actually code in (java, ms-windows c#).</p>
<p>I solved this (but I think there must be a better way) by using a SQL db instead of excel file, and a wrote a plug for VS (VB6,........,..., emacs) that was able to insert new keys into the db without... | 33,169 |
<p>In <code>C</code> can I <strong>pass a multidimensional array</strong> to a function <strong>as a single argument</strong> when I don't know what the dimensions of the array are going to be?</p>
<p>Besides, my multidimensional array may contain types other than strings.</p>
| <p>You can do this with any data type. Simply make it a pointer-to-pointer:</p>
<pre><code>typedef struct {
int myint;
char* mystring;
} data;
data** array;
</code></pre>
<p>But don't forget you still have to malloc the variable, and it does get a bit complex:</p>
<pre><code>//initialize
int x,y,w,h;
w = 10; //... | <pre><code>int matmax(int **p, int dim) // p- matrix , dim- dimension of the matrix
{
return p[0][0];
}
int main()
{
int *u[5]; // will be a 5x5 matrix
for(int i = 0; i < 5; i++)
u[i] = new int[5];
u[0][0] = 1; // initialize u[0][0] - not mandatory
// put data in u[][]
printf("%d", ... | 2,606 |
<p>I have a string "1112224444' it is a telephone number. I want to format as 111-222-4444 before I store it in a file. It is on a datarecord and I would prefer to be able to do this without assigning a new variable.</p>
<p>I was thinking:</p>
<pre><code>String.Format("{0:###-###-####}", i["MyPhone"].ToString() );
</... | <p>I prefer to use regular expressions:</p>
<pre><code>Regex.Replace("1112224444", @"(\d{3})(\d{3})(\d{4})", "$1-$2-$3");
</code></pre>
| <p>Here is an improved version of @Jon Skeet answer with null checks and has a extension method.</p>
<pre class="lang-csharp prettyprint-override"><code>public static string ToTelephoneNumberFormat(this string value, string format = "({0}) {1}-{2}") {
if (string.IsNullOrWhiteSpace(value))
{
return va... | 22,859 |
<p>I am trying to establish a basic .NET Remoting communication between 2x 64bit windows machines. If Machine1 is acting as client and Machine2 as server, then everything works fine. The other way around the following exception occurs:</p>
<p>System.Net.Sockets.SocketException: No connection could be made because the ... | <p>Windows Firewall? (Question author says this is not it.)</p>
<p>To track down connection issues the standard approach applies (apply in any order):</p>
<ul>
<li>ping the machine</li>
<li>double check if some process really is listening in port 6666 (<code>netstat -an</code>)</li>
<li>telnet the machine on port 666... | <p>Windows Firewall? (Question author says this is not it.)</p>
<p>To track down connection issues the standard approach applies (apply in any order):</p>
<ul>
<li>ping the machine</li>
<li>double check if some process really is listening in port 6666 (<code>netstat -an</code>)</li>
<li>telnet the machine on port 666... | 35,999 |
<p>I'm in need of a distributed file system that must scale to very large sizes (about 100TB realistic max). Filesizes are mostly in the 10-1500KB range, though some files may peak at about 250MB.</p>
<p>I very much like the thought of systems like GFS with built-in redundancy for backup which would - statistically - ... | <p>Do you absolutely need to host this on your own servers? Much of what you need could be provided by Amazon S3. The delayed delete feature could be implemented by recording deletes to a SimpleDB table and running a garbage collection pass periodically to expunge files when necessary. </p>
<p>There is still a single ... | <p>You could try running a source control system on top of your reliable file system. The problem then becomes how to expunge old check ins after your timeout. You can setup an Apache server with DAV_SVN and it will commit each change made through the DAV interface. I'm not sure how well this will scale with large file... | 42,235 |
<p>Setup is SQL2005 SP2 with Reporting Services installed local on Win2003 64bit.
When users browse report manager on <a href="http://server/reports" rel="nofollow noreferrer">http://server/reports</a> they get login dialog for every request, but only if they use IE7. In FireFox all works.</p>
<p>The site is in "local... | <p>After reading what the error code means thanks to the answer from VonC I understood where to look. The problem was a lot more obscure that it seems.</p>
<p>I looked into the configuration folder for Eclipse (logs are either written there or in the .metadata folder when something goes wrong), and I found a huge log... | <p>It should mean "<strong><em>ant</em></strong> <strong>build failed</strong>", meaning the headless ant script fails at some point.</p>
<p>You should check if you can catch the log/output generated by this script to analyze this ant session and see at what point the ant script fails.</p>
<hr>
<p>If it fails right ... | 48,905 |
<p>I'm re-designing an app I inherited that sends digital photos from a laptop to a web server. The idea is to take photos "out on the field" and have them instantly published on a web page (with some more fancy features).</p>
<p>Typical scenario<br>
1. Photos are transferred from the camera to the laptop using standa... | <p>I'd avoid using HTTP at all from any thread that has UI unless you actually want to block until the response is received. You can try using the same logic from a background thread which will run as long as it needs to. Just be sure to have logic which will detect when the connection is lost (probably from a timeout)... | <p>Firstly, I would put the transfer process outside of the application. Sync files with a utility that allows it to restart transfer from the middle of the last transfer.
<br><br>
You can simulate communication drops with some type of <a href="http://en.wikipedia.org/wiki/Faraday_cage" rel="nofollow noreferrer">Farad... | 35,510 |
<p>I was asked this question during an interview. They're both O(nlogn) and yet most people use Quicksort instead of Mergesort. Why is that?</p>
| <p>Quicksort has O(<i>n</i><sup>2</sup>) worst-case runtime and O(<i>n</i>log<i>n</i>) average case runtime. However, it’s superior to merge sort in many scenarios because many factors influence an algorithm’s runtime, and, when taking them all together, quicksort wins out.</p>
<p>In particular, the often-quoted runti... | <p>In c/c++ land, when not using stl containers, I tend to use quicksort, because it is built
into the run time, while mergesort is not.</p>
<p>So I believe that in many cases, it is simply the path of least resistance.</p>
<p>In addition performance can be much higher with quick sort, for cases where the entire data... | 9,579 |
<pre><code>int i = 4;
string text = "Player ";
cout << (text + i);
</code></pre>
<p>I'd like it to print <code>Player 4</code>.</p>
<p>The above is obviously wrong but it shows what I'm trying to do here. Is there an easy way to do this or do I have to start adding new includes?</p>
| <p>Well, if you use cout you can just write the integer directly to it, as in</p>
<pre><code>std::cout << text << i;
</code></pre>
<p>The C++ way of converting all kinds of objects to strings is through <a href="http://en.cppreference.com/w/cpp/io/basic_stringstream" rel="noreferrer">string streams</a>. I... | <p>There are a few options, and which one you want depends on the context.</p>
<p>The simplest way is</p>
<pre><code>std::cout << text << i;
</code></pre>
<p>or if you want this on a single line</p>
<pre><code>std::cout << text << i << endl;
</code></pre>
<p>If you are writing a singl... | 9,038 |
<p>I'm building a small web app in PHP that stores some information in a plain text file. However, this text file is used/modified by all users of my app at some given point in time and possible at the same time.</p>
<p>So the questions is. What would be the best way to make sure that only one user can make changes to... | <p>You should put a lock on the file</p>
<pre><code> $fp = fopen("/tmp/lock.txt", "r+");
if (flock($fp, LOCK_EX)) { // acquire an exclusive lock
ftruncate($fp, 0); // truncate file
fwrite($fp, "Write something here\n");
fflush($fp); // flush output before releasing the lock
flock($... | <p>A single file for many users really shouldn't be the strategy you use I don't think - otherwise you'll probably need to implement a single (global) access point that monitors if the file is currently being edited or not. Aquire a lock, do your modification, release the lock etc. I'd go with 'Nobody's suggestion to u... | 37,474 |
<p>I have a tree of active record objects, something like:</p>
<pre><code>class Part < ActiveRecord::Base
has_many :sub_parts, :class_name => "Part"
def complicated_calculation
if sub_parts.size > 0
return self.sub_parts.inject(0){ |sum, current| sum + current.complicated_calculation }
else... | <p>I suggest using association callbacks.</p>
<pre><code>class Part < ActiveRecord::Base
has_many :sub_parts,
:class_name => "Part",
:after_add => :count_sub_parts,
:after_remove => :count_sub_parts
private
def count_sub_parts
update_attribute(:sub_part_count, calculate_sub_part_cou... | <p>I've found that sometimes there is good reason to de-normalize information in your database. I have something similar in an app that I am working on and I just re-calculate that field anytime the collection changes. </p>
<p>It doesn't use a cache and it stores the most up to date figure in the database. </p>
| 21,850 |
<p>What does it mean when a <a href="http://en.wikipedia.org/wiki/PostgreSQL" rel="noreferrer">PostgreSQL</a> process is "idle in transaction"?</p>
<p>On a server that I'm looking at, the output of "ps ax | grep postgres" I see 9 PostgreSQL processes that look like the following:</p>
<pre><code>postgres: user db 127.... | <p>The <a href="http://www.postgresql.org/docs/8.3/interactive/monitoring-ps.html" rel="noreferrer">PostgreSQL manual</a> indicates that this means the transaction is open (inside BEGIN) and idle. It's most likely a user connected using the monitor who is thinking or typing. I have plenty of those on my system, too.<... | <p>As mentioned here: <a href="http://archives.postgresql.org/pgsql-bugs/2008-06/msg00102.php" rel="noreferrer">Re: BUG #4243: Idle in transaction</a> it is probably best to check your pg_locks table to see what is being locked and that might give you a better clue where the problem lies.</p>
| 7,386 |
<p>What's the shortest Perl one-liner that print out the first 9 powers of a hard-coded 2 digit decimal (say, for example, .37), each on its own line? </p>
<p>The output would look something like:</p>
<pre><code>1
0.37
0.1369
[etc.]
</code></pre>
<p>Official Perl golf rules:</p>
<ol>
<li>Smallest number of (key)st... | <p>With perl 5.10.0 and above:</p>
<pre><code>perl -E'say 0.37**$_ for 0..8'
</code></pre>
<p>With older perls you don't have <code>say</code> and -E, but this works:</p>
<pre><code>perl -le'print 0.37**$_ for 0..8'
</code></pre>
<p>Update: the first solution is made of 30 key strokes. Removing the first 0 gives 29... | <pre><code>perl -e "for(my $i = 1; $i < 10; $i++){ print((.37**$i). \"\n\"); }"
</code></pre>
<p>Just a quick entry. :)</p>
<p>Fixed to line break!</p>
| 25,782 |
<p>Will the individual UML diagram shapes be NSView subclasses or NSBezierPaths? How are the diagrams created and managed?</p>
| <p>One way to do this is to:</p>
<ul>
<li>Create a document-based app</li>
<li>Design model classes for the different objects the end-user will be able to draw in your canvas, all sharing one abstract superclass</li>
<li>In your CanvasView class, implement drawRect and have it call the NSDocument subclass, or for more... | <p>Have you looked at OmniGraffle? It may do what you need.</p>
<p>[non-programming-related answer...]</p>
| 39,598 |
<p>I know in ASP.NET I can get an item from a DropDownList by using</p>
<pre><code>DropDownList1.Items.FindByText
</code></pre>
<p>Is there a similar method I can use in WPF for a ComboBox?</p>
<p>Here's the scenario.</p>
<p>I have a table called RestrictionFormat that contains a column called RestrictionType, the ... | <p>Can you use ItemContainerGenerator?</p>
<p>ItemContainerGenerator contains a ContainerFromItem method that takes an object parameter. If you have a reference to the full object that your comboBox contains (or a way to reconstruct it), you can use the following:</p>
<pre><code>ComboBoxItem item =
(ComboBoxIte... | <p>You can retrieve combobox items in two ways:</p>
<p>By item:</p>
<pre><code>ComboBoxItem item = (ComboBoxItem) control.ItemContainerGenerator.ContainerFromItem(control.SelectedItem);
</code></pre>
<p>By index:</p>
<pre><code>ComboBoxItem item = (ComboBoxItem) control.ItemContainerGenerator.ContainerFromIndex(1);... | 6,260 |
<p>I'm currently logging via the simplest of methods within my servlet using Tomcat. I use the ServletConfig.getServletContext().log to record activity. This writes to the localhost.YYYY-MM-DD.log in $TOMCAT_HOME/logs.</p>
<p>I don't want to get away from the simplicity of this logging mechanism unless absolutely ne... | <p>This question is old, but I figured it was valuable to have the correct answer here.</p>
<p>Filip is confusing server-side Java with client-side Java. He is correct that you cannot share sessions between two server-side platforms, such as Java (J2EE) and ASP.Net without using a custom approach.</p>
<p>However, app... | <p>Filip's answer isn't entirely correct. I ran a program to sniff the HTTP headers on my workstation, and the Java applet does in fact present the ASP.NET authentication ticket in some circumstances - just not reliably enough for my needs.</p>
<p>Eventually I did find a solution to this, but it didn't entirely solve ... | 24,637 |
<p>Does anyone have tools or experience with code coverage for PL/SQL. I believe this is possible using DBMS_PROFILER?</p>
| <p><a href="http://www.toadworld.com/BLOGS/tabid/67/EntryID/267/Default.aspx" rel="noreferrer">http://www.toadworld.com/BLOGS/tabid/67/EntryID/267/Default.aspx</a> has info about checking code coverage using the PL/SQL profiler. </p>
<p>Some helpful info about profiling on 9i or 10g is included in Metalink Article 243... | <p>With Oracle 12.2c now you can use <strong>DBMS_PLSQL_CODE_COVERAGE</strong> package. In fact, this provides basic-block level coverage.</p>
<p>Basic-block is the smallest executable code.</p>
<p>These are few references to find more information.</p>
<p><a href="https://docs.oracle.com/en/database/oracle/oracle-datab... | 18,391 |
<p>I have to delete some rows from a data table. I've heard that it is not ok to change a collection while iterating through it. So instead of a for loop in which I check if a row meets the demands for deletion and then mark it as deleted, I should first iterate through the data table and add all of the rows in a list,... | <p>Iterating Backwards through the List sounds like a better approach, because if you remove an element and other elements "fall into the gap", that does not matter because you have already looked at those. Also, you do not have to worry about your counter variable becoming larger than the .Count.</p>
<pre><code> ... | <p>When I need to remove an item from a collection that I am enumerating I usually enumerate it in reverse.</p>
| 39,736 |
<p>I've had a hard time trying to find good examples of how to manage database schemas and data between development, test, and production servers.</p>
<p>Here's our setup. Each developer has a virtual machine running our app and the MySQL database. It is their personal sandbox to do whatever they want. Currently, deve... | <p>There are a couple of good options. I wouldn't use the "restore a backup" strategy.</p>
<ol>
<li><p>Script all your schema changes, and have your CI server run those scripts on the database. Have a version table to keep track of the current database version, and only execute the scripts if they are for a newer ve... | <p>I've written a tool which (by hooking into <a href="http://www.codeplex.com/OpenDBiff" rel="nofollow noreferrer">Open DBDiff</a>) compares database schemas, and will suggest migration scripts to you. If you make a change that deletes or modifies data, it will throw an error, but provide a suggestion for the script (... | 2,811 |
<p>I'm currently playing around with <a href="http://pear.php.net/package/HTML_QuickForm" rel="noreferrer">HTML_QuickForm</a> for generating forms in PHP. It seems kind of limited in that it's hard to insert my own javascript or customizing the display and grouping of certain elements.</p>
<p>Are there any alternativ... | <p>If you find it hard to insert Javascript into the form elements, consider using a JavaScript framework such as <a href="http://www.prototypejs.org/" rel="nofollow noreferrer">Prototype</a> or <a href="http://jquery.com/" rel="nofollow noreferrer">jQuery</a>. There, you can centralize the task of injecting event hand... | <p>I can't really say anything about it but, the other day, I ran across the <a href="http://www.phpformclass.com/page/index" rel="nofollow noreferrer">clonefish</a> form library. It looked promising enough to end up in my bookmarks list as a "look at this later".</p>
| 8,524 |
<p>In my multithreaded application and I see heavy lock contention in it, preventing good scalability across multiple cores. I have decided to use lock free programming to solve this.</p>
<p>How can I write a lock free structure?</p>
| <p>Short answer is:</p>
<p>You cannot.</p>
<p>Long answer is:</p>
<p>If you are asking this question, you do not probably know enough to be able to create a lock free structure. Creating lock free structures is extremely hard, and only experts in this field can do it. Instead of writing your own, search for an exist... | <p>Well, it depends on the kind of structure, but you have to make the structure so that it carefully and silently detects and handles possible conflicts.</p>
<p>I doubt you can make one that is 100% lock-free, but again, it depends on what kind of structure you need to build.</p>
<p>You might also need to shard the ... | 11,787 |
<p>I am using the ADONetAppender to (try) to log data via a stored procedure (so that I may inject logic into the logging routine).</p>
<p>My configuration settings are listed below. Can anybody tell what I'm doing wrong?</p>
<pre class="lang-xml prettyprint-override"><code><appender name="ADONetAppender_SqlServer... | <p>Use "AnsiString" as dbType for varchar. "String" for nvarchar.</p>
<p><a href="http://msdn.microsoft.com/en-us/library/system.data.dbtype%28v=VS.90%29.aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/system.data.dbtype%28v=VS.90%29.aspx</a></p>
| <p>
</p>
<pre><code></configSections>
<log4net>
<appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
<bufferSize value="1"/>
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.5000.0,Culture=neutral, PublicKe... | 15,744 |
<p>I have a problem redrawing a custom view in simple cocoa application. Drawing is based on one parameter that is being changed by a simple NSSlider. However, although i implement -setParameter: and -parameter methods and bind slider's value to that parameter in interface builder i cannot seem to make a custom view to... | <p>The usual syntax is: <code>[self setNeedsDisplay:YES]</code>, although I would assume that that means the same thing. Are you implementing the <code>- (void)drawRect:(NSRect)rect</code> method, or using the <code>drawRect:</code> method of your superclass?</p>
| <p>In the iOS 6 there isn't such function to call: <code>setNeedsDisplay:YES</code>. I've got the same problem, and came with this solution: <a href="https://stackoverflow.com/a/15027374/1280800">https://stackoverflow.com/a/15027374/1280800</a> .</p>
<p>Hope it will help.</p>
| 42,414 |
<p>I am trying to connect to 2 databases on the same instance of MySQL from 1 PHP script.</p>
<p>At the moment the only way I've figured out is to connect to both databases with a different user for each.</p>
<p>I am using this in a migration script where I am grabbing data from the original database and inserting it... | <p>You'll need to pass a boolean true as the optional fourth argument to mysql_connect(). See <a href="http://php.net/mysql_connect" rel="noreferrer">PHP's mysql_connect() documentation</a> for more info.</p>
| <p>First Connect Two Database</p>
<pre><code>$database1 = mysql_connect("localhost","root","password");
$database2 = mysql_connect("localhost","root","password");
</code></pre>
<p>Now Select The Database </p>
<pre><code>$database1_select = mysql_select_db("db_name_1") or die("Can't Connect To Database",$database1);
... | 29,120 |
<p>We have a warm sql backup. full backup nightly, txn logs shipped every so often during the day and restored. I need to move the data files to another disk. These DB's are in a "warm backup" state (such that I can't unmark them as read-only - "Error 5063: Database '<dbname>' is in warm standby. A warm-standby d... | <p>The only solution I know is to create a complete backup of your active database and restore this backup to a copy of the database in a 'warm backup' state. First create a backup from the active db:</p>
<pre><code>backup database activedb to disk='somefile'
</code></pre>
<p>Then restore the backup on another sql se... | <p>It looks like you didn't complete the restore task , just do the restore task only for the TRANSACTOINAL LOG .Then it will be fine immediately when you finish that.</p>
| 13,013 |
<p>I'm currently adding verbose tooltips to our site, and I'd like (without having to resort to a whizz-bang jQuery plugin, I know there are many!) to use carriage returns to format the tooltip.</p>
<p>To add the tip I'm using the <code>title</code> attribute. I've looked around the usual sites and using the basic tem... | <p>It’s simple: just press <kbd>Enter</kbd>!</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code><a href="#" title='Tool
Tip
On
New
Line'>link with tip</a></code>... | <p>Use <code>data-html="true"</code> and apply <code><br></code>.</p>
| 46,800 |
<p>just wanted to gather different ideas and perspectives as to which layer should (and why) LINQ fall into?</p>
| <p>it depends on what you want to do with linq. when using linq2sql i`d recommend the DAL, but Linq is more than just database access. you can use it to manipulate lists, ienumerables of business objects and so on... Linq itself can be useful everywhere in your application.</p>
| <p>I think LINQ should be the very lower-level (DAL) and I think it should be wrapped into a BLL.</p>
<p>I know a lot of people like to use the partial accessibility of the models that LINQ to SQL generates but I think you should have clear separation of interests (see what I did there?). I think if you're going to h... | 21,071 |
<p>If a part is wanted to be made the strongest possible, what slicer settings should be used? </p>
<ul>
<li><p>3-5 shells vs all shells, no infill? </p></li>
<li><p>100% infill vs some other % infill?</p></li>
<li><p>Thin layer height vs thick layer height?</p></li>
<li><p>Any other relevant settings?</p></li>
</ul... | <p>If your real question is what would be the strongest then I say - the solid would be the strongest - no doubt.</p>
<p>But if the question is: </p>
<ul>
<li>what be the strongest in comparison to weight or</li>
<li>what is the strongest in comparison to the cost (amount of material)</li>
</ul>
<p>then these are go... | <p>This question is practically unanswerable without the load case or the part being known.</p>
<p>Input for the "strongest" part is depending on:</p>
<ul>
<li>Load case (compression, tension, shear)</li>
<li>Part design</li>
<li># of perimeters</li>
<li>Filament type</li>
<li>Infill percentage (incl. local increased... | 491 |
<p>Vista has introduced a new API to display a text in the list view control when it doesn't have any items. As the MSDN library states, I should process the <code>LVN_GETEMPTYMARKUP</code> notification.</p>
<p>In the inherited <code>ListView</code> control the <code>WndProc</code> method is overriden:</p>
<pre><code... | <p><code>WM_NOTIFY</code> messages are not sent to the control (the listview), but rather to the parent (the form). This made sense in the Win32 world because these messages are very useful to intercept but it was moderately painful to subclass the control, especially when you wanted different behaviour in each case. ... | <p>Have you tried calling <code>SetWindowTheme</code> on the control, as indicated in <a href="http://msdn.microsoft.com/en-us/magazine/cc163384.aspx" rel="nofollow noreferrer">this article</a>?</p>
| 36,541 |
<p>I'm looking for suggestions on how to debug and chase down deadlock issues in an SQL Server 2000 database. I've had it recommended to me to use trace flags 1024 and 3605, which I have found give me the following:</p>
<p>1024 - this trace flag returns the type of locks participating in the deadlock and the current ... | <p>Here is the bible on deadlock troubleshooting: <a href="http://blogs.msdn.com/bartd/archive/2006/09/09/Deadlock-Troubleshooting_2C00_-Part-1.aspx" rel="nofollow noreferrer">http://blogs.msdn.com/bartd/archive/2006/09/09/Deadlock-Troubleshooting_2C00_-Part-1.aspx</a></p>
| <p>Once you know the sql statements involved, a code analysis will surely help. Some thumb rules are checking for the order in which the rows are accessed and checking for the isolation level used for the SQL statements. A profiler trace can help a lot.</p>
<p>Most of the time, it is because of a reader trying to get ... | 7,581 |
<p>My table structure looks like this:</p>
<pre><code> tbl.users tbl.issues
+--------+-----------+ +---------+------------+-----------+
| userid | real_name | | issueid | assignedid | creatorid |
+--------+-----------+ +---------+------------+-----------+
| 1 | test_1 | | ... | <pre><code>SELECT
IssueID,
AssignedID,
CreatorID,
AssignedUser.real_name AS AssignedName,
CreatorUser.real_name AS CreatorName
FROM Issues
LEFT JOIN Users AS AssignedUser
ON Issues.AssignedID = AssignedUser.UserID
LEFT JOIN Users AS CreatorUser
ON Issues.CreatorID = CreatorUser.User... | <pre><code>SELECT DISTINCT (i.issueid, i.creatorid, i.assignedid, u.real_name)
FROM issues i, users u
WHERE u.userid = i.creatorid OR u.userid = assignedid
ORDER BY i.issueid ASC
LIMIT 0 , 30
</code></pre>
<p>Not sure if the parenthesis are needed or not.</p>
| 31,705 |
<p>How do I create an ASP.NET web service that returns JSON formatted data?</p>
| <p>The most important thing to understand is to know how to represent data in JSON format.
Please refer <a href="http://www.json.org/" rel="nofollow noreferrer">http://www.json.org/</a> to know more about it.</p>
<p>Once you understand this, then the rest part is pretty straight forward.</p>
<p>Please check the foll... | <p>In our project the requirements were as follow -- ASP.NET 2.0 on the server, and pure Javascript on the browser (no JQuery libs, or .NET AJAX)</p>
<p>In that case on the server side, just mark the webmethod to use JSON. Note that both input and output params are json formatted</p>
<pre><code>[WebMethod]
[ScriptMe... | 42,088 |
<p>I would like to turn the HTML generated by my CFM page into a PDF, and have the user prompted with the standard "Save As" prompt when navigating to my page.</p>
| <p>You should use the cfdocument tag (with format="PDF") to generate the PDF by placing it around the page you are generating. You'll want to specify a filename attribute, otherwise the document will just stream right to your browser.</p>
<p>After you have saved the content as a PDF, use cfheader and cfcontent in com... | <p>I'm not that familiar with ColdFusion, but what you need to do is set the Content-Type of the page when the user requests it to be application/octet-stream. This will prompt them for a download every time. </p>
<p>Hope this helps!</p>
| 9,969 |
<p>I converted VS2006 vc++ project to VS2008. When compiling I get the above error. How do i fix it? am I missing this exe ?</p>
| <p>There is a bug in the Visual Studio 2008 Standard Edition installer. It does not install cl.exe if you only install Visual C++ but not Visual C#. To work around this you have to install Visual C# even if you do not need this.</p>
| <p>I had this problem under Windows 10 and solved it by adding the following paths to the PATH environment variable:</p>
<p>C:\ProgramFilesC\VS2008\Common7\IDE
C:\ProgramFilesC\VS2008\VC\bin\x86_amd64</p>
<p>where C:\ProgramFilesC\VS2008 is the path where I installed Visual Studio.</p>
| 13,462 |
<p>When an <code>Expression<T></code> is compiled, is the resultant code implicitly cached by the framework? I'm thinking along the lines of the static <code>Regex</code> methods where the framework implicitly compiles and caches the last few regexes.</p>
<p>If compiled <code>Expression<T></code> objects a... | <p>No; I do not believe that it is; if you want it cached, you must hold onto the <code>Delegate</code> reference (typically <code>Func<...></code> or <code>Action<...></code>). Likewise, if you want to get the best performance, you would compile it as a parameterised expression, so you can send in differen... | <p>Lambda experssions are not cached automatically. You will need to implement you own caching/memoization algorithms for that. Check the related Stackoverflow question:</p>
<p><a href="https://stackoverflow.com/questions/66382/is-it-possible-to-cache-a-value-evaluated-in-a-lambda-expression-c-linq">Is it possible to ... | 32,322 |
<p>I develop exclusively on VMs. I currently run Boot Camp on a MacBook Pro and do all my development on a series of Virtual PC VMs for many different environments. This <a href="http://www.andrewconnell.com/blog/articles/UseVirtualPCsDifferencingDisksToYourAdvantage.aspx" rel="nofollow noreferrer">post by Andrew Conne... | <p>There's actually a way to turn that "feature" off. This will allow the user to post whichever characters they want, and there will be no need to convert characters to an alias using Javascript. See this article for <a href="http://mdid.org/mdidwiki/index.php?title=Disabling_Request_Validation" rel="nofollow norefer... | <p>My first comment would be to avoid using JavaScript to change the angle brackets. Bypassing this is as simple as disabling JavaScript in the browser. Almost all server-side languages have some utility method that converts some HTML characters into their entity counterparts. For instance, PHP uses htmlentities(), and... | 8,707 |
<p>I've been working on a web crawling .NET app in my free time, and one of the features of this app that I wanted to included was a pause button to pause a specific thread.</p>
<p>I'm relatively new to multi-threading and I haven't been able to figure out a way to pause a thread indefinitely that is currently support... | <p>Never, ever use <code>Thread.Suspend</code>. The major problem with it is that 99% of the time you can't know what that thread is doing when you suspend it. If that thread holds a lock, you make it easier to get into a deadlock situation, etc. Keep in mind that code you are calling may be acquiring/releasing lock... | <p>The Suspend() and Resume() may be depricated, however they are in no way useless.
If, for example, you have a thread doing a lengthy work altering data, and the user wishes to stop it, he clicks on a button. Of course, you need to ask for verification, but, at the same time you do not want that thread to continue al... | 17,259 |
<p>Is exposing CRUD operations through SOAP web services a bad idea? My instinct tells me that it is not least of which because the overhead of doing database calls overhead could be huge. I'm struggling to find documentation for/against this (anti)pattern so I was wondering if anyone could point me to some documentati... | <p>I think publishing a SOAP service that exposes CRUD operations to anonymous, public "users" would be a particularly bad idea. If, however, you can restrict one or both of these caveats, then I see nothing wrong with it (moreover I've implemented such services many times).</p>
<ul>
<li><p>You can require, in additi... | <p>There is nothing wrong with exposing the CRUD operations via SOAP web-services per se.</p>
<p>You will obviously find quite a lot of examples for such services.</p>
<p>However depending on your particular requirements you might find that for you using SOAP is too much overhead or that you could be better off using... | 22,687 |
<p>Imagine in the Global.asax.cs file I had an instance class as a private field. Let's say like this:</p>
<pre><code>private MyClass _myClass = new MyClass();
</code></pre>
<p>And I had a static method on Global called GetMyClass() that gets the current HttpApplication and returns that instance.</p>
<pre><code>publ... | <p>Whether or not this fits the cookie-cutter pattern of a Singleton, it still suffers from the same problems as Singleton:</p>
<ul>
<li>It is a static, concrete reference and cannot be substituted for separate behavior or stubbed/mocked during a test</li>
<li>You cannot subclass this and preserve this behavior, so it... | <p>I would say that it is definitely NOT a singleton. Design patterns are most useful as definitions of common coding practices. When you talk about singletons, you are talking about an object where there is only one instance.</p>
<p>As you yourself have noted, there are multiple HttpApplications, so your code does no... | 22,427 |
<p>Modern UI's are starting to give their UI elments nice inertia when moving. Tabs slide in, page transitions, even some listboxes and scroll elments have nice inertia to them (the iphone for example). What is the best algorythm for this? It is more than just gravity as they speed up, and then slow down as they fal... | <p>You're talking about two different things here.</p>
<p>One is momentum - giving things residual motion when you release them from a drag. This is simply about remembering the velocity of a thing when the user releases it, then applying that velocity to the object every frame and also reducing the velocity every fra... | <p>It's playing with the numbers.. What feels good is good.</p>
<p>I've tried to develop magic formulas myself for years. In the end the ugly hack always felt best. Just make sure you somehow time your animations properly and don't rely on some kind of redraw/refresh rate. These tend to change based on the OS.</p>
| 23,837 |
<p>I'm writing a small GUI app that contains some "editor" functionality, and something that I'd like to let users open a few sample text files to test things out quickly. The easiest way of doing this would be to package a separate zip with the appropriate sample files, and have them open them manually; I'd like to ma... | <p>You can include a resource file right in the jar and then open it as a resource stream in your app. If you're using Spring, you can inject the resource right into a bean. If not, check out <a href="http://java.sun.com/javase/6/docs/api/java/lang/Class.html#getResourceAsStream(java.lang.String)" rel="nofollow norefer... | <p>Your FileDialog can be given a FilenameFilter that filters files by any criteria you like. You can default-point it to a directory of sample files, have it ignore everything not named ".sample" or "MySampleXXXX.java", e.g. </p>
<pre><code>myDialog.setFilenameFilter( new FilenameFilter() {
public void accept (Fi... | 33,939 |
<p>I'm writing a web app that points to external links. I'm looking to create a non-sequential, non-guessable id for each document that I can use in the URL. I did the obvious thing: treating the url as a string and str#crypt on it, but that seems to choke on any non-alphanumberic characters, like the slashes, dots and... | <p>Depending on how long a string you would like you can use a few alternatives:</p>
<pre><code>require 'digest'
Digest.hexencode('http://foo-bar.com/yay/?foo=bar&a=22')
# "687474703a2f2f666f6f2d6261722e636f6d2f7961792f3f666f6f3d62617226613d3232"
require 'digest/md5'
Digest::MD5.hexdigest('http://foo-bar.com/yay/... | <p>Use <a href="http://ruby-doc.org/stdlib/libdoc/digest/rdoc/index.html" rel="nofollow noreferrer">Digest::MD5</a> from Ruby's standard library:</p>
<pre><code>Digest::MD5.hexdigest(my_url)
</code></pre>
| 9,344 |
<p>I am trying to determine what issues could be caused by using the following serialization surrogate to enable serialization of anonymous functions/delegate/lambdas. </p>
<pre><code>// see http://msdn.microsoft.com/msdnmag/issues/02/09/net/#S3
class NonSerializableSurrogate : ISerializationSurrogate
{
public voi... | <p>Did you see this post that I wrote as a followup to the CountingDemo: <a href="http://dotnet.agilekiwi.com/blog/2007/12/update-on-persistent-iterators.html" rel="noreferrer">http://dotnet.agilekiwi.com/blog/2007/12/update-on-persistent-iterators.html</a> ? Unfortunately, Microsoft have confirmed that they probably ... | <p>I'm not 100% on this, but I believe that if you want to "save" a delegate or some code to the database that can be fairly dynamic, what you need to do is create an Expression, then you can compile the expression into a Func<...>. </p>
<p><a href="http://blogs.msdn.com/charlie/archive/2008/01/31/expression-tree-b... | 41,658 |
<p>In my everlasting quest to suck less I'm trying to understand the "yield" statement, but I keep encountering the same error.</p>
<blockquote>
<p>The body of [someMethod] cannot be an iterator block because
'System.Collections.Generic.List< AClass>' is not an iterator interface type.</p>
</blockquote>
<p>Thi... | <p>A method using <em>yield return</em> must be declared as returning one of the following two interfaces:</p>
<pre><code>IEnumerable<SomethingAppropriate>
IEnumerator<SomethingApropriate>
</code></pre>
<p>(thanks <a href="https://stackoverflow.com/users/22656/jon-skeet">Jon</a> and <a href="https://stack... | <p>What does the method you're using this in look like? I don't think this can be used in just a loop by itself.</p>
<p>For example...</p>
<pre><code>public IEnumerable<string> GetValues() {
foreach(string value in someArray) {
if (value.StartsWith("A")) { yield return value; }
}
}
</code></pre>... | 41,010 |
<p>Is there a way in PHP to compile a regular expression, so that it can then be compared to multiple strings without repeating the compilation process? Other major languages can do this -- Java, C#, Python, Javascript, etc.</p>
| <p>The Perl-Compatible Regular Expressions library may have already be optimized for your use case without providing a Regex class like other languages do: </p>
<blockquote>
<p>This extension maintains a global per-thread cache of compiled regular expressions (up to 4096).</p>
<p><a href="http://www.php.net/man... | <p>I'm not positive that you can. If you check out <a href="https://rads.stackoverflow.com/amzn/click/com/0596528124" rel="nofollow noreferrer" rel="nofollow noreferrer">Mastering Regular Expressions</a>, some PHP specific optimization techniques are discussed in Chapter10: PHP. Specifically the use of the S pattern mo... | 25,768 |
<p>What do I lose by adopting test driven design?</p>
<p>List only negatives; do not list benefits written in a negative form.</p>
| <p>If you want to do "real" TDD (read: test first with the red, green, refactor steps) then you also have to start using mocks/stubs, when you want to test integration points.</p>
<p>When you start using mocks, after a while, you will want to start using Dependency Injection (DI) and a Inversion of Control (IoC) conta... | <p>TDD requires a certain organization for your code. This might be inefficient or difficult to read. Or even architecturally wrong; for example, since <code>private</code> methods cannot be called outside a class, you have to make methods non-private to make them testable, which is just wrong.</p>
<p>When code chan... | 8,987 |
<p>As an amateur software developer (I'm still in academia) I've written a few schemas for XML documents. I routinely run into design flubs that cause ugly-looking XML documents because I'm not entirely certain what the semantics of XML exactly are.</p>
<p>My assumptions:</p>
<pre><code><property> value </prop... | <p>One general (but important!) recommendation is never to store multiple logical pieces of data in a single node (be it a text node or an attribute node). Otherwise, you end up needing your own parsing logic <strong>on top of</strong> the XML parsing logic you normally get for free from your framework.</p>
<p>So in y... | <p>Look at the relationships of the data you are trying to represent is the best approach that I've found.</p>
| 28,666 |
<p>I am trying to do a search in my Eclipse (Java) workspace to find all instances of static variables that are not final.</p>
<p>I tried various regexes but they do not result in any matches. Can someone suggest a regex that will match all lines containing <code>static</code> and not containing <code>final</code>, an... | <p>This pattern works:</p>
<pre><code>[^(final)] static [^(final)][^(\})]*$
</code></pre>
<p>Here is a test:</p>
<pre><code>$ cat test.txt
private int x = "3";
private static x = "3";
private final static String x = "3";
private static final String x = "3";
private static String x = "3";
public static void main(Stri... | <p>One of the IntelliJ code inspections already does this. You can actually run the code inspector stand alone if you want and have it generate a report (usefull for a nightly build).</p>
<p>As the previous poster said, Find Bugs will do this and I imagine other code inspection tools will do it as well. You're probabl... | 29,786 |
<p>Using the following code I get a nice formatted string:</p>
<pre><code>Request.QueryString.ToString
</code></pre>
<p>Gives me something like: &hello=world&microsoft=sucks</p>
<p>But when I use this code to clone the collection to another object (of the same type) I get the Type() back from the ToString()... | <p>HttpValueCollection is internal, but you can use "var" to declare it without extract it with reflector.</p>
<pre><code>var query = HttpUtility.ParseQueryString(Request.Url.Query);
query["Lang"] = myLanguage; // Add or replace param
string myNewUrl = Request.Url.AbsolutePath + "?" + query;
</code></pre>
| <p>Request.QueryString actually return a HttpValueCollection object (which unfortuately, is internal to System.Web so you can't you it). </p>
<p>Nevertheless, HttpValueCollection is derived from NameValueCollection, and it's Remove() method remains intact, so you should be able to call Request.QueryString.Remove("sid... | 28,462 |
<p>In a recent project the "lead" developer designed a database schema where "larger" tables would be split across two separate databases with a view on the main database which would union the two separate database-tables together. The main database is what the application was driven off of so these tables looked and ... | <p>I don't think that you are really going to gain anything by partitioning the table across multiple databases in a single server. All you have essentially done there is increased the overhead in working with the "table" in the first place by having several instances (i.e. open in two different DBs) of it under a sing... | <p>I would disagree with the assumption that nothing can be gained by partitioning.</p>
<p>If the partition data is physically and logically aligned, then the potential IO of queries should be dramatically reduced.</p>
<p>For example, We have a table which has the batch field as an INT representing an INT.</p>
<p>If... | 20,327 |
<p>I'm getting a 404 error when trying to run another web service on an IIS 6 server which is also running Sharepoint 2003. I'm pretty sure this is an issue with sharepoint taking over IIS configuration. Is there a way to make a certain web service or web site be ignored by whatever Sharepoint is doing?</p>
| <p>I found the command line solution.</p>
<pre><code>STSADM.EXE -o addpath -url http://localhost/<your web service/app> -type exclusion
</code></pre>
| <p>you'll have to go into the SharePoint admin console and explicitely allow that web application to run on on the same web site as SharePoint. </p>
<p>I believe it is under defined managed paths.</p>
<p>Central Administration > Application Management > Define Managed Paths</p>
| 12,987 |
<p>There are a lot of different systems for balancing load and achieving redundancy in production servers (Not just web servers)</p>
<ul>
<li>Round-robin DNS</li>
<li>Linux Virtual Server</li>
<li>Cisco Local Director</li>
<li>F5 BigIP</li>
<li>Windows NLB</li>
<li>etc?</li>
</ul>
<p>If you use one of these (or anoth... | <p>For our apache processes we use(d): <a href="http://www.f5.com/products/big-ip/" rel="noreferrer">http://www.f5.com/products/big-ip/</a>
This seems like the industry standard. I guess it all comes down to how much you're paying, and what you're load balancing. </p>
<p>e.g. Websphere could be done:</p>
<p>big ip ->... | <p>We are using HAProxy with great success. I had never seen it go above 2% CPU usage even during high load average.</p>
| 20,777 |
<p>Is this seen as an in efficient prime number generator. It seems to me that this is pretty efficient. Is it the use of the stream that makes the program run slower?</p>
<p>I am trying to submit this to <a href="http://www.spoj.pl/" rel="nofollow noreferrer">SPOJ</a> and it tells me that my time limit exceeded... </... | <p>This is one step (skipping even numbers) above the naive algorithm. I would suggest the <a href="http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes" rel="nofollow noreferrer">Sieve Of Eratosthenes</a> as a more efficient algorithm. From the above link:</p>
<blockquote>
<p>The complexity of the algorithm is
O(... | <p>It can be made slightly more efficient. You don't need to start k at 2, you're already making sure not to test even numbers. So start k at 3.<br>
Then increment k by 2 every time because you don't need to test other even numbers.
The most efficient way that I can think of is to only test if a number is divisible by... | 28,646 |
<p>My knowledge about implementing a parser is a bit rusty.</p>
<p>I have no idea about the current state of research in the area, and could need some links regarding recent advances and their impact on performance. </p>
<p>General resources about writing a parser are also welcome, (tutorials, guides etc.) since much... | <p>Mentioning the dragon book and antlr means you've answered your own question.</p>
<p>If you're looking for other parser generators you could also check out boost::spirit (<a href="http://spirit.sourceforge.net/" rel="noreferrer">http://spirit.sourceforge.net/</a>).</p>
<p>Depending on what you're trying to achieve... | <p>Hmm … your request is a bit unspecific. While there are many recent developments in this general area, they're all quite specialized (naturally, since the field has matured). The original parsing approaches haven't really changed, though. You might want to read up on changes in parser creation tools (<a href="http:/... | 30,284 |
<p>I'm asking myself if it is possible to check if in ADO.NET the current transaction can be rolled back.</p>
<p>The msdn suggests the following implementation:</p>
<pre><code>private static void ExecuteSqlTransaction(string connectionString)
{
using (SqlConnection connection = new SqlConnection(connectionString)... | <p>A lot of this complexity is handled by using a TransactionScope object in a "using" statement - check it out on <a href="http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx" rel="nofollow noreferrer">MSDN</a>. One caveat is that a TransactionScope will automatically "scale up" to use a ... | <p>the problem is that in non SQL 2005 the transactionscope is promoted to a distributed transaction which is quite an overhead.</p>
| 44,232 |
<p>I need a database that could be stored network drive and would allow multiple users (up to 20) to use it without any server software.</p>
<p>I'm considering MS Access or Berkeley DB.</p>
<p>Can you share your experience with file databases? <br>
Which one did you use, did you have any problems with it?</p>
| <p>I would suggest <a href="http://www.sqlite.org/index.html" rel="noreferrer">SQLite</a> because the entire database is stored in a single file, and it quite safely handles multiple users accessing it at the same time. There are several different libraries that you can use for your client application and there is no s... | <p>I have been using Access for some time and in a variety of situations, including on-line. I have found that Access works well if it is properly set up according to the <a href="http://msdn.microsoft.com/en-us/library/aa167840.aspx" rel="nofollow noreferrer">guidelines</a>. One advantage of Access is that it includes... | 5,545 |
<p>When I'm creating a user for my web application, an SMTP email (using ASP.NET's SmtpClient) is sent to the user with the
automatically generated password. However, sometimes what I notice is that it times out and the new user simply won't receive the email with the password.</p>
<p>Alright, so I'll display a messag... | <p>Well, depending on your platform, if you can just hand off your mail to a local MTA, it should handle the retries and such. Your program can just queue the mail and move on, not worry about dealing with timeouts and graylists etc.</p>
<p>If the message still can't be delivered, you could always try resending it (v... | <p>IMHO you should notify the user, asking him to verify the email, without retries. </p>
<p>If the user does not verify the email and leaves the page, you better roll back the account since the user can not access it anyway. </p>
<p>Most cases of timeout would be caused by invalid email accounts. Users either made a... | 8,148 |
<p>I would like to ask if there are any other alternatives, aside from DocumentViewer, for displaying an XPS document in a WPF application? A ready-to-use control or class in .NET if possible. </p>
<p>This is because DocumentViewer is a little slow when you are scrolling through the pages.</p>
<p>Thanks!</p>
| <p>No, unless there are any third-party controls that I'm unaware of.</p>
| <p>Use <a href="http://www.nixps.com/" rel="nofollow noreferrer">NiXPS</a> to convert your XPS document to PDF and use any PDF viewer for WPF out there. This way you will get better performance than you do with DocumentViewer.</p>
| 49,369 |
<p>I am using WinCVS as client and CVSNT as my source control server. Some of the files I wanted to add to my CVS repo, were added as Unicode files. Now, I want to recommit the same as ANSI (aka ASCII) files. However, despite deleting the old files from the repo, every time I add the file with the same name, it automa... | <p>There's a couple of things that (might) come into play here:</p>
<ul>
<li><p>you can disable automatic file type detection in WinCvs itself: go to Admin|Preferences|Globals, the option named "Supply control when adding files" - in theory you should be able to use the regular Add command from the toolbar after you h... | <p>Firstly, I'd recommend using <a href="http://www.tortoisecvs.org/" rel="nofollow noreferrer">TortoiseCVS</a> as it has better <code>CVSNT</code> support. Whie <code>CVS</code> and <code>CVSNT</code> are very similar, <code>CVSNT</code> is <strong><em>not</em></strong> <code>CVS</code>.
TortoiseCVS <code>Add</code> ... | 35,598 |
<p>I am developing an Intranet Application in ASP.NET that uses Windows Authentication. I have created an AD class that gets information from the Active Directory Domain Controller. This is what I use to get things like User Groups that the currently logged user is in. The problem is in the ASP.NET Roles that the user ... | <p>Part of your result is because some of the groups the user belongs to are members of other groups. The full list of a user's groups will include all groups the user belongs to, both directly and via membership in other groups who are also members. </p>
<p>The list will also include built-in groups that are normally... | <p>You might need to assign the website permissions specifically to the groups you want to enumerate.</p>
| 33,099 |
<p>How to UDP Broadcast with C in Linux?</p>
| <p>In many IP stack, such as Linux, this code does not work. Your socket must have broadcast permissions. Try this:</p>
<pre><code>bcast_sock = socket(AF_INET, SOCK_DGRAM, 0);
int broadcastEnable=1;
int ret=setsockopt(bcast_sock, SOL_SOCKET, SO_BROADCAST, &broadcastEnable, sizeof(broadcastEnable));
/* Add other c... | <p>Typically using the Berkeley sockets API, to <code>sendto()</code> one or more datagrams to a known <a href="http://en.wikipedia.org/wiki/Broadcast_address" rel="nofollow noreferrer">broadcast-class</a> IP address.</p>
| 43,784 |
<p>I would like to automate the process of setting up a new PC, this would include downloading and installing the latest windows and office updates; installing software from a network share (some software will require a restart so the script would need to be able to login and continue) adding PC to a domain and setting... | <p>Check out <a href="http://www.nliteos.com/" rel="nofollow noreferrer">nLite</a>. Allows you to pre-configure many options, slipstream updates and service packs, etc.</p>
| <p>The standard method in enterprise IT is the <a href="https://learn.microsoft.com/en-us/windows/deployment/deploy-windows-mdt/deploy-windows-10-with-the-microsoft-deployment-toolkit" rel="nofollow noreferrer">Microsoft Deployment Toolkit (MDT)</a>. Even if another OS deployment technique (SCCM, BigFix, SpecOps...) is... | 12,850 |
<p>Sometimes I get Oracle connection problems because I can't figure out which tnsnames.ora file my database client is using.</p>
<p>What's the best way to figure this out? ++happy for various platform solutions. </p>
| <p>Oracle provides a utility called <code>tnsping</code>:</p>
<pre><code>R:\>tnsping someconnection
TNS Ping Utility for 32-bit Windows: Version 9.0.1.3.1 - Production on 27-AUG-20
08 10:38:07
Copyright (c) 1997 Oracle Corporation. All rights reserved.
Used parameter files:
C:\Oracle92\network\ADMIN\sqlnet.ora
... | <p>The easiest way is probably to check the <strong>PATH</strong> environment variable of the process that is connecting to the database. Most likely the tnsnames.ora file is in <em>first Oracle bin directory in path</em>..\network\admin. TNS_ADMIN environment variable or value in registry (for the current Oracle home)... | 3,169 |
<p>I've been developing a Smalltalk variant for just the fun of it and I wonder what would be a fellow stackoverflowers choice when it comes to targeting a back-end. These were my current considerations:</p>
<p>.NET, JVM: These two VM's are mainly for statically typed languages and I assume it would be quite hard to t... | <p>Don't discount .NET or the JVM so quickly. Dynamic languages are being developed for both (e.g. Groovy, JRuby, Jython on the JVM; IronRuby, IronPython on .NET) and .NET is gaining the "DLR" - Dynamic Language Runtime. (See <a href="http://blogs.msdn.com/hugunin/" rel="nofollow noreferrer">Jim Hugunin's blog</a> for ... | <p>.NET as the DLR now that sit on top of the CLR for Dynamic language.</p>
| 32,784 |
<p>I am working on a large C++ project in Visual Studio 2008, and there are a lot of files with unnecessary <code>#include</code> directives. Sometimes the <code>#include</code>s are just artifacts and everything will compile fine with them removed, and in other cases classes could be forward declared and the #include ... | <p>While it won't reveal unneeded include files, Visual studio has a setting <code>/showIncludes</code> (right click on a <code>.cpp</code> file, <code>Properties->C/C++->Advanced</code>) that will output a tree of all included files at compile time. This can help in identifying files that shouldn't need to be i... | <p>Some of the existing answers state that it's hard. That's indeed true, because you need a full compiler to detect the cases in which a forward declaration would be appropriate. You cant parse C++ without knowing what the symbols mean; the grammar is simply too ambiguous for that. You must know whether a certain name... | 9,997 |
<p>I am trying to write a JavaScript function that will return its first argument(function) with all the rest of its arguments as preset parameters to that function.</p>
<p>So:</p>
<pre>function out(a, b) {
document.write(a + " " + b);
}
function setter(...) {...}
setter(out, "hello")("world");
setter(out, "hel... | <p>First of all, you need a partial - <a href="https://stackoverflow.com/questions/218025/what-is-the-difference-between-currying-and-partial-application"><strong>there is a difference between a partial and a curry</strong></a> - and here is all you need, <em>without a framework</em>:</p>
<pre><code>function partial(f... | <p>**
EDIT: See Jason Bunting's response. This answer actually shows a sub-par way of chaining numerous out calls, not a single out-call with presets for some of the arguments. If this answer actually helps with a similar problem, you should be sure to make use of apply and call as Jason recommends, instead of the obsc... | 41,548 |
<p>By default data extracted by the <code>GROUP BY</code> clause is ordered as ascending.
How to change it to descending.</p>
| <p>You should use the derived tables on your SQL.
For example if you want to pick up the most recent row for an specific activity you're attempt to use:</p>
<pre><code>select *
from activities
group by id_customer
order by creation_date
</code></pre>
<p>but it doesn't work. Try instead:</p>
<pre><code>SELECT *
... | <p><code>ORDER BY foo DESC</code>?</p>
| 11,690 |
<p>I find it much easier to write MXML classes with embedded Script than trying to make an actionscript file.</p>
<p>I was wondering however what kind of overhead there is of using an MXML file - in terms of file size. I'm not especially concerned about performance, but if that is relevant would be interested in any f... | <p>If you're going for the same functionality, MXML is not going to make your swf any bigger.</p>
<p>The thing that's affecting size is using the Flex SDK and its components. Whether you declare them with MXML or AS3, you're using them and their code is being built into the swf. By the same token, if you're referencin... | <p>Including the Flex framework (whether via MXML or pure Actionscript) will significantly increase the size of your final SWF.</p>
<p>I've just written a flash movie that consists of a single button. The MXML version was 175K while the no-Flex Actionscript version was 2K.</p>
<p>Though I'm not using it myself, this ... | 33,069 |
<p>What is the best method for adding options to a <code><select></code> from a JavaScript object using jQuery?</p>
<p>I'm looking for something that I don't need a plugin to do, but I would also be interested in the plugins that are out there.</p>
<p>This is what I did:</p>
<pre><code>selectValues = { "1": "t... | <p>The same as other answers, in a jQuery fashion:</p>
<pre><code>$.each(selectValues, function(key, value) {
$('#mySelect')
.append($("<option></option>")
.attr("value", key)
.text(value));
});
</code></pre>
| <p>I decided to chime in a bit.</p>
<ol>
<li>Deal with prior selected option; some browsers mess up when we append</li>
<li>ONLY hit DOM once with the append</li>
<li>Deal with <code>multiple</code> property while adding more options</li>
<li>Show how to use an object</li>
<li>Show how to map using an array of objects... | 20,622 |
<p>How can I find poor performing SQL queries in Oracle?</p>
<p>Oracle maintains statistics on shared SQL area and contains one row per SQL string(v$sqlarea).
But how can we identify which one of them are badly performing?</p>
| <p>I found this SQL statement to be a useful place to start (sorry I can't attribute this to the original author; I found it somewhere on the internet):</p>
<pre><code>SELECT * FROM
(SELECT
sql_fulltext,
sql_id,
elapsed_time,
child_number,
disk_reads,
executions,
first_load_time,
last_l... | <p>While searching I got the following query which does the job with one assumption(query execution time >6 seconds)</p>
<hr>
<p>SELECT username, sql_text, sofar, totalwork, units </p>
<p>FROM v$sql,v$session_longops</p>
<p>WHERE sql_address = address AND sql_hash_value = hash_value</p>
<p>ORDER BY address, hash_v... | 40,909 |
<p>So I've switched the Trigorilla board in the printer with a SKR 1.3 with TMC2208 drivers and installed the latest Marlin 2.0, with a config based on <a href="https://www.thingiverse.com/thing:3741425/" rel="nofollow noreferrer">this one</a>. You can find the <a href="https://pastebin.com/ij1G5tSw" rel="nofollow nore... | <p>So the problem was that the TMC2208 were wired for UART mode, yet Marlin was configured for standalone, which apparently makes them work, but with completely wrong step sizes. Changing it in the configuration completely eliminated the problem</p>
| <p>I would check the "steps per distance" setting. If the motors were moving more than the firmware thinks, the height would measure as shorter than actual (since the number of steps would be less than the firmware expected). Similarly, the radius would scale up.</p>
<p>You replaced the controller and motor drivers,... | 1,476 |
<p>In C I could, for example, zero out bit #10 in a 32 bit unsigned value like so:</p>
<pre><code>unsigned long value = 0xdeadbeef;
value &= ~(1<<10);
</code></pre>
<p>How do I do that in Python ?</p>
| <p>Bitwise operations on Python ints work much like in C. The <code>&</code>, <code>|</code> and <code>^</code> operators in Python work just like in C. The <code>~</code> operator works as for a signed integer in C; that is, <code>~x</code> computes <code>-x-1</code>.</p>
<p>You have to be somewhat careful with l... | <p>Have you tried copying and pasting your code into the Python REPL to see what will happen?</p>
<pre><code>>>> value = 0xdeadbeef
>>> value &= ~(1<<10)
>>> hex (value)
'0xdeadbaef'
</code></pre>
| 17,787 |
<p>What would I do if I want to have a generic method that only accepts types that have overloaded an operator, for instance the subtraction operator. I tried using an interface as a constraint but interfaces can't have operator overloading. </p>
<p>What is the best way to achieve this?</p>
| <p>There is no immediate answer; operators are static, and cannot be expressed in constraints - and the existing primatives don't implement any specific interface (contrast to IComparable[<T>] which can be used to emulate greater-than / less-than).</p>
<p>However; if you just want it to work, then in .NET 3.5 th... | <p>There is a piece of code stolen from the internats that I use a lot for this. It looks for or builds using <code>IL</code> basic arithmetic operators. It is all done within an <code>Operation<T></code> generic class, and all you have to do is assign the required operation into a delegate. Like <code>add = Oper... | 17,774 |
<p>How do you remove the jagged edges from a wide button in internet explorer? For example:</p>
<p><img src="https://i.stack.imgur.com/em5K0.gif" alt="alt text"></p>
| <p>You can also eliminate Windows XP's styling of buttons (and every other version of Windows) by setting the <code>background-color</code> and/or <code>border-color</code> on your buttons.</p>
<p>Try the following styles:</p>
<pre><code>background-color: black;
color: white;
border-color: red green blue yellow;
</co... | <p>Not too much you can do about it, but the good news is that it is fixed in IE8</p>
<p><a href="http://webbugtrack.blogspot.com/2007/08/bug-101-buttons-render-stretched-and.html" rel="nofollow noreferrer">http://webbugtrack.blogspot.com/2007/08/bug-101-buttons-render-stretched-and.html</a></p>
| 18,145 |
<p>Is there a difference between 3D printing and additive manufacturing if any then explain?</p>
| <p>Yes and No at the same time:</p>
<h1>3D Printing is a subset of Additive Manufacturing</h1>
<h3>but treated as a synonym at this time</h3>
<p>3D printing is a process that takes some material, in a fluid state that fuses with the model to shape an object from it. The material could be plastics, ceramic paste or even... | <h3>Origin</h3>
<p>3D printing and additive manufacturing (AM) both refer to a <a href="https://en.wikipedia.org/wiki/3D_printing_processes" rel="nofollow noreferrer">range of processes</a> where, opposed to subtractive manufacturing methodologies, materials are joined to create products. E.g. <a href="https://en.wikip... | 1,095 |
<p>How does one <strong>reliably</strong> determine a file's type? File extension analysis is not acceptable. There must be a rubyesque tool similar to the UNIX file(1) command?</p>
<p>This is regarding MIME or content type, not file system classifications, such as directory, file, or socket.</p>
| <p>There is a ruby binding to <code>libmagic</code> that does what you need. It is available as a gem named <a href="https://rubygems.org/gems/ruby-filemagic/versions/0.7.1" rel="noreferrer">ruby-filemagic</a>:</p>
<pre><code>gem install ruby-filemagic
</code></pre>
<p>Require <code>libmagic-dev</code>.</p>
<p>The d... | <p>You could give a go with <a href="http://mime-types.rubyforge.org/" rel="nofollow noreferrer">MIME::Types for Ruby</a>.</p>
<blockquote>
<p>This library allows for the identification of a file’s likely MIME content type. The identification of MIME content type is based on a file’s filename extensions.</p>
</block... | 7,469 |
<p>I am a bit confused about socket programming in C.</p>
<p>You create a socket, bind it to an interface and an IP address and get it to listen. I found a couple of web resources on that, and understood it fine. In particular, I found an article <s><a href="http://users.actcom.co.il/~choo/lupg/tutorials/internetworki... | <p>Short answer is that you have to do all the heavy lifting yourself. You can be notified that there is data available to be read, but you won't know how many bytes are available. In most IP protocols that use variable length packets, there will be a header with a known fixed length prepended to the packet. This he... | <p>Sockets operate at a higher level than raw packets - it's like a file you can read/write from. Also, when you try to read from a socket, the operating system will block (put on hold) your process until it has data to fulfill the request.</p>
| 7,132 |
<p>What is the difference between <strong><em>anonymous methods</em></strong> of C# 2.0 and <strong><em>lambda expressions</em></strong> of C# 3.0.?</p>
| <p><a href="http://msdn.microsoft.com/en-us/library/0yw3tz5k.aspx" rel="noreferrer">The MSDN page on anonymous methods explains it</a></p>
<blockquote>
<p>In versions of C# before 2.0, the only
way to declare a delegate was to use
named methods. C# 2.0 introduced
anonymous methods and in C# 3.0 and
later, la... | <p>First, convenience: lambdas are easier to read and write.</p>
<p>Second, expressions: lambdas can be compiled to <em>either</em> a delegate, <em>or</em> an expression tree (<code>Expression<T></code> for some delegate-type T, such as <code>Func<int,bool></code>). Expression trees are the more exciting, ... | 25,563 |
<p>I am trying to generate a report by querying 2 databases (Sybase) in classic ASP.</p>
<p>I have created 2 connection strings:<br></p>
<blockquote>
<p>connA for databaseA<br>
connB for databaseB</p>
</blockquote>
<p>Both databases are present on the same server (don't know if this matters)<br></p>
<p>Queries:</p>
<p>... | <p>With both queries, it looks like you are trying to insert into #temp. #temp is located on one of the databases (for arguments sake, databaseA). So when you try to insert into #temp from databaseB, it reports that it does not exist.</p>
<p>Try changing it from <em>Into <strong>#temp</strong> From</em> to <em>Into <s... | <p>your temp table is out of scope, it is only 'alive' during the first connection and will not be available in the 2nd connection
Just move all of it in one block of code and execute it inside one conection</p>
| 3,716 |
<p>Just wondering how much people log within their applications???</p>
<p>I have seen this:</p>
<blockquote>
<p>"I typically like to use the ERROR log
level to log any exceptions that are
caught by the application. I will use
the INFO log level as a "first level"
debugging scheme to show whenever I
enter ... | <p>You are right that this does make the code more difficult to read and maintain. One recommendation is to consider looking into an AOP (Aspect oriented Programming) tool to separate your logging logic from your application logic. Castle Windsor and Spring are two that come to mind within the .Net community that you... | <p>From a security standpoint logging can be an interesting topic. I wrote a <a href="http://blogs.csoonline.com/when_ddos_attacks_become_personal" rel="nofollow noreferrer">blog entry</a> on CSO Online a while back in the wake of a couple of DDOS attacks. This is the section where I talked about logging, hope it helps... | 28,708 |
<p>Here's another C#/.NET question based merely on curiousity more than an immediate <em>need</em> ...</p>
<p>If you had a <code>Socket</code> instance and you wanted to wrap it in the higher-level <code>TcpClient</code> class, is that possible and how would you do it?</p>
<p>Conversely if you have an instance of <co... | <blockquote>
<p>If you had a Socket instance and you
wanted to wrap it in the higher-level
TcpClient class, is that possible and
how would you do it?</p>
</blockquote>
<pre><code>Socket socket = ...;
TcpClient client = new TcpClient();
client.Client = socket;
</code></pre>
<blockquote>
<p>Conversely if you ... | <p>From TcpClient to Socket is very easy. <code>tcpClientInstance.Client</code> is the underlying Socket instance.</p>
| 24,848 |
<p>I need to read selected files, matching on the file name, from a remote zip archive using Python. I don't want to save the full zip to a temporary file (it's not that large, so I can handle everything in memory).</p>
<p>I've already written the code and it works, and I'm answering this myself so I can search for it... | <p>Here's how I did it (grabbing all files ending in ".ranks"):</p>
<pre><code>import urllib2, cStringIO, zipfile
try:
remotezip = urllib2.urlopen(url)
zipinmemory = cStringIO.StringIO(remotezip.read())
zip = zipfile.ZipFile(zipinmemory)
for fn in zip.namelist():
if fn.endswith(".ranks"):
... | <p>Bear in mind that merely decompressing a ZIP file may result in <a href="http://en.wikipedia.org/wiki/Decompression_bomb" rel="nofollow noreferrer">a security vulnerability</a>.</p>
| 12,010 |
<p>I have the following configuration, but I have not able to find any documentation on how to set a maximum backup files on date rolling style. I know that you can do this with size rolling style by using the maxSizeRollBackups.</p>
<pre><code><appender name="AppLogFileAppender" type="log4net.Appender.RollingFile... | <p>You can't.</p>
<p>from
<a href="https://logging.apache.org/log4net/release/sdk/html/T_log4net_Appender_RollingFileAppender.htm" rel="noreferrer">log4net SDK Reference<br />
RollingFileAppender Class
</a></p>
<blockquote>
<p><strong>CAUTION</strong></p>
<p>A maximum number of backup files when rolling on date/time bo... | <p>It's fairly easy to inherit from a log4net appender and add say your own override method which performs the clean up of files. I overrode OpenFile to do this. Here's an example of a custom log4net appender to get you started: <a href="https://stackoverflow.com/a/2385874/74585">https://stackoverflow.com/a/2385874/745... | 12,089 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.