qid int64 4 19.1M | question stringlengths 18 48.3k | answers list | date stringlengths 10 10 | metadata list |
|---|---|---|---|---|
409,217 | <p>First, let me say that I'm a complete beginner at Python. I've never learned the language, I just thought "how hard can it be" when Google turned up nothing but Python snippets to solve my problem. :)</p>
<p>I have a bunch of mailboxes in Maildir format (a backup from the mail server on my old web host), and I need to extract the emails from these.
So far, the simplest way I've found has been to convert them to the mbox format, which Thunderbird supports, and it seems Python has a few classes for reading/writing both formats. Seems perfect.</p>
<p>The Python docs even have this little code snippet doing exactly what I need:</p>
<pre><code>src = mailbox.Maildir('maildir', factory=None)
dest = mailbox.mbox('/tmp/mbox')
for msg in src: #1
dest.add(msg) #2
</code></pre>
<p><em>Except</em> it doesn't work. And here's where my complete lack of knowledge about Python sets in.
On a few messages, I get a UnicodeDecodeError during the iteration (that is, when it's trying to read <code>msg</code> from <code>src</code>, on line <code>#1</code>). On others, I get a UnicodeEncodeError when trying to add <code>msg</code> to <code>dest</code> (line <code>#2</code>).</p>
<p>Clearly it makes some wrong assumptions about the encoding used. But I have no clue how to specify an encoding on the mailbox (For that matter, I don't know what the encoding should be either, but I can probably figure that out once I find a way to actually specify an encoding). </p>
<p>I get stack traces similar to the following:</p>
<pre><code> File "E:\Python30\lib\mailbox.py", line 102, in itervalues
value = self[key]
File "E:\Python30\lib\mailbox.py", line 74, in __getitem__
return self.get_message(key)
File "E:\Python30\lib\mailbox.py", line 317, in get_message
msg = MaildirMessage(f)
File "E:\Python30\lib\mailbox.py", line 1373, in __init__
Message.__init__(self, message)
File "E:\Python30\lib\mailbox.py", line 1345, in __init__
self._become_message(email.message_from_file(message))
File "E:\Python30\lib\email\__init__.py", line 46, in message_from_file
return Parser(*args, **kws).parse(fp)
File "E:\Python30\lib\email\parser.py", line 68, in parse
data = fp.read(8192)
File "E:\Python30\lib\io.py", line 1733, in read
eof = not self._read_chunk()
File "E:\Python30\lib\io.py", line 1562, in _read_chunk
self._set_decoded_chars(self._decoder.decode(input_chunk, eof))
File "E:\Python30\lib\io.py", line 1295, in decode
output = self.decoder.decode(input, final=final)
File "E:\Python30\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 37: character maps to <undefined>
</code></pre>
<p>And on the UnicodeEncodeErrors:</p>
<pre><code> File "E:\Python30\lib\email\message.py", line 121, in __str__
return self.as_string()
File "E:\Python30\lib\email\message.py", line 136, in as_string
g.flatten(self, unixfrom=unixfrom)
File "E:\Python30\lib\email\generator.py", line 76, in flatten
self._write(msg)
File "E:\Python30\lib\email\generator.py", line 108, in _write
self._write_headers(msg)
File "E:\Python30\lib\email\generator.py", line 141, in _write_headers
header_name=h, continuation_ws='\t')
File "E:\Python30\lib\email\header.py", line 189, in __init__
self.append(s, charset, errors)
File "E:\Python30\lib\email\header.py", line 262, in append
input_bytes = s.encode(input_charset, errors)
UnicodeEncodeError: 'ascii' codec can't encode character '\xe5' in position 16:
ordinal not in range(128)
</code></pre>
<p>Anyone able to help me out here? (Suggestions for completely different solutions not involving Python are obviously welcome too. I just need a way to access get import the mails from these Maildir files.</p>
<p><em>Updates:</em></p>
<p>sys.getdefaultencoding returns 'utf-8'</p>
<p>I uploaded sample messages which cause both errors.
<a href="http://jalf.dk/python_problem/1187691008.H199308P14265.c1p.hostingzoom.com_2,S" rel="nofollow noreferrer">This one</a> throws UnicodeEncodeError, and <a href="http://jalf.dk/python_problem/1219438193.H364790P13554.c1p.hostingzoom.com_2,S" rel="nofollow noreferrer">this</a> throws UnicodeDecodeError</p>
<p>I tried running the same script in Python2.6, and got TypeErrors instead:</p>
<pre><code> File "c:\python26\lib\mailbox.py", line 529, in add
self._toc[self._next_key] = self._append_message(message)
File "c:\python26\lib\mailbox.py", line 665, in _append_message
offsets = self._install_message(message)
File "c:\python26\lib\mailbox.py", line 724, in _install_message
self._dump_message(message, self._file, self._mangle_from_)
File "c:\python26\lib\mailbox.py", line 220, in _dump_message
raise TypeError('Invalid message type: %s' % type(message))
TypeError: Invalid message type: <type 'instance'>
</code></pre>
| [
{
"answer_id": 409249,
"author": "Wayne Molina",
"author_id": 40667,
"author_profile": "https://Stackoverflow.com/users/40667",
"pm_score": 0,
"selected": false,
"text": "<% if @user.admin? # is the user an admin %>\n <h3>Admin Tools</h3>\n<% end %>\n<p>Regular site content</p>\n"
},
... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409217",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33213/"
] |
409,226 | <p>is there any difference between:</p>
<pre><code>lock((IDictionary) _collection).SyncRoot)
</code></pre>
<p>or</p>
<pre><code>lock(_collection)
</code></pre>
| [
{
"answer_id": 409242,
"author": "Rauhotz",
"author_id": 48722,
"author_profile": "https://Stackoverflow.com/users/48722",
"pm_score": 0,
"selected": false,
"text": "this SyncRoot"
},
{
"answer_id": 409246,
"author": "R. Martinho Fernandes",
"author_id": 46642,
"autho... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409226",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4653/"
] |
409,236 | <p>I am getting back a "string[]" from a 3rd party library. I want to do a contains on it. what is the most efficient way of doing this?</p>
| [
{
"answer_id": 409238,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 4,
"selected": true,
"text": "bool contains = Array.IndexOf(arr, value) >= 0;\n bool contains = arr.Contains(value);\n"
},
{
"answer_id": 40... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409236",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4653/"
] |
409,256 | <p>I have a byte array that represents a complete TCP/IP packet. For clarification, the byte array is ordered like this:</p>
<p>(IP Header - 20 bytes)(TCP Header - 20 bytes)(Payload - X bytes)</p>
<p>I have a <code>Parse</code> function that accepts a byte array and returns a <code>TCPHeader</code> object. It looks like this:</p>
<pre><code>TCPHeader Parse( byte[] buffer );
</code></pre>
<p>Given the original byte array, here is the way I'm calling this function right now.</p>
<pre><code>byte[] tcpbuffer = new byte[ 20 ];
System.Buffer.BlockCopy( packet, 20, tcpbuffer, 0, 20 );
TCPHeader tcp = Parse( tcpbuffer );
</code></pre>
<p>Is there a convenient way to pass the TCP byte array, i.e., bytes 20-39 of the complete TCP/IP packet, to the <code>Parse</code> function without extracting it to a new byte array first?</p>
<p>In C++, I could do the following:</p>
<pre><code>TCPHeader tcp = Parse( &packet[ 20 ] );
</code></pre>
<p>Is there anything similar in C#? I want to avoid the creation and subsequent garbage collection of the temporary byte array if possible.</p>
| [
{
"answer_id": 409267,
"author": "Greg Beech",
"author_id": 13552,
"author_profile": "https://Stackoverflow.com/users/13552",
"pm_score": 2,
"selected": false,
"text": "IEnumerable<byte> byte[] tcpbuffer.Skip(20).Take(20);\n"
},
{
"answer_id": 409270,
"author": "mmx",
"au... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409256",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/51170/"
] |
409,259 | <p>I'm trying to do that for a couple of days now, and after reading tons of messages of people trying to do that too, I'm still unable to have a fully working <code>UITextField</code> in some of my <code>UITableViewCells</code>, just like in this example: </p>
<p><img src="https://i.stack.imgur.com/gD4cE.png" alt="Screenshot"></p>
<p>Either I have the form working but the text is not visible (although I set its color to blue), the keyboard goes on the field when I click on it and I haven't been able to correctly implement the keyboard events.
I tried with a bunch of examples from Apple (mainly <code>UICatalog</code>, where there is a kinda similar control) but it's still not working correctly.</p>
<p>Can somebody help me (and all the people trying to realize this control) and post a simple implementation of a <code>UITextField</code> in a <code>UITableViewCell</code>, that works fine?</p>
| [
{
"answer_id": 412583,
"author": "lostInTransit",
"author_id": 46297,
"author_profile": "https://Stackoverflow.com/users/46297",
"pm_score": 4,
"selected": false,
"text": "UITextField *txtField = [[UITextField alloc] initWithFrame....]\n...\n[cell.contentView addSubview:txtField]\n"
},... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409259",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/50090/"
] |
409,286 | <p>Would you recommend using a <a href="https://dev.mysql.com/doc/refman/5.0/en/datetime.html" rel="noreferrer">datetime</a> or a <a href="https://dev.mysql.com/doc/refman/5.0/en/datetime.html" rel="noreferrer">timestamp</a> field, and why (using MySQL)? </p>
<p>I'm working with PHP on the server side.</p>
| [
{
"answer_id": 409292,
"author": "Mark Davidson",
"author_id": 50866,
"author_profile": "https://Stackoverflow.com/users/50866",
"pm_score": 5,
"selected": false,
"text": "time(); SELECT UNIX_TIMESTAMP();"
},
{
"answer_id": 409295,
"author": "Jeff Warnica",
"author_id": 3... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409286",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25152/"
] |
409,293 | <p><strong>Exact Duplicate of:</strong> <a href="https://stackoverflow.com/questions/409069/getting-the-size-free-total-of-a-windows-mobile-phone-drive-using-c-not-solve">Getting the size (free,total) of a Windows Mobile phone drive using c#</a>
<hr>
dear all;</p>
<p>i know my problem took alot of time and many of u helped me but i'm new in C# and this is my first application..</p>
<p>now i read an article:</p>
<p>C# Signature:</p>
<pre><code> [DllImport("coredll.dll", SetLastError=true, CharSet=CharSet.Auto)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetDiskFreeSpaceEx(string lpDirectoryName,
out ulong lpFreeBytesAvailable,
out ulong lpTotalNumberOfBytes,
out ulong lpTotalNumberOfFreeBytes);
</code></pre>
<p>Sample Code:</p>
<pre><code> ulong FreeBytesAvailable;
ulong TotalNumberOfBytes;
ulong TotalNumberOfFreeBytes;
bool success = GetDiskFreeSpaceEx("C:\\", out FreeBytesAvailable, out
TotalNumberOfBytes,out TotalNumberOfFreeBytes);
if (!success)
throw new System.ComponentModel.Win32Exception();
Console.WriteLine("Free Bytes Available: {0,15:D}", FreeBytesAvailable);
Console.WriteLine("Total Number Of Bytes: {0,15:D}", TotalNumberOfBytes);
Console.WriteLine("Total Number Of FreeBytes: {0,15:D}", TotalNumberOfFreeBytes);
</code></pre>
<p>now how to use this function GetDiskFreeSpaceEx , and should i add C# signature to somewhere ?!? and what about the coredll.dll ?!?</p>
<p>my code is like that :</p>
<pre><code> FolderInfo = (CONADefinitions.CONAPI_FOLDER_INFO)Marshal.PtrToStructure(Buffer,
typeof(CONADefinitions.CONAPI_FOLDER_INFO));
if (FolderInfo.pstrName[0].ToString() != "C" && level == 0)
{
// here i want to get the Total Size of the currentDirectory and freeSize
// i want them in Bytes
}
</code></pre>
<p>i searched on google but i dont have enough exprience to know the right tag</p>
<p>thnx</p>
| [
{
"answer_id": 409322,
"author": "casperOne",
"author_id": 50776,
"author_profile": "https://Stackoverflow.com/users/50776",
"pm_score": 3,
"selected": true,
"text": "FolderInfo = (CONADefinitions.CONAPI_FOLDER_INFO)Marshal.PtrToStructure(Buffer, typeof(CONADefinitions.CONAPI_FOLDER_INFO... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409293",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42782/"
] |
409,300 | <p>The v4 series of the <code>gcc</code> compiler can automatically vectorize loops using the <a href="http://en.wikipedia.org/wiki/SIMD" rel="noreferrer">SIMD</a> processor on some modern CPUs, such as the AMD Athlon or Intel Pentium/Core chips. How is this done?</p>
| [
{
"answer_id": 409302,
"author": "casualcoder",
"author_id": 10578,
"author_profile": "https://Stackoverflow.com/users/10578",
"pm_score": 6,
"selected": true,
"text": "gcc -O2 -ftree-vectorize -msse2 -mfpmath=sse -ftree-vectorizer-verbose=5\n -mfpmath=sse -ftree-vectorize -O3 gcc -O3 ... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409300",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10578/"
] |
409,321 | <p>So I'm trying to build a simple forum. It'll be a list of topics in descending order by the date of either the topic (if no replies) or latest reply. Here's the DB structure:</p>
<p><strong>forum_topic</strong></p>
<blockquote>
<p>id, name, email, body, date</p>
</blockquote>
<p><strong>forum_reply</strong></p>
<blockquote>
<p>id, email, body, date, topic_id</p>
</blockquote>
<p>The forum itself will consist of an HTML table with the following headers:</p>
<blockquote>
<p>Topic, Last Modified, # Replies</p>
</blockquote>
<p>What would the query or queries look like to produce such a structure? I was thinking it would involve a cross join, but not sure... Thanks in advance.</p>
| [
{
"answer_id": 409345,
"author": "Filip Ekberg",
"author_id": 39106,
"author_profile": "https://Stackoverflow.com/users/39106",
"pm_score": 2,
"selected": false,
"text": "select * from forum_topic\ninner join forum_reply on forum_topic.id=topc_id\n select * select ThreadID, Subject, Answ... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409321",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32881/"
] |
409,325 | <p>How do I check if a file is already used by another process from Powerscript ?</p>
| [
{
"answer_id": 411672,
"author": "RealHowTo",
"author_id": 25122,
"author_profile": "https://Stackoverflow.com/users/25122",
"pm_score": 3,
"selected": true,
"text": "FUNCTION Long CreateFile(ref string lpszName, long fdwAccess, long fdwShareMode, long lpsa, &\nlong fdwCreate, long fdwAt... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409325",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25122/"
] |
409,342 | <p>Do you think it may be OK for a person to have more than one role in a software development company that wants to use SCRUM?</p>
<p>E.g. is it ok/possible if a person is</p>
<ul>
<li>SCRUM master and team member</li>
<li>Product owner and team member</li>
<li>SCRUM master and product owner</li>
</ul>
<p>Which combinations do you think are possible? Do you work in such a team? What should be considered if a person has more than one roles?</p>
<p>Thanks for any hints.</p>
| [
{
"answer_id": 14946433,
"author": "Paul Rowland",
"author_id": 6268,
"author_profile": "https://Stackoverflow.com/users/6268",
"pm_score": 0,
"selected": false,
"text": "Scrum master and team member Product owner and team member Scrum master and product owner"
}
] | 2009/01/03 | [
"https://Stackoverflow.com/questions/409342",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19635/"
] |
409,348 | <p>What is the correct way of iterating over a vector in C++?</p>
<p>Consider these two code fragments, this one works fine:</p>
<pre><code>for (unsigned i=0; i < polygon.size(); i++) {
sum += polygon[i];
}
</code></pre>
<p>and this one:</p>
<pre><code>for (int i=0; i < polygon.size(); i++) {
sum += polygon[i];
}
</code></pre>
<p>which generates <code>warning: comparison between signed and unsigned integer expressions</code>.</p>
<p>I'm new in the world of C++, so the <code>unsigned</code> variable looks a bit frightening to me and I know <code>unsigned</code> variables can be dangerous if not used correctly, so - is this correct?</p>
| [
{
"answer_id": 409356,
"author": "Igor",
"author_id": 44673,
"author_profile": "https://Stackoverflow.com/users/44673",
"pm_score": 4,
"selected": false,
"text": "size_t for (size_t i=0; i < polygon.size(); i++)\n size_t size_t size_t size_t size_t"
},
{
"answer_id": 409358,
... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409348",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24545/"
] |
409,351 | <p>Some guy called one of my Snipplr submissions "crap" because I used <code>if ($_SERVER['REQUEST_METHOD'] == 'POST')</code> instead of <code>if ($_POST)</code></p>
<p>Checking the request method seems more correct to me because that's what I really want to do. Is there some operational difference between the two or is this just a code clarity issue?</p>
| [
{
"answer_id": 409365,
"author": "Alex UK",
"author_id": 51174,
"author_profile": "https://Stackoverflow.com/users/51174",
"pm_score": -1,
"selected": false,
"text": "$_POST isset()"
},
{
"answer_id": 409376,
"author": "Eran Galperin",
"author_id": 10585,
"author_prof... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409351",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6126/"
] |
409,354 | <p>Is there a way in Cocoa that is currently considered best practice for creating a multi-tier or client server application?</p>
<p>I'm an experienced web developer and I really love Python. I'm new to Cocoa though. The application I'm toying with writing is a patient management system for a large hospital. The system is expected to store huge amounts of data over time but the data transferred during a single session is very light (mostly just text). The communication is assumed to occur over a local network (wired or wireless). It has to be highly secure, of course.</p>
<p>The best I could come up with is to write a Python REST web service and connect to it through the Cocoa app. Maybe I'll even use Python to code the Cocoa app itself.</p>
<p>Looking at Cocoa, I see really great technologies in Cocoa like CoreData but I couldn't find anything similar for client server development. I just want to make sure that I'm not missing anything.</p>
<p>What do you think?</p>
<p>Real world examples will be greatly appreciated.</p>
<p>Thanks in advance.</p>
| [
{
"answer_id": 409925,
"author": "Barry Wark",
"author_id": 2140,
"author_profile": "https://Stackoverflow.com/users/2140",
"pm_score": 4,
"selected": true,
"text": "py2app"
}
] | 2009/01/03 | [
"https://Stackoverflow.com/questions/409354",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6053/"
] |
409,370 | <p>I have the following data structure (a list of lists)</p>
<pre><code>[
['4', '21', '1', '14', '2008-10-24 15:42:58'],
['3', '22', '4', '2somename', '2008-10-24 15:22:03'],
['5', '21', '3', '19', '2008-10-24 15:45:45'],
['6', '21', '1', '1somename', '2008-10-24 15:45:49'],
['7', '22', '3', '2somename', '2008-10-24 15:45:51']
]
</code></pre>
<p>I would like to be able to</p>
<ol>
<li><p>Use a function to reorder the list so that I can group by each item in the list. For example I'd like to be able to group by the second column (so that all the 21's are together) </p></li>
<li><p>Use a function to only display certain values from each inner list. For example i'd like to reduce this list to only contain the 4th field value of '2somename' </p></li>
</ol>
<p>so the list would look like this </p>
<pre><code>[
['3', '22', '4', '2somename', '2008-10-24 15:22:03'],
['7', '22', '3', '2somename', '2008-10-24 15:45:51']
]
</code></pre>
| [
{
"answer_id": 409394,
"author": "Federico A. Ramponi",
"author_id": 18770,
"author_profile": "https://Stackoverflow.com/users/18770",
"pm_score": 2,
"selected": false,
"text": "l = [\n ['4', '21', '1', '14', '2008-10-24 15:42:58'], \n ['3', '22', '4', '2somename', '2008-10-24 15:22:03']... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409370",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/51181/"
] |
409,372 | <p>I have a page where I would like it to remain static after refresh and does not default back to the top page again as it will disrupt the position I was viewing it last. Hence I have all the time to scroll down again to find the area I was viewing last. Is there a way of eliminating the burden of scrolling down again? </p>
| [
{
"answer_id": 2434861,
"author": "Patrick Foley",
"author_id": 44430,
"author_profile": "https://Stackoverflow.com/users/44430",
"pm_score": 2,
"selected": false,
"text": "<HTML>\n<HEAD>\n<TITLE>Test</TITLE>\n<script>\n function SaveScrollXY() {\n document.Form1.ScrollX.value = docu... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409372",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/44973/"
] |
409,385 | <p>I have a VB6 application that I am converting to .net. I am doing this in phases so clients will have both VB6 and .net applications at the same. Part of the application caches ADO 2.8 COM recordsets to a table in SQL Server and retrieves them as needed. The .net application uses that same persisted recordsets. I have c# code that retrieves the persisted recordset and converts it to a dataset. My question is -- Am I doing it in the most efficient manner?</p>
<p>This is my code that retrieves the recordset from the database --</p>
<pre><code>Stream adoStream = null;
SqlParameter cmdParameter;
SqlCommand cmd = null;
SqlDataReader dr = null;
string cmdText;
int bytesReturned;
int chunkSize = 65536;
int offSet = 0;
UnicodeEncoding readBytes;
try
{
cmdParameter = new SqlParameter(parameterName, idParamter);
cmdText = sqlString;
cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandTimeout = 0;
cmd.CommandText = cmdText;
cmd.Connection = this.pbiSQLConnection;
cmd.Parameters.Add(cmdParameter);
dr = cmd.ExecuteReader(CommandBehavior.SequentialAccess);
dr.Read();
if (dr.HasRows)
{
readBytes = new UnicodeEncoding();
byte[] byteChunk = new byte[chunkSize];
adoStream = new Stream();
adoStream.Type = StreamTypeEnum.adTypeText;
adoStream.Open(Type.Missing, ConnectModeEnum.adModeUnknown,
StreamOpenOptionsEnum.adOpenStreamUnspecified, "", "");
do
{
bytesReturned = (int)dr.GetBytes(0, offSet, byteChunk, 0,
chunkSize);
size += bytesReturned;
if (bytesReturned > 0)
{
if (bytesReturned < chunkSize)
{
Array.Resize(ref byteChunk, bytesReturned);
}
adoStream.WriteText(readBytes.GetString(byteChunk),
StreamWriteEnum.stWriteChar);
adoStream.Flush();
}
offSet += bytesReturned;
} while (bytesReturned == chunkSize);
}
}
catch (Exception exLoadResultsFromDB)
{
throw (exLoadResultsFromDB);
}
finally
{
if (dr != null)
{
if (!dr.IsClosed)
{
dr.Close();
}
dr.Dispose();
}
if (cmd != null)
{
cmd.Dispose();
}
}
</code></pre>
<p>This is the code that converts the ado stream to a datasets --</p>
<pre><code>adoStream = LoadTextFromDBToADODBStream(resultID, "@result_id",
"some sql statement", ref size);
if (adoStream.Size == 0)
{
success = false;
}
else
{
adoStream.Position = 0;
DataTable table = new DataTable();
Recordset rs = new Recordset();
rs.Open(adoStream, Type.Missing, CursorTypeEnum.adOpenStatic,
LockTypeEnum.adLockBatchOptimistic, -1);
if (adoStream != null)
{
adoStream.Close();
adoStream = null;
}
source.SourceRows = rs.RecordCount;
table.TableName = "Source";
source.Dataset = new DataSet();
source.Dataset.Tables.Add(table);
OleDbDataAdapter adapter = new OleDbDataAdapter();
adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
adapter.Fill(source.Dataset.Tables[0], rs);
if (adapter != null)
{
adapter.Dispose();
adapter = null;
}
if (adoStream != null)
{
adoStream.Close();
adoStream = null;
}
if (rs != null)
{
if (rs.State == 1)
{
rs.Close();
}
rs = null;
}
}
</code></pre>
<p>Thanks all</p>
<p>EDIT: I added a bounty to see if anyone can make the code more efficient.</p>
| [
{
"answer_id": 549793,
"author": "casperOne",
"author_id": 50776,
"author_profile": "https://Stackoverflow.com/users/50776",
"pm_score": 3,
"selected": true,
"text": "SqlConnection CreateConnection()\n{\n // Create the connection here and return it.\n return ...;\n}\n struct ComRef... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409385",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8219/"
] |
409,434 | <p>How can I automatically execute an Excel macro each time a value in a particular cell changes?</p>
<p>Right now, my working code is:</p>
<pre><code>Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("H5")) Is Nothing Then Macro
End Sub
</code></pre>
<p>where <code>"H5"</code> is the particular cell being monitored and <code>Macro</code> is the name of the macro.</p>
<p>Is there a better way?</p>
| [
{
"answer_id": 409439,
"author": "Joe",
"author_id": 13087,
"author_profile": "https://Stackoverflow.com/users/13087",
"pm_score": 3,
"selected": false,
"text": "Worksheet_Change Workbook_SheetChange"
},
{
"answer_id": 410876,
"author": "Javier Torón",
"author_id": 50730,... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409434",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34596/"
] |
409,449 | <p>I have a Python function in which I am doing some sanitisation of the input parameters:</p>
<pre><code>def func(param1, param2, param3):
param1 = param1 or ''
param2 = param2 or ''
param3 = param3 or ''
</code></pre>
<p>This caters for the arguments being passed as <em>None</em> rather than empty strings. Is there an easier/more concise way to loop round the function parameters to apply such an expression to all of them. My actual function has nine parameters.</p>
| [
{
"answer_id": 409467,
"author": "llimllib",
"author_id": 42559,
"author_profile": "https://Stackoverflow.com/users/42559",
"pm_score": -1,
"selected": false,
"text": "def func(x='', y='', z='hooray!'):\n print x, y, z\n\nIn [2]: f('test')\ntest hooray!\n\nIn [3]: f('test', 'and')\nt... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409449",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42974/"
] |
409,454 | <p>On C# 3.0 and .NET 3.5, imagine there's an interface:</p>
<pre><code>public interface INameable
{
string Name {get;}
}
</code></pre>
<p>and many immutable classes that implement the interface.</p>
<p>I would like to have a single extension method</p>
<pre><code>public static T Rename<T>(this T obj) where T : INameable
{
...
}
</code></pre>
<p>that returns a wrapped instance of the original object with just the name changed and all other property reads and method calls routed to the original object.</p>
<p>How to get a generic wrapper class for this, without implementing it for all INameable implementing types? Do you think that's possible?</p>
| [
{
"answer_id": 409481,
"author": "Lasse V. Karlsen",
"author_id": 267,
"author_profile": "https://Stackoverflow.com/users/267",
"pm_score": 1,
"selected": false,
"text": "SomeNameableObject a1 = new SomeNameableObject(\"ThisIsTheFirstName\");\nSomeNameableObject a2 = a1.Rename(\"ThisIsTh... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409454",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/48722/"
] |
409,465 | <p>Does anyone know of a way to make Eclipse an SDI application rather than an MDI one?
SDI - Single document interface, each pane is its own window
MDI - Multiple document interface, all of the panes are stuck inside one "master" window.</p>
<p>Eclipse is an MDI application. All of the little panes (like the call stack, variable viewer, etc) are part of the one master Eclipse window. Rather than having all of the windows stuck inside one master "eclipse" window, I'd like them to all be their own free-floating windows.</p>
| [
{
"answer_id": 412534,
"author": "VonC",
"author_id": 6309,
"author_profile": "https://Stackoverflow.com/users/6309",
"pm_score": 3,
"selected": false,
"text": "Window\\Save Perspective As"
}
] | 2009/01/03 | [
"https://Stackoverflow.com/questions/409465",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/51189/"
] |
409,483 | <p>I've been using C++ for about 6 or 7 years now, and I consider myself fluent in it. I've never bothered with Java until now, but I find myself out of the job (company went under) and I need to expand my skill set. Someone recommended Java, so I am wondering if there is any advice for where somebody like me might start. I am also interested to know what the key aspects of Java are that are most likely to come up in an interview.</p>
| [
{
"answer_id": 409489,
"author": "C. K. Young",
"author_id": 13,
"author_profile": "https://Stackoverflow.com/users/13",
"pm_score": 2,
"selected": false,
"text": "EnumSet"
}
] | 2009/01/03 | [
"https://Stackoverflow.com/questions/409483",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/43496/"
] |
409,491 | <p>This question originally asked which is the best method for uploading files via SFTP or FTPS in SSIS. It now just lists the pros and cons of each solution. I personally use CozyRoc's SFTP library these days, but I've used each of the below solutions at one point or another.</p>
<p>SSIS COMPONENT LIBRARY</p>
<p>Method: Install a SSIS component library from <a href="http://www.cozyroc.com/support/ssis_home.html" rel="noreferrer">CozyRoc</a>, <a href="http://ssissftp.codeplex.com/" rel="noreferrer">Codeplex</a>, <a href="http://www.eldos.com/bizcrypto/ssis-sftp-connection-task.php" rel="noreferrer">BizCrypto</a>, <a href="http://pragmaticworks.com/Products/Business-Intelligence/TaskFactory/SSIS-FTPS-SFTP-Task.aspx" rel="noreferrer">PragmaticWorks</a>, or some other vendor on each development and production server and use the SFTP task to upload the files.</p>
<p>Pros: Easy to use. It looks, smells, and feels like a normal SSIS task. SSIS also recognizes the password as sensitive information and allows you all the normal options for protecting the sensitive information instead of just storing it in clear text in a non-secure manner. Works well with other SSIS tasks such as ForEach Loop Containers. Errors out when uploads and downloads fail. Works well when you don't know the names of the files on the remote FTP site to download or when you won't know the name of the file to upload until run-time.</p>
<p>Cons: With the exception of the Codeplex solution, this costs money to license in a production environment. Requires installing the libraries on each development and production machine. If it is the Codeplex solution, then you are using software that isn't supported by any specific vendor. This also makes you dependent upon the vendor to update their libraries between each version. For instance, before 2008 RTM'd, I was developing a new server on a CTP version of 2008 and the CozyRoc 2005 library was incompatible with it. Eventually they released a 2008 compatible version, but I had to temporarily use the command line solution to work around this issue. </p>
<p>COMMAND LINE SFTP PROGRAM</p>
<p>Method: Install a free command-line SFTP application such as Putty and WinSCP and execute it either by running a batch file or operating system process task. Instructions for doing this via WinSCP are listed <a href="http://www.codeproject.com/KB/database/SSIS_SFTP.aspx" rel="noreferrer">here</a>.</p>
<p>Pros: Free, free, and free. You can be sure it is secure if you are using Putty since numerous GUI FTP clients appear to use Putty under the covers. You DEFINATELY know you are using SSH2 and not SSH.</p>
<p>Cons: The two command-line utilities I tried (Putty and Cygwin) required storing the SFTP password in a non-secure location. I haven't found a good way to capture failures or errors when uploading files. The process doesn't look and smell like SSIS. Most of the code is encapsulated in text files instead of SSIS itself. Difficult to use if you don't know the exact name of the file you are uploading or downloading.</p>
<p>A 3RD PARTY C# or VB.NET LIBRARY</p>
<p>Method: Install a SFTP or FTPS library and use a Script Task that references the library to upload the files. (I've never tried this, so I'm going to guess at the pros and cons)</p>
<p>Pros: Probably easy to capture errors. Should work well with variables, so it would probably be easy to use even when you don't know the exact name of the file you are uploading or downloading.</p>
<p>Cons: It's a script task combined with .NET libraries. If you are using SSIS, then you probably are more comfortable with SSIS tasks then .NET code. Script tasks are also difficult to troubleshoot since they don't have the same debugging tools and features as regular .NET projects. Creates a dependency on 3rd party code that may not work between different versions of SQL Server. To be fair, it is probably MORE likely to work between different versions of SQL Server than a 3rd party SSIS task library. Another huge con -- I haven't found a free C# or VB.NET library that does this as of yet. So if anyone knows of one, then please let me know!</p>
| [
{
"answer_id": 5800319,
"author": "sacha79",
"author_id": 726659,
"author_profile": "https://Stackoverflow.com/users/726659",
"pm_score": -1,
"selected": false,
"text": "Imports System\nImports Microsoft.SqlServer.Dts.Runtime\nImports Ftp\nImports System.IO\n\nPublic Class ScriptMain\n\n... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409491",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/38332/"
] |
409,495 | <p>This question is language agnostic but I am a C# guy so I use the term POCO to mean an object that only preforms data storage, usually using getter and setter fields.</p>
<p>I just reworked my Domain Model to be super-duper POCO and am left with a couple of concerns regarding how to ensure that the property values make sense witin the domain. </p>
<p>For example, the EndDate of a Service should not exceed the EndDate of the Contract that Service is under. However, it seems like a violation of SOLID to put the check into the Service.EndDate setter, not to mention that as the number of validations that need to be done grows my POCO classes will become cluttered.</p>
<p>I have some solutions (will post in answers), but they have their disadvantages and am wondering what are some favorite approaches to solving this dilemma?</p>
| [
{
"answer_id": 409508,
"author": "George Mauer",
"author_id": 5056,
"author_profile": "https://Stackoverflow.com/users/5056",
"pm_score": 2,
"selected": false,
"text": "public class ServiceEndDateValidator : IValidator<Service> {\n public void Check(Service s) {\n if(s.EndDate > s.Co... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409495",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5056/"
] |
409,496 | <p>I have a php file which I will be using as exclusively as an include. Therefore I would like to throw an error instead of executing it when it's accessed directly by typing in the URL instead of being included.</p>
<p>Basically I need to do a check as follows in the php file:</p>
<pre><code>if ( $REQUEST_URL == $URL_OF_CURRENT_PAGE ) die ("Direct access not premitted");
</code></pre>
<p>Is there an easy way to do this?</p>
| [
{
"answer_id": 409503,
"author": "Kyle Cronin",
"author_id": 658,
"author_profile": "https://Stackoverflow.com/users/658",
"pm_score": 2,
"selected": false,
"text": "$including = true;\n if (!$including) exit(\"direct access not permitted\");\n"
},
{
"answer_id": 409511,
"aut... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409496",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36848/"
] |
409,507 | <p>Is it possible to use PowerShell to script out SQL Server Reporting Services rdl files in SQL Server 2008? If so, can someone provide a code example of doing this? This would be a useful replacement for using a 3rd party tool to script out RDL files created by business users outside of my Business Intelligence department.</p>
<p><em>CLARIFICATION OF THE TERM "SCRIPT OUT"</em></p>
<p>By "script out", I mean I would like to automatically generate the underlying RDL file for each report on the server. For instance, when you code report in BIDS, you are generating a RDL file. When you deploy the file to the server, the file is somehow imported into the SQL Server ReportServer database and it is no longer a separate physical RDL file. I would like to extract all the reports from the server in a RDL file format. </p>
<p>I've used the RSScripter tool to extract the reports as RDL files, so I know it is possible using tools other than PowerShell. I would specifically like to know if it is possible to do it using PowerShell and, if so, get a sample of the code to do it.</p>
<p><em>CLARIFICATION ON WHY I WANT TO GENERATE RDL VERSIONS OF REPORTS</em></p>
<p>Why is it important to "script out" the reports to RDL files? I would like to check-in the RDL files to my source control system once a night to keep track of all reports created by users outside of my Business Intelligence department. I already keep track of all reports generated by my department since we develop our reports in BIDS, but I can't keep track of versioning history on reports built in the online Report Builder tool.</p>
<p><em>CLARIFICATION ON WHY POWERSHELL AND NOT SOMETHING ELSE</em></p>
<ol>
<li><p>Curiosity. I have a problem that I know can be solved by one of two methods (API or RSSCripter) and I would like to know if it can be solved by a 3rd method.</p></li>
<li><p>Opportunity to expand my problem solving toolbet via PowerShell. Using PowerShell to solve this problem may provide the foundation for learning how to use PowerShell to solve other problems that I haven't tried to solve yet.</p></li>
<li><p>PowerShell is easier to understand for my team and me. In general, my team members and I can understand PowerShell code more easily than .NET code. Although I know this problem can be solved with some .NET code using the API (that's how RSScripter works after all), I feel it will be easier for us to code and maintain a PowerShell script. I also realize a PowerShell script will probably use .NET code, but I'm hoping PowerShell will already be able to treat the reports like objects in some way so I won't have to use the Reporting Services API to extract the files.</p></li>
<li><p>RSScripter doesn't support 2008 yet. In the past, I've used RSScript to script out reports. Unfortunately, it doesn't appear to support 2008 yet. This means I have to write code against the API right now since that's the only way I present know how to extract the files in an automated unattended manner.</p></li>
</ol>
| [
{
"answer_id": 3198967,
"author": "Registered User",
"author_id": 38332,
"author_profile": "https://Stackoverflow.com/users/38332",
"pm_score": 2,
"selected": false,
"text": "SELECT CONVERT(VARCHAR(MAX), CONVERT(NVARCHAR(MAX), CONVERT(XML, CONVERT(VARBINARY(MAX), Content))))\nFROM [Repor... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409507",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/38332/"
] |
409,512 | <p>Is is possible to call a custom VB function, saved in the same Access Db, from a query written in that db, and if so, how?</p>
| [
{
"answer_id": 409534,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": true,
"text": " CustomFunction([field])\n"
}
] | 2009/01/03 | [
"https://Stackoverflow.com/questions/409512",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/51205/"
] |
409,529 | <p>This particular example relates to Django in Python, but should apply to any language supporting exceptions:</p>
<pre><code>try:
object = ModelClass.objects.get(search=value)
except DoesNotExist:
pass
if object:
# do stuff
</code></pre>
<p>The Django model class provides a simple method <em>get</em> which allows me to search for <em>one and only one</em> object from the database, if it finds more or less it raises an exception. If can find zero or more with an alternative <em>filter</em> method, which returns a list:</p>
<pre><code>objects = ModelClass.objects.filter(search=value)
if len(objects) == 1:
object = objects[0]
# do stuff
</code></pre>
<p><strong>Am I overly averse to exceptions?</strong> To me the exception seems a little wasteful, at a guess, a quarter-to-a-half of the time will be 'exceptional'. I'd much prefer a function that returns <em>None</em> on failure. Would I be better to use Django's <em>filter</em> method and process the list myself?</p>
| [
{
"answer_id": 409538,
"author": "Greg Beech",
"author_id": 13552,
"author_profile": "https://Stackoverflow.com/users/13552",
"pm_score": 4,
"selected": true,
"text": "get filter filter"
},
{
"answer_id": 409542,
"author": "Ned Batchelder",
"author_id": 14343,
"author... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409529",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42974/"
] |
409,555 | <p>I have three buttons and need to save some data. I have a idea, I have to set an ID to every button and then let the JS determinate witch button that has been pressed, like:</p>
<pre><code>$("#mySpecifikButton").click(function()
{
....some code here...
});
</code></pre>
<p>but then Im stuck. For example I have 9 users. All they have an ID in the db. So now we have all the users in separate rows:</p>
<pre><code><p><a id="userID">user 0</a></p>
<p><a id="userID">user 1</a></p>
<p><a id="userID">user 2</a></p>
<p><a id="userID">user 3</a></p>
...
</code></pre>
<p>When I press on a specifik user I want to add it to db through php with help of jquery.
But how do I sent it to php with JS (jquery)?</p>
<p>Im I thinking right or is there better ways?</p>
<p>If I didn't described it well, ask me.</p>
| [
{
"answer_id": 409567,
"author": "Salty",
"author_id": 50548,
"author_profile": "https://Stackoverflow.com/users/50548",
"pm_score": 3,
"selected": true,
"text": "<input type=\"button\" value=\"Button 1\" id=\"1\" />\n<input type=\"button\" value=\"Button 2\" id=\"2\" />\n<input type=\"b... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409555",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/50896/"
] |
409,560 | <p>Is it better in some sense to vectorize code by hand, using explicit pragmas or to rely on or use auto-vectorization? For optimum performance using auto-vectorization, one would have to monitor the compiler output to ensure that loops are being vectorized or modify them until they are vectorizable. </p>
<p>With hand coding, one is certain that the desired instructions are being emitted, but now the code is likely not portable (either to other architectures or other compilers).</p>
| [
{
"answer_id": 409723,
"author": "Norman Ramsey",
"author_id": 41661,
"author_profile": "https://Stackoverflow.com/users/41661",
"pm_score": 3,
"selected": false,
"text": "gcc gcc gcc objdump"
}
] | 2009/01/03 | [
"https://Stackoverflow.com/questions/409560",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10578/"
] |
409,563 | <p>I'm stuck deciding how to handle exceptions in my application. </p>
<p>Much if my issues with exceptions comes from 1) accessing data via a remote service or 2) deserializing a JSON object. Unfortunately I can't guarantee success for either of these tasks (cut network connection, malformed JSON object that is out of my control). </p>
<p>As a result, if I do encounter an exception I simply catch it within the function and return FALSE to the caller. My logic is that all the caller really cares about is if the task was successful, not why it is wasn't successful.</p>
<p>Here's some sample code (in JAVA) of a typical method)</p>
<pre><code>public boolean doSomething(Object p_somthingToDoOn)
{
boolean result = false;
try{
// if dirty object then clean
doactualStuffOnObject(p_jsonObject);
//assume success (no exception thrown)
result = true;
}
catch(Exception Ex)
{
//don't care about exceptions
Ex.printStackTrace();
}
return result;
}
</code></pre>
<p>I think this approach is fine, but I'm really curious to know what the best practices are for managing exceptions (should I really bubble an exception all the way up a call stack?). </p>
<p><strong>In summary of key questions:</strong></p>
<ol>
<li>Is it okay to just catch exceptions but not bubble them up or formally notifying the system (either via a log or a notification to the user)?</li>
<li>What best practices are there for exceptions that don't result in everything requiring a try/catch block?</li>
</ol>
<p><strong>Follow Up/Edit</strong></p>
<p>Thanks for all the feedback, found some excellent sources on exception management online:</p>
<ul>
<li><a href="http://www.onjava.com/pub/a/onjava/2003/11/19/exceptions.html" rel="noreferrer">Best Practices for Exception Handling | O'Reilly Media</a></li>
<li><a href="http://www.codeproject.com/KB/architecture/exceptionbestpractices.aspx" rel="noreferrer">Exception Handling Best Practices in .NET</a></li>
<li><a href="http://web.archive.org/web/20081207002838/http://www.dotnetjunkies.ddj.com/Article/197E493F-BA73-45A2-B39A-4EA282A2E562.dcik" rel="noreferrer">Best Practices: Exception Management</a> (Article now points to archive.org copy)</li>
<li><a href="http://today.java.net/pub/a/today/2006/04/06/exception-handling-antipatterns.html" rel="noreferrer">Exception-Handling Antipatterns</a></li>
</ul>
<p>It seems that exception management is one of those things that vary based on context. But most importantly, one should be consistent in how they manage exceptions within a system. </p>
<p>Additionally watch out for code-rot via excessive try/catches or not giving a exception its respect (an exception is warning the system, what else needs to be warned?).</p>
<p>Also, this is a pretty choice comment from <a href="https://stackoverflow.com/users/12460/m3rlinez">m3rLinEz</a>.</p>
<blockquote>
<p>I tend to agree with Anders Hejlsberg and you that the most callers only
care if operation is successful or not.</p>
</blockquote>
<p>From this comment it brings up some questions to think about when dealing with exceptions:</p>
<ul>
<li>What is the point this exception being thrown?</li>
<li>How does it make sense to handle it? </li>
<li>Does the caller really care about the exception or do they just care if the call was successful?</li>
<li>Is forcing a caller to manage a potential exception graceful?</li>
<li><strong><em>Are you being respectful to the idoms of the language?</em></strong>
<ul>
<li>Do you really need to return a success flag like boolean? Returning boolean (or an int) is more of a C mindset than a Java (in Java you would just handle the exception) one. </li>
<li>Follow the error management constructs associated with the language :) !</li>
</ul></li>
</ul>
| [
{
"answer_id": 409574,
"author": "JoshBerke",
"author_id": 26160,
"author_profile": "https://Stackoverflow.com/users/26160",
"pm_score": 5,
"selected": false,
"text": "try\n{\n //do something\n}\ncatch(Exception)\n{\n throw;\n}\n"
},
{
"answer_id": 409605,
"author": "Yuv... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409563",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/51211/"
] |
409,599 | <p>[EDIT] Hmm. Perhaps this question should be titled "what is the default user-input dialog view called in CocoaTouch?" I realize that I can create an entire view that is exactly what I want, and wrap it in a view controller and presentModalView -- but I was sort of hoping that there was a standard, normal user-input "dialog" view that came-with Cocoa-touch. "Enter your name", "enter text to search", etc., are VERY common things!</p>
<p>Anyway... here's the question as I originally asked it:</p>
<p>This code:</p>
<pre><code>UIAlertView* find = [[UIAlertView alloc] init];
[find setDelegate:self];
[find setTitle:@"Find"];
[find addButtonWithTitle:@"Cancel"];
[find addButtonWithTitle:@"Find & Bring"];
[find addButtonWithTitle:@"Find & Go"];
[find addButtonWithTitle:@"Go To Next"];
[find addSubview:_findText];
CGRect frm = find.frame;
int height = frm.size.height + _findText.frame.size.height + 100; // note how even 100 has no effect.
[find setFrame:CGRectMake(frm.origin.x, frm.origin.y, frm.size.width, height)];
[find setNeedsLayout];
[find show];
[find release];
</code></pre>
<p>Produces this Alert view:</p>
<p><a href="http://www.publicplayground.com/IMGs/Misc/FindAlert.png" rel="nofollow noreferrer">Find Alert http://www.publicplayground.com/IMGs/Misc/FindAlert.png</a></p>
<p>(I started with the code from <a href="https://stackoverflow.com/questions/376104/uitextfield-in-uialertview-on-iphone-how-to-make-it-responsive#376546" title="This other guy's question">this question by emi1Faber</a>, and it works as advertised; however, as I state in my comment, the cancel button overlays the text field.)</p>
<p>How do I reshuffle everything to make the text field fit properly? [findAlert setNeedsLayout] doesn't seem to do anything, even after I [findAlert setFrame:tallerFrame]. Hints?</p>
<p>Thanks!</p>
| [
{
"answer_id": 409714,
"author": "Stephen Darlington",
"author_id": 2998,
"author_profile": "https://Stackoverflow.com/users/2998",
"pm_score": 3,
"selected": false,
"text": "UIAlertView presentModalViewController: UIViewController alertViewStyle UIViewController"
},
{
"answer_id... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409599",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34820/"
] |
409,619 | <p>Does anyone know how to monitor long-running server-side processes in GWT, other than polling the server? We need to do some time-consuming, multiple-step, I/O-bound processing on the server, and it would be nice to display the progress of this processing in the browser.</p>
| [
{
"answer_id": 410070,
"author": "cletus",
"author_id": 18393,
"author_profile": "https://Stackoverflow.com/users/18393",
"pm_score": 3,
"selected": true,
"text": "checkStatus() public class JobStatus {\n private boolean done;\n // other info\n // ...\n}\n\npublic class JobStatusCallb... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409619",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/49642/"
] |
409,648 | <p>is there a way to make the datatextfield property of a dropdownlist in asp.net via c# composed of more than one property of an object?</p>
<pre><code>public class MyObject
{
public int Id { get; set; }
public string Name { get; set; }
public string FunkyValue { get; set; }
public int Zip { get; set; }
}
protected void Page_Load(object sender, EventArgs e)
{
List<MyObject> myList = getObjects();
ddList.DataSource = myList;
ddList.DataValueField = "Id";
ddList.DataTextField = "Name";
ddList.DataBind();
}
</code></pre>
<p>I want e.g. not use "Name", but "Name (Zip)" eg.</p>
<p>Sure, i can change the MyObject Class, but i don't want to do this (because the MyObject Class is in a model class and should not do something what i need in the UI).</p>
| [
{
"answer_id": 409681,
"author": "M4N",
"author_id": 19635,
"author_profile": "https://Stackoverflow.com/users/19635",
"pm_score": 6,
"selected": true,
"text": "public string DisplayValue\n{\n get { return string.Format(\"{0} ({1})\", Name, Zip); }\n}\n List<MyObject> myList = getObjects... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409648",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/49034/"
] |
409,686 | <p>I'm using Apache 2. I know how to handle .pl files as "cgi-script", but mod_perl is supposedly way faster. I successfully built and installed mod_perl, but how do I change httpd.conf so that .pl files will be handled by mod_perl (and not as cgi-script)?</p>
| [
{
"answer_id": 409693,
"author": "helloandre",
"author_id": 50,
"author_profile": "https://Stackoverflow.com/users/50",
"pm_score": 1,
"selected": false,
"text": "AddHandler mod_perl .pl"
},
{
"answer_id": 6037569,
"author": "AndrewPK",
"author_id": 705198,
"author_pr... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409686",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
409,688 | <p>This is a complex question, please consider carefully before answering.</p>
<p>Consider this situation. Two threads (a reader and a writer) access a single global <code>int</code>. Is this safe? Normally, I would respond without thought, yes!</p>
<p>However, it seems to me that Herb Sutter doesn't think so. In his articles on effective concurrency he discusses a <a href="http://www.ddj.com/cpp/210600279" rel="nofollow noreferrer">flawed lock-free queue</a> and the <a href="http://www.ddj.com/hpc-high-performance-computing/210604448" rel="nofollow noreferrer">corrected version</a>.</p>
<p>In the end of the first article and the beginning of the second he discusses a rarely considered trait of variables, write ordering. Int's are atomic, good, but ints aren't necessarily ordered which could destroy any lock-free algorithm, including my above scenario. I fully agree that the only way to <strong><em>guarantee</em></strong> correct multithreaded behavior on all platforms present and future is to use atomics(AKA memory barriers) or mutexes.</p>
<p>My question; is write re-odering ever a problem on real hardware? Or is the multithreaded paranoia just being pedantic?<br>
What about classic uniprocessor systems?<br>
What about simpler RISC processors like an embedded power-pc?</p>
<p><em>Clarification</em>: I'm more interested in what Mr. Sutter said about the hardware (processor/cache) reordering variable writes. I can stop the optimizer from breaking code with compiler switches or hand inspection of the assembly post-compilation. However, I'd like to know if the hardware can still mess up the code in practice.</p>
| [
{
"answer_id": 409749,
"author": "Henk",
"author_id": 4613,
"author_profile": "https://Stackoverflow.com/users/4613",
"pm_score": 2,
"selected": false,
"text": "volatile volatile int volatile volatile int AtomicInteger atomic<T> atomic<int>"
}
] | 2009/01/03 | [
"https://Stackoverflow.com/questions/409688",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28817/"
] |
409,705 | <p>Ok, here is my dilemma I have a database set up with about 5 tables all with the exact same data structure. The data is separated in this manner for localization purposes and to split up a total of about 4.5 million records.</p>
<p>A majority of the time only one table is needed and all is well. However, sometimes data is needed from 2 or more of the tables and it needs to be sorted by a user defined column. This is where I am having problems.</p>
<p>data columns:</p>
<pre><code>id, band_name, song_name, album_name, genre
</code></pre>
<p>MySQL statment:</p>
<pre><code>SELECT * from us_music, de_music where `genre` = 'punk'
</code></pre>
<p>MySQL spits out this error:</p>
<pre><code>#1052 - Column 'genre' in where clause is ambiguous
</code></pre>
<p>Obviously, I am doing this wrong. Anyone care to shed some light on this for me?</p>
| [
{
"answer_id": 409720,
"author": "Mihai Limbășan",
"author_id": 14444,
"author_profile": "https://Stackoverflow.com/users/14444",
"pm_score": 8,
"selected": true,
"text": "(SELECT * from us_music where `genre` = 'punk')\nUNION\n(SELECT * from de_music where `genre` = 'punk')\n"
},
{
... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409705",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24802/"
] |
409,727 | <p>I just finished transferring as much link-structure data concerning wikipedia (English) as I could. Basically, I downloaded a bunch of SQL dumps from wikipedia's <a href="http://download.wikimedia.org/enwiki/latest/" rel="nofollow noreferrer">latest dump repository</a>. Since I am using PostgreSQL instead of MySQL, I decided to load all these dumps into my db using <a href="http://jhacks.anzix.net/space/kocka/my2pg" rel="nofollow noreferrer">pipeline shell commands</a>.</p>
<p>Anyway, one of these tables has 295 million rows: the <em>pagelinks</em> table; it contains all intra-wiki hyperlinks. From my laptop, using pgAdmin III, I sent the following command to my database server (another computer):</p>
<pre><code>SELECT pl_namespace, COUNT(*) FROM pagelinks GROUP BY (pl_namespace);
</code></pre>
<p>Its been at it for an hour or so now. The thing is that the postmaster seems to be eating up more and more of my very limited HD space. I think it ate about 20 GB as of now. I had previously played around with the postgresql.conf file in order to give it more performance flexibility (i.e. let it use more resources) for it is running with 12 GB of RAM. I think I basically quadrupled most bytes and such related variables of this file thinking it would use more RAM to do its thing. </p>
<p>However, the db does not seem to use much RAM. Using the Linux system monitor, I am able to see that the postmaster is using 1.6 GB of shared memory (RAM). Anyway, I was wondering if you guys could help me better understand what it is doing for it seems that I really do not understand <em>how PostgreSQL uses HD resources</em>.</p>
<p>Concerning the metastructure of wikipedia databases, they provide a good <a href="http://upload.wikimedia.org/wikipedia/commons/4/41/Mediawiki-database-schema.png" rel="nofollow noreferrer">schema</a> that may be of use or even but of interest to you.</p>
<p>Feel free to ask me for more details, thx.</p>
| [
{
"answer_id": 409760,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 1,
"selected": false,
"text": "pl_namespace"
},
{
"answer_id": 409873,
"author": "Barry Brown",
"author_id": 17312,
"author_profile... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409727",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/49985/"
] |
409,732 | <p>I have a list of booleans where occasionally I reset them all to false. After first writing the reset as:</p>
<pre><code>for b in bool_list:
b = False
</code></pre>
<p>I found it doesn't work. I spent a moment scratching my head, then remembered that of course it won't work since I'm only changing a reference to the bool, not its value. So I rewrote as:</p>
<pre><code>for i in xrange(len(bool_list)):
bool_list[i] = False
</code></pre>
<p>and everything works fine. But I found myself asking, "Is that really the most pythonic way to alter all elements of a list?" Are there other ways that manage to be either more efficient or clearer?</p>
| [
{
"answer_id": 409744,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 4,
"selected": false,
"text": "bool_list = [False] * len(bool_list)\n False"
},
{
"answer_id": 409745,
"author": "Zoomulator",
"author_i... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409732",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22897/"
] |
409,761 | <p>I am trying to insert a very long text string into a MySQL Blob column, but MySQL is only saving 64kB of the data. The string is 75360 characters long. I am connecting with PHP's <code>mysql_connect()</code>.</p>
<p>Any ideas?</p>
<p>Does it make a difference if it's Blob or Text. I originally had it as a Text but changed it with no affect.</p>
| [
{
"answer_id": 409779,
"author": "Robert Gamble",
"author_id": 25222,
"author_profile": "https://Stackoverflow.com/users/25222",
"pm_score": 3,
"selected": false,
"text": "BLOB MEDIUMBLOB LONGBLOB"
},
{
"answer_id": 410093,
"author": "meouw",
"author_id": 12161,
"auth... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409761",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5441/"
] |
409,769 | <p>I am using google's appengine api</p>
<pre><code>from google.appengine.api import urlfetch
</code></pre>
<p>to fetch a webpage. The result of</p>
<pre><code>result = urlfetch.fetch("http://www.example.com/index.html")
</code></pre>
<p>is a string of the html content (in result.content). The problem is the data that I want to parse is not really in HTML form, so I don't think using a python HTML parser will work for me. I need to parse all of the plain text in the body of the html document. The only problem is that urlfetch returns a single string of the entire HTML document, removing all newlines and extra spaces.</p>
<p><strong>EDIT:</strong>
Okay, I tried fetching a different URL and apparently urlfetch does not strip the newlines, it was the original webpage I was trying to parse that served the HTML file that way...
<strong>END EDIT</strong></p>
<p>If the document is something like this:</p>
<pre><code><html><head></head><body>
AAA 123 888 2008-10-30 ABC
BBB 987 332 2009-01-02 JSE
...
A4A 288 AAA
</body></html>
</code></pre>
<p>result.content will be this, after urlfetch fetches it:</p>
<pre><code>'<html><head></head><body>AAA 123 888 2008-10-30 ABCBBB 987 2009-01-02 JSE...A4A 288 AAA</body></html>'
</code></pre>
<p>Using an HTML parser will not help me with the data between the body tags, so I was going to use regular expresions to parse my data, but as you can see the last part of one line gets combined with the first part of the next line, and I don't know how to split it. I tried</p>
<pre><code>result.content.split('\n')
</code></pre>
<p>and</p>
<pre><code>result.content.split('\r')
</code></pre>
<p>but the resulting list was all just 1 element. I don't see any options in google's urlfetch function to not remove newlines.</p>
<p>Any ideas how I can parse this data? Maybe I need to fetch it differently?</p>
<p>Thanks in advance!</p>
| [
{
"answer_id": 409844,
"author": "rob",
"author_id": 43927,
"author_profile": "https://Stackoverflow.com/users/43927",
"pm_score": 3,
"selected": true,
"text": "import re\ndata = re.findall('<body>([^\\<]*)</body>', result)[0]\n start = 0\nend = 5\nwhile (end<len(data)):\n print data[s... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409769",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40619/"
] |
409,783 | <p>I recently saw a bit of code that looked like this (with sock being a socket object of course):</p>
<pre><code>sock.shutdown(socket.SHUT_RDWR)
sock.close()
</code></pre>
<p>What exactly is the purpose of calling shutdown on the socket and then closing it? If it makes a difference, this socket is being used for non-blocking IO.</p>
| [
{
"answer_id": 598759,
"author": "Robert S. Barnes",
"author_id": 71074,
"author_profile": "https://Stackoverflow.com/users/71074",
"pm_score": 8,
"selected": false,
"text": "close shutdown close shutdown"
},
{
"answer_id": 19009869,
"author": "mykhal",
"author_id": 23424... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409783",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2147/"
] |
409,784 | <p>In Java, arrays don't override <code>toString()</code>, so if you try to print one directly, you get the <code>className</code> + '@' + the hex of the <a href="https://en.wikipedia.org/wiki/Java_hashCode()" rel="nofollow noreferrer"><code>hashCode</code></a> of the array, as defined by <code>Object.toString()</code>:</p>
<pre class="lang-java prettyprint-override"><code>int[] intArray = new int[] {1, 2, 3, 4, 5};
System.out.println(intArray); // Prints something like '[I@3343c8b3'
</code></pre>
<p>But usually, we'd actually want something more like <code>[1, 2, 3, 4, 5]</code>. What's the simplest way of doing that? Here are some example inputs and outputs:</p>
<pre class="lang-java prettyprint-override"><code>// Array of primitives:
int[] intArray = new int[] {1, 2, 3, 4, 5};
// Output: [1, 2, 3, 4, 5]
// Array of object references:
String[] strArray = new String[] {"John", "Mary", "Bob"};
// Output: [John, Mary, Bob]
</code></pre>
| [
{
"answer_id": 409795,
"author": "Esko",
"author_id": 44523,
"author_profile": "https://Stackoverflow.com/users/44523",
"pm_score": 13,
"selected": true,
"text": "Arrays.toString(arr) Arrays.deepToString(arr) Object[] .toString() String[] array = new String[] {\"John\", \"Mary\", \"Bob\"... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409784",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12149/"
] |
409,799 | <p>I am trying to setup roles in a dynamic data website..
the problem is that i cant set it by simpy doing this. </p>
<pre><code> <location path="List.aspx">
<system.web>
<authorization>
<allow roles="Administrators" />
<deny users="*" />
</authorization>
</system.web>
</location>
</code></pre>
<p>so even when i login as a role called "Member" it still alows me to go into List.aspx </p>
<p>can any one please guide me on this.. </p>
<p>oh btw i am also using mvc on the same site</p>
| [
{
"answer_id": 898965,
"author": "Merritt",
"author_id": 60385,
"author_profile": "https://Stackoverflow.com/users/60385",
"pm_score": 3,
"selected": false,
"text": " <location path=\"Admin/<TableName>/List.aspx\">\n <system.web>\n <authorization>\n <allow roles=\"Adminis... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409799",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/43838/"
] |
409,827 | <p>I'm trying to get my head around tuples (thanks @litb), and the common suggestion for their use is for functions returning > 1 value. </p>
<p>This is something that I'd normally use a struct for , and I can't understand the advantages to tuples in this case - it seems an error-prone approach for the terminally lazy.</p>
<p><a href="https://stackoverflow.com/questions/321068/returning-multiple-values-from-a-c-function">Borrowing an example</a>, I'd use this</p>
<pre><code>struct divide_result {
int quotient;
int remainder;
};
</code></pre>
<p>Using a tuple, you'd have</p>
<pre><code>typedef boost::tuple<int, int> divide_result;
</code></pre>
<p>But without reading the code of the function you're calling (or the comments, if you're dumb enough to trust them) you have no idea which int is quotient and vice-versa. It seems rather like... </p>
<pre><code>struct divide_result {
int results[2]; // 0 is quotient, 1 is remainder, I think
};
</code></pre>
<p>...which wouldn't fill me with confidence.</p>
<p>So, what <em>are</em> the advantages of tuples over structs that compensate for the ambiguity?</p>
| [
{
"answer_id": 409838,
"author": "Anteru",
"author_id": 39912,
"author_profile": "https://Stackoverflow.com/users/39912",
"pm_score": 3,
"selected": false,
"text": "tie std::tr1::tie (quotient, remainder) = do_division (); pair<int, bool> readFromFile()"
},
{
"answer_id": 409930,... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409827",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1737/"
] |
409,846 | <p>Im new into that asp.net thing, but here goes.</p>
<p>I got at ImageButton, and when its clicked i want the image displayed in another window. If I can avoid using ajax i would like to do that.
If possible would like to make the window modal, but still avoid ajax, since Im not ready to mix more technolgies yet.</p>
| [
{
"answer_id": 409851,
"author": "Filip Ekberg",
"author_id": 39106,
"author_profile": "https://Stackoverflow.com/users/39106",
"pm_score": 0,
"selected": false,
"text": "<asp:ImageButton ID=\"imbJoin\" CssClass=\"btn-find\" AlternateText=\"Find\" ToolTip=\"Find\" runat=\"server\" ImageU... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409846",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36476/"
] |
409,849 | <p>I am trying to select 100s of rows at a DB that contains 100000s of row and update those rows afters.</p>
<p>the problem is I don't want to go to DB twice for this purpose since update only marks those rows as "read".</p>
<p>is there any way I can do this in java using simple jdbc libraries? (hopefully without using stored procedures)</p>
<p>update: ok here is some clarification.</p>
<p>there are a few instance of same application running on different servers, they all need to select 100s of "UNREAD" rows sorted according to creation_date column, read blob data within it, write it to file and ftp that file to some server. (I know prehistoric but requirements are requirements)</p>
<p>The read and update part is for to ensure each instance getting diffent set of data. (in order, tricks like odds and evens wont work :/) </p>
<p>We select data for update. the data transfers through the wire (we wait and wait) and then we update them as "READ". then release lock for reading. this entire thing takes too long. By reading and updating at the same time, I would like to reduce lock time (from time we use select for update to actual update) so that using multiple instances would increase read rows per second. </p>
<p>Still have ideas?</p>
| [
{
"answer_id": 409943,
"author": "Todd",
"author_id": 49746,
"author_profile": "https://Stackoverflow.com/users/49746",
"pm_score": 2,
"selected": false,
"text": "update table_x\nset read = 'T'\nwhere date > sysdate-1;\n"
}
] | 2009/01/03 | [
"https://Stackoverflow.com/questions/409849",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/51238/"
] |
409,886 | <p>I can send any windows application key strokes with <code>PostMessage</code> api. But I can't send key strokes to Game window by using <code>PostMessage</code>.</p>
<p>Anyone know anything about using Direct Input functions for sending keys to games from C#.</p>
| [
{
"answer_id": 20898776,
"author": "Jason",
"author_id": 555547,
"author_profile": "https://Stackoverflow.com/users/555547",
"pm_score": 3,
"selected": false,
"text": "input.MoveMouseTo(5, 5);\ninput.MoveMouseBy(25, 25);\ninput.SendLeftClick();\n\ninput.KeyDelay = 1; // See below for exp... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409886",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/50985/"
] |
409,916 | <p>I'm creating a indoor navigation application (with the intention that a user can store maps for different buildings in the phones file system). The application starts up by asking the user to select a map for the desired building. Once this has been selected, a file parser would be used to parse and convert the map data from the file. While this is happening, i created a wait screen saying please wait... and also put up a loading/processing image which is a gif. But when i run this in Sun's WTK emulator, the gif doesn't change, it becomes a static picture. By the way, I'm using Netbeans 6.1 for this. Any ideas? Thanks a lot. </p>
| [
{
"answer_id": 410043,
"author": "Honza",
"author_id": 8621,
"author_profile": "https://Stackoverflow.com/users/8621",
"pm_score": 2,
"selected": false,
"text": "InputStream is = getClass().getResourceAsStream(\"/OceanFish.gif\");\nDataInputStream di = new DataInputStream(is);\nStaticAni... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409916",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/51243/"
] |
409,919 | <p>I'm trying to work this out.</p>
<p>In my project, i have a file called 'Hello.java' which is the file with the main() argument and which is called when the program is compiled. And I have another file called MyObj.java which has got just a random class I made up to test java's OO features. I'm trying to do this:</p>
<pre><code>class Hello
{
public MyObj an_obj;
public static void main(String[] args)
{
setObj();
}
public void setObj()
{
this.an_obj.set_size(7);
say("size is " + this.an_obj.get_size());
}
}
</code></pre>
<p>In the MyObj.java class i have this code:</p>
<pre><code>public class MyObj
{
private int size;
public MyObj()
{
//do nothing
}
public void set_size(int new_size)
{
this.size=new_size;
}
public int get_size()
{
return this.size;
}
}
</code></pre>
<p>This however gives the error:</p>
<blockquote>
<p>"Cannot make a static reference to
non-static method setObj() from the
type Hello".</p>
</blockquote>
<p>If I add 'static' to the declaration of setObj, i.e</p>
<pre><code>public static void setObj()
</code></pre>
<p>Then I get:</p>
<blockquote>
<p>Cannot make a static reference to
non-static field an_obj.</p>
</blockquote>
<p>My question is, how can I accomplish what I'm doing, i.e setting and retreiving an object's field if the only way to start a program is with the Main method, and the main Method can only call static methods?? In what, how can I do anything at all with this limitation of being able to call static methods only?????</p>
| [
{
"answer_id": 409927,
"author": "Ross",
"author_id": 29173,
"author_profile": "https://Stackoverflow.com/users/29173",
"pm_score": 5,
"selected": true,
"text": "/* Static */\nclass Hello {\n public static MyObj an_obj;\n public static void main(String[] args) { \n setObj();... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409919",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/49153/"
] |
409,932 | <p>I have code where I schedule a task using <code>java.util.Timer</code>. I was looking around and saw <code>ExecutorService</code> can do the same. So this question here, have you used <code>Timer</code> and <code>ExecutorService</code> to schedule tasks, what is the benefit of one using over another?</p>
<p>Also wanted to check if anyone had used the <code>Timer</code> class and ran into any issues which the <code>ExecutorService</code> solved for them.</p>
| [
{
"answer_id": 409993,
"author": "Peter Štibraný",
"author_id": 47190,
"author_profile": "https://Stackoverflow.com/users/47190",
"pm_score": 9,
"selected": true,
"text": "Timer ScheduledThreadPoolExecutor Timer ScheduledThreadPoolExecutor ThreadFactory TimerTask Timer ScheduledThreadExe... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409932",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/43756/"
] |
409,945 | <p>How, being inside the main form of my WinForm app can I tell if there are any modal windows/dialogs open that belong to the main form?</p>
| [
{
"answer_id": 409989,
"author": "Juliet",
"author_id": 40516,
"author_profile": "https://Stackoverflow.com/users/40516",
"pm_score": 3,
"selected": false,
"text": "foreach (Form f in Application.OpenForms)\n{\n if (f.Modal)\n {\n // do stuff\n }\n}\n"
},
{
"answe... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409945",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18046/"
] |
409,949 | <p>I've been using mutagen for reading and writing MP3 tags, but I want to be able to embed album art directly into the file.</p>
| [
{
"answer_id": 1002814,
"author": "Owen",
"author_id": 2109,
"author_profile": "https://Stackoverflow.com/users/2109",
"pm_score": 4,
"selected": false,
"text": "def update_id3(mp3_file_name, artwork_file_name, artist, item_title): \n #edit the ID3 tag to add the title, artist, art... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409949",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
409,955 | <p>Does heavy use of unit tests discourage the use of debug asserts? It seems like a debug assert firing in the code under test implies the unit test shouldn't exist or the debug assert shouldn't exist. "There can be only one" seems like a reasonable principle. Is this the common practice? Or do you disable your debug asserts when unit testing, so they can be around for integration testing?</p>
<p>Edit: I updated 'Assert' to debug assert to distinguish an assert in the code under test from the lines in the unit test that check state after the test has run. </p>
<p>Also here is an example that I believe shows the dilema:
A unit test passes invalid inputs for a protected function that asserts it's inputs are valid. Should the unit test not exist? It's not a public function. Perhaps checking the inputs would kill perf? Or should the assert not exist? The function is protected not private so it should be checking it's inputs for safety. </p>
| [
{
"answer_id": 2595786,
"author": "Orion Edwards",
"author_id": 234,
"author_profile": "https://Stackoverflow.com/users/234",
"pm_score": 3,
"selected": false,
"text": "Debug.Assert"
},
{
"answer_id": 2595941,
"author": "Paul Kohler",
"author_id": 276563,
"author_prof... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409955",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3892/"
] |
409,969 | <p>I've looked at other definitions and explanations and none of them satisfy me. I want to see if anybody can define polymorphism in at most two sentences without using any code or examples. I don't want to hear 'So you have a person/car/can opener...' or how the word is derived (nobody is impressed that you know what poly and morph means). If you have a very good grasp of what polymorphism is and have a good command of English than you should be able to answer this question in a short, albeit dense, definition. If your definition accurately defines polymorphism but is so dense that it requires a couple of read overs, then that's exactly what I am looking for.</p>
<p>Why only two sentences? Because a definition is short and intelligent. An explanation is long and contains examples and code. Look here for explanations (the answer on those pages are not satisfactory for my question):</p>
<p><a href="https://stackoverflow.com/questions/154577/polymorphism-vs-overriding-vs-overloading">Polymorphism vs Overriding vs Overloading</a> <br>
<a href="https://stackoverflow.com/questions/210460/try-to-describe-polymorphism-as-easy-as-you-can">Try to describe polymorphism as easy as you can</a></p>
<p>Why am I asking this question ? Because I was asked the same question and I found I was unable to come up with a satisfactory definition (by my standards, which are pretty high). I want to see if any of the great minds on this site can do it.</p>
<p>If you really can't make the two sentence requirement (it's a difficult subject to define) then it's fine if you go over. The idea is to have a definition that actually defines what polymorphism is and doesn't explain what it does or how to use it (get the difference?).</p>
| [
{
"answer_id": 15182108,
"author": "jazziiilove",
"author_id": 2128050,
"author_profile": "https://Stackoverflow.com/users/2128050",
"pm_score": 0,
"selected": false,
"text": "List list = new List();\n IList IList list = new List();\n IList IList IList virtual override"
},
{
"ans... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409969",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/51248/"
] |
409,991 | <p>I am trying to execute this SQL command:</p>
<pre><code>SELECT page.page_namespace, pagelinks.pl_namespace, COUNT(*)
FROM page, pagelinks
WHERE
(page.page_namespace <=3 OR page.page_namespace = 12
OR page.page_namespace = 13
)
AND
(pagelinks.pl_namespace <=3 OR pagelinks.pl_namespace = 12
OR pagelinks.pl_namespace = 13
)
AND
(page.page_is_redirect = 0)
AND
pagelinks.pl_from = page.page_id
GROUP BY (page.page_namespace, pagelinks.pl_namespace)
;
</code></pre>
<p>When I do so, I get the following error: </p>
<pre><code> ERROR: could not identify an ordering operator for type record
HINT: Use an explicit ordering operator or modify the query.
********** Error **********
ERROR: could not identify an ordering operator for type record
SQL state: 42883
Hint: Use an explicit ordering operator or modify the query.
</code></pre>
<p>I have tried adding : <em>ORDER BY (page.page_namespace, pagelinks.pl_namespace) ASC</em> to the end of the query without success. </p>
<p>UPDATE:</p>
<p>I also tried this:</p>
<pre><code>SELECT page.page_namespace, pagelinks.pl_namespace, COUNT(*)
FROM page, pagelinks
WHERE pagelinks.pl_from = page.page_id
GROUP BY (page.page_namespace, pagelinks.pl_namespace)
;
</code></pre>
<p>But I still get the same error.</p>
<p>Thx</p>
| [
{
"answer_id": 410037,
"author": "Peter Becker",
"author_id": 19820,
"author_profile": "https://Stackoverflow.com/users/19820",
"pm_score": 0,
"selected": false,
"text": "page.page_namespace <=3 pagelinks.pl_namespace <=3 <="
},
{
"answer_id": 410057,
"author": "Adrian Pronk"... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409991",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/49985/"
] |
409,995 | <p>How would I truncate a sentence at a certain character:</p>
<p>$sentence = 'Stack Overflow - Ask Questions Here';</p>
<p>so that only the following is echoed:</p>
<p>Stack Overflow</p>
<p>The character count varies, but the stop point is always "Space Dash Space"</p>
| [
{
"answer_id": 410032,
"author": "Robert Gamble",
"author_id": 25222,
"author_profile": "https://Stackoverflow.com/users/25222",
"pm_score": 0,
"selected": false,
"text": "$variable $sentence = 'Stack Overflow - Ask Questions Here';\n\nif ($sentence =~ /^(.*?) - /) {\n print \"Found mat... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409995",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
409,999 | <p>I want to retrieve information like the city, state, and country of a visitor from their IP address, so that I can customize my web page according to their location. Is there a good and reliable way to do this in PHP? I am using JavaScript for client-side scripting, PHP for server-side scripting, and MySQL for the database.</p>
| [
{
"answer_id": 410014,
"author": "Isaac Waller",
"author_id": 764272,
"author_profile": "https://Stackoverflow.com/users/764272",
"pm_score": 3,
"selected": false,
"text": "$data = file_get_contents(\"http://api.hostip.info/country.php?ip=12.215.42.19\");\n//$data contains: \"US\"\n\n$da... | 2009/01/03 | [
"https://Stackoverflow.com/questions/409999",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
410,002 | <p>PHP has the habit of evaluating (int)0 and (string)"0" as empty when using the <code>empty()</code> function. This can have unintended results if you expect numerical or string values of 0. How can I "fix" it to only return true to empty objects, arrays, strings, etc?</p>
| [
{
"answer_id": 410003,
"author": "null",
"author_id": 25411,
"author_profile": "https://Stackoverflow.com/users/25411",
"pm_score": 0,
"selected": false,
"text": "IsEmpty() function IsEmpty($mData) {\n return is_int($mData) ? false : \n is_string($mData) ? $mData==\"\" : \n ... | 2009/01/03 | [
"https://Stackoverflow.com/questions/410002",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25411/"
] |
410,005 | <p>I'm relatively new to the Component Object Model specification - I have a simple question:</p>
<ul>
<li> How can I access a <b>COM interface</b> from a C or C++ application
</ul>
<p>For instance, accessing Microsoft Excel COM interface to perform basic operations, without user intervention.</p>
<p>Kind regards</p>
| [
{
"answer_id": 410003,
"author": "null",
"author_id": 25411,
"author_profile": "https://Stackoverflow.com/users/25411",
"pm_score": 0,
"selected": false,
"text": "IsEmpty() function IsEmpty($mData) {\n return is_int($mData) ? false : \n is_string($mData) ? $mData==\"\" : \n ... | 2009/01/03 | [
"https://Stackoverflow.com/questions/410005",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/51078/"
] |
410,011 | <p>Right now in Flash CS3 and up (using Actionscript 3) if you have the same instance that is used in multiple keyframes in a layer, and you decide to assign or change the instance name later, you would have to go to each keyframe and set the instance name. This is a big nuisance. Is there a quicker or better way to do this?</p>
<p>NOTE: In AS2, you can set the name by using name property of the MovieClip in your code in the onLoad handler of the MovieClip class so it's done once and for all. Unfortunately in AS3, you are not allowed to set the name property anymore.</p>
| [
{
"answer_id": 410781,
"author": "Soviut",
"author_id": 46914,
"author_profile": "https://Stackoverflow.com/users/46914",
"pm_score": 3,
"selected": false,
"text": "var prefix:String = \"myInstance_\";\nfor(i in fl.getDocumentDOM().selection)\n{\n fl.getDocumentDOM().selection[i].name... | 2009/01/03 | [
"https://Stackoverflow.com/questions/410011",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/51258/"
] |
410,013 | <p>I've noticed on OSX, installation is frequently a drag and drop one file kinda deal. I assume that file is an archive of all the applications necessary bits and that the application runs directly from it. Where does the application store configuration data, particularly per user settings when there are multiple users? On Windows, this type of stuff might go in the registry under HKLU or HKLM, or in the Application Data folder for the user or for all users.</p>
| [
{
"answer_id": 410023,
"author": "harms",
"author_id": 41489,
"author_profile": "https://Stackoverflow.com/users/41489",
"pm_score": 8,
"selected": true,
"text": "/Users/username/Library/Preferences /Users/username/Library/Application Support /Users /Library /Users/username/Library/Prefe... | 2009/01/03 | [
"https://Stackoverflow.com/questions/410013",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/51259/"
] |
410,022 | <p>Can a <strong>PHP script</strong> (which can be working with a MySQL DB) <strong>send and/or receive SMSs</strong> using some sort of server-side solution?</p>
<p>Any special server-side <strong>application</strong>, or special <strong>hardware</strong> required?
And compatibility? Windows, <strong>Linux?</strong></p>
| [
{
"answer_id": 45932943,
"author": "Serve",
"author_id": 8295711,
"author_profile": "https://Stackoverflow.com/users/8295711",
"pm_score": 1,
"selected": false,
"text": "function CURLsendsms($number, $message_body){\n $api_params = $api_element.'?apikey='.$apikey.'&sender='.$sender.'&to=... | 2009/01/03 | [
"https://Stackoverflow.com/questions/410022",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41021/"
] |
410,026 | <p>The <a href="https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/yield" rel="noreferrer">yield</a> keyword is one of those <a href="https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/" rel="noreferrer">keywords</a> in C# that continues to mystify me, and I've never been confident that I'm using it correctly.</p>
<p>Of the following two pieces of code, which is the preferred and why?</p>
<p><strong>Version 1:</strong> Using yield return</p>
<pre><code>public static IEnumerable<Product> GetAllProducts()
{
using (AdventureWorksEntities db = new AdventureWorksEntities())
{
var products = from product in db.Product
select product;
foreach (Product product in products)
{
yield return product;
}
}
}
</code></pre>
<p><strong>Version 2:</strong> Return the list</p>
<pre><code>public static IEnumerable<Product> GetAllProducts()
{
using (AdventureWorksEntities db = new AdventureWorksEntities())
{
var products = from product in db.Product
select product;
return products.ToList<Product>();
}
}
</code></pre>
| [
{
"answer_id": 410047,
"author": "petr k.",
"author_id": 15497,
"author_profile": "https://Stackoverflow.com/users/15497",
"pm_score": 3,
"selected": false,
"text": "public static IEnumerable<Product> GetAllProducts()\n{\n using (AdventureWorksEntities db = new AdventureWorksEntities(... | 2009/01/03 | [
"https://Stackoverflow.com/questions/410026",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10792/"
] |
410,062 | <p>Functions in Python can be called using keyword arguments of the form keyword = value. For instance, the following function:</p>
<pre><code>def parrot(voltage, state='a stiff', action='voom', type='Norwegian Blue'):
print "-- This parrot wouldn't", action,
print "if you put", voltage, "volts through it."
print "-- Lovely plumage, the", type
print "-- It's", state, "!"
</code></pre>
<p>could be called in any of the following ways:</p>
<pre><code>parrot(1000)
parrot(action = 'VOOOOOM', voltage = 1000000)
parrot('a thousand', state = 'pushing up the daisies')
parrot('a million', 'bereft of life', 'jump')
</code></pre>
<p>ActionScript 3 does not have this facility. How would I best emulate it?</p>
| [
{
"answer_id": 410104,
"author": "grapefrukt",
"author_id": 914,
"author_profile": "https://Stackoverflow.com/users/914",
"pm_score": 3,
"selected": false,
"text": "public function awesomefunction(input:Object):void {\n if (input.foo) trace(\"got foo\");\n if (input.bar) trace(\"go... | 2009/01/03 | [
"https://Stackoverflow.com/questions/410062",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
410,073 | <p>I've seen many questions about this, but i've never really got the answer that I need. </p>
<p>I'm converting a fairly large web application from Web Forms to MVC and after a while I encountred a problem with passing data to the view. In the Action I execute the code: </p>
<p><code>//This is just an example
ViewData["QProducts"] = from p in db.Products select new{Name = p.Name, Date = p.ToShortDateString() }
ViewData["QUsers"] = from u in db.Users select u;</code></p>
<p>I use a foreach loop to iterate over the objects in html, like this: </p>
<pre><code>foreach(var q in (IEnumerable)ViewData["QEvents"])
{
/*Print the data here*/
}
</code></pre>
<p>Before using MVC I just used a <code>asp:Repeater</code>, but since this is MVC I can't use ASP.NET controls. </p>
<p>How am I supposed to pass this data to the View? I don't really have the option of not using Anonymous Types here. <code><%#ViewData.Eval()%></code> obviously won't work. </p>
<p>Any Ideas?</p>
| [
{
"answer_id": 410139,
"author": "ccook",
"author_id": 51275,
"author_profile": "https://Stackoverflow.com/users/51275",
"pm_score": 1,
"selected": false,
"text": "ViewData[\"QUsers\"] = (from u in db.Users select u).ToList();\n\nforeach(Users u in (List<Users>)ViewData[\"QUsers\"]){ \n\... | 2009/01/03 | [
"https://Stackoverflow.com/questions/410073",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/51269/"
] |
410,089 | <p>How do I append the previous item in array to the next item in the array for unknown number of items?</p>
<p>Here is what I'm trying to do. I have a string containing an LDAP path such as "OU=3,OU=2,OU=1,DC=Internal,DC=Net", I want to create each container in the above LDAP path so from the above string I need to create an array with the contents below so I can create each container. The first array item needs creating before I can create the second etc.</p>
<p>"OU=1,DC=Internal,DC=Net"</p>
<p>"OU=2,OU=1,DC=Internal,DC=Net"</p>
<p>"OU=3,OU=2,OU=1,DC=Internal,DC=Net"</p>
<p>My string example is just an example so the path may be longer or shorter and could contain 1 array item or 10+ I just don't know so I won't know how many array items there are I need to loop through them all so I have all the paths in the array.</p>
<p>Another example:</p>
<p>From "OU=Test4,OU=Number3,OU=Item2,OU=1,DC=Internal,DC=Net" I need:</p>
<p>"OU=1,DC=Internal,DC=Net"
"OU=Item2,OU=1,DC=Internal,DC=Net"
"OU=Number3,OU=Item2,OU=1,DC=Internal,DC=Net"
"OU=Test4,OU=Number3,OU=Item2,OU=1,DC=Internal,DC=Net"</p>
<p>Thanks for the help with this.</p>
<p>J</p>
| [
{
"answer_id": 410117,
"author": "JaredPar",
"author_id": 23283,
"author_profile": "https://Stackoverflow.com/users/23283",
"pm_score": 0,
"selected": false,
"text": "static string[] Split(string path)\n{\n const string postfix = \",DC=Internal,DC=Net\";\n string shortPath = path.S... | 2009/01/03 | [
"https://Stackoverflow.com/questions/410089",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
410,109 | <p>Are there any helper libs to read a cookie file in php. I have a cookie file on my local disk and I would like a better way of reading it. I am currently just reading to file like by line and parsing out the values.</p>
| [
{
"answer_id": 410159,
"author": "null",
"author_id": 25411,
"author_profile": "https://Stackoverflow.com/users/25411",
"pm_score": 0,
"selected": false,
"text": "setcookie()"
},
{
"answer_id": 410165,
"author": "lpfavreau",
"author_id": 35935,
"author_profile": "http... | 2009/01/03 | [
"https://Stackoverflow.com/questions/410109",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
410,111 | <p>I'm an Objective-C developer porting an application to the .Net world. In my Obj-C application, I use NSNotification objects to communicate asynchronously between a handful of objects. Is there some way to do something similar in the .Net world (more specifically, using the C# language)? The fundamental approach is that one object posts a notification that one or more objects listen for.</p>
<p>There's probably an obvious way of doing this, but I haven't found it yet...</p>
| [
{
"answer_id": 49100535,
"author": "Hussein Juybari",
"author_id": 5229540,
"author_profile": "https://Stackoverflow.com/users/5229540",
"pm_score": 0,
"selected": false,
"text": "NotificationCenter PM> Install-Package NotificationCenter\n"
}
] | 2009/01/03 | [
"https://Stackoverflow.com/questions/410111",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/44641/"
] |
410,112 | <p>Is it possible to use LINQ in win32 DELPHI applications</p>
| [
{
"answer_id": 410123,
"author": "JaredPar",
"author_id": 23283,
"author_profile": "https://Stackoverflow.com/users/23283",
"pm_score": 2,
"selected": false,
"text": "var query = from it in \"foobar\" select Char.ToUpper(it);\n var query = \"foobar\".Select(x => Char.ToUpper(x));\n"
}
... | 2009/01/03 | [
"https://Stackoverflow.com/questions/410112",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/48705/"
] |
410,127 | <p>I'm the developer of the trash-cli project.</p>
<p>The trash-cli project is a opensource implementation of the FreeDesktop.org
Trash Specification that provides a command line interface to manage the
trashcan.</p>
<p>Ideally trash-cli provides these commands:</p>
<ul>
<li>trash <em>(trashes files and directories)</em></li>
<li>trash-empty <em>(empty the trashcan(s))</em></li>
<li>trash-list <em>(list trashed files)</em></li>
<li>trash-restore <em>(restore a trashed file)</em></li>
</ul>
<p>But I must rename the 'trash' command because the name is too generic to let the trash-cli added in Fedora (see full discussion <a href="https://bugzilla.redhat.com/show_bug.cgi?id=448122" rel="nofollow noreferrer">here</a>)</p>
<p>I chose the 'trash' name because I think is the better name you could use (is short and intuitive), but, as I stated before, I can't use this name.</p>
<p>In any case I think a good choice keep the trash-* form because it exploit the
shell TAB completion.</p>
<p>In the beginning I was persuaded to rename the 'trash' command in 'trash-file' but I don't like it very much, and as Christoph Bloch <a href="https://bugs.launchpad.net/ubuntu/+source/trash-cli/+bug/310088/comments/3" rel="nofollow noreferrer">pointed out</a>:</p>
<blockquote>
<p>My arguments against "trash-file":
* It is not intuitive and therefore unnecessarily difficult to memorise.
* It is unnecessarily long.
* Every change in the name of programs causes confusion, so the new solution
should be a clear improvement (which it isn't).
* It is even wrong: Directories can be trashed, too.</p>
<p>Just "trash" was much better.</p>
</blockquote>
<p>I collected some ideas for renamng the 'trash' command. Would you like help me
to choose the best one? Do you know a better name?</p>
<p>Here the alternatives (some of them are ugly, I know it, but maybe they help you
to find a better name) :</p>
<ul>
<li>trash-put</li>
<li>trash-put-in</li>
<li>trash-trash</li>
<li>trash-throw</li>
<li>trash-f</li>
<li>trash-rm</li>
<li>trash-recycle</li>
<li>trash-do</li>
<li><p>trash-to</p></li>
<li><p>trash-</p></li>
<li>trash-now</li>
<li>trash-!</li>
<li>trash2</li>
<li>trash</li>
<li><p>trashit</p></li>
<li><p>trash-item</p></li>
<li>trash-entry</li>
<li>trash-elem</li>
<li>trash-path</li>
<li><p>trash-data</p></li>
<li><p>trash-this</p></li>
<li>trash-it</li>
<li>trash-that</li>
</ul>
| [
{
"answer_id": 410151,
"author": "slim",
"author_id": 7512,
"author_profile": "https://Stackoverflow.com/users/7512",
"pm_score": 3,
"selected": false,
"text": "tf"
},
{
"answer_id": 410977,
"author": "joel.neely",
"author_id": 3525,
"author_profile": "https://Stackov... | 2009/01/04 | [
"https://Stackoverflow.com/questions/410127",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36131/"
] |
410,146 | <p>One of the advantages of Flash/Flex is that you can use vector graphics (SVG), which is nice. I did a bit of searching around and came across this <a href="http://www.walterzorn.com/jsgraphics/jsgraphics_e.htm" rel="noreferrer">Javascript vector graphics library</a>. It's pretty simple stuff but it got me thinking: is there any possibility of using vector graphics files such as SVG with Javascript/HTML or it just can't be done or done reasonably?</p>
| [
{
"answer_id": 54959999,
"author": "mirageglobe",
"author_id": 154365,
"author_profile": "https://Stackoverflow.com/users/154365",
"pm_score": 0,
"selected": false,
"text": "$ meteor add mirageglobe:snapsvgcdn\n"
}
] | 2009/01/04 | [
"https://Stackoverflow.com/questions/410146",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18393/"
] |
410,150 | <p>I came across a site that demonstrated a Javascript library and it asked that you please not link to the Javascript file directly from your site. That's a reasonable request. In fact, it wouldn't have occurred to me to do that instead of hosting it myself but I guess will try and save on bandwidth any way they can.</p>
<p>This got me thinking: does Apache (in a shared hosting environment) come with any simple means of either preventing this or at least making it a little more difficult by looking at the HTTP_REFERRER or the likes? Or perhaps even just ensuring you have a PHP session?</p>
| [
{
"answer_id": 410168,
"author": "Forrest Marvez",
"author_id": 51237,
"author_profile": "https://Stackoverflow.com/users/51237",
"pm_score": 4,
"selected": true,
"text": "RewriteEngine on\nRewriteCond %{HTTP_REFERER} !^$\nRewriteCond %{HTTP_REFERER} !^http://(www\\.)?yourdomain.com(/)?.... | 2009/01/04 | [
"https://Stackoverflow.com/questions/410150",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18393/"
] |
410,163 | <p>I'm learning Python now because of the Django framework. I have been a Perl programmer for a number of years and I'm so used to Perl's tools. One of the things that I really miss is Perl's CPAN and its tools. Is there anything equivalent in Python? I would like to be able to search, install and maintain Python modules as easy as CPAN. Also, a system that can handle dependencies automatically. I tried to install a module in Python by downloading a zip file from a website, unzipped it, then do:</p>
<p><code>sudo python setup.py install</code></p>
<p>but it's looking for another module. Now, lazy as I am, I don't like chasing dependencies and such, is there an easy way?</p>
| [
{
"answer_id": 653629,
"author": "denis",
"author_id": 86643,
"author_profile": "https://Stackoverflow.com/users/86643",
"pm_score": 2,
"selected": false,
"text": "easy_install easy_install -v -Z package_name | tee date-package.log\n -Z --always-unzip .egg less *.egg/EGG-INFO/requires.... | 2009/01/04 | [
"https://Stackoverflow.com/questions/410163",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31026/"
] |
410,178 | <p>I have once tried to use typed DateSets in a relatively small production application. Initially it looked like a pretty good idea, but turned out to be different. It was pretty fine for some basic tasks, but as soon as something more advanced was required, it's limitations kicked in and it failed miserably. Luckily the project got cancelled, and from now on I try to stick to a proper ORM like NHibernate.</p>
<p>But I still wonder - they were created for a reason. Perhaps I just didn't understand how to use them properly? Is anyone out there successfully using them in production systems?</p>
<p><strong>Added:</strong></p>
<p>Could you also quickly explain how you are using them?</p>
<p>I tried to use them as my DAL - it was a Windows Forms applications, and it would fetch data from tables into the DataSet and then manipulate with the data, before calling the TableManager's hierarchial update thing (don't remember the exact name). The DataSet had one table for each of the DB's physical tables. The problems started when I had to do something like a master/details relationship where I had to insert a bunch of records at once (one master record and several details records) into several tables while also keeping foreign keys correct.</p>
<p><strong>Added 2:</strong></p>
<p>Oh, and if you are using them, where do you put your business logic then? (Validations, calculations, etc.)</p>
| [
{
"answer_id": 410194,
"author": "Ady",
"author_id": 31395,
"author_profile": "https://Stackoverflow.com/users/31395",
"pm_score": 2,
"selected": false,
"text": " oRow[\"row_pk\"] oRow.row_pk"
}
] | 2009/01/04 | [
"https://Stackoverflow.com/questions/410178",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41360/"
] |
410,186 | <p>I have found some info on the subject (<a href="http://rubylearning.com/satishtalim/object_serialization.html" rel="noreferrer">like this link)</a>, but nothing that tells me how it actually works under the covers. If you don't want to read the essay below, here are the real questions:</p>
<ol>
<li><p>How should I implement the <code>marshal_dump</code> and <code>marshal_load</code> methods? even a simple example will do.</p></li>
<li><p>when <code>marshal_load</code> is called, how does it 'know' which type of object to create? If there are multiple objects of the same type in the file, how do you tell which is which? I am obviously confused...</p></li>
<li><p>if I have an object which represents an image, is there a different way to write it out to disk?</p></li>
</ol>
<p><b>My specific problem is this:</b></p>
<p>It is a bit complicated because I do not have the source code for the object I wish to serialize.</p>
<p>I am working on a mod to a game engine (RPG Maker VX using the RGSS2 game library). There is a class called Bitmap which belongs to the (closed source) API. I would like to save this object/image between game plays, so I need to serialize it to the save file. I'm not a ruby pro, but I know that I can define two methods (<code>marshal_dump</code> and <code>marshal_load</code>) which will be called by the "Marshal" module when I attempt to serialize the object.</p>
<p>The problem is that I do not know how to implement the two methods needed. I can actually just leave them as empty methods and it <em>seems</em> to work, but the object is actually disposed and the image data is gone. Besides that, I don't understand what it is doing internally and obviously creating empty methods is just wrong.</p>
<p>So can anyone tell me how this stuff works internally? I think that would help me to solve my problem. Beyond that, is there another type of image format that I can use which I could just save to a file and avoid doing my own serialization?</p>
| [
{
"answer_id": 410290,
"author": "Chuck",
"author_id": 50742,
"author_profile": "https://Stackoverflow.com/users/50742",
"pm_score": 4,
"selected": true,
"text": "marshal_dump marshal_load marshal_load marshal_dump class Messenger\n\n attr_accessor :name, :message\n\n def marshal_dump\... | 2009/01/04 | [
"https://Stackoverflow.com/questions/410186",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1053/"
] |
410,221 | <p>I'd like a way to show natural times for dated items in Python. Similar to how Twitter will show a message from "a moment ago", "a few minutes ago", "two hours ago", "three days ago", etc.</p>
<p>Django 1.0 has a "humanize" method in django.contrib. I'm not using the Django framework, and even if I were, it's more limited than what I'd like.</p>
<p>Please let me (and generations of future searchers) know if there is a good working solution already. Since this is a common enough task, I imagine there must be something. </p>
| [
{
"answer_id": 410482,
"author": "runeh",
"author_id": 2906,
"author_profile": "https://Stackoverflow.com/users/2906",
"pm_score": 5,
"selected": true,
"text": "from datetime import timedelta\nfrom babel.dates import format_timedelta\ndelta = timedelta(days=6)\nformat_timedelta(delta, lo... | 2009/01/04 | [
"https://Stackoverflow.com/questions/410221",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9106/"
] |
410,222 | <p>I know that a lot of examples exist where a SqlConnection is defined and then a SqlCommand is defined, both in Using blocks:</p>
<pre><code>using (var conn = new SqlConnection(connString)) {
using (var cmd = new SqlCommand()) {
cmd.Connection = conn;
//open the connection
}
}
</code></pre>
<p>My question: If I define the connection directly on the SqlCommand, does the connection close when the command is disposed?</p>
<pre><code>using (var cmd = new SqlCommand()) {
cmd.Connection = new SqlConnection(connString);
//open the connection
}
</code></pre>
| [
{
"answer_id": 410237,
"author": "Andrew Hare",
"author_id": 34211,
"author_profile": "https://Stackoverflow.com/users/34211",
"pm_score": 3,
"selected": false,
"text": "using using (var conn = new SqlConnection(connString))\nusing (var cmd = new SqlCommand())\n{\n cmd.Connection = co... | 2009/01/04 | [
"https://Stackoverflow.com/questions/410222",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10104/"
] |
410,224 | <p>How can I go about creating a UITableView with taller cells? Basically, I want to create a full screen table with only four cells, but they should take up the entire screen (1/4 each).</p>
<p>Assuming this is possible using a UITableView, can it be done both in code and in Interface Builder? And also, can each cell have its own height?</p>
<p>--Tim</p>
| [
{
"answer_id": 410585,
"author": "jpm",
"author_id": 35478,
"author_profile": "https://Stackoverflow.com/users/35478",
"pm_score": 3,
"selected": false,
"text": "-tableView:heightForRowAtIndexPath: - (CGFloat)tableView:(UITableView *)tv heightForRowAtIndexPath:(NSIndexPath *)indexPath {\... | 2009/01/04 | [
"https://Stackoverflow.com/questions/410224",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5284/"
] |
410,227 | <p>What is the simplest way of testing if an object implements a given interface in C#? (Answer to this question
<a href="https://stackoverflow.com/questions/766106/test-if-object-implements-interface">in Java</a>)</p>
| [
{
"answer_id": 410230,
"author": "Robert C. Barth",
"author_id": 9209,
"author_profile": "https://Stackoverflow.com/users/9209",
"pm_score": 10,
"selected": true,
"text": "if (object is IBlah)\n IBlah myTest = originalObject as IBlah\n\nif (myTest != null)\n"
},
{
"answer_id": 41... | 2009/01/04 | [
"https://Stackoverflow.com/questions/410227",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23276/"
] |
410,236 | <p>When overriding the equals() function of java.lang.Object, the javadocs suggest that, </p>
<blockquote>
<p>it is generally necessary to override the hashCode method whenever this method is overridden, so as to maintain the general contract for the hashCode method, which states that equal objects must have equal hash codes.</p>
</blockquote>
<p>The hashCode() method must return a <b>unique integer</b> for each object (this is easy to do when comparing objects based on memory location, simply return the <b>unique integer</b> address of the object)</p>
<p>How should a hashCode() method be overriden so that it returns a <b>unique integer</b> for each object based only on that object's properities?</p>
<pre><code>
public class People{
public String name;
public int age;
public int hashCode(){
// How to get a unique integer based on name and age?
}
}
/*******************************/
public class App{
public static void main( String args[] ){
People mike = new People();
People melissa = new People();
mike.name = "mike";
mike.age = 23;
melissa.name = "melissa";
melissa.age = 24;
System.out.println( mike.hasCode() ); // output?
System.out.println( melissa.hashCode(); // output?
}
}
</code></pre>
| [
{
"answer_id": 410246,
"author": "Marc Novakowski",
"author_id": 27020,
"author_profile": "https://Stackoverflow.com/users/27020",
"pm_score": 6,
"selected": true,
"text": "public int hashCode() {\n int result = name != null ? name.hashCode() : 0;\n result = 31 * result + age;\n ... | 2009/01/04 | [
"https://Stackoverflow.com/questions/410236",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/48728/"
] |
410,243 | <p>I have my MySQL database server on Server 1. I want to have my Rails apps on two other servers - say A and B to be able to connect to this Server 1. What's the best way to do this?</p>
<p>In the my.cnf file it appears I can use the bind-address to bind to one and only one IP address. I can't specify the IP addresses of both A and B in my.cnf.</p>
<p>On the other hand, if I comment skip-networking, the gates are wide open. </p>
<p>Is there a golden mean? What are you folks doing to allow a DB server to listen to requests from multiple app servers and still stay secure?</p>
| [
{
"answer_id": 410244,
"author": "Michael Haren",
"author_id": 29,
"author_profile": "https://Stackoverflow.com/users/29",
"pm_score": 2,
"selected": false,
"text": "bind-address port mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('yourpassword');\n"
},
{
"answer_id": 4103... | 2009/01/04 | [
"https://Stackoverflow.com/questions/410243",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
410,253 | <p>We have an embedded device that needs to interact with an enterprise software system. </p>
<p>The enterprise system currently uses many different mechanisms for communication between its components: ODBC, RPC, proprietary protocol over TCP/IP, and is moving to .Net-implmented web services.</p>
<p>The embedded device runs a flavor of *nix, so we're looking at what the best interaction mechanism is.</p>
<p>The requirements for the communication are:
<li> Must run over TCP/IP.
<li> Must also run over RS-232 or USB.
<li> Must be secure (e.g. HTTPS or SSL).
<li> Must be capable of transferring ~32MB of data.
<br>
<br></p>
<p><a href="http://www.cs.fsu.edu/~engelen/soap.html" rel="nofollow noreferrer">Our current best option is gSOAP</a>.</p>
<p>Does anyone out there in SO-land have any other suggestions?</p>
<p><strong>Edit:</strong> Steven's answer gave me the most new pointers. Thanks to all!</p>
| [
{
"answer_id": 410244,
"author": "Michael Haren",
"author_id": 29,
"author_profile": "https://Stackoverflow.com/users/29",
"pm_score": 2,
"selected": false,
"text": "bind-address port mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('yourpassword');\n"
},
{
"answer_id": 4103... | 2009/01/04 | [
"https://Stackoverflow.com/questions/410253",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12570/"
] |
410,270 | <p>Or should you always create some other lock object?</p>
| [
{
"answer_id": 410274,
"author": "Michael Haren",
"author_id": 29,
"author_profile": "https://Stackoverflow.com/users/29",
"pm_score": 5,
"selected": true,
"text": ".SyncRoot Generic.Dictionary<int, int> dic = new Generic.Dictionary<int, int>();\n\nlock (((IDictionary)dic).SyncRoot)\n{\n... | 2009/01/04 | [
"https://Stackoverflow.com/questions/410270",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4653/"
] |
410,278 | <p>There are methods to transfer a CGPoint from one UIView to another and from one CALayer to another. I cannot find a way to change a CGPoint from a UIView's coordinate system to a CALayer's coordinate system. </p>
<p>Does a layer and it's host view have the same coordinate system? Do I need to transform points between them?</p>
<p>Thanks,
Corey</p>
<p>[EDIT]</p>
<p>Thanks for the answer! It is hard to find information on the differences/similarities between CA on the iPhone and Mac. I am surprised I couldn't find this issue addressed directly in any Apple Documentation. </p>
<p>I was pursuing this answer to help with a bug I am troubleshooting, and this was so far my best guess, but I suppose I am barking up the wrong tree. If the coordinate systems are the same, then I have another issue...</p>
<p>The actual issue I am having can be found here on Stack Overflow:
<a href="https://stackoverflow.com/questions/401040/layer-hit-test-only-returning-layer-when-bottom-half-of-layer-is-touched#414024">layer hit test only returning layer when bottom half of layer is touched</a></p>
| [
{
"answer_id": 412098,
"author": "Lily Ballard",
"author_id": 582,
"author_profile": "https://Stackoverflow.com/users/582",
"pm_score": 3,
"selected": true,
"text": "transform contents - (void)viewDidLoad {\n [super viewDidLoad];\n CALayer *rootLayer = [CALayer layer];\n rootLayer.fra... | 2009/01/04 | [
"https://Stackoverflow.com/questions/410278",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/48311/"
] |
410,313 | <p>I would like to render to an offscreen bitmap (or array of RGBA values) and then blit those to a <code>UIView</code> during in the view's <code>drawRect</code> function. I would prefer to do full 32-bit rendering (including alpha channel), but would also be content with 24-bit rendering.</p>
<p>Would anyone mind pointing me in the right direction with some code snippets or relevant APIs?</p>
<p>Also, I know exactly how to do this using OpenGL - I would just prefer to do this work in Core Graphics itself.</p>
| [
{
"answer_id": 657288,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "CGDataProviderCreateWithData CGImageCreate CGImageRef"
},
{
"answer_id": 1962986,
"author": "benzado",
"author... | 2009/01/04 | [
"https://Stackoverflow.com/questions/410313",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/338/"
] |
410,324 | <p>Is there a way I can write text to a file from a certain point in the file?</p>
<p>For example, I open a file of 10 lines of text but I want to write a line of text to the 5th line.</p>
<p>I guess one way is to get the lines of text in the file back as an array using the readalllines method, and then add a line at a certain index in the array.</p>
<p>But there is a distinction in that some collections can only add members to the end and some at any destination. To double check, an array would always allow me to add a value at any index, right? (I'm sure one of my books said other wise).</p>
<p>Also, is there a better way of going about this?</p>
<p>Thanks</p>
| [
{
"answer_id": 410332,
"author": "Charlie Martin",
"author_id": 35092,
"author_profile": "https://Stackoverflow.com/users/35092",
"pm_score": 3,
"selected": true,
"text": "open master file for reading.\ncount := 0\nwhile not EOF do\n read line from master file into buffer\n write l... | 2009/01/04 | [
"https://Stackoverflow.com/questions/410324",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32484/"
] |
410,343 | <p>I have a generic Callback object which provides a (primitive) callback capability for Java, in the absence of closures. The Callback object contains a Method, and returns the parameter and return types for the method via a couple of accessor methods that just delegate to the equivalent methods in Method.</p>
<p>I am trying to validate that a Callback I have been supplied points to a valid method. I need the return type assignment compatible with Number and all parameters to be assignment compatible with Double. My validating method looks like this:</p>
<pre><code>static public void checkFunctionSpec(Callback cbk) {
Class[] prms=cbk.getParmTypes();
Class ret =cbk.getReturnType();
if(!Number.class.isAssignableFrom(ret)) {
throw new IllegalArgumentException(
"A function callback must return a Number type " +
"(any Number object or numeric primitive) - function '" +
cbk + "' is not permitted");
}
for(Class prm: prms) {
if(!Double.class.isAssignableFrom(prm)) {
throw new IllegalArgumentException(
"A function callback must take parameters of " +
"assignment compatible with double " +
"(a Double or Float object or a double or float primitive) " +
"- function '" + cbk + "' is not permitted");
}
}
}
</code></pre>
<p>The problem I encounter is that the when I try this with, e.g. Math.abs(), it's throwing an exception for the return type as follows:</p>
<pre><code>java.lang.IllegalArgumentException:
A function callback must return a Number type (any Number object or numeric primitive)
- function 'public static double java.lang.Math.abs(double)' is not permitted
</code></pre>
<p>This was surprising to me because I expected primitives to simply work because (a) they are reflected using their wrapper classes, and (b) the Double.TYPE is declared to be of type Class<Double>.</p>
<p>Does anyone know how I can achieve this without modifying my checks to be:</p>
<pre><code>if(!Number.class.isAssignableFrom(ret)
&& ret!=Double.TYPE
&& ret!=Float.TYPE
&& ret!=...) {
</code></pre>
<hr>
<h2>Clarification</h2>
<p>When you invoke the method <code>double abs(double)</code> using Method.invoke(), you pass in a Object[]{Double} and get back a Double. However, my validation appears to be failing because Double.TYPE is not assignable to a Double. Since I require all these callbacks to return some sort of number, which will be returned by invoke() as a Number, I am trying to validate that the supplied method returns either Number or a numeric primitive.</p>
<p>Validation of the parms is likewise.</p>
<p>In other words, when using reflection the parm and return types Double and double are identical and I would like to validate them <em>easily</em> as such.</p>
<p>EDIT: To further clarify: I want to validate that a Method will, when invoke() is called return an Object of type Number (from which I can call obj.doubleValue() to get the double I want).</p>
| [
{
"answer_id": 410352,
"author": "Apocalisp",
"author_id": 3434,
"author_profile": "https://Stackoverflow.com/users/3434",
"pm_score": 1,
"selected": false,
"text": "public interface F<A, B> {\n public B $(A a);\n}\n F<Double, Double> F<? extends Number, ? extends Number> F<Double, F<D... | 2009/01/04 | [
"https://Stackoverflow.com/questions/410343",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8946/"
] |
410,355 | <p>I have a model, Thing, that has a has_many with ThingPhoto, using Paperclip to manage everything. On the "show" view for Thing, I want to have a file upload, and have it relate to the Thing model.</p>
<p>For some reason, I'm totally glitching on how this should be done. I've tried doing this (Haml):</p>
<pre><code>- form_for @thing.thing_photos, :html => {:multipart => true} do |f|
= f.file_field :photo
= f.submit
</code></pre>
<p>... and I get this error:</p>
<pre><code>undefined method `array_path' for #<ActionView::Base:0x24d42b4>
</code></pre>
<p>Google is failing me. I'm sure this is super easy, but I just can't get my brain around it.</p>
<p>Edit: I should have mentioned that if I change the @thing.thing_photos to just @thing, it works fine, in that it displays the form, but of course it's not associated with the correct model.</p>
| [
{
"answer_id": 410371,
"author": "zenazn",
"author_id": 46848,
"author_profile": "https://Stackoverflow.com/users/46848",
"pm_score": 0,
"selected": false,
"text": ".first"
},
{
"answer_id": 410503,
"author": "PJ Davis",
"author_id": 39077,
"author_profile": "https://... | 2009/01/04 | [
"https://Stackoverflow.com/questions/410355",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/722/"
] |
410,391 | <p>Okay so a continuation from <a href="https://stackoverflow.com/questions/409913/can-php-be-installed-on-a-local-machine">this question</a>, where you experts intro'd me to <a href="http://www.wampserver.com/en/presentation.php" rel="nofollow noreferrer">WAMP</a>, which can basically execute PHP within a Windows XP environment.</p>
<p>So now I've got it installed, but the <strong>tray icon forever shows YELLOW</strong>, and when I visit any PHP page in my browser, it just shows me the PHP source!</p>
<p>Also, when I visit "<a href="http://localhost/" rel="nofollow noreferrer">http://localhost/</a>" in IE7 it gives me a <strong>404 Not Found</strong>, FF3 just shows a <strong>blank</strong> page.</p>
<hr>
<p>BTW I've tried "Restart All Services" and restarting my machine, but it still won't work.</p>
<p>Any ideas? Any of you had this problem and <strong>solved it?</strong> Please help me here, I'm desperate to execute PHP client-side and I'm just reverting to testing on-server for now!</p>
| [
{
"answer_id": 7176802,
"author": "deepika ",
"author_id": 909788,
"author_profile": "https://Stackoverflow.com/users/909788",
"pm_score": 3,
"selected": false,
"text": "Listen 80 Listen 8080"
},
{
"answer_id": 13766222,
"author": "jchapa",
"author_id": 228353,
"autho... | 2009/01/04 | [
"https://Stackoverflow.com/questions/410391",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41021/"
] |
410,392 | <p>I'm working on a Django-based application in a corporate environment and would like to use the existing Active Directory system for authentication of users (so they don't get yet another login/password combo). I would also like to continue to use Django's user authorization / permission system to manage user capabilities.</p>
<p>Does anyone have a good example of this? </p>
| [
{
"answer_id": 7914309,
"author": "dgorissen",
"author_id": 494572,
"author_profile": "https://Stackoverflow.com/users/494572",
"pm_score": 3,
"selected": false,
"text": "group=Group.objects.get(pk=1)\n group,created=Group.objects.get_or_create(name=\"everyone\")\n ldapsearch -H ldaps://... | 2009/01/04 | [
"https://Stackoverflow.com/questions/410392",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40529/"
] |
410,393 | <p>I want to recomment Git to my boss as a new source control system, since we're stuck in the 90s with VSS (ouch), but are the tools and 3rd party support good enough yet?</p>
<p>Specifically I'm talking about GUI front-ends similar to TortoiseSVN, decent visual diff/merge support, as well as stuff like email commit notifications and general support from 3rd parties like IDEs and build systems.</p>
<p>Even though this will be used by programmers, we really need this kind of stuff in our team. I don't want to leave everyone stuck with a new tool, and even a new source control paradigm (distributed), with nothing but a command-line app and some online tutorials. This would be a step backwards.</p>
<p>So what do you think... is Git ready? What decent tools exist for Git and what third party development apps support it?</p>
<p>EDIT: My original question was pretty vague so I'm updating it to specifically ask for a list of available tools and 3rd party support for Git. Maybe we can get a community wiki post with a list of stuff.</p>
<p>I also do not consider 'use subversion' to be an adequate answer. There are other reasons to use a distributed source control system other than offline editing - private and cheap branches being one of them.</p>
| [
{
"answer_id": 410487,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 5,
"selected": false,
"text": "git-svn"
}
] | 2009/01/04 | [
"https://Stackoverflow.com/questions/410393",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/49658/"
] |
410,396 | <p>Can anybody let me know that what permission does public have in sql server.</p>
<p>Thanks</p>
| [
{
"answer_id": 410425,
"author": "Mitchell Gilman",
"author_id": 43219,
"author_profile": "https://Stackoverflow.com/users/43219",
"pm_score": 4,
"selected": false,
"text": "*"
}
] | 2009/01/04 | [
"https://Stackoverflow.com/questions/410396",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/47957/"
] |
410,411 | <p>I'm writing a sidebar extension for Firefox and need a way to get the URL of the current page so I can check it against a database and display the results. How can I do this?</p>
| [
{
"answer_id": 410915,
"author": "wimh",
"author_id": 33499,
"author_profile": "https://Stackoverflow.com/users/33499",
"pm_score": 5,
"selected": true,
"text": "window.top.getBrowser().selectedBrowser.contentWindow.location.href;\n var mainWindow = window.QueryInterface(Components.inter... | 2009/01/04 | [
"https://Stackoverflow.com/questions/410411",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/51310/"
] |
410,417 | <p>I was looking through my code and I found a couple of extension methods that I wrote in order to remove items from a System.Collections.Generic.Stack. I was curious, so I looked at the source of Stack with Reflector and I can see that they implemented it as an array instead of a linked list and I'm just wondering why? With a linked list there would be no need to resize an internal array...</p>
<p>Here are my extensions, any criticisms or suggestions are welcome. Thanks.</p>
<pre><code>public static Stack<T> Remove<T>(this Stack<T> stack, T item)
{
Stack<T> newStack = new Stack<T>();
EqualityComparer<T> eqc = EqualityComparer<T>.Default;
foreach( T newItem in stack.Reverse() )
{
if( !eqc.Equals(newItem, item) )
{
newStack.Push(newItem);
}
}
return newStack;
}
/// <summary>
/// Returns a new Stack{T} with one or more items removed, based on the given predicate.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="stack"></param>
/// <param name="fnRemove"></param>
/// <returns>The new stack.</returns>
/// <remarks>
/// We have to turn tricks in order to save the LIFO order of the pool
/// since there is no built-in remove method since they implement a Stack internally
/// as an array instead of a linked list. Maybe they have a good reason, I don't know...
///
/// So, to fix this I'm just using a LINQ extension method to enumerate in reverse.
/// </remarks>
public static Stack<T> RemoveWhere<T>(this Stack<T> stack, Predicate<T> fnRemove)
{
Stack<T> newStack = new Stack<T>();
foreach( T newItem in stack.Reverse() )
{
/// Check using the caller's method.
if( fnRemove(newItem) )
{
/// It's not allowed in the new stack.
continue;
}
newStack.Push(newItem);
}
return newStack;
}
</code></pre>
| [
{
"answer_id": 410684,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 4,
"selected": true,
"text": "Stack<byte>"
}
] | 2009/01/04 | [
"https://Stackoverflow.com/questions/410417",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16387/"
] |
410,419 | <p>I need to display text in an iPhone application, something like the way a book is displayed, for example:</p>
<p><h1>Heading</h1>
<h2>Sub heading</h2>
The actual text of the book. Blah. Blah. Blah.</p>
<p><br/>
How would I go about doing that? I've found the UITextView and UITextField and UIScrollView objects, but I can't figure out how to use them properly... Any suggestions?</p>
<p>I hope that makes sense...</p>
| [
{
"answer_id": 411948,
"author": "Lily Ballard",
"author_id": 582,
"author_profile": "https://Stackoverflow.com/users/582",
"pm_score": 1,
"selected": false,
"text": "-sizeToFit"
}
] | 2009/01/04 | [
"https://Stackoverflow.com/questions/410419",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16313/"
] |
410,437 | <p>Does anyone ever use stopwatch benchmarking, or should a performance tool always be used? Are there any good free tools available for Java? What tools do you use?</p>
<p>To clarify my concerns, stopwatch benchmarking is subject to error due to operating system scheduling. On a given run of your program the OS might schedule another process (or several) in the middle of the function you're timing. In Java, things are even a little bit worse if you're trying to time a threaded application, as the JVM scheduler throws even a little bit more randomness into the mix.</p>
<p>How do you address operating system scheduling when benchmarking?</p>
| [
{
"answer_id": 410460,
"author": "Lawrence Dol",
"author_id": 8946,
"author_profile": "https://Stackoverflow.com/users/8946",
"pm_score": 7,
"selected": true,
"text": "System.currentTimeMillis()"
},
{
"answer_id": 475697,
"author": "Peter Lawrey",
"author_id": 57695,
... | 2009/01/04 | [
"https://Stackoverflow.com/questions/410437",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1288/"
] |
410,450 | <p>Archaelus suggested in <a href="https://stackoverflow.com/questions/383407/what-are-some-interesting-projects-to-solve-in-erlang-for-learning-purposes#383456">this post</a> that writing a new format routine to handle named parameters may be a good learning exercise. So, in the spirit of learning the language I wrote a formatting routine which handles named parameters.</p>
<p><br /><br />
<strong>An Example:</strong></p>
<pre><code>1> fout:format("hello ~s{name}, ~p{one}, ~p{two}, ~p{three}~n",[{one,1},{three,3},{name,"Mike"},{two,2}]).
hello Mike, 1, 2, 3
ok
</code></pre>
<p><br /><br /></p>
<p><strong>The Benchmark:</strong></p>
<pre><code>1> timer:tc(fout,benchmark_format_overhead,["hello ~s{name}, ~p{one}, ~p{two}, ~p{three}~n",[{one,1},{name,"Mike"},{three,3},{two,2}],100000]).
{421000,true}
= 4.21us per call
</code></pre>
<p>Although I suspect that much of this overhead is due to looping, as a calling the function with one loop yields a response in < 1us.</p>
<pre><code>1> timer:tc(fout,benchmark_format_overhead,["hello ~s{name}, ~p{one}, ~p{two}, ~p{three}~n",[{one,1},{name,"Mike"},{three,3},{two,2}],1]).
{1,true}
</code></pre>
<p>If there is a better way of benchmarking in erlang, please let me know.</p>
<p><br /><br />
<strong>The Code:</strong>
(which has been revised in accordance with Doug's suggestion)</p>
<pre><code>-module(fout).
-export([format/2,benchmark_format_overhead/3]).
benchmark_format_overhead(_,_,0)->
true;
benchmark_format_overhead(OString,OList,Loops) ->
{FString,FNames}=parse_string(OString,ONames),
benchmark_format_overhead(OString,OList,Loops-1).
format(OString,ONames) ->
{FString,FNames}=parse_string(OString,ONames),
io:format(FString,FNames).
parse_string(FormatString,Names) ->
{F,N}=parse_format(FormatString),
{F,substitute_names(N,Names)}.
parse_format(FS) ->
parse_format(FS,"",[],"").
parse_format("",FormatString,ParamList,"")->
{lists:reverse(FormatString),lists:reverse(ParamList)};
parse_format([${|FS],FormatString,ParamList,"")->
parse_name(FS,FormatString,ParamList,"");
parse_format([$}|_FS],FormatString,_,_) ->
throw({'unmatched } found',lists:reverse(FormatString)});
parse_format([C|FS],FormatString,ParamList,"") ->
parse_format(FS,[C|FormatString],ParamList,"").
parse_name([$}|FS],FormatString,ParamList,ParamName) ->
parse_format(FS,FormatString,[list_to_atom(lists:reverse(ParamName))|ParamList],"");
parse_name([${|_FS],FormatString,_,_) ->
throw({'additional { found',lists:reverse(FormatString)});
parse_name([C|FS],FormatString,ParamList,ParamName) ->
parse_name(FS,FormatString,ParamList,[C|ParamName]).
substitute_names(Positioned,Values) ->
lists:map(fun(CN)->
case lists:keysearch(CN,1,Values) of
false ->
throw({'named parameter not found',CN,Values});
{_,{_,V}} ->
V
end end,
Positioned).
</code></pre>
<p>As this was a learning exercise, I was hoping that those more experienced with erlang could give me tips on how to improve my code.</p>
<p>Cheers,
Mike</p>
| [
{
"answer_id": 410515,
"author": "Doug Currie",
"author_id": 33252,
"author_profile": "https://Stackoverflow.com/users/33252",
"pm_score": 3,
"selected": true,
"text": "parse_in_format ([], FmtStr, ParmStrs, ParmName) -> {FmtStr, ParmStrs};\nparse_in_format ([${ | Vr], FmtStr, ParmStrs, ... | 2009/01/04 | [
"https://Stackoverflow.com/questions/410450",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42050/"
] |
410,469 | <p>I want to spawn another process to display an error message asynchronously while the rest of the application continues. </p>
<p>I'm using the <code>multiprocessing</code> module in Python 2.6 to create the process and I'm trying to display the window with <code>TKinter</code>. </p>
<p>This code worked okay on Windows, but running it on Linux the <code>TKinter</code> window does not appear if I call <code>'showerror("MyApp Error", "Something bad happened.")'</code>. It <em>does</em> appear if I run it in the same process by calling <code>showerrorprocess</code> directly. Given this, it seems <code>TKinter</code> is working properly. I can print to the console and do other things from processes spawned by <code>multiprocessing</code>, so it seems to be working too. </p>
<p>They just don't seem to work together. Do I need to do something special to allow spawned subprocesses to create windows?</p>
<pre><code>from multiprocessing import Process
from Tkinter import Tk, Text, END, BOTH, DISABLED
import sys
import traceback
def showerrorprocess(title,text):
"""Pop up a window with the given title and text. The
text will be selectable (so you can copy it to the
clipboard) but not editable. Returns when the
window is closed."""
root = Tk()
root.title(title)
text_box = Text(root,width=80,height=15)
text_box.pack(fill=BOTH)
text_box.insert(END,text)
text_box.config(state=DISABLED)
def quit():
root.destroy()
root.quit()
root.protocol("WM_DELETE_WINDOW", quit)
root.mainloop()
def showerror(title,text):
"""Pop up a window with the given title and text. The
text will be selectable (so you can copy it to the
clipboard) but not editable. Runs asynchronously in
a new child process."""
process = Process(target=showerrorprocess,args=(title,text))
process.start()
</code></pre>
<hr>
<p><strong>Edit</strong></p>
<p>The issue seems to be that <code>TKinter</code> was imported by the parent process, and "inherited" into the child process, but somehow its state is inextricably linked to the parent process and it cannot work in the child. So long as you make sure not to import <code>TKinter</code> before you spawn the child process, it will work because then it is the child process that is importing it for the first time.</p>
| [
{
"answer_id": 410587,
"author": "Nicholas Leonard",
"author_id": 49985,
"author_profile": "https://Stackoverflow.com/users/49985",
"pm_score": 0,
"selected": false,
"text": "xhost +"
},
{
"answer_id": 434207,
"author": "Malx",
"author_id": 51086,
"author_profile": "h... | 2009/01/04 | [
"https://Stackoverflow.com/questions/410469",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2283/"
] |
410,471 | <p>I have an application where I need to remove one view from the stack of a UINavigationController and replace it with another. The situation is that the first view creates an editable item and then replaces itself with an editor for the item. When I do the obvious solution within the first view:</p>
<pre><code>MyEditViewController *mevc = [[MYEditViewController alloc] initWithGizmo: gizmo];
[self retain];
[self.navigationController popViewControllerAnimated: NO];
[self.navigationController pushViewController: mevc animated: YES];
[self release];
</code></pre>
<p>I get very strange behavior. Usually the editor view will appear, but if I try to use the back button on the nav bar I get extra screens, some blank, and some just screwed up. The title becomes random too. It is like the nav stack is completely hosed.</p>
<p>What would be a better approach to this problem?</p>
<p>Thanks,
Matt</p>
| [
{
"answer_id": 410486,
"author": "diclophis",
"author_id": 32678,
"author_profile": "https://Stackoverflow.com/users/32678",
"pm_score": 1,
"selected": false,
"text": "UINavigationController - (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated\n"
... | 2009/01/04 | [
"https://Stackoverflow.com/questions/410471",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7383/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.