instruction
stringlengths
14
27.6k
completion
stringlengths
3
38.3k
__original_row_idx
int64
0
50k
conversations
listlengths
2
2
I'm filtering the messages that come to a form with PreFilterMessage like this: print("code sample"); public bool PreFilterMessage(ref Message m) { if (m.Msg == WM_KEYDOWN && (int)m.WParam == VK_ESCAPE) { this.Close(); return true; } return false; } print("code sample"); but t...
The issue you're experiencing where the form only closes on the first press of the ESC key is likely related to how the message filtering works and how the event handlers are being managed in your form. When the form is closed and reopened, certain message filters may not be registered or may not behave as expected. T...
38,033
[ { "from": "human", "value": "I'm filtering the messages that come to a form with PreFilterMessage like this:\nprint(\"code sample\");\n public bool PreFilterMessage(ref Message m) \n {\n if (m.Msg == WM_KEYDOWN && (int)m.WParam == VK_ESCAPE)\n {\n this.Close();\n return true;\n }...
I want to be able to launch a third party process from within an Adobe AIR application (actually a command line process). Is there a security context that AIR apps run in that prevents this?
Yes, Adobe AIR applications do run in a security context that imposes certain restrictions, especially when it comes to interacting with the operating system. By default, AIR applications operate in a sandboxed environment, which limits their ability to execute external processes directly. However, there are some appr...
36,741
[ { "from": "human", "value": "I want to be able to launch a third party process from within an Adobe AIR application (actually a command line process). Is there a security context that AIR apps run in that prevents this?\n" }, { "from": "gpt", "value": "Yes, Adobe AIR applications do run in a sec...
Is there a site online that lists common regular expressions or has a utility to help you create one based on sample text? Thanks!
Yes, there are several websites and resources that can help you find common regular expressions and assist you in creating your own based on sample text. Here are a few that you might find useful: 1. **Regex101** (https://regex101.com/): This is an excellent tool for testing and building regular expressions. It provid...
38,711
[ { "from": "human", "value": "Is there a site online that lists common regular expressions or has a utility to help you create one based on sample text?\nThanks!\n" }, { "from": "gpt", "value": "Yes, there are several websites and resources that can help you find common regular expressions and as...
Is it possible to load balance a Lucene.NET index across multiple processes / servers? Since Lucene.NET is filebased is it possible to just make a simple filecopy (using i.e. robocopy) of the index to the servers serving queries?
Loading balance a Lucene.NET index across multiple processes or servers involves several considerations, as Lucene.NET is primarily designed for high-performance text search and indexing on a single instance. Here's an overview of the approaches you might take and their implications: ### 1. **Read-Only Replication:** ...
36,279
[ { "from": "human", "value": "Is it possible to load balance a Lucene.NET index across multiple processes / servers?\nSince Lucene.NET is filebased is it possible to just make a simple filecopy (using i.e. robocopy) of the index to the servers serving queries?\n" }, { "from": "gpt", "value": "Loa...
I'm sick of waiting hours for Flash to publish. .NET / VisualStudio projects are WAAAAY faster - is that only compiling the classes that have changed? Update: Does the Flash IDE re-encode all your sounds and images every time you publish? Can't it cache them somewhere?
It sounds like you're experiencing some frustration with the Flash IDE's publishing process, which is understandable. The speed of the publishing process can differ significantly between Flash and .NET/Visual Studio projects due to how they handle compilation and asset management. ### .NET / Visual Studio Publishing ...
36,800
[ { "from": "human", "value": "I'm sick of waiting hours for Flash to publish. .NET / VisualStudio projects are WAAAAY faster - is that only compiling the classes that have changed?\nUpdate: Does the Flash IDE re-encode all your sounds and images every time you publish? Can't it cache them somewhere?\n" }, ...
I've read the documentation on WideCharToMultiByte, but I'm stuck on this parameter: lpMultiByteStr [out] Pointer to a buffer that receives the converted string. I'm not quite sure how to properly initialize the variable and feed it into the function
To use the `WideCharToMultiByte` function effectively, you need to allocate a buffer for the resulting multi-byte string. The `lpMultiByteStr` parameter is a pointer to this buffer where the function will store the converted string. Here’s a step-by-step explanation of how to initialize the variable and call the funct...
32,908
[ { "from": "human", "value": "I've read the documentation on WideCharToMultiByte, but I'm stuck on this parameter:\nlpMultiByteStr\n[out] Pointer to a buffer that receives the converted string.\n\nI'm not quite sure how to properly initialize the variable and feed it into the function\n" }, { "from":...
How does the HttpBrowserCapabilities.Crawler property (http://msdn.microsoft.com/en-us/library/aa332775(VS.71).aspx) work? I need to detect a partner's custom crawler and this property is returning false. Where/How can I add his user agent so that this property will return true? Any other way outside of creating my...
The `HttpBrowserCapabilities.Crawler` property in ASP.NET is designed to identify whether the request is coming from a web crawler or bot. It does this by checking the user agent string against a list of known crawlers. If the user agent is not recognized as a crawler, the property will return `false`. To have the pro...
35,468
[ { "from": "human", "value": "How does the HttpBrowserCapabilities.Crawler property (http://msdn.microsoft.com/en-us/library/aa332775(VS.71).aspx) work? I need to detect a partner's custom crawler and this property is returning false. \nWhere/How can I add his user agent so that this property will return t...
Real UID, effective UID, and some systems even have a "saved UID". What's the purpose of all these, especially the last one?
In Unix-like operating systems, user identifiers (UIDs) play a crucial role in managing permissions and access control. Here's a brief overview of the three types of UIDs you mentioned: real UID, effective UID, and saved UID. 1. **Real UID (RUID)**: - The real UID identifies the user who is currently logged into th...
34,788
[ { "from": "human", "value": "Real UID, effective UID, and some systems even have a \"saved UID\". What's the purpose of all these, especially the last one?\n" }, { "from": "gpt", "value": "In Unix-like operating systems, user identifiers (UIDs) play a crucial role in managing permissions and acc...
How do you add that little "X" button on the right side of a UITextField that clears the text? I can't find an attribute for adding this sub-control in Interface Builder in the iPhone OS 2.2 SDK. Note: In Xcode 4.x and later (iPhone 3.0 SDK and later), you can do this in Interface Builder.
In iOS versions prior to 3.0, there wasn't a built-in way to add a clear button directly to a `UITextField` in Interface Builder, but you can achieve this programmatically. Since you mentioned using iPhone OS 2.2 SDK, you would need to implement this in code. Here is how you can add a clear button (the "X" button) to ...
38,181
[ { "from": "human", "value": "How do you add that little \"X\" button on the right side of a UITextField that clears the text? I can't find an attribute for adding this sub-control in Interface Builder in the iPhone OS 2.2 SDK.\nNote: In Xcode 4.x and later (iPhone 3.0 SDK and later), you can do this in Int...
How can I change the background color of a Tab Control. I changed the forms color, but the tabs stay the same. Thanks.
To change the background color of a Tab Control in a Windows Forms application (WinForms), you need to take a few additional steps because the tab control does not automatically inherit the background color of the parent form. Instead, you'll typically need to customize the appearance of the tabs. Here's how you can d...
35,815
[ { "from": "human", "value": "How can I change the background color of a Tab Control. I changed the forms color, but the tabs stay the same.\nThanks.\n" }, { "from": "gpt", "value": "To change the background color of a Tab Control in a Windows Forms application (WinForms), you need to take a few...
I want to write a function that accepts two objects as parameters and compare only the fields contained within the objects. I do not know what type the objects will be at design time, but the objects passed will be classes used within our application. Is it possible to compare object's fields without knowing their type...
Yes, it's certainly possible to compare the fields of two objects without knowing their types at design time. In languages like Python, you can use reflection or introspection to achieve this. The idea is to access the attributes of the objects dynamically and compare them. Here's a simple example in Python to demonst...
35,794
[ { "from": "human", "value": "I want to write a function that accepts two objects as parameters and compare only the fields contained within the objects. I do not know what type the objects will be at design time, but the objects passed will be classes used within our application.\nIs it possible to compare ...
I know I should be using htmlentities for all my form text input fields but this doesn't work: <?php echo "<tr> <td align=\"right\">".Telephone." :</td> <td><input type=\"text\" name=\"telephone\" size=\"27\" value=\"htmlentities($row[telephone])\"> Inc. dialing codes </td> <...
The issue you're encountering is due to the way you're using the `htmlentities` function. In your code, you're treating the `htmlentities` function as a string literal within the double quotes, rather than executing it. To resolve this, you should call the `htmlentities` function outside of the string and then concat...
37,064
[ { "from": "human", "value": "I know I should be using htmlentities for all my form text input fields but this doesn't work:\n<?php\necho \"<tr>\n <td align=\\\"right\\\">\".Telephone.\" :</td> \n <td><input type=\\\"text\\\" name=\\\"telephone\\\" size=\\\"27\\\"\n value=\\\"html...
In C++, is it safe to extend scope via a reference? In code, what I mean is: MyCLass& function badIdea() { MyClass obj1; ... return obj1; }
No, it is not safe to return a reference to a local object from a function in C++. Your example has a critical issue. When the function `badIdea` returns, the local variable `obj1` goes out of scope and is destroyed. As a result, returning a reference to `obj1` would lead to undefined behavior because you would be refe...
37,023
[ { "from": "human", "value": "In C++, is it safe to extend scope via a reference?\nIn code, what I mean is: \nMyCLass& function badIdea()\n{\n MyClass obj1;\n ...\n return obj1;\n}\n\n" }, { "from": "gpt", "value": "No, it is not safe to return a reference to a local object from a functi...
EDIT: For the inner queries, there could be more than one match per inner query. It grabs a bunch of tags with the same game_ID. Thats why .First or .Max won't work. Need some help, I have a query in LINQ that looks like this: from yy in Tags_Lookups where yy.Tag_ID == (from xx in Tags_Lookups where xx.Game_ID == ne...
Certainly! The issue you are facing stems from attempting to compare `yy.Tag_ID` with a collection of `Tag_ID`s returned by the inner query. You need to use the `Contains` method correctly to check if `yy.Tag_ID` exists within the collection of `Tag_ID`s returned by the inner query. You can achieve this by transformin...
36,780
[ { "from": "human", "value": "EDIT: For the inner queries, there could be more than one match per inner query. It grabs a bunch of tags with the same game_ID. Thats why .First or .Max won't work.\nNeed some help, I have a query in LINQ that looks like this:\nfrom yy in Tags_Lookups\nwhere yy.Tag_ID == (fr...
The fuser command lets me know which processes are using a file or directory. I'm looking for command that does the opposite: lets me know which files are being used by a process. Update Forgot to mention that it's for a Solaris system.
On Solaris systems, you can use the `pfiles` command to list the files that are opened by a specific process. The `pfiles` command provides information about the file descriptors used by a given process, including regular files, sockets, pipes, and other types of files. Here’s how to use it: 1. First, you need to fin...
38,825
[ { "from": "human", "value": "The fuser command lets me know which processes are using a file or directory.\nI'm looking for command that does the opposite: lets me know which files are being used by a process.\n\nUpdate\nForgot to mention that it's for a Solaris system.\n" }, { "from": "gpt", "...
I have created an iPhone application based on an OpenGL view. Now I would like to show a "settings" form. Since my code runs in UIView, I have no pushViewController. How do I show a view controller on screen? Thanks!
To display a settings form or any other view controller while your application is primarily using a custom `UIView` (such as an OpenGL view), you can present a new `UIViewController` modally from your current view controller. Here's a simple way to do this: 1. **Create a Settings View Controller**: First, ensure you h...
35,439
[ { "from": "human", "value": "I have created an iPhone application based on an OpenGL view. Now I \nwould like to show a \"settings\" form. Since my code runs in UIView, I have no pushViewController. How do I show a view controller on screen?\nThanks!\n" }, { "from": "gpt", "value": "To display a...
I've Googled this in various ways, and there's no shortage of software to do it. Since this is something I'm unlikely ever to do again, I'd prefer a free solution, but I'm also willing to pay if the best solution requires it. I'm a fairly skilled software developer in multiple languages, so if anyone knows of a library...
Converting SWF files to H.264 can be a bit tricky, especially since SWF is a vector graphics format and is not designed for direct video output. However, there are several methods you can try on macOS to achieve this conversion. ### Free Solutions 1. **FFmpeg**: This is a powerful command-line tool that can handle a ...
35,195
[ { "from": "human", "value": "I've Googled this in various ways, and there's no shortage of software to do it. Since this is something I'm unlikely ever to do again, I'd prefer a free solution, but I'm also willing to pay if the best solution requires it.\nI'm a fairly skilled software developer in multiple ...
Is there any way to have a reset button in the SSRS parameter window?
SQL Server Reporting Services (SSRS) does not provide a built-in "reset" button in the parameters window of a report. However, you can implement a workaround to allow users to clear or reset the parameters. Here are a few potential methods: ### 1. Default Values You can set default values for parameters that effective...
37,132
[ { "from": "human", "value": "Is there any way to have a reset button in the SSRS parameter window?\n" }, { "from": "gpt", "value": "SQL Server Reporting Services (SSRS) does not provide a built-in \"reset\" button in the parameters window of a report. However, you can implement a workaround to a...
This is my code: internal enum WindowsMessagesFlags { WM_EXITSIZEMOVE = 0x00000232, WM_DISPLAYCHANGE = 0x0000007e, WM_MOVING = 0x00000216, } protected override void WndProc(ref Message m) { switch(m.Msg) { case (int)WindowsMessagesFlags.WM_DISPLAYCHANGE: FixWindo...
Yes, you can avoid casting by using the enum directly in the switch statement. Since the `enum` is defined as `internal`, it should be accessible within the same assembly. You can modify the `WndProc` method to use the enum values directly. Here's how you can do it: ```csharp protected override void WndProc(ref Messag...
39,494
[ { "from": "human", "value": "This is my code:\ninternal enum WindowsMessagesFlags {\n WM_EXITSIZEMOVE = 0x00000232,\n WM_DISPLAYCHANGE = 0x0000007e,\n WM_MOVING = 0x00000216,\n}\n\nprotected override void WndProc(ref Message m) {\n switch(m.Msg) {\n case (int)WindowsMe...
I have a RegEx that is working for me but I don't know WHY it is working for me. I'll explain. RegEx: \s*<in.*="(<?.*?>)"\s*/>\s* Text it finds (it finds the white-space before and after the input tag): <td class="style9"> <input name="guarantor4" id="guarantor4" size="50" type="text" tabindex="10" value="<?php...
The behavior you're observing in your regex is a result of how the `.*` (dot-star) operator works in regular expressions. Let's break down the relevant parts of your regex to clarify how it matches the input text. 1. **`<in`**: This part matches the literal string `<in`. This means that the regex is looking for any ta...
36,292
[ { "from": "human", "value": "I have a RegEx that is working for me but I don't know WHY it is working for me. I'll explain.\nRegEx: \\s*<in.*=\"(<?.*?>)\"\\s*/>\\s*\n\n\nText it finds (it finds the white-space before and after the input tag):\n<td class=\"style9\">\n <input name=\"guarantor4\" id=\"gua...
I am using sed from cygwin on Windows to do some substitutions in text files. Everything works fine for normal (ANSI) files, but it doesn't do anything for utf-16 files (no substitutions are made). Do you know how I can make it work for both types of files at the same time?
`sed` in Cygwin (or Unix-like environments) typically works with text files that are encoded in ASCII or UTF-8. It does not natively support UTF-16 encoding, which could be why you're seeing no substitutions for your UTF-16 files. To perform substitutions in UTF-16 files, you'll need to convert the files to a format t...
36,783
[ { "from": "human", "value": "I am using sed from cygwin on Windows to do some substitutions in text files. Everything works fine for normal (ANSI) files, but it doesn't do anything for utf-16 files (no substitutions are made). Do you know how I can make it work for both types of files at the same time? \n" ...
This is something that comes up so often I almost stopped thinking about it but I'm almost certain that I'm not doing this the best way. The question: Suppose you have the following table CREATE TABLE TEST_TABLE ( ID INTEGER, TEST_VALUE NUMBER, UPDATED DATE, FOREIGN_KEY INTEGER ); What is the be...
To efficiently retrieve the `TEST_VALUE` associated with the most recently updated row where `FOREIGN_KEY = 10`, you can avoid a potentially expensive `ORDER BY` operation by using a correlated subquery or a `ROW_NUMBER()` window function. Both approaches can be more efficient than sorting all the rows, especially in l...
37,087
[ { "from": "human", "value": "This is something that comes up so often I almost stopped thinking about it but I'm almost certain that I'm not doing this the best way.\nThe question: Suppose you have the following table\nCREATE TABLE TEST_TABLE\n(\n ID INTEGER,\n TEST_VALUE NUMBER,\n UPDATED ...
I have a BlackBerry app running in the background that needs to know when a "Missed call" system dialog is brought up by the system, and programmatically close it without user intervention. How can I do that? I could actually almost know when the dialog is brought up, i.e. a little later I programmatically end the call...
Interacting with system dialogs on BlackBerry (or any mobile platform, for that matter) in a way that programmatically closes them without user intervention is generally restricted by the platform's security model. This is typically in place to protect user experience and privacy. As of my last knowledge update in Oct...
35,751
[ { "from": "human", "value": "I have a BlackBerry app running in the background that needs to know when a \"Missed call\" system dialog is brought up by the system, and programmatically close it without user intervention. How can I do that?\nI could actually almost know when the dialog is brought up, i.e. a ...
In Ant is there any way to do something like this: <arguments id="arg-list"> <arg value="arg1" /> <arg value="arg2" /> </arguments> <property name="prop1" refid="arg-list" /> I'm trying to write a macro for psexec and I'm looking for a nice way to pass in the argument list. I know that you can do something si...
In Apache Ant, while you cannot directly reference an `arguments` structure like you can with classpaths, there are some ways to achieve similar results using properties or macros. The `refid` attribute is not supported for the `property` task in the way you're attempting to use it with `arguments`. However, you can ut...
36,852
[ { "from": "human", "value": "In Ant is there any way to do something like this:\n<arguments id=\"arg-list\">\n <arg value=\"arg1\" />\n <arg value=\"arg2\" />\n</arguments>\n\n<property name=\"prop1\" refid=\"arg-list\" />\n\nI'm trying to write a macro for psexec and I'm looking for a nice way to pas...
What is a DOCVARIABLE in Microsoft Word 2003? How do I set it? How do I make it display in my Word document?
In Microsoft Word 2003, a DOCVARIABLE is a type of field that allows you to define a variable that can store information for use throughout your document. This can be especially useful for managing repeated information, like author names, document titles, or dates, ensuring consistency and making updates easier. ### H...
35,993
[ { "from": "human", "value": "What is a DOCVARIABLE in Microsoft Word 2003? How do I set it? How do I make it display in my Word document?\n" }, { "from": "gpt", "value": "In Microsoft Word 2003, a DOCVARIABLE is a type of field that allows you to define a variable that can store information for ...
Is it a good practice to comment code that is removed? For example: // Code to do {task} was removed by Ajahn on 10/10/08 because {reason}. Someone in my developer group during a peer review made a note that we should comment the lines of code to be removed. I thought this was a terrible suggestion, since it clutters ...
When it comes to commenting on removed code, the approach largely depends on the context and the workflow of your development team. Here are a few key considerations: ### Pros of Commenting Removed Code: 1. **Historical Context**: Comments can provide valuable context about why certain code was removed, which can be h...
36,947
[ { "from": "human", "value": "Is it a good practice to comment code that is removed? For example:\n// Code to do {task} was removed by Ajahn on 10/10/08 because {reason}.\n\nSomeone in my developer group during a peer review made a note that we should comment the lines of code to be removed. I thought this w...
I could probably find this out from somewhere else but thought it would be a nice question to have on stack overflow. .NET 2.0 by default stopped managed exe's running from network shares despite the fact you can run unmanaged exe's. I have seen mention's that this was changed in .NET 3.5 SP1 Is this true? Would that ...
Yes, your understanding is mostly correct, and it's great that you're looking to clarify this! 1. **Execution Policy Change**: In .NET Framework 3.5 SP1, Microsoft introduced a change regarding the execution of managed applications from network shares. This change allowed managed executables (EXEs) to run from network...
30,372
[ { "from": "human", "value": "I could probably find this out from somewhere else but thought it would be a nice question to have on stack overflow.\n.NET 2.0 by default stopped managed exe's running from network shares despite the fact you can run unmanaged exe's. \nI have seen mention's that this was change...
Is there a way to have % in vim find the next ([{ or whatever, even if it is not on the same line? Example: int main(int argc, char ** argv) { #Your cursor is somewhere in this comment, I want #it to get to the ( after printf printf("Hello there.\n"); }
In Vim, you can use the `%` command to jump between matching pairs of parentheses, brackets, and braces. However, by default, the `%` command only works for characters on the same line. If you want to jump to the next matching character (like `(`, `{`, or `[`) across multiple lines, you can use a search command instead...
37,302
[ { "from": "human", "value": "Is there a way to have % in vim find the next ([{ or whatever, even if it is not on the same line?\nExample:\nint main(int argc, char ** argv) {\n #Your cursor is somewhere in this comment, I want\n #it to get to the ( after printf\n printf(\"Hello there.\\n\");\n}\n...
How do I force Postgres to use an index when it would otherwise insist on doing a sequential scan?
Forcing PostgreSQL to use an index instead of a sequential scan can be tricky, as PostgreSQL's query planner generally makes decisions based on cost estimates and the assumption that sequential scans are usually faster for large datasets. However, there are some approaches you can try to encourage or force the use of a...
36,245
[ { "from": "human", "value": "How do I force Postgres to use an index when it would otherwise insist on doing a sequential scan?\n" }, { "from": "gpt", "value": "Forcing PostgreSQL to use an index instead of a sequential scan can be tricky, as PostgreSQL's query planner generally makes decisions ...
I am trying to create a delegate protocol for a custom UIView. Here is my first attempt: @protocol FunViewDelegate @optional - (void) funViewDidInitialize:(FunView *)funView; @end @interface FunView : UIView { @private } @property(nonatomic, assign) id<FunViewDelegate> delegate; @end This doesn't work because ...
In Objective-C, when you need to declare a protocol that uses a class which has not been fully defined yet, you can use a forward declaration as you attempted, but you must ensure the forward declaration is placed correctly and that you use a `@class` declaration to avoid circular references. Here’s how you can do it ...
38,382
[ { "from": "human", "value": "I am trying to create a delegate protocol for a custom UIView. Here is my first attempt:\n@protocol FunViewDelegate\n@optional\n- (void) funViewDidInitialize:(FunView *)funView;\n@end\n\n\n@interface FunView : UIView { \n@private\n}\n\n@property(nonatomic, assign) id<FunViewD...
I have created a Visual Studio 2008 sp1 test suite web test that uploads a document to a document library in SharePoint. The test is a lot like the one described here. All is fine until the test is converted to a coded web test. Then the upload post returns the response "Request failed: Connot close stream until all b...
The error message "Request failed: Cannot close stream until all bytes are written" usually indicates that there is an issue with how the data is being written or streamed during the upload process in the coded web test. This can happen if the file stream is not properly handled or if there are issues with the HTTP req...
28,356
[ { "from": "human", "value": "I have created a Visual Studio 2008 sp1 test suite web test that uploads a document to a document library in SharePoint. The test is a lot like the one described here.\nAll is fine until the test is converted to a coded web test. Then the upload post returns the response \n\"Req...
I know I could do this with closures (var self = this) if object was a function: <a href="#" id="x">click here</a> <script type="text/javascript"> var object = { y : 1, handle_click : function (e) { alert('handling click'); //want to access y here retu...
In your code, the `handle_click` method is called as an event handler for the click event on the anchor element. However, when called this way, `this` within `handle_click` does not refer to the `object`, but rather to the element that triggered the event (in this case, the anchor element). To solve this problem and e...
36,919
[ { "from": "human", "value": "I know I could do this with closures (var self = this) if object was a function:\n<a href=\"#\" id=\"x\">click here</a>\n\n<script type=\"text/javascript\">\n var object = {\n y : 1,\n\n handle_click : function (e) {\n alert('handling click');\n \n...
In Linux When I invoke python from the shell it replicates its environment, and starts the python process. Therefore if I do something like the following: import os os.environ["FOO"] = "A_Value" When the python process returns, FOO, assuming it was undefined originally, will still be undefined. Is there a way for the ...
In Linux and Unix-like operating systems, when a child process (such as a Python script) is started, it inherits a copy of the environment variables from the parent process. However, any modifications made to environment variables within the child process do not affect the parent process's environment. This is because ...
36,438
[ { "from": "human", "value": "In Linux When I invoke python from the shell it replicates its environment, and starts the python process. Therefore if I do something like the following:\nimport os\nos.environ[\"FOO\"] = \"A_Value\"\n\nWhen the python process returns, FOO, assuming it was undefined originally,...
I'm working now together with others in a grails project. I have to write some Java-classes. But I need access to an searchable object created with groovy. It seems, that this object has to be placed in the default-package. My question is: Is there a way to access this object in the default-package from a Java-class i...
In Java, the concept of a "default package" refers to classes that do not belong to any named package. This means they are accessible only by other classes in the same default package. When you have a Java class in a named package (e.g., `com.example`), it cannot access classes that are in the default package due to th...
35,052
[ { "from": "human", "value": "I'm working now together with others in a grails project. I have to write some Java-classes. But I need access to an searchable object created with groovy. It seems, that this object has to be placed in the default-package. \nMy question is: Is there a way to access this object ...
Does anyone has a good solution for a C# version of the C++ __FUNCTION__ macro? The compiler does not seem to like it.
In C#, there's no direct equivalent to the C++ `__FUNCTION__` macro, which retrieves the name of the current function as a string at compile time. However, you can achieve similar functionality using the `nameof` operator or by utilizing the `StackTrace` class from the `System.Diagnostics` namespace. ### Option 1: Usi...
37,862
[ { "from": "human", "value": "Does anyone has a good solution for a C# version of the C++ __FUNCTION__ macro? The compiler does not seem to like it.\n" }, { "from": "gpt", "value": "In C#, there's no direct equivalent to the C++ `__FUNCTION__` macro, which retrieves the name of the current functi...
I'm looking for a way to change the CSS rules for pseudo-class selectors (such as :link, :hover, etc.) from JavaScript. So an analogue of the CSS code: a:hover { color: red } in JS. I couldn't find the answer anywhere else; if anyone knows that this is something browsers do not support, that would be a helpful result a...
You can modify CSS rules for pseudo-classes from JavaScript by manipulating the CSS stylesheets directly. Browsers support this functionality, and you can achieve the desired result by accessing the stylesheet and creating or modifying the appropriate CSS rules. Here's how you can do it: 1. Access the stylesheet. 2. ...
37,575
[ { "from": "human", "value": "I'm looking for a way to change the CSS rules for pseudo-class selectors (such as :link, :hover, etc.) from JavaScript.\nSo an analogue of the CSS code: a:hover { color: red } in JS.\nI couldn't find the answer anywhere else; if anyone knows that this is something browsers do no...
Given this in a grails action: def xml = { rss(version: '2.0') { ... } } render(contentType: 'application/rss+xml', xml) I see this: <rss><channel><title></title><description></description><link></link><item></item></channel></rss> Is there an easy way to pretty print the XML? Something built into the...
In Grails, the built-in rendering of XML does not include a pretty-print option directly in the `render` method. However, you can achieve pretty printing of the XML by converting the XML to a string and using an external library like `XmlUtil` from Groovy to format it properly. Here’s how you can do that: 1. First, y...
38,101
[ { "from": "human", "value": "Given this in a grails action:\ndef xml = {\n rss(version: '2.0') {\n ...\n }\n}\nrender(contentType: 'application/rss+xml', xml)\n\nI see this:\n<rss><channel><title></title><description></description><link></link><item></item></channel></rss>\n\nIs there an easy w...
I want to run a shell command in Terminal, then clear the console, from Applescript. If I was doing this by hand, I'd use ^K -- how do I send the ^K character in a string to Terminal?
In AppleScript, you can send control characters like `^K` (which represents the Control + K key combination) by using the `keystroke` command with the `using` parameter. You can also run a shell command directly from AppleScript and then clear the terminal using the appropriate keystroke. Here's an example AppleScript...
38,719
[ { "from": "human", "value": "I want to run a shell command in Terminal, then clear the console, from Applescript.\nIf I was doing this by hand, I'd use ^K -- how do I send the ^K character in a string to Terminal?\n" }, { "from": "gpt", "value": "In AppleScript, you can send control characters l...
some_var = foo() another_var = bar() or some_var = foo() another_var = bar() Including changing the whitespace as lines are added or removed to keep them lined up. Does this really look good? Is it worth the mucking up of the diff?
Aligning variable assignments like this can enhance readability by visually grouping related lines of code. However, it can also lead to several drawbacks: ### Pros: 1. **Readability**: It can make the code easier to read at a glance, especially if many variables are being defined together. 2. **Visual Consistency**: ...
38,234
[ { "from": "human", "value": "some_var = foo()\nanother_var = bar()\n\nor\nsome_var = foo()\nanother_var = bar()\n\nIncluding changing the whitespace as lines are added or removed to keep them lined up. Does this really look good? Is it worth the mucking up of the diff?\n" }, { "from": "gpt", ...
What is the best way to convert from Pascal Case (upper Camel Case) to a sentence. For example starting with "AwaitingFeedback" and converting that to "Awaiting feedback" C# preferable but I could convert it from Java or similar.
To convert a Pascal Case (Upper Camel Case) string like "AwaitingFeedback" to a sentence format like "Awaiting feedback", you can use the following C# approach. The idea is to insert a space before each uppercase letter that follows a lowercase letter and convert the first character to uppercase and the rest to lowerca...
37,943
[ { "from": "human", "value": "What is the best way to convert from Pascal Case (upper Camel Case) to a sentence.\nFor example starting with\n\"AwaitingFeedback\"\n\nand converting that to\n\"Awaiting feedback\"\n\nC# preferable but I could convert it from Java or similar.\n" }, { "from": "gpt", "...
We all know that you can overload a function according to the parameters: int mul(int i, int j) { return i*j; } std::string mul(char c, int n) { return std::string(n, c); } Can you overload a function according to the return value? Define a function that returns different things according to how the return value is u...
In C++, function overloading is based on the types of parameters passed to the function, but it cannot be based on the return type alone. However, we can achieve the desired behavior using templates and a helper type to distinguish between different uses of the return value. Here’s a way to implement a `mul` function...
32,809
[ { "from": "human", "value": "We all know that you can overload a function according to the parameters:\nint mul(int i, int j) { return i*j; }\nstd::string mul(char c, int n) { return std::string(n, c); } \n\nCan you overload a function according to the return value? Define a function that returns different ...
I've been doing some socket programming to transmit information across the wire. I've run into a problem with DataOutputStream.writeUTF(). It seems to allow strings of up to 64k but I have a few situations where I can run over this. Are there any good alternatives that support larger strings or do I need to roll my ...
The `DataOutputStream.writeUTF()` method indeed has a limitation on the length of the strings it can write, specifically a maximum of 65,535 bytes (or 64KB), due to the way it encodes the length of the string as a 16-bit integer. If you need to transmit strings larger than this limit, you have a few alternatives: ### ...
31,311
[ { "from": "human", "value": "I've been doing some socket programming to transmit information across the wire. I've run into a problem with DataOutputStream.writeUTF(). It seems to allow strings of up to 64k but I have a few situations where I can run over this. Are there any good alternatives that suppor...
Usually, we install VS.NET on our production server, to solve problems easily with our product, if necessary. Is this a good or bad idea?
Installing Visual Studio .NET (VS.NET) or any development tools on a production server is generally considered a bad practice for several reasons: 1. **Security Risks**: Development tools can introduce vulnerabilities that could be exploited by attackers. A production server should have a minimal attack surface, and u...
33,367
[ { "from": "human", "value": "Usually, we install VS.NET on our production server, to solve problems easily with our product, if necessary. \nIs this a good or bad idea?\n" }, { "from": "gpt", "value": "Installing Visual Studio .NET (VS.NET) or any development tools on a production server is gene...
I'm working on moving from using tables for layout purposes to using divs (yes, yes the great debate). I've got 3 divs, a header, content and footer. The header and footer are 50px each. How do I get the footer div to stay at the bottom of the page, and the content div to fill the space in between? I don't want to ...
To create a layout with a header, content area, and footer where the footer stays at the bottom of the page, you can use CSS Flexbox. This approach will allow the content div to fill the available space between the header and footer without hardcoding the height. Here’s a simple example of how to achieve this: ### HT...
27,533
[ { "from": "human", "value": "I'm working on moving from using tables for layout purposes to using divs (yes, yes the great debate). I've got 3 divs, a header, content and footer. The header and footer are 50px each. How do I get the footer div to stay at the bottom of the page, and the content div to fil...
I am new to mysqli, and trying to confirm that if I so something like the below, the errno will be set to the last error, if any, and not the error of the last query. Is this a decent practice or should I be checking for the error in between every query? Thanks! $mysqli->autocommit(FALSE); $mysqli->query("INSERT INT...
Your understanding of how `mysqli` error handling works is mostly correct, but there are some important considerations when it comes to using it effectively in your code. ### Key Points: 1. **Last Error Only**: The `$mysqli->errno` property holds the error number for the last error that occurred during the last MySQ...
37,713
[ { "from": "human", "value": "I am new to mysqli, and trying to confirm that if I so something like the below, the errno will be set to the last error, if any, and not the error of the last query. \nIs this a decent practice or should I be checking for the error in between every query?\nThanks! \n$mysqli->au...
I'm using GNU bash, version 3.00.15(1)-release (x86_64-redhat-linux-gnu). And this command: echo "-e" doesn't print anything. I guess this is because "-e" is one of a valid options of echo command because echo "-n" and echo "-E" (the other two options) also produce empty strings. The question is how to escape the seq...
In bash, when you use `echo` with options that start with a dash (`-`), those options can be interpreted as command-line options, which is why you're getting empty output for `-e`, `-n`, and `-E`. To print the string `-e` without it being interpreted as an option, you can do one of the following: 1. **Use `--` to ind...
38,435
[ { "from": "human", "value": "I'm using GNU bash, version 3.00.15(1)-release (x86_64-redhat-linux-gnu). And this command:\necho \"-e\" \n\ndoesn't print anything. I guess this is because \"-e\" is one of a valid options of echo command because echo \"-n\" and echo \"-E\" (the other two options) also produce ...
I am an upper level Software Engineering student currently in a Data Structures and Algorithms class. Our professor wants us to write a program using the List structure found in the C++ STL. I have been trying to use C# more and more, and was wondering if the ArrayList structure in .NET is a good substitute for the S...
While both C++ STL's `std::list` and C#'s `ArrayList` are used to store collections of items, they are quite different in terms of their implementation and characteristics. Here's a comparison of the two to help you understand whether `ArrayList` is a suitable substitute for `std::list`. ### 1. Underlying Data Structu...
30,543
[ { "from": "human", "value": "I am an upper level Software Engineering student currently in a Data Structures and Algorithms class. Our professor wants us to write a program using the List structure found in the C++ STL. I have been trying to use C# more and more, and was wondering if the ArrayList structu...
When editing really long code blocks (which should definitely be refactored anyway, but that's beyond the scope of this question), I often long for the ability to collapse statement blocks like one can collapse function blocks. That is to say, it would be great if the minus icon appeared on the code outline for everyt...
In Visual Studio 2008, the code folding feature is somewhat limited when it comes to collapsing conditional or iterative blocks (like `if`, `foreach`, `switch`, etc.) in C#. While you can collapse methods, classes, and regions, collapsing other types of blocks is not natively supported. Unfortunately, there is no bui...
36,311
[ { "from": "human", "value": "When editing really long code blocks (which should definitely be refactored anyway, but that's beyond the scope of this question), I often long for the ability to collapse statement blocks like one can collapse function blocks. That is to say, it would be great if the minus ico...
I'm currently looking into options for creating a client API for a RESTfull application. Up until now we have had WCF services to allow all application to connect to the Business Layer and we're growing dissatisfied with it. We already have most of the infrastructure in place for the web (html and json requests) but we...
Transitioning from WCF to a RESTful API can definitely be beneficial, especially when considering modern application architecture and the integration capabilities it provides. Here are some options and considerations you might find helpful as you explore creating a client API for your application: ### 1. API Specifica...
32,109
[ { "from": "human", "value": "I'm currently looking into options for creating a client API for a RESTfull application. Up until now we have had WCF services to allow all application to connect to the Business Layer and we're growing dissatisfied with it.\nWe already have most of the infrastructure in place f...
I have a website built using Asp.net and LinqToSql for Data Access. In a certain section of the site, LinqToSql produces a query that looks like this (from my dev machine): select ... from table1 left outer join table2 on table1 where ... left outer join table3 on table2 where ... Since the connection between table2 a...
The discrepancy you're encountering between your development environment and the production server may stem from the behavior of the LINQ to SQL query provider in different environments or potentially due to differences in the database schema or data. In your case, it appears that the condition used to construct the `...
29,343
[ { "from": "human", "value": "I have a website built using Asp.net and LinqToSql for Data Access. In a certain section of the site, LinqToSql produces a query that looks like this (from my dev machine):\nselect ...\nfrom table1\nleft outer join table2 on table1 where ...\nleft outer join table3 on table2 whe...
I have a dump of a windows service i made. The exception is that my code can't move a file (for some reason). Now, in my code there's a number of places where i move files around the filesystem. So, using Windbg, i'm trying to see the code where the exception occurs. here's my !clrstack dump.. 0:016> !clrstack -p OS Th...
To efficiently locate the specific `File.Move` call that is causing the issue in your `MyClass.Foo.DoSomeStuffInHere(System.String)` method using WinDbg, you can follow these steps: 1. **Get the Method's IL**: First, you need to find the Method Table and JIT-compiled code for `MyClass.Foo.DoSomeStuffInHere`. You can u...
33,325
[ { "from": "human", "value": "I have a dump of a windows service i made. The exception is that my code can't move a file (for some reason). Now, in my code there's a number of places where i move files around the filesystem. So, using Windbg, i'm trying to see the code where the exception occurs.\nhere's my ...
I've written a paged search stored procedure using SQL Server 2005. It takes a number of parameters and the search criteria is moderately complex. Due to the front-end architecture I need to be able to return the number of results that would come back without actually returning the results. The front end would then cal...
You are facing a common challenge in designing stored procedures that need to handle both counting and returning result sets. Here are a few strategies to address your requirements while considering the implications of maintainability, performance, and the existing architecture: ### 1. **Single Stored Procedure with a...
32,953
[ { "from": "human", "value": "I've written a paged search stored procedure using SQL Server 2005. It takes a number of parameters and the search criteria is moderately complex.\nDue to the front-end architecture I need to be able to return the number of results that would come back without actually returning...
We currently just utilize soap webservices for all our communication but have been thinking about moving to WCF instead. What are the benefits of using it over an asmx service? If we do go with a WCF service, can other languages still communicate with it? SOAP is standardized and all languages can interact with it. Ar...
Moving from ASMX web services to Windows Communication Foundation (WCF) services comes with several benefits that enhance communication capabilities, flexibility, and performance. Here’s a breakdown of the advantages of using WCF over ASMX and answers to your questions. ### Benefits of WCF over ASMX 1. **Multiple Pro...
34,168
[ { "from": "human", "value": "\nWe currently just utilize soap webservices for all our communication but have been thinking about moving to WCF instead. What are the benefits of using it over an asmx service?\nIf we do go with a WCF service, can other languages still communicate with it? SOAP is standardized...
For some reasons, I would like to do an explicit quoting of a string value (becoming a part of constructed SQL query) instead of waiting for implicit quotation performed by cursor.execute method on contents of its second parameter. By "implicit quotation" I mean: value = "Unsafe string" query = "SELECT * FROM some_tabl...
In Python's DB API (PEP 249), there is no standard built-in function for explicitly quoting strings for use in SQL queries. The preferred approach in Python is to use parameterized queries (as you've shown) to prevent SQL injection and ensure that values are properly escaped. However, if you are using `psycopg2` for P...
36,380
[ { "from": "human", "value": "For some reasons, I would like to do an explicit quoting of a string value (becoming a part of constructed SQL query) instead of waiting for implicit quotation performed by cursor.execute method on contents of its second parameter.\nBy \"implicit quotation\" I mean:\nvalue = \"U...
He want's to know our opinions on whether we should have flexitime, allow non-work related internet access etc. We've got about 200 people in the company, half are programmers half are sales. We all want the workplace to be productive and fun. What issues should I bring up? What are the arguments for and against them?...
When discussing policies like flexitime and non-work-related internet access in your workplace, it's important to consider various factors that affect both productivity and employee satisfaction. Here are some key issues to address, along with arguments for and against them, and suggestions on how to implement or regul...
35,065
[ { "from": "human", "value": "He want's to know our opinions on whether we should have flexitime, allow non-work related internet access etc.\nWe've got about 200 people in the company, half are programmers half are sales. We all want the workplace to be productive and fun.\n\nWhat issues should I bring up?\...
The company I work for has recently been hit with many header injection and file upload exploits on the sites we host and while we have fixed the problem with respect to header injection attacks, we have yet to get the upload exploits under control. I'm trying to set up a plug-and-play-type series of upload scripts to ...
Creating a secure file upload system in PHP involves several critical steps to prevent file upload vulnerabilities. Here’s a basic outline and sample code to help you set up a reliable and secure file upload script. This will ensure that you can safely allow users to upload files while minimizing the risk of exploits. ...
34,058
[ { "from": "human", "value": "The company I work for has recently been hit with many header injection and file upload exploits on the sites we host and while we have fixed the problem with respect to header injection attacks, we have yet to get the upload exploits under control.\nI'm trying to set up a plug-...
I have a Windows Forms app, that has a single ElementHost containing a WPF UserControl... in my WPF, I have a VERY simple ListView: <ListView Margin="4" ItemsSource="{Binding Notifications}"> <ListView.View> <GridView> <GridViewColumn Header="FirstName" DisplayMemberBinding="{Binding FirstName}"...
Performance issues when dealing with large collections in a WPF application can be influenced by a number of factors, including how data binding is set up, how items are rendered, and the efficiency of the visual tree. Let's explore the potential causes of the delays you are experiencing and suggest some optimization s...
34,567
[ { "from": "human", "value": "I have a Windows Forms app, that has a single ElementHost containing a WPF UserControl... in my WPF, I have a VERY simple ListView:\n<ListView Margin=\"4\" ItemsSource=\"{Binding Notifications}\">\n <ListView.View>\n <GridView>\n <GridViewColumn Header=\"Fir...
How would I be able to programmatically search and replace some text in a large number of PDF files? I would like to remove a URL that has been added to a set of files. I have been able to remove the link using javascript under Batch Processing in Adobe Pro, but the link text remains. I have seen recommendations to ...
To programmatically search and replace text in a large number of PDF files, you have several options. Since you've already found some success using Adobe Acrobat with JavaScript, I can recommend a few different approaches that can handle large batches of PDFs: ### 1. **Using Python with PyPDF2 or PyMuPDF (fitz)** Pyt...
34,965
[ { "from": "human", "value": "How would I be able to programmatically search and replace some text in a large number of PDF files? I would like to remove a URL that has been added to a set of files. I have been able to remove the link using javascript under Batch Processing in Adobe Pro, but the link text ...
I've got a class with Parent and Children properties. ADO.NET Entity Framework Hierarchical Page Class http://img148.imageshack.us/img148/6802/edmxxe8.gif I want to display this hierarchy in a WPF treeview. Here's my XAML... <TreeView Margin="12" Name="TreeViewPages" ItemsSource="{Binding}"> <TreeView.ItemTemplate>...
To display a hierarchical structure in a WPF TreeView, you need to ensure that the `ItemsSource` property of the `HierarchicalDataTemplate` is properly set up to allow for recursive nesting of items. Your current setup correctly binds to the `Children` property, but it seems like you might not have set up your `Childre...
34,009
[ { "from": "human", "value": "I've got a class with Parent and Children properties.\nADO.NET Entity Framework Hierarchical Page Class http://img148.imageshack.us/img148/6802/edmxxe8.gif\nI want to display this hierarchy in a WPF treeview.\nHere's my XAML...\n<TreeView Margin=\"12\" Name=\"TreeViewPages\" Ite...
How would you lay out the directory structure for a large C# solution, consisting of perhaps 20 to 30 projects, mostly C# but some C++? Where do you put external dependencies? When creating a branch in source control, do you branch absolutely everything? Do you override the defaults for where built files go?
When laying out a directory structure for a large C# solution with multiple projects, including C# and C++, it's essential to maintain clarity and organization. Below is a suggested directory structure, along with considerations for external dependencies, source control branching, and build outputs. ### Suggested Dire...
32,927
[ { "from": "human", "value": "How would you lay out the directory structure for a large C# solution, consisting of perhaps 20 to 30 projects, mostly C# but some C++? Where do you put external dependencies? When creating a branch in source control, do you branch absolutely everything? Do you override the defa...
I am working on a desktop application in PyGTK and seem to be bumping up against some limitations of my file organization. Thus far I've structured my project this way: application.py - holds the primary application class (most functional routines) gui.py - holds a loosely coupled GTK gui implementation. Handles sig...
You've raised some excellent points about structuring your PyGTK application and the challenges that can arise as your project grows. It's quite common for a single module to become bloated as functionality increases, so it's great that you're considering ways to refactor and improve organization. ### Suggestions for ...
33,252
[ { "from": "human", "value": "I am working on a desktop application in PyGTK and seem to be bumping up against some limitations of my file organization. Thus far I've structured my project this way:\n\napplication.py - holds the primary application class (most functional routines)\ngui.py - holds a loosely ...
Given my background as a generalist, I can cover much of the area from analog electronics to writing simple applications that interface to a RDBMS backend. I currently work in a company that develops hardware to solve industry-specific problems. We have an experienced programmer that have written business apps, video ...
Transitioning from high-level programming to low-level software or hardware programming can indeed be challenging, but it's often a rewarding journey. Your enthusiasm for low-level programming is important; it can be contagious and help motivate your colleague. Here are some thoughts based on my knowledge and experienc...
35,949
[ { "from": "human", "value": "Given my background as a generalist, I can cover much of the area from analog electronics to writing simple applications that interface to a RDBMS backend.\nI currently work in a company that develops hardware to solve industry-specific problems. We have an experienced programm...
I want to do something like this : myYear = record.GetValueOrNull<int?>("myYear"), Notice the nullable type as the generic parameter. Since the GetValueOrNull function could return null my first attempt was this: public static T GetValueOrNull<T>(this DbDataRecord reader, string columnName) where T : class { o...
Yes, it is possible to create a method that can return a nullable type as a generic parameter. The key is to avoid using `class` or `struct` constraints, as those apply to reference types and non-nullable value types, respectively. Instead, you can allow any type, and handle the nullable types explicitly within your me...
36,507
[ { "from": "human", "value": "I want to do something like this :\nmyYear = record.GetValueOrNull<int?>(\"myYear\"),\n\nNotice the nullable type as the generic parameter. \nSince the GetValueOrNull function could return null my first attempt was this: \npublic static T GetValueOrNull<T>(this DbDataRecord read...
I have a request for some contract work from an organization that uses Excel as a database and wants to do some work on the Excel data via a real database. (Yeah, I know, never mind...) The client has an Excel sheet that they use internally to keep track of some government programmes. The data from this Excel sheet use...
Yes, you can programmatically interface with Excel spreadsheets to read and modify specific cells while preserving the existing structure, formatting, and data links. There are several libraries available that allow you to work with Excel files programmatically. Here are some common approaches depending on your develop...
32,707
[ { "from": "human", "value": "I have a request for some contract work from an organization that uses Excel as a database and wants to do some work on the Excel data via a real database. (Yeah, I know, never mind...)\nThe client has an Excel sheet that they use internally to keep track of some government prog...
We would like to have the FormsCookieName of FormsCookiePath change per instance of our application. We have an application which has multiple instances on 1 server/domainname. Because of this we can only work in 1 application at the same time, since the cookies will overwrite eachother. Same for the Sessions btw. Is t...
Yes, you can dynamically set the FormsAuthentication cookie name for each instance of your application in the `Global.asax` file during the `Application_Start` event. You can leverage the license name (or any unique identifier) to generate a unique cookie name for each instance. Below are the steps to achieve this: 1....
32,701
[ { "from": "human", "value": "We would like to have the FormsCookieName of FormsCookiePath change per instance of our application. We have an application which has multiple instances on 1 server/domainname. Because of this we can only work in 1 application at the same time, since the cookies will overwrite e...
My Cocoa app needs some small dynamically generated windows. How can I programmatically create Cocoa windows at runtime? This is my non-working attempt so far. I see no result whatsoever. NSRect frame = NSMakeRect(0, 0, 200, 200); NSUInteger styleMask = NSBorderlessWindowMask; NSRect rect = [NSWindow contentRectForF...
Your current attempt to create a Cocoa window programmatically looks almost correct, but there are a couple of important considerations. Specifically, you should ensure the window is made key and visible, and you may want to consider how the window's frame and contentRect are set. Here's a modified version of your co...
36,792
[ { "from": "human", "value": "My Cocoa app needs some small dynamically generated windows. How can I programmatically create Cocoa windows at runtime?\nThis is my non-working attempt so far. I see no result whatsoever.\nNSRect frame = NSMakeRect(0, 0, 200, 200);\nNSUInteger styleMask = NSBorderlessWindowM...
In a nutshell, the hashCode contract, according to Java's object.hashCode(): The hash code shouldn't change unless something affecting equals() changes equals() implies hash codes are == Let's assume interest primarily in immutable data objects - their information never changes after they're constructed, so #1 is ass...
You are correct that ensuring the `hashCode` contract holds in Java, especially for immutable data objects, is crucial for maintaining consistent behavior in collections like `HashMap` and `HashSet`. Writing effective unit tests to verify that `equals()` implies `hashCode()` can be a bit of a challenge, especially when...
16,804
[ { "from": "human", "value": "In a nutshell, the hashCode contract, according to Java's object.hashCode():\n\nThe hash code shouldn't change unless something affecting equals() changes\nequals() implies hash codes are ==\n\nLet's assume interest primarily in immutable data objects - their information never c...
This isn't my code; I am trying to figure out what exactly this does. This is a part of a big, ancient system written in C (actually it was written 4 years ago, but most likely written by a late 80s programmer mentality). Part of the code: char DestFile[256]; char DestFile2[256]; //This part is just to show an example...
You're correct in your understanding of what this code does, and let's break it down step-by-step. 1. **Variable Declarations:** ```c char DestFile[256]; char DestFile2[256]; ``` These lines declare two character arrays (strings) with a maximum length of 256 characters. These will be used to store file ...
34,832
[ { "from": "human", "value": "This isn't my code; I am trying to figure out what exactly this does. This is a part of a big, ancient system written in C (actually it was written 4 years ago, but most likely written by a late 80s programmer mentality). Part of the code:\nchar DestFile[256];\nchar DestFile2[25...
I have a class with the following member functions: /// caller pid virtual pid_t Pid() const = 0; /// physical memory size in KB virtual uint64_t Size() const = 0; /// resident memory for this process virtual uint64_t Rss() const = 0; /// cpu used by this process virtual double PercentCpu() const = 0; /// mem...
To retrieve process information in a way that is efficient and avoids invoking external commands like `ps` or `top`, you can make use of the `/proc` filesystem or the Mach API for process details. Since you are on macOS, the `/proc` filesystem isn't available, but you can use the Mach API and sysctl calls to get the ne...
34,088
[ { "from": "human", "value": "I have a class with the following member functions:\n\n/// caller pid\nvirtual pid_t Pid() const = 0; \n\n/// physical memory size in KB\nvirtual uint64_t Size() const = 0; \n\n/// resident memory for this process\nvirtual uint64_t Rss() const = 0; \n\n/// cpu used by this proc...
My application has a WCF service tier between the front-end and the database. Since we currently host in IIS6 we are using SOAP over HTTP. How can I find out how much real world time I am spending doing serialization activities in my application?
To measure the real-world time spent on serialization activities in your WCF service tier, you can follow these steps: ### 1. **Enable WCF Tracing** WCF provides built-in tracing capabilities that allow you to log detailed information about service calls, including serialization and deserialization times. You can ena...
34,959
[ { "from": "human", "value": "My application has a WCF service tier between the front-end and the database. Since we currently host in IIS6 we are using SOAP over HTTP. How can I find out how much real world time I am spending doing serialization activities in my application?\n" }, { "from": "gpt",...
This is a bit of a strange one, but I've been struggling for a few hours now and I can't understand what is happening. I was wondering if anyone else has experienced this problem, and can perhaps explain it. I'm building a simple Winforms app and trying to use many of the built in controls. Basically, I've got a form ...
It sounds like you're experiencing an issue related to how data binding is set up for your dropdowns in your WinForms application. The behavior you describe, where the dropdown holds focus and prevents navigation to other controls after making a selection, is often related to event handling and property binding in WinF...
34,905
[ { "from": "human", "value": "This is a bit of a strange one, but I've been struggling for a few hours now and I can't understand what is happening.\nI was wondering if anyone else has experienced this problem, and can perhaps explain it. I'm building a simple Winforms app and trying to use many of the built...
We have a high security application and we want to allow users to enter URLs that other users will see. This introduces a high risk of XSS hacks - a user could potentially enter javascript that another user ends up executing. Since we hold sensitive data it's essential that this never happens. What are the best practic...
In a high-security application, allowing users to enter URLs that other users will see can indeed pose significant risks, particularly concerning Cross-Site Scripting (XSS) attacks. Here are best practices and considerations for handling user-generated URLs safely: ### 1. Validate and Sanitize Input **Use a Whitelist...
28,053
[ { "from": "human", "value": "We have a high security application and we want to allow users to enter URLs that other users will see.\nThis introduces a high risk of XSS hacks - a user could potentially enter javascript that another user ends up executing. Since we hold sensitive data it's essential that thi...
I've been investigating the effort needed in getting menu items displayed in bold face - without having to draw the menu myself - and discovered MFS_DEFAULT menu item state after some googling. The MSDN documentation mentions MFS_DEFAULT Specifies that the menu item is the default. A menu can contain only one default ...
Using the `MFS_DEFAULT` flag to make multiple menu items bold can lead to unexpected behavior and potential issues in your application. As you noted, the official documentation states that only one item in a menu can be marked as the default, which is conventionally represented by a bold font. Here are some considerati...
37,768
[ { "from": "human", "value": "I've been investigating the effort needed in getting menu items displayed in bold face - without having to draw the menu myself - and discovered MFS_DEFAULT menu item state after some googling. The MSDN documentation mentions\n\nMFS_DEFAULT\nSpecifies that the menu\nitem is the ...
I am trying to audit the action that the user performed that resulted in changes to corresponding tables. For example if a user were to transfer money between 2 accounts this would generate the following sequence of events: Insert transfer amount into Transfer table Subtract transfer amount from balance in Balance Tab...
To achieve the audit logging requirements you described using Hibernate, it's important to handle the cascade operations properly and ensure that transient entities are managed correctly. Since you're facing issues with the cascade options and transient entities, let's break down the approach and find a solution. ### ...
32,930
[ { "from": "human", "value": "I am trying to audit the action that the user performed that resulted in changes to corresponding tables. For example if a user were to transfer money between 2 accounts this would generate the following sequence of events:\n\nInsert transfer amount into Transfer table\nSubtract...
PHP, for all its warts, is pretty good on this count. There's no difference between an array and a hash (maybe I'm naive, but this seems obviously right to me), and to iterate through either you just do foreach (array/hash as $key => $value) In Ruby there are a bunch of ways to do this sort of thing: array.length.time...
You raise an interesting point about the differences in how PHP and Ruby handle arrays and hashes. Let’s break down a few aspects of your observations: ### PHP Arrays vs. Ruby Arrays 1. **Unified Data Structure**: In PHP, arrays are a unified data structure that can function as both indexed arrays and associative arr...
37,095
[ { "from": "human", "value": "PHP, for all its warts, is pretty good on this count. There's no difference between an array and a hash (maybe I'm naive, but this seems obviously right to me), and to iterate through either you just do\nforeach (array/hash as $key => $value)\n\nIn Ruby there are a bunch of ways...
I'm a Lisp beginner. I'm trying to memoize a recursive function for calculating the number of terms in a Collatz sequence (for problem 14 in Project Euler). My code as of yet is: (defun collatz-steps (n) (if (= 1 n) 0 (if (evenp n) (1+ (collatz-steps (/ n 2))) (1+ (collatz-steps (1+ (* 3...
You're correct that the issue with your initial memoization approach is that the recursive calls within the `collatz-steps` function still reference the original, non-memoized version of the function. Your idea to modify the function to call the memoized version instead works, but as you've noticed, it changes the orig...
35,244
[ { "from": "human", "value": "I'm a Lisp beginner. I'm trying to memoize a recursive function for calculating the number of terms in a Collatz sequence (for problem 14 in Project Euler). My code as of yet is:\n(defun collatz-steps (n)\n (if (= 1 n) 0\n (if (evenp n) \n (1+ (collatz-steps (/ ...
I'm interested of inserting the firewall log which I'm printing to the stdout to a mysql database as well. How would I do that? the line output is: 16:51:56 drop Nova <eth0 Attack Info: MS Word cascading style sheet vulnerability detected (MS08-026); attack: Content Protection Violation; viola profile: Default_Pro...
To insert your firewall log data into a MySQL database while also printing it to stdout, you can use a combination of Bash (or Perl) and MySQL commands. Here's a step-by-step guide on how to do this: ### Prerequisites 1. **MySQL Server**: Ensure that you have MySQL server installed and running. 2. **Database and Table...
32,600
[ { "from": "human", "value": "I'm interested of inserting the firewall log which I'm printing to the stdout to a mysql database as well. How would I do that?\nthe line output is: \n16:51:56 drop Nova <eth0 Attack Info: MS Word cascading style sheet vulnerability detected (MS08-026); attack: Content Prote...
I'm using IStorage's Compound File Implementation from C# (StgCreateDocfile). Is it safe to access one IStorage / IStream instance from multiple threads, provided I synchronized the reads and writes myself? Or are there any COM issues that might be problematic here? For example, can I safely call EnumElements to get al...
Accessing `IStorage` and `IStream` instances from multiple threads in a COM context can be tricky. While you can synchronize your reads and writes, there are still some considerations to keep in mind regarding thread safety with COM objects, particularly with Microsoft's Compound File (also known as Structured Storage)...
33,745
[ { "from": "human", "value": "I'm using IStorage's Compound File Implementation from C# (StgCreateDocfile).\nIs it safe to access one IStorage / IStream instance from multiple threads, provided I synchronized the reads and writes myself? Or are there any COM issues that might be problematic here?\nFor exampl...
A div, containing a table has the following CSS styling: #formulaAlts { float: right; height: 200px; overflow: auto; } This makes it so that when the table is >200px, a scrollbar appears only for the table and the other elements on the page stay put. Great! Now for our friend IE... In IE, the element sp...
It sounds like you're facing a common issue with Internet Explorer's handling of the `overflow` property. When using `overflow: auto;`, IE can sometimes behave unexpectedly, particularly with regards to the scrollbars and their effect on layout. Here are a few suggestions to address the issue: ### 1. Use a Fixed Width...
34,343
[ { "from": "human", "value": "A div, containing a table has the following CSS styling:\n#formulaAlts {\n float: right; \n height: 200px;\n overflow: auto;\n}\n\nThis makes it so that when the table is >200px, a scrollbar appears only for the table and the other elements on the page stay put. Great...
I'm setting up a new server and want to support UTF-8 fully in my web application. I have tried this in the past on existing servers and always seem to end up having to fall back to ISO-8859-1. Where exactly do I need to set the encoding/charsets? I'm aware that I need to configure Apache, MySQL, and PHP to do this — ...
Setting up a web application to fully support UTF-8 can indeed be tricky if there are mismatches in configuration across various components. Here's a checklist that you can follow to ensure that your Apache, MySQL, and PHP configurations are properly set up for UTF-8 support. ### 1. Apache Configuration First, you ne...
34,463
[ { "from": "human", "value": "\nI'm setting up a new server and want to support UTF-8 fully in my web application. I have tried this in the past on existing servers and always seem to end up having to fall back to ISO-8859-1.\nWhere exactly do I need to set the encoding/charsets? I'm aware that I need to con...
Does SQLAlchemy support some kind of caching so if I repeatedly run the same query it returns the response from cache instead of querying the database? Is this cache automatically cleared when the DB is updated? Or what's the best way to implement this on a CherryPy + SQLAlchemy setup?
SQLAlchemy itself does not have built-in caching mechanisms for query results. However, you can implement caching on top of SQLAlchemy using other libraries or techniques. Here are some common approaches you can consider: ### 1. **Using External Caching Libraries** You can use an external caching library such as: - ...
33,533
[ { "from": "human", "value": "Does SQLAlchemy support some kind of caching so if I repeatedly run the same query it returns the response from cache instead of querying the database? Is this cache automatically cleared when the DB is updated?\nOr what's the best way to implement this on a CherryPy + SQLAlchem...
I want to use Excel to capture survey results. I want to have a large number of questions each with 5 radio buttons ranging from Excellent to Poor. Each radio button should correspond to a numerical value stored in a set of data cells somewhere (e.g Excellent = 13, Poor = 10, Good = 5 etc). I would like to be able to c...
To capture survey results in Excel using radio buttons, you'll follow a few steps. Radio buttons in Excel are typically created using the Forms or ActiveX controls. For your use case of having multiple questions with corresponding radio buttons that represent numerical values, you'll want to set it up in a way that all...
31,314
[ { "from": "human", "value": "I want to use Excel to capture survey results. I want to have a large number of questions each with 5 radio buttons ranging from Excellent to Poor. Each radio button should correspond to a numerical value stored in a set of data cells somewhere (e.g Excellent = 13, Poor = 10, Go...
I am wondering what to include when building my project. I have a library I need to reference for my project to build but that library has 10 dependencies itself. Should I reference those dependencies as well or should I copy them to the output directory using a post build event? What is the best practice? I find it co...
When building a project in Visual Studio that relies on an external library, managing dependencies is crucial for both organization and functionality. Here are some insights to guide you through the best practices: ### 1. **Understand Dependency Types** - **Compile-time Dependencies:** These are required during the co...
33,597
[ { "from": "human", "value": "I am wondering what to include when building my project. I have a library I need to reference for my project to build but that library has 10 dependencies itself. Should I reference those dependencies as well or should I copy them to the output directory using a post build event...
Can anyone tell me what the need/advantage is to using a web service with an asp.net gui and using Linq to SQL? The web service layer seems unnecessary. Linq to SQL is completely new to me and I am researching as I am setting up a new project. Does anyone have any experience with this?
Using a web service in conjunction with an ASP.NET GUI and LINQ to SQL can provide several benefits, depending on your project requirements. Here are some of the advantages of using this architecture: ### 1. **Separation of Concerns:** - **Modularity:** By separating the UI (ASP.NET GUI) from the data access layer ...
33,264
[ { "from": "human", "value": "Can anyone tell me what the need/advantage is to using a web service with an asp.net gui and using Linq to SQL? The web service layer seems unnecessary. Linq to SQL is completely new to me and I am researching as I am setting up a new project. Does anyone have any experience wit...
Ok, i've read most relevant questions asked here previously on this but I still don't see a clear "best in class" suggestion for WYSIWYG editors for ASP.net I've used fckeditor up to now (found it ok but many problems with config/permissions on folder etc.). I'm looking for something that has a lot of flexibility/conf...
There are several WYSIWYG editors that are popular among ASP.NET developers and can meet your requirements for flexibility, configuration options, and smooth integration with CSS. Here are some of the top contenders: 1. **TinyMCE**: - **Overview**: A widely used WYSIWYG editor that is highly customizable. - **Fl...
35,499
[ { "from": "human", "value": "Ok, \ni've read most relevant questions asked here previously on this but I still don't see a clear \"best in class\" suggestion for WYSIWYG editors for ASP.net\nI've used fckeditor up to now (found it ok but many problems with config/permissions on folder etc.).\nI'm looking fo...
For my personal stuff I just use the svnadmin hotcopy command once a week but for more mission critical repositories that include many developers, is that enough? Or should I spend the time to put together a more rigorous backup strategy that includes full backups and incremental backups? hotcopy seems like the easiest...
The `svnadmin hotcopy` command is a useful way to create a full backup of a Subversion repository, including all versioned files, metadata, and properties. However, there are several considerations to take into account when evaluating whether this method is sufficient for mission-critical repositories: ### Advantages ...
35,999
[ { "from": "human", "value": "For my personal stuff I just use the svnadmin hotcopy command once a week but for more mission critical repositories that include many developers, is that enough? Or should I spend the time to put together a more rigorous backup strategy that includes full backups and incrementa...
I got the following class : class ConstraintFailureSet(dict, Exception) : """ Container for constraint failures. It act as a constraint failure itself but can contain other constraint failures that can be accessed with a dict syntax. """ def __init__(self, **failures) : dict.__init_...
The issue you're encountering stems from the way Python handles exception classes. In Python, exceptions are usually classes derived from the `BaseException` class (or its subclass `Exception`). When raising an exception, the interpreter expects the exception to be an instance of a class that directly inherits from `Ba...
35,886
[ { "from": "human", "value": "I got the following class :\nclass ConstraintFailureSet(dict, Exception) :\n \"\"\"\n Container for constraint failures. It act as a constraint failure itself\n but can contain other constraint failures that can be accessed with a dict syntax.\n \"\"\"\n\n ...
This question isn't about unit-testing. And it is for a desktop product. This is about testing of the gui and testing that the right stuff is input in the right text box at the right time. A company I used to work at used WinRunner (different department so I don't know much more that that), but that has now been shutdo...
Automated GUI testing tools can significantly enhance the testing process for desktop applications, especially those built with MFC (Microsoft Foundation Class). Here are some popular tools that meet many of your criteria: 1. **SikuliX**: - **Automation**: Yes, it supports automated GUI testing. - **Scriptable**...
33,897
[ { "from": "human", "value": "This question isn't about unit-testing. And it is for a desktop product.\nThis is about testing of the gui and testing that the right stuff is input in the right text box at the right time.\nA company I used to work at used WinRunner (different department so I don't know much mo...
I am trying to access my WCF service on a server from my client console application for testing. I am getting the following error: The caller was not authenticated by the service I am using wsHttpBinding. I'm not sure what kind of authentication the service is expecting? <behaviors> <serviceBehaviors> ...
The error "The caller was not authenticated by the service" typically indicates that there is an issue with how security is configured for your WCF service when using `wsHttpBinding`. When you switched to `basicHttpBinding`, the authentication worked because it has a different set of security settings and is generally ...
35,503
[ { "from": "human", "value": "I am trying to access my WCF service on a server from my client console application for testing. I am getting the following error: \n\nThe caller was not authenticated by\n the service\n\nI am using wsHttpBinding. I'm not sure what kind of authentication the service is expect...
I got myself a new 8 gig USB key and I'm looking for a decent solution to have a portable RoR environment to learn on. I did the google on it and found a few possibilities, but I'm curious to hear some real life experiences and opinions. Thanks!
Setting up a portable Ruby on Rails (RoR) environment on an 8 GB USB key can be a fun and educational project! Here are some options and tips based on real-life experiences: ### 1. **Use a Virtual Machine on USB** You can run a lightweight Linux distribution (like Ubuntu or a minimal version of Debian) from the USB d...
34,040
[ { "from": "human", "value": "I got myself a new 8 gig USB key and I'm looking for a decent solution to have a portable RoR environment to learn on. I did the google on it and found a few possibilities, but I'm curious to hear some real life experiences and opinions. Thanks!\n" }, { "from": "gpt", ...
When looking at C# code, I often see patterns like this: DataType[] items = GetSomeItems(); OtherDataType[] itemProps = new OtherDataType[items.Length]; int i = 0; foreach (DataType item in items) { // Do some stuff with item, then finally itemProps[i] = item.Prop; i++; } The for-loop iterates over the ob...
Both the `foreach` loop and the traditional `for` loop have their uses and can be employed effectively depending on the context and specific requirements. The two approaches you've described each have their benefits and potential drawbacks. Here's a detailed analysis of both: ### The `foreach` Approach ```csharp Data...
35,146
[ { "from": "human", "value": "When looking at C# code, I often see patterns like this:\nDataType[] items = GetSomeItems();\nOtherDataType[] itemProps = new OtherDataType[items.Length];\n\nint i = 0;\nforeach (DataType item in items)\n{\n // Do some stuff with item, then finally\n itemProps[i] = item.Pr...
I'm working on an ASP.Net application and working to add some Ajax to it to speed up certain areas. The first area that I am concentrating is the attendance area for the teachers to report attendance (and some other data) about the kids. This needs to be fast. I've created a dual-control set up where the user clicks on...
It's great that you're working to optimize the performance of your ASP.NET application, particularly in the attendance reporting area. Here are a few strategies to address the issues you're encountering with `__doPostBack()` and the UpdatePanel, especially in Internet Explorer. ### Understanding the Delay 1. **IE Per...
29,560
[ { "from": "human", "value": "I'm working on an ASP.Net application and working to add some Ajax to it to speed up certain areas. The first area that I am concentrating is the attendance area for the teachers to report attendance (and some other data) about the kids. This needs to be fast.\nI've created a du...
I'm trying to write a wstring to file with ofstream in binary mode, but I think I'm doing something wrong. This is what I've tried: ofstream outFile("test.txt", std::ios::out | std::ios::binary); wstring hello = L"hello"; outFile.write((char *) hello.c_str(), hello.length() * sizeof(wchar_t)); outFile.close(); Opening...
The issue you're encountering is due to how wide characters (`wchar_t`) are represented and how they should be written to a file in UTF-16 encoding. When you write a `std::wstring` containing wide characters to a file in binary mode, you need to ensure you're also correctly encoding those characters as UTF-16, which i...
33,293
[ { "from": "human", "value": "I'm trying to write a wstring to file with ofstream in binary mode, but I think I'm doing something wrong. This is what I've tried:\nofstream outFile(\"test.txt\", std::ios::out | std::ios::binary);\nwstring hello = L\"hello\";\noutFile.write((char *) hello.c_str(), hello.length...
In PHP, I can write: $vname = 'phone'; $$vname = '555-1234'; print $phone; ... And the script will output "555-1234". Is there any equivalent in Perl? Is there any way to constrain $phone to the scope of the local block, as if I'd written my $phone? Using my $$vname gives me "Can't declare scalar dereference in my at ...
In Perl, you can achieve a similar effect using hashes instead of symbolic references, which are not generally recommended due to their potential for confusion and difficulty in maintaining code. However, if you're looking for an equivalent to the PHP example you provided, you can use the `eval` function, but this appr...
38,171
[ { "from": "human", "value": "In PHP, I can write:\n$vname = 'phone';\n$$vname = '555-1234';\nprint $phone;\n\n... And the script will output \"555-1234\".\nIs there any equivalent in Perl?\nIs there any way to constrain $phone to the scope of the local block, as if I'd written my $phone? Using my $$vname gi...
I need to test a url that it does not end with .asp So test, test.html and test.aspx should match, but test.asp should not match. Normally you'd test if the url does end with .asp and negate the fact that it matched using the NOT operator in code: if(!regex.IsMatch(url)) { // Do something } In that case the regular ex...
To achieve your requirement using a regular expression that matches all URLs except those ending with `.asp`, you can use a negative lookbehind assertion in your regex pattern. In this case, you'll want a pattern that effectively says "match any string except those that end with `.asp`." Here's the regex pattern that ...
38,566
[ { "from": "human", "value": "I need to test a url that it does not end with .asp\nSo test, test.html and test.aspx should match, but test.asp should not match.\nNormally you'd test if the url does end with .asp and negate the fact that it matched using the NOT operator in code:\nif(!regex.IsMatch(url)) { //...
I have written this generator code but it returns 'can't convert nil into String' when I call m.directory inside the manifest. Anyone know what had happened? class AuthGenerator < Rails::Generator::NamedBase attr_reader :user_class_name def initialize(runtime_args, runtime_options={}) @user_class_name="User" ...
The error message you're encountering, `can't convert nil into String`, indicates that you're trying to use `nil` in a context where a string is expected. In your code, the issue is likely stemming from the fact that you are trying to use the `@user_class_name` variable in a string manipulation without it being properl...
35,587
[ { "from": "human", "value": "I have written this generator code but it returns 'can't convert nil into String' when I call m.directory inside the manifest. Anyone know what had happened?\nclass AuthGenerator < Rails::Generator::NamedBase\n attr_reader :user_class_name\n def initialize(runtime_args, runtim...
I'm looking for a good lightweight Java docking framework. I know that Netbeans and Eclipse can be used as RCP, but I'm looking for something a little bit more lightweight.
If you're looking for a lightweight Java docking framework, there are several options that might suit your needs better than the full-featured RCP solutions like NetBeans and Eclipse. Here are a few recommendations: 1. **JideDock**: - JideDock is part of the Jide Software library and offers a lightweight docking fr...
36,247
[ { "from": "human", "value": "I'm looking for a good lightweight Java docking framework.\nI know that Netbeans and Eclipse can be used as RCP, but I'm looking for something a little bit more lightweight.\n" }, { "from": "gpt", "value": "If you're looking for a lightweight Java docking framework, ...
How do I retrieve an item at random from the following list? foo = ['a', 'b', 'c', 'd', 'e']
You can retrieve an item at random from the list using the `random` module in Python. Here's how you can do it: ```python import random foo = ['a', 'b', 'c', 'd', 'e'] random_item = random.choice(foo) print(random_item) ``` In this code: - We first import the `random` module. - Then, we define the list `foo`. - We ...
38,805
[ { "from": "human", "value": "How do I retrieve an item at random from the following list?\nfoo = ['a', 'b', 'c', 'd', 'e']\n\n" }, { "from": "gpt", "value": "You can retrieve an item at random from the list using the `random` module in Python. Here's how you can do it:\n\n```python\nimport rando...
Do you know a simple script to count NLOCs (netto lines of code). The script should count lines of C Code. It should not count empty lines or lines with just braces. But it doesn't need to be overly exact either.
Certainly! Below is a simple Python script that counts Netto Lines of Code (NLOC) for C code by ignoring empty lines and lines that contain only braces. ```python import os def is_valid_line(line): stripped_line = line.strip() return stripped_line and not (stripped_line == "{" or stripped_line == "}") def c...
38,106
[ { "from": "human", "value": "Do you know a simple script to count NLOCs (netto lines of code). The script should count lines of C Code. It should not count empty lines or lines with just braces. But it doesn't need to be overly exact either.\n" }, { "from": "gpt", "value": "Certainly! Below is a...
Imagine I have the following: inFile = "/adda/adas/sdas/hello.txt" # that instruction give me hello.txt Name = inFile.name.split("/") [-1] # that one give me the name I want - just hello Name1 = Name.split(".") [0] Is there any chance to simplify that doing the same job in just one expression?
Yes, you can simplify the extraction of just the filename (without the extension) from a file path using Python's `pathlib` module, which provides an elegant way to handle file paths. Here’s how you can achieve that in one line: ```python from pathlib import Path inFile = "/adda/adas/sdas/hello.txt" Name1 = Path(inFi...
38,989
[ { "from": "human", "value": "Imagine I have the following:\ninFile = \"/adda/adas/sdas/hello.txt\"\n\n# that instruction give me hello.txt\nName = inFile.name.split(\"/\") [-1]\n\n# that one give me the name I want - just hello\nName1 = Name.split(\".\") [0]\n\nIs there any chance to simplify that doing the...