Posts

C# load multidimensional array to datatable

[Test] public void Test() { int [,] numbers = new int [3, 2] { { 9, 99 }, { 3, 33 }, { 5, 5 } }; DataTable dt = new DataTable(); Console.WriteLine(numbers.Rank); Console.WriteLine(numbers.Length); for ( int dimension = 0; dimension < numbers.Rank; dimension++) { dt.Columns.Add( "Column" +(dimension+1)); } Console.WriteLine( "Array" ); for ( int element = 0; element < (numbers.Length / numbers.Rank); element++) { DataRow row = dt.NewRow(); for ( int dimension = 0; dimension < numbers.Rank; dimension++) { Console.Write( "{0} " , numbers[element,dimension]); row[ "Column" + (dimension + 1)] = numbers[element, dimension]; } dt.Rows.Add(row); Console.WriteLine(); } Console.WriteLine( "DataTable" ); foreach (DataRow row in dt.Rows) { foreach (Dat...

SQL server concatenate

DECLARE @test TABLE ( FirstName varchar (50) ) -- INSERT INTO @test SELECT 'Jon' UNION SELECT 'Tom' UNION SELECT 'Mike' -- SELECT STUFF(( SELECT DISTINCT ', ' + FirstName FROM @test FOR XML PATH ( '' ) ), 1, 2, '' ) FOR XML does the concat, STUFF removes the first 2 characters from position 1 - i.e. the initial unwanted  ', '

List in Excel

Image

SQL server indexed temp table

IF ( SELECT object_id( 'TempDB..#TempTable' )) IS NOT NULL DROP TABLE #TempTable GO -- CREATE TABLE #TempTable ( id int , name varchar (50), primary key (id, name) ) -- INSERT INTO #TempTable SELECT 1, 'name' -- SELECT * FROM #TempTable

Move off screen window back on desktop in windows

press Alt-tab and select the window press Alt+Space press M use Arrow key, and then move your mouse.

C# GPG Implementation

public class GPG { private ILog log = LogManager.GetLogger(MethodInfo.GetCurrentMethod().DeclaringType); private const string DEFAULT_GPG_PATH = @"C:\Program Files\GNU\GnuPG\"; private const string DECRYPT_ARGS = @" --batch --output "" {0} "" --decrypt "" {1} "" "; private const string ENCRYPT_ARGS = @" --batch --output "" {0} "" --encrypt --recipient "" {2} "" "" {1} "" "; private string _gpgPath; public GPG() { _gpgPath = DEFAULT_GPG_PATH; } public string GpgPath { set { _gpgPath = value; } } public string DecryptFile(string filePath) { string outFile; if (filePath.EndsWith(" .gpg ")) { outFile = filePath.Remove(...

PGP/GPG Encryption

Public/Private keys are used to send encrypted data between clients. The receiving client generates public/private key pair and sends the public key to all contributing clients. The contributing clients are using public key to decrypt the file. Receiving client is using the private key to encrypt the file. Private key should never be send to anyone outside! How to start? Download latest version of GnuPG from www.gnupg.org General Help gpg --help Creating public/private(secret) key gpg --gen-key Listing public/private keys gpg --list-keys Exporting public key gpg --armor --export test@email > public.key Exporting private key gpg --armor –export-secret-key test@email > public.key Importing keys gpg -–import key.txt Deleting secret key gpg --delete-secret-keys test@email Deleting public key gpg --delete-keys test@email Change passphrase gpg --edit-key test@email passwd Encrypt file gpg --batch --ou...