Skip to content

Instantly share code, notes, and snippets.

View mahizsas's full-sized avatar

MAHIZ mahizsas

View GitHub Profile
using NLog;
using System;
using System.Threading.Tasks;
using System.Web.Hosting;
namespace Web.Models
{
/// <summary>
/// Static class for running background tasks in IIS.
/// Any spawned threads are registered properly with IIS
public class BackgroundService : IRegisteredObject
{
public static void Start(Action action, TimeSpan interval)
{
var backgroundService = new BackgroundService(interval, action);
HostingEnvironment.RegisterObject(backgroundService);
}
private Timer timer;
angular.module('autosaveExample', [])
.directive("Autosaved", ["$timeout", function($timeout) {
"use strict";
return {
link: function(scope, element, attrs) {
var autosave = function() {
$timeout(function() {
var form = scope[element.attr("name")];
if (form.$dirty) {
angular.module('saveBeforeExitExample', [])
.directive("saveBeforeExit", ["notificationService", function(notificationService) {
"use strict";
return {
link: function(scope, element, attrs) {
window.onbeforeunload = function(){
if (element.hasClass("ng-dirty")) {
element.submit();
}

project.json

{
  // ...
  "dependencies": {
    "Microsoft.AspNet.Server.IIS": "1.0.0-beta1",
    "Microsoft.AspNet.Mvc": "6.0.0-beta1",
    "Microsoft.AspNet.Owin": "1.0.0-beta1",
    "Microsoft.Owin": "3.0.0",
@mahizsas
mahizsas / kmonitor
Last active August 29, 2015 14:15 — forked from anuraj/kmonitor
using System;
using System.Diagnostics;
using System.IO;
namespace kmonitor
{
class Program
{
private static DateTime _lastRead = DateTime.MinValue;
public string GetVirtualPath(VirtualPathContext context)
{
foreach (var matcherParameter in _matcher.Template.Parameters)
{
context.Values.Remove(matcherParameter.Name); // make sure none of the domain-placeholders are appended as query string parameters
}
return _innerRoute.GetVirtualPath(context);
}
@mahizsas
mahizsas / BulkInsert.cs
Last active August 29, 2015 14:15 — forked from paully21/gist:7056277
BulkInsert with SqlBulkCopy
public static void BulkInsert<T>(string connection, string tableName, IList<T> list, string[] propsToSkip)
{
using (var bulkCopy = new SqlBulkCopy(connection, SqlBulkCopyOptions.TableLock))
{
bulkCopy.BatchSize = list.Count;
bulkCopy.DestinationTableName = tableName;
var table = new DataTable();
var props = TypeDescriptor.GetProperties(typeof(T))
//Dirty hack to make sure we only have system data types
(function () {
'use strict';
angular.module('app')
.factory('Storage', [function () {
var fn = {};
fn.has = function (key) {
var value = window.localStorage.getItem(key);
return !!value;
}
@mahizsas
mahizsas / AutofacConfig
Last active August 29, 2015 14:14 — forked from 3nth/AutofacConfig
public class AutofacConfig
{
public static void Configure()
{
var builder = new ContainerBuilder();
builder.RegisterType<ApplicationDbContext>().AsSelf().InstancePerLifetimeScope();
builder.RegisterType<ApplicationUserStore>().As<IUserStore<PortalUser>>().InstancePerLifetimeScope();
builder.RegisterType<ApplicationUserManager>().AsSelf().InstancePerLifetimeScope();
builder.RegisterType<ApplicationSignInManager>().AsSelf().InstancePerLifetimeScope();