qid int64 4 22.2M | question stringlengths 18 48.3k | answers list | date stringlengths 10 10 | metadata list |
|---|---|---|---|---|
321,118 | <p>What is the shortcut in eclipse to terminate debugging/running? Looking under Preferences -> Keys says <kbd>Ctrl</kbd> + <kbd>F2</kbd> but it doesn't work.</p>
| [
{
"answer_id": 321150,
"author": "VonC",
"author_id": 6309,
"author_profile": "https://Stackoverflow.com/users/6309",
"pm_score": 5,
"selected": true,
"text": "Window / Customize Perspective > Commands"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321118",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18722/"
] |
321,127 | <p>I have two simple tables in my database. A "card" table that contains Id, Name, and text of a card, and a "rulings" table which contains the Id of the card, and text detailing the rulings for the card.</p>
<p>Often enough in the ruling text, there is a reference to another card in the database. It is easy enough to find this in the text because each card is encapsulated within quotes in the text. It is not uncommon to have multiple cards referenced within the text of the ruling.</p>
<p>What I'd like to do is be able to create a cross reference table (or procedure if it is efficient enough) so that when I submit a query for a card, I can find all the ruling records that directly reference the card through the Id and get all of the ruling records where the card name is referenced in the text.</p>
<p>What would be the best way to approach this? My environment is SQL 2005, but any kind of "DB agnostic" solutions are greatly accepted here.</p>
| [
{
"answer_id": 321194,
"author": "George Mastros",
"author_id": 1408129,
"author_profile": "https://Stackoverflow.com/users/1408129",
"pm_score": 1,
"selected": false,
"text": "Declare @Card Table(Id Int, Name VarChar(20), CardText VarChar(8000))\n\nDeclare @Ruling Table(CardId Int, CardRuling VarChar(8000))\n\nInsert Into @Card Values(1, 'Card 1', 'This is the card ID = 1')\nInsert Into @Card Values(2, 'Card 2', 'This is the card id = 2.')\nInsert Into @Card Values(3, 'Card 3', 'This is the card id = 3.')\n\nInsert Into @Ruling Values(1, 'This is the ruling for 1 which references \"2\"')\nInsert Into @Ruling Values(2, 'This is the ruling for 2 which references nothing')\nInsert Into @Ruling Values(3, 'This is the ruling for 3 which references \"1\" and \"2\"')\n\nDeclare @CardId Int\nSet @CardId = 1\n\nSelect * \nFrom @Card As Card\n Inner Join @Ruling As Ruling\n On Card.Id = Ruling.CardId\n Left Join @Card As CardReferences\n On Ruling.CardRuling Like '%\"' + Convert(VarChar(10), CardReferences.Id) + '\"%'\n"
},
{
"answer_id": 321207,
"author": "Tom H",
"author_id": 5696608,
"author_profile": "https://Stackoverflow.com/users/5696608",
"pm_score": 3,
"selected": true,
"text": "CREATE TABLE dbo.Cards (\n id INT NOT NULL,\n name VARCHAR(50) NOT NULL,\n card_text VARCHAR(4000) NOT NULL,\n CONSTRAINT PK_Cards PRIMARY KEY CLUSTERED (id)\n)\nGO\nCREATE TABLE dbo.Card_Rulings (\n card_id INT NOT NULL,\n ruling_number INT NOT NULL,\n ruling_text VARCHAR(4000) NOT NULL,\n CONSTRAINT PK_Card_Rulings PRIMARY KEY CLUSTERED (card_id, ruling_number)\n)\nGO\nCREATE TABLE dbo.Card_Ruling_Referenced_Cards (\n parent_card_id INT NOT NULL,\n ruling_number INT NOT NULL,\n child_card_id INT NOT NULL,\n CONSTRAINT PK_Card_Ruling_Referenced_Cards PRIMARY KEY CLUSTERED (parent_card_id, ruling_number, child_card_id)\n)\nGO\nALTER TABLE dbo.Card_Rulings\nADD CONSTRAINT FK_CardRulings_Cards FOREIGN KEY (card_id) REFERENCES dbo.Cards(id)\nGO\nALTER TABLE dbo.Card_Ruling_Referenced_Cards\nADD CONSTRAINT FK_CardRulingReferencedCards_CardRulings FOREIGN KEY (parent_card_id, ruling_number) REFERENCES dbo.Card_Rulings (card_id, ruling_number)\nGO\nALTER TABLE dbo.Card_Ruling_Referenced_Cards\nADD CONSTRAINT FK_CardRulingReferencedCards_Cards FOREIGN KEY (child_card_id) REFERENCES dbo.Cards(id)\nGO\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321127",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/71/"
] |
321,128 | <p>I need to open a password protected shared folder on a network to gain access to an Access 97 database. How do I open the folder and pass in the password?</p>
| [
{
"answer_id": 322092,
"author": "Dirk Vollmar",
"author_id": 40347,
"author_profile": "https://Stackoverflow.com/users/40347",
"pm_score": 2,
"selected": false,
"text": "System.Diagnostics.Process.Start(\"net.exe\", \"use K: \\\\Server\\URI\\path\\here /USER:<username> <password>\" )\n"
},
{
"answer_id": 323658,
"author": "Fredou",
"author_id": 40868,
"author_profile": "https://Stackoverflow.com/users/40868",
"pm_score": 4,
"selected": true,
"text": "Public Declare Function WNetAddConnection2 Lib \"mpr.dll\" Alias \"WNetAddConnection2A\" _\n( ByRef lpNetResource As NETRESOURCE, ByVal lpPassword As String, _\n ByVal lpUserName As String, ByVal dwFlags As Integer) As Integer\n\n Public Declare Function WNetCancelConnection2 Lib \"mpr\" Alias \"WNetCancelConnection2A\" _\n (ByVal lpName As String, ByVal dwFlags As Integer, ByVal fForce As Integer) As Integer\n\n <StructLayout(LayoutKind.Sequential)> _\nPublic Structure NETRESOURCE\n Public dwScope As Integer\n Public dwType As Integer\n Public dwDisplayType As Integer\n Public dwUsage As Integer\n Public lpLocalName As String\n Public lpRemoteName As String\n Public lpComment As String\n Public lpProvider As String\n End Structure\n\nPublic Const ForceDisconnect As Integer = 1\nPublic Const RESOURCETYPE_DISK As Long = &H1\n\nPublic Function MapDrive(ByVal DriveLetter As String, ByVal UNCPath As String) As Boolean\n\n Dim nr As NETRESOURCE\n Dim strUsername As String\n Dim strPassword As String\n\n nr = New NETRESOURCE\n nr.lpRemoteName = UNCPath\n nr.lpLocalName = DriveLetter & \":\"\n strUsername = Nothing '(add parameters to pass this if necessary)\n strPassword = Nothing '(add parameters to pass this if necessary)\n nr.dwType = RESOURCETYPE_DISK\n\n Dim result As Integer\n result = WNetAddConnection2(nr, strPassword, strUsername, 0)\n\n If result = 0 Then\n Return True\n Else\n Return False\n End If\n End Function\n\nPublic Function UnMapDrive(ByVal DriveLetter As String) As Boolean\n Dim rc As Integer\n rc = WNetCancelConnection2(DriveLetter & \":\", 0, ForceDisconnect)\n\n If rc = 0 Then\n Return True\n Else\n Return False\n End If\n\n End Function\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321128",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/38349/"
] |
321,135 | <p>How do I make the computer's internal speaker beep in C# without external speakers?</p>
| [
{
"answer_id": 321144,
"author": "Barry Kelly",
"author_id": 3712,
"author_profile": "https://Stackoverflow.com/users/3712",
"pm_score": 5,
"selected": false,
"text": "Console.Beep\n"
},
{
"answer_id": 321145,
"author": "Chris Ballance",
"author_id": 1551,
"author_profile": "https://Stackoverflow.com/users/1551",
"pm_score": 4,
"selected": false,
"text": "\\a"
},
{
"answer_id": 321148,
"author": "a_hardin",
"author_id": 1497,
"author_profile": "https://Stackoverflow.com/users/1497",
"pm_score": 9,
"selected": true,
"text": "Console.Beep"
},
{
"answer_id": 321166,
"author": "Ta01",
"author_id": 7280,
"author_profile": "https://Stackoverflow.com/users/7280",
"pm_score": 7,
"selected": false,
"text": "System.Media.SystemSounds"
},
{
"answer_id": 38176987,
"author": "kuma DK",
"author_id": 3460275,
"author_profile": "https://Stackoverflow.com/users/3460275",
"pm_score": 3,
"selected": false,
"text": "system.beep()"
},
{
"answer_id": 47033963,
"author": "Jakub Szumiato",
"author_id": 5871208,
"author_profile": "https://Stackoverflow.com/users/5871208",
"pm_score": 3,
"selected": false,
"text": "using System.Runtime.InteropServices;\n [DllImport(\"kernel32.dll\")]\n public static extern bool Beep(int freq, int duration);\n\n public static void TestBeeps()\n {\n Beep(1000, 1600); //low frequency, longer sound\n Beep(2000, 400); //high frequency, short sound\n }\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321135",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1497/"
] |
321,139 | <p>I have a function that, among other things, takes in an object and a Type, and converts the object into that Type. However, the input object is often a double, and the type some variation of int (uint, long, etc.). I want this to work if a round number is passed in as a double (like 4.0), but to throw an exception if a decimal is passed in (4.3). Is there any more elegant way to check if the Type is some sort of int?</p>
<pre><code>if (inObject is double && (targetType == typeof (int)
|| targetType == typeof (uint)
|| targetType == typeof (long)
|| targetType == typeof (ulong)
|| targetType == typeof (short)
|| targetType == typeof (ushort)))
{
double input = (double) inObject;
if (Math.Truncate(input) != input)
throw new ArgumentException("Input was not an integer.");
}
</code></pre>
<p>Thanks.</p>
| [
{
"answer_id": 321435,
"author": "Amy B",
"author_id": 8155,
"author_profile": "https://Stackoverflow.com/users/8155",
"pm_score": 4,
"selected": true,
"text": " public int GetInt(IConvertible x)\n {\n int y = Convert.ToInt32(x);\n if (Convert.ToDouble(x) != Convert.ToDouble(y))\n throw new ArgumentException(\"Input was not an integer\");\n return y;\n }\n"
},
{
"answer_id": 321919,
"author": "Ricardo Villamil",
"author_id": 19314,
"author_profile": "https://Stackoverflow.com/users/19314",
"pm_score": 2,
"selected": false,
"text": "int intvalue;\nif(!Int32.TryParse(inObject.ToString(), out intvalue))\n throw InvalidArgumentException(\"Not rounded number or invalid int...etc\");\n\nreturn intvalue; //this now contains your value as an integer!\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321139",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17697/"
] |
321,140 | <p>I'm building a jar of my current application, which required several JVM arguments to be set.</p>
<p>Is there a way of setting these JVM arguments in a file rather than on the command line?</p>
<p>I've done some hunting and it looks like I might be able to do something witha java.properties file, possibly by setting a java-args, but I can't find any reference to the format for doing this.</p>
<p>Am I barking up the wrong tree?</p>
<p>Is this possible and if so how?</p>
<p>If not is there some other way to specify the JVM arguments?</p>
| [
{
"answer_id": 376610,
"author": "hhafez",
"author_id": 42303,
"author_profile": "https://Stackoverflow.com/users/42303",
"pm_score": 2,
"selected": false,
"text": "#!/bin/sh\nCLASSPATH=foo.jar:bar.jar\nJVMARGS=-some_arg\nMYAPP_ARGS=-some_args -for -my -app\n\njava $JVMARGS -classpath $CLASSPATH com.my.domain.myapp $MYAPP_ARGS\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321140",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20400/"
] |
321,143 | <p>For example, never define a macro like this:</p>
<pre><code>#define DANGER 60 + 2
</code></pre>
<p>This can potentially be dangerous when we do an operation like this:</p>
<pre><code>int wrong_value = DANGER * 2; // Expecting 124
</code></pre>
<p>Instead, define like this because you don't know how the user of the macro may use it:</p>
<pre><code>#define HARMLESS (60 + 2)
</code></pre>
<p>The example is trivial, but that pretty much explains my question. Are there any set of guidelines or best practices that you would recommend when writing a macro?</p>
<p>Thanks for your time!</p>
| [
{
"answer_id": 321151,
"author": "EvilTeach",
"author_id": 7734,
"author_profile": "https://Stackoverflow.com/users/7734",
"pm_score": 3,
"selected": false,
"text": "#define LESS_THAN(X,Y) (((X) < (Y) ? (X) : (Y))\n"
},
{
"answer_id": 321156,
"author": "unwind",
"author_id": 28169,
"author_profile": "https://Stackoverflow.com/users/28169",
"pm_score": 5,
"selected": false,
"text": " #define DOIT(x) do { x } while(0)\n"
},
{
"answer_id": 321160,
"author": "John Dibling",
"author_id": 241536,
"author_profile": "https://Stackoverflow.com/users/241536",
"pm_score": 3,
"selected": false,
"text": "static const int DANGER = 60 + 2;\n"
},
{
"answer_id": 321173,
"author": "Roddy",
"author_id": 1737,
"author_profile": "https://Stackoverflow.com/users/1737",
"pm_score": 6,
"selected": true,
"text": "#define MIN(a,b) a < b ? a : b // WRONG \n\nint i = MIN(1,2); // works\nint i = MIN(1,1+1); // breaks\n\n#define MIN(a,b) (a) < (b) ? (a) : (b) // STILL WRONG\n\nint i = MIN(1,2); // works\nint i = MIN(1,1+1); // now works\nint i = MIN(1,2) + 1; // breaks\n\n#define MIN(a,b) ((a) < (b) ? (a) : (b)) // GOOD\n\nint i = MIN(1,2); // works\nint i = MIN(1,1+1); // now works\nint i = MIN(1,2) + 1; // works\n"
},
{
"answer_id": 321186,
"author": "DarthPingu",
"author_id": 37199,
"author_profile": "https://Stackoverflow.com/users/37199",
"pm_score": 2,
"selected": false,
"text": "#define MAX 10\n"
},
{
"answer_id": 321221,
"author": "Robert Gamble",
"author_id": 25222,
"author_profile": "https://Stackoverflow.com/users/25222",
"pm_score": 3,
"selected": false,
"text": "#define MAX(x, y) ((x) > (y) ? (x) : (y))\n"
},
{
"answer_id": 321285,
"author": "Mike Dunlavey",
"author_id": 23771,
"author_profile": "https://Stackoverflow.com/users/23771",
"pm_score": 1,
"selected": false,
"text": "// define a list of variables, error messages, opcodes\n// or anything that you have to write multiple things about\n#define VARLIST \\\n DEFVAR(int, A, 1) \\\n DEFVAR(double, B, 2) \\\n DEFVAR(int, C, 3) \\\n\n// declare the variables\n#define DEFVAR(typ, name, val) typ name = (val);\n VARLIST\n#undef DEFVAR\n\n// write a routine to set a variable by name\nvoid SetVar(string varname, double value){\n if (0);\n #define DEFVAR(typ, name, val) else if (varname == #name) name = value;\n VARLIST\n #undef DEFVAR\n else printf(\"unrecognized variable %s\\n\", varname);\n}\n\n// write a routine to get a variable's value, given its name\n// .. you do it ..\n"
},
{
"answer_id": 321410,
"author": "dalle",
"author_id": 19100,
"author_profile": "https://Stackoverflow.com/users/19100",
"pm_score": 3,
"selected": false,
"text": "#define min(x, y) ({ \\\n typeof(x) _min1 = (x); \\\n typeof(y) _min2 = (y); \\\n (void) (&_min1 == &_min2); \\\n _min1 < _min2 ? _min1 : _min2; })\n"
},
{
"answer_id": 321525,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 0,
"selected": false,
"text": "void bar(void) {\n if(some_cond) {\n #define BAZ ...\n /* some code */\n #undef BAZ\n }\n}\n"
},
{
"answer_id": 451328,
"author": "lillq",
"author_id": 2064,
"author_profile": "https://Stackoverflow.com/users/2064",
"pm_score": 2,
"selected": false,
"text": "#defines"
},
{
"answer_id": 5878461,
"author": "sanjoyd",
"author_id": 360998,
"author_profile": "https://Stackoverflow.com/users/360998",
"pm_score": 2,
"selected": false,
"text": "do { } while (0)"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321143",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7205/"
] |
321,155 | <p>I am trying to center a form in VB.net. Instead of centering the form, it ends up about halfway between center and 0,0(upper left). </p>
<p>I am using the code</p>
<p>Me.StartPosition = FormStartPosition.CenterScreen</p>
<p>Which is called from the IntializeDisplay Method, which in turn is called from the Form Load method.</p>
<p>I assume I'm setting some propertity along the way that messes up the center calculation, but I'm not sure what it could be.</p>
<p>If anyone has any ideas they would be much appreciated.</p>
<p>Thanks.</p>
| [
{
"answer_id": 321247,
"author": "Vincent Van Den Berghe",
"author_id": 39259,
"author_profile": "https://Stackoverflow.com/users/39259",
"pm_score": 0,
"selected": false,
"text": "Form.StartPosition"
},
{
"answer_id": 521969,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "Public Sub New()\n\n ' This call is required by the Windows Form Designer.\n InitializeComponent()\n ' Add any initialization after the InitializeComponent() call.\n Me.StartPosition = FormStartPosition.CenterScreen\n\nEnd Sub\n"
},
{
"answer_id": 42542375,
"author": "Nathan",
"author_id": 5875316,
"author_profile": "https://Stackoverflow.com/users/5875316",
"pm_score": 0,
"selected": false,
"text": "Me.CenterToScreen()\n"
},
{
"answer_id": 42542448,
"author": "Trevor_G",
"author_id": 7501164,
"author_profile": "https://Stackoverflow.com/users/7501164",
"pm_score": 2,
"selected": false,
"text": " Me.CenterToScreen()\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321155",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27689/"
] |
321,158 | <p>I'm reading all the files in a single directory and I want to filter on JPG,JPEG,GIF and PNG.</p>
<p>Both capital and small letters. Those are the only files to be accepted.</p>
<p>I am currently using this:</p>
<pre><code>$testPics = takeFiles($picsDir, "([^\s]+(?=\.(jpg|JPG|jpeg|JPEG|png|PNG|gif|GIF))\.\2)");
</code></pre>
<p>and the function takeFiles looks like this:</p>
<pre><code>function takerFiles($dir, $rex="") {
$dir .= "/";
$files = array();
$dp = opendir($dir);
while ($file = readdir($dp)) {
if ($file == '.') continue;
if ($file == '..') continue;
if (is_dir($file)) continue;
if ($rex!="" && !preg_match($rex, $file)) continue;
$files[] = $file;
}
closedir($dp);
return $files;
}
</code></pre>
<p>And it always returns nothing. So something must be wrong with my regex code.</p>
| [
{
"answer_id": 321171,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 6,
"selected": true,
"text": "/^.*\\.(jpg|jpeg|png|gif)$/i"
},
{
"answer_id": 321192,
"author": "Eran Galperin",
"author_id": 10585,
"author_profile": "https://Stackoverflow.com/users/10585",
"pm_score": 4,
"selected": false,
"text": "$files = glob($dir . '*.{jpg,gif,png,jpeg}',GLOB_BRACE);\n"
},
{
"answer_id": 321225,
"author": "ringmaster",
"author_id": 40413,
"author_profile": "https://Stackoverflow.com/users/40413",
"pm_score": 0,
"selected": false,
"text": "$files = glob(\"{$picsDir}/*.{gif,jpeg,jpg,png}\", GLOB_BRACE);\n"
},
{
"answer_id": 321237,
"author": "smack0007",
"author_id": 26566,
"author_profile": "https://Stackoverflow.com/users/26566",
"pm_score": 2,
"selected": false,
"text": "scandir"
},
{
"answer_id": 35508365,
"author": "Rodrigo",
"author_id": 2456879,
"author_profile": "https://Stackoverflow.com/users/2456879",
"pm_score": 2,
"selected": false,
"text": "$string = \"your-file-name.jpg\";\npreg_match(\"/\\b(\\.jpg|\\.JPG|\\.png|\\.PNG|\\.gif|\\.GIF)\\b/\", $string, $output_array);\n"
},
{
"answer_id": 39776446,
"author": "zeros-and-ones",
"author_id": 2094495,
"author_profile": "https://Stackoverflow.com/users/2094495",
"pm_score": 0,
"selected": false,
"text": " $path = '/etc/apache2/';\n $conf_files = []; \n\n // Remove . and .. from the returned array from scandir\n $files = array_diff(scandir($path), array('.', '..'));\n foreach($files as $file) {\n if(in_array(pathinfo($file, PATHINFO_EXTENSION), ['conf'])) {\n $conf_files[] = $file; \n } \n }\n return $conf_files;\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321158",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11795/"
] |
321,175 | <p>I have the following code:</p>
<pre><code>var address;
getAddress(0,0);
function getAddress(latlng)
{
if (latlng != null)
{
geocoder.getLocations(latlng,
function(addresses)
{
if(addresses.Status.code == 200)
{
address = addresses.Placemark[0].address.toString();
alert(address); // Outputs something :)
}
});
}
return address; //returns nothing :(
}
</code></pre>
<p><code>address</code> always returns <code>undefined</code> but the alert does output something. Why is this?</p>
<p>(Geocoder is an instance of <a href="http://code.google.com/apis/maps/documentation/reference.html#GClientGeocoder" rel="nofollow noreferrer">Google Maps APIs</a>)</p>
| [
{
"answer_id": 321263,
"author": "Noah Goodrich",
"author_id": 20178,
"author_profile": "https://Stackoverflow.com/users/20178",
"pm_score": 2,
"selected": false,
"text": "var address = getAddress(0,0);\n\nfunction getAddress(latlng) {\n if (latlng != null) {\n var address = geocoder.getLocations(latlng, function(addresses) {\n if(addresses.Status.code == 200) { \n return addresses.Placemark[0].address.toString();\n }\n });\n }\nreturn address;\n}\n"
},
{
"answer_id": 321268,
"author": "Static Tony",
"author_id": 11508,
"author_profile": "https://Stackoverflow.com/users/11508",
"pm_score": -1,
"selected": false,
"text": "window.alert(getAddress(0,0));\n"
},
{
"answer_id": 321312,
"author": "Victor",
"author_id": 14514,
"author_profile": "https://Stackoverflow.com/users/14514",
"pm_score": 0,
"selected": false,
"text": "geocoder.getLocations\n"
},
{
"answer_id": 321445,
"author": "Chei",
"author_id": 11411,
"author_profile": "https://Stackoverflow.com/users/11411",
"pm_score": 0,
"selected": false,
"text": "var address;\nalert(\"B: address returned: \" + getAddress());\nfunction getAddress() {\n executeFunction(function() {\n address = \"myAddress\";\n alert(\"C: address set to: \" + address);\n });\n return address;\n}\n\nfunction executeFunction(aFunction) {\n alert(\"A: executing: \" + aFunction);\n window.setTimeout(aFunction, 1);\n}\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321175",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19929/"
] |
321,179 | <p>So I have a <code>stored procedure</code> that accepts a product code like <code>1234567890</code>. I want to facilitate a wildcard search option for those products. (i.e. <code>123456*</code>) and have it return all those products that match. What is the best way to do this?</p>
<p>I have in the past used something like below:</p>
<pre><code>SELECT @product_code = REPLACE(@product_code, '*', '%')
</code></pre>
<p>and then do a <code>LIKE</code> search on the <code>product_code</code> field, but i feel like it can be improved.</p>
| [
{
"answer_id": 321427,
"author": "AJ.",
"author_id": 7211,
"author_profile": "https://Stackoverflow.com/users/7211",
"pm_score": 0,
"selected": false,
"text": "LIKE"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321179",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
321,180 | <p>I want to write unit tests with NUnit that hit the database. I'd like to have the database in a consistent state for each test. I thought transactions would allow me to "undo" each test so I searched around and found several articles from 2004-05 on the topic:</p>
<ul>
<li><a href="http://weblogs.asp.net/rosherove/archive/2004/07/12/180189.aspx" rel="noreferrer">http://weblogs.asp.net/rosherove/archive/2004/07/12/180189.aspx</a></li>
<li><a href="http://weblogs.asp.net/rosherove/archive/2004/10/05/238201.aspx" rel="noreferrer">http://weblogs.asp.net/rosherove/archive/2004/10/05/238201.aspx</a></li>
<li><a href="http://davidhayden.com/blog/dave/archive/2004/07/12/365.aspx" rel="noreferrer">http://davidhayden.com/blog/dave/archive/2004/07/12/365.aspx</a></li>
<li><a href="http://davidhayden.com/blog/dave/archive/2004/07/12/365.aspx" rel="noreferrer">http://haacked.com/archive/2005/12/28/11377.aspx</a></li>
</ul>
<p>These seem to resolve around implementing a custom attribute for NUnit which builds in the ability to rollback DB operations after each test executes.</p>
<p>That's great but... </p>
<ol>
<li>Does this functionality exists somewhere in NUnit natively?</li>
<li>Has this technique been improved upon in the last 4 years? </li>
<li>Is this still the best way to test database-related code?</li>
</ol>
<hr>
<p>Edit: it's not that I want to test my DAL specifically, it's more that I want to test pieces of my code that interact with the database. For these tests to be "no-touch" and repeatable, it'd be awesome if I could reset the database after each one.</p>
<p>Further, I want to ease this into an existing project that has no testing place at the moment. For that reason, I can't practically script up a database and data from scratch for each test.</p>
| [
{
"answer_id": 367294,
"author": "Mike Two",
"author_id": 23659,
"author_profile": "https://Stackoverflow.com/users/23659",
"pm_score": 7,
"selected": true,
"text": "[Test]\npublic void YourTest() \n{\n using (TransactionScope scope = new TransactionScope())\n {\n // your test code here\n }\n}\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321180",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29/"
] |
321,193 | <p><strong>Problem</strong><br>
I've got a number of Dojo components on a page. When the user tries to tab from an input like component to a grid like component, I get a JavaScript "Can't move focus to control" error. The user base uses IE6. </p>
<p><strong>Solution</strong><br>
The first element in the DojoX Grid layout cannot be hidden. If it is hidden, you get a a JavaScript "Can't move focus to control" error. To fix this, I added a row # that displays. See below.</p>
<blockquote>
<pre><code> var gridLayout = [
new dojox.grid.cells.RowIndex({ name: "row #",
width: 2,
styles: "text-align: right;"
}),
{
field: "ele_id",
name: "Element ID",
styles: "text-align:right;",
width:5,
hidden:"true"
},
{
field: "ele_nm",
name: "Element Name",
styles: "text-align:left;",
width:8
}
];
</code></pre>
</blockquote>
| [
{
"answer_id": 321200,
"author": "Jaime Garcia",
"author_id": 32812,
"author_profile": "https://Stackoverflow.com/users/32812",
"pm_score": 1,
"selected": false,
"text": "function handleKeyDown(e)"
},
{
"answer_id": 321208,
"author": "Diodeus - James MacFarlane",
"author_id": 12579,
"author_profile": "https://Stackoverflow.com/users/12579",
"pm_score": 0,
"selected": false,
"text": "<input name=\"z\" onfocus=\"this.blur()\"/>\n"
},
{
"answer_id": 321215,
"author": "ARemesal",
"author_id": 36599,
"author_profile": "https://Stackoverflow.com/users/36599",
"pm_score": 2,
"selected": false,
"text": "<input id=\"Input-x\" type=\"text\" />\n<input id=\"Input-y\" type=\"text\" onChange=\"document.getElementById('Input_Z').removeAttribute('disabled');\" />\n<input id=\"Input-z\" type=\"text\" disabled />\n"
},
{
"answer_id": 321222,
"author": "Peter Bailey",
"author_id": 8815,
"author_profile": "https://Stackoverflow.com/users/8815",
"pm_score": 2,
"selected": false,
"text": "<span>"
},
{
"answer_id": 321326,
"author": "ARemesal",
"author_id": 36599,
"author_profile": "https://Stackoverflow.com/users/36599",
"pm_score": 1,
"selected": false,
"text": "<div id=\"mygrid\" tabindex=\"-1\"> <!-- Some stuff here --> </div>\n"
},
{
"answer_id": 788130,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": true,
"text": " var gridLayout = [\n new dojox.grid.cells.RowIndex({ name: \"row #\", \n width: 2, \n styles: \"text-align: right;\"\n }),\n {\n field: \"ele_id\",\n name: \"Element ID\",\n styles: \"text-align:right;\",\n width:5,\n hidden:\"true\" \n },\n {\n field: \"ele_nm\",\n name: \"Element Name\",\n styles: \"text-align:left;\",\n width:8 \n }\n ];\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321193",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
321,196 | <p>My team works on a project in cvs containing about 20,000 Java files. Because of the number of files, it takes a while to do a cvs update. I typically keep about 5 copies of the entire tree checked out, to make it easy to check in different requests without worrying about which files were modified for each. It's a real pain to keep all 5 trees up to date and in sync with each other.</p>
<p>I've read that it's fairly easy to use git locally with a remote cvs server, and that git is fast. Will git significantly speed up the updating of my local trees?</p>
<p>I realize the lower bound is the time to do one cvs update. But I'm thinking that once the first tree is up to date, it might possible to quickly sync the other 4 with the first, rather than to do 4 more cvs update commands. Do I understand git correctly?</p>
| [
{
"answer_id": 321428,
"author": "Pat Notz",
"author_id": 825,
"author_profile": "https://Stackoverflow.com/users/825",
"pm_score": 3,
"selected": false,
"text": "master"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321196",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23572/"
] |
321,203 | <p>I am trying to generate some code at runtime using the DynamicMethod class in the Reflection.Emit namespace but for some reason its throwing a "VerificationException". Here is the IL code I am trying to use...</p>
<pre><code>ldarg.1
ldarg.0
ldfld, System.String FirstName
callvirt, Void Write(System.String)
ldarg.1
ldarg.0
ldfld, System.String LastName
callvirt, Void Write(System.String)
ldarg.1
ldarg.0
ldfld, Int32 Age
callvirt, Void Write(Int32)
ret
</code></pre>
<p>I need a way to debug the generated IL code. What options do I have? I am using VS2008 professional.</p>
| [
{
"answer_id": 321541,
"author": "leppie",
"author_id": 15541,
"author_profile": "https://Stackoverflow.com/users/15541",
"pm_score": 0,
"selected": false,
"text": "ldarg.1\nldarg.0\nldfld, System.String FirstName\ncallvirt, Void Write(System.String)\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321203",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39648/"
] |
321,211 | <p>Does anyone know how to implement the standard bubble message that warns users whenever Caps Lock is enabled and a password control has focus? Is this built into the .NET framework, or do I need to write my own class to do this?</p>
| [
{
"answer_id": 6049811,
"author": "Jose",
"author_id": 101689,
"author_profile": "https://Stackoverflow.com/users/101689",
"pm_score": 4,
"selected": false,
"text": "Keyboard.IsKeyToggled(Key.CapsLock)"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321211",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/132931/"
] |
321,229 | <p>I would like to be able to fusion an <code>IEnumerable<IEnumerable<T>></code> into <code>IEnumerable<T></code> (i.e. merge all individual collections into one). The <code>Union</code> operators only applies to two collections. Any idea?</p>
| [
{
"answer_id": 321235,
"author": "JaredPar",
"author_id": 23283,
"author_profile": "https://Stackoverflow.com/users/23283",
"pm_score": 8,
"selected": true,
"text": "var it = GetTheNestedCase();\nreturn it.SelectMany(x => x);\n"
},
{
"answer_id": 774725,
"author": "Joe Chung",
"author_id": 86483,
"author_profile": "https://Stackoverflow.com/users/86483",
"pm_score": 4,
"selected": false,
"text": "var lists = GetTheNestedCase();\nreturn\n from list in lists\n from element in list\n select element;\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321229",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18858/"
] |
321,239 | <p>I'd like to hide a div when user click anywhere on the page outside of that div. How can I do that using raw javascript or jQuery?</p>
| [
{
"answer_id": 321256,
"author": "VonC",
"author_id": 6309,
"author_profile": "https://Stackoverflow.com/users/6309",
"pm_score": 2,
"selected": false,
"text": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<html>\n <head>\n <title>Untitled Document</title>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n <meta http-equiv=\"Content-Style-Type\" content=\"text/css\">\n <meta http-equiv=\"Content-Script-Type\" content=\"text/javascript\">\n <style type=\"text/css\">\n <!--\n #mydiv{\n background-color: #999999;\n height: 100px;\n width: 100px;\n }\n -->\n </style>\n <script type=\"text/javascript\">\n document.onclick=check;\n function check(e)\n {\n var target = (e && e.target) || (event && event.srcElement);\n var obj = document.getElementById('mydiv');\n if(target!=obj){obj.style.display='none'}\n }\n </script>\n </head>\n <body>\n <div id=\"mydiv\">my div</div>\n </body>\n</html> \n"
},
{
"answer_id": 321266,
"author": "Eran Galperin",
"author_id": 10585,
"author_profile": "https://Stackoverflow.com/users/10585",
"pm_score": 6,
"selected": true,
"text": "$(document).click(function(e) {\n $('#somediv').hide();\n});\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321239",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11439/"
] |
321,241 | <p>I have a large legacy C++ project compiled under Visual Studio 2008. I know there is a reasonably amount of 'dead' code that is not accessed anywhere -- methods that are not called, whole classes that are not used.</p>
<p>I'm looking for a tool that will identify this by <strong>static analysis</strong>.</p>
<p>This question: <a href="https://stackoverflow.com/questions/229069/dead-code-detection-in-legacy-cc-project">Dead code detection in legacy C/C++ project</a> suggests using code coverage tools. This isn't an option as the test coverage just isn't high enough. </p>
<p>It also mentions a -Wunreachable-code. option to gcc. I'd like something similar for Visual Studio. We already use the linker's /OPT:REF option to remove redundant code, but this doesn't report the dead code at a useful level (when used with /VERBOSE there are over 100,000 lines, including a lot from libraries).</p>
<p>Are there any better options that work well with a Visual Studio project?</p>
| [
{
"answer_id": 45918893,
"author": "unresolved_external",
"author_id": 747228,
"author_profile": "https://Stackoverflow.com/users/747228",
"pm_score": 1,
"selected": false,
"text": "-Wunused-function\n-Wunused-label\n-Wunused-value\n-Wunused-variable\n-Wunused-parameter\n-Wunused-but-set-parameter\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321241",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3631/"
] |
321,259 | <p>What should do to setup a sub-domain for the users when they sign-up into my site.</p>
<p>What are the infrastructure required? I am using Linux servers.</p>
| [
{
"answer_id": 321292,
"author": "Alnitak",
"author_id": 6782,
"author_profile": "https://Stackoverflow.com/users/6782",
"pm_score": 3,
"selected": false,
"text": "CNAME"
},
{
"answer_id": 321300,
"author": "Brian Gianforcaro",
"author_id": 3415,
"author_profile": "https://Stackoverflow.com/users/3415",
"pm_score": 0,
"selected": false,
"text": "Port 80\nServerName www.mydomain.com\n\nNameVirtualHost *:80\n\n<VirtualHost *:80>\nDocumentRoot /www/user-bob\nServerName bob.mydomain.com\n...\n</VirtualHost>\n\n<VirtualHost *:80>\nDocumentRoot /www/user-sally\nServerName sally.mydomain.com\n...\n</VirtualHost> \n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321259",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
321,260 | <p>I want to add the current month, and the previous two months to a prompt, for a user to select. </p>
<p>e.g. if this month is <code>2008 Nov</code>, <code>ddlbox</code> should show the following:</p>
<pre><code>112008
102008
092008
</code></pre>
<p>How can I do this? </p>
| [
{
"answer_id": 321303,
"author": "VB For the WIN",
"author_id": 36864,
"author_profile": "https://Stackoverflow.com/users/36864",
"pm_score": 2,
"selected": false,
"text": "<asp:DropDownList ID=\"DropDownList1\" runat=\"server\">\n</asp:DropDownList>\n\nfor (int i = 0; i < 3; i++)\n{\n ListItem item = new ListItem(string.Format(\"{0: MM/yyyy}\", DateTime.Now.AddMonths(-i)));\n DropDownList1.Items.Add(item);\n}\n"
},
{
"answer_id": 665843,
"author": "Richard Cresswell",
"author_id": 162605,
"author_profile": "https://Stackoverflow.com/users/162605",
"pm_score": 1,
"selected": false,
"text": "SELECT to_char(add_months(SYSDATE, -1 * LEVEL + 1), 'MMYYYY') AS mon\nFROM dual\nCONNECT BY rownum < 4\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321260",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
321,265 | <p>I have see code like this</p>
<pre><code>Dim s as something = new something
Dim s as new something
</code></pre>
<p>what's the difference? is there any?</p>
| [
{
"answer_id": 321290,
"author": "Oli",
"author_id": 12870,
"author_profile": "https://Stackoverflow.com/users/12870",
"pm_score": 4,
"selected": true,
"text": "Dim s as ParentType = new InheritedType\n"
},
{
"answer_id": 321434,
"author": "Binary Worrier",
"author_id": 18797,
"author_profile": "https://Stackoverflow.com/users/18797",
"pm_score": 1,
"selected": false,
"text": "Dim s as something = new something\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321265",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28647/"
] |
321,272 | <p>I am trying to validate xml file against schema using <a href="http://search.cpan.org/~samtregar/XML-Validator-Schema/Schema.pm" rel="nofollow noreferrer">XML::Validator::Schema</a>.<br>
But it gives me this error:</p>
<pre><code>Found unexpected <Submission> inside <<<<ROOT>>>>. This is not a valid child element. [Ln: 2, Col:119]
</code></pre>
<p>Note: <code><Submission></code> is the very first element I have after <code><xml version="1.0" encoding="UTF-8"?></code> </p>
<p>I can't figure out what it means.<br>
Appreciate any help.</p>
<p>XML is: </p>
<pre><code><?xml version="1.0" encoding="utf-8"?>
<Submission xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="layout-topologie.xsd">
<Return>
<NR4>
<NR4Slip>
<RCPNT_NM>
<snm>SYMPSOM</snm>
<gvn_nm>HOMER</gvn_nm>
<init>A</init>
</RCPNT_NM>
<SEC_RCPNT_NM></SEC_RCPNT_NM>
<RCPNT_ADDR>
<addr_l1_txt>C/O ABC A/C 555 6666</addr_l1_txt>
<addr_l2_txt>9999 - 88 STREET</addr_l2_txt>
<cntry_cd>CAN</cntry_cd>
<fgn_pstl_cd>T4S1M5</fgn_pstl_cd>
</RCPNT_ADDR>
<fssn_nbr>607-448-900</fssn_nbr>
<nr_acct_nbr>NRY454080</nr_acct_nbr>
<rcpnt_tcd>01</rcpnt_tcd>
<payr_nbr>100000</payr_nbr>
<inc_1_tcd>11</inc_1_tcd>
<crcy_1_cd>CAD</crcy_1_cd>
<tx_xmpt_1_cd>AB</tx_xmpt_1_cd>
<inc_2_tcd>02</inc_2_tcd>
<crcy_2_cd>CAD</crcy_2_cd>
<tx_xmpt_2_cd>PQ</tx_xmpt_2_cd>
<NR4_AMT>
<gro_1_incamt>1.1</gro_1_incamt>
<nr_tx_1_amt>0.00</nr_tx_1_amt>
<gro_2_incamt>90000000</gro_2_incamt>
<nr_tx_2_amt>0.00</nr_tx_2_amt>
</NR4_AMT>
<rpt_tcd>O</rpt_tcd>
</NR4Slip>
<NR4Slip>
<RCPNT_NM>
<snm>CARTMAN</snm>
<gvn_nm>ERIC</gvn_nm>
</RCPNT_NM>
<SEC_RCPNT_NM>
<sec_snm>SYMPSON</sec_snm>
<sec_gvn_nm>BART</sec_gvn_nm>
</SEC_RCPNT_NM>
<RCPNT_ADDR>
<addr_l1_txt>C/O DEFG A/C 555 2222</addr_l1_txt>
<addr_l2_txt>9999 - 88 STREET</addr_l2_txt>
<cntry_cd>CAN</cntry_cd>
<fgn_pstl_cd>T4S1M5</fgn_pstl_cd>
</RCPNT_ADDR>
<fssn_nbr>607-448-901</fssn_nbr>
<nr_acct_nbr>NRY454080</nr_acct_nbr>
<rcpnt_tcd>01</rcpnt_tcd>
<payr_nbr>200000</payr_nbr>
<inc_1_tcd>11</inc_1_tcd>
<crcy_1_cd>USD</crcy_1_cd>
<tx_xmpt_1_cd>BC</tx_xmpt_1_cd>
<inc_2_tcd>02</inc_2_tcd>
<crcy_2_cd>USD</crcy_2_cd>
<tx_xmpt_2_cd>QR</tx_xmpt_2_cd>
<NR4_AMT>
<gro_1_incamt>20.01</gro_1_incamt>
<nr_tx_1_amt>10</nr_tx_1_amt>
<gro_2_incamt>8000000</gro_2_incamt>
<nr_tx_2_amt>0.1</nr_tx_2_amt>
</NR4_AMT>
<rpt_tcd>O</rpt_tcd>
</NR4Slip>
<NR4Summary>
<PAYR_NM>
<l1_nm>THE BANK OF NOVA SCOTIA</l1_nm>
</PAYR_NM>
<PAYR_ADDR>
<addr_l1_txt>HR SHARED SERVICES PENSION DEPT.</addr_l1_txt>
<addr_l2_txt>7TH FLOOR, 888 BIRCHMOUNT ROAD</addr_l2_txt>
</PAYR_ADDR>
<tx_yr>2007</tx_yr>
<slp_cnt>10</slp_cnt>
</NR4Summary>
</NR4>
</Return>
</Submission>
</code></pre>
<p>XSD is: </p>
<pre><code><?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!-- @@@@ Definition of NR4 ComplexTypes @@@@ 2008/sept/03 Version# 2.8 -->
<xsd:complexType name="NR4SlipType">
<xsd:all>
<xsd:element name="RCPNT_NM" type="NameType" minOccurs="0"/>
<xsd:element name="SEC_RCPNT_NM" type="NameType_2" minOccurs="0"/>
<xsd:element name="ENTPRS_NM" type="NR4_Line2Type" minOccurs="0"/>
<xsd:element name="RCPNT_ADDR" type="NR4ForeignAddressType" minOccurs="0"/>
<xsd:element name="tx_cntry_cd" type="char3Type"/>
<xsd:element name="fssn_nbr" type="char20Type"/>
<xsd:element name="nr_acct_nbr" type="nrType"/>
<xsd:element name="rcpnt_tcd" type="indicator1-5Type"/>
<xsd:element name="payr_nbr" type="char20Type" minOccurs="0"/>
<xsd:element name="inc_1_tcd" type="numeric2Type" minOccurs="0"/>
<xsd:element name="crcy_1_cd" type="char3Type" minOccurs="0"/>
<xsd:element name="NR4_AMT" type="NR4AmountType" minOccurs="0"/>
<xsd:element name="tx_xmpt_1_cd" type="char1Type" minOccurs="0"/>
<xsd:element name="inc_2_tcd" type="numeric2Type" minOccurs="0"/>
<xsd:element name="crcy_2_cd" type="char3Type" minOccurs="0"/>
<xsd:element name="tx_xmpt_2_cd" type="char1Type" minOccurs="0"/>
<xsd:element name="rpt_tcd" type="slipDataType"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="NR4AmountType">
<xsd:all>
<xsd:element name="gro_1_incamt" type="decimal11Type" minOccurs="0"/>
<xsd:element name="nr_tx_1_amt" type="decimal11Type" minOccurs="0"/>
<xsd:element name="gro_2_incamt" type="decimal11Type" minOccurs="0"/>
<xsd:element name="nr_tx_2_amt" type="decimal11Type" minOccurs="0"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="NR4SummaryType">
<xsd:all>
<xsd:element name="nr_acct_nbr" type="nrType"/>
<xsd:element name="PAYR_NM" type="Line3Type"/>
<xsd:element name="PAYR_ADDR" type="NR4CanadaAddressType" minOccurs="0"/>
<xsd:element name="CNTC" type="ContactType2"/>
<xsd:element name="tx_yr" type="yearType"/>
<xsd:element name="slp_cnt" type="int7Type"/>
<xsd:element name="rmt_tcd" type="indicator1-2Type" minOccurs="0"/>
<xsd:element name="rpt_tcd" type="otherDataType"/>
<xsd:element name="NR4_TAMT" type="NR4TotalsType" minOccurs="0"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="NR4TotalsType">
<xsd:all>
<xsd:element name="tot_gro_1_incamt" type="decimal13Type" minOccurs="0"/>
<xsd:element name="tot_nr_tx_1_amt" type="decimal13Type" minOccurs="0"/>
<xsd:element name="tot_gro_2_incamt" type="decimal13Type" minOccurs="0"/>
<xsd:element name="tot_nr_tx_2_amt" type="decimal13Type" minOccurs="0"/>
<xsd:element name="tot_nrpt_incamt" type="decimal13Type" minOccurs="0"/>
<xsd:element name="tot_nr_nrpt_tx_amt" type="decimal13Type" minOccurs="0"/>
</xsd:all>
<xsd:attribute name="tot_incamt" type="xsd:string"/>
<xsd:attribute name="tot_tx_wthld" type="xsd:string"/>
</xsd:complexType>
</xsd:schema>
</code></pre>
| [
{
"answer_id": 321706,
"author": "rjray",
"author_id": 6421,
"author_profile": "https://Stackoverflow.com/users/6421",
"pm_score": 2,
"selected": false,
"text": "<Submission>"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321272",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
321,280 | <p>I've found databases typically come in two flavors, your traditional row-oriented RDBMS or an object oriented database (OODBMS). However, in the mid 90s I remember, a new breed of databases showing up that were column oriented. Some of these were given the term 4GL, but I don't think it was a term that stuck.</p>
<p>What I'd like to know is the following:</p>
<ul>
<li>What column oriented databases still exist?</li>
<li>What are the performance characteristics of these databases?</li>
<li>Are there any open source column oriented databases?</li>
<li>What platforms do they interoperate with (.NET, Java, etc)</li>
<li>What's been your general experience with them?</li>
</ul>
<p>The two column oriented databases that I remember working with are FAME and KDB.</p>
| [
{
"answer_id": 980941,
"author": "SuPra",
"author_id": 114484,
"author_profile": "https://Stackoverflow.com/users/114484",
"pm_score": 2,
"selected": false,
"text": "\"Most major DBMS vendors implement record-oriented \nstorage systems, where the attributes of a record (or tuple) \nare placed contiguously in storage. With this row store \narchitecture, a single disk write suffices to push all of the \nfields of a single record out to disk. Hence, high \nperformance writes are achieved, and we call a DBMS \nwith a row store architecture a write-optimized system. \n\nIn contrast, systems oriented toward ad-hoc querying \nof large amounts of data should be read-optimized. Data \nwarehouses represent one class of read-optimized system,\nin which periodically a bulk load of new data is \nperformed, followed by a relatively long period of ad-hoc \nqueries. Other read-mostly applications include customer \nrelationship management (CRM) systems, electronic \nlibrary card catalogs, and other ad-hoc inquiry systems. In \nsuch environments, a column store architecture, in which \nthe values for each single column (or attribute) are stored \ncontiguously, should be more efficient. This efficiency \nhas been demonstrated in the warehouse marketplace by \nproducts like Sybase IQ [FREN95, SYBA04], Addamark \n[ADDA04], and KDB [KDB04]. In this paper, we discuss \nthe design of a column store called C-Store that includes a \nnumber of novel features relative to existing systems.\"\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321280",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25228/"
] |
321,294 | <p>What is the easiest way to highlight the difference between two strings in PHP?</p>
<p>I'm thinking along the lines of the Stack Overflow edit history page, where new text is in green and removed text is in red. If there are any pre-written functions or classes available, that would be ideal.</p>
| [
{
"answer_id": 8329267,
"author": "xgretsch",
"author_id": 217953,
"author_profile": "https://Stackoverflow.com/users/217953",
"pm_score": 3,
"selected": false,
"text": "/**\n * @brief Find the difference between two strings, lines assumed to be separated by \"\\n|\n * @param $new string The new string\n * @param $old string The old string\n * @return string Human-readable output as produced by the Unix diff command,\n * or \"No changes\" if the strings are the same.\n * @throws Exception\n */\npublic static function diff($new, $old) {\n $tempdir = '/var/somewhere/tmp'; // Your favourite temporary directory\n $oldfile = tempnam($tempdir,'OLD');\n $newfile = tempnam($tempdir,'NEW');\n if (!@file_put_contents($oldfile,$old)) {\n throw new Exception('diff failed to write temporary file: ' . \n print_r(error_get_last(),true));\n }\n if (!@file_put_contents($newfile,$new)) {\n throw new Exception('diff failed to write temporary file: ' . \n print_r(error_get_last(),true));\n }\n $answer = array();\n $cmd = \"diff $newfile $oldfile\";\n exec($cmd, $answer, $retcode);\n unlink($newfile);\n unlink($oldfile);\n if ($retcode != 1) {\n throw new Exception('diff failed with return code ' . $retcode);\n }\n if (empty($answer)) {\n return 'No changes';\n } else {\n return implode(\"\\n\", $answer);\n }\n}\n"
},
{
"answer_id": 10397178,
"author": "Gordon",
"author_id": 208809,
"author_profile": "https://Stackoverflow.com/users/208809",
"pm_score": 3,
"selected": false,
"text": "<?php\n$old_article = file_get_contents('./old_article.txt');\n$new_article = $_POST['article'];\n\n$diff = xdiff_string_diff($old_article, $new_article, 1);\nif (is_string($diff)) {\n echo \"Differences between two articles:\\n\";\n echo $diff;\n}\n"
},
{
"answer_id": 22021254,
"author": "Calmarius",
"author_id": 58805,
"author_profile": "https://Stackoverflow.com/users/58805",
"pm_score": 5,
"selected": false,
"text": "function computeDiff($from, $to)\n{\n $diffValues = array();\n $diffMask = array();\n\n $dm = array();\n $n1 = count($from);\n $n2 = count($to);\n\n for ($j = -1; $j < $n2; $j++) $dm[-1][$j] = 0;\n for ($i = -1; $i < $n1; $i++) $dm[$i][-1] = 0;\n for ($i = 0; $i < $n1; $i++)\n {\n for ($j = 0; $j < $n2; $j++)\n {\n if ($from[$i] == $to[$j])\n {\n $ad = $dm[$i - 1][$j - 1];\n $dm[$i][$j] = $ad + 1;\n }\n else\n {\n $a1 = $dm[$i - 1][$j];\n $a2 = $dm[$i][$j - 1];\n $dm[$i][$j] = max($a1, $a2);\n }\n }\n }\n\n $i = $n1 - 1;\n $j = $n2 - 1;\n while (($i > -1) || ($j > -1))\n {\n if ($j > -1)\n {\n if ($dm[$i][$j - 1] == $dm[$i][$j])\n {\n $diffValues[] = $to[$j];\n $diffMask[] = 1;\n $j--; \n continue; \n }\n }\n if ($i > -1)\n {\n if ($dm[$i - 1][$j] == $dm[$i][$j])\n {\n $diffValues[] = $from[$i];\n $diffMask[] = -1;\n $i--;\n continue; \n }\n }\n {\n $diffValues[] = $from[$i];\n $diffMask[] = 0;\n $i--;\n $j--;\n }\n } \n\n $diffValues = array_reverse($diffValues);\n $diffMask = array_reverse($diffMask);\n\n return array('values' => $diffValues, 'mask' => $diffMask);\n}\n"
},
{
"answer_id": 68952840,
"author": "ARIF SHAIKH",
"author_id": 16758351,
"author_profile": "https://Stackoverflow.com/users/16758351",
"pm_score": 1,
"selected": false,
"text": " <?php\n $valueOne = $_POST['value'] ?? \"\";\n $valueTwo = $_POST['valueb'] ?? \"\" ;\n \n $trimValueOne = trim($valueOne);\n $trimValueTwo = trim($valueTwo);\n\n $arrayValueOne = explode(\" \",$trimValueOne);\n $arrayValueTwo = explode(\" \",$trimValueTwo);\n\n $allDiff = array_merge(array_diff($arrayValueOne, $arrayValueTwo), array_diff($arrayValueTwo, $arrayValueOne));\n if(array_intersect($arrayValueOne,$allDiff) && array_intersect($arrayValueTwo,$allDiff)){\n\n if(array_intersect($arrayValueOne,$allDiff)){\n $highlightArr = array_intersect($arrayValueOne,$allDiff);\n $highlightArrValue = array_values($highlightArr);\n for ($i=0; $i <count($arrayValueOne) ;$i++) { \n for ($j=0; $j <count($highlightArrValue) ; $j++) { \n if($arrayValueOne[$i] == $highlightArrValue[$j]){\n $arrayValueOne[$i] = \"<span>\".$arrayValueOne[$i].\"</span>\";\n }\n }\n }\n $strOne = implode(\" \",$arrayValueOne);\n echo \"<p class = \\\"one\\\">{$strOne}</p>\";\n }if(array_intersect($arrayValueTwo,$allDiff)){\n $highlightArr = array_intersect($arrayValueTwo,$allDiff);\n $highlightArrValue = array_values($highlightArr);\n for ($i=0; $i <count($arrayValueTwo) ;$i++) { \n for ($j=0; $j <count($highlightArrValue) ; $j++) { \n if($arrayValueTwo[$i] == $highlightArrValue[$j]){\n $arrayValueTwo[$i] = \"<span>\".$arrayValueTwo[$i].\"</span>\";\n }\n }\n }\n $strTwo = implode(\" \",$arrayValueTwo);\n echo \"<p class = \\\"two\\\">{$strTwo}</p>\";\n }\n }elseif(!(array_intersect($arrayValueOne,$allDiff) && array_intersect($arrayValueTwo,$allDiff))){\n if($trimValueOne == $trimValueTwo){\n echo\"<p class = \\\"one green\\\">$trimValueOne</p></p>\";\n echo\"<p class = \\\"two green\\\">$trimValueTwo</p></p>\";\n }\n else{\n echo\"<p class = \\\"one \\\">$trimValueOne</p></p>\";\n echo\"<p class = \\\"two \\\">$trimValueTwo</p></p>\";\n }\n\n }\n?>\n\n\n<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>Document</title>\n <link rel=\"stylesheet\" href=\"./style.css\">\n</head>\n<body>\n <form method=\"post\" action=\"\">\n <textarea type=\"text\" name=\"value\" placeholder=\"enter first text\"></textarea>\n <textarea type=\"text\" name=\"valueb\" placeholder=\"enter second text\"></textarea>\n <input type=\"submit\">\n </form>\n</body>\n</html>\n"
},
{
"answer_id": 70740408,
"author": "Oliver M Grech",
"author_id": 508134,
"author_profile": "https://Stackoverflow.com/users/508134",
"pm_score": 0,
"selected": false,
"text": "function strdiff($a,$b){\n\n $a = str_split($a);\n $b = str_split($b);\n\n return array_diff($a,$b);\n\n}\n"
},
{
"answer_id": 72394867,
"author": "Mike Harding",
"author_id": 15162749,
"author_profile": "https://Stackoverflow.com/users/15162749",
"pm_score": 0,
"selected": false,
"text": "$old_data = \"We'll of today's hunt we will find inner zen. You are awesome [TEAM_NAME]! Cleveland has a lot more to offer though, so keep on roaming and find some happiness with Let's Roam!;\";\n$new_data = \"We'll of today's hunt we will find inner zen. Great job today, you are freaking super awesome [TEAM_NAME]! though, so keep roaming Cleveland has a lot more to offer and find happiness on www.letsroam.com!;\";\n\nif($old_data) {\n $old_words = explode(\" \" , $old_data);\n $new_words = explode(\" \", $new_data);\n\n $added_words = array();\n $deleted_words = array();\n $unchanged_words = array();\n foreach($new_words as $new_word) {\n $new_word_index = array_search($new_word, $old_words);\n // if($new_word == \"you\"){\n // die_r(array());\n // }\n if( $new_word_index > -1) {\n // word already exists\n array_push($unchanged_words, $new_word);\n unset($old_words[$new_word_index]);\n } else {\n // word does not already exists\n array_push($added_words, $new_word);\n } \n \n }\n $deleted_words = $old_words;\n $added_word_count = count($added_words);\n $added_word_characters = strlen(implode(\" \", $added_words));\n}\ndie_r(array(\n \"old_data\"=> $old_data,\n \"new_data\"=> $new_data,\n \"unchanged_words\"=> $unchanged_words,\n \"added_words\"=> $added_words,\n \"deleted_words\"=> $deleted_words,\n \"added_word_count\"=>$added_word_count,\n \"added_word_characters\"=>$added_word_characters\n));"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321294",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21709/"
] |
321,299 | <p>I've seen a number of people claim that you should specifically name each column you want in your select query.</p>
<p>Assuming I'm going to use all of the columns anyway, why would I not use <code>SELECT *</code>?</p>
<p>Even considering the question *<a href="https://stackoverflow.com/questions/128412/sql-query-question-select-from-view-or-select-col1col2from-view">SQL query - Select * from view or Select col1, col2, … colN from view</a>*, I don't think this is an exact duplicate as I'm approaching the issue from a slightly different perspective. </p>
<p>One of our principles is to not optimize before it's time. With that in mind, it seems like using <code>SELECT *</code> should be the <strong>preferred</strong> method until it is proven to be a resource issue or the schema is pretty much set in stone. Which, as we know, won't occur until development is completely done.</p>
<p>That said, is there an overriding issue to not use <code>SELECT *</code>?</p>
| [
{
"answer_id": 321376,
"author": "dotjoe",
"author_id": 40822,
"author_profile": "https://Stackoverflow.com/users/40822",
"pm_score": 1,
"selected": false,
"text": "exists(select * ...)"
},
{
"answer_id": 321399,
"author": "kristof",
"author_id": 3241,
"author_profile": "https://Stackoverflow.com/users/3241",
"pm_score": 2,
"selected": false,
"text": "select *"
},
{
"answer_id": 322216,
"author": "Robert Paulson",
"author_id": 14033,
"author_profile": "https://Stackoverflow.com/users/14033",
"pm_score": 8,
"selected": true,
"text": "select *"
},
{
"answer_id": 1122127,
"author": "HLGEM",
"author_id": 9034,
"author_profile": "https://Stackoverflow.com/users/9034",
"pm_score": 1,
"selected": false,
"text": "Select *"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321299",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2424/"
] |
321,304 | <p>I've written this to try and log onto a forum (phpBB3).</p>
<pre><code>import urllib2, re
import urllib, re
logindata = urllib.urlencode({'username': 'x', 'password': 'y'})
page = urllib.urlopen("http://www.woarl.com/board/ucp.php?mode=login"[logindata])
output = page.read()
</code></pre>
<p>However when I run it it comes up with;</p>
<pre><code>Traceback (most recent call last):
File "C:/Users/Mike/Documents/python/test urllib2", line 4, in <module>
page = urllib.urlopen("http://www.woarl.com/board/ucp.php?mode=login"[logindata])
TypeError: string indices must be integers
</code></pre>
<p>any ideas as to how to solve this?</p>
<p><em>edit</em></p>
<p>adding a comma between the string and the data gives this error instead</p>
<pre><code>Traceback (most recent call last):
File "C:/Users/Mike/Documents/python/test urllib2", line 4, in <module>
page = urllib.urlopen("http://www.woarl.com/board/ucp.php?mode=login",[logindata])
File "C:\Python25\lib\urllib.py", line 84, in urlopen
return opener.open(url, data)
File "C:\Python25\lib\urllib.py", line 192, in open
return getattr(self, name)(url, data)
File "C:\Python25\lib\urllib.py", line 327, in open_http
h.send(data)
File "C:\Python25\lib\httplib.py", line 711, in send
self.sock.sendall(str)
File "<string>", line 1, in sendall
TypeError: sendall() argument 1 must be string or read-only buffer, not list
</code></pre>
<p><em>edit2</em></p>
<p>I've changed the code from what it was to;</p>
<pre><code>import urllib2, re
import urllib, re
logindata = urllib.urlencode({'username': 'x', 'password': 'y'})
page = urllib2.urlopen("http://www.woarl.com/board/ucp.php?mode=login", logindata)
output = page.read()
</code></pre>
<p>This doesn't throw any error messages, it just gives 3 blank lines. Is this because I'm trying to read from the log in page which disappears after logging in. If so how do I get it to display the index which is what should appear after hitting log in.</p>
| [
{
"answer_id": 321316,
"author": "Patrick Desjardins",
"author_id": 13913,
"author_profile": "https://Stackoverflow.com/users/13913",
"pm_score": 1,
"selected": false,
"text": "\"http://www.woarl.com/board/ucp.php?mode=login\"[logindata]\n"
},
{
"answer_id": 321317,
"author": "S.Lott",
"author_id": 10661,
"author_profile": "https://Stackoverflow.com/users/10661",
"pm_score": 1,
"selected": false,
"text": "\"http:...\""
},
{
"answer_id": 321322,
"author": "Eli Courtwright",
"author_id": 1694,
"author_profile": "https://Stackoverflow.com/users/1694",
"pm_score": 4,
"selected": true,
"text": "page = urllib.urlopen(\"http://www.woarl.com/board/ucp.php?mode=login\"[logindata])\n"
},
{
"answer_id": 321339,
"author": "Benjamin W. Smith",
"author_id": 1068060,
"author_profile": "https://Stackoverflow.com/users/1068060",
"pm_score": 1,
"selected": false,
"text": ">>> import urllib\n>>> logindata = urllib.urlencode({'username': 'x', 'password': 'y'})\n>>> type(logindata)\n<type 'str'>\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321304",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33061/"
] |
321,327 | <p>I have a situation where I am using wpf data binding and validation using the ExceptionValidationRule.</p>
<p>Another part of the solution invovles collapsing some panels and showing others.</p>
<p>If a validation exception is set - i.e. the UI is showing a red border around the UI element with the validation problem, and the containing panel is collapsed, the red border is still displayed. This is clearly not meant to be? Is there a workaround for this? Anyone know if this is by design?</p>
<p>Minimal code example provided (not my actual code, but replicates the problem). Create a new WpfApplication (I called mine WpfDataBindingProblem).</p>
<p>The xaml for window1 is as follows:</p>
<pre><code><Window x:Class="WpfDataBindingProblem.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<StackPanel Margin="5">
<StackPanel Name="panel1" Visibility="Visible" Margin="5">
<TextBox Name="DataBoundTextBox">
<Binding Path="TextValue">
<Binding.ValidationRules>
<ExceptionValidationRule/>
</Binding.ValidationRules>
</Binding>
</TextBox>
</StackPanel>
<StackPanel Name="panel2" Visibility="Collapsed" Margin="5">
<TextBlock>
The quick brown fox jumps over the lazy dog.
</TextBlock>
</StackPanel>
<Button Click="Button_Click" Margin="5">
Toggle panels
</Button>
</StackPanel>
</Window>
</code></pre>
<p>The code for window1 is as follows:</p>
<pre><code>using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfDataBindingProblem {
public partial class Window1 : Window {
public Window1() {
InitializeComponent();
this.DataContext = new MyClass("default");
}
private void Button_Click(object sender, RoutedEventArgs e) {
panel1.Visibility = panel1.Visibility == Visibility.Collapsed ?
Visibility.Visible : Visibility.Collapsed;
panel2.Visibility = panel2.Visibility == Visibility.Collapsed ?
Visibility.Visible : Visibility.Collapsed;
}
}
public class MyClass : INotifyPropertyChanged {
private string mTextValue;
public MyClass(string defaultText) {
TextValue = defaultText;
}
public string TextValue {
get {
return mTextValue;
}
set {
mTextValue = value;
if (string.IsNullOrEmpty(mTextValue)) {
throw new ApplicationException("Text value cannot be empty");
}
OnPropertyChanged(new PropertyChangedEventArgs("TextValue"));
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(PropertyChangedEventArgs e) {
if (this.PropertyChanged != null) {
this.PropertyChanged(this, e);
}
}
}
}
</code></pre>
<p>To reproduce the problem, run the application. Delete the <strong>default</strong> text from the textbox and tab off - red rectangle is shown indicating a validation problem. Click the button. Panel containing control with red rectangle is hidden and another panel is shown, but the red rectangle remains. Aargh!</p>
<p>All help much appreciated.</p>
<p>PS apologies for long question title!</p>
| [
{
"answer_id": 321367,
"author": "Sam Meldrum",
"author_id": 16005,
"author_profile": "https://Stackoverflow.com/users/16005",
"pm_score": 1,
"selected": false,
"text": "private void Button_Click(object sender, RoutedEventArgs e) {\n if (panel1.Visibility == Visibility.Collapsed) {\n panel1.Visibility = Visibility.Visible;\n DataBoundTextBox.GetBindingExpression(TextBox.TextProperty).UpdateSource();\n panel2.Visibility = Visibility.Collapsed;\n }\n else {\n panel1.Visibility = Visibility.Collapsed;\n DataBoundTextBox.GetBindingExpression(TextBox.TextProperty).UpdateTarget();\n panel2.Visibility = Visibility.Visible;\n }\n}\n"
},
{
"answer_id": 321987,
"author": "Donnelle",
"author_id": 28074,
"author_profile": "https://Stackoverflow.com/users/28074",
"pm_score": 6,
"selected": true,
"text": "<Setter Property=\"Validation.ErrorTemplate\">\n <Setter.Value>\n <ControlTemplate>\n <ControlTemplate.Resources>\n <BooleanToVisibilityConverter x:Key=\"converter\" />\n </ControlTemplate.Resources>\n <DockPanel LastChildFill=\"True\">\n <Border \n BorderThickness=\"1\"\n BorderBrush=\"Red\"\n Visibility=\"{Binding ElementName=placeholder, Mode=OneWay, Path=AdornedElement.IsVisible, Converter={StaticResource converter}}\">\n <AdornedElementPlaceholder x:Name=\"placeholder\" />\n </Border>\n </DockPanel>\n </ControlTemplate>\n </Setter.Value>\n</Setter>\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321327",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16005/"
] |
321,348 | <p>Both about <code>-a</code> and <code>-e</code> options in <a href="http://www.gnu.org/software/bash/manual/bashref.html#Bash-Conditional-Expressions" rel="noreferrer">Bash documentation</a> is said:</p>
<pre><code>-a file
True if file exists.
-e file
True if file exists.
</code></pre>
<p>Trying to get what the difference is I ran the following script:</p>
<pre><code>resin_dir=/Test/Resin_wheleph/Results
if [ -e ${resin_dir} ] ; then
echo "-e ";
fi
if [ ! -e ${resin_dir} ] ; then
echo "! -e";
fi
if [ -a ${resin_dir} ] ; then
echo "-a";
fi
if [ ! -a ${resin_dir} ] ; then
echo "! -a";
fi
</code></pre>
<p><code>/Test/Resin_wheleph/Results</code> exists and is a directory. And this is what I get:</p>
<pre><code>-e
-a
! -a
</code></pre>
<p>which seems to be a little strange (notice <code>-a</code> and <code>! -a</code>). But when I use double brackets (e. g. <code>if [[ -e ${resin_dir} ]]</code>) in the similar script it gives reasonable output:</p>
<pre><code>-e
-a
</code></pre>
<p>So: </p>
<ol>
<li>What is a difference between <code>-a</code> and <code>-e</code> options?</li>
<li>Why <code>-a</code> produces a strange result when used inside single brackets?</li>
</ol>
| [
{
"answer_id": 321352,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 7,
"selected": true,
"text": "-a"
},
{
"answer_id": 321419,
"author": "JimB",
"author_id": 32880,
"author_profile": "https://Stackoverflow.com/users/32880",
"pm_score": 0,
"selected": false,
"text": "$ [ $UNASIGNED_VAR == \"bar\" ]\nbash: [: ==: unary operator expected\n"
},
{
"answer_id": 321493,
"author": "Jonathan Leffler",
"author_id": 15168,
"author_profile": "https://Stackoverflow.com/users/15168",
"pm_score": 3,
"selected": false,
"text": "-a"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321348",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15647/"
] |
321,351 | <p>I have a structure which I create a custom constructor to initialize the members to 0's. I've seen in older compilers that when in release mode, without doing a memset to 0, the values are not initialized.</p>
<p>I now want to use this structure in a union, but get errors because it has a non-trivial constructor.</p>
<p>So, question 1. Does the default compiler implemented constructor guarantee that all members of a structure will be null initialized? The non-trivial constructor just does a memset of all the members to '0' to ensure a clean structure.</p>
<p>Question 2: If a constructor must be specified on the base structure, how can a union be implemented to contain that element and ensure a 0 initialized base element?</p>
| [
{
"answer_id": 321366,
"author": "John Dibling",
"author_id": 241536,
"author_profile": "https://Stackoverflow.com/users/241536",
"pm_score": 0,
"selected": false,
"text": "class Outer\n{\npublic:\n Outer()\n {\n memset(&inner_, 0, sizeof(inner_));\n }\nprivate:\n union Inner\n {\n int qty_;\n double price_;\n } inner_;\n};\n"
},
{
"answer_id": 321466,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "struct foo\n{\n int a;\n int b;\n};\n\nunion bar\n{\n int a;\n foo f;\n};\n\nbar b = { 0 };\n"
},
{
"answer_id": 321889,
"author": "David Rodríguez - dribeas",
"author_id": 36565,
"author_profile": "https://Stackoverflow.com/users/36565",
"pm_score": 7,
"selected": true,
"text": "union U \n{\n A a;\n B b;\n\n U() { memset( this, 0, sizeof( U ) ); }\n};\n"
},
{
"answer_id": 321907,
"author": "Adam Rosenfield",
"author_id": 9530,
"author_profile": "https://Stackoverflow.com/users/9530",
"pm_score": 2,
"selected": false,
"text": "struct foo\n{\n int a;\n int b;\n};\n\nunion bar\n{\n bar() { memset(this, 0, sizeof(*this)); }\n\n int a;\n foo f;\n};\n"
},
{
"answer_id": 33289972,
"author": "dan-man",
"author_id": 2399799,
"author_profile": "https://Stackoverflow.com/users/2399799",
"pm_score": 5,
"selected": false,
"text": "#include <new> // Required for placement 'new'.\n\nstruct Point {\n Point() {}\n Point(int x, int y): x_(x), y_(y) {}\n int x_, y_;\n};\n\nunion U {\n int z;\n double w;\n Point p; // Illegal in C++03; legal in C++11.\n U() {new(&p) Point();} // Due to the Point member, a constructor\n // definition is now *required*.\n};\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321351",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16496/"
] |
321,355 | <p>How would I set the "overwrite as needed" setting on Event logs other than Application/Security/System? Specifically I'd like to apply this to the Powershell and Windows Powershell Logs, in addition to any other future logs that may be added. This needs to be applied to both server 2003 & 2008.</p>
| [
{
"answer_id": 321576,
"author": "Zoredache",
"author_id": 20267,
"author_profile": "https://Stackoverflow.com/users/20267",
"pm_score": 2,
"selected": true,
"text": "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\Eventlog\\PowerShell\n"
},
{
"answer_id": 6771303,
"author": "rferrisx",
"author_id": 305675,
"author_profile": "https://Stackoverflow.com/users/305675",
"pm_score": 2,
"selected": false,
"text": "wevtutil sl <Log Name> /rt:false\n\nlimit-eventlog -Log Name -OverFlowAction OverwriteAsNeeded\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321355",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1635/"
] |
321,370 | <p>Can we convert a hex string to a byte array using a built-in function in C# or do I have to make a custom method for this?</p>
| [
{
"answer_id": 321404,
"author": "JaredPar",
"author_id": 23283,
"author_profile": "https://Stackoverflow.com/users/23283",
"pm_score": 10,
"selected": true,
"text": "public static byte[] StringToByteArray(string hex) {\n return Enumerable.Range(0, hex.Length)\n .Where(x => x % 2 == 0)\n .Select(x => Convert.ToByte(hex.Substring(x, 2), 16))\n .ToArray();\n}\n"
},
{
"answer_id": 8235530,
"author": "Aswath Krishnan",
"author_id": 1039182,
"author_profile": "https://Stackoverflow.com/users/1039182",
"pm_score": 6,
"selected": false,
"text": "public static byte[] ConvertHexStringToByteArray(string hexString)\n{\n if (hexString.Length % 2 != 0)\n {\n throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, \"The binary key cannot have an odd number of digits: {0}\", hexString));\n }\n\n byte[] data = new byte[hexString.Length / 2];\n for (int index = 0; index < data.Length; index++)\n {\n string byteValue = hexString.Substring(index * 2, 2);\n data[index] = byte.Parse(byteValue, NumberStyles.HexNumber, CultureInfo.InvariantCulture);\n }\n\n return data; \n}\n"
},
{
"answer_id": 9995303,
"author": "CainKellye",
"author_id": 356577,
"author_profile": "https://Stackoverflow.com/users/356577",
"pm_score": 7,
"selected": false,
"text": " public static byte[] StringToByteArrayFastest(string hex) {\n if (hex.Length % 2 == 1)\n throw new Exception(\"The binary key cannot have an odd number of digits\");\n\n byte[] arr = new byte[hex.Length >> 1];\n\n for (int i = 0; i < hex.Length >> 1; ++i)\n {\n arr[i] = (byte)((GetHexVal(hex[i << 1]) << 4) + (GetHexVal(hex[(i << 1) + 1])));\n }\n\n return arr;\n }\n\n public static int GetHexVal(char hex) {\n int val = (int)hex;\n //For uppercase A-F letters:\n //return val - (val < 58 ? 48 : 55);\n //For lowercase a-f letters:\n //return val - (val < 58 ? 48 : 87);\n //Or the two combined, but a bit slower:\n return val - (val < 58 ? 48 : (val < 97 ? 55 : 87));\n }\n"
},
{
"answer_id": 10757495,
"author": "Rick",
"author_id": 1417778,
"author_profile": "https://Stackoverflow.com/users/1417778",
"pm_score": 4,
"selected": false,
"text": "public static byte[] StrToByteArray(string str)\n {\n Dictionary<string, byte> hexindex = new Dictionary<string, byte>();\n for (int i = 0; i <= 255; i++)\n hexindex.Add(i.ToString(\"X2\"), (byte)i);\n\n List<byte> hexres = new List<byte>();\n for (int i = 0; i < str.Length; i += 2) \n hexres.Add(hexindex[str.Substring(i, 2)]);\n\n return hexres.ToArray();\n }\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321370",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39677/"
] |
321,377 | <p>I'm adding some lazy initialization logic to a const method, which makes the method in fact not const. Is there a way for me to do this without having to remove the "const" from the public interface?</p>
<pre><code>int MyClass::GetSomeInt() const
{
// lazy logic
if (m_bFirstTime)
{
m_bFirstTime = false;
Do something once
}
return some int...
}
</code></pre>
<p>EDIT: Does the "mutable" keyword play a role here?</p>
| [
{
"answer_id": 321387,
"author": "John Dibling",
"author_id": 241536,
"author_profile": "https://Stackoverflow.com/users/241536",
"pm_score": 4,
"selected": true,
"text": "class MyClass\n{\n : :\n mutable bool m_bFirstTime;\n};\n"
},
{
"answer_id": 321394,
"author": "John Dibling",
"author_id": 241536,
"author_profile": "https://Stackoverflow.com/users/241536",
"pm_score": 3,
"selected": false,
"text": "int MyClass::GetSomeInt() const\n{\n MyClass* that = const_cast<MyClass*>(this);\n\n // lazy logic\n if (that->m_bFirstTime)\n {\n that->m_bFirstTime = false;\n Do something once\n }\n\n return some int...\n\n}\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321377",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9328/"
] |
321,378 | <p>This only happens with IE (all versions), on line 1120 in
jquery-1.2.6.js I get the following error:</p>
<pre><code>Line 1120:
Invalid Property Value
</code></pre>
<p>The line in the js file is the following:</p>
<pre><code>elem[name] = value;
</code></pre>
<p>It is inside attr: <code>function( elem, name, value )</code></p>
<p>Does anybody have a problem similar to this? </p>
| [
{
"answer_id": 321416,
"author": "Simon",
"author_id": 33036,
"author_profile": "https://Stackoverflow.com/users/33036",
"pm_score": 3,
"selected": false,
"text": "jQuery.css('color', 'inherit');\n"
},
{
"answer_id": 376662,
"author": "Big Dave Diode",
"author_id": 9448,
"author_profile": "https://Stackoverflow.com/users/9448",
"pm_score": 0,
"selected": false,
"text": "$('div.foo').css('padding-left', 'NaNpx');\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321378",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
321,382 | <p>I am using cocos2d-iphone to place Sprites onto a Layer to setup a game playfield. At certain points in the game, certain Sprites need to be removed based upon game conditions. What I would like to do is setup an array of Sprite pointers, but I have two questions:</p>
<p>What's the best way to place Sprite pointers in an array? </p>
<p>How does one remove the Sprite in cocos2d with only a pointer to the Sprite? I know how to do it from its parent layer, but that is too runtime intensive for the main game loop.</p>
<p>Thanks in advance!</p>
| [
{
"answer_id": 321554,
"author": "e.James",
"author_id": 33686,
"author_profile": "https://Stackoverflow.com/users/33686",
"pm_score": 3,
"selected": true,
"text": "Sprite"
},
{
"answer_id": 321593,
"author": "user21293",
"author_id": 21293,
"author_profile": "https://Stackoverflow.com/users/21293",
"pm_score": 2,
"selected": false,
"text": "Sprite * mySprites[10][10]; // assuming a 10x10 playfield where obstacles get placed\n"
},
{
"answer_id": 10769906,
"author": "buildsucceeded",
"author_id": 395295,
"author_profile": "https://Stackoverflow.com/users/395295",
"pm_score": 2,
"selected": false,
"text": "[mySprite removeFromParentAndCleanup:YES]"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321382",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21293/"
] |
321,403 | <p>How would I go about adding the "Spent Time" as a column to be displayed in the issues list?</p>
| [
{
"answer_id": 4074299,
"author": "user2067021",
"author_id": 2067021,
"author_profile": "https://Stackoverflow.com/users/2067021",
"pm_score": 4,
"selected": false,
"text": " field_spent_hours: Spent time\n"
},
{
"answer_id": 4403442,
"author": "stwienert",
"author_id": 220292,
"author_profile": "https://Stackoverflow.com/users/220292",
"pm_score": 2,
"selected": false,
"text": "base.add_available_column(QueryColumn.new(:spent_hours, \n :sortable => \"(select sum(hours) from time_entries where time_entries.issue_id = t0_r0)\")\n) \n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321403",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1976/"
] |
321,413 | <p>What the difference between <code>LPCSTR</code>, <code>LPCTSTR</code> and <code>LPTSTR</code>?</p>
<p>Why do we need to do this to convert a string into a <code>LV</code> / <code>_ITEM</code> structure variable <code>pszText</code>: </p>
<pre><code>LV_DISPINFO dispinfo;
dispinfo.item.pszText = LPTSTR((LPCTSTR)string);
</code></pre>
| [
{
"answer_id": 321447,
"author": "Tim",
"author_id": 10755,
"author_profile": "https://Stackoverflow.com/users/10755",
"pm_score": 7,
"selected": false,
"text": "LP"
},
{
"answer_id": 321448,
"author": "John Sibly",
"author_id": 1078,
"author_profile": "https://Stackoverflow.com/users/1078",
"pm_score": 8,
"selected": true,
"text": "LPCSTR"
},
{
"answer_id": 321462,
"author": "JaredPar",
"author_id": 23283,
"author_profile": "https://Stackoverflow.com/users/23283",
"pm_score": 3,
"selected": false,
"text": "LPWSTR"
},
{
"answer_id": 7313635,
"author": "AAT",
"author_id": 121921,
"author_profile": "https://Stackoverflow.com/users/121921",
"pm_score": 3,
"selected": false,
"text": "LV_DISPINFO dispinfo; \ndispinfo.item.pszText = LPTSTR((LPCTSTR)string);\n"
},
{
"answer_id": 46457146,
"author": "Ian Boyd",
"author_id": 12597,
"author_profile": "https://Stackoverflow.com/users/12597",
"pm_score": 6,
"selected": false,
"text": "char"
},
{
"answer_id": 65299677,
"author": "zar",
"author_id": 841330,
"author_profile": "https://Stackoverflow.com/users/841330",
"pm_score": 0,
"selected": false,
"text": "CString"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321413",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41090/"
] |
321,417 | <p>I'm trying to set the initial display order of the column headers in a silverlight datagrid by changing the column header DisplayIndex values. If I try to set the column order at page load time, I get an out of range exception. If I set the column order (same routine) at a later time like, in a button click handler, it works. Is this just a bug in the silverlight datagrid control? Suggestions for a possible work around?</p>
| [
{
"answer_id": 343664,
"author": "David Padbury",
"author_id": 26401,
"author_profile": "https://Stackoverflow.com/users/26401",
"pm_score": 1,
"selected": false,
"text": "private void grid_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)\n{\n switch (e.PropertyName)\n {\n case \"Name\":\n e.Column.DisplayIndex = 1;\n break;\n\n case \"Age\":\n e.Column.DisplayIndex = 0;\n break;\n }\n}\n"
},
{
"answer_id": 2295348,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "public UserManagementControl()\n {\n InitializeComponent();\n dataGridUsers.Loaded += new RoutedEventHandler(dataGridUsers_Loaded);\n }\n\n void dataGridUsers_Loaded(object sender, RoutedEventArgs e)\n {\n dataGridUsers.Columns[0].DisplayIndex = 1;\n }\n"
},
{
"answer_id": 8080317,
"author": "xidius",
"author_id": 1039857,
"author_profile": "https://Stackoverflow.com/users/1039857",
"pm_score": 0,
"selected": false,
"text": "/// <summary>\n/// Automation DataGrid Control - Columns Localization and Ordering\n/// Option1: Localization of Columns Automatically\n/// Option2: Ordering columns in DataGrid Automatically\n/// </summary>\n/// <param name=\"dataGrid\"> DataGrid control</param>\n/// <param name=\"ContractType\"> Contract of Row DataItem \n/// Example: typeof(ClientType) \n/// </param>\n/// <param name=\"columns\"> Ordered Properties of Contract\n/// Example: columns = \"Id_Client,Client,GeographyItem,Flag_Approved,ClientType,ClientRelation,ClientPrestigeLevel\"\n/// </param>\npublic void AutomateDataGridColumns(DataGrid dataGrid, Type Contract, String columns)\n{\n try\n { \n List<String> OrderedColumns = columns.Split(new string[] { \",\", \"|\", \";\" }, StringSplitOptions.RemoveEmptyEntries).ToList();\n\n //Buid Order of created COLUMNS\n dataGrid.Loaded += (sndr, arg) =>\n {\n if (dataGrid.Columns.Count == OrderedColumns.Count && dataGrid.AutoGenerateColumns == true) \n {\n foreach (var item in dataGrid.Columns)\n {\n Int32 displayIndex = OrderedColumns.IndexOf(item.Header.ToString());\n if (displayIndex != -1)\n { item.DisplayIndex = displayIndex; } \n }\n };\n };\n\n //DataGridColumn Localization \n dataGrid.AutoGeneratingColumn += (sndr, arg) =>\n {\n LocalizeDataGridColumn(sndr as DataGrid, arg, Contract, OrderedColumns);\n\n //We need To Update DataGrid after last Column Localized -->so Loaded event will be Raised/\n // or ArgumentOutOfRange Exception will be thrown\n if (dataGrid.Columns.Count == OrderedColumns.Count && dataGrid.AutoGenerateColumns == true)\n {\n dataGrid.UpdateLayout();\n }\n };\n\n } \n catch (Exception exc)\n { throw exc;\n }\n}\n\n\n\n/// <summary>\n/// DataGridColumn Control Localization\n/// </summary>\n/// <param name=\"dataGrid\">Host DataGrid control </param>\n/// <param name=\"arg\">Auto Generated Column arg </param>\n/// <param name=\"Contract\">Type Contract</param>\n/// <param name=\"localizationColumns\">Ordered Properties to Contract </param>\nprotected void LocalizeDataGridColumn(DataGrid dataGrid, DataGridAutoGeneratingColumnEventArgs arg, Type Contract, List<String> localizationColumns)\n{\n try\n {\n DataGridColumn Column = arg.Column;\n\n if (localizationColumns.Contains(Column.Header.ToString()))\n {\n // LOCALIZING Column.Header \n\n // Check column local resource key exist \n // CultureKeys - local Culture enum type \n // SystemDispatcher - is My SL4 MEF Bootstrappper \n // LocalizationService - is My Localization service in SL4 \n // if somebody is interested i can share more of my LocalizationService - use mail \n CultureKeys currntCulture = SystemDispatcher.LocalizationService.CurrentCulture;\n string ResourceKey = LocalResKeys.BoPropElmNameLoc.ToString() + \"\\\\\" + Contract.Name + @\"|\" + Column.Header.ToString();\n\n if (SystemDispatcher.LocalizationService.CultureResources[currntCulture].Item2.ContainsKey(ResourceKey))\n Column.Header = SystemDispatcher.LocalizationService.CultureResources[currntCulture].Item2[ResourceKey]; \n }\n else\n { arg.Cancel = true;\n }\n }\n catch (Exception exc)\n {\n throw exc;\n }\n\n}\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321417",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11930/"
] |
321,418 | <p>Consider the code:</p>
<pre><code>PreparedStatement ps = null;
ResultSet rs = null;
try {
ps = conn.createStatement(myQueryString);
rs = ps.executeQuery();
// process the results...
} catch (java.sql.SQLException e) {
log.error("an error!", e);
throw new MyAppException("I'm sorry. Your query did not work.");
} finally {
ps.close();
rs.close();
}
</code></pre>
<p>The above does not compile, because both <code>PreparedStatement.close()</code> and <code>ResultSet.close()</code> throw a <code>java.sql.SQLException</code>. So do I add a try/catch block to the finally clause? Or move the close statements into the try clause? Or just not bother calling close?</p>
| [
{
"answer_id": 321452,
"author": "Steve B.",
"author_id": 19479,
"author_profile": "https://Stackoverflow.com/users/19479",
"pm_score": 5,
"selected": false,
"text": "public static void close(ResultSet rs, Statement ps, Connection conn)\n{\n if (rs!=null)\n {\n try\n {\n rs.close();\n\n }\n catch(SQLException e)\n {\n logger.error(\"The result set cannot be closed.\", e);\n }\n }\n if (ps != null)\n {\n try\n {\n ps.close();\n } catch (SQLException e)\n {\n logger.error(\"The statement cannot be closed.\", e);\n }\n }\n if (conn != null)\n {\n try\n {\n conn.close();\n } catch (SQLException e)\n {\n logger.error(\"The data source connection cannot be closed.\", e);\n }\n }\n\n}\n"
},
{
"answer_id": 321453,
"author": "Chris Nava",
"author_id": 45163,
"author_profile": "https://Stackoverflow.com/users/45163",
"pm_score": -1,
"selected": false,
"text": "finally\n{\n if (ps != null) ps.close();\n if (rs != null) rs.close();\n}\n"
},
{
"answer_id": 321454,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 3,
"selected": false,
"text": "close()"
},
{
"answer_id": 321879,
"author": "erickson",
"author_id": 3474,
"author_profile": "https://Stackoverflow.com/users/3474",
"pm_score": 6,
"selected": false,
"text": "private void doEverythingInOneSillyMethod(String key)\n throws MyAppException\n{\n try (Connection db = ds.getConnection()) {\n db.setReadOnly(true);\n ...\n try (PreparedStatement ps = db.prepareStatement(...)) {\n ps.setString(1, key);\n ...\n try (ResultSet rs = ps.executeQuery()) {\n ...\n }\n }\n } catch (SQLException ex) {\n throw new MyAppException(\"Query failed.\", ex);\n }\n}\n"
},
{
"answer_id": 11824592,
"author": "Kris",
"author_id": 1578631,
"author_profile": "https://Stackoverflow.com/users/1578631",
"pm_score": -1,
"selected": false,
"text": "finally {\n try {\n rs.close();\n ps.close();\n } catch (Exception e) {\n // Do something\n }\n}\n"
},
{
"answer_id": 11824707,
"author": "Guido",
"author_id": 12388,
"author_profile": "https://Stackoverflow.com/users/12388",
"pm_score": 2,
"selected": false,
"text": "PreparedStatement"
},
{
"answer_id": 17057974,
"author": "Xin",
"author_id": 2009500,
"author_profile": "https://Stackoverflow.com/users/2009500",
"pm_score": 1,
"selected": false,
"text": "static String readFirstLineFromFile(String path) throws IOException {\n try (BufferedReader br =\n new BufferedReader(new FileReader(path))) {\n return br.readLine();\n }\n}\n"
},
{
"answer_id": 27352089,
"author": "silver",
"author_id": 2806819,
"author_profile": "https://Stackoverflow.com/users/2806819",
"pm_score": 0,
"selected": false,
"text": "public class DatabaseTest {\n\n private Connection conn; \n private Statement st; \n private ResultSet rs;\n private PreparedStatement ps;\n\n public DatabaseTest() {\n // if needed\n }\n\n public String getSomethingFromDatabase(...) {\n String something = null;\n\n // code here\n\n try {\n // code here\n\n } catch(SQLException se) {\n se.printStackTrace();\n\n } finally { // will always execute even after a return statement\n closeDatabaseResources();\n }\n\n return something;\n }\n\n private void closeDatabaseResources() {\n try {\n if(conn != null) {\n System.out.println(\"conn closed\");\n conn.close();\n }\n\n if(st != null) {\n System.out.println(\"st closed\");\n st.close();\n }\n\n if(rs != null) {\n System.out.println(\"rs closed\");\n rs.close();\n }\n\n if(ps != null) {\n System.out.println(\"ps closed\");\n ps.close();\n }\n\n } catch(SQLException se) {\n se.printStackTrace();\n } \n }\n}\n"
},
{
"answer_id": 43261594,
"author": "Catfish",
"author_id": 222403,
"author_profile": "https://Stackoverflow.com/users/222403",
"pm_score": 2,
"selected": false,
"text": "try"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321418",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1094969/"
] |
321,423 | <p>Are there any libraries or guides for how to read and parse binary data in C?</p>
<p>I am looking at some functionality that will receive TCP packets on a network socket and then parse that binary data according to a specification, turning the information into a more useable form by the code.</p>
<p>Are there any libraries out there that do this, or even a primer on performing this type of thing?</p>
| [
{
"answer_id": 321460,
"author": "Gwaredd",
"author_id": 37304,
"author_profile": "https://Stackoverflow.com/users/37304",
"pm_score": 2,
"selected": false,
"text": "struct SomeDataFormat\n{\n ....\n}\n\nSomeDataFormat* pParsedData = (SomeDataFormat*) pBuffer;\n"
},
{
"answer_id": 323122,
"author": "qrdl",
"author_id": 28494,
"author_profile": "https://Stackoverflow.com/users/28494",
"pm_score": 1,
"selected": false,
"text": "struct"
},
{
"answer_id": 323150,
"author": "unwind",
"author_id": 28169,
"author_profile": "https://Stackoverflow.com/users/28169",
"pm_score": 3,
"selected": false,
"text": "struct"
},
{
"answer_id": 324115,
"author": "Casey Barker",
"author_id": 7046,
"author_profile": "https://Stackoverflow.com/users/7046",
"pm_score": 5,
"selected": false,
"text": "typedef struct _MyProtocolData\n{\n Bool myBitA; // Using a \"Bool\" type wastes a lot of space, but it's fast.\n Bool myBitB;\n Word32 myWord; // You have a list of base types like Word32, right?\n} MyProtocolData;\n\nVoid myProtocolParse(const Byte *pProtocol, MyProtocolData *pData)\n{\n // Somewhere, your code has to pick out the bits. Best to just do it one place.\n pData->myBitA = *(pProtocol + MY_BITS_OFFSET) & MY_BIT_A_MASK >> MY_BIT_A_SHIFT;\n pData->myBitB = *(pProtocol + MY_BITS_OFFSET) & MY_BIT_B_MASK >> MY_BIT_B_SHIFT;\n\n // Endianness and Alignment issues go away when you fetch byte-at-a-time.\n // Here, I'm assuming the protocol is big-endian.\n // You could also write a library of \"word fetchers\" for different sizes and endiannesses.\n pData->myWord = *(pProtocol + MY_WORD_OFFSET + 0) << 24;\n pData->myWord += *(pProtocol + MY_WORD_OFFSET + 1) << 16;\n pData->myWord += *(pProtocol + MY_WORD_OFFSET + 2) << 8;\n pData->myWord += *(pProtocol + MY_WORD_OFFSET + 3);\n\n // You could return something useful, like the end of the protocol or an error code.\n}\n\nVoid myProtocolPack(const MyProtocolData *pData, Byte *pProtocol)\n{\n // Exercise for the reader! :)\n}\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321423",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/277/"
] |
321,429 | <p>In my WPF app, I call a WCF service to retrieve my business object. I take that business object and bind it to a grid. I want to now apply the INotifyPropertyChanged attribute, but am unsure if it would work from WCF. My ultimate goal is to be able to edit items in a grid, click update and push those back through a WCF service. </p>
| [
{
"answer_id": 321438,
"author": "leppie",
"author_id": 15541,
"author_profile": "https://Stackoverflow.com/users/15541",
"pm_score": 4,
"selected": true,
"text": "svcutil /enableDataBinding"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321429",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3047/"
] |
321,455 | <p>The task is to take a list of tables which is changeable.</p>
<p>Write a piece of PL/SQL that when executed outputs every tables rows into individual csv files.</p>
<p>So if 5 tables. You will get 5 CSV files with the relevant table data in it.</p>
<p>The CSV should be | delimited and have " around each value (for easy import to excel)</p>
<p>All I know is the list of tables.</p>
<p>So load the list into an array at the top of the procedure, loop through this list and use UTL_FILE to output each row on a line by line basis.</p>
<p>I'm stuffed wondering if I need a cursor per table or if the cursor can be used dynamically to store the results from each table.</p>
<p>p.s. each file must also contain the column headings as the first row.</p>
<p>Is it even possible ? There is a list of over 30 tables, some of the tables have over 200 columns.</p>
<p>So ideas please :).</p>
<p>I'm slowly thinking this isn't possible. as i need some dynamic SQL that can gather all the column names etc. I'm getting bogged down!</p>
<p>It can't be a SQL script and simply spooling the output. All we ever want to do is add or remove tables from the array declaration.</p>
| [
{
"answer_id": 321472,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "SELECT * FROM ALL_TAB_COLUMNS \n"
},
{
"answer_id": 321507,
"author": "user34850",
"author_id": 34850,
"author_profile": "https://Stackoverflow.com/users/34850",
"pm_score": 0,
"selected": false,
"text": "DECLARE\n TYPE IDCurTyp IS REF CURSOR;\n fo UTL_FILE.FILE_TYPE;\n varRow VARCHAR2(4000);\n cur_output IDCurTyp;\nBEGIN\n fo := UTL_FILE.FOPEN('BILLING_DIR','BillingFile1.csv', 'W', 2000)\n OPEN cur_output FOR\n 'SELECT ''\"'' || t1.col1 || ''\",'' || t1.col2 || ''\",\"'' || t1.col2 || ''\"'' FROM t1'\n LOOP\n FETCH cur_output INTO varRow;\n EXIT WHEN cur_output%NOTFOUND;\n UTL_FILE.putf( fo, '%s\\n', varRow );\n END LOOP;\n\n CLOSE cur_output;\n\n UTL_FILE.FCLOSE( fo );\nEND:\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321455",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27412/"
] |
321,461 | <p>I was reading about refactoring a large slow SQL Query over <a href="https://stackoverflow.com/questions/320919/refactoring-extreme-sql-queries">here</a>, and the current highest response is from Mitch Wheat, who wants to make sure the query uses indexes for the major selects, and mentions:</p>
<blockquote>
<p>First thing I would do is check to make sure there is an active index maintenance job being run periodically. If not, get all existing indexs rebuilt or if not possible at least get statistics updated.</p>
</blockquote>
<p>I'm only am amateur DBA, and I've made a few programs freelance that are basically Java desktop clients and occasionally a MySQL backend. When I set up the system, I know to create an index on the columns that will be queried by, there's a varchar CaseID and a varchar CustName.</p>
<p>However, I set this system up months ago and left the client operating it, and I believe the indexes should grow as data is entered and I believe everything is still working nicely. I'm worried though that the indexes should be rebuilt periodically, because today i have read that there should be an 'active maintenance job'. The only maintenance job I set on the thing was a nightly backup.</p>
<p>I wanted to ask the community about regular maintenance that a database might require. Is it neccessary to rebuild indexes? Can I trust the MySQL backend to keep going so long as no one messes with it and the data stays under a few gigabytes?</p>
| [
{
"answer_id": 321606,
"author": "Eli",
"author_id": 5958,
"author_profile": "https://Stackoverflow.com/users/5958",
"pm_score": 4,
"selected": false,
"text": "mysqlcheck -Aaos"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321461",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36093/"
] |
321,465 | <p>So I have this app that checks for updates on the server getting a JSON response, each new update is put at the top of my list on a new div that is added via insertBefore using javascript.</p>
<p>All works just fine, but i'd like to add an animation effect when the div is added, i.e. "slowly" move the existing divs down, and add the new one at the top, Any pointers on how to do that ?</p>
<p>The application actually runs in facebook not using the iframe, I tried to use jquery but it does not seem to work on facebook, and looking at the code modifications that FB do, I assume other frameworks will have a similar problem.</p>
| [
{
"answer_id": 321577,
"author": "strager",
"author_id": 39992,
"author_profile": "https://Stackoverflow.com/users/39992",
"pm_score": 2,
"selected": false,
"text": "$(myListItem).hide().slideDown(2000);\n"
},
{
"answer_id": 322189,
"author": "Nathaniel Reinhart",
"author_id": 41122,
"author_profile": "https://Stackoverflow.com/users/41122",
"pm_score": 3,
"selected": true,
"text": "var newDiv; \n\nfunction insertNewDiv() {\n// This is called when you realize something was updated \n// ... \n newDiv = document.createElement('div');\n newDiv.style.height = \"0px\";\n document.body.appendChild(newDiv); \n setTimeout(slideInDiv, 0);\n}\n\nfunction slideInDiv(){ \n newDiv.style.height = newDiv.clientHeight + 10 + \"px\"; // Slowly make it bigger\n\n if (newDiv.clientHeight < 100){\n setTimeout(slideInDiv, 40); // 40ms is approx 25 fps\n } else {\n addContent();\n }\n}\n\n\nfunction addContent(){ \n newDiv.innerHTML = \"Done!\";\n}\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321465",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23238/"
] |
321,477 | <p>I am printing out a list of college majors we offer, then within each major, we have concentrations for each major.</p>
<p>Our Science Major has the following concentrations: Environmental Science & Forestry, Chiropractic, Chemistry, Biology</p>
<p>Here is a screen shot of what it is doing:
<a href="https://i.stack.imgur.com/sNslE.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sNslE.jpg" alt="alt text"></a>
</p>
<p>I do not want the spacing it displays (I do not want the spacing you see after Human Resource Management AAS and after Psychology.) in the screen shot, any help is appreciated.</p>
<p>The source would look like this:</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-css lang-css prettyprint-override"><code>.col-middle .majors-list li {
list-style-type: none;
width: 50%;
float: left;
margin-bottom: 2px;
}
.col-middle ul.majors-list {
margin-left: 0;
}
.col-middle ul.concentrations-list {
overflow: auto;
}
.col-middle .concentrations-list li {
float: none;
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code><ul class="majors-list">
<li>Major
<ul class="concentrations-list">
<li>Concentration Item</li>
<li>Concentration Item</li>
<li>Concentration Item</li>
<li>Concentration Item</li>
</ul>
</li>
<li>Major
<ul class="concentrations-list">
<li>Concentration Item</li>
<li>Concentration Item</li>
<li>Concentration Item</li>
<li>Concentration Item</li>
</ul>
</li>
<li>Major
<ul class="concentrations-list">
<li>Concentration Item</li>
<li>Concentration Item</li>
<li>Concentration Item</li>
<li>Concentration Item</li>
</ul>
</li>
<li>Major
<ul class="concentrations-list">
<li>Concentration Item</li>
<li>Concentration Item</li>
<li>Concentration Item</li>
<li>Concentration Item</li>
</ul>
</li>
</ul></code></pre>
</div>
</div>
</p>
| [
{
"answer_id": 321772,
"author": "mike nvck",
"author_id": 36531,
"author_profile": "https://Stackoverflow.com/users/36531",
"pm_score": 0,
"selected": false,
"text": "display: none;"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321477",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26130/"
] |
321,478 | <p>I've been reading through a few tutorials about css, and I saw two different ways to state which css file should be used to style the page:</p>
<pre><code><style type="text/css">@import url("style.css");</style>
</code></pre>
<p>and</p>
<pre><code><link rel="stylesheet" type="text/css" href="style.css" />
</code></pre>
<p>What's the difference between them? Which one should I use?</p>
| [
{
"answer_id": 321495,
"author": "Kostis",
"author_id": 35913,
"author_profile": "https://Stackoverflow.com/users/35913",
"pm_score": 1,
"selected": false,
"text": "ob_start (\"ob_gzhandler\");\nheader(\"Content-type: text/css\");\nheader(\"Cache-Control: must-revalidate\");\n$offset = 60 * 60 ;\n$ExpStr = \"Expires: \" . gmdate(\"D, d M Y H:i:s\",time() + $offset) . \" GMT\";\nheader($ExpStr); \necho (\"@import url(style1.css);\\r\");\necho (\"@import url(style2.css);\\r\");\necho (\"@import url(style3.css);\\r\");\n"
},
{
"answer_id": 321498,
"author": "One Crayon",
"author_id": 38666,
"author_profile": "https://Stackoverflow.com/users/38666",
"pm_score": 1,
"selected": false,
"text": "<link>"
},
{
"answer_id": 321533,
"author": "Eli",
"author_id": 5958,
"author_profile": "https://Stackoverflow.com/users/5958",
"pm_score": 1,
"selected": false,
"text": "@import"
},
{
"answer_id": 321846,
"author": "Armstrongest",
"author_id": 26931,
"author_profile": "https://Stackoverflow.com/users/26931",
"pm_score": 3,
"selected": false,
"text": "// bring CSS into the Page\n<style type=\"text/css\">@import url(\"importedStyles.css\");</style>\n\n/// Link to CSS Style Sheet\n<link rel=\"stylesheet\" type=\"text/css\" href=\"linkedStyles.css\" />\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321478",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27090/"
] |
321,494 | <p>I have a cron "time definition"</p>
<pre><code>1 * * * * (every hour at xx:01)
2 5 * * * (every day at 05:02)
0 4 3 * * (every third day of the month at 04:00)
* 2 * * 5 (every minute between 02:00 and 02:59 on fridays)
</code></pre>
<p>And I have an unix timestamp.</p>
<p>Is there an obvious way to find (calculate) the next time (after that given timestamp) the job is due to be executed?</p>
<p>I'm using PHP, but the problem should be fairly language-agnostic.</p>
<p>[Update]</p>
<p>The class "<a href="http://www.phpclasses.org/browse/package/2568.html" rel="noreferrer">PHP Cron Parser</a>" (suggested by Ray) calculates the LAST time the CRON job was supposed to be executed, not the next time.</p>
<p>To make it easier: In my case the cron time parameters are only absolute, single numbers or "*". There are no time-ranges and no "*/5" intervals.</p>
| [
{
"answer_id": 322058,
"author": "dlamblin",
"author_id": 459,
"author_profile": "https://Stackoverflow.com/users/459",
"pm_score": 6,
"selected": true,
"text": "//Totaly made up language\nnext = getTimeNow();\nnext.addMinutes(1) //so that next is never now\ndone = false;\nwhile (!done) {\n if (cron.minute != '*' && next.minute != cron.minute) {\n if (next.minute > cron.minute) {\n next.addHours(1);\n }\n next.minute = cron.minute;\n }\n if (cron.hour != '*' && next.hour != cron.hour) {\n if (next.hour > cron.hour) {\n next.hour = cron.hour;\n next.addDays(1);\n next.minute = 0;\n continue;\n }\n next.hour = cron.hour;\n next.minute = 0;\n continue;\n }\n if (cron.weekday != '*' && next.weekday != cron.weekday) {\n deltaDays = cron.weekday - next.weekday //assume weekday is 0=sun, 1 ... 6=sat\n if (deltaDays < 0) { deltaDays+=7; }\n next.addDays(deltaDays);\n next.hour = 0;\n next.minute = 0;\n continue;\n }\n if (cron.day != '*' && next.day != cron.day) {\n if (next.day > cron.day || !next.month.hasDay(cron.day)) {\n next.addMonths(1);\n next.day = 1; //assume days 1..31\n next.hour = 0;\n next.minute = 0;\n continue;\n }\n next.day = cron.day\n next.hour = 0;\n next.minute = 0;\n continue;\n }\n if (cron.month != '*' && next.month != cron.month) {\n if (next.month > cron.month) {\n next.addMonths(12-next.month+cron.month)\n next.day = 1; //assume days 1..31\n next.hour = 0;\n next.minute = 0;\n continue;\n }\n next.month = cron.month;\n next.day = 1;\n next.hour = 0;\n next.minute = 0;\n continue;\n }\n done = true;\n}\n"
},
{
"answer_id": 323780,
"author": "BlaM",
"author_id": 999,
"author_profile": "https://Stackoverflow.com/users/999",
"pm_score": 3,
"selected": false,
"text": "class myMiniDate {\n var $myTimestamp;\n static private $dateComponent = array(\n 'second' => 's',\n 'minute' => 'i',\n 'hour' => 'G',\n 'day' => 'j',\n 'month' => 'n',\n 'year' => 'Y',\n 'dow' => 'w',\n 'timestamp' => 'U'\n );\n static private $weekday = array(\n 1 => 'monday',\n 2 => 'tuesday',\n 3 => 'wednesday',\n 4 => 'thursday',\n 5 => 'friday',\n 6 => 'saturday',\n 0 => 'sunday'\n );\n\n function __construct($ts = NULL) { $this->myTimestamp = is_null($ts)?time():$ts; }\n\n function __set($var, $value) {\n list($c['second'], $c['minute'], $c['hour'], $c['day'], $c['month'], $c['year'], $c['dow']) = explode(' ', date('s i G j n Y w', $this->myTimestamp));\n switch ($var) {\n case 'dow':\n $this->myTimestamp = strtotime(self::$weekday[$value], $this->myTimestamp);\n break;\n\n case 'timestamp':\n $this->myTimestamp = $value;\n break;\n\n default:\n $c[$var] = $value;\n $this->myTimestamp = mktime($c['hour'], $c['minute'], $c['second'], $c['month'], $c['day'], $c['year']);\n }\n }\n\n\n function __get($var) {\n return date(self::$dateComponent[$var], $this->myTimestamp);\n }\n\n function modify($how) { return $this->myTimestamp = strtotime($how, $this->myTimestamp); }\n}\n\n\n$cron = new myMiniDate(time() + 60);\n$cron->second = 0;\n$done = 0;\n\necho date('Y-m-d H:i:s') . '<hr>' . date('Y-m-d H:i:s', $cron->timestamp) . '<hr>';\n\n$Job = array(\n 'Minute' => 5,\n 'Hour' => 3,\n 'Day' => 13,\n 'Month' => null,\n 'DOW' => 5,\n );\n\nwhile ($done < 100) {\n if (!is_null($Job['Minute']) && ($cron->minute != $Job['Minute'])) {\n if ($cron->minute > $Job['Minute']) {\n $cron->modify('+1 hour');\n }\n $cron->minute = $Job['Minute'];\n }\n if (!is_null($Job['Hour']) && ($cron->hour != $Job['Hour'])) {\n if ($cron->hour > $Job['Hour']) {\n $cron->modify('+1 day');\n }\n $cron->hour = $Job['Hour'];\n $cron->minute = 0;\n }\n if (!is_null($Job['DOW']) && ($cron->dow != $Job['DOW'])) {\n $cron->dow = $Job['DOW'];\n $cron->hour = 0;\n $cron->minute = 0;\n }\n if (!is_null($Job['Day']) && ($cron->day != $Job['Day'])) {\n if ($cron->day > $Job['Day']) {\n $cron->modify('+1 month');\n }\n $cron->day = $Job['Day'];\n $cron->hour = 0;\n $cron->minute = 0;\n }\n if (!is_null($Job['Month']) && ($cron->month != $Job['Month'])) {\n if ($cron->month > $Job['Month']) {\n $cron->modify('+1 year');\n }\n $cron->month = $Job['Month'];\n $cron->day = 1;\n $cron->hour = 0;\n $cron->minute = 0;\n }\n\n $done = (is_null($Job['Minute']) || $Job['Minute'] == $cron->minute) &&\n (is_null($Job['Hour']) || $Job['Hour'] == $cron->hour) &&\n (is_null($Job['Day']) || $Job['Day'] == $cron->day) &&\n (is_null($Job['Month']) || $Job['Month'] == $cron->month) &&\n (is_null($Job['DOW']) || $Job['DOW'] == $cron->dow)?100:($done+1);\n}\n\necho date('Y-m-d H:i:s', $cron->timestamp) . '<hr>';\n"
},
{
"answer_id": 3453872,
"author": "Michael Dowling",
"author_id": 151504,
"author_profile": "https://Stackoverflow.com/users/151504",
"pm_score": 5,
"selected": false,
"text": "<?php\n\n// Works with predefined scheduling definitions\n$cron = Cron\\CronExpression::factory('@daily');\n$cron->isDue();\n$cron->getNextRunDate();\n$cron->getPreviousRunDate();\n\n// Works with complex expressions\n$cron = Cron\\CronExpression::factory('15 2,6-12 */15 1 2-5');\n$cron->getNextRunDate();\n"
},
{
"answer_id": 5727401,
"author": "diyism",
"author_id": 264181,
"author_profile": "https://Stackoverflow.com/users/264181",
"pm_score": 3,
"selected": false,
"text": "function parse_crontab($time, $crontab)\n {$time=explode(' ', date('i G j n w', strtotime($time)));\n $crontab=explode(' ', $crontab);\n foreach ($crontab as $k=>&$v)\n {$v=explode(',', $v);\n foreach ($v as &$v1)\n {$v1=preg_replace(array('/^\\*$/', '/^\\d+$/', '/^(\\d+)\\-(\\d+)$/', '/^\\*\\/(\\d+)$/'),\n array('true', '\"'.$time[$k].'\"===\"\\0\"', '(\\1<='.$time[$k].' and '.$time[$k].'<=\\2)', $time[$k].'%\\1===0'),\n $v1\n );\n }\n $v='('.implode(' or ', $v).')';\n }\n $crontab=implode(' and ', $crontab);\n return eval('return '.$crontab.';');\n }\nvar_export(parse_crontab('2011-05-04 02:08:03', '*/2,3-5,9 2 3-5 */2 *'));\nvar_export(parse_crontab('2011-05-04 02:08:03', '*/8 */2 */4 */5 *'));\n"
},
{
"answer_id": 28242522,
"author": "epepepep",
"author_id": 4512615,
"author_profile": "https://Stackoverflow.com/users/4512615",
"pm_score": 2,
"selected": false,
"text": "date('i G j n w', $time)"
},
{
"answer_id": 30240125,
"author": "Rash",
"author_id": 1834562,
"author_profile": "https://Stackoverflow.com/users/1834562",
"pm_score": 2,
"selected": false,
"text": "Minute = 0-60\nHour = 0-23\nDay = 1-31\nMONTH = 1-12 where 1 = January.\nWEEKDAY = 1-7 where 1 = Sunday.\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321494",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/999/"
] |
321,526 | <p>I have a table view setup which currently, when being flickered up, has its sections flush up against right underneath the status bar, instead of flushing against the the navigation bar. I'm not sure if this is the proper behavior, but most applications have the Section Title flush properly below the navigation bar when it's slid into view.</p>
<p>What's the right way to correct this instead of downsizing the tableView arbitrarily?</p>
<p><strong>* EDIT *</strong></p>
<p>Related to a thread I created in <a href="https://stackoverflow.com/questions/321522/iphone-devel-broken-cell-with-an-odd-strikethrough">Broken cell with an odd strikethrough?</a>. This problem plus the 'cell strike-through' problem occurs when I set my Navigation Bar to a Translucent Black. When it's Black Opaque or Normal, such a problem does not exist. I'm not sure if that's a result of something else in my code or an issue with the SDK.</p>
| [
{
"answer_id": 5644504,
"author": "Sid",
"author_id": 294508,
"author_profile": "https://Stackoverflow.com/users/294508",
"pm_score": 1,
"selected": false,
"text": "self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;\n"
},
{
"answer_id": 11666167,
"author": "beggs",
"author_id": 121096,
"author_profile": "https://Stackoverflow.com/users/121096",
"pm_score": 0,
"selected": false,
"text": "UINavigationController *navigationController = [[UINavigationController alloc] init];\n[navigationController setModalPresentationStyle:UIModalPresentationFormSheet];\n[navigationController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];\n[navigationController.navigationBar setBarStyle:UIBarStyleBlack];\n[navigationController.navigationBar setTranslucent:TRUE];\n[navigationController setNavigationBarHidden:NO animated:NO];\n[self presentModalViewController:navigationController animated:YES];\n\nMyTableViewController *aTableViewController = [[[MyTableViewController alloc] initWithStyle:UITableViewStylePlain] autorelease];\naTableViewController.navigationItem.rightBarButtonItem = buttonItem;\n[navigationController pushViewController:aboutTableViewController animated:YES];\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321526",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40882/"
] |
321,549 | <p>What is the best way to convert a double to a long without casting?</p>
<p>For example:</p>
<pre><code>double d = 394.000;
long l = (new Double(d)).longValue();
System.out.println("double=" + d + ", long=" + l);
</code></pre>
| [
{
"answer_id": 321558,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 8,
"selected": false,
"text": "double d = 1234.56;\nlong x = (long) d; // x = 1234\n"
},
{
"answer_id": 321563,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 7,
"selected": false,
"text": "double d = 1234.56;\nlong x = Math.round(d); //1235\n"
},
{
"answer_id": 321564,
"author": "Michael Myers",
"author_id": 13531,
"author_profile": "https://Stackoverflow.com/users/13531",
"pm_score": 5,
"selected": false,
"text": "(new Double(d)).longValue()"
},
{
"answer_id": 11950386,
"author": "CyberPlayerOne",
"author_id": 1516331,
"author_profile": "https://Stackoverflow.com/users/1516331",
"pm_score": 4,
"selected": false,
"text": "long DoubleMath.roundToLong(double x, RoundingMode mode)\n"
},
{
"answer_id": 24130032,
"author": "leogps",
"author_id": 2946951,
"author_profile": "https://Stackoverflow.com/users/2946951",
"pm_score": 6,
"selected": false,
"text": "Double.valueOf(d).longValue()\n"
},
{
"answer_id": 30024672,
"author": "dutoitns",
"author_id": 2000673,
"author_profile": "https://Stackoverflow.com/users/2000673",
"pm_score": 3,
"selected": false,
"text": "public class NumberUtils {\n\n /**\n * Convert a {@link Double} to a {@link Long}.\n * Method is for {@link Double}s that are actually {@link Long}s and we just\n * want to get a handle on it as one.\n */\n public static long getDoubleAsLong(double specifiedNumber) {\n Assert.isTrue(NumberUtils.isWhole(specifiedNumber));\n Assert.isTrue(specifiedNumber <= Long.MAX_VALUE && specifiedNumber >= Long.MIN_VALUE);\n // we already know its whole and in the Long range\n return Double.valueOf(specifiedNumber).longValue();\n }\n\n public static boolean isWhole(double specifiedNumber) {\n // http://stackoverflow.com/questions/15963895/how-to-check-if-a-double-value-has-no-decimal-part\n return (specifiedNumber % 1 == 0);\n }\n}\n"
},
{
"answer_id": 52255270,
"author": "devll",
"author_id": 4078268,
"author_profile": "https://Stackoverflow.com/users/4078268",
"pm_score": 2,
"selected": false,
"text": "double d = 394.000;\nlong l = d * 1L;\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321549",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
321,561 | <p>my company started recently to use Git for source version control, and due to the incompetence of the coders - that's me and my boss :-P - we have a really nice spaghetti of files being overwritten here and there.<br>
Is there a way to mark certain files as 'untouchable' so if when updating a branch from another either do(es)n't overwrite the file(s) or doesn't do the update at all?<br>
Thanks in advance.</p>
| [
{
"answer_id": 321620,
"author": "Sixto Saez",
"author_id": 9711,
"author_profile": "https://Stackoverflow.com/users/9711",
"pm_score": 0,
"selected": false,
"text": "git rm <file>\n"
},
{
"answer_id": 321853,
"author": "Paul",
"author_id": 23356,
"author_profile": "https://Stackoverflow.com/users/23356",
"pm_score": 2,
"selected": false,
"text": "git reset HEAD~2"
},
{
"answer_id": 322048,
"author": "kristina",
"author_id": 4243,
"author_profile": "https://Stackoverflow.com/users/4243",
"pm_score": 2,
"selected": false,
"text": "*.log\n*~\nconf/*\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321561",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/38995/"
] |
321,566 | <p>I would like to return all rows from <code>TableA</code> table that does not exists in another table.</p>
<p>e.g. </p>
<pre><code>select bench_id from TableA where bench_id not in (select bench_id from TableB )
</code></pre>
<p>can you please help me write equivalent LINQ query. Here <code>TableA</code> is from Excel and <code>TableB</code> is from a Database </p>
<p>I am loading Excel sheet data into <code>DataTable</code>, <code>TableA</code>. <code>TableB</code> I am loading from Database. In short, <code>TableA</code> and <code>TableB</code> is type of <code>DataTable</code></p>
| [
{
"answer_id": 321574,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 2,
"selected": false,
"text": "var query = tableA.Where(entry => !tableBIdSet.Contains(entry.Id));\n"
},
{
"answer_id": 321578,
"author": "gfrizzle",
"author_id": 23935,
"author_profile": "https://Stackoverflow.com/users/23935",
"pm_score": 0,
"selected": false,
"text": "From a in TableA\nGroup Join b in TableB on a.bench_id Equalsb.bench_id into g = Group\nWhere g.Count = 0\nSelect a\n"
},
{
"answer_id": 9442798,
"author": "Chintan Udeshi",
"author_id": 1232314,
"author_profile": "https://Stackoverflow.com/users/1232314",
"pm_score": 1,
"selected": false,
"text": "var lPenaltyEmployee = from row1 in tBal.getPenaltyEmployeeList().AsEnumerable()\n select row1;\n\nvar PenaltyEmp = new HashSet<string>(lPenaltyEmployee.Select(Entry => Entry.Emsrno);\n\nDataTable lAbsentEmp = (from row in tBal.getAbsentEmployee(txtFromDate.Text).AsEnumerable()\n where !(PenaltyEmp).Contains(row[\"Emsrno\"].ToString())\n select row).CopyToDataTable();\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321566",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
321,568 | <p>I have Firefox as my default browser on my dev machine and when I start debugging from visual studio Firefox launches as I would expect and all the attributes of the experience are the same as IE except for one thing - when I close the browser. When using IE, when I close the browser visual studio will automatically shut down the debugger. When I close FF I do not get this behavior - does anyone know how to make this happen?</p>
| [
{
"answer_id": 486044,
"author": "Sunny Milenov",
"author_id": 8220,
"author_profile": "https://Stackoverflow.com/users/8220",
"pm_score": 3,
"selected": false,
"text": "c:\\> <installation path of ff>\\firefox.exe -profilemanager\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321568",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40714/"
] |
321,571 | <p>This is probably a simple question, and I'm slightly embarrassed to ask it, but I've been working with this chunk of JavaScript ad code for a while and it's bothered me that it's never really made sense to me and is probably out dated now with modern browsers. My question is, do we need to check for browser types still, and what is that second bit of script doing?</p>
<pre><code><script type="text/javascript">
document.write('<scr' + 'ipt src="" type="text/javascript"></scr' + 'ipt>');
</script>
<script type="text/javascript">
if ((!document.images && navigator.userAgent.indexOf('Mozilla/2.') >= 0) || navigator.userAgent.indexOf("WebTV")>= 0) {
document.write('<a href="">');
document.write('<img src="" border="0" alt="" /></a>');
}
</script>
</code></pre>
<p>I'd like to clarify that I'm actually calling someone some ad code, so while I could check for browser types, that would really be the responsibility of the keeper of the code. I'd love it if I could get this into jQuery - but I'm having trouble with the call (see my other post below).</p>
<p>What I was wondering is, do I still need to check for these browser types?</p>
<p>Cheers,<br />
Steve</p>
| [
{
"answer_id": 321664,
"author": "Steve Perks",
"author_id": 16124,
"author_profile": "https://Stackoverflow.com/users/16124",
"pm_score": 0,
"selected": false,
"text": "$(this).append().html('<script src=\"http://ad.doubleclick.net/adj/' + site + '.iclick.com/adtarget;subss=' + subss + ';subs=' + subs + ';area=' + area + ';site=' + site + ';kw=' + kw + ';sz=' + $adSize + ';pos=' + count + ';tile=' + tilecount + ';ord=' + zzzzadslotzzzz + '\"></script>');\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321571",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16124/"
] |
321,572 | <p>I have Enitity Type, Name of Primary Key and Guid of Primary Id. I want to get element of such Id in LinqToSql.</p>
<pre><code>model.GetTable<T>().Where(t => here equality );
</code></pre>
<p>I think I need to generate that Expression myself, but I dont know how :(</p>
| [
{
"answer_id": 323699,
"author": "Igor Golodnitsky",
"author_id": 40789,
"author_profile": "https://Stackoverflow.com/users/40789",
"pm_score": 1,
"selected": true,
"text": " public static T GetById(Guid id)\n {\n Type entType = typeof(T);\n\n if (!CheckTable(entType)) {\n throw new TypeLoadException(string.Format(\n \"{0} is not Table Entity, has no attribute Table\", entType.FullName));\n }\n\n string property = GetPrimaryKeyName(entType).Name;\n\n ParameterExpression cs;\n var lambda = Expression.Lambda<Func<Personal, bool>>(\n Expression.Equal(\n Expression.Property(\n cs = Expression.Parameter(typeof(T), \"p\"), \n entType.GetProperty(property).GetGetMethod()\n ), \n Expression.Constant(id), \n false, \n typeof(Guid).GetMethod(\"Equals\")\n ), new ParameterExpression[] { cs }\n );\n\n return Connection.Model.GetTable<T>().Single(lambda);\n }\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321572",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40789/"
] |
321,582 | <p>I've recently written this with help from SO. Now could someone please tell me how to make it actually log onto the board. It brings up everything just in a non logged in format.</p>
<pre><code>import urllib2, re
import urllib, re
logindata = urllib.urlencode({'username': 'x', 'password': 'y'})
page = urllib2.urlopen("http://www.woarl.com/board/index.php", logindata)
pagesource = page.read()
print pagesource
</code></pre>
| [
{
"answer_id": 322892,
"author": "monkut",
"author_id": 24718,
"author_profile": "https://Stackoverflow.com/users/24718",
"pm_score": 0,
"selected": false,
"text": "# Create handlers\ncookieHandler = urllib2.HTTPCookieProcessor() # Needed for cookie handling\nredirectionHandler = urllib2.HTTPRedirectHandler() # needed for redirection (not needed for javascript redirect?)\n\n# Create opener\nopener = urllib2.build_opener(cookieHandler,redirectionHandler)\n\n# Install the opener\nurllib2.install_opener(opener)\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321582",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33061/"
] |
321,617 | <p>Anyone know of a free xls to text converter that can be run from the unix command line?</p>
| [
{
"answer_id": 321639,
"author": "Paul Fisher",
"author_id": 39808,
"author_profile": "https://Stackoverflow.com/users/39808",
"pm_score": 1,
"selected": false,
"text": "apt-cache"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321617",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1094969/"
] |
321,622 | <p>How does one read a data file in an iPhone project? For example, lets say I have a static file called "level.dat" that is structured as follows:
obstacles: 10
time: 100
obstacle1: 10,20
...</p>
<p>I would like to read the contents of the file into a NSString then do the parsing. How do I read the contents of a file into a string? Also, where in the project should the "level.dat" file reside? Should it be under "Resources" or just in the main directory?</p>
<p>Thanks in advance!</p>
| [
{
"answer_id": 321655,
"author": "Ben Gottlieb",
"author_id": 6694,
"author_profile": "https://Stackoverflow.com/users/6694",
"pm_score": 5,
"selected": true,
"text": "NSString *path = [[NSBundle mainBundle] pathForResource: @\"level\" ofType: @\"dat\"]\nNSError *error = nil;\nNSString *data = [NSString stringWithContentsOfFile: path \n encoding: NSUTF8StringEncoding \n error: &error];\n"
},
{
"answer_id": 323919,
"author": "Chris Jefferson",
"author_id": 27074,
"author_profile": "https://Stackoverflow.com/users/27074",
"pm_score": 2,
"selected": false,
"text": "dict = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@\"levels\" ofType:@\"plist\"]];\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321622",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21293/"
] |
321,650 | <p>Given:</p>
<pre><code>FieldInfo field = <some valid string field on type T>;
ParameterExpression targetExp = Expression.Parameter(typeof(T), "target");
ParameterExpression valueExp = Expression.Parameter(typeof(string), "value");
</code></pre>
<p>How do I compile a lambda expression to set the field on the "target" parameter to "value"?</p>
| [
{
"answer_id": 321686,
"author": "Barry Kelly",
"author_id": 3712,
"author_profile": "https://Stackoverflow.com/users/3712",
"pm_score": 7,
"selected": true,
"text": "Expression.Assign"
},
{
"answer_id": 322411,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 5,
"selected": false,
"text": "Delegate.CreateDelegate"
},
{
"answer_id": 1523147,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "private static Action<object, object> CreateSetAccessor(FieldInfo field)\n {\n DynamicMethod setMethod = new DynamicMethod(field.Name, typeof(void), new[] { typeof(object), typeof(object) });\n ILGenerator generator = setMethod.GetILGenerator();\n LocalBuilder local = generator.DeclareLocal(field.DeclaringType);\n generator.Emit(OpCodes.Ldarg_0);\n if (field.DeclaringType.IsValueType)\n {\n generator.Emit(OpCodes.Unbox_Any, field.DeclaringType);\n generator.Emit(OpCodes.Stloc_0, local);\n generator.Emit(OpCodes.Ldloca_S, local);\n }\n else\n {\n generator.Emit(OpCodes.Castclass, field.DeclaringType);\n generator.Emit(OpCodes.Stloc_0, local);\n generator.Emit(OpCodes.Ldloc_0, local);\n }\n generator.Emit(OpCodes.Ldarg_1);\n if (field.FieldType.IsValueType)\n {\n generator.Emit(OpCodes.Unbox_Any, field.FieldType);\n }\n else\n {\n generator.Emit(OpCodes.Castclass, field.FieldType);\n }\n generator.Emit(OpCodes.Stfld, field);\n generator.Emit(OpCodes.Ret);\n return (Action<object, object>)setMethod.CreateDelegate(typeof(Action<object, object>));\n }\n"
},
{
"answer_id": 4397046,
"author": "Emmanuel",
"author_id": 446066,
"author_profile": "https://Stackoverflow.com/users/446066",
"pm_score": 2,
"selected": false,
"text": "public class GetterSetter<EntityType,propType>\n{\n private readonly Func<EntityType, propType> getter;\n private readonly Action<EntityType, propType> setter;\n private readonly string propertyName;\n private readonly Expression<Func<EntityType, propType>> propertyNameExpression;\n\n public EntityType Entity { get; set; }\n\n public GetterSetter(EntityType entity, Expression<Func<EntityType, propType>> property_NameExpression)\n {\n Entity = entity;\n propertyName = GetPropertyName(property_NameExpression);\n propertyNameExpression = property_NameExpression;\n //Create Getter\n getter = propertyNameExpression.Compile();\n // Create Setter()\n MethodInfo method = typeof (EntityType).GetProperty(propertyName).GetSetMethod();\n setter = (Action<EntityType, propType>)\n Delegate.CreateDelegate(typeof(Action<EntityType, propType>), method);\n }\n\n\n public propType Value\n {\n get\n {\n return getter(Entity);\n }\n set\n {\n setter(Entity, value);\n }\n }\n\n protected string GetPropertyName(LambdaExpression _propertyNameExpression)\n {\n var lambda = _propertyNameExpression as LambdaExpression;\n MemberExpression memberExpression;\n if (lambda.Body is UnaryExpression)\n {\n var unaryExpression = lambda.Body as UnaryExpression;\n memberExpression = unaryExpression.Operand as MemberExpression;\n }\n else\n {\n memberExpression = lambda.Body as MemberExpression;\n }\n var propertyInfo = memberExpression.Member as PropertyInfo;\n return propertyInfo.Name;\n }\n"
},
{
"answer_id": 22234173,
"author": "elios264",
"author_id": 3051147,
"author_profile": "https://Stackoverflow.com/users/3051147",
"pm_score": 2,
"selected": false,
"text": " public static IEnumerable<Func<T, object>> GetTypeGetters<T>()\n {\n var fields = typeof (T).GetFields();\n\n foreach (var field in fields)\n {\n ParameterExpression targetExp = Expression.Parameter(typeof(T), \"target\");\n UnaryExpression boxedFieldExp = Expression.Convert(Expression.Field(targetExp, field), typeof(object));\n yield return Expression.Lambda<Func<T,object>>(boxedFieldExp, targetExp).Compile();\n }\n }\n"
},
{
"answer_id": 26712972,
"author": "dadhi",
"author_id": 2492669,
"author_profile": "https://Stackoverflow.com/users/2492669",
"pm_score": 2,
"selected": false,
"text": "Delegate.CreateDelegate"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321650",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18941/"
] |
321,656 | <p>In Qt, when a widget receives focus, how can get a notification about it, so I can execute some custom code? Is there a signal or an event for that?</p>
| [
{
"answer_id": 321677,
"author": "Martin Beckett",
"author_id": 10897,
"author_profile": "https://Stackoverflow.com/users/10897",
"pm_score": 4,
"selected": false,
"text": "void QApplication::focusChanged(QWidget * old, QWidget * now)\n"
},
{
"answer_id": 324453,
"author": "mxcl",
"author_id": 6444,
"author_profile": "https://Stackoverflow.com/users/6444",
"pm_score": 4,
"selected": false,
"text": "class LineEdit : public QLineEdit\n{\n virtual void focusInEvent( QFocusEvent* )\n {}\n};\n"
},
{
"answer_id": 326688,
"author": "Harald Scheirich",
"author_id": 22080,
"author_profile": "https://Stackoverflow.com/users/22080",
"pm_score": 2,
"selected": false,
"text": "focusInEvent"
},
{
"answer_id": 1990462,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 5,
"selected": false,
"text": "event filter"
},
{
"answer_id": 35600651,
"author": "Yash",
"author_id": 2708266,
"author_profile": "https://Stackoverflow.com/users/2708266",
"pm_score": 2,
"selected": false,
"text": "if(e->type() == QEvent::WindowActivate)\n{\n //qDebug() << \"Focus IN \" << obj << e ;\n\n}\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321656",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
321,687 | <p>I have a table with a timestamp field of type datetime. I need to aggregate the data between a defined start and end time into x groups representing time intervals of equal length, where x is supplied as function parameter.</p>
<p>What would be the best way to do this with Hibernate?</p>
<p>EDIT: some explanations</p>
<p>mysql Table:</p>
<pre><code>data_ts: datetime pk
value1 : int
value2 : bigint
...
</code></pre>
<p>Entity class:</p>
<pre><code>Calendar dataTs;
Integer value1;
BigDecimal value2;
...
</code></pre>
<p>I am looking for a HQL query that does something like</p>
<pre><code>select max(c.value1), avg(c.value2) from MyClass c
where c.dataTs between :start and :end group by <interval>
</code></pre>
<p>where the whole time period is grouped into x equally sized time intervals.</p>
<p>Example: </p>
<pre><code>Start : 2008-10-01 00:00:00
End : 2008-10-03 00:00:00 (2 days)
Groups: 32
</code></pre>
<p>would need to be grouped by a time interval of 1.5 hours (48 hours / 32):</p>
<pre><code>2008-10-01 00:00:00 - 2008-10-01 01:29:59
2008-10-01 01:30:00 - 2008-10-01 02:59:59
2008-10-01 02:00:00 - 2008-10-01 04:29:59
...
</code></pre>
| [
{
"answer_id": 322287,
"author": "reta",
"author_id": 9183,
"author_profile": "https://Stackoverflow.com/users/9183",
"pm_score": 4,
"selected": true,
"text": "int hours = 2; // 2-hours interval\n\nCriteria criteria = session.createCriteria( MyClass.class )\n .add( Restrictions.ge( \"dataTs\", start ) )\n .add( Restrictions.le( \"dataTs\", end ) );\n\n\nProjectionList projList = Projections.projectionList();\n projList.add( Projections.max( \"value1\" ) );\n projList.add( Projections.avg( \"value2\" ) );\n projList.add( Projections.sqlGroupProjection(\n String.format( \"DATE_ADD( DATE( %s_.dataTs ), INTERVAL( HOUR( %s_.dataTs ) - HOUR( %s_.dataTs) %% %d ) HOUR) as hourly\", criteria.getAlias(), criteria.getAlias(), criteria.getAlias(), hours ),\n String.format( \"DATE_ADD( DATE( %s_.dataTs ), INTERVAL( HOUR( %s_.dataTs) - HOUR( %s_.dataTs ) %% %d ) HOUR)\", criteria.getAlias(), criteria.getAlias(), criteria.getAlias(), hours ),\n new String[]{ \"hourly\" },\n new Type[]{ Hibernate.TIMESTAMP } )\n );\n criteria.setProjection( projList );\n\nList results = criteria\n .setCacheable( false )\n .list();\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321687",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33805/"
] |
321,701 | <p>I change the FontSize of Text in a Style trigger, this causes the Control containing the text to resize as well. How can I change the Fontsize without affecting the parent's size? </p>
| [
{
"answer_id": 321707,
"author": "Micah",
"author_id": 17744,
"author_profile": "https://Stackoverflow.com/users/17744",
"pm_score": 0,
"selected": false,
"text": "<DataTemplate x:Key=\"MyHeaderTemplate\">\n <TextBlock Text=\"{Binding}\" Fontsize=\"14\" FontWeight=\"Bold\" />\n</DataTemplate>\n"
},
{
"answer_id": 357574,
"author": "Robert Macnee",
"author_id": 19273,
"author_profile": "https://Stackoverflow.com/users/19273",
"pm_score": 2,
"selected": false,
"text": "<StackPanel>\n <Button Content=\"ABC\">\n <Button.Style>\n <Style TargetType=\"{x:Type Button}\">\n <Setter Property=\"FontSize\" Value=\"20\"/>\n <Style.Triggers>\n <Trigger Property=\"IsPressed\" Value=\"True\">\n <Setter Property=\"FontSize\" Value=\"12\"/>\n <Setter Property=\"Padding\" Value=\"5\"/>\n </Trigger>\n </Style.Triggers>\n </Style>\n </Button.Style>\n </Button>\n <Button Margin=\"0,20\" Content=\"123\" FontSize=\"20\"/>\n <Button Content=\"Do Re Mi\" FontSize=\"20\"/>\n</StackPanel>\n"
},
{
"answer_id": 612264,
"author": "Ifeanyi Echeruo",
"author_id": 47702,
"author_profile": "https://Stackoverflow.com/users/47702",
"pm_score": 3,
"selected": false,
"text": "<Parent>\n <Grid>\n <Element Visibility=\"Hidden\"/>\n <Canvas>\n <Element />\n </Canvas>\n <Grid>\n</Parent>\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321701",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26092/"
] |
321,714 | <p>I am dynamically creating a table which I want to have clickable rows. When the user clicks on one of the rows I want to redirect to a page specific to the item of that row. My question is how on the server side can I wire the "onclick" event to a routine that will then allow me to build a url based on some of the data included in the row they clicked?</p>
<p>for example I would want to do this on click:</p>
<p><code>Response.Redirect("SomePage.aspx?" itemType + "&" + COLUMN1VALUE)</code>;</p>
<p>where COLUMN1VALUE would be the first column in the row that was clicked.</p>
| [
{
"answer_id": 321814,
"author": "HectorMac",
"author_id": 1400,
"author_profile": "https://Stackoverflow.com/users/1400",
"pm_score": 3,
"selected": true,
"text": "<tr onclick=\"window.location='DetailPage.aspx?id=<%= IdFromDb %>'\">\n <!-- etc......-->\n</tr>\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321714",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20748/"
] |
321,719 | <p>Say I'm extending a TextBox called CustomTextBox in .net. In certain situations I would like to force a tab to the next TabIndex on the form. Is there a way to do this beyond getting all the controls contained in CustomTextBox's parent, sorting them by their TabIndex, and then focusing the next ordinal one?</p>
| [
{
"answer_id": 321751,
"author": "Zachary Yates",
"author_id": 8360,
"author_profile": "https://Stackoverflow.com/users/8360",
"pm_score": 5,
"selected": true,
"text": "form1.SelectNextControl(textBox1, true, true, true, true);\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321719",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24571/"
] |
321,736 | <p>I have an application that I want to export high-resolution (or rather, high pixel density?) images for printing - for example, I want images that print at 250 dots per inch (DPI), instead of the default, which I understand to be 72 DPI.</p>
<p>I'm using a BufferedImage with a Graphics2D object to draw the image, then ImageIO.write() to save the image.</p>
<p>Any idea how I can set the DPI?</p>
| [
{
"answer_id": 4833697,
"author": "Peter Kofler",
"author_id": 104143,
"author_profile": "https://Stackoverflow.com/users/104143",
"pm_score": 6,
"selected": true,
"text": " private BufferedImage gridImage;\n ...\n\n private void saveGridImage(File output) throws IOException {\n output.delete();\n\n final String formatName = \"png\";\n\n for (Iterator<ImageWriter> iw = ImageIO.getImageWritersByFormatName(formatName); iw.hasNext();) {\n ImageWriter writer = iw.next();\n ImageWriteParam writeParam = writer.getDefaultWriteParam();\n ImageTypeSpecifier typeSpecifier = ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB);\n IIOMetadata metadata = writer.getDefaultImageMetadata(typeSpecifier, writeParam);\n if (metadata.isReadOnly() || !metadata.isStandardMetadataFormatSupported()) {\n continue;\n }\n\n setDPI(metadata);\n\n final ImageOutputStream stream = ImageIO.createImageOutputStream(output);\n try {\n writer.setOutput(stream);\n writer.write(metadata, new IIOImage(gridImage, null, metadata), writeParam);\n } finally {\n stream.close();\n }\n break;\n }\n }\n\n private void setDPI(IIOMetadata metadata) throws IIOInvalidTreeException {\n\n // for PMG, it's dots per millimeter\n double dotsPerMilli = 1.0 * DPI / 10 / INCH_2_CM;\n\n IIOMetadataNode horiz = new IIOMetadataNode(\"HorizontalPixelSize\");\n horiz.setAttribute(\"value\", Double.toString(dotsPerMilli));\n\n IIOMetadataNode vert = new IIOMetadataNode(\"VerticalPixelSize\");\n vert.setAttribute(\"value\", Double.toString(dotsPerMilli));\n\n IIOMetadataNode dim = new IIOMetadataNode(\"Dimension\");\n dim.appendChild(horiz);\n dim.appendChild(vert);\n\n IIOMetadataNode root = new IIOMetadataNode(\"javax_imageio_1.0\");\n root.appendChild(dim);\n\n metadata.mergeTree(\"javax_imageio_1.0\", root);\n }\n"
},
{
"answer_id": 35868285,
"author": "rj27",
"author_id": 5808579,
"author_profile": "https://Stackoverflow.com/users/5808579",
"pm_score": 2,
"selected": false,
"text": "import java.awt.image.BufferedImage;\nimport java.awt.image.RenderedImage;\nimport java.io.File;\nimport java.io.FileOutputStream;\nimport java.io.IOException;\nimport java.io.OutputStream;\nimport java.util.ArrayList;\nimport java.util.List;\nimport javax.imageio.ImageIO;\nimport javax.media.jai.NullOpImage;\nimport javax.media.jai.OpImage;\nimport javax.media.jai.PlanarImage;\nimport com.sun.media.jai.codec.FileSeekableStream;\nimport com.sun.media.jai.codec.ImageCodec;\nimport com.sun.media.jai.codec.ImageDecoder;\nimport com.sun.media.jai.codec.ImageEncoder;\nimport com.sun.media.jai.codec.SeekableStream;\nimport com.sun.media.jai.codec.TIFFEncodeParam;\nimport com.sun.media.jai.codec.TIFFField;\nclass SetDDPI\n {\nstatic void tiff_Maker(List<BufferedImage> output, String result) throws IOException\n{\n TIFFEncodeParam params = new TIFFEncodeParam();\n OutputStream out = new FileOutputStream(result);\n List<BufferedImage> imageList = new ArrayList<BufferedImage>();\n for (int i = 1; i < output.size(); i++)\n {\n imageList.add(output.get(i));\n }\n params.setWriteTiled(true);\n params.setCompression(TIFFEncodeParam.COMPRESSION_GROUP4);\n params.setExtraImages(imageList.iterator());\n TIFFField[] extras = new TIFFField[2];\n extras[0] = new TIFFField(282, TIFFField.TIFF_RATIONAL, 1, (Object) new long[][] { { (long) 300, (long) 1 },\n { (long) 0, (long) 0 } });\n extras[1] = new TIFFField(283, TIFFField.TIFF_RATIONAL, 1, (Object) new long[][] { { (long) 300, (long) 1 },\n { (long) 0, (long) 0 } });\n params.setExtraFields(extras);\n ImageEncoder encoder = ImageCodec.createImageEncoder(\"tiff\", out, params);\n encoder.encode(output.get(0));\n out.close();\n}\nstatic List<BufferedImage> tiff_Extractor(File tiff) throws IOException\n{\n List<BufferedImage> images = new ArrayList<BufferedImage>();\n SeekableStream ss = new FileSeekableStream(tiff);\n ImageDecoder decoder = ImageCodec.createImageDecoder(\"tiff\", ss, null);\n int numPages = decoder.getNumPages();\n for (int j = 0; j < numPages; j++)\n {\n PlanarImage op = new NullOpImage(decoder.decodeAsRenderedImage(j), null, null, OpImage.OP_IO_BOUND);\n images.add(op.getAsBufferedImage());\n\n }\n return images;\n}\n}\n"
},
{
"answer_id": 43043998,
"author": "Sergei Bubenshchikov",
"author_id": 3926506,
"author_profile": "https://Stackoverflow.com/users/3926506",
"pm_score": 2,
"selected": false,
"text": "private static IIOMetadata createMetadata(ImageWriter writer, ImageWriteParam writerParams, int resolution) throws\n IIOInvalidTreeException\n{\n // Get default metadata from writer\n ImageTypeSpecifier type = ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_BYTE_GRAY);\n IIOMetadata meta = writer.getDefaultImageMetadata(type, writerParams);\n\n // Convert default metadata to TIFF metadata\n TIFFDirectory dir = TIFFDirectory.createFromMetadata(meta);\n\n // Get {X,Y} resolution tags\n BaselineTIFFTagSet base = BaselineTIFFTagSet.getInstance();\n TIFFTag tagXRes = base.getTag(BaselineTIFFTagSet.TAG_X_RESOLUTION);\n TIFFTag tagYRes = base.getTag(BaselineTIFFTagSet.TAG_Y_RESOLUTION);\n\n // Create {X,Y} resolution fields\n TIFFField fieldXRes = new TIFFField(tagXRes, TIFFTag.TIFF_RATIONAL, 1, new long[][] { { resolution, 1 } });\n TIFFField fieldYRes = new TIFFField(tagYRes, TIFFTag.TIFF_RATIONAL, 1, new long[][] { { resolution, 1 } });\n\n // Add {X,Y} resolution fields to TIFFDirectory\n dir.addTIFFField(fieldXRes);\n dir.addTIFFField(fieldYRes);\n\n // Add unit field to TIFFDirectory (change to RESOLUTION_UNIT_CENTIMETER if necessary)\n dir.addTIFFField(new TIFFField(base.getTag(BaselineTIFFTagSet.TAG_RESOLUTION_UNIT), BaselineTIFFTagSet.RESOLUTION_UNIT_INCH));\n\n // Return TIFF metadata so it can be picked up by the IIOImage\n return dir.getAsMetadata();\n}\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321736",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2197/"
] |
321,757 | <p>Are the threadlocals variables global to all the requests made to the servlet that owns the variables?</p>
<p>I am using resin for the server.</p>
<p>Thanks for awnser.</p>
<p>I think I can make my self more clear.</p>
<p><strong>The specific Case:</strong> </p>
<p>I want to:</p>
<ul>
<li>initialize a static variable when the request starts the execution.</li>
<li>be able to query the value of the variable in the further executions of methods called from the servlet in a thread safety way until the request ends the execution</li>
</ul>
| [
{
"answer_id": 321762,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 2,
"selected": false,
"text": "ServletContext"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321757",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1356709/"
] |
321,779 | <p>I've seen a number of examples that have a thread procedure that looks like this.</p>
<pre><code> private void ThreadProc()
{
while (serviceStarted)
{
// do some work
Thread.Sleep(new TimeSpan(0, 0, 5));
}
Thread.CurrentThread.Abort();
}
</code></pre>
<p>Is the <code>Abort()</code> really necessary at the end?</p>
<p>There are number of arguments against calling <code>Abort()</code></p>
<ol>
<li>Once the procedure exited - it is expected it has already cleaned up after itself.</li>
<li>Calling <code>Abort()</code> throws an exception, which is generally more resource intensive than just exiting a procedure.</li>
</ol>
<p>I'd like to read an explanation for why this is or isn't a good practice.</p>
| [
{
"answer_id": 321823,
"author": "Zachary Yates",
"author_id": 8360,
"author_profile": "https://Stackoverflow.com/users/8360",
"pm_score": 4,
"selected": true,
"text": "Thread.Abort()"
},
{
"answer_id": 321835,
"author": "Brian Rasmussen",
"author_id": 38206,
"author_profile": "https://Stackoverflow.com/users/38206",
"pm_score": 1,
"selected": false,
"text": "Abort()"
},
{
"answer_id": 322375,
"author": "Juliet",
"author_id": 40516,
"author_profile": "https://Stackoverflow.com/users/40516",
"pm_score": 2,
"selected": false,
"text": "CurrentThread.Abort"
},
{
"answer_id": 18054840,
"author": "Paul Turner",
"author_id": 138578,
"author_profile": "https://Stackoverflow.com/users/138578",
"pm_score": 0,
"selected": false,
"text": "Thread.Abort()"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321779",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31339/"
] |
321,786 | <p>Is there any way to make sure that a table and cells it contains have a border only when the cells are not empty?
If all the cells of the table are empty, then no border should be visible.</p>
| [
{
"answer_id": 321824,
"author": "Benson",
"author_id": 13816,
"author_profile": "https://Stackoverflow.com/users/13816",
"pm_score": 0,
"selected": false,
"text": "$(\"table.someClass td\").change(function() { updateBorder(this) })\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321786",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21586/"
] |
321,787 | <p>I'm trying to encrypt some integers in java using java.security and javax.crypto. </p>
<p>The problem seems to be that the Cipher class only encrypts byte arrays. I can't directly convert an integer to a byte string (or can I?). What is the best way to do this?</p>
<p>Should I convert the integer to a string and the string to byte[]? This seems too inefficient.</p>
<p>Does anyone know a quick/easy or efficient way to do it?</p>
<p>Please let me know.</p>
<p>Thanks in advance.</p>
<p>jbu</p>
| [
{
"answer_id": 321803,
"author": "jodonnell",
"author_id": 4223,
"author_profile": "https://Stackoverflow.com/users/4223",
"pm_score": 4,
"selected": false,
"text": "ByteArrayOutputStream baos = new ByteArrayOutputStream ();\nDataOutputStream dos = new DataOutputStream (baos);\ndos.writeInt (i);\nbyte[] data = baos.toByteArray();\n// do encryption\n"
},
{
"answer_id": 321810,
"author": "Paulo Guedes",
"author_id": 33857,
"author_profile": "https://Stackoverflow.com/users/33857",
"pm_score": 2,
"selected": false,
"text": "public static byte[] intToFourBytes(int i, boolean bigEndian) { \n if (bigEndian) { \n byte[] data = new byte[4]; \n data[3] = (byte) (i & 0xFF); \n data[2] = (byte) ((i >> 8) & 0xFF); \n data[1] = (byte) ((i >> 16) & 0xFF); \n data[0] = (byte) ((i >> 24) & 0xFF); \n return data; \n\n } else { \n byte[] data = new byte[4]; \n data[0] = (byte) (i & 0xFF); \n data[1] = (byte) ((i >> 8) & 0xFF); \n data[2] = (byte) ((i >> 16) & 0xFF); \n data[3] = (byte) ((i >> 24) & 0xFF); \n return data; \n } \n} \n"
},
{
"answer_id": 321825,
"author": "asalamon74",
"author_id": 21348,
"author_profile": "https://Stackoverflow.com/users/21348",
"pm_score": 3,
"selected": false,
"text": " BigInteger.valueOf(integer).toByteArray();\n"
},
{
"answer_id": 322195,
"author": "James Schek",
"author_id": 17871,
"author_profile": "https://Stackoverflow.com/users/17871",
"pm_score": 3,
"selected": false,
"text": "ByteBuffer bbuffer = ByteBuffer.allocate(4*theIntArray.length);\nIntBuffer ibuffer = bbuffer.asIntBuffer(); //wrapper--doesn't allocate more memory\nibuffer.put(theIntArray); //add your int's here; can use \n //array if you want\nbyte[] rawBytes = bbuffer.array(); //returns array backed by bbuffer--\n //i.e. *doesn't* allocate more memory\n"
},
{
"answer_id": 31006610,
"author": "Jon Downs",
"author_id": 5040957,
"author_profile": "https://Stackoverflow.com/users/5040957",
"pm_score": 0,
"selected": false,
"text": " Integer.toString(int).getBytes();\n"
},
{
"answer_id": 51124731,
"author": "susan097",
"author_id": 7338066,
"author_profile": "https://Stackoverflow.com/users/7338066",
"pm_score": 0,
"selected": false,
"text": "public String encodeDiscussionId(int Id) {\n\n String tempEn = Id + \"\";\n String encryptNum =\"\";\n for(int i=0;i<tempEn.length();i++) {\n int a = (int)tempEn.charAt(i);\n a+=148113;\n encryptNum +=(char)a;\n }\n return encryptNum;\n}\n\npublic Integer decodeDiscussionId(String encryptText) {\n\n String decodeText = \"\";\n for(int i=0;i<encryptText.length();i++) {\n int a= (int)encryptText.charAt(i);\n a -= 148113;\n decodeText +=(char)a;\n }\n int decodeId = Integer.parseInt(decodeText);\n return decodeId;\n}\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321787",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/38663/"
] |
321,793 | <p>How do I convert a date string, formatted as <code>"MM-DD-YY HH:MM:SS"</code>, to a <code>time_t</code> value in either C or C++? </p>
| [
{
"answer_id": 321811,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 2,
"selected": false,
"text": "strptime"
},
{
"answer_id": 321812,
"author": "Robert Gamble",
"author_id": 25222,
"author_profile": "https://Stackoverflow.com/users/25222",
"pm_score": 5,
"selected": true,
"text": "strptime()"
},
{
"answer_id": 321847,
"author": "Rob",
"author_id": 9236,
"author_profile": "https://Stackoverflow.com/users/9236",
"pm_score": 2,
"selected": false,
"text": "strptime"
},
{
"answer_id": 15877361,
"author": "hmehdi",
"author_id": 1233573,
"author_profile": "https://Stackoverflow.com/users/1233573",
"pm_score": -1,
"selected": false,
"text": " static time_t MKTimestamp(int year, int month, int day, int hour, int min, int sec)\n{\n time_t rawtime;\n struct tm * timeinfo;\n\n time ( &rawtime );\n timeinfo = gmtime ( &rawtime );\n timeinfo->tm_year = year-1900 ;\n timeinfo->tm_mon = month-1;\n timeinfo->tm_mday = day;\n timeinfo->tm_hour = hour;\n timeinfo->tm_min = min;\n timeinfo->tm_sec = sec;\n timeinfo->tm_isdst = 0; // disable daylight saving time\n\n time_t ret = mktime ( timeinfo );\n\n return ret;\n}\n\n static time_t GetDateTime(const std::string pstr)\n{\n try \n {\n // yyyy-mm-dd\n int m, d, y, h, min;\n std::istringstream istr (pstr);\n\n istr >> y;\n istr.ignore();\n istr >> m;\n istr.ignore();\n istr >> d;\n istr.ignore();\n istr >> h;\n istr.ignore();\n istr >> min;\n time_t t;\n\n t=MKTimestamp(y,m,d,h-1,min,0);\n return t;\n }\n catch(...)\n {\n\n }\n}\n"
},
{
"answer_id": 48511977,
"author": "Shital Shah",
"author_id": 207661,
"author_profile": "https://Stackoverflow.com/users/207661",
"pm_score": 2,
"selected": false,
"text": "strptime"
},
{
"answer_id": 48512134,
"author": "chux - Reinstate Monica",
"author_id": 2410359,
"author_profile": "https://Stackoverflow.com/users/2410359",
"pm_score": 1,
"selected": false,
"text": "strftime()"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321793",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17035/"
] |
321,795 | <p>I have an object that can build itself from an XML string, and write itself out to an XML string. I'd like to write a unit test to test round tripping through XML, but I'm having trouble comparing the two XML versions. Whitespace and attribute order seem to be the issues. Any suggestions for how to do this? This is in Python, and I'm using ElementTree (not that that really matters here since I'm just dealing with XML in strings at this level).</p>
| [
{
"answer_id": 321893,
"author": "Kozyarchuk",
"author_id": 52490,
"author_profile": "https://Stackoverflow.com/users/52490",
"pm_score": 5,
"selected": true,
"text": "obj1 = objectify.fromstring(expect)\nexpect = etree.tostring(obj1)\nobj2 = objectify.fromstring(xml)\nresult = etree.tostring(obj2)\nself.assertEquals(expect, result)\n"
},
{
"answer_id": 321941,
"author": "bobince",
"author_id": 18936,
"author_profile": "https://Stackoverflow.com/users/18936",
"pm_score": 3,
"selected": false,
"text": "def isEqualXML(a, b):\n da, db= minidom.parseString(a), minidom.parseString(b)\n return isEqualElement(da.documentElement, db.documentElement)\n\ndef isEqualElement(a, b):\n if a.tagName!=b.tagName:\n return False\n if sorted(a.attributes.items())!=sorted(b.attributes.items()):\n return False\n if len(a.childNodes)!=len(b.childNodes):\n return False\n for ac, bc in zip(a.childNodes, b.childNodes):\n if ac.nodeType!=bc.nodeType:\n return False\n if ac.nodeType==ac.TEXT_NODE and ac.data!=bc.data:\n return False\n if ac.nodeType==ac.ELEMENT_NODE and not isEqualElement(ac, bc):\n return False\n return True\n"
},
{
"answer_id": 322600,
"author": "Rob Williams",
"author_id": 26682,
"author_profile": "https://Stackoverflow.com/users/26682",
"pm_score": 0,
"selected": false,
"text": "dbUnit"
},
{
"answer_id": 7060342,
"author": "Mikhail Korobov",
"author_id": 114795,
"author_profile": "https://Stackoverflow.com/users/114795",
"pm_score": 4,
"selected": false,
"text": "from doctest import Example\nfrom lxml.doctestcompare import LXMLOutputChecker\n\nclass XmlTest(TestCase):\n def assertXmlEqual(self, got, want):\n checker = LXMLOutputChecker()\n if not checker.check_output(want, got, 0):\n message = checker.output_difference(Example(\"\", want), got, 0)\n raise AssertionError(message)\n"
},
{
"answer_id": 8178899,
"author": "pfctdayelise",
"author_id": 54056,
"author_profile": "https://Stackoverflow.com/users/54056",
"pm_score": 1,
"selected": false,
"text": "doctestcompare"
},
{
"answer_id": 40754849,
"author": "moylop260",
"author_id": 3753497,
"author_profile": "https://Stackoverflow.com/users/3753497",
"pm_score": 0,
"selected": false,
"text": "def xml_to_json(self, xml):\n \"\"\"Receive 1 lxml etree object and return a json string\"\"\"\n def recursive_dict(element):\n return (element.tag.split('}')[1],\n dict(map(recursive_dict, element.getchildren()),\n **element.attrib))\n return json.dumps(dict([recursive_dict(xml)]),\n default=lambda x: str(x))\n\ndef assertEqualXML(self, xml_real, xml_expected):\n \"\"\"Receive 2 objectify objects and show a diff assert if exists.\"\"\"\n xml_expected_str = json.loads(self.xml_to_json(xml_expected))\n xml_real_str = json.loads(self.xml_to_json(xml_real))\n self.maxDiff = None\n self.assertEqual(xml_real_str, xml_expected_str)\n"
},
{
"answer_id": 52540212,
"author": "porton",
"author_id": 856090,
"author_profile": "https://Stackoverflow.com/users/856090",
"pm_score": 0,
"selected": false,
"text": "minidom"
},
{
"answer_id": 64369718,
"author": "kjaw",
"author_id": 14455249,
"author_profile": "https://Stackoverflow.com/users/14455249",
"pm_score": 0,
"selected": false,
"text": "from lxml.doctestcompare import LXMLOutputChecker, PARSE_XML\n\nclass XmlTest(TestCase):\ndef assertXmlEqual(self, got, want):\n checker = LXMLOutputChecker()\n if not checker.check_output(want.encode(), got.encode(), PARSE_XML):\n message = checker.output_difference(Example(b\"\", want.encode()), got.encode(), PARSE_XML)\n raise AssertionError(message)\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321795",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8240/"
] |
321,801 | <p>I was wondering in C++ if I have an enum can I access the value at the second index? For example I have</p>
<pre><code>enum Test{hi, bye};
</code></pre>
<p>if I want 'hi', can I do something like Test[0], thanks.</p>
| [
{
"answer_id": 321816,
"author": "strager",
"author_id": 39992,
"author_profile": "https://Stackoverflow.com/users/39992",
"pm_score": 2,
"selected": false,
"text": "int myInteger = 0;\nTest myValue = (Test)myInteger;\n"
},
{
"answer_id": 321818,
"author": "Rob Prouse",
"author_id": 30827,
"author_profile": "https://Stackoverflow.com/users/30827",
"pm_score": 2,
"selected": false,
"text": "Test test = (Test)0;\n"
},
{
"answer_id": 321820,
"author": "An̲̳̳drew",
"author_id": 17035,
"author_profile": "https://Stackoverflow.com/users/17035",
"pm_score": 0,
"selected": false,
"text": "enum Test{hi = 0, bye};\n"
},
{
"answer_id": 321821,
"author": "JaredPar",
"author_id": 23283,
"author_profile": "https://Stackoverflow.com/users/23283",
"pm_score": 5,
"selected": false,
"text": "enum Test {\n hi, // 0\n bye // 1\n}\n"
},
{
"answer_id": 321828,
"author": "xan",
"author_id": 15667,
"author_profile": "https://Stackoverflow.com/users/15667",
"pm_score": 4,
"selected": false,
"text": "enum Test\n{\n hi, //0\n bye, //1\n count //2\n}\n"
},
{
"answer_id": 42004015,
"author": "Chavan Maharshi",
"author_id": 7377411,
"author_profile": "https://Stackoverflow.com/users/7377411",
"pm_score": 0,
"selected": false,
"text": "string return_value(int index)\n{\nstring temp = \"\";\nswitch (index)\n{\ncase 1: temp = \"hi\"\nbreak;\ncase 2: temp = \"bye\";\nbreak;\ndefualt :\nbreak;\n}\nreturn temp;\n}\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321801",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
321,808 | <p>I'm looking to start a <a href="http://en.wikipedia.org/wiki/MUD" rel="nofollow noreferrer">MUD client</a> application, which connects to a MUD hosted on a telnet server. The only thing important to me is that it runs painlessly and efficiently across any OS. Aside from that requirement, I'm not really sold on any language.</p>
<p>So I'm looking for a freely available telnet client library on which I can base my application, so I don't have to deal with the details of the protocol too much.</p>
| [
{
"answer_id": 322209,
"author": "orip",
"author_id": 37020,
"author_profile": "https://Stackoverflow.com/users/37020",
"pm_score": 2,
"selected": false,
"text": "twisted.conch.telnet"
},
{
"answer_id": 9352878,
"author": "Jack Kelly",
"author_id": 429232,
"author_profile": "https://Stackoverflow.com/users/429232",
"pm_score": 0,
"selected": false,
"text": "IAC"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321808",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40866/"
] |
321,822 | <p>Consider the following Haskell code:</p>
<pre><code>module Expr where
-- Variables are named by strings, assumed to be identifiers:
type Variable = String
-- Representation of expressions:
data Expr = Const Integer
| Var Variable
| Plus Expr Expr
| Minus Expr Expr
| Mult Expr Expr
deriving (Eq, Show)
simplify :: Expr->Expr
simplify (Mult (Const 0)(Var"x"))
= Const 0
simplify (Mult (Var "x") (Const 0))
= Const 0
simplify (Plus (Const 0) (Var "x"))
= Var "x"
simplify (Plus (Var "x") (Const 0))
= Var "x"
simplify (Mult (Const 1) (Var"x"))
= Var "x"
simplify (Mult(Var"x") (Const 1))
= Var "x"
simplify (Minus (Var"x") (Const 0))
= Var "x"
simplify (Plus (Const x) (Const y))
= Const (x + y)
simplify (Minus (Const x) (Const y))
= Const (x - y)
simplify (Mult (Const x) (Const y))
= Const (x * y)
simplify x = x
toString :: Expr->String
</code></pre>
<p>How can I convert an expression to a string representation?</p>
<p>e.g.</p>
<pre><code>toString (Var "x") = "x"
toString (Plus (Var "x") (Const 1)) = "x + 1"
toString (Mult (Plus (Var "x") (Const 1)) (Var "y"))
= "(x + 1) * y"
</code></pre>
| [
{
"answer_id": 322025,
"author": "Dave",
"author_id": 40495,
"author_profile": "https://Stackoverflow.com/users/40495",
"pm_score": 1,
"selected": false,
"text": "toString (Plus e1 e2) = (toString e1) ++ \" + \" ++ (toString e2)\ntoString (Const i) = show i\n"
},
{
"answer_id": 322398,
"author": "Dan Dyer",
"author_id": 5171,
"author_profile": "https://Stackoverflow.com/users/5171",
"pm_score": 2,
"selected": false,
"text": "instance Show Expr where\n show (Var \"x\") = \"x\"\n -- etc.\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321822",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41000/"
] |
321,827 | <p>I am trying to determine what issues could be caused by using the following serialization surrogate to enable serialization of anonymous functions/delegate/lambdas. </p>
<pre><code>// see http://msdn.microsoft.com/msdnmag/issues/02/09/net/#S3
class NonSerializableSurrogate : ISerializationSurrogate
{
public void GetObjectData(object obj, SerializationInfo info, StreamingContext context)
{
foreach (FieldInfo f in obj.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
info.AddValue(f.Name, f.GetValue(obj));
}
public object SetObjectData(object obj, SerializationInfo info, StreamingContext context,
ISurrogateSelector selector)
{
foreach (FieldInfo f in obj.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
f.SetValue(obj, info.GetValue(f.Name, f.FieldType));
return obj;
}
}
</code></pre>
<p><strong>Listing 1</strong> <em>adapted from</em> <a href="http://www.agilekiwi.com/dotnet/CountingDemo.cs" rel="noreferrer">Counting Demo</a></p>
<p>The main issue I can think of that might be a problem is that the anonymous class is an internal compiler detail and it's structure is not guaranteed to remain constant between revisions to the .NET Framework. I'm fairly certain this is the case based on my research into the similar problem with iterators.</p>
<h2>Background</h2>
<p>I am investigating the serialization of anonymous functions. I was expecting this not to work, but found it did for some cases. As long as the lambda did *not& force the compiler to generate an anonymous class everything works fine. </p>
<p>A SerializationException is thrown if the compiler requires a generated class to implement the anonymous function. This is because the compiler generated class is not marked as serializable.</p>
<h2>Example</h2>
<pre><code>namespace Example
{
[Serializable]
class Other
{
public int Value;
}
[Serializable]
class Program
{
static void Main(string[] args)
{
MemoryStream m = new MemoryStream();
BinaryFormatter f = new BinaryFormatter();
// Example 1
Func<int> succeeds = () => 5;
f.Serialize(m, succeeds);
// Example 2
Other o = new Other();
Func<int> fails = () => o.Value;
f.Serialize(m, fails); // throws SerializationException - Type 'Example.Program+<>c__DisplayClass3' in Assembly 'Example, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.
}
}
</code></pre>
<p><strong>Listing 2</strong></p>
<p>This is similar to the issue of trying to serialize <em>iterators</em> and I had found the following code in a previous search (see <a href="http://www.agilekiwi.com/dotnet/CountingDemo.cs" rel="noreferrer">countingdemo</a>) Using the code from <strong>Listing 1</strong> and an ISurrogateSelector I was able to successfully serialize and deserialize the second failing example.</p>
<h2>Objective</h2>
<p>I have a system that is exposed via a web service. The system has a complex but small state (many objects, not a lot of properties per object). The state is saved in the ASP.NET Cache, but is also serialized to a BLOB in SQL in case of cache expiration. Some objects need to execute arbitrary "events" upon reaching some condition. Hence they have properties accepting Action/Func objects. Contrived example:</p>
<pre><code> class Command
{
public Command(Action action, Func<bool> condition);
}
</code></pre>
<p>Somewhere else</p>
<pre><code> void DoSomethingWithThing(Thing thing)
{
state = Store.GetCurrentState();
Command cmd = new Command(() => thing.Foo(), () => thing.IsReady())
state.Add(cmd);
Store.Save(state);
}
</code></pre>
| [
{
"answer_id": 335346,
"author": "Amy B",
"author_id": 8155,
"author_profile": "https://Stackoverflow.com/users/8155",
"pm_score": 3,
"selected": false,
"text": "public class Command<T> where T : ISerializable\n{\n T _target;\n int _actionId;\n int _conditionId;\n\n public Command<T>(T Target, int ActionId, int ConditionId)\n {\n _target = Target;\n _actionId = ActionId;\n _conditionId = ConditionId;\n }\n\n public bool FireRule()\n {\n Func<T, bool> theCondition = conditionMap.LookupCondition<T>(_conditionId)\n Action<T> theAction = actionMap.LookupAction<T>(_actionId);\n\n if (theCondition(_target))\n {\n theAction(_target);\n return true;\n }\n return false;\n } \n}\n"
},
{
"answer_id": 335592,
"author": "Joseph Kingry",
"author_id": 3046,
"author_profile": "https://Stackoverflow.com/users/3046",
"pm_score": 0,
"selected": false,
"text": " Other o = FromSomeWhere();\n Thing t = OtherPlace();\n target.OnWhatever = () => t.DoFoo() + o.DoBar();\n target.Save();c\n"
},
{
"answer_id": 336154,
"author": "Amy B",
"author_id": 8155,
"author_profile": "https://Stackoverflow.com/users/8155",
"pm_score": 1,
"selected": false,
"text": "Other o = FromSomeWhere();\nThing t = OtherPlace();\ntarget.OnWhatever = () => t.DoFoo() + o.DoBar();\ntarget.Save();\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321827",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3046/"
] |
321,834 | <p>I have an RSS source:</p>
<pre><code>http://feedity.com/rss.aspx/mr1-kossuth-hu/VVdXUlY
</code></pre>
<pre><code><item>
<title>2008. november 23.</title>
<link>http://www.mr1-kossuth.hu/m3u/0039c36f_3003051.m3u</link>
<description>........</description>
<pubDate>Wed, 26 Nov 2008 00:00:00 GMT</pubDate>
</item>
</code></pre>
<p>From this, I want to create a podcast-friendly feed. I want to replace the LINK children to:</p>
<pre><code>http://stream001.radio.hu:8000/content/*.mp3
</code></pre>
<p>Example:</p>
<pre><code><item>
<title>2008. november 23.</title>
<link>http://stream001.radio.hu:8000/content/0039c36f_3003051.mp3</link>
<description>........</description>
<pubDate>Wed, 26 Nov 2008 00:00:00 GMT</pubDate>
</item>
</code></pre>
<p>How I can do that in PHP?</p>
| [
{
"answer_id": 321859,
"author": "Greg",
"author_id": 24181,
"author_profile": "https://Stackoverflow.com/users/24181",
"pm_score": 0,
"selected": false,
"text": "$str = file_get_contents('http://feedity.com/rss.aspx/mr1-kossuth-hu/VVdXUlY');\n$str = str_replace('<link>http://www.mr1-kossuth.hu/m3u/', '<link>http://stream001.radio.hu:8000/content/', $str);\n$str = str_replace('m3u</link>', 'mp3</link>', $str);\n"
},
{
"answer_id": 322132,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "<?php\n $str = file_get_contents('http://feedity.com/rss.aspx/mr1-kossuth-hu/VVdXUlY');\n $xml = simplexml_load_string($str);\nif ($xml) {\n\n$intro = str_replace('<link>http://www.mr1-kossuth.hu/m3u/', '<enclosure url=\"http://stream001.radio.hu:8000/content/', $xml->asXML());\n$intro = str_replace('m3u</link>', 'mp3\" type=\"audio/mpeg\" />', $intro);\necho $intro; \n} else {\n $error = \"Could not load intro XML file.\";\n}\n\n?>\n"
},
{
"answer_id": 322603,
"author": "Dimitre Novatchev",
"author_id": 36305,
"author_profile": "https://Stackoverflow.com/users/36305",
"pm_score": 2,
"selected": false,
"text": "<xsl:param>"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321834",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
321,849 | <p>Is there a good equivalent implementation of <code>strptime()</code> available for Windows? Unfortunately, this POSIX function does not appear to be available.</p>
<p><a href="http://www.opengroup.org/onlinepubs/009695399/functions/strptime.html" rel="noreferrer">Open Group description of strptime</a> - summary: it converts a text string such as <code>"MM-DD-YYYY HH:MM:SS"</code> into a <code>tm struct</code>, the opposite of <code>strftime()</code>.</p>
| [
{
"answer_id": 321877,
"author": "Adam Rosenfield",
"author_id": 9530,
"author_profile": "https://Stackoverflow.com/users/9530",
"pm_score": 5,
"selected": true,
"text": "strptime()"
},
{
"answer_id": 321940,
"author": "ravenspoint",
"author_id": 16582,
"author_profile": "https://Stackoverflow.com/users/16582",
"pm_score": 4,
"selected": false,
"text": "#include \"stdafx.h\"\n#include \"boost/date_time/posix_time/posix_time.hpp\"\nusing namespace boost::posix_time;\n\nint _tmain(int argc, _TCHAR* argv[])\n{\n std::string ts(\"2002-01-20 23:59:59.000\");\n ptime t(time_from_string(ts));\n tm pt_tm = to_tm( t );\n"
},
{
"answer_id": 3137634,
"author": "amwinter",
"author_id": 329867,
"author_profile": "https://Stackoverflow.com/users/329867",
"pm_score": 5,
"selected": false,
"text": "sscanf"
},
{
"answer_id": 28895434,
"author": "Pr0t0c0l78",
"author_id": 4627927,
"author_profile": "https://Stackoverflow.com/users/4627927",
"pm_score": -1,
"selected": false,
"text": "GetSystemTime"
},
{
"answer_id": 33542189,
"author": "Orvid King",
"author_id": 776797,
"author_profile": "https://Stackoverflow.com/users/776797",
"pm_score": 5,
"selected": false,
"text": "#include <time.h>\n#include <iomanip>\n#include <sstream>\n\nextern \"C\" char* strptime(const char* s,\n const char* f,\n struct tm* tm) {\n // Isn't the C++ standard lib nice? std::get_time is defined such that its\n // format parameters are the exact same as strptime. Of course, we have to\n // create a string stream first, and imbue it with the current C locale, and\n // we also have to make sure we return the right things if it fails, or\n // if it succeeds, but this is still far simpler an implementation than any\n // of the versions in any of the C standard libraries.\n std::istringstream input(s);\n input.imbue(std::locale(setlocale(LC_ALL, nullptr)));\n input >> std::get_time(tm, f);\n if (input.fail()) {\n return nullptr;\n }\n return (char*)(s + input.tellg());\n}\n"
},
{
"answer_id": 73142448,
"author": "Andrew Henle",
"author_id": 4756299,
"author_profile": "https://Stackoverflow.com/users/4756299",
"pm_score": 0,
"selected": false,
"text": "sscanf()"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321849",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17035/"
] |
321,860 | <p>I have a lot of XML files which have something of the form:</p>
<pre><code><Element fruit="apple" animal="cat" />
</code></pre>
<p>Which I want to be removed from the file.</p>
<p>Using an XSLT stylesheet and the Linux command-line utility xsltproc, how could I do this?</p>
<p>By this point in the script I already have the list of files containing the element I wish to remove, so the single file can be used as a parameter.</p>
<hr />
<p><strong>EDIT:</strong> the question was originally lacking in intention.</p>
<p>What I am trying to achieve is to remove the entire element "Element" where (fruit=="apple" && animal=="cat"). In the same document there are many elements named "Element", I wish for these to remain. So</p>
<pre><code><Element fruit="orange" animal="dog" />
<Element fruit="apple" animal="cat" />
<Element fruit="pear" animal="wild three eyed mongoose of kentucky" />
</code></pre>
<p>Would become:</p>
<pre><code><Element fruit="orange" animal="dog" />
<Element fruit="pear" animal="wild three eyed mongoose of kentucky" />
</code></pre>
| [
{
"answer_id": 55071521,
"author": "Sboisen",
"author_id": 11121413,
"author_profile": "https://Stackoverflow.com/users/11121413",
"pm_score": 2,
"selected": false,
"text": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"\n xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"\n version=\"2.0\">\n\n <xsl:template match=\"node()|@*\">\n <xsl:copy>\n <xsl:apply-templates select=\"node()|@*\"/>\n </xsl:copy>\n </xsl:template>\n\n <!-- drop DropMe elements, keeping child text and elements -->\n <xsl:template match=\"DropMe\">\n <xsl:apply-templates/>\n </xsl:template>\n\n</xsl:stylesheet>\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321860",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4120/"
] |
321,861 | <p>I have a ‘page a’ using ‘css a’. This page has margins set in css.
I also have a ‘page b’ using ‘css b’. This page also has margins set in css, of the same size as in ‘css a’ (10px).</p>
<p>Is there any way I can make it so that when I am viewing ‘page a’ on its own it has margins, but when viewed in an iframe on ‘page b’ the margins don’t apply to ‘page a’. I know that’s kind of a long way of asking but the basic problem is that I am getting ‘double margins’ for the content in the iframe: the margin from ‘page a’ and then the margin from ‘page b’!</p>
<p>I guess one way of doing it would be to set the iframe not to be affected by ‘page a’s’ margins. Is there some way I can set ‘css a’ to exclude the iframe from the margins, that way only the margins from css b would apply and the page would still be in alignment. is that possible?</p>
<p>Thanks for any help</p>
<p>Matt </p>
| [
{
"answer_id": 55071521,
"author": "Sboisen",
"author_id": 11121413,
"author_profile": "https://Stackoverflow.com/users/11121413",
"pm_score": 2,
"selected": false,
"text": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"\n xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"\n version=\"2.0\">\n\n <xsl:template match=\"node()|@*\">\n <xsl:copy>\n <xsl:apply-templates select=\"node()|@*\"/>\n </xsl:copy>\n </xsl:template>\n\n <!-- drop DropMe elements, keeping child text and elements -->\n <xsl:template match=\"DropMe\">\n <xsl:apply-templates/>\n </xsl:template>\n\n</xsl:stylesheet>\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321861",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
321,864 | <p>Yesterday I had a two-hour technical phone interview (which I passed, woohoo!), but I completely muffed up the following question regarding dynamic binding in Java. And it's doubly puzzling because I used to teach this concept to undergraduates when I was a TA a few years ago, so the prospect that I gave them misinformation is a little disturbing...</p>
<p>Here's the problem I was given:</p>
<pre><code>/* What is the output of the following program? */
public class Test {
public boolean equals( Test other ) {
System.out.println( "Inside of Test.equals" );
return false;
}
public static void main( String [] args ) {
Object t1 = new Test();
Object t2 = new Test();
Test t3 = new Test();
Object o1 = new Object();
int count = 0;
System.out.println( count++ );// prints 0
t1.equals( t2 ) ;
System.out.println( count++ );// prints 1
t1.equals( t3 );
System.out.println( count++ );// prints 2
t3.equals( o1 );
System.out.println( count++ );// prints 3
t3.equals(t3);
System.out.println( count++ );// prints 4
t3.equals(t2);
}
}
</code></pre>
<p>I asserted that the output should have been two separate print statements from within the overridden <code>equals()</code> method: at <code>t1.equals(t3)</code> and <code>t3.equals(t3)</code>. The latter case is obvious enough, and with the former case, even though <code>t1</code> has a reference of type Object, it is instantiated as type Test, so dynamic binding should call the overridden form of the method.</p>
<p>Apparently not. My interviewer encouraged me to run the program myself, and lo and behold, there was only a single output from the overridden method: at the line <code>t3.equals(t3)</code>.</p>
<p>My question then is, why? As I mentioned already, even though <code>t1</code> is a reference of type Object (so static binding would invoke Object's <code>equals()</code> method), dynamic binding <em>should</em> take care of invoking the most specific version of the method based on the instantiated type of the reference. What am I missing?</p>
| [
{
"answer_id": 321891,
"author": "erickson",
"author_id": 3474,
"author_profile": "https://Stackoverflow.com/users/3474",
"pm_score": 5,
"selected": false,
"text": "equals"
},
{
"answer_id": 4192807,
"author": "ankush gatfane",
"author_id": 509329,
"author_profile": "https://Stackoverflow.com/users/509329",
"pm_score": 0,
"selected": false,
"text": "Object()"
},
{
"answer_id": 19694278,
"author": "Prabu R",
"author_id": 1604538,
"author_profile": "https://Stackoverflow.com/users/1604538",
"pm_score": 2,
"selected": false,
"text": "public class DynamicBinding {\n public boolean equals(Test other) {\n System.out.println(\"Inside of Test.equals\");\n return false;\n }\n\n @Override\n public boolean equals(Object other) {\n System.out.println(\"Inside @override: this is dynamic binding\");\n return false;\n }\n\n public static void main(String[] args) {\n Object t1 = new Test();\n Object t2 = new Test();\n Test t3 = new Test();\n Object o1 = new Object();\n\n int count = 0;\n System.out.println(count++);// prints 0\n t1.equals(t2);\n System.out.println(count++);// prints 1\n t1.equals(t3);\n System.out.println(count++);// prints 2\n t3.equals(o1);\n System.out.println(count++);// prints 3\n t3.equals(t3);\n System.out.println(count++);// prints 4\n t3.equals(t2);\n }\n}\n"
},
{
"answer_id": 43181977,
"author": "Devendra Lattu",
"author_id": 2889297,
"author_profile": "https://Stackoverflow.com/users/2889297",
"pm_score": -1,
"selected": false,
"text": "public class Test {\n\n public boolean equals(Test other) {\n System.out.println(\"Inside of Test.equals\");\n return false;\n }\n\n @Override\n public boolean equals(Object other) {\n System.out.println(\"Inside of Test.equals ot type Object\");\n return false;\n }\n\n public static void main(String[] args) {\n Object t1 = new Test();\n Object t2 = new Test();\n Test t3 = new Test();\n Object o1 = new Object();\n\n int count = 0;\n System.out.println(count++); // prints 0\n o1.equals(t2);\n\n System.out.println(\"\\n\" + count++); // prints 1\n o1.equals(t3);\n\n System.out.println(\"\\n\" + count++);// prints 2\n t1.equals(t2);\n\n System.out.println(\"\\n\" + count++);// prints 3\n t1.equals(t3);\n\n System.out.println(\"\\n\" + count++);// prints 4\n t3.equals(o1);\n\n System.out.println(\"\\n\" + count++);// prints 5\n t3.equals(t3);\n\n System.out.println(\"\\n\" + count++);// prints 6\n t3.equals(t2);\n }\n}\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321864",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13604/"
] |
321,865 | <p>I know there are many ways to prevent image caching (such as via META tags), as well as a few nice tricks to ensure that the current version of an image is shown with every page load (such as image.jpg?x=timestamp), but is there any way to actually clear or replace an image in the browsers cache so that neither of the methods above are necessary?</p>
<p>As an example, lets say there are 100 images on a page and that these images are named "01.jpg", "02.jpg", "03.jpg", etc. If image "42.jpg" is replaced, is there any way to replace it in the cache so that "42.jpg" will automatically display the new image on successive page loads? I can't use the META tag method, because I need everuthing that ISN"T replaced to remain cached, and I can't use the timestamp method, because I don't want ALL of the images to be reloaded every time the page loads.</p>
<p>I've racked my brain and scoured the Internet for a way to do this (preferrably via javascript), but no luck. Any suggestions?</p>
| [
{
"answer_id": 321871,
"author": "Greg",
"author_id": 24181,
"author_profile": "https://Stackoverflow.com/users/24181",
"pm_score": 6,
"selected": false,
"text": "<img src=\"image.jpg?lastmod=12345678\" ..."
},
{
"answer_id": 321875,
"author": "Kornel",
"author_id": 27009,
"author_profile": "https://Stackoverflow.com/users/27009",
"pm_score": 4,
"selected": false,
"text": "<meta>"
},
{
"answer_id": 321990,
"author": "Orion Edwards",
"author_id": 234,
"author_profile": "https://Stackoverflow.com/users/234",
"pm_score": 0,
"selected": false,
"text": "Tools"
},
{
"answer_id": 1921672,
"author": "Pete",
"author_id": 233783,
"author_profile": "https://Stackoverflow.com/users/233783",
"pm_score": 0,
"selected": false,
"text": "window.location.reload()"
},
{
"answer_id": 13067981,
"author": "Raju Jetla",
"author_id": 1688578,
"author_profile": "https://Stackoverflow.com/users/1688578",
"pm_score": 3,
"selected": false,
"text": "\"image1.jpg?\" + DateTime.Now.ToString(\"ddMMyyyyhhmmsstt\");\n"
},
{
"answer_id": 22430452,
"author": "Doin",
"author_id": 999120,
"author_profile": "https://Stackoverflow.com/users/999120",
"pm_score": 4,
"selected": false,
"text": "<iframe>"
},
{
"answer_id": 33897738,
"author": "abhiagNitk",
"author_id": 5222065,
"author_profile": "https://Stackoverflow.com/users/5222065",
"pm_score": 3,
"selected": false,
"text": "<script>\nvar num = Math.random();\nvar imgSrc= \"image.png?v=\"+num;\n$(function() {\n$('#imgID').attr(\"src\", imgSrc);\n})\n</script>\n"
},
{
"answer_id": 39830734,
"author": "Akbar Badhusha",
"author_id": 6915387,
"author_profile": "https://Stackoverflow.com/users/6915387",
"pm_score": 0,
"selected": false,
"text": "var url = imgUrl? + Math.random();\n"
},
{
"answer_id": 41897991,
"author": "Wagner Bertolini Junior",
"author_id": 2055989,
"author_profile": "https://Stackoverflow.com/users/2055989",
"pm_score": -1,
"selected": false,
"text": "function addMagicRefresh(url)\n{\n var symbol = url.indexOf('?') == -1 ? '?' : '&';\n var magic = Math.random()*999999;\n return url + symbol + 'magic=' + magic;\n}\n"
},
{
"answer_id": 59078790,
"author": "Ben Matheson",
"author_id": 12432821,
"author_profile": "https://Stackoverflow.com/users/12432821",
"pm_score": 1,
"selected": false,
"text": " var headers = new Headers()\n headers.append('pragma', 'no-cache')\n headers.append('cache-control', 'no-cache')\n\n var init = {\n method: 'GET',\n headers: headers,\n mode: 'no-cors',\n cache: 'no-cache',\n }\n\n fetch(new Request('path/to.file'), init)\n"
},
{
"answer_id": 61248178,
"author": "ImYash",
"author_id": 12249611,
"author_profile": "https://Stackoverflow.com/users/12249611",
"pm_score": 1,
"selected": false,
"text": "<?php \n $addthis = filemtime('myimf.jpg');\n?> \n<img src=\"myimg.jpg?\"<?= $addthis;?> >\n"
},
{
"answer_id": 65474459,
"author": "Juan Carlos",
"author_id": 5895493,
"author_profile": "https://Stackoverflow.com/users/5895493",
"pm_score": 0,
"selected": false,
"text": "if (!is_dir(getcwd(). 'articulostemp')){\n $oldmask = umask(0);mkdir(getcwd(). 'articulostemp', 0775);umask($oldmask);\n}else{\n rrmfiles(getcwd(). 'articulostemp');\n} \nforeach ($images as $image) { \n $tmpname = time().'-'.$image;\n $srcimage = getcwd().'articulos/'.$image;\n $tmpimage = getcwd().'articulostemp/'.$tmpname;\n copy($srcimage,$tmpimage);\n $urlimage='articulostemp/'.$tmpname;\n echo ' <img loading=\"lazy\" src=\"'.$urlimage.'\"/> '; \n}\n"
},
{
"answer_id": 67336959,
"author": "Matthew Peterson",
"author_id": 2730516,
"author_profile": "https://Stackoverflow.com/users/2730516",
"pm_score": 2,
"selected": false,
"text": "fetch('/thing/stuck/in/cache', {method:'POST', credentials:'include'});\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321865",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
321,867 | <p>I can't seem to get a custom action working. I might be doing this wrong. Here's what I'm trying to do:</p>
<p>I'd like to run a custom action in my application install (Visual Studio Installer project) that runs an executable. The executable simply does some system.io filecopy tasks, and I've confirmed that the executable when ran by itself works perfectly.</p>
<ol>
<li>I created the installer project</li>
<li>added the exe to the application folder</li>
<li>went to custom actions and added the exe to the Commit step</li>
<li>InstallerClass is set to true</li>
<li>Ran the installer, didn't get the result I was hoping for. So I added a line to write to the windows log. Looked in the Windows log after running the installer again and it looked like it didn't run. Added a debug.break to the exe code Unisntalled/reinstalled my installer and nothing happened. I finally sat and watched the processes and confirmed the exe never gets executed. </li>
</ol>
<p>Any thoughts?</p>
<p>Targeted Systems: Windows XP, Vista
Visual Studio Version: 2008 Sp1
Language: VB.NET
Targeted Framework: 2.0</p>
<hr>
<p>Excellent. I think I'm getting closer thanks to the code you posted. I converted it to VB and i'm getting this error: Cannot Find myexename.savedstate. I assume I'm supposed to pass something to the subs you posted but I don't know what. (by the way this is a console application) I added a reference to the System.Configuration.Install.dll and here is my code:</p>
<pre>
Imports System.ComponentModel
Imports System.Configuration.Install
_
Public Class ApplicationInstaller
Inherits Installer
Public Overloads Overrides Sub Commit(ByVal savedState As IDictionary)
' Do some work on commit
The_Sub_I_Want_To_Run()
End Sub
Public Overloads Overrides Sub Install(ByVal stateSaver As IDictionary)
' Do some work on install
End Sub
Public Overloads Overrides Sub Uninstall(ByVal savedState As IDictionary)
' Do some work on uninstall
End Sub
End Class
</pre>
<hr>
<p>I did not call that. I've never used the Installer class before. I might be doing something very rookie here. Per your instructions, I've added the code that I have pasted below in the exe I want to run during my install. I added the exe to my application folder, then added it to the Commit custom action. Now here is the code I now have in the source of my exe that I'm trying to run:</p>
<p><code></p>
<pre>
_
Public Class ApplicationInstaller
Inherits Installer
Public Overloads Overrides Sub Commit(ByVal savedState As IDictionary)
' Do some work on commit
The_Sub_I_Have_my_codein()
MyBase.Commit(savedState)
End Sub
Public Overloads Overrides Sub Install(ByVal stateSaver As IDictionary)
' Do some work on install
End Sub
Public Overloads Overrides Sub Uninstall(ByVal savedState As IDictionary)
' Do some work on uninstall
End Sub
End Class
</code>
</pre>
<hr>
<p>Hmmm... In the exe's Project Properties I clicked "Sign the assembly" and the error has gone away. However, looks like the exe doesn't run the code I want it to. </p>
| [
{
"answer_id": 321892,
"author": "Darin Dimitrov",
"author_id": 29407,
"author_profile": "https://Stackoverflow.com/users/29407",
"pm_score": 4,
"selected": true,
"text": "[RunInstaller(true)]\npublic class ApplicationInstaller : Installer\n{\n public override void Commit(IDictionary savedState) {\n // Do some work on commit\n }\n public override void Install(IDictionary stateSaver) {\n // Do some work on install\n }\n public override void Uninstall(IDictionary savedState) {\n // Do some work on uninstall\n }\n}\n"
},
{
"answer_id": 322032,
"author": "Darin Dimitrov",
"author_id": 29407,
"author_profile": "https://Stackoverflow.com/users/29407",
"pm_score": 2,
"selected": false,
"text": "public override void Commit(IDictionary savedState) {\n // Do some work on commit\n base.Commit(savedState);\n}\n"
},
{
"answer_id": 325502,
"author": "Andrey Neverov",
"author_id": 6698,
"author_profile": "https://Stackoverflow.com/users/6698",
"pm_score": 0,
"selected": false,
"text": "InstallerClass"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321867",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33371/"
] |
321,881 | <p>I have the following in a program (written in VB.NET):</p>
<pre><code>Imports Microsoft.Office.Interop.Excel
Public Class Form1
Dim eApp As New Excel.Application
Dim w As Excel.Workbook
w = eApp.Workbooks.Open( "path.xls", ReadOnly:=True)
.. Processing Code ..
//Attempts at killing the excel application
w.Close()
eApp.Workbooks.Close()
eApp.Quit()
End Class
</code></pre>
<p>When I run this a couple of times, I get a bunch of EXCEL.EXE instances in my task manager. How can I kill these processes in code? All of the ones in the code have been tried and did not work.</p>
| [
{
"answer_id": 321915,
"author": "Oscar Cabrero",
"author_id": 14440,
"author_profile": "https://Stackoverflow.com/users/14440",
"pm_score": 2,
"selected": false,
"text": "System.Runtime.InteropServices.Marshal.ReleaseComObject(eApp)\n"
},
{
"answer_id": 322182,
"author": "oglester",
"author_id": 2017,
"author_profile": "https://Stackoverflow.com/users/2017",
"pm_score": 0,
"selected": false,
"text": "Using eApp As New Excel.Application\n Using w As Excel.Workbook\n w = eApp.Workbooks.Open( \"path.xls\", ReadOnly:=True)\n .. Processing Code ..\n //Attempts at killing the excel application\n w.Close()\n eApp.Workbooks.Close()\n eApp.Quit()\n End Using\nEnd Using\n"
},
{
"answer_id": 1136838,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": " Process[] Proc = Process.GetProcessesByName(\"Excel\");\n foreach (Process p in Proc)\n {\n if (p.MainWindowTitle == \"\")\n p.Kill();\n }\n"
},
{
"answer_id": 13535049,
"author": "João Zaiden",
"author_id": 1549884,
"author_profile": "https://Stackoverflow.com/users/1549884",
"pm_score": 1,
"selected": false,
"text": "Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();\nWorkbook wb = xlApp.Workbooks.Open(...);\nWorksheet ws = (Worksheet)wb.Worksheets[1];\n"
},
{
"answer_id": 16322825,
"author": "da_jokker",
"author_id": 2340247,
"author_profile": "https://Stackoverflow.com/users/2340247",
"pm_score": 0,
"selected": false,
"text": "myExcelWorksheet = null;\nif (myExcelWorkbook != null)\n {\n myExcelWorkbook.Close();\n myExcelWorkbook = null;\n }\n if (myExcelApp != null)\n {\n myExcelApp.Quit();\n myExcelApp = null;\n }\n foreach (System.Diagnostics.Process myProcess in System.Diagnostics.Process.GetProcessesByName(\"Excel\"))\n {\n if (myProcess.MainWindowTitle == \"\")\n {\n myProcess.Kill();\n }\n }\n"
},
{
"answer_id": 17525350,
"author": "Samidjo",
"author_id": 526622,
"author_profile": "https://Stackoverflow.com/users/526622",
"pm_score": 0,
"selected": false,
"text": "//Quit Excel application\neApp.Quit();\n\n//Release COM objects (every object you used in eApp,like workbooks, Workbook, Sheets, Worksheet)\nSystem.Runtime.InteropServices.Marshal.ReleaseComObject(obj);\nobj = null;\n\n// Force garbage collector cleaning\nGC.Collect();\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321881",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22777/"
] |
321,896 | <p>Does anybody know if it is possible <strong>to choose the order of the fields</strong> in Dynamic Data (of course, without customizing the templates of each table) ?</p>
<p>Thanks !</p>
| [
{
"answer_id": 1260966,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "protected override void OnInit(EventArgs e)\n{\n ...\n this.gvItemsList.ColumnsGenerator = new EntityFieldsGenerator(CurrentDataSource.CurrentTableMetadata);\n ...\n}\n\npublic class EntityFieldsGenerator : IAutoFieldGenerator {\n...\npublic ICollection GenerateFields(Control control) \n{\n // based on entity meta info\n var fields = from item in this.entityMetadata.Columns\n where this.IncludeColumn(item.Value)\n orderby item.Value.Order\n select new DynamicField\n {\n DataField = item.Value.Column.Name,\n HeaderText = item.Value.DisplayName,\n DataFormatString = item.Value.DataFormatString,\n UIHint = GetColumnUIHint(item.Value)\n };\n return fields.ToList();\n} }\n"
},
{
"answer_id": 1403599,
"author": "Brian Hinchey",
"author_id": 62278,
"author_profile": "https://Stackoverflow.com/users/62278",
"pm_score": 1,
"selected": false,
"text": "[AttributeUsage(AttributeTargets.Property)]\npublic class ColumnOrderAttribute : Attribute\n{\n public int Order { get; private set; }\n public ColumnOrderAttribute() { Order = int.MaxValue; }\n public ColumnOrderAttribute(int order) { Order = order; }\n public static ColumnOrderAttribute Default = new ColumnOrderAttribute();\n}\n"
},
{
"answer_id": 2869777,
"author": "Ash Machine",
"author_id": 35615,
"author_profile": "https://Stackoverflow.com/users/35615",
"pm_score": 4,
"selected": false,
"text": "[Display(Name = \" Mission Statement\", Order = 30)]\npublic object MissionStatement { get; set; }\n\n[Display(Name = \"Last Mod\", Order = 40)] \npublic object DateModified { get; private set; }\n"
},
{
"answer_id": 5610853,
"author": "F.Filippi",
"author_id": 690580,
"author_profile": "https://Stackoverflow.com/users/690580",
"pm_score": 1,
"selected": false,
"text": "[Display(Order = 50)]\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321896",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/37592/"
] |
321,898 | <p>How do you get the name and/or description of an <a href="http://msdn.microsoft.com/en-us/library/ms680657(VS.85).aspx" rel="noreferrer">SEH</a> exception <strong>without</strong> having to hard-code the strings into your application?</p>
<p>I tried to use <code>FormatMessage()</code>, but it truncates the message sometimes, even if you specify to ignore inserts:</p>
<pre><code>__asm { // raise access violation
xor eax, eax
mov eax, [eax]
}
</code></pre>
<p>Raises an exception with the code <code>0xC0000005 (EXCEPTION_ACCESS_VIOLATION)</code>.</p>
<pre><code>char msg[256];
FormatMessageA(FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_IGNORE_INSERTS,
GetModuleHandleA("ntdll.dll"), 0xC0000005,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
msg, sizeof(msg), NULL);
</code></pre>
<p>Fills <code>msg</code> with the truncated string: "<code>The instruction at 0x</code>".</p>
| [
{
"answer_id": 33044673,
"author": "4LegsDrivenCat",
"author_id": 2006632,
"author_profile": "https://Stackoverflow.com/users/2006632",
"pm_score": 2,
"selected": false,
"text": "FORMAT_MESSAGE_FROM_SYSTEM"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321898",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36372/"
] |
321,914 | <p>I am new to LINQ. I am trying to find the rows that does not exists in the second data table. </p>
<p>report_list and benchmark both type are : DataTable. Both these datatables are being populated using OleDbCommand,OleDbDataAdapter. I am getting an error "Specified cast is not valid." in foreach ... loop. I would appreciate your help.</p>
<pre><code> var result = from a in report_list.AsEnumerable()
where !(from b in benchmark.AsEnumerable()
select b.Field<int>("bench_id")
)
.Contains(a.Field<int>("BenchmarkID"))
select a;
foreach (var c in result)
{
Console.WriteLine(c.Field<string>("Name"));
}
</code></pre>
| [
{
"answer_id": 322002,
"author": "Rafael Romão",
"author_id": 39281,
"author_profile": "https://Stackoverflow.com/users/39281",
"pm_score": 1,
"selected": false,
"text": "\nvar first = new string[] { \"b\", \"c\" };\nvar second = new string[] { \"a\", \"c\" };\n//find the itens that exist in \"first\" but not in \"second\"\nvar q = from f in first\n where !second.Contains(f)\n select f;\nforeach (var s in q) {\n Console.WriteLine(s);\n}\n\n//Prints:\n//b\n"
},
{
"answer_id": 322611,
"author": "gfrizzle",
"author_id": 23935,
"author_profile": "https://Stackoverflow.com/users/23935",
"pm_score": 0,
"selected": false,
"text": "From a in report_list\nGroup Join b in benchmark On a.bench_id Equals b.bench_id Into g = Group\nWhere g.Count = 0\nSelect a\n"
},
{
"answer_id": 322901,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 0,
"selected": false,
"text": "Field<int>()"
},
{
"answer_id": 323936,
"author": "Wobin",
"author_id": 15010,
"author_profile": "https://Stackoverflow.com/users/15010",
"pm_score": 0,
"selected": false,
"text": "(from b in benchmark.AsEnumerable() \n select new { id = b.Field<int>(\"bench_id\")}).Except(\n from a in report_list.AsEnumerable() \n select new {id = a.Field<int>(\"BenchmarkID\")})\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321914",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
321,921 | <p>I've been using extension methods quite a bit recently and have found a lot of uses for them. The only problem I have is remembering where they are and what namespace to use in order to get the extension methods.</p>
<p>However, I recently had a thought of writing the extension methods in the System namespace, System.Collections namespace or some other system namespace that makes sense. So for example, I've implemented the following.</p>
<pre><code>namespace System
{
/// <summary>Various array extensions</summary>
public static class ArrayExtensions
{
/// <summary>Converts the array to a hex string</summary>
/// <param name="value">The value.</param>
/// <returns>The array as a hex string</returns>
public static string ToHexString(this byte[] value)
{
var hex = new StringBuilder(value.Length * 2);
foreach (byte b in value)
{
hex.AppendFormat("{0:X2}", b);
}
return hex.ToString();
}
}
}
</code></pre>
<p>Is this the correct thing to do? </p>
| [
{
"answer_id": 321934,
"author": "Jeff Yates",
"author_id": 23234,
"author_profile": "https://Stackoverflow.com/users/23234",
"pm_score": 4,
"selected": false,
"text": "System.Collections"
},
{
"answer_id": 322004,
"author": "Scott Dorman",
"author_id": 1559,
"author_profile": "https://Stackoverflow.com/users/1559",
"pm_score": 6,
"selected": true,
"text": "System.Collection.Extensions"
},
{
"answer_id": 329871,
"author": "Greg Beech",
"author_id": 13552,
"author_profile": "https://Stackoverflow.com/users/13552",
"pm_score": 2,
"selected": false,
"text": "TimeSpan"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321921",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5932/"
] |
321,924 | <p>I currently working on an issue tracker for my company to help them keep track of problems that arise with the network. I am using C# and SQL. </p>
<p>Each issue has about twenty things we need to keep track of(status, work loss, who created it, who's working on it, etc). I need to attach a list of teams affected by the issue to each entry in my main issue table. The list of teams affected ideally contains some sort of link to a unique table instance, just for that issue, that shows the list of teams affected and what percentage of each teams labs are affected.</p>
<p>So my question is what is the best way to impliment this "link" between an entry into the issue table and a unique table for that issue? Or am I thinking about this problem wrong.</p>
| [
{
"answer_id": 321964,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "https://Stackoverflow.com/users/20860",
"pm_score": 5,
"selected": true,
"text": "CREATE TABLE teams (\n team_id INTEGER PRIMARY KEY\n -- other attributes\n);\n\nCREATE TABLE issues (\n issue_id INTEGER PRIMARY KEY\n -- other attributes\n);\n\nCREATE TABLE team_issue (\n issue_id INTEGER NOT NULL,\n team_id INTEGER NOT NULL,\n FOREIGN KEY (issue_id) REFERENCES issues(issue_id),\n FOREIGN KEY (team_id) REFERENCES teams(team_id),\n PRIMARY KEY (issue_id, team_id)\n);\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321924",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41138/"
] |
321,947 | <p>I am trying to replace all occurences of ???some.text.and.dots??? in a html page to add a link on it. I've built this regexp that does it :</p>
<p>\?\?\?([a-z0-9.]*)\?\?\?</p>
<p>However, I would like to exclude any result that is inside a link : "<a ...> ... MY PATTERN ... </a>", and I am a little stuck as to how to do that, all my attempts have failed for now.</p>
| [
{
"answer_id": 322468,
"author": "Borgar",
"author_id": 27388,
"author_profile": "https://Stackoverflow.com/users/27388",
"pm_score": 4,
"selected": true,
"text": "var html = document.body.innerHTML;\nhtml = html.replace(/(<a\\s.*?>.*?<\\/a>)|(\\?\\?\\?([a-z0-9.]*)\\?\\?\\?)/g, \n function ( a, b, c, d ) {\n return ( a[0] == '<' ) ? a : '<a href=\"#\">' + d + '</a>'; \n });\ncontext.innerHTML = html;\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321947",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41142/"
] |
321,971 | <p>I'm serializing to XML my class where one of properties has type List<string>.</p>
<pre><code>public class MyClass {
...
public List<string> Properties { get; set; }
...
}
</code></pre>
<p>XML created by serializing this class looks like this:</p>
<pre><code><MyClass>
...
<Properties>
<string>somethinghere</string>
<string>somethinghere</string>
</Properties>
...
</MyClass>
</code></pre>
<p>and now my question. How can I change my class to achieve XML like this:</p>
<pre><code><MyClass>
...
<Properties>
<Property>somethinghere</Property>
<Property>somethinghere</Property>
</Properties>
...
</MyClass>
</code></pre>
<p>after serializing. Thanks for any help!</p>
| [
{
"answer_id": 321997,
"author": "user7116",
"author_id": 7116,
"author_profile": "https://Stackoverflow.com/users/7116",
"pm_score": 4,
"selected": true,
"text": "using System;\nusing System.IO;\nusing System.Xml.Serialization;\nusing System.Collections.Generic;\n\npublic class Program\n{\n [XmlArrayItem(\"Property\")]\n public List<string> Properties = new List<string>();\n\n public static void Main(string[] args)\n {\n Program program = new Program();\n program.Properties.Add(\"test1\");\n program.Properties.Add(\"test2\");\n program.Properties.Add(\"test3\");\n\n XmlSerializer xser = new XmlSerializer(typeof(Program));\n xser.Serialize(new FileStream(\"test.xml\", FileMode.Create), program);\n }\n}\n"
},
{
"answer_id": 322001,
"author": "Paul Sonier",
"author_id": 28053,
"author_profile": "https://Stackoverflow.com/users/28053",
"pm_score": 0,
"selected": false,
"text": "[XmlElement(\"Property\")]"
},
{
"answer_id": 2945180,
"author": "kgriffs",
"author_id": 21784,
"author_profile": "https://Stackoverflow.com/users/21784",
"pm_score": 0,
"selected": false,
"text": "[CollectionDataContract(ItemName=\"Property\")]\npublic class PropertyList: List<string>\n{\n public PropertyList() { }\n public PropertyList(IEnumerable<string> source) : base(source) { }\n}\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321971",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23280/"
] |
321,974 | <p>I'm working on a college assignment where I must verify if a certain clause (as a fact or as a rule) exists in the current clause database.</p>
<p>The idea is to use a rule whose head is verify(+name, +arguments). This rule should be true if in the database exists another rule whose head is name(arguments)</p>
<p>Any help would be greatly appreciated...</p>
| [
{
"answer_id": 322152,
"author": "Aleksandar Dimitrov",
"author_id": 11797,
"author_profile": "https://Stackoverflow.com/users/11797",
"pm_score": 1,
"selected": false,
"text": "father(abraham,isaac).\n"
},
{
"answer_id": 338681,
"author": "Kaarel",
"author_id": 12547,
"author_profile": "https://Stackoverflow.com/users/12547",
"pm_score": 4,
"selected": true,
"text": "call/1"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321974",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13828/"
] |
321,979 | <p>Exactly as the question states: How can you check if a variable in PHP contains a file pointer? Some like <code>is_string()</code> or <code>is_object()</code>.</p>
| [
{
"answer_id": 321988,
"author": "Greg",
"author_id": 24181,
"author_profile": "https://Stackoverflow.com/users/24181",
"pm_score": 2,
"selected": false,
"text": "stream_get_meta_data()"
},
{
"answer_id": 322061,
"author": "Wickethewok",
"author_id": 30133,
"author_profile": "https://Stackoverflow.com/users/30133",
"pm_score": 4,
"selected": true,
"text": "get_resource_type()"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321979",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5441/"
] |
321,985 | <p>How do I use GDB to debug a program which do not have debugging symbols on a 32-bit x86 processor? Inspecting the function arguments, local variables, resolving pointers would be useful to know how to do.
The intention is not really to use this for reverse engineering, as I'm sometimes just too lazy to install the debugging symbols and would be great to know how to get some basic information out of gdb.</p>
| [
{
"answer_id": 1123090,
"author": "RandomNickName42",
"author_id": 67819,
"author_profile": "https://Stackoverflow.com/users/67819",
"pm_score": 5,
"selected": false,
"text": "gdb \"whatever\"\nbreak __libc_start_main\nr\n"
},
{
"answer_id": 4363356,
"author": "SamB",
"author_id": 294313,
"author_profile": "https://Stackoverflow.com/users/294313",
"pm_score": 1,
"selected": false,
"text": "-g"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321985",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14337/"
] |
321,989 | <p>Given an ordered set of 2D pixel locations (adjacent or adjacent-diagonal) that form a complete path with no repeats, how do I determine the Greatest Linear Dimension of the polygon whose perimeter is that set of pixels? (where the GLD is the greatest linear distance of any pair of points in the set)</p>
<p>For my purposes, the obvious O(n^2) solution is probably not fast enough for figures of thousands of points. Are there good heuristics or lookup methods that bring the time complexity nearer to O(n) or O(log(n))?</p>
| [
{
"answer_id": 338558,
"author": "Jared Updike",
"author_id": 2543,
"author_profile": "https://Stackoverflow.com/users/2543",
"pm_score": 2,
"selected": false,
"text": "using System; \nusing System.Collections.Generic; \nusing System.Drawing; \n\n// Based on code here: \n// http://code.activestate.com/recipes/117225/ \n// Jared Updike ported it to C# 3 December 2008 \n\npublic class Convexhull \n{ \n // given a polygon formed by pts, return the subset of those points \n // that form the convex hull of the polygon \n // for integer Point structs, not float/PointF \n public static Point[] ConvexHull(Point[] pts) \n { \n PointF[] mpts = FromPoints(pts); \n PointF[] result = ConvexHull(mpts); \n int n = result.Length; \n Point[] ret = new Point[n]; \n for (int i = 0; i < n; i++) \n ret[i] = new Point((int)result[i].X, (int)result[i].Y); \n return ret; \n } \n\n // given a polygon formed by pts, return the subset of those points \n // that form the convex hull of the polygon \n public static PointF[] ConvexHull(PointF[] pts) \n { \n PointF[][] l_u = ConvexHull_LU(pts); \n PointF[] lower = l_u[0]; \n PointF[] upper = l_u[1]; \n // Join the lower and upper hull \n int nl = lower.Length; \n int nu = upper.Length; \n PointF[] result = new PointF[nl + nu]; \n for (int i = 0; i < nl; i++) \n result[i] = lower[i]; \n for (int i = 0; i < nu; i++) \n result[i + nl] = upper[i]; \n return result; \n } \n\n // returns the two points that form the diameter of the polygon formed by points pts \n // takes and returns integer Point structs, not PointF \n public static Point[] Diameter(Point[] pts) \n { \n PointF[] fpts = FromPoints(pts); \n PointF[] maxPair = Diameter(fpts); \n return new Point[] { new Point((int)maxPair[0].X, (int)maxPair[0].Y), new Point((int)maxPair[1].X, (int)maxPair[1].Y) }; \n } \n\n // returns the two points that form the diameter of the polygon formed by points pts \n public static PointF[] Diameter(PointF[] pts) \n { \n IEnumerable<Pair> pairs = RotatingCalipers(pts); \n double max2 = Double.NegativeInfinity; \n Pair maxPair = null; \n foreach (Pair pair in pairs) \n { \n PointF p = pair.a; \n PointF q = pair.b; \n double dx = p.X - q.X; \n double dy = p.Y - q.Y; \n double dist2 = dx * dx + dy * dy; \n if (dist2 > max2) \n { \n maxPair = pair; \n max2 = dist2; \n } \n } \n\n // return Math.Sqrt(max2); \n return new PointF[] { maxPair.a, maxPair.b }; \n } \n\n private static PointF[] FromPoints(Point[] pts) \n { \n int n = pts.Length; \n PointF[] mpts = new PointF[n]; \n for (int i = 0; i < n; i++) \n mpts[i] = new PointF(pts[i].X, pts[i].Y); \n return mpts; \n } \n\n private static double Orientation(PointF p, PointF q, PointF r) \n { \n return (q.Y - p.Y) * (r.X - p.X) - (q.X - p.X) * (r.Y - p.Y); \n } \n\n private static void Pop<T>(List<T> l) \n { \n int n = l.Count; \n l.RemoveAt(n - 1); \n } \n\n private static T At<T>(List<T> l, int index) \n { \n int n = l.Count; \n if (index < 0) \n return l[n + index]; \n return l[index]; \n } \n\n private static PointF[][] ConvexHull_LU(PointF[] arr_pts) \n { \n List<PointF> u = new List<PointF>(); \n List<PointF> l = new List<PointF>(); \n List<PointF> pts = new List<PointF>(arr_pts.Length); \n pts.AddRange(arr_pts); \n pts.Sort(Compare); \n foreach (PointF p in pts) \n { \n while (u.Count > 1 && Orientation(At(u, -2), At(u, -1), p) <= 0) Pop(u); \n while (l.Count > 1 && Orientation(At(l, -2), At(l, -1), p) >= 0) Pop(l); \n u.Add(p); \n l.Add(p); \n } \n return new PointF[][] { l.ToArray(), u.ToArray() }; \n } \n\n private class Pair \n { \n public PointF a, b; \n public Pair(PointF a, PointF b) \n { \n this.a = a; \n this.b = b; \n } \n } \n\n private static IEnumerable<Pair> RotatingCalipers(PointF[] pts) \n { \n PointF[][] l_u = ConvexHull_LU(pts); \n PointF[] lower = l_u[0]; \n PointF[] upper = l_u[1]; \n int i = 0; \n int j = lower.Length - 1; \n while (i < upper.Length - 1 || j > 0) \n { \n yield return new Pair(upper[i], lower[j]); \n if (i == upper.Length - 1) j--; \n else if (j == 0) i += 1; \n else if ((upper[i + 1].Y - upper[i].Y) * (lower[j].X - lower[j - 1].X) > \n (lower[j].Y - lower[j - 1].Y) * (upper[i + 1].X - upper[i].X)) \n i++; \n else \n j--; \n } \n } \n\n private static int Compare(PointF a, PointF b) \n { \n if (a.X < b.X) \n { \n return -1; \n } \n else if (a.X == b.X) \n { \n if (a.Y < b.Y) \n return -1; \n else if (a.Y == b.Y) \n return 0; \n } \n return 1; \n } \n} \n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/321989",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2543/"
] |
322,005 | <p>Is it possible?</p>
<p>I have a listview with several gridviewcolumns. The last column has a dynamic header. I dont know what the column header will be at design time. It's actually a number I want to display as a string. </p>
<pre><code> <GridViewColumn Header="{Binding Path=SomeValue}"
DisplayMemberBinding="{Binding Path=OtherValue}"/>
</code></pre>
<p>This doesn't seem to work. The data will bind fine just the header remains blank. Stepping through the code and it doesn't even break on the SomeValue property.</p>
| [
{
"answer_id": 7287832,
"author": "denis morozov",
"author_id": 452941,
"author_profile": "https://Stackoverflow.com/users/452941",
"pm_score": 1,
"selected": false,
"text": "<common:DataContextSpy x:Key=\"dci\" DataContext=\"{Binding SomeProperty}\" />\n\n<DataGridTemplateColumn Header=\"{Binding Source={StaticResource dci}, \n Path=DataContext.SomePropertysListOfValues[14]}\">\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322005",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6204/"
] |
322,033 | <p>Our motor pool wants to scan drivers’ licenses and have the data imported into our custom system. We're looking for something that will allow us to programmatically get the data from the scanner (including the picture) and let us insert it into our application. I was wondering if anyone has had experience with this type of system and could recommend one or tell us which ones to avoid. Our application is written in PowerBuilder and uses a DB2 database. </p>
| [
{
"answer_id": 1564082,
"author": "Mike Spross",
"author_id": 17862,
"author_profile": "https://Stackoverflow.com/users/17862",
"pm_score": 2,
"selected": false,
"text": "Enter"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322033",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19072/"
] |
322,034 | <p>Looking to <strong>improve</strong> my IF statement, and I want to keep my code <b>looking pretty</b></p>
<p>This is what I am currently doing, is it <b>readable</b>, any room for <b>improvement</b>?</p>
<pre><code>SomeObject o = LoadSomeObject();
if( null == o
||
null == o.ID || null == o.Title
||
0 == o.ID.Length || 0 == o.Title.Length
)
</code></pre>
<p>I don't have anyone to ask around. That's why I came here in first place. Please don't close my question :( </p>
| [
{
"answer_id": 322038,
"author": "TravisO",
"author_id": 35116,
"author_profile": "https://Stackoverflow.com/users/35116",
"pm_score": 4,
"selected": true,
"text": "if ( null == o || null == o.ID || null.Title || 0 == o.ID.Length || 0 == o.Title.Length )\n{\n // do stuff\n}\n"
},
{
"answer_id": 322039,
"author": "Draemon",
"author_id": 26334,
"author_profile": "https://Stackoverflow.com/users/26334",
"pm_score": 2,
"selected": false,
"text": "if( null == o ||\n null == o.ID ||\n null == o.Title ||\n 0 == o.ID.Length ||\n 0 == o.Title.Length\n)\n"
},
{
"answer_id": 322043,
"author": "Ismael C",
"author_id": 41096,
"author_profile": "https://Stackoverflow.com/users/41096",
"pm_score": 2,
"selected": false,
"text": "if ( o == null || o.ID == null || null.Title ||\n o.ID.Length == 0 || o.Title.Length )\n"
},
{
"answer_id": 322044,
"author": "brabster",
"author_id": 2362,
"author_profile": "https://Stackoverflow.com/users/2362",
"pm_score": 4,
"selected": false,
"text": "if (value1 == value2 ||\n value3 == value4 ||\n value5 == value6 ||\n value7 == value8) {\n\n executeMyCode();\n}\n"
},
{
"answer_id": 322047,
"author": "strager",
"author_id": 39992,
"author_profile": "https://Stackoverflow.com/users/39992",
"pm_score": -1,
"selected": false,
"text": "if(x < 0 || x >= width\n|| y < 0 || y >= height)\n{\n /* Coordinate out of range ... */\n}\n"
},
{
"answer_id": 322049,
"author": "The Archetypal Paul",
"author_id": 21755,
"author_profile": "https://Stackoverflow.com/users/21755",
"pm_score": 2,
"selected": false,
"text": "if (o == null ||\n o.ID == null || o.ID.length == 0 ||\n o.Title == null || o.Title.Length == 0) \n"
},
{
"answer_id": 322123,
"author": "Albert",
"author_id": 40443,
"author_profile": "https://Stackoverflow.com/users/40443",
"pm_score": 3,
"selected": false,
"text": "if(null == o\n || null == o.ID\n || null == o.Title\n || 0 == o.ID.Length\n || 0 == o.Title.Length)\n"
},
{
"answer_id": 322236,
"author": "Paul Nathan",
"author_id": 26227,
"author_profile": "https://Stackoverflow.com/users/26227",
"pm_score": 0,
"selected": false,
"text": "if(\n o == null ||\n o.ID == null || \n o.Title == null ||\n o.ID.Length == 0 || \n o.Title.Length == 0\n )\n"
},
{
"answer_id": 322248,
"author": "John Dibling",
"author_id": 241536,
"author_profile": "https://Stackoverflow.com/users/241536",
"pm_score": 1,
"selected": false,
"text": "bool wereTheConditionsMet()\n{\n if( NULL == 0 )\n return true;\n if( NULL == o.ID )\n return true;\n : : // and so on until you exhaust all the affirmatives\n return false;\n}\n\nif ( wereTheConditionsMet() )\n{\n // do stuff\n}\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322034",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39677/"
] |
322,050 | <p>I am trying to make IBM jre to use PCF fonts from default X11 installation on my linux box. In particular adobe-helvetica font. I have toyed to modify fontconfig.properties in jre/lib folder but no matter what I do Java seams to use some other fonts. I guess there is some algorithm how java VM tries to link java logical fonts to actual physical fonts in the system even in case when font specified in config could not be used. On Windows it is pretty straight forward, but on Linux I was unable to make it work with anything except TrueType fonts.<br>
Anybody have experience with configuring fonts on IBM jre on Linux?</p>
| [
{
"answer_id": 322038,
"author": "TravisO",
"author_id": 35116,
"author_profile": "https://Stackoverflow.com/users/35116",
"pm_score": 4,
"selected": true,
"text": "if ( null == o || null == o.ID || null.Title || 0 == o.ID.Length || 0 == o.Title.Length )\n{\n // do stuff\n}\n"
},
{
"answer_id": 322039,
"author": "Draemon",
"author_id": 26334,
"author_profile": "https://Stackoverflow.com/users/26334",
"pm_score": 2,
"selected": false,
"text": "if( null == o ||\n null == o.ID ||\n null == o.Title ||\n 0 == o.ID.Length ||\n 0 == o.Title.Length\n)\n"
},
{
"answer_id": 322043,
"author": "Ismael C",
"author_id": 41096,
"author_profile": "https://Stackoverflow.com/users/41096",
"pm_score": 2,
"selected": false,
"text": "if ( o == null || o.ID == null || null.Title ||\n o.ID.Length == 0 || o.Title.Length )\n"
},
{
"answer_id": 322044,
"author": "brabster",
"author_id": 2362,
"author_profile": "https://Stackoverflow.com/users/2362",
"pm_score": 4,
"selected": false,
"text": "if (value1 == value2 ||\n value3 == value4 ||\n value5 == value6 ||\n value7 == value8) {\n\n executeMyCode();\n}\n"
},
{
"answer_id": 322047,
"author": "strager",
"author_id": 39992,
"author_profile": "https://Stackoverflow.com/users/39992",
"pm_score": -1,
"selected": false,
"text": "if(x < 0 || x >= width\n|| y < 0 || y >= height)\n{\n /* Coordinate out of range ... */\n}\n"
},
{
"answer_id": 322049,
"author": "The Archetypal Paul",
"author_id": 21755,
"author_profile": "https://Stackoverflow.com/users/21755",
"pm_score": 2,
"selected": false,
"text": "if (o == null ||\n o.ID == null || o.ID.length == 0 ||\n o.Title == null || o.Title.Length == 0) \n"
},
{
"answer_id": 322123,
"author": "Albert",
"author_id": 40443,
"author_profile": "https://Stackoverflow.com/users/40443",
"pm_score": 3,
"selected": false,
"text": "if(null == o\n || null == o.ID\n || null == o.Title\n || 0 == o.ID.Length\n || 0 == o.Title.Length)\n"
},
{
"answer_id": 322236,
"author": "Paul Nathan",
"author_id": 26227,
"author_profile": "https://Stackoverflow.com/users/26227",
"pm_score": 0,
"selected": false,
"text": "if(\n o == null ||\n o.ID == null || \n o.Title == null ||\n o.ID.Length == 0 || \n o.Title.Length == 0\n )\n"
},
{
"answer_id": 322248,
"author": "John Dibling",
"author_id": 241536,
"author_profile": "https://Stackoverflow.com/users/241536",
"pm_score": 1,
"selected": false,
"text": "bool wereTheConditionsMet()\n{\n if( NULL == 0 )\n return true;\n if( NULL == o.ID )\n return true;\n : : // and so on until you exhaust all the affirmatives\n return false;\n}\n\nif ( wereTheConditionsMet() )\n{\n // do stuff\n}\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322050",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20390/"
] |
322,052 | <p>I have read an example and tried to duplicate it's methods but with weird results. This is a 1 shot deal so I do not want to buy a package to do this. Also, it will be executed on a Multi-Valued database in a Basic that not many programmers write in anymore.
If anyone can post a small example of this It would be most helpful. Specifically, I need a box centered on an 8x11 paper with the left 1/3 filled in Green, the center 1/3 in Yellow and the last 1/3 in Red. Then Draw a line thru 3 points within each color of the box.</p>
<p>Thanks.</p>
| [
{
"answer_id": 334621,
"author": "Douglas Anderson",
"author_id": 5678,
"author_profile": "https://Stackoverflow.com/users/5678",
"pm_score": 1,
"selected": false,
"text": "<esc>&u300D<esc>*t300R<esc>*p300x300Y<esc>*r3U<esc>*v2S<esc>*c300a300b5P<esc>*p600x300Y<esc>*r3U<esc>*v3S<esc>*c300a300b5P<esc>*p900x300Y<esc>*r3U<esc>*v1S<esc>*c300a300b5P\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322052",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18225/"
] |
322,068 | <p>What is the best way to implement a 2D grid of radio buttons so that only one option in each column and one option in each row can be selected?</p>
| [
{
"answer_id": 325723,
"author": "tamberg",
"author_id": 3588,
"author_profile": "https://Stackoverflow.com/users/3588",
"pm_score": 0,
"selected": false,
"text": "using System;\nusing System.Drawing;\nusing System.Windows.Forms;\n\nclass Program {\n\n static RadioButton[] bs = new RadioButton[9];\n\n static void HandleCheckedChanged (object o, EventArgs a) {\n RadioButton b = o as RadioButton;\n if (b.Checked) {\n Console.WriteLine(Array.IndexOf(bs, b));\n }\n }\n\n static void Main () {\n Form f = new Form();\n int x = 0;\n int y = 0;\n int i = 0;\n int n = bs.Length;\n while (i < n) {\n bs[i] = new RadioButton();\n bs[i].Parent = f;\n bs[i].Location = new Point(x, y);\n bs[i].CheckedChanged += new EventHandler(HandleCheckedChanged);\n if ((i % 3) == 2) {\n x = 0;\n y += bs[i].Height;\n } else {\n x += bs[i].Width;\n }\n i++;\n }\n Application.Run(f);\n }\n\n}\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322068",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26428/"
] |
322,069 | <p>Just trying to make the enter key pressed after a time delay in vb6, all the examples I find don't seem to be working, any help?</p>
<p>Just trying to simulate a keystroke. Focus doesn't matter.</p>
| [
{
"answer_id": 329657,
"author": "GregUzelac",
"author_id": 27068,
"author_profile": "https://Stackoverflow.com/users/27068",
"pm_score": 0,
"selected": false,
"text": "Private Sub Command1_Click()\n Debug.Print CStr(Now) + \" Command1\"\nEnd Sub\nPrivate Sub Timer1_Timer()\n Debug.Print CStr(Now) + \" Sendkeys\"\n SendKeys \"{Enter}\"\nEnd Sub\n"
},
{
"answer_id": 13264741,
"author": "Ahmad",
"author_id": 736172,
"author_profile": "https://Stackoverflow.com/users/736172",
"pm_score": 0,
"selected": false,
"text": "t = Timer + 5 'Change 5 to a higher number if you need more time to wait\nDo While Timer < t\n DoEvents 'This is necessary to prevent freezing \nLoop\n\nSendKeys \"{ENTER}\"\n\nSendKeys \"{ENTER}\", True 'This might also work\n"
}
] | 2008/11/26 | [
"https://Stackoverflow.com/questions/322069",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.