Skip to content

Instantly share code, notes, and snippets.

@SLaks
SLaks / RoutingExtensions.cs
Created September 18, 2011 22:48
Default Controllers in ASP.Net MVC
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace SLaks.Web.Mvc {
//http://blog.slaks.net/2011/09/using-default-controller-in-aspnet-mvc.html
@SLaks
SLaks / AppHarborModule.cs
Created March 12, 2012 23:26
Fixed AppHarbor Module
using System;
using System.Collections.Specialized;
using System.Configuration;
using System.Linq.Expressions;
using System.Reflection;
using System.Web;
namespace SLaks {
//Based on: https://github.com/trilobyte/Premotion-AspNet-AppHarbor-Integration/blob/master/src/Premotion.AspNet.AppHarbor.Integration/AppHarborIntegrationModule.cs
@SLaks
SLaks / gist:2037478
Created March 14, 2012 16:01
Evil Razor scoping trick
public delegate IDisposable ViewScope();
public static class Scope {
public static readonly ViewScope StateOfEvil = new object().EnterScope;
private static IDisposable EnterScope(this object id) {
HttpContext.Current.Items.Add(id, null);
return new Disposable(() => HttpContext.Current.Items.Remove(id));
}
}
@SLaks
SLaks / gist:2418150
Created April 19, 2012 03:17
Reverse Indentation
//One style to revile them all...
function binarySearch(arr, ele)
{
var beginning = 0, end = arr.length, target;
while (true)
{
target = ((beginning + end) >> 1);
if ((target === end || target === beginning) && arr[target] !== ele)
{
return -1;
@SLaks
SLaks / ExcelResult.cs
Created July 4, 2012 02:40
ExcelExporter.Mvc – A simple ActionResult for returning Excel files from ASP.Net MVC actions using ExcelExporter
using System;
using System.Collections.Generic;
using System.IO;
using System.Web.Mvc;
namespace ExcelExporter.Mvc {
///<summary>An ActionResult that sends an Excel spreadsheet to the client.</summary>
public class ExcelResult : FilePathResult {
static readonly Dictionary<ExcelFormat, string> ContentTypes = new Dictionary<ExcelFormat, string> {
{ ExcelFormat.Excel2003, "application/vnd.ms-excel" },
@SLaks
SLaks / LogModule.cs
Created October 22, 2012 15:30 — forked from pawelpabich/LogModule.cs
Faster Log4Net and NLog modules for Autofac
using System;
using System.Linq;
using Autofac;
using Autofac.Core;
using NLog;
using log4net;
using LogManager = NLog.LogManager;
namespace AutofacIdea
{
@SLaks
SLaks / Bugs-1.js
Last active December 20, 2015 05:58
Interview Questions
function ajaxFindIndex(userIds, callback) {
for (var i = 0; i < userIds.length; i++) {
$.getJSON("http://some-api.com/get-user", { id: userIds[i] }, function (user) {
if (callback(user))
return i;
});
}
return -1;
}
if (pwd == 'correcthorsebatterystaple' || pwd == 'Tr0ub4dour&3' || pwd == 'Tr0ub4dor&3') { // easteregg
score = 0;
word = ['', 'lol']
if (pwd == 'correcthorsebatterystaple') {
// TRANSLATORS this text is displayed rarely, whenever a user selects a password that is from this comic:
// http://imgs.xkcd.com/comics/password_strength.png
bubble_text.update(_("Whoa there, don't take advice from a webcomic too literally ;)"))
} else {
// TRANSLATORS this text is displayed rarely, whenever a user selects a password that is from this comic:
// http://imgs.xkcd.com/comics/password_strength.png
@SLaks
SLaks / Problems.md
Last active December 24, 2015 12:09
Failed attempts to provide IntelliSense for Node.js in Visual Studio.

This is a failed attempt to make require('./folder/file.js') return the exports object created by that file.

The problem is that the IntelliSense engine runs all imported files before running any user code, so I cannot create a personalized module object for each file separately. Creating a single global module object won't let me figure out what exports come from each module. (If it's possible to pass a parameter to another file, I could solve that)

@SLaks
SLaks / Details.md
Last active December 31, 2015 14:28
Unreadable HTML properties