Tuesday 29 January 2019

Codility demo training programming links


https://app.codility.com/demo/results/demoXF96G5-4H5/ (Find the missing interger-codility)
https://app.codility.com/demo/results/trainingXZD43D-6TW/ (binarygap-problem-codility)-
https://codereview.stackexchange.com/questions/159650/find-the-binary-gap-of-a-number-n (binarygap-problem-codility)-
https://app.codility.com/demo/results/trainingFE6RMW-44G/ (OddOccurrencesInArray-codility)
https://app.codility.com/demo/results/training3NH77V-Y89/ (CyclicRotation-codility) -
https://app.codility.com/demo/results/training6ZQAN9-WGE/ (FrogJmp-codility)
https://app.codility.com/demo/results/trainingAY88RG-9EM/ (PermMissingElement-codility)
https://app.codility.com/demo/results/trainingTM4XUS-VHM/ (TapeEquilibrium-codility)
https://app.codility.com/demo/results/trainingSWH5QX-SEN/ (PermCheck-codility)
https://app.codility.com/demo/results/trainingTS6GZZ-6GT/ (FrogRiverOne-codility)
https://app.codility.com/demo/results/trainingU7FSV6-CZX/ (FrogRiverOne-codility)
https://app.codility.com/demo/results/trainingZQYA4X-FZC/ (MissingInteger-codility)
https://app.codility.com/demo/results/trainingTUTEYS-4FJ/ (MaxCounters-codility)
https://app.codility.com/demo/results/trainingJFZBPV-6BW/ (PassingCars-codility)
https://app.codility.com/demo/results/trainingD9AWNE-4VZ/ (GenomicRangeQuery-codility)
https://app.codility.com/demo/results/training99A36D-D3Z/ (MinAvgTwoSlice-codility)
https://app.codility.com/demo/results/trainingYFBVXK-ZRP/ (CountDiv-codility)
https://app.codility.com/demo/results/trainingQSK7RG-URT/ (Distinct-codility)
https://app.codility.com/demo/results/trainingMURZV2-UZ7/ (MaxProductOfThree-codility)
https://app.codility.com/demo/results/trainingZVCQ3P-ERB/ (Triangle-codility)
https://app.codility.com/demo/results/trainingTGEDU3-ZFD/ (NumberOfDiscIntersections-codility)
https://app.codility.com/demo/results/trainingK24AXU-H6Y/ (Fish-codility)
https://app.codility.com/demo/results/trainingJB3XFT-7KU/ (Brackets-codility)
https://app.codility.com/demo/results/trainingC6SCTG-WEX/ (Nesting-codility)
https://app.codility.com/demo/results/trainingVFYNUG-BHQ/ (StoneWall-codility)
https://app.codility.com/demo/results/training893RRV-274/ (EquiLeader-codility)
https://app.codility.com/demo/results/trainingVHJ7HY-KTK/ (Dominator-codility)
https://app.codility.com/demo/results/training8R8WZY-NJD/ (MaxSliceSum-codility)
https://app.codility.com/demo/results/trainingNUQKCT-RHV/ (MaxProfit-codility)
https://app.codility.com/demo/results/trainingTGCSDD-E7C/ (MaxDoubleSliceSum-codility)
https://app.codility.com/demo/results/trainingZ78U9V-GPH/ (CountFactors-codility)
https://app.codility.com/demo/results/trainingG8TT9Z-RFQ/ (MinPerimeterRectangle-codility)
https://app.codility.com/demo/results/trainingFGKQE5-E9V/ (Peals-codility)
https://app.codility.com/demo/results/trainingCUVCTT-GGA/ (Flags-codility)
https://app.codility.com/demo/results/trainingXUCSNA-6YP/ (CountNonDivisible-codility)
https://app.codility.com/demo/results/trainingZYXT6B-KH2/ (Count-Semiprimes-codility)
https://app.codility.com/demo/results/trainingBNQVFV-VE2/ (ChocolatesByNumbers-codility)
https://app.codility.com/demo/results/training8AF3EQ-72V/ (CommonPrimeDivisors)
https://app.codility.com/demo/results/training2M636M-X52/ (FibFrog)
https://app.codility.com/demo/results/trainingQEE5YS-9W4/ (MinMaxDivision)
https://app.codility.com/demo/results/training7ZQURV-HKU/ (NailingPlanks)
https://app.codility.com/demo/results/trainingM5AJY6-SRF/ (AbsDistinct)
https://app.codility.com/demo/results/trainingQU564C-PT5/ (CountDistinctSlices)
https://app.codility.com/demo/results/trainingJN5TQQ-BPA/ (CountTriangles)
https://app.codility.com/demo/results/training53F5KT-T7K/ (MinAbsSumOfTwo)
https://app.codility.com/demo/results/trainingUMNHGX-B4G/ (MaxNonoverlappingSegments)
https://app.codility.com/demo/results/trainingTS5Y2Y-K5J/ (TieRopes)
https://app.codility.com/demo/results/trainingFP6YTF-9JC/ (Ladder)
https://app.codility.com/demo/results/trainingQAGCUD-AT8/ (CommonPrimeDivisors)
https://app.codility.com/demo/results/trainingNH9BUV-88Y/ (NumberSolitaire)
https://app.codility.com/demo/results/trainingX2SB7C-9E9/ (MinAbsSum)
https://app.codility.com/demo/results/training62SMBQ-799/ (FloodDepth)










Friday 21 February 2014

How to Split a string by delimited char in SQL Server

CREATE FUNCTION [dbo].[fnSplitString] 
( 
    @string NVARCHAR(MAX), 
    @delimiter CHAR(1) 
) 
RETURNS @output TABLE(splitdata NVARCHAR(MAX) 
) 
BEGIN 
    DECLARE @start INT, @end INT 
    SELECT @start = 1, @end = CHARINDEX(@delimiter, @string) 
    WHILE @start < LEN(@string) + 1 BEGIN 
        IF @end = 0  
            SET @end = LEN(@string) + 1
       
        INSERT INTO @output (splitdata)  
        VALUES(SUBSTRING(@string, @start, @end - @start)) 
        SET @start = @end + 1 
        SET @end = CHARINDEX(@delimiter, @string, @start)
        
    END 
    RETURN 
END


select *from dbo.fnSplitString('Querying SQL Server','')


Character arrays in T-SQL

--Inputs
declare @x varchar(100)
set @x = 'WORDS'
--Table of letters (like an array)
select substring(@x, number, 1) as v
from master.dbo.spt_values where number between 1 and len(@x) group by number order by number
--Example manipulation
declare @y varchar(100)
select @y = isnull(@y, '') + char(ascii(substring(@x, number, 1))+1)
from master.dbo.spt_values where number between 1 and len(@x) group by number order by number
select @x as 'Original', @y as 'Manipulated (shifted by 1)'
/*Results
v   
----
W
O
R
D
S
Original         Manipulated (shifted by 1)  
---------------- -----------------------------
WORDS            XPSET
*/

Sunday 29 September 2013

How to write C# Program to Print Star Triangle

How to write C# Program to Print Star Triangle

This program will help beginners to write their lab assignment. You can take the logic from below given code. There is 3 loops
First loop is for printing limit and second loop is for space , third loop is for  printing star.
image
C# Program to print star triangle:
using System;
namespace MyApp
{
    class triangle_class
    {
        static void Main(string[] args)
        {
            int number = 12;
            for (int i = 1; i <= number; i++)
            {
                for (int j = 1; j <= number - i; j++)
                    Console.Write(" ");
                for (int k = 1; k <= i; k++)
                    Console.Write(" *");
                Console.WriteLine("");
            }                      
            Console.ReadLine();
        }
    }
}

Thursday 30 May 2013

How to get valuemember of display member in checkedlistbox c#

See more: C#
public void FillCheckedListBox1party()
            {
               try
                  {
                        if (con.State == ConnectionState.Closed)
                        {
                              con.Open();
                        }

                        string commandString = "SELECT NAME ,AC_CODE FROM AccountM where compcode='" + Compcls.Gcomp_cd + "'";
                 
                        DataTable accTable = new DataTable();
                        SqlCommand cmd = new SqlCommand(commandString, con);
                        SqlDataAdapter adpObj = new SqlDataAdapter(cmd);
                        accTable.TableName = "tbl";
                        adpObj.Fill(accTable);
                        con.Close();
                        checkedListBox1.DataSource = accTable;
                        checkedListBox1.ValueMember = "AC_CODE";
                        checkedListBox1.DisplayMember ="NAME";
                        checkedListBox1.BindingContext = new BindingContext();
                        // myChkListBox.BindingContext = new BindingContext();
                  }
                  catch (Exception ex)
                  {

                        throw ex;
                  }
                  finally
                  {
                        con.Close();
                  }
            }
 =================================>
 StringBuilder sb = new StringBuilder();
            for (int i = 0; i < ChkListBox.CheckedItems.Count; i++)
            {
                if (ChkListBox.CheckedItems.Count > 0)
                {
                    DataRow row;
                    row = ((DataRowView)this.ChkListBox.CheckedItems[i]).Row;
                   var val = (row[this.ChkListBox.ValueMember]).ToString();
                    row = null;

                    sb.AppendFormat("{0}, ", val.ToString());
                }
            }
            MessageBox.Show(sb.ToString().TrimEnd(',', ' '));







===================>

Ref: http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/405e0178-bfb2-494e-ba80-f06f89038ac0

Saturday 18 May 2013


Step1:

class Employee
    {
        public string ID{ get; set; }
        public string Name{ get; set; }
    }
Step2: Place a checkedListBox on Form.
Step3:
public void bind()
        {
            List<Employee> lis = new List<Employee>();
            for (int i = 0; i < 10; i++)
            {
                Employee obj = new Employee();
                obj.ID = i.ToString();
                obj.Name = "Name:" + i;
                lis.Add(obj);
            }
            checkedListBox1.DataSource = lis.ToList<Employee>();
            checkedListBox1.DisplayMember = "Name";
            checkedListBox1.ValueMember = "ID";

        }

Above method call in Form_Load.

Find the Item checked or not.
checkedListBox1.SetItemChecked(5, true);
Find the checkedList Items:
  foreach (var item in checkedListBox1.CheckedItems)
            {
                var Emp = (Employee)item;
                MessageBox.Show(Emp.ID + ": " + Emp.Name);
            }

Thursday 16 May 2013

Winform : How to Databind CheckedListBox if it is missing DataSource

Winform : How toDatabind CheckedListBox if it is missing DataSource


When you decide to use CheckedListBox Control, you might expect to useDisplayMemberValueMember or DataSource property like you do for example with ListBox, but you will discover that the Intellisense is not showing those properties at all.
The good news is that even though Intellisense will not show them, the code will still compile when you type those properties by hand.
Now you might think problem solved. Well not exactly.
Microsoft is not recommending this approach. According to them, Data Binding is not supported on CheckedListBox but since the above properties are inherited from a base class, they can not be removed, so the Microsoft just hid them. 
So keep this in mind if you decide to use those properties on  CheckedListBox

How do you fill the control with items without using DataSource property?

One solution of course is to use Items.Add method to add individual item. If you already have an array or a list that contains items, you then use foreach loop and add every item with Items.Add like this:
string[] IceCreamFlavors = {"Banana", "Chocolate", "Pistachio", "Strawberry""Vanilla"};
foreach (var item in IceCreamFlavors)
{
  checkedListBox1.Items.Add(item);
}
But there is simpler way to add items from array or a List by using Items.AddRangemethod instead like this:
checkedListBox1.Items.AddRange(IceCreamFlavors);
If you want to add items from a List, just use ToArray method:
checkedListBox1.Items.AddRange(myList.ToArray());
I hope you found this article useful. Feel free to drop a comment or connect with this blog on the social networks.