qid
int64
4
19.1M
question
stringlengths
18
48.3k
answers
list
date
stringlengths
10
10
metadata
list
280,449
<p>I have a page on which I must load controls dynamically based on the user selection. Let's say that I have something like this:</p> <pre><code>public static readonly Dictionary&lt;string, string&gt; DynamicControls = new Dictionary&lt;string, string&gt; { { "UserCtrl1", "~/Controls/UserCtrl1.ascx" }, { "UserCtrl2", "~/Controls/UserCtrl2.ascx" }, { "UserCtrl3", "~/Controls/UserCtrl3.ascx" }, { "UserCtrl4", "~/Controls/UserCtrl4.ascx"} }; </code></pre> <p>Now let's say than on the page where the controls are loaded the code is something like this:</p> <pre><code>protected void Page_Load(object sender, EventArgs e) { SomePanel.Controls.Add(GetControl()); } private Control GetControl() { string dynamicCtrl = CurrentItem.DynamicControl; string path = SomeClass.DynamicControls[dynamicCtrl]; Control ctrl = null; //TODO: find a better way to load the controls switch (dynamicCtrl) { case "UserCtrl1": { ctrl = (UserCtrl1)LoadControl(path); } break; case "UserCtrl2": { ctrl = (UserCtrl2)LoadControl(path); } break; case "UserCtrl3": { ctrl = (UserCtrl3)LoadControl(path); } break; default: { throw new ApplicationException("Invalid dynamic control added."); } } return ctrl; } </code></pre> <p>The page has the required registered statements. Any idea how I can get rid of this ugly switch statement?</p>
[ { "answer_id": 280470, "author": "Magnus", "author_id": 4184, "author_profile": "https://Stackoverflow.com/users/4184", "pm_score": 4, "selected": true, "text": "private Control GetControl()\n{\n string dynamicCtrl = CurrentItem.DynamicControl;\n string path = SomeClass.DynamicControls[dynamicCtrl];\n\n Control ctrl = LoadControl(path); \n\n return ctrl;\n}\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280449", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2099426/" ]
280,457
<p>I have a game in which you can score from -40 to +40 on each match. Users are allowed to play any number of matches. I want to calculate a total score that implicitly takes into account the number of matches played.</p> <p>Calculating only the average is not fair. For example, if Peter plays four games and gets 40 points on each match, he will have the same total score as Janne who played only one match with 40 points.</p> <p>Adding up the match scores isn't fair either. Peter plays 2 games (40 points on each match), total score 80. Janne plays 8 games (10 points on each match), total score 80.</p> <p>Is there a (simple) and fair way to calculate the total score? I have read about the Elo &amp; Glicko system for chess ratings, but both are based upon a players rating history and the opponents rating. </p>
[ { "answer_id": 281407, "author": "dreeves", "author_id": 4234, "author_profile": "https://Stackoverflow.com/users/4234", "pm_score": 2, "selected": false, "text": "SE = sqrt((ss - s^2/n) / (n-1) / n)\n s/n - SE\n d i d^(i-1)" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280457", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
280,472
<p>I need to make some changes to a ClickOnce application that I haven't touched for over a year and therefore the certificate has expired.</p> <p>I've read that publishing with a new certificate will make the application fail, because it will be signed with a different key.</p> <p>Therefore I think I need to use the same certificate but not sure how to renew it.</p>
[ { "answer_id": 54120387, "author": "Sogger", "author_id": 579234, "author_profile": "https://Stackoverflow.com/users/579234", "pm_score": 3, "selected": false, "text": " [DllImport(\"crypt32.dll\", CharSet = CharSet.Auto)]\n- internal static extern int CertNameToStr(X509Encoding dwCertEncodingType, ref CRYPT_DATA_BLOB pName, CertNameType dwStrType, ref string psz, int csz);\n+ internal static extern int CertNameToStr(X509Encoding dwCertEncodingType, ref CRYPT_DATA_BLOB pName, CertNameType dwStrType, [In, Out] char[] psz, int csz);\n - //var buffer = new char[1024];\n- string buffer = new string('\\0', 1024);\n+ char[] buffer = new char[1024];\n+ //string buffer = new string('\\0', 1024);\n int d;\n- if ((d = Crypt.CertNameToStr(Crypt.X509Encoding.ASN_Encodings, ref certNameBlob, Crypt.CertNameType.CERT_X500_NAME_STR, ref buffer, 1024 * sizeof(char))) != 0)\n+ if ((d = Crypt.CertNameToStr(Crypt.X509Encoding.ASN_Encodings, ref certNameBlob, Crypt.CertNameType.CERT_X500_NAME_STR, buffer, 1024 * sizeof(char))) != 0)\n \"[path-to-renew-cert-proj-dir\\bin\\Debug\\]renewCert.exe\" [old-cert-path\\]old_cert_name.pfx [new-cert-path\\]new_cert_name.pfx\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280472", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11989/" ]
280,485
<p>We have a DLL which is produced in house, and for which we have the associated static LIB of stubs.</p> <p>We also have an EXE which uses this DLL using the simple method of statically linking to the DLL's LIB file (ie, not manually using LoadLibrary).</p> <p>When we deploy the EXE we'd like the DLL file name to be changed for obfuscation reasons (at customer's request).</p> <p><strong>How can we do this so that our EXE still finds the DLL automagically?</strong></p> <p>I have tried renaming the DLL and LIB files (after they were built to their normal name), then changing the EXE project settings to link with the renamed LIB. This fails at runtime, as I guess the name of the DLL is baked into the LIB file, and not simply guessed at by the linker replacing ".lib" with ".dll".</p> <p>In general, we do not want to apply this obfuscation to all uses of the DLL, so we'd like to keep the current DLL project output files are they are.</p> <p>I'm hoping that there will be a method whereby we can edit the DLL's LIB file, and replace the hardcoded name of the DLL file with something else. In which case this could be done entirely within the EXE project (perhaps as a pre-build step).</p> <hr> <p><strong>Update</strong>: I find that Delay Loading does not work, as my DLL contains exported C++ classes. See <a href="http://www.tech-archive.net/Archive/VC/microsoft.public.vc.language/2004-09/0377.html" rel="noreferrer">this article</a>.</p> <p>Are there any alternatives?</p>
[ { "answer_id": 280567, "author": "wimh", "author_id": 33499, "author_profile": "https://Stackoverflow.com/users/33499", "pm_score": 4, "selected": false, "text": "dumpbin /exports ws2_32.dll LIBRARY WS2_32\nEXPORTS\n accept @1\n bind @2\n closesocket @3\n connect @4\n LIB /MACHINE:x86 /def:ws2_32.def dumpbin /exports ws2_32.lib" }, { "answer_id": 281011, "author": "QAZ", "author_id": 14260, "author_profile": "https://Stackoverflow.com/users/14260", "pm_score": 4, "selected": false, "text": "FARPROC WINAPI delayHook( unsigned dliNotify, PDelayLoadInfo pdli )\n{\n switch( dliNotify )\n {\n case dliNotePreLoadLibrary:\n if( strcmp( pdli->szDll, \"origional.dll\" ) == 0 )\n return (FARPROC)LoadLibrary( \"renamed.dll\" );\n break;\n default:\n return NULL;\n }\n\n return NULL;\n}\n" }, { "answer_id": 285867, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "enum ukOverwrite {dontOverwriteAnything = 0, overwriteWhateverPresent = 1};\nvoid unpackResource (ukOverwrite param1, int resourceID, const char* basePath, \nconst char* endFilename)\n{\n char* lpName = 0;\n lpName += resourceID;\n HRSRC MrResource = FindResource (0, lpName, \"file\");\n\n if (MrResource)\n {\n HGLOBAL loadedResource = LoadResource (0, MrResource);\n if (loadedResource)\n {\n void* lockedResource = LockResource (loadedResource);\n if (lockedResource)\n {\n DWORD size = SizeofResource (0, MrResource);\n if (size)\n {\n unsigned long creationDisposition = CREATE_NEW;\n if (param1 == overwriteWhateverPresent)\n creationDisposition = CREATE_ALWAYS;\n\n char filepath [MAX_PATH];\n strcpy (filepath, basePath);\n strcat (filepath, endFilename);\n HANDLE rabbit = CreateFile (filepath, GENERIC_WRITE, 0, 0, \ncreationDisposition, 0, 0);\n if (rabbit != INVALID_HANDLE_VALUE)\n {\n DWORD numBytesWritten = 0;\n int wf = WriteFile (rabbit, lockedResource, size, &numBytesWritten, \n0);\n CloseHandle (rabbit);\n }\n }\n }\n FreeResource (loadedResource);\n }\n }\n}\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280485", "https://Stackoverflow.com", "https://Stackoverflow.com/users/755/" ]
280,488
<p>I'm looking to convert the following <code>mod_rewrite</code> rule to the <a href="http://wiki.codemongers.com/NginxHttpRewriteModule" rel="noreferrer">Nginx equivalent</a>:</p> <pre><code>RewriteRule ^foo/(.*)$ /bar/index.php?title=$1 [PT,L,QSA] RewriteRule ^foo/*$ /bar/index.php [L,QSA] </code></pre> <p>So far I have:</p> <pre><code>rewrite ^foo/(.*)$ /bar/index.php?title=$1&amp;$query_string last; rewrite ^foo/?$ /bar/index.php?$query_string break; </code></pre> <p>The problem is (I think!) that the query string doesn't get appended. I haven't found a way to port the <code>QSA</code> argument to Nginx.</p>
[ { "answer_id": 282437, "author": "jumoel", "author_id": 1555170, "author_profile": "https://Stackoverflow.com/users/1555170", "pm_score": 4, "selected": true, "text": "rewrite ^/foo/([^?]*)(?:\\?(.*))? /bar/index.php?title=$1&$2;\nrewrite ^/foo /bar/index.php;\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280488", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1555170/" ]
280,494
<p>I have a group by clause in a sql statement and need to use an aggregate function to minus all the values in each group instead of adding like the Sum() function.</p> <p>i.e. </p> <pre><code>SELECT Sum(A) FROM ( SELECT 2 AS A UNION SELECT 1) AS t1 </code></pre> <p>..so will evaluate 2+1 and return 3.</p> <p>I need some way of doing 2-1 to return 1.</p> <p>Hope this makes sense. Only way I can think of doing this would be to use CLR integration to make my own aggregate function.</p> <p>Any other ideas?</p>
[ { "answer_id": 280496, "author": "Unsliced", "author_id": 2902, "author_profile": "https://Stackoverflow.com/users/2902", "pm_score": 2, "selected": false, "text": "SUM() -1 select top 1 @var = [value]\nfrom myTable \norder by [some condition] \n\nselect @minused = (2 * @var) - sum([value]) \nfrom myTable \n" }, { "answer_id": 280503, "author": "FlySwat", "author_id": 1965, "author_profile": "https://Stackoverflow.com/users/1965", "pm_score": 0, "selected": false, "text": "SELECT Sum(A) \nFROM ( \n SELECT (2 * -1) AS A\n UNION \n SELECT (1)) AS t1\n" }, { "answer_id": 280546, "author": "Ben Dowling", "author_id": 36191, "author_profile": "https://Stackoverflow.com/users/36191", "pm_score": 2, "selected": false, "text": "SELECT primary_key AS pk, field FROM table LIMIT 1;\n SELECT SUM(field) FROM table WHERE primary_key != pk;\n" }, { "answer_id": 281080, "author": "Steve Bosman", "author_id": 4389, "author_profile": "https://Stackoverflow.com/users/4389", "pm_score": 2, "selected": false, "text": "SELECT SUM(CASE WHEN ROWNUM=1 THEN 2*A ELSE -A END) \nFROM foo\n SELECT SUM(b) \nFROM (\n SELECT CASE WHEN ROWNUM=1 THEN 2*a ELSE -a END AS b\n FROM foo\n ORDER BY ???\n);\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280494", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11989/" ]
280,495
<p>When browsing ASP.NET MVC source code in <a href="http://www.codeplex.com/aspnet/SourceControl/FileView.aspx?itemId=266503&amp;changeSetId=17272" rel="noreferrer">codeplex</a>, I found it is common to have a class explicitly implementing interface. The explicitly implemented method/property then invoke another "protected virtual" method/property with same name.</p> <p>For example, </p> <pre><code>public class MvcHandler : IHttpHandler, IRequiresSessionState { protected virtual bool IsReusable { get { return false; } } bool IHttpHandler.IsReusable { get { return IsReusable; } } } </code></pre> <p>I'm now sure what's the benefit of this kind of programming. For me, I prefer to just implicitly implement the interface IHttpHandler.</p> <p>I guess the author just don't want <strong>MvcHandler</strong> has a public property <strong>IsResuable</strong>. The property <strong>IsReusable</strong> can only be used when instance of <strong>MvcHandler</strong> is treated as a <strong>IHttpHandler</strong>. Still, I'm not sure why the author what this way.</p> <p>Anybody know more benefits about this style of interface implementation?</p>
[ { "answer_id": 280505, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 5, "selected": true, "text": "ICloneable DbCommand class Foo : ICloneable\n{\n public Foo Clone() { return CloneCore(); }\n object ICloneable.Clone() { return CloneCore(); }\n protected virtual Foo CloneCore() { ... }\n}\n\nclass Bar : Foo\n{\n protected override Foo CloneCore() { ... }\n public new Bar Clone() { return (Bar)CloneCore(); }\n}\n override new class A\n{\n public virtual A SomeMethod() { ... }\n}\nclass B : A\n{\n public override A SomeMethod() { ... }\n //Error 1 Type 'B' already defines a member called 'SomeMethod' with the same parameter types\n public new B SomeMethod() { ... }\n}\n CloneCore()" }, { "answer_id": 12096386, "author": "Mohammad Nikravan", "author_id": 252229, "author_profile": "https://Stackoverflow.com/users/252229", "pm_score": 1, "selected": false, "text": "public interface IFoo\n{\n void method1();\n void method2();\n}\n\npublic class Foo : IFoo\n{\n // you can't declare explicit implemented method as public\n void IFoo.method1() \n {\n }\n\n public void method2()\n {\n }\n\n private void test()\n {\n var foo = new Foo();\n foo.method1(); //ERROR: not accessible because foo is object instance\n method1(); //ERROR: not accessible because foo is object instance\n foo.method2(); //OK\n method2(); //OK\n\n IFoo ifoo = new Foo();\n ifoo.method1(); //OK, because ifoo declared as interface\n ifoo.method2(); //OK\n }\n}\n" }, { "answer_id": 14185580, "author": "supercat", "author_id": 363751, "author_profile": "https://Stackoverflow.com/users/363751", "pm_score": 2, "selected": false, "text": "IFoo.Bar IFoo.Bar IFoo.Bar ((IFoo)this).Bar() IFoo.Bar ((IFoo)(BaseType)this).bar IFoo.Bar override void IFoo.Bar Overrides Sub Explicit_IFoo_Bar() IFoo.Bar IFoo.Bar Protected Overridable Sub IFoo_Bar() Implements IFoo.Bar" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280495", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26349/" ]
280,497
<p>I am having a peculiar problem with the order in which FlowLayoutPanels are added in to the form's <strong>controls</strong> property. This is what I tried,</p> <p>I added 7 FlowLayoutPanels in to a C# window application from left to right in vertical strips. Then I tagged the flow layouts as 1, 2, 3, ... 7 again from left to right. Now in the load handler of the form, I wrote the following snippet,</p> <pre><code> foreach (FlowLayoutPanel aDaysControl in this.Controls) { MessageBox.Show(aDaysControl.Tag.ToString()); } </code></pre> <p>I expected messages to appear in the order of <strong>1, 2, ... 7</strong>. But I got it in the reverse order (7, 6, ...1). Could some one help me out with the mistake I did ??</p> <p>Reason behind preserving the order,</p> <blockquote> <p>I am trying to make a calendar control with each row representing a day. If a month starts from Wednesday, then I need to add a empty label to the first(Monday) and the second(Tuesday) row. So the order matters a bit</p> </blockquote>
[ { "answer_id": 280517, "author": "Steve Morgan", "author_id": 5806, "author_profile": "https://Stackoverflow.com/users/5806", "pm_score": 0, "selected": false, "text": "FlowLayoutPanel[] panels = new FlowLayoutPanel[7];\n\nforeach(FlowLayoutPanel panel in this.Controls)\n{\n panels[(int)panel.Tag] = panel;\n}\n\n// Now, you can reference the panels directly by subscript:\n\npanels[2].BackColor = Color.Aquamarine;\n" }, { "answer_id": 280525, "author": "Hath", "author_id": 5186, "author_profile": "https://Stackoverflow.com/users/5186", "pm_score": 1, "selected": false, "text": " // \n // Form1\n // \n this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);\n this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;\n this.ClientSize = new System.Drawing.Size(658, 160);\n this.Controls.Add(this.flowLayoutPanel7);\n this.Controls.Add(this.flowLayoutPanel6);\n this.Controls.Add(this.flowLayoutPanel5);\n this.Controls.Add(this.flowLayoutPanel4);\n this.Controls.Add(this.flowLayoutPanel3);\n this.Controls.Add(this.flowLayoutPanel2);\n this.Controls.Add(this.flowLayoutPanel1);\n this.Name = \"Form1\";\n this.Text = \"Form1\";\n this.ResumeLayout(false);\n var flowpanelinOrder = from n in this.Controls.Cast<Control>()\n where n is FlowLayoutPanel\n orderby int.Parse(n.Tag.ToString())\n select n;\n\n /* non linq\n List<Control> flowpanelinOrder = new List<Control>();\n foreach (Control c in this.Controls)\n {\n if (c is FlowLayoutPanel) flowpanelinOrder.Add(c); \n }\n flowpanelinOrder.Sort();\n * */\n\n foreach (FlowLayoutPanel aDaysControl in flowpanelinOrder)\n {\n MessageBox.Show(aDaysControl.Tag.ToString());\n }\n" }, { "answer_id": 8157734, "author": "ispiro", "author_id": 939213, "author_profile": "https://Stackoverflow.com/users/939213", "pm_score": 4, "selected": false, "text": "SetChildIndex this.Controls.SetChildIndex(button1, 0);" }, { "answer_id": 12167665, "author": "nawfal", "author_id": 661933, "author_profile": "https://Stackoverflow.com/users/661933", "pm_score": 1, "selected": false, "text": "public static List<Control> ToControlsSorted(this Control panel)\n{\n var controls = panel.Controls.OfType<Control>().ToList();\n controls.Sort((c1, c2) => c1.TabIndex.CompareTo(c2.TabIndex));\n return controls;\n}\n foreach (FlowLayoutPanel aDaysControl in this.ToControlsSorted())\n{\n MessageBox.Show(aDaysControl.TabIndex.ToString());\n}\n TabIndex Tag" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280497", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
280,515
<p>I need to implement a queue using table. The business requirement is to have a single queue which will be accessed by 5-10 boxes to get the next job/jobs. There will not be more than 5000 jobs per day. Also, a batch of jobs should be "dequeued" at one time.</p> <p>Just wondering what are the problem areas and issues I might run into as I havent done it before. If anyone has faced this/done this before, can you please point me to a design/sample implementation or issues that need to be taken care of.</p> <p>Thanks</p>
[ { "answer_id": 280738, "author": "Vegard Larsen", "author_id": 1606, "author_profile": "https://Stackoverflow.com/users/1606", "pm_score": 2, "selected": false, "text": "UPDATE tblQueue SET mark = <unique application id> WHERE mark IS NULL ORDER BY timestamp ASC LIMIT 1\nSELECT * FROM tblQueue WHERE mark = <unique app id>\nDELETE FROM tblQueue WHERE mark = <unique app id>\n" }, { "answer_id": 280944, "author": "Tequila Guy", "author_id": 36494, "author_profile": "https://Stackoverflow.com/users/36494", "pm_score": 0, "selected": false, "text": "[GetNextItemsInQueue]" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280515", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36494/" ]
280,539
<p>As far as I understand, if I want to get my database under source control then I need to be checking in change scripts for each change and then running them from some revision to get the correct DB.</p> <p>I am trying to make a batch file that will be checked in too, that allows other developers on the team to re-build the DB locally without too much trouble. I believe sqlcmd is the way to achieve this. I have it setup to enumerate all files in the dir of .sql files and run sqlcmd for each.</p> <p>My question is who has done this before and do you have an advice on the best way to achieve this? Is the way I intend to do this the best way or is there a better way?</p> <p>Hope that's not too vague.</p> <p>Thanks in advance,</p> <p>Martin.</p>
[ { "answer_id": 280547, "author": "kristof", "author_id": 3241, "author_profile": "https://Stackoverflow.com/users/3241", "pm_score": 0, "selected": false, "text": ":: Parameters Required:\n:: %1 UserID\n:: %2 Password\n:: %3 Server\n:: %4 Database\n:: %5 file with scripted object\n::\necho. >> CreateDBObjectsLog.txt\necho %5 >> CreateDBObjectsLog.txt\nosql -U%1 -P%2 -S%3 -i%5 -d%4 -n >> CreateDBObjectsLog.txt\necho * %5\n :: Parameters Required:\n:: %1 UserID\n:: %2 Password\n:: %3 Server\n:: %4 Database\n::\necho object in %4 database on %3 server\necho Please Wait ...\n\nif exist CreateDBObjectsLog.txt del CreateDBObjectsLog.txt\n\n\ncall createDBObject.bat %1, %2, %3, %4, ScriptedTable1\ncall createDBObject.bat %1, %2, %3, %4, ScriptedTable2\n...\ncall createDBObject.bat %1, %2, %3, %4, ScriptedTableN\n\ncall createDBObject.bat %1, %2, %3, %4, ScriptedView1\n\ncall createDBObject.bat %1, %2, %3, %4, ScriptedSP1\n\netc\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280539", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
280,542
<p>I'm regularly creating an XSD schema by transforming a proprietary data model of a legacy system. This works out pretty good. However, the legacy system only allows me to specify very basic attributes of a parameter, such as the data type (<code>int</code>, <code>string</code> etc.).</p> <p>I would like to enhance the XSL transformation with a mechanism that allows me to add meta data in order to provide more details for the transformation. I thought of something like the Java properties notation to assign attributes to an XPath. </p> <p>Imagine the following example:</p> <p><strong>legacy system data model</strong> (actually that neat, but best suited for demonstration purposes)</p> <pre><code>&lt;datamodel&gt; &lt;customer&gt; &lt;firstName type="string"/&gt; &lt;lastName type="string"/&gt; &lt;age type="int"&gt; &lt;customer&gt; &lt;/datamodel&gt; </code></pre> <p><strong>meta data</strong></p> <pre><code>customer/firstName/@nillable=false customer/lastName/@nillable=false customer/age/@nillable=true customer/firstName/@minOccurs=1 customer/firstName/@maxOccurs=1 customer/lastName/@minOccurs=1 customer/lastName/@maxOccurs=1 </code></pre> <p><strong>resulting XSD schema</strong></p> <pre><code>... &lt;xs:complexType name="customerType"&gt; &lt;xs:sequence&gt; &lt;xs:element name="firstName" type="xs:string" nillable="false" minOccurs="1" maxOccurs="1"/&gt; &lt;xs:element name="lastName" type="xs:string" nillable="false" minOccurs="1" maxOccurs="1"/&gt; &lt;xs:element name="age" type="xs:int" nillable="true"/&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; ... </code></pre> <p>What do you think of that? Is there a way to include meta data into an XSL stylesheet?</p>
[ { "answer_id": 286272, "author": "Dimitre Novatchev", "author_id": 36305, "author_profile": "https://Stackoverflow.com/users/36305", "pm_score": 3, "selected": true, "text": "<datamodel xmlns:nm=\"my:new.meta\">\n <customer>\n <firstName type=\"string\"\n nm:nillable=\"false\"\n nm:minOccurs=\"1\"\n nm:maxOccurs=\"1\"\n />\n <lastName type=\"string\"\n nm:nillable=\"false\"\n nm:minOccurs=\"1\"\n nm:maxOccurs=\"1\"\n />\n <age type=\"int\" nm:nillable=\"true\"/>\n </customer>\n</datamodel>\n <xsl:variable> <newProperties xmlns:nm=\"my:new.meta\">\n <customer>\n <firstName nm:nillable=\"false\"\n nm:minOccurs=\"1\"\n nm:maxOccurs=\"1\"\n />\n <lastName nm:nillable=\"false\"\n nm:minOccurs=\"1\"\n nm:maxOccurs=\"1\"\n />\n <age nm:nillable=\"true\"/>\n </customer>\n</newProperties>\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280542", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25842/" ]
280,551
<p>I try get the <a href="http://flash-mp3-player.net/players/js/" rel="nofollow noreferrer">mp3 flash player</a> to work with my javascript on all browsers. All went well for first, but fast realized that my code doesn't work on MSIE.</p> <p>After trying to find out I found this in the reference code:</p> <pre><code>&lt;!--[if IE]&gt; &lt;script type="text/javascript" event="FSCommand(command,args)" for="myFlash"&gt; eval(args); &lt;/script&gt; &lt;![endif]--&gt; </code></pre> <p>How to turn this into a javascript or jquery clause that I could stuff it where it belongs to (in audio.js)?</p>
[ { "answer_id": 4434557, "author": "Troels", "author_id": 541245, "author_profile": "https://Stackoverflow.com/users/541245", "pm_score": 1, "selected": false, "text": "<script type=\"text/javascript\" event=\"FSCommand(command,args)\" for=\"myFlash\">\n eval(args);\n</script>\n function foo(command, args){\n eval(args);\n}\nvar ie_sucks = document.getElementById('myFlash');\nie_sucks.attachEvent(\"FSCommand\", foo);\n" }, { "answer_id": 6835723, "author": "Eugene Bos", "author_id": 792870, "author_profile": "https://Stackoverflow.com/users/792870", "pm_score": 1, "selected": false, "text": "var ie_sucks = document.getElementById('comebacker_audio');\nie_sucks.attachEvent(\"FSCommand\", function(command, args) {eval(args);});\n" }, { "answer_id": 11035610, "author": "Oliver Moran", "author_id": 681800, "author_profile": "https://Stackoverflow.com/users/681800", "pm_score": 0, "selected": false, "text": "<script type=\"text/javascript\">\n function mySwf_DoFSCommand(command, args) {\n // do stuff\n }\n</script>\n\n<!--[if IE]>\n<script type=\"text/javascript\" event=\"FSCommand(command,args)\" for=\"mySwf\">\n mySwf_DoFSCommand(command, args);\n</script>\n<![endif]-->\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280551", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21711/" ]
280,559
<p>This is probably easy but I am getting stuck: when I build a solution in Visual Studio - how do extract the exact cmd line for the current build command in order to be able to do the same build from VisualStudio console? </p> <p>In the output window I can see the single projects in the solution build commands but not the one for the whole solution.</p> <p>I am on VS2005.</p> <p>Any help would be appreciated</p>
[ { "answer_id": 280584, "author": "kenny", "author_id": 3225, "author_profile": "https://Stackoverflow.com/users/3225", "pm_score": 5, "selected": true, "text": "%comspec% /k \"\"C:\\Program Files\\Microsoft Visual Studio 8\\VC\\vcvarsall.bat\"\"x86\"\n @echo off\n\n:: setup VS2005 command line build environment\nset VSINSTALLDIR=C:\\Program Files\\Microsoft Visual Studio 8\nset VCINSTALLDIR=C:\\Program Files\\Microsoft Visual Studio 8\\VC\nset FrameworkDir=C:\\WINDOWS\\Microsoft.NET\\Framework\nset FrameworkVersion=v2.0.50727\nset FrameworkSDKDir=C:\\Program Files\\Microsoft Visual Studio 8\\SDK\\v2.0\nset DevEnvDir=C:\\Program Files\\Microsoft Visual Studio 8\\Common7\\IDE\nset PATH=C:\\Program Files\\Microsoft Visual Studio 8\\Common7\\IDE;C:\\Program Files\\Microsoft Visual Studio 8\\VC\\BIN;C:\\Program Files\\Microsoft Visual Studio 8\\Com\nmon7\\Tools;C:\\Program Files\\Microsoft Visual Studio 8\\Common7\\Tools\\bin;C:\\Program Files\\Microsoft Visual Studio 8\\VC\\PlatformSDK\\bin;C:\\Program Files\\Microsoft\n Visual Studio 8\\SDK\\v2.0\\bin;C:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727;C:\\Program Files\\Microsoft Visual Studio 8\\VC\\VCPackages;%PATH%\nset INCLUDE=C:\\Program Files\\Microsoft Visual Studio 8\\VC\\ATLMFC\\INCLUDE;C:\\Program Files\\Microsoft Visual Studio 8\\VC\\INCLUDE;C:\\Program Files\\Microsoft Visual\n Studio 8\\VC\\PlatformSDK\\include;C:\\Program Files\\Microsoft Visual Studio 8\\SDK\\v2.0\\include;%INCLUDE%\nset LIB=C:\\Program Files\\Microsoft Visual Studio 8\\VC\\ATLMFC\\LIB;C:\\Program Files\\Microsoft Visual Studio 8\\VC\\LIB;C:\\Program Files\\Microsoft Visual Studio 8\\VC\n\\PlatformSDK\\lib;C:\\Program Files\\Microsoft Visual Studio 8\\SDK\\v2.0\\lib;%LIB%\nset LIBPATH=C:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727;C:\\Program Files\\Microsoft Visual Studio 8\\VC\\ATLMFC\\LIB\n\necho %0 %*\necho %0 %* >> %MrB-LOG%\ncd\nif not \"\"==\"%~dp1\" pushd %~dp1\ncd\nif exist %~nx1 (\n echo VS2005 build of '%~nx1'.\n echo VS2005 build of '%~nx1'. >> %MrB-LOG%\n set MrB-BUILDLOG=%MrB-BASE%\\%MrB-WORK%.%MrB-NICEDATE%.%MrB-NICETIME%.build-errors.log\n msbuild.exe %~nx1 /t:Rebuild /p:Configuration=Release > %MrB-BUILDLOG%\n findstr /r /c:\"[1-9][0-9]* Error(s)\" %MrB-BUILDLOG%\n if not errorlevel 1 (\n echo ERROR: sending notification email for build errors in '%~nx1'.\n echo ERROR: sending notification email for build errors in '%~nx1'. >> %MrB-LOG%\n call mrb-email \"Mr Build isn't happy about build errors in '%~nx1'\" %MrB-BUILDLOG%\n ) else (\n findstr /r /c:\"[1-9][0-9]* Warning(s)\" %MrB-BUILDLOG%\n if not errorlevel 1 (\n echo ERROR: sending notification email for build warnings in '%~nx1'.\n echo ERROR: sending notification email for build warnings in '%~nx1'. >> %MrB-LOG%\n call mrb-email \"Mr Build isn't happy about build warnings in '%~nx1'\" %MrB-BUILDLOG%\n ) else (\n echo Successful build of '%~nx1'.\n echo Successful build of '%~nx1'. >> %MrB-LOG%\n )\n )\n) else (\n echo ERROR '%1' doesn't exist.\n echo ERROR '%1' doesn't exist. >> %MrB-LOG%\n)\npopd\n" }, { "answer_id": 281356, "author": "icelava", "author_id": 2663, "author_profile": "https://Stackoverflow.com/users/2663", "pm_score": 5, "selected": false, "text": "Msbuild.exe mySolution.sln\n" }, { "answer_id": 355547, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "devenv solutionfile.sln /build solutionconfig\n call \"C:\\Program Files\\Microsoft Visual Studio .NET 2003\\Common7\\Tools\\vsvars32.bat\"\n\ndevenv Tools.sln /build \"Release\"\n" }, { "answer_id": 14748432, "author": "crash", "author_id": 2050281, "author_profile": "https://Stackoverflow.com/users/2050281", "pm_score": 2, "selected": false, "text": "call \"%VS100COMNTOOLS%\\vsvars32.bat\"\n\ndevenv \"%CD%\\..\\soulutionfile.sln\" /build \"Release\"\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280559", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1311500/" ]
280,563
<p>Has anybody got any real world stories build mobile web sites with NetBiscuits?</p> <p>Someone told me it was the next big thing in mobile development (<a href="http://www.netbiscuits.com/home" rel="nofollow noreferrer">http://www.netbiscuits.com/home</a>) and it looks pretty good from their site. Just wondered if anybody (besides them) has actually used it.</p>
[ { "answer_id": 280584, "author": "kenny", "author_id": 3225, "author_profile": "https://Stackoverflow.com/users/3225", "pm_score": 5, "selected": true, "text": "%comspec% /k \"\"C:\\Program Files\\Microsoft Visual Studio 8\\VC\\vcvarsall.bat\"\"x86\"\n @echo off\n\n:: setup VS2005 command line build environment\nset VSINSTALLDIR=C:\\Program Files\\Microsoft Visual Studio 8\nset VCINSTALLDIR=C:\\Program Files\\Microsoft Visual Studio 8\\VC\nset FrameworkDir=C:\\WINDOWS\\Microsoft.NET\\Framework\nset FrameworkVersion=v2.0.50727\nset FrameworkSDKDir=C:\\Program Files\\Microsoft Visual Studio 8\\SDK\\v2.0\nset DevEnvDir=C:\\Program Files\\Microsoft Visual Studio 8\\Common7\\IDE\nset PATH=C:\\Program Files\\Microsoft Visual Studio 8\\Common7\\IDE;C:\\Program Files\\Microsoft Visual Studio 8\\VC\\BIN;C:\\Program Files\\Microsoft Visual Studio 8\\Com\nmon7\\Tools;C:\\Program Files\\Microsoft Visual Studio 8\\Common7\\Tools\\bin;C:\\Program Files\\Microsoft Visual Studio 8\\VC\\PlatformSDK\\bin;C:\\Program Files\\Microsoft\n Visual Studio 8\\SDK\\v2.0\\bin;C:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727;C:\\Program Files\\Microsoft Visual Studio 8\\VC\\VCPackages;%PATH%\nset INCLUDE=C:\\Program Files\\Microsoft Visual Studio 8\\VC\\ATLMFC\\INCLUDE;C:\\Program Files\\Microsoft Visual Studio 8\\VC\\INCLUDE;C:\\Program Files\\Microsoft Visual\n Studio 8\\VC\\PlatformSDK\\include;C:\\Program Files\\Microsoft Visual Studio 8\\SDK\\v2.0\\include;%INCLUDE%\nset LIB=C:\\Program Files\\Microsoft Visual Studio 8\\VC\\ATLMFC\\LIB;C:\\Program Files\\Microsoft Visual Studio 8\\VC\\LIB;C:\\Program Files\\Microsoft Visual Studio 8\\VC\n\\PlatformSDK\\lib;C:\\Program Files\\Microsoft Visual Studio 8\\SDK\\v2.0\\lib;%LIB%\nset LIBPATH=C:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727;C:\\Program Files\\Microsoft Visual Studio 8\\VC\\ATLMFC\\LIB\n\necho %0 %*\necho %0 %* >> %MrB-LOG%\ncd\nif not \"\"==\"%~dp1\" pushd %~dp1\ncd\nif exist %~nx1 (\n echo VS2005 build of '%~nx1'.\n echo VS2005 build of '%~nx1'. >> %MrB-LOG%\n set MrB-BUILDLOG=%MrB-BASE%\\%MrB-WORK%.%MrB-NICEDATE%.%MrB-NICETIME%.build-errors.log\n msbuild.exe %~nx1 /t:Rebuild /p:Configuration=Release > %MrB-BUILDLOG%\n findstr /r /c:\"[1-9][0-9]* Error(s)\" %MrB-BUILDLOG%\n if not errorlevel 1 (\n echo ERROR: sending notification email for build errors in '%~nx1'.\n echo ERROR: sending notification email for build errors in '%~nx1'. >> %MrB-LOG%\n call mrb-email \"Mr Build isn't happy about build errors in '%~nx1'\" %MrB-BUILDLOG%\n ) else (\n findstr /r /c:\"[1-9][0-9]* Warning(s)\" %MrB-BUILDLOG%\n if not errorlevel 1 (\n echo ERROR: sending notification email for build warnings in '%~nx1'.\n echo ERROR: sending notification email for build warnings in '%~nx1'. >> %MrB-LOG%\n call mrb-email \"Mr Build isn't happy about build warnings in '%~nx1'\" %MrB-BUILDLOG%\n ) else (\n echo Successful build of '%~nx1'.\n echo Successful build of '%~nx1'. >> %MrB-LOG%\n )\n )\n) else (\n echo ERROR '%1' doesn't exist.\n echo ERROR '%1' doesn't exist. >> %MrB-LOG%\n)\npopd\n" }, { "answer_id": 281356, "author": "icelava", "author_id": 2663, "author_profile": "https://Stackoverflow.com/users/2663", "pm_score": 5, "selected": false, "text": "Msbuild.exe mySolution.sln\n" }, { "answer_id": 355547, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "devenv solutionfile.sln /build solutionconfig\n call \"C:\\Program Files\\Microsoft Visual Studio .NET 2003\\Common7\\Tools\\vsvars32.bat\"\n\ndevenv Tools.sln /build \"Release\"\n" }, { "answer_id": 14748432, "author": "crash", "author_id": 2050281, "author_profile": "https://Stackoverflow.com/users/2050281", "pm_score": 2, "selected": false, "text": "call \"%VS100COMNTOOLS%\\vsvars32.bat\"\n\ndevenv \"%CD%\\..\\soulutionfile.sln\" /build \"Release\"\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280563", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36503/" ]
280,566
<p>Is there any clever method out there to make my executeEveryDayMethod() execute once a day, without having to involve the Windows TaskScheduler?</p>
[ { "answer_id": 280592, "author": "Vinko Vrsalovic", "author_id": 5190, "author_profile": "https://Stackoverflow.com/users/5190", "pm_score": 2, "selected": false, "text": "using System;\nusing System.Timers;\n\npublic class Timer1\n{\n private static Timer aTimer = new System.Timers.Timer(24*60*60*1000);\n\n public static void Main()\n {\n aTimer.Elapsed += new ElapsedEventHandler(ExecuteEveryDayMethod);\n aTimer.Enabled = true;\n\n Console.WriteLine(\"Press the Enter key to exit the program.\");\n Console.ReadLine();\n }\n\n // Specify what you want to happen when the Elapsed event is \n // raised.\n private static void ExecuteEveryDayMethod(object source, ElapsedEventArgs e)\n {\n Console.WriteLine(\"The Elapsed event was raised at {0}\", e.SignalTime);\n }\n}\n" }, { "answer_id": 280615, "author": "ZombieSheep", "author_id": 377, "author_profile": "https://Stackoverflow.com/users/377", "pm_score": 4, "selected": false, "text": "using System;\nusing System.Collections.Generic;\nusing System.Text;\nusing System.Timers;\n\nnamespace ConsoleApplication2\n{\n class Program\n {\n static void Main(string[] args)\n {\n Timer t1 = new Timer();\n t1.Interval = (1000 * 60 * 20); // 20 minutes...\n t1.Elapsed += new ElapsedEventHandler(t1_Elapsed);\n t1.AutoReset = true;\n t1.Start();\n\n Console.ReadLine();\n }\n\n static void t1_Elapsed(object sender, ElapsedEventArgs e)\n {\n DateTime scheduledRun = DateTime.Today.AddHours(3); // runs today at 3am.\n System.IO.FileInfo lastTime = new System.IO.FileInfo(@\"C:\\lastRunTime.txt\");\n DateTime lastRan = lastTime.LastWriteTime;\n if (DateTime.Now > scheduledRun)\n {\n TimeSpan sinceLastRun = DateTime.Now - lastRan;\n if (sinceLastRun.Hours > 23)\n {\n doStuff();\n // Don't forget to update the file modification date here!!!\n }\n }\n }\n\n static void doStuff()\n {\n Console.WriteLine(\"Running the method!\");\n }\n }\n}\n" }, { "answer_id": 26622322, "author": "drinky", "author_id": 3268030, "author_profile": "https://Stackoverflow.com/users/3268030", "pm_score": 0, "selected": false, "text": "private void timer1_Tick(object sender, EventArgs e)\n{\n //ensure that it is running between 7-8pm daily.\n if (DateTime.Now.Hour == 19)\n { \n RunJob(); \n }\n }\n {\n //ensure that it is running at 7:30pm daily.\n if (DateTime.Now.Hour == 19 && DateTime.Now.Minute == 30)\n { \n RunJob(); \n }\n }\n" }, { "answer_id": 51389924, "author": "HopeThisHelps", "author_id": 10094628, "author_profile": "https://Stackoverflow.com/users/10094628", "pm_score": 0, "selected": false, "text": "DateTime DateTime _DateLastRun;\n _DateLastRun = DateTime.Now.Date;\n if (_DateLastRun < DateTime.Now.Date) \n{\n // Perform your action\n _DateLastRun= DateTime.Now.Date;\n}\n" }, { "answer_id": 62272394, "author": "TymerTopCat", "author_id": 9251019, "author_profile": "https://Stackoverflow.com/users/9251019", "pm_score": 1, "selected": false, "text": " private void Main_Load( object sender, EventArgs e )\n {\n /*\n This example uses a System.Windows.Forms Timer\n\n This code allows you to schedule an event at any given time in one day.\n In this example the timer will tick at 3AM.\n\n */\n Int32 alarm = GetAlarmInMilliseconds( 3, 0, 0 ); // Milliseconds until 3:00 am.\n timer_MessageCount.Interval = alarm; // Timer will tick at 3:00am.\n\n timer_MessageCount.Start( ); \n }\n\n private Int32 GetAlarmInMilliseconds(Int32 eventHour, Int32 eventMinute, Int32 eventSecond )\n {\n DateTime now = DateTime.Now;\n DateTime eventTime = new DateTime( now.Year, now.Month, now.Day, eventHour, eventMinute, eventSecond );\n\n TimeSpan ts;\n\n if ( eventTime > now )\n {\n ts = eventTime - now;\n }\n else\n {\n eventTime = eventTime.AddDays( 1 );\n ts = eventTime - now;\n }\n\n Console.WriteLine(\"Next alarm in: {0}\", ts );\n\n return ( Int32 ) ts.TotalMilliseconds;\n } \n\n static void DoSomething( )\n {\n Console.WriteLine( \"Run your code here.\" );\n } \n\n private void timer_MessageCount_Tick( object sender, EventArgs e )\n {\n DoSomething( );\n\n Int32 alarm = GetAlarmInMilliseconds( 3, 0, 0 ); // Next alarm time = 3AM\n timer_MessageCount.Interval = alarm; \n }\n}\n" }, { "answer_id": 62513077, "author": "Jan", "author_id": 1802491, "author_profile": "https://Stackoverflow.com/users/1802491", "pm_score": 0, "selected": false, "text": " public Main()\n {\n StartService();\n }\n\n public async Task StartService(CancellationToken token = default(CancellationToken))\n {\n while (!token.IsCancellationRequested)\n {\n ExecuteFunction();\n try\n {\n await Task.Delay(TimeSpan.FromDays(1), token);\n }\n catch (TaskCanceledException)\n {\n break;\n }\n }\n }\n\n public async Task ExecuteFunction()\n {\n ...\n }\n" }, { "answer_id": 64911893, "author": "HobbyCodr", "author_id": 12252718, "author_profile": "https://Stackoverflow.com/users/12252718", "pm_score": 0, "selected": false, "text": " private void tmrAutoBAK_Tick(object sender, EventArgs e)\n {\n if (BakDB.Properties.Settings.Default.lastFireDate != DateTime.Now.ToString(\"yyyy-MM-dd\"))\n {\n tmrAutoBAK.Stop(); //STOPS THE TIMER IN CASE OF EVENTUAL MESSAGEBOXES.\n createBakup(); //EVENT\n BakDB.Properties.Settings.Default.lastFireDate = DateTime.Now.ToString(\"yyyy-MM-dd\"); //STORING CURRENT DATE TO SETTINGS FILE.\n BakDB.Properties.Settings.Default.Save(); //SAVING THE SETTING FILE.\n tmrAutoBAK.Start(); //RESTARTING TIMER\n }\n }\n" }, { "answer_id": 74429183, "author": "Gerhard Schmeusser", "author_id": 7441713, "author_profile": "https://Stackoverflow.com/users/7441713", "pm_score": 0, "selected": false, "text": " //note the namespace, there are 4 different timers in .NET\n System.Threading.Timer _Timer;\n\n DateTime now = DateTime.Now;\n //convert \"hh:mm:ss\" to three integers\n var dateparts = _Settings.DataCleanupTime.Split(new char[] { ':' }).Select(p => Convert.ToInt32(p)).ToArray();\n DateTime firstTime = new DateTime(now.Year, now.Month, now.Day, dateparts[0], dateparts[1], dateparts[2]);\n \n //e.g. firsttime is today at 2am and it is already 6am\n if(firstTime < now)\n {\n //first run will be tomorrow\n firstTime = firstTime.AddDays(1);\n }\n\n int delay = Convert.ToInt32((firstTime - now).TotalMilliseconds);\n\n _Timer = new Timer(DoWork, state:null, delay, 3600 * 24 * 1000);\n public void DoWork(Object state)\n _Timer.Dispose();\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280566", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36504/" ]
280,571
<p>I am confused about how popen() redirects stdin, stdout and stderr of the child process in unix. The man page on popen() is not very clear in this regard. The call</p> <pre><code>FILE *p = popen("/usr/bin/foo", "w"); </code></pre> <p>forks a child process and executes a shell with arguments "-c", "/usr/bin/foo", and redirects stdin of this shell (which is redirected stdin of foo), stdout to p. But what happens with stderr? What is the general principle behind it?</p> <p>I noticed that, if I open a file in foo (using fopen, socket, accept etc.), and the parent process has no stdout, it gets assigned the next available file number, which is 1 and so on. This delivers unexpected results from calls like fprintf(stderr, ...).</p> <p>It can be avoided by writing</p> <pre><code>FILE *p = popen("/usr/bin/foo 2&gt;/dev/null", "w"); </code></pre> <p>in the parent program, but are their better ways?</p>
[ { "answer_id": 280587, "author": "Johannes Schaub - litb", "author_id": 34509, "author_profile": "https://Stackoverflow.com/users/34509", "pm_score": 3, "selected": false, "text": "FILE * file = popen(\"/bin/cat\", \"w\");\nfwrite(\"hello\", 5, file);\npclose(file);\n \"hello\" \"foo\" FILE * error_file = fopen(\"foo\", \"w+\");\nif(error_file) {\n dup2(fileno(error_file), 2);\n fclose(error_file);\n}\n open stdout stdout" }, { "answer_id": 280628, "author": "Alnitak", "author_id": 6782, "author_profile": "https://Stackoverflow.com/users/6782", "pm_score": 6, "selected": true, "text": "popen(3) fork(2) pipe(2) pipe(2) stderr select stdout stderr" }, { "answer_id": 23234272, "author": "kangear", "author_id": 2193455, "author_profile": "https://Stackoverflow.com/users/2193455", "pm_score": 3, "selected": false, "text": "#include <stdio.h>\n#include <errno.h>\n#include <fcntl.h>\n#include <sys/wait.h>\n#include <malloc.h>\n#include <unistd.h>\n#include <string.h>\n#include <sys/types.h>\n\n/*\n * Pointer to array allocated at run-time.\n */\nstatic pid_t *childpid = NULL;\n\n/*\n * From our open_max(), {Prog openmax}.\n */\nstatic int maxfd;\n\nFILE *\nmypopen(const char *cmdstring, const char *type)\n{\n int i;\n int pfd[2];\n pid_t pid;\n FILE *fp;\n\n /* only allow \"r\" \"e\" or \"w\" */\n if ((type[0] != 'r' && type[0] != 'w' && type[0] != 'e') || type[1] != 0) {\n errno = EINVAL; /* required by POSIX */\n return(NULL);\n }\n\n if (childpid == NULL) { /* first time through */\n /* allocate zeroed out array for child pids */\n maxfd = 256;\n if ((childpid = calloc(maxfd, sizeof(pid_t))) == NULL)\n return(NULL);\n }\n\n if (pipe(pfd) < 0)\n return(NULL); /* errno set by pipe() */\n\n if ((pid = fork()) < 0) {\n return(NULL); /* errno set by fork() */\n } else if (pid == 0) { /* child */\n if (*type == 'e') {\n close(pfd[0]);\n if (pfd[1] != STDERR_FILENO) {\n dup2(pfd[1], STDERR_FILENO);\n close(pfd[1]);\n }\n } else if (*type == 'r') {\n close(pfd[0]);\n if (pfd[1] != STDOUT_FILENO) {\n dup2(pfd[1], STDOUT_FILENO);\n close(pfd[1]);\n }\n } else {\n close(pfd[1]);\n if (pfd[0] != STDIN_FILENO) {\n dup2(pfd[0], STDIN_FILENO);\n close(pfd[0]);\n }\n }\n\n /* close all descriptors in childpid[] */\n for (i = 0; i < maxfd; i++)\n if (childpid[i] > 0)\n close(i);\n\n execl(\"/bin/sh\", \"sh\", \"-c\", cmdstring, (char *)0);\n _exit(127);\n }\n\n /* parent continues... */\n if (*type == 'e') {\n close(pfd[1]);\n if ((fp = fdopen(pfd[0], \"r\")) == NULL)\n return(NULL);\n } else if (*type == 'r') {\n close(pfd[1]);\n if ((fp = fdopen(pfd[0], type)) == NULL)\n return(NULL);\n\n } else {\n close(pfd[0]);\n if ((fp = fdopen(pfd[1], type)) == NULL)\n return(NULL);\n }\n\n childpid[fileno(fp)] = pid; /* remember child pid for this fd */\n return(fp);\n}\n\nint\nmypclose(FILE *fp)\n{\n int fd, stat;\n pid_t pid;\n\n if (childpid == NULL) {\n errno = EINVAL;\n return(-1); /* popen() has never been called */\n }\n\n fd = fileno(fp);\n if ((pid = childpid[fd]) == 0) {\n errno = EINVAL;\n return(-1); /* fp wasn't opened by popen() */\n }\n\n childpid[fd] = 0;\n if (fclose(fp) == EOF)\n return(-1);\n\n while (waitpid(pid, &stat, 0) < 0)\n if (errno != EINTR)\n return(-1); /* error other than EINTR from waitpid() */\n\n return(stat); /* return child's termination status */\n}\n\nint shellcmd(char *cmd){\n FILE *fp;\n char buf[1024];\n fp = mypopen(cmd,\"e\");\n if (fp==NULL) return -1;\n\n while(fgets(buf,1024,fp)!=NULL)\n {\n printf(\"shellcmd:%s\", buf);\n }\n\n pclose(fp);\n return 0;\n}\n\nint main()\n{\n shellcmd(\"ls kangear\");\n}\n shellcmd:ls: cannot access kangear: No such file or directory\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280571", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31330/" ]
280,578
<p>I have got some code to load an assembly and get all types, which implement a certain interface, like this (assume asm is a valid and loaded assembly).</p> <pre><code>var results = from type in asm.GetTypes() where typeof(IServiceJob).IsAssignableFrom(type) select type; </code></pre> <p>Now I'm stuck: I need to create instances of these objects and invoke methods and properties on the object. And I need to store the references to the created objects in an array for later usage.</p>
[ { "answer_id": 280591, "author": "Matt Hamilton", "author_id": 615, "author_profile": "https://Stackoverflow.com/users/615", "pm_score": 5, "selected": true, "text": "private static IEnumerable<T> InstancesOf<T>() where T : class\n{\n var type = typeof(T);\n return from t in type.Assembly.GetExportedTypes()\n where t.IsClass\n && type.IsAssignableFrom(t)\n && t.GetConstructor(new Type[0]) != null\n select (T)Activator.CreateInstance(t);\n}\n" }, { "answer_id": 280610, "author": "AnthonyWJones", "author_id": 17516, "author_profile": "https://Stackoverflow.com/users/17516", "pm_score": 1, "selected": false, "text": "Activator.CreateInstance IServiceJob x = Activator.CreateInstance(type);\n IServiceJob[] results = (from type in asm.GetTypes()\n where typeof(IServiceJob).IsAssignableFrom(type)\n select (IServiceJob)Activator.CreateInstance(type)).ToArray();\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280578", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16440/" ]
280,579
<p>How do I pass a value from a child back to the parent form? I have a string that I would like to pass back to the parent.</p> <p>I launched the child using:</p> <pre><code>FormOptions formOptions = new FormOptions(); formOptions.ShowDialog(); </code></pre>
[ { "answer_id": 280586, "author": "Mitch Wheat", "author_id": 16076, "author_profile": "https://Stackoverflow.com/users/16076", "pm_score": 6, "selected": false, "text": "FormOptions GetMyResult using (FormOptions formOptions = new FormOptions())\n{\n formOptions.ShowDialog();\n\n string result = formOptions.GetMyResult;\n\n // do what ever with result...\n}\n" }, { "answer_id": 280630, "author": "stiduck", "author_id": 35398, "author_profile": "https://Stackoverflow.com/users/35398", "pm_score": 5, "selected": false, "text": "// Using and namespace...\n\npublic partial class FormOptions : Form\n{\n private string _MyString; // Use this\n public string MyString { // in \n get { return _MyString; } // .NET\n } // 2.0\n\n public string MyString { get; } // In .NET 3.0 or newer\n\n // The rest of the form code\n}\n FormOptions formOptions = new FormOptions();\nformOptions.ShowDialog();\n\nstring myString = formOptions.MyString;\n" }, { "answer_id": 280685, "author": "MusiGenesis", "author_id": 14606, "author_profile": "https://Stackoverflow.com/users/14606", "pm_score": 5, "selected": false, "text": "public void NotifyMe(string s)\n{\n // Do whatever you need to do with the string\n}\n using (FormOptions formOptions = new FormOptions())\n{\n // passing this in ShowDialog will set the .Owner \n // property of the child form\n formOptions.ShowDialog(this);\n}\n ParentForm parent = (ParentForm)this.Owner;\nparent.NotifyMe(\"whatever\");\n" }, { "answer_id": 280731, "author": "Ali Ersöz", "author_id": 4215, "author_profile": "https://Stackoverflow.com/users/4215", "pm_score": 3, "selected": false, "text": "public partial class FormOptions : Form\n{\n public DialogResult ShowDialog(out string result)\n {\n DialogResult dialogResult = base.ShowDialog();\n\n result = m_Result;\n return dialogResult;\n }\n}\n" }, { "answer_id": 395035, "author": "Ahmed", "author_id": 42749, "author_profile": "https://Stackoverflow.com/users/42749", "pm_score": 0, "selected": false, "text": "myvalue x=(myvalue)formoptions.Tag;\n" }, { "answer_id": 395104, "author": "abatishchev", "author_id": 41956, "author_profile": "https://Stackoverflow.com/users/41956", "pm_score": 2, "selected": false, "text": "frmOptions {\n public string Result; }\n\nfrmMain {\n frmOptions.ShowDialog(); string r = frmOptions.Result; }\n frmMain {\n frmOptions.OnResult += new ResultEventHandler(frmMain.frmOptions_Resukt);\n frmOptions.ShowDialog(); }\n frmOptions {\n public frmMain MainForm; MainForm.Result = \"result\"; }\n\nfrmMain {\n public string Result;\n frmOptions.MainForm = this;\n frmOptions.ShowDialog();\n string r = this.Result; }\n frmOptions {\n this.Tag = \"result\": }\nfrmMain {\n frmOptions.ShowDialog();\n string r = frmOptions.Tag as string; }\n" }, { "answer_id": 11013409, "author": "Odin", "author_id": 1453458, "author_profile": "https://Stackoverflow.com/users/1453458", "pm_score": 0, "selected": false, "text": "ShowDialog() Show()" }, { "answer_id": 13625756, "author": "Bravo Mike", "author_id": 1863172, "author_profile": "https://Stackoverflow.com/users/1863172", "pm_score": 1, "selected": false, "text": "ShowDialog() this.Close() Dispose() Close() Show()" }, { "answer_id": 30526895, "author": "Chagbert", "author_id": 1261930, "author_profile": "https://Stackoverflow.com/users/1261930", "pm_score": 2, "selected": false, "text": "RefDateSelect myDateFrm; myDateFrm = new RefDateSelect();\nmyDateFrm.MdiParent = this;\nmyDateFrm.Show();\nmyDateFrm.Focus();\n PDateEnd = myDateFrm.JustGetDateEnd();\npDateStart = myDateFrm.JustGetDateStart();`\n JustGetDateStart() public DateTime JustGetDateStart()\n{\n return DateTime.Parse(this.dtpStart.EditValue.ToString());\n}\n" }, { "answer_id": 56788194, "author": "user889030", "author_id": 889030, "author_profile": "https://Stackoverflow.com/users/889030", "pm_score": 1, "selected": false, "text": "namespace ParentChild\n{\n // Parent Form Class\n public partial class ParentForm : Form\n {\n // Forms Objects\n ChildForm child_obj = new ChildForm();\n\n\n // Show Child Forrm\n private void ShowChildForm_Click(object sender, EventArgs e)\n {\n child_obj.ShowDialog();\n }\n\n // Read Data from Child Form \n private void ReadChildFormData_Click(object sender, EventArgs e)\n {\n int ChildData = child_obj.child_value; // it will have 12345\n }\n\n } // parent form class end point\n\n\n // Child Form Class\n public partial class ChildForm : Form\n {\n\n public int child_value = 0; // variable where we will store value to be read by parent form \n\n // save something into child_value variable and close child form \n private void SaveData_Click(object sender, EventArgs e)\n {\n child_value = 12345; // save 12345 value to variable\n this.Close(); // close child form\n }\n\n } // child form class end point\n\n\n} // name space end point\n" }, { "answer_id": 65976609, "author": "mahdi yousefi", "author_id": 3247491, "author_profile": "https://Stackoverflow.com/users/3247491", "pm_score": 0, "selected": false, "text": "public string MyProperty {get; set;} private ParentForm ParentProperty {get; set;} public ChildForm(ParentForm parent){\n ParentProperty= parent;\n }\n ParentProperty.MyProperty = \"New value\"; MyProperty" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280579", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
280,597
<p>We have a problem affecting the production environment only.</p> <p>We have a VB6/ASP website that allows for data in a database table to be hand edited.</p> <p>It looks alot like an editable datagrid.</p> <p>One of the editable columns is a date and when the record is saved dates day/month are being reversed.</p> <p>03/11/2008 becomes 11/03/2008, if you were to resave the record the date is again 03/11/2008. </p> <p>I have checked the DB value and it is indeed being reversed however the same identical code on the test systems does not do this.</p> <p>So i'm very confident i'm looking for an environment change. The test system has the DB and Site hosted locally and in the live setup we have a separate web site server and database server. Where do you suggest I start looking for this problem. I've checked the regional settings on the servers and they are set to United Kingdom and the OS date format is correct.</p> <p>This is SQL Server 2000. hit me with some ideas!. </p> <p>Thanks :)</p>
[ { "answer_id": 280633, "author": "Tomalak", "author_id": 18771, "author_profile": "https://Stackoverflow.com/users/18771", "pm_score": 2, "selected": true, "text": "SET DATEFORMAT SET LANGUAGE" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280597", "https://Stackoverflow.com", "https://Stackoverflow.com/users/27412/" ]
280,624
<p>I'm writing an image processing program to perform real time processing of video frames. It's in C# using the Emgu.CV library (C#) that wraps the OpenCV library dll (unmanaged C++). Now I have to write my own special algorithm and it needs to be as fast as possible. </p> <p>Which will be a faster implementation of the algorithm?</p> <ol> <li><p>Writing an 'unsafe' function in C#</p></li> <li><p>Adding the function to the OpenCV library and calling it through Emgu.CV</p></li> </ol> <p>I'm guessing C# unsafe is slower because it goes throught the JIT compiler, but would the difference be significant?</p> <p>Edit:</p> <p>Compiled for .NET 3.5 under VS2008</p>
[ { "answer_id": 319726, "author": "Tom Barta", "author_id": 29839, "author_profile": "https://Stackoverflow.com/users/29839", "pm_score": 2, "selected": false, "text": "malloc()" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280624", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31045/" ]
280,634
<p>How can I check if a string ends with a particular character in JavaScript?</p> <p>Example: I have a string </p> <pre><code>var str = "mystring#"; </code></pre> <p>I want to know if that string is ending with <code>#</code>. How can I check it?</p> <ol> <li><p>Is there a <code>endsWith()</code> method in JavaScript?</p></li> <li><p>One solution I have is take the length of the string and get the last character and check it.</p></li> </ol> <p>Is this the best way or there is any other way?</p>
[ { "answer_id": 280644, "author": "Phillip B Oldham", "author_id": 30478, "author_profile": "https://Stackoverflow.com/users/30478", "pm_score": 7, "selected": false, "text": "if( \"mystring#\".substr(-1) === \"#\" ) {}" }, { "answer_id": 280651, "author": "duckyflip", "author_id": 7370, "author_profile": "https://Stackoverflow.com/users/7370", "pm_score": 4, "selected": false, "text": "if( (\"mystring#\").substr(-1,1) == '#' )\n if( (\"mystring#\").match(/#$/) )\n" }, { "answer_id": 280704, "author": "Phani Kumar Bhamidipati", "author_id": 15177, "author_profile": "https://Stackoverflow.com/users/15177", "pm_score": 0, "selected": false, "text": "String.prototype.endsWith = function(str)" }, { "answer_id": 280708, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 6, "selected": false, "text": "String.prototype.endsWith = function(str)\n{\n var lastIndex = this.lastIndexOf(str);\n return (lastIndex !== -1) && (lastIndex + str.length === this.length);\n}\n lastIndexOf charAt" }, { "answer_id": 611204, "author": "user73745", "author_id": 73745, "author_profile": "https://Stackoverflow.com/users/73745", "pm_score": 4, "selected": false, "text": "return this.lastIndexOf(str) + str.length == this.length;\n return this.length >= str.length && this.lastIndexOf(str) + str.length == this.length\n" }, { "answer_id": 679134, "author": "Mike Samuel", "author_id": 20394, "author_profile": "https://Stackoverflow.com/users/20394", "pm_score": 8, "selected": false, "text": "/#$/.test(str)\n String lastIndexOf '$' function makeSuffixRegExp(suffix, caseInsensitive) {\n return new RegExp(\n String(suffix).replace(/[$%()*+.?\\[\\\\\\]{|}]/g, \"\\\\$&\") + \"$\",\n caseInsensitive ? \"i\" : \"\");\n}\n makeSuffixRegExp(\"a[complicated]*suffix*\").test(str)\n" }, { "answer_id": 1483107, "author": "Oskar Liljeblad", "author_id": 179703, "author_profile": "https://Stackoverflow.com/users/179703", "pm_score": 6, "selected": false, "text": "endsWith String.prototype.endsWith = function (s) {\n return this.length >= s.length && this.substr(this.length - s.length) == s;\n}\n lastIndexOf" }, { "answer_id": 2548133, "author": "chakrit", "author_id": 3055, "author_profile": "https://Stackoverflow.com/users/3055", "pm_score": 12, "selected": true, "text": "this.substr(-suffix.length) === suffix String.prototype.endsWith = function(suffix) {\n return this.indexOf(suffix, this.length - suffix.length) !== -1;\n};\n indexOf indexOf function endsWith(str, suffix) {\n return str.indexOf(suffix, str.length - suffix.length) !== -1;\n}\n typeof if (typeof String.prototype.endsWith !== 'function') {\n String.prototype.endsWith = function(suffix) {\n return this.indexOf(suffix, this.length - suffix.length) !== -1;\n };\n}\n" }, { "answer_id": 3054087, "author": "manish", "author_id": 368321, "author_profile": "https://Stackoverflow.com/users/368321", "pm_score": 2, "selected": false, "text": "function check(str)\n{\n var lastIndex = str.lastIndexOf('/');\n return (lastIndex != -1) && (lastIndex == (str.length - 1));\n}\n" }, { "answer_id": 5854629, "author": "user511941", "author_id": 511941, "author_profile": "https://Stackoverflow.com/users/511941", "pm_score": 1, "selected": false, "text": "String.prototype.endsWith = function(suffix) {\n if (this[this.length - 1] == suffix) return true;\n return false;\n}\n function strEndsWith(str,suffix) {\n if (str[str.length - 1] == suffix) return true;\n return false;\n}\n" }, { "answer_id": 6739835, "author": "Dan Doyon", "author_id": 53635, "author_profile": "https://Stackoverflow.com/users/53635", "pm_score": 2, "selected": false, "text": "if (typeof String.endsWith !== 'function') {\n String.prototype.endsWith = function (suffix) {\n return this.indexOf(suffix, this.length - suffix.length) !== -1;\n };\n}\n" }, { "answer_id": 11158914, "author": "Ebubekir Dirican", "author_id": 869571, "author_profile": "https://Stackoverflow.com/users/869571", "pm_score": 1, "selected": false, "text": "String.prototype.endWith = function (a) {\n var isExp = a.constructor.name === \"RegExp\",\n val = this;\n if (isExp === false) {\n a = escape(a);\n val = escape(val);\n } else\n a = a.toString().replace(/(^\\/)|(\\/$)/g, \"\");\n return eval(\"/\" + a + \"$/.test(val)\");\n}\n\n// example\nvar str = \"Hello\";\nalert(str.endWith(\"lo\"));\nalert(str.endWith(/l(o|a)/));\n" }, { "answer_id": 12932780, "author": "Mohammed Rafeeq", "author_id": 1752917, "author_profile": "https://Stackoverflow.com/users/1752917", "pm_score": 3, "selected": false, "text": "String.prototype.endsWith = function(str) \n{return (this.match(str+\"$\")==str)}\n\nString.prototype.startsWith = function(str) \n{return (this.match(\"^\"+str)==str)}\n var myStr = “ Earth is a beautiful planet ”;\nvar myStr2 = myStr.trim(); \n//==“Earth is a beautiful planet”;\n\nif (myStr2.startsWith(“Earth”)) // returns TRUE\n\nif (myStr2.endsWith(“planet”)) // returns TRUE\n\nif (myStr.startsWith(“Earth”)) \n// returns FALSE due to the leading spaces…\n\nif (myStr.endsWith(“planet”)) \n// returns FALSE due to trailing spaces…\n function strStartsWith(str, prefix) {\n return str.indexOf(prefix) === 0;\n}\n\nfunction strEndsWith(str, suffix) {\n return str.match(suffix+\"$\")==suffix;\n}\n" }, { "answer_id": 16333087, "author": "Tici", "author_id": 1651168, "author_profile": "https://Stackoverflow.com/users/1651168", "pm_score": 3, "selected": false, "text": "var s = \"mystring#\";\ns.length >= 1 && s[s.length - 1] == '#'; // will do the thing!\n" }, { "answer_id": 17120898, "author": "Matthew Brown", "author_id": 515311, "author_profile": "https://Stackoverflow.com/users/515311", "pm_score": 0, "selected": false, "text": "if (typeof String.prototype.endsWith === 'undefined') {\n String.prototype.endsWith = function(suffix) {\n if (typeof suffix === 'String') {\n return this.indexOf(suffix, this.length - suffix.length) !== -1;\n }else if(suffix instanceof Array){\n return _.find(suffix, function(value){\n console.log(value, (this.indexOf(value, this.length - value.length) !== -1));\n return this.indexOf(value, this.length - value.length) !== -1;\n }, this);\n }\n };\n}\n" }, { "answer_id": 17594966, "author": "termi", "author_id": 1587897, "author_profile": "https://Stackoverflow.com/users/1587897", "pm_score": 0, "selected": false, "text": "if(typeof String.prototype.endsWith !== \"function\") {\n /**\n * String.prototype.endsWith\n * Check if given string locate at the end of current string\n * @param {string} substring substring to locate in the current string.\n * @param {number=} position end the endsWith check at that position\n * @return {boolean}\n *\n * @edition ECMA-262 6th Edition, 15.5.4.23\n */\n String.prototype.endsWith = function(substring, position) {\n substring = String(substring);\n\n var subLen = substring.length | 0;\n\n if( !subLen )return true;//Empty string\n\n var strLen = this.length;\n\n if( position === void 0 )position = strLen;\n else position = position | 0;\n\n if( position < 1 )return false;\n\n var fromIndex = (strLen < position ? strLen : position) - subLen;\n\n return (fromIndex >= 0 || subLen === -fromIndex)\n && (\n position === 0\n // if position not at the and of the string, we can optimise search substring\n // by checking first symbol of substring exists in search position in current string\n || this.charCodeAt(fromIndex) === substring.charCodeAt(0)//fast false\n )\n && this.indexOf(substring, fromIndex) === fromIndex\n ;\n };\n}\n" }, { "answer_id": 22201327, "author": "Aniket Kulkarni", "author_id": 1031945, "author_profile": "https://Stackoverflow.com/users/1031945", "pm_score": 4, "selected": false, "text": "endsWith() str.endsWith(searchString [, position]);\n var str = \"To be, or not to be, that is the question.\";\n\nalert( str.endsWith(\"question.\") ); // true\nalert( str.endsWith(\"to be\") ); // false\nalert( str.endsWith(\"to be\", 19) ); // true\n" }, { "answer_id": 23361885, "author": "Ashley Davis", "author_id": 25868, "author_profile": "https://Stackoverflow.com/users/25868", "pm_score": 3, "selected": false, "text": "S S('hi there').endsWith('hi there')\n npm install string\n S var S = require('string');\n" }, { "answer_id": 23732394, "author": "Tabish Usman", "author_id": 3651315, "author_profile": "https://Stackoverflow.com/users/3651315", "pm_score": 2, "selected": false, "text": "function strEndsWith(str,suffix) {\n var reguex= new RegExp(suffix+'$');\n\n if (str.match(reguex)!=null)\n return true;\n\n return false;\n}\n" }, { "answer_id": 26525300, "author": "Quanlong", "author_id": 622662, "author_profile": "https://Stackoverflow.com/users/622662", "pm_score": 0, "selected": false, "text": "String::endsWith = (suffix) ->\n -1 != @indexOf suffix, @length - suffix.length\n" }, { "answer_id": 26990323, "author": "LahiruBandara", "author_id": 3175948, "author_profile": "https://Stackoverflow.com/users/3175948", "pm_score": 2, "selected": false, "text": "var str = \"mystring#\";\nvar regex = /^.*#$/\n\nif (regex.test(str)){\n //if it has a trailing '#'\n}" }, { "answer_id": 28330768, "author": "rmehlinger", "author_id": 1141842, "author_profile": "https://Stackoverflow.com/users/1141842", "pm_score": 2, "selected": false, "text": "function endsWithHash(str) {\n return _.str.endsWith(str, '#');\n}\n" }, { "answer_id": 28807654, "author": "Dheeraj Vepakomma", "author_id": 165674, "author_profile": "https://Stackoverflow.com/users/165674", "pm_score": 3, "selected": false, "text": "_.endsWith('abc', 'c'); // true\n" }, { "answer_id": 30128677, "author": "Vinicius", "author_id": 528531, "author_profile": "https://Stackoverflow.com/users/528531", "pm_score": 3, "selected": false, "text": "// Would be equivalent to:\n// \"Hello World!\".endsWith(\"World!\")\n\"Hello World!\".match(\"World!$\") != null\n" }, { "answer_id": 30725350, "author": "Nikita Koksharov", "author_id": 764206, "author_profile": "https://Stackoverflow.com/users/764206", "pm_score": 5, "selected": false, "text": "slice function endsWith(str, suffix) {\n return str.slice(-suffix.length) === suffix\n}\n" }, { "answer_id": 35460962, "author": "faisalbhagat", "author_id": 1851358, "author_profile": "https://Stackoverflow.com/users/1851358", "pm_score": -1, "selected": false, "text": "function strEndsWith(str, endwith)\n{\n var lastIndex = url.lastIndexOf(endsWith);\n var result = false;\n if (lastIndex > 0 && (lastIndex + \"registerc\".length) == url.length)\n {\n result = true;\n }\n return result;\n}\n" }, { "answer_id": 35681532, "author": "immazharkhan", "author_id": 4945514, "author_profile": "https://Stackoverflow.com/users/4945514", "pm_score": 2, "selected": false, "text": "function end(str, target) {\n return str.substr(-target.length) == target;\n}\n" }, { "answer_id": 50940299, "author": "Singh123", "author_id": 3526891, "author_profile": "https://Stackoverflow.com/users/3526891", "pm_score": 0, "selected": false, "text": "endsWith String.prototype.endsWith = function (str) {\n return (this.length >= str.length) && (this.substr(this.length - str.length) === str);\n}\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280634", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15177/" ]
280,658
<p>I'm currently running into some issues resizing images using GD.</p> <p>Everything works fine until i want to resize an animated gif, which delivers the first frame on a black background.</p> <p>I've tried using <code>getimagesize</code> but that only gives me dimensions and nothing to distinguish between just any gif and an animated one.</p> <p>Actual resizing is not required for animated gifs, just being able to skip them would be enough for our purposes.</p> <p>Any clues?</p> <p>PS. I don't have access to imagemagick.</p> <p>Kind regards,</p> <p>Kris</p>
[ { "answer_id": 280705, "author": "Davide Gualano", "author_id": 28582, "author_profile": "https://Stackoverflow.com/users/28582", "pm_score": 5, "selected": true, "text": "imagecreatefromgif() imagecreatefromgif" }, { "answer_id": 280743, "author": "Kris", "author_id": 18565, "author_profile": "https://Stackoverflow.com/users/18565", "pm_score": 3, "selected": false, "text": "/**\n * Thanks to ZeBadger for original example, and Davide Gualano for pointing me to it\n * Original at http://it.php.net/manual/en/function.imagecreatefromgif.php#59787\n **/\nfunction is_animated_gif( $filename )\n{\n $raw = file_get_contents( $filename );\n\n $offset = 0;\n $frames = 0;\n while ($frames < 2)\n {\n $where1 = strpos($raw, \"\\x00\\x21\\xF9\\x04\", $offset);\n if ( $where1 === false )\n {\n break;\n }\n else\n {\n $offset = $where1 + 1;\n $where2 = strpos( $raw, \"\\x00\\x2C\", $offset );\n if ( $where2 === false )\n {\n break;\n }\n else\n {\n if ( $where1 + 8 == $where2 )\n {\n $frames ++;\n }\n $offset = $where2 + 1;\n }\n }\n }\n\n return $frames > 1;\n}\n" }, { "answer_id": 415942, "author": "Martijn Heemels", "author_id": 35434, "author_profile": "https://Stackoverflow.com/users/35434", "pm_score": 5, "selected": false, "text": "function is_ani($filename) {\n if(!($fh = @fopen($filename, 'rb')))\n return false;\n $count = 0;\n //an animated gif contains multiple \"frames\", with each frame having a\n //header made up of:\n // * a static 4-byte sequence (\\x00\\x21\\xF9\\x04)\n // * 4 variable bytes\n // * a static 2-byte sequence (\\x00\\x2C)\n\n // We read through the file til we reach the end of the file, or we've found\n // at least 2 frame headers\n while(!feof($fh) && $count < 2) {\n $chunk = fread($fh, 1024 * 100); //read 100kb at a time\n $count += preg_match_all('#\\x00\\x21\\xF9\\x04.{4}\\x00[\\x2C\\x21]#s', $chunk, $matches);\n }\n\n fclose($fh);\n return $count > 1;\n}\n" }, { "answer_id": 18524842, "author": "user2731504", "author_id": 2731504, "author_profile": "https://Stackoverflow.com/users/2731504", "pm_score": -1, "selected": false, "text": "\"\\x21\\xFF\\x0B\\x4E\\x45\\x54\\x53\\x43\\x41\\x50\\x45\\x32\\x2E\\x30\"\n" }, { "answer_id": 42191495, "author": "hdogan", "author_id": 1358561, "author_profile": "https://Stackoverflow.com/users/1358561", "pm_score": 2, "selected": false, "text": "file_get_contents <?php\n/**\n * Detects animated GIF from given file pointer resource or filename.\n *\n * @param resource|string $file File pointer resource or filename\n * @return bool\n */\nfunction is_animated_gif($file)\n{\n $fp = null;\n\n if (is_string($file)) {\n $fp = fopen($file, \"rb\");\n } else {\n $fp = $file;\n\n /* Make sure that we are at the beginning of the file */\n fseek($fp, 0);\n }\n\n if (fread($fp, 3) !== \"GIF\") {\n fclose($fp);\n\n return false;\n }\n\n $frames = 0;\n\n while (!feof($fp) && $frames < 2) {\n if (fread($fp, 1) === \"\\x00\") {\n /* Some of the animated GIFs do not contain graphic control extension (starts with 21 f9) */\n if (fread($fp, 1) === \"\\x2c\" || fread($fp, 2) === \"\\x21\\xf9\") {\n $frames++;\n }\n }\n }\n\n fclose($fp);\n\n return $frames > 1;\n}\n" }, { "answer_id": 47907134, "author": "Simon - ShortPixel", "author_id": 9122914, "author_profile": "https://Stackoverflow.com/users/9122914", "pm_score": 3, "selected": false, "text": "<?php\nfunction is_ani($filename) {\n if(!($fh = @fopen($filename, 'rb')))\n return false;\n $count = 0;\n //an animated gif contains multiple \"frames\", with each frame having a\n //header made up of:\n // * a static 4-byte sequence (\\x00\\x21\\xF9\\x04)\n // * 4 variable bytes\n // * a static 2-byte sequence (\\x00\\x2C) (some variants may use \\x00\\x21 ?)\n\n // We read through the file til we reach the end of the file, or we've found\n // at least 2 frame headers\n $chunk = false;\n while(!feof($fh) && $count < 2) {\n //add the last 20 characters from the previous string, to make sure the searched pattern is not split.\n $chunk = ($chunk ? substr($chunk, -20) : \"\") . fread($fh, 1024 * 100); //read 100kb at a time\n $count += preg_match_all('#\\x00\\x21\\xF9\\x04.{4}\\x00(\\x2C|\\x21)#s', $chunk, $matches);\n }\n\n fclose($fh);\n return $count > 1;\n}\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280658", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18565/" ]
280,672
<p>I have let's say two pc's.PC-a and PC-b which both have the same application installed with java db support.I want from time to time to copy the data from the database on PC-a to database to PC-b and vice-versa so the two PC's to have the same data all the time. Is there an already implemented API in the database layer for this(i.e 1.export-backup database from PC-a 2.import-merge databases to PC-b) or i have to do this in the sql layer(manually)?</p>
[ { "answer_id": 1235367, "author": "Chris K", "author_id": 51789, "author_profile": "https://Stackoverflow.com/users/51789", "pm_score": 2, "selected": true, "text": "Customer: \n SiteCode varchar,\n CustomerID varchar, \n .... \n primary key(siteCode, CustomerID) \n SiteCode|CustomerID|CustName |phone |email \n 1 XXX |0001 |Customer1 |555.555.1212 |darth@example.com\n SiteCode|CustomerID|CustName |phone |email \n 2 XXY |0001 |customer2 |555.555.1213 |darth@nowhere.com \n 3 XXX |0001 |customer1 |555.555.1212 |darth@nowhere.com\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280672", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36525/" ]
280,680
<pre><code>$images = array(); $images[0][0] = "boxes/blue.jpg"; $images[0][1] = "blah.html"; $images[1][0] = "boxes/green.jpg"; $images[1][1] = "blah.html"; $images[2][0] = "boxes/orange.jpg"; $images[2][1] = "blah.html"; $images[3][0] = "boxes/pink.jpg"; $images[3][1] = "blah.html"; $images[4][0] = "boxes/purple.jpg"; $images[4][1] = "blah.html"; $images[5][0] = "boxes/red.jpg"; $images[5][1] = "blah.html"; $images[6][0] = "boxes/yellow.jpg"; $images[6][1] = "blah.html"; $i = 0; *echo "&lt;a href='" . $images[0][1] . "'&gt;&lt;img src='" . $images[0][0] . "' /&gt;&lt;/a&gt;"; $boxes = array(); while($i&lt;5) { $rand = rand(0,(sizeof($images)-1)); //echo $rand; $slice = array_splice($images, $rand); $boxes[$i] = $slice; $i++; }* </code></pre> <p>I am trying to get a random image picker to choose from a list of images provided by the $images array. However, I am unable to fill the $boxes array with anything other than "Array". Can anyone tell me why? Any help is much appreciated</p> <p>UPDATE</p> <p>I am now using the code below and it breaks whenever it comes across an empty element. Unless i am very much mistaken, shouldn't splice patch up holes like that?</p> <pre><code>$rand = rand(0,(sizeof($images))); array_splice($images, $rand); $i = 0; while($i&lt;5) { echo "&lt;a href='" . $images[$i][1] . "'&gt;&lt;img src='" . $images[$i][0] . "' /&gt;&lt;/a&gt;"; $i++; } </code></pre>
[ { "answer_id": 280686, "author": "Davide Gualano", "author_id": 28582, "author_profile": "https://Stackoverflow.com/users/28582", "pm_score": 0, "selected": false, "text": "while($i<5)\n{\n $rand = rand(0,(sizeof($images)-1));\n $boxes[$i] = $images[$rand];\n $i++;\n}\n" }, { "answer_id": 280709, "author": "Tom Haigh", "author_id": 22224, "author_profile": "https://Stackoverflow.com/users/22224", "pm_score": 2, "selected": false, "text": "foreach (array_rand($images, 5) as $key) {\n $boxes[] = $images[$key];\n}\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280680", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31677/" ]
280,684
<p>Do web browsers send the file size in the http header when uploading a file to the server? And if that is the case, then, is it possible to refuse the file just by reading the header and not wait for the whole upload process to finish?</p>
[ { "answer_id": 280750, "author": "vincent", "author_id": 34871, "author_profile": "https://Stackoverflow.com/users/34871", "pm_score": 2, "selected": false, "text": "enctype=\"multipart/form-data\" POST / HTTP/1.1\nHost: 127.0.0.1:8000\nUser-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.3) Gecko/2008092414 Firefox/3.0.3\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\nAccept-Language: en-us,en;q=0.7,fr-be;q=0.3\nAccept-Encoding: gzip,deflate\nAccept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\nKeep-Alive: 300\nConnection: keep-alive\nContent-Type: multipart/form-data; boundary=---------------------------886261531333586100294758961\nContent-Length: 135361\n\n-----------------------------886261531333586100294758961\nContent-Disposition: form-data; name=\"\"; filename=\"IMG_1132.jpg\"\nContent-Type: image/jpeg\n\n(data starts here and ends with -----------------------------886261531333586100294758961 )\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280684", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36529/" ]
280,687
<p>I am trying to change the rows output by PHP in a table to links. I have added the a href tags to the example below, however it results in an unexpected <code>T_VARIABLE</code>. I have tried it without the extra quotes, but this displays a blank table. I am not sure what the flaw in the logic is.</p> <pre><code>while($row = mysql_fetch_row($result)) { echo "&lt;tr&gt;"; // $row is array... foreach( .. ) puts every element // of $row to $cell variable foreach($row as $cell) echo "&lt;td&gt;&lt;a href="$cell"&lt;/a&gt;&lt;/td&gt;"; echo "&lt;/tr&gt;\n"; } </code></pre>
[ { "answer_id": 280750, "author": "vincent", "author_id": 34871, "author_profile": "https://Stackoverflow.com/users/34871", "pm_score": 2, "selected": false, "text": "enctype=\"multipart/form-data\" POST / HTTP/1.1\nHost: 127.0.0.1:8000\nUser-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.3) Gecko/2008092414 Firefox/3.0.3\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\nAccept-Language: en-us,en;q=0.7,fr-be;q=0.3\nAccept-Encoding: gzip,deflate\nAccept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\nKeep-Alive: 300\nConnection: keep-alive\nContent-Type: multipart/form-data; boundary=---------------------------886261531333586100294758961\nContent-Length: 135361\n\n-----------------------------886261531333586100294758961\nContent-Disposition: form-data; name=\"\"; filename=\"IMG_1132.jpg\"\nContent-Type: image/jpeg\n\n(data starts here and ends with -----------------------------886261531333586100294758961 )\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280687", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1246613/" ]
280,690
<p>I'm developing an application that is so far using HttpListener to provide a small standalone http server. However, I've recently discovered that HttpListener needs to be run as Administrator, which is not always going to be possible.</p> <p>What would the best alternative be? I need http GET and POST, both of which are not simply reading/writing files on the filesystem, they need to run custom .Net code.</p> <p>My research so far has brought up Cassini, but as far as I can tell, I would have to write a custom version. Is there anything else? In partiular something with the same interface as HttpListener, but that does not require Administrator privileges would be amazing!</p>
[ { "answer_id": 9666157, "author": "ctrlplusb", "author_id": 350933, "author_profile": "https://Stackoverflow.com/users/350933", "pm_score": 2, "selected": false, "text": "netsh http add urlacl url=http://+:8346/ user=\"NTAuthority\\Authenticated Users\" sddl=\"D:(A;;GX;;;AU)\"\n" }, { "answer_id": 31474443, "author": "AlfeG", "author_id": 41483, "author_profile": "https://Stackoverflow.com/users/41483", "pm_score": 0, "selected": false, "text": "Owin ServerFactory HttpListener Microsoft.Owin.Host.HttpListener" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280690", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6448/" ]
280,692
<p>I am creating a form within InfoPath which is to be integrated into a SharePoint 2007 Portal. Within this form there will be a textfield into which a user can enter the Name of a Person. </p> <p>How can I validate whether this Person exists or not?</p> <p>Instead of validating the user, is there a way to fill a dropdown List with <em>all</em> usernames of the portal? (which of cause would be users from the Active Directory)</p>
[ { "answer_id": 415000, "author": "oillio", "author_id": 4354, "author_profile": "https://Stackoverflow.com/users/4354", "pm_score": 0, "selected": false, "text": "string ADName = System.Environment.UserName;\n IXMLDOMDocument3 UserQuery = (IXMLDOMDocument3)thisXDocument.GetDOM(\"GetUsersFromSP\");\n UserQuery.setProperty(\"SelectionNamespaces\",\n \"xmlns:dfs=\\\"http://schemas.microsoft.com/office/infopath/2003/dataFormSolution\\\" \" +\n \"xmlns:tns=\\\"http://schemas.microsoft.com/sharepoint/soap/directory/\\\"\");\n\n ((WebServiceAdapterObject)thisXDocument.DataAdapters[\"GetUsersFromSP\"]).Query();\n\n IXMLDOMNode Users = UserQuery.selectSingleNode(\"//dfs:myFields/dfs:dataFields/tns:GetUserCollectionFromSiteResponse/tns:GetUserCollectionFromSiteResult/tns:GetUserCollectionFromSite/tns:Users\");\n\n foreach (IXMLDOMNode current in Users.selectNodes(\"tns:User\"))\n {\n string Login = current.attributes.getNamedItem(\"LoginName\").text;\n\n Login = Login.ToUpper();\n if (Login.EndsWith(ADName.ToUpper()))\n {\n thisXDocument.DOM.selectSingleNode(\"my:root/my:config/my:User\").text = current.attributes.getNamedItem(\"Name\").text;\n break;\n }\n }\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280692", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25428/" ]
280,706
<p>I've been thinking of ways of providing syntactic sugar for a framework I have been working on. I want to deal with Immitable objects exclusively.</p> <h3>Say I have an immutable object and wish to create a modified version of it. Would, in your view, a non-instantiable class with a single static factory method break OO principles ?</h3> <br> <blockquote> <p>As an example using a String:</p> <pre><code>public final class LOWERCASE { private LOWERCASE() {} public static String string( final String STRING ) { return STRING.toLowerCase(); } } </code></pre> <p>Therefore from this example I could write:</p> <pre><code>String lowercaseString = LOWERCASE.string( targetString ); </code></pre> <p>Which I find very readable.</p> </blockquote> <br> <h3>Any provisos against such an approach?</h3>
[ { "answer_id": 280752, "author": "bruno conde", "author_id": 31136, "author_profile": "https://Stackoverflow.com/users/31136", "pm_score": 1, "selected": false, "text": "public final class Lowercase {\n\n private Lowercase() {}\n\n public static String string( final String string ) {\n\n return new String( string.toLowerCase() );\n }\n\n public static Foo foo( final Foo f ) {\n boolean isLowerCase = true;\n return new Foo(f, isLowerCase );\n }\n}\n" }, { "answer_id": 280863, "author": "Ken Gentle", "author_id": 8709, "author_profile": "https://Stackoverflow.com/users/8709", "pm_score": 1, "selected": false, "text": "new String() String String new String() public static String string( final String string ) {\n return new String( string.toLowerCase() );\n}\n toLowerCase() String new String() String toLowerCase() String a = 'CamelCase'\nString b = a.toLowerCase()\n\nprintln \"a='${a}'\"\nprintln \"b='${b}'\"\n a='CamelCase'\nb='camelcase'\n a b String BigDecimal.movePointLeft() BigDecimal BigDecimal Strings String String static method BigDecimal String" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280706", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4857/" ]
280,712
<p>There should be something akin to <code>\w</code> that can match any code-point in Letters or Marks category (not just the ASCII ones), and hopefully have filters like [[P*]] for punctuation, etc.</p>
[ { "answer_id": 280762, "author": "Tomalak", "author_id": 18771, "author_profile": "https://Stackoverflow.com/users/18771", "pm_score": 8, "selected": false, "text": "u [\\u2000-\\u206F\\u2E00-\\u2E7F]\n" }, { "answer_id": 8933546, "author": "mgibsonbr", "author_id": 520779, "author_profile": "https://Stackoverflow.com/users/520779", "pm_score": 6, "selected": false, "text": "\\p{...} var regex = unicode_hack(/\\p{L}(\\p{L}|\\p{Nd})*/g);\n /[\\u0041-\\u005a\\u0061-\\u007a...]([...]|[\\u0030-\\u0039\\u0660-\\u0669...])*/g\n" }, { "answer_id": 30058779, "author": "fiatjaf", "author_id": 973380, "author_profile": "https://Stackoverflow.com/users/973380", "pm_score": 3, "selected": false, "text": "/[A-Za-z\\u00C0-\\u00FF ]+/.exec('hipopótamo maçã pólen ñ poção água língüa')\n" }, { "answer_id": 30130489, "author": "Daniel", "author_id": 616974, "author_profile": "https://Stackoverflow.com/users/616974", "pm_score": 3, "selected": false, "text": "/^\\p{L}+$/" }, { "answer_id": 37668315, "author": "Laurel", "author_id": 6083675, "author_profile": "https://Stackoverflow.com/users/6083675", "pm_score": 6, "selected": false, "text": "FFFF \\p{L} [A-Za-z\\u00AA\\u00B5\\u00BA\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02C1\\u02C6-\\u02D1\\u02E0-\\u02E4\\u02EC\\u02EE\\u0370-\\u0374\\u0376\\u0377\\u037A-\\u037D\\u037F\\u0386\\u0388-\\u038A\\u038C\\u038E-\\u03A1\\u03A3-\\u03F5\\u03F7-\\u0481\\u048A-\\u052F\\u0531-\\u0556\\u0559\\u0561-\\u0587\\u05D0-\\u05EA\\u05F0-\\u05F2\\u0620-\\u064A\\u066E\\u066F\\u0671-\\u06D3\\u06D5\\u06E5\\u06E6\\u06EE\\u06EF\\u06FA-\\u06FC\\u06FF\\u0710\\u0712-\\u072F\\u074D-\\u07A5\\u07B1\\u07CA-\\u07EA\\u07F4\\u07F5\\u07FA\\u0800-\\u0815\\u081A\\u0824\\u0828\\u0840-\\u0858\\u08A0-\\u08B4\\u0904-\\u0939\\u093D\\u0950\\u0958-\\u0961\\u0971-\\u0980\\u0985-\\u098C\\u098F\\u0990\\u0993-\\u09A8\\u09AA-\\u09B0\\u09B2\\u09B6-\\u09B9\\u09BD\\u09CE\\u09DC\\u09DD\\u09DF-\\u09E1\\u09F0\\u09F1\\u0A05-\\u0A0A\\u0A0F\\u0A10\\u0A13-\\u0A28\\u0A2A-\\u0A30\\u0A32\\u0A33\\u0A35\\u0A36\\u0A38\\u0A39\\u0A59-\\u0A5C\\u0A5E\\u0A72-\\u0A74\\u0A85-\\u0A8D\\u0A8F-\\u0A91\\u0A93-\\u0AA8\\u0AAA-\\u0AB0\\u0AB2\\u0AB3\\u0AB5-\\u0AB9\\u0ABD\\u0AD0\\u0AE0\\u0AE1\\u0AF9\\u0B05-\\u0B0C\\u0B0F\\u0B10\\u0B13-\\u0B28\\u0B2A-\\u0B30\\u0B32\\u0B33\\u0B35-\\u0B39\\u0B3D\\u0B5C\\u0B5D\\u0B5F-\\u0B61\\u0B71\\u0B83\\u0B85-\\u0B8A\\u0B8E-\\u0B90\\u0B92-\\u0B95\\u0B99\\u0B9A\\u0B9C\\u0B9E\\u0B9F\\u0BA3\\u0BA4\\u0BA8-\\u0BAA\\u0BAE-\\u0BB9\\u0BD0\\u0C05-\\u0C0C\\u0C0E-\\u0C10\\u0C12-\\u0C28\\u0C2A-\\u0C39\\u0C3D\\u0C58-\\u0C5A\\u0C60\\u0C61\\u0C85-\\u0C8C\\u0C8E-\\u0C90\\u0C92-\\u0CA8\\u0CAA-\\u0CB3\\u0CB5-\\u0CB9\\u0CBD\\u0CDE\\u0CE0\\u0CE1\\u0CF1\\u0CF2\\u0D05-\\u0D0C\\u0D0E-\\u0D10\\u0D12-\\u0D3A\\u0D3D\\u0D4E\\u0D5F-\\u0D61\\u0D7A-\\u0D7F\\u0D85-\\u0D96\\u0D9A-\\u0DB1\\u0DB3-\\u0DBB\\u0DBD\\u0DC0-\\u0DC6\\u0E01-\\u0E30\\u0E32\\u0E33\\u0E40-\\u0E46\\u0E81\\u0E82\\u0E84\\u0E87\\u0E88\\u0E8A\\u0E8D\\u0E94-\\u0E97\\u0E99-\\u0E9F\\u0EA1-\\u0EA3\\u0EA5\\u0EA7\\u0EAA\\u0EAB\\u0EAD-\\u0EB0\\u0EB2\\u0EB3\\u0EBD\\u0EC0-\\u0EC4\\u0EC6\\u0EDC-\\u0EDF\\u0F00\\u0F40-\\u0F47\\u0F49-\\u0F6C\\u0F88-\\u0F8C\\u1000-\\u102A\\u103F\\u1050-\\u1055\\u105A-\\u105D\\u1061\\u1065\\u1066\\u106E-\\u1070\\u1075-\\u1081\\u108E\\u10A0-\\u10C5\\u10C7\\u10CD\\u10D0-\\u10FA\\u10FC-\\u1248\\u124A-\\u124D\\u1250-\\u1256\\u1258\\u125A-\\u125D\\u1260-\\u1288\\u128A-\\u128D\\u1290-\\u12B0\\u12B2-\\u12B5\\u12B8-\\u12BE\\u12C0\\u12C2-\\u12C5\\u12C8-\\u12D6\\u12D8-\\u1310\\u1312-\\u1315\\u1318-\\u135A\\u1380-\\u138F\\u13A0-\\u13F5\\u13F8-\\u13FD\\u1401-\\u166C\\u166F-\\u167F\\u1681-\\u169A\\u16A0-\\u16EA\\u16F1-\\u16F8\\u1700-\\u170C\\u170E-\\u1711\\u1720-\\u1731\\u1740-\\u1751\\u1760-\\u176C\\u176E-\\u1770\\u1780-\\u17B3\\u17D7\\u17DC\\u1820-\\u1877\\u1880-\\u18A8\\u18AA\\u18B0-\\u18F5\\u1900-\\u191E\\u1950-\\u196D\\u1970-\\u1974\\u1980-\\u19AB\\u19B0-\\u19C9\\u1A00-\\u1A16\\u1A20-\\u1A54\\u1AA7\\u1B05-\\u1B33\\u1B45-\\u1B4B\\u1B83-\\u1BA0\\u1BAE\\u1BAF\\u1BBA-\\u1BE5\\u1C00-\\u1C23\\u1C4D-\\u1C4F\\u1C5A-\\u1C7D\\u1CE9-\\u1CEC\\u1CEE-\\u1CF1\\u1CF5\\u1CF6\\u1D00-\\u1DBF\\u1E00-\\u1F15\\u1F18-\\u1F1D\\u1F20-\\u1F45\\u1F48-\\u1F4D\\u1F50-\\u1F57\\u1F59\\u1F5B\\u1F5D\\u1F5F-\\u1F7D\\u1F80-\\u1FB4\\u1FB6-\\u1FBC\\u1FBE\\u1FC2-\\u1FC4\\u1FC6-\\u1FCC\\u1FD0-\\u1FD3\\u1FD6-\\u1FDB\\u1FE0-\\u1FEC\\u1FF2-\\u1FF4\\u1FF6-\\u1FFC\\u2071\\u207F\\u2090-\\u209C\\u2102\\u2107\\u210A-\\u2113\\u2115\\u2119-\\u211D\\u2124\\u2126\\u2128\\u212A-\\u212D\\u212F-\\u2139\\u213C-\\u213F\\u2145-\\u2149\\u214E\\u2183\\u2184\\u2C00-\\u2C2E\\u2C30-\\u2C5E\\u2C60-\\u2CE4\\u2CEB-\\u2CEE\\u2CF2\\u2CF3\\u2D00-\\u2D25\\u2D27\\u2D2D\\u2D30-\\u2D67\\u2D6F\\u2D80-\\u2D96\\u2DA0-\\u2DA6\\u2DA8-\\u2DAE\\u2DB0-\\u2DB6\\u2DB8-\\u2DBE\\u2DC0-\\u2DC6\\u2DC8-\\u2DCE\\u2DD0-\\u2DD6\\u2DD8-\\u2DDE\\u2E2F\\u3005\\u3006\\u3031-\\u3035\\u303B\\u303C\\u3041-\\u3096\\u309D-\\u309F\\u30A1-\\u30FA\\u30FC-\\u30FF\\u3105-\\u312D\\u3131-\\u318E\\u31A0-\\u31BA\\u31F0-\\u31FF\\u3400-\\u4DB5\\u4E00-\\u9FD5\\uA000-\\uA48C\\uA4D0-\\uA4FD\\uA500-\\uA60C\\uA610-\\uA61F\\uA62A\\uA62B\\uA640-\\uA66E\\uA67F-\\uA69D\\uA6A0-\\uA6E5\\uA717-\\uA71F\\uA722-\\uA788\\uA78B-\\uA7AD\\uA7B0-\\uA7B7\\uA7F7-\\uA801\\uA803-\\uA805\\uA807-\\uA80A\\uA80C-\\uA822\\uA840-\\uA873\\uA882-\\uA8B3\\uA8F2-\\uA8F7\\uA8FB\\uA8FD\\uA90A-\\uA925\\uA930-\\uA946\\uA960-\\uA97C\\uA984-\\uA9B2\\uA9CF\\uA9E0-\\uA9E4\\uA9E6-\\uA9EF\\uA9FA-\\uA9FE\\uAA00-\\uAA28\\uAA40-\\uAA42\\uAA44-\\uAA4B\\uAA60-\\uAA76\\uAA7A\\uAA7E-\\uAAAF\\uAAB1\\uAAB5\\uAAB6\\uAAB9-\\uAABD\\uAAC0\\uAAC2\\uAADB-\\uAADD\\uAAE0-\\uAAEA\\uAAF2-\\uAAF4\\uAB01-\\uAB06\\uAB09-\\uAB0E\\uAB11-\\uAB16\\uAB20-\\uAB26\\uAB28-\\uAB2E\\uAB30-\\uAB5A\\uAB5C-\\uAB65\\uAB70-\\uABE2\\uAC00-\\uD7A3\\uD7B0-\\uD7C6\\uD7CB-\\uD7FB\\uF900-\\uFA6D\\uFA70-\\uFAD9\\uFB00-\\uFB06\\uFB13-\\uFB17\\uFB1D\\uFB1F-\\uFB28\\uFB2A-\\uFB36\\uFB38-\\uFB3C\\uFB3E\\uFB40\\uFB41\\uFB43\\uFB44\\uFB46-\\uFBB1\\uFBD3-\\uFD3D\\uFD50-\\uFD8F\\uFD92-\\uFDC7\\uFDF0-\\uFDFB\\uFE70-\\uFE74\\uFE76-\\uFEFC\\uFF21-\\uFF3A\\uFF41-\\uFF5A\\uFF66-\\uFFBE\\uFFC2-\\uFFC7\\uFFCA-\\uFFCF\\uFFD2-\\uFFD7\\uFFDA-\\uFFDC]\n \\p{Nd} [0-9\\u0660-\\u0669\\u06F0-\\u06F9\\u07C0-\\u07C9\\u0966-\\u096F\\u09E6-\\u09EF\\u0A66-\\u0A6F\\u0AE6-\\u0AEF\\u0B66-\\u0B6F\\u0BE6-\\u0BEF\\u0C66-\\u0C6F\\u0CE6-\\u0CEF\\u0D66-\\u0D6F\\u0DE6-\\u0DEF\\u0E50-\\u0E59\\u0ED0-\\u0ED9\\u0F20-\\u0F29\\u1040-\\u1049\\u1090-\\u1099\\u17E0-\\u17E9\\u1810-\\u1819\\u1946-\\u194F\\u19D0-\\u19D9\\u1A80-\\u1A89\\u1A90-\\u1A99\\u1B50-\\u1B59\\u1BB0-\\u1BB9\\u1C40-\\u1C49\\u1C50-\\u1C59\\uA620-\\uA629\\uA8D0-\\uA8D9\\uA900-\\uA909\\uA9D0-\\uA9D9\\uA9F0-\\uA9F9\\uAA50-\\uAA59\\uABF0-\\uABF9\\uFF10-\\uFF19]\n \\p{P} [!-#%-*,-/\\:;?@\\[-\\]_\\{\\}\\u00A1\\u00A7\\u00AB\\u00B6\\u00B7\\u00BB\\u00BF\\u037E\\u0387\\u055A-\\u055F\\u0589\\u058A\\u05BE\\u05C0\\u05C3\\u05C6\\u05F3\\u05F4\\u0609\\u060A\\u060C\\u060D\\u061B\\u061E\\u061F\\u066A-\\u066D\\u06D4\\u0700-\\u070D\\u07F7-\\u07F9\\u0830-\\u083E\\u085E\\u0964\\u0965\\u0970\\u0AF0\\u0DF4\\u0E4F\\u0E5A\\u0E5B\\u0F04-\\u0F12\\u0F14\\u0F3A-\\u0F3D\\u0F85\\u0FD0-\\u0FD4\\u0FD9\\u0FDA\\u104A-\\u104F\\u10FB\\u1360-\\u1368\\u1400\\u166D\\u166E\\u169B\\u169C\\u16EB-\\u16ED\\u1735\\u1736\\u17D4-\\u17D6\\u17D8-\\u17DA\\u1800-\\u180A\\u1944\\u1945\\u1A1E\\u1A1F\\u1AA0-\\u1AA6\\u1AA8-\\u1AAD\\u1B5A-\\u1B60\\u1BFC-\\u1BFF\\u1C3B-\\u1C3F\\u1C7E\\u1C7F\\u1CC0-\\u1CC7\\u1CD3\\u2010-\\u2027\\u2030-\\u2043\\u2045-\\u2051\\u2053-\\u205E\\u207D\\u207E\\u208D\\u208E\\u2308-\\u230B\\u2329\\u232A\\u2768-\\u2775\\u27C5\\u27C6\\u27E6-\\u27EF\\u2983-\\u2998\\u29D8-\\u29DB\\u29FC\\u29FD\\u2CF9-\\u2CFC\\u2CFE\\u2CFF\\u2D70\\u2E00-\\u2E2E\\u2E30-\\u2E42\\u3001-\\u3003\\u3008-\\u3011\\u3014-\\u301F\\u3030\\u303D\\u30A0\\u30FB\\uA4FE\\uA4FF\\uA60D-\\uA60F\\uA673\\uA67E\\uA6F2-\\uA6F7\\uA874-\\uA877\\uA8CE\\uA8CF\\uA8F8-\\uA8FA\\uA8FC\\uA92E\\uA92F\\uA95F\\uA9C1-\\uA9CD\\uA9DE\\uA9DF\\uAA5C-\\uAA5F\\uAADE\\uAADF\\uAAF0\\uAAF1\\uABEB\\uFD3E\\uFD3F\\uFE10-\\uFE19\\uFE30-\\uFE52\\uFE54-\\uFE61\\uFE63\\uFE68\\uFE6A\\uFE6B\\uFF01-\\uFF03\\uFF05-\\uFF0A\\uFF0C-\\uFF0F\\uFF1A\\uFF1B\\uFF1F\\uFF20\\uFF3B-\\uFF3D\\uFF3F\\uFF5B\\uFF5D\\uFF5F-\\uFF65]\n \\p{Hira} [\\u3041-\\u3096\\u309D-\\u309F]\n" }, { "answer_id": 46413244, "author": "Hamid Hoseini", "author_id": 4826188, "author_profile": "https://Stackoverflow.com/users/4826188", "pm_score": 5, "selected": false, "text": "[^\\u0000-\\u007F]+ function isNonLatinCharacters(s) {\n return /[^\\u0000-\\u007F]/.test(s);\n}\n\nconsole.log(isNonLatinCharacters(\"身分\"));// Japanese\nconsole.log(isNonLatinCharacters(\"测试\"));// Chinese\nconsole.log(isNonLatinCharacters(\"حمید\"));// Persian\nconsole.log(isNonLatinCharacters(\"테스트\"));// Korean\nconsole.log(isNonLatinCharacters(\"परीक्षण\"));// Hindi\nconsole.log(isNonLatinCharacters(\"מִבְחָן\"));// Hebrew" }, { "answer_id": 52205643, "author": "Kamil Kiełczewski", "author_id": 860099, "author_profile": "https://Stackoverflow.com/users/860099", "pm_score": 5, "selected": false, "text": "/\\p{L}/u In below field you should be able to to type letters but not numbers<br>\n<input type=\"text\" name=\"field\" onkeydown=\"return /\\p{L}/u.test(event.key)\" >" }, { "answer_id": 56795591, "author": "Tapan Upadhyay", "author_id": 1155396, "author_profile": "https://Stackoverflow.com/users/1155396", "pm_score": 2, "selected": false, "text": "function myFunction() {\n var str = \"xq234\"; \n var allowChars = \"^[a-zA-ZÀ-ÿ]+$\";\n var res = str.match(allowChars);\n if(!str.match(allowChars)){\n res=\"true\";\n }\n else {\n res=\"false\";\n }\n document.getElementById(\"demo\").innerHTML = res;\n" }, { "answer_id": 58999494, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "(?:[\\u0041-\\u005A\\u00C0-\\u00D6\\u00D8-\\u00DE\\u0100\\u0102\\u0104\\u0106\\u0108\\u010A\\u010C\\u010E\\u0110\\u0112\\u0114\\u0116\\u0118\\u011A\\u011C\\u011E\\u0120\\u0122\\u0124\\u0126\\u0128\\u012A\\u012C\\u012E\\u0130\\u0132\\u0134\\u0136\\u0139\\u013B\\u013D\\u013F\\u0141\\u0143\\u0145\\u0147\\u014A\\u014C\\u014E\\u0150\\u0152\\u0154\\u0156\\u0158\\u015A\\u015C\\u015E\\u0160\\u0162\\u0164\\u0166\\u0168\\u016A\\u016C\\u016E\\u0170\\u0172\\u0174\\u0176\\u0178-\\u0179\\u017B\\u017D\\u0181-\\u0182\\u0184\\u0186-\\u0187\\u0189-\\u018B\\u018E-\\u0191\\u0193-\\u0194\\u0196-\\u0198\\u019C-\\u019D\\u019F-\\u01A0\\u01A2\\u01A4\\u01A6-\\u01A7\\u01A9\\u01AC\\u01AE-\\u01AF\\u01B1-\\u01B3\\u01B5\\u01B7-\\u01B8\\u01BC\\u01C4\\u01C7\\u01CA\\u01CD\\u01CF\\u01D1\\u01D3\\u01D5\\u01D7\\u01D9\\u01DB\\u01DE\\u01E0\\u01E2\\u01E4\\u01E6\\u01E8\\u01EA\\u01EC\\u01EE\\u01F1\\u01F4\\u01F6-\\u01F8\\u01FA\\u01FC\\u01FE\\u0200\\u0202\\u0204\\u0206\\u0208\\u020A\\u020C\\u020E\\u0210\\u0212\\u0214\\u0216\\u0218\\u021A\\u021C\\u021E\\u0220\\u0222\\u0224\\u0226\\u0228\\u022A\\u022C\\u022E\\u0230\\u0232\\u023A-\\u023B\\u023D-\\u023E\\u0241\\u0243-\\u0246\\u0248\\u024A\\u024C\\u024E\\u0370\\u0372\\u0376\\u037F\\u0386\\u0388-\\u038A\\u038C\\u038E-\\u038F\\u0391-\\u03A1\\u03A3-\\u03AB\\u03CF\\u03D2-\\u03D4\\u03D8\\u03DA\\u03DC\\u03DE\\u03E0\\u03E2\\u03E4\\u03E6\\u03E8\\u03EA\\u03EC\\u03EE\\u03F4\\u03F7\\u03F9-\\u03FA\\u03FD-\\u042F\\u0460\\u0462\\u0464\\u0466\\u0468\\u046A\\u046C\\u046E\\u0470\\u0472\\u0474\\u0476\\u0478\\u047A\\u047C\\u047E\\u0480\\u048A\\u048C\\u048E\\u0490\\u0492\\u0494\\u0496\\u0498\\u049A\\u049C\\u049E\\u04A0\\u04A2\\u04A4\\u04A6\\u04A8\\u04AA\\u04AC\\u04AE\\u04B0\\u04B2\\u04B4\\u04B6\\u04B8\\u04BA\\u04BC\\u04BE\\u04C0-\\u04C1\\u04C3\\u04C5\\u04C7\\u04C9\\u04CB\\u04CD\\u04D0\\u04D2\\u04D4\\u04D6\\u04D8\\u04DA\\u04DC\\u04DE\\u04E0\\u04E2\\u04E4\\u04E6\\u04E8\\u04EA\\u04EC\\u04EE\\u04F0\\u04F2\\u04F4\\u04F6\\u04F8\\u04FA\\u04FC\\u04FE\\u0500\\u0502\\u0504\\u0506\\u0508\\u050A\\u050C\\u050E\\u0510\\u0512\\u0514\\u0516\\u0518\\u051A\\u051C\\u051E\\u0520\\u0522\\u0524\\u0526\\u0528\\u052A\\u052C\\u052E\\u0531-\\u0556\\u10A0-\\u10C5\\u10C7\\u10CD\\u13A0-\\u13F5\\u1C90-\\u1CBA\\u1CBD-\\u1CBF\\u1E00\\u1E02\\u1E04\\u1E06\\u1E08\\u1E0A\\u1E0C\\u1E0E\\u1E10\\u1E12\\u1E14\\u1E16\\u1E18\\u1E1A\\u1E1C\\u1E1E\\u1E20\\u1E22\\u1E24\\u1E26\\u1E28\\u1E2A\\u1E2C\\u1E2E\\u1E30\\u1E32\\u1E34\\u1E36\\u1E38\\u1E3A\\u1E3C\\u1E3E\\u1E40\\u1E42\\u1E44\\u1E46\\u1E48\\u1E4A\\u1E4C\\u1E4E\\u1E50\\u1E52\\u1E54\\u1E56\\u1E58\\u1E5A\\u1E5C\\u1E5E\\u1E60\\u1E62\\u1E64\\u1E66\\u1E68\\u1E6A\\u1E6C\\u1E6E\\u1E70\\u1E72\\u1E74\\u1E76\\u1E78\\u1E7A\\u1E7C\\u1E7E\\u1E80\\u1E82\\u1E84\\u1E86\\u1E88\\u1E8A\\u1E8C\\u1E8E\\u1E90\\u1E92\\u1E94\\u1E9E\\u1EA0\\u1EA2\\u1EA4\\u1EA6\\u1EA8\\u1EAA\\u1EAC\\u1EAE\\u1EB0\\u1EB2\\u1EB4\\u1EB6\\u1EB8\\u1EBA\\u1EBC\\u1EBE\\u1EC0\\u1EC2\\u1EC4\\u1EC6\\u1EC8\\u1ECA\\u1ECC\\u1ECE\\u1ED0\\u1ED2\\u1ED4\\u1ED6\\u1ED8\\u1EDA\\u1EDC\\u1EDE\\u1EE0\\u1EE2\\u1EE4\\u1EE6\\u1EE8\\u1EEA\\u1EEC\\u1EEE\\u1EF0\\u1EF2\\u1EF4\\u1EF6\\u1EF8\\u1EFA\\u1EFC\\u1EFE\\u1F08-\\u1F0F\\u1F18-\\u1F1D\\u1F28-\\u1F2F\\u1F38-\\u1F3F\\u1F48-\\u1F4D\\u1F59\\u1F5B\\u1F5D\\u1F5F\\u1F68-\\u1F6F\\u1FB8-\\u1FBB\\u1FC8-\\u1FCB\\u1FD8-\\u1FDB\\u1FE8-\\u1FEC\\u1FF8-\\u1FFB\\u2102\\u2107\\u210B-\\u210D\\u2110-\\u2112\\u2115\\u2119-\\u211D\\u2124\\u2126\\u2128\\u212A-\\u212D\\u2130-\\u2133\\u213E-\\u213F\\u2145\\u2183\\u2C00-\\u2C2E\\u2C60\\u2C62-\\u2C64\\u2C67\\u2C69\\u2C6B\\u2C6D-\\u2C70\\u2C72\\u2C75\\u2C7E-\\u2C80\\u2C82\\u2C84\\u2C86\\u2C88\\u2C8A\\u2C8C\\u2C8E\\u2C90\\u2C92\\u2C94\\u2C96\\u2C98\\u2C9A\\u2C9C\\u2C9E\\u2CA0\\u2CA2\\u2CA4\\u2CA6\\u2CA8\\u2CAA\\u2CAC\\u2CAE\\u2CB0\\u2CB2\\u2CB4\\u2CB6\\u2CB8\\u2CBA\\u2CBC\\u2CBE\\u2CC0\\u2CC2\\u2CC4\\u2CC6\\u2CC8\\u2CCA\\u2CCC\\u2CCE\\u2CD0\\u2CD2\\u2CD4\\u2CD6\\u2CD8\\u2CDA\\u2CDC\\u2CDE\\u2CE0\\u2CE2\\u2CEB\\u2CED\\u2CF2\\uA640\\uA642\\uA644\\uA646\\uA648\\uA64A\\uA64C\\uA64E\\uA650\\uA652\\uA654\\uA656\\uA658\\uA65A\\uA65C\\uA65E\\uA660\\uA662\\uA664\\uA666\\uA668\\uA66A\\uA66C\\uA680\\uA682\\uA684\\uA686\\uA688\\uA68A\\uA68C\\uA68E\\uA690\\uA692\\uA694\\uA696\\uA698\\uA69A\\uA722\\uA724\\uA726\\uA728\\uA72A\\uA72C\\uA72E\\uA732\\uA734\\uA736\\uA738\\uA73A\\uA73C\\uA73E\\uA740\\uA742\\uA744\\uA746\\uA748\\uA74A\\uA74C\\uA74E\\uA750\\uA752\\uA754\\uA756\\uA758\\uA75A\\uA75C\\uA75E\\uA760\\uA762\\uA764\\uA766\\uA768\\uA76A\\uA76C\\uA76E\\uA779\\uA77B\\uA77D-\\uA77E\\uA780\\uA782\\uA784\\uA786\\uA78B\\uA78D\\uA790\\uA792\\uA796\\uA798\\uA79A\\uA79C\\uA79E\\uA7A0\\uA7A2\\uA7A4\\uA7A6\\uA7A8\\uA7AA-\\uA7AE\\uA7B0-\\uA7B4\\uA7B6\\uA7B8\\uA7BA\\uA7BC\\uA7BE\\uA7C2\\uA7C4-\\uA7C6\\uFF21-\\uFF3A]|(?:\\uD801[\\uDC00-\\uDC27\\uDCB0-\\uDCD3]|\\uD803[\\uDC80-\\uDCB2]|\\uD806[\\uDCA0-\\uDCBF]|\\uD81B[\\uDE40-\\uDE5F]|\\uD835[\\uDC00-\\uDC19\\uDC34-\\uDC4D\\uDC68-\\uDC81\\uDC9C\\uDC9E-\\uDC9F\\uDCA2\\uDCA5-\\uDCA6\\uDCA9-\\uDCAC\\uDCAE-\\uDCB5\\uDCD0-\\uDCE9\\uDD04-\\uDD05\\uDD07-\\uDD0A\\uDD0D-\\uDD14\\uDD16-\\uDD1C\\uDD38-\\uDD39\\uDD3B-\\uDD3E\\uDD40-\\uDD44\\uDD46\\uDD4A-\\uDD50\\uDD6C-\\uDD85\\uDDA0-\\uDDB9\\uDDD4-\\uDDED\\uDE08-\\uDE21\\uDE3C-\\uDE55\\uDE70-\\uDE89\\uDEA8-\\uDEC0\\uDEE2-\\uDEFA\\uDF1C-\\uDF34\\uDF56-\\uDF6E\\uDF90-\\uDFA8\\uDFCA]|\\uD83A[\\uDD00-\\uDD21]))\n (?:[\\u0061-\\u007A\\u00B5\\u00DF-\\u00F6\\u00F8-\\u00FF\\u0101\\u0103\\u0105\\u0107\\u0109\\u010B\\u010D\\u010F\\u0111\\u0113\\u0115\\u0117\\u0119\\u011B\\u011D\\u011F\\u0121\\u0123\\u0125\\u0127\\u0129\\u012B\\u012D\\u012F\\u0131\\u0133\\u0135\\u0137-\\u0138\\u013A\\u013C\\u013E\\u0140\\u0142\\u0144\\u0146\\u0148-\\u0149\\u014B\\u014D\\u014F\\u0151\\u0153\\u0155\\u0157\\u0159\\u015B\\u015D\\u015F\\u0161\\u0163\\u0165\\u0167\\u0169\\u016B\\u016D\\u016F\\u0171\\u0173\\u0175\\u0177\\u017A\\u017C\\u017E-\\u0180\\u0183\\u0185\\u0188\\u018C-\\u018D\\u0192\\u0195\\u0199-\\u019B\\u019E\\u01A1\\u01A3\\u01A5\\u01A8\\u01AA-\\u01AB\\u01AD\\u01B0\\u01B4\\u01B6\\u01B9-\\u01BA\\u01BD-\\u01BF\\u01C6\\u01C9\\u01CC\\u01CE\\u01D0\\u01D2\\u01D4\\u01D6\\u01D8\\u01DA\\u01DC-\\u01DD\\u01DF\\u01E1\\u01E3\\u01E5\\u01E7\\u01E9\\u01EB\\u01ED\\u01EF-\\u01F0\\u01F3\\u01F5\\u01F9\\u01FB\\u01FD\\u01FF\\u0201\\u0203\\u0205\\u0207\\u0209\\u020B\\u020D\\u020F\\u0211\\u0213\\u0215\\u0217\\u0219\\u021B\\u021D\\u021F\\u0221\\u0223\\u0225\\u0227\\u0229\\u022B\\u022D\\u022F\\u0231\\u0233-\\u0239\\u023C\\u023F-\\u0240\\u0242\\u0247\\u0249\\u024B\\u024D\\u024F-\\u0293\\u0295-\\u02AF\\u0371\\u0373\\u0377\\u037B-\\u037D\\u0390\\u03AC-\\u03CE\\u03D0-\\u03D1\\u03D5-\\u03D7\\u03D9\\u03DB\\u03DD\\u03DF\\u03E1\\u03E3\\u03E5\\u03E7\\u03E9\\u03EB\\u03ED\\u03EF-\\u03F3\\u03F5\\u03F8\\u03FB-\\u03FC\\u0430-\\u045F\\u0461\\u0463\\u0465\\u0467\\u0469\\u046B\\u046D\\u046F\\u0471\\u0473\\u0475\\u0477\\u0479\\u047B\\u047D\\u047F\\u0481\\u048B\\u048D\\u048F\\u0491\\u0493\\u0495\\u0497\\u0499\\u049B\\u049D\\u049F\\u04A1\\u04A3\\u04A5\\u04A7\\u04A9\\u04AB\\u04AD\\u04AF\\u04B1\\u04B3\\u04B5\\u04B7\\u04B9\\u04BB\\u04BD\\u04BF\\u04C2\\u04C4\\u04C6\\u04C8\\u04CA\\u04CC\\u04CE-\\u04CF\\u04D1\\u04D3\\u04D5\\u04D7\\u04D9\\u04DB\\u04DD\\u04DF\\u04E1\\u04E3\\u04E5\\u04E7\\u04E9\\u04EB\\u04ED\\u04EF\\u04F1\\u04F3\\u04F5\\u04F7\\u04F9\\u04FB\\u04FD\\u04FF\\u0501\\u0503\\u0505\\u0507\\u0509\\u050B\\u050D\\u050F\\u0511\\u0513\\u0515\\u0517\\u0519\\u051B\\u051D\\u051F\\u0521\\u0523\\u0525\\u0527\\u0529\\u052B\\u052D\\u052F\\u0560-\\u0588\\u10D0-\\u10FA\\u10FD-\\u10FF\\u13F8-\\u13FD\\u1C80-\\u1C88\\u1D00-\\u1D2B\\u1D6B-\\u1D77\\u1D79-\\u1D9A\\u1E01\\u1E03\\u1E05\\u1E07\\u1E09\\u1E0B\\u1E0D\\u1E0F\\u1E11\\u1E13\\u1E15\\u1E17\\u1E19\\u1E1B\\u1E1D\\u1E1F\\u1E21\\u1E23\\u1E25\\u1E27\\u1E29\\u1E2B\\u1E2D\\u1E2F\\u1E31\\u1E33\\u1E35\\u1E37\\u1E39\\u1E3B\\u1E3D\\u1E3F\\u1E41\\u1E43\\u1E45\\u1E47\\u1E49\\u1E4B\\u1E4D\\u1E4F\\u1E51\\u1E53\\u1E55\\u1E57\\u1E59\\u1E5B\\u1E5D\\u1E5F\\u1E61\\u1E63\\u1E65\\u1E67\\u1E69\\u1E6B\\u1E6D\\u1E6F\\u1E71\\u1E73\\u1E75\\u1E77\\u1E79\\u1E7B\\u1E7D\\u1E7F\\u1E81\\u1E83\\u1E85\\u1E87\\u1E89\\u1E8B\\u1E8D\\u1E8F\\u1E91\\u1E93\\u1E95-\\u1E9D\\u1E9F\\u1EA1\\u1EA3\\u1EA5\\u1EA7\\u1EA9\\u1EAB\\u1EAD\\u1EAF\\u1EB1\\u1EB3\\u1EB5\\u1EB7\\u1EB9\\u1EBB\\u1EBD\\u1EBF\\u1EC1\\u1EC3\\u1EC5\\u1EC7\\u1EC9\\u1ECB\\u1ECD\\u1ECF\\u1ED1\\u1ED3\\u1ED5\\u1ED7\\u1ED9\\u1EDB\\u1EDD\\u1EDF\\u1EE1\\u1EE3\\u1EE5\\u1EE7\\u1EE9\\u1EEB\\u1EED\\u1EEF\\u1EF1\\u1EF3\\u1EF5\\u1EF7\\u1EF9\\u1EFB\\u1EFD\\u1EFF-\\u1F07\\u1F10-\\u1F15\\u1F20-\\u1F27\\u1F30-\\u1F37\\u1F40-\\u1F45\\u1F50-\\u1F57\\u1F60-\\u1F67\\u1F70-\\u1F7D\\u1F80-\\u1F87\\u1F90-\\u1F97\\u1FA0-\\u1FA7\\u1FB0-\\u1FB4\\u1FB6-\\u1FB7\\u1FBE\\u1FC2-\\u1FC4\\u1FC6-\\u1FC7\\u1FD0-\\u1FD3\\u1FD6-\\u1FD7\\u1FE0-\\u1FE7\\u1FF2-\\u1FF4\\u1FF6-\\u1FF7\\u210A\\u210E-\\u210F\\u2113\\u212F\\u2134\\u2139\\u213C-\\u213D\\u2146-\\u2149\\u214E\\u2184\\u2C30-\\u2C5E\\u2C61\\u2C65-\\u2C66\\u2C68\\u2C6A\\u2C6C\\u2C71\\u2C73-\\u2C74\\u2C76-\\u2C7B\\u2C81\\u2C83\\u2C85\\u2C87\\u2C89\\u2C8B\\u2C8D\\u2C8F\\u2C91\\u2C93\\u2C95\\u2C97\\u2C99\\u2C9B\\u2C9D\\u2C9F\\u2CA1\\u2CA3\\u2CA5\\u2CA7\\u2CA9\\u2CAB\\u2CAD\\u2CAF\\u2CB1\\u2CB3\\u2CB5\\u2CB7\\u2CB9\\u2CBB\\u2CBD\\u2CBF\\u2CC1\\u2CC3\\u2CC5\\u2CC7\\u2CC9\\u2CCB\\u2CCD\\u2CCF\\u2CD1\\u2CD3\\u2CD5\\u2CD7\\u2CD9\\u2CDB\\u2CDD\\u2CDF\\u2CE1\\u2CE3-\\u2CE4\\u2CEC\\u2CEE\\u2CF3\\u2D00-\\u2D25\\u2D27\\u2D2D\\uA641\\uA643\\uA645\\uA647\\uA649\\uA64B\\uA64D\\uA64F\\uA651\\uA653\\uA655\\uA657\\uA659\\uA65B\\uA65D\\uA65F\\uA661\\uA663\\uA665\\uA667\\uA669\\uA66B\\uA66D\\uA681\\uA683\\uA685\\uA687\\uA689\\uA68B\\uA68D\\uA68F\\uA691\\uA693\\uA695\\uA697\\uA699\\uA69B\\uA723\\uA725\\uA727\\uA729\\uA72B\\uA72D\\uA72F-\\uA731\\uA733\\uA735\\uA737\\uA739\\uA73B\\uA73D\\uA73F\\uA741\\uA743\\uA745\\uA747\\uA749\\uA74B\\uA74D\\uA74F\\uA751\\uA753\\uA755\\uA757\\uA759\\uA75B\\uA75D\\uA75F\\uA761\\uA763\\uA765\\uA767\\uA769\\uA76B\\uA76D\\uA76F\\uA771-\\uA778\\uA77A\\uA77C\\uA77F\\uA781\\uA783\\uA785\\uA787\\uA78C\\uA78E\\uA791\\uA793-\\uA795\\uA797\\uA799\\uA79B\\uA79D\\uA79F\\uA7A1\\uA7A3\\uA7A5\\uA7A7\\uA7A9\\uA7AF\\uA7B5\\uA7B7\\uA7B9\\uA7BB\\uA7BD\\uA7BF\\uA7C3\\uA7FA\\uAB30-\\uAB5A\\uAB60-\\uAB67\\uAB70-\\uABBF\\uFB00-\\uFB06\\uFB13-\\uFB17\\uFF41-\\uFF5A]|(?:\\uD801[\\uDC28-\\uDC4F\\uDCD8-\\uDCFB]|\\uD803[\\uDCC0-\\uDCF2]|\\uD806[\\uDCC0-\\uDCDF]|\\uD81B[\\uDE60-\\uDE7F]|\\uD835[\\uDC1A-\\uDC33\\uDC4E-\\uDC54\\uDC56-\\uDC67\\uDC82-\\uDC9B\\uDCB6-\\uDCB9\\uDCBB\\uDCBD-\\uDCC3\\uDCC5-\\uDCCF\\uDCEA-\\uDD03\\uDD1E-\\uDD37\\uDD52-\\uDD6B\\uDD86-\\uDD9F\\uDDBA-\\uDDD3\\uDDEE-\\uDE07\\uDE22-\\uDE3B\\uDE56-\\uDE6F\\uDE8A-\\uDEA5\\uDEC2-\\uDEDA\\uDEDC-\\uDEE1\\uDEFC-\\uDF14\\uDF16-\\uDF1B\\uDF36-\\uDF4E\\uDF50-\\uDF55\\uDF70-\\uDF88\\uDF8A-\\uDF8F\\uDFAA-\\uDFC2\\uDFC4-\\uDFC9\\uDFCB]|\\uD83A[\\uDD22-\\uDD43]))\n Regex1: LONG CLASS \n< none >\nCompleted iterations: 50 / 50 ( x 1 )\nMatches found per iteration: 1788\nElapsed Time: 0.73 s, 727.58 ms, 727584 µs\nMatches per sec: 122,872\n\n\nRegex2: \\p{Lu}\nOptions: < ICU - none >\nCompleted iterations: 50 / 50 ( x 1 )\nMatches found per iteration: 1788\nElapsed Time: 0.07 s, 65.32 ms, 65323 µs\nMatches per sec: 1,368,583\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280712", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
280,713
<p>Does the "for…in" loop in Javascript loop through the hashtables/elements in the order they are declared? Is there a browser which doesn't do it in order?<br> The object I wish to use will be declared <em>once</em> and will never be modified.</p> <p>Suppose I have:</p> <pre><code>var myObject = { A: "Hello", B: "World" }; </code></pre> <p>And I further use them in:</p> <pre><code>for (var item in myObject) alert(item + " : " + myObject[item]); </code></pre> <p>Can I expect 'A : "Hello"' to always come before 'B : "World"' in most decent browsers?</p>
[ { "answer_id": 280734, "author": "Tomalak", "author_id": 18771, "author_profile": "https://Stackoverflow.com/users/18771", "pm_score": 5, "selected": false, "text": "for .. in" }, { "answer_id": 280861, "author": "Borgar", "author_id": 27388, "author_profile": "https://Stackoverflow.com/users/27388", "pm_score": 9, "selected": true, "text": "Object.keys var obj = {\n \"first\":\"first\",\n \"2\":\"2\",\n \"34\":\"34\",\n \"1\":\"1\",\n \"second\":\"second\"\n};\nfor (var i in obj) { console.log(i); };\n// Order listed:\n// \"1\"\n// \"2\"\n// \"34\"\n// \"first\"\n// \"second\"\n" }, { "answer_id": 3567208, "author": "Kouber Saparev", "author_id": 83108, "author_profile": "https://Stackoverflow.com/users/83108", "pm_score": 2, "selected": false, "text": "<script type=\"text/javascript\">\nvar username = {\"14719\":\"A\",\"648\":\"B\",\"15185\":\"C\"};\n\nfor (var i in username) {\n window.alert(i + ' => ' + username[i]);\n}\n</script>\n" }, { "answer_id": 4591510, "author": "Brett Zamir", "author_id": 271577, "author_profile": "https://Stackoverflow.com/users/271577", "pm_score": 3, "selected": false, "text": "var obj = {};\nobj.a = 'a';\nobj.b = 'b';\nobj.c = 'c';\n\n// IE allows the value to be deleted...\ndelete obj.b;\n\n// ...but remembers the old position if it is added back later\nobj.b = 'bb';\nfor (var p in obj) {\n alert(obj[p]); // in IE, will be a, bb, then c;\n // not a, c, then bb as for FF/Chrome/Opera/Safari\n}\n" }, { "answer_id": 8704349, "author": "dvdrtrgn", "author_id": 94778, "author_profile": "https://Stackoverflow.com/users/94778", "pm_score": 6, "selected": false, "text": "function lineate(obj){\n var arr = [], i;\n for (i in obj) arr.push([i,obj[i]].join(':'));\n console.log(arr);\n}\nvar obj = { a:1, b:2, c:3, \"123\":'xyz' };\n/* log1 */ lineate(obj);\nobj.a = 4;\n/* log2 */ lineate(obj);\ndelete obj.a;\nobj.a = 4;\n/* log3 */ lineate(obj);\n [\"a:1\", \"b:2\", \"c:3\", \"123:xyz\"]\n[\"a:4\", \"b:2\", \"c:3\", \"123:xyz\"]\n[\"b:2\", \"c:3\", \"123:xyz\", \"a:4\"]\n [\"123:xyz\", \"a:1\", \"b:2\", \"c:3\"]\n[\"123:xyz\", \"a:4\", \"b:2\", \"c:3\"]\n[\"123:xyz\", \"b:2\", \"c:3\", \"a:4\"]\n [123:xyz,a:1,b:2,c:3] \n[123:xyz,a:4,b:2,c:3] \n[123:xyz,a:4,b:2,c:3] \n" }, { "answer_id": 50091737, "author": "JDQ", "author_id": 3662499, "author_profile": "https://Stackoverflow.com/users/3662499", "pm_score": 2, "selected": false, "text": "var myArray = [\n {\n 'key' : 'key1'\n 'value' : 0\n },\n {\n 'key' : 'key2',\n 'value' : 1\n } // ...\n];\n for (...in...) > console.log(myArray[0].key);\nkey1\n\n> for (let index in myArray) {console.log(myArray[index].value);}\n0\n1\n" }, { "answer_id": 63355429, "author": "Thierry J.", "author_id": 1710784, "author_profile": "https://Stackoverflow.com/users/1710784", "pm_score": 2, "selected": false, "text": "let keys = Object.keys(myObject);\nfor (let key of keys.sort()) {\n let value = myObject[key];\n \n // Do what you want with key and value \n}\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280713", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3055/" ]
280,729
<p>I am trying to use the following code to write data into an excel file</p> <pre><code> Dim objexcel As Excel.Application Dim wbexcel As Excel.Workbook Dim wbExists As Boolean Set objexcel = CreateObject("excel.Application") objexcel.Visible = True On Error GoTo Openwb wbExists = False Set wbexcel = objexcel.Documents.Open("C:\Documents and Settings\TAYYAPP\Desktop\test folder\ERROR REPORT2.xls") wbExists = True Openwb: On Error GoTo 0 If Not wbExists Then Set wbexcel = objexcel.Workbook.Add End If </code></pre> <p>but I'm getting an </p> <blockquote> <p>runtime error object doesn't support property or method</p> </blockquote> <p>in the line</p> <pre><code>Set wbexcel = objexcel.Workbook.Add </code></pre> <p>I have referenced the Excel object library.</p>
[ { "answer_id": 280758, "author": "Fionnuala", "author_id": 2548, "author_profile": "https://Stackoverflow.com/users/2548", "pm_score": 4, "selected": true, "text": " Set wbexcel = objexcel.WorkBooks.Open( _\n \"C:\\Documents and Settings\\TAYYAPP\\Desktop\\test folder\\ERROR REPORT2.xls\") \n objexcel.Workbooks.Add\nSet wbexcel = objexcel.ActiveWorkbook\n" }, { "answer_id": 286626, "author": "tksy", "author_id": 31132, "author_profile": "https://Stackoverflow.com/users/31132", "pm_score": 0, "selected": false, "text": "Dim objexcel As Excel.Application\n Dim wbexcel As Excel.Workbook\n Dim wbExists As Boolean\n Dim objSht As Excel.Worksheet\n Dim objRange As Excel.Range\n\n\n Set objexcel = CreateObject(\"excel.Application\")\n objexcel.Visible = True\n On Error GoTo Openwb\n wbExists = False\n Set wbexcel = objexcel.Workbooks.Open(\"C:\\Documents and Settings\\TAYYAPP\\Desktop\\test folder\\reports\\ERROR REPORT2.xls\")\n Set objSht = wbexcel.Worksheets(\"Sheet1\")\n objSht.Activate\n wbExists = True\nOpenwb:\n\n On Error GoTo 0\n If Not wbExists Then\n objexcel.Workbooks.Add\n Set wbexcel = objexcel.ActiveWorkbook\n Set objSht = wbexcel.Worksheets(\"Sheet1\")\n\n End If\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280729", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31132/" ]
280,748
<p>I have a T4 template that generates classes from an xml file. </p> <p>How can I add a dependency between the xml file and the template file so that when the xml file is modified the template is rerun automatically without choosing "Run custom tool" from the context menu?</p>
[ { "answer_id": 280827, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 2, "selected": false, "text": "<Exec ... /> targets" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280748", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4685/" ]
280,749
<p>I have some directories that are bundled with my installer and I need to access them from within a custom action. I have done some research and seen that the SourceDir can be used to obtain the currently executing dir location. However I cannot find any examples of how to obtain this property? Or another way to obtain the current directory?</p> <p>Can anyone advise or point me to anything other than the unhelpful Microsoft site?</p>
[ { "answer_id": 282465, "author": "w4g3n3r", "author_id": 36745, "author_profile": "https://Stackoverflow.com/users/36745", "pm_score": 1, "selected": false, "text": "strSourceDir = Session.Property(\"SourceDir\")\n" }, { "answer_id": 1004783, "author": "Chris", "author_id": 203114, "author_profile": "https://Stackoverflow.com/users/203114", "pm_score": 1, "selected": false, "text": "[CustomAction]\npublic static ActionResult MyCustomAction(Session session)\n{\n string sourceDir = session[\"SourceDir\"];\n string path = Path.Combine(sourceDir, \"yourfilename.txt\");\n ...\n" }, { "answer_id": 1004812, "author": "William Leara", "author_id": 116166, "author_profile": "https://Stackoverflow.com/users/116166", "pm_score": 0, "selected": false, "text": "MsiGetProperty(hMSI, \"CustomActionData\", strDirectory, numBuffer);\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280749", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
280,751
<p>I have a large c# solution file (~100 projects), and I am trying to improve build times. I think that "Copy Local" is wasteful in many cases for us, but I am wondering about best practices.</p> <p>In our .sln, we have application A depending on assembly B which depends on assembly C. In our case, there are dozens of "B" and a handful of "C". Since these are all included in the .sln, we're using project references. All assemblies currently build into $(SolutionDir)/Debug (or Release).</p> <p>By default, Visual Studio marks these project references as "Copy Local", which results in every "C" being copied into $(SolutionDir)/Debug once for every "B" that builds. This seems wasteful. What can go wrong if I just turn "Copy Local" off? What do other people with large systems do?</p> <p>FOLLOWUP:</p> <p>Lots of responses suggest breaking up the build into smaller .sln files... In the example above, I would build the foundation classes "C" first, followed by the bulk of the modules "B", and then a few applications, "A". In this model, I need to have non-project references to C from B. The problem I run into there is that "Debug" or "Release" gets baked into the hint path and I wind up building my Release builds of "B" against debug builds of "C". </p> <p>For those of you that split the build up into multiple .sln files, how do you manage this problem?</p>
[ { "answer_id": 280804, "author": "Aleksandar", "author_id": 29511, "author_profile": "https://Stackoverflow.com/users/29511", "pm_score": 1, "selected": false, "text": "<developmentMode developerInstallation=\"true\" />" }, { "answer_id": 283808, "author": "Bruno Shine", "author_id": 28294, "author_profile": "https://Stackoverflow.com/users/28294", "pm_score": 0, "selected": false, "text": "/p:Configuration=Release" }, { "answer_id": 649771, "author": "Bas Bossink", "author_id": 74198, "author_profile": "https://Stackoverflow.com/users/74198", "pm_score": 7, "selected": true, "text": "GetCopyToOutputDirectoryItems Common.targets Microsoft.CSharp.targets <Project DefaultTargets=\"Build\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n <PropertyGroup>\n ... snip ...\n </ItemGroup>\n <Import Project=\"$(MSBuildBinPath)\\Microsoft.CSharp.targets\" />\n <Import Project=\"[relative path to Common.targets]\" />\n <!-- To modify your build process, add your task inside one of the targets below and uncomment it. \n Other similar extension points exist, see Microsoft.Common.targets.\n <Target Name=\"BeforeBuild\">\n </Target>\n <Target Name=\"AfterBuild\">\n </Target>\n -->\n</Project>\n GetCopyToOutputDirectoryItems C:\\WINDOWS\\Microsoft.NET\\Framework\\v2.0.50727\\Microsoft.Common.targets Common.targets <!-- This is a modified version of the Microsoft.Common.targets\n version of this target it does not include transitively\n referenced projects. Since this leads to enormous memory\n consumption and is not needed since we use the single\n output directory strategy.\n============================================================\n GetCopyToOutputDirectoryItems\n\nGet all project items that may need to be transferred to the\noutput directory.\n============================================================ -->\n<Target\n Name=\"GetCopyToOutputDirectoryItems\"\n Outputs=\"@(AllItemsFullPathWithTargetPath)\"\n DependsOnTargets=\"AssignTargetPaths;_SplitProjectReferencesByFileExistence\">\n\n <!-- Get items from this project last so that they will be copied last. -->\n <CreateItem\n Include=\"@(ContentWithTargetPath->'%(FullPath)')\"\n Condition=\"'%(ContentWithTargetPath.CopyToOutputDirectory)'=='Always' or '%(ContentWithTargetPath.CopyToOutputDirectory)'=='PreserveNewest'\"\n >\n <Output TaskParameter=\"Include\" ItemName=\"AllItemsFullPathWithTargetPath\"/>\n <Output TaskParameter=\"Include\" ItemName=\"_SourceItemsToCopyToOutputDirectoryAlways\"\n Condition=\"'%(ContentWithTargetPath.CopyToOutputDirectory)'=='Always'\"/>\n <Output TaskParameter=\"Include\" ItemName=\"_SourceItemsToCopyToOutputDirectory\"\n Condition=\"'%(ContentWithTargetPath.CopyToOutputDirectory)'=='PreserveNewest'\"/>\n </CreateItem>\n\n <CreateItem\n Include=\"@(_EmbeddedResourceWithTargetPath->'%(FullPath)')\"\n Condition=\"'%(_EmbeddedResourceWithTargetPath.CopyToOutputDirectory)'=='Always' or '%(_EmbeddedResourceWithTargetPath.CopyToOutputDirectory)'=='PreserveNewest'\"\n >\n <Output TaskParameter=\"Include\" ItemName=\"AllItemsFullPathWithTargetPath\"/>\n <Output TaskParameter=\"Include\" ItemName=\"_SourceItemsToCopyToOutputDirectoryAlways\"\n Condition=\"'%(_EmbeddedResourceWithTargetPath.CopyToOutputDirectory)'=='Always'\"/>\n <Output TaskParameter=\"Include\" ItemName=\"_SourceItemsToCopyToOutputDirectory\"\n Condition=\"'%(_EmbeddedResourceWithTargetPath.CopyToOutputDirectory)'=='PreserveNewest'\"/>\n </CreateItem>\n\n <CreateItem\n Include=\"@(Compile->'%(FullPath)')\"\n Condition=\"'%(Compile.CopyToOutputDirectory)'=='Always' or '%(Compile.CopyToOutputDirectory)'=='PreserveNewest'\">\n <Output TaskParameter=\"Include\" ItemName=\"_CompileItemsToCopy\"/>\n </CreateItem>\n <AssignTargetPath Files=\"@(_CompileItemsToCopy)\" RootFolder=\"$(MSBuildProjectDirectory)\">\n <Output TaskParameter=\"AssignedFiles\" ItemName=\"_CompileItemsToCopyWithTargetPath\" />\n </AssignTargetPath>\n <CreateItem Include=\"@(_CompileItemsToCopyWithTargetPath)\">\n <Output TaskParameter=\"Include\" ItemName=\"AllItemsFullPathWithTargetPath\"/>\n <Output TaskParameter=\"Include\" ItemName=\"_SourceItemsToCopyToOutputDirectoryAlways\"\n Condition=\"'%(_CompileItemsToCopyWithTargetPath.CopyToOutputDirectory)'=='Always'\"/>\n <Output TaskParameter=\"Include\" ItemName=\"_SourceItemsToCopyToOutputDirectory\"\n Condition=\"'%(_CompileItemsToCopyWithTargetPath.CopyToOutputDirectory)'=='PreserveNewest'\"/>\n </CreateItem>\n\n <CreateItem\n Include=\"@(_NoneWithTargetPath->'%(FullPath)')\"\n Condition=\"'%(_NoneWithTargetPath.CopyToOutputDirectory)'=='Always' or '%(_NoneWithTargetPath.CopyToOutputDirectory)'=='PreserveNewest'\"\n >\n <Output TaskParameter=\"Include\" ItemName=\"AllItemsFullPathWithTargetPath\"/>\n <Output TaskParameter=\"Include\" ItemName=\"_SourceItemsToCopyToOutputDirectoryAlways\"\n Condition=\"'%(_NoneWithTargetPath.CopyToOutputDirectory)'=='Always'\"/>\n <Output TaskParameter=\"Include\" ItemName=\"_SourceItemsToCopyToOutputDirectory\"\n Condition=\"'%(_NoneWithTargetPath.CopyToOutputDirectory)'=='PreserveNewest'\"/>\n </CreateItem>\n</Target>\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280751", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6996/" ]
280,759
<p>I am using the <strong><a href="http://en.wikipedia.org/wiki/JQuery" rel="noreferrer">jQuery</a> validation plugin</strong>. Great stuff! I want to migrate my existing ASP.NET solution to use jQuery instead of the ASP.NET validators. I am missing a replacement for the <strong>regular expression</strong> validator. I want to be able to do something like this:</p> <pre><code>$("Textbox").rules("add", { regularExpression: "^[a-zA-Z'.\s]{1,40}$" }) </code></pre> <p>How do I <strong>add a custom rule</strong> to achieve this?</p>
[ { "answer_id": 280952, "author": "redsquare", "author_id": 6440, "author_profile": "https://Stackoverflow.com/users/6440", "pm_score": 6, "selected": false, "text": "$.validator.addMethod('postalCode', function (value) { \n return /^((\\d{5}-\\d{4})|(\\d{5})|([A-Z]\\d[A-Z]\\s\\d[A-Z]\\d))$/.test(value); \n}, 'Please enter a valid US or Canadian postal code.');\n" }, { "answer_id": 709358, "author": "PeterFromCologne", "author_id": 36546, "author_profile": "https://Stackoverflow.com/users/36546", "pm_score": 9, "selected": true, "text": "$.validator.addMethod(\n \"regex\",\n function(value, element, regexp) {\n var re = new RegExp(regexp);\n return this.optional(element) || re.test(value);\n },\n \"Please check your input.\"\n);\n $(\"#Textbox\").rules(\"add\", { regex: \"^[a-zA-Z'.\\\\s]{1,40}$\" })\n additional-methods.js RegExp pattern $(\"#Textbox\").rules(\"add\", { pattern: \"^[a-zA-Z'.\\\\s]{1,40}$\" })\n" }, { "answer_id": 843611, "author": "Markus Jarderot", "author_id": 22364, "author_profile": "https://Stackoverflow.com/users/22364", "pm_score": 5, "selected": false, "text": "$.validator.addMethod(\n \"regex\",\n function(value, element, regexp) {\n if (regexp.constructor != RegExp)\n regexp = new RegExp(regexp);\n else if (regexp.global)\n regexp.lastIndex = 0;\n return this.optional(element) || regexp.test(value);\n },\n \"Please check your input.\"\n);\n $(\"Textbox\").rules(\"add\", { regex: /^[a-zA-Z'.\\s]{1,40}$/ });\n lastIndex g RegExp $(\"password\").rules(\"add\", {\n regex: [\n /^[a-zA-Z'.\\s]{8,40}$/,\n /^.*[a-z].*$/,\n /^.*[A-Z].*$/,\n /^.*[0-9].*$/\n ],\n '!regex': /password|123/\n});\n" }, { "answer_id": 1217344, "author": "bshack", "author_id": 149057, "author_profile": "https://Stackoverflow.com/users/149057", "pm_score": 6, "selected": false, "text": "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n <script src=\"http://YOURJQUERYPATH/js/jquery.js\" type=\"text/javascript\"></script>\n <script src=\"http://YOURJQUERYPATH/js/jquery.validate.js\" type=\"text/javascript\"></script>\n <script type=\"text/javascript\">\n\n $().ready(function() {\n $.validator.addMethod(\"EMAIL\", function(value, element) {\n return this.optional(element) || /^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\\.[a-zA-Z.]{2,5}$/i.test(value);\n }, \"Email Address is invalid: Please enter a valid email address.\");\n\n $.validator.addMethod(\"PASSWORD\",function(value,element){\n return this.optional(element) || /^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{8,16}$/i.test(value);\n },\"Passwords are 8-16 characters with uppercase letters, lowercase letters and at least one number.\");\n\n $.validator.addMethod(\"SUBMIT\",function(value,element){\n return this.optional(element) || /[^ ]/i.test(value);\n },\"You did not click the submit button.\");\n\n // Validate signup form on keyup and submit\n $(\"#LOGIN\").validate({\n rules: {\n EMAIL: \"required EMAIL\",\n PASSWORD: \"required PASSWORD\",\n SUBMIT: \"required SUBMIT\",\n },\n });\n });\n </script>\n</head>\n<body>\n <div id=\"LOGIN_FORM\" class=\"form\">\n <form id=\"LOGIN\" name=\"LOGIN\" method=\"post\" action=\"/index/secure/authentication?action=login\">\n <h1>Log In</h1>\n <div id=\"LOGIN_EMAIL\">\n <label for=\"EMAIL\">Email Address</label>\n <input id=\"EMAIL\" name=\"EMAIL\" type=\"text\" value=\"\" tabindex=\"1\" />\n </div>\n <div id=\"LOGIN_PASSWORD\">\n <label for=\"PASSWORD\">Password</label>\n <input id=\"PASSWORD\" name=\"PASSWORD\" type=\"password\" value=\"\" tabindex=\"2\" />\n </div>\n <div id=\"LOGIN_SUBMIT\">\n <input id=\"SUBMIT\" name=\"SUBMIT\" type=\"submit\" value=\"Submit\" tabindex=\"3\" />\n </div>\n </form>\n </div>\n</body>\n</html>\n" }, { "answer_id": 2040384, "author": "Sam", "author_id": 247853, "author_profile": "https://Stackoverflow.com/users/247853", "pm_score": 5, "selected": false, "text": "$.validator.addMethod(\n \"regex\",\n function(value, element, regexp) {\n var check = false;\n return this.optional(element) || regexp.test(value);\n },\n \"Please check your input.\"\n);\n telephone: { required: true, regex : /^[\\d\\s]+$/, minlength: 5 },\n" }, { "answer_id": 4062771, "author": "Kris Nobels", "author_id": 492677, "author_profile": "https://Stackoverflow.com/users/492677", "pm_score": 4, "selected": false, "text": "$.validator.addMethod(\n \"regex\",\n function(value, element, regexp) {\n return this.optional(element) || regexp.test(value);\n },\n \"Please check your input.\"\n);\n\n\n$(function () {\n $('#uiEmailAdress').focus();\n $('#NewsletterForm').validate({\n rules: {\n uiEmailAdress:{\n required: true,\n email: true,\n minlength: 5\n },\n uiConfirmEmailAdress:{\n required: true,\n email: true,\n equalTo: '#uiEmailAdress'\n },\n DDLanguage:{\n required: true\n },\n Testveld:{\n required: true,\n regex: /^[0-9]{3}$/\n }\n },\n messages: {\n uiEmailAdress:{\n required: 'Verplicht veld',\n email: 'Ongeldig emailadres',\n minlength: 'Minimum 5 charaters vereist'\n },\n uiConfirmEmailAdress:{\n required: 'Verplicht veld',\n email: 'Ongeldig emailadres',\n equalTo: 'Veld is niet gelijk aan E-mailadres'\n },\n DDLanguage:{\n required: 'Verplicht veld'\n },\n Testveld:{\n required: 'Verplicht veld',\n regex: '_REGEX'\n }\n }\n });\n});\n /" }, { "answer_id": 22814773, "author": "staabm", "author_id": 1597388, "author_profile": "https://Stackoverflow.com/users/1597388", "pm_score": 2, "selected": false, "text": "<input type=\"text\" name=\"myfield\" regex=\"/^[0-9]{3}$/i\" />\n $.validator.addMethod(\n \"regex\",\n function(value, element, regstring) {\n // fast exit on empty optional\n if (this.optional(element)) {\n return true;\n }\n\n var regParts = regstring.match(/^\\/(.*?)\\/([gim]*)$/);\n if (regParts) {\n // the parsed pattern had delimiters and modifiers. handle them. \n var regexp = new RegExp(regParts[1], regParts[2]);\n } else {\n // we got pattern string without delimiters\n var regexp = new RegExp(regstring);\n }\n\n return regexp.test(value);\n },\n \"Please check your input.\"\n); \n" }, { "answer_id": 36867078, "author": "ArunDhwaj IIITH", "author_id": 1509738, "author_profile": "https://Stackoverflow.com/users/1509738", "pm_score": 3, "selected": false, "text": "function validateSignup()\n{ \n $.validator.addMethod(\n \"regex\",\n function(value, element, regexp) \n {\n if (regexp.constructor != RegExp)\n regexp = new RegExp(regexp);\n else if (regexp.global)\n regexp.lastIndex = 0;\n return this.optional(element) || regexp.test(value);\n },\n \"Please check your input.\"\n );\n\n $('#signupForm').validate(\n {\n\n onkeyup : false,\n errorClass: \"req_mess\",\n ignore: \":hidden\",\n validClass: \"signup_valid_class\",\n errorClass: \"signup_error_class\",\n\n rules:\n {\n\n email:\n {\n required: true,\n email: true,\n regex: /^[A-Za-z0-9_]+\\@[A-Za-z0-9_]+\\.[A-Za-z0-9_]+/,\n },\n\n userId:\n {\n required: true,\n minlength: 6,\n maxlength: 15,\n regex: /^[A-Za-z0-9_]{6,15}$/,\n },\n\n phoneNum:\n {\n required: true,\n regex: /^[+-]{1}[0-9]{1,3}\\-[0-9]{10}$/,\n },\n\n },\n messages: \n {\n email: \n {\n required: 'You must enter a email',\n regex: 'Please enter a valid email without spacial chars, ie, Example@gmail.com'\n },\n\n userId:\n {\n required: 'Alphanumeric, _, min:6, max:15',\n regex: \"Please enter any alphaNumeric char of length between 6-15, ie, sbp_arun_2016\"\n },\n\n phoneNum: \n {\n required: \"Please enter your phone number\",\n regex: \"e.g. +91-1234567890\" \n },\n\n },\n\n submitHandler: function (form)\n {\n return true;\n }\n });\n}\n" }, { "answer_id": 37563111, "author": "Bogdan Mates", "author_id": 5068697, "author_profile": "https://Stackoverflow.com/users/5068697", "pm_score": 2, "selected": false, "text": " Zip: {\n required: true,\n regex: /^\\d{5}(?:[-\\s]\\d{4})?$/\n }\n" }, { "answer_id": 47163549, "author": "Wiktor Stribiżew", "author_id": 3832970, "author_profile": "https://Stackoverflow.com/users/3832970", "pm_score": 4, "selected": false, "text": "pattern additional-methods.js $(\"#frm\").validate({\n rules: {\n Textbox: {\n pattern: /^[a-zA-Z'.\\s]{1,40}$/\n },\n },\n messages: {\n Textbox: {\n pattern: 'The Textbox string format is invalid'\n }\n }\n}); <script src=\"https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js\"></script>\n<script src=\"https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.17.0/jquery.validate.js\"></script>\n<script src=\"https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.17.0/additional-methods.min.js\"></script>\n<form id=\"frm\" method=\"get\" action=\"\">\n <fieldset>\n <p>\n <label for=\"fullname\">Textbox</label>\n <input id=\"Textbox\" name=\"Textbox\" type=\"text\">\n </p>\n </fieldset>\n</form>" }, { "answer_id": 63363750, "author": "Amir Hosseinzadeh", "author_id": 2858268, "author_profile": "https://Stackoverflow.com/users/2858268", "pm_score": 1, "selected": false, "text": " $.validator.methods.checkEmail = function( value, element ) {\n return this.optional( element ) || /[a-z]+@[a-z]+\\.[a-z]+/.test( value );\n }\n\n $(\"#myForm\").validate({\n rules: {\n email: {\n required: true,\n checkEmail: true\n }\n },\n messages: {\n email: \"incorrect email\"\n }\n });\n" }, { "answer_id": 64769318, "author": "Noob", "author_id": 8604852, "author_profile": "https://Stackoverflow.com/users/8604852", "pm_score": 0, "selected": false, "text": "$(\"Textbox\").rules(\"add\", { regex: \"^[a-zA-Z'.\\\\s]{1,40}$\", messages: { regex: \"The text is invalid...\" } })\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280759", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36546/" ]
280,767
<p>After years of programming it's still some of the simple things that keep tripping me up.</p> <p>Is there a commonly agreed definition of filename ?</p> <p>Even the <a href="http://en.wikipedia.org/wiki/Filename" rel="noreferrer">wikipedia article</a> confuses the two interpretations.</p> <p>It starts by defining it as 'a special kind of string used to uniquely identify a file stored on the file system of a computer'. That seems clear enough, and suggests that a filename is a fully qualified filename, specifying the complete path to the file.</p> <p>However, it then goes on to:</p> <ul> <li>talk about basename and extension (so basename would contain an absolute path ?)</li> <li>says that the length of a filename in DOS is limited to 8.3</li> <li>says that a filename without a path part is assumed to be a file in the current working directory (so the filename does not uniquely identify a file)</li> </ul> <p>So, simple questions:</p> <ul> <li>what is a correct definition of 'filename' (include references)</li> <li>how should I unambiguously name variables for: <ul> <li>a path to a file (which can be absolute/full or relative)</li> <li>a path to a resource that can be a file/directory/socket</li> </ul></li> </ul>
[ { "answer_id": 280785, "author": "Adam Liss", "author_id": 29157, "author_profile": "https://Stackoverflow.com/users/29157", "pm_score": 3, "selected": false, "text": "path filespec filename extension basename" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280767", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2900/" ]
280,769
<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/2246772/whats-the-difference-between-not-exists-vs-not-in-vs-left-join-where-is-null">What&#39;s the difference between NOT EXISTS vs. NOT IN vs. LEFT JOIN WHERE IS NULL?</a> </p> </blockquote> <p>I need to wite a query that will retrieve the records from Table A , provided that the key in Table A does not exist in Table B.</p> <p>Any help will be appreciated.</p> <p>Thanks</p>
[ { "answer_id": 280775, "author": "Galwegian", "author_id": 3201, "author_profile": "https://Stackoverflow.com/users/3201", "pm_score": 3, "selected": true, "text": "SELECT *\nFROM A\nWHERE ID NOT IN\n (SELECT ID FROM B)\n" }, { "answer_id": 280778, "author": "CubanX", "author_id": 27555, "author_profile": "https://Stackoverflow.com/users/27555", "pm_score": 0, "selected": false, "text": "select * from TableA ta where ta.Id not in (select Id from TableB)\n" }, { "answer_id": 280780, "author": "kristof", "author_id": 3241, "author_profile": "https://Stackoverflow.com/users/3241", "pm_score": 3, "selected": false, "text": "select a.* \nfrom\n tableA a\n left join tableB b\n ON a.id = b.id\nwhere\n b.id is null\n" }, { "answer_id": 280792, "author": "okoman", "author_id": 35903, "author_profile": "https://Stackoverflow.com/users/35903", "pm_score": 2, "selected": false, "text": "SELECT TableA.* FROM TableA LEFT JOIN TableB ON TableA.id = TableB.id WHERE TableB.id IS NULL\n" }, { "answer_id": 280858, "author": "Kaniu", "author_id": 3236, "author_profile": "https://Stackoverflow.com/users/3236", "pm_score": 0, "selected": false, "text": "SELECT * FROM TableA\nWHERE NOT Exists(SELECT * FROM TableB WHERE id=TableA.id)\n" }, { "answer_id": 1464339, "author": "Rahul", "author_id": 24424, "author_profile": "https://Stackoverflow.com/users/24424", "pm_score": 2, "selected": false, "text": "SELECT * \n FROM TableA AS a \n WHERE NOT EXISTS (\n SELECT * \n FROM TableB b \n WHERE b.id1 = a.id1 \n AND b.id2 = a.id2 \n AND b.id3 = a.id3\n );\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280769", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
280,787
<p>I need to suppress autoplay for the mass storage devices. This needs to be achieved programatically through a service/deamon running in the background.</p> <p>I know it can be done by an application which opens a window and handles the "queryCancelAutoPlay" message sent by windows.</p> <p>Can this be done without GUI.I have the guid/pid/vid for the device whose autoplay needs to be disabled.</p>
[ { "answer_id": 280813, "author": "Robert Gamble", "author_id": 25222, "author_profile": "https://Stackoverflow.com/users/25222", "pm_score": 0, "selected": false, "text": "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer \n NoDriveTypeAutoRun\n\nValue Meaning\n0x1 Disables Autoplay on drives of unknown type.\n0x4 Disables Autoplay on removable drives.\n0x8 Disables Autoplay on fixed drives.\n0x10 Disables Autoplay on network drives.\n0x20 Disables Autoplay on CD-ROM drives.\n0x40 Disables Autoplay on RAM drives.\n0x80 Disables Autoplay on drives of unknown type.\n0xFF Disables Autoplay on all types of drives.\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280787", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
280,793
<p>I need to highlight, case insensitively, given keywords in a JavaScript string.</p> <p>For example:</p> <ul> <li><code>highlight("foobar Foo bar FOO", "foo")</code> should return <code>"&lt;b&gt;foo&lt;/b&gt;bar &lt;b&gt;Foo&lt;/b&gt; bar &lt;b&gt;FOO&lt;/b&gt;"</code></li> </ul> <p>I need the code to work for any keyword, and therefore using a hardcoded regular expression like <code>/foo/i</code> is not a sufficient solution.</p> <p>What is the easiest way to do this?</p> <p>(This an instance of a more general problem detailed in the title, but I feel that it's best to tackle with a concrete, useful example.)</p>
[ { "answer_id": 280805, "author": "okoman", "author_id": 35903, "author_profile": "https://Stackoverflow.com/users/35903", "pm_score": 7, "selected": true, "text": "function preg_quote (str, delimiter) {\n // discuss at: https://locutus.io/php/preg_quote/\n // original by: booeyOH\n // improved by: Ates Goral (https://magnetiq.com)\n // improved by: Kevin van Zonneveld (https://kvz.io)\n // improved by: Brett Zamir (https://brett-zamir.me)\n // bugfixed by: Onno Marsman (https://twitter.com/onnomarsman)\n // example 1: preg_quote(\"$40\")\n // returns 1: '\\\\$40'\n // example 2: preg_quote(\"*RRRING* Hello?\")\n // returns 2: '\\\\*RRRING\\\\* Hello\\\\?'\n // example 3: preg_quote(\"\\\\.+*?[^]$(){}=!<>|:\")\n // returns 3: '\\\\\\\\\\\\.\\\\+\\\\*\\\\?\\\\[\\\\^\\\\]\\\\$\\\\(\\\\)\\\\{\\\\}\\\\=\\\\!\\\\<\\\\>\\\\|\\\\:'\n\n return (str + '')\n .replace(new RegExp('[.\\\\\\\\+*?\\\\[\\\\^\\\\]$(){}=!<>|:\\\\' + (delimiter || '') + '-]', 'g'), '\\\\$&')\n}\n function highlight(str, search) {\n return str.replace(new RegExp(\"(\" + preg_quote(search) + \")\", 'gi'), \"<b>$1</b>\");\n}\n" }, { "answer_id": 280811, "author": "Erik Hesselink", "author_id": 8071, "author_profile": "https://Stackoverflow.com/users/8071", "pm_score": 0, "selected": false, "text": "new Regex([pat], [flags])\n" }, { "answer_id": 280824, "author": "tvanfosson", "author_id": 12950, "author_profile": "https://Stackoverflow.com/users/12950", "pm_score": 6, "selected": false, "text": "function highlightWords( line, word )\n{\n var regex = new RegExp( '(' + word + ')', 'gi' );\n return line.replace( regex, \"<b>$1</b>\" );\n}\n" }, { "answer_id": 280837, "author": "bobince", "author_id": 18936, "author_profile": "https://Stackoverflow.com/users/18936", "pm_score": 3, "selected": false, "text": "var re= new RegExp('('+word+')', 'gi');\nreturn s.replace(re, '<b>$1</b>');\n" }, { "answer_id": 280970, "author": "Tomalak", "author_id": 18771, "author_profile": "https://Stackoverflow.com/users/18771", "pm_score": 4, "selected": false, "text": "RegExp.escape = function(str) \n{\n var specials = /[.*+?|()\\[\\]{}\\\\$^]/g; // .*+?|()[]{}\\$^\n return str.replace(specials, \"\\\\$&\");\n}\n function highlightWordsNoCase(line, word)\n{\n var regex = new RegExp(\"(\" + RegExp.escape(word) + \")\", \"gi\");\n return line.replace(regex, \"<b>$1</b>\");\n}\n" }, { "answer_id": 12431195, "author": "GitCarter", "author_id": 892598, "author_profile": "https://Stackoverflow.com/users/892598", "pm_score": 3, "selected": false, "text": "if(typeof String.prototype.highlight !== 'function') {\n String.prototype.highlight = function(match, spanClass) {\n var pattern = new RegExp( match, \"gi\" );\n replacement = \"<span class='\" + spanClass + \"'>$&</span>\";\n\n return this.replace(pattern, replacement);\n }\n}\n var result = \"The Quick Brown Fox Jumped Over The Lazy Brown Dog\".highlight(\"brown\",\"text-highlight\");\n" }, { "answer_id": 42215678, "author": "exebook", "author_id": 1968972, "author_profile": "https://Stackoverflow.com/users/1968972", "pm_score": 2, "selected": false, "text": "function replacei(str, sub, f){\n let A = str.toLowerCase().split(sub.toLowerCase());\n let B = [];\n let x = 0;\n for (let i = 0; i < A.length; i++) {\n let n = A[i].length;\n B.push(str.substr(x, n));\n if (i < A.length-1)\n B.push(f(str.substr(x + n, sub.length)));\n x += n + sub.length;\n }\n return B.join('');\n}\n\ns = 'Foo and FOO (and foo) are all -- Foo.'\nt = replacei(s, 'Foo', sub=>'<'+sub+'>')\nconsole.log(t) <Foo> and <FOO> (and <foo>) are all -- <Foo>.\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280793", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
280,797
<p>When you use the POISSON function in Excel (or in OpenOffice Calc), it takes two arguments:</p> <ul> <li>an integer</li> <li>an 'average' number</li> </ul> <p>and returns a float.</p> <p>In Python (I tried RandomArray and NumPy) it returns an array of random poisson numbers. What I really want is the percentage that this event will occur (it is a constant number and the array has every time different numbers - so is it an average?).</p> <p>for example:</p> <pre><code>print poisson(2.6,6) </code></pre> <p>returns <code>[1 3 3 0 1 3]</code> (and every time I run it, it's different).</p> <p>The number I get from calc/excel is 3.19 (<code>POISSON(6,2.16,0)*100</code>).</p> <p>Am I using the python's poisson wrong (no pun!) or am I missing something?</p>
[ { "answer_id": 280843, "author": "Alex Coventry", "author_id": 1941213, "author_profile": "https://Stackoverflow.com/users/1941213", "pm_score": 5, "selected": false, "text": "scipy >>> scipy.stats.distributions\n<module 'scipy.stats.distributions' from '/home/coventry/lib/python2.5/site-packages/scipy/stats/distributions.pyc'>\n>>> scipy.stats.distributions.poisson.pmf(6, 2.6)\narray(0.031867055625524499)\n" }, { "answer_id": 280862, "author": "Ned Batchelder", "author_id": 14343, "author_profile": "https://Stackoverflow.com/users/14343", "pm_score": 5, "selected": true, "text": "def poisson_probability(actual, mean):\n # naive: math.exp(-mean) * mean**actual / factorial(actual)\n\n # iterative, to keep the components from getting too large or small:\n p = math.exp(-mean)\n for i in xrange(actual):\n p *= mean\n p /= i+1\n return p\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280797", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
280,798
<p>I'm trying to make a class that will execute any one of a number of stored procedures with any amount of variables</p> <p>Im using php and mysqli</p> <ul> <li>My class enumerates an array and constructs a string based on the number of elements if any</li> <li>giving something like this <code>CALL spTestLogin(?,?)</code> for example</li> <li><p>I now need to bind the input from my array using somethin like this:</p> <p>$stmt->bind_param($this->paramTypes,$this->paramValues);//paramValues is my array</p></li> </ul> <p>Then if that works I can work on getting my results</p> <p>Any ideas</p>
[ { "answer_id": 280829, "author": "Stefan Gehrig", "author_id": 11354, "author_profile": "https://Stackoverflow.com/users/11354", "pm_score": 2, "selected": false, "text": "$params=array_merge(\n array($this->paramTypes), \n $this->paramValues\n);\ncall_user_func_array(array($stmt, 'bind_param'), $params);\n $this->paramTypes mysqli_stmt::bind_param string out inout" }, { "answer_id": 280856, "author": "Tom Haigh", "author_id": 22224, "author_profile": "https://Stackoverflow.com/users/22224", "pm_score": 2, "selected": false, "text": "mysqli_stmt::bind_param() $this->paramTypes $params = $this->paramValues;\narray_unshift($params, implode($this->paramTypes));\ncall_user_func_array( array( $stmt, 'bind_param' ), $params);\n call_user_func_array()" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280798", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11394/" ]
280,801
<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/16991/what-ruby-ide-do-you-prefer">What Ruby IDE do you prefer?</a> </p> </blockquote> <p>I'm making a <strong>simple</strong> script using ruby on a Windows 2003 Server. My questions are:</p> <ul> <li>How can I connect to a database through ODBC? I will be connecting to both <strong>Sybase on Solaris</strong> and <strong>MSSQL Server</strong>.</li> <li>How can I send emails through an Exchange Server 2003?</li> </ul> <hr> <h2>Update</h2> <ul> <li>What's the best simple IDE for Ruby scripting? I currently use SciTE (which comes with Ruby)</li> </ul>
[ { "answer_id": 280857, "author": "Tomalak", "author_id": 18771, "author_profile": "https://Stackoverflow.com/users/18771", "pm_score": 2, "selected": false, "text": "require 'DBI'\n\n# make an ODBC connection\nconn = DBI.connect('DBI:ODBC:datasource','your_username','your_password')\n\n# returns a list of the table names from your database\nconn.tables\n\n# returns an array with the resultset from your query\nrs = conn.select_all('SELECT * FROM TheTable')\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280801", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15884/" ]
280,818
<p>I'm developing a small utility application that needs to detect whether another one has one of its MDI child windows open (it's an off-the-shelf Win32 business application over which I have neither source code nor control). From my app, I would like to be able to poll or detect when a particular MDI Child window is open.</p> <p>In .Net, it's easy to iterate over running processes, but I haven't found an easy way to iterate through the (sub)windows and controls of a given Win32 process from .Net.</p> <p>Any ideas?</p> <p><strong>Update</strong><br> Thanks for the answers they got me on the right path.<br> I found an <a href="http://www.vbaccelerator.com/home/NET/Code/Libraries/Windows/Enumerating_Windows/article.asp" rel="nofollow noreferrer">article with a test project</a> that uses both <code>EnumWindows</code>and <code>EnumChidWindows</code> and other API calls to get extended information on controls.</p>
[ { "answer_id": 280878, "author": "Robert Vuković", "author_id": 438025, "author_profile": "https://Stackoverflow.com/users/438025", "pm_score": 4, "selected": true, "text": " \n\n[DllImport(\"user32\")]\n\n[return: MarshalAs(UnmanagedType.Bool)]\npublic static extern bool EnumChildWindows(IntPtr window, EnumWindowProc callback, IntPtr i);\n\n/// <summary>\n/// Returns a list of child windows\n/// </summary>\n/// <param name=\"parent\">Parent of the windows to return</param>\n/// <returns>List of child windows</returns>\npublic static List<IntPtr> GetChildWindows(IntPtr parent)\n{\nList<IntPtr> result = new List<IntPtr>();\nGCHandle listHandle = GCHandle.Alloc(result);\ntry\n{\n EnumWindowProc childProc = new EnumWindowProc(EnumWindow);\n EnumChildWindows(parent, childProc, GCHandle.ToIntPtr(listHandle));\n}\nfinally\n{\n if (listHandle.IsAllocated)\n listHandle.Free();\n}\nreturn result;\n}\n\n/// <summary>\n/// Callback method to be used when enumerating windows.\n/// </summary>\n/// <param name=\"handle\">Handle of the next window</param>\n/// <param name=\"pointer\">Pointer to a GCHandle that holds a reference to the list to fill</param>\n/// <returns>True to continue the enumeration, false to bail</returns>\nprivate static bool EnumWindow(IntPtr handle, IntPtr pointer)\n{\nGCHandle gch = GCHandle.FromIntPtr(pointer);\nList<IntPtr> list = gch.Target as List<IntPtr>;\nif (list == null)\n{\n throw new InvalidCastException(\"GCHandle Target could not be cast as List<IntPtr>\");\n}\nlist.Add(handle);\n// You can modify this to check to see if you want to cancel the operation, then return a null here\nreturn true;\n}\n\n/// <summary>\n/// Delegate for the EnumChildWindows method\n/// </summary>\n/// <param name=\"hWnd\">Window handle</param>\n/// <param name=\"parameter\">Caller-defined variable; we use it for a pointer to our list</param>\n/// <returns>True to continue enumerating, false to bail.</returns>\npublic delegate bool EnumWindowProc(IntPtr hWnd, IntPtr parameter);\n\n\n [DllImport(\"user32\")]\n\n[return: MarshalAs(UnmanagedType.Bool)]\npublic static extern bool EnumChildWindows(IntPtr window, EnumWindowProc callback, IntPtr i);\n\n/// <summary>\n/// Returns a list of child windows\n/// </summary>\n/// <param name=\"parent\">Parent of the windows to return</param>\n/// <returns>List of child windows</returns>\npublic static List<IntPtr> GetChildWindows(IntPtr parent)\n{\nList<IntPtr> result = new List<IntPtr>();\nGCHandle listHandle = GCHandle.Alloc(result);\ntry\n{\n EnumWindowProc childProc = new EnumWindowProc(EnumWindow);\n EnumChildWindows(parent, childProc, GCHandle.ToIntPtr(listHandle));\n}\nfinally\n{\n if (listHandle.IsAllocated)\n listHandle.Free();\n}\nreturn result;\n}\n\n/// <summary>\n/// Callback method to be used when enumerating windows.\n/// </summary>\n/// <param name=\"handle\">Handle of the next window</param>\n/// <param name=\"pointer\">Pointer to a GCHandle that holds a reference to the list to fill</param>\n/// <returns>True to continue the enumeration, false to bail</returns>\nprivate static bool EnumWindow(IntPtr handle, IntPtr pointer)\n{\nGCHandle gch = GCHandle.FromIntPtr(pointer);\nList<IntPtr> list = gch.Target as List<IntPtr>;\nif (list == null)\n{\n throw new InvalidCastException(\"GCHandle Target could not be cast as List<IntPtr>\");\n}\nlist.Add(handle);\n// You can modify this to check to see if you want to cancel the operation, then return a null here\nreturn true;\n}\n\n/// <summary>\n/// Delegate for the EnumChildWindows method\n/// </summary>\n/// <param name=\"hWnd\">Window handle</param>\n/// <param name=\"parameter\">Caller-defined variable; we use it for a pointer to our list</param>\n/// <returns>True to continue enumerating, false to bail.</returns>\npublic delegate bool EnumWindowProc(IntPtr hWnd, IntPtr parameter);\n " }, { "answer_id": 43541456, "author": "Peter Talbot", "author_id": 7901147, "author_profile": "https://Stackoverflow.com/users/7901147", "pm_score": 2, "selected": false, "text": "PRC=process name\nWIN=window title\n Imports System\nImports System.IO\nImports System.Runtime.InteropServices\nImports System.Text\nModule Module1\n Dim hShellWindow As IntPtr = GetShellWindow()\n Dim dictWindows As New Dictionary(Of IntPtr, String)\n Dim dictChildWindows As New Dictionary(Of IntPtr, String)\n Dim currentProcessID As Integer = -1\n <DllImport(\"USER32.DLL\")>\n Function GetShellWindow() As IntPtr\n End Function\n <DllImport(\"USER32.DLL\")>\n Function GetForegroundWindow() As IntPtr\n End Function\n <DllImport(\"USER32.DLL\")>\n Function GetWindowText(ByVal hWnd As IntPtr, ByVal lpString As StringBuilder, ByVal nMaxCount As Integer) As Integer\n End Function\n <DllImport(\"USER32.DLL\")>\n Function GetWindowTextLength(ByVal hWnd As IntPtr) As Integer\n End Function\n <DllImport(\"user32.dll\", SetLastError:=True)>\n Function GetWindowThreadProcessId(ByVal hWnd As IntPtr, <Out()> ByRef lpdwProcessId As UInt32) As UInt32\n End Function\n <DllImport(\"USER32.DLL\")>\n Function IsWindowVisible(ByVal hWnd As IntPtr) As Boolean\n End Function\n Delegate Function EnumWindowsProc(ByVal hWnd As IntPtr, ByVal lParam As Integer) As Boolean\n <DllImport(\"USER32.DLL\")>\n Function EnumWindows(ByVal enumFunc As EnumWindowsProc, ByVal lParam As Integer) As Boolean\n End Function\n <DllImport(\"USER32.DLL\")>\n Function EnumChildWindows(ByVal hWndParent As System.IntPtr, ByVal lpEnumFunc As EnumWindowsProc, ByVal lParam As Integer) As Boolean\n End Function\n <DllImport(\"USER32.DLL\")>\n Function PostMessage(ByVal hwnd As Integer, ByVal message As UInteger, ByVal wParam As Integer, ByVal lParam As Integer) As Boolean\n End Function\n <DllImport(\"USER32.DLL\")>\n Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr\n End Function\n\n Function enumWindowsInternal(ByVal hWnd As IntPtr, ByVal lParam As Integer) As Boolean\n Dim a As String = \"\"\n Dim length As Integer = GetWindowTextLength(hWnd)\n If (length > 0) Then\n Dim stringBuilder As New System.Text.StringBuilder(length)\n GetWindowText(hWnd, stringBuilder, (length + 1))\n a = stringBuilder.ToString\n End If\n dictWindows.Add(hWnd, a)\n EnumChildWindows(hWnd, AddressOf enumChildWindowsInternal, 0)\n Return True\n End Function\n Function enumChildWindowsInternal(ByVal hWnd As IntPtr, ByVal lParam As Integer) As Boolean\n Dim a As String = \"\"\n Dim length As Integer = GetWindowTextLength(hWnd)\n If (length > 0) Then\n Dim stringBuilder As New System.Text.StringBuilder(length)\n GetWindowText(hWnd, stringBuilder, (length + 1))\n a = stringBuilder.ToString\n End If\n dictChildWindows.Add(hWnd, a)\n Return True\n End Function\n Function cleanstring(ByVal a As String) As String\n Dim c As String = \"\"\n Dim b As String = \"\"\n Dim i As Integer\n Do While i < Len(a)\n i = i + 1\n c = Mid(a, i, 1)\n If Asc(c) > 31 And Asc(c) < 128 Then\n b = b & c\n End If\n Loop\n cleanstring = b\n End Function\n Sub Main()\n '\n '\n Dim a As String = \"\"\n Dim b As String = \"\"\n Dim c As String = \"\"\n Dim d As String = \"\"\n Dim f As String = \"C:\\FIS5\\WK.txt\"\n Dim a1 As String = \"\"\n Dim a2 As String = \"\"\n Dim p As Process\n Dim windows As IDictionary(Of IntPtr, String)\n Dim kvp As KeyValuePair(Of IntPtr, String)\n Dim windowPid As UInt32\n Dim hWnd As IntPtr\n Dim fhWnd As IntPtr\n Dim WM_CLOSE As UInteger = &H12\n Dim WM_SYSCOMMAND As UInteger = &H112\n Dim SC_CLOSE As UInteger = &HF060\n Dim x As Boolean = True\n Dim y As IntPtr\n Dim processes As Process() = Process.GetProcesses\n Dim params As String = File.ReadAllText(\"C:\\FIS5\\WindowKiller.txt\")\n Dim words As String() = params.Split(vbCrLf)\n Dim word As String\n Dim myprocname As String = \"\"\n Dim mywinname As String = \"\"\n Dim i As Integer = 0\n Dim v1 As Integer = 0\n For Each word In words\n word = Trim(cleanstring(word)).ToUpper\n i = InStr(word, \"=\", CompareMethod.Text)\n ' a = a & word & \" \" & i.ToString & vbCrLf\n If i = 4 And 4 < Len(word) Then\n If Left(word, 4) = \"PRC=\" Then\n myprocname = Mid(word, 5)\n End If\n If Left(word, 4) = \"WIN=\" Then\n mywinname = Mid(word, 5)\n End If\n End If\n Next\n a = a & params & vbCrLf & \"procname=\" & myprocname & \", winname=\" & mywinname & vbCrLf\n fhWnd = GetForegroundWindow()\n dictWindows.Clear()\n dictChildWindows.Clear()\n EnumWindows(AddressOf enumWindowsInternal, 0)\n windows = dictChildWindows\n For Each kvp In windows\n hWnd = kvp.Key\n GetWindowThreadProcessId(hWnd, windowPid)\n b = \"\"\n c = \"\"\n For Each p In processes\n If p.Id = windowPid Then\n b = p.ProcessName\n c = p.Id.ToString\n End If\n Next\n d = \"hidden\"\n If IsWindowVisible(hWnd) Then\n d = \"visible\"\n End If\n If hWnd = fhWnd Then\n d = d & \", foreground\"\n End If\n a = a & \"Child window=\" & hWnd.ToString & \", processname=\" & b & \", procid=\" & c & \", windowname=\" & kvp.Value & \", \" & d & vbCrLf\n Next\n windows = dictWindows\n For Each kvp In windows\n v1 = 0\n hWnd = kvp.Key\n GetWindowThreadProcessId(hWnd, windowPid)\n b = \"\"\n c = \"\"\n For Each p In processes\n If p.Id = windowPid Then\n b = p.ProcessName\n c = p.Id.ToString\n End If\n Next\n d = \"hidden\"\n If IsWindowVisible(hWnd) Then\n d = \"visible\"\n v1 = 1\n End If\n If hWnd = fhWnd Then\n d = d & \", foreground\"\n End If\n word = kvp.Value\n a = a & \"Window=\" & hWnd.ToString & \", processname=\" & b & \", procid=\" & c & \", windowname=\" & word & \", \" & d & vbCrLf\n If Trim(cleanstring(b).ToUpper) = myprocname Then\n a = a & \"procname match\" & vbCrLf\n If Trim(cleanstring(word)).ToUpper = mywinname And v1 <> 0 Then\n a = a & \"ATTEMPTING To CLOSE: \" & b & \" # \" & word & \" # \" & c & vbCrLf\n ' x = PostMessage(hWnd, WM_CLOSE, 0, 0)\n 'If x Then\n 'a = a & \"PostMessage returned True\" & vbCrLf\n 'Else\n 'a = a & \"PostMessage returned False\" & vbCrLf\n 'End If\n y = SendMessage(hWnd, WM_SYSCOMMAND, SC_CLOSE, 0)\n a = a & \"SendMessage returned \" & y.ToString & vbCrLf\n End If\n End If\n Next\n My.Computer.FileSystem.WriteAllText(f, a, False)\n End Sub\nEnd Module\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280818", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3811/" ]
280,819
<p>My WCF service involves the sending of a dataset (in csv format) data between client and service. This dataset must be encrypted so that the data cannot be intercepted. I'm using wshttpbinding and trying to encrypt the message by using the following settings in web.config:</p> <pre><code>&lt;wsHttpBinding&gt; &lt;binding name="wsHttp"&gt; &lt;reliableSession enabled="true" /&gt; &lt;security mode="Message"&gt; &lt;message clientCredentialType="UserName" algorithmSuite="TripleDes" /&gt; &lt;/security&gt; &lt;/binding&gt; &lt;/wsHttpBinding&gt; </code></pre> <p>When I try and generate a client proxy I get a long error messagebox (which cannot be completely read because it goes off the bottom of the screen!). The error message does mention something about a "service certificate not being provided".</p> <p>How do I encrypt a message? Do I need a certificate? I should mention that this service will be used over the internet from different domains so I'm not sure whether using "Username" security is the best option (?)</p> <p>Basically I'm confused!</p>
[ { "answer_id": 280890, "author": "Martin", "author_id": 1529, "author_profile": "https://Stackoverflow.com/users/1529", "pm_score": 3, "selected": true, "text": "makecert -sr LocalMachine -ss My -pe -n CN=subject-name -eku 1.3.6.1.5.5.7.3.1 -sky exchange\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280819", "https://Stackoverflow.com", "https://Stackoverflow.com/users/445/" ]
280,834
<p>I would like to know if it is possible, to select certain columns from one table, and another column from a second table, which would relate to a non imported column in the first table. I have to obtain this data from access, and do not know if this is possible with Access, or SQL in general.</p>
[ { "answer_id": 280848, "author": "Noah Goodrich", "author_id": 20178, "author_profile": "https://Stackoverflow.com/users/20178", "pm_score": 4, "selected": true, "text": "CREATE TABLE tbl_1 (\n pk_1 int,\n field_1 varchar(25),\n field_2 varchar(25)\n);\n\nCREATE TABLE tbl_2 (\n pk_2 int,\n fk_1 int,\n field_3 varchar(25),\n field_4 varchar(25)\n);\n SELECT t1.field_1, t2.field_3\nFROM tbl_1 t1\nINNER JOIN tbl_2 t2 ON t1.pk_1 = t2.fk_1\nWHERE t2.field_3 = \"Some String\"\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280834", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1246613/" ]
280,846
<p><strong>Mark Up</strong></p> <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="Zuhaib.test" %&gt; &lt;!-- Put IE into quirks mode --&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"&gt; &lt;head runat="server"&gt; &lt;title&gt;&lt;/title&gt; &lt;link href="css/general.css" rel="stylesheet" type="text/css" /&gt; &lt;link href="css/outbound.css" rel="stylesheet" type="text/css" /&gt; &lt;/head&gt; &lt;body&gt; &lt;form id="form1" runat="server" class="wrapper"&gt; &lt;asp:ScriptManager ID="ScriptManager1" runat="server"&gt; &lt;/asp:ScriptManager&gt; &lt;div id="left"&gt; &lt;/div&gt; &lt;div id="right"&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>CSS</strong></p> <pre><code>html, body { margin:0; padding:0; border:0; overflow:hidden; width:100%; height:100%; } * html body { height:100%; width:100%; } *{ margin:0; padding:0; } .wrapper { position:fixed; top:0px; bottom:0px; left:0px; right:0px; height:100%; width:100%; } * html .wrapper { width:100%; height:100%; } #left{ float:left; height:100%; width:100px; overflow:hidden; background-color:Blue; } * html #left{ height:100%; width:100px; } #right{ margin-left:100px; height:100%; background-color:Red; } * html #right{ height:100%; } </code></pre> <p><strong>Result in IE &amp;&amp; FF</strong><br> <a href="http://img139.imageshack.us/img139/9871/ie3pxgapnl4.jpg" rel="nofollow noreferrer">Resutls in IE &amp; FF http://img139.imageshack.us/img139/9871/ie3pxgapnl4.jpg</a><br> The result is same with both IE 6 &amp; 7. How can I remove the gap between the divs?</p> <p><strong>Udate</strong><br> I have two divs each with 100% height. the left div is a fixed width floating div. Even after giving correct margin-left to the right div, there remains a gap (3px) between the two divs. Where as in firefox it renders correctly.</p> <p>The reason I have used quirk mode is to able to get 100% height for the divs</p> <p>Can this gap be eliminated? Or is there a better way to do two column 100% height layout with pure css?</p>
[ { "answer_id": 280947, "author": "phihag", "author_id": 35070, "author_profile": "https://Stackoverflow.com/users/35070", "pm_score": 4, "selected": true, "text": "#right{\n position: absolute;\n left: 100px;\n padding-left: -100px;\n width: 100%;\n ...\n}\n" }, { "answer_id": 11905015, "author": "David Eison", "author_id": 72670, "author_profile": "https://Stackoverflow.com/users/72670", "pm_score": 1, "selected": false, "text": "<div id=\"left\">\n</div><div id=\"right\">\n</div> \n <div id=\"left\">\n </div><!-- IE doesn't ignore whitespace between divs\n --><div id=\"right\">\n </div> \n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280846", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25138/" ]
280,864
<p>Does anyone know of an open source web service/wcf service that can stream media content to clients? In particular I am looking for something that could access my music collection and stream it to a client (could be a client browser, win mobile app or even iphone application).</p> <p>I guess it would have to be WCF based as I'm not sure that webservices do streaming really well. Also Windows Media Streaming Services is not the best way to go as the service should operate from a vista/xp machine (preferably). </p> <p>If not, does anyone know the best way to start going about creating something like this - I'm not sure I know where to start with this one, although I can see many many uses for such a service!</p>
[ { "answer_id": 280947, "author": "phihag", "author_id": 35070, "author_profile": "https://Stackoverflow.com/users/35070", "pm_score": 4, "selected": true, "text": "#right{\n position: absolute;\n left: 100px;\n padding-left: -100px;\n width: 100%;\n ...\n}\n" }, { "answer_id": 11905015, "author": "David Eison", "author_id": 72670, "author_profile": "https://Stackoverflow.com/users/72670", "pm_score": 1, "selected": false, "text": "<div id=\"left\">\n</div><div id=\"right\">\n</div> \n <div id=\"left\">\n </div><!-- IE doesn't ignore whitespace between divs\n --><div id=\"right\">\n </div> \n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280864", "https://Stackoverflow.com", "https://Stackoverflow.com/users/445/" ]
280,872
<p>I'm trying to write a <a href="/questions/tagged/vba" class="post-tag" title="show questions tagged &#39;vba&#39;" rel="tag">vba</a> macro for a group tha</p> <ul> <li>has one workbook where they daily create new worksheets, and also have</li> <li><em>Sheet 1</em>, <em>Sheet 2</em> and <em>Sheet 3</em> at the end of their long list of sheets. </li> </ul> <p>I need to create a external cell reference in a new column in a different workbook where this information is being summarized.</p> <p>So I need to know how to get the <strong>last non-empty sheet</strong> so I can grab this data and place it appropriately in the summary.</p>
[ { "answer_id": 280979, "author": "dbb", "author_id": 25675, "author_profile": "https://Stackoverflow.com/users/25675", "pm_score": 4, "selected": true, "text": "Function GetLastNonEmptySheetName() As String\nDim i As Long\nFor i = Worksheets.Count To 1 Step -1\n If Sheets(i).UsedRange.Cells.Count > 1 Then\n GetLastNonEmptySheetName = Sheets(i).Name\n Exit Function\n End If\nNext i\nEnd Function\n" }, { "answer_id": 8061601, "author": "brettdj", "author_id": 641067, "author_profile": "https://Stackoverflow.com/users/641067", "pm_score": 1, "selected": false, "text": "Find xlFormulas Find xlValues Sub FindLastSht()\n Dim lngCnt As Long\n Dim rng1 As Range\n Dim strSht As String\n With ActiveWorkbook\n For lngCnt = .Worksheets.Count To 1 Step -1\n Set rng1 = .Sheets(lngCnt).Cells.Find(\"*\", , xlFormulas)\n If Not rng1 Is Nothing Then\n strSht = .Sheets(lngCnt).Name\n Exit For\n End If\n Next lngCnt\n If Len(strSht) > 0 Then\n MsgBox \"Last used sheet in \" & .Name & \" is \" & strSht\n Else\n MsgBox \"No data is contained in \" & .Name\n End If\n End With\nEnd Sub\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280872", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26140/" ]
280,879
<p>In some existing code there is a test to see if the user is running IE, by checking if the object Browser.Engine.trident is defined and returns true.</p> <p>But how can I determine if the user is running IE6 (or earlier) or IE7 (or later)?</p> <p>The test is needed inside a JavaScript function so a conditional comment doesn't seem suitable.</p>
[ { "answer_id": 280886, "author": "Nick Berardi", "author_id": 17, "author_profile": "https://Stackoverflow.com/users/17", "pm_score": 2, "selected": false, "text": "if (jQuery.browser.msie == true) { \nif (jQuery.browser.version == 7.0)\n // .. do something for 7.0\nelse \n // .. do something for < 7.0\n}\n" }, { "answer_id": 280925, "author": "Piskvor left the building", "author_id": 19746, "author_profile": "https://Stackoverflow.com/users/19746", "pm_score": 2, "selected": false, "text": "if (window.focus) {window.focus();} navigator.appName navigator.appVersion" }, { "answer_id": 280949, "author": "James Hughes", "author_id": 34671, "author_profile": "https://Stackoverflow.com/users/34671", "pm_score": 4, "selected": false, "text": "<script>\n var isIE = false;\n var version = -1;\n</script>\n<!--[if IE 6]>\n <script>\n isIE = true;\n version = 6\n </script>\n<![endif]-->\n<!--[if IE 7]>\n <script>\n isIE = true;\n version = 7\n </script>\n<![endif]-->\n isIE true version 6 isIE true version 7 isIE version -1 var userAgent = navigator.userAgent.toLowerCase();\nvar version = (userAgent.match( /.+(?:rv|it|ra|ie)[\\/: ]([\\d.]+)/ ) || [])[1],\nvar isIE = /msie/.test( userAgent ) && !/opera/.test( userAgent ), \n" }, { "answer_id": 281176, "author": "Jason Bunting", "author_id": 1790, "author_profile": "https://Stackoverflow.com/users/1790", "pm_score": 0, "selected": false, "text": "// Returns 0 if the browser is anything but IE\nfunction getIEVersion() {\n var ua = window.navigator.userAgent;\n var ie = ua.indexOf(\"MSIE \");\n return ((ie > 0) ? parseInt(ua.substring(ie+5, ua.indexOf(\".\", ie))) : 0);\n}\n" }, { "answer_id": 281291, "author": "kmilo", "author_id": 14015, "author_profile": "https://Stackoverflow.com/users/14015", "pm_score": 5, "selected": true, "text": "function getInternetExplorerVersion()\n// Returns the version of Internet Explorer or a -1\n// (indicating the use of another browser).\n{\n var rv = -1; // Return value assumes failure.\n if (navigator.appName == 'Microsoft Internet Explorer')\n {\n var ua = navigator.userAgent;\n var re = new RegExp(\"MSIE ([0-9]{1,}[\\.0-9]{0,})\");\n if (re.exec(ua) != null)\n rv = parseFloat( RegExp.$1 );\n }\n return rv;\n}\n\nfunction checkVersion()\n{\n var msg = \"You're not using Internet Explorer.\";\n var ver = getInternetExplorerVersion();\n\n if ( ver > -1 )\n {\n if ( ver >= 6.0 ) \n msg = \"You're using a recent copy of Internet Explorer.\"\n else\n msg = \"You should upgrade your copy of Internet Explorer.\";\n }\n alert( msg );\n}\n" }, { "answer_id": 281293, "author": "Illandril", "author_id": 17887, "author_profile": "https://Stackoverflow.com/users/17887", "pm_score": 0, "selected": false, "text": "var agent = navigator.userAgent;\nvar msiePattern = /.*MSIE ((\\d+).\\d+).*/\nif( msiePattern.test( agent ) ) {\n var majorVersion = agent.replace(msiePattern,\"$2\");\n var fullVersion = agent.replace(msiePattern,\"$1\");\n var majorVersionInt = parseInt( majorVersion );\n var fullVersionFloat = parseFloat( fullVersion );\n}\n" }, { "answer_id": 282214, "author": "bobince", "author_id": 18936, "author_profile": "https://Stackoverflow.com/users/18936", "pm_score": 0, "selected": false, "text": "function something() {\n var IE_WIN= false;\n var IE_WIN_7PLUS= false;\n /*@cc_on\n @if (@_win32)\n IE_WIN= true;\n @if (@_jscript_version>=5.7)\n IE_WIN_7PLUS = true;\n @end\n @end @*/\n ...\n}\n" }, { "answer_id": 3831044, "author": "Mike Ruhlin", "author_id": 453031, "author_profile": "https://Stackoverflow.com/users/453031", "pm_score": 2, "selected": false, "text": " // IE8's \"Compatibility mode\" is anything but. Oh well, at least it doesn't take 40 lines of code to detect and work around it.\n// Oh wait:\n/*\n * Author: Rob Reid\n * CreateDate: 20-Mar-09\n * Description: Little helper function to return details about IE 8 and its various compatibility settings either use as it is\n * or incorporate into a browser object. Remember browser sniffing is not the best way to detect user-settings as spoofing is\n * very common so use with caution.\n*/\nfunction IEVersion(){\n var _n=navigator,_w=window,_d=document;\n var version=\"NA\";\n var na=_n.userAgent;\n var ieDocMode=\"NA\";\n var ie8BrowserMode=\"NA\";\n // Look for msie and make sure its not opera in disguise\n if(/msie/i.test(na) && (!_w.opera)){\n // also check for spoofers by checking known IE objects\n if(_w.attachEvent && _w.ActiveXObject){ \n // Get version displayed in UA although if its IE 8 running in 7 or compat mode it will appear as 7\n version = (na.match( /.+ie\\s([\\d.]+)/i ) || [])[1];\n // Its IE 8 pretending to be IE 7 or in compat mode \n if(parseInt(version)==7){ \n // documentMode is only supported in IE 8 so we know if its here its really IE 8\n if(_d.documentMode){\n version = 8; //reset? change if you need to\n // IE in Compat mode will mention Trident in the useragent\n if(/trident\\/\\d/i.test(na)){\n ie8BrowserMode = \"Compat Mode\";\n // if it doesn't then its running in IE 7 mode\n }else{\n ie8BrowserMode = \"IE 7 Mode\";\n }\n }\n }else if(parseInt(version)==8){\n // IE 8 will always have documentMode available\n if(_d.documentMode){ ie8BrowserMode = \"IE 8 Mode\";}\n }\n // If we are in IE 8 (any mode) or previous versions of IE we check for the documentMode or compatMode for pre 8 versions \n ieDocMode = (_d.documentMode) ? _d.documentMode : (_d.compatMode && _d.compatMode==\"CSS1Compat\") ? 7 : 5;//default to quirks mode IE5 \n }\n }\n\n return {\n \"UserAgent\" : na,\n \"Version\" : version,\n \"BrowserMode\" : ie8BrowserMode,\n \"DocMode\": ieDocMode\n } \n}\nvar ieVersion = IEVersion();\nvar IsIE8 = ieVersion.Version != \"NA\" && ieVersion.Version >= 8;\n" }, { "answer_id": 17086279, "author": "Jerad Rutnam", "author_id": 2482093, "author_profile": "https://Stackoverflow.com/users/2482093", "pm_score": 1, "selected": false, "text": "if (navigator.appName == 'Microsoft Internet Explorer') {\n // Take navigator appversion to an array & split it \n var appVersion = navigator.appVersion.split(';');\n // Get the part that you want from the above array \n var verNumber = appVersion[1];\n\n alert(verNumber);\n}\n if (navigator.appName == 'Microsoft Internet Explorer') {\n var appVersion = navigator.appVersion.split(';');\n var verNumber = appVersion[1];\n // Reaplce \"MSIE \" from the srting and parse it to integer value \n var IEversion = parseInt(verNumber.replace('MSIE ', ''));\n\n if(IEversion <= 9){\n alert(verNumber);\n }\n}\n" }, { "answer_id": 22380361, "author": "user3415643", "author_id": 3415643, "author_profile": "https://Stackoverflow.com/users/3415643", "pm_score": 0, "selected": false, "text": "<script>\n alert(\"It is \" + isIE());\n\n //return ie number as int else return false\n function isIE() {\n var myNav = navigator.userAgent.toLowerCase();\n if (myNav.indexOf('msie') != -1) //ie less than ie11 (6-10)\n {\n return parseInt(myNav.split('msie')[1]);\n }\n else \n {\n //Is the version more than ie11? Then return false else return ie int number\n return (!!(myNav.match(/trident/) && !myNav.match(/msie/)) == false)?false : parseInt(myNav.split('rv:')[1].substring(0, 2)); \n }\n }\n</script>\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280879", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
280,891
<p>I've decided to reimplement the datetime picker, as a standard datetime picker isn't nullable. The user wants to start with a blank field and type (not select) the date.</p> <p>I've created a user control to do just that, but if the user control is near the edge of the form, it will be cut off on the form boundry. The standard datetime picker doesn't suffer from this problem.</p> <p>Here is a picture showing the problem. My user control is on the left, the standard datetimepicker is on the right:</p> <p><a href="http://img50.imageshack.us/img50/9104/datetimepickervu6.jpg">alt text http://img50.imageshack.us/img50/9104/datetimepickervu6.jpg</a></p> <p>As you can see, the standard control will display over the form AND application boundry. How do I get the month picker in my control to do the same thing?</p> <p>Thanks!</p>
[ { "answer_id": 280932, "author": "Bruno Shine", "author_id": 28294, "author_profile": "https://Stackoverflow.com/users/28294", "pm_score": 1, "selected": false, "text": "SafeNativeMethods.SetWindowPos SetBoundsCore" }, { "answer_id": 282008, "author": "Robert Rossney", "author_id": 19403, "author_profile": "https://Stackoverflow.com/users/19403", "pm_score": 2, "selected": false, "text": "Windows.Forms" }, { "answer_id": 282217, "author": "Jesper Palm", "author_id": 36455, "author_profile": "https://Stackoverflow.com/users/36455", "pm_score": 6, "selected": true, "text": "/// <summary>\n/// A simple popup window that can host any System.Windows.Forms.Control\n/// </summary>\npublic class PopupWindow : System.Windows.Forms.ToolStripDropDown\n{\n private System.Windows.Forms.Control _content;\n private System.Windows.Forms.ToolStripControlHost _host;\n\n public PopupWindow(System.Windows.Forms.Control content)\n {\n //Basic setup...\n this.AutoSize = false;\n this.DoubleBuffered = true;\n this.ResizeRedraw = true;\n\n this._content = content;\n this._host = new System.Windows.Forms.ToolStripControlHost(content);\n\n //Positioning and Sizing\n this.MinimumSize = content.MinimumSize;\n this.MaximumSize = content.Size;\n this.Size = content.Size;\n content.Location = Point.Empty;\n\n //Add the host to the list\n this.Items.Add(this._host);\n }\n}\n PopupWindow popup = new PopupWindow(MyControlToHost);\npopup.Show(new Point(100,100));\n...\npopup.Close();\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280891", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29830/" ]
280,892
<p>I'm looking to write a small proxy server for kicks and giggles.</p> <p>Apart from the options in libWWW, can anyone recommend any opensource options for the HTTP server and client code? Thinking of a library of some kind similar to libWWW.</p> <p>Chosen language is C/C++ but open to Java, C#, Python... etc. :-)</p>
[ { "answer_id": 280932, "author": "Bruno Shine", "author_id": 28294, "author_profile": "https://Stackoverflow.com/users/28294", "pm_score": 1, "selected": false, "text": "SafeNativeMethods.SetWindowPos SetBoundsCore" }, { "answer_id": 282008, "author": "Robert Rossney", "author_id": 19403, "author_profile": "https://Stackoverflow.com/users/19403", "pm_score": 2, "selected": false, "text": "Windows.Forms" }, { "answer_id": 282217, "author": "Jesper Palm", "author_id": 36455, "author_profile": "https://Stackoverflow.com/users/36455", "pm_score": 6, "selected": true, "text": "/// <summary>\n/// A simple popup window that can host any System.Windows.Forms.Control\n/// </summary>\npublic class PopupWindow : System.Windows.Forms.ToolStripDropDown\n{\n private System.Windows.Forms.Control _content;\n private System.Windows.Forms.ToolStripControlHost _host;\n\n public PopupWindow(System.Windows.Forms.Control content)\n {\n //Basic setup...\n this.AutoSize = false;\n this.DoubleBuffered = true;\n this.ResizeRedraw = true;\n\n this._content = content;\n this._host = new System.Windows.Forms.ToolStripControlHost(content);\n\n //Positioning and Sizing\n this.MinimumSize = content.MinimumSize;\n this.MaximumSize = content.Size;\n this.Size = content.Size;\n content.Location = Point.Empty;\n\n //Add the host to the list\n this.Items.Add(this._host);\n }\n}\n PopupWindow popup = new PopupWindow(MyControlToHost);\npopup.Show(new Point(100,100));\n...\npopup.Close();\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280892", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
280,894
<p>I have an access database, with a query made. I need to automate it so that each night this query can run and export to a tab delimited csv file. It is not possible to export a query to a csv file from within access. My question is, are there any tools that can select certain tables, or perform an sql query on an mdb file, and export to a csv file?</p>
[ { "answer_id": 280900, "author": "Fionnuala", "author_id": 2548, "author_profile": "https://Stackoverflow.com/users/2548", "pm_score": 2, "selected": false, "text": " Sub TransferCSV()\n\n DoCmd.TransferText acExportDelim, , \"PutNameOfQueryHere\", \"C:\\PutPathAnd\\FilenameHere.csv\", True\n\n End Sub\n db = \"C:\\Docs\\LTD.mdb\"\nTextExportFile = \"C:\\Docs\\Exp.txt\"\n\nSet cn = CreateObject(\"ADODB.Connection\")\nSet rs = CreateObject(\"ADODB.Recordset\")\n\ncn.Open _\n \"Provider = Microsoft.Jet.OLEDB.4.0; \" & _\n \"Data Source =\" & db\n\nstrSQL = \"SELECT * FROM tblMembers\"\n\nrs.Open strSQL, cn, 3, 3\n\nSet fs = CreateObject(\"Scripting.FileSystemObject\")\n\nSet f = fs.CreateTextFile(TextExportFile, True)\n\na = rs.GetString\n\nf.WriteLine a\n\nf.Close\n" }, { "answer_id": 280965, "author": "Patrick Cuff", "author_id": 7903, "author_profile": "https://Stackoverflow.com/users/7903", "pm_score": 3, "selected": true, "text": " Name = ExportQuery\n Action = TransferText\n Transfer Type = Export Delimited\n Table Name = [name of your Access query]\n File Name = [path of output file]\n Has Field Names = [Yes or No, as desired]\n \"[your MS Office path]\\msaccess.exe\" [your databse].mdb /excl /X ExportQuery /runtime\n Function ExportQuery()\n DoCmd.TransferText acExportDelim, , \"[your query]\", \"[output file].csv\"\nEnd Function\n Action = RunCode\nFunction Name = ExportQuery ()\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280894", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1246613/" ]
280,896
<p>I seem to be in the minority, but to be honest I am not comfortable with linq and don't see any benefits in my personal development (not to say there are no benefits, just a personal opinion based on my situation).</p> <p>I build web applications (.net, .net mvc) and I love having part of my data layer in stored procedures. One thing I love about sprocs is that I can generate the entire db to script, then scan my queries, <b>readable queries</b> I might add, at a high level.</p> <p>For those of you who don't like linq, what is your reason? Is it just lack of knowledge/learning curve or is there a business case for not using it?</p>
[ { "answer_id": 280954, "author": "b1tsn4ck", "author_id": 36481, "author_profile": "https://Stackoverflow.com/users/36481", "pm_score": 1, "selected": false, "text": "foreach" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280896", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
280,904
<p>I hope this is a simple enough question for any SQL people out there...</p> <p>We have a table which hold system configuration data, and this is tied to a history table via triggers so we can track who changed what, and when. </p> <p>I have a requirement to add another value in to this table, but it is one that will change frequently from code, and has a requirement that we don't track it's history (we don't want to clog the table with many thousands of updates per day.</p> <p>At present, our trigger is a little like this...</p> <pre><code>CREATE TRIGGER [dbo].[SystemParameterInsertUpdate] ON [dbo].[SystemParameter] FOR INSERT, UPDATE AS BEGIN SET NOCOUNT ON INSERT INTO SystemParameterHistory ( Attribute, ParameterValue, ParameterDescription, ChangeDate ) SELECT Attribute, ParameterValue, ParameterDescription, ChangeDate FROM Inserted AS I END </code></pre> <p>I'd like to be able to add some logic to stop it creating the record if an Attribute colum value is prefixed with a specific string (e.g. "NoHist_")</p> <p>Given that I have almost no experience working with triggers, I was wondering how it would be best to implement this... I have tried a where clause like the following</p> <pre><code>where I.Attribute NOT LIKE 'NoHist_%' </code></pre> <p>but it doesn't seem to work. The value is still copied over into the history table.</p> <p>Any help you could offer would be appreciated.</p> <hr> <p>OK - as predicted by Cade Roux, this fail spectacularly on multiple updates. I'm going to have to take a new approach to this. Does anyone have any other suggestions, please?</p> <hr> <p>Guys - Please educate me here... Why would LEFT() be preferable to LIKE in this scenario? I know I've accepted the answer, but I'd like to know for my own education. </p>
[ { "answer_id": 280956, "author": "Joel Coehoorn", "author_id": 3043, "author_profile": "https://Stackoverflow.com/users/3043", "pm_score": 7, "selected": true, "text": "CREATE TRIGGER \n [dbo].[SystemParameterInsertUpdate]\nON \n [dbo].[SystemParameter]\nFOR INSERT, UPDATE \nAS\n BEGIN\n SET NOCOUNT ON\n\n If (SELECT Attribute FROM INSERTED) LIKE 'NoHist_%'\n Begin\n Return\n End\n\n INSERT INTO SystemParameterHistory \n (\n Attribute,\n ParameterValue,\n ParameterDescription,\n ChangeDate\n )\n SELECT\n Attribute,\n ParameterValue,\n ParameterDescription,\n ChangeDate\n FROM Inserted AS I\nEND\n" }, { "answer_id": 280975, "author": "Matty", "author_id": 26241, "author_profile": "https://Stackoverflow.com/users/26241", "pm_score": 3, "selected": false, "text": "CREATE TRIGGER \n[dbo].[SystemParameterInsertUpdate]\nON \n[dbo].[SystemParameter]\nFOR INSERT, UPDATE \nAS\nBEGIN\nSET NOCOUNT ON\n IF (LEFT((SELECT Attribute FROM INSERTED), 7) <> 'NoHist_') \n BEGIN\n INSERT INTO SystemParameterHistory \n (\n Attribute,\n ParameterValue,\n ParameterDescription,\n ChangeDate\n )\n SELECT\n Attribute,\n ParameterValue,\n ParameterDescription,\n ChangeDate\n FROM Inserted AS I\nEND\nEND\n" }, { "answer_id": 281849, "author": "Cade Roux", "author_id": 18255, "author_profile": "https://Stackoverflow.com/users/18255", "pm_score": 3, "selected": false, "text": "_ CREATE TRIGGER \n [dbo].[SystemParameterInsertUpdate]\nON \n [dbo].[SystemParameter]\nFOR INSERT, UPDATE \nAS\n BEGIN\n SET NOCOUNT ON\n INSERT INTO SystemParameterHistory \n (\n Attribute,\n ParameterValue,\n ParameterDescription,\n ChangeDate\n )\n SELECT\n I.Attribute,\n I.ParameterValue,\n I.ParameterDescription,\n I.ChangeDate\n FROM Inserted AS I\n WHERE I.Attribute NOT LIKE 'NoHist[_]%'\nEND\n" }, { "answer_id": 562458, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": -1, "selected": false, "text": "DECLARE @Attribute;\nDECLARE @ParameterValue;\nDECLARE mycursor CURSOR FOR SELECT Attribute, ParameterValue FROM inserted;\nOPEN mycursor;\nFETCH NEXT FROM mycursor into @Attribute, @ParameterValue;\nWHILE @@FETCH_STATUS = 0\nBEGIN\n\nIf @Attribute LIKE 'NoHist_%'\n Begin\n Return\n End\n\netc.\n\nFETCH NEXT FROM mycursor into @Attribute, @ParameterValue;\nEND\n" }, { "answer_id": 3631976, "author": "QuintessentialSolutions", "author_id": 438470, "author_profile": "https://Stackoverflow.com/users/438470", "pm_score": 2, "selected": false, "text": "CREATE TRIGGER\n [dbo].[SystemParameterInsertUpdate]\nON \n [dbo].[SystemParameter]\nFOR INSERT, UPDATE \nAS\n BEGIN\n SET NOCOUNT ON \n\n DECLARE @StartRow int\n DECLARE @EndRow int\n DECLARE @CurrentRow int\n\n SET @StartRow = 1\n SET @EndRow = (SELECT count(*) FROM inserted)\n SET @CurrentRow = @StartRow\n\n WHILE @CurrentRow <= @EndRow BEGIN\n\n IF (SELECT Attribute FROM (SELECT ROW_NUMBER() OVER (ORDER BY Attribute ASC) AS 'RowNum', Attribute FROM inserted) AS INS WHERE RowNum = @CurrentRow) LIKE 'NoHist_%' BEGIN\n\n INSERT INTO SystemParameterHistory(\n Attribute,\n ParameterValue,\n ParameterDescription,\n ChangeDate)\n SELECT\n I.Attribute,\n I.ParameterValue,\n I.ParameterDescription,\n I.ChangeDate\n FROM\n (SELECT Attribute, ParameterValue, ParameterDescription, ChangeDate FROM (\n SELECT ROW_NUMBER() OVER (ORDER BY Attribute ASC) AS 'RowNum', * \n FROM inserted)\n AS I \n WHERE RowNum = @CurrentRow\n\n END --END IF\n\n SET @CurrentRow = @CurrentRow + 1\n\n END --END WHILE\nEND --END TRIGGER\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280904", "https://Stackoverflow.com", "https://Stackoverflow.com/users/377/" ]
280,909
<p>Is there a programmatic method to set CPU affinity for a process in c/c++ for the Linux operating system?</p>
[ { "answer_id": 280924, "author": "Alnitak", "author_id": 6782, "author_profile": "https://Stackoverflow.com/users/6782", "pm_score": 7, "selected": true, "text": "sched_setaffinity(2) #define _GNU_SOURCE\n#include <sched.h>\n\ncpu_set_t mask;\nCPU_ZERO(&mask);\nCPU_SET(0, &mask);\nCPU_SET(2, &mask);\nint result = sched_setaffinity(0, sizeof(mask), &mask);\n 0 sched_getcpu(3)" }, { "answer_id": 280996, "author": "thAAAnos", "author_id": 36557, "author_profile": "https://Stackoverflow.com/users/36557", "pm_score": 2, "selected": false, "text": "unsigned long mask = 7; /* processors 0, 1, and 2 */\nunsigned int len = sizeof(mask);\nif (sched_setaffinity(0, len, &mask) < 0) {\n perror(\"sched_setaffinity\");\n}\n" }, { "answer_id": 41299791, "author": "Amiri", "author_id": 7030791, "author_profile": "https://Stackoverflow.com/users/7030791", "pm_score": 3, "selected": false, "text": "gcc #include <sched.h> \ncpu_set_t mask;\n\ninline void assignToThisCore(int core_id)\n{\n CPU_ZERO(&mask);\n CPU_SET(core_id, &mask);\n sched_setaffinity(0, sizeof(mask), &mask);\n}\nint main(){\n //cal this:\n assignToThisCore(2);//assign to core 0,1,2,...\n\n return 0;\n}\n -D _GNU_SOURCE GRUB_CMDLINE_LINUX_DEFAULT=\"quiet splash isolcpus=2,3\" /etc/default sudo update-grub inline void assignToThisCores(int core_id1, int core_id2)\n{\n CPU_ZERO(&mask1);\n CPU_SET(core_id1, &mask1);\n CPU_SET(core_id2, &mask1);\n sched_setaffinity(0, sizeof(mask1), &mask1);\n //__asm__ __volatile__ ( \"vzeroupper\" : : : ); // It is hear because of that bug which dirtied the AVX registers, so, if you rely on AVX uncomment it.\n}\n" }, { "answer_id": 54478296, "author": "Ciro Santilli OurBigBook.com", "author_id": 895245, "author_profile": "https://Stackoverflow.com/users/895245", "pm_score": 2, "selected": false, "text": "sched_setaffinity sched_getaffinity sched_getaffinity sched_getcpu() #define _GNU_SOURCE\n#include <assert.h>\n#include <sched.h>\n#include <stdbool.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <unistd.h>\n\nvoid print_affinity() {\n cpu_set_t mask;\n long nproc, i;\n\n if (sched_getaffinity(0, sizeof(cpu_set_t), &mask) == -1) {\n perror(\"sched_getaffinity\");\n assert(false);\n }\n nproc = sysconf(_SC_NPROCESSORS_ONLN);\n printf(\"sched_getaffinity = \");\n for (i = 0; i < nproc; i++) {\n printf(\"%d \", CPU_ISSET(i, &mask));\n }\n printf(\"\\n\");\n}\n\nint main(void) {\n cpu_set_t mask;\n\n print_affinity();\n printf(\"sched_getcpu = %d\\n\", sched_getcpu());\n CPU_ZERO(&mask);\n CPU_SET(0, &mask);\n if (sched_setaffinity(0, sizeof(cpu_set_t), &mask) == -1) {\n perror(\"sched_setaffinity\");\n assert(false);\n }\n print_affinity();\n /* TODO is it guaranteed to have taken effect already? Always worked on my tests. */\n printf(\"sched_getcpu = %d\\n\", sched_getcpu());\n return EXIT_SUCCESS;\n}\n gcc -ggdb3 -O0 -std=c99 -Wall -Wextra -pedantic -o main.out main.c\n./main.out\n sched_getaffinity = 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \nsched_getcpu = 9\nsched_getaffinity = 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \nsched_getcpu = 0\n taskset taskset -c 1,3 ./a.out\n sched_getaffinity = 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 \nsched_getcpu = 2\nsched_getaffinity = 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \nsched_getcpu = 0\n taskset os.sched_getaffinity os.sched_setaffinity" }, { "answer_id": 64960466, "author": "Rachid K.", "author_id": 14393739, "author_profile": "https://Stackoverflow.com/users/14393739", "pm_score": 0, "selected": false, "text": "$ ls -l /sys/fs/cgroup/\ntotal 0\ndrwxr-xr-x 15 root root 380 nov. 22 20:00 ./\ndrwxr-xr-x 8 root root 0 nov. 22 20:00 ../\ndr-xr-xr-x 2 root root 0 nov. 22 20:00 blkio/\n[...]\nlrwxrwxrwx 1 root root 11 nov. 22 20:00 cpuacct -> cpu,cpuacct/\ndr-xr-xr-x 2 root root 0 nov. 22 20:00 cpuset/\ndr-xr-xr-x 5 root root 0 nov. 22 20:00 devices/\ndr-xr-xr-x 3 root root 0 nov. 22 20:00 freezer/\n[...]\n $ cd /sys/fs/cgroup/cpuset\n$ cat cpuset.cpus\n0-7\n $ cat cgroup.procs\n1\n2\n3\n[...]\n12364\n12423\n12424\n12425\n[...]\n $ pwd\n/sys/fs/cgroup/cpuset\n$ sudo mkdir subset1\n$ cd subset1\n$ pwd\n/sys/fs/cgroup/cpuset/subset1\n$ ls -l \ntotal 0\n-rw-r--r-- 1 root root 0 nov. 22 23:28 cgroup.clone_children\n-rw-r--r-- 1 root root 0 nov. 22 23:28 cgroup.procs\n-rw-r--r-- 1 root root 0 nov. 22 23:28 cpuset.cpu_exclusive\n-rw-r--r-- 1 root root 0 nov. 22 23:28 cpuset.cpus\n-r--r--r-- 1 root root 0 nov. 22 23:28 cpuset.effective_cpus\n-r--r--r-- 1 root root 0 nov. 22 23:28 cpuset.effective_mems\n-rw-r--r-- 1 root root 0 nov. 22 23:28 cpuset.mem_exclusive\n-rw-r--r-- 1 root root 0 nov. 22 23:28 cpuset.mem_hardwall\n-rw-r--r-- 1 root root 0 nov. 22 23:28 cpuset.memory_migrate\n-r--r--r-- 1 root root 0 nov. 22 23:28 cpuset.memory_pressure\n-rw-r--r-- 1 root root 0 nov. 22 23:28 cpuset.memory_spread_page\n-rw-r--r-- 1 root root 0 nov. 22 23:28 cpuset.memory_spread_slab\n-rw-r--r-- 1 root root 0 nov. 22 23:28 cpuset.mems\n-rw-r--r-- 1 root root 0 nov. 22 23:28 cpuset.sched_load_balance\n-rw-r--r-- 1 root root 0 nov. 22 23:28 cpuset.sched_relax_domain_level\n-rw-r--r-- 1 root root 0 nov. 22 23:28 notify_on_release\n-rw-r--r-- 1 root root 0 nov. 22 23:28 tasks\n$ cat cpuset.cpus\n\n$ sudo sh -c \"echo 1,3 > cpuset.cpus\"\n$ cat cpuset.cpus \n1,3\n $ cat cgroup.procs\n\n$ echo $$\n4753\n$ sudo sh -c \"echo 4753 > cgroup.procs\"\nsh: 1: echo: echo: I/O error\n$ cat cpuset.mems\n\n$ sudo sh -c \"echo 0 > cpuset.mems\"\n$ cat cpuset.mems\n0\n$ sudo sh -c \"echo 4753 > cgroup.procs\"\n$ cat cgroup.procs\n4753\n12569\n $ ps -o pid,ppid,psr,command\n PID PPID PSR COMMAND\n 4753 2372 3 bash\n 12672 4753 1 ps -o pid,ppid,psr,command\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280909", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7362/" ]
280,940
<p>I am programming in C against a third party library (in HP/Mercury Loadrunner) that allows a varargs-style variable size argument list for one of it's functions. I want to call this function but I do not know up front how many arguments I will have. </p> <p>There is a function made by one of my predecessors that serves somewhat but the problem here is that this function assumes the worst case scenario (over 3000 arguments) and hand-codes for that.</p> <p>To illuminate, here's the (beginning of) the code. The function we call is <code>web_submit_data()</code>. It will HTTP post a set of form data. This implementation came about when dealing with dynamically generated forms with an arbitrary number of fields. (Cleaned up a fair bit from the original, which hand coded indexes by hand as well..)</p> <hr> <pre><code>web_submit_data_buffer_gazillion_items( const char *bufferName, const char *bufferValue) { const int size = 129; int i = 0; int j = 11; web_submit_data(&amp;bufferName[i++ * size], //"some form" &amp;bufferName[i++ * size], //"Action=https://blah.blah/form"); &amp;bufferName[i++ * size], //"Method=POST"); &amp;bufferName[i++ * size], //"TargetFrame="); &amp;bufferName[i++ * size], //"RecContentType=text/html"); &amp;bufferName[i++ * size], //"Referer=https://blah.blah/index.html"); &amp;bufferName[i++ * size], //"Snapshot=t1.inf"); &amp;bufferName[i++ * size], //"Mode=HTML"); ITEMDATA, // missing in action: indexes 8 through 10 &amp;bufferName[j * size],&amp;bufferValue[j++ * size], ENDITEM, &amp;bufferName[j * size],&amp;bufferValue[j++ * size], ENDITEM, &amp;bufferName[j * size],&amp;bufferValue[j++ * size], ENDITEM, .. (repeat the last 3 lines ad nauseum) .. &amp;bufferName[j * size],&amp;bufferValue[j++ * size], ENDITEM, &amp;bufferName[j * size]); } </code></pre> <p>Now I have found an external library that might work (<a href="http://www.dyncall.org" rel="noreferrer">http://www.dyncall.org</a>) but I would much rather not a) be completely processor dependant and b) attempt to teach Loadrunner about linking in external sources..</p> <p>Edit: The original function used hardcoded indexes instead of using a variable. Can still revert to that if it turns out to be too unpredictable. However, as I am unlikely to run this with a different compiler or hardware / OS I doubt that really is worth it.</p> <p>Also: I don't have control over the implementation of web_submit_data(). So just pushing the problem down one level isn't going to cut it..</p> <p>Another thing to note: The spec for <code>web_submit_data()</code> uses a constant called LAST to mark the end of the argument list. The original implementation doesn't use it. Presumably the callsite does ..</p>
[ { "answer_id": 281029, "author": "pnkfelix", "author_id": 36585, "author_profile": "https://Stackoverflow.com/users/36585", "pm_score": 1, "selected": false, "text": "web_submit_data" }, { "answer_id": 281055, "author": "Ben Collins", "author_id": 3279, "author_profile": "https://Stackoverflow.com/users/3279", "pm_score": 1, "selected": false, "text": "struct form_field\n{\n char[FIELD_NAME_MAX] name;\n char[FIELD_VALUE_MAX] val;\n};\n\nweb_submit_data_buffer_gazillion_items( const char *bufferName, const char *bufferValue)\n{\n /*\n loop over bufferName somehow, either with a known size or terminating record,\n and build an array of form_field records\n */\n //loop\n {\n // build array of records\n }\n\n\n web_submit_data(record_array, array_len);\n\n}\n" }, { "answer_id": 281153, "author": "HUAGHAGUAH", "author_id": 27233, "author_profile": "https://Stackoverflow.com/users/27233", "pm_score": 1, "selected": false, "text": "#define WEB_SUBMIT_BUFFER(name, val) \\\n do { \\\n const int size = 129; \\\n int i = 0; \\\n int j = 11; \\\n web_submit_data(&(name)[i++ * size], \\\n &(name)[i++ * size], \\\n /* etc ad nauseum */ \\\n } while (0)\n #define WEB_SUBMIT_BUFFER_32(name, val) \\\n do { \\\n const int size = 129; \\\n int i = 0; \\\n int j = 11; \\\n web_submit_data(&(name)[i++ * size], \\\n &(name)[i++ * size], \\\n /* 32 times */ \\\n } while (0)\n#define WEB_SUBMIT_BUFFER_33(name, val) ...\n#define WEB_SUBMIT_BUFFER_34(name, val) /* etc */\n" }, { "answer_id": 281603, "author": "Michael Burr", "author_id": 12711, "author_profile": "https://Stackoverflow.com/users/12711", "pm_score": 1, "selected": false, "text": "i j i j web_submit_data() web_submit_data()" }, { "answer_id": 281731, "author": "Michael Burr", "author_id": 12711, "author_profile": "https://Stackoverflow.com/users/12711", "pm_score": 2, "selected": false, "text": "// you didn't give a clear specification of what you want/need, so this \n// example may not be quite what you want as I've had to guess at\n// some of the specifications. Hopefully the comments will make clear\n// what I may have assumed.\n//\n// NOTE: while I have compiled this example, I have not tested it,\n// so there is a distinct possiblity of bugs (particularly\n// off-by-one errors). Check me on this stuff, please.\n\n// I made these up so I could compile the example\n#define ITEMDATA ((char const*) NULL)\n#define ENDITEM ((char const*) 0xffffffff)\n\nvoid web_submit_data_wrapper( const char*bufferName, \n const char* bufferValue, \n size_t headerCount, // number of header pointers to pass (8 in your example)\n size_t itemStartIndex, // index where items start in the buffers (11 in your example)\n size_t itemCount, // number of items to pass (unspecified in your example)\n size_t dataSize ) // size of each header or item (129 in your example)\n{\n // kMaxVarArgs would be 3000 or a gazillion in your case\n\n // size_t const kMaxVarArgs = 20; // I'd prefer to use this in C++\n #define kMaxVarArgs (20)\n\n typedef char const* char_ptr_t;\n typedef char_ptr_t char_ptr_array_t[kMaxVarArgs];\n\n char_ptr_array_t varargs = {0};\n\n size_t idx = 0;\n\n // build up the array of pararmeters we'll pass to the variable arg list\n\n // first the headers\n while (headerCount--) {\n varargs[idx++] = &bufferName[idx * dataSize];\n }\n\n // mark the end of the header data\n varargs[idx++] = ITEMDATA;\n\n // now the \"items\"\n while (itemCount--) {\n varargs[idx++] = &bufferName[itemStartIndex * dataSize];\n varargs[idx++] = &bufferValue[itemStartIndex * dataSize];\n varargs[idx++] = ENDITEM;\n\n ++itemStartIndex;\n }\n\n // the thing after the last item \n // (I'm not sure what this is from your example)\n varargs[idx] = &bufferName[itemStartIndex * dataSize];\n\n // now call the target function - the fact that we're passing more arguments\n // than necessary should not matter due to the way VA_ARGS are handled \n // but see the Footnote in the SO answer for a disclaimer\n\n web_submit_data( \n varargs[0],\n varargs[1],\n varargs[2],\n\n //... ad nasuem until\n\n varargs[kMaxVarArgs-1]\n );\n\n}\n stdargs.h" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280940", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36574/" ]
280,948
<p>I am setting-up my DataGridView like this:</p> <pre><code> jobs = new List&lt;DisplayJob&gt;(); uxJobList.AutoGenerateColumns = false; jobListBindingSource.DataSource = jobs; uxJobList.DataSource = jobListBindingSource; int newColumn; newColumn = uxJobList.Columns.Add("Id", "Job No."); uxJobList.Columns[newColumn].DataPropertyName = "Id"; uxJobList.Columns[newColumn].DefaultCellStyle.Format = Global.JobIdFormat; uxJobList.Columns[newColumn].DefaultCellStyle.Font = new Font(uxJobList.DefaultCellStyle.Font, FontStyle.Bold); uxJobList.Columns[newColumn].AutoSizeMode = DataGridViewAutoSizeColumnMode.None; uxJobList.Columns[newColumn].Width = 62; uxJobList.Columns[newColumn].Resizable = DataGridViewTriState.False; uxJobList.Columns[newColumn].SortMode = DataGridViewColumnSortMode.Automatic; : : </code></pre> <p>where the DisplayJob class looks like:</p> <pre><code> public class DisplayJob { public DisplayJob(int id) { Id = id; } public DisplayJob(JobEntity job) { Id = job.Id; Type = job.JobTypeDescription; CreatedAt = job.CreatedAt; StartedAt = job.StartedAt; ExternalStatus = job.ExternalStatus; FriendlyExternalStatus = job.FriendlyExternalStatus; ExternalStatusFriendly = job.ExternalStatusFriendly; CustomerName = job.Customer.Name; CustomerKey = job.Customer.CustomerKey; WorkAddress = job.WorkAddress; CreatedBy = job.CreatedBy; CancelledAt = job.CancelledAt; ClosedAt = job.ClosedAt; ReasonWaiting = job.ReasonWaiting; CancelledBy = job.CancelledBy; CancelledReason = job.CancelledReason; DisplayCreator = Global.GetDisplayName(CreatedBy); ActionRedoNeeded = job.ActionRedoNeeded; if (job.Scheme != null) { SchemeCode = job.Scheme.Code; } } public int Id { get; private set; } public string Type { get; private set; } public DateTime CreatedAt { get; private set; } public DateTime? StartedAt { get; private set; } public string ExternalStatus { get; private set; } public string FriendlyExternalStatus { get; private set; } public string ExternalStatusFriendly { get; private set; } public string CustomerName { get; private set; } public string CustomerKey { get; private set; } public string WorkAddress { get; private set; } public string CreatedBy { get; private set; } public DateTime? CancelledAt { get; private set; } public DateTime? ClosedAt { get; private set; } public string CancelledBy { get; private set; } public string ReasonWaiting { get; private set; } public string DisplayCreator { get; private set; } public string CancelledReason { get; private set; } public string SchemeCode { get; private set; } public bool ActionRedoNeeded { get; private set; } } </code></pre> <p>However the column sorting does not work. What is the best way to get this working?</p>
[ { "answer_id": 280958, "author": "Bruno Shine", "author_id": 28294, "author_profile": "https://Stackoverflow.com/users/28294", "pm_score": 1, "selected": false, "text": "IComparable" }, { "answer_id": 280992, "author": "Patrick Desjardins", "author_id": 13913, "author_profile": "https://Stackoverflow.com/users/13913", "pm_score": 4, "selected": true, "text": "protected override bool SupportsSearchingCore\n{\n get\n {\n return true;\n }\n}\n\nprotected override bool SupportsSortingCore\n{\n get { return true; }\n}\n ListSortDirection sortDirectionValue;\nPropertyDescriptor sortPropertyValue;\n\nprotected override void ApplySortCore(PropertyDescriptor prop, \n ListSortDirection direction)\n{\n sortedList = new ArrayList();\n\n // Check to see if the property type we are sorting by implements\n // the IComparable interface.\n Type interfaceType = prop.PropertyType.GetInterface(\"IComparable\");\n\n if (interfaceType != null)\n {\n // If so, set the SortPropertyValue and SortDirectionValue.\n sortPropertyValue = prop;\n sortDirectionValue = direction;\n\n unsortedItems = new ArrayList(this.Count);\n\n // Loop through each item, adding it the the sortedItems ArrayList.\n foreach (Object item in this.Items) {\n sortedList.Add(prop.GetValue(item));\n unsortedItems.Add(item);\n }\n // Call Sort on the ArrayList.\n sortedList.Sort();\n T temp;\n\n // Check the sort direction and then copy the sorted items\n // back into the list.\n if (direction == ListSortDirection.Descending)\n sortedList.Reverse();\n\n for (int i = 0; i < this.Count; i++)\n {\n int position = Find(prop.Name, sortedList[i]);\n if (position != i) {\n temp = this[i];\n this[i] = this[position];\n this[position] = temp;\n }\n }\n\n isSortedValue = true;\n\n // Raise the ListChanged event so bound controls refresh their\n // values.\n OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1));\n }\n else\n // If the property type does not implement IComparable, let the user\n // know.\n throw new NotSupportedException(\"Cannot sort by \" + prop.Name +\n \". This\" + prop.PropertyType.ToString() + \n \" does not implement IComparable\");\n}\n" }, { "answer_id": 281973, "author": "Robert Rossney", "author_id": 19403, "author_profile": "https://Stackoverflow.com/users/19403", "pm_score": 3, "selected": false, "text": "IBindingList" }, { "answer_id": 2115736, "author": "Martijn Boeker", "author_id": 226103, "author_profile": "https://Stackoverflow.com/users/226103", "pm_score": 2, "selected": false, "text": "//---------------------------------------------------------------------\n// Copyright (C) Microsoft Corporation. All rights reserved.\n// \n//THIS CODE AND INFORMATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY\n//KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE\n//IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A\n//PARTICULAR PURPOSE.\n//---------------------------------------------------------------------\n\nusing System;\nusing System.Collections.Generic;\nusing System.ComponentModel;\nusing System.Data;\nusing System.Drawing;\nusing System.Text;\nusing System.Windows.Forms;\nusing System.Reflection;\nusing System.Collections;\n\nnamespace SomethingSomething\n{\n /// <summary>\n /// Supports sorting of list in data grid view.\n /// </summary>\n /// <typeparam name=\"T\">Type of object to be displayed in data grid view.</typeparam>\n public class SortableSearchableList<T> : BindingList<T>\n {\n #region Data Members\n\n private ListSortDirection _sortDirectionValue;\n private PropertyDescriptor _sortPropertyValue = null;\n\n /// <summary>\n /// Dictionary from property name to custom comparison function.\n /// </summary>\n private Dictionary<string, Comparison<T>> _customComparisons = new Dictionary<string, Comparison<T>>();\n\n #endregion\n\n #region Constructors\n\n /// <summary>\n /// Default constructor.\n /// </summary>\n public SortableSearchableList()\n {\n }\n\n #endregion\n\n #region Properties\n\n /// <summary>\n /// Indicates if sorting is supported.\n /// </summary>\n protected override bool SupportsSortingCore\n {\n get\n {\n return true;\n }\n }\n\n /// <summary>\n /// Indicates if list is sorted.\n /// </summary>\n protected override bool IsSortedCore\n {\n get\n {\n return _sortPropertyValue != null;\n }\n }\n\n /// <summary>\n /// Indicates which property the list is sorted.\n /// </summary>\n protected override PropertyDescriptor SortPropertyCore\n {\n get\n {\n return _sortPropertyValue;\n }\n }\n\n /// <summary>\n /// Indicates in which direction the list is sorted on.\n /// </summary>\n protected override ListSortDirection SortDirectionCore\n {\n get\n {\n return _sortDirectionValue;\n }\n }\n\n #endregion\n\n #region Methods \n\n /// <summary>\n /// Add custom compare method for property.\n /// </summary>\n /// <param name=\"propertyName\"></param>\n /// <param name=\"compareProperty\"></param>\n protected void AddCustomCompare(string propertyName, Comparison<T> comparison)\n {\n _customComparisons.Add(propertyName, comparison);\n }\n\n /// <summary>\n /// Apply sort.\n /// </summary>\n /// <param name=\"prop\"></param>\n /// <param name=\"direction\"></param>\n protected override void ApplySortCore(PropertyDescriptor prop, ListSortDirection direction)\n {\n Comparison<T> comparison;\n if (!_customComparisons.TryGetValue(prop.Name, out comparison))\n {\n // Check to see if the property type we are sorting by implements\n // the IComparable interface.\n Type interfaceType = prop.PropertyType.GetInterface(\"IComparable\");\n if (interfaceType != null)\n {\n comparison = delegate(T t1, T t2)\n {\n IComparable val1 = (IComparable)prop.GetValue(t1);\n IComparable val2 = (IComparable)prop.GetValue(t2);\n return val1.CompareTo(val2);\n };\n }\n else\n {\n // Last option: convert to string and compare.\n comparison = delegate(T t1, T t2)\n {\n string val1 = prop.GetValue(t1).ToString();\n string val2 = prop.GetValue(t2).ToString();\n return val1.CompareTo(val2);\n };\n }\n }\n\n if (comparison != null)\n {\n // If so, set the SortPropertyValue and SortDirectionValue.\n _sortPropertyValue = prop;\n _sortDirectionValue = direction;\n\n // Create sorted list.\n List<T> _sortedList = new List<T>(this); \n _sortedList.Sort(comparison);\n\n // Reverse order if needed.\n if (direction == ListSortDirection.Descending)\n {\n _sortedList.Reverse();\n }\n\n // Update list.\n int count = this.Count;\n for (int i = 0; i < count; i++)\n {\n this[i] = _sortedList[i];\n }\n\n // Raise the ListChanged event so bound controls refresh their\n // values.\n OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1));\n }\n }\n\n // Method below was in the original implementation from MS. Don't know what it's for.\n // -- Martijn Boeker, Jan 21, 2010\n\n //protected override void RemoveSortCore()\n //{\n // //int position;\n // //object temp;\n // //// Ensure the list has been sorted.\n // //if (unsortedItems != null)\n // //{\n // // // Loop through the unsorted items and reorder the\n // // // list per the unsorted list.\n // // for (int i = 0; i < unsortedItems.Count; )\n // // {\n // // position = this.Find(SortPropertyCore.Name,\n // // unsortedItems[i].GetType().\n // // GetProperty(SortPropertyCore.Name).\n // // GetValue(unsortedItems[i], null));\n // // if (position >= 0 && position != i)\n // // {\n // // temp = this[i];\n // // this[i] = this[position];\n // // this[position] = (T)temp;\n // // i++;\n // // }\n // // else if (position == i)\n // // i++;\n // // else\n // // // If an item in the unsorted list no longer exists, delete it.\n // // unsortedItems.RemoveAt(i);\n // // }\n // // OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1));\n // //}\n //}\n\n /// <summary>\n /// Ability to search an item.\n /// </summary>\n protected override bool SupportsSearchingCore\n {\n get\n {\n return true;\n }\n }\n\n /// <summary>\n /// Finds an item in the list.\n /// </summary>\n /// <param name=\"prop\"></param>\n /// <param name=\"key\"></param>\n /// <returns></returns>\n protected override int FindCore(PropertyDescriptor prop, object key)\n {\n // Implementation not changed from MS example code.\n\n // Get the property info for the specified property.\n PropertyInfo propInfo = typeof(T).GetProperty(prop.Name);\n T item;\n\n if (key != null)\n {\n // Loop through the the items to see if the key\n // value matches the property value.\n for (int i = 0; i < Count; ++i)\n {\n item = (T)Items[i];\n if (propInfo.GetValue(item, null).Equals(key))\n return i;\n }\n }\n return -1;\n }\n\n /// <summary>\n /// Finds an item in the list.\n /// </summary>\n /// <param name=\"prop\"></param>\n /// <param name=\"key\"></param>\n /// <returns></returns>\n private int Find(string property, object key)\n {\n // Implementation not changed from MS example code.\n\n // Check the properties for a property with the specified name.\n PropertyDescriptorCollection properties =\n TypeDescriptor.GetProperties(typeof(T));\n PropertyDescriptor prop = properties.Find(property, true);\n\n // If there is not a match, return -1 otherwise pass search to\n // FindCore method.\n if (prop == null)\n return -1;\n else\n return FindCore(prop, key);\n }\n\n #endregion\n }\n}\n" }, { "answer_id": 2136930, "author": "CXRom", "author_id": 258917, "author_profile": "https://Stackoverflow.com/users/258917", "pm_score": 0, "selected": false, "text": "if (!_customComparisons.TryGetValue(prop.Name, out comparison))\n{\n // Check to see if the property type we are sorting by implements\n // the IComparable interface.\n Type interfaceType = prop.PropertyType.GetInterface(\"IComparable\");\n if (interfaceType != null)\n {\n comparison = delegate(T t1, T t2)\n {\n IComparable val1 = (IComparable)prop.GetValue(t1) ?? \"\";\n IComparable val2 = (IComparable)prop.GetValue(t2) ?? \"\";\n return val1.CompareTo(val2);\n };\n }\n else\n {\n // Last option: convert to string and compare.\n comparison = delegate(T t1, T t2)\n {\n string val1 = (prop.GetValue(t1) ?? \"\").ToString();\n string val2 = (prop.GetValue(t2) ?? \"\").ToString();\n return val1.CompareTo(val2);\n };\n }\n}\n" }, { "answer_id": 2137687, "author": "Joe H", "author_id": 95659, "author_profile": "https://Stackoverflow.com/users/95659", "pm_score": 1, "selected": false, "text": "jobs = new List<DisplayJob>();\n jobs = new SortableBindingList<DisplayJob>();\n itemsList.Sort(delegate(T t1, T t2)\n{\n object value1 = prop.GetValue(t1);\n object value2 = prop.GetValue(t2);\n\n return reverse * Comparer.Default.Compare(value1, value2);\n});\n int j;\nT index;\nfor (int i = 0; i < itemsList.Count; i++)\n{\n index = itemsList[i];\n j = i;\n\n while ((j > 0) && (reverse * Comparer.Default.Compare(prop.GetValue(itemsList[j - 1]), prop.GetValue(index)) > 0))\n {\n itemsList[j] = itemsList[j - 1];\n j = j - 1;\n }\n\n itemsList[j] = index;\n}\n" }, { "answer_id": 5662644, "author": "grabah", "author_id": 437931, "author_profile": "https://Stackoverflow.com/users/437931", "pm_score": 0, "selected": false, "text": "uxJobList.Columns[newColumn].SortMemberPath=\"Id\";" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280948", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18349/" ]
280,953
<p>Could anyboby help me with the alternative solution in C# regarding <strong>AddressOf operator in VB6</strong>? AddressOf returns a long value. What way can I get the output in C#?</p>
[ { "answer_id": 280959, "author": "Joel Coehoorn", "author_id": 3043, "author_profile": "https://Stackoverflow.com/users/3043", "pm_score": 3, "selected": false, "text": "<delegate> += <function>;" }, { "answer_id": 280967, "author": "TcKs", "author_id": 20382, "author_profile": "https://Stackoverflow.com/users/20382", "pm_score": 0, "selected": false, "text": "EventHandler handler1 = this.button1_Click;\nEventHandler handler2 = new EventHandler( this.button1_Click );\n...\n...\n...\nvoid button1_Click( object sender, EventArgs e ){\n // ....\n}\n" }, { "answer_id": 281106, "author": "John Rudy", "author_id": 14048, "author_profile": "https://Stackoverflow.com/users/14048", "pm_score": 4, "selected": false, "text": "int number;\nint* p = &number;\nConsole.WriteLine(\"Value pointed to by p: {0}\", p->ToString());\n number p fixed int* p = &GetSomeInt();" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280953", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
280,969
<p>I need to grab the folder name of a currently executing batch file. I have been trying to loop over the current directory using the following syntax (which is wrong at present):</p> <pre><code>set mydir = %~p0 for /F "delims=\" %i IN (%mydir%) DO @echo %i </code></pre> <p>Couple of issues in that I cannot seem to pass the 'mydir' variable value in as the search string. It only seems to work if I pass in commands; I have the syntax wrong and cannot work out why.</p> <p>My thinking was to loop over the folder string with a '\' delimiter but this is causing problems too. If I set a variable on each loop then the last value set will be the current folder name. For example, given the following path:</p> <blockquote> <p>C:\Folder1\Folder2\Folder3\Archive.bat</p> </blockquote> <p>I would expect to parse out the value 'Folder3'.</p> <p>I need to parse that value out as its name will be part of another folder I am going to create further down in the batch file.</p> <p>Many thanks if anyone can help. I may be barking up the wrong tree completely so any other approaches would be greatly received also.</p>
[ { "answer_id": 281073, "author": "Patrick Cuff", "author_id": 7903, "author_profile": "https://Stackoverflow.com/users/7903", "pm_score": 4, "selected": true, "text": "@echo OFF\nset mydir=\"%~p0\"\nSET mydir=%mydir:\\=;%\n\nfor /F \"tokens=* delims=;\" %%i IN (%mydir%) DO call :LAST_FOLDER %%i\ngoto :EOF\n\n:LAST_FOLDER\nif \"%1\"==\"\" (\n @echo %LAST%\n goto :EOF\n)\n\nset LAST=%1\nSHIFT\n\ngoto :LAST_FOLDER\n SET mydir=%mydir:\\=;%" }, { "answer_id": 281130, "author": "Tim Peel", "author_id": 31412, "author_profile": "https://Stackoverflow.com/users/31412", "pm_score": 0, "selected": false, "text": "@echo off\nfor /f \"tokens=1-10 delims=\\\" %%A in ('echo %~p0') do (\n if NOT .%%A==. set new=%%A\n if NOT .%%B==. set new=%%B\n if NOT .%%C==. set new=%%C\n if NOT .%%D==. set new=%%D\n if NOT .%%E==. set new=%%E\n if NOT .%%F==. set new=%%F\n if NOT .%%G==. set new=%%G\n if NOT .%%H==. set new=%%H\n if NOT .%%I==. set new=%%I\n if NOT .%%J==. set new=%%J\n)\n\n@echo %new%\n" }, { "answer_id": 281284, "author": "Tim Peel", "author_id": 31412, "author_profile": "https://Stackoverflow.com/users/31412", "pm_score": 1, "selected": false, "text": "set mydir=\"%~p0\"\nset mydir=%mydir:\\=;%\nset mydir=%mydir: =:%\n\nfor /F \"tokens=* delims=;\" %%i IN (%mydir%) DO call :LAST_FOLDER %%i\ngoto :EOF\n\n:LAST_FOLDER\nif \"%1\"==\"\" (\n set LAST=%LAST::= %\n goto :EOF\n)\n\nset LAST=%1\nSHIFT\n\ngoto :LAST_FOLDER\n" }, { "answer_id": 3025534, "author": "ahains", "author_id": 98722, "author_profile": "https://Stackoverflow.com/users/98722", "pm_score": 0, "selected": false, "text": "@echo off\nif \"%1\"==\"\" goto :USAGE\n\nset FULLPATH=%~f1\nset STOPDIR=%2\nset PATHROOT=\n\n:: Replace backslashes with semicolons\nset FULLPATH=%FULLPATH:\\=;%\n\n:: Iterate through path (the semicolons cause each dir name to be a new argument)\ncall :LOOP %FULLPATH%\ngoto :EOF\n\n:LOOP\n\n::Exit loop if reached the end of the path, or the stop dir\nif \"%1\"==\"\" (goto :EOF)\nif \"%1\"==\"%STOPDIR%\" (goto :EOF)\n\n::If this is the first segment of the path, set value directly. Else append.\nif not defined PATHROOT (set PATHROOT=%1) else (set PATHROOT=%PATHROOT%\\%1)\n\n::shift the arguments - the next path segment becomes %i\nSHIFT\n\ngoto :LOOP\n\n:USAGE\necho Usage:\necho %~0 ^<full path to parse^> ^<dir name to stop at^>\necho E.g. for a command:\necho %~0 c:\\root1\\child1\\child2 child2\necho The value of c:\\root1\\child1 would be assigned to env variable PATHROOT\n" }, { "answer_id": 3176320, "author": "John Dove", "author_id": 383261, "author_profile": "https://Stackoverflow.com/users/383261", "pm_score": 2, "selected": false, "text": "@echo off\nset pathtofind=%~dp0\nif not exist %pathtofind% echo Path does not exist&pause>nul&goto :eof\n\ncd /d %pathtofind%\nset path1=%cd%\ncd ..\nset path2=%cd%\n\ncall set \"path3=%%path1:%path2%\\=%%\"\n\necho %path3%\n\npause>nul\n" }, { "answer_id": 3544114, "author": "jeth", "author_id": 427944, "author_profile": "https://Stackoverflow.com/users/427944", "pm_score": -1, "selected": false, "text": "@echo off\nset pathtofind=%~dp0\nif not exist %pathtofind% echo Path does not exist&pause>nul&goto :eof\n\ncd /d %pathtofind%\nset path1=%cd%\ncd ..\nset path2=%cd%\nset path4=%~dp1\ncall set \"path3=%%path1:%path2%\\=%%\"\ncall set \"path5=%%path3:%path4%*\\=%%\"\necho %path5%\n\npause>nul\n" }, { "answer_id": 3962928, "author": "auvixa", "author_id": 479739, "author_profile": "https://Stackoverflow.com/users/479739", "pm_score": 1, "selected": false, "text": "@echo off&setlocal enableextensions,enabledelayedexpansion\n\ncall :l_truncpath \"C:\\Windows\\temp\"\n\n----------\n\n:l_truncpath\nset \"_pathtail=%~1\"\n:l_truncpathloop\nfor /f \"delims=\\ tokens=1*\" %%x in (\"!_pathtail!\") do (\nif \"%%y\"==\"\" (\nset \"_result=!_path!\\!_pathtail!\"\necho:!_result!\nexit/b\n)\nset \"_path=%%x\"\nset \"_pathtail=%%y\"\n)\ngoto l_truncpathloop\n" }, { "answer_id": 4587447, "author": "Jonathan", "author_id": 561648, "author_profile": "https://Stackoverflow.com/users/561648", "pm_score": 4, "selected": false, "text": "for %%a in (!FullPath!) do set LastFolder=%%~nxa\n" }, { "answer_id": 7990167, "author": "djangofan", "author_id": 118228, "author_profile": "https://Stackoverflow.com/users/118228", "pm_score": 2, "selected": false, "text": "@echo off\nSET CDIR=%~p0\nSET CDIR=%CDIR:~1,-1%\nSET CDIR=%CDIR:\\=,%\nSET CDIR=%CDIR: =#%\nFOR %%a IN (%CDIR%) DO SET \"CNAME=%%a\"\nECHO Current directory path: %CDIR%\nSET CNAME=%CNAME:#= %\nECHO Current directory name: %CNAME%\npause\n Current directory path: Documents#and#Settings,username,.sqldeveloper,tmp,my_folder,MY.again\nCurrent directory name: MY.again\nPress any key to continue . . .\n @echo off\nSET \"CDIR=%~dp0\"\n:: for loop requires removing trailing backslash from %~dp0 output\nSET \"CDIR=%CDIR:~0,-1%\"\nFOR %%i IN (\"%CDIR%\") DO SET \"PARENTFOLDERNAME=%%~nxi\"\nECHO Parent folder: %PARENTFOLDERNAME%\nECHO Full path: %~dp0\npause>nul\n" }, { "answer_id": 10536346, "author": "foo2", "author_id": 1387325, "author_profile": "https://Stackoverflow.com/users/1387325", "pm_score": 2, "selected": false, "text": "for /D %%I in (\"C:\\Folder1\\Folder2\\Folder3\\Archive.bat\\..\") do echo parentdir=%%~nxI\n" }, { "answer_id": 12566010, "author": "Paul Margetts", "author_id": 1694535, "author_profile": "https://Stackoverflow.com/users/1694535", "pm_score": 3, "selected": false, "text": "FOR /D %%I IN (\"%CD%\") DO SET _LAST_SEGMENT_=%%~nxI\nECHO Last segment = \"%_LAST_SEGMENT_%\"\n" }, { "answer_id": 58246152, "author": "Super_PDX", "author_id": 12167722, "author_profile": "https://Stackoverflow.com/users/12167722", "pm_score": 1, "selected": false, "text": "for %%a in (\"%CD%\") do set LastFolder=%%~nxa\necho %LastFolder%\n C:\\Users\\SuperPDX\\OneDrive\\Desktop Environment\\\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280969", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31412/" ]
280,971
<p>Within my InfoPath form (which has to be loaded within a SharePoint Portal by the browser)I have a repeating table containing multiple fields. Now I would like to make the first textfield autoincrement starting by 1. How exactly can I do this?</p> <p>I have already heard of a way by using the "count" function but this produces errors or in best case a static number which unfortunately does not count. The function I have added for the field is "count(.) + 1"</p> <p>Any suggestions?</p>
[ { "answer_id": 281227, "author": "Alex", "author_id": 35999, "author_profile": "https://Stackoverflow.com/users/35999", "pm_score": 2, "selected": true, "text": "count(/my:myFields/my:item)\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280971", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25428/" ]
280,990
<p>I have a snippet looking something like the below.</p> <pre><code>string bodyTypeAssemblyQualifiedName = "XXX.XX.XI.CustomerPayment.Schemas.r1.CustomerPayments_v01, XXX.XX.XI.CustomerPaym" + "ent.Schemas.r1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ac564f277cd4488" + "e"; </code></pre> <p>I'd like use regular expression in C# to get it to: </p> <pre><code>string bodyTypeAssemblyQualifiedName = null; </code></pre> <p>I've tried using a RegEx like the below but it doesn't match the newlines ...</p> <pre><code>bodyTypeAssemblyQualifiedName\s=\s(?&lt;location&gt;.*?); </code></pre>
[ { "answer_id": 281014, "author": "Tomalak", "author_id": 18771, "author_profile": "https://Stackoverflow.com/users/18771", "pm_score": 0, "selected": false, "text": "bodyTypeAssemblyQualifiedName\\s=\\s(?<location>[.\\n]*?);\n RegexOptions.Singleline" }, { "answer_id": 281183, "author": "Alan Moore", "author_id": 20938, "author_profile": "https://Stackoverflow.com/users/20938", "pm_score": 1, "selected": false, "text": "bodyTypeAssemblyQualifiedName\\s+=\\s+(?<location>[^;]+);\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280990", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
280,991
<p>I have been working on splitting up the app tier and web tier of a web application. In the app tier, I managed to separate the business logic into a bunch of services exposed using WCF proxies. The problem is that these services talk to another legacy application that uses a large CLR object as its primary means of communication. To keep things quick, I had been keeping a copy of this object in the session after I created it the first time. Now I know that WCF can do sessions, but the session storage is per service whereas my business logic is now split into multiple services (as it should be). </p> <p>Now the questions:</p> <ol> <li>Is there a way to share session storage between WCF services hosted on the same host? </li> <li>Is this even something I should be doing? </li> <li>If not, then what are the best practices here? </li> </ol> <p>This is probably not the first time somebody’s had a large business object on the server. Unfortunately for me, I really do need to cache this object per user (hence the session).</p> <p>It’s possible the answer is obvious and I'm just not seeing it. Help please!</p>
[ { "answer_id": 12067200, "author": "Niels Brinch", "author_id": 392362, "author_profile": "https://Stackoverflow.com/users/392362", "pm_score": 0, "selected": false, "text": "System.Web.Caching" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/280991", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16671/" ]
281,015
<p>Hi would like to send an email alert after checking the result of a query which will return the numbers of rows in a table. Does anyone have any ideas how I could do this in SQL Server 2000 in 2005 I would use a maintenence plan but not sure how in 2000?</p>
[ { "answer_id": 281083, "author": "Valerion", "author_id": 16156, "author_profile": "https://Stackoverflow.com/users/16156", "pm_score": 1, "selected": false, "text": "-- @From varchar(100) ,\n -- @To varchar(100) ,\n -- @Subject varchar(100)=\" \",\n --@Body varchar(4000) =\" \"\n/*********************************************************************\n\nThis stored procedure takes the parameters and sends an e-mail.\nAll the mail configurations are hard-coded in the stored procedure.\nComments are added to the stored procedure where necessary.\nReferences to the CDOSYS objects are at the following MSDN Web site:\nhttp://msdn.microsoft.com/library/default.asp?url=/library/en-us/cdosys/html/_cdosys_messaging.asp\n\n***********************************************************************/\n AS\n Declare @From varchar(100) --origninally passed as parameter above. We want to hard-code it.\n Declare @To varchar(100) --origninally passed as parameter above. We want to hard-code it.\n Declare @Subject varchar(100) --origninally passed as parameter above. We want to hard-code it.\n Declare @Body varchar(4000) --origninally passed as parameter above. We want to hard-code it.\n Declare @iMsg int\n Declare @hr int\n Declare @source varchar(255)\n Declare @description varchar(500)\n Declare @output varchar(1000)\n Set @From = 'abc@xyz.com'\n Set @To = 'xyz@abc.com'\n Set @Subject = 'Whatever Subject You Want'\n Set @Body = 'Some useful text'\n\n\n--************* Create the CDO.Message Object ************************\n EXEC @hr = sp_OACreate 'CDO.Message', @iMsg OUT\n IF @hr <>0 BEGIN\nprint 'sp_OACreate failed'\n END\n\n--***************Configuring the Message Object ******************\n-- This is to configure a remote SMTP server.\n-- http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cdosys/html/_cdosys_schema_configuration_sendusing.asp\n EXEC @hr = sp_OASetProperty @iMsg, 'Configuration.fields(\"http://schemas.microsoft.com/cdo/configuration/sendusing\").Value','2'\n-- This is to configure the Server Name or IP address.\n-- Replace MailServerName by the name or IP of your SMTP Server.\n EXEC @hr = sp_OASetProperty @iMsg, 'Configuration.fields(\"http://schemas.microsoft.com/cdo/configuration/smtpserver\").Value', 'mail.xxxxxxxxxx.com'\n-- Save the configurations to the message object.\n EXEC @hr = sp_OAMethod @iMsg, 'Configuration.Fields.Update', null\n-- Set the e-mail parameters.\n EXEC @hr = sp_OASetProperty @iMsg, 'To', @To\n EXEC @hr = sp_OASetProperty @iMsg, 'From', @From\n EXEC @hr = sp_OASetProperty @iMsg, 'Subject', @Subject\n-- If you are using HTML e-mail, use 'HTMLBody' instead of 'TextBody'.\n EXEC @hr = sp_OASetProperty @iMsg, 'TextBody', @Body\n EXEC @hr = sp_OAMethod @iMsg, 'Send', NULL\n IF @hr <>0\n BEGIN\n EXEC @hr = sp_OAGetErrorInfo NULL, @source OUT, @description OUT\n IF @hr = 0\n BEGIN\n SELECT @output = ' Source: ' + @source\n PRINT @output\n SELECT @output = ' Description: ' + @description\n PRINT @output\n END\n\n END\n\n-- Do some error handling after each step if you have to.\n-- Clean up the objects created.\n send_cdosysmail_cleanup:\nIf (@iMsg IS NOT NULL) -- if @iMsg is NOT NULL then destroy it\nBEGIN\n EXEC @hr=sp_OADestroy @iMsg\n\nEND\nELSE\nBEGIN\n PRINT ' sp_OADestroy skipped because @iMsg is NULL.'\n\n RETURN\nEND\n" }, { "answer_id": 297457, "author": "beach", "author_id": 53892, "author_profile": "https://Stackoverflow.com/users/53892", "pm_score": 0, "selected": false, "text": "xp_smtp_sendmail\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/281015", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
281,017
<p>(Warning - asp newbie) I have an aspx file with the tag</p> <pre><code> &lt;%@ Page Language=VB ... %&gt; </code></pre> <p>right at the beginning of the file.</p> <p>When calling this from my IIS server (<a href="http://localhost/myservice/default.aspx" rel="noreferrer">http://localhost/myservice/default.aspx</a>), this gives me the error </p> <blockquote> <p>This page contains the following errors: </p> <p>error on line 1 at column 2: StartTag: invalid element name<br> Below is a rendering of the page up to the first error.</p> </blockquote> <p>What am I doing wrong?</p>
[ { "answer_id": 65036058, "author": "Victor Muñoz", "author_id": 8325863, "author_profile": "https://Stackoverflow.com/users/8325863", "pm_score": 0, "selected": false, "text": " - < tag > text < / tag > ---> wrong\n\n - <tag> text </tag> ----> good.\n\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/281017", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6583/" ]
281,020
<p>I want to call some RESTful web services from a J2ME client running on a MIDP enabled mobile device. I read the MIDP api for HTTPConnections and thought this is just crying out for a simple wrapper to hide all those unpleasant byte arrays and such like. Before I write my own I wondered whether there was a good open source library already available.</p> <p>-FE- </p>
[ { "answer_id": 287057, "author": "darius", "author_id": 5896, "author_profile": "https://Stackoverflow.com/users/5896", "pm_score": 4, "selected": true, "text": "* Asynchronous versions of HTTP Get and Post\n* HTTP Basic Authentication\n* Multipart MIME (sender only)\n* Progress listeners\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/281020", "https://Stackoverflow.com", "https://Stackoverflow.com/users/32747/" ]
281,034
<p>Under visual studio if you run a web project by pressing the <kbd>Go</kbd> button on the Debugging toolbar, then stop it by pressing the <kbd>Stop</kbd> button on the debugging toolbar, Internet Explorer is opened and closed by the IDE.</p> <p>Is there a way to prevent the IDE from closing Internet Explorer when stopping debugging? I want to do this to allow myself to refer to the content of the pages in IE while editing my code.</p>
[ { "answer_id": 281063, "author": "Bruno Shine", "author_id": 28294, "author_profile": "https://Stackoverflow.com/users/28294", "pm_score": 4, "selected": true, "text": "Detach All Debug" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/281034", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36591/" ]
281,036
<p>Are "out" parameters a bad thing in .NET? Any good articles/discussions on this topic?</p>
[ { "answer_id": 281049, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 7, "selected": true, "text": "out" }, { "answer_id": 281077, "author": "Simon", "author_id": 15371, "author_profile": "https://Stackoverflow.com/users/15371", "pm_score": -1, "selected": false, "text": "void doSomeThing(Thing toDoItTo,\n out OtherThing result1,\n out AnotherThing result2)\n{\n ...\n}\n\nOtherThing y;\nAnotherThing z;\n\ndoSomeThing(x, out y, out z);\n\ny.method1();\nz.method2();\n struct DoSomeThingResults\n{\n public OtherThing Result1;\n public OtherThing Result2;\n}\n\nDoSomeThingResults doSomeThing(Thing toDoItTo)\n{\n ...\n}\n\nDoSomethingResults results = doSomeThing(x);\n\nresults.Result1.method1();\nresults.Result2.method2();\n" }, { "answer_id": 281078, "author": "MrKurt", "author_id": 35296, "author_profile": "https://Stackoverflow.com/users/35296", "pm_score": 2, "selected": false, "text": "out TryParse let success, value = Int32.TryParse(\"1234\")\n(* success is true *)\n(* value is 1234 *)\n" }, { "answer_id": 37364885, "author": "Eidivandi", "author_id": 6365123, "author_profile": "https://Stackoverflow.com/users/6365123", "pm_score": -1, "selected": false, "text": " using ref force us to initialize it so we are letting the ref variable to place in heap and consume some spaces .\n\n in most cases we return null if the operation has some none logic conditions \n\n but with Out we avoid consuming the heap and refspace\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/281036", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36590/" ]
281,041
<p>I am not that hot at regular expressions and it has made my little mind melt some what.</p> <p>I am trying to find all the tables names in a query. So say I have the query:</p> <pre><code>SELECT one, two, three FROM table1, table2 WHERE X=Y </code></pre> <p>I would like to pull out "table1, table2" or "table1" and "table2"</p> <p>But what if there is no where statement. It could be the end of the file, or there could be a group by or an order by etc. I know "most" of the time this will not be an issue but I don't like the idea of coding for "most" situations and knowing I have left a hole that could cause things to go wrong later.</p> <p>Is this a doable Regex expression? Am I being a Regex pleb?</p> <p>(P.S. this will be done in C# but presume that doesn't matter much).</p>
[ { "answer_id": 281053, "author": "LeppyR64", "author_id": 16592, "author_profile": "https://Stackoverflow.com/users/16592", "pm_score": 1, "selected": false, "text": "select\n *\nfrom\n A\n join (\n select\n top 5 *\n from\n B)\n on B.ID = A.ID\nwhere\n A.ID in (\n select\n ID\n from\n C\n where C.DOB = A.DOB)\n" }, { "answer_id": 281057, "author": "Bill the Lizard", "author_id": 1288, "author_profile": "https://Stackoverflow.com/users/1288", "pm_score": 1, "selected": false, "text": "FROM WHERE GROUP BY HAVING" }, { "answer_id": 281098, "author": "Stefan Gehrig", "author_id": 11354, "author_profile": "https://Stackoverflow.com/users/11354", "pm_score": 3, "selected": false, "text": "FROM\\s+([^ ,]+)(?:\\s*,\\s*([^ ,]+))*\\s+ \n" }, { "answer_id": 2253513, "author": "MrEdmundo", "author_id": 52026, "author_profile": "https://Stackoverflow.com/users/52026", "pm_score": 2, "selected": false, "text": "\\bjoin\\s+(?<Retrieve>[a-zA-Z\\._\\d]+)\\b|\\bfrom\\s+(?<Retrieve>[a-zA-Z\\._\\d]+)\\b|\\bupdate\\s+(?<Update>[a-zA-Z\\._\\d]+)\\b|\\binsert\\s+(?:\\binto\\b)?\\s+(?<Insert>[a-zA-Z\\._\\d]+)\\b|\\btruncate\\s+table\\s+(?<Delete>[a-zA-Z\\._\\d]+)\\b|\\bdelete\\s+(?:\\bfrom\\b)?\\s+(?<Delete>[a-zA-Z\\._\\d]+)\\b\n" }, { "answer_id": 3780365, "author": "Psymon25", "author_id": 456396, "author_profile": "https://Stackoverflow.com/users/456396", "pm_score": 0, "selected": false, "text": "(?<=(INTO)\\s)[^\\s]*(?=\\(())\n (?<=(from|join)\\s)[^\\s]*(?=\\s(on|join|where))\n (?i)(?<=VALUES[ ]*\\().*(?=\\))\n" }, { "answer_id": 6221794, "author": "Mauro", "author_id": 678455, "author_profile": "https://Stackoverflow.com/users/678455", "pm_score": 0, "selected": false, "text": "function getQueryTable ($query) {\n require_once \"SQL/Parser.php\";\n $parser = new SQL_Parser();\n $parser->setDialect('MySQL');\n\n // Stripping fields section\n $queryType = substr(strtoupper($query),0,6); \n if($queryType == 'SELECT') { $query = \"SELECT * \".stristr($query, \"FROM\"); }\n if ($havingPos = stripos($query, 'HAVING')) { $query = substr($query, 0, $havingPos); }\n\n\n $struct = $parser->parse($query);\n\n $tableReferences = $struct[0]['from']['table_references']['table_factors'];\n\n foreach ((Array) $tableReferences as $ref) {\n $tables[] = ($ref['database'] ? $ref['database'].'.' : $ref['database']).$ref['table'];\n }\n\n return $tables;\n\n}\n" }, { "answer_id": 7909505, "author": "itsjavi", "author_id": 1015501, "author_profile": "https://Stackoverflow.com/users/1015501", "pm_score": 0, "selected": false, "text": "function sql_query_get_tables($statement){\n preg_match_all(\"/(from|into|update|join) [\\\\'\\\\´]?([a-zA-Z0-9_-]+)[\\\\'\\\\´]?/i\",\n $statement, $matches);\n if(!empty($matches)){\n return array_unique($matches[2]);\n }else return array();\n}\n" }, { "answer_id": 10885156, "author": "Will", "author_id": 487176, "author_profile": "https://Stackoverflow.com/users/487176", "pm_score": 2, "selected": false, "text": "SELECT tbltable1.one, tbltable1.two, tbltable2.three\nFROM tbltable1\n INNER JOIN tbltable2\n ON tbltable1.one = tbltable2.three\n (\"SELECT\",\"tbltable1.one,\",\"tbltable1.two,\",\"tbltable2.three\",\"FROM\",\"tbltable1\",\"INNER\",\"JOIN\",\"tbltable2\",\"ON\",\"tbltable1.one\",\"=\",\"tbltable2.three\") (\"SELECT\",\"tbltable1\",\"tbltable1\",\"tbltable2\",\"FROM\",\"tbltable1\",\"INNER\",\"JOIN\",\"tbltable2\",\"ON\",\"tbltable1\",\"=\",\"tbltable2\") (\"SELECT\",\"tbltable1\",\"tbltable1\",\"tbltable2\",\"FROM\",\"tbltable1\",\"INNER\",\"JOIN\",\"tbltable2\",\"ON\",\"tbltable1\",\"tbltable2\") (\"SELECT\",\"tbltable1\",\"tbltable2\",\"FROM\",\"INNER\",\"JOIN\",\"ON\") \"tbl\" (\"tbltable1\",\"tbltable2\")" }, { "answer_id": 34907041, "author": "user3398001", "author_id": 3398001, "author_profile": "https://Stackoverflow.com/users/3398001", "pm_score": 0, "selected": false, "text": "select from a , b , c SQL Sub get_tables()\n sql_query = Cells(5, 1).Value\n tables = \"\"\n\n 'get all tables after from\n sql_from = sql_query\n\n While InStr(1, UCase(sql_from), UCase(\"from\")) > 0\n\n i = InStr(1, UCase(sql_from), UCase(\"from\"))\n sql_from = Mid(sql_from, i + 5, Len(sql_from) - i - 5)\n i = InStr(1, UCase(sql_from), UCase(\" \"))\n\n While i = 1\n\n sql_from = Mid(sql_from, 2, Len(sql_from) - 1)\n i = InStr(1, UCase(sql_from), UCase(\" \"))\n\n end\n\n i = InStr(1, sql_join, Chr(9))\n\n While i = 1\n\n sql_join = Mid(sql_join, 2, Len(sql_join) - 1)\n i = InStr(1, sql_join, Chr(9))\n\n end\n\n a = InStr(1, UCase(sql_from), UCase(\" \"))\n b = InStr(1, sql_from, Chr(10))\n c = InStr(1, sql_from, Chr(13))\n d = InStr(1, sql_from, Chr(9))\n\n MinC = a\n\n If MinC > b And b > 0 Then MinC = b\n If MinC > c And c > 0 Then MinC = c\n If MinC > d And d > 0 Then MinC = d\n\n tables = tables + \"[\" + Mid(sql_from, 1, MinC - 1) + \"]\"\n\n end\n\n 'get all tables after join\n sql_join = sql_query\n\n While InStr(1, UCase(sql_join), UCase(\"join\")) > 0\n\n i = InStr(1, UCase(sql_join), UCase(\"join\"))\n sql_join = Mid(sql_join, i + 5, Len(sql_join) - i - 5)\n i = InStr(1, UCase(sql_join), UCase(\" \"))\n\n While i = 1\n\n sql_join = Mid(sql_join, 2, Len(sql_join) - 1)\n i = InStr(1, UCase(sql_join), UCase(\" \"))\n\n end\n\n i = InStr(1, sql_join, Chr(9))\n\n While i = 1\n\n sql_join = Mid(sql_join, 2, Len(sql_join) - 1)\n i = InStr(1, sql_join, Chr(9))\n\n end\n\n a = InStr(1, UCase(sql_join), UCase(\" \"))\n b = InStr(1, sql_join, Chr(10))\n c = InStr(1, sql_join, Chr(13))\n d = InStr(1, sql_join, Chr(9))\n\n MinC = a\n\n If MinC > b And b > 0 Then MinC = b\n If MinC > c And c > 0 Then MinC = c\n If MinC > d And d > 0 Then MinC = d\n\n tables = tables + \"[\" + Mid(sql_join, 1, MinC - 1) + \"]\"\n\n end\n\n tables = Replace(tables, \")\", \"\")\n tables = Replace(tables, \"(\", \"\")\n tables = Replace(tables, \" \", \"\")\n tables = Replace(tables, Chr(10), \"\")\n tables = Replace(tables, Chr(13), \"\")\n tables = Replace(tables, Chr(9), \"\")\n tables = Replace(tables, \"[]\", \"\")\n\nEnd Sub\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/281041", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6486/" ]
281,045
<p>This is a question that was sparked by <a href="https://stackoverflow.com/users/3631/rob-walker">Rob Walker</a>'s answer <a href="https://stackoverflow.com/questions/36455/alignment-restrictions-for-mallocfree#36466">here</a>.</p> <p>Suppose I declare a class/struct like so:</p> <pre><code>struct { char A; int B; char C; int D; }; </code></pre> <p>Is it safe to assume that these members will be declared in exactly that order in memory, or is this a compiler dependent thing? I'm asking because I had always assumed that the compiler can do whatever it wants with them.</p> <p>This leads into my next question. If the above example causes memory alignment issues, why can the compiler not just turn that into something like this implicitly:</p> <pre><code>struct { char A; char C; int B; int D; }; </code></pre> <p>(I'm primarily asking about C++, but I'd be interested to hear the C answer as well)</p> <h3>Related topics</h3> <ul> <li><a href="https://stackoverflow.com/questions/118068/why-doesnt-gcc-optimize-structs">Why doesn't GCC optimize structs?</a></li> </ul>
[ { "answer_id": 281154, "author": "Jason Baker", "author_id": 2147, "author_profile": "https://Stackoverflow.com/users/2147", "pm_score": 0, "selected": false, "text": "struct foo{};\n extern \"C\" foo;\nstruct bar: public foo{};\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/281045", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2147/" ]
281,095
<p>I would like to retrieve at runtime the values for the "dialect" and "connection.driver_class" properties specified in the configuration file.</p> <p>Do you know how to do that?</p> <p>Many thanks, Nicola</p>
[ { "answer_id": 289528, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 4, "selected": false, "text": " public static Dialect GetDialect(ISession session)\n {\n Dialect dialect = session.GetSessionImplementation().Factory.Dialect;\n return dialect;\n }\n public static Dialect GetDialect(ISessionFactory sessionFactory)\n {\n var implementor = sessionFactory as ISessionFactoryImplementor;\n Dialect dialect = implementor.Dialect;\n return dialect;\n }\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/281095", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
281,101
<p>When building a application that accesses a MySQL database on linux using C/C++ i have to dynamically link into the mysql client library. Is there a way in which i can statically link the application so that the mysql client libraries are no longer required?</p> <p>What is the best practice, with regards to C\C++ development, to include rather long queries in the application but outside the code? Using stored procedures an not possible as the database runs on a MySQL 4 server.</p>
[ { "answer_id": 294919, "author": "AndrewR", "author_id": 2994, "author_profile": "https://Stackoverflow.com/users/2994", "pm_score": 0, "selected": false, "text": "gcc -I/usr/include/mysql -c mysql.c\ngcc -o mysql mysql.o -static -lmysqlclient -static-libgcc -lm -lz -lpthread\n /usr/lib/gcc/i486-linux-gnu/4.2.4/../../../../lib/libmysqlclient.a(mf_pack.o): In function `unpack_dirname':\n(.text+0x6cc): warning: Using 'getpwnam' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking\n/usr/lib/gcc/i486-linux-gnu/4.2.4/../../../../lib/libmysqlclient.a(libmysql.o): In function `read_user_name':\n(.text+0x5ed7): warning: Using 'getpwuid' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking\n/usr/lib/gcc/i486-linux-gnu/4.2.4/../../../../lib/libmysqlclient.a(mf_pack.o): In function `unpack_dirname':\n(.text+0x6e1): warning: Using 'endpwent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking\n/usr/lib/gcc/i486-linux-gnu/4.2.4/../../../../lib/libmysqlclient.a(my_gethostbyname.o): In function `my_gethostbyname_r':\n(.text+0x3c): warning: Using 'gethostbyname_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking\n/usr/lib/gcc/i486-linux-gnu/4.2.4/../../../../lib/libmysqlclient.a(libmysql.o): In function `mysql_server_init':\n(.text+0x695d): warning: Using 'getservbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/281101", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7362/" ]
281,108
<p>I have a compiled AppleScript application which I have moved to my windows server. I'd like to then insert a text file into the application (which looks like a zip file on windows):</p> <pre><code>myapplescript.app/Contents/Resources/MyNewDir/MyTxtFile.txt </code></pre> <p>So, I've precompiled the AppleScript to try to read from this text file and get the contents as a string. This is what I do:</p> <pre><code>set theFolder to POSIX path of (the path to me) set theFile to theFolder &amp; "Contents/Resources/MyNewDir/MyTxtFile.txt" open for access theFile set fileContents to (read theFile) close access theFile </code></pre> <p>but this is the error I get:</p> <blockquote> <p>Can't make "/Users/mike/Desktop/myapplescript.app/Contents/Resources/MyNewDir/MyTxtFile.txt" into type file</p> </blockquote>
[ { "answer_id": 284311, "author": "Mike Blandford", "author_id": 28643, "author_profile": "https://Stackoverflow.com/users/28643", "pm_score": 3, "selected": true, "text": "set theFile to (POSIX file (theFolder & \"Contents/Resources/MyNewDir/MyTxtFile.txt\"))\n" }, { "answer_id": 15752803, "author": "Lri", "author_id": 495470, "author_profile": "https://Stackoverflow.com/users/495470", "pm_score": 1, "selected": false, "text": "read POSIX file \"/tmp/test.txt\" as «class utf8»\n as «class utf8» as Unicode text" }, { "answer_id": 40123670, "author": "Stephen W. Wright", "author_id": 3143126, "author_profile": "https://Stackoverflow.com/users/3143126", "pm_score": 0, "selected": false, "text": "set fRef to \"Macintosh HD:Users:sww:Devel:afile.csv\"\n\nset myData to read file fRef -- No good\n set myData to read file (fRef as string) -- OK\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/281108", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28643/" ]
281,111
<p>How do I replace text from one file with text from another file using vbscript?</p> <p>The text being replaced is somewhere in the middle of the file. </p>
[ { "answer_id": 281138, "author": "Svante Svenson", "author_id": 19707, "author_profile": "https://Stackoverflow.com/users/19707", "pm_score": 2, "selected": false, "text": "Dim oFSO\nDim sFileAContents\nDim sFileBContents\nDim sFileCContents\nDim sResult\nSet oFSO = CreateObject(\"Scripting.FileSystemObject\")\nsFileAContents = oFSO.OpenTextFile(\"c:\\filea.txt\").ReadAll()\nsFileBContents = oFSO.OpenTextFile(\"c:\\fileb.txt\").ReadAll()\nsFileCContents = oFSO.OpenTextFile(\"c:\\filec.txt\").ReadAll()\nsResult = Replace(sFileAContents, sFileBContents, \"\")\n" }, { "answer_id": 11679819, "author": "Kevin Fegan", "author_id": 606539, "author_profile": "https://Stackoverflow.com/users/606539", "pm_score": 0, "selected": false, "text": "Dim objFSO\nDim strFileToSearch\nDim strFileReplaceText\n\nDim strTextToFind\nDim strTextToSearch\nDim strTextReplaceText\nDim strFinalText\n\n strFileToSearch = \"C:\\FileToSearch.txt\"\n strFileReplaceText = \"C:\\FileReplaceText.txt\"\n\n strTextToFind = \"text to search for here\"\n\n Set objFSO = CreateObject(\"Scripting.FileSystemObject\") \n strTextToSearch = objFSO.OpenTextFile(strFileToSearch).ReadAll() \n strFileReplaceText = objFSO.OpenTextFile(strFileReplaceText).ReadAll() \n\n strFinalText = Replace(strTextToSearch, strTextToFind, strFileReplaceText) \n Const ForWriting = 2\nDim strFileFinalOutput\n\n strFileFinalOutput = \"C:\\FileFinalOutput.txt\"\n\n Set objTextFile = objFSO.OpenTextFile(strFileFinalOutput, ForWriting, True)\n objTextFile.Write strFinalText\n objTextFile.Close\n Set objTextFile = Nothing\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/281111", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
281,119
<p>Has anyone written a version of .Net's generic Queue that implements INotifyCollectionChanged, or is there one hidden deep in the .Net framework somewhere already?</p>
[ { "answer_id": 281148, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": true, "text": "// this isn't the best code ever; refactor as desired\nprotected void OnCollectionChanged( NotifyCollectionChangedEventArgs ccea){\n var temp = CollectionChanged;\n if(temp != null) temp(this, ccea); \n}\n\n// and later in the class\n\npublic override SomeMethodThatAltersTheQueue(object something){\n // record state of collection prior to change\n base.SomeMethodThatAltersTheQueue(something)\n // create NotifyCollectionChangedEventArgs with prior state and new state\n OnCollectionChanged(ccea);\n}\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/281119", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5548/" ]
281,121
<p>The default generated hashCode and equals implementations are ugly at best.</p> <p>Is it possible to make eclipse generate ones from HashCodeBuilder and EqualsBuilder, and perhaps even a toString with ToStringBuilder?</p>
[ { "answer_id": 281179, "author": "bruno conde", "author_id": 31136, "author_profile": "https://Stackoverflow.com/users/31136", "pm_score": 2, "selected": false, "text": " public boolean equals(Object o) {\n boolean result = false;\n\n if (this == o) {\n result = true;\n } else if (o instanceof $CLASSNAME$) {\n $CLASSNAME$ other = ($CLASSNAME$) o;\n\n result = new org.apache.commons.lang.builder.EqualsBuilder()\n .append($END$\n .isEquals();\n }\n\n return result;\n }\n public int hashCode() {\n return new org.apache.commons.lang.builder.HashCodeBuilder()\n .append( $END$ )\n .toHashCode();\n }\n" }, { "answer_id": 2514431, "author": "Jens Geiregat", "author_id": 223055, "author_profile": "https://Stackoverflow.com/users/223055", "pm_score": -1, "selected": false, "text": "@Override\npublic boolean equals(Object obj) {\n if (obj == null) {\n return false;\n } else if (obj == this) {\n return true;\n } else if (obj.getClass() != this.getClass()) {\n return false;\n }\n\n ${enclosing_type} other = (${enclosing_type}) obj;\n return new EqualsBuilder()//\n .appendSuper(super.equals(other))//\n .append(${cursor})//\n .isEquals();\n}\n @Override\npublic int hashCode() {\n return new HashCodeBuilder(${cursor})//\n .append()//\n .toHashCode();\n}\n" }, { "answer_id": 6975502, "author": "Andrei Zagorneanu", "author_id": 883094, "author_profile": "https://Stackoverflow.com/users/883094", "pm_score": 3, "selected": false, "text": "toString() ToStringBuilder equals() hashCode() compareTo()" }, { "answer_id": 29500357, "author": "Sebastian D'Agostino", "author_id": 3294286, "author_profile": "https://Stackoverflow.com/users/3294286", "pm_score": 1, "selected": false, "text": "${:import(org.apache.commons.lang3.builder.HashCodeBuilder, org.apache.commons.lang3.builder.EqualsBuilder)}\n@Override\npublic int hashCode() {\n HashCodeBuilder hashCodeBuilder = new HashCodeBuilder();\n hashCodeBuilder.append(${field1:field});\n hashCodeBuilder.append(${field2:field});\n hashCodeBuilder.append(${field3:field});\n hashCodeBuilder.append(${field4:field});\n hashCodeBuilder.append(${field5:field});\n return hashCodeBuilder.toHashCode();\n}\n\n@Override\npublic boolean equals(Object obj) {\n if (this == obj) {\n return true;\n }\n if (obj == null) {\n return false;\n }\n if (getClass() != obj.getClass()) {\n return false;\n }\n ${enclosing_type} rhs = (${enclosing_type}) obj;\n EqualsBuilder equalsBuilder = new EqualsBuilder();\n equalsBuilder.append(${field1}, rhs.${field1});\n equalsBuilder.append(${field2}, rhs.${field2});\n equalsBuilder.append(${field3}, rhs.${field3});\n equalsBuilder.append(${field4}, rhs.${field4});\n equalsBuilder.append(${field5}, rhs.${field5});${cursor}\n return equalsBuilder.isEquals();\n}\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/281121", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11858/" ]
281,123
<p>I have a loop (for item in @dataset) and I want, in each iteration, to get different data from another table and make some operations that will be printed in the view. I cant't get this data from the dataset used in the loop.</p> <p>How can I do this according to MVC? I can put the code into the loop, in the view, but I think it's horrible.</p> <p>Must I use a helper for do this, and call the function from the view? </p>
[ { "answer_id": 282109, "author": "Orion Edwards", "author_id": 234, "author_profile": "https://Stackoverflow.com/users/234", "pm_score": 7, "selected": true, "text": "has_many @people Person has_many Address # Controller\n@people = Person.find(:all, :include => :addresses)\n...\n\n# View\n@people.each do |p|\n p.addresses.each do |address|\n ...\n # Controller\n@people = Person.find(:all)\n@people.each do |p|\n # attach loaded data to the person object in controller\n p.addresses = Address.load_from_somewhere_by_name(p.name)\n...\n # View\n@people.each do |p|\n p.addresses.each do |address|\n ...\n" }, { "answer_id": 6857064, "author": "Nadeem Yasin", "author_id": 867188, "author_profile": "https://Stackoverflow.com/users/867188", "pm_score": 1, "selected": false, "text": "Person(id, name, other fields...)\nEvent(id, title, ...)\nDate(id, date, time, event_id, ...)\nDisponibility(id, percent, date_id, person_id, ...)\n <% for date in @Dates \n available = Disponibility.find_by_date_id(date.id)\n for item in available\n guy = Person.find_by_id(item.person_id)\n%>\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/281123", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36599/" ]
281,132
<p>Is there any difference between a <code>volatile</code> Object reference and <code>AtomicReference</code> in case I would just use <code>get()</code> and <code>set()</code>-methods from <code>AtomicReference</code>?</p>
[ { "answer_id": 281163, "author": "pgras", "author_id": 12719, "author_profile": "https://Stackoverflow.com/users/12719", "pm_score": 8, "selected": true, "text": "java.util.concurrent.atomic get volatile set volatile AtomicReference::lazySet volatile" }, { "answer_id": 497150, "author": "Peter Lawrey", "author_id": 57695, "author_profile": "https://Stackoverflow.com/users/57695", "pm_score": 2, "selected": false, "text": "AtomicReference volatile" }, { "answer_id": 14674019, "author": "endless", "author_id": 1364959, "author_profile": "https://Stackoverflow.com/users/1364959", "pm_score": 3, "selected": false, "text": "private volatile V value;\n" }, { "answer_id": 45187442, "author": "Nitsan Wakart", "author_id": 1047667, "author_profile": "https://Stackoverflow.com/users/1047667", "pm_score": 5, "selected": false, "text": "AtomicReference AtomicReference AtomicReference AtomicReference AtomicFieldUpdater VarHandle sun.misc.Unsafe AtomicReference Unsafe AtomicReference AtomicFieldUpdater Unsafe AtomicReference" }, { "answer_id": 62212388, "author": "nme", "author_id": 1361495, "author_profile": "https://Stackoverflow.com/users/1361495", "pm_score": -1, "selected": false, "text": "private volatile Status status;\n...\npublic setNewStatus(Status newStatus){\n status = newStatus;\n}\n\npublic void doSomethingConditionally() {\n if(status.isOk()){\n System.out.println(\"Status is ok: \" + status); // here status might not be OK anymore because in the meantime some called setNewStatus(). setNewStatus should be synchronized\n }\n}\n private AtomicReference<Status> statusWrapper;\n...\n\npublic void doSomethingConditionally() {\n Status status = statusWrapper.get();\n if(status.isOk()){\n System.out.println(\"Status is ok: \" + status); // here even if in the meantime some called setNewStatus() we're still referring to the old one\n }\n}\n Status status = statusWrapper.get();\n Status statusCopy = status;\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/281132", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4110/" ]
281,133
<p>What would be the easiest way to move the mouse around (and possibly click) using Python on OS X? </p> <p>This is just for rapid prototyping, it doesn't have to be elegant.</p>
[ { "answer_id": 281330, "author": "Ben", "author_id": 36522, "author_profile": "https://Stackoverflow.com/users/36522", "pm_score": 4, "selected": true, "text": "#include <ApplicationServices/ApplicationServices.h>\n\nint to(int x, int y)\n{\n CGPoint newloc;\n CGEventRef eventRef;\n newloc.x = x;\n newloc.y = y;\n\n eventRef = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved, newloc,\n kCGMouseButtonCenter);\n //Apparently, a bug in xcode requires this next line\n CGEventSetType(eventRef, kCGEventMouseMoved);\n CGEventPost(kCGSessionEventTap, eventRef);\n CFRelease(eventRef);\n\n return 0;\n}\n" }, { "answer_id": 281366, "author": "Jeremy", "author_id": 1114, "author_profile": "https://Stackoverflow.com/users/1114", "pm_score": 3, "selected": false, "text": "java.awt.Robot import java.awt\n\nrobot = java.awt.Robot()\n\nrobot.mouseMove(x, y)\nrobot.mousePress(java.awt.event.InputEvent.BUTTON1_MASK)\nrobot.mouseRelease(java.awt.event.InputEvent.BUTTON1_MASK)\n" }, { "answer_id": 292117, "author": "Rizwan Kassim", "author_id": 35335, "author_profile": "https://Stackoverflow.com/users/35335", "pm_score": 0, "selected": false, "text": "// File:\n// click.m\n//\n// Compile with:\n// gcc -o click click.m -framework ApplicationServices -framework Foundation\n//\n// Usage:\n// ./click -x pixels -y pixels\n// At the given coordinates it will click and release.\n\n#import <Foundation/Foundation.h>\n#import <ApplicationServices/ApplicationServices.h>\n\nint main(int argc, char **argv) {\n NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];\n NSUserDefaults *args = [NSUserDefaults standardUserDefaults];\n\n\n // grabs command line arguments -x and -y\n //\n int x = [args integerForKey:@\"x\"];\n int y = [args integerForKey:@\"y\"];\n\n // The data structure CGPoint represents a point in a two-dimensional\n // coordinate system. Here, X and Y distance from upper left, in pixels.\n //\n CGPoint pt;\n pt.x = x;\n pt.y = y;\n\n\n // https://stackoverflow.com/questions/1483567/cgpostmouseevent-replacement-on-snow-leopard\n CGEventRef theEvent = CGEventCreateMouseEvent(NULL, kCGEventLeftMouseDown, pt, kCGMouseButtonLeft);\n CGEventSetType(theEvent, kCGEventLeftMouseDown);\n CGEventPost(kCGHIDEventTap, theEvent);\n CFRelease(theEvent);\n\n [pool release];\n return 0;\n}\n gcc -o click click.m -framework ApplicationServices -framework Foundation" }, { "answer_id": 664417, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 4, "selected": false, "text": "#!/usr/bin/python\n\nimport objc\n\nclass ETMouse(): \n def setMousePosition(self, x, y):\n bndl = objc.loadBundle('CoreGraphics', globals(), \n '/System/Library/Frameworks/ApplicationServices.framework')\n objc.loadBundleFunctions(bndl, globals(), \n [('CGWarpMouseCursorPosition', 'v{CGPoint=ff}')])\n CGWarpMouseCursorPosition((x, y))\n\nif __name__ == \"__main__\":\n et = ETMouse()\n et.setMousePosition(200, 200)\n" }, { "answer_id": 8202674, "author": "Mike Rhodes", "author_id": 290514, "author_profile": "https://Stackoverflow.com/users/290514", "pm_score": 5, "selected": false, "text": "mousemove mouseclick CGWarpMouseCursorPosition from Quartz.CoreGraphics import CGEventCreateMouseEvent\nfrom Quartz.CoreGraphics import CGEventPost\nfrom Quartz.CoreGraphics import kCGEventMouseMoved\nfrom Quartz.CoreGraphics import kCGEventLeftMouseDown\nfrom Quartz.CoreGraphics import kCGEventLeftMouseUp\nfrom Quartz.CoreGraphics import kCGMouseButtonLeft\nfrom Quartz.CoreGraphics import kCGHIDEventTap\n\ndef mouseEvent(type, posx, posy):\n theEvent = CGEventCreateMouseEvent(\n None, \n type, \n (posx,posy), \n kCGMouseButtonLeft)\n CGEventPost(kCGHIDEventTap, theEvent)\n\ndef mousemove(posx,posy):\n mouseEvent(kCGEventMouseMoved, posx,posy);\n\ndef mouseclick(posx,posy):\n # uncomment this line if you want to force the mouse \n # to MOVE to the click location first (I found it was not necessary).\n #mouseEvent(kCGEventMouseMoved, posx,posy);\n mouseEvent(kCGEventLeftMouseDown, posx,posy);\n mouseEvent(kCGEventLeftMouseUp, posx,posy);\n ##############################################################\n# Python OSX MouseClick\n# (c) 2010 Alex Assouline, GeekOrgy.com\n##############################################################\nimport sys\ntry:\n xclick=intsys.argv1\n yclick=intsys.argv2\n try:\n delay=intsys.argv3\n except:\n delay=0\nexcept:\n print \"USAGE mouseclick [int x] [int y] [optional delay in seconds]\"\n exit\nprint \"mouse click at \", xclick, \",\", yclick,\" in \", delay, \"seconds\"\n# you only want to import the following after passing the parameters check above, because importing takes time, about 1.5s\n# (why so long!, these libs must be huge : anyone have a fix for this ?? please let me know.)\nimport time\nfrom Quartz.CoreGraphics import CGEventCreateMouseEvent\nfrom Quartz.CoreGraphics import CGEventPost\nfrom Quartz.CoreGraphics import kCGEventMouseMoved\nfrom Quartz.CoreGraphics import kCGEventLeftMouseDown\nfrom Quartz.CoreGraphics import kCGEventLeftMouseDown\nfrom Quartz.CoreGraphics import kCGEventLeftMouseUp\nfrom Quartz.CoreGraphics import kCGMouseButtonLeft\nfrom Quartz.CoreGraphics import kCGHIDEventTap\ndef mouseEventtype, posx, posy:\n theEvent = CGEventCreateMouseEventNone, type, posx,posy, kCGMouseButtonLeft\n CGEventPostkCGHIDEventTap, theEvent\ndef mousemoveposx,posy:\n mouseEventkCGEventMouseMoved, posx,posy;\ndef mouseclickposx,posy:\n #mouseEvent(kCGEventMouseMoved, posx,posy); #uncomment this line if you want to force the mouse to MOVE to the click location first (i found it was not necesary).\n mouseEventkCGEventLeftMouseDown, posx,posy;\n mouseEventkCGEventLeftMouseUp, posx,posy;\ntime.sleepdelay;\nmouseclickxclick, yclick;\nprint \"done.\"\n" }, { "answer_id": 10696392, "author": "dfred", "author_id": 1128898, "author_profile": "https://Stackoverflow.com/users/1128898", "pm_score": 1, "selected": false, "text": "python2.6 python which python 2.7 easy_install –-prefix /Path/To/Python/Version pyobjc==2.3 easy_install –-prefix /Library/Frameworks/Python.framework/Versions/2.7 pyobjc==2.3 import objc easy_install --prefix /Library/Frameworks/Python.framework/Versions/2.7 pyobjc-core==2.3 defaults write com.apple.versioner.python Version 2.6 Command+Shift+4" }, { "answer_id": 17578617, "author": "Gwen", "author_id": 2383522, "author_profile": "https://Stackoverflow.com/users/2383522", "pm_score": 2, "selected": false, "text": "import autopy\nautopy.mouse.move(200,200)\n" }, { "answer_id": 42749433, "author": "GJ.", "author_id": 303295, "author_profile": "https://Stackoverflow.com/users/303295", "pm_score": 5, "selected": false, "text": "pynput from pynput.mouse import Button, Controller\n\nmouse = Controller()\n\n# Read pointer position\nprint('The current pointer position is {0}'.format(\n mouse.position))\n\n# Set pointer position\nmouse.position = (10, 20)\nprint('Now we have moved it to {0}'.format(\n mouse.position))\n\n# Move pointer relative to current position\nmouse.move(5, -5)\n\n# Press and release\nmouse.press(Button.left)\nmouse.release(Button.left)\n\n# Double click; this is different from pressing and releasing\n# twice on Mac OSX\nmouse.click(Button.left, 2)\n\n# Scroll two steps down\nmouse.scroll(0, 2)\n" }, { "answer_id": 44202804, "author": "kenorb", "author_id": 55075, "author_profile": "https://Stackoverflow.com/users/55075", "pm_score": 0, "selected": false, "text": "CoreGraphics from Quartz.CoreGraphics import CGEventCreate\nfrom Quartz.CoreGraphics import CGEventGetLocation\nourEvent = CGEventCreate(None);\ncurrentpos = CGEventGetLocation(ourEvent);\nmousemove(currentpos.x,currentpos.y)\n" }, { "answer_id": 44230608, "author": "kenorb", "author_id": 55075, "author_profile": "https://Stackoverflow.com/users/55075", "pm_score": 0, "selected": false, "text": "Quartz #!/usr/bin/python\nimport sys\nfrom AppKit import NSEvent\nimport Quartz\n\nclass Mouse():\n down = [Quartz.kCGEventLeftMouseDown, Quartz.kCGEventRightMouseDown, Quartz.kCGEventOtherMouseDown]\n up = [Quartz.kCGEventLeftMouseUp, Quartz.kCGEventRightMouseUp, Quartz.kCGEventOtherMouseUp]\n [LEFT, RIGHT, OTHER] = [0, 1, 2]\n\n def position(self):\n point = Quartz.CGEventGetLocation( Quartz.CGEventCreate(None) )\n return point.x, point.y\n\n def location(self):\n loc = NSEvent.mouseLocation()\n return loc.x, Quartz.CGDisplayPixelsHigh(0) - loc.y\n\n def move(self, x, y):\n moveEvent = Quartz.CGEventCreateMouseEvent(None, Quartz.kCGEventMouseMoved, (x, y), 0)\n Quartz.CGEventPost(Quartz.kCGHIDEventTap, moveEvent)\n\n def press(self, x, y, button=1):\n event = Quartz.CGEventCreateMouseEvent(None, Mouse.down[button], (x, y), button - 1)\n Quartz.CGEventPost(Quartz.kCGHIDEventTap, event)\n\n def release(self, x, y, button=1):\n event = Quartz.CGEventCreateMouseEvent(None, Mouse.up[button], (x, y), button - 1)\n Quartz.CGEventPost(Quartz.kCGHIDEventTap, event)\n\n def click(self, button=LEFT):\n x, y = self.position()\n self.press(x, y, button)\n self.release(x, y, button)\n\n def click_pos(self, x, y, button=LEFT):\n self.move(x, y)\n self.click(button)\n\n def to_relative(self, x, y):\n curr_pos = Quartz.CGEventGetLocation( Quartz.CGEventCreate(None) )\n x += current_position.x;\n y += current_position.y;\n return [x, y]\n\n def move_rel(self, x, y):\n [x, y] = to_relative(x, y)\n moveEvent = Quartz.CGEventCreateMouseEvent(None, Quartz.kCGEventMouseMoved, Quartz.CGPointMake(x, y), 0)\n Quartz.CGEventPost(Quartz.kCGHIDEventTap, moveEvent)\n Mouse.py mouseUtils.py # DEMO\nif __name__ == '__main__':\n mouse = Mouse()\n if sys.platform == \"darwin\":\n print(\"Current mouse position: %d:%d\" % mouse.position())\n print(\"Moving to 100:100...\");\n mouse.move(100, 100)\n print(\"Clicking 200:200 position with using the right button...\");\n mouse.click_pos(200, 200, mouse.RIGHT)\n elif sys.platform == \"win32\":\n print(\"Error: Platform not supported!\")\n" }, { "answer_id": 49514242, "author": "biendltb", "author_id": 6088342, "author_profile": "https://Stackoverflow.com/users/6088342", "pm_score": 4, "selected": false, "text": "pip install pyautogui\n >>> pyautogui.position()\n(187, 567)\n >>> pyautogui.moveTo(100,200)\n >>> pyautogui.click()\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/281133", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36522/" ]
281,144
<p>I am having some trouble grasping some concepts behind the MVC framework. I am doing a very simple application which categorizes products.</p> <p>The Creation screen will simply use a dropdown list showing the list of categories, the name of the product and submit.</p> <p>On a normal .Net app, I would databind a server dropdownlist in the Page_Load, but in a MVC app, what is the best way to retrieve my categories from the database and add them to the dropdown list?</p> <p>(Sorry, my question is extremely noobish but unfortunately resources are spare on MVC, and examples are often broken due to early changes)</p>
[ { "answer_id": 281211, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "public class LogEvent{\n public string Title {get;set;}\n public string Date {get;set;}\n public string Message {get;set;}\n\n // this is for example only; you would most likely bind directly against the host.GetAllLogs() result\n public static IEnumerable<LogEvent> RetrieveAllLogs(ILogProvider host){\n return from x in host.GetAllLogs() select new LogEvent(x.LogTitle, x.Date, x.Message);\n }\n [DependencyPropertyLolJk]\nprotected ILogProvider MyLogProvider {get;set;} // set by DI\n\n[AcceptVerbs(HttpVerbs.Get)]\npublic ActionResult Logs()\n{\n return View(\"Logs\", LogEvent.GetAllLogs(MyLogProvider).OrderByDescending(x => x.Date));\n}\n <!-- header left out for brevity -->\n<table>\n <thead>\n <tr>\n <th>\n Date\n </th>\n <th>\n Title\n </th>\n <th>\n Message\n </th>\n </tr>\n </thead>\n <% foreach(var log in ViewData.Model) %>\n <tr>\n<td><%= log.Date %></td>\n<td><%= log.Title %></td>\n<td><%= log.Message %></td>\n </tr>\n <% }; %>\n</table>\n\n<!-- ... -->\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/281144", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5789/" ]
281,167
<p>I've got a particular SQL statement which takes about 30 seconds to perform, and I'm wondering if anyone can see a problem with it, or where I need additional indexing.</p> <p>The code is on a subform in Access, which shows results dependent on the content of five fields in the master form. There are nearly 5000 records in the table that's being queried. The Access project is stored and run from a terminal server session on the actual SQL server, so I don't think it's a network issue, and there's another form which is very similar that uses the same type of querying...</p> <p>Thanks</p> <p>PG</p> <pre><code>SELECT TabDrawer.DrawerName, TabDrawer.DrawerSortCode, TabDrawer.DrawerAccountNo, TabDrawer.DrawerPostCode, QryAllTransactons.TPCChequeNumber, tabdrawer.drawerref FROM TabDrawer LEFT JOIN QryAllTransactons ON TabDrawer.DrawerRef=QryAllTransactons.tpcdrawer WHERE (Forms!FrmSearchCompany!SearchName Is Null Or [drawername] Like Forms!FrmSearchCompany!SearchName &amp; "*") And (Forms!FrmSearchCompany.SearchPostcode Is Null Or [Drawerpostcode] Like Forms!FrmSearchCompany!Searchpostcode &amp; "*") And (Forms!FrmSearchCompany!SearchSortCode Is Null Or [drawersortcode] Like Forms!FrmSearchCompany!Searchsortcode &amp; "*") And (Forms!FrmSearchCompany!Searchaccount Is Null Or [draweraccountno] Like Forms!FrmSearchCompany!Searchaccount &amp; "*") And (Forms!FrmSearchCompany!Searchcheque Is Null Or [tpcchequenumber] Like Forms!FrmSearchCompany!Searchcheque &amp; "*"); "); </code></pre> <hr> <p><strong>EDIT</strong></p> <p>The Hold up seems to be in the union query that forms the QryAllTransactons query.</p> <pre><code>SELECT "TPC" AS Type, TabTPC.TPCRef, TabTPC.TPCBranch, TabTPC.TPCDate, TabTPC.TPCChequeNumber, TabTPC.TPCChequeValue, TabTPC.TPCFee, TabTPC.TPCAction, TabTPC.TPCMember, tabtpc.tpcdrawer, TabTPC.TPCUser, TabTPC.TPCDiscount, tabcustomers.* FROM TabTPC INNER JOIN TabCustomers ON TabTPC.TPCMember = TabCustomers.CustomerID UNION ALL SELECT "CTP" AS Type, TabCTP.CTPRef, TabCTP.CTPBranch, TabCTP.CTPDate, TabCTP.CTPChequeNumb, TabCTP.CTPAmount, TabCTP.CTPFee, TabCTP.CTPAction, TabCTP.CTPMember, 0 as CTPXXX, TabCTP.CTPUser, TabCTP.CTPDiscount, TABCUSTOMERS.* FROM TabCTP INNER JOIN TabCustomers ON Tabctp.ctpMember = TabCustomers.CustomerID; </code></pre> <p>I've done a fair bit of work with simple union queries, but never had this before...</p>
[ { "answer_id": 281214, "author": "Tomalak", "author_id": 18771, "author_profile": "https://Stackoverflow.com/users/18771", "pm_score": 1, "selected": false, "text": "WHERE\n [drawername] Like Nz(Forms!FrmSearchCompany!SearchName, \"\") & \"*\"\n And \n [Drawerpostcode] Like Nz(Forms!FrmSearchCompany!Searchpostcode, \"\") & \"*\"\n And \n [drawersortcode] Like Nz(Forms!FrmSearchCompany!Searchsortcode, \"\") & \"*\"\n And \n [draweraccountno] Like Nz(Forms!FrmSearchCompany!Searchaccount, \"\") & \"*\"\n And \n [tpcchequenumber] Like Nz(Forms!FrmSearchCompany!Searchcheque, \"\") & \"*\"\n" }, { "answer_id": 281839, "author": "VVS", "author_id": 21038, "author_profile": "https://Stackoverflow.com/users/21038", "pm_score": 0, "selected": false, "text": "Left([field], Len(value)) = value\n SELECT\n TabDrawer.DrawerName, \n TabDrawer.DrawerSortCode, \n TabDrawer.DrawerAccountNo, \n TabDrawer.DrawerPostCode, \n QryAllTransactons.TPCChequeNumber, \n TabDrawer.DrawerRef\nFROM\n TabDrawer \n LEFT JOIN QryAllTransactons \n ON TabDrawer.DrawerRef = QryAllTransactons.TpcDrawer\nWHERE \n (Forms!FrmSearchCompany!SearchName Is Null \n Or Left([drawername], Len(Forms!FrmSearchCompany!SearchName)) = Forms!FrmSearchCompany!SearchName)\nAnd\n (Forms!FrmSearchCompany.SearchPostcode Is Null \n Or Left([Drawerpostcode], Len(Forms!FrmSearchCompany!Searchpostcode)) = Forms!FrmSearchCompany!Searchpostcode) \nAnd \n (Forms!FrmSearchCompany!SearchSortCode Is Null \n Or Left([drawersortcode], Len(Forms!FrmSearchCompany!Searchsortcode)) = Forms!FrmSearchCompany!Searchsortcode) \nAnd \n (Forms!FrmSearchCompany!Searchaccount Is Null \n Or Left([draweraccountno], Len(Forms!FrmSearchCompany!Searchaccount)) = Forms!FrmSearchCompany!Searchaccount) \nAnd \n (Forms!FrmSearchCompany!Searchcheque Is Null \n Or Left([tpcchequenumber], Len(Forms!FrmSearchCompany!Searchcheque)) = Forms!FrmSearchCompany!Searchcheque)\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/281167", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30140/" ]
281,170
<p>I have an installer that deploys web services to IIS. After this has finshed a custom action fires that updates the database with the scripts required by the webservices. The scripts are currently deploying to IIS aswell because they are part of the .net project. How can I configure the installation process so the scripts arn't part of the project and get un-packed from the MSI so my custom action can access them?</p>
[ { "answer_id": 281364, "author": "CheGueVerra", "author_id": 17787, "author_profile": "https://Stackoverflow.com/users/17787", "pm_score": 0, "selected": false, "text": "<Binary Id=\"webServiceScript.sql\" src=\"[DirectoryToFile]\\webServiceDataScript.sql\" />\n <CustomAction Id=\"CallCmd\" Value=\"[Path_to_Exe_Folder][Your_EXE_TO_RUN_SCRIPT_HERE]\" />\n\n<CustomAction Id=\"RunCmd\" ExeCommand=\"webServiceScript.sql\" BinaryKey=\"webServiceScript.sql\" Return=\"Ignore\" />\n <InstallExecuteSequence>\n <Custom Action=\"CallCmd\" Before=\"InstallFinalize\" />\n <Custom Action=\"RunCmd\" After=\"CallCmd\" />\n</InstallExecuteSequence>\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/281170", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
281,177
<p>Is it a good practice to comment code that is removed? For example:</p> <pre><code>// Code to do {task} was removed by Ajahn on 10/10/08 because {reason}. </code></pre> <p>Someone in my developer group during a peer review made a note that we should comment the lines of code to be removed. I thought this was a terrible suggestion, since it clutters the code with useless comments. Which one of us is right?</p>
[ { "answer_id": 281206, "author": "andy.gurin", "author_id": 22388, "author_profile": "https://Stackoverflow.com/users/22388", "pm_score": 2, "selected": false, "text": "// removed because of this and that\n/* \n removed this stuff because my left leg...\n*/\n doSomething();\n// this piece of has been removed, we don't need it...\n" }, { "answer_id": 281543, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": " // this is now handled by the heartbeat thread\n // m_data.resort(m_ascending);\n // don't re-sort here, as it is now handled by the heartbeat thread\n cutoff = m_previous_cutofftime;\n cutoff = (!ok_during) ? m_previous_cutofftime : 0;\n // this works for overlong events but not resuming\n// cutoff = m_previous_cutofftime;\n // this works for resuming but not overlong events\n// cutoff = (!ok_during) ? m_previous_cutofftime : 0;\n // this works for both\n cutoff = (!resuming || !ok_during) ? m_previous_cutofftime : 0;\n" }, { "answer_id": 317646, "author": "PhiLho", "author_id": 15459, "author_profile": "https://Stackoverflow.com/users/15459", "pm_score": 1, "selected": false, "text": "#ifdef OLD /* PL - 11/10/1989 */\nvoid Buggy()\n{\n// ...\n}\n#else\nvoid Good()\n{\n// ...\n}\n#end\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/281177", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5831/" ]
281,210
<p>We have scalar functions in our database for returning things like "number of tasks for a customer" or "total invoice amount for a customer". </p> <p>We are experimenting and looking to try to do this w/o stored procedures ... normally we would just call this function in our stored procedure and return it as a single value. </p> <p>Is there a way to use or access scalar functions with LINQ to SQL? If so, I would be interested in see an example of how to ... if not, how would it be best to handle this type of situation ... if it is even doable.</p>
[ { "answer_id": 281224, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 4, "selected": true, "text": "[Function(..., IsComposable=true)] var qry = from cust in ctx.Custs\n select new {Id = cust.Id, Value = ctx.GetTotalValue(cust.Id)};\n SELECT t1.Id, dbo.MyUdf(t1.Id)\nFROM CUSTOMER t1\n Where() WHERE JOIN" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/281210", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1768/" ]
281,246
<p>I have to add either an embed tag for Firefox or an object tag for Internet Explorer with JavaScript to address the appropriate ActiveX / Plugin depending on the browser. The plugin could be missing and needs to get downloaded in this case. The dynamically added embed tag for Firefox works as expected. The dynamically added object tag for Internet Explorer seems to do nothing at all. The object tag needs the following attributes to function properly.</p> <p><code>id ="SomeId" classid = "CLSID:{GUID}" codebase = "http://www.MyActicexSource.com/MyCuteActivex.CAB#Version=2,0,0,1"</code></p> <p>Even a general working idea or method would be nice.</p> <p>Thanks!</p>
[ { "answer_id": 281280, "author": "Jason Bunting", "author_id": 1790, "author_profile": "https://Stackoverflow.com/users/1790", "pm_score": 5, "selected": true, "text": "// something akin to this:\ndocument.getElementById(myDivId).innerHTML = \"<OBJECT id='foo' classid='CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95'.....etc\";\n innerHTML <body onload=\"loadAppropriatePlugin()\"> id <script> <head> function getIEVersion() { // or something like this\n var ua = window.navigator.userAgent;\n var msie = ua.indexOf(\"MSIE \");\n return ((msie > 0) ? parseInt(ua.substring(msie+5, ua.indexOf(\".\", msie))) : 0);\n}\n\nfunction loadAppropriatePlugin() {\n if(getIEVersion() != 0) { // this means we are in IE\n document.getElementById(\"Foo\").innerHTML = \"<OBJECT id='foo' classid='CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95'.....etc\";\n } else {\n // if you want to maybe do the same for FF and load that stuff...\n }\n}\n" }, { "answer_id": 281287, "author": "Andrew G. Johnson", "author_id": 428190, "author_profile": "https://Stackoverflow.com/users/428190", "pm_score": -1, "selected": false, "text": "<script type=\"text/javascript\">\n<!--\n document.write(\"<object id=\\\"SomeId\\\" classid=\\\"CLSID:{GUID}\\\" codebase=\\\"http://www.MyActicexSource.com/MyCuteActivex.CAB#Version=2,0,0,1\\\"></object>\");\n-->\n</script>\n <div id=\"my-div\"></div>\n<script type=\"text/javascript\">\n<!--\n document.getElementById(\"my-div\").innerHTML = \"<object id=\\\"SomeId\\\" classid=\\\"CLSID:{GUID}\\\" codebase=\\\"http://www.MyActicexSource.com/MyCuteActivex.CAB#Version=2,0,0,1\\\"></object>\";\n-->\n</script>\n" }, { "answer_id": 2759283, "author": "dgFish3r", "author_id": 331562, "author_profile": "https://Stackoverflow.com/users/331562", "pm_score": 1, "selected": false, "text": "var object = document.createelement('object')\nobject.setAttribute('id','name')\nobject.setAttribute('clssid','CLSID:{}')\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/281246", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1890/" ]
281,247
<p>I'm relatively new to NHibernate, but have been using it for the last few programs and I'm in love. I've come to a situation where I need to aggregate data from 4-5 databases into a single database. Specifically it is serial number data. Each database will have its own mapping file, but ultimately the entities all share the same basic structure (Serial class).</p> <p>I understand NHibernate wants a mapping per class, and so my initial thought was to have a base Serial Class and then inherit from it for each different database and create a unique mapping file (the inherited class would have zero content). This should work great for grabbing all the data and populating the objects. What I would then like to do is save these inherited classes (not sure what the proper term is) to the base class table using the base class mapping.</p> <p>The problem is I have no idea how to force NHIbernate to use a specific mapping file for an object. Casting the inherited class to the base class does nothing when using 'session.save()' (it complains of no mapping).</p> <p>Is there a way to explicitly specify which mapping to use? Or is there just some OOP principal I am missing to more specifically cast an inherited class to base class? Or is this idea just a bad one.</p> <p>All of the inheritance stuff I could find with regards to NHibernate (Chapter 8) doesn't seem to be totally applicable to this function, but I could be wrong (the table-per-concrete-class looks maybe useful, but I can't wrap my head around it totally with regards to how NHibernate figures out what to do).</p>
[ { "answer_id": 291994, "author": "anonymous", "author_id": 36602, "author_profile": "https://Stackoverflow.com/users/36602", "pm_score": 0, "selected": false, "text": "public class Serial\n{\n public string SerialNumber {get; set;}\n public string ItemNumber {get; set;}\n public string OrderNumber {get; set;}\n}\n Serial serial = sessionX.get(typeof(Serial), someID);\nsessionY.save(serial);\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/281247", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36602/" ]
281,257
<p>In an earlier question about <a href="https://stackoverflow.com/questions/280579/c-beginner-help-how-do-i-pass-a-value-from-a-child-back-to-the-parent-form">how to return a string from a dialog window</a>, <strong>yapiskan</strong> suggested <a href="https://stackoverflow.com/questions/280579/c-beginner-help-how-do-i-pass-a-value-from-a-child-back-to-the-parent-form#280731">overloading the child form's ShowDialog() method</a> to include an out parameter.</p> <p>My question is whether or not this is a good approach in C#.</p> <p>Here is some example code, based on yapiskan's suggestion. In the child form (in this example, it's a form with a textbox on it), you just need to add the ShowDialog overload and assign UI values to the out parameter:</p> <pre><code>public DialogResult ShowDialog(out string s) { DialogResult result = this.ShowDialog(); s = this.textBox1.Text; return result; } </code></pre> <p>And to show the form and retrieve the entered text, you do this:</p> <pre><code>using (CustomDialog frm = new CustomDialog()) { string s; if (frm.ShowDialog(out s) == DialogResult.OK) { // do something with s } } </code></pre> <p>One advantage I can think of is that this approach forces the user of the CustomDialog form to get the information it contains through the form's ShowDialog method (rather than from a who-knows-what-it's-called method like GetMyData() or something).</p>
[ { "answer_id": 281953, "author": "Robert Rossney", "author_id": 19403, "author_profile": "https://Stackoverflow.com/users/19403", "pm_score": 2, "selected": false, "text": "MyDialog d = new MyDialog();\nd.ShowDialog(\n string foo;\nstring\n bar Parameters MyDialog d = new MyDialog();\nd.Parameters.Foo = \"foo\";\nd.Parameters.Bar = \"bar\";\nd.Parameters.Baz = \"baz\";\n" }, { "answer_id": 281976, "author": "Erik Forbes", "author_id": 16942, "author_profile": "https://Stackoverflow.com/users/16942", "pm_score": 2, "selected": false, "text": "public string GetFolderName(){\n if(this.ShowDialog() == DialogResult.OK) {\n return this.FolderName.Text;\n }\n return String.Empty;\n}\n public struct FolderData {\n public static FolderData Empty = new FolderData();\n\n public string FolderName {get; set;}\n public int FilesInFolder {get; set;}\n}\n\npublic FolderData GetFolderData(){\n if(this.ShowDialog() == DialogResult.OK) {\n return new FolderData {\n FolderName = this.FolderName.Text;\n FilesInFolder = int.Parse(this.FilesInFolder.Text);\n }\n }\n return FolderData.Empty;\n}\n" }, { "answer_id": 282046, "author": "Robert Paulson", "author_id": 14033, "author_profile": "https://Stackoverflow.com/users/14033", "pm_score": 1, "selected": false, "text": "public sealed class MySaveDialogResult\n{\n public static MySaveDialogResult NonOkResult(); // Null Object pattern\n public MySaveDialogResult( string filePath ) { ... }\n\n // encapsulate the dialog result\n public DialogResult DialogResult { get; private set; } \n // some property that was set in the dialog\n public string FilePath { get; private set; }\n // another property set in the dialog\n public bool AllowOVerwrite { get; private set; }\n}\n public MySaveDialog ...\n{\n public MySaveDialogResult GetDialogResult() { .... }\n}\n GetDialogResult() MyDialogResult GetDialogResult() out GetDialogResult()" }, { "answer_id": 284166, "author": "Serhat Ozgel", "author_id": 31505, "author_profile": "https://Stackoverflow.com/users/31505", "pm_score": 3, "selected": false, "text": "string dummyFileName;\nstring[] dummyFileNames;\nstring safeFileName;\nstring[] dummySafeFileNames;\n\nmyDialog.ShowDialog(out dummyFileName, out dummyFileNames, out safeFileName, out dummySafeFileNames);\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/281257", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14606/" ]
281,258
<p>Suppose I have one html page with frames. The left frame is simply a list of links, which will be displayed in the right frame. Is it possible, using javascript, to generate the contents of the left frame when the page loads?</p>
[ { "answer_id": 281953, "author": "Robert Rossney", "author_id": 19403, "author_profile": "https://Stackoverflow.com/users/19403", "pm_score": 2, "selected": false, "text": "MyDialog d = new MyDialog();\nd.ShowDialog(\n string foo;\nstring\n bar Parameters MyDialog d = new MyDialog();\nd.Parameters.Foo = \"foo\";\nd.Parameters.Bar = \"bar\";\nd.Parameters.Baz = \"baz\";\n" }, { "answer_id": 281976, "author": "Erik Forbes", "author_id": 16942, "author_profile": "https://Stackoverflow.com/users/16942", "pm_score": 2, "selected": false, "text": "public string GetFolderName(){\n if(this.ShowDialog() == DialogResult.OK) {\n return this.FolderName.Text;\n }\n return String.Empty;\n}\n public struct FolderData {\n public static FolderData Empty = new FolderData();\n\n public string FolderName {get; set;}\n public int FilesInFolder {get; set;}\n}\n\npublic FolderData GetFolderData(){\n if(this.ShowDialog() == DialogResult.OK) {\n return new FolderData {\n FolderName = this.FolderName.Text;\n FilesInFolder = int.Parse(this.FilesInFolder.Text);\n }\n }\n return FolderData.Empty;\n}\n" }, { "answer_id": 282046, "author": "Robert Paulson", "author_id": 14033, "author_profile": "https://Stackoverflow.com/users/14033", "pm_score": 1, "selected": false, "text": "public sealed class MySaveDialogResult\n{\n public static MySaveDialogResult NonOkResult(); // Null Object pattern\n public MySaveDialogResult( string filePath ) { ... }\n\n // encapsulate the dialog result\n public DialogResult DialogResult { get; private set; } \n // some property that was set in the dialog\n public string FilePath { get; private set; }\n // another property set in the dialog\n public bool AllowOVerwrite { get; private set; }\n}\n public MySaveDialog ...\n{\n public MySaveDialogResult GetDialogResult() { .... }\n}\n GetDialogResult() MyDialogResult GetDialogResult() out GetDialogResult()" }, { "answer_id": 284166, "author": "Serhat Ozgel", "author_id": 31505, "author_profile": "https://Stackoverflow.com/users/31505", "pm_score": 3, "selected": false, "text": "string dummyFileName;\nstring[] dummyFileNames;\nstring safeFileName;\nstring[] dummySafeFileNames;\n\nmyDialog.ShowDialog(out dummyFileName, out dummyFileNames, out safeFileName, out dummySafeFileNames);\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/281258", "https://Stackoverflow.com", "https://Stackoverflow.com/users/34329/" ]
281,264
<p>How do I remove empty elements from an array in JavaScript? </p> <p>Is there a straightforward way, or do I need to loop through it and remove them manually?</p>
[ { "answer_id": 281288, "author": "Matty", "author_id": 26241, "author_profile": "https://Stackoverflow.com/users/26241", "pm_score": -1, "selected": false, "text": "function removeEmptyElem(ary) {\n for (var i = ary.length - 1; i >= 0; i--) {\n if (ary[i] == undefined) {\n ary.splice(i, 1);\n } \n }\n return ary;\n}\n" }, { "answer_id": 281306, "author": "Jason Bunting", "author_id": 1790, "author_profile": "https://Stackoverflow.com/users/1790", "pm_score": 3, "selected": false, "text": "function removeFalsyElementsFromArray(someArray) {\n var newArray = [];\n for(var index = 0; index < someArray.length; index++) {\n if(someArray[index]) {\n newArray.push(someArray[index]);\n }\n }\n return newArray;\n}\n function removeElementsFromArray(someArray, filter) {\n var newArray = [];\n for(var index = 0; index < someArray.length; index++) {\n if(filter(someArray[index]) == false) {\n newArray.push(someArray[index]);\n }\n }\n return newArray;\n}\n\n// then provide one or more filter functions that will \n// filter out the elements based on some condition:\nfunction isNullOrUndefined(item) {\n return (item == null || typeof(item) == \"undefined\");\n}\n\n// then call the function like this:\nvar myArray = [1,2,,3,,3,,,,,,4,,4,,5,,6,,,,];\nvar results = removeElementsFromArray(myArray, isNullOrUndefined);\n\n// results == [1,2,3,3,4,4,5,6]\n" }, { "answer_id": 281335, "author": "Christian C. Salvadó", "author_id": 5445, "author_profile": "https://Stackoverflow.com/users/5445", "pm_score": 11, "selected": true, "text": "Array.prototype filter null undefined var array = [0, 1, null, 2, \"\", 3, undefined, 3,,,,,, 4,, 4,, 5,, 6,,,,];\n\nvar filtered = array.filter(function (el) {\n return el != null;\n});\n\nconsole.log(filtered); \"\" 0 NaN null undefined false filter Boolean var filtered = array.filter(Boolean);\n var filtered = array.filter(function(el) { return el; });\n filter Boolean filter Boolean filter var sparseArray = [0, , , 1, , , , , 2, , , , 3],\n cleanArray = sparseArray.filter(function () { return true });\n\nconsole.log(cleanArray); // [ 0, 1, 2, 3 ] Array.prototype.clean = function(deleteValue) {\n for (var i = 0; i < this.length; i++) {\n if (this[i] == deleteValue) { \n this.splice(i, 1);\n i--;\n }\n }\n return this;\n};\n\ntest = new Array(\"\", \"One\", \"Two\", \"\", \"Three\", \"\", \"Four\").clean(\"\");\ntest2 = [1, 2,, 3,, 3,,,,,, 4,, 4,, 5,, 6,,,,];\ntest2.clean(undefined);\n // Will remove all falsy values: undefined, null, 0, false, NaN and \"\" (empty string)\nfunction cleanArray(actual) {\n var newArray = new Array();\n for (var i = 0; i < actual.length; i++) {\n if (actual[i]) {\n newArray.push(actual[i]);\n }\n }\n return newArray;\n}\n\ncleanArray([1, 2,, 3,, 3,,,,,, 4,, 4,, 5,, 6,,,,]);\n" }, { "answer_id": 281393, "author": "Alnitak", "author_id": 6782, "author_profile": "https://Stackoverflow.com/users/6782", "pm_score": 7, "selected": false, "text": "Array.filter return true arr = arr.filter(function() { return true; });\n .filter filter null undefined" }, { "answer_id": 281638, "author": "Joe Pineda", "author_id": 21258, "author_profile": "https://Stackoverflow.com/users/21258", "pm_score": 1, "selected": false, "text": "/* appjet:version 0.1 */\nfunction Joes_remove(someArray) {\n var newArray = [];\n var element;\n for( element in someArray){\n if(someArray[element]!=undefined ) {\n newArray.push(someArray[element]);\n }\n }\n return newArray;\n}\n\nvar myArray2 = [1,2,,3,,3,,,0,,,4,,4,,5,,6,,,,];\n\nprint(\"Original array:\", myArray2);\nprint(\"Clenased array:\", Joes_remove(myArray2) );\n/*\nReturns: [1,2,3,3,0,4,4,5,6]\n*/\n" }, { "answer_id": 660553, "author": "Erik Johansson", "author_id": 15307, "author_profile": "https://Stackoverflow.com/users/15307", "pm_score": 4, "selected": false, "text": "var array = [\"\",\"one\",0,\"\",null,0,1,2,4,\"two\"];\n\nfunction isempty(x){\nif(x!==\"\")\n return true;\n}\nvar res = array.filter(isempty);\ndocument.writeln(res.toJSONString());\n// gives: [\"one\",0,null,0,1,2,4,\"two\"] \n //This prototype is provided by the Mozilla foundation and\n//is distributed under the MIT license.\n//http://www.ibiblio.org/pub/Linux/LICENSES/mit.license\n\nif (!Array.prototype.filter)\n{\n Array.prototype.filter = function(fun /*, thisp*/)\n {\n var len = this.length;\n if (typeof fun != \"function\")\n throw new TypeError();\n\n var res = new Array();\n var thisp = arguments[1];\n for (var i = 0; i < len; i++)\n {\n if (i in this)\n {\n var val = this[i]; // in case fun mutates this\n if (fun.call(thisp, val, i, this))\n res.push(val);\n }\n }\n\n return res;\n };\n}\n" }, { "answer_id": 2333725, "author": "lcabral", "author_id": 281178, "author_profile": "https://Stackoverflow.com/users/281178", "pm_score": -1, "selected": false, "text": "array = array.filter(/\\w/);\nfilter + regexp\n" }, { "answer_id": 2843625, "author": "vsync", "author_id": 104380, "author_profile": "https://Stackoverflow.com/users/104380", "pm_score": 11, "selected": false, "text": "var arr = [1,2,,3,,-3,null,,0,,undefined,4,,4,,5,,6,,,,];\n\narr.filter(n => n)\n// [1, 2, 3, -3, 4, 4, 5, 6]\n\narr.filter(Number) \n// [1, 2, 3, -3, 4, 4, 5, 6]\n\narr.filter(Boolean) \n// [1, 2, 3, -3, 4, 4, 5, 6]\n ['','1','2',3,,'4',,undefined,,,'5'].join('').split(''); \n// output: [\"1\",\"2\",\"3\",\"4\",\"5\"]\n var arr = [1,2,null, undefined,3,,3,,,0,,,[],,{},,5,,6,,,,],\n len = arr.length, i;\n\nfor(i = 0; i < len; i++ )\n arr[i] && arr.push(arr[i]); // copy non-empty values to the end of the array\n\narr.splice(0 , len); // cut the array and leave only the non-empty values\n// [1,2,3,3,[],Object{},5,6]\n var arr = [1,2,,3,,3,,,0,,,4,,4,,5,,6,,,,];\n \narr = $.grep(arr, n => n == 0 || n);\n// [1, 2, 3, 3, 0, 4, 4, 5, 6]\n" }, { "answer_id": 4423182, "author": "JessyNinja", "author_id": 506411, "author_profile": "https://Stackoverflow.com/users/506411", "pm_score": 2, "selected": false, "text": "js> [1,2,,3,,3,,,0,,,4,,4,,5,,6,,,,].filter(String).join(',')\n1,2,3,3,0,4,4,5,6\n" }, { "answer_id": 5443800, "author": "Tomás Senart", "author_id": 138153, "author_profile": "https://Stackoverflow.com/users/138153", "pm_score": 6, "selected": false, "text": "var arr = [0,1,2,\"Thomas\",\"false\",false,true,null,3,4,undefined,5,\"end\"];\narr = arr.filter(Boolean);\n// [1, 2, \"Thomas\", \"false\", true, 3, 4, 5, \"end\"]\n" }, { "answer_id": 7924304, "author": "lepe", "author_id": 196507, "author_profile": "https://Stackoverflow.com/users/196507", "pm_score": 8, "selected": false, "text": "arr = arr.filter(function(e){return e}); \n arr = arr.filter(function(e){ return e.replace(/(\\r\\n|\\n|\\r)/gm,\"\")});\n arr = [\"hello\",0,\"\",null,undefined,1,100,\" \"] \narr.filter(function(e){return e});\n [\"hello\", 1, 100, \" \"]\n arr.filter(function(e){ return e === 0 || e });\n [\"hello\", 0, 1, 100, \" \"]\n" }, { "answer_id": 12091280, "author": "Jason", "author_id": 1584271, "author_profile": "https://Stackoverflow.com/users/1584271", "pm_score": -1, "selected": false, "text": "1. replace \"__\" or more with just one \"_\",\n2. replace preceding \"_\" with nothing \"\" and similarly \n3. replace and ending \"_\" with nothing \"\"\n var myArr = new Array(\"\",\"\",\"a\",\"b\",\"\",\"c\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"e\",\"\");\nvar myStr = \"\";\n\nmyStr = myArr.join(\"_\");\n\nmyStr = myStr.replace(new RegExp(/__*/g),\"_\");\nmyStr = myStr.replace(new RegExp(/^_/i),\"\");\nmyStr = myStr.replace(new RegExp(/_$/i),\"\");\nmyArr = myStr.split(\"_\");\n\nalert(\"myArr=\" + myArr.join(\",\"));\n var myArr = new Array(\"\",\"\",\"a\",\"b\",\"\",\"c\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"e\",\"\");\n\nmyArr = myArr.join(\"_\").replace(new RegExp(/__*/g),\"_\").replace(new RegExp(/^_/i),\"\").replace(new RegExp(/_$/i),\"\").split(\"_\");\n\nalert(\"myArr=\" + myArr.join(\",\"));\n Array.prototype.clean = function() {\n return this.join(\"_\").replace(new RegExp(/__*/g),\"_\").replace(new RegExp(/^_/i),\"\").replace(new RegExp(/_$/i),\"\").split(\"_\");\n};\n\nvar myArr = new Array(\"\",\"\",\"a\",\"b\",\"\",\"c\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"e\",\"\");\n\nalert(\"myArr=\" + myArr.clean().join(\",\"));\n" }, { "answer_id": 13587612, "author": "ELLIOTTCABLE", "author_id": 31897, "author_profile": "https://Stackoverflow.com/users/31897", "pm_score": 2, "selected": false, "text": "Array..filter() Object String Boolean Number filter() undefined true filter() undefined > [1,,5,6,772,5,24,5,'abc',function(){},1,5,,3].filter(function(){return true})\n[1, 5, 6, 772, 5, 24, 5, 'abc', function (){}, 1, 5, 3]\n ...(function(){return true;}) ...(Object) Object Object function(){return true} > [1,,5,6,772,5,24,5,'abc',function(){},1,5,,3].filter(Object)\n[1, 5, 6, 772, 5, 24, 5, 'abc', function (){}, 1, 5, 3]\n" }, { "answer_id": 13650939, "author": "c4urself", "author_id": 750979, "author_profile": "https://Stackoverflow.com/users/750979", "pm_score": 5, "selected": false, "text": "_.without(array, emptyVal, otherEmptyVal);\n_.without([1, 2, 1, 0, 3, 1, 4], 0, 1);\n _.without(['foo', 'bar', '', 'baz', '', '', 'foobar'], '');\n--> [\"foo\", \"bar\", \"baz\", \"foobar\"]\n" }, { "answer_id": 13798078, "author": "Andreas Louv", "author_id": 887539, "author_profile": "https://Stackoverflow.com/users/887539", "pm_score": 7, "selected": false, "text": "[1, false, \"\", undefined, 2].filter(Boolean); // [1, 2]\n _.filter([1, false, \"\", undefined, 2], Boolean); // [1, 2]\n// or even:\n_.compact([1, false, \"\", undefined, 2]); // [1, 2]\n" }, { "answer_id": 16752942, "author": "GameAlchemist", "author_id": 856501, "author_profile": "https://Stackoverflow.com/users/856501", "pm_score": 2, "selected": false, "text": "var removeNull = function() {\n var nullCount = 0 ;\n var length = this.length ;\n for (var i=0, len=this.length; i<len; i++) { if (!this[i]) {nullCount++} }\n // no item is null\n if (!nullCount) { return this}\n // all items are null\n if (nullCount == length) { this.length = 0; return this }\n // mix of null // non-null\n var idest=0, isrc=length-1;\n length -= nullCount ; \n while (true) {\n // find a non null (source) slot on the right\n while (!this[isrc]) { isrc--; nullCount--; } \n if (!nullCount) { break } // break if found all null\n // find one null slot on the left (destination)\n while ( this[idest]) { idest++ } \n // perform copy\n this[idest]=this[isrc];\n if (!(--nullCount)) {break}\n idest++; isrc --; \n }\n this.length=length; \n return this;\n}; \n\nObject.defineProperty(Array.prototype, 'removeNull', \n { value : removeNull, writable : true, configurable : true } ) ;\n" }, { "answer_id": 17474586, "author": "A. Zalonis", "author_id": 2455661, "author_profile": "https://Stackoverflow.com/users/2455661", "pm_score": -1, "selected": false, "text": "Array.prototype.ReplaceAllValues = function(OldValue,newValue)\n{\n for( var i = 0; i < this.length; i++ ) \n {\n if( this[i] == OldValue ) \n {\n this[i] = newValue;\n }\n }\n};\n" }, { "answer_id": 24671138, "author": "sqram", "author_id": 93026, "author_profile": "https://Stackoverflow.com/users/93026", "pm_score": 2, "selected": false, "text": "foo = [0, 1, 2, \"\", , false, 3, \"four\", null]\n\nfoo.filter(e => e === 0 ? true : e)\n [0, 1, 2, 3, \"four\"]\n foo.filter(e => e)\n" }, { "answer_id": 26497390, "author": "Goku Nymbus", "author_id": 2565512, "author_profile": "https://Stackoverflow.com/users/2565512", "pm_score": 2, "selected": false, "text": "var stringObject = [\"\", \"some string yay\", \"\", \"\", \"Other string yay\"];\nstringObject = stringObject.filter(function(n){ return n.length > 0});\n [\"some string yay\", \"Other string yay\"]\n" }, { "answer_id": 26589651, "author": "Nico Napoli", "author_id": 566697, "author_profile": "https://Stackoverflow.com/users/566697", "pm_score": -1, "selected": false, "text": "var arr = [\"a\", \"b\", undefined, undefined, \"e\", undefined, \"g\", undefined, \"i\", \"\", \"k\"]\nvar cleanArr = arr.join('.').split(/\\.+/);\n" }, { "answer_id": 26820396, "author": "Josh Bedo", "author_id": 509754, "author_profile": "https://Stackoverflow.com/users/509754", "pm_score": 4, "selected": false, "text": "_.without(array, *values); _.without([\"text\", \"string\", null, null, null, \"text\"], null)\n// => [\"text\", \"string\", \"text\"]\n" }, { "answer_id": 33089999, "author": "rpearce", "author_id": 680394, "author_profile": "https://Stackoverflow.com/users/680394", "pm_score": -1, "selected": false, "text": "Array.prototype.clean = function() {\n var args = [].slice.call(arguments);\n return this.filter(item => args.indexOf(item) === -1);\n};\n\n// Usage\nvar arr = [\"\", undefined, 3, \"yes\", undefined, undefined, \"\"];\narr.clean(undefined); // [\"\", 3, \"yes\", \"\"];\narr.clean(undefined, \"\"); // [3, \"yes\"];\n" }, { "answer_id": 34222552, "author": "VIJAY P", "author_id": 1936006, "author_profile": "https://Stackoverflow.com/users/1936006", "pm_score": 3, "selected": false, "text": "var arr = [0,1,2,\"test\",\"false\",false,true,null,3,4,undefined,5,\"end\"];\n\narr.filter((v) => (!!(v)==true));\n\n//output:\n\n//[1, 2, \"test\", \"false\", true, 3, 4, 5, \"end\"]\n" }, { "answer_id": 35947346, "author": "John Slegers", "author_id": 1946501, "author_profile": "https://Stackoverflow.com/users/1946501", "pm_score": 0, "selected": false, "text": "Array.prototype.filter() Array.prototype.filter() Array.prototype.filter() if (!Array.prototype.filter) {\n Array.prototype.filter = function(fun/*, thisArg*/) {\n 'use strict';\n if (this === void 0 || this === null) {\n throw new TypeError();\n }\n var t = Object(this);\n var len = t.length >>> 0;\n if (typeof fun !== 'function') {\n throw new TypeError();\n }\n var res = [];\n var thisArg = arguments.length >= 2 ? arguments[1] : void 0;\n for (var i = 0; i < len; i++) {\n if (i in t) {\n var val = t[i];\n if (fun.call(thisArg, val, i, t)) {\n res.push(val);\n }\n }\n }\n return res;\n };\n}\n" }, { "answer_id": 35988168, "author": "cluster1", "author_id": 2645857, "author_profile": "https://Stackoverflow.com/users/2645857", "pm_score": 1, "selected": false, "text": "// --- Example ----------\nvar field = [];\n\nfield[0] = 'One';\nfield[1] = 1;\nfield[3] = true;\nfield[5] = 43.68;\nfield[7] = 'theLastElement';\n// --- Example ----------\n\nvar originalLength;\n\n// Store the length of the array.\noriginalLength = field.length;\n\nfor (var i in field) {\n // Attach the truthy values upon the end of the array. \n field.push(field[i]);\n}\n\n// Delete the original range within the array so that\n// only the new elements are preserved.\nfield.splice(0, originalLength);\n" }, { "answer_id": 38359497, "author": "siddhant narang", "author_id": 5800860, "author_profile": "https://Stackoverflow.com/users/5800860", "pm_score": -1, "selected": false, "text": "// Removes all falsy values \narr = arr.filter(function(array_val) { // creates an anonymous filter func\n var x = Boolean(array_val); // checks if val is null\n return x == true; // returns val to array if not null\n });\n" }, { "answer_id": 40784002, "author": "Puni", "author_id": 5101585, "author_profile": "https://Stackoverflow.com/users/5101585", "pm_score": 0, "selected": false, "text": "var qwerty = {\n test1: null,\n test2: 'somestring',\n test3: 3,\n test4: {},\n test5: {\n foo: \"bar\"\n },\n test6: \"\",\n test7: undefined,\n test8: \" \",\n test9: true,\n test10: [],\n test11: [\"77\",\"88\"],\n test12: {\n foo: \"foo\",\n bar: {\n foo: \"q\",\n bar: {\n foo:4,\n bar:{}\n }\n },\n bob: {}\n }\n}\n\nvar asdfg = [,,\"\", \" \", \"yyyy\", 78, null, undefined,true, {}, {x:6}, [], [2,3,5]];\n\nfunction clean_data(obj) {\n for (var key in obj) {\n // Delete null, undefined, \"\", \" \"\n if (obj[key] === null || obj[key] === undefined || obj[key] === \"\" || obj[key] === \" \") {\n delete obj[key];\n }\n // Delete empty object\n // Note : typeof Array is also object\n if (typeof obj[key] === 'object' && Object.keys(obj[key]).length <= 0) {\n delete obj[key];\n }\n // If non empty object call function again\n if(typeof obj[key] === 'object'){\n clean_data(obj[key]);\n }\n }\n return obj;\n}\n\nvar objData = clean_data(qwerty);\nconsole.log(objData);\nvar arrayData = clean_data(asdfg);\nconsole.log(arrayData);\n null undefined \"\" \" \" empty object empty array" }, { "answer_id": 41430492, "author": "Trevor", "author_id": 2697942, "author_profile": "https://Stackoverflow.com/users/2697942", "pm_score": 0, "selected": false, "text": " function cleanArray(a, removeNull) {\n var i, l, temp = [];\n l = a.length;\n if (removeNull) {\n for (i = 0; i < l; i++) {\n if (a[i] !== undefined && a[i] !== null) {\n temp.push(a[i]);\n }\n }\n } else {\n for (i = 0; i < l; i++) {\n if (a[i] !== undefined) {\n temp.push(a[i]);\n }\n }\n }\n a.length = 0;\n l = temp.length;\n for (i = 0; i < l; i++) {\n a[i] = temp[i];\n }\n temp.length = 0;\n return a;\n }\n var myArray = [1, 2, , 3, , 3, , , 0, , null, false, , NaN, '', 4, , 4, , 5, , 6, , , , ];\n cleanArray(myArray);\n myArray;\n" }, { "answer_id": 42961952, "author": "ML13", "author_id": 4352178, "author_profile": "https://Stackoverflow.com/users/4352178", "pm_score": 5, "selected": false, "text": "['a','b','',,,'w','b'].filter(v => v);\n" }, { "answer_id": 43090968, "author": "KARTHIKEYAN.A", "author_id": 4652706, "author_profile": "https://Stackoverflow.com/users/4652706", "pm_score": 2, "selected": false, "text": "var data = [null, 1,2,3];\nvar r = data.filter(function(i){ return i != null; })\n console.log(r) \n" }, { "answer_id": 43109339, "author": "Sandeep M", "author_id": 3999929, "author_profile": "https://Stackoverflow.com/users/3999929", "pm_score": 1, "selected": false, "text": "var details = [\n {\n reference: 'ref-1',\n description: 'desc-1',\n price: 1\n }, {\n reference: '',\n description: '',\n price: ''\n }, {\n reference: 'ref-2',\n description: 'desc-2',\n price: 200\n }, {\n reference: 'ref-3',\n description: 'desc-3',\n price: 3\n }, {\n reference: '',\n description: '',\n price: ''\n }\n ];\n\n scope.removeEmptyDetails(details);\n expect(details.length).toEqual(3);\n scope.removeEmptyDetails = function(details){\n _.remove(details, function(detail){\n return (_.isEmpty(detail.reference) && _.isEmpty(detail.description) && _.isEmpty(detail.price));\n });\n };\n" }, { "answer_id": 47553243, "author": "KARTHIKEYAN.A", "author_id": 4652706, "author_profile": "https://Stackoverflow.com/users/4652706", "pm_score": 0, "selected": false, "text": "var s = [ '1,201,karthikeyan,K201,HELPER,karthikeyan.a@limitlessmobil.com,8248606269,7/14/2017,45680,TN-KAR24,8,800,1000,200,300,Karthikeyan,11/24/2017,Karthikeyan,11/24/2017,AVAILABLE\\r',\n '' ]\nvar newArr = s.filter(function(entry) { return entry.trim() != ''; })\n\nconsole.log(newArr); " }, { "answer_id": 48005993, "author": "Gapur Kassym", "author_id": 8179428, "author_profile": "https://Stackoverflow.com/users/8179428", "pm_score": 3, "selected": false, "text": "const array = [1, 32, 2, undefined, 3];\nconst newArray = array.filter(arr => arr);\n" }, { "answer_id": 48163228, "author": "tsh", "author_id": 2045384, "author_profile": "https://Stackoverflow.com/users/2045384", "pm_score": 7, "selected": false, "text": "arr.filter(() => true)\narr.flat(0) // New in ES2019\n arr.filter(x => x != null)\n arr.filter(x => x)\n arr = [, null, (void 0), 0, -0, 0n, NaN, false, '', 42];\nconsole.log(arr.filter(() => true)); // [null, (void 0), 0, -0, 0n, NaN, false, '', 42]\nconsole.log(arr.filter(x => x != null)); // [0, -0, 0n, NaN, false, \"\", 42]\nconsole.log(arr.filter(x => x)); // [42] arr = [, ,];\nconsole.log(arr[0], 0 in arr, arr.length); // undefined, false, 2; arr[0] is a hole\narr[42] = 42;\nconsole.log(arr[10], 10 in arr, arr.length); // undefined, false, 43; arr[10] is a hole\n\narr1 = [1, 2, 3];\narr1[0] = (void 0);\nconsole.log(arr1[0], 0 in arr1); // undefined, true; a[0] is undefined, not a hole\n\narr2 = [1, 2, 3];\ndelete arr2[0]; // NEVER do this please\nconsole.log(arr2[0], 0 in arr2, arr2.length); // undefined, false; a[0] is a hole\n arr = [1, 3, null, 4];\nfiltered = arr.filter(x => x != null);\nconsole.log(filtered); // [1, 3, 4]\nconsole.log(arr); // [1, 3, null, 4]; not modified\n" }, { "answer_id": 48899849, "author": "Jitendra virani", "author_id": 7646491, "author_profile": "https://Stackoverflow.com/users/7646491", "pm_score": 1, "selected": false, "text": "var data= { \n myAction: function(array){\n return array.filter(function(el){\n return (el !== (undefined || null || ''));\n }).join(\" \");\n }\n}; \nvar string = data.myAction([\"I\", \"am\",\"\", \"working\", \"\", \"on\",\"\", \"nodejs\", \"\" ]);\nconsole.log(string);\n" }, { "answer_id": 51264015, "author": "Kanan Farzali", "author_id": 2470558, "author_profile": "https://Stackoverflow.com/users/2470558", "pm_score": 5, "selected": false, "text": "let newArr = arr.filter(e => e);\n" }, { "answer_id": 52828995, "author": "AmerllicA", "author_id": 6877799, "author_profile": "https://Stackoverflow.com/users/6877799", "pm_score": 6, "selected": false, "text": "ES6+ const arr = [1,2,3,undefined,4,5,6,undefined,7,8,undefined,undefined,0,9];\n const clearArray = arr.filter(i => i); // [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]\n const clearArray = arr.filter(Boolean); // [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]\n 0 const notNil = (i) => !(typeof i === 'undefined' || i === null);\n\nconst clearArray = arr.filter(i => isNil(i));\n const arr = [1,2,3,undefined,4,5,6,undefined,7,8,undefined,undefined,0,9];\nconst notNil = (i) => !(typeof i === 'undefined' || i === null);\n\nconsole.log(\"Not nil: \", arr.filter(notNil));" }, { "answer_id": 56886122, "author": "Andrea Perdicchia", "author_id": 2285574, "author_profile": "https://Stackoverflow.com/users/2285574", "pm_score": -1, "selected": false, "text": "fees.map( ( e ) => e.avail ).filter( v => v!== '').map( i => parseInt( i ) );\n" }, { "answer_id": 57974884, "author": "bittnkr", "author_id": 9464885, "author_profile": "https://Stackoverflow.com/users/9464885", "pm_score": 0, "selected": false, "text": "function pack(arr) { // remove undefined values\n let p = -1\n for (let i = 0, len = arr.length; i < len; i++) {\n if (arr[i] !== undefined) { if (p >= 0) { arr[p] = arr[i]; p++ } }\n else if (p < 0) p = i\n }\n if (p >= 0) arr.length = p\n return arr\n}\n\nlet a = [1, 2, 3, undefined, undefined, 4, 5, undefined, null]\nconsole.log(JSON.stringify(a))\npack(a)\nconsole.log(JSON.stringify(a))\n" }, { "answer_id": 58968655, "author": "Trung", "author_id": 4038253, "author_profile": "https://Stackoverflow.com/users/4038253", "pm_score": -1, "selected": false, "text": "var a = [{a1: 1, children: [{a1: 2}, undefined, {a1: 3}]}, undefined, {a1: 5}, undefined, {a1: 6}]\nfunction removeNilItemInArray(arr) {\n if (!arr || !arr.length) return;\n for (let i = 0; i < arr.length; i++) {\n if (!arr[i]) {\n arr.splice(i , 1);\n continue;\n }\n removeNilItemInArray(arr[i].children);\n }\n}\nvar b = a;\nremoveNilItemInArray(a);\n// Always keep this memory zone\nconsole.log(b);\n" }, { "answer_id": 59905255, "author": "Zalom", "author_id": 3251051, "author_profile": "https://Stackoverflow.com/users/3251051", "pm_score": 2, "selected": false, "text": "const arr = [ [], ['not', 'empty'], {}, { key: 'value' }, 0, 1, null, 2, \"\", \"here\", \" \", 3, undefined, 3, , , , , , 4, , 4, , 5, , 6, , , ]\n\nlet filtered = JSON.stringify(\n arr.filter((obj) => {\n return ![null, undefined, ''].includes(obj)\n }).filter((el) => {\n return typeof el != \"object\" || Object.keys(el).length > 0\n })\n)\n\nconsole.log(JSON.parse(filtered)) const arr = [0, 1, null, 2, \"\", 3, undefined, 3, , , , , , 4, , 4, , 5, , 6, , , ,]\n\nlet filtered = arr.filter((obj) => { return ![null, undefined].includes(obj) })\n\nconsole.log(filtered) var arr = [0, 1, null, 2, \"\", 3, undefined, 3, , , , , , 4, , 4, , 5, , 6, , , ,]\n\nvar filtered = arr.filter(function (obj) { return ![null, undefined].includes(obj) })\n\nconsole.log(filtered)" }, { "answer_id": 61928808, "author": "Bhupesh Kumar", "author_id": 13379286, "author_profile": "https://Stackoverflow.com/users/13379286", "pm_score": 1, "selected": false, "text": "array.filter(String);" }, { "answer_id": 63564418, "author": "Kamil Kiełczewski", "author_id": 860099, "author_profile": "https://Stackoverflow.com/users/860099", "pm_score": 2, "selected": false, "text": "in let a = [1,,2,,,3];\nlet b = a.filter((x,i)=> i in a);\n\nconsole.log({a,b});" }, { "answer_id": 68562363, "author": "XDavidT", "author_id": 7340422, "author_profile": "https://Stackoverflow.com/users/7340422", "pm_score": 0, "selected": false, "text": "npm i clean-deep const cleanDeep = require('clean-deep');\nvar array = [0, 1, null, 2, \"\", 3, undefined, 3,,,,,, 4,, 4,, 5,, 6,,,,];\nconst filterd = cleanDeep(array);\nconsole.log(filterd);\n" }, { "answer_id": 68714483, "author": "user3328281", "author_id": 3328281, "author_profile": "https://Stackoverflow.com/users/3328281", "pm_score": 4, "selected": false, "text": "const array = [\n { name: \"tim\", age: 1 },\n undefined,\n { name: \"ewrfer\", age: 22 },\n { name: \"3tf5gh\", age: 56 },\n null,\n { name: \"kygm\", age: 19 },\n undefined,\n];\nconsole.log(array.filter(Boolean));" }, { "answer_id": 68852055, "author": "Ashish Rawat", "author_id": 2092405, "author_profile": "https://Stackoverflow.com/users/2092405", "pm_score": 2, "selected": false, "text": "{} [] NaN function removeNil(obj) {\n // recursively remove null and undefined from nested object too.\n return JSON.parse(JSON.stringify(obj), (k,v) => {\n if(v === null || v === '') return undefined;\n // convert date string to date.\n if (typeof v === \"string\" && /^\\d\\d\\d\\d-\\d\\d-\\d\\dT\\d\\d:\\d\\d:\\d\\d.\\d\\d\\dZ$/.test(v))\n return new Date(v);\n // remove empty array and object.\n if(typeof v === 'object' && !Object.keys(v).length) return undefined;\n return v;\n });\n }\n function removeNil(obj) {\n // recursively remove null and undefined from nested object too.\n return JSON.parse(JSON.stringify(obj), (k,v) => {\n if(v === null || v === '') return undefined;\n // convert date string to date.\n if (typeof v === \"string\" && /^\\d\\d\\d\\d-\\d\\d-\\d\\dT\\d\\d:\\d\\d:\\d\\d.\\d\\d\\dZ$/.test(v))\n return new Date(v);\n // remove empty array and object.\n if(typeof v === 'object' && !Object.keys(v).length) return undefined;\n return v;\n });\n }\n \n const ob = {\n s: 'a',\n b: 43,\n countries: [ 'a', 'b', 'c' ],\n l: null,\n n: { ks: 'a', efe: null, ce: '' },\n d: new Date(),\n nan: NaN,\n k: undefined,\n emptyO: {},\n emptyArr: [],\n }\n \n const output = removeNil(ob);\n \n console.log(output);\n console.log('Tests: ', ob.countries.length, typeof(ob.d))" }, { "answer_id": 70167528, "author": "hamza ahmad", "author_id": 11882053, "author_profile": "https://Stackoverflow.com/users/11882053", "pm_score": -1, "selected": false, "text": "// recursive implementation\nfunction compact(arr) {\n const compactArray = [];\n //base case \n if(!arr.length) return []\n if(typeof arr[0] !== \"undefined\" \n && arr[0]!==null && arr[0] !== \" \" && \n arr[0]!== false &&\n arr[0]!== 0){\n compactArray.push(arr[0]);\n }\n return compactArray.concat(compact(arr.slice(1)))\n }\n \n compact([1,0,false,null,undefined,\"banana\"])`\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/281264", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8954/" ]
281,275
<p>I have two STL containers that I want to merge, removing any elements that appear more than once. For example:</p> <pre><code>typedef std::list&lt;int&gt; container; container c1; container c2; c1.push_back(1); c1.push_back(2); c1.push_back(3); c2.push_back(2); c2.push_back(3); c2.push_back(4); container c3 = unique_merge(c1, c2); // c3 now contains the following 4 elements: // 1, 2, 3, 4 </code></pre> <p>std::unique seems to be for adjacent elements only, and in my case the containers could be in any order. I could do some <strong>std::set</strong> trickery I guess:</p> <pre><code>container unique_merge(const container&amp; c1, const container&amp; c2) { std::set&lt;container::value_type&gt; s; BOOST_FOREACH(const container::value_type&amp; val, c1) s.insert(val); BOOST_FOREACH(const container::value_type&amp; val, c2) s.insert(val); return container(s.begin(), s.end()); } </code></pre> <p>Is there a better way or have I missed something bleeding obvious?</p>
[ { "answer_id": 281296, "author": "Eclipse", "author_id": 8701, "author_profile": "https://Stackoverflow.com/users/8701", "pm_score": 4, "selected": true, "text": "set_union sort merge unique erase template <typename container>\ncontainer unique_merge(container c1, container c2)\n{\n std::sort(c1.begin(), c1.end());\n std::sort(c2.begin(), c2.end());\n container mergeTarget;\n std::merge(c1.begin(), c1.end(), c2.begin(), c2.end(), \n std::insert_iterator(mergeTarget, mergeTarget.end())\n );\n std::erase(\n std::unique(mergeTarget.begin(), mergeTarget.end()), \n mergeTarget.end()\n );\n\n return mergeTarget;\n}\n" }, { "answer_id": 281326, "author": "Chris Morley", "author_id": 36034, "author_profile": "https://Stackoverflow.com/users/36034", "pm_score": 2, "selected": false, "text": "container c(c1.begin(), c1.end());\nc.insert(c.end(), c2.begin(), c2.end());\nstd::sort(c.begin(), c.end());\nc.erase(std::unique(c.begin(), c.end()), c.end());\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/281275", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9236/" ]
281,276
<p>Here's an open ended question. I work on a lot of mssql files, and I like to have a date stamp on each. This is so I can know just by looking at the source of a stored procedure whether it's up to date or not.</p> <p>I'd like to have a shortcut autocomplete key, that, if i type say, d-tab-tab, I get the current date printed to the file. And yes, I am that lazy. :)</p> <p>So the question is:</p> <ol> <li>Is there any way of getting around this problem entirely?</li> <li>If not, how would you suggest solving it?</li> </ol> <p>Clever ideas welcome.</p>
[ { "answer_id": 281354, "author": "Alex B", "author_id": 6180, "author_profile": "https://Stackoverflow.com/users/6180", "pm_score": 0, "selected": false, "text": "$Date: $" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/281276", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40352/" ]
281,300
<p>I have a collection of items that the user needs to group/categorize in several ways. For the sake of an example, let's say it's a collection of cars and the user wants to categorize them in the following ways:</p> <ul> <li>Color (red, silver, blue, black, etc.)</li> <li>Body shape (hatch, sedan, coupe, stationwagon, etc.)</li> <li>Seats (2, 4, 5, 6, etc.)</li> <li>etc.</li> </ul> <p>Have you ever come across a particularly elegant way of doing this that allows the user full freedom to define their own categories and values?</p> <p>Obviously, there will many be trade-offs to make in any design. For example, a learnable design might not be efficient, and vice versa. Or some designs may be more demanding of real estate than others. And some will take significantly longer to develop than others.</p> <p>Regardless, if you've seen -- or designed -- a good pattern for this, I'd be interested to hear about it. If you have screenshots, all the better.</p> <p><strong>Attempt at clarification</strong>: tags are indeed a great way of categorizing things, but in all implmentations I've seen, there's only ever one level of tagging. The user doesn't generally get to define a category/property and the item's value <em>in that category</em>. To use the example above and StackOverflow's tagging, you'd tag a car as "blue", "sedan", "4", and so on. StackOverflow would have no inherent knowledge that an item couldn't be tagged as both "sedan" and "coupe".</p> <p>The interface I'm thinking of would need to know that kind of thing, so the user-defined attributes suggestion is more along the lines of what I'm thinking. I'm just keen to find a concrete example of how that kind of system could be elegantly implemented (in a desktop app, if that makes a difference).</p> <p>Is that any clearer? If not, leave a comment and I'll try to clarify again. :)</p>
[ { "answer_id": 281319, "author": "Bob", "author_id": 45, "author_profile": "https://Stackoverflow.com/users/45", "pm_score": 1, "selected": false, "text": "TagType { Color, Seats, BodyType, Seats }\nTabSubType { Color-Red, Color-Blue, Color-Green, Seats-2, Seats-4, ... }\n" }, { "answer_id": 282337, "author": "Ali Afshar", "author_id": 28380, "author_profile": "https://Stackoverflow.com/users/28380", "pm_score": 0, "selected": false, "text": "Car|Tagged_with|Red\nRed|Is_child_of|Colours\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/281300", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8705/" ]
281,323
<p>I am attempting to insert a copy of a row from one table into another table with the same schema, with the addition of one column (a timestamp) to provide a "history" of the first table in MS Sql Server 2005.</p> <p>So, my query, without the additional column would be:</p> <pre><code>"SELECT INTO [WebsiteHistory] FROM [Website]" </code></pre> <p>I want to populate the timestamp column as well, but am not sure how to best do this. I'd like to do something like:</p> <pre><code>"SELECT Website.*, '" + DateTime.Now.ToShortDateString() + "' INTO [WebsiteHistory] FROM [Website]" </code></pre> <p>But that shouldn't work, especially if the timestamp column is not the last one. Is there any way to do this?</p>
[ { "answer_id": 281336, "author": "Tomalak", "author_id": 18771, "author_profile": "https://Stackoverflow.com/users/18771", "pm_score": 5, "selected": true, "text": "INSERT\n WebsiteHistory\nSELECT\n *,\n GETDATE()\nFROM\n Website\nWHERE\n Id = @WebsiteId\n WebsiteHistory Website DATETIME INSERT\n WebsiteHistory\n (\n Id,\n Field1,\n Field2,\n Field3,\n Field4,\n ModifiedDate\n )\nSELECT\n Id,\n Field1,\n Field2,\n Field3,\n Field4,\n GETDATE()\nFROM\n Website\nWHERE\n Id = @WebsiteId\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/281323", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2327/" ]
281,334
<p>I have a UL that looks like this:</p> <pre><code>&lt;ul class="popular-pages"&gt; &lt;li&gt;&lt;a href="region/us/california/"&gt;California&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="region/us/michigan/"&gt;Michigan&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="region/us/missouri/"&gt;Missouri&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="region/us/new-york/"&gt;New York&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="region/us/oregon/"&gt;Oregon&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="region/us/oregon-washington/"&gt;Oregon; Washington&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="region/us/pennsylvania/"&gt;Pennsylvania&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="region/us/texas/"&gt;Texas&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="region/us/virginia/"&gt;Virginia&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="region/us/washington/"&gt;Washington&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; </code></pre> <p>And CSS that looks like this:</p> <pre><code>ul.popular-pages li a { display:block; float:left; border-right:1px solid #b0b0b0; border-bottom:1px solid #8d8d8d; padding:10px; background-color:#ebf4e0; margin:2px; color:#526d3f } ul.popular-pages li a:hover { text-decoration:none; border-left:1px solid #b0b0b0; border-top:1px solid #8d8d8d; border-right:none; border-bottom:none; } </code></pre> <p>So it's working fine in modern browsers, but it's looking like this in IE6. Any suggestions? <img src="https://thecleverest.com/Picture_26.png" alt="alt text"></p>
[ { "answer_id": 281360, "author": "Arief", "author_id": 34096, "author_profile": "https://Stackoverflow.com/users/34096", "pm_score": 0, "selected": false, "text": "*html ul.popular-pages li a { \n display:block; \n float:left; \n border-right:1px solid #b0b0b0; \n border-bottom:1px solid #8d8d8d; \n padding:10px; \n background-color:#ebf4e0; \n margin:2px; \n color:#526d3f \n}\n\n*html ul.popular-pages li a:hover { \n text-decoration:none; \n border-left:1px solid #b0b0b0; \n border-top:1px solid #8d8d8d; \n border-right:none; \n border-bottom:none;\n}\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/281334", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
281,339
<p>So for the second day in a row, someone has wiped out an entire table of data as opposed to the one row they were trying to delete because they didn't have the qualified where clause.</p> <p>I've been all up and down the mgmt studio options, but can't find a confirm option. I know other tools for other databases have it.</p>
[ { "answer_id": 281344, "author": "Galwegian", "author_id": 3201, "author_profile": "https://Stackoverflow.com/users/3201", "pm_score": 3, "selected": false, "text": "BEGIN TRANSACTION DELETE COMMIT ROLLBACK" }, { "answer_id": 281392, "author": "Dave DuPlantis", "author_id": 8174, "author_profile": "https://Stackoverflow.com/users/8174", "pm_score": 2, "selected": false, "text": "SET IMPLICIT_TRANSACTIONS" }, { "answer_id": 281805, "author": "HLGEM", "author_id": 9034, "author_profile": "https://Stackoverflow.com/users/9034", "pm_score": 2, "selected": false, "text": "delete a\n--select a.* from \nfrom table1 a \njoin table 2 b on a.id = b.id\nwhere b.somefield = 'test'\n" }, { "answer_id": 281833, "author": "Cade Roux", "author_id": 18255, "author_profile": "https://Stackoverflow.com/users/18255", "pm_score": 1, "selected": false, "text": "REVOKE" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/281339", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36614/" ]
281,350
<p>Our windows deliverable has different sets of config files and binary assets for different customers. Right now the configuring is done by hand before packaging and its error prone. What do you think of using branches for each customer, and having the package build/script automerge the customer's branch with trunk?</p> <p>I'm less concerned with scalability than I am of getting this automated ASAP.</p> <p>The entire packag contents is in SVN, but SVN branching and merging is so delicate that I don't trust it to work consistently when its automated. If you guys like the idea I might try to use git-svn for this, because it will hopefully make merging less delicate. We don't necessarily have to merge the assets, because they are organized so the installer can just skip inappropriate directory trees, but configuration is not so simple.</p>
[ { "answer_id": 281575, "author": "Brian Schmitt", "author_id": 30492, "author_profile": "https://Stackoverflow.com/users/30492", "pm_score": 0, "selected": false, "text": "#If FirstCustomer Then\n ' <code specific to the FirstCustomer version>.\n#ElseIf SecondCustomer Then\n ' <code specific to the SecondCustomer version>.\n#Else\n ' <code specific to other versions>.\n#End If\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/281350", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20003/" ]
281,363
<p>I am using WinCVS as client and CVSNT as my source control server. Some of the files I wanted to add to my CVS repo, were added as Unicode files. Now, I want to recommit the same as ANSI (aka ASCII) files. However, despite deleting the old files from the repo, every time I add the file with the same name, it automatically assigns Unicode encoding to the file. </p> <p>Is there a way out? Or in other words, can I change the encoding of a file, once it is added to CVS?</p>
[ { "answer_id": 281802, "author": "Ken Gentle", "author_id": 8709, "author_profile": "https://Stackoverflow.com/users/8709", "pm_score": 0, "selected": false, "text": "CVSNT CVS CVSNT CVSNT CVS Add Attic ,v cvs add" }, { "answer_id": 282726, "author": "Oliver Giesen", "author_id": 9784, "author_profile": "https://Stackoverflow.com/users/9784", "pm_score": 3, "selected": true, "text": "cvs update -kt cvs commit -f" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/281363", "https://Stackoverflow.com", "https://Stackoverflow.com/users/382974/" ]
281,365
<p>If I have the following code,</p> <pre><code>Foo *f = new Foo(); vector&lt;Foo*&gt; vect; vect.push_back(f); // do stuff vect.erase(f); </code></pre> <p>Did I create a memory leak? I guess so, but the word <em>erase</em> gives the feeling that it is deleting it. </p> <p>Writing this, I am wondering if it is not a mistake to put a pointer in a STL vector. What do you think?</p>
[ { "answer_id": 281385, "author": "Johannes Schaub - litb", "author_id": 34509, "author_profile": "https://Stackoverflow.com/users/34509", "pm_score": 4, "selected": true, "text": "{ \n boost::shared_ptr<foo> f(new foo);\n\n std::vector< boost::shared_ptr<foo> > v;\n v.push_back(f);\n v.erase(v.begin());\n} /* if the last copy of foo goes out of scope, the memory is automatically freed */\n std::shared_ptr std::unique_ptr<T> std::unique_ptr ptr_container" }, { "answer_id": 281423, "author": "Martin York", "author_id": 14065, "author_profile": "https://Stackoverflow.com/users/14065", "pm_score": 2, "selected": false, "text": "Foo *f = new Foo();\nboost::ptr_vector<Foo> vect;\nvect.push_back(f);\n// do stuff\nvect.erase(f);\n" }, { "answer_id": 281536, "author": "jalf", "author_id": 33213, "author_profile": "https://Stackoverflow.com/users/33213", "pm_score": 1, "selected": false, "text": "vector<Foo> vect;\nvect.push_back(Foo());\n// do stuff\nvect.erase(f);\n" }, { "answer_id": 283472, "author": "MSalters", "author_id": 15416, "author_profile": "https://Stackoverflow.com/users/15416", "pm_score": 2, "selected": false, "text": "std::vector<char const*> strings;\nstrings.push_back(\"hello\");\nstrings.push_back(\"world\");\n// .erase should not call delete, pointers are to literals\n\nstd::vector<int*> arrays;\nstrings.push_back(new int[10]);\nstrings.push_back(new int[20]);\n// .erase should call delete[] instead of delete\n\nstd::vector<unsigned char*> raw;\nstrings.push_back(malloc(1000));\nstrings.push_back(malloc(2000));\n// .erase should call free() instead of delete\n vector<T*>::erase T*" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/281365", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20986/" ]
281,372
<p>How do I set up a shell script to execute from the Mac OSX dock? It seems that simply creating a shortcut will open the file in my editor. Is there a flag I need to set somewhere to tell it to run instead of opening it for editing?</p>
[ { "answer_id": 281389, "author": "Jeremy", "author_id": 1114, "author_profile": "https://Stackoverflow.com/users/1114", "pm_score": 6, "selected": false, "text": "Example Example.app/Contents/MacOS/Example Example.app Contents/MacOS Example" }, { "answer_id": 281455, "author": "dbr", "author_id": 745, "author_profile": "https://Stackoverflow.com/users/745", "pm_score": 9, "selected": true, "text": "File > Save As /Applications" }, { "answer_id": 310183, "author": "Joe McMahon", "author_id": 39791, "author_profile": "https://Stackoverflow.com/users/39791", "pm_score": 3, "selected": false, "text": "do shell script \"/full/path/to/your/script -with 'all desired args'" }, { "answer_id": 8612176, "author": "CJoshDoll", "author_id": 1112817, "author_profile": "https://Stackoverflow.com/users/1112817", "pm_score": 3, "selected": false, "text": "mono \"/Volumes/Media/~Users/me/Software/keepass/keepass.exe\" do shell script \"sh /Volumes/Media/~Users/me/Software/StartKeepass.sh\" user name \"<enter username here>\" password \"<Enter password here>\" with administrator privileges do shell script \"sh ....\" user name \"<enter username here> password \"<enter password here>\" with administrative privileges" }, { "answer_id": 21048589, "author": "stiemannkj1", "author_id": 2880970, "author_profile": "https://Stackoverflow.com/users/2880970", "pm_score": 6, "selected": false, "text": "chmod +x your-shell-script.sh\n .app mv your-shell-script.sh your-shell-script.app\n .sh mv your-shell-script.app your-shell-script.sh\n exit 0" }, { "answer_id": 67275324, "author": "Sridhar Sarnobat", "author_id": 714112, "author_profile": "https://Stackoverflow.com/users/714112", "pm_score": 0, "selected": false, "text": "pip install mac-appify\n /opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/appify ~/bin/webex_start.sh ~/Desktop/webex.app\n" }, { "answer_id": 71604943, "author": "cahen", "author_id": 1967100, "author_profile": "https://Stackoverflow.com/users/1967100", "pm_score": 2, "selected": false, "text": "Automator File New Application Library Utilities Run Shell Script osascript -e 'tell app \"System Events\" to tell appearance preferences to set dark mode to not dark mode'\n File Save" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/281372", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5291/" ]
281,373
<p>I am looking for a query that will work on Sharepoint 2003 to show me all the documents created/touched by a given userID.</p> <p>I have found tables with the documents (Docs) and tables for users (UserInfo, UserData) but the relationship between seems a bit odd - there are 99,000 records in our userdata table, and 12,000 records in userinfo - we have 400 users!</p> <p>I suppose I was expecting a simple 1 to many relationship with a user table having 400 records and joining that to the documents table, but I see thats not the case.</p> <p>Any help would be appreciated.</p> <p>Edit: Thanks Bjorn, I have translated that query back to the Sharepoint 2003 structure:</p> <pre><code>select d.* from userinfo u join userdata d on u.tp_siteid = d.tp_siteid and u.tp_id = d.tp_author where u.tp_login = 'userid' and d.tp_iscurrent = 1 </code></pre> <p>This gets me a list of siteid/listid/tp_id's I'll have to see if I can trace those back to a filename / path. All: any additional help is still appreciated!</p>
[ { "answer_id": 283290, "author": "Bjørn Stærk", "author_id": 36164, "author_profile": "https://Stackoverflow.com/users/36164", "pm_score": 2, "selected": true, "text": "select d.* from userinfo u \njoin alluserdata d on u.tp_siteid = d.tp_siteid \nand u.tp_id = d.tp_author \nwhere u.tp_login = '[username]'\nand d.tp_iscurrentversion = 1\n" } ]
2008/11/11
[ "https://Stackoverflow.com/questions/281373", "https://Stackoverflow.com", "https://Stackoverflow.com/users/33186/" ]