Helpful Posts For Developers

Some Of The Best Answers From Latest Asked Questions

50

answers

Should a function have only one return statement?

Are there good reasons why it's a better practice to have only one return statement in a function? Or is it okay to return from a function as soon as it is logically correct to do so, meaning there ..

20

answers

Struct like objects in Java

Is it completely against the Java way to create struct like objects? class SomeData1 { public int x; public int y; } I can see a class with accessors and mutators being more Java like. cla..

24

answers

What is a 'Closure'?

I asked a question about Currying and closures were mentioned. What is a closure? How does it relate to currying?..

48

answers

Why functional languages?

I see a lot of talk on here about functional languages and stuff. Why would you use one over a "traditional" language? What do they do better? What are they worse at? What's the ideal functional p..

15

answers

Why doesn't JavaScript support multithreading?

Is it a deliberate design decision or a problem with our current day browsers which will be rectified in the coming versions?..

22

answers

Embed a PowerPoint presentation into HTML

Is it possible to embed a PowerPoint presentation (.ppt) into a webpage (.xhtml)? This will be used on a local intranet where there is a mix of Internet Explorer 6 and Internet Explore..

22

answers

Is a GUID unique 100% of the time?

Is a GUID unique 100% of the time? Will it stay unique over multiple threads?..

7

answers

How to loop through files matching wildcard in batch file

I have a set of base filenames, for each name 'f' there are exactly two files, 'f.in' and 'f.out'. I want to write a batch file (in Windows XP) which goes through all the filenames, for each one it s..

9

answers

Best way to do multi-row insert in Oracle?

I'm looking for a good way to perform multi-row inserts into an Oracle 9 database. The following works in MySQL but doesn't seem to be supported in Oracle. INSERT INTO TMP_DIM_EXCH_RT (EXCH_WH_KEY,..

11

answers

What is the best way to convert an array to a hash in Ruby

In Ruby, given an array in one of the following forms... [apple, 1, banana, 2] [[apple, 1], [banana, 2]] ...what is the best way to convert this into a hash in the form of... {apple => 1, banan..

17

answers

What is the yield keyword used for in C#?

In the How Can I Expose Only a Fragment of IList<> question one of the answers had the following code snippet: IEnumerable<object> FilteredList() { foreach(object item in FullList) {..

3

answers

How large is a DWORD with 32- and 64-bit code?

In Visual C++ a DWORD is just an unsigned long that is machine, platform, and SDK dependent. However, since DWORD is a double word (that is 2 * 16), is a DWORD still 32-bit on 64-bit architectures?..

9

answers

How do I install a color theme for IntelliJ IDEA 7.0.x

I prefer dark backgrounds for coding, and I've downloaded a jar file containing an IntelliJ IDEA color theme that has a dark background. How do I tell IntelliJ about it?..

13

answers

Search and replace a line in a file in Python

I want to loop over the contents of a text file and do a search and replace on some lines and write the result back to the file. I could first load the whole file in memory and then write it back, but..

48

answers

How do I merge two dictionaries in a single expression (taking union of dictionaries)?

I have two Python dictionaries, and I want to write a single expression that returns these two dictionaries, merged (i.e. taking the union). The update() method would be what I need, if it returned i..

5

answers

How to find out if a file exists in C# / .NET?

I would like to test a string containing a path to a file for existence of that file (something like the -e test in Perl or the os.path.exists() in Python) in C#...

9

answers

What static analysis tools are available for C#?

What tools are there available for static analysis against C# code? I know about FxCop and StyleCop. Are there others? I've run across NStatic before but it's been in development for what seems like f..

16

answers

Using Django time/date widgets in custom form

How can I use the nifty JavaScript date and time widgets that the default admin uses with my custom view? I have looked through the Django forms documentation, and it briefly mentions django.contrib...

7

answers

What is the argument for printf that formats a long?

The printf function takes an argument type, such as %d or %i for a signed int. However, I don't see anything for a long value...

27

answers

What is the difference between "INNER JOIN" and "OUTER JOIN"?

Also how do LEFT JOIN, RIGHT JOIN and FULL JOIN fit in?..

18

answers

What is the purpose of class methods?

I'm teaching myself Python and my most recent lesson was that Python is not Java, and so I've just spent a while turning all my Class methods into functions. I now realise that I don't need to use Cl..

33

answers

How can I get the DateTime for the start of the week?

How do I find the start of the week (both Sunday and Monday) knowing just the current time in C#? Something like: DateTime.Now.StartWeek(Monday); ..

12

answers

How do I find the authoritative name-server for a domain name?

How can I find the origins of conflicting DNS records?..

15

answers

Sorting an IList in C#

So I came across an interesting problem today. We have a WCF web service that returns an IList. Not really a big deal until I wanted to sort it. Turns out the IList interface doesn't have a sort meth..

10

answers

How to change the icon of .bat file programmatically?

I'd like to know what's the way to actually set the icon of a .bat file to an arbitrary icon. How would I go about doing that programmatically, independently of the language I may be using...

50

answers

What's the best UML diagramming tool?

I'm trying to choose a tool for creating UML diagrams of all flavours. Usability is a major criteria for me, but I'd still take more power with a steeper learning curve and be happy. Free (as in beer)..

16

answers

How to retrieve a file from a server via SFTP?

I'm trying to retrieve a file from a server using SFTP (as opposed to FTPS) using Java. How can I do this?..

22

answers

LINQ-to-SQL vs stored procedures?

I took a look at the "Beginner's Guide to LINQ" post here on StackOverflow (Beginners Guide to LINQ), but had a follow-up question: We're about to ramp up a new project where nearly all of our databa..

10

answers

fopen deprecated warning

On Visual Studio 2005 C++ compiler, I get the following warning when my code uses the fopen and such calls. 1>foo.cpp(5) : warning C4996: 'fopen' was declared deprecated 1> c:\program fi..

9

answers

How can I remove a child node in HTML using JavaScript?

Is there a function like document.getElementById("FirstDiv").clear()?..

21

answers

How can I permanently enable line numbers in IntelliJ?

How can I permanently enable line numbers in IntelliJ IDEA?..

19

answers

Warning: Found conflicts between different versions of the same dependent assembly

I am currently developing a .NET application, which consists of 20 projects. Some of those projects are compiled using .NET 3.5, some others are still .NET 2.0 projects (so far no problem). The probl..

30

answers

When should you use 'friend' in C++?

I have been reading through the C++ FAQ and was curious about the friend declaration. I personally have never used it, however I am interested in exploring the language. What is a good example of us..

26

answers

How do I send a file as an email attachment using Linux command line?

I've created a script that runs every night on my Linux server that uses mysqldump to back up each of my MySQL databases to .sql files and packages them together as a compressed .tar file. The next s..

32

answers

What is the most effective way for float and double comparison?

What would be the most efficient way to compare two double or two float values? Simply doing this is not correct: bool CompareDoubles1 (double A, double B) { return A == B; } But something like..

12

answers

When to use IList and when to use List

I know that IList is the interface and List is the concrete type but I still don't know when to use each one. What I'm doing now is if I don't need the Sort or FindAll methods I use the interface. Am ..

19

answers

How to generate sample XML documents from their DTD or XSD?

We are developing an application that involves a substantial amount of XML transformations. We do not have any proper input test data per se, only DTD or XSD files. We'd like to generate our test data..

25

answers

What Ruby IDE do you prefer?

I've been using Eclipse with RDT (not RadRails) a lot lately, and I'm quite happy with it, but I'm wondering if you guys know any decent alternatives. I know NetBeans also supports Ruby these days, bu..

33

answers

How to select the nth row in a SQL database table?

I'm interested in learning some (ideally) database agnostic ways of selecting the nth row from a database table. It would also be interesting to see how this can be achieved using the native functiona..

23

answers

What is a lambda (function)?

For a person without a comp-sci background, what is a lambda in the world of Computer Science?..

24

answers

Parse usable Street Address, City, State, Zip from a string

Problem: I have an address field from an Access database which has been converted to SQL Server 2005. This field has everything all in one field. I need to parse out the address's individual sections ..

7

answers

How to redirect siteA to siteB with A or CNAME records

I have 2 hosts and I would like to point a subdomain on host one to a subdomain on host two: subdomain.hostone.com --> subdomain.hosttwo.com I added a CNAME record to host one that points to sub..

16

answers

What do "branch", "tag" and "trunk" mean in Subversion repositories?

I've seen these words a lot around Subversion (and I guess general repository) discussions. I have been using SVN for my projects for the last few years, but I've never grasped the complete concept of..

25

answers

Convert a string to an enum in C#

What's the best way to convert a string to an enumeration value in C#? I have an HTML select tag containing the values of an enumeration. When the page is posted, I want to pick up the value (which wi..

10

answers

How do I convert a file path to a URL in ASP.NET

Basically I have some code to check a specific directory to see if an image is there and if so I want to assign a URL to the image to an ImageControl. if (System.IO.Directory.Exists(photosLocation)) ..

32

answers

Reading Excel files from C#

Is there a free or open source library to read Excel files (.xls) directly from a C# program? It does not need to be too fancy, just to select a worksheet and read the data as strings. So far, I've ..

15

answers

Changing the resolution of a VNC session in linux

I use VNC to connect to a Linux workstation at work. At work I have a 20" monitor that runs at 1600x1200, while at home I use my laptop with its resolution of 1440x900. If I set the vncserver to run ..

13

answers

What's the best way to validate an XML file against an XSD file?

I'm generating some xml files that needs to conform to an xsd file that was given to me. What's the best way to verify they conform?..

10

answers

How can I determine whether a specific file is open in Windows?

One of my favourite tools for linux is lsof - a real swiss army knife! Today I found myself wondering which programs on a WinXP system had a specific file open. Is there any equivalent utility to lso..

100

answers

Hidden Features of Java

After reading Hidden Features of C# I wondered, What are some of the hidden features of Java?..

6

answers

How do I use 3DES encryption/decryption in Java?

Every method I write to encode a string in Java using 3DES can't be decrypted back to the original string. Does anyone have a simple code snippet that can just encode and then decode the string back ..

4

answers

Where can I find decent visio templates/diagrams for software architecture?

Anyone have any good urls for templates or diagram examples in Visio 2007 to be used in software architecture?..

25

answers

MyISAM versus InnoDB

I'm working on a projects which involves a lot of database writes, I'd say (70% inserts and 30% reads). This ratio would also include updates which I consider to be one read and one write. The reads..

9

answers

Is there a way to make Firefox ignore invalid ssl-certificates?

I am maintaining a few web applications. The development and qa environments use invalid/outdated ssl-certificates. Although it is generally a good thing, that Firefox makes me click like a dozen tim..

15

answers

What's the best way to parse command line arguments?

What's the easiest, tersest, and most flexible method or library for parsing Python command line arguments?..

12

answers

How do you embed binary data in XML?

I have two applications written in Java that communicate with each other using XML messages over the network. I'm using a SAX parser at the receiving end to get the data back out of the messages. On..

30

answers

How to request a random row in SQL?

How can I request a random row (or as close to truly random as is possible) in pure SQL?..

12

answers

Transpose/Unzip Function (inverse of zip)?

I have a list of 2-item tuples and I'd like to convert them to 2 lists where the first contains the first item in each tuple and the second list holds the second item. For example: original = [('a',..

10

answers

Build a basic Python iterator

How would one create an iterative function (or iterator object) in python?..

37

answers

What is the correct way to create a single-instance WPF application?

Using C# and WPF under .NET (rather than Windows Forms or console), what is the correct way to create an application that can only be run as a single instance? I know it has something to do with some..

38

answers

How can I remove duplicate rows?

What is the best way to remove duplicate rows from a fairly large SQL Server table (i.e. 300,000+ rows)? The rows, of course, will not be perfect duplicates because of the existence of the RowID iden..

9

answers

How to find keys of a hash?

I know in javascript Objects double as hashes but i have been unable to find a built in function to get the keys var h = {a:'b',c:'d'}; I want something like var k = h.keys() ; // k = ['a','c'];..

11

answers

Random integer in VB.NET

I need to generate a random integer between 1 and n (where n is a positive whole number) to use for a unit test. I don't need something overly complicated to ensure true randomness - just an old-fashi..

17

answers

Quick easy way to migrate SQLite3 to MySQL?

Anyone know a quick easy way to migrate a SQLite3 database to MySQL?..

3

answers

How do you configure tomcat to bind to a single ip address (localhost) instead of all addresses?

How do you configure tomcat to bind to a single ip address (localhost) instead of all addresses?..

22

answers

Converting List<Integer> to List<String>

I have a list of integers, List<Integer> and I'd like to convert all the integer objects into Strings, thus finishing up with a new List<String>. Naturally, I could create a new List<S..

7

answers

What are some good SSH Servers for windows?

Trying to setup an SSH server on Windows Server 2003. What are some good ones? Preferably open source. I plan on using WinSCP as a client so a server which supports the advanced features implemented b..

49

answers

Validate decimal numbers in JavaScript - IsNumeric()

What's the cleanest, most effective way to validate decimal numbers in JavaScript? Bonus points for: Clarity. Solution should be clean and simple. Cross-platform. Test cases: 01. IsNumeric('-1')..

12

answers

How to generate a core dump in Linux on a segmentation fault?

I have a process in Linux that's getting a segmentation fault. How can I tell it to generate a core dump when it fails?..

16

answers

How to round up the result of integer division?

I'm thinking in particular of how to display pagination controls, when using a language such as C# or Java. If I have x items which I want to display in chunks of y per page, how many pages will be n..

7

answers

How do I perform a Perl substitution on a string while keeping the original?

In Perl, what is a good way to perform a replacement on a string using a regular expression and store the value in a different variable, without changing the original? I usually just copy the string ..

11

answers

How to decode viewstate

I need to see the contents of the viewstate of an asp.net page. I looked for a viewstate decoder, found Fridz Onion's ViewState Decoder but it asks for the url of a page to get its viewstate. Since my..

14

answers

What's the best mock framework for Java?

What's the best framework for creating mock objects in Java? Why? What are the pros and cons of each framework?..

25

answers

How to download a file over HTTP?

I have a small utility that I use to download an MP3 file from a website on a schedule and then builds/updates a podcast XML file which I've added to iTunes. The text processing that creates/updates ..

11

answers

Best practices for catching and re-throwing .NET exceptions

What are the best practices to consider when catching exceptions and re-throwing them? I want to make sure that the Exception object's InnerException and stack trace are preserved. Is there a differen..

9

answers

Format numbers to strings in Python

I need to find out how to format numbers as strings. My code is here: return str(hours)+":"+str(minutes)+":"+str(seconds)+" "+ampm Hours and minutes are integers, and seconds is a float. the str()..

40

answers

How can I develop for iPhone using a Windows development machine?

Is there any way to tinker with the iPhone SDK on a Windows machine? Are there plans for an iPhone SDK version for Windows? The only other way I can think of doing this is to run a Mac VM image on a ..

9

answers

Cleanest Way to Invoke Cross-Thread Events

I find that the .NET event model is such that I'll often be raising an event on one thread and listening for it on another thread. I was wondering what the cleanest way to marshal an event from a bac..

14

answers

Why can't I declare static methods in an interface?

The topic says the most of it - what is the reason for the fact that static methods can't be declared in an interface? public interface ITest { public static String test(); } The code above giv..

7

answers

Reading from text file until EOF repeats last line

The following C++ code uses a ifstream object to read integers from a text file (which has one number per line) until it hits EOF. Why does it read the integer on the last line twice? How to fix this?..

7

answers

.NET - Get protocol, host, and port

Is there a simple way in .NET to quickly get the current protocol, host, and port? For example, if I'm on the following URL: http://www.mywebsite.com:80/pages/page1.aspx I need to return: http://ww..

30

answers

What is the difference between #include <filename> and #include "filename"?

In the C and C++ programming languages, what is the difference between using angle brackets and using quotes in an include statement, as follows? #include <filename> #include "filename" ..

11

answers

In C++, what is a virtual base class?

I want to know what a "virtual base class" is and what it means. Let me show an example: class Foo { public: void DoSomething() { /* ... */ } }; class Bar : public virtual Foo { public: voi..

16

answers

In SQL Server, how do I generate a CREATE TABLE statement for a given table?

I've spent a good amount of time coming up with solution to this problem, so in the spirit of this post, I'm posting it here, since I think it might be useful to others. If anyone has a better scrip..

28

answers

Dynamically load a JavaScript file

How can you reliably and dynamically load a JavaScript file? This will can be used to implement a module or component that when 'initialized' the component will dynamically load all needed JavaScript..

12

answers

Which .NET Dependency Injection frameworks are worth looking into?

Which C#/.NET Dependency Injection frameworks are worth looking into? And what can you say about their complexity and speed...

13

answers

Simplest way to profile a PHP script

What's the easiest way to profile a PHP script? I'd love tacking something on that shows me a dump of all function calls and how long they took but I'm also OK with putting something around specific ..

17

answers

Most efficient way to concatenate strings?

What's the most efficient way to concatenate strings?..

13

answers

List of standard lengths for database fields

I'm designing a database table and once again asking myself the same stupid question: How long should the firstname field be? Does anyone have a list of reasonable lengths for the most common fields,..

6

answers

Recommended SQL database design for tags or tagging

I've heard of a few ways to implement tagging; using a mapping table between TagID and ItemID (makes sense to me, but does it scale?), adding a fixed number of possible TagID columns to ItemID (seems ..

8

answers

How do you clear a stringstream variable?

I've tried several things already, std::stringstream m; m.empty(); m.clear(); both of which don't work...

6

answers

Image UriSource and Data Binding

I'm trying to bind a list of custom objects to a WPF Image like this: <Image> <Image.Source> <BitmapImage UriSource="{Binding Path=ImagePath}" /> </Image.Source&g..

39

answers

List of macOS text editors and code editors

I searched for this and found Maudite's question about text editors but they were all for Windows. As you have no doubt guessed, I am trying to find out if there are any text/code editors for the Mac..

13

answers

100% Min Height CSS layout

What's the best way to make an element of 100% minimum height across a wide range of browsers ? In particular if you have a layout with a header and footer of fixed height, how do you make the..

21

answers

Difference between EXISTS and IN in SQL?

What is the difference between the EXISTS and IN clause in SQL? When should we use EXISTS, and when should we use IN?..

14

answers

Is there a performance difference between i++ and ++i in C?

Is there a performance difference between i++ and ++i if the resulting value is not used?..

11

answers

How do I fix "for loop initial declaration used outside C99 mode" GCC error?

I'm trying to solve the 3n+1 problem and I have a for loop that looks like this: for(int i = low; i <= high; ++i) { res = runalg(i); if (res > highestre..

21

answers

C: What is the difference between ++i and i++?

In C, what is the difference between using ++i and i++, and which should be used in the incrementation block of a for loop?..

15

answers

Execute script after specific delay using JavaScript

Is there any JavaScript method similar to the jQuery delay() or wait() (to delay the execution of a script for a specific amount of time)?..

26

answers

Escaping HTML strings with jQuery

Does anyone know of an easy way to escape HTML from strings in jQuery? I need to be able to pass an arbitrary string and have it properly escaped for display in an HTML page (preventing JavaScript/HT..