Thursday, May 18, 2017

Smart Resizing of Remote Desktop Resolution

I recently tried to remote login from a Windows 7 machine to a Windows 8.1. Everything worked fine except for the resolution became too low. Though the remote desktop resolution was showing the correct values, yet the contents were so large and annoying. To make things harder, even the remote desktop resolution settings were uneditable. After trying out various option, I figured out that the adding the following line to the end of the .rdp file did the trick:

smart sizing:i:1

Thanks for the tip from: https://support.smartbear.com/testcomplete/docs/testing-with/running/via-rdp/smart-resizing.html

Sunday, May 31, 2015

Auto Expand WPF TextBox Height


There weren't many direct explanations on the internet to achieve this, so I thought of briefly blogging it here. If you want to auto expand the Textbox to a certain height and then stop and enable the vertical scroll bar from that point onwards, please use have a look at the following sample Textbox declaration in XAML:

   <TextBox Width="500"
       
        MinWidth="100"

        Margin="{StaticResource TextCommentMargin}" 
                                                                            VerticalContentAlignment="Center" 
                                                                            VerticalAlignment="Center" 
                                                                            MinHeight="{StaticResource TextCommentHeight}" 
                                                                            MaxHeight="75.0" 
                                                                            Height="Auto"
                                                                            TextWrapping="Wrap"
                                                                            AcceptsReturn="True" 
                                                                            VerticalScrollBarVisibility="Auto">

The important properties to enable this auto expand feature are; MaxHeight, Height, TextWrapping and VerticalScrollBarVisibility. 
  • Setting the MaxHeight to a certain height limits the Textbox from growing beyond that limit
  • Setting 'Height' to 'Auto' (a non numerical value) is the core to this feature, which enable the textbox to grow as contents fit.
  • Setting TextWrapping to 'Wrap' basically breaks off the sentence when it reaches the tip of the width of the text box.
  • Setting VerticalScrollBarVisibility to 'Auto', will enable the vertical scroll bars, once the text attempts to go beyond the MaxHeight of the Textbox.
All other properties are optional. The AcceptsReturn property provides you with a choice that whether you need to accept carriage returns within the Textbox or not.

I hope this helps somebody.

Thursday, August 21, 2014

Using C# Ternary (?) operator statement as a method parameter


The '?' operator is one of the oldest conditional operators that has been coming along with object oriented languages such as C++, Java and C#. The most significant advantage of using it is it will reduce a couple of lines of code than using the traditional if-else or switch statements, where there is a need to return values.

I first came across the functionality and power of using this just a couple of years ago, while assigned with a task to re-factor some existing code of a senior. More often I have seen the use of this being used with assigning the results to variables. And subsequently my coding behaviour also followed suit. 


Recently I was wondering if the usage could only be limited to assigning variables, and tried adding the statement directly to a method passing it as a variable. It just works fine, since as long as the returning type matches the variable type of the method parameter, such an assignment succeeds. Though this maybe already a straight forward understanding for C# or Java experts, yet this explanation could serve for those in doubt, and to understand the beauty of the language. Ok, with out any further exaggeration, let's have a look at what I am talking about.

Lets assume you have a method to display a name by passing in a name parameter like the following:


Code:
void DisplayName(string name)
{
//
}

Now simply let's assume Two names, 'Ahmed' and 'Jack', and we are to display the name which has less than 5 characters and pass that name to the above method to be further processed. Using the ternary operator the approach would be:


Code:
string name1 = "Ahmed";
string name2 = "Jack";
var nameLessThanFour = name1.Length < 5 ? name1: name2;
DisplayName(nameLessThanFour);

Eliminating the intermediate variable assignment, this could be achieved also as the following:


Code:
DisplayName(name1.Length < 5 ? name1: name2);


Note : This approach would work only for methods that pass arguments by value and not for those that pass arguments by reference (i.e the arguments with ref and out keywords will not work).

Personally I would not recommend the over usage of this approach on method parameters as it could negate the very purpose of simplicity of reading (i.e You might end up with a longer line in the method parameters mixed up with '?'s, ':'s and ","s thereby making it complex to read).

I find the following scenarios where you can advocate this approach:
  1. Methods that have parameters which have a need to pass arguments which require results from a condition.
  2. Using this approach on no more than two or three arguments of a method to reduce reading complexity.
  3. Using this approach on methods that could be called on parts of other lengthy conditional statements such as switch or if-else. This way we could save a lot of unnecessary variable assingments prior to method calls.
That's it. I would like to hear opinions of others on this. Happy Coding ahead...!

Tuesday, August 5, 2014

Operation Protective Edge இல் கொல்லப்பட்ட ஷஹீத் ஒருவருக்கான இரங்கல் செய்தி


Abdul-Hamid Mohammad Abdul-Hamid Al-Maghrabi, 31 வயதான இவர் கடந்த 2014, ஜூலை 26 ஆம் திகதி காஸாவில் கொல்லப்பட்டார். கடந்த ஜூன் மாதம் ரமழானுக்காக காஸாவை விட்டும் வெளியேறுவதற்கு இவருக்கு அனுமதி கிடைத்தும் அதை மறுத்தவராக "இந்த வருடம் எமது பள்ளிகளுக்கு இமாமாக இருக்க விரும்புகின்றேன்" என்றும் தெரிவித்திருந்தார். இந்த அருமையான ஷஹீதைப் பற்றி சகோதரி ஸைனப் அமீன் என்பவருடைய வலைப்பூவில் பின்வருமாறு அனுதாபச் செய்தி வழங்கப்பட்டிருந்தது:
சுப்ஹானல்லாஹ்..! இந்த காணொளி பல தரங்களில் சிறப்பு பெறுகின்றது.
1) முதலாவதாக, இந்த மனிதர் காஸாவை விட்டும் வெளியேறுவதற்கு அனுமதி வழங்கப்பட்டும் அதனை மறுத்துள்ளார். ஏன்? எதற்காக? அவரது வரிகளில்:
"இந்த வருடம் எமது பள்ளிகளுக்கு இமாமாக இருக்க விரும்புகின்றேன்" . அல்லாஹு அக்பர்...!
2) இரண்டாவதாக, எமது படைப்பாளனிடம் சிறந்த நிலையில்( நோன்பு நோற்றவராக), சிறந்த மாதத்தில் மீண்டுள்ளார். அல்லாஹ் அவரைப் பொருந்திக் கொள்வானாக..அல்லாஹு அக்பர்...!
3) மூன்றாவதாக, இந்த குர்ஆன் வரிகளை திட்டவட்டமாக ஓதுவதற்கு என்ன சாத்தியங்கள் இருந்தன:
"அல்லாஹ்வின் பாதையில் போரிட்டுக் கொல்லப்பட்டவர்களை மரித்தவர்கள் என்று நிச்சயமாக எண்ணாதீர்கள் - தம் ரப்பினிடத்தில் அவர்கள் உயிருடனேயே இருக்கிறார்கள் - (அவனால்) அவர்கள் உணவளிக்கப்படுகிறார்கள்." (3:169)
இது தற்செயலாக நடைபெற்றது அல்லவே. மாற்றமாக இந்த மனிதர் சந்த்ரப்பத்துக்கு ஏற்ற மிகப் பொருத்தமான குர்ஆன் வசனங்களையே ஒதுகின்றார்.
4) நான்காவது, அவரது குரல். ஒரே வரியில் கூறுவதென்றால் "பிரம்மாதம்". வேறு எப்படி என்னால் விபரிக்க முடியும்?
'தியானி', 'பிரதிபலி', 'செயற்படுத்து'. அல்லாஹ் தான் தன்னுடைய ரப்பு என்றும், ரிzஸ்க்கும், வெகுமதிகளும் அவன் பாலிருந்தே வருகின்றன என்பதனை அறிந்திருப்பதனை விட வேறு என்ன சந்தோஷம் ஒரு இறை நம்பிக்கையாளருக்கு இருக்க முடியும். நிச்சயமாக அவன் நம்பிக்கையாளர்களின் செயல்களை வீணாக்குவதில்லை. இந்த ஆயத்துகள், முஸ்லிம் உலகம் தற்போது இருக்கும் நிலைக்கு மிகவும் பொருத்தமாக இருக்கின்றன.
"யா அல்லாஹ்! இன்னாரை மன்னித்து அன்பைச் சொரிவாயாக, இவரை மன்னித்து கிருபை செய்வாயாக, அவரது மீட்சியை அருள்பாளிக்கப்பட்டதாக்குவாயாக. அவரது நுழைவை விசாலமாக்கி, நீர், பனி, மற்றும் பனிக்கட்டிகள் மூலமாக அவரை கழுவி விடுவாயாக, மேலும் கறை படிந்த வெண்ணிற ஆடையை தூயமையாக்குவது போல அன்னாரது பாவங்களிலிருந்தும் அன்னாரை அகற்றிவிடுவாயாக. அன்னாரது வதிவிடத்துக்கு பதிலாக சிறந்த வதிவிடத்தையும், அன்னாரது குடும்பத்துக்கு பதிலாக சிறந்த குடும்பம் ஒன்றையும், அன்னாரது துணைவிக்கு பதிலாக சிறந்த துணைவியையும் மாற்றீடாக வழங்குவாயாக. மேலான சுவர்க்கத்தில் அவரை அனுமதிப்பதோடு, கப்ரின் வேதனை மற்றும் நரக நெருப்பின் தீங்கிலிருந்தும் அவரை பாதுகாப்பாயாக"
எனது சமூகமே..! அநியாயக்காரர்களின் கரங்களில் சிக்குண்டு தவிக்கும் எமது உம்மத்தினருக்காக பிரார்த்திப்பதனை மறந்து விட வேண்டாம். அவர்களை உங்களில் ஒருவராக கருதி அவர்களுக்காக பிரார்த்தியுங்கள்! இன்ஷா அல்லாஹ்..!
சுப்ஹானல்லாஹ்..! அல்லாஹ் அவர்களை ஏற்றுக் கொள்வானாக, அல்லாஹ் அவர்களை ஜென்னதுல் பிர்தவ்சில் அவர்களை மீண்டும் இணைப்பானாக. அவர்களை பிரிந்து வாடும் அவர்களின் அன்புக்குரியவர்களுக்கு அல்லாஹ் பொறுமையை வழங்குவானாக. அடுத்தவருடைய மறுமை வாழ்வுக்காக உழைக்கும் மனிதர்களில் நின்றும் எம்மை வல்ல அல்லாஹ் திகழச் செய்வானாக. மேலான சுவனத்தில் எமது சகோதர சகோதரிகளை சந்திக்கும் மிகப்பெரிய பாக்கியத்தை எமக்கு வல்ல அல்லாஹ் தந்தருள்வானாக...!
மூலம்: http://goo.gl/Kyz5ut

Thursday, July 17, 2014

My first voluntary translation of ACJU's press statement on GAZA attacks

Upon request of the ACJU, I recently did a translation for them for a statement against Israel's aggression on Palestine. The article was originally in Tamil:

http://www.acju.lk/press-release/against-israel/

Tuesday, July 8, 2014

Dealing with C# constants

These days I'm more focused on polishing up my existing C# programming skills as well as attempting to learn more of the language with its new versions. I've begun to read a book titled "Effective C#: 50 Specific Ways to Improve Your C#" . I prefer to post the summary of each section of what I have learnt new from this book, which may be of useful to others too. Here is a summary of the usage of the const and readonly keywords:


  • const is a Compile-Time constant where as the readonly is a Run-Time constant.
  • Updating the value of a public constant should be viewed as an interface change.You must recompile all code that references that constant. 
  • Updating the value of a read-only constant is an implementation change; it is binary compatible with existing client code.
  • To further elaborate the above points further:
    • const must be used when the value must be available at compile time:
      • Attribute parameters and enum definitions, and those rare times when you mean to define a value that does not change from release to release. 
    • For everything else, prefer the increased flexibility of readonly constants.


Wednesday, March 19, 2014

Analyzing SQL Server Modules

There might be situations where you find mysterious behaviours of your SQL Server Stored Procedures or Functions probably while deploying a lengthy script with multiple creations or alterations of SPs or Functions. In such cases a DROP statement of one stored procedure could accidentally get included in the CREATE script of another one, possibly if you had forgotten the batch terminator GO. Recently at my workplace we were puzzled to see a stored procedure getting disappeared hours after deployment. After some hazzle, search on the internet, I posted this question on StackOverflow, I was able to get a good suggestion from this guy, to check on tracing the usage of the stored procedure by suggesting the following query on this post.

By querying the sys.sql_modules we'll be able to get the definitions of all stored procedures and functions.

SELECT o.type_desc AS ROUTINE_TYPE
        ,o.[name] AS ROUTINE_NAME
        ,m.definition AS ROUTINE_DEFINITION
FROM sys.sql_modules AS m
INNER JOIN sys.objects AS o
    ON m.object_id = o.object_id
WHERE m.definition LIKE '%search term here%'
The search term could be partial name of the stored procedure in question and the "Definition" field will give the complete script on the creation of that SP or Function.

Wednesday, February 19, 2014

Creating Object instances with a LINQ query


I've written many lines of code with LINQ, yet until I came across one astonishing example, which made my jaws drop. Wow.... The following example on MSDN demonstrates the power and beauty of LINQ of how you can create object instances on the fly with a single statement:

This is the sample class:

class Contact
    {
        // Read-only properties. 
        public string Name { get; private set; }
        public string Address { get; private set; }

        // Public constructor. 
        public Contact(string contactName, string contactAddress)
        {
            Name = contactName;
            Address = contactAddress;               
        }
    }

This is the sample code:
// Some simple data sources. 
string[] names = {"Terry Adams","Fadi Fakhouri", "Hanying Feng", 
                              "Cesar Garcia", "Debra Garcia"};
string[] addresses = {"123 Main St.", "345 Cypress Ave.", "678 1st Ave","12 108th St.", "89 E. 42nd St."};

// Simple query to demonstrate object creation in select clause. 
// Create Contact objects by using a constructor. 
var query1 = from i in Enumerable.Range(0, 5)
             select new Contact(names[i],addresses[i]);


Monday, November 25, 2013

Angola denies "BAN of ISLAM"

இணையத்தை தேடும் போது, இதுவும் வதந்தி அடிப்படையில் வந்த செய்தியாகவே தோன்றுகின்றது. குறித்த நாட்டில் பெரும்பான்மை கிறிஸ்தவர்களுக்கும் 1% இற்கும் குறைவான முஸ்லிம் சமூகத்துக்கும் இடையில் முறுகல் நிலை உள்ளது என்பது உண்மையே. ஆனால் இப்படி ஒரு முடிவை தமது அரசாங்கம் எடுக்காது என்றும், தமக்கு அப்படி ஒன்றை அறிவிக்கவில்லை என்றும் அமெரிக்காவில் உள்ள அங்கோலா நாட்டு உயர்ஸ்தானிகர் ஒருவர் கருத்து தெரிவித்துள்ளார். அநேக சமூக வலைதளங்களில் இந்த செய்தியுடன் பரப்பப்பட்ட பள்ளி ஒன்று இடிந்து விழுவது 2008 ஆம் ஆண்டில் இஸ்ரேல் நாட்டில் எடுக்கப்பட்டது என்று International Business Times கருத்து தெரிவித்துள்ளது. ஒரு செய்தி "அங்கு சொல்கிறார்கள், இங்கு சொல்கிறார்கள்" என்று துவங்கினால், அது ஒரு வதந்திகான முழு தகைமைகளையும் கொண்டது எனலாம்.

பொறுப்புள்ள முஸ்லிம் சமூகம் என்கிற வகையில் சில "பரபரப்பான" செய்திகளை ஆர்வத்துடன் பதிவிடுவதற்கு முன்பு, குறித்த செய்தி "பரபரப்பாக" பேசப்படுவதற்கான காரணம் என்ன என்பவற்றை ஆராய்ந்து பதிவிட்டால் "வதந்தி" பரப்பிய பாவத்திலிருந்து நாமும் விடுபடலாம்.

IBL இன் முழு செய்தி இதோ:


Thursday, August 29, 2013

Alternative way to get latest selected value from a Combo Box

In .NET at times the ComboBox acts strangely, when you try to select a value but returns a null value (Though the value is displayed in the dropdown list). Using the following work around in the SelectedIndexChanged event or SelectionChangeCommitted event should do the needful.

foreach (Binding binding in (sender as ComboBox).DataBindings)
                {
                    binding.WriteValue();
                }

  var whateverObject = (sender as ComboBox).SelectedItem;

If anybody could explain on what cases a null could be returned, it would benefit many including me. Until that the above solution should save your day.