Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Greg Miller http://www.principiaprogramatica.com

« Newer Snippets
Older Snippets »
Showing 1-4 of 4 total  RSS 

Get MD5 hash in a few lines of Java

// MD5 in Java, short and sweet version.

    1 import java.security.*;
    2 import java.math.*;
    3 
    4 public class MD5 {
    5    public static void main(String args[]) throws Exception{
    6       String s="This is a test";
    7       MessageDigest m=MessageDigest.getInstance("MD5");
    8       m.update(s.getBytes(),0,s.length());
    9       System.out.println("MD5: "+new BigInteger(1,m.digest()).toString(16));
   10    }
   11 }

Get the Unix Epoch time in one line of C#

int epoch = (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;

Query and join tables across server instances.

Use the following to query or join tables on remote servers. The query must be executed on a system running SQL Server, but the remote system can be pretty much anything an ODBC driver exists for:
select * from OpenDataSource(’SQLOLEDB‘,’Data Source=server.asdf.com;User ID=yourusername;Password=yourpassword‘).somedatabase.dbo.sometable;

MD5 hash in one line of .Net code

// Get an MD5 hash of a string in only one line of code.
// This requires no "using" clauses other than System, and
// produces a string encoded in base64 of the hash.

string hash = Convert.ToBase64String(new System.Security.Cryptography.MD5CryptoServiceProvider().ComputeHash(System.Text.Encoding.Default.GetBytes(SomeString)));
« Newer Snippets
Older Snippets »
Showing 1-4 of 4 total  RSS