Skip to content

Instantly share code, notes, and snippets.

View joeriks's full-sized avatar
💭
I may be slow to respond.

Jonas Eriksson joeriks

💭
I may be slow to respond.
View GitHub Profile
var sw = new System.Diagnostics.Stopwatch();
var x = new []{"foo","bar","baz"};
sw.Start();
foreach(var iterations in Enumerable.Range(1,10000000))
{
var result = x.Aggregate ((a,s)=>a+ ", " + s);
}
sw.ElapsedMilliseconds.Dump();
@joeriks
joeriks / structure_and_content_creation_script.cshtml
Created March 27, 2015 10:59
Poor mans "Code First" implementation for Umbraco - or rather a sample of a Structure and Content creation script
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
Layout = null;
}
@functions{
/*
* Poor mans "Code First" implementation for Umbraco
@joeriks
joeriks / app.ts
Created October 7, 2012 09:27
Single Page Application structure with TypeScript - version 1
/// <reference path='ref.ts'/>
module app {
export class Main {
constructor(){
// data context
var data = new app.data.Items();
// initiate some client side router
// using backbone currently, but that's easy to change
@joeriks
joeriks / ArticlePageViewModel.cs
Last active March 8, 2021 08:14
PartialFor - resolve name of partial from type name or from UIHint (like DisplayFor)
public class ArticlePageViewModel {
// use partial view "TopMenuViewModel.cshtml"
public TopMenuViewModel TopMenu {get;set;}
// use partial view "WidgetsViewModel.cshtml"
public WidgetsViewModel Widgets {get;set;}
// use partial view "ExtraWidgets.cshtml"
[UIHint("ExtraWidgets")]
@joeriks
joeriks / sample.d.ts
Last active February 5, 2021 23:35
Generate Typescript Interfaces for all types (classes) within one assembly. 1. Add reference to your assembly within a project. 2. Create somename.tt file with below contents. 3. Insert your own assembly name in the tt file 4. Get the assembly with one of the types 5. Save the tt and the generator will create a interfacefile for you (somename.d.ts)
// Sample generation:
//
// Types in assembly: MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// Generated 01/28/2013 13:11:37
//
module myInterfaces {
//
// Type: MyAssembly.Models.Client
//
@joeriks
joeriks / External-site-a-Global.asax.cs
Created June 30, 2012 18:38
Umbraco: Return node content as json and use it on another site (MVC3)
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"UmbracoContent",
"content/{*url}", new { controller = "Content", action = "Index" });
routes.MapRoute(
"Default", // Route name
@joeriks
joeriks / globals.cshtml
Last active June 7, 2019 11:36
Easily add a global helper in Razor (WebPages and MVC) - without the need for app_code (or recompile the whole app)
@{
// declare a dynamic property and attach current this to it:
PageData[0].Globals = this;
}
@helper Foo(string message){
<p>Foo @message</p>
}
@functions{
@joeriks
joeriks / about.html
Last active November 2, 2018 02:11
KendoUI with router, layout, views and mvvm in Typescript
<h1>About</h1>
@joeriks
joeriks / 1readme.md
Last active May 22, 2018 21:08
Linqpad Extension method to generate csv with class (keep strongly typed) (Temp Tables in LinqPad)

##Preparation:

  1. Get Nuget CsvHelper

  2. Copy extension method to My Extensions in LinqPad

##Usage:

  1. Write your query (C# Statements)
@joeriks
joeriks / createAppLoginWidget.ts
Created February 11, 2013 12:28
Sample custom KendoUI widget using Typescript - with intellisense niceness. Showing html creation, event handling, public element referencing and subviews (show/hide). Simplicity.
module createAppLoginWidget {
declare var kendo;
declare var ui;
declare var $;
var ui = kendo.ui, Widget = ui.Widget
class AppLoginWidget {