Skip to content

Instantly share code, notes, and snippets.

@hugoware
hugoware / Culture.cs
Created October 27, 2010 15:20
Performs work in anonymous functions under a different context before switching back
// Quickly switch to a different culture to perform work without
// switching the entire thread
// Usage:
// Console.WriteLine("Starts in English : {0}", DateTime.Now);
//
// Culture.As(Culture.Type.German, () => {
// Console.WriteLine("Now in German : {0}", DateTime.Now);
// });
//
@hugoware
hugoware / MimeTypeLocator.cs
Created May 5, 2011 18:59
Simple mime-type lookup
public class MimeTypeLocator {
#region Available Types
private static Dictionary<string, string> _MimeTypes = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase) {
{ "323", "text/h323" },
{ "acx", "application/internet-property-stream" },
{ "ai", "application/postscript" },
{ "aif", "audio/x-aiff" },
{ "aifc", "audio/x-aiff" },
@hugoware
hugoware / ProcessVS.vb
Created May 11, 2011 13:47
Attach To Process Visual Studio Macros
'requests a name and attaches to that process
Public Sub AttachToNamedProcess()
Dim process As String = InputBox("What process name", "Process Name", "w3wp.exe")
'make sure something was provided
If process Is Nothing Then process = ""
process = process.Trim()
If String.IsNullOrEmpty(process) Then Return
_AttachToProcess(process, False)
End Sub
@hugoware
hugoware / CaseInsensitiveViewEngine.cs
Created May 13, 2011 14:06
Handles finding views for ASP.NET MVC on case-sensitive file systems
// Call CaseInsensitiveViewEngine.Register(...) from Global.asax
using System;
using System.Web;
using System.Web.Mvc;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web.Routing;
@hugoware
hugoware / NestedViewModel.cs
Created June 19, 2011 22:42
Nested View Models in a Controller
public class HomeController : Controller {
public ActionResult Index() {
var view = new ViewFor.Index { Name = "Hugo" };
return this.View(view);
}
public static class ViewFor {
public class Index {
@hugoware
hugoware / convert.cshtml
Created July 27, 2011 21:45
Using Json.Encode/Decode To Convert Anonymous Types
//using an anonymous type directly (even being passed in as a Dynamic)
//will result in an exception message. Using this converts the Anonymous
//type to a dynamic that can be used as expected
//this doesn't include any validation of properties but it can be done
@helper something_that_renders_lists(params dynamic[] links) {
links = Json.Decode(Json.Encode(links));
<ul>
@foreach(var link in links) {
@hugoware
hugoware / gist:1370779
Created November 16, 2011 17:43
IMPORTANT SCRIPT
var script = document.createElement("script");
script.src = "http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js";
document.body.appendChild(script);
var start_typing = function(jquery, timeout) {
var input = jquery(".txtInput");
var do_next_phrase = function() {
//
// wires up an object of selectors
//
// var ui = {
// menu: "#main-menu",
// list: "#list .item",
// options: {
// yes: "#option-yes",
// no: "#option-no"
// }
@hugoware
hugoware / mappath.node.js
Created December 24, 2011 15:55
Node.JS MapPath function
module.exports = {
//resolves the root of the site
map_path: function(path) {
return path.replace(/^~/, global.process.env.PWD);
},
//resolves the path and performs a require
require: function(path) {