logs of my work and digital life
Uncategorized
git tracking and deleting remote branches
Jul 20th
List the remote branches that exist for a repository you have cloned:
git remote show origin
Create a local branch that tracks one of the remote branches and then use that local branch:
git checkout –track -b name_of_local_branch origin/name_of_remote_branch
If you have not done a pull since someone else created the remote branch, you may first need to do:
git fetch
Remove branch from repo.
Ex:
removes somebranch
Circa Wear
Jul 9th
I have uploaded another static website that might become an e-commerce website in future.
Design Patterns: Iterator
Jul 8th
Hi Guys,
I am reading more on design patterns from thisĀ article after little theory session here is working code. Key point was all of the collection classes in the System.Collections namespace, as well as arrays, implement IEnumerable and can therefore be iterated over.
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class IteratorPattern
{
static void Main(string[] args)
{
int[] values = new int[] { 1, 2, 3, 4, 5 };
IEnumerator<int> e = ((IEnumerable<int>)values).GetEnumerator();
while (e.MoveNext())
{
Console.Write(e.Current.ToString() + " ");
}
Console.ReadKey();
}
}
}
Observer pattern with .net
Jul 8th
Hi folks,
Well I am investigating design patterns by reading an article so after reading a bit I thought it would be nice if I write some code and test it.
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
/// <summary>
/// Product Class
/// </summary>
public class Product
{
public delegate void NameChangeEventHandler(int a);
public event NameChangeEventHandler NameChanged;
private string _name;
public string Name
{
get
{
return _name;
}
set
{
_name = value;
if (NameChanged != null)
{
NameChanged(5);
}
}
}
public Product(string name)
{
Name = name;
}
public void PrintName()
{
Console.WriteLine("ProductName={0}", Name);
}
}
/// <summary>
/// Test Class
/// </summary>
public class Test
{
public Test(Product P)
{
P.NameChanged += new Product.NameChangeEventHandler(ChangeDetected);
}
public void ChangeDetected(int a)
{
Console.WriteLine("change found,argument passed is {0}",a);
}
}
static void Main(string[] args)
{
Product p = new Product("najam awan");
p.PrintName();
Test t = new Test(p);
p.Name = "najaf awan";
p.PrintName();
Console.ReadKey();
}
}
}
Custom Event for Classes
Jul 6th
I was reading how to write events for your custom classes so after reading a little I thought give it a shot and created this sample code. Below code is using Product class with event and delegate for event handling and other class named Test is using this class and manipulate product class data. If you change the Name of the product event will fire.
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
/// <summary>
/// Product Class
/// </summary>
public class Product
{
public delegate void NameChangeEventHandler(int a);
public event NameChangeEventHandler NameChanged;
private string _name;
public string Name
{
get
{
return _name;
}
set
{
_name = value;
if (NameChanged != null)
{
NameChanged(5);
}
}
}
public Product(string name)
{
Name = name;
}
public void PrintName()
{
Console.WriteLine("ProductName={0}", Name);
}
}
/// <summary>
/// Test Class
/// </summary>
public class Test
{
public void ChangeDetected(int a)
{
Console.WriteLine("change found,argument passed is {0}",a);
}
public void TestProduct()
{
Product p = new Product("najam awan");
p.PrintName();
p.NameChanged += ChangeDetected;
p.Name = "najaf";
p.PrintName();
Console.ReadKey();
}
}
static void Main(string[] args)
{
Test t = new Test();
t.TestProduct();
}
}
}
JavaScript, 5 ways to call a function
Jun 29th
Hello
I have came across to this wonderful blog post that show in details how to call javascript functions using different ways its a must read article even if you are not good in javascript please read article at
http://devlicio.us/blogs/sergio_pereira/archive/2009/02/09/javascript-5-ways-to-call-a-function.aspx
ELMAH: Error Logging Modules and Handlers
Jun 24th
Today from a blog I discovered this project called ELMAH: Error Logging Modules and Handlers by the name you can guessed by now what it does
and let me tell you it does it very well. After reading a tutorial ELMAH plugged into my asp.net 3.5 test project and working good. I really liked it and thinking to use it into my future projects.
If you need a serious error logging utiliy download ELMAH now.
Show Detailed ASP.NET Error Messages to Developers
Jun 24th
If ELMAH project will not work for me I will implement this error handling technique from scott gu blog.
C# Interfaces
Jun 22nd
These parts are taken from msdn and some might be taken from other websites.
An interface can inherit from one or more base interfaces.
When a base type list contains a base class and interfaces, the base class must come first in the list.
A class that implements an interface can explicitly implement members of that interface. An explicitly implemented member cannot be accessed through a class instance, but only through an instance of the interface.
Ref: http://msdn.microsoft.com/en-us/library/87d83y5b(VS.80).aspx
Interfaces can consist of methods, properties, events, indexers, or any combination of those four member types. An interface cannot contain fields. Interfaces members are automatically public.
if a base class implements an interface, the derived class inherits that implementation.
Classes and structs can inherit from interfaces in a manner similar to how classes can inherit a base class or struct, with two exceptions:
- A class or struct can inherit more than one interface.
- When a class or struct inherits an interface, it inherits only the method names and signatures, because the interface itself contains no implementations
To implement an interface member, the corresponding member on the class must be public, non-static, and have the same name and signature as the interface member. Properties and indexers on a class can define extra accessors for a property or indexer defined on an interface. For example, an interface may declare a property with a get accessor, but the class implementing the interface can declare the same property with both a get and set accessor. However, if the property or indexer uses explicit implementation, the accessors must match.
Interfaces can inherit other interfaces. It is possible for a class to inherit an interface multiple times, through base classes or interfaces it inherits. In this case, the class can only implement the interface one time, if it is declared as part of the new class. If the inherited interface is not declared as part of the new class, its implementation is provided by the base class that declared it. It is possible for a base class to implement interface members using virtual members; in that case, the class inheriting the interface can change the interface behavior by overriding the virtual members. For more information about virtual members
Overview:
An interface has the following properties:
- An interface is like an abstract base class: any non-abstract type inheriting the interface must implement all its members.
- An interface cannot be instantiated directly.
- Interfaces can contain events, indexers, methods and properties.
- Interfaces contain no implementation of methods.
- Classes and structs can inherit from more than one interface.
- An interface can itself inherit from multiple interfaces.