Skip to content

Instantly share code, notes, and snippets.

View aolde's full-sized avatar

Andreas Oldeskog aolde

View GitHub Profile
@aolde
aolde / Button.server.test.tsx
Last active April 13, 2021 09:09
How to test React components work in Server Side Rendering
/**
* @jest-environment node
*/
import React from 'react';
import { renderToString } from 'react-dom/server';
import Button from '../Button';
describe('<Button> SSR', () => {
it('should render correctly in server-side render', () => {
const result = renderToString(
@aolde
aolde / DebugBundlingAttribute.cs
Created October 9, 2014 12:35
Turn off ASP.NET Bundling based on "debug" query string
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class DebugBundlingAttribute : ActionFilterAttribute
{
private const string DEBUG_MODE_SESSION_KEY = "BundlingDebugMode";
public bool PersistPerSession { get; set; }
public DebugBundlingAttribute()
{
PersistPerSession = true;
@aolde
aolde / BundleConfig.cs
Last active August 29, 2015 14:07
Strip console debug statements with ASP.NET Bundling
var appJs = new ScriptBundle("~/assets/app-js")
.Include(
"~/assets/scripts/main.js"
);
appJs.Transforms.Clear();
appJs.Transforms.Add(new ConfigurableJsMinify
{
CodeSettings = new CodeSettings
{
EvalTreatment = EvalTreatment.MakeImmediateSafe,
@aolde
aolde / static_server.js
Last active February 27, 2024 23:00 — forked from ryanflorence/static_server.js
Simple web server in Node.js. This fork added mime types for common file types.
var http = require("http"),
url = require("url"),
path = require("path"),
fs = require("fs")
port = process.argv[2] || 8888,
mimeTypes = {
"html": "text/html",
"jpeg": "image/jpeg",
"jpg": "image/jpeg",
"png": "image/png",
routes.MapContentRoute(
name: "Search",
url: "{language}/{node}/{event}/{location}/{action}",
defaults: new { action = "Index", @event = UrlParameter.Optional, location = UrlParameter.Optional },
parameters: new MapContentRouteParameters {
Constraints = new { node = new ContentTypeConstraint<SearchPage>(matchInheritedTypes: true) }
}
);
@aolde
aolde / WildcardModelBinder.cs
Last active December 26, 2015 16:59
Implementing support for wildcard routes in EPiServer CMS 7. The WildcardModelBinder is optional. Blog post about the subject: http://simply.io/blog/2013/10/supporting-wildcard-routes-in-episerver-7-cms
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
namespace Project.Core.Mvc.Routing {
/*
// Example of using the modelbinder:
@aolde
aolde / SegmentRouteCollectionExtensions.cs
Last active December 26, 2015 16:29
Getting nice URLs to work in EPiServer CMS 7 with MVC usually means you have to create an ISegment implementation. This extension method makes it a bit tidier.
using System.Collections.Generic;
using System.Web.Routing;
using EPiServer.Web.Routing;
using EPiServer.Web.Routing.Segments;
namespace Project.Core.Mvc.Routing {
public static class SegmentRouteCollectionExtensions {
public static ContentRoute MapContentRouteWithSegments(this RouteCollection routes, string name, string url, object defaults, params ISegment[] segments) {
return routes.MapContentRouteWithSegments(name, url, defaults, null, segments);
}
@aolde
aolde / clipboard.js
Created November 10, 2012 13:23
Clipboard in JavaScript
Clipboard = {};
Clipboard.utilities = {};
Clipboard.utilities.createTextArea = function(value) {
var txt = document.createElement('textarea');
txt.style.position = "absolute";
txt.style.left = "-100%";
if (value != null)
txt.value = value;