qid
int64 4
19.1M
| question
stringlengths 18
48.3k
| answers
list | date
stringlengths 10
10
| metadata
list |
|---|---|---|---|---|
106,472
|
<p>What are good methodologies for creating sprocs that reduce the pain of debugging? And what tools are out there for debugging stored procedures?</p>
<p>Perhaps most importantly, what are indications to look out for that errors are happening in a sproc and not in the code? I hope I'm not all over the board too terribly bad here. Votes for answers to any of the above. Thanks.</p>
<p>For what it's worth, I work in a .NET environment, SQL servers.</p>
|
[
{
"answer_id": 106648,
"author": "Seibar",
"author_id": 357,
"author_profile": "https://Stackoverflow.com/users/357",
"pm_score": 1,
"selected": false,
"text": "LEFT JOIN\n /************************************\n MyProcName\n\n Test:\n -----\n exec MyProcName @myParam\n*************************************/\n"
},
{
"answer_id": 106698,
"author": "Ron Savage",
"author_id": 12476,
"author_profile": "https://Stackoverflow.com/users/12476",
"pm_score": 3,
"selected": false,
"text": " --**************************************************************************\n -- Create a log table variable to store messages to be returned to the\n -- calling application.\n --**************************************************************************\n declare @log as table ( msg varchar(MAX) );\n\nthen\n\n insert into @log values ('Inserted a new DVO Order into IRMA, order id: [' + convert(varchar(10), @@IDENTITY ) + ']');\netc.\n\nthen ...\n\n select msg from @log;\nend\n"
},
{
"answer_id": 119458,
"author": "karlgrz",
"author_id": 318,
"author_profile": "https://Stackoverflow.com/users/318",
"pm_score": 2,
"selected": false,
"text": "SELECT\n [Fields]\nFROM\n Table\nWHERE\n x = x\n"
},
{
"answer_id": 1370805,
"author": "Jafin",
"author_id": 40513,
"author_profile": "https://Stackoverflow.com/users/40513",
"pm_score": 1,
"selected": false,
"text": "Select * from LogEvent where BatchId = 'blah'\n EXEC LogEvent @Source='MyProc', @Type='Start'\n, @Comment='Processed rows',@Value=50, @BatchId = @batchNum\n CREATE PROCEDURE [dbo].[LogEvent]\n @Source varchar(50),\n @Type varchar(50),\n @Comment varchar(400),\n @Value decimal = null,\n @BatchId varchar(255) = 'BLANK'\nAS\n\nIF @BatchId = 'BLANK'\n SET @BatchId = NEWID()\n\n INSERT INTO dbo.Log\n (Source, EventTime, [Type], Comment, [Value],BatchId)\n VALUES\n (@Source, GETDATE(), @Type, @Comment, @Value,@BatchId)\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/106472",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13578/"
] |
106,473
|
<p>We make heavy use of Velocity in our web application. While it is easy to debug the Java side of things and ensure the Velocity Context is populated correctly, it would be extremely valuable to be able to step through the parsing of the VTL on the merge step, set breakpoints, etc. Are there any tools or IDEs/IDE plugins that would make this kind of thing possible with VTL (Velocity Template Language)?</p>
|
[
{
"answer_id": 7972815,
"author": "DJ.",
"author_id": 10638,
"author_profile": "https://Stackoverflow.com/users/10638",
"pm_score": 3,
"selected": false,
"text": "#if($logger.log($data)) #end"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/106473",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17123/"
] |
106,476
|
<p>I have a setup executable that I need to install. When I run it, it launches a msi to do the actual install and then dies immediately. The side effect of this is it will return control back to any console you call it from before the install finishes. Depending on what machine I run it on, it can take from three to ten minutes so having the calling script sleep is undesirable. I would launch the msi directly but it complains about missing components. </p>
<p>I have a WSH script that uses WMI to start a process and then watch until it's pid is no longer running. Is there some way to determine the pid of the MSI the initial executable is executing, and then watch for that pid to end using WMI? Is the launching process information even associated with a process?</p>
|
[
{
"answer_id": 106601,
"author": "Jim Olsen",
"author_id": 15603,
"author_profile": "https://Stackoverflow.com/users/15603",
"pm_score": 2,
"selected": true,
"text": "c:\\>wmic PROCESS WHERE ParentProcessId=4000 GET CommandLine, ProcessId \nCommandLine ProcessId\n\"C:\\Windows\\System32\\msiexec.exe\" /i \"C:\\blahblahblah.msi\" 2752\n Set objWMIService = GetObject(\"winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\cimv2\")\nSet colProcesses = objWMIService.ExecQuery(\"select * from Win32_Process where ParentProcessId = 4000\")\nFor Each objProcess in colProcesses\n Wscript.Echo \"Process ID: \" & objProcess.ProcessId\nNext\n"
},
{
"answer_id": 107110,
"author": "halr9000",
"author_id": 6637,
"author_profile": "https://Stackoverflow.com/users/6637",
"pm_score": 0,
"selected": false,
"text": "$p1 = [diagnostics.process]::start($pathToExecutable) # this way we know the PID of the initial exe\n$p2 = get-wmiobject win32_process -filter \"ParentProcessId = $($p1.Id)\" # using Jim Olsen's tip\n(get-process -id $p2.ProcessId).WaitForExit() # voila--no messy sleeping\n"
}
] |
2008/09/19
|
[
"https://Stackoverflow.com/questions/106476",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
106,481
|
<p>I have this line in a javascript block in a page:</p>
<pre><code>res = foo('<%= @ruby_var %>');
</code></pre>
<p>What is the best way to handle the case where <code>@ruby_var</code> has a single-quote in it? Else it will break the JavaScript code.</p>
|
[
{
"answer_id": 106518,
"author": "Max Cantor",
"author_id": 16034,
"author_profile": "https://Stackoverflow.com/users/16034",
"pm_score": 2,
"selected": false,
"text": "@ruby_var.gsub(/[']/, '\\\\\\\\\\'')\n"
},
{
"answer_id": 106557,
"author": "TFKyle",
"author_id": 19208,
"author_profile": "https://Stackoverflow.com/users/19208",
"pm_score": 5,
"selected": true,
"text": "res = foo(<%= @ruby_var.to_json %>)\n"
},
{
"answer_id": 106808,
"author": "Toby Hede",
"author_id": 14971,
"author_profile": "https://Stackoverflow.com/users/14971",
"pm_score": 2,
"selected": false,
"text": "res = foo(\"<%= @ruby_var %>\"); \n"
},
{
"answer_id": 108422,
"author": "Joseph Pecoraro",
"author_id": 792,
"author_profile": "https://Stackoverflow.com/users/792",
"pm_score": 0,
"selected": false,
"text": "p inspect <%= print puts p >> p \"String ' \\\" String\"\n\"String ' \\\" String\"\n# => nil \n>> p 'alpha \" \\' alpha'\n\"alpha \\\" ' alpha\"\n# => nil \n"
},
{
"answer_id": 192389,
"author": "Caged",
"author_id": 26876,
"author_profile": "https://Stackoverflow.com/users/26876",
"pm_score": 2,
"selected": false,
"text": "res = foo(<%= @ruby_var.inspect %>);\n"
},
{
"answer_id": 9283249,
"author": "Mike Jarema",
"author_id": 1001980,
"author_profile": "https://Stackoverflow.com/users/1001980",
"pm_score": 3,
"selected": false,
"text": "res = foo('<%= escape_javascript @ruby_var %>');\n res = foo('<%= j @ruby_var %>');\n"
},
{
"answer_id": 41139801,
"author": "Rakshit Singh",
"author_id": 7165943,
"author_profile": "https://Stackoverflow.com/users/7165943",
"pm_score": 0,
"selected": false,
"text": "json res = foo('<%= @ruby_var %>.first'); \n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/106481",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19409/"
] |
106,508
|
<p>What is a smart pointer and when should I use one?</p>
|
[
{
"answer_id": 106523,
"author": "C. K. Young",
"author_id": 13,
"author_profile": "https://Stackoverflow.com/users/13",
"pm_score": 4,
"selected": false,
"text": "std::tr1::shared_ptr boost::shared_ptr std::auto_ptr shared_ptr shared_ptr libc"
},
{
"answer_id": 106568,
"author": "sergtk",
"author_id": 13441,
"author_profile": "https://Stackoverflow.com/users/13441",
"pm_score": 7,
"selected": false,
"text": "std::auto_ptr boost::shared_ptr std::shared_ptr std::shared_ptr std::weak_ptr std::unique_ptr std::auto_ptr boost::shared_ptr"
},
{
"answer_id": 106614,
"author": "Lloyd",
"author_id": 9952,
"author_profile": "https://Stackoverflow.com/users/9952",
"pm_score": 12,
"selected": true,
"text": "std::unique_ptr std::shared_ptr std::weak_ptr std::auto_ptr std::auto_ptr<MyObject> p1 (new MyObject());\nstd::auto_ptr<MyObject> p2 = p1; // Copy and transfer ownership. \n // p1 gets set to empty!\np2->DoSomething(); // Works.\np1->DoSomething(); // Oh oh. Hopefully raises some NULL pointer exception.\n // Need to create the object to achieve some goal\nMyObject* ptr = new MyObject(); \nptr->DoSomething(); // Use the object in some way\ndelete ptr; // Destroy the object. Done with it.\n// Wait, what if DoSomething() raises an exception...?\n SomeSmartPtr<MyObject> ptr(new MyObject());\nptr->DoSomething(); // Use the object in some way.\n\n// Destruction of the object happens, depending \n// on the policy the smart pointer class uses.\n\n// Destruction would happen even if DoSomething() \n// raises an exception\n boost::scoped_ptr std::unique_ptr void f()\n{\n {\n std::unique_ptr<MyObject> ptr(new MyObject());\n ptr->DoSomethingUseful();\n } // ptr goes out of scope -- \n // the MyObject is automatically destroyed.\n\n // ptr->Oops(); // Compile error: \"ptr\" not defined\n // since it is no longer in scope.\n}\n std::unique_ptr std::unique_ptr boost::shared_ptr std::shared_ptr void f()\n{\n typedef std::shared_ptr<MyObject> MyObjectPtr; // nice short alias\n MyObjectPtr p1; // Empty\n\n {\n MyObjectPtr p2(new MyObject());\n // There is now one \"reference\" to the created object\n p1 = p2; // Copy the pointer.\n // There are now two references to the object.\n } // p2 is destroyed, leaving one reference to the object.\n} // p1 is destroyed, leaving a reference count of zero. \n // The object is deleted.\n // Create the smart pointer on the heap\nMyObjectPtr* pp = new MyObjectPtr(new MyObject())\n// Hmm, we forgot to destroy the smart pointer,\n// because of that, the object is never destroyed!\n struct Owner {\n std::shared_ptr<Owner> other;\n};\n\nstd::shared_ptr<Owner> p1 (new Owner());\nstd::shared_ptr<Owner> p2 (new Owner());\np1->other = p2; // p1 references p2\np2->other = p1; // p2 references p1\n\n// Oops, the reference count of of p1 and p2 never goes to zero!\n// The objects are never destroyed!\n weak_ptr shared_ptr"
},
{
"answer_id": 106759,
"author": "Sridhar Iyer",
"author_id": 13820,
"author_profile": "https://Stackoverflow.com/users/13820",
"pm_score": 6,
"selected": false,
"text": "-> * shared_ptr auto_ptr"
},
{
"answer_id": 15357935,
"author": "Saqlain",
"author_id": 1012551,
"author_profile": "https://Stackoverflow.com/users/1012551",
"pm_score": 5,
"selected": false,
"text": "shared_ptr<T> T scoped_ptr<T> intrusive_ptr<T> shared_ptr T weak_ptr<T> shared_ptr shared_array<T> shared_ptr T scoped_array<T> scoped_ptr T std::unique_ptr std::shared_ptr std::weak_ptr std::auto_ptr"
},
{
"answer_id": 22245665,
"author": "Santosh",
"author_id": 3240133,
"author_profile": "https://Stackoverflow.com/users/3240133",
"pm_score": 4,
"selected": false,
"text": "template <class X>\nclass smart_pointer\n{\n public:\n smart_pointer(); // makes a null pointer\n smart_pointer(const X& x) // makes pointer to copy of x\n\n X& operator *( );\n const X& operator*( ) const;\n X* operator->() const;\n\n smart_pointer(const smart_pointer <X> &);\n const smart_pointer <X> & operator =(const smart_pointer<X>&);\n ~smart_pointer();\n private:\n //...\n};\n smart_pointer <employee> p= employee(\"Harris\",1333);\n cout<<*p;\np->raise_salary(0.5);\n"
},
{
"answer_id": 30143936,
"author": "einpoklum",
"author_id": 1593077,
"author_profile": "https://Stackoverflow.com/users/1593077",
"pm_score": 9,
"selected": false,
"text": "std::unique_ptr std::shared_ptr std::weak_ptr boost:: std::auto_ptr"
},
{
"answer_id": 35761185,
"author": "nnrales",
"author_id": 4749396,
"author_profile": "https://Stackoverflow.com/users/4749396",
"pm_score": 4,
"selected": false,
"text": "T a; \nT * _ptr = &a; \n T a ; \nconst T * ptr1 = &a ; \nT const * ptr1 = &a ;\n *ptr1 = 19 ptr1++ , ptr1-- T * const ptr2 ;\n *ptr2 = 19 ptr2++ ; ptr2-- const T * const ptr3 ; \n ptr3-- ; ptr3++ ; *ptr3 = 19; #include <memory> T a ; \n //shared_ptr<T> shptr(new T) ; not recommended but works \n shared_ptr<T> shptr = make_shared<T>(); // faster + exception safe\n\n std::cout << shptr.use_count() ; // 1 // gives the number of \" \nthings \" pointing to it. \n T * temp = shptr.get(); // gives a pointer to object\n\n // shared_pointer used like a regular pointer to call member functions\n shptr->memFn();\n (*shptr).memFn(); \n\n //\n shptr.reset() ; // frees the object pointed to be the ptr \n shptr = nullptr ; // frees the object \n shptr = make_shared<T>() ; // frees the original object and points to new object\n T a ; \nshared_ptr<T> shr = make_shared<T>() ; \nweak_ptr<T> wk = shr ; // initialize a weak_ptr from a shared_ptr \nwk.lock()->memFn() ; // use lock to get a shared_ptr \n// ^^^ Can lead to exception if the shared ptr has gone out of scope\nif(!wk.expired()) wk.lock()->memFn() ;\n// Check if shared ptr has gone out of scope before access\n unique_ptr<T> uptr(new T);\nuptr->memFn(); \n\n//T * ptr = uptr.release(); // uptr becomes null and object is pointed to by ptr\nuptr.reset() ; // deletes the object pointed to by uptr \n unique_ptr<T> uptr1(new T);\nunique_ptr<T> uptr2(new T);\nuptr2 = std::move(uptr1); \n// object pointed by uptr2 is deleted and \n// object pointed by uptr1 is pointed to by uptr2\n// uptr1 becomes null \n r-value reference : reference to a temporary object \nl-value reference : reference to an object whose address can be obtained\nconst reference : reference to a data type which is const and cannot be modified \n"
},
{
"answer_id": 63325001,
"author": "lbsweek",
"author_id": 2482283,
"author_profile": "https://Stackoverflow.com/users/2482283",
"pm_score": 3,
"selected": false,
"text": "RAII: Resource Acquisition Is Initialization.\n\n● When you initialize an object, it should already have \n acquired any resources it needs (in the constructor).\n\n\n● When an object goes out of scope, it should release every \n resource it is using (using the destructor).\n ● There should never be a half-ready or half-dead object.\n● When an object is created, it should be in a ready state.\n● When an object goes out of scope, it should release its resources. \n● The user shouldn’t have to do anything more. \n Have a smart pointer class:\n● Allocates the memory when initialized\n● Frees the memory when destructor is called\n● Allows access to underlying pointer\n ● use another memory to store Reference counting and shared.\n● increment when copy, decrement when destructor.\n● delete memory when Reference counting is 0. \n also delete memory that store Reference counting.\n ● not change Reference counting.\n correct way:\nstd::shared_ptr<T> t1 = std::make_shared<T>(TArgs);\nstd::shared_ptr<T> t2 = std::shared_ptr<T>(new T(Targs));\n\nwrong way:\nT* pt = new T(TArgs); // never exposure the raw pointer\nshared_ptr<T> t1 = shared_ptr<T>(pt);\nshared_ptr<T> t2 = shared_ptr<T>(pt);\n not use T*\nuse T& \n T* pt; is optional reference and maybe nullptr.\nNot own the raw pointer, \nRaw pointer is managed by some one else.\nI only know that the caller is sure it is not released now.\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/106508",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19410/"
] |
106,509
|
<p>I have a button that I would like to disable when the form submits to prevent the user submitting multiple times.</p>
<p>I have tried naively disabling the button with javascript onclick but then if a client side validation that fails the button remains disabled.</p>
<p>How do I disable the button when the form successfully submits not just when the user clicks?</p>
<p>This is an ASP.NET form so I would like to hook in nicely with the asp.net ajax page lifecycle if possible.</p>
|
[
{
"answer_id": 106840,
"author": "Turnkey",
"author_id": 13144,
"author_profile": "https://Stackoverflow.com/users/13144",
"pm_score": 3,
"selected": false,
"text": "<input type=\"hidden\" name=\"form_submitted\" value=\"0\">\n\nfunction check_submit (){\n if (document.Form1.form_submitted.value == 1){\n alert(\"Don't submit twice. Please wait.\");\n return false;\n }\n else{\n document.Form1.form_submitted.value = 1;\n return true;\n }\n return false;\n }\n"
},
{
"answer_id": 106958,
"author": "rp.",
"author_id": 2536,
"author_profile": "https://Stackoverflow.com/users/2536",
"pm_score": 5,
"selected": true,
"text": "using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Web;\nusing System.Web.UI;\nusing System.Web.UI.WebControls;\nusing System.Threading;\n\npublic partial class _Default : System.Web.UI.Page \n{\n protected void Page_Load(object sender, EventArgs e)\n {\n\n // Identify button as a \"disabled-when-clicked\" button...\n WebHelpers.DisableButtonOnClick( buttonTest, \"showPleaseWait\" ); \n }\n\n protected void buttonTest_Click( object sender, EventArgs e )\n {\n // Emulate a server-side process to demo the disabled button during\n // postback.\n Thread.Sleep( 5000 );\n }\n}\n\n\n\nusing System;\nusing System.Web;\nusing System.Web.UI.WebControls;\nusing System.Text;\n\npublic class WebHelpers\n{\n //\n // Disable button with no secondary JavaScript function call.\n //\n public static void DisableButtonOnClick( Button ButtonControl )\n {\n DisableButtonOnClick( ButtonControl, string.Empty ); \n }\n\n //\n // Disable button with a JavaScript function call.\n //\n public static void DisableButtonOnClick( Button ButtonControl, string ClientFunction )\n { \n StringBuilder sb = new StringBuilder( 128 );\n\n // If the page has ASP.NET validators on it, this code ensures the\n // page validates before continuing.\n sb.Append( \"if ( typeof( Page_ClientValidate ) == 'function' ) { \" );\n sb.Append( \"if ( ! Page_ClientValidate() ) { return false; } } \" );\n\n // Disable this button.\n sb.Append( \"this.disabled = true;\" ); \n\n // If a secondary JavaScript function has been provided, and if it can be found,\n // call it. Note the name of the JavaScript function to call should be passed without\n // parens.\n if ( ! String.IsNullOrEmpty( ClientFunction ) ) \n {\n sb.AppendFormat( \"if ( typeof( {0} ) == 'function' ) {{ {0}() }};\", ClientFunction ); \n }\n\n // GetPostBackEventReference() obtains a reference to a client-side script function \n // that causes the server to post back to the page (ie this causes the server-side part \n // of the \"click\" to be performed).\n sb.Append( ButtonControl.Page.ClientScript.GetPostBackEventReference( ButtonControl ) + \";\" );\n\n // Add the JavaScript created a code to be executed when the button is clicked.\n ButtonControl.Attributes.Add( \"onclick\", sb.ToString() );\n }\n}\n"
},
{
"answer_id": 107394,
"author": "nickf",
"author_id": 9021,
"author_profile": "https://Stackoverflow.com/users/9021",
"pm_score": 2,
"selected": false,
"text": "function validate(form) {\n // perform validation here\n if (isValid) {\n form.mySubmitButton.disabled = true;\n return true;\n } else {\n return false;\n }\n}\n\n<form onsubmit=\"return validate(this);\">...</form>\n"
},
{
"answer_id": 108330,
"author": "Adhip Gupta",
"author_id": 384,
"author_profile": "https://Stackoverflow.com/users/384",
"pm_score": 0,
"selected": false,
"text": "function submit(button) {\n Page_ClientValidate(); \n if(Page_IsValid)\n {\n button.disabled = true;\n }\n}\n\n <asp:Button runat=\"server\" ID=\"btnSubmit\" OnClick=\"btnSubmit_OnClick\" OnClientClick=\"submit(this)\" Text=\"Submit Me\" />\n"
},
{
"answer_id": 108701,
"author": "Kyle B.",
"author_id": 6158,
"author_profile": "https://Stackoverflow.com/users/6158",
"pm_score": 1,
"selected": false,
"text": "\nbtnSubmit.Attributes(\"onClick\") = document.getElementById('btnName').style.display = 'none';"
},
{
"answer_id": 612630,
"author": "Adam Nofsinger",
"author_id": 18524,
"author_profile": "https://Stackoverflow.com/users/18524",
"pm_score": 4,
"selected": false,
"text": "<asp:Button ID=\"btnSubmit\" runat=\"server\" Text=\"Submit\" OnClick=\"btnSubmit_Click\" OnClientClick=\"doSubmit(this)\" />\n <script type=\"text/javascript\"><!--\nfunction doSubmit(btnSubmit) {\n if (typeof(Page_ClientValidate) == 'function' && Page_ClientValidate() == false) { \n return false;\n } \n btnSubmit.disabled = 'disabled';\n btnSubmit.value = 'Processing. This may take several minutes...';\n <%= ClientScript.GetPostBackEventReference(btnSubmit, string.Empty) %>; \n}\n//-->\n</script>\n"
},
{
"answer_id": 937262,
"author": "Steve J",
"author_id": 50568,
"author_profile": "https://Stackoverflow.com/users/50568",
"pm_score": 0,
"selected": false,
"text": "<asp:Button ID=\"submit\" runat=\"server\" Text=\"Save\"\n OnClick=\"yourClickEvent\" DisableOnSubmit=\"true\" />\n onclick=\"this.disabled=true; setTimeout('enableBack()', 3000);\n WebForm_DoPostBackWithOptions(new\n WebForm_PostBackOptions('yourControlsName', '', true, '', '', false, true))\n function enableBack()\n{\n document.getElementById('yourControlsName').disabled=false;\n}\n"
},
{
"answer_id": 955148,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "UseSubmitBehavior=\"false\" public static void DisableButtonOnClick(Button button, string clientFunction)\n{\n // If the page has ASP.NET validators on it, this code ensures the\n // page validates before continuing.\n string script = \"if (typeof(Page_ClientValidate) == 'function') { \"\n + \"if (!Page_ClientValidate()) { return false; } } \";\n\n // disable the button\n script += \"this.disabled = true; \";\n\n // If a secondary JavaScript function has been provided, and if it can be found, call it.\n // Note the name of the JavaScript function to call should be passed without parens.\n if (!string.IsNullOrEmpty(clientFunction))\n script += string.Format(\"if (typeof({0}) == 'function') {{ {0}() }} \", clientFunction);\n\n // only need to post back if button is using submit behaviour\n if (button.UseSubmitBehavior)\n script += button.Page.GetPostBackEventReference(button) + \"; \";\n\n button.Attributes.Add(\"onclick\", script);\n}\n"
},
{
"answer_id": 1073332,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": " HtmlGenericControl includeMyJava = new HtmlGenericControl(\"script\");\n includeMyJava.Attributes.Add(\"type\", \"text/javascript\");\n includeMyJava.InnerHtml = \"\\nfunction dsbButton(button) {\";\n includeMyJava.InnerHtml += \"\\nPage_ClientValidate();\";\n includeMyJava.InnerHtml += \"\\nif(Page_IsValid)\";\n includeMyJava.InnerHtml += \"\\n{\";\n includeMyJava.InnerHtml += \"\\nbutton.disabled = true;\";\n includeMyJava.InnerHtml += \"}\";\n includeMyJava.InnerHtml += \"\\n}\";\n this.Page.Header.Controls.Add(includeMyJava);\n <asp:Button ID=\"send\" runat=\"server\" UseSubmitBehavior=\"false\" OnClientClick=\"dsbButton(this);\" Text=\"Send\" OnClick=\"send_Click\" />\n"
},
{
"answer_id": 9008614,
"author": "joelmdev",
"author_id": 663246,
"author_profile": "https://Stackoverflow.com/users/663246",
"pm_score": 0,
"selected": false,
"text": "OnClientClick=\"this.disabled=true;\" <script type=\"text/javascript\">\nvar buttonToDisable;\nfunction disableButton(sender)\n{\n buttonToDisable=sender;\n setTimeout('if(Page_IsValid==true)buttonToDisable.disabled=true;', 10);\n}\n</script>\n <asp:Button runat=\"server\" ID=\"btnSubmit\" Text=\"Submit\" OnClientClick=\"disableButton(this);\" />\n"
},
{
"answer_id": 23803541,
"author": "Techek",
"author_id": 231144,
"author_profile": "https://Stackoverflow.com/users/231144",
"pm_score": 0,
"selected": false,
"text": "public static void DisableButtonOnClick(Button ButtonControl, string ClientFunction)\n{\n StringBuilder sb = new StringBuilder(128);\n\n if (!String.IsNullOrEmpty(ClientFunction))\n {\n sb.AppendFormat(\"if (typeof({0}) == 'function') {{ if ({0}()) {{ {1}; this.disabled=true; return true; }} else {{ return false; }} }};\", ClientFunction, ButtonControl.Page.ClientScript.GetPostBackEventReference(ButtonControl, null));\n }\n else\n {\n sb.Append(\"return true;\");\n }\n\n ButtonControl.Attributes.Add(\"onclick\", sb.ToString());\n}\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/106509",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6600/"
] |
106,534
|
<p>The default rails XML builder escapes all HTML, so something like:</p>
<pre class="lang-ruby prettyprint-override"><code>atom_feed do |feed|
@stories.each do |story|
feed.entry story do |entry|
entry.title story.title
entry.content "<b>foo</b>"
end
end
end
</code></pre>
<p>will produce the text:</p>
<pre class="lang-html prettyprint-override"><code><b>foo</b>
</code></pre>
<p>instead of: <strong>foo</strong></p>
<p>Is there any way to instruct the XML builder to not escape the XML?</p>
|
[
{
"answer_id": 106616,
"author": "Shalmanese",
"author_id": 14559,
"author_profile": "https://Stackoverflow.com/users/14559",
"pm_score": 4,
"selected": true,
"text": "entry.content \"<b>foo</b>\", :type => \"html\"\n"
},
{
"answer_id": 5706949,
"author": "Rodrigo",
"author_id": 713910,
"author_profile": "https://Stackoverflow.com/users/713910",
"pm_score": 3,
"selected": false,
"text": "entry.content \"type\" => \"html\" do\n entry.cdata!(post.content)\nend\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/106534",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14559/"
] |
106,544
|
<p>I get the following error when trying to run the latest Cygwin version of rsync in Windows XP SP2. The error occurs for attempts at both local syncs (that is: source and destination on the local harddisk only) and remote syncs (using "-e ssh" from the openssh package). Any advice on how to fix/workaround it?</p>
<pre>
bash-3.2$ rsync -a dir1 dir2
rsync: Failed to dup/close: Socket operation on non-socket (108)
rsync error: error in IPC code (code 14) at /home/lapo/packaging/tmp/rsync-2.6.9/pipe.c(143) [receiver=2.6.9]
rsync: read error: Connection reset by peer (104)
rsync error: error in IPC code (code 14) at /home/lapo/packaging/tmp/rsync-2.6.9/io.c(604) [sender=2.6.9]
</pre>
|
[
{
"answer_id": 2507539,
"author": "DH4",
"author_id": 267429,
"author_profile": "https://Stackoverflow.com/users/267429",
"pm_score": 2,
"selected": false,
"text": "$ gdb --args /usr/bin/rsync -a somedir/ anotherdir\nGNU gdb 6.8.0.20080328-cvs (cygwin-special)\n.....\n(no debugging symbols found)\n(gdb) run \n Starting program: /usr/bin/rsync -a somedir/ anotherdir\n.....\n(no debugging symbols found)\nwarning: NOD32 protected [MSAFD Tcpip [TCP/IP]]\nwarning: NOD32 protected [MSAFD Tcpip [UDP/IP]]\nwarning: NOD32 protected [MSAFD Tcpip [RAW/IP]]\nwarning: NOD32 protected [RSVP UDP Service Provider]\nwarning: NOD32 protected [RSVP TCP Service Provider]\n(no debugging symbols found)\n(no debugging symbols found)\n---Type <return> to continue, or q <return> to quit---\n(no debugging symbols found)\n[New thread 1508.0x720]\n[New thread 1508.0xeb0]\n[New thread 1508.0x54c]\nrsync: Failed to dup/close: Socket operation on non-socket\n(108)\nrsync error: error in IPC code (code 14) at\n/home/lapo/packaging/rsync-3.0.4-1/src/rsync-3.0.4/pipe.c(147)\n[receiver=3.0.4] \n"
},
{
"answer_id": 23960010,
"author": "tvl",
"author_id": 1692965,
"author_profile": "https://Stackoverflow.com/users/1692965",
"pm_score": 0,
"selected": false,
"text": "cygrunsrv --install \"rsyncd\" --path /usr/bin/rsync --args \"--daemon --no-detach\" --desc \"Starts a rsync daemon for accepting incoming rsync connections\" --disp \"Rsync Daemon\" --type auto\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/106544",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19417/"
] |
106,554
|
<p>I use this code in my Windows Service to be notified of USB disk drives being inserted and removed:</p>
<pre><code>WqlEventQuery query = new WqlEventQuery("__InstanceOperationEvent",
"TargetInstance ISA 'Win32_LogicalDisk' AND TargetInstance.DriveType=2");
query.WithinInterval = TimeSpan.FromSeconds(1);
_deviceWatcher = new ManagementEventWatcher(query);
_deviceWatcher.EventArrived += new EventArrivedEventHandler(OnDeviceEventArrived);
_deviceWatcher.Start();
</code></pre>
<p>It works on XP and Vista, but on XP I can hear the very noticeable sound of the hard drive being accessed every second. Is there another WMI query that will give me the events without the sound effect?</p>
|
[
{
"answer_id": 52615754,
"author": "Mujtaba",
"author_id": 6880486,
"author_profile": "https://Stackoverflow.com/users/6880486",
"pm_score": 1,
"selected": false,
"text": "using System;\nusing System.Management;\n\nnamespace MonitorDrives\n{\nclass Program\n{\n public enum EventType\n {\n Inserted = 2,\n Removed = 3\n }\n\n static void Main(string[] args)\n {\n ManagementEventWatcher watcher = new ManagementEventWatcher();\n WqlEventQuery query = new WqlEventQuery(\"SELECT * FROM Win32_VolumeChangeEvent WHERE EventType = 2 or EventType = 3\");\n\n watcher.EventArrived += (s, e) =>\n {\n string driveName = e.NewEvent.Properties[\"DriveName\"].Value.ToString();\n EventType eventType = (EventType)(Convert.ToInt16(e.NewEvent.Properties[\"EventType\"].Value));\n\n string eventName = Enum.GetName(typeof(EventType), eventType);\n\n Console.WriteLine(\"{0}: {1} {2}\", DateTime.Now, driveName, eventName);\n };\n\n watcher.Query = query;\n watcher.Start();\n\n Console.ReadKey();\n }\n}\n}\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/106554",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14842/"
] |
106,555
|
<p>I have a Perl script where I maintain a very simple cache using a hash table. I would like to clear the hash once it occupies more than n bytes, to avoid Perl (32-bit) running out of memory and crashing. </p>
<p>I can do a check on the number of keys-value pairs:</p>
<pre><code>if (scalar keys %cache > $maxSize)
{
%cache = ();
}
</code></pre>
<p>But is it possible to check the actual memory occupied by the hash?</p>
|
[
{
"answer_id": 106565,
"author": "mbac32768",
"author_id": 18446,
"author_profile": "https://Stackoverflow.com/users/18446",
"pm_score": 4,
"selected": false,
"text": "use Devel::Size qw(size total_size);\n\nmy $size = size(\"A string\");\nmy @foo = (1, 2, 3, 4, 5);\nmy $other_size = size(\\@foo);\nmy $foo = {a => [1, 2, 3],\n b => {a => [1, 3, 4]}\n };\nmy $total_size = total_size($foo);\n"
},
{
"answer_id": 106707,
"author": "Brad Gilbert",
"author_id": 1337,
"author_profile": "https://Stackoverflow.com/users/1337",
"pm_score": 1,
"selected": false,
"text": "use Cache::Memory;\n\nmy $cache = Cache::Memory->new(\n namespace => 'MyNamespace',\n default_expires => '600 sec'\n);\n\nmy $size = $cache->size()\nmy $limit = $cache->size_limit();\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/106555",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5734/"
] |
106,563
|
<p>I'd like to log the output of a command to <code>stdout</code> as well as to a log file. I've got Cygwin installed and I'm trying to use the <code>tee</code> command to accomplish this.</p>
<pre><code>devenv mysolution.sln /build myproject "Release|Win32" | tee build.log
</code></pre>
<p>Trouble is that <code>tee</code> seems to insist on waiting for the end of file before outputting anything to either <code>stdout</code> or the log file. This takes away the point of it all, which is to have a log file for future reference, but also some <code>stdout</code> logging so I can easily see the build progress.</p>
<p><code>tee</code>'s options appear to be limited to <code>--append</code>, <code>--ignore-interrupts</code>, <code>--help</code>, and <code>--version</code>. So is there another method to get to what I'm trying to do?</p>
|
[
{
"answer_id": 106579,
"author": "C. K. Young",
"author_id": 13,
"author_profile": "https://Stackoverflow.com/users/13",
"pm_score": 2,
"selected": false,
"text": "$| tee #!/usr/bin/perl -w\nuse strict;\nuse IO::File;\n$| = 1;\nmy @fhs = map IO::File->new(\">$_\"), @ARGV;\nwhile (my $line = <STDIN>) {\n print $line;\n $_->print($line) for @fhs;\n}\n$_->close for @fhs;\n perlmilktee"
},
{
"answer_id": 108370,
"author": "jon",
"author_id": 12215,
"author_profile": "https://Stackoverflow.com/users/12215",
"pm_score": 3,
"selected": true,
"text": "$ cat test\n#!/bin/sh\necho \"hello\"\nsleep 5\necho \"goodbye\"\n\n$ ./test | tee test.log\nhello\n<pause>\ngoodbye\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/106563",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4790/"
] |
106,586
|
<p><strong>There is a lot of relativity involved in working with exceptions.</strong> Beyond low level APIs where exceptions cover errors raised from hardware and the OS there is a shady area where the programmer decides what constitutes an exception and what is a normal condition.</p>
<p>How do you decide when to use exceptions? <strong>Do you have a consistent policy regarding exceptions?</strong></p>
|
[
{
"answer_id": 107098,
"author": "Harold Ekstrom",
"author_id": 8429,
"author_profile": "https://Stackoverflow.com/users/8429",
"pm_score": 0,
"selected": false,
"text": "HRESULT Foo()\n{\n HRESULT hr = S_OK;\n try {\n // Avoid a whole lot of nested ifs and return code\n // checking - internal stuff just throws.\n DoStuff();\n DoMoreStuff(); // etc.\n } catch ( CAtlException& e ) {\n hr = e;\n }\n return hr;\n}\n\nvoid DoSomething()\n{\n // If something goes wrong, AtlThrow( E_FAILED or E_WHATEVER ); \n}\n"
},
{
"answer_id": 125381,
"author": "computinglife",
"author_id": 17224,
"author_profile": "https://Stackoverflow.com/users/17224",
"pm_score": 3,
"selected": false,
"text": "catch(...) main \n{\n try {\n all code....\n }\n catch(...) {} \n}\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/106586",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13615/"
] |
106,591
|
<p>At work today, I came across the <code>volatile</code> keyword in Java. Not being very familiar with it, I found <a href="http://web.archive.org/web/20210221170926/https://www.ibm.com/developerworks/java/library/j-jtp06197/" rel="noreferrer">this explanation</a>.</p>
<p>Given the detail in which that article explains the keyword in question, do you ever use it or could you ever see a case in which you could use this keyword in the correct manner?</p>
|
[
{
"answer_id": 106641,
"author": "Ande Turner",
"author_id": 4857,
"author_profile": "https://Stackoverflow.com/users/4857",
"pm_score": 8,
"selected": false,
"text": "volatile java.util.concurrent"
},
{
"answer_id": 106787,
"author": "Greg Mattes",
"author_id": 13940,
"author_profile": "https://Stackoverflow.com/users/13940",
"pm_score": 11,
"selected": true,
"text": "volatile volatile volatile volatile volatile true false false volatile volatile volatile"
},
{
"answer_id": 107040,
"author": "Dave L.",
"author_id": 3093,
"author_profile": "https://Stackoverflow.com/users/3093",
"pm_score": 5,
"selected": false,
"text": "volatile volatile boolean volatile synchronized"
},
{
"answer_id": 130320,
"author": "Pyrolistical",
"author_id": 21838,
"author_profile": "https://Stackoverflow.com/users/21838",
"pm_score": 6,
"selected": false,
"text": "volatile public class Foo extends Thread {\n\n private volatile boolean close = false;\n\n public void run() {\n while(!close) {\n // do work\n }\n }\n public void close() {\n close = true;\n // interrupt here if needed\n }\n}\n close close()"
},
{
"answer_id": 15179454,
"author": "fatih tekin",
"author_id": 2034733,
"author_profile": "https://Stackoverflow.com/users/2034733",
"pm_score": 3,
"selected": false,
"text": "volatile package io.netty.example.telnet;\n\nimport java.util.ArrayList;\nimport java.util.List;\n\npublic class Main {\n\n public static volatile int a = 0;\n public static void main(String args[]) throws InterruptedException{\n\n List<Thread> list = new ArrayList<Thread>();\n for(int i = 0 ; i<11 ;i++){\n list.add(new Pojo());\n }\n\n for (Thread thread : list) {\n thread.start();\n }\n\n Thread.sleep(20000);\n System.out.println(a);\n }\n}\nclass Pojo extends Thread{\n int a = 10001;\n public void run() {\n while(a-->0){\n try {\n Thread.sleep(1);\n } catch (InterruptedException e) {\n e.printStackTrace();\n }\n Main.a++;\n System.out.println(\"a = \"+Main.a);\n }\n }\n}\n package io.netty.example.telnet;\n\n import java.util.ArrayList;\n import java.util.List;\n import java.util.concurrent.atomic.AtomicInteger;\n\n public class Main {\n\n public static volatile AtomicInteger a = new AtomicInteger(0);\n public static void main(String args[]) throws InterruptedException{\n\n List<Thread> list = new ArrayList<Thread>();\n for(int i = 0 ; i<11 ;i++){\n list.add(new Pojo());\n }\n\n for (Thread thread : list) {\n thread.start();\n }\n\n Thread.sleep(20000);\n System.out.println(a.get());\n\n }\n }\n class Pojo extends Thread{\n int a = 10001;\n public void run() {\n while(a-->0){\n try {\n Thread.sleep(1);\n } catch (InterruptedException e) {\n e.printStackTrace();\n }\n Main.a.incrementAndGet();\n System.out.println(\"a = \"+Main.a);\n }\n }\n }\n"
},
{
"answer_id": 34364511,
"author": "Premraj",
"author_id": 1697099,
"author_profile": "https://Stackoverflow.com/users/1697099",
"pm_score": 7,
"selected": false,
"text": "volatile synchronized volatile synchronized synchronized synchronized volatile volatile volatile volatile public class Singleton {\n private static volatile Singleton _instance; // volatile variable\n public static Singleton getInstance() {\n if (_instance == null) {\n synchronized (Singleton.class) {\n if (_instance == null)\n _instance = new Singleton();\n }\n }\n return _instance;\n }\n}\n _instance volatile Singleton _instance _instance volatile public class Singleton { \n private static Singleton _instance; //without volatile variable\n public static Singleton getInstance() { \n if (_instance == null) { \n synchronized(Singleton.class) { \n if (_instance == null) \n _instance = new Singleton(); \n } \n }\n return _instance; \n }\n}\n volatile volatile Iterator Iterator Iterator ConcurrentModificationException"
},
{
"answer_id": 37116960,
"author": "Ravindra babu",
"author_id": 4999394,
"author_profile": "https://Stackoverflow.com/users/4999394",
"pm_score": 1,
"selected": false,
"text": "volatile volatile Peter Parker volatile volatile java.text.SimpleDateFormat(\"HH-mm-ss\") SimpleDateFormat"
},
{
"answer_id": 42550536,
"author": "Mohan",
"author_id": 1380968,
"author_profile": "https://Stackoverflow.com/users/1380968",
"pm_score": 2,
"selected": false,
"text": "while (busy) {\n /* do something else */\n}\n busy = 0;\n"
},
{
"answer_id": 49098807,
"author": "Supun Wijerathne",
"author_id": 5715934,
"author_profile": "https://Stackoverflow.com/users/5715934",
"pm_score": 5,
"selected": false,
"text": "volatile volatile volatile volatile"
},
{
"answer_id": 50617902,
"author": "sankar banerjee",
"author_id": 9874027,
"author_profile": "https://Stackoverflow.com/users/9874027",
"pm_score": 2,
"selected": false,
"text": "thread 0 prints 0\nthread 1 prints 1\nthread 2 prints 2\nthread 3 prints 3\nthread 0 prints 0\nthread 1 prints 1\nthread 2 prints 2\nthread 3 prints 3\nthread 0 prints 0\nthread 1 prints 1\nthread 2 prints 2\nthread 3 prints 3\n public class Solution {\n static volatile int counter = 0;\n static int print = 0;\n public static void main(String[] args) {\n // TODO Auto-generated method stub\n Thread[] ths = new Thread[4];\n for (int i = 0; i < ths.length; i++) {\n ths[i] = new Thread(new MyRunnable(i, ths.length));\n ths[i].start();\n }\n }\n static class MyRunnable implements Runnable {\n final int thID;\n final int total;\n public MyRunnable(int id, int total) {\n thID = id;\n this.total = total;\n }\n @Override\n public void run() {\n // TODO Auto-generated method stub\n while (true) {\n if (thID == counter) {\n System.out.println(\"thread \" + thID + \" prints \" + print);\n print++;\n if (print == total)\n print = 0;\n counter++;\n if (counter == total)\n counter = 0;\n } else {\n try {\n Thread.sleep(30);\n } catch (InterruptedException e) {\n // log it\n }\n }\n }\n }\n }\n}\n"
},
{
"answer_id": 54683948,
"author": "manikanta",
"author_id": 340290,
"author_profile": "https://Stackoverflow.com/users/340290",
"pm_score": -1,
"selected": false,
"text": "volatile volatile // Code to prove importance of 'volatile' when state of one thread is being mutated from another thread.\n// Try running this class with and without 'volatile' for 'state' property of Task class.\npublic class VolatileTest {\n public static void main(String[] a) throws Exception {\n Task task = new Task();\n new Thread(task).start();\n\n Thread.sleep(500);\n long stoppedOn = System.nanoTime();\n\n task.stop(); // -----> do this to stop the thread\n\n System.out.println(\"Stopping on: \" + stoppedOn);\n }\n}\n\nclass Task implements Runnable {\n // Try running with and without 'volatile' here\n private volatile boolean state = true;\n private int i = 0;\n\n public void stop() {\n state = false;\n } \n\n @Override\n public void run() {\n while(state) {\n i++;\n }\n System.out.println(i + \"> Stopped on: \" + System.nanoTime());\n }\n}\n\n volatile Stopping on: 1895303906650500\n volatile Stopping on: 1895285647980000\n324565439> Stopped on: 1895285648087300\n"
},
{
"answer_id": 59498520,
"author": "yoAlex5",
"author_id": 4770877,
"author_profile": "https://Stackoverflow.com/users/4770877",
"pm_score": 4,
"selected": false,
"text": "volatile synchronized volatile volatile Java 5 volatile happens-before Read is after write\n volatile race condition synchronized volatile"
},
{
"answer_id": 63754630,
"author": "Abhishek Luthra",
"author_id": 9494420,
"author_profile": "https://Stackoverflow.com/users/9494420",
"pm_score": 3,
"selected": false,
"text": "public class VisibilityDemonstration {\n\nprivate static int sCount = 0;\n\npublic static void main(String[] args) {\n new Consumer().start();\n try {\n Thread.sleep(100);\n } catch (InterruptedException e) {\n return;\n }\n new Producer().start();\n}\n\nstatic class Consumer extends Thread {\n @Override\n public void run() {\n int localValue = -1;\n while (true) {\n if (localValue != sCount) {\n System.out.println(\"Consumer: detected count change \" + sCount);\n localValue = sCount;\n }\n if (sCount >= 5) {\n break;\n }\n }\n System.out.println(\"Consumer: terminating\");\n }\n}\n\nstatic class Producer extends Thread {\n @Override\n public void run() {\n while (sCount < 5) {\n int localValue = sCount;\n localValue++;\n System.out.println(\"Producer: incrementing count to \" + localValue);\n sCount = localValue;\n try {\n Thread.sleep(1000);\n } catch (InterruptedException e) {\n return;\n }\n }\n System.out.println(\"Producer: terminating\");\n }\n}\n}\n Consumer: detected count change 0\nProducer: incrementing count to 1\nProducer: incrementing count to 2\nProducer: incrementing count to 3\nProducer: incrementing count to 4\nProducer: incrementing count to 5\nProducer: terminating\n private volatile static int sCount = 0;\n Consumer: detected count change 0\nProducer: incrementing count to 1\nConsumer: detected count change 1\nProducer: incrementing count to 2\nConsumer: detected count change 2\nProducer: incrementing count to 3\nConsumer: detected count change 3\nProducer: incrementing count to 4\nConsumer: detected count change 4\nProducer: incrementing count to 5\nConsumer: detected count change 5\nConsumer: terminating\nProducer: terminating\n"
},
{
"answer_id": 65126556,
"author": "CJay",
"author_id": 9944300,
"author_profile": "https://Stackoverflow.com/users/9944300",
"pm_score": 3,
"selected": false,
"text": "volatile Visibility Problem volatile public class SharedObject {\n public volatile int sharedVariable = 0;\n}\n public class SharedObject {\n public int counter = 0;\n}\n"
},
{
"answer_id": 73677124,
"author": "Yilmaz",
"author_id": 10262805,
"author_profile": "https://Stackoverflow.com/users/10262805",
"pm_score": 0,
"selected": false,
"text": "volatile"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/106591",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16759/"
] |
106,599
|
<p>I would like to serialize and deserialize objects without having to worry about the entire class graph.</p>
<p>Flexibility is key. I would like to be able to serialize any object passed to me without complete attributes needed throughout the entire object graph.</p>
<blockquote>
<p>That means that Binary Serialization
is not an option as it only works with
the other .NET Platforms. I would
also like something readable by a
person, and thus decipherable by a
management program and other
interpreters.</p>
</blockquote>
<p>I've found problems using the DataContract, JSON, and XML Serializers.</p>
<ul>
<li>Most of these errors seem to center around Serialization of Lists/Dictionaries (i.e. <a href="http://weblogs.asp.net/pwelter34/archive/2006/05/03/444961.aspx" rel="noreferrer">XML Serializable Generic Dictionary</a>).</li>
<li>"Add any types not known statically
to the list of known types - for
example, by using the
KnownTypeAttribute attribute or by
adding them to the list of known
types passed to
DataContractSerializer."</li>
</ul>
<p>Please base your answers on actual experiences and not theory or reading of an article.</p>
|
[
{
"answer_id": 106697,
"author": "Ian Suttle",
"author_id": 19421,
"author_profile": "https://Stackoverflow.com/users/19421",
"pm_score": 2,
"selected": false,
"text": "[XmlArray(\"Foo\")]\n[XmlArrayItem(\"Bar\")]\npublic List<BarClass> FooBars\n{ get; set; }\n <Foo>\n <Bar />\n <Bar />\n</Foo>\n"
},
{
"answer_id": 106792,
"author": "oglester",
"author_id": 2017,
"author_profile": "https://Stackoverflow.com/users/2017",
"pm_score": 1,
"selected": false,
"text": "using System.IO;\nusing System.Runtime.Serialization;\nusing System.Runtime.Serialization.Formatters.Binary;\n\npublic class Serializer\n{\n public Serializer()\n {\n }\n\n public void SerializeObject(string filename,\n ObjectToSerialize objectToSerialize)\n {\n Stream stream = File.Open(filename, FileMode.Create);\n BinaryFormatter bFormatter = new BinaryFormatter();\n bFormatter.Serialize(stream, objectToSerialize);\n stream.Close();\n }\n\n public ObjectToSerialize DeSerializeObject(string filename)\n {\n ObjectToSerialize objectToSerialize;\n Stream stream = File.Open(filename, FileMode.Open);\n BinaryFormatter bFormatter = new BinaryFormatter();\n objectToSerialize =\n (ObjectToSerialize)bFormatter.Deserialize(stream);\n stream.Close();\n return objectToSerialize;\n }\n}\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/106599",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2744/"
] |
106,623
|
<p>I have a Java program that loads thirdparty class files (classes I did not write) and executes them. These classes often use <code>java.util.Random</code>, which by default generates random starting seed values every time it gets instantiated. For reasons of reproducability, I want to give these classes the same starting seed every time, changing it only at my discretion.</p>
<p>Here are some of the obvious solutions, and why they don't work:</p>
<ol>
<li><p>Use a different Random class in the thirdparty classfiles. The problem here is I only load the class files, and cannot modify the source.</p></li>
<li><p>Use a custom classloader to load our own Random class instead of the JVM's version. This approach will not work because Java does not allow classloaders to override classes in the <code>java</code> package.</p></li>
<li><p>Swap out the rt.jar's <code>java.util.Random</code> implementation for our own, or putting files into trusted locations for the JVM. These approaches require the user of the application messing with the JVM install on their machine, and are no good.</p></li>
<li><p>Adding a custom <code>java.util.Random</code> class to the bootclasspath. While this would technically work, for this particular application, it is impractical because this application is intended for end users to run from an IDE. I want to make running the app convenient for users, which means forcing them to set their bootclasspath is a pain. I can't hide this in a script, because it's intended to be run from an IDE like Eclipse (for easy debugging.)</p></li>
</ol>
<p>So how can I do this?</p>
|
[
{
"answer_id": 106693,
"author": "OscarRyz",
"author_id": 20654,
"author_profile": "https://Stackoverflow.com/users/20654",
"pm_score": 2,
"selected": false,
"text": "java -X\n"
},
{
"answer_id": 2972293,
"author": "mahaveer",
"author_id": 358208,
"author_profile": "https://Stackoverflow.com/users/358208",
"pm_score": 0,
"selected": false,
"text": "ThirdPartyClass.java Random.java ThirdPartyClass.class jar -cvf tpc.jar ThirdPartyClass.class\n Random.class jar -cvf rt123.jar Random.class\n java -Xbootclasspath/p:tcp.jar:rt123.jar -cp . -verbose ThirdPartyClass\n seed value for ThirdPartyClass-> 1 import java.util.Random;\n\npublic class ThirdPartyClass {\n ThirdPartyClass(long seed ) {\n System.out.println(\"seed value for ThirdPartyClass-> \"+seed);\n } \n\n public static void main(String [] args) {\n ThirdPartyClass tpc=new ThirdPartyClass(new Random().nextLong());\n }\n}\n package java.util;\n\nimport java.io.Serializable;\n\npublic class Random extends Object implements Serializable\n{\n public Random() {\n }\n\n public Random(long seed) {\n }\n\n public long nextLong() {\n return 1;\n }\n}\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/106623",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9871/"
] |
106,627
|
<blockquote>
<p><strong>Possible Duplicates:</strong><br>
<a href="https://stackoverflow.com/questions/370427/learn-obj-c-memory-management">Learn Obj-C Memory Management</a><br>
<a href="https://stackoverflow.com/questions/710288/where-are-the-best-explanations-of-memory-management-for-iphone">Where are the best explanations of memory management for iPhone?</a> </p>
</blockquote>
<p>I come from a C/C++ background and the dynamic nature of Objective-C is somewhat foreign to me, is there a good resource anyone can point me to for some basic memory management techniques in Objective-C? ex. retaining, releasing, autoreleasing</p>
<p>For instance, is it completely illegal to use a pointer to an Objective-C object and treat it as an array? Are you forced to use NSArray and NSMutableArray for data structures?</p>
<p>I know these are pretty newbie questions, thanks for any help you can offer me.</p>
|
[
{
"answer_id": 126149,
"author": "benzado",
"author_id": 10947,
"author_profile": "https://Stackoverflow.com/users/10947",
"pm_score": 2,
"selected": false,
"text": "alloc copy release retain release autorelease NSObject *threeObjects[3];\n\nthreeObjects[0] = @\"a string\";\nthreeObjects[1] = [NSNumber numberWithInt:2];\nthreeObjects[2] = someOtherObject;\n [threeObjects[0] length]"
},
{
"answer_id": 146720,
"author": "mmalc",
"author_id": 23233,
"author_profile": "https://Stackoverflow.com/users/23233",
"pm_score": 4,
"selected": false,
"text": "stringWithFormat: alloc init"
},
{
"answer_id": 159093,
"author": "Ashley Clark",
"author_id": 4556,
"author_profile": "https://Stackoverflow.com/users/4556",
"pm_score": 1,
"selected": false,
"text": "NSAllocateCollectable(sizeof(id)*size, NSScannedOption) __strong"
},
{
"answer_id": 278396,
"author": "Peter Hosey",
"author_id": 30461,
"author_profile": "https://Stackoverflow.com/users/30461",
"pm_score": 1,
"selected": false,
"text": "NS{,Mutable}Array NS{,Mutable}Set NS{,Mutable}Dictionary"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/106627",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
106,630
|
<p>I start by creating a string variable with some <strong>non-ascii</strong> <em>utf-8</em> encoded data on it:</p>
<pre><code>>>> text = 'á'
>>> text
'\xc3\xa1'
>>> text.decode('utf-8')
u'\xe1'
</code></pre>
<p>Using <code>unicode()</code> on it raises errors...</p>
<pre><code>>>> unicode(text)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 0:
ordinal not in range(128)
</code></pre>
<p>...but if I know the encoding I can use it as second parameter:</p>
<pre><code>>>> unicode(text, 'utf-8')
u'\xe1'
>>> unicode(text, 'utf-8') == text.decode('utf-8')
True
</code></pre>
<p>Now if I have a class that returns this text in the <code>__str__()</code> method:</p>
<pre><code>>>> class ReturnsEncoded(object):
... def __str__(self):
... return text
...
>>> r = ReturnsEncoded()
>>> str(r)
'\xc3\xa1'
</code></pre>
<p><code>unicode(r)</code> seems to use <code>str()</code> on it, since it raises the same error as <code>unicode(text)</code> above:</p>
<pre><code>>>> unicode(r)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 0:
ordinal not in range(128)
</code></pre>
<p>Until now everything is as planned!</p>
<p><strong>But as no one would ever expect, <code>unicode(r, 'utf-8')</code> won't even try:</strong></p>
<pre><code>>>> unicode(r, 'utf-8')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: coercing to Unicode: need string or buffer, ReturnsEncoded found
</code></pre>
<p>Why? Why this inconsistent behavior? Is it a bug? is it intended? Very awkward.</p>
|
[
{
"answer_id": 106640,
"author": "John Millikin",
"author_id": 3560,
"author_profile": "https://Stackoverflow.com/users/3560",
"pm_score": 3,
"selected": false,
"text": "unicode unicode __unicode__() unicode(r) __str__() __unicode__() __unicode__() __str__() ascii unicode() basestring text __unicode__()"
},
{
"answer_id": 106709,
"author": "Blair Conrad",
"author_id": 1199,
"author_profile": "https://Stackoverflow.com/users/1199",
"pm_score": 4,
"selected": true,
"text": "unicode(r, 'utf-8') __str__() utf-8 utf-8 unicode() __unicode__() __str__()"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/106630",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17160/"
] |
106,632
|
<p>Strange question, but: Sharepoint 2007 greets you with the Administrator Tasks on the Central Administration after installation.</p>
<p>I just wonder if this list is "safe" to be used for my own Administration Tasks? The reason why i'm asking is because I found that Sharepoint uses a lot of "black magic" and unlogical behaviour and breaks rather easily, so I do not want risk breaking anything if i'm entering my own tasks into the task list.</p>
|
[
{
"answer_id": 106640,
"author": "John Millikin",
"author_id": 3560,
"author_profile": "https://Stackoverflow.com/users/3560",
"pm_score": 3,
"selected": false,
"text": "unicode unicode __unicode__() unicode(r) __str__() __unicode__() __unicode__() __str__() ascii unicode() basestring text __unicode__()"
},
{
"answer_id": 106709,
"author": "Blair Conrad",
"author_id": 1199,
"author_profile": "https://Stackoverflow.com/users/1199",
"pm_score": 4,
"selected": true,
"text": "unicode(r, 'utf-8') __str__() utf-8 utf-8 unicode() __unicode__() __str__()"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/106632",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/91/"
] |
106,668
|
<p>I've used poderosa(a .NET terminal app) to monitor logs on multiple linux/solaris servers. This application is NOT getting currently maintained and I've had several problems with it.</p>
<p>I'm wondering what other users do to simultaneously monitor several logs in real-time(as in tail -f logfile). I would like to be able to tab/cascade several ssh tails.</p>
|
[
{
"answer_id": 106690,
"author": "zigdon",
"author_id": 4913,
"author_profile": "https://Stackoverflow.com/users/4913",
"pm_score": 1,
"selected": false,
"text": "ssh serverX tail -f /path/to/log/file\n"
},
{
"answer_id": 126083,
"author": "dsm",
"author_id": 7780,
"author_profile": "https://Stackoverflow.com/users/7780",
"pm_score": 1,
"selected": false,
"text": "~/.bashrc function create-follower () {\n local _NAME=$1;\n local _USER=$2;\n local _HOST=$3;\n local _PATH=$4;\n\n if ! [ \"${_NAME}\" ]\\\n || ! [ \"${_USER}\" ]\\\n || ! [ \"${_HOST}\" ]\\\n || ! [ \"${_PATH}\" ] ; then\n { echo \"Cannot create log follower.\" ;\n echo;\n echo \"Usage: create-follower NAME USER HOST LOG-FILE\";\n } >&2;\n return 1 ;\n fi ;\n\n eval \"function ${_NAME}(){ ssh ${_USER}@${_HOST} tail -f \\\"${_PATH}\\\" & }\"\n}\n\nfunction activate-followers () {\n if (( $# < 1 )) ; then\n { echo \"You must specify at least one follower to use\" ;\n echo ;\n echo \"Usage:\" ;\n echo \" activate-followers follower1 [follower2 ... followerN]\";\n } >&2;\n return 1 ;\n fi ;\n\n for FOLLOW in \"${@}\" ; do\n ${FOLLOW} ;\n done ;\n\n wait;\n}\n\nfunction stop-followers () {\n if [ \"$(jobs)\" ] ; then\n kill -9 $(jobs | perl -pe 's/\\[([0-9]+)\\].*/%$1/') ;\n fi ;\n}\n [dsm@localhost:~]$ create-follower test1 user1 localhost /tmp/log-1.txt\n[dsm@localhost:~]$ create-follower test2 user2 otherhost /tmp/log-2.txt\n[dsm@localhost:~]$ create-follower test2 user3 remotebox /tmp/log-3.txt\n [dsm@localhost:~]$ activate-followers test1 test2 test3\n CTRL+C [dsm@localhost:~]$ stop-followers\n"
},
{
"answer_id": 71867383,
"author": "serv-inc",
"author_id": 1587329,
"author_profile": "https://Stackoverflow.com/users/1587329",
"pm_score": 0,
"selected": false,
"text": "fab -P --linewise -H host1,host2,host3 -- tail -f /path/to/logfile\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/106668",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11142/"
] |
106,684
|
<p>What I'm trying to do with MRS is to teach myself some basic AI; what I want to do is to make a rocket entity, with things such as vectored exhaust, and staging. Anyone have an idea on how to make an entity that can fly? Or do I just need to constantly apply a force upwards?</p>
|
[
{
"answer_id": 514016,
"author": "AShelly",
"author_id": 10396,
"author_profile": "https://Stackoverflow.com/users/10396",
"pm_score": 2,
"selected": false,
"text": "Simulation.Physics.PhysicsEntity.ApplyForce() Update()"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/106684",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18658/"
] |
106,685
|
<p>I use <code>PHPMyAdmi</code>n for convenience in updating a remote database.</p>
<p>But it doesn't show warnings, by default, which recently got me into some embarrassing trouble where I was updating a SET field with string not on its list and not noticing the problem. </p>
<p>I'm using <code>2.11.9.1 (Dreamhost's default install)</code>.</p>
<p>On the <code>PHPMyAdmin</code> wiki it lists "Display warnings" as a feature of <a href="http://wiki.cihar.com/pma/phpMyAdmin_2.9.0-rc1" rel="nofollow noreferrer">version 2.9.0</a> and even "Display all warnings" as a feature of 2.10.2 -- but how do I actually turn this on? The documentation isn't great.</p>
|
[
{
"answer_id": 9611839,
"author": "Simon East",
"author_id": 195835,
"author_profile": "https://Stackoverflow.com/users/195835",
"pm_score": 1,
"selected": false,
"text": "INSERTs SHOW WARNINGS INSERT INTO test2 SELECT * FROM test1;\nSHOW WARNINGS;\n Level Code Message\nWarning 1265 Data truncated for column 'a' at row 1\nWarning 1265 Data truncated for column 'a' at row 3\nWarning 1265 Data truncated for column 'b' at row 3\nWarning 1366 Incorrect integer value: 'x' for column 'b' at row...\n SHOW WARNINGS INSERT INTO test2 VALUES ('my text', 'something else');\nSHOW WARNINGS; # you won't see the warnings from here\nINSERT INTO test2 VALUES ('my text', 'something else');\nSHOW WARNINGS;\n INSERT INSERT INTO test2 VALUES \n('my text', 'something else'), \n('my text', 'something else');\nSHOW WARNINGS;\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/106685",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/242241/"
] |
106,711
|
<p>Here's a simplified version of what I'm trying to do :</p>
<ol>
<li>Before any other actions are performed, present the user with a form to retrieve a string.</li>
<li>Input the string, and then redirect to the default controller action (e.g. index). The string only needs to exist, no other validations are necessary.</li>
<li>The string must be available (as an instance variable?) to all the actions in this controller.</li>
</ol>
<p>I'm very new with Rails, but this doesn't seem like it ought to be exceedingly hard, so I'm feeling kind of dumb.</p>
<p>What I've tried :
I have a <code>before_filter</code> redirecting to a private method that looks like</p>
<pre><code>def check_string
if @string
return true
else
get_string
end
end
</code></pre>
<p>the <code>get_string</code> method looks like </p>
<pre><code>def get_string
if params[:string]
respond_to do |format|
format.html {redirect_to(accounts_url)} # authenticate.html.erb
end
end
respond_to do |format|
format.html {render :action =>"get_string"} # get_string.html.erb
end
end
</code></pre>
<p>This fails because i have two render or redirect calls in the same action. I can take out that first <code>respond_to</code>, of course, but what happens is that the controller gets trapped in the <code>get_string</code> method. I can more or less see why that's happening, but I don't know how to fix it and break out. I need to be able to show one form (View), get and then do something with the input string, and then proceed as normal.</p>
<p>The <code>get_string.html.erb</code> file looks like </p>
<pre><code><h1>Enter a string</h1>
<% form_tag('/accounts/get_string') do %>
<%= password_field_tag(:string, params[:string])%>
<%= submit_tag('Ok')%>
<% end %>
</code></pre>
<p>I'll be thankful for any help!</p>
<h2>EDIT</h2>
<p>Thanks for the replies...<br>
@Laurie Young : You are right, I was misunderstanding. For some reason I had it in my head that the instance of any given controller invoked by a user would persist throughout their session, and that some of the Rails magic was in tracking objects associated with each user session. I can see why that doesn't make a whole lot of sense in retrospect, and why my attempt to use an instance variable (which I'd thought would persist) won't work. Thanks to you as well :)</p>
|
[
{
"answer_id": 106757,
"author": "Toby Hede",
"author_id": 14971,
"author_profile": "https://Stackoverflow.com/users/14971",
"pm_score": 3,
"selected": true,
"text": "def get_string\n @string = params[:string] || session[:string] \n respond_to do |format|\n if @string \n format.html {redirect_to(accounts_url)} # authenticate.html.erb\n else \n format.html {render :action =>\"get_string\"} # get_string.html.erb\n end\n end\nend\n"
},
{
"answer_id": 108563,
"author": "Laurie Young",
"author_id": 7473,
"author_profile": "https://Stackoverflow.com/users/7473",
"pm_score": 0,
"selected": false,
"text": "class MyController < ApplicationController::Base\n before_filter :require_string\n\n def require_string\n return true if @string #return early if called multiple times in one request\n if params['string'] or session['string'] #depending on if you set it as a URL or session var\n @string = (params['string'] or session['string'])\n return true\n end\n\n #We now know that string is not set\n redirect_to string_setting_url and return false #the return false prevents any futher processing in this request\n end\nend\n login_required' action in"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/106711",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17046/"
] |
106,712
|
<p>I have a VB.NET Windows Forms project that at one point paints text directly to onto the form at runtime. Before I paint with the font though, I want to make sure that the font and font-size exists on the user's machine. If they don't, I'll try a few other similar fonts, eventually defaulting with Arial or something.</p>
<p>What's the best way to test and validate a font on a user's computer?</p>
|
[
{
"answer_id": 106724,
"author": "Charlie",
"author_id": 18529,
"author_profile": "https://Stackoverflow.com/users/18529",
"pm_score": 4,
"selected": true,
"text": "\n\nInstalledFontCollection installedFontCollection = new InstalledFontCollection();\n\n// Get the array of FontFamily objects.\nFontFamily[] fontFamilies = installedFontCollection.Families;\n\n"
},
{
"answer_id": 106728,
"author": "Jason Stevenson",
"author_id": 13368,
"author_profile": "https://Stackoverflow.com/users/13368",
"pm_score": 2,
"selected": false,
"text": "public partial class Form1 : Form\n{\n public Form1()\n {\n SetFontFinal();\n InitializeComponent();\n }\n\n /// <summary>\n /// This method attempts to set the font in the form to Cambria, which\n /// will only work in some scenarios. If Cambria is not available, it will\n /// fall back to Times New Roman, so the font is good on almost all systems.\n /// </summary>\n private void SetFontFinal()\n {\n string fontName = \"Cambria\";\n Font testFont = new Font(fontName, 16.0f, FontStyle.Regular,\n GraphicsUnit.Pixel);\n\n if (testFont.Name == fontName)\n {\n // The font exists, so use it.\n this.Font = testFont;\n }\n else\n {\n // The font we tested doesn't exist, so fallback to Times.\n this.Font = new Font(\"Times New Roman\", 16.0f,\n FontStyle.Regular, GraphicsUnit.Pixel);\n }\n }\n}\n Public Function FontExists(FontName As String) As Boolean\n\n Dim oFont As New StdFont\n Dim bAns As Boolean\n\n oFont.Name = FontName\n bAns = StrComp(FontName, oFont.Name, vbTextCompare) = 0\n FontExists = bAns\n\nEnd Function\n"
},
{
"answer_id": 253741,
"author": "GvS",
"author_id": 11492,
"author_profile": "https://Stackoverflow.com/users/11492",
"pm_score": 1,
"selected": false,
"text": " private bool IsFontInstalled(string fontName) {\n using (var testFont = new Font(fontName, 8)) {\n return 0 == string.Compare(\n fontName,\n testFont.Name,\n StringComparison.InvariantCultureIgnoreCase);\n }\n }\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/106712",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5473/"
] |
106,766
|
<p>A common task in programs I've been working on lately is modifying a text file in some way. (Hey, I'm on Linux. Everything's a file. And I do large-scale system admin.)</p>
<p>But the file the code modifies may not exist on my desktop box. And I probably don't want to modify it if it IS on my desktop.</p>
<p>I've read about unit testing in Dive Into Python, and it's pretty clear what I want to do when testing an app that converts decimal to Roman Numerals (the example in DintoP). The testing is nicely self-contained. You don't need to verify that the program PRINTS the right thing, you just need to verify that the functions are returning the right output to a given input.</p>
<p>In my case, however, we need to test that the program is modifying its environment correctly. Here's what I've come up with:</p>
<p>1) Create the "original" file in a standard location, perhaps /tmp.</p>
<p>2) Run the function that modifies the file, passing it the path to the file in /tmp.</p>
<p>3) Verify that the file in /tmp was changed correctly; pass/fail unit test accordingly.</p>
<p>This seems kludgy to me. (Gets even kludgier if you want to verify that backup copies of the file are created properly, etc.) Has anyone come up with a better way?</p>
|
[
{
"answer_id": 106780,
"author": "S.Lott",
"author_id": 10661,
"author_profile": "https://Stackoverflow.com/users/10661",
"pm_score": 3,
"selected": false,
"text": "PYTHONPATH"
},
{
"answer_id": 111199,
"author": "Glyph",
"author_id": 13564,
"author_profile": "https://Stackoverflow.com/users/13564",
"pm_score": 5,
"selected": true,
"text": "setUp StringIO open() os.open open os.open"
},
{
"answer_id": 1866162,
"author": "Graham",
"author_id": 130988,
"author_profile": "https://Stackoverflow.com/users/130988",
"pm_score": 2,
"selected": false,
"text": "def fake_open(module):\n \"\"\"Patch module's `open` builtin so that it returns StringIOs instead of\n creating real files, which is useful for testing. Returns a dict that maps\n opened file names to StringIO objects.\"\"\"\n from contextlib import closing\n from StringIO import StringIO\n streams = {}\n def fakeopen(filename,mode):\n stream = StringIO()\n stream.close = lambda: None\n streams[filename] = stream\n return closing(stream)\n module.open = fakeopen\n return streams\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/106766",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19207/"
] |
106,770
|
<p>It has always bothered me that the only way to copy a file in Java involves opening streams, declaring a buffer, reading in one file, looping through it, and writing it out to the other steam. The web is littered with similar, yet still slightly different implementations of this type of solution.</p>
<p>Is there a better way that stays within the bounds of the Java language (meaning does not involve exec-ing OS specific commands)? Perhaps in some reliable open source utility package, that would at least obscure this underlying implementation and provide a one line solution?</p>
|
[
{
"answer_id": 115086,
"author": "Josh",
"author_id": 2204759,
"author_profile": "https://Stackoverflow.com/users/2204759",
"pm_score": 8,
"selected": false,
"text": "public static void copyFile(File sourceFile, File destFile) throws IOException {\n if(!destFile.exists()) {\n destFile.createNewFile();\n }\n\n FileChannel source = null;\n FileChannel destination = null;\n\n try {\n source = new FileInputStream(sourceFile).getChannel();\n destination = new FileOutputStream(destFile).getChannel();\n destination.transferFrom(source, 0, source.size());\n }\n finally {\n if(source != null) {\n source.close();\n }\n if(destination != null) {\n destination.close();\n }\n }\n}\n"
},
{
"answer_id": 3180908,
"author": "Andrew McKinlay",
"author_id": 52687,
"author_profile": "https://Stackoverflow.com/users/52687",
"pm_score": 5,
"selected": false,
"text": "to from to from from to IOException IllegalArgumentException from.equals(to)"
},
{
"answer_id": 6863770,
"author": "Scott",
"author_id": 868089,
"author_profile": "https://Stackoverflow.com/users/868089",
"pm_score": 8,
"selected": false,
"text": "public static void copyFile( File from, File to ) throws IOException {\n\n if ( !to.exists() ) { to.createNewFile(); }\n\n try (\n FileChannel in = new FileInputStream( from ).getChannel();\n FileChannel out = new FileOutputStream( to ).getChannel() ) {\n\n out.transferFrom( in, 0, in.size() );\n }\n}\n public static void copyFile( File from, File to ) throws IOException {\n Files.copy( from.toPath(), to.toPath() );\n}\n"
},
{
"answer_id": 10138489,
"author": "saji",
"author_id": 1331227,
"author_profile": "https://Stackoverflow.com/users/1331227",
"pm_score": 3,
"selected": false,
"text": "org.apache.tools.ant.util.ResourceUtils.copyResource"
},
{
"answer_id": 16600787,
"author": "Glen Best",
"author_id": 1528401,
"author_profile": "https://Stackoverflow.com/users/1528401",
"pm_score": 7,
"selected": false,
"text": "package com.yourcompany.nio;\n\nclass Files {\n\n static int copyRecursive(Path source, Path target, boolean prompt, CopyOptions options...) {\n CopyVisitor copyVisitor = new CopyVisitor(source, target, options).copy();\n EnumSet<FileVisitOption> fileVisitOpts;\n if (Arrays.toList(options).contains(java.nio.file.LinkOption.NOFOLLOW_LINKS) {\n fileVisitOpts = EnumSet.noneOf(FileVisitOption.class) \n } else {\n fileVisitOpts = EnumSet.of(FileVisitOption.FOLLOW_LINKS);\n }\n Files.walkFileTree(source[i], fileVisitOpts, Integer.MAX_VALUE, copyVisitor);\n }\n\n private class CopyVisitor implements FileVisitor<Path> {\n final Path source;\n final Path target;\n final CopyOptions[] options;\n\n CopyVisitor(Path source, Path target, CopyOptions options...) {\n this.source = source; this.target = target; this.options = options;\n };\n\n @Override\n FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {\n // before visiting entries in a directory we copy the directory\n // (okay if directory already exists).\n Path newdir = target.resolve(source.relativize(dir));\n try {\n Files.copy(dir, newdir, options);\n } catch (FileAlreadyExistsException x) {\n // ignore\n } catch (IOException x) {\n System.err.format(\"Unable to create: %s: %s%n\", newdir, x);\n return SKIP_SUBTREE;\n }\n return CONTINUE;\n }\n\n @Override\n public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {\n Path newfile= target.resolve(source.relativize(file));\n try {\n Files.copy(file, newfile, options);\n } catch (IOException x) {\n System.err.format(\"Unable to copy: %s: %s%n\", source, x);\n }\n return CONTINUE;\n }\n\n @Override\n public FileVisitResult postVisitDirectory(Path dir, IOException exc) {\n // fix up modification time of directory when done\n if (exc == null && Arrays.toList(options).contains(COPY_ATTRIBUTES)) {\n Path newdir = target.resolve(source.relativize(dir));\n try {\n FileTime time = Files.getLastModifiedTime(dir);\n Files.setLastModifiedTime(newdir, time);\n } catch (IOException x) {\n System.err.format(\"Unable to copy all attributes to: %s: %s%n\", newdir, x);\n }\n }\n return CONTINUE;\n }\n\n @Override\n public FileVisitResult visitFileFailed(Path file, IOException exc) {\n if (exc instanceof FileSystemLoopException) {\n System.err.println(\"cycle detected: \" + file);\n } else {\n System.err.format(\"Unable to copy: %s: %s%n\", file, exc);\n }\n return CONTINUE;\n }\n}\n long bytes = java.nio.file.Files.copy( \n new java.io.File(\"<filepath1>\").toPath(), \n new java.io.File(\"<filepath2>\").toPath(),\n java.nio.file.StandardCopyOption.REPLACE_EXISTING,\n java.nio.file.StandardCopyOption.COPY_ATTRIBUTES,\n java.nio.file.LinkOption.NOFOLLOW_LINKS);\n long bytes = java.nio.file.Files.move( \n new java.io.File(\"<filepath1>\").toPath(), \n new java.io.File(\"<filepath2>\").toPath(),\n java.nio.file.StandardCopyOption.ATOMIC_MOVE,\n java.nio.file.StandardCopyOption.REPLACE_EXISTING);\n long bytes = com.yourcompany.nio.Files.copyRecursive( \n new java.io.File(\"<filepath1>\").toPath(), \n new java.io.File(\"<filepath2>\").toPath(),\n java.nio.file.StandardCopyOption.REPLACE_EXISTING,\n java.nio.file.StandardCopyOption.COPY_ATTRIBUTES\n java.nio.file.LinkOption.NOFOLLOW_LINKS );\n"
},
{
"answer_id": 19542599,
"author": "Rakshi",
"author_id": 979752,
"author_profile": "https://Stackoverflow.com/users/979752",
"pm_score": 5,
"selected": false,
"text": "public void copy(File src, File dst) throws IOException {\n InputStream in = new FileInputStream(src);\n try {\n OutputStream out = new FileOutputStream(dst);\n try {\n // Transfer bytes from in to out\n byte[] buf = new byte[1024];\n int len;\n while ((len = in.read(buf)) > 0) {\n out.write(buf, 0, len);\n }\n } finally {\n out.close();\n }\n } finally {\n in.close();\n }\n}\n"
},
{
"answer_id": 19974236,
"author": "user1079877",
"author_id": 1079877,
"author_profile": "https://Stackoverflow.com/users/1079877",
"pm_score": 2,
"selected": false,
"text": "private void copy(final File f1, final File f2) throws IOException {\n f2.createNewFile();\n\n final RandomAccessFile file1 = new RandomAccessFile(f1, \"r\");\n final RandomAccessFile file2 = new RandomAccessFile(f2, \"rw\");\n\n file2.getChannel().write(file1.getChannel().map(FileChannel.MapMode.READ_ONLY, 0, f1.length()));\n\n file1.close();\n file2.close();\n}\n"
},
{
"answer_id": 21151754,
"author": "user3200607",
"author_id": 3200607,
"author_profile": "https://Stackoverflow.com/users/3200607",
"pm_score": 3,
"selected": false,
"text": "public static void copyFile(File src, File dst) throws IOException\n{\n long p = 0, dp, size;\n FileChannel in = null, out = null;\n\n try\n {\n if (!dst.exists()) dst.createNewFile();\n\n in = new FileInputStream(src).getChannel();\n out = new FileOutputStream(dst).getChannel();\n size = in.size();\n\n while ((dp = out.transferFrom(in, p, size)) > 0)\n {\n p += dp;\n }\n }\n finally {\n try\n {\n if (out != null) out.close();\n }\n finally {\n if (in != null) in.close();\n }\n }\n}\n"
},
{
"answer_id": 24333657,
"author": "Kevin Sadler",
"author_id": 969833,
"author_profile": "https://Stackoverflow.com/users/969833",
"pm_score": 6,
"selected": false,
"text": "File src = new File(\"original.txt\");\nFile target = new File(\"copy.txt\");\n\nFiles.copy(src.toPath(), target.toPath(), StandardCopyOption.REPLACE_EXISTING);\n"
},
{
"answer_id": 26908379,
"author": "JaskeyLam",
"author_id": 2087628,
"author_profile": "https://Stackoverflow.com/users/2087628",
"pm_score": 3,
"selected": false,
"text": "private static void copyFileUsingJava7Files(File source, File dest) throws IOException {\n Files.copy(source.toPath(), dest.toPath());\n}\n private static void copyFileUsingApacheCommonsIO(File source, File dest) throws IOException {\n FileUtils.copyFile(source, dest);\n}\n private static void copyFileUsingGuava(File source,File dest) throws IOException{\n Files.copy(source,dest); \n}\n"
},
{
"answer_id": 28388413,
"author": "Tony",
"author_id": 1985234,
"author_profile": "https://Stackoverflow.com/users/1985234",
"pm_score": 2,
"selected": false,
"text": "import java.io.Closeable;\nimport java.io.File;\nimport java.io.FileInputStream;\nimport java.io.FileOutputStream;\nimport java.io.IOException;\nimport java.nio.ByteBuffer;\nimport java.nio.channels.FileChannel;\nimport java.text.DecimalFormat;\n\n\npublic class test {\n\nprivate static final int BUFFER = 4096*16;\nstatic final DecimalFormat df = new DecimalFormat(\"#,###.##\");\npublic static void nioBufferCopy(final File source, final File target ) {\n FileChannel in = null;\n FileChannel out = null;\n double size=0;\n long overallT1 = System.currentTimeMillis();\n\n try {\n in = new FileInputStream(source).getChannel();\n out = new FileOutputStream(target).getChannel();\n size = in.size();\n double size2InKB = size / 1024 ;\n ByteBuffer buffer = ByteBuffer.allocateDirect(BUFFER);\n\n while (in.read(buffer) != -1) {\n buffer.flip();\n\n while(buffer.hasRemaining()){\n out.write(buffer);\n }\n\n buffer.clear();\n }\n long overallT2 = System.currentTimeMillis();\n System.out.println(String.format(\"Copied %s KB in %s millisecs\", df.format(size2InKB), (overallT2 - overallT1)));\n }\n catch (IOException e) {\n e.printStackTrace();\n }\n\n finally {\n close(in);\n close(out);\n }\n}\n\nprivate static void close(Closeable closable) {\n if (closable != null) {\n try {\n closable.close();\n } catch (IOException e) {\n if (FastCopy.debug)\n e.printStackTrace();\n } \n }\n}\n"
},
{
"answer_id": 50602790,
"author": "Vinit Shandilya",
"author_id": 2173438,
"author_profile": "https://Stackoverflow.com/users/2173438",
"pm_score": 1,
"selected": false,
"text": "private static long fileCopyUsingFileStreams(File fileToCopy, File newFile) throws IOException {\n FileInputStream input = new FileInputStream(fileToCopy);\n FileOutputStream output = new FileOutputStream(newFile);\n byte[] buf = new byte[1024];\n int bytesRead;\n long start = System.currentTimeMillis();\n while ((bytesRead = input.read(buf)) > 0)\n {\n output.write(buf, 0, bytesRead);\n }\n long end = System.currentTimeMillis();\n\n input.close();\n output.close();\n\n return (end-start);\n}\n\nprivate static long fileCopyUsingNIOChannelClass(File fileToCopy, File newFile) throws IOException\n{\n FileInputStream inputStream = new FileInputStream(fileToCopy);\n FileChannel inChannel = inputStream.getChannel();\n\n FileOutputStream outputStream = new FileOutputStream(newFile);\n FileChannel outChannel = outputStream.getChannel();\n\n long start = System.currentTimeMillis();\n inChannel.transferTo(0, fileToCopy.length(), outChannel);\n long end = System.currentTimeMillis();\n\n inputStream.close();\n outputStream.close();\n\n return (end-start);\n}\n\nprivate static long fileCopyUsingApacheCommons(File fileToCopy, File newFile) throws IOException\n{\n long start = System.currentTimeMillis();\n FileUtils.copyFile(fileToCopy, newFile);\n long end = System.currentTimeMillis();\n return (end-start);\n}\n\nprivate static long fileCopyUsingNIOFilesClass(File fileToCopy, File newFile) throws IOException\n{\n Path source = Paths.get(fileToCopy.getPath());\n Path destination = Paths.get(newFile.getPath());\n long start = System.currentTimeMillis();\n Files.copy(source, destination, StandardCopyOption.REPLACE_EXISTING);\n long end = System.currentTimeMillis();\n\n return (end-start);\n}\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/106770",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17123/"
] |
106,800
|
<p>Does anyone know of where to find unit testing guidelines and recommendations? I'd like to have something which addresses the following types of topics (for example):</p>
<ul>
<li>Should tests be in the same project as application logic?</li>
<li>Should I have test classes to mirror my logic classes or should I have only as many test classes as I feel I need to have?</li>
<li>How should I name my test classes, methods, and projects (if they go in different projects)</li>
<li>Should private, protected, and internal methods be tested, or just those that are publicly accessible?</li>
<li>Should unit and integration tests be separated?</li>
<li>Is there a <strong>good</strong> reason not to have 100% test coverage?</li>
</ul>
<p>What am I not asking about that I should be?</p>
<p>An online resource would be best.</p>
|
[
{
"answer_id": 106813,
"author": "Josh",
"author_id": 11702,
"author_profile": "https://Stackoverflow.com/users/11702",
"pm_score": 5,
"selected": true,
"text": "public class UserBehavior\n public void ShouldBeAbleToSetUserFirstName()\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/106800",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19421/"
] |
106,820
|
<p>I realize that literally it translates to Java Enterprise Edition. But what I'm asking is what does this really mean? When a company requires Java EE experience, what are they really asking for? Experience with EJBs? Experience with Java web apps? </p>
<p>I suspect that this means something different to different people and the definition is subjective.</p>
|
[
{
"answer_id": 231843,
"author": "oxbow_lakes",
"author_id": 16853,
"author_profile": "https://Stackoverflow.com/users/16853",
"pm_score": 5,
"selected": false,
"text": "API"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/106820",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/292/"
] |
106,828
|
<p>I need to display a bunch of images on a web page using AJAX. All of them have different dimensions, so I want to adjust their size before displaying them. Is there any way to do this in JavaScript?</p>
<p>Using PHP's <code>getimagesize()</code> for each image causes an unnecessary performance hit since there will be many images.</p>
|
[
{
"answer_id": 106843,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "<img>"
},
{
"answer_id": 106844,
"author": "Stephen Wrighton",
"author_id": 7516,
"author_profile": "https://Stackoverflow.com/users/7516",
"pm_score": 4,
"selected": false,
"text": "var curHeight;\nvar curWidth;\n\nfunction getImgSize(imgSrc)\n{\nvar newImg = new Image();\nnewImg.src = imgSrc;\ncurHeight = newImg.height;\ncurWidth = newImg.width;\n\n}\n"
},
{
"answer_id": 110786,
"author": "ConroyP",
"author_id": 2287,
"author_profile": "https://Stackoverflow.com/users/2287",
"pm_score": 2,
"selected": false,
"text": "var image_from_ajax = new Image();\nimage_from_ajax.src = fetch_image_from_ajax(); // Downloaded via ajax call?\n\nimage_from_ajax = rescaleImage(image_from_ajax);\n\n// Rescale the given image to a max of max_height and max_width\nfunction rescaleImage(image_name)\n{\n var max_height = 100;\n var max_width = 100;\n\n var height = image_name.height;\n var width = image_name.width;\n var ratio = height/width;\n\n // If height or width are too large, they need to be scaled down\n // Multiply height and width by the same value to keep ratio constant\n if(height > max_height)\n {\n ratio = max_height / height;\n height = height * ratio;\n width = width * ratio;\n }\n\n if(width > max_width)\n {\n ratio = max_width / width;\n height = height * ratio;\n width = width * ratio;\n }\n\n image_name.width = width;\n image_name.height = height;\n return image_name;\n}\n"
},
{
"answer_id": 952185,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 6,
"selected": false,
"text": "<script type=\"text/javascript\">\n\n var imgHeight;\n var imgWidth;\n\n function findHHandWW() {\n imgHeight = this.height;\n imgWidth = this.width;\n return true;\n }\n\n function showImage(imgPath) {\n var myImage = new Image();\n myImage.name = imgPath;\n myImage.onload = findHHandWW;\n myImage.src = imgPath;\n }\n</script>\n"
},
{
"answer_id": 9718666,
"author": "Hoan Huynh",
"author_id": 1046168,
"author_profile": "https://Stackoverflow.com/users/1046168",
"pm_score": 2,
"selected": false,
"text": "<script type=\"text/javascript\">\nfunction jquery_get_width_height()\n{\n var imgWidth = $(\"#img\").width();\n var imgHeight = $(\"#img\").height();\n alert(\"JQuery -- \" + \"imgWidth: \" + imgWidth + \" - imgHeight: \" + imgHeight);\n}\n</script>\n <script type=\"text/javascript\">\nfunction javascript_get_width_height()\n{\n var img = document.getElementById('img');\n alert(\"JavaSript -- \" + \"imgWidth: \" + img.width + \" - imgHeight: \" + img.height);\n}\n</script>\n"
},
{
"answer_id": 16193510,
"author": "Ray",
"author_id": 2209094,
"author_profile": "https://Stackoverflow.com/users/2209094",
"pm_score": 0,
"selected": false,
"text": "<img> style = \"display none\" Image()"
},
{
"answer_id": 56649435,
"author": "moto",
"author_id": 7435898,
"author_profile": "https://Stackoverflow.com/users/7435898",
"pm_score": 2,
"selected": false,
"text": "img.naturalWidth img.naturalHeight"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/106828",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
106,854
|
<p>Whats a good value for an identity increment for an 'Orders' table? (orders as in shopping cart orders)</p>
<p>I want the order numbers to appear so that we have more orders than we really do, plus make it harder for users to guess order numbers of other users in cases where that might be a problem.</p>
<p>I dont want too big a value such that I might run out of values, and i also don't want a noticable sequence to be apparent.</p>
<p>I've settled on 42 for now</p>
|
[
{
"answer_id": 106875,
"author": "David Basarab",
"author_id": 2469,
"author_profile": "https://Stackoverflow.com/users/2469",
"pm_score": 0,
"selected": false,
"text": "[ID] [int] IDENTITY(5497,73) NOT NULL,\n"
},
{
"answer_id": 9463851,
"author": "soniiic",
"author_id": 104435,
"author_profile": "https://Stackoverflow.com/users/104435",
"pm_score": 0,
"selected": false,
"text": "Id OrderNumber Id"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/106854",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16940/"
] |
106,880
|
<p>I am trying to use the <code>InternalsVisibleTo</code> assembly attribute to make my internal classes in a .NET class library visible to my unit test project. For some reason, I keep getting an error message that says:</p>
<blockquote>
<p>'MyClassName' is inaccessible due to its protection level</p>
</blockquote>
<p>Both assemblies are signed and I have the correct key listed in the attribute declaration. Any ideas?</p>
|
[
{
"answer_id": 107958,
"author": "Joe",
"author_id": 13087,
"author_profile": "https://Stackoverflow.com/users/13087",
"pm_score": 8,
"selected": true,
"text": "[assembly: InternalsVisibleTo(\"MyFriendAssembly,\nPublicKey=0024000004800000940000000602000000240000525341310004000001000100F73\nF4DDC11F0CA6209BC63EFCBBAC3DACB04B612E04FA07F01D919FB5A1579D20283DC12901C8B66\nA08FB8A9CB6A5E81989007B3AA43CD7442BED6D21F4D33FB590A46420FB75265C889D536A9519\n674440C3C2FB06C5924360243CACD4B641BE574C31A434CE845323395842FAAF106B234C2C140\n6E2F553073FF557D2DB6C5\")]\n"
},
{
"answer_id": 770404,
"author": "Colin Desmond",
"author_id": 93399,
"author_profile": "https://Stackoverflow.com/users/93399",
"pm_score": 4,
"selected": false,
"text": "#using \"AssemblyUnderTest.dll\" as_friend\n #using"
},
{
"answer_id": 3594856,
"author": "Skimedic",
"author_id": 365309,
"author_profile": "https://Stackoverflow.com/users/365309",
"pm_score": 5,
"selected": false,
"text": "[assembly: AssemblyKeyFile(\"\")]\n[assembly: AssemblyKeyName(\"\")]\n"
},
{
"answer_id": 9827552,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "/bin/debug Sub GetInternalsVisibleToForCurrentProject()\n Dim temp = \"[assembly: global::System.Runtime.CompilerServices.\" + _\n \"InternalsVisibleTo(\"\"{0}, publickey={1}\"\")]\"\n Dim projs As System.Array\n Dim proj As Project\n projs = DTE.ActiveSolutionProjects()\n If projs.Length < 1 Then\n Return\n End If\n\n proj = CType(projs.GetValue(0), EnvDTE.Project)\n Dim path, dir, filename As String\n path = proj.FullName\n dir = System.IO.Path.GetDirectoryName(path)\n filename = System.IO.Path.GetFileNameWithoutExtension(path)\n filename = System.IO.Path.ChangeExtension(filename, \"dll\")\n dir += \"\\bin\\debug\\\"\n filename = System.IO.Path.Combine(dir, filename)\n If Not System.IO.File.Exists(filename) Then\n MsgBox(\"Cannot load file \" + filename)\n Return\n End If\n Dim assy As System.Reflection.Assembly\n assy = System.Reflection.Assembly.Load(filename)\n Dim pk As Byte() = assy.GetName().GetPublicKey()\n Dim hex As String = BitConverter.ToString(pk).Replace(\"-\", \"\")\n System.Windows.Forms.Clipboard.SetText(String.Format(temp, assy.GetName().Name, hex))\n MsgBox(\"InternalsVisibleTo attribute copied to the clipboard.\")\nEnd Sub\n"
},
{
"answer_id": 15085309,
"author": "Keysharpener",
"author_id": 1314858,
"author_profile": "https://Stackoverflow.com/users/1314858",
"pm_score": 0,
"selected": false,
"text": "InternalsVisibleTo"
},
{
"answer_id": 17887998,
"author": "John Beyer",
"author_id": 1575257,
"author_profile": "https://Stackoverflow.com/users/1575257",
"pm_score": 5,
"selected": false,
"text": "InternalsVisibleToAttribute Thingamajig ThingamajigAutoTests [assembly: InternalsVisibleTo( \"ThingamajigAutoTests\" )] AssemblyKeyFile AssemblyKeyName Thingamajig ThingamajigAutoTests InternalsVisibleTo"
},
{
"answer_id": 33130126,
"author": "Micaël",
"author_id": 2312731,
"author_profile": "https://Stackoverflow.com/users/2312731",
"pm_score": 2,
"selected": false,
"text": "[assembly: InternalsVisibleTo(\"NameSpace.MyFriendAssembly, PublicKey=0024000004800000940000000602000000240000525341310004000001000100F73F4DDC11F0CA6209BC63EFCBBAC3DACB04B612E04FA07F01D919FB5A1579D20283DC12901C8B66A08FB8A9CB6A5E81989007B3AA43CD7442BED6D21F4D33FB590A46420FB75265C889D536A9519674440C3C2FB06C5924360243CACD4B641BE574C31A434CE845323395842FAAF106B234C2C1406E2F553073FF557D2DB6C5\")]\n sn -Tp path\\to\\assembly\\MyFriendAssembly.dll\n"
},
{
"answer_id": 33201501,
"author": "Murugan Sivananantha Perumal",
"author_id": 4856270,
"author_profile": "https://Stackoverflow.com/users/4856270",
"pm_score": 2,
"selected": false,
"text": "[assembly: InternalsVisibleTo(\"assemblyname,\nPublicKey=\"Full Public Key\")]\n"
},
{
"answer_id": 33915479,
"author": "Jochen",
"author_id": 628755,
"author_profile": "https://Stackoverflow.com/users/628755",
"pm_score": 1,
"selected": false,
"text": "<Assembly: InternalsVisibleTo(\"friend_unsigned_B\")>"
},
{
"answer_id": 39927370,
"author": "Tatiana Racheva",
"author_id": 132042,
"author_profile": "https://Stackoverflow.com/users/132042",
"pm_score": 2,
"selected": false,
"text": "// In X\ninternal static class XType\n{\n internal static ZType GetZ() { ... }\n}\n\n// In Y:\nobject someUntypedValue = XType.GetZ();\n\n// In Z:\ninternal class ZType { ... }\n"
},
{
"answer_id": 70007000,
"author": "Alexander Høst",
"author_id": 2149075,
"author_profile": "https://Stackoverflow.com/users/2149075",
"pm_score": 2,
"selected": false,
"text": "AssemblyInfo InternalsVisibleTo ItemGroup csproj <ItemGroup>\n <InternalsVisibleTo Include=\"My.Project.Tests\" />\n </ItemGroup>\n"
},
{
"answer_id": 72241838,
"author": "Alexander Høst",
"author_id": 2149075,
"author_profile": "https://Stackoverflow.com/users/2149075",
"pm_score": 0,
"selected": false,
"text": "InternalsVisibleTo Moq Moq [assembly: InternalsVisibleTo(\"DynamicProxyGenAssembly2\")] AssemblyInfo"
},
{
"answer_id": 74610374,
"author": "DevDave",
"author_id": 896631,
"author_profile": "https://Stackoverflow.com/users/896631",
"pm_score": 0,
"selected": false,
"text": "MyField field;\n internal MyField field;\n internal"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/106880",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14101/"
] |
106,886
|
<p>I have a table that is dynamically created using DIVs. Each row of the table has two images. I want to set the height for the div (that represents a particular row) to the height of image that is greater of the two images being displayed in that particular row. The images to displayed will always change, and they are from an external server.</p>
<p>How do I set the height for my div so that I can fit images?</p>
|
[
{
"answer_id": 106915,
"author": "MetaGuru",
"author_id": 18309,
"author_profile": "https://Stackoverflow.com/users/18309",
"pm_score": 0,
"selected": false,
"text": "function getSize(imgSrc){\n\n var aImg = new Image();\n\n aImg.src = imgSrc;\n\n aHeight = newImg.height;\n aWidth = newImg.width;\n\n}\n"
},
{
"answer_id": 4788508,
"author": "Lukke",
"author_id": 588288,
"author_profile": "https://Stackoverflow.com/users/588288",
"pm_score": 2,
"selected": false,
"text": " this.img = new Image();\n this.img.src = url;\n alert(this.img.width);\n var img = new Image();\n img.src = url;\n alert(img.width);\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/106886",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
106,896
|
<p>I'm used to the Java model where you can have one public class per file. Python doesn't have this restriction, and I'm wondering what's the best practice for organizing classes.</p>
|
[
{
"answer_id": 107836,
"author": "S.Lott",
"author_id": 10661,
"author_profile": "https://Stackoverflow.com/users/10661",
"pm_score": 9,
"selected": true,
"text": "from ssReader import Reader\nfrom theCalcs import ACalc, AnotherCalc\nfrom theDB import Loader\n\ndef main( sourceFileName ):\n rdr= Reader( sourceFileName )\n c1= ACalc( options )\n c2= AnotherCalc( options )\n ldr= Loader( parameters )\n for myObj in rdr.readAll():\n c1.thisOp( myObj )\n c2.thatOp( myObj )\n ldr.laod( myObj )\n import"
},
{
"answer_id": 328563,
"author": "dbr",
"author_id": 745,
"author_profile": "https://Stackoverflow.com/users/745",
"pm_score": 4,
"selected": false,
"text": "class SomeData: pass data_model.py from mypackage.data_model import SomeData, SomeSubData from mypackage.database.schema import MyModel from mypackage.email.errors import MyDatabaseModel"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/106896",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14139/"
] |
106,907
|
<p>We put all of our unit tests in their own projects. We find that we have to make certain classes public instead of internal just for the unit tests. Is there anyway to avoid having to do this. What are the memory implication by making classes public instead of sealed?</p>
|
[
{
"answer_id": 106948,
"author": "Ash",
"author_id": 5023,
"author_profile": "https://Stackoverflow.com/users/5023",
"pm_score": 9,
"selected": true,
"text": "[assembly: InternalsVisibleTo(\"NameAssemblyYouWantToPermitAccess\")]\nnamespace NameOfYourNameSpace\n{\n"
},
{
"answer_id": 11167226,
"author": "ktutnik",
"author_id": 212706,
"author_profile": "https://Stackoverflow.com/users/212706",
"pm_score": 2,
"selected": false,
"text": "Type.GetType //IServiceWrapper is public class which is \n//the same assembly with the internal class \nvar asm = typeof(IServiceWrapper).Assembly;\n//Namespace.ServiceWrapper is internal\nvar type = asm.GetType(\"Namespace.ServiceWrapper\");\nreturn (IServiceWrapper<T>)Activator\n .CreateInstance(type, new object[1] { /*constructor parameter*/ });\n var asm = typeof(IServiceWrapper).Assembly;\n//note the name Namespace.ServiceWrapper`1\n//this is for calling Namespace.ServiceWrapper<>\nvar type = asm.GetType(\"Namespace.ServiceWrapper`1\");\nvar genType = type.MakeGenericType(new Type[1] { typeof(T) });\nreturn (IServiceWrapper<T>)Activator\n .CreateInstance(genType, new object[1] { /*constructor parameter*/});\n"
},
{
"answer_id": 67281561,
"author": "babula pradhan",
"author_id": 8704435,
"author_profile": "https://Stackoverflow.com/users/8704435",
"pm_score": 3,
"selected": false,
"text": "[assembly: InternalsVisibleTo(\"AssemblytoVisible\")] <ItemGroup>\n <AssemblyAttribute Include=\"System.Runtime.CompilerServices.InternalsVisibleTo\">\n <_Parameter1>Test_Project_Name</_Parameter1> <!-- The name of the project that you want the Internal class to be visible To it -->\n </AssemblyAttribute>\n</ItemGroup>\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/106907",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4653/"
] |
106,912
|
<p>How do you draw a custom button next to the minimize, maximize and close buttons within the Titlebar of the Form?</p>
<p>I know you need to use Win32 API calls and override the WndProc procedure, but I haven't been able to figure out a solution that works right.</p>
<p>Does anyone know how to do this? More specifically, does anyone know a way to do this that works in Vista?</p>
|
[
{
"answer_id": 107437,
"author": "Matthew Scharley",
"author_id": 15537,
"author_profile": "https://Stackoverflow.com/users/15537",
"pm_score": 4,
"selected": true,
"text": "// The state of our little button\nButtonState _buttState = ButtonState.Normal;\nRectangle _buttPosition = new Rectangle();\n\n[DllImport(\"user32.dll\")]\nprivate static extern IntPtr GetWindowDC(IntPtr hWnd);\n[DllImport(\"user32.dll\")]\nprivate static extern int GetWindowRect(IntPtr hWnd, \n ref Rectangle lpRect);\n[DllImport(\"user32.dll\")]\nprivate static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);\nprotected override void WndProc(ref Message m)\n{\n int x, y;\n Rectangle windowRect = new Rectangle();\n GetWindowRect(m.HWnd, ref windowRect);\n\n switch (m.Msg)\n {\n // WM_NCPAINT\n case 0x85:\n // WM_PAINT\n case 0x0A:\n base.WndProc(ref m);\n\n DrawButton(m.HWnd);\n\n m.Result = IntPtr.Zero;\n\n break;\n\n // WM_ACTIVATE\n case 0x86:\n base.WndProc(ref m);\n DrawButton(m.HWnd);\n\n break;\n\n // WM_NCMOUSEMOVE\n case 0xA0:\n // Extract the least significant 16 bits\n x = ((int)m.LParam << 16) >> 16;\n // Extract the most significant 16 bits\n y = (int)m.LParam >> 16;\n\n x -= windowRect.Left;\n y -= windowRect.Top;\n\n base.WndProc(ref m);\n\n if (!_buttPosition.Contains(new Point(x, y)) && \n _buttState == ButtonState.Pushed)\n {\n _buttState = ButtonState.Normal;\n DrawButton(m.HWnd);\n }\n\n break;\n\n // WM_NCLBUTTONDOWN\n case 0xA1:\n // Extract the least significant 16 bits\n x = ((int)m.LParam << 16) >> 16;\n // Extract the most significant 16 bits\n y = (int)m.LParam >> 16;\n\n x -= windowRect.Left;\n y -= windowRect.Top;\n\n if (_buttPosition.Contains(new Point(x, y)))\n {\n _buttState = ButtonState.Pushed;\n DrawButton(m.HWnd);\n }\n else\n base.WndProc(ref m);\n\n break;\n\n // WM_NCLBUTTONUP\n case 0xA2:\n // Extract the least significant 16 bits\n x = ((int)m.LParam << 16) >> 16;\n // Extract the most significant 16 bits\n y = (int)m.LParam >> 16;\n\n x -= windowRect.Left;\n y -= windowRect.Top;\n\n if (_buttPosition.Contains(new Point(x, y)) &&\n _buttState == ButtonState.Pushed)\n {\n _buttState = ButtonState.Normal;\n // [[TODO]]: Fire a click event for your button \n // however you want to do it.\n DrawButton(m.HWnd);\n }\n else\n base.WndProc(ref m);\n\n break;\n\n // WM_NCHITTEST\n case 0x84:\n // Extract the least significant 16 bits\n x = ((int)m.LParam << 16) >> 16;\n // Extract the most significant 16 bits\n y = (int)m.LParam >> 16;\n\n x -= windowRect.Left;\n y -= windowRect.Top;\n\n if (_buttPosition.Contains(new Point(x, y)))\n m.Result = (IntPtr)18; // HTBORDER\n else\n base.WndProc(ref m);\n\n break;\n\n default:\n base.WndProc(ref m);\n break;\n }\n}\n\nprivate void DrawButton(IntPtr hwnd)\n{\n IntPtr hDC = GetWindowDC(hwnd);\n int x, y;\n\n using (Graphics g = Graphics.FromHdc(hDC))\n {\n // Work out size and positioning\n int CaptionHeight = Bounds.Height - ClientRectangle.Height;\n Size ButtonSize = SystemInformation.CaptionButtonSize;\n x = Bounds.Width - 4 * ButtonSize.Width;\n y = (CaptionHeight - ButtonSize.Height) / 2;\n _buttPosition.Location = new Point(x, y);\n\n // Work out color\n Brush color;\n if (_buttState == ButtonState.Pushed)\n color = Brushes.LightGreen;\n else\n color = Brushes.Red;\n\n // Draw our \"button\"\n g.FillRectangle(color, x, y, ButtonSize.Width, ButtonSize.Height);\n }\n\n ReleaseDC(hwnd, hDC);\n}\n\nprivate void Form1_Load(object sender, EventArgs e)\n{\n _buttPosition.Size = SystemInformation.CaptionButtonSize;\n}\n"
},
{
"answer_id": 862532,
"author": "AlexDrenea",
"author_id": 39624,
"author_profile": "https://Stackoverflow.com/users/39624",
"pm_score": 2,
"selected": false,
"text": " switch (m.Msg)\n {\n // WM_NCPAINT / WM_PAINT \n case 0x85:\n case 0x0A:\n //Call base method\n base.WndProc(ref m);\n //we have 3 buttons in the corner of the window. So first's new button left coord is offseted by 4 widths\n int crt = 4;\n //navigate trough all titlebar buttons on the form\n foreach (TitleBarImageButton crtBtn in titleBarButtons.Values)\n {\n //Calculate button coordinates\n p.X = (Bounds.Width - crt * crtBtn.Size.Width);\n p.Y = (Bounds.Height - ClientRectangle.Height - crtBtn.Size.Height) / 2;\n //Initialize button and draw\n crtBtn.Location = p;\n crtBtn.ButtonState = ImageButtonState.NORMAL;\n crtBtn.DrawButton(m.HWnd);\n //increment button left coord location offset\n crt++;\n }\n m.Result = IntPtr.Zero;\n break;\n // WM_ACTIVATE \n case 0x86:\n //Call base method\n base.WndProc(ref m);\n //Draw each button\n foreach (TitleBarImageButton crtBtn in titleBarButtons.Values)\n {\n crtBtn.ButtonState = ImageButtonState.NORMAL;\n crtBtn.DrawButton(m.HWnd);\n }\n break;\n // WM_NCMOUSEMOVE \n case 0xA0:\n //Get current mouse position\n p.X = ((int)m.LParam << 16) >> 16;// Extract the least significant 16 bits \n p.Y = (int)m.LParam >> 16; // Extract the most significant 16 bits \n p.X -= windowRect.Left;\n p.Y -= windowRect.Top;\n\n //Call base method\n base.WndProc(ref m);\n\n ImageButtonState newButtonState;\n foreach (TitleBarImageButton crtBtn in titleBarButtons.Values)\n {\n if (crtBtn.HitTest(p))\n {//mouse is over the current button\n if (crtBtn.MouseButtonState == MouseButtonState.PRESSED)\n //button is pressed - set pressed state\n newButtonState = ImageButtonState.PRESSED;\n else\n //button not pressed - set hoover state\n newButtonState = ImageButtonState.HOOVER;\n }\n else\n {\n //mouse not over the current button - set normal state\n newButtonState = ImageButtonState.NORMAL;\n }\n\n //if button state not modified, do not repaint it.\n if (newButtonState != crtBtn.ButtonState)\n {\n crtBtn.ButtonState = newButtonState;\n crtBtn.DrawButton(m.HWnd);\n }\n }\n break;\n // WM_NCLBUTTONDOWN \n case 0xA1:\n //Get current mouse position\n p.X = ((int)m.LParam << 16) >> 16;// Extract the least significant 16 bits\n p.Y = (int)m.LParam >> 16; // Extract the most significant 16 bits \n p.X -= windowRect.Left;\n p.Y -= windowRect.Top;\n\n //Call base method\n base.WndProc(ref m);\n\n foreach (TitleBarImageButton crtBtn in titleBarButtons.Values)\n {\n if (crtBtn.HitTest(p))\n {\n crtBtn.MouseButtonState = MouseButtonState.PRESSED;\n crtBtn.ButtonState = ImageButtonState.PRESSED;\n crtBtn.DrawButton(m.HWnd);\n }\n }\n break;\n // WM_NCLBUTTONUP \n case 0xA2:\n case 0x202:\n //Get current mouse position\n p.X = ((int)m.LParam << 16) >> 16;// Extract the least significant 16 bits \n p.Y = (int)m.LParam >> 16; // Extract the most significant 16 bits \n p.X -= windowRect.Left;\n p.Y -= windowRect.Top;\n\n //Call base method\n base.WndProc(ref m);\n foreach (TitleBarImageButton crtBtn in titleBarButtons.Values)\n {\n //if button is press\n if (crtBtn.ButtonState == ImageButtonState.PRESSED)\n {\n //Rasie button's click event\n crtBtn.OnClick(EventArgs.Empty);\n\n if (crtBtn.HitTest(p))\n crtBtn.ButtonState = ImageButtonState.HOOVER;\n else\n crtBtn.ButtonState = ImageButtonState.NORMAL;\n }\n\n crtBtn.MouseButtonState = MouseButtonState.NOTPESSED;\n crtBtn.DrawButton(m.HWnd);\n }\n break;\n // WM_NCHITTEST \n case 0x84:\n //Get current mouse position\n p.X = ((int)m.LParam << 16) >> 16;// Extract the least significant 16 bits\n p.Y = (int)m.LParam >> 16; // Extract the most significant 16 bits\n p.X -= windowRect.Left;\n p.Y -= windowRect.Top;\n\n bool isAnyButtonHit = false;\n foreach (TitleBarImageButton crtBtn in titleBarButtons.Values)\n {\n //if mouse is over the button, or mouse is pressed \n //(do not process messages when mouse was pressed on a button)\n if (crtBtn.HitTest(p) || crtBtn.MouseButtonState == MouseButtonState.PRESSED)\n {\n //return 18 (do not process further)\n m.Result = (IntPtr)18;\n //we have a hit\n isAnyButtonHit = true;\n //return \n break;\n }\n else\n {//mouse is not pressed and not over the button, redraw button if needed \n if (crtBtn.ButtonState != ImageButtonState.NORMAL)\n {\n crtBtn.ButtonState = ImageButtonState.NORMAL;\n crtBtn.DrawButton(m.HWnd);\n }\n }\n }\n //if we have a hit, do not process further\n if (!isAnyButtonHit)\n //Call base method\n base.WndProc(ref m);\n break;\n default:\n //Call base method\n base.WndProc(ref m);\n //Console.WriteLine(m.Msg + \"(0x\" + m.Msg.ToString(\"x\") + \")\");\n break;\n }\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/106912",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7831/"
] |
106,941
|
<p>I'm a pretty new C# and .NET developer. I recently created an MMC snapin using C# and was gratified by how easy it was to do, especially after hearing a lot of horror stories by some other developers in my organisation about how hard it is to do in C++.</p>
<p>I pretty much went through the whole project at some point and made every instance of the "public" keyword to "internal", except as required by the runtime in order to run the snapin. What is your feeling on this, should you generally make classes and methods public or internal?</p>
|
[
{
"answer_id": 106962,
"author": "Ryan Farley",
"author_id": 1627,
"author_profile": "https://Stackoverflow.com/users/1627",
"pm_score": -1,
"selected": false,
"text": "class Class1\n{\n}\n"
},
{
"answer_id": 106971,
"author": "Jay Bazuzi",
"author_id": 5314,
"author_profile": "https://Stackoverflow.com/users/5314",
"pm_score": 2,
"selected": false,
"text": "public internal public"
},
{
"answer_id": 106996,
"author": "Ryan Lundy",
"author_id": 5486,
"author_profile": "https://Stackoverflow.com/users/5486",
"pm_score": 4,
"selected": false,
"text": "internal InternalsVisibleTo InternalsVisibleTo"
},
{
"answer_id": 13183114,
"author": "James",
"author_id": 1185191,
"author_profile": "https://Stackoverflow.com/users/1185191",
"pm_score": 2,
"selected": false,
"text": "internal public public public internal"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/106941",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3146/"
] |
106,963
|
<p>I'm building the world's simplest library application. All I want to be able to do is scan in a book's UPC (barcode) using a typical scanner (which just types the numbers of the barcode into a field) and then use it to look up data about the book... at a minimum, title, author, year published, and either the Dewey Decimal or Library of Congress catalog number.</p>
<p>The goal is to print out a tiny sticker ("spine label") with the card catalog number that I can stick on the spine of the book, and then I can sort the books by card catalog number on the shelves in our company library. That way books on similar subjects will tend to be near each other, for example, if you know you're looking for a book about accounting, all you have to do is find SOME book about accounting and you'll see the other half dozen that we have right next to it which makes it convenient to browse the library.</p>
<p>There seem to be lots of web APIs to do this, including Amazon and the Library of Congress. But those are all extremely confusing to me. What I really just want is a single higher level function that takes a UPC barcode number and returns some basic data about the book.</p>
|
[
{
"answer_id": 106987,
"author": "Philip Rieck",
"author_id": 12643,
"author_profile": "https://Stackoverflow.com/users/12643",
"pm_score": 3,
"selected": false,
"text": "if (indexisbn.indexOf(\"978\") == 0) {\n isbn = isbn.substr(3,9);\n var xsum = 0;\n var add = 0;\n var i = 0;\n for (i = 0; i < 9; i++) {\n add = isbn.substr(i,1);\n xsum += (10 - i) * add;\n }\n xsum %= 11;\n xsum = 11 - xsum;\n if (xsum == 10) { xsum = \"X\"; }\n if (xsum == 11) { xsum = \"0\"; }\n isbn += xsum;\n}\n"
},
{
"answer_id": 107032,
"author": "curtisk",
"author_id": 17651,
"author_profile": "https://Stackoverflow.com/users/17651",
"pm_score": 7,
"selected": true,
"text": "http://isbndb.com/api/books.xml?access_key= &index1=isbn&results=details&value1=9780143038092 <ISBNdb server_time=\"2008-09-21T00:08:57Z\">\n <BookList total_results=\"1\" page_size=\"10\" page_number=\"1\" shown_results=\"1\">\n <BookData book_id=\"the_joy_luck_club_a12\" isbn=\"0143038095\">\n <Title>The Joy Luck Club</Title>\n <TitleLong/>\n <AuthorsText>Amy Tan, </AuthorsText>\n <PublisherText publisher_id=\"penguin_non_classics\">Penguin (Non-Classics)</PublisherText>\n <Details dewey_decimal=\"813.54\" physical_description_text=\"288 pages\" language=\"\" edition_info=\"Paperback; 2006-09-21\" dewey_decimal_normalized=\"813.54\" lcc_number=\"\" change_time=\"2006-12-11T06:26:55Z\" price_time=\"2008-09-20T23:51:33Z\"/>\n </BookData>\n </BookList>\n</ISBNdb>\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/106963",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4/"
] |
106,965
|
<p>Is there a way to read a locked file across a network given that you are the machine admin on the remote machine? I haven't been able to read the locked file locally, and attempting it over the network adds another layer of difficulty.</p>
|
[
{
"answer_id": 106987,
"author": "Philip Rieck",
"author_id": 12643,
"author_profile": "https://Stackoverflow.com/users/12643",
"pm_score": 3,
"selected": false,
"text": "if (indexisbn.indexOf(\"978\") == 0) {\n isbn = isbn.substr(3,9);\n var xsum = 0;\n var add = 0;\n var i = 0;\n for (i = 0; i < 9; i++) {\n add = isbn.substr(i,1);\n xsum += (10 - i) * add;\n }\n xsum %= 11;\n xsum = 11 - xsum;\n if (xsum == 10) { xsum = \"X\"; }\n if (xsum == 11) { xsum = \"0\"; }\n isbn += xsum;\n}\n"
},
{
"answer_id": 107032,
"author": "curtisk",
"author_id": 17651,
"author_profile": "https://Stackoverflow.com/users/17651",
"pm_score": 7,
"selected": true,
"text": "http://isbndb.com/api/books.xml?access_key= &index1=isbn&results=details&value1=9780143038092 <ISBNdb server_time=\"2008-09-21T00:08:57Z\">\n <BookList total_results=\"1\" page_size=\"10\" page_number=\"1\" shown_results=\"1\">\n <BookData book_id=\"the_joy_luck_club_a12\" isbn=\"0143038095\">\n <Title>The Joy Luck Club</Title>\n <TitleLong/>\n <AuthorsText>Amy Tan, </AuthorsText>\n <PublisherText publisher_id=\"penguin_non_classics\">Penguin (Non-Classics)</PublisherText>\n <Details dewey_decimal=\"813.54\" physical_description_text=\"288 pages\" language=\"\" edition_info=\"Paperback; 2006-09-21\" dewey_decimal_normalized=\"813.54\" lcc_number=\"\" change_time=\"2006-12-11T06:26:55Z\" price_time=\"2008-09-20T23:51:33Z\"/>\n </BookData>\n </BookList>\n</ISBNdb>\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/106965",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2712/"
] |
106,979
|
<p>I have two threads, one needs to poll a bunch of separate static resources looking for updates. The other one needs to get the data and store it in the database. How can thread 1 tell thread 2 that there is something to process?</p>
|
[
{
"answer_id": 106994,
"author": "1800 INFORMATION",
"author_id": 3146,
"author_profile": "https://Stackoverflow.com/users/3146",
"pm_score": 4,
"selected": true,
"text": "QueueUserWorkItem TaskInfo ti = new TaskInfo(\"This report displays the number {0}.\", 42);\n\n // Queue the task and data.\n if (ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProc), ti)) { \n Console.WriteLine(\"Main thread does some work, then sleeps.\");\n\n // If you comment out the Sleep, the main thread exits before\n // the ThreadPool task has a chance to run. ThreadPool uses \n // background threads, which do not keep the application \n // running. (This is a simple example of a race condition.)\n Thread.Sleep(1000);\n\n Console.WriteLine(\"Main thread exits.\");\n }\n else {\n Console.WriteLine(\"Unable to queue ThreadPool request.\"); \n }\n\n\n// The thread procedure performs the independent task, in this case\n// formatting and printing a very simple report.\n//\nstatic void ThreadProc(Object stateInfo) {\n TaskInfo ti = (TaskInfo) stateInfo;\n Console.WriteLine(ti.Boilerplate, ti.Value); \n}\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/106979",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14101/"
] |
107,005
|
<p>I'm trying to find if there is a reliable way (using <a href="http://en.wikipedia.org/wiki/SQLite" rel="noreferrer">SQLite</a>) to find the ID of the next row to be inserted, <em>before it gets inserted</em>. I need to use the id for another insert statement, but don't have the option of instantly inserting and getting the next row.</p>
<p>Is predicting the next id as simple as getting the last id and adding one? Is that a guarantee?</p>
<p>Edit: A little more reasoning...
I can't insert immediately because the insert may end up being canceled by the user. User will make some changes, SQL statements will be stored, and from there the user can either save (inserting all the rows at once), or cancel (not changing anything). In the case of a program crash, the desired functionality is that nothing gets changed.</p>
|
[
{
"answer_id": 107115,
"author": "Eevee",
"author_id": 17875,
"author_profile": "https://Stackoverflow.com/users/17875",
"pm_score": 5,
"selected": true,
"text": "BEGIN; COMMIT; ROLLBACK; MAX(id)"
},
{
"answer_id": 409834,
"author": "Einstein",
"author_id": 41898,
"author_profile": "https://Stackoverflow.com/users/41898",
"pm_score": 2,
"selected": false,
"text": "SELECT Balance FROM Bank ...\nUPDATE Bank SET Balance = valuefromselect + 1.00 WHERE ...\n WHERE Balance = valuefromselect\n"
},
{
"answer_id": 5232836,
"author": "abugen",
"author_id": 649843,
"author_profile": "https://Stackoverflow.com/users/649843",
"pm_score": 0,
"selected": false,
"text": "select max(id) from particular_table;\n"
},
{
"answer_id": 5301923,
"author": "Greg J",
"author_id": 659211,
"author_profile": "https://Stackoverflow.com/users/659211",
"pm_score": 5,
"selected": false,
"text": "SELECT * FROM SQLITE_SEQUENCE WHERE name='TABLE'; seq"
},
{
"answer_id": 8235802,
"author": "contributor",
"author_id": 1060890,
"author_profile": "https://Stackoverflow.com/users/1060890",
"pm_score": 2,
"selected": false,
"text": "select max(id) from particular_table is unreliable for the reason below..\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107005",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14278/"
] |
107,054
|
<p>I'm trying to implement an outdent of the first letter of the first paragraph of the body text. Where I'm stuck is in getting consistent spacing between the first letter and the rest of the paragraph. </p>
<p>For example, there is a huge difference in spacing between a "W" and an "I"</p>
<p><img src="https://i.stack.imgur.com/2TsvYm.png" alt="'I' Outdent"><br>
<img src="https://i.stack.imgur.com/DnZVSm.png" alt="'W' Outdent"></p>
<p>Anyone have any ideas about how to mitigate the differences? I'd prefer a pure CSS solution, but will resort to JavaScript if need be.</p>
<p><strong>PS</strong>: I don't necessarily need compatibility in IE or Opera</p>
|
[
{
"answer_id": 107111,
"author": "Matthew Rapati",
"author_id": 15000,
"author_profile": "https://Stackoverflow.com/users/15000",
"pm_score": 0,
"selected": false,
"text": "p.outdent:first-letter {\n font-family: ms mincho;\n font-size: 8em;\n line-height: 1;\n font-weight: normal;\n float: left;\n margin: -0.1em 0 0 -.55em;\n letter-spacing: 0.05em;\n}\n"
},
{
"answer_id": 107149,
"author": "Eevee",
"author_id": 17875,
"author_profile": "https://Stackoverflow.com/users/17875",
"pm_score": 4,
"selected": true,
"text": "p.outdent:first-letter margin-left: -800px;\npadding-right: 460px;\nfloat: right;\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107054",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11577/"
] |
107,073
|
<p>I am designing a game to be played in the browser.</p>
<p>Game is a space theme and I need to generate a map of the "Galaxy".</p>
<p>The basic idea of the map is here:</p>
<p><a href="http://www.oglehq.com/map.png" rel="nofollow noreferrer">game map http://www.oglehq.com/map.png</a></p>
<p>The map is a grid, with each grid sector can contain a planet/system and each of these has links to a number of adjacent grids.</p>
<p>To generate the maps I figured that I would have a collection of images representing the grid elements. So in the case of the sample above, each of the squares is a separate graphic. </p>
<p>To create a new map I would "weave" the images together.
The map element images would have the planets and their links already on them, and I, therefore, need to stitch the map together in such a way that each image is positioned with its appropriate counterparts => so the image in the bottom corner must have images to the left and diagonal left that link up with it correctly. </p>
<p>How would you go about creating the code to know where to place the images?
Is there a better way than using images?</p>
<p>At the moment performance and/or load should not be a consideration (if I need to generate maps to have preconfigured rather than do it in real-time, I don't mind).</p>
<p>If it makes a difference I will be using HTML, CSS, and JavaScript and backed by a Ruby on Rails app. </p>
|
[
{
"answer_id": 107161,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": -1,
"selected": false,
"text": "Bit 0 : Has planet\nBit 1 : Has line from planet going north\nBit 2 : Has line from planet going northwest\n...\nBit 8 : Has line from planet going northeast\n <table border=\"0\" cellspace=\"0\" cellpadding=\"0\">\n<tr>\n<td><img src=\"cell_X.gif\"></td>\n<td><img src=\"cell_X.gif\"></td>\n</tr>\n<tr>\n<td><img src=\"cell_X.gif\"></td>\n<td><img src=\"cell_X.gif\"></td>\n</tr>\n</table>\n"
},
{
"answer_id": 107177,
"author": "slim",
"author_id": 7512,
"author_profile": "https://Stackoverflow.com/users/7512",
"pm_score": 2,
"selected": false,
"text": "11000010.jpeg\n 196.jpg\n"
},
{
"answer_id": 107209,
"author": "Lloyd",
"author_id": 9952,
"author_profile": "https://Stackoverflow.com/users/9952",
"pm_score": 1,
"selected": false,
"text": " Tile Connections\n nw n ne w e sw s se\n nw 0 0 0 0 0 0 0 0 \n n 0 0 0 0 1 0 1 0\n ne 0 0 0 1 0 0 0 0\n w 0 0 0 0 0 0 0 0\n center 0 1 0 0 0 0 1 1\n e 0 0 0 0 0 0 0 0\n se 0 0 0 0 0 0 0 0\n s 0 1 0 0 1 0 0 0\n sw 1 0 0 1 0 0 0 0\n draw_map(connection_map):\n For each grid_square in connection_map\n connection_data = connection_map[grid_square]\n filenames = bitmap_filenames_from(connection_data)\n insert_image_references_into_table(grid_square,filenames)\n\n# For each square having one of 256 bitmaps:\nbitmap_filenames_from(connection_data):\n filename=\"Bitmap\"\n for each bit in connection_data:\n filename += bit ? \"1\" : 0\n return [filename,]\n\n# For each square having zero through nine bitmaps:\nbitmap_filename_from(connection_data):\n # Special case - square is empty\n if 1 not in connection_data:\n return []\n filenames=[]\n for i in 0..7:\n if connection_data[i]:\n filenames.append(\"Bitmap\"+i)\n filenames.append(\"BitmapSystem\");\n return filenames\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107073",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14971/"
] |
107,079
|
<p>I know WCF supports many WS-* protocols but WS-Eventing does seem to be listed.</p>
<p>I do know that WCF has a pub/sub model, but is it WS-Eventing compliant?</p>
|
[
{
"answer_id": 4185246,
"author": "till",
"author_id": 148337,
"author_profile": "https://Stackoverflow.com/users/148337",
"pm_score": 1,
"selected": false,
"text": " Subscribe s = new Subscribe();\n (s.Delivery = new DeliveryType()).Mode = \"http://schemas.xmlsoap.org/ws/2004/08/eventing/DeliveryModes/Push\";\n\n XmlDocument doc = new XmlDocument();\n using (XmlWriter writer = doc.CreateNavigator().AppendChild())\n {\n EndpointReferenceType notifyTo = new EndpointReferenceType();\n\n (notifyTo.Address = new AttributedURI()).Value = callbackEndpoint.Uri.AbsoluteUri;\n\n XmlRootAttribute notifyToElem = new XmlRootAttribute(\"NotifyTo\");\n notifyToElem.Namespace = \"http://schemas.xmlsoap.org/ws/2004/08/eventing\";\n\n XmlDocument doc2 = new XmlDocument(); \n using (XmlWriter writer2 = doc2.CreateNavigator().AppendChild())\n {\n XmlRootAttribute ReferenceElement = new XmlRootAttribute(\"ReferenceElement\");\n foreach(AddressHeader h in callbackEndpoint.Headers)\n {\n h.WriteAddressHeader(writer2); \n }\n\n writer2.Close();\n notifyTo.ReferenceParameters = new ReferenceParametersType();\n notifyTo.ReferenceParameters.Any = notifyTo.ReferenceParameters.Any = doc2.ChildNodes.Cast<XmlElement>().ToArray<XmlElement>(); \n }\n\n new XmlSerializer(notifyTo.GetType(), notifyToElem).Serialize(writer, notifyTo);\n }\n\n (s.Delivery.Any = new XmlElement[1])[0] = doc.DocumentElement;\n (s.Filter = new FilterType()).Dialect = \"http://schemas.xmlsoap.org/ws/2006/02/devprof/Action\";\n (s.Filter.Any = new System.Xml.XmlNode[1])[0] = new System.Xml.XmlDocument().CreateTextNode(\"http://www.teco.edu/SensorValues/SensorValuesEventOut\");\n\n SubscribeResponse subscription;\n try\n {\n Console.WriteLine(\"Subscribing to the event...\");\n //Console.ReadLine();\n subscription = eventSource.SubscribeOp(s);\n }\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107079",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2744/"
] |
107,117
|
<p>I noticed that you can call Queue.Synchronize to get a thread-safe queue object, but the same method isn't available on Queue<T>. Does anyone know why? Seems kind of weird.</p>
|
[
{
"answer_id": 107182,
"author": "Domenic",
"author_id": 3191,
"author_profile": "https://Stackoverflow.com/users/3191",
"pm_score": 3,
"selected": false,
"text": "Queue<T> ConcurrentQueue<T>"
},
{
"answer_id": 107789,
"author": "Matt Ryan",
"author_id": 19548,
"author_profile": "https://Stackoverflow.com/users/19548",
"pm_score": 7,
"selected": true,
"text": "ConcurrentQueue<T> ConcurrentQueue<T> Interlocked.CompareExchange() Thread.SpinWait() if (queue.Count > 0) {\n object obj = null;\n try {\n obj = queue.Dequeue();\n private static object lockObjForQueueOperations = new object();\n"
},
{
"answer_id": 5463018,
"author": "Shane Castle",
"author_id": 90340,
"author_profile": "https://Stackoverflow.com/users/90340",
"pm_score": 3,
"selected": false,
"text": "ConcurrentQueue<T> \n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107117",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14101/"
] |
107,132
|
<p>As a follow up to "<a href="https://stackoverflow.com/questions/105400/what-are-indexes-and-how-can-i-use-them-to-optimize-queries-in-my-database">What are indexes and how can I use them to optimise queries in my database?</a>" where I am attempting to learn about indexes, what columns are good index candidates? Specifically for an MS SQL database?</p>
<p>After some googling, everything I have read suggests that columns that are generally increasing and unique make a good index (things like MySQL's auto_increment), I understand this, but I am using MS SQL and I am using GUIDs for primary keys, so it seems that indexes would not benefit GUID columns...</p>
|
[
{
"answer_id": 107166,
"author": "Eevee",
"author_id": 17875,
"author_profile": "https://Stackoverflow.com/users/17875",
"pm_score": 2,
"selected": false,
"text": "SELECT ORDER too"
},
{
"answer_id": 107172,
"author": "pappes",
"author_id": 19494,
"author_profile": "https://Stackoverflow.com/users/19494",
"pm_score": 3,
"selected": false,
"text": "select * from tblOrder where status_id=:v_outstanding\n select * from tblCust where Surname like \"O'Brian%\"\n select * from tblOrder where paidYN='N'\n"
},
{
"answer_id": 8937872,
"author": "Somnath Muluk",
"author_id": 1045444,
"author_profile": "https://Stackoverflow.com/users/1045444",
"pm_score": 7,
"selected": false,
"text": "SELECT\n buyer_id /* no need to index */\nFROM buyers\nWHERE first_name='Tariq' /* consider indexing */\nAND last_name='Iqbal' /* consider indexing */\n SELECT\n buyers.buyer_id, /* no need to index */\n country.name /* no need to index */\nFROM buyers LEFT JOIN country\nON buyers.country_id=country.country_id /* consider indexing */\nWHERE\n first_name='Tariq' /* consider indexing */\nAND\n last_name='Iqbal' /* consider indexing */\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107132",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1638/"
] |
107,150
|
<p>How do I capture the event of the clicking the Selected Node of a TreeView?
It doesn't fire the <strong>SelectedNodeChanged</strong> since the selection has obviously not changed but then what event can I catch so I know that the Selected Node was clicked?</p>
<p><strong>UPDATE</strong>:
When I have some time, I'm going to have to dive into the bowels of the TreeView control and dig out what and where it handles the click events and subclass the TreeView to expose a new event OnSelectedNodeClicked.</p>
<p>I'll probably do this over the Christmas holidays and I'll report back with the results.</p>
<p><strong>UPDATE</strong>:
I have come up with a solution below that sub-classes the TreeView control.</p>
|
[
{
"answer_id": 107298,
"author": "Wayne",
"author_id": 8236,
"author_profile": "https://Stackoverflow.com/users/8236",
"pm_score": 3,
"selected": false,
"text": "protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e){\n // Do whatever you're doing\n TreeView1.SelectedNode.Selected = false;\n}\n"
},
{
"answer_id": 107509,
"author": "Larry Smithmier",
"author_id": 4911,
"author_profile": "https://Stackoverflow.com/users/4911",
"pm_score": 2,
"selected": false,
"text": "<form id=\"form1\" runat=\"server\">\n<div>\n <asp:TreeView ID=\"TreeView1\" runat=\"server\" OnSelectedNodeChanged=\"TreeView1_SelectedNodeChanged\"\n ShowLines=\"True\">\n <Nodes>\n <asp:TreeNode Text=\"Root\" Value=\"Root\">\n <asp:TreeNode Text=\"RootSub1\" Value=\"RootSub1\"></asp:TreeNode>\n <asp:TreeNode Text=\"RootSub2\" Value=\"RootSub2\"></asp:TreeNode>\n </asp:TreeNode>\n <asp:TreeNode Text=\"Root2\" Value=\"Root2\">\n <asp:TreeNode Text=\"Root2Sub1\" Value=\"Root2Sub1\">\n <asp:TreeNode Text=\"Root2Sub1Sub1\" Value=\"Root2Sub1Sub1\"></asp:TreeNode>\n </asp:TreeNode>\n <asp:TreeNode Text=\"Root2Sub2\" Value=\"Root2Sub2\"></asp:TreeNode>\n </asp:TreeNode>\n </Nodes>\n </asp:TreeView>\n <asp:Label ID=\"Label1\" runat=\"server\" Text=\"Selected\"></asp:Label>\n <asp:TextBox ID=\"TextBox1\" runat=\"server\"></asp:TextBox>\n <asp:Label ID=\"Label2\" runat=\"server\" Text=\"Label\"></asp:Label></div>\n</form>\n protected void Page_Load(object sender, EventArgs e)\n{\n if(TreeView1.SelectedNode!=null && this.TextBox1.Text == TreeView1.SelectedNode.Value.ToString())\n {\n Label2.Text = (int.Parse(Label2.Text) + 1).ToString();\n }\n else\n {\n Label2.Text = \"0\";\n }\n}\nprotected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)\n{\n this.TextBox1.Text = TreeView1.SelectedNode.Value.ToString();\n}\n"
},
{
"answer_id": 357247,
"author": "Drell",
"author_id": 41801,
"author_profile": "https://Stackoverflow.com/users/41801",
"pm_score": 1,
"selected": false,
"text": "TreeNode newCNode;\nnewCNode = new TreeNode(\"New Node\");\n\nnewCNode.SelectAction = TreeNodeSelectAction.Select;\n\n//now you can set the .NavigateUrl property to call the same page with some query string parameter to catch in the page_load()\n\nnewCNode.NavigateUrl = \"~/ThisPage.aspx?args=\" + someNodeAction\n\nRootNode.ChildNodes.Add(newCNode);\n"
},
{
"answer_id": 384163,
"author": "BlackMael",
"author_id": 19377,
"author_profile": "https://Stackoverflow.com/users/19377",
"pm_score": 3,
"selected": false,
"text": "Imports System.Web.UI\nImports System.Web\n\n\nPublic Class MyTreeView\n Inherits System.Web.UI.WebControls.TreeView\n\n Public Event SelectedNodeClicked As EventHandler\n\n Private Shared ReadOnly SelectedNodeClickEvent As Object\n\n Private Const CurrentValuePathState As String = \"CurrentValuePath\"\n\n Protected Property CurrentValuePath() As String\n Get\n Return Me.ViewState(CurrentValuePathState)\n End Get\n Set(ByVal value As String)\n Me.ViewState(CurrentValuePathState) = value\n End Set\n End Property\n\n Friend Sub RaiseSelectedNodeClicked()\n\n Me.OnSelectedNodeClicked(EventArgs.Empty)\n\n End Sub\n\n Protected Overridable Sub OnSelectedNodeClicked(ByVal e As EventArgs)\n\n RaiseEvent SelectedNodeClicked(Me, e)\n\n End Sub\n\n Protected Overrides Sub OnSelectedNodeChanged(ByVal e As System.EventArgs)\n\n MyBase.OnSelectedNodeChanged(e)\n\n ' Whenever the Selected Node changed, remember its ValuePath for future reference\n Me.CurrentValuePath = Me.SelectedNode.ValuePath\n\n End Sub\n\n Protected Overrides Sub RaisePostBackEvent(ByVal eventArgument As String)\n\n ' Check if the node that caused the event is the same as the previously selected node\n If Me.SelectedNode IsNot Nothing AndAlso Me.SelectedNode.ValuePath.Equals(Me.CurrentValuePath) Then\n Me.RaiseSelectedNodeClicked()\n End If\n\n MyBase.RaisePostBackEvent(eventArgument)\n\n End Sub\n\nEnd Class\n"
},
{
"answer_id": 4324859,
"author": "Evren",
"author_id": 526612,
"author_profile": "https://Stackoverflow.com/users/526612",
"pm_score": 1,
"selected": false,
"text": "protected void Page_Load(object sender, EventArgs e) \n {\n if (!IsPostBack)\n {\n TreeView1.SelectedNode.Selected = false;\n }\n }\n"
},
{
"answer_id": 12234199,
"author": "Randa Hesham",
"author_id": 1428242,
"author_profile": "https://Stackoverflow.com/users/1428242",
"pm_score": 1,
"selected": false,
"text": "TreeNode node = TreeTypes.FindNode(obj.CustomerTypeId.ToString());\n\n\nTreeTypes.Nodes[TreeTypes.Nodes.IndexOf(node)].Select();\n"
},
{
"answer_id": 27902024,
"author": "MOJTABA GIVI",
"author_id": 2906181,
"author_profile": "https://Stackoverflow.com/users/2906181",
"pm_score": -1,
"selected": false,
"text": " protected void MainTreeView_SelectedNodeChanged(object sender, EventArgs e)\n {\n ClearTreeView();\n MainTreeView.SelectedNode.Text = \"<span class='SelectedTreeNodeStyle'>\" + MainTreeView.SelectedNode.Text + \"</span>\";\n MainTreeView.SelectedNode.Selected = false;\n\n }\n\n public void ClearTreeView()\n {\n for (int i = 0; i < MainTreeView.Nodes.Count; i++)\n {\n for(int j=0;j< MainTreeView.Nodes[i].ChildNodes.Count;j++)\n {\n ClearNodeText(MainTreeView.Nodes[i].ChildNodes[j]);\n }\n ClearNodeText(MainTreeView.Nodes[i]);\n }\n }\n\n public void ClearNodeText(TreeNode tn)\n {\n tn.Text = tn.Text.Replace(\"<span class='SelectedTreeNodeStyle'>\", \"\").Replace(\"</span>\", \"\");\n }\n <style type=\"text/css\">\n .SelectedTreeNodeStyle { font-weight: bold;}\n </style>\n"
},
{
"answer_id": 60446718,
"author": "French Refilou",
"author_id": 12977684,
"author_profile": "https://Stackoverflow.com/users/12977684",
"pm_score": 0,
"selected": false,
"text": "ShowCheckBox SelectedNodeChanged ShowCheckBox Checked ShowCheckBox Checked myTreeView.SelecteNode.Selected = false"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107150",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19377/"
] |
107,154
|
<p>I've just read up on <code>Thread.IsBackground</code> and if I understand it correctly, when it's set to <code>false</code> the Thread is a foreground thread which means it should stay alive until it has finished working even though the app have been exited out. Now I tested this with a winform app and it works as expected but when used with a console app the process doesn't stay alive but exits right away. Does the <code>Thread.IsBackground</code> behave differently from a console app than a winform app?</p>
|
[
{
"answer_id": 107306,
"author": "Adrian Clark",
"author_id": 148,
"author_profile": "https://Stackoverflow.com/users/148",
"pm_score": 3,
"selected": true,
"text": "Thread.IsBackground"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107154",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19490/"
] |
107,160
|
<p>I recently started work on a personal coding project using C++ and KDevelop. Although I started out by just hacking around, I figure it'll be better in the long run if I set up a proper unit test suite before going too much further. I've created a seperate test-runner executable as a sub project, and the tests I've added to it appear to function properly. So far, success.</p>
<p>However, I'd really like to get my unit tests running every time I build, not only when I explicitly run them. This will be especially true as I split up the mess I've made into convenience libraries, each of which will probably have its own test executable. Rather than run them all by hand, I'd like to get them to run as the final step in my build process. I've looked all through the options in the project menu and the automake manager, but I can't figure out how to set this up.</p>
<p>I imagine this could probably be done by editing the makefile by hand. Unfortunately, my makefile-fu is a bit weak, and I'm also afraid that KDevelop might overwrite any changes I make by hand the next time I change something through the IDE. Therefore, if there's an option on how to do this through KDevelop itself, I'd much prefer to go that way.</p>
<p>Does anybody know how I could get KDevelop to run my test executables as part of the build process? Thank you!</p>
<p>(I'm not 100% tied to KDevelop. If KDevelop can't do this, or else if there's an IDE that makes this much easier, I could be convinced to switch.)</p>
|
[
{
"answer_id": 8608452,
"author": "Caruccio",
"author_id": 561948,
"author_profile": "https://Stackoverflow.com/users/561948",
"pm_score": 0,
"selected": false,
"text": "$ cat src/base64.c\n//code to be tested\nint encode64(...) { ... }\n\n#ifdef UNITTEST\n#include <assert.h>\nint main(int argc, char* argv[])\n{\n assert( encode64(...) == 0 );\n return 0;\n}\n#endif //UNITTEST\n/* end file.c */\n\n$ cat src/Makefile.am\n...\ncheck_PROGRAMS = base64-test\nbase64_test_SOURCES = base64.c\nbase64_test_CPPFLAGS = -I../include -DUNITTEST\nTESTS = base64-test\n $ make check\n...\nPASS: base64-test\n==================\nAll 1 tests passed\n==================\n...\n MAKE_UNITTEST(base64.c)\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107160",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19491/"
] |
107,165
|
<p>I'm asking more about what this means to my code. I understand the concepts mathematically, I just have a hard time wrapping my head around what they mean conceptually. For example, if one were to perform an O(1) operation on a data structure, I understand that the number of operations it has to perform won't grow because there are more items. And an O(n) operation would mean that you would perform a set of operations on each element. Could somebody fill in the blanks here?</p>
<ul>
<li>Like what exactly would an O(n^2) operation do?</li>
<li>And what the heck does it mean if an operation is O(n log(n))?</li>
<li>And does somebody have to smoke crack to write an O(x!)?</li>
</ul>
|
[
{
"answer_id": 3461832,
"author": "Albin Sunnanbo",
"author_id": 401728,
"author_profile": "https://Stackoverflow.com/users/401728",
"pm_score": 5,
"selected": false,
"text": "C# JavaScript List<int> numbers = new List<int> {1,2,3,4,5,6,7,12,543,7}; return numbers.First();\n int result = 0;\nforeach (int num in numbers)\n{\n result += num;\n}\nreturn result;\n int result = 0;\nforeach (int num in numbers)\n{\n int index = numbers.Count - 1;\n while (index > 1)\n {\n // yeah, stupid, but couldn't come up with something more useful :-(\n result += numbers[index];\n index /= 2;\n }\n}\nreturn result;\n int result = 0;\nforeach (int outerNum in numbers)\n{\n foreach (int innerNum in numbers)\n {\n result += outerNum * innerNum;\n }\n}\nreturn result;\n const numbers = [ 1, 2, 3, 4, 5, 6, 7, 12, 543, 7 ]; numbers[0];\n let result = 0;\nfor (num of numbers){\n result += num;\n}\n let result = 0;\nfor (num of numbers){\n\n let index = numbers.length - 1;\n while (index > 1){\n // yeah, stupid, but couldn't come up with something more useful :-(\n result += numbers[index];\n index = Math.floor(index/2)\n }\n}\n let result = 0;\nfor (outerNum of numbers){\n for (innerNum of numbers){\n result += outerNum * innerNum;\n }\n}\n"
},
{
"answer_id": 30371967,
"author": "Khaled.K",
"author_id": 2128327,
"author_profile": "https://Stackoverflow.com/users/2128327",
"pm_score": 0,
"selected": false,
"text": "O(n^2) n n(n-1) n^2 O(n log(n)) n n n * log n to the base 10 O(x!) x 1 2 (x-1) x number of children = depth 1 * 2 * 3 * .. * x"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107165",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2147/"
] |
107,196
|
<p>When I do a clean build my C# project, the produced dll is different then the previously built one (which I saved separately). No code changes were made, just clean and rebuild. </p>
<p>Diff shows some bytes in the DLL have changes -- few near the beginning and few near the end, but I can't figure out what these represent. Does anybody have insights on why this is happening and how to prevent it? </p>
<p>This is using Visual Studio 2005 / WinForms.</p>
<p><strong>Update:</strong> Not using automatic version incrementing, or signing the assembly. If it's a timestamp of some sort, how to I prevent VS from writing it? </p>
<p><strong>Update:</strong> After looking in Ildasm/diff, it seems like the following items are different:</p>
<ul>
<li>Two bytes in PE header at the start of the file.</li>
<li><PrivateImplementationDetails>{<em>guid</em>} section </li>
<li>Cryptic part of the string table near the end (wonder why, I did not change the strings)</li>
<li>Parts of assembly info at the end of file.</li>
</ul>
<p>No idea how to eliminate any of these, if at all possible...</p>
|
[
{
"answer_id": 107448,
"author": "Alex Lyman",
"author_id": 5897,
"author_profile": "https://Stackoverflow.com/users/5897",
"pm_score": 5,
"selected": true,
"text": "View > MetaInfo > Raw:Header,Schema,Rows // important, otherwise you get very basic info from the next step\n\nView > MetaInfo > Show!\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107196",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/838/"
] |
107,243
|
<p>I was reading Andrew Kennedy's blog post series on <a href="http://blogs.msdn.com/andrewkennedy/archive/2008/08/29/units-of-measure-in-f-part-one-introducing-units.aspx" rel="noreferrer">units of measurement in F#</a> and it makes a lot of sense in a lot of cases. Are there any other languages that have such a system?</p>
<p>Edit: To be more clear, I mean the flexible units of measurement system where you can define your own arbitrarily.</p>
|
[
{
"answer_id": 107250,
"author": "Alex M",
"author_id": 9652,
"author_profile": "https://Stackoverflow.com/users/9652",
"pm_score": 2,
"selected": false,
"text": "RPL 40_gal 5_l +"
},
{
"answer_id": 107287,
"author": "Eevee",
"author_id": 17875,
"author_profile": "https://Stackoverflow.com/users/17875",
"pm_score": 5,
"selected": true,
"text": "54_kg * (_c^2) __repr__"
},
{
"answer_id": 5230390,
"author": "NN_",
"author_id": 558098,
"author_profile": "https://Stackoverflow.com/users/558098",
"pm_score": 2,
"selected": false,
"text": "def m3 = 1 g;\ndef m4 = Si.Mass(m1);\n\nWriteLine($\"Mass in SI: $m4, in CGS: $m3\");\n\ndef x1 = Si.Area(1 cm * 10 m);\n\nWriteLine($\"Area of 1 cm * 10 m = $x1 m\");\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107243",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4977/"
] |
107,292
|
<p>We are starting a new SOA project with a lot of shared .net assemblies. The code for these assemblies will be stored in SVN.</p>
<p>In development phase, we would like to be able to code these assemblies as an entire solution with as little SVN 'friction' as possible. </p>
<p>When the project enters more of a maintenance mode, the assemblies will be maintained on an individual level.</p>
<p>Without making Branching, Tagging, and Automated Builds a maintenance nightmare, what's the best way to organize these libraries in SVN that also works well with the VS 2008 IDE?</p>
<p>Do you setup Trunk/Branches/Tags at each library level and try to spaghetti it all together somehow at compile time, or is it better to keep it all as one big project with code replicated here and there for simplicity? Is there a solution using externs?</p>
|
[
{
"answer_id": 107525,
"author": "Craig Trader",
"author_id": 12895,
"author_profile": "https://Stackoverflow.com/users/12895",
"pm_score": 4,
"selected": true,
"text": "/svn/tools/\n vendor1/\n too11/\n 1.0/\n 1.1/\n latest = a copy of vendor1/tool1/1.1\n tool2/\n 1.0/\n 1.5/\n latest = a copy of vendor1/tool2/1.5\n vendor2/\n foo/\n 1.0.0/\n 1.1.0/\n 1.2.0/\n latest = a copy of vendor2/foo/1.2.0\n /svn/\n branches/\n tags/\n trunk/\n foo/\n source/\n tools/\n publish/\n foo-build.xml (for NAnt)\n foo.build (for MSBuild)\n svn import publish /svn/tools/vendor2/foo/1.2.3\nsvn delete /svn/tools/vendor2/foo/latest\nsvn copy /svn/tools/vendor2/foo/1.2.3 /svn/tools/vendor2/foo/latest\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107292",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6354/"
] |
107,294
|
<p>I understand the overall meaning of pointers and references(or at least I think i do), I also understand that when I use <b>new</b> I am dynamically allocating memory.</p>
<p>My question is the following:</p>
<p>If i were to use <code>cout << &p</code>, it would display the "virtual memory location" of <code>p</code>.
Is there a way in which I could manipulate this "virtual memory location?"</p>
<p>For example, the following code shows an array of <code>int</code>s.</p>
<p>If I wanted to show the value of <code>p[1]</code> and I knew the "virtual memory location" of <code>p</code>, could I somehow do "<code>&p + 1</code>" and obtain the value of <code>p[1]</code> with <code>cout << *p</code>, which will now point to the second element in the array?</p>
<pre><code>int *p;
p = new int[3];
p[0] = 13;
p[1] = 54;
p[2] = 42;
</code></pre>
|
[
{
"answer_id": 107301,
"author": "KTC",
"author_id": 12868,
"author_profile": "https://Stackoverflow.com/users/12868",
"pm_score": 4,
"selected": true,
"text": "int *p = new int[3];\np[0] = 13;\np[1] = 54;\np[2] = 42;\n\ncout << *p << ' ' << *(p+1) << ' ' << *(p+2);\n"
},
{
"answer_id": 107313,
"author": "freespace",
"author_id": 8297,
"author_profile": "https://Stackoverflow.com/users/8297",
"pm_score": 2,
"selected": false,
"text": "&p p &p+1 int* p=p+1; /* or ++p or p++ */\n cout << *p;\n p &p p &p int **q = &p; /* q now points to p */\n*q = *q+1;\ncout << *p;\n"
},
{
"answer_id": 107316,
"author": "Guy",
"author_id": 1463,
"author_profile": "https://Stackoverflow.com/users/1463",
"pm_score": 2,
"selected": false,
"text": "cout << *(p+1)\n cout << *(++p)\n"
},
{
"answer_id": 107351,
"author": "Adam Pierce",
"author_id": 5324,
"author_profile": "https://Stackoverflow.com/users/5324",
"pm_score": 2,
"selected": false,
"text": "&p[1]\n"
},
{
"answer_id": 107461,
"author": "Kevin Little",
"author_id": 14028,
"author_profile": "https://Stackoverflow.com/users/14028",
"pm_score": 1,
"selected": false,
"text": "\"int *\" \"double *\" \"struct foo *\" \"struct foo\" *(p+10)"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107294",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17162/"
] |
107,314
|
<p>We've been using selenium with great success to handle high-level website testing (in addition to extensive python doctests at a module level). However now we're using extjs for a lot of pages and its proving difficult to incorporate Selenium tests for the complex components like grids. </p>
<p>Has anyone had success writing automated tests for extjs-based web pages? Lots of googling finds people with similar problems, but few answers. Thanks!</p>
|
[
{
"answer_id": 185372,
"author": "Marko Dumic",
"author_id": 5817,
"author_profile": "https://Stackoverflow.com/users/5817",
"pm_score": 2,
"selected": false,
"text": "/**\n * Javascript needed to execute in order to select row in the grid\n * \n * @param gridId Grid id\n * @param rowIndex Index of the row to select\n * @return Javascript to select row\n */\npublic static String selectGridRow(String gridId, int rowIndex) {\n return \"Ext.getCmp('\" + gridId + \"').getSelectionModel().selectRow(\" + rowIndex + \", true)\";\n}\n selenium.runScript( SeleniumExtJsUtils.selectGridRow(\"<myGridId>\", 5) );\n"
},
{
"answer_id": 219506,
"author": "Ates Goral",
"author_id": 23501,
"author_profile": "https://Stackoverflow.com/users/23501",
"pm_score": 8,
"selected": true,
"text": "<select> var combo = Ext.getCmp('genderComboBox'); // returns the ComboBox components\ncombo.setValue('female'); // set the value\ncombo.fireEvent('select'); // because setValue() doesn't trigger the event\n runScript with (Ext.getCmp('genderComboBox')) { setValue('female'); fireEvent('select'); }\n Command: waitForElementNotPresent\nTarget: css=div:contains('Loading...')\n pause Command: waitForElementPresent\nTarget: css=span:contains('Do the funky thing')\nCommand: click\nTarget: css=span:contains('Do the funky thing')\n click mouseDown Command: mouseDownAt\nTarget: css=.x-tab-strip-text:contains('Options')\nValue: 0,0\n validationDelay validateOnDelay Command: keyUp\nTarget: someTextArea\nValue: x\nCommand: pause\nTarget: 500\n Command: runScript\nTarget: someComponent.nameTextField.fireEvent(\"blur\")\n Command: verifyElementNotPresent \nTarget: //*[@id=\"nameTextField\"]/../*[@class=\"x-form-invalid-msg\" and not(contains(@style, \"display: none\"))]\n\nCommand: verifyElementPresent \nTarget: //*[@id=\"nameTextField\"]/../*[@class=\"x-form-invalid-msg\" and not(contains(@style, \"display: none\"))]\n Command: runScript\nTarget: with (Ext.getCmp('genderComboBox')) { setValue('female'); fireEvent('select'); }\n"
},
{
"answer_id": 441741,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": " sub get_grid_row {\n my ($browser, $grid, $row) = @_;\n\n\n my $script = \"var doc = this.browserbot.getCurrentWindow().document;\\n\" .\n \"var grid = doc.getElementById('$grid');\\n\" .\n \"var table = grid.getElementsByTagName('table');\\n\" .\n \"var result = '';\\n\" .\n \"var row = 0;\\n\" . \n \"for (var i = 0; i < table.length; i++) {\\n\" .\n \" if (table[i].className == 'x-grid3-row-table') {\\n\".\n \" row++;\\n\" . \n \" if (row == $row) {\\n\" .\n \" var cols_len = table[i].rows[0].cells.length;\\n\" .\n \" for (var j = 0; j < cols_len; j++) {\\n\" .\n \" var cell = table[i].rows[0].cells[j];\\n\" .\n \" if (result.length == 0) {\\n\" .\n \" result = getText(cell);\\n\" .\n \" } else { \\n\" .\n \" result += '|' + getText(cell);\\n\" .\n \" }\\n\" .\n \" }\\n\" .\n \" }\\n\" .\n \" }\\n\" .\n \"}\\n\" .\n \"result;\\n\";\n\n my $result = $browser->get_eval($script);\n my @res = split('\\|', $result);\n return @res;\n }\n"
},
{
"answer_id": 1471119,
"author": "Master-Test",
"author_id": 178398,
"author_profile": "https://Stackoverflow.com/users/178398",
"pm_score": 2,
"selected": false,
"text": "not(contains(@style, \"display: none\") visible_clause = \"not(ancestor::*[contains(@style,'display: none')\" +\n \" or contains(@style, 'visibility: hidden') \" + \n \" or contains(@class,'x-hide-display')])\"\n\nhidden_clause = \"parent::*[contains(@style,'display: none')\" + \n \" or contains(@style, 'visibility: hidden')\" + \n \" or contains(@class,'x-hide-display')]\"\n"
},
{
"answer_id": 2542989,
"author": "Chun",
"author_id": 292829,
"author_profile": "https://Stackoverflow.com/users/292829",
"pm_score": 1,
"selected": false,
"text": "String fullXpath = \"xpath=//div[@id='mainDiv']//div[contains(@class,'x-grid-row')]//table/tbody/tr[1]/td[1]//button\"\n\nselenium.click(fullXpath);\n"
},
{
"answer_id": 19590566,
"author": "Brian Wendt",
"author_id": 2308628,
"author_profile": "https://Stackoverflow.com/users/2308628",
"pm_score": 2,
"selected": false,
"text": "Ext.AbstractComponent onBoxReady testIdAttr itemId Testing.overrides.AbstractComponent application.js requires /**\n * Overrides the Ext.AbstracComponent's onBoxReady\n * method to add custom data attributes to the\n * component's dom structure.\n *\n * @author Brian Wendt\n */\nExt.define('Testing.overrides.AbstractComponent', {\n override: 'Ext.AbstractComponent',\n\n\n onBoxReady: function () {\n var me = this,\n el = me.getEl();\n\n\n if (el && el.dom && me.itemId) {\n el.dom.setAttribute(me.testIdAttr || 'data-selenium-id', me.itemId);\n }\n\n\n me.callOverridden(arguments);\n }\n});\n"
},
{
"answer_id": 19802364,
"author": "John V",
"author_id": 2958562,
"author_profile": "https://Stackoverflow.com/users/2958562",
"pm_score": 2,
"selected": false,
"text": "findExtJsGridRow(\"Foo\");\n extjsgridrow by text \"Foo\"\n"
},
{
"answer_id": 24670268,
"author": "olyv",
"author_id": 2504101,
"author_profile": "https://Stackoverflow.com/users/2504101",
"pm_score": 1,
"selected": false,
"text": "@for <label id=\"dynamic_id_label\" class=\"TextboxLabel\" for=\"textField_which_I_am_lloking_for\">\nName Of Needed Label\n<label/>\n //input[@id=(//label[contains(text(),'Name Of Needed Label')]/@for)] @for"
},
{
"answer_id": 38885163,
"author": "bertanasco",
"author_id": 890222,
"author_profile": "https://Stackoverflow.com/users/890222",
"pm_score": 2,
"selected": false,
"text": "public static boolean waitUntilDOMIsReady(WebDriver driver) {\n def maxSeconds = DEFAULT_WAIT_SECONDS * 10\n for (count in 1..maxSeconds) {\n Thread.sleep(100)\n def ready = isDOMReady(driver);\n if (ready) {\n break;\n }\n }\n}\n\npublic static boolean isDOMReady(WebDriver driver){\n return driver.executeScript(\"return document.readyState\");\n}\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107314",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19506/"
] |
107,390
|
<p>They both seem to be sending data to the server inside the body, so what makes them different?</p>
|
[
{
"answer_id": 107415,
"author": "Jonathan Arkell",
"author_id": 11052,
"author_profile": "https://Stackoverflow.com/users/11052",
"pm_score": 8,
"selected": false,
"text": "PUT POST"
},
{
"answer_id": 107450,
"author": "Brian R. Bondy",
"author_id": 3153,
"author_profile": "https://Stackoverflow.com/users/3153",
"pm_score": 11,
"selected": true,
"text": "created replaced"
},
{
"answer_id": 107542,
"author": "bhollis",
"author_id": 11284,
"author_profile": "https://Stackoverflow.com/users/11284",
"pm_score": 7,
"selected": false,
"text": "POST /books /books/5 PUT /books/5 POST PUT PUT POST POST"
},
{
"answer_id": 107599,
"author": "Jason Morrison",
"author_id": 15098,
"author_profile": "https://Stackoverflow.com/users/15098",
"pm_score": 4,
"selected": false,
"text": "POST PUT PUT, DELETE,"
},
{
"answer_id": 22879514,
"author": "Najeebul Hasan",
"author_id": 3500894,
"author_profile": "https://Stackoverflow.com/users/3500894",
"pm_score": 4,
"selected": false,
"text": "obj.set_attribute(value) # A POST request.\n obj.attribute = value # A PUT request.\n"
},
{
"answer_id": 43252771,
"author": "Long Nguyen",
"author_id": 4642316,
"author_profile": "https://Stackoverflow.com/users/4642316",
"pm_score": 5,
"selected": false,
"text": "REST model POST POST PUT PUT PUT POST PUT or PATCH PUT PATCH PUT PUT POST and PATCH"
},
{
"answer_id": 49181516,
"author": "Jonatan Dragon",
"author_id": 1319086,
"author_profile": "https://Stackoverflow.com/users/1319086",
"pm_score": 7,
"selected": false,
"text": "https://"
},
{
"answer_id": 52936441,
"author": "irfan",
"author_id": 5015695,
"author_profile": "https://Stackoverflow.com/users/5015695",
"pm_score": 3,
"selected": false,
"text": "GET POST PUT PATCH DELETE TRACE OPTIONS HEAD CONNECT"
},
{
"answer_id": 55382661,
"author": "Marinos An",
"author_id": 1555615,
"author_profile": "https://Stackoverflow.com/users/1555615",
"pm_score": 3,
"selected": false,
"text": "POST PUT PUT attackersite.com admin target.site.com attackersite.com attackersite.com target.site.com PUT <form> <!--deletes user with id 5-->\n<form id=\"myform\" method=\"post\" action=\"http://target.site.com/deleteUser\" >\n <input type=\"hidden\" name=\"userId\" value=\"5\">\n</form>\n<script>document.createElement('form').submit.call(document.getElementById('myform'));</script>\n target.site.com PUT PUT deleteUser //deletes user with id 5\nvar xhr = new XMLHttpRequest();\nxhr.open(\"POST\", \"http://target.site.com/deleteUser\");\nxhr.withCredentials=true;\nxhr.send([\"userId=5\"]);\n"
},
{
"answer_id": 56525720,
"author": "Melad Basilius",
"author_id": 1973933,
"author_profile": "https://Stackoverflow.com/users/1973933",
"pm_score": 2,
"selected": false,
"text": "POST URI EX \n REQUEST : POST ..../books\n {\n \"book\":\"booName\",\n \"author\":\"authorName\"\n }\n URI Response ...THE-NEW-RESOURCE-URI/books/5\n PUT REQUEST : PUT ..../books/5\n{\n\"book\":\"booName\",\n\"author\":\"authorName\"\n}\n PUT POST POST PUT POST PUT"
},
{
"answer_id": 60279749,
"author": "Dzenis H.",
"author_id": 8146571,
"author_profile": "https://Stackoverflow.com/users/8146571",
"pm_score": 4,
"selected": false,
"text": "PUT PUT PUT /resources/:resourceId PATCH POST POST => /resources PUT POST GET GET POST PUT PATCH DELETE"
},
{
"answer_id": 65144867,
"author": "Maggyero",
"author_id": 2326961,
"author_profile": "https://Stackoverflow.com/users/2326961",
"pm_score": 1,
"selected": false,
"text": "PUT POST POST PUT POST PUT POST PUT PUT PUT POST POST PUT GET HEAD DELETE CONNECT OPTIONS TRACE POST GET HEAD OPTIONS TRACE GET HEAD PUT DELETE OPTIONS TRACE GET HEAD POST GET PUT POST POST"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107390",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10708/"
] |
107,404
|
<p>What are the down sides of using a composite/compound primary key?</p>
|
[
{
"answer_id": 877556,
"author": "onedaywhen",
"author_id": 15354,
"author_profile": "https://Stackoverflow.com/users/15354",
"pm_score": 1,
"selected": false,
"text": "PRIMARY KEY PRIMARY KEY PRIMARY KEY PRIMARY KEY PRIMARY KEY PRIMARY KEY PRIMARY KEY"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107404",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6354/"
] |
107,405
|
<p>What I'm trying to do here is get the headers of a given URL so I can determine the MIME type. I want to be able to see if <code>http://somedomain/foo/</code> will return an HTML document or a JPEG image for example. Thus, I need to figure out how to send a HEAD request so that I can read the MIME type without having to download the content. Does anyone know of an easy way of doing this?</p>
|
[
{
"answer_id": 107427,
"author": "Eevee",
"author_id": 17875,
"author_profile": "https://Stackoverflow.com/users/17875",
"pm_score": 8,
"selected": true,
"text": ">>> import httplib\n>>> conn = httplib.HTTPConnection(\"www.google.com\")\n>>> conn.request(\"HEAD\", \"/index.html\")\n>>> res = conn.getresponse()\n>>> print res.status, res.reason\n200 OK\n>>> print res.getheaders()\n[('content-length', '0'), ('expires', '-1'), ('server', 'gws'), ('cache-control', 'private, max-age=0'), ('date', 'Sat, 20 Sep 2008 06:43:36 GMT'), ('content-type', 'text/html; charset=ISO-8859-1')]\n getheader(name)"
},
{
"answer_id": 358075,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": -1,
"selected": false,
"text": ">>> import urllib\n>>> f = urllib.urlopen('http://google.com')\n>>> f.info().gettype()\n'text/html'\n"
},
{
"answer_id": 2070916,
"author": "doshea",
"author_id": 251448,
"author_profile": "https://Stackoverflow.com/users/251448",
"pm_score": 7,
"selected": false,
"text": ">>> import urllib2\n>>> class HeadRequest(urllib2.Request):\n... def get_method(self):\n... return \"HEAD\"\n... \n>>> response = urllib2.urlopen(HeadRequest(\"http://google.com/index.html\"))\n >>> print response.geturl()\nhttp://www.google.com.au/index.html\n"
},
{
"answer_id": 4421712,
"author": "Paweł Prażak",
"author_id": 539481,
"author_profile": "https://Stackoverflow.com/users/539481",
"pm_score": 4,
"selected": false,
"text": "import urllib2\nrequest = urllib2.Request('http://localhost:8080')\nrequest.get_method = lambda : 'HEAD'\n\nresponse = urllib2.urlopen(request)\nresponse.info().gettype()\n import httplib2\nh = httplib2.Http()\nresp = h.request(\"http://www.google.com\", 'HEAD')\nassert resp[0]['status'] == 200\nassert resp[0]['content-type'] == 'text/html'\n...\n"
},
{
"answer_id": 9227931,
"author": "Pranay Agarwal",
"author_id": 1175514,
"author_profile": "https://Stackoverflow.com/users/1175514",
"pm_score": 2,
"selected": false,
"text": "import httplib\nimport urlparse\n\ndef unshorten_url(url):\n parsed = urlparse.urlparse(url)\n h = httplib.HTTPConnection(parsed.netloc)\n h.request('HEAD', parsed.path)\n response = h.getresponse()\n if response.status/100 == 3 and response.getheader('Location'):\n return response.getheader('Location')\n else:\n return url\n"
},
{
"answer_id": 12997216,
"author": "K Z",
"author_id": 853611,
"author_profile": "https://Stackoverflow.com/users/853611",
"pm_score": 6,
"selected": false,
"text": "Requests import requests\n\nresp = requests.head(\"http://www.google.com\")\nprint resp.status_code, resp.text, resp.headers\n"
},
{
"answer_id": 15420705,
"author": "Octavian Damiean",
"author_id": 418183,
"author_profile": "https://Stackoverflow.com/users/418183",
"pm_score": 4,
"selected": false,
"text": "from http.client import HTTPConnection\n\nconn = HTTPConnection('www.google.com')\nconn.request('HEAD', '/index.html')\nres = conn.getresponse()\n\nprint(res.status, res.reason)\n"
},
{
"answer_id": 16960321,
"author": "estani",
"author_id": 1182464,
"author_profile": "https://Stackoverflow.com/users/1182464",
"pm_score": 0,
"selected": false,
"text": "import urllib2\nimport types\n\nrequest = urllib2.Request('http://localhost:8080')\nrequest.get_method = types.MethodType(lambda self: 'HEAD', request, request.__class__)\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107405",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10708/"
] |
107,413
|
<p>I have a 3d object that I wish to be able to rotate around in 3d. The easiest way is to directly translate X and Y mouse motion to rotation about the Y and X axes, but if there is some rotation along both axes, the way the model rotates becomes highly counterintuitive (i.e. if you flip the object 180 degrees about one axis, your motion along the other axis is reversed).</p>
<p>I could simply do the above method, but instead of storing the amount to rotate about the two axes, I could store the full rotation matrix and just further rotate it along the same axes for each mouse drag, but I'm concerned that that would quickly have precision issues.</p>
|
[
{
"answer_id": 107510,
"author": "Lloyd",
"author_id": 9952,
"author_profile": "https://Stackoverflow.com/users/9952",
"pm_score": 3,
"selected": false,
"text": "q.x = sin(0.5*angle) * axis.x;\nq.y = sin(0.5*angle) * axis.y;\nq.z = sin(0.5*angle) * axis.z;\nq.w = cos(0.5*angle);\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107413",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
107,414
|
<p>As a base SAS programmer, you know the drill:</p>
<p>You submit your SAS code, which contains an unbalanced quote, so now you've got not only and unclosed quote, but also unclosed comments, macro function definitions, and a missing run; or quit; statement.</p>
<p>What's your best trick for not having those unbalanced quotes bother you?</p>
|
[
{
"answer_id": 107443,
"author": "Martin Bøgelund",
"author_id": 18968,
"author_profile": "https://Stackoverflow.com/users/18968",
"pm_score": 3,
"selected": false,
"text": "*); */; /*’*/ /*”*/; %mend;\n"
},
{
"answer_id": 536803,
"author": "AFHood",
"author_id": 65050,
"author_profile": "https://Stackoverflow.com/users/65050",
"pm_score": 3,
"selected": false,
"text": " ;*';*\";*/;quit;run;\n ODS _ALL_ CLOSE;\n QUIT; RUN;\n"
},
{
"answer_id": 557654,
"author": "robmandu",
"author_id": 67082,
"author_profile": "https://Stackoverflow.com/users/67082",
"pm_score": 0,
"selected": false,
"text": "ODS _ALL_ CLOSE;"
},
{
"answer_id": 573419,
"author": "Chang Chung",
"author_id": 69117,
"author_profile": "https://Stackoverflow.com/users/69117",
"pm_score": 4,
"selected": true,
"text": "*';*\";*/;run;\n ods _all_ close; ods results; ods results on; %put sysvlong=&sysvlong sysscpl=&sysscpl;\n/* sysvlong=9.02.01M0P020508 sysscpl=X64_VSPRO */\n\nods _all_ close;\nproc print data=sashelp.class;\nrun;\n/* on log\nWARNING: No output destinations active.\n*/\n\nods results on;\nproc print data=sashelp.class;\nrun;\n/* on log\nWARNING: No output destinations active.\n*/\n"
},
{
"answer_id": 59709280,
"author": "StatsStudent",
"author_id": 4615298,
"author_profile": "https://Stackoverflow.com/users/4615298",
"pm_score": 1,
"selected": false,
"text": "; *'; *\"; */;\nODS _ALL_ CLOSE;\nquit; run; %MEND;\ndata _NULL_; putlog \"DONE\"; run;\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107414",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18968/"
] |
107,456
|
<p>So I'm looking at writing an iPhone application that shows things on a map. What frameworks/methodologies are out there for doing this?</p>
<p>Searching around on Google, I could only find this one:
<a href="http://code.google.com/p/iphone-google-maps-component/" rel="nofollow noreferrer">http://code.google.com/p/iphone-google-maps-component/</a></p>
<p>Which according to the issues list is slow, and stops working after a while. Does anyone know of something better, or have any experience with the library above?</p>
|
[
{
"answer_id": 3759873,
"author": "sanjay",
"author_id": 451368,
"author_profile": "https://Stackoverflow.com/users/451368",
"pm_score": 0,
"selected": false,
"text": "[[uiapplication sharedapplication]openurl:@\"www.maps.google.com];"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107456",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6044/"
] |
107,464
|
<p>There have been some questions about whether or not JavaScript is an object-oriented language. Even a statement, "just because a language has objects doesn't make it OO."</p>
<p>Is JavaScript an object-oriented language?</p>
|
[
{
"answer_id": 108773,
"author": "AnthonyWJones",
"author_id": 17516,
"author_profile": "https://Stackoverflow.com/users/17516",
"pm_score": 7,
"selected": true,
"text": "function MyClass() {\n var _value = 1;\n this.getValue = function() { return _value; }\n}\n function MyClass() {\n var _value = 1;\n}\nMyClass.prototype.getValue = function() { return _value; }\n this"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107464",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1538/"
] |
107,531
|
<p>I would like to create an XML-based website. I want to use XML files as datasources since it is a kind of online directory site. Can someone please give me a starting point? Are there any good online resources that I can refer to? I am pretty comfortable with ASP and JavaScript.</p>
|
[
{
"answer_id": 108920,
"author": "Svante Svenson",
"author_id": 19707,
"author_profile": "https://Stackoverflow.com/users/19707",
"pm_score": 0,
"selected": false,
"text": "<data>\n <item visible=\"no\">\n <title>Invisible item 1</title>\n </item>\n <item visible=\"yes\">\n <title>Visible item 1</title>\n </item>\n <item visible=\"yes\">\n <title>Visible item 2</title>\n </item>\n</data>\n Dim oXMLDoc\nDim oNode\nSet oXMLDoc = CreateObject(\"MSXML.DOMDocument\")\noXMLDoc.Load Server.MapPath(\"../_private/data.xml\")\nSet oNode = oXMLDoc.SelectSingleNode(\"data/item\")\nDo Until oNode Is Nothing\n If oNode.GetNamedAttribute(\"visible\") = \"yes\" Then\n Response.Write \"Title: \" & oNode.SelectSingleNode(\"title\").Text & \"<br />\" & vbCrLf\n End If\n Set oNode = oNode.nextSibling\nLoop\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107531",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19536/"
] |
107,546
|
<p>I need to implement auto-capitalization inside of a Telerik RadEditor control on an ASPX page as a user types.</p>
<p>This can be an IE specific solution (IE6+).</p>
<p>I currently capture every keystroke (down/up) as the user types to support a separate feature called "macros" that are essentially short keywords that expand into formatted text. i.e. the macro "so" could auto expand upon hitting spacebar to "stackoverflow".</p>
<p>That said, I have access to the keyCode information, as well I am using the TextRange methods to select a word ("so") and expanding it to "stackoverflow". Thus, I have some semblence of context.</p>
<p>However, I need to check this context to know whether I should auto-capitalize. This also needs to work regardless of whether a macro is involved.</p>
<p>Since I'm monitoring keystrokes for the macros, should I just monitor for punctuation (it's more than just periods that signal a capital letter) and auto-cap the next letter typed, or should I use TextRange and analyze context?</p>
|
[
{
"answer_id": 107662,
"author": "Andrew Hedges",
"author_id": 11577,
"author_profile": "https://Stackoverflow.com/users/11577",
"pm_score": 3,
"selected": true,
"text": "function toTitleCase(str) {\n return str.replace(/([\\w&`'‘’\"“.@:\\/\\{\\(\\[<>_]+-? *)/g, function(match, p1, index, title){ // ' fix syntax highlighting\n if (index > 0 && title.charAt(index - 2) != \":\" && \n match.search(/^(a(nd?|s|t)?|b(ut|y)|en|for|i[fn]|o[fnr]|t(he|o)|vs?\\.?|via)[ -]/i) > -1)\n return match.toLowerCase();\n if (title.substring(index - 1, index + 1).search(/['\"_{([]/) > -1)\n return match.charAt(0) + match.charAt(1).toUpperCase() + match.substr(2);\n if (match.substr(1).search(/[A-Z]+|&|[\\w]+[._][\\w]+/) > -1 ||\n title.substring(index - 1, index + 1).search(/[\\])}]/) > -1)\n return match;\n return match.charAt(0).toUpperCase() + match.substr(1);\n });\n}\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107546",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2742/"
] |
107,549
|
<p>When we compile a dll using __stdcall inside visual studio 2008 the compiled function names inside the dll are.</p>
<p>FunctionName</p>
<p>Though when we compile the same dll using GCC using wx-dev-cpp GCC appends the number of paramers the function has, so the name of the function using Dependency walker looks like.</p>
<p>FunctionName@numberOfParameters or == FunctionName@8</p>
<p>How do you tell GCC compiler to remove @nn from exported symbols in the dll?</p>
|
[
{
"answer_id": 107564,
"author": "Roger Lipscombe",
"author_id": 8446,
"author_profile": "https://Stackoverflow.com/users/8446",
"pm_score": 4,
"selected": true,
"text": "void __stdcall Foo(int a, int b);\n"
},
{
"answer_id": 254789,
"author": "CesarB",
"author_id": 28258,
"author_profile": "https://Stackoverflow.com/users/28258",
"pm_score": 3,
"selected": false,
"text": "-Wl,--kill-at --kill-at"
},
{
"answer_id": 24137148,
"author": "Matthias",
"author_id": 519852,
"author_profile": "https://Stackoverflow.com/users/519852",
"pm_score": 2,
"selected": false,
"text": "-Wl,--add-stdcall-alias"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107549",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17382/"
] |
107,562
|
<p>I'm trying to install faac and am running into errors. Here are the errors I get when trying to build it:</p>
<hr>
<pre><code>[root@test faac]# ./bootstrap
configure.in:11: warning: underquoted definition of MY_DEFINE
run info '(automake)Extending aclocal'
or see http://sources.redhat.com/automake/automake.html#Extending-aclocal
aclocal:configure.in:17: warning: macro `AM_PROG_LIBTOOL' not found in library
common/mp4v2/Makefile.am:5: Libtool library used but `LIBTOOL' is undefined
common/mp4v2/Makefile.am:5:
common/mp4v2/Makefile.am:5: The usual way to define `LIBTOOL' is to add `AC_PROG_LIBTOOL'
common/mp4v2/Makefile.am:5: to `configure.in' and run `aclocal' and `autoconf' again.
libfaac/Makefile.am:1: Libtool library used but `LIBTOOL' is undefined
libfaac/Makefile.am:1:
libfaac/Makefile.am:1: The usual way to define `LIBTOOL' is to add `AC_PROG_LIBTOOL'
libfaac/Makefile.am:1: to `configure.in' and run `aclocal' and `autoconf' again.
configure.in:17: error: possibly undefined macro: AM_PROG_LIBTOOL
If this token and others are legitimate, please use m4_pattern_allow.
See the Autoconf documentation.
</code></pre>
<hr>
<p>Does anyone know what this means? I was unable to find anything about this so I figured I'd ask you guys. Thank you for your help.</p>
<p>EDIT:
Here's my versions of linux, libtool, automake and autoconf:</p>
<pre><code>[root@test faac]# libtool --version
ltmain.sh (GNU libtool) 2.2
Written by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
[root@test faac]# autoconf --version
autoconf (GNU Autoconf) 2.59
Written by David J. MacKenzie and Akim Demaille.
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
[root@test faac]# automake --version
automake (GNU automake) 1.9.2
Written by Tom Tromey <tromey@redhat.com>.
Copyright 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
[root@test faac]# cat /etc/redhat-release
Red Hat Enterprise Linux WS release 4 (Nahant)
</code></pre>
|
[
{
"answer_id": 107592,
"author": "Douglas Leeder",
"author_id": 3978,
"author_profile": "https://Stackoverflow.com/users/3978",
"pm_score": 2,
"selected": false,
"text": "$ ./bootstrap \nconfigure.in:11: warning: underquoted definition of MY_DEFINE\nconfigure.in:11: run info '(automake)Extending aclocal'\nconfigure.in:11: or see http://sources.redhat.com/automake/automake.html#Extending-aclocal\nconfigure.in:4: installing `./install-sh'\nconfigure.in:4: installing `./missing'\ncommon/mp4v2/Makefile.am: installing `./depcomp'\n\n$ libtool --version\nltmain.sh (GNU libtool) 1.5.26 Debian 1.5.26-1ubuntu1 (1.1220.2.493 2008/02/01 16:58:18)\n\nCopyright (C) 2008 Free Software Foundation, Inc.\nThis is free software; see the source for copying conditions. There is NO\nwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n$ autoconf --version\nautoconf (GNU Autoconf) 2.61\nCopyright (C) 2006 Free Software Foundation, Inc.\nThis is free software. You may redistribute copies of it under the terms of\nthe GNU General Public License <http://www.gnu.org/licenses/gpl.html>.\nThere is NO WARRANTY, to the extent permitted by law.\n\nWritten by David J. MacKenzie and Akim Demaille.\n\n$ automake --version\nautomake (GNU automake) 1.10.1\nCopyright (C) 2008 Free Software Foundation, Inc.\nLicense GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl.html>\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law.\n\nWritten by Tom Tromey <tromey@redhat.com>\n and Alexandre Duret-Lutz <adl@gnu.org>.\n"
},
{
"answer_id": 107607,
"author": "Douglas Leeder",
"author_id": 3978,
"author_profile": "https://Stackoverflow.com/users/3978",
"pm_score": 0,
"selected": false,
"text": "which libtool\nwhich automake\nwhich autoconf\n"
},
{
"answer_id": 188741,
"author": "jvasak",
"author_id": 5840,
"author_profile": "https://Stackoverflow.com/users/5840",
"pm_score": 0,
"selected": false,
"text": "libtool.m4 AM_PROG_LIBTOOL /usr/share/aclocal/"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107562",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
107,566
|
<p>My last couple of projects have involved websites that sell a product/service and require a 'checkout' process in which users put in their credit card information and such. Obviously we got SSL certificates for the security of it plus giving peace of mind to the customers. I am, however, a little clueless as to the subtleties of it, and most importantly as to which parts of the website should 'use' the certificate.</p>
<p>For example, I've been to websites where the moment you hit the homepage you are put in https - mostly banking sites - and then there are websites where you are only put in https when you are finally checking out. Is it overkill to make the entire website run through https if it doesn't deal with something on the level of banking? Should I only make the checkout page https? What is the performance hit on going all out?</p>
|
[
{
"answer_id": 7468106,
"author": "Blans",
"author_id": 952203,
"author_profile": "https://Stackoverflow.com/users/952203",
"pm_score": 0,
"selected": false,
"text": "https"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107566",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16417/"
] |
107,598
|
<p>Given an arbitrary sequence of points in space, how would you produce a smooth continuous interpolation between them?</p>
<p>2D and 3D solutions are welcome. Solutions that produce a list of points at arbitrary granularity and solutions that produce control points for bezier curves are also appreciated.</p>
<p>Also, it would be cool to see an iterative solution that could approximate early sections of the curve as it received the points, so you could draw with it.</p>
|
[
{
"answer_id": 107664,
"author": "freespace",
"author_id": 8297,
"author_profile": "https://Stackoverflow.com/users/8297",
"pm_score": 2,
"selected": false,
"text": "p(x) a_n x^n + a_(n-1) x^(n-1) + ...+ a_0 _ ^ p(x_1) = y_1\np(x_2) = y_2\n...\np(x_n) = y_n\n a_0 ... a_n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107598",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2653/"
] |
107,603
|
<p>I am constantly learning new tools, even old fashioned ones, because I like to use the right solution for the problem.</p>
<p>Nevertheless, I wonder if there is still any reason to learn some of them. <code>awk</code> for example is interesting to me, but for simple text processing, I can use <code>grep</code>, <code>cut</code>, <code>sed</code>, etc. while for complex ones, I'll go for Python.</p>
<p>Now I don't mean that's it's not a powerful and handy tool. But since it takes time and energy to learn a new tool, <strong>is it worth it</strong> ?</p>
|
[
{
"answer_id": 107618,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 5,
"selected": false,
"text": "awk awk '{print $3}' < file.in\n file.in tr -s ' ' < file.in | cut -d' ' -f3\n"
},
{
"answer_id": 107619,
"author": "Matthias Kestenholz",
"author_id": 317346,
"author_profile": "https://Stackoverflow.com/users/317346",
"pm_score": 1,
"selected": false,
"text": "$ dpkg -l|awk '/^rc/ {print $2}'|xargs sudo dpkg -P\n"
},
{
"answer_id": 107626,
"author": "freespace",
"author_id": 8297,
"author_profile": "https://Stackoverflow.com/users/8297",
"pm_score": 8,
"selected": true,
"text": "awk sh grep sed, awk linux awk awk awk awk"
},
{
"answer_id": 107653,
"author": "Nikhil",
"author_id": 5734,
"author_profile": "https://Stackoverflow.com/users/5734",
"pm_score": 5,
"selected": false,
"text": "awk -F \\t '{ if ($2 > $3) print; }' <filename>\n"
},
{
"answer_id": 138667,
"author": "Zsolt Botykai",
"author_id": 11621,
"author_profile": "https://Stackoverflow.com/users/11621",
"pm_score": 2,
"selected": false,
"text": "awk"
},
{
"answer_id": 138858,
"author": "zvrba",
"author_id": 2583,
"author_profile": "https://Stackoverflow.com/users/2583",
"pm_score": 0,
"selected": false,
"text": "perl -F':' -ane 'print $F[3],\"\\n\";' /etc/passwd\n"
},
{
"answer_id": 275275,
"author": "Dave",
"author_id": 9056,
"author_profile": "https://Stackoverflow.com/users/9056",
"pm_score": 3,
"selected": false,
"text": "BEGIN {s=\"\"; FS=\"n\"}\n/<td/ { gsub(/<[^>]*>/, \"\"); s=(s \", \" $1);}\n/<tr|<TR/ { print s; s=\"\" }\n"
},
{
"answer_id": 31798393,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "awk awk grep sed awk awk"
},
{
"answer_id": 49828059,
"author": "Kenneth",
"author_id": 8110881,
"author_profile": "https://Stackoverflow.com/users/8110881",
"pm_score": 1,
"selected": false,
"text": "if( team mates and leader ask to write awk ){\n if( you can reject that){\n if( awk code is very small){\n learn little just like learn Regex\n }else{\n use python or even java\n }\n }else{\n do as they ask\n }\n}\n"
},
{
"answer_id": 72387898,
"author": "RARE Kpop Manifesto",
"author_id": 14672114,
"author_profile": "https://Stackoverflow.com/users/14672114",
"pm_score": 0,
"selected": false,
"text": "C/C++ assembly awk mawk 1.9.9.6 perl python3 javascript C awk AVX/SSE"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107603",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9951/"
] |
107,611
|
<p>I need to load some fonts temporarily in my program. Preferably from a dll resource file.</p>
|
[
{
"answer_id": 107702,
"author": "Brian Matthews",
"author_id": 1969,
"author_profile": "https://Stackoverflow.com/users/1969",
"pm_score": 2,
"selected": false,
"text": "\n34 FONT \"myfont.ttf\"\n"
},
{
"answer_id": 110705,
"author": "Francesca",
"author_id": 9842,
"author_profile": "https://Stackoverflow.com/users/9842",
"pm_score": 4,
"selected": true,
"text": "procedure LoadFontFromDll(const DllName, FontName: PWideChar);\nvar\n DllHandle: HMODULE;\n ResHandle: HRSRC;\n ResSize, NbFontAdded: Cardinal;\n ResAddr: HGLOBAL;\nbegin\n DllHandle := LoadLibrary(DllName);\n if DllHandle = 0 then\n RaiseLastOSError;\n ResHandle := FindResource(DllHandle, FontName, RT_FONT);\n if ResHandle = 0 then\n RaiseLastOSError;\n ResAddr := LoadResource(DllHandle, ResHandle);\n if ResAddr = 0 then\n RaiseLastOSError;\n ResSize := SizeOfResource(DllHandle, ResHandle);\n if ResSize = 0 then\n RaiseLastOSError;\n if 0 = AddFontMemResourceEx(Pointer(ResAddr), ResSize, nil, @NbFontAdded) then\n RaiseLastOSError;\nend;\n var\n FontName: PChar;\n FontHandle: THandle;\n...\n FontName := 'DEJAVUSANS';\n LoadFontFromDll('Project1.dll' , FontName);\n FontHandle := CreateFont(0, 0, 0, 0, FW_NORMAL, 0, 0, 0, DEFAULT_CHARSET,\n OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH,\n FontName);\n if FontHandle = 0 then\n RaiseLastOSError;\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107611",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13219/"
] |
107,660
|
<p>What is the best (regarding performance) way to compute the critical path of a directional acyclic graph when the nodes of the graph have weight?</p>
<p>For example, if I have the following structure:</p>
<pre><code> Node A (weight 3)
/ \
Node B (weight 4) Node D (weight 7)
/ \
Node E (weight 2) Node F (weight 3)
</code></pre>
<p>The critical path should be A->B->F (total weight: 10)</p>
|
[
{
"answer_id": 37254469,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "a > b -a < -b"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107660",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19331/"
] |
107,668
|
<p>If you have a situation where a TCP connection is potentially too slow and a UDP 'connection' is potentially too unreliable what do you use? There are various standard reliable UDP protocols out there, what experiences do you have with them?</p>
<p>Please discuss one protocol per reply and if someone else has already mentioned the one you use then consider voting them up and using a comment to elaborate if required.</p>
<p><strong>I'm interested in the various options here, of which TCP is at one end of the scale and UDP is at the other. Various reliable UDP options are available and each brings some elements of TCP to UDP.</strong></p>
<p>I know that often TCP is the correct choice but having a list of the alternatives is often useful in helping one come to that conclusion. Things like Enet, RUDP, etc that are built on UDP have various pros and cons, have you used them, what are your experiences?</p>
<p>For the avoidance of doubt there is no more information, this is a hypothetical question and one that I hoped would elicit a list of responses that detailed the various options and alternatives available to someone who needs to make a decision.</p>
|
[
{
"answer_id": 108451,
"author": "smo",
"author_id": 16080,
"author_profile": "https://Stackoverflow.com/users/16080",
"pm_score": 3,
"selected": false,
"text": "int opt = -1;\nif (setsockopt(sock_fd, IPPROTO_TCP, TCP_NODELAY, (char *)&opt, sizeof(opt)))\n printf(\"Error disabling Nagle's algorithm.\\n\");\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107668",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7925/"
] |
107,674
|
<p>I'd like to build a real quick and dirty administrative backend for a Ruby on Rails application I have been attached to at the last minute. I've looked at activescaffold and streamlined and think they are both very attractive and they should be simple to get running, but I don't quite understand how to set up either one as a backend administration page. They seem designed to work like standard Ruby on Rails generators/scaffolds for creating visible front ends with model-view-controller-table name correspondence.</p>
<p>How do you create a admin_players interface when players is already in use and you want to avoid, as much as possible, affecting any of its related files?</p>
<p>The show, edit and index of the original resource are not usuable for the administrator.</p>
|
[
{
"answer_id": 107715,
"author": "Toby Hede",
"author_id": 14971,
"author_profile": "https://Stackoverflow.com/users/14971",
"pm_score": 3,
"selected": false,
"text": "class CustomersController < ApplicationController\n layout 'streamlined'\n acts_as_streamlined \n\n Streamlined.ui_for(Customer) do\n exporters :csv \n new_submit_button :ajax => false \n default_order_options :order => \"created_at desc\" \n list_columns :name, :email, :mobile, :comments, :action_required_yes_no \n end\nend\n"
},
{
"answer_id": 107736,
"author": "Laurie Young",
"author_id": 7473,
"author_profile": "https://Stackoverflow.com/users/7473",
"pm_score": 7,
"selected": true,
"text": "map.namespace :admin do |admin|\n admin.resources :customers\nend\n admin_customers new_admin_customers app/controller admin ./script/generate rspec_controller admin/admin\n\nclass Admin::AdminController < ApplicationController\n\n layout \"admin\"\n before_filter :login_required\nend\n ./script/generate rspec_controller admin/customers\n class Admin::CustomersController < Admin::AdminController\n app/views/admin/customers app/views/layouts/admin.html.erb resourcecs_controller"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107674",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6805/"
] |
107,675
|
<p>I'd like to unit test responses from the Google App Engine webapp.WSGIApplication, for example request the url '/' and test that the responses status code is 200, using <a href="http://code.google.com/p/gaeunit" rel="noreferrer">GAEUnit</a>. How can I do this? </p>
<p>I'd like to use the webapp framework and GAEUnit, which runs within the App Engine sandbox (unfortunately <a href="http://pythonpaste.org/webtest/" rel="noreferrer">WebTest</a> does not work within the sandbox).</p>
|
[
{
"answer_id": 107753,
"author": "David Coffin",
"author_id": 13049,
"author_profile": "https://Stackoverflow.com/users/13049",
"pm_score": 2,
"selected": false,
"text": "import webbrowser\n"
},
{
"answer_id": 114449,
"author": "Steve",
"author_id": 7424,
"author_profile": "https://Stackoverflow.com/users/7424",
"pm_score": 4,
"selected": false,
"text": "import unittest\nfrom webtest import TestApp\nfrom google.appengine.ext import webapp\nimport index\n\nclass IndexTest(unittest.TestCase):\n\n def setUp(self):\n self.application = webapp.WSGIApplication([('/', index.IndexHandler)], debug=True)\n\n def test_default_page(self):\n app = TestApp(self.application)\n response = app.get('/')\n self.assertEqual('200 OK', response.status)\n self.assertTrue('Hello, World!' in response)\n\n def test_page_with_param(self):\n app = TestApp(self.application)\n response = app.get('/?name=Bob')\n self.assertEqual('200 OK', response.status)\n self.assertTrue('Hello, Bob!' in response)\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107675",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13049/"
] |
107,683
|
<p>Question in the title.</p>
<p>And what happens when all 3 of <code>$_GET[foo]</code>, <code>$_POST[foo]</code> and <code>$_COOKIE[foo] exist?</code> Which one of them gets included to <code>$_REQUEST?</code></p>
|
[
{
"answer_id": 107727,
"author": "e-satis",
"author_id": 9951,
"author_profile": "https://Stackoverflow.com/users/9951",
"pm_score": 3,
"selected": false,
"text": "$_REQUEST $_REQUEST"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107683",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1897/"
] |
107,693
|
<p>I'm having trouble with global variables in php. I have a <code>$screen</code> var set in one file, which requires another file that calls an <code>initSession()</code> defined in yet another file. The <code>initSession()</code> declares <code>global $screen</code> and then processes $screen further down using the value set in the very first script.</p>
<p>How is this possible?</p>
<p>To make things more confusing, if you try to set $screen again then call the <code>initSession()</code>, it uses the value first used once again. The following code will describe the process. Could someone have a go at explaining this?</p>
<pre><code>$screen = "list1.inc"; // From model.php
require "controller.php"; // From model.php
initSession(); // From controller.php
global $screen; // From Include.Session.inc
echo $screen; // prints "list1.inc" // From anywhere
$screen = "delete1.inc"; // From model2.php
require "controller2.php"
initSession();
global $screen;
echo $screen; // prints "list1.inc"
</code></pre>
<p>Update:<br>
If I declare <code>$screen</code> global again just before requiring the second model, $screen is updated properly for the <code>initSession()</code> method. Strange.</p>
|
[
{
"answer_id": 107759,
"author": "e-satis",
"author_id": 9951,
"author_profile": "https://Stackoverflow.com/users/9951",
"pm_score": 7,
"selected": true,
"text": "Global Global <?php\n\n$var = \"test\"; // this is accessible in all the rest of the code, even an included one\n\nfunction foo2()\n{\n global $var;\n echo $var; // this print \"test\"\n $var = 'test2';\n}\n\nglobal $var; // this is totally useless, unless this file is included inside a class or function\n\nfunction foo()\n{\n echo $var; // this print nothing, you are using a local var\n $var = 'test3';\n}\n\nfoo();\nfoo2();\necho $var; // this will print 'test2'\n?>\n global"
},
{
"answer_id": 107760,
"author": "Athena",
"author_id": 17846,
"author_profile": "https://Stackoverflow.com/users/17846",
"pm_score": 4,
"selected": false,
"text": "global $foo global $foo $foo global $screen"
},
{
"answer_id": 107821,
"author": "Internet Friend",
"author_id": 18037,
"author_profile": "https://Stackoverflow.com/users/18037",
"pm_score": 2,
"selected": false,
"text": "//We're doing \"foo\", and we need importantString and relevantObject to do it\n$fooContext = new StdClass(); //StdClass is an empty class\n$fooContext->importantString = \"a very important string\";\n$fooContext->relevantObject = new RelevantObject();\n\ndoFoo($fooContext);\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107693",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10583/"
] |
107,701
|
<p>How can I remove those annoying Mac OS X <code>.DS_Store</code> files from a Git repository?</p>
|
[
{
"answer_id": 107703,
"author": "John Topley",
"author_id": 1450,
"author_profile": "https://Stackoverflow.com/users/1450",
"pm_score": 3,
"selected": false,
"text": "find . -name \"*.DS_Store\" -type f -exec git-rm {} \\;\n .DS_Store ._.DS_Store"
},
{
"answer_id": 107711,
"author": "Nathan",
"author_id": 6062,
"author_profile": "https://Stackoverflow.com/users/6062",
"pm_score": 3,
"selected": false,
"text": "git-rm .gitignore"
},
{
"answer_id": 107921,
"author": "benzado",
"author_id": 10947,
"author_profile": "https://Stackoverflow.com/users/10947",
"pm_score": 13,
"selected": true,
"text": ".DS_Store find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch\n .DS_Store\n .gitignore echo .DS_Store >> .gitignore\n git add .gitignore\ngit commit -m '.DS_Store banished!'\n"
},
{
"answer_id": 108108,
"author": "webmat",
"author_id": 6349,
"author_profile": "https://Stackoverflow.com/users/6349",
"pm_score": 6,
"selected": false,
"text": "git config --global core.excludesfile /Users/mat/.gitignore\n"
},
{
"answer_id": 1161174,
"author": "manat",
"author_id": 136492,
"author_profile": "https://Stackoverflow.com/users/136492",
"pm_score": 3,
"selected": false,
"text": ".DS_Store find . -depth -name '.DS_Store' -exec git-rm --cached '{}' \\; -print\n --cached .DS_Store .DS_Store"
},
{
"answer_id": 3290774,
"author": "David Kahn",
"author_id": 396882,
"author_profile": "https://Stackoverflow.com/users/396882",
"pm_score": 4,
"selected": false,
"text": "find . -depth -name '.DS_Store' -exec git rm --cached '{}' \\; -print\n"
},
{
"answer_id": 6701239,
"author": "Turadg",
"author_id": 46040,
"author_profile": "https://Stackoverflow.com/users/46040",
"pm_score": 8,
"selected": false,
"text": "git rm # remove any existing files from the repo, skipping over ones not in repo\nfind . -name .DS_Store -print0 | xargs -0 git rm --ignore-unmatch\n# specify a global exclusion list\ngit config --global core.excludesfile ~/.gitignore\n# adding .DS_Store to that list\necho .DS_Store >> ~/.gitignore\n"
},
{
"answer_id": 7577219,
"author": "jordantbro",
"author_id": 505359,
"author_profile": "https://Stackoverflow.com/users/505359",
"pm_score": 3,
"selected": false,
"text": "find . -name .DS_Store -print0 | xargs -0 git rm --ignore-unmatch -f\n touch ~/.gitignore\n .DS_Store\n git config --global core.excludesfile ~/.gitignore\n"
},
{
"answer_id": 7815479,
"author": "JZ.",
"author_id": 165448,
"author_profile": "https://Stackoverflow.com/users/165448",
"pm_score": 2,
"selected": false,
"text": "$ git commit -m \"filter-branch --index-filter 'git rm --cached --ignore-unmatch .DS_Store\"\n$ git push origin master --force\n"
},
{
"answer_id": 15921520,
"author": "Invincible",
"author_id": 968732,
"author_profile": "https://Stackoverflow.com/users/968732",
"pm_score": 3,
"selected": false,
"text": "rm .DS_Store\n git pull origin master\n"
},
{
"answer_id": 17628243,
"author": "Nerve",
"author_id": 1541507,
"author_profile": "https://Stackoverflow.com/users/1541507",
"pm_score": 8,
"selected": false,
"text": "vi ~/.gitignore_global\n # Compiled source #\n###################\n*.com\n*.class\n*.dll\n*.exe\n*.o\n*.so\n\n# Packages #\n############\n# it's better to unpack these files and commit the raw source\n# git has its own built in compression methods\n*.7z\n*.dmg\n*.gz\n*.iso\n*.jar\n*.rar\n*.tar\n*.zip\n\n# Logs and databases #\n######################\n*.log\n*.sql\n*.sqlite\n\n# OS generated files #\n######################\n.DS_Store\n.DS_Store?\n._*\n.Spotlight-V100\n.Trashes\nehthumbs.db\nThumbs.db\n git config --global core.excludesfile ~/.gitignore_global\n"
},
{
"answer_id": 23391733,
"author": "dav1dhunt",
"author_id": 3290784,
"author_profile": "https://Stackoverflow.com/users/3290784",
"pm_score": 2,
"selected": false,
"text": "-u\n"
},
{
"answer_id": 23599379,
"author": "Reggie Pinkham",
"author_id": 2927114,
"author_profile": "https://Stackoverflow.com/users/2927114",
"pm_score": 6,
"selected": false,
"text": "git rm --cached -f *.DS_Store\n"
},
{
"answer_id": 37282582,
"author": "Ezequiel García",
"author_id": 5984091,
"author_profile": "https://Stackoverflow.com/users/5984091",
"pm_score": 2,
"selected": false,
"text": "#Ignore folder mac\n.DS_Store\n git add -A\ngit commit -m \"ignore .DS_Store\"\n"
},
{
"answer_id": 40782483,
"author": "Karthick Vadivel",
"author_id": 1920908,
"author_profile": "https://Stackoverflow.com/users/1920908",
"pm_score": 5,
"selected": false,
"text": "find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch nano .gitignore .DS_Store git add .gitignore git commit -m '.DS_Store removed.'"
},
{
"answer_id": 41011905,
"author": "Sunny",
"author_id": 6438500,
"author_profile": "https://Stackoverflow.com/users/6438500",
"pm_score": 4,
"selected": false,
"text": "find . -name '*.DS_Store' -type f -delete\n .DS_Store .gitignore"
},
{
"answer_id": 47029298,
"author": "Joshua Dance",
"author_id": 1296746,
"author_profile": "https://Stackoverflow.com/users/1296746",
"pm_score": 5,
"selected": false,
"text": "touch touch .gitignore nano .gitignore # OS generated files #\n######################\n.DS_Store\n.DS_Store?\n find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch git status git add .gitignore git commit -m '.DS_Store banished!'"
},
{
"answer_id": 47966101,
"author": "zeozod",
"author_id": 9004603,
"author_profile": "https://Stackoverflow.com/users/9004603",
"pm_score": 3,
"selected": false,
"text": "cd directory/above/affected/workareas\nfind . -name .DS_Store -delete\n"
},
{
"answer_id": 49066965,
"author": "Cubiczx",
"author_id": 2053708,
"author_profile": "https://Stackoverflow.com/users/2053708",
"pm_score": 2,
"selected": false,
"text": "$ find . -name .DS_Store -print0 | xargs -0 git rm --ignore-unmatch\n"
},
{
"answer_id": 49970762,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 4,
"selected": false,
"text": "find . -name .DS_Store -print0 | xargs -0 git rm --ignore-unmatch\n echo \".DS_Store\" >> ~/.gitignore_global\necho \"._.DS_Store\" >> ~/.gitignore_global\necho \"**/.DS_Store\" >> ~/.gitignore_global\necho \"**/._.DS_Store\" >> ~/.gitignore_global\ngit config --global core.excludesfile ~/.gitignore_global\n"
},
{
"answer_id": 56650972,
"author": "Wael Assaf",
"author_id": 6241797,
"author_profile": "https://Stackoverflow.com/users/6241797",
"pm_score": 2,
"selected": false,
"text": ".DS_STORE .gitignore nano .gitignore .DS_Store CTRL+X > y > Hit Return git status git add .gitignore git commit -m 'YOUR COMMIT MESSAGE' git push origin master"
},
{
"answer_id": 58263198,
"author": "2rahulsk",
"author_id": 9949370,
"author_profile": "https://Stackoverflow.com/users/9949370",
"pm_score": 2,
"selected": false,
"text": ".gitignore touch .gitignore .DS_Store\n .gitignore"
},
{
"answer_id": 61207904,
"author": "Kasem777",
"author_id": 9190334,
"author_profile": "https://Stackoverflow.com/users/9190334",
"pm_score": 5,
"selected": false,
"text": ".gitignore echo .DS_Store >> ~/.gitignore_global\n git config --global core.excludesfile ~/.gitignore_global\n .DS_Store"
},
{
"answer_id": 64747901,
"author": "Fernando Comet",
"author_id": 1568267,
"author_profile": "https://Stackoverflow.com/users/1568267",
"pm_score": 0,
"selected": false,
"text": "git checkout -- ../.DS_Store\n"
},
{
"answer_id": 64850992,
"author": "stevec",
"author_id": 5783745,
"author_profile": "https://Stackoverflow.com/users/5783745",
"pm_score": 3,
"selected": false,
"text": ".DS_Store find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch\n .gitignore **/.DS_Store\n"
},
{
"answer_id": 66825451,
"author": "RajVimalC",
"author_id": 8467381,
"author_profile": "https://Stackoverflow.com/users/8467381",
"pm_score": 5,
"selected": false,
"text": "# Ignore Mac DS_Store files\n.DS_Store\n**/.DS_Store\n git rm -r --cached .\ngit add .\ngit commit -am \"Removed git ignored files\"\ngit push -f origin master\n"
},
{
"answer_id": 74563580,
"author": "Maksym Kosenko",
"author_id": 11968199,
"author_profile": "https://Stackoverflow.com/users/11968199",
"pm_score": 0,
"selected": false,
"text": ".DS_Store\ngensrc\n!custom/**\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107701",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1450/"
] |
107,705
|
<p>Is output buffering enabled by default in Python's interpreter for <code>sys.stdout</code>?</p>
<p>If the answer is positive, what are all the ways to disable it?</p>
<p>Suggestions so far:</p>
<ol>
<li>Use the <code>-u</code> command line switch</li>
<li>Wrap <code>sys.stdout</code> in an object that flushes after every write</li>
<li>Set <code>PYTHONUNBUFFERED</code> env var</li>
<li><code>sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)</code></li>
</ol>
<p>Is there any other way to set some global flag in <code>sys</code>/<code>sys.stdout</code> programmatically during execution?</p>
|
[
{
"answer_id": 107717,
"author": "Seb",
"author_id": 189,
"author_profile": "https://Stackoverflow.com/users/189",
"pm_score": 10,
"selected": true,
"text": "python -u class Unbuffered(object):\n def __init__(self, stream):\n self.stream = stream\n def write(self, data):\n self.stream.write(data)\n self.stream.flush()\n def writelines(self, datas):\n self.stream.writelines(datas)\n self.stream.flush()\n def __getattr__(self, attr):\n return getattr(self.stream, attr)\n\nimport sys\nsys.stdout = Unbuffered(sys.stdout)\nprint 'Hello'\n"
},
{
"answer_id": 107746,
"author": "stderr",
"author_id": 19556,
"author_profile": "https://Stackoverflow.com/users/19556",
"pm_score": 2,
"selected": false,
"text": "sys.stderr sys.stdout sys.stdout.flush() import sys; sys.stdout = sys.stderr\nprint \"Hello World!\"\n print print >>sys.stderr, \"Hello World!\"\n sys.stdout = sys.__stdout__\n"
},
{
"answer_id": 107854,
"author": "S.Lott",
"author_id": 10661,
"author_profile": "https://Stackoverflow.com/users/10661",
"pm_score": 2,
"selected": false,
"text": "import sys \nmyFile= open( \"a.log\", \"w\", 0 ) \nsys.stdout= myFile\n"
},
{
"answer_id": 181654,
"author": "Federico A. Ramponi",
"author_id": 18770,
"author_profile": "https://Stackoverflow.com/users/18770",
"pm_score": 7,
"selected": false,
"text": "# reopen stdout file descriptor with write mode\n# and 0 as the buffer size (unbuffered)\nimport io, os, sys\ntry:\n # Python 3, open as binary, then wrap in a TextIOWrapper with write-through.\n sys.stdout = io.TextIOWrapper(open(sys.stdout.fileno(), 'wb', 0), write_through=True)\n # If flushing on newlines is sufficient, as of 3.7 you can instead just call:\n # sys.stdout.reconfigure(line_buffering=True)\nexcept TypeError:\n # Python 2\n sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)\n"
},
{
"answer_id": 1736047,
"author": "jimx",
"author_id": 47606,
"author_profile": "https://Stackoverflow.com/users/47606",
"pm_score": 2,
"selected": false,
"text": "fl = fcntl.fcntl(fd.fileno(), fcntl.F_GETFL)\nfl |= os.O_SYNC # or os.O_DSYNC (if you don't care the file timestamp updates)\nfcntl.fcntl(fd.fileno(), fcntl.F_SETFL, fl)\n"
},
{
"answer_id": 3678114,
"author": "Mark Seaborn",
"author_id": 443562,
"author_profile": "https://Stackoverflow.com/users/443562",
"pm_score": 4,
"selected": false,
"text": "def disable_stdout_buffering():\n # Appending to gc.garbage is a way to stop an object from being\n # destroyed. If the old sys.stdout is ever collected, it will\n # close() stdout, which is not good.\n gc.garbage.append(sys.stdout)\n sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)\n\n# Then this will give output in the correct order:\ndisable_stdout_buffering()\nprint \"hello\"\nsubprocess.call([\"echo\", \"bye\"])\n Traceback (most recent call last):\n File \"test/buffering.py\", line 17, in <module>\n print \"hello\"\nIOError: [Errno 9] Bad file descriptor\nclose failed: [Errno 9] Bad file descriptor\n def disable_stdout_buffering():\n fileno = sys.stdout.fileno()\n temp_fd = os.dup(fileno)\n sys.stdout.close()\n os.dup2(temp_fd, fileno)\n os.close(temp_fd)\n sys.stdout = os.fdopen(fileno, \"w\", 0)\n"
},
{
"answer_id": 11276965,
"author": "Laimis",
"author_id": 1493464,
"author_profile": "https://Stackoverflow.com/users/1493464",
"pm_score": 2,
"selected": false,
"text": "def DisOutBuffering():\n if sys.stdout.name == '<stdout>':\n sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)\n\n if sys.stderr.name == '<stderr>':\n sys.stderr = os.fdopen(sys.stderr.fileno(), 'w', 0)\n"
},
{
"answer_id": 14729823,
"author": "Cristóvão D. Sousa",
"author_id": 1062531,
"author_profile": "https://Stackoverflow.com/users/1062531",
"pm_score": 8,
"selected": false,
"text": "print('Hello World!', flush=True)\n"
},
{
"answer_id": 17047064,
"author": "tzp",
"author_id": 1278711,
"author_profile": "https://Stackoverflow.com/users/1278711",
"pm_score": 2,
"selected": false,
"text": "\\n' flush() for line in sys.stdin: flush() while True:\n line=sys.stdin.readline()"
},
{
"answer_id": 23034580,
"author": "Gummbum",
"author_id": 3527428,
"author_profile": "https://Stackoverflow.com/users/3527428",
"pm_score": 4,
"selected": false,
"text": "import os\nimport sys\nbuf_arg = 0\nif sys.version_info[0] == 3:\n os.environ['PYTHONUNBUFFERED'] = '1'\n buf_arg = 1\nsys.stdout = os.fdopen(sys.stdout.fileno(), 'a+', buf_arg)\nsys.stderr = os.fdopen(sys.stderr.fileno(), 'a+', buf_arg)\n"
},
{
"answer_id": 31170728,
"author": "dyomas",
"author_id": 1329132,
"author_profile": "https://Stackoverflow.com/users/1329132",
"pm_score": 3,
"selected": false,
"text": "stdbuf -oL python <script>"
},
{
"answer_id": 40161931,
"author": "Tim",
"author_id": 3734258,
"author_profile": "https://Stackoverflow.com/users/3734258",
"pm_score": 5,
"selected": false,
"text": "flush import functools\nprint = functools.partial(print, flush=True)\n flush=False print stdout stderr sys.stdout flush print"
},
{
"answer_id": 42461528,
"author": "Vasily E.",
"author_id": 7623015,
"author_profile": "https://Stackoverflow.com/users/7623015",
"pm_score": 2,
"selected": false,
"text": "write sys.stdout flush def write_flush(args, w=stdout.write):\n w(args)\n stdout.flush()\n w write write_flush write stdout.write = write_flush\n stdout from sys import stdout"
},
{
"answer_id": 53488262,
"author": "Oliver",
"author_id": 869951,
"author_profile": "https://Stackoverflow.com/users/869951",
"pm_score": 4,
"selected": false,
"text": "_orig_print = print\n\ndef print(*args, **kwargs):\n _orig_print(*args, flush=True, **kwargs)\n functools.partial print = functools.partial(print, flush=True)\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107705",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8206/"
] |
107,735
|
<p>After hitting a few StackOverflowExceptions in .NET I noticed they completely bypass the unhandled exception handlers that .NET offers (Application.ThreadException / AppDomain.UnhandledException).
This is very disturbing since we have critical cleanup code in those exception handlers.</p>
<p>Is there any way to overcome this?</p>
|
[
{
"answer_id": 2952513,
"author": "NBB",
"author_id": 355782,
"author_profile": "https://Stackoverflow.com/users/355782",
"pm_score": 0,
"selected": false,
"text": "private Thing _myThing = null;\n\nPublic Thing MyThing\n{\n get{\n return this.MyThing;}\n set{\n this.MyThing = value;}\n}\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107735",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18910/"
] |
107,755
|
<p><strong>What libraries are there to write C# internationalized applications?</strong></p>
<p>Typical functionalities that should be contained in the library:</p>
<ul>
<li>Validation of country specific data (e.g. VAT numbers, phone numbers, addresses,...)</li>
<li>Validation of bank and financial coordinates (e.g. Credit Card numbers, IBAN,...)</li>
<li>Language-specific functionalities (e.g. numbers to words to numbers, summarize,...)</li>
<li>Language specific content filtering (e.g. swearword filtering...)</li>
</ul>
<p>An example of such libraries in Perl would be the <a href="http://search.cpan.org/modlist/Internationalization_Locale" rel="noreferrer">Internationalization/Locale section</a> of CPAN.</p>
<p>What C# solutions are available?</p>
<hr>
<p>Note: I am not looking for an introduction to the System.Globalization namespace :)</p>
<hr>
<p>Note 2: Should I desume that there are no options available? Is someone interested in joining forces and create one?</p>
<hr>
<p>Note 3: Edit to make the question appear on front page in hope of more answers. This isn't such a hard question, how is it possible that Stackers don't ever do i18n?</p>
|
[
{
"answer_id": 145744,
"author": "Carra",
"author_id": 21679,
"author_profile": "https://Stackoverflow.com/users/21679",
"pm_score": 1,
"selected": false,
"text": " culture = new CultureInfo(locale);\n int number = Convert.ToInt32(myString, culture.NumberFormat);\n string str= Convert.ToString(myNumber, culture.NumberFormat);\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107755",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7028/"
] |
107,772
|
<p>From my understanding the XMPP protocol is based on an always-on connection where you have no, immediate, indication of when an XML message ends.</p>
<p>This means you have to evaluate the stream as it comes. This also means that, probably, you have to deal with asynchronous connections since the socket can block in the middle of an XML message, either due to message length or a connection being slow.</p>
<p>I would appreciate one source per answer so we can mod them up and see what's the favourite.</p>
|
[
{
"answer_id": 110215,
"author": "Joe Hildebrand",
"author_id": 8388,
"author_profile": "https://Stackoverflow.com/users/8388",
"pm_score": 2,
"selected": true,
"text": "stanza = null\nwhile parser has more:\n switch on token type:\n START_TAG:\n elem = create element from parser state\n if stanza is not null:\n add elem as child of stanza\n stanza = elem\n END_TAG:\n parent = parent of stanza\n if parent is not null:\n fire OnStanza event\n stanza = parent\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107772",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8167/"
] |
107,794
|
<p>Are there any import and export tools that would let us move projects into and out of team system <strong>with full history and log</strong>? Our current SCM is SVN.</p>
<p>PS - Sorry, I know it's a repost, but I didn't get an answer before... :)</p>
|
[
{
"answer_id": 608896,
"author": "Matthew Savage",
"author_id": 18434,
"author_profile": "https://Stackoverflow.com/users/18434",
"pm_score": 3,
"selected": false,
"text": "svn co <url> Proj_SVN svn co http:// localhost:8080/<tfs_server>/<project_repo_path> Proj_TFS svn2svn /s:c:\\temp\\src\\Proj_SVN /d:c:\\temp\\src\\Proj_TFS /r:<start_rev>:<end_rev>"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107794",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7028/"
] |
107,823
|
<p>(Jeopardy-style question, I wish the answer had been online when I had this issue)</p>
<p>Using Java 1.4, I have a method that I want to run as a thread some of the time, but not at others. So I declared it as a subclass of Thread, then either called start() or run() depending on what I needed.</p>
<p>But I found that my program would leak memory over time. What am I doing wrong?</p>
|
[
{
"answer_id": 107832,
"author": "slim",
"author_id": 7512,
"author_profile": "https://Stackoverflow.com/users/7512",
"pm_score": 7,
"selected": true,
"text": "Thread start() Thread run() Runnable Thread myRunnable.run();\n Thread myThread = new Thread(myRunnable);\nmyThread.start();\n"
},
{
"answer_id": 107937,
"author": "Alexander",
"author_id": 16724,
"author_profile": "https://Stackoverflow.com/users/16724",
"pm_score": 2,
"selected": false,
"text": "public final class Test {\n public static final void main(String[] params) throws Exception {\n final Runtime rt = Runtime.getRuntime();\n long i = 0;\n while(true) {\n new MyThread().run();\n i++;\n if ((i % 100) == 0) {\n System.out.println((i / 100) + \": \" + (rt.freeMemory() / 1024 / 1024) + \" \" + (rt.totalMemory() / 1024 / 1024));\n }\n }\n }\n\n static class MyThread extends Thread {\n private final byte[] tmp = new byte[10 * 1024 * 1024];\n\n public void run() {\n System.out.print(\".\");\n }\n }\n}\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107823",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7512/"
] |
107,828
|
<p>I don't want <code>PHP</code> errors to display /html, but I want them to display in <code>/html/beta/usercomponent</code>. Everything is set up so that errors do not display at all. How can I get errors to just show up in that one folder (and its subfolders)?</p>
|
[
{
"answer_id": 107843,
"author": "Kent Fredric",
"author_id": 15614,
"author_profile": "https://Stackoverflow.com/users/15614",
"pm_score": 6,
"selected": true,
"text": ".htaccess php_value error_reporting 2147483647\n php -r 'echo E_ALL | E_STRICT ;'\n AllowOverride All\n error_reporting( E_ALL | E_STRICT ); \n display_errors = 0\nerror_logging = E_ALL | E_STRICT \nerror_log = /var/log/php \n <Directory> <Directory /path/to/wherever/on/filesystem> \n <IfModule mod_php5.c>\n php_value error_reporting 214748364\n </IfModule>\n </Directory>\n"
},
{
"answer_id": 107849,
"author": "Twan",
"author_id": 6702,
"author_profile": "https://Stackoverflow.com/users/6702",
"pm_score": 2,
"selected": false,
"text": "php_value error_reporting [int]\n"
},
{
"answer_id": 108982,
"author": "farzad",
"author_id": 9394,
"author_profile": "https://Stackoverflow.com/users/9394",
"pm_score": 2,
"selected": false,
"text": "if ($_ENV['MY_PHP_APP_MODE'] == 'devel') {\n // show errors and debugging info\n} elseif ($_ENV['MY_PHP_APP_MODE'] == 'production') {\n // show some cool message to the user so he won't freak out\n // log the errors and send email to the admin\n}\n setenv MY_PHP_APP_MODE devel\n setenv MY_PHP_APP_MODE production\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107828",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
107,840
|
<p>I'm wondering how do you deal with displaying release revision number when pushing live new versions of your app?</p>
<p>You can use <code>$Rev$</code> in a file to get latest revision, but only after you update the file.</p>
<p>What if I want to update a string in one file every time I change any file in the repository/directory?</p>
<p>Is there a way?</p>
|
[
{
"answer_id": 107853,
"author": "Eevee",
"author_id": 17875,
"author_profile": "https://Stackoverflow.com/users/17875",
"pm_score": 1,
"selected": false,
"text": "svnversion"
},
{
"answer_id": 107869,
"author": "benzado",
"author_id": 10947,
"author_profile": "https://Stackoverflow.com/users/10947",
"pm_score": 3,
"selected": false,
"text": "svnversion svn info svnversion"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107840",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19217/"
] |
107,846
|
<p>I've encrypted the connectionstring in my web.config file using the steps in the link below:
<a href="http://www.codeproject.com/KB/database/WebFarmConnStringsNet20.aspx" rel="nofollow noreferrer">http://www.codeproject.com/KB/database/WebFarmConnStringsNet20.aspx</a></p>
<p>However, whenever I call my application, it will give the following error: </p>
<blockquote>
<p>Failed to decrypt using provider
'CustomProvider'. Error message from
the provider: The RSA key container
could not be opened.</p>
</blockquote>
<p>The server where I perform the encryption is a 64-bit Windows Server 2003 R2 SP2. Because of that I assign the ACL to <code>NT Authority\Network Service</code>. Yet it still doesn't work. </p>
<p>Hope someone has some ideas what else do I need to check to get this working.</p>
<p>PS. If I used the default rsa key <code>NetFrameworkConfigurationKey</code> for encryption, then the connection string will not have an access problem. </p>
|
[
{
"answer_id": 107889,
"author": "Per Hornshøj-Schierbeck",
"author_id": 11619,
"author_profile": "https://Stackoverflow.com/users/11619",
"pm_score": 0,
"selected": false,
"text": "<configProtectedData>\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107846",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19582/"
] |
107,872
|
<p>I have <a href="http://laconi.ca/trac/" rel="nofollow noreferrer">Laconica</a> (self hosted <a href="http://twitter.com/home" rel="nofollow noreferrer">twitter</a>) configured on my local intranet and would like to integrate the public stream into SharePoint site with a web part. How can I do this?</p>
|
[
{
"answer_id": 107874,
"author": "Eric Schoonover",
"author_id": 3957,
"author_profile": "https://Stackoverflow.com/users/3957",
"pm_score": 4,
"selected": true,
"text": "<xsl:stylesheet xmlns:x=\"http://www.w3.org/2001/XMLSchema\" version=\"1.0\" exclude-result-prefixes=\"xsl ddwrt msxsl rssaggwrt\"\n xmlns:ddwrt=\"http://schemas.microsoft.com/WebParts/v2/DataView/runtime\"\n xmlns:rssaggwrt=\"http://schemas.microsoft.com/WebParts/v3/rssagg/runtime\"\n xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"\n xmlns:msxsl=\"urn:schemas-microsoft-com:xslt\"\n xmlns:rssFeed=\"urn:schemas-microsoft-com:sharepoint:RSSAggregatorWebPart\"\n xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"\n xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n xmlns:rss=\"http://purl.org/rss/1.0/\"\n xmlns:atom=\"http://www.w3.org/2005/Atom\"\n xmlns:itunes=\"http://www.itunes.com/dtds/podcast-1.0.dtd\"\n xmlns:atom2=\"http://purl.org/atom/ns#\"\n xmlns:ddwrt2=\"urn:frontpage:internal\"\n xmlns:laconica=\"http://laconi.ca/ont/\">\n <xsl:param name=\"rss_FeedLimit\">5</xsl:param>\n <xsl:param name=\"rss_ExpandFeed\">false</xsl:param>\n <xsl:param name=\"rss_LCID\">1033</xsl:param>\n <xsl:param name=\"rss_WebPartID\">RSS_Viewer_WebPart</xsl:param>\n <xsl:param name=\"rss_alignValue\">left</xsl:param>\n <xsl:param name=\"rss_IsDesignMode\">True</xsl:param>\n <xsl:template match=\"rdf:RDF\">\n <xsl:call-template name=\"RDFMainTemplate\"/>\n </xsl:template>\n <xsl:template name=\"RDFMainTemplate\" xmlns:ddwrt=\"http://schemas.microsoft.com/WebParts/v2/DataView/runtime\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" xmlns:msxsl=\"urn:schemas-microsoft-com:xslt\">\n <xsl:variable name=\"Rows\" select=\"rss:item\"/>\n <xsl:variable name=\"RowCount\" select=\"count($Rows)\"/>\n <div class=\"slm-layout-main\" >\n <xsl:call-template name=\"RDFMainTemplate.body\">\n <xsl:with-param name=\"Rows\" select=\"$Rows\"/>\n <xsl:with-param name=\"RowCount\" select=\"count($Rows)\"/>\n </xsl:call-template>\n </div>\n </xsl:template>\n <xsl:template name=\"RDFMainTemplate.body\" xmlns:ddwrt=\"http://schemas.microsoft.com/WebParts/v2/DataView/runtime\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" xmlns:msxsl=\"urn:schemas-microsoft-com:xslt\">\n <xsl:param name=\"Rows\"/>\n <xsl:param name=\"RowCount\"/>\n <xsl:for-each select=\"$Rows\">\n <xsl:variable name=\"CurPosition\" select=\"position()\" />\n <xsl:variable name=\"RssFeedLink\" select=\"$rss_WebPartID\" />\n <xsl:variable name=\"CurrentElement\" select=\"concat($RssFeedLink,$CurPosition)\" />\n <xsl:if test=\"($CurPosition <= $rss_FeedLimit)\">\n <xsl:element name=\"div\">\n <xsl:if test=\"($CurPosition mod 2 = 1)\">\n <xsl:attribute name=\"style\"><![CDATA[background-color:#F9F9F9;]]></xsl:attribute>\n </xsl:if>\n <xsl:element name=\"table\">\n <xsl:attribute name=\"cellpadding\">0</xsl:attribute>\n <xsl:attribute name=\"border\">0</xsl:attribute>\n <xsl:attribute name=\"style\"><![CDATA[margin:0px;padding:0px;border-spacing:0px;background-color:transparent;]]></xsl:attribute>\n <xsl:element name=\"tr\">\n <xsl:element name=\"td\">\n <xsl:attribute name=\"style\"><![CDATA[vertical-align:top;padding:0px;background-color:transparent;]]></xsl:attribute>\n <xsl:attribute name=\"rowspan\">2</xsl:attribute>\n <xsl:element name=\"img\">\n <xsl:attribute name=\"src\"><xsl:value-of select=\"laconica:postIcon/@rdf:resource\"/></xsl:attribute>\n <xsl:attribute name=\"style\"><![CDATA[margin:3px;height:48px;width:48px;]]></xsl:attribute>\n </xsl:element>\n </xsl:element>\n <xsl:element name=\"td\">\n <xsl:attribute name=\"style\"><![CDATA[vertical-align:top;padding:0px;background-color:transparent;]]></xsl:attribute>\n <div>\n <strong><xsl:value-of select=\"substring-before(rss:title, ':')\"/></strong>\n </div>\n <div style=\"width:300px;overflow-x:hidden;\">\n <div>\n <xsl:value-of select=\"substring-after(rss:title, ':')\"/>\n </div>\n </div>\n </xsl:element>\n </xsl:element>\n <xsl:element name=\"tr\">\n <xsl:element name=\"td\">\n <xsl:attribute name=\"style\"><![CDATA[padding:0px;background-color:transparent;]]></xsl:attribute>\n <xsl:element name=\"a\">\n <xsl:attribute name=\"href\"><xsl:value-of select=\"rss:link\"/></xsl:attribute>\n <xsl:value-of select=\"ddwrt:FormatDate(dc:date,number($rss_LCID),15)\"/>\n </xsl:element>\n </xsl:element>\n </xsl:element>\n </xsl:element>\n </xsl:element>\n </xsl:if>\n </xsl:for-each>\n </xsl:template>\n</xsl:stylesheet>\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107872",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3957/"
] |
107,884
|
<p>I'm trying to identify differences between a base case and supplied case. Looking for a library to tell me similarity in percentage or something like that.</p>
<p>For Example:</p>
<p>I've 10 different HTML pages.
* All of them are 404 responses with only one 2 lines of random code (such as time or quote of the day).</p>
<p>Now when I supply a new 404 page I want a result back such as "%80" similar,however if I supply another page totally different or same website but quite different content I should get something lile "%20 similar".</p>
<p>Basically what I want to do is, when I've got a new response I want to identify if the new response is similar to these 10 pages which I supplied before.</p>
<p>I'm trying to solve this in .NET, A library or an algorithm recommendation would be great.</p>
|
[
{
"answer_id": 17126186,
"author": "Matt Mullens",
"author_id": 2000867,
"author_profile": "https://Stackoverflow.com/users/2000867",
"pm_score": 0,
"selected": false,
"text": "// This could probably be optimized significantly, but is a real-world\n// example of how to use tree edit distance in the browser.\n\n// For cheerio, you'll have to browserify, \n// which requires some fiddling around\n// due to cheerio's dynamically generated \n// require's (good grief) that browserify \n// does not see due to the static nature \n// of its code analysis (dynamic off-line\n// analysis is hard, but doable).\n//\n// Ultimately, the goal is to end up with \n// something like this in the browser:\n\nvar cheerio = require('./lib/cheerio'); \n\n// The easy part, jqgram:\nvar jq = require(\"../jqgram\").jqgram;\n\n// Make a cheerio DOM:\nvar html = '<body><div id=\"a\"><div class=\"c d\"><span>Irrelevent text</span></div></div></body>';\n\nvar cheeriodom = cheerio.load(html, {\n ignoreWhitespace: false,\n lowerCaseTags: true\n});\n\n// For ease, lets assume you have jQuery laoded:\nvar realdom = $('body');\n\n// The lfn and cfn functions allow you to specify\n// how labels and children should be defined:\njq.distance({\n root: cheeriodom,\n lfn: function(node){ \n // We don't have to lowercase this because we already\n // asked cheerio to do that for us above (lowerCaseTags).\n return node.name; \n },\n cfn: function(node){ \n // Cheerio maintains attributes in the attribs array:\n // We're going to put id's and classes in as children \n // of nodes in our cheerio tree\n var retarr = []; \n if(!! node.attribs && !! node.attribs.class){\n retarr = retarr.concat(node.attribs.class.split(' '));\n }\n if(!! node.attribs && !! node.attribs.id){\n retarr.push(node.attribs.id);\n }\n retarr = retarr.concat(node.children);\n return retarr;\n }\n},{\n root: realdom,\n lfn: function(node){ \n return node.nodeName.toLowerCase(); \n },\n cfn: function(node){ \n var retarr = [];\n if(!! node.attributes && !! node.attributes.class && !! node.attributes.class.nodeValue){\n retarr = retarr.concat(node.attributes.class.nodeValue.split(' '));\n }\n if(!! node.attributes && !! node.attributes.id && !! node.attributes.id.nodeValue) {\n retarr.push(node.attributes.id.nodeValue);\n }\n for(var i=0; i<node.children.length; ++i){\n retarr.push(node.children[i]);\n }\n return retarr;\n }\n},{ p:2, q:3, depth:10 },\nfunction(result) {\n console.log(result.distance);\n});\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107884",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
107,888
|
<p>On Linux/GCC I can use the -rpath flag to change an executables search path for shared libraries without tempering with environment variables.</p>
<p>Can this also be accomplished on Windows? As far as I know, dlls are always searched in the executable's directory and in PATH. </p>
<p>My scenario: I would like to put shared libraries into locations according to their properties (32/64bit/Debug/Release) without taking care of unique names. On Linux, this is easily be done via rpath, but I haven't found any way doing this on Windows yet.</p>
<p>Thanks for any hints!</p>
|
[
{
"answer_id": 107899,
"author": "ChrisN",
"author_id": 3853,
"author_profile": "https://Stackoverflow.com/users/3853",
"pm_score": 3,
"selected": false,
"text": "LoadLibrary"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107888",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
107,903
|
<p>On Mac OS X, you can create a zip archive from the Finder by selecting some files and selecting "Compress" from the contextual menu or the File menu. Unfortunately, the resulting file is not identical to the archive created by the <code>zip</code> command (with the default options).</p>
<p>This distinction matters to at least one service operated by Apple, which fails to accept archives created with the <code>zip</code> command. Having to create archives manually is preventing me from fully automating my release build process.</p>
<p>How can I create a zip archive in the correct format within a shell script?</p>
<p>EDIT: Since writing this question long ago, I've figured out that the key difference between <code>ditto</code> and <code>zip</code> is how they handle symbolic links: because the code signature inside an app bundle contains a symlink, it needs to be preserved as a link and not stored as a regular file. <code>ditto</code> does this by default, but <code>zip</code> does not (option <code>-y</code> is required).</p>
|
[
{
"answer_id": 107938,
"author": "millenomi",
"author_id": 6061,
"author_profile": "https://Stackoverflow.com/users/6061",
"pm_score": 5,
"selected": true,
"text": "ditto -ck --rsrc --sequesterRsrc folder file.zip\n"
},
{
"answer_id": 2473201,
"author": "Jared Egan",
"author_id": 296900,
"author_profile": "https://Stackoverflow.com/users/296900",
"pm_score": 4,
"selected": false,
"text": "ditto -c -k --sequesterRsrc --keepParent AppName.app AppName.zip\n"
},
{
"answer_id": 4230992,
"author": "valexa",
"author_id": 314546,
"author_profile": "https://Stackoverflow.com/users/314546",
"pm_score": 4,
"selected": false,
"text": " The command:\n ditto -c -k --sequesterRsrc --keepParent src_directory archive.zip\n will create a PKZip archive similarly to the Finder's Compress functionality.\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107903",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10947/"
] |
107,936
|
<p>Is there a way to add some custom font on a website without using images, <a href="http://en.wikipedia.org/wiki/Adobe_Flash" rel="noreferrer">Flash</a> or some other graphics?</p>
<p>For example, I was working on a wedding website, and I found a lot of nice fonts for that subject. But I can't find the right way to add that font on the server. And how do I include that font with CSS into the HTML? Is this possible to do without graphics?</p>
|
[
{
"answer_id": 107951,
"author": "hangy",
"author_id": 11963,
"author_profile": "https://Stackoverflow.com/users/11963",
"pm_score": 10,
"selected": true,
"text": "<style type=\"text/css\">\n@font-face {\n font-family: \"My Custom Font\";\n src: url(http://www.example.org/mycustomfont.ttf) format(\"truetype\");\n}\np.customfont { \n font-family: \"My Custom Font\", Verdana, Tahoma;\n}\n</style>\n<p class=\"customfont\">Hello world!</p>\n"
},
{
"answer_id": 107967,
"author": "mattlant",
"author_id": 14642,
"author_profile": "https://Stackoverflow.com/users/14642",
"pm_score": 2,
"selected": false,
"text": "PrivateFontCollection pfont = new PrivateFontCollection();\npfont.AddFontFile(filename);\nFontFamily ff = pfont.Families[0];\n Graphics"
},
{
"answer_id": 3130621,
"author": "Michał Pękała",
"author_id": 298858,
"author_profile": "https://Stackoverflow.com/users/298858",
"pm_score": 7,
"selected": false,
"text": "@font-face <head> <link href=' http://fonts.googleapis.com/css?family=Droid+Sans' rel='stylesheet' type='text/css'>\n h1 { font-family: 'Droid Sans', arial, serif; }\n"
},
{
"answer_id": 12391656,
"author": "BiAiB",
"author_id": 521257,
"author_profile": "https://Stackoverflow.com/users/521257",
"pm_score": 4,
"selected": false,
"text": "@font-face {\n font-family: TempestaSevenCondensed;\n src: url(\"../fonts/pf_tempesta_seven_condensed.eot\") /* EOT file for IE */\n}\n@font-face {\n font-family: TempestaSevenCondensed;\n src: url(\"../fonts/pf_tempesta_seven_condensed.ttf\") /* TTF file for CSS3 browsers */\n}\n"
},
{
"answer_id": 21959207,
"author": "Wilf",
"author_id": 2943276,
"author_profile": "https://Stackoverflow.com/users/2943276",
"pm_score": 2,
"selected": false,
"text": "@font-face {\nfont-family: 'Plakat Fraktur';\nsrc: url('/resources/fonts/plakat-fraktur-black-modified.woff') format('woff');\nfont-weight: bold;\nfont-style: normal;\n }\n"
},
{
"answer_id": 22738998,
"author": "Javier Cadiz",
"author_id": 1373105,
"author_profile": "https://Stackoverflow.com/users/1373105",
"pm_score": 6,
"selected": false,
"text": "@font-face {\n font-family: 'MyWebFont';\n src: url('webfont.eot'); /* IE9 Compat Modes */\n src: url('webfont.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */\n url('webfont.woff') format('woff'), /* Modern Browsers */\n url('webfont.ttf') format('truetype'), /* Safari, Android, iOS */\n url('webfont.svg#svgFontName') format('svg'); /* Legacy iOS */\n}\n @font-face {\n font-family: 'MyWebFont';\n src: url('myfont.woff') format('woff'), /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */\n url('myfont.ttf') format('truetype'); /* Chrome 4+, Firefox 3.5, Opera 10+, Safari 3—5 */\n}\n body {\n font-family: 'MyWebFont', Fallback, sans-serif;\n}\n"
},
{
"answer_id": 47240004,
"author": "Abhijeet Kumar",
"author_id": 6207701,
"author_profile": "https://Stackoverflow.com/users/6207701",
"pm_score": 2,
"selected": false,
"text": "<!DOCTYPE html>\n<html>\n<head>\n<link href='https://fonts.googleapis.com/css?family=Montserrat' rel='stylesheet'>\n<style>\nbody {\nfont-family: 'Montserrat';font-size: 22px;\n}\n</style>\n</head>\n<body>\n\n<h1>Montserrat</h1>\n<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p>\n\n\n</body>\n</html>\n"
},
{
"answer_id": 64129171,
"author": "Hello Hack",
"author_id": 8734258,
"author_profile": "https://Stackoverflow.com/users/8734258",
"pm_score": 1,
"selected": false,
"text": "@font-face {\nfont-family: \"CustomFont\";\nsrc: url(\"CustomFont.eot\");\nsrc: url(\"CustomFont.woff\") format(\"woff\"),\nurl(\"CustomFont.otf\") format(\"opentype\"),\nurl(\"CustomFont.svg#filename\") format(\"svg\");\n}\n"
},
{
"answer_id": 71880291,
"author": "Ajay Sahu",
"author_id": 12799742,
"author_profile": "https://Stackoverflow.com/users/12799742",
"pm_score": 0,
"selected": false,
"text": "@font-face {\nfont-family: myFirstFont;\nsrc: url(fileLocation);} \n\ndiv{\n font-family: myfirstfont;}\n"
},
{
"answer_id": 74317500,
"author": "github host2",
"author_id": 20372154,
"author_profile": "https://Stackoverflow.com/users/20372154",
"pm_score": 0,
"selected": false,
"text": "@import url(url) url"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107936",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16039/"
] |
107,964
|
<p>I am using YUI reset/base, after the reset it sets the <code>ul</code> and <code>li</code> tags to list-style: disc outside;</p>
<p>My markup looks like this:</p>
<pre><code><div id="nav">
<ul class="links">
<li><a href="">Testing</a></li>
</ul>
</div>
</code></pre>
<p>My CSS is:</p>
<pre><code>#nav {}
#nav ul li {
list-style: none;
}
</code></pre>
<p>Now that makes the small disc beside each li disappear.</p>
<p>Why doesn't this work though?</p>
<pre><code> #nav {}
#nav ul.links
{
list-style: none;
}
</code></pre>
<p>It works if I remove the link to the base.css file, why?.</p>
<p>Updated: <code>sidenav</code> -> <code>nav</code></p>
|
[
{
"answer_id": 107965,
"author": "Matt",
"author_id": 17759,
"author_profile": "https://Stackoverflow.com/users/17759",
"pm_score": 1,
"selected": false,
"text": "#nav ul.links\n"
},
{
"answer_id": 107983,
"author": "Josti",
"author_id": 11231,
"author_profile": "https://Stackoverflow.com/users/11231",
"pm_score": 2,
"selected": false,
"text": "#nav ul.links li\n{\n list-style: none;\n}\n"
},
{
"answer_id": 107996,
"author": "Dan",
"author_id": 17121,
"author_profile": "https://Stackoverflow.com/users/17121",
"pm_score": 2,
"selected": false,
"text": "ul li{ list-style: disc outside; }\n li #nav ul li{ list-style: none; }\n"
},
{
"answer_id": 108008,
"author": "vaske",
"author_id": 16039,
"author_profile": "https://Stackoverflow.com/users/16039",
"pm_score": 0,
"selected": false,
"text": ".nav ul li {\n list-style: none;\n}\n .links li {\n list-style: none;\n}\n"
},
{
"answer_id": 110309,
"author": "Prestaul",
"author_id": 5628,
"author_profile": "https://Stackoverflow.com/users/5628",
"pm_score": 4,
"selected": true,
"text": "ul li{ list-style: disc outside; } /* in YUI base.css */\n\n#nav ul.links {\n list-style: none; /* doesn't override styles for LIs, just the UL */\n}\n ul li{ list-style: disc outside; } /* in YUI base.css */\n\n#nav ul.links li {\n list-style: none;\n}\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107964",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1368/"
] |
107,971
|
<p>I'm using the following JavaScript code:</p>
<pre><code><script language="JavaScript1.2" type="text/javascript">
function CreateBookmarkLink(title, url) {
if (window.sidebar) {
window.sidebar.addPanel(title, url,"");
} else if( window.external ) {
window.external.AddFavorite( url, title); }
else if(window.opera && window.print) {
return true; }
}
</script>
</code></pre>
<p>This will create a bookmark for Firefox and IE. But the link for Firefox will show up in the sidepanel of the browser, instead of being displayed in the main screen. I personally find this very annoying and am looking for a better solution. It is of course possible to edit the bookmark manually to have it <em>not</em> show up in the side panel, but that requires extra steps. I just want to be able to have people bookmark a page (that has a lot of GET information in the URL which is used to build a certain scheme) the easy way.</p>
<p>I'm afraid that it might not be possible to have Firefox present the page in the main screen at all (as Googling this subject resulted in practically nothing worth using), but I might have missed something. If anyone has an idea if this is possible, or if there's a workaround, I'd love to hear about it.</p>
|
[
{
"answer_id": 107985,
"author": "Per Hornshøj-Schierbeck",
"author_id": 11619,
"author_profile": "https://Stackoverflow.com/users/11619",
"pm_score": 0,
"selected": false,
"text": "if (window.sidebar) \n"
},
{
"answer_id": 107993,
"author": "iBobo",
"author_id": 10567,
"author_profile": "https://Stackoverflow.com/users/10567",
"pm_score": 3,
"selected": true,
"text": "<script type=\"text/javascript\">\nfunction addBookmark(url,name){\n if(window.sidebar && window.sidebar.addPanel) {\n window.sidebar.addPanel(name,url,''); //obsolete from FF 23.\n} else if(window.opera && window.print) { \n var e=document.createElement('a');\n e.setAttribute('href',url);\n e.setAttribute('title',name);\n e.setAttribute('rel','sidebar');\n e.click();\n} else if(window.external) {\n try {\n window.external.AddFavorite(url,name);\n }\n catch(e){}\n}\nelse\n alert(\"To add our website to your bookmarks use CTRL+D on Windows and Linux and Command+D on the Mac.\");\n}\n</script>\n"
},
{
"answer_id": 9080361,
"author": "Atul Kushwah",
"author_id": 1179998,
"author_profile": "https://Stackoverflow.com/users/1179998",
"pm_score": 3,
"selected": false,
"text": "<a href=\"http://www.google.com\" title=\"Google\" rel=\"sidebar\">Bookmark This Page</a>\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107971",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18922/"
] |
107,972
|
<p>Is it possible under any set of circumstances to be able to accomplish this?</p>
<p>My current circumstances are this:</p>
<pre><code>public class CustomForm : Form
{
public class CustomGUIElement
{
...
public event MouseEventHandler Click;
// etc, and so forth.
...
}
private List<CustomGUIElement> _elements;
...
public void CustomForm_Click(object sender, MouseEventArgs e)
{
// we might want to call one of the _elements[n].Click in here
// but we can't because we aren't in the same class.
}
}
</code></pre>
<p>My first thought was to have a function similar to:</p>
<pre><code>internal enum GUIElementHandlers { Click, ... }
internal void CustomGUIElement::CallHandler(GUIElementHandler h, object[] args) {
switch (h) {
case Click:
this.Click(this, (EventArgs)args[0]);
break;
... // etc and so forth
}
}
</code></pre>
<p>It's a horribly ugly kludge, but it should work... There must be a more elegant solution though? The .NET library does this all the time with message handlers and calling events in Control's. Does anyone else have any other/better ideas?</p>
|
[
{
"answer_id": 107979,
"author": "Phil Wright",
"author_id": 6276,
"author_profile": "https://Stackoverflow.com/users/6276",
"pm_score": 6,
"selected": true,
"text": "public class CustomGUIElement \n{\n public void PerformClick()\n {\n OnClick(EventArgs.Empty);\n }\n\n protected virtual void OnClick(EventArgs e)\n {\n if (Click != null)\n Click(this, e);\n }\n}\n public void CustomForm_Click(object sender, MouseEventArgs e) \n{\n _elements[0].PerformClick();\n}\n"
},
{
"answer_id": 112125,
"author": "Lee",
"author_id": 13943,
"author_profile": "https://Stackoverflow.com/users/13943",
"pm_score": 3,
"selected": false,
"text": "public class CustomGUIElement\n{\n...\n public MouseEventHandler Click;\n // etc, and so forth.\n...\n}\n myCustomGUIElement.Click(sender,args);\n myCustomGUIElement.Click = null;\n"
},
{
"answer_id": 57007130,
"author": "Larry",
"author_id": 24472,
"author_profile": "https://Stackoverflow.com/users/24472",
"pm_score": 2,
"selected": false,
"text": "public event Action<int> RecipeSelected;\npublic void RaiseRecpeSelected(int recipe) => RecipeSelected?.Invoke(recipe);\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107972",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15537/"
] |
107,984
|
<p>In toad, I can see unicode characters that are coming from oracle db. But when I click one of the fields in the data grid into the edit mode, the unicode characters are converted to meaningless symbols, but this is not the big issue.</p>
<p>While editing this field, the unicode characters are displayed correctly as I type. But as soon as I press enter and exit edit mode, they are converted to the nearest (most similar) non-unicode character. So I cannot type unicode characters on data grids. Copy & pasting one of the unicode characters also does not work.</p>
<p>How can I solve this?</p>
<p>Edit: I am using toad 9.0.0.160.</p>
|
[
{
"answer_id": 107979,
"author": "Phil Wright",
"author_id": 6276,
"author_profile": "https://Stackoverflow.com/users/6276",
"pm_score": 6,
"selected": true,
"text": "public class CustomGUIElement \n{\n public void PerformClick()\n {\n OnClick(EventArgs.Empty);\n }\n\n protected virtual void OnClick(EventArgs e)\n {\n if (Click != null)\n Click(this, e);\n }\n}\n public void CustomForm_Click(object sender, MouseEventArgs e) \n{\n _elements[0].PerformClick();\n}\n"
},
{
"answer_id": 112125,
"author": "Lee",
"author_id": 13943,
"author_profile": "https://Stackoverflow.com/users/13943",
"pm_score": 3,
"selected": false,
"text": "public class CustomGUIElement\n{\n...\n public MouseEventHandler Click;\n // etc, and so forth.\n...\n}\n myCustomGUIElement.Click(sender,args);\n myCustomGUIElement.Click = null;\n"
},
{
"answer_id": 57007130,
"author": "Larry",
"author_id": 24472,
"author_profile": "https://Stackoverflow.com/users/24472",
"pm_score": 2,
"selected": false,
"text": "public event Action<int> RecipeSelected;\npublic void RaiseRecpeSelected(int recipe) => RecipeSelected?.Invoke(recipe);\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107984",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31505/"
] |
107,995
|
<p>The <code>unzip</code> command doesn't have an option for recursively unzipping archives.</p>
<p>If I have the following directory structure and archives:</p>
<pre>
/Mother/Loving.zip
/Scurvy/Sea Dogs.zip
/Scurvy/Cures/Limes.zip
</pre>
<p>And I want to unzip all of the archives into directories with the same name as each archive:</p>
<pre>
/Mother/Loving/1.txt
/Mother/Loving.zip
/Scurvy/Sea Dogs/2.txt
/Scurvy/Sea Dogs.zip
/Scurvy/Cures/Limes/3.txt
/Scurvy/Cures/Limes.zip
</pre>
<p>What command or commands would I issue?</p>
<p>It's important that this doesn't choke on filenames that have spaces in them.</p>
|
[
{
"answer_id": 107999,
"author": "chuckrector",
"author_id": 10645,
"author_profile": "https://Stackoverflow.com/users/10645",
"pm_score": 5,
"selected": false,
"text": "find . -name \"*.zip\" | while read filename; do unzip -o -d \"`basename -s .zip \"$filename\"`\" \"$filename\"; done;\n"
},
{
"answer_id": 108019,
"author": "Jahangir",
"author_id": 6927,
"author_profile": "https://Stackoverflow.com/users/6927",
"pm_score": 2,
"selected": false,
"text": "find . -name \"*.zip\" -exec unzip {} \\;\n"
},
{
"answer_id": 739171,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "find . -name \"*.zip\" | while read filename; do unzip -o -d \"`basename \"$filename\" .zip`\" \"$filename\"; done;\n"
},
{
"answer_id": 2318189,
"author": "Vivek Thomas",
"author_id": 279472,
"author_profile": "https://Stackoverflow.com/users/279472",
"pm_score": 8,
"selected": true,
"text": "find . -name \"*.zip\" | while read filename; do unzip -o -d \"`dirname \"$filename\"`\" \"$filename\"; done;\n find . -name \"*.zip\" | xargs -P 5 -I fileName sh -c 'unzip -o -d \"$(dirname \"fileName\")/$(basename -s .zip \"fileName\")\" \"fileName\"'\n"
},
{
"answer_id": 16540353,
"author": "Thor84no",
"author_id": 692560,
"author_profile": "https://Stackoverflow.com/users/692560",
"pm_score": 1,
"selected": false,
"text": "function explode {\n local target=\"$1\"\n echo \"Exploding $target.\"\n if [ -f \"$target\" ] ; then\n explodeFile \"$target\"\n elif [ -d \"$target\" ] ; then\n while [ \"$(find \"$target\" -type f -regextype posix-egrep -iregex \".*\\.(zip|jar|ear|war|sar)\")\" != \"\" ] ; do\n find \"$target\" -type f -regextype posix-egrep -iregex \".*\\.(zip|jar|ear|war|sar)\" -exec bash -c 'source \"<file-where-this-function-is-stored>\" ; explode \"{}\"' \\;\n done\n else\n echo \"Could not find $target.\"\n fi\n}\n\nfunction explodeFile {\n local target=\"$1\"\n echo \"Exploding file $target.\"\n mv \"$target\" \"$target.tmp\"\n unzip -q \"$target.tmp\" -d \"$target\"\n rm \"$target.tmp\"\n}\n <file-where-this-function-is-stored> .bashrc source explodeFile"
},
{
"answer_id": 22384233,
"author": "robinst",
"author_id": 305973,
"author_profile": "https://Stackoverflow.com/users/305973",
"pm_score": 6,
"selected": false,
"text": "find . -iname '*.zip' -exec sh -c 'unzip -o -d \"${0%.*}\" \"$0\"' '{}' ';'\n .jar -o find . '(' -iname '*.zip' -o -iname '*.jar' ')' -exec ...\n"
},
{
"answer_id": 23920166,
"author": "Prometheus",
"author_id": 2587178,
"author_profile": "https://Stackoverflow.com/users/2587178",
"pm_score": 0,
"selected": false,
"text": "DESTINY=[Give the output that you intend]\n\n# Don't forget to change from .ZIP to .zip.\n# In my case the files were in .ZIP.\n# The echo were for debug purpose.\n\nfind . -name \"*.ZIP\" | while read filename; do\nADDRESS=$filename\n#echo \"Address: $ADDRESS\"\nBASENAME=`basename $filename .ZIP`\n#echo \"Basename: $BASENAME\"\nunzip -d \"$DESTINY$BASENAME\" \"$ADDRESS\";\ndone;\n"
},
{
"answer_id": 49554119,
"author": "Prabhav",
"author_id": 7113627,
"author_profile": "https://Stackoverflow.com/users/7113627",
"pm_score": 2,
"selected": false,
"text": "find . -name \"*.zip\" | xargs -P 5 -I FILENAME sh -c 'unzip -o -d \"$(dirname \"FILENAME\")\" \"FILENAME\"'\n find . -depth -name '*.zip' -exec rm {} \\;\n"
},
{
"answer_id": 68138355,
"author": "Josué Martínez Morales",
"author_id": 16318953,
"author_profile": "https://Stackoverflow.com/users/16318953",
"pm_score": -1,
"selected": false,
"text": "def unzip(zip_file, path_to_extract):\n \"\"\"\n Decompress zip archives recursively\n Args:\n zip_file: name of zip archive\n path_to_extract: folder where the files will be extracted\n \"\"\"\n try:\n if is_zipfile(zip_file):\n parent_file = ZipFile(zip_file)\n parent_file.extractall(path_to_extract)\n for file_inside in parent_file.namelist():\n if is_zipfile(os.path.join(os.getcwd(),file_inside)):\n unzip(file_inside,path_to_extract)\n os.remove(f\"{zip_file}\")\n except Exception as e:\n print(e)\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/107995",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10645/"
] |
108,005
|
<p>first question here. I'm developing a program in C# (.NET 3.5) that displays files in a listview. I'd like to have the "large icon" view display the icon that Windows Explorer uses for that filetype, otherwise I'll have to use some existing code like this:</p>
<pre><code> private int getFileTypeIconIndex(string fileName)
{
string fileLocation = Application.StartupPath + "\\Quarantine\\" + fileName;
FileInfo fi = new FileInfo(fileLocation);
switch (fi.Extension)
{
case ".pdf":
return 1;
case ".doc": case ".docx": case ".docm": case ".dotx":case ".dotm": case ".dot":case ".wpd": case ".wps":
return 2;
default:
return 0;
}
}
</code></pre>
<p>The above code returns an integer that is used to select an icon from an imagelist that I populated with some common icons. It works fine but I'd need to add every extension under the sun! Is there a better way? Thanks!</p>
|
[
{
"answer_id": 108056,
"author": "eric",
"author_id": 5798,
"author_profile": "https://Stackoverflow.com/users/5798",
"pm_score": 3,
"selected": false,
"text": "private System.Windows.Forms.ListView FileView;\n\nprivate ImageList _SmallImageList = new ImageList();\nprivate ImageList _LargeImageList = new ImageList();\nprivate IconListManager _IconListManager;\n _SmallImageList.ColorDepth = ColorDepth.Depth32Bit;\n_LargeImageList.ColorDepth = ColorDepth.Depth32Bit;\n\n_SmallImageList.ImageSize = new System.Drawing.Size(16, 16);\n_LargeImageList.ImageSize = new System.Drawing.Size(32, 32);\n\n_IconListManager = new IconListManager(_SmallImageList, _LargeImageList);\n\nFileView.SmallImageList = _SmallImageList;\nFileView.LargeImageList = _LargeImageList;\n ListViewItem item = new ListViewItem(file.Name, _IconListManager.AddFileIcon(file.FullName));\n"
},
{
"answer_id": 108062,
"author": "dummy",
"author_id": 6297,
"author_profile": "https://Stackoverflow.com/users/6297",
"pm_score": 2,
"selected": false,
"text": "[StructLayout(LayoutKind.Sequential)]\npublic struct SHFILEINFO\n{\n public IntPtr hIcon;\n public IntPtr iIcon;\n public uint dwAttributes;\n [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]\n public string szDisplayName;\n [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]\n public string szTypeName;\n};\n\npublic const uint SHGFI_ICON = 0x100;\npublic const uint SHGFI_LARGEICON = 0x0; // 'Large icon\npublic const uint SHGFI_SMALLICON = 0x1; // 'Small icon\n\n[DllImport(\"shell32.dll\")]\npublic static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, uint cbSizeFileInfo, uint uFlags);\n\n[DllImport(\"User32.dll\")]\npublic static extern int DestroyIcon(IntPtr hIcon);\n\npublic static System.Drawing.Icon GetSystemIcon(string sFilename)\n{\n //Use this to get the small Icon\n IntPtr hImgSmall; //the handle to the system image list\n //IntPtr hImgLarge; //the handle to the system image list\n APIFuncs.SHFILEINFO shinfo = new APIFuncs.SHFILEINFO();\n hImgSmall = APIFuncs.SHGetFileInfo(sFilename, 0, ref shinfo,\n (uint)Marshal.SizeOf(shinfo), APIFuncs.SHGFI_ICON | APIFuncs.SHGFI_SMALLICON);\n\n //Use this to get the large Icon\n //hImgLarge = SHGetFileInfo(fName, 0, \n // ref shinfo, (uint)Marshal.SizeOf(shinfo), \n // Win32.SHGFI_ICON | Win32.SHGFI_LARGEICON);\n\n //The icon is returned in the hIcon member of the shinfo struct\n System.Drawing.Icon myIcon = (System.Drawing.Icon)System.Drawing.Icon.FromHandle(shinfo.hIcon).Clone();\n DestroyIcon(shinfo.hIcon); // Cleanup\n return myIcon;\n}\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/108005",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14333/"
] |
108,009
|
<p>I'm writing a C parser using PLY, and recently ran into a problem.
This code:</p>
<pre><code>typedef int my_type;
my_type x;
</code></pre>
<p>Is correct C code, because my_type is defined as a type previously to
being used as such. I handle it by filling a type symbol table in the
parser that gets used by the lexer to differentiate between types and
simple identifiers.</p>
<p>However, while the type declaration rule ends with SEMI (the ';' token), PLY shifts the token <code>my_type</code> from the second line before deciding it's done with the first one. Because of this, I have no chance to pass the update in the type symbol table to the lexer and it
sees my_type as an identifier and not a type.</p>
<p>Any ideas for a fix ?</p>
<p>The full code is at: <a href="http://code.google.com/p/pycparser/source/browse/trunk/src/c_parser.py" rel="nofollow noreferrer">http://code.google.com/p/pycparser/source/browse/trunk/src/c_parser.py</a>
Not sure how I can create a smaller example out of this. </p>
<p><strong>Edit:</strong></p>
<p>Problem solved. See my solution below.</p>
|
[
{
"answer_id": 108482,
"author": "Eli Bendersky",
"author_id": 8206,
"author_profile": "https://Stackoverflow.com/users/8206",
"pm_score": 3,
"selected": true,
"text": "declaration def p_decl_body(self, p):\n \"\"\" decl_body : declaration_specifiers init_declarator_list_opt\n \"\"\"\n # <<Handle the declaration here>> \n\ndef p_declaration(self, p):\n \"\"\" declaration : decl_body SEMI \n \"\"\"\n p[0] = p[1]\n decl_body"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/108009",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8206/"
] |
108,010
|
<p>Greetings.</p>
<p>I'm looking for a way to parse a number of XML files in a particular directory with ASP.NET (C#). I'd like to be able to return content from particular elements, but before that, need to find those that have a certain value between an element.</p>
<p>Example XML file 1:</p>
<pre><code><file>
<title>Title 1</title>
<someContent>Content</someContent>
<filter>filter</filter>
</file>
</code></pre>
<p>Example XML file 2:</p>
<pre><code><file>
<title>Title 2</title>
<someContent>Content</someContent>
<filter>filter, different filter</filter>
</file>
</code></pre>
<p>Example case 1:</p>
<p>Give me all XML that has a filter of 'filter'.</p>
<p>Example case 2:</p>
<p>Give me all XML that has a title of 'Title 1'.</p>
<p>Looking, it seems this should be possible with LINQ, but I've only seen examples on how to do this when there is one XML file, not when there are multiples, such as in this case.</p>
<p>I would prefer that this be done on the server-side, so that I can cache on that end.</p>
<p>Functionality from any version of the .NET Framework can be used.</p>
<p>Thanks!</p>
<p>~James</p>
|
[
{
"answer_id": 108044,
"author": "chakrit",
"author_id": 3055,
"author_profile": "https://Stackoverflow.com/users/3055",
"pm_score": 2,
"selected": false,
"text": "var xc = new XMLContentEnumerator(@\"C:\\dir\");\n\nvar filesWithHello = xc.Where(x => x.title.Contains(\"hello\"));\n"
},
{
"answer_id": 108045,
"author": "naspinski",
"author_id": 14777,
"author_profile": "https://Stackoverflow.com/users/14777",
"pm_score": 4,
"selected": true,
"text": "//get the files\nXElement xe1 = XElement.Load(string_file_path_1);\nXElement xe2 = XElement.Load(string_file_path_2);\n\n//Give me all XML that has a filter of 'filter'.\nvar filter_elements1 = from p in xe1.Descendants(\"filter\") select p;\nvar filter_elements2 = from p in xe2.Descendants(\"filter\") select p;\nvar filter_elements = filter_elements1.Union(filter_elements2);\n\n//Give me all XML that has a title of 'Title 1'.\nvar title1 = from p in xe1.Descendants(\"title\") where p.Value.Equals(\"Title 1\") select p;\nvar title2 = from p in xe2.Descendants(\"title\") where p.Value.Equals(\"Title 1\") select p;\nvar titles = title1.Union(title2);\n XElement xe1 = XElement.Load(string_file_path_1);\nXElement xe2 = XElement.Load(string_file_path_2);\nvar _filter_elements = (from p1 in xe1.Descendants(\"filter\") select p1).Union(from p2 in xe2.Descendants(\"filter\") select p2);\nvar _titles = (from p1 in xe1.Descendants(\"title\") where p1.Value.Equals(\"Title 1\") select p1).Union(from p2 in xe2.Descendants(\"title\") where p2.Value.Equals(\"Title 1\") select p2);\n foreach (var v in filter_elements)\n Response.Write(\"value of filter element\" + v.Value + \"<br />\");\n"
},
{
"answer_id": 108426,
"author": "Mattio",
"author_id": 19626,
"author_profile": "https://Stackoverflow.com/users/19626",
"pm_score": 2,
"selected": false,
"text": "static void Main(string[] args)\n{\n string[] myFiles = { @\"C:\\temp\\XMLFile1.xml\", \n @\"C:\\temp\\XMLFile2.xml\", \n @\"C:\\temp\\XMLFile3.xml\" };\n foreach (string file in myFiles)\n {\n System.Xml.XPath.XPathDocument myDoc = \n new System.Xml.XPath.XPathDocument(file);\n System.Xml.XPath.XPathNavigator myNav = \n myDoc.CreateNavigator();\n\n if(myNav.SelectSingleNode(\"/file/filter[1]\") != null &&\n myNav.SelectSingleNode(\"/file/filter[1]\").InnerXml.Contains(\"filter\"))\n Console.WriteLine(file + \" Contains 'filter'\");\n\n if (myNav.SelectSingleNode(\"/file/title[1]\") != null &&\n myNav.SelectSingleNode(\"/file/title[1]\").InnerXml.Contains(\"Title 1\"))\n Console.WriteLine(file + \" Contains 'Title 1'\");\n }\n\n Console.ReadLine();\n}\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/108010",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11912/"
] |
108,043
|
<p>When I create a socket using accept() and make a FILE out of it using fdopen(), what do I have to do to clean everything up? Do I need to do fclose() on the FILE, shutdown() and close() on the socket, or only the shutdown() and or close() or fclose()? If I don't do fclose(), do I have to free() the FILE pointer manually?</p>
|
[
{
"answer_id": 108049,
"author": "freespace",
"author_id": 8297,
"author_profile": "https://Stackoverflow.com/users/8297",
"pm_score": -1,
"selected": false,
"text": "FILE fclose() FILE close() shutdown() fdclose() close() fdclose()"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/108043",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12523/"
] |
108,081
|
<p>Are there any good, cross platform (SBCL and CLISP at the very least) easy to install GUI libraries?</p>
|
[
{
"answer_id": 108142,
"author": "Matthias Benkard",
"author_id": 15517,
"author_profile": "https://Stackoverflow.com/users/15517",
"pm_score": 6,
"selected": true,
"text": "(require :asdf-install)\n(asdf-install:install :ltk)\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/108081",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7780/"
] |
108,094
|
<p>Is there anyway to disable the rather annoying feature that Visual Studio (2008 in my case) has of copying the line (with text on it) the cursor is on when <kbd>CTRL</kbd>-<kbd>C</kbd> is pressed and no selection is made?</p>
<p>I know of the option to disable copying blank lines. But this is driving me crazy as well.</p>
<p>ETA: I'm not looking to customize the keyboard shortcut.</p>
<p>ETA-II: I am NOT looking for "Tools->Options->Text Editor->All Languages->Apply cut or copy to blank lines...".</p>
|
[
{
"answer_id": 2509622,
"author": "David Walthall",
"author_id": 301019,
"author_profile": "https://Stackoverflow.com/users/301019",
"pm_score": 5,
"selected": true,
"text": "Sub CopyOnlyIfSelection()\n Dim s As String = DTE.ActiveDocument.Selection.Text\n Dim n As Integer = Len(s)\n If n > 0 Then\n DTE.ActiveDocument.Selection.Copy()\n End If\nEnd Sub\n"
}
] |
2008/09/20
|
[
"https://Stackoverflow.com/questions/108094",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4192/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.