Musings

A random collection

Archive for July 2011

TECH: Encrypting a file

  1. In order to encrypt a file
    openssl des3 -e -k opensesame -in inputfile.tar -out outputfile.des3
    
    openssl aes-256-cbc -e -salt -k password -in inputfile.tar -out outputfile.enc
    
  2. In order to decrypt a file
    openssl des3 -d -k opensesame -in outputfile.des3 -out inputfile.tar
    
    openssl aes-256-cbc -d -salt -k password -in outputfile.dec -out origfile.tar
    
  3. Decrypt, Gunzip, untar in 1 step (and vice versa)
    openssl des3 -d -k opensesame -in input.tgz.des3  | gzip -c -d - | tar -xf -
    
    tar -cf - contentsDir | gzip -c - | openssl des3 -e -k opensesame -out output.tgz.des3
    
Advertisements

Written by curious

July 27, 2011 at 1:12 pm

Posted in tech-tips

Protected: IND: Madhushala

This content is password protected. To view it please enter your password below:

Written by curious

July 19, 2011 at 12:11 pm

Posted in india

.NET: Bulk Inserts

Using Entity Framework and want to do a bulk copy to SQL Server database:

using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Transactions;

string bulkCopyConnStr = ConfigurationManager.ConnectionStrings["BulkOperations"].ConnectionString;

List<trade> trades = new List<trade>();
foreach (OptionTO inst in instruments)
{
  if (inst.value != null)
  {
    var newTrade = new trade
    {
      bookid = inst.bookId,
      strike = inst.K,
      impliedVol = inst.sigma
    };
    trades.Add(newTrade);
  }
}

using (SqlConnection conn = new SqlConnection(bulkCopyConnStr))
{
  conn.Open();
  using (var tx = conn.BeginTransaction())
  {
    SqlBulkCopy bc = new SqlBulkCopy(conn,
      SqlBulkCopyOptions.CheckConstraints |
      SqlBulkCopyOptions.FireTriggers |
      SqlBulkCopyOptions.KeepNulls, tx);
    bc.BatchSize = 10000;
    bc.DestinationTableName = "trade";
    bc.WriteToServer(trades.AsDataReader());
    tx.Commit();
  }
  conn.Close();
}

Note: this code uses EntityDataReader class for trades.AsDataReader() call.

You will ofcourse need to put this in your app.config

<connectionStrings>
  <add name="BulkOperations" connectionString="data source=DBSERVER;Initial Catalog=DBINSTANCE;user id=DBUSER;password=DBPASSWD;MultipleActiveResultSets=True;persist security info=False;packet size=4096" providerName="" />
</connectionStrings>

Written by curious

July 6, 2011 at 9:13 am

Posted in dotNET