Skip to content

Instantly share code, notes, and snippets.

View mahizsas's full-sized avatar

MAHIZ mahizsas

View GitHub Profile
@mahizsas
mahizsas / StringFormat.js
Created April 16, 2013 04:10
String.Format in Javascript
String.prototype.format = function () {
var literal = this;
for (var i = 0; i < arguments.length; i++) {
var regex = new RegExp('\\{' + i + '\\}', 'g');
literal = literal.replace(regex, arguments[i]);
}
return literal;
};
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Register an Action selector that can include template parameters in the name
config.Services.Replace(typeof(IHttpActionSelector), new ODataActionSelector());
var model = GetEdmModel();
var odataFormatter = new ODataMediaTypeFormatter(model);
@mahizsas
mahizsas / DependencyInjection.cs
Created April 19, 2013 13:04 — forked from iamkoch/DependencyInjection.cs
How to Inject deps in controllers with Castle
using System;
using System.IO;
using System.Reflection;
using System.Web;
using System.Web.Mvc;
using Castle.MicroKernel.Registration;
using Castle.Windsor;
using Castle.Windsor.Installer;
using WednesdayFootball.Factory;
@mahizsas
mahizsas / global.asax.txt
Created April 24, 2013 11:34
Global asax event's
Global.asax contains the following events:
Application_Init: Fired when an application initializes or is first called. It’s invoked for all HttpApplication object instances.
Application_Disposed: Fired just before an application is destroyed. This is the ideal location for cleaning up previously used resources.
Application_Error: Fired when an unhandled exception is encountered within the application.
Application_Start: Fired when the first instance of the HttpApplication class is created. It allows you to create objects that are accessible by all HttpApplication instances.
Application_End: Fired when the last instance of an HttpApplication class is destroyed. It’s fired only once during an application’s lifetime.
Application_BeginRequest: Fired when an application request is received. It’s the first event fired for a request, which is often a page request (URL) that a user enters.
Application_EndRequest: The last event fired for an application request.
Application_PreRequestHandlerExecute: Fired before the
@mahizsas
mahizsas / wcf.diagnostic.xml
Created April 24, 2013 12:07
WCF Error diagnostic
<system.diagnostics>
<sources>
<source name="System.ServiceModel"
switchValue="Information, ActivityTracing"
propagateActivity="true">
<listeners>
<add name="traceListener"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData= "c:\temp\Traces.svclog" />
</listeners>
@mahizsas
mahizsas / gist:5497549
Created May 1, 2013 19:07 — forked from Mithrandir0x/gist:3639232
How to use Service, Factory, Provider
// Source: https://groups.google.com/forum/#!topic/angular/hVrkvaHGOfc
// jsFiddle: http://jsfiddle.net/pkozlowski_opensource/PxdSP/14/
// author: Pawel Kozlowski
var myApp = angular.module('myApp', []);
//service style, probably the simplest one
myApp.service('helloWorldFromService', function() {
this.sayHello = function() {
return "Hello, World!"
@mahizsas
mahizsas / Id.cs
Created May 6, 2013 19:46 — forked from jmhdez/Id.cs
public struct Id<T>
{
public readonly int Value;
public Id(int value)
{
this.value = value;
}
public static implicit operator Id<T>(int value)
public abstract class CircuitBreakerState
{
protected readonly CircuitBreaker circuitBreaker;
protected CircuitBreakerState(CircuitBreaker circuitBreaker)
{
this.circuitBreaker = circuitBreaker;
}
public virtual void ProtectedCodeIsAboutToBeCalled() { }
public class AutoLocalizingRoute : Route
{
public AutoLocalizingRoute(string url, object defaults, object constraints)
: base(url, new RouteValueDictionary(defaults), new RouteValueDictionary(constraints), new MvcRouteHandler()) { }
public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
{
// only set the culture if it's not present in the values dictionary yet
// this check ensures that we can link to a specific language when we need to (fe: when picking your language)
if (!values.ContainsKey("language"))
@mahizsas
mahizsas / delete.bat
Created May 7, 2013 14:34
Delete Files recursively by Date via command shell
# Delete all files order than 7 days under C:\Windows\Temp directory recursively:
forfiles /P c:\Windows\Temp /S /D -7 /C "cmd /c del @path"
# FORCE delete all files order than 7 days under C:\Windows\Temp directory recursively:
forfiles /P c:\Windows\Temp /S /D -7 /C "cmd /c del /f @path"