qid int64 4 19.1M | question stringlengths 18 48.3k | answers list | date stringlengths 10 10 | metadata list |
|---|---|---|---|---|
398,871 | <p>Is there a way to do the following using LINQ?</p>
<pre><code>foreach (var c in collection)
{
c.PropertyToSet = value;
}
</code></pre>
<p>To clarify, I want to iterate through each object in a collection and then update a property on each object.</p>
<p>My use case is I have a bunch of comments on a blog post, and I want to iterate through each comment on a blog post and set the datetime on the blog post to be +10 hours. I could do it in SQL, but I want to keep it in the business layer.</p>
| [
{
"answer_id": 398894,
"author": "JaredPar",
"author_id": 23283,
"author_profile": "https://Stackoverflow.com/users/23283",
"pm_score": 3,
"selected": false,
"text": "collection.Iterate(c => { c.PropertyToSet = value;} );\n public static void Iterate<T>(this IEnumerable<T> enumerable, Ac... | 2008/12/29 | [
"https://Stackoverflow.com/questions/398871",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/493/"
] |
398,878 | <p>I see that over on this question <a href="https://stackoverflow.com/questions/312024/linqy-way-to-check-if-any-objects-in-a-collection-have-the-same-property-value">LINQy way to check if any objects in a collection have the same property value</a> there is a request to say how to do something using LINQ to see if a property matches in a collection. However, is this the fastest reasonable process by which to do this? I will be deploying something that requires a certain amount of resource management, and I want the application to be as responsive as can be, without making the code terribly hard to decipher when someone else, or myself come back to it later.</p>
| [
{
"answer_id": 399075,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 0,
"selected": false,
"text": "Enumerable"
},
{
"answer_id": 399215,
"author": "ChrisW",
"author_id": 49942,
"author_profile": "... | 2008/12/29 | [
"https://Stackoverflow.com/questions/398878",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22777/"
] |
398,882 | <p>I'm building an application in C# that has a static class which initiate a COM class and handles some event handlers of another class that hooks keyboard.
When I call a method of the COM class from a button event handler in my WPF window, the method works without any problems but when I call it in one of the event callbacks within my static class it throws following exception: </p>
<blockquote>
<p>Unable to cast COM object of type 'BLAHBLAH' to interface type
'BLAHBLAH'. This operation failed because the QueryInterface call on
the COM component for the interface with IID
'{9DD6680B-3EDC-40DB-A771-E6FE4832E34A}' failed due to the following
error: An outgoing call cannot be made since the application is
dispatching an input-synchronous call. (Exception from HRESULT:
0x8001010D (RPC_E_CANTCALLOUT_ININPUTSYNCCALL)).</p>
</blockquote>
<p>Can you please tell me, what this exception means and how can I solve it?</p>
| [
{
"answer_id": 29555418,
"author": "mvermand",
"author_id": 2528609,
"author_profile": "https://Stackoverflow.com/users/2528609",
"pm_score": 1,
"selected": false,
"text": "Thread thread = new Thread(() =>\n{\n ManagementObjectSearcher theSearcher = new ManagementObjectSearcher(\"SELE... | 2008/12/29 | [
"https://Stackoverflow.com/questions/398882",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34623/"
] |
398,883 | <p>I have a structure</p>
<pre><code>typedef struct my_s {
int x;
...
} my_T;
my_t * p_my_t;
</code></pre>
<p>I want to set the address of <code>p_my_t</code> to <code>NULL</code> and so far this is how I've tried to do this:</p>
<pre><code>memset (&p_my_t, 0, sizeof(my_t*))
</code></pre>
<p>This doesn't not look right to me though. What is the correct way of doing this?</p>
<hr>
<p><em>Amendment to question - asking a radically more complex question</em>:</p>
<p>Here is what I am trying to do:</p>
<ul>
<li>Two processes, A and B</li>
<li>malloc p_my_t in A, B has N threads and can access it</li>
<li>Start deleting in A but I can not simply free it since threads in B may still using it.</li>
<li>So I call a function, pass address of p_my_t to B to set its address to NULL in B so no other threads in B can use anymore</li>
<li>After call back from B, I then free memory in A</li>
</ul>
<p><em>NB: there is no standard way to manage memory allocations via shared memory between processes. You will have to do some rather careful thinking about what is going on.</em></p>
| [
{
"answer_id": 398897,
"author": "Robert Gamble",
"author_id": 25222,
"author_profile": "https://Stackoverflow.com/users/25222",
"pm_score": 4,
"selected": false,
"text": "memset p_my_t = NULL;\n p_my_t = 0;\n"
},
{
"answer_id": 398899,
"author": "Adam Rosenfield",
"autho... | 2008/12/29 | [
"https://Stackoverflow.com/questions/398883",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
398,884 | <p>Does anyone know a situation where a PostgreSQL HASH should be used instead of a B-TREE for it seems to me that these things are a trap. They are take way more time to CREATE or maintain than a B-TREE (at least 10 times more), they also take more space (for one of my table.columns, a B-TREE takes up 240 MB, while a HASH would take 4 GB) and I seem to have understood from my googling, that they do not SELECT faster than B-TREEs; yet the HASH may have recently been optimized or google was wrong. </p>
<p>Anyway, I wanted you guy's opinions and experiences. If these HASHs are evil, people should know. </p>
<p>Thanks<br>
Also: what about MySQL's HASHs?</p>
| [
{
"answer_id": 398921,
"author": "Kent Fredric",
"author_id": 15614,
"author_profile": "https://Stackoverflow.com/users/15614",
"pm_score": 6,
"selected": true,
"text": "< > O(1) O(log n) ITEM=\"foo\""
}
] | 2008/12/29 | [
"https://Stackoverflow.com/questions/398884",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/49985/"
] |
398,886 | <p>I am working with a shared memory application, and to delete the segments I use the following command:</p>
<pre><code> ipcrm -M 0x0000162e (this is the key)
</code></pre>
<p>But I do not know if I'm doing the right things, because when I run <code>ipcs</code> I see the same segment but with the key 0x0000000. So is the memory segment really deleted? When I run my application several times I see different memory segments with the key 0x000000, like this:</p>
<pre><code> key shmid owner perms bytes nattch status
0x00000000 65538 me 666 27 2 dest
0x00000000 98307 me 666 5 2 dest
0x00000000 131076 me 666 5 1 dest
0x00000000 163845 me 666 5 0
</code></pre>
<p>What is actually happening? Is the memory segment really deleted? </p>
<p><strong>Edit:</strong> The problem was - as said below in the accepted answer - that there were two processes using the shared memory, until all the process were closed, the memory segment is not going to disappear.</p>
| [
{
"answer_id": 398910,
"author": "paxdiablo",
"author_id": 14860,
"author_profile": "https://Stackoverflow.com/users/14860",
"pm_score": 6,
"selected": true,
"text": "ipcs"
},
{
"answer_id": 398980,
"author": "hhafez",
"author_id": 42303,
"author_profile": "https://St... | 2008/12/29 | [
"https://Stackoverflow.com/questions/398886",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39160/"
] |
398,903 | <p>I've seen them used in a lot of the same ways, and I am worried I'm about to go down a path in design that is irreversible if I don't understand this better. Also, I am using .NET.</p>
| [
{
"answer_id": 398916,
"author": "OwenP",
"author_id": 2547,
"author_profile": "https://Stackoverflow.com/users/2547",
"pm_score": 2,
"selected": false,
"text": "Collection<T> ComVisibleAttribute(false)"
},
{
"answer_id": 398920,
"author": "tuinstoel",
"author_id": 43901,... | 2008/12/29 | [
"https://Stackoverflow.com/questions/398903",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22777/"
] |
398,906 | <p>I have created an installation package using Wix which installs a Windows service on the user's machine. Currently, the files are being installed to [%ProgramFiles%\APLICATIONNAME].</p>
<p>Is this a future proof way of structuring an installation folder?
Should I be installing to [%ProgramFiles%\APLICATIONNAME\VERSION_NUMBER] instead?</p>
<p>Any recommendations would be greatly appreciated.</p>
<p>Thanks,</p>
<p>Arnie</p>
<hr>
<p><strong>Update:</strong></p>
<p>Side-by-side installation of different versions will not be supported.</p>
| [
{
"answer_id": 399141,
"author": "saschabeaumont",
"author_id": 592,
"author_profile": "https://Stackoverflow.com/users/592",
"pm_score": 2,
"selected": false,
"text": "%AppData%\\Manufacturer\\Application\\1.0 HKCU\\Manufacturer\\Product\\1.0"
}
] | 2008/12/29 | [
"https://Stackoverflow.com/questions/398906",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/169/"
] |
398,945 | <p>I'm looking for an algorithm (or PHP code, I suppose) to end up with the 10 lowest numbers from a group of numbers. I was thinking of making a ten item array, checking to see if the current number is lower than one of the numbers in the array, and if so, finding the highest number in the array and replacing it with the current number. </p>
<p>However, I'm planning on finding the lowest 10 numbers from thousands, and was thinking there might be a faster way to do it. I plan on implementing this in PHP, so any native PHP functions are usable.</p>
| [
{
"answer_id": 398964,
"author": "Andrew Coleson",
"author_id": 2072,
"author_profile": "https://Stackoverflow.com/users/2072",
"pm_score": 2,
"selected": false,
"text": "output[0-9] = input[0-9];\nsort(output);\nfor i=10..n-1\n if input[i] < output[9]\n insert(input[i])\n"
},
{
... | 2008/12/29 | [
"https://Stackoverflow.com/questions/398945",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5464/"
] |
398,953 | <p><a href="http://java.sun.com/docs/books/effective/" rel="noreferrer">Effective Java (Second Edition)</a>, Item 4, discusses using private constructors to enforce noninstantiability. Here's the code sample from the book:</p>
<pre><code>public final class UtilityClass {
private UtilityClass() {
throw new AssertionError();
}
}
</code></pre>
<p>However, <code>AssertionError</code> doesn't seem like the right thing to throw. Nothing is being "asserted", which is how the API defines the use of <a href="http://java.sun.com/javase/6/docs/api/java/lang/AssertionError.html" rel="noreferrer">AssertionError</a>.</p>
<p>Is there a different <code>Throwable</code> that's typically in this situation? Does one usually just throw a general <code>Exception</code> with a message? Or is it common to write a custom <code>Exception</code> for this?</p>
<p>It's pretty trivial, but more than anything I guess I'm just curious about it from a style and standards perspective.</p>
| [
{
"answer_id": 398960,
"author": "C. K. Young",
"author_id": 13,
"author_profile": "https://Stackoverflow.com/users/13",
"pm_score": 6,
"selected": true,
"text": "AssertionError"
},
{
"answer_id": 399074,
"author": "Charlie Martin",
"author_id": 35092,
"author_profile... | 2008/12/29 | [
"https://Stackoverflow.com/questions/398953",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29995/"
] |
398,956 | <p>Has anyone created HTML microformats for video and video overlays including:</p>
<ul>
<li>Video File</li>
<li>Links with timecode (start/end) and screen region</li>
</ul>
<p>Thanks,</p>
<p>Michael</p>
| [
{
"answer_id": 398960,
"author": "C. K. Young",
"author_id": 13,
"author_profile": "https://Stackoverflow.com/users/13",
"pm_score": 6,
"selected": true,
"text": "AssertionError"
},
{
"answer_id": 399074,
"author": "Charlie Martin",
"author_id": 35092,
"author_profile... | 2008/12/29 | [
"https://Stackoverflow.com/questions/398956",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27306/"
] |
398,966 | <p>I was having a conversation with a co-worker and the subject of null came up. He was telling me that in .NET behind the scenes it is just a really small number. I always thought that the object just didn't have a pointer to any memory on the heap but i wasn't sure either way.</p>
<p>So i'm hoping the community can clear it up for us ;P</p>
| [
{
"answer_id": 398972,
"author": "Sukasa",
"author_id": 50005,
"author_profile": "https://Stackoverflow.com/users/50005",
"pm_score": 0,
"selected": false,
"text": "Nothing DBNull.Value"
},
{
"answer_id": 399041,
"author": "lomaxx",
"author_id": 493,
"author_profile":... | 2008/12/29 | [
"https://Stackoverflow.com/questions/398966",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42707/"
] |
398,982 | <p>Which types of classes can use <code>foreach</code> loops?</p>
| [
{
"answer_id": 398986,
"author": "George Stocker",
"author_id": 16587,
"author_profile": "https://Stackoverflow.com/users/16587",
"pm_score": 3,
"selected": false,
"text": "foreach foreach int[] fibarray = new int[] { 0, 1, 2, 3, 5, 8, 13 };\n foreach (int i in fibarray)\n {\n ... | 2008/12/29 | [
"https://Stackoverflow.com/questions/398982",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/48616/"
] |
398,992 | <p>So, I'm using jdbc to talk to a MySQL DB. For many a table and for many queries/views, I have created one class which encapsulates one row of the table or the query/table result. Accesses to the DB return one object of such a class (when I know exactly that there's only one matching row) or a Vector of such objects. </p>
<p>Each class features a factory method that builds an object from a row of a ResultSet. A lot of ResultSet.getXXX() methods are needed, as is finicky bookkeeping about which value is in which column, especially after changes to the table/query/view layout. </p>
<p>Creating and maintaining these objects is a boring, work-intensive and mind-numbing task. In other words, the sort of task that is done by a tool. It should read SQL (the MySQL variant, alas) and generate Java code. Or, at least, give me a representation (XML? DOM?) of the table/query/view, allowing me to do the java code generation myself.</p>
<p>Can you name this tool?</p>
| [
{
"answer_id": 399088,
"author": "OscarRyz",
"author_id": 20654,
"author_profile": "https://Stackoverflow.com/users/20654",
"pm_score": 0,
"selected": false,
"text": " Employee e = ( Employee ) MagicDataSource.find( \"select * from employee where id = 1 \");\n Employee[] emps = ( Employe... | 2008/12/29 | [
"https://Stackoverflow.com/questions/398992",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/235914/"
] |
399,003 | <p>For example:
<code>sizeof(char*)</code> returns 4. As does <code>int*</code>, <code>long long*</code>, everything that I've tried. Are there any exceptions to this?</p>
| [
{
"answer_id": 399030,
"author": "David Thornley",
"author_id": 14148,
"author_profile": "https://Stackoverflow.com/users/14148",
"pm_score": 9,
"selected": true,
"text": "sizeof(char) == 1 sizeof(int *) == sizeof(double *)"
},
{
"answer_id": 399999,
"author": "dmityugov",
... | 2008/12/29 | [
"https://Stackoverflow.com/questions/399003",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25632/"
] |
399,021 | <p>I recently came upon something called <a href="http://sourceforge.net/projects/rpoku/" rel="nofollow noreferrer">Rpoku</a> which is a spoken computer language. I also found some research called <a href="http://sourceforge.net/projects/voicecode/" rel="nofollow noreferrer">Voice Code</a> which takes a different approach. There's a <a href="http://www.youtube.com/watch?v=A7f9Iik3q58" rel="nofollow noreferrer">demo video here</a>..</p>
<p>Does this look promising, or is just a toy? Is it or will it be possible to create applications some day without typing at a keyboard?</p>
| [
{
"answer_id": 399047,
"author": "George Stocker",
"author_id": 16587,
"author_profile": "https://Stackoverflow.com/users/16587",
"pm_score": 1,
"selected": false,
"text": "List<Employee> ListOfEmployees = new List<Employee>();\n\nforeach (Employee emp in ListOfEmployees) {\nConsole.Writ... | 2008/12/29 | [
"https://Stackoverflow.com/questions/399021",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11397/"
] |
399,022 | <p>Why doesn't the following work (Python 2.5.2)?</p>
<pre><code>>>> import datetime
>>> class D(datetime.date):
def __init__(self, year):
datetime.date.__init__(self, year, 1, 1)
>>> D(2008)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: function takes exactly 3 arguments (1 given)
</code></pre>
<p>I wanted to create a class that was just like <code>datetime.date</code>, but with a different <code>__init__</code> function. Apparently my function never gets called. Instead the original <code>datetime.date.__init__</code> is called and fails because that expects 3 arguments and I am passing in one.</p>
<p>What's going on here? And is this a clue?</p>
<pre><code>>>> datetime.date.__init__
<slot wrapper '__init__' of 'object' objects>
</code></pre>
<p>Thanks!</p>
| [
{
"answer_id": 399061,
"author": "orip",
"author_id": 37020,
"author_profile": "https://Stackoverflow.com/users/37020",
"pm_score": 0,
"selected": false,
"text": "def first_day_of_the_year(year):\n return datetime.date(year, 1, 1)\n"
},
{
"answer_id": 399418,
"author": "Benj... | 2008/12/29 | [
"https://Stackoverflow.com/questions/399022",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1626/"
] |
399,032 | <p>Im writing a program at the moment that interacts with a MySQL database and im having a problem. As you can see I've written a query that will look for products in the products table that corresponds to the barcode that the user has inputted. </p>
<p>If the barcode that is input by the user is found in the products table, I want to increase the 'amount' field by 1 in the stocks table where the product that corresponds to the barcode input, is the same as the product in the stocks table. </p>
<p>As you can see I've tried to assign a variable to the for loop to try and get it to work that way but its not working. does anyone have any idea of how to do it?</p>
<pre><code>import MySQLdb
def look_up_product():
db = MySQLdb.connect(host='localhost', user = 'root', passwd='$$', db='fillmyfridge')
cursor = db.cursor (MySQLdb.cursors.DictCursor)
user_input=raw_input('please enter the product barcode that you wish to checkin to the fridge: \n')
if cursor.execute("""select * from products where product = %s""", (user_input)):
db.commit()
result_set = cursor.fetchall ()
#i want here to assign a variable to this for loop and the line below = for product in result_set:
print "%s" % (row["product"])
cursor.execute('update stocks set amount = amount + 1 where product = %s', (#here i want the result of the for loop))
db.commit()
else:
print 'no not in products table'
</code></pre>
<p>thanks a million.</p>
| [
{
"answer_id": 399056,
"author": "orip",
"author_id": 37020,
"author_profile": "https://Stackoverflow.com/users/37020",
"pm_score": 0,
"selected": false,
"text": "row = cursor.fetchone()\nprint row[\"product\"]\ncursor.execute('update stocks set amount = amount + 1 where product = %s', r... | 2008/12/29 | [
"https://Stackoverflow.com/questions/399032",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/47204/"
] |
399,040 | <p>I'd like to know if there is a way to tell the Enterprise Library Caching objects to flush all configured caches for that process to flush.</p>
<p>Even enumerating through all of the configured caches for that process, and manually flushing each one, is ok, but is there an API method from EntLib.Caching that will give me those values?</p>
<p>Or do I need to enum through the config file myself?</p>
| [
{
"answer_id": 12106890,
"author": "Jeroen Visscher",
"author_id": 961139,
"author_profile": "https://Stackoverflow.com/users/961139",
"pm_score": 1,
"selected": false,
"text": "CacheManagerSettings conf = (CacheManagerSettings)ConfigurationSourceFactory.Create()\n .GetSection(CacheMa... | 2008/12/29 | [
"https://Stackoverflow.com/questions/399040",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/698/"
] |
399,053 | <p>I've read a lot of tutorials and can not really find anything comprehensive on this subject. </p>
<p>I had written the following code to do one function:</p>
<pre><code>#include <fstream>
#include <string>
#include <iostream>
using namespace std;
ifstream ReadFile( ifstream& openInputFile, string& sLine, int& chgLine );
int main()
{
int chgLine;
string MyFile, sLine,
sFile = "test.txt";
cout << "Enter a file: ";
cin >> MyFile ;
ifstream openInputFile;
if ( MyFile != sFile ) // file must be 'hello.cpp' to proceed
{
cout << "Error";
exit(0);
}
// if correct file is entered print the contents of it
ReadFile( openInputFile, sLine, chgLine );
system("pause");
return 0;
}
ifstream ReadFile( ifstream& openInputFile, string& sLine, int& chgLine )
{
while ( getline ( openInputFile, sLine ) )
{
if ( sLine.length() == 0 ) continue; // to proceed
for ( chgLine = 0; chgLine < sLine.length(); chgLine++ )
{
if ( sLine[chgLine] >= 97 && sLine[chgLine] <= 122 || sLine[chgLine] >= 65 && sLine[chgLine] <= 90 )
{
cout << sLine[chgLine];
}
}
}
}
</code></pre>
<p>But now I've decided to break all of this up into three functions that do what I want separately, and then call them from the <code>main()</code> function. </p>
<p>The first function opens the file:</p>
<pre><code>#include <iostream>
#include <fstream>
using namespace std;
ifstream openInputFile()
{
// use a pointer..return a pointer
// ifstream definition is the challenge
ifstream *fp;
//fp = new ifstream openInputFile;
return openInputFile;
}
int main()
{
cout << "Hello, world!" << endl;
system("pause");
return 0;
}
</code></pre>
<p>I get stuck trying to return a pointer. I don't understand what I'm doing wrong. How can I get the last bit of code to work? And how does one return a pointer with <code>ifstream</code> if it has the function's type?</p>
| [
{
"answer_id": 399094,
"author": "Doug T.",
"author_id": 8123,
"author_profile": "https://Stackoverflow.com/users/8123",
"pm_score": 0,
"selected": false,
"text": "void openInputFile(ifstream& file)\n{\n file.open(...);\n}\n\nint main()\n{\n ifstream file;\n openInputFile(file);... | 2008/12/29 | [
"https://Stackoverflow.com/questions/399053",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40120/"
] |
399,066 | <p>I'm writing an algorithm in PHP to solve a given Sudoku puzzle. I've set up a somewhat object-oriented implementation with two classes: a <code>Square</code> class for each individual tile on the 9x9 board, and a <code>Sudoku</code> class, which has a matrix of <code>Square</code>s to represent the board.</p>
<p>The implementation of the algorithm I'm using is a sort of triple-tier approach. The first step, which will solve only the most basic puzzles (but is the most efficient), is to fill in any squares which can only take a single value based on the board's initial setup, and to adjust the constraints accordingly on the rest of the unsolved squares.</p>
<p>Usually, this process of "constant propagation" doesn't solve the board entirely, but it does solve a sizable chunk. The second tier will then kick in. This parses each unit (or 9 squares which must all have unique number assignments, e.g. a row or column) for the "possible" values of each unsolved square. This list of possible values is represented as a string in the <code>Square</code> class:</p>
<pre><code>class Square {
private $name; // 00, 01, 02, ... , 86, 87, 88
private $peers; // All squares in same row, col, and box
private $number; // Assigned value (0 if not assigned)
private $possibles; // String of possible numbers (1-9)
public function __construct($name, $p = 0) {
$this->name = $name;
$this->setNumber($p);
if ($p == 0) {
$this->possibles = "123456789";
}
}
// ... other functions
</code></pre>
<p>Given a whole array of unsolved squares in a unit (as described in the second tier above), the second tier will concatenate all the strings of "possibles" into a single string. It will then search through that single string for any unique character values - values which do not repeat themselves. This will indicate that, within the unit of squares, there is only one square that can take on that particular value.</p>
<p>My question is: for implementing this second tier, how can I parse this string of all the possible values in a unit and easily detect the unique value(s)? I know I could create an array where each index is represented by the numbers 1-9, and I could increment the value at the corresponding index by 1 for each possible-value of that number that I find, then scan the array again for any values of 1, but this seems extremely inefficient, requiring two linear scans of an array for each unit, and in a Sudoku puzzle there are 27 units.</p>
| [
{
"answer_id": 399225,
"author": "PEZ",
"author_id": 44639,
"author_profile": "https://Stackoverflow.com/users/44639",
"pm_score": 3,
"selected": true,
"text": "$all_possibilities = \"1234567891234\";\n$unique = array();\nforeach (count_chars($all_possibilities, 1) as $c => $occurrences)... | 2008/12/29 | [
"https://Stackoverflow.com/questions/399066",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13604/"
] |
399,067 | <p>Bear with me while I explain my question. Skip down to the bold heading if you already understand extended slice list indexing.</p>
<p>In python, you can index lists using slice notation. Here's an example:</p>
<pre><code>>>> A = list(range(10))
>>> A[0:5]
[0, 1, 2, 3, 4]
</code></pre>
<p>You can also include a stride, which acts like a "step":</p>
<pre><code>>>> A[0:5:2]
[0, 2, 4]
</code></pre>
<p>The stride is also allowed to be negative, meaning the elements are retrieved in reverse order:</p>
<pre><code>>>> A[5:0:-1]
[5, 4, 3, 2, 1]
</code></pre>
<p>But wait! I wanted to see <code>[4, 3, 2, 1, 0]</code>. Oh, I see, I need to decrement the start and end indices:</p>
<pre><code>>>> A[4:-1:-1]
[]
</code></pre>
<p>What happened? It's interpreting -1 as being at the end of the array, not the beginning. I know you can achieve this as follows:</p>
<pre><code>>>> A[4::-1]
[4, 3, 2, 1, 0]
</code></pre>
<p>But you can't use this in all cases. For example, in a method that's been passed indices. </p>
<h2>My question is:</h2>
<p>Is there any good pythonic way of using extended slices with negative strides <em>and explicit start and end indices</em> that include the first element of a sequence?</p>
<p>This is what I've come up with so far, but it seems unsatisfying.</p>
<pre><code>>>> A[0:5][::-1]
[4, 3, 2, 1, 0]
</code></pre>
| [
{
"answer_id": 399082,
"author": "Charlie Martin",
"author_id": 35092,
"author_profile": "https://Stackoverflow.com/users/35092",
"pm_score": 0,
"selected": false,
"text": "a[4::-1]\n Python 2.6 (r26:66714, Dec 4 2008, 11:34:15) \n[GCC 4.0.1 (Apple Inc. build 5488)] on darwin\nType \"he... | 2008/12/29 | [
"https://Stackoverflow.com/questions/399067",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/44743/"
] |
399,078 | <p>I am tired of always trying to guess, if I should escape special characters like '<code>()[]{}|</code>' etc. when using many implementations of regexps.</p>
<p>It is different with, for example, Python, sed, grep, awk, Perl, rename, Apache, find and so on.
Is there any rule set which tells when I should, and when I should not, escape special characters? Does it depend on the regexp type, like PCRE, POSIX or extended regexps?</p>
| [
{
"answer_id": 399175,
"author": "Rob Wells",
"author_id": 2974,
"author_profile": "https://Stackoverflow.com/users/2974",
"pm_score": 2,
"selected": false,
"text": "sed -e 's/foo\\(bar/something_else/'\n sed -e 's/foo[(]bar/something_else/'\n"
},
{
"answer_id": 400316,
"auth... | 2008/12/29 | [
"https://Stackoverflow.com/questions/399078",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/37511/"
] |
399,101 | <p>Here is some XAML</p>
<pre><code><HierarchicalDataTemplate DataType="{x:Type data:FolderEntity}"
ItemsSource="{Binding Path=FolderEntities,UpdateSourceTrigger=PropertyChanged}">
<Label Content="{Binding FolderName}"/>
</HierarchicalDataTemplate>
<TreeView/>
</code></pre>
<p>data:FolderEntity is a LINQ to SQL data class which implements the INotifyPropertyChanging and INotifyPropertyChanged interfaces.</p>
<p>My problem is that when I change the FolderEntities property the binding doesn't update. If I change the FolderName property the tree node that corresponds to that item will change, but the collection that is FolderEntities just wont.</p>
<p>I'm thinking WPF checks to see whether the collection reference has changed, or does the ItemsSource object have to be an ObservableCollection`1 for this to work?</p>
<p>Any input on the matter is much appreciated.</p>
| [
{
"answer_id": 399127,
"author": "Matt Hamilton",
"author_id": 615,
"author_profile": "https://Stackoverflow.com/users/615",
"pm_score": 3,
"selected": true,
"text": "ObservableCollection<T>"
},
{
"answer_id": 399267,
"author": "Dennis",
"author_id": 73025,
"author_pr... | 2008/12/29 | [
"https://Stackoverflow.com/questions/399101",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/58961/"
] |
399,114 | <p>C++ offers three floating point types: float, double, and long double. I infrequently use floating-point in my code, but when I do, I'm always caught out by warnings on innocuous lines like</p>
<pre><code>float PiForSquares = 4.0;
</code></pre>
<p>The problem is that the literal 4.0 is a double, not a float - Which is irritating.</p>
<p>For integer types, we have short int, int and long int, which is pretty straightforward. Why doesn't C just have short float, float and long float? And where on earth did "double" come from?</p>
<p>EDIT: It seems the relationship between floating types is similar to that of integers. double must be at least as big as float, and long double is at least as big as double. No other guarantees of precision/range are made.</p>
| [
{
"answer_id": 399120,
"author": "Doug T.",
"author_id": 8123,
"author_profile": "https://Stackoverflow.com/users/8123",
"pm_score": 5,
"selected": false,
"text": " float f = 4.0f;\n long double f = 4.0l;\n"
},
{
"answer_id": 399160,
"author": "Charlie Martin",
"author_id... | 2008/12/29 | [
"https://Stackoverflow.com/questions/399114",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1737/"
] |
399,129 | <p>I've been trying (and failing) to figure out how to send email via Python.</p>
<p>Trying the example from here:
<a href="http://docs.python.org/library/smtplib.html#smtplib.SMTP" rel="noreferrer">http://docs.python.org/library/smtplib.html#smtplib.SMTP</a></p>
<p>but added the line <code>server = smtplib.SMTP_SSL('smtp.gmail.com', 465)</code> after I got a bounceback about not having an SSL connection. </p>
<p>Now I'm getting this:</p>
<pre><code>Traceback (most recent call last):
File "C:/Python26/08_emailconnects/12_29_EmailSendExample_NotWorkingYet.py", line 37, in <module>
server = smtplib.SMTP('smtp.gmail.com', 65)
File "C:\Python26\lib\smtplib.py", line 239, in __init__
(code, msg) = self.connect(host, port)
File "C:\Python26\lib\smtplib.py", line 295, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "C:\Python26\lib\smtplib.py", line 273, in _get_socket
return socket.create_connection((port, host), timeout)
File "C:\Python26\lib\socket.py", line 512, in create_connection
raise error, msg
error: [Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
>>>
</code></pre>
<p>Thoughts?</p>
<hr>
<p>server = smtplib.SMTP("smtp.google.com", 495) gives me a timeout error. just smtplib.smtp("smtp.google.com", 495) gives me "SSLError: [Errno 1] _ssl.c:480: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol" (see below).</p>
<p>I'm trying different ports and now I'm getting a completely new error. I'll just post the whole bit of code, I'm probably making some rookie mistake.</p>
<p>"</p>
<pre><code>import smtplib
mailuser = 'MYEMAIL@gmail.com'
mailpasswd = 'MYPASSWORD'
fromaddr = 'MYEMAIL@gmail.com'
toaddrs = 'MYEMAIL2@gmail.com'
msg = 'Hooooorah!'
print msg
server = smtplib.SMTP_SSL('smtp.google.com')
server = smtplib.SMTP_SSL_PORT=587
server.user(mailuser)
server.pass_(mailpasswd)
server.set_debuglevel(1)
server.sendmail(fromaddr, toaddrs, msg)
server.quit()
</code></pre>
<p>"</p>
<p>and then I get this error message: "</p>
<pre><code>Traceback (most recent call last):
File "C:/Python26/08_emailconnects/12_29_eMAILSendtryin_stripped.py", line 16, in <module>
server = smtplib.SMTP_SSL('smtp.google.com')
File "C:\Python26\lib\smtplib.py", line 749, in __init__
SMTP.__init__(self, host, port, local_hostname, timeout)
File "C:\Python26\lib\smtplib.py", line 239, in __init__
(code, msg) = self.connect(host, port)
File "C:\Python26\lib\smtplib.py", line 295, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "C:\Python26\lib\smtplib.py", line 755, in _get_socket
self.sock = ssl.wrap_socket(self.sock, self.keyfile, self.certfile)
File "C:\Python26\lib\ssl.py", line 350, in wrap_socket
suppress_ragged_eofs=suppress_ragged_eofs)
File "C:\Python26\lib\ssl.py", line 118, in __init__
self.do_handshake()
File "C:\Python26\lib\ssl.py", line 293, in do_handshake
self._sslobj.do_handshake()
SSLError: [Errno 1] _ssl.c:480: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol
</code></pre>
<p>"</p>
<p>note that actually the which looks like "server = smtplib.SMTPSSLPORT=587" is actually "server = smtplib.SMTP <em>underscore</em> SSL <em>underscore</em> PORT=587", there's some sort of formatting thing going on here.</p>
| [
{
"answer_id": 399240,
"author": "Federico A. Ramponi",
"author_id": 18770,
"author_profile": "https://Stackoverflow.com/users/18770",
"pm_score": 5,
"selected": false,
"text": "import smtplib\n\nFROMADDR = \"my.real.address@gmail.com\"\nLOGIN = FROMADDR\nPASSWORD = \"my.real.password... | 2008/12/29 | [
"https://Stackoverflow.com/questions/399129",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/50019/"
] |
399,135 | <p>When using Visual Studio (though ideally this can apply to the generic case) and double click on a button I've created, the event handler code that is auto generated uses the following signature:</p>
<pre><code>Protected Sub btnSubmitRequest_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSubmitRequest.Click
End Sub
</code></pre>
<p>Is it best practice to leave the name of this method as is, or should it be renamed to something a little more descriptive, such as SubmitNewEmployeeRequest?</p>
| [
{
"answer_id": 399145,
"author": "recursive",
"author_id": 44743,
"author_profile": "https://Stackoverflow.com/users/44743",
"pm_score": 4,
"selected": true,
"text": "SubmitNewEmployeeRequest btnSubmitRequest_Click SubmitNewEmployeeRequest"
}
] | 2008/12/29 | [
"https://Stackoverflow.com/questions/399135",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/71/"
] |
399,137 | <p>Here's a PHP example of mine. Can anyone find a shorter/easier way to do this?</p>
<pre><code><? foreach($posts as $post){?>
<div class="<?=($c++%2==1)?‘odd’:NULL?>">
<?=$post?>
</div>
<? }?>
<style>
.odd{background-color:red;}
</style>
</code></pre>
<p>Examples in other languages would be fun to see as well.</p>
| [
{
"answer_id": 399156,
"author": "Vilx-",
"author_id": 41360,
"author_profile": "https://Stackoverflow.com/users/41360",
"pm_score": 7,
"selected": true,
"text": "$c = true; // Let's not forget to initialize our variables, shall we?\nforeach($posts as $post)\n echo '<div'.(($c = !$c)?... | 2008/12/29 | [
"https://Stackoverflow.com/questions/399137",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/46443/"
] |
399,155 | <p>I posted days ago about access control to web service (<a href="https://stackoverflow.com/questions/390853/access-control-to-web-service">Access control to web service</a>). In short, I have an ASP.NET web service deployed on <strong>//service/webservice</strong> and I want my ASP.NET web application (app1) on the <strong>//web1</strong> to access the web service with certificate authentication. I keep getting <em>System.Net.WebException: The request failed with HTTP status 403: Forbidden</em> exception. The following is my setup:</p>
<p>On certificate export;</p>
<ul>
<li>I exported a server certificate issued to <strong>//service</strong> from LocalMachine store and saved it as service.cer.</li>
<li>I also exported a client certificate issued to <strong>//web1</strong> from LocalMachine store and saved it as web1.cer</li>
</ul>
<p>Setup on <strong>//service/webservice</strong>:</p>
<ul>
<li>On Directory Security, unchecked Anonymous Access and all Authentication Access (Integrated Windows Access, Digest Authentication and Basic Authentication). </li>
<li>On Secure communications, checked Required secure channel(SSL), Require 128-bit encyption, Require client certificate, and Enable client certificate mapping. I then mapped web1.cer to an AD account <strong>MyDomain/user</strong> which has access right to <strong>//service/webservice</strong></li>
<li>For <strong>//service/webservice/WebService.asmx</strong>, set <code><authentication mode="Windows" /></code> on web.config</li>
</ul>
<p>Setup on <strong>//web1/app1</strong></p>
<ul>
<li>Set <code><authentication mode="Windows" /></code> and <code><identity impersonate="true" /></code> on web.config</li>
<li>In VS2008, I added the web reference to <strong>//service/webservice/WebService.asmx</strong> and named it WService</li>
<li>In <strong>//web1/app1/default.aspx.cs</strong>, I had this:</li>
</ul>
<blockquote>
<p></p>
</blockquote>
<pre><code>using System.Security.Cryptography.X509Certificates;
using System.Net;
WService.WebService ws = new WService.WebService();
ServicePointManager.ServerCertificateValidationCallback = delegate(Object sender1, X509Certificate cert, X509Chain chain, System.Net.Security.SslPolicyErrors errors) { return true; };
//I was a bit confused here on which certificate I should use so I have tried both service.cer and web1.cer but still got the same error
X509Certificate x509 = X509Certificate.CreateFromCertFile(@"C:\Certificates\service.cer");
ws.ClientCertificates.Add(x509);
ws.DoSomething();
</code></pre>
<ul>
<li>I ran WinHttpCertCfg.exe to grant access to both certificates in LocalMachine for ASPNET account</li>
</ul>
<p>I went to <strong><a href="https://service/webservice/WebService.asmx" rel="nofollow noreferrer">https://service/webservice/WebService.asmx</a></strong> and was prompted to provide a client certificate and after that I was through. But if I went to <strong><a href="https://web1/app1/default.aspx" rel="nofollow noreferrer">https://web1/app1/default.aspx</a></strong> (which would call the web service) and I would get the HTTP status 403 exception.</p>
<p>What did I miss? I would assume the problem is because <strong>//web1/app1/default.aspx.cs</strong> failed to transmit the certificate across. If that's the problem, how do I do that? I built both the asmx and aspx on VS 2008 and ASP.NET 3.5.</p>
| [
{
"answer_id": 23294310,
"author": "Hugh Jeffner",
"author_id": 383761,
"author_profile": "https://Stackoverflow.com/users/383761",
"pm_score": 1,
"selected": false,
"text": "403 7 5"
}
] | 2008/12/30 | [
"https://Stackoverflow.com/questions/399155",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31936/"
] |
399,165 | <p>My marketing department, bless them, has decided to make a sweepstakes where people enter over a webpage. That is great but the information isn't stored to a DB of any sort but is sent to an exchange mail box as an email. Great.</p>
<p>My challenge is to extract the entry (and marketing info) from these emails and store them someplace more useful, say a flat file or CSV. The only saving grace is that the emails have a highly consistant format.</p>
<p>I am sure I could spend the time saving all the emails to files and then write an app to munge through them all but was hoping for a much more elegant solution. Can I programmatically access an exchange mailbox, read all the emails and then save that data? </p>
| [
{
"answer_id": 403999,
"author": "Craig",
"author_id": 2894,
"author_profile": "https://Stackoverflow.com/users/2894",
"pm_score": 3,
"selected": false,
"text": "Private Sub btnGo_Click()\n If ComboBox1.SelText <> \"\" Then\n Dim objOutlook As New Outlook.Application\n Dim objName... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399165",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2894/"
] |
399,180 | <p>I have an application where users can upload video files of any size, and I'd like to be able to determine the the height/width of a Flash video file (flv or f4v) from a PHP script so that I can size the player appropriately. I'd love a pure PHP solution, but I'd be open to shelling out to a command line tool and parsing the output (if such a tool exists).</p>
<p>Thanks in advance!</p>
| [
{
"answer_id": 713517,
"author": "Christoph",
"author_id": 48015,
"author_profile": "https://Stackoverflow.com/users/48015",
"pm_score": 1,
"selected": false,
"text": "function flvdim($name) {\n $file = @fopen($name, 'rb');\n if($file === false)\n return false;\n\n $heade... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399180",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/38458/"
] |
399,190 | <p>When using ActionLink to render data from database which has HTML tags </p>
<pre><code>(ie <p>)
</code></pre>
<p>incorporated in it, ActionLink escapes the tags. What is the best way to handle this? </p>
| [
{
"answer_id": 713517,
"author": "Christoph",
"author_id": 48015,
"author_profile": "https://Stackoverflow.com/users/48015",
"pm_score": 1,
"selected": false,
"text": "function flvdim($name) {\n $file = @fopen($name, 'rb');\n if($file === false)\n return false;\n\n $heade... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399190",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/49632/"
] |
399,202 | <p>I thought a great way to test my understanding of generic functions would be to create a function that would spit out a hex representation of a hash using one of the classes that inherits from HashAlgorithm. Since all of the HashAlgorithm classes offer ComputeHash, I thought this would be simple. When I construct such a function. though, I get an error because HashAlgorithm itself doesn't offer a constructor. I couldn't find any sort of interface or subclass of HashAlgorithm that does offer a constructor, either. If not all HashAlgorithm classes are required to support a constructor, is there some additional constraint I can put on a generic type to ensure a type offers an empty constructor or will I be forced to create an overload for each of the HashAlgorithm classes I know offer an empty constructor.</p>
<p>Here is what I have so far (in its non-compiling state):</p>
<pre><code>public static string GetHexHash<HashAlgorithmToUse>(Stream dataStreamToHash) where HashAlgorithmToUse : HashAlgorithm
{
StringBuilder Result = new StringBuilder();
byte[] ByteHash = (new HashAlgorithmToUse()).ComputeHash(dataStreamToHash);
foreach (byte HashByte in ByteHash)
{
Result.Append(HashByte.ToString("X2"));
}
return Result.ToString();
}
</code></pre>
<p><strong>Edit</strong> Matt Hamilton's answer nailed it right away, simply making the generic constraint more complex: <code>where HashAlgorithmToUse : HashAlgorith, new()</code>. I didn't even realize I could have multiple constraints. I definitely have a way to go before I fully understand all I can do with Generics. I suppose you can make a very non-generic, generic function if you get too carried away with the constraints.</p>
| [
{
"answer_id": 399217,
"author": "Matt Hamilton",
"author_id": 615,
"author_profile": "https://Stackoverflow.com/users/615",
"pm_score": 3,
"selected": true,
"text": "new() public static string GetHexHash<HashAlgorithmToUse>(Stream dataStreamToHash)\n where HashAlgorithmToUse : HashAl... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399202",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/48700/"
] |
399,204 | <p>Given the following xml fragment:</p>
<pre><code><Problems>
<Problem>
<File>file1</File>
<Description>desc1</Description>
</Problem>
<Problem>
<File>file1</File>
<Description>desc2</Description>
</Problem>
<Problem>
<File>file2</File>
<Description>desc1</Description>
</Problem>
</Problems>
</code></pre>
<p>I need to produce something like</p>
<pre><code><html>
<body>
<h1>file1</h1>
<p>des1</p>
<p>desc2</p>
<h1>file2</h1>
<p>des1</p>
</body>
</html>
</code></pre>
<p>I tried using a key, like </p>
<pre><code><xsl:key name="files" match="Problem" use="File"/>
</code></pre>
<p>but I don't really understand how to take it to the next step, or if that's even the right approach. </p>
| [
{
"answer_id": 399262,
"author": "Richard A",
"author_id": 24355,
"author_profile": "https://Stackoverflow.com/users/24355",
"pm_score": 4,
"selected": true,
"text": "<?xml version=\"1.0\"?>\n<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">\n <xsl:ou... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399204",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/246/"
] |
399,209 | <p>In bash is there a quick way to do tab auto-completion based on the middle of a word. </p>
<p>So for example, if I have these files in a directory: </p>
<pre><code>001_apple.txt 002_pear.txt 003_dog.txt
</code></pre>
<p>I would like to type the sequence: <code>*d<TAB></code> to auto-complete 003_dog.txt. </p>
<p>Can this be done in bash? Is it easier to do in other shells? </p>
| [
{
"answer_id": 399221,
"author": "Ben",
"author_id": 36522,
"author_profile": "https://Stackoverflow.com/users/36522",
"pm_score": 0,
"selected": false,
"text": "`ls *d*`"
},
{
"answer_id": 399275,
"author": "codelogic",
"author_id": 43427,
"author_profile": "https://... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399209",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17174/"
] |
399,222 | <p>Isn't the use of delegates to help with some asynchronous cases? I tried the following but my UI still hangs. When on earth do you use delegates?</p>
<pre><code> Public Class Form1
Private Delegate Sub testDelegate()
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Button1.Click
Dim d As testDelegate = New testDelegate(AddressOf Add)
d.Invoke()
End Sub
Private Sub Add()
For i As Integer = 0 To 10000
TextBox1.Text = i + 1
Next
End Sub
End Class
</code></pre>
| [
{
"answer_id": 399229,
"author": "Otávio Décio",
"author_id": 48684,
"author_profile": "https://Stackoverflow.com/users/48684",
"pm_score": 2,
"selected": false,
"text": "//Callbacks \n//--------------------------------------------------------------------------------------------------... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399222",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23667/"
] |
399,224 | <p>I want to write tests for my app, though each time I look at rspec.info, I really don't see a definite path to take towards "doing things right" and testing first. I watched the peepcode videos on rspec more than once, yet it doesn't take. I want to take more pride in my work, and I think that testing will help. How can I break through this mental block? </p>
| [
{
"answer_id": 399426,
"author": "Norman Ramsey",
"author_id": 41661,
"author_profile": "https://Stackoverflow.com/users/41661",
"pm_score": 3,
"selected": false,
"text": "73 tests passed.\n"
}
] | 2008/12/30 | [
"https://Stackoverflow.com/questions/399224",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33287/"
] |
399,250 | <p>PHP's parse_url() has a host field, which includes the full host. I'm looking for the most reliable (and least costly) way to only return the domain and TLD.</p>
<p>Given the examples:</p>
<ul>
<li><a href="http://www.google.com/foo" rel="noreferrer">http://www.google.com/foo</a>, parse_url() returns www.google.com for host</li>
<li><a href="http://www.google.co.uk/foo" rel="noreferrer">http://www.google.co.uk/foo</a>, parse_url() returns www.google.co.uk for host</li>
</ul>
<p>I am looking for only <strong>google.com</strong> or <strong>google.co.uk</strong>. I have contemplated a table of valid TLD's/suffixes and only allowing those and one word. Would you do it any other way? Does anyone know of a pre-canned valid REGEX for this sort of thing?</p>
| [
{
"answer_id": 399294,
"author": "Eineki",
"author_id": 29125,
"author_profile": "https://Stackoverflow.com/users/29125",
"pm_score": 0,
"selected": false,
"text": "<?php\n $urlCompoments=parse_url($theUrl);\n $chunk=explode('.',$urlComponents['host']);\n\n $tldIndex = count($ch... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399250",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13203/"
] |
399,252 | <p>For testing purposes I want send mail to my localhost user account rather than my webserver. I am unsure how to do this using mail.app. Any help would be appreciated.</p>
| [
{
"answer_id": 399284,
"author": "codelogic",
"author_id": 43427,
"author_profile": "https://Stackoverflow.com/users/43427",
"pm_score": 4,
"selected": true,
"text": "mail mail -s \"Testing\" `whoami`@`hostname`\n<type something>\nCtrl-D to finish and send\n whoami hostname mail -s \"Tes... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399252",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/49684/"
] |
399,263 | <p>I'm writing a Firefox extension that needs to know what the username of the currently logged in user is in Windows, Mac, or Linux. So if I'm logged into my machine as "brh", it'll return "brh". Any idea how to do that from extension JavaScript?</p>
| [
{
"answer_id": 399885,
"author": "James Brady",
"author_id": 29903,
"author_profile": "https://Stackoverflow.com/users/29903",
"pm_score": 5,
"selected": true,
"text": "Components.classes[\"@mozilla.org/process/environment;1\"].getService(Components.interfaces.nsIEnvironment).get('USER')... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399263",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11284/"
] |
399,270 | <p>If I'm using a <code>Hashtable</code>, I can write code like this:</p>
<pre><code>object item = hashtable[key] ?? default_value;
</code></pre>
<p>That works whether or not <code>key</code> appears in the <code>Hashtable</code>.</p>
<p>I can't do that with a <code>Dictionary<TKey. TValue></code>. If the key's not present in the dictionary, that will throw a <code>KeyNotFoundException</code>. So I have to write code like this:</p>
<pre><code>MyClass item;
if (!(dict.TryGetValue(key, out item))
{
item = default_value;
}
</code></pre>
<p>I'm wondering why this is. <code>Dictionary<TKey, TValue></code> is just a wrapper around <code>Hashtable</code>. Why has this restriction been added to it?</p>
<p><strong>Edit:</strong></p>
<p>For another perspective on PopCatalin's answer (see below), the code I'd written above won't work if the dictionary's values are of a value type. If I'm using a <code>Dictionary<int, int></code>, then the code I would <em>like</em> to use looks like this:</p>
<pre><code>int i = dict[key] ?? default_value;
</code></pre>
<p>And that won't compile, because <code>dict[key]</code> isn't a nullable or reference type.</p>
| [
{
"answer_id": 399278,
"author": "Otávio Décio",
"author_id": 48684,
"author_profile": "https://Stackoverflow.com/users/48684",
"pm_score": 1,
"selected": false,
"text": "public TValue get_Item(TKey key)\n{\n int index = this.FindEntry(key);\n if (index >= 0)\n {\n return... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399270",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19403/"
] |
399,286 | <p>Can anybody provide some instruction on how to setup a war file to show a favicon.ico in the browser address bar?</p>
| [
{
"answer_id": 399773,
"author": "stian",
"author_id": 17542,
"author_profile": "https://Stackoverflow.com/users/17542",
"pm_score": 6,
"selected": true,
"text": "<link rel=\"icon\" type=\"image/gif\" href=\"/img/image.gif\">\n"
}
] | 2008/12/30 | [
"https://Stackoverflow.com/questions/399286",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6218/"
] |
399,291 | <p>Curious as to 99.95% uptime REALLY means; Is it really going to go down 7 minutes a month? Please post your longest/average uptimes on EC2, thanks.</p>
| [
{
"answer_id": 399684,
"author": "kgiannakakis",
"author_id": 24054,
"author_profile": "https://Stackoverflow.com/users/24054",
"pm_score": 5,
"selected": true,
"text": "365 * 0.0005 = 0.1825 days or 4.38 hours\n"
},
{
"answer_id": 460610,
"author": "Community",
"author_i... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399291",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1263/"
] |
399,304 | <p>I've got a C++ program that's likely to generate a HUGE amount of data -- billions of binary records of varying sizes, most probably less than 256 bytes but a few stretching to several K. Most of the records will seldom be looked at by the program after they're created, but some will be accessed and modified regularly. There's no way to tell which are which when they're created.</p>
<p>Considering the volume of data, there's no way I can store it all in memory. But as the data only needs to be indexed and accessed by its number (a 64-bit integer), I <em>don't</em> want the overhead of a full-fledged database program. Ideally I'd like to treat it as an <code>std::map</code> with its data stored on disk until requested.</p>
<p>Is there an already-written library that will do what I'm looking for, or do I need to write it myself?</p>
<p>EDIT: After some thought, I realized that Rob Walker's answer had a valid point: I'd be hard-pressed to get anywhere near the same kind of data integrity out of a home-brew class that I'd get from a real database.</p>
<p>Although BerkeleyDB (as suggested by RHM) looks like it would do exactly what we're looking for, the dual-licensing is a headache that we don't want to deal with. When we're done with the code and can prove that it would benefit noticeably from BerkeleyDB (which it probably would), we'll reexamine the issue.</p>
<p>I did look at Ferruccio's suggestion of stxxl, but I wasn't able to tell how it would handle the program being interrupted and restarted (maybe with changes). With that much data, I'd hate to just scrap what it had already completed and start over every time, if some of the data could be saved.</p>
<p>So we've decided to use an SQLite database, at least for the initial development. Thanks to everyone who answered or voted.</p>
| [
{
"answer_id": 399328,
"author": "Ferruccio",
"author_id": 4086,
"author_profile": "https://Stackoverflow.com/users/4086",
"pm_score": 3,
"selected": false,
"text": "stxxl::map<>"
},
{
"answer_id": 2211790,
"author": "Frank",
"author_id": 60628,
"author_profile": "htt... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399304",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12193/"
] |
399,311 | <p>I please for your help.</p>
<p>I apologize for my English, it is still learning. I do one application in GUI in Java. I have one problem. </p>
<p>In this application I have an ArrayList that I want to meet with data.</p>
<p>User clicks on the button and data from JTextfield shall be placed in Arraylist. </p>
<p>When they do so, it is inserted only into the first row. Other entries in Arraylist are not. </p>
<p>Ask me please how do I do that.</p>
<p>Here is code of my application:</p>
<pre><code>public void save_to_array(String jmeno_zad,
String prijmeni_zad,
String rodne_cislo_zad,
String mesto_zad,
String spz_zad,
String barva_zad,
String vin_zad,
String znacka_zad){
String arraytext=prijmeni_zad+ ","+
jmeno_zad+ ","+
rodne_cislo_zad+ ","+
mesto_zad+","+
spz_zad+","+
barva_zad+","+
vin_zad+","+
znacka_zad;
int posl=arlist.size();
if(arlist.isEmpty()||posl==1){
arlist.add(0,arraytext);
}
if(!arlist.isEmpty()&& posl>1){
arlist.add(posl-1, cele_jmeno);
}
}
</code></pre>
| [
{
"answer_id": 399342,
"author": "Paul Tomblin",
"author_id": 3333,
"author_profile": "https://Stackoverflow.com/users/3333",
"pm_score": 2,
"selected": false,
"text": " int posl=arlist.size(); \n if(arlist.isEmpty()||posl==1){ \n arlist.add(0,arraytext);\n }\n if(!arlist.is... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399311",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
399,312 | <p>I encountered this term <em>Hindley-Milner</em>, and I'm not sure if grasp what it means.</p>
<p>I've read the following posts:</p>
<ul>
<li>Steve Yegge - <a href="http://steve-yegge.blogspot.com/2008/05/dynamic-languages-strike-back.html" rel="noreferrer">Dynamic Languages Strike Back</a></li>
<li>Steve Yegge - <a href="http://steve-yegge.blogspot.com/2007/01/pinocchio-problem.html" rel="noreferrer">The Pinocchio Problem</a></li>
<li>Daniel Spiewak - <a href="https://web.archive.org/web/20181118000004/http://www.codecommit.com/blog/scala/what-is-hindley-milner-and-why-is-it-cool" rel="noreferrer">What is Hindley-Milner? (and why is it cool?)</a></li>
</ul>
<p>But there is no single entry for this term in wikipedia where usually offers me a concise explanation.<br />
<sup><strong>Note</strong> - one has <a href="http://en.wikipedia.org/wiki/Hindley%E2%80%93Milner" rel="noreferrer">now been added</a></sup></p>
<p>What is it?<br />
What languages and tools implement or use it?<br />
Would you please offer a concise answer?</p>
| [
{
"answer_id": 399392,
"author": "Norman Ramsey",
"author_id": 41661,
"author_profile": "https://Stackoverflow.com/users/41661",
"pm_score": 9,
"selected": true,
"text": "a a a fun 'a length [] = 0\n | 'a length (x::xs) = 1 + length xs\n"
},
{
"answer_id": 11322607,
"... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399312",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/46090/"
] |
399,314 | <p>My product opens a web browser and points it at an HTML file containing a local Flash application. How do I detect programmatically whether this file loaded successfully and if not what exception was thrown? Is there a way to do this using Javascript?</p>
<p>Checking externally whether the file exists on disk is not enough because I've seen other failures occur (race conditions might be involved).</p>
| [
{
"answer_id": 399378,
"author": "Gili",
"author_id": 14731,
"author_profile": "https://Stackoverflow.com/users/14731",
"pm_score": 5,
"selected": true,
"text": "var params:Object = LoaderInfo(this.root.loaderInfo).parameters;\nif (ExternalInterface.available)\n{\n var onLoaded:String... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399314",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14731/"
] |
399,332 | <p>I'm doing a bookmarking system and looking for the fastest (easiest) way to retrieve a page's title with PHP. </p>
<p>It would be nice to have something like <code>$title = page_title($url)</code></p>
| [
{
"answer_id": 399341,
"author": "alex",
"author_id": 31671,
"author_profile": "https://Stackoverflow.com/users/31671",
"pm_score": 3,
"selected": false,
"text": "preg_match('/<title>(.*)<\\/title>/iU', $htmlSource, $titleMatches);\n\nprint_r($titleMatches);\n"
},
{
"answer_id": ... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399332",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
399,340 | <p>I always try to do the following:</p>
<pre><code><label><input type="checkbox" /> Some text</label>
</code></pre>
<p>or</p>
<pre><code><label for="idOfField"><input type="checkbox" id="idOfField" /> Some text</label>
</code></pre>
<p>My question is related to the label tag, specifically on a checkbox.</p>
<p>Most websites (I would say >40%) don't use the <code><label></code> tag.</p>
<p>Is there a reason for this? Is there a problem in a browser or some other issue?</p>
<p><strong>Note:</strong> Incase people don't know about the <code><label></code> tag, it has a number of advantages:</p>
<ul>
<li>checkboxes & radios: you can click on the text as well as the checkbox to check the checkbox (as well as focus I believe): Blah blah blah</li>
<li>other inputs: if you click the text, it will focus the input (textarea, text, file) (this functionality isn't as useful as checkboxes & radios)</li>
</ul>
<p><strong>Note 2:</strong> Some people have mentioned that example #2 is more correct than #1 (above), but according to the documentation <a href="http://www.w3.org/TR/html401/interact/forms.html#h-17.9.1" rel="noreferrer">here</a>, either is correct</p>
| [
{
"answer_id": 399351,
"author": "BQ.",
"author_id": 4632,
"author_profile": "https://Stackoverflow.com/users/4632",
"pm_score": 2,
"selected": false,
"text": "<label>"
},
{
"answer_id": 399364,
"author": "Eineki",
"author_id": 29125,
"author_profile": "https://Stacko... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399340",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5441/"
] |
399,348 | <p>In Joomla:</p>
<pre><code>$mainframe->getCfg('lang');
</code></pre>
<p>will return "english" (i think this is a default value), anyone can tell me where defined it? </p>
<p>Can I change it?</p>
| [
{
"answer_id": 401009,
"author": "jlleblanc",
"author_id": 586,
"author_profile": "https://Stackoverflow.com/users/586",
"pm_score": 0,
"selected": false,
"text": "$lang =& JFactory::getLanguage();\necho $lang->getName();\n"
},
{
"answer_id": 402046,
"author": "Community",
... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399348",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
399,352 | <p>My app will be full screen, but I am having trouble finding the document that explains how to change the status bar properties.</p>
<p>How can I change the status bar properties?</p>
| [
{
"answer_id": 399371,
"author": "dancavallaro",
"author_id": 42891,
"author_profile": "https://Stackoverflow.com/users/42891",
"pm_score": 6,
"selected": true,
"text": "[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO] Info.plist <key>UIStatusBarHidden</key>\n<true ... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399352",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/46865/"
] |
399,353 | <p>Say I have a thread that keeps running in the background to figure if a URL is accessible. If the URL is not accessible, the application need to show a modal dialog box. Things cannot go on if the URL is down. If I simply do a MessageBox.show from inside the thread, that message box will not be modal. ShowDialog won't work either.</p>
| [
{
"answer_id": 399362,
"author": "Otávio Décio",
"author_id": 48684,
"author_profile": "https://Stackoverflow.com/users/48684",
"pm_score": 2,
"selected": false,
"text": "private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) {\n this.Invoke(new MessageBoxDelegate(S... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399353",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
399,356 | <pre><code>.section .data
astring: .asciz "11010101"
format: .asciz "%d\n"
.section .text
.globl _start
_start:
xorl %ecx, %ecx
movb astring(%ecx,1), %al
movzbl %al, %eax
pushl %eax
pushl $format
call printf
addl $8, %esp
movl $1, %eax
movl $0, %ebx
int $0x80
</code></pre>
<p>Suppose I wanna break the .asciz string 1101011 and get it's first one. How do I go about it? The code above ain't working, it prints 49 or something.</p>
| [
{
"answer_id": 399363,
"author": "Robert Gamble",
"author_id": 25222,
"author_profile": "https://Stackoverflow.com/users/25222",
"pm_score": 3,
"selected": true,
"text": "printf %d %c"
},
{
"answer_id": 9782866,
"author": "charlyasap",
"author_id": 1280260,
"author_pr... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399356",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/45963/"
] |
399,359 | <p>My issue is that sometimes a piece of JavaScript (often Google Analytics) may take a very long time to load, although it's not important to the HTML be ready to be "traversed and manipulated". If I were to use the following code:</p>
<pre><code>$(document).ready(function () {
$("p").text("The DOM is now loaded and can be manipulated.");
});
</code></pre>
<p>would this mean that the <code><p></code> would not be populated till after something like Google Analytics is loaded?</p>
<p>Something like Google Analytics is generally not required on most websites and I have often found that I am waiting for it to load. (I don't want to use onload because <a href="http://docs.jquery.com/Events/ready#fn" rel="nofollow noreferrer">of it's unreliability</a>.)</p>
<p>Is there a better way or a way to say "don't wait for [...]"?</p>
<p>Note: I usually cannot put the code in a <code><script></code> tag just before the <code></body></code> tag because the site is based in a template. I usually can only edit the "content" of the page.</p>
| [
{
"answer_id": 399432,
"author": "Tamas Czinege",
"author_id": 8954,
"author_profile": "https://Stackoverflow.com/users/8954",
"pm_score": -1,
"selected": false,
"text": "$(document).ready(function()\n{\n setTimeOut(function()\n {\n // Your code comes here\n }, 0); // We don't... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399359",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5441/"
] |
399,370 | <p>I'm embedding a Flash video into an HTML and would like the user to have to click it to begin playing. According to the <a href="http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_12701" rel="nofollow noreferrer">Adobe <code><object></code> / <code><embed></code> element documentation</a>, there are variety of methods to do this:</p>
<p>1) Add a Flash parameter inside the <code><object></code> tag:</p>
<pre><code><param name="play" value="false">
</code></pre>
<p>2) Add the attribute <code>play</code> inside the <code><embed></code> tag:</p>
<pre><code><embed ... play="false">
</code></pre>
<p>3) Add the attribute <code>flashvars</code> inside the <code><embed></code> tag:</p>
<pre><code><embed ... flashvars="play=false">
</code></pre>
<p>Which is awesome. Only ... none of them work for me:</p>
<p><a href="http://johnboxall.github.com/test/flash/flash.htm" rel="nofollow noreferrer">http://johnboxall.github.com/test/flash/flash.htm</a></p>
<p>My code looks like this now:</p>
<pre><code><object width="590" height="475">
<param name="movie" value="untitled_skin.swf">
<param name="play" value="false">
<embed src="untitled_skin.swf" width="590" height="475" type="application/x-shockwave-flash" play="false" flashvars="autoplay=false&play=false" menu="false"></embed>
</object>
</code></pre>
<p>Anyone have any ideas? What am I doing wrong?</p>
| [
{
"answer_id": 401077,
"author": "fenomas",
"author_id": 10651,
"author_profile": "https://Stackoverflow.com/users/10651",
"pm_score": 5,
"selected": true,
"text": "autoplay"
},
{
"answer_id": 2636525,
"author": "Duke",
"author_id": 316384,
"author_profile": "https://... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399370",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/37522/"
] |
399,396 | <p>I'm writing a rake task that does some DB work outside of Rails/ActiveRecord.</p>
<p>Is there a way to get the DB connection info (host, username, password, DB name) for the current environment as defined in <code>database.yml</code>?</p>
<p>I'd like to get it so I can use it to connect like this...</p>
<pre><code>con = Mysql.real_connect("host", "user", "pw", "current_db")
</code></pre>
| [
{
"answer_id": 399411,
"author": "Robert Gamble",
"author_id": 25222,
"author_profile": "https://Stackoverflow.com/users/25222",
"pm_score": 9,
"selected": true,
"text": "config = Rails.configuration.database_configuration\nhost = config[Rails.env][\"host\"]\ndatabase = config[Rail... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399396",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42595/"
] |
399,401 | <p>I have a hibernate mapping as follows:</p>
<p>
</p>
<pre><code><hibernate-mapping>
<class name="kochman.elie.data.types.InvoiceTVO" table="INVOICE">
<id name="id" column="ID">
<generator class="increment"/>
</id>
<property name="date" column="INVOICE_DATE"/>
<property name="customerId" column="CUSTOMER_ID"/>
<property name="schoolId" column="SCHOOL_ID"/>
<property name="bookFee" column="BOOK_FEE"/>
<property name="adminFee" column="ADMIN_FEE"/>
<property name="totalFee" column="TOTAL_FEE"/>
</class>
</hibernate-mapping>
</code></pre>
<p>where InvoiceTVO has variables defined as:</p>
<pre><code>private int id;
private Date date;
private int customerId;
private int schoolId;
private float bookFee;
private float adminFee;
private float totalFee;
</code></pre>
<p>When I do an insert on this table, I get the following error:</p>
<pre><code>Hibernate: insert into INVOICE (INVOICE_DATE, CUSTOMER_ID, SCHOOL_ID, BOOK_FEE, ADMIN_FEE, TOTAL_FEE, ID) values (?, ?, ?, ?, ?, ?, ?)
50156 [AWT-EventQueue-0] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 0, SQLState: 22001
50156 [AWT-EventQueue-0] ERROR org.hibernate.util.JDBCExceptionReporter - Data truncation: Data truncated for column 'ADMIN_FEE' at row 1
50156 [AWT-EventQueue-0] ERROR org.hibernate.event.def.AbstractFlushingEventListener - Could not synchronize database state with session
</code></pre>
<p>I tried changing the type of adminFee to double, and that didn't work either. The problem is, Hibernate did actually perform the insert properly, and future select statements work to return the current set of values, but this error prevents me from doing further processing on this invoice.</p>
<p>The fields bookFee, adminFee, and totalFee are all supposed to be currencies. They are defined in the MySQL database as decimal(5,2).</p>
<p>Any help in how to resolve this would be greatly appreciated.</p>
| [
{
"answer_id": 399420,
"author": "OscarRyz",
"author_id": 20654,
"author_profile": "https://Stackoverflow.com/users/20654",
"pm_score": 1,
"selected": false,
"text": "<property name=\"adminFee\" column=\"ADMIN_FEE\" type=\"float\"/>\n"
}
] | 2008/12/30 | [
"https://Stackoverflow.com/questions/399401",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23249/"
] |
399,406 | <p>Does Microsoft Access have Full Text Search?</p>
<p>I know that MySQL and SQL Server have Full Text Search, but I am not too certain on Access.</p>
<p>If Access doesn't have Full Text, what is the best alternative to achieve the same objective of Full Text Search?</p>
<p>Thanks</p>
| [
{
"answer_id": 27727194,
"author": "AndrewM",
"author_id": 3133514,
"author_profile": "https://Stackoverflow.com/users/3133514",
"pm_score": 2,
"selected": false,
"text": "'This code requires a table called tblWordList with fields called Word (str 255), WordCount (long), FirstCopyID (lon... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399406",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/50050/"
] |
399,409 | <p>Are there any good language-agnostic distributed make systems for linux that are secure and free?</p>
<p><strong>Background Information:</strong></p>
<p>I run scientific experiments (computer-science ones) that sometimes have large dependency trees, occasionally on the order of thousands or tens of thousands of tree nodes. This dependency tree is over the data files, data processing executables, and results files. </p>
<p>I've experimented with various techniques over the years including:</p>
<ol>
<li>Rolling my own dependency tracker using a database and running a script on each worker machine. This can get a bit cumbersome, especially when trying to work with non-scripting languages.</li>
<li>Putting all the processing commands in single makefile, with pseudo-targets that can be manually "built" on different worker machines. This requires no special tools, but it can be a pain to manually break up the work into evenly-sized pseudo-target chunks and correctly invoking "make" on each worker box.</li>
<li><em><a href="http://distmake.sourceforge.net/pmwiki/pmwiki.php" rel="noreferrer">distmake</a></em>: automatically distribute the execution of commands from a single makefile...</li>
</ol>
<p>I'm basically looking for something like distmake, but more secure. As far as I can tell, distmake essentially leaves a wide-open backdoor into each worker node. </p>
<p>It would also be nice if a replacement were more robust than distmake. If you break out of the main distmake call, it can shut down the backdoor servers, but it doesn't properly kill the executing processes on the worker nodes.</p>
<hr>
<p><strong>Clarifications:</strong></p>
<p>I am processing data with the makefile, not compiling and linking with gcc. From what I read in the documentation, distcc is a specialized tool for distributing gcc. I'll be running my own executables on very large data files hosted on a shared filesystem, not gcc on source files, so distcc isn't helpful.</p>
<p>The worker nodes are externally-visible machines, so I want any worker daemons to be at least as secure as ssh. As best I can tell without reading the source, distmake worker daemons open up a port and will accept commands from anyone who attaches to it. They will execute the commands as the user who started the daemon. </p>
| [
{
"answer_id": 399461,
"author": "James Cape",
"author_id": 41044,
"author_profile": "https://Stackoverflow.com/users/41044",
"pm_score": 3,
"selected": true,
"text": "make"
},
{
"answer_id": 399502,
"author": "Norman Ramsey",
"author_id": 41661,
"author_profile": "ht... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399409",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25050/"
] |
399,447 | <p>I have a site in rails and want to have site-wide settings. One part of my app can notify the admin by SMS if a specific event happens. This is an example of a feature that I want configurable via the site-wide settings.</p>
<p>So I was thinking I should have a Setting model or something. It needs to be a model because I want to be able to has_many :contacts for the SMS notification.</p>
<p>The problem is that there can only be one post in the database for the settings model. So I was thinking of using a Singleton model but that only prevents new object to be created right?</p>
<p>Would I still need to create getter and setter methods for each attribute like so:</p>
<pre><code>def self.attribute=(param)
Model.first.attribute = param
end
def self.attribute
Model.first.attribute
end
</code></pre>
<p>Is it perhaps not best-practice to use Model.attribute directly but always create an instance of it and use that?</p>
<p>What should I do here?</p>
| [
{
"answer_id": 399650,
"author": "Otto",
"author_id": 9594,
"author_profile": "https://Stackoverflow.com/users/9594",
"pm_score": 1,
"selected": false,
"text": "has_many :contacts has_many has_many :contacts"
},
{
"answer_id": 12463209,
"author": "Rich",
"author_id": 8261... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399447",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9191/"
] |
399,452 | <p>I am using the pimpl idiom and want to reference one of the methods of the forward declared class. Below isn't exactly what I'm doing but uses the same concepts.</p>
<pre><code>template< typename Class, void (Class::*Method)(void) >
struct Call
{
Call( Class* c )
: m_c(c)
{ }
void operator()( void )
{
(m_c->*Method)();
}
Class* m_c;
};
class A
{
public:
void foo( void )
{
std::cout << "A::foo\n";
}
};
// this works
void do_foo( A* a )
{
Call<A,&A::foo> c(a);
c();
}
class B;
// this doesn't compile
extern void B::bar( void );
// this is what i'd ultimately like to do
void do_bar( B* b )
{
Call<B,&B::bar> c(b);
c();
}
</code></pre>
<p>Two questions:</p>
<ul>
<li>Can this be done?</li>
<li>Why can't it be done?</li>
</ul>
| [
{
"answer_id": 399515,
"author": "jmucchiello",
"author_id": 44065,
"author_profile": "https://Stackoverflow.com/users/44065",
"pm_score": 0,
"selected": false,
"text": "void do_bar( B* b )\n{\n Call<B,&B::bar> c(b);\n c();\n}\n void do_Bar(B* b) {\n b->bar();\n}\n extern void B::... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399452",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28817/"
] |
399,459 | <p>Hi I'm looking for some help in mapping the following tables to a hibernate mapping file:
<a href="http://barry-jones.com/temp/sch2.jpg" rel="nofollow noreferrer">schema image http://barry-jones.com/temp/sch2.jpg</a></p>
<p>I'm trying to fill the localCalandarGroups List with related localCalendarGroups when loading my userVOs. I'm using a intermediary table(user_localCalendarGroup) to keep the user and localCalendarGroup ids</p>
<pre><code> public class UserVO
{
public virtual int id { get; set; }
public virtual string name { get; set; }
public virtual string pass { get; set; }
public virtual string email { get; set; }
public virtual string level { get; set; }
public virtual List<LocalCalendarGroupVO> localCalendarGroups { get; set; }
}
public class LocalCalendarGroupVO
{
public virtual int id { get; set; }
public virtual string name { get; set; }
}
</code></pre>
<p>This is my mapping file thus far. How can I make NHibernate aware of the intermediary table?</p>
<pre><code> <class name="UserVO" table="tb_users" lazy="false">
<id name="id" column="id">
<generator class="native" />
</id>
<property name="name" />
<property name="pass" />
<property name="level" />
<property name="email" />
<property name="localCalendarGroups"/>
</code></pre>
<p></p>
<p>Any help,pointers much appreciated.</p>
| [
{
"answer_id": 399799,
"author": "Darin Dimitrov",
"author_id": 29407,
"author_profile": "https://Stackoverflow.com/users/29407",
"pm_score": 3,
"selected": true,
"text": "<class name=\"UserVO\" table=\"tb_users\">\n <id name=\"id\" column=\"id\">\n <generator class=\"native\" ... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399459",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17510/"
] |
399,482 | <p>I want to self-draw the caption bar of my application's window, so I decided to override OnNcPaint() methods. But I don't know how to set a different height of the caption bar. Everytime I use GetSystemMetrics(SM_CYCAPTION), it retruns the same value.</p>
<p>Can anyone tell me how to do it? Thank you!</p>
| [
{
"answer_id": 399679,
"author": "Rob Kennedy",
"author_id": 33732,
"author_profile": "https://Stackoverflow.com/users/33732",
"pm_score": 2,
"selected": false,
"text": "wm_NCHitTest htCaption GetSystemMetrics"
}
] | 2008/12/30 | [
"https://Stackoverflow.com/questions/399482",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26404/"
] |
399,486 | <p>When a user clicks on an image on a web page, I'd like to trigger the browser's Save Image dialog and to let the user save the image on their hard drive. Is there a cross-browser way to do this with jQuery/Javascript?</p>
| [
{
"answer_id": 25787294,
"author": "mheg",
"author_id": 3752742,
"author_profile": "https://Stackoverflow.com/users/3752742",
"pm_score": 1,
"selected": false,
"text": "$('.yourImageClass').click(function(){\n $('.hiddenInputClass').trigger('click');\n})\n"
}
] | 2008/12/30 | [
"https://Stackoverflow.com/questions/399486",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1050/"
] |
399,488 | <p>Below is a macro to save multiple sheets to different csv files BUT it keeps renaming and saving the original workbook, how to stop this.</p>
<pre><code>Private Sub CommandButton1_Click()
Dim WS As Excel.Worksheet
Dim SaveToDirectory As String
Dim CurrentWorkbook As String
Dim CurrentFormat As Long
Dim myName As String
myName = myName & Application.Cells(2, 2) 'cell B2 '
CurrentWorkbook = ThisWorkbook.FullName
CurrentFormat = ThisWorkbook.FileFormat
' Store current details for the workbook '
SaveToDirectory = "C:\temp\"
</code></pre>
<p>' This line to correct problem with slash in Stackoverflow code formatting </p>
<pre><code>For Each WS In ThisWorkbook.Worksheets
WS.SaveAs SaveToDirectory & myName & WS.Name, xlCSV
Next
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=CurrentWorkbook, FileFormat:=CurrentFormat
Application.DisplayAlerts = False
' Temporarily turn alerts off to prevent the user being prompted '
' about overwriting the original file. '
End Sub
</code></pre>
| [
{
"answer_id": 399540,
"author": "shahkalpesh",
"author_id": 23574,
"author_profile": "https://Stackoverflow.com/users/23574",
"pm_score": 2,
"selected": false,
"text": "\nActiveWorkbook.SaveAs Filename:=CurrentWorkbook, FileFormat:=CurrentFormat Application.DisplayAlerts = False\n"
},... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399488",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
399,490 | <p>I have some rails models which don't need any persistence, however I'd like rails to think the model actually has attributes x, y, z so when calling methods like to_json in the controller I get them included for free.</p>
<p>For example,</p>
<pre><code>class ModelWithoutTableColumns << ActiveRecord::Base
def x
return "Custom stuff here"
end
</code></pre>
<p>There is no column x in the database for Table "ModelWithoutTable" (sorry for the slightly confusing name!)</p>
<p>Anyone have an idea how to tackle this one?</p>
| [
{
"answer_id": 8042227,
"author": "Adam Tanner",
"author_id": 489215,
"author_profile": "https://Stackoverflow.com/users/489215",
"pm_score": 3,
"selected": true,
"text": "to_json"
}
] | 2008/12/30 | [
"https://Stackoverflow.com/questions/399490",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/46758/"
] |
399,498 | <p>For some reasons, SSIS is not avalialble.</p>
<p>I read about OPENROWSET, but I will have others problem from on the format file and path of file.</p>
<p>How can I do it in a elegant way?</p>
| [
{
"answer_id": 8042227,
"author": "Adam Tanner",
"author_id": 489215,
"author_profile": "https://Stackoverflow.com/users/489215",
"pm_score": 3,
"selected": true,
"text": "to_json"
}
] | 2008/12/30 | [
"https://Stackoverflow.com/questions/399498",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40214/"
] |
399,527 | <p>With the Cocoa framework how can I parse @"2008-12-29T00:27:42-08:00" into an NSDate object? The standard <code>-dateWithString:</code> doesn't like it.</p>
| [
{
"answer_id": 399896,
"author": "mfazekas",
"author_id": 27048,
"author_profile": "https://Stackoverflow.com/users/27048",
"pm_score": 6,
"selected": true,
"text": " NSDateFormatter* dateFormatter = [[[NSDateFormatter alloc] init] autorelease];\n [dateFormatter setDateFormat:@\"yy... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399527",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36170/"
] |
399,530 | <p>I'm new to iPhone development, and multiple views (xib or nib) are really confusing me. This is what i'm trying to achieve...</p>
<ol>
<li>View with Tab Bar (Tab 1, Tab 2, Tab 3)</li>
<li>Tab 2 View (Navigation Controller)
2.1 Selecting Table Row will show a View with cell details
2.2 Add button on the navigation bar will show a series of view interfaces to get different type of information (e.g. Location Information, Personal Information, etc) - Need this to be sequential, can't use control segment for this. Once information is successfully gathered, create a new cell in Tab 2 View Table, Save related information to a custom structure, and show a completion page with 2 options (Add another, View added item - readonly view)</li>
</ol>
<p>I'm confused about how to handle these multiple views (both linking them together, and communicating information back and forth). Will all these be handled by my application delegate class or i can/should use multiple delegate classes? Either way can you point me in the right direction - possibly some sample application or tutorial explaining how to handle situation like this or more complex.</p>
<p>Any help in this regard will be highly appreciated.</p>
<hr>
<p>I have seen both TheElements and SeismicXML examples. </p>
<p>TheElements sample code gives a basic idea of how to use <code>UITabBarController</code>, and <code>UINavigationController</code>, but the example does not discuss passing information from Child Controller to Parent. </p>
<p>In my case, I have a <code>UITabBarController</code>, one of the Tab shows a <code>UINavigationController</code> with (+) on the top right corner or Navigation Bar. Now (+) will open an interface for user input and that input will be used to store the data (say in sql), and create a new Table Cell in <code>UITableView</code> embedded in <code>UINavigationController</code>. Now, the interface that will open using (+) will take user input following a sequence of steps (like Main > Step 1 > Step 2> Complete). Each step will show a separate view. I'm getting hard time trying to design this model. Or, maybe I'm not used to programming in Cocoa/iPhone and I'm not looking straight. What other options do I have - when it comes to taking user input involving 20-30 fields (Text, List, Date, Image e.t.c.). Can you provide some input regarding this.</p>
<p>Thanks for your help.</p>
| [
{
"answer_id": 399896,
"author": "mfazekas",
"author_id": 27048,
"author_profile": "https://Stackoverflow.com/users/27048",
"pm_score": 6,
"selected": true,
"text": " NSDateFormatter* dateFormatter = [[[NSDateFormatter alloc] init] autorelease];\n [dateFormatter setDateFormat:@\"yy... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399530",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/49739/"
] |
399,532 | <p>How can I grab something like ^MM (CTRL + M + M) in .NET, using C#?</p>
| [
{
"answer_id": 399573,
"author": "Mitch Wheat",
"author_id": 16076,
"author_profile": "https://Stackoverflow.com/users/16076",
"pm_score": 1,
"selected": false,
"text": " private static bool lastKeyWasControlM = false;\n\n protected override bool ProcessCmdKey(ref Message msg, Keys... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399532",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/50069/"
] |
399,538 | <p>I'm building a C++ application and need to use PDCurses on Windows. I'm compiling with VC++ from MS VS 2005 and I'm getting a link error.</p>
<blockquote>
<pre><code> error LNK2019: unresolved external
symbol __imp__GetKeyState@4 referenced
in function __get_key_count
</code></pre>
</blockquote>
<p>There are 11 errors all with the same error code and different symbols. The missing symbols are __imp__MapVirtualKeyA@8, __imp__FindWindowA@8, __imp__wsprintfA, __imp__SendMessageA@16, __imp__GetWindowThreadProcessId@8, __imp__MessageBeep@4. It is almost like the VC++ can't find the appropriate ASCII implementations of these functions. I should also note that the demo programs that come with PDCurses compiled fine, though they are C programs.</p>
<p>In the C++ program, I include the header using </p>
<pre><code>extern "C"
{
#include <curses.h>
}
</code></pre>
<p>I'm sure I'm forgetting to link against some C standard library, but I'm not sure which one.</p>
| [
{
"answer_id": 401899,
"author": "oz10",
"author_id": 14069,
"author_profile": "https://Stackoverflow.com/users/14069",
"pm_score": 0,
"selected": false,
"text": "USER32_LIB USER32_LIb USER32_LIB"
}
] | 2008/12/30 | [
"https://Stackoverflow.com/questions/399538",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14069/"
] |
399,546 | <p>What is a synthetic class in Java? Why should it be used? How can I use it?</p>
| [
{
"answer_id": 1260517,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 4,
"selected": false,
"text": "class MyOuter {\n\n private MyInner inner;\n\n void createInner() {\n // The Compiler has to create a synthetic method\n... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399546",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20301/"
] |
399,559 | <p>I can see in the postgresql logs that certain simple queries (no joins and using only match conditions that use indexes) take anywhere from 1 to 3 seconds to execute. I log queries that take longer than a second to execute thus there are similar queries which execute under a second which don't get reported.</p>
<p>When I try the same query using EXPLAIN ANALYZE, it takes a few milliseconds.</p>
<p>The table contains around 8 million records and is written to and queried extensively.
I have enabled auto vacuum and even recently (few hours ago) ran a VACUUM ANALYZE on that table.</p>
<p>Sample query log entry:
Dec 30 10:14:57 db01 postgres[7400]: [20-1] LOG: duration: 3857.322 ms statement: SELECT * FROM "responses" WHERE ("responses".contest_id = 17469) AND (user_id is not
Dec 30 10:14:57 db01 postgres[7400]: [20-2] null) ORDER BY updated_on desc LIMIT 5</p>
<p>contest_id and user_id is indexed. updated_on is not indexed. If I index it, the query planner ignores the contest_id index ans uses updated_on instead which further slows down the query. The maximum entries on the above query without the LIMIT would not be more than 1000.</p>
<p>Any help would be much appreciated.</p>
| [
{
"answer_id": 1374459,
"author": "Jeff Davis",
"author_id": 153464,
"author_profile": "https://Stackoverflow.com/users/153464",
"pm_score": 0,
"selected": false,
"text": "(responses.contest_id = 17469) AND (user_id is not null) work_mem updated_on auto_explain EXPLAIN ANALYZE"
}
] | 2008/12/30 | [
"https://Stackoverflow.com/questions/399559",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/38877/"
] |
399,567 | <p>I seem to have a problem with this SQL query:</p>
<pre><code>SELECT * FROM appts
WHERE timeStart >='$timeStart'
AND timeEnd <='$timeEnd'
AND dayappt='$boatdate'
</code></pre>
<p>The time is formatted as military time. The logistics is that a boat rental can be reserved at 7am til 1pm or 9am til 1pm or 9am til 5pm. If there is an appt within that range, it should return appts but it has proven to be inconsistent. If I pick 9am til 1pm, it will ignore appts that started with 7am even though it overlaps 9am-1pm. If I pick 9 to 5, it will return nothing even though it should with the 7am to 1pm. How do I make a SQL statement that includes the whole range from timeStart to timeEnd including those that overlap? </p>
| [
{
"answer_id": 399577,
"author": "Shane Delmore",
"author_id": 50031,
"author_profile": "https://Stackoverflow.com/users/50031",
"pm_score": 4,
"selected": true,
"text": "SELECT * FROM appts \nWHERE timeStart <='$timeEnd' \nAND timeEnd >='$timeStart' \nAND dayappt='$boatdate'\n"
},
{... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399567",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/47301/"
] |
399,572 | <p>The HtmlObject provides all the necessary functionality to register managed event handlers for script and DOM events, but what if the class you need to listen to doesn't exist as a DOM element, but a scripting variable (referenced via ScriptObject) instead? </p>
| [
{
"answer_id": 399577,
"author": "Shane Delmore",
"author_id": 50031,
"author_profile": "https://Stackoverflow.com/users/50031",
"pm_score": 4,
"selected": true,
"text": "SELECT * FROM appts \nWHERE timeStart <='$timeEnd' \nAND timeEnd >='$timeStart' \nAND dayappt='$boatdate'\n"
},
{... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399572",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5988/"
] |
399,582 | <p>I have a Grails application with a JSP page (I'm porting a legacy JSP application). For some reason, the page renders completely blank. Looking at the HTTP headers I see it's 200 with a content length of 0.</p>
<pre><code>HTTP/1.1 200 OK
Content-Language: en-US
Content-Type: text/html; charset=iso-8859-1
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Set-Cookie: JSESSIONID=1sh9r73vqvukj;Path=/myGrailsApp
Content-Length: 0
Server: Jetty(6.1.12)
</code></pre>
<p>The page is a combination of HTML, tags (<code>${property}</code>), JSP includes (<code><jsp:include></code>), and short code snippets (<code><% code %></code>, yes I know this is a bad idea). There is nothing in the log file or console that indicates an error. Is Grails somehow silently hiding an exception or error?</p>
<p>Edit: The problem is related to the JSP <code><jsp:include/></code> include tag. If I remove all JSP includes then Grails will render. Is Grails compatible with JSP? Since JSP functionality is provided by the web application (Jetty, Tomcat) I would think yes.</p>
<p>Edit: This occurs with Grails 1.0.4 and 1.1 beta 2 (1.1 claims to have added JSP support)</p>
| [
{
"answer_id": 399577,
"author": "Shane Delmore",
"author_id": 50031,
"author_profile": "https://Stackoverflow.com/users/50031",
"pm_score": 4,
"selected": true,
"text": "SELECT * FROM appts \nWHERE timeStart <='$timeEnd' \nAND timeEnd >='$timeStart' \nAND dayappt='$boatdate'\n"
},
{... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399582",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24396/"
] |
399,595 | <p>I may be missing something here because I thought this might be really easy but...</p>
<p>Using Flex, how can you tell when a ComboBox is open? I do find the open and close events that this component dispatches can be flaky so I'm looking for something a little more solid - it's probably staring me in the face.</p>
| [
{
"answer_id": 400514,
"author": "Niko Nyman",
"author_id": 36817,
"author_profile": "https://Stackoverflow.com/users/36817",
"pm_score": 3,
"selected": true,
"text": "dropDown if (myComboBox.dropDown != null && myComboBox.dropDown.visible) {\n // myComboBox is open\n}\n myComboBox.dr... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399595",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3435/"
] |
399,606 | <p>I wonder if anyone here has any experience with mercurial running on Ubuntu? I've been playing with it all morning and love everything I've seen so far.</p>
<p>The one problem I though is when I do a merge and conflicts are detected, it doesn't automatically bring the file up in the command line editor to allow me to resolve the conflicts. It just tells me there's a conflict, then it's up to me to open the editor and resolve it.</p>
<p>But this is strange as the docs show that the editor is automatically launched when there is a merge conflict. I know it's not a problem with the editor (nano) in general as it's works when I do a commit and have to add a comment.</p>
<p>Any ideas?</p>
<p>Chris</p>
<p>p.s I already tried the mercurial IRC channel, but silence....</p>
| [
{
"answer_id": 399644,
"author": "too much php",
"author_id": 28835,
"author_profile": "https://Stackoverflow.com/users/28835",
"pm_score": 3,
"selected": true,
"text": "[ui]\nmerge = vimdiff\n"
}
] | 2008/12/30 | [
"https://Stackoverflow.com/questions/399606",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/37196/"
] |
399,616 | <p>For a scripting utility I need to be able to record a series of keyboard and mouse events that occur when an application has focus. The second part is being able to later send those events to the active window.</p>
<p>I do not need to worry about menus or tracking the identifier of which window receives input.</p>
<p>I know how to do this under Windows but have no idea about Mac OS X.</p>
| [
{
"answer_id": 399640,
"author": "Ben",
"author_id": 36522,
"author_profile": "https://Stackoverflow.com/users/36522",
"pm_score": 3,
"selected": false,
"text": "#include <ApplicationServices/ApplicationServices.h>\n\nint to(int x, int y)\n{\n CGPoint newloc;\n CGEventRef eventRef;... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399616",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1043/"
] |
399,618 | <p>I'm working with a couple of AI algorithms at school and I find people use the words Fuzzy Logic to explain any situation that they can solve with a couple of cases. When I go back to the books I just read about how instead of a state going from On to Off it's a diagonal line and something can be in both states but in different "levels". </p>
<p>I've read the wikipedia entry and a couple of tutorials and even programmed stuff that "uses fuzzy logic" (an edge detector and a 1-wheel self-controlled robot) and still I find it very confusing going from Theory to Code... for you, in the less complicated definition, what is fuzzy logic?</p>
| [
{
"answer_id": 399680,
"author": "Alan",
"author_id": 17205,
"author_profile": "https://Stackoverflow.com/users/17205",
"pm_score": 3,
"selected": false,
"text": " (basis clause) For all A, v(A) in {0,1}\n (iterative) For the following connectives,\n v(!A) = 1 - v(A)\n v(A & B) = min... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399618",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/47846/"
] |
399,633 | <p>.NET has the <a href="http://msdn.microsoft.com/en-us/library/system.uri_members.aspx" rel="nofollow noreferrer">Uri class</a>.</p>
<p>Perl has its <a href="http://search.cpan.org/dist/URI" rel="nofollow noreferrer">URI module</a>.</p>
<p>The major difference is that URI.pm allows you to <strong>retrieve the query string components as a hash</strong>, and <strong>set a hash into the URI to construct a nice URI with query arguments</strong>. I don't see anything like that on the .NET side. Is there some hidden class I don't know about? </p>
| [
{
"answer_id": 399688,
"author": "gimel",
"author_id": 6491,
"author_profile": "https://Stackoverflow.com/users/6491",
"pm_score": 2,
"selected": false,
"text": "String querystring;\n...\n// Parse the query string variables into a NameValueCollection.\nNameValueCollection qscoll = HttpUt... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399633",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11284/"
] |
399,648 | <p>If I am assigning an event handler at runtime and it is in a spot that can be called multiple times, what is the recommended practice to prevent multiple assignments of the same handler to the same event.</p>
<pre><code>object.Event += MyFunction
</code></pre>
<p>Adding this in a spot that will be called more than once will execute the handler 'n' times (of course).</p>
<p>I have resorted to removing any previous handler before trying to add via </p>
<pre><code>object.Event -= MyFunction;
object.Event += MyFunction;
</code></pre>
<p>This works but seems off somehow. Any suggestions on proper handling ;) of this scenario.</p>
| [
{
"answer_id": 399772,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 6,
"selected": true,
"text": "private EventHandler foo;\n\npublic event EventHandler Foo\n{\n add\n {\n // First try to remove the handler... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399648",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
399,669 | <p>I'm using Subversion 1.4.6, and I cannot upgrade to version 1.5 right now.</p>
<p>The situation:</p>
<ol>
<li><p>The trunk has a lot of structural changes (i.e. moving files around, mostly).</p></li>
<li><p>I have a branch that was recently merged from the trunk, but before the major changes.</p></li>
</ol>
<p>What is the best way to merge the trunk to the branch?</p>
<p>What I had in mind:</p>
<ol>
<li><p>First carefully merge the branch to the trunk, by merging only the modified files in the branch to the trunk.</p></li>
<li><p>Copy the trunk to the branch. What is the best way to do this without losing the branch history? Should I deprecate the branch and create a new one?</p></li>
</ol>
<hr/>
<p>Okay, it looks like I didn't given SVN enough credit. It's smart enough after all. I was just put off by the output of "D" and "A", but in the background it did a move.</p>
| [
{
"answer_id": 399701,
"author": "Stefan",
"author_id": 48003,
"author_profile": "https://Stackoverflow.com/users/48003",
"pm_score": 7,
"selected": true,
"text": "svn merge -rLastRevisionMergedFromTrunkToBranch:HEAD url/of/trunk path/to/branch/wc\n"
},
{
"answer_id": 2170776,
... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399669",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11515/"
] |
399,674 | <p>How can I read Authorization header information from a REST based WCF service?</p>
| [
{
"answer_id": 399755,
"author": "Ray Lu",
"author_id": 11413,
"author_profile": "https://Stackoverflow.com/users/11413",
"pm_score": 3,
"selected": false,
"text": "OperationContext.Current.OutgoingMessageProperties\nor\nOperationContext.Current.IncomingMessageProperties\n"
},
{
... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399674",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27052/"
] |
399,689 | <p>How can I give the user the ability to change the style of a webpage, of course I have to make several CSS files , but how can I make the code that permits the change upon the user's choice</p>
| [
{
"answer_id": 399764,
"author": "Ali",
"author_id": 49153,
"author_profile": "https://Stackoverflow.com/users/49153",
"pm_score": 0,
"selected": false,
"text": "document.getElementById(\"header\").style.background-color=\"#ABCDEF\";\n SELECT css_id,css_class,css_code FROM css_styles WHE... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399689",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/49809/"
] |
399,702 | <p>So it looks like Grails' GSP does not have an include tag (correct me if I'm wrong). The closest thing to "include" is to use the <a href="http://docs.codehaus.org/display/GRAILS/Tag+-+render" rel="nofollow noreferrer">render tag</a>. There is also the <a href="http://grails.org/Include+Plugin" rel="nofollow noreferrer">include plugin</a>.</p>
<p>In my case, I have a classic top-left-middle-right-bottom paned page. The top header or left side would include navigation. The middle would be the content. The right side might include ads. In the JSP version of my app, each pane except for the middle would be in their own JSP. I'd then include (using <code><jsp:include/></code>) the various panels into my page. Is this the right approach in GSP?</p>
<p>What is the preferred pattern of accomplishing this in GSP?</p>
| [
{
"answer_id": 400837,
"author": "Rob Hruska",
"author_id": 29995,
"author_profile": "https://Stackoverflow.com/users/29995",
"pm_score": 2,
"selected": false,
"text": "grails-app/views/layouts/main.gsp <g:layoutBody/> main.gsp grails-app/views/layouts main-ads.gsp <head></head> <meta na... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399702",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24396/"
] |
399,704 | <p>Can you suggest some of the best XML Parser for C ?</p>
| [
{
"answer_id": 407642,
"author": "bortzmeyer",
"author_id": 15625,
"author_profile": "https://Stackoverflow.com/users/15625",
"pm_score": 6,
"selected": false,
"text": "/* \n A simple test program to parse XML documents with expat\n <http://expat.sourceforge.net/>. It just displays t... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399704",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21011/"
] |
399,713 | <p>I have a listbox with the ItemsPanelTemplate set to UniformGrid with rows= 6 and cols= 7.</p>
<p>I want the listbox items to fill their space.</p>
<p>I am using a datatemplete defined in a dictionary.</p>
<p>The outer control of my template is a Border with HorizontalAlignment=Stretch
and VerticalAlignent=Strectch but the templates do not fill the listbox items space?</p>
<p>Any ideas?
Malcolm</p>
| [
{
"answer_id": 399762,
"author": "Dennis",
"author_id": 73025,
"author_profile": "https://Stackoverflow.com/users/73025",
"pm_score": 2,
"selected": false,
"text": "ListBoxItems Grid DataTemplate <ItemsControl Grid.IsSharedSizeScope=\"True\" ItemsSource=\"{Binding Path=Items}\">\n <Item... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399713",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40568/"
] |
399,734 | <p>I have a script that calls an application that requires user input, e.g. run app that requires user to type in 'Y' or 'N'.<br>
How can I get the shell script not to ask the user for the input but rather use the value from a predefined variable in the script?</p>
<p>In my case there will be two questions that require input.</p>
| [
{
"answer_id": 399736,
"author": "Marc Novakowski",
"author_id": 27020,
"author_profile": "https://Stackoverflow.com/users/27020",
"pm_score": 5,
"selected": true,
"text": "echo \"Y\" | myapp\n echo $ANSWER | myapp\n"
},
{
"answer_id": 399749,
"author": "jon skulski",
"au... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399734",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
399,754 | <p>I want to create a table in a Microsoft Office Word file using Java. Can anybody tell me how to do it with an example?</p>
| [
{
"answer_id": 11899716,
"author": "lakshmi",
"author_id": 1589972,
"author_profile": "https://Stackoverflow.com/users/1589972",
"pm_score": 1,
"selected": false,
"text": "WPFDocument document = new XWPFDocument();\nXWPFTable tableTwo = document.createTable();\nXWPFTableRow tableTwoRowOn... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399754",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
399,768 | <p>Is there any way to make Visual Studio show the code of a control / form by default instead of the designer? I tend not to be a fan of the designers as they add bloat.</p>
| [
{
"answer_id": 21339799,
"author": "Aaron Palmer",
"author_id": 24908,
"author_profile": "https://Stackoverflow.com/users/24908",
"pm_score": 3,
"selected": false,
"text": "Tools | Options HTML Designer Enable HTML designer Start pages in: Source View"
},
{
"answer_id": 21791378,... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399768",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26566/"
] |
399,791 | <p>I recently installed my video script to a new server but I am seeing that it will start to convert 1 video (via mencoder) then before finishing it, it will try and convery another, and another, so it will be trying to convert 4+ videos at the same time causing the server to shut down. The script developer said:</p>
<p>"It converts each video in a PHP background process. There might be a way to limit the number of PHP background processes on your server and queue them."</p>
<p>So how is this done please?</p>
<p>Regards</p>
| [
{
"answer_id": 399816,
"author": "M.N",
"author_id": 18615,
"author_profile": "https://Stackoverflow.com/users/18615",
"pm_score": 1,
"selected": false,
"text": "Begin\n init sem=MAX;\n\n wait(sem) //sem--, waits if sem=0, till atleast one process comes out of the critical section\... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399791",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
399,792 | <p>It seems that </p>
<pre><code>if (x=y) { .... }
</code></pre>
<p>instead of</p>
<pre><code>if (x==y) { ... }
</code></pre>
<p>is a root of many evils.</p>
<p>Why don't <em>all</em> compilers <em>mark it as error</em> instead of a configurable warning?</p>
<p>I'm interested in finding out cases where the construct <code>if (x=y)</code> is useful.</p>
| [
{
"answer_id": 399800,
"author": "lImbus",
"author_id": 32490,
"author_profile": "https://Stackoverflow.com/users/32490",
"pm_score": 5,
"selected": false,
"text": "char *pBuffer;\nif (pBuffer = malloc(100))\n{\n // Continue to work here\n}\n new while (pointer = getNextElement(contex... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399792",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18275/"
] |
399,798 | <pre><code> string str1 = "12345ABC...\\...ABC100000";
// Hypothetically huge string of 100000 + Unicode Chars
str1 = str1.Replace("1", string.Empty);
str1 = str1.Replace("22", string.Empty);
str1 = str1.Replace("656", string.Empty);
str1 = str1.Replace("77ABC", string.Empty);
// ... this replace anti-pattern might happen with upto 50 consecutive lines of code.
str1 = str1.Replace("ABCDEFGHIJD", string.Empty);
</code></pre>
<p>I have inherited some code that does the same as the snippet above. It takes a huge string and replaces (removes) constant smaller strings from the large string.</p>
<p>I believe this is a very memory intensive process given that new large immutable strings are being allocated in memory for each replace, awaiting death via the GC.</p>
<p><strong>1. What is the fastest way of replacing these values, ignoring memory concerns?</strong></p>
<p><strong>2. What is the most memory efficient way of achieving the same result?</strong></p>
<p>I am hoping that these are the same answer!</p>
<p>Practical solutions that fit somewhere in between these goals are also appreciated.</p>
<p>Assumptions: </p>
<ul>
<li>All replacements are constant and known in advance</li>
<li>Underlying characters do contain some unicode [non-ascii] chars</li>
</ul>
| [
{
"answer_id": 399811,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 6,
"selected": true,
"text": "Regex.Replace StringBuilder.Replace using System;\nusing System.Text;\nusing System.Text.RegularExpressions;\n\nclass Tes... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399798",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/46100/"
] |
399,822 | <p>I am trying to use NVelocity templates in a .Net application: using a template to output results to a file. It all seems to work fine except for the fact that the output is never fully overwritten. If my file is 100 characters long and the template only renders 20 characters, the last 80 characters are never altered!</p>
<p>Code sample: </p>
<pre><code> FileStream fileStream = new FileStream(outputPath, FileMode.OpenOrCreate, FileAccess.Write);
using (StreamWriter streamWriter = new StreamWriter(fileStream))
{
velocityEngine.MergeTemplate(templateName, Encoding.Default.WebName, velocityContext, streamWriter);
}
</code></pre>
<p>So if my template outputs AAAA and the file already contains BBBBBBBB then at the end, the file contains AAAABBBB at the end of the op.</p>
<p>Any clue how I can get it to fully overwrite the file? - e.g. in the above example the final output should be AAAA. Not too sure whether this is just pure stream-related stuff - but I haven't had this problem before with filestreams.</p>
<p>Happy to write a reset method, or just output to a memorystream and overwrite the file, but I would like to get it working like this if possible!
**EDIT:'' got it working by calling </p>
<pre><code> fileStream.SetLength(0);
</code></pre>
<p>when I open the file. But would appreciate knowing if there was a better way!</p>
| [
{
"answer_id": 427963,
"author": "Andrew",
"author_id": 5662,
"author_profile": "https://Stackoverflow.com/users/5662",
"pm_score": 2,
"selected": false,
"text": "FileMode.OpenOrCreate FileMode.Create"
}
] | 2008/12/30 | [
"https://Stackoverflow.com/questions/399822",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22360/"
] |
399,826 | <p>I have 3 buttons in a form. One of them is the submit button. How can I make it the default button to be clicked when I press the enter key. Is there a property for this?</p>
| [
{
"answer_id": 399839,
"author": "Biri",
"author_id": 968,
"author_profile": "https://Stackoverflow.com/users/968",
"pm_score": 4,
"selected": true,
"text": "<form runat=\"server\" defaultbutton=\"myButton\">\n...\n</form>\n"
},
{
"answer_id": 399892,
"author": "Kb.",
"au... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399826",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1688440/"
] |
399,835 | <p>I got a problem when I put 2 instances of FckEditor to a page in dotnetnuke.
sometimes, I got empty text when I call the text property.</p>
<p>Anyone helps?</p>
| [
{
"answer_id": 400797,
"author": "bdukes",
"author_id": 2688,
"author_profile": "https://Stackoverflow.com/users/2688",
"pm_score": 1,
"selected": false,
"text": "Text"
}
] | 2008/12/30 | [
"https://Stackoverflow.com/questions/399835",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
399,850 | <p>What compiler warning level do you recommend for different C/C++ compilers?</p>
<p>gcc and g++ will let you get away with a lot on the default level. I find the best warning level for me is '-Wall'. And I always try to remove fix the code for the warnings it generates. (Even the silly ones about using parenthesis for logical precedence rules or to say I really mean 'if (x = y)')</p>
<p>What are your favorite levels for the different compilers, such as Sun CC, aCC (HPUX ?), Visual Studio, intel?</p>
<p>Edit:</p>
<p>I just wanted to point out that I don't use "-Werror" (but I do understand it's utility) on gcc/g++ because, I use:</p>
<pre>
#warning "this is a note to myself"
</pre>
<p>in a few places in my code. Do all the compilers understand the #warning macro?</p>
| [
{
"answer_id": 399855,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 3,
"selected": false,
"text": "-Wall -Werror"
},
{
"answer_id": 399865,
"author": "Paulius",
"author_id": 1353085,
"au... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399850",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
399,866 | <p>I'm trying to port an application to Mono, however Mono doesn't support "Application Settings". I don't and won't use Mono Develop, the development is done with Visual Studio.</p>
<p>Is there any quick way to solve this? Or should I implement my own settings replacement class?</p>
<p>If it matters this is a VB.NET application.</p>
| [
{
"answer_id": 400564,
"author": "dr. evil",
"author_id": 40322,
"author_profile": "https://Stackoverflow.com/users/40322",
"pm_score": 0,
"selected": false,
"text": "Dim Threshold As Integer = My.Settings.Threshold\n My.Settings.Threshold = 15\n"
}
] | 2008/12/30 | [
"https://Stackoverflow.com/questions/399866",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40322/"
] |
399,867 | <p>I'm looking for some input on how to implement custom eventhandling in jquery the best way. I know how to hook up events from the dom elements like 'click' etc, but I'm building a tiny javascript library/plugin to handle some preview functionality.</p>
<p>I've got a script running to update some text in a dom element from a set of rules and data/user input I got, but now I need that same text shown in other elements that this script can't possibly know of. What I need is a good pattern to somehow observe this script producing the needed text.</p>
<p>So how do I do this? Did I overlook some builtin functionality in jquery to raise/handle user events or do I need some jquery plugin to do it? What do you think is the best way/plugin to handle this?</p>
| [
{
"answer_id": 399877,
"author": "Tuxified",
"author_id": 49792,
"author_profile": "https://Stackoverflow.com/users/49792",
"pm_score": 4,
"selected": false,
"text": " $(\"p\").bind(\"myCustomEvent\", function(e, myName, myValue){\n $(this).text(myName + \", hi there!\");\n $(\... | 2008/12/30 | [
"https://Stackoverflow.com/questions/399867",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11619/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.