Archive for Settembre 19th, 2007

Computer Security Ethics and Privacy

Settembre 19th, 2007

Today, many people rely on computers to do homework, work, create, etc., so it’s important to take special care with your data storage. This week you’ll learn about how to protect your data and prevent intrusions. By Vincent Deguzman. 0919

Sprawdzenie wyrazenia regularnego

Settembre 19th, 2007

Description: np dla email wzorzec
_WzorzecEMail =@”^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$”;

Link: http://www.codekeep.net/snippets/b573881f-0a96-49f1-82c1-ea6c5932b8d0.aspx

			Regex reg = new Regex(_WzorzecEMail);
			if (!reg.IsMatch(_ToEmail))
			{
				Komunikat("Blednie wprowadzony adres e-mail:" + _ToEmail);
				//komunikat jesli nie pasuje do wzorca
			}

Sprawdz polaczenie z baza

Settembre 19th, 2007

Description: metoda wywolywana w celu sprawdzeniea czy jest polaczenie z baza

Link: http://www.codekeep.net/snippets/15869de3-e1b1-4895-908e-98fb562abbc9.aspx

private bool SprawdzPolaczenie()
		{
			SqlConnection m_Conn = new SqlConnection(_ConnectionString);
			try
			{
				m_Conn.Open();
				m_Conn.Close();
				return true;
			}
			catch
			{
				return false;
			}
		}

Wyjatek

Settembre 19th, 2007

Description: Wyjatek

Link: http://www.codekeep.net/snippets/f23dfe37-3c76-41c2-9b0a-11b7c5a172f5.aspx

throw new System.NotImplementedException();

Find Occurence index(s) of substring within a string

Settembre 19th, 2007

Description: method to find number of occurences of a string and index of, within another string

Link: http://www.codekeep.net/snippets/240bbe37-3efd-413f-bd42-aefdbb2e3451.aspx

 private static int[] StringContainsIndexOf(string subString, string fullString)
        {
            ArrayList arrList = new ArrayList();
            for (int i = 0; i < fullString.Length; i++)
            {
                int loc = fullString.IndexOf(subString, i);
                if (loc == -1)
                    break;

                arrList.Add(loc);
                i = loc;
            }

            int[] output = new int[arrList.Count];
            for (int i = 0; i < arrList.Count; i++)
                output[i] = (int)arrList[i];

            return output;
        }

File Count Lines

Settembre 19th, 2007

Description: Very fast method to count the lines in a file.

Link: http://www.codekeep.net/snippets/84502287-a10f-4f15-871b-86df47f9d8f4.aspx

private int CountFileLines(string FileName)
        {
            TextReader reader = File.OpenText(FileName);
            char[] buffer = new char[32 * 1024]; // Read 32K chars at a time
            int total = 1; // All files have at least one line!
            int read;
            while ((read = reader.Read(buffer, 0, buffer.Length)) > 0)
            {
                for (int i = 0; i < read; i++)
                {
                    if (buffer[i] == '\n')
                    {
                        total++;
                    }
                }
            }
            return total;
        }

Auto-incrementing ID counter

Settembre 19th, 2007

Description: A property that increments automatically each time it is accessed.

Link: http://www.codekeep.net/snippets/7440fda7-0c38-42ca-8645-af46eae49379.aspx

      private int m_idCounter = 1;
      /// <summary>
      /// This is the IDCounter that will be used to designate a node's ID.
      /// It will automatically increment each time it is accessed.
      /// </summary>
      public int IDCounter
      {
         get
         {
            // Increment the counter
            m_idCounter = m_idCounter + 1;
            // If this ID already exists, increment the counter.  Repeat as necessary.
            while (idList.Contains(m_idCounter))
            {
               m_idCounter = m_idCounter + 1;
            }
            // Add this ID to the idList
            idList.Add(m_idCounter);
            return m_idCounter;
         }
         set { m_idCounter = value; }
      }