qid
int64 4
19.1M
| question
stringlengths 18
48.3k
| answers
list | date
stringlengths 10
10
| metadata
list |
|---|---|---|---|---|
253,099
|
<p>I want to examine the contents of a <code>std::vector</code> in GDB, how do I do it? Let's say it's a <code>std::vector<int></code> for the sake of simplicity.</p>
|
[
{
"answer_id": 253101,
"author": "John Carter",
"author_id": 8331,
"author_profile": "https://Stackoverflow.com/users/8331",
"pm_score": 8,
"selected": false,
"text": "print *(myVector._M_impl._M_start)@myVector.size()\n print *(myVector._M_impl._M_start)@N\n myVector._M_impl._M_start \n print P@N\n p P@N\n"
},
{
"answer_id": 2123260,
"author": "Michał Oniszczuk",
"author_id": 257401,
"author_profile": "https://Stackoverflow.com/users/257401",
"pm_score": 7,
"selected": true,
"text": "(gdb) print myVector\n $1 = std::vector of length 3, capacity 4 = {10, 20, 30}\n"
},
{
"answer_id": 25499805,
"author": "badeip",
"author_id": 327721,
"author_profile": "https://Stackoverflow.com/users/327721",
"pm_score": 4,
"selected": false,
"text": "define print_vector\n if $argc == 2\n set $elem = $arg0.size()\n if $arg1 >= $arg0.size()\n printf \"Error, %s.size() = %d, printing last element:\\n\", \"$arg0\", $arg0.size()\n set $elem = $arg1 -1\n end\n print *($arg0._M_impl._M_start + $elem)@1\n else\n print *($arg0._M_impl._M_start)@$arg0.size()\n end\nend\n\ndocument print_vector\nDisplay vector contents\nUsage: print_vector VECTOR_NAME INDEX\nVECTOR_NAME is the name of the vector\nINDEX is an optional argument specifying the element to display\nend\n gdb) help print_vector\nDisplay vector contents\nUsage: print_vector VECTOR_NAME INDEX\nVECTOR_NAME is the name of the vector\nINDEX is an optional argument specifying the element to display\n (gdb) print_vector videoconfig_.entries 0\n$32 = {{subChannelId = 177 '\\261', sourceId = 0 '\\000', hasH264PayloadInfo = false, bitrate = 0, payloadType = 68 'D', maxFs = 0, maxMbps = 0, maxFps = 134, encoder = 0 '\\000', temporalLayers = 0 '\\000'}}\n"
},
{
"answer_id": 61823610,
"author": "Mike P",
"author_id": 201706,
"author_profile": "https://Stackoverflow.com/users/201706",
"pm_score": 0,
"selected": false,
"text": "p/x *(&vec[2])@4\n vec vec[2]"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253099",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8331/"
] |
253,121
|
<p>In CSS, you can specify the spacing between table cells using the border-spacing property of a table.</p>
<p>However, this results in uniform spacing between columns and rows, and I am finding more situations where the designs I am using call for gaps between rows, but not columns, or visa versa.</p>
<p>If I have a solid background, I can simulate spacing using borders the same colour as the background colour.</p>
<p>I could also make a div (for example) the first child of every table cell, and using either padding or margins to get the desired results, but that is a lot of extra markup just to accommodate the style.</p>
<p>Given that that the data I am displaying is tabular data, is there a sensible way to achieve this style using tables?</p>
|
[
{
"answer_id": 253126,
"author": "C. K. Young",
"author_id": 13,
"author_profile": "https://Stackoverflow.com/users/13",
"pm_score": 5,
"selected": true,
"text": "border-spacing border-spacing: 1px 2px;\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253121",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1577190/"
] |
253,125
|
<p>Does anyone know how I can add a class to the link rendered using the Html.RouteLink helper method in ASP.Net MVC, it has the htmlAttributes object as the last parameter which I assumed I would be able to use, but since class is obviously a reserved word, I cannot supply this as one of the properties on the object.</p>
|
[
{
"answer_id": 253180,
"author": "Hrvoje Hudo",
"author_id": 1407,
"author_profile": "https://Stackoverflow.com/users/1407",
"pm_score": 3,
"selected": false,
"text": "<%= Html.RouteLink(\"Default\", \"Default\",null, new { Class=\"css_class\"}) %>\n"
},
{
"answer_id": 253369,
"author": "Robert Dean",
"author_id": 3396,
"author_profile": "https://Stackoverflow.com/users/3396",
"pm_score": 6,
"selected": true,
"text": "<%= Html.RouteLink(\"Default\", \"Default\",null, new { @class=\"css_class\"}) %>\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253125",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5160/"
] |
253,138
|
<p>Having a bit of trouble with the syntax where we want to call a delegate anonymously within a Control.Invoke.</p>
<p>We have tried a number of different approaches, all to no avail.</p>
<p>For example:</p>
<pre><code>myControl.Invoke(delegate() { MyMethod(this, new MyEventArgs(someParameter)); });
</code></pre>
<p>where someParameter is local to this method</p>
<p>The above will result in a compiler error:</p>
<blockquote>
<p>Cannot convert anonymous method to type 'System.Delegate' because it is not a delegate type</p>
</blockquote>
|
[
{
"answer_id": 253148,
"author": "François",
"author_id": 32379,
"author_profile": "https://Stackoverflow.com/users/32379",
"pm_score": 4,
"selected": false,
"text": "myControl.Invoke(new MethodInvoker(delegate() {...}))\n"
},
{
"answer_id": 253149,
"author": "Jelon",
"author_id": 2326,
"author_profile": "https://Stackoverflow.com/users/2326",
"pm_score": 4,
"selected": false,
"text": "myControl.Invoke(new MethodInvoker(delegate() { (MyMethod(this, new MyEventArgs(someParameter)); }));\n"
},
{
"answer_id": 253150,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 9,
"selected": true,
"text": "Invoke BeginInvoke Delegate MethodInvoker Action control.Invoke((MethodInvoker) delegate {this.Text = \"Hi\";});\n string message = \"Hi\";\ncontrol.Invoke((MethodInvoker) delegate {this.Text = message;});\n public static void Invoke(this Control control, Action action)\n{\n control.Invoke((Delegate)action);\n}\n this.Invoke(delegate { this.Text = \"hi\"; });\n// or since we are using C# 3.0\nthis.Invoke(() => { this.Text = \"hi\"; });\n BeginInvoke public static void BeginInvoke(this Control control, Action action)\n{\n control.BeginInvoke((Delegate)action);\n}\n Form"
},
{
"answer_id": 253158,
"author": "Vokinneberg",
"author_id": 208062,
"author_profile": "https://Stackoverflow.com/users/208062",
"pm_score": 6,
"selected": false,
"text": "control.Invoke((MethodInvoker)(() => {this.Text = \"Hi\"; }));\n"
},
{
"answer_id": 285604,
"author": "Rory",
"author_id": 8479,
"author_profile": "https://Stackoverflow.com/users/8479",
"pm_score": 3,
"selected": false,
"text": " // Create delegates for the different return types needed.\n private delegate void VoidDelegate();\n private delegate Boolean ReturnBooleanDelegate();\n private delegate Hashtable ReturnHashtableDelegate();\n\n // Now use the delegates and the delegate() keyword to create \n // an anonymous method as required\n\n // Here a case where there's no value returned:\n public void SetTitle(string title)\n {\n myWindow.Invoke(new VoidDelegate(delegate()\n {\n myWindow.Text = title;\n }));\n }\n\n // Here's an example of a value being returned\n public Hashtable CurrentlyLoadedDocs()\n {\n return (Hashtable)myWindow.Invoke(new ReturnHashtableDelegate(delegate()\n {\n return myWindow.CurrentlyLoadedDocs;\n }));\n }\n"
},
{
"answer_id": 4494513,
"author": "mhamrah",
"author_id": 30881,
"author_profile": "https://Stackoverflow.com/users/30881",
"pm_score": 3,
"selected": false,
"text": "//Process is a method, invoked as a method group\nDispatcher.Current.BeginInvoke((Action) Process);\n//or use an anonymous method\nDispatcher.Current.BeginInvoke((Action)delegate => {\n SomeFunc();\n SomeOtherFunc();\n});\n"
},
{
"answer_id": 52291769,
"author": "Jürgen Steinblock",
"author_id": 98491,
"author_profile": "https://Stackoverflow.com/users/98491",
"pm_score": 0,
"selected": false,
"text": "public static class ControlExtensions\n{\n public static void Invoke(this Control control, Action action)\n {\n control.Invoke(action);\n }\n}\n Control.Invoke public static class ControlExtensions\n{\n public static void Invoke(this Control control, Action action)\n {\n try\n {\n if (!control.IsDisposed) control.Invoke(action);\n }\n catch (ObjectDisposedException) { }\n }\n}\n"
},
{
"answer_id": 61158066,
"author": "Du D.",
"author_id": 1302259,
"author_profile": "https://Stackoverflow.com/users/1302259",
"pm_score": 1,
"selected": false,
"text": "Invoke((Action)(() => {\n DoSomething();\n}));\n\n// OR\n\nInvoke((Action)delegate {\n DoSomething();\n});\n // Thread-safe update on a form control\npublic void DisplayResult(string text){\n if (txtResult.InvokeRequired){\n txtResult.Invoke((Action)delegate {\n DisplayResult(text);\n });\n return;\n }\n\n txtResult.Text += text + \"\\r\\n\";\n}\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253138",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7140/"
] |
253,142
|
<p>I'd like to post some form variables into a classic ASP page. I don't want to have to alter the classic ASP pages, because of the amount of work that would need to be done, and the amount of pages that consume them.</p>
<p>The classic ASP page expects form variables Username and Userpassword to be submitted to them.</p>
<pre><code>username = Request.Form("UserName")
userpassword = Request.Form("Userpassword")
</code></pre>
<p>It then performs various actions and sets up sessions, going into an ASP application.</p>
<p>I want to submit these variables into the page from ASP.NET, but the login control is nested inside usercontrols and templates, so I can't get the form element's names to be "username" and "UserPassword".</p>
<p>Any ideas?</p>
|
[
{
"answer_id": 253195,
"author": "digiguru",
"author_id": 5055,
"author_profile": "https://Stackoverflow.com/users/5055",
"pm_score": 0,
"selected": false,
"text": "public class RemotePost{\n private System.Collections.Specialized.NameValueCollection Inputs \n = new System.Collections.Specialized.NameValueCollection() ;\n\n public string Url = \"\" ;\n public string Method = \"post\" ;\n public string FormName = \"form1\" ;\n\n public void Add( string name, string value ){\n Inputs.Add(name, value ) ;\n }\n\n public void Post(){\n System.Web.HttpContext.Current.Response.Clear() ;\n\n System.Web.HttpContext.Current.Response.Write( \"<html><head>\" ) ;\n\n System.Web.HttpContext.Current.Response.Write( string .Format( \"</head><body onload=\\\"document.{0}.submit()\\\">\" ,FormName)) ;\n\n System.Web.HttpContext.Current.Response.Write( string .Format( \"<form name=\\\"{0}\\\" method=\\\"{1}\\\" action=\\\"{2}\\\" >\" ,\n\n FormName,Method,Url)) ;\n for ( int i = 0 ; i< Inputs.Keys.Count ; i++){\n System.Web.HttpContext.Current.Response.Write( string .Format( \"<input name=\\\"{0}\\\" type=\\\"hidden\\\" value=\\\"{1}\\\">\" ,Inputs.Keys[i],Inputs[Inputs.Keys[i]])) ;\n }\n System.Web.HttpContext.Current.Response.Write( \"</form>\" ) ;\n System.Web.HttpContext.Current.Response.Write( \"</body></html>\" ) ;\n System.Web.HttpContext.Current.Response.End() ;\n }\n} \n"
},
{
"answer_id": 253474,
"author": "HectorMac",
"author_id": 1400,
"author_profile": "https://Stackoverflow.com/users/1400",
"pm_score": 1,
"selected": false,
"text": "<input type=\"text\" name=\"UserName\" />\n\n<input type=\"password\" name=\"Userpassword\" />\n\n<asp:Button ID=\"btnLogin\" runat=\"server\" PostBackUrl=\"Destination.asp\" />\n"
},
{
"answer_id": 256140,
"author": "sliderhouserules",
"author_id": 31385,
"author_profile": "https://Stackoverflow.com/users/31385",
"pm_score": 3,
"selected": true,
"text": "public class RemotePost{\n private System.Collections.Specialized.NameValueCollection Inputs \n = new System.Collections.Specialized.NameValueCollection() ;\n\n public string Url = \"\" ;\n public string Method = \"post\" ;\n public string FormName = \"form1\" ;\n\n public void Add( string name, string value ){\n Inputs.Add(name, value ) ;\n }\n\n public void Post(){\n System.Web.HttpContext.Current.Response.Clear() ;\n\n System.Web.HttpContext.Current.Response.Write( \"<html><head>\" ) ;\n\n System.Web.HttpContext.Current.Response.Write( string .Format( \"</head><body onload=\\\"document.{0}.submit()\\\">\" ,FormName)) ;\n\n System.Web.HttpContext.Current.Response.Write( string .Format( \"<form name=\\\"{0}\\\" method=\\\"{1}\\\" action=\\\"{2}\\\" >\" ,\n\n FormName,Method,Url)) ;\n for ( int i = 0 ; i< Inputs.Keys.Count ; i++){\n System.Web.HttpContext.Current.Response.Write( string .Format( \"<input name=\\\"{0}\\\" type=\\\"hidden\\\" value=\\\"{1}\\\">\" ,Inputs.Keys[i],Inputs[Inputs.Keys[i]])) ;\n }\n System.Web.HttpContext.Current.Response.Write( \"</form>\" ) ;\n System.Web.HttpContext.Current.Response.Write( \"</body></html>\" ) ;\n System.Web.HttpContext.Current.Response.End() ;\n }\n}\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253142",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5055/"
] |
253,157
|
<p>Is there a way to resize a <code>std::vector</code> to lower capacity when I no longer need previously reserved space?</p>
|
[
{
"answer_id": 253173,
"author": "Sébastien RoccaSerra",
"author_id": 2797,
"author_profile": "https://Stackoverflow.com/users/2797",
"pm_score": 7,
"selected": true,
"text": "swap vector<Person>(persons).swap(persons);\n persons vector"
},
{
"answer_id": 9525865,
"author": "Alex Korban",
"author_id": 221619,
"author_profile": "https://Stackoverflow.com/users/221619",
"pm_score": 4,
"selected": false,
"text": "vec.shrink_to_fit()"
},
{
"answer_id": 20092836,
"author": "jimifiki",
"author_id": 512225,
"author_profile": "https://Stackoverflow.com/users/512225",
"pm_score": 2,
"selected": false,
"text": "vector<Person>(persons).swap(persons);\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253157",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23766/"
] |
253,170
|
<p>I'm addicted to Vim, it's now my de facto way of editing text files.</p>
<p>Being that it's mainly a text editor and not an IDE, has anyone got tricks for me to make it easier when developing Java apps?</p>
<p>Some questions I have:</p>
<ul>
<li>How do I invoke a maven task without leaving vi?</li>
<li>Can I get code completion?</li>
<li>How's the syntax highlighting?</li>
</ul>
<p>Anything else (other than "Don't do it!") that I should know about?</p>
|
[
{
"answer_id": 257276,
"author": "ngn",
"author_id": 23109,
"author_profile": "https://Stackoverflow.com/users/23109",
"pm_score": 5,
"selected": false,
"text": ":!mvn :set makeprg=mvn :make <C-n> <C-p> bsh"
},
{
"answer_id": 836623,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 5,
"selected": false,
"text": ":set path=**\n:chdir your/project/root\n ^wf"
},
{
"answer_id": 15150020,
"author": "critium",
"author_id": 404238,
"author_profile": "https://Stackoverflow.com/users/404238",
"pm_score": 3,
"selected": false,
"text": "autocmd Filetype java setl makeprg=play_compile\nautocmd Filetype java setl efm=%A\\ %#[error]\\ %f:%l:\\ %m,%-Z\\ %#[error]\\ %p^,%-C%.%#\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253170",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2443/"
] |
253,178
|
<p>I'm developing my first Word 2007 addin, and I've added an OfficeRibbon to my project. In a button-click handler, I'd like a reference to either the current <code>Word.Document</code> or <code>Word.Application</code>.</p>
<p>I'm trying to get a reference via the <code>OfficeRibbon.Context</code> property, which the documentation says should refer to the current <code>Application</code> object. However, it is always <code>null</code>.</p>
<p>Does anyone know either</p>
<p>a) if there is something I need to do to make <code>OfficeRibbon.Context</code> appear correctly populated?<br>
b) if there is some other way I can get a reference to the Word Application or active Word Document?</p>
<p>Notes:</p>
<ul>
<li><p>I'm using VS2008 SP1</p></li>
<li><p>The ribbon looks like it has initialized fine: The ribbon renders correctly in Word; I can step the debugger through both the constructor and the OnLoad members; Button click handlers execute correctly. </p></li>
<li><p>Here's <a href="http://msdn.microsoft.com/en-us/library/microsoft.office.tools.ribbon.officeribbon.context.aspx?ppud=4" rel="nofollow noreferrer">the online help for this property</a>; </p></li>
</ul>
<blockquote>
<p><strong>OfficeRibbon.Context Property</strong></p>
<p><code>C#</code><br>
<code>public Object Context { get; internal set; }</code></p>
<p>An Object that represents the Inspector window or application instance that is associated with this OfficeRibbon object. </p>
<p><strong>Remarks</strong></p>
<p>In Outlook, this property refers to the Inspector window in which this OfficeRibbon is displayed.</p>
<p>In Excel, Word, and PowerPoint, this property returns the application instance in which this OfficeRibbon is displayed. </p>
</blockquote>
|
[
{
"answer_id": 895455,
"author": "Joseph Sturtevant",
"author_id": 317,
"author_profile": "https://Stackoverflow.com/users/317",
"pm_score": 3,
"selected": true,
"text": "internal static public partial class ThisAddIn\n{\n internal static Application Context { get; private set; }\n\n private void ThisAddIn_Startup(object sender, System.EventArgs e)\n {\n Context = Application;\n }\n ...\n}\n\npublic partial class MyRibbon : OfficeRibbon\n{\n private void button1_Click(object sender, RibbonControlEventArgs e)\n {\n DoStuffWithApplication(ThisAddIn.Context);\n }\n ...\n}\n"
},
{
"answer_id": 896622,
"author": "Michael Regan",
"author_id": 1027,
"author_profile": "https://Stackoverflow.com/users/1027",
"pm_score": 2,
"selected": false,
"text": "Globals.ThisDocument.[some item]\n"
},
{
"answer_id": 11023497,
"author": "Lukas Winzenried",
"author_id": 937411,
"author_profile": "https://Stackoverflow.com/users/937411",
"pm_score": 2,
"selected": false,
"text": "Globals.ThisAddIn.Application"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253178",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6722/"
] |
253,179
|
<p>I am starting new project with SqlServer and Linq to Sql.
What data type would be better for surrogate keys in tables: <code>identity</code> or <code>uniqueidentifier</code> ?</p>
<p>As I understood, <code>identity</code> is automatically generated on insert, while <code>uniqueidentifier</code> should be generated in code (GUID). </p>
<p>Are there any significant performance differences?
e.g. <code>identity</code> value must be read after insert, so there is extra database trip after insert. </p>
<p><strong>Edit:</strong><br>
I found very detailed answer in another question: <a href="https://stackoverflow.com/questions/5600/tables-with-no-primary-key">Tables with no primary keys</a>. Read selected answer.</p>
<p><strong>Edit 2:</strong><br>
<em>Regarding answers about surrogate keys: I like surrogate keys more than natural keys. That decision is done, so please do not suggest to reconsider database design. Also, please, do not discuss pros and cons of natural and surrogate keys.</em></p>
|
[
{
"answer_id": 253199,
"author": "James Curran",
"author_id": 12725,
"author_profile": "https://Stackoverflow.com/users/12725",
"pm_score": 0,
"selected": false,
"text": "uniqueidentifier NEWID()"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253179",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25732/"
] |
253,198
|
<p>What is the best way to send e-mail using outlook express from the command line? It has to be an automated operation with no user interaction. There will be some .jpg files in attachment.
Thanks.</p>
|
[
{
"answer_id": 254845,
"author": "PabloG",
"author_id": 394,
"author_profile": "https://Stackoverflow.com/users/394",
"pm_score": 0,
"selected": false,
"text": "; Send a mail vía outlook \"automation\"\n\n$sRcpt = \"test@test.com\"\n$sSubj = \"Test subject\"\n$sBody = \"This is a test\"\n$sAttach = \"g:\\AutoIt\\AnHoras.PRG\"\n\nIf Not WinActivate (\"[REGEXPTITLE:.*\\- Outlook Express]\") Then\n RunWait (\"d:\\Archivos de programa\\Outlook Express\\msimn.exe\") ; Set your path to the Outlook .exe\nEndif\n\nSend (\"!anm\") ; Archivo->Nuevo->Mensaje (in spanish, sorry, I suppose that in english it will be File->New->Message)\nSend ($sRcpt & \"{Tab 3}\")\nSend ($sSubj & \"{Tab}\")\nSend ($sBody)\n\nIf $sAttach <> \"\" Then\n Send (\"!i{Enter}\" & $sAttach & \"{Enter}\") ; Insertar adjunto (Insert->Attachment)\nEndIf\n\nSend (\"!a{Down}{Enter}\") ; Archivo->Enviar mensaje (File->Send message)\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253198",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3221/"
] |
253,211
|
<p>I'm working on a C# library which offloads certain work tasks to the GPU using NVIDIA's CUDA. An example of this is adding two arrays together using extension methods:</p>
<pre><code>float[] a = new float[]{ ... }
float[] b = new float[]{ ... }
float[] c = a.Add(b);
</code></pre>
<p>The work in this code is done on the GPU. However, I would like it to be done asynchronously such that only when the result is needed will the code running on the CPU block (if the result is not finished on the GPU yet). To do this I've created an ExecutionResult class which hides the asynchronous execution. In use this looks as follows:</p>
<pre><code>float[] a = new float[]{ ... }
float[] b = new float[]{ ... }
ExecutionResult res = a.Add(b);
float[] c = res; //Implicit converter
</code></pre>
<p>At the last line the program blocks if the data is done ready yet. I'm not certain of the best way to implement this blocking behavior inside the ExecutionResult class as I'm not very experienced with synchronizing threads and those sorts of things.</p>
<pre><code>public class ExecutionResult<T>
{
private T[] result;
private long computed = 0;
internal ExecutionResult(T[] a, T[] b, Action<T[], T[], Action<T[]>> f)
{
f(a, b, UpdateData); //Asych call - 'UpdateData' is the callback method
}
internal void UpdateData(T[] data)
{
if (Interlocked.Read(ref computed) == 0)
{
result = data;
Interlocked.Exchange(ref computed, 1);
}
}
public static implicit operator T[](ExecutionResult<T> r)
{
//This is obviously a stupid way to do it
while (Interlocked.Read(ref r.computed) == 0)
{
Thread.Sleep(1);
}
return result;
}
}
</code></pre>
<p>The Action passed to the constructor is an asynchronous method which performs the actual work on the GPU. The nested Action is the asynchronous callback method.</p>
<p>My main concern is how to best/most elegantly handle the waiting done in the converter but also if there are more appropriate ways to attack the problem as a whole. Just leave a comment if there is something I need to elaborate or explain further.</p>
|
[
{
"answer_id": 253214,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 1,
"selected": false,
"text": "Delegate.BeginInvoke Delegate.EndInvoke ManualResetEvent using System.Threading;\nstatic class Program {\n static void Main()\n {\n ThreadPool.QueueUserWorkItem(DoWork);\n\n System.Console.WriteLine(\"Main: waiting\");\n wait.WaitOne();\n System.Console.WriteLine(\"Main: done\");\n }\n static void DoWork(object state)\n {\n System.Console.WriteLine(\"DoWork: working\");\n Thread.Sleep(5000); // simulate work\n System.Console.WriteLine(\"DoWork: done\");\n wait.Set();\n }\n static readonly ManualResetEvent wait = new ManualResetEvent(false);\n\n}\n using System.Threading;\nstatic class Program {\n static void Main()\n {\n object syncObj = new object();\n lock (syncObj)\n {\n ThreadPool.QueueUserWorkItem(DoWork, syncObj);\n\n System.Console.WriteLine(\"Main: waiting\");\n Monitor.Wait(syncObj);\n System.Console.WriteLine(\"Main: done\");\n }\n }\n static void DoWork(object syncObj)\n {\n\n System.Console.WriteLine(\"DoWork: working\");\n Thread.Sleep(5000); // simulate work\n System.Console.WriteLine(\"DoWork: done\");\n lock (syncObj)\n {\n Monitor.Pulse(syncObj);\n }\n }\n\n}\n"
},
{
"answer_id": 258281,
"author": "Morten Christiansen",
"author_id": 4055,
"author_profile": "https://Stackoverflow.com/users/4055",
"pm_score": 2,
"selected": false,
"text": "private Func<T[]> getResult;\n\ninternal ExecutionResult(T[] a, T[] b, Func<T[], T[], Func<T[]>> asynchBinaryFunction)\n{\n getResult = asynchUnaryFunction(a);\n}\n\npublic static implicit operator T[](ExecutionResult<T> r)\n{\n return r.getResult();\n}\n ...\n\n status = LaunchGrid(func, length);\n\n //Fetch result\n float[] c = new float[length];\n status = CUDADriver.cuMemcpyDtoH(c, ptrA, byteSize);\n status = Free(ptrA, ptrB);\n\n return c;\n}\n ...\n\n status = LaunchGrid(func, length);\n\n return delegate\n {\n float[] c = new float[length];\n CUDADriver.cuMemcpyDtoH(c, ptrA, byteSize); //Blocks until work is done\n Free(ptrA, ptrB);\n return c;\n };\n}\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253211",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4055/"
] |
253,212
|
<p>How are assertions done in c++? Example code is appreciated.</p>
|
[
{
"answer_id": 253219,
"author": "Pieter",
"author_id": 5822,
"author_profile": "https://Stackoverflow.com/users/5822",
"pm_score": 3,
"selected": false,
"text": "void some_function(int age)\n{\n assert(age > 0);\n}\n"
},
{
"answer_id": 253223,
"author": "andygeers",
"author_id": 4397,
"author_profile": "https://Stackoverflow.com/users/4397",
"pm_score": 6,
"selected": true,
"text": "#include <assert.h>\n\nvoid function(int* pointer_arg)\n{\n assert(pointer_arg != NULL);\n\n ...\n}\n assert(a++ == 5);\n assert((a == 5) && \"a has the wrong value!!\");\n"
},
{
"answer_id": 253224,
"author": "Onorio Catenacci",
"author_id": 2820,
"author_profile": "https://Stackoverflow.com/users/2820",
"pm_score": 0,
"selected": false,
"text": "mypointer->myfunct();\n"
},
{
"answer_id": 253227,
"author": "SmacL",
"author_id": 22564,
"author_profile": "https://Stackoverflow.com/users/22564",
"pm_score": 3,
"selected": false,
"text": "// Given customer and product details for a sale, generate an invoice\n\nInvoice ProcessOrder(Customer Cust,Product Prod)\n{\n assert(IsValid(Cust));\n assert(IsValid(Prod);\n'\n'\n'\n assert(IsValid(RetInvoice))\n return(RetInvoice);\n\n}\n extern void _my_assert(void *, void *, unsigned);\n\n#define myassert(exp) \\\n{ \\\n if (InDiagnostics) \\\n if ( !(exp) ) \\\n _my_assert(#exp, __FILE__, __LINE__); \\\n} \\\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253212",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22076/"
] |
253,226
|
<p>I have an interface - here's a nicely contrived version as an example:</p>
<pre><code>public interface Particle {
enum Charge {
POSITIVE, NEGATIVE
}
Charge getCharge();
double getMass();
etc...
}
</code></pre>
<p>Is there any difference in how implementations of this would behave if I defined the <code>Charge</code> enum as static - i.e. does this have any effect:</p>
<pre><code>public interface Particle {
static enum Charge {
POSITIVE, NEGATIVE
}
Charge getCharge();
double getMass();
etc...
}
</code></pre>
|
[
{
"answer_id": 253239,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 5,
"selected": false,
"text": "static public"
},
{
"answer_id": 253282,
"author": "idrosid",
"author_id": 17876,
"author_profile": "https://Stackoverflow.com/users/17876",
"pm_score": 7,
"selected": true,
"text": "public class A {\n enum E {A,B};\n}\n\npublic class A {\n static enum E {A,B};\n}\n public class A {\n private static enum E {A,B}\n}\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253226",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1853/"
] |
253,242
|
<p>I have a query where i have a date column (time) which tells about "IN" & "OUT" timing of the people attendance by this single column</p>
<p>My queries are :-</p>
<p>1) How to get the daily attendance of each employee
2) How to come to know if the employee is present less than 5 hours</p>
<p>Please let me know the queries in SQL server.</p>
|
[
{
"answer_id": 253249,
"author": "splattne",
"author_id": 6461,
"author_profile": "https://Stackoverflow.com/users/6461",
"pm_score": 0,
"selected": false,
"text": " select \n datediff(minute, TimeFrom, TimeTo) as AttendedTimeInMinutes,\n case when datediff(minute, sTimeFrom, sTimeTo) < 5 * 60 \n then \n 'less than 5 hours' \n else '5 hours or more' \n end\n from YourTable\n"
},
{
"answer_id": 253250,
"author": "Rune Grimstad",
"author_id": 30366,
"author_profile": "https://Stackoverflow.com/users/30366",
"pm_score": 0,
"selected": false,
"text": "SELECT Datepart(hour, dateTimeEnd - dateTimeStart)\n"
},
{
"answer_id": 253310,
"author": "Unsliced",
"author_id": 2902,
"author_profile": "https://Stackoverflow.com/users/2902",
"pm_score": 1,
"selected": false,
"text": "declare @users table (\n UserId int, \n DateColumn datetime\n)\n\ninsert into @users values (1, '2008-10-31 15:15') \ninsert into @users values (1, '2008-10-31 10:30') \ninsert into @users values (1, '2008-10-30 16:15') \ninsert into @users values (1, '2008-10-30 10:30') \n\nselect\n UserID\n , cast(dt as datetime) dt\n , [in]\n , [out]\n , case when datepart(hour, [out]-[in]) >= 5 then 'yes' else 'no' end [5Hours?], \n , cast(datediff(minute, [in], [out]) as float)/60 [hours] \nfrom (\n select\n UserID\n , convert(varchar, DateColumn, 112) dt\n , min(DateColumn) [in]\n , max(DateColumn) [out] \n from @users \n group by \n UserID, convert(varchar, DateColumn, 112) \n ) a \n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253242",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
253,247
|
<p>I have an animation that I'm displaying using a UIImageView:</p>
<pre><code>imageView.animationImages = myImages;
imageView.animationDuration = 3;
[imageView startAnimating];
</code></pre>
<p>I know I can stop it using stopAnimating, but what I want is to be able to pause it. The reason is that when you call stop, none of your animation images are displayed, whereas I would like the last one that is up at the time when I hit a button to stay up.</p>
<p>I have tried setting the duration to a much larger number, but that causes all the images to disappear as well. There must be a really basic way to do this?</p>
|
[
{
"answer_id": 255109,
"author": "rustyshelf",
"author_id": 6044,
"author_profile": "https://Stackoverflow.com/users/6044",
"pm_score": 4,
"selected": true,
"text": "UIView UIImageView subview NSTimer"
},
{
"answer_id": 624980,
"author": "mazniak",
"author_id": 42523,
"author_profile": "https://Stackoverflow.com/users/42523",
"pm_score": 4,
"selected": false,
"text": "UIView *viewBeingAnimated = //your view that is being animated\nviewBeingAnimated.frame = [[viewBeingAnimated.layer presentationLayer] frame];\n[viewBeingAnimated.layer removeAllAnimations];\n//when user unpauses, create new animation from current position.\n"
},
{
"answer_id": 1628560,
"author": "oddmeter",
"author_id": 166365,
"author_profile": "https://Stackoverflow.com/users/166365",
"pm_score": 0,
"selected": false,
"text": "animationImages UIImageView UIImageView NSMutableArray self.animationImages = images;\n//yes, I'm skipping the step to check and make sure you have at least one\n//element in your array\nself.image = [images objectAtIndex: 0];\n"
},
{
"answer_id": 9241109,
"author": "SW_Cali",
"author_id": 838813,
"author_profile": "https://Stackoverflow.com/users/838813",
"pm_score": 2,
"selected": false,
"text": " animatedView.animationImages = images; //images is your array\n [animatedView startAnimating];\n\n\n //Then when you need to pause;\n\n[animatedView stopAnimating]; //Important!!\n animatedView.image = [images objectAtIndex: 0];\n"
},
{
"answer_id": 9794053,
"author": "Mihai Timar",
"author_id": 757408,
"author_profile": "https://Stackoverflow.com/users/757408",
"pm_score": 2,
"selected": false,
"text": "CALayer CALayer UIImageView UIImage"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253247",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6044/"
] |
253,267
|
<p>I need to output some JavaScript in a WebControl based on some processing and some properties that the consumer can set, doing it on the load of the page will be to early.</p>
<p>When is the latest I can call RegisterClientScriptBlock and still have it output on the page?</p>
|
[
{
"answer_id": 398857,
"author": "sliderhouserules",
"author_id": 31385,
"author_profile": "https://Stackoverflow.com/users/31385",
"pm_score": 3,
"selected": false,
"text": "protected internal override void RenderChildren(HtmlTextWriter writer)\n{\n Page page = this.Page;\n if (page != null)\n {\n page.OnFormRender();\n page.BeginFormRender(writer, this.UniqueID);\n }\n base.RenderChildren(writer);\n if (page != null)\n {\n page.EndFormRender(writer, this.UniqueID);\n page.OnFormPostRender();\n }\n}\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253267",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5791/"
] |
253,284
|
<p>I am having dependency troubles. I have two classes: <code>Graphic</code> and <code>Image</code>. Each one has its own .cpp and .h files. I am declaring them as the following: </p>
<p><code>Graphic.h</code>: </p>
<pre><code>
#include "Image.h"
class Image;
class Graphic {
...
};
</code></pre>
<p><code>Image.h</code>:<br>
<pre><code>
#include "Graphic.h"
class Graphic;
class Image : public Graphic {
...
};</code></pre></p>
<p>When I try to compile, I get the following error: </p>
<pre>
Image.h:12: error: expected class-name before ‘{’ token
</pre>
<p>If I remove the forward declaration of <code>Graphic</code> from <code>Image.h</code> I get the following error: </p>
<pre>
Image.h:13: error: invalid use of incomplete type ‘struct Graphic’
Image.h:10: error: forward declaration of ‘struct Graphic’
</pre>
|
[
{
"answer_id": 253295,
"author": "Bill the Lizard",
"author_id": 1288,
"author_profile": "https://Stackoverflow.com/users/1288",
"pm_score": 1,
"selected": false,
"text": "Graphic.h class Graphic {\n ...\n};\n"
},
{
"answer_id": 253297,
"author": "activout.se",
"author_id": 20444,
"author_profile": "https://Stackoverflow.com/users/20444",
"pm_score": 0,
"selected": false,
"text": "class Graphic;\n"
},
{
"answer_id": 253318,
"author": "Claudiu",
"author_id": 15055,
"author_profile": "https://Stackoverflow.com/users/15055",
"pm_score": 5,
"selected": true,
"text": "#ifndef IMAGE_H\n#define IMAGE_H\n\n#include \"Graphic.h\"\nclass Image : public Graphic {\n\n};\n\n#endif\n #ifndef GRAPHIC_H\n#define GRAPHIC_H\n\n#include \"Image.h\"\n\nclass Graphic {\n};\n\n#endif\n #include \"Graphic.h\"\n\nint main()\n{\n return 0;\n}\n"
},
{
"answer_id": 253331,
"author": "John Dibling",
"author_id": 241536,
"author_profile": "https://Stackoverflow.com/users/241536",
"pm_score": 2,
"selected": false,
"text": "Graphic.h: class Graphic {\n ...\n};\n Image.h #include \"Graphic.h\"\nclass Image : public Graphic {\n ...\n};\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253284",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3831/"
] |
253,286
|
<p>I'm trying to design a model for a application allowing 2 people to bet with each other (I know, sounds stupid...). What I'm wondering about is how to connect the bet with users. The structure is like this</p>
<pre><code>|-------------| |----------|
| Bet | | User |
| BetUser1 | |----------|
| BetUser2 |
| Winner |
| ... |
|-------------|
</code></pre>
<p>So we got 2 people that bet with each other (both are <code>Users</code> from django auth system) and then, after one of them wins, there's a winner. Now all those 3 fields are of type <code>User</code>, but:</p>
<ul>
<li>Should I make BetUser1 and BetUser2 separate fields, or design some many-to-two relationship here? (with many-to-two being a many-to-many and with some external way of ensuring no more then 2 <code>Users</code> can be assigned to each bet?</li>
<li>winner can only be either user 1 or user 2, noone else of course. How should I create this field, yet another <code>ForeignKey(User)</code>, or some else?</li>
</ul>
<p>Just looking for some fresh point of view, as it seems that in such stupid case I'm stuck with the django model system.</p>
|
[
{
"answer_id": 253335,
"author": "tghw",
"author_id": 2363,
"author_profile": "https://Stackoverflow.com/users/2363",
"pm_score": 3,
"selected": true,
"text": "USER WAGER BET\n User (FK(User)) Description\n Bet (FK(Bet)) Winner (FK (Wager), null=True)\n Amount\n user.wager_set bet.wager_set unique_together User Bet bet.winner related_name Bet Wager Wager Bet related_name=wagers Wager.bet"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253286",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4172/"
] |
253,289
|
<p>I am new to PHP and trying to get the following code to work:</p>
<pre><code><?php
include 'config.php';
include 'opendb.php';
$query = "SELECT name, subject, message FROM contact";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo "Name :{$row['name']} <br>" .
"Subject : {$row['subject']} <br>" .
"Message : {$row['message']} <br><br>";
"ARTICLE_NO :{$row['ARTICLE_NO']} <br>" .
"ARTICLE_NAME :{$row['ARTICLE_NAME']} <br>" .
"SUBTITLE :{$row['SUBTITLE']} <br>" .
"CURRENT_BID :{$row['CURRENT_BID']} <br>" .
"START_PRICE :{$row['START_PRICE']} <br>" .
"BID_COUNT :{$row['BID_COUNT']} <br>" .
"QUANT_TOTAL :{$row['QUANT_TOTAL']} <br>" .
"QUANT_SOLD :{$row['QUANT_SOLD']} <br>" .
"STARTS :{$row['STARTS']} <br>" .
"ENDS :{$row['ENDS']} <br>" .
"ORIGIN_END :{$row['ORIGIN_END']} <br>" .
"SELLER_ID :{$row['SELLER_ID']} <br>" .
"BEST_BIDDER_ID :{$row['BEST_BIDDER_ID']} <br>" .
"FINISHED :{$row['FINISHED']} <br>" .
"WATCH :{$row['WATCH']} <br>" .
"BUYITNOW_PRICE :{$row['BUYITNOW_PRICE']} <br>" .
"PIC_URL :{$row['PIC_URL']} <br>" .
"PRIVATE_AUCTION :{$row['PRIVATE_AUCTION']} <br>" .
"AUCTION_TYPE :{$row['AUCTION_TYPE']} <br>" .
"INSERT_DATE :{$row['INSERT_DATE']} <br>" .
"UPDATE_DATE :{$row['UPDATE_DATE']} <br>" .
"CAT_1_ID :{$row['CAT_1_ID']} <br>" .
"CAT_2_ID :{$row['CAT_2_ID']} <br>" .
"ARTICLE_DESC :{$row['ARTICLE_DESC']} <br>" .
"DESC_TEXTONLY :{$row['DESC_TEXTONLY']} <br>" .
"COUNTRYCODE :{$row['COUNTRYCODE']} <br>" .
"LOCATION :{$row['LOCATION']} <br>" .
"CONDITIONS :{$row['CONDITIONS']} <br>" .
"REVISED :{$row['REVISED']} <br>" .
"PAYPAL_ACCEPT :{$row['PAYPAL_ACCEPT']} <br>" .
"PRE_TERMINATED :{$row['PRE_TERMINATED']} <br>" .
"SHIPPING_TO :{$row['SHIPPING_TO']} <br>" .
"FEE_INSERTION :{$row['FEE_INSERTION']} <br>" .
"FEE_FINAL :{$row['FEE_FINAL']} <br>" .
"FEE_LISTING :{$row['FEE_LISTING']} <br>" .
"PIC_XXL :{$row['PIC_XXL']} <br>" .
"PIC_DIASHOW :{$row['PIC_DIASHOW']} <br>" .
"PIC_COUNT :{$row['PIC_COUNT']} <br>" .
"ITEM_SITE_ID :{$row['ITEM_SITE_ID']};
}
include 'closedb.php';
?>
</code></pre>
<p>However I get this error:</p>
<pre><code>Parse error: syntax error, unexpected $end in C:\Programme\EasyPHP 2.0b1\www\test.php on line 56
</code></pre>
<p>I would also like to know if there is perhaps an easier way to obtain mysql records instead of typing by hand?</p>
<p>edit:</p>
<p>I fixed the semicolon and quote issue, and now get:</p>
<pre><code>Parse error: syntax error, unexpected T_STRING in C:\Programme\EasyPHP 2.0b1\www\test.php on line 51
</code></pre>
<p>I am sorry I don't know how to make colors in the code.</p>
|
[
{
"answer_id": 253299,
"author": "Mark Biek",
"author_id": 305,
"author_profile": "https://Stackoverflow.com/users/305",
"pm_score": 4,
"selected": true,
"text": "while($row = mysql_fetch_array($result, MYSQL_ASSOC))\n{\n foreach($row as $field=>$value)\n {\n echo \"$field: {$value} <br />\";\n }\n}\n"
},
{
"answer_id": 253305,
"author": "Kip",
"author_id": 18511,
"author_profile": "https://Stackoverflow.com/users/18511",
"pm_score": 2,
"selected": false,
"text": "while($row = mysql_fetch_array($result, MYSQL_ASSOC))\n{\n foreach($row as $key => $value)\n {\n echo \"$key: $value\\n\";\n }\n}\n"
},
{
"answer_id": 253308,
"author": "jakber",
"author_id": 29812,
"author_profile": "https://Stackoverflow.com/users/29812",
"pm_score": 0,
"selected": false,
"text": "include 'closedb.php';\n\n?>\n \"ITEM_SITE_ID :{$row['ITEM_SITE_ID']};\n \"Message : {$row['message']} <br><br>\";\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253289",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1246613/"
] |
253,312
|
<p>Any ideas why this won't validate here:</p>
<p><a href="http://validator.w3.org/#validate_by_input" rel="nofollow noreferrer">http://validator.w3.org/#validate_by_input</a></p>
<p>It seems the form input tags are wrong but reading through the XHTML spec they should validate fine. Any ideas?</p>
<pre><code><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test</title>
</head>
<body>
<div class="Header">
<table class="HeaderTable">
<tr>
<td>
<div class="Heading">Test <span class="Standard">Test</span>
</div>
</td>
<td>
<div class="Controls">
<form id="ControlForm" method="get" action="Edit.php">
<input type="submit" name="action" id="Edit" value="Edit" />
<input type="submit" name="action" id="New" value="New" />
</form>
</div>
</td>
</tr>
</table>
</div>
</body>
</html>
</code></pre>
|
[
{
"answer_id": 253340,
"author": "Rahul",
"author_id": 16308,
"author_profile": "https://Stackoverflow.com/users/16308",
"pm_score": 3,
"selected": false,
"text": "fieldset"
},
{
"answer_id": 253348,
"author": "FOR",
"author_id": 27826,
"author_profile": "https://Stackoverflow.com/users/27826",
"pm_score": 2,
"selected": false,
"text": "<!ELEMENT form %form.content;>\n\n<!ENTITY % form.content \"(%block; | %misc;)*\">\n\n<!ENTITY % misc \"noscript | %misc.inline;\">\n<!ENTITY % misc.inline \"ins | del | script\">\n\n<!ENTITY % block \"p | %heading; | div | %lists; | %blocktext; | fieldset | table\">\n\n<!ENTITY % heading \"h1|h2|h3|h4|h5|h6\">\n<!ENTITY % lists \"ul | ol | dl\">\n<!ENTITY % blocktext \"pre | hr | blockquote | address\">\n"
},
{
"answer_id": 253353,
"author": "Mark Biek",
"author_id": 305,
"author_profile": "https://Stackoverflow.com/users/305",
"pm_score": 3,
"selected": true,
"text": "<div class=\"Controls\">\n <!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 <title>Test</title>\n</head>\n\n<body>\n <div class=\"Header\">\n <table class=\"HeaderTable\">\n <tr>\n <td>\n <div class=\"Heading\">Test <span class=\"Standard\">Test</span></div>\n </td>\n <td>\n <form id=\"ControlForm\" method=\"get\" action=\"Edit.php\">\n <div class=\"Controls\">\n <input type=\"submit\" name=\"action\" id=\"Edit\" value=\"Edit\" />\n <input type=\"submit\" name=\"action\" id=\"New\" value=\"New\" />\n </div>\n </form>\n </td>\n </tr>\n </table>\n </div>\n</body>\n</html>\n"
},
{
"answer_id": 253361,
"author": "François",
"author_id": 32379,
"author_profile": "https://Stackoverflow.com/users/32379",
"pm_score": 0,
"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 <title>Test</title>\n </head>\n\n <body>\n <div class=\"Header\">\n <table class=\"HeaderTable\">\n <tr>\n <td>\n <div class=\"Heading\">Test <span class=\"Standard\">Test</span>\n </div>\n </td>\n <td>\n\n <form id=\"ControlForm\" method=\"get\" action=\"Edit.php\">\n <div class=\"Controls\">\n <input type=\"submit\" name=\"action\" id=\"Edit\" value=\"Edit\" />\n <input type=\"submit\" name=\"action\" id=\"New\" value=\"New\" />\n </div>\n </form>\n\n </td>\n </tr>\n </table>\n </div>\n </body>\n</html>\n"
},
{
"answer_id": 253379,
"author": "John Topley",
"author_id": 1450,
"author_profile": "https://Stackoverflow.com/users/1450",
"pm_score": 0,
"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 <title>Test</title>\n </head>\n <body>\n <div class=\"Header\">\n <table class=\"HeaderTable\">\n <tr>\n <td>\n <div class=\"Heading\">Test <span class=\"Standard\">Test</span></div>\n </td>\n <td>\n <div class=\"Controls\">\n <form id=\"ControlForm\" method=\"get\" action=\"Edit.php\">\n <fieldset>\n <input type=\"submit\" name=\"action\" id=\"Edit\" value=\"Edit\" />\n <input type=\"submit\" name=\"action\" id=\"New\" value=\"New\" />\n </fieldset>\n </form>\n </div>\n </td>\n </tr>\n </table>\n </div>\n </body>\n</html>\n"
},
{
"answer_id": 2629855,
"author": "Adrian",
"author_id": 315514,
"author_profile": "https://Stackoverflow.com/users/315514",
"pm_score": 1,
"selected": false,
"text": "<div>\n<form>\n <label></label>\n <input />\n <label></label>\n <input />\n <label></label>\n <input />\n</form>\n <div>\n<form>\n <fieldset>or<div>\n <label></label>\n <input />\n <label></label>\n <input />\n <label></label>\n <input />\n </fieldset>or</div>\n</form>\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253312",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13227/"
] |
253,314
|
<p>Yesterday I was having a heated debate with a coworker on what would be the preferred error reporting method. Mainly we were discussing the usage of exceptions or error codes for reporting errors between application layers or modules.</p>
<p><strong>What rules do you use to decide if you throw exceptions or return error codes for error reporting?</strong></p>
|
[
{
"answer_id": 253533,
"author": "sakana",
"author_id": 28921,
"author_profile": "https://Stackoverflow.com/users/28921",
"pm_score": 2,
"selected": false,
"text": "public class DataValidationException extends Exception {\n\n\n private DataValidation error;\n\n /**\n * \n */\n DataValidationException(DataValidation dataValidation) {\n super();\n this.error = dataValidation;\n }\n\n\n}\n\nenum DataValidation{\n\n TOO_SMALL(1,\"The input is too small\"),\n\n TOO_LARGE(2,\"The input is too large\");\n\n\n private DataValidation(int code, String input) {\n this.input = input;\n this.code = code;\n }\n\n private String input;\n\n private int code;\n\n}\n"
},
{
"answer_id": 254073,
"author": "Charles Bretana",
"author_id": 32632,
"author_profile": "https://Stackoverflow.com/users/32632",
"pm_score": 4,
"selected": false,
"text": "Employee EmpOfMonth = GetEmployeeOfTheMonth();\n Employee EmpOfMonth; \nif (getEmployeeOfTheMonth(ref EmpOfMonth) == ERROR)\n // code to Handle the error here\n"
},
{
"answer_id": 254693,
"author": "Eclipse",
"author_id": 8701,
"author_profile": "https://Stackoverflow.com/users/8701",
"pm_score": 2,
"selected": false,
"text": "TryParse()"
},
{
"answer_id": 28648679,
"author": "Dogs",
"author_id": 2526056,
"author_profile": "https://Stackoverflow.com/users/2526056",
"pm_score": 4,
"selected": false,
"text": "try {\n // Normal things are happening logic\ncatch (// A problem) {\n // Something went wrong logic\n}\n // Some normal stuff logic\nif (errorCode means error) {\n // Some stuff went wrong logic\n}\n// Some normal stuff logic\nif (errorCode means error) {\n // Some stuff went wrong logic\n}\n// Some normal stuff logic\nif (errorCode means error) {\n // Some stuff went wrong logic\n}\n"
},
{
"answer_id": 43054826,
"author": "orad",
"author_id": 450913,
"author_profile": "https://Stackoverflow.com/users/450913",
"pm_score": 2,
"selected": false,
"text": "public class ServiceResponse\n{\n public bool IsSuccess => string.IsNullOrEmpty(this.ErrorMessage);\n\n public string ErrorMessage { get; set; }\n}\n\npublic class ServiceResponse<TResult> : ServiceResponse\n{\n public TResult Result { get; set; }\n}\n public async Task<ServiceResponse<string>> GetUserName(Guid userId)\n{\n var response = await this.GetUser(userId);\n if (!response.IsSuccess) return new ServiceResponse<string>\n {\n ErrorMessage = $\"Failed to get user.\"\n };\n return new ServiceResponse<string>\n {\n Result = user.Name\n };\n}\n"
},
{
"answer_id": 46823898,
"author": "drizin",
"author_id": 3606250,
"author_profile": "https://Stackoverflow.com/users/3606250",
"pm_score": 4,
"selected": false,
"text": "on error goto on error resume next public MethodResult<CreateOrderResultCodeEnum, Order> CreateOrder(CreateOrderOptions options)\n{\n ....\n return MethodResult<CreateOrderResultCodeEnum>.CreateError(CreateOrderResultCodeEnum.NO_DELIVERY_AVAILABLE, \"There is no delivery service in your area\");\n\n ...\n return MethodResult<CreateOrderResultCodeEnum>.CreateSuccess(CreateOrderResultCodeEnum.SUCCESS, order);\n}\n\nvar result = CreateOrder(options);\nif (result.ResultCode == CreateOrderResultCodeEnum.OUT_OF_STOCK)\n // do something\nelse if (result.ResultCode == CreateOrderResultCodeEnum.SUCCESS)\n order = result.Entity; // etc...\n \npublic enum CreateUserResultCodeEnum\n{\n [Description(\"Username not available\")]\n NOT_AVAILABLE,\n}\n\npublic (User user, CreateUserResultCodeEnum? error) CreateUser(string userName)\n // (try to create user, check if not available...)\n if (notAvailable)\n return (null, CreateUserResultCodeEnum.NOT_AVAILABLE);\n return (user, null);\n}\n\n// How to call and deconstruct tuple:\n(var user, var error) = CreateUser(\"john.doe\");\nif (user != null) ...\nif (error == CreateUserResultCodeEnum.NOT_AVAILABLE) ...\n\n// Or returning a single object (named tuple):\nvar result = CreateUser(\"john.doe\");\nif (result.user != null) ...\nif (result.error == CreateUserResultCodeEnum.NOT_AVAILABLE) ...\n ValueTuple CommandResult<TEntity, TError>"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253314",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6508/"
] |
253,324
|
<p>I need a smart way to get the data types out of INFORMATION_SCHEMA.COLUMNS in a way that could be used in a CREATE TABLE statement. The problem is the 'extra' fields that need to be understood, such as NUMERIC<code>_</code>PRECISION and NUMERIC<code>_</code>SCALE.</p>
<p>Obviously, I can ignore the columns for INTEGER (precision of 10 and scale of 0), but there are other types I would be interested in, such as NUMERIC. So without writing lots of code to parse the table, any ideas on how to get a sort of field shorthand out of the column definition?</p>
<p>I would like to be able to get something like :
int,
datetime,
money,
numeric**(10,2)**</p>
|
[
{
"answer_id": 253330,
"author": "StingyJack",
"author_id": 16391,
"author_profile": "https://Stackoverflow.com/users/16391",
"pm_score": 1,
"selected": false,
"text": "I need a smart way to get the data types out of INFORMATION_SCHEMA.COLUMNS in a way that could be used in a CREATE TABLE statement"
},
{
"answer_id": 253374,
"author": "GalacticCowboy",
"author_id": 29638,
"author_profile": "https://Stackoverflow.com/users/29638",
"pm_score": 3,
"selected": false,
"text": "select column_type = data_type + \n case\n when data_type like '%text' then ''\n when data_type like '%char' and character_maximum_length = -1 then '(max)'\n when character_maximum_length is not null then '(' + convert(varchar(10), character_maximum_length) + ')'\n when data_type = 'numeric' then '(' + convert(varchar(10), isnull(numeric_precision, 18)) + ', ' + \n convert(varchar(10), isnull(numeric_scale, 0)) + ')'\n else ''\n end\n,*\nfrom information_schema.columns\n"
},
{
"answer_id": 11234044,
"author": "Tim Lehner",
"author_id": 880904,
"author_profile": "https://Stackoverflow.com/users/880904",
"pm_score": 4,
"selected": true,
"text": "select data_type + \n case\n when data_type like '%text' or data_type in ('image', 'sql_variant' ,'xml')\n then ''\n when data_type in ('float')\n then '(' + cast(coalesce(numeric_precision, 18) as varchar(11)) + ')'\n when data_type in ('datetime2', 'datetimeoffset', 'time')\n then '(' + cast(coalesce(datetime_precision, 7) as varchar(11)) + ')'\n when data_type in ('decimal', 'numeric')\n then '(' + cast(coalesce(numeric_precision, 18) as varchar(11)) + ',' + cast(coalesce(numeric_scale, 0) as varchar(11)) + ')'\n when (data_type like '%binary' or data_type like '%char') and character_maximum_length = -1\n then '(max)'\n when character_maximum_length is not null\n then '(' + cast(character_maximum_length as varchar(11)) + ')'\n else ''\n end as CONDENSED_TYPE\n , *\nfrom information_schema.columns\norder by table_schema, table_name, ordinal_position\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253324",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3893/"
] |
253,351
|
<p>I am writing a Java Application for Data Entry using Eclipse and SWT. Naturally it has a great many Text objects. </p>
<p>What I would like to happen is that when user enters something into one field focus automatically changes to the next field.</p>
<p>Thanks in advance</p>
|
[
{
"answer_id": 254030,
"author": "Drazen Urch",
"author_id": 33074,
"author_profile": "https://Stackoverflow.com/users/33074",
"pm_score": 2,
"selected": false,
"text": "final Text textBox = new Text(shell, SWT.NONE);\ntextBox.addKeyListener(new KeyAdapter() {\n public void keyPressed(KeyEvent e) {\n if (x.getText().length() == 1); {\n x.traverse(SWT.TRAVERSE_TAB_NEXT);\n }\n }\n});\n"
},
{
"answer_id": 254055,
"author": "James Van Huis",
"author_id": 31828,
"author_profile": "https://Stackoverflow.com/users/31828",
"pm_score": 1,
"selected": false,
"text": "final Text textBox = new Text(shell, SWT.NONE);\ntextBox.addKeyListener(new KeyAdapter() {\n\n public void keyPressed(KeyEvent arg0) {\n if (textBox.getText().equals(\"\") == false) {\n textBox.traverse(SWT.TRAVERSE_TAB_NEXT);\n }\n }});\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253351",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33074/"
] |
253,357
|
<p>For some reason Eclipse is no longer showing me Java compilation Errors in the Problems View.</p>
<p>It is still showing Warnings.</p>
<p>This has suddenly happened and I cannot think of anything that I have changed which would affect this.</p>
<p>I am using the "Maven Integration for Eclipse" plugin but I have been for some time - not sure if this could have affected it or not.</p>
<p>Any ideas?</p>
|
[
{
"answer_id": 941904,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "public enum Foo {\nDummy(new Bar [] {new Bar()});\nstatic {\n for (Foo foo: Foo.values());\n}\nprivate Foo(Bar [] params) {}\npublic class Bar {}\n }\n"
},
{
"answer_id": 9586448,
"author": "Kees",
"author_id": 1252550,
"author_profile": "https://Stackoverflow.com/users/1252550",
"pm_score": 4,
"selected": false,
"text": "<Project><Properties><Builders> <buildSpec>\n <buildCommand>\n <name>org.eclipse.jdt.core.javabuilder</name>\n <arguments>\n </arguments>\n </buildCommand>\n</buildSpec>\n<natures>\n <nature>org.eclipse.jdt.core.javanature</nature>\n</natures>\n"
},
{
"answer_id": 23904661,
"author": "Chandra Sekhar",
"author_id": 1213738,
"author_profile": "https://Stackoverflow.com/users/1213738",
"pm_score": 4,
"selected": false,
"text": "Right-click your project > Build Path > Configure Build Path > Source Project->Clean project > Build Automatically"
},
{
"answer_id": 57160287,
"author": "gRaWEty",
"author_id": 2627215,
"author_profile": "https://Stackoverflow.com/users/2627215",
"pm_score": 1,
"selected": false,
"text": "mvn eclipse:eclipse\n"
},
{
"answer_id": 70130428,
"author": "Gerardo Roza",
"author_id": 6661361,
"author_profile": "https://Stackoverflow.com/users/6661361",
"pm_score": 3,
"selected": false,
"text": "New Problems View"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253357",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8633/"
] |
253,360
|
<p>Whilst trying to get our app working in Firefox (I'm a big proponent of X-Browser support but our lead dev is resisting me saying IE is good enough). So I'm doing a little side project to see how much work it is to convert.</p>
<p>I've hit a problem straight away.</p>
<p>The main.aspx page binds to a webservice using the IE only method of adding behaviour through a htc file, which is auto-generated by VS I beleive.</p>
<p> </p>
<p>Firefox doesn't support this but there is an xml bindings file which can be used to enable htc support (see here: <a href="http://dean.edwards.name/moz-behaviors/overview/" rel="nofollow noreferrer">http://dean.edwards.name/moz-behaviors/overview/</a>). The examples work in FF3 but when I use my webservice.htc as I normally would e.g.:</p>
<pre><code>//Main.aspx
/*SNIP*/
<style type="text/css" media="all">
#webservice
{
behavior:url(webservice.htc);
-moz-binding:url(bindings.xml#webservice.htc);
}
</style>
</head>
<body>
<div id="webservice"></div> <!-- we use this div to load the webservice stuff -->
/*SNIP*/
//Main.js
webservice.useService(url + asmpath + "/WebServiceWrapper.asmx?WSDL","WebServiceWrapper");
</code></pre>
<p>I get webservice is not defined (works fine in IE), I obviously tried</p>
<pre><code>var webservice = document.getElementById("webservice")
</code></pre>
<p>and </p>
<pre><code>$("#webservice").useService(url + asmpath + "/WebServiceWrapper.asmx?WSDL","WebServiceWrapper");
</code></pre>
<p>as well which just gives me "useService is not defined" in Firebug. Which leads me to beleive that the binding is not working. However I can see that webservice.htc is being loaded by Firefox in the Firebug console window.</p>
<p>Anyone got any experience of this?</p>
<p>Am I going to have to rewrite how the webservice is called?</p>
<p>Cheers,
Rob</p>
|
[
{
"answer_id": 259631,
"author": "savetheclocktower",
"author_id": 25720,
"author_profile": "https://Stackoverflow.com/users/25720",
"pm_score": 1,
"selected": false,
"text": "useService $(\"#webservice\")[0].useService(url + asmpath +\n \"/WebServiceWrapper.asmx?WSDL\",\"WebServiceWrapper\");\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253360",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4950/"
] |
253,375
|
<p>I once did a cursory search and found no good CVS bindings for Python. I wanted to be able to write helper scripts to do some fine-grained manipulation of the repository and projects in it. I had to resort to using <code>popen</code> and checking <code>stdout</code> and <code>stderr</code> and then parsing those. It was messy and error-prone.</p>
<p>Are there any good quality modules for CVS integration for Python? Which module do you prefer and why?</p>
<p>While I am at it, is there a good Subversion integration module for Python? My understanding is that Subversion has a great API for such things.</p>
|
[
{
"answer_id": 254092,
"author": "ephemient",
"author_id": 20713,
"author_profile": "https://Stackoverflow.com/users/20713",
"pm_score": 1,
"selected": false,
"text": "cvs svn"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253375",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19215/"
] |
253,378
|
<p>I am trying the following code:</p>
<pre><code><?php
$link = mysql_connect('localhost', 'root', 'geheim');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
$query = "SELECT * FROM Auctions";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
foreach($row as $field=>$value)
{
echo "$field: {$value} <br />";
}
}
mysql_close($link);
?>
</code></pre>
<p>And get this error:</p>
<pre><code>Warning: mysql_fetch_array(): supplied argument is not a
valid MySQL result resource in
C:\Programme\EasyPHP 2.0b1\www\test.php on line 14
</code></pre>
<p>What am I missing?</p>
|
[
{
"answer_id": 253386,
"author": "Aron Rotteveel",
"author_id": 11568,
"author_profile": "https://Stackoverflow.com/users/11568",
"pm_score": 2,
"selected": false,
"text": "$query = \"SELECT * FROM Auctions\"; \n$result = mysql_query($query);\n\nif ($result !== false) {\n while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { \n foreach ($row as $field=>$value) { \n echo $field . ':' . $value\n }\n }\n} else {\n // query returned 0 rows\n}\n"
},
{
"answer_id": 253389,
"author": "Greg",
"author_id": 24181,
"author_profile": "https://Stackoverflow.com/users/24181",
"pm_score": 4,
"selected": true,
"text": "mysql_select_db() <?php\n $link = mysql_connect('localhost', 'root', 'geheim');\n if (!$link) {\n die('Could not connect: ' . mysql_error());\n }\n echo 'Connected successfully';\n\n $db_selected = mysql_select_db('foo', $link);\n if (!$db_selected) {\n die ('Error selecting database: '. mysql_error());\n }\n echo 'Using database successfully';\n\n $query = \"SELECT * FROM Auctions\";\n $result = mysql_query($query);\n while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {\n foreach($row as $field=>$value) {\n echo \"$field: {$value} <br />\";\n }\n }\n mysql_close($link);\n?> \n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253378",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1246613/"
] |
253,380
|
<p>In <a href="http://en.wikipedia.org/wiki/Vim_%28text_editor%29" rel="noreferrer">Vim</a>, how do I insert characters at the beginning of each line in a selection?</p>
<p>For instance, I want to comment out a block of code by prepending <code>//</code> at the beginning of each line assuming my language's comment system doesn't allow block commenting like <code>/* */</code>. How would I do this?</p>
|
[
{
"answer_id": 253388,
"author": "Tomalak",
"author_id": 18771,
"author_profile": "https://Stackoverflow.com/users/18771",
"pm_score": 8,
"selected": false,
"text": ":%s!^!//!\n :'<,'>s!^!//!\n gv"
},
{
"answer_id": 253477,
"author": "Lucas Oman",
"author_id": 6726,
"author_profile": "https://Stackoverflow.com/users/6726",
"pm_score": 4,
"selected": false,
"text": "vmap \\c :s!^!//!<CR>\nvmap \\u :s!^//!!<CR>\n \\c \\u"
},
{
"answer_id": 256285,
"author": "Brian Carper",
"author_id": 23070,
"author_profile": "https://Stackoverflow.com/users/23070",
"pm_score": 4,
"selected": false,
"text": ":'<,'>g/^/norm I//\n /^/ norm I// :g"
},
{
"answer_id": 256301,
"author": "Benedikt Waldvogel",
"author_id": 4308,
"author_profile": "https://Stackoverflow.com/users/4308",
"pm_score": 2,
"selected": false,
"text": "let maplocalleader=','\nvmap <silent> <LocalLeader>c <Plug>VisualTraditional\nnmap <silent> <LocalLeader>c <Plug>Traditional\nlet g:EnhCommentifyBindInInsert = 'No'\nlet g:EnhCommentifyMultiPartBlocks = 'Yes'\nlet g:EnhCommentifyPretty = 'Yes'\nlet g:EnhCommentifyRespectIndent = 'Yes'\nlet g:EnhCommentifyUseBlockIndent = 'Yes'\n"
},
{
"answer_id": 731633,
"author": "ninegrid",
"author_id": 13661,
"author_profile": "https://Stackoverflow.com/users/13661",
"pm_score": 6,
"selected": false,
"text": " some█\n code\n here\n // █some\n code\n here\n // some\n // code\n //█here\n"
},
{
"answer_id": 1352056,
"author": "Kevin",
"author_id": 114614,
"author_profile": "https://Stackoverflow.com/users/114614",
"pm_score": 2,
"selected": false,
"text": "Shift-V\n...select the lines of text you want to comment....\n ,cc\n ,cu\n ,c<space>\n"
},
{
"answer_id": 2030709,
"author": "Jar-jarhead",
"author_id": 246729,
"author_profile": "https://Stackoverflow.com/users/246729",
"pm_score": 5,
"selected": false,
"text": "# :%s/^/#/\n"
},
{
"answer_id": 3875539,
"author": "cyber-monk",
"author_id": 468304,
"author_profile": "https://Stackoverflow.com/users/468304",
"pm_score": 7,
"selected": false,
"text": ":s/search/replace/\n :s/search/replace/g\n :%s/search/replace/c\n :14,20s/^/#/\n :14,20s!^!//!\n :14,20s/^/\\/\\//\n :set nu\n"
},
{
"answer_id": 32842973,
"author": "JJoao",
"author_id": 2991627,
"author_profile": "https://Stackoverflow.com/users/2991627",
"pm_score": 1,
"selected": false,
"text": "<C-V c#<ESC>p c \\q :vmap \\q c#<ESC>p\n"
},
{
"answer_id": 53716645,
"author": "Mac",
"author_id": 10773674,
"author_profile": "https://Stackoverflow.com/users/10773674",
"pm_score": 3,
"selected": false,
"text": "% norm I ABC"
},
{
"answer_id": 57113282,
"author": "TheUnseen",
"author_id": 4285089,
"author_profile": "https://Stackoverflow.com/users/4285089",
"pm_score": 1,
"selected": false,
"text": "vip shift-i escape escape"
},
{
"answer_id": 66726688,
"author": "Xopi García",
"author_id": 9391770,
"author_profile": "https://Stackoverflow.com/users/9391770",
"pm_score": 0,
"selected": false,
"text": "<leader>zzz vnoremap <leader>zzz <C-V>^I-<Space><Esc>\n <C-V> ^ 0 I -<Space> <Esc> nnoremap <leader>zzz gv<C-V>^I-<Space><Esc>\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253380",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20133/"
] |
253,394
|
<p>I need to add a row to a spreadsheet using VBScript on a PC that does not have Microsoft Office installed.</p>
<p>I tried [<code>Set objExcel = CreateObject("Excel.Application")</code>]</p>
<p>Since Excel does not exist on the PC I cannot create this object.</p>
<p>Is there a way to modify a spreadsheet without Excel?</p>
|
[
{
"answer_id": 254209,
"author": "aphoria",
"author_id": 2441,
"author_profile": "https://Stackoverflow.com/users/2441",
"pm_score": 3,
"selected": false,
"text": "First Last\nJoe Smith\nMary Jones\nSam Nelson\n Const adOpenStatic = 3\nConst adLockOptimistic = 3\n\nfilename = \"Test.xls\"\nSet cn = CreateObject(\"ADODB.Connection\")\ncn.Open \"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\" & filename & _\n \";Extended Properties=Excel 8.0\"\n\nquery = \"Select * from [Sheet1$A1:B65535]\"\nSet rs = CreateObject(\"ADODB.Recordset\")\nrs.Open query, cn, adOpenStatic, adLockOptimistic\n\nrs.AddNew\nrs(\"First\") = \"George\"\nrs(\"Last\") = \"Washington\"\nrs.Update\n\nrs.MoveFirst\nDo Until rs.EOF\n WScript.Echo rs.Fields(\"First\") & \" \" & rs.Fields(\"Last\")\n rs.MoveNext\nLoop\n CSCRIPT Yourfile.vbs\n Joe Smith\nMary Jones\nSam Nelson\nGeorge Washington\n"
},
{
"answer_id": 254602,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "Dim arrValue\narrValue = Array(\"Test\",\"20\",\"\",\"I\",\"2.25\",\"3.9761\",\"20\",\"60\",\"12\",\"1\",\"\",\"1\",\"1\",\"1\")\nAddXLSRow \"C:\\Test.xls\", \"A1:N109\", arrValue\n\nSub AddXLSRow(strSource, strRange, arrValues)\n'This routine uses the data from an array to fill fields in the specified spreadsheet.\n'Input strSource (String) = The Full path and filename of the spreadsheet to be used.\n'Input arrValues (Array) = An array of values to be added to the spreadsheet.\nDim strConnection, conn, rs, strSQL, index\n\nstrConnection = \"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\" & strSource & \";Extended Properties=\"\"Excel 8.0;HDR=Yes;\"\";\"\n\nSet conn = CreateObject(\"ADODB.Connection\")\nconn.Open strConnection\nSet rs = CreateObject(\"ADODB.recordset\")\nstrSQL = \"SELECT * FROM \" & strRange\nrs.open strSQL, conn, 3,3\nrs.AddNew \nindex = 0\nFor Each field In rs.Fields\n If field.Type = 202 Then\n field.value = arrValues(index)\n ElseIffield.Type = 5 And arrValues(index) <> \"\" Then\n field.value = CDbl(arrValues(index))\n End If\n If NOT index >= UBound(arrValues) Then\n index = index + 1\n End If\nNext\nrs.Update\nrs.Close\nSet rs = Nothing\nconn.Close\nSet conn = Nothing\nEnd Sub\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253394",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
253,399
|
<p>Delphi (and probably a lot of other languages) has class helpers. These provide a way to add extra methods to an existing class. Without making a subclass.</p>
<p>So, what are good uses for class helpers?</p>
|
[
{
"answer_id": 253400,
"author": "Toon Krijthe",
"author_id": 18061,
"author_profile": "https://Stackoverflow.com/users/18061",
"pm_score": 4,
"selected": false,
"text": "type\n TStringsHelper = class helper for TStrings\n public\n function IsEmpty: Boolean;\n end;\n\nfunction TStringsHelper.IsEmpty: Boolean;\nbegin\n Result := Count = 0;\nend;\n procedure TForm1.Button1Click(Sender: TObject);\nbegin\n if Memo1.Lines.IsEmpty then\n Button1.Caption := 'Empty'\n else\n Button1.Caption := 'Filled';\nend;\n"
},
{
"answer_id": 253421,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 3,
"selected": false,
"text": "IEnumerable<T> IQueryable<T> var query = someOriginalSequence.Where(person => person.Age > 18)\n .OrderBy(person => person.Name)\n .Select(person => person.Job);\n"
},
{
"answer_id": 253471,
"author": "gabr",
"author_id": 4997,
"author_profile": "https://Stackoverflow.com/users/4997",
"pm_score": 6,
"selected": true,
"text": "TGpStringListHelper = class helper for TStringList\npublic\n function Last: string;\n function Contains(const s: string): boolean;\n function FetchObject(const s: string): TObject;\n procedure Sort;\n procedure Remove(const s: string);\nend; { TGpStringListHelper }\n"
},
{
"answer_id": 253636,
"author": "Robert Walker",
"author_id": 28300,
"author_profile": "https://Stackoverflow.com/users/28300",
"pm_score": 2,
"selected": false,
"text": "- (id)valueForKey:(NSString *)key\n NSArray *myArray = [NSArray array]; // Make a new empty array\nid myValue = [myArray valueForKey:@\"name\"]; // Call a method defined in the category\n"
},
{
"answer_id": 253697,
"author": "Uwe Raabe",
"author_id": 26833,
"author_profile": "https://Stackoverflow.com/users/26833",
"pm_score": 2,
"selected": false,
"text": "type\n TMyObject = class\n public\n procedure DoSomething;\n end;\n\n TMyObjectStringsHelper = class helper for TStrings\n private\n function GetMyObject(const Name: string): TMyObject;\n procedure SetMyObject(const Name: string; const Value: TMyObject);\n public\n property MyObject[const Name: string]: TMyObject read GetMyObject write SetMyObject; default;\n end;\n\nfunction TMyObjectStringsHelper.GetMyObject(const Name: string): TMyObject;\nvar\n idx: Integer;\nbegin\n idx := IndexOf(Name);\n if idx < 0 then\n result := nil\n else\n result := Objects[idx] as TMyObject;\nend;\n\nprocedure TMyObjectStringsHelper.SetMyObject(const Name: string; const Value:\n TMyObject);\nvar\n idx: Integer;\nbegin\n idx := IndexOf(Name);\n if idx < 0 then\n AddObject(Name, Value)\n else\n Objects[idx] := Value;\nend;\n\nvar\n lst: TStrings;\nbegin\n ...\n lst['MyName'] := TMyObject.Create; \n ...\n lst['MyName'].DoSomething;\n ...\nend;\n type\n TRegistryHelper = class helper for TRegistry\n public\n function ReadStrings(const ValueName: string): TStringDynArray;\n end;\n\nfunction TRegistryHelper.ReadStrings(const ValueName: string): TStringDynArray;\nvar\n DataType: DWord;\n DataSize: DWord;\n Buf: PChar;\n P: PChar;\n Len: Integer;\n I: Integer;\nbegin\n result := nil;\n if RegQueryValueEx(CurrentKey, PChar(ValueName), nil, @DataType, nil, @DataSize) = ERROR_SUCCESS then begin\n if DataType = REG_MULTI_SZ then begin\n GetMem(Buf, DataSize + 2);\n try\n if RegQueryValueEx(CurrentKey, PChar(ValueName), nil, @DataType, PByte(Buf), @DataSize) = ERROR_SUCCESS then begin\n for I := 0 to 1 do begin\n if Buf[DataSize - 2] <> #0 then begin\n Buf[DataSize] := #0;\n Inc(DataSize);\n end;\n end;\n\n Len := 0;\n for I := 0 to DataSize - 1 do\n if Buf[I] = #0 then\n Inc(Len);\n Dec(Len);\n if Len > 0 then begin\n SetLength(result, Len);\n P := Buf;\n for I := 0 to Len - 1 do begin\n result[I] := StrPas(P);\n Inc(P, Length(P) + 1);\n end;\n end;\n end;\n finally\n FreeMem(Buf, DataSize);\n end;\n end;\n end;\nend;\n"
},
{
"answer_id": 254877,
"author": "Mason Wheeler",
"author_id": 32914,
"author_profile": "https://Stackoverflow.com/users/32914",
"pm_score": 2,
"selected": false,
"text": "type\n TCompetitionToMyClass = class helper for TMyClass\n public\n constructor Convert(base: TCompetition);\n end;\n"
},
{
"answer_id": 69827499,
"author": "Ian Boyd",
"author_id": 12597,
"author_profile": "https://Stackoverflow.com/users/12597",
"pm_score": 0,
"selected": false,
"text": "TGuidHelper = class\npublic\n class function IsEmpty(this Value: TGUID): Boolean;\nend;\n\nclass function TGuidHelper(this Value: TGUID): Boolean;\nbegin\n Result := (Value = TGuid.Empty);\nend;\n if customerGuid.IsEmpty then ... IDataRecord orderGuid := xmlDocument.GetGuid('/Order/OrderID');\n var\n node: IXMLDOMNode;\n\n node := xmlDocument.selectSingleNode('/Order/OrderID');\n if Assigned(node) then\n orderID := StrToGuid(node.Text) //throw convert error on empty or invalid\n else\n orderID := TGuid.Empty; // \"DBNull\" becomes the null guid\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253399",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18061/"
] |
253,403
|
<p>I am developing a java web app using servlet, in order to prevent user from hitting the back button to see previous users' info, I have the following code :</p>
<pre><code> protected void processRequest(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException
{
HttpSession session=request.getSession(true);
response.setContentType("text/html");
response.setHeader("Cache-Control","no-cache,no-store");
response.setDateHeader("Expires",0);
response.setHeader("Pragma","no-cache");
......
// if (!User_Logged_In)
session.invalidate();
}
</code></pre>
<p>Besides I also have the following code in the file : web/WEB-INF/web.xml</p>
<pre><code><?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
......
<filter>
<filter-name>ResponseHeaderFilter</filter-name>
<filter-class>ResponseHeaderFilter</filter-class>
<init-param>
<param-name>Cache-Control</param-name>
<param-value>private,no-cache,no-store</param-value>
</init-param>
<init-param>
<param-name>Pragma</param-name>
<param-value>no-cache</param-value>
</init-param>
<init-param>
<param-name>Expires</param-name>
<param-value>0</param-value>
</init-param>
</filter>
</web-app>
</code></pre>
<p>And the ResponseHeaderFilter.java looks like this :</p>
<pre><code>import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
public class ResponseHeaderFilter implements Filter
{
FilterConfig fc;
public void doFilter(ServletRequest req,ServletResponse res,FilterChain chain) throws IOException,ServletException
{
HttpServletResponse response=(HttpServletResponse)res;
for (Enumeration e=fc.getInitParameterNames();e.hasMoreElements();) // Set the provided HTTP response parameters
{
String headerName=(String)e.nextElement();
response.addHeader(headerName,fc.getInitParameter(headerName));
}
chain.doFilter(req,response); // Pass the request/response on
}
public void init(FilterConfig filterConfig)
{
this.fc=filterConfig;
}
public void destroy()
{
this.fc=null;
}
}
</code></pre>
<p>So far it's still not working correctly. The back button will bring up a warning window saying the data has expired, it asks if the user wants to repost it. If you choose yes, it will still display the previous pages info. What am I doing wrong? What's the fix ?</p>
<p>Frank</p>
<hr>
<p>Yes, I am developing a web app for a PC in public place, if user B hits the back button he might see user A's private info.</p>
<p>I was trying to use session id with servlet, but how to do it, any sample code ?</p>
<p>I also tried the following :</p>
<pre><code><Html>
<Head>...</Head>
<Body onLoad=document.execCommand("ClearAuthenticationCache","false")>
......
<script type="text/javascript">
// Clear current credentials : Requires IE6 SP1 or later
// document.execCommand("ClearAuthenticationCache");
document.execCommand("ClearAuthenticationCache","false");
</script>
......
</Html>
</code></pre>
<p>It works for IE but but Firefox.</p>
|
[
{
"answer_id": 253489,
"author": "Brian Matthews",
"author_id": 1969,
"author_profile": "https://Stackoverflow.com/users/1969",
"pm_score": 2,
"selected": false,
"text": "WHERE OWNER=?"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253403",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32834/"
] |
253,410
|
<p>Alright, I know how the <code>fieldset</code>/<code>legend</code> works out in HTML. Say you have a form with some fields:</p>
<pre><code><form>
<fieldset>
<legend>legend</legend>
<input name="input1" />
</fieldset>
</form>
</code></pre>
<p>What should I use the <code>legend</code> for? It's being displayed as a <strong>title</strong>, but isn't a legend semantically an explanation of the contents? In my view, preferably you'd do something like this:</p>
<pre><code><form>
<fieldset>
<legend>* = required</legend>
<label for="input1">input 1 *</label><input id="input1" name="input1" />
</fieldset>
</form>
</code></pre>
<p>But that doesn't really work out with how fieldsets are rendered. Is this just a ambigious naming in HTML, or is it my misunderstanding of the English word 'legend'?</p>
<hr>
<p>Edit: fixed some errors ;-)</p>
|
[
{
"answer_id": 253413,
"author": "Gareth",
"author_id": 31582,
"author_profile": "https://Stackoverflow.com/users/31582",
"pm_score": 4,
"selected": true,
"text": "FIELDSET LEGEND LEGEND FIELDSET FIELDSET"
},
{
"answer_id": 253419,
"author": "Dan Maharry",
"author_id": 2756,
"author_profile": "https://Stackoverflow.com/users/2756",
"pm_score": 1,
"selected": false,
"text": "<form>\n <fieldset>\n <legend>legend</legend>\n <input name=\"input1\" />\n </fieldset>\n</form>\n"
},
{
"answer_id": 253449,
"author": "Már Örlygsson",
"author_id": 16271,
"author_profile": "https://Stackoverflow.com/users/16271",
"pm_score": 1,
"selected": false,
"text": "<legend> <fieldset> fieldset <input> <legend> <div> <p> <li> <input> <legend>"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253410",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/909/"
] |
253,415
|
<p>I'm having trouble getting the right number of elements in the ArrayList <code>alt</code> in the JSP page below. When I view the JSP it shows the size is 1 (<code><%=alt.size()%></code>) when it should be 3; I think I'm adding that method to the array in the generator class, so I don't understand why it's showing 1.</p>
<p>This is my jsp page:</p>
<pre><code><%
ArrayList<Alert> a = AlertGenerator.getAlert();
pageContext.setAttribute("alt", a);
%>
<c:forEach var="alert" items="${alt}" varStatus="status" >
<p>You have <%=alt.size()%> Active Alert(s)</p>
<ul>
<li><a href="#" class="linkthree">${alert.alert1}</a></li>
<li><a href="#" class="linkthree">${alert.alert2}</a></li>
<li><a href="#" class="linkthree">${alert.alert3}</a></li>
</ul>
</c:forEach>
</code></pre>
<p>This is class that generates the alerts:</p>
<pre><code>package com.cg.mock;
import java.util.ArrayList;
public class AlertGenerator {
public static ArrayList<Alert> getAlert() {
ArrayList<Alert> alt = new ArrayList<Alert>();
alt.add(new Alert("alert1","alert2","alert3"));
return alt;
}
}
</code></pre>
<p>This is my bean class:</p>
<pre><code>package com.cg.mock;
public class Alert {
String alert1;
String alert2;
String alert3;
public Alert(String alert1, String alert2,String alert3) {
super();
this.alert1 = alert1;
this.alert2 = alert2;
this.alert3 = alert3;
}
public String getAlert1() {
return alert1;
}
public void setAlert1(String alert1) {
this.alert1 = alert1;
}
public String getAlert2() {
return alert2;
}
public void setAlert2(String alert2) {
this.alert2 = alert2;
}
public String getAlert3() {
return alert3;
}
public void setAlert3(String alert3) {
this.alert3 = alert3;
}
}
</code></pre>
|
[
{
"answer_id": 253432,
"author": "Jonny Buchanan",
"author_id": 6760,
"author_profile": "https://Stackoverflow.com/users/6760",
"pm_score": 1,
"selected": false,
"text": "3 add List"
},
{
"answer_id": 253433,
"author": "toolkit",
"author_id": 3295,
"author_profile": "https://Stackoverflow.com/users/3295",
"pm_score": 2,
"selected": false,
"text": "alt.add(new Alert(\"alert1\",\"alert2\",\"alert3\"));\n public class Alert {\n private String description;\n private String status;\n private Date raisedOn;\n public Alert(String description, String status) {\n this.description = description;\n this.status = status;\n this.raisedOn = new Date();\n }\n public String getDescription() { return description; }\n public String getStatus() { return status; }\n public Date getRaisedOn() { return raisedOn; }\n}\n\n\n....\nalt.add(new Alert(\"Disk Almost Full\", \"Warning\"));\nalt.add(new Alert(\"Disk Full\", \"Severe\"));\n...\n\n...\n<table>\n <tr><th>Description</th><th>Status</th><th>Raised</th></td>\n <c:forEach var=\"alert\" items=\"${alt}\">\n <tr>\n <td><c:out value=\"${alert.description}\"/></td>\n <td><c:out value=\"${alert.status}\"/></td>\n <td><c:out value=\"${alert.raisedOn}\"/></td>\n </tr>\n </c:forEach>\n</table>\n"
},
{
"answer_id": 253601,
"author": "Vincent Ramdhanie",
"author_id": 27439,
"author_profile": "https://Stackoverflow.com/users/27439",
"pm_score": 1,
"selected": true,
"text": "package com.cg.mock;\n\npublic class Alert {\n String alert1;\n public Alert(String alert1) {\n super();\n this.alert1 = alert1; \n }\n public String getAlert1() {\n return alert1;\n }\n public void setAlert1(String alert1) {\n this.alert1 = alert1;\n }\n}\n ArrayList<Alert> alt = new ArrayList<Alert>();\n\nalt.add(new Alert(\"alert1\");\nalt.add(new Alert(\"alert2\");\nalt.add(new Alert(\"alert3\");\n\nreturn alt;\n <p>You have <%=alt.size()%> Active Alert(s)</p>\n<ul>\n<c:forEach var=\"alert\" items=\"${alt}\" varStatus=\"status\" > \n\n <li><a href=\"#\" class=\"linkthree\">${alert.alert1}</a></li>\n\n </c:forEach>\n </ul>\n"
},
{
"answer_id": 253623,
"author": "Brian Matthews",
"author_id": 1969,
"author_profile": "https://Stackoverflow.com/users/1969",
"pm_score": 0,
"selected": false,
"text": "<%\n ArrayList<Alert> a = AlertGenerator.getAlert();\n pageContext.setAttribute(\"alt\", a);\n%>\n<p>You have <%=alt.size()%> Active Alert(s)</p>\n<ul>\n <c:forEach var=\"alert\" items=\"${alt}\" varStatus=\"status\" >\n <li><a href=\"#\" class=\"linkthree\">${alert.alert}</a></li>\n </c:forEach>\n</ul>\n package com.cg.mock;\n\nimport java.util.ArrayList;\n\npublic class AlertGenerator {\n\n public static ArrayList<Alert> getAlert() {\n\n ArrayList<Alert> alt = new ArrayList<Alert>();\n\n alt.add(new Alert(\"alert2\"));\n alt.add(new Alert(\"alert2\"));\n alt.add(new Alert(\"alert3\"));\n\n return alt;\n }\n}\n package com.cg.mock;\n\npublic class Alert {\n String alert;\n public Alert(String alert) {\n this.alert = alert;\n }\n public String getAlert() {\n return alert;\n }\n public void setAlert(String alert) {\n this.alert = alert;\n }\n}\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253415",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28557/"
] |
253,426
|
<p>Working with TCL and I'd like to implement something like the <a href="http://en.wikipedia.org/wiki/Strategy_pattern" rel="nofollow noreferrer">Strategy Pattern</a>. I want to pass in the "strategy" for printing output in a TCL function, so I can easily switch between printing to the screen and printing to a log file. What's the best way to do this in TCL?</p>
|
[
{
"answer_id": 254632,
"author": "Jackson",
"author_id": 29061,
"author_profile": "https://Stackoverflow.com/users/29061",
"pm_score": 5,
"selected": true,
"text": "proc A { x } {\n puts $x\n}\n\nset strat A\n$strat Hello\n"
},
{
"answer_id": 255441,
"author": "ramanman",
"author_id": 11093,
"author_profile": "https://Stackoverflow.com/users/11093",
"pm_score": 2,
"selected": false,
"text": "proc PrintToPDF {document} {\n<snip logic>\n}\n\nproc PrintToScreen {document} {\n<snip logic>\n}\n\nproc PrintToPrinter {document} {\n<snip logic>\n}\n\n\nset document \"my cool formatted document here\"\n\nset printMethod \"printer\"\n\n\nswitch -- $printMethod {\n \"printer\" {\n set pMethodName \"PrintToPrinter\"\n }\n \"pdf\" {\n set pMethodName \"PrintToScreen\"\n }\n \"screen\" {\n set pMethodName \"PrintToPDF\"\n }\n}\n\n$pMethodName $document\n"
},
{
"answer_id": 274443,
"author": "Michael Mathews",
"author_id": 21242,
"author_profile": "https://Stackoverflow.com/users/21242",
"pm_score": 3,
"selected": false,
"text": "\nproc foo { a } {\n puts \"a = $a\"\n}\n\nproc bar { b } {\n puts \"b = $b\"\n}\n\nproc foobar { c } {\n $c 1\n}\n\nfoobar foo\nfoobar bar\n"
},
{
"answer_id": 1181202,
"author": "SingleNegationElimination",
"author_id": 65696,
"author_profile": "https://Stackoverflow.com/users/65696",
"pm_score": 2,
"selected": false,
"text": "eval set strategy {\n puts $x\n}\n\nset x \"Hello\"\neval $strategy\nunset x\n set x \"Hello\"\nif 1 $strategy\nunset x\n if eval $strategy % uplevel upvar set strategy {\n puts %x\n}\n\nif 1 [string map [list %% % %x Hello] $strategy]\n eval if 1 set strategy \"$localvar %x\" apply proc set strategy [list {x} {\n puts $x\n}]\n\napply $strategy \"Hello\"\n"
},
{
"answer_id": 1292509,
"author": "name",
"author_id": 158263,
"author_profile": "https://Stackoverflow.com/users/158263",
"pm_score": 1,
"selected": false,
"text": "% set val 4444\n4444\n\n% set pointer val\nval\n\n% eval puts $$pointer\n4444\n\n% puts [ set $pointer ]\n4444\n\n% set tmp [ set $pointer ]\n4444\n"
},
{
"answer_id": 50622878,
"author": "user1134991",
"author_id": 1134991,
"author_profile": "https://Stackoverflow.com/users/1134991",
"pm_score": 0,
"selected": false,
"text": "[namespace current ]::proc_name"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253426",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1541/"
] |
253,431
|
<p>I have a WPF control, that has a list of "Investors", and in the right column of the list, a "Delete" button.</p>
<p>I could either waste some time making an image of an "x" in photoshop. Or, I could just use Wingdings font and set the content to "Õ" (which makes a cool looking delete button).</p>
<p>Is this appropriate? My thinking is... while not every font family is on every computer, I'm pretty sure that it's safe to say that if you're running my WPF Windows Forms program, then you have Wingdings.</p>
<p>What do you think? Please try to give statistics (not just feelings) on the matter. Should I worry about font size? etc.</p>
|
[
{
"answer_id": 253444,
"author": "Bob King",
"author_id": 6897,
"author_profile": "https://Stackoverflow.com/users/6897",
"pm_score": 5,
"selected": true,
"text": " <Style x:Key=\"DeleteButtonStyle\" TargetType=\"{x:Type Button}\">\n <Setter Property=\"HorizontalAlignment\" Value=\"Stretch\"/>\n <Setter Property=\"HorizontalContentAlignment\" Value=\"Center\"/>\n <Setter Property=\"VerticalAlignment\" Value=\"Stretch\"/>\n <Setter Property=\"VerticalContentAlignment\" Value=\"Center\"/>\n <Setter Property=\"Cursor\" Value=\"Hand\"/>\n <Setter Property=\"Template\">\n <Setter.Value>\n <ControlTemplate TargetType=\"{x:Type Button}\">\n <Grid HorizontalAlignment=\"Center\" VerticalAlignment=\"Center\">\n <Path Name=\"Circle\" Data=\"F1 M 0 7.5 A 7.5 7.5 0 1 1 15 7.5 A 7.5 7.5 0 1 1 0 7.5\"/>\n <Path Fill=\"White\" Data=\"F1 M 7.5 6 L 10.5,3 12,4.5 9,7.5 12,10.5 10.5,12 7.5,9 4.5,12 3,10.5 6,7.5 3,4.5 4.5,3 Z\"/>\n </Grid>\n <ControlTemplate.Triggers>\n <Trigger Property=\"IsMouseOver\" Value=\"True\">\n <Setter Property=\"Fill\" TargetName=\"Circle\" Value=\"SlateGray\"/>\n </Trigger>\n <Trigger Property=\"IsMouseOver\" Value=\"False\">\n <Setter Property=\"Fill\" TargetName=\"Circle\" Value=\"DarkGray\"/>\n </Trigger>\n <DataTrigger Binding=\"{Binding}\" Value=\"{x:Null}\">\n <Setter Property=\"Visibility\" Value=\"Hidden\"/>\n </DataTrigger>\n </ControlTemplate.Triggers>\n </ControlTemplate>\n </Setter.Value>\n </Setter>\n <Setter Property=\"ToolTip\" Value=\"Delete This Item\"/>\n </Style>\n"
},
{
"answer_id": 1981969,
"author": "imam kuncoro",
"author_id": 241120,
"author_profile": "https://Stackoverflow.com/users/241120",
"pm_score": 0,
"selected": false,
"text": "static Font wingdings2 = new Font(\"Wingdings 2\", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(2)));\n myTextBoxt.Font = wingdings2;\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253431",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11917/"
] |
253,435
|
<p>I was loading a Bitmap Image from a File. When I tried to save the Image to another file I got the following error "A generic error occurred in GDI+". I believe this is because the file is locked by the image object.</p>
<p>Ok so tried calling the Image.Clone function. This still locks the file.</p>
<p>hmm. Next I try loading a Bitmap Image from a FileStream and load the image into memory so GDI+ doesn't lock the file. This works great except I need to generate thumbnails using Image.GetThumbnailImage method it throws an out of memory exception. Apparently I need to keep the stream open to stop this exception but if I keep the stream open then the file remains locked.</p>
<p>So no good with that method. In the end I created a copy of the file. So now I have 2 versions of the file. 1 I can lock and manipulate in my c# program. This other original file remains unlocked to which I can save modifications to. This has the bonus of allowing me to revert changes even after saving them because I'm manipulating the copy of the file which cant change.</p>
<p>Surely there is a better way of achieving this without having to have 2 versions of the image file. Any ideas?</p>
|
[
{
"answer_id": 253493,
"author": "Sciolist",
"author_id": 16045,
"author_profile": "https://Stackoverflow.com/users/16045",
"pm_score": 2,
"selected": false,
"text": "var stream = new FileStream(\"original-image\", FileMode.Open);\nvar bufr = new byte[stream.Length];\nstream.Read(bufr, 0, (int)stream.Length);\nstream.Dispose();\n\nvar memstream = new MemoryStream(bufr);\nvar image = Image.FromStream(memstream);\n"
},
{
"answer_id": 262032,
"author": "Crippeoblade",
"author_id": 6204,
"author_profile": "https://Stackoverflow.com/users/6204",
"pm_score": 3,
"selected": true,
"text": " //open the file\n Image i = Image.FromFile(path);\n\n //create temporary\n Image t=new Bitmap(i.Width,i.Height);\n\n //get graphics\n Graphics g=Graphics.FromImage(t);\n\n //copy original\n g.DrawImage(i,0,0);\n\n //close original\n i.Dispose();\n\n //Can now save\n t.Save(path)\n"
},
{
"answer_id": 28983950,
"author": "schlafanzug93",
"author_id": 4592266,
"author_profile": "https://Stackoverflow.com/users/4592266",
"pm_score": 1,
"selected": false,
"text": " public void SaveHeightmap(string path)\n {\n if (File.Exists(path))\n {\n Bitmap bitmap = new Bitmap(image); //create bitmap from image\n image.Dispose(); //delete image, so the file\n\n bitmap.Save(path); //save bitmap\n\n image = (Image) bitmap; //recreate image from bitmap\n }\n else\n //...\n }\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253435",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6204/"
] |
253,437
|
<p>It appears that Directory.GetFiles() in C# modifies the Last access date of a file.
I've googled for hours and can't seem to find a work around for this issue. Is there anyway to keep all the MAC (Modified, Accessed, Created) attributes of a file?
I'm using Directory.GetDirectories(), Directory.GetFiles(), and FileInfo.</p>
<p>Also, the fi.LastAccessTime is giving strange results -- the date is correct, however, the time is off by 2 minutes, or a few hours.</p>
<pre><code>Time of function execution: 10/31/2008 8:35 AM
Program Shows As Last Access Time
0_PDFIndex.html - 10/31/2008 8:17:24 AM
AdvancedArithmetic.pdf - 10/31/2008 8:31:05 AM
AdvancedControlStructures.pdf - 10/30/2008 1:18:00 PM
AoAIX.pdf - 10/30/2008 1:18:00 PM
AoATOC.pdf - 10/30/2008 12:29:51 PM
AoATOC2.pdf - 10/30/2008 1:18:00 PM
Actual Last Access Time
0_PDFIndex.html - 10/31/2008 8:17 AM
AdvancedArithmetic.pdf - 10/30/2008 12:29 PM
AdvancedControlStructures.pdf - 10/30/2008 12:29 PM
AoAIX.pdf - 10/30/2008 12:29 PM
AoATOC.pdf - 10/30/2008 12:29 PM
AoATOC2.pdf - 10/30/2008 12:29 PM
</code></pre>
<p>Below is the method I'm using. If you require more information, please let me know.</p>
<p>Thanks!</p>
<pre><code>public void PopulateTreeView(string directoryValue, ref TreeNode parentNode)
{
string[] directoryArray = Directory.GetDirectories(directoryValue);
string[] fileArray = Directory.GetFiles(directoryValue, "*.*", SearchOption.AllDirectories);
try
{
#region Directories
if (directoryArray.Length != 0)
{
foreach (string directory in directoryArray)
{
DirectoryInfo di = new DirectoryInfo(directory);
TreeNode dirNode = parentNode.Nodes.Add(di.Name);
FileNode fn = new FileNode();
fn.bIsDir = true;
fn.dir = di;
dirNode.Tag = fn;
PopulateTreeView(directory, ref dirNode);
Application.DoEvents();
}
}
#endregion
#region Files
if (fileArray.Length != 0)
{
foreach (string file in fileArray)
{
FileInfo fi = new FileInfo(file);
TreeNode fileNode = parentNode.Nodes.Add(fi.Name);
FileNode fn = new FileNode();
fn.bIsDir = false;
fn.file = fi;
fileNode.Tag = fn;
fileNode.ImageIndex = 1;
Console.WriteLine(fi.Name + " - " + fi.LastAccessTime);
}
}
#endregion
}
catch (UnauthorizedAccessException)
{
parentNode.Nodes.Add("Access denied");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
Application.DoEvents();
}
}
</code></pre>
<hr>
<p>i know the differences between the attributes. What i need is for the file to remain exactly the same all attributes and meta-data, as if my program never touched the file; this includes the last access date.</p>
|
[
{
"answer_id": 253461,
"author": "dbkk",
"author_id": 838,
"author_profile": "https://Stackoverflow.com/users/838",
"pm_score": 4,
"selected": true,
"text": "fsutil behavior set disablelastaccess 1\n Process.Start(\"fsutil\", \"behavior set disablelastaccess 1\").WaitForExit();\n"
},
{
"answer_id": 253708,
"author": "Alnitak",
"author_id": 6782,
"author_profile": "https://Stackoverflow.com/users/6782",
"pm_score": 0,
"selected": false,
"text": "hdd \"write protect\""
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253437",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33082/"
] |
253,446
|
<p>How does one add a comment to an MS Access Query, to provide a description of what it does?</p>
<p>Once added, how can one retrieve such comments programmatically?</p>
|
[
{
"answer_id": 253784,
"author": "Patrick Cuff",
"author_id": 7903,
"author_profile": "https://Stackoverflow.com/users/7903",
"pm_score": 5,
"selected": true,
"text": "Dim db As Database\nDim qry As QueryDef\n\nSet db = Application.CurrentDb\nSet qry = db.QueryDefs(\"myQuery\")\n\nDebug.Print qry.Properties(\"Description\")\n"
},
{
"answer_id": 4763339,
"author": "JTR",
"author_id": 585005,
"author_profile": "https://Stackoverflow.com/users/585005",
"pm_score": 2,
"selected": false,
"text": "SELECT \"2011-01-21;JTR;Added FIELD02;;2011-01-20;JTR;Added qryHISTORY;;\" as qryHISTORY, ...rest of query here...\n qryHISTORY FIELD01 FIELD02 ...\n2011-01-21;JTR;Added FIELD02;;2011-01-20;JTR;Added qryHISTORY;;\" 0000001 ABCDEF ...\n"
},
{
"answer_id": 12311190,
"author": "Patrick Boylan",
"author_id": 1653616,
"author_profile": "https://Stackoverflow.com/users/1653616",
"pm_score": 2,
"selected": false,
"text": "Dim dbs As DAO.Database\nDim qry As DAO.QueryDef\n\nSet dbs = CurrentDb\n'put your comments wherever in your program makes the most sense\ndbs.QueryDefs(\"qryName\").SQL = \"SELECT whatever.fields FROM whatever_table;\"\nDoCmd.OpenQuery \"qryname\"\n"
},
{
"answer_id": 12448538,
"author": "Jarad Pillemer",
"author_id": 1675906,
"author_profile": "https://Stackoverflow.com/users/1675906",
"pm_score": 1,
"selected": false,
"text": "Field: | Comment |ContractStatus | ProblemDealtWith | ...... |\n\nTable: | ElecContracts |ElecContracts | ElecContracts | ...... |\n\nSort: \n\nShow: \n\nCriteria | <> \"all problems are | \"objection\" Or |\n\n | picked up with this | \"rejected\" Or |\n\n | criteria\" OR Is Null | \"rolled\" |\n\n | OR \"\"\n <>"
},
{
"answer_id": 28096339,
"author": "Dan",
"author_id": 839501,
"author_profile": "https://Stackoverflow.com/users/839501",
"pm_score": 5,
"selected": false,
"text": "Where Select\n ...\nFrom\n ...\nWhere\n ....\n And \"Comment: FYI, Access doesn't support normal comments!\"<>\"\"\n"
},
{
"answer_id": 66747336,
"author": "NewSites",
"author_id": 5803910,
"author_profile": "https://Stackoverflow.com/users/5803910",
"pm_score": 1,
"selected": false,
"text": "WHERE iif() A / B\n iif(\"Comment: B is never 0.\" = \"\", \"\", A / B)\n iif(false, \"Comment: B is never 0.\", A / B)\n iif(0, \"Comment: B is never 0.\", A / B)\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253446",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6613/"
] |
253,460
|
<p>What is their use if when you call the method, it might not exist?</p>
<p>Does that mean that you would be able to dynamically create a method on a dynamic object?</p>
<p>What are the practical use of this?</p>
|
[
{
"answer_id": 253473,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 5,
"selected": true,
"text": "IDynamicMetaObject DynamicObject document.RootElement.Person[5].Name[\"Attribute\"]"
},
{
"answer_id": 463864,
"author": "Adam Ruth",
"author_id": 10262,
"author_profile": "https://Stackoverflow.com/users/10262",
"pm_score": 1,
"selected": false,
"text": "object value = GetSomeObject();\nMethod method = value.GetType().GetMethod(\"DoSomething\");\nmethod.Invoke(value, new object[] { 1, 2, 3 });\n IDynamicObject value = GetSomeObject();\nvalue.DoSomething(1, 2, 3);\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253460",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24975/"
] |
253,468
|
<p>For my apps, I store some configuration file in xml along with the assembly(exe), and something other temporary files for proccessing purpose. </p>
<p>I found some quirk with <code>".\\"</code> and <code>Application.StartupPath</code>.</p>
<p>I've been using </p>
<pre><code>String configPath = ".\\config.xml";
</code></pre>
<p>It works fine until I called <code>OpenFIleDialog</code> to open some files in other folders, the statement above failed. Apparently ".\" is referring to "CurrentDirectory", which changes every time when we browse to another folder.</p>
<p>At some point, I was using </p>
<pre><code>String configPath = Path.Combine(Application.StartupPath + "config.xml");
</code></pre>
<p>At some point, when I need to execute this assembly from another folder by using <code>Process.Start()</code>, things start to fall apart. Apparently the working directory is not set properly, and <code>Application.StartupPath</code> is actually referring to working directory instead of the directory of which the assembly is executing, as I've assumed. So I have to resort to using ProcessInfo to setup the working directory to the assembly's directory. I also had problem with this when I was writing VSTO.</p>
<p>So, my question is, what's the best, simplest and most assured way to get the current directory that the assembly is executing, without those quirks(or misunderstanding) that I've just mentioned?</p>
<p>EDIT: I meant to get the directory which the assembly reside</p>
<p>EDIT: According to MSDN on <a href="http://msdn.microsoft.com/en-us/library/system.appdomain.basedirectory.aspx" rel="noreferrer">AppDomain.BaseDirectory</a>, it seems that it can be changes during runtime, which is what I don't want(Just to clarify, not that I don't want to allow changing BaseDirectory, but rather, when I retrieve it without knowing for sure whether it's been changed)</p>
<p>EDIT: I've notice that a related question was posted much earlier. <a href="https://stackoverflow.com/questions/158219/what-would-cause-the-current-directory-of-an-executing-app-to-change">What would cause the current directory of an executing app to change?</a></p>
<p>Thanks guys for the answer.</p>
|
[
{
"answer_id": 253486,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 3,
"selected": false,
"text": "Environment.CurrentDirectory Path.GetDirectoryName(typeof(Foo).Assembly.ManifestModule.FullyQualifiedName)"
},
{
"answer_id": 253500,
"author": "tafa",
"author_id": 22186,
"author_profile": "https://Stackoverflow.com/users/22186",
"pm_score": 3,
"selected": false,
"text": "System.Reflection.Assembly.GetExecutingAssembly().CodeBase\n"
},
{
"answer_id": 253502,
"author": "GalacticCowboy",
"author_id": 29638,
"author_profile": "https://Stackoverflow.com/users/29638",
"pm_score": 1,
"selected": false,
"text": "string currentAssemblyFile = System.Reflection.Assembly.GetExecutingAssembly().Location;\n"
},
{
"answer_id": 253504,
"author": "korro",
"author_id": 22650,
"author_profile": "https://Stackoverflow.com/users/22650",
"pm_score": 7,
"selected": true,
"text": "System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location))\n"
},
{
"answer_id": 253505,
"author": "Mat Nadrofsky",
"author_id": 26853,
"author_profile": "https://Stackoverflow.com/users/26853",
"pm_score": 2,
"selected": false,
"text": "string path;\npath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase );\nMessageBox.Show( path );\n"
},
{
"answer_id": 253513,
"author": "rslite",
"author_id": 15682,
"author_profile": "https://Stackoverflow.com/users/15682",
"pm_score": 3,
"selected": false,
"text": "AppDomain.Current.BaseDirectory\n"
},
{
"answer_id": 284435,
"author": "John Sibly",
"author_id": 1078,
"author_profile": "https://Stackoverflow.com/users/1078",
"pm_score": 4,
"selected": false,
"text": "static public string AssemblyLoadDirectory\n{\n get\n {\n string codeBase = Assembly.GetCallingAssembly().CodeBase;\n UriBuilder uri = new UriBuilder(codeBase);\n string path = Uri.UnescapeDataString(uri.Path);\n return Path.GetDirectoryName(path);\n }\n}\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253468",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20007/"
] |
253,469
|
<p>I have a <code>CMFCRibbonStatusBar</code> in my mainframe to which I add a <code>CMFCRibbonButtonsGroup</code> which again has a <code>CMFCRibbonButton</code>. This button has the same ID as a menu entry.</p>
<p>Creating the button is done as follows:</p>
<pre><code>CMFCRibbonButtonsGroup* pBGroup = new CMFCRibbonButtonsGroup();
CMFCToolBarImages images;
images.SetImageSize(CSize(32, 16)); // Non-square bitmaps
if(images.Load(IDB_STATUSBAR_IMAGES))
{
pBGroup->SetImages(&images, NULL, NULL);
}
m_pStatusButton = new CMFCRibbonButton(ID_STATUS_SHOWSTATUS,
_T(""),
IMAGEINDEX_DEFAULTSTATUS);
pBGroup->AddButton(m_pStatusButton);
m_wndStatusBar.AddExtendedElement(pBGroup, _T(""));
</code></pre>
<p>I want to use this button as a status indicator.</p>
<p>I want to display a tool tip in the following two cases:</p>
<ul>
<li>when the status changes and</li>
<li>when the user moves the mouse over the button.</li>
</ul>
<p>I have no idea how to start in the first place. I have looked at the <code>ToolTipDemo</code> and <code>DlgToolTips</code> sample projects but couldn't figure out how to do it since all they do is display tooltips for the toolbar items or dialog buttons (<code>CWnd</code>-derived instead of <code>CMFCRibbonButton</code>).</p>
<p>If you are familiar with the <code>ToolTipDemo</code> sample project: Since there seem to be several ways of doing things, I would prefer the tooltip to look like the "Extended Visual Manager-based" tool tip as <a href="http://img394.imageshack.us/my.php?image=tooltiptm7.png" rel="nofollow noreferrer">shown in this screenshot</a>.</p>
<p>Thanks!</p>
|
[
{
"answer_id": 505535,
"author": "demoncodemonkey",
"author_id": 61697,
"author_profile": "https://Stackoverflow.com/users/61697",
"pm_score": 3,
"selected": true,
"text": "SetToolTipText SetDescription CMFCRibbonButton* pBtn = new CMFCRibbonButton(12345, _T(\"\"), 1);\npBtn->SetToolTipText(\"This is the bold Title\");\npBtn->SetDescription(\"This is the not-so-bold Description\");\npGroup->AddButton(pBtn);\n"
},
{
"answer_id": 11353849,
"author": "David Carr",
"author_id": 695807,
"author_profile": "https://Stackoverflow.com/users/695807",
"pm_score": 0,
"selected": false,
"text": "CMFCRibbonButton CMFCRibbonButtonGroup CMFCRibbonStatusBar CMFCRibbonButton() bAlwaysShowDescription SetDescription() SetDescription() bAlwaysShowDescription SetDescription() bAlwaysShowDescription bAlwaysShowDescription SetDescription() bAlwaysShowDescription SetDescription()"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253469",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27596/"
] |
253,475
|
<pre><code>struct elem
{
int i;
char k;
};
elem user; // compile error!
struct elem user; // this is correct
</code></pre>
<p>In the above piece of code we are getting an error for the first declaration. But this error doesn't occur with a C++ compiler. In C++ we don't need to use the keyword struct again and again.
<p>So why doesn't anyone update their C compiler, so that we can use structure without the keyword as in C++ ?
<p>Why doesn't the C compiler developer remove some of the glitches of C, like the one above, and update with some advanced features without damaging the original concept of C?
<p>Why it is the same old compiler not updated from 1970's ?
<p>Look at visual studio etc.. It is frequently updated with new releases and for every new release we have to learn some new function usage (even though it is a problem we can cope up with it). We will also get updated with the new compiler if there is any.
<p>Don't take this as a silly question. Why it is not possible? It could be developed without any incompatibility issues (without affecting the code that was developed on the present / old compiler)
<p>Ok, lets develop the new C language, C+, which is in between C and C++ which removes all glitches of C and adds some advanced features from C++ while keeping it useful for specific applications like system level applications, embedded systems etc.</p>
|
[
{
"answer_id": 253501,
"author": "Bill the Lizard",
"author_id": 1288,
"author_profile": "https://Stackoverflow.com/users/1288",
"pm_score": 2,
"selected": false,
"text": "struct elem\n{\n int i;\n char k;\n};\nelem user;\n"
},
{
"answer_id": 253509,
"author": "Ilya",
"author_id": 6807,
"author_profile": "https://Stackoverflow.com/users/6807",
"pm_score": 2,
"selected": false,
"text": "foo test;\n struct foo test;\n"
},
{
"answer_id": 253542,
"author": "Miro Kropacek",
"author_id": 21009,
"author_profile": "https://Stackoverflow.com/users/21009",
"pm_score": 4,
"selected": false,
"text": "typedef struct\n{\n int i;\n char k;\n} elem;\n\nelem user;\n"
},
{
"answer_id": 253814,
"author": "Michael Carman",
"author_id": 8233,
"author_profile": "https://Stackoverflow.com/users/8233",
"pm_score": 3,
"selected": false,
"text": "(char *) p += 100;\n p p"
},
{
"answer_id": 254300,
"author": "Michael Burr",
"author_id": 12711,
"author_profile": "https://Stackoverflow.com/users/12711",
"pm_score": 2,
"selected": false,
"text": "// //"
},
{
"answer_id": 255507,
"author": "Chris Young",
"author_id": 9417,
"author_profile": "https://Stackoverflow.com/users/9417",
"pm_score": 3,
"selected": false,
"text": "struct elem\n{\n int foo;\n};\n\nint elem;\n foo(void); /* declare a function foo that takes no parameters and returns an int */\n"
},
{
"answer_id": 258644,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "#include <stdio.h>\n\ntypedef struct\n{\n int a;\n int b;\n} X;\n\nint main(void)\n{\n union X\n {\n int a;\n int b;\n };\n\n X x;\n x.a = 1;\n x.b = 2;\n\n printf(\"%d\\n\", x.a);\n\n return 0;\n}\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253475",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31116/"
] |
253,490
|
<p>I have a problem with the <a href="http://freetextbox.com/" rel="nofollow noreferrer">FreeTextBox</a> rich Text Editor in my ASP.NET site. The problem occurs when I access the site with firefox, and I have a freetextbox instance in a hidden div. The hidden div might also be an AJAX Tab Panel. The actual problem is that when the page loads it throws an uncaught exception (firebug shows the StoreHtml() function) and halts the postback!! </p>
<p>Is anywhere of the problem and a solution for it?? </p>
<p>Thanks</p>
|
[
{
"answer_id": 258210,
"author": "Vegard Larsen",
"author_id": 1606,
"author_profile": "https://Stackoverflow.com/users/1606",
"pm_score": 3,
"selected": true,
"text": ".hiddentab\n{\n position: absolute;\n left: -99999999999999;\n}\n"
},
{
"answer_id": 268790,
"author": "Nikos Steiakakis",
"author_id": 932,
"author_profile": "https://Stackoverflow.com/users/932",
"pm_score": 2,
"selected": false,
"text": "function OvrdSubmit()\n{\n var ftbSubmit=document.forms[0].onsubmit;\n if (typeof(ftbSubmit) == 'function')\n {\n document.forms[0].onsubmit = function()\n {\n try{ftbSubmit();}\n catch(ex){}\n }\n }\n\n // We are ok\n return true;\n}\n ClientScript.RegisterOnSubmitStatement(this.GetType(), String.Concat(this.ClientID, \"_OnSubmit\"), \"javascript: return OvrdSubmit();\");\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253490",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/932/"
] |
253,492
|
<p>I was looking at the Java code for <code>LinkedList</code> and noticed that it made use of a static nested class, <code>Entry</code>.</p>
<pre><code>public class LinkedList<E> ... {
...
private static class Entry<E> { ... }
}
</code></pre>
<p>What is the reason for using a static nested class, rather than an normal inner class?</p>
<p>The only reason I could think of, was that Entry doesn't have access to instance variables, so from an OOP point of view it has better encapsulation. </p>
<p>But I thought there might be other reasons, maybe performance. What might it be?</p>
<p>Note. I hope I have got my terms correct, I would have called it a static inner class, but I think this is wrong: <a href="http://java.sun.com/docs/books/tutorial/java/javaOO/nested.html" rel="noreferrer">http://java.sun.com/docs/books/tutorial/java/javaOO/nested.html</a></p>
|
[
{
"answer_id": 253521,
"author": "matt b",
"author_id": 4249,
"author_profile": "https://Stackoverflow.com/users/4249",
"pm_score": 9,
"selected": true,
"text": "LinkedList.Entry LinkedList Entry Map.Entry"
},
{
"answer_id": 253575,
"author": "Vinze",
"author_id": 26859,
"author_profile": "https://Stackoverflow.com/users/26859",
"pm_score": 2,
"selected": false,
"text": "package test;\n\npublic class UpperClass {\npublic static class StaticInnerClass {}\n\npublic class InnerClass {}\n\npublic static void main(String[] args) {\n // works\n StaticInnerClass stat = new StaticInnerClass();\n // doesn't compile\n InnerClass inner = new InnerClass();\n}\n}\n"
},
{
"answer_id": 20608594,
"author": "user1923551",
"author_id": 1923551,
"author_profile": "https://Stackoverflow.com/users/1923551",
"pm_score": 4,
"selected": false,
"text": "/* AUTO-GENERATED FILE. DO NOT MODIFY.\n *\n * This class was automatically generated by the\n * aapt tool from the resource data it found. It\n * should not be modified by hand.\n */\n\npackage com.techpalle.b17_testthird;\n\npublic final class R {\n public static final class drawable {\n public static final int ic_launcher=0x7f020000;\n }\n public static final class layout {\n public static final int activity_main=0x7f030000;\n }\n public static final class menu {\n public static final int main=0x7f070000;\n }\n public static final class string {\n public static final int action_settings=0x7f050001;\n public static final int app_name=0x7f050000;\n public static final int hello_world=0x7f050002;\n }\n}\n"
},
{
"answer_id": 35716726,
"author": "Gaurav Tiwari",
"author_id": 5961515,
"author_profile": "https://Stackoverflow.com/users/5961515",
"pm_score": -1,
"selected": false,
"text": "class car{\n class wheel{\n\n }\n}\n Outer 0=new Outer();\nOuter.Inner i= O.new Inner(); Inner i=new Inner(); Outer 0=new Outer();\nOuter.Inner i= O.new Inner(); this.member-current inner class\nouterclassname.this--outer class final,abstract,strictfp,+private,protected,static class outer{\n\n int x=10;\n static int y-20;\n\n public void m1() {\n int i=30;\n final j=40;\n\n class inner{\n\n public void m2() {\n // have accees x,y and j\n }\n }\n }\n}\n"
},
{
"answer_id": 40192585,
"author": "JenkinsY",
"author_id": 6088463,
"author_profile": "https://Stackoverflow.com/users/6088463",
"pm_score": 0,
"selected": false,
"text": "Comparator public class Student {\n public static final Comparator<Student> BY_NAME = new ByName();\n private final String name;\n ...\n private static class ByName implements Comparator<Student> {\n public int compare() {...}\n }\n}\n static"
},
{
"answer_id": 40267521,
"author": "seenimurugan",
"author_id": 745401,
"author_profile": "https://Stackoverflow.com/users/745401",
"pm_score": 4,
"selected": false,
"text": "class OuterClass {\n private OuterClass(int x) {\n System.out.println(\"x: \" + x);\n }\n \n static class InnerClass {\n public static void test() {\n OuterClass outer = new OuterClass(1);\n }\n }\n}\n\npublic class Test {\n public static void main(String[] args) {\n OuterClass.InnerClass.test();\n // OuterClass outer = new OuterClass(1); // It is not possible to create outer instance from outside.\n }\n}\n"
},
{
"answer_id": 63950042,
"author": "Sahil Gupta",
"author_id": 2484748,
"author_profile": "https://Stackoverflow.com/users/2484748",
"pm_score": 1,
"selected": false,
"text": "public class Message {\n\nprivate MessageType messageType; // component of parent class\n\npublic enum MessageType {\n SENT, RECEIVE;\n}\n}\n\n\n\nclass Otherclass {\n\npublic boolean isSent(Message message) {\n if (message.getMessageType() == MessageType.SENT) { // accessible at other places as well\n return true;\n }\n return false;\n}\n}\n public class Message {\n\n private Content content; // Component of message class\n\n private static class Content { // can only be a component of message class\n\n private String body;\n private int sentBy;\n\n public String getBody() {\n return body;\n }\n\n public int getSentBy() {\n return sentBy;\n }\n\n}\n}\n\nclass Message2 {\n private Message.Content content; // Not possible\n}\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253492",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10171/"
] |
253,517
|
<p>I want to create a subclass of TabPage that contains some control, and I want to control the layout and properties of those controls through the designer. However, if I open my subclass in the designer, I can't position them like I could on a UserControl. I don't want to have to create a TabPage with an UserControl instance on it, I want to design the TabPage directly.</p>
<p>How do I do that? I've tried changing the Designer and DesignerCategory attributes, but I haven't found any values that help.</p>
|
[
{
"answer_id": 254210,
"author": "Hath",
"author_id": 5186,
"author_profile": "https://Stackoverflow.com/users/5186",
"pm_score": 3,
"selected": false,
"text": "public class UserTabControl<T> : TabPage\n where T : UserControl, new ()\n{\n private T _userControl;\n public T UserControl \n { \n get{ return _userControl;}\n set\n { \n _userControl = value;\n OnUserControlChanged(EventArgs.Empty);\n }\n }\n public event EventHandler UserControlChanged;\n protected virtual void OnUserControlChanged(EventArgs e)\n {\n //add user control docked to tabpage\n this.Controls.Clear(); \n UserControl.Dock = DockStyle.Fill;\n this.Controls.Add(UserControl);\n\n if (UserControlChanged != null)\n {\n UserControlChanged(this, e);\n }\n }\n\n public UserTabControl() : this(\"UserTabControl\")\n {\n }\n\n public UserTabControl(string text) \n : this( new T(),text )\n {\n }\n\n public UserTabControl(T userControl) \n : this(userControl, userControl.Name)\n {\n }\n\n public UserTabControl(T userControl, string tabtext)\n : base(tabtext)\n {\n InitializeComponent();\n UserControl = userControl; \n }\n\n private void InitializeComponent()\n {\n this.SuspendLayout();\n // \n // UserTabControl\n // \n\n this.BackColor = System.Drawing.Color.Transparent;\n this.Padding = new System.Windows.Forms.Padding(3);\n this.UseVisualStyleBackColor = true;\n this.ResumeLayout(false);\n }\n}\n"
},
{
"answer_id": 254667,
"author": "Tim Robinson",
"author_id": 32133,
"author_profile": "https://Stackoverflow.com/users/32133",
"pm_score": 1,
"selected": false,
"text": "TabPage form.TopLevel = false;\nform.Parent = tabPage;\nform.FormBorderStyle = FormBorderStyle.None; // otherwise you get a form with a \n // title bar inside the tab page, \n // which is a little odd\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253517",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15371/"
] |
253,522
|
<p>For example if I have an auto-numbered field, I add new records without specifying this field and let DB engine to pick it for me.<br>
So, will it pick the number of the deleted record? If yes, when?</p>
<p>// SQL Server, MySQL. //</p>
<p>Follow-up question: <a href="https://stackoverflow.com/questions/253616/what-happens-when-db-engine-runs-out-of-numbers-to-use-for-primary-keys">What happens when DB engine runs out of numbers to use for primary keys?</a></p>
|
[
{
"answer_id": 253540,
"author": "ConcernedOfTunbridgeWells",
"author_id": 15401,
"author_profile": "https://Stackoverflow.com/users/15401",
"pm_score": 1,
"selected": false,
"text": "set identity_insert on"
},
{
"answer_id": 253580,
"author": "Lucas Oman",
"author_id": 6726,
"author_profile": "https://Stackoverflow.com/users/6726",
"pm_score": 1,
"selected": false,
"text": "truncate delete from where truncate"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253522",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28098/"
] |
253,544
|
<p>I have been reading the post here:</p>
<p><a href="http://encosia.com/2008/10/04/using-jquery-to-enhance-aspnet-ajax-progress-indication/" rel="nofollow noreferrer">http://encosia.com/2008/10/04/using-jquery-to-enhance-aspnet-ajax-progress-indication/</a></p>
<p>But it wants to use the following object:</p>
<pre><code>Sys.WebForms.PageRequestManager.getInstance()
</code></pre>
<p>Which doesn't exist when using the MVC AJAX code. Has anyone tried to hook when the postback ends from MVC AJAX to know when to unblock the UI?</p>
|
[
{
"answer_id": 253540,
"author": "ConcernedOfTunbridgeWells",
"author_id": 15401,
"author_profile": "https://Stackoverflow.com/users/15401",
"pm_score": 1,
"selected": false,
"text": "set identity_insert on"
},
{
"answer_id": 253580,
"author": "Lucas Oman",
"author_id": 6726,
"author_profile": "https://Stackoverflow.com/users/6726",
"pm_score": 1,
"selected": false,
"text": "truncate delete from where truncate"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253544",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24227/"
] |
253,545
|
<p>I have been asked to provide information on available techniques for assessing our current, and any future websites for security problems. the request is in the form of</p>
<blockquote>
<p>Do you know of any good free one that examines for security holes?</p>
</blockquote>
<p>I think our data security is probably worth a small amount of upfront spend so any non-free methods would be appreciated too.</p>
<p>Our systems are a mish mash of mySQL, Oracle, SQLServer, PHP, ASP.NET etc etc systems though I guess that that does not matter too much. All the systems are secured in as much as they are patched and the firewalls are set sensibly so outside people cannot get directly to the database boxes etc.</p>
<p>It is XSS and similar attacks that we wish to prevent. </p>
<p>What do YOU use to give you confidence in your systems? ');DROP TABLE answer;</p>
|
[
{
"answer_id": 253540,
"author": "ConcernedOfTunbridgeWells",
"author_id": 15401,
"author_profile": "https://Stackoverflow.com/users/15401",
"pm_score": 1,
"selected": false,
"text": "set identity_insert on"
},
{
"answer_id": 253580,
"author": "Lucas Oman",
"author_id": 6726,
"author_profile": "https://Stackoverflow.com/users/6726",
"pm_score": 1,
"selected": false,
"text": "truncate delete from where truncate"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253545",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5552/"
] |
253,546
|
<p>I have a line (actually a cube) going from (x1,y1,z1) to (x2,y2,z2). I would like to rotate it so that it is aligned along another line going from (x3,y3,z3) to (x4,y4,z4). Presently I am using <code>Math::Atan2</code> along with <code>Matrix::RotateYawPitchRoll</code>. Any better ways to do this?</p>
<p>Edit: I think I've worded this post very badly. What I am actually looking for is a Rotation Matrix from two Vectors.</p>
|
[
{
"answer_id": 253674,
"author": "timday",
"author_id": 24283,
"author_profile": "https://Stackoverflow.com/users/24283",
"pm_score": 3,
"selected": true,
"text": "(f0x f1x f2x)\n(f0y f1y f2y)\n(f0z f1z f2z)\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253546",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/45603/"
] |
253,549
|
<p>I have the following code which works just fine when the method is "POST", but changing to "GET" doesn't work:</p>
<pre><code>HttpWebRequest request = null;
request = HttpWebRequest.Create(uri) as HttpWebRequest;
request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
request.Method = "POST"; // Doesn't work with "GET"
request.BeginGetRequestStream(this.RequestCallback, null);
</code></pre>
<p>I get a <code>ProtocolViolationException</code> exception with the "GET" method.</p>
<p><strong>Edit:</strong> After having a look using Reflector, it seems there is an explicit check for the "GET" method, if it's set to that it throws the exception.</p>
<p><strong>Edit2:</strong> I've updated my code to the following, but it still throws an exception when I call EndGetResponse()</p>
<pre><code>if (request.Method == "GET")
{
request.BeginGetResponse(this.ResponseCallback, state);
}
else
{
request.BeginGetRequestStream(this.RequestCallback, state);
}
</code></pre>
<p>In my function, ResponseCallback, I have this:</p>
<pre><code>HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asyncResult);
</code></pre>
<p>Which throws the exception as well.</p>
<p><strong>Answer</strong> </p>
<p>The above code now works, I had forgotten to take out the Content-Type line which was causing the exception to be thrown at the end. +1 to tweakt & answer to Jon.</p>
<p>The working code is now below:</p>
<pre><code>HttpWebRequest request = null;
request = HttpWebRequest.Create(uri) as HttpWebRequest;
request.Method = "GET";// Supports POST too
if (request.Method == "GET")
{
request.BeginGetResponse(this.ResponseCallback, state);
}
else
{
request.BeginGetRequestStream(this.RequestCallback, state);
}
</code></pre>
|
[
{
"answer_id": 253619,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 5,
"selected": true,
"text": "BeginGetRequestStream"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253549",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/986/"
] |
253,574
|
<p>I've written some custom model binders (implementing IModelBinder) in our ASP.NET MVC application. I'm wondering what is a good approach to unittest them (binders)?</p>
|
[
{
"answer_id": 254447,
"author": "Korbin",
"author_id": 17902,
"author_profile": "https://Stackoverflow.com/users/17902",
"pm_score": 5,
"selected": true,
"text": "var formElements = new NameValueCollection() { {\"FirstName\",\"Bubba\"}, {\"MiddleName\", \"\"}, {\"LastName\", \"Gump\"} }; \nvar fakeController = GetControllerContext(formElements);\nvar valueProvider = new Mock<IValueProvider>(); \n\nvar bindingContext = new ModelBindingContext(fakeController, valueProvider.Object, typeof(Guid), null, null, null, null);\n\n\n\nprivate static ControllerContext GetControllerContext(NameValueCollection form) {\n Mock<HttpRequestBase> mockRequest = new Mock<HttpRequestBase>();\n mockRequest.Expect(r => r.Form).Returns(form);\n\n Mock<HttpContextBase> mockHttpContext = new Mock<HttpContextBase>();\n mockHttpContext.Expect(c => c.Request).Returns(mockRequest.Object);\n\n return new ControllerContext(mockHttpContext.Object, new RouteData(), new Mock<ControllerBase>().Object);\n}\n"
},
{
"answer_id": 589250,
"author": "Scott Hanselman",
"author_id": 6380,
"author_profile": "https://Stackoverflow.com/users/6380",
"pm_score": 4,
"selected": false,
"text": "[TestMethod] \npublic void DateTime_Can_Be_Pulled_Via_Provided_Month_Day_Year_Hour_Minute_Second_Alternate_Names() \n{ \n var dict = new ValueProviderDictionary(null) { \n { \"foo.month1\", new ValueProviderResult(\"2\",\"2\",null) }, \n { \"foo.day1\", new ValueProviderResult(\"12\", \"12\", null) }, \n { \"foo.year1\", new ValueProviderResult(\"1964\", \"1964\", null) }, \n { \"foo.hour1\", new ValueProviderResult(\"13\",\"13\",null) }, \n { \"foo.minute1\", new ValueProviderResult(\"44\", \"44\", null) }, \n { \"foo.second1\", new ValueProviderResult(\"01\", \"01\", null) } \n }; \n\n var bindingContext = new ModelBindingContext() { ModelName = \"foo\", ValueProvider = dict }; \n\n DateAndTimeModelBinder b = new DateAndTimeModelBinder() { Month = \"month1\", Day = \"day1\", Year = \"year1\", Hour = \"hour1\", Minute = \"minute1\", Second = \"second1\" }; \n\n DateTime result = (DateTime)b.BindModel(null, bindingContext); \n Assert.AreEqual(DateTime.Parse(\"1964-02-12 13:44:01\"), result); \n} \n"
},
{
"answer_id": 625106,
"author": "labilbe",
"author_id": 1195872,
"author_profile": "https://Stackoverflow.com/users/1195872",
"pm_score": 2,
"selected": false,
"text": " FormCollection form = new FormCollection\n {\n { \"month1\", \"2\" },\n { \"day1\", \"12\" },\n { \"year1\", \"1964\" },\n { \"hour1\", \"13\" },\n { \"minute1\", \"44\" },\n { \"second1\", \"01\" }\n };\n\n var bindingContext = new ModelBindingContext() { ModelName = \"foo\", ValueProvider = form.ToValueProvider() }; \n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253574",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3182/"
] |
253,587
|
<p>I've recently started using code coverage tools (particularily Emma and EclEmma), and I really like the view that it gives me as to the completeness of my unit tests - and the ability to see what areas of the code my unit tests aren't hitting at all. I currently work in an organization that doesn't do a lot of unit testing, and I plan on really pushing everyone to take on unit testing and code coverage and TDD and hopefully convert the organization.</p>
<p>One issue that I'm unsure of with this subject is exactly how far I should take my code coverage. For example, if I have a class such as this:</p>
<pre><code>//this class is meant as a pseudo-enum - I'm stuck on Java 1.4 for time being
public final class BillingUnit {
public final static BillingUnit MONTH = new BillingUnit("month");
public final static BillingUnit YEAR = new BillingUnit("year");
private String value;
private BillingUnit(String value) {
this.value = value;
}
public String getValue() {
return this.value;
}
public boolean equals(Object obj) {
return value.equals(((BillingUnit) obj).getValue());
}
public int hashCode() {
return value.hashCode();
}
}
</code></pre>
<p>I wrote some simple unit tests to make sure that <code>equals()</code> works correctly, that <code>getValue()</code> returns what I expected, etc. But thanks to the visual nature of EclEmma, the <code>hashcode()</code> method shows up as bright red for "not tested".</p>
<p>Is it worthwhile to even bother to test <code>hashCode()</code>, in this example, considering how simple the implementation is? I feel like I would be adding a unit test for this method simply to bump the code coverage % up, and get rid of the glaring red highlight that EclEmma adds to these lines.</p>
<p>Maybe I'm being neurotic and OCD-like, but I find that using something like EclEmma that makes it so easy to see what is untested - the plugin highlights the source code in red, and covered code in green - really makes me want to push to get as many classes 100% green as a I can - even when it doesn't add much of a benefit.</p>
|
[
{
"answer_id": 253625,
"author": "Chris Marasti-Georg",
"author_id": 96,
"author_profile": "https://Stackoverflow.com/users/96",
"pm_score": 3,
"selected": false,
"text": "if(logger.isDebugEnabled()) {\n logger.debug(\"something\");\n}\n if(log.isDebugEnabled())"
},
{
"answer_id": 253627,
"author": "kͩeͣmͮpͥ ͩ",
"author_id": 26479,
"author_profile": "https://Stackoverflow.com/users/26479",
"pm_score": 0,
"selected": false,
"text": "equals() getValue() hashCode()"
},
{
"answer_id": 253712,
"author": "Ryan Boucher",
"author_id": 27818,
"author_profile": "https://Stackoverflow.com/users/27818",
"pm_score": 2,
"selected": false,
"text": "public float reciprocal (float ex)\n{\n return (1.0 / ex) ;\n}\n"
},
{
"answer_id": 253738,
"author": "Ken Gentle",
"author_id": 8709,
"author_profile": "https://Stackoverflow.com/users/8709",
"pm_score": 2,
"selected": false,
"text": "equals hashCode Comparable Serializable equals/hashCode equals/Comparable"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253587",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4249/"
] |
253,642
|
<p>Currently using System.Web.UI.WebControls.FileUpload wrapped in our own control.</p>
<p>We have licenses for Telerik. I wanted to know if anyone had experience with that or could suggest a better one?</p>
<p>Some criteria to be measured by</p>
<ul>
<li>validation</li>
<li>peformance</li>
<li>multiple files</li>
<li>localisation (<a href="https://stackoverflow.com/questions/94316/how-to-change-the-text-of-the-browse-button-in-the-fileupload-control-systemweb">browse</a> is difficult)</li>
<li>security</li>
</ul>
|
[
{
"answer_id": 8063388,
"author": "NicoJuicy",
"author_id": 209555,
"author_profile": "https://Stackoverflow.com/users/209555",
"pm_score": 1,
"selected": false,
"text": " <HttpPost()> _\n Public Function Upload(uploadedFile As System.Web.HttpPostedFileBase) As ActionResult\n If uploadedFile IsNot Nothing Then \n If uploadedFile.ContentLength > 0 Then\n\n Dim mimeType As String = Nothing \n 'Upload\n Dim PathFileName As String = System.IO.Path.GetFileName(uploadedFile.FileName)\n\n Dim path = System.IO.Path.Combine(Server.MapPath(\"~/App_Data/Uploads\"), PathFileName)\n\n If Not System.IO.Directory.Exists(Path) Then\n System.IO.Directory.CreateDirectory(Path)\n End If\n\n Dim firstLoop As Boolean = True\n uploadedFile.SaveAs(path) \n Next\n End If\n Return Nothing\n End Function\n <h1>\n @SharedStrings.Upload</h1>\n <h2>\n @SharedStrings.UploadInformation</h2>\n <div id=\"dropbox\">\n </div>\n <div id=\"upload\">\n </div>\n <script type=\"text/javascript\">\n\n $(function () {\n\n var fileTemplate = \"<div id=\\\"{{id}}\\\">\"; fileTemplate += \"<div class=\\\"progressbar\\\"></div>\"; fileTemplate += \"<div class=\\\"preview\\\"></div>\"; fileTemplate += \"<div class=\\\"filename\\\">{{filename}}</div>\"; fileTemplate += \"</div>\"; function slugify(text) { text = text.replace(/[^-a-zA-Z0-9,&\\s]+/ig, ''); text = text.replace(/-/gi, \"_\"); text = text.replace(/\\s/gi, \"-\"); return text; }\n $(\"#dropbox\").html5Uploader({ onClientLoadStart: function (e, file) {\n var upload = $(\"#upload\"); if (upload.is(\":hidden\")) { upload.show(); }\n upload.append(fileTemplate.replace(/{{id}}/g, slugify(file.name)).replace(/{{filename}}/g, file.name));\n }, onClientLoad: function (e, file) { /*$(\"#\" + slugify(file.name)).find(\".preview\").append(\"<img src=\\\"\" + e.target.result + \"\\\" alt=\\\"\\\">\");*/ }, onServerLoadStart: function (e, file) { $(\"#\" + slugify(file.name)).find(\".progressbar\").progressbar({ value: 0 }); }, onServerProgress: function (e, file) { if (e.lengthComputable) { var percentComplete = (e.loaded / e.total) * 100; $(\"#\" + slugify(file.name)).find(\".progressbar\").progressbar({ value: percentComplete }); } }, onServerLoad: function (e, file) { $(\"#\" + slugify(file.name)).find(\".progressbar\").progressbar({ value: 100 }); } \n }); \n });\n </script>\n /*html 5 uploader*/\n#dropbox \n{\n/*picture where people would drag-drop their files to*/\n background-image:url(../Images/UploadToMedia.png);\n height:128px;\n margin-bottom:40px;\n margin-left:auto;\n margin-right:auto;\n background-repeat:no-repeat;\n margin-top:0;\n width:128px;\n}\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253642",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30913/"
] |
253,644
|
<p>I was using an XSL style sheet to do the sorting but it seems to be very slow. Is there a more efficient way?</p>
<p>It is a flat list of nodes, if I convert the nodes to an object and sort in a GenericList would it help?</p>
<p><strong>EDIT</strong> I don't need the end result to be XML.</p>
|
[
{
"answer_id": 8063388,
"author": "NicoJuicy",
"author_id": 209555,
"author_profile": "https://Stackoverflow.com/users/209555",
"pm_score": 1,
"selected": false,
"text": " <HttpPost()> _\n Public Function Upload(uploadedFile As System.Web.HttpPostedFileBase) As ActionResult\n If uploadedFile IsNot Nothing Then \n If uploadedFile.ContentLength > 0 Then\n\n Dim mimeType As String = Nothing \n 'Upload\n Dim PathFileName As String = System.IO.Path.GetFileName(uploadedFile.FileName)\n\n Dim path = System.IO.Path.Combine(Server.MapPath(\"~/App_Data/Uploads\"), PathFileName)\n\n If Not System.IO.Directory.Exists(Path) Then\n System.IO.Directory.CreateDirectory(Path)\n End If\n\n Dim firstLoop As Boolean = True\n uploadedFile.SaveAs(path) \n Next\n End If\n Return Nothing\n End Function\n <h1>\n @SharedStrings.Upload</h1>\n <h2>\n @SharedStrings.UploadInformation</h2>\n <div id=\"dropbox\">\n </div>\n <div id=\"upload\">\n </div>\n <script type=\"text/javascript\">\n\n $(function () {\n\n var fileTemplate = \"<div id=\\\"{{id}}\\\">\"; fileTemplate += \"<div class=\\\"progressbar\\\"></div>\"; fileTemplate += \"<div class=\\\"preview\\\"></div>\"; fileTemplate += \"<div class=\\\"filename\\\">{{filename}}</div>\"; fileTemplate += \"</div>\"; function slugify(text) { text = text.replace(/[^-a-zA-Z0-9,&\\s]+/ig, ''); text = text.replace(/-/gi, \"_\"); text = text.replace(/\\s/gi, \"-\"); return text; }\n $(\"#dropbox\").html5Uploader({ onClientLoadStart: function (e, file) {\n var upload = $(\"#upload\"); if (upload.is(\":hidden\")) { upload.show(); }\n upload.append(fileTemplate.replace(/{{id}}/g, slugify(file.name)).replace(/{{filename}}/g, file.name));\n }, onClientLoad: function (e, file) { /*$(\"#\" + slugify(file.name)).find(\".preview\").append(\"<img src=\\\"\" + e.target.result + \"\\\" alt=\\\"\\\">\");*/ }, onServerLoadStart: function (e, file) { $(\"#\" + slugify(file.name)).find(\".progressbar\").progressbar({ value: 0 }); }, onServerProgress: function (e, file) { if (e.lengthComputable) { var percentComplete = (e.loaded / e.total) * 100; $(\"#\" + slugify(file.name)).find(\".progressbar\").progressbar({ value: percentComplete }); } }, onServerLoad: function (e, file) { $(\"#\" + slugify(file.name)).find(\".progressbar\").progressbar({ value: 100 }); } \n }); \n });\n </script>\n /*html 5 uploader*/\n#dropbox \n{\n/*picture where people would drag-drop their files to*/\n background-image:url(../Images/UploadToMedia.png);\n height:128px;\n margin-bottom:40px;\n margin-left:auto;\n margin-right:auto;\n background-repeat:no-repeat;\n margin-top:0;\n width:128px;\n}\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253644",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18107/"
] |
253,664
|
<p>We've got products built both with GUI and CHUI. Going forward, we're looking at redesigning a lot of our software and mainly taking the route of going all GUI. My question to the group is, do we need to account for keeping a CHUI around? What are the advantages of CHUI over GUI? Many times in the past people have said that CHUI is faster because you don't need a mouse. I argue that GUI can be just as fast with the right keyboard shortcuts, hotkeys and/or touch screens.</p>
<p>Is CHUI something we should no longer consider if hardware no longer provides a constraint?</p>
<p>Also to clarify, when I speak about CHUI I mean a CHaracter based User Interface, and I'm also mainly concerned with the effective presentation of data to an end user.</p>
<p>There have been some fantastic responses that have highlighted the importance of having a command line based interface for automation and scripting based tasks which I will certainly take to heart when we begin the design!</p>
|
[
{
"answer_id": 2001954,
"author": "JeffO",
"author_id": 61339,
"author_profile": "https://Stackoverflow.com/users/61339",
"pm_score": 1,
"selected": false,
"text": "A) - This Menu\nB) - That Menu\nC) - Some other Menu\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253664",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26853/"
] |
253,666
|
<p>In Microsoft Oslo SDK CTP 2008 (using Intellipad) the following code compiles fine:</p>
<pre><code>module M {
type T {
Text : Text;
}
}
</code></pre>
<p>while compiling the below code leads to the error "M0197: 'Text' cannot be used in a Type context"</p>
<pre><code>module M {
type T {
Text : Text;
Value : Text; // error
}
}
</code></pre>
<p>I do not see the difference between the examples, as in the first case Text is also used in a Type context.</p>
<p>UPDATE:</p>
<p>To add to the confusion, consider the following example, which also compiles fine:</p>
<pre><code>module M {
type X;
type T {
X : X;
Y : X;
}
}
</code></pre>
<p>The M Language Specification states that:</p>
<blockquote>
<p>Field declarations override lexical scoping to prevent the type of a declaration binding to the declaration itself. The ascribed type of a field declaration must not be the declaration itself; however, the declaration may be used in a constraint. Consider the following example:</p>
<p>type A;
type B {
A : A;
}</p>
<p>The lexically enclosing scope for the type ascription of the field declaration A is the entity declaration B. With no exception, the type ascription A would bind to the field declaration in a circular reference which is an error. The exception allows lexical lookup to skip the field declaration in this case. </p>
</blockquote>
<p>It seems that user defined types and built-in (intrinsic) types are not treated equal.</p>
<p>UPDATE2:</p>
<p>Note that <em>Value</em> in the above example is not a reserved keyword. The same error results if you rename <em>Value</em> to <em>Y</em>.</p>
<p>Any ideas?</p>
<p>Regards, tamberg</p>
|
[
{
"answer_id": 2001954,
"author": "JeffO",
"author_id": 61339,
"author_profile": "https://Stackoverflow.com/users/61339",
"pm_score": 1,
"selected": false,
"text": "A) - This Menu\nB) - That Menu\nC) - Some other Menu\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253666",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3588/"
] |
253,673
|
<p>What is the slowest (therefore best) hash algorithm for passwords in ASP Classic?</p>
<p>EDIT: For those unaware, when hashing passwords, slower hashes are preferred to faster to help slow rainbow table style attacks. </p>
<p>EDIT2: And yes, of course speed isn't the only valid concern for hash selection. My question assumes that <strong>All other things being equal</strong>, <a href="http://www.securityfocus.com/blogs/262" rel="nofollow noreferrer">the slowest hash method is preferred</a> when hashing a password. Though collision/reverse engineering is of course a concern too, I'm prioritizing speed in this question since it is arguably the most critical factor to consider when comparing popular hash algorithms for use on passwords.</p>
<p>Thanks!</p>
|
[
{
"answer_id": 253699,
"author": "chills42",
"author_id": 23855,
"author_profile": "https://Stackoverflow.com/users/23855",
"pm_score": -1,
"selected": false,
"text": "function hashPassword(password)\n sleep for 10 seconds\n return password\nend function\n"
},
{
"answer_id": 253703,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 2,
"selected": false,
"text": " testHash = computeHash( user.salt + \"98hloj5674\" + password );\n if (testHash == user.hashedPassword)\n {\n valid = true;\n }\n"
},
{
"answer_id": 463713,
"author": "Svante Svenson",
"author_id": 19707,
"author_profile": "https://Stackoverflow.com/users/19707",
"pm_score": 2,
"selected": false,
"text": "Dim sPassword, sSalt\nsPassword = \"Lorem\"\nsSalt = \"Ipsum\"\nWith CreateObject(\"CAPICOM.HashedData\")\n .Algorithm = 0 ' CAPICOM_HASH_ALGORITHM_SHA1\n .Hash sPassword & sSalt\n Response.Write \"Here is your hash: \" & .Value\nEnd With\n CAPICOM_HASH_ALGORITHM_SHA1 = 0\nCAPICOM_HASH_ALGORITHM_MD2 = 1\nCAPICOM_HASH_ALGORITHM_MD4 = 2\nCAPICOM_HASH_ALGORITHM_MD5 = 3\nCAPICOM_HASH_ALGORITHM_SHA_256 = 4 - Not supported on Windows XP or 2000\nCAPICOM_HASH_ALGORITHM_SHA_384 = 5 - Not supported on Windows XP or 2000\nCAPICOM_HASH_ALGORITHM_SHA_512 = 6 - Not supported on Windows XP or 2000\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253673",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26180/"
] |
253,689
|
<p>I am making an expand/collapse call rates table for the company I work for. I currently have a table with a button under it to expand it, the button says "Expand". It is functional except I need the button to change to "Collapse" when it is clicked and then of course back to "Expand" when it is clicked again. The writing on the button is a background image.</p>
<p>So basically all I need is to change the background image of a div when it is clicked, except sort of like a toggle.</p>
|
[
{
"answer_id": 253710,
"author": "Nick",
"author_id": 26161,
"author_profile": "https://Stackoverflow.com/users/26161",
"pm_score": 9,
"selected": false,
"text": "$('#divID').css(\"background-image\", \"url(/myimage.jpg)\"); \n $('#divID').click(function()\n{\n // do my image switching logic here.\n});\n"
},
{
"answer_id": 253717,
"author": "alexp206",
"author_id": 666,
"author_profile": "https://Stackoverflow.com/users/666",
"pm_score": 3,
"selected": false,
"text": "$(document).ready(function(){\n $(\".button\").click(function () {\n $(this).children(\".arrow\").toggle();\n return false;\n });\n});\n\n<a href=\"#\" class=\"button\">\n <span class=\"arrow\">\n <img src=\"/images/icons/left.png\" alt=\"+\" />\n </span>\n <span class=\"arrow\" style=\"display: none;\">\n <img src=\"/images/down.png\" alt=\"-\" />\n </span>\n</a>\n"
},
{
"answer_id": 253722,
"author": "enobrev",
"author_id": 14651,
"author_profile": "https://Stackoverflow.com/users/14651",
"pm_score": 3,
"selected": false,
"text": "<html>\n <head>\n <script src=\"http://www.google.com/jsapi\"></script>\n <script>\n google.load(\"jquery\", \"1.2.6\");\n google.setOnLoadCallback(function() {\n var original_image = 'url(http://stackoverflow.com/Content/img/wmd/link.png)';\n var second_image = 'url(http://stackoverflow.com/Content/img/wmd/code.png)';\n\n $('.mydiv').click(function() {\n if ($(this).css('background-image').replace(/\"/g, '') == original_image) {\n $(this).css('background-image', second_image);\n } else {\n $(this).css('background-image', original_image);\n }\n\n return false;\n });\n });\n </script>\n\n <style>\n .mydiv {\n background-image: url('http://stackoverflow.com/Content/img/wmd/link.png');\n width: 100px;\n height: 100px;\n }\n </style>\n </head>\n <body>\n <div class=\"mydiv\"> </div>\n </body>\n</html>\n"
},
{
"answer_id": 3808559,
"author": "Kelly",
"author_id": 460029,
"author_profile": "https://Stackoverflow.com/users/460029",
"pm_score": 6,
"selected": false,
"text": ".div {\n /* button size etc properties */\n}\n\n.expanded {background: url(img/x.gif) no-repeat left top;}\n.collapsed {background: url(img/y.gif) no-repeat left top;}\n .div {\n background: url(img/sprite.gif) no-repeat left top;\n /* Other styles */\n}\n\n.expanded {background-position: left bottom;}\n $(function){\n $('#button').click(function(){\n if($(this).hasClass('expanded'))\n {\n $(this).addClass('collapsed').removeClass('expanded');\n }\n else\n {\n $(this).addClass('expanded').removeClass('collapsed');\n }\n });\n}\n addClass removeClass $(function){\n $('#button').click(function(){\n $(this).toggleClass('expanded');\n });\n }\n\n$(function){\n $('#button').click(function(){\n if($(this).hasClass('expanded'))\n {\n $(this).removeClass('expanded');\n }\n else\n {\n $(this).addClass('expanded');\n }\n });\n }\n"
},
{
"answer_id": 4917267,
"author": "Ecropolis",
"author_id": 249355,
"author_profile": "https://Stackoverflow.com/users/249355",
"pm_score": 6,
"selected": false,
"text": "$('selector').css('backgroundImage','url(images/example.jpg)'); $('selector').css({'background-image':'url(images/example.jpg)'});"
},
{
"answer_id": 8827670,
"author": "Loupax",
"author_id": 208271,
"author_profile": "https://Stackoverflow.com/users/208271",
"pm_score": 4,
"selected": false,
"text": "#button{\n background-image: url(\"initial_image.png\");\n}\n\n#button.toggled{\n background-image:url(\"toggled_image.png\");\n}\n $('#button').click(function(){\n $('#my_content').toggle();\n $(this).toggleClass('toggled');\n});\n"
},
{
"answer_id": 10592845,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "function randomToN(maxVal) {\n var randVal = Math.random() * maxVal;\n return typeof 0 == 'undefined' ? Math.round(randVal) : randVal.toFixed(0);\n};\nvar list = [ \"IMG0.EXT\", \"IMG2.EXT\",\"IMG3.EXT\" ], // Images\n ram = list[parseFloat(randomToN(list.length))], // Random 1 to n\n img = ram == undefined || ram == null ? list[0] : ram; // Detect null\n$(\"div#ID\").css(\"backgroundImage\", \"url(\" + img + \")\"); // push de background\n"
},
{
"answer_id": 11102959,
"author": "bphillips",
"author_id": 1466663,
"author_profile": "https://Stackoverflow.com/users/1466663",
"pm_score": 2,
"selected": false,
"text": "$.each($('.smallPreview'), function(i){\n var $this = $(this);\n\n $this.mouseenter(function(){\n $this.css('background', 'url(Assets/imgs/imgBckg-Small_Over.png) no-repeat 0 0');\n });\n\n $this.mouseleave(function(){\n $this.css('background', 'url(Assets/imgs/imgBckg-Small.png) no-repeat 0 0');\n });\n\n});\n"
},
{
"answer_id": 15684169,
"author": "user2220104",
"author_id": 2220104,
"author_profile": "https://Stackoverflow.com/users/2220104",
"pm_score": 3,
"selected": false,
"text": "$(\".travelinfo-btn\").click(\n function() {\n $(\"html, body\").animate({scrollTop: $(this).offset().top}, 200);\n var bgImg = $(this).css('background-image')\n var bgPath = bgImg.substr(0, bgImg.lastIndexOf('/')+1)\n if(bgImg.match(/collapse/)) {\n $(this).stop().css('background-image', bgImg.replace(/collapse/,'expand'));\n $(this).next(\".travelinfo-item\").stop().slideToggle(400);\n } else {\n $(this).stop().css('background-image', bgImg.replace(/expand/,'collapse'));\n $(this).next(\".travelinfo-item\").stop().slideToggle(400);\n }\n }\n );\n"
},
{
"answer_id": 38220660,
"author": "yPhil",
"author_id": 1729094,
"author_profile": "https://Stackoverflow.com/users/1729094",
"pm_score": 3,
"selected": false,
"text": "$(this).animate({\n opacity: 0\n}, 100, function() {\n // Callback\n $(this).css(\"background-image\", \"url(\" + new_img + \")\").promise().done(function(){\n // Callback of the callback :)\n $(this).animate({\n opacity: 1\n }, 600)\n }); \n});\n"
},
{
"answer_id": 59030469,
"author": "AdamVanBuskirk",
"author_id": 2456574,
"author_profile": "https://Stackoverflow.com/users/2456574",
"pm_score": 2,
"selected": false,
"text": "var d = new Date();\nvar t = d.getTime();\n\n$('#avatar').css(\"background-image\", \"url(\" + iPath + \"?\" + t + \")\");\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253689",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26823/"
] |
253,692
|
<p>I am trying to start WebLogic within Eclipse</p>
<p>When it starts it complains like this.</p>
<p>Unable to load performance pack. Using Java I/O instead. Please ensure that wlntio.dll is in: 'C:\bea81\jdk142_04\bin;.;C:\WINDOWS\system32;C:\WINDOWS;C:\bea81\jdk142_04\jre\bin;C:\Program Files\Java\jre1.6.0\bin\client;C:\Program Files\Java\jre1.6.0\bin;C:\sybase\JS-12_5\bin;C:\sybase\OCS-12_5\lib3p;C:\sybase\OCS-12_5\dll;C:\sybase\OCS-12_5\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Common Files\Roxio Shared\DLLShared\;C:\Program Files\Common Files\Roxio Shared\DLLShared\;C:\Program Files\Common Files\Roxio Shared\9.0\DLLShared\;C:\Program Files\cvsnt;C:\Program Files\Executive Software\DiskeeperWorkstation\;'</p>
<blockquote>
<p></p>
</blockquote>
|
[
{
"answer_id": 1469248,
"author": "Pascal Thivent",
"author_id": 70604,
"author_profile": "https://Stackoverflow.com/users/70604",
"pm_score": 1,
"selected": false,
"text": "$BEA_HOME/server/bin PATH"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253692",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
253,695
|
<p>I have a Silverlight 2 application that validates data OnTabSelectionChanged. Immediately I began wishing that UpdateSourceTrigger allowed more than just LostFocus because if you click the tab without tabbing off of a control the LINQ object is not updated before validation. </p>
<p>I worked around the issue for TextBoxes by setting focus to another control and then back OnTextChanged:</p>
<pre><code>Private Sub OnTextChanged(ByVal sender As Object, ByVal e As TextChangedEventArgs)
txtSetFocus.Focus()
sender.Focus()
End Sub
</code></pre>
<p>Now I am trying to accomplish the same sort of hack within a DataGrid. My DataGrid uses DataTemplates generated at runtime for the CellTemplate and CellEditingTemplate. I tried writing the TextChanged="OnTextChanged" into the TextBox in the DataTemplate, but it is not triggered.</p>
<p>Anyone have any ideas? </p>
|
[
{
"answer_id": 3077562,
"author": "Ben Brodie",
"author_id": 371280,
"author_profile": "https://Stackoverflow.com/users/371280",
"pm_score": 0,
"selected": false,
"text": "public class DefaultButtonHub\n{\n ButtonAutomationPeer peer = null;\n\n private void Attach(DependencyObject source)\n {\n if (source is Button)\n {\n peer = new ButtonAutomationPeer(source as Button);\n }\n else if (source is TextBox)\n {\n TextBox tb = source as TextBox;\n tb.KeyUp += OnKeyUp;\n }\n else if (source is PasswordBox)\n {\n PasswordBox pb = source as PasswordBox;\n pb.KeyUp += OnKeyUp;\n }\n }\n\n private void OnKeyUp(object sender, KeyEventArgs arg)\n {\n if (arg.Key == Key.Enter)\n if (peer != null)\n {\n if (sender is TextBox)\n {\n TextBox t = (TextBox)sender;\n BindingExpression expression = t.GetBindingExpression(TextBox.TextProperty);\n expression.UpdateSource();\n }\n ((IInvokeProvider)peer).Invoke();\n }\n }\n\n public static DefaultButtonHub GetDefaultHub(DependencyObject obj)\n {\n return (DefaultButtonHub)obj.GetValue(DefaultHubProperty);\n }\n\n public static void SetDefaultHub(DependencyObject obj, DefaultButtonHub value)\n {\n obj.SetValue(DefaultHubProperty, value);\n }\n\n // Using a DependencyProperty as the backing store for DefaultHub. This enables animation, styling, binding, etc...\n public static readonly DependencyProperty DefaultHubProperty =\n DependencyProperty.RegisterAttached(\"DefaultHub\", typeof(DefaultButtonHub), typeof(DefaultButtonHub), new PropertyMetadata(OnHubAttach));\n\n private static void OnHubAttach(DependencyObject source, DependencyPropertyChangedEventArgs prop)\n {\n DefaultButtonHub hub = prop.NewValue as DefaultButtonHub;\n hub.Attach(source);\n }\n\n}\n"
},
{
"answer_id": 3251313,
"author": "Simon_Weaver",
"author_id": 16940,
"author_profile": "https://Stackoverflow.com/users/16940",
"pm_score": 4,
"selected": true,
"text": "// xmlns:int is System.Windows.Interactivity from System.Windows.Interactivity.DLL)\n// xmlns:behavior is your namespace for the class below\n<TextBox Text=\"{Binding Description,Mode=TwoWay,UpdateSourceTrigger=Explicit}\">\n <int:Interaction.Behaviors>\n <behavior:TextBoxUpdatesTextBindingOnPropertyChanged />\n </int:Interaction.Behaviors>\n</TextBox>\n\n\npublic class TextBoxUpdatesTextBindingOnPropertyChanged : Behavior<TextBox>\n{\n protected override void OnAttached()\n {\n base.OnAttached();\n\n AssociatedObject.TextChanged += new TextChangedEventHandler(TextBox_TextChanged);\n }\n\n protected override void OnDetaching()\n {\n base.OnDetaching();\n\n AssociatedObject.TextChanged -= TextBox_TextChanged;\n }\n\n void TextBox_TextChanged(object sender, TextChangedEventArgs e)\n {\n var bindingExpression = AssociatedObject.GetBindingExpression(TextBox.TextProperty);\n bindingExpression.UpdateSource();\n }\n}\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253695",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33102/"
] |
253,701
|
<p>I have a web application that allows a user to search on some criteria, select an object, edit it and then return to the previous search. All the editing takes place on a separate page linked to the datagrid of returned results. I was wondering what is the best way to store the previous search parameters so that when they return to the grid they have the same search they previously used. The best option I came up with is to use a NameValue collection of each of the selected paramters and store that to Session or a cookie when the user presses the search button. Any other ideas as to a better way to approach this?</p>
|
[
{
"answer_id": 253845,
"author": "Jason Kealey",
"author_id": 20893,
"author_profile": "https://Stackoverflow.com/users/20893",
"pm_score": 2,
"selected": true,
"text": " public static string GenerateSessionKeyFromPage(Page page)\n {\n return \"__\" + page.Request.Path;\n }\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253701",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30383/"
] |
253,705
|
<p>I have a dropdown list that stores name/value pairs. The dropdown appears in each row of a gridview.</p>
<p>The values in the dropdown correspond to a third attribute (data type) not persisted in the dropdown list. I'd like to create a client-side "lookup" table so that when a user chooses a dropdown value, the proper data type populates next to it.</p>
<p>What's the best way to accomplish this in an ASP.NET application? The List of value/attributes could potentially range from 1 to 100 members in a list...</p>
|
[
{
"answer_id": 253715,
"author": "Ady",
"author_id": 31395,
"author_profile": "https://Stackoverflow.com/users/31395",
"pm_score": 0,
"selected": false,
"text": "var oVals = new Array('1','2','3','4','5');\n\ndocument.getElementById(\"cell1\").innerHTML = oVals[document.getElementById(\"dropdown1\").selectedIndex];\n"
},
{
"answer_id": 263515,
"author": "Caveatrob",
"author_id": 335036,
"author_profile": "https://Stackoverflow.com/users/335036",
"pm_score": 2,
"selected": true,
"text": "var profileHeaders = new AArray(); \n\nprofileHeaders .add(\"k01\", \"hi\");\nprofileHeaders .add(\"k02\", \"ho\");\n\nvar oC = profileHeaders .get(\"k02\");\n\nalert(oC); \n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253705",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/335036/"
] |
253,720
|
<p>I have a problem with a simple included file.</p>
<p>The file being included is in two MFC programs - one of which is a dll, and it also compiles itself into a non-mfc dll.</p>
<p>Recently I was using the larger dll which wraps around the <em>source</em> of the smaller dll when I wanted access to some of the features of the original code that isn't exposed by the larger dll.</p>
<p>Since this was a test I simply added the source to my project and called the functions. I got this error: <strong>syntax error : missing ')' before ';'</strong></p>
<p>The file is correctly included, and I have both the .cpp and the .h in the source folder, and within the project but it wouldn't compile. </p>
<p>I eventually created a very small test project, main.cpp, spooler.cpp and spooler.h (the spooler is a wrapper around the comms) and tried to compile that. Same issue.</p>
<p>So I ripped out all the dll related stuff just in case there is a weird issue going on with that and it still won't compile.</p>
<p>I can't think of the life of me what is wrong. Does anyone else have any ideas?</p>
<p>p.s. Jeff you really need to add the ability to attach files because the source would fill up too many screens with data.</p>
|
[
{
"answer_id": 253750,
"author": "Jasper Bekkers",
"author_id": 31486,
"author_profile": "https://Stackoverflow.com/users/31486",
"pm_score": 3,
"selected": true,
"text": "( )"
},
{
"answer_id": 253827,
"author": "graham.reeds",
"author_id": 342,
"author_profile": "https://Stackoverflow.com/users/342",
"pm_score": 0,
"selected": false,
"text": "// the only two includes\n#include <windows.h>\n#include \"spooler.h\"\n// in WinMain\n// create window then...\nShowWindow (hwnd, iCmdShow);\nUpdateWindow (hwnd);\n\nSpoolerInitiallize( hwnd, ID_SPOOLER_EVENT ); // <-- our function\n...\n"
},
{
"answer_id": 253923,
"author": "Michael Burr",
"author_id": 12711,
"author_profile": "https://Stackoverflow.com/users/12711",
"pm_score": 3,
"selected": false,
"text": "C/C++ - Preprocessor - Generate Preprocessed File\n"
},
{
"answer_id": 254051,
"author": "crashmstr",
"author_id": 1441,
"author_profile": "https://Stackoverflow.com/users/1441",
"pm_score": 0,
"selected": false,
"text": "#define"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253720",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/342/"
] |
253,724
|
<p>I'm looking for a way to supply an argument to a ruby on rails project at runtime. Essentially, our project uses public key cryptography to encrypt some sensitive client data and we want the ability to supply the password to the private key file at runtime.</p>
|
[
{
"answer_id": 254703,
"author": "Jsnydr",
"author_id": 32503,
"author_profile": "https://Stackoverflow.com/users/32503",
"pm_score": 2,
"selected": true,
"text": "module StartupArgs\n @@argHash = {}\n\n def self.setArg(key, value)\n @@argHash[key.to_sym] = value\n end\n\n def self.getArg(key)\n return @@argHash[key.to_sym]\n end\nend\n require \"startup_args\"\n\npromptString = \"Enter arg name (type nothing to continue):\"\n\nputs promptString\nwhile (newArg = gets.chomp) != \"\"\n puts \"Enter value for '#{newArg}':\"\n newVal = gets.chomp\n StartupArgs.setArg(newArg, newVal)\n\n puts promptString\nend\n"
},
{
"answer_id": 254858,
"author": "webmat",
"author_id": 6349,
"author_profile": "https://Stackoverflow.com/users/6349",
"pm_score": 2,
"selected": false,
"text": "puts ENV['PATH']\n MY_ARG=supersecret ruby script.rb\n puts ENV['MY_ARG'] $ MY_ARG=supersecret mongrel_rails start\n** Starting Mongrel listening at 0.0.0.0:3000\n** Starting Rails with development environment...\nsupersecret\n** Rails loaded.\n** Loading any Rails specific GemPlugins\n** Signals ready. TERM => stop. USR2 => restart. INT => stop (no restart).\n** Rails signals registered. HUP => reload (without restart). It might not work well.\n** Mongrel 1.1.5 available at 0.0.0.0:3000\n** Use CTRL-C to stop.\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253724",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11042/"
] |
253,727
|
<p>When building static libraries with VS2005 I keep getting linker warnings that VC80.pdb cant be found with my library.lib. Apparently, as a result, the edit and continue feature of the IDE fails to work any project that incorporates library.lib</p>
<p>What magic is needed to tell VS2005 to produce a static lib with edit and continue debug info that does NOT reference or require vs80.pdb when linked into a project?</p>
<p>--Upon Further Understanding--
So, In order to get edit-and-continue to function with a pre-compiled static lib, we need to place the vs80.pdb and vs80.pdb file into SVN along with the .lib, AND rename the pdb/idb to prevent conflicts when doing this with multiple pre-compiled libs.</p>
|
[
{
"answer_id": 254257,
"author": "Steve Steiner",
"author_id": 3892,
"author_profile": "https://Stackoverflow.com/users/3892",
"pm_score": 4,
"selected": true,
"text": "SECTION HEADER #7\n.debug$T name\n 0 physical address\n 0 virtual address\n 48 size of raw data\n 838 file pointer to raw data (00000838 to 0000087F)\n 0 file pointer to relocation table\n 0 file pointer to line numbers\n 0 number of relocations\n 0 number of line numbers\n42100040 flags\n Initialized Data\n Discardable\n 1 byte align\n Read Only\n\nRAW DATA #7\n 00000000: 04 00 00 00 42 00 15 15 D5 EA 1E C9 7C 10 3A 40 ....B...Õê.É|.:@\n 00000010: 93 63 CE 95 77 15 49 4A 03 00 00 00 64 3A 5C 64 .cÎ.w.IJ....d:\\d\n 00000020: 65 76 5C 74 65 73 74 5C 74 65 73 74 6C 69 62 5C ev\\test\\testlib\\\n 00000030: 74 65 73 74 6C 69 62 5C 64 65 62 75 67 5C 76 63 testlib\\debug\\vc\n 00000040: 38 30 2E 70 64 62 00 F1 80.pdb.ñ\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253727",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27491/"
] |
253,731
|
<p>I have a web page that has a web form for signing up. I want to remove fields. I've tried removing the field code from the .asp file but obviously there are other things that I need to remove along those lines. I have full access to all the code but I need help knowing where things are linked as far as making the form work again. Our programmer bailed. </p>
<p>A step by step guide would be great on this. thanks.</p>
|
[
{
"answer_id": 253762,
"author": "John",
"author_id": 30006,
"author_profile": "https://Stackoverflow.com/users/30006",
"pm_score": 2,
"selected": false,
"text": "<asp:TextBox id=\"text1\" runat=\"server\" />\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253731",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
253,735
|
<p>I have a report that is used by a windows service and a form application. So, I want to put embed the report in a DLL file that can be used by both.</p>
<p>The problem is that if I try to set the ReportEmbeddedResource property of a ReportViewer control in my windows form app, it will search the windows form app for the resource, not the dll file.</p>
<p>e.g.: Code from the windows form app:</p>
<pre><code>rv.LocalReport.ReportEmbeddedResource = "MyReportInMyDLLFile.rdlc"
</code></pre>
<p>How can I make the above command look for the embedded resource in my DLL file?</p>
|
[
{
"answer_id": 261842,
"author": "DrCamel",
"author_id": 4168,
"author_profile": "https://Stackoverflow.com/users/4168",
"pm_score": 4,
"selected": false,
"text": "rv.LocalReport.ReportEmbeddedResource = \"TheApp.Reports.MyReport.rdlc\";\n"
},
{
"answer_id": 358276,
"author": "gschuager",
"author_id": 19716,
"author_profile": "https://Stackoverflow.com/users/19716",
"pm_score": 7,
"selected": true,
"text": "Assembly assembly = Assembly.LoadFrom(\"Reports.dll\");\nStream stream = assembly.GetManifestResourceStream(\"Reports.MyReport.rdlc\");\nreportViewer.LocalReport.LoadReportDefinition(stream);\n"
},
{
"answer_id": 3334002,
"author": "Dan Higham",
"author_id": 402149,
"author_profile": "https://Stackoverflow.com/users/402149",
"pm_score": 5,
"selected": false,
"text": "rv.LocalReport.ReportEmbeddedResource = \n \"My.Assembly.Namespace.Folder1.Folder2.MyReport.rdlc\";\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253735",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/681/"
] |
253,746
|
<p>In Microsoft Oslo SDK CTP 2008 (using Intellipad) the following code compiles fine:</p>
<pre><code>module T {
type A {
Id : Integer32 = AutoNumber();
} where identity Id;
As : A*;
type B {
Id : Integer32 = AutoNumber();
// A : A;
// } where A in As && identity Id;
} where identity Id;
Bs : B*;
type C {
Id : Integer32 = AutoNumber();
B : B;
} where B in Bs && identity Id;
Cs : C*;
}
</code></pre>
<p>and results in the following Reach SQL output:</p>
<pre><code>set xact_abort on;
go
begin transaction;
go
set ansi_nulls on;
go
create schema [T];
go
create table [T].[As]
(
[Id] int not null identity,
constraint [PK_As] primary key clustered ([Id])
);
go
create table [T].[Bs]
(
[Id] int not null identity,
constraint [PK_Bs] primary key clustered ([Id])
);
go
create table [T].[Cs]
(
[Id] int not null identity,
[B] int not null,
constraint [PK_Cs] primary key clustered ([Id]),
constraint [FK_Cs_B_T_Bs] foreign key ([B]) references [T].[Bs] ([Id])
);
go
commit transaction;
go
</code></pre>
<p>But after changing the commented line in module T as follows</p>
<pre><code> A : A;
} where A in As && identity Id;
// } where identity Id;
</code></pre>
<p>the error message "M2037: SQL Generation Internal Error: Missing generator for variable 'A'" is displayed (in Intellipad's Reach SQL Window).</p>
<p>Any Ideas?</p>
<p>Regards, tamberg</p>
|
[
{
"answer_id": 254473,
"author": "cfeduke",
"author_id": 5645,
"author_profile": "https://Stackoverflow.com/users/5645",
"pm_score": 2,
"selected": true,
"text": "type A {\n Id : Integer32 = AutoNumber();\n} where identity Id;\n\nAs : A*;\n\ntype B {\n Id : Integer32 = AutoNumber();\n A : A;\n} where identity Id;\n\nBs : (B where value.A in As)*;\n\ntype C {\n Id : Integer32 = AutoNumber();\n B : B;\n} where identity Id && B in Bs;\n\nCs : (C where value.B in Bs)*;\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253746",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3588/"
] |
253,747
|
<p>I'm using .NET typed datasets on a project, and I often get into situations where I prefetch data from several tables into a dataset and then pass that dataset to several methods for processing. It seems cleaner to let each method decide exactly which data it needs and then load the data itself. However, several of the methods work with the same data, and I want the performance benefit of loading data in the beginning only once.</p>
<p>My problem is that I don't know of a good way or pattern to use for managing dependencies (I want to be sure I load all the data that I'm going to need for each class/method that will use the dataset). Currently, I just end up looking through the code for the various classes that will use the dataset to make sure I'm loading everything appropriately.</p>
<p>What are good approaches or patterns to use in this situation? Am I doing something fundamentally wrong? Although I'm using typed datasets, this seems like it would be a common situation where prefetching data is used.</p>
<p>Thanks!</p>
|
[
{
"answer_id": 254473,
"author": "cfeduke",
"author_id": 5645,
"author_profile": "https://Stackoverflow.com/users/5645",
"pm_score": 2,
"selected": true,
"text": "type A {\n Id : Integer32 = AutoNumber();\n} where identity Id;\n\nAs : A*;\n\ntype B {\n Id : Integer32 = AutoNumber();\n A : A;\n} where identity Id;\n\nBs : (B where value.A in As)*;\n\ntype C {\n Id : Integer32 = AutoNumber();\n B : B;\n} where identity Id && B in Bs;\n\nCs : (C where value.B in Bs)*;\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253747",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33096/"
] |
253,757
|
<p>In following code, I want to extend the behaviour of a class by deriving/subclassing it, and make use of an event of the base class:</p>
<pre><code>public class A
{
public event EventHandler SomeEvent;
public void someMethod()
{
if(SomeEvent != null) SomeEvent(this, someArgs);
}
}
public class B : A
{
public void someOtherMethod()
{
if(SomeEvent != null) SomeEvent(this, someArgs); // << why is this not possible?
//Error: The event 'SomeEvent' can only appear on the left hand side of += or -=
//(except when used from within the type 'A')
}
}
</code></pre>
<p>Why isn't it possible?</p>
<p>And what is the common solution for this kind of situation?</p>
|
[
{
"answer_id": 253776,
"author": "Todd White",
"author_id": 30833,
"author_profile": "https://Stackoverflow.com/users/30833",
"pm_score": 6,
"selected": true,
"text": "public class A\n{\n public event EventHandler SomeEvent;\n\n public void someMethod()\n {\n OnSomeEvent();\n }\n\n protected void OnSomeEvent()\n {\n EventHandler handler = SomeEvent;\n if(handler != null)\n handler(this, someArgs);\n }\n}\n\npublic class B : A\n{\n public void someOtherMethod()\n {\n OnSomeEvent();\n }\n}\n"
},
{
"answer_id": 253793,
"author": "Keith",
"author_id": 905,
"author_profile": "https://Stackoverflow.com/users/905",
"pm_score": 1,
"selected": false,
"text": "public class BaseClass\n{\n public event EventHandler<MyArgs> SomeEvent;\n\n protected virtual void OnSomeEvent()\n {\n if(SomeEvent!= null)\n SomeEvent(this, new MyArgs(...) );\n }\n}\n public class DerivedClass : BaseClass\n{\n protected override void OnSomeEvent()\n {\n //do something\n\n base.OnSomeEvent();\n }\n}\n"
},
{
"answer_id": 253806,
"author": "cfeduke",
"author_id": 5645,
"author_profile": "https://Stackoverflow.com/users/5645",
"pm_score": 3,
"selected": false,
"text": "OnXXX(EventArgs) public class Foo\n{\n public event EventHandler Click;\n\n protected virtual void OnClick(EventArgs e)\n {\n var click = Click;\n if (click != null)\n click(this, e);\n }\n}\n EventArgs<T> EventHandler<T> CustomEventArgs CustomEventHandler"
},
{
"answer_id": 253813,
"author": "Tim Robinson",
"author_id": 32133,
"author_profile": "https://Stackoverflow.com/users/32133",
"pm_score": 2,
"selected": false,
"text": "private add_SomeEvent remove_SomeEvent"
},
{
"answer_id": 253969,
"author": "Gishu",
"author_id": 1695,
"author_profile": "https://Stackoverflow.com/users/1695",
"pm_score": 2,
"selected": false,
"text": "public class GoodVigilante\n{\n public event EventHandler LaunchMissiles;\n\n public void Evaluate()\n {\n Action a = DetermineCourseOfAction(); // method that evaluates every possible\n// non-violent solution before resorting to 'Unleashing the fury'\n\n if (null != a) \n { a.Do(); }\n else\n { if (null != LaunchMissiles) LaunchMissiles(this, EventArgs.Empty); }\n }\n\n virtual protected string WhatsTheTime()\n { return DateTime.Now.ToString(); }\n .... \n}\npublic class TriggerHappy : GoodVigilante\n{\n protected override string WhatsTheTime()\n {\n if (null != LaunchMissiles) LaunchMissiles(this, EventArgs.Empty);\n }\n\n}\n\n// client code\nGoodVigilante a = new GoodVigilante();\na.LaunchMissiles += new EventHandler(FireAway);\nGoodVigilante b = new TriggerHappy(); // rogue/imposter\nb.LaunchMissiles += new EventHandler(FireAway);\n\nprivate void FireAway(object sender, EventArgs e)\n{\n // nuke 'em\n}\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253757",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26070/"
] |
253,767
|
<p>I'm looking for a KDTree implementation in Java.<br>
I've done a google search and the results seem pretty haphazard. There are actually lots of results, but they're mostly just little one-off implementations, and I'd rather find something with a little more "production value". Something like apache collections or the excellent C5 collection library for .NET. Something where I can see the public bug tracker and check to see when the last SVN commit happened. Also, in an ideal world, I'd find a nice well-designed API for spatial data structures, and the KDTree would be just one class in that library.</p>
<p>For this project, I'll only be working in either 2 or 3 dimensions, and I'm mostly just interested in a good nearest-neighbors implementation.</p>
|
[
{
"answer_id": 27467323,
"author": "grepit",
"author_id": 717630,
"author_profile": "https://Stackoverflow.com/users/717630",
"pm_score": 1,
"selected": false,
"text": "private class KDNode {\n KDNode left;\n KDNode right;\n E val;\n int depth;\n private KDNode(E e, int depth){\n this.left = null;\n this.right = null;\n this.val = e;\n this.depth = depth;\n}\n"
},
{
"answer_id": 41410420,
"author": "Gayathri",
"author_id": 3978295,
"author_profile": "https://Stackoverflow.com/users/3978295",
"pm_score": -1,
"selected": false,
"text": "package kdtree;\n\nclass KDNode{\n KDNode left;\n KDNode right;\n int []data;\n\n public KDNode(){\n left=null;\n right=null;\n }\n\n public KDNode(int []x){\n left=null;\n right=null;\n data = new int[2];\n for (int k = 0; k < 2; k++)\n data[k]=x[k];\n }\n}\nclass KDTreeImpl{\n KDNode root;\n int cd=0;\n int DIM=2;\n\n public KDTreeImpl() {\n root=null;\n }\n\n public boolean isEmpty(){\n return root == null;\n }\n\n public void insert(int []x){\n root = insert(x,root,cd);\n }\n private KDNode insert(int []x,KDNode t,int cd){\n if (t == null)\n t = new KDNode(x);\n else if (x[cd] < t.data[cd])\n t.left = insert(x, t.left, (cd+1)%DIM);\n else\n t.right = insert(x, t.right, (cd+1)%DIM);\n return t;\n }\n\n public boolean search(int []data){\n return search(data,root,0);\n }\n\n private boolean search(int []x,KDNode t,int cd){\n boolean found=false;\n if(t==null){\n return false;\n }\n else {\n if(x[cd]==t.data[cd]){\n if(x[0]==t.data[0] && x[1]==t.data[1]) \n return true;\n }else if(x[cd]<t.data[cd]){\n found = search(x,t.left,(cd+1)%DIM);\n }else if(x[cd]>t.data[cd]){\n found = search(x,t.right,(cd+1)%DIM);\n }\n return found;\n }\n }\n\n public void inorder(){\n inorder(root);\n }\n private void inorder(KDNode r){\n if (r != null){\n inorder(r.left);\n System.out.print(\"(\"+r.data[0]+\",\"+r.data[1] +\") \");\n inorder(r.right);\n }\n }\n public void preorder() {\n preorder(root);\n }\n private void preorder(KDNode r){\n if (r != null){\n System.out.print(\"(\"+r.data[0]+\",\"+r.data[1] +\") \");\n preorder(r.left); \n preorder(r.right);\n }\n }\n /* Function for postorder traversal */\n public void postorder() {\n postorder(root);\n }\n private void postorder(KDNode r) {\n if (r != null){\n postorder(r.left); \n postorder(r.right);\n System.out.print(\"(\"+r.data[0]+\",\"+r.data[1] +\") \");\n }\n }\n}\npublic class KDTree {\n\n /**\n * @param args the command line arguments\n */\n public static void main(String[] args) {\n // TODO code application logic here\n KDTreeImpl kdt = new KDTreeImpl();\n int x[] = new int[2];\n x[0] = 30;\n x[1] = 40;\n kdt.insert(x);\n\n x[0] = 5;\n x[1] = 25;\n kdt.insert(x);\n\n x[0] = 10;\n x[1] = 12;\n kdt.insert(x);\n\n x[0] = 70;\n x[1] = 70;\n kdt.insert(x);\n\n x[0] = 50;\n x[1] = 30;\n kdt.insert(x);\n System.out.println(\"Input Elements\");\n System.out.println(\"(30,40) (5,25) (10,12) (70,70) (50,30)\\n\\n\");\n System.out.println(\"Printing KD Tree in Inorder\");\n kdt.inorder();\n System.out.println(\"\\nPrinting KD Tree in PreOder\");\n kdt.preorder();\n System.out.println(\"\\nPrinting KD Tree in PostOrder\");\n kdt.postorder();\n System.out.println(\"\\nsearching...............\");\n x[0]=40;x[1]=40;\n System.out.println(kdt.search(x));\n }\n}\n"
},
{
"answer_id": 42705972,
"author": "Raman Sharma",
"author_id": 7686879,
"author_profile": "https://Stackoverflow.com/users/7686879",
"pm_score": 2,
"selected": false,
"text": "import java.util.ArrayList;\nimport java.util.List;\nimport edu.princeton.cs.algs4.In;\nimport edu.princeton.cs.algs4.Point2D;\nimport edu.princeton.cs.algs4.RectHV;\nimport edu.princeton.cs.algs4.StdDraw;\npublic class KdTree {\n private static class Node {\n public Point2D point; // the point\n public RectHV rect; // the axis-aligned rectangle corresponding to this\n public Node lb; // the left/bottom subtree\n public Node rt; // the right/top subtree\n public int size;\n public double x = 0;\n public double y = 0;\n public Node(Point2D p, RectHV rect, Node lb, Node rt) {\n super();\n this.point = p;\n this.rect = rect;\n this.lb = lb;\n this.rt = rt;\n x = p.x();\n y = p.y();\n }\n\n }\n private Node root = null;;\n\n public KdTree() {\n }\n\n public boolean isEmpty() {\n return root == null;\n }\n\n public int size() {\n return rechnenSize(root);\n }\n\n private int rechnenSize(Node node) {\n if (node == null) {\n return 0;\n } else {\n return node.size;\n }\n }\n\n public void insert(Point2D p) {\n if (p == null) {\n throw new NullPointerException();\n }\n if (isEmpty()) {\n root = insertInternal(p, root, 0);\n root.rect = new RectHV(0, 0, 1, 1);\n } else {\n root = insertInternal(p, root, 1);\n }\n }\n\n // at odd level we will compare x coordinate, and at even level we will\n // compare y coordinate\n private Node insertInternal(Point2D pointToInsert, Node node, int level) {\n if (node == null) {\n Node newNode = new Node(pointToInsert, null, null, null);\n newNode.size = 1;\n return newNode;\n }\n if (level % 2 == 0) {//Horizontal partition line\n if (pointToInsert.y() < node.y) {//Traverse in bottom area of partition\n node.lb = insertInternal(pointToInsert, node.lb, level + 1);\n if(node.lb.rect == null){\n node.lb.rect = new RectHV(node.rect.xmin(), node.rect.ymin(),\n node.rect.xmax(), node.y);\n }\n } else {//Traverse in top area of partition\n if (!node.point.equals(pointToInsert)) {\n node.rt = insertInternal(pointToInsert, node.rt, level + 1);\n if(node.rt.rect == null){\n node.rt.rect = new RectHV(node.rect.xmin(), node.y,\n node.rect.xmax(), node.rect.ymax());\n }\n }\n }\n\n } else if (level % 2 != 0) {//Vertical partition line\n if (pointToInsert.x() < node.x) {//Traverse in left area of partition\n node.lb = insertInternal(pointToInsert, node.lb, level + 1);\n if(node.lb.rect == null){\n node.lb.rect = new RectHV(node.rect.xmin(), node.rect.ymin(),\n node.x, node.rect.ymax());\n }\n } else {//Traverse in right area of partition\n if (!node.point.equals(pointToInsert)) {\n node.rt = insertInternal(pointToInsert, node.rt, level + 1);\n if(node.rt.rect == null){\n node.rt.rect = new RectHV(node.x, node.rect.ymin(),\n node.rect.xmax(), node.rect.ymax());\n }\n }\n }\n }\n node.size = 1 + rechnenSize(node.lb) + rechnenSize(node.rt);\n return node;\n }\n\n public boolean contains(Point2D p) {\n return containsInternal(p, root, 1);\n }\n\n private boolean containsInternal(Point2D pointToSearch, Node node, int level) {\n if (node == null) {\n return false;\n }\n if (level % 2 == 0) {//Horizontal partition line\n if (pointToSearch.y() < node.y) {\n return containsInternal(pointToSearch, node.lb, level + 1);\n } else {\n if (node.point.equals(pointToSearch)) {\n return true;\n }\n return containsInternal(pointToSearch, node.rt, level + 1);\n }\n } else {//Vertical partition line\n if (pointToSearch.x() < node.x) {\n return containsInternal(pointToSearch, node.lb, level + 1);\n } else {\n if (node.point.equals(pointToSearch)) {\n return true;\n }\n return containsInternal(pointToSearch, node.rt, level + 1);\n }\n }\n\n }\n\n public void draw() {\n StdDraw.clear();\n drawInternal(root, 1);\n }\n\n private void drawInternal(Node node, int level) {\n if (node == null) {\n return;\n }\n StdDraw.setPenColor(StdDraw.BLACK);\n StdDraw.setPenRadius(0.02);\n node.point.draw();\n double sx = node.rect.xmin();\n double ex = node.rect.xmax();\n double sy = node.rect.ymin();\n double ey = node.rect.ymax();\n StdDraw.setPenRadius(0.01);\n if (level % 2 == 0) {\n StdDraw.setPenColor(StdDraw.BLUE);\n sy = ey = node.y;\n } else {\n StdDraw.setPenColor(StdDraw.RED);\n sx = ex = node.x;\n }\n StdDraw.line(sx, sy, ex, ey);\n drawInternal(node.lb, level + 1);\n drawInternal(node.rt, level + 1);\n }\n\n /**\n * Find the points which lies in the rectangle as parameter\n * @param rect\n * @return\n */\n public Iterable<Point2D> range(RectHV rect) {\n List<Point2D> resultList = new ArrayList<Point2D>();\n rangeInternal(root, rect, resultList);\n return resultList;\n }\n\n private void rangeInternal(Node node, RectHV rect, List<Point2D> resultList) {\n if (node == null) {\n return;\n }\n if (node.rect.intersects(rect)) {\n if (rect.contains(node.point)) {\n resultList.add(node.point);\n }\n rangeInternal(node.lb, rect, resultList);\n rangeInternal(node.rt, rect, resultList);\n }\n\n }\n\n public Point2D nearest(Point2D p) {\n if(root == null){\n return null;\n }\n Champion champion = new Champion(root.point,Double.MAX_VALUE);\n return nearestInternal(p, root, champion, 1).champion;\n }\n\n private Champion nearestInternal(Point2D targetPoint, Node node,\n Champion champion, int level) {\n if (node == null) {\n return champion;\n }\n double dist = targetPoint.distanceSquaredTo(node.point);\n int newLevel = level + 1;\n if (dist < champion.championDist) {\n champion.champion = node.point;\n champion.championDist = dist;\n }\n boolean goLeftOrBottom = false;\n //We will decide which part to be visited first, based upon in which part point lies.\n //If point is towards left or bottom part, we traverse in that area first, and later on decide\n //if we need to search in other part too.\n if(level % 2 == 0){\n if(targetPoint.y() < node.y){\n goLeftOrBottom = true;\n }\n } else {\n if(targetPoint.x() < node.x){\n goLeftOrBottom = true;\n }\n }\n if(goLeftOrBottom){\n nearestInternal(targetPoint, node.lb, champion, newLevel);\n Point2D orientationPoint = createOrientationPoint(node.x,node.y,targetPoint,level);\n double orientationDist = orientationPoint.distanceSquaredTo(targetPoint);\n //We will search on the other part only, if the point is very near to partitioned line\n //and champion point found so far is far away from the partitioned line.\n if(orientationDist < champion.championDist){\n nearestInternal(targetPoint, node.rt, champion, newLevel);\n }\n } else {\n nearestInternal(targetPoint, node.rt, champion, newLevel);\n Point2D orientationPoint = createOrientationPoint(node.x,node.y,targetPoint,level);\n //We will search on the other part only, if the point is very near to partitioned line\n //and champion point found so far is far away from the partitioned line.\n double orientationDist = orientationPoint.distanceSquaredTo(targetPoint);\n if(orientationDist < champion.championDist){\n nearestInternal(targetPoint, node.lb, champion, newLevel);\n }\n\n }\n return champion;\n }\n /**\n * Returns the point from a partitioned line, which can be directly used to calculate\n * distance between partitioned line and the target point for which neighbours are to be searched.\n * @param linePointX\n * @param linePointY\n * @param targetPoint\n * @param level\n * @return\n */\n private Point2D createOrientationPoint(double linePointX, double linePointY, Point2D targetPoint, int level){\n if(level % 2 == 0){\n return new Point2D(targetPoint.x(),linePointY);\n } else {\n return new Point2D(linePointX,targetPoint.y());\n }\n }\n\n private static class Champion{\n public Point2D champion;\n public double championDist;\n public Champion(Point2D c, double d){\n champion = c;\n championDist = d;\n }\n }\n\n public static void main(String[] args) {\n String filename = \"/home/raman/Downloads/kdtree/circle100.txt\";\n In in = new In(filename);\n KdTree kdTree = new KdTree();\n while (!in.isEmpty()) {\n double x = in.readDouble();\n double y = in.readDouble();\n Point2D p = new Point2D(x, y);\n kdTree.insert(p);\n }\n // kdTree.print();\n System.out.println(kdTree.size());\n kdTree.draw();\n System.out.println(kdTree.nearest(new Point2D(0.4, 0.5)));\n System.out.println(new Point2D(0.7, 0.4).distanceSquaredTo(new Point2D(0.9,0.5)));\n System.out.println(new Point2D(0.7, 0.4).distanceSquaredTo(new Point2D(0.9,0.4)));\n\n }\n}\n"
},
{
"answer_id": 71298202,
"author": "Vladimir",
"author_id": 17993968,
"author_profile": "https://Stackoverflow.com/users/17993968",
"pm_score": 0,
"selected": false,
"text": "import edu.princeton.cs.algs4.Point2D;\nimport edu.princeton.cs.algs4.RectHV;\nimport edu.princeton.cs.algs4.StdDraw;\n\nimport java.util.ArrayList;\nimport java.util.List;\n\npublic class KdTree {\n private Node root;\n private int size;\n\n private static class Node {\n private Point2D p; // the point\n private RectHV rect; // the axis-aligned rectangle corresponding to this node\n private Node lb; // the left/bottom subtree\n private Node rt; // the right/top subtree\n public Node(Point2D p, RectHV rect) {\n this.p = p;\n this.rect = rect;\n }\n }\n\n public KdTree() {\n }\n\n public boolean isEmpty() {\n return size == 0;\n }\n\n public int size() {\n return size;\n }\n\n public boolean contains(Point2D p) {\n if (p == null) throw new IllegalArgumentException(\"argument to contains() is null\");\n return contains(root, p, 1);\n }\n\n private boolean contains(Node node, Point2D p, int level) {\n if (node == null) return false; // a base case for recursive call\n\n if (node.p.equals(p)) return true;\n\n if (level % 2 == 0) { // search by y coordinate (node with horizontal partition line)\n if (p.y() < node.p.y())\n return contains(node.lb, p, level + 1);\n else\n return contains(node.rt, p, level + 1);\n }\n else { // search by x coordinate (node with vertical partition line)\n if (p.x() < node.p.x())\n return contains(node.lb, p, level + 1);\n else\n return contains(node.rt, p, level + 1);\n }\n }\n\n public void insert(Point2D p) {\n if (p == null) throw new IllegalArgumentException(\"calls insert() with a null point\");\n root = insert(root, p, 1);\n }\n\n private Node insert(Node x, Point2D p, int level) {\n if (x == null) {\n size++;\n return new Node(p, new RectHV(0, 0, 1, 1));\n }\n\n if (x.p.equals(p)) return x; // if we try to insert existed point just return its node\n\n if (level % 2 == 0) { // search by y coordinate (node with horizontal partition line)\n if (p.y() < x.p.y()) {\n x.lb = insert(x.lb, p, level + 1);\n if (x.lb.rect.equals(root.rect))\n x.lb.rect = new RectHV(x.rect.xmin(), x.rect.ymin(), x.rect.xmax(), x.p.y());\n }\n else {\n x.rt = insert(x.rt, p, level + 1);\n if (x.rt.rect.equals(root.rect))\n x.rt.rect = new RectHV(x.rect.xmin(), x.p.y(), x.rect.xmax(), x.rect.ymax());\n }\n }\n else { // search by x coordinate (node with vertical partition line)\n if (p.x() < x.p.x()) {\n x.lb = insert(x.lb, p, level + 1);\n if (x.lb.rect.equals(root.rect))\n x.lb.rect = new RectHV(x.rect.xmin(), x.rect.ymin(), x.p.x(), x.rect.ymax());\n }\n else {\n x.rt = insert(x.rt, p, level + 1);\n if (x.rt.rect.equals(root.rect))\n x.rt.rect = new RectHV(x.p.x(), x.rect.ymin(), x.rect.xmax(), x.rect.ymax());\n }\n }\n return x;\n }\n\n public void draw() {\n draw(root, 1);\n }\n\n private void draw(Node node, int level) {\n if (node == null) return;\n\n StdDraw.setPenColor(StdDraw.BLACK);\n StdDraw.setPenRadius(0.01);\n node.p.draw();\n StdDraw.setPenRadius();\n\n if (level % 2 == 0) {\n StdDraw.setPenColor(StdDraw.BLUE);\n StdDraw.line(node.rect.xmin(), node.p.y(), node.rect.xmax(), node.p.y());\n }\n else {\n StdDraw.setPenColor(StdDraw.RED);\n StdDraw.line(node.p.x(), node.rect.ymin(), node.p.x(), node.rect.ymax());\n }\n\n draw(node.lb, level + 1);\n draw(node.rt, level + 1);\n }\n\n public Iterable<Point2D> range(RectHV rect) {\n if (rect == null) throw new IllegalArgumentException(\"calls range() with a null rect\");\n List<Point2D> points = new ArrayList<>(); // create an Iterable object with all points we found\n range(root, rect, points); // call helper method with rects intersects comparing\n \n return points; // return an Iterable object (It could be any type - Queue, LinkedList etc)\n }\n\n private void range(Node node, RectHV rect, List<Point2D> points) {\n if (node == null || !node.rect.intersects(rect)) return; // a base case for recursive call\n\n\n if (rect.contains(node.p))\n points.add(node.p);\n range(node.lb, rect, points);\n range(node.rt, rect, points);\n\n } \n\n public Point2D nearest(Point2D query) {\n if (isEmpty()) return null;\n if (query == null) throw new IllegalArgumentException(\"calls nearest() with a null point\");\n // set the start distance from root to query point\n double best = root.p.distanceSquaredTo(query);\n // StdDraw.setPenColor(StdDraw.BLACK); // just for debugging\n // StdDraw.setPenRadius(0.01);\n // query.draw();\n return nearest(root, query, root.p, best, 1); // call a helper method\n }\n\n private Point2D nearest(Node node, Point2D query, Point2D champ, double best, int level) {\n // a base case for the recursive call\n if (node == null || best < node.rect.distanceSquaredTo(query)) return champ;\n // we'll need to set an actual best distance when we recur\n best = champ.distanceSquaredTo(query);\n // check whether a distance from query point to the traversed node less than\n // distance from current champion to query point\n double temp = node.p.distanceSquaredTo(query);\n if (temp < best) {\n best = temp;\n champ = node.p;\n }\n\n if (level % 2 == 0) { // search by y coordinate (node with horizontal partition line)\n // we compare y coordinate and decide go up or down\n if (node.p.y() < query.y()) { // if true go up\n champ = nearest(node.rt, query, champ, best, level + 1);\n // important case - when we traverse node and go back up through the tree\n // we need to decide whether we need to go down(left) in this node or not\n // we just check our bottom (left) node on null && compare distance\n // from query point to the nearest point of the node's rectangle and\n // the distance from current champ point to thr query point\n if (node.lb != null && node.lb.rect.distanceSquaredTo(query) < champ.distanceSquaredTo(query)) {\n champ = nearest(node.lb, query, champ, best, level + 1);\n }\n\n }\n else { // if false go down\n champ = nearest(node.lb, query, champ, best, level + 1);\n if (node.rt != null && node.rt.rect.distanceSquaredTo(query) < champ.distanceSquaredTo(query))\n // when we traverse node and go back up through the tree\n // we need to decide whether we need to go up(right) in this node or not\n // we just check our top (right) node on null && compare distance\n // from query point to the nearest point of the node's rectangle and\n // the distance from current champ point to thr query point\n champ = nearest(node.rt, query, champ, best, level + 1);\n\n }\n\n }\n else {\n // search by x coordinate (node with vertical partition line)\n if (node.p.x() < query.x()) { // if true go right\n champ = nearest(node.rt, query, champ, best, level + 1);\n // the same check as mentioned above when we search by y coordinate\n if (node.lb != null && node.lb.rect.distanceSquaredTo(query) < champ.distanceSquaredTo(query))\n champ = nearest(node.lb, query, champ, best, level + 1);\n }\n else { // if false go left\n champ = nearest(node.lb, query, champ, best, level + 1);\n if (node.rt != null && node.rt.rect.distanceSquaredTo(query) < champ.distanceSquaredTo(query))\n champ = nearest(node.rt, query, champ, best, level + 1);\n }\n }\n return champ;\n }\n\n\n\n public static void main(String[] args) {\n // unit tests\n KdTree kd = new KdTree();\n Point2D p1 = new Point2D(0.7, 0.2);\n Point2D p2 = new Point2D(0.5, 0.4);\n Point2D p3 = new Point2D(0.2, 0.3);\n Point2D p4 = new Point2D(0.4, 0.7);\n Point2D p5 = new Point2D(0.9, 0.6);\n // Point2D query = new Point2D(0.676, 0.736);\n Point2D query1 = new Point2D(0.972, 0.887);\n // RectHV test = new RectHV(0, 0, 0.7, 0.4);\n // Point2D query = new Point2D(0.331, 0.762);\n\n // Point2D p6 = new Point2D(0.4, 0.4);\n // Point2D p7 = new Point2D(0.1, 0.6);\n // RectHV rect = new RectHV(0.05, 0.1, 0.15, 0.6);\n\n kd.insert(p1);\n kd.insert(p2);\n kd.insert(p3);\n kd.insert(p4);\n kd.insert(p5);\n System.out.println(kd.nearest(query1));\n // System.out.println(\"Dist query to 0.4,0.7= \" + query.distanceSquaredTo(p4));\n // System.out.println(\"Dist query to RectHV 0.2,0,3= \" + test.distanceSquaredTo(p4));\n // kd.insert(p6);\n // kd.insert(p7);\n // System.out.println(kd.size);\n // System.out.println(kd.contains(p3));\n // // System.out.println(kd.range(rect));\n\n kd.draw();\n \n\n }\n}\n"
},
{
"answer_id": 74315594,
"author": "Ilvis Faulbaums",
"author_id": 14675985,
"author_profile": "https://Stackoverflow.com/users/14675985",
"pm_score": 0,
"selected": false,
"text": "package kdtreeexample; //place your package name here\nimport net.sf.javaml.core.kdtree.KDTree; //import library\npublic class KDTreeExample {\n\npublic static void main(String[] args) {\n KDTree kdTree = new KDTree(2); //2 dimensions (x, y)\n// point insertion:\n kdTree.insert(new double[]{4, 3}, 0); //insert points (x=4,y=3), index = 0\n kdTree.insert(new double[]{1, 10}, 1); //insert points (x=1,y=10), index = 1\n kdTree.insert(new double[]{10, 10}, 2); //insert points (x=10,y=10), index = 2\n kdTree.insert(new double[]{5, 1}, 3); //insert points (x=5,y=1), index = 3\n// nearest index to point in coordinates x, y:\n int x = 0; //x coordinate for target point\n int y = 11; //y coordinate for target point\n int nearestIndex = (int) kdTree.nearest(new double[]{x, y}); //doing calculation here\n // result:\n System.out.println(\"Nearest point value index to point(\" + x + \", \" + y + \") = \" + nearestIndex);\n System.out.println(kdTree.toString()); //check the data\n }\n}\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253767",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22979/"
] |
253,807
|
<p>We all know to keep it simple, right?</p>
<p>I've seen complexity being measured as the number of interactions between systems, and I guess that's a very good place to start. Aside from gut feel though, what other (preferably more objective) methods can be used to determine the level of complexity of a particular design or piece of software?</p>
<p>What are YOUR favorite rules or heuristics?</p>
|
[
{
"answer_id": 253841,
"author": "lfalin",
"author_id": 28106,
"author_profile": "https://Stackoverflow.com/users/28106",
"pm_score": 2,
"selected": false,
"text": "A B\n0 0\n1 0\n0 1\n1 1\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253807",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15310/"
] |
253,810
|
<p>Much searching has lead me to find several descriptions of how to create a bootstrapping msi, but these solutions all assume the msi is local or a standard Windows component. Is there a way to make an msi that downloads an installer (which is also an msi) with normal MSI or Wix code rather than by having the bootstrapper execute some non-native program to do so?</p>
|
[
{
"answer_id": 257841,
"author": "saschabeaumont",
"author_id": 592,
"author_profile": "https://Stackoverflow.com/users/592",
"pm_score": 0,
"selected": false,
"text": "InstallExecuteSequence msiexec.exe /i http://some.domain/blah.msi /passive"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253810",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18192/"
] |
253,820
|
<p>I've been crossing things out on my TODO list. I've recently picked up Colemak. Next I wanted to learn Vim or Emacs. I was leaning towards Vim, however one of its benefits are sticking to the home row. With Colemak, the home row has been changed. I realize that I could remap the keys, but assigning the functionality to different letters is not extremely appealing to me (if there is any relation between letters and their function. I know movement is not correlated but I'm not sure on all the rest.)</p>
<p>I don't want to start an argumentative post about text editors, but rather receive comments from Colemak (or Dvorak) users about alternative keymappings and these two editors.</p>
<p>Thanks</p>
|
[
{
"answer_id": 2190106,
"author": "Graham",
"author_id": 130988,
"author_profile": "https://Stackoverflow.com/users/130988",
"pm_score": 3,
"selected": false,
"text": "noremap h k\nnoremap j h\nnoremap k j\n"
},
{
"answer_id": 5622090,
"author": "c_oreills",
"author_id": 702225,
"author_profile": "https://Stackoverflow.com/users/702225",
"pm_score": 4,
"selected": false,
"text": "set langmap=hk,jh,kj\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253820",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17234/"
] |
253,834
|
<p>Has anyone found a good class, or other file that will convert a .doc file into html or something that I can read and turn into html? </p>
<p>I have been looking around for a couple hours now and have only found ones that require msword on the server in order to convert the file. I am pretty sure that is not an option but I have not actually talked to my hosting provider about it.</p>
<p>The goal is for a user to be able to upload the file to my server and the server handle the conversion and then display it as html, much like googles view as html feature.</p>
|
[
{
"answer_id": 2968182,
"author": "CronosNull",
"author_id": 356675,
"author_profile": "https://Stackoverflow.com/users/356675",
"pm_score": 3,
"selected": false,
"text": "AbiWord --to=html archivo.doc\n"
},
{
"answer_id": 11334583,
"author": "forever99",
"author_id": 1502362,
"author_profile": "https://Stackoverflow.com/users/1502362",
"pm_score": 0,
"selected": false,
"text": "<?php\nfunction content($file){\n$data_array = explode(chr(0x0D),fread(fopen($file, \"r\"), filesize($file)));\n$data_text = \"\";\nforeach($data_array as $data_line){\nif (strpos($data_line, chr(0x00) !== false)||(strlen($data_line)==0))\n{} else {if(chr(0)) {$data_text .= \"<br>\";\n $data_text .= preg_replace(\"/[^a-zA-Z0-9\\s\\,\\.\\-\\n\\r\\t@\\/\\_\\(\\)]/\",\"\",$data_line); \n } \n } \n}\nreturn $data_text;}\n$destination = str_replace('index.php', '', $_SERVER['SCRIPT_FILENAME']);\n$destination.= \"upload/\";\n$maxsize = 5120000;\nif (isset($_GET['upload'])) {\n if($_FILES['userfile']['name'] && $_FILES['userfile']['size'] < $maxsize) {\n if(move_uploaded_file($_FILES['userfile']['tmp_name'], \"$destination/\".$_FILES['userfile']['name'])){\n $file = $destination.\"/\".$_FILES['userfile']['name'];\n $data = content($file);\n echo $data;\n } \n }\n}else{\n echo \"<form enctype='multipart/form-data' method='post' action='index.php?upload'>\n <input name='userfile' type='file'>\n <input value='Upload' name='submit' type='submit'>\n </form>\";\n }\n?>\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253834",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1925/"
] |
253,843
|
<p>What is the best way to refresh a <code>DataGridView</code> when you update an underlying data source?</p>
<p>I'm updating the datasource frequently and wanted to display the outcome to the user as it happens.</p>
<p>I've got something like this (and it works), but setting the <code>DataGridView.DataSource</code> to <code>null</code> doesn't seem like the right way.</p>
<pre><code>List<ItemState> itemStates = new List<ItemState>();
dataGridView1.DataSource = itemStates;
for (int i = 0; i < 10; i++) {
itemStates.Add(new ItemState { Id = i.ToString() });
dataGridView1.DataSource = null;
dataGridView1.DataSource = itemStates;
System.Threading.Thread.Sleep(500);
}
</code></pre>
|
[
{
"answer_id": 253863,
"author": "Georg",
"author_id": 30776,
"author_profile": "https://Stackoverflow.com/users/30776",
"pm_score": -1,
"selected": false,
"text": "List itemStates = new List();\n\nfor (int i = 0; i < 10; i++)\n{ \n itemStates.Add(new ItemState { Id = i.ToString() });\n dataGridView1.DataSource = itemStates;\n dataGridView1.DataBind();\n System.Threading.Thread.Sleep(500);\n}\n"
},
{
"answer_id": 253945,
"author": "Alan",
"author_id": 31223,
"author_profile": "https://Stackoverflow.com/users/31223",
"pm_score": 7,
"selected": true,
"text": "dataGridView1.DataSource = typeof(List); \ndataGridView1.DataSource = itemStates;\n"
},
{
"answer_id": 30174930,
"author": "starko",
"author_id": 3185406,
"author_profile": "https://Stackoverflow.com/users/3185406",
"pm_score": 0,
"selected": false,
"text": "this.XXXTableAdapter.Fill(this.DataSet.XXX);\n"
},
{
"answer_id": 30175479,
"author": "Kashif",
"author_id": 636740,
"author_profile": "https://Stackoverflow.com/users/636740",
"pm_score": 2,
"selected": false,
"text": "Observablecollection<ItemState> itemStates = new Observablecollection<ItemState>();\n\nfor (int i = 0; i < 10; i++) { \n itemStates.Add(new ItemState { Id = i.ToString() });\n }\n dataGridView1.DataSource = itemStates;\n"
},
{
"answer_id": 32018111,
"author": "Stix",
"author_id": 4917652,
"author_profile": "https://Stackoverflow.com/users/4917652",
"pm_score": 0,
"selected": false,
"text": "for (int i = 0; i < 10; i++) { \n itemStates.Add(new ItemState { Id = i.ToString() });\n dataGridView1.DataSource = null;\n dataGridView1.DataSource = itemStates;\n System.Threading.Thread.Sleep(500);\n}\n for (int i = 0; i < 10; i++) { \n itemStates.Add(new ItemState { Id = i.ToString() });\n\n}\n dataGridView1.DataSource = typeof(List); \n dataGridView1.DataSource = itemStates;\n System.Threading.Thread.Sleep(500);\n"
},
{
"answer_id": 40953879,
"author": "Alexander Abakumov",
"author_id": 3345644,
"author_profile": "https://Stackoverflow.com/users/3345644",
"pm_score": 5,
"selected": false,
"text": "System.Windows.Forms.BindingSource DataGridView var itemStates = new List<ItemState>();\nvar bindingSource1 = new System.Windows.Forms.BindingSource { DataSource = itemStates };\ndataGridView1.DataSource = bindingSource1;\n Add() BindingSource Add() for (var i = 0; i < 10; i++)\n{\n bindingSource1.Add(new ItemState { Id = i.ToString() });\n System.Threading.Thread.Sleep(500);\n}\n DataGridView DataGridView DataSource BindingSource DataGridView"
},
{
"answer_id": 72885206,
"author": "David",
"author_id": 19495496,
"author_profile": "https://Stackoverflow.com/users/19495496",
"pm_score": 0,
"selected": false,
"text": "BindingList<ItemState> itemStates = new BindingList<ItemState>();\ndatagridview1.Rows.Clear();\n\nfor(int i = 0; i < 10; i++)\n{\n itemStates.Add(new ItemState { id = i.ToString() });\n}\n\ndatagridview1.DataSource = itemStates;\nThread.Sleep(500);"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253843",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21180/"
] |
253,849
|
<p>Using MSSQL2005, can I truncate a table with a foreign key constraint if I first truncate the child table (the table with the primary key of the FK relationship)?</p>
<p>I know that I can either</p>
<ul>
<li>Use a <code>DELETE</code> without a where clause and then <code>RESEED</code> the identity (or)</li>
<li>Remove the FK, truncate the table, and recreate the FK.</li>
</ul>
<p>I thought that as long as I truncated the child table before the parent, I'd be okay without doing either of the options above, but I'm getting this error:</p>
<blockquote>
<p>Cannot truncate table 'TableName' because it is being referenced by a FOREIGN KEY constraint.</p>
</blockquote>
|
[
{
"answer_id": 253931,
"author": "ctrlShiftBryan",
"author_id": 6161,
"author_profile": "https://Stackoverflow.com/users/6161",
"pm_score": 8,
"selected": false,
"text": "TRUNCATE TABLE DELETE TRUNCATE TABLE"
},
{
"answer_id": 3039404,
"author": "denver_citizen",
"author_id": 244053,
"author_profile": "https://Stackoverflow.com/users/244053",
"pm_score": 4,
"selected": false,
"text": "SET NOCOUNT ON\n\n-- GLOBAL VARIABLES\nDECLARE @i int\nDECLARE @Debug bit\nDECLARE @Recycle bit\nDECLARE @Verbose bit\nDECLARE @TableName varchar(80)\nDECLARE @ColumnName varchar(80)\nDECLARE @ReferencedTableName varchar(80)\nDECLARE @ReferencedColumnName varchar(80)\nDECLARE @ConstraintName varchar(250)\n\nDECLARE @CreateStatement varchar(max)\nDECLARE @DropStatement varchar(max) \nDECLARE @TruncateStatement varchar(max)\nDECLARE @CreateStatementTemp varchar(max)\nDECLARE @DropStatementTemp varchar(max)\nDECLARE @TruncateStatementTemp varchar(max)\nDECLARE @Statement varchar(max)\n\n -- 1 = Will not execute statements \n SET @Debug = 0\n -- 0 = Will not create or truncate storage table\n -- 1 = Will create or truncate storage table\n SET @Recycle = 0\n -- 1 = Will print a message on every step\n set @Verbose = 1\n\n SET @i = 1\n SET @CreateStatement = 'ALTER TABLE [dbo].[<tablename>] WITH NOCHECK ADD CONSTRAINT [<constraintname>] FOREIGN KEY([<column>]) REFERENCES [dbo].[<reftable>] ([<refcolumn>])'\n SET @DropStatement = 'ALTER TABLE [dbo].[<tablename>] DROP CONSTRAINT [<constraintname>]'\n SET @TruncateStatement = 'TRUNCATE TABLE [<tablename>]'\n\n-- Drop Temporary tables\nDROP TABLE #FKs\n\n-- GET FKs\nSELECT ROW_NUMBER() OVER (ORDER BY OBJECT_NAME(parent_object_id), clm1.name) as ID,\n OBJECT_NAME(constraint_object_id) as ConstraintName,\n OBJECT_NAME(parent_object_id) as TableName,\n clm1.name as ColumnName, \n OBJECT_NAME(referenced_object_id) as ReferencedTableName,\n clm2.name as ReferencedColumnName\n INTO #FKs\n FROM sys.foreign_key_columns fk\n JOIN sys.columns clm1 \n ON fk.parent_column_id = clm1.column_id \n AND fk.parent_object_id = clm1.object_id\n JOIN sys.columns clm2\n ON fk.referenced_column_id = clm2.column_id \n AND fk.referenced_object_id= clm2.object_id\n WHERE OBJECT_NAME(parent_object_id) not in ('//tables that you do not wont to be truncated')\n ORDER BY OBJECT_NAME(parent_object_id)\n\n\n-- Prepare Storage Table\nIF Not EXISTS(SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Internal_FK_Definition_Storage')\n BEGIN\n IF @Verbose = 1\n PRINT '1. Creating Process Specific Tables...'\n\n -- CREATE STORAGE TABLE IF IT DOES NOT EXISTS\n CREATE TABLE [Internal_FK_Definition_Storage] \n (\n ID int not null identity(1,1) primary key,\n FK_Name varchar(250) not null,\n FK_CreationStatement varchar(max) not null,\n FK_DestructionStatement varchar(max) not null,\n Table_TruncationStatement varchar(max) not null\n ) \n END \nELSE\n BEGIN\n IF @Recycle = 0\n BEGIN\n IF @Verbose = 1\n PRINT '1. Truncating Process Specific Tables...'\n\n -- TRUNCATE TABLE IF IT ALREADY EXISTS\n TRUNCATE TABLE [Internal_FK_Definition_Storage] \n END\n ELSE\n PRINT '1. Process specific table will be recycled from previous execution...'\n END\n\nIF @Recycle = 0\n BEGIN\n\n IF @Verbose = 1\n PRINT '2. Backing up Foreign Key Definitions...'\n\n -- Fetch and persist FKs \n WHILE (@i <= (SELECT MAX(ID) FROM #FKs))\n BEGIN\n SET @ConstraintName = (SELECT ConstraintName FROM #FKs WHERE ID = @i)\n SET @TableName = (SELECT TableName FROM #FKs WHERE ID = @i)\n SET @ColumnName = (SELECT ColumnName FROM #FKs WHERE ID = @i)\n SET @ReferencedTableName = (SELECT ReferencedTableName FROM #FKs WHERE ID = @i)\n SET @ReferencedColumnName = (SELECT ReferencedColumnName FROM #FKs WHERE ID = @i)\n\n SET @DropStatementTemp = REPLACE(REPLACE(@DropStatement,'<tablename>',@TableName),'<constraintname>',@ConstraintName)\n SET @CreateStatementTemp = REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(@CreateStatement,'<tablename>',@TableName),'<column>',@ColumnName),'<constraintname>',@ConstraintName),'<reftable>',@ReferencedTableName),'<refcolumn>',@ReferencedColumnName)\n SET @TruncateStatementTemp = REPLACE(@TruncateStatement,'<tablename>',@TableName) \n\n INSERT INTO [Internal_FK_Definition_Storage]\n SELECT @ConstraintName, @CreateStatementTemp, @DropStatementTemp, @TruncateStatementTemp\n\n SET @i = @i + 1\n\n IF @Verbose = 1\n PRINT ' > Backing up [' + @ConstraintName + '] from [' + @TableName + ']'\n\n END\n END \n ELSE \n PRINT '2. Backup up was recycled from previous execution...'\n\n IF @Verbose = 1\n PRINT '3. Dropping Foreign Keys...'\n\n -- DROP FOREING KEYS\n SET @i = 1\n WHILE (@i <= (SELECT MAX(ID) FROM [Internal_FK_Definition_Storage]))\n BEGIN\n SET @ConstraintName = (SELECT FK_Name FROM [Internal_FK_Definition_Storage] WHERE ID = @i)\n SET @Statement = (SELECT FK_DestructionStatement FROM [Internal_FK_Definition_Storage] WITH (NOLOCK) WHERE ID = @i)\n\n IF @Debug = 1 \n PRINT @Statement\n ELSE\n EXEC(@Statement)\n\n SET @i = @i + 1\n\n IF @Verbose = 1\n PRINT ' > Dropping [' + @ConstraintName + ']'\n END \n\n IF @Verbose = 1\n PRINT '4. Truncating Tables...'\n\n -- TRUNCATE TABLES\n SET @i = 1\n WHILE (@i <= (SELECT MAX(ID) FROM [Internal_FK_Definition_Storage]))\n BEGIN\n SET @Statement = (SELECT Table_TruncationStatement FROM [Internal_FK_Definition_Storage] WHERE ID = @i)\n\n IF @Debug = 1 \n PRINT @Statement\n ELSE\n EXEC(@Statement)\n\n SET @i = @i + 1\n\n IF @Verbose = 1\n PRINT ' > ' + @Statement\n END\n\n IF @Verbose = 1\n PRINT '5. Re-creating Foreign Keys...'\n\n -- CREATE FOREING KEYS\n SET @i = 1\n WHILE (@i <= (SELECT MAX(ID) FROM [Internal_FK_Definition_Storage]))\n BEGIN\n SET @ConstraintName = (SELECT FK_Name FROM [Internal_FK_Definition_Storage] WHERE ID = @i)\n SET @Statement = (SELECT FK_CreationStatement FROM [Internal_FK_Definition_Storage] WHERE ID = @i)\n\n IF @Debug = 1 \n PRINT @Statement\n ELSE\n EXEC(@Statement)\n\n SET @i = @i + 1\n\n IF @Verbose = 1\n PRINT ' > Re-creating [' + @ConstraintName + ']'\n END\n\n IF @Verbose = 1\n PRINT '6. Process Completed'\n"
},
{
"answer_id": 5177130,
"author": "Freddie Bell",
"author_id": 381084,
"author_profile": "https://Stackoverflow.com/users/381084",
"pm_score": 3,
"selected": false,
"text": "EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'\nEXEC sp_MSForEachTable 'ALTER TABLE ? DISABLE TRIGGER ALL'\n-- EXEC sp_MSForEachTable 'DELETE FROM ?' -- Uncomment to execute\nEXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL'\nEXEC sp_MSForEachTable 'ALTER TABLE ? ENABLE TRIGGER ALL'\n"
},
{
"answer_id": 6736316,
"author": "Rene",
"author_id": 850426,
"author_profile": "https://Stackoverflow.com/users/850426",
"pm_score": -1,
"selected": false,
"text": "DELETE FROM <your table >;"
},
{
"answer_id": 11784890,
"author": "s15199d",
"author_id": 280785,
"author_profile": "https://Stackoverflow.com/users/280785",
"pm_score": 9,
"selected": false,
"text": "DELETE FROM TABLENAME\nDBCC CHECKIDENT ('DATABASENAME.dbo.TABLENAME', RESEED, 0)\n"
},
{
"answer_id": 12710667,
"author": "Oleg",
"author_id": 1717419,
"author_profile": "https://Stackoverflow.com/users/1717419",
"pm_score": 2,
"selected": false,
"text": "PRINT 'Script starts'\n\nDECLARE @foreign_key_name varchar(255)\nDECLARE @keycnt int\nDECLARE @foreign_table varchar(255)\nDECLARE @foreign_column_1 varchar(255)\nDECLARE @foreign_column_2 varchar(255)\nDECLARE @primary_table varchar(255)\nDECLARE @primary_column_1 varchar(255)\nDECLARE @primary_column_2 varchar(255)\nDECLARE @TablN varchar(255)\n\n-->> Type the primary table name\nSET @TablN = ''\n--------------------------------------------------------------------------------------- ------------------------------\n--Here will be created the temporary table with all reference FKs\n---------------------------------------------------------------------------------------------------------------------\nPRINT 'Creating the temporary table'\nselect cast(f.name as varchar(255)) as foreign_key_name\n , r.keycnt\n , cast(c.name as varchar(255)) as foreign_table\n , cast(fc.name as varchar(255)) as foreign_column_1\n , cast(fc2.name as varchar(255)) as foreign_column_2\n , cast(p.name as varchar(255)) as primary_table\n , cast(rc.name as varchar(255)) as primary_column_1\n , cast(rc2.name as varchar(255)) as primary_column_2\n into #ConTab\n from sysobjects f\n inner join sysobjects c on f.parent_obj = c.id \n inner join sysreferences r on f.id = r.constid\n inner join sysobjects p on r.rkeyid = p.id\n inner join syscolumns rc on r.rkeyid = rc.id and r.rkey1 = rc.colid\n inner join syscolumns fc on r.fkeyid = fc.id and r.fkey1 = fc.colid\n left join syscolumns rc2 on r.rkeyid = rc2.id and r.rkey2 = rc.colid\n left join syscolumns fc2 on r.fkeyid = fc2.id and r.fkey2 = fc.colid\n where f.type = 'F' and p.name = @TablN\n ORDER BY cast(p.name as varchar(255))\n---------------------------------------------------------------------------------------------------------------------\n--Cursor, below, will drop all reference FKs\n---------------------------------------------------------------------------------------------------------------------\nDECLARE @CURSOR CURSOR\n/*Fill in cursor*/\n\nPRINT 'Cursor 1 starting. All refernce FK will be droped'\n\nSET @CURSOR = CURSOR SCROLL\nFOR\nselect foreign_key_name\n , keycnt\n , foreign_table\n , foreign_column_1\n , foreign_column_2\n , primary_table\n , primary_column_1\n , primary_column_2\n from #ConTab\n\nOPEN @CURSOR\n\nFETCH NEXT FROM @CURSOR INTO @foreign_key_name, @keycnt, @foreign_table, @foreign_column_1, @foreign_column_2, \n @primary_table, @primary_column_1, @primary_column_2\n\nWHILE @@FETCH_STATUS = 0\nBEGIN\n\n EXEC ('ALTER TABLE ['+@foreign_table+'] DROP CONSTRAINT ['+@foreign_key_name+']')\n\nFETCH NEXT FROM @CURSOR INTO @foreign_key_name, @keycnt, @foreign_table, @foreign_column_1, @foreign_column_2, \n @primary_table, @primary_column_1, @primary_column_2\nEND\nCLOSE @CURSOR\nPRINT 'Cursor 1 finished work'\n---------------------------------------------------------------------------------------------------------------------\n--Here you should provide the chainging script for the primary table\n---------------------------------------------------------------------------------------------------------------------\n\nPRINT 'Altering primary table begin'\n\nTRUNCATE TABLE table_name\n\nPRINT 'Altering finished'\n\n---------------------------------------------------------------------------------------------------------------------\n--Cursor, below, will add again all reference FKs\n--------------------------------------------------------------------------------------------------------------------\n\nPRINT 'Cursor 2 starting. All refernce FK will added'\nSET @CURSOR = CURSOR SCROLL\nFOR\nselect foreign_key_name\n , keycnt\n , foreign_table\n , foreign_column_1\n , foreign_column_2\n , primary_table\n , primary_column_1\n , primary_column_2\n from #ConTab\n\nOPEN @CURSOR\n\nFETCH NEXT FROM @CURSOR INTO @foreign_key_name, @keycnt, @foreign_table, @foreign_column_1, @foreign_column_2, \n @primary_table, @primary_column_1, @primary_column_2\n\nWHILE @@FETCH_STATUS = 0\nBEGIN\n\n EXEC ('ALTER TABLE [' +@foreign_table+ '] WITH NOCHECK ADD CONSTRAINT [' +@foreign_key_name+ '] FOREIGN KEY(['+@foreign_column_1+'])\n REFERENCES [' +@primary_table+'] (['+@primary_column_1+'])')\n\n EXEC ('ALTER TABLE [' +@foreign_table+ '] CHECK CONSTRAINT [' +@foreign_key_name+']')\n\nFETCH NEXT FROM @CURSOR INTO @foreign_key_name, @keycnt, @foreign_table, @foreign_column_1, @foreign_column_2, \n @primary_table, @primary_column_1, @primary_column_2\nEND\nCLOSE @CURSOR\nPRINT 'Cursor 2 finished work'\n---------------------------------------------------------------------------------------------------------------------\nPRINT 'Temporary table droping'\ndrop table #ConTab\nPRINT 'Finish'\n"
},
{
"answer_id": 13243261,
"author": "karan_s438",
"author_id": 1050973,
"author_profile": "https://Stackoverflow.com/users/1050973",
"pm_score": -1,
"selected": false,
"text": "SET FOREIGN_KEY_CHECKS=0;\nTRUNCATE table1;\nTRUNCATE table2;\nSET FOREIGN_KEY_CHECKS=1;\n"
},
{
"answer_id": 13249209,
"author": "Peter Szanto",
"author_id": 157591,
"author_profile": "https://Stackoverflow.com/users/157591",
"pm_score": 6,
"selected": false,
"text": "CREATE PROCEDURE [dbo].[truncate_non_empty_table]\n\n @TableToTruncate VARCHAR(64)\n\nAS \n\nBEGIN\n\nSET NOCOUNT ON\n\n-- GLOBAL VARIABLES\nDECLARE @i int\nDECLARE @Debug bit\nDECLARE @Recycle bit\nDECLARE @Verbose bit\nDECLARE @TableName varchar(80)\nDECLARE @ColumnName varchar(80)\nDECLARE @ReferencedTableName varchar(80)\nDECLARE @ReferencedColumnName varchar(80)\nDECLARE @ConstraintName varchar(250)\n\nDECLARE @CreateStatement varchar(max)\nDECLARE @DropStatement varchar(max) \nDECLARE @TruncateStatement varchar(max)\nDECLARE @CreateStatementTemp varchar(max)\nDECLARE @DropStatementTemp varchar(max)\nDECLARE @TruncateStatementTemp varchar(max)\nDECLARE @Statement varchar(max)\n\n -- 1 = Will not execute statements \n SET @Debug = 0\n -- 0 = Will not create or truncate storage table\n -- 1 = Will create or truncate storage table\n SET @Recycle = 0\n -- 1 = Will print a message on every step\n set @Verbose = 1\n\n SET @i = 1\n SET @CreateStatement = 'ALTER TABLE [dbo].[<tablename>] WITH NOCHECK ADD CONSTRAINT [<constraintname>] FOREIGN KEY([<column>]) REFERENCES [dbo].[<reftable>] ([<refcolumn>])'\n SET @DropStatement = 'ALTER TABLE [dbo].[<tablename>] DROP CONSTRAINT [<constraintname>]'\n SET @TruncateStatement = 'TRUNCATE TABLE [<tablename>]'\n\n-- Drop Temporary tables\n\nIF OBJECT_ID('tempdb..#FKs') IS NOT NULL\n DROP TABLE #FKs\n\n-- GET FKs\nSELECT ROW_NUMBER() OVER (ORDER BY OBJECT_NAME(parent_object_id), clm1.name) as ID,\n OBJECT_NAME(constraint_object_id) as ConstraintName,\n OBJECT_NAME(parent_object_id) as TableName,\n clm1.name as ColumnName, \n OBJECT_NAME(referenced_object_id) as ReferencedTableName,\n clm2.name as ReferencedColumnName\n INTO #FKs\n FROM sys.foreign_key_columns fk\n JOIN sys.columns clm1 \n ON fk.parent_column_id = clm1.column_id \n AND fk.parent_object_id = clm1.object_id\n JOIN sys.columns clm2\n ON fk.referenced_column_id = clm2.column_id \n AND fk.referenced_object_id= clm2.object_id\n --WHERE OBJECT_NAME(parent_object_id) not in ('//tables that you do not wont to be truncated')\n WHERE OBJECT_NAME(referenced_object_id) = @TableToTruncate\n ORDER BY OBJECT_NAME(parent_object_id)\n\n\n-- Prepare Storage Table\nIF Not EXISTS(SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Internal_FK_Definition_Storage')\n BEGIN\n IF @Verbose = 1\n PRINT '1. Creating Process Specific Tables...'\n\n -- CREATE STORAGE TABLE IF IT DOES NOT EXISTS\n CREATE TABLE [Internal_FK_Definition_Storage] \n (\n ID int not null identity(1,1) primary key,\n FK_Name varchar(250) not null,\n FK_CreationStatement varchar(max) not null,\n FK_DestructionStatement varchar(max) not null,\n Table_TruncationStatement varchar(max) not null\n ) \n END \nELSE\n BEGIN\n IF @Recycle = 0\n BEGIN\n IF @Verbose = 1\n PRINT '1. Truncating Process Specific Tables...'\n\n -- TRUNCATE TABLE IF IT ALREADY EXISTS\n TRUNCATE TABLE [Internal_FK_Definition_Storage] \n END\n ELSE\n PRINT '1. Process specific table will be recycled from previous execution...'\n END\n\n\nIF @Recycle = 0\n BEGIN\n\n IF @Verbose = 1\n PRINT '2. Backing up Foreign Key Definitions...'\n\n -- Fetch and persist FKs \n WHILE (@i <= (SELECT MAX(ID) FROM #FKs))\n BEGIN\n SET @ConstraintName = (SELECT ConstraintName FROM #FKs WHERE ID = @i)\n SET @TableName = (SELECT TableName FROM #FKs WHERE ID = @i)\n SET @ColumnName = (SELECT ColumnName FROM #FKs WHERE ID = @i)\n SET @ReferencedTableName = (SELECT ReferencedTableName FROM #FKs WHERE ID = @i)\n SET @ReferencedColumnName = (SELECT ReferencedColumnName FROM #FKs WHERE ID = @i)\n\n SET @DropStatementTemp = REPLACE(REPLACE(@DropStatement,'<tablename>',@TableName),'<constraintname>',@ConstraintName)\n SET @CreateStatementTemp = REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(@CreateStatement,'<tablename>',@TableName),'<column>',@ColumnName),'<constraintname>',@ConstraintName),'<reftable>',@ReferencedTableName),'<refcolumn>',@ReferencedColumnName)\n SET @TruncateStatementTemp = REPLACE(@TruncateStatement,'<tablename>',@TableName) \n\n INSERT INTO [Internal_FK_Definition_Storage]\n SELECT @ConstraintName, @CreateStatementTemp, @DropStatementTemp, @TruncateStatementTemp\n\n SET @i = @i + 1\n\n IF @Verbose = 1\n PRINT ' > Backing up [' + @ConstraintName + '] from [' + @TableName + ']'\n\n END \n END \n ELSE \n PRINT '2. Backup up was recycled from previous execution...'\n\n IF @Verbose = 1\n PRINT '3. Dropping Foreign Keys...'\n\n -- DROP FOREING KEYS\n SET @i = 1\n WHILE (@i <= (SELECT MAX(ID) FROM [Internal_FK_Definition_Storage]))\n BEGIN\n SET @ConstraintName = (SELECT FK_Name FROM [Internal_FK_Definition_Storage] WHERE ID = @i)\n SET @Statement = (SELECT FK_DestructionStatement FROM [Internal_FK_Definition_Storage] WITH (NOLOCK) WHERE ID = @i)\n\n IF @Debug = 1 \n PRINT @Statement\n ELSE\n EXEC(@Statement)\n\n SET @i = @i + 1\n\n\n IF @Verbose = 1\n PRINT ' > Dropping [' + @ConstraintName + ']'\n\n END \n\n\n IF @Verbose = 1\n PRINT '4. Truncating Tables...'\n\n -- TRUNCATE TABLES\n-- SzP: commented out as the tables to be truncated might also contain tables that has foreign keys\n-- to resolve this the stored procedure should be called recursively, but I dont have the time to do it... \n /*\n SET @i = 1\n WHILE (@i <= (SELECT MAX(ID) FROM [Internal_FK_Definition_Storage]))\n BEGIN\n\n SET @Statement = (SELECT Table_TruncationStatement FROM [Internal_FK_Definition_Storage] WHERE ID = @i)\n\n IF @Debug = 1 \n PRINT @Statement\n ELSE\n EXEC(@Statement)\n\n SET @i = @i + 1\n\n IF @Verbose = 1\n PRINT ' > ' + @Statement\n END\n*/ \n\n\n IF @Verbose = 1\n PRINT ' > TRUNCATE TABLE [' + @TableToTruncate + ']'\n\n IF @Debug = 1 \n PRINT 'TRUNCATE TABLE [' + @TableToTruncate + ']'\n ELSE\n EXEC('TRUNCATE TABLE [' + @TableToTruncate + ']')\n\n\n IF @Verbose = 1\n PRINT '5. Re-creating Foreign Keys...'\n\n -- CREATE FOREING KEYS\n SET @i = 1\n WHILE (@i <= (SELECT MAX(ID) FROM [Internal_FK_Definition_Storage]))\n BEGIN\n SET @ConstraintName = (SELECT FK_Name FROM [Internal_FK_Definition_Storage] WHERE ID = @i)\n SET @Statement = (SELECT FK_CreationStatement FROM [Internal_FK_Definition_Storage] WHERE ID = @i)\n\n IF @Debug = 1 \n PRINT @Statement\n ELSE\n EXEC(@Statement)\n\n SET @i = @i + 1\n\n\n IF @Verbose = 1\n PRINT ' > Re-creating [' + @ConstraintName + ']'\n\n END\n\n IF @Verbose = 1\n PRINT '6. Process Completed'\n\n\nEND\n"
},
{
"answer_id": 17731757,
"author": "renanleandrof",
"author_id": 549913,
"author_profile": "https://Stackoverflow.com/users/549913",
"pm_score": 3,
"selected": false,
"text": "SET NOCOUNT ON\nGO\n\nDECLARE @table TABLE(\nRowId INT PRIMARY KEY IDENTITY(1, 1),\nForeignKeyConstraintName NVARCHAR(200),\nForeignKeyConstraintTableSchema NVARCHAR(200),\nForeignKeyConstraintTableName NVARCHAR(200),\nForeignKeyConstraintColumnName NVARCHAR(200),\nPrimaryKeyConstraintName NVARCHAR(200),\nPrimaryKeyConstraintTableSchema NVARCHAR(200),\nPrimaryKeyConstraintTableName NVARCHAR(200),\nPrimaryKeyConstraintColumnName NVARCHAR(200)\n)\n\nINSERT INTO @table(ForeignKeyConstraintName, ForeignKeyConstraintTableSchema, ForeignKeyConstraintTableName, ForeignKeyConstraintColumnName)\nSELECT\nU.CONSTRAINT_NAME,\nU.TABLE_SCHEMA,\nU.TABLE_NAME,\nU.COLUMN_NAME\nFROM\nINFORMATION_SCHEMA.KEY_COLUMN_USAGE U\nINNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS C\nON U.CONSTRAINT_NAME = C.CONSTRAINT_NAME\nWHERE\nC.CONSTRAINT_TYPE = 'FOREIGN KEY'\n\nUPDATE @table SET\nPrimaryKeyConstraintName = UNIQUE_CONSTRAINT_NAME\nFROM\n@table T\nINNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS R\nON T.ForeignKeyConstraintName = R.CONSTRAINT_NAME\n\nUPDATE @table SET\nPrimaryKeyConstraintTableSchema = TABLE_SCHEMA,\nPrimaryKeyConstraintTableName = TABLE_NAME\nFROM @table T\nINNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS C\nON T.PrimaryKeyConstraintName = C.CONSTRAINT_NAME\n\nUPDATE @table SET\nPrimaryKeyConstraintColumnName = COLUMN_NAME\nFROM @table T\nINNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE U\nON T.PrimaryKeyConstraintName = U.CONSTRAINT_NAME\n\n--DROP CONSTRAINT:\n\nDECLARE @dynSQL varchar(MAX);\n\nDECLARE cur CURSOR FOR\nSELECT\n'\nALTER TABLE [' + ForeignKeyConstraintTableSchema + '].[' + ForeignKeyConstraintTableName + ']\nDROP CONSTRAINT ' + ForeignKeyConstraintName + '\n'\nFROM\n@table\n\nOPEN cur\n\nFETCH cur into @dynSQL\nWHILE @@FETCH_STATUS = 0 \nBEGIN\n exec(@dynSQL)\n print @dynSQL\n\n FETCH cur into @dynSQL\nEND\nCLOSE cur\nDEALLOCATE cur\n---------------------\n\n\n\n --HERE GOES YOUR TRUNCATES!!!!!\n --HERE GOES YOUR TRUNCATES!!!!!\n --HERE GOES YOUR TRUNCATES!!!!!\n\n truncate table your_table\n\n --HERE GOES YOUR TRUNCATES!!!!!\n --HERE GOES YOUR TRUNCATES!!!!!\n --HERE GOES YOUR TRUNCATES!!!!!\n\n---------------------\n--ADD CONSTRAINT:\n\nDECLARE cur2 CURSOR FOR\nSELECT\n'\nALTER TABLE [' + ForeignKeyConstraintTableSchema + '].[' + ForeignKeyConstraintTableName + ']\nADD CONSTRAINT ' + ForeignKeyConstraintName + ' FOREIGN KEY(' + ForeignKeyConstraintColumnName + ') REFERENCES [' + PrimaryKeyConstraintTableSchema + '].[' + PrimaryKeyConstraintTableName + '](' + PrimaryKeyConstraintColumnName + ')\n'\nFROM\n@table\n\nOPEN cur2\n\nFETCH cur2 into @dynSQL\nWHILE @@FETCH_STATUS = 0 \nBEGIN\n exec(@dynSQL)\n\n print @dynSQL\n\n FETCH cur2 into @dynSQL\nEND\nCLOSE cur2\nDEALLOCATE cur2\n"
},
{
"answer_id": 17916304,
"author": "Serj Sagan",
"author_id": 550975,
"author_profile": "https://Stackoverflow.com/users/550975",
"pm_score": 2,
"selected": false,
"text": "MS SQL ALTER TABLE Orders\nNOCHECK CONSTRAINT [FK_dbo.Orders_dbo.Customers_Customer_Id]\nGO\n\nTRUNCATE TABLE Customers\nGO\n\nALTER TABLE Orders\nWITH CHECK CHECK CONSTRAINT [FK_dbo.Orders_dbo.Customers_Customer_Id]\nGO\n"
},
{
"answer_id": 18003505,
"author": "drzaus",
"author_id": 1037948,
"author_profile": "https://Stackoverflow.com/users/1037948",
"pm_score": 2,
"selected": false,
"text": "USE [YourDB];\n\nDECLARE @TransactionName varchar(20) = 'stopdropandroll';\n\nBEGIN TRAN @TransactionName;\nset xact_abort on; /* automatic rollback https://stackoverflow.com/a/1749788/1037948 */\n -- ===== DO WORK // =====\n\n -- dynamic sql placeholder\n DECLARE @SQL varchar(300);\n\n -- LOOP: https://stackoverflow.com/a/10031803/1037948\n -- list of things to loop\n DECLARE @delim char = ';';\n DECLARE @foreach varchar(MAX) = 'Table;Names;Separated;By;Delimiter' + @delim + 'AnotherName' + @delim + 'Still Another';\n DECLARE @token varchar(MAX);\n WHILE len(@foreach) > 0\n BEGIN\n -- set current loop token\n SET @token = left(@foreach, charindex(@delim, @foreach+@delim)-1)\n -- ======= DO WORK // ===========\n\n -- dynamic sql (parentheses are required): https://stackoverflow.com/a/989111/1037948\n SET @SQL = 'DELETE FROM [' + @token + ']; DBCC CHECKIDENT (''' + @token + ''',RESEED, 0);'; -- https://stackoverflow.com/a/11784890\n PRINT @SQL;\n EXEC (@SQL);\n\n -- ======= // END WORK ===========\n -- continue loop, chopping off token\n SET @foreach = stuff(@foreach, 1, charindex(@delim, @foreach+@delim), '')\n END\n\n -- ===== // END WORK =====\n-- review and commit\nSELECT @@TRANCOUNT as TransactionsPerformed, @@ROWCOUNT as LastRowsChanged;\nCOMMIT TRAN @TransactionName;\n EXEC sp_MSForEachTable 'DELETE FROM ?; DBCC CHECKIDENT (''?'',RESEED, 0);';\n"
},
{
"answer_id": 18165956,
"author": "abdelwahed",
"author_id": 2671161,
"author_profile": "https://Stackoverflow.com/users/2671161",
"pm_score": 5,
"selected": false,
"text": "delete from tablename\n\nDBCC CHECKIDENT ('tablename', RESEED, 0)\n"
},
{
"answer_id": 20198884,
"author": "PWF",
"author_id": 3033281,
"author_profile": "https://Stackoverflow.com/users/3033281",
"pm_score": -1,
"selected": false,
"text": "ALTER TABLE CHILD_TABLE DISABLE CONSTRAINT child_par_ref;\nTRUNCATE TABLE CHILD_TABLE;\nTRUNCATE TABLE PARENT_TABLE;\nALTER TABLE CHILD_TABLE ENABLE CONSTRAINT child_par_ref;\n"
},
{
"answer_id": 20463740,
"author": "Rajneesh Kumar",
"author_id": 3081619,
"author_profile": "https://Stackoverflow.com/users/3081619",
"pm_score": 4,
"selected": false,
"text": "reseeding table delete from table_name\ndbcc checkident('table_name',reseed,0)\n"
},
{
"answer_id": 21437099,
"author": "Lauro Wolff Valente Sobrinho",
"author_id": 1378854,
"author_profile": "https://Stackoverflow.com/users/1378854",
"pm_score": 5,
"selected": false,
"text": "ID TABLE_OWNING_CONSTRAINT ALTER TABLE TABLE_OWNING_CONSTRAINT DROP CONSTRAINT FK_PROBLEM_REASON\n TRUNCATE TABLE TABLE_TO_TRUNCATE\n ALTER TABLE TABLE_OWNING_CONSTRAINT ADD CONSTRAINT FK_PROBLEM_REASON FOREIGN KEY(ID) REFERENCES TABLE_TO_TRUNCATE (ID)\n"
},
{
"answer_id": 24706210,
"author": "Eduardo Cuomo",
"author_id": 717267,
"author_profile": "https://Stackoverflow.com/users/717267",
"pm_score": 7,
"selected": false,
"text": "ALTER TABLE -- Delete all records\nDELETE FROM [TableName]\n-- Set current ID to \"1\"\n-- If table already contains data, use \"0\"\n-- If table is empty and never insert data, use \"1\"\n-- Use SP https://github.com/reduardo7/TableTruncate\nDBCC CHECKIDENT ([TableName], RESEED, 0)\n"
},
{
"answer_id": 36208370,
"author": "Ji_in_coding",
"author_id": 3855886,
"author_profile": "https://Stackoverflow.com/users/3855886",
"pm_score": 3,
"selected": false,
"text": "EXEC ('DELETE FROM [schemaName].[tableName]')\nIF EXISTS (Select * from sys.identity_columns where object_name(object_id) = 'tableName')\nBEGIN\n EXEC ('DBCC CHECKIDENT ([schemaName.tableName], RESEED, 0)')\nEND\n"
},
{
"answer_id": 45087029,
"author": "pim",
"author_id": 2421277,
"author_profile": "https://Stackoverflow.com/users/2421277",
"pm_score": 0,
"selected": false,
"text": "SIMPLE begin tran commit tran"
},
{
"answer_id": 45292561,
"author": "Ramin Bateni",
"author_id": 1474613,
"author_profile": "https://Stackoverflow.com/users/1474613",
"pm_score": 3,
"selected": false,
"text": "Query document SP ---------------------------------------------------------------\n------------------- Just Fill Parameters Value ----------------\n---------------------------------------------------------------\nDECLARE @DbName AS NVARCHAR(30) = 'MyDb' --< Db Name\nDECLARE @Schema AS NVARCHAR(30) = 'dbo' --< Schema\nDECLARE @TableName AS NVARCHAR(30) = 'Book' --< Table Name\n------------------ /Just Fill Parameters Value ----------------\n\nDECLARE @Query AS NVARCHAR(500) = 'Delete FROM ' + @TableName\n\nEXECUTE sp_executesql @Query\nSET @Query=@DbName+'.'+@Schema+'.'+@TableName\nDBCC CHECKIDENT (@Query,RESEED, 0)\n -- Book Student\n--\n-- | BookId | Field1 | | StudentId | BookId |\n-- --------------------- ------------------------ \n-- | 1 | A | | 2 | 1 | \n-- | 2 | B | | 1 | 1 |\n-- | 3 | C | | 2 | 3 | \n\n---------------------------------------------------------------\n------------------- Just Fill Parameters Value ----------------\n---------------------------------------------------------------\nDECLARE @DbName AS NVARCHAR(30) = 'MyDb'\nDECLARE @Schema AS NVARCHAR(30) = 'dbo'\nDECLARE @TableName_ToTruncate AS NVARCHAR(30) = 'Book'\n\nDECLARE @TableName_OfOwnerOfConstraint AS NVARCHAR(30) = 'Student' --< Decelations About FK_Book_Constraint\nDECLARE @Ref_ColumnName_In_TableName_ToTruncate AS NVARCHAR(30) = 'BookId' --< Decelations About FK_Book_Constraint\nDECLARE @FK_ColumnName_In_TableOfOwnerOfConstraint AS NVARCHAR(30) = 'Fk_BookId' --< Decelations About FK_Book_Constraint\nDECLARE @FK_ConstraintName AS NVARCHAR(30) = 'FK_Book_Constraint' --< Decelations About FK_Book_Constraint\n------------------ /Just Fill Parameters Value ----------------\n\nDECLARE @Query AS NVARCHAR(2000)\n\nSET @Query= 'ALTER TABLE '+@TableName_OfOwnerOfConstraint+' DROP CONSTRAINT '+@FK_ConstraintName\nEXECUTE sp_executesql @Query\n\nSET @Query= 'Truncate Table '+ @TableName_ToTruncate\nEXECUTE sp_executesql @Query\n\nSET @Query= 'ALTER TABLE '+@TableName_OfOwnerOfConstraint+' ADD CONSTRAINT '+@FK_ConstraintName+' FOREIGN KEY('+@FK_ColumnName_In_TableOfOwnerOfConstraint+') REFERENCES '+@TableName_ToTruncate+'('+@Ref_ColumnName_In_TableName_ToTruncate+')'\nEXECUTE sp_executesql @Query\n"
},
{
"answer_id": 45597248,
"author": "Victor Jimenez",
"author_id": 6434021,
"author_profile": "https://Stackoverflow.com/users/6434021",
"pm_score": 4,
"selected": false,
"text": "SET FOREIGN_KEY_CHECKS = 0; \n\ntruncate table \"yourTableName\";\n\nSET FOREIGN_KEY_CHECKS = 1;\n"
},
{
"answer_id": 54353773,
"author": "GhotiPhud",
"author_id": 600743,
"author_profile": "https://Stackoverflow.com/users/600743",
"pm_score": 4,
"selected": false,
"text": "DECLARE @Debug bit = 0;\n\n-- List of tables to truncate\nselect\n SchemaName, Name\ninto #tables\nfrom (values \n ('schema', 'table')\n ,('schema2', 'table2')\n) as X(SchemaName, Name)\n\n\nBEGIN TRANSACTION TruncateTrans;\n\nwith foreignKeys AS (\n SELECT \n SCHEMA_NAME(fk.schema_id) as SchemaName\n ,fk.Name as ConstraintName\n ,OBJECT_NAME(fk.parent_object_id) as TableName\n ,SCHEMA_NAME(t.SCHEMA_ID) as ReferencedSchemaName\n ,OBJECT_NAME(fk.referenced_object_id) as ReferencedTableName\n ,fc.constraint_column_id\n ,COL_NAME(fk.parent_object_id, fc.parent_column_id) AS ColumnName\n ,COL_NAME(fk.referenced_object_id, fc.referenced_column_id) as ReferencedColumnName\n ,fk.delete_referential_action_desc\n ,fk.update_referential_action_desc\n FROM sys.foreign_keys AS fk\n JOIN sys.foreign_key_columns AS fc\n ON fk.object_id = fc.constraint_object_id\n JOIN #tables tbl \n ON OBJECT_NAME(fc.referenced_object_id) = tbl.Name\n JOIN sys.tables t on OBJECT_NAME(t.object_id) = tbl.Name \n and SCHEMA_NAME(t.schema_id) = tbl.SchemaName\n and t.OBJECT_ID = fc.referenced_object_id\n)\n\n\n\nselect\n quotename(fk.ConstraintName) AS ConstraintName\n ,quotename(fk.SchemaName) + '.' + quotename(fk.TableName) AS TableName\n ,quotename(fk.ReferencedSchemaName) + '.' + quotename(fk.ReferencedTableName) AS ReferencedTableName\n ,replace(fk.delete_referential_action_desc, '_', ' ') AS DeleteAction\n ,replace(fk.update_referential_action_desc, '_', ' ') AS UpdateAction\n ,STUFF((\n SELECT ',' + quotename(fk2.ColumnName)\n FROM foreignKeys fk2 \n WHERE fk2.ConstraintName = fk.ConstraintName and fk2.SchemaName = fk.SchemaName\n ORDER BY fk2.constraint_column_id\n FOR XML PATH('')\n ),1,1,'') AS ColumnNames\n ,STUFF((\n SELECT ',' + quotename(fk2.ReferencedColumnName)\n FROM foreignKeys fk2 \n WHERE fk2.ConstraintName = fk.ConstraintName and fk2.SchemaName = fk.SchemaName\n ORDER BY fk2.constraint_column_id\n FOR XML PATH('')\n ),1,1,'') AS ReferencedColumnNames\ninto #FKs\nfrom foreignKeys fk\nGROUP BY fk.SchemaName, fk.ConstraintName, fk.TableName, fk.ReferencedSchemaName, fk.ReferencedTableName, fk.delete_referential_action_desc, fk.update_referential_action_desc\n\n\n\n-- Drop FKs\nselect \n identity(int,1,1) as ID,\n 'ALTER TABLE ' + fk.TableName + ' DROP CONSTRAINT ' + fk.ConstraintName AS script\ninto #scripts\nfrom #FKs fk\n\n-- Truncate \ninsert into #scripts\nselect distinct \n 'TRUNCATE TABLE ' + quotename(tbl.SchemaName) + '.' + quotename(tbl.Name) AS script\nfrom #tables tbl\n\n-- Recreate\ninsert into #scripts\nselect \n 'ALTER TABLE ' + fk.TableName + \n ' WITH CHECK ADD CONSTRAINT ' + fk.ConstraintName + \n ' FOREIGN KEY ('+ fk.ColumnNames +')' + \n ' REFERENCES ' + fk.ReferencedTableName +' ('+ fk.ReferencedColumnNames +')' +\n ' ON DELETE ' + fk.DeleteAction COLLATE Latin1_General_CI_AS_KS_WS + ' ON UPDATE ' + fk.UpdateAction COLLATE Latin1_General_CI_AS_KS_WS AS script\nfrom #FKs fk\n\n\nDECLARE @script nvarchar(MAX);\n\nDECLARE curScripts CURSOR FOR \n select script\n from #scripts\n order by ID\n\nOPEN curScripts\n\nWHILE 1=1 BEGIN\n FETCH NEXT FROM curScripts INTO @script\n IF @@FETCH_STATUS != 0 BREAK;\n\n print @script;\n IF @Debug = 0\n EXEC (@script);\nEND\nCLOSE curScripts\nDEALLOCATE curScripts\n\n\ndrop table #scripts\ndrop table #FKs\ndrop table #tables\n\n\nCOMMIT TRANSACTION TruncateTrans;\n"
},
{
"answer_id": 56327530,
"author": "mwafi",
"author_id": 407412,
"author_profile": "https://Stackoverflow.com/users/407412",
"pm_score": 1,
"selected": false,
"text": "delete from tablename;\n ALTER TABLE tablename AUTO_INCREMENT = 1;\n"
},
{
"answer_id": 60891315,
"author": "Ehsan Mirsaeedi",
"author_id": 1780760,
"author_profile": "https://Stackoverflow.com/users/1780760",
"pm_score": 2,
"selected": false,
"text": "DECLARE @drop NVARCHAR(MAX) = N'';\n\nSELECT @drop += N'\nALTER TABLE ' + QUOTENAME(cs.name) + '.' + QUOTENAME(ct.name) \n + ' DROP CONSTRAINT ' + QUOTENAME(fk.name) + ';'\nFROM sys.foreign_keys AS fk\nINNER JOIN sys.tables AS ct\n ON fk.parent_object_id = ct.[object_id]\nINNER JOIN sys.schemas AS cs \n ON ct.[schema_id] = cs.[schema_id];\n\nSELECT @drop\n DECLARE @create NVARCHAR(MAX) = N'';\n\nSELECT @create += N'\nALTER TABLE ' \n + QUOTENAME(cs.name) + '.' + QUOTENAME(ct.name) \n + ' ADD CONSTRAINT ' + QUOTENAME(fk.name) \n + ' FOREIGN KEY (' + STUFF((SELECT ',' + QUOTENAME(c.name)\n -- get all the columns in the constraint table\n FROM sys.columns AS c \n INNER JOIN sys.foreign_key_columns AS fkc \n ON fkc.parent_column_id = c.column_id\n AND fkc.parent_object_id = c.[object_id]\n WHERE fkc.constraint_object_id = fk.[object_id]\n ORDER BY fkc.constraint_column_id \n FOR XML PATH(N''), TYPE).value(N'.[1]', N'nvarchar(max)'), 1, 1, N'')\n + ') REFERENCES ' + QUOTENAME(rs.name) + '.' + QUOTENAME(rt.name)\n + '(' + STUFF((SELECT ',' + QUOTENAME(c.name)\n -- get all the referenced columns\n FROM sys.columns AS c \n INNER JOIN sys.foreign_key_columns AS fkc \n ON fkc.referenced_column_id = c.column_id\n AND fkc.referenced_object_id = c.[object_id]\n WHERE fkc.constraint_object_id = fk.[object_id]\n ORDER BY fkc.constraint_column_id \n FOR XML PATH(N''), TYPE).value(N'.[1]', N'nvarchar(max)'), 1, 1, N'') + ');'\nFROM sys.foreign_keys AS fk\nINNER JOIN sys.tables AS rt -- referenced table\n ON fk.referenced_object_id = rt.[object_id]\nINNER JOIN sys.schemas AS rs \n ON rt.[schema_id] = rs.[schema_id]\nINNER JOIN sys.tables AS ct -- constraint table\n ON fk.parent_object_id = ct.[object_id]\nINNER JOIN sys.schemas AS cs \n ON ct.[schema_id] = cs.[schema_id]\nWHERE rt.is_ms_shipped = 0 AND ct.is_ms_shipped = 0;\n\nSELECT @create\n"
},
{
"answer_id": 67451757,
"author": "NM Naufaldo",
"author_id": 11235449,
"author_profile": "https://Stackoverflow.com/users/11235449",
"pm_score": 0,
"selected": false,
"text": "Foo Bar Foo FooColumn Bar BarColumn public override void Down()\n{\n DropForeignKey(\"dbo.Bar\", \"BarColumn\", \"dbo.Foo\");\n Sql(\"TRUNCATE TABLE Foo\");\n AddForeignKey(\"dbo.Bar\", \"BarColumn\", \"dbo.Foo\", \"FooColumn\", cascadeDelete: true);\n}\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253849",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6161/"
] |
253,865
|
<p>In a WPF app, is there a object I can assign to FileSystemWatcher.SynchronizingObject?</p>
<p>I can make my own, but if there is one available, I would like to use it.</p>
|
[
{
"answer_id": 254120,
"author": "Bradley Grainger",
"author_id": 23633,
"author_profile": "https://Stackoverflow.com/users/23633",
"pm_score": 4,
"selected": true,
"text": "ISynchronizeInvoke FileSystemWatcher.SynchronizingObject System.Windows.Form.Control"
},
{
"answer_id": 1096689,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "var fsw = new FileSystemWatcher() \n{ \n //Setting the properties: Path, Filter, NotifyFilter, etc. \n};\n\nfsw.Created += (sender, e) => \n{ \n Dispatcher.Invoke(new Action<params_types>((params_identifiers) => \n { \n //here the code wich interacts with your IU elements \n }), here_params); \n};\n\n\n//... in this way (via Dispatcher.Invoke) with the rest of events\n\nfsw.EnableRaisingEvents = true;\n"
},
{
"answer_id": 6803233,
"author": "Justin",
"author_id": 675699,
"author_profile": "https://Stackoverflow.com/users/675699",
"pm_score": -1,
"selected": false,
"text": " DispatcherTimer t1 = new DispatcherTimer();\n\n private void Window_Loaded(object sender, RoutedEventArgs e)\n {\n t1.Interval = new TimeSpan(0,0,0,0,200);\n t1.Tick += new EventHandler(t1_Tick);\n t1.Start();\n ...\n void t1_Tick(object sender, EventArgs e)\n {\n\n //some work\n\n }\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253865",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14841/"
] |
253,868
|
<p>I'm looking at all the CSS Drop shadow tutorials, which are great. Unfortunately, I need to put a shadow on three sides of a block element (left, bottom, right). All the tutorials talk about shifting your block element up and to the left. Anyone have insights into putting a shadow on three or even four sides?</p>
|
[
{
"answer_id": 253915,
"author": "Diodeus - James MacFarlane",
"author_id": 12579,
"author_profile": "https://Stackoverflow.com/users/12579",
"pm_score": 1,
"selected": false,
"text": "<div style='position:relative;'>\n <div style='position:absolute;top:10px;left:10px;width:300px;height:100px;z-index:1;background-color:#CCCCCC'></div>\n <div style='position:absolute;top:0px;left:0px;width:300px;height:100px;z-index:2;background-color:#00CCFF'>\n <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse at felis. Etiam ullamcorper.</p>\n </div>\n</div>\n"
},
{
"answer_id": 253916,
"author": "Vincent Ramdhanie",
"author_id": 27439,
"author_profile": "https://Stackoverflow.com/users/27439",
"pm_score": 1,
"selected": false,
"text": "<div style=\"position:absolute;top:8;left:12;width:200;height:204;background-color:#888888\"></div>\n<div style=\"position:absolute;top:10;left:10;width:200;height:200;background-color:#FFFFFF\">The element</div>\n"
},
{
"answer_id": 371526,
"author": "Nathan DeWitt",
"author_id": 1753,
"author_profile": "https://Stackoverflow.com/users/1753",
"pm_score": 1,
"selected": true,
"text": "<div id=\"top_margin\"></div>\n<div id=\"left_right_shadow\">this div has a 5 px tall repeating background that is a bit bigger than the width of my content block, shadow on the left, white space, shadow on the right\n <div id=\"content\">Content as normal</div>\n</div>\n<div id=\"bottom_margin\">This has the bottom shadow</div>\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253868",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1753/"
] |
253,881
|
<p>Can't figure out why I'm getting 'SQL Statement ignored' and 'ORA-01775: looping chain of synonyms' on line 52 of this stored procedure. Got any ideas?</p>
<pre><code>CREATE OR REPLACE PACKAGE PURGE_LOG_BY_EVENT_DAYS AS
TYPE dual_cursorType IS REF CURSOR RETURN dual%ROWTYPE;
PROCEDURE log_master_by_event_days (event_id NUMBER, purge_recs_older_than NUMBER, result_cursor OUT dual_cursorType);
END PURGE_LOG_BY_EVENT_DAYS;
/
CREATE OR REPLACE PACKAGE BODY PURGE_LOG_BY_EVENT_DAYS
AS
err_msg VARCHAR2(4000);
PROCEDURE log_master_by_event_days (event_id NUMBER, purge_recs_older_than NUMBER, result_cursor OUT dual_cursorType)
IS
TYPE type_rowid IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
TYPE type_ref_cur IS REF CURSOR;
l_rid type_rowid;
c1 type_ref_cur;
l_sql_stmt VARCHAR2(4000);
proc_start_time DATE := sysdate;
purge_date DATE;
l_bulk_collect_limit NUMBER := 1000;
retry NUMBER := 5;
retry_count NUMBER := 0;
loop_count NUMBER := 0;
err_code VARCHAR2(10);
BEGIN
purge_date := to_date(sysdate - purge_recs_older_than);
l_sql_stmt := '';
l_sql_stmt := l_sql_stmt ||' SELECT rowid FROM LOG_MASTER ';
l_sql_stmt := l_sql_stmt ||' WHERE last_changed_date < :purge_date';
l_sql_stmt := l_sql_stmt ||' AND event_id = :event_id';
-- The following while loop
-- executes the purge code
-- 'retry' number of times in case of ORA-01555
WHILE retry > 0 LOOP
BEGIN
-- START of purge code
OPEN c1 FOR l_sql_stmt USING purge_date, event_id;
LOOP
FETCH c1 BULK COLLECT into l_rid LIMIT l_bulk_collect_limit;
FORALL i IN 1..l_rid.COUNT
DELETE from log_master
WHERE rowid = l_rid(i);
COMMIT;
loop_count := loop_count + 1;
EXIT WHEN c1%NOTFOUND;
END LOOP;
CLOSE c1;
-- End of purge code
-- if processing reached this point
-- Process completed successfuly, set retry = 0 to exit loop
retry := 0;
EXCEPTION
WHEN OTHERS THEN
-- ====================================
-- Get error msg
-- ====================================
ROLLBACK;
err_code := sqlcode;
dbms_output.put_line(err_code);
-- ====================================
-- Check if it is 01555
-- if so retry, else exit loop
-- ====================================
retry := retry - 1;
if err_code = '-1555' and retry > 0 THEN
CLOSE c1;
retry_count := retry_count + 1;
else
err_msg := sqlerrm;
exit;
end if;
END;
END LOOP;
IF err_msg IS NULL THEN
open result_cursor for select '1 - PURGE_LOG_BY_EVENT_DAYS ran successfully (event_id : '||event_id||', loop_count : '||loop_count||', bulk_limit : '||l_bulk_collect_limit||', retries : '||retry_count||') ' from dual;
ELSE
open result_cursor for select '2 - PURGE_LOG_BY_EVENT_DAYS After (event_id : '||event_id||', loop_count : '||loop_count||', bulk_limit : '||l_bulk_collect_limit||', retries : '||retry_count||') with Error: ' || err_msg from dual;
END IF;
END log_master_by_event_days;
END PURGE_LOG_BY_EVENT_DAYS;
</code></pre>
|
[
{
"answer_id": 253909,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "SELECT table_owner, table_name, db_link\n FROM dba_synonyms \n WHERE owner = 'PUBLIC' and db_link is not null\n"
},
{
"answer_id": 254275,
"author": "Dave Costa",
"author_id": 6568,
"author_profile": "https://Stackoverflow.com/users/6568",
"pm_score": 1,
"selected": false,
"text": "LOOP\n DELETE FROM log_master\n WHERE last_changed_date < :purge_date\n AND event_id = :event_id\n AND rownum <= :batch_delete_limit\n USING purge_date, event_id, l_bulk_collect_limit;\n EXIT WHEN SQL%NOTFOUND;\nEND LOOP;\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253881",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
253,911
|
<p>I have a case that keeps coming up where I'm using a ListView or similar control with a simple array such as string[].</p>
<p>Is there a way to use the DataKeyNames property when you are binding to simple collections?</p>
|
[
{
"answer_id": 253939,
"author": "craigmoliver",
"author_id": 12252,
"author_profile": "https://Stackoverflow.com/users/12252",
"pm_score": 0,
"selected": false,
"text": "public class LettersInfo\n{\n public String Letter { get; set; }\n}\n List<LettersInfo> list = new List<LettersInfo>();\nlist.add(new LettersInfo{ Letter = \"A\" });\nlist.add(new LettersInfo{ Letter = \"B\" });\nlist.add(new LettersInfo{ Letter = \"C\" });\n lv.DataKeyNames = \"Letter\";\nlv.DataSource = list;\nlv.DataBind();\n"
},
{
"answer_id": 264452,
"author": "Keltex",
"author_id": 28260,
"author_profile": "https://Stackoverflow.com/users/28260",
"pm_score": 3,
"selected": true,
"text": "string [] files = ...;\n\nvar list = from f in files\n select new { Letter = f };\n\n// anonymous type created with member called Letter\n\nlv.DataKeyNames = \"Letter\";\nlv.DataSource = list;\nlv.DataBind();\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253911",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10115/"
] |
253,913
|
<p>I have a function I've written that was initially supposed to take a string field and populate an excel spreadsheet with the values. Those values continually came up null. I started tracking it back to the recordset and found that despite the query being valid and running properly through the Access query analyzer the recordset was empty or had missing fields.</p>
<p>To test the problem, I created a sub in which I created a query, opened a recordset, and then paged through the values (outputting them to a messagebox). The most perplexing part of the problem seems to revolve around the "WHERE" clause of the query. If I don't put a "WHERE" clause on the query, the recordset always has data and the values for "DESCRIPTION" are normal.</p>
<p>If I put <em>anything</em> in for the WHERE clause the recordset comes back either totally empty (<code>rs.EOF = true</code>) or the Description field is totally blank where the other fields have values. I want to stress again that if I debug.print the query, I can copy/paste it into the query analyzer and get a valid and returned values that I expect.</p>
<p>I'd sure appreciate some help with this. Thank you!</p>
<pre><code>Private Sub NewTest()
' Dimension Variables
'----------------------------------------------------------
Dim rsNewTest As ADODB.Recordset
Dim sqlNewTest As String
Dim Counter As Integer
' Set variables
'----------------------------------------------------------
Set rsNewTest = New ADODB.Recordset
sqlNewTest = "SELECT dbo_partmtl.partnum as [Job/Sub], dbo_partmtl.revisionnum as Rev, " & _
"dbo_part.partdescription as Description, dbo_partmtl.qtyper as [Qty Per] " & _
"FROM dbo_partmtl " & _
"LEFT JOIN dbo_part ON dbo_partmtl.partnum = dbo_part.partnum " & _
"WHERE dbo_partmtl.mtlpartnum=" & Chr(34) & "3C16470" & Chr(34)
' Open recordset
rsNewTest.Open sqlNewTest, CurrentProject.Connection, adOpenDynamic, adLockOptimistic
Do Until rsNewTest.EOF
For Counter = 0 To rsNewTest.Fields.Count - 1
MsgBox rsNewTest.Fields(Counter).Name
Next
MsgBox rsNewTest.Fields("Description")
rsNewTest.MoveNext
Loop
' close the recordset
rsNewTest.Close
Set rsNewTest = Nothing
End Sub
</code></pre>
<p>EDIT: Someone requested that I post the DEBUG.PRINT of the query. Here it is:</p>
<pre><code>SELECT dbo_partmtl.partnum as [Job/Sub], dbo_partmtl.revisionnum as Rev, dbo_part.partdescription as [Description], dbo_partmtl.qtyper as [Qty Per] FROM dbo_partmtl LEFT JOIN dbo_part ON dbo_partmtl.partnum = dbo_part.partnum WHERE dbo_partmtl.mtlpartnum='3C16470'
</code></pre>
<hr>
<p>I have tried double and single quotes using ASCII characters and implicitly.</p>
<p>For example:</p>
<pre><code>"WHERE dbo_partmtl.mtlpartnum='3C16470'"
</code></pre>
<p>I even tried your suggestion with chr(39):</p>
<pre><code>"WHERE dbo_partmtl.mtlpartnum=" & Chr(39) & "3C16470" & Chr(39)
</code></pre>
<p>Both return a null value for description. However, if I debug.print the query and paste it into the Access query analyzer, it displays just fine. Again (as a side note), if I do a LIKE statement in the WHERE clause, it will give me a completely empty recordset. Something is really wonky here.</p>
<hr>
<p>Here is an interesting tidbit. The tables are linked to a <code>SQL Server</code>. If I copy the tables (data and structure) locally, the ADO code above worked flawlessly. If I use DAO it works fine. I've tried this code on <code>Windows XP</code>, <code>Access 2003</code>, and various versions of <code>ADO (2.5, 2.6, 2.8)</code>. <code>ADO</code> will not work if the tables are linked.</p>
<p>There is some flaw in ADO that causes the issue.</p>
<hr>
<p>Absolutely I do. Remember, the <code>DEBUG.PRINT</code> query you see runs perfectly in the query analyzer. It returns the following:</p>
<pre>
Job/Sub Rev Description Qty Per
36511C01 A MAIN ELECTRICAL ENCLOSURE 1
36515C0V A VISION SYSTEM 1
36529C01 A MAIN ELECTRICAL ENCLOSURE 1
</pre>
<p>However, the same query returns empty values for Description (everything else is the same) when run through the recordset (messagebox errors because of "Null" value).</p>
<hr>
<p>I tried renaming the "description" field to "testdep", but it's still empty. The only way to make it display data is to remove the WHERE section of the query. I'm starting to believe this is a problem with ADO. Maybe I'll rewriting it with DAO and seeing what results i get.</p>
<p>EDIT: I also tried compacting and repairing a couple of times. No dice.</p>
|
[
{
"answer_id": 254202,
"author": "Mr Furious",
"author_id": 33124,
"author_profile": "https://Stackoverflow.com/users/33124",
"pm_score": 1,
"selected": false,
"text": "Private Sub AltTest()\n\n' Dimension Variables\n'----------------------------------------------------------\nDim rsNewTest As DAO.Recordset\nDim dbl As DAO.Database\n\nDim sqlNewTest As String\nDim Counter As Integer\n\n' Set variables\n'----------------------------------------------------------\n\nsqlNewTest = \"SELECT dbo_partmtl.partnum as [Job/Sub], dbo_partmtl.revisionnum as Rev, \" & _\n \"dbo_part.partdescription as [TestDep], dbo_partmtl.qtyper as [Qty Per] \" & _\n \"FROM dbo_partmtl \" & _\n \"LEFT JOIN dbo_part ON dbo_partmtl.partnum = dbo_part.partnum \" & _\n \"WHERE dbo_partmtl.mtlpartnum=\" & Chr(39) & \"3C16470\" & Chr(39)\n\n\nDebug.Print \"sqlNewTest: \" & sqlNewTest\nSet dbl = CurrentDb()\nSet rsNewTest = dbl.OpenRecordset(sqlNewTest, dbOpenDynaset)\n\n\n' rsnewtest.OpenRecordset\n\n Do Until rsNewTest.EOF\n\n For Counter = 0 To rsNewTest.Fields.Count - 1\n MsgBox rsNewTest.Fields(Counter).Name\n Next\n\n MsgBox rsNewTest.Fields(\"TestDep\")\n\n rsNewTest.MoveNext\n\n Loop\n\n' close the recordset\n\ndbl.Close\nSet rsNewTest = Nothing\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253913",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33124/"
] |
253,919
|
<p>I want to have CListCtrl.EditLabel() for any column of the list. How can I implement such a feature?</p>
|
[
{
"answer_id": 254202,
"author": "Mr Furious",
"author_id": 33124,
"author_profile": "https://Stackoverflow.com/users/33124",
"pm_score": 1,
"selected": false,
"text": "Private Sub AltTest()\n\n' Dimension Variables\n'----------------------------------------------------------\nDim rsNewTest As DAO.Recordset\nDim dbl As DAO.Database\n\nDim sqlNewTest As String\nDim Counter As Integer\n\n' Set variables\n'----------------------------------------------------------\n\nsqlNewTest = \"SELECT dbo_partmtl.partnum as [Job/Sub], dbo_partmtl.revisionnum as Rev, \" & _\n \"dbo_part.partdescription as [TestDep], dbo_partmtl.qtyper as [Qty Per] \" & _\n \"FROM dbo_partmtl \" & _\n \"LEFT JOIN dbo_part ON dbo_partmtl.partnum = dbo_part.partnum \" & _\n \"WHERE dbo_partmtl.mtlpartnum=\" & Chr(39) & \"3C16470\" & Chr(39)\n\n\nDebug.Print \"sqlNewTest: \" & sqlNewTest\nSet dbl = CurrentDb()\nSet rsNewTest = dbl.OpenRecordset(sqlNewTest, dbOpenDynaset)\n\n\n' rsnewtest.OpenRecordset\n\n Do Until rsNewTest.EOF\n\n For Counter = 0 To rsNewTest.Fields.Count - 1\n MsgBox rsNewTest.Fields(Counter).Name\n Next\n\n MsgBox rsNewTest.Fields(\"TestDep\")\n\n rsNewTest.MoveNext\n\n Loop\n\n' close the recordset\n\ndbl.Close\nSet rsNewTest = Nothing\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253919",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28161/"
] |
253,925
|
<p>I have a Winforms application created in Visual Studio 2005 Pro, it connects to an SQL Server 2005 database using the SqlConnection / SqlCommand / SqlDataAdapter classes to extract data. I have stored procedures in my database to return the data to me.</p>
<p>What is the best way to handle queries that take a "long time" to complete? (i.e long enough that the user starts to think something is wrong). Currently my application locks up until the query is complete, or the query times out. Obviously this is unnacceptable.</p>
<p>I'd at least like a progress meter with a "stop" button on it. The progress meter doesn't even have to do anything useful, being a hint to sit patiently and wait would be enough.</p>
<p>Even better would be a warning that said something like "This will return 140,000 rows of data. Do you want to continue?"</p>
<p>I know this probably requires threads, but how?</p>
|
[
{
"answer_id": 253954,
"author": "John",
"author_id": 30006,
"author_profile": "https://Stackoverflow.com/users/30006",
"pm_score": 2,
"selected": false,
"text": " private void Form_Load(object sender, EventArgs e)\n {\n BackgroundWorker bw = new BackgroundWorker();\n bw.DoWork += new DoWorkEventHandler(bw_DoWork);\n bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);\n //change UI to reflect we're doing this\n bw.RunWorkerAsync();\n }\n\n void bw_DoWork(object sender, DoWorkEventArgs e)\n {\n //SQL Work\n }\n\n void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)\n {\n //Let the user know we're done\n }\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253925",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18854/"
] |
253,937
|
<p>If I wanted to find checked check boxes on an ASP.NET page I could use the following LINQ query.</p>
<pre><code>var checkBoxes = this.Controls
.OfType<CheckBox>()
.TakeWhile<CheckBox>(cb => cb.Checked);
</code></pre>
<p>That works fine if the checkboxes are nested in the current control collection, but I'd like to know how to extend the search by drilling down into the control collections of the top-level controls.</p>
<p>The question was asked here:</p>
<p><a href="https://stackoverflow.com/questions/28642/finding-controls-that-use-a-certain-interface-in-aspnet">Finding controls that use a certain interface in ASP.NET</a></p>
<p>And received non-LINQ answers, I already have my own version of a recursive control search on type and ID as extension methods, but I just wondered how easy this is to do in LINQ?</p>
|
[
{
"answer_id": 253962,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 7,
"selected": true,
"text": "public static IEnumerable<Control> GetAllControls(this Control parent)\n{\n foreach (Control control in parent.Controls)\n {\n yield return control;\n foreach(Control descendant in control.GetAllControls())\n {\n yield return descendant;\n }\n }\n}\n var checkBoxes = this.GetAllControls()\n .OfType<CheckBox>()\n .TakeWhile<CheckBox>(cb => cb.Checked);\n"
},
{
"answer_id": 254056,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "AllControls public static IEnumerable<Control> AllControls(this Control parent)\n {\n foreach (Control control in parent.Controls)\n {\n yield return control;\n }\n foreach (Control control in parent.Controls)\n {\n foreach (Control cc in AllControls(control)) yield return cc;\n }\n }\n foreach"
},
{
"answer_id": 5185293,
"author": "Arthur Dzhelali",
"author_id": 643538,
"author_profile": "https://Stackoverflow.com/users/643538",
"pm_score": 2,
"selected": false,
"text": "public static IEnumerable<Control> AllControls(this Control container)\n{\n //Get all controls\n var controls = container.Controls.Cast<Control>();\n\n //Get all children\n var children = controls.Select(c => c.AllControls());\n\n //combine controls and children\n var firstGen = controls.Concat(children.SelectMany(b => b));\n\n return firstGen;\n}\n public static Control FindControl(this Control container, string Id)\n{\n var child = container.AllControls().FirstOrDefault(c => c.ID == Id);\n return child;\n}\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253937",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29294/"
] |
253,938
|
<p>I have some complex stored procedures that may return many thousands of rows, and take a long time to complete.</p>
<p>Is there any way to find out how many rows are going to be returned before the query executes and fetches the data?</p>
<p>This is with Visual Studio 2005, a Winforms application and SQL Server 2005.</p>
|
[
{
"answer_id": 253965,
"author": "Keltex",
"author_id": 28260,
"author_profile": "https://Stackoverflow.com/users/28260",
"pm_score": 0,
"selected": false,
"text": "select firstname, lastname, email, orderdate from \ncustomer inner join productorder on customer.customerid=productorder.productorderid\nwhere orderdate>@orderdate order by lastname, firstname;\n select count(*) from productorder where orderdate>@orderdate;\n"
},
{
"answer_id": 254001,
"author": "MusiGenesis",
"author_id": 14606,
"author_profile": "https://Stackoverflow.com/users/14606",
"pm_score": 1,
"selected": true,
"text": "SELECT TOP 1000 * FROM tblWHATEVER\n SELECT * FROM tblWHATEVER WHERE ROWNUM <= 1000\n"
},
{
"answer_id": 254219,
"author": "Kibbee",
"author_id": 1862,
"author_profile": "https://Stackoverflow.com/users/1862",
"pm_score": 0,
"selected": false,
"text": "SET showplan_text OFF\nGO\nSET showplan_all on\nGO\n--Replace with call you your stored procedure\nselect * from MyTable\nGO \nSET showplan_all ofF\nGO\n"
},
{
"answer_id": 254643,
"author": "Charles Bretana",
"author_id": 32632,
"author_profile": "https://Stackoverflow.com/users/32632",
"pm_score": 0,
"selected": false,
"text": "Alter Procedure <storedProcName>\n@param1 Type, \n-- Other current params\n@CountsOnly TinyInt = 0\nAs\nSet NoCount On\n\n If @CountsOnly = 1\n Select Count(*) \n From TableA A \n Join TableB B On etc. etc...\n Where < here put all Filtering predicates >\n\n Else\n <Here put old SQL That returns complete resultset with all data>\n\n Return 0\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253938",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18854/"
] |
253,971
|
<p>I have 2 databases, and <strong>I want to transport an existing table containing a CHAR column from database A to database B.</strong></p>
<p>Database A is Oracle 9i, has encoding WE8ISO8859P1, and contains a table "foo" with at least 1 column of type CHAR(1 char). I can not change the table on database A because it is part of a third party setup.</p>
<p>Database B is my own Oracle 10g database, using encoding AL32UTF8 for all kinds of reasons, and I want to copy foo into this database.</p>
<p>I setup a database link from database B to database A. Then I issue the following command:</p>
<p>*create table bar as select * from #link#.foo;*</p>
<p>The data gets copied over nicely, but when I check the types of the columns, I notice that CHAR(1 char) has been converted into CHAR(3 char), and when querying the data in database B, it is all padded with spaces.</p>
<p>I think somewhere underwater, Oracle confuses it's own bytes and chars. CHAR(1 byte) is different from CHAR(1 char) etc. I've read about all that.</p>
<p><strong>Why does the datatype change into a padded CHAR(3 char) and how do I stop Oracle from doing this?</strong></p>
<p><em>Edit: It seems to have to do with transfering CHAR's between two specific patchlevels of Oracle 9 and 10. It looks like it is really a bug. as soon as I find out I'll post an update. Meanwhile: don't try to move CHAR's between databases like I described. VARCHAR2 works fine (tested).</em></p>
<p><em>Edit 2: <strong>I found the answer and posted it here:</strong> <a href="https://stackoverflow.com/questions/253971/why-does-char1-change-to-char3-when-copying-over-an-oracle-dblink#263467">Why does Char(1) change to Char(3) when copying over an Oracle DBLINK?</a>
Too bad I can not accept my own answer, because my problem is solved.</em></p>
|
[
{
"answer_id": 254083,
"author": "Thomas Jones-Low",
"author_id": 23030,
"author_profile": "https://Stackoverflow.com/users/23030",
"pm_score": 2,
"selected": false,
"text": "ALTER SESSION NLS_NCHAR WE8ISO8859P1 \ncreate table bar as select * from #link#.foo;\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253971",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3540161/"
] |
253,982
|
<p>Mac's have TextMate as there preferred application for ruby development, but what would be the preferred application for linux? I need something where it's easy to work with multiple files, project structure and setup commands to run my ruby app or if it is one my merb app.Syntax highlighting is also a must.</p>
<p>Now I typically use Vim, but it's not the best for working with multiple files or with a project structure, even with VTreeView plug-in or multiple VIM windows.</p>
<p>So what would you guys suggest?</p>
<p>If you have better plugins to use for VIM feel free to mention them, I'm not ruling out VIM here.</p>
|
[
{
"answer_id": 8587899,
"author": "Eki Eqbal",
"author_id": 1080046,
"author_profile": "https://Stackoverflow.com/users/1080046",
"pm_score": 1,
"selected": false,
"text": " ⌘+shift+p → “install” → ENTER → “codeintel” → ENTER → Restart ST2\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253982",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1610/"
] |
253,987
|
<p><code>select max(DELIVERY_TIMESTAMP) from DOCUMENTS;</code> will return the time that the latest document was delivered. How do I return <strong>the other columns</strong> for the latest document? For example I want <code>DOC_NAME</code> for the document that was most recently delivered?</p>
<p>I'm not sure how to form the <code>WHERE</code> clause.</p>
|
[
{
"answer_id": 253995,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "Select Max(DELIVERY_TIMESTAMP), \n Doc_Name\nFrom TableName\nGroup By Doc_Name\n"
},
{
"answer_id": 253996,
"author": "Tomalak",
"author_id": 18771,
"author_profile": "https://Stackoverflow.com/users/18771",
"pm_score": 2,
"selected": false,
"text": "SELECT\n DELIVERY_TIMESTAMP,\n OTHER_COLUMN\nFROM\n DOCUMENTS\nWHERE\n DELIVERY_TIMESTAMP = (SELECT MAX(DELIVERY_TIMESTAMP) FROM DOCUMENTS)\n"
},
{
"answer_id": 254003,
"author": "Cade Roux",
"author_id": 18255,
"author_profile": "https://Stackoverflow.com/users/18255",
"pm_score": 4,
"selected": true,
"text": "SELECT DOC_NAME\nFROM DOCUMENTS\nWHERE DELIVERY_TIMESTAMP IN (\n SELECT MAX(DELIVERY_TIMESTAMP)\n FROM DOCUMENTS\n)\n SELECT DOC_NAME\nFROM DOCUMENTS\nINNER JOIN (\n SELECT MAX(DELIVERY_TIMESTAMP) AS MAX_DELIVERY_TIMESTAMP\n FROM DOCUMENTS\n) AS M\n ON M.MAX_DELIVERY_TIMESTAMP = DOCUMENTS.DELIVERY_TIMESTAMP\n MAX() JOIN SELECT DOC_NAME\nFROM DOCUMENTS\nWHERE (DELIVERY_TIMESTAMP, ORDERID) IN (\n SELECT TOP 1 DELIVERY_TIMESTAMP, ORDERID\n FROM DOCUMENTS\n ORDER BY DELIVERY_TIMESTAMP DESC, ORDERID DESC\n)\n SELECT DOC_NAME\nFROM DOCUMENTS\nINNER JOIN (\n SELECT TOP 1 DELIVERY_TIMESTAMP, ORDERID\n FROM DOCUMENTS\n ORDER BY DELIVERY_TIMESTAMP DESC, ORDERID DESC\n) AS M\n ON M.DELIVERY_TIMESTAMP = DOCUMENTS.DELIVERY_TIMESTAMP\n AND M.ORDERID = DOCUMENTS.ORDERID\n"
},
{
"answer_id": 254015,
"author": "TrevorD",
"author_id": 12492,
"author_profile": "https://Stackoverflow.com/users/12492",
"pm_score": 2,
"selected": false,
"text": "SELECT TOP 1 * FROM DOCUMENTS ORDER BY DELIVERY_TIMESTAMP DESC\n"
},
{
"answer_id": 254019,
"author": "Alnitak",
"author_id": 6782,
"author_profile": "https://Stackoverflow.com/users/6782",
"pm_score": 2,
"selected": false,
"text": "SELECT *\nFROM DOCUMENTS\nORDER BY DELIVERY_TIMESTAMP DESC\nLIMIT 1\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253987",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18995/"
] |
253,993
|
<p>Is there a way in C# to:</p>
<ol>
<li><p>Get all the properties of a class that have attributes on them (versus having to loop through all properties and then check if attribute exists.</p></li>
<li><p>If i want all Public, Internal, and Protected properties but NOT private properties, i can't find a way of doing that. I can only do this: </p>
<p>PropertyInfo[] props = type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)</p></li>
</ol>
<p>Is there a way to avoid getting private properties but do get everything else.</p>
|
[
{
"answer_id": 254625,
"author": "Tim Robinson",
"author_id": 32133,
"author_profile": "https://Stackoverflow.com/users/32133",
"pm_score": 1,
"selected": false,
"text": "internal protected private"
},
{
"answer_id": 254641,
"author": "Tim Robinson",
"author_id": 32133,
"author_profile": "https://Stackoverflow.com/users/32133",
"pm_score": 2,
"selected": false,
"text": "TypeDescriptor.GetProperties TypeDescriptor public protected internal"
},
{
"answer_id": 255042,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 2,
"selected": false,
"text": "static class PropertyCache<T>\n{\n private static SomeCacheType cache;\n public static SomeCacheType Cache\n {\n get\n {\n if (cache == null) Build();\n return cache;\n }\n }\n static void Build()\n {\n /// populate \"cache\"\n }\n}\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/253993",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4653/"
] |
254,002
|
<p>I am looking for an expression for the .hgignore file, to ignore all files beneath a specified folder.</p>
<p>eg: I would like to ignore all files and folders beneath bin</p>
<p>Actually any advice on how the expressions are formed would be great</p>
|
[
{
"answer_id": 254049,
"author": "Xian",
"author_id": 4642,
"author_profile": "https://Stackoverflow.com/users/4642",
"pm_score": 2,
"selected": false,
"text": "syntax: regexp\nbin\\\\*\n"
},
{
"answer_id": 255094,
"author": "Ry4an Brase",
"author_id": 8992,
"author_profile": "https://Stackoverflow.com/users/8992",
"pm_score": 8,
"selected": true,
"text": "syntax: glob\nbin/**\n"
},
{
"answer_id": 255123,
"author": "Derek Slager",
"author_id": 18636,
"author_profile": "https://Stackoverflow.com/users/18636",
"pm_score": 3,
"selected": false,
"text": "cabin ^/bin/\n bin"
},
{
"answer_id": 309976,
"author": "user2427",
"author_id": 1356709,
"author_profile": "https://Stackoverflow.com/users/1356709",
"pm_score": -1,
"selected": false,
"text": "syntax: regexp\n?\\.class\n"
},
{
"answer_id": 346233,
"author": "PhiLho",
"author_id": 15459,
"author_profile": "https://Stackoverflow.com/users/15459",
"pm_score": 6,
"selected": false,
"text": "hg status"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/254002",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4642/"
] |
254,004
|
<p>I am using the EMMA tool for code coverage yet despite my best efforts, EMMA is refusing to see the original .java files and generate coverage on a line-by-line basis.</p>
<p>We are using ANT to build the code and debug is set to true. I know that EMMA is measuring coverage as the .emma files seem to be generating and merging correctly. The reports are able to present high level method coverage with percentages. </p>
<p>But why won't it see the .java files? All I get is:
[source file 'a/b/c/d/e/f/code.java' not found in sourcepath]</p>
|
[
{
"answer_id": 254041,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "sourcepath report <report>\n <sourcepath>\n <pathelement path=\"${java.src.dir}\" />\n </sourcepath>\n <fileset dir=\"data\">\n <include name=\"*.emma\" />\n </fileset>\n\n <txt outfile=\"coverage.txt\" />\n <html outfile=\"coverage.html\" />\n</report>\n"
},
{
"answer_id": 254067,
"author": "Ken Gentle",
"author_id": 8709,
"author_profile": "https://Stackoverflow.com/users/8709",
"pm_score": 2,
"selected": false,
"text": "build.xml EMMA report sourcepath report sourcepath -verbose -debug"
},
{
"answer_id": 254087,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "{java.src.dir} src <target name=\"emma.report\" if=\"use.emma\">\n <emma enabled=\"true\">\n <report sourcepath=\"${test.reports.dir}\">\n <!-- collect all EMMA data dumps (metadata and runtime): --> \n <infileset dir=\"${test.data.dir}\" includes=\"*.emma\" /> \n <html outfile=\"${test.reports.dir}/coverage.html\" /> \n </report>\n </emma>\n </target>\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/254004",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
254,009
|
<p>This probably has a simple answer, but I must not have had enough coffee to figure it out on my own:</p>
<p>If I had a comma delimited string such as:</p>
<pre><code>string list = "Fred,Sam,Mike,Sarah";
</code></pre>
<p>How would get each element and add quotes around it and stick it back in a string like this:</p>
<pre><code>string newList = "'Fred','Sam','Mike','Sarah'";
</code></pre>
<p>I'm assuming iterating over each one would be a start, but I got stumped after that.</p>
<p>One solution that is ugly:</p>
<pre><code>int number = 0;
string newList = "";
foreach (string item in list.Split(new char[] {','}))
{
if (number > 0)
{
newList = newList + "," + "'" + item + "'";
}
else
{
newList = "'" + item + "'";
}
number++;
}
</code></pre>
|
[
{
"answer_id": 254012,
"author": "FOR",
"author_id": 27826,
"author_profile": "https://Stackoverflow.com/users/27826",
"pm_score": 8,
"selected": true,
"text": "string s = \"A,B,C\";\nstring replaced = \"'\"+s.Replace(\",\", \"','\")+\"'\";\n string list = \"Fred,Sam,Mike,Sarah\";\nstring newList = string.Join(\",\", list.Split(',').Select(x => string.Format(\"'{0}'\", x)).ToList());\n"
},
{
"answer_id": 254024,
"author": "Tor Haugen",
"author_id": 32050,
"author_profile": "https://Stackoverflow.com/users/32050",
"pm_score": 4,
"selected": false,
"text": "string[] splitList = list.Split(',');\nstring newList = \"'\" + string.Join(\"','\", splitList) + \"'\";\n"
},
{
"answer_id": 254025,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 5,
"selected": false,
"text": "string[] bits = list.Split(','); // Param arrays are your friend\nfor (int i=0; i < bits.Length; i++)\n{\n bits[i] = \"'\" + bits[i] + \"'\";\n}\nreturn string.Join(\",\", bits);\n IEnumerable<string> return list.Split(',').Select(x => \"'\" + x + \"'\").JoinStrings(\",\");\n public static string JoinStrings<T>(this IEnumerable<T> source, \n string separator)\n{\n StringBuilder builder = new StringBuilder();\n bool first = true;\n foreach (T element in source)\n {\n if (first)\n {\n first = false;\n }\n else\n {\n builder.Append(separator);\n }\n builder.Append(element);\n }\n return builder.ToString();\n}\n string.Join return string.Join(\",\", list.Split(',').Select(x => $\"'{x}'\"));\n"
},
{
"answer_id": 254026,
"author": "PhiLho",
"author_id": 15459,
"author_profile": "https://Stackoverflow.com/users/15459",
"pm_score": 2,
"selected": false,
"text": "var s = \"Fred,Sam,Mike,Sarah\";\nalert(s.replace(/\\b/g, \"'\"));\n"
},
{
"answer_id": 254028,
"author": "Jacob Carpenter",
"author_id": 26627,
"author_profile": "https://Stackoverflow.com/users/26627",
"pm_score": 2,
"selected": false,
"text": "Split Join string nameList = \"Fred,Sam,Mike,Sarah\";\nstring[] names = nameList.Split(',');\nstring quotedNames = \"'\" + string.Join(\"','\", names) + \"'\";\n"
},
{
"answer_id": 254029,
"author": "RickL",
"author_id": 7261,
"author_profile": "https://Stackoverflow.com/users/7261",
"pm_score": 1,
"selected": false,
"text": "string list = \"Fred,Sam,Mike,Sarah\";\n\nstring[] splitList = list.Split(',');\n\nfor (int i = 0; i < splitList.Length; i++)\n splitList[i] = String.Format(\"'{0}'\", splitList[i]);\n\nstring newList = String.Join(\",\", splitList);\n"
},
{
"answer_id": 254077,
"author": "bdukes",
"author_id": 2688,
"author_profile": "https://Stackoverflow.com/users/2688",
"pm_score": 0,
"selected": false,
"text": "Regex regex = new Regex(\n @\"\\b\",\n RegexOptions.ECMAScript\n | RegexOptions.Compiled\n );\n\nstring list = \"Fred,Sam,Mike,Sarah\";\nstring newList = regex.Replace(list,\"'\");\n"
},
{
"answer_id": 254163,
"author": "bruno conde",
"author_id": 31136,
"author_profile": "https://Stackoverflow.com/users/31136",
"pm_score": 0,
"selected": false,
"text": "string list = \"Fred,Sam,Mike,Sarah\";\nStringBuilder sb = new StringBuilder();\n\nstring[] listArray = list.Split(new char[] { ',' });\n\nfor (int i = 0; i < listArray.Length; i++)\n{\n sb.Append(\"'\").Append(listArray[i]).Append(\"'\");\n if (i != (listArray.Length - 1))\n sb.Append(\",\");\n}\nstring newList = sb.ToString();\nConsole.WriteLine(newList);\n"
},
{
"answer_id": 9705435,
"author": "vcuankit",
"author_id": 159272,
"author_profile": "https://Stackoverflow.com/users/159272",
"pm_score": 5,
"selected": false,
"text": "List<String> string sep = String.Join(\", \", __messages.Select(x => \"'\" + x + \"'\"));\n"
},
{
"answer_id": 16050294,
"author": "Atish Narlawar",
"author_id": 944663,
"author_profile": "https://Stackoverflow.com/users/944663",
"pm_score": 1,
"selected": false,
"text": "var string[] keys = list.Split(',');\nconsole.log(JSON.stringify(keys));\n"
},
{
"answer_id": 34294571,
"author": "KenB",
"author_id": 4879380,
"author_profile": "https://Stackoverflow.com/users/4879380",
"pm_score": 0,
"selected": false,
"text": "string newList = string.Join(\",\", list.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)\n .Select(x => $\"'{x}'\")\n .ToList());\n string newList = string.Join(\",\", list.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)\n .Select(x => String.Format(\"'{0}'\", x))\n .ToList());\n"
},
{
"answer_id": 37827369,
"author": "Thivan Mydeen",
"author_id": 5626575,
"author_profile": "https://Stackoverflow.com/users/5626575",
"pm_score": 0,
"selected": false,
"text": "String str1 = String.Empty;\nString str2 = String.Empty; \n//str1 = String.Join(\",\", values); if you use this method,result \"X,Y,Z\"\n str1 =String.Join(\"'\" + \",\" + \"'\", values);\n//The result of str1 is \"X','Y','Z\"\n str2 = str1.Insert(0, \"'\").Insert(str1.Length+1, \"'\");\n//The result of str2 is 'X','Y','Z'\n"
},
{
"answer_id": 39274564,
"author": "Dheeraj Palagiri",
"author_id": 2263758,
"author_profile": "https://Stackoverflow.com/users/2263758",
"pm_score": 0,
"selected": false,
"text": " public static string MethodA(this string[] array, string seperatedCharecter = \"|\")\n {\n return array.Any() ? string.Join(seperatedCharecter, array) : string.Empty;\n }\n\n public static string MethodB(this string[] array, string seperatedChar = \"|\")\n {\n return array.Any() ? MethodA(array.Select(x => $\"'{x}'\").ToArray(), seperatedChar) : string.Empty;\n }\n"
},
{
"answer_id": 59863000,
"author": "dylanh724",
"author_id": 6541639,
"author_profile": "https://Stackoverflow.com/users/6541639",
"pm_score": 3,
"selected": false,
"text": "// [ \"foo\", \"bar\" ] => \"\\\"foo\\\"\", \"\\\"bar\\\"\" \nstring.Join(\", \", strList.Select(x => $\"\\\"{x}\\\"\"));\n"
},
{
"answer_id": 74477036,
"author": "Charitha Basnayake",
"author_id": 636148,
"author_profile": "https://Stackoverflow.com/users/636148",
"pm_score": 0,
"selected": false,
"text": "String newList = \"'\" + String.Join(\"','\", list.Split(',')) + \"'\";\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/254009",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12999/"
] |
254,047
|
<p>Is it possible to send a HTTP response with a permanent redirect from a Stellent (now called Oracle UCM) website? We're using version 7.5.2 with iDoc script.</p>
<p>We can use the iDoc function setHttpHeader() to send the Location HTTP header, but how to send the HTTP response code 301, to signal the permanent redirect to the browser?</p>
|
[
{
"answer_id": 34593757,
"author": "Jonathan Hult",
"author_id": 423351,
"author_profile": "https://Stackoverflow.com/users/423351",
"pm_score": 0,
"selected": false,
"text": "<$setRedirectUrl(\"some url\")$>"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/254047",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4167/"
] |
254,054
|
<p>We have a Linux server application that is comprised of a number of open-source tools as well as programs we've written ourselves. Ideally we would like to be able to install this application on any common Linux distribution.</p>
<p>In the past, we've written perl scripts to automate installs of this application. Unfortunately, due to idiosyncrasies of different Linux distros, the logic inside these install scripts gets horribly complex, and can change as new versions of each supported distro are released. Maintaining the installer thus becomes one of the most time-intensive parts of the project!</p>
<p>I'm looking for assistance, be it a framework, documentation, code samples, that can make this process less painful. Here are the types of things our installer needs to do:</p>
<ul>
<li><p>Create user/group accounts</p></li>
<li><p>Create directory trees with specific ownership and permissions</p></li>
<li><p>Install open-source applications, potentially compiling them from source during install</p></li>
<li><p>Insert pre-compiled binaries, scripts, config files, and docs into specific directories</p></li>
<li><p>Register init-type startup and shutdown scripts</p></li>
<li><p>Generate encryption keys</p></li>
<li><p>Verify connectivity to a central server</p></li>
</ul>
|
[
{
"answer_id": 266143,
"author": "Josh Kelley",
"author_id": 25507,
"author_profile": "https://Stackoverflow.com/users/25507",
"pm_score": 2,
"selected": false,
"text": "adduser mkdir install install install /etc/init.d /etc/rc*.d"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/254054",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28314/"
] |
254,058
|
<p>Where can I set the display name in the Service Control Manager of a c++ app?</p>
|
[
{
"answer_id": 12137377,
"author": "Jama A.",
"author_id": 416996,
"author_profile": "https://Stackoverflow.com/users/416996",
"pm_score": 0,
"selected": false,
"text": "sc config <ServiceName> DisplayName= <NewName>\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/254058",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
254,060
|
<p>I am using the WMD markdown editor in a project for a large number of fields that correspond to a large number of properties in a large number of Entity classes. Some classes may have multiple properties that require the markdown.</p>
<p>I am storing the markdown itself since this makes it easier to edit the fields later. However, I need to convert the properties to HTML for display later on. The question is: is there some pattern that I can use to avoid writing markdown conversion code in all my entity classes?</p>
<p>I created a utility class with a method that accepts a markdown string and returns the HTML. I am using markdownj and this works fine.</p>
<p>The problem is for each property of each class that stores markdown I may need another method that converts to HTML:</p>
<pre><code>public class Course{
private String description;
.
.
.
public String getDescription(){
return description;
}
public String getDescriptionAsHTML(){
return MarkdownUtil.convert(getDescription());
}
.
.
.
}
</code></pre>
<p>The problem there is that if the Course class has 2 more properties Tuition and Prerequisites say, that both need converters then I will have to write getTuitionAsHTML() and getPrerequisiteAsHTML().</p>
<p>I find that a bit ugly and would like a cleaner solution. The classes that require this are not part of a single inheritance hierarchy. </p>
<p>The other option I am considering is doing this in the controller rather than the model. What are your thoughts on this? </p>
<p>Thanks.</p>
<p>[EDIT]: New thoughts (Thanks Jasper). Since the project uses struts2 (I did not say this before) I could create a view component say that will convert the markdown for me. Then I use that wherever I need to display the value as HTML.</p>
|
[
{
"answer_id": 254148,
"author": "Chris Cudmore",
"author_id": 18907,
"author_profile": "https://Stackoverflow.com/users/18907",
"pm_score": 1,
"selected": false,
"text": "public String getDescription(MarkDownUtil converter)\n{\n if (converter == null) return description;\n else return MarkdownUtil.convert(description);\n}\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/254060",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27439/"
] |
254,066
|
<p>On Windows XP, the following command in a script will prevent any power saving options from being enabled on the PC (monitor sleep, HD sleep, etc.). This is useful for kiosk applications.</p>
<pre><code>powercfg.exe /setactive presentation
</code></pre>
<p>What is the equivalent on Vista?</p>
|
[
{
"answer_id": 254131,
"author": "jeremyasnyder",
"author_id": 33143,
"author_profile": "https://Stackoverflow.com/users/33143",
"pm_score": 3,
"selected": true,
"text": "powercfg.exe -list\n powercfg.exe -setactive GUID\n Usage: POWERCFG -X <SETTING> <VALUE>\n\n <SETTING> Specifies one of the following options:\n -monitor-timeout-ac <minutes>\n -monitor-timeout-dc <minutes>\n -disk-timeout-ac <minutes>\n -disk-timeout-dc <minutes>\n -standby-timeout-ac <minutes>\n -standby-timeout-dc <minutes>\n -hibernate-timeout-ac <minutes>\n -hibernate-timeout-dc <minutes>\n\n Example:\n POWERCFG -Change -monitor-timeout-ac 5\n\n This would set the monitor idle timeout value to 5 minutes\n when on AC power.\n"
},
{
"answer_id": 258777,
"author": "Nick",
"author_id": 1490,
"author_profile": "https://Stackoverflow.com/users/1490",
"pm_score": 3,
"selected": false,
"text": "0 -change powercfg.exe -change -monitor-timeout-ac 0\n powercfg.exe -change -monitor-timeout-ac 0\npowercfg.exe -change -disk-timeout-ac 0\npowercfg.exe -change -standby-timeout-ac 0\npowercfg.exe -change -hibernate-timeout-ac 0\n"
},
{
"answer_id": 40845554,
"author": "Binu AN",
"author_id": 7220425,
"author_profile": "https://Stackoverflow.com/users/7220425",
"pm_score": 0,
"selected": false,
"text": "@ECHO OFF\n\npowercfg -change -monitor-timeout-ac 0\npowercfg -change -standby-timeout-ac 0\npowercfg -change -disk-timeout-ac 0\npowercfg -change -hibernate-timeout-ac 0\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/254066",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1490/"
] |
254,071
|
<p>I tried to use <code>OPTION (MAXRECURSION 0)</code> in a view to generate a list of dates.
This seems to be unsupported. Is there a workaround for this issue?</p>
<p>EDIT to Explain what I actually want to do:</p>
<p>I have 2 tables.</p>
<p>table1: int weekday, bool available</p>
<p>table2: datetime date, bool available</p>
<p>I want the result:
view1: date (here all days in this year), available(from table2 or from table1 when not in table2).</p>
<p>That means I have to apply a join on a date with a weekday.
I hope this explanation is understandable, because I actually use more tables with more fields in the query.</p>
<p>I found this code to generate the recursion:</p>
<pre><code>WITH Dates AS
(
SELECT cast('2008-01-01' as datetime) Date
UNION ALL
SELECT Date + 1
FROM Dates
WHERE Date + 1 < DATEADD(yy, 1, GETDATE())
)
</code></pre>
|
[
{
"answer_id": 13417526,
"author": "Stefan Steiger",
"author_id": 155077,
"author_profile": "https://Stackoverflow.com/users/155077",
"pm_score": 0,
"selected": false,
"text": ";WITH CTE_Stack(IsPartOfRecursion, Depth, MyDate) AS\n(\n SELECT \n 0 AS IsPartOfRecursion\n ,0 AS Dept \n ,DATEADD(DAY, -1, CAST('01.01.2012' as datetime)) AS MyDate \n UNION ALL\n\n SELECT \n 1 AS IsPartOfRecursion \n ,Parent.Depth + 1 AS Depth \n --,DATEADD(DAY, 1, Parent.MyDate) AS MyDate\n ,DATEADD(DAY, 1, Parent.MyDate) AS MyDate\n FROM \n (\n SELECT 0 AS Nothing \n ) AS TranquillizeSyntaxCheckBecauseWeDontHaveAtable \n\n INNER JOIN CTE_Stack AS Parent \n --ON Parent.Depth < 2005 \n ON DATEADD(DAY, 1, Parent.MyDate) < DATEADD(YEAR, 1, CAST('01.01.2012' as datetime)) \n)\n\nSELECT * FROM CTE_Stack \nWHERE IsPartOfRecursion = 1\nOPTION (MAXRECURSION 367) -- Accounting for leap-years\n;\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/254071",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13376/"
] |
254,076
|
<p>This is the error Dependency Walker gives me on an executable that I am building with VC++ 2005 Express Edition. When trying to run the .exe, I get:</p>
<pre><code>This application has failed to start because the application configuration
is incorrect. Reinstalling the application may fix this problem.
</code></pre>
<p>(I am new to the manifest/SxS/etc. way of doing things post VC++ 2003.)</p>
<p>EDIT:
I am running on the same machine I am building the .exe with. In Event Viewer, I have the unhelpful:</p>
<pre><code>Faulting application blah.exe, version 0.0.0.0, faulting module blah.exe,
version 0.0.0.0, fault address 0x004239b0.
</code></pre>
|
[
{
"answer_id": 1093162,
"author": "Ian Kemp",
"author_id": 70345,
"author_profile": "https://Stackoverflow.com/users/70345",
"pm_score": 3,
"selected": false,
"text": "C:\\Program Files\\Microsoft Visual Studio 8\\VC\\redist\\x86\\Microsoft.VC80.CRT\n"
}
] |
2008/10/31
|
[
"https://Stackoverflow.com/questions/254076",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2666/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.