Skip to content

Instantly share code, notes, and snippets.

@snippe
snippe / factory1.cs
Created November 6, 2016 12:43
Parameterized Factory
public class PersonFactory
{
public Person GetPerson(int id)
{
if (id > 1000)
{
return new Employee();
}
else
{
<html>
<head>
<title></title>
</head>
<body>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
<div ng-app="">
<input type="text" ng-model="name" />
<p ng-bind="name"></p>
</div>
@snippe
snippe / objectcontext_detach.cs
Created July 26, 2015 03:53
DbContext Examples
ObjectContext objectContext = ((IObjectContextAdapter)entities).ObjectContext;
Employee emp1 = new Employee() { EmployeeName = "Employee 1" };
Employee emp2 = new Employee() { EmployeeName = "Employee 2" };
entities.Employees.Add(emp1);
entities.Employees.Add(emp2);
entities.SaveChanges();
public class Person : IComparable
{
public string Name { get; set; }
public int Age { get; set; }
public int CompareTo(Object obj)
{
Person otherPerson = obj as Person;
if (otherPerson == null)
{
@snippe
snippe / list_sort1.cs
Created January 24, 2015 07:01
Sorting a list
public class Program
{
static void Main(string[] args)
{
Person p1 = new Person() { Name = "Person 1", Age = 34 };
Person p2 = new Person() { Name = "Person 2", Age = 31 };
Person p3 = new Person() { Name = "Person 3", Age = 33 };
Person p4 = new Person() { Name = "Person 4", Age = 26 };
List<Person> people = new List<Person> { p1, p2, p3, p4 };
@snippe
snippe / javascript_factory.js
Created December 31, 2014 05:22
Factory Function in JavaScript
function FactoryFunction() {
var obj = {
prop3: 3,
prop4: 4
};
return obj;
}
FactoryFunction.prototype.myMethod = function () { };
function ConstructorFunction() {
this.prop1 = 1;
this.prop2 = 2;
}
ConstructorFunction.prototype.myMethod = function () { };
//obj1 is assigned with prop1,2 and myMethod
var obj1 = new ConstructorFunction();
function changeValue(val) {
val = val + " changed";
console.log(val); //A changed
}
var val = "A";
changeValue(val);
console.log(val); //A
//----------------------------
@snippe
snippe / routing.cs
Created December 31, 2014 03:36
Registering routes in Global.asax
public class MvcApplication : System.Web.HttpApplication
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
IEnumerable<int> values = new List<int>() { 1, 2, 3 };
int sum = values.Sum(); //6
double average = values.Average(); //2.0