Thursday, May 18, 2017

Prioritization

Always start with WHY am I doing anything before thinking about what should I do or how should I do it.. What! How! Why!

Thursday, November 21, 2013

How to get specific DB object in APAX trigger



QTCustomSettings__c settings = QTCustomSettings__c.getValues('Default');

Monday, August 12, 2013

Java script: get the type of a variable

To get the type of a variable:

Object.prototype.toString.call( someVar )

Compare the type of a variable:

if( Object.prototype.toString.call( someVar ) === '[object Array]' ) {
    alert( 'Array!' );
}

Monday, July 1, 2013

Print contents of a JavaScript object

function printObject(o) {
  var out = '';
  for (var p in o) {
    out += p + ': ' + o[p] + '\n';
  }
  alert(out);
}

Monday, May 13, 2013

Shortcut Key for Table Details in Sql Server Management Studio

If you select a table name in the query window of Sql Server Management Studio and press ALT + F1 it will display the details of that table.

Monday, April 15, 2013

Serializing object to XML while preserving white-space


void Main()
{
var s = XmlSerialize(new C1{Value= "  "});
tblTests.First (t => t.id == 1).val = XElement.Parse(s);
SubmitChanges();

var dbStr = tblTests.First (t => t.id == 1).val.ToString();
var obj = XmlDeSerialize(dbStr, typeof(C1));
(((C1)obj).Value == "  ");
}

internal static string XmlSerialize(object o)
{
var serializer = new XmlSerializer(o.GetType());
            using (var sw = new StringWriter())
            using (var xw = new XmlTextWriter(sw))
            {
                serializer.Serialize(xw, o);
                return sw.GetStringBuilder().ToString();
            }
}

internal static object XmlDeSerialize(string s, Type t)
{
var serializer = new XmlSerializer(t);
using (var sr = new StringReader(s))
            using(var xmlTxtReader = new XmlTextReader(sr))
{
return serializer.Deserialize(xmlTxtReader);
}
}

public class C1
{
[XmlAttribute("xml:space")]
public String SpacePreserve = "preserve";

public string Value{get;set;}
}

Tuesday, March 19, 2013

C#: Using Tasks API for multi tasking


var threads = 100;
                var bag = new ConcurrentBag();
                var act = new List();
                var eachTaskChunkSize = (int)Math.Ceiling((float) nplIds.Keys.Count/(float) threads);
                var subChunks = nplIds.Keys.SplitInChunks(eachTaskChunkSize).ToArray();
                for (int i = 0; i < threads; i++)
                {
                    var taskId = i;
                    var task = new Task(() =>
                                            {
                                                    GetProductDetails( subChunks[taskId] ).ForEach(bag.Add);
                                            });
                    task.Start();
                    act.Add(task);
                }

                Task.WaitAll(act.ToArray());