qid
int64 4
19.1M
| question
stringlengths 18
48.3k
| answers
list | date
stringlengths 10
10
| metadata
list |
---|---|---|---|---|
33,175 |
<p>Is there a way when executing a stored procedure in Management Studio to get the data types of the result sets coming back? I'm looking for something like functionality of when you pass a table name to sp_help</p>
|
[
{
"answer_id": 65029,
"author": "Charles Graham",
"author_id": 7705,
"author_profile": "https://Stackoverflow.com/users/7705",
"pm_score": -1,
"selected": false,
"text": "if exists (select * from sys.tables where name = 'tmp_TableName')\n drop table tmp_TableName\ngo\nselect * into tmp_TableName from MyTable\n\n--do some stuff\n\ngo\nif exists (select * from sys.tables where name = 'tmp_TableName')\n drop table tmp_TableName\ngo\n"
},
{
"answer_id": 156031,
"author": "Cade Roux",
"author_id": 18255,
"author_profile": "https://Stackoverflow.com/users/18255",
"pm_score": 0,
"selected": false,
"text": "EXEC ('if exists (select * from sys.tables where name = ''tmp_TableName'') drop table tmp_TableName')\n\nEXEC ('select * into tmp_TableName from MyTable')\n\n-- Grab the column types from INFORMATION_SCHEMA here\n\nEXEC ('if exists (select * from sys.tables where name = ''tmp_TableName'') drop table tmp_TableName')\n"
},
{
"answer_id": 156795,
"author": "Rory",
"author_id": 8479,
"author_profile": "https://Stackoverflow.com/users/8479",
"pm_score": 0,
"selected": false,
"text": "select * into tmp_Results \nfrom openrowset( 'SQLOLEDB.1'\n , 'Server=your_server_name;Trusted_Connection=yes;'\n , 'exec your_stored_proc')\nexec sp_help 'tmp_Results'\ndrop table tmp_Results\n"
}
] |
2008/08/28
|
[
"https://Stackoverflow.com/questions/33175",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1302/"
] |
33,199 |
<p>Would it be possible to print <code>Hello</code> twice using single <code>condition</code>?</p>
<pre><code>if "condition"
printf ("Hello");
else
printf("World");
</code></pre>
|
[
{
"answer_id": 33202,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 3,
"selected": false,
"text": "if printf condition"
},
{
"answer_id": 33205,
"author": "scoob",
"author_id": 1165587,
"author_profile": "https://Stackoverflow.com/users/1165587",
"pm_score": 3,
"selected": false,
"text": "if ( printf(\"Hello\")==0)\n"
},
{
"answer_id": 33206,
"author": "Jake Pearson",
"author_id": 632,
"author_profile": "https://Stackoverflow.com/users/632",
"pm_score": 0,
"selected": false,
"text": "if(printf(\"Hello\") == 1)\n printf(\"Hello\")\nelse\n printf(\"World\")\n"
},
{
"answer_id": 33208,
"author": "Matt Dillard",
"author_id": 863,
"author_profile": "https://Stackoverflow.com/users/863",
"pm_score": 7,
"selected": true,
"text": "if ( printf(\"Hello\") == 0 )\n printf (\"Hello\");\nelse\n printf (\"World\");\n"
},
{
"answer_id": 33211,
"author": "travis",
"author_id": 1414,
"author_profile": "https://Stackoverflow.com/users/1414",
"pm_score": 2,
"selected": false,
"text": "if (true) printf (\"Hello\"); if (false)\n printf (\"Hello\");\nelse\n printf(\"World\");\n"
},
{
"answer_id": 33212,
"author": "Frank Krueger",
"author_id": 338,
"author_profile": "https://Stackoverflow.com/users/338",
"pm_score": 4,
"selected": false,
"text": "\"condition\" === (printf(\"Hello\"), 0)\n int main() {\n if (printf(\"Hello\"), 0)\n printf (\"Hello\");\n else\n printf(\"World\");\n}\n printf"
},
{
"answer_id": 33213,
"author": "Daren Thomas",
"author_id": 2260,
"author_profile": "https://Stackoverflow.com/users/2260",
"pm_score": 1,
"selected": false,
"text": "if (printf(\"Hello\") - strlen(\"Hello\"))\n printf(\"Hello\")\nelse\n printf(\"World\")\n printf"
},
{
"answer_id": 33216,
"author": "Billy Jo",
"author_id": 3447,
"author_profile": "https://Stackoverflow.com/users/3447",
"pm_score": 0,
"selected": false,
"text": "if (printf(\"Hello\") < 1)\n printf(\"Hello\");\nelse\n printf(\"World\");\n"
},
{
"answer_id": 33219,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "#define CONDITION (0) if (0) {} else\n"
},
{
"answer_id": 33253,
"author": "ryan",
"author_id": 2454,
"author_profile": "https://Stackoverflow.com/users/2454",
"pm_score": 0,
"selected": false,
"text": " if ( System.out.printf(\"Hello\").equals(\"\") )\n System.out.printf(\"Hello\");\n else\n System.out.printf(\"World\");\n"
},
{
"answer_id": 33724,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "printf if (printf(\"Hello\") && 0)\n printf(\"Hello\");\nelse\n printf(\"World\");\n"
},
{
"answer_id": 80684,
"author": "GowriKumar",
"author_id": 15150,
"author_profile": "https://Stackoverflow.com/users/15150",
"pm_score": 4,
"selected": false,
"text": "if (fork())\n printf (\"Hello\");\nelse\n printf(\"World\");\n"
},
{
"answer_id": 784683,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "int main(int argc, char* argv[])\n{ \n if( argc == 2 || main( 2, NULL ) )\n {\n printf(\"Hello \"); \n }\n else\n {\n printf(\"World\\n\");\n }\n return 0;\n}\n int main(int argc, char* argv[])\n{ \n if( !fork() )\n {\n printf(\"Hello \"); \n }\n else\n {\n printf(\"World\\n\");\n }\n return 0;\n}\n"
},
{
"answer_id": 1373971,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 2,
"selected": false,
"text": "exit if(printf(\"HelloWorld\"), exit(0), \"ByeBye\") \n printf (\"Hello\");\nelse\n printf (\"World\");\n"
},
{
"answer_id": 1774683,
"author": "Ed S.",
"author_id": 1053,
"author_profile": "https://Stackoverflow.com/users/1053",
"pm_score": 2,
"selected": false,
"text": "if something\n do_this\n do_that\nend\n"
},
{
"answer_id": 1774706,
"author": "Tordek",
"author_id": 77542,
"author_profile": "https://Stackoverflow.com/users/77542",
"pm_score": 2,
"selected": false,
"text": "if(foo)\n{\n bar();\n}\n//else\n{\n baz();\n}\n"
},
{
"answer_id": 1774711,
"author": "Eli Bendersky",
"author_id": 8206,
"author_profile": "https://Stackoverflow.com/users/8206",
"pm_score": 4,
"selected": false,
"text": "#include <stdio.h>\n#include <setjmp.h>\n\nint main()\n{\n jmp_buf env;\n\n if (!setjmp(env))\n {\n printf(\"if executed\\n\");\n longjmp(env, 1);\n }\n else\n {\n printf(\"else executed\\n\");\n }\n\n return 0;\n}\n if executed\nelse executed\n fork"
},
{
"answer_id": 1774717,
"author": "sud03r",
"author_id": 91593,
"author_profile": "https://Stackoverflow.com/users/91593",
"pm_score": 4,
"selected": false,
"text": "\n#include <stdio.h>\n\nint main()\n{\n static int i = 0 ;\n if( i++==0 ? main(): 1)\n printf(\"Hello,\");\n else\n printf(\"World\\n\");\n\n return 0 ;\n}\n Hello, World"
},
{
"answer_id": 1774757,
"author": "Jonathan Leffler",
"author_id": 15168,
"author_profile": "https://Stackoverflow.com/users/15168",
"pm_score": 2,
"selected": false,
"text": " if (condition == true)\n {\n ...stuff...\n goto Else;\n }\n else\n {\nElse:\n ...more stuff...\n }\n if (condition == true)\n {\n ...stuff...\n }\n ...more stuff...\n done_then = false;\n if (condition == true)\n {\nThen:\n ...stuff...\n done_then = true;\n goto Else;\n }\n else\n {\nElse:\n ...more stuff...\n if (!done_then) goto Then;\n }\n"
},
{
"answer_id": 1774759,
"author": "Dustin E",
"author_id": 215931,
"author_profile": "https://Stackoverflow.com/users/215931",
"pm_score": 2,
"selected": false,
"text": "int main()\n{\n runIfElse(true);\n runIfElse(false);\n\n return 0;\n}\n\nvoid runIfElse(bool p)\n{\n if(p)\n {\n // do if\n }\n else\n {\n // do else\n }\n}\n"
},
{
"answer_id": 1774788,
"author": "lpz",
"author_id": 215987,
"author_profile": "https://Stackoverflow.com/users/215987",
"pm_score": 0,
"selected": false,
"text": "if (condition)\n // do if stuff\nelse;\n // do else stuff\n for (int ii=0; ii<2; ii++)\n{\n if (condition && !ii)\n // do if stuff\n else\n {\n // do else stuff\n break;\n }\n}\n"
},
{
"answer_id": 10151648,
"author": "firesofmay",
"author_id": 679390,
"author_profile": "https://Stackoverflow.com/users/679390",
"pm_score": 0,
"selected": false,
"text": "#include <stdio.h>\n\nint\nmain(void)\n{\n if (!stdin || (stdin = 0, main()))\n printf(\"hello\");\n else\n printf(\"world\");\n return 0;\n}\n #include<stdio.h>\nvoid main()\n{\nif (1\n#define else if (1) \n)\n{ \n printf(\"hello\"); \n} \nelse\n { \n printf(\"world\"); \n}\n}\n"
},
{
"answer_id": 12060150,
"author": "mafia",
"author_id": 1137405,
"author_profile": "https://Stackoverflow.com/users/1137405",
"pm_score": -1,
"selected": false,
"text": " if(printf(\"hello\")? 0 : 1) { }\n"
},
{
"answer_id": 25564384,
"author": "shiju",
"author_id": 1179556,
"author_profile": "https://Stackoverflow.com/users/1179556",
"pm_score": 0,
"selected": false,
"text": "if (printf(\"hello\") & 0)\n{\nprintf(\"hello\");\n}\nelse\n{\nprintf(\"world\");\n"
},
{
"answer_id": 29992356,
"author": "Shankha Jana",
"author_id": 2550691,
"author_profile": "https://Stackoverflow.com/users/2550691",
"pm_score": 1,
"selected": false,
"text": " #include<stdio.h>\n int main()\n{\n if(! printf(\"Hello\"))\n printf (\"Hello\");\nelse\n printf (\"World\");\n return 0;\n}\n"
},
{
"answer_id": 29992672,
"author": "Michael Dorgan",
"author_id": 527574,
"author_profile": "https://Stackoverflow.com/users/527574",
"pm_score": 0,
"selected": false,
"text": "\n#define else \nif(1)\n{\n printf(\"hello\");\n}\nelse\n{\n printf(\"world\");\n}\n#undef else\n"
}
] |
2008/08/28
|
[
"https://Stackoverflow.com/questions/33199",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2454/"
] |
33,226 |
<p>Assuming such a query exists, I would greatly appreciate the help.</p>
<p>I'm trying to develop a permissions script that will grant "select" and "references" permissions on the user tables and views in a database. My hope is that executing the "grant" commands on each element in such a set will make it easier to keep permissions current when new tables and views are added to the database.</p>
|
[
{
"answer_id": 33266,
"author": "Jas",
"author_id": 777,
"author_profile": "https://Stackoverflow.com/users/777",
"pm_score": 0,
"selected": false,
"text": "select * from information_schema.tables\nwhere table_type = 'view'\n"
},
{
"answer_id": 33285,
"author": "SQLMenace",
"author_id": 740,
"author_profile": "https://Stackoverflow.com/users/740",
"pm_score": 4,
"selected": true,
"text": "select * from information_schema.tables\nWHERE OBJECTPROPERTY(OBJECT_ID(table_name),'IsMSShipped') =0 \n where table_type = 'view' \n"
},
{
"answer_id": 33302,
"author": "karlgrz",
"author_id": 318,
"author_profile": "https://Stackoverflow.com/users/318",
"pm_score": 2,
"selected": false,
"text": "SELECT\n *\nFROM\n sysobjects\nWHERE\n xtype = 'V' AND\n type = 'V' AND\n category = 0\n"
}
] |
2008/08/28
|
[
"https://Stackoverflow.com/questions/33226",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3475/"
] |
33,233 |
<p>Imagine you homebrew a custom gui framework that <em>doesn't</em> use windows handles (compact framework, so please don't argue with "whys"). One of the main disadvantages of developing such a framework is that you lose compatability with the winform designer.</p>
<p>So my question is to all of you who know a lot about VS customisation, would there be a clever mechanism by which one could incorperate the gui framework into the designer and get it to spit out your custom code instead of the standard windows stuff in the <code>InitialiseComponent()</code> method?</p>
|
[
{
"answer_id": 33266,
"author": "Jas",
"author_id": 777,
"author_profile": "https://Stackoverflow.com/users/777",
"pm_score": 0,
"selected": false,
"text": "select * from information_schema.tables\nwhere table_type = 'view'\n"
},
{
"answer_id": 33285,
"author": "SQLMenace",
"author_id": 740,
"author_profile": "https://Stackoverflow.com/users/740",
"pm_score": 4,
"selected": true,
"text": "select * from information_schema.tables\nWHERE OBJECTPROPERTY(OBJECT_ID(table_name),'IsMSShipped') =0 \n where table_type = 'view' \n"
},
{
"answer_id": 33302,
"author": "karlgrz",
"author_id": 318,
"author_profile": "https://Stackoverflow.com/users/318",
"pm_score": 2,
"selected": false,
"text": "SELECT\n *\nFROM\n sysobjects\nWHERE\n xtype = 'V' AND\n type = 'V' AND\n category = 0\n"
}
] |
2008/08/28
|
[
"https://Stackoverflow.com/questions/33233",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1143/"
] |
33,242 |
<p>Is there a method (other than trial and error) I can use to find unused image files? How about CSS declarations for ID's and Classes that don't even exist in the site?</p>
<p>It seems like there might be a way to write a script that scans the site, profile it, and see which images and styles are never loaded.</p>
|
[
{
"answer_id": 33318,
"author": "BCS",
"author_id": 1343,
"author_profile": "https://Stackoverflow.com/users/1343",
"pm_score": 4,
"selected": false,
"text": "diff \\\n <(sed some_rules httpd_log | sort -u) \\\n <(ls /var/www/whatever | sort -u) \\\n | grep something\n"
},
{
"answer_id": 9572622,
"author": "Șerban Ghiță",
"author_id": 976827,
"author_profile": "https://Stackoverflow.com/users/976827",
"pm_score": 6,
"selected": false,
"text": "(Inspector)->Audits->Remove unused CSS rules"
},
{
"answer_id": 32874830,
"author": "toddmo",
"author_id": 1045881,
"author_profile": "https://Stackoverflow.com/users/1045881",
"pm_score": 1,
"selected": false,
"text": "/* CSS CLEANER INSTRUCTIONS\n 1. Paste your HTML into the HTML window\n 2. Paste your CSS into the CSS window\n 5. The web page result now ends with a list of just the CSS used by your HTML!\n*/\n\nfunction cssRecursive(e) {\n var cssList = css(e);\n for (var i = 0; i < e.children.length; ++i) {\n var childElement = e.children[i];\n cssList = union(cssList, cssRecursive(childElement));\n }\n return cssList;\n}\n\nfunction css(a) {\n var sheets = document.styleSheets,\n o = [];\n a.matches = a.matches || a.webkitMatchesSelector || a.mozMatchesSelector || a.msMatchesSelector || a.oMatchesSelector;\n for (var i in sheets) {\n var rules = sheets[i].rules || sheets[i].cssRules;\n for (var r in rules) {\n if (a.matches(rules[r].selectorText)) {\n o.push(rules[r].cssText);\n }\n }\n }\n return o;\n}\n\nfunction union(x, y) {\n return unique(x.concat(y));\n};\n\nfunction unique(x) {\n return x.filter(function(elem, index) {\n return x.indexOf(elem) == index;\n });\n};\n\ndocument.write(\"<br/><hr/><code style='background-color:white; color:black;'>\");\nvar allCss = cssRecursive(document.body);\nfor (var i = 0; i < allCss.length; ++i) {\n var cssRule = allCss[i];\n document.write(cssRule + \"<br/>\");\n}\ndocument.write(\"</code>\");"
}
] |
2008/08/28
|
[
"https://Stackoverflow.com/questions/33242",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5/"
] |
33,250 |
<p>In one of my applications, I am querying active directory to get a list of all users below a given user (using the "Direct Reports" thing). So basically, given the name of the person, it is looked up in AD, then the Direct Reports are read. But then for every direct report, the tool needs to check the direct reports of the direct reports. Or, more abstract: The Tool will use a person as the root of the tree and then walk down the complete tree to get the names of all the leaves (can be several hundred)</p>
<p>Now, my concern is obviously performance, as this needs to be done quite a few times. My idea is to manually cache that (essentially just put all the names in a long string and store that somewhere and update it once a day).</p>
<p>But I just wonder if there is a more elegant way to first get the information and then cache it, possibly using something in the System.DirectoryServices Namespace?</p>
|
[
{
"answer_id": 39091,
"author": "Erick Sgarbi",
"author_id": 4171,
"author_profile": "https://Stackoverflow.com/users/4171",
"pm_score": 3,
"selected": true,
"text": "System.DirectoryServices.DirectoryEntry entry = new System.DirectoryServices.DirectoryEntry(); \n\n// Push the property values from AD back to cache.\n\nentry.RefreshCache(new string[] {\"cn\", \"www\" });\n"
}
] |
2008/08/28
|
[
"https://Stackoverflow.com/questions/33250",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/91/"
] |
33,252 |
<p>As a temporary stopgap until all the designers are in place we are currently hand-cranking a whole bunch of xml configuration files at work. One of the issues with this is file-versioning because people forget to update version numbers when updating the files (which is to be expected as humans generally suck at perfection).</p>
<p>Therefore I figure that as we store the files in Sharepoint I should be able to write a script to pull the files down from Sharepoint, get the version number and automatically enter/update the version number from Sharepoint into the file. This means when someone wants the "latest" files they can run the script and get the latest files with the version numbers correct (there is slightly more to it than this so the reason for using the script isn't just the benefit of auto-versioning).</p>
<p>Does anyone know how to get the files + version numbers from Sharepoint?</p>
|
[
{
"answer_id": 39091,
"author": "Erick Sgarbi",
"author_id": 4171,
"author_profile": "https://Stackoverflow.com/users/4171",
"pm_score": 3,
"selected": true,
"text": "System.DirectoryServices.DirectoryEntry entry = new System.DirectoryServices.DirectoryEntry(); \n\n// Push the property values from AD back to cache.\n\nentry.RefreshCache(new string[] {\"cn\", \"www\" });\n"
}
] |
2008/08/28
|
[
"https://Stackoverflow.com/questions/33252",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1143/"
] |
33,262 |
<p>I have a complete XML document in a string and would like a <code>Document</code> object. Google turns up all sorts of garbage. What is the simplest solution? (In Java 1.5)</p>
<p><strong>Solution</strong> Thanks to <a href="https://stackoverflow.com/users/1322/matt-mcminn">Matt McMinn</a>, I have settled on this implementation. It has the right level of input flexibility and exception granularity for me. (It's good to know if the error came from malformed XML - <code>SAXException</code> - or just bad IO - <code>IOException</code>.)</p>
<pre><code>public static org.w3c.dom.Document loadXMLFrom(String xml)
throws org.xml.sax.SAXException, java.io.IOException {
return loadXMLFrom(new java.io.ByteArrayInputStream(xml.getBytes()));
}
public static org.w3c.dom.Document loadXMLFrom(java.io.InputStream is)
throws org.xml.sax.SAXException, java.io.IOException {
javax.xml.parsers.DocumentBuilderFactory factory =
javax.xml.parsers.DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
javax.xml.parsers.DocumentBuilder builder = null;
try {
builder = factory.newDocumentBuilder();
}
catch (javax.xml.parsers.ParserConfigurationException ex) {
}
org.w3c.dom.Document doc = builder.parse(is);
is.close();
return doc;
}
</code></pre>
|
[
{
"answer_id": 33283,
"author": "Matt McMinn",
"author_id": 1322,
"author_profile": "https://Stackoverflow.com/users/1322",
"pm_score": 7,
"selected": true,
"text": "import javax.xml.parsers.DocumentBuilderFactory;\nimport javax.xml.parsers.DocumentBuilder;\nimport org.w3c.dom.Document;\nimport java.io.ByteArrayInputStream;\n\npublic Document loadXMLFromString(String xml) throws Exception\n{\n DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();\n\n factory.setNamespaceAware(true);\n DocumentBuilder builder = factory.newDocumentBuilder();\n\n return builder.parse(new ByteArrayInputStream(xml.getBytes()));\n}\n"
},
{
"answer_id": 33618,
"author": "erickson",
"author_id": 3474,
"author_profile": "https://Stackoverflow.com/users/3474",
"pm_score": 7,
"selected": false,
"text": "String String.getBytes() import java.io.StringReader;\nimport org.xml.sax.InputSource;\n…\n return builder.parse(new InputSource(new StringReader(xml)));\n"
},
{
"answer_id": 46121,
"author": "shsteimer",
"author_id": 292,
"author_profile": "https://Stackoverflow.com/users/292",
"pm_score": 3,
"selected": false,
"text": "private String DOC_ROOT=\"root\";\nString xml=getXmlString();\nDocument xmlDoc=loadXMLFrom(xml);\nElement template=xmlDoc.getDocumentElement();\nNodeList nodes=xmlDoc.getElementsByTagName(DOC_ROOT);\n\npublic static Document loadXMLFrom(String xml) throws Exception {\n InputSource is= new InputSource(new StringReader(xml));\n DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();\n factory.setNamespaceAware(true);\n DocumentBuilder builder = null;\n builder = factory.newDocumentBuilder();\n Document doc = builder.parse(is);\n return doc;\n }\n"
},
{
"answer_id": 25137190,
"author": "Xavier Dury",
"author_id": 599011,
"author_profile": "https://Stackoverflow.com/users/599011",
"pm_score": 2,
"selected": false,
"text": "import javax.xml.transform.Source;\nimport javax.xml.transform.TransformerException;\nimport javax.xml.transform.TransformerFactory;\nimport javax.xml.transform.dom.DOMResult;\nimport javax.xml.transform.stream.StreamSource;\n\npublic static Document loadXMLFrom(String xml) throws TransformerException {\n Source source = new StreamSource(new StringReader(xml));\n DOMResult result = new DOMResult();\n TransformerFactory.newInstance().newTransformer().transform(source , result);\n return (Document) result.getNode();\n} \n"
}
] |
2008/08/28
|
[
"https://Stackoverflow.com/questions/33262",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/338/"
] |
33,263 |
<p>I'm using the <a href="http://msdn.microsoft.com/en-us/library/ms178329.aspx" rel="nofollow noreferrer">ASP.NET Login Controls</a> and <a href="http://msdn.microsoft.com/en-us/library/aa480476.aspx" rel="nofollow noreferrer">Forms Authentication</a> for membership/credentials for an ASP.NET web application.</p>
<p>I've got two roles:</p>
<ul>
<li>Users</li>
<li>Administrators</li>
</ul>
<p>I want pages to be viewable by four different groups:</p>
<ul>
<li>Everyone <em>(Default, Help)</em></li>
<li>Anonymous <em>(CreateUser, Login, PasswordRecovery)</em></li>
<li>Users <em>(ChangePassword, DataEntry)</em></li>
<li>Administrators <em>(Report)</em></li>
</ul>
<p>Expanding on the example in the <a href="http://www.asp.net/learn/videos/video-45.aspx" rel="nofollow noreferrer">ASP.NET HOW DO I Video Series: Membership and Roles</a>, I've put those page files into such folders:</p>
<p><img src="https://i.stack.imgur.com/Ps7sm.gif" alt="Visual Studio Solution Explorer"></p>
<p>And I used the ASP.NET Web Site Administration Tool to set up access rules for each folder.</p>
<p>It works but seems kludgy to me and it creates issues <a href="https://stackoverflow.com/questions/33089/how-do-i-use-aspnet-login-controls-when-my-loginaspx-is-not-at-the-root-of-my-a">when Login.aspx is not at the root</a> and with the <a href="https://stackoverflow.com/questions/33166/how-do-i-keep-my-loginaspx-pages-returnurl-parameter-from-overriding-my-aspnet">ReturnUrl parameter</a> of Login.aspx.</p>
<p>Is there a better way to do this? Is there perhaps a simple way I can set permissions at the page level rather than at the folder level?</p>
|
[
{
"answer_id": 33283,
"author": "Matt McMinn",
"author_id": 1322,
"author_profile": "https://Stackoverflow.com/users/1322",
"pm_score": 7,
"selected": true,
"text": "import javax.xml.parsers.DocumentBuilderFactory;\nimport javax.xml.parsers.DocumentBuilder;\nimport org.w3c.dom.Document;\nimport java.io.ByteArrayInputStream;\n\npublic Document loadXMLFromString(String xml) throws Exception\n{\n DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();\n\n factory.setNamespaceAware(true);\n DocumentBuilder builder = factory.newDocumentBuilder();\n\n return builder.parse(new ByteArrayInputStream(xml.getBytes()));\n}\n"
},
{
"answer_id": 33618,
"author": "erickson",
"author_id": 3474,
"author_profile": "https://Stackoverflow.com/users/3474",
"pm_score": 7,
"selected": false,
"text": "String String.getBytes() import java.io.StringReader;\nimport org.xml.sax.InputSource;\n…\n return builder.parse(new InputSource(new StringReader(xml)));\n"
},
{
"answer_id": 46121,
"author": "shsteimer",
"author_id": 292,
"author_profile": "https://Stackoverflow.com/users/292",
"pm_score": 3,
"selected": false,
"text": "private String DOC_ROOT=\"root\";\nString xml=getXmlString();\nDocument xmlDoc=loadXMLFrom(xml);\nElement template=xmlDoc.getDocumentElement();\nNodeList nodes=xmlDoc.getElementsByTagName(DOC_ROOT);\n\npublic static Document loadXMLFrom(String xml) throws Exception {\n InputSource is= new InputSource(new StringReader(xml));\n DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();\n factory.setNamespaceAware(true);\n DocumentBuilder builder = null;\n builder = factory.newDocumentBuilder();\n Document doc = builder.parse(is);\n return doc;\n }\n"
},
{
"answer_id": 25137190,
"author": "Xavier Dury",
"author_id": 599011,
"author_profile": "https://Stackoverflow.com/users/599011",
"pm_score": 2,
"selected": false,
"text": "import javax.xml.transform.Source;\nimport javax.xml.transform.TransformerException;\nimport javax.xml.transform.TransformerFactory;\nimport javax.xml.transform.dom.DOMResult;\nimport javax.xml.transform.stream.StreamSource;\n\npublic static Document loadXMLFrom(String xml) throws TransformerException {\n Source source = new StreamSource(new StringReader(xml));\n DOMResult result = new DOMResult();\n TransformerFactory.newInstance().newTransformer().transform(source , result);\n return (Document) result.getNode();\n} \n"
}
] |
2008/08/28
|
[
"https://Stackoverflow.com/questions/33263",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/83/"
] |
33,265 |
<p>There are two weird operators in C#:</p>
<ul>
<li>the <a href="http://msdn.microsoft.com/en-us/library/6x6y6z4d.aspx" rel="noreferrer">true operator</a></li>
<li>the <a href="http://msdn.microsoft.com/en-us/library/6292hy1k.aspx" rel="noreferrer">false operator</a></li>
</ul>
<p>If I understand this right these operators can be used in types which I want to use instead of a boolean expression and where I don't want to provide an implicit conversion to bool.</p>
<p>Let's say I have a following class:</p>
<pre><code> public class MyType
{
public readonly int Value;
public MyType(int value)
{
Value = value;
}
public static bool operator true (MyType mt)
{
return mt.Value > 0;
}
public static bool operator false (MyType mt)
{
return mt.Value < 0;
}
}
</code></pre>
<p>So I can write the following code:</p>
<pre><code> MyType mTrue = new MyType(100);
MyType mFalse = new MyType(-100);
MyType mDontKnow = new MyType(0);
if (mTrue)
{
// Do something.
}
while (mFalse)
{
// Do something else.
}
do
{
// Another code comes here.
} while (mDontKnow)
</code></pre>
<p>However for all the examples above only the true operator is executed. So what's the false operator in C# good for?</p>
<p><em>Note: More examples can be found <a href="http://www.java2s.com/Tutorial/CSharp/0160__Operator-Overload/truefalseoperatorforComplex.htm" rel="noreferrer">here</a>, <a href="http://www.java2s.com/Tutorial/CSharp/0160__Operator-Overload/OverloadtrueandfalseforTwoDimension.htm" rel="noreferrer">here</a> and <a href="http://www.java2s.com/Tutorial/CSharp/0160__Operator-Overload/trueandfalseoperator.htm" rel="noreferrer">here</a>.</em></p>
|
[
{
"answer_id": 33337,
"author": "ljs",
"author_id": 3394,
"author_profile": "https://Stackoverflow.com/users/3394",
"pm_score": 2,
"selected": false,
"text": "SELECT COUNT(*) FROM Table WHERE Foo = TRUE OR Foo = FALSE\n6\n SELECT COUNT(*) FROM Table WHERE Foo = TRUE OR Foo = FALSE OR Foo IS NULL\n9\n int totalCount = (from s in MyTypeEnumerable\n where s || !s\n select s).Count();\n int totalCount = (from s in MyTypeEnumerable\n where s || !s || s.IsNull()\n select s).Count();\n"
},
{
"answer_id": 33339,
"author": "Shog9",
"author_id": 811,
"author_profile": "https://Stackoverflow.com/users/811",
"pm_score": 3,
"selected": false,
"text": "&& if ( mFalse && mTrue) \n{\n // ... something\n}\n mFalse.false() true false & mFalse.false() false"
},
{
"answer_id": 33391,
"author": "Nir",
"author_id": 3509,
"author_profile": "https://Stackoverflow.com/users/3509",
"pm_score": 7,
"selected": true,
"text": "&& || && || | & true false | & || && public static AbstractCriterion operator &(AbstractCriterion lhs, AbstractCriterion rhs)\n{\n return new AndExpression(lhs, rhs);\n}\n\npublic static AbstractCriterion operator |(AbstractCriterion lhs, AbstractCriterion rhs)\n{\n return new OrExpression(lhs, rhs);\n}\n\npublic static bool operator false(AbstractCriterion criteria)\n{\n return false;\n}\npublic static bool operator true(AbstractCriterion criteria)\n{\n return false;\n}\n"
}
] |
2008/08/28
|
[
"https://Stackoverflow.com/questions/33265",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2361/"
] |
33,275 |
<p>Is there a PDF library that one can use to automate creating PDFs from URLs? The current approach I use is to "Print" a page and select a PDF plugin like PrimoPDF to generate the PDF document but I was wanting to automate that. </p>
|
[
{
"answer_id": 8562361,
"author": "Alasdair",
"author_id": 1018582,
"author_profile": "https://Stackoverflow.com/users/1018582",
"pm_score": 2,
"selected": false,
"text": "wkpdfhtmltopdf http://www.whatever.com/page.html page.pdf\n"
}
] |
2008/08/28
|
[
"https://Stackoverflow.com/questions/33275",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/64/"
] |
33,301 |
<p>I have a JavaScript method that I need to run on one of my pages, in particular, the <code>onresize</code> event. </p>
<p>However, I don't see how I can set that event from my content page. I wish I could just put it on my master page, but I don't have the need for the method to be called on all pages that use that master page.</p>
<p>Any help would be appreciated.</p>
|
[
{
"answer_id": 33440,
"author": "Jason Bunting",
"author_id": 1790,
"author_profile": "https://Stackoverflow.com/users/1790",
"pm_score": 3,
"selected": true,
"text": "<script type=\"text/javascript\">\n\n// here is a cross-browser compatible way of connecting \n// handlers to events, in case you don't have one\nfunction attachEventHandler(element, eventToHandle, eventHandler) {\n if(element.attachEvent) {\n element.attachEvent(eventToHandle, eventHandler);\n } else if(element.addEventListener) {\n element.addEventListener(eventToHandle.replace(\"on\", \"\"), eventHandler, false);\n } else {\n element[eventToHandle] = eventHandler;\n }\n}\n\nattachEventHandler(window, \"onresize\", function() {\n // the code you want to run when the browser is resized\n});\n\n</script>\n"
},
{
"answer_id": 33603,
"author": "Adhip Gupta",
"author_id": 384,
"author_profile": "https://Stackoverflow.com/users/384",
"pm_score": 0,
"selected": false,
"text": "Page.ClientScript.RegisterStartupScript(this.GetType(), \"resizeMyPage\", \"window.onresize=function(){ resizeMyPage();}\", true);\n resizeMyPage"
}
] |
2008/08/28
|
[
"https://Stackoverflow.com/questions/33301",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1226/"
] |
33,334 |
<p>In this <a href="https://stackoverflow.com/questions/32877/how-to-remove-vsdebuggercausalitydata-data-from-soap-message">question</a> the answer was to flip on a switch that is picked up by the debugger disabling the extraneous header that was causing the problem. The Microsoft help implies these switched are user generated and does not list any switches.</p>
<pre><code><configuration>
<system.diagnostics>
<switches>
<add name="Remote.Disable" value="1" />
</switches>
</system.diagnostics>
</configuration>
</code></pre>
<p>What I would like to know is where the value "Remote.Disable" comes from and how find out what other things can be switched on or off. Currently it is just some config magic, and I don't like magic.</p>
|
[
{
"answer_id": 33683,
"author": "Glenn Slaven",
"author_id": 2975,
"author_profile": "https://Stackoverflow.com/users/2975",
"pm_score": 3,
"selected": true,
"text": "public static BooleanSwitch DisableRemoteDebugging\n{\n get\n {\n if (disableRemoteDebugging == null)\n {\n disableRemoteDebugging = new BooleanSwitch(\"Remote.Disable\", \"Disable remote debugging for web methods.\");\n }\n return disableRemoteDebugging;\n }\n}\n new BooleanSwitch\n"
}
] |
2008/08/28
|
[
"https://Stackoverflow.com/questions/33334",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1834/"
] |
33,341 |
<p>Is there a way to hide radio buttons inside a RadioButtonList control programmatically?</p>
|
[
{
"answer_id": 33365,
"author": "Dillie-O",
"author_id": 71,
"author_profile": "https://Stackoverflow.com/users/71",
"pm_score": 4,
"selected": true,
"text": "RadioButtonList.Items(1).CssClass.Add(\"visibility\", \"hidden\")\n"
},
{
"answer_id": 33371,
"author": "James Hall",
"author_id": 514,
"author_profile": "https://Stackoverflow.com/users/514",
"pm_score": 0,
"selected": false,
"text": "foreach(ListItem myItem in rbl.Items)\n{\nif(whatever condition)\nmyItem.Attributes.Add(\"visibility\",\"hidden\");\n\n}\n"
},
{
"answer_id": 319114,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "RadioButtonList.Items.Add(\"Item Name\" or index);\nRadioButtonList.Items.Remove(\"Item Name\" or index);\n"
},
{
"answer_id": 1594238,
"author": "BlueGreenWorld",
"author_id": 193072,
"author_profile": "https://Stackoverflow.com/users/193072",
"pm_score": 1,
"selected": false,
"text": "RadioButtonList.Items.Remove(RadioButtonList.Items.FindByValue(\"3\"));\n"
},
{
"answer_id": 12178048,
"author": "Airn5475",
"author_id": 229897,
"author_profile": "https://Stackoverflow.com/users/229897",
"pm_score": 2,
"selected": false,
"text": "RadioButtonList.Items(1).Attributes.Add(\"style\", \"display:none\") RadioButtonList.Items(1).Attributes.Add(\"style\", \"visibility:hidden\")"
},
{
"answer_id": 59497513,
"author": "Sumate Mephokkij",
"author_id": 10863080,
"author_profile": "https://Stackoverflow.com/users/10863080",
"pm_score": 0,
"selected": false,
"text": "RadioButtonList.Items(1).CssClass.Add(\"display\", \"none\");\n"
}
] |
2008/08/28
|
[
"https://Stackoverflow.com/questions/33341",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/877/"
] |
33,347 |
<p>I'm considering developing a website similar to stackoverflow, but the answers may also consist of drawings (schematics, in this case). I want to have an area in the answer form where they can make this schematic without requiring special plugins, etc. </p>
<ol>
<li>Are we to the point where SVG has or should have critical mass soon (1-2 years) such that designing a website where script-run SVG as a primary feature is reasonable (ie, requiring Firefox or another SVG/AJAX compliant browser)?</li>
<li>What are some good resources for learning cross platform SVG scripting (likely in javascript)?</li>
</ol>
<p>-Adam Davis</p>
|
[
{
"answer_id": 33502,
"author": "Jörg W Mittag",
"author_id": 2988,
"author_profile": "https://Stackoverflow.com/users/2988",
"pm_score": 4,
"selected": true,
"text": "<canvas> <canvas> <canvas> <canvas>"
},
{
"answer_id": 33602,
"author": "Brian Gianforcaro",
"author_id": 3415,
"author_profile": "https://Stackoverflow.com/users/3415",
"pm_score": 2,
"selected": false,
"text": "<canvas> <canvas>"
}
] |
2008/08/28
|
[
"https://Stackoverflow.com/questions/33347",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2915/"
] |
33,386 |
<p>Im sure this has happened to folks before, something works in debug mode, you compile in release, and something breaks.</p>
<p>This happened to me while working on a Embedded XP environment, the best way i found to do it really was to write a log file to determine where it would go wrong.</p>
<p>What are your experiences/ discoveries trying to tackle an annoying Release-mode bug?</p>
|
[
{
"answer_id": 33394,
"author": "Vin",
"author_id": 1747,
"author_profile": "https://Stackoverflow.com/users/1747",
"pm_score": 0,
"selected": false,
"text": "Trace.WriteLine(myVar);\n"
}
] |
2008/08/28
|
[
"https://Stackoverflow.com/questions/33386",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/514/"
] |
33,390 |
<p>What's the best lifetime model for a <code>DataContext</code>? Should I just create a new one whenever I need it (aka, function level), should I keep one available in each class that would use it (class level), or should I create a static class with a static DataContext (app-domain level)? Are there any considered best practices on this?</p>
|
[
{
"answer_id": 33405,
"author": "ljs",
"author_id": 3394,
"author_profile": "https://Stackoverflow.com/users/3394",
"pm_score": 4,
"selected": true,
"text": ".SubmitChanges() .SubmitChanges() datacontext .SubmitChanges() datacontext StateChange"
}
] |
2008/08/28
|
[
"https://Stackoverflow.com/questions/33390",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1194/"
] |
33,395 |
<p>I'm using the <a href="http://msdn.microsoft.com/en-us/library/ms178329.aspx" rel="nofollow noreferrer">ASP.NET Login Controls</a> and <a href="http://msdn.microsoft.com/en-us/library/aa480476.aspx" rel="nofollow noreferrer">Forms Authentication</a> for membership/credentials for an ASP.NET web application. And I'm using a <a href="http://msdn.microsoft.com/en-us/library/yy2ykkab.aspx" rel="nofollow noreferrer">site map</a> for site navigation.</p>
<p>I have ASP.NET TreeView and Menu navigation controls populated using a SiteMapDataSource. But off-limits administrator-only pages are visible to non-administrator users.</p>
<hr>
<blockquote>
<p><strong><a href="https://stackoverflow.com/users/1574/kevin-pang">Kevin Pang</a></strong> wrote:</p>
<p>I'm not sure how this question is any
different than your <a href="https://stackoverflow.com/questions/33263/how-do-i-best-handle-role-based-permissions-using-forms-authentication-on-my-as">other question</a>…</p>
</blockquote>
<p>The other question deals with assigning and maintaining permissions.</p>
<p>This question just deals with presentation of navigation. Specifically TreeView and Menu controls with sitemap data sources.</p>
<pre><code><asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource1" />
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" ShowStartingNode="False" />
</code></pre>
<hr>
<blockquote>
<p><strong><a href="https://stackoverflow.com/users/2808/nicholas">Nicholas</a></strong> wrote:</p>
<p>add role="SomeRole" in the sitemap</p>
</blockquote>
<p>Does that only handle the display issue? Or are such page permissions enforced?</p>
|
[
{
"answer_id": 33405,
"author": "ljs",
"author_id": 3394,
"author_profile": "https://Stackoverflow.com/users/3394",
"pm_score": 4,
"selected": true,
"text": ".SubmitChanges() .SubmitChanges() datacontext .SubmitChanges() datacontext StateChange"
}
] |
2008/08/28
|
[
"https://Stackoverflow.com/questions/33395",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/83/"
] |
33,409 |
<p>I am using SQL Server 2005. I have a table with a text column and I have many rows in the table where the value of this column is not null, but it is empty. Trying to compare against '' yields this response:</p>
<blockquote>
<p>The data types text and varchar are incompatible in the not equal to operator.</p>
</blockquote>
<p>Is there a special function to determine whether the value of a text column is not null but empty?</p>
|
[
{
"answer_id": 33425,
"author": "Eric Z Beard",
"author_id": 1219,
"author_profile": "https://Stackoverflow.com/users/1219",
"pm_score": 9,
"selected": true,
"text": "where datalength(mytextfield)=0\n"
},
{
"answer_id": 34036,
"author": "Dane",
"author_id": 2929,
"author_profile": "https://Stackoverflow.com/users/2929",
"pm_score": 5,
"selected": false,
"text": "SELECT * FROM mytable WHERE mytextfield LIKE ''\n"
},
{
"answer_id": 3104438,
"author": "Eric",
"author_id": 374536,
"author_profile": "https://Stackoverflow.com/users/374536",
"pm_score": 6,
"selected": false,
"text": "ISNULL(\ncase textcolum1\n WHEN '' THEN NULL\n ELSE textcolum1\nEND \n,textcolum2) textcolum1\n"
},
{
"answer_id": 9608085,
"author": "Yoosaf Abdulla",
"author_id": 676508,
"author_profile": "https://Stackoverflow.com/users/676508",
"pm_score": 0,
"selected": false,
"text": "StrengthInfo = CASE WHEN ((SELECT COUNT(UnitsOrdered) FROM [Data_Sub_orders].[dbo].[Snappy_Orders_Sub] WHERE IdPatient = @PatientId and IdDrugService = 226)> 0)\n THEN cast((S.UnitsOrdered) as varchar(50))\n ELSE 'No Labs Available'\n END\n"
},
{
"answer_id": 11017855,
"author": "Mike Roberts",
"author_id": 1454021,
"author_profile": "https://Stackoverflow.com/users/1454021",
"pm_score": 1,
"selected": false,
"text": "WHERE xyz LIKE CAST('% %' as text)\n"
},
{
"answer_id": 12326533,
"author": "marklark",
"author_id": 462234,
"author_profile": "https://Stackoverflow.com/users/462234",
"pm_score": 0,
"selected": false,
"text": "SELECT * FROM Table WHERE Text IS NULL or Text LIKE ''"
},
{
"answer_id": 16915901,
"author": "Pearl",
"author_id": 1920827,
"author_profile": "https://Stackoverflow.com/users/1920827",
"pm_score": 2,
"selected": false,
"text": "Select * from tb_Employee where ename is null\n"
},
{
"answer_id": 21686029,
"author": "Enrique Garcia",
"author_id": 1231186,
"author_profile": "https://Stackoverflow.com/users/1231186",
"pm_score": 2,
"selected": false,
"text": "SELECT * FROM TABLE\nWHERE ISNULL(FIELD, '')=''\n"
},
{
"answer_id": 25454764,
"author": "Nima",
"author_id": 3715742,
"author_profile": "https://Stackoverflow.com/users/3715742",
"pm_score": 4,
"selected": false,
"text": "SELECT * FROM myTable WHERE myColumn = ''\n SELECT * FROM myTable WHERE myColumn IS NULL OR myColumn = ''\n SELECT * FROM myTable WHERE myColumn IS NULL\n SELECT * FROM myTable WHERE myColumn <> ''\n"
},
{
"answer_id": 31875178,
"author": "Leo",
"author_id": 4189349,
"author_profile": "https://Stackoverflow.com/users/4189349",
"pm_score": 0,
"selected": false,
"text": "SELECT datalength(' ')\n SELECT datalength(RTRIM(LTRIM(ISNULL([TextColumn], ''))))\n"
},
{
"answer_id": 32258632,
"author": "Jorgesys",
"author_id": 250260,
"author_profile": "https://Stackoverflow.com/users/250260",
"pm_score": 1,
"selected": false,
"text": "SELECT length = DATALENGTH(myField)\nFROM myTABLE\n"
},
{
"answer_id": 52740656,
"author": "Luiz Fernando Corrêa Leite",
"author_id": 4267702,
"author_profile": "https://Stackoverflow.com/users/4267702",
"pm_score": 0,
"selected": false,
"text": "select * from mytable where convert(varchar, mycolumn) = ''\n"
},
{
"answer_id": 56599223,
"author": "Enrique Garcia",
"author_id": 1231186,
"author_profile": "https://Stackoverflow.com/users/1231186",
"pm_score": 1,
"selected": false,
"text": "isnull case case when campo is null then '' else campo end\n case when campo is null then '' else\n case when len(campo) = 0 then '' else campo en\nend\n create table #tabla(\nid int,\ncampo varchar(10)\n)\n\ninsert into #tabla\nvalues(1,null)\n\ninsert into #tabla\nvalues(2,'')\n\ninsert into #tabla\nvalues(3,null)\n\ninsert into #tabla\nvalues(4,'dato4')\n\ninsert into #tabla\nvalues(5,'dato5')\n\nselect id, case when campo is null then 'DATA NULL' else\n case when len(campo) = 0 then 'DATA EMPTY' else campo end\nend\nfrom #tabla\n\ndrop table #tabla\n"
},
{
"answer_id": 57628088,
"author": "user11968038",
"author_id": 11968038,
"author_profile": "https://Stackoverflow.com/users/11968038",
"pm_score": 0,
"selected": false,
"text": "DECLARE @temp as nvarchar(20)\n\nSET @temp = NULL\n--SET @temp = ''\n--SET @temp = 'Test'\n\nSELECT IIF(ISNULL(@temp,'')='','[Empty]',@temp)\n"
},
{
"answer_id": 68573417,
"author": "Pallav Chanana",
"author_id": 10538842,
"author_profile": "https://Stackoverflow.com/users/10538842",
"pm_score": 0,
"selected": false,
"text": "SELECT coalesce(NULLIF(column_name,''),'NA') as 'desired_name') from table;\n"
}
] |
2008/08/28
|
[
"https://Stackoverflow.com/questions/33409",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1214/"
] |
33,412 |
<p>After reading Jeff's blog post on <a href="http://www.codinghorror.com/blog/archives/001167.html" rel="noreferrer">Protecting Your Cookies: HttpOnly</a>. I'd like to implement HttpOnly cookies in my web application.</p>
<p>How do you tell tomcat to use http only cookies for sessions?</p>
|
[
{
"answer_id": 33456,
"author": "Shabaz",
"author_id": 1827,
"author_profile": "https://Stackoverflow.com/users/1827",
"pm_score": 3,
"selected": false,
"text": "//this is what needs to be changed\n//response.addCookieInternal(cookie);\n\n//this is whats new\nresponse.addCookieInternal(cookie, true);\n}\n public void addCookieInternal(final Cookie cookie) {\naddCookieInternal(cookie, false);\n}\n\npublic void addCookieInternal(final Cookie cookie, boolean HTTPOnly) {\n\nif (isCommitted())\nreturn;\n\nfinal StringBuffer sb = new StringBuffer();\n//web application code can receive a IllegalArgumentException\n//from the appendCookieValue invokation\nif (SecurityUtil.isPackageProtectionEnabled()) {\nAccessController.doPrivileged(new PrivilegedAction() {\npublic Object run(){\nServerCookie.appendCookieValue\n(sb, cookie.getVersion(), cookie.getName(),\ncookie.getValue(), cookie.getPath(),\ncookie.getDomain(), cookie.getComment(),\ncookie.getMaxAge(), cookie.getSecure());\nreturn null;\n}\n});\n} else {\nServerCookie.appendCookieValue\n(sb, cookie.getVersion(), cookie.getName(), cookie.getValue(),\ncookie.getPath(), cookie.getDomain(), cookie.getComment(),\ncookie.getMaxAge(), cookie.getSecure());\n}\n//of course, we really need to modify ServerCookie\n//but this is the general idea\nif (HTTPOnly) {\nsb.append(\"; HttpOnly\");\n}\n\n//if we reached here, no exception, cookie is valid\n// the header name is Set-Cookie for both \"old\" and v.1 ( RFC2109 )\n// RFC2965 is not supported by browsers and the Servlet spec\n// asks for 2109.\naddHeader(\"Set-Cookie\", sb.toString());\n\ncookies.add(cookie);\n}\n"
},
{
"answer_id": 33461,
"author": "Cheekysoft",
"author_id": 1820,
"author_profile": "https://Stackoverflow.com/users/1820",
"pm_score": 4,
"selected": false,
"text": "response.setHeader( \"Set-Cookie\", \"name=value; HttpOnly\");\n if (response.containsHeader( \"SET-COOKIE\" )) {\n String sessionid = request.getSession().getId();\n response.setHeader( \"SET-COOKIE\", \"JSESSIONID=\" + sessionid \n + \";Path=/<whatever>; Secure; HttpOnly\" );\n} \n"
},
{
"answer_id": 1088009,
"author": "jt.",
"author_id": 4362,
"author_profile": "https://Stackoverflow.com/users/4362",
"pm_score": 7,
"selected": true,
"text": "<Context useHttpOnly=\"true\">\n...\n</Context>\n"
},
{
"answer_id": 1465092,
"author": "Hendrik Brummermann",
"author_id": 177701,
"author_profile": "https://Stackoverflow.com/users/177701",
"pm_score": 4,
"selected": false,
"text": "private void rewriteCookieToHeader(HttpServletRequest request, HttpServletResponse response) {\n if (response.containsHeader(\"SET-COOKIE\")) {\n String sessionid = request.getSession().getId();\n String contextPath = request.getContextPath();\n String secure = \"\";\n if (request.isSecure()) {\n secure = \"; Secure\"; \n }\n response.setHeader(\"SET-COOKIE\", \"JSESSIONID=\" + sessionid\n + \"; Path=\" + contextPath + \"; HttpOnly\" + secure);\n }\n}\n"
},
{
"answer_id": 14610452,
"author": "Jesse Vogt",
"author_id": 9822,
"author_profile": "https://Stackoverflow.com/users/9822",
"pm_score": 2,
"selected": false,
"text": "response.addCookie(cookie) cookie.saveTo(request, response)"
},
{
"answer_id": 30995999,
"author": "Alireza Fattahi",
"author_id": 2648077,
"author_profile": "https://Stackoverflow.com/users/2648077",
"pm_score": 4,
"selected": false,
"text": "web.xml <session-config>\n <cookie-config>\n <http-only>true</http-only> \n <secure>true</secure> \n </cookie-config>\n</session-config>\n"
},
{
"answer_id": 34147407,
"author": "Systemsplanet",
"author_id": 586841,
"author_profile": "https://Stackoverflow.com/users/586841",
"pm_score": 1,
"selected": false,
"text": "public void contextInitialized(ServletContextEvent event) { \n if (Boolean.getBoolean(\"HTTP_ONLY_SESSION\")) HttpOnlyConfig.enable(event);\n}\n import java.lang.reflect.Field;\nimport javax.servlet.ServletContext;\nimport javax.servlet.ServletContextEvent;\nimport org.apache.catalina.core.StandardContext;\npublic class HttpOnlyConfig\n{\n public static void enable(ServletContextEvent event)\n {\n ServletContext servletContext = event.getServletContext();\n Field f;\n try\n { // WARNING TOMCAT6 SPECIFIC!!\n f = servletContext.getClass().getDeclaredField(\"context\");\n f.setAccessible(true);\n org.apache.catalina.core.ApplicationContext ac = (org.apache.catalina.core.ApplicationContext) f.get(servletContext);\n f = ac.getClass().getDeclaredField(\"context\");\n f.setAccessible(true);\n org.apache.catalina.core.StandardContext sc = (StandardContext) f.get(ac);\n sc.setUseHttpOnly(true);\n }\n catch (Exception e)\n {\n System.err.print(\"HttpOnlyConfig cant enable\");\n e.printStackTrace();\n }\n }\n}\n"
},
{
"answer_id": 53652036,
"author": "Ravipati Praveen",
"author_id": 3876619,
"author_profile": "https://Stackoverflow.com/users/3876619",
"pm_score": 2,
"selected": false,
"text": "<session-config>\n <cookie-config>\n <http-only>true</http-only>\n </cookie-config>\n</session-config>\n"
},
{
"answer_id": 67748208,
"author": "Akash Chatterjee",
"author_id": 5010765,
"author_profile": "https://Stackoverflow.com/users/5010765",
"pm_score": 0,
"selected": false,
"text": " <cookie-config>\n <http-only>true</http-only>\n <secure>true</secure>\n </cookie-config>\n"
}
] |
2008/08/28
|
[
"https://Stackoverflow.com/questions/33412",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1310/"
] |
33,449 |
<p>Is there a way to call out from a TSQL stored procedure or function to a webservice?</p>
|
[
{
"answer_id": 33884,
"author": "Orion Edwards",
"author_id": 234,
"author_profile": "https://Stackoverflow.com/users/234",
"pm_score": 5,
"selected": false,
"text": "INSERT INTO BLAH"
},
{
"answer_id": 30211736,
"author": "Kiran.Bakwad",
"author_id": 2940450,
"author_profile": "https://Stackoverflow.com/users/2940450",
"pm_score": 6,
"selected": true,
"text": "CREATE PROCEDURE CALLWEBSERVICE(@Para1 ,@Para2)\nAS\nBEGIN\n Declare @Object as Int;\n Declare @ResponseText as Varchar(8000);\n\n Exec sp_OACreate 'MSXML2.XMLHTTP', @Object OUT;\n Exec sp_OAMethod @Object, 'open', NULL, 'get', 'http://www.webservicex.com/stockquote.asmx/GetQuote?symbol=MSFT','false'\n Exec sp_OAMethod @Object, 'send'\n Exec sp_OAMethod @Object, 'responseText', @ResponseText OUTPUT\n Select @ResponseText\n Exec sp_OADestroy @Object\nEND\n"
},
{
"answer_id": 43993270,
"author": "Tom Stickel",
"author_id": 756246,
"author_profile": "https://Stackoverflow.com/users/756246",
"pm_score": 3,
"selected": false,
"text": "EXEC sp_OACreate 'WinHttp.WinHttpRequest.5.1', @Object OUT;\nEXEC sp_OAMethod @Object, 'Open', NULL, 'POST', 'http://server/api/method', 'false'\nEXEC sp_OAMethod @Object, 'setRequestHeader', null, 'Content-Type', 'application/json'\nDECLARE @len INT = len(@requestBody) \n Alter Procedure yoursprocname\n\n @WavName varchar(50),\n @Dnis char(4) \n\n AS\nBEGIN\n\n SET NOCOUNT ON;\n\n\nDECLARE @Object INT;\nDECLARE @Status INT;\n\n\nDECLARE @requestBody NVARCHAR(MAX) = '{\n\"WavName\": \"{WavName}\",\n\"Dnis\": \"{Dnis}\"\n}'\n\n\nSET @requestBody = REPLACE(@requestBody, '{WavName}', @WavName)\nSET @requestBody = REPLACE(@requestBody, '{Dnis}', @Dnis)\n\n\nEXEC sp_OACreate 'WinHttp.WinHttpRequest.5.1', @Object OUT;\nEXEC sp_OAMethod @Object, 'Open', NULL, 'POST', 'http://server/api/method', 'false'\nEXEC sp_OAMethod @Object, 'setRequestHeader', null, 'Content-Type', 'application/json'\nDECLARE @len INT = len(@requestBody) \nEXEC sp_OAMethod @Object, 'setRequestHeader', null, 'Content-Length', @len\nEXEC sp_OAMethod @Object, 'send', null, @requestBody\nEXEC sp_OAGetProperty @Object, 'Status', @Status OUT\nEXEC sp_OADestroy @Object\n"
},
{
"answer_id": 59046429,
"author": "Jan",
"author_id": 2386040,
"author_profile": "https://Stackoverflow.com/users/2386040",
"pm_score": 2,
"selected": false,
"text": "--first configure MSSQL to enable calling out to a webservice (1=true, 0=false)\nsp_configure 'show advanced options', 1; \nGO \nRECONFIGURE; \nGO \nsp_configure 'Ole Automation Procedures', 1; \nGO \nRECONFIGURE; \nGO \n\nCREATE PROCEDURE CallWebAPI_ParseUserAgent @UserAgent VARCHAR(512)\nAS\nBEGIN\n SET NOCOUNT ON;\n\n DECLARE @Object INT;\n DECLARE @ResponseText AS VARCHAR(8000);\n DECLARE @url VARCHAR(512)\n\n SET @url = 'http://www.useragentstring.com/?getJSON=all&uas=' + @UserAgent;\n\n EXEC sp_OACreate 'WinHttp.WinHttpRequest.5.1', @Object OUT;\n EXEC sp_OAMethod @Object, 'Open', NULL, 'GET', @url, 'false'\n EXEC sp_OAMethod @Object, 'setRequestHeader', NULL, 'Content-Type', 'application/json'\n EXEC sp_OAMethod @Object, 'send'\n EXEC sp_OAMethod @Object, 'responseText', @ResponseText OUTPUT\n SELECT @ResponseText\n EXEC sp_OADestroy @Object\nEND\n\n--example how to call the API\nCallWebAPI_ParseUserAgent 'Mozilla/5.0 (Windows NT 6.2; rv:53.0) Gecko/20100101 Firefox/53.0'\n"
}
] |
2008/08/28
|
[
"https://Stackoverflow.com/questions/33449",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1874/"
] |
33,457 |
<p>Does anyone have a definitive answer to whether <a href="http://msdn.microsoft.com/en-us/library/ms162557.aspx" rel="nofollow noreferrer">Sql Server Management Objects</a> is compatible with Sql Server 7.0?
The docs state:</p>
<blockquote>
<p>Because SMO is compatible with SQL Server version 7.0, SQL Server 2000, SQL Server 2005, and SQL Server 2008, you easily manage a multi-version environment.</p>
</blockquote>
<p>But trying to connect to a Sql 7 instance gets me:</p>
<blockquote>
<p>"This SQL Server version (7.0) is not supported."</p>
</blockquote>
<p>Has anyone been successful in getting these 2 to play nice?</p>
|
[
{
"answer_id": 35118,
"author": "Mark Brackett",
"author_id": 2199,
"author_profile": "https://Stackoverflow.com/users/2199",
"pm_score": 1,
"selected": false,
"text": "protected void CheckServerVersion(ServerVersion version) {\n if ((version.Major <= 7 || (version.Major > 9)) {\n throw new ConnectionFailureException(\n StringConnectionInfo.ConnectToInvalidVersion(version.ToString())\n );\n }\n}\n"
}
] |
2008/08/28
|
[
"https://Stackoverflow.com/questions/33457",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2199/"
] |
33,459 |
<p>Is it possible to use a flash document embedded in HTML as a link?</p>
<p>I tried just wrapping the <code>object</code> element with an <code>a</code> like this:</p>
<pre><code><a href="http://whatever.com">
<object ...>
<embed ... />
</object>
</a>
</code></pre>
<p>In Internet Explorer, that made it show the location in the status bar like a link, but it doesn't do anything.</p>
<p>I just have the .swf file, so I can't add a click handler in ActionScript.</p>
|
[
{
"answer_id": 33519,
"author": "dlamblin",
"author_id": 459,
"author_profile": "https://Stackoverflow.com/users/459",
"pm_score": 2,
"selected": true,
"text": "_root.onPress=function(){getURL(\"http://yes.no/\");}; _root.addEventHandler(MouseEvent.PRESS, function (e:event) {getURL(\"http://yes.no/\");});"
},
{
"answer_id": 2945945,
"author": "s0natagrl",
"author_id": 354886,
"author_profile": "https://Stackoverflow.com/users/354886",
"pm_score": 1,
"selected": false,
"text": "<object onclick=\"window.location='URLHERE'; return false;\">\n"
}
] |
2008/08/28
|
[
"https://Stackoverflow.com/questions/33459",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2214/"
] |
33,465 |
<p>Working on a little side project web app...</p>
<p>I'd like to have it set up so that, when users send email to a certain account, I can kick off a PHP script that reads the email, pulls out some key info, and writes it to a database.</p>
<p>What's the best way to do this? A cron job that checks for new email?</p>
<p>The app is running on a "Dedicated-Virtual" Server at MediaTemple, so I guess I have a reasonable level of control, which should give me a range of options.</p>
<p>I'm very slowly learning the ropes (PHP, MySQL, configuring/managing the server), so your advice and insight are much appreciated.</p>
<p>Cheers,
Matt Stuehler</p>
|
[
{
"answer_id": 33488,
"author": "Pat",
"author_id": 238,
"author_profile": "https://Stackoverflow.com/users/238",
"pm_score": 0,
"selected": false,
"text": "|/full/path/to/script.php\n"
},
{
"answer_id": 33921,
"author": "hoyhoy",
"author_id": 3499,
"author_profile": "https://Stackoverflow.com/users/3499",
"pm_score": 2,
"selected": false,
"text": ":0: \n* ^(From).*[email protected]\n{ \n :0 c\n | php /var/www/app/process_email.php\n\n}\n"
},
{
"answer_id": 804920,
"author": "Warren Krewenki",
"author_id": 98028,
"author_profile": "https://Stackoverflow.com/users/98028",
"pm_score": 1,
"selected": false,
"text": "#!/usr/local/bin/php\n<?php\n$fd = fopen(\"php://stdin\",\"r\");\n$email = '';\nwhile($feof($fd)){\n $email .= fread($fd, 1024);\n}\nfclose($fd);\n?>\n"
}
] |
2008/08/28
|
[
"https://Stackoverflow.com/questions/33465",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
33,469 |
<p>So I just fixed a bug in a framework I'm developing. The pseudo-pseudocode looks like this:</p>
<pre><code>myoldObject = new MyObject { someValue = "old value" };
cache.Insert("myObjectKey", myoldObject);
myNewObject = cache.Get("myObjectKey");
myNewObject.someValue = "new value";
if(myObject.someValue != cache.Get("myObjectKey").someValue)
myObject.SaveToDatabase();
</code></pre>
<p>So, essentially, I was getting an object from the cache, and then later on comparing the original object to the cached object to see if I need to save it to the database in case it's changed. The problem arose because the original object is a reference...so changing someValue also changed the referenced cached object, so it'd never save back to the database. I fixed it by cloning the object off of the cached version, severing the reference and allowing me to compare the new object against the cached one.</p>
<p>My question is: <strong>is there a better way to do this, some pattern, that you could recommend?</strong> I can't be the only person that's done this before :)</p>
|
[
{
"answer_id": 33795,
"author": "Mark Brackett",
"author_id": 2199,
"author_profile": "https://Stackoverflow.com/users/2199",
"pm_score": 6,
"selected": true,
"text": "class MyObject {\n public string SomeValue { \n get { return _someValue; }\n set { \n if (value != SomeValue) {\n IsDirty = true;\n _someValue = value;\n }\n }\n\n public bool IsDirty {\n get;\n private set;\n }\n\n void SaveToDatabase() {\n base.SaveToDatabase(); \n IsDirty = false;\n }\n}\n\nmyoldObject = new MyObject { someValue = \"old value\" };\ncache.Insert(\"myObjectKey\", myoldObject);\nmyNewObject = cache.Get(\"myObjectKey\");\nmyNewObject.someValue = \"new value\";\nif(myNewObject.IsDirty)\n myNewObject.SaveToDatabase();\n"
},
{
"answer_id": 9415335,
"author": "Contra",
"author_id": 112508,
"author_profile": "https://Stackoverflow.com/users/112508",
"pm_score": 1,
"selected": false,
"text": "private string _name;\n[Column]\npublic string Name\n{\n get { return _name; }\n set\n {\n if (value != _name)\n {\n if (_name != null)\n {\n IsDirty = true; \n }\n _name = value;\n }\n }\n}\n"
}
] |
2008/08/28
|
[
"https://Stackoverflow.com/questions/33469",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1212/"
] |
33,471 |
<p>Is there a way to tell subversion "update/merge unless it would cause a conflict"?</p>
<p>I know you can use <code>--dry-run</code> / <code>status -u</code> to check before running the update, but I often have others running updates and getting broken webpages because they don't notice the "C index.php" line.</p>
<p>I've also noticed that svn doesn't seem too unhappy about conflicts - it still says "updated to revision blah" and exits zero, regardless of conflicts. So I have to parse the line-by-line output to discover them. Surely there's a better way?</p>
|
[
{
"answer_id": 164940,
"author": "Sander Rijken",
"author_id": 5555,
"author_profile": "https://Stackoverflow.com/users/5555",
"pm_score": 3,
"selected": true,
"text": "--accept ARG : specify automatic conflict resolution action\n ('postpone', 'base', 'mine-full', 'theirs-full',\n 'edit', 'launch')\n"
}
] |
2008/08/28
|
[
"https://Stackoverflow.com/questions/33471",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1806/"
] |
33,475 |
<p>I need to launch a server on the remote machine and retrieve the port number that the server process is lsitening on. When invoked, the server will listen on a random port and output the port number on stderr.</p>
<p>I want to automate the process of logging on to the remote machine, launching the process, and retrieving the port number. I wrote a Python script called "<code>invokejob.py</code>" that lives on the remote machine to act as a wrapper that invokes the job and then returns the port number, it looks like this:</p>
<pre><code>import re, subprocess
executable = ... # Name of executable
regex = ... # Regex to extract the port number from the output
p = subprocess.Popen(executable,
bufsize=1, # line buffered
stderr=subprocess.PIPE
)
s = p.stderr.readline()
port = re.match(regex).groups()[0]
print port
</code></pre>
<p>If I log in interactively, this script works:</p>
<pre><code>$ ssh remotehost.example.com
Last login: Thu Aug 28 17:31:18 2008 from localhost
$ ./invokejob.py
63409
$ exit
logout
Connection to remotehost.example.com closed.
</code></pre>
<p>(Note: successful logout, it did not hang).</p>
<p>However, if I try to invoke it from the command-line, it just hangs:</p>
<pre><code>$ ssh remotehost.example.com invokejob.py
</code></pre>
<p>Does anybody know why it hangs in the second case, and what I can do to avoid this? </p>
<p>Note that I need to retrieve the output of the program, so I can't just use the ssh "-f" flag or redirect standard output.</p>
|
[
{
"answer_id": 33486,
"author": "Ben Collins",
"author_id": 3279,
"author_profile": "https://Stackoverflow.com/users/3279",
"pm_score": 3,
"selected": true,
"text": "s = p.stderr.readline()\n"
},
{
"answer_id": 33673,
"author": "Misha M",
"author_id": 3467,
"author_profile": "https://Stackoverflow.com/users/3467",
"pm_score": 0,
"selected": false,
"text": "ssh <remote host> '<your command> ;<your regexp using awk or something>' ssh <remote host> '<your program>; ps aux | awk \\'/root/ {print $2}\\''"
}
] |
2008/08/28
|
[
"https://Stackoverflow.com/questions/33475",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/742/"
] |
33,476 |
<p>There are a couple of things that I am having a difficult time understanding with regards to developing custom components in JSF. For the purposes of these questions, you can assume that all of the custom controls are using valuebindings/expressions (not literal bindings), but I'm interested in explanations on them as well.</p>
<ol>
<li>Where do I set the value for the valuebinding? Is this supposed to happen in decode? Or should decode do something else and then have the value set in encodeBegin?</li>
<li>Read from the Value Binding - When do I read data from the valuebinding vs. reading it from submittedvalue and putting it into the valuebinding? </li>
<li>When are action listeners on forms called in relation to all of this? The JSF lifecycle pages all mention events happening at various steps, but its not completely clear to me when just a simple listener for a commandbutton is being called</li>
</ol>
<p>I've tried a few combinations, but always end up with hard to find bugs that I believe are coming from basic misunderstandings of the event lifecycle.</p>
|
[
{
"answer_id": 72753,
"author": "David Waters",
"author_id": 12148,
"author_profile": "https://Stackoverflow.com/users/12148",
"pm_score": 1,
"selected": false,
"text": "\npublic String getBar() { \n if (null != this.bar) { \n return this.bar ; \n } \n ValueBinding _vb = getValueBinding(\"bar\"); \n return (_vb != null) ? (bar) _vb.getValue(getFacesContext()) : null; \n}\n if (bar!= null) { \n if (isValueReference(bar)) { \n ValueBinding vb = Util.getValueBinding(bar); \n foo.setValueBinding(\"bar\", vb); \n } else { \n throw new IllegalStateException(\"The value for 'bar' must be a ValueBinding.\"); \n } \n } \n"
}
] |
2008/08/28
|
[
"https://Stackoverflow.com/questions/33476",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1432/"
] |
33,497 |
<p>Unchecked exceptions are alright if you want to handle every failure the same way, for example by logging it and skipping to the next request, displaying a message to the user and handling the next event, etc. If this is my use case, all I have to do is catch some general exception type at a high level in my system, and handle everything the same way.</p>
<p>But I want to recover from specific problems, and I'm not sure the best way to approach it with unchecked exceptions. Here is a concrete example.</p>
<p>Suppose I have a web application, built using Struts2 and Hibernate. If an exception bubbles up to my "action", I log it, and display a pretty apology to the user. But one of the functions of my web application is creating new user accounts, that require a unique user name. If a user picks a name that already exists, Hibernate throws an <code>org.hibernate.exception.ConstraintViolationException</code> (an unchecked exception) down in the guts of my system. I'd really like to recover from this particular problem by asking the user to choose another user name, rather than giving them the same "we logged your problem but for now you're hosed" message.</p>
<p>Here are a few points to consider:</p>
<ol>
<li>There a lot of people creating accounts simultaneously. I don't want to lock the whole user table between a "SELECT" to see if the name exists and an "INSERT" if it doesn't. In the case of relational databases, there might be some tricks to work around this, but what I'm really interested in is the general case where pre-checking for an exception won't work because of a fundamental race condition. Same thing could apply to looking for a file on the file system, etc.</li>
<li>Given my CTO's propensity for drive-by management induced by reading technology columns in "Inc.", I need a layer of indirection around the persistence mechanism so that I can throw out Hibernate and use Kodo, or whatever, without changing anything except the lowest layer of persistence code. As a matter of fact, there are several such layers of abstraction in my system. How can I prevent them from leaking in spite of unchecked exceptions?</li>
<li>One of the declaimed weaknesses of checked exceptions is having to "handle" them in every call on the stack—either by declaring that a calling method throws them, or by catching them and handling them. Handling them often means wrapping them in another checked exception of a type appropriate to the level of abstraction. So, for example, in checked-exception land, a file-system–based implementation of my UserRegistry might catch <code>IOException</code>, while a database implementation would catch <code>SQLException</code>, but both would throw a <code>UserNotFoundException</code> that hides the underlying implementation. How do I take advantage of unchecked exceptions, sparing myself of the burden of this wrapping at each layer, without leaking implementation details?</li>
</ol>
|
[
{
"answer_id": 33651,
"author": "Cem Catikkas",
"author_id": 3087,
"author_profile": "https://Stackoverflow.com/users/3087",
"pm_score": 0,
"selected": false,
"text": "try {\n throw new IllegalArgumentException();\n} catch (Exception e) {\n System.out.println(\"boom\");\n}\n"
},
{
"answer_id": 39769,
"author": "Jan Soltis",
"author_id": 3997,
"author_profile": "https://Stackoverflow.com/users/3997",
"pm_score": 1,
"selected": false,
"text": "// insert the user\ntry {\n hibernateSession.save(user);\n} catch (ConstraintViolationException e) {\n throw new MessageException(\"Username \" + user.getName() + \" already exists. Please choose a different name.\");\n}\n try {\n ... render the page\n} catch (MessageException e) {\n ... render a nice page with the message\n} catch (Exception e) {\n ... render \"we logged your problem but for now you're hosed\" message\n}\n"
}
] |
2008/08/28
|
[
"https://Stackoverflow.com/questions/33497",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3474/"
] |
33,510 |
<p>I hope this question does not come off as broad as it may seem at first. I am designing a software application that I would like to be both cross-platform and modular. I am still in the planning phase and can pick practically any language and toolset.</p>
<p>This makes things harder, not easier, because there are seemingly so many ways of accomplishing both of the goals (modularity, platform agnosticism).</p>
<p>My basic premise is that security, data storage, interaction with the operating system, and configuration should all be handled by a "container" application - but most of the other functionality will be supplied through plug-in modules. If I had to describe it at a high level (without completely giving away my idea), it would be a single application that can do many different jobs, all dedicated to the same goal (there are lots of disparate things to do, but all the data has to interact and be highly available).</p>
<p>I find myself wrestling with not so much how to do it (I can think of lots of ways), but which method is best.</p>
<p>For example, I know that Eclipse practically embodies what I am describing, but I find Java applications in general (and Eclipse is no exception) to be too large and slow for what I need. Ditto desktop apps written Python and Ruby (which are excellent languages!)</p>
<p>I don't mind recompiling the code base for different platforms as native exectables. Yet, C and C++ have their own set of issues.</p>
<p>As a C# developer, I have a preference for managed code, but I am not at all sold on Mono, yet (I could be convinced).</p>
<p>Does anyone have any ideas/experiences/ specific favorite frameworks to share?</p>
|
[
{
"answer_id": 190433,
"author": "dbr",
"author_id": 745,
"author_profile": "https://Stackoverflow.com/users/745",
"pm_score": 0,
"selected": false,
"text": "os.path config_path = \"/home/$USER\" UserConfig Application Data ~/Library/Preferences/"
}
] |
2008/08/28
|
[
"https://Stackoverflow.com/questions/33510",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/958/"
] |
33,529 |
<p>Inspired by this CodingHorror article, "<a href="http://www.codinghorror.com/blog/archives/001167.html" rel="noreferrer">Protecting Your Cookies: HttpOnly</a>"</p>
<p>How do you set this property? Somewhere in the web config?</p>
|
[
{
"answer_id": 33532,
"author": "Dillie-O",
"author_id": 71,
"author_profile": "https://Stackoverflow.com/users/71",
"pm_score": 4,
"selected": false,
"text": "<httpCookies domain=\"\" httpOnlyCookies=\"true|false\" requireSSL=\"true|false\" />\n"
},
{
"answer_id": 33541,
"author": "Corey McKinnon",
"author_id": 633,
"author_profile": "https://Stackoverflow.com/users/633",
"pm_score": 7,
"selected": true,
"text": "<httpCookies httpOnlyCookies=\"true\"/>\n"
},
{
"answer_id": 33887,
"author": "Portman",
"author_id": 1690,
"author_profile": "https://Stackoverflow.com/users/1690",
"pm_score": 3,
"selected": false,
"text": "// Create a new HttpCookie.\nHttpCookie myHttpCookie = new HttpCookie(\"LastVisit\", DateTime.Now.ToString());\n// By default, the HttpOnly property is set to false \n// unless specified otherwise in configuration.\nmyHttpCookie.Name = \"MyHttpCookie\";\nResponse.AppendCookie(myHttpCookie);\n// Show the name of the cookie.\nResponse.Write(myHttpCookie.Name);\n// Create an HttpOnly cookie.\nHttpCookie myHttpOnlyCookie = new HttpCookie(\"LastVisit\", DateTime.Now.ToString());\n// Setting the HttpOnly value to true, makes\n// this cookie accessible only to ASP.NET.\nmyHttpOnlyCookie.HttpOnly = true;\nmyHttpOnlyCookie.Name = \"MyHttpOnlyCookie\";\nResponse.AppendCookie(myHttpOnlyCookie);\n// Show the name of the HttpOnly cookie.\nResponse.Write(myHttpOnlyCookie.Name);\n"
},
{
"answer_id": 770764,
"author": "Matthew Lock",
"author_id": 74585,
"author_profile": "https://Stackoverflow.com/users/74585",
"pm_score": 2,
"selected": false,
"text": "<httpCookies httpOnlyCookies=\"false\"/> httpOnlyCookies"
}
] |
2008/08/28
|
[
"https://Stackoverflow.com/questions/33529",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1842/"
] |
33,534 |
<p>I'm trying to extend some "base" classes in Python:</p>
<pre><code>class xlist (list):
def len(self):
return len(self)
def add(self, *args):
self.extend(args)
return None
class xint (int):
def add(self, value):
self += value
return self
x = xlist([1,2,3])
print x.len() ## >>> 3 ok
print x ## >>> [1,2,3] ok
x.add (4, 5, 6)
print x ## >>> [1,2,3,4,5,6] ok
x = xint(10)
print x ## >>> 10 ok
x.add (2)
print x ## >>> 10 # Not ok (#1)
print type(x) ## >>> <class '__main__.xint'> ok
x += 5
print type(x) ## >>> <type 'int'> # Not ok (#2)
</code></pre>
<p>It works fine in the <em>list</em> case because the <em>append</em> method modifies the object "in place", without returning it. But in the <em>int</em> case, the <em>add</em> method doesn't modify the value of the external <em>x</em> variable. I suppose that's fine in the sense that <em>self</em> is a local variable in the <em>add</em> method of the class, but this is preventing me from modifying the initial value assigned to the instance of the class.</p>
<p>Is it possible to extend a class this way or should I define a class property with the base type and map all the needed methods to this property?</p>
|
[
{
"answer_id": 33563,
"author": "John Douthat",
"author_id": 2774,
"author_profile": "https://Stackoverflow.com/users/2774",
"pm_score": 4,
"selected": true,
"text": "int += int list"
},
{
"answer_id": 33663,
"author": "dF.",
"author_id": 3002,
"author_profile": "https://Stackoverflow.com/users/3002",
"pm_score": 5,
"selected": false,
"text": "xint self += value self = self + value self >>> x = xint(10)\n>>> x.add(2)\n int __add__ class xint(int):\n def __add__(self, value):\n return xint(int.__add__(self, value))\n\n>>> x = xint(10)\n>>> type(x)\n<class '__main__.xint'>\n>>> x += 3\n>>> x\n13\n>>> type(x)\n<class '__main__.xint'>\n"
},
{
"answer_id": 6809498,
"author": "gtmanfred",
"author_id": 786635,
"author_profile": "https://Stackoverflow.com/users/786635",
"pm_score": 2,
"selected": false,
"text": "class xlist:\n def __init__(self,alist):\n if type(alist)==type(' '):\n self.alist = [int(i) for i in alist.split(' ')]\n else:\n self.alist = alist\n def __iter__(self):\n i = 0\n while i<len(self.alist):\n yield self.alist[i]\n i+=1\n def len(self):\n return len(self.alist)\n def add(self, *args):\n if type(args[0])==type([1]):\n if len(args)>1:\n tmp = []\n [tmp.extend(i) for i in args]\n args = tmp\n else:args = args[0]\n if type(args)==type(''):args = [int(i) for i in args.split(' ')] \n (self.alist).extend(args)\n return None\n def index(self,val):\n gen = (i for i,x in enumerate(self.alist) if x == val)\n return list(gen)\n"
},
{
"answer_id": 71140509,
"author": "Raphael",
"author_id": 5943840,
"author_profile": "https://Stackoverflow.com/users/5943840",
"pm_score": 0,
"selected": false,
"text": "class MutablePartialInt:\n def __init__(self, value):\n self.value = value\n\n def _do_relational_method(self, other, method_to_run):\n func = getattr(self.value, method_to_run)\n if type(other) is MutablePartialInt:\n return func(other.value)\n else:\n return func(other)\n\n def __add__(self, other):\n return self._do_relational_method(other, \"__add__\")\n \n def __sub__(self, other):\n return self._do_relational_method(other, \"__sub__\")\n\n def __mul__(self, other):\n return self._do_relational_method(other, \"__mul__\")\n \n def __truediv__(self, other):\n return self._do_relational_method(other, \"__truediv__\")\n\n def __floordiv__(self, other):\n return self._do_relational_method(other, \"__floordiv__\")\n\n def __eq__(self, other):\n return self._do_relational_method(other, \"__eq__\")\n \n def __neq__(self, other):\n return self._do_relational_method(other, \"__neq__\")\n\n def __lt__(self, other):\n return self._do_relational_method(other, \"__lt__\")\n\n def __gt__(self, other):\n return self._do_relational_method(other, \"__gt__\")\n\n def __str__(self):\n return str(self.value)\n\n def __repr__(self):\n return self.__str__()\n"
}
] |
2008/08/28
|
[
"https://Stackoverflow.com/questions/33534",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/394/"
] |
33,577 |
<p>I want to check out all files in all subdirectories of a specified folder.</p>
<p>(And it is painful to do this using the GUI, because there is no recursive checkout option).</p>
|
[
{
"answer_id": 33605,
"author": "aku",
"author_id": 1196,
"author_profile": "https://Stackoverflow.com/users/1196",
"pm_score": 3,
"selected": false,
"text": "cleartool find somedir -exec \"cleartool checkout -nc \\\"%CLEARCASE_PN%\\\"\"\n"
},
{
"answer_id": 119595,
"author": "VonC",
"author_id": 6309,
"author_profile": "https://Stackoverflow.com/users/6309",
"pm_score": 6,
"selected": true,
"text": "cleartool c:\\MyFolder> cleartool\ncleartool> co -c \"Reason for massive checkout\" .../*\n cleartool find somedir -type f -exec \"cleartool checkout -c \\\"Reason for massive checkout\\\" \\\"%CLEARCASE_PN%\\\"\"\n ct lsco -r -cvi -fmt \"ci -nc \\\"%n\\\"\\n\" | ct\nct lsco -r -cvi -fmt \"unco -rm %n\\n\" | ct\n ct cleartool doskey ct=cleartool $* ct ci -nc -nc"
}
] |
2008/08/28
|
[
"https://Stackoverflow.com/questions/33577",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/814/"
] |
33,590 |
<p>Has anyone looked at <a href="http://developer.yahoo.com/flash/" rel="nofollow noreferrer">Yahoo's ASTRA</a>? It's fairly nifty, but I had some issues creating a custom label for a pie chart. They have an example for a line chart, which overrides an axis's series's label renderer. My solution was to override the <code>myPieChart.dataTipFunction</code>. For data that looks like:</p>
<pre><code>myPieChart.dataProvider =
[ { category: "Groceries", cost: 50 },
{ category: "Transportation", cost: 175} ]
myPieChart.dataField = "cost";
myPieChart.categoryField = "category";
</code></pre>
<p>I wrote a function like this:</p>
<pre><code>import com.yahoo.astra.fl.charts.series.*
myPieChart.dataTipFunction =
function (obj:Object, index:int, series:ISeries):String {
return obj.category + "\n$" + obj.cost;
};
</code></pre>
<p>There's ceil(2.718281828459045) problems with this:</p>
<ol>
<li><p>I'm directly calling the category and cost properties of the data provider. The names are actually configurable when setting up the chart, I'd like to maintain that flexibility.</p>
</li>
<li><p>The default data tip would show the category, the cost (without a dollar sign), and the percentage it makes up in the pie chart. So here, I've lost the percentage. I just have no idea which property of what would hold that. It might be part of the series.</p>
</li>
<li><p>I probably only need to override the <code>dataItemRenderer</code> for the cost part of the series, but I don't know how to access it. The documentation is a little ... lacking there.</p>
</li>
</ol>
<p>Normally I would just look at the default implementation of the <code>dataTipFunction</code> but it's all inside a compiled shm that's part of the components distributed from yahoo.</p>
<p>Can anyone help me complete this overridden function with percentage information and the flexibility mentioned in point 1?</p>
|
[
{
"answer_id": 35019,
"author": "dlamblin",
"author_id": 459,
"author_profile": "https://Stackoverflow.com/users/459",
"pm_score": 3,
"selected": true,
"text": "myPieChart.dataTipFunction = \n function (item:Object, index:int, series:ISeries):String {\n var oPieSeries:PieSeries = series as PieSeries;\n return oPieSeries.itemToCategory(item,index) + \"\\n$\" + \n oPieSeries.itemToData(item) + \"\\n\" + \n Number(oPieSeries.itemToPercentage(item)).toFixed(2) + \"%\";\n };\n"
}
] |
2008/08/28
|
[
"https://Stackoverflow.com/questions/33590",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/459/"
] |
33,594 |
<p>I need to <code>ShellExecute</code> something as another user, currently I start a helper process with <code>CreateProcessAsUser</code> that calls <code>ShellExecute</code>, but that seems like too much of a hack (Wrong parent process etc.) Is there a better way to do this?</p>
<p>@PabloG: ImpersonateLoggedOnUser does not work:</p>
<pre>
HANDLE hTok;
VERIFY(LogonUser("otheruser",0,"password",LOGON32_LOGON_INTERACTIVE,LOGON32_PROVIDER_DEFAULT,&hTok));
VERIFY(ImpersonateLoggedOnUser(hTok));
ShellExecute(0,0,"calc.exe",0,0,SW_SHOW);
RevertToSelf();
CloseHandle(hTok);
</pre>
<p>will just start calc as the logged in user, not "otheruser"</p>
<p>@1800 INFORMATION: <code>CreateProcess</code>/<code>CreateProcessAsUser</code> is not the same as <code>ShellExecute</code>, with UAC on Vista, <code>CreateProcess</code> is useless when you don't have control over what program the user is executing (<code>CreateProcess</code> will return with a error if you give it a exe file with a manifest marked as requireAdmin)</p>
<p>@Brian R. Bondy: I already know this info (And don't get me wrong, its good stuff), but it is off topic (IMHO) I am asking for a <code>ShellExecuteAsUser</code>, not about starting processes as another user, I already know how to do that.</p>
|
[
{
"answer_id": 1012800,
"author": "devdimi",
"author_id": 54983,
"author_profile": "https://Stackoverflow.com/users/54983",
"pm_score": 2,
"selected": false,
"text": "C:\\windwos\\system32\\cmd.exe /k\" start <your_target_to_be_ShellExecuted>\" CreateProcessAsUser"
}
] |
2008/08/28
|
[
"https://Stackoverflow.com/questions/33594",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3501/"
] |
33,664 |
<p>I've just started using Linq to SQL, and I'm wondering if anyone has any best practices they can share for managing dbml files.</p>
<ul>
<li>How do you keep them up to date with the database?</li>
<li>Do you have a single dbml file for the entire database, or is it split into multiple logical units? </li>
<li>How does managing this file work in a team environment?</li>
</ul>
<p>Any other tips and tricks welcome.</p>
|
[
{
"answer_id": 1790664,
"author": "Alison R.",
"author_id": 59870,
"author_profile": "https://Stackoverflow.com/users/59870",
"pm_score": 3,
"selected": false,
"text": " [Test]\n public void TestMetaData()\n {\n MyObj my_obj = new MyObj()\n {\n Foo = \"bar\",\n };\n\n Type type = MyObj.GetType();\n PropertyInfo prop = type.GetProperty(\"UpdatedOn\");\n IEnumerable<ColumnAttribute> info = (IEnumerable<ColumnAttribute>)prop.GetCustomAttributes(typeof(ColumnAttribute), true);\n Assert.IsTrue(\n info.Any<ColumnAttribute>(x => x.IsDbGenerated == true), \n \"The DBML file needs to have MyObj.UpdatedOn AutoGenerated == true set. This must be done manually if the DBML for this table gets refreshed from the database.\"\n );\n }\n"
}
] |
2008/08/28
|
[
"https://Stackoverflow.com/questions/33664",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/637/"
] |
33,685 |
<p>This is a sql 2000 database that I am working with.</p>
<p>I have what I call a staging table that is a raw data dump of data, so everything is ntext or nvarchar(255). </p>
<p>I need to cast/convert all of this data into the appropriate data types (ie int, decimal, nvarchar, etc.)</p>
<p>The way I was going to do this was to iterate through all records using a while loop and attempt a CAST on each column on a single record during each iteration, after I visit a particular record I flag it as processed (bit field).</p>
<p>But how can I log the error when/if it occurs but allow the while loop to continue.</p>
<p>At first I implemented this using a TRY CATCH in a local SQL 2005 instance (to get the project going) and all was working well, but i learned today that the dev & production database that the international DBA's have set up is a SQL 2000 instance so I have to conform.</p>
<p><strong>EDIT</strong>: I am using a SSIS package to populate the staging table. I see that now I must revisit that package and implement a script component to handle the conversions. Thanks guys</p>
<p><strong>EDIT</strong>: I <em>am</em> doing this on a record by record basis, not a batch insert, so the transaction idea seems like it would be feasible but I'm not sure how to trap @@ERROR and allow the stored procedure to continue.</p>
<p><strong>EDIT</strong>: I really like <a href="https://stackoverflow.com/questions/33685/sql-2000-try-catch-like-error-handling#39161">Guy's approach</a>, I am going to implement it this way.</p>
|
[
{
"answer_id": 33717,
"author": "jason saldo",
"author_id": 1293,
"author_profile": "https://Stackoverflow.com/users/1293",
"pm_score": 2,
"selected": false,
"text": "IF @@Error <> 0\n GOTO LABEL\n"
},
{
"answer_id": 39161,
"author": "Guy",
"author_id": 993,
"author_profile": "https://Stackoverflow.com/users/993",
"pm_score": 3,
"selected": true,
"text": "UPDATE staging_table\nSET status_code = 'FAIL_TEST_1'\nWHERE status_code IS NULL\nAND ISDATE(ntext_column1) = 0;\n\nUPDATE staging_table\nSET status_code = 'FAIL_TEST_2'\nWHERE status_code IS NULL\nAND ISNUMERIC(ntext_column2) = 0;\n\netc...\n INSERT INTO results_table ( mydate, myprice )\nSELECT ntext_column1 AS mydate, ntext_column2 AS myprice\nFROM staging_table\nWHERE status_code IS NULL;\n\nDELETE FROM staging_table\nWHERE status_code IS NULL;\n"
}
] |
2008/08/28
|
[
"https://Stackoverflow.com/questions/33685",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1950/"
] |
33,708 |
<p>So I've got a <code>JPanel</code> implementing <code>MouseListener</code> and <code>MouseMotionListener</code>:</p>
<pre><code>import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class DisplayArea extends JPanel implements MouseListener, MouseMotionListener {
public DisplayArea(Rectangle bounds, Display display) {
setLayout(null);
setBounds(bounds);
setOpaque(false);
setPreferredSize(new Dimension(bounds.width, bounds.height));
this.display = display;
}
public void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D)g;
if (display.getControlPanel().Antialiasing()) {
g2.addRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
}
g2.setColor(Color.white);
g2.fillRect(0, 0, getWidth(), getHeight());
}
public void mousePressed(MouseEvent event) {
System.out.println("mousePressed()");
mx1 = event.getX();
my1 = event.getY();
}
public void mouseReleased(MouseEvent event) {
System.out.println("mouseReleased()");
mx2 = event.getX();
my2 = event.getY();
int mode = display.getControlPanel().Mode();
switch (mode) {
case ControlPanel.LINE:
System.out.println("Line from " + mx1 + ", " + my1 + " to " + mx2 + ", " + my2 + ".");
}
}
public void mouseEntered(MouseEvent event) {
System.out.println("mouseEntered()");
}
public void mouseExited(MouseEvent event) {
System.out.println("mouseExited()");
}
public void mouseClicked(MouseEvent event) {
System.out.println("mouseClicked()");
}
public void mouseMoved(MouseEvent event) {
System.out.println("mouseMoved()");
}
public void mouseDragged(MouseEvent event) {
System.out.println("mouseDragged()");
}
private Display display = null;
private int mx1 = -1;
private int my1 = -1;
private int mx2 = -1;
private int my2 = -1;
}
</code></pre>
<p>The trouble is, none of these mouse functions are ever called. <code>DisplayArea</code> is created like this:</p>
<pre><code>da = new DisplayArea(new Rectangle(CONTROL_WIDTH, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT), this);
</code></pre>
<p>I am not really a Java programmer (this is part of an assignment), but I can't see anything glaringly obvious. Can someone smarter than I see anything?</p>
|
[
{
"answer_id": 33715,
"author": "Shabaz",
"author_id": 1827,
"author_profile": "https://Stackoverflow.com/users/1827",
"pm_score": 5,
"selected": true,
"text": "this.addMouseListener(this);\nthis.addMouseMotionListener(this);\n"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/33708",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/61/"
] |
33,720 |
<p>How would I change the initial templates created by Xcode when creating a new Cocoa Class.</p>
<p>I am referring to the comments and class name created when using Xcode's new class wizard.</p>
|
[
{
"answer_id": 33743,
"author": "Chris Hanson",
"author_id": 714,
"author_profile": "https://Stackoverflow.com/users/714",
"pm_score": 8,
"selected": true,
"text": "/Developer Library/Application Support ~/Library/Application Support/Developer/Shared/Xcode/File Templates/ ~/Library/Application Support/Developer/Shared/Xcode/Target Templates/ ~/Library/Application Support/Developer/Shared/Xcode/Project Templates/ ~/Library/Developer/Xcode/Templates/File Templates/Source"
},
{
"answer_id": 33789,
"author": "Barry Wark",
"author_id": 2140,
"author_profile": "https://Stackoverflow.com/users/2140",
"pm_score": 5,
"selected": false,
"text": "defaults write com.apple.Xcode PBXCustomTemplateMacroDefinitions '{ \"ORGANIZATIONNAME\" = \"NewCompanyName\";}'\n"
},
{
"answer_id": 8756703,
"author": "v01pe",
"author_id": 1050264,
"author_profile": "https://Stackoverflow.com/users/1050264",
"pm_score": 4,
"selected": false,
"text": "~/Library/Developer/Xcode/Templates/[Category]"
},
{
"answer_id": 25548430,
"author": "Alex Cio",
"author_id": 1141395,
"author_profile": "https://Stackoverflow.com/users/1141395",
"pm_score": 1,
"selected": false,
"text": "contents/Developer/Library/Xcode/Templates"
},
{
"answer_id": 27620151,
"author": "pconcepcion",
"author_id": 574353,
"author_profile": "https://Stackoverflow.com/users/574353",
"pm_score": 6,
"selected": false,
"text": "/Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/File Templates/Source\n ~/Library/Developer/Xcode/Templates/File Templates/Source /Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates/File Templates/Source"
},
{
"answer_id": 34561066,
"author": "carbo18",
"author_id": 2782573,
"author_profile": "https://Stackoverflow.com/users/2782573",
"pm_score": 3,
"selected": false,
"text": "~/Library/Developer/Xcode/Templates/File Templates ~/Library/Developer/Xcode/Templates/Project Templates Empty Application.xctemplate ~/Library/Developer/Xcode/Templates/Project Templates/Application"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/33720",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3467/"
] |
33,739 |
<p>Does anyone know how to debug <code>JSP</code> in <strong>IntelliJ</strong> IDEA?</p>
<p>When I set breakpoint in my <code>JSP</code> files, those breakpoints never seem to take effect. The debugger never hits them. IDEA seems to think that the breakpoints are valid. I do see a red dot placed to the left of the line where I place my breakpoint.</p>
<p>I read in IntelliJ forum <a href="http://intellij.net/forums/thread.jspa;jsessionid=2B86A25AECC06A4BE3447388882AA79F?messageID=5218405&#5218405" rel="noreferrer">in this post</a> that <code>JSP</code> files need to be under web-inf for debugging to work. </p>
<p>But then I also read that <code>JSP</code> files placed under web-inf won't be directly accessible by the user.</p>
<p>I am not sure who's really right. </p>
|
[
{
"answer_id": 23781314,
"author": "ccpizza",
"author_id": 191246,
"author_profile": "https://Stackoverflow.com/users/191246",
"pm_score": 5,
"selected": false,
"text": "localhost"
},
{
"answer_id": 35792469,
"author": "Romeo Frenksen",
"author_id": 6017489,
"author_profile": "https://Stackoverflow.com/users/6017489",
"pm_score": 1,
"selected": false,
"text": "<init-param>\n <param-name>suppressSmap</param-name>\n <param-value>false</param-value>\n</init-param>\n"
},
{
"answer_id": 48931123,
"author": "naXa stands with Ukraine",
"author_id": 1429387,
"author_profile": "https://Stackoverflow.com/users/1429387",
"pm_score": 1,
"selected": false,
"text": "this.jspContext.request.getAttribute(\"attributeName\")"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/33739",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
33,746 |
<p>At work we are being asked to create XML files to pass data to another offline application that will then create a second XML file to pass back in order to update some of our data. During the process we have been discussing with the team of the other application about the structure of the XML file. </p>
<p>The sample I came up with is essentially something like:</p>
<pre><code><INVENTORY>
<ITEM serialNumber="something" location="something" barcode="something">
<TYPE modelNumber="something" vendor="something"/>
</ITEM>
</INVENTORY>
</code></pre>
<p>The other team said that this was not industry standard and that attributes should only be used for meta data. They suggested:</p>
<pre><code><INVENTORY>
<ITEM>
<SERIALNUMBER>something</SERIALNUMBER>
<LOCATION>something</LOCATION>
<BARCODE>something</BARCODE>
<TYPE>
<MODELNUMBER>something</MODELNUMBER>
<VENDOR>something</VENDOR>
</TYPE>
</ITEM>
</INVENTORY>
</code></pre>
<p>The reason I suggested the first is that the size of the file created is much smaller. There will be roughly 80000 items that will be in the file during transfer. Their suggestion in reality turns out to be three times larger than the one I suggested. I searched for the mysterious "Industry Standard" that was mentioned, but the closest I could find was that XML attributes should only be used for meta data, but said the debate was about what was actually meta data.</p>
<p>After the long winded explanation (sorry) how do you determine what is meta data, and when designing the structure of an XML document how should you decide when to use an attribute or an element?</p>
|
[
{
"answer_id": 33757,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 8,
"selected": true,
"text": " <ITEM serialNumber=\"something\">\n <BARCODE encoding=\"Code39\">something</BARCODE>\n <LOCATION>XYX</LOCATION>\n <TYPE modelNumber=\"something\">\n <VENDOR>YYZ</VENDOR>\n </TYPE>\n </ITEM>\n"
},
{
"answer_id": 152363,
"author": "Rory Becker",
"author_id": 11356,
"author_profile": "https://Stackoverflow.com/users/11356",
"pm_score": 2,
"selected": false,
"text": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<data>\n <people>\n <person name=\"Rory\" surname=\"Becker\" age=\"30\" />\n <person name=\"Travis\" surname=\"Illig\" age=\"32\" />\n <person name=\"Scott\" surname=\"Hanselman\" age=\"34\" />\n </people>\n</data>\n <?xml version=\"1.0\" encoding=\"utf-8\"?>\n<data>\n <people>\n <person>\n <name>Rory</name>\n <surname>Becker</surname>\n <age>30</age>\n </person>\n <person>\n <name>Travis</name>\n <surname>Illig</surname>\n <age>32</age>\n </person>\n <person>\n <name>Scott</name>\n <surname>Hanselman</surname>\n <age>34</age>\n </person>\n </people>\n</data>\n <?xml version=\"1.0\" encoding=\"utf-8\"?>\n<data>\n <people>\n <person name=\"Rory\" surname=\"Becker\" age=\"30\" >\n <comment>A programmer whose interested in all sorts of misc stuff. His Blog can be found at http://rorybecker.blogspot.com and he's on twitter as @RoryBecker</comment>\n </person>\n <person name=\"Travis\" surname=\"Illig\" age=\"32\" >\n <comment>A cool guy for who has helped me out with all sorts of SVn information</comment>\n </person>\n <person name=\"Scott\" surname=\"Hanselman\" age=\"34\" >\n <comment>Scott works for MS and has a great podcast available at http://www.hanselminutes.com </comment>\n </person>\n </people>\n</data>\n"
},
{
"answer_id": 152509,
"author": "AnthonyWJones",
"author_id": 17516,
"author_profile": "https://Stackoverflow.com/users/17516",
"pm_score": 5,
"selected": false,
"text": "<INVENTORY>\n <ITEM serialNumber=\"something\" barcode=\"something\">\n <Location>XYX</LOCATION>\n <TYPE modelNumber=\"something\">\n <VENDOR>YYZ</VENDOR>\n </TYPE>\n </ITEM>\n</INVENTORY>\n <ITEM serialNumber=\"something\">\n <barcode encoding=\"Code39\">something</barcode>\n <Location>XYX</LOCATION>\n <TYPE modelNumber=\"something\">\n <VENDOR>YYZ</VENDOR>\n </TYPE>\n </ITEM>\n"
},
{
"answer_id": 420197,
"author": "user44350",
"author_id": 44350,
"author_profile": "https://Stackoverflow.com/users/44350",
"pm_score": 6,
"selected": false,
"text": "<note day=\"12\" month=\"11\" year=\"2002\" \n to=\"Tove\" to2=\"John\" from=\"Jani\" heading=\"Reminder\" \n body=\"Don't forget me this weekend!\"> \n</note>\n"
},
{
"answer_id": 1083932,
"author": "peter.murray.rust",
"author_id": 130964,
"author_profile": "https://Stackoverflow.com/users/130964",
"pm_score": 3,
"selected": false,
"text": "<foo title=\"bar\"/>;\n <foo>\n <title>bar</title>;\n</foo>;\n"
},
{
"answer_id": 3107163,
"author": "dan04",
"author_id": 287586,
"author_profile": "https://Stackoverflow.com/users/287586",
"pm_score": 5,
"selected": false,
"text": "<p><span lang=\"es\">El Jefe</span> insists that you\n <em class=\"urgent\">MUST</em> complete your project by Friday.</p>\n"
},
{
"answer_id": 5600135,
"author": "oh pot",
"author_id": 699275,
"author_profile": "https://Stackoverflow.com/users/699275",
"pm_score": -1,
"selected": false,
"text": "<image type=\"gif\">wank.jpg</image> ...etc etc\n <image>\n <url>wank.jpg</url>\n <fileType>gif</fileType>\n</image>\n"
},
{
"answer_id": 7252024,
"author": "Walter A. Jablonowski",
"author_id": 509073,
"author_profile": "https://Stackoverflow.com/users/509073",
"pm_score": 1,
"selected": false,
"text": "<customer format=\"\">\n <name></name>\n ...\n</customer>\n"
},
{
"answer_id": 23133755,
"author": "kjhughes",
"author_id": 290085,
"author_profile": "https://Stackoverflow.com/users/290085",
"pm_score": 5,
"selected": false,
"text": "<versus>\n <element attribute=\"Meta content\">\n Content\n </element>\n <element attribute=\"Flat\">\n <parent>\n <child>Hierarchical</child>\n </parent>\n </element>\n <element attribute=\"Unordered\">\n <ol>\n <li>Has</li>\n <li>order</li>\n </ol>\n </element>\n <element attribute=\"Must copy to reuse\">\n Can reference to re-use\n </element>\n <element attribute=\"For software\">\n For humans\n </element>\n <element attribute=\"Extreme use leads to micro-parsing\">\n Extreme use leads to document bloat\n </element>\n <element attribute=\"Unique names\">\n Unique or non-unique names\n </element>\n <element attribute=\"SAX parse: read first\">\n SAX parse: read later\n </element>\n <element attribute=\"DTD: default value\">\n DTD: no default value\n </element>\n</versus>\n"
},
{
"answer_id": 30265154,
"author": "MGrier",
"author_id": 3956776,
"author_profile": "https://Stackoverflow.com/users/3956776",
"pm_score": 1,
"selected": false,
"text": "<car><make>Ford</make><color>Red</color></car> <car make=\"Ford\" color=\"Red\" />"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/33746",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3340/"
] |
33,751 |
<p>I would like to add the following MIME type to a site run by <code>Apache</code>:</p>
<pre><code><mime-mapping>
<extension>jnlp</extension>
<mime-type>application/x-java-jnlp-file</mime-type>
</mime-mapping>
</code></pre>
<p><strong>That is the Tomcat format.</strong></p>
<p>I'm on a shared host, so I can only create an <code>.htaccess</code> file. Would someone please specify the complete contents of such a file?</p>
|
[
{
"answer_id": 33762,
"author": "Ryan Guest",
"author_id": 1811,
"author_profile": "https://Stackoverflow.com/users/1811",
"pm_score": 2,
"selected": false,
"text": "AddType application/x-java-jnlp-file .jnlp\n"
},
{
"answer_id": 33767,
"author": "Jörg W Mittag",
"author_id": 2988,
"author_profile": "https://Stackoverflow.com/users/2988",
"pm_score": 5,
"selected": true,
"text": "AddType application/x-java-jnlp-file .jnlp\n"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/33751",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/338/"
] |
33,761 |
<p>Using C# and System.Data.SqlClient, is there a way to retrieve a list of parameters that belong to a stored procedure on a SQL Server before I actually execute it?</p>
<p>I have an a "multi-environment" scenario where there are multiple versions of the same database schema. Examples of environments might be "Development", "Staging", & "Production". "Development" is going to have one version of the stored procedure and "Staging" is going to have another.</p>
<p>All I want to do is validate that a parameter is going to be there before passing it a value and calling the stored procedure. Avoiding that SqlException rather than having to catch it is a plus for me.</p>
<p>Joshua</p>
|
[
{
"answer_id": 33772,
"author": "Joshua Hayworth",
"author_id": 2049,
"author_profile": "https://Stackoverflow.com/users/2049",
"pm_score": 2,
"selected": false,
"text": "SqlCommandBuilder.DeriveParameters(command)\n Public Sub GetLogEntriesForApplication(ByVal settings As FilterSettings,\n Optional ByVal RowGovernor As Integer = -1)\n\n Dim command As New SqlCommand(\"GetApplicationActions\", \n New SqlConnection(m_environment.LoggingDatabaseConnectionString))\n Dim adapter As New SqlDataAdapter(command)\n\n Using command.Connection\n\n With command\n\n .Connection.Open()\n .CommandType = CommandType.StoredProcedure\n\n SqlCommandBuilder.DeriveParameters(command)\n\n With .Parameters\n\n If settings.FilterOnLoggingLevel Then\n If .Contains(\"@loggingLevel\") Then\n .Item(\"@loggingLevel\").Value = settings.LoggingLevel\n End If\n End If\n\n If settings.FilterOnApplicationID Then\n If .Contains(\"@applicationID\") Then\n .Item(\"@applicationID\").Value = settings.ApplicationID\n End If\n End If\n\n If settings.FilterOnCreatedDate Then\n If .Contains(\"@startDate\") Then\n .Item(\"@startDate\").Value = settings.CreatedDate.Ticks\n End If\n End If\n\n If settings.FilterOnEndDate Then\n If .Contains(\"@endDate\") Then\n .Item(\"@endDate\").Value = settings.EndDate.Ticks\n End If\n End If\n\n If settings.FilterOnSuccess Then\n If .Contains(\"@success\") Then\n .Item(\"@success\").Value = settings.Success\n End If\n End If\n\n If settings.FilterOnProcess Then\n If settings.Process > -1 Then\n If .Contains(\"@process\") Then\n .Item(\"@process\").Value = settings.Process\n End If\n End If\n End If\n\n If RowGovernor > -1 Then\n If .Contains(\"@topRows\") Then\n .Item(\"@topRows\").Value = RowGovernor\n End If\n End If\n\n End With\n\n End With\n\n adapter.TableMappings.Clear()\n adapter.TableMappings.Add(\"Table\", \"ApplicationActions\")\n adapter.TableMappings.Add(\"Table1\", \"Milestones\")\n\n LogEntries.Clear()\n Milestones.Clear()\n adapter.Fill(m_logEntryData)\n\n End Using\n\nEnd Sub\n"
},
{
"answer_id": 33781,
"author": "Mark Brackett",
"author_id": 2199,
"author_profile": "https://Stackoverflow.com/users/2199",
"pm_score": 4,
"selected": false,
"text": "using (SqlConnection conn = new SqlConnection(CONNSTRING))\nusing (SqlCommand cmd = new SqlCommand(\"StoredProc\", conn)) {\n cmd.CommandType = CommandType.StoredProcedure;\n SqlCommandBuilder.DeriveParameters(cmd);\n\n cmd.Parameters[\"param1\"].Value = \"12345\";\n\n // ....\n}\n"
},
{
"answer_id": 33809,
"author": "Steve Wranovsky",
"author_id": 3429,
"author_profile": "https://Stackoverflow.com/users/3429",
"pm_score": 3,
"selected": false,
"text": " public void LoadProcedureInfo()\n {\n SqlConnection connection = new SqlConnection();\n\n ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings[\"ConnectionString\"];\n\n connection.ConnectionString = settings.ConnectionString;\n connection.Open();\n\n DataTable procedureDataTable = connection.GetSchema(\"Procedures\");\n DataColumn procedureDataColumn = procedureDataTable.Columns[\"ROUTINE_NAME\"];\n\n if (procedureDataColumn != null)\n {\n foreach (DataRow row in procedureDataTable.Rows)\n {\n String procedureName = row[procedureDataColumn].ToString();\n\n DataTable parmsDataTable = connection.GetSchema(\"ProcedureParameters\", new string[] { null, null, procedureName });\n\n DataColumn parmNameDataColumn = parmsDataTable.Columns[\"PARAMETER_NAME\"];\n DataColumn parmTypeDataColumn = parmsDataTable.Columns[\"DATA_TYPE\"];\n\n foreach (DataRow parmRow in parmsDataTable.Rows)\n {\n string parmName = parmRow[parmNameDataColumn].ToString();\n string parmType = parmRow[parmTypeDataColumn].ToString();\n }\n }\n }\n }\n"
},
{
"answer_id": 472819,
"author": "MatthewMartin",
"author_id": 33264,
"author_profile": "https://Stackoverflow.com/users/33264",
"pm_score": 0,
"selected": false,
"text": "Select count(*) from information_schema.parameters \nwhere ...(proc name =.. param name=...) (pseudo-code)\n"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/33761",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2049/"
] |
33,768 |
<p>I run Flex Builder 3 on a mac and as my project grows - the compile time gets longer and longer and longer. I am using some SWC's and there is a fair amount of code but it shouldn't take minutes to build and crash daily should it?</p>
|
[
{
"answer_id": 34017,
"author": "jcsalterego",
"author_id": 1416,
"author_profile": "https://Stackoverflow.com/users/1416",
"pm_score": 0,
"selected": false,
"text": "mxmlc optimize=false mxmlc"
},
{
"answer_id": 34583,
"author": "Theo",
"author_id": 1109,
"author_profile": "https://Stackoverflow.com/users/1109",
"pm_score": 3,
"selected": false,
"text": "mxmlc optimize -incremental -keep-generated-actionscript mxmlc"
},
{
"answer_id": 449697,
"author": "Ted Naleid",
"author_id": 8912,
"author_profile": "https://Stackoverflow.com/users/8912",
"pm_score": 2,
"selected": false,
"text": "-vmargs -Xms768m -Xmx768m -XX:PermSize=128m -XX:MaxPermSize=128m \n"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/33768",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3435/"
] |
33,778 |
<p>One of my co-workers checked in a some files in SVN and one of the files has a password in it. The password has been removed from the file and a new version checked in but the password is obviously still in the repository if we look at the revision history and go to that revision. (We're using TortoiseSVN as the client.)</p>
<p>So how do I securely delete that single file from the repository in SVN?</p>
|
[
{
"answer_id": 56724,
"author": "Sam Hasler",
"author_id": 2541,
"author_profile": "https://Stackoverflow.com/users/2541",
"pm_score": 2,
"selected": false,
"text": "db\\revs db\\revprops #!/usr/bin/python\n\ndef dec_to_36(dec):\n key = '0123456789abcdefghijklmnopqrstuvwxyz'\n result = ''\n while 1:\n div = dec / 36\n mod = dec % 36\n dec = div\n result = key[mod] + result\n if dec == 0:\n break\n return result\n\n\nimport os, re, sys\n\nrepo_path = sys.argv[1]\nrev_path = os.path.join(repo_path, 'db', 'revs')\ncurrent_path = os.path.join(repo_path, 'db', 'current')\n\nid_re = re.compile(r'^id:\\ ([a-z0-9]+)\\.([a-z0-9]+)\\.r([0-9]+).*')\n\nmax_node_id = 0\nmax_copy_id = 0\nmax_rev_id = 0\n\nfor rev in os.listdir(rev_path):\n f = open(os.path.join(rev_path, rev), 'r')\n\n for line in f:\n m = id_re.match(line)\n if m:\n node_id = int(m.group(1), 36)\n copy_id = int(m.group(2), 36)\n rev_id = int(m.group(3), 10)\n\n if copy_id > max_copy_id:\n max_copy_id = copy_id\n\n if node_id > max_node_id:\n max_node_id = node_id\n\n if rev_id > max_rev_id:\n max_rev_id = rev_id\n\nf = open(current_path, 'w+b')\nf.write(\"%d %s %s\\n\" % (max_rev_id, dec_to_36(max_node_id+1),\n dec_to_36(max_copy_id+1)))\nf.close()\n"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/33778",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1463/"
] |
33,779 |
<p>Does anyone know of a powershell cmdlet out there for automating task scheduler in XP/2003? If you've ever tried to work w/ schtasks you know it's pretty painful.</p>
|
[
{
"answer_id": 33817,
"author": "Matt Hamilton",
"author_id": 615,
"author_profile": "https://Stackoverflow.com/users/615",
"pm_score": 2,
"selected": false,
"text": "$svc = new-object -com Schedule.Service\n $svc | get-member\n"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/33779",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1635/"
] |
33,790 |
<p>I am currently using the following command to upload my site content:</p>
<pre><code>scp -r web/* [email protected]:site.com/
</code></pre>
<p>This works great except that the .htaccess file is not sent. Presumably, this is because it's hidden.</p>
<p>I have tried adding a second line to send the file explicitely:</p>
<pre><code>scp -r web/.htaccess [email protected]:site.com/.htaccess
</code></pre>
<p>This works great except now I have to enter my password twice.</p>
<p>Any thoughts on how to make this deploy with only 1 or 0 entries of my password?</p>
|
[
{
"answer_id": 33791,
"author": "dF.",
"author_id": 3002,
"author_profile": "https://Stackoverflow.com/users/3002",
"pm_score": 4,
"selected": true,
"text": "scp -r web/* web/.htaccess [email protected]:site.com/\n"
},
{
"answer_id": 33803,
"author": "Kyle Cronin",
"author_id": 658,
"author_profile": "https://Stackoverflow.com/users/658",
"pm_score": 2,
"selected": false,
"text": ".htaccess .* .. rm /var .* cp root@krash:/# mkdir a\nroot@krash:/# mkdir b\nroot@krash:/# mkdir a/c\nroot@krash:/# touch a/d\nroot@krash:/# touch a/c/e\nroot@krash:/# cp -r a/c/.* b\ncp: will not create hard link `b/c' to directory `b/.'\nroot@krash:/# ls b\nd e\n .* .. d b"
},
{
"answer_id": 33804,
"author": "Jörg W Mittag",
"author_id": 2988,
"author_profile": "https://Stackoverflow.com/users/2988",
"pm_score": 2,
"selected": false,
"text": "* * . .. rm -rf *"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/33790",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/338/"
] |
33,813 |
<p>I noticed that many people here use <a href="http://macromates.com/" rel="nofollow noreferrer">TextMate</a> for coding on OS X. I've recently started using it, and although I like its minimalistic interface, it makes it harder to stumble upon cool features if you don't know what you're looking for.</p>
<p>So, what feature have you found most helpful for coding (mainly in Python)? Are there any third-party bundles I should know about, besides what's included?</p>
|
[
{
"answer_id": 36316,
"author": "jlleblanc",
"author_id": 586,
"author_profile": "https://Stackoverflow.com/users/586",
"pm_score": 6,
"selected": true,
"text": "diff file1.py file2.py | mate\n"
},
{
"answer_id": 248289,
"author": "feoh",
"author_id": 32514,
"author_profile": "https://Stackoverflow.com/users/32514",
"pm_score": 2,
"selected": false,
"text": "mate"
},
{
"answer_id": 618848,
"author": "DEfusion",
"author_id": 6432,
"author_profile": "https://Stackoverflow.com/users/6432",
"pm_score": 0,
"selected": false,
"text": "mate mate ."
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/33813",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3002/"
] |
33,814 |
<p>I'm writing a PHP script that involves scraping web pages. Currently, the script analyzes the page line by line, but it breaks if there is a tag that spans multiple lines, like </p>
<pre><code><img src="example.jpg"
alt="example">
</code></pre>
<p>If worse comes to worst, I could possibly preprocess the page by removing all line breaks, then re-inserting them at the closest <code>></code>, but this seems like a kludge.</p>
<p>Ideally, I'd be able to detect a tag that spans lines, conjoin only those to lines, and continue processing.<br>
So what's the best method to detect this?</p>
|
[
{
"answer_id": 34614,
"author": "Factor Mystic",
"author_id": 1569,
"author_profile": "https://Stackoverflow.com/users/1569",
"pm_score": 2,
"selected": true,
"text": "rstrpos for($i=0; $i<count($lines); $i++)\n{\n $line = handle_mulitline_tags(&$i, $line, $lines);\n}\n function rstrpos($string, $charToFind, $relativePos)\n{\n $searchPos = $relativePos;\n $searchChar = '';\n\n while (($searchChar != $charToFind)&&($searchPos>-1))\n {\n $newPos = $searchPos-1;\n $searchChar = substr($string,$newPos,strlen($charToFind));\n $searchPos = $newPos;\n }\n\n if (!empty($searchChar))\n {\n return $searchPos;\n return TRUE;\n }\n else\n {\n return FALSE;\n }\n}\n\nfunction handle_multiline_tags(&$i, $line, $lines)\n{\n //if a tag is opened but not closed before a line break,\n\n $open = rstrpos($line, '<', strlen($line));\n $close = rstrpos($line, '>', strlen($line));\n if(($open > $close)&&($open > -1)&&($close > -1))\n {\n $i++;\n return trim($line).trim(handle_multiline_tags(&$i, $lines[$i], $lines));\n }\n else\n {\n return trim($line);\n }\n}\n"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/33814",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1569/"
] |
33,822 |
<p>Every time I turn on my company-owned development machine, I have to kill 10+ processes using the Task Manager or any other process management app just to get decent performance out of my IDE. Yes, these are processes from programs that my company installs on my machine for security and compliance. What I'd like to do is have a .bat file or script of some kind with which I can kill the processes in question. </p>
<p>Does anybody know how to do this?</p>
|
[
{
"answer_id": 33828,
"author": "DevelopingChris",
"author_id": 1220,
"author_profile": "https://Stackoverflow.com/users/1220",
"pm_score": 7,
"selected": false,
"text": "taskkill /f /im \"devenv.exe\"\n"
},
{
"answer_id": 33831,
"author": "Factor Mystic",
"author_id": 1569,
"author_profile": "https://Stackoverflow.com/users/1569",
"pm_score": 9,
"selected": true,
"text": "taskkill /im somecorporateprocess.exe\n taskkill /f /im somecorporateprocess.exe\n"
},
{
"answer_id": 28273570,
"author": "npocmaka",
"author_id": 388389,
"author_profile": "https://Stackoverflow.com/users/388389",
"pm_score": 3,
"selected": false,
"text": "TSKILL processName\n TSKILL PID\n processName .exe WMIC wmic Path win32_process Where \"Caption Like 'MyProcess%.exe'\" Call Terminate\n wmic Path win32_process get %"
},
{
"answer_id": 40262412,
"author": "Sarath Subramanian",
"author_id": 3312636,
"author_profile": "https://Stackoverflow.com/users/3312636",
"pm_score": 1,
"selected": false,
"text": "taskkill /im applicationname.exe takskill taskkill tasklist /fi \"imagename eq applicationname.exe\" |find \":\" > nul\n\nif errorlevel 1 taskkill /f /im \"applicationname.exe\"\n"
},
{
"answer_id": 48756190,
"author": "Eduard Florinescu",
"author_id": 1577343,
"author_profile": "https://Stackoverflow.com/users/1577343",
"pm_score": 1,
"selected": false,
"text": "cmd chrome.exe FOR /F \"tokens=2 delims= \" %P IN ('tasklist /FO Table /M \"chrome*\" /NH') DO (TASKKILL /PID %P)\n PID tasklist TASKKILL /PID PID tasklist /FO Table /M \"chrome*\" /NH\n"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/33822",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3030/"
] |
33,829 |
<p>I have an application which <em>really</em> should be installed, but does work fine when deployed using JNLP.</p>
<p>However, it would seem that some Java functions such as <code>Runtime.exec</code> don't work using the default security options.</p>
<p>I would like to therefore <a href="http://www.joelonsoftware.com/items/2008/07/01.html" rel="nofollow noreferrer">disable</a> UI functionality that relies upon such functions. </p>
<p>So my question is, <strong>how do I detect at runtime whether certain functions are available or not?</strong></p>
<p>The case study, here of course, is <code>Runtime.exec</code>.</p>
|
[
{
"answer_id": 33851,
"author": "Frank Krueger",
"author_id": 338,
"author_profile": "https://Stackoverflow.com/users/338",
"pm_score": 1,
"selected": false,
"text": "<security>\n <all-permissions/>\n</security>\n Runtime.exec"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/33829",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/338/"
] |
33,836 |
<p>This is a follow on question to "<a href="https://stackoverflow.com/questions/33778/how-do-i-delete-1-file-from-a-revision-in-svn">How do I delete 1 file from a revision in SVN?</a>" but because it probably has a very different answer and I believe that others would benefit from knowing the answer. (I don't know the answer yet.)</p>
<p>The previous question was answered and I discovered that it is not possible to remove a revision from SVN. The second best solution was to remove the file from SVN, commit and then add the file back and commit again.</p>
<p>I now want to make sure that the original file's revision history has gone. So I am hoping that the answer to the question "<strong>How can I find the revision history of the file that was deleted and then resubmitted to SVN?</strong>" is that you can't.</p>
|
[
{
"answer_id": 33862,
"author": "Damien B",
"author_id": 3069,
"author_profile": "https://Stackoverflow.com/users/3069",
"pm_score": 3,
"selected": true,
"text": "svn log -v [folder]\n ------------------------------------------------------------------------\nr14 | kame | 2008-08-29 04:23:43 +0200 (ven., 29 aoû2008) | 1 line\nChemins modifié :\n A /a.txt\n\nReadded a\n------------------------------------------------------------------------\nr13 | kame | 2008-08-29 04:23:24 +0200 (ven., 29 aoû2008) | 1 line\nChemins modifié :\n D /a.txt\n\nDelete a\n------------------------------------------------------------------------\nr12 | kame | 2008-08-29 04:23:06 +0200 (ven., 29 aoû2008) | 1 line\nChemins modifié :\n A /a.txt\n"
},
{
"answer_id": 33874,
"author": "Jörg W Mittag",
"author_id": 2988,
"author_profile": "https://Stackoverflow.com/users/2988",
"pm_score": 2,
"selected": false,
"text": "svndumpfilter --drop-empty-revs --renumber-revs"
},
{
"answer_id": 33878,
"author": "AndrewR",
"author_id": 2994,
"author_profile": "https://Stackoverflow.com/users/2994",
"pm_score": 2,
"selected": false,
"text": "$ touch one\n$ svn add one\n$ svn ci -m \"Added file one\"\n$ date >> one \n$ svn ci -m \"Updated file one\"\n$ date >> one\n$ svn ci -m \"Updated file one again\"\n$ svn log file:///repos/one\n\n------------------------------------------------------------------------\nr3 | andrewr | 2008-08-29 12:27:10 +1000 (Fri, 29 Aug 2008) | 1 line\n\nUpdated file one again\n------------------------------------------------------------------------\nr2 | andrewr | 2008-08-29 12:26:50 +1000 (Fri, 29 Aug 2008) | 1 line\n\nUpdated file one\n------------------------------------------------------------------------\nr1 | andrewr | 2008-08-29 12:25:07 +1000 (Fri, 29 Aug 2008) | 1 line\n\nAdded file one\n------------------------------------------------------------------------\n\n$ svn delete one\n$ svn ci -m \"Deleted file one\"\n$ svn up\n$ touch one\n$ svn add one\n$ svn ci -m \"Adding file one back in\"\n$ svn log file:///repos/one\n\n------------------------------------------------------------------------\nr5 | andrewr | 2008-08-29 12:29:13 +1000 (Fri, 29 Aug 2008) | 1 line\n\nadd one back\n------------------------------------------------------------------------\n $ svn log -r 3:1 file:///repos/one\n\n------------------------------------------------------------------------\nr3 | andrewr | 2008-08-29 12:27:10 +1000 (Fri, 29 Aug 2008) | 1 line\n\nUpdated file one again\n------------------------------------------------------------------------\nr2 | andrewr | 2008-08-29 12:26:50 +1000 (Fri, 29 Aug 2008) | 1 line\n\nUpdated file one\n------------------------------------------------------------------------\nr1 | andrewr | 2008-08-29 12:25:07 +1000 (Fri, 29 Aug 2008) | 1 line\n\nAdded file one\n------------------------------------------------------------------------\n"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/33836",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1463/"
] |
33,837 |
<p>I have a page where there is a column and a content div, somewhat like this:</p>
<pre><code><div id="container">
<div id="content">blahblahblah</div>
<div id="column"> </div>
</div>
</code></pre>
<p>With some styling I have an image that is split between the column and the content but needs to maintain the same vertical positioning so that it lines up.</p>
<p>Styling is similar to this:</p>
<pre class="lang-css prettyprint-override"><code>#column
{
width:150px;
height:450px;
left:-150px;
bottom:-140px;
background:url(../images/image.png) no-repeat;
position:absolute;
z-index:1;
}
#container
{
background:transparent url(../images/container.png) no-repeat scroll left bottom;
position:relative;
width:100px;
}
</code></pre>
<p>This works great when content in <code>#content</code> is dynamically loaded before rendering. This also works great in firefox always. However, in IE6 and IE7 if I use javascript to change the content (and thus height) of <code>#content</code>, the images no longer line up (<code>#column</code> doesn't move). If I use IE Developer Bar to just update the div (say add position:absolute manually) the image jumps down and lines up again.</p>
<p>Is there something I am missing here?</p>
<p>@Ricky - Hmm, that means in this case there is no solution I think. At its best there will be a jaggedy matchup afterwards but as my content expands and contracts etc. hiding/showing doesn't work out to be practical. Still thanks for answering with the best solution.</p>
|
[
{
"answer_id": 33854,
"author": "Ricky",
"author_id": 653,
"author_profile": "https://Stackoverflow.com/users/653",
"pm_score": 3,
"selected": true,
"text": "var divCol = document.getElementById('column');\ndivCol.style.display = 'none';\ndivCol.style.display = 'block';\n"
},
{
"answer_id": 2073214,
"author": "tedL",
"author_id": 251706,
"author_profile": "https://Stackoverflow.com/users/251706",
"pm_score": 0,
"selected": false,
"text": "var divCol = document.getElementById('column');\ndivCol.style.zoom = '1';\ndivCol.style.zoom = '';\n"
},
{
"answer_id": 4237045,
"author": "Yousef Salimpour",
"author_id": 405316,
"author_profile": "https://Stackoverflow.com/users/405316",
"pm_score": 1,
"selected": false,
"text": "$(element).toggleClass('damn-you-ie')\n"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/33837",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/364/"
] |
33,852 |
<p>Most of time we represent concepts which can never be less than 0. For example to declare length, we write:</p>
<pre><code>int length;
</code></pre>
<p>The name expresses its purpose well but you can assign negative values to it. It seems that for some situations, you can represent your intent more clearly by writing it this way instead:</p>
<pre><code>uint length;
</code></pre>
<p>Some disadvantages that I can think of:</p>
<ul>
<li>unsigned types (uint, ulong, ushort) are not CLS compliant so you can't use it with other languages that don't support this</li>
<li>.Net classes use signed types most of the time so you have to cast</li>
</ul>
<p>Thoughts?</p>
|
[
{
"answer_id": 33858,
"author": "Dan Herbert",
"author_id": 392,
"author_profile": "https://Stackoverflow.com/users/392",
"pm_score": 3,
"selected": false,
"text": "int uint int long"
},
{
"answer_id": 34008,
"author": "Eric Burnett",
"author_id": 3524,
"author_profile": "https://Stackoverflow.com/users/3524",
"pm_score": 2,
"selected": false,
"text": "/checked unchecked length"
},
{
"answer_id": 34108,
"author": "Konrad Rudolph",
"author_id": 1968,
"author_profile": "https://Stackoverflow.com/users/1968",
"pm_score": 4,
"selected": true,
"text": "uints int"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/33852",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/718/"
] |
33,860 |
<p>In Ruby on Rails, I'm attempting to update the <code>innerHTML</code> of a div tag using the <code>form_remote_tag</code> helper. This update happens whenever an associated select tag receives an onchange event. The problem is, <code><select onchange="this.form.submit();"></code>; doesn't work. Nor does <code>document.forms[0].submit()</code>. The only way to get the onsubmit code generated in the form_remote_tag to execute is to create a hidden submit button, and invoke the click method on the button from the select tag. Here's a working ERb partial example.</p>
<pre><code><% form_remote_tag :url => product_path, :update => 'content', :method => 'get' do -%>
<% content_tag :div, :id => 'content' do -%>
<%= select_tag :update, options_for_select([["foo", 1], ["bar", 2]]), :onchange => "this.form.commit.click" %>
<%= submit_tag 'submit_button', :style => "display: none" %>
<% end %>
<% end %>
</code></pre>
<p>What I want to do is something like this, but it doesn't work.</p>
<pre><code><% form_remote_tag :url => product_path, :update => 'content', :method => 'get' do -%>
<% content_tag :div, :id => 'content' do -%>
# the following line does not work
<%= select_tag :update, options_for_select([["foo", 1], ["bar", 2]]), :onchange => "this.form.onsubmit()" %>
<% end %>
<% end %>
</code></pre>
<p>So, is there any way to remove the invisible submit button for this use case?</p>
<p>There seems to be some confusion. So, let me explain. The basic problem is that <code>submit()</code> doesn't call the <code>onsubmit()</code> code rendered into the form.</p>
<p>The actual HTML form that Rails renders from this ERb looks like this:</p>
<pre><code><form action="/products/1" method="post" onsubmit="new Ajax.Updater('content', '/products/1', {asynchronous:true, evalScripts:true, method:'get', parameters:Form.serialize(this)}); return false;">
<div style="margin:0;padding:0">
<input name="authenticity_token" type="hidden" value="4eacf78eb87e9262a0b631a8a6e417e9a5957cab" />
</div>
<div id="content">
<select id="update" name="update" onchange="this.form.commit.click">
<option value="1">foo</option>
<option value="2">bar</option>
</select>
<input name="commit" style="display: none" type="submit" value="submit_button" />
</div>
</form>
</code></pre>
<p>I want to axe the invisible submit button, but using a straight form.submit appears to not work. So, I need some way to call the form's onsubmit event code.</p>
<p>Update: Orion Edwards solution would work if there wasn't a <code>return(false);</code> generated by Rails. I'm not sure which is worse though, sending a phantom click to an invisible submit button or calling eval on the <code>getAttribute('onsubmit')</code> call after removing the return call with a javascript string replacement! </p>
|
[
{
"answer_id": 33879,
"author": "FlySwat",
"author_id": 1965,
"author_profile": "https://Stackoverflow.com/users/1965",
"pm_score": 2,
"selected": false,
"text": "id document.getElementById('formid').submit();\n div innerHTML"
},
{
"answer_id": 33941,
"author": "Orion Edwards",
"author_id": 234,
"author_profile": "https://Stackoverflow.com/users/234",
"pm_score": -1,
"selected": true,
"text": "var code = document.getElementById('formId').getAttribute('onsubmit');\neval(code);\n"
},
{
"answer_id": 33999,
"author": "John Millikin",
"author_id": 3560,
"author_profile": "https://Stackoverflow.com/users/3560",
"pm_score": 2,
"selected": false,
"text": "eval ('(function(){' + code + '})()');\n"
},
{
"answer_id": 34046,
"author": "hoyhoy",
"author_id": 3499,
"author_profile": "https://Stackoverflow.com/users/3499",
"pm_score": -1,
"selected": false,
"text": "eval ('function(){' + code + '}()'); onchange onsubmit onchange onchange"
},
{
"answer_id": 481682,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "onclick onsubmit submit"
},
{
"answer_id": 2466332,
"author": "ErikE",
"author_id": 57611,
"author_profile": "https://Stackoverflow.com/users/57611",
"pm_score": 3,
"selected": false,
"text": "document.getElementById('formId').onsubmit();\ndocument.getElementById('formId').submit();\n document.formName.onsubmit();\ndocument.formName.submit();\n alert(typeof document.formName.onsubmit); // function\n"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/33860",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3499/"
] |
33,881 |
<p>I always run into the same problem when creating web pages. When I add a font that is larger then about 16-18px it looks terrible. Its jagged, and pixelated. I have tried using different fonts and weights, however I haven't had much luck there. </p>
<p>Note: Its only in windows that it is like this. Mainly in Opera and FF also in IE7 but not quite as bad. In Linux the font looks good. I haven't looked at a Mac.</p>
<p>What do you guys do to fix this? if anything. I noticed that the titles here on SO are also pretty jagged but they are just small enough not to look bad. </p>
|
[
{
"answer_id": 316867,
"author": "Jack Ryan",
"author_id": 28882,
"author_profile": "https://Stackoverflow.com/users/28882",
"pm_score": 2,
"selected": true,
"text": "<style>\n h1\n {\n height: 32px;\n width: 100px;\n background: url(\"path/to/image\")\n }\n\n h1 span\n {\n display: none;\n }\n</style>\n\n<h1>\n <span>\n Heading Text\n <span>\n</h1>\n"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/33881",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1925/"
] |
33,893 |
<p>In my (PHP) web app, I have a part of my site that keeps a history of recent searches. The most recent queries get shown in a side box. If the query text is too long, I truncate it and show ellipses. Eg: "My very long query is..."</p>
<p>Currently, I truncate after a certain number of characters. Since the font is not monotype, a query of all I's is more narrow than a query of all W's. I'd like them to all be about the same width prior to the ellipses. Is there a way to get the approximate width of the resulting string so that the ellipses for any given string will occur in about the same number of pixels from the beginning? Does CSS have a way? Does PHP? Would this be better handled by JavaScript?</p>
|
[
{
"answer_id": 33899,
"author": "Orion Edwards",
"author_id": 234,
"author_profile": "https://Stackoverflow.com/users/234",
"pm_score": 2,
"selected": false,
"text": "div overflow: hidden .line_of_text {\n height:1.3em;\n line-height:1.3em;\n overflow:hidden;\n}\n\n<div class=\"line_of_text\"> Some long text which will arbitrarily be cut off at whatever word fits best</div>\n"
},
{
"answer_id": 33919,
"author": "Robert Groves",
"author_id": 3534,
"author_profile": "https://Stackoverflow.com/users/3534",
"pm_score": 4,
"selected": true,
"text": "<html>\n<head>\n\n<style>\ndiv.sidebox {\n width: 25%;\n}\n\ndiv.sidebox div.qrytxt {\n height: 1em;\n line-height: 1em;\n overflow: hidden;\n}\n\ndiv.sidebox div.qrytxt span.ellipsis {\n float: right;\n}\n</style>\n\n\n</head>\n\n<body>\n\n<div class=\"sidebox\">\n <div class=\"qrytxt\">\n <span class=\"ellipsis\">…</span>\n Some long text which will arbitrarily be cut off at whatever word fits best but will have an ellipsis at the end.\n </div>\n <div class=\"qrytxt\">\n <span class=\"ellipsis\">…</span>\n Some more long text which will arbitrarily be cut off at whatever word fits best but will have an ellipsis at the end.\n </div>\n <div class=\"qrytxt\">\n <span class=\"ellipsis\">…</span>\n Short text. Fail!\n </div>\n</body>\n\n</html>\n doctype display: inline-block .qrytxt <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n<html>\n<head>\n <style>\n div.sidebox \n {\n width: 25%;\n }\n\n div.sidebox div.qrytxt\n {\n height: 1em;\n line-height: 1em;\n overflow: hidden;\n display: inline-block;\n }\n\n div.sidebox div.qrytxt span.ellipsis\n {\n float: right;\n }\n</style>\n</head>\n\n<body>\n <div class=\"sidebox\">\n <div class=\"qrytxt\">\n <span class=\"ellipsis\">…</span>\n Some long text which will arbitrarily be cut off at whatever word fits best but will have an ellipsis at the end.\n </div>\n\n <div class=\"qrytxt\">\n <span class=\"ellipsis\">…</span>\n Some more long text which will arbitrarily be cut off at whatever word fits best but will have an ellipsis at the end.\n </div>\n\n <div class=\"qrytxt\">\n <span class=\"ellipsis\">…</span>\n Short text. FTW\n </div>\n </div>\n</body>\n</html>\n doctype display: inline-block .qrytxt <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n\n<html>\n<head>\n <style>\n div.sidebox \n {\n width: 26%;\n }\n\n div.sidebox div.qrytxt\n {\n height: 1em;\n line-height: 1em;\n overflow: hidden;\n text-overflow:ellipsis;\n -o-text-overflow:ellipsis;\n -ms-text-overflow:ellipsis;\n -moz-binding:url(ellipsis-xbl.xml#ellipsis);\n white-space:nowrap;\n }\n </style>\n</head>\n\n<body>\n <div class=\"sidebox\">\n <div class=\"qrytxt\">\n Some long text which will arbitrarily be cut off at whatever word fits best but will have an ellipsis at the end.\n </div>\n\n <div class=\"qrytxt\">\n Some more long text which will arbitrarily be cut off at whatever word fits best but will have an ellipsis at the end.\n </div>\n\n <div class=\"qrytxt\">\n Short text. FTW\n </div>\n </div>\n</body>\n</html>\n <?xml version=\"1.0\" encoding=\"UTF-8\"?>\n <bindings xmlns=\"http://www.mozilla.org/xbl\" xmlns:xbl=\"http://www.mozilla.org/xbl\" xmlns:xul=\"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul\">\n <binding id=\"ellipsis\">\n <content>\n <xul:window>\n <xul:description crop=\"end\" xbl:inherits=\"value=xbl:text\"><children/></xul:description>\n </xul:window>\n </content>\n </binding>\n </bindings>\n"
},
{
"answer_id": 33942,
"author": "Jiaaro",
"author_id": 2908,
"author_profile": "https://Stackoverflow.com/users/2908",
"pm_score": 2,
"selected": false,
"text": "z-index"
},
{
"answer_id": 43472,
"author": "Evil Andy",
"author_id": 4431,
"author_profile": "https://Stackoverflow.com/users/4431",
"pm_score": 2,
"selected": false,
"text": "document.getElementByID(\"qrytxt\").offsetWidth;\n"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/33893",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/356/"
] |
33,923 |
<p>Whilst starting to learn lisp, I've come across the term <em>tail-recursive</em>. What does it mean exactly?</p>
|
[
{
"answer_id": 33929,
"author": "Peter Meyer",
"author_id": 1875,
"author_profile": "https://Stackoverflow.com/users/1875",
"pm_score": 6,
"selected": false,
"text": "factorial(x, fac=1) {\n if (x == 1)\n return fac;\n else\n return factorial(x-1, x*fac);\n}\n factorial(n) fac=1"
},
{
"answer_id": 33930,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 10,
"selected": false,
"text": "(return (recursive-function params))"
},
{
"answer_id": 33931,
"author": "Kyle Cronin",
"author_id": 658,
"author_profile": "https://Stackoverflow.com/users/658",
"pm_score": 6,
"selected": false,
"text": "(define (factorial x)\n (if (= x 0) 1\n (* x (factorial (- x 1)))))\n (define factorial\n (letrec ((fact (lambda (x accum)\n (if (= x 0) accum\n (fact (- x 1) (* accum x))))))\n (lambda (x)\n (fact x 1))))\n"
},
{
"answer_id": 34540,
"author": "Hoffmann",
"author_id": 3485,
"author_profile": "https://Stackoverflow.com/users/3485",
"pm_score": 7,
"selected": false,
"text": "g function f (x)\n return g(x)\nend\n f g function foo (n)\n if n > 0 then return foo(n - 1) end\nend\n function room1 ()\n local move = io.read()\n if move == \"south\" then return room3()\n elseif move == \"east\" then return room2()\n else print(\"invalid move\")\n return room1() -- stay in the same room\n end\nend\n\nfunction room2 ()\n local move = io.read()\n if move == \"south\" then return room4()\n elseif move == \"west\" then return room1()\n else print(\"invalid move\")\n return room2()\n end\nend\n\nfunction room3 ()\n local move = io.read()\n if move == \"north\" then return room1()\n elseif move == \"east\" then return room4()\n else print(\"invalid move\")\n return room3()\n end\nend\n\nfunction room4 ()\n print(\"congratulations!\")\nend\n function x(n)\n if n==0 then return 0\n n= n-2\n return x(n) + 1\nend\n"
},
{
"answer_id": 36985,
"author": "Chris Conway",
"author_id": 1412,
"author_profile": "https://Stackoverflow.com/users/1412",
"pm_score": 8,
"selected": false,
"text": "while(E) { S }; return Q\n E Q S f() = if E then { S; return f() } else { return Q }\n E S Q sum(n) {\n int i = 1, k = 0;\n while( i <= n ) {\n k += i;\n ++i;\n }\n return k;\n}\n sum_aux(n,i,k) {\n if( i <= n ) {\n return sum_aux(n,i+1,k+i);\n } else {\n return k;\n }\n}\n\nsum(n) {\n return sum_aux(n,1,0);\n}\n"
},
{
"answer_id": 37010,
"author": "Lorin Hochstein",
"author_id": 742,
"author_profile": "https://Stackoverflow.com/users/742",
"pm_score": 12,
"selected": true,
"text": "sum(5) = 0 + 1 + 2 + 3 + 4 + 5 = 15 function recsum(x) {\n if (x === 0) {\n return 0;\n } else {\n return x + recsum(x - 1);\n }\n}\n recsum(5) recsum(5)\n5 + recsum(4)\n5 + (4 + recsum(3))\n5 + (4 + (3 + recsum(2)))\n5 + (4 + (3 + (2 + recsum(1))))\n5 + (4 + (3 + (2 + (1 + recsum(0)))))\n5 + (4 + (3 + (2 + (1 + 0))))\n5 + (4 + (3 + (2 + 1)))\n5 + (4 + (3 + 3))\n5 + (4 + 6)\n5 + 10\n15\n function tailrecsum(x, running_total = 0) {\n if (x === 0) {\n return running_total;\n } else {\n return tailrecsum(x - 1, running_total + x);\n }\n}\n tailrecsum(5) tailrecsum(5, 0) tailrecsum(5, 0)\ntailrecsum(4, 5)\ntailrecsum(3, 9)\ntailrecsum(2, 12)\ntailrecsum(1, 14)\ntailrecsum(0, 15)\n15\n running_total"
},
{
"answer_id": 39604,
"author": "magice",
"author_id": 227049,
"author_profile": "https://Stackoverflow.com/users/227049",
"pm_score": 3,
"selected": false,
"text": "(define (un-ended name)\n (un-ended 'me)\n (print \"How can I get here?\"))\n (define (un-ended name)\n (print \"hello\")\n (un-ended 'me))\n (define (map lst op)\n (define (helper done left)\n (if (nil? left)\n done\n (helper (cons (op (car left))\n done)\n (cdr left))))\n (reverse (helper '() lst)))\n"
},
{
"answer_id": 159975,
"author": "Brad Gilbert",
"author_id": 1337,
"author_profile": "https://Stackoverflow.com/users/1337",
"pm_score": 3,
"selected": false,
"text": "tailrecsum sub tail_rec_sum($;$){\n my( $x,$running_total ) = (@_,0);\n\n return $running_total unless $x;\n\n @_ = ($x-1,$running_total+$x);\n goto &tail_rec_sum; # throw away current stack frame\n}\n"
},
{
"answer_id": 202904,
"author": "jorgetown",
"author_id": 7465,
"author_profile": "https://Stackoverflow.com/users/7465",
"pm_score": 4,
"selected": false,
"text": "public int tailRecursive(final int n) {\n if (n <= 2)\n return 1;\n return tailRecursiveAux(n, 1, 1);\n}\n\nprivate int tailRecursiveAux(int n, int iter, int acc) {\n if (iter == n)\n return acc;\n return tailRecursiveAux(n, ++iter, acc + iter);\n}\n public int recursive(final int n) {\n if (n <= 2)\n return 1;\n return recursive(n - 1) + recursive(n - 2);\n}\n"
},
{
"answer_id": 4483714,
"author": "AbuZubair",
"author_id": 547780,
"author_profile": "https://Stackoverflow.com/users/547780",
"pm_score": 5,
"selected": false,
"text": "public static int factorial(int mynumber) {\n if (mynumber == 1) {\n return 1;\n } else { \n return mynumber * factorial(--mynumber);\n }\n}\n\npublic static int tail_factorial(int mynumber, int sofar) {\n if (mynumber == 1) {\n return sofar;\n } else {\n return tail_factorial(--mynumber, sofar * mynumber);\n }\n}\n"
},
{
"answer_id": 9652860,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "(defun ! (n &optional (product 1))\n (if (zerop n) product\n (! (1- n) (* product n))))\n (format nil \"~R\" (! 25))"
},
{
"answer_id": 34394967,
"author": "Abhiroop Sarkar",
"author_id": 1942289,
"author_profile": "https://Stackoverflow.com/users/1942289",
"pm_score": 5,
"selected": false,
"text": "tail call recursion def recsum(x):\n if x == 1:\n return x\n else:\n return x + recsum(x - 1)\n def tailrecsum(x, running_total=0):\n if x == 0:\n return running_total\n else:\n return tailrecsum(x - 1, running_total + x)\n x + recsum(x - 1) recsum x + .. tailrecsum(x - 1, running_total + x)"
},
{
"answer_id": 40498100,
"author": "justyy",
"author_id": 1479619,
"author_profile": "https://Stackoverflow.com/users/1479619",
"pm_score": 3,
"selected": false,
"text": "function N(x, p) {\n return x == 1 ? p : N(x - 1, p * x);\n}\n function N(x) {\n return x == 1 ? 1 : x * N(x - 1);\n}\n function F(x) {\n if (x == 1) return 0;\n if (x == 2) return 1;\n return F(x - 1) + F(x - 2);\n}\n"
},
{
"answer_id": 44924202,
"author": "pnkfelix",
"author_id": 36585,
"author_profile": "https://Stackoverflow.com/users/36585",
"pm_score": 2,
"selected": false,
"text": "(if E0 E1 E2) E1 E2"
},
{
"answer_id": 47952480,
"author": "coding_ninza",
"author_id": 8295641,
"author_profile": "https://Stackoverflow.com/users/8295641",
"pm_score": 3,
"selected": false,
"text": " factorial(n):\n\n if n==0 then 1\n\n else n*factorial(n-1)\n factorial(4)\n / \\\n 4 factorial(3)\n / \\\n 3 factorial(2)\n / \\\n 2 factorial(1)\n / \\\n1 factorial(0)\n \\\n 1 \n factAux(m,n):\nif n==0 then m;\nelse factAux(m*n,n-1);\n\nfactTail(n):\n return factAux(1,n);\n factTail(4)\n |\nfactAux(1,4)\n |\nfactAux(4,3)\n |\nfactAux(12,2)\n |\nfactAux(24,1)\n |\nfactAux(24,0)\n |\n 24\n"
},
{
"answer_id": 54573509,
"author": "Nursnaaz",
"author_id": 6949469,
"author_profile": "https://Stackoverflow.com/users/6949469",
"pm_score": 4,
"selected": false,
"text": "public static int fact(int n){\n if(n <=1)\n return 1;\n else \n return n * fact(n-1);\n}\n if(n <=1)\n return 1;\n else \n return n * fact(n-1);\n fact(4) public static int fact(4){\n if(4 <=1)\n return 1;\n else \n return 4 * fact(4-1);\n}\n If else 4 * fact(3) 4 * fact(3) public static int fact(3){\n if(3 <=1)\n return 1;\n else \n return 3 * fact(3-1);\n}\n If else 3 * fact(2) fact(3) = 3 * fact(2) 4 * fact(3) = 4 * 3 * fact(2) 4 * 3 * fact(2) public static int fact(2){\n if(2 <=1)\n return 1;\n else \n return 2 * fact(2-1);\n}\n If else 2 * fact(1) 4 * 3 * fact(2) fact(2) = 2 * fact(1) 4 * 3 * fact(2) = 4 * 3 * 2 * fact(1) 4 * 3 * 2 * fact(1) public static int fact(1){\n if(1 <=1)\n return 1;\n else \n return 1 * fact(1-1);\n}\n If 1 4 * 3 * 2 * fact(1) fact(1) = 1 4 * 3 * 2 * fact(1) = 4 * 3 * 2 * 1 public static int fact(x, running_total=1) {\n if (x==1) {\n return running_total;\n } else {\n return fact(x-1, running_total*x);\n }\n}\n\n public static int fact(4, running_total=1) {\n if (x==1) {\n return running_total;\n } else {\n return fact(4-1, running_total*4);\n }\n}\n If else fact(3, 4) fact(3, 4) public static int fact(3, running_total=4) {\n if (x==1) {\n return running_total;\n } else {\n return fact(3-1, 4*3);\n }\n}\n If else fact(2, 12) fact(2, 12) public static int fact(2, running_total=12) {\n if (x==1) {\n return running_total;\n } else {\n return fact(2-1, 12*2);\n }\n}\n If else fact(1, 24) fact(1, 24) public static int fact(1, running_total=24) {\n if (x==1) {\n return running_total;\n } else {\n return fact(1-1, 24*1);\n }\n}\n If running_total running_total = 24"
},
{
"answer_id": 54601924,
"author": "Al Sweigart",
"author_id": 1893164,
"author_profile": "https://Stackoverflow.com/users/1893164",
"pm_score": 3,
"selected": false,
"text": "def recursiveFunction(some_params):\n # some code here\n return recursiveFunction(some_args)\n # no code after the return statement\n def factorial(number):\n if number == 1:\n # BASE CASE\n return 1\n else:\n # RECURSIVE CASE\n # Note that `number *` happens *after* the recursive call.\n # This means that this is *not* tail call recursion.\n return number * factorial(number - 1)\n def factorial(number, accumulator=1):\n if number == 0:\n # BASE CASE\n return accumulator\n else:\n # RECURSIVE CASE\n # There's no code after the recursive call.\n # This is tail call recursion:\n return factorial(number - 1, number * accumulator)\nprint(factorial(5))\n accumulator"
},
{
"answer_id": 64956968,
"author": "Hari",
"author_id": 216562,
"author_profile": "https://Stackoverflow.com/users/216562",
"pm_score": 2,
"selected": false,
"text": "g(a, b, n) = a * b^n\n g(a, b, n) | n is zero = a\n | n is odd = g(a*b, b, n-1)\n | otherwise = g(a, b*b, n/2)\n g(...) g(...) g'(a, b, n) = a * f(b, n)\nf(b, n) | n is zero = 1\n | n is odd = f(b, n-1) * b\n | otherwise = f(b, n/2) ^ 2\n f(...) g' g"
},
{
"answer_id": 71566598,
"author": "Yilmaz",
"author_id": 10262805,
"author_profile": "https://Stackoverflow.com/users/10262805",
"pm_score": 3,
"selected": false,
"text": "O(n) O(N)=>O(1)\n function Factorial(x) {\n //Base case x<=1\n if (x <= 1) {\n return 1;\n } else {\n // x is waiting for the return value of Factorial(x-1)\n // the last thing we do is NOT applying the recursive call\n // after recursive call we still have to multiply.\n return x * Factorial(x - 1);\n }\n}\n Factorial(4); // waiting in the memory for Factorial(3)\n4 * Factorial(3); // waiting in the memory for Factorial(2)\n4 * (3 * Factorial(2)); // waiting in the memory for Factorial(1)\n4 * (3 * (2 * Factorial(1)));\n4 * (3 * (2 * 1));\n function tailFactorial(x, totalSoFar = 1) {\n //Base Case: x===0. In recursion there must be base case. Otherwise they will never stop\n if (x === 0) {\n return totalSoFar;\n } else {\n // there is nothing waiting for tailFactorial to complete. we are returning another instance of tailFactorial()\n // we are not doing any additional computaion with what we get back from this recursive call\n return tailFactorial(x - 1, totalSoFar * x);\n }\n}\n"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/33923",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2045/"
] |
33,933 |
<p>I have the following <code>textarea</code> in a <code>table</code>:</p>
<pre><code><table width="300"><tr><td>
<textarea style="width:100%">
longstringlongstringlongstringlongstringlongstringlongstringlongstringlongstringlongstringlongstringlongstringlongstringlongstring
</textarea>
</td></tr></table>
</code></pre>
<p>With a long string in the textarea, the textarea stretches out to accommodate it in one line in IE7, but retains its 300px width in other browsers.</p>
<p>Any ideas as to how to fix this in IE?</p>
|
[
{
"answer_id": 33936,
"author": "Jiaaro",
"author_id": 2908,
"author_profile": "https://Stackoverflow.com/users/2908",
"pm_score": 0,
"selected": false,
"text": "overflow: hidden;"
},
{
"answer_id": 33938,
"author": "Peter Meyer",
"author_id": 1875,
"author_profile": "https://Stackoverflow.com/users/1875",
"pm_score": 0,
"selected": false,
"text": "overflow: scroll;\n <DIV> <TD> <TABLE> overflow: scroll"
},
{
"answer_id": 33947,
"author": "travis",
"author_id": 1414,
"author_profile": "https://Stackoverflow.com/users/1414",
"pm_score": 0,
"selected": false,
"text": "word-break"
},
{
"answer_id": 33948,
"author": "dansays",
"author_id": 1923,
"author_profile": "https://Stackoverflow.com/users/1923",
"pm_score": 3,
"selected": false,
"text": "td table td {\n width: 300px;\n}\n $('textarea[width=100%]').parent('td').css('width', '300px');\n"
},
{
"answer_id": 33951,
"author": "seanb",
"author_id": 3354,
"author_profile": "https://Stackoverflow.com/users/3354",
"pm_score": 0,
"selected": false,
"text": "<div style=\"width:300px; overflow:auto;\">"
},
{
"answer_id": 35568,
"author": "seanb",
"author_id": 3354,
"author_profile": "https://Stackoverflow.com/users/3354",
"pm_score": 1,
"selected": false,
"text": "style=\"width:100%;width:expression(this.parentNode.parentNode.parentNode.parentNode.width +'px')\" \n"
},
{
"answer_id": 450690,
"author": "John Dunagan",
"author_id": 28939,
"author_profile": "https://Stackoverflow.com/users/28939",
"pm_score": 0,
"selected": false,
"text": "<table width='300'"
},
{
"answer_id": 594697,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "<table style=\"width:100%;table-layout:fixed\"><tr><td>\n<textarea style=\"width:100%\">longstringlongstringlongstringlongstringlongstringlongstringlongstringlongstringlongstringlongstringlongstringlongstringlongstring</textarea>\n</td></tr></table>\n"
},
{
"answer_id": 13009054,
"author": "Saeed",
"author_id": 1726377,
"author_profile": "https://Stackoverflow.com/users/1726377",
"pm_score": 0,
"selected": false,
"text": "overflow:hidden\n"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/33933",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2749/"
] |
33,956 |
<p>Assume that I have a field called <em>price</em> for the documents in Solr and I have that field faceted. I want to get the facets as ranges of values (eg: 0-100, 100-500, 500-1000, etc). How to do it?</p>
<p>I can specify the ranges beforehand, but I also want to know whether it is possible to calculate the ranges (say for 5 values) automatically based on the values in the documents?</p>
|
[
{
"answer_id": 34027,
"author": "erickson",
"author_id": 3474,
"author_profile": "https://Stackoverflow.com/users/3474",
"pm_score": 2,
"selected": false,
"text": "Filter FilteredQuery Query FieldCache"
},
{
"answer_id": 170477,
"author": "Mauricio Scheffer",
"author_id": 21239,
"author_profile": "https://Stackoverflow.com/users/21239",
"pm_score": 4,
"selected": false,
"text": "http://localhost:8983/solr/select?q=video&rows=0&facet=true&facet.query=price:[*+TO+500]&facet.query=price:[500+TO+*]\n"
},
{
"answer_id": 11329853,
"author": "Graham",
"author_id": 130988,
"author_profile": "https://Stackoverflow.com/users/130988",
"pm_score": 3,
"selected": false,
"text": " public static decimal RoundPrice(decimal price)\n {\n if (price < 25)\n return Math.Ceiling(price);\n else if (price < 100)\n return Math.Ceiling(price / 5) * 5;\n else if (price < 250)\n return Math.Ceiling(price / 10) * 10;\n else if (price < 1000)\n return Math.Ceiling(price / 25) * 25;\n else if (price < 2500)\n return Math.Ceiling(price / 100) * 100;\n else if (price < 10000)\n return Math.Ceiling(price / 250) * 250;\n else if (price < 25000)\n return Math.Ceiling(price / 1000) * 1000;\n else if (price < 100000)\n return Math.Ceiling(price / 2500) * 2500;\n else\n return Math.Ceiling(price / 5000) * 5000;\n }\n facet.field=rounded_price public static List<Tuple<string, string, int>> CombinePriceFacets(int nSegments, ICollection<KeyValuePair<string, int>> prices)\n {\n var ranges = new List<Tuple<string, string, int>>();\n int productCount = prices.Sum(p => p.Value);\n int productsRemaining = productCount;\n if (nSegments < 2)\n return ranges;\n int segmentSize = productCount / nSegments;\n string start = \"*\";\n string end = \"0\";\n int count = 0;\n int totalCount = 0;\n int segmentIdx = 1;\n foreach (KeyValuePair<string, int> price in prices)\n {\n end = price.Key;\n count += price.Value;\n totalCount += price.Value;\n productsRemaining -= price.Value;\n if (totalCount >= segmentSize * segmentIdx)\n {\n ranges.Add(new Tuple<string, string, int>(start, end, count));\n start = end;\n count = 0;\n segmentIdx += 1;\n }\n if (segmentIdx == nSegments)\n {\n ranges.Add(new Tuple<string, string, int>(start, \"*\", count + productsRemaining));\n break;\n }\n }\n return ranges;\n }\n fq=price:[250 TO 500]"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/33956",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1448/"
] |
33,969 |
<p>We're experimenting with various ways to throttle user actions in a <strong>given time period</strong>:</p>
<ul>
<li>Limit question/answer posts</li>
<li>Limit edits</li>
<li>Limit feed retrievals</li>
</ul>
<p>For the time being, we're using the Cache to simply insert a record of user activity - if that record exists if/when the user does the same activity, we throttle.</p>
<p>Using the Cache automatically gives us stale data cleaning and sliding activity windows of users, but how it will scale could be a problem.</p>
<p>What are some other ways of ensuring that requests/user actions can be effectively throttled (emphasis on stability)?</p>
|
[
{
"answer_id": 584689,
"author": "notandy",
"author_id": 4221,
"author_profile": "https://Stackoverflow.com/users/4221",
"pm_score": 6,
"selected": false,
"text": "X requests in Y milliseconds X concurrent connections in Y milliseconds Y milliseconds"
},
{
"answer_id": 1318059,
"author": "Jarrod Dixon",
"author_id": 3,
"author_profile": "https://Stackoverflow.com/users/3",
"pm_score": 9,
"selected": true,
"text": "/// <summary>\n/// Decorates any MVC route that needs to have client requests limited by time.\n/// </summary>\n/// <remarks>\n/// Uses the current System.Web.Caching.Cache to store each client request to the decorated route.\n/// </remarks>\n[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]\npublic class ThrottleAttribute : ActionFilterAttribute\n{\n /// <summary>\n /// A unique name for this Throttle.\n /// </summary>\n /// <remarks>\n /// We'll be inserting a Cache record based on this name and client IP, e.g. \"Name-192.168.0.1\"\n /// </remarks>\n public string Name { get; set; }\n\n /// <summary>\n /// The number of seconds clients must wait before executing this decorated route again.\n /// </summary>\n public int Seconds { get; set; }\n\n /// <summary>\n /// A text message that will be sent to the client upon throttling. You can include the token {n} to\n /// show this.Seconds in the message, e.g. \"Wait {n} seconds before trying again\".\n /// </summary>\n public string Message { get; set; }\n\n public override void OnActionExecuting(ActionExecutingContext c)\n {\n var key = string.Concat(Name, \"-\", c.HttpContext.Request.UserHostAddress);\n var allowExecute = false;\n\n if (HttpRuntime.Cache[key] == null)\n {\n HttpRuntime.Cache.Add(key,\n true, // is this the smallest data we can have?\n null, // no dependencies\n DateTime.Now.AddSeconds(Seconds), // absolute expiration\n Cache.NoSlidingExpiration,\n CacheItemPriority.Low,\n null); // no callback\n\n allowExecute = true;\n }\n\n if (!allowExecute)\n {\n if (String.IsNullOrEmpty(Message))\n Message = \"You may only perform this action every {n} seconds.\";\n\n c.Result = new ContentResult { Content = Message.Replace(\"{n}\", Seconds.ToString()) };\n // see 409 - http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html\n c.HttpContext.Response.StatusCode = (int)HttpStatusCode.Conflict;\n }\n }\n}\n [Throttle(Name=\"TestThrottle\", Message = \"You must wait {n} seconds before accessing this url again.\", Seconds = 5)]\npublic ActionResult TestThrottle()\n{\n return Content(\"TestThrottle executed\");\n}\n"
},
{
"answer_id": 71646995,
"author": "JsAndDotNet",
"author_id": 852806,
"author_profile": "https://Stackoverflow.com/users/852806",
"pm_score": 2,
"selected": false,
"text": "Microsoft.Extensions.Caching.Memory using Microsoft.Extensions.Caching.Memory;\nusing Microsoft.Extensions.Primitives;\nusing System;\nusing System.Threading;\n\nnamespace MyWebApplication\n{\n public interface IThrottleCache\n {\n bool AddToCache(string key, int expriryTimeInSeconds);\n\n bool AddToCache<T>(string key, T value, int expriryTimeInSeconds);\n\n T GetFromCache<T>(string key);\n\n bool IsInCache(string key);\n }\n\n /// <summary>\n /// A caching class, based on the docs\n /// https://learn.microsoft.com/en-us/aspnet/core/performance/caching/memory?view=aspnetcore-6.0\n /// Uses the recommended library \"Microsoft.Extensions.Caching.Memory\"\n /// </summary>\n public class ThrottleCache : IThrottleCache\n {\n private IMemoryCache _memoryCache;\n\n public ThrottleCache(IMemoryCache memoryCache)\n {\n _memoryCache = memoryCache;\n }\n\n\n public bool AddToCache(string key, int expriryTimeInSeconds)\n {\n bool isSuccess = false; // Only a success if a new value gets added.\n\n if (!IsInCache(key))\n {\n var cancellationTokenSource = new CancellationTokenSource(\n TimeSpan.FromSeconds(expriryTimeInSeconds));\n\n var cacheEntryOptions = new MemoryCacheEntryOptions()\n .SetSize(1)\n .AddExpirationToken(\n new CancellationChangeToken(cancellationTokenSource.Token));\n\n _memoryCache.Set(key, DateTime.Now, cacheEntryOptions);\n\n isSuccess = true;\n }\n\n return isSuccess;\n }\n\n\n public bool AddToCache<T>(string key, T value, int expriryTimeInSeconds)\n {\n bool isSuccess = false;\n\n if (!IsInCache(key))\n {\n var cancellationTokenSource = new CancellationTokenSource(\n TimeSpan.FromSeconds(expriryTimeInSeconds));\n\n var cacheEntryOptions = new MemoryCacheEntryOptions()\n .SetAbsoluteExpiration(DateTimeOffset.Now.AddSeconds(expriryTimeInSeconds))\n .SetSize(1)\n .AddExpirationToken(\n new CancellationChangeToken(cancellationTokenSource.Token));\n\n _memoryCache.Set<T>(key, value, cacheEntryOptions);\n\n isSuccess = true;\n }\n\n return isSuccess;\n }\n\n\n public T GetFromCache<T>(string key)\n {\n return _memoryCache.Get<T>(key);\n }\n\n\n public bool IsInCache(string key)\n {\n var item = _memoryCache.Get(key);\n\n return item != null;\n }\n\n\n }\n}\n using Microsoft.AspNetCore.Mvc;\nusing Microsoft.AspNetCore.Mvc.Filters;\nusing System;\nusing System.Net;\n\nnamespace MyWebApplication\n{\n /// <summary>\n /// Decorates any MVC route that needs to have client requests limited by time.\n /// Based on how they throttle at stack overflow (updated for .NET5+)\n /// https://stackoverflow.com/questions/33969/best-way-to-implement-request-throttling-in-asp-net-mvc/1318059#1318059\n /// </summary>\n /// <remarks>\n /// Uses the current System.Web.Caching.Cache to store each client request to the decorated route.\n /// </remarks>\n [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]\n public class ThrottleByIPAddressAttribute : ActionFilterAttribute\n {\n /// <summary>\n /// The caching class (which will be instantiated as a singleton)\n /// </summary>\n private IThrottleCache _throttleCache;\n\n\n /// <summary>\n /// A unique name for this Throttle.\n /// </summary>\n /// <remarks>\n /// We'll be inserting a Cache record based on this name and client IP, e.g. \"Name-192.168.0.1\"\n /// </remarks>\n public string Name { get; set; }\n\n /// <summary>\n /// The number of seconds clients must wait before executing this decorated route again.\n /// </summary>\n public int Seconds { get; set; }\n\n /// <summary>\n /// A text message that will be sent to the client upon throttling. You can include the token {n} to\n /// show this.Seconds in the message, e.g. \"Wait {n} seconds before trying again\".\n /// </summary>\n public string Message { get; set; } = \"You may only perform this action every {n} seconds.\";\n\n public override void OnActionExecuting(ActionExecutingContext c)\n {\n if(_throttleCache == null)\n {\n var cache = c.HttpContext.RequestServices.GetService(typeof(IThrottleCache));\n _throttleCache = (IThrottleCache)cache;\n }\n \n var key = string.Concat(Name, \"-\", c.HttpContext.Request.HttpContext.Connection.RemoteIpAddress);\n\n var allowExecute = _throttleCache.AddToCache(key, Seconds);\n\n\n if (!allowExecute)\n {\n if (String.IsNullOrEmpty(Message))\n Message = \"You may only perform this action every {n} seconds.\";\n\n c.Result = new ContentResult { Content = Message.Replace(\"{n}\", Seconds.ToString()) };\n // see 409 - http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html\n c.HttpContext.Response.StatusCode = (int)HttpStatusCode.Conflict;\n }\n }\n }\n}\n AddControllersWithViews builder.Services.AddRazorPages(); var app = builder.Build(); services builder.Services // The cache for throttling must be a singleton and requires IMemoryCache to be set up.\n// Place it after AddControllersWithViews or AddRazorPages as they build a cache themselves\n\n// Need this for IThrottleCache to work.\nservices.AddMemoryCache(_ => new MemoryCacheOptions\n{\n SizeLimit = 1024, /* TODO: CHECK THIS IS THIS THE RIGHT SIZE FOR YOU! */\n CompactionPercentage = .3,\n ExpirationScanFrequency = TimeSpan.FromSeconds(30),\n});\nservices.AddSingleton<IThrottleCache, ThrottleCache>();\n [HttpGet, Route(\"GetTest\")]\n[ThrottleByIPAddress(Name = \"MyControllerGetTest\", Seconds = 5)]\npublic async Task<ActionResult<string>> GetTest()\n{\n return \"Hello world\";\n}\n"
},
{
"answer_id": 72008712,
"author": "prem",
"author_id": 3085520,
"author_profile": "https://Stackoverflow.com/users/3085520",
"pm_score": 1,
"selected": false,
"text": "Microsoft has discontinued the Dynamic IP Restrictions extension and this download is no longer available.\n"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/33969",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3/"
] |
33,978 |
<p>How would you go about finding out how much memory is being used by an object? I know it is possible to find out how much is used by a block of code, but not by an instantiated object (anytime during its life), which is what I want. </p>
|
[
{
"answer_id": 19865746,
"author": "Uzer",
"author_id": 1732607,
"author_profile": "https://Stackoverflow.com/users/1732607",
"pm_score": 8,
"selected": false,
"text": "sys.getsizeof(object)\n __sizeof__"
},
{
"answer_id": 20906366,
"author": "rafaelvalle",
"author_id": 3038791,
"author_profile": "https://Stackoverflow.com/users/3038791",
"pm_score": 3,
"selected": false,
"text": ">>> mfcc = MelFrequencyCepstrum(filepath, params)\n>>> data = mfcc.X[:]\n>>> sys.getsizeof(mfcc)\n64\n>>> sys.getsizeof(mfcc.X)\n>>>80\n>>> sys.getsizeof(data)\n80\n>>> mfcc\n<bregman.features.MelFrequencyCepstrum object at 0x104ad3e90>\n"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/33978",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3119/"
] |
34,015 |
<p>How can you allow a PHP script to write to a file with high-security restrictions, such as only allowing a single user to write to it?</p>
<p>The difficulty seems to be that a PHP script is running as a low-permissions user (maybe apache, or www, or nobody?), and even if I <code>chown</code> apache the_writable_file, the directory it's in might not be writable for the low-level user. In general, what's the usual way that PHP can work with local files in a secure way?</p>
|
[
{
"answer_id": 34018,
"author": "hoyhoy",
"author_id": 3499,
"author_profile": "https://Stackoverflow.com/users/3499",
"pm_score": 0,
"selected": false,
"text": "chgrp apache the_writable_file chmod g+w the_writable_file"
},
{
"answer_id": 34058,
"author": "Jiaaro",
"author_id": 2908,
"author_profile": "https://Stackoverflow.com/users/2908",
"pm_score": 0,
"selected": false,
"text": "/foo/bar/the_writable_file"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/34015",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3561/"
] |
34,020 |
<p>A reliable coder friend told me that Python's current multi-threading implementation is seriously buggy - enough to avoid using altogether. What can said about this rumor?</p>
|
[
{
"answer_id": 34078,
"author": "Daren Thomas",
"author_id": 2260,
"author_profile": "https://Stackoverflow.com/users/2260",
"pm_score": 3,
"selected": false,
"text": "processing import multiprocessing"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/34020",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3561/"
] |
34,065 |
<p>Given the key for some registry value (e.g. HKEY_LOCAL_MACHINE\blah\blah\blah\foo) how can I:</p>
<ol>
<li>Safely determine that such a key exists.</li>
<li>Programmatically (i.e. with code) get its value.</li>
</ol>
<p>I have absolutely no intention of writing anything back to the registry (for the duration of my career if I can help it). So we can skip the lecture about every molecule in my body exploding at the speed of light if I write to the registry incorrectly. </p>
<p>Prefer answers in C++, but mostly just need to know what the special Windows API incantation to get at the value is.</p>
|
[
{
"answer_id": 34082,
"author": "Gishu",
"author_id": 1695,
"author_profile": "https://Stackoverflow.com/users/1695",
"pm_score": 3,
"selected": false,
"text": "const CString REG_SW_GROUP_I_WANT = _T(\"SOFTWARE\\\\My Corporation\\\\My Package\\\\Group I want\");\nconst CString REG_KEY_I_WANT= _T(\"Key Name\");\n\nCRegKey regKey;\nDWORD dwValue = 0;\n\nif(ERROR_SUCCESS != regKey.Open(HKEY_LOCAL_MACHINE, REG_SW_GROUP_I_WANT))\n{\n m_pobLogger->LogError(_T(\"CRegKey::Open failed in Method\"));\n regKey.Close();\n goto Function_Exit;\n}\nif( ERROR_SUCCESS != regKey.QueryValue( dwValue, REG_KEY_I_WANT))\n{\n m_pobLogger->LogError(_T(\"CRegKey::QueryValue Failed in Method\"));\n regKey.Close();\n goto Function_Exit;\n}\n\n// dwValue has the stuff now - use for further processing\n"
},
{
"answer_id": 35717,
"author": "Brian R. Bondy",
"author_id": 3153,
"author_profile": "https://Stackoverflow.com/users/3153",
"pm_score": 7,
"selected": true,
"text": "HKEY hKey;\nLONG lRes = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L\"SOFTWARE\\\\Perl\", 0, KEY_READ, &hKey);\nbool bExistsAndSuccess (lRes == ERROR_SUCCESS);\nbool bDoesNotExistsSpecifically (lRes == ERROR_FILE_NOT_FOUND);\nstd::wstring strValueOfBinDir;\nstd::wstring strKeyDefaultValue;\nGetStringRegKey(hKey, L\"BinDir\", strValueOfBinDir, L\"bad\");\nGetStringRegKey(hKey, L\"\", strKeyDefaultValue, L\"bad\");\n\nLONG GetDWORDRegKey(HKEY hKey, const std::wstring &strValueName, DWORD &nValue, DWORD nDefaultValue)\n{\n nValue = nDefaultValue;\n DWORD dwBufferSize(sizeof(DWORD));\n DWORD nResult(0);\n LONG nError = ::RegQueryValueExW(hKey,\n strValueName.c_str(),\n 0,\n NULL,\n reinterpret_cast<LPBYTE>(&nResult),\n &dwBufferSize);\n if (ERROR_SUCCESS == nError)\n {\n nValue = nResult;\n }\n return nError;\n}\n\n\nLONG GetBoolRegKey(HKEY hKey, const std::wstring &strValueName, bool &bValue, bool bDefaultValue)\n{\n DWORD nDefValue((bDefaultValue) ? 1 : 0);\n DWORD nResult(nDefValue);\n LONG nError = GetDWORDRegKey(hKey, strValueName.c_str(), nResult, nDefValue);\n if (ERROR_SUCCESS == nError)\n {\n bValue = (nResult != 0) ? true : false;\n }\n return nError;\n}\n\n\nLONG GetStringRegKey(HKEY hKey, const std::wstring &strValueName, std::wstring &strValue, const std::wstring &strDefaultValue)\n{\n strValue = strDefaultValue;\n WCHAR szBuffer[512];\n DWORD dwBufferSize = sizeof(szBuffer);\n ULONG nError;\n nError = RegQueryValueExW(hKey, strValueName.c_str(), 0, NULL, (LPBYTE)szBuffer, &dwBufferSize);\n if (ERROR_SUCCESS == nError)\n {\n strValue = szBuffer;\n }\n return nError;\n}\n"
},
{
"answer_id": 7199329,
"author": "Jim Michaels",
"author_id": 591668,
"author_profile": "https://Stackoverflow.com/users/591668",
"pm_score": 0,
"selected": false,
"text": "#include <windows.h>\n#include <map>\n#include <string>\n#include <stdio.h>\n#include <string.h>\n#include <tr1/stdint.h>\n\nusing namespace std;\n\nvoid printerr(DWORD dwerror) {\n LPVOID lpMsgBuf;\n FormatMessage(\n FORMAT_MESSAGE_ALLOCATE_BUFFER |\n FORMAT_MESSAGE_FROM_SYSTEM |\n FORMAT_MESSAGE_IGNORE_INSERTS,\n NULL,\n dwerror,\n MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language\n (LPTSTR) &lpMsgBuf,\n 0,\n NULL\n );\n // Process any inserts in lpMsgBuf.\n // ...\n // Display the string.\n if (isOut) {\n fprintf(fout, \"%s\\n\", lpMsgBuf);\n } else {\n printf(\"%s\\n\", lpMsgBuf);\n }\n // Free the buffer.\n LocalFree(lpMsgBuf);\n}\n\n\n\nbool regreadSZ(string& hkey, string& subkey, string& value, string& returnvalue, string& regValueType) {\n char s[128000];\n map<string,HKEY> keys;\n keys[\"HKEY_CLASSES_ROOT\"]=HKEY_CLASSES_ROOT;\n keys[\"HKEY_CURRENT_CONFIG\"]=HKEY_CURRENT_CONFIG; //DID NOT SURVIVE?\n keys[\"HKEY_CURRENT_USER\"]=HKEY_CURRENT_USER;\n keys[\"HKEY_LOCAL_MACHINE\"]=HKEY_LOCAL_MACHINE;\n keys[\"HKEY_USERS\"]=HKEY_USERS;\n HKEY mykey;\n\n map<string,DWORD> valuetypes;\n valuetypes[\"REG_SZ\"]=REG_SZ;\n valuetypes[\"REG_EXPAND_SZ\"]=REG_EXPAND_SZ;\n valuetypes[\"REG_MULTI_SZ\"]=REG_MULTI_SZ; //probably can't use this.\n\n LONG retval=RegOpenKeyEx(\n keys[hkey], // handle to open key\n subkey.c_str(), // subkey name\n 0, // reserved\n KEY_READ, // security access mask\n &mykey // handle to open key\n );\n if (ERROR_SUCCESS != retval) {printerr(retval); return false;}\n DWORD slen=128000;\n DWORD valuetype = valuetypes[regValueType];\n retval=RegQueryValueEx(\n mykey, // handle to key\n value.c_str(), // value name\n NULL, // reserved\n (LPDWORD) &valuetype, // type buffer\n (LPBYTE)s, // data buffer\n (LPDWORD) &slen // size of data buffer\n );\n switch(retval) {\n case ERROR_SUCCESS:\n //if (isOut) {\n // fprintf(fout,\"RegQueryValueEx():ERROR_SUCCESS:succeeded.\\n\");\n //} else {\n // printf(\"RegQueryValueEx():ERROR_SUCCESS:succeeded.\\n\");\n //}\n break;\n case ERROR_MORE_DATA:\n //what do I do now? data buffer is too small.\n if (isOut) {\n fprintf(fout,\"RegQueryValueEx():ERROR_MORE_DATA: need bigger buffer.\\n\");\n } else {\n printf(\"RegQueryValueEx():ERROR_MORE_DATA: need bigger buffer.\\n\");\n }\n return false;\n case ERROR_FILE_NOT_FOUND:\n if (isOut) {\n fprintf(fout,\"RegQueryValueEx():ERROR_FILE_NOT_FOUND: registry value does not exist.\\n\");\n } else {\n printf(\"RegQueryValueEx():ERROR_FILE_NOT_FOUND: registry value does not exist.\\n\");\n }\n return false;\n default:\n if (isOut) {\n fprintf(fout,\"RegQueryValueEx():unknown error type 0x%lx.\\n\", retval);\n } else {\n printf(\"RegQueryValueEx():unknown error type 0x%lx.\\n\", retval);\n }\n return false;\n\n }\n retval=RegCloseKey(mykey);\n if (ERROR_SUCCESS != retval) {printerr(retval); return false;}\n\n returnvalue = s;\n return true;\n}\n"
},
{
"answer_id": 50821858,
"author": "Roi Danton",
"author_id": 4566599,
"author_profile": "https://Stackoverflow.com/users/4566599",
"pm_score": 3,
"selected": false,
"text": "RegOpenKeyEx RegCloseKey NUL REG_SZ REG_MULTI_SZ REG_EXPAND_SZ #include <iostream>\n#include <string>\n#include <exception>\n#include <windows.h>\n\n/*! \\brief Returns a value from HKLM as string.\n \\exception std::runtime_error Replace with your error handling.\n*/\nstd::wstring GetStringValueFromHKLM(const std::wstring& regSubKey, const std::wstring& regValue)\n{\n size_t bufferSize = 0xFFF; // If too small, will be resized down below.\n std::wstring valueBuf; // Contiguous buffer since C++11.\n valueBuf.resize(bufferSize);\n auto cbData = static_cast<DWORD>(bufferSize * sizeof(wchar_t));\n auto rc = RegGetValueW(\n HKEY_LOCAL_MACHINE,\n regSubKey.c_str(),\n regValue.c_str(),\n RRF_RT_REG_SZ,\n nullptr,\n static_cast<void*>(valueBuf.data()),\n &cbData\n );\n while (rc == ERROR_MORE_DATA)\n {\n // Get a buffer that is big enough.\n cbData /= sizeof(wchar_t);\n if (cbData > static_cast<DWORD>(bufferSize))\n {\n bufferSize = static_cast<size_t>(cbData);\n }\n else\n {\n bufferSize *= 2;\n cbData = static_cast<DWORD>(bufferSize * sizeof(wchar_t));\n }\n valueBuf.resize(bufferSize);\n rc = RegGetValueW(\n HKEY_LOCAL_MACHINE,\n regSubKey.c_str(),\n regValue.c_str(),\n RRF_RT_REG_SZ,\n nullptr,\n static_cast<void*>(valueBuf.data()),\n &cbData\n );\n }\n if (rc == ERROR_SUCCESS)\n {\n cbData /= sizeof(wchar_t);\n valueBuf.resize(static_cast<size_t>(cbData - 1)); // remove end null character\n return valueBuf;\n }\n else\n {\n throw std::runtime_error(\"Windows system error code: \" + std::to_string(rc));\n }\n}\n\nint main()\n{\n std::wstring regSubKey;\n#ifdef _WIN64 // Manually switching between 32bit/64bit for the example. Use dwFlags instead.\n regSubKey = L\"SOFTWARE\\\\WOW6432Node\\\\Company Name\\\\Application Name\\\\\";\n#else\n regSubKey = L\"SOFTWARE\\\\Company Name\\\\Application Name\\\\\";\n#endif\n std::wstring regValue(L\"MyValue\");\n std::wstring valueFromRegistry;\n try\n {\n valueFromRegistry = GetStringValueFromHKLM(regSubKey, regValue);\n }\n catch (std::exception& e)\n {\n std::cerr << e.what();\n }\n std::wcout << valueFromRegistry;\n}\n dwFlags RRF_ZEROONFAILURE RRF_SUBKEY_WOW6464KEY RRF_SUBKEY_WOW6432KEY"
},
{
"answer_id": 53074007,
"author": "kayleeFrye_onDeck",
"author_id": 3543437,
"author_profile": "https://Stackoverflow.com/users/3543437",
"pm_score": 1,
"selected": false,
"text": ".reg Windows Registry Editor Version 5.00\n\n[HKEY_CURRENT_USER\\added\\subkey]\n\"String_Value\"=\"hello, world!\"\n\"Binary_Value\"=hex:01,01,01,01\n\"Dword value\"=dword:00001224\n\"QWord val\"=hex(b):24,22,12,00,00,00,00,00\n\"multi-line val\"=hex(7):4c,00,69,00,6e,00,65,00,20,00,30,00,00,00,4c,00,69,00,\\\n 6e,00,65,00,20,00,31,00,00,00,4c,00,69,00,6e,00,65,00,20,00,32,00,00,00,00,\\\n 00\n\"expanded_val\"=hex(2):25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,49,\\\n 00,4c,00,45,00,25,00,5c,00,6e,00,65,00,77,00,5f,00,73,00,74,00,75,00,66,00,\\\n 66,00,00,00\n #include <Windows.h>\n#include <iostream>\n#include <string>\n#include <locale>\n#include <vector>\n#include <iomanip>\n\nint wmain()\n{\n const auto hKey = HKEY_CURRENT_USER;\n constexpr auto lpSubKey = TEXT(\"added\\\\subkey\");\n auto openedKey = HKEY();\n auto status = RegOpenKeyEx(hKey, lpSubKey, 0, KEY_READ, &openedKey);\n\n if (status == ERROR_SUCCESS) {\n auto valueCount = static_cast<DWORD>(0);\n auto maxNameLength = static_cast<DWORD>(0);\n auto maxValueLength = static_cast<DWORD>(0);\n status = RegQueryInfoKey(openedKey, NULL, NULL, NULL, NULL, NULL, NULL,\n &valueCount, &maxNameLength, &maxValueLength, NULL, NULL);\n\n if (status == ERROR_SUCCESS) {\n DWORD type = 0;\n DWORD index = 0;\n std::vector<wchar_t> valueName = std::vector<wchar_t>(maxNameLength + 1);\n std::vector<BYTE> dataBuffer = std::vector<BYTE>(maxValueLength);\n\n for (DWORD index = 0; index < valueCount; index++) {\n DWORD charCountValueName = static_cast<DWORD>(valueName.size());\n DWORD charBytesData = static_cast<DWORD>(dataBuffer.size());\n status = RegEnumValue(openedKey, index, valueName.data(), &charCountValueName,\n NULL, &type, dataBuffer.data(), &charBytesData);\n\n if (type == REG_SZ) {\n const auto reg_string = reinterpret_cast<wchar_t*>(dataBuffer.data());\n std::wcout << L\"Type: REG_SZ\" << std::endl;\n std::wcout << L\"\\tName: \" << valueName.data() << std::endl;\n std::wcout << L\"\\tData : \" << reg_string << std::endl;\n }\n else if (type == REG_EXPAND_SZ) {\n const auto casted = reinterpret_cast<wchar_t*>(dataBuffer.data());\n TCHAR buffer[32000];\n ExpandEnvironmentStrings(casted, buffer, 32000);\n std::wcout << L\"Type: REG_EXPAND_SZ\" << std::endl;\n std::wcout << L\"\\tName: \" << valueName.data() << std::endl;\n std::wcout << L\"\\tData: \" << buffer << std::endl;\n }\n else if (type == REG_MULTI_SZ) {\n std::vector<std::wstring> lines;\n const auto str = reinterpret_cast<wchar_t*>(dataBuffer.data());\n auto line = str;\n lines.emplace_back(line);\n for (auto i = 0; i < charBytesData / sizeof(wchar_t) - 1; i++) {\n const auto c = str[i];\n if (c == 0) {\n line = str + i + 1;\n const auto new_line = reinterpret_cast<wchar_t*>(line);\n if (wcsnlen_s(new_line, 1024) > 0)\n lines.emplace_back(new_line);\n }\n }\n std::wcout << L\"Type: REG_MULTI_SZ\" << std::endl;\n std::wcout << L\"\\tName: \" << valueName.data() << std::endl;\n std::wcout << L\"\\tData: \" << std::endl;\n for (size_t i = 0; i < lines.size(); i++) {\n std::wcout << L\"\\t\\tLine[\" << i + 1 << L\"]: \" << lines[i] << std::endl;\n }\n }\n if (type == REG_DWORD) {\n const auto dword_value = reinterpret_cast<unsigned long*>(dataBuffer.data());\n std::wcout << L\"Type: REG_DWORD\" << std::endl;\n std::wcout << L\"\\tName: \" << valueName.data() << std::endl;\n std::wcout << L\"\\tData : \" << std::to_wstring(*dword_value) << std::endl;\n }\n else if (type == REG_QWORD) {\n const auto qword_value = reinterpret_cast<unsigned long long*>(dataBuffer.data());\n std::wcout << L\"Type: REG_DWORD\" << std::endl;\n std::wcout << L\"\\tName: \" << valueName.data() << std::endl;\n std::wcout << L\"\\tData : \" << std::to_wstring(*qword_value) << std::endl;\n }\n else if (type == REG_BINARY) {\n std::vector<uint16_t> bins;\n for (auto i = 0; i < charBytesData; i++) {\n bins.push_back(static_cast<uint16_t>(dataBuffer[i]));\n }\n std::wcout << L\"Type: REG_BINARY\" << std::endl;\n std::wcout << L\"\\tName: \" << valueName.data() << std::endl;\n std::wcout << L\"\\tData:\";\n for (size_t i = 0; i < bins.size(); i++) {\n std::wcout << L\" \" << std::uppercase << std::hex << \\\n std::setw(2) << std::setfill(L'0') << std::to_wstring(bins[i]);\n }\n std::wcout << std::endl;\n }\n }\n }\n }\n\n RegCloseKey(openedKey);\n return 0;\n}\n Type: REG_SZ\n Name: String_Value\n Data : hello, world!\nType: REG_BINARY\n Name: Binary_Value\n Data: 01 01 01 01\nType: REG_DWORD\n Name: Dword value\n Data : 4644\nType: REG_DWORD\n Name: QWord val\n Data : 1188388\nType: REG_MULTI_SZ\n Name: multi-line val\n Data:\n Line[1]: Line 0\n Line[2]: Line 1\n Line[3]: Line 2\nType: REG_EXPAND_SZ\n Name: expanded_val\n Data: C:\\Users\\user name\\new_stuff\n"
},
{
"answer_id": 57627988,
"author": "Jarek C",
"author_id": 3736444,
"author_profile": "https://Stackoverflow.com/users/3736444",
"pm_score": 2,
"selected": false,
"text": "Computer\\HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\FileSystem\\LongPathsEnabled #include <windows.h>\n\nDWORD val;\nDWORD dataSize = sizeof(val);\nif (ERROR_SUCCESS == RegGetValueA(HKEY_LOCAL_MACHINE, \"SYSTEM\\\\CurrentControlSet\\\\Control\\\\FileSystem\", \"LongPathsEnabled\", RRF_RT_DWORD, nullptr /*type not required*/, &val, &dataSize)) {\n printf(\"Value is %i\\n\", val);\n // no CloseKey needed because it is a predefined registry key\n}\nelse {\n printf(\"Error reading.\\n\");\n}\n"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/34065",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3551/"
] |
34,079 |
<p>What's the best way to specify a proxy with username and password for an http connection in python?</p>
|
[
{
"answer_id": 34116,
"author": "bernhardrusch",
"author_id": 3056,
"author_profile": "https://Stackoverflow.com/users/3056",
"pm_score": 6,
"selected": false,
"text": "import urllib2\n\nproxy = urllib2.ProxyHandler({'http': 'http://\nusername:password@proxyurl:proxyport'})\nauth = urllib2.HTTPBasicAuthHandler()\nopener = urllib2.build_opener(proxy, auth, urllib2.HTTPHandler)\nurllib2.install_opener(opener)\n\nconn = urllib2.urlopen('http://python.org')\nreturn_str = conn.read()\n"
},
{
"answer_id": 35443,
"author": "gz.",
"author_id": 3665,
"author_profile": "https://Stackoverflow.com/users/3665",
"pm_score": 3,
"selected": false,
"text": "import urllib2\n\ndef get_proxy_opener(proxyurl, proxyuser, proxypass, proxyscheme=\"http\"):\n password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()\n password_mgr.add_password(None, proxyurl, proxyuser, proxypass)\n\n proxy_handler = urllib2.ProxyHandler({proxyscheme: proxyurl})\n proxy_auth_handler = urllib2.ProxyBasicAuthHandler(password_mgr)\n\n return urllib2.build_opener(proxy_handler, proxy_auth_handler)\n\nif __name__ == \"__main__\":\n import sys\n if len(sys.argv) > 4:\n url_opener = get_proxy_opener(*sys.argv[1:4])\n for url in sys.argv[4:]:\n print url_opener.open(url).headers\n else:\n print \"Usage:\", sys.argv[0], \"proxy user pass fetchurls...\"\n"
},
{
"answer_id": 142324,
"author": "Tony Meyer",
"author_id": 4966,
"author_profile": "https://Stackoverflow.com/users/4966",
"pm_score": 2,
"selected": false,
"text": "import urllib2\nurl = 'www.proxyurl.com'\nusername = 'user'\npassword = 'pass'\npassword_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()\n# None, with the \"WithDefaultRealm\" password manager means\n# that the user/pass will be used for any realm (where\n# there isn't a more specific match).\npassword_mgr.add_password(None, url, username, password)\nauth_handler = urllib2.HTTPBasicAuthHandler(password_mgr)\nopener = urllib2.build_opener(auth_handler)\nurllib2.install_opener(opener)\nprint urllib2.urlopen(\"http://www.example.com/folder/page.html\").read()\n"
},
{
"answer_id": 36216636,
"author": "daz",
"author_id": 799873,
"author_profile": "https://Stackoverflow.com/users/799873",
"pm_score": 2,
"selected": false,
"text": "import urllib.request\n\n# set up authentication info\nauthinfo = urllib.request.HTTPBasicAuthHandler()\nproxy_support = urllib.request.ProxyHandler({\"http\" : \"http://ahad-haam:3128\"})\n\n# build a new opener that adds authentication and caching FTP handlers\nopener = urllib.request.build_opener(proxy_support, authinfo,\n urllib.request.CacheFTPHandler)\n\n# install it\nurllib.request.install_opener(opener)\n\nf = urllib.request.urlopen('http://www.python.org/')\n\"\"\"\n"
},
{
"answer_id": 41920303,
"author": "Aminah Nuraini",
"author_id": 1564659,
"author_profile": "https://Stackoverflow.com/users/1564659",
"pm_score": 6,
"selected": true,
"text": "import requests\n\nproxies = {\"http\":\"http://username:password@proxy_ip:proxy_port\"}\n\nr = requests.get(\"http://www.example.com/\", proxies=proxies)\n\nprint(r.content)\n urllib urllib"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/34079",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3573/"
] |
34,087 |
<pre><code><xsl:for-each select="./node [position() &lt;= (count(*) div 2)]">
<li>foo</li>
</xsl:for-each>
<xsl:for-each select="./node [count(*) div 2 &lt; position()]">
<li>bar</li>
</xsl:for-each>
</code></pre>
<p>My list has 12 nodes, but the second list is always 8 and the first is always 4. What's wrong with my selects?</p>
|
[
{
"answer_id": 34111,
"author": "A. Rex",
"author_id": 3508,
"author_profile": "https://Stackoverflow.com/users/3508",
"pm_score": 0,
"selected": false,
"text": "count(*) last()"
},
{
"answer_id": 34114,
"author": "jelovirt",
"author_id": 2679,
"author_profile": "https://Stackoverflow.com/users/2679",
"pm_score": 4,
"selected": true,
"text": "count(*) node count(current()/node) last() <xsl:variable name=\"nodes\" select=\"node\"/>\n<xsl:variable name=\"mid\" select=\"count($nodes) div 2\"/>\n<xsl:for-each select=\"$nodes[position() <= $mid]\">\n <li>foo</li>\n</xsl:for-each>\n<xsl:for-each select=\"$nodes[$mid < position()]\">\n <li>bar</li>\n</xsl:for-each>\n"
},
{
"answer_id": 34133,
"author": "codeape",
"author_id": 3571,
"author_profile": "https://Stackoverflow.com/users/3571",
"pm_score": 0,
"selected": false,
"text": "<xsl:for-each select=\"node[position() <= (count(../node) div 2)]\">\n ...\n</xsl:for-each>\n<xsl:for-each select=\"node[(count(../node) div 2) < position()]\">\n ...\n</xsl:for-each>\n"
},
{
"answer_id": 34159,
"author": "samjudson",
"author_id": 1908,
"author_profile": "https://Stackoverflow.com/users/1908",
"pm_score": 2,
"selected": false,
"text": "last() <xsl:for-each select=\"./node [position() <= last() div 2]\">\n <li>foo</li>\n</xsl:for-each>\n<xsl:for-each select=\"./node [last() div 2 < position()]\">\n <li>bar</li>\n</xsl:for-each>\n"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/34087",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1786/"
] |
34,093 |
<p>I want to apply an XSLT Stylesheet to an XML Document using C# and write the output to a File.</p>
|
[
{
"answer_id": 34095,
"author": "Daren Thomas",
"author_id": 2260,
"author_profile": "https://Stackoverflow.com/users/2260",
"pm_score": 9,
"selected": true,
"text": "XPathDocument myXPathDoc = new XPathDocument(myXmlFile) ;\nXslTransform myXslTrans = new XslTransform() ;\nmyXslTrans.Load(myStyleSheet);\nXmlTextWriter myWriter = new XmlTextWriter(\"result.html\",null) ;\nmyXslTrans.Transform(myXPathDoc,null,myWriter) ;\n XslTransform XslCompiledTransform XPathDocument myXPathDoc = new XPathDocument(myXmlFile) ;\nXslCompiledTransform myXslTrans = new XslCompiledTransform();\nmyXslTrans.Load(myStyleSheet);\nXmlTextWriter myWriter = new XmlTextWriter(\"result.html\",null);\nmyXslTrans.Transform(myXPathDoc,null,myWriter);\n"
},
{
"answer_id": 10596241,
"author": "Heinzi",
"author_id": 87698,
"author_profile": "https://Stackoverflow.com/users/87698",
"pm_score": 7,
"selected": false,
"text": "var myXslTrans = new XslCompiledTransform(); \nmyXslTrans.Load(\"stylesheet.xsl\"); \nmyXslTrans.Transform(\"source.xml\", \"result.html\"); \n code block With New XslCompiledTransform()\n .Load(\"stylesheet.xsl\")\n .Transform(\"source.xml\", \"result.html\")\nEnd With\n"
},
{
"answer_id": 58930747,
"author": "Vinod Srivastav",
"author_id": 3057246,
"author_profile": "https://Stackoverflow.com/users/3057246",
"pm_score": 2,
"selected": false,
"text": "public static string TransformDocument(string doc, string stylesheetPath)\n{\n Func<string,XmlDocument> GetXmlDocument = (xmlContent) =>\n {\n XmlDocument xmlDocument = new XmlDocument();\n xmlDocument.LoadXml(xmlContent);\n return xmlDocument;\n };\n\n try\n {\n var document = GetXmlDocument(doc);\n var style = GetXmlDocument(File.ReadAllText(stylesheetPath));\n\n System.Xml.Xsl.XslCompiledTransform transform = new System.Xml.Xsl.XslCompiledTransform();\n transform.Load(style); // compiled stylesheet\n System.IO.StringWriter writer = new System.IO.StringWriter();\n XmlReader xmlReadB = new XmlTextReader(new StringReader(document.DocumentElement.OuterXml));\n transform.Transform(xmlReadB, null, writer);\n return writer.ToString();\n }\n catch (Exception ex)\n {\n throw ex;\n }\n\n} \n"
},
{
"answer_id": 72905605,
"author": "Mubashar",
"author_id": 806076,
"author_profile": "https://Stackoverflow.com/users/806076",
"pm_score": 0,
"selected": false,
"text": "xslt-extensions var schema = XDocument.Load(XsltPath);\nusing (var connection = new SqlConnection(ConnectionString))\n{\n connection.Open();\n using (var command = new SqlCommand(Sql, connection))\n {\n var reader = command.ExecuteReader();\n var dt = new DataTable(SourceNode);\n dt.Load(reader);\n \n string xml = \"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?>\" + Environment.NewLine;\n using (var stringWriter = new StringWriter())\n {\n dt.WriteXml(stringWriter, true);\n xml += stringWriter.GetStringBuilder().ToString();\n }\n\n XDocument transformedXml = new XDocument();\n var xsltArgumentList = new XsltArgumentList();\n xsltArgumentList.AddExtensionObject(\"urn:xslt-extensions\", new XsltExtensions());\n\n using (XmlWriter writer = transformedXml.CreateWriter())\n {\n XslCompiledTransform xslt = new XslCompiledTransform();\n xslt.Load(schema.CreateReader());\n xslt.Transform(XmlReader.Create(new StringReader(xml)), xsltArgumentList, writer);\n }\n var result = transformedXml.ToString();\n }\n}\n XsltPath ConnectionString Sql SourceNode urn:xslt-extensions new XsltExtensions() public class XsltExtensions\n{\n public string FormatDate(string dateString, string format)\n {\n DateTime date;\n\n if (DateTime.TryParse(dateString, out date))\n return date.ToString(format);\n\n return dateString;\n }\n}\n <xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" xmlns:ext=\"urn:xslt-extensions\">\n...\n<myTag><xsl:value-of select=\"ext:FormatDate(record_date, 'yyyy-MM-dd')\"/></myTag>\n...\n</xsl:stylesheet>\n"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/34093",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2260/"
] |
34,125 |
<p>It seems to me that it would work perfectly well to do tail-recursion optimization in both C and C++, yet while debugging I never seem to see a frame stack that indicates this optimization. That is kind of good, because the stack tells me how deep the recursion is. However, the optimization would be kind of nice as well.</p>
<p>Do any C++ compilers do this optimization? Why? Why not?</p>
<p>How do I go about telling the compiler to do it?</p>
<ul>
<li>For MSVC: <code>/O2</code> or <code>/Ox</code></li>
<li>For GCC: <code>-O2</code> or <code>-O3</code></li>
</ul>
<p>How about checking if the compiler has done this in a certain case?</p>
<ul>
<li>For MSVC, enable PDB output to be able to trace the code, then inspect the code</li>
<li>For GCC..?</li>
</ul>
<p>I'd still take suggestions for how to determine if a certain function is optimized like this by the compiler (even though I find it reassuring that Konrad tells me to assume it)</p>
<p>It is always possible to check if the compiler does this at all by making an infinite recursion and checking if it results in an infinite loop or a stack overflow (I did this with GCC and found out that <code>-O2</code> is sufficient), but I want to be able to check a certain function that I know will terminate anyway. I'd love to have an easy way of checking this :)</p>
<hr>
<p>After some testing, I discovered that destructors ruin the possibility of making this optimization. It can sometimes be worth it to change the scoping of certain variables and temporaries to make sure they go out of scope before the return-statement starts.</p>
<p>If any destructor needs to be run after the tail-call, the tail-call optimization can not be done.</p>
|
[
{
"answer_id": 34129,
"author": "Konrad Rudolph",
"author_id": 1968,
"author_profile": "https://Stackoverflow.com/users/1968",
"pm_score": 8,
"selected": true,
"text": "int bar(int, int);\n\nint foo(int n, int acc) {\n return (n == 0) ? acc : bar(n - 1, acc + 2);\n}\n\nint bar(int n, int acc) {\n return (n == 0) ? acc : foo(n - 1, acc + 1);\n}\n /O2 /Ox -O3"
},
{
"answer_id": 220660,
"author": "Tom Barta",
"author_id": 29839,
"author_profile": "https://Stackoverflow.com/users/29839",
"pm_score": 5,
"selected": false,
"text": "atoi() main() -O1 static extern #include <stdio.h>\nstatic int atoi(const char *str, int n)\n{\n if (str == 0 || *str == 0)\n return n;\n return atoi(str+1, n*10 + *str-'0');\n}\nint main(int argc, char **argv)\n{\n for (int i = 1; i != argc; ++i)\n printf(\"%s -> %d\\n\", argv[i], atoi(argv[i], 0));\n return 0;\n}\n"
},
{
"answer_id": 35649259,
"author": "Martin Bonner supports Monica",
"author_id": 771073,
"author_profile": "https://Stackoverflow.com/users/771073",
"pm_score": 5,
"selected": false,
"text": " int fn(int j, int i)\n {\n if (i <= 0) return j;\n Funky cls(j,i);\n return fn(j, i-1);\n }\n cls Funky std::vector"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/34125",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2971/"
] |
34,126 |
<p>I see 2 main ways to set events in JavaScript:</p>
<ol>
<li><p>Add an event directly inside the tag like this:</p>
<p><code><a href="" onclick="doFoo()">do foo</a></code></p></li>
<li><p>Set them by JavaScript like this:</p>
<p><code><a id="bar" href="">do bar</a></code></p></li>
</ol>
<p>and add an event in a <code><script></code> section inside the <code><head></code> section or in an external JavaScript file, like that if you're using <strong>prototypeJS</strong>:</p>
<pre><code>Event.observe(window, 'load', function() {
$('bar').observe('click', doBar);
}
</code></pre>
<p>I think the first method is easier to read and maintain (because the JavaScript action is directly bound to the link) but it's not so clean (because users can click on the link even if the page is not fully loaded, which may cause JavaScript errors in some cases).</p>
<p>The second method is cleaner (actions are added when the page is fully loaded) but it's more difficult to know that an action is linked to the tag.</p>
<p>Which method is the best?</p>
<p>A killer answer will be fully appreciated!</p>
|
[
{
"answer_id": 34130,
"author": "Polsonby",
"author_id": 137,
"author_profile": "https://Stackoverflow.com/users/137",
"pm_score": 0,
"selected": false,
"text": "window.onload = function () {\n init();\n}\nfunction init() {\n // actual function calls go here\n doFoo();\n}\n onDOMReady"
},
{
"answer_id": 34141,
"author": "Konrad Rudolph",
"author_id": 1968,
"author_profile": "https://Stackoverflow.com/users/1968",
"pm_score": 3,
"selected": false,
"text": "$$('#itemlist table th > a').invoke('observe', 'click', performSort);\n"
},
{
"answer_id": 34163,
"author": "Thomas Lötzer",
"author_id": 3587,
"author_profile": "https://Stackoverflow.com/users/3587",
"pm_score": 3,
"selected": true,
"text": "Event.observe()"
},
{
"answer_id": 34179,
"author": "Tyler",
"author_id": 3561,
"author_profile": "https://Stackoverflow.com/users/3561",
"pm_score": 1,
"selected": false,
"text": "onclick=X"
},
{
"answer_id": 34293,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "var myObject = {\n\n allLinkElements: null, \n\n init: function()\n {\n // Set all the elements we need\n myObject.setElements();\n\n // Set event handlers for elements\n myObject.setEventHandlers();\n },\n\n clickedLink: function()\n {\n // Handle the click event\n alert('you clicked a link');\n },\n\n setElements: function()\n {\n // Find all <a> tags on the page\n myObject.allLinkElements = $('a');\n\n // Find other elements...\n },\n\n setEventHandlers: function()\n {\n // Loop through each link\n myObject.allLinkElements.each(function(id)\n { \n // Assign the handler for the click event\n $(this).click(myObject.clickedLink);\n });\n\n // Assign handlers for other elements...\n }\n}\n\n// Wait for the DOM to be ready before initialising\n$(document).ready(myObject.init);\n"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/34126",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3122/"
] |
34,144 |
<p>I would like to know which dependency described in my pom.xml brings a transitive dependency in my target directory.</p>
<p>To be more precise, I have the library "poi-2.5.1-final-20040804.jar" in my WEB-INF/lib directory and I would like to know which dependency in my pom.xml brings that.</p>
|
[
{
"answer_id": 34156,
"author": "David Crow",
"author_id": 2783,
"author_profile": "https://Stackoverflow.com/users/2783",
"pm_score": 6,
"selected": false,
"text": "mvn dependency:tree\n"
},
{
"answer_id": 34167,
"author": "A. Rex",
"author_id": 3508,
"author_profile": "https://Stackoverflow.com/users/3508",
"pm_score": 8,
"selected": true,
"text": "mvn dependency:tree -Dincludes=velocity:velocity\n [INFO] [dependency:tree]\n[INFO] org.apache.maven.plugins:maven-dependency-plugin:maven-plugin:2.0-alpha-5-SNAPSHOT\n[INFO] \\- org.apache.maven.doxia:doxia-site-renderer:jar:1.0-alpha-8:compile\n[INFO] \\- org.codehaus.plexus:plexus-velocity:jar:1.1.3:compile\n[INFO] \\- velocity:velocity:jar:1.4:compile\n"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/34144",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3122/"
] |
34,151 |
<p>Is the following safe?</p>
<p>I am new to threading and I want to delegate a time consuming process to a separate thread in my C++ program.
Using the boost libraries I have written code something like this:</p>
<p>thrd = new boost::thread(boost::bind(&myclass::mymethod, this, &finished_flag);</p>
<p>Where finished_flag is a boolean member of my class. When the thread is finished it sets the value and the main loop of my program checks for a change in that value.
I assume that this is okay because I only ever start one thread, and that thread is the only thing that changes the value (except for when it is initialised before I start the thread)
So is this okay, or am I missing something, and need to use locks and mutexes, etc</p>
|
[
{
"answer_id": 34174,
"author": "roo",
"author_id": 716,
"author_profile": "https://Stackoverflow.com/users/716",
"pm_score": 3,
"selected": false,
"text": "condition condition condition thread thread.timed_join timed_join"
},
{
"answer_id": 69570,
"author": "bk1e",
"author_id": 8090,
"author_profile": "https://Stackoverflow.com/users/8090",
"pm_score": 2,
"selected": false,
"text": "lib = loadLibrary(\"someLibrary\");\nfun = getFunction(\"someFunction\");\nfun();\nunloadLibrary(lib);\n void someFunction() {\n volatile bool finished_flag = false;\n thrd = new boost::thread(boost::bind(&myclass::mymethod, this, &finished_flag);\n while(!finished_flag) { // ignore the polling loop, it's besides the point\n sleep();\n }\n delete thrd;\n}\n\nvoid myclass::mymethod() {\n // do stuff\n finished_flag = true;\n}\n myclass::mymethod() finished_flag true myclass::mymethod() myclass::mymethod() someFunction() myclass::mymethod() someFunction() thrd->join()"
},
{
"answer_id": 111694,
"author": "oz10",
"author_id": 14069,
"author_profile": "https://Stackoverflow.com/users/14069",
"pm_score": 3,
"selected": false,
"text": "// launch the thread...\nthrd = new boost::thread(boost::bind(&myclass::mymethod, this, &finished_flag);\n\n// ... do other things maybe ... \n\n// wait for the thread to complete\nthrd.join();\n"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/34151",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
34,155 |
<p>I'm trying to grasp the concept of continuations and I found several small teaching examples like this one from the <a href="http://en.wikipedia.org/wiki/Continuation" rel="noreferrer">Wikipedia article</a>:</p>
<pre><code>(define the-continuation #f)
(define (test)
(let ((i 0))
; call/cc calls its first function argument, passing
; a continuation variable representing this point in
; the program as the argument to that function.
;
; In this case, the function argument assigns that
; continuation to the variable the-continuation.
;
(call/cc (lambda (k) (set! the-continuation k)))
;
; The next time the-continuation is called, we start here.
(set! i (+ i 1))
i))
</code></pre>
<p>I understand what this little function does, but I can't see any obvious application of it. While I don't expect to use continuations all over my code anytime soon, I wish I knew a few cases where they can be appropriate. </p>
<p>So I'm looking for more explicitely usefull code samples of what continuations can offer me as a programmer.</p>
<p>Cheers!</p>
|
[
{
"answer_id": 34327,
"author": "Sébastien RoccaSerra",
"author_id": 2797,
"author_profile": "https://Stackoverflow.com/users/2797",
"pm_score": 3,
"selected": false,
"text": "WAComponent >> call: aComponent\n \"Pass control from the receiver to aComponent. The receiver will be\n temporarily replaced with aComponent. Code can return from here later\n on by sending #answer: to aComponent.\"\n\n ^ AnswerContinuation currentDo: [ :cc |\n self show: aComponent onAnswer: cc.\n WARenderNotification raiseSignal ]\n"
},
{
"answer_id": 34387,
"author": "sven",
"author_id": 46,
"author_profile": "https://Stackoverflow.com/users/46",
"pm_score": 5,
"selected": true,
"text": "(define (BFS graph root-discovered node-discovered edge-discovered edge-bumped . nodes)\n (define visited (make-vector (graph.order graph) #f))\n (define q (queue.new))\n (define exit ())\n (define (BFS-tree node)\n (if (node-discovered node)\n (exit node))\n (graph.map-edges\n graph\n node\n (lambda (node2)\n (cond ((not (vector-ref visited node2))\n (when (edge-discovered node node2)\n (vector-set! visited node2 #t)\n (queue.enqueue! q node2)))\n (else\n (edge-bumped node node2)))))\n (if (not (queue.empty? q))\n (BFS-tree (queue.serve! q))))\n\n (call-with-current-continuation\n (lambda (my-future)\n (set! exit my-future)\n (cond ((null? nodes)\n (graph.map-nodes\n graph\n (lambda (node)\n (when (not (vector-ref visited node))\n (vector-set! visited node #t)\n (root-discovered node)\n (BFS-tree node)))))\n (else\n (let loop-nodes\n ((node-list (car nodes)))\n (vector-set! visited (car node-list) #t)\n (root-discovered (car node-list))\n (BFS-tree (car node-list))\n (if (not (null? (cdr node-list)))\n (loop-nodes (cdr node-list)))))))))\n (if (node-discovered node)\n (exit node))\n (call-with-current-continuation\n (lambda (my-future)\n (set! exit my-future)\n (define (connected? g node1 node2)\n (define visited (make-vector (graph.order g) #f))\n (define return ())\n (define (connected-rec x y)\n (if (eq? x y)\n (return #t))\n (vector-set! visited x #t)\n (graph.map-edges g\n x\n (lambda (t)\n (if (not (vector-ref visited t))\n (connected-rec t y)))))\n (call-with-current-continuation\n (lambda (future)\n (set! return future)\n (connected-rec node1 node2)\n (return #f))))\n"
},
{
"answer_id": 53674,
"author": "Sébastien RoccaSerra",
"author_id": 2797,
"author_profile": "https://Stackoverflow.com/users/2797",
"pm_score": 3,
"selected": false,
"text": "amb amb # amb will (appear to) choose values\n# for x and y that prevent future\n# trouble.\nx = amb 1, 2, 3\ny = amb 4, 5, 6\n\n# Ooops! If x*y isn't 8, amb would\n# get angry. You wouldn't like\n# amb when it's angry.\namb if x*y != 8\n\n# Sure enough, x is 2 and y is 4.\nputs x, y \n # A list of places we can \"rewind\" to\n# if we encounter amb with no\n# arguments.\n$backtrack_points = []\n\n# Rewind to our most recent backtrack\n# point.\ndef backtrack\n if $backtrack_points.empty?\n raise \"Can't backtrack\"\n else\n $backtrack_points.pop.call\n end\nend\n\n# Recursive implementation of the\n# amb operator.\ndef amb *choices\n # Fail if we have no arguments.\n backtrack if choices.empty?\n callcc {|cc|\n # cc contains the \"current\n # continuation\". When called,\n # it will make the program\n # rewind to the end of this block.\n $backtrack_points.push cc\n\n # Return our first argument.\n return choices[0]\n }\n\n # We only get here if we backtrack\n # using the stored value of cc,\n # above. We call amb recursively\n # with the arguments we didn't use.\n amb *choices[1...choices.length]\nend\n\n# Backtracking beyond a call to cut\n# is strictly forbidden.\ndef cut\n $backtrack_points = []\nend\n amb"
},
{
"answer_id": 499490,
"author": "Tom Dunham",
"author_id": 6402,
"author_profile": "https://Stackoverflow.com/users/6402",
"pm_score": 1,
"selected": false,
"text": "Async map.getZoomAsync(function(zoom) {\n alert(\"Current zoom level is \" + zoom); // this is the continuation\n}); \nalert(\"This might happen before or after you see the zoom level message\");\n"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/34155",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2797/"
] |
34,161 |
<p>I have the following situation: I built an Access form with a subform (which records are linked to the records of main form via certain key). When I try to delete any record in the subform, I get the following message: “Access has suspended the action because you and another user tried to change the data” (approximate translation from German). Does anyone know how to delete those records from the subform (and, respectively, from the table behind the form).</p>
|
[
{
"answer_id": 34172,
"author": "samjudson",
"author_id": 1908,
"author_profile": "https://Stackoverflow.com/users/1908",
"pm_score": 2,
"selected": true,
"text": "DoCmd.RunCommand acCmdUndo\n"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/34161",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2717/"
] |
34,182 |
<p>I need to read from a variety of different text files (I've some delimited files and some fixed width files). I've considered parsing the files line by line (slow using the File.ReadLine type methods) and reading the file using the ODBC text driver (faster) but does anyone have any other (better) suggestions? I'm using .NET/C#.</p>
|
[
{
"answer_id": 34250,
"author": "ljs",
"author_id": 3394,
"author_profile": "https://Stackoverflow.com/users/3394",
"pm_score": 1,
"selected": false,
"text": "using System.IO;\n\n...\n\npublic class Program {\n public static void Main() {\n foreach(string s in File.ReadAllLines(@\"c:\\foo\\bar\\something.txt\") {\n // Do something with each line...\n }\n }\n}\n"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/34182",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1826/"
] |
34,183 |
<p>I'm trying to run a batch file, as another user, from my web app. For some reason, the batch file hangs! I can see "cmd.exe" running in the task manager, but it just sits there forever, unable to be killed, and the batch file is not running. Here's my code:</p>
<pre><code>SecureString password = new SecureString();
foreach (char c in "mypassword".ToCharArray())
password.AppendChar(c);
ProcessStartInfo psi = new ProcessStartInfo();
psi.WorkingDirectory = @"c:\build";
psi.FileName = Environment.SystemDirectory + @"\cmd.exe";
psi.Arguments = "/q /c build.cmd";
psi.UseShellExecute = false;
psi.UserName = "builder";
psi.Password = password;
Process.Start(psi);
</code></pre>
<p>If you didn't guess, this batch file builds my application (a different application than the one that is executing this command).</p>
<p>The Process.Start(psi); line returns immediately, as it should, but the batch file just seems to hang, without executing. Any ideas?</p>
<p><strong>EDIT:</strong> See my answer below for the contents of the batch file.</p>
<ul>
<li>The output.txt never gets created.</li>
</ul>
<p>I added these lines: </p>
<pre><code>psi.RedirectStandardOutput = true;
Process p = Process.Start(psi);
String outp = p.StandardOutput.ReadLine();
</code></pre>
<p>and stepped through them in debug mode. The code hangs on the <code>ReadLine()</code>. I'm stumped!</p>
|
[
{
"answer_id": 34191,
"author": "Martin Marconcini",
"author_id": 2684,
"author_profile": "https://Stackoverflow.com/users/2684",
"pm_score": 2,
"selected": false,
"text": "Path.Combine( Environment.SystemDirectory, \"cmd.exe\" );\n"
},
{
"answer_id": 34193,
"author": "Biri",
"author_id": 968,
"author_profile": "https://Stackoverflow.com/users/968",
"pm_score": 1,
"selected": false,
"text": "psi.RedirectStandardOutput = True;\nProcess proc = Process.Start(psi);\nString whatever = proc.StandardOutput.ReadLine();\n"
},
{
"answer_id": 34197,
"author": "Josh Hinman",
"author_id": 2527,
"author_profile": "https://Stackoverflow.com/users/2527",
"pm_score": 0,
"selected": false,
"text": "@echo off\nset path=C:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727;%path%\n\nmsbuild myproject.csproj /t:Build > output.txt\nIF NOT ERRORLEVEL 1 goto :end\n\n:error\nbmail -s k2smtpout.secureserver.net -f [email protected] -t [email protected] -a \"Build failed.\" -m output.txt -h\n\n:end\ndel output.txt\n"
},
{
"answer_id": 34205,
"author": "Martin Marconcini",
"author_id": 2684,
"author_profile": "https://Stackoverflow.com/users/2684",
"pm_score": 1,
"selected": false,
"text": "psi.Arguments = @\"/q /c build.cmd\";\n"
},
{
"answer_id": 34801,
"author": "sieben",
"author_id": 1147,
"author_profile": "https://Stackoverflow.com/users/1147",
"pm_score": 0,
"selected": false,
"text": "ProcessStartInfo psi = new ProcessStartInfo();\nProcess p = new Process();\npsi.WindowStyle = ProcessWindowStyle.Hidden;\npsi.WorkingDirectory = @\"c:\\build\";\npsi.FileName = @\"C:\\build\\build.cmd\";\npsi.UseShellExecute = true;\npsi.UserName = \"builder\";\npsi.Password = password;\np.StartInfo = psi;\np.Start();\n"
},
{
"answer_id": 38164,
"author": "sieben",
"author_id": 1147,
"author_profile": "https://Stackoverflow.com/users/1147",
"pm_score": 2,
"selected": false,
"text": "using System;\nusing System.IO;\nusing System.Text;\nusing System.Security;\nusing System.Diagnostics;\n\nnamespace asdf\n{\n class StackoverflowQuestion\n {\n private const string MSBUILD = @\"path\\to\\msbuild.exe\";\n private const string BMAIL = @\"path\\to\\bmail.exe\";\n private const string WORKING_DIR = @\"path\\to\\working_directory\";\n\n private string stdout;\n private Process p;\n\n public void DoWork()\n {\n // build project\n StartProcess(MSBUILD, \"myproject.csproj /t:Build\", true);\n }\n\n public void StartProcess(string file, string args, bool redirectStdout)\n {\n SecureString password = new SecureString();\n foreach (char c in \"mypassword\".ToCharArray())\n password.AppendChar(c);\n\n ProcessStartInfo psi = new ProcessStartInfo();\n p = new Process();\n psi.WindowStyle = ProcessWindowStyle.Hidden;\n psi.WorkingDirectory = WORKING_DIR;\n psi.FileName = file;\n psi.UseShellExecute = false;\n psi.RedirectStandardOutput = redirectStdout;\n psi.UserName = \"builder\";\n psi.Password = password;\n p.StartInfo = psi;\n p.EnableRaisingEvents = true;\n p.Exited += new EventHandler(p_Exited);\n p.Start();\n\n if (redirectStdout)\n {\n stdout = p.StandardOutput.ReadToEnd();\n }\n }\n\n void p_Exited(object sender, EventArgs e)\n {\n if (p.ExitCode != 0)\n {\n // failed\n StringBuilder args = new StringBuilder();\n args.Append(\"-s k2smtpout.secureserver.net \");\n args.Append(\"-f [email protected] \");\n args.Append(\"-t [email protected] \");\n args.Append(\"-a \\\"Build failed.\\\" \");\n args.AppendFormat(\"-m {0} -h\", stdout);\n\n // send email\n StartProcess(BMAIL, args.ToString(), false);\n }\n }\n }\n}\n"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/34183",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2527/"
] |
34,194 |
<p>Where can I find some good pointers on best practices for running ASP.NET MVC on IIS6?</p>
<p>I haven't seen any realistic options for web-hosts who provide IIS7-hosting yet. Mostly because I don't live in the U.S.</p>
<p>So I was wondering on how you best build applications in ASP.NET MVC and make it easily available to deploy on both IIS6 and IIS7. Keep in mind that this is for standard web-hosts, so there is no access to ISAPI-filters or special settings inside IIS6.</p>
<p>Are there anything else one should think about when developing ASP.NET MVC-applications to target IIS6? Any functions that doesn't work?</p>
<p>UPDATE: One of the bigger issues is the thing with routes. The pattern {controller}/{action} will work on IIS7, but not IIS6 which needs {controller}.mvc/{action}. So how do I make this transparent? Again, <strong>no ISAPI</strong> and <strong>no IIS-settings</strong>, please.</p>
|
[
{
"answer_id": 316015,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 5,
"selected": true,
"text": "routes.MapRoute(\n \"Default\", // Route name\n \"{controller}.aspx/{action}/{id}\", // URL with parameters\n new { controller = \"Home\", action = \"Index\", id = \"\" } // Parameter defaults\n);\n routes.MapRoute(\n \"Default2\", // Route name\n \"Default.aspx\", // URL with parameters\n new { controller = \"Home\", action = \"Index\", id = \"\" } // Parameter defaults\n);\n routes.MapRoute(\n \"Default2\", // Route name\n \"{controller}/{action}/{id}\", // URL with parameters\n new { controller = \"Home\", action = \"Index\", id = \"\" } // Parameter defaults\n);\n public class MvcApplication : System.Web.HttpApplication\n{\n public static void RegisterRoutes(RouteCollection routes)\n {\n routes.IgnoreRoute(\"{resource}.axd/{*pathInfo}\");\n\n routes.MapRoute(\n \"Default\", // Route name\n \"{controller}.aspx/{action}/{id}\", // URL with parameters\n new { controller = \"Home\", action = \"Index\", id = \"\" } // Parameter defaults\n );\n\n routes.MapRoute(\n \"Default2\", // Route name\n \"{controller}/{action}/{id}\", // URL with parameters\n new { controller = \"Home\", action = \"Index\", id = \"\" } // Parameter defaults\n );\n }\n\n protected void Application_Start()\n {\n RegisterRoutes(RouteTable.Routes);\n }\n}\n"
},
{
"answer_id": 2687318,
"author": "anov",
"author_id": 181295,
"author_profile": "https://Stackoverflow.com/users/181295",
"pm_score": 0,
"selected": false,
"text": "<%@ Page Language=\"C#\"%>\n<script runat=\"server\">\nprotected void Page_Load(object sender, EventArgs e)\n{\n HttpContext.Current.RewritePath(\"~/Home.aspx/index\");\n IHttpHandler httpHandler = new MvcHttpHandler();\n httpHandler.ProcessRequest(HttpContext.Current);\n}\n</script>\n"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/34194",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2429/"
] |
34,204 |
<p>How do I get the latest version of my solution recursively like its done in the solution explorer context menu of Visual Studio? I want to do this from the command line or via a macro. I'm trying to automate a part of my daily routine by using a set of batch files. I am sure a lot of developers would love to have something like this.</p>
<p><code>tf get</code> only gets contents of a folder recursively (not solution). It does not look at project dependencies and so on. That won't work.</p>
|
[
{
"answer_id": 185256,
"author": "tbreffni",
"author_id": 637,
"author_profile": "https://Stackoverflow.com/users/637",
"pm_score": 3,
"selected": true,
"text": "TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(\"MyServer\");\nVersionControlServer vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));\n\nWorkSpace[] myWorkSpaces = vcs.QueryWorkSpaces(\"MyWorkSpaceName\", \"MyLoginName\", \"MyComputer\");\n\nmyWorkSpaces[0].Get(VersionSpec.Latest, GetOptions.GetAll);\n"
},
{
"answer_id": 10179887,
"author": "TheKnucklehead",
"author_id": 1276038,
"author_profile": "https://Stackoverflow.com/users/1276038",
"pm_score": 2,
"selected": false,
"text": "C:\\Project\\SupportingProjects FOR /D %%G IN (\"*\") DO ECHO ..from....%%G && tf get C:\\Projects\\SupportingProjects\\%%G \n\n::Get the latest for the Main project\ntf get C:\\Projects\\MainProject /recursive \n"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/34204",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/45603/"
] |
34,209 |
<p>In the transition to newforms admin I'm having difficulty figuring out how specify core=False for ImageFields.</p>
<p>I get the following error:</p>
<pre><code>TypeError: __init__() got an unexpected keyword argument 'core'
</code></pre>
<p>[Edit] However, by just removing the core argument I get a "This field is required." error in the admin interface on attempted submission. How does one accomplish what core=False is meant to do using newforms admin?</p>
|
[
{
"answer_id": 35089,
"author": "Dan",
"author_id": 444,
"author_profile": "https://Stackoverflow.com/users/444",
"pm_score": 2,
"selected": false,
"text": "core core"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/34209",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3594/"
] |
34,227 |
<p>I am familiar with several approaches to making the back button work in AJAX applications in various situations, but I have not found a solution that will work gracefully in my specific scenario.</p>
<p>The pages I am working with are the search interface for a site. You enter terms in a normal search box, click "go and wind up at a search results page. On the search results page there are a ton of UI controls for filtering/sorting the search results to find what you are looking for. Some of the operations triggered by these controls may take a (relatively) long time to complete (e.g. several seconds).</p>
<p>This latency is fine in case where the user is initially filtering/sorting their results... there's a nice AJAX spinner and so on... however when the user clicks on a search result and then clicks on the BACK button, I would like the page to instantly be restored to the state it was in when they clicked through. </p>
<p>I can restore the states using IFRAMEs/fragment identifiers as a dictionary of page history, but what ends up happening is that when the user first hits the back button the initial page is loaded, then it (re) makes the AJAX query to get the page state back, which triggers the AJAX spinner and another wait of possible several seconds.</p>
<p>Is there any approach that does not require this kind of two-stage load of the page when the user returns to the page via the BACK button?</p>
<p>Edited to add: I am partial to jquery but I'd be happy with solutions that depend on other libraries/toolkits or that are standalone/raw javascript.</p>
<p>Edited to add: I should've added that I'm trying to avoid cookies/sessions because this prevents people having multiple brower windows/tabs open and manipulating different sets of search results at the same time.</p>
<p>Edit: Matt, can you elaborate on your proposed solution (triggering a page change event via fragment identifer)? I see how this would help with BACK button clicks across the same page but not coming BACK to the search results page after clicking on a specific result.</p>
|
[
{
"answer_id": 271114,
"author": "J.C. Inacio",
"author_id": 35292,
"author_profile": "https://Stackoverflow.com/users/35292",
"pm_score": 0,
"selected": false,
"text": "{\"ajaxcache\":[{\"token\":<token>,\"time\":<time>,\"data\":<data>}, ... ]}\n"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/34227",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2168/"
] |
34,249 |
<p>What's the best (halting) algorithm for determining if a linked list has a cycle in it?</p>
<p>[Edit] Analysis of asymptotic complexity for both time and space would be sweet so answers can be compared better.</p>
<p>[Edit] Original question was not addressing nodes with outdegree > 1, but there's some talk about it. That question is more along the lines of "Best algorithm to detect cycles in a directed graph".</p>
|
[
{
"answer_id": 34255,
"author": "DrPizza",
"author_id": 2131,
"author_profile": "https://Stackoverflow.com/users/2131",
"pm_score": 7,
"selected": true,
"text": "node* tortoise(begin), * hare(begin);\nwhile(hare = hare->next)\n{\n if(hare == tortoise) { throw std::logic_error(\"There's a cycle\"); }\n hare = hare->next;\n if(hare == tortoise) { throw std::logic_error(\"There's a cycle\"); }\n tortoise = tortoise->next;\n}\n"
},
{
"answer_id": 14070358,
"author": "Harry He",
"author_id": 1092195,
"author_profile": "https://Stackoverflow.com/users/1092195",
"pm_score": 0,
"selected": false,
"text": "bool HasLoop(ListNode* pHead)\n{\n if(pHead == NULL)\n return false;\n\n\n ListNode* pSlow = pHead->m_pNext;\n if(pSlow == NULL)\n return false;\n\n\n ListNode* pFast = pSlow->m_pNext;\n while(pFast != NULL && pSlow != NULL)\n {\n if(pFast == pSlow)\n return true;\n\n\n pSlow = pSlow->m_pNext;\n\n\n pFast = pFast->m_pNext;\n if(pFast != NULL)\n pFast = pFast->m_pNext;\n }\n\n\n return false;\n}\n"
},
{
"answer_id": 19701109,
"author": "Ayrat",
"author_id": 801203,
"author_profile": "https://Stackoverflow.com/users/801203",
"pm_score": 0,
"selected": false,
"text": "next"
},
{
"answer_id": 38452940,
"author": "FlyingAura",
"author_id": 3426358,
"author_profile": "https://Stackoverflow.com/users/3426358",
"pm_score": 0,
"selected": false,
"text": "def hash_cycle(node):\n hashl=[]\n while(node):\n if node in hashl:\n return True\n else:\n hashl.append(node)\n node=node.next\n return False\n"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/34249",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3594/"
] |
34,284 |
<p>I get the following error when building my Windows Forms solution: </p>
<blockquote>
<p>"LC.exe" exited with code -1</p>
</blockquote>
<p>I use two commercial Windows Forms Libraries: Infragistics and the Gantt-Control from plexityhide.com, that's why I have licenses.licx files in my WinForms Projects. We also use Visual Sourcesafe as our Source Control.</p>
<p>When the licenses.licx files are in the Projects I cannot build without the above error. However, when I exclude them from my projects the build works fine. But I need the licenses.licx files when I want to work with the commercial controls in the designer.</p>
<p>This is a brand new developer machine with Windows XP SP3 (German) and Visual Studio 2005 Team Edition for Software Developers (German) with SP1. </p>
<p>It's Windows XP 32-Bit by the way.</p>
<p>Any suggestions?</p>
|
[
{
"answer_id": 34310,
"author": "Timbo",
"author_id": 1810,
"author_profile": "https://Stackoverflow.com/users/1810",
"pm_score": 2,
"selected": false,
"text": "x.y.z.*"
},
{
"answer_id": 6531709,
"author": "rahul chavan",
"author_id": 822597,
"author_profile": "https://Stackoverflow.com/users/822597",
"pm_score": 5,
"selected": false,
"text": "licenses.licx"
},
{
"answer_id": 10311386,
"author": "vezenkov",
"author_id": 1025264,
"author_profile": "https://Stackoverflow.com/users/1025264",
"pm_score": 1,
"selected": false,
"text": "license.licx \"LC.EXE\" exited with code -1"
},
{
"answer_id": 59926886,
"author": "cjspuy",
"author_id": 6649339,
"author_profile": "https://Stackoverflow.com/users/6649339",
"pm_score": 1,
"selected": false,
"text": "licenses.licx licenses.licx licenses.licx"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/34284",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3353/"
] |
34,286 |
<p>I'm looking for a way to visually mark or tag a window (any OS) so that it stands out.</p>
<p>A while back, I accidentally replaced a live production database containing thousands of records with an empty dev version, simply because the two instances of Enterprise Manager looked identical to one another. I'd like to avoid that in the future!</p>
|
[
{
"answer_id": 34302,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 0,
"selected": false,
"text": "root"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/34286",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/45603/"
] |
34,301 |
<p>At work, we have multiple branches that we may be working on at any time.
Our solution so far as been to create multiple web-sites but you can only run one web-site at a time. This makes switching between branches more of a pain that in should be. </p>
<p>I just want to go to the URL, mapped in my hosts file, for that branch and it just work. </p>
<p>Our client machines are XP machines with IIS 5.1. Is there any way to make IIS 5.1 run more than one web-site simultaneously?</p>
|
[
{
"answer_id": 34323,
"author": "Espo",
"author_id": 2257,
"author_profile": "https://Stackoverflow.com/users/2257",
"pm_score": 0,
"selected": false,
"text": "Request.ServerVariables[\"SERVER-NAME\"]"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/34301",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/854/"
] |
34,312 |
<p>I was wondering if anyone that has experience in both this stuff can shed some light on the <em>significant</em> difference between the two if any?</p>
<p>Any specific strength of each that makes it suitable for any specific case?</p>
|
[
{
"answer_id": 4534779,
"author": "T0xicCode",
"author_id": 142020,
"author_profile": "https://Stackoverflow.com/users/142020",
"pm_score": 2,
"selected": false,
"text": "pear upgrade"
},
{
"answer_id": 8715966,
"author": "edorian",
"author_id": 285578,
"author_profile": "https://Stackoverflow.com/users/285578",
"pm_score": 8,
"selected": true,
"text": "web interface to phpunit tests pear channel-discover pear.phpunit.de\npear install phpunit/PHPUnit\n PHPUnit 3.7 PHAR Archive wget http://pear.phpunit.de/get/phpunit.phar\nchmod +x phpunit-3.7.6.phar\n php phpunit-.phar\n \"require-dev\": {\n \"phpunit/phpunit\": \"3.7.*\"\n}\n"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/34312",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2976/"
] |
34,365 |
<p>Here's a wierd one. I'm reusing a code base that unfortunately must not be updated. This code makes a call to <code>HttpContext.Current.Request.QueryString</code>. Ideally, I need to push a value into this collection with every request that is made. Is this possible - perhaps in an HTTP Module?</p>
|
[
{
"answer_id": 34375,
"author": "Espo",
"author_id": 2257,
"author_profile": "https://Stackoverflow.com/users/2257",
"pm_score": 4,
"selected": true,
"text": "context.RewritePath(context.Request.Path, context.Request.PathInfo, newQueryStringHere!);\n"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/34365",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1735/"
] |
34,390 |
<p>Since there are no header sections for user controls in asp.net, user controls have no way of knowing about stylesheet files. So css classes in the user controls are not recognized by visual studio and produces warnings. How can I make a user control know that it will relate to a css class, so if it is warning me about a non-existing css class, it means that the class really do not exist?</p>
<p>Edit: Or should I go for a different design like exposing css classes as properties like "HeaderStyle-CssClass" of GridView?</p>
|
[
{
"answer_id": 34502,
"author": "Adam Lassek",
"author_id": 1249,
"author_profile": "https://Stackoverflow.com/users/1249",
"pm_score": 7,
"selected": true,
"text": "<link rel=\"Stylesheet\" type=\"text/css\" href=\"Stylesheet.css\" id=\"style\" runat=\"server\" visible=\"false\" />\n <% if (false) { %>\n <link rel=\"Stylesheet\" type=\"text/css\" href=\"Stylesheet.css\" />\n <script type=\"text/javascript\" src=\"js/jquery-1.2.6.js\" />\n<% } %>\n"
},
{
"answer_id": 9953418,
"author": "Kirtish Srivastava",
"author_id": 1304634,
"author_profile": "https://Stackoverflow.com/users/1304634",
"pm_score": -1,
"selected": false,
"text": "CSS userControl UserControl <head>\n <title></title> \n <style type=\"text/css\">\n .wrapper {\n margin: 0 auto -142px; \n /* the bottom margin is the negative value of the footer's height */ \n }\n </style>\n </head>\n"
},
{
"answer_id": 14774992,
"author": "Abdul Saboor",
"author_id": 1176903,
"author_profile": "https://Stackoverflow.com/users/1176903",
"pm_score": 2,
"selected": false,
"text": " <%@ Control Language=\"vb\" AutoEventWireup=\"false\" CodeBehind=\"WCReportCalendar.ascx.vb\"\nInherits=\"Intra.WCReportCalender\" %>\n <style type='text/css'> \n @import url(\"path of file.css\");\n // This is how i used jqueryui css\n @import url(\"http://code.jquery.com/ui/1.10.0/themes/base/jquery-ui.css\"); \n\n </style>\n\n your html \n"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/34390",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31505/"
] |
34,394 |
<p>How would you programmacially abbreviate <code>XHTML</code> to an arbitrary number of words without leaving unclosed or corrupted tags?</p>
<p>i.e.</p>
<pre><code><p>
Proin tristique dapibus neque. Nam eget purus sit amet leo
tincidunt accumsan.
</p>
<p>
Proin semper, orci at mattis blandit, augue justo blandit nulla.
<span>Quisque ante congue justo</span>, ultrices aliquet, mattis eget,
hendrerit, <em>justo</em>.
</p>
</code></pre>
<p>Abbreviated to 25 words would be:</p>
<pre><code><p>
Proin tristique dapibus neque. Nam eget purus sit amet leo
tincidunt accumsan.
</p>
<p>
Proin semper, orci at mattis blandit, augue justo blandit nulla.
<span>Quisque ante congue...</span>
</p>
</code></pre>
|
[
{
"answer_id": 34502,
"author": "Adam Lassek",
"author_id": 1249,
"author_profile": "https://Stackoverflow.com/users/1249",
"pm_score": 7,
"selected": true,
"text": "<link rel=\"Stylesheet\" type=\"text/css\" href=\"Stylesheet.css\" id=\"style\" runat=\"server\" visible=\"false\" />\n <% if (false) { %>\n <link rel=\"Stylesheet\" type=\"text/css\" href=\"Stylesheet.css\" />\n <script type=\"text/javascript\" src=\"js/jquery-1.2.6.js\" />\n<% } %>\n"
},
{
"answer_id": 9953418,
"author": "Kirtish Srivastava",
"author_id": 1304634,
"author_profile": "https://Stackoverflow.com/users/1304634",
"pm_score": -1,
"selected": false,
"text": "CSS userControl UserControl <head>\n <title></title> \n <style type=\"text/css\">\n .wrapper {\n margin: 0 auto -142px; \n /* the bottom margin is the negative value of the footer's height */ \n }\n </style>\n </head>\n"
},
{
"answer_id": 14774992,
"author": "Abdul Saboor",
"author_id": 1176903,
"author_profile": "https://Stackoverflow.com/users/1176903",
"pm_score": 2,
"selected": false,
"text": " <%@ Control Language=\"vb\" AutoEventWireup=\"false\" CodeBehind=\"WCReportCalendar.ascx.vb\"\nInherits=\"Intra.WCReportCalender\" %>\n <style type='text/css'> \n @import url(\"path of file.css\");\n // This is how i used jqueryui css\n @import url(\"http://code.jquery.com/ui/1.10.0/themes/base/jquery-ui.css\"); \n\n </style>\n\n your html \n"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/34394",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3187/"
] |
34,395 |
<p>I would like to put a string into a byte array, but the string may be too big to fit. In the case where it's too large, I would like to put as much of the string as possible into the array. Is there an efficient way to find out how many characters will fit?</p>
|
[
{
"answer_id": 34431,
"author": "otsdr",
"author_id": 321238,
"author_profile": "https://Stackoverflow.com/users/321238",
"pm_score": 4,
"selected": true,
"text": "static string Truncate(string s, int maxLength) {\n if (Encoding.UTF8.GetByteCount(s) <= maxLength)\n return s;\n var cs = s.ToCharArray();\n int length = 0;\n int i = 0;\n while (i < cs.Length){\n int charSize = 1;\n if (i < (cs.Length - 1) && char.IsSurrogate(cs[i]))\n charSize = 2;\n int byteSize = Encoding.UTF8.GetByteCount(cs, i, charSize);\n if ((byteSize + length) <= maxLength){\n i = i + charSize;\n length += byteSize;\n }\n else\n break;\n }\n return s.Substring(0, i);\n}\n"
},
{
"answer_id": 34448,
"author": "skolima",
"author_id": 3205,
"author_profile": "https://Stackoverflow.com/users/3205",
"pm_score": 1,
"selected": false,
"text": "Encoding.GetMaxByteCount(1);\n public virtual int Encoding.GetBytes (\n string s,\n int charIndex,\n int charCount,\n byte[] bytes,\n int byteIndex\n)\n Encoding.GetByteCount(string);\n"
},
{
"answer_id": 34450,
"author": "Joseph Daigle",
"author_id": 507,
"author_profile": "https://Stackoverflow.com/users/507",
"pm_score": 1,
"selected": false,
"text": "GetByteCount GetMaxByteCount"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/34395",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2348/"
] |
34,398 |
<p>I have a new database table I need to create...<br>
It logically contains an <code>ID</code>, a <code>name</code>, and a <code>"value"</code>.<br>
That value field could be either numeric or a character string in nature. </p>
<p>I don't think I want to just make the field a <code>varchar</code>, because I also want to be able to query with filters like <code>WHERE value > 0.5</code> and such.</p>
<p>What's the best way to model this concept in SQL Server 2005?</p>
<p><strong>EDIT:</strong>
I'm not opposed to creating multiple fields here (one for numbers, one for non-numbers), but since they're all really the same concept, I wasn't sure that was a great idea.<br>
I guess I could create separate fields, then have a view that sort of coalesces them into a single logical column. </p>
<p>Any opinions on that?</p>
<p>What I want to achieve is really pretty simple... usually this data will just be blindly displayed in a grid-type view.<br>
I want to be also able to filter on the numeric values in that grid. This table will end up being in the tens of millions of records, so I don't want to paint myself into a corner with querying performance.<br>
That querying performance is my main concern.</p>
|
[
{
"answer_id": 34406,
"author": "jason saldo",
"author_id": 1293,
"author_profile": "https://Stackoverflow.com/users/1293",
"pm_score": 0,
"selected": false,
"text": "Table: (ValueLable as char(x), Value as numerica(p,s))\n"
},
{
"answer_id": 34408,
"author": "Ryan Ahearn",
"author_id": 75,
"author_profile": "https://Stackoverflow.com/users/75",
"pm_score": 0,
"selected": false,
"text": "WHERE value_type = 'number' AND number_value > 0.5\n"
},
{
"answer_id": 34480,
"author": "Keith",
"author_id": 905,
"author_profile": "https://Stackoverflow.com/users/905",
"pm_score": 3,
"selected": true,
"text": "where value > '20.5'\n select [ID], [Name], Coalesce( [value_str], [value_num] )\nfrom [tablename]\n"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/34398",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/404/"
] |
34,399 |
<p>I have an html file with an unordered list. I want to show the list items horizontally but still keep the bullets. No matter what I try, whenever I set the style to inline to meet the horizontal requirement I can't get the bullets to display.</p>
|
[
{
"answer_id": 34427,
"author": "Erik van Brakel",
"author_id": 909,
"author_profile": "https://Stackoverflow.com/users/909",
"pm_score": 1,
"selected": false,
"text": "float: left <li/> <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n<html>\n<head>\n <style type=\"text/css\">\n ul li {\n float: left;\n margin-left: 2em;\n }\n </style>\n</head>\n<body>\n <ul>\n <li>test</li>\n <li>test2</li>\n </ul>\n</body>\n</html>\n margin <ul/> ul {\n overflow: auto;\n background: #f0f;\n}\n"
},
{
"answer_id": 34443,
"author": "Chris Marasti-Georg",
"author_id": 96,
"author_profile": "https://Stackoverflow.com/users/96",
"pm_score": 3,
"selected": false,
"text": "li {\n background-image: url(i/bullet.gif) no-repeat center left;\n padding-left: 20px;\n display: inline;\n}\n"
},
{
"answer_id": 34656,
"author": "Joel Coehoorn",
"author_id": 3043,
"author_profile": "https://Stackoverflow.com/users/3043",
"pm_score": 6,
"selected": true,
"text": "float:left; •"
},
{
"answer_id": 201798,
"author": "Peter Hilton",
"author_id": 2670,
"author_profile": "https://Stackoverflow.com/users/2670",
"pm_score": 5,
"selected": false,
"text": "ul.tabs li {\n list-style: none;\n float: left;\n}\nul.tabs li:before {\n content: '\\ffed';\n margin-right: 0.5em;\n}\n"
},
{
"answer_id": 15607606,
"author": "user2194160",
"author_id": 2194160,
"author_profile": "https://Stackoverflow.com/users/2194160",
"pm_score": -1,
"selected": false,
"text": "li {\n background-image: url(img.gif) no-repeat center left;\n padding-left: 20px;\n display: inline;\n}\n"
},
{
"answer_id": 19989335,
"author": "L.Jordens",
"author_id": 2994084,
"author_profile": "https://Stackoverflow.com/users/2994084",
"pm_score": 2,
"selected": false,
"text": "display:list-item;\n"
},
{
"answer_id": 29008904,
"author": "kris",
"author_id": 3061233,
"author_profile": "https://Stackoverflow.com/users/3061233",
"pm_score": 0,
"selected": false,
"text": "<ul class=\"inline-list>\n <li> • Your list item </li>\n</ul>\n"
},
{
"answer_id": 34168327,
"author": "AenAllAin",
"author_id": 3546985,
"author_profile": "https://Stackoverflow.com/users/3546985",
"pm_score": 2,
"selected": false,
"text": "<div class=\"block-list\">\n <ul>\n <li><ul><li>a</li></ul></li>\n <li><ul><li>b</li></ul></li>\n <li><ul><li>c</li></ul></li>\n </ul>\n</div>\n .block-list > ul > li { display: inline; float: left; }\n o a o b o c\n"
},
{
"answer_id": 46148156,
"author": "YeRe415",
"author_id": 8585408,
"author_profile": "https://Stackoverflow.com/users/8585408",
"pm_score": 0,
"selected": false,
"text": "<li>Water is Sacred</li><br>\n<li>Water is Sacred</li><br>\n<li>Water is Sacred</li><br>\n<li>Water is Sacred</li><br>\n<li>Water is Sacred</li><br>\n<li>Water is Sacred</li><br> \n li { float:left; }\n"
},
{
"answer_id": 62758705,
"author": "Leon",
"author_id": 3619192,
"author_profile": "https://Stackoverflow.com/users/3619192",
"pm_score": 1,
"selected": false,
"text": "<ul> <li> <li> ul {\n display: grid;\n grid-template-columns: 100px 100px 100px; /* or a smarter width setting */\n} <ul>\n <li>item 1</li>\n <li>item 2</li>\n <li>item 3</li>\n</ul>"
},
{
"answer_id": 63530912,
"author": "MazeChaZer",
"author_id": 1276288,
"author_profile": "https://Stackoverflow.com/users/1276288",
"pm_score": 0,
"selected": false,
"text": "float: left ul ul {\n display: flex;\n flex-wrap: wrap;\n}\n\nli {\n margin-right: 24px;\n}\n"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/34399",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3043/"
] |
34,401 |
<p>Is anyone using Elmah to send exceptions via email? I've got Elmah logging set up via SQL Server, and can view the errors page via the Elmah.axd page, but I am unable to get the email component working. The idea here is to get the email notification so we can react more quickly to exceptions. Here is my web.config (unnecessary sectionss omitted), with all the sensitive data replaced by * * *. Even though I am specifying a server to connect to, does the SMTP service need to be running on the local machine?</p>
<pre><code><?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="elmah">
<section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah"/>
<section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah"/>
<section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah"/>
</sectionGroup>
</configSections>
<appSettings/>
<connectionStrings>
<add name="elmah-sql" connectionString="Data Source=***;Initial Catalog=***;Persist Security Info=True;User ID=***;Password=***" />
</connectionStrings>
<elmah>
<errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="elmah-sql" >
</errorLog>
<errorMail from="[email protected]"
to="[email protected]"
subject="Application Exception"
async="false"
smtpPort="25"
smtpServer="***"
userName="***"
password="***">
</errorMail>
</elmah>
<system.web>
<customErrors mode="RemoteOnly" defaultRedirect="CustomError.aspx">
<error statusCode="403" redirect="NotAuthorized.aspx" />
<!--<error statusCode="404" redirect="FileNotFound.htm" />-->
</customErrors>
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
<add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
</httpHandlers>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah"/>
</httpModules>
</system.web>
</configuration>
</code></pre>
|
[
{
"answer_id": 34435,
"author": "TonyB",
"author_id": 3543,
"author_profile": "https://Stackoverflow.com/users/3543",
"pm_score": 7,
"selected": true,
"text": "<add name=\"ErrorMail\" type=\"Elmah.ErrorMailModule, Elmah\" />\n"
},
{
"answer_id": 7254040,
"author": "Anand Patel",
"author_id": 840003,
"author_profile": "https://Stackoverflow.com/users/840003",
"pm_score": 6,
"selected": false,
"text": "<configSections>\n <sectionGroup name=\"elmah\">\n <section name=\"errorMail\" requirePermission=\"false\" type=\"Elmah.ErrorMailSectionHandler, Elmah\"> \n </sectionGroup>\n</configSections> \n\n<elmah> \n <errorMail from=\"from Mail Address\" to=\"to mail address\" \n async=\"true\" smtpPort=\"0\" useSsl=\"true\" /> \n</elmah>\n\n<system.net> \n <mailSettings> \n <smtp deliveryMethod =\"Network\"> \n <network host=\"smtp.gmail.com\" port=\"587\" userName=\"yourgmailEmailAddress\" password=\"yourGmailEmailPassword\" /> \n </smtp> \n </mailSettings> \n</system.net>\n"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/34401",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1284/"
] |
34,411 |
<p>I always tend to forget these built-in <strong>Symfony</strong> functions for making links.</p>
|
[
{
"answer_id": 36026,
"author": "jamz",
"author_id": 3734,
"author_profile": "https://Stackoverflow.com/users/3734",
"pm_score": 4,
"selected": true,
"text": "recent_questions:\n url: questions/recent/:page\n param: { module: questions, action: recent, page: 1 }\n url_for() <a href=\"<?php echo url_for('questions/recent?page=1') ?>\">Recent Questions</a>\n http://myapp/questions/recent/1.html :/page link_to() <a>"
},
{
"answer_id": 372205,
"author": "thrashr888",
"author_id": 46443,
"author_profile": "https://Stackoverflow.com/users/46443",
"pm_score": 0,
"selected": false,
"text": "link_to('My link name', 'yourmodule/youraction?key=value&key2=value',array('query_string'=>'page=2'));\n"
},
{
"answer_id": 8052024,
"author": "priyabagus",
"author_id": 1035374,
"author_profile": "https://Stackoverflow.com/users/1035374",
"pm_score": 0,
"selected": false,
"text": "$this->generateUrl('default', array('module'=>'[ModuleName]','action'=>'[ActionName]'))\n url_for('[ModuleName]/[ActionName]', $absolute)\n <a href=\"\"></a>"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/34411",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2108/"
] |
34,413 |
<p>I am getting a <code>NoClassDefFoundError</code> when I run my Java application. What is typically the cause of this?</p>
|
[
{
"answer_id": 34444,
"author": "shsteimer",
"author_id": 292,
"author_profile": "https://Stackoverflow.com/users/292",
"pm_score": 5,
"selected": false,
"text": "set classpath=%classpath%;axis.jar\n set classpath=axis.jar;%classpath%;\n"
},
{
"answer_id": 5756989,
"author": "Jared",
"author_id": 44757,
"author_profile": "https://Stackoverflow.com/users/44757",
"pm_score": 10,
"selected": false,
"text": "java.lang.ClassNotFoundException java.lang.NoClassDefFoundError"
},
{
"answer_id": 28507116,
"author": "xli",
"author_id": 1018906,
"author_profile": "https://Stackoverflow.com/users/1018906",
"pm_score": 7,
"selected": false,
"text": "java.lang.NoClassDefFoundError public class NoClassDefFoundErrorDemo {\n public static void main(String[] args) {\n try {\n // The following line would throw ExceptionInInitializerError\n SimpleCalculator calculator1 = new SimpleCalculator();\n } catch (Throwable t) {\n System.out.println(t);\n }\n // The following line would cause NoClassDefFoundError\n SimpleCalculator calculator2 = new SimpleCalculator();\n }\n\n}\n public class SimpleCalculator {\n static int undefined = 1 / 0;\n}\n"
},
{
"answer_id": 31914707,
"author": "Nikhil Sahu",
"author_id": 1889574,
"author_profile": "https://Stackoverflow.com/users/1889574",
"pm_score": 3,
"selected": false,
"text": "NoClassDefFoundError ExceptionInInitializerError"
},
{
"answer_id": 32479072,
"author": "codeDr",
"author_id": 108153,
"author_profile": "https://Stackoverflow.com/users/108153",
"pm_score": 3,
"selected": false,
"text": "// ClassLoaderTracer.java\n// From: https://blogs.oracle.com/sundararajan/entry/tracing_class_loading_1_5\n\nimport java.lang.instrument.*;\nimport java.security.*;\n\n// manifest.mf\n// Premain-Class: ClassLoadTracer\n\n// jar -cvfm tracer.jar manifest.mf ClassLoaderTracer.class\n\n// java -javaagent:tracer.jar [...]\n\npublic class ClassLoadTracer \n{\n public static void premain(String agentArgs, Instrumentation inst) \n {\n final java.io.PrintStream out = System.out;\n inst.addTransformer(new ClassFileTransformer() {\n public byte[] transform(ClassLoader loader, String className, Class classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {\n\n String pd = (null == protectionDomain) ? \"null\" : protectionDomain.getCodeSource().toString();\n out.println(className + \" loaded by \" + loader + \" at \" + new java.util.Date() + \" in \" + pd);\n\n // dump stack trace of the thread loading class \n Thread.dumpStack();\n\n // we just want the original .class bytes to be loaded!\n // we are not instrumenting it...\n return null;\n }\n });\n }\n}\n"
},
{
"answer_id": 32593355,
"author": "Ram Patra",
"author_id": 1385441,
"author_profile": "https://Stackoverflow.com/users/1385441",
"pm_score": 3,
"selected": false,
"text": "org.mypackage D:\\myprogram /home/user/myprogram org.mypackage.HelloWorld"
},
{
"answer_id": 36870883,
"author": "Alex ",
"author_id": 4644763,
"author_profile": "https://Stackoverflow.com/users/4644763",
"pm_score": -1,
"selected": false,
"text": "module:app module:lib android {\n compileSdkVersion 23\n buildToolsVersion '22.0.1'\n packagingOptions {\n }\n\n defaultConfig {\n minSdkVersion 17\n targetSdkVersion 23\n versionCode 11\n versionName \"2.1\"\n }\n"
},
{
"answer_id": 38383004,
"author": "sudar",
"author_id": 5555429,
"author_profile": "https://Stackoverflow.com/users/5555429",
"pm_score": -1,
"selected": false,
"text": "private static HttpHost proxy = new HttpHost(proxyHost, Integer.valueOf(proxyPort), \"http\");\n"
},
{
"answer_id": 38614741,
"author": "Aram Paronikyan",
"author_id": 1682984,
"author_profile": "https://Stackoverflow.com/users/1682984",
"pm_score": 2,
"selected": false,
"text": "System.out.println(TheNoDefFoundClass.class.getProtectionDomain().getCodeSource().getLocation());\n"
},
{
"answer_id": 44632379,
"author": "ST7",
"author_id": 1855286,
"author_profile": "https://Stackoverflow.com/users/1855286",
"pm_score": 0,
"selected": false,
"text": "java.lang.NoClassDefFoundError: org/apache/log4j/Logger log4j-1.2-api-<version>.jar"
},
{
"answer_id": 46925897,
"author": "manuelvigarcia",
"author_id": 5108777,
"author_profile": "https://Stackoverflow.com/users/5108777",
"pm_score": 1,
"selected": false,
"text": "NoClassDefFoundError"
},
{
"answer_id": 48615116,
"author": "Michael",
"author_id": 2739201,
"author_profile": "https://Stackoverflow.com/users/2739201",
"pm_score": 1,
"selected": false,
"text": "dexOptions {\n preDexLibraries false\n ...\n"
},
{
"answer_id": 49601683,
"author": "Brent Bradburn",
"author_id": 86967,
"author_profile": "https://Stackoverflow.com/users/86967",
"pm_score": 0,
"selected": false,
"text": "sdk list java\nsdk install java 8u152-zulu\nsdk use java 8u152-zulu\n mvn clean install -DskipTests\n mvn test\n"
},
{
"answer_id": 52544691,
"author": "ᴠɪɴᴄᴇɴᴛ",
"author_id": 1548776,
"author_profile": "https://Stackoverflow.com/users/1548776",
"pm_score": 1,
"selected": false,
"text": "NoClassDefFoundError META-INF NoClassDefFoundError catch Throwable try {\n // Statement(s) that cause(s) the affected class to be loaded\n} catch (Throwable t) {\n Logger.getLogger(\"<logger-name>\").info(\"Loading my class went wrong\", t);\n}\n"
},
{
"answer_id": 53616950,
"author": "Bartek Lipinski",
"author_id": 1993204,
"author_profile": "https://Stackoverflow.com/users/1993204",
"pm_score": 3,
"selected": false,
"text": "NoClassDefFoundErrors throw RuntimeException static Example Example static class Example {\n static {\n thisThrowsRuntimeException();\n }\n}\n\nstatic class OuterClazz {\n\n OuterClazz() {\n try {\n new Example();\n } catch (Throwable ignored) { //simulating catching RuntimeException from static block\n // DO NOT DO THIS IN PRODUCTION CODE, THIS IS JUST AN EXAMPLE in StackOverflow\n }\n\n new Example(); //this throws NoClassDefFoundError\n }\n}\n NoClassDefError ExceptionInInitializerError RuntimeException NoClassDefFoundErrors static ExceptionInInitializerError Example Example NoClassDefFoundErrors"
},
{
"answer_id": 58654225,
"author": "Alan Ackart",
"author_id": 6060637,
"author_profile": "https://Stackoverflow.com/users/6060637",
"pm_score": 1,
"selected": false,
"text": "-Xss2m"
},
{
"answer_id": 64129484,
"author": "Thomas McSwain",
"author_id": 6741141,
"author_profile": "https://Stackoverflow.com/users/6741141",
"pm_score": 0,
"selected": false,
"text": "package valentines;\n\nimport java.math.BigInteger;\nimport java.util.ArrayList;\n\npublic class StudentSolver {\n public static ArrayList<Boolean> solve(ArrayList<ArrayList<BigInteger>> problems) {\n //DOING WORK HERE\n \n }\n public static void main(String[] args){\n //TESTING SOLVE FUNCTION\n }\n \n}\n java StudentSolver package valentines;"
},
{
"answer_id": 66816030,
"author": "yoAlex5",
"author_id": 4770877,
"author_profile": "https://Stackoverflow.com/users/4770877",
"pm_score": 2,
"selected": false,
"text": "Static(Implicit) class loading MyClass myClass = new MyClass();\n Dynamic(Explicit) class loading MyClass myClass = (MyClass) Class.forName(\"MyClass\").newInstance();\n ClassLoader loadClass(String name); explicit class loader uses implicit class loader\n NoClassDefFoundError explicit class loader Error ClassNotFoundException implicit class loader Exception"
},
{
"answer_id": 74520294,
"author": "douglas",
"author_id": 5930157,
"author_profile": "https://Stackoverflow.com/users/5930157",
"pm_score": 0,
"selected": false,
"text": "javac --classpath \"ext/commons-io-2.11.0;ext/bc-fips-1.0.2.3\" hello.java\n Error: Unable to initialize main class hello\nCaused by: java.lang.NoClassDefFoundError: \norg/bouncycastle/jcajce/provider/BouncyCastleFipsProvider\n"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/34413",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3535/"
] |
34,439 |
<p>Given a Python object of any kind, is there an easy way to get the list of all methods that this object has?</p>
<p>Or,</p>
<p>if this is not possible, is there at least an easy way to check if it has a particular method other than simply checking if an error occurs when the method is called?</p>
|
[
{
"answer_id": 34452,
"author": "ljs",
"author_id": 3394,
"author_profile": "https://Stackoverflow.com/users/3394",
"pm_score": 10,
"selected": true,
"text": "object_methods = [method_name for method_name in dir(object)\n if callable(getattr(object, method_name))]\n AttributeError getattr() import pandas as pd\ndf = pd.DataFrame([[10, 20, 30], [100, 200, 300]],\n columns=['foo', 'bar', 'baz'])\ndef get_methods(object, spacing=20):\n methodList = []\n for method_name in dir(object):\n try:\n if callable(getattr(object, method_name)):\n methodList.append(str(method_name))\n except Exception:\n methodList.append(str(method_name))\n processFunc = (lambda s: ' '.join(s.split())) or (lambda s: s)\n for method in methodList:\n try:\n print(str(method.ljust(spacing)) + ' ' +\n processFunc(str(getattr(object, method).__doc__)[0:90]))\n except Exception:\n print(method.ljust(spacing) + ' ' + ' getattr() failed')\n\nget_methods(df['foo'])\n"
},
{
"answer_id": 34467,
"author": "Bill the Lizard",
"author_id": 1288,
"author_profile": "https://Stackoverflow.com/users/1288",
"pm_score": 8,
"selected": false,
"text": "dir() >>> import moduleName\n>>> dir(moduleName)\n hasattr(module_name, \"attr_name\")"
},
{
"answer_id": 34472,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 5,
"selected": false,
"text": "hasattr(object,\"method\")\n"
},
{
"answer_id": 34481,
"author": "jmanning2k",
"author_id": 1480,
"author_profile": "https://Stackoverflow.com/users/1480",
"pm_score": 5,
"selected": false,
"text": "help(object.method)\n"
},
{
"answer_id": 15640132,
"author": "Bruno Bronosky",
"author_id": 117471,
"author_profile": "https://Stackoverflow.com/users/117471",
"pm_score": 1,
"selected": false,
"text": "d={'foo':'bar', 'spam':'eggs'}\nif 'get' in dir(d):\n d.get('foo')\n# OUT: 'bar'\n"
},
{
"answer_id": 20100900,
"author": "Pawan Kumar",
"author_id": 1668274,
"author_profile": "https://Stackoverflow.com/users/1668274",
"pm_score": 7,
"selected": false,
"text": "dir(objectname)"
},
{
"answer_id": 27380776,
"author": "Cld",
"author_id": 3973130,
"author_profile": "https://Stackoverflow.com/users/3973130",
"pm_score": 3,
"selected": false,
"text": "__getattr__ __getattribute__ class MoreMethod(object):\n def some_method(self, x):\n return x\n def __getattr__(self, *args):\n return lambda x: x*2\n >>> o = MoreMethod()\n>>> o.some_method(5)\n5\n>>> dir(o)\n['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattr__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'some_method']\n>>> o.i_dont_care_of_the_name(5)\n10\n"
},
{
"answer_id": 28220562,
"author": "paulmelnikow",
"author_id": 893113,
"author_profile": "https://Stackoverflow.com/users/893113",
"pm_score": 4,
"selected": false,
"text": "import inspect\nmethod_names = [attr for attr in dir(self) if inspect.ismethod(getattr(self, attr))]\n import inspect\nmethods = [member for member in [getattr(self, attr) for attr in dir(self)] if inspect.ismethod(member)]\n inspect.isroutine"
},
{
"answer_id": 29851741,
"author": "james_womack",
"author_id": 230571,
"author_profile": "https://Stackoverflow.com/users/230571",
"pm_score": 1,
"selected": false,
"text": "getAttrs def getAttrs(object):\n return filter(lambda m: callable(getattr(object, m)), dir(object))\n\nprint getAttrs('Foo bar'.split(' '))\n ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__',\n '__delslice__', '__eq__', '__format__', '__ge__', '__getattribute__', \n '__getitem__', '__getslice__', '__gt__', '__iadd__', '__imul__', '__init__', \n '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', \n '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', \n '__setattr__', '__setitem__', '__setslice__', '__sizeof__', '__str__', \n '__subclasshook__', 'append', 'count', 'extend', 'index', 'insert', 'pop', \n 'remove', 'reverse', 'sort']\n"
},
{
"answer_id": 32608298,
"author": "aver",
"author_id": 3165751,
"author_profile": "https://Stackoverflow.com/users/3165751",
"pm_score": 2,
"selected": false,
"text": "dir(object) dir() callable(getattr(object, method))"
},
{
"answer_id": 37464502,
"author": "ivanleoncz",
"author_id": 5780109,
"author_profile": "https://Stackoverflow.com/users/5780109",
"pm_score": 5,
"selected": false,
"text": "dir() help(dir) dir([object]) -> list of strings\n __dir__ $ python\nPython 2.7.6 (default, Jun 22 2015, 17:58:13)\n[GCC 4.8.2] on linux2\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n\n>>> a = \"I am a string\"\n>>>\n>>> type(a)\n<class 'str'>\n>>>\n>>> dir(a)\n['__add__', '__class__', '__contains__', '__delattr__', '__doc__',\n'__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__',\n'__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__',\n'__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__',\n'__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__',\n'__setattr__', '__sizeof__', '__str__', '__subclasshook__',\n'_formatter_field_name_split', '_formatter_parser', 'capitalize',\n'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find',\n'format', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace',\n'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'partition',\n'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip',\n'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title',\n'translate', 'upper', 'zfill']\n"
},
{
"answer_id": 47317075,
"author": "Valery Ramusik",
"author_id": 5992385,
"author_profile": "https://Stackoverflow.com/users/5992385",
"pm_score": 4,
"selected": false,
"text": "user@note:~$ python3\nPython 3.4.3 (default, Nov 17 2016, 01:08:31)\n[GCC 4.8.4] on linux\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n>>> import readline\n>>> readline.parse_and_bind(\"tab: complete\")\n>>> s = \"Any object. Now it's a string\"\n>>> s. # here tab should be pressed twice\ns.__add__( s.__rmod__( s.istitle(\ns.__class__( s.__rmul__( s.isupper(\ns.__contains__( s.__setattr__( s.join(\ns.__delattr__( s.__sizeof__( s.ljust(\ns.__dir__( s.__str__( s.lower(\ns.__doc__ s.__subclasshook__( s.lstrip(\ns.__eq__( s.capitalize( s.maketrans(\ns.__format__( s.casefold( s.partition(\ns.__ge__( s.center( s.replace(\ns.__getattribute__( s.count( s.rfind(\ns.__getitem__( s.encode( s.rindex(\ns.__getnewargs__( s.endswith( s.rjust(\ns.__gt__( s.expandtabs( s.rpartition(\ns.__hash__( s.find( s.rsplit(\ns.__init__( s.format( s.rstrip(\ns.__iter__( s.format_map( s.split(\ns.__le__( s.index( s.splitlines(\ns.__len__( s.isalnum( s.startswith(\ns.__lt__( s.isalpha( s.strip(\ns.__mod__( s.isdecimal( s.swapcase(\ns.__mul__( s.isdigit( s.title(\ns.__ne__( s.isidentifier( s.translate(\ns.__new__( s.islower( s.upper(\ns.__reduce__( s.isnumeric( s.zfill(\ns.__reduce_ex__( s.isprintable(\ns.__repr__( s.isspace(\n"
},
{
"answer_id": 48284803,
"author": "Mahdi Ghelichi",
"author_id": 8291566,
"author_profile": "https://Stackoverflow.com/users/8291566",
"pm_score": 1,
"selected": false,
"text": "obj = []\n list(filter(lambda x:callable(getattr(obj,x)),obj.__dir__())) ['__add__',\n '__class__',\n '__contains__',\n '__delattr__',\n '__delitem__',\n '__dir__',\n '__eq__',\n '__format__',\n '__ge__',\n '__getattribute__',\n '__getitem__',\n '__gt__',\n '__iadd__',\n '__imul__',\n '__init__',\n '__init_subclass__',\n '__iter__',\n '__le__',\n '__len__',\n '__lt__',\n '__mul__',\n '__ne__',\n '__new__',\n '__reduce__',\n '__reduce_ex__',\n '__repr__',\n '__reversed__',\n '__rmul__',\n '__setattr__',\n '__setitem__',\n '__sizeof__',\n '__str__',\n '__subclasshook__',\n 'append',\n 'clear',\n 'copy',\n 'count',\n 'extend',\n 'index',\n 'insert',\n 'pop',\n 'remove',\n 'reverse',\n 'sort']\n"
},
{
"answer_id": 49194581,
"author": "Simon PII",
"author_id": 9467669,
"author_profile": "https://Stackoverflow.com/users/9467669",
"pm_score": 0,
"selected": false,
"text": "for method in dir(module) :\n if \"keyword_of_methode\" in method :\n print(method, end=\"\\n\")\n"
},
{
"answer_id": 50050651,
"author": "Paritosh Vyas",
"author_id": 6852381,
"author_profile": "https://Stackoverflow.com/users/6852381",
"pm_score": 5,
"selected": false,
"text": "help() help(object)\n help(str)\n"
},
{
"answer_id": 58987382,
"author": "The Mob",
"author_id": 8812904,
"author_profile": "https://Stackoverflow.com/users/8812904",
"pm_score": 2,
"selected": false,
"text": "import moduleName\nfor x in dir(moduleName):\n print(x)\n"
},
{
"answer_id": 61189861,
"author": "Nick Cuevas",
"author_id": 5784892,
"author_profile": "https://Stackoverflow.com/users/5784892",
"pm_score": 0,
"selected": false,
"text": ">> MyObject??\n"
},
{
"answer_id": 63481052,
"author": "Sanmitha Sadhishkumar",
"author_id": 13827419,
"author_profile": "https://Stackoverflow.com/users/13827419",
"pm_score": -1,
"selected": false,
"text": "import module_name\ndir(module_name)\n dir(object_name)\n"
},
{
"answer_id": 63620684,
"author": "revliscano",
"author_id": 7303434,
"author_profile": "https://Stackoverflow.com/users/7303434",
"pm_score": 2,
"selected": false,
"text": "get_object_functions object_ functions def get_object_functions(object_):\n functions = [attr_name\n for attr_name in dir(object_)\n if str(type(getattr(object_,\n attr_name))) in (\"<class 'function'>\",\n \"<class 'method'>\")]\n return functions\n \"<class 'function'>\" \"<class 'method'>\" functions True class Person:\n def __init__(self, name, age):\n self.name = name\n self.age = age\n\n def introduce(self):\n print(f'My name is {self.name}')\n\n @staticmethod\n def say_hi():\n print('hi')\n\n @classmethod\n def reproduce(cls, name):\n return cls(name, 0)\n\n\nperson = Person('Rafael', 27)\nprint(get_object_functions(person))\n\n ['__init__', 'introduce', 'reproduce', 'say_hi']\n"
},
{
"answer_id": 65186594,
"author": "Sergey Bushmanov",
"author_id": 4317058,
"author_profile": "https://Stackoverflow.com/users/4317058",
"pm_score": 4,
"selected": false,
"text": "obj __ print(dir(obj))\n [m for m in dir(obj) if not m.startswith('__')]\n"
},
{
"answer_id": 67662964,
"author": "Zack Plauché",
"author_id": 10415970,
"author_profile": "https://Stackoverflow.com/users/10415970",
"pm_score": -1,
"selected": false,
"text": "print(*dir(obj), sep='\\n')\n"
},
{
"answer_id": 68474764,
"author": "Dharma",
"author_id": 2103732,
"author_profile": "https://Stackoverflow.com/users/2103732",
"pm_score": 0,
"selected": false,
"text": "object_methods = [method_name for method_name in dir(object) if callable(getattr(object, method_name)) and '__' not in method_name] \n class Person: \n def __init__(self, name): \n self.name = name \n def print_name(self):\n print(self.name)\n"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/34439",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3587/"
] |
34,476 |
<p>I have to do some JavaScript in the future, so it is time to update my toolbox. Right now I use Firefox with some addons:</p>
<ul>
<li>JavaScript Shell from <a href="https://www.squarefree.com/bookmarklets/webdevel.html" rel="nofollow noreferrer">https://www.squarefree.com/bookmarklets/webdevel.html</a></li>
<li>Firefox Dom Inspector</li>
<li>Firebug</li>
<li>Greasemonkey</li>
<li>Stylish</li>
</ul>
<p>I plan to use <a href="http://www.hacksrus.com/~ginda/venkman/" rel="nofollow noreferrer">Venkman Javascript debugger</a> as well as <a href="https://github.com/pivotal/jsunit" rel="nofollow noreferrer">jsunit</a> and <a href="http://jslint.com/" rel="nofollow noreferrer">js-lint</a>.</p>
<p>For programming I'm stick with vim.</p>
<p>So what other tools do you use when developing JavaScript?</p>
|
[
{
"answer_id": 34525,
"author": "Sébastien RoccaSerra",
"author_id": 2797,
"author_profile": "https://Stackoverflow.com/users/2797",
"pm_score": 2,
"selected": false,
"text": "var window;\nload(\"Library/env.js\");\nwindow.location = 'index.html'; // Load the page 'index.html'\n\nprint($('aForm').id); // Play with the Dom in a standalone script!\n"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/34476",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/720/"
] |
34,486 |
<p>I have a small JS function that does Ajax for me and another like it that adds in POST data to the request. With Ajax being such a big topic with so many libraries about it, what am I missing from my function, is it insecure or something else worrying?</p>
<pre><code>function loadPage(pagePath, displayElement)
{
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
document.getElementById(displayElement).innerHTML = xmlHttp.responseText;
}
}
xmlHttp.open("GET", pagePath, true);
xmlHttp.send(null);
}
</code></pre>
|
[
{
"answer_id": 34539,
"author": "Patrick McElhaney",
"author_id": 437,
"author_profile": "https://Stackoverflow.com/users/437",
"pm_score": 3,
"selected": false,
"text": "alert(\"Your browser does not support AJAX!\")\n"
},
{
"answer_id": 34714,
"author": "Lee Theobald",
"author_id": 1900,
"author_profile": "https://Stackoverflow.com/users/1900",
"pm_score": 2,
"selected": false,
"text": "var xmlHttp;\nif (window.XMLHttpRequest) {\n // Firefox, Opera 8.0+, Safari\n xmlHttp=new XMLHttpRequest();\n} else if (window.ActiveXObject) {\n try {\n xmlHttp=new ActiveXObject(\"Msxml2.XMLHTTP\");\n } catch (e) {\n xmlHttp=new ActiveXObject(\"Microsoft.XMLHTTP\");\n }\n}\n\nif (xmlHttp) {\n // No errors, do whatever you need.\n}\n"
},
{
"answer_id": 39376,
"author": "erlando",
"author_id": 4192,
"author_profile": "https://Stackoverflow.com/users/4192",
"pm_score": 1,
"selected": false,
"text": "function loadPage(pagePath, displayElement) {\n new Ajax.Updater(displayElement, pagePath);\n}\n"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/34486",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1384652/"
] |
34,490 |
<p><a href="http://en.wikipedia.org/wiki/SHA-1" rel="noreferrer">SHA Hash functions</a></p>
|
[
{
"answer_id": 34514,
"author": "devstopfix",
"author_id": 3366,
"author_profile": "https://Stackoverflow.com/users/3366",
"pm_score": 10,
"selected": true,
"text": "require 'digest/sha1'\nDigest::SHA1.hexdigest 'foo'\n"
},
{
"answer_id": 5269105,
"author": "r4ccoon",
"author_id": 79770,
"author_profile": "https://Stackoverflow.com/users/79770",
"pm_score": -1,
"selected": false,
"text": " def generateKey(data)\n return Digest::SHA1.hexdigest (\"#{serialize(data)}\")\n end\n"
},
{
"answer_id": 5968830,
"author": "Thiago Ganzarolli",
"author_id": 287604,
"author_profile": "https://Stackoverflow.com/users/287604",
"pm_score": 3,
"selected": false,
"text": "require 'base64'\nrequire 'hmac-sha1'\n\nBase64.encode64((HMAC::SHA1.new('key') << 'base').digest).strip\n"
},
{
"answer_id": 19819184,
"author": "Gregory Ostermayr",
"author_id": 833555,
"author_profile": "https://Stackoverflow.com/users/833555",
"pm_score": 3,
"selected": false,
"text": "require 'rickshaw'\n> Rickshaw::SHA1.hash('LICENSE.txt')\n\n => \"4659d94e7082a65ca39e7b6725094f08a413250a\" \n\n> \"hello world\".to_sha1\n\n => \"2aae6c35c94fcfb415dbe95f408b9ce91ee846ed\" \n"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/34490",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3624/"
] |
34,493 |
<p>We have a few very large Excel workbooks (dozens of tabs, over a MB each, very complex calculations) with many dozens, perhaps hundreds of formulas that use the dreaded INDIRECT function. These formulas are spread out throughout the workbook, and target several tables of data to look-up for values.</p>
<p>Now I need to move the ranges of data that are targeted by these formulas to a different location in the same workbook.</p>
<p>(The reason is not particularly relevant, but interesting on its own. We need to run these things in Excel Calculation Services and the latency hit of loading each of the rather large tables one at a time proved to be unacceptably high. We are moving the tables in a contiguous range so we can load them all in one shot.)</p>
<p><strong>Is there any way to locate all the INDIRECT formulas that currently refer to the tables we want to move?</strong></p>
<p>I don't need to do this on-line. I'll happily take something that takes 4 hours to run as long as it is reliable.</p>
<p>Be aware that the .Precedent, .Dependent, etc methods only track direct formulas.</p>
<p>(Also, rewriting the spreadsheets in <em>whatever</em> is not an option for us).</p>
<p>Thanks!</p>
|
[
{
"answer_id": 34719,
"author": "sdfx",
"author_id": 3445,
"author_profile": "https://Stackoverflow.com/users/3445",
"pm_score": 4,
"selected": true,
"text": "Sub iterateOverWorkbook()\nFor Each i In ThisWorkbook.Worksheets\n Set rRng = i.UsedRange\n For Each j In rRng\n If (Not IsEmpty(j)) Then\n If (j.HasFormula) Then\n If InStr(oCell.Formula, \"INDIRECT\") Then\n j.Value = Replace(j.Formula, \"INDIRECT(D4)\", \"INDIRECT(C4)\")\n End If\n End If\n End If\n Next j\nNext i\nEnd Sub\n"
},
{
"answer_id": 34750,
"author": "PabloG",
"author_id": 394,
"author_profile": "https://Stackoverflow.com/users/394",
"pm_score": 0,
"selected": false,
"text": "Sub ListIndirectRef()\n\nDim rRng As Range\nDim oSh As Worksheet\nDim oCell As Range\n\nFor Each oSh In ThisWorkbook.Worksheets\n Set rRng = oSh.UsedRange\n For Each oCell In rRng\n If InStr(oCell.Formula, \"INDIRECT\") Then\n Debug.Print oCell.Address, oCell.Formula\n End If\n Next\nNext\n\nEnd Sub\n"
},
{
"answer_id": 35042,
"author": "sdfx",
"author_id": 3445,
"author_profile": "https://Stackoverflow.com/users/3445",
"pm_score": 0,
"selected": false,
"text": "=IF(INDIRECT(\"'\"&$B$5&\"'!\"&$O5&\"1\")=\"\",\"\",INDIRECT(\"'\"&$B$5&\"'!\"&$O5&\"1\"))"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/34493",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2230/"
] |
34,505 |
<p>The MSDN documentation on <a href="http://msdn.microsoft.com/en-us/library/system.object.gethashcode.aspx" rel="noreferrer">Object.GetHashCode()</a> describes 3 contradicting rules for how the method should work. </p>
<ol>
<li>If two objects of the same type represent the same value, the hash function must return the same constant value for either object.</li>
<li>For the best performance, a hash function must generate a random distribution for all input.</li>
<li>The hash function must return exactly the same value regardless of any changes that are made to the object.</li>
</ol>
<p>Rules 1 & 3 are contradictory to me.</p>
<p>Does Object.GetHashCode() return a unique number based on the <strong>value</strong> of an object, or the <strong>reference</strong> to the object. If I override the method I can choose what to use, but I'd like to know what is used internally if anyone knows.</p>
|
[
{
"answer_id": 34541,
"author": "Konrad Rudolph",
"author_id": 1968,
"author_profile": "https://Stackoverflow.com/users/1968",
"pm_score": 6,
"selected": true,
"text": "struct Person {\n public readonly string FirstName;\n public readonly string Name;\n public readonly DateTime Birthday;\n\n public int ShoeSize;\n}\n public int GetHashCode() {\n return FirstName.GetHashCode() ^ Name.GetHashCode() ^ Birthday.GetHashCode();\n}\n"
},
{
"answer_id": 32736203,
"author": "thewhiteambit",
"author_id": 2042691,
"author_profile": "https://Stackoverflow.com/users/2042691",
"pm_score": 1,
"selected": false,
"text": "GetHashCode"
}
] |
2008/08/29
|
[
"https://Stackoverflow.com/questions/34505",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/392/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.