qid
int64
4
19.1M
question
stringlengths
18
48.3k
answers
list
date
stringlengths
10
10
metadata
list
125,878
<p>I am new to java so excuse my lame questions:)</p> <p>I am trying to build a web service in Java NetBeans 6.1 , but I have some troubles with configuration parameters ( like .settings in .net).</p> <p>What is the right way to save and access such settings in a java web service.</p> <p>Is there a way to read context parameters from web.xml in a web method?</p> <p>If no what are the alternatives for storing your configuration variables like pathnames ?</p> <p>Thank you</p>
[ { "answer_id": 125949, "author": "Lars Westergren", "author_id": 15627, "author_profile": "https://Stackoverflow.com/users/15627", "pm_score": 2, "selected": false, "text": "<servlet>\n <servlet-name>jsp</servlet-name>\n <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>\n <init-param>\n <param-name>fork</param-name>\n <param-value>false</param-value>\n </init-param>\n</servlet>\n System.getProperty(String name);\n" }, { "answer_id": 7735823, "author": "dosER_42", "author_id": 990812, "author_profile": "https://Stackoverflow.com/users/990812", "pm_score": 1, "selected": false, "text": "MessageContext ctx = MessageContext.getCurrentThreadsContext(); \nServlet wsServlet = (Servlet) ctx.getProperty(HTTPConstants.MC_HTTP_SERVLET); \nServletConfig wsServletConfig = wsServlet.getServletConfig(); \nServletContext wsContext = wsServletConfig.getServletContext(); \n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/125878", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18834/" ]
125,880
<p>Maps are great to get things done easily, but they are memory hogs and suffer from caching issues. And when you have a map in a critical loop that can be bad.</p> <p>So I was wondering if anyone can recommend another container that has the same API but uses lets say a vector or hash implementation instead of a tree implementation. My goal here is to swap the containers and not have to rewrite all the user code that relies on the map.</p> <p>Update: performance wise the best solution would be a tested map facade on a std::vector</p>
[ { "answer_id": 125938, "author": "Carl Seleborg", "author_id": 2095, "author_profile": "https://Stackoverflow.com/users/2095", "pm_score": 2, "selected": false, "text": "std::vector" }, { "answer_id": 125943, "author": "Luc Touraille", "author_id": 20984, "author_profile": "https://Stackoverflow.com/users/20984", "pm_score": 4, "selected": false, "text": "template <class Key,\n class T,\n class Hash = std::tr1::hash<Key>,\n class Pred = std::equal_to<Key>,\n class Alloc = std::allocator<std::pair<const Key, T> > >\nclass unordered_map;\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/125880", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15124/" ]
125,885
<p>I'm working on a fairly complex project, a custom encryption routine if you will (just for fun) and I've run into this issue in designing my code layout.</p> <p>I have a number of functions that I want to be able to call by index. Specifically, I need to be able to call one randomly for the encrypt process, but then address that by a specific index in the decrypt process.</p> <p>I was considering a classic function array, but my main concern is that a function array would be tricky to maintain, and a little ugly. (The goal is to get each function pair in a separate file, to reduce compile times and make the code easier to manage.) Does anyone have a more elegant C++ solution as an alternative to a function array? Speed isn't really an issue, I'm more worried about maintainability.</p> <p>-Nicholas</p>
[ { "answer_id": 125915, "author": "NeARAZ", "author_id": 6799, "author_profile": "https://Stackoverflow.com/users/6799", "pm_score": 3, "selected": false, "text": "struct FunctionPair {\n EncodeFunction encode;\n DecodeFunction decode;\n};\nFunctionPair g_Functions[] = {\n { MyEncode1, MyDecode1 },\n { MySuperEncode, MySuperDecode },\n { MyTurboEncode, MyTurboDecode },\n};\n" }, { "answer_id": 125942, "author": "Khoth", "author_id": 20686, "author_profile": "https://Stackoverflow.com/users/20686", "pm_score": 3, "selected": true, "text": "class EncryptionFunction\n{\npublic:\n virtual Foo Run(Bar input) = 0;\n virtual ~MyFunction() {}\n};\n\nclass SomeSpecificEncryptionFunction : public EncryptionFunction\n{\n // override the Run function\n};\n\n// ...\n\nstd::vector<EncryptionFunction*> functions;\n\n// ...\n\nfunctions[2]->Run(data);\n operator() Run" }, { "answer_id": 125956, "author": "xtofl", "author_id": 6610, "author_profile": "https://Stackoverflow.com/users/6610", "pm_score": 0, "selected": false, "text": "// functiontype.h\ntypedef bool (*forwardfunction)( double*, double* );\n\n// f1.h\n#include \"functiontype.h\"\nbool f1( double*, double* );\n\n// f1.c\n#include \"functiontype.h\"\n#include \"f1.h\"\nbool f1( double* p1, double* p2 ) { return false; }\n\n\n// functioncontainer.c \n#include \"functiontype.h\"\n#include \"f1.h\"\n#include \"f2.h\"\n#include \"f3.h\"\n\nforwardfunction my_functions[] = { f1, f2, f3 };\n" }, { "answer_id": 126232, "author": "Eddie", "author_id": 21116, "author_profile": "https://Stackoverflow.com/users/21116", "pm_score": 0, "selected": false, "text": "boost::signals void print_sum(float x, float y)\n{\n std::cout << \"The sum is \" << x+y << std::endl;\n}\n\nvoid print_product(float x, float y)\n{\n std::cout << \"The product is \" << x*y << std::endl;\n}\n\nvoid print_difference(float x, float y)\n{\n std::cout << \"The difference is \" << x-y << std::endl;\n}\n\nvoid print_quotient(float x, float y)\n{\n std::cout << \"The quotient is \" << x/y << std::endl;\n}\n boost::signal<void (float, float)> sig;\n\nsig.connect(&print_sum);\nsig.connect(&print_product);\nsig.connect(&print_difference);\nsig.connect(&print_quotient);\n\nsig(5, 3);\n The sum is 8\nThe product is 15\nThe difference is 2\nThe quotient is 1.66667\n" }, { "answer_id": 3111657, "author": "Jim Fell", "author_id": 214296, "author_profile": "https://Stackoverflow.com/users/214296", "pm_score": 0, "selected": false, "text": "int Proto1( void );\nint Proto2( void );\nint Proto3( void );\n\nint (*functinPointer[3])( void ) =\n{\n Proto1,\n Proto2,\n Proto3\n};\n int iFuncIdx = 0;\nint iRetCode = functinPointer[iFuncIdx++]();\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/125885", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19521/" ]
125,921
<p>I'm trying to handle Winsock_Connect event (Actually I need it in Excel macro) using the following code:</p> <pre><code>Dim Winsock1 As Winsock 'Object type definition Sub Init() Set Winsock1 = CreateObject("MSWinsock.Winsock") 'Object initialization Winsock1.RemoteHost = "MyHost" Winsock1.RemotePort = "22" Winsock1.Connect Do While (Winsock1.State &lt;&gt; sckConnected) Sleep 200 Loop End Sub 'Callback handler Private Sub Winsock1_Connect() MsgBox "Winsock1::Connect" End Sub </code></pre> <p>But it never goes to Winsock1_Connect subroutine although Winsock1.State is "Connected". I want to use standard MS library because I don't have administrative rights on my PC and I'm not able to register some custom libraries. Can anybody tell me, where I'm wrong?</p>
[ { "answer_id": 125975, "author": "Nescio", "author_id": 14484, "author_profile": "https://Stackoverflow.com/users/14484", "pm_score": 3, "selected": true, "text": "Private WithEvents Winsock1 As Winsock\n" }, { "answer_id": 27361729, "author": "befzz", "author_id": 1079200, "author_profile": "https://Stackoverflow.com/users/1079200", "pm_score": 0, "selected": false, "text": "Dim sock\nSet sock = WScript.CreateObject(\"MSWinsock.Winsock\",\"sock_\")\nsock.RemoteHost = \"www.yandex.com\"\nsock.RemotePort = \"80\"\nsock.Connect\n\nDim received\nreceived = 0\n\nSub sock_Connect()\n WScript.Echo \"[sock] Connection Successful!\"\n sock.SendData \"GET / HTTP/1.1\"& vbCrLf & \"Host: \" & sock.RemoteHost & vbCrLf & vbCrLf\nEnd Sub\n\nSub sock_Close()\n WScript.Echo \"[sock] Connection closed!\"\nEnd Sub\n\nSub sock_DataArrival(Byval b)\n Dim data\n sock.GetData data, vbString\n received = received + b\n WScript.Echo \"---------------------------------------\"\n WScript.Echo \" Bytes received: \" & b & \" ( Total: \" & received & \" )\"\n WScript.Echo \"---------------------------------------\"\n WScript.Echo data\nEnd Sub\n\n'Wait for server close connection\nDo While sock.State <> 8\n rem WScript.Echo sock.State\n WScript.Sleep 1000\nLoop\n cscript /nologo sockhttp.vbs [sock] Connection Successful!\n-------------------------------\n Bytes received: 1376 ( Total: 1376 )\n-------------------------------\nHTTP/1.1 200 Ok\nDate: Mon, 08 Dec 2014 15:41:36 GMT\nContent-Type: text/html; charset=UTF-8\nCache-Control: no-cache,no-store,max-age=0,must-revalidate\nExpires: Mon, 08 Dec 2014 15:41:36 GMT\n...\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/125921", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21530/" ]
125,934
<p>I'm writing an application to start and monitor other applications in C#. I'm using the System.Diagnostics.Process class to start applications and then monitor the applications using the Process.Responding property to poll the state of the application every 100 milisecs. I use Process.CloseMainWindow to stop the application or Process.Kill to kill it if it's not responding.</p> <p>I've noticed a weird behaviour where sometimes the process object gets into a state where the responding property always returns true even when the underlying process hangs in a loop and where it doesn't respond to CloseMainWindow.</p> <p>One way to reproduce it is to poll the Responding property right after starting the process instance. So for example</p> <pre><code>_process.Start(); bool responding = _process.Responding; </code></pre> <p>will reproduce the error state while</p> <pre><code>_process.Start(); Thread.Sleep(1000); bool responding = _process.Responding; </code></pre> <p>will work. Reducing the sleep period to 500 will introduce the error state again.</p> <p>Something in calling _process.Responding too fast after starting seems to prevent the object from getting the right windows message queue handler. I guess I need to wait for _process.Start to finish doing it's asynchronous work. Is there a better way to wait for this than calling Thread.Sleep ? I'm not too confident that the 1000 ms will always be enough.</p>
[ { "answer_id": 126001, "author": "Rob Cooper", "author_id": 832, "author_profile": "https://Stackoverflow.com/users/832", "pm_score": 4, "selected": true, "text": "WaitForInputIdle" }, { "answer_id": 126140, "author": "Mendelt", "author_id": 3320, "author_profile": "https://Stackoverflow.com/users/3320", "pm_score": 2, "selected": false, "text": "_process.Start();\n_process.WaitForInputIdle();\n _process.Start();\nIntPtr mainWindow = _process.MainWindowHandle;\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/125934", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3320/" ]
125,951
<p>What is a good command line tool to create screenshots of websites on Linux? I need to automatically generate screenshots of websites without human interaction. The only tool that I found was <a href="http://khtml2png.sourceforge.net/" rel="noreferrer">khtml2png</a>, but I wonder if there are others that aren't based on khtml (i.e. have good JavaScript support, ...).</p>
[ { "answer_id": 143148, "author": "Shannon Nelson", "author_id": 14450, "author_profile": "https://Stackoverflow.com/users/14450", "pm_score": 7, "selected": true, "text": "--height --width #!/bin/sh\n\n# start a server with a specific DISPLAY\nvncserver :11 -geometry 1024x768\n\n# start firefox in this vnc session\nfirefox --display :11\n\n# read URLs from a data file in a loop\ncount=1\nwhile read url\ndo\n # send URL to the firefox session\n firefox --display :11 $url\n\n # take a picture after waiting a bit for the load to finish\n sleep 5\n import -window root image$count.jpg\n\n count=`expr $count + 1`\ndone < url_list.txt\n\n# clean up when done\nvncserver -kill :11\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/125951", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4936/" ]
125,964
<p>Is there an easier way to step through the code than to start the service through the Windows Service Control Manager and then attaching the debugger to the thread? It's kind of cumbersome and I'm wondering if there is a more straightforward approach.</p>
[ { "answer_id": 125983, "author": "Paul van Brenk", "author_id": 1837197, "author_profile": "https://Stackoverflow.com/users/1837197", "pm_score": 5, "selected": false, "text": "/ConsoleRunner\n /....\n/ServiceRunner\n /....\n/ApplicationLogic\n /....\n" }, { "answer_id": 125995, "author": "Maurice", "author_id": 19676, "author_profile": "https://Stackoverflow.com/users/19676", "pm_score": 2, "selected": false, "text": "static void Main(string[] args) {\n if (Console.In != StreamReader.Null) {\n if (args.Length > 0 && args[0] == \"/console\") {\n // Start your service work.\n }\n }\n}\n" }, { "answer_id": 126016, "author": "jop", "author_id": 11830, "author_profile": "https://Stackoverflow.com/users/11830", "pm_score": 9, "selected": true, "text": "Debugger.Break() #if DEBUG Conditional(\"DEBUG_SERVICE\") [Conditional(\"DEBUG_SERVICE\")]\nprivate static void DebugMode()\n{\n Debugger.Break();\n}\n OnStart public override void OnStart()\n{\n DebugMode();\n /* ... do the rest */\n}\n" }, { "answer_id": 126110, "author": "rohancragg", "author_id": 5351, "author_profile": "https://Stackoverflow.com/users/5351", "pm_score": 4, "selected": false, "text": "using System;\nusing System.Threading;\nusing System.Configuration; \n\npublic class ServiceEventHandler\n{\n Timer _timer;\n public ServiceEventHandler()\n {\n // get configuration etc.\n _timer = new Timer(\n new TimerCallback(EventTimerCallback)\n , null\n , Timeout.Infinite\n , Timeout.Infinite);\n }\n\n private void EventTimerCallback(object state)\n {\n // do something\n }\n\n public void StartEventLoop()\n {\n // wait a minute, then run every 30 minutes\n _timer.Change(TimeSpan.Parse(\"00:01:00\"), TimeSpan.Parse(\"00:30:00\");\n }\n}\n #if DEBUG\nif (!System.Diagnostics.Debugger.IsAttached)\n{\n System.Diagnostics.Debugger.Break();\n}\n#endif\n" }, { "answer_id": 126163, "author": "Christian.K", "author_id": 21567, "author_profile": "https://Stackoverflow.com/users/21567", "pm_score": 8, "selected": false, "text": "public static int Main(string[] args)\n{\n if (!Environment.UserInteractive)\n {\n // Startup as service.\n }\n else\n {\n // Startup as application\n }\n}\n /console Environment.UserInteractive WSF_VISIBLE false" }, { "answer_id": 150855, "author": "Thomas Bratt", "author_id": 15985, "author_profile": "https://Stackoverflow.com/users/15985", "pm_score": 4, "selected": false, "text": "static void Main()\n{\n#if DEBUG\n // Run as interactive exe in debug mode to allow easy\n // debugging.\n\n var service = new MyService();\n service.OnStart(null);\n\n // Sleep the main thread indefinitely while the service code\n // runs in .OnStart\n\n Thread.Sleep(Timeout.Infinite);\n#else\n // Run normally as service in release mode.\n\n ServiceBase[] ServicesToRun;\n ServicesToRun = new ServiceBase[]{ new MyService() };\n ServiceBase.Run(ServicesToRun);\n#endif\n}\n" }, { "answer_id": 313618, "author": "Ervin Ter", "author_id": 34983, "author_profile": "https://Stackoverflow.com/users/34983", "pm_score": 1, "selected": false, "text": "#if DEBUG\n System.Diagnostics.Debugger.Break();\n#endif\n" }, { "answer_id": 795682, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "protected override void OnStart(string[] args)\n{\n if (args.Contains<string>(\"DEBUG_SERVICE\"))\n {\n Debugger.Break();\n }\n ...\n}\n" }, { "answer_id": 6551189, "author": "BitMask777", "author_id": 509891, "author_profile": "https://Stackoverflow.com/users/509891", "pm_score": 3, "selected": false, "text": "MyService MyServiceDebug ServiceBase Program.cs /// <summary>\n /// The main entry point for the application.\n /// </summary>\n static void Main()\n {\n ServiceBase[] ServicesToRun;\n ServicesToRun = new ServiceBase[] \n { \n new MyService(),\n new MyServiceDebug()\n };\n ServiceBase.Run(ServicesToRun);\n }\n" }, { "answer_id": 10838170, "author": "Anders Abel", "author_id": 280222, "author_profile": "https://Stackoverflow.com/users/280222", "pm_score": 7, "selected": false, "text": "OnStart OnStop Environment.Interactive static void Main()\n{\n ServiceBase[] servicesToRun;\n servicesToRun = new ServiceBase[] \n {\n new MyService()\n };\n if (Environment.UserInteractive)\n {\n RunInteractive(servicesToRun);\n }\n else\n {\n ServiceBase.Run(servicesToRun);\n }\n}\n RunInteractive OnStart OnStop static void RunInteractive(ServiceBase[] servicesToRun)\n{\n Console.WriteLine(\"Services running in interactive mode.\");\n Console.WriteLine();\n\n MethodInfo onStartMethod = typeof(ServiceBase).GetMethod(\"OnStart\", \n BindingFlags.Instance | BindingFlags.NonPublic);\n foreach (ServiceBase service in servicesToRun)\n {\n Console.Write(\"Starting {0}...\", service.ServiceName);\n onStartMethod.Invoke(service, new object[] { new string[] { } });\n Console.Write(\"Started\");\n }\n\n Console.WriteLine();\n Console.WriteLine();\n Console.WriteLine(\n \"Press any key to stop the services and end the process...\");\n Console.ReadKey();\n Console.WriteLine();\n\n MethodInfo onStopMethod = typeof(ServiceBase).GetMethod(\"OnStop\", \n BindingFlags.Instance | BindingFlags.NonPublic);\n foreach (ServiceBase service in servicesToRun)\n {\n Console.Write(\"Stopping {0}...\", service.ServiceName);\n onStopMethod.Invoke(service, null);\n Console.WriteLine(\"Stopped\");\n }\n\n Console.WriteLine(\"All services stopped.\");\n // Keep the console alive for a second to allow the user to see the message.\n Thread.Sleep(1000);\n}\n" }, { "answer_id": 12783287, "author": "Matt", "author_id": 1016343, "author_profile": "https://Stackoverflow.com/users/1016343", "pm_score": 6, "selected": false, "text": "#if DEBUG\n base.RequestAdditionalTime(600000); // 600*1000ms = 10 minutes timeout\n Debugger.Launch(); // launch and attach debugger\n#endif\n OnStart protected override void OnStart(string[] args)\n{\n #if DEBUG\n base.RequestAdditionalTime(600000); // 10 minutes timeout for startup\n Debugger.Launch(); // launch and attach debugger\n #endif\n MyInitOnstart(); // my individual initialization code for the service\n // allow the base class to perform any work it needs to do\n base.OnStart(args);\n}\n InstallUtil Debugger.Launch Debugger.Launch MyInitOnStart Debugger.Launch() Debugger.Break() RequestAdditionalTime Debugger.Launch base.Onstart(args)" }, { "answer_id": 17038801, "author": "Misterhex", "author_id": 1610747, "author_profile": "https://Stackoverflow.com/users/1610747", "pm_score": 3, "selected": false, "text": "class Program\n {\n static void Main(string[] args)\n {\n HostFactory.Run(x =>\n {\n\n // setup service start and stop.\n x.Service<Controller>(s =>\n {\n s.ConstructUsing(name => new Controller());\n s.WhenStarted(controller => controller.Start());\n s.WhenStopped(controller => controller.Stop());\n });\n\n // setup recovery here\n x.EnableServiceRecovery(rc =>\n {\n rc.RestartService(delayInMinutes: 0);\n rc.SetResetPeriod(days: 0);\n });\n\n x.RunAsLocalSystem();\n });\n }\n}\n\npublic class Controller\n {\n public void Start()\n {\n\n }\n\n public void Stop()\n {\n\n }\n }\n" }, { "answer_id": 18728886, "author": "Jason Miller", "author_id": 1543423, "author_profile": "https://Stackoverflow.com/users/1543423", "pm_score": 5, "selected": false, "text": "namespace YourNamespace\n{\n static class Program\n {\n /// <summary>\n /// The main entry point for the application.\n /// </summary>\n static void Main()\n {\n#if DEBUG\n Service1 myService = new Service1();\n myService.OnDebug();\n System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);\n#else\n ServiceBase[] ServicesToRun;\n ServicesToRun = new ServiceBase[]\n {\n new Service1()\n };\n ServiceBase.Run(ServicesToRun);\n#endif\n\n }\n }\n}\n public Service1()\n {\n InitializeComponent();\n }\n\n public void OnDebug()\n {\n OnStart(null);\n }\n\n protected override void OnStart(string[] args)\n {\n // your code to do something\n }\n\n protected override void OnStop()\n {\n }\n public void OnDebug() OnStart(string[] args) void Main() #if #DEBUG DEBUG Service1 myService = new Service1();\nmyService.OnDebug();\nSystem.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);\n Release else" }, { "answer_id": 35715389, "author": "wotanii", "author_id": 5132456, "author_profile": "https://Stackoverflow.com/users/5132456", "pm_score": 1, "selected": false, "text": "#if DEBUG\n Debugger.Launch();\n#endif\n reg add \"HKCR\\AppID{E62A7A31-6025-408E-87F6-81AEB0DC9347}\" /v AppIDFlags /t REG_DWORD /d 8 /f\n" }, { "answer_id": 41464830, "author": "MisterDr", "author_id": 1895206, "author_profile": "https://Stackoverflow.com/users/1895206", "pm_score": 2, "selected": false, "text": "[TestMethod]\npublic void TestMyService()\n{\n MyService fs = new MyService();\n\n var OnStart = fs.GetType().BaseType.GetMethod(\"OnStart\", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);\n\n OnStart.Invoke(fs, new object[] { null });\n}\n\n// As an extension method\npublic static void Start(this ServiceBase service, List<string> parameters)\n{\n string[] par = parameters == null ? null : parameters.ToArray();\n\n var OnStart = service.GetType().GetMethod(\"OnStart\", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);\n\n OnStart.Invoke(service, new object[] { par });\n}\n" }, { "answer_id": 42830685, "author": "Chutipong Roobklom", "author_id": 4896926, "author_profile": "https://Stackoverflow.com/users/4896926", "pm_score": 0, "selected": false, "text": "Debugger.Break();\n internal static class Program\n{\n /// <summary>\n /// The main entry point for the application.\n /// </summary>\n private static void Main()\n {\n Debugger.Break();\n ServiceBase[] ServicesToRun;\n ServicesToRun = new ServiceBase[]\n {\n new Service1()\n };\n ServiceBase.Run(ServicesToRun);\n }\n}\n Debugger.Break();" }, { "answer_id": 49274260, "author": "Mansoor", "author_id": 4240382, "author_profile": "https://Stackoverflow.com/users/4240382", "pm_score": 1, "selected": false, "text": "static class Program\n{\n static void Main()\n {\n #if DEBUG\n\n // TODO: Add code to start application here\n\n // //If the mode is in debugging\n // //create a new service instance\n Service1 myService = new Service1();\n\n // //call the start method - this will start the Timer.\n myService.Start();\n\n // //Set the Thread to sleep\n Thread.Sleep(300000);\n\n // //Call the Stop method-this will stop the Timer.\n myService.Stop();\n\n #else\n ServiceBase[] ServicesToRun;\n ServicesToRun = new ServiceBase[] \n { \n new Service1() \n };\n\n ServiceBase.Run(ServicesToRun);\n #endif\n }\n}\n" }, { "answer_id": 49314576, "author": "Amey P Naik", "author_id": 3754966, "author_profile": "https://Stackoverflow.com/users/3754966", "pm_score": 0, "selected": false, "text": "#if DEBUG // for debug mode\n **Debugger.Launch();** //debugger will hit here\n foreach (var job in JobFactory.GetJobs())\n {\n //do something \n }\n\n#else // for release mode\n **Debugger.Launch();** //debugger will hit here\n // write code here to do something in Release mode.\n\n#endif\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/125964", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16440/" ]
125,997
<p>I'm a newbie in C# bu I'm experienced Delphi developer. In Delphi I can use same code for MenuItem and ToolButton using TAction.OnExecute event and I can disable/enable MenuItem and ToolButton together using TAction.OnUpdate event. Is there a similar way to do this in C# without using external libraries? Or more - How C# developers share code between different controls? </p> <hr> <p>Ok, may be I write my question in wrong way. I want to know not witch property to use (I know about Enabled property) but I want to know on witch event I should attach to if I want to enable/disable more than one control. In delphi TAction.OnUpdate event ocurs when Application is idle - is there similar event in C#?</p>
[ { "answer_id": 127214, "author": "Michael Meadows", "author_id": 7643, "author_profile": "https://Stackoverflow.com/users/7643", "pm_score": 1, "selected": false, "text": "public abstract class ToolStripItemCommand\n{\n private bool enabled = true;\n private bool visible = true;\n private readonly List<ToolStripItem> controls;\n\n protected ToolStripItemCommand()\n {\n controls = new List<ToolStripItem>();\n }\n\n public void RegisterControl(ToolStripItem item, string eventName)\n {\n item.Click += delegate { Execute(); };\n controls.Add(item);\n }\n\n public bool Enabled\n {\n get { return enabled; }\n set\n {\n enabled = value;\n foreach (ToolStripItem item in controls)\n item.Enabled = value;\n }\n }\n\n public bool Visible\n {\n get { return visible; }\n set\n {\n visible = value;\n foreach (ToolStripItem item in controls)\n item.Visible = value;\n }\n }\n\n protected abstract void Execute();\n}\n private ToolStripItemCommand fooCommand;\n\nprivate void wireUpCommands()\n{\n fooCommand = new HelloWorldCommand();\n fooCommand.RegisterControl(fooToolStripMenuItem, \"Click\");\n fooCommand.RegisterControl(fooToolStripButton, \"Click\"); \n}\n\nprivate void toggleEnabledClicked(object sender, EventArgs e)\n{\n fooCommand.Enabled = !fooCommand.Enabled;\n}\n\nprivate void toggleVisibleClicked(object sender, EventArgs e)\n{\n fooCommand.Visible = !fooCommand.Visible;\n}\n public class HelloWorldCommand : ToolStripItemCommand\n{\n #region Overrides of ControlCommand\n protected override void Execute()\n {\n MessageBox.Show(\"Hello World\");\n }\n #endregion\n}\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/125997", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21540/" ]
126,002
<p>I need to find out what ports are attached to which processes on a Unix machine (HP Itanium). Unfortunately, <code>lsof</code> is not installed and I have no way of installing it. </p> <p>Does anyone know an alternative method? A fairly lengthy Googling session hasn't turned up anything.</p>
[ { "answer_id": 126014, "author": "dogbane", "author_id": 7412, "author_profile": "https://Stackoverflow.com/users/7412", "pm_score": 2, "selected": false, "text": "pfiles PID" }, { "answer_id": 126026, "author": "lms", "author_id": 21359, "author_profile": "https://Stackoverflow.com/users/21359", "pm_score": 5, "selected": false, "text": "netstat -putan or lsof | grep TCP lsof | grep TCP lsof" }, { "answer_id": 126039, "author": "Sergey Stolyarov", "author_id": 15958, "author_profile": "https://Stackoverflow.com/users/15958", "pm_score": 4, "selected": false, "text": "netstat -pln\n" }, { "answer_id": 126062, "author": "tzot", "author_id": 6899, "author_profile": "https://Stackoverflow.com/users/6899", "pm_score": 3, "selected": false, "text": "netstat -ln | awk '/^(tcp|udp)/ { split($4, a, /:/); print $1, a[2]}' | sort -u\n fuser -n tcp fuser -n udp fuser" }, { "answer_id": 54462787, "author": "Linden X. Quan", "author_id": 8820559, "author_profile": "https://Stackoverflow.com/users/8820559", "pm_score": 2, "selected": false, "text": "netstat -tulpn | grep LISTEN\n" }, { "answer_id": 55114623, "author": "YAP", "author_id": 8227514, "author_profile": "https://Stackoverflow.com/users/8227514", "pm_score": 0, "selected": false, "text": " netstat -tulpn\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126002", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21544/" ]
126,005
<p>Specifically I have a PHP command-line script that at a certain point requires input from the user. I would like to be able to execute an external editor (such as vi), and wait for the editor to finish execution before resuming the script.</p> <p>My basic idea was to use a temporary file to do the editing in, and to retrieve the contents of the file afterwards. Something along the lines of:</p> <pre><code>$filename = '/tmp/script_' . time() . '.tmp'; get_user_input ($filename); $input = file_get_contents ($filename); unlink ($filename); </code></pre> <p>I suspect that this isn't possible from a PHP command-line script, however I'm hoping that there's some sort of shell scripting trick that can be employed to achieve the same effect.</p> <p>Suggestions for how this can be achieved in other scripting languages are also more than welcome.</p>
[ { "answer_id": 126031, "author": "lms", "author_id": 21359, "author_profile": "https://Stackoverflow.com/users/21359", "pm_score": 0, "selected": false, "text": "system('vi');\n" }, { "answer_id": 126037, "author": "Seldaek", "author_id": 6512, "author_profile": "https://Stackoverflow.com/users/6512", "pm_score": 2, "selected": false, "text": "exec() <?php\n\nexec('notepad c:\\test'); \necho file_get_contents('c:\\test');\n\n?>\n\n$ php -r test.php\n exec('nano test'); echo file_get_contents('test');" }, { "answer_id": 126648, "author": "Seldaek", "author_id": 6512, "author_profile": "https://Stackoverflow.com/users/6512", "pm_score": 0, "selected": false, "text": "<?php\n\n$out = fopen('php://stdout', 'w+');\n$in = fopen('php://stdin', 'r+');\n\nfwrite($out, \"foo?\\n\");\n$var = fread($in, 1024);\necho strtoupper($var);\n $ php test.php\nfoo?\nbar <= my input\nBAR\n" }, { "answer_id": 130049, "author": "Ole Helgesen", "author_id": 21892, "author_profile": "https://Stackoverflow.com/users/21892", "pm_score": 4, "selected": true, "text": "system(\"vim > `tty`\");\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126005", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10942/" ]
126,012
<p>I have a stored procedure in SQL 2005. The Stored Procedure is actually creating temporary tables in the beginning of SP and deleting it in the end. I am now debugging the SP in VS 2005. In between the SP i would want to know the contents into the temporary table. Can anybody help in in viewing the contents of the temporary table at run time.</p> <p>Thanks Vinod T</p>
[ { "answer_id": 126040, "author": "Ilya Kochetov", "author_id": 15329, "author_profile": "https://Stackoverflow.com/users/15329", "pm_score": 5, "selected": true, "text": "@table #table ##table" }, { "answer_id": 126060, "author": "Vinod", "author_id": 20951, "author_profile": "https://Stackoverflow.com/users/20951", "pm_score": 1, "selected": false, "text": "SELECT * FROM #Name\n\nUSE [TEMPDB]\nGO\n\nSELECT * FROM syscolumns \n WHERE id = ( SELECT id FROM sysobjects WHERE [Name] LIKE '#Name%')\n" }, { "answer_id": 126112, "author": "Luke Bennett", "author_id": 17602, "author_profile": "https://Stackoverflow.com/users/17602", "pm_score": 1, "selected": false, "text": "-- Get rid of the table if it already exists\nif object_id('TempData') is not null\n drop table TempData\n\nselect * into TempData from #TempTable\n" }, { "answer_id": 5732157, "author": "Filip De Vos", "author_id": 619960, "author_profile": "https://Stackoverflow.com/users/619960", "pm_score": 3, "selected": false, "text": "exec sp_select 'tempdb..#temp'" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126012", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20951/" ]
126,028
<p>We have a 3D viewer that uses OpenGL, but our clients sometimes complain about it "not working". We suspect that most of these issues stem from them trying to use, what is in effect a modern 3d realtime game, on a businiss laptop computer.</p> <p><strong>How can we, in the windows msi installer we use, check for support for openGL?</strong></p> <p>And as a side note, if you can answer "List of OpenGL supported graphic cards?", that would also be greate. Strange that google doesnt help here..</p>
[ { "answer_id": 126553, "author": "NeARAZ", "author_id": 6799, "author_profile": "https://Stackoverflow.com/users/6799", "pm_score": 4, "selected": true, "text": "// setup minimal required GL\nHWND wnd = CreateWindow(\n \"STATIC\",\n \"GL\",\n WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,\n 0, 0, 16, 16,\n NULL, NULL,\n AfxGetInstanceHandle(), NULL );\nHDC dc = GetDC( wnd );\n\nPIXELFORMATDESCRIPTOR pfd = {\n sizeof(PIXELFORMATDESCRIPTOR), 1,\n PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL,\n PFD_TYPE_RGBA, 32,\n 0, 0, 0, 0, 0, 0,\n 0, 0, 0, 0, 0, 0, 0,\n 16, 0,\n 0, PFD_MAIN_PLANE, 0, 0, 0, 0\n};\n\nint fmt = ChoosePixelFormat( dc, &pfd );\nSetPixelFormat( dc, fmt, &pfd );\n\nHGLRC rc = wglCreateContext( dc );\nwglMakeCurrent( dc, rc );\n\n// get information\nconst char* vendor = (const char*)glGetString(GL_VENDOR);\nconst char* renderer = (const char*)glGetString(GL_RENDERER);\nconst char* extensions = (const char*)glGetString(GL_EXTENSIONS);\nconst char* version = (const char*)glGetString(GL_VERSION);\n\n// DO SOMETHING WITH THOSE STRINGS HERE!\n\n// cleanup\nwglDeleteContext( rc );\nReleaseDC( wnd, dc );\nDestroyWindow( wnd );\n" }, { "answer_id": 137959, "author": "Ashwin Nanjappa", "author_id": 1630, "author_profile": "https://Stackoverflow.com/users/1630", "pm_score": 1, "selected": false, "text": "if (GLEW_OK != glewInit())\n{\n // GLEW failed!\n exit(1);\n}\n\n// Check if required extensions are supported\nif (!GLEW_ARB_occlusion_query)\n cout << \"Occlusion query not supported\" << endl;\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126028", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4013/" ]
126,036
<p>Is there a way to know and output the stack size needed by a function at compile time in C ? Here is what I would like to know :</p> <p>Let's take some function :</p> <pre><code>void foo(int a) { char c[5]; char * s; //do something return; } </code></pre> <p>When compiling this function, I would like to know how much stack space it will consume whent it is called. This might be useful to detect the on stack declaration of a structure hiding a big buffer.</p> <p>I am looking for something that would print something like this :</p> <p>file foo.c : function foo stack usage is <code>n</code> bytes</p> <p>Is there a way not to look at the generated assembly to know that ? Or a limit that can be set for the compiler ?</p> <p>Update : I am not trying to avoid runtime stack overflow for a given process, I am looking for a way to find before runtime, if a function stack usage, as determined by the compiler, is available as an output of the compilation process.</p> <p>Let's put it another way : is it possible to know the size of all the objects local to a function ? I guess compiler optimization won't be my friend, because some variable will disappear but a superior limit is fine.</p>
[ { "answer_id": 126047, "author": "1800 INFORMATION", "author_id": 3146, "author_profile": "https://Stackoverflow.com/users/3146", "pm_score": 1, "selected": false, "text": "alloca" }, { "answer_id": 126490, "author": "shodanex", "author_id": 11589, "author_profile": "https://Stackoverflow.com/users/11589", "pm_score": 3, "selected": false, "text": "* The name of the function.\n* A number of bytes.\n* One or more qualifiers: static, dynamic, bounded. \n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126036", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11589/" ]
126,044
<p>I just got Delphi 2009 and have previously read some articles about modifications that might be necessary because of the switch to Unicode strings. Mostly, it is mentioned that sizeof(char) is not guaranteed to be 1 anymore. But why would this be interesting regarding string manipulation?</p> <p>For example, if I use an AnsiString:='Test' and do the same with a String (which is unicode now), then I get Length() = 4 which is correct for both cases. Without having tested it, I'm sure all other string manipulation functions behave the same way and decide internally if the argument is a unicode string or anything else.</p> <p>Why would the actual size of a char be of interest for me if I do string manipulations? (Of course if I use strings as strings and not to store any other data)</p> <p>Thanks for any help! Holger</p>
[ { "answer_id": 126079, "author": "Loesje", "author_id": 17559, "author_profile": "https://Stackoverflow.com/users/17559", "pm_score": 1, "selected": false, "text": "var p : pchar;\nbegin\n p := s[1];\n for i := 0 to length(string)-1 do\n begin\n write(p);\n inc(p);\n end; \nend;\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126044", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5015/" ]
126,048
<p>I have a problem where a Web Application needs to (after interaction from the user via Javascript)<br> &nbsp;&nbsp; 1) open a Windows Forms Application<br> &nbsp;&nbsp; 2) send a parameter to the app (e.g. an ID)</p> <p>Correspondingly, the Windows Forms Application should be able to<br> &nbsp;&nbsp; 1) send parameters back to the Web Application (updating the URL is ok)<br> &nbsp;&nbsp; 2) open the Web App in a new brower, if it does not exist<br> If many browser windows are open it's important that the correct one is updated.</p> <p>Windows Forms Application is in ASP.NET<br> Browser is IE6+<br> The applications are controlled and internal for a specific organisation so it's not a question of launching a custom app. </p> <p>Question A) Is this possible?<br> Question B) How do I send parameters to an open Windows Forms Application from a Web App?<br> Question C) If updating the Web App, how do I make sure the right browser is targeted? </p>
[ { "answer_id": 126067, "author": "Ilya Kochetov", "author_id": 15329, "author_profile": "https://Stackoverflow.com/users/15329", "pm_score": 3, "selected": false, "text": "System.Diagnostics.Process.Start(\"http://example.com?key=value\");\n" }, { "answer_id": 136740, "author": "Kevin Lamb", "author_id": 3149, "author_profile": "https://Stackoverflow.com/users/3149", "pm_score": 0, "selected": false, "text": "System.Diagnostics.Process.Start(\"c:\\ie6\\ie6.exe http://www.example.com/mypage\");\n" }, { "answer_id": 152839, "author": "Bruce", "author_id": 21552, "author_profile": "https://Stackoverflow.com/users/21552", "pm_score": 0, "selected": false, "text": "<script type=\"text/vbscript\" language=\"vbscript\">\n <!--\n Function OpenWinformApp(chSocialSecurityNumber)\n Dim oWinformAppWebStart\n Set oWinformAppWebStart = CreateObject(\"WinformAppWebStart.CWinformAppWebStart\")\n oWinformAppWebStart.OpenPersonForm CStr(chSocialSecurityNumber)\n End Function\n -->\n </script>" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126048", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21552/" ]
126,068
<p>I'm building a public website which has its own domain name with pop/smtp mail services. I'm considering giving users the option to update their data via email - something similar to the functionality found in Flickr or Blogger where you email posts to a special email address. The email data is then processed and stored in the underlying database for the website.</p> <p>I'm using ASP.NET and SQL Server and using a shared hosting service. Any ideas how one would implement this, or if it's even possible using shared hosting?</p> <p>Thanks</p>
[ { "answer_id": 126375, "author": "Espo", "author_id": 2257, "author_profile": "https://Stackoverflow.com/users/2257", "pm_score": 2, "selected": false, "text": "username@domain.com username-randomnumer@domain.com" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126068", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18655/" ]
126,070
<p>I have an email subject of the form:</p> <pre><code>=?utf-8?B?T3.....?= </code></pre> <p>The body of the email is utf-8 base64 encoded - and has decoded fine. I am current using Perl's Email::MIME module to decode the email.</p> <p>What is the meaning of the =?utf-8 delimiter and how do I extract information from this string?</p>
[ { "answer_id": 126087, "author": "1800 INFORMATION", "author_id": 3146, "author_profile": "https://Stackoverflow.com/users/3146", "pm_score": 6, "selected": true, "text": "encoded-word =?<charset>?<encoding>?<data>?=\n B Q use Encode qw/encode decode/;\n$utf8 = decode('MIME-Header', $header);\n$header = encode('MIME-Header', $utf8);\n decode() encode() \nMIME-Header Both B and Q =?UTF-8?B?....?= \nMIME-B B only; Q croaks =?UTF-8?B?....?= \nMIME-Q Q only; B croaks =?UTF-8?Q?....?=\n" }, { "answer_id": 126103, "author": "moritz", "author_id": 14132, "author_profile": "https://Stackoverflow.com/users/14132", "pm_score": 4, "selected": false, "text": "MIME-Header use Encode qw(decode);\nmy $decoded = decode(\"MIME-Header\", $encoded);\n" }, { "answer_id": 21923828, "author": "Philonious", "author_id": 3335339, "author_profile": "https://Stackoverflow.com/users/3335339", "pm_score": 2, "selected": false, "text": "use MIME::Words qw(:all);\n$decoded = decode_mimewords(\n 'To: =?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?= <keld@dkuug.dk>',\n);\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126070", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21553/" ]
126,094
<p>Considering that the debug data file is available (PDB) and by using either <strong>System.Reflection</strong> or another similar framework such as <strong>Mono.Cecil</strong>, how to retrieve programmatically the source file name and the line number where a type or a member of a type is declared.</p> <p>For example, let's say you have compiled this file into an assembly:</p> <p><em>C:\MyProject\Foo.cs</em></p> <pre><code>1: public class Foo 2: { 3: public string SayHello() 4: { 5: return "Hello"; 6: } 7: } </code></pre> <p>How to do something like:</p> <pre><code>MethodInfo methodInfo = typeof(Foo).GetMethod("SayHello"); string sourceFileName = methodInfo.GetSourceFile(); // ?? Does not exist! int sourceLineNumber = methodInfo.GetLineNumber(); // ?? Does not exist! </code></pre> <p>sourceFileName would contain "C:\MyProject\Foo.cs" and sourceLineNumber be equal to 3.</p> <p><em>Update: <code>System.Diagnostics.StackFrame</code> is indeed able to get that information, but only in the scope of current executing call stack. It means that the method must be invoked first. I would like to get the same info, but without invoking the type member.</em></p>
[ { "answer_id": 126132, "author": "Richard", "author_id": 20038, "author_profile": "https://Stackoverflow.com/users/20038", "pm_score": -1, "selected": false, "text": "Dim CurrentStack As System.Diagnostics.StackTrace\nMsgBox (CurrentStack.GetFrame(0).GetFileLineNumber)\n Public Function MeAndMyCaller As String\n Dim CurrentStack As New System.Diagnostics.StackTrace\n Dim Myself As String = CurrentStack.GetFrame(0).GetMethod.Name\n Dim MyCaller As String = CurrentStack.GetFrame(1).GetMethod.Name\n Return \"In \" & Myself & vbCrLf & \"Called by \" & MyCaller\nEnd Function\n" }, { "answer_id": 16295971, "author": "illegal-immigrant", "author_id": 407443, "author_profile": "https://Stackoverflow.com/users/407443", "pm_score": 3, "selected": false, "text": "private static void Log(string text,\n [CallerFilePath] string file = \"\",\n [CallerMemberName] string member = \"\",\n [CallerLineNumber] int line = 0)\n{\n Console.WriteLine(\"{0}_{1}({2}): {3}\", Path.GetFileName(file), member, line, text);\n}\n Framework API" }, { "answer_id": 26431841, "author": "Harald Hoyer", "author_id": 805390, "author_profile": "https://Stackoverflow.com/users/805390", "pm_score": 2, "selected": false, "text": "sealed class ProvideSourceLocation : Attribute\n {\n public readonly string File;\n public readonly string Member;\n public readonly int Line;\n public ProvideSourceLocation\n (\n [CallerFilePath] string file = \"\",\n [CallerMemberName] string member = \"\",\n [CallerLineNumber] int line = 0)\n {\n File = file;\n Member = member;\n Line = line;\n }\n\n public override string ToString() { return File + \"(\" + Line + \"):\" + Member; }\n }\n\n\n[ProvideSourceLocation]\nclass Test\n{\n ...\n}\n Console.WriteLine(typeof(Test).GetCustomAttribute<ProvideSourceLocation>(true));\n a:\\develop\\HWClassLibrary.cs\\src\\Tester\\Program.cs(65):\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126094", "https://Stackoverflow.com", "https://Stackoverflow.com/users/563/" ]
126,100
<p>What's the fastest way to count the number of keys/properties of an object? Is it possible to do this without iterating over the object? I.e., without doing:</p> <pre><code>var count = 0; for (k in myobj) if (myobj.hasOwnProperty(k)) ++count; </code></pre> <p>(Firefox did provide a magic <code>__count__</code> property, but this was removed somewhere around version 4.)</p>
[ { "answer_id": 126151, "author": "Confusion", "author_id": 16784, "author_profile": "https://Stackoverflow.com/users/16784", "pm_score": 5, "selected": false, "text": "getNumberOfProperties(object)" }, { "answer_id": 126157, "author": "Luke Bennett", "author_id": 17602, "author_profile": "https://Stackoverflow.com/users/17602", "pm_score": 4, "selected": false, "text": "__count__ if (myobj.__count__ === undefined) {\n myobj.__count__ = ...\n}\n __count__ if (myobj.__count__ === undefined) {\n myobj.__count__ = function() { return ... }\n myobj.__count__.toString = function() { return this(); }\n}\n __count__" }, { "answer_id": 4889658, "author": "Avi Flax", "author_id": 7012, "author_profile": "https://Stackoverflow.com/users/7012", "pm_score": 13, "selected": true, "text": "Object.keys(obj).length\n" }, { "answer_id": 5675579, "author": "Renaat De Muynck", "author_id": 288264, "author_profile": "https://Stackoverflow.com/users/288264", "pm_score": 7, "selected": false, "text": "if (!Object.keys) {\n Object.keys = function (obj) {\n var keys = [],\n k;\n for (k in obj) {\n if (Object.prototype.hasOwnProperty.call(obj, k)) {\n keys.push(k);\n }\n }\n return keys;\n };\n}\n var len = Object.keys(obj).length;\n" }, { "answer_id": 6019605, "author": "studgeek", "author_id": 255961, "author_profile": "https://Stackoverflow.com/users/255961", "pm_score": 7, "selected": false, "text": "_.size(obj)\n _.keys(obj).length\n" }, { "answer_id": 6504767, "author": "Ali", "author_id": 49153, "author_profile": "https://Stackoverflow.com/users/49153", "pm_score": 3, "selected": false, "text": "function BasicList()\n{\n var items = {};\n this.count = 0;\n\n this.add = function(index, item)\n {\n items[index] = item;\n this.count++;\n }\n\n this.remove = function (index)\n {\n delete items[index];\n this.count--;\n }\n\n this.get = function(index)\n {\n if (undefined === index)\n return items;\n else\n return items[index];\n }\n}\n" }, { "answer_id": 8724297, "author": "hakunin", "author_id": 517529, "author_profile": "https://Stackoverflow.com/users/517529", "pm_score": 3, "selected": false, "text": "_({a:'', b:''}).size() // => 2\n _.size({a:'', b:''}) // => 2\n" }, { "answer_id": 10119408, "author": "Mark Rhodes", "author_id": 509619, "author_profile": "https://Stackoverflow.com/users/509619", "pm_score": 2, "selected": false, "text": "Ext.Object.getSize(myobj);\n" }, { "answer_id": 12232776, "author": "codejoecode", "author_id": 1641237, "author_profile": "https://Stackoverflow.com/users/1641237", "pm_score": -1, "selected": false, "text": "$(Object.Item).length\n" }, { "answer_id": 14377849, "author": "BenderTheOffender", "author_id": 1047014, "author_profile": "https://Stackoverflow.com/users/1047014", "pm_score": 4, "selected": false, "text": "Object.keys(obj).length\n Object.getOwnPropertyNames var myObject = new Object();\n\nObject.defineProperty(myObject, \"nonEnumerableProp\", {\n enumerable: false\n});\nObject.defineProperty(myObject, \"enumerableProp\", {\n enumerable: true\n});\n\nconsole.log(Object.getOwnPropertyNames(myObject).length); //outputs 2\nconsole.log(Object.keys(myObject).length); //outputs 1\n\nconsole.log(myObject.hasOwnProperty(\"nonEnumerableProp\")); //outputs true\nconsole.log(myObject.hasOwnProperty(\"enumerableProp\")); //outputs true\n\nconsole.log(\"nonEnumerableProp\" in myObject); //outputs true\nconsole.log(\"enumerableProp\" in myObject); //outputs true\n Object.keys" }, { "answer_id": 16763915, "author": "Luc125", "author_id": 746757, "author_profile": "https://Stackoverflow.com/users/746757", "pm_score": 7, "selected": false, "text": "Object Object Object.keys(obj).length; Object.keys .hasOwnProperty() .hasOwnProperty() Object.prototype k var k ++count var count = 0;\nfor (var k in myobj) if (myobj.hasOwnProperty(k)) ++count;\n hasOwnProperty var hasOwn = Object.prototype.hasOwnProperty;\nvar count = 0;\nfor (var k in myobj) if (hasOwn.call(myobj, k)) ++count;\n" }, { "answer_id": 22739088, "author": "Belldandu", "author_id": 3271268, "author_profile": "https://Stackoverflow.com/users/3271268", "pm_score": 4, "selected": false, "text": "obj = {\"lol\": \"what\", owo: \"pfft\"};\nObject.keys(obj).length; // should be 2\n arr = [];\nobj = {\"lol\": \"what\", owo: \"pfft\"};\nobj.omg = function(){\n _.each(obj, function(a){\n arr.push(a);\n });\n};\nObject.keys(obj).length; // should be 3 because it looks like this\n/* obj === {\"lol\": \"what\", owo: \"pfft\", omg: function(){_.each(obj, function(a){arr.push(a);});}} */\n Object.keys(obj).length _ _.size(obj)" }, { "answer_id": 32131981, "author": "lepe", "author_id": 196507, "author_profile": "https://Stackoverflow.com/users/196507", "pm_score": 3, "selected": false, "text": "Object.defineProperty(Object.prototype, \"length\", {\n enumerable: false,\n get: function() {\n return Object.keys(this).length;\n }\n});\n var myObj = {};\nObject.defineProperty(myObj, \"length\", {\n enumerable: false,\n get: function() {\n return Object.keys(this).length;\n }\n});\n var myObj = {};\nmyObj.name = \"John Doe\";\nmyObj.email = \"leaked@example.com\";\nmyObj.length; // Output: 2\n for(var i in myObj) {\n console.log(i + \": \" + myObj[i]);\n}\n name: John Doe\nemail: leaked@example.com\n" }, { "answer_id": 48337446, "author": "Flavien Volken", "author_id": 532695, "author_profile": "https://Stackoverflow.com/users/532695", "pm_score": 5, "selected": false, "text": "Object.keys(obj).length const map = new Map();\nmap.set(\"key\", \"value\");\nmap.size; // THE fastest way\n" }, { "answer_id": 49023825, "author": "Fayaz", "author_id": 8301207, "author_profile": "https://Stackoverflow.com/users/8301207", "pm_score": 2, "selected": false, "text": "Object.keys(objectName).length; \n Object.values(objectName).length;\n" }, { "answer_id": 49831635, "author": "Taquatech", "author_id": 9540188, "author_profile": "https://Stackoverflow.com/users/9540188", "pm_score": -1, "selected": false, "text": "Object.defineProperty(Object.prototype,\n \"length\",\n {\n get() {\n if (!Object.keys) {\n Object.keys = function (obj) {\n var keys = [],k;\n for (k in obj) {\n if (Object.prototype.hasOwnProperty.call(obj, k)) {\n keys.push(k);\n }\n }\n return keys;\n };\n }\n return Object.keys(this).length;\n },});\n\nconsole.log({\"Name\":\"Joe\", \"Age\":26}.length) // Returns 2\n" }, { "answer_id": 56712818, "author": "Robert Sinclair", "author_id": 1907888, "author_profile": "https://Stackoverflow.com/users/1907888", "pm_score": 1, "selected": false, "text": "buttons = document.querySelectorAll('[id=button)) {\nconsole.log('Found ' + buttons.length + ' on the screen');\n" }, { "answer_id": 58492580, "author": "Steve Cooper", "author_id": 6722, "author_profile": "https://Stackoverflow.com/users/6722", "pm_score": 6, "selected": false, "text": "return Object.keys(objectToRead).length;\n let size=0;\nfor(let k in objectToRead) {\n size++\n}\nreturn size;\n return mapToRead.size;\n" }, { "answer_id": 70914677, "author": "dazzafact", "author_id": 1163485, "author_profile": "https://Stackoverflow.com/users/1163485", "pm_score": 4, "selected": false, "text": "//count objects/arrays\nfunction count(obj){\n return Object.keys(obj).length\n }\n function count(obj){\n var x=0;\n for(k in obj){\n x++;\n }\n return x;\n }\n function count(obj){\n if (typeof (obj) === 'string' || obj instanceof String)\n {\n return obj.length; \n }\n return Object.keys(obj).length\n }\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126100", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11543/" ]
126,109
<p>I defined a record named <code>log</code>. I want to create an mnesia table with name <code>log_table</code>. When I try to write a record to table, I get <code>bad_type</code> error as follows:</p> <pre><code>(node1@kitt)4&gt; mnesia:create_table(log_table, [{ram_copies, [node()]}, {attributes, record_info(fields, log)}]). {atomic,ok} (node1@kitt)5&gt; mnesia:dirty_write(log_table, #log{id="hebelek"}). ** exception exit: {aborted,{bad_type,#log{id = "hebelek"}}} in function mnesia:abort/1 </code></pre> <p>What am I missing?</p>
[ { "answer_id": 126223, "author": "Haldun", "author_id": 21000, "author_profile": "https://Stackoverflow.com/users/21000", "pm_score": 2, "selected": false, "text": "mnesia:create_table mnesia:create_table(log_table, [{ram_copies, [node()]},\n {record_name, log},\n {attributes, record_info(fields, log)}]).\n" }, { "answer_id": 126930, "author": "Adam Lindberg", "author_id": 2457, "author_profile": "https://Stackoverflow.com/users/2457", "pm_score": 4, "selected": true, "text": "log {record_name, log} mnesia:write/1" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126109", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21000/" ]
126,114
<p><strong>Problem</strong>. I need a way to find Starteam server time through Starteam Java SDK 8.0. Version of server is 8.0.172 so method <code>Server.getCurrentTime()</code> is not available since it was added only in server version 9.0.</p> <p><strong>Motivation</strong>. My application needs to use views at specific dates. So if there's some difference in system time between client (where the app is running) and server then obtained views are not accurate. In the worst case the client's requested date is in the future for server so the operation results in exception.</p>
[ { "answer_id": 126516, "author": "Ioannis", "author_id": 20428, "author_profile": "https://Stackoverflow.com/users/20428", "pm_score": -1, "selected": false, "text": "<stab_in_the_dark> </stab_in_the_dark>" }, { "answer_id": 127671, "author": "wheleph", "author_id": 15647, "author_profile": "https://Stackoverflow.com/users/15647", "pm_score": 3, "selected": true, "text": "public Date getCurrentServerTime() {\n Folder rootFolder = project.getDefaultView().getRootFolder();\n\n Topic newItem = (Topic) Item.createItem(project.getTypeNames().TOPIC, rootFolder);\n newItem.update();\n newItem.remove();\n newItem.update();\n return newItem.getCreatedTime().createDate();\n}\n" }, { "answer_id": 244496, "author": "Doug Porter", "author_id": 4311, "author_profile": "https://Stackoverflow.com/users/4311", "pm_score": 1, "selected": false, "text": "net time \\\\my_starteam_server_machine_name\n \"Current time at \\\\my_starteam_server_machine_name is 10/28/2008 2:19 PM\"\n\n\"The command completed successfully.\"\n" }, { "answer_id": 732149, "author": "Jeremy Murray", "author_id": 88834, "author_profile": "https://Stackoverflow.com/users/88834", "pm_score": 1, "selected": false, "text": " static void Main(string[] args)\n {\n // ServerTime replacement for pre-2006 StarTeam servers.\n // Picks a date in the future.\n // Gets a view, sets the configuration to the date, and tries to get a property from the root folder.\n // If it cannot retrieve the property, the date is too far in the future. Roll back the date to an earlier time.\n\n DateTime StartTime = DateTime.Now;\n\n Server s = new Server(\"serverAddress\", 49201);\n s.LogOn(\"User\", \"Password\");\n\n // Getting a view - doesn't matter which, as long as it is not deleted.\n Project p = s.Projects[0];\n View v = p.AccessibleViews[0]; // AccessibleViews saves checking permissions.\n\n // Timestep to use when searching. One hour is fairly quick for resolution.\n TimeSpan deltaTime = new TimeSpan(1, 0, 0);\n deltaTime = new TimeSpan(24 * 365, 0, 0);\n\n // Invalid calls return faster - start a ways in the future.\n TimeSpan offset = new TimeSpan(24, 0, 0);\n\n // Times before the view was created are invalid.\n DateTime minTime = v.CreatedTime;\n DateTime localTime = DateTime.Now;\n\n if (localTime < minTime)\n {\n System.Console.WriteLine(\"Current time is older than view creation time: \" + minTime);\n\n // If the dates are so dissimilar that the current date is before the creation date,\n // it is probably a good idea to use a bigger delta.\n deltaTime = new TimeSpan(24 * 365, 0, 0);\n\n // Set the offset to the minimum time and work up from there.\n offset = minTime - localTime;\n }\n\n // Storage for calculated date.\n DateTime testTime;\n\n // Larger divisors converge quicker, but might take longer depending on offset.\n const float stepDivisor = 10.0f;\n\n bool foundValid = false;\n\n while (true)\n {\n localTime = DateTime.Now;\n\n testTime = localTime.Add(offset);\n\n ViewConfiguration vc = ViewConfiguration.CreateFromTime(testTime);\n\n View tempView = new View(v, vc);\n\n System.Console.Write(\"Testing \" + testTime + \" (Offset \" + (int)offset.TotalSeconds + \") (Delta \" + deltaTime.TotalSeconds + \"): \");\n\n // Unfortunately, there is no isValid operation. Attempting to\n // read a property from an invalid date configuration will\n // throw an exception.\n // An alternate to this would be proferred.\n bool valid = true;\n try\n {\n string testname = tempView.RootFolder.Name;\n }\n catch (ServerException)\n {\n System.Console.WriteLine(\" InValid\");\n valid = false;\n }\n\n if (valid)\n {\n System.Console.WriteLine(\" Valid\");\n\n // If the last check was invalid, the current check is valid, and \n // If the change is this small, the time is very close to the server time.\n if (foundValid == false && deltaTime.TotalSeconds <= 1)\n {\n break;\n }\n\n foundValid = true;\n offset = offset.Add(deltaTime);\n }\n else\n {\n offset = offset.Subtract(deltaTime);\n\n // Once a valid time is found, start reducing the timestep.\n if (foundValid)\n {\n foundValid = false;\n deltaTime = new TimeSpan(0,0,Math.Max((int)(deltaTime.TotalSeconds / stepDivisor), 1));\n }\n }\n\n }\n\n System.Console.WriteLine(\"Run time: \" + (DateTime.Now - StartTime).TotalSeconds + \" seconds.\");\n System.Console.WriteLine(\"The local time is \" + localTime);\n System.Console.WriteLine(\"The server time is \" + testTime);\n System.Console.WriteLine(\"The server time is offset from the local time by \" + offset.TotalSeconds + \" seconds.\");\n }\n Testing 4/9/2009 3:05:40 PM (Offset 86400) (Delta 31536000): InValid\nTesting 4/9/2008 3:05:40 PM (Offset -31449600) (Delta 31536000): Valid\n...\nTesting 4/8/2009 10:05:41 PM (Offset 25200) (Delta 3): InValid\nTesting 4/8/2009 10:05:38 PM (Offset 25197) (Delta 1): Valid\nRun time: 9.0933426 seconds.\nThe local time is 4/8/2009 3:05:41 PM\nThe server time is 4/8/2009 10:05:38 PM\nThe server time is offset from the local time by 25197 seconds.\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126114", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15647/" ]
126,116
<p>Is it possbile to execute linux commands with java? I am trying to create a web servlet to allow ftp users to change their passwords without ssh login access. I would like to execute the next commands: </p> <pre><code># adduser -s /sbin/nologin clientA -d /home/mainclient/clientA # passwd clientA # cd /home/mainclient; chgrp -R mainclient clientA # cd /home/mainclient/clientA; chmod 770 . </code></pre>
[ { "answer_id": 126124, "author": "Josh Moore", "author_id": 5004, "author_profile": "https://Stackoverflow.com/users/5004", "pm_score": 3, "selected": false, "text": "Runtime.getRuntim().exec(\"Command\");\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126116", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2138/" ]
126,128
<p>Anyone know if it is possible? And got any sample code for this? Or any other java API that can do this?</p>
[ { "answer_id": 3332837, "author": "Leonardo", "author_id": 401906, "author_profile": "https://Stackoverflow.com/users/401906", "pm_score": 1, "selected": false, "text": " IDocument myDoc = new Document2004(); \n myDoc.getBody().addEle(\"path/myImage.png\"));\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126128", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17147/" ]
126,138
<p>I'm trying to run a process and do stuff with its input, output and error streams. The obvious way to do this is to use something like <code>select()</code>, but the only thing I can find in Java that does that is <code>Selector.select()</code>, which takes a <code>Channel</code>. It doesn't appear to be possible to get a <code>Channel</code> from an <code>InputStream</code> or <code>OutputStream</code> (<code>FileStream</code> has a <code>getChannel()</code> method but that doesn't help here)</p> <p>So, instead I wrote some code to poll all the streams:</p> <pre><code>while( !out_eof || !err_eof ) { while( out_str.available() ) { if( (bytes = out_str.read(buf)) != -1 ) { // Do something with output stream } else out_eof = true; } while( err_str.available() ) { if( (bytes = err_str.read(buf)) != -1 ) { // Do something with error stream } else err_eof = true; } sleep(100); } </code></pre> <p>which works, except that it never terminates. When one of the streams reaches end of file, <code>available()</code> returns zero so <code>read()</code> isn't called and we never get the -1 return that would indicate EOF.</p> <p>One solution would be a non-blocking way to detect EOF. I can't see one in the docs anywhere. Alternatively is there a better way of doing what I want to do?</p> <p>I see this question here: <a href="https://stackoverflow.com/questions/60302/starting-a-process-with-inherited-stdinstdoutstderr-in-java-6#60578" title="Processes with inherited stdin/stdout/stderr in Java">link text</a> and although it doesn't exactly do what I want, I can probably use that idea, of spawning separate threads for each stream, for the particular problem I have now. But surely that isn't the only way to do it? Surely there must be a way to read from multiple streams without using a thread for each?</p>
[ { "answer_id": 126423, "author": "Daniel Schneller", "author_id": 1252368, "author_profile": "https://Stackoverflow.com/users/1252368", "pm_score": 2, "selected": false, "text": "public void run() {\n BufferedReader tStreamReader = null;\n try {\n while (externalCommand == null && !shouldHalt) {\n logger.warning(\"ExtProcMonitor(\"\n + (watchStdErr ? \"err\" : \"out\")\n + \") Sleeping until external command is found\");\n Thread.sleep(500);\n }\n if (externalCommand == null) {\n return;\n }\n tStreamReader =\n new BufferedReader(new InputStreamReader(watchStdErr ? externalCommand.getErrorStream()\n : externalCommand.getInputStream()));\n String tLine;\n while ((tLine = tStreamReader.readLine()) != null) {\n logger.severe(tLine);\n if (filter != null) {\n if (filter.matches(tLine)) {\n informFilterListeners(tLine);\n return;\n }\n }\n }\n } catch (IOException e) {\n logger.logExceptionMessage(e, \"IOException stderr\");\n } catch (InterruptedException e) {\n logger.logExceptionMessage(e, \"InterruptedException waiting for external process\");\n } finally {\n if (tStreamReader != null) {\n try {\n tStreamReader.close();\n } catch (IOException e) {\n // ignore\n }\n }\n }\n}\n Thread tExtMonitorThread = new Thread(new Runnable() {\n\n public void run() {\n try {\n while (externalCommand == null) {\n getLogger().warning(\"Monitor: Sleeping until external command is found\");\n Thread.sleep(500);\n if (isStopRequested()) {\n getLogger()\n .warning(\"Terminating external process on user request\");\n if (externalCommand != null) {\n externalCommand.destroy();\n }\n return;\n }\n }\n int tReturnCode = externalCommand.waitFor();\n getLogger().warning(\"External command exited with code \" + tReturnCode);\n } catch (InterruptedException e) {\n getLogger().logExceptionMessage(e, \"Interrupted while waiting for external command to exit\");\n }\n }\n }, \"ExtCommandWaiter\");\n\n ExternalProcessOutputHandlerThread tExtErrThread =\n new ExternalProcessOutputHandlerThread(\"ExtCommandStdErr\", getLogger(), true);\n ExternalProcessOutputHandlerThread tExtOutThread =\n new ExternalProcessOutputHandlerThread(\"ExtCommandStdOut\", getLogger(), true);\n tExtMonitorThread.start();\n tExtOutThread.start();\n tExtErrThread.start();\n tExtErrThread.setFilter(new FilterFunctor() {\n\n public boolean matches(Object o) {\n String tLine = (String)o;\n return tLine.indexOf(\"Error\") > -1;\n }\n });\n\n FilterListener tListener = new FilterListener() {\n private boolean abortFlag = false;\n\n public boolean shouldAbort() {\n return abortFlag;\n }\n\n public void matched(String aLine) {\n abortFlag = abortFlag || (aLine.indexOf(\"Error\") > -1);\n }\n\n };\n\n tExtErrThread.addFilterListener(tListener);\n externalCommand = new ProcessBuilder(aCommand).start();\n tExtErrThread.setProcess(externalCommand);\n try {\n tExtMonitorThread.join();\n tExtErrThread.join();\n tExtOutThread.join();\n } catch (InterruptedException e) {\n // when this happens try to bring the external process down \n getLogger().severe(\"Aborted because auf InterruptedException.\");\n getLogger().severe(\"Killing external command...\");\n externalCommand.destroy();\n getLogger().severe(\"External command killed.\");\n externalCommand = null;\n return -42;\n }\n int tRetVal = tListener.shouldAbort() ? -44 : externalCommand.exitValue();\n\n externalCommand = null;\n try {\n getLogger().warning(\"command exit code: \" + tRetVal);\n } catch (IllegalThreadStateException ex) {\n getLogger().warning(\"command exit code: unknown\");\n }\n return tRetVal;\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126138", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11815/" ]
126,141
<p>I need to determine which version of GTK+ is installed on Ubuntu</p> <p>Man does not seem to help</p>
[ { "answer_id": 126145, "author": "Torsten Marek", "author_id": 9567, "author_profile": "https://Stackoverflow.com/users/9567", "pm_score": 5, "selected": false, "text": "$ dpkg -s libgtk2.0-0|grep '^Version'\n" }, { "answer_id": 126193, "author": "Mark Baker", "author_id": 11815, "author_profile": "https://Stackoverflow.com/users/11815", "pm_score": 7, "selected": true, "text": "dpkg -l libgtk* | grep -e '^i' | grep -e 'libgtk-*[0-9]'\n dpkg -l pkg-config --modversion gtk+\n pkg-config --modversion gtk+-2.0\n pkg-config --modversion gtk+-3.0\n" }, { "answer_id": 126395, "author": "Xqj37", "author_id": 14688, "author_profile": "https://Stackoverflow.com/users/14688", "pm_score": 2, "selected": false, "text": "gtk-config --version" }, { "answer_id": 13098607, "author": "Dr Casper Black", "author_id": 229901, "author_profile": "https://Stackoverflow.com/users/229901", "pm_score": 5, "selected": false, "text": "dpkg -s libgtk-3-0|grep '^Version'\n dpkg -s libgtk-3-0|grep '^Version' | cut -d' ' -f2-\n" }, { "answer_id": 16231467, "author": "Helge", "author_id": 180954, "author_profile": "https://Stackoverflow.com/users/180954", "pm_score": 1, "selected": false, "text": "env | grep gtk\n locate locate gtk | grep /usr/lib\n /usr/lib64/gtk-2.0 2.10.0 rpm -qa | grep gtk2" }, { "answer_id": 16402135, "author": "Chimera", "author_id": 1076451, "author_profile": "https://Stackoverflow.com/users/1076451", "pm_score": 3, "selected": false, "text": "#include <gtk/gtk.h>\n#include <glib/gprintf.h>\n\nint main(int argc, char *argv[])\n{\n /* Initialize GTK */\n gtk_init (&argc, &argv);\n\n g_printf(\"%d.%d.%d\\n\", gtk_major_version, gtk_minor_version, gtk_micro_version);\n return(0);\n}\n gcc version.c -o version `pkg-config --cflags --libs gtk+-2.0`\n [root@n00E04B3730DF n2]# ./version \n2.10.4\n[root@n00E04B3730DF n2]#\n" }, { "answer_id": 27871238, "author": "Максим Шатов", "author_id": 1737151, "author_profile": "https://Stackoverflow.com/users/1737151", "pm_score": 3, "selected": false, "text": "apt-cache policy libgtk2.0-0 libgtk-3-0 \n dpkg -l libgtk2.0-0 libgtk-3-0\n" }, { "answer_id": 32215303, "author": "ThorSummoner", "author_id": 1695680, "author_profile": "https://Stackoverflow.com/users/1695680", "pm_score": 2, "selected": false, "text": " dpkg-query -W libgtk-3-bin\n" }, { "answer_id": 47659005, "author": "liberforce", "author_id": 518853, "author_profile": "https://Stackoverflow.com/users/518853", "pm_score": 2, "selected": false, "text": "dpkg -l | egrep \"libgtk(2.0-0|-3-0|-4)\"\n ii libgtk-3-0:amd64 3.10.8-0ubuntu1.6 amd64 GTK+ graphical user interface library\nii libgtk2.0-0:amd64 2.24.23-0ubuntu1.4 amd64 GTK+ graphical user interface library\n pkg-config --modversion gtk+-2.0 pkg-config --modversion gtk+-3.0 pkg-config --modversion gtk4 + GTK+" }, { "answer_id": 63590934, "author": "stragu", "author_id": 1494531, "author_profile": "https://Stackoverflow.com/users/1494531", "pm_score": 2, "selected": false, "text": "apt-cache policy apt list --installed libgtk*\n" }, { "answer_id": 63867633, "author": "survivor303", "author_id": 5584567, "author_profile": "https://Stackoverflow.com/users/5584567", "pm_score": 5, "selected": false, "text": "gtk-launch --version\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126141", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15352/" ]
126,148
<p>How is the salt generated in HashProvider in Microsoft Enterprise Library when we set SaltEnabled?</p> <p>Is it random to new machines? Is it some magic number?</p> <p>(I know what is a salt, the question is what's the actual value of a/the salt in Enterprise Library HashProvider)</p>
[ { "answer_id": 128481, "author": "Corbin March", "author_id": 7625, "author_profile": "https://Stackoverflow.com/users/7625", "pm_score": 2, "selected": false, "text": "public bool CompareHash(byte[] plaintext, byte[] hashedtext)\n" }, { "answer_id": 27247664, "author": "Gareth Stephenson", "author_id": 869376, "author_profile": "https://Stackoverflow.com/users/869376", "pm_score": 0, "selected": false, "text": "CryptographyUtility.GetRandomBytes(16); Microsoft.Practices.EnterpriseLibrary.Security.Cryptography [DllImport(\"QCall\", CharSet = CharSet.Unicode)]\nprivate static extern void GetBytes(SafeProvHandle hProv, byte[] randomBytes, int count);" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126148", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
126,154
<p>I am designing a page to Add/Edit users - I used a repeater control and a table to display users. In users view the individual columns of the table row have labels to display a record values and when users click on edit button, the labels are hidden and text boxes are displayed for users to edit values - The problem is - as soon as the text boxes are visible, the table size increases - the row height and cells size becomes large. Is there a way to display the text boxes so that they take the same size as the labels</p>
[ { "answer_id": 126254, "author": "Oli", "author_id": 12870, "author_profile": "https://Stackoverflow.com/users/12870", "pm_score": 0, "selected": false, "text": "<td> <td> <td> <td>" }, { "answer_id": 126311, "author": "Filini", "author_id": 21162, "author_profile": "https://Stackoverflow.com/users/21162", "pm_score": 1, "selected": false, "text": "\n.CellContent { display:block; width: ...; height: ...; }\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126154", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17296/" ]
126,164
<p>Assume the following class:</p> <pre><code>public class MyEnum: IEnumerator { private List&lt;SomeObject&gt; _myList = new List&lt;SomeObject&gt;(); ... } </code></pre> <p>It is necessary to implement the IEnumerator methods in MyEnum. But is it possible to 'delegate' or redirect the implementation for IEnumerator directly to _myList without needing to implement the IEnumerator methods?</p>
[ { "answer_id": 126171, "author": "Paul van Brenk", "author_id": 1837197, "author_profile": "https://Stackoverflow.com/users/1837197", "pm_score": -1, "selected": false, "text": "public class MyEnum : List<SomeObject>, IEnumerable<SomeObject>{}\n" }, { "answer_id": 126191, "author": "TcKs", "author_id": 20382, "author_profile": "https://Stackoverflow.com/users/20382", "pm_score": 1, "selected": false, "text": "public class MyEnum : IEnumerator {\n private List<SomeObject> _myList = new List<SomeObject>();\n public IEnumerator GetEnumerator() { return this._myList.GetEnumerator(); }\n}\n" }, { "answer_id": 126198, "author": "Jorge Ferreira", "author_id": 6508, "author_profile": "https://Stackoverflow.com/users/6508", "pm_score": 4, "selected": true, "text": "class SomeObject\n{\n}\n\nclass MyEnum : IEnumerable<SomeObject>\n{\n private List<SomeObject> _myList = new List<SomeObject>();\n\n public void Add(SomeObject o)\n {\n _myList.Add(o);\n }\n\n public IEnumerator<SomeObject> GetEnumerator()\n {\n return _myList.GetEnumerator();\n }\n\n IEnumerator IEnumerable.GetEnumerator()\n {\n return this.GetEnumerator();\n }\n}\n\nclass Program\n{\n static void Main(string[] args)\n {\n MyEnum a = new MyEnum();\n a.Add(new SomeObject());\n\n foreach (SomeObject o in a)\n {\n Console.WriteLine(o.GetType().ToString());\n }\n\n Console.ReadLine();\n }\n}\n class SomeObject\n{\n}\n\nclass MyEnum : List<SomeObject>\n{\n}\n\nclass Program\n{\n static void Main(string[] args)\n {\n MyEnum a = new MyEnum();\n a.Add(new SomeObject());\n\n foreach (SomeObject o in a)\n {\n Console.WriteLine(o.GetType().ToString());\n }\n\n Console.ReadLine();\n }\n}\n" }, { "answer_id": 126201, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 1, "selected": false, "text": "this GetEnumerator IEnumerator<T> IEnumerable" }, { "answer_id": 126287, "author": "Willem", "author_id": 21568, "author_profile": "https://Stackoverflow.com/users/21568", "pm_score": -1, "selected": false, "text": " class MyEnum : IEnumerable<SomeObject>\n{\n private List<SomeObject> _myList = new List<SomeObject>();\n public IEnumerator<SomeObject> GetEnumerator()\n {\n // Create a read-only copy of the list.\n ReadOnlyCollection<CustomDevice> items = new ReadOnlyCollection<CustomDevice>(_myList);\n return items.GetEnumerator();\n }\n}\n" }, { "answer_id": 44422396, "author": "yoyo", "author_id": 503688, "author_profile": "https://Stackoverflow.com/users/503688", "pm_score": -1, "selected": false, "text": "foreach GetEnumerator IEnumerable class SomeObject\n{\n}\n\n class MyEnum\n {\n private List<SomeObject> _myList = new List<SomeObject>();\n\n public IEnumerator<SomeObject> GetEnumerator()\n {\n return _myList.GetEnumerator();\n }\n }\n MyEnum objects = new MyEnum();\n// ... add some objects\nforeach (SomeObject obj in objects)\n{\n Console.WriteLine(obj.ToString());\n}\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126164", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21568/" ]
126,167
<p>Application able to record error in OnError, but we are not able to do any redirect or so to show something meaningfull to user. Any ideas? I know that we can set maxRequestLength in web.config, but anyway user can exceed this limit and some normal error need to be displayed.</p>
[ { "answer_id": 126376, "author": "JohnIdol", "author_id": 1311500, "author_profile": "https://Stackoverflow.com/users/1311500", "pm_score": 4, "selected": true, "text": "<system.web>\n <customErrors mode=On defaultRedirect=yourCustomErrorPage.aspx />\n</system.web>\n <system.web> \n <customErrors mode=\"On\" defaultRedirect=\"yourCustomErrorPage.aspx\">\n <error statusCode=\"404\" redirect=\"PageNotFound.aspx\" />\n </customErrors>\n</system.web>\n" }, { "answer_id": 839909, "author": "Mike Strother", "author_id": 21320, "author_profile": "https://Stackoverflow.com/users/21320", "pm_score": 1, "selected": false, "text": " <customErrors mode=\"On\" defaultRedirect=\"~/Errors/Error.aspx\">\n <error statusCode=\"413\" redirect=\"~/Errors/UploadError.aspx\"/>\n </customErrors>\n" }, { "answer_id": 7196929, "author": "joelmdev", "author_id": 663246, "author_profile": "https://Stackoverflow.com/users/663246", "pm_score": 0, "selected": false, "text": " if (ex.InnerException != null && ex.InnerException.GetType() == typeof(HttpException) && ((HttpException)ex.InnerException).WebEventCode == System.Web.Management.WebEventCodes.RuntimeErrorPostTooLarge)\n {\n //Handle and redirect here, you can use Server.ClearError() and Response.Redirect(\"FileTooBig.aspx\") or whatever you choose\n }\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126167", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11768/" ]
126,179
<p>If I have a query like, </p> <pre><code>DELETE FROM table WHERE datetime_field &lt; '2008-01-01 00:00:00' </code></pre> <p>does having the <code>datetime_field</code> column indexed help? i.e. is the index only useful when using equality (or inequality) testing, or is it useful when doing an ordered comparison as well?</p> <blockquote> <p>(Suggestions for better executing this query, without recreating the table, would also be ok!)</p> </blockquote>
[ { "answer_id": 126461, "author": "Bruno De Fraine", "author_id": 6918, "author_profile": "https://Stackoverflow.com/users/6918", "pm_score": 2, "selected": false, "text": "EXPLAIN" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126179", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4966/" ]
126,207
<p>Are there any best practices (or even standards) to store addresses in a consistent and comprehensive way in a database ?</p> <p>To be more specific, I believe at this stage that there are two cases for address storage :</p> <ul> <li>you just need to associate an address to a person, a building or any item (the most common case). Then a flat table with text columns (address1, address2, zip, city) is probably enough. This is not the case I'm interested in.</li> <li>you want to run statistics on your addresses : how many items in a specific street, or city or... Then you want to avoid misspellings of any sorts, and ensure consistency. My question is about best practices in this specific case : what are the best ways to model a consistent address database ?</li> </ul> <p>A country specific design/solution would be an excellent start.</p> <p><strong>ANSWER</strong> : There does not seem to exist a perfect answer to this question yet, but :</p> <ul> <li><a href="http://www.oasis-open.org/committees/ciq/ciq.html#6" rel="noreferrer">xAL</a>, as <a href="https://stackoverflow.com/questions/126207/best-practices-for-consistent-and-comprehensive-address-storage-in-a-database#126219">suggested by Hank</a>, is the closest thing to a global standard that popped up. It seems to be quite an overkill though, and I am not sure many people would want to implement it in their database...</li> <li>To start one's own design (for a specific country), <a href="https://stackoverflow.com/questions/126207/best-practices-for-consistent-and-comprehensive-address-storage-in-a-database#126860">Dave's link</a> to the <a href="http://www.upu.int/post_code/en/postal_addressing_systems_member_countries.shtml" rel="noreferrer">Universal Postal Union</a> (UPU) site is a very good starting point.</li> <li>As for France, there is a norm (non official, but de facto standard) for addresses, which bears the lovely name of <a href="http://www.boutique.afnor.org/NEL5DetailNormeEnLigne.aspx?&amp;nivCtx=NELZNELZ1A10A101A107&amp;ts=1843530&amp;CLE_ART=FA047725" rel="noreferrer">AFNOR XP Z10-011</a> (french only), and has to be paid for. The <a href="http://www.upu.int/post_code/en/postal_addressing_systems_member_countries.shtml" rel="noreferrer">UPU</a> description for France is based on this norm.</li> <li>I happened to find the equivalent norm for Sweden : <a href="http://www.sis.se/DesktopDefault.aspx?tabName=@DocType_1&amp;Doc_ID=34763" rel="noreferrer">SS 613401</a>.</li> <li>At European level, some effort has been made, resulting in the norm EN 14142-1. It is obtainable via <a href="http://www.cen.eu/cenorm/members/national+members/members.asp" rel="noreferrer">CEN national members</a>.</li> </ul>
[ { "answer_id": 126219, "author": "Hank Gay", "author_id": 4203, "author_profile": "https://Stackoverflow.com/users/4203", "pm_score": 3, "selected": true, "text": "Address" }, { "answer_id": 414803, "author": "Nicholas Piasecki", "author_id": 32187, "author_profile": "https://Stackoverflow.com/users/32187", "pm_score": 5, "selected": false, "text": "\nenum address-fields \n{\n name,\n company-name,\n street-lines[], // up to 4 free-type street lines\n county/sublocality,\n city/town/district,\n state/province/region/territory,\n postal-code,\n country\n}\n Address AmericanAddress CanadianAddress GermanAddress \nstructure address-field-metadata \n{\n field-number, // corresponds to the enumeration above\n field-index, // the order in which the field is usually displayed\n field-name, // a \"localized\" name; US == \"State\", CA == \"Province\", etc\n is-applicable, // whether or not the field is even looked at / valid\n is-required, // whether or not the field is required\n validation-regex, // an optional regex to apply against the field\n allowed-values[] // an optional array of specific values the field can be set to\n}\n Address AddressStrategy \nobject address\n{\n set-field(field-number, field-value),\n address-strategy\n}\n\nobject address-strategy\n{\n validate-field(field-number, field-value),\n cleanse-address(address),\n format-address(address, formatting-options)\n}\n Address AddressStrategy SetField() address.GetMetadata() AddressFieldMetadata is-applicable false field-name is-required validation-regex allowed-values address.SetField() field-number Address Address Address" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126207", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8696/" ]
126,238
<p>Imagine to have two RESTful controllers (UsersController, OffersController) and a PagesController (used for static content such as index, about and so on) in your application.</p> <p>You have the following routes defined:</p> <pre><code>map.with_options :controller =&gt; 'pages' do |pages| pages.root :action =&gt; 'index' # static home page pages.about :action =&gt; 'about' # static about page # maybe more static pages... end map.resources :users # RESTful UsersController map.resources :posts # RESTful PostsController </code></pre> <p>Your application layout looks like this:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;Demo Application&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;ul id="menu"&gt; &lt;li&gt; &lt;%= link_to 'Home', root_path %&gt; &lt;/li&gt; &lt;li&gt; &lt;%= link_to 'Offers', offers_path %&gt; &lt;ul id="submenu&gt; &lt;li&gt;&lt;%= link_to 'Search', 'path/to/search' %&gt;&lt;/li&gt; &lt;li&gt;maybe more links...&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li&gt; &lt;%= link_to 'About', about_path %&gt; &lt;/li&gt; &lt;li&gt; &lt;%= link_to 'Admin', users_path %&gt; &lt;ul id="submenu"&gt; &lt;li&gt;&lt;%= link_to 'New User', new_user_path %&gt;&lt;/li&gt; &lt;li&gt;&lt;%= link_to 'New Offer', new_offer_path %&gt;&lt;/li&gt; &lt;li&gt;maybe more links&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/li&gt; &lt;%= yield %&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>The problem with the layout is that I want only one <code>#submenu</code> to be visible at any time. All other submenus can be completely skipped (don't need to rendered at all).</p> <p>Take the Admin menu for example: This menu should be active for all RESTful paths in the application except for <code>offers_path</code>. Active means that the submenu is visible.</p> <p>The only solution I can think of to achieve this is to build a lot complicated if conditions and that sucks (really complicated to write and to maintain). I'm looking for an elegant solution?</p> <p>I hope someone understands my question - if there's something unclear just comment the question and I'm going to explain it in more detail.</p>
[ { "answer_id": 126849, "author": "Jeremiah Peschka", "author_id": 11780, "author_profile": "https://Stackoverflow.com/users/11780", "pm_score": 1, "selected": false, "text": "def render_admin_menu()\n if !current_path.contains('offer')\n render :partial => 'shared/admin_menu'\n end\nend\n" }, { "answer_id": 127619, "author": "PJ.", "author_id": 3230, "author_profile": "https://Stackoverflow.com/users/3230", "pm_score": 4, "selected": true, "text": "<%= yield(:menu) %>\n <% content_for(:menu) do %>\n <%= render :partial => 'layouts/menu' %>\n <%= render :partial => 'layouts/search_menu' %>\n etc...\n <% end %>\n <%= yield(:menu) || render :partial => 'layouts/menu_default' %>\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126238", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20467/" ]
126,242
<p>This is probably explained more easily with an example. I'm trying to find a way of turning a relative URL, e.g. "/Foo.aspx" or "~/Foo.aspx" into a full URL, e.g. <a href="http://localhost/Foo.aspx" rel="noreferrer">http://localhost/Foo.aspx</a>. That way when I deploy to test or stage, where the domain under which the site runs is different, I will get <a href="http://test/Foo.aspx" rel="noreferrer">http://test/Foo.aspx</a> and <a href="http://stage/Foo.aspx" rel="noreferrer">http://stage/Foo.aspx</a>.</p> <p>Any ideas?</p>
[ { "answer_id": 126258, "author": "Oli", "author_id": 12870, "author_profile": "https://Stackoverflow.com/users/12870", "pm_score": 7, "selected": true, "text": "public string ConvertRelativeUrlToAbsoluteUrl(string relativeUrl) {\n return string.Format(\"http{0}://{1}{2}\",\n (Request.IsSecureConnection) ? \"s\" : \"\", \n Request.Url.Host,\n Page.ResolveUrl(relativeUrl)\n );\n}\n" }, { "answer_id": 2788568, "author": "StocksR", "author_id": 6892, "author_profile": "https://Stackoverflow.com/users/6892", "pm_score": 3, "selected": false, "text": "public string GetFullUrl(string relativeUrl) {\n string root = Request.Url.GetLeftPart(UriPartial.Authority);\n return root + Page.ResolveUrl(\"~/\" + relativeUrl) ;\n}\n" }, { "answer_id": 4146744, "author": "Joshua Grippo", "author_id": 503496, "author_profile": "https://Stackoverflow.com/users/503496", "pm_score": 2, "selected": false, "text": "//\"~/SomeFolder/SomePage.aspx\"\npublic static string GetFullURL(string relativePath)\n{\n string sRelative=Page.ResolveUrl(relativePath);\n string sAbsolute=Request.Url.AbsoluteUri.Replace(Request.Url.PathAndQuery,sRelative);\n return sAbsolute;\n}\n" }, { "answer_id": 7427598, "author": "Marcus", "author_id": 946286, "author_profile": "https://Stackoverflow.com/users/946286", "pm_score": 5, "selected": false, "text": "page.request.url AbsoluteUri New System.Uri(Page.Request.Url, \"Foo.aspx\").AbsoluteUri\n" }, { "answer_id": 9020514, "author": "Josh M.", "author_id": 374198, "author_profile": "https://Stackoverflow.com/users/374198", "pm_score": 5, "selected": false, "text": "public static string AbsoluteAction(this UrlHelper url, string actionName, string controllerName, object routeValues)\n{\n return url.Action(actionName, controllerName, routeValues, url.RequestContext.HttpContext.Request.Url.Scheme);\n}\n\npublic static string AbsoluteContent(this UrlHelper url, string path)\n{\n Uri uri = new Uri(path, UriKind.RelativeOrAbsolute);\n\n //If the URI is not already absolute, rebuild it based on the current request.\n if (!uri.IsAbsoluteUri)\n {\n Uri requestUrl = url.RequestContext.HttpContext.Request.Url;\n UriBuilder builder = new UriBuilder(requestUrl.Scheme, requestUrl.Host, requestUrl.Port);\n\n builder.Path = VirtualPathUtility.ToAbsolute(path);\n uri = builder.Uri;\n }\n\n return uri.ToString();\n}\n" }, { "answer_id": 12461030, "author": "Menelaos Vergis", "author_id": 1503307, "author_profile": "https://Stackoverflow.com/users/1503307", "pm_score": 1, "selected": false, "text": "url = new Uri(baseUri, url);\n" }, { "answer_id": 14440359, "author": "stucampbell", "author_id": 21379, "author_profile": "https://Stackoverflow.com/users/21379", "pm_score": 2, "selected": false, "text": "Uri public static class UrlHelperExtensions\n{\n public static string AbsolutePath(this UrlHelper urlHelper, \n string relativePath)\n {\n return new Uri(urlHelper.RequestContext.HttpContext.Request.Url,\n relativePath).ToString();\n }\n}\n // gives absolute path, e.g. https://example.com/customers\nUrl.AbsolutePath(Url.Action(\"Index\", \"Customers\"));\n UrlHelper // gives absolute path, e.g. https://example.com/customers\nUrl.AbsoluteAction(\"Index\", \"Customers\");\n Url.AbsoluteAction(\"Details\", \"Customers\", new{id = 123});\n public static class UrlHelperExtensions\n{\n public static string AbsolutePath(this UrlHelper urlHelper, \n string relativePath)\n {\n return new Uri(urlHelper.RequestContext.HttpContext.Request.Url,\n relativePath).ToString();\n }\n\n public static string AbsoluteAction(this UrlHelper urlHelper, \n string actionName, \n string controllerName)\n {\n return AbsolutePath(urlHelper, \n urlHelper.Action(actionName, controllerName));\n }\n\n public static string AbsoluteAction(this UrlHelper urlHelper, \n string actionName, \n string controllerName, \n object routeValues)\n {\n return AbsolutePath(urlHelper, \n urlHelper.Action(actionName, \n controllerName, routeValues));\n }\n}\n" }, { "answer_id": 14950535, "author": "Carl G", "author_id": 39396, "author_profile": "https://Stackoverflow.com/users/39396", "pm_score": 1, "selected": false, "text": "HtmlHelper UrlHelper protocol host public static MvcHtmlString ActionLinkAbsolute<TViewModel>(\n this HtmlHelper<TViewModel> html, \n string linkText, \n string actionName, \n string controllerName, \n object routeValues = null,\n object htmlAttributes = null)\n{\n var request = html.ViewContext.HttpContext.Request;\n var url = new UriBuilder(request.Url);\n return html.ActionLink(linkText, actionName, controllerName, url.Scheme, url.Host, null, routeValues, htmlAttributes);\n}\n @Html.ActionLinkAbsolute(\"Click here\", \"Action\", \"Controller\", new { id = Model.Id }) \n" }, { "answer_id": 37122000, "author": "Robert McKee", "author_id": 856353, "author_profile": "https://Stackoverflow.com/users/856353", "pm_score": 0, "selected": false, "text": "public static string ResolveFullUrl(this System.Web.UI.Page page, string relativeUrl)\n{\n if (string.IsNullOrEmpty(relativeUrl))\n return relativeUrl;\n\n if (relativeUrl.StartsWith(\"/\"))\n relativeUrl = relativeUrl.Insert(0, \"~\");\n if (!relativeUrl.StartsWith(\"~/\"))\n relativeUrl = relativeUrl.Insert(0, \"~/\");\n\n return $\"{page.Request.Url.Scheme}{Uri.SchemeDelimiter}{page.Request.Url.Authority}{VirtualPathUtility.ToAbsolute(relativeUrl)}\";\n}\n" }, { "answer_id": 37884172, "author": "Xavier J", "author_id": 3167751, "author_profile": "https://Stackoverflow.com/users/3167751", "pm_score": 0, "selected": false, "text": " /// <summary>\n /// This function turns arbitrary strings containing a \n /// URI into an appropriate absolute URI. \n /// </summary>\n /// <param name=\"input\">A relative or absolute URI (as a string)</param>\n /// <param name=\"baseUri\">The base URI to use if the input parameter is relative.</param>\n /// <returns>An absolute URI</returns>\n public static Uri MakeFullUri(string input, Uri baseUri)\n {\n var tmp = new Uri(input, UriKind.RelativeOrAbsolute);\n //if it's absolute, return that\n if (tmp.IsAbsoluteUri)\n {\n return tmp;\n }\n // build relative on top of the base one instead\n return new Uri(baseUri, tmp);\n }\n Uri baseUri = new Uri(\"http://yahoo.com/folder\");\nUri newUri = MakeFullUri(\"/some/path?abcd=123\", baseUri);\n//\n//newUri will contain http://yahoo.com/some/path?abcd=123\n//\nUri newUri2 = MakeFullUri(\"some/path?abcd=123\", baseUri);\n//\n//newUri2 will contain http://yahoo.com/folder/some/path?abcd=123\n//\nUri newUri3 = MakeFullUri(\"http://google.com\", baseUri);\n//\n//newUri3 will contain http://google.com, and baseUri is not used at all.\n//\n" }, { "answer_id": 43555252, "author": "Softcanon Development", "author_id": 7852940, "author_profile": "https://Stackoverflow.com/users/7852940", "pm_score": 0, "selected": false, "text": " /// <summary>\n /// Return full URL from virtual relative path like ~/dir/subir/file.html\n /// usefull in ex. external links\n /// </summary>\n /// <param name=\"rootVirtualPath\"></param>\n /// <returns></returns>\n public static string GetAbsoluteFullURLFromRootVirtualPath(string rootVirtualPath)\n {\n\n return string.Format(\"http{0}://{1}{2}{3}\",\n (HttpContext.Current.Request.IsSecureConnection) ? \"s\" : \"\"\n , HttpContext.Current.Request.Url.Host\n , (HttpContext.Current.Request.Url.IsDefaultPort) ? \"\" : \":\" + HttpContext.Current.Request.Url.Port\n , VirtualPathUtility.ToAbsolute(rootVirtualPath)\n );\n\n }\n" }, { "answer_id": 60466798, "author": "Aftab Ahmed Kalhoro", "author_id": 1767839, "author_profile": "https://Stackoverflow.com/users/1767839", "pm_score": 0, "selected": false, "text": "Url.Content(relativePath)" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126242", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12277/" ]
126,260
<p>Since the release of Adobe AIR I am wondering why Java Web Start has not gained more attention in the past as to me it seems to be very similar, but web start is available for a much longer time.</p> <p>Is it mainly because of bad marketing from Sun, or are there more technical concerns other than the need of having the right JVM installed? Do you have bad experiences using Web Start? If yes, which? What are you recommendations when using Web Start for distributing applications?</p>
[ { "answer_id": 11465462, "author": "Mikko Rantalainen", "author_id": 334451, "author_profile": "https://Stackoverflow.com/users/334451", "pm_score": 2, "selected": false, "text": "application/x-java-jnlp-file javaws javaws.exe .jnlp application/x- https://example.com/app/launch.jnlp javaws://example.com/app/launch.jnlp .jnlp javaws javaws .jnlp javaws .jnlp" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126260", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7524/" ]
126,271
<p>Does someone have experience with storing key-value pairs in a database?</p> <p>I've been using this type of table:</p> <pre><code>CREATE TABLE key_value_pairs ( itemid varchar(32) NOT NULL, itemkey varchar(32) NOT NULL, itemvalue varchar(32) NOT NULL, CONSTRAINT ct_primarykey PRIMARY KEY(itemid,itemkey) ) </code></pre> <p>Then for example the following rows could exist:</p> <pre><code> itemid itemkey itemvalue ---------------- ------------- ------------ 123 Colour Red 123 Size Medium 123 Fabric Cotton </code></pre> <p>The trouble with this scheme is the SQL syntax required to extract data is quite complex. Would it be better to just create a series of key/value columns?</p> <pre><code>CREATE TABLE key_value_pairs ( itemid varchar(32) NOT NULL, itemkey1 varchar(32) NOT NULL, itemvalue1 varchar(32) NOT NULL, itemkey2 varchar(32) NOT NULL, itemvalue2 varchar(32) NOT NULL, . . .etc . . . ) </code></pre> <p>This will be easier and faster to query but lacks the extensibility of the first approach. Any advice?</p>
[ { "answer_id": 126308, "author": "Vinko Vrsalovic", "author_id": 5190, "author_profile": "https://Stackoverflow.com/users/5190", "pm_score": 1, "selected": false, "text": "create table item_config (item_id int, colour varchar, size varchar, fabric varchar)\n" }, { "answer_id": 126383, "author": "Adam Pierce", "author_id": 5324, "author_profile": "https://Stackoverflow.com/users/5324", "pm_score": 2, "selected": false, "text": "SELECT itemkey,itemvalue FROM key_value_pairs WHERE itemid='123';\n SELECT itemvalue FROM key_value_pairs WHERE itemid='123' AND itemkey='Fabric';\n" }, { "answer_id": 126397, "author": "Peter Marshall", "author_id": 4692, "author_profile": "https://Stackoverflow.com/users/4692", "pm_score": 4, "selected": false, "text": "<items> <item key=\"colour\" value=\"red\"/><item key=\"xxx\" value=\"blah\"/></items>" }, { "answer_id": 126467, "author": "Jarrett Meyer", "author_id": 5834, "author_profile": "https://Stackoverflow.com/users/5834", "pm_score": 1, "selected": false, "text": "key_1, value_1, key_2, value_2, ... key_n, value_n key_n+1, value_n+1" }, { "answer_id": 126735, "author": "Matthew Watson", "author_id": 3839, "author_profile": "https://Stackoverflow.com/users/3839", "pm_score": 4, "selected": false, "text": "CREATE TABLE valid_keys ( \n id NUMBER(10) NOT NULL,\n description varchar(32) NOT NULL,\n CONSTRAINT pk_valid_keys PRIMARY KEY(id)\n);\n\nCREATE TABLE item_values ( \n item_id NUMBER(10) NOT NULL,\n key_id NUMBER(10) NOT NULL,\n item_value VARCHAR2(32) NOT NULL,\n CONSTRAINT pk_item_values PRIMARY KEY(item_id),\n CONSTRAINT fk_item_values_iv FOREIGN KEY (key_id) REFERENCES valid_keys (id)\n);\n" }, { "answer_id": 72413084, "author": "nomadus", "author_id": 2480869, "author_profile": "https://Stackoverflow.com/users/2480869", "pm_score": 0, "selected": false, "text": "CREATE TABLE `tasks` (\n `task_id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,\n `account_id` BIGINT(20) UNSIGNED NOT NULL,\n `type` VARCHAR(128) COLLATE UTF8MB4_UNICODE_CI DEFAULT NULL,\n `title` VARCHAR(256) COLLATE UTF8MB4_UNICODE_CI NOT NULL,\n `description` TEXT COLLATE UTF8MB4_UNICODE_CI NOT NULL,\n `priority` VARCHAR(40) COLLATE UTF8MB4_UNICODE_CI DEFAULT NULL,\n `created_by` VARCHAR(40) COLLATE UTF8MB4_UNICODE_CI DEFAULT NULL,\n `creation_date` TIMESTAMP NULL DEFAULT NULL,\n `last_updated_by` VARCHAR(40) COLLATE UTF8MB4_UNICODE_CI DEFAULT NULL,\n `last_updated_date` TIMESTAMP NULL DEFAULT NULL,\n PRIMARY KEY (`task_id`),\n KEY `tasks_fk_1` (`account_id`),\n CONSTRAINT `tasks_fk_1` FOREIGN KEY (`account_id`)\n REFERENCES `accounts` (`account_id`)\n ON DELETE CASCADE ON UPDATE NO ACTION\n) ENGINE=INNODB AUTO_INCREMENT=1 DEFAULT CHARSET=UTF8MB4 COLLATE = UTF8MB4_UNICODE_CI ROW_FORMAT=DYNAMIC;\n CREATE TABLE `task_variables` (\n `row_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n `task_id` bigint(20) unsigned NOT NULL,\n `name` varchar(128) COLLATE utf8mb4_unicode_ci NOT NULL,\n `type` varchar(40) COLLATE utf8mb4_unicode_ci DEFAULT NULL,\n `variable_text_value` varchar(256) COLLATE utf8mb4_unicode_ci DEFAULT NULL,\n `variable_number_value` double DEFAULT NULL,\n `variable_date_value` datetime DEFAULT NULL,\n `created_by` varchar(40) COLLATE utf8mb4_unicode_ci DEFAULT NULL,\n `creation_date` timestamp NULL DEFAULT NULL,\n `last_updated_by` varchar(40) COLLATE utf8mb4_unicode_ci DEFAULT NULL,\n `last_updated_date` timestamp NULL DEFAULT NULL,\n PRIMARY KEY (`row_id`),\n KEY `task_variables_fk` (`task_id`),\n CONSTRAINT `task_variables_fk` FOREIGN KEY (`task_id`) REFERENCES `tasks` (`task_id`) ON DELETE CASCADE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126271", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2887/" ]
126,277
<p>Say you want to generate a matched list of identifiers and strings</p> <pre><code>enum { NAME_ONE, NAME_TWO, NAME_THREE }; myFunction(NAME_ONE, "NAME_ONE"); myFunction(NAME_TWO, "NAME_TWO"); myFunction(NAME_THREE, "NAME_THREE"); </code></pre> <p>..without repeating yourself, and without auto-generating the code, using C/C++ macros</p> <p><b>Initial guess:</b></p> <p>You could add an #include file containing</p> <pre><code>myDefine(NAME_ONE) myDefine(NAME_TWO) myDefine(NAME_THREE) </code></pre> <p>Then use it twice like:</p> <pre><code>#define myDefine(a) a, enum { #include "definitions" } #undef myDefine #define myDefine(a) myFunc(a, "a"); #include "definitions" #undef myDefine </code></pre> <p>but #define doesn't let you put parameters within a string?</p>
[ { "answer_id": 126291, "author": "Kristopher Johnson", "author_id": 1175, "author_profile": "https://Stackoverflow.com/users/1175", "pm_score": 6, "selected": true, "text": "#define myDefine(a) myFunc(a, #a);\n" }, { "answer_id": 126511, "author": "AareP", "author_id": 11741, "author_profile": "https://Stackoverflow.com/users/11741", "pm_score": 2, "selected": false, "text": "#define FOR_ALL_FUNCTIONS(F)\\\n F(NameOne)\\\n F(NameTwo)\\\n F(NameThree)\\\n\n#define DECLARE_FUNCTION(N)\\\n void N();\n\n#define IMPLEMENT_FUNCTION(N)\\\n void N(){}\n\nFOR_ALL_FUNCTIONS(DECLARE_FUNCTION);\nFOR_ALL_FUNCTIONS(IMPLEMENT_FUNCTION);\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126277", "https://Stackoverflow.com", "https://Stackoverflow.com/users/46478/" ]
126,279
<p>To my amazement I just discovered that the C99 stdint.h is missing from MS Visual Studio 2003 upwards. I'm sure they have their reasons, but does anyone know where I can download a copy? Without this header I have no definitions for useful types such as uint32_t, etc.</p>
[ { "answer_id": 127166, "author": "Nicholas Mancuso", "author_id": 8945, "author_profile": "https://Stackoverflow.com/users/8945", "pm_score": 6, "selected": false, "text": "#ifdef _MSC_VER\n\ntypedef __int32 int32_t;\ntypedef unsigned __int32 uint32_t;\ntypedef __int64 int64_t;\ntypedef unsigned __int64 uint64_t;\n\n#else\n#include <stdint.h>\n#endif\n" }, { "answer_id": 2628014, "author": "Ashwin Nanjappa", "author_id": 1630, "author_profile": "https://Stackoverflow.com/users/1630", "pm_score": 6, "selected": false, "text": "stdint.h C:\\Program Files\\Microsoft Visual Studio 10.0\\VC\\include" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126279", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9236/" ]
126,297
<p>After I <a href="https://stackoverflow.com/questions/121922/automatic-casts">messed up the description of my previous post</a> on this I have sat down and tried to convey my exact intent.</p> <p>I have a class called P which performs some distinct purpose. I also have PW which perform some distinct purpose on P. PW has no member variables, just member functions.</p> <p>From this description you would assume that the code would follow like this:</p> <pre><code>class P { public: void a( ); }; class PW { public: PW( const P&amp; p ) : p( p ) { } void b( ); P&amp; p; }; class C { public: P GetP( ) const { return p; } private: P p; }; // ... PW&amp; p = c.GetP( ); // valid // ... </code></pre> <p>However that brings up a problem. I can't call the functions of P without indirection everywhere.</p> <pre><code>// ... p-&gt;p-&gt;a( ) // ... </code></pre> <p><strong>What I would like to do is call p->a( ) and have it automatically determine that I would like to call the member function of P.</strong></p> <p>Also having a member of PW called <em>a</em> doesn't really scale - what if I add (or remove) another function to P - this will need to be added (or removed) to PW.</p>
[ { "answer_id": 126446, "author": "Luc Touraille", "author_id": 20984, "author_profile": "https://Stackoverflow.com/users/20984", "pm_score": 3, "selected": true, "text": "class P\n{\n public:\n void a( ) { std::cout << \"a\" << std::endl; }\n};\n\nclass PW\n{\n public:\n PW(P& p) : p(p) { }\n\n void b( ) { std::cout << \"b\" << std::endl; }\n\n P & operator*() { return p; }\n P * operator->() { return &p; }\n\n private:\n P & p;\n};\n\nclass C\n{\n public:\n P & getP() { return p; }\n\n private:\n P p;\n};\n\n\nint main()\n{\n C c;\n PW pw(c.getP());\n\n (*pw).a();\n pw->a();\n pw.b();\n\n return EXIT_SUCCESS;\n}\n a\na\nb\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126297", "https://Stackoverflow.com", "https://Stackoverflow.com/users/342/" ]
126,320
<p>Suppose I have a set of commits in a repository folder...</p> <pre><code>123 (250 new files, 137 changed files, 14 deleted files) 122 (150 changed files) 121 (renamed folder) 120 (90 changed files) 119 (115 changed files, 14 deleted files, 12 added files) 118 (113 changed files) 117 (10 changed files) </code></pre> <p>I want to get a working copy that includes all changes from revision 117 onward but does NOT include the changes for revisions 118 and 120.</p> <p>EDIT: To perhaps make the problem clearer, I want to undo the changes that were made in 118 and 120 while retaining all other changes. The folder contains thousands of files in hundreds of subfolders.</p> <p>What is the best way to achieve this?</p> <p><strong>The answer</strong>, thanks to Bruno and Bert, is the command (in this case, for removing 120 after the full merge was performed)</p> <pre><code>svn merge -c -120 . </code></pre> <p>Note that the revision number must be specified with a leading minus. '-120' not '120'</p>
[ { "answer_id": 126357, "author": "Christian Davén", "author_id": 12534, "author_profile": "https://Stackoverflow.com/users/12534", "pm_score": -1, "selected": false, "text": "svn copy -r 117 source destination\n svnmerge.py merge -r119,120-123 svn merge" }, { "answer_id": 126411, "author": "Bruno De Fraine", "author_id": 6918, "author_profile": "https://Stackoverflow.com/users/6918", "pm_score": 6, "selected": true, "text": "svn up -r HEAD # get latest revision\nsvn merge -c -120 . # undo revision 120\nsvn merge -c -118 . # undo revision 118\nsvn commit # after solving problems (if any)\n -c -120 -c --change -r 120:119" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126320", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4200/" ]
126,331
<p>I'm calling a non-.NET dll from my project using P/Invoke, meaning that the .dll must always be present in the .exe's directory. </p> <p>Is there any way to tell Visual Studio of this dependency, so that it will automatically copy the .dll to the output directory when compiling, and will automatically include the .dll in the setup? Or do I have to do this manually?</p>
[ { "answer_id": 126351, "author": "Magnus Johansson", "author_id": 3584, "author_profile": "https://Stackoverflow.com/users/3584", "pm_score": 3, "selected": false, "text": "Properties Build Action Content Copy to Output Directory Copy if newer" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126331", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6448/" ]
126,332
<p>I'm wanting a method called same_url? that will return true if the passed in URLs are equal. The passed in URLs might be either params options hash or strings.</p> <pre><code>same_url?({:controller =&gt; :foo, :action =&gt; :bar}, "http://www.example.com/foo/bar") # =&gt; true </code></pre> <p>The Rails Framework helper <a href="http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#M001607" rel="nofollow noreferrer">current_page?</a> seems like a good starting point but I'd like to pass in an arbitrary number of URLs.</p> <p>As an added bonus It would be good if a hash of params to exclude from the comparison could be passed in. So a method call might look like:</p> <pre><code>same_url?(projects_path(:page =&gt; 2), "projects?page=3", :excluding =&gt; :page) # =&gt; true </code></pre>
[ { "answer_id": 126693, "author": "Codebeef", "author_id": 12037, "author_profile": "https://Stackoverflow.com/users/12037", "pm_score": 1, "selected": false, "text": "def same_url?(one, two)\n url_for(one) == url_for(two)\nend\n" }, { "answer_id": 126816, "author": "Dave Nolan", "author_id": 9474, "author_profile": "https://Stackoverflow.com/users/9474", "pm_score": 3, "selected": false, "text": "def same_page?(a, b, params_to_exclude = {})\n if a.respond_to?(:except) && b.respond_to?(:except)\n url_for(a.except(params_to_exclude)) == url_for(b.except(params_to_exclude))\n else\n url_for(a) == url_for(b)\n end\nend\n except class Hash\n # Usage { :a => 1, :b => 2, :c => 3}.except(:a) -> { :b => 2, :c => 3}\n def except(*keys)\n self.reject { |k,v|\n keys.include? k.to_sym\n }\n end\nend\n except" }, { "answer_id": 648828, "author": "kch", "author_id": 13989, "author_profile": "https://Stackoverflow.com/users/13989", "pm_score": 0, "selected": false, "text": "def all_urls_same_as_current? *params_for_urls\n params_for_urls.map do |a_url_hash| \n url_for a_url_hash.except(*exclude_keys)\n end.all? do |a_url_str|\n a_url_str == request.request_uri\n end\nend\n params_for_urls exclude_keys request.request_uri" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126332", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19588/" ]
126,367
<p>This is kind of hard to explain, I hope my English is sufficient:</p> <p>I have a class "A" which should maintain a list of objects of class "B" (like a private List). A consumer of class "A" should be able to add items to the list. After the items are added to the list, the consumer should not be able to modify them again, left alone that he should not be able to temper with the list itself (add or remove items). But he should be able to enumerate the items in the list and get their values. Is there a pattern for it? How would you do that? </p> <p>If the question is not clear enough, please let me know.</p>
[ { "answer_id": 126374, "author": "Jorge Ferreira", "author_id": 6508, "author_profile": "https://Stackoverflow.com/users/6508", "pm_score": 0, "selected": false, "text": "namespace ConsoleApplication2\n{\n using System;\n using System.Collections.Generic;\n using System.Collections;\n\n class B\n {\n }\n\n interface IEditable\n {\n void StartEdit();\n void StopEdit();\n }\n\n class EditContext<T> : IDisposable where T : IEditable\n {\n private T parent;\n\n public EditContext(T parent)\n {\n parent.StartEdit();\n this.parent = parent;\n }\n\n public void Dispose()\n {\n this.parent.StopEdit();\n }\n }\n\n class A : IEnumerable<B>, IEditable\n {\n private List<B> _myList = new List<B>();\n private bool editable;\n\n public void Add(B o)\n {\n if (!editable)\n {\n throw new NotSupportedException();\n }\n _myList.Add(o);\n }\n\n public EditContext<A> ForEdition()\n {\n return new EditContext<A>(this);\n }\n\n public IEnumerator<B> GetEnumerator()\n {\n return _myList.GetEnumerator();\n }\n\n IEnumerator IEnumerable.GetEnumerator()\n {\n return this.GetEnumerator();\n }\n\n public void StartEdit()\n {\n this.editable = true;\n }\n\n public void StopEdit()\n {\n this.editable = false;\n }\n }\n\n class Program\n {\n static void Main(string[] args)\n {\n A a = new A();\n using (EditContext<A> edit = a.ForEdition())\n {\n a.Add(new B());\n a.Add(new B());\n }\n\n foreach (B o in a)\n {\n Console.WriteLine(o.GetType().ToString());\n }\n\n a.Add(new B());\n\n Console.ReadLine();\n }\n }\n}\n" }, { "answer_id": 126429, "author": "Paul van Brenk", "author_id": 1837197, "author_profile": "https://Stackoverflow.com/users/1837197", "pm_score": 0, "selected": false, "text": "public class MyList<T> : IEnumerable<T>{\n\n public MyList(IEnumerable<T> source){\n data.AddRange(source);\n }\n\n public IEnumerator<T> GetEnumerator(){\n return data.Enumerator();\n }\n\n private List<T> data = new List<T>();\n}\n" }, { "answer_id": 126434, "author": "Chris Ballard", "author_id": 18782, "author_profile": "https://Stackoverflow.com/users/18782", "pm_score": 0, "selected": false, "text": "internal class B : IB\n{\n private string someData;\n\n public string SomeData\n {\n get { return someData; }\n set { someData = value; }\n }\n}\n\npublic interface IB\n{\n string SomeData { get; }\n}\n" }, { "answer_id": 126451, "author": "jop", "author_id": 11830, "author_profile": "https://Stackoverflow.com/users/11830", "pm_score": 0, "selected": false, "text": "public IList ListOfB\n{\n get \n {\n if (_readOnlyMode) \n return listOfB.AsReadOnly(); // also use ArrayList.ReadOnly(listOfB);\n else\n return listOfB;\n }\n}\n" }, { "answer_id": 126532, "author": "Matt Hinze", "author_id": 2676, "author_profile": "https://Stackoverflow.com/users/2676", "pm_score": 0, "selected": false, "text": "List<T> public void AddItem(T item) public T[] GetItems() return _theList.ToArray()" }, { "answer_id": 127007, "author": "Seb Rose", "author_id": 12405, "author_profile": "https://Stackoverflow.com/users/12405", "pm_score": 1, "selected": false, "text": "class B\n{\n public B(int data) \n { \n this.data = data; \n }\n\n public int data\n {\n get { return privateData; }\n set { privateData = value; }\n }\n\n private int privateData;\n}\n\nclass ProxyB\n{\n public ProxyB(B b) \n { \n actual = b; \n }\n\n public int data\n {\n get { return actual.data; }\n }\n\n private B actual;\n}\n\nclass A : IEnumerable<ProxyB>\n{\n private List<B> bList = new List<B>();\n\n class ProxyEnumerator : IEnumerator<ProxyB>\n {\n private IEnumerator<B> b_enum;\n\n public ProxyEnumerator(IEnumerator<B> benum)\n {\n b_enum = benum;\n }\n\n public bool MoveNext()\n {\n return b_enum.MoveNext();\n }\n\n public ProxyB Current\n {\n get { return new ProxyB(b_enum.Current); }\n }\n\n Object IEnumerator.Current\n {\n get { return this.Current; }\n }\n\n public void Reset()\n {\n b_enum.Reset();\n }\n\n public void Dispose()\n {\n b_enum.Dispose();\n }\n }\n\n public void AddB(B b) { bList.Add(b); }\n\n public IEnumerator<ProxyB> GetEnumerator()\n {\n return new ProxyEnumerator(bList.GetEnumerator());\n }\n\n IEnumerator IEnumerable.GetEnumerator()\n {\n return this.GetEnumerator();\n }\n}\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126367", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16440/" ]
126,373
<p>I write a lot of dynamically generated content (developing under PHP) and I use jQuery to add extra flexibility and functionality to my projects.</p> <p>Thing is that it's rather hard to add JavaScript in an unobtrusive manner. Here's an example:</p> <p>You have to generate a random number of <code>div</code> elements each with different functionality triggered <code>onClick</code>. I can use the <code>onclick</code> attribute on my <code>div</code> elements to call a JS function with a parameter but that is just a bad solution. Also I could generate some jQuery code along with each div in my PHP <code>for</code> loop, but then again this won't be entirely unobtrusive.</p> <p>So what's the solution in situations like this?</p>
[ { "answer_id": 126398, "author": "roryf", "author_id": 270, "author_profile": "https://Stackoverflow.com/users/270", "pm_score": 3, "selected": false, "text": "<div class=\"odd\">...</div>\n<div class=\"even\">...</div>\n<div class=\"odd\">...</div>\n<div class=\"even\">...</div>\n $(document).load(function() {\n$('.odd').click(function(el) {\n// do stuff\n});\n$('.even').click(function(el) {\n// dostuff\n});\n});\n" }, { "answer_id": 126404, "author": "Andrew Hedges", "author_id": 11577, "author_profile": "https://Stackoverflow.com/users/11577", "pm_score": 0, "selected": false, "text": "<div class=\"section-1\">\n <div></div>\n</div>\n<div class=\"section-2\">\n <div></div>\n</div>\n $('.section-1 div').onclick(...one set of functionality...);\n$('.section-2 div').onclick(...another set of functionality...);\n" }, { "answer_id": 126464, "author": "cllpse", "author_id": 20946, "author_profile": "https://Stackoverflow.com/users/20946", "pm_score": 1, "selected": false, "text": "<ul>\n <li handler=\"doAlertOne\"></li>\n <li handler=\"doAlertTwo\"></li>\n <li handler=\"doAlertThree\"></li>\n</ul>\n function doAlertOne() { }\nfunction doAlertTwo() { }\nfunction doAlertThree() { }\n $(\"ul li\").each(function ()\n{\n switch($(this).attr(\"handler\"))\n {\n case \"doAlertOne\":\n doAlertOne();\n break;\n\n case ... etc.\n }\n});\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126373", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20603/" ]
126,381
<p>I am looking for a hash-algorithm, to create as close to a unique hash of a string (max len = 255) as possible, that produces a long integer (DWORD).</p> <p>I realize that 26^255 >> 2^32, but also know that the number of words in the English language is far less than 2^32.</p> <p>The strings I need to 'hash' would be mostly single words or some simple construct using two or three words.</p> <hr> <p><strong>The answer</strong>:</p> <p>One of the <a href="http://isthe.com/chongo/tech/comp/fnv/" rel="nofollow noreferrer">FNV variants</a> should meet your requirements. They're fast, and produce fairly evenly distributed outputs. (Answered by <a href="https://stackoverflow.com/users/12030/arachnid">Arachnid</a>)</p> <hr>
[ { "answer_id": 126391, "author": "Armin Ronacher", "author_id": 19990, "author_profile": "https://Stackoverflow.com/users/19990", "pm_score": 1, "selected": false, "text": "static long\nstring_hash(PyStringObject *a)\n{\n register Py_ssize_t len;\n register unsigned char *p;\n register long x;\n\n if (a->ob_shash != -1)\n return a->ob_shash;\n len = Py_SIZE(a);\n p = (unsigned char *) a->ob_sval;\n x = *p << 7;\n while (--len >= 0)\n x = (1000003*x) ^ *p++;\n x ^= Py_SIZE(a);\n if (x == -1)\n x = -2;\n a->ob_shash = x;\n return x;\n}\n" }, { "answer_id": 126407, "author": "Stephen Denne", "author_id": 11721, "author_profile": "https://Stackoverflow.com/users/11721", "pm_score": 0, "selected": false, "text": "s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126381", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15161/" ]
126,385
<p>In our game project we did have a timer loop set to fire about 20 times a second (the same as the application framerate). We use this to move some sprites around. I'm wondering if this could cause problems and we should instead do our updates using an EnterFrame event handler? I get the impression that having a timer loop run faster than the application framerate is likely to cause problems... is this the case?</p> <p>As an update, trying to do it on EnterFrame caused very weird problems. Instead of a frame every 75ms, suddenly it jumped to 25ms. Note, it wasn't just our calculation <em>claimed</em> the framerate was different, suddenly the animations sped up to a crazy rate.</p>
[ { "answer_id": 131216, "author": "fenomas", "author_id": 10651, "author_profile": "https://Stackoverflow.com/users/10651", "pm_score": 2, "selected": false, "text": "ENTER_FRAME updateAfterEvent()" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126385", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13220/" ]
126,401
<p>Debugging some finance-related SQL code found a strange issue with numeric(24,8) mathematics precision.</p> <p>Running the following query on your MSSQL you would get A + B * C expression result to be 0.123457</p> <p>SELECT A, B, C, A + B * C FROM ( SELECT CAST(0.12345678 AS NUMERIC(24,8)) AS A, CAST(0 AS NUMERIC(24,8)) AS B, CAST(500 AS NUMERIC(24,8)) AS C ) T</p> <p>So we have lost 2 significant symbols. Trying to get this fixed in different ways i got that conversion of the intermediate multiplication result (which is Zero!) to numeric (24,8) would work fine.</p> <p>And finally a have a solution. But still I hace a question - why MSSQL behaves in this way and which type conversions actually occured in my sample?</p>
[ { "answer_id": 126473, "author": "Eugene Yokota", "author_id": 3827, "author_profile": "https://Stackoverflow.com/users/3827", "pm_score": 4, "selected": true, "text": "NUMERIC(24,8) NUMERIC(24,8) SELECT A, B, C, A + B * C\nFROM ( SELECT CAST(0.12345678 AS NUMERIC(24,8)) AS A,\n CAST(0 AS NUMERIC(24,8)) AS B,\n CAST(500 AS NUMERIC(24,8)) AS C ) T\n SELECT A, B, C, A + D\nFROM ( SELECT CAST(0.12345678 AS NUMERIC(24,8)) AS A,\n CAST(0 AS NUMERIC(24,8)) AS B,\n CAST(500 AS NUMERIC(24,8)) AS C,\n CAST(0 AS NUMERIC(38,6)) AS D ) T\n NUMERIC(24,8) NUMERIC(38,6) A + D SELECT CAST(0.12345678 AS NUMERIC(38,6))\n 0.123457" }, { "answer_id": 126713, "author": "kristof", "author_id": 3241, "author_profile": "https://Stackoverflow.com/users/3241", "pm_score": 0, "selected": false, "text": "create function dbo.myMath(@a as numeric(24,8), @b as numeric(24,8), @c as numeric(24,8))\nreturns numeric(24,8)\nas\nbegin \n declare @d as numeric(24,8)\n set @d = @b* @c\n return @a + @d\nend\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126401", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21603/" ]
126,406
<p>I would like to change the database files location of MySQL administrator to another drive of my computer. (I run Windows XP SP2 and MySQL Administrator 1.2.8.)</p> <p>--Under the startup variable --> General Parameters --> I changed <code>Data directory:</code> from <code>C:/Program Files/MySQL/MySQL Server 5.0/data</code> to <code>D:/.....</code>, but after I stopped the service and restarted it, the following error appeared: </p> <pre><code>Could not re-connect to the MySQL Server. Server could not be started. Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist </code></pre> <p>Has anyone else had this problem? </p>
[ { "answer_id": 126420, "author": "Armin Ronacher", "author_id": 19990, "author_profile": "https://Stackoverflow.com/users/19990", "pm_score": 5, "selected": true, "text": "[mysqld] [mysqld_safe] datadir basedir" }, { "answer_id": 13462057, "author": "ajcw", "author_id": 310174, "author_profile": "https://Stackoverflow.com/users/310174", "pm_score": 3, "selected": false, "text": "C:\\Program Files\\MySQL\\MySQL Server 5.4\\ my.ini C:\\Documents and Settings\\All Users\\Application Data\\MySQL\\MySQL Server 5.4\\data\\" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126406", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21608/" ]
126,409
<p>What are the ways to eliminate the use of switch in code?</p>
[ { "answer_id": 126415, "author": "Bernard", "author_id": 61, "author_profile": "https://Stackoverflow.com/users/61", "pm_score": 4, "selected": false, "text": "if else" }, { "answer_id": 126417, "author": "Josh", "author_id": 11702, "author_profile": "https://Stackoverflow.com/users/11702", "pm_score": 5, "selected": false, "text": "void InitMap(){\n Map[key1] = Object/Action;\n Map[key2] = Object/Action;\n}\n\nObject/Action DoStuff(Object key){\n return Map[key];\n}\n" }, { "answer_id": 126455, "author": "mlarsen", "author_id": 17700, "author_profile": "https://Stackoverflow.com/users/17700", "pm_score": 9, "selected": true, "text": "foreach (var animal in zoo) {\n switch (typeof(animal)) {\n case \"dog\":\n echo animal.bark();\n break;\n\n case \"cat\":\n echo animal.meow();\n break;\n }\n}\n foreach (var animal in zoo) {\n echo animal.speak();\n}\n" }, { "answer_id": 126466, "author": "seanyboy", "author_id": 1726, "author_profile": "https://Stackoverflow.com/users/1726", "pm_score": -1, "selected": false, "text": " if a = 1 then \n do something else \n if a = 2 then \n do something else\n else \n if a = 3 then \n do the last thing\n endif\n endif \n endif\n if a = 1 then \n do something\nendif \nif a = 2 then \n do something else\nendif \nif a = 3 then \n do something more\nendif \n procedure processA(a:int)\n if a = 1 then \n do something\n procedure_return\n endif \n if a = 2 then \n do something else\n procedure_return\n endif \n if a = 3 then \n do something more\n procedure_return\n endif \nend_procedure\n private void doLog(LogLevel logLevel, String msg) {\n String prefix;\n switch (logLevel) {\n case INFO:\n prefix = \"INFO\";\n break;\n case WARN:\n prefix = \"WARN\";\n break;\n case ERROR:\n prefix = \"ERROR\";\n break;\n default:\n throw new RuntimeException(\"Oops, forgot to add stuff on new enum constant\");\n }\n System.out.println(String.format(\"%s: %s\", prefix, msg));\n }\n for i from 1 to 1000 {statement1; statement2}\nif something=false then {statement1; statement2}\nwhile isOKtoLoop {statement1; statement2}\n" }, { "answer_id": 126475, "author": "toolkit", "author_id": 3295, "author_profile": "https://Stackoverflow.com/users/3295", "pm_score": 8, "selected": false, "text": "class RequestHandler {\n\n public void handleRequest(int action) {\n switch(action) {\n case LOGIN:\n doLogin();\n break;\n case LOGOUT:\n doLogout();\n break;\n case QUERY:\n doQuery();\n break;\n }\n }\n}\n interface Command {\n public void execute();\n}\n\nclass LoginCommand implements Command {\n public void execute() {\n // do what doLogin() used to do\n }\n}\n\nclass RequestHandler {\n private Map<Integer, Command> commandMap; // injected in, or obtained from a factory\n public void handleRequest(int action) {\n Command command = commandMap.get(action);\n command.execute();\n }\n}\n" }, { "answer_id": 126575, "author": "jamesh", "author_id": 4737, "author_profile": "https://Stackoverflow.com/users/4737", "pm_score": 3, "selected": false, "text": "switch switch case switch if - else IState switch case switch IState" }, { "answer_id": 127933, "author": "Cheery", "author_id": 21711, "author_profile": "https://Stackoverflow.com/users/21711", "pm_score": 1, "selected": false, "text": "switch(*IP) {\n case OPCODE_ADD:\n ...\n break;\n case OPCODE_NOT_ZERO:\n ...\n break;\n case OPCODE_JUMP:\n ...\n break;\n default:\n fixme(*IP);\n}\n opcode_table[*IP](*IP, vm);\n\n... // in somewhere else:\nvoid opcode_add(byte_opcode op, Vm* vm) { ... };\nvoid opcode_not_zero(byte_opcode op, Vm* vm) { ... };\nvoid opcode_jump(byte_opcode op, Vm* vm) { ... };\nvoid opcode_default(byte_opcode op, Vm* vm) { /* fixme */ };\n\nOpcodeFuncPtr opcode_table[256] = {\n ...\n opcode_add,\n opcode_not_zero,\n opcode_jump,\n opcode_default,\n opcode_default,\n ... // etc.\n};\n" }, { "answer_id": 318339, "author": "Sheraz", "author_id": 40723, "author_profile": "https://Stackoverflow.com/users/40723", "pm_score": 2, "selected": false, "text": "public class Animal\n{\n public abstract void Speak();\n}\n\n\npublic class Dog : Animal\n{\n public virtual void Speak()\n {\n Console.WriteLine(\"Hao Hao\");\n }\n}\n\npublic class Cat : Animal\n{\n public virtual void Speak()\n {\n Console.WriteLine(\"Meauuuu\");\n }\n}\n foreach (var animal in zoo) \n{\n echo animal.speak();\n}\n" }, { "answer_id": 31155996, "author": "Premraj", "author_id": 1697099, "author_profile": "https://Stackoverflow.com/users/1697099", "pm_score": 2, "selected": false, "text": "function getItemPricing(customer, item) {\n switch (customer.type) {\n // VIPs are awesome. Give them 50% off.\n case 'VIP':\n return item.price * item.quantity * 0.50;\n\n // Preferred customers are no VIPs, but they still get 25% off.\n case 'Preferred':\n return item.price * item.quantity * 0.75;\n\n // No discount for other customers.\n case 'Regular':\n case\n default:\n return item.price * item.quantity;\n }\n}\n function getItemPricing(customer, item) {\nvar pricing = {\n 'VIP': function(item) {\n return item.price * item.quantity * 0.50;\n },\n 'Preferred': function(item) {\n if (item.price <= 100.0)\n return item.price * item.quantity * 0.75;\n\n // Else\n return item.price * item.quantity;\n },\n 'Regular': function(item) {\n return item.price * item.quantity;\n }\n};\n\n if (pricing[customer.type])\n return pricing[customer.type](item);\n else\n return pricing.Regular(item);\n}\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126409", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12514/" ]
126,430
<p>Is it possible to change the natural order of columns in Postgres 8.1?</p> <p>I know that you shouldn't rely on column order - it's not <em>essential</em> to what I am doing - I only need it to make some auto-generated stuff come out in a way that is more pleasing, so that the field order matches all the way from pgadmin through the back end and out to the front end.</p>
[ { "answer_id": 126437, "author": "Vinko Vrsalovic", "author_id": 5190, "author_profile": "https://Stackoverflow.com/users/5190", "pm_score": 0, "selected": false, "text": "postgres=# create table a(a int, b int, c int);\nCREATE TABLE\npostgres=# insert into a values (1,2,3);\nINSERT 0 1\npostgres=# select * from a;\n a | b | c\n---+---+---\n 1 | 2 | 3\n(1 row)\n\npostgres=# alter table a add column a2 int;\nALTER TABLE\npostgres=# select * from a;\n a | b | c | a2\n---+---+---+----\n 1 | 2 | 3 |\n(1 row)\n\npostgres=# update a set a2 = a;\nUPDATE 1\npostgres=# alter table a drop column a;\nALTER TABLE\npostgres=# alter table a rename column a2 to a;\nALTER TABLE\npostgres=# select * from a;\n b | c | a\n---+---+---\n 2 | 3 | 1\n(1 row)\n\npostgres=#\n" }, { "answer_id": 126749, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "drop your_table --create a table where column bar comes before column baz:\nCREATE TABLE foo ( moo integer, bar character varying(10), baz date ); \n\n--insert some data\ninsert into foo (moo, bar, baz) values (34, 'yadz', now()); \ninsert into foo (moo, bar, baz) values (12, 'blerp', now()); \nselect * from foo; \n ┌─────┬───────┬────────────┐ \n │ moo │ bar │ baz │ \n ├─────┼───────┼────────────┤ \n │ 34 │ yadz │ 2021-04-07 │ \n │ 12 │ blerp │ 2021-04-07 │ \n └─────┴───────┴────────────┘ \n\n-- Define your reordered columns here, don't forget one, \n-- or it'll be missing from the replacement.\ndrop view if exists my_view;\ncreate view my_view as ( select moo, baz, bar from foo );\nselect * from my_view; \n\nDROP TABLE IF EXISTS foo2; \n--foo2 is your replacement table that has columns ordered correctly\ncreate table foo2 as select * from my_view; \nselect * from foo2;\n--finally drop the view and the original table and rename\nDROP VIEW my_view; \nDROP TABLE foo; \nALTER TABLE foo2 RENAME TO foo; \n\n--observe the reordered columns:\nselect * from foo;\n ┌─────┬────────────┬───────┐ \n │ moo │ baz │ bar │ \n ├─────┼────────────┼───────┤ \n │ 34 │ 2021-04-07 │ yadz │ \n │ 12 │ 2021-04-07 │ blerp │ \n └─────┴────────────┴───────┘ \n SELECT string_agg(column_name, ',') from ( \n select * FROM INFORMATION_SCHEMA.COLUMNS \n WHERE table_name = 'your_big_table' \n order by ordinal_position asc \n) f1;\n column_name_1,column_name_2, ..., column_name_n\n" }, { "answer_id": 127507, "author": "Tometzky", "author_id": 15862, "author_profile": "https://Stackoverflow.com/users/15862", "pm_score": 4, "selected": false, "text": "pg_dump --create --column-inserts databasename > databasename.pgdump.sql CREATE TABLE split cat drop database databasename psql --single-transaction -f databasename.pgdump.sql --single-transaction" }, { "answer_id": 40898553, "author": "Alex Willison", "author_id": 7221965, "author_profile": "https://Stackoverflow.com/users/7221965", "pm_score": 1, "selected": false, "text": "CREATE TABLE test_new AS SELECT b, c, a FROM test;\nSELECT * from test_new;\n b | c | a \n---+---+---\n 2 | 3 | 1\n(1 row)\n BEGIN;\nDROP TABLE test;\nALTER TABLE test_new RENAME TO test;\nCOMMIT;\n" }, { "answer_id": 48573607, "author": "Turgs", "author_id": 426935, "author_profile": "https://Stackoverflow.com/users/426935", "pm_score": 3, "selected": false, "text": "id, name, email\n email name CREATE TABLE mytable_tmp\n(\n id SERIAL PRIMARY KEY,\n email text,\n name text\n);\n INSERT INTO mytable_tmp --- << new tmp table\n(\n id\n, email\n, name\n)\nSELECT\n id\n, email\n, name\nFROM mytable; --- << this is the existing table\n DROP TABLE mytable;\n ALTER TABLE mytable_tmp RENAME TO mytable;\n CREATE INDEX ...\n SELECT setval('public.mytable_id_seq', max(id)) FROM mytable;\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126430", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3408/" ]
126,431
<p>For a report in MS Access (2007) I need to put data of some columns on all odd pages and other columns on all even pages. It is for printing out double sided card files onto sheets of paper.</p> <p>Does somebody have an idea how to do that?</p>
[ { "answer_id": 127621, "author": "BIBD", "author_id": 685, "author_profile": "https://Stackoverflow.com/users/685", "pm_score": 1, "selected": false, "text": "A B \nC D\n A\nB\nC\nD\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126431", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
126,445
<p>I am implementing a design that uses custom styled submit-buttons. They are quite simply light grey buttons with a slightly darker outer border:</p> <pre><code>input.button { background: #eee; border: 1px solid #ccc; } </code></pre> <p>This looks just right in Firefox, Safari and Opera. The problem is with Internet Explorer, both 6 and 7. </p> <p>Since the form is the first one on the page, it's counted as the main form - and thus active from the get go. The first submit button in the active form receives a solid black border in IE, to mark it as the main action.</p> <p>If I turn off borders, then the black extra border in IE goes away too. I am looking for a way to keep my normal borders, but remove the outline.</p>
[ { "answer_id": 126474, "author": "Oli", "author_id": 12870, "author_profile": "https://Stackoverflow.com/users/12870", "pm_score": 1, "selected": false, "text": "<span> span.button {\n background: #eee;\n border: 1px solid #ccc;\n}\n\nspan.button input {\n background: #eee;\n border:0;\n}\n <span class=\"button\"><input type=\"button\" name=\"...\" value=\"Button\"/></span>\n" }, { "answer_id": 126476, "author": "Lasar", "author_id": 9438, "author_profile": "https://Stackoverflow.com/users/9438", "pm_score": 0, "selected": false, "text": "<button><span>Go</span></button>\n" }, { "answer_id": 126482, "author": "Magnar", "author_id": 1123, "author_profile": "https://Stackoverflow.com/users/1123", "pm_score": 1, "selected": false, "text": "<div class='submit_button'><input type=\"submit\" class=\"button\"></div>\n .submit_button { width: 150px; border: 1px solid #ccc; }\n.submit_button .button { width: 150px; border: none; }\n" }, { "answer_id": 126517, "author": "Oli", "author_id": 12870, "author_profile": "https://Stackoverflow.com/users/12870", "pm_score": 6, "selected": true, "text": "<html>\n <head>\n <style type=\"text/css\">\n span.button {\n background: #eee;\n border: 1px solid #ccc;\n }\n\n span.button input {\n background:none;\n border:0;\n margin:0;\n padding:0;\n } \n </style>\n </head>\n <body>\n <span class=\"button\"><input type=\"button\" name=\"...\" value=\"Button\"/></span>\n </body>\n</html>\n" }, { "answer_id": 785748, "author": "nickmorss", "author_id": 91007, "author_profile": "https://Stackoverflow.com/users/91007", "pm_score": 5, "selected": false, "text": "<!--[if IE]>\n<style type=\"text/css\">\ninput {\nfilter:chroma(color=#000000);\nborder:none;\n}\n</style>\n<![endif]-->\n" }, { "answer_id": 2210717, "author": "Benxamin", "author_id": 218119, "author_profile": "https://Stackoverflow.com/users/218119", "pm_score": 0, "selected": false, "text": "spans button button <button><span class=\"open\">Search<span class=\"close\"></span></span></button>\n" }, { "answer_id": 2726037, "author": "rexusdiablos", "author_id": 327374, "author_profile": "https://Stackoverflow.com/users/327374", "pm_score": 2, "selected": false, "text": "<form><fieldset><input type=\"submit\"></fieldset></form>\n" }, { "answer_id": 3365781, "author": "David Murdoch", "author_id": 160173, "author_profile": "https://Stackoverflow.com/users/160173", "pm_score": 3, "selected": false, "text": "input type=\"submit\" <input type=\"submit\" value=\"\" style=\"height:0;overflow:auto;position:absolute;left:-9999px;\" />\n <!doctype html>" }, { "answer_id": 8054579, "author": "Holf", "author_id": 169334, "author_profile": "https://Stackoverflow.com/users/169334", "pm_score": 2, "selected": false, "text": "// Test for IE7.\nif ($.browser.msie && parseInt($.browser.version, 10) == 7) {\n $('<input type=\"submit\" value=\"\" style=\"height:0;overflow:auto;position:absolute;left:-9999px;\" />')\n.insertBefore(\"input:submit\");\n }\n" }, { "answer_id": 8130571, "author": "Tyler", "author_id": 539300, "author_profile": "https://Stackoverflow.com/users/539300", "pm_score": 0, "selected": false, "text": "<input type=\"submit\" value=\"Go\" style=\"display:none;\" id=\"WorkaroundForOperaInputFocusBorderBug\" />\n<input type=\"submit\" value=\"Go\" />\n" }, { "answer_id": 8661062, "author": "Drew Chapin", "author_id": 1017257, "author_profile": "https://Stackoverflow.com/users/1017257", "pm_score": 2, "selected": false, "text": "<!--[if IE]>\n<style type=\"text/css\">\n input[type=\"submit\"], input[type=\"button\"], button\n {\n border: none !important;\n filter: progid:DXImageTransform.Microsoft.glow(color=#d0d0d0,strength=1);\n height: 24px; /* I had to adjust the height from the original value */\n }\n</style>\n<![endif]-->\n" }, { "answer_id": 8741469, "author": "Gregor", "author_id": 536082, "author_profile": "https://Stackoverflow.com/users/536082", "pm_score": 0, "selected": false, "text": ".submitbutton { \nbackground-color: #fff;\nborder: #fff dotted 1px; \n}\n" }, { "answer_id": 9291644, "author": "Luca Fagioli", "author_id": 636561, "author_profile": "https://Stackoverflow.com/users/636561", "pm_score": 1, "selected": false, "text": "input[type=button]\n{\n filter:chroma(color=#000000);\n}\n button background-image" }, { "answer_id": 12828931, "author": "curly_brackets", "author_id": 315200, "author_profile": "https://Stackoverflow.com/users/315200", "pm_score": 1, "selected": false, "text": "outline: none;\n" }, { "answer_id": 27618972, "author": "Shubh", "author_id": 769678, "author_profile": "https://Stackoverflow.com/users/769678", "pm_score": 0, "selected": false, "text": "<!--[if IE]>\n <style type=\"text/css\">\n input[type=submit],input[type=reset],input[type=button]\n {\n filter:chroma(color=#000000);\n color:#010101;\n }\n </style>\n<![endif]-->\n @Mark's" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126445", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1123/" ]
126,465
<p>If I want to create the registry key</p> <blockquote> <p>HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Application\MyApp</p> </blockquote> <p>with the string value</p> <blockquote> <p>EventMessageFile : C:\Path\To\File.dll</p> </blockquote> <p>how do I define this in my <a href="http://en.wikipedia.org/wiki/WiX" rel="nofollow noreferrer">WiX</a> 3.0 WXS file? Examples of what the XML should look like is much appreciated.</p>
[ { "answer_id": 126565, "author": "SCdF", "author_id": 1666, "author_profile": "https://Stackoverflow.com/users/1666", "pm_score": 1, "selected": false, "text": "<registry action=\"write\" \n root\"HKLM\" key=\"SYSTEM\\CurrentControlSet\\Services\\Eventlog\\Application\\MyApp\"\n type=\"string\" value=\"EventMessageFile : C:\\Path\\To\\File.dll\" />\n" }, { "answer_id": 126983, "author": "Iain", "author_id": 20457, "author_profile": "https://Stackoverflow.com/users/20457", "pm_score": 1, "selected": false, "text": "<Component Id=\"EventLogRegKeys\" Guid=\"{my guid}\">\n <RegistryKey Id=\"Registry_EventLog\" Root=\"HKLM\" Key=\"SYSTEM\\CurrentControlSet\\Services\\Eventlog\\Application\\MyApp\" Action=\"create\">\n <RegistryValue Id=\"Registry_EventLog_EventSourceDll\" Action=\"write\" KeyPath=\"yes\" Name=\"EventMessageFile\" Type=\"string\" Value=\"C:\\Path\\To\\File.dll\" />\n </RegistryKey> \n</Component>\n" }, { "answer_id": 128037, "author": "Mike Dimmick", "author_id": 6970, "author_profile": "https://Stackoverflow.com/users/6970", "pm_score": 1, "selected": false, "text": "[#filekey] filekey Id File" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126465", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20457/" ]
126,513
<p>I am running following <code>PHP</code> code to interact with a MS Access database.</p> <pre><code>$odbc_con = new COM("ADODB.Connection"); $constr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . $db_path . ";"; $odbc_con -&gt; open($constr); $rs_select = $odbc_con -&gt; execute ("SELECT * FROM Main"); </code></pre> <p>Using <code>($rs_select -&gt; RecordCount)</code> gives -1 though the query is returning non-zero records.</p> <p>(a) What can be the reason? (b) Is there any way out?</p> <p>I have also tried using <code>count($rs_select -&gt; GetRows())</code>. This satisfies the need but looks inefficient as it will involve copying of all the records into an array first.</p>
[ { "answer_id": 126543, "author": "Oli", "author_id": 12870, "author_profile": "https://Stackoverflow.com/users/12870", "pm_score": 0, "selected": false, "text": "$rs_select = $odbc_con -> execute (\"SELECT COUNT(*) FROM Main\");\n" }, { "answer_id": 126603, "author": "Otherside", "author_id": 18697, "author_profile": "https://Stackoverflow.com/users/18697", "pm_score": 1, "selected": false, "text": "SELECT COUNT(*)" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126513", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6561/" ]
126,524
<p>I could swear I've seen the function (or method) that takes a list, like this <code>[3, 7, 19]</code> and makes it into iterable list of tuples, like so: <code>[(0,3), (1,7), (2,19)]</code> to use it instead of:</p> <pre><code>for i in range(len(name_of_list)): name_of_list[i] = something </code></pre> <p>but I can't remember the name and googling "iterate list" gets nothing.</p>
[ { "answer_id": 126533, "author": "Vinko Vrsalovic", "author_id": 5190, "author_profile": "https://Stackoverflow.com/users/5190", "pm_score": 10, "selected": true, "text": ">>> a = [3,4,5,6]\n>>> for i, val in enumerate(a):\n... print i, val\n...\n0 3\n1 4\n2 5\n3 6\n>>>\n" }, { "answer_id": 126535, "author": "PierreBdR", "author_id": 7136, "author_profile": "https://Stackoverflow.com/users/7136", "pm_score": 7, "selected": false, "text": "enumerate list(enumerate([3,7,19]))\n\n[(0, 3), (1, 7), (2, 19)]\n" }, { "answer_id": 127375, "author": "S.Lott", "author_id": 10661, "author_profile": "https://Stackoverflow.com/users/10661", "pm_score": 5, "selected": false, "text": "zip >>> a = [3, 7, 19]\n>>> zip(range(len(a)), a)\n[(0, 3), (1, 7), (2, 19)]\n" }, { "answer_id": 18777094, "author": "Lucas Ribeiro", "author_id": 2055970, "author_profile": "https://Stackoverflow.com/users/2055970", "pm_score": 3, "selected": false, "text": ">>> a = [3, 7, 19]\n>>> map(lambda x: (x, a[x]), range(len(a)))\n[(0, 3), (1, 7), (2, 19)]\n >>> a = [3,7,19]\n>>> [(x, a[x]) for x in range(len(a))]\n[(0, 3), (1, 7), (2, 19)]\n" }, { "answer_id": 35429590, "author": "Sнаđошƒаӽ", "author_id": 3375713, "author_profile": "https://Stackoverflow.com/users/3375713", "pm_score": 2, "selected": false, "text": "enumerate zip list1 = [1, 2, 3, 4, 5]\nlist2 = [10, 20, 30, 40, 50]\nlist3 = [100, 200, 300, 400, 500]\nfor i, (l1, l2, l3) in enumerate(zip(list1, list2, list3)):\n print(i, l1, l2, l3)\n 0 1 10 100\n1 2 20 200\n2 3 30 300\n3 4 40 400\n4 5 50 500\n i ValueError: need more than 2 values to unpack" }, { "answer_id": 36571189, "author": "Harun ERGUL", "author_id": 4104008, "author_profile": "https://Stackoverflow.com/users/4104008", "pm_score": 3, "selected": false, "text": "enumerate result = list(enumerate([1,3,7,12]))\nprint result\n [(0, 1), (1, 3), (2, 7),(3,12)]\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126524", "https://Stackoverflow.com", "https://Stackoverflow.com/users/37141/" ]
126,526
<p>Has anyone got any suggestions for unit testing a Managed Application Add-In for Office? I'm using NUnit but I had the same issues with MSTest.</p> <p>The problem is that there is a .NET assembly loaded inside the Office application (in my case, Word) and I need a reference to that instance of the .NET assembly. I can't just instantiate the object because it wouldn't then have an instance of Word to do things to.</p> <p>Now, I can use the Application.COMAddIns("Name of addin").Object interface to get a reference, but that gets me a COM object that is returned through the RequestComAddInAutomationService. My solution so far is that for that object to have proxy methods for every method in the real .NET object that I want to test (all set under conditional-compilation so they disappear in the released version).</p> <p>The COM object (a VB.NET class) actually has a reference to the instance of the real add-in, but I tried just returning that to NUnit and I got a nice p/Invoke error:</p> <p>System.Runtime.Remoting.RemotingException : This remoting proxy has no channel sink which means either the server has no registered server channels that are listening, or this application has no suitable client channel to talk to the server. at System.Runtime.Remoting.Proxies.RemotingProxy.InternalInvoke(IMethodCallMessage reqMcmMsg, Boolean useDispatchMessage, Int32 callType) at System.Runtime.Remoting.Proxies.RemotingProxy.Invoke(IMessage reqMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&amp; msgData, Int32 type) </p> <p>I tried making the main add-in COM visible and the error changes:</p> <p>System.InvalidOperationException : Operation is not valid due to the current state of the object. at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData&amp; msgData) </p> <p>While I have a work-around, it's messy and puts lots of test code in the real project instead of the test project - which isn't really the way NUnit is meant to work.</p>
[ { "answer_id": 713567, "author": "Richard Gadsden", "author_id": 20354, "author_profile": "https://Stackoverflow.com/users/20354", "pm_score": 3, "selected": true, "text": "Private Sub btnMemo_Click(ByVal Ctrl As Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean) Handles btnMemo.Click\n DocMemo()\nEnd Sub\n Friend Sub DocMemo()\n OpenDocByNumber(\"Prec\", 8862, 1)\nEnd Sub\n #If DEBUG Then Sub DocMemo()\n #End If End Interface\n\n\nPublic Class AddInUtilities\n Implements IAddInUtilities\n Private Addin as ThisAddIn\n #If DEBUG Then Public Sub DocMemo() Implements IAddInUtilities.DocMemo\n Addin.DocMemo()\nEnd Sub\n #End If Friend Sub New(ByRef theAddin as ThisAddIn)\n Addin=theAddin\n End Sub\n End Class\n <TestFixture()> Public Class Numbering\n\nPrivate appWord As Word.Application\nPrivate objMacros As Object\n\n<TestFixtureSetUp()> Public Sub LaunchWord()\n appWord = New Word.Application\n appWord.Visible = True\n\n Dim AddIn As COMAddIn = Nothing\n Dim AddInUtilities As IAddInUtilities\n For Each tempAddin As COMAddIn In appWord.COMAddIns\n If tempAddin.Description = \"CobbettsMacrosVsto\" Then\n AddIn = tempAddin\n End If\n Next\n AddInUtilities = AddIn.Object\n objMacros = AddInUtilities.TestObject\n\n\nEnd Sub\n\n<Test()> Public Sub DocMemo()\n\n\n objMacros.DocMemo()\nEnd Sub\n\n<TestFixtureTearDown()> Public Sub TearDown()\n appWord.Quit(False)\nEnd Sub\n\nEnd Class\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126526", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20354/" ]
126,528
<p>On the safari browser, the standard &lt;asp:Menu&gt; doesn't render well at all. How can this be fixed?</p>
[ { "answer_id": 127649, "author": "deepcode.co.uk", "author_id": 20524, "author_profile": "https://Stackoverflow.com/users/20524", "pm_score": 3, "selected": true, "text": "<browsers>\n <browser refID=\"safari1plus\">\n <controlAdapters>\n <adapter controlType=\"System.Web.UI.WebControls.Menu\" adapterType=\"\" />\n </controlAdapters>\n </browser>\n</browsers>\n" }, { "answer_id": 977072, "author": "jonezy", "author_id": 2272, "author_profile": "https://Stackoverflow.com/users/2272", "pm_score": 0, "selected": false, "text": "if (Request.UserAgent.IndexOf(\"AppleWebKit\") > 0)\n Request.Browser.Adapters.Clear();\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126528", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20524/" ]
126,562
<p>I want to replace a single file inside a msi. How to do it?</p>
[ { "answer_id": 519098, "author": "saschabeaumont", "author_id": 592, "author_profile": "https://Stackoverflow.com/users/592", "pm_score": 1, "selected": false, "text": "Const MSI_SOURCE = \"application.msi\"\nConst FILE_REPLACE = \"config.xml\"\n\nDim filesys, installer, database, view\nDim objFile, size, result, objCab\n\nSet filesys=CreateObject(\"Scripting.FileSystemObject\")\nSet installer = CreateObject(\"WindowsInstaller.Installer\")\nSet database = installer.OpenDatabase (MSI_SOURCE, 1)\n\nSet objFile = filesys.GetFile(FILE_REPLACE)\nsize = objFile.Size\n\nSet objCab = CreateObject(\"MakeCab.MakeCab.1\")\nobjCab.CreateCab \"config.cab\", False, False, False\nobjCab.AddFile FILE_REPLACE, filesys.GetFileName(FILE_REPLACE)\nobjCab.CloseCab\n\nSet view = database.OpenView (\"SELECT LastSequence FROM Media WHERE DiskId = 1\")\nview.Execute\n\nSet result = view.Fetch\nseq = result.StringData(1) + 1 ' Sequence for new configuration file\n\nSet view = database.OpenView (\"INSERT INTO Media (DiskId, LastSequence, Cabinet) VALUES ('2', '\" & seq & \"', 'config.cab')\")\nview.Execute\n\nSet view = database.OpenView (\"UPDATE File SET FileSize = \" & size & \", Sequence = \" & seq & \" WHERE File = '\" & LCase(FILE_REPLACE) & \"'\")\nview.Execute\n" }, { "answer_id": 29560372, "author": "Henrik", "author_id": 1331076, "author_profile": "https://Stackoverflow.com/users/1331076", "pm_score": 1, "selected": false, "text": "/**\n * this is a bastard class, as it is not really a part of building an installer package, \n * however, we need to be able to modify a prebuild package, and add user specific files, post build, to save memory on server, and have a fast execution time.\n * \n * \\author Henrik Dalsager\n */\n\n//I'm using everything...\nusing System;\nusing System.IO;\nusing System.Linq;\nusing System.Text;\nusing System.Collections;\nusing System.Collections.Generic;\nusing System.Diagnostics.CodeAnalysis;\nusing System.Globalization;\nusing System.Text.RegularExpressions;\nusing Microsoft.Deployment.Compression.Cab;\nusing Microsoft.Deployment.WindowsInstaller;\nusing Microsoft.Deployment.WindowsInstaller.Package;\n\nnamespace MSIFileManipulator\n{\n/**\n * \\brief updates an existing MSI, I.E. add new files\n * \n */\nclass updateMSI\n{\n //everything revolves around this package..\n InstallPackage pkg = null;\n\n //the destruction should close connection with the database, just in case we forgot..\n ~updateMSI()\n {\n if (pkg != null)\n {\n try\n {\n pkg.Close();\n }\n catch (Exception ex)\n {\n //rollback?\n\n //do nothing.. we just don't want to break anything if database was already closed, but not dereffered.\n }\n }\n }\n\n /**\n * \\brief compresses a list of files, in a workdir, to a cabinet file, in the same workdir.\n * \\param workdir path to the workdir\n * \\param filesToArchive a list of filenames, of the files to include in the cabinet file.\n * \\return filename of the created cab file\n */\n public string createCabinetFileForMSI(string workdir, List<string> filesToArchive)\n {\n //create temporary cabinet file at this path:\n string GUID = Guid.NewGuid().ToString();\n string cabFile = GUID + \".cab\";\n string cabFilePath = Path.Combine(workdir, cabFile);\n\n //create a instance of Microsoft.Deployment.Compression.Cab.CabInfo\n //which provides file-based operations on the cabinet file\n CabInfo cab = new CabInfo(cabFilePath);\n\n //create a list with files and add them to a cab file\n //now an argument, but previously this was used as test:\n //List<string> filesToArchive = new List<string>() { @\"C:\\file1\", @\"C:\\file2\" };\n cab.PackFiles(workdir, filesToArchive, filesToArchive);\n\n //we will ned the path for this file, when adding it to an msi..\n return cabFile;\n }\n\n /**\n * \\brief embeds a cabinet file into an MSI into the \"stream\" table, and adds it as a new media in the media table\n * This does not install the files on a clients computer, if he runs the installer,\n * as none of the files in the cabinet, is defined in the MSI File Table (that informs msiexec where to place mentioned files.)\n * It simply allows cabinet files to piggypack within a package, so that they may be extracted again at clients computer.\n * \n * \\param pathToCabFile full absolute path to the cabinet file\n * \\return media number of the new cabinet file wihtin the MSI\n */\n public int insertCabFileAsNewMediaInMSI(string cabFilePath, int numberOfFilesInCabinet = -1)\n {\n if (pkg == null)\n {\n throw new Exception(\"Cannot insert cabinet file into non-existing MSI package. Please Supply a path to the MSI package\");\n }\n\n int numberOfFilesToAdd = numberOfFilesInCabinet;\n if (numberOfFilesInCabinet < 0)\n {\n CabInfo cab = new CabInfo(cabFilePath);\n numberOfFilesToAdd = cab.GetFiles().Count;\n }\n\n //create a cab file record as a stream (embeddable into an MSI)\n Record cabRec = new Record(1);\n cabRec.SetStream(1, cabFilePath);\n\n /*The Media table describes the set of disks that make up the source media for the installation.\n we want to add one, after all the others\n DiskId - Determines the sort order for the table. This number must be equal to or greater than 1,\n for out new cab file, it must be > than the existing ones...\n */\n //the baby SQL service in the MSI does not support \"ORDER BY `` DESC\" but does support order by..\n IList<int> mediaIDs = pkg.ExecuteIntegerQuery(\"SELECT `DiskId` FROM `Media` ORDER BY `DiskId`\");\n int lastIndex = mediaIDs.Count - 1;\n int DiskId = mediaIDs.ElementAt(lastIndex) + 1;\n\n //wix name conventions of embedded cab files is \"#cab\" + DiskId + \".cab\"\n string mediaCabinet = \"cab\" + DiskId.ToString() + \".cab\";\n\n //The _Streams table lists embedded OLE data streams.\n //This is a temporary table, created only when referenced by a SQL statement.\n string query = \"INSERT INTO `_Streams` (`Name`, `Data`) VALUES ('\" + mediaCabinet + \"', ?)\";\n pkg.Execute(query, cabRec);\n Console.WriteLine(query);\n\n /*LastSequence - File sequence number for the last file for this new media.\n The numbers in the LastSequence column specify which of the files in the File table\n are found on a particular source disk.\n\n Each source disk contains all files with sequence numbers (as shown in the Sequence column of the File table)\n less than or equal to the value in the LastSequence column, and greater than the LastSequence value of the previous disk\n (or greater than 0, for the first entry in the Media table).\n This number must be non-negative; the maximum limit is 32767 files.\n /MSDN\n */\n IList<int> sequences = pkg.ExecuteIntegerQuery(\"SELECT `LastSequence` FROM `Media` ORDER BY `LastSequence`\");\n lastIndex = sequences.Count - 1;\n int LastSequence = sequences.ElementAt(lastIndex) + numberOfFilesToAdd;\n\n query = \"INSERT INTO `Media` (`DiskId`, `LastSequence`, `Cabinet`) VALUES (\" + DiskId.ToString() + \",\" + LastSequence.ToString() + \",'#\" + mediaCabinet + \"')\";\n Console.WriteLine(query);\n pkg.Execute(query);\n\n return DiskId;\n\n }\n\n /**\n * \\brief embeds a cabinet file into an MSI into the \"stream\" table, and adds it as a new media in the media table\n * This does not install the files on a clients computer, if he runs the installer,\n * as none of the files in the cabinet, is defined in the MSI File Table (that informs msiexec where to place mentioned files.)\n * It simply allows cabinet files to piggypack within a package, so that they may be extracted again at clients computer.\n * \n * \\param pathToCabFile full absolute path to the cabinet file\n * \\param pathToMSIFile full absolute path to the msi file\n * \\return media number of the new cabinet file wihtin the MSI\n */\n public int insertCabFileAsNewMediaInMSI(string cabFilePath, string pathToMSIFile, int numberOfFilesInCabinet = -1)\n {\n //open the MSI package for editing\n pkg = new InstallPackage(pathToMSIFile, DatabaseOpenMode.Direct); //have also tried direct, while database was corrupted when writing.\n return insertCabFileAsNewMediaInMSI(cabFilePath, numberOfFilesInCabinet);\n }\n\n /**\n * \\brief overloaded method, that embeds a cabinet file into an MSI into the \"stream\" table, and adds it as a new media in the media table\n * This does not install the files on a clients computer, if he runs the installer,\n * as none of the files in the cabinet, is defined in the MSI File Table (that informs msiexec where to place mentioned files.)\n * It simply allows cabinet files to piggypack within a package, so that they may be extracted again at clients computer.\n *\n * \\param workdir absolute path to the cabinet files location\n * \\param cabFile is the filename of the cabinet file\n * \\param pathToMSIFile full absolute path to the msi file\n * \\return media number of the new cabinet file wihtin the MSI\n */\n public int insertCabFileAsNewMediaInMSI(string workdir, string cabFile, string pathToMSIFile, int numberOfFilesInCabinet = -1)\n {\n string absPathToCabFile = Path.Combine(workdir, cabFile);\n string absPathToMSIFile = Path.Combine(workdir, pathToMSIFile);\n return insertCabFileAsNewMediaInMSI(absPathToCabFile, absPathToMSIFile, numberOfFilesInCabinet);\n }\n\n /**\n * \\brief reconfigures the MSI, so that a file pointer is \"replaced\" by a file pointer to another cabinets version of said file...\n * The original file will not be removed from the MSI, but simply orphaned (no component refers to it). It will not be installed, but will remain in the package.\n * \n * \\param OriginalFileName (this is the files target name at the clients computer after installation. It is our only way to locate the file in the file table. If two or more files have the same target name, we cannot reorient the pointer to that file!)\n * \\param FileNameInCabinet (In case you did not have the excact same filename for the new file, as the original file, you can specify the name of the file, as it is known in the cabinet, here.)\n * \\param DiskIdOfCabinetFile - Very important information. This is the Id of the new cabinet file, it is the only way to know where the new source data is within the MSI cabinet stream. This function extracts the data it needs from there, like sequence numbers\n */\n public void PointAPreviouslyConfiguredComponentsFileToBeFetchedFromAnotherCabinet(string OriginalFileName, string FileNameInCabinet, string newFileSizeInBytes, int DiskIdOfCabinetFile)\n {\n //retrieve the range of sequence numbers for this cabinet file. \n string query = \"SELECT `DiskId` FROM `Media` ORDER BY `LastSequence`\";\n Console.WriteLine(query);\n IList<int> medias = pkg.ExecuteIntegerQuery(\"SELECT `DiskId` FROM `Media` ORDER BY `LastSequence`\");\n\n query = \"SELECT `LastSequence` FROM `Media` ORDER BY `LastSequence`\";\n Console.WriteLine(query); \n IList<int> mediaLastSequences = pkg.ExecuteIntegerQuery(\"SELECT `LastSequence` FROM `Media` ORDER BY `LastSequence`\");\n\n if(medias.Count != mediaLastSequences.Count)\n {\n throw new Exception(\"there is something wrong with the Media Table, There is a different number of DiskId and LastSequence rows\");\n }\n\n if(medias.Count <= 0)\n {\n throw new Exception(\"there is something wrong with the Media Table, There are no rows with medias available..\");\n }\n\n int FirstSequence = -1;\n int LastSequence = -1;\n int lastIndex = medias.Count - 1;\n\n for (int index = lastIndex; index >= 0; index--)\n {\n int rowLastSequence = mediaLastSequences.ElementAt(index);\n int rowDiskId = medias.ElementAt(index);\n\n if (rowDiskId == DiskIdOfCabinetFile)\n {\n LastSequence = rowLastSequence;\n if (index < lastIndex)\n {\n //the next cabinet files last sequence number + 1, is this ones first..\n FirstSequence = mediaLastSequences.ElementAt(index + 1) + 1;\n break;\n }\n else\n {\n //all files from the first, to this last sequence number, are found in this cabinet\n FirstSequence = mediaLastSequences.ElementAt(lastIndex);\n break;\n }\n }\n }\n\n //now we will look in the file table to get a vacant sequence number in the new cabinet (if available - first run will return empty, and thus default to FirstSequence)\n int Sequence = FirstSequence;\n query = \"SELECT `Sequence` FROM `File` WHERE `Sequence` >= \" + FirstSequence.ToString() + \" AND `Sequence` <= \" + LastSequence.ToString() + \" ORDER BY `Sequence`\";\n Console.WriteLine(query);\n\n IList<int> SequencesInRange = pkg.ExecuteIntegerQuery(query);\n for (int index = 0; index < SequencesInRange.Count; index++)\n {\n if (FirstSequence + index != SequencesInRange.ElementAt(index))\n {\n Sequence = FirstSequence + index;\n break;\n }\n }\n\n //now we set this in the file table, to re-point this file to the new media..\n //File.FileName = FileNameInCabinet;\n //File.FileSize = newFileSizeInBytes;\n //File.Sequence = sequence;\n query = \"UPDATE `File` SET `File`.`FileName`='\" + FileNameInCabinet + \"' WHERE `File`='\" + OriginalFileName + \"'\";\n Console.WriteLine(query);\n pkg.Execute(query);\n query = \"UPDATE `File` SET `File`.`FileSize`=\" + newFileSizeInBytes + \" WHERE `File`='\" + OriginalFileName + \"'\";\n Console.WriteLine(query);\n pkg.Execute(query);\n query = \"UPDATE `File` SET `File`.`Sequence`=\" + Sequence.ToString() + \" WHERE `File`='\" + OriginalFileName + \"'\";\n Console.WriteLine(query);\n pkg.Execute(query);\n } \n}\n}\n using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\n\nnamespace MSIFileManipulator\n{\nclass Program\n{\n static void Main(string[] args)\n {\n string workdir = @\"C:\\Users\\Me\\MyDevFolder\\tests\";\n string msiFile = \"replace_test_copy.msi\";\n string fileName = \"REPLACE_THIS_IMAGE.png\";\n\n List<string> filesToInclude = new List<string>();\n System.IO.FileInfo fileInfo = new System.IO.FileInfo(System.IO.Path.Combine(workdir, fileName));\n if (fileInfo.Exists)\n {\n Console.WriteLine(\"now adding: \" + fileName + \" to cabinet\");\n filesToInclude.Add(fileName);\n\n updateMSI myMSI = new updateMSI();\n string cabfileName = myMSI.createCabinetFileForMSI(workdir, filesToInclude);\n Console.WriteLine(\"cabinet file saved as: \" + cabfileName);\n\n int diskID = myMSI.insertCabFileAsNewMediaInMSI(workdir, cabfileName, msiFile);\n Console.WriteLine(\"new media added with disk ID: \" + diskID.ToString());\n myMSI.PointAPreviouslyConfiguredComponentsFileToBeFetchedFromAnotherCabinet(fileName, fileName, fileInfo.Length.ToString(), diskID);\n Console.WriteLine(\"Done\");\n\n }\n else\n {\n Console.WriteLine(\"Could not locate the replacement file:\" + fileName);\n }\n Console.WriteLine(\"press any key to exit\");\n Console.ReadKey();\n }\n}\n}\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126562", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5978/" ]
126,584
<p>I have a requirement to be be able to embed scanned tiff images into some SSRS reports.</p> <p>When I design a report in VS2005 and add an image control the tiff image displays perfectly however when I build it. I get the warning :</p> <p><code>Warning 2 [rsInvalidMIMEType] The value of the MIMEType property for the image ‘image1’ is “image/tiff”, which is not a valid MIMEType. c:\SSRSStuff\TestReport.rdl 0 0</code></p> <p>and instead of an image I get the little red x.</p> <p>Has anybody overcome this issue?</p>
[ { "answer_id": 130950, "author": "Peter Wone", "author_id": 1715673, "author_profile": "https://Stackoverflow.com/users/1715673", "pm_score": 3, "selected": true, "text": "Response.ContentType = \"image/png\";\nResponse.Clear();\nusing (Bitmap bmp = new Bitmap(tifFilepath))\n bmp.Save(Response.OutputStream, ImageFormat.Png);\nResponse.End();\n" }, { "answer_id": 132873, "author": "Johnno Nolan", "author_id": 1116, "author_profile": "https://Stackoverflow.com/users/1116", "pm_score": 0, "selected": false, "text": "protected void Page_Load(object sender, EventArgs e)\n{\n Response.ContentType = \"image/jpeg\";\n Response.Clear(); \n Bitmap bmp = new Bitmap(tifFileLocation);\n bmp.Save(Response.OutputStream, ImageFormat.Jpeg);\n Response.End();\n\n}\n" }, { "answer_id": 2721462, "author": "Fulbert Fadri", "author_id": 326884, "author_profile": "https://Stackoverflow.com/users/326884", "pm_score": 2, "selected": false, "text": "Public Shared Function ToImage(ByVal imageBytes As Byte()) As Byte()\n Dim ms As System.IO.MemoryStream = New System.IO.MemoryStream(imageBytes)\n Dim os As System.IO.MemoryStream = New System.IO.MemoryStream()\n Dim img As System.Drawing.Image = System.Drawing.Image.FromStream(ms)\n\n img.Save(os, System.Drawing.Imaging.ImageFormat.Jpeg)\n\n Return os.ToArray()\nEnd Function\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126584", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1116/" ]
126,587
<p>I have an old server with a defunct evaluation version of SQL 2000 on it (from 2006), and two databases which were sitting on it.</p> <p>For some unknown reason, the LDF log files are missing. Presumed deleted.</p> <p>I have the mdf files (and in one case an ndf file too) for the databases which used to exist on that server, and I am trying to get them up and running on another SQL 2000 box I have sitting around.</p> <p><code>sp_attach_db</code> complains that the logfile is missing, and will not attach the database. Attempts to fool it by using a logfile from a database with the same name failed miserably. <code>sp_attach_single_file_db</code> will not work either. The mdf files have obviously not been cleanly detached.</p> <p>How do I get the databases attached and readable?</p>
[ { "answer_id": 126633, "author": "Jonathan", "author_id": 6910, "author_profile": "https://Stackoverflow.com/users/6910", "pm_score": 4, "selected": true, "text": "sp_configure 'allow updates', 1\ngo\nreconfigure with override\nGO\nupdate sysdatabases set status = 32768 where name = 'TestDB'\ngo\nsp_configure 'allow updates', 0\ngo\nreconfigure with override\nGO\n DBCC REBUILD_LOG(TestDB,'D:\\SQL_Log\\TestDB_Log.LDF')\n exec sp_resetstatus TestDB\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126587", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6910/" ]
126,611
<p>I am not too familiar with .NET desktop applications (using <a href="http://en.wikipedia.org/wiki/Microsoft_Visual_Studio#Visual_Studio_2005" rel="noreferrer">Visual&nbsp;Studio&nbsp;2005</a>). Is it possible to have the entire application run from a single .exe file?</p>
[ { "answer_id": 126694, "author": "Vertigo", "author_id": 5468, "author_profile": "https://Stackoverflow.com/users/5468", "pm_score": 2, "selected": false, "text": "netz -s application.exe foo.dll bar.dll\n" }, { "answer_id": 10600027, "author": "nawfal", "author_id": 661933, "author_profile": "https://Stackoverflow.com/users/661933", "pm_score": 0, "selected": false, "text": "ResolveHandler class Program\n{\n [STAThread]\n static void Main()\n {\n AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>\n {\n string assemblyName = new AssemblyName(args.Name).Name;\n if (assemblyName.EndsWith(\".resources\"))\n return null;\n\n string dllName = assemblyName + \".dll\";\n string dllFullPath = Path.Combine(GetMyApplicationSpecificPath(), dllName);\n\n using (Stream s = Assembly.GetEntryAssembly().GetManifestResourceStream(typeof(Program).Namespace + \".Resources.\" + dllName))\n {\n byte[] data = new byte[stream.Length];\n s.Read(data, 0, data.Length);\n\n // Or just byte[] data = new BinaryReader(s).ReadBytes((int)s.Length);\n\n File.WriteAllBytes(dllFullPath, data);\n }\n\n return Assembly.LoadFrom(dllFullPath);\n };\n }\n}\n Program GetMyApplicationSpecificPath() using (Stream s = Assembly.GetEntryAssembly().GetManifestResourceStream(typeof(Program).Namespace + \".Resources.\" + dllName))\n{\n byte[] data = new byte[stream.Length];\n s.Read(data, 0, data.Length);\n return Assembly.Load(data);\n}\n\n// Or just\n\nreturn Assembly.LoadFrom(dllFullPath); // If location is known.\n" }, { "answer_id": 13426379, "author": "surfmuggle", "author_id": 819887, "author_profile": "https://Stackoverflow.com/users/819887", "pm_score": 2, "selected": false, "text": "AppDomain.CurrentDomain.AssemblyResolve += (sender, \n args) => {\n String resourceName = \"AssemblyLoadingAndReflection.\" +\n new AssemblyName(args.Name).Name + \".dll\";\n using (var stream = \n Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)){\n Byte[] assemblyData = new Byte[stream.Length];\n stream.Read(assemblyData, 0, assemblyData.Length);\n return Assembly.Load(assemblyData);\n }\n };\n" }, { "answer_id": 67026468, "author": "jjxtra", "author_id": 56079, "author_profile": "https://Stackoverflow.com/users/56079", "pm_score": 3, "selected": false, "text": "dotnet.exe publish YourProject.csproj -f net5.0 -o package/win-x64 -c Release -r win-x64 /p:PublishTrimmed=true /p:TrimMode=Link /p:PublishSingleFile=true /p:IncludeNativeLibrariesForSelfExtract=true\n PublishTrimmed false TrimMode copyused link -f -c Release -r win-x86 win-x64 linux-x64 -o" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126611", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1368/" ]
126,631
<p>Is it possible to pass a function/callback from javascript to a java applet?</p> <p>For example i have an applet with a button that when pressed it will call the passed js callback</p> <pre><code>function onCommand() { alert('Button pressed from applet'); } applet.onCommand(onCommand); </code></pre>
[ { "answer_id": 126650, "author": "moonshadow", "author_id": 11834, "author_profile": "https://Stackoverflow.com/users/11834", "pm_score": 2, "selected": false, "text": "import netscape.javascript.*;\nimport java.applet.*;\nimport java.awt.*;\nclass MyApplet extends Applet {\n public void init() {\n JSObject win = JSObject.getWindow(this);\n JSObject doc = (JSObject) win.getMember(\"document\");\n JSObject loc = (JSObject) doc.getMember(\"location\");\n\n String s = (String) loc.getMember(\"href\"); // document.location.href\n win.call(\"f\", null); // Call f() in HTML page\n }\n}\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126631", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20300/" ]
126,652
<p>(Oracle) I have to return all records from last 12 months. How to do that in PL/SQL?</p> <p>EDIT: Sorry, I forgot to explain, I do have a column of DATA type</p>
[ { "answer_id": 126684, "author": "cagcowboy", "author_id": 19629, "author_profile": "https://Stackoverflow.com/users/19629", "pm_score": -1, "selected": false, "text": "SELECT *\nFROM table\nWHERE date_column > SYSDATE - 365\n" }, { "answer_id": 126707, "author": "cagcowboy", "author_id": 19629, "author_profile": "https://Stackoverflow.com/users/19629", "pm_score": 0, "selected": false, "text": "SELECT *\nFROM table\nWHERE date_column > ADD_MONTHS(SYSDATE, -12)\n" }, { "answer_id": 126747, "author": "David Aldridge", "author_id": 6742, "author_profile": "https://Stackoverflow.com/users/6742", "pm_score": 2, "selected": false, "text": "SELECT *\nFROM table\nWHERE date_column >= ADD_MONTHS(TRUNC(SYSDATE),-12)\n SELECT *\nFROM table\nWHERE date_column >= ADD_MONTHS(TRUNC(SYSDATE,'MM'),-12)\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126652", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3221/" ]
126,656
<p>I am doing a project at the moment, and in the interest of code reuse, I went looking for a library that can perform some probabilistic accept/reject of an item: </p> <p>i.e., there are three people (a, b c), and each of them have a probability P{i} of getting an item, where p{a} denotes the probability of a. These probabilities are calculated at run time, and cannot be hardcoded. </p> <p>What I wanted to do is to generate one random number (for an item), and calculate who gets that item based on their probability of getting it. The alias method (<a href="http://books.google.com/books?pg=PA133&amp;dq=alias+method+walker&amp;ei=D4ORR8ncFYuWtgOslpVE&amp;sig=TjEThBUa4odbGJmjyF4daF1AKF4&amp;id=ERSSDBDcYOIC&amp;output=html" rel="nofollow noreferrer">http://books.google.com/books?pg=PA133&amp;dq=alias+method+walker&amp;ei=D4ORR8ncFYuWtgOslpVE&amp;sig=TjEThBUa4odbGJmjyF4daF1AKF4&amp;id=ERSSDBDcYOIC&amp;output=html</a>) outlined here explained how, but I wanted to see if there is a ready made implementation so I wouldn't have to write it up.</p>
[ { "answer_id": 127132, "author": "finalman", "author_id": 20522, "author_profile": "https://Stackoverflow.com/users/20522", "pm_score": 2, "selected": true, "text": "public int selectPerson(float[] probabilies, Random r) {\n float t = r.nextFloat();\n float p = 0.0f;\n\n for (int i = 0; i < probabilies.length; i++) {\n p += probabilies[i];\n if (t < p) {\n return i;\n }\n }\n\n // We should not end up here if probabilities are normalized properly (sum up to one)\n return probabilies.length - 1; \n}\n" }, { "answer_id": 133223, "author": "Chii", "author_id": 17335, "author_profile": "https://Stackoverflow.com/users/17335", "pm_score": 0, "selected": false, "text": " void test() {\n for (int i = 0; i < 10; i++) {\n once()\n }\n }\n private def once() {\n def double[] probs = [1 / 11, 2 / 11, 3 / 11, 1 / 11, 2 / 11, 2 / 11]\n def int[] whoCounts = new int[probs.length]\n def Random r = new Random()\n def int who\n int TIMES = 1000000\n for (int i = 0; i < TIMES; i++) {\n who = selectPerson(probs, r.nextDouble())\n whoCounts[who]++\n }\n for (int j = 0; j < probs.length; j++) {\n System.out.printf(\" %10f \", (probs[j] - (whoCounts[j] / TIMES)))\n }\n println \"\"\n }\n public int selectPerson(double[] probabilies, double r) {\n double t = r\n double p = 0.0f;\n for (int i = 0; i < probabilies.length; i++) {\n p += probabilies[i];\n if (t < p) {\n return i;\n }\n }\n return probabilies.length - 1;\n }\n\noutputs: the difference betweenn the probability, and the actual count/total \nobtained over ten 1,000,000 runs:\n -0.000009 0.000027 0.000149 -0.000125 0.000371 -0.000414 \n -0.000212 -0.000346 -0.000396 0.000013 0.000808 0.000132 \n 0.000326 0.000231 -0.000113 0.000040 -0.000071 -0.000414 \n 0.000236 0.000390 -0.000733 -0.000368 0.000086 0.000388 \n -0.000202 -0.000473 -0.000250 0.000101 -0.000140 0.000963 \n 0.000076 0.000487 -0.000106 -0.000044 0.000095 -0.000509 \n 0.000295 0.000117 -0.000545 -0.000112 -0.000062 0.000306 \n -0.000584 0.000651 0.000191 0.000280 -0.000358 -0.000181 \n -0.000334 -0.000043 0.000484 -0.000156 0.000420 -0.000372\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126656", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17335/" ]
126,667
<p>When I launch the "mvn install" command, maven sometimes tries to download dependencies that it has already downloaded. That's expected for SNAPSHOT but why does maven do that for other JARs?</p> <p>I know I can avoid that behavior by "-o" flag but I just wonder what the cause is.</p>
[ { "answer_id": 7780139, "author": "fivetenwill", "author_id": 983104, "author_profile": "https://Stackoverflow.com/users/983104", "pm_score": 0, "selected": false, "text": "find ~/.m2/repository -name '_maven*' | xargs rm\nfind ~/.m2/repository -name '*lastUpdated' | xargs rm\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126667", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3122/" ]
126,678
<p>I don't seem to be able to close the OledbDataReader object after reading data from it. Here is the relevant code -</p> <pre><code>Dim conSyBase As New OleDb.OleDbConnection("Provider=Sybase.ASEOLEDBProvider.2;Server Name=xx.xx.xx.xx;Server Port Address=5000;Initial Catalog=xxxxxxxxxx;User ID=xxxxxxxx;Password=xxxxxxxxx;") conSyBase.Open() Dim cmdSyBase As New OleDb.OleDbCommand("MySQLStatement", conSyBase) Dim drSyBase As OleDb.OleDbDataReader = cmdSyBase.ExecuteReader Try While drSyBase.Read /*Do some stuff with the data here */ End While Catch ex As Exception NotifyError(ex, "Read failed.") End Try drSyBase.Close() /* CODE HANGS HERE */ conSyBase.Close() drSyBase.Dispose() cmdSyBase.Dispose() conSyBase.Dispose() </code></pre> <p>The console application just hangs at the point at which I try to close the reader. Opening and closing a connection is not a problem, therefore does anyone have any ideas for what may be causing this?</p>
[ { "answer_id": 126784, "author": "Mikey", "author_id": 13347, "author_profile": "https://Stackoverflow.com/users/13347", "pm_score": 0, "selected": false, "text": "\nDim conSyBase As New OleDb.OleDbConnection(\"Provider=Sybase.ASEOLEDBProvider.2;Server Name=xx.xx.xx.xx;Server Port Address=5000;Initial Catalog=xxxxxxxxxx;User ID=xxxxxxxx;Password=xxxxxxxxx;\")\nconSyBase.Open()\nDim cmdSyBase As New OleDb.OleDbCommand(\"MySQLStatement\", conSyBase)\nDim drSyBase As OleDb.OleDbDataReader = cmdSyBase.ExecuteReader\nTry\n While drSyBase.Read\n /*Do some stuff with the data here */\n End While\nCatch ex As Exception \n NotifyError(ex, \"Read failed.\")\nFinally\n drSyBase.Close() \n conSyBase.Close()\n drSyBase.Dispose()\n cmdSyBase.Dispose()\n conSyBase.Dispose()\nEnd Try\n" }, { "answer_id": 126996, "author": "Russ Cam", "author_id": 1831, "author_profile": "https://Stackoverflow.com/users/1831", "pm_score": 3, "selected": true, "text": "drSyBase.Close()\n cmdSyBase.Cancel()\n" }, { "answer_id": 127021, "author": "Seb Nilsson", "author_id": 2429, "author_profile": "https://Stackoverflow.com/users/2429", "pm_score": 0, "selected": false, "text": "using (OleDb.OleDbConnection connection = new OleDb.OleDbConnection(connectionString)) \n{\n DoDataAccessStuff();\n} // Your resource(s) are killed, disposed and all that\n Using conSyBase As New OleDb.OleDbConnection(\"Provider=Sybase.ASEOLEDBProvider.2;Server Name=xx.xx.xx.xx;Server Port Address=5000;Initial Catalog=xxxxxxxxxx;User ID=xxxxxxxx;Password=xxxxxxxxx;\"), _\n cmdSyBase As New OleDb.OleDbCommand(\"MySQLStatement\", conSyBase) \n\n conSyBase.Open()\n Dim drSyBase As OleDb.OleDbDataReader = cmdSyBase.ExecuteReader\n\n Try\n While drSyBase.Read()\n\n '...'\n\n End While\n Catch ex As Exception\n NotifyError(ex, \"Read failed.\")\n End Try\n\n cmdSyBase.Cancel()\nEnd Using\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126678", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1831/" ]
126,680
<p>Looking for one that is fast enough and still graceful with memory. The image is a 24bpp System.Drawing.Bitmap.</p>
[ { "answer_id": 126712, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 2, "selected": false, "text": "var cnt = new HashSet<System.Drawing.Color>();\n\nforeach (Color pixel in image)\n cnt.Add(pixel);\n\nConsole.WriteLine(\"The image has {0} distinct colours.\", cnt.Count);\n .GetArgb() Color Color GetHashCode" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126680", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21623/" ]
126,718
<p>I'm working on a VB6 application and I would like to send a Type as a reference and store it in another form. Is this possible?</p> <p>Sending it is no problem, I just use the <code>ByRef</code> keyword:</p> <pre><code>public Sub SetStopToEdit(ByRef currentStop As StopType) </code></pre> <p>But when I try to use Set to store <code>currentStop</code> in the receiving module I get the "Object required" error when running the program:</p> <pre><code>Private stopToEdit As StopTypeModule.StopType ' ... Lots of code Set stopToEdit = currentStop </code></pre> <p><code>StopType</code> is defined as follows in a Module (<strong>not a class module</strong>):</p> <pre><code>Public Type StopType MachineName As String StartDate As Date StartTime As String Duration As Double End Type </code></pre> <p>Is it possible to store the sent reference or do I have to turn <code>StopType</code> into a class?</p> <p>While just setting a local variable works:</p> <pre><code>stopToEdit = currentStop </code></pre> <p>When <code>stopToEdit</code> is later changed the change is not visible in the variable sent to <code>SetStopToEdit</code>.</p>
[ { "answer_id": 126740, "author": "Daren Thomas", "author_id": 2260, "author_profile": "https://Stackoverflow.com/users/2260", "pm_score": 1, "selected": false, "text": "Set stopToEdit = currentStop\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126718", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16047/" ]
126,720
<p>Is it possible to setup a JDBC connection to Oracle without providing username/password information in a configuration file (or in any other standard readable location)?</p> <p>Typically applications have a configuration file that contains setup parameters to connect to a database. Some DBAs have problems with the fact that usernames and passwords are in clear text in config files.</p> <p>I don't think this is possible with Oracle and JDBC, but I need some confirmation...</p> <p>A possible compromise is to encrypt the password in the config file and decrypt it before setting up the connection. Of course, the decryption key should not be in the same config file. This will only solve accidental opening of the config file by unauthorized users.</p>
[ { "answer_id": 822248, "author": "Achille", "author_id": 100733, "author_profile": "https://Stackoverflow.com/users/100733", "pm_score": 2, "selected": false, "text": "J2EE 1/100 JBOSS J2EE" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126720", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9504/" ]
126,737
<p>After watching The Dark Knight I became rather enthralled with the concept of the Prisoner's Dilemma. There <em>must</em> be an algorithm that that maximizes one's own gain given a situation.</p> <p>For those that find this foreign: <a href="http://en.wikipedia.org/wiki/Prisoner%27s_dilemma" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Prisoner%27s_dilemma</a></p> <p>Very, very interesting stuff.</p> <p>Edit: The question is, <em>what</em> is, if any, the most efficient algorithm that exists for the Prisoner's Dilemma?</p>
[ { "answer_id": 126826, "author": "slim", "author_id": 7512, "author_profile": "https://Stackoverflow.com/users/7512", "pm_score": 5, "selected": true, "text": "cooperate = true;\n cooperate = false\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126737", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14877/" ]
126,738
<p>I have drawn an image in the device context using python and I want to move it smoothly/animate either vertically or horizontally.</p> <p>What algorithm should I use? Where can I get info for this kind of tasks in python?</p>
[ { "answer_id": 127216, "author": "freespace", "author_id": 8297, "author_profile": "https://Stackoverflow.com/users/8297", "pm_score": 0, "selected": false, "text": "(x1, y1) (x2,y2) t dx = (x2-x1)/t\ndy = (y2-y1)/t\n (dx,dy) (x,y) (x1,y1) (x,y)==(x2,y2)\n v(t) = u(t) + t*a(t)\nx(t) = v(t) + t*v(t)\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126738", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20894/" ]
126,751
<p>During a long compilation with Visual Studio 2005 (version 8.0.50727.762), I sometimes get the following error in several files in some project: </p> <pre><code>fatal error C1033: cannot open program database 'v:\temp\apprtctest\win32\release\vc80.pdb' </code></pre> <p>(The file mentioned is either <code>vc80.pdb</code> or <code>vc80.idb</code> in the project's temp dir.)</p> <p>The next build of the same project succeeds. There is no other Visual Studio open that might access the same files.</p> <p>This is a serious problem because it makes nightly compilation impossible.</p>
[ { "answer_id": 18296973, "author": "M.H.", "author_id": 2610299, "author_profile": "https://Stackoverflow.com/users/2610299", "pm_score": 4, "selected": false, "text": "Project Options -> C/C++ -> General -> Debug Information Format C7" }, { "answer_id": 19676823, "author": "Jeff McClintock", "author_id": 64078, "author_profile": "https://Stackoverflow.com/users/64078", "pm_score": 0, "selected": false, "text": "%TEMP%\\$(ProjectName)\\$(Platform)\\$(Configuration)\\\n C:\\temp\\$(ProjectName)\\$(Platform)\\$(Configuration)\\\n" }, { "answer_id": 28415723, "author": "Tejas Sharma", "author_id": 1556026, "author_profile": "https://Stackoverflow.com/users/1556026", "pm_score": 2, "selected": false, "text": "vc100.pdb procexp mspdbsrv" }, { "answer_id": 36930252, "author": "CLIFFORD P Y", "author_id": 1942413, "author_profile": "https://Stackoverflow.com/users/1942413", "pm_score": 1, "selected": false, "text": "C1033: cannot open program database C1033: cannot open program database" }, { "answer_id": 43009826, "author": "jozxyqk", "author_id": 1888983, "author_profile": "https://Stackoverflow.com/users/1888983", "pm_score": 1, "selected": false, "text": ".pdb" }, { "answer_id": 69833094, "author": "DebbyX3", "author_id": 12084395, "author_profile": "https://Stackoverflow.com/users/12084395", "pm_score": 0, "selected": false, "text": "procexp" }, { "answer_id": 71883696, "author": "borey", "author_id": 5972783, "author_profile": "https://Stackoverflow.com/users/5972783", "pm_score": 0, "selected": false, "text": "BuildConsole abc.sln /rebuild /cfg=\"release|Win32\"\nif %errorlevel% neq 0 (\n BuildConsole abc.sln /cfg=\"release|Win32\"\n if %errorlevel% neq 0 (\n rem process error\n exit 1\n )\n)\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126751", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7224/" ]
126,756
<p>Can anybody suggest programming examples that illustrate recursive functions? There are the usual old horses such as <strong><em>Fibonacci series</em></strong> and <strong><em>Towers of Hanoi</em></strong>, but anything besides them would be fun.</p>
[ { "answer_id": 126793, "author": "Yuval F", "author_id": 1702, "author_profile": "https://Stackoverflow.com/users/1702", "pm_score": 0, "selected": false, "text": "void rev(string s) {\n if (!s.empty()) {\n rev(s[1..s.length]);\n }\n print(s[0]);\n}\n" }, { "answer_id": 126960, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 3, "selected": false, "text": "ToString class List {\n public List(params object[] items) {\n foreach (object o in items)\n this.Add(o);\n }\n\n // Most of the implementation omitted …\n public override string ToString() {\n var ret = new StringBuilder();\n ret.Append(\"( \");\n foreach (object o in this) {\n ret.Append(o);\n ret.Append(\" \");\n }\n ret.Append(\")\");\n return ret.ToString();\n }\n}\n\nvar lst = new List(1, 2, new List(3, 4), new List(new List(5), 6), 7);\nConsole.WriteLine(lst);\n// yields:\n// ( 1 2 ( 3 4 ) ( ( 5 ) 6 ) 7 )\n Eval" }, { "answer_id": 127163, "author": "Kip", "author_id": 18511, "author_profile": "https://Stackoverflow.com/users/18511", "pm_score": 4, "selected": false, "text": "Ackermann(m, n)\n{\n if(m==0)\n return n+1;\n else if(m>0 && n==0)\n return Ackermann(m-1, 1);\n else if(m>0 && n>0)\n return Ackermann(m-1, Ackermann(m, n-1));\n else\n throw exception; //not defined for negative m or n\n}\n" }, { "answer_id": 127203, "author": "Kip", "author_id": 18511, "author_profile": "https://Stackoverflow.com/users/18511", "pm_score": 4, "selected": false, "text": "bool isPalindrome(char* s, int len)\n{\n if(len < 2)\n return TRUE;\n else\n return s[0] == s[len-1] && isPalindrome(&s[1], len-2);\n}\n" }, { "answer_id": 127253, "author": "FlySwat", "author_id": 1965, "author_profile": "https://Stackoverflow.com/users/1965", "pm_score": 3, "selected": false, "text": "public Control FindControl(Control startControl, string id)\n{\n if (startControl.Id == id)\n return startControl\n\n if (startControl.Children.Count > 0)\n {\n foreach (Control c in startControl.Children)\n {\n return FindControl(c, id);\n }\n }\n return null;\n}\n" }, { "answer_id": 128161, "author": "Joel Coehoorn", "author_id": 3043, "author_profile": "https://Stackoverflow.com/users/3043", "pm_score": -1, "selected": false, "text": "Function ColumnName(ByVal index As Integer) As String\n Static chars() As Char = {\"A\"c, \"B\"c, \"C\"c, \"D\"c, \"E\"c, \"F\"c, \"G\"c, \"H\"c, \"I\"c, \"J\"c, \"K\"c, \"L\"c, \"M\"c, \"N\"c, \"O\"c, \"P\"c, \"Q\"c, \"R\"c, \"S\"c, \"T\"c, \"U\"c, \"V\"c, \"W\"c, \"X\"c, \"Y\"c, \"Z\"c}\n\n index -= 1 'adjust index so it matches 0-indexed array rather than 1-indexed column'\n\n Dim quotient As Integer = index \\ 26 'normal / operator rounds. \\ does integer division'\n If quotient > 0 Then\n Return ColumnName(quotient) & chars(index Mod 26)\n Else\n Return chars(index Mod 26)\n End If\nEnd Function\n" }, { "answer_id": 2765589, "author": "Jonik", "author_id": 56285, "author_profile": "https://Stackoverflow.com/users/56285", "pm_score": 3, "selected": false, "text": "public static int countFiles(File f) {\n if (f.isFile()){\n return 1;\n }\n\n // Count children & recurse into subdirs:\n int count = 0;\n File[] files = f.listFiles();\n for (File fileOrDir : files) {\n count += countFiles(fileOrDir);\n }\n return count;\n}\n File FileUtils.deleteDirectory()" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126756", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4021/" ]
126,759
<p>I've created an implementation of the <code>QAbstractListModel</code> class in Qt Jambi 4.4 and am finding that using the model with a <code>QListView</code> results in nothing being displayed, however using the model with a <code>QTableView</code> displays the data correctly.</p> <p>Below is my implementation of <code>QAbstractListModel</code>:</p> <pre><code>public class FooListModel extends QAbstractListModel { private List&lt;Foo&gt; _data = new Vector&lt;Foo&gt;(); public FooListModel(List&lt;Foo&gt; data) { if (data == null) { return; } for (Foo foo : data) { _data.add(Foo); } reset(); } public Object data(QModelIndex index, int role) { if (index.row() &lt; 0 || index.row() &gt;= _data.size()) { return new QVariant(); } Foo foo = _data.get(index.row()); if (foo == null) { return new QVariant(); } return foo; } public int rowCount(QModelIndex parent) { return _data.size(); } } </code></pre> <p>And here is how I set the model:</p> <pre><code>Foo foo = new Foo(); foo.setName("Foo!"); List&lt;Foo&gt; data = new Vector&lt;Foo&gt;(); data.add(foo); FooListModel fooListModel = new FooListModel(data); ui.fooListView.setModel(fooListModel); ui.fooTableView.setModel(fooListModel); </code></pre> <p>Can anyone see what I'm doing wrong? I'd like to think it was a problem with my implementation because, as everyone says, select ain't broken!</p>
[ { "answer_id": 126793, "author": "Yuval F", "author_id": 1702, "author_profile": "https://Stackoverflow.com/users/1702", "pm_score": 0, "selected": false, "text": "void rev(string s) {\n if (!s.empty()) {\n rev(s[1..s.length]);\n }\n print(s[0]);\n}\n" }, { "answer_id": 126960, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 3, "selected": false, "text": "ToString class List {\n public List(params object[] items) {\n foreach (object o in items)\n this.Add(o);\n }\n\n // Most of the implementation omitted …\n public override string ToString() {\n var ret = new StringBuilder();\n ret.Append(\"( \");\n foreach (object o in this) {\n ret.Append(o);\n ret.Append(\" \");\n }\n ret.Append(\")\");\n return ret.ToString();\n }\n}\n\nvar lst = new List(1, 2, new List(3, 4), new List(new List(5), 6), 7);\nConsole.WriteLine(lst);\n// yields:\n// ( 1 2 ( 3 4 ) ( ( 5 ) 6 ) 7 )\n Eval" }, { "answer_id": 127163, "author": "Kip", "author_id": 18511, "author_profile": "https://Stackoverflow.com/users/18511", "pm_score": 4, "selected": false, "text": "Ackermann(m, n)\n{\n if(m==0)\n return n+1;\n else if(m>0 && n==0)\n return Ackermann(m-1, 1);\n else if(m>0 && n>0)\n return Ackermann(m-1, Ackermann(m, n-1));\n else\n throw exception; //not defined for negative m or n\n}\n" }, { "answer_id": 127203, "author": "Kip", "author_id": 18511, "author_profile": "https://Stackoverflow.com/users/18511", "pm_score": 4, "selected": false, "text": "bool isPalindrome(char* s, int len)\n{\n if(len < 2)\n return TRUE;\n else\n return s[0] == s[len-1] && isPalindrome(&s[1], len-2);\n}\n" }, { "answer_id": 127253, "author": "FlySwat", "author_id": 1965, "author_profile": "https://Stackoverflow.com/users/1965", "pm_score": 3, "selected": false, "text": "public Control FindControl(Control startControl, string id)\n{\n if (startControl.Id == id)\n return startControl\n\n if (startControl.Children.Count > 0)\n {\n foreach (Control c in startControl.Children)\n {\n return FindControl(c, id);\n }\n }\n return null;\n}\n" }, { "answer_id": 128161, "author": "Joel Coehoorn", "author_id": 3043, "author_profile": "https://Stackoverflow.com/users/3043", "pm_score": -1, "selected": false, "text": "Function ColumnName(ByVal index As Integer) As String\n Static chars() As Char = {\"A\"c, \"B\"c, \"C\"c, \"D\"c, \"E\"c, \"F\"c, \"G\"c, \"H\"c, \"I\"c, \"J\"c, \"K\"c, \"L\"c, \"M\"c, \"N\"c, \"O\"c, \"P\"c, \"Q\"c, \"R\"c, \"S\"c, \"T\"c, \"U\"c, \"V\"c, \"W\"c, \"X\"c, \"Y\"c, \"Z\"c}\n\n index -= 1 'adjust index so it matches 0-indexed array rather than 1-indexed column'\n\n Dim quotient As Integer = index \\ 26 'normal / operator rounds. \\ does integer division'\n If quotient > 0 Then\n Return ColumnName(quotient) & chars(index Mod 26)\n Else\n Return chars(index Mod 26)\n End If\nEnd Function\n" }, { "answer_id": 2765589, "author": "Jonik", "author_id": 56285, "author_profile": "https://Stackoverflow.com/users/56285", "pm_score": 3, "selected": false, "text": "public static int countFiles(File f) {\n if (f.isFile()){\n return 1;\n }\n\n // Count children & recurse into subdirs:\n int count = 0;\n File[] files = f.listFiles();\n for (File fileOrDir : files) {\n count += countFiles(fileOrDir);\n }\n return count;\n}\n File FileUtils.deleteDirectory()" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126759", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13678/" ]
126,772
<h2>Background</h2> <p>I am writing and using a very simple CGI-based (Perl) content management tool for two pro-bono websites. It provides the website administrator with HTML forms for events where they fill the fields (date, place, title, description, links, etc.) and save it. On that form I allow the administrator to upload an image related to the event. On the HTML page displaying the form, I am also showing a preview of the picture uploaded (HTML img tag).</p> <h2>The Problem</h2> <p>The problem happens when the administrator wants to change the picture. He would just have to hit the "browse" button, pick a new picture and press ok. And this works fine.</p> <p>Once the image is uploaded, my back-end CGI handles the upload and reloads the form properly.</p> <p>The problem is that the image shown <strong>does not</strong> get refreshed. The old image is still shown, even though the database holds the right image. I have narrowed it down to the fact that the IMAGE IS CACHED in the web browser. If the administrator hits the RELOAD button in Firefox/Explorer/Safari, everything gets refreshed fine and the new image just appears.</p> <h2>My Solution - Not Working</h2> <p>I am trying to control the cache by writing a HTTP Expires instruction with a date very far in the past.</p> <pre><code>Expires: Mon, 15 Sep 2003 1:00:00 GMT </code></pre> <p>Remember that I am on the administrative side and I don't really care if the pages takes a little longer to load because they are always expired.</p> <p>But, this does not work either.</p> <h2>Notes</h2> <p>When uploading an image, its filename is not kept in the database. It is renamed as <strong>Image.jpg</strong> (to simply things out when using it). When replacing the existing image with a new one, the name doesn't change either. Just the content of the image file changes.</p> <p>The webserver is provided by the hosting service/ISP. It uses Apache.</p> <h2>Question</h2> <p>Is there a way to force the web browser to NOT cache things from this page, not even images?</p> <p>I am juggling with the option to actually "save the filename" with the database. This way, if the image is changed, the src of the IMG tag will also change. However, this requires a lot of changes throughout the site and I rather not do it if I have a better solution. Also, this will still not work if the new image uploaded has the same name (say the image is photoshopped a bit and re-uploaded).</p>
[ { "answer_id": 126782, "author": "Armin Ronacher", "author_id": 19990, "author_profile": "https://Stackoverflow.com/users/19990", "pm_score": 6, "selected": false, "text": "<img src=\"foo.cgi?random=323527528432525.24234\" alt=\"\">\n Cache-Control: no-cache\n" }, { "answer_id": 126831, "author": "epochwolf", "author_id": 16204, "author_profile": "https://Stackoverflow.com/users/16204", "pm_score": 9, "selected": true, "text": "<img src=\"picture.jpg?1222259157.415\" alt=\"\">\n performance.now() time.time()" }, { "answer_id": 126918, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "<img src=\"image.php?img=imageFile.jpg&some-random-number-262376\" />\n // PHP\nif( isset( $_GET['img'] ) && is_file( IMG_PATH . $_GET['img'] ) ) {\n\n // read contents\n $f = open( IMG_PATH . $_GET['img'] );\n $img = $f.read();\n $f.close();\n\n // no-cache headers - complete set\n // these copied from [php.net/header][1], tested myself - works\n header(\"Expires: Sat, 26 Jul 1997 05:00:00 GMT\"); // Some time in the past\n header(\"Last-Modified: \" . gmdate(\"D, d M Y H:i:s\") . \" GMT\"); \n header(\"Cache-Control: no-store, no-cache, must-revalidate\"); \n header(\"Cache-Control: post-check=0, pre-check=0\", false); \n header(\"Pragma: no-cache\"); \n\n // image related headers\n header('Accept-Ranges: bytes');\n header('Content-Length: '.strlen( $img )); // How many bytes we're going to send\n header('Content-Type: image/jpeg'); // or image/png etc\n\n // actual image\n echo $img;\n exit();\n}\n" }, { "answer_id": 12452993, "author": "Rick", "author_id": 1676598, "author_profile": "https://Stackoverflow.com/users/1676598", "pm_score": 5, "selected": false, "text": "echo <img src='Images/image.png?\" . filemtime('Images/image.png') . \"' />\";\n" }, { "answer_id": 18709475, "author": "x-yuri", "author_id": 52499, "author_profile": "https://Stackoverflow.com/users/52499", "pm_score": 4, "selected": false, "text": "<img src=\"picture.jpg?20130910043254\">\n php" }, { "answer_id": 22429999, "author": "Doin", "author_id": 999120, "author_profile": "https://Stackoverflow.com/users/999120", "pm_score": 2, "selected": false, "text": "Expires: location.reload(true)" }, { "answer_id": 33794312, "author": "Tarik", "author_id": 5105831, "author_profile": "https://Stackoverflow.com/users/5105831", "pm_score": 3, "selected": false, "text": "<img src=\"image.png?cache=none\">\n <img src=\"image.png?nocache=<?php echo time(); ?>\">\n $chart_hash = md5(implode('-', $_GET));\necho \"<img src='/images/mychart.png?hash=$chart_hash'>\";\n echo \"<img src='/images/mychart.png?hash=\" . filemtime('mychart.png') . \"'>\";\n" }, { "answer_id": 36339104, "author": "Timmy T.", "author_id": 6140939, "author_profile": "https://Stackoverflow.com/users/6140939", "pm_score": 3, "selected": false, "text": "<meta Http-Equiv=\"Cache\" content=\"no-cache\">\n<meta Http-Equiv=\"Pragma-Control\" content=\"no-cache\">\n<meta Http-Equiv=\"Cache-directive\" Content=\"no-cache\">\n<meta Http-Equiv=\"Pragma-directive\" Content=\"no-cache\">\n<meta Http-Equiv=\"Cache-Control\" Content=\"no-cache\">\n<meta Http-Equiv=\"Pragma\" Content=\"no-cache\">\n<meta Http-Equiv=\"Expires\" Content=\"0\">\n<meta Http-Equiv=\"Pragma-directive: no-cache\">\n<meta Http-Equiv=\"Cache-directive: no-cache\">\n" }, { "answer_id": 48036276, "author": "Aref Rostamkhani", "author_id": 9156495, "author_profile": "https://Stackoverflow.com/users/9156495", "pm_score": 4, "selected": false, "text": "<div>\n <img class=\"NO-CACHE\" src=\"images/img1.jpg\" />\n <img class=\"NO-CACHE\" src=\"images/imgLogo.jpg\" />\n</div>\n $(document).ready(function ()\n { \n $('.NO-CACHE').attr('src',function () { return $(this).attr('src') + \"?a=\" + Math.random() });\n });\n var nods = document.getElementsByClassName('NO-CACHE');\nfor (var i = 0; i < nods.length; i++)\n{\n nods[i].attributes['src'].value += \"?a=\" + Math.random();\n}\n" }, { "answer_id": 48190796, "author": "BritishSam", "author_id": 1630276, "author_profile": "https://Stackoverflow.com/users/1630276", "pm_score": 2, "selected": false, "text": "<img src=\"picture.jpg?t=<?php echo time();?>\">" }, { "answer_id": 52859558, "author": "Dmytro", "author_id": 2012715, "author_profile": "https://Stackoverflow.com/users/2012715", "pm_score": 1, "selected": false, "text": "<!DOCTYPE html>\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\n <head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <meta name=\"mobile-web-app-capable\" content=\"yes\" /> \n <title>Resource Synchronization Test</title>\n <script>\nfunction sync() {\n var xhr = new XMLHttpRequest;\n xhr.onreadystatechange = function() {\n if (this.readyState == 4 && this.status == 200) { \n var images = document.getElementsByClassName(\"depends-on-resource\");\n\n for (var i = 0; i < images.length; ++i) {\n var image = images[i];\n if (image.getAttribute('data-resource-name') == 'resource.bmp') {\n image.src = 'resource.bmp?i=' + new Date().getTime(); \n }\n }\n }\n }\n xhr.open('GET', 'resource.bmp', true);\n xhr.send();\n}\n </script>\n </head>\n <body>\n <img class=\"depends-on-resource\" data-resource-name=\"resource.bmp\" src=\"resource.bmp\"></img>\n <button onclick=\"sync()\">sync</button>\n </body>\n</html>\n" }, { "answer_id": 60277745, "author": "Ali Han", "author_id": 585626, "author_profile": "https://Stackoverflow.com/users/585626", "pm_score": 2, "selected": false, "text": "<img src=\"cars.png?1287361287\" alt=\"\">\n <img src=\"cars.png?2020-02-18\" alt=\"\">\n <img src=\"cars.png?<?php echo time();?>\" alt=\"\">\n var items = document.querySelectorAll(\"img.NO-CACHE\");\nfor (var i = items.length; i--;) {\n var img = items[i];\n img.src = img.src + '?' + Date.now();\n}\n <img class=\"NO-CACHE\" src=\"https://upload.wikimedia.org/wikipedia/commons/6/6a/JavaScript-logo.png\" alt=\"\">\n https://example.com/image.png?1582018163634\n" }, { "answer_id": 67368084, "author": "rahul sati", "author_id": 15822444, "author_profile": "https://Stackoverflow.com/users/15822444", "pm_score": -1, "selected": false, "text": "<img src=\"www.abc.com/123.png?t=current_time\"> performance.now()" }, { "answer_id": 70954519, "author": "Ravi Singh", "author_id": 11216915, "author_profile": "https://Stackoverflow.com/users/11216915", "pm_score": 0, "selected": false, "text": "cache.put caches.open('YOUR_CACHE_NAME').then(cache => {\n const url = 'URL_OF_IMAGE_TO_UPDATE'\n fetch(url).then(res => {\n cache.put(url, res.clone())\n })\n})\n\n cache.put" }, { "answer_id": 72390770, "author": "Bucket", "author_id": 971246, "author_profile": "https://Stackoverflow.com/users/971246", "pm_score": 0, "selected": false, "text": "<img src=\"picture.jpg\">\n <img src=\"picture.JPG?t=current_time\">\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126772", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7984/" ]
126,781
<p>I'm translating a library written in C++ to C#, and the keyword 'union' exists once. In a struct.</p> <p>What's the correct way of translating it into C#? And what does it do? It looks something like this;</p> <pre><code>struct Foo { float bar; union { int killroy; float fubar; } as; } </code></pre>
[ { "answer_id": 126807, "author": "Armin Ronacher", "author_id": 19990, "author_profile": "https://Stackoverflow.com/users/19990", "pm_score": 8, "selected": true, "text": "[StructLayout(LayoutKind.Explicit)] \npublic struct SampleUnion\n{\n [FieldOffset(0)] public float bar;\n [FieldOffset(4)] public int killroy;\n [FieldOffset(4)] public float fubar;\n}\n" }, { "answer_id": 126867, "author": "ckramer", "author_id": 20504, "author_profile": "https://Stackoverflow.com/users/20504", "pm_score": 0, "selected": false, "text": "public struct Foo\n{\n float bar;\n int Kilroy;\n float Fubar;\n}\n" }, { "answer_id": 39614418, "author": "Steve Lillis", "author_id": 4230704, "author_profile": "https://Stackoverflow.com/users/4230704", "pm_score": 2, "selected": false, "text": "union BitConverter float fubar = 125f; \nint killroy = BitConverter.ToInt32(BitConverter.GetBytes(fubar), 0);\n int killroy = 125;\nfloat fubar = BitConverter.ToSingle(BitConverter.GetBytes(killroy), 0);\n" }, { "answer_id": 51097798, "author": "Yan Chen", "author_id": 1545391, "author_profile": "https://Stackoverflow.com/users/1545391", "pm_score": -1, "selected": false, "text": "public class Foo\n{\n public float bar;\n public int killroy;\n\n public float fubar\n {\n get{ return (float)killroy;}\n set{ killroy = (int)value;}\n }\n}\n" }, { "answer_id": 71504088, "author": "Kenneth Parker", "author_id": 1449630, "author_profile": "https://Stackoverflow.com/users/1449630", "pm_score": 0, "selected": false, "text": " public class MyUnion\n {\n private object _id;\n public T GetValue<T>() => (T)_id;\n public void SetValue<T>(T value) => _id = value;\n }\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126781", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15067/" ]
126,787
<p>Almost every Python web framework has a simple server that runs a wsgi application and automatically reloads the imported modules every time the source gets changed. I know I can look at the code and see how it's done, but that may take some time and I'm asking just out of curiosity. Does anyone have any idea how this is implemented?</p>
[ { "answer_id": 126843, "author": "Armin Ronacher", "author_id": 19990, "author_profile": "https://Stackoverflow.com/users/19990", "pm_score": 3, "selected": true, "text": "reload()" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126787", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7883/" ]
126,794
<p>I'm trying to write a query that will pull back the two most recent rows from the Bill table where the Estimated flag is true. The catch is that these need to be consecutive bills. </p> <p>To put it shortly, I need to enter a row in another table if a Bill has been estimated for the last two bill cycles.</p> <p>I'd like to do this without a cursor, if possible, since I am working with a sizable amount of data and this has to run fairly often.</p> <p><strong>Edit</strong></p> <p>There is an AUTOINCREMENT(1,1) column on the table. Without giving away too much of the table structure, the table is essentially of the structure:</p> <pre><code> CREATE TABLE Bills ( BillId INT AUTOINCREMENT(1,1,) PRIMARY KEY, Estimated BIT NOT NULL, InvoiceDate DATETIME NOT NULL ) </code></pre> <p>So you might have a set of results like:</p> <pre> BillId AccountId Estimated InvoiceDate -------------------- -------------------- --------- ----------------------- 1111196 1234567 1 2008-09-03 00:00:00.000 1111195 1234567 0 2008-08-06 00:00:00.000 1111194 1234567 0 2008-07-03 00:00:00.000 1111193 1234567 0 2008-06-04 00:00:00.000 1111192 1234567 1 2008-05-05 00:00:00.000 1111191 1234567 0 2008-04-04 00:00:00.000 1111190 1234567 1 2008-03-05 00:00:00.000 1111189 1234567 0 2008-02-05 00:00:00.000 1111188 1234567 1 2008-01-07 00:00:00.000 1111187 1234567 1 2007-12-04 00:00:00.000 1111186 1234567 0 2007-11-01 00:00:00.000 1111185 1234567 0 2007-10-01 00:00:00.000 1111184 1234567 1 2007-08-30 00:00:00.000 1111183 1234567 0 2007-08-01 00:00:00.000 1111182 1234567 1 2007-07-02 00:00:00.000 1111181 1234567 0 2007-06-01 00:00:00.000 1111180 1234567 1 2007-05-02 00:00:00.000 1111179 1234567 0 2007-03-30 00:00:00.000 1111178 1234567 1 2007-03-02 00:00:00.000 1111177 1234567 0 2007-02-01 00:00:00.000 1111176 1234567 1 2007-01-03 00:00:00.000 1111175 1234567 0 2006-11-29 00:00:00.000 </pre> <p>In this case, only records 1111188 and 1111187 would be consecutive.</p>
[ { "answer_id": 126828, "author": "Kibbee", "author_id": 1862, "author_profile": "https://Stackoverflow.com/users/1862", "pm_score": 2, "selected": false, "text": "select top 2 * \nfrom bills\nwhere estimated = 1 \norder by billdate desc\n" }, { "answer_id": 126848, "author": "kristian", "author_id": 20377, "author_profile": "https://Stackoverflow.com/users/20377", "pm_score": 5, "selected": true, "text": "select top 1 * \nfrom \nBills b1\ninner join Bills b2 on b1.id = b2.id - 1\nwhere\nb1.IsEstimate = 1 and b2.IsEstimate = 1\norder by\nb1.BillDate desc\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126794", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11780/" ]
126,798
<p>Does anyone know how to solve this java error?</p> <pre><code>java.io.IOException: Invalid keystore format </code></pre> <p>I get it when I try and access the certificate store from the Java option in control panels. It's stopping me from loading applets that require elevated privileges.</p> <p><a href="http://img72.imageshack.us/my.php?image=javaerrorxq7.jpg" rel="nofollow noreferrer">Error Image</a></p>
[ { "answer_id": 126981, "author": "Craig Day", "author_id": 5193, "author_profile": "https://Stackoverflow.com/users/5193", "pm_score": 3, "selected": true, "text": "C:\\Documents and Settings\\CDay\\Application Data\\Sun\\Java\\Deployment\\security" }, { "answer_id": 23430647, "author": "Emperor 2052", "author_id": 2055938, "author_profile": "https://Stackoverflow.com/users/2055938", "pm_score": -1, "selected": false, "text": "C:\\Users\\<username>\\AppData\\LocalLow\\Sun\\Java\\Deployment\\security\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126798", "https://Stackoverflow.com", "https://Stackoverflow.com/users/942/" ]
126,800
<p>In a destructor, is there a way to determine if an exception is currently being processed?</p>
[ { "answer_id": 126950, "author": "Eddie", "author_id": 21116, "author_profile": "https://Stackoverflow.com/users/21116", "pm_score": 0, "selected": false, "text": "struct my_exception1\n{\n explicit my_exception1( int res_code ) : m_res_code( res_code ) {}\n int m_res_code;\n};\n\n\nstruct my_exception2\n{\n explicit my_exception2( int res_code ) : m_res_code( res_code ) {}\n int m_res_code;\n};\n\nclass dangerous_call {\npublic:\n dangerous_call( int argc ) : m_argc( argc ) {}\n int operator()()\n {\n if( m_argc < 2 )\n throw my_exception1( 23 );\n if( m_argc > 3 )\n throw my_exception2( 45 );\n else if( m_argc > 2 )\n throw \"too many args\";\n\n return 1;\n }\n\nprivate:\n int m_argc;\n};\n\n\nvoid translate_my_exception1( my_exception1 const& ex )\n{\n std::cout << \"Caught my_exception1(\" << ex.m_res_code << \")\"<< std::endl;\n}\n\n\nvoid translate_my_exception2( my_exception2 const& ex )\n{\n std::cout << \"Caught my_exception2(\" << ex.m_res_code << \")\"<< std::endl;\n}\n\n\n\nint \ncpp_main( int argc , char *[] )\n{ \n ::boost::execution_monitor ex_mon;\n ex_mon.register_exception_translator<my_exception1>(\n &translate_my_exception1);\n ex_mon.register_exception_translator<my_exception2>(\n &translate_my_exception2);\n try{\n // ex_mon.detect_memory_leak( true);\n ex_mon.execute( ::boost::unit_test::callback0<int>( \n dangerous_call( argc ) ) );\n } \n catch ( boost::execution_exception const& ex ) {\n std::cout << \"Caught exception: \" << ex.what() << std::endl;\n }\n return 0;\n}\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126800", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
126,801
<p>I'm confused about what the various testing appliances in Ruby on Rails are for. I have been using the framework for about 6 months but I've never understood the testing part of it. The only testing I've used is JUnit3 in Java and that only briefly.</p> <p>Everything I've read about it just shows testing validations. Shouldn't the validations in rails just work? It seems more like testing the framework than testing the your code. Why would you need to test validations? </p> <p>Furthermore, the tests seem super fragile to any change in your code. So if you change anything in your models, you have to change your tests and fixtures to match. Doesn't this violate the DRY principle?</p> <p>Third, writing test code seems to take alot of time. Is that normal? Wouldn't it just be faster to refresh my browser and see if it worked? I already have to play with my application just to see if it flows correctly and make sure my CSS hasn't exploded. Why wouldn't manual testing be enough?</p> <p>I've asked these questions before and I haven't gotten more than "automated testing is automated". I am smart enough to figure out the advantages of automating a task. My problem is that costs of writing tests seem absurdly high compared to the benefits. That said, any detailed response is welcome because I probably missed a benefit or two.</p>
[ { "answer_id": 130710, "author": "Ian Terrell", "author_id": 9269, "author_profile": "https://Stackoverflow.com/users/9269", "pm_score": 6, "selected": true, "text": "validates_numericality_of" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126801", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16204/" ]
126,804
<p>I have used "traditional" version control systems to maintain source code repositories on past projects. I am starting a new project with a distributed team and I can see advantages to using a distributed system. Given that I understand SourceSafe, CVS, and Subversion; what suggestions do you have for a Git newbie?</p>
[ { "answer_id": 126937, "author": "Jonathan Tran", "author_id": 12887, "author_profile": "https://Stackoverflow.com/users/12887", "pm_score": 2, "selected": false, "text": "-a git commit -a git diff git diff git status" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126804", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3014/" ]
126,829
<p>Here's a question to expose my lack of experience: I have a method <strong>DoSomething()</strong> which throws an exception if it doesn't manage to do it cleanly. If it fails, I try the less accurate method <strong>DoSomethingApproximately()</strong> several times in the hope that it will find a sufficiently good solution; if this also fails I finally call <strong>DoSomethingInaccurateButGuaranteedToWork()</strong>. All three are methods belonging to this object.</p> <p>Two questions: first, is this (admittedly ugly) pattern acceptable, or is there a more elegant way?</p> <p>Second, what is the best way to keep track of how many times I have called <strong>DoSomethingApproximately()</strong>, given that it is likely to throw an exception? I am currently keeping a variable iNoOfAttempts in the object, and nesting try blocks... this is horrible and I am ashamed. </p>
[ { "answer_id": 126859, "author": "Vinko Vrsalovic", "author_id": 5190, "author_profile": "https://Stackoverflow.com/users/5190", "pm_score": 2, "selected": false, "text": " bool result = DoSomething();\n while (!result && tries < MAX_TRIES) {\n result = DoSomethingApproximately(); //This will increment tries\n if (tries > THRESHOLD) {\n result = DoSomethingThatAlwaysWorks();\n }\n }\n" }, { "answer_id": 126916, "author": "Marcin", "author_id": 21640, "author_profile": "https://Stackoverflow.com/users/21640", "pm_score": 2, "selected": false, "text": "try{ return doSomething(); }\ncatch(ExpectedException) { ...not much here probably...}\n\nfor(i = 0 to RETRIES){\ntry{ return doSomethingApproximately; }\ncatch(ExpectedException) { ...not much here probably...}\n}\n\ndoSomethingGuaranteed();\n" }, { "answer_id": 127082, "author": "Mark Brackett", "author_id": 2199, "author_profile": "https://Stackoverflow.com/users/2199", "pm_score": 2, "selected": false, "text": "Queue<Action> actions = new Queue<Action>(new Action[] {\n obj.DoSomething,\n obj.DoSomethingApproximately,\n obj.DoSomethingApproximately,\n obj.DoSomethingApproximately,\n obj.DoSomethingApproximately,\n obj.DoSomethingGuaranteed\n});\n\nactions.First(a => {\n try {\n a();\n return true;\n } catch (Exception) {\n return false;\n }\n});\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126829", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6091/" ]
126,853
<p>I saw <a href="http://www.gnegg.ch/2008/09/automatic-language-detection/" rel="nofollow noreferrer">this</a> on reddit, and it reminded me of one of my vim gripes: It shows the UI in German. I want English. But since my OS is set up in German (the standard at our office), I guess vim is actually trying to be helpful.</p> <p>What magic incantations must I perform to get vim to switch the UI language? I have tried googling on various occasions, but can't seem to find an answer.</p>
[ { "answer_id": 126858, "author": "Armin Ronacher", "author_id": 19990, "author_profile": "https://Stackoverflow.com/users/19990", "pm_score": 2, "selected": false, "text": "LC_ALL=en_GB.utf-8 vim\n" }, { "answer_id": 127539, "author": "Aristotle Pagaltzis", "author_id": 9410, "author_profile": "https://Stackoverflow.com/users/9410", "pm_score": 6, "selected": true, "text": ":language .vimrc .gvimrc LC_ALL LC_MESSAGES --cmd -c gvim --cmd \"lang en_US\"\n LC_ALL LANG=en_US.utf8\nLC_CTYPE=de_DE.utf8\nLC_COLLATE=C\n man 7 locale" }, { "answer_id": 1831461, "author": "Pavel Bastov", "author_id": 22623, "author_profile": "https://Stackoverflow.com/users/22623", "pm_score": 4, "selected": false, "text": "set langmenu=en_US.UTF-8\n" }, { "answer_id": 2860971, "author": "August Lilleaas", "author_id": 26051, "author_profile": "https://Stackoverflow.com/users/26051", "pm_score": 7, "selected": false, "text": "C:\\Program Files (x86)\\Vim\\vim72\\lang" }, { "answer_id": 5403623, "author": "Anton Orel", "author_id": 368144, "author_profile": "https://Stackoverflow.com/users/368144", "pm_score": 3, "selected": false, "text": "if has('unix')\n language messages C\nelse\n language messages en\nendif\n" }, { "answer_id": 6967789, "author": "zjk", "author_id": 264442, "author_profile": "https://Stackoverflow.com/users/264442", "pm_score": 5, "selected": false, "text": "set langmenu=en_US\nlet $LANG = 'en_US'\nsource $VIMRUNTIME/delmenu.vim\nsource $VIMRUNTIME/menu.vim\n" }, { "answer_id": 8227089, "author": "Marc", "author_id": 1059800, "author_profile": "https://Stackoverflow.com/users/1059800", "pm_score": 2, "selected": false, "text": "let $LANG = 'en'\nset langmenu=none\n" }, { "answer_id": 8770404, "author": "PerseP", "author_id": 1128695, "author_profile": "https://Stackoverflow.com/users/1128695", "pm_score": 4, "selected": false, "text": "set langmenu=en_US.UTF-8 [or just set langmenu=en for short]\n language en \n :let $LANG = 'en'\n language messages en\n" }, { "answer_id": 31152145, "author": "Ignacio", "author_id": 3389227, "author_profile": "https://Stackoverflow.com/users/3389227", "pm_score": 3, "selected": false, "text": "set langmenu=en_US\nlet $LANG = 'en_US'\n" }, { "answer_id": 41089301, "author": "it3xl", "author_id": 390940, "author_profile": "https://Stackoverflow.com/users/390940", "pm_score": 2, "selected": false, "text": "vim --version | grep vimrc\n C:\\Program Files (x86)\\Vim\\vim80\\lang language messages en_US C:\\Program Files\\Git\\etc\\vimrc C:\\Program Files\\Git\\usr\\share\\vim\\vim80\\lang C:\\Users\\User_name_xxx\\AppData\\Local\\Programs\\Git\\usr\\share\\vim\\vim80\\lang C:\\Program Files\\Git\\etc\\bash.bashrc LANG='en_US' LANG=C en_US.UTF-8 find 'xxx_yyy_zzz_aaa.bbbddd'" }, { "answer_id": 42717200, "author": "s.m.", "author_id": 129782, "author_profile": "https://Stackoverflow.com/users/129782", "pm_score": 0, "selected": false, "text": "Program Files\\Vim\\vim80\\lang" }, { "answer_id": 48237964, "author": "Lucien", "author_id": 8583134, "author_profile": "https://Stackoverflow.com/users/8583134", "pm_score": 1, "selected": false, "text": "let $LANG='en_US'\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126853", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2260/" ]
126,855
<p>I have two tables, Users and DoctorVisit</p> <p>User - UserID - Name</p> <p>DoctorsVisit - UserID - Weight - Date </p> <p>The doctorVisit table contains all the visits a particular user did to the doctor. The user's weight is recorded per visit.</p> <p>Query: Sum up all the Users weight, using the last doctor's visit's numbers. (then divide by number of users to get the average weight)</p> <p>Note: some users may have not visited the doctor at all, while others may have visited many times.</p> <p>I need the average weight of all users, but using the latest weight.</p> <p><b>Update</b></p> <p>I want the average weight across all users.</p>
[ { "answer_id": 126892, "author": "JPrescottSanders", "author_id": 19444, "author_profile": "https://Stackoverflow.com/users/19444", "pm_score": 0, "selected": false, "text": "select user.name, temp.AvgWeight\nfrom user left outer join (select userid, avg(weight)\n from doctorsvisit\n group by userid) temp\n on user.userid = temp.userid\n" }, { "answer_id": 126900, "author": "Hank Gay", "author_id": 4203, "author_profile": "https://Stackoverflow.com/users/4203", "pm_score": 0, "selected": false, "text": "SELECT AVG(weight) FROM (QueryA)\n" }, { "answer_id": 126909, "author": "Josef", "author_id": 5581, "author_profile": "https://Stackoverflow.com/users/5581", "pm_score": 2, "selected": false, "text": "SELECT avg(uv.weight) FROM (SELECT weight FROM uservisit uv INNER JOIN\n(SELECT userid, MAX(dateVisited) DateVisited FROM uservisit GROUP BY userid) us \nON us.UserID = uv.UserId and us.DateVisited = uv.DateVisited\n" }, { "answer_id": 126929, "author": "Adam Bellaire", "author_id": 21632, "author_profile": "https://Stackoverflow.com/users/21632", "pm_score": 0, "selected": false, "text": "SELECT AVG(dv.Weight) \nFROM DoctorsVisit dv\nWHERE dv.Date = (\n SELECT MAX(Date)\n FROM DoctorsVisit innerdv\n WHERE innerdv.UserID = dv.UserID\n )\n" }, { "answer_id": 128246, "author": "DaveF", "author_id": 17579, "author_profile": "https://Stackoverflow.com/users/17579", "pm_score": 0, "selected": false, "text": "SELECT AVG(a.weight) FROM\n(select\n ROW_NUMBER() OVER(PARTITION BY dv.UserId ORDER BY Date desc) as ID,\n dv.weight \nfrom \n DoctorsVisit dv) a \nWHERE a.Id = 1\n" }, { "answer_id": 128746, "author": "Walter Mitty", "author_id": 19937, "author_profile": "https://Stackoverflow.com/users/19937", "pm_score": 0, "selected": false, "text": "select\n avg(a.Weight) as AverageWeight\nfrom\n DoctorsVisit as a\ninnner join\n (select \n UserID,\n max (Date) as LatestDate\n from\n DoctorsVisit\n group by\n UserID) as b\n on a.UserID = b.UserID and a.Date = b.LatestDate;\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126855", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
126,863
<p>In some instances, I prefer working with custom objects instead of strongly typed datasets and data rows. However, it seems like Microsoft Reporting (included with VS2005) requires strongly typed datasets.</p> <p>Is there a way to use my custom objects to design and populate reports?</p>
[ { "answer_id": 11303040, "author": "CRice", "author_id": 55693, "author_profile": "https://Stackoverflow.com/users/55693", "pm_score": 2, "selected": false, "text": "Aies.Core.Model.Invoice.MemberInvoice reportViewer.LocalReport.DataSources.Add(new ReportDataSource(\"MemberInvoice\", new[] { invoice1 }));\n <DataSources>\n <DataSource Name=\"MemberInvoice\">\n <ConnectionProperties>\n <DataProvider>System.Data.DataSet</DataProvider>\n <ConnectString>/* Local Connection */</ConnectString>\n </ConnectionProperties>\n <rd:DataSourceID>3fe04def-105a-4e9b-99db-630c1f8bb2c9</rd:DataSourceID>\n </DataSource>\n </DataSources>\n <DataSets>\n <DataSet Name=\"MemberInvoice\">\n <Fields>\n <Field Name=\"MemberId\">\n <DataField>MemberId</DataField>\n <rd:TypeName>System.Int32</rd:TypeName>\n </Field>\n <Field Name=\"DateOfIssue\">\n <DataField>DateOfIssue</DataField>\n <rd:TypeName>System.DateTime</rd:TypeName>\n </Field>\n <Field Name=\"DateDue\">\n <DataField>DateDue</DataField>\n <rd:TypeName>System.DateTime</rd:TypeName>\n </Field>\n <Field Name=\"Amount\">\n <DataField>Amount</DataField>\n <rd:TypeName>System.Decimal</rd:TypeName>\n </Field>\n </Fields>\n <Query>\n <DataSourceName>MemberInvoice</DataSourceName>\n <CommandText>/* Local Query */</CommandText>\n </Query>\n <rd:DataSetInfo>\n <rd:DataSetName>Aies.Core.Model.Invoice</rd:DataSetName>\n <rd:TableName>MemberInvoiceData</rd:TableName>\n <rd:ObjectDataSourceSelectMethod>GetInvoices</rd:ObjectDataSourceSelectMethod>\n <rd:ObjectDataSourceSelectMethodSignature>System.Collections.Generic.IEnumerable`1[Aies.Core.Model.Invoice.MemberInvoice] GetInvoices()</rd:ObjectDataSourceSelectMethodSignature>\n <rd:ObjectDataSourceType>Aies.Core.Model.Invoice.MemberInvoiceData, Aies.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</rd:ObjectDataSourceType>\n </rd:DataSetInfo>\n </DataSet>\n </DataSets>\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126863", "https://Stackoverflow.com", "https://Stackoverflow.com/users/681/" ]
126,868
<p>I'm developing a C# assembly which is to be called via COM from a Delphi 7 (iow, native win32, not .net) application.</p> <p>So far, it seems to work. I've exported a TLB file, imported that into my Delphi project, and I can create my C# object and call its functions.</p> <p>So that's great, but soon I'm going to <strong>really</strong> want to use Visual Studio to debug the C# code while it's running. Set breakpoints, step through code, all that stuff.</p> <p>I've tried breaking in the Delphi code after the COM object is created, then looking for a process for VS to attach to, but I can't find one.</p> <p>Is there a way to set VS2008 up to do this? I'd prefer to just be able to hit f5 and have VS start the Delphi executable, wait for the C# code to be called, and then attach itself to it.. But I could live with manually attaching to a process, I suppose.</p> <p>Just please don't tell me I have to make do with MessageBox.Show etc.</p>
[ { "answer_id": 126886, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "#if DEBUG\n if (!System.Diagnostics.Debugger.IsAttached)\n Debugger.Launch();\n#endif\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126868", "https://Stackoverflow.com", "https://Stackoverflow.com/users/369/" ]
126,870
<p>I am designing a class that stores (caches) a set of data. I want to lookup a value, if the class contains the value then use it and modify a property of the class. I am concerned about the design of the public interface.<br> Here is how the class is going to be used:</p> <pre> ClassItem *pClassItem = myClass.Lookup(value); if (pClassItem) { // item is found in class so modify and use it pClassItem->SetAttribute(something); ... // use myClass } else { // value doesn't exist in the class so add it myClass.Add(value, something); } </pre> <p>However I don't want to have to expose ClassItem to this client (ClassItem is an implementation detail of MyClass). To get round that the following could be considered:</p> <pre> bool found = myClass.Lookup(value); if (found) { // item is found in class so modify and use it myClass.ModifyAttribute(value, something); ... // use myClass } else { // value doesn't exist in the class so add it myClass.Add(value, something); } </pre> <p>However this is inefficient as Modify will have to do the lookup again. This would suggest a lookupAndModify type of method:</p> <pre> bool found = myClass.LookupAndModify(value, something); if (found) { // item is found in class ... // use myClass } else { // value doesn't exist in the class so add it myClass.Add(value, something); } </pre> <p>But rolling LookupAndModify into one method seems like very poor design. It also only modifies if value is found and so the name is not only cumbersome but misleading as well.</p> <p>Is there another better design that gets round this issue? Any design patterns for this (I couldn't find anything through google)?</p>
[ { "answer_id": 126944, "author": "Mark Brackett", "author_id": 2199, "author_profile": "https://Stackoverflow.com/users/2199", "pm_score": 1, "selected": false, "text": "if (!myClass.AddIfNotExists(value, something)) {\n // use myClass\n}\n if (myClass.TryModify(value, something)) {\n // use myClass\n} else {\n myClass.Add(value, otherSomething);\n}\n" }, { "answer_id": 127865, "author": "S.Lott", "author_id": 10661, "author_profile": "https://Stackoverflow.com/users/10661", "pm_score": 2, "selected": true, "text": "ClassItem * void *index = myClass.lookup( value );\nif( index ) {\n myClass.modify( index, value );\n}\nelse {\n myClass.add( value );\n}\n" }, { "answer_id": 137944, "author": "user22044", "author_id": 22044, "author_profile": "https://Stackoverflow.com/users/22044", "pm_score": 2, "selected": false, "text": "std::set<>::insert() myClass.SetAttribute(value, something)\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126870", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12663/" ]
126,876
<p>During a complicated update I might prefer to display all the changes at once. I know there is a method that allows me to do this, but what is it?</p>
[ { "answer_id": 126904, "author": "Romain Verdier", "author_id": 4687, "author_profile": "https://Stackoverflow.com/users/4687", "pm_score": 2, "selected": false, "text": "BeginUpdate EndUpdate" }, { "answer_id": 126914, "author": "moobaa", "author_id": 3569, "author_profile": "https://Stackoverflow.com/users/3569", "pm_score": 3, "selected": false, "text": "[DllImport(\"user32.dll\")]\nprivate static extern long LockWindowUpdate(long Handle);\n\ntry {\n // Lock Window...\n LockWindowUpdate(frm.Handle);\n // Perform your painting / updates...\n} \nfinally {\n // Release the lock...\n LockWindowUpdate(0);\n}\n" }, { "answer_id": 126952, "author": "Magnus Johansson", "author_id": 3584, "author_profile": "https://Stackoverflow.com/users/3584", "pm_score": 4, "selected": false, "text": "SuspendLayout() ResumeLayout() LockWindowsUpdate() LockWindowUpdate using System;\nusing System.Windows.Forms;\nusing Microsoft.Win32;\nusing System.Runtime.InteropServices;\n\npublic partial class Form1 : Form\n{\n [DllImport(\"user32.dll\")]\n public static extern int SendMessage(IntPtr hWnd, Int32 wMsg, bool wParam, Int32 lParam);\n private const int WM_SETREDRAW = 11; \n\n public Form1()\n {\n InitializeComponent();\n }\n\n private void button1_Click(object sender, EventArgs e)\n {\n SendMessage(this.Handle, WM_SETREDRAW, false, 0);\n\n // Do your thingies here\n SendMessage(this.Handle, WM_SETREDRAW, true, 0);\n\n this.Refresh();\n }\n}\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126876", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4694/" ]
126,885
<p>We have a SQL Server table containing Company Name, Address, and Contact name (among others).</p> <p>We regularly receive data files from outside sources that require us to match up against this table. Unfortunately, the data is slightly different since it is coming from a completely different system. For example, we have "123 E. Main St." and we receive "123 East Main Street". Another example, we have "Acme, LLC" and the file contains "Acme Inc.". Another is, we have "Ed Smith" and they have "Edward Smith" </p> <p>We have a legacy system that utilizes some rather intricate and CPU intensive methods for handling these matches. Some involve pure SQL and others involve VBA code in an Access database. The current system is good but not perfect and is cumbersome and difficult to maintain </p> <p>The management here wants to expand its use. The developers who will inherit the support of the system want to replace it with a more agile solution that requires less maintenance. </p> <p>Is there a commonly accepted way for dealing with this kind of data matching?</p>
[ { "answer_id": 126903, "author": "torial", "author_id": 13990, "author_profile": "https://Stackoverflow.com/users/13990", "pm_score": 3, "selected": true, "text": " Public Shared Function FindMostSimilarString(ByVal toFind As String, ByVal ParamArray stringList() As String) As String\n Dim bestMatch As String = \"\"\n Dim bestDistance As Integer = 1000 'Almost anything should be better than that!\n\n For Each matchCandidate As String In stringList\n Dim candidateDistance As Integer = LevenshteinDistance(toFind, matchCandidate)\n If candidateDistance < bestDistance Then\n bestMatch = matchCandidate\n bestDistance = candidateDistance\n End If\n Next\n\n Return bestMatch\n End Function\n\n 'This will be used to determine how similar strings are. Modified from the link below...\n 'Fxn from: http://ca0v.terapad.com/index.cfm?fa=contentNews.newsDetails&newsID=37030&from=list\n Public Shared Function LevenshteinDistance(ByVal s As String, ByVal t As String) As Integer\n Dim sLength As Integer = s.Length ' length of s\n Dim tLength As Integer = t.Length ' length of t\n Dim lvCost As Integer ' cost\n Dim lvDistance As Integer = 0\n Dim zeroCostCount As Integer = 0\n\n Try\n ' Step 1\n If tLength = 0 Then\n Return sLength\n ElseIf sLength = 0 Then\n Return tLength\n End If\n\n Dim lvMatrixSize As Integer = (1 + sLength) * (1 + tLength)\n Dim poBuffer() As Integer = New Integer(0 To lvMatrixSize - 1) {}\n\n ' fill first row\n For lvIndex As Integer = 0 To sLength\n poBuffer(lvIndex) = lvIndex\n Next\n\n 'fill first column\n For lvIndex As Integer = 1 To tLength\n poBuffer(lvIndex * (sLength + 1)) = lvIndex\n Next\n\n For lvRowIndex As Integer = 0 To sLength - 1\n Dim s_i As Char = s(lvRowIndex)\n For lvColIndex As Integer = 0 To tLength - 1\n If s_i = t(lvColIndex) Then\n lvCost = 0\n zeroCostCount += 1\n Else\n lvCost = 1\n End If\n ' Step 6\n Dim lvTopLeftIndex As Integer = lvColIndex * (sLength + 1) + lvRowIndex\n Dim lvTopLeft As Integer = poBuffer(lvTopLeftIndex)\n Dim lvTop As Integer = poBuffer(lvTopLeftIndex + 1)\n Dim lvLeft As Integer = poBuffer(lvTopLeftIndex + (sLength + 1))\n lvDistance = Math.Min(lvTopLeft + lvCost, Math.Min(lvLeft, lvTop) + 1)\n poBuffer(lvTopLeftIndex + sLength + 2) = lvDistance\n Next\n Next\n Catch ex As ThreadAbortException\n Err.Clear()\n Catch ex As Exception\n WriteDebugMessage(Application.StartupPath , [Assembly].GetExecutingAssembly().GetName.Name.ToString, MethodBase.GetCurrentMethod.Name, Err)\n End Try\n\n Return lvDistance - zeroCostCount\n End Function\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126885", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2173/" ]
126,894
<p>I use the right button>Refactor>Encapsultate field to have my accessor every time. The problem is when I create new class, I can have more than 10 attributes and it's long to do 1 by 1 every accessor. Is there a faster way to create them?</p> <p>Thank you for your time.</p>
[ { "answer_id": 142910, "author": "Jay Bazuzi", "author_id": 5314, "author_profile": "https://Stackoverflow.com/users/5314", "pm_score": 1, "selected": false, "text": "public string Name { get; private set; }\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126894", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13913/" ]
126,896
<p>we are using git-svn to manage branches of an SVN repo. We are facing the following problem: after a number of commits by user X in the branch, user Y would like to use git-svn to merge the changes in branch to trunk. The problem we're seeing is that the commit messages for all the individual merge operations look as if they were made by user Y, whereas the actual change in branch was made by user X.</p> <p>Is there a way to indicate to git-svn that when merging, use the original commit message/author for a given change rather than the person doing the merge?</p>
[ { "answer_id": 127242, "author": "richq", "author_id": 4596, "author_profile": "https://Stackoverflow.com/users/4596", "pm_score": 5, "selected": true, "text": "------------------------------------------------------------------------\nr5 | Y | 2008-09-24 15:17:12 +0200 (Wed, 24 Sep 2008) | 1 line\n\nMerged release-1.0 into trunk\n------------------------------------------------------------------------\nr4 | X | 2008-09-24 15:16:13 +0200 (Wed, 24 Sep 2008) | 1 line\nMerged via: r5\n\nReturn 1\n------------------------------------------------------------------------\nr3 | X | 2008-09-24 15:15:48 +0200 (Wed, 24 Sep 2008) | 2 lines\nMerged via: r5\n\nCreate a branch\n 2 Y int main()\n 2 Y {\nG 4 X return 1;\n 2 Y }\n git merge git svn dcommit git svn clone svn merge" }, { "answer_id": 127380, "author": "Aristotle Pagaltzis", "author_id": 9410, "author_profile": "https://Stackoverflow.com/users/9410", "pm_score": 3, "selected": false, "text": "echo \"$merge_sha1 $parent1_sha1 $parent2_sha1\" >> .git/info/grafts\n $merge_sha1 $parent1_sha1 git svn find-rev r$revnum $branch\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126896", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
126,897
<p>The question is pretty self-explanatory. I'm looking for a PostgreSQL equivalent to the <a href="http://www.sqlite.org/cvstrac/wiki?p=DateAndTimeFunctions" rel="nofollow noreferrer">SQLite datetime function</a>.</p>
[ { "answer_id": 126920, "author": "Vinko Vrsalovic", "author_id": 5190, "author_profile": "https://Stackoverflow.com/users/5190", "pm_score": 3, "selected": false, "text": "postgres=# select to_char(now(),'YYYY-mm-dd HH:MM:ss');\n to_char\n---------------------\n 2008-09-24 02:09:20\n(1 row)\n\npostgres=# select to_char(now(),'YYYY-mm-dd HH24:MM:ss');\n to_char\n---------------------\n 2008-09-24 14:09:20\n(1 row)\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126897", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6583/" ]
126,898
<p>I ran into a problem a few days ago when I had to introduce C++ files into a Java project. It started with a need to measure the CPU usage of the Java process and it was decided that the way to go was to use JNI to call out to a native library (a shared library on a Unix machine) written in C. The problem was to find an appropriate place to put the C files in the source repository (incidentally Clearcase) which consists of only Java files.</p> <p>I thought of a couple of alternatives:</p> <p>(a) Create a separate directory for putting the C files (specifically, one .h file and one .c file) at the top of the source base like:</p> <p>/vobs/myproduct/javasrc /vobs/myproduct/cppsrc</p> <p>I didn't like this because I have only two C files and it seemed very odd to split the source base at the language level like this. Had substantial portions of the project been written more or less equally in C++ and Java, this could be okay.</p> <p>(b) Put the C files into the Java package that uses it.</p> <p>I have the calling Java classes in /vobs/myproduct/com/mycompany/myproduct/util/ and the C files also go in there.</p> <p>I didn't like this either because I think the C files just don't belong in the Java package.</p> <p>Has anybody solved a problem like this before? Generally, what's a good strategy to follow when organizing codebase that mixes two or more languages?</p> <p>Update: I don't have any plan to use any C or C++ in my project, some Jython perhaps, but you never know when my customers need a feature that can be solved only by using C or best solved by using C.</p>
[ { "answer_id": 127018, "author": "m_pGladiator", "author_id": 446104, "author_profile": "https://Stackoverflow.com/users/446104", "pm_score": 0, "selected": false, "text": "Product/Workspace(1)/JavaProject1/src \nProduct/Workspace(1)/JavaProject2/src \nProduct/Workspace(1 or 2)/CPPproject1/src \nProduct/Workspace(1 or 2)/CPPproject2/src ...\n" }, { "answer_id": 127022, "author": "Jim Kiley", "author_id": 7178, "author_profile": "https://Stackoverflow.com/users/7178", "pm_score": 2, "selected": false, "text": "src/main/java src/test/java src/main/resources src/test/resources src/main/cpp src/test/cpp" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126898", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21647/" ]
126,917
<p>In ASPNET, I grew to love the Application and Cache stores. They're awesome. For the uninitiated, you can just throw your data-logic objects into them, and hey-presto, you only need query the database once for a bit of data. </p> <p>By far one of the best ASPNET features, IMO.</p> <p>I've since ditched Windows for Linux, and therefore PHP, Python and Ruby for webdev. I use PHP most because I dev several open source projects, all using PHP.</p> <p>Needless to say, I've explored what PHP has to offer in terms of caching data-objects. So far I've played with:</p> <ol> <li>Serializing to file (a pretty slow/expensive process)</li> <li>Writing the data to file as JSON/XML/plaintext/etc (even slower for read ops)</li> <li>Writing the data to file as pure PHP (the fastest read, but quite a convoluted write op)</li> </ol> <p>I should stress now that I'm looking for a solution that doesn't rely on a third party app (eg memcached) as the apps are installed in all sorts of scenarios, most of which don't have install rights (eg: a cheap shared hosting account).</p> <p>So back to what I'm doing now, <strong>is persisting to file secure?</strong> <code>Rule 1</code> in production server security has always been disable file-writing, but I really don't see any way PHP <em>could</em> cache if it couldn't write. Are there any tips and/or tricks to boost the security?</p> <p><strong>Is there another persist-to-file method that I'm forgetting?</strong></p> <p><strong>Are there any better methods of caching in "limited" environments?</strong></p>
[ { "answer_id": 127098, "author": "Michael Johnson", "author_id": 17688, "author_profile": "https://Stackoverflow.com/users/17688", "pm_score": 2, "selected": false, "text": "project/\n app/\n html/\n index.php\n data/\n cache/\n app cache data project/html index.php app" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126917", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12870/" ]
126,925
<p>I have an Internet Explorer Browser Helper Object (BHO), written in c#, and in various places I open forms as modal dialogs. Sometimes this works but in some cases it doesn't. The case that I can replicate at present is where IE is running javascript to open other child windows... I guess it's getting a bit confused somewhere.... </p> <p>The problem is that when I call:</p> <pre><code>(new MyForm(someParam)).ShowDialog(); </code></pre> <p>the form is not modal, so I can click on the IE window and it gets focus. Since IE is in the middle of running my code it doesn't refresh and therefore to the user it appears that IE is hanging.</p> <p>Is there a way of ensuring that the form will be opened as modal, ie that it's not possible for the form to be hidden behind IE windows.</p> <p>(I'm using IE7.)</p> <p>NB: this is a similar question to <a href="https://stackoverflow.com/questions/73000/modal-dialogs-in-ie-gets-hidden-behind-ie-if-user-clicks-on-ie-pane">this post</a> although that's using java. I guess the solution is around correctly passing in the IWin32Window of the IE window, so I'm looking into that.</p>
[ { "answer_id": 126959, "author": "Rory", "author_id": 8479, "author_profile": "https://Stackoverflow.com/users/8479", "pm_score": 2, "selected": true, "text": "IWebBrowser2 browser = siteObject as IWebBrowser2;\nif (browser != null) hwnd = new IntPtr(browser.HWND);\n(new MyForm(someParam)).ShowDialog(new WindowWrapper(hwnd));\n\n...\n\n// Wrapper class so that we can return an IWin32Window given a hwnd\npublic class WindowWrapper : System.Windows.Forms.IWin32Window\n{\n public WindowWrapper(IntPtr handle)\n {\n _hwnd = handle;\n }\n\n public IntPtr Handle\n {\n get { return _hwnd; }\n }\n\n private IntPtr _hwnd;\n}\n" }, { "answer_id": 2341942, "author": "g t", "author_id": 254882, "author_profile": "https://Stackoverflow.com/users/254882", "pm_score": 2, "selected": false, "text": "internal class WindowWrapper : IWin32Window\n{\n public IntPtr Handle { get; private set; }\n public WindowWrapper(IntPtr hwnd) { Handle = hwnd; }\n}\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126925", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8479/" ]
126,926
<p>It seems like if you compile a Visual Studio solution and have a version # in your AssemblyInfo.cs file, that should propagate to say, the Windows Explorer properties dialog. This way, someone could simply right click on the *.exe and click 'properties' to see the version #. Is there a special setting in Visual Studio to make this happen?</p> <p><a href="http://content.screencast.com/users/Pincas/folders/Jing/media/40442efd-6d74-4d8a-8e77-c1e725e6c150/2008-09-24_0849.png" rel="nofollow noreferrer">example picture http://content.screencast.com/users/Pincas/folders/Jing/media/40442efd-6d74-4d8a-8e77-c1e725e6c150/2008-09-24_0849.png</a></p> <p>Edit: I should have mentioned that this is, specifically, for .NET <strong>Compact Framework</strong> 2.0, which doesn't support AssemblyFileVersion. Is all hope lost?</p>
[ { "answer_id": 126948, "author": "Nigel Hawkins", "author_id": 1389021, "author_profile": "https://Stackoverflow.com/users/1389021", "pm_score": 1, "selected": false, "text": "[assembly: AssemblyFileVersion(\"1.0.114.0\")]" }, { "answer_id": 126961, "author": "Wolfwyrd", "author_id": 15570, "author_profile": "https://Stackoverflow.com/users/15570", "pm_score": 1, "selected": false, "text": "[assembly: AssemblyFileVersion(\"1.0.114.0\")]\n" }, { "answer_id": 25671986, "author": "jarmst", "author_id": 3169713, "author_profile": "https://Stackoverflow.com/users/3169713", "pm_score": 2, "selected": false, "text": "[assembly: AssemblyInformationalVersion(\"1.0.0.0 Alpha\")]\n //using System.Reflection;\n//using System.Linq;\npublic static string AssemblyInformationalVersion\n{\n get\n {\n AssemblyInformationalVersionAttribute informationalVersion = (AssemblyInformationalVersionAttribute) \n (AssemblyInformationalVersionAttribute.GetCustomAttributes(Assembly.GetExecutingAssembly())).Where( \n at => at.GetType().Name == \"AssemblyInformationalVersionAttribute\").First();\n\n return informationalVersion.InformationalVersion;\n }\n}\n //using System.Reflection;\npublic static string AssemblyVersion\n{\n get\n {\n return Assembly.GetExecutingAssembly().GetName().Version.ToString();\n }\n}\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126926", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2273/" ]
126,966
<p>What I'm looking for is a simple timer queue possibly with an external timing source and a poll method (in this way it will be multi-platform). Each enqueued message could be an object implementing a simple interface with a <code>virtual onTimer()</code> member function.</p>
[ { "answer_id": 127074, "author": "TonJ", "author_id": 11537, "author_profile": "https://Stackoverflow.com/users/11537", "pm_score": 2, "selected": false, "text": "#ifdef -- #endif" }, { "answer_id": 127182, "author": "Len Holgate", "author_id": 7925, "author_profile": "https://Stackoverflow.com/users/7925", "pm_score": 3, "selected": true, "text": "Boost::ASIO" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126966", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15785/" ]
126,976
<p>I am looking for a good primer or technical description of the <strong>System Call</strong> mechanism that is used by operating systems to transition from user space to the kernel to invoke functions such as "open", "read", "write", etc...</p> <p>Is there anything other than the <a href="http://en.wikipedia.org/wiki/System_call" rel="nofollow noreferrer">Wikipedia</a> entry? Websites, pdfs, books, source code, all are welcome :)</p>
[ { "answer_id": 127187, "author": "Mike Dimmick", "author_id": 6970, "author_profile": "https://Stackoverflow.com/users/6970", "pm_score": 2, "selected": false, "text": "SYSCALL SYSENTER" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126976", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10703/" ]
126,980
<p>I would like to support keyboard shortcuts in my WPF XBAP application, such as <kbd>Ctrl</kbd>+<kbd>O</kbd> for 'Open' etc. How do I disable the browsers built-in keyboard shortcuts and replace them with my own?</p>
[ { "answer_id": 1058624, "author": "John Donoghue", "author_id": 130473, "author_profile": "https://Stackoverflow.com/users/130473", "pm_score": 1, "selected": false, "text": "Private Shared m_handle As IntPtr\nPrivate Shared m_hook As Interop.HwndSourceHook\nPrivate Shared m_hookCreated As Boolean = False\n\n'Call on application start\nPublic Shared Sub SetWindowHook(ByVal visualSource As Visual)\n 'Add in a Win32 hook to stop the browser app from loading\n If Not m_hookCreated Then\n m_handle = DirectCast(PresentationSource.FromVisual(visualSource), Interop.HwndSource).Handle\n m_hook = New Interop.HwndSourceHook(AddressOf WindowProc)\n Interop.HwndSource.FromHwnd(m_handle).AddHook(m_hook)\n m_hookCreated = True\n End If\nEnd Sub\n\n'Call on application exit\nPublic Shared Sub RemoveWindowHook()\n 'Remove the win32 hook\n If m_hookCreated AndAlso Not m_hook Is Nothing Then\n If Not Interop.HwndSource.FromHwnd(m_handle) Is Nothing Then\n Interop.HwndSource.FromHwnd(m_handle).RemoveHook(m_hook)\n End If\n m_hook = Nothing\n m_handle = IntPtr.Zero\n End If\nEnd Sub\n\n'Intercept key presses\nPrivate Shared Function WindowProc(ByVal hwnd As System.IntPtr, ByVal msg As Integer, ByVal wParam As System.IntPtr, ByVal lParam As System.IntPtr, ByRef handled As Boolean) As System.IntPtr\n 'Stop the OS from handling help\n If msg = WM_HELP Then\n handled = True\n End If\n Return IntPtr.Zero\nEnd Function\n" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126980", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
126,999
<p>When writing j2me applications for cellphones, using <code>System.out.println()</code> prints on the console if using an emulator. However, when the code is deployed on a cellphone, where does the console output go?</p> <p>If it is impossible to see this in the untethered cellphone, is there a way to see it if the cellphone is still connected to the deploying PC [via USB] ?</p>
[ { "answer_id": 127078, "author": "Animesh", "author_id": 20386, "author_profile": "https://Stackoverflow.com/users/20386", "pm_score": 2, "selected": false, "text": "System.out.println()" }, { "answer_id": 807496, "author": "kozen", "author_id": 98649, "author_profile": "https://Stackoverflow.com/users/98649", "pm_score": 0, "selected": false, "text": "System.out" }, { "answer_id": 1499644, "author": "michael aubert", "author_id": 17867, "author_profile": "https://Stackoverflow.com/users/17867", "pm_score": 2, "selected": false, "text": "javax.microedition.io.Connector.openDataInputStream(\"redirect://\");" } ]
2008/09/24
[ "https://Stackoverflow.com/questions/126999", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20386/" ]