elegant

How does the SQL Server JDBC Trusted Connection Authentication work?

How does the SQL Server JDBC Trusted Connection Authentication work? (ie how does the trusted connection authenticate the logged in AD user in such a transparent and elegant fashion and how can I implement a similar authentication solution for my client-server applications in Java without a database connection or any use of the existing ...

What is the most elegant way of bubble-sorting in F#?

What is the most elegant way of bubble-sorting in F#? UPDATE As pointed out in one of the answers, bubble sorting isn't efficient in a functional language to begin with. A humourously-cynical commenter also pointed out that bubble sorting is only appropriate when the list is small and it's almost sorted anyway. However, I'm curious t...

Math factors game - who can write the most elegant solution?

Here's a fun exercise. http://www.hughchou.org/hugh/grid_game.cgi?CLEAR Who can write the most elegant yet performant code to win this game? My solution is in C/C++. #include<vector> #include<iostream> #include<fstream> #define N 64 std::vector<int> numbers(N+1); void init() { for(int i = 0; i < N+1; ++i) numbers[i] = 1; ...

using Java to get a file's md5 checksum?

I am looking to use java to get the md5 checksum of a file. I was really surprised but I haven't been able to find anything that shows how (and the best way) to get the md5 checksum of a file. Any ideas on how to go forward? Thanks. ...

Is returning early from a function more elegant than an if statement?

Myself and a colleague have a dispute about which of the following is more elegant. I won't say who's who, so it is impartial. Which is more elegant? public function set hitZone(target:DisplayObject):void { if(_hitZone != target) { _hitZone.removeEventListener(MouseEvent.ROLL_OVER, onBtOve...

How to elegantly compute the anagram signature of a word in ruby?

Arising out of this question, I'm looking for an elegant (ruby) way to compute the word signature suggested in this answer. The idea suggested is to sort the letters in the word, and also run length encode repeated letters. So, for example "mississippi" first becomes "iiiimppssss", and then could be further shortened by encoding as "4im...

When is the right time and the wrong time to do the quick and dirty solution?

When is it the right time and when is it the wrong time to take the quick and dirty approach versus the proper elegant solution? This started from the comments on my question: http://stackoverflow.com/questions/469695/decode-base64-data-in-java. I wanted a way to do something using only internal Java or something I wrote. The only bui...

What's the fuss about Haskell?

I know a few programmers who keep talking about Haskell when they are among themselves, and here on SO everyone seems to love that language. Being good at Haskell seems somewhat like the hallmark of a genius programmer. Can someone give a few Haskell examples that show why it is so elegant / superior? ...

Generic Authentication Call to Active Directory in C#

I would like to have a clean C# class that authenticates from Active Directory. It should be pretty simple, it just has to ask for credentials and check if it matches what AD is expecting. I am responsible for a number of C# applications, and I would like all of them to use the same class. Could someone please provide a clean code s...

Tips on creating clean, elegant code

Writing clean, elegant code is what makes coding a pleasure for me. I'm always looking for more ways to do so. Here are some of my strategies/tactics: Keep large code blocks in smaller chunks of routines/methods/classes Be sure every routine has one point of exit. Exit loops with logic at the top of the loop, not with breaks or some ty...

WinForms - Baffled - How to Handle Certain Controls Dynamically - Properly

I have a System.Windows.Form class (my main class). There is a RootMenu object. This is my own custom object. I'm trying to loop through the RootMenu object and on each pass add a ToolStripMenuItem to a ContextMenuStrip (which I named ContextMenu). The RootMenu object contains a List. Links have Names and Urls (both strings). When the f...

Java anonymous class that implements ActionListener?

I was recently doing a programming assignment that required us to implement in code a program specified by a UML diagram. At one point, the diagram specified that I had to create an anonymous JButton that displayed a count (starting at one) and decremented each time it was clicked. The JButton and its ActionListener both had to be anonym...

Find longest repeating strings?

I have some HTML/CSS/JavaScript with painfully long class, id, variable and function names and other, combined strings that get used over and over. I could probably rename or restructure a few of them and cut the text in half. So I'm looking for a simple algorithm that reports on the longest repeated strings in text. Ideally, it would r...

Solutions to organize Guice binding configurations

It's apparently a bad idea to put all bindings in one module, so what do you think is the more elegant way? I think Bob's idea could be good start for this discussion: It's hard to come up with one-size-fits-all rules for this sort of thing, but one Module per package is certainly a good place to start. Putting a Module in each pack...

Tiny serializer

I have a family of classes that contain only variables of the following types: std::string, int, double. I should be able to serialize/deserialize objects of these classes to/from C string (null terminated). I don't want to use some 3rdparty serializer and do not want to write full-featured serializer by myself. I will serialize/deserial...

What's the most elegant way to bubble-sort in C#?

Can this be cleaned up? using System; class AscendingBubbleSort { public static void Main() { int i = 0,j = 0,t = 0; int []c=new int[20]; for(i=0;i<20;i++) { Console.WriteLine("Enter Value p[{0}]:", i); c[i]=int.Parse(Console.ReadLine()); } // Sortin...

What is the most elegant way of shell sorting (comb / diminishing increment sorting) in C#?

Hi SO, Is there a better way to shell sort using C#? // array of integers to hold values private int[] a = new int[100]; // number of elements in array private int count; // Shell Sort Algorithm public void sortArray() { int i, j, increment, temp; increment = 3; while( increment > 0 ) { for( i=0; i < count; i++ ) {...

simplest way to do recursive t-sql for multiple selects

Hi all, I am developing a Bill Of Materials cost calculator program and I am struggling to fathom a simple solution to some recursive selects I want. I am using SQL Server 2005 for this part of the application. Say I have Product A, which contains assembly B, and Part C. Assembly B will contain parts D and E, but, here is where I s...

Munging non-printable characters to dots using string.translate()

So I've done this before and it's a surprising ugly bit of code for such a seemingly simple task. The goal is to translate any non-printable character into a . (dot). For my purposes "printable" does exclude the last few characters from string.printable (new-lines, tabs, and so on). This is for printing things like the old MS-DOS debu...

Elegant coding, how to deal with hidden/invisible HTML code ?

I am developing an ask-and-answer website. There is a "Choose as best answer" button besides each answer, this button should be visible to the asker but should be invisible to other viewers. Other part of the web page is almost the same. So how can I code this web page? Should I check the viewer identity every time to determine whether o...