qid
int64 4
19.1M
| question
stringlengths 18
48.3k
| answers
list | date
stringlengths 10
10
| metadata
list |
|---|---|---|---|---|
209,086
|
<p>I've got a C++ Win32 application that has a number of threads that might be busy doing IO (HTTP calls, etc) when the user wants to shutdown the application. Currently, I play nicely and wait for all the threads to end before returning from <code>main</code>. Sometimes, this takes longer than I would like and indeed, it seems kind of pointless to make the user wait when I could just exit. However, if I just go ahead and return from <code>main</code>, I'm likely to get crashes as destructors start getting called while there are still threads using the objects.</p>
<p>So, recognizing that in an ideal, platonic world of virtue, the best thing to do would be to wait for all the threads to exit and then shutdown cleanly, what is the next best real world solution? Simply making the threads exit faster may not be an option. The goal is to get the process dead as quickly as possible so that, for example, a new version can be installed over it. The only disk IO I'm doing is in a transactional db, so I'm not terribly concerned about pulling the plug on that.</p>
|
[
{
"answer_id": 210385,
"author": "Roddy",
"author_id": 1737,
"author_profile": "https://Stackoverflow.com/users/1737",
"pm_score": 3,
"selected": false,
"text": "QueueUserAPC() catch (...) catch(const Exception &e) sleepex(N, true) sleep(N) sleepex(0,true)"
},
{
"answer_id": 8440351,
"author": "Daniel",
"author_id": 362589,
"author_profile": "https://Stackoverflow.com/users/362589",
"pm_score": 0,
"selected": false,
"text": "*NULL = 0 exit()"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209086",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23524/"
] |
209,095
|
<p>Requirement is to pass module name and function name from the command-line argument.
I need to get the command-line argument in the program and I need to call that function from that module</p>
<p>For example, calling a try.pl program with 2 arguments: MODULE1(Module name) Display(Function name)</p>
<pre><code> perl try.pl MODULE1 Display
</code></pre>
<p>I want to some thing like this, but its not working, please guide me: </p>
<pre><code>use $ARGV[0];
& $ARGV[0]::$ARGV[1]();
</code></pre>
|
[
{
"answer_id": 209284,
"author": "Yanick",
"author_id": 10356,
"author_profile": "https://Stackoverflow.com/users/10356",
"pm_score": 3,
"selected": false,
"text": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\nmy ( $package, $function ) = @ARGV;\n\neval \"use $package; 1\" or die $@;\n\n$package->$function(); \n"
},
{
"answer_id": 209310,
"author": "Leon Timmermans",
"author_id": 4727,
"author_profile": "https://Stackoverflow.com/users/4727",
"pm_score": 2,
"selected": false,
"text": "perl -Mmodule -e function\n"
},
{
"answer_id": 209336,
"author": "cjm",
"author_id": 8355,
"author_profile": "https://Stackoverflow.com/users/8355",
"pm_score": 3,
"selected": false,
"text": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\nmy ( $package, $function ) = @ARGV;\n\neval \"use $package (); ${package}::$function()\";\ndie $@ if $@;\n"
},
{
"answer_id": 209454,
"author": "Axeman",
"author_id": 11289,
"author_profile": "https://Stackoverflow.com/users/11289",
"pm_score": 2,
"selected": false,
"text": "perl -MMyModule -e 'MyModule::doit()'\n @EXPORT perl -MMyModule -e doit\n @EXPORT_OK perl -MMyModule=doit -e doit\n"
},
{
"answer_id": 209999,
"author": "Robert P",
"author_id": 18097,
"author_profile": "https://Stackoverflow.com/users/18097",
"pm_score": 2,
"selected": false,
"text": "my %routines = (\n Module => {\n Routine1 => \\&Module::Method,\n Routine2 => \\&Module::Method2, \n },\n Module2 => { \n # and so on\n },\n);\n\nmy $module = shift @ARGV;\nmy $routine = shift @ARGV;\n\nif (defined $module\n && defined $routine\n && exists $routines{$module} # use `exists` to prevent \n && exists $routines{$module}{$routine}) # unnecessary autovivication\n{\n $routines{$module}{$routine}->(@ARGV); # with remaining command line args\n}\nelse { } # error handling\n print \"Available commands:\\n\";\nforeach my $module (keys %routines)\n{\n foreach my $routine (keys %$module)\n {\n print \"$module::$routine\\n\";\n }\n} \n"
},
{
"answer_id": 210833,
"author": "JDrago",
"author_id": 28758,
"author_profile": "https://Stackoverflow.com/users/28758",
"pm_score": 2,
"selected": false,
"text": "use strict;\nuse warnings 'all';\n no strict 'refs';\nmy ($class, $method) = @_;\n(my $file = \"$class.pm\") =~ s/::/\\//g;\nrequire $file;\n&{\"$class\\::$method\"}();\n"
},
{
"answer_id": 210956,
"author": "Axeman",
"author_id": 11289,
"author_profile": "https://Stackoverflow.com/users/11289",
"pm_score": 2,
"selected": false,
"text": "use strict;\nuse warnings;\n\n{\n no strict;\n use Symbol qw<qualify>;\n my $symb = qualify( $ARGV[1], $ARGV[0] );\n unless ( defined &{$symb} ) { \n die \"&$ARGV[1] not defined to package $ARGV[0]\\::\";\n }\n &{$symb};\n}\n -M perl -MMyModule try.pl MyModule a_subroutine_which_does_something_cool\n eval \"use $ARGV[0];\"; \n perl try.pl \"Carp; `do something disastrous`;\" no_op\n"
},
{
"answer_id": 220477,
"author": "gpojd",
"author_id": 28071,
"author_profile": "https://Stackoverflow.com/users/28071",
"pm_score": 1,
"selected": false,
"text": "use UNIVERSAL::require;\n\n$ARGV[0]->use or die $UNIVERSAL::require::ERROR;\n$ARGV[0]::$ARGV[1]();\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209095",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28622/"
] |
209,110
|
<p>In my application I have a number of panes from m_wndspliter classes. What I want to do is at run time show and hide one of these panes. Whilst with the following code I can show and hide the view associated with the pane, I can't temporarily remove the pane itself. </p>
<pre><code>CWnd * pCurView = m_wndSplitter2.GetPane(2, 0);
if( !pCurView == NULL )
{
if( fShow )
{
pCurView->ShowWindow(SW_SHOW);
RecalcLayout();
}
else
{
pCurView->ShowWindow(SW_HIDE);
RecalcLayout();
}
}
</code></pre>
<p>Any examples / ideas ?</p>
|
[
{
"answer_id": 66088935,
"author": "thomiel",
"author_id": 1284927,
"author_profile": "https://Stackoverflow.com/users/1284927",
"pm_score": 0,
"selected": false,
"text": "CExtSplitter"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209110",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18664/"
] |
209,127
|
<p>I'm looking for a plugin for jQuery that can validate as a key is pressed and after it loses focus (text boxes). </p>
<p>I'm currently using <a href="http://www.overset.com/2008/07/31/jval-jquery-form-field-validation-plugin/" rel="nofollow noreferrer">jVal - jQuery Form Field Validation Plugin</a>. It works pretty good. The only issue I have is that I can only use a generic error message.</p>
<p>For example:
I need a string to between 2 and 5 characters. If its too short I would like to display an error message that indicates it to short, equally if its too long. I know I could display an error message that requires the string to between 2 and 5 characters. <strong>The validation that is being done is more complicated.</strong> </p>
<p>Any ideas of other validators or how I could use this plug-in to display unique error messages.</p>
<hr>
<p>Edit:</p>
<p>The validation tool needs to prevent particular letters or numbers and not require a form. </p>
<p>Thanks</p>
|
[
{
"answer_id": 209168,
"author": "hasseg",
"author_id": 4111,
"author_profile": "https://Stackoverflow.com/users/4111",
"pm_score": 5,
"selected": true,
"text": "// validate signup form on keyup and submit\n$(\"#signupForm\").validate({\n rules: {\n firstname: \"required\",\n lastname: \"required\",\n username: {\n required: true,\n minlength: 2\n },\n password: {\n required: true,\n minlength: 5\n },\n confirm_password: {\n required: true,\n minlength: 5,\n equalTo: \"#password\"\n },\n email: {\n required: true,\n email: true\n },\n topic: {\n required: \"#newsletter:checked\",\n minlength: 2\n },\n agree: \"required\"\n },\n messages: {\n firstname: \"Please enter your firstname\",\n lastname: \"Please enter your lastname\",\n username: {\n required: \"Please enter a username\",\n minlength: \"Your username must consist of at least 2 characters\"\n },\n password: {\n required: \"Please provide a password\",\n minlength: \"Your password must be at least 5 characters long\"\n },\n confirm_password: {\n required: \"Please provide a password\",\n minlength: \"Your password must be at least 5 characters long\",\n equalTo: \"Please enter the same password as above\"\n },\n email: \"Please enter a valid email address\",\n agree: \"Please accept our policy\"\n }\n});\n"
},
{
"answer_id": 324956,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "<input id=\"web_pswd\" type=\"password\" size=\"20\"\n jVal=\"{valid:function (val) { if ( val.length < 8 ) return '8 or more characters required'; else if ( val.search(/[0-9]/) == -1 ) return '1 number or more required'; else if ( val.search(/[a-zA-Z]/) == -1 ) return '1 letter or more required'; else return ''; }, styleType:'pod'}\"\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209127",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7617/"
] |
209,132
|
<p>How would I assign a variable within scriplet code in JSP <%> and then use struts logic tags to do stuff based on the value of the variable assigned in the scriplet code block?</p>
<p>I have tried using struts:logic equal and greaterthan to no avail....</p>
<p>Many Thanks,</p>
|
[
{
"answer_id": 209882,
"author": "myplacedk",
"author_id": 28683,
"author_profile": "https://Stackoverflow.com/users/28683",
"pm_score": 1,
"selected": false,
"text": "<% String foo = \"Test\"; %>\n<bean:write name=\"foo\" />\n <% pageContext.setAttribute(\"foo\", \"Test\"); %>\n<bean:write name=\"foo\" />\n"
},
{
"answer_id": 18515083,
"author": "rohan",
"author_id": 2551459,
"author_profile": "https://Stackoverflow.com/users/2551459",
"pm_score": 0,
"selected": false,
"text": "<c:set var=\"contains\" value=\"true\" />\n <c:if test=\"%{#variable=='String 1'}\">\n This is String 1\n</c:if>\n <%@ taglib uri=\"http://java.sun.com/jsp/jstl/core\" prefix=\"c\"%>\n"
},
{
"answer_id": 22174753,
"author": "Rajesh",
"author_id": 1395623,
"author_profile": "https://Stackoverflow.com/users/1395623",
"pm_score": 1,
"selected": false,
"text": "<%\n request.setAttribute(\"customerName\", \"rajesh\");\n%>\n <logic:match name=\"customerName\" value=\"Vijay\"></logic:match>\n"
},
{
"answer_id": 27055549,
"author": "HASNEN LAXMIDHAR",
"author_id": 3451553,
"author_profile": "https://Stackoverflow.com/users/3451553",
"pm_score": 1,
"selected": false,
"text": "<%int var=1; %>in jsp its declaration ( <%! int i = 0; %> )\n <p> Today's date: <%= (new java.util.Date()).toLocaleString()%></p>\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209132",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21004/"
] |
209,133
|
<p>We are logging any exceptions that happen in our system by writing the Exception.Message to a file. However, they are written in the culture of the client. And Turkish errors don't mean a lot to me.</p>
<p>So how can we log any error messages in English without changing the users culture?</p>
|
[
{
"answer_id": 209222,
"author": "morechilli",
"author_id": 5427,
"author_profile": "https://Stackoverflow.com/users/5427",
"pm_score": 1,
"selected": false,
"text": "0x00000001"
},
{
"answer_id": 209259,
"author": "mdb",
"author_id": 8562,
"author_profile": "https://Stackoverflow.com/users/8562",
"pm_score": 7,
"selected": true,
"text": "try\n{\n System.IO.StreamReader sr=new System.IO.StreamReader(@\"c:\\does-not-exist\");\n}\ncatch(Exception ex)\n{\n Console.WriteLine(ex.ToString()); //Will display localized message\n ExceptionLogger el = new ExceptionLogger(ex);\n System.Threading.Thread t = new System.Threading.Thread(el.DoLog);\n t.CurrentUICulture = new System.Globalization.CultureInfo(\"en-US\");\n t.Start();\n}\n class ExceptionLogger\n{\n Exception _ex;\n\n public ExceptionLogger(Exception ex)\n {\n _ex = ex;\n }\n\n public void DoLog()\n {\n Console.WriteLine(_ex.ToString()); //Will display en-US message\n }\n}\n"
},
{
"answer_id": 448549,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "CultureInfo oldCI = Thread.CurrentThread.CurrentCulture;\n\nThread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture (\"en-US\");\nThread.CurrentThread.CurrentUICulture=new CultureInfo(\"en-US\");\ntry\n{\n System.IO.StreamReader sr=new System.IO.StreamReader(@\"c:\\does-not-exist\");\n}\ncatch(Exception ex)\n{\n Console.WriteLine(ex.ToString());\n}\nThread.CurrentThread.CurrentCulture = oldCI;\nThread.CurrentThread.CurrentUICulture = oldCI;\n"
},
{
"answer_id": 4627708,
"author": "danobrega",
"author_id": 567169,
"author_profile": "https://Stackoverflow.com/users/567169",
"pm_score": 4,
"selected": false,
"text": "Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(\"pt-PT\");\nstring msg1 = new DirectoryNotFoundException().Message;\n\nThread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(\"en-US\");\nstring msg2 = new FileNotFoundException().Message;\n\nThread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(\"fr-FR\");\nstring msg3 = new FileNotFoundException().Message;\n"
},
{
"answer_id": 13955941,
"author": "Vortex852456",
"author_id": 1916285,
"author_profile": "https://Stackoverflow.com/users/1916285",
"pm_score": 2,
"selected": false,
"text": "Thread.CurrentThread.CurrentUICulture public static string TranslateExceptionMessage(Exception ex, CultureInfo targetCulture)\n{\n try\n {\n Assembly assembly = ex.GetType().Assembly;\n ResourceManager resourceManager = new ResourceManager(assembly.GetName().Name, assembly);\n ResourceSet originalResources = resourceManager.GetResourceSet(Thread.CurrentThread.CurrentUICulture, createIfNotExists: true, tryParents: true);\n ResourceSet targetResources = resourceManager.GetResourceSet(targetCulture, createIfNotExists: true, tryParents: true);\n foreach (DictionaryEntry originalResource in originalResources)\n if (originalResource.Value.ToString().Equals(ex.Message.ToString(), StringComparison.Ordinal))\n return targetResources.GetString(originalResource.Key.ToString(), ignoreCase: false); // success\n\n }\n catch { }\n return ex.Message; // failed (error or cause it's not smart enough to find texts with '{0}'-patterns)\n}\n"
},
{
"answer_id": 17845078,
"author": "MPelletier",
"author_id": 210916,
"author_profile": "https://Stackoverflow.com/users/210916",
"pm_score": 6,
"selected": false,
"text": "en-US Invariant Invariant Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;\nThread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;\n"
},
{
"answer_id": 22712176,
"author": "user3472484",
"author_id": 3472484,
"author_profile": "https://Stackoverflow.com/users/3472484",
"pm_score": -1,
"selected": false,
"text": " public static string GetEnglishMessageAndStackTrace(this Exception ex)\n {\n CultureInfo currentCulture = Thread.CurrentThread.CurrentUICulture;\n try\n {\n\n dynamic exceptionInstanceLocal = System.Activator.CreateInstance(ex.GetType());\n string str;\n Thread.CurrentThread.CurrentUICulture = new CultureInfo(\"en-US\");\n\n if (ex.Message == exceptionInstanceLocal.Message)\n {\n dynamic exceptionInstanceENG = System.Activator.CreateInstance(ex.GetType());\n\n str = exceptionInstanceENG.ToString() + ex.StackTrace;\n\n }\n else\n {\n str = ex.ToString();\n }\n Thread.CurrentThread.CurrentUICulture = currentCulture;\n\n return str;\n\n }\n catch (Exception)\n {\n Thread.CurrentThread.CurrentUICulture = currentCulture;\n\n return ex.ToString();\n }\n"
},
{
"answer_id": 34659244,
"author": "Simon Mourier",
"author_id": 403671,
"author_profile": "https://Stackoverflow.com/users/403671",
"pm_score": 4,
"selected": false,
"text": "app.config [myapp].exe.config web.config <configuration>\n ...\n <runtime>\n <assemblyBinding xmlns=\"urn:schemas-microsoft-com:asm.v1\">\n <dependentAssembly>\n <assemblyIdentity name=\"mscorlib.resources\" publicKeyToken=\"b77a5c561934e089\"\n culture=\"fr\" /> <!-- change this to your language -->\n\n <bindingRedirect oldVersion=\"1.0.0.0-999.0.0.0\" newVersion=\"999.0.0.0\"/>\n </dependentAssembly>\n <dependentAssembly>\n <assemblyIdentity name=\"System.Xml.resources\" publicKeyToken=\"b77a5c561934e089\"\n culture=\"fr\" /> <!-- change this to your language -->\n\n <bindingRedirect oldVersion=\"1.0.0.0-999.0.0.0\" newVersion=\"999.0.0.0\"/>\n </dependentAssembly>\n\n <!-- add other assemblies and other languages here -->\n\n </assemblyBinding>\n </runtime>\n ...\n</configuration>\n mscorlib System.Xml fr"
},
{
"answer_id": 42831715,
"author": "Ron16",
"author_id": 3061428,
"author_profile": "https://Stackoverflow.com/users/3061428",
"pm_score": -1,
"selected": false,
"text": " try\n {\n int[] a = { 3, 6 };\n Console.WriteLine(a[3]); //Throws index out of bounds exception\n\n System.IO.StreamReader sr = new System.IO.StreamReader(@\"c:\\does-not-exist\"); // throws file not found exception\n throw new System.IO.IOException();\n\n }\n catch (Exception ex)\n {\n\n Console.WriteLine(ex.Message);\n Type t = ex.GetType();\n\n CultureInfo CurrentUICulture = System.Threading.Thread.CurrentThread.CurrentUICulture;\n\n System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(\"en-US\");\n\n object o = Activator.CreateInstance(t);\n\n System.Threading.Thread.CurrentThread.CurrentUICulture = CurrentUICulture; // Changing the UICulture back to earlier culture\n\n\n Console.WriteLine(((Exception)o).Message.ToString());\n Console.ReadLine();\n\n }\n"
},
{
"answer_id": 43524961,
"author": "Tobias Knauss",
"author_id": 2505186,
"author_profile": "https://Stackoverflow.com/users/2505186",
"pm_score": 1,
"selected": false,
"text": "Thread.CurrentUICulture Win32Exception Win32Exception FormatMessage() CreateMessages() SaveMessagesToXML() LoadMessagesFromXML() using System;\nusing System.Collections.Generic;\nusing System.ComponentModel;\nusing System.Globalization;\nusing System.Reflection;\nusing System.Threading;\nusing System.Xml;\n\npublic struct CException\n{\n //----------------------------------------------------------------------------\n public CException(Exception i_oException)\n {\n m_oException = i_oException;\n m_oCultureInfo = null;\n m_sMessage = null;\n }\n\n //----------------------------------------------------------------------------\n public CException(Exception i_oException, string i_sCulture)\n {\n m_oException = i_oException;\n try\n { m_oCultureInfo = new CultureInfo(i_sCulture); }\n catch\n { m_oCultureInfo = CultureInfo.InvariantCulture; }\n m_sMessage = null;\n }\n\n //----------------------------------------------------------------------------\n public CException(Exception i_oException, CultureInfo i_oCultureInfo)\n {\n m_oException = i_oException;\n m_oCultureInfo = i_oCultureInfo == null ? CultureInfo.InvariantCulture : i_oCultureInfo;\n m_sMessage = null;\n }\n\n //----------------------------------------------------------------------------\n // GetMessage\n //----------------------------------------------------------------------------\n public string GetMessage() { return GetMessage(m_oException, m_oCultureInfo); }\n\n public string GetMessage(String i_sCulture) { return GetMessage(m_oException, i_sCulture); }\n\n public string GetMessage(CultureInfo i_oCultureInfo) { return GetMessage(m_oException, i_oCultureInfo); }\n\n public static string GetMessage(Exception i_oException) { return GetMessage(i_oException, CultureInfo.InvariantCulture); }\n\n public static string GetMessage(Exception i_oException, string i_sCulture)\n {\n CultureInfo oCultureInfo = null;\n try\n { oCultureInfo = new CultureInfo(i_sCulture); }\n catch\n { oCultureInfo = CultureInfo.InvariantCulture; }\n return GetMessage(i_oException, oCultureInfo);\n }\n\n public static string GetMessage(Exception i_oException, CultureInfo i_oCultureInfo)\n {\n if (i_oException == null) return null;\n if (i_oCultureInfo == null) i_oCultureInfo = CultureInfo.InvariantCulture;\n\n if (ms_dictCultureExceptionMessages == null) return null;\n if (!ms_dictCultureExceptionMessages.ContainsKey(i_oCultureInfo))\n return CreateMessage(i_oException, i_oCultureInfo);\n\n Dictionary<string, string> dictExceptionMessage = ms_dictCultureExceptionMessages[i_oCultureInfo];\n string sExceptionName = i_oException.GetType().FullName;\n sExceptionName = MakeXMLCompliant(sExceptionName);\n Win32Exception oWin32Exception = (Win32Exception)i_oException;\n if (oWin32Exception != null)\n sExceptionName += \"_\" + oWin32Exception.NativeErrorCode;\n if (dictExceptionMessage.ContainsKey(sExceptionName))\n return dictExceptionMessage[sExceptionName];\n else\n return CreateMessage(i_oException, i_oCultureInfo);\n }\n\n //----------------------------------------------------------------------------\n // CreateMessages\n //----------------------------------------------------------------------------\n public static void CreateMessages(CultureInfo i_oCultureInfo)\n {\n Thread oTH = new Thread(new ThreadStart(CreateMessagesInThread));\n if (i_oCultureInfo != null)\n {\n oTH.CurrentCulture = i_oCultureInfo;\n oTH.CurrentUICulture = i_oCultureInfo;\n }\n oTH.Start();\n while (oTH.IsAlive)\n { Thread.Sleep(10); }\n }\n\n //----------------------------------------------------------------------------\n // LoadMessagesFromXML\n //----------------------------------------------------------------------------\n public static void LoadMessagesFromXML(string i_sPath, string i_sBaseFilename)\n {\n if (i_sBaseFilename == null) i_sBaseFilename = msc_sBaseFilename;\n\n string[] asFiles = null;\n try\n {\n asFiles = System.IO.Directory.GetFiles(i_sPath, i_sBaseFilename + \"_*.xml\");\n }\n catch { return; }\n\n ms_dictCultureExceptionMessages.Clear();\n for (int ixFile = 0; ixFile < asFiles.Length; ixFile++)\n {\n string sXmlPathFilename = asFiles[ixFile];\n\n XmlDocument xmldoc = new XmlDocument();\n try\n {\n xmldoc.Load(sXmlPathFilename);\n XmlNode xmlnodeRoot = xmldoc.SelectSingleNode(\"/\" + msc_sXmlGroup_Root);\n\n string sCulture = xmlnodeRoot.SelectSingleNode(msc_sXmlGroup_Info + \"/\" + msc_sXmlData_Culture).Value;\n CultureInfo oCultureInfo = new CultureInfo(sCulture);\n\n XmlNode xmlnodeMessages = xmlnodeRoot.SelectSingleNode(msc_sXmlGroup_Messages);\n XmlNodeList xmlnodelistMessage = xmlnodeMessages.ChildNodes;\n Dictionary<string, string> dictExceptionMessage = new Dictionary<string, string>(xmlnodelistMessage.Count + 10);\n for (int ixNode = 0; ixNode < xmlnodelistMessage.Count; ixNode++)\n dictExceptionMessage.Add(xmlnodelistMessage[ixNode].Name, xmlnodelistMessage[ixNode].InnerText);\n ms_dictCultureExceptionMessages.Add(oCultureInfo, dictExceptionMessage);\n }\n catch\n { return; }\n }\n }\n\n //----------------------------------------------------------------------------\n // SaveMessagesToXML\n //----------------------------------------------------------------------------\n public static void SaveMessagesToXML(string i_sPath, string i_sBaseFilename)\n {\n if (i_sBaseFilename == null) i_sBaseFilename = msc_sBaseFilename;\n\n foreach (KeyValuePair<CultureInfo, Dictionary<string, string>> kvpCultureExceptionMessages in ms_dictCultureExceptionMessages)\n {\n string sXmlPathFilename = i_sPath + i_sBaseFilename + \"_\" + kvpCultureExceptionMessages.Key.TwoLetterISOLanguageName + \".xml\";\n Dictionary<string, string> dictExceptionMessage = kvpCultureExceptionMessages.Value;\n\n XmlDocument xmldoc = new XmlDocument();\n XmlWriter xmlwriter = null;\n XmlWriterSettings writerSettings = new XmlWriterSettings();\n writerSettings.Indent = true;\n\n try\n {\n XmlNode xmlnodeRoot = xmldoc.CreateElement(msc_sXmlGroup_Root);\n xmldoc.AppendChild(xmlnodeRoot);\n XmlNode xmlnodeInfo = xmldoc.CreateElement(msc_sXmlGroup_Info);\n XmlNode xmlnodeMessages = xmldoc.CreateElement(msc_sXmlGroup_Messages);\n xmlnodeRoot.AppendChild(xmlnodeInfo);\n xmlnodeRoot.AppendChild(xmlnodeMessages);\n\n XmlNode xmlnodeCulture = xmldoc.CreateElement(msc_sXmlData_Culture);\n xmlnodeCulture.InnerText = kvpCultureExceptionMessages.Key.Name;\n xmlnodeInfo.AppendChild(xmlnodeCulture);\n\n foreach (KeyValuePair<string, string> kvpExceptionMessage in dictExceptionMessage)\n {\n XmlNode xmlnodeMsg = xmldoc.CreateElement(kvpExceptionMessage.Key);\n xmlnodeMsg.InnerText = kvpExceptionMessage.Value;\n xmlnodeMessages.AppendChild(xmlnodeMsg);\n }\n\n xmlwriter = XmlWriter.Create(sXmlPathFilename, writerSettings);\n xmldoc.WriteTo(xmlwriter);\n }\n catch (Exception e)\n { return; }\n finally\n { if (xmlwriter != null) xmlwriter.Close(); }\n }\n }\n\n //----------------------------------------------------------------------------\n // CreateMessagesInThread\n //----------------------------------------------------------------------------\n private static void CreateMessagesInThread()\n {\n Thread.CurrentThread.Name = \"CException.CreateMessagesInThread\";\n\n Dictionary<string, string> dictExceptionMessage = new Dictionary<string, string>(0x1000);\n\n GetExceptionMessages(dictExceptionMessage);\n GetExceptionMessagesWin32(dictExceptionMessage);\n\n ms_dictCultureExceptionMessages.Add(Thread.CurrentThread.CurrentUICulture, dictExceptionMessage);\n }\n\n //----------------------------------------------------------------------------\n // GetExceptionTypes\n //----------------------------------------------------------------------------\n private static List<Type> GetExceptionTypes()\n {\n Assembly[] aoAssembly = AppDomain.CurrentDomain.GetAssemblies();\n\n List<Type> listoExceptionType = new List<Type>();\n\n Type oExceptionType = typeof(Exception);\n for (int ixAssm = 0; ixAssm < aoAssembly.Length; ixAssm++)\n {\n if (!aoAssembly[ixAssm].GlobalAssemblyCache) continue;\n Type[] aoType = aoAssembly[ixAssm].GetTypes();\n for (int ixType = 0; ixType < aoType.Length; ixType++)\n {\n if (aoType[ixType].IsSubclassOf(oExceptionType))\n listoExceptionType.Add(aoType[ixType]);\n }\n }\n\n return listoExceptionType;\n }\n\n //----------------------------------------------------------------------------\n // GetExceptionMessages\n //----------------------------------------------------------------------------\n private static void GetExceptionMessages(Dictionary<string, string> i_dictExceptionMessage)\n {\n List<Type> listoExceptionType = GetExceptionTypes();\n for (int ixException = 0; ixException < listoExceptionType.Count; ixException++)\n {\n Type oExceptionType = listoExceptionType[ixException];\n string sExceptionName = MakeXMLCompliant(oExceptionType.FullName);\n try\n {\n if (i_dictExceptionMessage.ContainsKey(sExceptionName))\n continue;\n Exception e = (Exception)(Activator.CreateInstance(oExceptionType));\n i_dictExceptionMessage.Add(sExceptionName, e.Message);\n }\n catch (Exception)\n { i_dictExceptionMessage.Add(sExceptionName, null); }\n }\n }\n\n //----------------------------------------------------------------------------\n // GetExceptionMessagesWin32\n //----------------------------------------------------------------------------\n private static void GetExceptionMessagesWin32(Dictionary<string, string> i_dictExceptionMessage)\n {\n string sTypeName = MakeXMLCompliant(typeof(Win32Exception).FullName) + \"_\";\n for (int iError = 0; iError < 0x4000; iError++) // Win32 errors may range from 0 to 0xFFFF\n {\n Exception e = new Win32Exception(iError);\n if (!e.Message.StartsWith(\"Unknown error (\", StringComparison.OrdinalIgnoreCase))\n i_dictExceptionMessage.Add(sTypeName + iError, e.Message);\n }\n }\n\n //----------------------------------------------------------------------------\n // CreateMessage\n //----------------------------------------------------------------------------\n private static string CreateMessage(Exception i_oException, CultureInfo i_oCultureInfo)\n {\n CException oEx = new CException(i_oException, i_oCultureInfo);\n Thread oTH = new Thread(new ParameterizedThreadStart(CreateMessageInThread));\n oTH.Start(oEx);\n while (oTH.IsAlive)\n { Thread.Sleep(10); }\n return oEx.m_sMessage;\n }\n\n //----------------------------------------------------------------------------\n // CreateMessageInThread\n //----------------------------------------------------------------------------\n private static void CreateMessageInThread(Object i_oData)\n {\n if (i_oData == null) return;\n CException oEx = (CException)i_oData;\n if (oEx.m_oException == null) return;\n\n Thread.CurrentThread.CurrentUICulture = oEx.m_oCultureInfo == null ? CultureInfo.InvariantCulture : oEx.m_oCultureInfo;\n // create new exception in desired culture\n Exception e = null;\n Win32Exception oWin32Exception = (Win32Exception)(oEx.m_oException);\n if (oWin32Exception != null)\n e = new Win32Exception(oWin32Exception.NativeErrorCode);\n else\n {\n try\n {\n e = (Exception)(Activator.CreateInstance(oEx.m_oException.GetType()));\n }\n catch { }\n }\n if (e != null)\n oEx.m_sMessage = e.Message;\n }\n\n //----------------------------------------------------------------------------\n // MakeXMLCompliant\n // from https://www.w3.org/TR/xml/\n //----------------------------------------------------------------------------\n private static string MakeXMLCompliant(string i_sName)\n {\n if (string.IsNullOrEmpty(i_sName))\n return \"_\";\n\n System.Text.StringBuilder oSB = new System.Text.StringBuilder();\n for (int ixChar = 0; ixChar < (i_sName == null ? 0 : i_sName.Length); ixChar++)\n {\n char character = i_sName[ixChar];\n if (IsXmlNodeNameCharacterValid(ixChar, character))\n oSB.Append(character);\n }\n if (oSB.Length <= 0)\n oSB.Append(\"_\");\n return oSB.ToString();\n }\n\n //----------------------------------------------------------------------------\n private static bool IsXmlNodeNameCharacterValid(int i_ixPos, char i_character)\n {\n if (i_character == ':') return true;\n if (i_character == '_') return true;\n if (i_character >= 'A' && i_character <= 'Z') return true;\n if (i_character >= 'a' && i_character <= 'z') return true;\n if (i_character >= 0x00C0 && i_character <= 0x00D6) return true;\n if (i_character >= 0x00D8 && i_character <= 0x00F6) return true;\n if (i_character >= 0x00F8 && i_character <= 0x02FF) return true;\n if (i_character >= 0x0370 && i_character <= 0x037D) return true;\n if (i_character >= 0x037F && i_character <= 0x1FFF) return true;\n if (i_character >= 0x200C && i_character <= 0x200D) return true;\n if (i_character >= 0x2070 && i_character <= 0x218F) return true;\n if (i_character >= 0x2C00 && i_character <= 0x2FEF) return true;\n if (i_character >= 0x3001 && i_character <= 0xD7FF) return true;\n if (i_character >= 0xF900 && i_character <= 0xFDCF) return true;\n if (i_character >= 0xFDF0 && i_character <= 0xFFFD) return true;\n // if (i_character >= 0x10000 && i_character <= 0xEFFFF) return true;\n\n if (i_ixPos > 0)\n {\n if (i_character == '-') return true;\n if (i_character == '.') return true;\n if (i_character >= '0' && i_character <= '9') return true;\n if (i_character == 0xB7) return true;\n if (i_character >= 0x0300 && i_character <= 0x036F) return true;\n if (i_character >= 0x203F && i_character <= 0x2040) return true;\n }\n return false;\n }\n\n private static string msc_sBaseFilename = \"exception_messages\";\n private static string msc_sXmlGroup_Root = \"exception_messages\";\n private static string msc_sXmlGroup_Info = \"info\";\n private static string msc_sXmlGroup_Messages = \"messages\";\n private static string msc_sXmlData_Culture = \"culture\";\n\n private Exception m_oException;\n private CultureInfo m_oCultureInfo;\n private string m_sMessage;\n\n static Dictionary<CultureInfo, Dictionary<string, string>> ms_dictCultureExceptionMessages = new Dictionary<CultureInfo, Dictionary<string, string>>();\n}\n\ninternal class Program\n{\n public static void Main()\n {\n CException.CreateMessages(null);\n CException.SaveMessagesToXML(@\"d:\\temp\\\", \"emsg\");\n CException.LoadMessagesFromXML(@\"d:\\temp\\\", \"emsg\");\n }\n}\n"
},
{
"answer_id": 53167419,
"author": "jan",
"author_id": 4675936,
"author_profile": "https://Stackoverflow.com/users/4675936",
"pm_score": 2,
"selected": false,
"text": "public static string TranslateExceptionMessage(Exception exception, CultureInfo targetCulture)\n{\n Assembly a = exception.GetType().Assembly;\n ResourceManager rm = new ResourceManager(a.GetName().Name, a);\n ResourceSet rsOriginal = rm.GetResourceSet(Thread.CurrentThread.CurrentUICulture, true, true);\n ResourceSet rsTranslated = rm.GetResourceSet(targetCulture, true, true);\n\n var result = exception.Message;\n\n foreach (DictionaryEntry item in rsOriginal)\n {\n if (!(item.Value is string message))\n continue;\n\n string translated = rsTranslated.GetString(item.Key.ToString(), false);\n\n if (!message.Contains(\"{\"))\n {\n result = result.Replace(message, translated);\n }\n else\n {\n var pattern = $\"{Regex.Escape(message)}\";\n pattern = Regex.Replace(pattern, @\"\\\\{([0-9]+)\\}\", \"(?<group$1>.*)\");\n\n var regex = new Regex(pattern);\n\n var replacePattern = translated;\n replacePattern = Regex.Replace(replacePattern, @\"{([0-9]+)}\", @\"${group$1}\");\n replacePattern = replacePattern.Replace(\"\\\\$\", \"$\");\n\n result = regex.Replace(result, replacePattern);\n }\n }\n\n return result;\n}\n"
},
{
"answer_id": 59659725,
"author": "Nabeel Haxxan",
"author_id": 8765805,
"author_profile": "https://Stackoverflow.com/users/8765805",
"pm_score": -1,
"selected": false,
"text": "try\n{\n ......\n}\ncatch (Exception ex)\n{\n throw new UserFriendlyException(L(\"ExceptionmessagesinEnglish\"));\n}\n <text name=\"ExceptionmessagesinEnglish\">Exception Message in English</text>\n"
},
{
"answer_id": 70770332,
"author": "pgermanis",
"author_id": 15893027,
"author_profile": "https://Stackoverflow.com/users/15893027",
"pm_score": 0,
"selected": false,
"text": " //Exception Class Extensions\n public static class ExceptionExtensions\n {\n public static string EnMessage(this Exception ex)\n {\n CultureInfo oldCI = Thread.CurrentThread.CurrentCulture;\n string englishExceptionMessage = ex.Message;\n Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(\"en-US\");\n Thread.CurrentThread.CurrentUICulture = new CultureInfo(\"en-US\");\n try\n {\n var objectType = Type.GetType(ex.GetType().FullName);\n var instantiatedObject = Activator.CreateInstance(objectType); \n throw (Exception)instantiatedObject;\n }\n catch (Exception e)\n {\n englishExceptionMessage = e.Message;\n }\n Thread.CurrentThread.CurrentCulture = oldCI;\n Thread.CurrentThread.CurrentUICulture = oldCI;\n return englishExceptionMessage;\n }\n }\n"
},
{
"answer_id": 74561143,
"author": "Martin Schneider",
"author_id": 1951524,
"author_profile": "https://Stackoverflow.com/users/1951524",
"pm_score": 0,
"selected": false,
"text": "Thread.CurrentUICulture CultureInfo.CurrentUICulture CultureInfo.CurrentUICulture = CultureInfo.InvariantCulture;\n CultureInfo.DefaultThreadCurrentUICulture CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.InvariantCulture;\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209133",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21679/"
] |
209,135
|
<p>When working on some code, I add extra debug logging of some kind to make it easier for me to trace the state and values that I care about for this particular fix.</p>
<p>But if I would check this in into the source code repository, my colleagues would get angry on me for polluting the Log output and polluting the code.</p>
<p>So how do I locally keep these lines of code that are important to me, without checking them in?</p>
<p><strong>Clarification:</strong>
Many answers related to the log output, and that you with log levels can filter that out. And I agree with that.</p>
<p>But. I also mentioned the problem of polluting the actual code. If someone puts a log statement between every other line of code, to print the value of all variables all the time. It really makes the code hard to read. So I would really like to avoid that as well. Basically by not checking in the logging code at all. So the question is: how to keep your own special purpose log lines. So you can use them for your debug builds, without cluttering up the checked in code.</p>
|
[
{
"answer_id": 209179,
"author": "Chris Marasti-Georg",
"author_id": 96,
"author_profile": "https://Stackoverflow.com/users/96",
"pm_score": 2,
"selected": false,
"text": "#if DEBUG\n logger.debug(\"stuff I care about\");\n#endif\n if(logger.isTraceEnabled()) {\n logger.log(\"My expensive logging operation\");\n}\n"
},
{
"answer_id": 209324,
"author": "user28636",
"author_id": 28636,
"author_profile": "https://Stackoverflow.com/users/28636",
"pm_score": 1,
"selected": false,
"text": "#if DEBUG #endif....\n #if MYDEBUGCONFIG \n...your debugging code\n#endif;\n"
},
{
"answer_id": 209332,
"author": "Jonathan Leffler",
"author_id": 15168,
"author_profile": "https://Stackoverflow.com/users/15168",
"pm_score": 2,
"selected": false,
"text": "patch patch -R"
},
{
"answer_id": 244062,
"author": "Omar Kooheji",
"author_id": 20400,
"author_profile": "https://Stackoverflow.com/users/20400",
"pm_score": 0,
"selected": false,
"text": "// ##LOG-START##\nlogger.print(\"OOh A log statment\");\n// ##END-LOG##\n logger.print(\"My Innane log message\"); //##LOG\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209135",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28625/"
] |
209,138
|
<p>I need to make a mouseover menu that opens diagonally (from top-left to bottom-right). </p>
|
[
{
"answer_id": 212069,
"author": "Pier Luigi",
"author_id": 27789,
"author_profile": "https://Stackoverflow.com/users/27789",
"pm_score": 1,
"selected": false,
"text": "$('#mymenu').animate({width: '80px', height: '200px'})\n $('#mymenu').animate({width: '0px', height: '0px', opacity: 'hide'})\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209138",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
209,145
|
<p>When setting the export path in Unix, example:</p>
<pre><code>export PATH=$PATH: $EC2_HOME/bin
</code></pre>
<p>If I quit terminal and open it back up to continue working, I have to go through all the steps again, setting up the paths each time.
I'm wondering how I can set the path and have it "stick" so my system knows where to find everything the next time I open terminal without having to do it all over again.
Thanks!</p>
|
[
{
"answer_id": 209165,
"author": "Mo.",
"author_id": 1870,
"author_profile": "https://Stackoverflow.com/users/1870",
"pm_score": 1,
"selected": false,
"text": ".bashrc"
},
{
"answer_id": 209166,
"author": "JSBձոգչ",
"author_id": 8078,
"author_profile": "https://Stackoverflow.com/users/8078",
"pm_score": 5,
"selected": true,
"text": "~/.bashrc. ~/.shrc export PATH=$PATH:$EC2_HOME/bi\n .bashrc (executed when you shart a shell)\n .bash_profile (executed when you log in)\n .cshrc\n .profile\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209145",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2293/"
] |
209,148
|
<p>What on earth is a caret in the context of a CSplitterWnd class? I can't find any documentation relating explicitly to CSplitterWnds...</p>
<p>EDIT: Specifically, what do these functions <em>actually</em> do:</p>
<pre><code>CWnd * pCurView = m_wndSplitter2.GetPane(2, 0);
pCurView->ShowCaret()
pCurView->HideCaret()
</code></pre>
<p>EDIT2: Please note, I know what a caret is, I am specifically asking about the functions within the context of the CSlitterWnd Class. I have seen the MSDN documentation and it offers no real explaination.</p>
|
[
{
"answer_id": 209321,
"author": "SmacL",
"author_id": 22564,
"author_profile": "https://Stackoverflow.com/users/22564",
"pm_score": 1,
"selected": false,
"text": "CWnd * pCurView = m_wndSplitter2.GetPane(2, 0);\n pCurView->ShowCaret()\n pCurView->HideCaret()\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209148",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18664/"
] |
209,160
|
<p>I want to do something like this :</p>
<pre><code>myYear = record.GetValueOrNull<int?>("myYear"),
</code></pre>
<p>Notice the nullable type as the generic parameter. </p>
<p>Since the <code>GetValueOrNull</code> function could return null my first attempt was this: </p>
<pre><code>public static T GetValueOrNull<T>(this DbDataRecord reader, string columnName)
where T : class
{
object columnValue = reader[columnName];
if (!(columnValue is DBNull))
{
return (T)columnValue;
}
return null;
}
</code></pre>
<p>But the error I'm getting now is:</p>
<blockquote>
<p>The type 'int?' must be a reference type in order to use it as parameter 'T' in the generic type or method</p>
</blockquote>
<p>Right! <code>Nullable<int></code> is a <code>struct</code>! So I tried changing the class constraint to a <code>struct</code> constraint (and as a side effect can't return <code>null</code> any more):</p>
<pre><code>public static T GetValueOrNull<T>(this DbDataRecord reader, string columnName)
where T : struct
</code></pre>
<p>Now the assignment:</p>
<pre><code>myYear = record.GetValueOrNull<int?>("myYear");
</code></pre>
<p>Gives the following error:</p>
<blockquote>
<p>The type 'int?' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method</p>
</blockquote>
<p>Is specifying a nullable type as a generic parameter at all possible?</p>
|
[
{
"answer_id": 209219,
"author": "Greg Dean",
"author_id": 1200558,
"author_profile": "https://Stackoverflow.com/users/1200558",
"pm_score": 9,
"selected": true,
"text": "Nullable<T> static void Main(string[] args)\n{\n int? i = GetValueOrNull<int>(null, string.Empty);\n}\n\n\npublic static Nullable<T> GetValueOrNull<T>(DbDataRecord reader, string columnName) where T : struct\n{\n object columnValue = reader[columnName];\n\n if (!(columnValue is DBNull))\n return (T)columnValue;\n\n return null;\n}\n"
},
{
"answer_id": 210681,
"author": "Robert C. Barth",
"author_id": 9209,
"author_profile": "https://Stackoverflow.com/users/9209",
"pm_score": 6,
"selected": false,
"text": "where return return null return default(T) is if if (columnValue != DBNull.Value)"
},
{
"answer_id": 3367820,
"author": "Toby",
"author_id": 402107,
"author_profile": "https://Stackoverflow.com/users/402107",
"pm_score": 2,
"selected": false,
"text": "public T IsNull<T>(this object value, T nullAlterative)\n{\n if(value != DBNull.Value)\n {\n Type type = typeof(T);\n if (type.IsGenericType && \n type.GetGenericTypeDefinition() == typeof(Nullable<>).GetGenericTypeDefinition())\n {\n type = Nullable.GetUnderlyingType(type);\n }\n\n return (T)(type.IsEnum ? Enum.ToObject(type, Convert.ToInt32(value)) :\n Convert.ChangeType(value, type));\n }\n else \n return nullAlternative;\n}\n"
},
{
"answer_id": 5517264,
"author": "James Jones",
"author_id": 84088,
"author_profile": "https://Stackoverflow.com/users/84088",
"pm_score": 7,
"selected": false,
"text": "public static T GetValueOrDefault<T>(this IDataRecord rdr, int index)\n{\n object val = rdr[index];\n\n if (!(val is DBNull))\n return (T)val;\n\n return default(T);\n}\n decimal? Quantity = rdr.GetValueOrDefault<decimal?>(1);\nstring Unit = rdr.GetValueOrDefault<string>(2);\n"
},
{
"answer_id": 7574875,
"author": "Roland Roos",
"author_id": 967799,
"author_profile": "https://Stackoverflow.com/users/967799",
"pm_score": 3,
"selected": false,
"text": "public T GetValueOrNull<T>(string strElementNameToSearchFor, IFormatProvider provider = null ) \n {\n IFormatProvider theProvider = provider == null ? Provider : provider;\n XElement elm = GetUniqueXElement(strElementNameToSearchFor);\n\n if (elm == null)\n {\n object o = Activator.CreateInstance(typeof(T));\n return (T)o; \n }\n else\n {\n try\n {\n Type type = typeof(T);\n if (type.IsGenericType &&\n type.GetGenericTypeDefinition() == typeof(Nullable<>).GetGenericTypeDefinition())\n {\n type = Nullable.GetUnderlyingType(type);\n }\n return (T)Convert.ChangeType(elm.Value, type, theProvider); \n }\n catch (Exception)\n {\n object o = Activator.CreateInstance(typeof(T));\n return (T)o; \n }\n }\n }\n iRes = helper.GetValueOrNull<int?>(\"top_overrun_length\");\nAssert.AreEqual(100, iRes);\n\n\n\ndecimal? dRes = helper.GetValueOrNull<decimal?>(\"top_overrun_bend_degrees\");\nAssert.AreEqual(new Decimal(10.1), dRes);\n\nString strRes = helper.GetValueOrNull<String>(\"top_overrun_bend_degrees\");\nAssert.AreEqual(\"10.1\", strRes);\n"
},
{
"answer_id": 9350505,
"author": "Ian Kemp",
"author_id": 70345,
"author_profile": "https://Stackoverflow.com/users/70345",
"pm_score": 3,
"selected": false,
"text": "dynamic public static dynamic GetNullableValue(this IDataRecord record, string columnName)\n{\n var val = reader[columnName];\n\n return (val == DBNull.Value ? null : val);\n}\n int? value = myDataReader.GetNullableValue(\"MyColumnName\");\n var value = myDataReader.GetNullableValue(\"MyColumnName\");\n value Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot convert null to 'int' because it is a non-nullable value type\n dynamic"
},
{
"answer_id": 19797877,
"author": "Ryan Horch",
"author_id": 1772730,
"author_profile": "https://Stackoverflow.com/users/1772730",
"pm_score": 2,
"selected": false,
"text": "public static T? GetValueOrNull<T>(this DbDataRecord reader, string columnName)\nwhere T : struct \n{\n return reader[columnName] as T?;\n}\n"
},
{
"answer_id": 25554495,
"author": "nurchi",
"author_id": 461189,
"author_profile": "https://Stackoverflow.com/users/461189",
"pm_score": 2,
"selected": false,
"text": "public static bool GetValueOrDefault<T>(this SqlDataReader Reader, string ColumnName, out T Result)\n{\n try\n {\n object ColumnValue = Reader[ColumnName];\n\n Result = (ColumnValue!=null && ColumnValue != DBNull.Value) ? (T)ColumnValue : default(T);\n\n return ColumnValue!=null && ColumnValue != DBNull.Value;\n }\n catch\n {\n // Possibly an invalid cast?\n return false;\n }\n}\n T ...\ndecimal Quantity;\nif (rdr.GetValueOrDefault<decimal>(\"YourColumnName\", out Quantity))\n{\n // Do something with Quantity\n}\n int.TryParse(\"123\", out MyInt);"
},
{
"answer_id": 41580113,
"author": "Hele",
"author_id": 1935753,
"author_profile": "https://Stackoverflow.com/users/1935753",
"pm_score": 2,
"selected": false,
"text": "... = reader[\"myYear\"] as int?;"
},
{
"answer_id": 43693232,
"author": "Casey Plummer",
"author_id": 704532,
"author_profile": "https://Stackoverflow.com/users/704532",
"pm_score": 3,
"selected": false,
"text": " public static TSource FirstOrNull<TSource>(this IEnumerable<TSource> source)\n where TSource: class\n {\n if (source == null) return null;\n var result = source.FirstOrDefault(); // Default for a class is null\n return result;\n }\n\n public static TSource? FirstOrNullable<TSource>(this IEnumerable<TSource?> source)\n where TSource : struct\n {\n if (source == null) return null;\n var result = source.FirstOrDefault(); // Default for a nullable is null\n return result;\n }\n"
},
{
"answer_id": 62141979,
"author": "Amirhossein Yari",
"author_id": 1945443,
"author_profile": "https://Stackoverflow.com/users/1945443",
"pm_score": 2,
"selected": false,
"text": "public static T ValueOrDefault<T>(this DataRow reader, string columnName) => \n reader.IsNull(columnName) ? default : (T) reader[columnName];\n 0 int null int?"
},
{
"answer_id": 65611953,
"author": "classicSchmosby98",
"author_id": 7368872,
"author_profile": "https://Stackoverflow.com/users/7368872",
"pm_score": 2,
"selected": false,
"text": "public static bool HasValueAndIsNotDefault<T>(this T? v)\n where T : struct\n{\n return v.HasValue && !v.Value.Equals(default(T));\n}\n"
},
{
"answer_id": 71357333,
"author": "Dave Black",
"author_id": 251267,
"author_profile": "https://Stackoverflow.com/users/251267",
"pm_score": 0,
"selected": false,
"text": "public static T GetValue<T>(this DbDataReader reader, string columnName)\n{\n if (reader == null) throw new ArgumentNullException(nameof(reader));\n if (string.IsNullOrWhiteSpace(columnName))\n throw new ArgumentException(\"Value cannot be null or whitespace.\", nameof(columnName));\n\n // do not swallow exceptions here - let them bubble up to the calling API to be handled and/or logged\n var index = reader.GetOrdinal(columnName);\n if (!reader.IsDBNull(index))\n {\n return (T)reader.GetValue(index);\n }\n return default;\n}\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209160",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25145/"
] |
209,192
|
<p>I would like to match the time (10.00) from a string with the date and time ("21.01.08 10.00"). I'm using the following regular expression:</p>
<pre><code>new RegExp("\\b[0-9]{1,2}\\.[0-9]{1,2}\\b" "g");
</code></pre>
<p>But this matches 21.01 from 21.01.08 and 10.00.</p>
<p>I'm using PCRE as my regualar expression engine. </p>
<p>Update:</p>
<p>I'm sorry, i should have more been more clear. The data and time are part of a larger string. I want to extract the time from that string.</p>
<p>For example:</p>
<p>"On 21.01.08 from 10.00 a party will take place in the library"
"21.08.08 - At 10:00 there will be a party"
"On 21.08.08 you are scheduled for a ... . The ... will begin at 10.00"</p>
<p>Is this possible?</p>
|
[
{
"answer_id": 209231,
"author": "Pat",
"author_id": 238,
"author_profile": "https://Stackoverflow.com/users/238",
"pm_score": 0,
"selected": false,
"text": "new RegExp(\"\\\\b[0-9]{1,2}\\\\.[0-9]{1,2}$\" \"g\");\n"
},
{
"answer_id": 209243,
"author": "theraccoonbear",
"author_id": 7210,
"author_profile": "https://Stackoverflow.com/users/7210",
"pm_score": 1,
"selected": false,
"text": "^\\d{2}\\.\\d{2}\\.\\d{2}\\s(\\d{2}\\.\\d{2})$\n if (\"21.01.08 10.00\" =~ m/^\\d{2}\\.\\d{2}\\.\\d{2}\\s(\\d{2}\\.\\d{2})$/g) {\n $time_part = $1;\n}\n Regex r = new Regex(@\"^\\d{2}\\.\\d{2}\\.\\d{2}\\s(\\d{2}\\.\\d{2})$\");\n string dateTimeString = \"21.01.08 10.00\";\n if (r.IsMatch(dateTimeString)) {\n string timePart = r.Match(dateTimeString).Groups[1].Value;\n Console.Write(timePart);\n }\n Console.ReadKey();\n"
},
{
"answer_id": 209444,
"author": "Michael Carman",
"author_id": 8233,
"author_profile": "https://Stackoverflow.com/users/8233",
"pm_score": 3,
"selected": true,
"text": "\\b (?:[^\\d:.]|^)(\\d\\d?[.:]\\d\\d)(?![.:\\d])\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209192",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/948/"
] |
209,193
|
<p>I am creating a left navigation system utilizing xml and xsl. Everything was been going great until I tried to use a special character in my xml document. I am using <code>&raquo;</code> and I get th error.</p>
<blockquote>
<p>reason: Reference to undefined entity 'raquo'.<br>
error code: -1072898046</p>
</blockquote>
<p>How do I make this work?</p>
|
[
{
"answer_id": 209272,
"author": "Pat",
"author_id": 238,
"author_profile": "https://Stackoverflow.com/users/238",
"pm_score": 3,
"selected": false,
"text": "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n » « instead of » and «\n"
},
{
"answer_id": 209294,
"author": "Joe Lencioni",
"author_id": 18986,
"author_profile": "https://Stackoverflow.com/users/18986",
"pm_score": 5,
"selected": false,
"text": "» » <!ENTITY entity-name \"entity-value\">\n<!ENTITY raquo \"»\">\n »\n"
},
{
"answer_id": 209300,
"author": "Rontologist",
"author_id": 13925,
"author_profile": "https://Stackoverflow.com/users/13925",
"pm_score": 1,
"selected": false,
"text": "» becomes »\n <![CDATA[»]]>\n <!DOCTYPE ROOT_XML_ELEMENT [ <!ENTITY raquo \"»\"> ]>\n"
},
{
"answer_id": 210035,
"author": "Robert Rossney",
"author_id": 19403,
"author_profile": "https://Stackoverflow.com/users/19403",
"pm_score": 2,
"selected": false,
"text": " XmlDocument d = new XmlDocument();\n d.LoadXml(\"<foo/>\");\n char c = (char)187;\n d.DocumentElement.InnerText = \"Here's that character: \" + c;\n Debug.WriteLine(d.OuterXml);\n d.DocumentElement.InnerText = \"Here it is as an HTML entity: »\";\n Debug.WriteLine(d.OuterXml);\n <foo>Here's that character: »</foo>\n<foo>Here it is as an HTML entity: &raquo;</foo>\n » &raquo;"
},
{
"answer_id": 212511,
"author": "Ben Bryant",
"author_id": 28953,
"author_profile": "https://Stackoverflow.com/users/28953",
"pm_score": 0,
"selected": false,
"text": "» »"
},
{
"answer_id": 3863983,
"author": "BungleFeet",
"author_id": 205821,
"author_profile": "https://Stackoverflow.com/users/205821",
"pm_score": 0,
"selected": false,
"text": "» <xsl:output use-character-maps=\"raquo.ent\"/>\n<xsl:character-map name=\"raquo.ent\">\n <xsl:output-character character=\"»\" string=\"&raquo;\"/>\n</xsl:character-map>\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209193",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27516/"
] |
209,198
|
<p>I am using Borland Turbo C++ with some inlined assembler code, so presumably Turbo Assembler (TASM) style assembly code. I wish to do the following:</p>
<pre><code>void foo::bar( void )
{
__asm
{
mov eax, SomeLabel
// ...
}
// ...
SomeLabel:
// ...
}
</code></pre>
<p>So the address of SomeLabel is placed into EAX. This doesn't work and the compiler complains of: Undefined symbol 'SomeLabel'.</p>
<p>In Microsoft Assembler (MASM) the dollar symbol ($) serves as the current location counter, which would be useful for my purpose. But again this does not seem to work in Borlands Assember (expression syntax error).</p>
<p>Update: To be a little more specific, I need the compiler to generate the address it moves into eax as a constant during compilation/linking and not at run time, so it will compile like "mov eax, 0x00401234".</p>
<p>Can anybody suggest how to get this working?</p>
<p>UPDATE: To respond to Pax's question (see comment), If the base address is changed at run time by the Windows loader the DLL/EXE PE image will still be relocated by the Windows loader and the labels address will be patched at run time by the loader to use the re-based address so using a compile/link time value for the label address is not an issue.</p>
<p>Many thanks in advance.</p>
|
[
{
"answer_id": 209359,
"author": "Sean",
"author_id": 4919,
"author_profile": "https://Stackoverflow.com/users/4919",
"pm_score": 0,
"selected": false,
"text": "int result=0;\n\n__asm__ {\n mov result, 1\n}\n\nswitch (result){\n case 1: printf(\"You wanted case 1 to happen in your assembler\\n\"); break;\n case 0: printf(\"Nothing changed with the result variable.. defaulting to:\\n\");\n default: printf(\"Default case!\\n\"); break;\n}\n"
},
{
"answer_id": 482797,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 1,
"selected": false,
"text": "__asm lea mov"
},
{
"answer_id": 483740,
"author": "Skizz",
"author_id": 1898,
"author_profile": "https://Stackoverflow.com/users/1898",
"pm_score": 0,
"selected": false,
"text": "// get_address\n// gets the address of the instruction following the call\n// to this function, for example\n// int addr = get_address (); // effectively returns the address of 'label'\n// label:\nint get_address ()\n{\n int address;\n asm\n {\n mov eax,[esp+8]\n mov address,eax\n }\n return address;\n}\n// get_label_address\n// a bit like get_address but returns the address of the instruction pointed\n// to by the jmp instruction after the call to this function, for example:\n// int addr;\n// asm\n// {\n// call get_label_address // gets the address of 'label'\n// jmp label\n// mov addr,eax\n// }\n// <some code>\n// label:\n// note that the function should only be called from within an asm block.\nint get_label_address()\n{\n int address = 0;\n asm\n {\n mov esi,[esp+12]\n mov al,[esi]\n cmp al,0ebh\n jne not_short\n movsx eax,byte ptr [esi+1]\n lea eax,[eax+esi-1]\n mov address,eax\n add esi,2\n mov [esp+12],esi\n jmp done\n not_short:\n cmp al,0e9h\n jne not_long\n mov eax,dword ptr [esi+1]\n lea eax,[eax+esi+2]\n mov address,eax\n add esi,5\n mov [esp+12],esi\n jmp done\n not_long:\n // handle other jmp forms or generate an error\n done:\n }\n return address;\n}\nint main(int argc, char* argv[])\n{\n int addr1,addr2;\n asm\n {\n call get_label_address\n jmp Label1\n mov addr1,eax\n }\n\n addr2 = get_address ();\nLabel1:\n return 0;\n}\n"
},
{
"answer_id": 487139,
"author": "Ivan Vučica",
"author_id": 39974,
"author_profile": "https://Stackoverflow.com/users/39974",
"pm_score": 0,
"selected": false,
"text": "void foo::bar( void )\n{\n __asm\n {\n mov eax, SomeLabel\n // ...\n }\n // ...\n __asm\n {\n SomeLabel:\n // ...\n }\n // ...\n}\n"
},
{
"answer_id": 487497,
"author": "Kim Reece",
"author_id": 1911072,
"author_profile": "https://Stackoverflow.com/users/1911072",
"pm_score": 2,
"selected": false,
"text": "#include <stdio.h>\nint main()\n{\n void *too = &&SomeLabel;\n unsigned int out;\n asm\n (\n \"movl %0, %%eax;\"\n :\"=a\"(out)\n :\"r\"(&&SomeLabel)\n );\nSomeLabel:\n printf(\"Result: %p %x\\n\", too, out);\n\n return 0;\n}\n ...\n movl $.L2, %eax\n...\n.L2:\n"
},
{
"answer_id": 508507,
"author": "Michael Burr",
"author_id": 12711,
"author_profile": "https://Stackoverflow.com/users/12711",
"pm_score": 1,
"selected": false,
"text": "mov eax, offset SomeLabel\n goto int foo()\n{\n int x = 3;\n printf( \"x =%d\\n\", x);\n goto SomeLabel;\n //\n __asm {\n mov eax, 0x01\n }\n //\nSomeLabel:\n printf( \"x =%d\\n\", x);\n //\n return x;\n}\n"
},
{
"answer_id": 4172533,
"author": "greatwolf",
"author_id": 234175,
"author_profile": "https://Stackoverflow.com/users/234175",
"pm_score": 0,
"selected": false,
"text": "void foo::bar( void )\n{\n __asm\n {\n mov eax, offset SomeLabel\n // ...\n }\n // ...\n __asm SomeLabel:\n // ...\n}\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209198",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14260/"
] |
209,199
|
<p>The <a href="http://msdn.microsoft.com/en-us/library/bb384061.aspx" rel="noreferrer">var</a> keyword does away with the need for an explicit type declaration and I have read with interest the <a href="https://stackoverflow.com/questions/41479/use-of-var-keyword-in-c">SO discussion</a> of when it might be appropriate.</p>
<p>I have also read about (but not used) <a href="https://github.com/boo-lang/boo" rel="noreferrer">Boo</a> which seems to take things a step further by making it <a href="https://github.com/boo-lang/boo/wiki/Type-Inference" rel="noreferrer">optional to declare a local variable</a>. With Boo, both the type and the declaration can be implied.</p>
<p>Which leads me to wonder, why did the C# language designers bother to include a var keyword at all? </p>
<p><strong>Update</strong>: Yes, var supports Anonymous types, but anonymous types by themselves do not necessitate the var keyword...</p>
<pre><code>var anon = new { Name = "Terry", Age = 34 };
</code></pre>
<p>versus</p>
<pre><code>anon = new { Name = "Terry", Age = 34 };
</code></pre>
|
[
{
"answer_id": 209225,
"author": "Ferruccio",
"author_id": 4086,
"author_profile": "https://Stackoverflow.com/users/4086",
"pm_score": 6,
"selected": false,
"text": "name = \"fred\";\n ...\nName = \"barney\"; // whoops! we meant to reuse name\n"
},
{
"answer_id": 209239,
"author": "Jason Jackson",
"author_id": 13103,
"author_profile": "https://Stackoverflow.com/users/13103",
"pm_score": 3,
"selected": false,
"text": "var myVariable = SomeCodeToSetVariableHere;\nmyVariable = SomeOtherCodeTOSetVariable;\n myVariable = SomeCodeToSetVariableHere;\nmyVariable = SomeOtherCodeTOSetVariable;\n"
},
{
"answer_id": 209261,
"author": "JSBձոգչ",
"author_id": 8078,
"author_profile": "https://Stackoverflow.com/users/8078",
"pm_score": 7,
"selected": true,
"text": "SomeGeneric<VeryLongTypename<NestedTypename>> thing = new \nSomeGeneric<VeryLongTypename<NestedTypename>>();\n var thing = new SomeGeneric<VeryLongTypename<NestedTypename>>();\n"
},
{
"answer_id": 209314,
"author": "Bill K",
"author_id": 12943,
"author_profile": "https://Stackoverflow.com/users/12943",
"pm_score": 2,
"selected": false,
"text": "bill=5;\nbi11=bill+5\n DataOutputStream ds=new DataOutputStream();\n DataOutput ds=new DataOutputStream();\n"
},
{
"answer_id": 209409,
"author": "Joel Coehoorn",
"author_id": 3043,
"author_profile": "https://Stackoverflow.com/users/3043",
"pm_score": 3,
"selected": false,
"text": "var anon anon = new { Name = \"Terry\", Age = 34 };\n"
},
{
"answer_id": 804561,
"author": "Kelsey",
"author_id": 8707,
"author_profile": "https://Stackoverflow.com/users/8707",
"pm_score": 5,
"selected": false,
"text": "// What myVar is, is obvious\nSomeObject myVar = new SomeObject();\n\n// What myVar is, is obvious here as well\nvar myVar = new SomeObject();\n // WTF is var without really knowing what GetData() returns?\n// Now the var shortcut is making me look somewhere else when this should\n// just be readable!\nvar myVar = GetData();\n\n// If the developer would have just done it explicitly it would actually\n// be easily readable.\nSomeObject myVar = GetData();\n var weight = GetExactWeightOfTheBrownYakInKilograms();\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209199",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4200/"
] |
209,224
|
<p>I have to consume 2 different web services. Both contain a definition for a 'user' object. </p>
<p>When I reference the services using "Add service reference" I give each service a unique namespace:</p>
<pre><code>com.xyz.appname.ui.usbo.UserManagement
com.xyz.appname.ui.usbo.AgencyManagement
</code></pre>
<p>The problem I have is that each one of the proxies that are generated contain a new user class. One is located at com.xyz.appname.ui.usbo.UserManagement.user and the other at com.xyz.appname.ui.usbo.AgencyManagement.user. However, the user objects are identical and I would like to treat them as such.</p>
<p>Is there a way that I can somehow reference the user object as one object instead of treating them as two different?</p>
<p>I am using .Net 3.5 to consume the service. The service being consumed is written in Java.</p>
<p>Thanks!!</p>
<p>Edit:</p>
<p><a href="http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/8c55f517-72c0-4add-8f9d-264acd334e83/" rel="noreferrer" title="This forum thread">This forum thread</a> got very close to an answer, but the accepted answer ended up being to share types from client and server - which I cannot do because we're crossing platforms (Java to .Net). The real question is, is there a /sharetypes type of parameter for svcutil in WCF?</p>
|
[
{
"answer_id": 209277,
"author": "leppie",
"author_id": 15541,
"author_profile": "https://Stackoverflow.com/users/15541",
"pm_score": 2,
"selected": false,
"text": "/sharetypes\n Turns on type sharing feature. This feature creates one code file with\n a single type definition for identical types shared between different\n services (namespace, name and wire signature must be identical).\n Reference the services with http:// URLs as command-line parameters\n or create a discomap document for local files.\n"
},
{
"answer_id": 2929365,
"author": "CJBrew",
"author_id": 177762,
"author_profile": "https://Stackoverflow.com/users/177762",
"pm_score": 2,
"selected": false,
"text": "wsdl.exe /sharetypes file://c:\\path\\to\\file.wsdl file://c:\\path\\to\\otherFile.wsdl /namespace:<your namespace> /output:(any switches etc...)\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209224",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10589/"
] |
209,237
|
<p>I know I should be using htmlentities for all my form text input fields but this doesn't work:</p>
<pre><code><?php
echo "<tr>
<td align=\"right\">".Telephone." :</td>
<td><input type=\"text\" name=\"telephone\" size=\"27\"
value=\"htmlentities($row[telephone])\"> Inc. dialing codes
</td>
</tr>";
?>
</code></pre>
<p>It simply shows the input value as "htmlentities(0123456789)" in the form? What have I done wrong please?</p>
|
[
{
"answer_id": 209246,
"author": "workmad3",
"author_id": 16035,
"author_profile": "https://Stackoverflow.com/users/16035",
"pm_score": 3,
"selected": false,
"text": "value=\\\"\" . htmlentities($row[telephone]) . \"\\\"\n"
},
{
"answer_id": 209248,
"author": "Quentin",
"author_id": 19068,
"author_profile": "https://Stackoverflow.com/users/19068",
"pm_score": 2,
"selected": false,
"text": "<tr>\n <td align=\"right\">\n <label for=\"telephone\">Telephone:</label>\n </td> \n <td>\n <input type=\"text\" \n name=\"telephone\" \n id=\"telephone\"\n size=\"27\" \n value=\"<?php \n echo htmlentities($row[telephone]); \n ?>\"> \n Inc. dialing codes \n </td>\n</tr>\n"
},
{
"answer_id": 209251,
"author": "eyelidlessness",
"author_id": 17964,
"author_profile": "https://Stackoverflow.com/users/17964",
"pm_score": 0,
"selected": false,
"text": "<tr>\n <td align=\"right\">Telephone :</td>\n <td><input type=\"text\" name=\"telephone\" size=\"27\"\n value=\"<?php echo htmlentities($row['telephone']); ?>\"> Inc. dialing codes</td>\n</tr>\n"
},
{
"answer_id": 209253,
"author": "Darryl Hein",
"author_id": 5441,
"author_profile": "https://Stackoverflow.com/users/5441",
"pm_score": 1,
"selected": false,
"text": "<?php echo '<tr>\n <td align=\"right\">' . Telephone . ' :</td> \n <td><input type=\"text\" name=\"telephone\" size=\"27\" value=\"' . htmlentities($row[telephone]) . '\" /> Inc. dialing codes</td> \n </tr>';\n"
},
{
"answer_id": 209274,
"author": "Lucas Oman",
"author_id": 6726,
"author_profile": "https://Stackoverflow.com/users/6726",
"pm_score": 1,
"selected": false,
"text": "<?php\necho \" <tr>\n <td align=\\\"right\\\">Telephone :</td> \n <td><input type=\\\"text\\\" name=\\\"telephone\\\" size=\\\"27\\\" value=\\\"\".htmlentities($row[telephone]).\"\\\"> Inc. dialing codes</td> \n </tr>\";\n?>\n"
},
{
"answer_id": 210064,
"author": "Martijn Gorree",
"author_id": 23381,
"author_profile": "https://Stackoverflow.com/users/23381",
"pm_score": 1,
"selected": false,
"text": "htmlspecialchars($row[telephone], ENT_QUOTES);"
},
{
"answer_id": 12658181,
"author": "John Fro",
"author_id": 1709196,
"author_profile": "https://Stackoverflow.com/users/1709196",
"pm_score": 1,
"selected": false,
"text": "$txt = <<<HERETEXT\nPut your HTML here.\nHERETEXT;\n\necho $txt;\n $he = 'htmlentities';\n\n$txt = <<<HERETEXT\n{$he($string, ENT_QUOTES, 'UTF-8')}\nHERETEXT;\n\necho $txt;\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209237",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
209,254
|
<p>I'm writing a web application that decodes Morse Code that is tapped in using mouse button.</p>
<p>I originally did a proof of concept using conventional JavaScript, but now I'm redoing it using jQuery.</p>
<p>Is there a clever way with jQuery to tell if a button has been pressed again within so many milliseconds, or not - and run some jQuery code if the button was NOT pressed again.</p>
<p>I've been going over the jQuery API and I'm not seeing a clever way of doing this....</p>
<p>Any ideas...</p>
<p>Derek</p>
|
[
{
"answer_id": 209358,
"author": "Pseudo Masochist",
"author_id": 8529,
"author_profile": "https://Stackoverflow.com/users/8529",
"pm_score": 1,
"selected": false,
"text": "setTimeout() clearTimeout()"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209254",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5440/"
] |
209,255
|
<p>I've got a unidirectional tree of objects, in which each objects points to its parent. Given an object, I need to obtain its entire subtree of descendants, as a collection of objects. The objects are not actually in any data structure, but I can easily get a collection of all the objects.</p>
<p>The naive approach is to examine each object in the batch, see if the given object is an ancestor, and keep it aside. This would not be too efficient... It carries an overhead of O(N*N), where N is the number of objects.</p>
<p>Another approach is the recursive one, meaning search for the object's direct children and repeat the process for the next level. Unfortunately the tree is unidirectional... there's no direct approach to the children, and this would be only slightly less costly than the previous approach.</p>
<p>My question: Is there an efficient algorithm I'm overlooking here?</p>
<p>Thanks,</p>
<p>Yuval =8-)</p>
|
[
{
"answer_id": 209450,
"author": "matt b",
"author_id": 4249,
"author_profile": "https://Stackoverflow.com/users/4249",
"pm_score": 3,
"selected": true,
"text": "public static Set<Node> findDescendants(List<Node> allNodes, Node thisNode) {\n\n // keep a map of Nodes to a List of that Node's direct children\n Map<Node, List<Node>> map = new HashMap<Node, List<Node>>();\n\n // populate the map - this is O(n) since we examine each and every node\n // in the list\n for (Node n : allNodes) {\n\n Node parent = n.getParent();\n if (parent != null) {\n\n List<Node> children = map.get(parent);\n if (children == null) {\n // instantiate list\n children = new ArrayList<Node>();\n map.put(parent, children);\n }\n children.add(n);\n }\n }\n\n\n // now, create a collection of thisNode's children (of all levels)\n Set<Node> allChildren = new HashSet<Node>();\n\n // keep a \"queue\" of nodes to look at\n List<Node> nodesToExamine = new ArrayList<Node>();\n nodesToExamine.add(thisNode);\n\n while (nodesToExamine.isEmpty() == false) {\n // pop a node off the queue\n Node node = nodesToExamine.remove(0);\n\n List<Node> children = map.get(node);\n if (children != null) {\n for (Node c : children) {\n allChildren.add(c);\n nodesToExamine.add(c);\n }\n }\n }\n\n return allChildren;\n}\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209255",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2819/"
] |
209,257
|
<p>I getting the following error when I try to connect to my server app using remoting:</p>
<blockquote>
<p><em>A problem seems to have occured whilst connecting to the remote server:<br>
Server encountered an internal error. For more information, turn off customErrors in the server's .config file.</em></p>
</blockquote>
<p>This is the code on my server app:</p>
<pre><code>TcpChannel tcpChannel = new TcpChannel(999);
MyRemoteObject remObj = new MyRemoteObject (this);
RemotingServices.Marshal(remObj, "MyUri");
ChannelServices.RegisterChannel(tcpChannel);
</code></pre>
<p>It seems to work the first time, but unless the server app is restarted the error occurs.</p>
<p>I would guess something isn't being cleaned up properly but I'm not sure what as the customError is still on.</p>
<p>Any ideas where I start. Thanks.</p>
<p>[EDIT] - Thanks to Gulzar, I modified my code above to the following and now the errors are shown:</p>
<pre><code>RemotingConfiguration.CustomErrorsMode = CustomErrorsModes.Off;
TcpChannel tcpChannel = new TcpChannel(999);
MyRemoteObject remObj = new MyRemoteObject (this);
RemotingServices.Marshal(remObj, "MyUri");
ChannelServices.RegisterChannel(tcpChannel);
</code></pre>
|
[
{
"answer_id": 209278,
"author": "Gulzar Nazim",
"author_id": 4337,
"author_profile": "https://Stackoverflow.com/users/4337",
"pm_score": 6,
"selected": true,
"text": "<ServerEXE>.config <?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<configuration>\n <system.runtime.remoting> \n <customErrors mode=\"off\" />\n </system.runtime.remoting>\n</configuration>\n"
},
{
"answer_id": 209293,
"author": "DOK",
"author_id": 27637,
"author_profile": "https://Stackoverflow.com/users/27637",
"pm_score": 0,
"selected": false,
"text": "web.config file customErrors <customErrors mode=\"Off\"/>"
},
{
"answer_id": 209344,
"author": "sometimes",
"author_id": 21344,
"author_profile": "https://Stackoverflow.com/users/21344",
"pm_score": 3,
"selected": false,
"text": "RemotingConfiguration.CustomErrorsEnabled(bool);\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209257",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11989/"
] |
209,258
|
<p>I am trying to use a third party DLL that wants an int** as one of the parameters to the method. It describes the parameter as the address of the pointer that will point to the memory allocation.</p>
<p>Sorry for any confusion. The parameter is two-way I think. The DLL is for talking to an FPGA board and the method is setting up DMA transfer between the host PC and the PCI board.</p>
|
[
{
"answer_id": 209267,
"author": "Mark Cidade",
"author_id": 1659,
"author_profile": "https://Stackoverflow.com/users/1659",
"pm_score": 4,
"selected": true,
"text": "System.IntPtr [DllImport(\"thirdparty.dll\")]\n static extern long ThirdPartyFunction(ref IntPtr arg);\n\n long f(int[] array)\n { long retval = 0;\n int size = Marshal.SizeOf(typeof(int));\n var ptr = IntPtr.Zero;\n\n try \n { ptr = Marshal.AllocHGlobal(size * array.Length);\n\n for (int i= 0; i < array.Length; ++i) \n { IntPtr tmpPtr = new IntPtr(ptr.ToInt64() + (i * size));\n Marshal.StructureToPtr(array, tmpPtr, false);\n }\n\n retval = ThirdPartyFunction(ref ptr);\n }\n finally \n { if (ptr != IntPtr.Zero) Marshal.FreeHGlobal(ptr);\n }\n\n return retval;\n }\n"
},
{
"answer_id": 209270,
"author": "leppie",
"author_id": 15541,
"author_profile": "https://Stackoverflow.com/users/15541",
"pm_score": 1,
"selected": false,
"text": "ref int[] list"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209258",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1629/"
] |
209,281
|
<p>I am aware that you can lock an object in c# using lock but can you give up the lock and wait for something else to notify you that it's changed like you can in java with wait and notify?</p>
<p>It seems to me that synchronised and lock in java and c# respectively are synonomous.</p>
|
[
{
"answer_id": 209319,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 8,
"selected": true,
"text": "foo.notify() => Monitor.Pulse(foo)\nfoo.notifyAll() => Monitor.PulseAll(foo)\nfoo.wait() => Monitor.Wait(foo)\n lock Monitor.Enter Monitor.Exit"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209281",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20400/"
] |
209,301
|
<p>How do I post a form from an HTML page to and ASPX page (2.0) and be able to read the values?</p>
<p>I currently have an ASP.NET site using the Membership provider and everything is working fine. Users can log in from the Login.aspx page.</p>
<p>We now want to be able to have users log in directly from another web site--which is basically a static HTML page. The users need to be able to enter their name and password on this HTML page and have it POST to my Login.aspx page (where I can then log them in manually).</p>
<p>Is it possible to pass form values from HTML to ASPX? I have tried everything and the Request.Form.Keys collection is always empty. I can't use a HTTP GET as these are credentials and can't be passed on a query string.</p>
<p>The only way I know of is an iframe.</p>
|
[
{
"answer_id": 209455,
"author": "Pseudo Masochist",
"author_id": 8529,
"author_profile": "https://Stackoverflow.com/users/8529",
"pm_score": 5,
"selected": false,
"text": "<form id=\"form1\" runat=\"server\">\n <div>\n <asp:TextBox ID=\"TextBox1\" runat=\"server\"></asp:TextBox>\n <asp:TextBox TextMode=\"password\" ID=\"TextBox2\" runat=\"server\"></asp:TextBox>\n <asp:Button ID=\"Button1\" runat=\"server\" Text=\"Button\" />\n </div>\n</form>\n Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load\n For Each s As String In Request.Form.AllKeys\n Response.Write(s & \": \" & Request.Form(s) & \"<br />\")\n Next\nEnd Sub\n <form action=\"http://localhost/MyTestApp/Default.aspx\" method=\"post\">\n <input name=\"TextBox1\" type=\"text\" value=\"\" id=\"TextBox1\" />\n <input name=\"TextBox2\" type=\"password\" id=\"TextBox2\" />\n <input type=\"submit\" name=\"Button1\" value=\"Button\" id=\"Button1\" />\n</form>\n"
},
{
"answer_id": 22559051,
"author": "user3446429",
"author_id": 3446429,
"author_profile": "https://Stackoverflow.com/users/3446429",
"pm_score": 1,
"selected": false,
"text": "<html><body> <form id='postForm' action='WebForm.aspx' method='POST'>\n <input type='text' name='postData' value='base-64-encoded-value' />\n <input type='hidden' name='__VIEWSTATE' value='' /> <!-- still need __VIEWSTATE, even empty one -->\n </form>\n\n</body></html>\n <%@ Page Language=\"C#\" AutoEventWireup=\"true\" \nCodeBehind=\"WebForm.aspx.cs\" Inherits=\"WebForm\"\n EnableEventValidation=\"False\" EnableViewState=\"false\" %>\n\n<!DOCTYPE html>\n\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<head runat=\"server\">\n <title></title>\n</head>\n<body>\n <form id=\"postForm\" runat=\"server\">\n <asp:TextBox ID=\"postData\" runat=\"server\"></asp:TextBox>\n <div>\n\n </div>\n </form>\n</body>\n</html>\n EnableEventValidation=\"False\", EnableViewState=\"false\" public partial class WebForm : System.Web.UI.Page\n{\n protected void Page_Load(object sender, EventArgs e)\n {\n string value = Encoding.Unicode.GetString(Convert.FromBase64String(this.postData.Text));\n }\n}\n"
},
{
"answer_id": 22595430,
"author": "Vinay Krishna Kudtarkar",
"author_id": 3452967,
"author_profile": "https://Stackoverflow.com/users/3452967",
"pm_score": 0,
"selected": false,
"text": " if (!IsPostBack)\n {\n CompleteRegistration();\n }\n }\n NameValueCollection nv = Request.Form;\n if (nv.Count != 0)\n {\n string strname = nv[\"txtbox1\"];\n string strPwd = nv[\"txtbox2\"];\n }\n }\n"
},
{
"answer_id": 67869340,
"author": "Aravamudan",
"author_id": 16152564,
"author_profile": "https://Stackoverflow.com/users/16152564",
"pm_score": -1,
"selected": false,
"text": "<FORM NAME=\"Logon\" action=\"default\" method=\"post\">"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209301",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
209,305
|
<p>I'm writing a C/C++ application under Linux that reads data from a raw socket (for ICMP packets). Question: is there a way to discard all data that is still queued on the socket?</p>
<p>The problem is that after sleeping for a while, there is data queued up on the socket which I'm not interested in; so it would be best to just tell the socket "forget all data you have buffered right now", so that if I go into a select()/recvfrom() loop then, I only get data that was received recently.</p>
<p>Is there a better way than going into a separate poll()/recvfrom() loop first? Some socket API call maybe? Portable, even? :-)</p>
|
[
{
"answer_id": 219923,
"author": "Tim Howland",
"author_id": 4276,
"author_profile": "https://Stackoverflow.com/users/4276",
"pm_score": 0,
"selected": false,
"text": "for(n=0;n<=MAX_BUFFER_SIZE;n++)\n{\nrecv_buffer[n] = 0;\n}\n"
},
{
"answer_id": 219946,
"author": "Adam Rosenfield",
"author_id": 9530,
"author_profile": "https://Stackoverflow.com/users/9530",
"pm_score": 2,
"selected": true,
"text": "recvfrom()"
},
{
"answer_id": 221682,
"author": "JayG",
"author_id": 5823,
"author_profile": "https://Stackoverflow.com/users/5823",
"pm_score": 3,
"selected": false,
"text": " int optval = 0; /* May need to be 1 on some platforms */\n\n setsockopt(sockDesc, SOL_SOCKET, SO_RCVBUF, (char *)(&optval), sizeof(optval));\n"
},
{
"answer_id": 228897,
"author": "user30684",
"author_id": 30684,
"author_profile": "https://Stackoverflow.com/users/30684",
"pm_score": 2,
"selected": false,
"text": "while (1)\n{\n\n FD_ZERO (&sockets);\n FD_SET (raw_socket, &sockets);\n\n timeout.tv_sec = 1;\n timeout.tv_usec = 0;\n\n if (select (raw_socket + 1, &sockets, NULL, NULL, &timeout))\n {\n if (FD_ISSET (raw_socket, &sockets))\n {\n // handle the packet\n }\n }\n else\n {\n /* Select Timed Out */\n fprintf(stderr, \"Timed out\");\n }\n} \n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209305",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2148773/"
] |
209,320
|
<p>I have an activex object I loaded into an html page. I then use that activex object to create another object, but I need to register an event with the new object created. The object is expecting an event listener of a certain type.</p>
<p>I can load this same dll in c# and it will work fine. Code looks like this for c#.</p>
<pre><code>upload = obj.constructUploadObj(uploadConfig);
upload.stateChanged += new UploadActionEvents_stateChangedEventHandler(upload_stateChanged);
</code></pre>
<p>In javascript I have similar code however I cannot get the event registered with the object.</p>
<pre><code>uploadAction = obj.constructUploadObj(uploadConfig);
uploadAction.stateChanged = upload_stateChanged;
function upload_stateChanged(sender){
writeLine("uploadState changed " + sender.getState());
}
</code></pre>
<p>I have enumerated some of the properties of the uploadAction object in javascript to ensure that it is actually created. When I try and register the event with uploadAction it throws an error saying "Object doesn't support this property or method."</p>
<p>To me it seems like its expecting a strongly typed event. Is there anyway to register the event similar to that of C# in javascript?</p>
<p>Thanks In Advance.</p>
|
[
{
"answer_id": 219923,
"author": "Tim Howland",
"author_id": 4276,
"author_profile": "https://Stackoverflow.com/users/4276",
"pm_score": 0,
"selected": false,
"text": "for(n=0;n<=MAX_BUFFER_SIZE;n++)\n{\nrecv_buffer[n] = 0;\n}\n"
},
{
"answer_id": 219946,
"author": "Adam Rosenfield",
"author_id": 9530,
"author_profile": "https://Stackoverflow.com/users/9530",
"pm_score": 2,
"selected": true,
"text": "recvfrom()"
},
{
"answer_id": 221682,
"author": "JayG",
"author_id": 5823,
"author_profile": "https://Stackoverflow.com/users/5823",
"pm_score": 3,
"selected": false,
"text": " int optval = 0; /* May need to be 1 on some platforms */\n\n setsockopt(sockDesc, SOL_SOCKET, SO_RCVBUF, (char *)(&optval), sizeof(optval));\n"
},
{
"answer_id": 228897,
"author": "user30684",
"author_id": 30684,
"author_profile": "https://Stackoverflow.com/users/30684",
"pm_score": 2,
"selected": false,
"text": "while (1)\n{\n\n FD_ZERO (&sockets);\n FD_SET (raw_socket, &sockets);\n\n timeout.tv_sec = 1;\n timeout.tv_usec = 0;\n\n if (select (raw_socket + 1, &sockets, NULL, NULL, &timeout))\n {\n if (FD_ISSET (raw_socket, &sockets))\n {\n // handle the packet\n }\n }\n else\n {\n /* Select Timed Out */\n fprintf(stderr, \"Timed out\");\n }\n} \n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209320",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21664/"
] |
209,327
|
<p>How should I format URLs with special/international characters?</p>
<p>Currently I try to make URLs "look good", so that: </p>
<pre><code>www.myhost.com/this is a test, do you know how?
</code></pre>
<p>is converted to: </p>
<pre><code>www.myhost.com/this_is_a_test_do_you_know_how
</code></pre>
<p>I know some international letters could be converted (ü = ue, æ = ae, å = aa), some characters could be removed. I general I try to make the URL look "good", but is that stupid? </p>
<p>But what do I do with chinese, japanese, arabian letters that has nothing to do with our western ASCII format? </p>
<p>I really don't like the idea of rewriting the URL with hex codes, so right now I just use my internal unique ID if the url contains too many "non convertable" characters.</p>
|
[
{
"answer_id": 209776,
"author": "balexandre",
"author_id": 28004,
"author_profile": "https://Stackoverflow.com/users/28004",
"pm_score": 0,
"selected": false,
"text": "Server.URLEncode( myURL );\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209327",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
209,335
|
<p>I have a chart in a Worksheet in Excel and I have a macro set up so that when I change the value in a certain cell the range of data in the chart is set to <code>A2</code> down as far as the row number corresponding in this certain cell.</p>
<p>What I can't seem to be able to do is to modify the axis as the specified axis no longer covers the range of the graph i.e. the current X axis is set to:</p>
<pre><code>=Sheet1!$C$2:$C$600
</code></pre>
<p>I can't figure out how I can update this in a macro. Any help would be much appreciated.</p>
|
[
{
"answer_id": 209486,
"author": "Dave DuPlantis",
"author_id": 8174,
"author_profile": "https://Stackoverflow.com/users/8174",
"pm_score": 4,
"selected": true,
"text": "Charts(\"chartname\").SeriesCollection(1).XValues = \"=MYXAXIS\"\n"
},
{
"answer_id": 260933,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "Dim rXVals As Range\nDim sAddress AS String\n\nsAddress = \"Sheet1!$C$2:$C$\" & Worksheets(\"Sheet1\").Range(\"F1\").Value\nSet rXVals = Range(sAddress)\nWorksheets(\"Sheet1\").ChartObjects(1).Chart.SeriesCollection(1).XValues = rXVals\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209335",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4014/"
] |
209,354
|
<p>I am currently developing an approval routing WCF service that will allow an user to create "rules" which determine how an request is routed. The route is determined by comparing the "ObjectToEvaluate" property of the Request class against the "ObjectToEvaluate" property of the "Rule" class. The "UnitOfMeasurement" enum determines how to cast the "ObjectToEvaluate" property for each class. </p>
<pre><code>public enum UnitOfMeasurement
{
Currency = 1,
Numeric = 2,
Special = 3,
Text = 4,
}
public class Request
{
public object ObjectToEvaluate { get; set; }
}
public class Rule
{
public object ObjectToEvaluate { get; set; }
public virtual void ExecuteRule()
{
//logic to see if it passes the rule condition
}
}
</code></pre>
<p>What would be the best way to implement the method to cast the "ObjectToEvaluate" property using the "UnitOfMeasurement" enum?</p>
|
[
{
"answer_id": 209442,
"author": "JSBձոգչ",
"author_id": 8078,
"author_profile": "https://Stackoverflow.com/users/8078",
"pm_score": 4,
"selected": true,
"text": "public class CastableObject {\n\n private UnitOfMeasurement eUnit; // Assign this somehow\n\n public static implicit operator int(CastableObject obj) \n {\n if (obj.eUnit != UnitOfMeasurement.Numeric)\n {\n throw new InvalidCastException(\"Mismatched unit of measurement\");\n }\n // return the numeric value\n }\n\n // Create other cast operators for the other unit types\n}\n"
},
{
"answer_id": 209507,
"author": "Michael Kniskern",
"author_id": 26327,
"author_profile": "https://Stackoverflow.com/users/26327",
"pm_score": 1,
"selected": false,
"text": "public class LessThanRule : Rule\n{\n private bool m_Result = false;\n private object m_ObjectToCompare = null;\n private object m_ObjectToEvaluate = null;\n\n public bool Result\n {\n get { return this.m_Result; }\n }\n\n public object ObjectToCompare\n {\n get { return this.m_ObjectToCompare; }\n set { this.m_ObjectToCompare = value; }\n }\n\n public object ObjectToEvaluate\n {\n get { return this.m_ObjectToEvaluate; }\n set { this.m_ObjectToEvaluate = value; }\n }\n\n public override void ExecuteRule()\n {\n if (((IComparable)this.m_ObjectToEvaluate).CompareTo(this.m_ObjectToCompare) < 0)\n this.m_Result = true;\n }\n}\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209354",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26327/"
] |
209,366
|
<p>Is there any way to take a Class and determine if it represents a primitive type (is there a solution that doesn't require specifically enumerating all the primitive types)?</p>
<p>NOTE: I've seen <a href="https://stackoverflow.com/questions/180097/dynamically-find-the-class-that-represents-a-primitive-java-type">this question</a>. I'm asking basically the opposite. I have the Class, I want to know if it's a primitive.</p>
|
[
{
"answer_id": 10195276,
"author": "kentcdodds",
"author_id": 971592,
"author_profile": "https://Stackoverflow.com/users/971592",
"pm_score": 2,
"selected": false,
"text": "/**\n* Checks first whether it is primitive and then whether it's wrapper is a primitive wrapper. Returns true\n* if either is true\n*\n* @param c\n* @return whether it's a primitive type itself or it's a wrapper for a primitive type\n*/\npublic static boolean isPrimitive(Class c) {\n if (c.isPrimitive()) {\n return true;\n } else if (c == Byte.class\n || c == Short.class\n || c == Integer.class\n || c == Long.class\n || c == Float.class\n || c == Double.class\n || c == Boolean.class\n || c == Character.class) {\n return true;\n } else {\n return false;\n }\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209366",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16430/"
] |
209,376
|
<p>Is it possible to use SQL Server 2008 CROSS APPLY with LINQ-2-SQL? </p>
<p>Example SQL:</p>
<pre><code>select d.dateCol, tvf.descr, tvf.value
from dateTable d
cross apply tvFunction(d.dt, 'anotherParam') tvf
where d.category='someCat'
</code></pre>
<p>CROSS APPLY enables using values from a table (dateTable in the example) as parameters to a tablevalue function. This is very usefull if you need do do a complex calculation (encapsulated in a table value function) for a range of inputs.</p>
|
[
{
"answer_id": 5579182,
"author": "Djordje",
"author_id": 1272040,
"author_profile": "https://Stackoverflow.com/users/1272040",
"pm_score": 2,
"selected": false,
"text": "from d in dateTable\nfrom tvf in tvFunction(d.dt, 'anotherProgram')\nwhere d.category = 'someCat'\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209376",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/224/"
] |
209,383
|
<p>I have a stored procedure that returns 80 columns, and 300 rows. I want to write a select that gets 2 of those columns. Something like </p>
<pre><code>SELECT col1, col2 FROM EXEC MyStoredProc 'param1', 'param2'
</code></pre>
<p>When I used the above syntax I get the error: </p>
<blockquote>
<p>"Invalid Column Name".</p>
</blockquote>
<p>I know the easiest solution would be to change the stored procedure, but I didn't write it, and I can't change it. </p>
<p>Is there any way to do what I want?</p>
<ul>
<li><p>I could make a temp table to put the results in, but because there are 80 columns so I would need to make an 80 column temp table just to get 2 columns. I wanted to avoid tracking down all the columns that are returned.</p></li>
<li><p>I tried using <code>WITH SprocResults AS ....</code> as suggested by Mark, but I got 2 errors <BR></p>
<blockquote>
<p>Incorrect syntax near the keyword 'EXEC'.<BR>Incorrect syntax near ')'.</p>
</blockquote></li>
<li><p>I tried declaring a table variable and I got the following error <br></p>
<blockquote>
<p>Insert Error: Column name or number of supplied values does not match table definition</p>
</blockquote></li>
<li><p>If I try <BR>
<code>SELECT * FROM EXEC MyStoredProc 'param1', 'param2'</code><br>
I get the error :<br></p>
<blockquote>
<p>Incorrect syntax near the keyword 'exec'.</p>
</blockquote></li>
</ul>
|
[
{
"answer_id": 209390,
"author": "Gulzar Nazim",
"author_id": 4337,
"author_profile": "https://Stackoverflow.com/users/4337",
"pm_score": 8,
"selected": false,
"text": "Declare @tablevar table(col1 col1Type,..\ninsert into @tablevar(col1,..) exec MyStoredProc 'param1', 'param2'\n\nSELECT col1, col2 FROM @tablevar\n"
},
{
"answer_id": 209647,
"author": "Brannon",
"author_id": 5745,
"author_profile": "https://Stackoverflow.com/users/5745",
"pm_score": 4,
"selected": false,
"text": "INSERT INTO ... EXEC"
},
{
"answer_id": 2006063,
"author": "SelvirK",
"author_id": 17465,
"author_profile": "https://Stackoverflow.com/users/17465",
"pm_score": 2,
"selected": false,
"text": "use mydatabase\ncreate procedure sp_onetwothree as\nselect 1 as '1', 2 as '2', 3 as '3'\ngo\nSELECT a.[1], a.[2]\nFROM OPENROWSET('SQLOLEDB','myserver';'sa';'mysapass',\n 'exec mydatabase.dbo.sp_onetwothree') AS a\nGO\n"
},
{
"answer_id": 3111199,
"author": "newbie007",
"author_id": 375401,
"author_profile": "https://Stackoverflow.com/users/375401",
"pm_score": 4,
"selected": false,
"text": "SELECT * FROM (exec sp_tables) Table1"
},
{
"answer_id": 3963991,
"author": "Peter Nazarov",
"author_id": 479858,
"author_profile": "https://Stackoverflow.com/users/479858",
"pm_score": 6,
"selected": false,
"text": "CREATE TABLE #Result\n(\n ID int, Name varchar(500), Revenue money\n)\nINSERT #Result EXEC RevenueByAdvertiser '1/1/10', '2/1/10'\nSELECT * FROM #Result ORDER BY Name\nDROP TABLE #Result\n"
},
{
"answer_id": 4894179,
"author": "Merenzo",
"author_id": 483655,
"author_profile": "https://Stackoverflow.com/users/483655",
"pm_score": 5,
"selected": false,
"text": "sp_help_job SELECT name, current_execution_status \nFROM OPENQUERY (MYSERVER, \n 'EXEC msdb.dbo.sp_help_job @job_name = ''My Job'', @job_aspect = ''JOB'''); \n sp_serveroption 'MYSERVER', 'DATA ACCESS', TRUE;\n sys.servers DECLARE @innerSql varchar(1000);\nDECLARE @outerSql varchar(1000);\n\n-- Set up the original stored proc definition.\nSET @innerSql = \n'EXEC msdb.dbo.sp_help_job @job_name = '''+@param1+''', @job_aspect = N'''+@param2+'''' ;\n\n-- Handle quotes.\nSET @innerSql = REPLACE(@innerSql, '''', '''''');\n\n-- Set up the OPENQUERY definition.\nSET @outerSql = \n'SELECT name, current_execution_status \nFROM OPENQUERY (MYSERVER, ''' + @innerSql + ''');';\n\n-- Execute.\nEXEC (@outerSql);\n sp_serveroption sys.servers sp_addlinkedserver sp_help_job"
},
{
"answer_id": 9041986,
"author": "Samir Basic",
"author_id": 1174652,
"author_profile": "https://Stackoverflow.com/users/1174652",
"pm_score": 3,
"selected": false,
"text": "'@Column_Name' CREATE PROCEDURE [dbo].[MySproc]\n @Column_Name AS VARCHAR(50)\nAS\nBEGIN\n IF (@Column_Name = 'ColumnName1')\n BEGIN\n SELECT @ColumnItem1 as 'ColumnName1'\n END\n ELSE\n BEGIN\n SELECT @ColumnItem1 as 'ColumnName1', @ColumnItem2 as 'ColumnName2', @ColumnItem3 as 'ColumnName3'\n END\nEND\n"
},
{
"answer_id": 13300747,
"author": "ShawnFeatherly",
"author_id": 228738,
"author_profile": "https://Stackoverflow.com/users/228738",
"pm_score": 3,
"selected": false,
"text": "DataTable table = MyStoredProc (param1, param2).Tables[0];\n(from row in table.AsEnumerable()\n select new\n {\n Col1 = row.Field<string>(\"col1\"),\n Col2 = row.Field<string>(\"col2\"),\n }).Dump();\n"
},
{
"answer_id": 25637401,
"author": "Navneet",
"author_id": 3962930,
"author_profile": "https://Stackoverflow.com/users/3962930",
"pm_score": 4,
"selected": false,
"text": "#test_table create table #test_table(\n col1 int,\n col2 int,\n .\n .\n .\n col80 int\n)\n #test_table insert into #test_table\nEXEC MyStoredProc 'param1', 'param2'\n #test_table select col1,col2....,col80 from #test_table\n"
},
{
"answer_id": 28247808,
"author": "dyatchenko",
"author_id": 2013969,
"author_profile": "https://Stackoverflow.com/users/2013969",
"pm_score": 3,
"selected": false,
"text": "CREATE PROCEDURE sp_GetDiffDataExample\n @columnsStatement NVARCHAR(MAX) -- required columns statement (e.g. \"field1, field2\")\nAS\nBEGIN\n DECLARE @query NVARCHAR(MAX)\n SET @query = N'SELECT ' + @columnsStatement + N' INTO ##TempTable FROM dbo.TestTable'\n EXEC sp_executeSql @query\n SELECT * FROM ##TempTable\n DROP TABLE ##TempTable\nEND\n"
},
{
"answer_id": 35516588,
"author": "Alex T",
"author_id": 342468,
"author_profile": "https://Stackoverflow.com/users/342468",
"pm_score": 3,
"selected": false,
"text": "DECLARE @temp TABLE (firstname NVARCHAR(30), lastname nvarchar(50));\n\nINSERT INTO @temp EXEC dbo.GetPersonName @param1,@param2;\n-- assumption is that dbo.GetPersonName returns a table with firstname / lastname columns\n\nSELECT * FROM @temp;\n"
},
{
"answer_id": 35594430,
"author": "sqluser",
"author_id": 2958272,
"author_profile": "https://Stackoverflow.com/users/2958272",
"pm_score": 3,
"selected": false,
"text": "SELECT * INTO #temp FROM OPENROWSET('SQLNCLI', 'Server=localhost;Trusted_Connection=yes;'\n ,'EXEC MyStoredProc')\n sp_configure 'Show Advanced Options', 1\nGO\nRECONFIGURE\nGO\nsp_configure 'Ad Hoc Distributed Queries', 1\nGO\nRECONFIGURE\nGO\n sp_configure RECONFIGURE ALTER SETTINGS SELECT col1, col2\nFROM #temp\n"
},
{
"answer_id": 54116262,
"author": "Emil",
"author_id": 2133723,
"author_profile": "https://Stackoverflow.com/users/2133723",
"pm_score": 0,
"selected": false,
"text": "OPENROWSET DECLARE @spName VARCHAR(MAX) = 'MyStoredProc'\nDECLARE @tempTableName VARCHAR(MAX) = '#tempTable'\n\n-- might need to update this if your param value is a string and you need to escape quotes\nDECLARE @insertCommand VARCHAR(MAX) = 'INSERT INTO ' + @tempTableName + ' EXEC MyStoredProc @param=value'\n\nDECLARE @createTableCommand VARCHAR(MAX)\n\n-- update this to select the columns you want\nDECLARE @selectCommand VARCHAR(MAX) = 'SELECT col1, col2 FROM ' + @tempTableName\n\nDECLARE @dropCommand VARCHAR(MAX) = 'DROP TABLE ' + @tempTableName\n\n-- Generate command to create temp table\nSELECT @createTableCommand = 'CREATE TABLE ' + @tempTableName + ' (' +\n STUFF\n (\n (\n SELECT ', ' + CONCAT('[', name, ']', ' ', system_type_name)\n FROM sys.dm_exec_describe_first_result_set_for_object\n (\n OBJECT_ID(@spName), \n NULL\n )\n FOR XML PATH('')\n )\n ,1\n ,1\n ,''\n ) + ')'\n\nEXEC( @createTableCommand + ' '+ @insertCommand + ' ' + @selectCommand + ' ' + @dropCommand)\n"
},
{
"answer_id": 56556364,
"author": "Humayoun_Kabir",
"author_id": 1427614,
"author_profile": "https://Stackoverflow.com/users/1427614",
"pm_score": 2,
"selected": false,
"text": "Declare @sql nvarchar(max)\nSet @sql='SELECT col1, col2 FROM OPENROWSET(''SQLNCLI'', ''Server=(local);uid=test;pwd=test'',\n ''EXEC MyStoredProc ''''param1'''', ''''param2'''''')'\n Exec(@sql)\n Declare @sql nvarchar(max)\nSet @sql='SELECT col1, col2 FROM OPENROWSET(''SQLNCLI'', ''Server=(local);Trusted_Connection=yes;'',\n ''EXEC MyStoredProc ''''param1'''', ''''param2'''''')'\n Exec(@sql)\n sp_configure 'Show Advanced Options', 1\nGO\nRECONFIGURE\nGO\nsp_configure 'Ad Hoc Distributed Queries', 1\nGO\nRECONFIGURE\nGO\n --for table variable \nDeclare @t table(col1 col1Type, col2 col2Type)\ninsert into @t exec MyStoredProc 'param1', 'param2'\nSELECT col1, col2 FROM @t\n\n--for temp table\ncreate table #t(col1 col1Type, col2 col2Type)\ninsert into #t exec MyStoredProc 'param1', 'param2'\nSELECT col1, col2 FROM #t\n"
},
{
"answer_id": 59392101,
"author": "Nilesh Umaretiya",
"author_id": 635188,
"author_profile": "https://Stackoverflow.com/users/635188",
"pm_score": 1,
"selected": false,
"text": "CREATE PROCEDURE dbo.usp_userwise_columns_value\n(\n @userid BIGINT\n)\nAS \nBEGIN\n DECLARE @maincmd NVARCHAR(max);\n DECLARE @columnlist NVARCHAR(max);\n DECLARE @columnname VARCHAR(150);\n DECLARE @nickname VARCHAR(50);\n\n SET @maincmd = '';\n SET @columnname = '';\n SET @columnlist = '';\n SET @nickname = '';\n\n DECLARE CUR_COLUMNLIST CURSOR FAST_FORWARD\n FOR\n SELECT columnname , nickname\n FROM dbo.v_userwise_columns \n WHERE userid = @userid\n\n OPEN CUR_COLUMNLIST\n IF @@ERROR <> 0\n BEGIN\n ROLLBACK\n RETURN\n END \n\n FETCH NEXT FROM CUR_COLUMNLIST\n INTO @columnname, @nickname\n\n WHILE @@FETCH_STATUS = 0\n BEGIN\n SET @columnlist = @columnlist + @columnname + ','\n\n FETCH NEXT FROM CUR_COLUMNLIST\n INTO @columnname, @nickname\n END\n CLOSE CUR_COLUMNLIST\n DEALLOCATE CUR_COLUMNLIST \n\n IF NOT EXISTS (SELECT * FROM sys.views WHERE name = 'v_userwise_columns_value')\n BEGIN\n SET @maincmd = 'CREATE VIEW dbo.v_userwise_columns_value AS SELECT sjoid, CONVERT(BIGINT, ' + CONVERT(VARCHAR(10), @userid) + ') as userid , ' \n + CHAR(39) + @nickname + CHAR(39) + ' as nickname, ' \n + @columnlist + ' compcode FROM dbo.SJOTran '\n END\n ELSE\n BEGIN\n SET @maincmd = 'ALTER VIEW dbo.v_userwise_columns_value AS SELECT sjoid, CONVERT(BIGINT, ' + CONVERT(VARCHAR(10), @userid) + ') as userid , ' \n + CHAR(39) + @nickname + CHAR(39) + ' as nickname, ' \n + @columnlist + ' compcode FROM dbo.SJOTran '\n END\n\n --PRINT @maincmd\n EXECUTE sp_executesql @maincmd\nEND\n\n-----------------------------------------------\nSELECT * FROM dbo.v_userwise_columns_value\n"
},
{
"answer_id": 67879276,
"author": "Lemiarty",
"author_id": 3687905,
"author_profile": "https://Stackoverflow.com/users/3687905",
"pm_score": 2,
"selected": false,
"text": "SELECT ColA, ColB\nFROM OPENROWSET('SQLNCLI','server=localhost;trusted_connection=yes;','exec schema.procedurename')\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209383",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28281/"
] |
209,389
|
<p>If I have a string (010) and i want to add 1 to it (011) what value type should i use to convert this string into a number for adding and at the same time preserve the whole number and not 10 + 1 = 11. </p>
|
[
{
"answer_id": 209392,
"author": "Omer van Kloeten",
"author_id": 4979,
"author_profile": "https://Stackoverflow.com/users/4979",
"pm_score": 3,
"selected": false,
"text": "if (int.TryParse(str, out i))\n str = (i + 1).ToString(\"000\");\n"
},
{
"answer_id": 209395,
"author": "Ilya Kochetov",
"author_id": 15329,
"author_profile": "https://Stackoverflow.com/users/15329",
"pm_score": 5,
"selected": true,
"text": "string initialValue = \"010\";\nint tempValue = Int.Parse(initialValue) + 1;\nstring newValue = tempValue.ToString(\"000\");\n .ToString()"
},
{
"answer_id": 209397,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 1,
"selected": false,
"text": "string ParseAndAdd(string text, int add)\n{\n int parsed = int.Parse(text);\n return (parsed + add).ToString().PadLeft(text.Length, '0');\n}\n"
},
{
"answer_id": 209399,
"author": "David Thibault",
"author_id": 5903,
"author_profile": "https://Stackoverflow.com/users/5903",
"pm_score": 1,
"selected": false,
"text": "int value = 10;// or, int value = Convert.ToInt32(\"010\");\nvalue += 1;\nstring text = value.ToString(\"000\");\n"
},
{
"answer_id": 209402,
"author": "Jorge Ferreira",
"author_id": 6508,
"author_profile": "https://Stackoverflow.com/users/6508",
"pm_score": 1,
"selected": false,
"text": "string a = \"010\";\nstring b = \"1\";\na = (int.Parse(a) + int.Parse(b)).ToString(new string('0', Math.Max(a.Length, b.Length)));\nConsole.WriteLine(a);\n"
},
{
"answer_id": 209411,
"author": "Jobi Joy",
"author_id": 8091,
"author_profile": "https://Stackoverflow.com/users/8091",
"pm_score": 0,
"selected": false,
"text": "BinaryString + -"
},
{
"answer_id": 209480,
"author": "Ferruccio",
"author_id": 4086,
"author_profile": "https://Stackoverflow.com/users/4086",
"pm_score": 2,
"selected": false,
"text": "string s = \"010\";\ns = Convert.ToString(Convert.ToInt32(\"010\", 2) + 1, 2);\n"
},
{
"answer_id": 209482,
"author": "Vyas Bharghava",
"author_id": 28413,
"author_profile": "https://Stackoverflow.com/users/28413",
"pm_score": 1,
"selected": false,
"text": "string str = \"110\";\nint i = 0;\nint maxSize = 3;\nif (int.TryParse(str, out i))\n{\n str = string.Concat(new string('0', maxSize - (i + 1).ToString().Length), i + 1);\n}\n"
},
{
"answer_id": 210363,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": " public string AddOne (string text)\n {\n int parsed = int.Parse(text);\n string formatString = \"{0:D\" + text.Length + \"}\";\n return string.Format(formatString, parsed + 1);\n }\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209389",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28647/"
] |
209,403
|
<p>i know this doesnt work but i dont know why, also how can i make it work?</p>
<pre><code> <% int result = referer.indexOf("smlMoverDetail.do"); %>
<% if (result == -1){%>
<%out.print("checking");%>
<bean:define id="JOININGDATE" name="smlMoverDetailForm"
property="empFDJoiningDate" type="java.lang.String" toScope="session"/>
<%}%>
</code></pre>
<p>Please please help i dont understand</p>
<p>i have tried this</p>
<pre><code><logic:Equal name="result" value = "-1">
<bean:define id="JOININGDATE" name="smlMoverDetailForm"
property="empFDJoiningDate" type="java.lang.String" toScope="session"/>
</logic:Equal>
</code></pre>
<p>but that doenst work either it doesnt exicute the bean:define part</p>
<p>help
thansk</p>
|
[
{
"answer_id": 212272,
"author": "Shivasubramanian A",
"author_id": 9195,
"author_profile": "https://Stackoverflow.com/users/9195",
"pm_score": 1,
"selected": false,
"text": "<logic:Equal name=\"result\" value = \"-1\">\n <logic:equal name=\"result\" value = \"-1\">\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209403",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
209,407
|
<p>I am developing a specialty application where the end-user needs to operate multiple controls simultaneously. The application is used to "tune" the control parameters of an electronic device to calibrate the unit to its best performance.</p>
<p>Currently, there is a UI with multiple graphical sliders which the operator click-drags one slider at a time. He can also click on a slider, and use the mouse-scroll wheel, which is a little easier to use.</p>
<p>This works, sort of, but is somewhat cumbersome. The various parameters (5 in this particular case) are sufficiently independent of each other so that I can't just refactor the parameters into a single adjustment. And, if the operator can keep his eye on the device being adjusted, rather than the UI of the control application, it would speed up and simplify his work.</p>
<p>One idea that I had was that I might buy a whole bunch of the USB jog-dial products, and bind each dial to a specific control. This way, the operator can quickly adjust any parameter, or even two parameters simultaneously. (BTW, Griffin PowerMate comes to immediate mind, but I know there are a few other jog dials out there.)</p>
<p>Do you have any suggestions?</p>
<p>ADDED:</p>
<p>Keep in mind that in some cases, the parameters are adjusted in different directions, and may be significantly different in the adjustment steps. It's not a simple "track two channels together, and then fine tune the last bit of difference".</p>
|
[
{
"answer_id": 209424,
"author": "theraccoonbear",
"author_id": 7210,
"author_profile": "https://Stackoverflow.com/users/7210",
"pm_score": 3,
"selected": true,
"text": "A/Z are the up/down keys for slider 1\nS/X are the up/down keys for slider 2\nD/C are the up/down keys for slider 3\nF/V are the up/down keys for slider 4\nG/B are the up/down keys for slider 5\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209407",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22329/"
] |
209,415
|
<p>Some text before the code so that the question summary isn't mangled.</p>
<pre><code>class Tree
{
public event EventHandler MadeSound;
public void Fall() { MadeSound(this, new EventArgs()); }
static void Main(string[] args)
{
Tree oaky = new Tree();
oaky.Fall();
}
}
</code></pre>
<p>I haven't used events much in C#, but the fact that this would cause a NullRefEx seems weird. The EventHandler reference is considered null because it currently has no subsribers - but that doesn't mean that the event hasn't occurred, does it?</p>
<p>EventHandlers are differentiated from standard delegates by the <strong>event</strong> keyword. Why didn't the language designers set them up to fire silently in to the void when they have no subscribers? (I gather you can do this manually by explicitly adding an empty delegate).</p>
|
[
{
"answer_id": 209437,
"author": "James Curran",
"author_id": 12725,
"author_profile": "https://Stackoverflow.com/users/12725",
"pm_score": 3,
"selected": false,
"text": "void OnMadeSound()\n{\n if (MadeSound != null)\n {\n MadeSound(this, new EventArgs());\n }\n}\n\npublic void Fall() { OnMadeSound(); }\n"
},
{
"answer_id": 209443,
"author": "Jon B",
"author_id": 27414,
"author_profile": "https://Stackoverflow.com/users/27414",
"pm_score": 2,
"selected": false,
"text": "protected void OnMyEvent()\n{\n if (this.MyEvent != null) this.MyEvent(this, EventArgs.Empty);\n}\n"
},
{
"answer_id": 209459,
"author": "Chris Marasti-Georg",
"author_id": 96,
"author_profile": "https://Stackoverflow.com/users/96",
"pm_score": 2,
"selected": false,
"text": "class Tree\n{\n public event EventHandler MadeSound = delegate {};\n\n public void Fall() { MadeSound(this, new EventArgs()); }\n\n static void Main(string[] args)\n {\n Tree oaky = new Tree();\n oaky.Fall();\n }\n}\n"
},
{
"answer_id": 209683,
"author": "xyz",
"author_id": 82,
"author_profile": "https://Stackoverflow.com/users/82",
"pm_score": 0,
"selected": false,
"text": "MadeSound(this, EventArgs.Empty)\n if (MadeSound != null) { MadeSound(this, EventArgs.Empty); }\n"
},
{
"answer_id": 210655,
"author": "Robert Paulson",
"author_id": 14033,
"author_profile": "https://Stackoverflow.com/users/14033",
"pm_score": 2,
"selected": false,
"text": "public class MyClass\n{\n public event EventHandler<EventArgs> MyEvent; // the event\n\n // protected to allow subclasses to override what happens when event raised.\n protected virtual void OnMyEvent(object sender, EventArgs e)\n {\n // prevent race condition by copying reference locally\n EventHandler<EventArgs> localHandler = MyEvent;\n if (localHandler != null)\n {\n localHandler(sender, e);\n }\n }\n public void SomethingThatGeneratesEvent()\n {\n OnMyEvent(this, EventArgs.Empty);\n }\n}\n event != null OnMyEvent()"
},
{
"answer_id": 1236201,
"author": "Taylor Leese",
"author_id": 105744,
"author_profile": "https://Stackoverflow.com/users/105744",
"pm_score": 1,
"selected": false,
"text": "public static class EventExtension\n{\n public static void RaiseEvent<T>(this EventHandler<T> handler, object obj, T args) where T : EventArgs\n {\n if (handler != null)\n {\n handler(obj, args);\n }\n }\n}\n public event EventHandler<YourEventArgs> YourEvent;\n...\nYourEvent.RaiseEvent(this, new YourEventArgs());\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209415",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/82/"
] |
209,416
|
<p>I have a WPF ListView which currently scrolls everytime I click on an item which is only partially visible. How can I keep the control from scrolling that item into view (instead simply selecting the partially visible one)? This behavior is very annoying when doing a drag from this control. </p>
<p>Thanks.</p>
<p>Added: I am looking for a solution to keep the control itself from scrolling when contents are clicked that the control believes are not fully visible. Often this is by a few pixels and the scroll is not necessary.</p>
|
[
{
"answer_id": 218476,
"author": "David Schmitt",
"author_id": 4918,
"author_profile": "https://Stackoverflow.com/users/4918",
"pm_score": 1,
"selected": false,
"text": "ListView ItemsPanel RequestBringIntoView"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209416",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26152/"
] |
209,418
|
<p>My main JavaScript framework is <a href="http://jquery.com/" rel="nofollow noreferrer">jQuery</a>, so I would like my unit test and mocking frameworks to be compatible with that. I'd rather not have to introduce another JavaScript framework.</p>
<p>I am currently using <a href="http://docs.jquery.com/QUnit" rel="nofollow noreferrer">QUnit</a> for unit testing and <a href="https://github.com/keronsen/jack" rel="nofollow noreferrer">Jack</a> for mocking, but I am pretty new to the whole unit testing of JavaScript.</p>
<p>Is there a better tool to suggest? What has worked for you?</p>
|
[
{
"answer_id": 209673,
"author": "Chris MacDonald",
"author_id": 18146,
"author_profile": "https://Stackoverflow.com/users/18146",
"pm_score": 0,
"selected": false,
"text": "setup() teardown()"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209418",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4481/"
] |
209,428
|
<p>HTML (or maybe just XHTML?) is relatively strict when it comes to non-standard attributes on tags. If they aren't part of the spec, then your code is considered non-compliant.</p>
<p>Non-standard attributes can be fairly useful for passing along meta-data to Javascript however. For instance, if a link is suppose to show a popup, you can set the name of the popup in an attribute:</p>
<pre><code><a href="#null" class="popup" title="See the Popup!"
popup_title="Title for My Popup">click me</a>
</code></pre>
<p>Alternatively, you can store the title for the popup in a hidden element, like a span:</p>
<pre><code><style>
.popup .title { display: none; }
</style>
<a href="#null" title="See the Popup!" class="popup">
click me
<span class="title">Title for My Popup</span>
</a>
</code></pre>
<p>I am torn however as to which should be a preferred method. The first method is more concise and, I'm guessing, doesn't screw with search engines and screen readers as much. Conversely, the second option makes storing large amounts of data easier and is thus, more versatile. It is also standards compliant.</p>
<p>I am curious what this communities thoughts are. How do you handle a situation like this? Does the simplicity of the first method outweigh the potential downsides (if there are any)?</p>
|
[
{
"answer_id": 209432,
"author": "eyelidlessness",
"author_id": 17964,
"author_profile": "https://Stackoverflow.com/users/17964",
"pm_score": 7,
"selected": true,
"text": "data-"
},
{
"answer_id": 881334,
"author": "ibz",
"author_id": 5475,
"author_profile": "https://Stackoverflow.com/users/5475",
"pm_score": 3,
"selected": false,
"text": "<script type=\"text/javascript\">\nvar link_titles = {link1: \"Title 1\", link2: \"Title 2\"};\n</script>\n var poi_types = {1: \"City\", 2: \"Restaurant\"};\nvar poi = {1: {lat: X, lng: Y, name: \"Beijing\", type: 1}, 2: {lat: A, lng: B, name: \"Hatsune\", type: 2}};\n <a id=\"poi-2\" href=\"/poi/2/\">Hatsune</a>\n"
},
{
"answer_id": 881365,
"author": "jon skulski",
"author_id": 47545,
"author_profile": "https://Stackoverflow.com/users/47545",
"pm_score": 2,
"selected": false,
"text": "<a href=\"#\" alt=\"\" title=\"Title of My Pop-up\">click</a>\n"
},
{
"answer_id": 1273632,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": -1,
"selected": false,
"text": "<a href=\"#\" alt=\"\" title=\"\" rel=\"{popup_title:'Title of My Pop-up'}\">click</a>\n"
},
{
"answer_id": 4313015,
"author": "Ioan Alexandru Cucu",
"author_id": 222397,
"author_profile": "https://Stackoverflow.com/users/222397",
"pm_score": 2,
"selected": false,
"text": "<a id=\"anchor_id\">\n <input type=\"hidden\" class=\"articleid\" value=\"5\">\n Link text here\n</a>\n $('#anchor_id .articleid').val()\n"
},
{
"answer_id": 12841810,
"author": "Matt Parkins",
"author_id": 406592,
"author_profile": "https://Stackoverflow.com/users/406592",
"pm_score": 0,
"selected": false,
"text": "<a href=\"#\" class=\"article\" id=\"Title_of_My_Pop-up__47\">click</a>\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209428",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10093/"
] |
209,429
|
<p>I have installed CherryPy 3.1.0,. Here is what happens when I try to run tutorial 9:</p>
<pre><code>$ cd /Library/Python/2.5/site-packages/cherrypy/tutorial/
$ python tut09_files.py
Traceback (most recent call last):
File "tut09_files.py", line 48, in <module>
from cherrypy.lib import static
ImportError: cannot import name static
</code></pre>
<p>The previous line in the file:</p>
<pre><code>import cherrypy
</code></pre>
<p>passes without error, so it appears that it can find cherrypy on the path. What am I missing?</p>
|
[
{
"answer_id": 209432,
"author": "eyelidlessness",
"author_id": 17964,
"author_profile": "https://Stackoverflow.com/users/17964",
"pm_score": 7,
"selected": true,
"text": "data-"
},
{
"answer_id": 881334,
"author": "ibz",
"author_id": 5475,
"author_profile": "https://Stackoverflow.com/users/5475",
"pm_score": 3,
"selected": false,
"text": "<script type=\"text/javascript\">\nvar link_titles = {link1: \"Title 1\", link2: \"Title 2\"};\n</script>\n var poi_types = {1: \"City\", 2: \"Restaurant\"};\nvar poi = {1: {lat: X, lng: Y, name: \"Beijing\", type: 1}, 2: {lat: A, lng: B, name: \"Hatsune\", type: 2}};\n <a id=\"poi-2\" href=\"/poi/2/\">Hatsune</a>\n"
},
{
"answer_id": 881365,
"author": "jon skulski",
"author_id": 47545,
"author_profile": "https://Stackoverflow.com/users/47545",
"pm_score": 2,
"selected": false,
"text": "<a href=\"#\" alt=\"\" title=\"Title of My Pop-up\">click</a>\n"
},
{
"answer_id": 1273632,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": -1,
"selected": false,
"text": "<a href=\"#\" alt=\"\" title=\"\" rel=\"{popup_title:'Title of My Pop-up'}\">click</a>\n"
},
{
"answer_id": 4313015,
"author": "Ioan Alexandru Cucu",
"author_id": 222397,
"author_profile": "https://Stackoverflow.com/users/222397",
"pm_score": 2,
"selected": false,
"text": "<a id=\"anchor_id\">\n <input type=\"hidden\" class=\"articleid\" value=\"5\">\n Link text here\n</a>\n $('#anchor_id .articleid').val()\n"
},
{
"answer_id": 12841810,
"author": "Matt Parkins",
"author_id": 406592,
"author_profile": "https://Stackoverflow.com/users/406592",
"pm_score": 0,
"selected": false,
"text": "<a href=\"#\" class=\"article\" id=\"Title_of_My_Pop-up__47\">click</a>\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209429",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/173/"
] |
209,458
|
<p>How do you concatenate bits in VHDL? I'm trying to use the following code:</p>
<p>Case b0 & b1 & b2 & b3 is
...</p>
<p>and it throws an error</p>
<p>Thanks</p>
|
[
{
"answer_id": 209504,
"author": "user21246",
"author_id": 21246,
"author_profile": "https://Stackoverflow.com/users/21246",
"pm_score": 4,
"selected": false,
"text": "architecture EXAMPLE of CONCATENATION is\n signal Z_BUS : bit_vector (3 downto 0);\n signal A_BIT, B_BIT, C_BIT, D_BIT : bit;\nbegin\n Z_BUS <= A_BIT & B_BIT & C_BIT & D_BIT;\nend EXAMPLE;\n"
},
{
"answer_id": 1826799,
"author": "Justin",
"author_id": 222176,
"author_profile": "https://Stackoverflow.com/users/222176",
"pm_score": 4,
"selected": false,
"text": "process(b0,b1,b2,b3)\n variable bcat : std_logic_vector(0 to 3);\nbegin\n bcat := b0 & b1 & b2 & b3;\n case bcat is\n when \"0000\" => x <= 1;\n when others => x <= 2;\n end case;\nend process;\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209458",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21539/"
] |
209,465
|
<p>I could use some help trying to track down an intermittent error that I've been having with our ASP.Net project for quite some time.</p>
<p>Intermittently when building the solution, the build will fail with the error "/: Build (web): Object reference not set to an instance of an object." The error has no associated file, line, column or project information. The weird thing about the error is that it will go away on successive rebuilds and doesn't seem to result in any run-time errors that we've come across once the build is successful. Sometimes the error will pop only once, sometimes 3-4 times, but eventually the build will finish successfully and then seems to build just fine each time after. I haven't been able to nail down a pattern as to why and when the error will happen, and since it always eventually builds it hasn't been a critical problem for us. Just an annoyance. But one that I want gone for obvious reasons.</p>
<p>I guess I should add that this is an application that was originally developed in ASP.net 1.1 and converted to 2.0 and I inherited it somewhere down the line after that, so I don't know when the problem originally surfaced. As far as everyone here is concerned, it's always been there.</p>
<p>Obviously I'm not expecting someone to pick out the cause of my problem as that would require them to look at our entire solution to pick out potential problems. Just hoping someone can give me a couple fresh ideas as to how to go about tracking down the actual source of the error in code. It has to be coming from somewhere, right? How would you go about finding out where?</p>
|
[
{
"answer_id": 4896338,
"author": "bcolin",
"author_id": 587536,
"author_profile": "https://Stackoverflow.com/users/587536",
"pm_score": 2,
"selected": false,
"text": "<buildProviders>\n <add extension=\".rdlc\" type=\"Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.Common, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a\"/>\n <!-- add this line below -->\n <remove extension=\".rdlc\"/> \n </buildProviders>\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209465",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
209,470
|
<p>I currently do my textfile manipulation through a bunch of badly remembered AWK, sed, Bash and a tiny bit of Perl.</p>
<p>I've seen mentioned a few places that python is good for this kind of thing. How can I use Python to replace shell scripting, AWK, sed and friends?</p>
|
[
{
"answer_id": 209562,
"author": "S.Lott",
"author_id": 10661,
"author_profile": "https://Stackoverflow.com/users/10661",
"pm_score": 8,
"selected": true,
"text": "shutil os (a | b; c ) | something >result a b something result os.walk"
},
{
"answer_id": 209565,
"author": "Davide",
"author_id": 25891,
"author_profile": "https://Stackoverflow.com/users/25891",
"pm_score": 1,
"selected": false,
"text": "import popen2\nstdout_text, stdin_text=popen2.popen2(\"your-shell-command-here\")\nfor line in stdout_text:\n if line.startswith(\"#\"):\n pass\n else\n jobID=int(line.split(\",\")[0].split()[1].lstrip(\"<\").rstrip(\">\"))\n # do something with jobID\n"
},
{
"answer_id": 3851454,
"author": "Nickolay",
"author_id": 1026,
"author_profile": "https://Stackoverflow.com/users/1026",
"pm_score": 2,
"selected": false,
"text": "for line in sh(\"cat /tmp/junk2\") | cut(d=',',f=1) | 'sort' | uniq:\n sys.stdout.write(line)\n"
},
{
"answer_id": 15712610,
"author": "TheK",
"author_id": 2225943,
"author_profile": "https://Stackoverflow.com/users/2225943",
"pm_score": 6,
"selected": false,
"text": "#!/usr/bin/env ipython3\n\n# *** How to have the most comfort scripting experience of your life ***\n# ######################################################################\n#\n# … by using ipython for scripting combined with subcommands from bash!\n#\n# 1. echo \"#!/usr/bin/env ipython3\" > scriptname.ipy # creates new ipy-file\n#\n# 2. chmod +x scriptname.ipy # make in executable\n#\n# 3. starting with line 2, write normal python or do some of\n# the ! magic of ipython, so that you can use unix commands\n# within python and even assign their output to a variable via\n# var = !cmd1 | cmd2 | cmd3 # enjoy ;)\n#\n# 4. run via ./scriptname.ipy - if it fails with recognizing % and !\n# but parses raw python fine, please check again for the .ipy suffix\n\n# ugly example, please go and find more in the wild\nfiles = !ls *.* | grep \"y\"\nfor file in files:\n !echo $file | grep \"p\"\n# sorry for this nonsense example ;)\n"
},
{
"answer_id": 25820270,
"author": "RussellStewart",
"author_id": 2237635,
"author_profile": "https://Stackoverflow.com/users/2237635",
"pm_score": 2,
"selected": false,
"text": "$ echo me2 | py -x 're.sub(\"me\", \"you\", x)'\nyou2\n"
},
{
"answer_id": 27881288,
"author": "Jerry T",
"author_id": 2292993,
"author_profile": "https://Stackoverflow.com/users/2292993",
"pm_score": 1,
"selected": false,
"text": "pip install ez files = fls('.','py$'); cp(files, myDir)"
},
{
"answer_id": 30617053,
"author": "Kamilion",
"author_id": 1628578,
"author_profile": "https://Stackoverflow.com/users/1628578",
"pm_score": 5,
"selected": false,
"text": "env | uniq | sort -r | grep PATH\n my-web-server 2>&1 | my-log-sorter\n ? ?? *.xsh ${} $() $[] @() *"
},
{
"answer_id": 35443255,
"author": "Alexander Ponomarev",
"author_id": 618525,
"author_profile": "https://Stackoverflow.com/users/618525",
"pm_score": 2,
"selected": false,
"text": "import json\nimport os\nimport tempfile\n\n# get the api answer with curl\nanswer = `curl https://api.github.com/users/python\n# syntactic sugar for checking returncode of executed process for zero\nif answer:\n answer_json = json.loads(answer.stdout)\n avatar_url = answer_json['avatar_url']\n\n destination = os.path.join(tempfile.gettempdir(), 'python.png')\n\n # execute curl once again, this time to get the image\n result = `curl {avatar_url} > {destination}\n if result:\n # if there were no problems show the file\n p`ls -l {destination}\n else:\n print('Failed to download avatar')\n\n print('Avatar downloaded')\nelse:\n print('Failed to access github api')\n log = `git log --pretty=oneline --grep='Create'\n git log --pretty=oneline --grep='Create'"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209470",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27074/"
] |
209,478
|
<p>Hopefully I haven't misunderstood the meaning of "duck typing", but from what I've read, it means that I should write code based on how an object responds to methods rather than what type/class it is.</p>
<p>Here's the code:</p>
<pre><code>def convert_hash(hash)
if hash.keys.all? { |k| k.is_a?(Integer) }
return hash
elsif hash.keys.all? { |k| k.is_a?(Property) }
new_hash = {}
hash.each_pair {|k,v| new_hash[k.id] = v}
return new_hash
else
raise "Custom attribute keys should be ID's or Property objects"
end
end
</code></pre>
<p>What I want is to make sure that I end up with a hash where the keys are an integer representing the ID of an ActiveRecord object. I don't particularly enjoy having to iterate through the hash keys twice with <code>all?</code> to determine if I need to grab the ID's out.</p>
<p>Of course, I'll accept any other suggestions to improve this code as well :)</p>
|
[
{
"answer_id": 209532,
"author": "Eli Courtwright",
"author_id": 1694,
"author_profile": "https://Stackoverflow.com/users/1694",
"pm_score": 5,
"selected": true,
"text": "def convert(hash)\n new_hash = {}\n hash.each_pair { |k,v| new_hash[ k.is_a?(Integer) ? k : k.id ] = v }\n return new_hash\nend\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209478",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24848/"
] |
209,491
|
<p>I have a form using multiple <code><cfinput type="datefield" ...></code>. They are positioned in such a way that the pop-up CSS calendar should appear over the field for others. However, the text fields for the other dates end up in front of the calendar.</p>
<p>This is only an IE issue as Firefox and Safari work just fine.</p>
<p>Is there a simple CSS hack or some other simple thing I can do to get the calendar to act as it should? Re-arranging the form is not very helpful.</p>
|
[
{
"answer_id": 209696,
"author": "Ben Doom",
"author_id": 12267,
"author_profile": "https://Stackoverflow.com/users/12267",
"pm_score": 0,
"selected": false,
"text": "<cfinput type=\"datefiled\" name=\"bob\" value=\"\" style=\"z-index: -1;\">\n"
},
{
"answer_id": 556879,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "<div style=\"position:relative; z-index:3\">\n<cfinput type=\"dateField\" name=\"info_dateDebutPub\" value=\"#dateformat(info_dateDebutPub,'dd/mm/yy')#\" mask=\"dd/mm/yy\">\n</div>\n"
},
{
"answer_id": 1362017,
"author": "kayteen",
"author_id": 150977,
"author_profile": "https://Stackoverflow.com/users/150977",
"pm_score": 0,
"selected": false,
"text": "position:relative;z-index:0\n position:absolute;z-index:1\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209491",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21960/"
] |
209,495
|
<p>I am looking for a concise way to check a value to see if it is nil or zero. Currently I am doing something like:</p>
<pre><code>if (!val || val == 0)
# Is nil or zero
end
</code></pre>
<p>But this seems very clumsy.</p>
|
[
{
"answer_id": 209522,
"author": "unwind",
"author_id": 28169,
"author_profile": "https://Stackoverflow.com/users/28169",
"pm_score": 2,
"selected": false,
"text": "nil false !val nil false if val == nil || val == 0\n # do stuff\nend\n"
},
{
"answer_id": 209575,
"author": "Adrian Dunston",
"author_id": 8344,
"author_profile": "https://Stackoverflow.com/users/8344",
"pm_score": 3,
"selected": false,
"text": "class Object\n def nil_or_zero?\n return (self.nil? or self == 0)\n end\nend\n\nmy_object = MyClass.new\nmy_object.nil_or_zero?\n==> false\n"
},
{
"answer_id": 209577,
"author": "Gishu",
"author_id": 1695,
"author_profile": "https://Stackoverflow.com/users/1695",
"pm_score": 2,
"selected": false,
"text": "if (model.attribute?) # => false if attribute is 0 and model is an ActiveRecord::Base derivation\n"
},
{
"answer_id": 209797,
"author": "Christian Lescuyer",
"author_id": 341,
"author_profile": "https://Stackoverflow.com/users/341",
"pm_score": 7,
"selected": true,
"text": "if val.nil? || val == 0\n [do something]\nend\n [do something] if val.nil? || val == 0\n"
},
{
"answer_id": 217545,
"author": "Joshua Swink",
"author_id": 14732,
"author_profile": "https://Stackoverflow.com/users/14732",
"pm_score": 2,
"selected": false,
"text": "if val.nil? or val == 0\n # Do something\nend\n"
},
{
"answer_id": 263970,
"author": "lmumar",
"author_id": 20204,
"author_profile": "https://Stackoverflow.com/users/20204",
"pm_score": -1,
"selected": false,
"text": "val ||= 0\nif val == 0\n# do something here\nend\n"
},
{
"answer_id": 273282,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 5,
"selected": false,
"text": "\nif val.nil? || val.zero?\n # do stuff\nend\n"
},
{
"answer_id": 478542,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "case case val with nil, 0\n # do stuff\n end\n === not_valid = nil, 0\ncase val1 with *not_valid\n # do stuff\n end\n #do other stuff\n case val2 with *not_valid, false #Test for values that is nil, 0 or false\n # do other other stuff\n end\n if case Enum.any? Enum.include? if [0, nil].include? val\n #do stuff\nend\n"
},
{
"answer_id": 480206,
"author": "Scott",
"author_id": 7399,
"author_profile": "https://Stackoverflow.com/users/7399",
"pm_score": -1,
"selected": false,
"text": "if val.to_i == 0\n # do stuff\nend\n"
},
{
"answer_id": 1689936,
"author": "ntl",
"author_id": 205181,
"author_profile": "https://Stackoverflow.com/users/205181",
"pm_score": 3,
"selected": false,
"text": "val.to_i.zero?\n"
},
{
"answer_id": 2257865,
"author": "klew",
"author_id": 58877,
"author_profile": "https://Stackoverflow.com/users/58877",
"pm_score": 0,
"selected": false,
"text": "blank? true 0 def nil_zero? \n if respond_to?(:zero?) \n zero? \n else \n !self \n end \nend \n nil.nil_zero?\n=> true\n0.nil_zero?\n=> true\n10.nil_zero?\n=> false\n\nif val.nil_zero?\n #...\nend\n"
},
{
"answer_id": 26043684,
"author": "antinome",
"author_id": 793309,
"author_profile": "https://Stackoverflow.com/users/793309",
"pm_score": 0,
"selected": false,
"text": "if (val || 0) == 0\n # Is nil, false, or zero.\nend\n false nil .nil? .zero? val .zero?"
},
{
"answer_id": 28065067,
"author": "Mohamad",
"author_id": 276959,
"author_profile": "https://Stackoverflow.com/users/276959",
"pm_score": 0,
"selected": false,
"text": "module NilOrZero\n refine Object do\n def nil_or_zero?\n nil? or zero?\n end\n end\nend\n\nusing NilOrZero\nclass Car\n def initialize(speed: 100)\n puts speed.nil_or_zero?\n end\nend\n\ncar = Car.new # false\ncar = Car.new(speed: nil) # true\ncar = Car.new(speed: 0) # true\n class Car\n using NilOrZero\nend\n"
},
{
"answer_id": 34819715,
"author": "ndnenkov",
"author_id": 2423164,
"author_profile": "https://Stackoverflow.com/users/2423164",
"pm_score": 5,
"selected": false,
"text": "&. Numeric#nonzero? &. nil nil nonzero? 0 unless val&.nonzero?\n # Is nil or zero\nend\n do_something unless val&.nonzero?\n"
},
{
"answer_id": 40063856,
"author": "Stanislav Kr.",
"author_id": 6413990,
"author_profile": "https://Stackoverflow.com/users/6413990",
"pm_score": 2,
"selected": false,
"text": "[0, nil].include?(val)"
},
{
"answer_id": 40291812,
"author": "user2097847",
"author_id": 2097847,
"author_profile": "https://Stackoverflow.com/users/2097847",
"pm_score": 2,
"selected": false,
"text": "if val&.>(0)\n # do something\nend\n val&.>(0) val == 0"
},
{
"answer_id": 42813542,
"author": "Sam",
"author_id": 5496634,
"author_profile": "https://Stackoverflow.com/users/5496634",
"pm_score": 0,
"selected": false,
"text": "nil.to_s.to_d == 0"
},
{
"answer_id": 52274283,
"author": "RichOrElse",
"author_id": 6913691,
"author_profile": "https://Stackoverflow.com/users/6913691",
"pm_score": 2,
"selected": false,
"text": "module Nothingness\n refine Numeric do\n alias_method :nothing?, :zero?\n end\n\n refine NilClass do\n alias_method :nothing?, :nil?\n end\nend\n\nusing Nothingness\n\nif val.nothing?\n # Do something\nend\n"
},
{
"answer_id": 54098879,
"author": "Abel",
"author_id": 3212572,
"author_profile": "https://Stackoverflow.com/users/3212572",
"pm_score": 0,
"selected": false,
"text": "unless (val || 0).zero?\n\n # do stufff\n\nend\n"
},
{
"answer_id": 66688875,
"author": "Vasanth Saminathan",
"author_id": 5634603,
"author_profile": "https://Stackoverflow.com/users/5634603",
"pm_score": 0,
"selected": false,
"text": "[do_something] if val.to_i == 0\n nil.to_i 0"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209495",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19839/"
] |
209,509
|
<p>Instead of using the <code><input type="file"></code> tag I'd like to have a button that launches a file browser dialog.</p>
<p>My first thought was to have a hidden file input tag and a button. I'd use the button click on the button to fire the onclick of the hidden file input, but I haven't been able to get this working properly.</p>
<p>So the question is, is this even possible? And second is there a nicer way to do this and still be able to send the information back in a form?</p>
<p>This will be the bottom layer of degrading functionality (from Flash to JavaScript (our site doesn't work without JS)) so it has to work with just basic JS and HTML.</p>
|
[
{
"answer_id": 21069776,
"author": "Rolf",
"author_id": 370786,
"author_profile": "https://Stackoverflow.com/users/370786",
"pm_score": 1,
"selected": false,
"text": "$(\"#upload-box\").change(function(){\n $(\"#upload-click-handler\").val($(this).val());\n});\n$(\"#upload-click-handler\").click(function(){\n $(\"#upload-box\").click();\n});\n <input id=\"upload-box\" style=\"visibility:hidden;height:0;\" name=\"Photo\" type=\"file\" />\n<input id=\"upload-click-handler\" type=\"text\" readonly />\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209509",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28655/"
] |
209,513
|
<p>How do I convert a hex string to an integer?</p>
<pre><code>"0xffff" ⟶ 65535
"ffff" ⟶ 65535
</code></pre>
|
[
{
"answer_id": 209529,
"author": "unwind",
"author_id": 28169,
"author_profile": "https://Stackoverflow.com/users/28169",
"pm_score": 8,
"selected": false,
"text": "int(hexstring, 16) >>> int(\"a\", 16)\n10\n>>> int(\"0xa\", 16)\n10\n"
},
{
"answer_id": 209530,
"author": "Jorge Ferreira",
"author_id": 6508,
"author_profile": "https://Stackoverflow.com/users/6508",
"pm_score": 6,
"selected": false,
"text": "int(s, 16)\n"
},
{
"answer_id": 209550,
"author": "Dan Lenski",
"author_id": 20789,
"author_profile": "https://Stackoverflow.com/users/20789",
"pm_score": 11,
"selected": true,
"text": "0x x = int(\"deadbeef\", 16)\n 0x >>> print(int(\"0xdeadbeef\", 0))\n3735928559\n>>> print(int(\"10\", 0))\n10\n 0 int()"
},
{
"answer_id": 11275700,
"author": "Max",
"author_id": 1261433,
"author_profile": "https://Stackoverflow.com/users/1261433",
"pm_score": 4,
"selected": false,
"text": "print int(0xdeadbeef) # valid\n\nmyHex = \"0xdeadbeef\"\nprint int(myHex) # invalid, raises ValueError\nprint int(myHex , 16) # valid\n"
},
{
"answer_id": 17250080,
"author": "Soundararajan",
"author_id": 866670,
"author_profile": "https://Stackoverflow.com/users/866670",
"pm_score": 1,
"selected": false,
"text": "a = int('0x100', 16)\nprint(a) #256\nprint('%x' % a) #100\nb = a\nprint(b) #256\nc = '%x' % a\nprint(c) #100\n"
},
{
"answer_id": 21187085,
"author": "André Laszlo",
"author_id": 98057,
"author_profile": "https://Stackoverflow.com/users/98057",
"pm_score": 4,
"selected": false,
"text": ">>> def hex_to_int(x):\n return eval(\"0x\" + x)\n\n>>> hex_to_int(\"c0ffee\")\n12648430\n"
},
{
"answer_id": 37221971,
"author": "Russia Must Remove Putin",
"author_id": 541136,
"author_profile": "https://Stackoverflow.com/users/541136",
"pm_score": 6,
"selected": false,
"text": "\"0xffff\" \"ffff\" int >>> string_1 = \"0xffff\"\n>>> string_2 = \"ffff\"\n>>> int(string_1, 16)\n65535\n>>> int(string_2, 16)\n65535\n int int >>> int(string_1, 0)\n65535\n 0x int >>> int(string_2, 0)\nTraceback (most recent call last):\n File \"<stdin>\", line 1, in <module>\nValueError: invalid literal for int() with base 0: 'ffff'\n >>> integer = 0xffff\n>>> integer\n65535\n ffff >>> integer = ffff\nTraceback (most recent call last):\n File \"<stdin>\", line 1, in <module>\nNameError: name 'ffff' is not defined\n"
},
{
"answer_id": 52884568,
"author": "U12-Forward",
"author_id": 8708364,
"author_profile": "https://Stackoverflow.com/users/8708364",
"pm_score": 3,
"selected": false,
"text": "ast.literal_eval eval ast.literal_eval(\"0xffff\")\n >>> import ast\n>>> ast.literal_eval(\"0xffff\")\n65535\n>>> \n"
},
{
"answer_id": 56859334,
"author": "maysara",
"author_id": 5503714,
"author_profile": "https://Stackoverflow.com/users/5503714",
"pm_score": 2,
"selected": false,
"text": ">>> 0xffff\n\n65535\n"
},
{
"answer_id": 58997192,
"author": "shrewmouse",
"author_id": 2464381,
"author_profile": "https://Stackoverflow.com/users/2464381",
"pm_score": 1,
"selected": false,
"text": "def to_number(n):\n ''' Convert any number representation to a number \n This covers: float, decimal, hex, and octal numbers.\n '''\n\n try:\n return int(str(n), 0)\n except:\n try:\n # python 3 doesn't accept \"010\" as a valid octal. You must use the\n # '0o' prefix\n return int('0o' + n, 0)\n except:\n return float(n)\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209513",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17693/"
] |
209,516
|
<p>I inherited this gigantic legacy Java web app using Struts 1.2.4. I have a specific question regarding Actions. Most of the pages have exactly one Action, and the processExecute() methods are hideous monsters (very long and tons of nested if statements based on request parameters).</p>
<p>Given that Actions are an implementation of the command pattern, I'm thinking to split these Actions into one Action per user gesture. This will be a large refactoring though, and I'm wondering:</p>
<ol>
<li>Is this the right direction?</li>
<li>Is there an intermediate step I could take, a pattern that deals with the mess inside the monolithic actions? Maybe another command pattern inside the Action?</li>
</ol>
|
[
{
"answer_id": 209730,
"author": "extraneon",
"author_id": 24582,
"author_profile": "https://Stackoverflow.com/users/24582",
"pm_score": 1,
"selected": false,
"text": "enum Operation {\n ADD, DELETE;\n}\n\n...\n\nOperation operation = determineOperation(form);\nif (operation == Operation.DELETE) { \n doDelete(form); \n} else if (operation == Operation.ADD) {\n doAdd(form);\n}\n"
},
{
"answer_id": 210893,
"author": "Ogre Psalm33",
"author_id": 13140,
"author_profile": "https://Stackoverflow.com/users/13140",
"pm_score": 2,
"selected": false,
"text": "Original Hierarchy: New Hierarchy:\n\n Action Action\n | |\n | BaseA\n (old)ClassA |\n +--------+----------+\n | | |\n ClassB (new)ClassA ClassC\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209516",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13041/"
] |
209,528
|
<p>How would I drag and drop something into a static control? It looks like I need to create a sub class of COleDropTarget and include that as a member variable in a custom CStatic. That doesn't appear to be working though. When I try and drag something onto the Static control I get the drop denied cursor.</p>
|
[
{
"answer_id": 209870,
"author": "ChrisN",
"author_id": 3853,
"author_profile": "https://Stackoverflow.com/users/3853",
"pm_score": 3,
"selected": true,
"text": "m_hWnd COleDropTarget::Register CMyStatic CWnd::PreSubclassWindow CMyStatic class CMyStatic : public CStatic {\n ...\n virtual void PreSubclassWindow();\n};\n\nvoid CMyStatic::PreSubclassWindow()\n{\n CStatic::PreSubclassWindow();\n\n m_MyDropTarget.Register(this);\n}\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209528",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6701/"
] |
209,534
|
<p>Please don't reply I should use ddd, nemiver, emacs, vim, or any other front-end, I just prefer gdb as it is, but would like to see its output with some terminal colors.</p>
|
[
{
"answer_id": 249750,
"author": "John Carter",
"author_id": 8331,
"author_profile": "https://Stackoverflow.com/users/8331",
"pm_score": 7,
"selected": false,
"text": "gdb -tui executable.out\n"
},
{
"answer_id": 1123400,
"author": "RandomNickName42",
"author_id": 67819,
"author_profile": "https://Stackoverflow.com/users/67819",
"pm_score": -1,
"selected": false,
"text": "# gdb\n(gdb) shell echo -en '\\E[47;34m'\"\\033[1m\"\n...\nanything is now blue foreground and white background\n...\n(gdb) shell tput sgr0\n... back to normal\n"
},
{
"answer_id": 3256580,
"author": "Mike",
"author_id": 14717,
"author_profile": "https://Stackoverflow.com/users/14717",
"pm_score": 4,
"selected": false,
"text": "set prompt \\033[1;31m(gdb) \\033[m set prompt \\033[01;31m\\n\\n#####################################> \\033[0m"
},
{
"answer_id": 10418251,
"author": "ftk",
"author_id": 1370490,
"author_profile": "https://Stackoverflow.com/users/1370490",
"pm_score": 3,
"selected": false,
"text": "#into .gdbinit\nshell mkfifo /tmp/colorPipe\n\ndefine hook-disassemble\necho \\n\nshell cat /tmp/colorPipe | c++filt | highlight --syntax=asm -s darkness -Oxterm256 &\nset logging redirect on\nset logging on /tmp/colorPipe\nend \n\ndefine hookpost-disassemble\nhookpost-list\nend \n\ndefine hook-list\necho \\n\nshell cat /tmp/colorPipe | c++filt | highlight --syntax=cpp -s darkness -Oxterm256 &\nset logging redirect on\nset logging on /tmp/colorPipe\nend \n\ndefine hookpost-list\nset logging off \nset logging redirect off \nshell sleep 0.1s\nend \n\ndefine hook-quit\nshell rm /tmp/colorPipe\nend \n\ndefine re\nhookpost-disassemble\necho \\033[0m\nend \ndocument re\nRestore colorscheme\nend \n"
},
{
"answer_id": 15916463,
"author": "justin.yqyang",
"author_id": 1012014,
"author_profile": "https://Stackoverflow.com/users/1012014",
"pm_score": 3,
"selected": false,
"text": "cgdb gdb -tui"
},
{
"answer_id": 17341335,
"author": "BenC",
"author_id": 1043187,
"author_profile": "https://Stackoverflow.com/users/1043187",
"pm_score": 9,
"selected": true,
"text": "~/.gdbinit .gdbinit windbg pwndbg pwnd-bag .gdbinit"
},
{
"answer_id": 21201688,
"author": "Evgeni Sergeev",
"author_id": 1143274,
"author_profile": "https://Stackoverflow.com/users/1143274",
"pm_score": 2,
"selected": false,
"text": "gdb backtrace python stack_trace = gdb.execute('backtrace', False, True')\n stack_trace def term_style(*v):\n \"\"\"1 is bold, 30--37 are the 8 colours, but specifying bold may also\n change the colour. 40--47 are background colours.\"\"\"\n return '\\x1B['+';'.join(map(str, v))+'m'\n\n#Use like this:\nprint term_style(1) + 'This will be bold' + term_style(0) #Reset.\nprint term_style(1,30) + 'This will be bold and coloured' + term_style(0)\nprint term_style(1,30,40) + 'Plus coloured background' + term_style(0)\n"
},
{
"answer_id": 46733327,
"author": "Andrea Araldo",
"author_id": 2110769,
"author_profile": "https://Stackoverflow.com/users/2110769",
"pm_score": 2,
"selected": false,
"text": "~/.gdbinit"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209534",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1277510/"
] |
209,554
|
<p>I'm seeing this exception message coming from XslCompiledTransform.Transform(), but after handling the exception the XSL transform still appears to have been successful. The full exception message is:</p>
<blockquote>
<p>Token Text in state EndRootElement
would result in an invalid XML
document. Make sure that the
ConformanceLevel setting is set to
ConformanceLevel.Fragment or
ConformanceLevel.Auto if you want to
write an XML fragment.</p>
</blockquote>
<p>The stylesheet looks like this:</p>
<pre><code><xsl:stylesheet version="1.0" xmlns:ext="ext:extensions" xmlns:f="http://schemas.foo.com/FOAMSchema">
<xsl:template match="/Root/Documents/PO/DROPSHIP">
<Transactions>
<Transaction>
<f:partnerTransmission>
<transmission_id>
<xsl:value-of select="ext:NewGUID()"/>
</transmission_id>
<partner_code>
<xsl:value-of select="/Root/@PartnerCode"/>
</partner_code>
<control_nbr>
<xsl:value-of select="@GS_CNTRL_NUM"/>
</control_nbr>
<creationTime>
<xsl:value-of select="ext:ConvertToStandardDateTime(@DATE,@TIME,'ISO8601Basic')"/>
</creationTime>
<direction>I</direction>
<messageCount>
<xsl:value-of select="count(ORDERS/ORDER)"/>
</messageCount>
<syntax>XML</syntax>
<format>BARBAZ</format>
<deliveryMethod>FTP</deliveryMethod>
</f:partnerTransmission>
</Transaction>
</Transactions>
</xsl:template>
</xsl:stylesheet>
</code></pre>
<p>The generated XML looks like this:</p>
<pre><code><Transactions xmlns="http://schemas.foo.com/IntegrationProfile" xmlns:ext="ext:extensions">
<Transaction>
<f:partnerTransmission xmlns:f="http://schemas.foo.com/FOAMSchema">
<transmission_id>a5e0ec76-6c24-426b-9eb5-aef9c45d913f</transmission_id>
<partner_code>VN000033</partner_code>
<control_nbr>650</control_nbr>
<creationTime>9/27/2008 12:51:00 AM</creationTime>
<direction>I</direction>
<messageCount>2</messageCount>
<syntax>XML</syntax>
<format>BARBAZ</format>
<deliveryMethod>FTP</deliveryMethod>
</f:partnerTransmission>
</Transaction>
</Transactions>
</code></pre>
<p>The above is what I get when I catch and ignore the exception.</p>
<p>I haven't been able to find a way to set the ConformanceLevel (the property is read-only), but at the same time I also don't think there should be a problem here anyway.</p>
<p>Does my output constitute an XML fragment? Am I missing something in the stylesheet?</p>
|
[
{
"answer_id": 209697,
"author": "ddaa",
"author_id": 11549,
"author_profile": "https://Stackoverflow.com/users/11549",
"pm_score": 0,
"selected": false,
"text": "conformanceLevel conformanceLevel"
},
{
"answer_id": 2451956,
"author": "John Saunders",
"author_id": 76337,
"author_profile": "https://Stackoverflow.com/users/76337",
"pm_score": 4,
"selected": true,
"text": "<xsl:template match=\"/\">\n <xsl:apply-templates select=\"/Root/Documents/PO/DROPSHIP\"/>\n</xsl:template>\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209554",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5548/"
] |
209,558
|
<p>I'm attempting to put together some basic report screens. I've got some fairly complicated SQL queries that I'm feeding into ActiveRecord's find_by_sql method. The problem I am having here is that I am losing the order of the columns as given in the original query. I'm assuming that this is because the Hash class does not preserve entry order of its keys. </p>
<p>Is there a way around this problem? Should I be using a different method then find_by_sql for my queries?</p>
|
[
{
"answer_id": 209894,
"author": "Mike Woodhouse",
"author_id": 1060,
"author_profile": "https://Stackoverflow.com/users/1060",
"pm_score": 3,
"selected": true,
"text": "<% for row in @report.rows %>\n <tr>\n <% for col in [:a, :b, :c] %>\n <td><%= row[col] %></td>\n <% end %>\n </tr>\n<% end %>\n"
},
{
"answer_id": 36153593,
"author": "Stan Brajewski",
"author_id": 6098343,
"author_profile": "https://Stackoverflow.com/users/6098343",
"pm_score": 1,
"selected": false,
"text": "attribute_names find_by_sql Product.find_by_sql Product"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209558",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23513/"
] |
209,595
|
<p>I want to make a deep copy of a LINQ to XML XElement. The reason I want to do this is there are some nodes in the document that I want to create modified copies of (in the same document). I don't see a method to do this.</p>
<p>I could convert the element to an XML string and then reparse it, but I'm wondering if there's a better way.</p>
|
[
{
"answer_id": 209674,
"author": "Daniel Plaisted",
"author_id": 1509,
"author_profile": "https://Stackoverflow.com/users/1509",
"pm_score": 3,
"selected": false,
"text": "XElement copy = XElement.Parse(original.ToString());\n"
},
{
"answer_id": 212259,
"author": "Wonko",
"author_id": 14842,
"author_profile": "https://Stackoverflow.com/users/14842",
"pm_score": 2,
"selected": false,
"text": "var address = new XElement (\"address\",\n new XElement (\"street\", \"Lawley St\"),\n new XElement (\"town\", \"North Beach\")\n );\nvar customer1 = new XElement (\"customer1\", address);\nvar customer2 = new XElement (\"customer2\", address);\n\ncustomer1.Element (\"address\").Element (\"street\").Value = \"Another St\";\nConsole.WriteLine (\n customer2.Element (\"address\").Element (\"street\").Value); // Lawley St\n"
},
{
"answer_id": 356489,
"author": "Jonathan Moffatt",
"author_id": 45031,
"author_profile": "https://Stackoverflow.com/users/45031",
"pm_score": 8,
"selected": true,
"text": "XElement original = new XElement(\"original\");\nXElement deepCopy = new XElement(original);\n [TestMethod]\npublic void XElementShallowCopyShouldOnlyCopyReference()\n{\n XElement original = new XElement(\"original\");\n XElement shallowCopy = original;\n shallowCopy.Name = \"copy\";\n Assert.AreEqual(\"copy\", original.Name);\n}\n\n[TestMethod]\npublic void ShouldGetXElementDeepCopyUsingConstructorArgument()\n{\n XElement original = new XElement(\"original\");\n XElement deepCopy = new XElement(original);\n deepCopy.Name = \"copy\";\n Assert.AreEqual(\"original\", original.Name);\n Assert.AreEqual(\"copy\", deepCopy.Name);\n}\n"
},
{
"answer_id": 18276905,
"author": "Chris Cavanagh",
"author_id": 2689926,
"author_profile": "https://Stackoverflow.com/users/2689926",
"pm_score": -1,
"selected": false,
"text": "var copy = new XElement(original.Name, original.Attributes(),\n original.Elements() );\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209595",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1509/"
] |
209,603
|
<p>What are the easiest steps to make a small circuit with an LED flash from a C/C++ program?</p>
<p>I would prefer the least number of dependencies and packages needed. </p>
<ul>
<li>What port would I connect something into?</li>
<li>Which compiler would I use?</li>
<li>How do I send data to that port?</li>
<li>Do I need to have a micro-processor? If not I don't want to use one for this simple project.</li>
</ul>
<p>EDIT: Interested in any OS specific solutions.</p>
|
[
{
"answer_id": 209658,
"author": "mwilliams",
"author_id": 23909,
"author_profile": "https://Stackoverflow.com/users/23909",
"pm_score": 5,
"selected": true,
"text": "/* Blinking LED\n * ------------\n *\n * turns on and off a light emitting diode(LED) connected to a digital \n * pin, in intervals of 2 seconds. Ideally we use pin 13 on the Arduino \n * board because it has a resistor attached to it, needing only an LED\n\n * \n * Created 1 June 2005\n * copyleft 2005 DojoDave <http://www.0j0.org>\n * http://arduino.berlios.de\n *\n * based on an orginal by H. Barragan for the Wiring i/o board\n */\n\nint ledPin = 13; // LED connected to digital pin 13\n\nvoid setup()\n{\n pinMode(ledPin, OUTPUT); // sets the digital pin as output\n}\n\nvoid loop()\n{\n digitalWrite(ledPin, HIGH); // sets the LED on\n delay(1000); // waits for a second\n digitalWrite(ledPin, LOW); // sets the LED off\n delay(1000); // waits for a second\n}\n"
},
{
"answer_id": 209671,
"author": "Dan Lenski",
"author_id": 20789,
"author_profile": "https://Stackoverflow.com/users/20789",
"pm_score": 3,
"selected": false,
"text": "ioctl()"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209603",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3153/"
] |
209,615
|
<p>Using the following query:</p>
<pre><code> SELECT pe.prodtree_element_name_l, MAX(rs.resource_value) AS resource_value
FROM prodtree_element pe
LEFT JOIN resource_shortstrings rs
ON pe.prodtree_element_name_l_rk = rs.resource_key
WHERE rs.language_id = '5'
AND pe.prodtree_element_name_l <> ''
GROUP BY prodtree_element_name_l
</code></pre>
<p>I'm trying to figure out how to grab ANY of the "resource_value". The problem being that while this works for a number of other queries, I have one particular table that uses ntext datatypes instead of varchars (which can't utilize the MAX function). So basically, MAX doesn't work here. Is there a substitute I can use on MS SQL Server 2005?</p>
<p>I need the prodtree_element_name_l column grouped, but I only need one value from the resource_value column, and I don't care what it is as most of them are identical regardless (although some are not, hence I can't group that one as well).</p>
<p>UPDATE:</p>
<p>Whoops, I was wrong, prodtree_element_name_l is ALSO an NTEXT. That might help a little :p</p>
|
[
{
"answer_id": 209623,
"author": "Dave Markle",
"author_id": 24995,
"author_profile": "https://Stackoverflow.com/users/24995",
"pm_score": 0,
"selected": false,
"text": " SELECT pe.prodtree_element_name_l, MAX(CAST(rs.resource_value AS NVARCHAR(MAX))) AS resource_value\n FROM prodtree_element pe\n LEFT JOIN resource_shortstrings rs\n ON pe.prodtree_element_name_l_rk = rs.resource_key\n WHERE rs.language_id = '5'\n AND pe.prodtree_element_name_l <> ''\n GROUP BY prodtree_element_name_l\n"
},
{
"answer_id": 209688,
"author": "Mitchel Sellers",
"author_id": 13279,
"author_profile": "https://Stackoverflow.com/users/13279",
"pm_score": 2,
"selected": true,
"text": "SELECT DISTINCT \n pe.prodtree_element_name_l, \n (SELECT TOP 1 rs2.resource_value\n FROM resource_shortstrings rs2\n WHERE rs2.language_id = '5'\n AND rs2.resource_key = pe.prodtree_element_name_l_rk) AS \"resource_value\"\nFROM prodtree_element pe\nLEFT JOIN resource_shortstrings rs\n ON pe.prodtree_element_name_l_rk = rs.resource_key\nWHERE rs.language_id = '5'\n AND pe.prodtree_element_name_l IS NOT NULL\n--GROUP BY prodtree_element_name_l\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209615",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16631/"
] |
209,657
|
<p>I have a footer that is a 1 x 70px, which is set as the background and tiles horizonally.</p>
<p>In cases when the web page does not contain a lot of content on it, it will display the footer above where the footer should be. I want it to fill in with a solid color, so if they scroll down, it won't show the footer, then the white under the footer.</p>
<p>Here is the style I have for the footer.</p>
<pre><code>.footer{
background:#055830 url('/images/footer_tile.gif') repeat-x top left;
color:#fff;
font-size:12px;
height: 70px;
margin-top: 10px;
font-family: Arial, Verdana, sans-serif;
width:100%;
}
</code></pre>
<p><img src="https://i.stack.imgur.com/pUzIQ.jpg" alt="alt text"></p>
<p>I want the footer to look like this:
<img src="https://i.stack.imgur.com/s96Ft.jpg" alt="alt text"></p>
|
[
{
"answer_id": 209664,
"author": "Mitchel Sellers",
"author_id": 13279,
"author_profile": "https://Stackoverflow.com/users/13279",
"pm_score": 0,
"selected": false,
"text": "position:absolute;\nbottom: 0;\n"
},
{
"answer_id": 209668,
"author": "JSBձոգչ",
"author_id": 8078,
"author_profile": "https://Stackoverflow.com/users/8078",
"pm_score": 0,
"selected": false,
"text": ".footer{\n background:#055830 url('/images/footer_tile.gif') repeat top left;\n color:#fff;\n font-size:12px;\n height: 100%;\n margin-top: 10px;\n font-family: Arial, Verdana, sans-serif;\n width:100%;\n}\n"
},
{
"answer_id": 209684,
"author": "Chris Marasti-Georg",
"author_id": 96,
"author_profile": "https://Stackoverflow.com/users/96",
"pm_score": 3,
"selected": true,
"text": "body {\n background-color:#060;\n}\n"
},
{
"answer_id": 209702,
"author": "Ken Penn",
"author_id": 3531,
"author_profile": "https://Stackoverflow.com/users/3531",
"pm_score": 1,
"selected": false,
"text": "body {\n\nbackground: rgb(173, 173, 173);\n}\n"
},
{
"answer_id": 209713,
"author": "Brad",
"author_id": 26130,
"author_profile": "https://Stackoverflow.com/users/26130",
"pm_score": 0,
"selected": false,
"text": ".footer{\n background:#055830 url('/images/footer_tile.gif') repeat top left;\n color:#fff;\n font-size:12px;\n margin-top: 10px;\n font-family: Arial, Verdana, sans-serif;\n width:100%;\n position:absolute;\n bottom: 0;\n}\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209657",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26130/"
] |
209,686
|
<p>I've often had to load multiple items to a particular record in the database. For example: a web page displays items to include for a single report, all of which are records in the database (Report is a record in the Report table, Items are records in Item table). A user is selecting items to include in a single report via a web app, and let's say they select 3 items and submit. The process will add these 3 items to this report by adding records to a table called ReportItems (ReportId,ItemId).</p>
<p>Currently, I would do something like this in in the code:</p>
<pre><code>public void AddItemsToReport(string connStr, int Id, List<int> itemList)
{
Database db = DatabaseFactory.CreateDatabase(connStr);
string sqlCommand = "AddItemsToReport"
DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);
string items = "";
foreach (int i in itemList)
items += string.Format("{0}~", i);
if (items.Length > 0)
items = items.Substring(0, items.Length - 1);
// Add parameters
db.AddInParameter(dbCommand, "ReportId", DbType.Int32, Id);
db.AddInParameter(dbCommand, "Items", DbType.String, perms);
db.ExecuteNonQuery(dbCommand);
}
</code></pre>
<p>and this in the Stored procedure:</p>
<pre><code>INSERT INTO ReportItem (ReportId,ItemId)
SELECT @ReportId,
Id
FROM fn_GetIntTableFromList(@Items,'~')
</code></pre>
<p>Where the function returns a one column table of integers.</p>
<p>My question is this: is there a better way to handle something like this? Note, I'm not asking about database normalizing or anything like that, my question relates specifically with the code.</p>
|
[
{
"answer_id": 209711,
"author": "Jason Jackson",
"author_id": 13103,
"author_profile": "https://Stackoverflow.com/users/13103",
"pm_score": 4,
"selected": false,
"text": "string items = \n string.Join(\"~\", itemList.Select(item=>item.ToString()).ToArray());\n"
},
{
"answer_id": 209895,
"author": "Joe",
"author_id": 13087,
"author_profile": "https://Stackoverflow.com/users/13087",
"pm_score": 3,
"selected": false,
"text": "public static IEnumerable<string> ConcatenateValues(IEnumerable<int> values, string separator, int maxLength, bool skipDuplicates)\n{\n IDictionary<int, string> valueDictionary = null;\n StringBuilder sb = new StringBuilder();\n if (skipDuplicates)\n {\n valueDictionary = new Dictionary<int, string>();\n }\n foreach (int value in values)\n {\n if (skipDuplicates)\n {\n if (valueDictionary.ContainsKey(value)) continue;\n valueDictionary.Add(value, \"\");\n }\n string s = value.ToString(CultureInfo.InvariantCulture);\n if ((sb.Length + separator.Length + s.Length) > maxLength)\n {\n // Max length reached, yield the result and start again\n if (sb.Length > 0) yield return sb.ToString();\n sb.Length = 0;\n }\n if (sb.Length > 0) sb.Append(separator);\n sb.Append(s);\n }\n // Yield whatever's left over\n if (sb.Length > 0) yield return sb.ToString();\n}\n using(SqlCommand command = ...)\n{\n command.Connection = ...;\n command.Transaction = ...; // if in a transaction\n SqlParameter parameter = command.Parameters.Add(\"@Items\", ...);\n foreach(string itemList in ConcatenateValues(values, \"~\", 8000, false))\n {\n parameter.Value = itemList;\n command.ExecuteNonQuery();\n }\n}\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209686",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27908/"
] |
209,687
|
<p>I'm trying to order items based on an attribute value:</p>
<pre><code><xsl:apply-templates select="Question">
<xsl:sort order="ascending" select="@Value"></xsl:sort>
</xsl:apply-templates>
</code></pre>
<p>This does order them, but I could have values like 1,2,3, ... 10, 11, ... 20 and it will order them 1,10,11, ... 2,20... 3. etc.<br>
I could also have values like 1.A, 1.B, 2.A, 2.B etc.</p>
<p>How can I order these values to take into account the numeric content and the alphabetic, in that priority?</p>
|
[
{
"answer_id": 209700,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 2,
"selected": false,
"text": "data-type <xsl:sort order=\"ascending\" select=\"@Value\" data-type=\"number\"></xsl:sort>\n"
},
{
"answer_id": 209746,
"author": "rasx",
"author_id": 22944,
"author_profile": "https://Stackoverflow.com/users/22944",
"pm_score": 0,
"selected": false,
"text": "<xsl:template match=\"employees\">\n <xsl:apply-templates>\n <xsl:sort select=\"salary\" data-type=\"number\"/>\n </xsl:apply-templates>\n</xsl:template>\n data-type xsl:number"
},
{
"answer_id": 209837,
"author": "JeniT",
"author_id": 6739,
"author_profile": "https://Stackoverflow.com/users/6739",
"pm_score": 4,
"selected": true,
"text": "<xsl:sort> <xsl:apply-templates select=\"Question\">\n <xsl:sort select=\"substring-before(@Value, '.')\" data-type=\"number\" />\n <xsl:sort select=\"substring-after(@Value, '.')\" />\n</xsl:apply-templates>\n <xsl:apply-templates select=\"Question\">\n <xsl:sort select=\"substring-before(concat(@Value, '.'), '.')\" data-type=\"number\" />\n <xsl:sort select=\"substring-after(@Value, '.')\" />\n</xsl:apply-templates>\n concat(@Value, '.') . substring-before()"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209687",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9266/"
] |
209,706
|
<p>I'm asking in generalities - why would any server not set and return headers and/or status codes? I can't think of a good reason for this. Perhaps I'm overlooking something.</p>
|
[
{
"answer_id": 210183,
"author": "Paul Dixon",
"author_id": 6521,
"author_profile": "https://Stackoverflow.com/users/6521",
"pm_score": 2,
"selected": false,
"text": "GET /\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209706",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/572/"
] |
209,717
|
<p>I'm using a column of checkboxes in a YUI DataTable, I works fine. But I haven't found a way to put a name and value attribute so I can use when the form is submitted.</p>
<p>Thanks in advance.</p>
|
[
{
"answer_id": 342945,
"author": "Ryan Doherty",
"author_id": 956,
"author_profile": "https://Stackoverflow.com/users/956",
"pm_score": 0,
"selected": false,
"text": "<input type=\"checkbox\" name=\"the_name\" value=\"the_value\" />\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209717",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24927/"
] |
209,721
|
<p>I'm doing a personal organizer for learning purposes, and i've never worked with XML so i'm not sure if my solution is the best. Here's the basic structure for the XML file i came with:</p>
<pre><code><calendar>
<year value="2008">
<month value="october">
<day value="16">
<activity name="mike's birthday" time="21:00" address="mike's apartment" urgency="10">
activity description.
</activity>
</day>
</month>
</year>
</calendar>
</code></pre>
<p>The urgency attribute should be on a scale of 1 to 10. <br/>
I did a quick search on google and couldn't find a good example. Maybe that's not the best solution, and i'd like to know if its adequate. I'm doing the application in PHP if that has any relevance.</p>
|
[
{
"answer_id": 209733,
"author": "Adam V",
"author_id": 517,
"author_profile": "https://Stackoverflow.com/users/517",
"pm_score": 3,
"selected": true,
"text": "<activity>\n <name>Mike's Birthday</name>\n <time>2100</time>\n <address>Mike's Place</address>\n <urgency>10</urgency>\n <description>activity description</description>\n</activity>\n"
},
{
"answer_id": 209762,
"author": "Kev",
"author_id": 419,
"author_profile": "https://Stackoverflow.com/users/419",
"pm_score": 0,
"selected": false,
"text": "<calendar>\n <activity\n id=\"123456\"\n name=\"mike's birthday\" \n year=\"2008\"\n month=\"10\"\n day=\"16\"\n time=\"21:00\" \n address=\"mike's apartment\" \n urgency=\"10\">\n activity description.\n </activity>\n</calendar>\n <calendar>\n <activity id=\"12345\">\n <name>mike's birthday</name>\n <year>2008</year>\n <month>10<month>\n <day>16</day>\n <time>21:00</time>\n <urgency>10</urgency>\n <address>mike's apartment<address>\n <description>activity description.</description>\n </activity>\n</calendar>\n"
},
{
"answer_id": 209879,
"author": "Robert Rossney",
"author_id": 19403,
"author_profile": "https://Stackoverflow.com/users/19403",
"pm_score": 1,
"selected": false,
"text": "/calendar/year[@value='2008']/month[@value='10']/day[@value='7']/activity\n /calendar/activity[@year='2008' and @month='10' and @day='7']\n month day @day='7' day \"07\" number()"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209721",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27090/"
] |
209,725
|
<p>We have an auto-complete list that's populated when an you send an email to someone, which is all well and good until the list gets really big you need to type more and more of an address to get to the one you want, which goes against the purpose of auto-complete</p>
<p>I was thinking that some logic should be added so that the auto-complete results should be sorted by some function of most recently contacted or most often contacted rather than just alphabetical order.</p>
<p>What I want to know is if there's any known good algorithms for this kind of search, or if anyone has any suggestions. </p>
<p>I was thinking just a point system thing, with something like same day is 5 points, last three days is 4 points, last week is 3 points, last month is 2 points and last 6 months is 1 point. Then for most often, 25+ is 5 points, 15+ is 4, 10+ is 3, 5+ is 2, 2+ is 1. No real logic other than those numbers "feel" about right.</p>
<p>Other than just arbitrarily picked numbers does anyone have any input? Other numbers also welcome if you can give a reason why you think they're better than mine</p>
<p>Edit: This would be primarily in a business environment where recentness (yay for making up words) is often just as important as frequency. Also, past a certain point there really isn't much difference between say someone you talked to 80 times vs say 30 times.</p>
|
[
{
"answer_id": 9336825,
"author": "Umbrella",
"author_id": 1125513,
"author_profile": "https://Stackoverflow.com/users/1125513",
"pm_score": 0,
"selected": false,
"text": "UPDATE `addresslist` SET `favor` = `favor` + 10 WHERE `address` = 'foo@bar.com'\n UPDATE `addresslist` SET `favor` = FLOOR(`favor` * 0.9)\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209725",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23822/"
] |
209,731
|
<p>First of all, using gnome is not an option (but it is possible to install its libraries).</p>
<p>I need to know what is necessary to display a Java Swing desktop application using the current installed KDE look and feel of KDE. Ideally, the solution should allow me to apply a look and feel that looks like the underlying windowing system (ie: Windows LNF for Windows, GTK LNF for Gnome(GTK), QT LNF for KDE (QT), the default one for other platforms).</p>
<p>Under KDE, you can configure it to use the current KDE theme for GTK applications, too. So, if the solution works with GTK it is fine.</p>
<p>When I run the following piece of code under Gnome (Ubuntu 8.04), the Java application looks beautiful. It integrates very well with the rest of applications:</p>
<pre><code>try {
// Set System L&F
UIManager.setLookAndFeel(
UIManager.getSystemLookAndFeelClassName());
} catch(Exception e) { //Handle it }
</code></pre>
<p>However, if I run the same thing under Debian (Lenny) with KDE, the UIManager.getSystemLookAndFeelClassName() call returns the Java default one.
If I go ahead and force it to use the GTK LNF, the application doesn't work. Some fields are invisible, others become out of place, everything is unusable:</p>
<pre><code>try {
//Force the GTK LNF on top of KDE, but **it doesn't work**
UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
} catch (Exception e) { /*Handle it*/ }
</code></pre>
<p>I've also tried to put the following code. It let's the user chose any one of the available LNF and then tries to set it. Metal and Motif work fine. GTK doesn't. The slider is really messed up. The list box looks ugly and disappears, but seems to work. Buttons and menu seem ok. The relevant code is shown here:</p>
<pre><code>(...)
/** Creates new form SwingFrame */
public SwingFrame() {
initComponents();
//Save all available lafs in a combobox
cbLafs.removeAllItems();
UIManager.LookAndFeelInfo[] lafs=UIManager.getInstalledLookAndFeels();
for (int i=0,t=lafs.length;i<t;i++)
{
cbLafs.addItem(lafs[i]);
System.out.println(lafs[i].getName());
}
}
public void changeLookAndFeel(String laf)
{
//If not specified, get the default one
if (laf==null) {
laf=UIManager.getSystemLookAndFeelClassName();
}
try {
// Set System L&F
UIManager.setLookAndFeel(laf);
}
catch (Exception e) {
// handle exception
e.printStackTrace();
}
SwingUtilities.updateComponentTreeUI(this);
}
private void cbLafsActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
UIManager.LookAndFeelInfo laf=(UIManager.LookAndFeelInfo)cbLafs.getSelectedItem();
if (laf==null)
changeLookAndFeel(null);
else
changeLookAndFeel(laf.getClassName());
}
</code></pre>
<p>This same system has all GTK applications working (for example: Firefox) as expected. So:</p>
<p>1) What is missing from the environment to have a Java GTK LNF application working under KDE?</p>
<p>2) What does the JVM checks for to return GTK as the default system theme?</p>
<p>Thanks for you help
Luis Fernando</p>
<p>PS->I've tried other solutions,too, such as JGoodies, plain AWT and SWT. However, Swing with GTK LNF would be the best solution to avoid the hassle of SWT native libraries and JGoodies extra jars (also, JGoodies LNF doesn't look as integrated as Swing GTK under Gnome). AWT looks hideous (motif-like) and misses lots of features.</p>
|
[
{
"answer_id": 211004,
"author": "Marcus Tik",
"author_id": 23450,
"author_profile": "https://Stackoverflow.com/users/23450",
"pm_score": 0,
"selected": false,
"text": "try {\n// sure look and feel\nUIManager.setLookAndFeel(\"com.sun.java.swing.plaf.gtk.GTKLookAndFeel\");\n// not-so-sure look and feel\nSystem.setProperty(\"os.name\", \"Windows\");\nSystem.setProperty(\"os.version\", \"5.1\");\nUIManager.setLookAndFeel(\"com.sun.java.swing.plaf.windows.WindowsLookAndFeel\");\n} \ncatch (Exception ex) {\nex.printStackTrace();\n}\n"
},
{
"answer_id": 213546,
"author": "Davide",
"author_id": 25891,
"author_profile": "https://Stackoverflow.com/users/25891",
"pm_score": 1,
"selected": false,
"text": "swing.defaultlaf swing.properties swing.defaultlaf swing.properties ${java.home}/lib/swing.properties updateUI JComponents SwingUtilities.updateComponentTreeUI(java.awt.Component) updateUI JComponents UIManager.setLookAndFeel"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209731",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24165/"
] |
209,732
|
<p>I have code similar to this filtering entries in an Array of Objects:</p>
<pre><code>var filterRegex = new RegExp(".*blah.*","ig");
if (filterRegex.test(events[i].thing) && events[i].show) {
console.log("SUCCESS: filtering thing " + i + " " + events[i].thing);
events[i].show = false;
numevents--;
}
</code></pre>
<p>I get inconsistent results with this if condition (checking with Firebug, both conditions are true individually, but <em>sometimes</em> the whole expression evaluates to false). HOWEVER, if I actually put an <code>alert()</code> called inside this if statement (like line 4), it becomes consistent and I get the result I want.</p>
<p>Can you see anything wrong with this logic and tell me why it's not always producing what is expected?</p>
|
[
{
"answer_id": 209817,
"author": "Tomalak",
"author_id": 18771,
"author_profile": "https://Stackoverflow.com/users/18771",
"pm_score": 0,
"selected": false,
"text": "regex.test() event.show event[0].show event[i].show"
},
{
"answer_id": 210077,
"author": "Shog9",
"author_id": 811,
"author_profile": "https://Stackoverflow.com/users/811",
"pm_score": 7,
"selected": true,
"text": "g lastIndex var testRegex = /blah/ig;\n// logs: true 4\nconsole.log(testRegex.test(\"blah blah\"), testRegex.lastIndex);\n// logs: true 9 \nconsole.log(testRegex.test(\"blah blah\"), testRegex.lastIndex);\n// logs: false 0\nconsole.log(testRegex.test(\"blah blah\"), testRegex.lastIndex);\n g lastIndex lastIndex lastIndex lastIndex lastIndex lastIndex test() var filterRegex = /.*blah.*/ig;\n// logs: true, 9\nconsole.log(filterRegex.test(\"blah blah\"), filterRegex.lastIndex);\n// logs: false, 0 \nconsole.log(filterRegex.test(\"blah blah\"), filterRegex.lastIndex);\n test() test() test() test() false var filterRegex = /.*blah.*/i;\n// logs: true, 0\nconsole.log(filterRegex.test(\"blah blah\"), filterRegex.lastIndex);\n// logs: true, 0 \nconsole.log(filterRegex.test(\"blah blah\"), filterRegex.lastIndex);\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209732",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25066/"
] |
209,738
|
<p>I need that my Apache require authentication only to external access but free in my local network. I have mod_user in my Apache.</p>
|
[
{
"answer_id": 209821,
"author": "James Schek",
"author_id": 17871,
"author_profile": "https://Stackoverflow.com/users/17871",
"pm_score": 2,
"selected": false,
"text": "Require valid-user\nAllow from 192.168.1\nSatisfy Any \n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209738",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
209,753
|
<p>I have an error handling method in my ApplicationController:</p>
<pre><code>rescue_from ActiveRecord::RecordNotFound, :with => :not_found
def not_found(exception)
@exception = exception
render :template => '/errors/not_found', :status => 404
end
</code></pre>
<p>In <code>RAILS_ROOT/app/views/errors/not_found.html.erb</code>, I have this:</p>
<pre><code><h1>Error 404: Not Found</h1>
<%= debug @exception %>
</code></pre>
<p>But <code>@exception</code> is always <code>nil</code> there. I've tried <code>debug assigns</code>, but that's always <code>{}</code>. Do assigns not get copied when calling <code>render :template</code>? If so, how can I get them?</p>
<p>I'm on edge Rails.</p>
|
[
{
"answer_id": 209792,
"author": "Avdi",
"author_id": 20487,
"author_profile": "https://Stackoverflow.com/users/20487",
"pm_score": 4,
"selected": true,
"text": "def not_found(exception)\n render :template => '/errors/not_found', \n :status => 404, \n :locals => {:exception => exception}\nend\n <h1>Error 404: Not Found</h1>\n<%= debug exception %> <!-- Note no '@' -->\n"
},
{
"answer_id": 209796,
"author": "Brian Kelly",
"author_id": 8252,
"author_profile": "https://Stackoverflow.com/users/8252",
"pm_score": 1,
"selected": false,
"text": "render :template => '/errors/not_found', :status => 404, :locals => {:exception => exception}\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209753",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1190/"
] |
209,754
|
<p>We have a sitemap for our site <a href="http://www.appsamuck.com/" rel="nofollow noreferrer">http://www.appsamuck.com/</a></p>
<p>The sitemap is here <a href="http://www.appsamuck.com/sitemap.xml" rel="nofollow noreferrer">http://www.appsamuck.com/sitemap.xml</a></p>
<p>But Google seems to hate it. My question is why? I'm just staring at it now saying to myself it looks right. Am I missing something?</p>
<p>3 Paths don't match
We've detected that you submitted your Sitemap using a URL path that doesn't include the www prefix (for instance, <a href="http://example.com/sitemap.xml" rel="nofollow noreferrer">http://example.com/sitemap.xml</a>). However, the URLs listed inside your Sitemap do use the www prefix (for instance, <a href="http://www.example.com/myfile.htm" rel="nofollow noreferrer">http://www.example.com/myfile.htm</a>). Help Help
URL:
Problem detected on: <a href="http://www.appsamuck.com/" rel="nofollow noreferrer">http://www.appsamuck.com/</a>
Oct 15, 2008</p>
|
[
{
"answer_id": 209767,
"author": "Diodeus - James MacFarlane",
"author_id": 12579,
"author_profile": "https://Stackoverflow.com/users/12579",
"pm_score": -1,
"selected": false,
"text": "<lastmod></lastmod>, <changefreq></changefreq>, <priority></priority>"
},
{
"answer_id": 211531,
"author": "Paul M",
"author_id": 28241,
"author_profile": "https://Stackoverflow.com/users/28241",
"pm_score": 2,
"selected": false,
"text": "print(\"code sample\");<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset\n xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9\n http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\">\n print(\"code sample\");\n <url>\n <loc>http://www.appsamuck.com/</loc>\n <priority>1.00</priority>\n <lastmod>2008-10-17T03:01:05+00:00</lastmod>\n <changefreq>monthly</changefreq>\n </url>\n <url>\n <loc>http://www.appsamuck.com/index.html</loc>\n <priority>0.80</priority>\n <lastmod>2008-10-17T03:01:05+00:00</lastmod>\n <changefreq>monthly</changefreq>\n </url>\n <url>\n <loc>http://www.appsamuck.com/blog/</loc>\n <priority>0.80</priority>\n <changefreq>monthly</changefreq>\n </url>\n <url>\n <loc>http://www.appsamuck.com/about.html</loc>\n <priority>0.80</priority>\n <lastmod>2008-10-16T00:00:32+00:00</lastmod>\n <changefreq>monthly</changefreq>\n </url>\n <url>\n <loc>http://www.appsamuck.com/contact.html</loc>\n <priority>0.80</priority>\n <lastmod>2008-10-16T00:00:33+00:00</lastmod>\n <changefreq>monthly</changefreq>\n </url>\n <url>\n <loc>http://www.appsamuck.com/iphonesdkdev.html</loc>\n <priority>0.80</priority>\n <lastmod>2008-10-14T05:41:03+00:00</lastmod>\n <changefreq>monthly</changefreq>\n </url>\n <url>\n <loc>http://www.appsamuck.com/day16.html</loc>\n <priority>0.80</priority>\n <lastmod>2008-10-17T03:13:21+00:00</lastmod>\n <changefreq>monthly</changefreq>\n </url>\n <url>\n <loc>http://www.appsamuck.com/day15.html</loc>\n <priority>0.80</priority>\n <lastmod>2008-10-16T15:58:57+00:00</lastmod>\n <changefreq>monthly</changefreq>\n </url>\n <url>\n <loc>http://www.appsamuck.com/day14.html</loc>\n <priority>0.80</priority>\n <lastmod>2008-10-15T16:58:06+00:00</lastmod>\n <changefreq>monthly</changefreq>\n </url>\n <url>\n <loc>http://www.appsamuck.com/day13.html</loc>\n <priority>0.80</priority>\n <lastmod>2008-10-13T17:52:08+00:00</lastmod>\n <changefreq>monthly</changefreq>\n </url>\n</urlset>\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209754",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23294/"
] |
209,774
|
<p>I found this <a href="http://pecl.php.net/package/threads" rel="noreferrer">PECL package called threads</a>, but there is not a release yet. And nothing is coming up on the PHP website.</p>
|
[
{
"answer_id": 210919,
"author": "Darryl Hein",
"author_id": 5441,
"author_profile": "https://Stackoverflow.com/users/5441",
"pm_score": 6,
"selected": false,
"text": "$cmd = 'nohup nice -n 10 /usr/bin/php -c /path/to/php.ini -f /path/to/php/file.php action=generate var1_id=23 var2_id=35 gen_id=535 > /path/to/log/file.log & echo $!';\n$pid = shell_exec($cmd);\n exec('ps ' . $pid , $processState);\nif (count($processState) < 2) {\n // less than 2 rows in the ps, therefore report is complete\n}\n"
},
{
"answer_id": 3434350,
"author": "The Surrican",
"author_id": 413910,
"author_profile": "https://Stackoverflow.com/users/413910",
"pm_score": 3,
"selected": false,
"text": "pcntl_fork() usleep() while ($process1->isRunning() && $process2->isRunning()) {\n sleep(1);\n}\nshould of course be:\nwhile ($process1->isRunning() || $process2->isRunning()) {\n sleep(1);\n}\n"
},
{
"answer_id": 14201579,
"author": "Francois Bourgeois",
"author_id": 1703313,
"author_profile": "https://Stackoverflow.com/users/1703313",
"pm_score": 5,
"selected": false,
"text": "$cmd = 'nice php script.php 2>&1 & echo $!';\npclose(popen($cmd, 'r'));\n $cmd = 'start \"processname\" /MIN /belownormal cmd /c \"script.php 2>&1\"';\npclose(popen($cmd, 'r'));\n class MyThread extends Thread {\n public function run(){\n //do something time consuming\n }\n}\n\n$t = new MyThread();\nif($t->start()){\n while($t->isRunning()){\n echo \".\";\n usleep(100);\n }\n $t->join();\n}\n extension=php_pthreads.dll\n"
},
{
"answer_id": 14548828,
"author": "Joe Watkins",
"author_id": 1658631,
"author_profile": "https://Stackoverflow.com/users/1658631",
"pm_score": 8,
"selected": false,
"text": "public function run() {\n ...\n (1) $this->data = $data;\n ...\n (2) $this->other = someOperation($this->data);\n ...\n}\n\n(3) echo preg_match($pattern, $replace, $thread->data);\n"
},
{
"answer_id": 17906444,
"author": "user2627170",
"author_id": 2627170,
"author_profile": "https://Stackoverflow.com/users/2627170",
"pm_score": 1,
"selected": false,
"text": "appserver"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209774",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/572/"
] |
209,779
|
<p>I am developing a wizard for a machine that is to be used as a backup of other machines. When it replaces an existing machine, it needs to set its IP address, DNS, WINS, and host name to match the machine being replaced.</p>
<p>Is there a library in .net (C#) which allows me to do this programatically?</p>
<p>There are multiple NICs, each which need to be set individually.</p>
<p><strong>EDIT</strong></p>
<p>Thank you <a href="https://stackoverflow.com/questions/209779/how-can-you-change-network-settings-ip-address-dns-wins-host-name-with-code-in-c#209822">TimothyP</a> for your example. It got me moving on the right track and the quick reply was awesome.</p>
<p>Thanks <a href="https://stackoverflow.com/questions/209779/how-can-you-change-network-settings-ip-address-dns-wins-host-name-with-code-in-c#209983">balexandre</a>. Your code is perfect. I was in a rush and had already adapted the example TimothyP linked to, but I would have loved to have had your code sooner.</p>
<p>I've also developed a routine using similar techniques for changing the computer name. I'll post it in the future so subscribe to this questions <a href="https://stackoverflow.com/feeds/question/209779" title="RSS Feed">RSS feed</a> if you want to be informed of the update. I may get it up later today or on Monday after a bit of cleanup.</p>
|
[
{
"answer_id": 209983,
"author": "balexandre",
"author_id": 28004,
"author_profile": "https://Stackoverflow.com/users/28004",
"pm_score": 7,
"selected": true,
"text": "using System;\nusing System.Management;\n\nnamespace WindowsFormsApplication_CS\n{\n class NetworkManagement\n {\n public void setIP(string ip_address, string subnet_mask)\n {\n ManagementClass objMC =\n new ManagementClass(\"Win32_NetworkAdapterConfiguration\");\n ManagementObjectCollection objMOC = objMC.GetInstances();\n\n foreach (ManagementObject objMO in objMOC)\n {\n if ((bool)objMO[\"IPEnabled\"])\n {\n ManagementBaseObject setIP;\n ManagementBaseObject newIP =\n objMO.GetMethodParameters(\"EnableStatic\");\n\n newIP[\"IPAddress\"] = new string[] { ip_address };\n newIP[\"SubnetMask\"] = new string[] { subnet_mask };\n\n setIP = objMO.InvokeMethod(\"EnableStatic\", newIP, null);\n }\n }\n }\n\n public void setGateway(string gateway)\n {\n ManagementClass objMC = new ManagementClass(\"Win32_NetworkAdapterConfiguration\");\n ManagementObjectCollection objMOC = objMC.GetInstances();\n\n foreach (ManagementObject objMO in objMOC)\n {\n if ((bool)objMO[\"IPEnabled\"])\n {\n ManagementBaseObject setGateway;\n ManagementBaseObject newGateway =\n objMO.GetMethodParameters(\"SetGateways\");\n\n newGateway[\"DefaultIPGateway\"] = new string[] { gateway };\n newGateway[\"GatewayCostMetric\"] = new int[] { 1 };\n\n setGateway = objMO.InvokeMethod(\"SetGateways\", newGateway, null);\n }\n }\n }\n\n public void setDNS(string NIC, string DNS)\n {\n ManagementClass objMC = new ManagementClass(\"Win32_NetworkAdapterConfiguration\");\n ManagementObjectCollection objMOC = objMC.GetInstances();\n\n foreach (ManagementObject objMO in objMOC)\n {\n if ((bool)objMO[\"IPEnabled\"])\n {\n // if you are using the System.Net.NetworkInformation.NetworkInterface\n // you'll need to change this line to\n // if (objMO[\"Caption\"].ToString().Contains(NIC))\n // and pass in the Description property instead of the name \n if (objMO[\"Caption\"].Equals(NIC))\n {\n ManagementBaseObject newDNS =\n objMO.GetMethodParameters(\"SetDNSServerSearchOrder\");\n newDNS[\"DNSServerSearchOrder\"] = DNS.Split(',');\n ManagementBaseObject setDNS =\n objMO.InvokeMethod(\"SetDNSServerSearchOrder\", newDNS, null);\n }\n }\n }\n }\n\n public void setWINS(string NIC, string priWINS, string secWINS)\n {\n ManagementClass objMC = new ManagementClass(\"Win32_NetworkAdapterConfiguration\");\n ManagementObjectCollection objMOC = objMC.GetInstances();\n\n foreach (ManagementObject objMO in objMOC)\n {\n if ((bool)objMO[\"IPEnabled\"])\n {\n if (objMO[\"Caption\"].Equals(NIC))\n {\n ManagementBaseObject setWINS;\n ManagementBaseObject wins =\n objMO.GetMethodParameters(\"SetWINSServer\");\n wins.SetPropertyValue(\"WINSPrimaryServer\", priWINS);\n wins.SetPropertyValue(\"WINSSecondaryServer\", secWINS);\n\n setWINS = objMO.InvokeMethod(\"SetWINSServer\", wins, null);\n }\n }\n }\n } \n }\n}\n"
},
{
"answer_id": 2514071,
"author": "LukeSkywalker",
"author_id": 301526,
"author_profile": "https://Stackoverflow.com/users/301526",
"pm_score": 3,
"selected": false,
"text": "using (WmiContext context = new WmiContext(@\"\\\\.\")) {\n\n context.ManagementScope.Options.Impersonation = ImpersonationLevel.Impersonate;\n context.Log = Console.Out;\n\n var dnss = from nic in context.Source<Win32_NetworkAdapterConfiguration>()\n where nic.IPEnabled\n select nic;\n\n var ips = from s in dnss.SelectMany(dns => dns.DNSServerSearchOrder)\n select IPAddress.Parse(s);\n} \n"
},
{
"answer_id": 7926134,
"author": "Marc",
"author_id": 105443,
"author_profile": "https://Stackoverflow.com/users/105443",
"pm_score": 5,
"selected": false,
"text": "/// <summary>\n/// Helper class to set networking configuration like IP address, DNS servers, etc.\n/// </summary>\npublic class NetworkConfigurator\n{\n /// <summary>\n /// Set's a new IP Address and it's Submask of the local machine\n /// </summary>\n /// <param name=\"ipAddress\">The IP Address</param>\n /// <param name=\"subnetMask\">The Submask IP Address</param>\n /// <param name=\"gateway\">The gateway.</param>\n /// <remarks>Requires a reference to the System.Management namespace</remarks>\n public void SetIP(string ipAddress, string subnetMask, string gateway)\n {\n using (var networkConfigMng = new ManagementClass(\"Win32_NetworkAdapterConfiguration\"))\n {\n using (var networkConfigs = networkConfigMng.GetInstances())\n {\n foreach (var managementObject in networkConfigs.Cast<ManagementObject>().Where(managementObject => (bool)managementObject[\"IPEnabled\"]))\n {\n using (var newIP = managementObject.GetMethodParameters(\"EnableStatic\"))\n {\n // Set new IP address and subnet if needed\n if ((!String.IsNullOrEmpty(ipAddress)) || (!String.IsNullOrEmpty(subnetMask)))\n {\n if (!String.IsNullOrEmpty(ipAddress))\n {\n newIP[\"IPAddress\"] = new[] { ipAddress };\n }\n\n if (!String.IsNullOrEmpty(subnetMask))\n {\n newIP[\"SubnetMask\"] = new[] { subnetMask };\n }\n\n managementObject.InvokeMethod(\"EnableStatic\", newIP, null);\n }\n\n // Set mew gateway if needed\n if (!String.IsNullOrEmpty(gateway))\n {\n using (var newGateway = managementObject.GetMethodParameters(\"SetGateways\"))\n {\n newGateway[\"DefaultIPGateway\"] = new[] { gateway };\n newGateway[\"GatewayCostMetric\"] = new[] { 1 };\n managementObject.InvokeMethod(\"SetGateways\", newGateway, null);\n }\n }\n }\n }\n }\n }\n }\n\n /// <summary>\n /// Set's the DNS Server of the local machine\n /// </summary>\n /// <param name=\"nic\">NIC address</param>\n /// <param name=\"dnsServers\">Comma seperated list of DNS server addresses</param>\n /// <remarks>Requires a reference to the System.Management namespace</remarks>\n public void SetNameservers(string nic, string dnsServers)\n {\n using (var networkConfigMng = new ManagementClass(\"Win32_NetworkAdapterConfiguration\"))\n {\n using (var networkConfigs = networkConfigMng.GetInstances())\n {\n foreach (var managementObject in networkConfigs.Cast<ManagementObject>().Where(objMO => (bool)objMO[\"IPEnabled\"] && objMO[\"Caption\"].Equals(nic)))\n {\n using (var newDNS = managementObject.GetMethodParameters(\"SetDNSServerSearchOrder\"))\n {\n newDNS[\"DNSServerSearchOrder\"] = dnsServers.Split(',');\n managementObject.InvokeMethod(\"SetDNSServerSearchOrder\", newDNS, null);\n }\n }\n }\n }\n }\n}\n"
},
{
"answer_id": 31483129,
"author": "usr",
"author_id": 122718,
"author_profile": "https://Stackoverflow.com/users/122718",
"pm_score": 1,
"selected": false,
"text": "public static class NetworkConfigurator\n{\n /// <summary>\n /// Set's a new IP Address and it's Submask of the local machine\n /// </summary>\n /// <param name=\"ipAddress\">The IP Address</param>\n /// <param name=\"subnetMask\">The Submask IP Address</param>\n /// <param name=\"gateway\">The gateway.</param>\n /// <param name=\"nicDescription\"></param>\n /// <remarks>Requires a reference to the System.Management namespace</remarks>\n public static void SetIP(string nicDescription, string[] ipAddresses, string subnetMask, string gateway)\n {\n using (var networkConfigMng = new ManagementClass(\"Win32_NetworkAdapterConfiguration\"))\n {\n using (var networkConfigs = networkConfigMng.GetInstances())\n {\n foreach (var managementObject in networkConfigs.Cast<ManagementObject>().Where(mo => (bool)mo[\"IPEnabled\"] && (string)mo[\"Description\"] == nicDescription))\n {\n using (var newIP = managementObject.GetMethodParameters(\"EnableStatic\"))\n {\n // Set new IP address and subnet if needed\n if (ipAddresses != null || !String.IsNullOrEmpty(subnetMask))\n {\n if (ipAddresses != null)\n {\n newIP[\"IPAddress\"] = ipAddresses;\n }\n\n if (!String.IsNullOrEmpty(subnetMask))\n {\n newIP[\"SubnetMask\"] = Array.ConvertAll(ipAddresses, _ => subnetMask);\n }\n\n managementObject.InvokeMethod(\"EnableStatic\", newIP, null);\n }\n\n // Set mew gateway if needed\n if (!String.IsNullOrEmpty(gateway))\n {\n using (var newGateway = managementObject.GetMethodParameters(\"SetGateways\"))\n {\n newGateway[\"DefaultIPGateway\"] = new[] { gateway };\n newGateway[\"GatewayCostMetric\"] = new[] { 1 };\n managementObject.InvokeMethod(\"SetGateways\", newGateway, null);\n }\n }\n }\n }\n }\n }\n }\n\n /// <summary>\n /// Set's the DNS Server of the local machine\n /// </summary>\n /// <param name=\"nic\">NIC address</param>\n /// <param name=\"dnsServers\">Comma seperated list of DNS server addresses</param>\n /// <remarks>Requires a reference to the System.Management namespace</remarks>\n public static void SetNameservers(string nicDescription, string[] dnsServers)\n {\n using (var networkConfigMng = new ManagementClass(\"Win32_NetworkAdapterConfiguration\"))\n {\n using (var networkConfigs = networkConfigMng.GetInstances())\n {\n foreach (var managementObject in networkConfigs.Cast<ManagementObject>().Where(mo => (bool)mo[\"IPEnabled\"] && (string)mo[\"Description\"] == nicDescription))\n {\n using (var newDNS = managementObject.GetMethodParameters(\"SetDNSServerSearchOrder\"))\n {\n newDNS[\"DNSServerSearchOrder\"] = dnsServers;\n managementObject.InvokeMethod(\"SetDNSServerSearchOrder\", newDNS, null);\n }\n }\n }\n }\n }\n}\n"
},
{
"answer_id": 35761109,
"author": "Sverrir Sigmundarson",
"author_id": 779521,
"author_profile": "https://Stackoverflow.com/users/779521",
"pm_score": 2,
"selected": false,
"text": " using System;\n using System.Management;\n\n namespace Utils\n {\n class NetworkManagement\n {\n /// <summary>\n /// Returns a list of all the network interface class names that are currently enabled in the system\n /// </summary>\n /// <returns>list of nic names</returns>\n public static string[] GetAllNicDescriptions()\n {\n List<string> nics = new List<string>();\n\n using (var networkConfigMng = new ManagementClass(\"Win32_NetworkAdapterConfiguration\"))\n {\n using (var networkConfigs = networkConfigMng.GetInstances())\n {\n foreach (var config in networkConfigs.Cast<ManagementObject>()\n .Where(mo => (bool)mo[\"IPEnabled\"])\n .Select(x=> new NetworkAdapterConfiguration(x)))\n {\n nics.Add(config.Description);\n }\n }\n }\n\n return nics.ToArray();\n }\n\n /// <summary>\n /// Set's the DNS Server of the local machine\n /// </summary>\n /// <param name=\"nicDescription\">The full description of the network interface class</param>\n /// <param name=\"dnsServers\">Comma seperated list of DNS server addresses</param>\n /// <remarks>Requires a reference to the System.Management namespace</remarks>\n public static bool SetNameservers(string nicDescription, string[] dnsServers, bool restart = false)\n {\n using (ManagementClass networkConfigMng = new ManagementClass(\"Win32_NetworkAdapterConfiguration\"))\n {\n using (ManagementObjectCollection networkConfigs = networkConfigMng.GetInstances())\n {\n foreach (ManagementObject mboDNS in networkConfigs.Cast<ManagementObject>().Where(mo => (bool)mo[\"IPEnabled\"] && (string)mo[\"Description\"] == nicDescription))\n {\n // NAC class was generated by opening a developer console and entering:\n // mgmtclassgen Win32_NetworkAdapterConfiguration -p NetworkAdapterConfiguration.cs\n // See: http://blog.opennetcf.com/2008/06/24/disableenable-network-connections-under-vista/\n\n using (NetworkAdapterConfiguration config = new NetworkAdapterConfiguration(mboDNS))\n {\n if (config.SetDNSServerSearchOrder(dnsServers) == 0)\n {\n RestartNetworkAdapter(nicDescription);\n }\n }\n }\n }\n }\n\n return false;\n }\n\n /// <summary>\n /// Restarts a given Network adapter\n /// </summary>\n /// <param name=\"nicDescription\">The full description of the network interface class</param>\n public static void RestartNetworkAdapter(string nicDescription)\n {\n using (ManagementClass networkConfigMng = new ManagementClass(\"Win32_NetworkAdapter\"))\n {\n using (ManagementObjectCollection networkConfigs = networkConfigMng.GetInstances())\n {\n foreach (ManagementObject mboDNS in networkConfigs.Cast<ManagementObject>().Where(mo=> (string)mo[\"Description\"] == nicDescription))\n {\n // NA class was generated by opening dev console and entering\n // mgmtclassgen Win32_NetworkAdapter -p NetworkAdapter.cs\n using (NetworkAdapter adapter = new NetworkAdapter(mboDNS))\n {\n adapter.Disable();\n adapter.Enable();\n Thread.Sleep(4000); // Wait a few secs until exiting, this will give the NIC enough time to re-connect\n return;\n }\n }\n }\n }\n }\n\n /// <summary>\n /// Get's the DNS Server of the local machine\n /// </summary>\n /// <param name=\"nicDescription\">The full description of the network interface class</param>\n public static string[] GetNameservers(string nicDescription)\n {\n using (var networkConfigMng = new ManagementClass(\"Win32_NetworkAdapterConfiguration\"))\n {\n using (var networkConfigs = networkConfigMng.GetInstances())\n {\n foreach (var config in networkConfigs.Cast<ManagementObject>()\n .Where(mo => (bool)mo[\"IPEnabled\"] && (string)mo[\"Description\"] == nicDescription)\n .Select( x => new NetworkAdapterConfiguration(x)))\n {\n return config.DNSServerSearchOrder;\n }\n }\n }\n\n return null;\n }\n\n /// <summary>\n /// Set's a new IP Address and it's Submask of the local machine\n /// </summary>\n /// <param name=\"nicDescription\">The full description of the network interface class</param>\n /// <param name=\"ipAddresses\">The IP Address</param>\n /// <param name=\"subnetMask\">The Submask IP Address</param>\n /// <param name=\"gateway\">The gateway.</param>\n /// <remarks>Requires a reference to the System.Management namespace</remarks>\n public static void SetIP(string nicDescription, string[] ipAddresses, string subnetMask, string gateway)\n {\n using (var networkConfigMng = new ManagementClass(\"Win32_NetworkAdapterConfiguration\"))\n {\n using (var networkConfigs = networkConfigMng.GetInstances())\n {\n foreach (var config in networkConfigs.Cast<ManagementObject>()\n .Where(mo => (bool)mo[\"IPEnabled\"] && (string)mo[\"Description\"] == nicDescription)\n .Select( x=> new NetworkAdapterConfiguration(x)))\n {\n // Set the new IP and subnet masks if needed\n config.EnableStatic(ipAddresses, Array.ConvertAll(ipAddresses, _ => subnetMask));\n\n // Set mew gateway if needed\n if (!String.IsNullOrEmpty(gateway))\n {\n config.SetGateways(new[] {gateway}, new ushort[] {1});\n }\n }\n }\n }\n }\n\n }\n }\n"
},
{
"answer_id": 52642434,
"author": "Vova",
"author_id": 6153759,
"author_profile": "https://Stackoverflow.com/users/6153759",
"pm_score": 1,
"selected": false,
"text": "static NetworkInterface GetNetworkInterface(string macAddress)\n{\n foreach(NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces())\n {\n if (macAddress == ni.GetPhysicalAddress().ToString())\n return ni;\n }\n return null;\n}\nstatic ManagementObject GetNetworkInterfaceManagementObject(string macAddress)\n{\n NetworkInterface ni = GetNetworkInterface(macAddress);\n if (ni == null)\n return null;\n ManagementClass managementClass = new ManagementClass(\"Win32_NetworkAdapterConfiguration\");\n ManagementObjectCollection moc = managementClass.GetInstances();\n foreach(ManagementObject mo in moc)\n {\n if (mo[\"settingID\"].ToString() == ni.Id)\n return mo;\n }\n return null;\n}\nstatic bool SetupNIC(string macAddress, string ip, string subnet, string gateway, string dns)\n{\n try\n {\n ManagementObject mo = GetNetworkInterfaceManagementObject(macAddress);\n\n //Set IP\n ManagementBaseObject mboIP = mo.GetMethodParameters(\"EnableStatic\");\n mboIP[\"IPAddress\"] = new string[] { ip };\n mboIP[\"SubnetMask\"] = new string[] { subnet };\n mo.InvokeMethod(\"EnableStatic\", mboIP, null);\n\n //Set Gateway\n ManagementBaseObject mboGateway = mo.GetMethodParameters(\"SetGateways\");\n mboGateway[\"DefaultIPGateway\"] = new string[] { gateway };\n mboGateway[\"GatewayCostMetric\"] = new int[] { 1 };\n mo.InvokeMethod(\"SetGateways\", mboGateway, null);\n\n //Set DNS\n ManagementBaseObject mboDNS = mo.GetMethodParameters(\"SetDNSServerSearchOrder\");\n mboDNS[\"DNSServerSearchOrder\"] = new string[] { dns };\n mo.InvokeMethod(\"SetDNSServerSearchOrder\", mboDNS, null);\n\n return true;\n }\n catch (Exception e)\n {\n return false;\n }\n}\n"
},
{
"answer_id": 52924042,
"author": "Apfelkuacha",
"author_id": 9758687,
"author_profile": "https://Stackoverflow.com/users/9758687",
"pm_score": 2,
"selected": false,
"text": "netsh netsh interface ip set address \"Local Area Connection\" static 192.168.0.10 255.255.255.0\n public bool SetIP(string networkInterfaceName, string ipAddress, string subnetMask, string gateway = null)\n{\n var networkInterface = NetworkInterface.GetAllNetworkInterfaces().FirstOrDefault(nw => nw.Name == networkInterfaceName);\n var ipProperties = networkInterface.GetIPProperties();\n var ipInfo = ipProperties.UnicastAddresses.FirstOrDefault(ip => ip.Address.AddressFamily == AddressFamily.InterNetwork);\n var currentIPaddress = ipInfo.Address.ToString();\n var currentSubnetMask = ipInfo.IPv4Mask.ToString();\n var isDHCPenabled = ipProperties.GetIPv4Properties().IsDhcpEnabled;\n\n if (!isDHCPenabled && currentIPaddress == ipAddress && currentSubnetMask == subnetMask)\n return true; // no change necessary\n\n var process = new Process\n {\n StartInfo = new ProcessStartInfo(\"netsh\", $\"interface ip set address \\\"{networkInterfaceName}\\\" static {ipAddress} {subnetMask}\" + (string.IsNullOrWhiteSpace(gateway) ? \"\" : $\"{gateway} 1\")) { Verb = \"runas\" }\n };\n process.Start();\n var successful = process.ExitCode == 0;\n process.Dispose();\n return successful;\n}\n\npublic bool SetDHCP(string networkInterfaceName)\n{\n var networkInterface = NetworkInterface.GetAllNetworkInterfaces().FirstOrDefault(nw => nw.Name == networkInterfaceName);\n var ipProperties = networkInterface.GetIPProperties();\n var isDHCPenabled = ipProperties.GetIPv4Properties().IsDhcpEnabled;\n\n if (isDHCPenabled)\n return true; // no change necessary\n\n var process = new Process\n {\n StartInfo = new ProcessStartInfo(\"netsh\", $\"interface ip set address \\\"{networkInterfaceName}\\\" dhcp\") { Verb = \"runas\" }\n };\n process.Start();\n var successful = process.ExitCode == 0;\n process.Dispose();\n return successful;\n}\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209779",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10119/"
] |
209,787
|
<p>In the following one to many</p>
<pre><code>CREATE TABLE source(id int, name varchar(10), PRIMARY KEY(id));
CREATE TABLE params(id int, source int, value int);
</code></pre>
<p>where params.source is a foreign key to source.id</p>
<pre><code>INSERT INTO source values(1, 'yes');
INSERT INTO source values(2, 'no');
INSERT INTO params VALUES(1,1,1);
INSERT INTO params VALUES(2,1,2);
INSERT INTO params VALUES(3,1,3);
INSERT INTO params VALUES(4,2,1);
INSERT INTO params VALUES(5,2,3);
INSERT INTO params VALUES(6,2,4);
</code></pre>
<p>If i have a list of param values (say [1,2,3]), how do I find all the sources that have ALL of the values in the list (source 1, "yes") in SQL?</p>
<p>Thanks</p>
|
[
{
"answer_id": 209819,
"author": "Lasse V. Karlsen",
"author_id": 267,
"author_profile": "https://Stackoverflow.com/users/267",
"pm_score": 4,
"selected": true,
"text": "SELECT\n *\nFROM\n source\nWHERE\n (\n SELECT COUNT(DISTINCT value)\n FROM params\n WHERE params.source = source.id\n AND params.value IN (1, 2, 3)\n ) = 3\n SELECT\n source.*\nFROM\n source\n INNER JOIN params ON params.source = source.id\nWHERE\n params.value IN (1, 2, 3)\nGROUP BY\n source.id,\n source.name\nHAVING\n COUNT(DISTINCT params.value) = 3\n"
},
{
"answer_id": 209823,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "https://Stackoverflow.com/users/20860",
"pm_score": 4,
"selected": false,
"text": "SELECT s.*\nFROM source AS s\n JOIN params AS p ON (p.source = s.id)\nWHERE p.value IN (1,2,3)\nGROUP BY s.id\nHAVING COUNT(DISTINCT p.value) = 3;\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209787",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
209,789
|
<p>Is there a way to start an instance of eclipse, passing it some sort of parameter telling it to use a specific workspace?</p>
<p>The problem I'm trying to solve is that I have a workspace for work projects and one for personal projects. I'd like to be able to tie these to workspaces to separate shortcuts that I could launch independently.</p>
|
[
{
"answer_id": 209794,
"author": "Matt H",
"author_id": 18049,
"author_profile": "https://Stackoverflow.com/users/18049",
"pm_score": 9,
"selected": true,
"text": "-data your_workspace_location\n -data c:\\users\\robert\\myworkspace\n -data ../workspace\n"
},
{
"answer_id": 10507415,
"author": "santaranger",
"author_id": 1383222,
"author_profile": "https://Stackoverflow.com/users/1383222",
"pm_score": 3,
"selected": false,
"text": "-data ../workspace\n"
},
{
"answer_id": 23220470,
"author": "user3560541",
"author_id": 3560541,
"author_profile": "https://Stackoverflow.com/users/3560541",
"pm_score": 0,
"selected": false,
"text": "\"C:\\MyEclipse Blue Edition\\MyEclipse Blue Edition 10\\myeclipse-blue.exe\" -showlocation -data \"C:\\EclipseWork\\WorkSpace\"\n"
},
{
"answer_id": 30487656,
"author": "DGolberg",
"author_id": 1848286,
"author_profile": "https://Stackoverflow.com/users/1848286",
"pm_score": 2,
"selected": false,
"text": "C:\\Eclipse\\eclipse.exe -data E:\\Eclipse Projects2 C:\\Eclipse\\eclipse.exe -data \"E:\\Eclipse Projects2\""
},
{
"answer_id": 46182778,
"author": "Mrinal",
"author_id": 2437050,
"author_profile": "https://Stackoverflow.com/users/2437050",
"pm_score": 0,
"selected": false,
"text": "osgi.instance.area -Dosgi.instance.area=../workspace\n -Xms, -Xmx"
},
{
"answer_id": 58304760,
"author": "Pramod H G",
"author_id": 7895005,
"author_profile": "https://Stackoverflow.com/users/7895005",
"pm_score": 1,
"selected": false,
"text": "E\\STS.exe -data \"WORKSPACE_LOCATION\"\n cd ECLIPSE_LOCATION \nstart STS.exe -data \"WORKSPACE_LOCATION\"\n cd /D D:\\IDE\\sts-bundle\\sts-3.7.0.RELEASE \nstart STS.exe -data \"D:\\My Workspace\\workspace1\"\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209789",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5291/"
] |
209,790
|
<p>I would like to have the same editor available on all of the platforms I frequent.</p>
<p>Emacs and Vi are not desired solutions.</p>
|
[
{
"answer_id": 209794,
"author": "Matt H",
"author_id": 18049,
"author_profile": "https://Stackoverflow.com/users/18049",
"pm_score": 9,
"selected": true,
"text": "-data your_workspace_location\n -data c:\\users\\robert\\myworkspace\n -data ../workspace\n"
},
{
"answer_id": 10507415,
"author": "santaranger",
"author_id": 1383222,
"author_profile": "https://Stackoverflow.com/users/1383222",
"pm_score": 3,
"selected": false,
"text": "-data ../workspace\n"
},
{
"answer_id": 23220470,
"author": "user3560541",
"author_id": 3560541,
"author_profile": "https://Stackoverflow.com/users/3560541",
"pm_score": 0,
"selected": false,
"text": "\"C:\\MyEclipse Blue Edition\\MyEclipse Blue Edition 10\\myeclipse-blue.exe\" -showlocation -data \"C:\\EclipseWork\\WorkSpace\"\n"
},
{
"answer_id": 30487656,
"author": "DGolberg",
"author_id": 1848286,
"author_profile": "https://Stackoverflow.com/users/1848286",
"pm_score": 2,
"selected": false,
"text": "C:\\Eclipse\\eclipse.exe -data E:\\Eclipse Projects2 C:\\Eclipse\\eclipse.exe -data \"E:\\Eclipse Projects2\""
},
{
"answer_id": 46182778,
"author": "Mrinal",
"author_id": 2437050,
"author_profile": "https://Stackoverflow.com/users/2437050",
"pm_score": 0,
"selected": false,
"text": "osgi.instance.area -Dosgi.instance.area=../workspace\n -Xms, -Xmx"
},
{
"answer_id": 58304760,
"author": "Pramod H G",
"author_id": 7895005,
"author_profile": "https://Stackoverflow.com/users/7895005",
"pm_score": 1,
"selected": false,
"text": "E\\STS.exe -data \"WORKSPACE_LOCATION\"\n cd ECLIPSE_LOCATION \nstart STS.exe -data \"WORKSPACE_LOCATION\"\n cd /D D:\\IDE\\sts-bundle\\sts-3.7.0.RELEASE \nstart STS.exe -data \"D:\\My Workspace\\workspace1\"\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209790",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7734/"
] |
209,793
|
<p>Kind of a random question...</p>
<p>What I'm looking for is a way to express a cast operation which uses a defined operator of the class instance I'm casting from, and generates a compile-time error if there is not a defined cast operator for the type. So, for example, what I'm looking for is something like:</p>
<pre><code>template< typename RESULT_TYPE, typename INPUT_TYPE >
RESULT_TYPE operator_cast( const INPUT_TYPE& tValue )
{
return tValue.operator RESULT_TYPE();
}
// Should work...
CString sString;
LPCTSTR pcszString = operator_cast< LPCTSTR >( sString );
// Should fail...
int iValue = 42;
DWORD dwValue = operator_cast< DWORD >( iValue );
</code></pre>
<p>Interesting side-note: The above code crashes the VS2005 C++ compiler, and doesn't compile correctly in the VS2008 C++ compiler due to what I'm guessing is a compiler bug, but hopefully demonstrates the idea.</p>
<p>Anybody know of any way to achieve this effect?</p>
<p>Edit: More rationale, to explain why you might use this. Say you have a wrapper class which is supposed to encapsulate or abstract a type, and you're casting it to the encapsulated type. You could use static_cast<>, but that might work when you wanted it to fail (ie: the compiler chooses an operator which is allowed to convert to the type you asked for, when you wanted a failure because that operator is not present).</p>
<p>Admittedly it's an uncommon case, but it's annoying that I can't express exactly what I want the compiler to do in an encapsulated function... hence the question here.</p>
|
[
{
"answer_id": 210254,
"author": "Evan Teran",
"author_id": 13430,
"author_profile": "https://Stackoverflow.com/users/13430",
"pm_score": 0,
"selected": false,
"text": "/* general template */\ntemplate<typename T1, typename T2> T1 operator_cast(const T2 &x);\n\n/* do this for each valid cast */\ntemplate<> LPCTSTR operator_cast(const CString &x) { return (LPCTSTR)x; }\n"
},
{
"answer_id": 210339,
"author": "user23167",
"author_id": 23167,
"author_profile": "https://Stackoverflow.com/users/23167",
"pm_score": 1,
"selected": false,
"text": "#include <string>\n\n// Class to trigger compiler warning \nclass NO_OPERATOR_CONVERSION_AVAILABLE\n{\nprivate:\n NO_OPERATOR_CONVERSION_AVAILABLE(){};\n};\n\n// Default template definition to cause compiler error\ntemplate<typename T1, typename T2> T1 operator_cast(const T2&)\n{\n NO_OPERATOR_CONVERSION_AVAILABLE a;\n return T1();\n}\n\n// Template specialisation\ntemplate<> std::string operator_cast(const std::string &x)\n{\n return x;\n}\n"
},
{
"answer_id": 223541,
"author": "Motti",
"author_id": 3848,
"author_profile": "https://Stackoverflow.com/users/3848",
"pm_score": 3,
"selected": true,
"text": "void* bool template< typename Res, typename T>\nRes operator_cast( const T& t )\n{\n typedef Res (T::*cast_op_t)() const;\n cast_op_t cast_op = &T::operator Res;\n return (t.*cast_op)();\n}\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209793",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26240/"
] |
209,795
|
<p>All of this is pertaining to WebHttp binding, hosted in a custom Service Host (IIS is not an option at this time).</p>
<p>I've implemented a custom UserNamePasswordValidator, and a custom IAuthorizationPolicy. When I configure the endpoint's binding to use Basic authentication, everything works just as I'd like (custom principal, custom roles, etc..). </p>
<p>I'd like to add the ability for anonymous HTTP access as well, and have my custom implementations put the Anonymous user in some default roles, etc.. (if no Authenticate header is sent).</p>
<p>What happens now is that anonymous users are given a 401 before any of my custom code is hit. If I turn off the HTTP Basic authentication requirement, then the Authenticate header is ignored altogether.</p>
<p>How do I configure, <strong>or inject an Authenticate header</strong>, to do this both ways (without creating 2 separate endpoints)?</p>
|
[
{
"answer_id": 234376,
"author": "Ronald Wildenberg",
"author_id": 23562,
"author_profile": "https://Stackoverflow.com/users/23562",
"pm_score": 2,
"selected": true,
"text": "System.Net.HttpListener System.ServiceModel.Channels.SharedHttpTransportManager.OnOpen HandleAuthentication"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209795",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18941/"
] |
209,804
|
<p>What reason is there for C# or java having lambdas? Neither language is based around them, it appears to be another coding method to do the same thing that C# already did.<br>
I'm not being confrontational, if there is a reason I would like to know the reason why. For the purpose of full disclosure I am a Java programmer with a C++ background with no lisp experience, I may just be missing the point. </p>
|
[
{
"answer_id": 209829,
"author": "Daniel Spiewak",
"author_id": 9815,
"author_profile": "https://Stackoverflow.com/users/9815",
"pm_score": 6,
"selected": true,
"text": "JButton button = new JButton(\"Push me!\");\nbutton.addActionListener(new ActionListener() {\n public void actionPerformed(ActionEvent e) {\n System.out.println(\"Pressed!\");\n }\n});\n val button = new JButton(\"Push me!\")\nbutton.addActionListener { e =>\n println(\"Pressed!\")\n}\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209804",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13491/"
] |
209,806
|
<p>I have an instance of a general purpose class that will be executed both under
ASP.NET and a stand alone program. This code is sensative to the process where it
is being run - that is, there are certin methods that should not called if
running under ASP.NET. How do you determine if the code is executing in an ASP.NET
process?</p>
<p>The solution I am currently using is answered below.</p>
<hr>
<p>I wish someone would add a comment as to why this question has gotten downvoted and/or propose a better way to ask it! I can only assume at least some folks have looked at the question and said "what an idiot, ASP.NET code is .NET code".</p>
|
[
{
"answer_id": 209807,
"author": "jr.",
"author_id": 2415,
"author_profile": "https://Stackoverflow.com/users/2415",
"pm_score": -1,
"selected": false,
"text": "public class SomeClass {\n\n public bool RunningUnderAspNet { get; private set; }\n\n\n public SomeClass()\n //\n // constructor\n //\n {\n try {\n RunningUnderAspNet = null != HttpContext.Current;\n }\n catch {\n RunningUnderAspNet = false;\n }\n }\n}\n"
},
{
"answer_id": 209856,
"author": "StingyJack",
"author_id": 16391,
"author_profile": "https://Stackoverflow.com/users/16391",
"pm_score": -1,
"selected": false,
"text": "If HttpContext Is Nothing OrElse HttpContext.Current Is Nothing Then\n 'Not hosted by web server'\nEnd If\n"
},
{
"answer_id": 209908,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 2,
"selected": false,
"text": "public interface IDoFunctions\n{\n void DoSomething();\n}\n\npublic static class FunctionFactory\n{\n public static IDoFunctions GetFunctionInterface()\n {\n if (HttpContext.Current != null)\n {\n return new WebFunctionInterface();\n }\n else\n {\n return new NonWebFunctionInterface();\n }\n }\n}\n\npublic IDoFunctions WebFunctionInterface\n{\n public void DoSomething()\n {\n ... do something the web way ...\n }\n}\n\npublic IDoFunctions NonWebFunctionInterface\n{\n public void DoSomething()\n {\n ... do something the non-web way ...\n }\n}\n"
},
{
"answer_id": 28993766,
"author": "ghigad",
"author_id": 2856659,
"author_profile": "https://Stackoverflow.com/users/2856659",
"pm_score": 2,
"selected": false,
"text": "using System.Web.Hosting;\n\n// ...\n\nif (HostingEnvironment.IsHosted)\n{\n // You are in ASP.NET\n}\nelse\n{\n // You are in a standalone application\n}\n"
},
{
"answer_id": 41546230,
"author": "akomarov",
"author_id": 7394085,
"author_profile": "https://Stackoverflow.com/users/7394085",
"pm_score": 1,
"selected": false,
"text": "using System.Diagnostics; \n\nif (Process.GetCurrentProcess().ProcessName == \"w3wp\")\n //ASP.NET\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209806",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2415/"
] |
209,812
|
<p>I'm using NetBeans, trying to change the familiar Java coffee cup icon to a png file that I have saved in a resources directory in the jar file. I've found many different web pages that claim they have a solution, but so far none of them work.</p>
<p>Here's what I have at the moment (leaving out the try-catch block):</p>
<pre><code>URL url = new URL("com/xyz/resources/camera.png");
Toolkit kit = Toolkit.getDefaultToolkit();
Image img = kit.createImage(url);
getFrame().setIconImage(img);
</code></pre>
<p>The class that contains this code is in the <strong>com.xyz</strong> package, if that makes any difference. That class also extends JFrame. This code is throwing a MalformedUrlException on the first line.</p>
<p>Anyone have a solution that works?</p>
|
[
{
"answer_id": 209824,
"author": "JeeBee",
"author_id": 17832,
"author_profile": "https://Stackoverflow.com/users/17832",
"pm_score": 7,
"selected": true,
"text": "java.net.URL url = ClassLoader.getSystemResource(\"com/xyz/resources/camera.png\");\n"
},
{
"answer_id": 210197,
"author": "John Gardner",
"author_id": 13687,
"author_profile": "https://Stackoverflow.com/users/13687",
"pm_score": 2,
"selected": false,
"text": "com.xyz.SomeClassInThisPackage.class.getResource( \"resources/camera.png\" );\n"
},
{
"answer_id": 13041618,
"author": "user1456935",
"author_id": 1456935,
"author_profile": "https://Stackoverflow.com/users/1456935",
"pm_score": 2,
"selected": false,
"text": " /** Creates new form Java Program1*/\n public Java Program1() \n\n\n Image im = null;\n try {\n im = ImageIO.read(getClass().getResource(\"/image location\"));\n } catch (IOException ex) {\n Logger.getLogger(chat.class.getName()).log(Level.SEVERE, null, ex);\n }\n setIconImage(im);\n"
},
{
"answer_id": 14355281,
"author": "Ayoub Aneddame",
"author_id": 1983129,
"author_profile": "https://Stackoverflow.com/users/1983129",
"pm_score": 4,
"selected": false,
"text": "JFrame iconImage Form.SetIconImage() Toolkit.getDefaultToolkit().getImage(name_of_your_JFrame.class.getResource(\"image.png\"))\n import java.awt.Toolkit;\n"
},
{
"answer_id": 18927847,
"author": "user2601995",
"author_id": 2601995,
"author_profile": "https://Stackoverflow.com/users/2601995",
"pm_score": 2,
"selected": false,
"text": "javax.swing.JFrame setIconImage this.setIconImage(new ImageIcon(getClass().getResource(\"/resource/icon.png\")).getImage());\n"
},
{
"answer_id": 19469704,
"author": "user2895893",
"author_id": 2895893,
"author_profile": "https://Stackoverflow.com/users/2895893",
"pm_score": 2,
"selected": false,
"text": "initcomponents();\n\nsetIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource(\"Your image address\")));\n"
},
{
"answer_id": 26055825,
"author": "Rrezart A. Prebreza",
"author_id": 4025602,
"author_profile": "https://Stackoverflow.com/users/4025602",
"pm_score": -1,
"selected": false,
"text": "URL imageURL = this.getClass().getClassLoader().getResource(\"Gui/icon/report-go-icon.png\");\nImageIcon iChing = new ImageIcon(\"C:\\\\Users\\\\RrezartP\\\\Documents\\\\NetBeansProjects\\\\Inventari\\\\src\\\\Gui\\\\icon\\\\report-go-icon.png\"); \nbtnReport.setIcon(iChing); \nSystem.out.println(imageURL);\n"
},
{
"answer_id": 38547712,
"author": "ron190",
"author_id": 2073804,
"author_profile": "https://Stackoverflow.com/users/2073804",
"pm_score": 2,
"selected": false,
"text": "public static final URL ICON16 = HelperUi.class.getResource(\"/com/jsql/view/swing/resources/images/software/bug16.png\");\npublic static final URL ICON32 = HelperUi.class.getResource(\"/com/jsql/view/swing/resources/images/software/bug32.png\");\npublic static final URL ICON96 = HelperUi.class.getResource(\"/com/jsql/view/swing/resources/images/software/bug96.png\");\n\nList<Image> images = new ArrayList<>();\ntry {\n images.add(ImageIO.read(HelperUi.ICON96));\n images.add(ImageIO.read(HelperUi.ICON32));\n images.add(ImageIO.read(HelperUi.ICON16));\n} catch (IOException e) {\n LOGGER.error(e, e);\n}\n\n// Define a small and large app icon\nthis.setIconImages(images);\n"
},
{
"answer_id": 46866648,
"author": "Alex S",
"author_id": 6360179,
"author_profile": "https://Stackoverflow.com/users/6360179",
"pm_score": 0,
"selected": false,
"text": "try{ \n setIconImage(ImageIO.read(new File(\"./images/icon.png\"))); \n }\ncatch (Exception ex){\n //do something\n }\n"
},
{
"answer_id": 54374846,
"author": "Spicy strike",
"author_id": 10970074,
"author_profile": "https://Stackoverflow.com/users/10970074",
"pm_score": 1,
"selected": false,
"text": "` ImageIcon icon = new ImageIcon(\".//Ressources//User_50.png\");\n this.setIconImage(icon.getImage());`\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209812",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1288/"
] |
209,820
|
<p>I want to be able to introduce new 'tag lines' into a database that are shown 'randomly' to users. (These tag lines are shown as an introduction as animated text.)</p>
<p>Based upon the number of sales that result from those taglines I'd like the good ones to trickle to the top, but still show the others less frequently.</p>
<p>I could come up with a basic algorithm quite easily but I want something thats a little more 'statistically accurate'.</p>
<p>I dont really know where to start. Its been a while since I've done anything more than basic statistics. My model would need to be sensitive to tolerances, but obviously it doesnt need to be worthy of a PHD.</p>
<p><strong>Edit:</strong> I am currently tracking a 'conversion rate' - i.e. hits per order. This value would probably be best calculated as a cumulative 'all time' convertsion rate to be fed into the algorithm.</p>
|
[
{
"answer_id": 212573,
"author": "Tnilsson",
"author_id": 4165,
"author_profile": "https://Stackoverflow.com/users/4165",
"pm_score": 1,
"selected": false,
"text": "START:\nx = random(1, 3); \nif x = 3 goto NEW else goto NORMAL\n\nNEW:\nTagVec = Taglines.filterYounger(5 days); // I'm taking a LOT of liberties with the pseudo code,,,\nx = random(1, TagVec.Length);\nreturn tagVec[x-1]; // 0 indexed vectors even in made up language,\n\n\nNORMAL:\n// Similar to EBGREEN above\nsum = 0;\nForEach(TagLine in TagLines) {\n sum += TagLine.noOfPurhcases;\n}\nx = random(1, sum);\nForEach(TagLine in TagLines) {\n x -= TagLine.noOfPurchase;\n if ( x > 0) return TagLine; // Find the TagLine that represent our random number\n}\n"
},
{
"answer_id": 217488,
"author": "user5084",
"author_id": 5084,
"author_profile": "https://Stackoverflow.com/users/5084",
"pm_score": 0,
"selected": false,
"text": "/*\n * an example set of taglines\n * hits are sales\n * views are times its been shown\n */\nvar taglines = [\n {\"tag\":\"tagline 1\",\"hits\":1,\"views\":234},\n {\"tag\":\"tagline 2\",\"hits\":5,\"views\":566},\n {\"tag\":\"tagline 3\",\"hits\":3,\"views\":421},\n {\"tag\":\"tagline 4\",\"hits\":1,\"views\":120}, \n {\"tag\":\"tagline 5\",\"hits\":7,\"views\":200}\n];\n\n/*set up our stat model for the tags*/\nvar TagModel = function(set){ \n var hits, views, sumOfDiff, sumOfSqDiff; \n hits = views = sumOfDiff = sumOfSqDiff = 0;\n /*find average*/\n for (n in set){\n hits += set[n].hits;\n views += set[n].views; \n }\n this.avg = hits/views;\n /*find standard deviation and variance*/\n for (n in set){\n var diff =((set[n].hits/set[n].views)-this.avg);\n sumOfDiff += diff;\n sumOfSqDiff += diff*diff; \n }\n this.variance = sumOfDiff;\n this.std_dev = Math.sqrt(sumOfSqDiff/set.length);\n /*return tag to use fChooser determines likelyhood of tag*/\n this.getTag = function(fChooser){\n var m = this;\n set.sort(function(a,b){\n return fChooser((a.hits/a.views),(b.hits/b.views), m);\n });\n return set[0];\n };\n};\n\nvar config = {\n\n \"uniformDistribution\":function(a,b,model){\n return Math.random()*b-Math.random()*a;\n },\n \"normalDistribution\":function(a,b,model){\n var a1 = createMemberInNormalDistribution(model.avg,model.std_dev)* a;\n var b1 = createMemberInNormalDistribution(model.avg,model.std_dev)* b;\n return b1-a1;\n },\n //say weight = 10^n... higher n is the more even the distribution will be.\n \"weight\": .5,\n \"weightedDistribution\":function(a,b,model){\n var a1 = createMemberInNormalDistribution(model.avg,model.std_dev*config.weight)* a;\n var b1 = createMemberInNormalDistribution(model.avg,model.std_dev*config.weight)* b;\n return b1-a1;\n }\n}\n\nvar model = new TagModel(taglines);\n\n//to use\nmodel.getTag(config.uniformDistribution).tag;\n//running 10000 times: ({'tagline 4':836, 'tagline 5':7608, 'tagline 1':100, 'tagline 2':924, 'tagline 3':532})\n\nmodel.getTag(config.normalDistribution).tag;\n//running 10000 times: ({'tagline 4':1775, 'tagline 5':3471, 'tagline 1':1273, 'tagline 2':1857, 'tagline 3':1624})\n\nmodel.getTag(config.weightedDistribution).tag;\n//running 10000 times: ({'tagline 4':1514, 'tagline 5':5045, 'tagline 1':577, 'tagline 2':1627, 'tagline 3':1237})\n\nconfig.weight = 2;\nmodel.getTag(config.weightedDistribution).tag;\n//running 10000 times: {'tagline 4':1941, 'tagline 5':2715, 'tagline 1':1559, 'tagline 2':1957, 'tagline 3':1828})\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209820",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24727/"
] |
209,840
|
<p>I want to combine these:</p>
<pre class="lang-py prettyprint-override"><code>keys = ['name', 'age', 'food']
values = ['Monty', 42, 'spam']
</code></pre>
<p>Into a single dictionary:</p>
<pre class="lang-py prettyprint-override"><code>{'name': 'Monty', 'age': 42, 'food': 'spam'}
</code></pre>
|
[
{
"answer_id": 209854,
"author": "Dan Lenski",
"author_id": 20789,
"author_profile": "https://Stackoverflow.com/users/20789",
"pm_score": 12,
"selected": true,
"text": "keys = ['a', 'b', 'c']\nvalues = [1, 2, 3]\ndictionary = dict(zip(keys, values))\nprint(dictionary) # {'a': 1, 'b': 2, 'c': 3}\n dict zip"
},
{
"answer_id": 209855,
"author": "iny",
"author_id": 27067,
"author_profile": "https://Stackoverflow.com/users/27067",
"pm_score": 5,
"selected": false,
"text": "keys = ('name', 'age', 'food')\nvalues = ('Monty', 42, 'spam')\nout = dict(zip(keys, values))\n {'food': 'spam', 'age': 42, 'name': 'Monty'}\n"
},
{
"answer_id": 209880,
"author": "Mike Davis",
"author_id": 28471,
"author_profile": "https://Stackoverflow.com/users/28471",
"pm_score": 7,
"selected": false,
"text": ">>> import itertools\n>>> keys = ('name', 'age', 'food')\n>>> values = ('Monty', 42, 'spam')\n>>> adict = dict(itertools.izip(keys,values))\n>>> adict\n{'food': 'spam', 'age': 42, 'name': 'Monty'}\n zip"
},
{
"answer_id": 210234,
"author": "jfs",
"author_id": 4279,
"author_profile": "https://Stackoverflow.com/users/4279",
"pm_score": 4,
"selected": false,
"text": ">>> adict = dict((str(k), v) for k, v in zip(['a', 1, 'b'], [2, 'c', 3])) \n"
},
{
"answer_id": 10971932,
"author": "Brendan Berg",
"author_id": 39053,
"author_profile": "https://Stackoverflow.com/users/39053",
"pm_score": 5,
"selected": false,
"text": ">>> keys = ('name', 'age', 'food')\n>>> values = ('Monty', 42, 'spam')\n>>> {k: v for k, v in zip(keys, values)}\n{'food': 'spam', 'age': 42, 'name': 'Monty'}\n"
},
{
"answer_id": 15709950,
"author": "exploitprotocol",
"author_id": 2225469,
"author_profile": "https://Stackoverflow.com/users/2225469",
"pm_score": 3,
"selected": false,
"text": "zip List1 = ['This', 'is', 'a', 'list']\nList2 = ['Put', 'this', 'into', 'dictionary']\n d = {List1[n]: List2[n] for n in range(len(List1))}\n"
},
{
"answer_id": 16750190,
"author": "kiriloff",
"author_id": 1141493,
"author_profile": "https://Stackoverflow.com/users/1141493",
"pm_score": 4,
"selected": false,
"text": "keys = ('name', 'age', 'food')\nvalues = ('Monty', 42, 'spam')\n\ndic = {k:v for k,v in zip(keys, values)}\n\nprint(dic)\n >>> print {i : chr(65+i) for i in range(4)}\n {0 : 'A', 1 : 'B', 2 : 'C', 3 : 'D'}\n"
},
{
"answer_id": 33728822,
"author": "Polla A. Fattah",
"author_id": 235449,
"author_profile": "https://Stackoverflow.com/users/235449",
"pm_score": 4,
"selected": false,
"text": "keys = ('name', 'age', 'food')\nvalues = ('Monty', 42, 'spam') \ndict = {keys[i]: values[i] for i in range(len(keys))}\n"
},
{
"answer_id": 33737067,
"author": "Russia Must Remove Putin",
"author_id": 541136,
"author_profile": "https://Stackoverflow.com/users/541136",
"pm_score": 8,
"selected": false,
"text": "keys = ('name', 'age', 'food')\nvalues = ('Monty', 42, 'spam')\n dict = {'name' : 'Monty', 'age' : 42, 'food' : 'spam'}\n dict zip new_dict = dict(zip(keys, values))\n dict(zip(keys, values)) dict zip new_dict = {k: v for k, v in zip(keys, values)}\n zip izip from itertools import izip as zip\n new_dict = {k: v for k, v in zip(keys, values)}\n izip itertools zip izip from itertools import izip\nnew_dict = dict(izip(keys, values))\n >>> new_dict\n{'age': 42, 'name': 'Monty', 'food': 'spam'}\n dict \n>>> help(dict)\n\nclass dict(object)\n | dict() -> new empty dictionary\n | dict(mapping) -> new dictionary initialized from a mapping object's\n | (key, value) pairs\n | dict(iterable) -> new dictionary initialized as if via:\n | d = {}\n | for k, v in iterable:\n | d[k] = v\n | dict(**kwargs) -> new dictionary initialized with the name=value pairs\n | in the keyword argument list. For example: dict(one=1, two=2)\n\n >>> zip(keys, values)\n[('name', 'Monty'), ('age', 42), ('food', 'spam')]\n >>> list(zip(keys, values))\n[('name', 'Monty'), ('age', 42), ('food', 'spam')]\n zip >>> zip(keys, values)\n<zip object at 0x7f0e2ad029c8>\n zip generator_expression = ((k, v) for k, v in zip(keys, values))\ndict(generator_expression)\n dict((k, v) for k, v in zip(keys, values))\n dict([(k, v) for k, v in zip(keys, values)])\n >>> min(timeit.repeat(lambda: dict(zip(keys, values))))\n0.6695233230129816\n>>> min(timeit.repeat(lambda: {k: v for k, v in zip(keys, values)}))\n0.6941362579818815\n>>> min(timeit.repeat(lambda: {keys[i]: values[i] for i in range(len(keys))}))\n0.8782548159942962\n>>> \n>>> min(timeit.repeat(lambda: dict([(k, v) for k, v in zip(keys, values)])))\n1.077607496001292\n>>> min(timeit.repeat(lambda: dict((k, v) for k, v in zip(keys, values))))\n1.1840861019445583\n dict(zip(keys, values)) min mean max min mean max dict dict(zip(... mean max import numpy\nimport timeit\nl1 = list(numpy.random.random(100))\nl2 = list(numpy.random.random(100))\n dict(zip(... >>> min(timeit.repeat(lambda: {k: v for k, v in zip(l1, l2)}))\n9.698965263989521\n>>> min(timeit.repeat(lambda: dict(zip(l1, l2))))\n7.9965161079890095\n"
},
{
"answer_id": 44149939,
"author": "xiyurui",
"author_id": 4318842,
"author_profile": "https://Stackoverflow.com/users/4318842",
"pm_score": -1,
"selected": false,
"text": "l1 = [1,2,3,4,5]\nl2 = ['a','b','c','d','e']\nd1 = {}\nfor l1_ in l1:\n for l2_ in l2:\n d1[l1_] = l2_\n l2.remove(l2_)\n break \n\nprint (d1)\n\n\n{1: 'd', 2: 'b', 3: 'e', 4: 'a', 5: 'c'}\n"
},
{
"answer_id": 47331117,
"author": "Akash Nayak",
"author_id": 8818872,
"author_profile": "https://Stackoverflow.com/users/8818872",
"pm_score": 2,
"selected": false,
"text": "dict(zip(['name', 'age', 'food'], ['Monty', 42, 'spam']))\n"
},
{
"answer_id": 49890306,
"author": "AbstProcDo",
"author_id": 7301792,
"author_profile": "https://Stackoverflow.com/users/7301792",
"pm_score": 2,
"selected": false,
"text": "In [92]: keys = ('name', 'age', 'food')\n...: values = ('Monty', 42, 'spam')\n...: \n\nIn [93]: dt = dict(zip(keys, values))\nIn [94]: dt\nOut[94]: {'age': 42, 'food': 'spam', 'name': 'Monty'}\n lst = [('name', 'Monty'), ('age', 42), ('food', 'spam')]\n keys, values = zip(*lst)\n In [101]: keys\n Out[101]: ('name', 'age', 'food')\n In [102]: values\n Out[102]: ('Monty', 42, 'spam')\n"
},
{
"answer_id": 54786370,
"author": "Cyd",
"author_id": 4805124,
"author_profile": "https://Stackoverflow.com/users/4805124",
"pm_score": 2,
"selected": false,
"text": "list1 = [\"Name\", \"Surname\", \"Age\"]\nlist2 = [[\"Cyd\", \"JEDD\", \"JESS\"], [\"DEY\", \"AUDIJE\", \"PONGARON\"], [21, 32, 47]]\ndic = dict(zip(list1, list2))\nprint(dic)\n {'Name': ['Cyd', 'JEDD', 'JESS'], 'Surname': ['DEY', 'AUDIJE', 'PONGARON'], 'Age': [21, 32, 47]}\n"
},
{
"answer_id": 57123635,
"author": "Mayank Prakash",
"author_id": 8581348,
"author_profile": "https://Stackoverflow.com/users/8581348",
"pm_score": 2,
"selected": false,
"text": "import timeit\ndef dictionary_creation(n_nodes):\n dummy_dict = dict()\n for node in range(n_nodes):\n dummy_dict[node] = []\n return dummy_dict\n\n\ndef dictionary_creation_1(n_nodes):\n keys = list(range(n_nodes))\n values = [[] for i in range(n_nodes)]\n graph = dict(zip(keys, values))\n return graph\n\n\ndef wrapper(func, *args, **kwargs):\n def wrapped():\n return func(*args, **kwargs)\n return wrapped\n\niteration = wrapper(dictionary_creation, n_nodes)\nshorthand = wrapper(dictionary_creation_1, n_nodes)\n\nfor trail in range(1, 8):\n print(f'Itertion: {timeit.timeit(iteration, number=trails)}\\nShorthand: {timeit.timeit(shorthand, number=trails)}')\n"
},
{
"answer_id": 58700255,
"author": "jay123",
"author_id": 11073169,
"author_profile": "https://Stackoverflow.com/users/11073169",
"pm_score": 0,
"selected": false,
"text": "dict = {item : values[index] for index, item in enumerate(keys)}\n dict = {}\nfor index, item in enumerate(keys):\n dict[item] = values[index]\n"
},
{
"answer_id": 63626892,
"author": "Franco",
"author_id": 6184958,
"author_profile": "https://Stackoverflow.com/users/6184958",
"pm_score": -1,
"selected": false,
"text": "dict(zip(key, value)) y = [1,2,3,4]\nx = [\"a\",\"b\",\"c\",\"d\"]\n\n# This below is a brute force method\nobj = {}\nfor i in range(len(y)):\n obj[y[i]] = x[i]\nprint(obj)\n\n# Recursive approach \nobj = {}\ndef map_two_lists(a,b,j=0):\n if j < len(a):\n obj[b[j]] = a[j]\n j +=1\n map_two_lists(a, b, j)\n return obj\n \n\n\nres = map_two_lists(x,y)\nprint(res)\n\n {1: 'a', 2: 'b', 3: 'c', 4: 'd'} \n"
},
{
"answer_id": 65325139,
"author": "DonkeyKong",
"author_id": 2348356,
"author_profile": "https://Stackoverflow.com/users/2348356",
"pm_score": 0,
"selected": false,
"text": "def as_dict_list(data: list, columns: list):\n return [dict((zip(columns, row))) for row in data]\n"
},
{
"answer_id": 66474032,
"author": "Zeinab Mardi",
"author_id": 13194716,
"author_profile": "https://Stackoverflow.com/users/13194716",
"pm_score": 0,
"selected": false,
"text": "keys = ['name', 'age', 'food']\nvalues = ['Monty', 42, 'spam']\ndic = {}\nc = 0\nfor i in keys:\n dic[i] = values[c]\n c += 1\n\nprint(dic)\n{'name': 'Monty', 'age': 42, 'food': 'spam'}\n"
},
{
"answer_id": 72278884,
"author": "J.Jai",
"author_id": 6441604,
"author_profile": "https://Stackoverflow.com/users/6441604",
"pm_score": 1,
"selected": false,
"text": "keys = ['name', 'age', 'food']\nvalues = ['Monty', 42, 'spam'] \n\ndict = {}\n\nfor i in range(len(keys)):\n dict[keys[i]] = values[i]\n \nprint(dict)\n\n{'name': 'Monty', 'age': 42, 'food': 'spam'}\n"
},
{
"answer_id": 74518881,
"author": "guest",
"author_id": 19215298,
"author_profile": "https://Stackoverflow.com/users/19215298",
"pm_score": 1,
"selected": false,
"text": "l = [1, 5, 8, 9]\nll = [3, 7, 10, 11]\n dict(zip(l,ll)) # {1: 3, 5: 7, 8: 10, 9: 11}\n\n#if you want to play with key or value @recommended\n\n{k:v*10 for k, v in zip(l, ll)} #{1: 30, 5: 70, 8: 100, 9: 110}\n d = {}\nc=0\nfor k in l:\n d[k] = ll[c] #setting up keys from the second list values\n c += 1\nprint(d)\n{1: 3, 5: 7, 8: 10, 9: 11}\n\n d = {}\nfor i,k in enumerate(l):\n d[k] = ll[i]\nprint(d)\n{1: 3, 5: 7, 8: 10, 9: 11}\n"
},
{
"answer_id": 74680310,
"author": "Soudipta Dutta",
"author_id": 6037956,
"author_profile": "https://Stackoverflow.com/users/6037956",
"pm_score": 0,
"selected": false,
"text": " import pprint\n def makeDictUsingAlternateLists1(**rest):\n print(\"*rest.keys() : \",*rest.keys())\n print(\"rest.keys() : \",rest.keys())\n print(\"*rest.values() : \",*rest.values())\n print(\"**rest.keys() : \",rest.keys())\n print(\"**rest.values() : \",rest.values())\n [print(a) for a in zip(*rest.values())]\n \n [ print(dict(zip(rest.keys(),a))) for a in zip(*rest.values())]\n print(\"...\")\n \n \n finalRes= [ dict( zip( rest.keys(),a)) for a in zip(*rest.values())] \n return finalRes\n \n l = makeDictUsingAlternateLists1(p=p,q=q,r=r,s=s)\n pprint.pprint(l) \n\"\"\"\n*rest.keys() : p q r s\nrest.keys() : dict_keys(['p', 'q', 'r', 's'])\n*rest.values() : ['A', 'B', 'C'] [5, 2, 7] ['M', 'F', 'M'] ['Sovabazaar', 'Shyambazaar', 'Bagbazaar', 'Hatkhola']\n**rest.keys() : dict_keys(['p', 'q', 'r', 's'])\n**rest.values() : dict_values([['A', 'B', 'C'], [5, 2, 7], ['M', 'F', 'M'], ['Sovabazaar', 'Shyambazaar', 'Bagbazaar', 'Hatkhola']])\n('A', 5, 'M', 'Sovabazaar')\n('B', 2, 'F', 'Shyambazaar')\n('C', 7, 'M', 'Bagbazaar')\n{'p': 'A', 'q': 5, 'r': 'M', 's': 'Sovabazaar'}\n{'p': 'B', 'q': 2, 'r': 'F', 's': 'Shyambazaar'}\n{'p': 'C', 'q': 7, 'r': 'M', 's': 'Bagbazaar'}\n...\n[{'p': 'A', 'q': 5, 'r': 'M', 's': 'Sovabazaar'},\n {'p': 'B', 'q': 2, 'r': 'F', 's': 'Shyambazaar'},\n {'p': 'C', 'q': 7, 'r': 'M', 's': 'Bagbazaar'}]\n\"\"\"\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209840",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12388/"
] |
209,861
|
<p>I have a HTML page that scrolls up and down (not a lot, but it does scroll). How can I set the scroll position in the page after executing some JavaScript?</p>
<p>I'm using jQuery to inject some additional HTML at the bottom of the page and I'd like to programmatically scroll to the position of that new content after it's added.</p>
|
[
{
"answer_id": 209881,
"author": "KernelM",
"author_id": 22328,
"author_profile": "https://Stackoverflow.com/users/22328",
"pm_score": 3,
"selected": false,
"text": "window.scroll // put the 100th vertical pixel at the top of the window\n<button onClick=\"scroll(0, 100);\">click to scroll down 100 pixels</button>\n"
},
{
"answer_id": 210028,
"author": "Jason Bunting",
"author_id": 1790,
"author_profile": "https://Stackoverflow.com/users/1790",
"pm_score": 1,
"selected": true,
"text": "// add HTML like this, dynamically:\n// <a name=\"moveHere\" />\n\n// the javascript to make the page go to that location:\nwindow.location.hash = \"moveHere\";\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209861",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2536/"
] |
209,862
|
<p>This page displays beautifully in firefox but i get all kinds of problems when testing the site in opera or internet explorer, mostly with the menu. I would like to know what techniques have caused this and how to avoid them. </p>
<p><a href="http://www.jkhbdesign.se/" rel="nofollow noreferrer">http://www.jkhbdesign.se/</a></p>
<p>Edit 2: Here are some screenshots of some specific problems</p>
<p>The dropdown as it should look:</p>
<p><a href="http://nibbo.se/slask/correct.png" rel="nofollow noreferrer">alt text http://nibbo.se/slask/correct.png</a></p>
<p>The way it looks in IE 7:</p>
<p><a href="http://nibbo.se/slask/dropdownie.png" rel="nofollow noreferrer">alt text http://nibbo.se/slask/dropdownie.png</a></p>
<p>The way it looks in Opera:</p>
<p><a href="http://nibbo.se/slask/dropdownopera.png" rel="nofollow noreferrer">alt text http://nibbo.se/slask/dropdownopera.png</a></p>
|
[
{
"answer_id": 209934,
"author": "Geoff",
"author_id": 1097,
"author_profile": "https://Stackoverflow.com/users/1097",
"pm_score": 3,
"selected": true,
"text": "ul.menu li:hover ul.submenu {\nbackground:white none repeat scroll 0 0;\nborder:1px solid #A6A6A6;\ndisplay:block;\nmargin-left:-25px;\nmargin-top:23px;\npadding:2px 0;\nposition:absolute;\n}\n"
},
{
"answer_id": 209956,
"author": "George Stocker",
"author_id": 16587,
"author_profile": "https://Stackoverflow.com/users/16587",
"pm_score": 2,
"selected": false,
"text": "<li> <ul> <div id=\"menu\">\n <ul><a href=\"/index.html\">Home</a>\n\n <li><a href=\"/aboutus/index.html\">About Us</a>\n <ul>\n <li><a href=\"/aboutus/history.html\">History</a>\n </li>"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209862",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28668/"
] |
209,869
|
<p>Some of my data are 64-bit integers. I would like to send these to a JavaScript program running on a page.</p>
<p>However, as far as I can tell, integers in most JavaScript implementations are 32-bit signed quantities.</p>
<p>My two options seem to be:</p>
<ol>
<li>Send the values as strings</li>
<li>Send the values as 64-bit floating point numbers</li>
</ol>
<p>Option (1) isn't perfect, but option (2) seems far less perfect (loss of data).</p>
<p>How have you handled this situation?</p>
|
[
{
"answer_id": 209892,
"author": "Simon Howard",
"author_id": 24806,
"author_profile": "https://Stackoverflow.com/users/24806",
"pm_score": 6,
"selected": true,
"text": " [ 12345678, 12345678 ]\n output_values[0] = (input_value >> 32) & 0xffffffff;\n output_values[1] = input_value & 0xffffffff;\n input_value = ((int64_t) output_values[0]) << 32) | output_values[1];\n"
},
{
"answer_id": 858857,
"author": "David Leonard",
"author_id": 19502,
"author_profile": "https://Stackoverflow.com/users/19502",
"pm_score": 3,
"selected": false,
"text": "function and64(a,b) {\n var r = \"\";\n for (var i = 0; i < 4; i++)\n r += String.fromCharCode(a.charCodeAt(i) & b.charCodeAt(i));\n return r;\n}\n"
},
{
"answer_id": 34989371,
"author": "Arnaud Bouchez",
"author_id": 458259,
"author_profile": "https://Stackoverflow.com/users/458259",
"pm_score": 5,
"selected": false,
"text": "> parseInt(\"10765432100123456789\")\n10765432100123458000\n Number.MAX_SAFE_INTEGER Number.isSafeInteger() MAX_SAFE_INTEGER 9007199254740991 -(2^53 - 1) 2^53 - 1 Number.MAX_SAFE_INTEGER + 1 === Number.MAX_SAFE_INTEGER + 2 true Number.isSafeInteger() Edm.Int64 Edm.Decimal \".._str\": {\n \"id\": 10765432100123456789, // for JSON compliant clients\n \"id_str\": \"10765432100123456789\", // for JavaScript\n ...\n}\n"
},
{
"answer_id": 62771952,
"author": "Desmond Coertzen",
"author_id": 3735736,
"author_profile": "https://Stackoverflow.com/users/3735736",
"pm_score": 0,
"selected": false,
"text": "\n{ \"the_sequence_number\": \"20200707105904535\" }\n { \"the_sequence_number\": \"20200707105904535\" } \n{ \"the_sequence_number\": 20200707105904535 }\n { \"the_sequence_number\": 20200707105904535 } \nconsole.log('event_listen[' + global_weird_counter + ']: to be sure, server responded with [' + aresponsetxt + ']');\nvar response = JSON.parse(aresponsetxt);\nconsole.log('event_listen[' + global_weird_counter + ']: after json parse: ' + JSON.stringify(response));\n\n console.log('event_listen[' + global_weird_counter + ']: to be sure, server responded with [' + aresponsetxt + ']');\nvar response = JSON.parse(aresponsetxt);\nconsole.log('event_listen[' + global_weird_counter + ']: after json parse: ' + JSON.stringify(response));\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209869",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/338/"
] |
209,874
|
<p>New to javascript/jquery and having a hard time with using <code>this</code> or <code>$(this)</code> to get the current object.</p>
<p>I have a table with a set of <code>radio buttons</code> on each row, each named <code>s_<rowindex></code>. None of the radio buttons are checked by default:</p>
<pre><code><tr>
<td align="left" style="width: 300px">
<div id="div_s_0">
<input type="radio" name="s_0" value="1" />Public
<input type="radio" name="s_0" value="2" />Not Public
<input type="radio" name="s_0" value="3" />Confidential
</div>
</td>
</tr>
<tr>
<td align="left" style="width: 300px">
<div id="div_s_1">
<input type="radio" name="s_1" value="1" />Public
<input type="radio" name="s_1" value="2" />Not Public
<input type="radio" name="s_1" value="3" />Confidential
</div>
</td>
</tr>
</code></pre>
<p>I'm trying to write a jQuery function to add a new row to the table whenever the user selects a radio button, but only if they are currently on the last row of the table. What I'd like to do is get the name attribute of the clicked radio button, parse it to get the row index (i.e. the part after the '_') and compare it to the number of rows in the table. If they are equal, add a new row, otherwise, do nothing.</p>
<p>My question is twofold, depending on how I should attack this:</p>
<p>1) How do I return the name attribute of a radio button, OR
2) How do I return the row index of the row I am currently in?</p>
|
[
{
"answer_id": 209926,
"author": "MDCore",
"author_id": 1896,
"author_profile": "https://Stackoverflow.com/users/1896",
"pm_score": 0,
"selected": false,
"text": "$(\"#div_s_0 input[type='radio']\").onclick = function() {\n if ($(\"#div_s_0 input[type='radio']:last\").attr('checked') == 'checked') {\n /* add a new element */\n }\n}\n div_s_0 ... :last"
},
{
"answer_id": 209951,
"author": "Ryan Duffield",
"author_id": 2696,
"author_profile": "https://Stackoverflow.com/users/2696",
"pm_score": 4,
"selected": true,
"text": "$(document).ready(function() {\n $(\"input:radio\").click(function() {\n var index = parseInt(this.name.split('_')[1])\n });\n});\n $($(\"table\").children()[0]).children().length\n"
},
{
"answer_id": 210070,
"author": "Pseudo Masochist",
"author_id": 8529,
"author_profile": "https://Stackoverflow.com/users/8529",
"pm_score": 2,
"selected": false,
"text": "var rowIndex = $(\"#mytable tr\").index($(this).parents(\"tr\"));\nvar inputName = $(this).attr(\"name\");\nalert(\"Input Name: \" + inputName + \"; RowIndex: \" + rowIndex);\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209874",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23585/"
] |
209,888
|
<p>Python 3.0 is in beta with a final release coming shortly. Obviously it will take some significant time for general adoption and for it to eventually replace 2.x.</p>
<p>I am writing a tutorial about certain aspects of programming Python. I'm wondering if I should do it in Python 2.x or 3.0? (not that the difference is huge)</p>
<p>a 2.x tutorial is probably more useful now, but it would be nice to start producing 3.0 tutorials.</p>
<p>anyone have thoughts?</p>
<p>(of course I could do both, but I would prefer to do one or the other)</p>
|
[
{
"answer_id": 209911,
"author": "Dan Lenski",
"author_id": 20789,
"author_profile": "https://Stackoverflow.com/users/20789",
"pm_score": 2,
"selected": false,
"text": "print print"
},
{
"answer_id": 214510,
"author": "Glyph",
"author_id": 13564,
"author_profile": "https://Stackoverflow.com/users/13564",
"pm_score": 5,
"selected": true,
"text": "2to3 /usr/bin/python"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209888",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16148/"
] |
209,890
|
<p>I'm looking for a regex that can pull out quoted sections in a string, both single and double quotes.</p>
<p>IE:</p>
<pre><code>"This is 'an example', \"of an input string\""
</code></pre>
<p>Matches:</p>
<ul>
<li>an example</li>
<li>of an input string</li>
</ul>
<p>I wrote up this:</p>
<pre><code> [\"|'][A-Za-z0-9\\W]+[\"|']
</code></pre>
<p>It works but does anyone see any flaws with it?</p>
<p>EDIT: The main issue I see is that it can't handle nested quotes.</p>
|
[
{
"answer_id": 209898,
"author": "Chris Bunch",
"author_id": 422,
"author_profile": "https://Stackoverflow.com/users/422",
"pm_score": 0,
"selected": false,
"text": "[\\\"']([^\\\"']*)[\\\"']\n"
},
{
"answer_id": 209899,
"author": "Tomalak",
"author_id": 18771,
"author_profile": "https://Stackoverflow.com/users/18771",
"pm_score": 1,
"selected": false,
"text": "\"([\\\"'])(.*?)\\1\"\n"
},
{
"answer_id": 209931,
"author": "Bill the Lizard",
"author_id": 1288,
"author_profile": "https://Stackoverflow.com/users/1288",
"pm_score": 2,
"selected": false,
"text": "\"This is 'an example', \\\"of 'quotes within quotes'\\\"\"\n (\\\"|')[A-Za-z0-9\\\\W]+?\\1\n"
},
{
"answer_id": 210131,
"author": "jfs",
"author_id": 4279,
"author_profile": "https://Stackoverflow.com/users/4279",
"pm_score": 0,
"selected": false,
"text": "@\"(\\\"|')(.*?)\\1\"\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209890",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1965/"
] |
209,905
|
<p>Can somebody explain what is <a href="https://stackoverflow.com/tags/rest/info">REST</a> and what is <a href="https://stackoverflow.com/tags/soap/info">SOAP</a> in plain english? And how Web Services work? </p>
|
[
{
"answer_id": 22415123,
"author": "cmd",
"author_id": 2616755,
"author_profile": "https://Stackoverflow.com/users/2616755",
"pm_score": 5,
"selected": false,
"text": "SOAP REST SOAP HTTP SOAP REST HTTP HTTP REST HTTP"
},
{
"answer_id": 25706876,
"author": "inf3rno",
"author_id": 607033,
"author_profile": "https://Stackoverflow.com/users/607033",
"pm_score": 3,
"selected": false,
"text": "https://example.com/api/v1/users?offset=50&count=25 https://example.com/api/v1/ https://example.com/api/v2/ https://example.com/api/v1/ PATCH https://example.com/api/v1/users/1 {name: \"Mrs Smith\"} {name: \"Mrs Smith\"} GET https://example.com/api/v1/users/1?fields=\"name\" 200 ok, {name: \"Mrs Smith\"} accept image/jpeg"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209905",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26927/"
] |
209,906
|
<p>Is there a way in PHP to compile a regular expression, so that it can then be compared to multiple strings without repeating the compilation process? Other major languages can do this -- Java, C#, Python, Javascript, etc.</p>
|
[
{
"answer_id": 7119245,
"author": "Mike",
"author_id": 902114,
"author_profile": "https://Stackoverflow.com/users/902114",
"pm_score": 4,
"selected": false,
"text": "<?php\n\nfunction microtime_float() {\n list($usec, $sec) = explode(\" \", microtime());\n return ((float)$usec + (float)$sec);\n}\n\n// test string\n$text='The big brown <b>fox</b> jumped over a lazy <b>cat</b>';\n$testTimes=10;\n\n\n$avg=0;\nfor ($x=0; $x<$testTimes; $x++)\n{\n $start=microtime_float();\n for ($i=0; $i<10000; $i++) {\n preg_match_all('/<b>(.*)<\\/b>0?/', $text, $m);\n }\n $end=microtime_float();\n $avg += (float)$end-$start;\n}\n\necho 'Regexp with caching avg '.($avg/$testTimes);\n\n// regexp without caching\n$avg=0;\nfor ($x=0; $x<$testTimes; $x++)\n{\n $start=microtime_float();\n for ($i=0; $i<10000; $i++) {\n $pattern='/<b>(.*)<\\/b>'.$i.'?/';\n preg_match_all($pattern, $text, $m);\n }\n $end=microtime_float();\n $avg += (float)$end-$start;\n}\n\necho '<br/>Regexp without caching avg '.($avg/$testTimes);\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209906",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25213/"
] |
209,924
|
<p>My code for sql connection using linq is:</p>
<pre><code>var query1 = from u in dc.Usage_Computers
where u.DomainUser == s3
select u; // selects all feilds from table
GridView1.DataSource = query1;
GridView1.DataBind();
</code></pre>
<p>I have a field called "Operation" in the table "Domainuser" which has values like "1, 2, 3". When I populate these values to data grid I wanted to convert them to meaningful values like if the value of Operation is 1 then display in datagrid as "logon", if 2 then "logoff" etc...</p>
<p>How do i assign values for them after retrieving from database?</p>
|
[
{
"answer_id": 209944,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 0,
"selected": false,
"text": "protected void label_OnPreRender( object sender, EventArgs e )\n{\n Label l = (Label)sender;\n switch (l.Text) {\n case \"1\":\n l.Text = \"Logon\";\n break;\n ...\n default:\n break;\n }\n}\n"
},
{
"answer_id": 210003,
"author": "Brendan Kendrick",
"author_id": 13473,
"author_profile": "https://Stackoverflow.com/users/13473",
"pm_score": 2,
"selected": false,
"text": "<asp:GridView ID=\"gvDomain\" runat=\"server\" OnRowDataBound=\"gvDomain_RowDataBound\">\n <Columns>\n <asp:TemplateField>\n <HeaderTemplate>\n Operation\n </HeaderTemplate>\n <ItemTemplate>\n <asp:Label id=\"lblLogon\" runat=\"server\" />\n </ItemTemplate>\n </asp:TemplateField>\n </Columns>\n</asp:GridView>\n Protected Sub gvDomain_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvStates.RowDataBound\n Dim lblLogon As Label = DirectCast(e.Row.FindControl(\"lblLogon\"), Label)\n Dim drv As DataRowView = DirectCast(e.Row.DataItem, DataRowView)\n\n If lblLogon IsNot Nothing Then\n Select Case drv(\"Operation\").ToString()\n Case \"1\" \n lblLogon.Text = \"Logon\"\n Break\n Case \"2\"\n lblLogon.Text = \"Logoff\"\n Break\n //etc...\n End Select\n End If\nEnd Sub\n"
},
{
"answer_id": 210051,
"author": "David Alpert",
"author_id": 8997,
"author_profile": "https://Stackoverflow.com/users/8997",
"pm_score": 1,
"selected": false,
"text": "static Func<int?, string> MapSqlIntToArbitraryLabel = (i =>\n{\n // for performance, abstract this reference \n // dictionary out to a static property\n Dictionary<int, string> labels = new Dictionary<int, string>();\n labels.Add(1, \"logon\");\n labels.Add(2, \"logoff\");\n labels.Add(...);\n\n if (i == null) throw new ArgumentNullException();\n if (i < 1 || i > labels.Count) throw new ArgumentOutOfRangeException();\n\n return labels.Where(x => x.Key == i.Value)\n .Select(x.Value)\n .Single();\n}\n return (from kvp in labels\n where kvp.Key == i.Value\n select kvp.Value).Single();\n var query1 = from u in dc.Usage_Computers \n where u.DomainUser == s3 \n select {\n Operation = MapSqlIntToArbitraryLabel(u.Operation)\n // add other properties to this anonymous type as needed\n };\n"
},
{
"answer_id": 210056,
"author": "Amy B",
"author_id": 8155,
"author_profile": "https://Stackoverflow.com/users/8155",
"pm_score": 5,
"selected": true,
"text": "var query1 =\n from u in dc.Usage_Computers\n where u.DomainUser == s3\n select new {usage = u, \n operation =\n u.DomainUser.Operation == 1 ? \"login\" :\n u.DomainUser.Operation == 2 ? \"logoff\" :\n \"something else\"\n };\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209924",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
209,935
|
<p>I'm trying to set up a virtual host on a new VPS using apache 2.x on a Ubuntu server.</p>
<p>When starting apache I get the error " xxx.241.214.xxx:80 has no VirtualHosts", and the url for the site still points to the default location which means my virtual host file isn't taking effect:</p>
<pre><code><VirtualHost xxx.241.214.xxx:80>
ServerName xxx.co.uk
ServerAlias www.xxx.co.uk
DocumentRoot /var/www/vhosts/xxx.co.uk/httpdocs/xxx.co.uk
</VirtualHost>
</code></pre>
<p>Please help, I'm no good at all this server config stuff.</p>
|
[
{
"answer_id": 209954,
"author": "Richard Harrison",
"author_id": 19624,
"author_profile": "https://Stackoverflow.com/users/19624",
"pm_score": 0,
"selected": false,
"text": "<VirtualHost *>\n"
},
{
"answer_id": 212176,
"author": "Rodent43",
"author_id": 28869,
"author_profile": "https://Stackoverflow.com/users/28869",
"pm_score": 1,
"selected": false,
"text": "Listen 80\n\nNameVirtualHost *:80\n\n# Site 1 Comment\n\n<VirtualHost *:80>\n ServerName site1.intranet\n ServerAdmin administrator@whatever.com\n DocumentRoot /var/www/html/site1\n</VirtualHost>\n\n# Site 2 Comment\n\n<VirtualHost *:80>\n ServerName site2.intranet\n ServerAdmin administrator@whatever.com\n DocumentRoot /var/www/html/site2\n</VirtualHost>\n http://site1.intranet"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209935",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
209,963
|
<p>I've got a table of hardware and a table of incidents. Each hardware has a unique tag, and the incidents are tied to the tag.</p>
<p>How can I select all the hardware which has at least one incident listed as unresolved?</p>
<p>I can't just do a join, because then if one piece of hardware had multiple unresolved issues, it would show up multiple times.</p>
|
[
{
"answer_id": 209967,
"author": "Richard Harrison",
"author_id": 19624,
"author_profile": "https://Stackoverflow.com/users/19624",
"pm_score": 4,
"selected": true,
"text": "select distinct(hardware_name) \nfrom hardware,incidents \nwhere hardware.id = incidents.hardware_id and incidents.resolved=0;\n"
},
{
"answer_id": 209984,
"author": "Eric Hogue",
"author_id": 4137,
"author_profile": "https://Stackoverflow.com/users/4137",
"pm_score": 2,
"selected": false,
"text": "Select A.HardwareID A.HadwareName, B.UnresolvedCount\nFrom (Hardware A) \nInner Join \n(\n Select HardwareID, Count(1) As UnresolvedCount \n From Incidents \n Where Resolved = 0 \n Group By HardwareID\n) As B On A.HardwareID = B.HardwareID\n"
},
{
"answer_id": 44405135,
"author": "Passionate Coder",
"author_id": 5817313,
"author_profile": "https://Stackoverflow.com/users/5817313",
"pm_score": 0,
"selected": false,
"text": "SELECT hd.name, inc.issue, FROM hardware hd INNER JOIN inc ON hd.tag = inc.tag AND inc.issue = 'unresolved' group by hd.name \n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209963",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18210/"
] |
209,972
|
<p>How to Programmatically Inject JavaScript in PDF files?</p>
<p>Can it be done without Adobe Professional?</p>
<hr>
<p>My goal is: I want to show up the print dialog immediately when I open the PDF. </p>
<p>I know that this can be done with JavaScript code embedded in the document.</p>
|
[
{
"answer_id": 3963918,
"author": "Mark Storer",
"author_id": 477771,
"author_profile": "https://Stackoverflow.com/users/477771",
"pm_score": 2,
"selected": false,
"text": "PdfReader myReader = new PdfReader( myFilePath ); // throws IOException\nPdfStamper myStamper = new PdfStamper( myReader, new FileOutputStream(outPath) ); // throws IOE, DocumentException\n\n// add a document script\nmyStamper.addJavaScript( myScriptString );\n\n// add a page-open script, 1 is the first page, not zero0\nPdfAction jsAction = PdfAction.javaScript( someScriptString );\nmyStamper.setPageAction( PdfWriter.PAGE_OPEN, jsAction, myStamper.getWriter(), pageNumber ); // throws PdfException (for bad first param)\n\nPdfFormField button = PdfFormField.createButton(myWriter, PdfFormField.FF_PUSHBUTTON);\nbutton.setWidget( myRectangle, PdfAnnotation.HIGHLIGHT_INVERT );\n\n// the important part, adding jsAction\njsAction = PdfAction.javaScript( buttonScriptString );\nbutton.setAdditionalActions( PdfAnnotation.AA_DOWN, jsAction ); // mouse down\n\nmyStamper.addAnnotation( pageNum, button );\n\nmyStamper.close(); // write everything out, throws DocumentException, IOE\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209972",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1100/"
] |
209,980
|
<p>I have tried</p>
<pre><code><ul id="contact_list">
<li id="phone">Local 604-555-5555</li>
<li id="i18l_phone">Toll-Free 1-800-555-5555</li>
</ul>
</code></pre>
<p>with</p>
<pre><code>#contact_list
{
list-style: disc none inside;
}
#contact_list #phone
{
list-style-image: url(images/small_wood_phone.png);
}
#contact_list #i18l_phone
{
list-style-image: url(images/i18l_wood_phone.png);
}
</code></pre>
<p>to no avail. Only a disc appears. If I want each individual list item to have it's own bullet, how can I accomplish this with css, <strong><em>without using background images</em></strong>.</p>
<p>Edit : I have discovered that, despite what firebug tells me, the list-style-image rule is being overridden somehow. If I inline the rule, like so:</p>
<pre><code> <li id="phone" style="list-style-image: url(images/small_wood_phone.png);">Local 604-555-5555</li>
</code></pre>
<p>then all is well. Since I have no other rules in the test case I'm running that contains ul or li in the selector, I'm not sure why inlining gives a different result.</p>
|
[
{
"answer_id": 209997,
"author": "Remy Sharp",
"author_id": 22617,
"author_profile": "https://Stackoverflow.com/users/22617",
"pm_score": 2,
"selected": false,
"text": "#contact_list\n{\n list-style: none;\n}\n\n#contact_list li {\n padding-left: 20px; /* assumes the icons are 16px */\n}\n\n#contact_list #phone\n{\n background: url(images/small_wood_phone.png) no-repeat top left;\n}\n\n#contact_list #i18l_phone\n{\n background: url(images/i18l_wood_phone.png) no-repeat top left;\n}\n"
},
{
"answer_id": 209998,
"author": "Marius",
"author_id": 1585,
"author_profile": "https://Stackoverflow.com/users/1585",
"pm_score": -1,
"selected": false,
"text": "#contact_list\n{\n list-style: disc none inside;\n}\n\n#contact_list #phone\n{\n background-image: url(images/small_wood_phone.png) no-repeat top left;\n padding-left: <image width>px;\n}\n\n#contact_list #i18l_phone\n{\n background-image: url(images/i18l_wood_phone.png) no-repeat top left;\n padding-left: <image width>px;\n}\n"
},
{
"answer_id": 210013,
"author": "Anne Porosoff",
"author_id": 28701,
"author_profile": "https://Stackoverflow.com/users/28701",
"pm_score": 3,
"selected": false,
"text": "#contact_list li\n{\n list-style: none;\n}\n\n#contact_list li#phone\n{\n list-style-image: url('images/small_wood_phone.png');\n}\n\n#contact_list li#i18l_phone\n{\n list-style-image: url('images/i18l_wood_phone.png');\n}\n"
},
{
"answer_id": 210232,
"author": "Dustman",
"author_id": 16398,
"author_profile": "https://Stackoverflow.com/users/16398",
"pm_score": 2,
"selected": false,
"text": "#contact_list #phone\n{\n list-style-image: url(\"/images/small_wood_phone.png\");\n}\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/209980",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16398/"
] |
210,022
|
<p>I have a requirement on my current project (a Flex app which will be run in Flash player) to display an arbitrary subset of the components on a form while hiding all the other components based on certain aspects of the application state. There are about a dozen different text boxes and drop downs, but some become irrelevant based on previously entered user data and we don't want to display those when we get to this particular form. Every time this form is displayed I could need to show any one of the many permutations of these components.</p>
<p>I'm trying to decide what the best way to approach this problem is. Should I create a Canvas (or other container) with all of the needed controls on it and then just set visible = false on the ones I don't need? The problem then becomes making sure the layout looks decent. I don't want there to be gaps where the hidden controls would have been.</p>
<p>The other option I've thought about is just having a mechanism that could dynamically instantiate the TextInput or CheckBox etc. component and then call container.addChild(control) in order to build up the components and not have to worry about the gap issue.</p>
<p>This seems like a problem that has an idiomatic solution in flex, but I don't know what it is. Neither of these ideas seem great so I'm wondering if anyone else has a better idea.</p>
|
[
{
"answer_id": 210090,
"author": "rmeador",
"author_id": 10861,
"author_profile": "https://Stackoverflow.com/users/10861",
"pm_score": 3,
"selected": true,
"text": "visible = false includeInLayout = false"
},
{
"answer_id": 210105,
"author": "David Arno",
"author_id": 7122,
"author_profile": "https://Stackoverflow.com/users/7122",
"pm_score": 3,
"selected": false,
"text": "<mx:states>\n <mx:State name=\"State1\">\n <mx:AddChild position=\"lastChild\">\n <components.../>\n </mx:AddChild>\n </mx:State>\n <mx:State name=\"State2\">\n <mx:AddChild position=\"lastChild\">\n <mx:Canvas.../>\n </mx:AddChild>\n <mx:AddChild position=\"lastChild\">\n <mx:VBox.../>\n </mx:AddChild>\n </mx:State>\n</mx:states>\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/210022",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1247/"
] |
210,026
|
<p>I have some C++ source code with templates maybe like this - doxygen runs without errors but none of the documentation is added to the output, what is going on?</p>
<pre><code>///
/// A class
///
class A
{
///
/// A typedef
///
typedef B<C<D>> SomeTypedefOfTemplates;
};
</code></pre>
|
[
{
"answer_id": 210043,
"author": "1800 INFORMATION",
"author_id": 3146,
"author_profile": "https://Stackoverflow.com/users/3146",
"pm_score": 3,
"selected": true,
"text": "///\n/// A class\n///\nclass A\n{\n ///\n /// A typedef\n ///\n typedef B<C<D> > SomeTypedefOfTemplates;\n};\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/210026",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3146/"
] |
210,068
|
<p>What's the shortest Perl one-liner that print out the first 9 powers of a hard-coded 2 digit decimal (say, for example, .37), each on its own line? </p>
<p>The output would look something like:</p>
<pre><code>1
0.37
0.1369
[etc.]
</code></pre>
<p>Official Perl golf rules:</p>
<ol>
<li>Smallest number of (key)strokes wins</li>
<li>Your stroke count includes the command line</li>
</ol>
|
[
{
"answer_id": 210107,
"author": "willasaywhat",
"author_id": 12234,
"author_profile": "https://Stackoverflow.com/users/12234",
"pm_score": 0,
"selected": false,
"text": "perl -e \"for(my $i = 1; $i < 10; $i++){ print((.37**$i). \\\"\\n\\\"); }\"\n"
},
{
"answer_id": 210132,
"author": "toolkit",
"author_id": 3295,
"author_profile": "https://Stackoverflow.com/users/3295",
"pm_score": 1,
"selected": false,
"text": "print join(\"\\n\", map { 0.37**$_ } (0..9));\n"
},
{
"answer_id": 210140,
"author": "moritz",
"author_id": 14132,
"author_profile": "https://Stackoverflow.com/users/14132",
"pm_score": 5,
"selected": true,
"text": "perl -E'say 0.37**$_ for 0..8'\n say perl -le'print 0.37**$_ for 0..8'\n perl -E'say.37**$_ for 0..8'\n"
},
{
"answer_id": 210150,
"author": "kixx",
"author_id": 11260,
"author_profile": "https://Stackoverflow.com/users/11260",
"pm_score": 2,
"selected": false,
"text": "perl -e 'print .37**$_,\"\\n\" for 0..9'\n"
},
{
"answer_id": 210325,
"author": "C. K. Young",
"author_id": 13,
"author_profile": "https://Stackoverflow.com/users/13",
"pm_score": 1,
"selected": false,
"text": "print.37**$_.$/for 0..8\n"
},
{
"answer_id": 210471,
"author": "1800 INFORMATION",
"author_id": 3146,
"author_profile": "https://Stackoverflow.com/users/3146",
"pm_score": 3,
"selected": false,
"text": "perl -le'map{print.37**$_}0..8'\n perl -E'map{say.37**$_}0..8'\n"
},
{
"answer_id": 211217,
"author": "ysth",
"author_id": 17389,
"author_profile": "https://Stackoverflow.com/users/17389",
"pm_score": 2,
"selected": false,
"text": "seq 9|perl -nE'say.37**$_'\n"
},
{
"answer_id": 215331,
"author": "Aristotle Pagaltzis",
"author_id": 9410,
"author_profile": "https://Stackoverflow.com/users/9410",
"pm_score": 2,
"selected": false,
"text": "perl6 -e'.say for .37»**»^9'\n perl6 -e'say .37**$_ for^9'\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/210068",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2683/"
] |
210,069
|
<p>In ASP.NET what's the best way to do the following:</p>
<ol>
<li>Show certain controls based on your rights?</li>
<li>For a gridview control, how do you show certain columns based on your role?</li>
</ol>
<p>I'm thinking for number 2, have the data come from a role specific view on the database.</p>
|
[
{
"answer_id": 210117,
"author": "Elijah Manor",
"author_id": 4481,
"author_profile": "https://Stackoverflow.com/users/4481",
"pm_score": 4,
"selected": true,
"text": "//Delete Icon Column\ngridViewContacts.Columns[0].Visible = user.IsInRole(\"DeleteAnyContact\"); \n"
},
{
"answer_id": 210162,
"author": "John Rudy",
"author_id": 14048,
"author_profile": "https://Stackoverflow.com/users/14048",
"pm_score": 1,
"selected": false,
"text": "LoginView LoginView RoleGroups ContentTemplates"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/210069",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/781/"
] |
210,079
|
<p>I have a 10 second sound effect wave file. What I would like to do is take that file and repeat it n number of times and then save the longer WAV file to disk. This way I can create a much longer background effect rather than auto-repeat on the media player which is a bit stuttered between repeats. I am trying to do this in C#.</p>
|
[
{
"answer_id": 216932,
"author": "Mark Heath",
"author_id": 7532,
"author_profile": "https://Stackoverflow.com/users/7532",
"pm_score": 0,
"selected": false,
"text": "WaveFileReader WaveFileWriter WaveStream"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/210079",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27294/"
] |
210,080
|
<p>I'm sure this one is easy but I've tried a ton of variations and still cant match what I need. The thing is being too greedy and I cant get it to stop being greedy.</p>
<p>Given the text:</p>
<pre><code>test=this=that=more text follows
</code></pre>
<p>I want to just select:</p>
<pre><code>test=
</code></pre>
<p>I've tried the following regex</p>
<pre><code>(\S+)=(\S.*)
(\S+)?=
[^=]{1}
...
</code></pre>
<p>Thanks all.</p>
|
[
{
"answer_id": 210102,
"author": "Owen",
"author_id": 4853,
"author_profile": "https://Stackoverflow.com/users/4853",
"pm_score": 5,
"selected": true,
"text": "// matches \"test=, test\"\n(\\S+?)=\n\nor\n\n// matches \"test=, test\" too\n(\\S[^=]+)=\n \"test=this=that=more text follows\" test=this=that= test=this= test= test= test="
},
{
"answer_id": 210108,
"author": "chills42",
"author_id": 23855,
"author_profile": "https://Stackoverflow.com/users/23855",
"pm_score": 1,
"selected": false,
"text": "(\\S+?)=(\\S.*)\n"
},
{
"answer_id": 210484,
"author": "Andy Lester",
"author_id": 8454,
"author_profile": "https://Stackoverflow.com/users/8454",
"pm_score": 1,
"selected": false,
"text": "([^=]+)=([^=]+)\n [^=]{1}"
},
{
"answer_id": 738841,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "^(\\w+=)\n ^(\\w+=)*\n [th\\w+=]*test=\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/210080",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14230/"
] |
210,088
|
<p>I have a website that is deployed between 3 different environments - Dev, Stage, and Prod. For Stage and Prod, the site can resolve local paths to images with just the base url to the file, such as /SiteImages/banner.png. However, on the Dev server I have to hard code the full URL of the image path for the image to be resolved, such as <a href="http://server/folder/SiteImages/banner.png" rel="nofollow noreferrer">http://server/folder/SiteImages/banner.png</a>. Is there a setting I can flip to make the Dev server behave in the same manner as the other 2? I am using IIS 6.0 on a Win 2003 server. </p>
|
[
{
"answer_id": 210102,
"author": "Owen",
"author_id": 4853,
"author_profile": "https://Stackoverflow.com/users/4853",
"pm_score": 5,
"selected": true,
"text": "// matches \"test=, test\"\n(\\S+?)=\n\nor\n\n// matches \"test=, test\" too\n(\\S[^=]+)=\n \"test=this=that=more text follows\" test=this=that= test=this= test= test= test="
},
{
"answer_id": 210108,
"author": "chills42",
"author_id": 23855,
"author_profile": "https://Stackoverflow.com/users/23855",
"pm_score": 1,
"selected": false,
"text": "(\\S+?)=(\\S.*)\n"
},
{
"answer_id": 210484,
"author": "Andy Lester",
"author_id": 8454,
"author_profile": "https://Stackoverflow.com/users/8454",
"pm_score": 1,
"selected": false,
"text": "([^=]+)=([^=]+)\n [^=]{1}"
},
{
"answer_id": 738841,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "^(\\w+=)\n ^(\\w+=)*\n [th\\w+=]*test=\n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/210088",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1284/"
] |
210,094
|
<p>There is a store procedure that uses FREETEXTTABLE twice on two tables and then merges the results and returns the top 50. </p>
<p>The problem is if I do a search on "Women of Brewster", the results returns "Confession of an ex doofus motha" with a rank of 143 from table A and second "Women of Brewster Place" with a rank of 102 from table B.</p>
<p>Is this because of the count? (Table A return results total is 2399. Table B return results total is 3445.)</p>
|
[
{
"answer_id": 67916046,
"author": "pj2494",
"author_id": 5018023,
"author_profile": "https://Stackoverflow.com/users/5018023",
"pm_score": 0,
"selected": false,
"text": "USE AdventureWorks2012; \nGO \n \nSELECT FT_TBL.Description \n ,KEY_TBL.RANK \nFROM Production.ProductDescription AS FT_TBL \n INNER JOIN FREETEXTTABLE(Production.ProductDescription, \n Description, \n 'high level of performance') AS KEY_TBL \nON FT_TBL.ProductDescriptionID = KEY_TBL.[KEY] \nORDER BY RANK DESC; \nGO \n"
}
] |
2008/10/16
|
[
"https://Stackoverflow.com/questions/210094",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8737/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.