qid int64 4 19.1M | question stringlengths 18 48.3k | answers list | date stringlengths 10 10 | metadata list |
|---|---|---|---|---|
301,528 | <p>I've got this date time string:</p>
<pre><code>post["date"] = "2007-07-18 10:03:19"
</code></pre>
<p>I'd like to extract just "2007-07-18" as a date. I've seen some reference to <code>strptime</code> but I'm not sure how to use it. How can I extract the date from this string?</p>
| [
{
"answer_id": 301537,
"author": "gimel",
"author_id": 6491,
"author_profile": "https://Stackoverflow.com/users/6491",
"pm_score": 3,
"selected": false,
"text": ">>> d1=\"2007-07-18 10:03:19\"\n>>> d1.split()[0]\n'2007-07-18'\n>>> \n strptime \"%Y-%m-%d %H:%M:%S\" >>> import time\n>>> time.strptime(d1,\"%Y-%m-%d %H:%M:%S\")\ntime.struct_time(tm_year=2007, tm_mon=7, tm_mday=18, tm_hour=10, tm_min=3, tm_sec=19, tm_wday=2, tm_yday=199, tm_isdst=-1)\n>>> time.strftime(\"%Y-%m-%d\", _)\n'2007-07-18'\n>>> \n"
},
{
"answer_id": 301542,
"author": "Ashy",
"author_id": 32933,
"author_profile": "https://Stackoverflow.com/users/32933",
"pm_score": 2,
"selected": false,
"text": "post[\"date\"].split()[0]\n '2007-07-18'"
},
{
"answer_id": 301580,
"author": "babbageclunk",
"author_id": 38851,
"author_profile": "https://Stackoverflow.com/users/38851",
"pm_score": 7,
"selected": true,
"text": "datetime from datetime import datetime\nd = datetime.strptime('2007-07-18 10:03:19', '%Y-%m-%d %H:%M:%S')\nday_string = d.strftime('%Y-%m-%d')\n"
},
{
"answer_id": 301591,
"author": "Oli",
"author_id": 22035,
"author_profile": "https://Stackoverflow.com/users/22035",
"pm_score": 1,
"selected": false,
"text": "mx.DateTime import mx\n\ndate_object = mx.DateTime.Parser.DateTimeFromString('2007-07-18 10:03:19')\nprint \"%s-%s-%s\" % (date_object.year, date_object.month, date_object.day)\n 2007-07-18"
},
{
"answer_id": 301593,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": ">>> from parsedatetime.parsedatetime import Calendar\n>>> c = Calendar()\n>>> c.parse(\"2007-07-18 10:03:19\")\n((2008, 11, 19, 10, 3, 19, 2, 324, 0), 2)\n"
},
{
"answer_id": 16184809,
"author": "PBD",
"author_id": 1633300,
"author_profile": "https://Stackoverflow.com/users/1633300",
"pm_score": 2,
"selected": false,
"text": ">>> from dateutil.parser import parse\n>>> d1=\"2007-07-18 10:03:19\"\n>>> date_obj = parse(d1)\n>>> date_obj\ndatetime.datetime(2007, 7, 18, 10, 3, 19)\n>>> date_obj.strftime(\"%Y-%m-%d\")\n'2007-07-18'\n>>> d2 = \"18-07-2007 10:03:19\"\n>>> d = parse(d2)\n>>> d\ndatetime.datetime(2007, 7, 18, 10, 3, 19)\n>>> d.strftime(\"%Y-%m-%d\")\n'2007-07-18'\n"
},
{
"answer_id": 39764551,
"author": "Jack Sparrow",
"author_id": 3293019,
"author_profile": "https://Stackoverflow.com/users/3293019",
"pm_score": 0,
"selected": false,
"text": "import dateutil.parser\na = \"2007-07-18 10:03:19\"\nd = dateutil.parser.parse(b).date()\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301528",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16974/"
] |
301,532 | <p>I'm using the <a href="http://www.microsoft.com/unlimitedpotential/programs/multipoint.mspx" rel="nofollow noreferrer">MultiPoint</a> SDK to create a collaborative educational application for children in less affluent countries, where there is not one computer for each student in the classroom.</p>
<p>Because we need to support up to 40 mice connected to one computer, we need an automated way to test our software. The SDK will support as many mice that it can find on the system and detects when mice are added and removed. Each mouse appears as a 'virtual' mouse pointer within a WPF window. Each child has independent control of 'their' pointer on the screen.</p>
<p>We would like to create a test harness that tricks Windows into thinking that it has more than one mouse. The harness would need to create these fake devices (40+) and use them to send mouse messages like move, button down, etc</p>
<p>Any help would be greatly appreciated.</p>
| [
{
"answer_id": 302221,
"author": "Sunlight",
"author_id": 33650,
"author_profile": "https://Stackoverflow.com/users/33650",
"pm_score": 2,
"selected": true,
"text": "DeviceIoControl"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301532",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21606/"
] |
301,536 | <p><strong>PHP has a <a href="http://php.net/var_dump" rel="noreferrer">var_dump()</a> function which outputs the internal contents of an object, showing an object's type and content.</strong></p>
<p>For example:</p>
<pre><code>class Person {
private $firstName;
private $lastName;
public function __construct($firstName, $lastName) {
$this->firstName = $firstName;
$this->lastName = $lastName;
}
}
$person = new Person('Jon', 'Smith');
var_dump($person);
</code></pre>
<p>will output:</p>
<pre><code>object(Person)#1 (2) {
["firstName:private"]=>
string(3) "Jon"
["lastName:private"]=>
string(5) "Smith"
}
</code></pre>
<p><strong>What is the equivalent in Java that will do the same?</strong></p>
| [
{
"answer_id": 301575,
"author": "serg10",
"author_id": 1853,
"author_profile": "https://Stackoverflow.com/users/1853",
"pm_score": 7,
"selected": true,
"text": "toString toString() Person toString()"
},
{
"answer_id": 301581,
"author": "Harry Lime",
"author_id": 21590,
"author_profile": "https://Stackoverflow.com/users/21590",
"pm_score": 4,
"selected": false,
"text": "toString() Object Field[] fields = o.getClass().getDeclaredFields();\nfor (int i=0; i<fields.length; i++)\n{\n System.out.println(fields[i].getName() + \" - \" + fields[i].get(o));\n}\n"
},
{
"answer_id": 20567226,
"author": "Ali Mamedov",
"author_id": 603774,
"author_profile": "https://Stackoverflow.com/users/603774",
"pm_score": 4,
"selected": false,
"text": "HashMap<String, String> map = new HashMap<String, String>();\n\nmap.put(\"key_1\", \"Baku\");\nmap.put(\"key_2\", \"Azerbaijan\");\nmap.put(\"key_3\", \"Ali Mamedov\");\n\nGson gson = new Gson();\n\nSystem.out.println(gson.toJson(map));\n {\"key_3\":\"Ali Mamedov\",\"key_2\":\"Azerbaijan\",\"key_1\":\"Baku\"}\n"
},
{
"answer_id": 37191419,
"author": "mattalxndr",
"author_id": 334966,
"author_profile": "https://Stackoverflow.com/users/334966",
"pm_score": 3,
"selected": false,
"text": "public static String getDump(Object o) {\n return new GsonBuilder().setPrettyPrinting().create().toJson(o);\n}\n"
},
{
"answer_id": 52741197,
"author": "Necare",
"author_id": 9087910,
"author_profile": "https://Stackoverflow.com/users/9087910",
"pm_score": 0,
"selected": false,
"text": "public static void dd(Object obj) { System.out.println(obj); }\n"
},
{
"answer_id": 62554429,
"author": "Stephane",
"author_id": 4801452,
"author_profile": "https://Stackoverflow.com/users/4801452",
"pm_score": 0,
"selected": false,
"text": "public static void dd(Object obj) throws IllegalArgumentException, IllegalAccessException {\n Field[] fields = obj.getClass().getDeclaredFields();\n for (int i=0; i<fields.length; i++)\n {\n fields[i].setAccessible(true);\n System.out.println(fields[i].getName() + \" - \" + fields[i].get(obj));\n } \n\n}\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301536",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5343/"
] |
301,544 | <p>I have this SQL query:</p>
<pre><code>SELECT * FROM IMAGES WHERE
IMAGENAME in ('IMG1', 'IMG2', 'IMG3', 'IMG4', 'IMG5', 'IMG6')
ORDER BY CASE IMAGENAME
WHEN 'IMG1' THEN 1
WHEN 'IMG2' THEN 2
WHEN 'IMG3' THEN 3
WHEN 'IMG4' THEN 4
WHEN 'IMG5' THEN 5
WHEN 'IMG6' THEN 6
ELSE 7
END
</code></pre>
<p>I cannot guarantee that the list of IMAGENAMEs will be in alphabetical order, hence the case statement, but I would prefer to sort in the DB rather than in code because I trust their sorting code better than mine :)</p>
<p>SQL server analyses that 78% of the execution time is spent sorting - can I reduce this?</p>
<p>It needs to be fairly vanilla SQL as we target SQL Server and Oracle.</p>
<p>Any tuning advice would be fantastic.</p>
| [
{
"answer_id": 301596,
"author": "Andrew",
"author_id": 5662,
"author_profile": "https://Stackoverflow.com/users/5662",
"pm_score": 0,
"selected": false,
"text": "IMG IMAGENAME SELECT * FROM IMAGES WHERE\nIMAGENAME in ('IMG1', 'IMG2', 'IMG3', 'IMG4', 'IMG5', 'IMG6')\nORDER BY IMAGENO\nEND\n IMAGENO 1, 2, 3, 4, 5, 6"
},
{
"answer_id": 301601,
"author": "Tom Haigh",
"author_id": 22224,
"author_profile": "https://Stackoverflow.com/users/22224",
"pm_score": 0,
"selected": false,
"text": "CAST(SUBSTRING(IMAGENAME, 4, LEN(IMAGENAME) -3) as INTEGER)\n"
},
{
"answer_id": 301603,
"author": "gx.",
"author_id": 21580,
"author_profile": "https://Stackoverflow.com/users/21580",
"pm_score": 2,
"selected": false,
"text": "SELECT *\nFROM IMAGES\nWHERE IMAGENAME in ('IMG1', 'IMG2', 'IMG3', 'IMG4', 'IMG5', 'IMG6')\nORDER BY IMAGENAME ASC\n"
},
{
"answer_id": 301606,
"author": "Tony Andrews",
"author_id": 18747,
"author_profile": "https://Stackoverflow.com/users/18747",
"pm_score": 0,
"selected": false,
"text": "SELECT * FROM IMAGES WHERE\nIMAGENAME in ('IMG1', 'IMG2', 'IMG3', 'IMG4', 'IMG5', 'IMG6')\nORDER BY TO_NUMBER(SUBSTR(IMAGENAME,4));\n"
},
{
"answer_id": 301615,
"author": "ChrisThomas123",
"author_id": 916,
"author_profile": "https://Stackoverflow.com/users/916",
"pm_score": 4,
"selected": true,
"text": "SELECT * FROM IMAGES WHERE\n IMAGENAME IN ('IMG1', 'IMG2', 'IMG3', 'IMG4', 'IMG5', 'IMG6')\n ORDER BY FIELD(IMAGENAME, 'IMG1', 'IMG2', 'IMG3', 'IMG4', 'IMG5', 'IMG6');\n"
},
{
"answer_id": 301704,
"author": "Mark Pim",
"author_id": 38883,
"author_profile": "https://Stackoverflow.com/users/38883",
"pm_score": 0,
"selected": false,
"text": "ORDER BY CHARINDEX(IMAGENAME, 'A,B,C,D,E,F,G')\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301544",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/38883/"
] |
301,546 | <p>There's a web services I want to call in my application, I can use it with importing the WSDL or by just use "HTTP GET" with the URL and parameters, so I prefer the later because it's simple thing.</p>
<p>I know I can use indy idhttp.get, to do the job, but this is very simple thing and I don't want to add complex indy code to my application.</p>
<p><strong>UPDATE</strong>: sorry if I was not clear, I meant by "not to add complex indy code", that I don't want add indy components for just this simple task, and prefer more lighter way for that.</p>
| [
{
"answer_id": 301598,
"author": "Bruce McGee",
"author_id": 19183,
"author_profile": "https://Stackoverflow.com/users/19183",
"pm_score": 5,
"selected": false,
"text": "function GetURLAsString(const aURL: string): string;\nvar\n lHTTP: TIdHTTP;\nbegin\n lHTTP := TIdHTTP.Create;\n try\n Result := lHTTP.Get(aURL);\n finally\n lHTTP.Free;\n end;\nend;\n"
},
{
"answer_id": 301621,
"author": "Lars Truijens",
"author_id": 1242,
"author_profile": "https://Stackoverflow.com/users/1242",
"pm_score": 6,
"selected": true,
"text": "uses WinInet;\n\nfunction GetUrlContent(const Url: string): string;\nvar\n NetHandle: HINTERNET;\n UrlHandle: HINTERNET;\n Buffer: array[0..1024] of Char;\n BytesRead: dWord;\nbegin\n Result := '';\n NetHandle := InternetOpen('Delphi 5.x', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);\n\n if Assigned(NetHandle) then \n begin\n UrlHandle := InternetOpenUrl(NetHandle, PChar(Url), nil, 0, INTERNET_FLAG_RELOAD, 0);\n\n if Assigned(UrlHandle) then\n { UrlHandle valid? Proceed with download }\n begin\n FillChar(Buffer, SizeOf(Buffer), 0);\n repeat\n Result := Result + Buffer;\n FillChar(Buffer, SizeOf(Buffer), 0);\n InternetReadFile(UrlHandle, @Buffer, SizeOf(Buffer), BytesRead);\n until BytesRead = 0;\n InternetCloseHandle(UrlHandle);\n end\n else\n { UrlHandle is not valid. Raise an exception. }\n raise Exception.CreateFmt('Cannot open URL %s', [Url]);\n\n InternetCloseHandle(NetHandle);\n end\n else\n { NetHandle is not valid. Raise an exception }\n raise Exception.Create('Unable to initialize Wininet');\nend;\n"
},
{
"answer_id": 2483034,
"author": "Michael Madsen",
"author_id": 27528,
"author_profile": "https://Stackoverflow.com/users/27528",
"pm_score": 3,
"selected": false,
"text": "procedure TMainForm.DownloadFile(URL: string; Dest: string);\nvar\n dl: TDownloadURL;\nbegin\n dl := TDownloadURL.Create(self);\n try\n dl.URL := URL;\n dl.FileName := Dest;\n dl.ExecuteTarget(nil); //this downloads the file\n finally\n dl.Free;\n end;\nend;\n"
},
{
"answer_id": 7759944,
"author": "Aldis",
"author_id": 994289,
"author_profile": "https://Stackoverflow.com/users/994289",
"pm_score": 4,
"selected": false,
"text": "uses WinInet;\n\nfunction GetUrlContent(const Url: string): UTF8String;\nvar\n NetHandle: HINTERNET;\n UrlHandle: HINTERNET;\n Buffer: array[0..1023] of byte;\n BytesRead: dWord;\n StrBuffer: UTF8String;\nbegin\n Result := '';\n NetHandle := InternetOpen('Delphi 2009', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);\n if Assigned(NetHandle) then\n try\n UrlHandle := InternetOpenUrl(NetHandle, PChar(Url), nil, 0, INTERNET_FLAG_RELOAD, 0);\n if Assigned(UrlHandle) then\n try\n repeat\n InternetReadFile(UrlHandle, @Buffer, SizeOf(Buffer), BytesRead);\n SetString(StrBuffer, PAnsiChar(@Buffer[0]), BytesRead);\n Result := Result + StrBuffer;\n until BytesRead = 0;\n finally\n InternetCloseHandle(UrlHandle);\n end\n else\n raise Exception.CreateFmt('Cannot open URL %s', [Url]);\n finally\n InternetCloseHandle(NetHandle);\n end\n else\n raise Exception.Create('Unable to initialize Wininet');\nend;\n"
},
{
"answer_id": 34464207,
"author": "Arioch 'The",
"author_id": 976391,
"author_profile": "https://Stackoverflow.com/users/976391",
"pm_score": 3,
"selected": false,
"text": "procedure TForm1.Button1Click(Sender: TObject);\nvar http: variant;\nbegin\n http:=createoleobject('WinHttp.WinHttpRequest.5.1');\n http.open('GET', 'http://lazarus.freepascal.org', false);\n http.send;\n showmessage(http.responsetext);\nend;\n procedure TfmHaspList.YieldBlinkHTTP(const LED: boolean; const Key_Hardware_ID: cardinal);\nvar URL: WideString;\nbegin\n URL := 'http://127.0.0.1:1947/action.html?blink' +\n IfThen( LED, 'on', 'off') + '=' + IntToStr(Key_Hardware_ID);\n\n TThread.CreateAnonymousThread(\n procedure\n var Request: OleVariant;\n begin\n // COM library initialization for the current thread\n CoInitialize(nil);\n try\n // create the WinHttpRequest object instance\n Request := CreateOleObject('WinHttp.WinHttpRequest.5.1');\n // open HTTP connection with GET method in synchronous mode\n Request.Open('GET', URL, False);\n // set the User-Agent header value\n// Request.SetRequestHeader('User-Agent', 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0');\n // sends the HTTP request to the server, the Send method does not return\n // until WinHTTP completely receives the response (synchronous mode)\n Request.Send;\n// // store the response into the field for synchronization\n// FResponseText := Request.ResponseText;\n// // execute the SynchronizeResult method within the main thread context\n// Synchronize(SynchronizeResult);\n finally\n // release the WinHttpRequest object instance\n Request := Unassigned;\n // uninitialize COM library with all resources\n CoUninitialize;\n end;\n end\n ).Start;\nend;\n"
},
{
"answer_id": 41400389,
"author": "EugeneK",
"author_id": 1325672,
"author_profile": "https://Stackoverflow.com/users/1325672",
"pm_score": 4,
"selected": false,
"text": "THTTPClient System.Net.HttpClient function GetURL(const AURL: string): string;\nvar\n HttpClient: THttpClient;\n HttpResponse: IHttpResponse;\nbegin\n HttpClient := THTTPClient.Create;\n try\n HttpResponse := HttpClient.Get(AURL);\n Result := HttpResponse.ContentAsString();\n finally\n HttpClient.Free;\n end;\nend;\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301546",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24462/"
] |
301,551 | <p>If I'm using ConcurrentHashMap (where the put is thread safe) , and I supply a public function myPut that uses the ConcurrentHashMap put - do I need to synchronize my function? </p>
<p>meaning : should this be synchronized?</p>
<pre><code>ConcurrentHashMap map;
public void myPut(int something) {
this.map.put(something);
}
</code></pre>
| [
{
"answer_id": 301816,
"author": "Bill Michell",
"author_id": 7938,
"author_profile": "https://Stackoverflow.com/users/7938",
"pm_score": 0,
"selected": false,
"text": "ConcurrentHashMap"
},
{
"answer_id": 302201,
"author": "Tom Hawtin - tackline",
"author_id": 4725,
"author_profile": "https://Stackoverflow.com/users/4725",
"pm_score": 2,
"selected": false,
"text": "map final map final final final private map private"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301551",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4038/"
] |
301,552 | <p>Is it possible (by using the stock c# TreeView) to have Multiline TreeNodes? </p>
<p>Also, is it possible to add control characters to TreeNode's text e.g. '\t'? This same effect could also be achieved by adding columns to the TreeNode. is this possible?</p>
| [
{
"answer_id": 43540335,
"author": "Simon Philipp Schmidt",
"author_id": 6508198,
"author_profile": "https://Stackoverflow.com/users/6508198",
"pm_score": 0,
"selected": false,
"text": "mynode.NodeFont = new System.Drawing.Font(\"Consolas\", 9,FontStyle.Regular);\n\nstring displaytext = String.Format(CultureInfo.InvariantCulture, \"{0}{2} = {1}\", mystringOfDifferentLenght, myresult, GetEmptyInfoByIndex(mystringOfDifferentLength, 20));\nmynode.Text = displaytext;\nrootnode.Nodes.Add(mynode);\n\nprivate string GetEmptyInfoByIndex(string _string, int maxLength)\n {\n string retstr = string.Empty;\n for (int i = 0; i < maxLength - _string.Length; i++)\n {\n retstr += \" \";\n }\n return retstr;\n }\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301552",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1816/"
] |
301,555 | <p>The 'attach to process' dialogue box on VC6 running on win 2003 (I believe vista as well) has no processes to attach to in it... I've tried logging on as an administrator and running as an administrator but no luck. Any other ideas?</p>
| [
{
"answer_id": 43540335,
"author": "Simon Philipp Schmidt",
"author_id": 6508198,
"author_profile": "https://Stackoverflow.com/users/6508198",
"pm_score": 0,
"selected": false,
"text": "mynode.NodeFont = new System.Drawing.Font(\"Consolas\", 9,FontStyle.Regular);\n\nstring displaytext = String.Format(CultureInfo.InvariantCulture, \"{0}{2} = {1}\", mystringOfDifferentLenght, myresult, GetEmptyInfoByIndex(mystringOfDifferentLength, 20));\nmynode.Text = displaytext;\nrootnode.Nodes.Add(mynode);\n\nprivate string GetEmptyInfoByIndex(string _string, int maxLength)\n {\n string retstr = string.Empty;\n for (int i = 0; i < maxLength - _string.Length; i++)\n {\n retstr += \" \";\n }\n return retstr;\n }\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301555",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/38892/"
] |
301,563 | <p>Whats this syntax useful for : </p>
<pre><code> function(String... args)
</code></pre>
<p>Is this same as writing </p>
<pre><code> function(String[] args)
</code></pre>
<p>with difference only while invoking this method or is there any other feature involved with it ?</p>
| [
{
"answer_id": 301599,
"author": "bruno conde",
"author_id": 31136,
"author_profile": "https://Stackoverflow.com/users/31136",
"pm_score": 8,
"selected": true,
"text": "public static void main(String[] args) {\n callMe1(new String[] {\"a\", \"b\", \"c\"});\n callMe2(\"a\", \"b\", \"c\");\n // You can also do this\n // callMe2(new String[] {\"a\", \"b\", \"c\"});\n}\npublic static void callMe1(String[] args) {\n System.out.println(args.getClass() == String[].class);\n for (String s : args) {\n System.out.println(s);\n }\n}\npublic static void callMe2(String... args) {\n System.out.println(args.getClass() == String[].class);\n for (String s : args) {\n System.out.println(s);\n }\n}\n"
},
{
"answer_id": 301605,
"author": "kgiannakakis",
"author_id": 24054,
"author_profile": "https://Stackoverflow.com/users/24054",
"pm_score": 3,
"selected": false,
"text": "function(arg1, arg2, arg3);\n String [] args = new String[3];\nargs[0] = \"\";\nargs[1] = \"\";\nargs[2] = \"\";\nfunction(args);\n"
},
{
"answer_id": 301608,
"author": "michelemarcon",
"author_id": 15173,
"author_profile": "https://Stackoverflow.com/users/15173",
"pm_score": 4,
"selected": false,
"text": "String... function(arg1);\nfunction(arg1, arg2);\nfunction(arg1, arg2, arg3);\n String[]"
},
{
"answer_id": 301644,
"author": "Mecki",
"author_id": 15809,
"author_profile": "https://Stackoverflow.com/users/15809",
"pm_score": 5,
"selected": false,
"text": "function(s1, s2, s3);\n function(new String[] { s1, s2, s3 });\n"
},
{
"answer_id": 3439741,
"author": "kamal",
"author_id": 415040,
"author_profile": "https://Stackoverflow.com/users/415040",
"pm_score": 2,
"selected": false,
"text": "class StringArray1\n{\n public static void main(String[] args) {\n callMe1(new String[] {\"a\", \"b\", \"c\"});\n callMe2(1,\"a\", \"b\", \"c\");\n callMe2(2);\n // You can also do this\n // callMe2(3, new String[] {\"a\", \"b\", \"c\"});\n}\npublic static void callMe1(String[] args) {\n System.out.println(args.getClass() == String[].class);\n for (String s : args) {\n System.out.println(s);\n }\n }\n public static void callMe2(int i,String... args) {\n System.out.println(args.getClass() == String[].class);\n for (String s : args) {\n System.out.println(s);\n }\n }\n}\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301563",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11614/"
] |
301,566 | <p>I am having a postgres production database in production (which contains a lot of Data). now I need to modify the model of the tg-app to add couple of new tables to the database. </p>
<p>How do i do this? I am using sqlAlchemy.</p>
| [
{
"answer_id": 301706,
"author": "EoghanM",
"author_id": 6691,
"author_profile": "https://Stackoverflow.com/users/6691",
"pm_score": 0,
"selected": false,
"text": "tg-admin sql create\n"
},
{
"answer_id": 390485,
"author": "James Brady",
"author_id": 29903,
"author_profile": "https://Stackoverflow.com/users/29903",
"pm_score": 1,
"selected": false,
"text": "tg-admin sql status\n sql status"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301566",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2220518/"
] |
301,577 | <p>I wrote a simple add-in for Visual Studio 2008 that opens a dockable window pane. </p>
<p><a href="http://www.codeplex.com/ora" rel="noreferrer">You can download the source and a binary installer by clicking here.</a></p>
<p>The nature of the add-in means that it is ideally going to stay docked next to where you edit your source. But sometimes, on some installs, it won't stay docked. You run VS, you dock my pane, you shutdown VS, you restart VS, and dang it - the pane is floating again. On some machines I have to re-dock it every time.</p>
<p>But on other installs it stays docked wherever I put it forever. I originally thought it might be a difference between Vista and XP but now I have reports of it coming unstuck on XP as well.</p>
<p>From what I've read (and the fact that it sometimes stays docked) I get the impression that VS is supposed to take care of saving the docking state for me. But it isn't doing that. And yet other plugins on the same VS install don't have this problem. So there has to be something I can do to improve the situation.</p>
<p>I suspect the only relevant part of my code is this:</p>
<pre><code>public class Connect : IDTExtensibility2
{
private static DTE2 _applicationObject;
private AddIn _addInInstance;
private static CodeModelEvents _codeModelEvents;
public static DTE2 VisualStudioApplication
{
get { return _applicationObject; }
}
public static CodeModelEvents CodeModelEvents
{
get { return _codeModelEvents; }
}
public static event EventHandler SourceChanged = delegate { };
public void OnConnection(object application,
ext_ConnectMode connectMode, object addInInst, ref Array custom)
{
_applicationObject = (DTE2)application;
_addInInstance = (AddIn)addInInst;
}
public void OnStartupComplete(ref Array custom)
{
try
{
Events2 events = (Events2)_applicationObject.Events;
_codeModelEvents = events.get_CodeModelEvents(null);
object objTemp = null;
Windows2 toolWins = (Windows2)_applicationObject.Windows;
Window toolWin = toolWins.CreateToolWindow2(
_addInInstance, GetType().Assembly.Location, "Ora.OraPane", "Ora",
"{DC8A399C-D9B3-40f9-90E2-EAA16F0FBF94}", ref objTemp);
toolWin.Visible = true;
}
catch (Exception ex)
{
MessageBox.Show("Exception: " + ex.Message);
}
}
public void OnBeginShutdown(ref Array custom) { }
public void OnDisconnection(ext_DisconnectMode disconnectMode, ref Array custom) { }
public void OnAddInsUpdate(ref Array custom) { }
}
</code></pre>
<p>(The MSDN docs suggest that the window should be created in OnConnection, but if I do that then the window mostly doesn't appear.)</p>
| [
{
"answer_id": 313046,
"author": "JB Brown",
"author_id": 21360,
"author_profile": "https://Stackoverflow.com/users/21360",
"pm_score": 4,
"selected": true,
"text": "EnvDTE80.Window2 frame = toolWins.CreateLinkedWindowFrame(toolWin, toolWin, vsLinkedWindowType.vsLinkedWindowTypeTabbed);\n\n\nframe.SetKind(EnvDTE.vsWindowType.vsWindowTypeToolWindow);\n\n\n_applicationObject.MainWindow.LinkedWindows.Add(frame);\n\nframe.Activate();\n"
},
{
"answer_id": 561148,
"author": "Juozas Kontvainis",
"author_id": 64605,
"author_profile": "https://Stackoverflow.com/users/64605",
"pm_score": 1,
"selected": false,
"text": "public void OnBeginShutdown(ref Array custom)\n{\n if (_toolWin != null)\n _toolWin.Visible = false;\n}\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301577",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27423/"
] |
301,579 | <p>I have created a windows installer for a windows forms app as an MSI.
I have published this and put it in a zip file and sent it to the client.
When they try to run the installer they get the message
'The publisher could not be verified. Are you sure you want to run this software?β</p>
<p>Is there a setting or something i need to do to stop this message appearing when the client clicks on the installer?</p>
<p>Cheers</p>
| [
{
"answer_id": 301609,
"author": "Pablo Retyk",
"author_id": 30729,
"author_profile": "https://Stackoverflow.com/users/30729",
"pm_score": 1,
"selected": false,
"text": "signtool"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301579",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35441/"
] |
301,586 | <p>What is the difference between using <code>#include<filename> and #include<filename.h</code>> in <a href="http://en.wikipedia.org/wiki/C%2B%2B" rel="noreferrer">C++</a>? Which of the two is used and why is it is used?</p>
| [
{
"answer_id": 301589,
"author": "Robert Gould",
"author_id": 15124,
"author_profile": "https://Stackoverflow.com/users/15124",
"pm_score": 2,
"selected": false,
"text": "#include< header >\n//my code\n #include< header.h >\n//my code\n #include< cmath >\n//my code\n #include< math.h >\n//my code\n"
},
{
"answer_id": 301600,
"author": "CAdaker",
"author_id": 30579,
"author_profile": "https://Stackoverflow.com/users/30579",
"pm_score": 5,
"selected": false,
"text": "#include <foo.h> #include <foo> std #include <stdio.h>\n #include <cstdio>\n"
},
{
"answer_id": 301848,
"author": "Ferruccio",
"author_id": 4086,
"author_profile": "https://Stackoverflow.com/users/4086",
"pm_score": 3,
"selected": false,
"text": "#include <filename.h> #include <filename> #include <filename.h> #include <filename>"
},
{
"answer_id": 301907,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 6,
"selected": true,
"text": "filename.h filename cfilename filename.h filename.h std:: cfilename filename.h ::size_t std::size_t std:: filename.h"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301586",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22076/"
] |
301,590 | <p>I have a few longtables that stretch several pages and I want to use pageref and hyperref to link to these rows.</p>
<p>But whatever I try, the links always refer to the start of the table.
When I look into the aux file, the labels all seem to be re-defined into table.[number of table].</p>
<p>I tried putting invisible dummy figures into the table, but that just gives me errors of too many floats.</p>
<p>I also tried putting the labels into minipages, to no avail.</p>
<p>Even putting the labels into footnotes doesn't work, somehow longtable always seems to get to them.</p>
| [
{
"answer_id": 919492,
"author": "heeen",
"author_id": 38893,
"author_profile": "https://Stackoverflow.com/users/38893",
"pm_score": 3,
"selected": true,
"text": "\\newcounter{mycounter}\n\\newcommand{\\mylabel}[1]{\\refstepcounter{mycounter} \\label{#1}}\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301590",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/38893/"
] |
301,604 | <p>How to create a WCF application without using the svcutil.exe tool?</p>
| [
{
"answer_id": 310898,
"author": "Jeremy Wiebe",
"author_id": 11807,
"author_profile": "https://Stackoverflow.com/users/11807",
"pm_score": 3,
"selected": false,
"text": "var factory = new ChannelFactory<IMyWcfService>();\nvar wcfClient = factory.CreateChannel();\nbool closedSuccessfully = false;\n\ntry\n{\n // Now you can make calls on the wcfClient object\n ((ICommunicationObject)wcfClient).Close();\n closedSuccessfully = true;\n}\nfinally\n{\n if (!closedSuccessfully)\n {\n ((ICommunicationObject)wcfClient).Abort();\n }\n} \n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301604",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
301,613 | <p>I'm using Visual Studio 2008 and I want to automate the process of building the installer by running a batch file.</p>
<p>The batch file should first sign the assemblies and than start the building of the installer. After the installer is created the batch file should sign the <code>.msi</code> file too.</p>
<p>Is this possible? </p>
| [
{
"answer_id": 310898,
"author": "Jeremy Wiebe",
"author_id": 11807,
"author_profile": "https://Stackoverflow.com/users/11807",
"pm_score": 3,
"selected": false,
"text": "var factory = new ChannelFactory<IMyWcfService>();\nvar wcfClient = factory.CreateChannel();\nbool closedSuccessfully = false;\n\ntry\n{\n // Now you can make calls on the wcfClient object\n ((ICommunicationObject)wcfClient).Close();\n closedSuccessfully = true;\n}\nfinally\n{\n if (!closedSuccessfully)\n {\n ((ICommunicationObject)wcfClient).Abort();\n }\n} \n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301613",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
301,622 | <p>I found this in the code I'm working on at the moment and thought it was the cause of some problems I'm having.</p>
<p>In a header somewhere:</p>
<pre><code>enum SpecificIndexes{
//snip
INVALID_INDEX = -1
};
</code></pre>
<p>Then later - initialization:</p>
<pre><code>nextIndex = INVALID_INDEX;
</code></pre>
<p>and use</p>
<pre><code>if(nextIndex != INVALID_INDEX)
{
//do stuff
}
</code></pre>
<p>Debugging the code, the values in nextIndex didn't quite make sence (they were very large), and I found that it was declared:</p>
<pre><code>unsigned int nextIndex;
</code></pre>
<p>So, the initial setting to INVALID_INDEX was underflowing the unsigned int and setting it to a huge number. I assumed that was what was causing the problem, but looking more closely, the test</p>
<pre><code>if(nextIndex != INVALID_INDEX)
</code></pre>
<p>Was behaving correctly, i.e, it never executed the body of the if when nextIndex was the "large +ve value".</p>
<p>Is this correct? How is this happening? Is the enum value being implicitly cast to an unsigned int of the same type as the variable, and hence being wrapped in the same way?</p>
| [
{
"answer_id": 301657,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "unsigned int nextIndex;\n int nextIndex;\n"
},
{
"answer_id": 308693,
"author": "Steve Jessop",
"author_id": 13005,
"author_profile": "https://Stackoverflow.com/users/13005",
"pm_score": 2,
"selected": false,
"text": "SpecificIndexes value = INVALID_VALUE;\nreturn (value >= 0);\n unsigned int value = INVALID_VALUE;\nreturn (value >= 0);\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301622",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15667/"
] |
301,624 | <p>I'm trying to load spring beans using XmlWebApplicationContext setConfigLocations method. However, I keep getting a </p>
<pre><code>BeanIsAbstractException
</code></pre>
<p>I know that the bean is abstract, I have it configured this way, so Spring should know not to try to instantiate it.</p>
<p>I'm using Spring2.0.8.jar with jetspeed2.1.</p>
<p>Spring bean:</p>
<pre><code><bean id="ThreadPool" abstract="true" class="com.sample.ThreadPoolFactoryBean"/>
</code></pre>
<p>Code:</p>
<pre><code>ctx = appContext;
appContext.refresh();
BeanFactory factory = appContext.getBeanFactory();
String[] beansName = appContext.getBeanFactory()
.getBeanDefinitionNames();
...
map.put(beansName[mnCnt], factory.getBean(beansName[mnCnt]));
</code></pre>
<p>Anyone have any ideas?</p>
| [
{
"answer_id": 301645,
"author": "toolkit",
"author_id": 3295,
"author_profile": "https://Stackoverflow.com/users/3295",
"pm_score": 2,
"selected": false,
"text": "map.put(beansName[mnCnt], factory.getBean(beansName[mnCnt]));\n class Fruit {\n private String colour;\n private String name;\n // setters...\n}\n\nclass Car {\n private String colour;\n private String manufacturer;\n // setters...\n}\n <!-- specifying a class for an abstract bean is optional -->\n<bean id=\"sharedPropsBean\" abstract=\"true\">\n <property name=\"colour\" value=\"red\" />\n</bean>\n\n<bean id=\"myFruit\" parent=\"sharedPropsBean\" class=\"Fruit\">\n <property name=\"name\" value=\"apple\" />\n</bean>\n\n<bean id=\"myCar\" parent=\"sharedPropsBean\" class=\"Car\">\n <property name=\"manufacturer\" value=\"Ferrari\" />\n</bean>\n"
},
{
"answer_id": 301654,
"author": "cdugga",
"author_id": 24481,
"author_profile": "https://Stackoverflow.com/users/24481",
"pm_score": 0,
"selected": false,
"text": "<bean id=\"ThreadPool\" abstract=\"true\" class=\"com.sample.ThreadPoolFactoryBean\"/>\n ctx = appContext;\n appContext.refresh();\n BeanFactory factory = appContext.getBeanFactory();\n String[] beansName = appContext.getBeanFactory()\n .getBeanDefinitionNames();\n"
},
{
"answer_id": 301794,
"author": "Nils-Petter Nilsen",
"author_id": 35014,
"author_profile": "https://Stackoverflow.com/users/35014",
"pm_score": 3,
"selected": true,
"text": "map.put(beansName[mnCnt], factory.getBean(beansName[mnCnt]));\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301624",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24481/"
] |
301,637 | <p>I need to perform a HTTP GET from PHP. </p>
<p>More specifically, from within /index.php I need to get the content of /trac/ and /svn/, find the "ul" element and then render then inline on the index.php.</p>
<p>/trac and /svn are relative URLs and not filesystem folders.
<a href="http://myserver/trac" rel="nofollow noreferrer">http://myserver/trac</a> and <a href="http://myserver/svn" rel="nofollow noreferrer">http://myserver/svn</a></p>
| [
{
"answer_id": 301664,
"author": "Greg",
"author_id": 24181,
"author_profile": "https://Stackoverflow.com/users/24181",
"pm_score": 4,
"selected": true,
"text": "file_get_contents() $str = file_get_contents('http://myserver/svn/');\n\n// Or, if you don't want to hardcode the server\n$str = file_get_contents('http://' . $_SERVER['HTTP_HOST'] . '/svn/');\n\nif ($str)\n{\n // Find the ul\n}\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301637",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29075/"
] |
301,639 | <p>We have a huge web application running on lasso, mainly because it first was a huge internal Filemaker database, that was to be opened to the public as a web app.</p>
<p>The web application doesn't use Filemaker though, it runs on a MySQL database, recreated every day.</p>
<p>The only reason I know of for using lasso is it's easy integration with Filemaker, but I never used lasso. (I'm a perl/php/mysql/javascript guy)</p>
<hr>
<p>So I have three questions:<br>
Is lasso a viable language for a web app? Are there any important benefits it offers over other languages?</p>
<p>Should we want to upgrade that app, should we use a more widely used and know language, or should we stick with lasso?</p>
<p>Is there anyone here that actually uses lasso?</p>
| [
{
"answer_id": 677851,
"author": "Sam",
"author_id": 81767,
"author_profile": "https://Stackoverflow.com/users/81767",
"pm_score": 2,
"selected": true,
"text": "[SquareBrackets]"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301639",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2452/"
] |
301,655 | <p>Can anyone explain to me what this means?</p>
<p>"Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention."</p>
| [
{
"answer_id": 301952,
"author": "Andreas Magnusson",
"author_id": 5811,
"author_profile": "https://Stackoverflow.com/users/5811",
"pm_score": 0,
"selected": false,
"text": "DialogBox(hInstance, MAKEINTRESOURCE(MY_DIALOG), hWnd, &dlgProc);\n INT_PTR WINAPI dlgProc(HWND, UINT, WPARAM, LPARAM);\n INT_PTR dlgProc(HWND, UINT, WPARAM, LPARAM);\n DialogBox(hInstance, MAKEINTRESOURCE(MY_DIALOG), hWnd, (DLGPROC)&dlgProc); // be a DLGPROC already, dammit!!\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301655",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18664/"
] |
301,658 | <p>How do you set a break points in server tags in .aspx pages. e.g.</p>
<pre><code><% dim breakhere =new object() %>
</code></pre>
<p>The web application is running in debug mode with the <code><compilation debug="true" ...</code> in the web.config. But the page says:</p>
<blockquote>
<p>The break point will not currently be
hit. No symbols have been loaded for
this document.</p>
</blockquote>
<p>Is there anything else i need to set?</p>
| [
{
"answer_id": 301950,
"author": "rams",
"author_id": 3635,
"author_profile": "https://Stackoverflow.com/users/3635",
"pm_score": -1,
"selected": false,
"text": "<%\nSTOP\nDim o as Object = new Object()\n%>\n"
},
{
"answer_id": 302146,
"author": "Scott Ivey",
"author_id": 36297,
"author_profile": "https://Stackoverflow.com/users/36297",
"pm_score": 6,
"selected": true,
"text": "<% System.Diagnostics.Debugger.Break();\n\n // more code here...\n\n %>\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301658",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29547/"
] |
301,667 | <p>I would like to replace "&gt" with ">" and "&lt" with "<" but only when they occur outside "<pre>" and "</pre>". Is this possible?</p>
<pre><code>$newText = preg_replace('&gt', '>', $text);
</code></pre>
<p>I would be using the preg_replace in PHP as above.</p>
| [
{
"answer_id": 301753,
"author": "annakata",
"author_id": 13018,
"author_profile": "https://Stackoverflow.com/users/13018",
"pm_score": 0,
"selected": false,
"text": "/(?<!(<pre>[^(<\\/pre>)]*))XXX(?!(.*<\\/pre>))/\n"
},
{
"answer_id": 301768,
"author": "Tom Haigh",
"author_id": 22224,
"author_profile": "https://Stackoverflow.com/users/22224",
"pm_score": 2,
"selected": false,
"text": "<?php\n\n$html = ' <pre>hello > <</pre>\n > <\n <pre></pre>';\n\n\nfunction stringReplaceThing($str) {\n $offset = 0;\n $num = 0;\n $preContents = array();\n $length = strlen($str);\n\n //copy string so can maintain offsets/positions in the first string after replacements are made\n $str2=$str;\n\n //get next position of <pre> tag\n while (false !== ($startPos = stripos($str, '<pre>', $offset))) {\n //the end of the opening <pre> tag\n $startPos += 5;\n\n //try to get closing tag\n $endPos = stripos($str, '</pre>', $startPos);\n\n if ($endPos === false) {\n die('unclosed pre tag..');\n }\n\n $stringWithinPreTags = substr($str, $startPos, $endPos - $startPos);\n //replace string within tags with some sort of token\n if (strlen($stringWithinPreTags)) {\n $token = \"!!T{$num}!!\";\n $str2 = str_replace($stringWithinPreTags, $token, $str2);\n $preContents[$token] = $stringWithinPreTags;\n $num++;\n }\n\n $offset = $endPos + 5;\n }\n\n //do the actual replacement\n $str2 = str_replace(array('>', '<'), array('>', '<'), $str2);\n\n //put the contents of <pre></pre> blocks back in\n $str2 = str_replace(array_keys($preContents), array_values($preContents), $str2);\n return $str2;\n}\n\n\nprint stringReplaceThing($html);\n"
},
{
"answer_id": 304574,
"author": "Jan Goyvaerts",
"author_id": 33358,
"author_profile": "https://Stackoverflow.com/users/33358",
"pm_score": 3,
"selected": true,
"text": "$new_text = preg_replace_callback('%<|>|<pre>.*?</pre>%si', compute_replacement, $text);\n\nfunction compute_replacement($groups) {\n if ($groups[0] == '<') {\n return '<';\n } elseif ($groups[1] == '>') {\n return '>';\n } else {\n return $groups[0];\n }\n}\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301667",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4639/"
] |
301,669 | <p>to do some visualization of data I would like to include rectangles, circles and text within my graphs. Does anyone know a Java based framework (maybe similar to very basic Powerpoint functionality) that can export SVG graphics?</p>
| [
{
"answer_id": 301721,
"author": "Nailer",
"author_id": 37346,
"author_profile": "https://Stackoverflow.com/users/37346",
"pm_score": 0,
"selected": false,
"text": "public void draw(Graphics graphicsIn)"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301669",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39444/"
] |
301,678 | <p>Is it possible to embed a windows form within another windows form?</p>
<p>I have created a windows form in Visual Studio along with all its associated behaviour.</p>
<p>I now want to create another windows form containing a tab view, and I want to embed the first windows form into the tab view. Is this possible?</p>
| [
{
"answer_id": 893369,
"author": "Refracted Paladin",
"author_id": 46724,
"author_profile": "https://Stackoverflow.com/users/46724",
"pm_score": 4,
"selected": false,
"text": "public static void ShowFormInContainerControl(Control ctl, Form frm)\n{\n frm.TopLevel = false;\n frm.FormBorderStyle = FormBorderStyle.None;\n frm.Dock = DockStyle.Fill;\n frm.Visible = true;\n ctl.Controls.Add(frm);\n}\n public FrmCaseNotes FrmCaseNotes;\nFrmCaseNotes = new FrmCaseNotes();\nWinFormCustomHandling.ShowFormInContainerControl(tpgCaseNotes, FrmCaseNotes);\n tpgCaseNotes FrmCaseNotes"
},
{
"answer_id": 6863473,
"author": "LBQC",
"author_id": 868050,
"author_profile": "https://Stackoverflow.com/users/868050",
"pm_score": 2,
"selected": false,
"text": " win2.Form1 formI = new win2.Form1();\n formI.TopLevel = false;\n formI.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;\n formI.Size = this.Size;\n formI.BringToFront();\n formI.Visible = true;\n this.Controls.Add(formI);\n"
},
{
"answer_id": 66322703,
"author": "Proger",
"author_id": 15262408,
"author_profile": "https://Stackoverflow.com/users/15262408",
"pm_score": 0,
"selected": false,
"text": "using System.Runtime.InteropServices;\nclass EmbedForm{\n [DllImport(\"user32.dll\")]\n public extern IntPtr SetParent(IntPtr hWndChild, hWndNewParent);\n //code, code, code...\n}\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301678",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/38900/"
] |
301,679 | <p>I'm trying to print a RDLC file directly without showing Microsoft Report Viewer, I have followed the <a href="http://msdn.microsoft.com/en-us/library/ms252172.aspx" rel="noreferrer">MSDN's example</a> but now, every time I call the "Render" method of my instance of LocalReport class it throws the "One or more parameters required to run the report have not been specified." exception.</p>
<p>Can anyone tell me which parameter is required that I missed? or how can I find more detail about this exception?</p>
<pre><code> LocalReport report = new LocalReport();
report.ReportPath = System.Windows.Forms.Application.StartupPath + "\\" + rdlcFileName;
report.EnableExternalImages = true;
ReportParameter[] reportParams = new ReportParameter[]
{
new ReportParameter("LogoAddress", settings.LogoFileName),
new ReportParameter("FooterValue", settings.InvoicesFooter)
};
report.SetParameters(reportParams);
report.DataSources.Add(new ReportDataSource("Invoice", new PrintableInvoice[] { invoice }));
report.DataSources.Add(new ReportDataSource("InvoiceItem", invoiceItems));
Warning[] warnings;
try
{
string deviceInfo =
"<DeviceInfo>" +
" <OutputFormat>EMF</OutputFormat>" +
" <PageWidth>8.5in</PageWidth>" +
" <PageHeight>11in</PageHeight>" +
" <MarginTop>0.25in</MarginTop>" +
" <MarginLeft>0.25in</MarginLeft>" +
" <MarginRight>0.25in</MarginRight>" +
" <MarginBottom>0.25in</MarginBottom>" +
"</DeviceInfo>";
m_streams = new List<Stream>();
report.Render("Image", deviceInfo, _CreateStream, out warnings);
foreach( Stream stream in m_streams )
stream.Position = 0;
}
catch( Exception ex )
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}
</code></pre>
<p>and the _CreateStream is:</p>
<pre><code> private Stream _CreateStream(string name, string fileNameExtension, Encoding encoding, string mimeType, bool willSeek)
{
Stream stream = new FileStream(name + "." + fileNameExtension, FileMode.Create);
m_streams.Add(stream);
return stream;
}
</code></pre>
| [
{
"answer_id": 34086732,
"author": "Konstantine Muradov",
"author_id": 2714152,
"author_profile": "https://Stackoverflow.com/users/2714152",
"pm_score": 2,
"selected": false,
"text": "var result = report.LocalReport.GetParameters(); result[0].State MissingValidValue var rv = new ReportViewer { ProcessingMode = ProcessingMode.Local };\n rv.LocalReport.ReportPath = Server.MapPath(\"~/PrintForms/FromForm.rdlc\");\n rv.LocalReport.Refresh();\n\n string mimeType;\n string encoding;\n string filenameExtension;\n string[] streamids;\n Warning[] warnings;\n\n rv.LocalReport.SetParameters(new ReportParameter(\"ClientName\", \"αααα αα αααα ααα«α\"));\n rv.LocalReport.SetParameters(new ReportParameter(\"Account\", \"888\"));var streamBytes = rv.LocalReport.Render(\"PDF\", null, out mimeType, out encoding, out filenameExtension, out streamids, out warnings);\n return File(streamBytes, mimeType);\n rv.LocalReport.SetParameters(new ReportParameter(\"Account\", null));\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301679",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34623/"
] |
301,681 | <p>Edit: This behaviour is reproducible with <a href="https://stackoverflow.com/questions/301766/mutability-and-reference-of-php5-get-variables">query globals</a> on.</p>
<p>I have the following:</p>
<pre><code> $_SESSION['query_key'] = $_GET['query_key'];
print($query_key);
</code></pre>
<p>Vs.</p>
<pre><code> $_SESSION['query_key'] = clone $_GET['query_key'];
print($query_key);
</code></pre>
<p>The former prints out the value of $query_key, while the latter prints nothing.
What sort of weird side effect is this of clone?</p>
| [
{
"answer_id": 301888,
"author": "Tom Haigh",
"author_id": 22224,
"author_profile": "https://Stackoverflow.com/users/22224",
"pm_score": 0,
"selected": false,
"text": "$_SESSION['query_key'] = 'anything'\n $_SESSION['query_key']"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301681",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6691/"
] |
301,683 | <p>In the grails-framework some objects are using log. This is normally injected by grails. It works on execution of <code>grails test-app</code>. But the same test (an integration-test) fails on execution of <code>grails test-app -integration</code>.</p>
<p>What goes wrong here and can I force the injection of the log-object somehow?</p>
| [
{
"answer_id": 303441,
"author": "Ted Naleid",
"author_id": 8912,
"author_profile": "https://Stackoverflow.com/users/8912",
"pm_score": 2,
"selected": false,
"text": "class FooService {\n def logSomething(message) {\n log.error(message)\n return true\n }\n}\n class FooServiceTests extends GroovyTestCase {\n def fooService\n void testSomething() {\n assert fooService.logSomething(\"it works\")\n }\n}\n % grails test-app \n\nWelcome to Grails 1.0.4 - http://grails.org/\n....\n-------------------------------------------------------\nRunning 1 Integration Test...\nRunning test FooServiceTests...\n testSomething...[4174] service.FooService it works\nSUCCESS\nIntegration Tests Completed in 440ms\n-------------------------------------------------------\n...\n % grails test-app -integration\n\nWelcome to Grails 1.0.4 - http://grails.org/\n....\n-------------------------------------------------------\nRunning 1 Integration Test...\nRunning test FooServiceTests...\n testSomething...[4444] service.FooService it works\nSUCCESS\nIntegration Tests Completed in 481ms\n-------------------------------------------------------\n....\n"
},
{
"answer_id": 1547576,
"author": "Scott Bennett-McLeish",
"author_id": 1915,
"author_profile": "https://Stackoverflow.com/users/1915",
"pm_score": 1,
"selected": false,
"text": "void testTheMagic() {\n mockLogging(MyMagicService)\n def testService = new MyMagicService()\n ...\n}\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301683",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21005/"
] |
301,695 | <p>This is an SQL problem I can't wrap my head around in a simple query Is it possible?</p>
<p>The data set is (letters added for ease of understanding):</p>
<pre><code>Start End
10:01 10:12 (A)
10:03 10:06 (B)
10:05 10:25 (C)
10:14 10:42 (D)
10:32 10:36 (E)
</code></pre>
<p>The desired output is:</p>
<pre><code>PeriodStart New ActiveAtEnd MinActive MaxActive
09:50 0 0 0 0
10:00 3 (ABC) 2 (AC) 0 3 (ABC)
10:10 1 (D) 2 (CD) 1 (C) 2 (AC or CD)
10:20 0 1 (D) 1 (C) 2 (CD)
10:30 1 (E) 1 (D) 1 (D) 2 (DE)
10:40 0 0 0 1 (D)
10:50 0 0 0 0
</code></pre>
<p>So, the query needed is a summary of the first table, calculating the minimum overlapping time periods (Start-End) and the maximum overlapping time periods (Start-End) from the first table within a 10 minute period.</p>
<p>'New' is the number of rows with a Start in the summary period. 'ActiveAtEnd' is the number of rows active at the end of the summary period.</p>
<p>I'm using Oracle, but I'm sure a solution can be adjusted. Stored procedures not allowed - just plain SELECT/INSERT (views are allowed). Its also OK to run one SQL command per 10 minute output (as once populated, that will be how it keeps up to date.</p>
<p>Thanks for any ideas, including 'not possible' ;-)</p>
| [
{
"answer_id": 301740,
"author": "Unsliced",
"author_id": 2902,
"author_profile": "https://Stackoverflow.com/users/2902",
"pm_score": 0,
"selected": false,
"text": "select @periodStart PeriodStart\n, @periodEnd PeriodEnd \n, n.[new]\n, ae.ActiveAtEnd\nfrom (\nselect count(*) [new] \nfrom @times \nwhere [start] >= @periodStart\nand [start] < @PeriodEnd \n) n \ncross join \n(\nselect count(*) [ActiveAtEnd] \nfrom @times\nwhere [start] < @PeriodEnd \nand [end] >= @PeriodEnd \n) ae\n"
},
{
"answer_id": 301996,
"author": "Martin",
"author_id": 37367,
"author_profile": "https://Stackoverflow.com/users/37367",
"pm_score": 1,
"selected": false,
"text": "set @active:=0;\n\nselect \n period, \n sum( if( score=1, 1, 0)) New, \n if( max(ab) > max(aa), max(ab), max(aa)) MaxActive, \n if( min( ab ) < min( aa ), min(ab), min(aa)) MinActive \nfrom (\n select \n period, \n etime, \n score, \n @active ab, \n @active:=@active+score aa \n from (\n select \n from_unixtime( floor( unix_timestamp(start)/600) * 600) period, \n start etime, \n +1 score \n from ev \n union all\n select from_unixtime( floor( unix_timestamp(end)/600) * 600) period, \n end etime, \n -1 score\n from ev \n ) event order by etime\n ) as temp \ngroup by period;\n +---------------------+------+-----------+-----------+\n| period | New | MaxActive | MinActive |\n+---------------------+------+-----------+-----------+\n| 2008-11-19 10:00:00 | 3 | 3 | 0 |\n| 2008-11-19 10:10:00 | 1 | 2 | 1 |\n| 2008-11-19 10:20:00 | 0 | 2 | 1 |\n| 2008-11-19 10:30:00 | 1 | 2 | 1 |\n| 2008-11-19 10:40:00 | 0 | 1 | 0 |\n+---------------------+------+-----------+-----------+\n"
},
{
"answer_id": 302336,
"author": "Charles Bretana",
"author_id": 32632,
"author_profile": "https://Stackoverflow.com/users/32632",
"pm_score": 2,
"selected": false,
"text": " Select T.Start, \n (Select Count(*) From testTab\n Where Start Between T.Start \n And DateAdd(minute, 10, T.Start)) New,\n (Select Count(*) From testTab\n Where Start < DateAdd(minute, 10, T.Start)\n And EndDt > DateAdd(minute, 10, T.Start)) ActiveAtEnd,\n (Select Max(Cnt) From \n (Select Count(Distinct T.Which) Cnt\n From (Select Distinct Start\n From testTab\n Where Start Between T.Start \n And DateAdd(minute, 10, T.Start)\n Union Select T.Start \n Union Select DateAdd(minute, 10, T.Start)) Z\n Left Join testTab T \n On Z.Start Between T.Start And T.EndDt\n Group By Z.Start) ZZ ) MaxActive,\n (Select Min(Cnt) From \n (Select Count(Distinct T.Which) Cnt\n From (Select Distinct Start\n From testTab\n Where Start Between T.Start \n And DateAdd(minute, 10, T.Start)\n Union Select T.Start \n Union Select DateAdd(minute, 10, T.Start)) Z\n Left Join testTab T \n On Z.Start Between T.Start And T.EndDt\n Group By Z.Start) ZZ ) MinActive \n From @Times T\n Declare @Times Table (Start datetime Primary key Not Null)\nDeclare @Start DateTime \nSet @Start = '1 Nov 2008 10:00'\nWhile @Start < '1 Nov 2008 11:00' begin\n Insert @Times(Start) values(@Start)\n Set @Start = DateAdd(minute, 10, @Start) \nEnd\n start endDt Which\n----------------------- ----------------------- -----\n2008-11-01 10:01:00.000 2008-11-01 10:12:00.000 A\n2008-11-01 10:03:00.000 2008-11-01 10:06:00.000 B\n2008-11-01 10:05:00.000 2008-11-01 10:25:00.000 C\n2008-11-01 10:14:00.000 2008-11-01 10:42:00.000 D\n2008-11-01 10:32:00.000 2008-11-01 10:36:00.000 E\n2008-11-01 10:22:00.000 2008-11-01 10:51:00.000 F\n2008-11-01 10:22:00.000 2008-11-01 10:23:00.000 G\n\nStart New ActiveAtEnd MaxActive MinActive\n----------------------- ----------- ----------- ----------- -----------\n2008-11-01 10:00:00.000 3 2 3 0\n2008-11-01 10:10:00.000 1 2 2 2\n2008-11-01 10:20:00.000 2 2 4 2\n2008-11-01 10:30:00.000 1 2 3 2\n2008-11-01 10:40:00.000 0 1 2 1\n2008-11-01 10:50:00.000 0 0 1 0\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301695",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/38896/"
] |
301,696 | <p>I have a web app that is heavily loaded in javascript and css. First time users log in it takes some time to load once it is downloading js etc. Then the caching will make everything faster.</p>
<p>I want my users to be aware of this loading time. How can I add some code to "show" some loading information while js and css are downloaded?</p>
| [
{
"answer_id": 301736,
"author": "Alexander Malfait",
"author_id": 27449,
"author_profile": "https://Stackoverflow.com/users/27449",
"pm_score": 3,
"selected": true,
"text": "<html>\n <head>\n ... a bunch of CSS and JS files ...\n\n <script type=\"text/javascript\" src=\"clear-load.js\"></script>\n </head>\n <body>\n <div \n style=\"position: absolute; left: 50px; right: 50px; top: 50px; bottom: 50px; border: 3px solid black;\"\n id=\"loading-div\"\n >\n This page is loading! Be patient!\n </div>\n\n ... Your body content ...\n </body>\n</html>\n document.getElementById('loading-div').style.display = 'none';\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301696",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19224/"
] |
301,711 | <p>I would like to do the equivalent of the following:</p>
<pre><code>#define print_max(TYPE) \
# ifdef TYPE##_MAX \
printf("%lld\n", TYPE##_MAX); \
# endif
print_max(INT);
</code></pre>
<p>Now the <code>#ifdef</code> or any nested preprocessor directive is
not allowed as far as I can see in a function macro.
Any ideas?</p>
<p>Update: So it seems like this is not possible. Even a hack to check at runtime seems unachievable. So I think I'll go with something like:</p>
<pre><code>#ifndef BLAH_MAX
# define BLAH_MAX 0
#endif
# etc... for each type I'm interested in
#define print_max(TYPE) \
if (TYPE##_MAX) \
printf("%lld\n", TYPE##_MAX);
print_max(INT);
print_max(BLAH);
</code></pre>
| [
{
"answer_id": 301819,
"author": "Ferruccio",
"author_id": 4086,
"author_profile": "https://Stackoverflow.com/users/4086",
"pm_score": 0,
"selected": false,
"text": "#define _print_max(TYPE) \\\n#ifdef TYPE \\\nprintf(\"%lld\\n\", _TYPE); \\\n#endif\n\n#define print_max(TYPE) _print_max(MAX##_TYPE)\n\n\nvoid main() \n{\n print_max(INT)\n}\n"
},
{
"answer_id": 301875,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 3,
"selected": false,
"text": "# #"
},
{
"answer_id": 301889,
"author": "Andreas Magnusson",
"author_id": 5811,
"author_profile": "https://Stackoverflow.com/users/5811",
"pm_score": 0,
"selected": false,
"text": "#ifdef print_max _MAX INT_MAX"
},
{
"answer_id": 301910,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "#define PRINT_MAX(type) printf(\"%lld\\n\", _TYPE##_MAX);\n#define HAVE_MAX(type) _TYPE##_MAX // not sure if this works \n\n\n/* a repetitious block of code that I cannot factor out - this is the cheat */\n#ifdef HAVE_MAX(INT)\n#define PRINT_INT_MAX PRINT_MAX(INT)\n#endif\n\n#ifdef HAVE_MAX(LONG)\n#define PRINT_LONG_MAX PRINT_MAX(LONG)\n#endif\n/* end of cheat */\n\n\n#define print_max(type) PRINT_##TYPE##_MAX\n"
},
{
"answer_id": 302343,
"author": "Josh Kelley",
"author_id": 25507,
"author_profile": "https://Stackoverflow.com/users/25507",
"pm_score": 4,
"selected": false,
"text": "#define MAXES (SHRT)(INT)(LONG)(PATH)(DOESNT_EXIST)\n\n#if !BOOST_PP_IS_ITERATING\n\n/* This portion of the file (from here to #else) is the \"main\" file */\n\n#include <values.h>\n#include <stdio.h>\n#include <boost/preprocessor.hpp>\n\n/* Define a function print_maxes that iterates over the bottom portion of this\n * file for each word in MAXES */\n#define BOOST_PP_FILENAME_1 \"max.c\"\n#define BOOST_PP_ITERATION_LIMITS (0,BOOST_PP_DEC(BOOST_PP_SEQ_SIZE(MAXES)))\nvoid print_maxes(void) {\n#include BOOST_PP_ITERATE()\n}\n\nint main(int argc, char *argv[])\n{\n print_maxes();\n}\n\n#else\n\n/* This portion of the file is evaluated multiple times, with\n * BOOST_PP_ITERATION() resolving to a different number every time */\n\n/* Use BOOST_PP_ITERATION() to look up the current word in MAXES */\n#define CURRENT BOOST_PP_SEQ_ELEM(BOOST_PP_ITERATION(), MAXES)\n#define CURRENT_MAX BOOST_PP_CAT(CURRENT, _MAX)\n\n#if CURRENT_MAX\nprintf(\"The max of \" BOOST_PP_STRINGIZE(CURRENT) \" is %lld\\n\", (long long) CURRENT_MAX);\n#else\nprintf(\"The max of \" BOOST_PP_STRINGIZE(CURRENT) \" is undefined\\n\");\n#endif\n\n#undef CURRENT\n#undef CURRENT_MAX\n\n#endif\n"
},
{
"answer_id": 1365717,
"author": "Chris Dodd",
"author_id": 16406,
"author_profile": "https://Stackoverflow.com/users/16406",
"pm_score": 0,
"selected": false,
"text": "#undef IFDEF_INT_MAX\n#ifdef INT_MAX\n#define IFDEF_INT_MAX(X) X\n#else\n#define IFDEF_INT_MAX(X)\n#endif\n\n#undef IFDEF_BLAH_MAX\n#ifdef BLAH_MAX\n#define IFDEF_BLAH_MAX(X) X\n#else\n#define IFDEF_BLAH_MAX(X)\n#endif\n\n :\n #include \"ifdefs.h\"\n#define print_max(TYPE) \\\nIFDEF_##TYPE##_MAX( printf(\"%lld\\n\", TYPE##_MAX); )\n\nprint_max(INT);\nprint_max(BLAH);\n"
},
{
"answer_id": 51905218,
"author": "Gary H",
"author_id": 7898105,
"author_profile": "https://Stackoverflow.com/users/7898105",
"pm_score": 0,
"selected": false,
"text": "// Of course all this MAX/MIN stuff assumes 2's compilment, with 8-bit bytes...\n\n#define LARGEST_INTEGRAL_TYPE long long\n\n/* This will evaluate to TRUE for an unsigned type, and FALSE for a signed\n * type. We use 'signed char' since it should be the smallest signed type\n * (which will sign-extend up to <type>'s size) vs. possibly overflowing if\n * going in the other direction (from a larger type to a smaller one).\n */\n#define ISUNSIGNED(type) (((type) ((signed char) -1)) > (type) 0)\n\n/* We must test for the \"signed-ness\" of <type> to determine how to calculate\n * the minimum/maximum value.\n *\n * e.g., If a typedef'ed type name is passed in that is actually an unsigned\n * type:\n *\n * typedef unsigned int Oid;\n * MAXIMUM_(Oid);\n */\n#define MINIMUM_(type) ((type) (ISUNSIGNED(type) ? MINIMUM_UNSIGNED_(type) \\\n : MINIMUM_SIGNED_( type)))\n\n#define MAXIMUM_(type) ((type) (ISUNSIGNED(type) ? MAXIMUM_UNSIGNED_(type) \\\n : MAXIMUM_SIGNED_( type)))\n\n/* Minumum unsigned value; zero, by definition -- we really only have this\n * macro for symmetry.\n */\n#define MINIMUM_UNSIGNED_(type) ((type) 0)\n\n// Maximum unsigned value; all 1's.\n#define MAXIMUM_UNSIGNED_(type) \\\n ((~((unsigned LARGEST_INTEGRAL_TYPE) 0)) \\\n >> ((sizeof(LARGEST_INTEGRAL_TYPE) - sizeof(type)) * 8))\n\n/* Minimum signed value; a 1 in the most-significant bit.\n *\n * We use LARGEST_INTEGRAL_TYPE as our base type for the initial bit-shift\n * because we should never overflow (i.e., <type> should always be the same\n * size or smaller than LARGEST_INTEGRAL_TYPE).\n */\n#define MINIMUM_SIGNED_(type) \\\n ((type) \\\n ((signed LARGEST_INTEGRAL_TYPE) \\\n (~((unsigned LARGEST_INTEGRAL_TYPE) 0x0) << ((sizeof(type) * 8) - 1))))\n\n// Maximum signed value; 0 in most-significant bit; remaining bits all 1's.\n#define MAXIMUM_SIGNED_(type) (~MINIMUM_SIGNED_(type))\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301711",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4421/"
] |
301,714 | <p>I am using the following html page:</p>
<pre><code><html>
<head>
<title>AJAX Example</title>
<meta http-equiv="Content-Type" content="text/html"; charset="iso-8859-1">
</head>
<script language="JavaScript" src="ajaxlib.js"></script>
<!--define the ajax javascript library-->
<body>
Click this <a href="#" OnClick="GetEmployee()">link</a> to show ajax
content (will be processed backgroundly without
refreshing whole page)<br/>
<!--a href=# OnClick=GetEmployee() is the javascript event on a
link to execute javascript function (GetEmployee) inside ajaxlib.js-->
<div id="Result">< the result will be fetched here ></div>
<!--javascript use GetElementById function to replace the data
backgroundly, we use <div> tag with id Result here so javascript
can replace this value-->
</body>
</html>
</code></pre>
<p>The Javascript is here: <a href="http://www.nomorepasting.com/getpaste.php?pasteid=22046" rel="nofollow noreferrer">http://www.nomorepasting.com/getpaste.php?pasteid=22046</a></p>
<p>And the PHP is here: <a href="http://www.nomorepasting.com/getpaste.php?pasteid=22047" rel="nofollow noreferrer">http://www.nomorepasting.com/getpaste.php?pasteid=22047</a></p>
<p>The problem is, everything seems logical and there are no errors, but the javascript does not seem to be called, and calling the php file directly gives a result such as this:</p>
<p>Well the characters will not even paste in apparently...., but lots of little boxes with like this:</p>
<pre><code>10
01
</code></pre>
| [
{
"answer_id": 301745,
"author": "Greg",
"author_id": 24181,
"author_profile": "https://Stackoverflow.com/users/24181",
"pm_score": 2,
"selected": true,
"text": "getEmployee() return false; <a>"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301714",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1246613/"
] |
301,716 | <p>My scenario is:</p>
<p>I have a WPF Window with 3 data-bound text boxes</p>
<pre class="lang-xml prettyprint-override"><code>SettingsUI : Window
<Grid Name="SettingsUIGrid1">
<TextBox Text="{Binding val1}" ....
<TextBox Text="{Binding val2}" ....
<TextBox Text="{Binding val3}" ....
</Grid>
</code></pre>
<p>In the constructor I do this:</p>
<pre><code>SettingsUIGrid1.DataContext = coll[0]; // collection first value
</code></pre>
<p>When the Cancel button is clicked, I close my window:</p>
<pre><code>private void btnCancel_Click(object sender, RoutedEventArgs e) {
Close();
}
</code></pre>
<p>When I click the Show button, is shows values from the DB in text boxes, if user changes a text box value, and reloads the window the new value is displayed not the old one. Can someone suggest what to do to reload the values again and clear the in memory object?</p>
| [
{
"answer_id": 301818,
"author": "Bijington",
"author_id": 32348,
"author_profile": "https://Stackoverflow.com/users/32348",
"pm_score": 0,
"selected": false,
"text": "private static bool DataRowReallyChanged(DataRow row)\n {\n if (row == null)\n {\n return false;\n }\n\n if (!row.HasVersion(DataRowVersion.Current) || (row.RowState == DataRowState.Unchanged))\n {\n return false;\n }\n\n foreach (DataColumn c in row.Table.Columns)\n {\n if (row[c, DataRowVersion.Current].ToString() != row[c, DataRowVersion.Original].ToString())\n {\n return true;\n }\n }\n\n return false;\n }\n if (DataRowReallyChanged((DataRow)SettingsUIGrid1.DataContext))\n{\n ((DataRow)SettingsUIGrid1.DataContext).RejectChanges();\n}\n"
},
{
"answer_id": 301824,
"author": "Arcturus",
"author_id": 900,
"author_profile": "https://Stackoverflow.com/users/900",
"pm_score": 2,
"selected": false,
"text": "{Binding Path =val1, Mode=OneTime}\n"
},
{
"answer_id": 301954,
"author": "Sacha Bruttin",
"author_id": 20761,
"author_profile": "https://Stackoverflow.com/users/20761",
"pm_score": 0,
"selected": false,
"text": "<Grid Name=\"SettingsUIGrid1\">\n<TextBox Text=\"{Binding Path =val1, Mode=OneWay}\" ....\n<TextBox Text=\"{Binding Path =val2, Mode=OneWay}\" ....\n<TextBox Text=\"{Binding Path =val3, Mode=OneWay}\" ....\n</Grid>\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301716",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
301,722 | <p>I have a form with a DIV, 3 INPUTS, each INPUT sits within a LABEL element. I would like to change the background image of the DIV element when focusing on each INPUT.</p>
<p>I can't move back up the DOM to fix this with CSS, so could someone suggest a few lines of jQuery please?</p>
<p>Thanks</p>
| [
{
"answer_id": 301748,
"author": "Pat",
"author_id": 238,
"author_profile": "https://Stackoverflow.com/users/238",
"pm_score": 1,
"selected": false,
"text": "$('input').focus(function(){\n $(this).parent().parent().addClass('highlight');\n}).blur(function(){\n $(this).parent().parent().removeClass('highlight');\n});\n"
},
{
"answer_id": 301749,
"author": "James",
"author_id": 21677,
"author_profile": "https://Stackoverflow.com/users/21677",
"pm_score": 2,
"selected": false,
"text": "$('div input').focus(function(){\n $(this).parents('div:eq(0)').addClass('specialCSSclass');\n}).blur(function(){\n $(this).parents('div:eq(0)').removeClass('specialCSSclass');\n});\n"
},
{
"answer_id": 4694950,
"author": "Lawrence",
"author_id": 293578,
"author_profile": "https://Stackoverflow.com/users/293578",
"pm_score": 0,
"selected": false,
"text": "closest( selector )\n .closest( selector )\n .closest( selector, [ context ] )\nclosest( selectors, [ context ] )\n .closest( selectors, [ context ] )\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301722",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
301,725 | <p>I need to find out the position of the TR.</p>
<p>Actually, I got the index of the TD which is 291,
But I need to get the index of the TR contains the TD.</p>
<p>We can get the <code>innerHTML</code> by</p>
<pre><code>document.getElementsByTagName("td")[291].parentNode.innerHTML..
</code></pre>
<p>How to get the index of that <code>parentNode</code> I mean the TR.</p>
<p>Please help me</p>
| [
{
"answer_id": 301758,
"author": "Tor Haugen",
"author_id": 32050,
"author_profile": "https://Stackoverflow.com/users/32050",
"pm_score": 2,
"selected": false,
"text": "var parent = document.getElementsByTagName(\"td\")[291].parentNode;\nvar index = -1;\nfor (var i = 0; i < parent.childNodes.length; i++) {\n if (parent.childNodes.item(i) == tr) {\n index = i;\n break;\n }\n}\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301725",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/38172/"
] |
301,759 | <p>How can I return to the start of a line and overwrite what has already been output on the console? The following does not appear to work:</p>
<pre><code>System.out.print(mystuff+'\r');
</code></pre>
| [
{
"answer_id": 301779,
"author": "Avi",
"author_id": 1605,
"author_profile": "https://Stackoverflow.com/users/1605",
"pm_score": 2,
"selected": false,
"text": "System.out.println(mystuff);\n"
},
{
"answer_id": 302055,
"author": "mtruesdell",
"author_id": 6479,
"author_profile": "https://Stackoverflow.com/users/6479",
"pm_score": 5,
"selected": false,
"text": "public class Foo {\n public static void main(String[] args) throws Exception {\n System.out.print(\"old line\");\n Thread.sleep(3000);\n System.out.print(\"\\rnew\");\n }\n}\n System.out.println(\"foo\\b\\bun\")\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301759",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
301,766 | <p>I have the following in a page e.g. <code>/mypage?myvar=oldvalue</code></p>
<pre><code>$_SESSION['myvar'] = $_GET['myvar'];
$myvar = 'a_new_string'
</code></pre>
<p>Now <code>$_SESSION['myvar']</code> has the value <code>'a_new_string'</code></p>
<p>Is this by design?</p>
<p>How can I copy the <em>value</em> of <code>'myvar'</code> rather than a reference to it?</p>
| [
{
"answer_id": 301788,
"author": "Adriano Varoli Piazza",
"author_id": 22184,
"author_profile": "https://Stackoverflow.com/users/22184",
"pm_score": 0,
"selected": false,
"text": "<?php\nsession_start(); \n$_GET['myvar'] = ''; \n$_SESSION['myvar'] = $_GET['myvar']; \n$myvar = 'a_new_string'; \nvar_dump($_SESSION); \n?>\n array(1) { [\"myvar\"]=> string(0) \"\" }\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301766",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6691/"
] |
301,770 | <p>All the examples that I can search online use the App.Config mode of specifying the context definition retrieved by </p>
<pre><code>contextToGetSprungObjects = ContextRegistry.GetContext(contextname)
</code></pre>
<p>I want to use </p>
<pre><code>contextToGetSprungObjects = new XmlApplicationContext(sXmlFileName)
</code></pre>
<p>(I'm calling into a DLL (that needs Spring.net) from another executable (MsWord) so app.config approach is out). I tried sneaking in MyDll.dll.config.. didn't fly.
On using the XmlApplicationContext approach to read it from a specified xml file, I get the following error </p>
<pre><code>{"Error registering object with name '' defined in 'file [D:\\Work\\Seven\\WordAutomation\\ContentControls\\WordDocument1\\bin\\debug\\MyWPFPlotPopup.dll.config]' : There is no parser registered for namespace ''\r\n<configSections><sectionGroup name=\"spring\"><section name=\"context\" type=\"Spring.Context.Support.ContextHandler, Spring.Core\" /></sectionGroup><section name=\"log4net\" type=\"log4net.Config.Log4NetConfigurationSectionHandler, log4net\" /></configSections>"}
</code></pre>
<p>Which leads me to believe that the two approaches need their xml in a differently shaped bottle. I searched high and low but the schema for the xml that is needed eludes me.. everything I can find uses X.exe.config or Web.config. Can someone point me to a valid xml context defintion for Spring.net?</p>
<pre><code><spring>
<context>
<context name="MyApplication">
<resource uri="file://Resources/MyApplicationContext.xml"/>
</context>
</context>
</spring>
</code></pre>
<p>I think this is the relevant section of the app.config that I want Spring.net to readd</p>
| [
{
"answer_id": 301788,
"author": "Adriano Varoli Piazza",
"author_id": 22184,
"author_profile": "https://Stackoverflow.com/users/22184",
"pm_score": 0,
"selected": false,
"text": "<?php\nsession_start(); \n$_GET['myvar'] = ''; \n$_SESSION['myvar'] = $_GET['myvar']; \n$myvar = 'a_new_string'; \nvar_dump($_SESSION); \n?>\n array(1) { [\"myvar\"]=> string(0) \"\" }\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301770",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1695/"
] |
301,772 | <p>I am using Rob Connery's excellent MVC Storefront as a loose basis for my new MVC Web App but I'm having trouble porting the LazyList code to VB.NET (don't ask).</p>
<p>It seems that VB doesn't allow the GetEnumerator function to be specified twice with only differing return types. Does anyone know how I might get around this?</p>
<p>Thanks</p>
<pre><code>Private Function GetEnumerator() As IEnumerator(Of T) Implements IEnumerable(Of T).GetEnumerator
Return Inner.GetEnumerator()
End Function
Public Function GetEnumerator() As IEnumerator Implements IList(Of T).GetEnumerator
Return DirectCast(Inner, IEnumerable).GetEnumerator()
End Function
</code></pre>
| [
{
"answer_id": 322884,
"author": "BlackMael",
"author_id": 19377,
"author_profile": "https://Stackoverflow.com/users/19377",
"pm_score": 3,
"selected": true,
"text": "Public Function GetEnumerator() As IEnumerator(Of T) _\n Implements IEnumerable(Of T).GetEnumerator\n\n Return Inner.GetEnumerator()\nEnd Function\n\nPublic Function GetListEnumerator() As IEnumerator _\n Implements IList(Of T).GetEnumerator\n\n Return DirectCast(Inner, IEnumerable).GetEnumerator()\nEnd Function\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301772",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/38911/"
] |
301,776 | <p>I would like to know if there is any easy way to print multiple emails(about 200) so that they continue on as opposed to printing one per page. I have tried with thunderbird and evolution and this does not seem possible. Would concatenating the individual mail files work or are there other unix utilities that could do this? WOuld sed or awk be suited for this?</p>
| [
{
"answer_id": 301796,
"author": "boutta",
"author_id": 15108,
"author_profile": "https://Stackoverflow.com/users/15108",
"pm_score": 3,
"selected": true,
"text": "cat *.eml > file.txt\n cat *.eml | lpr\n"
},
{
"answer_id": 317717,
"author": "shank",
"author_id": 24697,
"author_profile": "https://Stackoverflow.com/users/24697",
"pm_score": 1,
"selected": false,
"text": "#!/usr/bin/perl\n\nuse Email::Abstract;\n\nwhile ($mfile = shift @ARGV)\n{\n open(DATA, \"<$mfile\") || die \"unable to open $mfile\";\n\n my $message = do { local $/; <DATA>; };\n\n my $email = Email::Abstract->new($message);\n\n my $subject = $email->get_header(\"Subject\");\n my $from = $email->get_header(\"From\");\n my $date = $email->get_header(\"Date\");\n my $body = $email->get_body;\n\n print \"SUBJECT: $subject\\nFROM: $from\\nDATE: $date\\n\\n$body\\n\\n\";\n print \"-\" x 65, \"\\n\" if $#ARGV > 0;\n}\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301776",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1246613/"
] |
301,793 | <p>I am trying to accomplish the following in MySQL (see <code>pseudo</code> code)</p>
<pre><code>SELECT DISTINCT gid
FROM `gd`
WHERE COUNT(*) > 10
ORDER BY lastupdated DESC
</code></pre>
<p>Is there a way to do this without using a (SELECT...) in the WHERE clause because that would seem like a waste of resources.</p>
| [
{
"answer_id": 301804,
"author": "Winston Smith",
"author_id": 35086,
"author_profile": "https://Stackoverflow.com/users/35086",
"pm_score": 5,
"selected": false,
"text": "SELECT COUNT(*)\nFROM `gd`\nGROUP BY gid\nHAVING COUNT(gid) > 10\nORDER BY lastupdated DESC;\n SELECT MIN(gid)\nFROM `gd`\nGROUP BY gid\nHAVING COUNT(gid) > 10\nORDER BY lastupdated DESC\n"
},
{
"answer_id": 301805,
"author": "Ali ErsΓΆz",
"author_id": 4215,
"author_profile": "https://Stackoverflow.com/users/4215",
"pm_score": 8,
"selected": false,
"text": "select gid\nfrom `gd`\ngroup by gid \nhaving count(*) > 10\norder by lastupdated desc\n"
},
{
"answer_id": 301806,
"author": "Greg",
"author_id": 24181,
"author_profile": "https://Stackoverflow.com/users/24181",
"pm_score": 5,
"selected": false,
"text": "SELECT gid, COUNT(*) AS num FROM gd GROUP BY gid HAVING num > 10 ORDER BY lastupdated DESC\n"
},
{
"answer_id": 301807,
"author": "sme",
"author_id": 4497,
"author_profile": "https://Stackoverflow.com/users/4497",
"pm_score": 4,
"selected": false,
"text": "SELECT DISTINCT gid\nFROM `gd`\ngroup by gid\nhaving count(*) > 10\nORDER BY max(lastupdated) DESC\n"
},
{
"answer_id": 8152344,
"author": "zzapper",
"author_id": 94335,
"author_profile": "https://Stackoverflow.com/users/94335",
"pm_score": 3,
"selected": false,
"text": "SELECT stationid\nFROM weather_data \nWHERE `Timestamp` LIKE '2011-11-15 %' AND \nstationid IN (SELECT `ID` FROM `weather_stations`)\nGROUP BY stationid \nHAVING COUNT(*) != 48;\n"
},
{
"answer_id": 10023703,
"author": "Tushar Pandey",
"author_id": 2377323,
"author_profile": "https://Stackoverflow.com/users/2377323",
"pm_score": 1,
"selected": false,
"text": "count() where where having having select count(*) from table_name\n where count()"
},
{
"answer_id": 18718933,
"author": "MΓ‘Ε₯a - Stitod.cz",
"author_id": 1164552,
"author_profile": "https://Stackoverflow.com/users/1164552",
"pm_score": 4,
"selected": false,
"text": "select *\nfrom (\n select gid, count(*) as tmpcount from gd group by gid\n) as tmp\nwhere tmpcount > 10;\n"
},
{
"answer_id": 34895771,
"author": "pushkarr",
"author_id": 5440350,
"author_profile": "https://Stackoverflow.com/users/5440350",
"pm_score": 4,
"selected": false,
"text": "SELECT column_name, aggregate_function(column_name)\nFROM table_name\nWHERE column_name operator value\nGROUP BY column_name\nHAVING aggregate_function(column_name) operator value;\n"
},
{
"answer_id": 57806931,
"author": "Mridul Pandey",
"author_id": 5375399,
"author_profile": "https://Stackoverflow.com/users/5375399",
"pm_score": 3,
"selected": false,
"text": "SELECT COUNT(*), M_Director.PID FROM Movie\nINNER JOIN M_Director ON Movie.MID = M_Director.MID \nGROUP BY M_Director.PID\nHAVING COUNT(*) > 10\nORDER BY COUNT(*) ASC\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301793",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
301,809 | <p>There has been a lot of sentiment to include a <code>nameof</code> operator in C#. As an example of how this operator would work, <code>nameof(Customer.Name)</code> would return the string <code>"Name"</code>.</p>
<p>I have a domain object. And I have to bind it. And I need names of properties as strings then. And I want them to be type-safe.</p>
<p>I remember coming across a workaround in .NET 3.5 which provided the functionality of <code>nameof</code> and involved lambda expressions. However, I have not been able to locate this workaround. Can anyone provide that workaround to me?</p>
<p>I am also interested in a way to implement the functionality of <code>nameof</code> in .NET 2.0 if that is possible.</p>
| [
{
"answer_id": 301812,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 2,
"selected": false,
"text": "MemberInfo PropertyInfo"
},
{
"answer_id": 301957,
"author": "reshefm",
"author_id": 30717,
"author_profile": "https://Stackoverflow.com/users/30717",
"pm_score": 7,
"selected": true,
"text": "class Program\n{\n static void Main()\n {\n var propName = Nameof<SampleClass>.Property(e => e.Name);\n\n Console.WriteLine(propName);\n }\n}\n\npublic class Nameof<T>\n{\n public static string Property<TProp>(Expression<Func<T, TProp>> expression)\n {\n var body = expression.Body as MemberExpression;\n if(body == null)\n throw new ArgumentException(\"'expression' should be a member expression\");\n return body.Member.Name;\n }\n}\n"
},
{
"answer_id": 302101,
"author": "Judah Gabriel Himango",
"author_id": 536,
"author_profile": "https://Stackoverflow.com/users/536",
"pm_score": 3,
"selected": false,
"text": "private void FuncPoo()\n{\n}\n\n...\n\n// Get the name of the function\nstring funcName = new Action(FuncPoo).Method.Name;\n"
},
{
"answer_id": 2041633,
"author": "Ad P.",
"author_id": 248010,
"author_profile": "https://Stackoverflow.com/users/248010",
"pm_score": 2,
"selected": false,
"text": "/// <summary>\n/// Provides the <see cref=\"nameof\"/> extension method that works as a workarounds for a nameof() operator, \n/// which should be added to C# sometime in the future.\n/// </summary>\npublic static class NameOfHelper\n{\n /// <summary>\n /// Returns a string represantaion of a property name (or a method name), which is given using a lambda expression.\n /// </summary>\n /// <typeparam name=\"T\">The type of the <paramref name=\"obj\"/> parameter.</typeparam>\n /// <typeparam name=\"TProp\">The type of the property (or the method's return type), which is used in the <paramref name=\"expression\"/> parameter.</typeparam>\n /// <param name=\"obj\">An object, that has the property (or method), which its name is returned.</param>\n /// <param name=\"expression\">A Lambda expression of this pattern: x => x.Property <BR/>\n /// Where the x is the <paramref name=\"obj\"/> and the Property is the property symbol of x.<BR/>\n /// (For a method, use: x => x.Method()</param>\n /// <returns>A string that has the name of the given property (or method).</returns>\n public static string nameof<T, TProp>(this T obj, Expression<Func<T, TProp>> expression)\n {\n MemberExpression memberExp = expression.Body as MemberExpression;\n if (memberExp != null)\n return memberExp.Member.Name;\n\n MethodCallExpression methodExp = expression.Body as MethodCallExpression;\n if (methodExp != null)\n return methodExp.Method.Name;\n\n throw new ArgumentException(\"'expression' should be a member expression or a method call expression.\", \"expression\");\n }\n\n /// <summary>\n /// Returns a string represantaion of a property name (or a method name), which is given using a lambda expression.\n /// </summary>\n /// <typeparam name=\"TProp\">The type of the property (or the method's return type), which is used in the <paramref name=\"expression\"/> parameter.</typeparam>\n /// <param name=\"expression\">A Lambda expression of this pattern: () => x.Property <BR/>\n /// Where Property is the property symbol of x.<BR/>\n /// (For a method, use: () => x.Method()</param>\n /// <returns>A string that has the name of the given property (or method).</returns>\n public static string nameof<TProp>(Expression<Func<TProp>> expression)\n {\n MemberExpression memberExp = expression.Body as MemberExpression;\n if (memberExp != null)\n return memberExp.Member.Name;\n\n MethodCallExpression methodExp = expression.Body as MethodCallExpression;\n if (methodExp != null)\n return methodExp.Method.Name;\n\n throw new ArgumentException(\"'expression' should be a member expression or a method call expression.\", \"expression\");\n }\n}\n static class Program\n{\n static void Main()\n {\n string strObj = null;\n Console.WriteLine(strObj.nameof(x => x.Length)); //gets the name of an object's property.\n Console.WriteLine(strObj.nameof(x => x.GetType())); //gets the name of an object's method.\n Console.WriteLine(NameOfHelper.nameof(() => string.Empty)); //gets the name of a class' property.\n Console.WriteLine(NameOfHelper.nameof(() => string.Copy(\"\"))); //gets the name of a class' method.\n }\n}\n"
},
{
"answer_id": 14929258,
"author": "Sergey",
"author_id": 1337779,
"author_profile": "https://Stackoverflow.com/users/1337779",
"pm_score": 1,
"selected": false,
"text": "NameOf.Property(() => new Order().Status) using System;\nusing System.Diagnostics.Contracts;\nusing System.Linq.Expressions;\n\nnamespace AgileDesign.Utilities\n{\npublic static class NameOf\n{\n ///<summary>\n /// Returns name of any method expression with any number of parameters either void or with a return value\n ///</summary>\n ///<param name = \"expression\">\n /// Any method expression with any number of parameters either void or with a return value\n ///</param>\n ///<returns>\n /// Name of any method with any number of parameters either void or with a return value\n ///</returns>\n [Pure]\n public static string Method(Expression<Action> expression)\n {\n Contract.Requires<ArgumentNullException>(expression != null);\n\n return ( (MethodCallExpression)expression.Body ).Method.Name;\n }\n\n ///<summary>\n /// Returns name of property, field or parameter expression (of anything but method)\n ///</summary>\n ///<param name = \"expression\">\n /// Property, field or parameter expression\n ///</param>\n ///<returns>\n /// Name of property, field, parameter\n ///</returns>\n [Pure]\n public static string Member(Expression<Func<object>> expression)\n {\n Contract.Requires<ArgumentNullException>(expression != null);\n\n if(expression.Body is UnaryExpression)\n {\n return ((MemberExpression)((UnaryExpression)expression.Body).Operand).Member.Name;\n }\n return ((MemberExpression)expression.Body).Member.Name;\n }\n }\n}\n"
},
{
"answer_id": 26085597,
"author": "Ronnie Overby",
"author_id": 64334,
"author_profile": "https://Stackoverflow.com/users/64334",
"pm_score": 2,
"selected": false,
"text": "nameof"
},
{
"answer_id": 33798662,
"author": "Larry",
"author_id": 24472,
"author_profile": "https://Stackoverflow.com/users/24472",
"pm_score": 2,
"selected": false,
"text": "public static string Property<TProp>(Expression<Func<T, TProp>> expression)\n{\n var s = expression.Body.ToString();\n var p = s.Remove(0, s.IndexOf('.') + 1);\n return p;\n}\n ? Nameof<DataGridViewCell>.Property(c => c.Style.BackColor.A);\n\"Style.BackColor.A\"\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301809",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/38325/"
] |
301,817 | <p>I have some data of the form</p>
<pre><code>Key ID Link
1 MASTER 123
2 AA 123
3 AA 123
4 BB 123
5 MASTER 456
6 CC 456
</code></pre>
<p>I would like to be able to select in the same select all linked items matching the selection criteria, plus the linked master. For example, if I have an ID of 'AA', I want the rows with ID = 'AA' to be returned, plus the row with ID = 'MASTER' and a link of 123:</p>
<pre><code>1 MASTER 123
2 AA 123
3 AA 123
</code></pre>
<p>I'm using Oracle 10.2g, so if any special Oracle syntax will make this easier, then that would be ok.</p>
| [
{
"answer_id": 301843,
"author": "rich",
"author_id": 25502,
"author_profile": "https://Stackoverflow.com/users/25502",
"pm_score": 0,
"selected": false,
"text": "select * from my_table where link in\n(select link\nfrom my_table\nwhere id = 'AA')\nand id in ('AA','MASTER')\n"
},
{
"answer_id": 301856,
"author": "Dave Costa",
"author_id": 6568,
"author_profile": "https://Stackoverflow.com/users/6568",
"pm_score": 3,
"selected": true,
"text": "SELECT DISTINCT key, id, link\n FROM the_table\n START WITH id = 'AA'\n CONNECT BY id = 'MASTER' and link = PRIOR link and 'AA' = PRIOR ID\n"
},
{
"answer_id": 301898,
"author": "Fabi1816",
"author_id": 32374,
"author_profile": "https://Stackoverflow.com/users/32374",
"pm_score": 0,
"selected": false,
"text": "select i.link from table i\nwhere i.id = YOUR_ID\n select * from table \nwhere link in (select i.link from table i where i.id = YOUR_ID)\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301817",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8163/"
] |
301,839 | <p>Currently, I am splitting all my tests by package (projects). So if I have 12 projects, I will create 1 more project for Unit Test with 12 classes that will test all my package. </p>
<p>Do you do the same way or do you have 1 testing class by class? How do you organize all your test?</p>
| [
{
"answer_id": 301866,
"author": "David Holm",
"author_id": 22247,
"author_profile": "https://Stackoverflow.com/users/22247",
"pm_score": 2,
"selected": false,
"text": "package/Class.cpp\npackage/Class.hpp\npackage/test/ClassUnitTest.cpp\npackage/test/ClassIntegrationTest.cpp\ntest/unit-test/main.cpp\ntest/integration-test/main.cpp\ntest/data\ntest/tmp\n"
},
{
"answer_id": 301885,
"author": "Bill the Lizard",
"author_id": 1288,
"author_profile": "https://Stackoverflow.com/users/1288",
"pm_score": 1,
"selected": false,
"text": "src.com.app\nsrc.com.app.model\nsrc.com.app.view\nsrc.com.app.controller\n\ntests.com.app\ntests.com.app.model\ntests.com.app.view\ntests.com.app.controller\n"
},
{
"answer_id": 301887,
"author": "boutta",
"author_id": 15108,
"author_profile": "https://Stackoverflow.com/users/15108",
"pm_score": 3,
"selected": false,
"text": "project/src/main/java/Package/Class.java\nproject/src/test/java/Package/ClassTest.java\nproject/src/main/resources/Package/resource.properties\nproject/src/test/resources/Package/test_resource.properties\n"
},
{
"answer_id": 302034,
"author": "Hates_",
"author_id": 3410,
"author_profile": "https://Stackoverflow.com/users/3410",
"pm_score": 1,
"selected": false,
"text": "src/com/company/package/Class.java\ntestsrc/com/company/package/ClassTest.java\n"
},
{
"answer_id": 323181,
"author": "philant",
"author_id": 18804,
"author_profile": "https://Stackoverflow.com/users/18804",
"pm_score": 0,
"selected": false,
"text": " .../component/src/\n /include/\n /doc/\n /bin/\n /test/\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301839",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13913/"
] |
301,844 | <p>I'm currently writing some methods that do some basic operations on form controls eg Textbox, Groupbox, these operations are generic and can be used in any application. </p>
<p>I started to write some unit tests and was just wondering should I use the real form controls found in System.Windows.Forms or should I just mock up the sections that I'm trying to test. So for example:</p>
<p>Say I have this method which takes a control and if it is a textbox it will clear the text property like this:</p>
<pre><code> public static void clearall(this Control control)
{
if (control.GetType() == typeof(TextBox))
{
((TextBox)control).Clear();
}
}
</code></pre>
<p>Then I want to test this method so I do something like this:</p>
<pre><code> [TestMethod]
public void TestClear()
{
List<Control> listofcontrols = new List<Control>();
TextBox textbox1 = new TextBox() {Text = "Hello World" };
TextBox textbox2 = new TextBox() { Text = "Hello World" };
TextBox textbox3 = new TextBox() { Text = "Hello World" };
TextBox textbox4 = new TextBox() { Text = "Hello World" };
listofcontrols.Add(textbox1);
listofcontrols.Add(textbox2);
listofcontrols.Add(textbox3);
listofcontrols.Add(textbox4);
foreach (Control control in listofcontrols)
{
control.clearall();
Assert.AreEqual("", control.Text);
}
}
</code></pre>
<p>Should I be adding a referance to System.Window.Forms to my unit test and use the real Textbox object? or am I doing it wrong? </p>
<p>NOTE: The above code is only an example, I didn't compile or run it.</p>
| [
{
"answer_id": 301884,
"author": "Brian Genisio",
"author_id": 36687,
"author_profile": "https://Stackoverflow.com/users/36687",
"pm_score": 2,
"selected": false,
"text": "public interface ITextBox\n{\n public string Text {get; set;}\n}\n\npublic class TextBoxAdapter : ITextBox\n{\n private readonly System.Windows.Forms.TextBox _textBox;\n public TextBoxAdapter(System.Windows.Forms.TextBox textBox)\n {\n _textBox = textBox;\n }\n\n public string Text\n {\n get { return _textBox.Text; }\n set { _textBox.Text = value; }\n }\n}\n\npublic class YourClass\n{\n private ITextBox _textBox;\n public YourClass(ITextBox textBox)\n {\n _textBox = textBox;\n }\n\n public void DoSomething()\n {\n _textBox.Text = \"twiddleMe\";\n }\n}\n"
},
{
"answer_id": 302540,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "[Test] public void ShouldCopyFromAvailableToSelectedWhenAddButtonIsCLicked(){\n myForm.AvailableList.Items.Add(\"red\");\n myForm.AvailableList.Items.Add(\"yellow\");\n myForm.AvailableList.Items.Add(\"blue\");\n\n myForm.AvailableList.SelectedIndex = 1;\n myForm.AddButton.Click();\n\n Assert.That(myForm.AvaiableList.Items.Count, Is.EqualTo(2));\n Assert.That(myForm.SelectedList.Items[0], Is.EqualTo(\"yellow\"));\n}\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301844",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6335/"
] |
301,854 | <p>Am I right to think that there is no way to set the selected value in the C# class SelectList after it is created?
Isn't that a bit silly?</p>
| [
{
"answer_id": 301923,
"author": "Tor Haugen",
"author_id": 32050,
"author_profile": "https://Stackoverflow.com/users/32050",
"pm_score": 0,
"selected": false,
"text": "var select = document.getElementById('mySelect');\nselect.options[newIndex].selected = true;\n"
},
{
"answer_id": 637264,
"author": "linh1987",
"author_id": 75931,
"author_profile": "https://Stackoverflow.com/users/75931",
"pm_score": 0,
"selected": false,
"text": "<%= Html.DropDownList(\"clientId\", ViewData[\"clients\"] as List<SelectListItem>,)%>\n ViewData[\"clientId\"] = \"ASD\"; //This should be the value of item you want to select\n ViewData[\"clients\"] = clientItemList; //List<SelectListItem>\n"
},
{
"answer_id": 1343176,
"author": "CmdrTallen",
"author_id": 74071,
"author_profile": "https://Stackoverflow.com/users/74071",
"pm_score": 0,
"selected": false,
"text": "$(function() {\n $(\"#myselectlist option[@value='ItemToSelectValue'].attr('selected', 'true');\n});\n"
},
{
"answer_id": 2253481,
"author": "awrigley",
"author_id": 271087,
"author_profile": "https://Stackoverflow.com/users/271087",
"pm_score": 5,
"selected": true,
"text": "SelectList DropDownList List<T> SelectList List<T> DropDownList Country of birth\nCountry of residence\n SelectLists List<Country> List<T> public class TaxCheatsFormViewModel\n{\n private List<Country> countries { get; set; }\n\n public TaxCheat Cheat { get; private set; }\n public SelectList CountryOfBirth { get; private set; }\n public SelectList CountryOfResidence { get; private set; }\n public SelectList CountryOfDomicile { get; private set; }\n\n public TaxCheatsFormViewModel(TaxCheat baddie)\n {\n TaxCheat = baddie;\n countries = TaxCheatRepository.GetList<Country>();\n CountryOfBirth = new SelectList(countries, baddie.COB);\n CountryOfResidence = new SelectList(countries, baddie.COR);\n CountryOfDomicile = new SelectList(countries, baddie.COD);\n }\n}\n List<T>"
},
{
"answer_id": 5602438,
"author": "eudaimos",
"author_id": 528748,
"author_profile": "https://Stackoverflow.com/users/528748",
"pm_score": 2,
"selected": false,
"text": "var model = new SubjectViewModel()\n{\n Subject = new Subject(),\n Types = data.SubjectTypes.ToList()\n}\nmodel.Subject.SubjectType = model.Types.FirstOrDefault(t => t.Id == typeId);\nViewData.Model = model;\nreturn View();\n Html.DropDownListFor(model => model.Subject.SubjectTypeId, new SelectList(model.Types, \"Id\", \"Name\"))\n"
},
{
"answer_id": 12287080,
"author": "JoeSharp",
"author_id": 220246,
"author_profile": "https://Stackoverflow.com/users/220246",
"pm_score": 2,
"selected": false,
"text": "SelectList myList = GetMySelectList();\nSelectListItem selected = myList.FirstOrDefault(x => x.Text.ToUpper().Contains(\"UNITED STATES\"));\nif (selected != null)\n{\n myList = new SelectList(myList, \"value\", \"text\", selected.Value);\n}\n"
},
{
"answer_id": 15917899,
"author": "spadelives",
"author_id": 1667230,
"author_profile": "https://Stackoverflow.com/users/1667230",
"pm_score": 0,
"selected": false,
"text": "@Html.DropDownListFor(x => myViewModelFieldName, new SelectList(Model.MyRawSelectListFromMyViewModel.Select(x=> new {x.Value, x.Text}), \"Value\", \"Text\", TheValueYouWantToSelect))\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301854",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11333/"
] |
301,860 | <p>I need to check whether the user executing the script has administrative privileges on the machine.</p>
<p>I have specified the user executing the script because the script could have been executed with a user other than the logged on using something similar to "Runas".</p>
<p>@Javier: Both solutions work in a PC with an English version of Windows installed but not if the installed is in different language. This is because the Administrators group doesn't exist, the name is different for instance in Spanish. I need the solution to work in all configurations. </p>
| [
{
"answer_id": 301920,
"author": "Tim C",
"author_id": 7585,
"author_profile": "https://Stackoverflow.com/users/7585",
"pm_score": 3,
"selected": true,
"text": "Set objNetwork = CreateObject(\"Wscript.Network\")\nstrComputer = objNetwork.ComputerName\nstrUser = objNetwork.UserName\n\nisAdministrator = false\n\nSet objGroup = GetObject(\"WinNT://\" & strComputer & \"/Administrators\")\nFor Each objUser in objGroup.Members\n If objUser.Name = strUser Then\n isAdministrator = true \n End If\nNext\n\nIf isAdministrator Then\n Wscript.Echo strUser & \" is a local administrator.\"\nElse\n Wscript.Echo strUser & \" is not a local administrator.\"\nEnd If\n"
},
{
"answer_id": 302155,
"author": "Patrick Cuff",
"author_id": 7903,
"author_profile": "https://Stackoverflow.com/users/7903",
"pm_score": 1,
"selected": false,
"text": "Function RetrieveUsers(domainName,grpName)\n\ndim GrpObj\ndim mbrlist\ndim mbr\n\n'-------------------------------------------------------------------------------\n' *** Enumerate Group Members ***\n'-------------------------------------------------------------------------------\n\n' Build the ADSI query and retrieve the group object\nSet GrpObj = GetObject(\"WinNT://\" & domainName & \"/\" & grpName & \",group\")\n\n' Loop through the group membership and build a string containing the names\nfor each mbr in GrpObj.Members\n mbrlist = mbrlist & vbTab & mbr.name & vbCrLf\nNext\n\nRetrieveUsers=mbrlist\n\nEnd Function\n Function IsAdmin(user)\n IsAdmin = InStr(RetrieveUsers(\"MachineName\", \"Administrators\"), user) > 0\nEnd Function\n If IsAdmin(\"LocalAccount\") Then\n Wscript.Echo \"LocalAccount is an admin\"\nElse\n Wscript.Echo \"LocalAccount is not an admin\"\nEnd If\n"
},
{
"answer_id": 7841964,
"author": "Dss",
"author_id": 227664,
"author_profile": "https://Stackoverflow.com/users/227664",
"pm_score": 2,
"selected": false,
"text": "Function isAdmin\n Dim shell\n set shell = CreateObject(\"WScript.Shell\")\n isAdmin = false\n errlvl = shell.Run(\"%comspec% /c defrag /?>nul 2>nul\", 0, True)\n if errlvl = 0 OR errlvl = 2 Then '0 on Win 7, 2 on XP\n isAdmin = true\n End If\nEnd Function\n"
},
{
"answer_id": 8371575,
"author": "JohnZaj",
"author_id": 38696,
"author_profile": "https://Stackoverflow.com/users/38696",
"pm_score": 2,
"selected": false,
"text": "function IsLoggedInAsAdmin()\n isAdmin = false\n set shell = CreateObject(\"WScript.Shell\")\n computername = WshShell.ExpandEnvironmentStrings(\"%computername%\")\n strAdmin = \"\\\\\" & computername & \"\\Admin$\\System32\"\n\n isAdmin = false\n\n set fso = CreateObject(\"Scripting.FileSystemObject\")\n\n if fso.FolderExists(strAdmin) then\n isAdmin = true\n end if\n\n IsLoggedInAsAdmin = isAdmin\nend function\n"
},
{
"answer_id": 16566961,
"author": "spudw",
"author_id": 2386190,
"author_profile": "https://Stackoverflow.com/users/2386190",
"pm_score": 1,
"selected": false,
"text": "Function IsNotAdmin()\n With CreateObject(\"Wscript.Shell\")\n IsNotAdmin = .Run(\"%comspec% /c OPENFILES > nul\", 0, True)\n End With\nEnd Function\n"
},
{
"answer_id": 26429227,
"author": "lygstate",
"author_id": 321938,
"author_profile": "https://Stackoverflow.com/users/321938",
"pm_score": 0,
"selected": false,
"text": "Function isAdmin\n Dim shell\n Set shell = CreateObject(\"WScript.Shell\")\n isAdmin = false\n errorLevel = shell.Run(\"%comspec% /c net session >nul 2>&1\", 0, True)\n if errorLevel = 0\n isAdmin = true\n End If\nEnd Function\n"
},
{
"answer_id": 38660671,
"author": "Stefan Bohlein",
"author_id": 4960339,
"author_profile": "https://Stackoverflow.com/users/4960339",
"pm_score": 0,
"selected": false,
"text": "' get_admin_status.vbs\nOption Explicit\n\nDim oGroup: Set oGroup = GetObject(\"WinNT://localhost/Administrators,group\")\nDim oNetwork: Set oNetwork = CreateObject(\"Wscript.Network\")\n\nDim sSearchPattern: sSearchPattern = \"WinNT://\" & oNetwork.UserDomain & \"/\" & oNetwork.UserName\n\nDim sMember\nFor Each sMember In oGroup.Members\n If sMember.adsPath = sSearchPattern Then\n ' Found...\n Call WScript.Quit(0)\n End If\nNext\n\n' Not found...\nCall WScript.Quit(1)\n"
},
{
"answer_id": 45068852,
"author": "RLH",
"author_id": 1742115,
"author_profile": "https://Stackoverflow.com/users/1742115",
"pm_score": 2,
"selected": false,
"text": "Option Explicit \n\nmsgbox isAdmin(), vbOkonly, \"Am I an admin?\"\n\nPrivate Function IsAdmin()\n On Error Resume Next\n CreateObject(\"WScript.Shell\").RegRead(\"HKEY_USERS\\S-1-5-19\\Environment\\TEMP\")\n if Err.number = 0 Then \n IsAdmin = True\n else\n IsAdmin = False\n end if\n Err.Clear\n On Error goto 0\nEnd Function\n"
},
{
"answer_id": 53652700,
"author": "OlegSu",
"author_id": 10755060,
"author_profile": "https://Stackoverflow.com/users/10755060",
"pm_score": 1,
"selected": false,
"text": "Set Shell = CreateObject(\"WScript.Shell\")\nset fso = CreateObject(\"Scripting.FileSystemObject\")\nstrCheckFolder = Shell.ExpandEnvironmentStrings(\"%USERPROFILE%\") \nstrCheckFolder = strCheckFolder+\"\\TempFolder\"\n\nif fso.FolderExists(strCheckFolder) then\n fso.DeleteFolder(strCheckFolder)\nend if\n\nfso.CreateFolder(strCheckFolder)\ntempstr = \"cmd.exe /u /c chcp 65001 | whoami /all >\" & strCheckFolder & \"\\rights.txt\"\nShell.run tempstr\n\ntempstr = strCheckFolder & \"\\rights.txt\"\nWScript.Sleep 200\nSet txtFile = FSO.OpenTextFile(tempstr,1)\n\nIsAdmin = False\n\nDo While Not txtFile.AtEndOfStream\n x=txtFile.Readline\n If InStr(x, \"S-1-5-32-544\") Then\n IsAdmin = True\n End If\nLoop\n\ntxtFile.Close\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301860",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14053/"
] |
301,865 | <p>So our scenario is this: We have multiple Sharepoint sites that are created dynamically on a "as requested" basis. Basically there's a new site for each new project. Now, for every site we want to add a search clause that says that only contents with a metadata tag value equal to the sitename should be found. Quick example:
There are 2 sites/projects: Bear and Wolf. Sharepoint Search has index all of the documents/lists/etc from these sites and a common archive for them. All documents in the common archive has a property called "ProjectName". When Bill, who's on the Wolf team, wants to search for "specifications" in his project site (Wolf) he only wants to see documents relevant to that project.
So how do I make sure that all the documents have the "ProjectName" value set to "Wolf"?</p>
<p>I'm guessing I <em>could</em> use Scopes here, but currently there are ~200 sites and this is growing every month and so maintaining that manually is not an option. If there's a relativly easy way of automating Scopes; excellent.</p>
| [
{
"answer_id": 301920,
"author": "Tim C",
"author_id": 7585,
"author_profile": "https://Stackoverflow.com/users/7585",
"pm_score": 3,
"selected": true,
"text": "Set objNetwork = CreateObject(\"Wscript.Network\")\nstrComputer = objNetwork.ComputerName\nstrUser = objNetwork.UserName\n\nisAdministrator = false\n\nSet objGroup = GetObject(\"WinNT://\" & strComputer & \"/Administrators\")\nFor Each objUser in objGroup.Members\n If objUser.Name = strUser Then\n isAdministrator = true \n End If\nNext\n\nIf isAdministrator Then\n Wscript.Echo strUser & \" is a local administrator.\"\nElse\n Wscript.Echo strUser & \" is not a local administrator.\"\nEnd If\n"
},
{
"answer_id": 302155,
"author": "Patrick Cuff",
"author_id": 7903,
"author_profile": "https://Stackoverflow.com/users/7903",
"pm_score": 1,
"selected": false,
"text": "Function RetrieveUsers(domainName,grpName)\n\ndim GrpObj\ndim mbrlist\ndim mbr\n\n'-------------------------------------------------------------------------------\n' *** Enumerate Group Members ***\n'-------------------------------------------------------------------------------\n\n' Build the ADSI query and retrieve the group object\nSet GrpObj = GetObject(\"WinNT://\" & domainName & \"/\" & grpName & \",group\")\n\n' Loop through the group membership and build a string containing the names\nfor each mbr in GrpObj.Members\n mbrlist = mbrlist & vbTab & mbr.name & vbCrLf\nNext\n\nRetrieveUsers=mbrlist\n\nEnd Function\n Function IsAdmin(user)\n IsAdmin = InStr(RetrieveUsers(\"MachineName\", \"Administrators\"), user) > 0\nEnd Function\n If IsAdmin(\"LocalAccount\") Then\n Wscript.Echo \"LocalAccount is an admin\"\nElse\n Wscript.Echo \"LocalAccount is not an admin\"\nEnd If\n"
},
{
"answer_id": 7841964,
"author": "Dss",
"author_id": 227664,
"author_profile": "https://Stackoverflow.com/users/227664",
"pm_score": 2,
"selected": false,
"text": "Function isAdmin\n Dim shell\n set shell = CreateObject(\"WScript.Shell\")\n isAdmin = false\n errlvl = shell.Run(\"%comspec% /c defrag /?>nul 2>nul\", 0, True)\n if errlvl = 0 OR errlvl = 2 Then '0 on Win 7, 2 on XP\n isAdmin = true\n End If\nEnd Function\n"
},
{
"answer_id": 8371575,
"author": "JohnZaj",
"author_id": 38696,
"author_profile": "https://Stackoverflow.com/users/38696",
"pm_score": 2,
"selected": false,
"text": "function IsLoggedInAsAdmin()\n isAdmin = false\n set shell = CreateObject(\"WScript.Shell\")\n computername = WshShell.ExpandEnvironmentStrings(\"%computername%\")\n strAdmin = \"\\\\\" & computername & \"\\Admin$\\System32\"\n\n isAdmin = false\n\n set fso = CreateObject(\"Scripting.FileSystemObject\")\n\n if fso.FolderExists(strAdmin) then\n isAdmin = true\n end if\n\n IsLoggedInAsAdmin = isAdmin\nend function\n"
},
{
"answer_id": 16566961,
"author": "spudw",
"author_id": 2386190,
"author_profile": "https://Stackoverflow.com/users/2386190",
"pm_score": 1,
"selected": false,
"text": "Function IsNotAdmin()\n With CreateObject(\"Wscript.Shell\")\n IsNotAdmin = .Run(\"%comspec% /c OPENFILES > nul\", 0, True)\n End With\nEnd Function\n"
},
{
"answer_id": 26429227,
"author": "lygstate",
"author_id": 321938,
"author_profile": "https://Stackoverflow.com/users/321938",
"pm_score": 0,
"selected": false,
"text": "Function isAdmin\n Dim shell\n Set shell = CreateObject(\"WScript.Shell\")\n isAdmin = false\n errorLevel = shell.Run(\"%comspec% /c net session >nul 2>&1\", 0, True)\n if errorLevel = 0\n isAdmin = true\n End If\nEnd Function\n"
},
{
"answer_id": 38660671,
"author": "Stefan Bohlein",
"author_id": 4960339,
"author_profile": "https://Stackoverflow.com/users/4960339",
"pm_score": 0,
"selected": false,
"text": "' get_admin_status.vbs\nOption Explicit\n\nDim oGroup: Set oGroup = GetObject(\"WinNT://localhost/Administrators,group\")\nDim oNetwork: Set oNetwork = CreateObject(\"Wscript.Network\")\n\nDim sSearchPattern: sSearchPattern = \"WinNT://\" & oNetwork.UserDomain & \"/\" & oNetwork.UserName\n\nDim sMember\nFor Each sMember In oGroup.Members\n If sMember.adsPath = sSearchPattern Then\n ' Found...\n Call WScript.Quit(0)\n End If\nNext\n\n' Not found...\nCall WScript.Quit(1)\n"
},
{
"answer_id": 45068852,
"author": "RLH",
"author_id": 1742115,
"author_profile": "https://Stackoverflow.com/users/1742115",
"pm_score": 2,
"selected": false,
"text": "Option Explicit \n\nmsgbox isAdmin(), vbOkonly, \"Am I an admin?\"\n\nPrivate Function IsAdmin()\n On Error Resume Next\n CreateObject(\"WScript.Shell\").RegRead(\"HKEY_USERS\\S-1-5-19\\Environment\\TEMP\")\n if Err.number = 0 Then \n IsAdmin = True\n else\n IsAdmin = False\n end if\n Err.Clear\n On Error goto 0\nEnd Function\n"
},
{
"answer_id": 53652700,
"author": "OlegSu",
"author_id": 10755060,
"author_profile": "https://Stackoverflow.com/users/10755060",
"pm_score": 1,
"selected": false,
"text": "Set Shell = CreateObject(\"WScript.Shell\")\nset fso = CreateObject(\"Scripting.FileSystemObject\")\nstrCheckFolder = Shell.ExpandEnvironmentStrings(\"%USERPROFILE%\") \nstrCheckFolder = strCheckFolder+\"\\TempFolder\"\n\nif fso.FolderExists(strCheckFolder) then\n fso.DeleteFolder(strCheckFolder)\nend if\n\nfso.CreateFolder(strCheckFolder)\ntempstr = \"cmd.exe /u /c chcp 65001 | whoami /all >\" & strCheckFolder & \"\\rights.txt\"\nShell.run tempstr\n\ntempstr = strCheckFolder & \"\\rights.txt\"\nWScript.Sleep 200\nSet txtFile = FSO.OpenTextFile(tempstr,1)\n\nIsAdmin = False\n\nDo While Not txtFile.AtEndOfStream\n x=txtFile.Readline\n If InStr(x, \"S-1-5-32-544\") Then\n IsAdmin = True\n End If\nLoop\n\ntxtFile.Close\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301865",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11220/"
] |
301,869 | <p>There seem to be so many color wheel, color picker, and color matcher web apps out there, where you give one color and the they'll find a couple of other colors that will create a harmonic layout when being used in combination. However most of them focus on background colors only and any text printed on each background color (if text is printed at all in the preview) is either black or white.</p>
<p>My problem is different. I know the background color I want to use for a text area. What I need help with is choosing a couple of colors (the more, the merrier) I can use as font colors on this background. Most important is that the color will make sure the font is readable (contrast not being too low, also maybe not being too high to avoid that eyes are stressed) and of course that the combination of foreground and background just looks good.</p>
<p>Anyone being aware of such an application? I'd prefer a web application to anything I have to download. Thanks.</p>
| [
{
"answer_id": 302091,
"author": "Aaron Digulla",
"author_id": 34088,
"author_profile": "https://Stackoverflow.com/users/34088",
"pm_score": 6,
"selected": true,
"text": "h = (h + 180) % 360;\n l = 1.0 - l;\nv = 1.0 - v;\n def q(x):\n return x*x\ndef diff(col1, col2):\n return math.sqrt(q(col1.r-col2.r) + q(col1.g-col2.g) + q(col1.b-col2.b))\n"
},
{
"answer_id": 302961,
"author": "Mecki",
"author_id": 15809,
"author_profile": "https://Stackoverflow.com/users/15809",
"pm_score": 2,
"selected": false,
"text": "java FontColorChooser 33FFB4\n || cDiff > 18.0\n import java.io.*;\n\n/* For text being readable, it must have a good contrast difference. Why?\n * Your eye has receptors for brightness and receptors for each of the colors\n * red, green and blue. However, it has much more receptors for brightness\n * than for color. If you only change the color, but both colors have the\n * same contrast, your eye must distinguish fore- and background by the\n * color only and this stresses the brain a lot over the time, because it\n * can only use the very small amount of signals it gets from the color\n * receptors, since the breightness receptors won't note a difference.\n * Actually contrast is so much more important than color that you don't\n * have to change the color at all. E.g. light red on dark red reads nicely\n * even though both are the same color, red.\n */\n\n\npublic class FontColorChooser {\n int bred;\n int bgreen;\n int bblue;\n\n public FontColorChooser(String hexColor) throws NumberFormatException {\n int i;\n\n i = Integer.parseInt(hexColor, 16);\n bred = (i >> 16);\n bgreen = (i >> 8) & 0xFF;\n bblue = i & 0xFF;\n }\n\n public static void main(String[] args) {\n FontColorChooser fcc;\n\n if (args.length == 0) {\n System.out.println(\"Missing argument!\");\n System.out.println(\n \"The first argument must be the background\" +\n \"color in hex notation.\"\n );\n System.out.println(\n \"E.g. \\\"FFFFFF\\\" for white or \\\"000000\\\" for black.\"\n );\n return;\n }\n try {\n fcc = new FontColorChooser(args[0]);\n } catch (Exception e) {\n System.out.println(\n args[0] + \" is no valid hex color!\"\n );\n return;\n }\n try {\n fcc.start();\n } catch (IOException e) {\n System.out.println(\"Failed to write output file!\");\n }\n }\n\n public void start() throws IOException {\n int r;\n int b;\n int g;\n OutputStreamWriter out;\n\n out = new OutputStreamWriter(\n new FileOutputStream(\"chosen-font-colors.html\"),\n \"UTF-8\"\n );\n\n // simple, not W3C comform (most browsers won't care), HTML header\n out.write(\"<html><head><title>\\n\");\n out.write(\"</title><style type=\\\"text/css\\\">\\n\");\n out.write(\"body { background-color:#\");\n out.write(rgb2hex(bred, bgreen, bblue));\n out.write(\"; }\\n</style></head>\\n<body>\\n\");\n\n // try 4096 colors\n for (r = 0; r <= 15; r++) {\n for (g = 0; g <= 15; g++) {\n for (b = 0; b <= 15; b++) {\n int red;\n int blue;\n int green;\n double cDiff;\n\n // brightness increasse like this: 00, 11,22, ..., ff\n red = (r << 4) | r;\n blue = (b << 4) | b;\n green = (g << 4) | g;\n\n cDiff = contrastDiff(\n red, green, blue,\n bred, bgreen, bblue\n );\n if (cDiff < 5.0) continue;\n writeDiv(red, green, blue, out);\n }\n }\n }\n\n // finalize HTML document\n out.write(\"</body></html>\");\n\n out.close();\n }\n\n private void writeDiv(int r, int g, int b, OutputStreamWriter out)\n throws IOException\n {\n String hex;\n\n hex = rgb2hex(r, g, b);\n out.write(\"<div style=\\\"color:#\" + hex + \"\\\">\");\n out.write(\"This is a sample text for color \" + hex + \"</div>\\n\");\n }\n\n private double contrastDiff(\n int r1, int g1, int b1, int r2, int g2, int b2\n ) {\n double l1;\n double l2;\n\n l1 = ( \n 0.2126 * Math.pow((double)r1/255.0, 2.2) +\n 0.7152 * Math.pow((double)g1/255.0, 2.2) +\n 0.0722 * Math.pow((double)b1/255.0, 2.2) +\n 0.05\n );\n l2 = ( \n 0.2126 * Math.pow((double)r2/255.0, 2.2) +\n 0.7152 * Math.pow((double)g2/255.0, 2.2) +\n 0.0722 * Math.pow((double)b2/255.0, 2.2) +\n 0.05\n );\n\n return (l1 > l2) ? (l1 / l2) : (l2 / l1);\n }\n\n private String rgb2hex(int r, int g, int b) {\n String rs = Integer.toHexString(r);\n String gs = Integer.toHexString(g);\n String bs = Integer.toHexString(b);\n if (rs.length() == 1) rs = \"0\" + rs;\n if (gs.length() == 1) gs = \"0\" + gs;\n if (bs.length() == 1) bs = \"0\" + bs;\n return (rs + gs + bs);\n }\n}\n"
},
{
"answer_id": 34714330,
"author": "FlΓ‘vio Batista",
"author_id": 4282643,
"author_profile": "https://Stackoverflow.com/users/4282643",
"pm_score": 2,
"selected": false,
"text": "r = 127-(r-127) and so on.\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301869",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15809/"
] |
301,882 | <p>Thats what I am using to read e-mail using C#:</p>
<pre><code>outLookApp.NewMailEx += new ApplicationEvents_11_NewMailExEventHandler(outLookApp_NewMailEx);
Outlook.NameSpace olNameSpace = outLookApp.GetNamespace("mapi");
olNameSpace.Logon("xxxx", "xxxxx", false, true);
Outlook.MAPIFolder oInbox = olNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
Outlook.Items oItems = oInbox.Items;
MessageBox.Show("Total : " + oItems.Count); //Total Itemin inbox
oItems = oItems.Restrict("[Unread] = true");
MessageBox.Show("Total Unread : " + oItems.Count); //Unread Items
Outlook.MailItem oMsg;
Outlook.Attachment mailAttachement;
for (int i = 0; i < oItems.Count; i++)
{
oMsg = (Outlook.MailItem)oItems.GetFirst();
MessageBox.Show(i.ToString());
MessageBox.Show(oMsg.SenderName);
MessageBox.Show(oMsg.Subject);
MessageBox.Show(oMsg.ReceivedTime.ToString());
MessageBox.Show(oMsg.Body);
</code></pre>
<p>The problem that I am facing is this application only works if the Outlook is open on the machine. If Outlook is closed it throws an exception:</p>
<blockquote>
<p>The server is not available. Contact your administrator if this condition persists.</p>
</blockquote>
<p>Is there anyway I can read e-mail with Outlook open?</p>
| [
{
"answer_id": 22501981,
"author": "theAlse",
"author_id": 576671,
"author_profile": "https://Stackoverflow.com/users/576671",
"pm_score": 1,
"selected": false,
"text": "using Outlook = Microsoft.Office.Interop.Outlook;\n\n// Create the Outlook application.\nOutlook.Application oApp = null;\n\n// Check whether there is an Outlook process running.\nint outlookRunning = Process.GetProcessesByName(\"OUTLOOK\").Length;\nif (outlookRunning > 0)\n{\n // If so, use the GetActiveObject method to obtain the process and cast it to an Application object.\n try\n {\n oApp = Marshal.GetActiveObject(\"Outlook.Application\") as Outlook.Application;\n }\n catch (Exception)\n {\n oApp = Activator.CreateInstance(Type.GetTypeFromProgID(\"Outlook.Application\")) as Outlook.Application;\n }\n finally\n {\n // At this point we must kill Outlook (since outlook was started by user on a higher prio level than this current application)\n // kill Outlook (otherwise it will only work if UAC is disabled)\n // this is really a kind of last resort\n Process[] workers = Process.GetProcessesByName(\"OUTLOOk\");\n foreach (Process worker in workers)\n {\n worker.Kill();\n worker.WaitForExit();\n worker.Dispose();\n }\n }\n}\nelse\n{\n // If not, create a new instance of Outlook and log on to the default profile.\n oApp = new Outlook.Application();\n Outlook.NameSpace nameSpace = oApp.GetNamespace(\"MAPI\");\n try\n {\n // use default profile and DO NOT pop up a window\n // on some pc bill gates fails to login without the popup, then we must pop up and lets use choose profile and allow access\n nameSpace.Logon(\"\", \"\", false, Missing.Value);\n }\n catch (Exception)\n {\n // use default profile and DO pop up a window\n nameSpace.Logon(\"\", \"\", true, true);\n }\n nameSpace = null;\n}\n\n// Done, now you can do what ever you want with the oApp, like creating a message and send it\n// Create a new mail item.\nOutlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301882",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
301,922 | <p>"Fatal error: Allowed memory size of 31457280 bytes exhausted (tried to allocate 9828 bytes)".</p>
<p>This is the error i get but I am only trying to upload a 1mb image. I have increased the memory limit in php.ini and the execution time. I am trying this on a local MAMP server, on a Mac using firefox. This going to be for an online image gallery.
Any ideas?
Below is the code:</p>
<pre><code> ini_set("memory_limit","30M");
if(isset($_POST['submit'])){
if (isset ($_FILES['new_image'])){
$imagename = $_FILES['new_image']['name'];
$source = $_FILES['new_image']['tmp_name'];
$target = "images/".$imagename;
move_uploaded_file($source, $target);
$imagepath = $imagename;
//below here for the removed code
$save = "thumbs/uploads/" . $imagepath; //This is the new file you saving
$file = "images/" . $imagepath; //This is the original file
$imagesize = getimagesize($file);
list($width, $height) = $imagesize;
unset($imagesize);
if($width>$height)
{
$modwidth = 150;
$diff = $width / $modwidth;
$modheight = $height / $diff;
}else{
$modheight = 150;
$diff = $height / $modheight;
$modwidth = $width / $diff;
}
$tn = imagecreatetruecolor($modwidth, $modheight);
$image = imagecreatefromjpeg($file);
$imagecopy = imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height);
imagedestroy($image);
imagedestroy($im);
imagedestroy($imagecopy);
imagedestroy($source);
$imagejpg = imagejpeg($tn, $save, 100);
imagedestroy($tn);
imagedestroy($imagejpg);
</code></pre>
<hr>
<p>EDIT</p>
<p>This has now been sorted out hopefully. One of my colleagues had a solution all along but neglected to tell me!</p>
| [
{
"answer_id": 302209,
"author": "Ciaran McNulty",
"author_id": 34024,
"author_profile": "https://Stackoverflow.com/users/34024",
"pm_score": 2,
"selected": false,
"text": "anytopnm <file> | pnmscale -xysize <dimensions> | pnmtojpg > <outfile> \n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301922",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31677/"
] |
301,924 | <p>I'm trying to test the functionality of a web app by scripting a login sequence in Python, but I'm having some troubles.</p>
<p>Here's what I need to do:</p>
<ol>
<li>Do a POST with a few parameters and headers.</li>
<li>Follow a redirect</li>
<li>Retrieve the HTML body.</li>
</ol>
<p>Now, I'm relatively new to python, but the two things I've tested so far haven't worked. First I used httplib, with putrequest() (passing the parameters within the URL), and putheader(). This didn't seem to follow the redirects.</p>
<p>Then I tried urllib and urllib2, passing both headers and parameters as dicts. This seems to return the login page, instead of the page I'm trying to login to, I guess it's because of lack of cookies or something.</p>
<p>Am I missing something simple?</p>
<p>Thanks.</p>
| [
{
"answer_id": 301987,
"author": "gimel",
"author_id": 6491,
"author_profile": "https://Stackoverflow.com/users/6491",
"pm_score": 3,
"selected": false,
"text": "Python from twill import get_browser\nb = get_browser()\n\nb.go(\"http://www.python.org/\")\nb.showforms()\n"
},
{
"answer_id": 302099,
"author": "S.Lott",
"author_id": 10661,
"author_profile": "https://Stackoverflow.com/users/10661",
"pm_score": 6,
"selected": true,
"text": "urllib2 httplib urllib2 HTTPRedirectHandler HTTPRedirectHandler cookie_handler= urllib2.HTTPCookieProcessor( self.cookies )\nredirect_handler= HTTPRedirectHandler()\nopener = urllib2.build_opener(redirect_handler,cookie_handler)\n opener HTTPHandler"
},
{
"answer_id": 302184,
"author": "Eli Courtwright",
"author_id": 1694,
"author_profile": "https://Stackoverflow.com/users/1694",
"pm_score": 4,
"selected": false,
"text": "from urllib import urlencode\nfrom urllib2 import urlopen, Request\n\n# encode my POST parameters for the login page\nlogin_qs = urlencode( [(\"username\",USERNAME), (\"password\",PASSWORD)] )\n\n# extract my session id by loading a page from the site\nset_cookie = urlopen(URL_BASE).headers.getheader(\"Set-Cookie\")\nsess_id = set_cookie[set_cookie.index(\"=\")+1:set_cookie.index(\";\")]\n\n# construct headers dictionary using the session id\nheaders = {\"Cookie\": \"session_id=\"+sess_id}\n\n# perform login and make sure it worked\nif \"Announcements:\" not in urlopen(Request(URL_BASE+\"login\",headers=headers), login_qs).read():\n print \"Didn't log in properly\"\n exit(1)\n\n# here's the function I used after this for loading pages\ndef download(page=\"\"):\n return urlopen(Request(URL_BASE+page, headers=headers)).read()\n\n# for example:\nprint download(URL_BASE + \"config\")\n"
},
{
"answer_id": 302205,
"author": "Ace",
"author_id": 18673,
"author_profile": "https://Stackoverflow.com/users/18673",
"pm_score": 4,
"selected": false,
"text": "data = urllib.urlencode(params)\nurl = host+page\nrequest = urllib2.Request(url, data, headers)\nresponse = urllib2.urlopen(request)\n\ncookies = CookieJar()\ncookies.extract_cookies(response,request)\n\ncookie_handler= urllib2.HTTPCookieProcessor( cookies )\nredirect_handler= HTTPRedirectHandler()\nopener = urllib2.build_opener(redirect_handler,cookie_handler)\n\nresponse = opener.open(request)\n"
},
{
"answer_id": 4836113,
"author": "Jason Pepas",
"author_id": 558735,
"author_profile": "https://Stackoverflow.com/users/558735",
"pm_score": 4,
"selected": false,
"text": "#!/usr/bin/env python\n\nimport urllib\nimport urllib2\n\n\nclass HttpBot:\n \"\"\"an HttpBot represents one browser session, with cookies.\"\"\"\n def __init__(self):\n cookie_handler= urllib2.HTTPCookieProcessor()\n redirect_handler= urllib2.HTTPRedirectHandler()\n self._opener = urllib2.build_opener(redirect_handler, cookie_handler)\n\n def GET(self, url):\n return self._opener.open(url).read()\n\n def POST(self, url, parameters):\n return self._opener.open(url, urllib.urlencode(parameters)).read()\n\n\nif __name__ == \"__main__\":\n bot = HttpBot()\n ignored_html = bot.POST('https://example.com/authenticator', {'passwd':'foo'})\n print bot.GET('https://example.com/interesting/content')\n ignored_html = bot.POST('https://example.com/deauthenticator',{})\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301924",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18673/"
] |
301,937 | <p>I have the following table in MySQL (version 5):</p>
<pre><code>id int(10) UNSIGNED No auto_increment
year varchar(4) latin1_swedish_ci No
title varchar(250) latin1_swedish_ci Yes NULL
body text latin1_swedish_ci Yes NULL
</code></pre>
<p>And I want the db to auto add the current year on insert, I've tried the following SQL statement:</p>
<pre><code>ALTER TABLE `tips` CHANGE `year` `year` VARCHAR(4) NOT NULL DEFAULT year(now())
</code></pre>
<p>But it gives the following error:</p>
<pre><code>1067 - Invalid default value for 'year'
</code></pre>
<p>What can I do to get this functionality? Thanks in advance!</p>
| [
{
"answer_id": 301944,
"author": "Noah Goodrich",
"author_id": 20178,
"author_profile": "https://Stackoverflow.com/users/20178",
"pm_score": 3,
"selected": false,
"text": "ALTER TABLE tips MODIFY COLUMN year YEAR(4) NOT NULL DEFAULT CURRENT_TIMESTAMP\n CREATE TRIGGER example_trigger AFTER INSERT ON tips\nFOR EACH ROW BEGIN\nUPDATE tips SET year = YEAR(NOW()) WHERE tip_id = NEW.tip_id\nEND;\n"
},
{
"answer_id": 301955,
"author": "Powerlord",
"author_id": 15880,
"author_profile": "https://Stackoverflow.com/users/15880",
"pm_score": 5,
"selected": true,
"text": "CREATE TRIGGER ins_year\nBEFORE INSERT ON tips\n FOR EACH ROW SET NEW.year = YEAR(NOW());\n"
},
{
"answer_id": 64432114,
"author": "John C",
"author_id": 3117194,
"author_profile": "https://Stackoverflow.com/users/3117194",
"pm_score": 3,
"selected": false,
"text": "YEAR 10 2010 ALTER TABLE `tips`\n CHANGE `year` `year` YEAR NOT NULL DEFAULT (YEAR(CURDATE()));\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301937",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
301,959 | <p>I have an abstract base class called Shape from which both Circle and Rectangle are derived, but when I execute the following code in VS 2005 I get the error Debug assertion failed. At the same time I have not overloaded == operator in any class</p>
<p>Expression:Vector iterator not dereferencable, what is the reason for this.</p>
<pre><code> vector<Shape*> s1;
s1.push_back(new Circle(point(1,2),3));
s1.push_back(new Circle(point(4,3),5));
s1.push_back(new Rectangle(point(1,1),4,5));
vector<Shape*> s2(s1);
reverse(s1.begin(),s1.end());
(*find(s1.begin(),s1.end(),new Circle(point(1,2),3)))->move(point(10,20));
</code></pre>
| [
{
"answer_id": 302057,
"author": "xtofl",
"author_id": 6610,
"author_profile": "https://Stackoverflow.com/users/6610",
"pm_score": 3,
"selected": false,
"text": "new Circle(point(1,2),3) find_if class Shape {\npublic:\n //amongst other functions\n virtual bool equal( const Shape* ) const = 0;\n};\n\nclass Circle : public Shape {\npublic:\n bool equal( const Shape* pOther ) const {\n const Circle* pOtherCircle = dynamic_cast<const Circle*>( pOther );\n if( pOtherCircle == NULL ) return false;\n // compare circle members\n }\n};\n\nclass Rectangle : public Shape {\npublic:\n bool equal( const Shape* pOther ) const {\n const Rectangle* pOtherR = dynamic_cast<const Rectangle*>( pOther );\n if( pOtherR == NULL ) return false;\n // compare rectangle members\n }\n};\n\n\n\nShape* pFindThis = new Circle(point(1,2),3);\nvector<Shape*>::const_iterator itFound = find_if(s1.begin(),s1.end(), \n bind1st( mem_fun( &Shape::equal ), pFindThis) ) );\ndelete pFindThis; //leak resolved by Mark Ransom - tx!\n\nif( itFound != s1.end() ) {\n (*itFound)->move(point(10,20));\n}\n"
},
{
"answer_id": 303143,
"author": "Martin York",
"author_id": 14065,
"author_profile": "https://Stackoverflow.com/users/14065",
"pm_score": 2,
"selected": false,
"text": "#include <boost/ptr_container/ptr_vector.hpp>\n#include <iostream>\n\nclass Shape\n{\n public:\n ~Shape() {}\n bool operator==(Shape const& rhs) const\n {\n if (typeid(*this) != typeid(rhs))\n {\n return false;\n }\n\n return this->isEqual(rhs);\n }\n private:\n virtual bool isEqual(Shape const& rhs) const = 0;\n};\n\nclass Circle: public Shape\n{\n public:\n Circle(int r)\n :radius(r)\n {}\n private:\n virtual bool isEqual(Shape const& r) const\n {\n Circle const& rhs = dynamic_cast<Circle const&>(r);\n return radius == rhs.radius;\n }\n int radius;\n};\nclass Rectangle: public Shape\n{\n public:\n Rectangle(int h,int w)\n :height(h)\n ,width(w)\n {}\n private:\n virtual bool isEqual(Shape const& r) const\n {\n Rectangle const& rhs = dynamic_cast<Rectangle const&>(r);\n return (height == rhs.height) && (width == rhs.width);\n }\n int height;\n int width;\n};\n\n\nint main()\n{\n\n boost::ptr_vector<Shape> data;\n\n data.push_back(new Circle(5));\n data.push_back(new Circle(6));\n data.push_back(new Rectangle(7,4));\n\n boost::ptr_vector<Shape>::iterator f;\n f = find(data.begin(),data.end(),Circle(6));\n\n std::cout << \"Find(\" << (f - data.begin() ) << \")\" << std::endl;\n\n\n}\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301959",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7965/"
] |
301,965 | <p>This is my first crack at a method that is run periodically during the lifetime of my ASP.NET application to clean up expired sessions stored in my database. It seems to work pretty well, but the software engineer in me doesn't feel "right" about this code. I've been working with LINQ to SQL for a few months now, but I'm not very confident in the following code. I'm worried about a few things:</p>
<ol>
<li><p>Is the following code safe to run in a situation where the database is being accessed by different threads in my application? I have a decent understanding of the idea of transactions, but I want to make sure I'm using them properly.</p></li>
<li><p>Is my query going to cause performance issues? Or is it appropriate in this case to select all of the records in this particular table? This method only runs every 15 minutes, so it's not like that query will be made over and over again in a short period of time.</p></li>
<li><p>Is there a better way that I could do this? I have a nagging feeling that there is.</p></li>
</ol>
<p>Code:</p>
<pre><code>/// <summary>
/// Method, run periodically, to remove all sign in records that correspond to expired sessions.
/// </summary>
/// <param name="connectionString">Database connection string</param>
/// <returns>Number of expired sign in records removed</returns>
public static int Clean(String connectionString)
{
MyDatabaseDataContext db = new MyDatabaseDataContext(connectionString);
var signIns = db.SignIns.Select(x => x);
int removeCount = 0;
using (TransactionScope scope = new TransactionScope())
{
foreach (SignIn signIn in signIns)
{
DateTime currentTime = DateTime.Now;
TimeSpan span = currentTime.Subtract(signIn.LastActivityTime);
if (span.Minutes > 10)
{
db.SignIns.DeleteOnSubmit(signIn);
++removeCount;
}
}
db.SubmitChanges();
scope.Complete();
}
return removeCount;
}
</code></pre>
| [
{
"answer_id": 302023,
"author": "Coderer",
"author_id": 26286,
"author_profile": "https://Stackoverflow.com/users/26286",
"pm_score": 4,
"selected": true,
"text": " DELETE * FROM tblSignIns \n WHERE LastActivityTime < DATEADD(\"minute\", -10, GETDATE());\n"
},
{
"answer_id": 302028,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 2,
"selected": false,
"text": "TimeSpan.Minutes TimeSpan.TotalMinutes"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301965",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18505/"
] |
301,968 | <p>I heard that Visual Studio came with an Image Library, but I can't find it anywhere. Does anyone know where it is?</p>
| [
{
"answer_id": 60420692,
"author": "greg",
"author_id": 5266970,
"author_profile": "https://Stackoverflow.com/users/5266970",
"pm_score": 3,
"selected": false,
"text": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\Common7\\IDE\\Assets"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301968",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1204/"
] |
301,983 | <p>I am working on a project that I want to implement AJAX, and I have decided on jQuery as a JavaScript Library. Here is the HTML:</p>
<pre><code><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>jQuery AJAX</title>
<!--<script language="javascript" type="text/javascript" src="inc/scripts.js"></script>-->
<script language="javascript" type="text/javascript" src="inc/jquery-1.2.6-intellisense.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function(){
$("#clicker").click(function () {
$.ajax({
type: "POST",
url: "test.aspx/randomString",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
$("#result").append(msg.d);
}
});
});
});
</script>
</head>
<body runat="server">
<form id="form1" runat="server">
<div id="result" runat="server" style="margin-bottom:5em;"></div>
<div id="clicker" runat="server" style="cursor:pointer;">Click Here to Refresh</div>
</form>
</body>
</html>
</code></pre>
<p>And here is the back-end on <strong><code>test.aspx</code></strong>:</p>
<pre><code><WebMethod()> _
Public Shared Function randomString() As String
Dim KeyGen As RandomKeyGenerator
Dim NumKeys As Integer
Dim i_Keys As Integer
Dim RandomKey As String
Dim oRet As New StringBuilder
NumKeys = 20
KeyGen = New RandomKeyGenerator
KeyGen.KeyLetters = "abcdefghijklmnopqrstuvwxyz"
KeyGen.KeyNumbers = "0123456789"
KeyGen.KeyChars = 12
For i_Keys = 1 To NumKeys
RandomKey = KeyGen.Generate()
oRet.AppendLine(String.Format("{0}{1}", RandomKey, ControlChars.NewLine))
Next
Return oRet.ToString
End Function
</code></pre>
<p>I have tried <strong><code>$("#result).text(msg.d)</code></strong> as well as forming a list, <strong><code>String.Format("<li>{0}</li>",RandomKey)</code></strong>, and adding a break tag <strong><code>String.Format("{0}<br />",RandomKey)</code></strong>. </p>
<p>When I run the page it returns as one line, all HTML is shown. What do I need to do to make it render the HTML?</p>
<p>I got the information on how to call a page without a ScriptManager from <a href="http://encosia.com/2008/05/29/using-jquery-to-directly-call-aspnet-ajax-page-methods/" rel="nofollow noreferrer">this site</a>.</p>
| [
{
"answer_id": 302044,
"author": "Dave Ward",
"author_id": 60,
"author_profile": "https://Stackoverflow.com/users/60",
"pm_score": 3,
"selected": true,
"text": "$(\"#result\").html(msg.d)\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301983",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25515/"
] |
301,991 | <p>Inspired by the question <a href="https://stackoverflow.com/questions/301546/whats-the-simplest-way-to-call-http-get-url-using-delphi">Whatβs the simplest way to call Http GET url using Delphi?</a>
I really would like to see a sample of how to use POST. Preferably to receive XML from the call.</p>
<p>Added: What about including an image or other file in the post data?</p>
| [
{
"answer_id": 302061,
"author": "Bruce McGee",
"author_id": 19183,
"author_profile": "https://Stackoverflow.com/users/19183",
"pm_score": 7,
"selected": true,
"text": "function PostExample: string;\nvar\n lHTTP: TIdHTTP;\n lParamList: TStringList;\nbegin\n lParamList := TStringList.Create;\n lParamList.Add('id=1');\n\n lHTTP := TIdHTTP.Create;\n try\n Result := lHTTP.Post('http://blahblahblah...', lParamList);\n finally\n lHTTP.Free;\n lParamList.Free;\n end;\nend;\n"
},
{
"answer_id": 302925,
"author": "skamradt",
"author_id": 9217,
"author_profile": "https://Stackoverflow.com/users/9217",
"pm_score": 3,
"selected": false,
"text": "function HttpPostURL(const URL, URLData: string; const Data: TStream): Boolean;\n"
},
{
"answer_id": 967018,
"author": "Conor Boyd",
"author_id": 91872,
"author_profile": "https://Stackoverflow.com/users/91872",
"pm_score": 4,
"selected": false,
"text": "procedure AddImage(const AlbumID: Integer; const Image: TStream; const ImageFilename, Caption, Description, Summary: String);\nvar\n Response: String;\n HTTPClient: TidHTTP;\n ImageStream: TIdMultipartFormDataStream;\nbegin\n\n HTTPClient := TidHTTP.Create;\n\n try\n ImageStream := TIdMultiPartFormDataStream.Create;\n try\n ImageStream.AddFormField('g2_form[cmd]', 'add-item');\n ImageStream.AddFormField('g2_form[set_albumId]', Format('%d', [AlbumID]));\n ImageStream.AddFormField('g2_form[caption]', Caption);\n ImageStream.AddFormField('g2_form[force_filename]', ImageFilename);\n ImageStream.AddFormField('g2_form[extrafield.Summary]', Summary);\n ImageStream.AddFormField('g2_form[extrafield.Description]', Description);\n\n ImageStream.AddObject('g2_userfile', 'image/jpeg', Image, ImageFilename);\n\n Response := HTTPClient.Post('http://mygallery.com/main.php?g2_controller=remote:GalleryRemote', ImageStream);\n finally\n ImageStream.Free;\n end;\n finally\n HTTPClient.Free;\n end;\nend;\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301991",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13219/"
] |
301,999 | <p>What's the best way to move a document from one doc library to another? I don't care about version history or preserving CreatedBy and ModifiedBy metadata...</p>
<pre><code>SPList lib1 = (SPDocumentLibrary) web.Lists["lib1"];
SPList lib2 = (SPDocumentLibrary) web.Lists["lib2"];
SPItem item1 = lib1.Items[0];
//insert code to move item1 to lib2
</code></pre>
<p>I'm currently looking at <code>SPItem.MoveTo()</code> but wonder if anyone already solved this problem and has some advice.<br>
Thanks in advance.</p>
| [
{
"answer_id": 302117,
"author": "vitule",
"author_id": 1287,
"author_profile": "https://Stackoverflow.com/users/1287",
"pm_score": 4,
"selected": true,
"text": "SPList lib1 = (SPDocumentLibrary) web.Lists[\"lib1\"];\nSPList lib2 = (SPDocumentLibrary) web.Lists[\"lib2\"];\nSPListItem item1 = lib1.Items[0];\nbyte[] fileBytes = item1.File.OpenBinary();\nstring destUrl = lib2.RootFolder.Url + \"/\" + item1.File.Name;\nSPFile destFile = lib2.RootFolder.Files.Add(destUrl, fileBytes, true /*overwrite*/);\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/301999",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1287/"
] |
302,017 | <p>Is there a way to browse and edit/delete saved form entries in Firefox?</p>
<p>I know I can:</p>
<ul>
<li>Delete all form data, using the <em>Clear Private Data</em> dialog;</li>
<li><a href="http://kb.mozillazine.org/Deleting_autocomplete_entries" rel="nofollow noreferrer">Delete specific entries</a> in a form using shift-delete when the cursor is over them (*).</li>
</ul>
<p>I want is way to see all saved entries for a specific keyword, edit them, and easily delete all or selectively.</p>
<p>I expected to find a plugin that does it, but I couldn't find any. Or is there an external tool that manipulates the <em>formhistory.sqlite</em> file?</p>
<p>(*) For those of you that don't know this: go to your favorite search engine's search box, and press the down key to see the history. <kbd>Shift</kbd> + <kbd>Delete</kbd> will delete the "current" entry from saved form data.</p>
| [
{
"answer_id": 302040,
"author": "Greg",
"author_id": 24181,
"author_profile": "https://Stackoverflow.com/users/24181",
"pm_score": 4,
"selected": false,
"text": "sqlite"
},
{
"answer_id": 1550680,
"author": "Cactus",
"author_id": 187963,
"author_profile": "https://Stackoverflow.com/users/187963",
"pm_score": 6,
"selected": true,
"text": "formhistory.sqlite .sqlite"
},
{
"answer_id": 8773910,
"author": "gMale",
"author_id": 178433,
"author_profile": "https://Stackoverflow.com/users/178433",
"pm_score": 2,
"selected": false,
"text": "/Users/[yourName]/Library/Application Support/Firefox/Profiles/[profileName] C:\\Documents and Settings\\[yourName]\\Application Data\\Mozilla\\Firefox\\Profiles\\[profileName]"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/302017",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/38557/"
] |
302,026 | <p><strong>For a particular segment of Java code, I'd like to measure:</strong></p>
<ul>
<li><strong>Execution time (most likely <em>thread execution time</em>)</strong></li>
<li><strong>Memory usage</strong></li>
<li><strong>CPU load (specifically attributable to the code segment)</strong></li>
</ul>
<p>I'm a relative Java novice and am not familiar with how this might be achieved. I've been referred to <a href="http://en.wikipedia.org/wiki/JMX" rel="nofollow noreferrer">JMX</a>, however I'm not sure how that might be used, and JMX looks a bit 'heavy' for what I'm looking to do.</p>
<p>Ideally I'd like some measurement class that can be told what I would like to measure, with the option of calling a <code>start()</code> method prior to a code segment and a <code>stop()</code> method after. Relevant metrics would be logged to a file I specify.</p>
<p>For example:</p>
<pre><code>import com.example.metricLogger;
metricLogger logger = new metricLogger();
logger.setLogPath(pathToLogFile);
logger.monitor(executionTime);
logger.monitor(memoryUsage);
logger.monitor(cpuLoad);
logger.start();
/* Code to be measured */
logger.stop();
</code></pre>
<p><strong>Is there any standard/common/conventional way of achieving this in Java?</strong></p>
<p>Such measurements are for one-off performance comparisons, and so I'm not looking for any in-production long-term monitoring processes.</p>
<p>I'm more than happy to be referred to tutorials or external examples and don't expect a full answer here. That said, if anything as simple as the above can be achieved a realistic example would go down really well.</p>
| [
{
"answer_id": 302077,
"author": "basszero",
"author_id": 287,
"author_profile": "https://Stackoverflow.com/users/287",
"pm_score": 5,
"selected": true,
"text": "long start = System.nanoTime(); // requires java 1.5\n// Segment to monitor\ndouble elapsedTimeInSec = (System.nanoTime() - start) * 1.0e-9;\n"
},
{
"answer_id": 57134080,
"author": "davidxxx",
"author_id": 270371,
"author_profile": "https://Stackoverflow.com/users/270371",
"pm_score": 0,
"selected": false,
"text": "OperatingSystemMXBean osBean = ManagementFactory.getPlatformMXBean(\n OperatingSystemMXBean.class); \ndouble processCpuLoad = osBean.getProcessCpuLoad();\n MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();\nint currentHeapUsedInMo = (int) (memoryMXBean.getHeapMemoryUsage().getUsed() / 1_000_000);\n import com.google.common.testing.GcFinalization;\n\nGcFinalization.awaitFullGc();\nfoo.execute(); // method to execute\n GcFinalization"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/302026",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5343/"
] |
302,047 | <p>In VB.NET, what is the difference between <code>And</code> and <code>AndAlso</code>? Which should I use?</p>
| [
{
"answer_id": 302067,
"author": "Nico",
"author_id": 22970,
"author_profile": "https://Stackoverflow.com/users/22970",
"pm_score": 10,
"selected": true,
"text": "And AndAlso If mystring IsNot Nothing And mystring.Contains(\"Foo\") Then\n ' bla bla\nEnd If\n mystring = Nothing If mystring IsNot Nothing AndAlso mystring.Contains(\"Foo\") Then\n ' bla bla\nEnd If\n AndAlso &&"
},
{
"answer_id": 302070,
"author": "Bryan Anderson",
"author_id": 21186,
"author_profile": "https://Stackoverflow.com/users/21186",
"pm_score": 4,
"selected": false,
"text": "If Bool1 And Bool2 Then\n If Bool1 AndAlso Bool2 Then\n"
},
{
"answer_id": 302080,
"author": "Ed Marty",
"author_id": 36007,
"author_profile": "https://Stackoverflow.com/users/36007",
"pm_score": 5,
"selected": false,
"text": "And if x = 5 And y = 7\n if x = 5 AndAlso y = 7\n If Not Object Is Nothing AndAlso Object.Load()\n And AndAlso Object.Load() nothing"
},
{
"answer_id": 302081,
"author": "Tor Haugen",
"author_id": 32050,
"author_profile": "https://Stackoverflow.com/users/32050",
"pm_score": 3,
"selected": false,
"text": "If Not IsNull(myObj) AndAlso myObj.SomeProperty = 3 Then\n ...\nEnd If\n"
},
{
"answer_id": 302135,
"author": "Joel Coehoorn",
"author_id": 3043,
"author_profile": "https://Stackoverflow.com/users/3043",
"pm_score": 3,
"selected": false,
"text": "And"
},
{
"answer_id": 4811404,
"author": "Ian",
"author_id": 545430,
"author_profile": "https://Stackoverflow.com/users/545430",
"pm_score": 4,
"selected": false,
"text": "While File1.Seek_Next_Row() And File2.Seek_Next_Row()\n Str1 = File1.GetRow()\n Str2 = File2.GetRow()\nEnd While\n And AndAlso File1 File2"
},
{
"answer_id": 8503147,
"author": "rbrill",
"author_id": 1097609,
"author_profile": "https://Stackoverflow.com/users/1097609",
"pm_score": 3,
"selected": false,
"text": "If Bool1 And Bool2 Then\nIf [both are true] Then\n\n\nIf Bool1 AndAlso Bool2 Then\nIf [first is true then evaluate the second] Then\n"
},
{
"answer_id": 27111323,
"author": "Charles Jacks",
"author_id": 4288533,
"author_profile": "https://Stackoverflow.com/users/4288533",
"pm_score": 5,
"selected": false,
"text": "And Or OrElse AndAlso Dim a = 3 OR 5 ' Will set a to the value 7, 011 or 101 = 111\nDim a = 3 And 5 ' Will set a to the value 1, 011 and 101 = 001\nDim b = 3 OrElse 5 ' Will set b to the value true and not evaluate the 5\nDim b = 3 AndAlso 5 ' Will set b to the value true after evaluating the 5\nDim c = 0 AndAlso 5 ' Will set c to the value false and not evaluate the 5\n true Dim e = not 0 e -1 Not || && OrElse AndAlso 3 5 v || 5 5 v null 0 v Or And OrElse AndAlso If valid(evaluation) andalso evaluation then if not (unsafe(evaluation) orelse (not evaluation)) then Dim e = Not 0 And 3\n"
},
{
"answer_id": 69665115,
"author": "UnhandledException-InvalidChar",
"author_id": 11975130,
"author_profile": "https://Stackoverflow.com/users/11975130",
"pm_score": 1,
"selected": false,
"text": "x% = y% Or 3 If x > 3 AndAlso x <= 5 Then If (x > 3) And (x <= 5) Then If x = (y And 3) AndAlso ..."
},
{
"answer_id": 72727414,
"author": "Fawlty",
"author_id": 15053619,
"author_profile": "https://Stackoverflow.com/users/15053619",
"pm_score": 0,
"selected": false,
"text": "And AndAlso Or OrElse DoSomethingWihtAandB A B False Dim A,B,C,D As Object\nIf DoSomethingWithAandB(A,B)=True And A=1 And B=2 Then C=3\n DoSomethingWithAandB False And A B Nothing Dim A,B,C,D As Object\nIf DoSomethingWithAandB(A,B)=True AndAlso A=1 AndAlso B=2 Then C=3\n DoSomethingWithAandB False DoSomethingWithAandB(A,B)=True False AndAlso OrElse True"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/302047",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34588/"
] |
302,064 | <p>I want to allow only users with a 3G phone to use a particular GPS function. How do I run a check on the device before allowing that feature to be used?</p>
| [
{
"answer_id": 303606,
"author": "wisequark",
"author_id": 33159,
"author_profile": "https://Stackoverflow.com/users/33159",
"pm_score": 2,
"selected": false,
"text": "- (NSString *)deviceModel\n{\n NSString *deviceModel = nil;\n char buffer[32];\n size_t length = sizeof(buffer);\n if (sysctlbyname(\"hw.machine\", &buffer, &length, NULL, 0) == 0) {\n deviceModel = [[NSString alloc] initWithCString:buffer encoding:NSASCIIStringEncoding];\n }\n return [deviceModel autorelease];\n}\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/302064",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/38953/"
] |
302,082 | <p>I'm using a SqlDataSource to populate my GridView, because the two seem to be so tightly coupled together. Since this grid shows results of a search, I have a dynamic sql string being written in my codebehind that references parameters I pass in, such as below:</p>
<pre><code>sdsResults.SelectParameters.Add("CodeID", TypeCode.String, strCodeID)
</code></pre>
<p>My problem is that the CodeID field is a varchar field. As you may have experienced, passing in an nvarchar field to be evaluated against a varchar field can be very detrimental to sql performance. However, SelectParameters.Add only takes in TypeCode types, which seems to only give me the unicode TypeCode.String as my viable option.</p>
<p>How do I force my SqlDataSource to use varchars? I can't change the datatype at this point--it's a main key of a large 10 year old app, and frankly, varchar is right for the application. </p>
| [
{
"answer_id": 406975,
"author": "Coentje",
"author_id": 41424,
"author_profile": "https://Stackoverflow.com/users/41424",
"pm_score": 0,
"selected": false,
"text": "using System.Data;\n\nsdsResults.SelectParameters.Add(\"CodeID\", SqlDbType.VarChar, strCodeID);\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/302082",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
302,086 | <p>I have a lengthy user-interface operation on my form which is triggered whenever an event is fired. Rather than have the UI block while the operation takes place, I'd like to perform the operation in another thread, and abort that thread and start again if the event fires again.</p>
<p>However, to safely alter controls on my form, I need to use the form's Invoke or BeginInvoke methods. If I do that, then I could put all my UI operations in one function like this:</p>
<pre><code>private delegate void DoUIStuffDelegate(Thing1 arg1, Thing2 arg2);
private void doUIStuff(Thing1 arg1, Thing2 arg2)
{
control1.Visible = false;
this.Controls.Add(arg1.ToButton());
...
control100.Text = arg2.ToString();
}
...
private void backgroundThread()
{
Thing1 arg1 = new Thing1();
Thing2 arg2 = new Thing2();
this.Invoke(new DoUIStuffDelegate(doUIStuff), arg1, arg2);
}
Thread uiStuffThread = null;
public void OnEventFired()
{
if (uiStuffThread != null)
uiStuffThread.Abort();
uiStuffThread = new Thread(backgroundThread);
uiStuffThread.Start();
}
</code></pre>
<p>but if I do that, then I lose the benefit of working in a separate thread. Alternatively, I could put them each in their own function like this:</p>
<pre><code>private delegate void DoUIStuffLine1Delegate();
private delegate void DoUIStuffLine2Delegate(Thing1 arg1);
...
private delegate void DoUIStuffLine100Delegate(Thing2 arg2);
private void doUIStuffLine1()
{
control1.Visible = false;
}
private void doUIStuffLine2()
{
this.Controls.Add(arg1.ToButton());
}
...
private void doUIStuffLine100(Thing2 arg2)
{
control100.Text = arg2.ToString();
}
...
private void backgroundThread()
{
Thing1 arg1 = new Thing1();
Thing2 arg2 = new Thing2();
this.Invoke(new DoUIStuffLine1Delegate(doUIStuffLine1));
this.Invoke(new DoUIStuffLine2Delegate(doUIStuffLine2), arg1);
...
this.Invoke(new DoUIStuffLine100Delegate(doUIStuffLine100), arg2);
}
Thread uiStuffThread = null;
public void OnEventFired()
{
if (uiStuffThread != null)
uiStuffThread.Abort();
uiStuffThread = new Thread(backgroundThread);
uiStuffThread.Start();
}
</code></pre>
<p>but that's a horrible, unmaintainable mess. Is there a way to create a thread that can modify the user interface, and that I can abort? So that I can just do something like this:</p>
<pre><code>private void doUIStuff()
{
Thing1 arg1 = new Thing1();
Thing2 arg2 = new Thing2();
control1.Visible = false;
this.Controls.Add(arg1.ToButton());
...
control100.Text = arg2.ToString();
}
Thread uiStuffThread = null;
public void OnEventFired()
{
if (uiStuffThread != null)
uiStuffThread.Abort();
uiStuffThread = this.GetNiceThread(doUIStuff);
uiStuffThread.Start();
}
</code></pre>
<p>without having to disable cross-thread checks on my form? Ideally I'd like to be able to set some attribute on the thread or the method which individually wrapped all of the operations in delegates that then got invoked on the form's thread.</p>
| [
{
"answer_id": 302106,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 2,
"selected": false,
"text": " void worker_DoWork(object sender, DoWorkEventArgs e)\n {\n try {\n Action<Action> update = thingToDo =>\n {\n if (worker.CancellationPending) throw new SomeException();\n this.Invoke(thingToDo);\n };\n\n //...\n string tmp = \"abc\"; // long running\n update(() => this.Text = tmp);\n\n tmp = \"def\"; // long running\n update(() => textbox1.Text = tmp);\n } catch (SomeException) {\n e.Cancel = true;\n }\n }\n"
},
{
"answer_id": 303527,
"author": "netadictos",
"author_id": 31791,
"author_profile": "https://Stackoverflow.com/users/31791",
"pm_score": 0,
"selected": false,
"text": " private Thread workerThread;\n\n private AsyncOperation operation;\n\n public event EventHandler SomethingHappened;\n\n public MySynchronizedClass()\n {\n operation = AsyncOperationManager.CreateOperation(null);\n\n workerThread = new Thread(new ThreadStart(DoWork));\n\n workerThread.Start();\n }\n\n private void DoWork()\n {\n operation.Post(new SendOrPostCallback(delegate(object state)\n {\n EventHandler handler = SomethingHappened;\n\n if(handler != null)\n {\n handler(this, EventArgs.Empty);\n }\n }), null);\n\n operation.OperationCompleted();\n }\n"
},
{
"answer_id": 304733,
"author": "netadictos",
"author_id": 31791,
"author_profile": "https://Stackoverflow.com/users/31791",
"pm_score": 0,
"selected": false,
"text": "bw = new BackgroundWorkerExtended();\nbw.DoWork += (DoWorkEventHandler)work;\nbw.WorkerSupportsCancellation = true;\n//bw.WorkerReportsProgress = true;\nbw.RunWorkerCompleted += (RunWorkerCompletedEventHandler)workCompleted;\n//bw.ProgressChanged+=new ProgressChangedEventHandler(bw_ProgressChanged);\nbw.RunWorkerAsync();\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/302086",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15371/"
] |
302,087 | <p>I am designing the (G)UI of a program, and have stumbled across a problem; The program will convert a number into different units, and the layout of a unit been converted to is:</p>
<p>[Unit name (when clicked gives information)]
[Special status, if any]
[Output in textfield that can also be used for input (to convert to other units)]</p>
<p>I want the user to be able to copy an outputnumber onto the clipboard, without having to mess around with highlighting and finding the right buttons to press. So, I thought I'd make a button after the text-output field, saying something like "C" or "Copy".</p>
<p>But I was reading on <a href="http://www.joelonsoftware.com/uibook/chapters/fog0000000063.html" rel="nofollow noreferrer">joelonsoftware.com</a> yesterday, and discovered that users seem to be cursorclumsy. So what should I do?</p>
<p>I've thought about a number of different options:</p>
<ol>
<li>Click on textfield to copy to clipboard - BUT: I want to use it for input as well</li>
<li>Pressing a numeral on the keyboard to copy the respective one - BUT: There will probably be more than 10, and I need them for new input</li>
<li>Bigger Copy button, like on that actually says "Copy" - Hmm, would this work? I know that I like to use the keyboard when I can, so a solution involving it would be nice.</li>
<li>Each unit will have its own space, where everything (name, textfield etc.) fits in. What if it would copy to clipboard when clicked anywhere in that space except for on the name or textfield. - BUT: What if you miss, meaning to click below one textfield, and clicking above another?</li>
<li>But what about highlighting the unit's space as I went along? - Could still mean trouble...</li>
</ol>
<p>What do you think? I think I just might opt for #3 - Bigger copy-button..</p>
| [
{
"answer_id": 302104,
"author": "Ed Marty",
"author_id": 36007,
"author_profile": "https://Stackoverflow.com/users/36007",
"pm_score": 0,
"selected": false,
"text": "ctrl-click shift-click"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/302087",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36948/"
] |
302,096 | <p>I have a generic method with this (dummy) code (yes I'm aware IList has predicates, but my code is not using IList but some other collection, anyway this is irrelevant for the question...)</p>
<pre class="lang-cs prettyprint-override"><code> static T FindThing<T>(IList collection, int id) where T : IThing, new()
{
foreach (T thing in collection)
{
if (thing.Id == id)
return thing;
}
return null; // ERROR: Cannot convert null to type parameter 'T' because it could be a value type. Consider using 'default(T)' instead.
}
</code></pre>
<p>This gives me a build error</p>
<blockquote>
<p>"Cannot convert null to type parameter
'T' because it could be a value type.
Consider using 'default(T)' instead."</p>
</blockquote>
<p>Can I avoid this error?</p>
| [
{
"answer_id": 302111,
"author": "Ricardo Villamil",
"author_id": 19314,
"author_profile": "https://Stackoverflow.com/users/19314",
"pm_score": 7,
"selected": false,
"text": "return default(T);\n"
},
{
"answer_id": 302112,
"author": "Mitchel Sellers",
"author_id": 13279,
"author_profile": "https://Stackoverflow.com/users/13279",
"pm_score": 2,
"selected": false,
"text": "default(T) new T"
},
{
"answer_id": 302129,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 11,
"selected": true,
"text": "default default(T) null T 0 int '\\0' char T where T : class null T where T : struct null T?"
},
{
"answer_id": 302137,
"author": "BFree",
"author_id": 15861,
"author_profile": "https://Stackoverflow.com/users/15861",
"pm_score": 3,
"selected": false,
"text": " where T : class\n where T: IList\n"
},
{
"answer_id": 302138,
"author": "TheSoftwareJedi",
"author_id": 18941,
"author_profile": "https://Stackoverflow.com/users/18941",
"pm_score": 5,
"selected": false,
"text": "where T : class\n"
},
{
"answer_id": 302143,
"author": "Min",
"author_id": 14461,
"author_profile": "https://Stackoverflow.com/users/14461",
"pm_score": 4,
"selected": false,
"text": "static T FindThing<T>(IList collection, int id) where T : class, IThing, new()\n"
},
{
"answer_id": 8354727,
"author": "gdbdable",
"author_id": 451495,
"author_profile": "https://Stackoverflow.com/users/451495",
"pm_score": 3,
"selected": false,
"text": "static T? FindThing<T>(IList collection, int id) where T : struct, IThing\n{\n foreach T thing in collecion\n {\n if (thing.Id == id)\n return thing;\n }\n return null;\n}\n"
},
{
"answer_id": 11827192,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 4,
"selected": false,
"text": "return (T)(object)(employee);\n return default(T);\n"
},
{
"answer_id": 29000424,
"author": "Luke",
"author_id": 4660920,
"author_profile": "https://Stackoverflow.com/users/4660920",
"pm_score": 2,
"selected": false,
"text": "public static TEnum? ParseOptional<TEnum>(this string value) where TEnum : struct\n{\n return value == null ? (TEnum?)null : (TEnum) Enum.Parse(typeof(TEnum), value);\n}\n"
},
{
"answer_id": 32754777,
"author": "Jaydeep Shil",
"author_id": 3428626,
"author_profile": "https://Stackoverflow.com/users/3428626",
"pm_score": 4,
"selected": false,
"text": "return default(T);\n where T : class, IThing\n return null;\n"
},
{
"answer_id": 51338680,
"author": "Jeson Martajaya",
"author_id": 868532,
"author_profile": "https://Stackoverflow.com/users/868532",
"pm_score": 0,
"selected": false,
"text": "object null static object FindThing<T>(IList collection, int id)\n{\n foreach T thing in collecion\n {\n if (thing.Id == id)\n return (T) thing;\n }\n return null; // allowed now\n}\n"
},
{
"answer_id": 59736423,
"author": "LCIII",
"author_id": 1439748,
"author_profile": "https://Stackoverflow.com/users/1439748",
"pm_score": 3,
"selected": false,
"text": "return default;\n return default(T);"
},
{
"answer_id": 61104031,
"author": "Mertuarez",
"author_id": 1071165,
"author_profile": "https://Stackoverflow.com/users/1071165",
"pm_score": 2,
"selected": false,
"text": "using System;\nusing System.Collections.Generic;\n\npublic class Program\n{\n public static void Main()\n {\n Console.WriteLine(\"Hello World\");\n \n IThing x = new List<Thing>().FindThing(1);\n \n }\n\n}\n\npublic static class Ext {\n public static T FindThing<T>(this IList<T> collection, int id) where T : IThing, new()\n {\n foreach (T thing in collection)\n {\n if (thing.Id == id) return (T)thing;\n }\n \n //return null; //not work\n //return (T)null; //not work\n //return null as T; //not work\n return default(T); //work\n }\n}\n\npublic interface IThing { int Id {get; set;} }\npublic class Thing : IThing { public int Id {get;set;}}\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/302096",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6399/"
] |
302,110 | <p>I have been searching for info on this to no avail. The context of why i need this is <a href="https://stackoverflow.com/questions/271944/storing-temporary-user-files-in-aspnet-in-medium-trust">another question I asked here</a>. More specifically, does creating/updating/deleting files in App_Data cause a pool recycle?</p>
<p>If someone could provide a detailed list of what causes a recycle, that would be great.</p>
<p><strong>UPDATE</strong>: As two users already noticed I would also be happy to an answer specifying reasons for recycling the AppDomain only and not the whole pool.</p>
| [
{
"answer_id": 305966,
"author": "Christopher G. Lewis",
"author_id": 13532,
"author_profile": "https://Stackoverflow.com/users/13532",
"pm_score": 5,
"selected": false,
"text": "cscript adsutil.vbs Set w3svc/AppPools/DefaultAppPool/LogEventOnRecycle 255 \n"
},
{
"answer_id": 51993110,
"author": "Jesus is Lord",
"author_id": 569302,
"author_profile": "https://Stackoverflow.com/users/569302",
"pm_score": 0,
"selected": false,
"text": "w3wp.exe Application_Start Global.asax Faulting application name: w3wp.exe, version: 10.0.16299.15, time stamp: 0x0aeb5595\nFaulting module name: KERNELBASE.dll, version: 10.0.16299.334, time stamp: 0x6369e29f\nException code: 0xe0434352\nFault offset: 0x0000000000014008\nFaulting process id: 0x2900\nFaulting application start time: 0x01d43b16f726cbb9\nFaulting application path: c:\\windows\\system32\\inetsrv\\w3wp.exe\nFaulting module path: C:\\WINDOWS\\System32\\KERNELBASE.dll\nReport Id: 998cf55d-2cd9-4b8d-9884-2110e3fd1411\nFaulting package full name: \nFaulting package-relative application ID: \n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/302110",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1801/"
] |
302,122 | <p>With jQuery, how do I find out which key was pressed when I bind to the keypress event?</p>
<pre><code>$('#searchbox input').bind('keypress', function(e) {});
</code></pre>
<p>I want to trigger a submit when <kbd>ENTER</kbd> is pressed.</p>
<p><strong>[Update]</strong></p>
<p>Even though I found the (or better: one) answer myself, there seems to be some room for variation ;)</p>
<p>Is there a difference between <code>keyCode</code> and <code>which</code> - especially if I'm just looking for <kbd>ENTER</kbd>, which will never be a unicode key?</p>
<p>Do some browsers provide one property and others provide the other one? </p>
| [
{
"answer_id": 302140,
"author": "BlaM",
"author_id": 999,
"author_profile": "https://Stackoverflow.com/users/999",
"pm_score": 3,
"selected": false,
"text": "e.which\n"
},
{
"answer_id": 302154,
"author": "Vladimir Prudnikov",
"author_id": 29364,
"author_profile": "https://Stackoverflow.com/users/29364",
"pm_score": 7,
"selected": false,
"text": "$('#searchbox input').bind('keypress', function(e) {\n if(e.keyCode==13){\n // Enter pressed... do anything here...\n }\n});\n"
},
{
"answer_id": 302161,
"author": "Eran Galperin",
"author_id": 10585,
"author_profile": "https://Stackoverflow.com/users/10585",
"pm_score": 11,
"selected": true,
"text": " var code = e.keyCode || e.which;\n if(code == 13) { //Enter keycode\n //Do something\n }\n"
},
{
"answer_id": 302462,
"author": "user35612",
"author_id": 35612,
"author_profile": "https://Stackoverflow.com/users/35612",
"pm_score": 6,
"selected": false,
"text": "$.ui.keyCode = { \n ...\n ENTER: 13, \n ...\n};\n >>> String.charCodeAt('\\r') == 13\ntrue\n>>> String.fromCharCode(13) == '\\r'\ntrue\n"
},
{
"answer_id": 556356,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 4,
"selected": false,
"text": "$(document).ready(function(){\n $(\"#btnSubmit\").bind(\"click\",function(){$('#'+'<%=btnUpload.ClientID %>').trigger(\"click\");return false;});\n $(\"body, input, textarea\").keypress(function(e){\n if(e.which==13) $(\"#btnSubmit\").click();\n });\n});\n"
},
{
"answer_id": 2231846,
"author": "Omar Yepez",
"author_id": 269765,
"author_profile": "https://Stackoverflow.com/users/269765",
"pm_score": -1,
"selected": false,
"text": "jQuery('#myInput').keypress(function(e) {\n code = e.keyCode ? e.keyCode : e.which;\n if(code.toString() == 13) {\n alert('You pressed enter!');\n }\n});\n"
},
{
"answer_id": 2789752,
"author": "Luca Filosofi",
"author_id": 91130,
"author_profile": "https://Stackoverflow.com/users/91130",
"pm_score": 5,
"selected": false,
"text": " // in jquery source code...\n if (!event.which && ((event.charCode || event.charCode === 0) ? event.charCode : event.keyCode)) {\n event.which = event.charCode || event.keyCode;\n }\n\n // So you have just to use\n $('#searchbox input').bind('keypress', function(e) {\n if (e.which === 13) {\n alert('ENTER WAS PRESSED');\n }\n });\n"
},
{
"answer_id": 2823377,
"author": "user184365",
"author_id": 184365,
"author_profile": "https://Stackoverflow.com/users/184365",
"pm_score": 5,
"selected": false,
"text": "$('input#search').keypress(function(e) {\n if (e.which == '13') {\n e.preventDefault();\n doSomethingWith(this.value);\n }\n});\n"
},
{
"answer_id": 3293551,
"author": "user397198",
"author_id": 397198,
"author_profile": "https://Stackoverflow.com/users/397198",
"pm_score": 4,
"selected": false,
"text": "$(document).bind('keydown', 'ctrl+c', fn);\n"
},
{
"answer_id": 5718382,
"author": "Pedja",
"author_id": 715440,
"author_profile": "https://Stackoverflow.com/users/715440",
"pm_score": 2,
"selected": false,
"text": "<form>\n <input type=\"text\">\n <input type=\"submit\" style=\"display:none\">\n</form>\n"
},
{
"answer_id": 6695921,
"author": "molokoloco",
"author_id": 174449,
"author_profile": "https://Stackoverflow.com/users/174449",
"pm_score": 2,
"selected": false,
"text": "/*\nThis code is for example. In real life you have plugins like :\nhttps://code.google.com/p/jquery-utils/wiki/JqueryUtils\nhttps://github.com/jeresig/jquery.hotkeys/blob/master/jquery.hotkeys.js\nhttps://github.com/madrobby/keymaster\nhttp://dmauro.github.io/Keypress/\n\nhttp://api.jquery.com/keydown/\nhttp://api.jquery.com/keypress/\n*/\n\nvar event2key = {'97':'a', '98':'b', '99':'c', '100':'d', '101':'e', '102':'f', '103':'g', '104':'h', '105':'i', '106':'j', '107':'k', '108':'l', '109':'m', '110':'n', '111':'o', '112':'p', '113':'q', '114':'r', '115':'s', '116':'t', '117':'u', '118':'v', '119':'w', '120':'x', '121':'y', '122':'z', '37':'left', '39':'right', '38':'up', '40':'down', '13':'enter'};\n\nvar documentKeys = function(event) {\n console.log(event.type, event.which, event.keyCode);\n\n var keycode = event.which || event.keyCode; // par exemple : 112\n var myKey = event2key[keycode]; // par exemple : 'p'\n\n switch (myKey) {\n case 'a':\n $('div').css({\n left: '+=50'\n });\n break;\n case 'z':\n $('div').css({\n left: '-=50'\n });\n break;\n default:\n //console.log('keycode', keycode);\n }\n};\n\n$(document).on('keydown keyup keypress', documentKeys);\n"
},
{
"answer_id": 7414935,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "<form action=\"javascript:alert('Enter');\">\n<input type=text value=\"press enter\">\n</form>\n"
},
{
"answer_id": 8166080,
"author": "manny",
"author_id": 780941,
"author_profile": "https://Stackoverflow.com/users/780941",
"pm_score": 2,
"selected": false,
"text": "$(document).bind('keypress', function (e) {\n console.log(e.which); //or alert(e.which);\n\n});\n"
},
{
"answer_id": 8535147,
"author": "Rodolfo Jorge Nemer Nogueira",
"author_id": 1102037,
"author_profile": "https://Stackoverflow.com/users/1102037",
"pm_score": 2,
"selected": false,
"text": "$(\"#element\").keydown(function(event) {\n if (event.keyCode == 13) {\n localiza_cep(this.value);\n }\n});\n"
},
{
"answer_id": 9234052,
"author": "dzona",
"author_id": 936930,
"author_profile": "https://Stackoverflow.com/users/936930",
"pm_score": 3,
"selected": false,
"text": "e.preventDefault(); var code = (e.keyCode ? e.keyCode : e.which);\n if(code == 13) { //Enter keycode\n e.preventDefault();\n //Do something\n }\n"
},
{
"answer_id": 12863468,
"author": "Reid Evans",
"author_id": 1390339,
"author_profile": "https://Stackoverflow.com/users/1390339",
"pm_score": 2,
"selected": false,
"text": "(function ($) {\n $.prototype.enterPressed = function (fn) {\n $(this).keyup(function (e) {\n if ((e.keyCode || e.which) == 13) {\n fn();\n }\n });\n };\n}(jQuery || {}));\n\n$(\"#myInput\").enterPressed(function() {\n //do something\n});\n"
},
{
"answer_id": 14206924,
"author": "Kevin",
"author_id": 1226546,
"author_profile": "https://Stackoverflow.com/users/1226546",
"pm_score": 5,
"selected": false,
"text": "$(document).ready( function() {\n $('#searchbox input').keydown(function(e)\n {\n setTimeout(function ()\n { \n //rather than using keyup, you can use keydown to capture \n //the input as it's being typed.\n //You may need to use a timeout in order to allow the input to be updated\n }, 5);\n }); \n if(e.key == \"Enter\")\n {\n //Enter key was pressed, do stuff\n }else if(e.key == \"Spacebar\")\n {\n //Spacebar was pressed, do stuff\n }\n});\n"
},
{
"answer_id": 23540602,
"author": "Hitesh Modha",
"author_id": 3274503,
"author_profile": "https://Stackoverflow.com/users/3274503",
"pm_score": 2,
"selected": false,
"text": "$('#searchbox input').bind('keypress', function(e) {\n if(e.keyCode==13){\n\n }\n});\n"
},
{
"answer_id": 31131720,
"author": "Zach Barham",
"author_id": 2518552,
"author_profile": "https://Stackoverflow.com/users/2518552",
"pm_score": 2,
"selected": false,
"text": "keypress $(document).keydown(function(e) {\n if (getPressedKey(e) == theKeyYouWantToFireAPressEventFor /*Add 'e.ctrlKey here to only fire if the combo is CTRL+theKeyYouWantToFireAPressEventFor'*/) {\n // Your Code To Fire When You Press theKeyYouWantToFireAPressEventFor \n }\n});\n theKeyYouWantToFireAPressEventFor \"a\" \"ctrl\" 1 function getPressedKey(e){var a,s=e.keyCode||e.which,c=65,r=66,o=67,l=68,t=69,f=70,n=71,d=72,i=73,p=74,u=75,h=76,m=77,w=78,k=79,g=80,b=81,v=82,q=83,y=84,j=85,x=86,z=87,C=88,K=89,P=90,A=32,B=17,D=8,E=13,F=16,G=18,H=19,I=20,J=27,L=33,M=34,N=35,O=36,Q=37,R=38,S=40,T=45,U=46,V=91,W=92,X=93,Y=48,Z=49,$=50,_=51,ea=52,aa=53,sa=54,ca=55,ra=56,oa=57,la=96,ta=97,fa=98,na=99,da=100,ia=101,pa=102,ua=103,ha=104,ma=105,wa=106,ka=107,ga=109,ba=110,va=111,qa=112,ya=113,ja=114,xa=115,za=116,Ca=117,Ka=118,Pa=119,Aa=120,Ba=121,Da=122,Ea=123,Fa=114,Ga=145,Ha=186,Ia=187,Ja=188,La=189,Ma=190,Na=191,Oa=192,Qa=219,Ra=220,Sa=221,Ta=222;return s==Fa&&(a=\"numlock\"),s==Ga&&(a=\"scrolllock\"),s==Ha&&(a=\"semicolon\"),s==Ia&&(a=\"equals\"),s==Ja&&(a=\"comma\"),s==La&&(a=\"dash\"),s==Ma&&(a=\"period\"),s==Na&&(a=\"slash\"),s==Oa&&(a=\"grave\"),s==Qa&&(a=\"openbracket\"),s==Ra&&(a=\"backslash\"),s==Sa&&(a=\"closebracket\"),s==Ta&&(a=\"singlequote\"),s==B&&(a=\"ctrl\"),s==D&&(a=\"backspace\"),s==E&&(a=\"enter\"),s==F&&(a=\"shift\"),s==G&&(a=\"alt\"),s==H&&(a=\"pause\"),s==I&&(a=\"caps\"),s==J&&(a=\"esc\"),s==L&&(a=\"pageup\"),s==M&&(a=\"padedown\"),s==N&&(a=\"end\"),s==O&&(a=\"home\"),s==Q&&(a=\"leftarrow\"),s==R&&(a=\"uparrow\"),s==S&&(a=\"downarrow\"),s==T&&(a=\"insert\"),s==U&&(a=\"delete\"),s==V&&(a=\"winleft\"),s==W&&(a=\"winright\"),s==X&&(a=\"select\"),s==Z&&(a=1),s==$&&(a=2),s==_&&(a=3),s==ea&&(a=4),s==aa&&(a=5),s==sa&&(a=6),s==ca&&(a=7),s==ra&&(a=8),s==oa&&(a=9),s==Y&&(a=0),s==ta&&(a=1),s==fa&&(a=2),s==na&&(a=3),s==da&&(a=4),s==ia&&(a=5),s==pa&&(a=6),s==ua&&(a=7),s==ha&&(a=8),s==ma&&(a=9),s==la&&(a=0),s==wa&&(a=\"times\"),s==ka&&(a=\"add\"),s==ga&&(a=\"minus\"),s==ba&&(a=\"decimal\"),s==va&&(a=\"devide\"),s==qa&&(a=\"f1\"),s==ya&&(a=\"f2\"),s==ja&&(a=\"f3\"),s==xa&&(a=\"f4\"),s==za&&(a=\"f5\"),s==Ca&&(a=\"f6\"),s==Ka&&(a=\"f7\"),s==Pa&&(a=\"f8\"),s==Aa&&(a=\"f9\"),s==Ba&&(a=\"f10\"),s==Da&&(a=\"f11\"),s==Ea&&(a=\"f12\"),s==c&&(a=\"a\"),s==r&&(a=\"b\"),s==o&&(a=\"c\"),s==l&&(a=\"d\"),s==t&&(a=\"e\"),s==f&&(a=\"f\"),s==n&&(a=\"g\"),s==d&&(a=\"h\"),s==i&&(a=\"i\"),s==p&&(a=\"j\"),s==u&&(a=\"k\"),s==h&&(a=\"l\"),s==m&&(a=\"m\"),s==w&&(a=\"n\"),s==k&&(a=\"o\"),s==g&&(a=\"p\"),s==b&&(a=\"q\"),s==v&&(a=\"r\"),s==q&&(a=\"s\"),s==y&&(a=\"t\"),s==j&&(a=\"u\"),s==x&&(a=\"v\"),s==z&&(a=\"w\"),s==C&&(a=\"x\"),s==K&&(a=\"y\"),s==P&&(a=\"z\"),s==A&&(a=\"space\"),a}\n\n$(document).keydown(function(e) {\n $(\"#key\").text(getPressedKey(e));\n console.log(getPressedKey(e));\n if (getPressedKey(e)==\"space\") {\n e.preventDefault();\n }\n if (getPressedKey(e)==\"backspace\") {\n e.preventDefault();\n }\n}); <script src=\"https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js\"></script>\n<p>The Pressed Key: <span id=key></span></p>"
},
{
"answer_id": 45534377,
"author": "Ivan",
"author_id": 6331369,
"author_profile": "https://Stackoverflow.com/users/6331369",
"pm_score": 4,
"selected": false,
"text": "3: \"break\",\n8: \"backspace / delete\",\n9: \"tab\",\n12: 'clear',\n13: \"enter\",\n16: \"shift\",\n17: \"ctrl\",\n18: \"alt\",\n19: \"pause/break\",\n20: \"caps lock\",\n27: \"escape\",\n28: \"conversion\",\n29: \"non-conversion\",\n32: \"spacebar\",\n33: \"page up\",\n34: \"page down\",\n35: \"end\",\n36: \"home \",\n37: \"left arrow \",\n38: \"up arrow \",\n39: \"right arrow\",\n40: \"down arrow \",\n41: \"select\",\n42: \"print\",\n43: \"execute\",\n44: \"Print Screen\",\n45: \"insert \",\n46: \"delete\",\n48: \"0\",\n49: \"1\",\n50: \"2\",\n51: \"3\",\n52: \"4\",\n53: \"5\",\n54: \"6\",\n55: \"7\",\n56: \"8\",\n57: \"9\",\n58: \":\",\n59: \"semicolon (firefox), equals\",\n60: \"<\",\n61: \"equals (firefox)\",\n63: \"Γ\",\n64: \"@ (firefox)\",\n65: \"a\",\n66: \"b\",\n67: \"c\",\n68: \"d\",\n69: \"e\",\n70: \"f\",\n71: \"g\",\n72: \"h\",\n73: \"i\",\n74: \"j\",\n75: \"k\",\n76: \"l\",\n77: \"m\",\n78: \"n\",\n79: \"o\",\n80: \"p\",\n81: \"q\",\n82: \"r\",\n83: \"s\",\n84: \"t\",\n85: \"u\",\n86: \"v\",\n87: \"w\",\n88: \"x\",\n89: \"y\",\n90: \"z\",\n91: \"Windows Key / Left β / Chromebook Search key\",\n92: \"right window key \",\n93: \"Windows Menu / Right β\",\n96: \"numpad 0 \",\n97: \"numpad 1 \",\n98: \"numpad 2 \",\n99: \"numpad 3 \",\n100: \"numpad 4 \",\n101: \"numpad 5 \",\n102: \"numpad 6 \",\n103: \"numpad 7 \",\n104: \"numpad 8 \",\n105: \"numpad 9 \",\n106: \"multiply \",\n107: \"add\",\n108: \"numpad period (firefox)\",\n109: \"subtract \",\n110: \"decimal point\",\n111: \"divide \",\n112: \"f1 \",\n113: \"f2 \",\n114: \"f3 \",\n115: \"f4 \",\n116: \"f5 \",\n117: \"f6 \",\n118: \"f7 \",\n119: \"f8 \",\n120: \"f9 \",\n121: \"f10\",\n122: \"f11\",\n123: \"f12\",\n124: \"f13\",\n125: \"f14\",\n126: \"f15\",\n127: \"f16\",\n128: \"f17\",\n129: \"f18\",\n130: \"f19\",\n131: \"f20\",\n132: \"f21\",\n133: \"f22\",\n134: \"f23\",\n135: \"f24\",\n144: \"num lock \",\n145: \"scroll lock\",\n160: \"^\",\n161: '!',\n163: \"#\",\n164: '$',\n165: 'ΓΉ',\n166: \"page backward\",\n167: \"page forward\",\n169: \"closing paren (AZERTY)\",\n170: '*',\n171: \"~ + * key\",\n173: \"minus (firefox), mute/unmute\",\n174: \"decrease volume level\",\n175: \"increase volume level\",\n176: \"next\",\n177: \"previous\",\n178: \"stop\",\n179: \"play/pause\",\n180: \"e-mail\",\n181: \"mute/unmute (firefox)\",\n182: \"decrease volume level (firefox)\",\n183: \"increase volume level (firefox)\",\n186: \"semi-colon / Γ±\",\n187: \"equal sign \",\n188: \"comma\",\n189: \"dash \",\n190: \"period \",\n191: \"forward slash / Γ§\",\n192: \"grave accent / Γ± / Γ¦\",\n193: \"?, / or Β°\",\n194: \"numpad period (chrome)\",\n219: \"open bracket \",\n220: \"back slash \",\n221: \"close bracket / Γ₯\",\n222: \"single quote / ΓΈ\",\n223: \"`\",\n224: \"left or right β key (firefox)\",\n225: \"altgr\",\n226: \"< /git >\",\n230: \"GNOME Compose Key\",\n231: \"Γ§\",\n233: \"XF86Forward\",\n234: \"XF86Back\",\n240: \"alphanumeric\",\n242: \"hiragana/katakana\",\n243: \"half-width/full-width\",\n244: \"kanji\",\n255: \"toggle touchpad\"\n"
},
{
"answer_id": 48855666,
"author": "Gibolt",
"author_id": 974045,
"author_profile": "https://Stackoverflow.com/users/974045",
"pm_score": 3,
"selected": false,
"text": "event.key \"Enter\" \"LeftArrow\" \"r\" \"R\" const input = document.getElementById(\"searchbox\");\ninput.addEventListener(\"keypress\", function onEvent(event) {\n if (event.key === \"Enter\") {\n // Submit\n }\n else if (event.key === \"Q\") {\n // Play quacking duck sound, maybe...\n }\n});\n"
},
{
"answer_id": 58724467,
"author": "bakrall",
"author_id": 5465801,
"author_profile": "https://Stackoverflow.com/users/5465801",
"pm_score": 2,
"selected": false,
"text": "event.keyCode event.which event.key keypress"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/302122",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/999/"
] |
302,131 | <p>I'm writing a CLR stored procedure to take XML data in the form of a string, then use the data to execute certain commands etc. </p>
<p>The problem that I'm running into is that whenever I try to send XML that is longer than 4000 characters, I get an error, as the XmlDocument object can't load the XML as a lot of the closing tags are missing, due to the text being truncated after 4000 chars.</p>
<p>I think this problem boils down to the CLR stored procedure mapping the string parameter onto nvarchar(4000), when I'm thinking something like nvarchar(max) or ntext would be what I need. </p>
<p>Unfortunately, I can't find a mapping from a .NET type onto ntext, and the string type automatically goes to nvarchar(max).</p>
<p>Does anyone know of a solution to my problem?</p>
<p>Thanks for any help</p>
| [
{
"answer_id": 533745,
"author": "Dave Cluderay",
"author_id": 30933,
"author_profile": "https://Stackoverflow.com/users/30933",
"pm_score": 2,
"selected": false,
"text": "System.Data.SqlTypes.SqlXml using System;\nusing System.Data;\nusing System.Data.SqlClient;\nusing System.Data.SqlTypes;\nusing System.Xml;\n\nusing Microsoft.SqlServer.Server;\n\npublic partial class StoredProcedures\n{\n [SqlProcedure]\n public static void StoredProcedure1(SqlXml data)\n {\n using (XmlReader reader = data.CreateReader())\n {\n reader.MoveToContent();\n // Do stuff here.\n }\n }\n};\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/302131",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
302,136 | <p>I'm currently designing a database schema that's used to store recipes. In this database there are different types of entities that I want to be able to tag (ingredients, recipe issuers, recipes, etc). So a tag has multiple n:m relations. If I use the "three table design", this would result in tables (cross table) for every entity type (recipes, ingredients, issuers) that I have. In other words every time I introduce an entity I have to add a cross table for it.</p>
<p>I was thinking of creating one table which has a unique id, that all the entities refer to, and a n:m relation between the tags table and the "unique id"-table. This way there is just one cross table between the "unique id"-table and the tag table.</p>
<p>Just in case that some people will think this question already was asked. I already read <a href="https://stackoverflow.com/questions/48475/database-design-for-tagging">Database Design for Tagging</a>. And there the three table design is mentioned.</p>
| [
{
"answer_id": 302770,
"author": "Yarik",
"author_id": 31415,
"author_profile": "https://Stackoverflow.com/users/31415",
"pm_score": 2,
"selected": false,
"text": "- - - - - - - - - -\nTag\n ID // PK\n Name\n ...\n\n- - - - - - - - - -\nTaggable\n ID // PK\n ...\n\n- - - - - - - - - -\nTagAssignment\n Tag_ID // FK -> Tag.ID\n Taggable_ID // FK -> Taggable.ID\n ...\n\n- - - - - - - - - -\nEntityOne\n Taggable_ID // FK -> Taggable.ID\n ...\n\n- - - - - - - - - -\nEntityTwo\n Taggable_ID // FK -> Taggable.ID\n ...\n EntityOne.TaggableID EntityTwo.TaggableID EntityOne EntityTwo - - - - - - - - - -\nEntityOne\n ID // PK\n Taggable_ID // FK -> Taggable.ID (Nullable)\n ...\n\n- - - - - - - - - -\nEntityTwo\n ID // PK\n Taggable_ID // FK -> Taggable.ID (Nullable)\n ...\n Taggable Taggable Taggable Taggable Taggable_ID Taggable - - - - - - - - - -\nTaggable\n ID // PK\n Type \n ... \n - - - - - - - -\n Constraint: (ID, Type) is unique\n\n\n- - - - - - - - - -\nEntityOne\n ID\n Taggable_ID \n Taggable_Type // Constraint: always = 'EntityOne'\n ...\n - - - - - - - -\n FK: (Taggable_ID, Taggable_Type) -> (Taggable.ID, Taggable.Type)\n"
},
{
"answer_id": 302838,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "https://Stackoverflow.com/users/20860",
"pm_score": 2,
"selected": false,
"text": "CREATE TABLE Recipes (\n recipe_id INT NOT NULL PRIMARY KEY, -- not auto-generated\n FOREIGN KEY (recipe_id) REFERENCES Taggables(id)\n);\n Recipes Ingredients Taggables INSERT INTO Taggables (id) VALUES (327);\nINSERT INTO Recipes (recipe_id, name) VALUES (327, 'Hollandaise sauce');\nINSERT INTO Ingredients (ingr_id, name) VALUES (327, 'eggs');\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/302136",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33110/"
] |
302,157 | <p>I have a base class vehicle and some children classes like car, motorbike etc.. inheriting from vehicle.
In each children class there is a function Go();
now I want to log information on every vehicle when the function Go() fires, and on that log I want to know which kind of vehicle did it.</p>
<p>Example:</p>
<pre><code>public class vehicle
{
public void Go()
{
Log("vehicle X fired");
}
}
public class car : vehicle
{
public void Go() : base()
{
// do something
}
}
</code></pre>
<hr>
<p>How can I know in the function Log that car called me during the base()?
Thanks,</p>
<p>Omri</p>
| [
{
"answer_id": 302172,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 5,
"selected": true,
"text": "GetType() public abstract class Vehicle \n{\n public void Go()\n {\n Log(\"vehicle {0} fired\", GetType().Name);\n GoImpl();\n }\n\n protected abstract void GoImpl();\n}\n\npublic class Car : Vehicle\n{\n protected override void GoImpl()\n {\n // do something\n }\n}\n"
},
{
"answer_id": 302185,
"author": "Brian Genisio",
"author_id": 36687,
"author_profile": "https://Stackoverflow.com/users/36687",
"pm_score": 2,
"selected": false,
"text": "GetType().Name\n"
},
{
"answer_id": 302304,
"author": "Barry Jones",
"author_id": 38286,
"author_profile": "https://Stackoverflow.com/users/38286",
"pm_score": 2,
"selected": false,
"text": "public class Vehicle {\n public virtual void Go() {\n Log(this.GetType().Name);\n }\n}\n\npublic class Car : Vehicle {\n public override void Go() {\n base.Go();\n // Do car specific stuff\n }\n}\n\npublic class Bus : Vehicle {\n}\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/302157",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/38963/"
] |
302,160 | <p>Good morning,</p>
<p>Apologies for the newbie question. I'm just getting started with ASP.NET internationalization settings.</p>
<p>Background info:</p>
<p>I have a website which displays a <code><table></code> HTML object. In that <code><table></code> HTML object, I have a column which displays dates. My server being in the US, those dates show up as <code>MM/DD/YYYY</code>. Many of my users plug into this webpage through Excel, via the Data --> Import External Data --> Import Web Query interface. My users, for the most part, are in the US, so those dates show up correctly in their Excel screens.</p>
<p>Now I need to make the webpage work for UK users. As is, they are downloading the dates as <code>MM/DD/YYYY</code>, which makes their spreadsheets unusable since their regional settings are set to <code>DD/MM/YYYY</code>.</p>
<p>My question is:</p>
<p>How do I make it so the web server realizes that the incoming request has a <code>en-GB</code> culture setting? I could engineer my own little custom workaround, but I'm sure I'm not the first programmer to come across this. How do the pro's handle this? I'm looking for a solution that would be relatively simple and quick to put up, but I don't want to just put some crappy buggy piece of my own logic togethe that I'm going to dread 6 months from now.</p>
<p>Thanks a lot in advance,
-Alan.</p>
| [
{
"answer_id": 302180,
"author": "Ben Scheirman",
"author_id": 3381,
"author_profile": "https://Stackoverflow.com/users/3381",
"pm_score": 2,
"selected": false,
"text": "<configuration>\n <system.web> \n <globalization uiCulture=\"auto\" />\n ...\n"
},
{
"answer_id": 302582,
"author": "baretta",
"author_id": 30052,
"author_profile": "https://Stackoverflow.com/users/30052",
"pm_score": 1,
"selected": false,
"text": "protected override void InitializeCulture ( )\n{\n Thread.CurrentThread.CurrentCulture\n = Thread.CurrentThread.CurrentUICulture\n = Request.QueryString [ \"culture\" ] != null ? new CultureInfo ( Request.QueryString [ \"culture\" ] ) : CultureInfo.InvariantCulture;\n //base.InitializeCulture ( );\n}\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/302160",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7311/"
] |
302,166 | <p>I've recently been exposed to the fluent interface in nUnit and I love it; however, I am using msTest. </p>
<p>Does anyone know if there is a fluent interface that is either testing framework agnostic or for msTest? </p>
| [
{
"answer_id": 2048227,
"author": "nietras",
"author_id": 98692,
"author_profile": "https://Stackoverflow.com/users/98692",
"pm_score": 3,
"selected": false,
"text": "true.Should().Be.True();\nfalse.Should().Be.False();\n\nconst string something = \"something\";\nsomething.Should().Contain(\"some\");\nsomething.Should().Not.Contain(\"also\");\nsomething.ToUpperInvariant().Should().Not.Contain(\"some\");\n\nsomething.Should()\n .StartWith(\"so\")\n .And\n .EndWith(\"ing\")\n .And\n .Contain(\"meth\");\n\nsomething.Should()\n .Not.StartWith(\"ing\")\n .And\n .Not.EndWith(\"so\")\n .And\n .Not.Contain(\"body\");\n\nvar ints = new[] { 1, 2, 3 };\nints.Should().Have.SameSequenceAs(new[] { 1, 2, 3 });\nints.Should().Not.Have.SameSequenceAs(new[] { 3, 2, 1 });\nints.Should().Not.Be.Null();\nints.Should().Not.Be.Empty();\n\nints.Should()\n .Contain(2)\n .And\n .Not.Contain(4);\n\n(new int[0]).Should().Be.Empty();\n"
},
{
"answer_id": 3434628,
"author": "Dennis Doomen",
"author_id": 253961,
"author_profile": "https://Stackoverflow.com/users/253961",
"pm_score": 5,
"selected": true,
"text": "\"ABCDEFGHI\".Should().StartWith(\"AB\").And.EndWith(\"HI\").And.Contain(\"EF\").And.HaveLength(9);\n\nnew[] { 1, 2, 3 }.Should().HaveCount(4, \"because we thought we put three items in the \ncollection\"))\n\ndtoCollection.Should().Contain(dto => dto.Id != null);\n\ncollection.Should().HaveCount(c => c >= 3);\n\ndto.ShouldHave().AllPropertiesBut(d => d.Id).EqualTo(customer);\n\ndt1.Should().BeWithin(TimeSpan.FromHours(50)).Before(dt2); \n\nAction action = () => recipe.AddIngredient(\"Milk\", 100, Unit.Spoon);\naction\n .ShouldThrow<RuleViolationException>()\n .WithMessage(\"Cannot change the unit of an existing ingredient\")\n .And.Violations.Should().Contain(BusinessRule.CannotChangeIngredientQuanity\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/302166",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26160/"
] |
302,171 | <p>I'm compiling library for a private project, which depends on a number of libraries. Specifically one of the dependencies is compiled with Fortran. On some instances, I've seen the dependency compiled with <code>g77</code>, on others I've seen it compiled with <code>gfortran</code>. My project then is <code>./configure</code>'d to link with either <code>-lg2c</code> or <code>-lgfortran</code>, but so far I've been doing it by hand.</p>
<p>If it is possible, how can I find out, from looking into the dependent library (via e.g. <code>nm</code> or some other utility?), whether the used compiler was <code>g77</code> (and then I'll use <code>-lg2c</code> in my link options) or <code>gfortran</code> (and then I'll use <code>-lgfortran</code>)?</p>
<p>Thanks in advance!</p>
| [
{
"answer_id": 303165,
"author": "geocar",
"author_id": 37507,
"author_profile": "https://Stackoverflow.com/users/37507",
"pm_score": 4,
"selected": true,
"text": "nm filename | fgrep ' __g77'\n nm filename | fgrep '@@GFORTRAN'\n"
},
{
"answer_id": 1170330,
"author": "F'x",
"author_id": 143495,
"author_profile": "https://Stackoverflow.com/users/143495",
"pm_score": 2,
"selected": false,
"text": "nm filename g77 gfortran nm filename | grep _g77_\nnm filename | grep _gfortran_\n @@GFORTRAN"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/302171",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36145/"
] |
302,181 | <p>I've got two ASP.Net applications residing in two different folders on my server:</p>
<ul>
<li><code>/Foo</code> <-- this is the standard unsecure application</li>
<li><code>/Secure</code> <-- this is a separate application that requires SSL by IIS</li>
</ul>
<p>The problem is that by default, the <code>ASP.NET_SessionId</code> cookie is specified on the domain and is shared between the two applications in different directories. I need the session cookie to be different because I can't allow a hijacked cookie on <code>/Foo</code> to be used to grant access to the <code>/Secure</code> application.</p>
<p>Ideally, I would like each application's cookie to be limited by the cookie <code>Path</code> property. There's apparently no way to do this in .Net out of the box.</p>
<p>As an added headache, even if I write custom code to set the cookie path, I'm fearful that some browsers are case sensitive and won't use the same session cookie for <code>/Foo</code> and <code>/foo</code>, which, depending on how the links are built, can result in multiple sessions in the same application.</p>
<p>Has anyone encountered and overcome this issue?</p>
| [
{
"answer_id": 302248,
"author": "Kev",
"author_id": 419,
"author_profile": "https://Stackoverflow.com/users/419",
"pm_score": 1,
"selected": false,
"text": "/Secure /Foo"
},
{
"answer_id": 11860233,
"author": "ZokiPoki",
"author_id": 1584014,
"author_profile": "https://Stackoverflow.com/users/1584014",
"pm_score": 1,
"selected": false,
"text": "<forms name=\"Foo\"...\n<forms name=\"Secure\"...\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/302181",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34409/"
] |
302,195 | <p>Im trying to extract a line from wget's result but having trouble with it.
This is my wget call:</p>
<pre><code>$ wget -SO- -T 1 -t 1 http://myurl.com:15000/myhtml.html
</code></pre>
<p>Output:</p>
<pre>
--18:24:12-- http://xxx.xxxx.xxxx:15000/myhtml.html
=> `-'
Resolving xxx.xxxx.xxxx... xxx.xxxx.xxxx
Connecting to xxx.xxxx.xxxx|xxx.xxxx.xxxx|:15000... connected.
HTTP request sent, awaiting response...
HTTP/1.1 302 Found
Date: Tue, 18 Nov 2008 23:24:12 GMT
Server: IBM_HTTP_Server
Expires: Thu, 01 Dec 1994 16:00:00 GMT
Location: https://xxx.xxxx.xxxx/siteminderagent/...
Content-Length: 508
Keep-Alive: timeout=10, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=iso-8859-1
Location: https://xxx.xxxx.xxxx//siteminderagent/...
--18:24:13-- https://xxx.xxxx.xxxx/siteminderagent/...
=> `-'
Resolving xxx.xxxx.xxxx... failed: Name or service not known.
</pre>
<p>if I do this: <br/><br/></p>
<pre><code>$ wget -SO- -T 1 -t 1 http://myurl.com:15000/myhtml.html | egrep -i "302" <br/>
</code></pre>
<p>It doesnt return me the line that contains the string. I just want to check if the site or siteminder is up.</p>
| [
{
"answer_id": 302213,
"author": "Piotr Lesnicki",
"author_id": 38796,
"author_profile": "https://Stackoverflow.com/users/38796",
"pm_score": 5,
"selected": true,
"text": "$ wget -SO- -T 1 -t 1 http://myurl.com:15000/myhtml.html 2>&1 | egrep -i \"302\" \n"
},
{
"answer_id": 302232,
"author": "Adam Rosenfield",
"author_id": 9530,
"author_profile": "https://Stackoverflow.com/users/9530",
"pm_score": 3,
"selected": false,
"text": "wget wget -SO- -T 1 -t 1 http://myurl.com:15000/myhtml.html 2>&1 | egrep -i \"302\"\n"
},
{
"answer_id": 4888862,
"author": "DrBao",
"author_id": 601899,
"author_profile": "https://Stackoverflow.com/users/601899",
"pm_score": 2,
"selected": false,
"text": "2>&1 >/dev/null egrep -c"
},
{
"answer_id": 8980119,
"author": "MarkHu",
"author_id": 699665,
"author_profile": "https://Stackoverflow.com/users/699665",
"pm_score": 1,
"selected": false,
"text": "-S --server-response wget curl curl --head --silent $yourURL\n curl -I -s $yourURL\n --silent grep -s"
},
{
"answer_id": 73189323,
"author": "Timmah",
"author_id": 1594373,
"author_profile": "https://Stackoverflow.com/users/1594373",
"pm_score": 0,
"selected": false,
"text": "curl curl -o /dev/null -I --silent --head --write-out %{http_code} https://example.com wget -Sq -T 1 -t 1 --no-check-certificate --spider https://example.com 2>&1 | egrep 'HTTP/1.1 ' | cut -d ' ' -f 4 302 200"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/302195",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/38961/"
] |
302,208 | <p>I've built the x86 Boost libraries many times, but I can't seem to build x64 libraries. I start the "Visual Studio 2005 x64 Cross Tools Command Prompt" and run my usual build:</p>
<pre><code>bjam --toolset=msvc --build-type=complete --build-dir=c:\build install
</code></pre>
<p>But it still produces x86 .lib files (I verified this with dumpbin /headers).
What am I doing wrong?</p>
| [
{
"answer_id": 302257,
"author": "macbirdie",
"author_id": 5049,
"author_profile": "https://Stackoverflow.com/users/5049",
"pm_score": 7,
"selected": true,
"text": "address-model=64"
},
{
"answer_id": 30814129,
"author": "sergtk",
"author_id": 13441,
"author_profile": "https://Stackoverflow.com/users/13441",
"pm_score": 1,
"selected": false,
"text": "address-model=64\n"
},
{
"answer_id": 44541404,
"author": "Teemu Ikonen",
"author_id": 969597,
"author_profile": "https://Stackoverflow.com/users/969597",
"pm_score": 3,
"selected": false,
"text": "C:\\Work\\Boost_1_63> C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Auxiliary\\Build\\vcvarsall.bat amd64\nC:\\Work\\Boost_1_63> bootstrap.bat\nC:\\Work\\Boost_1_63> bjam -j4 architecture=x86 address-model=64 link=static stage\nC:\\Work\\Boost_1_63> bjam --prefix=C:\\opt\\boost architecture=x86 address-model=64 link=static install\n C:\\Work> dumpbin /headers C:\\work\\boost_1_63\\stage\\lib\\libboost_locale-vc140-mt-1_63.lib | findstr machine\n8664 machine (x64)\n8664 machine (x64)\n8664 machine (x64)\n8664 machine (x64) \n...\n"
},
{
"answer_id": 58617909,
"author": "RemiDav",
"author_id": 3651347,
"author_profile": "https://Stackoverflow.com/users/3651347",
"pm_score": 2,
"selected": false,
"text": "b2 --build-dir=build/x64 address-model=64 threading=multi --build-type=complete --stagedir=./stage/x64\n default address-model: 32-bit library-vc140-mt-x64-1_71.dll"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/302208",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4086/"
] |
302,219 | <p>I'm using the following logon trigger on an Oracle 10.2 database:</p>
<pre><code>CREATE OR REPLACE TRIGGER AlterSession_trg
AFTER LOGON ON DATABASE
BEGIN
EXECUTE IMMEDIATE 'ALTER SESSION SET NLS_COMP=LINGUISTIC';
EXECUTE IMMEDIATE 'ALTER SESSION SET NLS_SORT=BINARY_AI';
END AlterSession_trg;
</code></pre>
<p>This is intended to make case sensitive queries a thing of the past, and when I connect from PL/SQL Developer this is indeed the case. However, when I connect from SQL Developer or the ASP.NET application I'm working on queries are again case sensitive. Is there anyway that SQL Developer/.NET could be skipping over this trigger? Have I set the trigger up wrong?</p>
| [
{
"answer_id": 302832,
"author": "Serxipc",
"author_id": 34009,
"author_profile": "https://Stackoverflow.com/users/34009",
"pm_score": 3,
"selected": true,
"text": "NLS_COMP NLS_SORT"
},
{
"answer_id": 304634,
"author": "Dave Lewis",
"author_id": 29740,
"author_profile": "https://Stackoverflow.com/users/29740",
"pm_score": 1,
"selected": false,
"text": "ALTER SYSTEM SET NLS_COMP=LINGUISTIC SCOPE SPFILE;\nALTER SYSTEM SET NLS_SORT=BINARY_AI SCOPE SPFILE;\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/302219",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29740/"
] |
302,223 | <p>I have a PHP-generated page which is displaying some data about a set of films. The page is updated using POST. The form only shows films starting with a particular letter. I want to present a set of clickable options at the top of the screen, each of which is a letter. So if you click on "B" it submits the form and re-draws the page showing only films that start with B. (I know, Ajax would be a better way to do this, but I'm trying to get something done quickly).</p>
<p>Anyway, I know I can do this by having each link be a Javascript call which sets the value of a hidden field and then submits the form, or I could do it by having each letter be a button which has a particular value and submits the form directly, but neither of those strikes me as particularly elegant. Is there a standard way to do this? Am I missing something really obvious?</p>
| [
{
"answer_id": 302400,
"author": "Piskvor left the building",
"author_id": 19746,
"author_profile": "https://Stackoverflow.com/users/19746",
"pm_score": 0,
"selected": false,
"text": "<input type=\"submit\" name=\"letter\" value=\"A\" />\n<input type=\"submit\" name=\"letter\" value=\"B\" />\n<input type=\"submit\" name=\"letter\" value=\"C\" />\n...\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/302223",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11522/"
] |
302,234 | <p>In my asp.net mvc page I create a link that renders as followed:</p>
<p><code>http://localhost:3035/Formula/OverView?colorId=349405&paintCode=744&name=BRILLANT%20SILVER&formulaId=570230</code></p>
<p>According to the W3C validator, this is not correct and it errors after the first ampersand. It complains about the & not being encoded and the entity &p not recognised etc.</p>
<p>AFAIK the & shouldn't be encoded because it is a separator for the key value pair.</p>
<p>For those who care: I send these pars as querystring and not as "/" seperated values because there is no decent way of passing on optional parameters that I know of.</p>
<p>To put all the bits together:</p>
<ul>
<li>an anchor (<a>) tag's href attribute needs an encoded value</li>
<li>& encodes to &amp;</li>
<li>to encode an '&' when it is part of your parameter's value, use %26</li>
</ul>
<p>Wouldn't encoding the ampersand into & make it part of my parameter's value?
I need it to seperate the second variable from the first</p>
<p>Indeed, by encoding my href value, I do get rid of the errors. What I'm wondering now however is what to do if for example my colorId would be "123&456", where the ampersand is part of the value.
Since the separator has to be encoded, what to do with encoded ampersands. Do they need to be encoded twice so to speak?</p>
<p>So to get the url: </p>
<p><code>www.mySite.com/search?query=123&amp;456&page=1</code></p>
<p>What should my href value be?</p>
<p>Also, I think I'm about the first person in the world to care about this.. go check the www and count the pages that get their query string validated in the W3C validator..</p>
| [
{
"answer_id": 302255,
"author": "Illandril",
"author_id": 17887,
"author_profile": "https://Stackoverflow.com/users/17887",
"pm_score": 3,
"selected": true,
"text": "<a href=\"http://localhost:3035/Formula/OverView?colorId=349405&paintCode=744&name=BRILLANT%20SILVER&formulaId=570230\">Whatever</a>\n <a href=\"http://localhost/Hello?name=Bob&text=you%20%26%20me%20"forever"\">Hello</a>\n"
},
{
"answer_id": 304089,
"author": "nickf",
"author_id": 9021,
"author_profile": "https://Stackoverflow.com/users/9021",
"pm_score": 1,
"selected": false,
"text": "& <a href=\"abc?def=5&ghi=10\"> abc?def=5&ghi=10 // though you define your string like this:\nmyString = \"this is \\\"something\\\" you know?\"\n\n// the string is ACTUALLY: this is \"something\" you know?\n\n// when you look at the HTML, you see:\n<a href=\"foo?bar=1&baz=2\">\n\n// but the url is ACTUALLY: foo?bar=1&bar=2\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/302234",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11333/"
] |
302,239 | <p>I'm trying to add a publisher policy file to the gac as per this <a href="https://stackoverflow.com/questions/283419/how-to-just-load-the-latest-version-of-dll-from-gac">thread</a> but I'm having problems when I try and add the file on my test server. </p>
<p>I get "A module specified in the manifest of assembly 'policy.3.0.assemblyname.dll' could not be found"</p>
<p>My policy file looks like this:</p>
<pre><code><configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="*assemblyname*"
publicKeyToken="7a19eec6f55e2f84"
culture="neutral" />
<bindingRedirect oldVersion="3.0.0.0"
newVersion="3.0.0.1"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
</code></pre>
<p>Please help!</p>
<p>Thanks</p>
<p>Ben</p>
<hr>
<p>I've recreated the problem from scratch with a new assembly that has no dependancies (apart from the defaults) itself - all works fine on my local development machine (and redirects fine too) but gives the same error adding the policy file to the GAC on the server!</p>
<pre><code><configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="TestAsm"
publicKeyToken="5f55456fdcc9b528"
culture="neutral" />
<bindingRedirect oldVersion="3.0.0.0"
newVersion="3.0.0.1"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
</code></pre>
<p>linked in the following way</p>
<pre><code>C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\al.exe /link:PublisherPolicy.xml /out:policy.3.0.TestAsm.dll /keyfile:..\..\key.snk /version:3.0.0.0
pause
</code></pre>
<p>Please help!</p>
| [
{
"answer_id": 302417,
"author": "Kev",
"author_id": 419,
"author_profile": "https://Stackoverflow.com/users/419",
"pm_score": 1,
"selected": false,
"text": "al.exe /link:assembly.config /out:policy.3.0.assembly.dll \n /keyfile:mykey.snk /version:3.0.0.0\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/302239",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36852/"
] |
302,244 | <p>I'm working on a .NET web application and I'm using a CalendarExtender control within it to have the user specify a date. For some reason, when I click the icon to display the calendar, the background seems to be transparent.</p>
<p>I'm using the extender on other pages and do not run into this issue.</p>
<p>I'm not sure if it is worth mentioning, but the calendar is nested within a panel that has a rounded corner extender attached to it, as well as the panel below it (where the "From" is overlapping).</p>
<p>Within that panel, I do have a div layout setup to create two columns.</p>
<p>EDIT: The other thing to note here is that the section that has the name and "placeholders" for nickname are all ASP.NET label controls, if that matters.</p>
| [
{
"answer_id": 306595,
"author": "Dillie-O",
"author_id": 71,
"author_profile": "https://Stackoverflow.com/users/71",
"pm_score": 6,
"selected": true,
"text": ".ajax__calendar_container { z-index : 1000 ; }\n <style type=\"text/css\">\n .ajax__calendar_container { z-index : 1000 ; }\n</style>\n .ajax__calendar {\n position: relative;\n left: 0px !important;\n top: 0px !important;\n visibility: visible; display: block;\n}\n.ajax__calendar iframe\n{\n left: 0px !important;\n top: 0px !important;\n}\n"
},
{
"answer_id": 866281,
"author": "Paul Rowland",
"author_id": 6268,
"author_profile": "https://Stackoverflow.com/users/6268",
"pm_score": 0,
"selected": false,
"text": "<fieldset> some content... including ajax popup </fieldset>\n<fieldset> some more content </fieldset>\n <fieldset style=\"z-index: 2;\"> some content... including ajax popup </fieldset>\n<fieldset style=\"z-index: 1;\"> some more content </fieldset> \n"
},
{
"answer_id": 14833355,
"author": "Bucket",
"author_id": 971246,
"author_profile": "https://Stackoverflow.com/users/971246",
"pm_score": 2,
"selected": false,
"text": ".ajax__calendar_container\n{\n position:static;\n}\n"
},
{
"answer_id": 44924076,
"author": "Gregor Primar",
"author_id": 1107945,
"author_profile": "https://Stackoverflow.com/users/1107945",
"pm_score": 0,
"selected": false,
"text": ".ajax__scroll_none {\n overflow: visible !important;\n z-index: 10000 !important;\n}\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/302244",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/71/"
] |
302,252 | <p>I have a class that looks like this:</p>
<pre><code>public class TextField : TextBox
{
public bool Required { get; set; }
RequiredFieldValidator _validator;
protected override void CreateChildControls()
{
base.CreateChildControls();
_validator = new RequiredFieldValidator();
_validator.ControlToValidate = this.ID;
if(Required)
Controls.Add(_validator);
}
public override void Render(HtmlTextWriter tw)
{
base.Render(tw);
if(Required)
_validator.RenderControl(tw);
}
}
</code></pre>
<p>This has been working for a while in a internal application where javascript is always enabled. I recently noticed that an upstream javascript error can prevent the validators from firing, so the server side validation should kick in... right? right?</p>
<p>So the Page.IsValid property always returns true (I even tried explicitly calling Page.Validate() before-hand). </p>
<p>After some digging, I found that the validator init method should add the validator to the page, but due to the way I'm building it up, I don't think this ever happens. Thus, client side validation works, but server side validation does not.</p>
<p>I've tried this:</p>
<pre><code>protected override OnInit()
{
base.OnInit();
Page.Validators.Add(_validator); // <-- validator is null here
}
</code></pre>
<p>But of course the validator is null here (and sometimes it's not required so it shouldn't be added)... but OnInit() is really early for me to make those decisions (the Required property won't have been loaded from ViewState for example).</p>
<p>Ideas?</p>
| [
{
"answer_id": 302468,
"author": "azamsharp",
"author_id": 3797,
"author_profile": "https://Stackoverflow.com/users/3797",
"pm_score": 2,
"selected": true,
"text": "public class RequiredTextBox : TextBox\n {\n private RequiredFieldValidator _req;\n private string _errorMessage;\n\n public string ErrorMessage\n {\n get { return _errorMessage; }\n set { _errorMessage = value; } \n }\n\n protected override void OnInit(EventArgs e)\n {\n _req = new RequiredFieldValidator();\n _req.ControlToValidate = this.ID;\n _req.ErrorMessage = _errorMessage;\n Controls.Add(_req);\n base.OnInit(e); \n } \n\n protected override void Render(System.Web.UI.HtmlTextWriter writer)\n {\n base.Render(writer);\n _req.RenderControl(writer); \n }\n }\n protected void SubmitClick(object sender, EventArgs e)\n {\n if(Page.IsValid)\n {\n // do something\n }\n }\n <MyControl:RequiredTextBox runat=\"server\" ErrorMessage=\"Name is required!\" ID=\"txtName\"></MyControl:RequiredTextBox>\n\n <asp:Button ID=\"Btn_Submit\" runat=\"server\" Text=\"Submit\" OnClick=\"SubmitClick\" /> \n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/302252",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3381/"
] |
302,258 | <p>does anybody know how to save and retrieve files in MS SQL-Server 2000? I guess the image data type could be used as a container.</p>
<p>I want to import/export the following file types: DOC, XLS, PDF, BMP, TIFF, etc.</p>
<p>Due to resource issues we are using MS-Access 2007 as the front end, so I am looking for VBA code.</p>
<p>Thanks in Advance.</p>
| [
{
"answer_id": 319332,
"author": "Philippe Grondier",
"author_id": 11436,
"author_profile": "https://Stackoverflow.com/users/11436",
"pm_score": 2,
"selected": false,
"text": "Tbl_Folder Tbl_File filename Access.followHyperlink"
},
{
"answer_id": 324790,
"author": "Birger",
"author_id": 11485,
"author_profile": "https://Stackoverflow.com/users/11485",
"pm_score": 0,
"selected": false,
"text": "Set rs = New ADODB.Recordset\nrs.Open \"select * from YourTable\", Connection, adOpenKeyset, adLockOptimistic\n\nSet mstream = New ADODB.Stream\nmstream.Type = adTypeBinary\nmstream.Open\nmstream.LoadFromFile \"c:\\myfile.pdf\"\nrs.Fields(\"blobfield\").Value = mstream.Read\nrs.Update\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/302258",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
302,271 | <p>I am trying to use the <code>System.Net.Mail.MailMessage</code> class in C# to create an email that is sent to a list of email addresses all via <code>BCC</code>. I do not want to include a <code>TO</code> address, but it seems that I must because I get an exception if I use an empty string for the <code>TO</code> address in the <code>MailMessage</code> constructor. The error states: </p>
<pre><code>ArgumentException
The parameter 'addresses' cannot be an empty string.
Parameter name: addresses
</code></pre>
<p>Surely it is possible to send an email using only <code>BCC</code> as this is not a limitation of SMTP.</p>
<p><strong>Is there a way around this?</strong></p>
| [
{
"answer_id": 302335,
"author": "FlySwat",
"author_id": 1965,
"author_profile": "https://Stackoverflow.com/users/1965",
"pm_score": 2,
"selected": false,
"text": "Mailer@CompanyName.com TO NoReply@CompanyName FROM"
},
{
"answer_id": 1045761,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 5,
"selected": true,
"text": "emailMessage.To.Add(sendTo); To"
},
{
"answer_id": 44440944,
"author": "Olivier de Rivoyre",
"author_id": 740362,
"author_profile": "https://Stackoverflow.com/users/740362",
"pm_score": 0,
"selected": false,
"text": "MailMessage msg = new MailMessage(from, \"fake@example.com\");\nmsg.To.Clear();\nforeach (string email in bcc.Split(';').Select(x => x.Trim()).Where(x => x != \"\"))\n{\n msg.Bcc.Add(email);\n}\n"
},
{
"answer_id": 55251210,
"author": "A J",
"author_id": 8469477,
"author_profile": "https://Stackoverflow.com/users/8469477",
"pm_score": 0,
"selected": false,
"text": "var msg = new MailMessage(\"no-reply@notreal.com\", \"\");\n MailMessage msg = new MailMessage();\nSmtpClient SmtpServer = new SmtpClient(\"smtp.notreal.com\");\nmsg.From = new MailAddress(\"no-reply@notreal.com\");\n//msg.To.Add(\"target@notreal.com\"); <--not needed\nmsg.Bcc.Add(\"BCCtarget@notreal.com\");\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/302271",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12081/"
] |
302,277 | <p>I was wondering whether the object to test should be a field and thus set up during a <code>SetUp</code> method (ie. JUnit, nUnit, MS Test, β¦).</p>
<p>Consider the following examples (this is Cβ― with MsTest, but the idea should be similar for any other language and testing framework):</p>
<pre><code>public class SomeStuff
{
public string Value { get; private set; }
public SomeStuff(string value)
{
this.Value = value;
}
}
[TestClass]
public class SomeStuffTestWithSetUp
{
private string value;
private SomeStuff someStuff;
[TestInitialize]
public void MyTestInitialize()
{
this.value = Guid.NewGuid().ToString();
this.someStuff = new SomeStuff(this.value);
}
[TestCleanup]
public void MyTestCleanup()
{
this.someStuff = null;
this.value = string.Empty;
}
[TestMethod]
public void TestGetValue()
{
Assert.AreEqual(this.value, this.someStuff.Value);
}
}
[TestClass]
public class SomeStuffTestWithoutSetup
{
[TestMethod]
public void TestGetValue()
{
string value = Guid.NewGuid().ToString();
SomeStuff someStuff = new SomeStuff(value);
Assert.AreEqual(value, someStuff.Value);
}
}
</code></pre>
<p>Of course, with just one test method, the first example is much too long, but with more test methods, this could be safe quite some redundant code.</p>
<p>What are the pros and cons of each approach? Are there any βBest Practicesβ?</p>
| [
{
"answer_id": 302541,
"author": "silverbugg",
"author_id": 29650,
"author_profile": "https://Stackoverflow.com/users/29650",
"pm_score": 0,
"selected": false,
"text": "[Test]\npublic void TestSomething()\n{\n _myVar = \"value\";\n InstantiateClass();\n RunTheClass();\n Assert.IsTrue(this, that);\n}\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/302277",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11963/"
] |
302,279 | <p>I want to know if I'm missing something.
Here's how I would do it:
For SPFolder I would change the associtaed item's permissions (SPFolder.Item).
So I suppose managing SPFolder permissions boils down to managing SPListItem permissions.
For SPListItem I would frist break role inheritance with <code>SPListItem.BreakRoleInheritance()</code> and then work with <code>RoleAssignments</code> collections adding and removing roles there.</p>
<p>I wonder if RoleAssignments is the only way to manage SPListItem's permissions (besides inheritance) and is there a way to manage individual permissions without roles.
There is also EffectiveBasePermissions property but I'm not sure.</p>
<p>So the question is
is there other ways (besides inheritance) to manage SPListItem permissions apart from the RoleAssignments collection?</p>
<p><strong>@Edit:</strong> there's also AllRolesForCurrentUser, but I guess you can get the same info from the RoleAssignments property, so this one is just for convenience.</p>
<p><strong>@Edit:</strong> As Flo notes in his answer there is a problem with setting</p>
<pre><code>folder.ParentWeb.AllowUnsafeUpdates = true;
</code></pre>
<p>And using <code>BreakRoleInheritance</code> with argument of 'false' (i.e. without copying permissions of the parent object).</p>
<pre><code>folder.Item.BreakRoleInheritance(false);
</code></pre>
<p><code>BreakRoleInheritance</code> simply won't work on GET request as you'd expect after allowing unsafe updates. Presumably the method resets <code>AllowUnsafeUpdates</code> back to 'false'.</p>
<p>One workaround I know for this is to manually delete the inherited permissions after you BreakRoleInheritance(true), like this:</p>
<pre><code>folder.Item.BreakRoleInheritance(false);
while(folder.Item.RoleAssignments.Count > 0) {
folder.Item.RoleAssignments.Remove(0);
}
</code></pre>
<p>Thanks!</p>
| [
{
"answer_id": 302541,
"author": "silverbugg",
"author_id": 29650,
"author_profile": "https://Stackoverflow.com/users/29650",
"pm_score": 0,
"selected": false,
"text": "[Test]\npublic void TestSomething()\n{\n _myVar = \"value\";\n InstantiateClass();\n RunTheClass();\n Assert.IsTrue(this, that);\n}\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/302279",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/578/"
] |
302,294 | <p>Where does Firefox store cookies and in what format are they stored</p>
| [
{
"answer_id": 302308,
"author": "VonC",
"author_id": 6309,
"author_profile": "https://Stackoverflow.com/users/6309",
"pm_score": 6,
"selected": true,
"text": "cookies.txt cookies.sqlite C:\\Documents and Settings\\username\\Application Data\\Mozilla\\Firefox\\Profiles\\xxxx.default \n xxxx ~/.mozilla/firefox/xxxx.default/cookies.sqlite\n xxxx"
},
{
"answer_id": 302394,
"author": "Brian",
"author_id": 18192,
"author_profile": "https://Stackoverflow.com/users/18192",
"pm_score": 2,
"selected": false,
"text": "PathFromCSIDL(CSIDL_APPDATA) + \"Mozilla\\Firefox\\Profiles\\\" + [[profiledirectory]] + \"\\\" + \"cookies.sqlite\" PathFromCSIDL [[profiledirectory]]"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/302294",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1443363/"
] |
302,303 | <p>Good morning,</p>
<p>I am working on a C# winform application that is using validation for the controls. The issue I'm having is that when a user clicks into a textbox and attempts to click out, the validation fires and re-focuses the control, basically the user cannot click out of the control to another control.</p>
<p>My desired result is to have ALL of the controls on the form validate when the user clicks the submit button. I would like to have the errorProvider icon appear next to the fields that are in error and allow the user to correct them as they see fit.</p>
<p>My question is, how do I setup a control to allow a user to click outside of it when there is an error. I'd like the user to have the ability to fill in the rest of the form and come back to the error on their own instead of being forced to deal with it immediately.</p>
<p>Thank you in advance for any help and advice,</p>
| [
{
"answer_id": 302590,
"author": "Hath",
"author_id": 5186,
"author_profile": "https://Stackoverflow.com/users/5186",
"pm_score": 2,
"selected": false,
"text": " private void OnSave()\n {\n if(ValidateData())\n {\n //do save\n }\n }\n\n public bool ValidateData()\n {\n errorProvider.Clear();\n bool valid = true;\n if (this.defectStatusComboBox.SelectedIndex == -1)\n {\n errorProvider.SetError(defectStatusComboBox, \"This is a required feild.\");\n valid = false;\n }\n //etc...\n return valid;\n }\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/302303",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
302,310 | <p>What does it mean that a Transaction Log is Full? I have it the file set to grow 20% when needed. I have 4GBs left on the drive. How do I solve this issue permanently?
Running these commands solves the issue temporarily:</p>
<pre>
DBCC SHRINKFILE('MyDatabase_log', 1)
BACKUP LOG MyDatabase WITH TRUNCATE_ONLY
DBCC SHRINKFILE('MyDatabase_log', 1)
</pre>
| [
{
"answer_id": 319574,
"author": "Astra",
"author_id": 5862,
"author_profile": "https://Stackoverflow.com/users/5862",
"pm_score": 0,
"selected": false,
"text": "BACKUP LOG MyDatabase WITH TRUNCATE_ONLY"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/302310",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36590/"
] |
302,312 | <p>I have a tab page that should be hidden if a property (BlahType) is set to 1 and shown if set to 0. This is what I <em>WANT</em> to do:</p>
<pre><code><TabItem Header="Blah">
<TabItem.Triggers>
<DataTrigger Binding="{Binding BlahType}" Value="0">
<Setter Property="TabItem.Visibility" Value="Hidden" />
</DataTrigger>
</TabItem.Triggers>
</TabItem>
</code></pre>
<p>The problem is, I get this error:</p>
<pre><code>"Triggers collection members must be of type EventTrigger"
</code></pre>
<p>If you Google that error, you'll see that <a href="http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/f816fd72-4f41-4a1a-b0a2-4e409e89c75c/" rel="nofollow noreferrer">Dr. WPF explains the error</a>. Is there a clean way to do what I'm trying to achieve here?</p>
| [
{
"answer_id": 302358,
"author": "David Padbury",
"author_id": 26401,
"author_profile": "https://Stackoverflow.com/users/26401",
"pm_score": 5,
"selected": true,
"text": "<TabItem Header=\"Blah\">\n <TabItem.Style>\n <Style>\n <Style.Triggers>\n <DataTrigger Binding=\"{Binding BlahType}\" Value=\"0\">\n <Setter Property=\"TabItem.Visibility\" Value=\"Hidden\" />\n </DataTrigger>\n </Style.Triggers>\n </Style>\n </TabItem.Style>\n</TabItem>\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/302312",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11917/"
] |
302,365 | <p>A class has a property (and instance var) of type NSMutableArray with synthesized accessors (via <code>@property</code>). If you observe this array using:</p>
<pre><code>[myObj addObserver:self forKeyPath:@"theArray" options:0 context:NULL];
</code></pre>
<p>And then insert an object in the array like this:</p>
<pre><code>[myObj.theArray addObject:NSString.string];
</code></pre>
<p>An observeValueForKeyPath... notification is <strong>not</strong> sent. However, the following does send the proper notification:</p>
<pre><code>[[myObj mutableArrayValueForKey:@"theArray"] addObject:NSString.string];
</code></pre>
<p>This is because <code>mutableArrayValueForKey</code> returns a proxy object that takes care of notifying observers.</p>
<p>But shouldn't the synthesized accessors automatically return such a proxy object? What's the proper way to work around this--should I write a custom accessor that just invokes <code>[super mutableArrayValueForKey...]</code>?</p>
| [
{
"answer_id": 302763,
"author": "Ben Gottlieb",
"author_id": 6694,
"author_profile": "https://Stackoverflow.com/users/6694",
"pm_score": 0,
"selected": false,
"text": "addObject: willChangeValueForKey: didChangeValueForKey:"
},
{
"answer_id": 303128,
"author": "Marc Charbonneau",
"author_id": 35136,
"author_profile": "https://Stackoverflow.com/users/35136",
"pm_score": 3,
"selected": false,
"text": "willChangeValueForKey didChangeValueForKey willChange:valuesAtIndexes:forKey: addSomeObject: mutableArrayValueForKey: insertObject:in<Key>AtIndex: removeObjectFrom<Key>AtIndex:"
},
{
"answer_id": 304143,
"author": "Peter Hosey",
"author_id": 30461,
"author_profile": "https://Stackoverflow.com/users/30461",
"pm_score": 7,
"selected": true,
"text": "[super mutableArrayValueForKey...] [myObject insertObject:newObject inTheArrayAtIndex:[myObject countOfTheArray]];\n addTheArrayObject: - (void) addTheArrayObject:(NSObject *) newObject {\n [self insertObject:newObject inTheArrayAtIndex:[self countOfTheArray]];\n}\n NSObject [myObject insertObject:β¦] [myObject addTheArrayObject:newObject] add<Key>Object: remove<Key>Object:"
},
{
"answer_id": 3058782,
"author": "matt",
"author_id": 341994,
"author_profile": "https://Stackoverflow.com/users/341994",
"pm_score": 2,
"selected": false,
"text": "theArray theMutableArray - (NSMutableArray*) theMutableArray {\n return [self mutableArrayValueForKey:@\"theArray\"];\n}\n thisObject.theMutableArray insertObject:inTheArrayAtIndex: removeObjectFromTheArrayAtIndex:"
},
{
"answer_id": 19313719,
"author": "Peter Lapisu",
"author_id": 533422,
"author_profile": "https://Stackoverflow.com/users/533422",
"pm_score": 0,
"selected": false,
"text": "- (void)addSomeObject:(id)object {\n self.myArray = [self.myArray arrayByAddingObject:object];\n}\n\n- (void)removeSomeObject:(id)object {\n NSMutableArray * ma = [self.myArray mutableCopy];\n [ma removeObject:object];\n self.myArray = ma;\n}\n"
},
{
"answer_id": 19708720,
"author": "berbie",
"author_id": 647835,
"author_profile": "https://Stackoverflow.com/users/647835",
"pm_score": 3,
"selected": false,
"text": "[myObj addObserver:self forKeyPath:@\"theArray.@count\" options:0 context:NULL];\n"
},
{
"answer_id": 23123046,
"author": "Patrick Pijnappel",
"author_id": 1096070,
"author_profile": "https://Stackoverflow.com/users/1096070",
"pm_score": 2,
"selected": false,
"text": "// Interface\n@property (nonatomic, strong, readonly) NSMutableArray *items;\n\n// Implementation\n@synthesize items = _items;\n\n- (NSMutableArray *)items\n{\n return [self mutableArrayValueForKey:@\"items\"];\n}\n\n// Somewhere else\n[myObject.items insertObject:@\"test\"]; // Will result in KVO notifications for key \"items\"\n mutableArrayValueForKey: _<key> <key>"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/302365",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/79/"
] |
302,369 | <p>The hover "joke" in #505 <a href="http://en.wikipedia.org/wiki/Xkcd" rel="noreferrer">xkcd</a> touts "I call rule 34 on Wolfram's Rule 34".</p>
<p>I know <a href="http://www.urbandictionary.com/define.php?term=Rule%2034" rel="noreferrer">what rule 34 is in Internet terms</a> and I've googled up <a href="http://en.wikipedia.org/wiki/Stephen_Wolfram" rel="noreferrer">who Wolfram is</a> but I'm having a hard time figuring out what Wolfram's Rule 34 is.</p>
<p>So what exactly is this "Rule 34"?</p>
<p>Here's the comic: <a href="http://xkcd.com/505/" rel="noreferrer">http://xkcd.com/505/</a>.</p>
| [
{
"answer_id": 302411,
"author": "Lucas Oman",
"author_id": 6726,
"author_profile": "https://Stackoverflow.com/users/6726",
"pm_score": 7,
"selected": true,
"text": "RULES:\n0: 0 0 0\n1: 0 0 1\n2: 0 1 0\n3: 0 1 1\n4: 1 0 0\n5: 1 0 1\n6: 1 1 0\n7: 1 1 1\n"
},
{
"answer_id": 310972,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 4,
"selected": false,
"text": "0;0 -> 0\n0;0 -> 1\n0;1 -> 0\n0;1 -> 1\n1;0 -> 0\n1;0 -> 1\n1;1 -> 0\n1;1 -> 1\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/302369",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8724/"
] |
302,371 | <p><strong>Description |</strong> A Java program to read a text file and print each of the unique words in alphabetical order together with the number of times the word occurs in the text. </p>
<p>The program should declare a variable of type <code>Map<String, Integer></code> to store the words and corresponding frequency of occurrence. Which concrete type, though? <code>TreeMap<String, Number></code> or <code>HashMap<String, Number></code> ?</p>
<p>The input should be converted to lower case.</p>
<p>A word does not contain any of these characters: <code>\t\t\n]f.,!?:;\"()'</code></p>
<p><strong>Example output |</strong> </p>
<pre><code> Word Frequency
a 1
and 5
appearances 1
as 1
.
.
.
</code></pre>
<p><strong>Remark |</strong> I know, I've seen elegant solutions to this in Perl with roughly two lines of code. However, I want to see it in Java. </p>
<p>Edit: Oh yeah, it be helpful to show an implementation using one of these structures (in Java). </p>
| [
{
"answer_id": 302378,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 7,
"selected": true,
"text": "TreeMap HashMap TreeMap HashMap TreeMap TreeMap HashMap"
},
{
"answer_id": 302402,
"author": "JodaStephen",
"author_id": 38896,
"author_profile": "https://Stackoverflow.com/users/38896",
"pm_score": 4,
"selected": false,
"text": "bag.add(\"big\")\nbag.add(\"small\")\nbag.add(\"big\")\nint count = bag.getCount(\"big\")\n"
},
{
"answer_id": 302439,
"author": "erickson",
"author_id": 3474,
"author_profile": "https://Stackoverflow.com/users/3474",
"pm_score": 2,
"selected": false,
"text": "TreeMap<String,Number> Map<String,Integer> Double Long TreeMap<String,Number> Map<String,Integer> Integer class Counter {\n\n public static void main(String... argv)\n throws Exception\n {\n FileChannel fc = new FileInputStream(argv[0]).getChannel();\n ByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());\n CharBuffer cb = Charset.defaultCharset().decode(bb);\n Pattern p = Pattern.compile(\"[^ \\t\\r\\n\\f.,!?:;\\\"()']+\");\n Map<String, Integer> counts = new TreeMap<String, Integer>();\n Matcher m = p.matcher(cb);\n while (m.find()) {\n String word = m.group();\n Integer count = counts.get(word);\n count = (count == null) ? 1 : count + 1;\n counts.put(word, count);\n }\n fc.close();\n for (Map.Entry<String, Integer> e : counts.entrySet()) {\n System.out.printf(\"%s: %d%n\", e.getKey(), e.getValue());\n }\n }\n\n}\n"
},
{
"answer_id": 5664680,
"author": "saurabh",
"author_id": 708130,
"author_profile": "https://Stackoverflow.com/users/708130",
"pm_score": 4,
"selected": false,
"text": "O(n log n) O(log n) O(log n) O(n + k log k) O(k + n log k)"
},
{
"answer_id": 10431954,
"author": "Balu",
"author_id": 1372529,
"author_profile": "https://Stackoverflow.com/users/1372529",
"pm_score": 2,
"selected": false,
"text": "import java.io.BufferedReader;\nimport java.io.DataInputStream;\nimport java.io.FileInputStream;\nimport java.io.FileNotFoundException;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.io.ObjectInputStream.GetField;\nimport java.util.Iterator;\nimport java.util.Map;\nimport java.util.StringTokenizer;\nimport java.util.TreeMap;\n\npublic class TreeMapExample {\n\n public static void main (String args[]){\n Map<String,Integer> tm = new TreeMap<String,Integer>();\n try {\n\n FileInputStream fis = new FileInputStream(\"Test.txt\");\n DataInputStream in = new DataInputStream(fis);\n BufferedReader br = new BufferedReader(new InputStreamReader(in));\n String line;\n int countValue = 1;\n while((line = br.readLine())!= null ){\n line = line.replaceAll(\"[-+.^:;,()\\\"\\\\[\\\\]]\",\"\");\n StringTokenizer st = new StringTokenizer(line, \" \"); \n while(st.hasMoreTokens()){\n String nextElement = (String) st.nextElement();\n\n if(tm.size()>0 && tm.containsKey(nextElement)){\n int val = 0;\n if(tm.get(nextElement)!= null){\n val = (Integer) tm.get(nextElement);\n val = val+1;\n }\n tm.put(nextElement, val);\n }else{\n tm.put(nextElement, 1);\n }\n\n }\n }\n for(Map.Entry<String,Integer> entry : tm.entrySet()) {\n System.out.println(entry.getKey() + \" : \" + entry.getValue());\n }\n\n } catch (FileNotFoundException e) {\n // TODO Auto-generated catch block\n e.printStackTrace();\n } catch (IOException e) {\n // TODO Auto-generated catch block\n e.printStackTrace();\n }\n }\n\n}\n"
},
{
"answer_id": 31100032,
"author": "hardeep thakur",
"author_id": 1392352,
"author_profile": "https://Stackoverflow.com/users/1392352",
"pm_score": 0,
"selected": false,
"text": "public class SortFileWords {\n\n public static void main(String[] args) {\n HashMap<String, Integer> map = new HashMap<String, Integer>();\n ValueCompare vc = new ValueCompare(map);\n TreeMap<String, Integer> sorted_map = new TreeMap<String, Integer>(map);\n List<String> list = new ArrayList<>();\n Scanner sc;\n try {\n sc = new Scanner(new File(\"c:\\\\ReadMe1.txt\"));\n while (sc.hasNext()) {\n list.add(sc.next());\n }\n sc.close();\n } catch (FileNotFoundException e) {\n e.printStackTrace();\n }\n\n for (String s : list) {\n if (map.containsKey(s)) {\n map.put(s, map.get(s) + 1);\n } else\n map.put(s, 1);\n }\n\n System.out.println(\"Unsorted map: \" + map);\n sorted_map.putAll(map);\n System.out.println(\"Sorted map on keys: \" + sorted_map);\n\n TreeMap<String, Integer> sorted_value_map = new TreeMap<>(vc);\n sorted_value_map.putAll(map);\n System.out.println(\"Sorted map on values: \" + sorted_value_map);\n }\n}\n\nclass ValueCompare implements Comparator<String> {\n\n Map<String, Integer> map;\n\n public ValueCompare(Map<String, Integer> map) {\n this.map = map;\n }\n\n @Override\n public int compare(String s1, String s2) {\n if (map.get(s1) >= map.get(s2))\n return -1;\n else\n return 1;\n }\n}\n"
},
{
"answer_id": 35802595,
"author": "Slava Vedenin",
"author_id": 4318868,
"author_profile": "https://Stackoverflow.com/users/4318868",
"pm_score": 2,
"selected": false,
"text": " Order | Guava | Apache | Eclipse(GS) | JDK analog\nββββββββββββββΌβββββββββββββββββββΌββββββββββββΌββββββββββββββΌβββββββββββββ\nNot define | HashMultiset | HashBag | HashBag | HashMap<String, Integer>\nββββββββββββββΌβββββββββββββββββββΌββββββββββββΌββββββββββββββΌβββββββββββββ\nSorted | TreeMultiset | TreeBag | TreeBag | TreeMap<String, Integer>\nββββββββββββββΌβββββββββββββββββββΌββββββββββββΌββββββββββββββΌβββββββββββββ\nLinked |LinkedHashMultiset| - | - | LinkedHashMap<String, Integere>\nββββββββββββββΌβββββββββββββββββββΌββββββββββββΌββββββββββββββΌβββββββββββββ\nConcurrent & | ConcurrentHash- |Synchroniz-|Synchroniz- | Collections.synchronizedMap(\nnot define | Multiset | edBag | edBag | HashMap<String, Integer>)\nββββββββββββββΌβββββββββββββββββββΌββββββββββββΌββββββββββββββΌβββββββββββββ\nConcurrent | - |Synchroniz-|Synchroniz- | Collections.synchronizedSorted-\nand sorted | |edSortedBag| edSortedBag | Map(TreeMap<>))\nββββββββββββββΌβββββββββββββββββββΌββββββββββββΌββββββββββββββΌβββββββββββββ\nImmutable and| ImmutableMultiset|Unmodifiab-|Unmodifiab- | Collections.unmodifiableMap(\nnot define | | leBag | leBag | HashMap<String, Integer>)\nββββββββββββββΌβββββββββββββββββββΌββββββββββββΌββββββββββββββΌβββββββββββββ\nImmutable and| ImmutableSorted- |Unmodifiab-|Unmodifiab- | Collections.unmodifiableSorted-\nsorted | Multiset |leSortedBag| leSortedBag | Map(TreeMap<String, Integer>))\nββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ\n // Parse text to separate words\n String INPUT_TEXT = \"Hello World! Hello All! Hi World!\";\n // Create Multiset\n Bag bag = SynchronizedSortedBag.synchronizedBag(new TreeBag(Arrays.asList(INPUT_TEXT.split(\" \"))));\n\n // Print count words\n System.out.println(bag); // print [1:All!,2:Hello,1:Hi,2:World!]- in natural (alphabet) order\n // Print all unique words\n System.out.println(bag.uniqueSet()); // print [All!, Hello, Hi, World!]- in natural (alphabet) order\n\n\n // Print count occurrences of words\n System.out.println(\"Hello = \" + bag.getCount(\"Hello\")); // print 2\n System.out.println(\"World = \" + bag.getCount(\"World!\")); // print 2\n System.out.println(\"All = \" + bag.getCount(\"All!\")); // print 1\n System.out.println(\"Hi = \" + bag.getCount(\"Hi\")); // print 1\n System.out.println(\"Empty = \" + bag.getCount(\"Empty\")); // print 0\n\n // Print count all words\n System.out.println(bag.size()); //print 6\n\n // Print count unique words\n System.out.println(bag.uniqueSet().size()); //print 4\n // Parse text to separate words\n String INPUT_TEXT = \"Hello World! Hello All! Hi World!\";\n // Create Multiset\n MutableSortedBag<String> bag = TreeBag.newBag(Arrays.asList(INPUT_TEXT.split(\" \")));\n\n // Print count words\n System.out.println(bag); // print [All!, Hello, Hello, Hi, World!, World!]- in natural order\n // Print all unique words\n System.out.println(bag.toSortedSet()); // print [All!, Hello, Hi, World!]- in natural order\n\n // Print count occurrences of words\n System.out.println(\"Hello = \" + bag.occurrencesOf(\"Hello\")); // print 2\n System.out.println(\"World = \" + bag.occurrencesOf(\"World!\")); // print 2\n System.out.println(\"All = \" + bag.occurrencesOf(\"All!\")); // print 1\n System.out.println(\"Hi = \" + bag.occurrencesOf(\"Hi\")); // print 1\n System.out.println(\"Empty = \" + bag.occurrencesOf(\"Empty\")); // print 0\n\n // Print count all words\n System.out.println(bag.size()); //print 6\n\n // Print count unique words\n System.out.println(bag.toSet().size()); //print 4\n // Parse text to separate words\n String INPUT_TEXT = \"Hello World! Hello All! Hi World!\";\n // Create Multiset\n Multiset<String> multiset = LinkedHashMultiset.create(Arrays.asList(INPUT_TEXT.split(\" \")));\n\n // Print count words\n System.out.println(multiset); // print [Hello x 2, World! x 2, All!, Hi]- in predictable iteration order\n // Print all unique words\n System.out.println(multiset.elementSet()); // print [Hello, World!, All!, Hi] - in predictable iteration order\n\n // Print count occurrences of words\n System.out.println(\"Hello = \" + multiset.count(\"Hello\")); // print 2\n System.out.println(\"World = \" + multiset.count(\"World!\")); // print 2\n System.out.println(\"All = \" + multiset.count(\"All!\")); // print 1\n System.out.println(\"Hi = \" + multiset.count(\"Hi\")); // print 1\n System.out.println(\"Empty = \" + multiset.count(\"Empty\")); // print 0\n\n // Print count all words\n System.out.println(multiset.size()); //print 6\n\n // Print count unique words\n System.out.println(multiset.elementSet().size()); //print 4\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/302371",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/38696/"
] |
302,379 | <p>Okay, this bugged me for several years, now. If you sucked in statistics and higher math at school, turn away, <em>now</em>. Too late.</p>
<p>Okay. Take a deep breath. Here are the rules. Take <em>two</em> thirty sided dice (yes, <a href="http://paizo.com/store/byCompany/k/koplow/dice/d30" rel="nofollow noreferrer">they do exist</a>) and roll them simultaneously.</p>
<ul>
<li>Add the two numbers</li>
<li>If both dice show <= 5 or >= 26, throw again and <em>add</em> the result to what you have</li>
<li>If one is <= 5 and the other >= 26, throw again and <em>subtract</em> the result from what
you have</li>
<li>Repeat until either is > 5 and < 26!</li>
</ul>
<p>If you write some code (see below), roll those dice a few million times and you count how often you receive each number as the final result, you get a curve that is pretty flat left of 1, around 45Β° degrees between 1 and 60 and flat above 60. The chance to roll 30.5 or better is greater than 50%, to roll better than 18 is 80% and to roll better than 0 is 97%.</p>
<p>Now the question: Is it possible to write a program to <em>calculate</em> the <em>exact</em> value f(x), i.e. the probability to roll a certain value?</p>
<p>Background: For our role playing game "Jungle of Stars" we looked for a way to keep random events in check. The rules above guarantee a much more stable outcome for something you try :)</p>
<p>For the geeks around, the code in Python:</p>
<pre><code>import random
import sys
def OW60 ():
"""Do an open throw with a "60" sided dice"""
val = 0
sign = 1
while 1:
r1 = random.randint (1, 30)
r2 = random.randint (1, 30)
#print r1,r2
val = val + sign * (r1 + r2)
islow = 0
ishigh = 0
if r1 <= 5:
islow += 1
elif r1 >= 26:
ishigh += 1
if r2 <= 5:
islow += 1
elif r2 >= 26:
ishigh += 1
if islow == 2 or ishigh == 2:
sign = 1
elif islow == 1 and ishigh == 1:
sign = -1
else:
break
#print sign
#print val
return val
result = [0] * 2000
N = 100000
for i in range(N):
r = OW60()
x = r+1000
if x < 0:
print "Too low:",r
if i % 1000 == 0:
sys.stderr.write('%d\n' % i)
result[x] += 1
i = 0
while result[i] == 0:
i += 1
j = len(result) - 1
while result[j] == 0:
j -= 1
pSum = 0
# Lower Probability: The probability to throw this or less
# Higher Probability: The probability to throw this or higher
print "Result;Absolut Count;Probability;Lower Probability;Rel. Lower Probability;Higher Probability;Rel. Higher Probability;"
while i <= j:
pSum += result[i]
print '%d;%d;%.10f;%d;%.10f;%d;%.10f' % (i-1000, result[i], (float(result[i])/N), pSum, (float(pSum)/N), N-pSum, (float(N-pSum)/N))
i += 1
</code></pre>
| [
{
"answer_id": 305649,
"author": "ShreevatsaR",
"author_id": 4958,
"author_profile": "https://Stackoverflow.com/users/4958",
"pm_score": 4,
"selected": true,
"text": "def OW60(sign=1):\n r1 = random.randint (1, 30)\n r2 = random.randint (1, 30)\n val = sign * (r1 + r2)\n\n islow = (r1<=5) + (r2<=5)\n ishigh = (r1>=26) + (r2>=26)\n\n if islow == 2 or ishigh == 2:\n return val + OW60(1)\n elif islow == 1 and ishigh == 1:\n return val + OW60(-1)\n else:\n return val\n F(x) = the probability that OW60(1) returns a value β€ x.\n G(x) = the probability that OW60(-1) returns a value β€ x.\n F(x) = (1/900)(2+F(x-2) + 3+F(x-3) + ... + 59+F(x-59) + 60+F(x-60))\n G(x) = (1/900)(-2+F(x-2) + (-3)+F(x-3) + ... + (-59)+F(x-59) + (-60)+F(x-60))\n V(x) = [F(x-60) G(x-60) ... F(x-2) G(x-2) F(x-1) G(x-1) F(x) G(x)]\n V(x) = A*V(x-1) + B\n"
},
{
"answer_id": 3435254,
"author": "Stefano Palazzo",
"author_id": 379799,
"author_profile": "https://Stackoverflow.com/users/379799",
"pm_score": 2,
"selected": false,
"text": "Median: 17 (+18, -?) # This result is meaningless\nArithmetic Mean: 31.0 (Β±0.1)\nStandard Deviation: 21 (+1, -2)\nRoot Mean Square: 35.4 (Β±0.7)\nMode: 36 (seemingly accurate)\n Median: 30.5\nArithmetic Mean: 30.5\nStandard Deviation: 7.68114574787\nRoot Mean Square: 35.0737318611\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/302379",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34088/"
] |
302,381 | <p>There's an in-house program we use and it's stored on a UNC share so that updates are transparent. I'd like to supply it some command line parameters like so:</p>
<pre><code>\\server\share\in_house_thingy.exe myusername mypassword
</code></pre>
<p>But I can't seem to get it to work in either CMD or PowerShell or via a shortcut.</p>
<p>Anyone got any ideas?</p>
| [
{
"answer_id": 305407,
"author": "Steven Murawski",
"author_id": 1233,
"author_profile": "https://Stackoverflow.com/users/1233",
"pm_score": 3,
"selected": false,
"text": "$app = '\\\\server\\share\\in_house_thingy.exe'\n$arguments = 'myusername mypassword'\n$process = [System.Diagnostics.Process]::Start($app, $arguments)\n"
},
{
"answer_id": 306256,
"author": "Orihara",
"author_id": 456628,
"author_profile": "https://Stackoverflow.com/users/456628",
"pm_score": 3,
"selected": true,
"text": "\"\\\\server\\share\\in_house_thingy.exe\" myusername mypassword\n"
},
{
"answer_id": 829432,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "%~dp0 \\ \\ $0 = $myInvocation.MyCommand.Definition\n$dp0 = [System.IO.Path]::GetDirectoryName($0)\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/302381",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/549/"
] |
302,393 | <p>I'm just starting out with WiX as I need to be able to automate building an MSI on our CI server. Is there anyway to automatically include all the dependencies of a project?</p>
| [
{
"answer_id": 18517549,
"author": "Eric Craeymeersch",
"author_id": 2730260,
"author_profile": "https://Stackoverflow.com/users/2730260",
"pm_score": 2,
"selected": false,
"text": "call \"$(ProjectDir)GenerateDependency.bat\" \"$(SolutionDir)\" \"$(ProjectDir)Dependencies.wxs\"\n @echo off\nset SOLUTIONDIR=%1\nset OUTPUTFILE=%2\necho Starting Dependency check...\necho ^<?xml version=\"1.0\" encoding=\"UTF-8\"?^> > %OUTPUTFILE%\necho ^<Wix xmlns=\"http://schemas.microsoft.com/wix/2006/wi\"^> >> %OUTPUTFILE%\necho ^<Fragment^> >> %OUTPUTFILE%\necho ^<ComponentGroup Id=\"MesDependance\" Directory=\"INSTALLFOLDER\"^> >> %OUTPUTFILE%\n\nfor %%F in (%SOLUTIONDIR%WixServiceInstallerExample\\bin\\Debug\\*.dll) do (\n echo \"-- Adding %%~nxF\" \n echo ^<Component Id=\"%%~nF\"^> >> %OUTPUTFILE%\n echo ^<File Id=\"%%~nF\" Name=\"%%~nxF\" Source=\"%%~dpnxF\" Vital=\"yes\" KeyPath=\"yes\" DiskId=\"1\"/^> >> %OUTPUTFILE%\n echo ^</Component^> >> %OUTPUTFILE%\n)\necho ^</ComponentGroup^> >> %OUTPUTFILE%\necho ^</Fragment^> >> %OUTPUTFILE%\necho ^</Wix^> >> %OUTPUTFILE%\necho Dependency check done.\n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/302393",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5802/"
] |
302,399 | <p>Somehow my iPhone Simulator is unable to play sounds. First an app I'm working on using <code>AudioServicesPlaySystemSound()</code> stopped working.. I spent a while debugging this but sound is still working on the iPhone when I run the app on the device. I get the same results with other iPhone apps such as the sample Crash Landing app.</p>
<p>I can't find a sound setting anywhere in the simulator or Xcode preferences. I've tried resetting the simulator through "Reset Content and Settings" menu item to no avail.</p>
| [
{
"answer_id": 303102,
"author": "Marc Novakowski",
"author_id": 27020,
"author_profile": "https://Stackoverflow.com/users/27020",
"pm_score": 2,
"selected": false,
"text": "AudioSessionInitialize kAudioSessionProperty_AudioCategory AudioSessionSetProperty kAudioSessionCategory_MediaPlayback AudioSessionSetActive(YES)"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/302399",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/72/"
] |
302,409 | <p>Delphi strings use single quotes, for example '<code>a valid string</code>'. How does one specify the <code>'</code> character within a literal string? How would one refer to the null byte (Unicode code point <code>U+0000</code>)? </p>
| [
{
"answer_id": 302431,
"author": "Jamie",
"author_id": 922,
"author_profile": "https://Stackoverflow.com/users/922",
"pm_score": 7,
"selected": true,
"text": "' str := '''test string''';\nWriteln(str)\n # str := 'Newline' + #13 + #10 \n str := 'Newline'#13#10\n"
},
{
"answer_id": 302437,
"author": "vrad",
"author_id": 12891,
"author_profile": "https://Stackoverflow.com/users/12891",
"pm_score": 3,
"selected": false,
"text": "' 'Don''t'"
},
{
"answer_id": 302485,
"author": "Toon Krijthe",
"author_id": 18061,
"author_profile": "https://Stackoverflow.com/users/18061",
"pm_score": 4,
"selected": false,
"text": "#$0000 \n"
}
] | 2008/11/19 | [
"https://Stackoverflow.com/questions/302409",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2892/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.