qid int64 4 22.2M | question stringlengths 18 48.3k | answers list | date stringlengths 10 10 | metadata list |
|---|---|---|---|---|
279,473 | <p>currently I have the following code:</p>
<pre><code>String select = qry.substring("select ".length(),qry2.indexOf(" from "));
String[] attrs = select.split(",");
</code></pre>
<p>which works for the most parts but fails if given the following:</p>
<pre><code>qry = "select a,b,c,DATETOSTRING(date_attr_name,'mm/dd/yyyy') from tbl_a";
</code></pre>
<p>what I'm looking for is the regex to feed to String.split() which will hande that situation, and for that matter any other special cases you might be able to think of that I'm missing.</p>
| [
{
"answer_id": 279499,
"author": "VonC",
"author_id": 6309,
"author_profile": "https://Stackoverflow.com/users/6309",
"pm_score": 2,
"selected": true,
"text": "[^,]+\\([^\\)]+\\)|[^,]+,\n"
}
] | 2008/11/10 | [
"https://Stackoverflow.com/questions/279473",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/292/"
] |
279,475 | <p>On a web page that is to be displayed on an iPhone, is there a way to get the number pad to come up when the user taps in the field, instead of the qwerty keypad? </p>
<p><a href="http://www.bennadel.com/blog/1197-Defaulting-To-The-Numeric-Keyboard-On-The-iPhone.htm" rel="nofollow noreferrer">This guy says here's how to do it</a>, but as of 2.0, this "feature" was disabled. </p>
<p>I'm guessing there's some fancy javascript to employ to get around this limitation? </p>
| [
{
"answer_id": 6951937,
"author": "icktoofay",
"author_id": 200291,
"author_profile": "https://Stackoverflow.com/users/200291",
"pm_score": 2,
"selected": false,
"text": "number"
}
] | 2008/11/10 | [
"https://Stackoverflow.com/questions/279475",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21447/"
] |
279,478 | <p>Given a model</p>
<pre><code>class BaseModel < ActiveRecord::Base
validates_presence_of :parent_id
before_save :frobnicate_widgets
end
</code></pre>
<p>and a derived model (the underlying database table has a <code>type</code> field - this is simple rails STI)</p>
<pre><code>class DerivedModel < BaseModel
end
</code></pre>
<p><code>DerivedModel</code> will in good OO fashion inherit all the behaviour from <code>BaseModel</code>, including the <code>validates_presence_of :parent_id</code>. I would like to turn the validation off for <code>DerivedModel</code>, and prevent the callback methods from firing, preferably without modifying or otherwise breaking <code>BaseModel</code></p>
<p>What's the easiest and most robust way to do this?</p>
| [
{
"answer_id": 279584,
"author": "Orion Edwards",
"author_id": 234,
"author_profile": "https://Stackoverflow.com/users/234",
"pm_score": 2,
"selected": false,
"text": "before_validation_on_create"
},
{
"answer_id": 279591,
"author": "Orion Edwards",
"author_id": 234,
... | 2008/11/10 | [
"https://Stackoverflow.com/questions/279478",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/234/"
] |
279,491 | <p>I'm experiencing some problems with CSS and/or tables on my newly redesigned <a href="http://www.artinthepicture.com" rel="nofollow noreferrer">website</a>. Because of the well known "100% div height"-issue, I have resorted to using tables as a structural element of the website. So it looks something like this:</p>
<p>HTML MARKUP:</p>
<pre><code><div id="header">...</div>
<table>
<tr>
<td><div id="main">...</div></td>
<td class="crighttd"><div id="cright">...</div></td>
</tr>
</table>
<div id="footer">...</div>
</code></pre>
<p>AND CORRESPONDING CSS</p>
<pre><code>table {
border-top: 1px solid #6A6A6A;
padding: 0;
margin-top: 20px;
border-spacing: 0
}
td {
vertical-align: top;
padding:0;
margin:0
}
.crighttd {
background: #4F4F4F;
vertical-align:top;
margin: 0
}
#cright {
width: 185px;
float: right;
background: #4F4F4F;
height: 100%;
line-height: 1.2em;
margin: 0;
padding: 25px 0 25px 20px;
}
</code></pre>
<p>The issue here is that apparently the td on the right will not display at all in certain browsers (have seen this on Mac as well as on old instances of IE). Is this a CSS problem or something with the tables ?</p>
| [
{
"answer_id": 279517,
"author": "Kyle Trauberman",
"author_id": 21461,
"author_profile": "https://Stackoverflow.com/users/21461",
"pm_score": 0,
"selected": false,
"text": "border: 1px solid red;\n"
},
{
"answer_id": 279518,
"author": "Konrad Rudolph",
"author_id": 1968,... | 2008/11/10 | [
"https://Stackoverflow.com/questions/279491",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
279,493 | <p>What is the way to avoid phpunit having to call the constructor for a mock object? Otherwise I would need a mock object as constructor argument, another one for that etc. The api seems to be like this:</p>
<pre><code>getMock($className, $methods = array(), array $arguments = array(),
$mockClassName = '', $callOriginalConstructor = TRUE,
$callOriginalClone = TRUE, $callAutoload = TRUE)
</code></pre>
<p>I don't get it to work. It still complains about the constructor argument, even with <code>$callOriginalConstructor</code> set to false.</p>
<p>I only have one object in the constructor and it is a dependency injection. So I don't think I have a design problem there.</p>
| [
{
"answer_id": 628308,
"author": "Matthew Purdon",
"author_id": 75873,
"author_profile": "https://Stackoverflow.com/users/75873",
"pm_score": 5,
"selected": false,
"text": " // Get a Mock Soap Client object to work with.\n $classToMock = 'SoapClient';\n $methodsToMock = array('_... | 2008/11/10 | [
"https://Stackoverflow.com/questions/279493",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
279,495 | <p>This is a C# console application. I have a function that does something like this:</p>
<pre><code>static void foo()
{
Application powerpointApp;
Presentation presentation = null;
powerpointApp = new Microsoft.Office.Interop.PowerPoint.ApplicationClass();
}
</code></pre>
<p>That's all it does. When it is called there is a fifteen second delay before the function gets hit. I added something like this:</p>
<pre><code>static void MyAssemblyLoadEventHandler(object sender, AssemblyLoadEventArgs args)
{
Console.WriteLine(DateTime.Now.ToString() + " ASSEMBLY LOADED: " + args.LoadedAssembly.FullName);
Console.WriteLine();
}
</code></pre>
<p>This gets fired telling me that my interop assemblies have been loaded about 10 milliseconds before my foo function gets hit. What can I do about this? The program needs to call this function (and eventually do something else) once and then exit so I need for these assemblies to be cached or something. Ideas?</p>
| [
{
"answer_id": 2505375,
"author": "Anonymous Type",
"author_id": 141720,
"author_profile": "https://Stackoverflow.com/users/141720",
"pm_score": 1,
"selected": false,
"text": "<runtime>\n\n <generatePublisherEvidence enabled=\"false\"/>\n\n</runtime>\n"
}
] | 2008/11/10 | [
"https://Stackoverflow.com/questions/279495",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12261/"
] |
279,500 | <p>I have a program that I need to run under *nix and windows. because the program takes file paths from files the issue is what to do about the <code>\</code> vs <code>/</code> issue. </p>
<p>My current thought is to put in a regex that converts the wrong one to the right one depending on what system I'm on. This will have the effect of letting either type work on either system. Aside from the fact that <a href="http://fishbowl.pastiche.org/2003/08/18/beware_regular_expressions/" rel="nofollow noreferrer">now I have two problems</a>, does anyone see any other problems?</p>
<p>(Other better solutions are more than welcome)</p>
<p>Edit: the primary issue is getting windows paths to work on unix rather than the other way around.</p>
| [
{
"answer_id": 279511,
"author": "Dillie-O",
"author_id": 71,
"author_profile": "https://Stackoverflow.com/users/71",
"pm_score": 1,
"selected": false,
"text": "LoadApplicationData(FileManager.GetDataFilePath)\n"
}
] | 2008/11/10 | [
"https://Stackoverflow.com/questions/279500",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1343/"
] |
279,507 | <p>This could be the dumbest question ever asked but I think it is quite confusing for a Java newbie. </p>
<ol>
<li>Can somebody clarify what is meant by <em>immutable</em>? </li>
<li>Why is a <code>String</code> immutable?</li>
<li>What are the advantages/disadvantages of the immutable objects?</li>
<li>Why should a mutable object such as <code>StringBuilder</code> be preferred over String and vice-verse?</li>
</ol>
<p>A nice example (in Java) will be really appreciated.</p>
| [
{
"answer_id": 279515,
"author": "eishay",
"author_id": 16201,
"author_profile": "https://Stackoverflow.com/users/16201",
"pm_score": 2,
"selected": false,
"text": "String"
},
{
"answer_id": 279516,
"author": "Georgy Bolyuba",
"author_id": 4052,
"author_profile": "htt... | 2008/11/10 | [
"https://Stackoverflow.com/questions/279507",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33203/"
] |
279,523 | <p>I have written an installation class that extends Installer and overrides afterInstall, but I'm getting a null pointer exception. How can I go about debugging my class?</p>
| [
{
"answer_id": 280161,
"author": "stephbu",
"author_id": 12702,
"author_profile": "https://Stackoverflow.com/users/12702",
"pm_score": 6,
"selected": false,
"text": "System.Diagnostics.Debugger.Break()\n"
},
{
"answer_id": 2702598,
"author": "Timex",
"author_id": 179333,
... | 2008/11/10 | [
"https://Stackoverflow.com/questions/279523",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16684/"
] |
279,524 | <p>I have a class that maintans a reference to a Hashtable and serializes/deserializes that Hashtable. After the call to SerializationInfo.GetValue, the Hashtable is not fully deserialized because the deserialization happens during the IDeserialization calback.</p>
<pre><code>Hashtable hashtable = (Hashtable) info.GetValue("hash", typeof(Hashtable));
</code></pre>
<p>I also implemented the IDeserialization callback in the parent class, but there too the Hashtable is not fully deserialized yet. I expected it to be if the deserialization is happening from the inside out.</p>
<p>My question is, is it safe to explicitely call Hashtable.OnDeserialization from the OnDeserialization method of my parent class, so that I can enumerate it at that point?</p>
<pre><code>public virtual void OnDeserialization(object sender)
{
hashtable.OnDeserialization(sender);
}
</code></pre>
| [
{
"answer_id": 287887,
"author": "Brian Adams",
"author_id": 32992,
"author_profile": "https://Stackoverflow.com/users/32992",
"pm_score": 2,
"selected": false,
"text": "public BoringClass(SerializationInfo info, StreamingContext context)\n{\n Hashtable hashtable = (Hashtable) info.Ge... | 2008/11/10 | [
"https://Stackoverflow.com/questions/279524",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36373/"
] |
279,534 | <p>Once a programmer decides to implement <code>IXmlSerializable</code>, what are the rules and best practices for implementing it? I've heard that <code>GetSchema()</code> should return <code>null</code> and <code>ReadXml</code> should move to the next element before returning. Is this true? And what about <code>WriteXml</code> - should it write a root element for the object or is it assumed that the root is already written? How should child objects be treated and written?</p>
<p>Here's a sample of what I have now. I'll update it as I get good responses.</p>
<pre><code>public class MyCalendar : IXmlSerializable
{
private string _name;
private bool _enabled;
private Color _color;
private List<MyEvent> _events = new List<MyEvent>();
public XmlSchema GetSchema() { return null; }
public void ReadXml(XmlReader reader)
{
if (reader.MoveToContent() == XmlNodeType.Element && reader.LocalName == "MyCalendar")
{
_name = reader["Name"];
_enabled = Boolean.Parse(reader["Enabled"]);
_color = Color.FromArgb(Int32.Parse(reader["Color"]));
if (reader.ReadToDescendant("MyEvent"))
{
while (reader.MoveToContent() == XmlNodeType.Element && reader.LocalName == "MyEvent")
{
MyEvent evt = new MyEvent();
evt.ReadXml(reader);
_events.Add(evt);
}
}
reader.Read();
}
}
public void WriteXml(XmlWriter writer)
{
writer.WriteAttributeString("Name", _name);
writer.WriteAttributeString("Enabled", _enabled.ToString());
writer.WriteAttributeString("Color", _color.ToArgb().ToString());
foreach (MyEvent evt in _events)
{
writer.WriteStartElement("MyEvent");
evt.WriteXml(writer);
writer.WriteEndElement();
}
}
}
public class MyEvent : IXmlSerializable
{
private string _title;
private DateTime _start;
private DateTime _stop;
public XmlSchema GetSchema() { return null; }
public void ReadXml(XmlReader reader)
{
if (reader.MoveToContent() == XmlNodeType.Element && reader.LocalName == "MyEvent")
{
_title = reader["Title"];
_start = DateTime.FromBinary(Int64.Parse(reader["Start"]));
_stop = DateTime.FromBinary(Int64.Parse(reader["Stop"]));
reader.Read();
}
}
public void WriteXml(XmlWriter writer)
{
writer.WriteAttributeString("Title", _title);
writer.WriteAttributeString("Start", _start.ToBinary().ToString());
writer.WriteAttributeString("Stop", _stop.ToBinary().ToString());
}
}
</code></pre>
<p>Corresponding Sample XML</p>
<pre><code><MyCalendar Name="Master Plan" Enabled="True" Color="-14069085">
<MyEvent Title="Write Code" Start="-8589241828854775808" Stop="-8589241756854775808" />
<MyEvent Title="???" Start="-8589241828854775808" Stop="-8589241756854775808" />
<MyEvent Title="Profit!" Start="-8589247048854775808" Stop="-8589246976854775808" />
</MyCalendar>
</code></pre>
| [
{
"answer_id": 280077,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 8,
"selected": true,
"text": "Read()"
},
{
"answer_id": 2665097,
"author": "EMP",
"author_id": 20336,
"author_profile": "https:/... | 2008/11/10 | [
"https://Stackoverflow.com/questions/279534",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12971/"
] |
279,546 | <p>How could you calculate the minimum width needed to display a string in X lines, given that text should break on whitespace?</p>
| [
{
"answer_id": 279654,
"author": "John Lemp",
"author_id": 12915,
"author_profile": "https://Stackoverflow.com/users/12915",
"pm_score": 0,
"selected": false,
"text": "public SizeF CalculateWidth(Font font, Graphics graphics, int numOfLines,\n string text)\n{\n... | 2008/11/10 | [
"https://Stackoverflow.com/questions/279546",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4066/"
] |
279,552 | <p>I am using the Ajax Control Toolkit Calendar Extender control. In some fields though I want to display the time along with the date. I have tried just setting the Format to "dd/MM/yyyy hh:mm:ss" but the time section gets wiped off. If the user wants to change the time section they can do it manually, the calendar drop down is only used for changing the date part. </p>
<p>Are there any workarounds or alternatives to get this working? </p>
| [
{
"answer_id": 18371967,
"author": "Rajkumar",
"author_id": 2705954,
"author_profile": "https://Stackoverflow.com/users/2705954",
"pm_score": 1,
"selected": false,
"text": " function dateselect(ev)\n {\n var calendarBehavior1 = $find(\"Calendar1\");\n var d = calendar... | 2008/11/10 | [
"https://Stackoverflow.com/questions/279552",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27294/"
] |
279,557 | <p>WPF GridSplitter makes my Grid wider than my Window!</p>
<p>I've got a WPF Grid with a GridSplitter. If I resize my columns, then I can make my grid wider than my window and non-viewable.</p>
<p>It starts like this: </p>
<p><a href="http://img201.imageshack.us/img201/9505/onehg6.jpg" rel="nofollow noreferrer">WPF Grid http://img201.imageshack.us/img201/9505/onehg6.jpg</a></p>
<p>But after widening the left column, I can no longer see the right column (green): </p>
<p><a href="http://img201.imageshack.us/img201/1804/twomy6.jpg" rel="nofollow noreferrer">WPF GridSplitter http://img201.imageshack.us/img201/1804/twomy6.jpg</a></p>
<p>What am I doing wrong? How do I keep the GridSplitter from changing the size of my Grid?</p>
<hr>
<p>Update:</p>
<p>I'm still struggling with this. I've now tried nesting grids within grids. That didn't help. Here's my XAML ColumnDefinitions, RowDefinitions, and GridSplitters...</p>
<pre><code><Window ... >
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" MinWidth="150" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" MinWidth="400" />
</Grid.ColumnDefinitions>
<GridSplitter
ResizeDirection="Columns"
ResizeBehavior="BasedOnAlignment"
Grid.Column="1"
HorizontalAlignment="Center"
VerticalAlignment="Stretch"
Width="2"
Margin="0,5,0,5"
Panel.ZIndex="1"/>
<Grid Grid.Column="0">
...
</Grid>
<Grid Grid.Column="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" MinWidth="150" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" MinWidth="200" />
</Grid.ColumnDefinitions>
<GridSplitter
ResizeDirection="Columns"
ResizeBehavior="PreviousAndNext"
Grid.Column="1"
HorizontalAlignment="Center"
VerticalAlignment="Stretch"
Width="2"
Margin="0,5,0,5"
Panel.ZIndex="1"/>
<Grid Grid.Column="0">
...
</Grid>
<Grid Grid.Column="2">
...
</Grid>
</Grid>
</Grid>
</Window>
</code></pre>
<hr>
<p>Update:</p>
<p>I think the problem is with the WebBrowser control. See new question:</p>
<p><a href="https://stackoverflow.com/questions/375841/wpf-gridsplitter-doesnt-work-with-webbrowser-control">WPF GridSplitter Doesn't Work With WebBrowser Control?</a></p>
| [
{
"answer_id": 281317,
"author": "Abe Heidebrecht",
"author_id": 9268,
"author_profile": "https://Stackoverflow.com/users/9268",
"pm_score": 3,
"selected": false,
"text": "<Grid>\n <Grid.ColumnDefinitions>\n <ColumnDefinition Width=\"2*\" MinWidth=\"100\" />\n <ColumnDef... | 2008/11/10 | [
"https://Stackoverflow.com/questions/279557",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/83/"
] |
279,561 | <p>What is the idiomatic Python equivalent of this C/C++ code?</p>
<pre class="lang-cpp prettyprint-override"><code>void foo()
{
static int counter = 0;
counter++;
printf("counter is %d\n", counter);
}
</code></pre>
<p>specifically, how does one implement the static member at the function level, as opposed to the class level? And does placing the function into a class change anything?</p>
| [
{
"answer_id": 279568,
"author": "gnud",
"author_id": 27204,
"author_profile": "https://Stackoverflow.com/users/27204",
"pm_score": 4,
"selected": false,
"text": "def foo_gen():\n n = 0\n while True:\n n+=1\n yield n\n"
},
{
"answer_id": 279586,
"author": ... | 2008/11/10 | [
"https://Stackoverflow.com/questions/279561",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10569/"
] |
279,572 | <p>I have a database where one of the common queries is has a "where blobCol is null", I think that this is getting bad performance (as in a full table scan). I have no need to index the contents of the blobCol. </p>
<p>What indexes would improve this? Can an index be built on an expression (blobCol is not null) rather than just a column?</p>
| [
{
"answer_id": 279580,
"author": "Vinko Vrsalovic",
"author_id": 5190,
"author_profile": "https://Stackoverflow.com/users/5190",
"pm_score": 3,
"selected": true,
"text": "CREATE INDEX notNullblob ON myTable (blobCol is not NULL);\n"
}
] | 2008/11/10 | [
"https://Stackoverflow.com/questions/279572",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1343/"
] |
279,575 | <p>HI All,</p>
<p>I have a piece of javaScript that removes commas from a provided string (in my case currency values)</p>
<p>It is:</p>
<pre><code> function replaceCommaInCurrency(myField, val)
{
var re = /,/g;
document.net1003Form.myField.value=val.replace(re, '');
}
</code></pre>
<p>'MyField' was my attempt to dynamically have this work on any field that I pass in, but it doesn't work, I get errors saying 'MyField' is not valid. I sort of get my, but I thought this was valid.</p>
<p>I am calling by using: onBlur="replaceCommaInCurrency(this.name, this.value);return false;"</p>
<p>this.name and this.value are passing in the right values...field name and its value.</p>
<p>How do I do this dynamically?</p>
<p>-Jason</p>
| [
{
"answer_id": 279604,
"author": "flatline",
"author_id": 20846,
"author_profile": "https://Stackoverflow.com/users/20846",
"pm_score": 2,
"selected": false,
"text": "myField.value = myField.value.replace(re, '');\n"
},
{
"answer_id": 279607,
"author": "MrKurt",
"author_i... | 2008/11/10 | [
"https://Stackoverflow.com/questions/279575",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
279,583 | <p>I have a very basic app that I believe should change the width of an image, but it does nothing... can anyone tell me why, when I click on the image, nothing happens to the image? </p>
<p><em>(note, the image itself doesnt really matter, Im just trying to figure out how to shrink and grow and image in JavaFX)</em></p>
<pre><code>import javafx.application.Frame;
import javafx.application.Stage;
import javafx.scene.image.ImageView;
import javafx.scene.image.Image;
import javafx.input.MouseEvent;
var w:Number = 250;
Frame {
title: "Image View Sample"
width: 500
height: 500
closeAction: function() {
java.lang.System.exit( 0 );
}
visible: true
stage: Stage {
content: [
ImageView {
x: 200;
y: 200;
image: Image {
url: "{__DIR__}/c1.png"
width: bind w;
}
onMouseClicked: function( e: MouseEvent ):Void {
w = 100;
}
}
]
}
}
</code></pre>
<p>Thanks heaps!</p>
| [
{
"answer_id": 279604,
"author": "flatline",
"author_id": 20846,
"author_profile": "https://Stackoverflow.com/users/20846",
"pm_score": 2,
"selected": false,
"text": "myField.value = myField.value.replace(re, '');\n"
},
{
"answer_id": 279607,
"author": "MrKurt",
"author_i... | 2008/11/10 | [
"https://Stackoverflow.com/questions/279583",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26310/"
] |
279,601 | <p>I have a <code>vector</code> that I want to insert into a <code>set</code>. This is one of three different calls (the other two are more complex, involving <code>boost::lambda::if_()</code>), but solving this simple case will help me solve the others.</p>
<pre><code>std::vector<std::string> s_vector;
std::set<std::string> s_set;
std::for_each(s_vector.begin(), s_vector.end(), s_set.insert(boost::lambda::_1));
</code></pre>
<p>Unfortunately, this fails with a conversion error message (trying to convert <code>boost::lambda::placeholder1_type</code> to <code>std::string</code>).</p>
<p>So... what's wrong with this?</p>
| [
{
"answer_id": 279649,
"author": "Ferruccio",
"author_id": 4086,
"author_profile": "https://Stackoverflow.com/users/4086",
"pm_score": 1,
"selected": false,
"text": "for_each()"
},
{
"answer_id": 279677,
"author": "Austin Ziegler",
"author_id": 36378,
"author_profile"... | 2008/11/10 | [
"https://Stackoverflow.com/questions/279601",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36378/"
] |
279,610 | <p>I want to create a history table to track field changes across a number of tables in DB2. </p>
<p>I know history is usually done with copying an entire table's structure and giving it a suffixed name (e.g. user --> user_history). Then you can use a pretty simple trigger to copy the old record into the history table on an UPDATE.</p>
<p>However, for my application this would use too much space. It doesn't seem like a good idea (to me at least) to copy an entire record to another table every time a field changes. So I thought I could have a generic 'history' table which would track individual field changes:</p>
<pre><code>CREATE TABLE history
(
history_id LONG GENERATED ALWAYS AS IDENTITY,
record_id INTEGER NOT NULL,
table_name VARCHAR(32) NOT NULL,
field_name VARCHAR(64) NOT NULL,
field_value VARCHAR(1024),
change_time TIMESTAMP,
PRIMARY KEY (history_id)
);
</code></pre>
<p>OK, so every table that I want to track has a single, auto-generated id field as the primary key, which would be put into the 'record_id' field. And the maximum VARCHAR size in the tables is 1024. Obviously if a non-VARCHAR field changes, it would have to be converted into a VARCHAR before inserting the record into the history table.</p>
<p>Now, this could be a completely retarded way to do things (hey, let me know why if it is), but I think it it's a good way of tracking changes that need to be pulled up rarely and need to be stored for a significant amount of time. </p>
<p>Anyway, I need help with writing the trigger to add records to the history table on an update. Let's for example take a hypothetical user table:</p>
<pre><code>CREATE TABLE user
(
user_id INTEGER GENERATED ALWAYS AS IDENTITY,
username VARCHAR(32) NOT NULL,
first_name VARCHAR(64) NOT NULL,
last_name VARCHAR(64) NOT NULL,
email_address VARCHAR(256) NOT NULL
PRIMARY KEY(user_id)
);
</code></pre>
<p>So, can anyone help me with a trigger on an update of the user table to insert the changes into the history table? My guess is that some procedural SQL will need to be used to loop through the fields in the old record, compare them with the fields in the new record and if they don't match, then add a new entry into the history table. </p>
<p>It'd be preferable to use the same trigger action SQL for every table, regardless of its fields, if it's possible.</p>
<p>Thanks!</p>
| [
{
"answer_id": 279649,
"author": "Ferruccio",
"author_id": 4086,
"author_profile": "https://Stackoverflow.com/users/4086",
"pm_score": 1,
"selected": false,
"text": "for_each()"
},
{
"answer_id": 279677,
"author": "Austin Ziegler",
"author_id": 36378,
"author_profile"... | 2008/11/10 | [
"https://Stackoverflow.com/questions/279610",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
279,615 | <p>I've got an NSArrayController, and I'm using KVO to observe the Old/New values of it's selection method.</p>
<p>This works perfectly (triggers when the selection changes, the usual) except that the items in the change dictionary are all null instead of being the old/new selected object. [arrayController selection] still returns the proper object, but I'd like to be able to access the previously selected object as well if possible (my workaround will probably be to observe the selected index instead and see if that works).</p>
<p>The only possible reason for this I've come up with is perhaps it's because the NSArrayController is a proxy object.</p>
<p>So is this the expected behavior, or is something weird going on?</p>
<p>EDIT: I tried observing just the Indexes, but that didn't work either. Both old and new keys still show up as null.</p>
| [
{
"answer_id": 1220907,
"author": "Tom Dalling",
"author_id": 108105,
"author_profile": "https://Stackoverflow.com/users/108105",
"pm_score": 0,
"selected": false,
"text": "NSKeyValueObservingOptionNew"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/279615",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1512/"
] |
279,631 | <p>I'm trying to load an external swf movie then adding the ability to drag it around the stage, however whenever I try to do this I just hit a dead end. Are there any limitations on what you can set be draggable or clickable? An example of what I'm doing is below:</p>
<pre><code>public function loadSwf(url:String, swfUniqueName:String)
{
var ldr:Loader = new Loader();
var url:String = "Swfs/Label.swf";
var urlReq:URLRequest = new URLRequest(url);
ldr.load(urlReq);
ldr.contentLoaderInfo.addEventListener("complete", loadCompleteHandler);
}
private function loadCompleteHandler(event):void{
var ldr = event.currentTarget;
// These are only here because I can't seem to get the drag to work
ldr.content.doubleClickEnabled = true;
ldr.content.buttonMode = true;
ldr.content.useHandCursor = true;
ldr.content.mouseEnabled = true;
ldr.content.txtLabel.mouseEnabled = true;
this.addChild(ldr.content);
ldr.content.addEventListener(MouseEvent.MOUSE_DOWN, mouse_down);
}
mouse_down = function(event) {
trace(event.target);
}
</code></pre>
<p>Using the code above i can only get it to recognise a click on the movie itself if it is over a click on the textfield, but this really needs to work on any part of the movie. Any ideas?</p>
| [
{
"answer_id": 282050,
"author": "Iain",
"author_id": 11911,
"author_profile": "https://Stackoverflow.com/users/11911",
"pm_score": 2,
"selected": false,
"text": "ldr.content.mouseChildren = false;"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/279631",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26081/"
] |
279,634 | <p>I have this piece of Javascript and it just won't work. I allready checked JSlint but that said everything works. Still doesn't work. The javascript is located not in the HTML but is linked in the <code><head></code></p>
<p>note: I am working with a local server, so pageload in instant.</p>
<pre><code>function changeVisibility() {
var a = document.getElementById('invisible');
a.style.display = 'block';
}
var changed = document.getElementById('click1');
changed.onchange = changeVisibility;
</code></pre>
<p>This here is the corresponding HTML</p>
<pre><code><input type="file" name="click[]" size="35" id="click1" />
<div id="invisible" style="display: none;">
<a href="javascript:addFileInput();">Attach another File</a>
</div>
</code></pre>
<p>So what happens is I click on the input, select a file and approve. Then then onchange event triggers and the style of my invisible div is set to block.</p>
<p>Problem is, I keep getting this error:</p>
<p>"changed is null:
changed.onchange = changeVisibility;"</p>
<p>i don't get it, I seriously don't get what I'm overlooking here.</p>
<hr>
<p>EDIT: question answered, thank you Mercutio for your help and everyone else too of course.
Final code: </p>
<pre><code>function loadEvents() {
var changed = document.getElementById('click1');
var a = document.getElementById('invisible');
document.getElementById('addField').onclick = addFileInput;
changed.onchange = function() {
a.style.display = 'block';
}
}
if (document.getElementById) window.onload = loadEvents;
</code></pre>
<p>This here is the corresponding HTML:</p>
<pre><code><input type="file" name="click[]" size="35" id="click1" />
<div id="invisible" style="display: none;">
<a href="#">Attach another File</a>
</div>
</code></pre>
<p>Also, thanks for the link to <a href="http://www.jsbin.com" rel="nofollow noreferrer">JSbin</a>, didn't know about that, looks nifty. </p>
| [
{
"answer_id": 279637,
"author": "mercutio",
"author_id": 1951,
"author_profile": "https://Stackoverflow.com/users/1951",
"pm_score": 4,
"selected": true,
"text": "document.getElementById('addField').onclick = addFileInput;\n"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/279634",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11795/"
] |
279,655 | <p>I need some help with what is probably a newbie question in terms of modifying phpBB.</p>
<p>I have a whole system developed in PHP, and I would like to integrate phpBB so that people can navigate into the forums and post seamlessly, without logging in again.</p>
<p>Now, using the phpBB users table as the users table for my system (and having people register in phpBB instead of in my website) is not possible unfortunately (it'd take more work to redo our system than to build our own basic forum).<br>
I'm assuming I can hack my way into making phpBB believe that a certain user ID has logged in, however, that user won't exist in phpBB's users table (which I'm assuming will cause it to error out pretty much everywhere).</p>
<p>All the tutorials and forum posts I could find implied having phpBB as the primary. I couldn't find anything to do it the other way around.</p>
<p>I'm guessing the only possible way to solve this is by having both tables relatively synchronized.</p>
<p>Now, provided that I can have both users table synchronized, what is the best way to integrate both sites, keeping my site's login and users table as the "primary" ones?<br>
Also, is there anything in particular I should keep in mind when creating records in phpBB's users table? Or is it relatively straightforward to figure out? What tables should I be writing to, if there is more than one?</p>
| [
{
"answer_id": 282181,
"author": "Murat Ayfer",
"author_id": 25910,
"author_profile": "https://Stackoverflow.com/users/25910",
"pm_score": 3,
"selected": false,
"text": "profile_fields"
},
{
"answer_id": 423604,
"author": "Community",
"author_id": -1,
"author_profile"... | 2008/11/11 | [
"https://Stackoverflow.com/questions/279655",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3314/"
] |
279,665 | <p>How can I return the result of a different action or move the user to a different action if there is an error in my <code>ModelState</code> without losing my <code>ModelState</code> information?</p>
<p>The scenario is; <code>Delete</code> action accepts a POST from a DELETE form rendered by my <code>Index</code> Action/View. If there is an error in the <code>Delete</code> I want to move the user back to the <code>Index</code> Action/View and show the errors that are stored by the <code>Delete</code> action in the <code>ViewData.ModelState</code>. How can this be done in ASP.NET MVC?</p>
<pre><code>[AcceptVerbs(HttpVerbs.Post | HttpVerbs.Delete)]
public ActionResult Delete([ModelBinder(typeof(RdfUriBinder))] RdfUri graphUri)
{
if (!ModelState.IsValid)
return Index(); //this needs to be replaced with something that works :)
return RedirectToAction("Index");
}
</code></pre>
| [
{
"answer_id": 279680,
"author": "Ty.",
"author_id": 16948,
"author_profile": "https://Stackoverflow.com/users/16948",
"pm_score": -1,
"selected": false,
"text": "return View(\"Index\");\n"
},
{
"answer_id": 279740,
"author": "tvanfosson",
"author_id": 12950,
"author_... | 2008/11/11 | [
"https://Stackoverflow.com/questions/279665",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3957/"
] |
279,673 | <p>I wonder if it's possible to save all files in a Visual Studio 2008 project into a specific character encoding. I got a solution with mixed encodings and I want to make them all the same (UTF-8 with signature).</p>
<p>I know how to save single files, but how about all files in a project?</p>
| [
{
"answer_id": 280325,
"author": "Martin v. Löwis",
"author_id": 33006,
"author_profile": "https://Stackoverflow.com/users/33006",
"pm_score": 3,
"selected": false,
"text": "import glob, codecs\n\nfor f in glob.glob(\"*.py\"):\n data = open(\"f\", \"rb\").read()\n if data.startswit... | 2008/11/11 | [
"https://Stackoverflow.com/questions/279673",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33349/"
] |
279,693 | <p>I'm new to cryptography and modular arithmetic. So, I'm sure it's a silly question, but I can't help it. </p>
<p>How do I calculate <em>a</em> from <br>
pow(<em>a</em>,<strong>q</strong>) = 1 (mod <strong>p</strong>), <br>
where <strong>p</strong> and <strong>q</strong> are known? I don't get the "1 (mod <strong>p</strong>)" part, it equals to 1, doesn't it? If so, than what is "mod <strong>p</strong>" about? <br>
Is this the same as <br>
pow(<em>a</em>,<strong>-q</strong>) (mod <strong>p</strong>) = 1?</p>
| [
{
"answer_id": 279700,
"author": "Adam Liss",
"author_id": 29157,
"author_profile": "https://Stackoverflow.com/users/29157",
"pm_score": 3,
"selected": false,
"text": "p"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/279693",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24622/"
] |
279,696 | <p>Still struggling to understand what best practices are with respect to macros. I'm attempting to write a macro which defines packages on the fly.</p>
<pre><code>(defmacro def-dynamic-package (name)
`(defpackage ,(intern (string-upcase name) "KEYWORD")
(:use :common-lisp)))
</code></pre>
<p>This works fine only for expressions such as:</p>
<pre><code>(def-dynamic-package "helloworld")
</code></pre>
<p>But fails miserably for something like this:</p>
<pre><code>(defun make-package-from-path (path)
(def-dynamic-package (pathname-name path)))
</code></pre>
<p>or</p>
<pre><code>(defun make-package-from-path (path)
(let ((filename (pathname-path)))
(def-dynamic-package filename)))
</code></pre>
<p>I understand how most basic macros work but how to implement this one escapes me.</p>
| [
{
"answer_id": 279725,
"author": "Nowhere man",
"author_id": 400277,
"author_profile": "https://Stackoverflow.com/users/400277",
"pm_score": 0,
"selected": false,
"text": "(list 'pathname-name 'path)\n"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/279696",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32797/"
] |
279,701 | <p>I'm trying to get a handle on if there's a good time to use standard linq keywords or linq extension methods with lambda expressions. They seems to do the same thing, just are written differently. Is it purely a matter of style?</p>
<pre><code>var query = from p in Products
where p.Name.Contains("foo")
orderby c.Name
select p;
// or with extension methods:
var query = Products
.Where(p => p.Name.Contains("foo"))
.OrderBy(p => p.Name);
</code></pre>
<p>They're very similar with the second example being a bit more terse, but perhaps less expressive if you don't know what the => is doing.</p>
<p><strong>Other than writing terse code, are there other advantages to using the extension methods as opposed to the LINQ syntax?</strong></p>
| [
{
"answer_id": 279738,
"author": "Nathan W",
"author_id": 6335,
"author_profile": "https://Stackoverflow.com/users/6335",
"pm_score": 5,
"selected": false,
"text": "Into"
},
{
"answer_id": 284313,
"author": "Programmin Tool",
"author_id": 21691,
"author_profile": "htt... | 2008/11/11 | [
"https://Stackoverflow.com/questions/279701",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26931/"
] |
279,705 | <p>My shared host did not provide git, so I built and installed it into ~/bin.
When I ran it, I got the following error on most commands, although they were successful. </p>
<blockquote>
<p><code>stdin: is not a tty</code></p>
</blockquote>
<p>I can solve that problem by adding: </p>
<blockquote>
<p><code>default_run_options[:pty] = true</code></p>
</blockquote>
<p>to my deploy.rb, but then I get this error, which blocks deployment:</p>
<blockquote>
<p><code>sh: git: command not found</code></p>
</blockquote>
<p>How can I resolve both errors?</p>
<p>I tried adding a ~/.ssh/environment file with <code>"PATH=$PATH:$HOME/bin"</code> (and changing sshd_config to use it) but it did nothing.</p>
<p>It seems whatever shell is being used by capistrano is not using the ~/.bashrc or ~/.bash_profile on the remote server.</p>
<p>Any ideas how to set the path on the remote machine?</p>
<p>other info: I'm using OS X locally, and the shared server is linux on Site5.</p>
| [
{
"answer_id": 279746,
"author": "Denis Hennessy",
"author_id": 35958,
"author_profile": "https://Stackoverflow.com/users/35958",
"pm_score": 2,
"selected": false,
"text": "set :deploy_via, :copy\n"
},
{
"answer_id": 281124,
"author": "Chu Yeow",
"author_id": 25226,
"... | 2008/11/11 | [
"https://Stackoverflow.com/questions/279705",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
279,729 | <p>I am forking a number of processes and I want to measure how long it takes to complete the whole task, that is when all processes forked are completed. Please advise how to make the parent process wait until all child processes are terminated? I want to make sure that I stop the timer at the right moment.</p>
<p>Here is as a code I use:</p>
<pre><code>#include <iostream>
#include <string>
#include <fstream>
#include <sys/time.h>
#include <sys/wait.h>
using namespace std;
struct timeval first, second, lapsed;
struct timezone tzp;
int main(int argc, char* argv[])// query, file, num. of processes.
{
int pCount = 5; // process count
gettimeofday (&first, &tzp); //start time
pid_t* pID = new pid_t[pCount];
for(int indexOfProcess=0; indexOfProcess<pCount; indexOfProcess++)
{
pID[indexOfProcess]= fork();
if (pID[indexOfProcess] == 0) // child
{
// code only executed by child process
// magic here
// The End
exit(0);
}
else if (pID[indexOfProcess] < 0) // failed to fork
{
cerr << "Failed to fork" << endl;
exit(1);
}
else // parent
{
// if(indexOfProcess==pCount-1) and a loop with waitpid??
gettimeofday (&second, &tzp); //stop time
if (first.tv_usec > second.tv_usec)
{
second.tv_usec += 1000000;
second.tv_sec--;
}
lapsed.tv_usec = second.tv_usec - first.tv_usec;
lapsed.tv_sec = second.tv_sec - first.tv_sec;
cout << "Job performed in " <<lapsed.tv_sec << " sec and " << lapsed.tv_usec << " usec"<< endl << endl;
}
}//for
}//main
</code></pre>
| [
{
"answer_id": 279744,
"author": "gnud",
"author_id": 27204,
"author_profile": "https://Stackoverflow.com/users/27204",
"pm_score": 4,
"selected": false,
"text": "while(wait() > 0) { /* no-op */ ; }\n"
},
{
"answer_id": 279745,
"author": "BCS",
"author_id": 1343,
"aut... | 2008/11/11 | [
"https://Stackoverflow.com/questions/279729",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3515/"
] |
279,748 | <p>I have some code like this:</p>
<pre><code>[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Save([Bind(Prefix="")]Person person)
{
String s = person.property;
/* ... */
}
</code></pre>
<p>But it throws the error: "Cannot use local variable 'person' before it is declared".</p>
<p>What simple thing am I missing?</p>
| [
{
"answer_id": 18253246,
"author": "Frankie Lee",
"author_id": 2685909,
"author_profile": "https://Stackoverflow.com/users/2685909",
"pm_score": 2,
"selected": false,
"text": " public ChartData(MetricInfo metricInfo, MetricItem[] metricItems) : this()\n {\n int e... | 2008/11/11 | [
"https://Stackoverflow.com/questions/279748",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/364/"
] |
279,749 | <p>I'm working on a kind of unique app which needs to generate images at specific resolutions according to the device they are displayed on. So the output is different on a regular Windows browser (96ppi), iPhone (163ppi), Android G1 (180ppi), and other devices. I'm wondering if there's a way to detect this automatically.</p>
<p>My initial research seems to say no. The only suggestion I've seen is to make an element whose width is specified as "1in" in CSS, then check its offsetWidth (see also <a href="https://stackoverflow.com/q/476815/698168">How to access screen display’s DPI settings via javascript?</a>). Makes sense, but iPhone is lying to me with that technique, saying it's 96ppi.</p>
<p>Another approach might be to get the dimensions of the display in inches and then divide by the width in pixels, but I'm not sure how to do that either.</p>
| [
{
"answer_id": 4472024,
"author": "john",
"author_id": 488480,
"author_profile": "https://Stackoverflow.com/users/488480",
"pm_score": 2,
"selected": false,
"text": "<body><div id=\"ppitest\" style=\"width:1in;visible:hidden;padding:0px\"></div></body>\n"
},
{
"answer_id": 821298... | 2008/11/11 | [
"https://Stackoverflow.com/questions/279749",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
279,753 | <p>I have written code that automatically creates CSS sprites based on the IMG tags in a page and replaces them with DIV's with (what I thought was) appropriate CSS to position the sprite image as a background letting the appropriate part show through -- the problem is that I cannot get DIVs to behave as drop in replacements for IMGs. </p>
<p>If I leave the default 'display' value set to 'block' then if the original IMG was positioned at the end of some text, the replacement DIV will jump down to the next line after text (which of course is what I would expect something with display: block to do).</p>
<p>If I change the 'display' to inline, then the DIV stays on the same line as the text but it ignores the 'width' and 'height' I have set and collapses. I've tried putting 's inside the DIV but it then only takes up enough width to contain the nbsp.</p>
<p>I've tried experimenting with setting display to all possible values (including the "obscure" ones like 'table-row', 'run-in', 'compact', etc) but all with no luck. Is it even possible to create a DIV with the same layout behavior as an IMG?</p>
<p>I am open to having something more complicated than just a single DIV, however I've tried the obvious things there (one DIV inside another where the inner DIV is set to display: block with the outer set to display: inline) but I haven't found a combination there that works either.</p>
<p>There are always specific things I can do outside of the replaced IMG/DIV to get the layout I want, but my goal is to have a generic auto-CSS-sprite mechanism that works regardless of the rest of the HTML.</p>
| [
{
"answer_id": 279777,
"author": "Andy Ford",
"author_id": 17252,
"author_profile": "https://Stackoverflow.com/users/17252",
"pm_score": 5,
"selected": true,
"text": "display: inline-block;"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/279753",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2168/"
] |
279,763 | <p>I am trying to write a C program that uses <code>dlysm</code>, and I keep getting an undefined reference to dlysm. I think I need to set my <code>-ldl</code> flags but I have no idea how to do this. </p>
<p>I am very new to linux and setting variables. If this is what I need to do can someone help me out with the commands?</p>
| [
{
"answer_id": 279767,
"author": "Kknd",
"author_id": 18403,
"author_profile": "https://Stackoverflow.com/users/18403",
"pm_score": 1,
"selected": false,
"text": "-ldl"
},
{
"answer_id": 279771,
"author": "gnud",
"author_id": 27204,
"author_profile": "https://Stackove... | 2008/11/11 | [
"https://Stackoverflow.com/questions/279763",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
279,769 | <p>How do you convert between a DateTime and a Time object in Ruby?</p>
| [
{
"answer_id": 279785,
"author": "Gordon Wilson",
"author_id": 23071,
"author_profile": "https://Stackoverflow.com/users/23071",
"pm_score": 7,
"selected": true,
"text": " Time "
},
{
"answer_id": 280464,
"author": "anshul",
"author_id": 17674,
"author_profile": "http... | 2008/11/11 | [
"https://Stackoverflow.com/questions/279769",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4883/"
] |
279,779 | <p>I know in the MVC Framework, you have the Html Class to create URLs:</p>
<pre><code>Html.ActionLink("About us", "about", "home");
</code></pre>
<p>But what if you want to generate Urls in Webforms?</p>
<p>I haven't found a really good resource on the details on generating URLs with Webforms.</p>
<p>For example, if I'm generating routes like so:</p>
<pre><code>Route r = new Route("{country}/{lang}/articles/{id}/{title}",
new ArticleRouteHandler("~/Forms/Article.aspx"));
Route r2 = new Route("{country}/{lang}/articles/",
new ArticleRouteHandler("~/Forms/ArticlesList.aspx"));
Routes.Add(r);
Routes.Add(r2);
</code></pre>
<p>How would i generate URLs using the Routing table data.</p>
<h2>How do I generate URLS based on my routes?</h2>
<p>eg. /ca/en/articles/123/Article-Title without</p>
| [
{
"answer_id": 281340,
"author": "MikeO",
"author_id": 36616,
"author_profile": "https://Stackoverflow.com/users/36616",
"pm_score": 3,
"selected": true,
"text": "Dim routedurl = RouteTable.Routes.GetVirtualPath(context, rvd).VirtualPath\n"
},
{
"answer_id": 285882,
"author":... | 2008/11/11 | [
"https://Stackoverflow.com/questions/279779",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26931/"
] |
279,781 | <p>Hey everyone, I am trying to run the following program, but am getting a NullPointerException. I am new to the Java swing library so I could be doing something very dumb. Either way here are my two classes I am just playing around for now and all i want to do is draw a damn circle (ill want to draw a gallow, with a hangman on it in the end).</p>
<pre><code>package hangman2;
import java.awt.*;
import javax.swing.*;
public class Hangman2 extends JFrame{
private GridLayout alphabetLayout = new GridLayout(2,2,5,5);
private Gallow gallow = new Gallow();
public Hangman2() {
setLayout(alphabetLayout);
setSize(1000,500);
setVisible( true );
}
public static void main( String args[] ) {
Hangman2 application = new Hangman2();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
}
package hangman2;
import java.awt.*;
import javax.swing.*;
public class Gallow extends JPanel {
private Graphics g;
public Gallow(){
g.fillOval(10, 20, 40, 25);
}
}
</code></pre>
<p>The NullPointerException comes in at the g.fillOval line.</p>
<p>Thanks in advance,</p>
<p>Tomek</p>
| [
{
"answer_id": 279798,
"author": "sblundy",
"author_id": 4893,
"author_profile": "https://Stackoverflow.com/users/4893",
"pm_score": 3,
"selected": true,
"text": "g"
},
{
"answer_id": 279851,
"author": "Vincent Ramdhanie",
"author_id": 27439,
"author_profile": "https:... | 2008/11/11 | [
"https://Stackoverflow.com/questions/279781",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29326/"
] |
279,782 | <p>Given:</p>
<pre><code>from django.db import models
class Food(models.Model):
"""Food, by name."""
name = models.CharField(max_length=25)
class Cat(models.Model):
"""A cat eats one type of food"""
food = models.ForeignKey(Food)
class Cow(models.Model):
"""A cow eats one type of food"""
food = models.ForeignKey(Food)
class Human(models.Model):
"""A human may eat lots of types of food"""
food = models.ManyToManyField(Food)
</code></pre>
<p>How can one, given only the class Food, get a set of all classes that it has "reverse relationships" to. I.e. given the class <strong>Food</strong>, how can one get the classes <strong>Cat</strong>, <strong>Cow</strong> and <strong>Human</strong>.</p>
<p>I would think it's possible because Food has the three "reverse relations": <em>Food.cat_set</em>, <em>Food.cow_set</em>, and <em>Food.human_set</em>.</p>
<p>Help's appreciated & thank you!</p>
| [
{
"answer_id": 279809,
"author": "Brian M. Hunt",
"author_id": 19212,
"author_profile": "https://Stackoverflow.com/users/19212",
"pm_score": 4,
"selected": false,
"text": "def get_all_related_objects(self, local_only=False):\n\ndef get_all_related_many_to_many_objects(self, local_only=Fa... | 2008/11/11 | [
"https://Stackoverflow.com/questions/279782",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19212/"
] |
279,791 | <p>Suppose the following data schema:</p>
<pre><code>Usage
======
client_id
resource
type
amount
Billing
======
client_id
usage_resource
usage_type
rate
</code></pre>
<p>In this example, suppose I have multiple resources, each of which can be used in many ways. For example, one resource is a <code>widget</code>. <code>Widgets</code> can be <code>foo</code>ed and they can be <code>bar</code>ed. <code>Gizmo</code>s can also be <code>foo</code>ed and <code>bar</code>ed. These usage types are billed at different rates, possibly even different rates for different clients. Each occurence of a usage (of a resource) is recorded in the Usage table. Each billing rate (for client, resource, and type combination) is stored in the billing table.</p>
<p><em>(By the way, if this data schema is not the right way to approach this problem, please make suggestions.)</em></p>
<p>Is it possible, using Ruby on Rails and ActiveRecord, to create a <code>has_many</code> relationship from Billings to Usages so that I can get a list of usage instances for a given billing rate? Is there a syntax of the <code>has_many, :through</code> that I don't know?</p>
<p>Once again, I may be approaching this problem from the wrong angle, so if you can think of a better way, please speak up!</p>
| [
{
"answer_id": 279838,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "https://Stackoverflow.com/users/20860",
"pm_score": 4,
"selected": true,
"text": "id"
},
{
"answer_id": 1081092,
"author": "Michael Sofaer",
"author_id": 132613,
"author_profile": "... | 2008/11/11 | [
"https://Stackoverflow.com/questions/279791",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4257/"
] |
279,822 | <p>I'm looking for a (preferably free) component for Delphi for users to easily select about 100 different colours.</p>
<p>I've currently got one as part of DevExpress's editors, but it only has about 20 proper colours to choose, with a bunch of other 'Windows' colours like clHighlight, clBtnFace, etc.</p>
<p>It's for regular users, so would like to avoid requiring them to manually select RGB values. </p>
<p>Something similar to the colour picker in MS Paint might work, or something that lists X11/web colours:</p>
<p><a href="http://en.wikipedia.org/wiki/Web_Colors" rel="noreferrer">http://en.wikipedia.org/wiki/Web_Colors</a></p>
<p>So, please let me know if you got any recommendations.</p>
<p><strong>Thanks for the suggestions from everyone</strong></p>
<p>All of the suggestions were good, I didn't realise the MS Paint colour dialog can be called, that's all I needed and is the simplest solution. Thanks</p>
| [
{
"answer_id": 280103,
"author": "Francesca",
"author_id": 9842,
"author_profile": "https://Stackoverflow.com/users/9842",
"pm_score": 5,
"selected": true,
"text": "object ColorDialog1: TColorDialog\n Options = [cdFullOpen, cdAnyColor]\nend\n"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/279822",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26305/"
] |
279,833 | <p>I am not looking for links to information on hashing.</p>
<p>I am not looking for the worlds greatest hash function.</p>
<p>I am interested in mini-stories describing</p>
<ul>
<li>The problem domain you were working in</li>
<li>The nature of the data you were working with</li>
<li>What your thought process was in designing a hash function for your data.</li>
<li>How happy were you with your result.</li>
<li>What you learned from the experience that might be of value to others.</li>
</ul>
| [
{
"answer_id": 279893,
"author": "S.Lott",
"author_id": 10661,
"author_profile": "https://Stackoverflow.com/users/10661",
"pm_score": 3,
"selected": true,
"text": "{ \n ( (col1, col2), (col3, col4) ) : [ aRow, anotherRow, row3, ... ],\n ( (col1, col2), (col3, col4) ) : [ row1, row2... | 2008/11/11 | [
"https://Stackoverflow.com/questions/279833",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7734/"
] |
279,837 | <p>It's kind of a C puzzle. You have to tell if the program finish its execution, if so, how much time it takes to run and what it returns to the OS.</p>
<pre><code>static unsigned char buffer[256];
int main(void)
{
unsigned char *p, *q;
q = (p = buffer) + sizeof(buffer);
while (q - p)
{
p = buffer;
while (!++*p++);
}
return p - q;
}
</code></pre>
<p>[EDIT]
I removed the interview-questions tag since that seems to be the primary thing people are objecting to. This is a great little puzzle but as everyone has already pointed out, not a great interview question.</p>
| [
{
"answer_id": 279855,
"author": "Steven A. Lowe",
"author_id": 9345,
"author_profile": "https://Stackoverflow.com/users/9345",
"pm_score": 4,
"selected": false,
"text": "static unsigned char buffer[256];\nint main(void)\n{\n unsigned char *p, *q;\n q = (p = buffer) + sizeof(buffer); ... | 2008/11/11 | [
"https://Stackoverflow.com/questions/279837",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1876/"
] |
279,854 | <p>If I have a vector of pairs:</p>
<pre><code>std::vector<std::pair<int, int> > vec;
</code></pre>
<p>Is there and easy way to sort the list in <strong>increasing</strong> order based on the second element of the pair?</p>
<p>I know I can write a little function object that will do the work, but is there a way to use existing parts of the <em>STL</em> and <code>std::less</code> to do the work directly?</p>
<p>EDIT: I understand that I can write a separate function or class to pass to the third argument to sort. The question is whether or not I can build it out of standard stuff. I'd really something that looks like:</p>
<pre><code>std::sort(vec.begin(), vec.end(), std::something_magic<int, int, std::less>());
</code></pre>
| [
{
"answer_id": 279878,
"author": "Evan Teran",
"author_id": 13430,
"author_profile": "https://Stackoverflow.com/users/13430",
"pm_score": 9,
"selected": true,
"text": "auto"
},
{
"answer_id": 280128,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_prof... | 2008/11/11 | [
"https://Stackoverflow.com/questions/279854",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34502/"
] |
279,860 | <h2>Background</h2>
<p>I'm trying out Scons by setting up a basic C++ sample project that has two sub-projects: </p>
<ul>
<li>Prj1 is an EXE that depends on Prj2</li>
<li>Prj2 is a DLL that exports some functions</li>
</ul>
<p>The problem I'm running into is that the library builds its .obj, .pdb, .lib, .dll, etc. files in the same directory as it's SConscript file while the EXE builds its files in the same directory as its SConscript. The application successfully builds both the Prj2 dependency and itself. However, you cannot run the resulting EXE because it can't find the library it needs because it is in the other directory.</p>
<h2>Question</h2>
<p>How can I get multiple projects that have dependences to output their binaries and debug information into a common directory so that they can be executed and debugged?</p>
<h2>Potential Solutions</h2>
<p>This is what I have thought of so far:</p>
<ul>
<li>I tried using VariantDir (previously called BuildDir) however this doesn't seem to work. Perhaps I'm messing something up here.</li>
<li>I could potentially tell the compiler and the linker explicitly (via Fo/Fd for example) where to drop their files (is this the best or only solution???)</li>
<li>Execute a copy command on the resulting binaries (this seems like a hack and quite a pain to manage/maintain)</li>
</ul>
<h2>Update</h2>
<p>I updated the File Structure and file contents below to reflect the working solution in it's entirety. Thanks to grieve for his insight.</p>
<h2>Command</h2>
<p>With this configuration, you must unfortunately execute the build by cd'ing to the build directory and then running the command below. I need to get a properly working alias setup to get around this.</p>
<pre><code>
build> scons ../bin/project1.exe
</code></pre>
<h2>File Structure</h2>
<pre><code> /scons-sample
/bin
/release
/debug
/build
SConstruct
scons_helper.py
/prj1
SConscript
/include
/src
main.cpp
/prj2
SConscript
/include
functions.h
/src
functions.cpp
</code></pre>
<h2>SConstruct</h2>
<pre><code>
import os.path
BIN_DIR = '../bin'
OBJ_DIR = './obj'
#--------------------------------------
# CxxTest Options
#--------------------------------------
CXXTEST_DIR = '../extern/CxxTest/CxxTest-latest'
PERL = 'perl -w'
TESTS = '*.h'
TESTGEN = PERL + CXXTEST_DIR + '/cxxtestgen.pl'
CXXTESTGEN_FLAGS = '--runner=ParenPrinter \
--abort-on-fail \
--have-eh'
#--------------------------------------
# Options
#--------------------------------------
SetOption( 'implicit_cache', 1 )
# command line options
opts = Options()
opts.AddOptions(
EnumOption(
'debug',
'Debug version (useful for developers only)',
'no',
allowed_values = ('yes', 'no'),
map = { },
ignorecase = 1
)
)
#--------------------------------------
# Environment
#--------------------------------------
env = Environment(
options = opts,
#--------------------------------------
# Linker Options
#--------------------------------------
LIBPATH = [
'../extern/wxWidgets/wxWidgets-latest/lib/vc_dll'
],
LIBS = [
# 'wxmsw28d_core.lib',
# 'wxbase28d.lib',
# 'wxbase28d_odbc.lib',
# 'wxbase28d_net.lib',
'kernel32.lib',
'user32.lib',
'gdi32.lib',
'winspool.lib',
'comdlg32.lib',
'advapi32.lib',
'shell32.lib',
'ole32.lib',
'oleaut32.lib',
'uuid.lib',
'odbc32.lib',
'odbccp32.lib'
],
LINKFLAGS = '/nologo /subsystem:console /incremental:yes /debug /machine:I386',
#--------------------------------------
# Compiler Options
#--------------------------------------
CPPPATH = [
'./include/',
'../extern/wxWidgets/wxWidgets-latest/include',
'../extern/wxWidgets/wxWidgets-latest/vc_dll/mswd'
],
CPPDEFINES = [
'WIN32',
'_DEBUG',
'_CONSOLE',
'_MBCS',
'WXUSINGDLL',
'__WXDEBUG__'
],
CCFLAGS = '/W4 /EHsc /RTC1 /MDd /nologo /Zi /TP /errorReport:prompt'
)
env.Decider( 'MD5-timestamp' ) # For speed, use timestamps for change, followed by MD5
Export( 'env', 'BIN_DIR' ) # Export this environment for use by the SConscript files
#--------------------------------------
# Builders
#--------------------------------------
SConscript( '../prj1/SConscript' )
SConscript( '../prj2/SConscript' )
Default( 'prj1' )
</code></pre>
<h2>scons_helper.py</h2>
<pre><code>
import os.path
#--------------------------------------
# Functions
#--------------------------------------
# Prepends the full path information to the output directory so that the build
# files are dropped into the directory specified by trgt rather than in the
# same directory as the SConscript file.
#
# Parameters:
# env - The environment to assign the Program value for
# outdir - The relative path to the location you want the Program binary to be placed
# trgt - The target application name (without extension)
# srcs - The list of source files
# Ref:
# Credit grieve and his local SCons guru for this:
# http://stackoverflow.com/questions/279860/how-do-i-get-projects-to-place-their-build-output-into-the-same-directory-with
def PrefixProgram(env, outdir, trgt, srcs):
env.Program(target = os.path.join(outdir, trgt), source = srcs)
# Similar to PrefixProgram above, except for SharedLibrary
def PrefixSharedLibrary(env, outdir, trgt, srcs):
env.SharedLibrary(target = os.path.join(outdir, trgt), source = srcs)
def PrefixFilename(filename, extensions):
return [(filename + ext) for ext in extensions]
# Prefix the source files names with the source directory
def PrefixSources(srcdir, srcs):
return [os.path.join(srcdir, x) for x in srcs]
</code></pre>
<h2>SConscript for Prj1</h2>
<pre><code>
import os.path
import sys
sys.path.append( '../build' )
from scons_helper import *
Import( 'env', 'BIN_DIR' ) # Import the common environment
prj1_env = env.Clone() # Clone it so we don't make changes to the global one
#--------------------------------------
# Project Options
#--------------------------------------
PROG = 'project1'
#--------------------------------------
# Header Files
#--------------------------------------
INC_DIR = [
'../prj2/include'
]
HEADERS = [
''
]
#--------------------------------------
# Source Files
#--------------------------------------
SRC_DIR = './src'
SOURCES = [
'main.cpp'
]
# Prefix the source files names with the source directory
SOURCES = PrefixSources( SRC_DIR, SOURCES )
#--------------------------------------
# Compiler and Linker Overrides
#--------------------------------------
prj1_env.Append(
CPPPATH = INC_DIR,
LIBS = 'project2',
LIBPATH = BIN_DIR,
# Microsoft Visual Studio Specific
PDB = os.path.join( BIN_DIR, PROG + '.pdb' )
)
#--------------------------------------
# Builders
#--------------------------------------
PrefixProgram( prj1_env, BIN_DIR, PROG, SOURCES )
</code></pre>
<h2>SConscript for Prj2</h2>
<pre><code>
import os.path
import sys
sys.path.append( '../build' )
from scons_helper import *
Import( 'env', 'BIN_DIR' ) # Import the common environment
prj2_env = env.Clone() # Clone it so we don't make changes to the global one
#--------------------------------------
# Project Options
#--------------------------------------
PROG = 'project2'
#--------------------------------------
# Header Files
#--------------------------------------
INC_DIR = [
''
]
HEADERS = [
'functions.h'
]
#--------------------------------------
# Source Files
#--------------------------------------
SRC_DIR = './src/'
SOURCES = [
'functions.cpp'
]
# Prefix the source files names with the source directory
SOURCES = PrefixSources( SRC_DIR, SOURCES )
#--------------------------------------
# Compiler and Linker Overrides
#--------------------------------------
# Update the environment with the project specific information
prj2_env.Append(
CPPPATH = INC_DIR,
# Microsoft Visual Studio Specific
PDB = os.path.join( BIN_DIR, PROG + '.pdb' )
)
#--------------------------------------
# Builders
#--------------------------------------
PrefixSharedLibrary( prj2_env, BIN_DIR, PROG, SOURCES )
</code></pre>
| [
{
"answer_id": 279883,
"author": "grieve",
"author_id": 34329,
"author_profile": "https://Stackoverflow.com/users/34329",
"pm_score": 2,
"selected": false,
"text": "env.Install(\"../bin\", <your target exe or dll>)\n"
},
{
"answer_id": 281103,
"author": "grieve",
"author_... | 2008/11/11 | [
"https://Stackoverflow.com/questions/279860",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2233/"
] |
279,902 | <p>Or better said: When to use array as a field data type in a table?</p>
<p>Which solution provides better search results?</p>
| [
{
"answer_id": 59516125,
"author": "mattdlockyer",
"author_id": 1060487,
"author_profile": "https://Stackoverflow.com/users/1060487",
"pm_score": 3,
"selected": false,
"text": "create table data (\n id serial primary key,\n tags int[],\n data jsonb\n);\n\ncreate table tags (\n ... | 2008/11/11 | [
"https://Stackoverflow.com/questions/279902",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34565/"
] |
279,907 | <p>What is the best way to display a checkbox in a Crystal Report?</p>
<p>Example: My report has a box for "Male" and "Female", and one should be checked.</p>
<p>My current workaround is to draw a small graphical square, and line it up with a formula which goes like this:</p>
<pre><code>if {table.gender} = "M" then "X" else " "
</code></pre>
<p>This is a poor solution, because changing the font misaligns my "X" and the box around it, and it is absurdly tedious to squint at the screen and get a pixel-perfect alignment for every box (there are dozens).</p>
<p>Does anyone have a better solution? I've thought about using the old-style terminal characters, but I'm not sure if they display properly in Crystal.</p>
<p><em>Edit: I'm using Crystal XI.</em></p>
| [
{
"answer_id": 281304,
"author": "jons911",
"author_id": 34375,
"author_profile": "https://Stackoverflow.com/users/34375",
"pm_score": 2,
"selected": false,
"text": "0xFE"
},
{
"answer_id": 2891048,
"author": "hatem gamil",
"author_id": 298416,
"author_profile": "http... | 2008/11/11 | [
"https://Stackoverflow.com/questions/279907",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/672/"
] |
279,912 | <p>I am looking to do some tinkering with openGL and Python and haven't been able to find good reasons for using PyOpenGl versus pyglet</p>
<p>Which would you recommend and why?</p>
| [
{
"answer_id": 38231267,
"author": "Szabolcs Dombi",
"author_id": 6557569,
"author_profile": "https://Stackoverflow.com/users/6557569",
"pm_score": 4,
"selected": false,
"text": "pip install ModernGL\n"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/279912",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16584/"
] |
279,917 | <p>I'm loading data from my database, and exporting to an Excel file via a method I found on this site: <a href="http://www.appservnetwork.com/modules.php?name=News&file=article&sid=8" rel="noreferrer">http://www.appservnetwork.com/modules.php?name=News&file=article&sid=8</a></p>
<p>It works, but what I want to do now is format the text before it exports - change the font and text size. Does anybody have any ideas on how to do this?</p>
| [
{
"answer_id": 279926,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "https://Stackoverflow.com/users/20860",
"pm_score": 3,
"selected": false,
"text": "PEAR :: Package :: Spreadsheet_Excel_Writer"
},
{
"answer_id": 281902,
"author": "Eric Caron",
"author... | 2008/11/11 | [
"https://Stackoverflow.com/questions/279917",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20826/"
] |
279,919 | <p>Is there a C function call that can change the last modified date of a file or directory in Windows?</p>
| [
{
"answer_id": 279931,
"author": "FlySwat",
"author_id": 1965,
"author_profile": "https://Stackoverflow.com/users/1965",
"pm_score": 2,
"selected": false,
"text": "BOOL WINAPI SetFileTime(\n __in HANDLE hFile,\n __in_opt const FILETIME *lpCreationTime,\n __in_opt const FILETIME... | 2008/11/11 | [
"https://Stackoverflow.com/questions/279919",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
279,945 | <p>I have a file <code>test.txt</code> that is inside a zip archive <code>test.zip</code>. The permissions on <code>test.txt</code> are out of my control when it's compressed, but now I want them to be group-writeable. I am extracting the file with Python, and don't want to escape out to the shell.</p>
<p><strong>EDIT:</strong>
Here's what I've got so far:</p>
<pre><code>import zipfile
z = zipfile.ZipFile('test.zip', 'w')
zi = zipfile.ZipInfo('test.txt')
zi.external_attr = 0777 << 16L
z.writestr(zi, 'FOO')
z.close()
z = zipfile.ZipFile('test.zip', 'r')
for name in z.namelist():
newFile = open(name, "wb")
newFile.write(z.read(name))
newFile.close()
z.close()
</code></pre>
<p>This works perfectly on OS X using 2.5.1, but it doesn't work on my home box (Debian, Python 2.4 & 2.5) or on RHEL 5 with Python 2.4. On anything but OS X it doesn't error, but doesn't change the permissions either. Any ideas why? Also, how does <code>writestr()</code> work? I know I'm using it incorrectly here.</p>
<p>Is there a way to do this without <code>os.chmod</code> (the user extracting the file doesn't have permissions to use <code>os.chmod</code> after it's extracted)? I have full write access to the zip file.</p>
<p>More info:</p>
<pre><code>> ls -l test.zip
-rwxrwxrwx 1 myuser mygroup 2008-11-11 13:24 test.zip
> unzip test.zip
Archive: test.zip
inflating: test.txt
> ls -l test.txt
-rw-r--r-- 1 myuser mygroup 2008-11-11 13:34 test.txt
</code></pre>
<p>The user extracting is not <code>myuser</code>, but is in <code>mygroup</code>.</p>
| [
{
"answer_id": 279985,
"author": "John Fouhy",
"author_id": 15154,
"author_profile": "https://Stackoverflow.com/users/15154",
"pm_score": 0,
"selected": false,
"text": "for n in `unzip -l test.zip | awk 'NR > 3 && NF == 4 { print $4 }'`; do unzip -p test.zip $n > $n; done\n"
},
{
... | 2008/11/11 | [
"https://Stackoverflow.com/questions/279945",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1057/"
] |
279,953 | <p>I am using a service component through ASP.NET MVC.
I would like to send the email in a asynchronous way to let the user do other stuff without having to wait for the sending.</p>
<p>When I send a message without attachments it works fine.
When I send a message with at least one in-memory attachment it fails.</p>
<p>So, I would like to know if it is possible to use an async method with in-memory attachments.</p>
<p>Here is the sending method</p>
<pre><code>
public static void Send() {
MailMessage message = new MailMessage("from@foo.com", "too@foo.com");
using (MemoryStream stream = new MemoryStream(new byte[64000])) {
Attachment attachment = new Attachment(stream, "my attachment");
message.Attachments.Add(attachment);
message.Body = "This is an async test.";
SmtpClient smtp = new SmtpClient("localhost");
smtp.Credentials = new NetworkCredential("foo", "bar");
smtp.SendAsync(message, null);
}
}
</code></pre>
<p>Here is my current error</p>
<pre><code>
System.Net.Mail.SmtpException: Failure sending mail.
---> System.NotSupportedException: Stream does not support reading.
at System.Net.Mime.MimeBasePart.EndSend(IAsyncResult asyncResult)
at System.Net.Mail.Message.EndSend(IAsyncResult asyncResult)
at System.Net.Mail.SmtpClient.SendMessageCallback(IAsyncResult result)
--- End of inner exception stack trace ---
</code></pre>
<hr>
<p>Solution</p>
<pre><code> public static void Send()
{
MailMessage message = new MailMessage("from@foo.com", "to@foo.com");
MemoryStream stream = new MemoryStream(new byte[64000]);
Attachment attachment = new Attachment(stream, "my attachment");
message.Attachments.Add(attachment);
message.Body = "This is an async test.";
SmtpClient smtp = new SmtpClient("localhost");
//smtp.Credentials = new NetworkCredential("login", "password");
smtp.SendCompleted += delegate(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
{
if (e.Error != null)
{
System.Diagnostics.Trace.TraceError(e.Error.ToString());
}
MailMessage userMessage = e.UserState as MailMessage;
if (userMessage != null)
{
userMessage.Dispose();
}
};
smtp.SendAsync(message, message);
}
</code></pre>
| [
{
"answer_id": 41071322,
"author": "sweetfa",
"author_id": 490614,
"author_profile": "https://Stackoverflow.com/users/490614",
"pm_score": 0,
"selected": false,
"text": " public event EventHandler EmailSendCancelled = delegate { };\n\n public event EventHandler EmailSendFailure = d... | 2008/11/11 | [
"https://Stackoverflow.com/questions/279953",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1195872/"
] |
279,959 | <p>I have an entry in my .vimrc which makes it page down the viewport when I hit the spacebar. It looks like this:</p>
<pre><code>map <Space> <PageDown>
</code></pre>
<p>I want to create another key mapping which pages the viewport up when holding shift and hitting the spacebar. I have tried the following entries:</p>
<pre><code>map <Shift><Space> <PageUp>
map <S-Space> <PageUp>
</code></pre>
<p>Neither work. Anybody know how to achieve this functionality?</p>
| [
{
"answer_id": 279973,
"author": "Christian C. Salvadó",
"author_id": 5445,
"author_profile": "https://Stackoverflow.com/users/5445",
"pm_score": 3,
"selected": false,
"text": "map <Space> ^D \" Pagedown when press Space\nmap <S-Space> ^U \" Page Up when press Shift Space\n"
},
{
... | 2008/11/11 | [
"https://Stackoverflow.com/questions/279959",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2476/"
] |
279,962 | <p>How can I export a GridView's data to a Microsoft Excel 2007 file?</p>
<p>Also, does Microsoft Excel 2007 support html elements and tags?</p>
| [
{
"answer_id": 280012,
"author": "Charles Graham",
"author_id": 7705,
"author_profile": "https://Stackoverflow.com/users/7705",
"pm_score": 2,
"selected": false,
"text": "Response.ContentType = \"application/vnd.ms-excel\";\n"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/279962",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36430/"
] |
279,966 | <p>I am building a PHP application in CodeIgniter. CodeIgniter sends all requests to the main controller: <code>index.php</code>. However, I don't like to see <code>index.php</code> in the URI. For example, <code>http://www.example.com/faq/whatever</code> will route to <code>http://www.example.com/index.php/faq/whatever</code>. I need a reliable way for a script to know what it's address is, so it will know what to do with the navigation. I've used <code>mod_rewrite</code>, as per CodeIgniter documentation.</p>
<p>The rule is as follows:</p>
<pre><code>RewriteEngine on
RewriteCond $1 !^(images|inc|favicon\.ico|index\.php|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
</code></pre>
<p>Normally, I would just check <code>php_self</code>, but in this case it's always <code>index.php</code>. I can get it from <code>REQUEST_URI</code>, <code>PATH_INFO</code>, etc., but I'm trying to decide which will be most reliable. Does anyone know (or know where to find) the real difference between <code>PHP_SELF</code>, <code>PATH_INFO</code>, <code>SCRIPT_NAME</code>, and <code>REQUEST_URI</code>? Thanks for your help!</p>
<p><strong>Note</strong>: I've had to add spaces, as SO sees the underscore, and makes it italic for some reason. </p>
<p><strong>Updated</strong>: Fixed the spaces.</p>
| [
{
"answer_id": 279986,
"author": "Xenph Yan",
"author_id": 264,
"author_profile": "https://Stackoverflow.com/users/264",
"pm_score": 2,
"selected": false,
"text": "$REQUEST_URI"
},
{
"answer_id": 280068,
"author": "Adam",
"author_id": 13320,
"author_profile": "https:/... | 2008/11/11 | [
"https://Stackoverflow.com/questions/279966",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27580/"
] |
279,974 | <p>I'm finding myself writing a bunch of related functions dealing with different nouns (clusters, sql servers, servers in general, files, etc.) and put each of these groups of functions in separate files (say cluster_utils.ps1, for example). I want to be able to "import" some of these libraries in my profile and others in my powershell session if I need them. I have written 2 functions that seem to solve the problem, but since I've only been using powershell for a month I thought I'd ask to see if there were any existing "best practice" type scripts I could be using instead.</p>
<p>To use these functions, I dot-source them (in my profile or my session)... for example,</p>
<pre><code># to load c:\powershellscripts\cluster_utils.ps1 if it isn't already loaded
. require cluster_utils
</code></pre>
<p>Here are the functions:</p>
<pre><code>$global:loaded_scripts=@{}
function require([string]$filename){
if (!$loaded_scripts[$filename]){
. c:\powershellscripts\$filename.ps1
$loaded_scripts[$filename]=get-date
}
}
function reload($filename){
. c:\powershellscripts\$filename.ps1
$loaded_scripts[$filename]=get-date
}
</code></pre>
<p>Any feedback would be helpful.</p>
| [
{
"answer_id": 282098,
"author": "Steven Murawski",
"author_id": 1233,
"author_profile": "https://Stackoverflow.com/users/1233",
"pm_score": 2,
"selected": false,
"text": "$global:scriptdirectory= 'c:\\powershellscripts'\n$global:loaded_scripts=@{}\nfunction require(){\n param ([str... | 2008/11/11 | [
"https://Stackoverflow.com/questions/279974",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36429/"
] |
279,988 | <p>If i try to paste source code in word 2007 the spacing between the lines seems to get messed up as all new lines are spaced way apart compared to a programming text editor.</p>
<p>Can somebody tell me how to paste source code in word 2007 preserving the formatting and the spacing between lines?</p>
| [
{
"answer_id": 446085,
"author": "Nathan Fellman",
"author_id": 1084,
"author_profile": "https://Stackoverflow.com/users/1084",
"pm_score": 0,
"selected": false,
"text": "2html.vim"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/279988",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14316/"
] |
279,991 | <p>Please tell me how can save a string with special characters to DB.Special characters may contatin single <code>quotes/double quotes</code> etc.. I am using ASP.NET with C#</p>
| [
{
"answer_id": 280025,
"author": "FlySwat",
"author_id": 1965,
"author_profile": "https://Stackoverflow.com/users/1965",
"pm_score": 0,
"selected": false,
"text": "Using (SqlConnection conn = new SqlConnection(connstr))\n{\n Using (SqlCommand command = new SqlCommand(\"INSERT INTO FOO... | 2008/11/11 | [
"https://Stackoverflow.com/questions/279991",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
280,003 | <p>Preferably in VB.Net, but C# is fine, how can I access the extra properties added to a file by my digital camera, like <code>Date Picture Taken</code>, <code>Shutter Speed</code> or <code>Camera Model</code>?</p>
| [
{
"answer_id": 280117,
"author": "Eric Schoonover",
"author_id": 3957,
"author_profile": "https://Stackoverflow.com/users/3957",
"pm_score": 1,
"selected": false,
"text": "BitmapMetadata"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/280003",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16415/"
] |
280,014 | <p>I have a script which logs on to a remote server and tries to rename files, using PHP.</p>
<p>The code currently looks something like this example from the php.net website:</p>
<pre><code>if (ftp_rename($conn_id, $old_file, $new_file)) {
echo "successfully renamed $old_file to $new_file\n";
} else {
echo "There was a problem while renaming $old_file to $new_file\n";
}
</code></pre>
<p>but ... what was the error? Permissions, no such directory, disk full?</p>
<p>How can I get PHP to return the FTP error? Something like this:</p>
<pre><code>echo "There was a problem while renaming $old_file to $new_file:
the server says $error_message\n";
</code></pre>
| [
{
"answer_id": 12910495,
"author": "Peter Hopfgartner",
"author_id": 1630567,
"author_profile": "https://Stackoverflow.com/users/1630567",
"pm_score": 4,
"selected": false,
"text": "$trackErrors = ini_get('track_errors');\nini_set('track_errors', 1);\nif (!@ftp_put($my_ftp_conn_id, $tmpR... | 2008/11/11 | [
"https://Stackoverflow.com/questions/280014",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/242241/"
] |
280,033 | <p>I am new to C++ and I had a few general questions about code separation. I have currently built a small application, all in one file. What I want to do now is convert this into separate files such that they contain similar code or whatnot. My real question right now is, how do I know how to separate things? What is the invisible margin that code should be separated at? </p>
<p>Also, what's the point of header files? Is it to forward declare methods and classes so I can use them in my code before they are included by the linker during compilation? </p>
<p>Any insight into methods or best practises would be great, thanks!</p>
| [
{
"answer_id": 280048,
"author": "Martin York",
"author_id": 14065,
"author_profile": "https://Stackoverflow.com/users/14065",
"pm_score": 5,
"selected": false,
"text": "Menu.h: Contains the Menu declaration.\nMenu.cpp: Contains the Menu definition.\n"
},
{
"answer_id": 280... | 2008/11/11 | [
"https://Stackoverflow.com/questions/280033",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
280,049 | <p>I want to know when an image has finished loading. Is there a way to do it with a callback?</p>
<p>If not, is there a way to do it at all?</p>
| [
{
"answer_id": 280087,
"author": "keparo",
"author_id": 19468,
"author_profile": "https://Stackoverflow.com/users/19468",
"pm_score": 6,
"selected": false,
"text": " window.onload = function () {\n\n var logo = document.getElementById('sologo');\n\n logo.onload = functio... | 2008/11/11 | [
"https://Stackoverflow.com/questions/280049",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
280,053 | <p>Please help! Have been staring at this for 12 hours; and have looked online and can't find solution.</p>
<p>In my application, I use 2 UIView controls in separate pages/controllers:</p>
<ul>
<li>UIImageView (retrieve data via
NSData dataWithContentsOfUrl)</li>
<li>UIWebView</li>
</ul>
<p>Just to isolate my code, and make it easier to explain, I created a new view based project called "MyTestApplication"</p>
<p>1 - I added a simple NSData dataWithContentsOfUrl in the delegate function.</p>
<pre><code>NSData *imageData = [NSData dataWithContentsOfURL:
[NSURL URLWithString:@"http://www.google.com/intl/en_ALL/images/logo.gif"]];
</code></pre>
<p>(Nothing to release here since it's all using convenience functions)</p>
<p><a href="http://img.skitch.com/20081110-j5tn5n7ixph95ys4rpchibaw5p.preview.jpg" rel="nofollow noreferrer">alt text http://img.skitch.com/20081110-j5tn5n7ixph95ys4rpchibaw5p.preview.jpg</a></p>
<p><a href="http://img.skitch.com/20081110-j5tn5n7ixph95ys4rpchibaw5p.jpg" rel="nofollow noreferrer">View Image</a></p>
<p>2 - Run it to verify no leaks (as expected)</p>
<p><a href="http://img.skitch.com/20081110-fy2qrkgy47hm4fe2f1aakd4muw.preview.jpg" rel="nofollow noreferrer">alt text http://img.skitch.com/20081110-fy2qrkgy47hm4fe2f1aakd4muw.preview.jpg</a></p>
<p><a href="http://img.skitch.com/20081110-fy2qrkgy47hm4fe2f1aakd4muw.jpg" rel="nofollow noreferrer">View Image</a></p>
<p>3 - Open the ViewController.xib and simply add a UIWebView from the library (no need to wire it up)</p>
<p><a href="http://img.skitch.com/20081110-d63c3yh1a1kqiciy73q8uyd68j.preview.jpg" rel="nofollow noreferrer">alt text http://img.skitch.com/20081110-d63c3yh1a1kqiciy73q8uyd68j.preview.jpg</a></p>
<p><a href="http://img.skitch.com/20081110-d63c3yh1a1kqiciy73q8uyd68j.jpg" rel="nofollow noreferrer">View Image</a></p>
<p>4 - Run it to verify there are leaks! (why???)</p>
<p><a href="http://img.skitch.com/20081110-qtxcfwntbcc3csabda3r6nfjg6.preview.jpg" rel="nofollow noreferrer">alt text http://img.skitch.com/20081110-qtxcfwntbcc3csabda3r6nfjg6.preview.jpg</a></p>
<p><a href="http://img.skitch.com/20081110-qtxcfwntbcc3csabda3r6nfjg6.jpg" rel="nofollow noreferrer">View Image</a></p>
<p>What am I doing wrong? Please help!</p>
<p>Why would NSData cause memory leak if I'm using UIWebView? I just don't get it.
Thanks. </p>
| [
{
"answer_id": 1442691,
"author": "Sam",
"author_id": 101750,
"author_profile": "https://Stackoverflow.com/users/101750",
"pm_score": 3,
"selected": false,
"text": "dataWithContentsOfURL:"
},
{
"answer_id": 30437935,
"author": "palob",
"author_id": 395963,
"author_pro... | 2008/11/11 | [
"https://Stackoverflow.com/questions/280053",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
280,058 | <p>Basically I need to insert a bunch of data to an Excel file. Creating an OleDB connection appears to be the fastest way but I've seen to have run into memory issues. The memory used by the process seems to keep growing as I execute INSERT queries. I've narrowed them down to only happen when I output to the Excel file (the memory holds steady without the output to Excel). I close and reopen the connection in between each worksheet, but this doesn't seem to have an effect on the memory usage (as so does Dispose()). The data is written successfully as I can verify with relatively small data sets. If anyone has insight, it would be appreciated.</p>
<p><em>initializeADOConn()</em> is called in the constructor</p>
<p><em>initADOConnInsertComm()</em> creates the insert parameterized insert query</p>
<p><em>writeRecord()</em> is called whenever a new record is written. New worksheets are created as needed.</p>
<pre><code>public bool initializeADOConn()
{
/* Set up the connection string and connect.*/
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + this.destination + ";Extended Properties=\"Excel 8.0;HDR=YES;\"";
//DbProviderFactory factory =
//DbProviderFactories.GetFactory("System.Data.OleDb");
conn = new OleDbConnection(connectionString);
conn.ConnectionString = connectionString;
conn.Open();
/* Intialize the insert command. */
initADOConnInsertComm();
return true;
}
public override bool writeRecord(FileListerFileInfo file)
{
/* If all available sheets are full, make a new one. */
if (numWritten % EXCEL_MAX_ROWS == 0)
{
conn.Close();
conn.Open();
createNextSheet();
}
/* Count this record as written. */
numWritten++;
/* Get all of the properties of the FileListerFileInfo record and add
* them to the parameters of the insert query. */
PropertyInfo[] properties = typeof(FileListerFileInfo).GetProperties();
for (int i = 0; i < insertComm.Parameters.Count; i++)
insertComm.Parameters[i].Value = properties[i].GetValue(file, null);
/* Add the record. */
insertComm.ExecuteNonQuery();
return true;
}
</code></pre>
<p>EDIT:</p>
<p>No, I do not use Excel at all. I'm intentionally avoiding Interop.Excel due to its poor performance (at least from my dabbles with it).</p>
| [
{
"answer_id": 280348,
"author": "onedaywhen",
"author_id": 15354,
"author_profile": "https://Stackoverflow.com/users/15354",
"pm_score": 1,
"selected": false,
"text": "CREATE TABLE"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/280058",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1469014/"
] |
280,069 | <p>I'm writing a C++ program that doesn't work (I get a segmentation fault) when I compile it with optimizations (options -O1, -O2, -O3, etc.), but it works just fine when I compile it without optimizations.</p>
<p>Is there any chance that the error is in my code? or should I assume that this is a bug in GCC?</p>
<p>My GCC version is 3.4.6.</p>
<p>Is there any known workaround for this kind of problem?</p>
<p>There is a big difference in speed between the optimized and unoptimized version of my program, so I really need to use optimizations.</p>
<hr>
<p>This is my original functor. The one that works fine with no levels of optimizations and throws a segmentation fault with any level of optimization:</p>
<pre><code>struct distanceToPointSort{
indexedDocument* point ;
distanceToPointSort(indexedDocument* p): point(p) {}
bool operator() (indexedDocument* p1,indexedDocument* p2){
return distance(point,p1) < distance(point,p2) ;
}
} ;
</code></pre>
<p>And this one works flawlessly with any level of optimization:</p>
<pre><code>struct distanceToPointSort{
indexedDocument* point ;
distanceToPointSort(indexedDocument* p): point(p) {}
bool operator() (indexedDocument* p1,indexedDocument* p2){
float d1=distance(point,p1) ;
float d2=distance(point,p2) ;
std::cout << "" ; //without this line, I get a segmentation fault anyways
return d1 < d2 ;
}
} ;
</code></pre>
<p>Unfortunately, this problem is hard to reproduce because it happens with some specific values. I get the segmentation fault upon sorting just one out of more than a thousand vectors, so it really depends on the specific combination of values each vector has.</p>
| [
{
"answer_id": 280080,
"author": "Adam Rosenfield",
"author_id": 9530,
"author_profile": "https://Stackoverflow.com/users/9530",
"pm_score": 3,
"selected": false,
"text": "-Wall"
},
{
"answer_id": 280082,
"author": "Martin York",
"author_id": 14065,
"author_profile": ... | 2008/11/11 | [
"https://Stackoverflow.com/questions/280069",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25700/"
] |
280,075 | <p>I'm trying to implement (what I think is) a pretty simple data model for a counter:</p>
<pre><code>class VisitorDayTypeCounter(models.Model):
visitType = models.CharField(max_length=60)
visitDate = models.DateField('Visit Date')
counter = models.IntegerField()
</code></pre>
<p>When someone comes through, it will look for a row that matches the visitType and visitDate; if this row doesn't exist, it will be created with counter=0.</p>
<p>Then we increment the counter and save.</p>
<p>My concern is that this process is totally a race. Two requests could simultaneously check to see if the entity is there, and both of them could create it. Between reading the counter and saving the result, another request could come through and increment it (resulting in a lost count).</p>
<p>So far I haven't really found a good way around this, either in the Django documentation or in the tutorial (in fact, it looks like the tutorial has a race condition in the Vote part of it).</p>
<p>How do I do this safely?</p>
| [
{
"answer_id": 280125,
"author": "Daniel Naab",
"author_id": 32638,
"author_profile": "https://Stackoverflow.com/users/32638",
"pm_score": 3,
"selected": false,
"text": "class VisitorDayTypeCounter(models.Model):\n visitType = models.CharField(max_length=60)\n visitDate = models.Da... | 2008/11/11 | [
"https://Stackoverflow.com/questions/280075",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13868/"
] |
280,101 | <p>What are the best ways (or at least most common ways) in ASP (VBScript) for input handling? My main concerns are HTML/JavaScript injections & SQL injections. Is there some equivalent to PHP's <code>htmlspecialchars</code> or <code>addslashes</code>, et cetera? Or do I have to do it manually with something like string replace functions?</p>
| [
{
"answer_id": 280259,
"author": "Tomalak",
"author_id": 18771,
"author_profile": "https://Stackoverflow.com/users/18771",
"pm_score": 4,
"selected": true,
"text": "Server.HTMLEncode()"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/280101",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25413/"
] |
280,106 | <p>I am implementing a Comment box facility in my application which user can resize using mouse. This comment box contains a scrollpane which instead contains a <code>JEditorPane</code> in which user can insert comment. I have added the editor pane inside a scroll pane for the following reason:</p>
<p><a href="https://stackoverflow.com/questions/271881/auto-scolling-of-jeditorpane">auto scolling of jeditorpane</a></p>
<p>When the user resizes the comment box, I am setting the desired size for <code>JScrollPane</code> and the <code>JEditorPane</code>. When the user is increasing the size of the comment box, the size of these components are increasing as desired but when the size of the comment box is decreased, the size of the <code>JEditorPane</code> does not decrease even after setting the size. This leads to the scrollbars inside the scrollpane.</p>
<p>I tried using <code>setPreferrredSize</code>, <code>setSize</code>, <code>setMaximumSize</code> for <code>JEditorPane</code>. Still the size of the editor pane is not reducing. I tried calling <code>revalidate()</code> or <code>updateUI()</code> after the setting of size but no use. </p>
<p>I am using Java 1.4.2. </p>
<p>Please provide me some insight....</p>
| [
{
"answer_id": 1525149,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "public static void main(String...args) {\n //our test frame\n JFrame frame = new JFrame(\"JEditorPane inside JScrollPan... | 2008/11/11 | [
"https://Stackoverflow.com/questions/280106",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22550/"
] |
280,107 | <p>I have often heard this term being used, but I have never really understood it.</p>
<p>What does it mean, and can anyone give some examples/point me to some links?</p>
<p>EDIT: Thanks to everyone for the replies. Can you also tell me how the canonical representation is useful in equals() performance, as stated in Effective Java?</p>
| [
{
"answer_id": 361827,
"author": "Dov Wasserman",
"author_id": 26010,
"author_profile": "https://Stackoverflow.com/users/26010",
"pm_score": 6,
"selected": false,
"text": "myFile.txt # in current working dir\n../conf/myFile.txt ... | 2008/11/11 | [
"https://Stackoverflow.com/questions/280107",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9195/"
] |
280,109 | <p>I'm creating a data entry app for some in-house stuff.</p>
<p>My team needs to enter info about "items" which can have many "categories" and vice versa.</p>
<p>I need a quick way to let them enter an arbitrary amount of categories.</p>
<p>Here's my idea:</p>
<p>On the item entry page, I'll have it so that initially there's one text input for "categories" and if it's tabbed out of while it's empty, the input field is deleted (unless it's the only one) and focus skips to the next field. If it's <em>not</em> empty when it's tabbed out of <strong>and</strong> if it's the last input field in the array, then an additional "category" text input will be added and focused.</p>
<p>This way people can enter an arbitrary amount of categories really quickly, without taking their hands off the keyboard, just by typing and hitting tab. Then hitting tab twice to denote the end of the list.</p>
<p>First of all, what do you think of this interface? Is there a better way to do it?</p>
<p>Second of all, is there a jQuery (or something) plugin to do this? I've searched but can't find one. I searched scriptaculous/prototype and mootools too, with no luck.</p>
<p>I would obviously rather use something tried and tested than roll my own.</p>
<p>Any and all advice appreciated</p>
| [
{
"answer_id": 361827,
"author": "Dov Wasserman",
"author_id": 26010,
"author_profile": "https://Stackoverflow.com/users/26010",
"pm_score": 6,
"selected": false,
"text": "myFile.txt # in current working dir\n../conf/myFile.txt ... | 2008/11/11 | [
"https://Stackoverflow.com/questions/280109",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
280,115 | <p>I am creating menus in WPF programatically using vb.net. Can someone show me how I can add separator bar to a menu in code? No xaml please.</p>
| [
{
"answer_id": 280194,
"author": "Jeff Donnici",
"author_id": 821,
"author_profile": "https://Stackoverflow.com/users/821",
"pm_score": 7,
"selected": true,
"text": "using System.Windows.Controls;\n\n//\n\nMenu myMenu = new Menu();\nmyMenu.Items.Add(new Separator());\n"
},
{
"ans... | 2008/11/11 | [
"https://Stackoverflow.com/questions/280115",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3566/"
] |
280,127 | <p>I'm bored with surrounding code with try catch like this..</p>
<pre><code>try
{
//some boring stuff
}
catch(Exception ex)
{
//something even more boring stuff
}
</code></pre>
<p>I would like something like</p>
<pre><code>SurroundWithTryCatch(MyMethod)
</code></pre>
<p>I know I can accomplish this behaviour by creating a delegate with the exact signature of the function, but creating a delegate for all the methods in my application it's just not an option.</p>
<p>I can also do this by injecting IL code but this is expensive in terms of performance as it creates an wrapper assembly around mine.</p>
<p>Any other valid ideeas?</p>
| [
{
"answer_id": 280132,
"author": "stiduck",
"author_id": 35398,
"author_profile": "https://Stackoverflow.com/users/35398",
"pm_score": 2,
"selected": false,
"text": "var user = db.Users.SingleOrDefault(u => u.Username == 3);\n\nif (user == null)\n throw new ArgumentNullException(\"Use... | 2008/11/11 | [
"https://Stackoverflow.com/questions/280127",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34296/"
] |
280,162 | <p>I have some low level serialization code that is templated, and I need to know the system's endianness at compiletime obviously (because the templates specializes based on the system's endianness). </p>
<p>Right now I have a header with some platform defines, but I'd rather have someway to make assertions about endianness with some templated test (like a static_assert or boost_if). Reason being my code will need to be compiled and ran on a wide range of machines, of many specialized vendor, and probably devices that don't exist in 2008, so I can't really guess what might need to go into that header years down the road. And since the code-base has an expected lifetime of about 10 years. So I can't follow the code for-ever.</p>
<p>Hopefully this makes my situation clear.</p>
<p>So does anyone know of a compile-time test that can determine endianness, without relying on vendor specific defines?</p>
| [
{
"answer_id": 280164,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 3,
"selected": false,
"text": "BOOST_STATIC_ASSERT(!BIG_ENDIAN);"
},
{
"answer_id": 280526,
"author": "Hasturkun",
"author... | 2008/11/11 | [
"https://Stackoverflow.com/questions/280162",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15124/"
] |
280,199 | <p>The library should;</p>
<ul>
<li>Be easy to use and few lines of client code should accomplish much</li>
<li>Be as platform independent as possible. (In case of future ports to other platforms)</li>
<li>Have C++ bindings.</li>
<li>Be mature and stable</li>
</ul>
<p>I would also like to be notified of most HID events through callbacks.</p>
<p>I have considered the following alternatives:</p>
<ul>
<li>libhid - (Unfortunately?) this is GPL and cannot be used in my application.</li>
<li>WDK - Seems to be a bit low-level for my use. I don’t need that kind of control.</li>
<li>atusbhid - This has an appropriate level of abstraction, but it is firmly tied to the Windows messaging loop</li>
</ul>
<p>Are there other alternatives to offer?</p>
| [
{
"answer_id": 508526,
"author": "Coderer",
"author_id": 26286,
"author_profile": "https://Stackoverflow.com/users/26286",
"pm_score": 2,
"selected": false,
"text": "HKML\\SYSTEM\\CCS\\Control\\DeviceClasses\\{4d1e55...}\\"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/280199",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36112/"
] |
280,201 | <p>In a html page we use the head tag to add reference to our external .js files .. we can also include script tags in the body .. But how do we include our external .js file in a web user control?</p>
<p>After little googling I got this. It works but is this the only way?</p>
<pre><code>ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "MyUniquekey", @"<script src=""myJsFile.js"" type=""text/javascript""></script>", false);
</code></pre>
<p>-- Zuhaib</p>
| [
{
"answer_id": 280338,
"author": "Phil Jenkins",
"author_id": 35496,
"author_profile": "https://Stackoverflow.com/users/35496",
"pm_score": 3,
"selected": true,
"text": "Page.ClientScript.RegisterClientScriptInclude(\"key\", \"path/to/script.js\");\n"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/280201",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25138/"
] |
280,207 | <p>I have an object.</p>
<pre><code> fp = open(self.currentEmailPath, "rb")
p = email.Parser.Parser()
self._currentEmailParsedInstance= p.parse(fp)
fp.close()
</code></pre>
<p>self.currentEmailParsedInstance, from this object I want to get the body of an email, text only no HTML....</p>
<p>How do I do it?</p>
<hr>
<p>something like this? </p>
<pre><code> newmsg=self._currentEmailParsedInstance.get_payload()
body=newmsg[0].get_content....?
</code></pre>
<p>then strip the html from body.
just what is that .... method to return the actual text... maybe I mis-understand you</p>
<pre><code> msg=self._currentEmailParsedInstance.get_payload()
print type(msg)
</code></pre>
<p>output = type 'list'</p>
<hr>
<p>the email </p>
<p>Return-Path: <br>
Received: from xx.xx.net (example) by mxx3.xx.net (xxx)<br>
id 485EF65F08EDX5E12 for xxx@xx.com; Thu, 23 Oct 2008 06:07:51 +0200<br>
Received: from xxxxx2 (ccc) by example.net (ccc) (authenticated as xxxx.xxx@example.com)
id 48798D4001146189 for example.example@example-example.com; Thu, 23 Oct 2008 06:07:51 +0200<br>
From: "example" <br>
To: <br>
Subject: FW: example
Date: Thu, 23 Oct 2008 12:07:45 +0800<br>
Organization: example
Message-ID: <001601c934c4$xxxx30$a9ff460a@xxx><br>
MIME-Version: 1.0<br>
Content-Type: multipart/mixed;<br>
boundary="----=_NextPart_000_0017_01C93507.F6F64E30"<br>
X-Mailer: Microsoft Office Outlook 11<br>
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3138<br>
Thread-Index: Ack0wLaumqgZo1oXSBuIpUCEg/wfOAABAFEA </p>
<p>This is a multi-part message in MIME format. </p>
<p>------=_NextPart_000_0017_01C93507.F6F64E30<br>
Content-Type: multipart/alternative;<br>
boundary="----=_NextPart_001_0018_01C93507.F6F64E30" </p>
<p>------=_NextPart_001_0018_01C93507.F6F64E30<br>
Content-Type: text/plain;<br>
charset="us-ascii"<br>
Content-Transfer-Encoding: 7bit </p>
<p>From: example.example[mailto:example@example.com]<br>
Sent: Thursday, October 23, 2008 11:37 AM<br>
To: xxxx@example.com<br>
Subject: S/I for example(B/L<br>
No.:4357-0120-810.044) </p>
<p>Please find attached the example.doc), </p>
<p>Thanks. </p>
<p>B.rgds, </p>
<p>xxx xxx </p>
<p>------=_NextPart_001_0018_01C93507.F6F64E30<br>
Content-Type: text/html;<br>
charset="us-ascii"<br>
Content-Transfer-Encoding: quoted-printable </p>
<p>
xmlns:o=3D"urn:schemas-microsoft-com:office:office" =<br>
xmlns:w=3D"urn:schemas-microsoft-com:office:word" =<br>
xmlns:st1=3D"urn:schemas-microsoft-com:office:smarttags" =<br>
xmlns=3D"<a href="http://www.w3.org/TR/REC-html40" rel="nofollow noreferrer">http://www.w3.org/TR/REC-html40</a>"> </p>
<p>HTML STUFF till </p>
<p>------=_NextPart_001_0018_01C93507.F6F64E30-- </p>
<p>------=_NextPart_000_0017_01C93507.F6F64E30<br>
Content-Type: application/msword;<br>
name="xxxx.doc"<br>
Content-Transfer-Encoding: base64<br>
Content-Disposition: attachment;<br>
filename="xxxx.doc" </p>
<p>0M8R4KGxGuEAAAAAAAAAAAAAAAAAAAAAPgADAP7/CQAGAAAAAAAAAAAAAAABAAAAYAAAAAAAAAAA
EAAAYgAAAAEAAAD+////AAAAAF8AAAD/////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////s
pcEAI2AJBAAA+FK/AAAAAAAAEAAAAAAABgAAnEIAAA4AYmpiaqEVoRUAAAAAAAAAAAAAAAAAAAAA
AAAECBYAMlAAAMN/AADDfwAAQQ4AAAAAAAAPAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD//w8AAAAA
AAAAAAD//w8AAAAAAAAAAAD//w8AAAAAAAAAAAAAAAAAAAAAAKQAAAAAAEYEAAAAAAAARgQAAEYE
AAAAAAAARgQAAAAAAABGBAAAAAAAAEYEAAAAAAAARgQAABQAAAAAAAAAAAAAAFoEAAAAAAAA4hsA
AAAAAADiGwAAAAAAAOIbAAA4AAAAGhwAAHwAAACWHAAARAAAAFoEAAAAAAAABzcAAEgBAADmHAAA
FgAAAPwcAAAAAAAA/BwAAAAAAAD8HAAAAAAAAPwcAAAAAAAA/BwAAAAAAAD8HAAAAAAAAPwcAAAA
AAAAMjYAAAIAAAA0NgAAAAAAADQ2AAAAAAAANDYAAAAAAAA0NgAAAAAAADQ2AAAAAAAANDYAACQA
AABPOAAAaAIAALc6AACOAAAAWDYAAGkAAAAAAAAAAAAAAAAAAAAAAAAARgQAAAAAAABHLAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAD8HAAAAAAAAPwcAAAAAAAARywAAAAAAABHLAAAAAAAAFg2AAAAAAAA</p>
<p>------=_NextPart_000_0017_01C93507.F6F64E30-- </p>
<hr>
<p>I just want to get : </p>
<p>From: xxxx.xxxx [mailto:xxxx@example.com]<br>
Sent: Thursday, October 23, 2008 11:37 AM<br>
To: xxxx@example.com<br>
Subject: S/I for xxxxx (B/L<br>
No.:4357-0120-810.044) </p>
<p>Pls find attached the xxxx.doc), </p>
<p>Thanks. </p>
<p>B.rgds, </p>
<p>xxx xxx </p>
<hr>
<p>not sure if the mail is malformed!
seems if you get an html page you have to do this:</p>
<pre><code> parts=self._currentEmailParsedInstance.get_payload()
print parts[0].get_content_type()
..._multipart/alternative_
textParts=parts[0].get_payload()
print textParts[0].get_content_type()
..._text/plain_
body=textParts[0].get_payload()
print body
...get the text without a problem!!
</code></pre>
<p>thank you so much Vinko.</p>
<p>So its kinda like dealing with xml, recursive in nature.</p>
| [
{
"answer_id": 280238,
"author": "Vinko Vrsalovic",
"author_id": 5190,
"author_profile": "https://Stackoverflow.com/users/5190",
"pm_score": 3,
"selected": true,
"text": "self.currentEmailParsedInstance.get_payload()\n"
},
{
"answer_id": 280562,
"author": "Setori",
"autho... | 2008/11/11 | [
"https://Stackoverflow.com/questions/280207",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21537/"
] |
280,222 | <p>I have input consisting of a list of nested lists like this:</p>
<pre><code>l = [[[[[39]]]], [1, 2, 3], [4, [5, 3], 1], [[[[8, 9], 10], 11], 12]]
</code></pre>
<p>I want to sort this list based on the sum of all the numbers in the nested lists... so, the values I want to sort by of l would look like this:</p>
<pre><code>[39, 6, 13, 50]
</code></pre>
<p>Then I want to sort based on these. So the output should be:</p>
<pre><code>[[1, 2, 3], [4, [5, 3], 1], [[[[39]]]], [[[[8, 9], 10], 11], 12]]
</code></pre>
<p>What's a nice pythonic way of doing this?</p>
| [
{
"answer_id": 280224,
"author": "jfs",
"author_id": 4279,
"author_profile": "https://Stackoverflow.com/users/4279",
"pm_score": 3,
"selected": false,
"text": "l.sort(key=sum_nested)\n"
},
{
"answer_id": 280226,
"author": "Greg Hewgill",
"author_id": 893,
"author_prof... | 2008/11/11 | [
"https://Stackoverflow.com/questions/280222",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15055/"
] |
280,229 | <p>I want to add an item to an ASP.Net combobox using Javascript. I can retrieve the ID (No Masterpage). How can I add values to the combobox from Javascript? My present code looks like this.</p>
<pre><code> //Fill the years (counting 100 from the first)
function fillvarYear() {
var dt = $('#txtBDate').val();
dt = dt.toString().substring(6);
var ye = parseInt(dt);
//Loop and add the next 100 years from the birth year to the combo
for (var j = 1; j <= 100; j++) {
ye += 1; //Add one year to the year count
var opt = document.createElement("OPTION");
opt.text = ye;
opt.value = ye;
document.form1.ddlYear.add(opt);
}
}
</code></pre>
| [
{
"answer_id": 280520,
"author": "FlySwat",
"author_id": 1965,
"author_profile": "https://Stackoverflow.com/users/1965",
"pm_score": 2,
"selected": true,
"text": "string selectedValue = Request.Params[combobox.UniqueId]\n"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/280229",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33052/"
] |
280,243 | <p>What's the easiest way to use a linked list in python? In scheme, a linked list is defined simply by <code>'(1 2 3 4 5)</code>. Python's lists, <code>[1, 2, 3, 4, 5]</code>, and tuples, <code>(1, 2, 3, 4, 5)</code>, are not, in fact, linked lists, and linked lists have some nice properties such as constant-time concatenation, and being able to reference separate parts of them. Make them immutable and they are really easy to work with!</p>
| [
{
"answer_id": 280284,
"author": "Martin v. Löwis",
"author_id": 33006,
"author_profile": "https://Stackoverflow.com/users/33006",
"pm_score": 4,
"selected": false,
"text": "def mklist(*args):\n result = None\n for element in reversed(args):\n result = (element, result)\n ... | 2008/11/11 | [
"https://Stackoverflow.com/questions/280243",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15055/"
] |
280,247 | <p>I've tried my best and cannot figure out what happened here. It worked fine in Delphi 4. After upgrading to Delphi 2009, I don't know if this is the way it is supposed to work, or if it's a problem:</p>
<p>This is what my program's menu looks like in Design Mode under Delphi 2009:</p>
<p><a href="https://i.stack.imgur.com/lg57M.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lg57M.gif" alt="enter image description here"></a></p>
<p>Notice that every word in the Main Menu and the File submenu have one letter underlined. It is supposed to be like this. This underlined letter is called the Accelerator Key and is standard in Windows applications so that you can use the Alt-key and that letter to quickly select the menu item and then submenu item with the keyboard rather than with your mouse.</p>
<p>You get them this way by using the "&" character as part of the caption of the item, for example: Save &As...</p>
<p>When I run my application, and use the mouse to open the File menu, it looks like this:</p>
<p><a href="https://i.stack.imgur.com/zpw14.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zpw14.gif" alt="enter image description here"></a></p>
<p>The characters are underlined in the main menu, but are not underlined in the File menu.</p>
<p>If instead, I use the Alt-F key to open up the File submenu, then it looks correct like this:</p>
<p><a href="https://i.stack.imgur.com/Hxwn0.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Hxwn0.gif" alt="enter image description here"></a></p>
<p>and all the Accelerator Key letters are properly underlined.</p>
<p>I've played with the AutoHotKeys option but that's not the problem.</p>
<p>Has someone encountered this problem before? Is the example in the 2nd image correct behavior that I don't know of? Or is there some option or coding mistake that I might have missed?</p>
<hr>
<p>Nov 2009 (one year later): mghie seems to have got to the root of this and figured out the problem. See his accepted answer below.</p>
| [
{
"answer_id": 280289,
"author": "mghie",
"author_id": 30568,
"author_profile": "https://Stackoverflow.com/users/30568",
"pm_score": 4,
"selected": true,
"text": "WM_DRAWITEM"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/280247",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30176/"
] |
280,249 | <p>I have created a site, which parses XML files and display its content on the appropriate page. Is my site a dynamic web page or static web page?</p>
<p>How do dynamic and static web pages differ?</p>
<p>I feel it's dynamic, because I parse the content from xml files; initially i don't have any content in my main page..</p>
<p>What do you think about this, please explain it..</p>
| [
{
"answer_id": 280330,
"author": "dbr",
"author_id": 745,
"author_profile": "https://Stackoverflow.com/users/745",
"pm_score": 2,
"selected": false,
"text": "/view.php?page=index"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/280249",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
280,260 | <p>EDIT: <strong>I would really like to see some general discussion about the formats, their pros and cons!</strong></p>
<p>EDIT2: The 'bounty didn't really help to create the needed discussion, there are a few interesting answers but the comprehensive coverage of the topic is still missing. Six persons marked the question as favourites, which shows me that there is an interest in this discussion.</p>
<p>When deciding about <strong>internationalization</strong> the toughest part IMO is the choice of storage format.</p>
<p>For example the Zend PHP Framework offers the following adapters which cover pretty much all my options:</p>
<ul>
<li>Array : no, hard to maintain</li>
<li><strong>CSV : don't know, possible problems with encoding</strong></li>
<li><strong>Gettext : frequently used, poEdit for all platforms available BUT complicated</strong></li>
<li><strong>INI : don't know, possible problems with encoding</strong></li>
<li>TBX : no clue</li>
<li>TMX : too much of a big thing? no editors freely available.</li>
<li>QT : not very widespread, no free tools</li>
<li><strong>XLIFF : the comming standard? BUT no free tools available.</strong></li>
<li>XMLTM : no, not what I need</li>
</ul>
<p>basically I'm stuck with the 4 'bold' choices. I would like to use INI files but I'm reading about the encoding problems... is it really a problem, if I use strict UTF-8 (files, connections, db, etc.)?</p>
<p>I'm on Windows and I tried to figure out how poEdit functions but just didn't manage. No tutorials on the web either, is <strong>gettext</strong> still a choice or an endangered species anyways?</p>
<p>What about <strong>XLIFF</strong>, has anybody worked with it? Any tips on what tools to use?</p>
<p>Any ideas for <strong>Eclipse</strong> integration of any of these technologies?</p>
| [
{
"answer_id": 280291,
"author": "Josh",
"author_id": 10902,
"author_profile": "https://Stackoverflow.com/users/10902",
"pm_score": 4,
"selected": false,
"text": "_(\"Text\"), gettext(\"Text\")"
},
{
"answer_id": 501722,
"author": "John Nilsson",
"author_id": 24243,
"... | 2008/11/11 | [
"https://Stackoverflow.com/questions/280260",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11995/"
] |
280,270 | <p>Using LINQ to Entities sounds like a great way to query against a database and get actual CLR objects that I can modify, data bind against and so forth. But if I perform the same query a second time do I get back references to the same CLR objects or an entirely new set? </p>
<p>I do not want multiple queries to generate an ever growing number of copies of the same actual data. The problem here is that I could alter the contents of one entity and save it back to the database but another instance of the entity is still in existence elsewhere and holding the old data.</p>
| [
{
"answer_id": 280335,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 0,
"selected": false,
"text": "// uses object identity cache (IIRC)\nvar obj = ctx.Single(x=>x.Id == id);\n"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/280270",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6276/"
] |
280,298 | <p>A complicated-sounding term with no good explanations from a simple google search... are there any more academically-oriented folk who could explain this one?</p>
| [
{
"answer_id": 286474,
"author": "Claudiu",
"author_id": 15055,
"author_profile": "https://Stackoverflow.com/users/15055",
"pm_score": 3,
"selected": true,
"text": "public class Hey<T>\n{\n public T idOrInc(T var)\n {\n if (var instanceof Integer)\n return (T)(new... | 2008/11/11 | [
"https://Stackoverflow.com/questions/280298",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15055/"
] |
280,313 | <p>I am trying to merge several XML files in a single XDocument object.</p>
<p>Merge does not exist in XDocument object. I miss this.</p>
<p>Has anyone already implemented a Merge extension method for XDocument, or something similar ?</p>
| [
{
"answer_id": 280379,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 2,
"selected": false,
"text": "XDocument"
},
{
"answer_id": 280512,
"author": "Larry",
"author_id": 24472,
"author_profile": "ht... | 2008/11/11 | [
"https://Stackoverflow.com/questions/280313",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24472/"
] |
280,324 | <p>I have been using classes for only a short while and when I write a method, I make all variables reference self, e.g. self.foo.</p>
<p>However, I'm looking through the <em>wxPython in Action</em> book and notice that "self" isn't used all the time. For example:</p>
<pre><code> import wx
class TextFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Text Entry Example',
size=(300, 100))
panel = wx.Panel(self, -1)
basicLabel = wx.StaticText(panel, -1, "Basic Control:")
basicText = wx.TextCtrl(panel, -1, "I've entered some text!",
size=(175, -1))
basicText.SetInsertionPoint(0)
pwdLabel = wx.StaticText(panel, -1, "Password:")
pwdText = wx.TextCtrl(panel, -1, "password", size=(175, -1),
style=wx.TE_PASSWORD)
sizer = wx.FlexGridSizer(cols=2, hgap=6, vgap=6)
sizer.AddMany([basicLabel, basicText, pwdLabel, pwdText])
panel.SetSizer(sizer)
</code></pre>
<p>The one below does use "self".</p>
<pre><code>import wx
class ButtonFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Button Example',
size=(300, 100))
panel = wx.Panel(self, -1)
self.button = wx.Button(panel, -1, "Hello", pos=(50, 20))
self.Bind(wx.EVT_BUTTON, self.OnClick, self.button)
self.button.SetDefault()
def OnClick(self, event):
self.button.SetLabel("Clicked")
</code></pre>
<p>If I remember correctly, "self" is reference to a particular instance of the class, so when is it not necessary? Is there a general rule of thumb?</p>
| [
{
"answer_id": 280332,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 2,
"selected": false,
"text": "self"
},
{
"answer_id": 280561,
"author": "Community",
"author_id": -1,
"author_profile": "https://St... | 2008/11/11 | [
"https://Stackoverflow.com/questions/280324",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18676/"
] |
280,331 | <p>This seems like it should be easy but I'm stumped. In WPF, I'd like a TextBox that stretches to the width of it's parent, but only to a maximum width. The problem is that I want it to be left justified within its parent. To get it to stretch you have to use HorizontalAlignment="Stretch", but then the result is centered. I've experimented with HorizontalContentAlignment, but it doesn't seem to do anything.</p>
<p>How do I get this blue text box to grow with the size of the window, have a maximum width of 200 pixels, and be left justified?</p>
<pre><code><Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel>
<TextBox Background="Azure" Text="Hello" HorizontalAlignment="Stretch" MaxWidth="200" />
</StackPanel>
</Page>
</code></pre>
<p>What's the trick?</p>
| [
{
"answer_id": 280402,
"author": "Kent Boogaart",
"author_id": 5380,
"author_profile": "https://Stackoverflow.com/users/5380",
"pm_score": 6,
"selected": false,
"text": "<Grid>\n <Grid.ColumnDefinitions>\n <ColumnDefinition Width=\"*\" MaxWidth=\"200\"/>\n </Grid.ColumnDefin... | 2008/11/11 | [
"https://Stackoverflow.com/questions/280331",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9045/"
] |
280,345 | <p>I'm trying to start <code>iexplore.exe</code> let it run for 5 seconds and then close it again.</p>
<p><code>iexplore</code> opens just fine however it doesn't close when I call the PostThreadMessage.
Can anyone see what I'm doing wrong? Here is my code:</p>
<pre><code>CString IEPath = "C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE";//GetIEPath();
//IEPath += ' ' + url;
std::string strCommand((LPCTSTR)IEPath);
PROCESS_INFORMATION procinfo;
STARTUPINFO startupinfo;
GetStartupInfo(&startupinfo);
CreateProcess(
NULL,
(char *)strCommand.c_str(),// name of executable module
NULL, // lpProcessAttributes
NULL, // lpThreadAttributes
false, // handle inheritance option
CREATE_SHARED_WOW_VDM, // creation flags
NULL, // new environment block
NULL, // current directory name
&startupinfo, // startup information
&procinfo // process information
);
Sleep(5000);
::PostThreadMessage(procinfo.dwThreadId, WM_QUIT, 0, 0); //<---Dosent Close internet explorer!
</code></pre>
<p>Anyone have an idea of what I'm doing wrong? Or is there better way what to do the trick?</p>
| [
{
"answer_id": 280377,
"author": "schnaader",
"author_id": 34065,
"author_profile": "https://Stackoverflow.com/users/34065",
"pm_score": 1,
"selected": false,
"text": "TerminateProcess(procinfo.hProcess, 0);\n"
}
] | 2008/11/11 | [
"https://Stackoverflow.com/questions/280345",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36476/"
] |
280,347 | <p>How to convert Unicode string into a utf-8 or utf-16 string?
My VS2005 project is using Unicode char set, while sqlite in cpp provide </p>
<pre><code>int sqlite3_open(
const char *filename, /* Database filename (UTF-8) */
sqlite3 **ppDb /* OUT: SQLite db handle */
);
int sqlite3_open16(
const void *filename, /* Database filename (UTF-16) */
sqlite3 **ppDb /* OUT: SQLite db handle */
);
</code></pre>
<p>for opening a folder.
How can I convert string, CString, or wstring into UTF-8 or UTF-16 charset?</p>
<p>Thanks very much!</p>
| [
{
"answer_id": 280358,
"author": "1800 INFORMATION",
"author_id": 3146,
"author_profile": "https://Stackoverflow.com/users/3146",
"pm_score": 3,
"selected": false,
"text": "CP_UTF8"
},
{
"answer_id": 280360,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"aut... | 2008/11/11 | [
"https://Stackoverflow.com/questions/280347",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25749/"
] |
280,356 | <p>In my webpage, I want the website to greet the user, but the username is surrounded by 'single quotations'. Since this isn't to prevent MySQL injection, i just want to remove quotes around my name on the display page.</p>
<p>Ex: Welcome 'user'!
I'm trying to find the way where i can strip the quotations around the user and have it display on the example below.</p>
<p>Ex: Welcome user!</p>
<p>The only line of code that I can think relating is this:</p>
<p>$login = $_SESSION['login'];</p>
<p>Does anyone know how to strip single lines quotes?</p>
| [
{
"answer_id": 280366,
"author": "davil",
"author_id": 22592,
"author_profile": "https://Stackoverflow.com/users/22592",
"pm_score": 1,
"selected": false,
"text": "echo 'Welcome ' . trim($login, \"'\");\n"
},
{
"answer_id": 280368,
"author": "Stefan Gehrig",
"author_id": ... | 2008/11/11 | [
"https://Stackoverflow.com/questions/280356",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
280,363 | <p>Spring IoC container gives you <a href="http://static.springframework.org/spring/docs/2.5.x/reference/beans.html#beans-factory-arbitrary-method-replacement" rel="nofollow noreferrer">an option</a> of replacing a method of a bean. Can someone provide a real life example of using this feature to solve real life problem?</p>
<p>I can see this used for adapting an old legacy code (w/o sources) to work with your app. But I think I would consider writing an adapter class using the legacy code directly instead of Spring method replacement approach.</p>
| [
{
"answer_id": 280433,
"author": "MrM",
"author_id": 319803,
"author_profile": "https://Stackoverflow.com/users/319803",
"pm_score": 0,
"selected": false,
"text": "<bean id=\"propertyConfigurer\" class=\"org.springframework.beans.factory.config.PropertyPlaceholderConfigurer\">\n ... | 2008/11/11 | [
"https://Stackoverflow.com/questions/280363",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4052/"
] |
280,378 | <p>I read a little of the help for my advanced installer 6.5.1 and couldn't find a way to change the version string except by hand.</p>
| [
{
"answer_id": 2076057,
"author": "Fred",
"author_id": 251983,
"author_profile": "https://Stackoverflow.com/users/251983",
"pm_score": 3,
"selected": false,
"text": ":COMPILE_AIP\n\nSET AIP_DIR=\"C:\\Program Files\\Caphyon\\Advanced Installer 7.1.3\"\n\nECHO Advanced Installer Directiry:... | 2008/11/11 | [
"https://Stackoverflow.com/questions/280378",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30324/"
] |
280,385 | <p>Let's say we have a method signature like </p>
<pre><code>public static function explodeDn($dn, array &$keys = null, array &$vals = null,
$caseFold = self::ATTR_CASEFOLD_NONE)
</code></pre>
<p>we can easily call the method by omitting all parameters after <code>$dn</code>:</p>
<pre><code>$dn=Zend_Ldap_Dn::explodeDn('CN=Alice Baker,CN=Users,DC=example,DC=com');
</code></pre>
<p>We can also call the method with 3 parameters:</p>
<pre><code>$dn=Zend_Ldap_Dn::explodeDn('CN=Alice Baker,CN=Users,DC=example,DC=com', $k, $v);
</code></pre>
<p>and with 4 parameters:</p>
<pre><code>$dn=Zend_Ldap_Dn::explodeDn('CN=Alice Baker,CN=Users,DC=example,DC=com', $k, $v,
Zend_Ldap_Dn::ATTR_CASEFOLD_UPPER);
</code></pre>
<p>But why is it impossible to call the method with the following parameter combination for example:</p>
<pre><code>$dn=Zend_Ldap_Dn::explodeDn('CN=Alice Baker,CN=Users,DC=example,DC=com', $k, null,
Zend_Ldap_Dn::ATTR_CASEFOLD_UPPER);
$dn=Zend_Ldap_Dn::explodeDn('CN=Alice Baker,CN=Users,DC=example,DC=com', null, $v);
</code></pre>
<p>What's the difference between passing <code>null</code> to the method and relying on the default value? Is this constraint written in the manual? Can it be circumvented?</p>
| [
{
"answer_id": 280404,
"author": "Stefan Gehrig",
"author_id": 11354,
"author_profile": "https://Stackoverflow.com/users/11354",
"pm_score": 1,
"selected": false,
"text": "$k=array();\n$v=null;\n$dn=Zend_Ldap_Dn::explodeDn('CN=Alice Baker,CN=Users,DC=example,DC=com', $k, $v, \n Zend_L... | 2008/11/11 | [
"https://Stackoverflow.com/questions/280385",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11354/"
] |
280,389 | <pre><code>function main()
{
Hello();
}
function Hello()
{
// How do you find out the caller function is 'main'?
}
</code></pre>
<p>Is there a way to find out the call stack?</p>
| [
{
"answer_id": 280396,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 11,
"selected": true,
"text": "function Hello()\n{\n alert(\"caller is \" + Hello.caller);\n}\n"
},
{
"answer_id": 280466,
"author": "Pab... | 2008/11/11 | [
"https://Stackoverflow.com/questions/280389",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11413/"
] |
280,406 | <p>I have problems with bringing a windows mobile 6 form to the front.
I tried things like this already</p>
<pre><code>Form1 testForm = new Form1();
testForm.Show();
testForm.BringToFront();
testForm.Focus();
</code></pre>
<p>But it's always behind the form that includes that code.
The only things that have worked for me are</p>
<pre><code>testForm.TopMost = true;
</code></pre>
<p>or Hide(); the old form and then show the new one, but i want to avoid hiding the other form. TopMost isn't very clean anyway with using multiple other forms.</p>
<p>The other thing that works is</p>
<pre><code>testForm.ShowDialog();
</code></pre>
<p>but I don't want to show the form modal.</p>
<p>To cut it short. I just want to show the new form in front of another form, and if I close it, I want to see the old form again.</p>
<p>Maybe someone can help me with this problem. Thank you.</p>
| [
{
"answer_id": 280478,
"author": "kgiannakakis",
"author_id": 24054,
"author_profile": "https://Stackoverflow.com/users/24054",
"pm_score": 3,
"selected": true,
"text": "[DllImport(\"coredll.dll\")]\nprivate static extern IntPtr FindWindow(string lpClassName, string lpWindowName);\n\n[Dl... | 2008/11/11 | [
"https://Stackoverflow.com/questions/280406",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36481/"
] |
280,413 | <p><strong>Closed as exact duplicate of <a href="https://stackoverflow.com/questions/171970/how-can-i-find-the-method-that-called-the-current-method">"How can I find the method that called the current method?"</a></strong></p>
<p>Is <a href="https://stackoverflow.com/questions/280389/javascript-how-do-you-find-the-caller-function">this</a> possible with c#?</p>
<pre><code>void main()
{
Hello();
}
void Hello()
{
// how do you find out the caller is function 'main'?
}
</code></pre>
| [
{
"answer_id": 280425,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 5,
"selected": true,
"text": "Console.WriteLine(new StackFrame(1).GetMethod().Name);\n"
},
{
"answer_id": 280432,
"author": "schnaader",... | 2008/11/11 | [
"https://Stackoverflow.com/questions/280413",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31505/"
] |
280,421 | <p>It seems that when I have one mysql_real_query() function in a continuous while loop, the query will get executed OK.</p>
<p>However, if multiple mysql_real_query() are inside the while loop, one right after the other. Depending on the query, sometimes neither the first query nor second query will execute properly.</p>
<p>This seems like a threading issue to me. I'm wondering if the mysql c api has a way of dealing with this? Does anyone know how to deal with this? mysql_free_result() doesn't work since I am not even storing the results.</p>
<pre><code>//keep polling as long as stop character '-' is not read
while(szRxChar != '-')
{
// Check if a read is outstanding
if (HasOverlappedIoCompleted(&ovRead))
{
// Issue a serial port read
if (!ReadFile(hSerial,&szRxChar,1,
&dwBytesRead,&ovRead))
{
DWORD dwErr = GetLastError();
if (dwErr!=ERROR_IO_PENDING)
return dwErr;
}
}
// Wait 5 seconds for serial input
if (!(HasOverlappedIoCompleted(&ovRead)))
{
WaitForSingleObject(hReadEvent,RESET_TIME);
}
// Check if serial input has arrived
if (GetOverlappedResult(hSerial,&ovRead,
&dwBytesRead,FALSE))
{
// Wait for the write
GetOverlappedResult(hSerial,&ovWrite,
&dwBytesWritten,TRUE);
//load tagBuffer with byte stream
tagBuffer[i] = szRxChar;
i++;
tagBuffer[i] = 0; //char arrays are \0 terminated
//run query with tagBuffer
if( strlen(tagBuffer)==PACKET_LENGTH )
{
sprintf(query,"insert into scan (rfidnum) values ('");
strcat(query, tagBuffer);
strcat(query, "')");
mysql_real_query(&mysql,query,(unsigned int)strlen(query));
i=0;
}
mysql_real_query(&mysql,"insert into scan (rfidnum) values ('2nd query')",(unsigned int)strlen("insert into scan (rfid) values ('2nd query')"));
mysql_free_result(res);
}
}
</code></pre>
| [
{
"answer_id": 280456,
"author": "Alnitak",
"author_id": 6782,
"author_profile": "https://Stackoverflow.com/users/6782",
"pm_score": 0,
"selected": false,
"text": "tagBuffer"
},
{
"answer_id": 282302,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "htt... | 2008/11/11 | [
"https://Stackoverflow.com/questions/280421",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28462/"
] |
280,426 | <p>We've got a fairly complex httphandler for handling images. Basically it streams any part of the image at any size that is requested. Some clients use this handler without any problems. But we've got one location that gives us problems, and now it also gives problems on my development environment.</p>
<p>What happens is that the client never receives anything on some requests. So request 1 and 2 are fine, but request 3 and 4 never end. </p>
<ul>
<li>While debugging I can see that the server is ready and has completed the request.</li>
<li>The client however is still waiting on a result (debugging with fiddler2 shows that there is no response received)</li>
</ul>
<p>The code that we use to stream an image is</p>
<pre><code> if (!context.Response.IsClientConnected)
{
imageStream.Close();
imageStream.Dispose();
return;
}
context.Response.BufferOutput = true;
context.Response.ContentType = "image/" + imageformat;
context.Response.AppendHeader("Content-Length", imageStream.Length.ToString());
if (imageStream != null && imageStream.Length > 0 && context.Response.IsClientConnected)
context.Response.BinaryWrite(imageStream.ToArray());
if (context.Response.IsClientConnected)
context.Response.Flush();
imageStream.Close();
imageStream.Dispose();
</code></pre>
<p>The imageStream is a MemoryStream with the contents of an image.</p>
<p>After the call to response.Flush() we do some more clean-up and writing summaries to the eventlog. </p>
<p>We also call GC.Collect() after every request, because the objects that we use in-memory become very large. I know that that is not a good practice, but could it give us trouble?</p>
<p>The problems with not returning requests happen at both IIS 5 (Win XP) and IIS 6 (Win 2003), we use .NET framework v2.</p>
| [
{
"answer_id": 280436,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 2,
"selected": false,
"text": "MemoryStream"
},
{
"answer_id": 280438,
"author": "Jon Skeet",
"author_id": 22656,
"author_profil... | 2008/11/11 | [
"https://Stackoverflow.com/questions/280426",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5043/"
] |
280,428 | <p>I have one autocomplete search, in which by typing few characters it will show all the names, which matches the entered character. I am populating this data in the jsp using DIV tag, by using mouse I'm able to select the names. But I want to select the names in the DIV tag to be selected using the keyboard up and down arrow. Can anyone please help me out from this.</p>
| [
{
"answer_id": 280455,
"author": "Shivasubramanian A",
"author_id": 9195,
"author_profile": "https://Stackoverflow.com/users/9195",
"pm_score": 0,
"selected": false,
"text": "event.keyCode"
},
{
"answer_id": 375426,
"author": "EndangeredMassa",
"author_id": 106,
"auth... | 2008/11/11 | [
"https://Stackoverflow.com/questions/280428",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
280,435 | <p>I want to use input from a user as a regex pattern for a search over some text. It works, but how I can handle cases where user puts characters that have meaning in regex?</p>
<p>For example, the user wants to search for Word <code>(s)</code>: regex engine will take the <code>(s)</code> as a group. I want it to treat it like a string <code>"(s)" </code>. I can run <code>replace</code> on user input and replace the <code>(</code> with <code>\(</code> and the <code>)</code> with <code>\)</code> but the problem is I will need to do replace for every possible regex symbol.</p>
<p>Do you know some better way ?</p>
| [
{
"answer_id": 280441,
"author": "ddaa",
"author_id": 11549,
"author_profile": "https://Stackoverflow.com/users/11549",
"pm_score": 10,
"selected": true,
"text": "re.escape()"
},
{
"answer_id": 280463,
"author": "gimel",
"author_id": 6491,
"author_profile": "https://S... | 2008/11/11 | [
"https://Stackoverflow.com/questions/280435",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/288629/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.