Skip to content

Instantly share code, notes, and snippets.

@markrendle
markrendle / CheckQueueRoutes.cs
Created August 6, 2014 14:10
Route-validating Assertion
public class CheckQueueRoutes : RouteMarchBase<QueueController>
{
[Fact]
public void MatchesDeleteMessagePath()
{
AssertRoute("api/testaccount/queue/delete/testqueue/testid?pop=testpop",
ctrl => ctrl.Delete("testaccount", "testqueue", "testid", "testpop", null));
}
}
@markrendle
markrendle / trashTheForm.js
Created July 17, 2014 14:52
Trash ASPX server-side form for SPA pages
// Requires jQuery
$(function() {
var $theForm = $("#theForm"), contents = $theForm.contents();
$theForm.after(contents);
});
module SgDirectives {
declare function marked(source: string): string;
function syncHeights(source: HTMLElement, target: HTMLElement) {
var syncHeight = () => target.style.height = source.offsetHeight + "px";
syncHeight();
source.addEventListener("mouseup", syncHeight);
}
function link(scope: ng.IScope, jelem: ng.IAugmentedJQuery) {
@markrendle
markrendle / command.ts
Created June 12, 2014 15:20
ICommand-ish pattern for AngularJS
module Zudio.System {
var trueFunc = ()=> true;
export class Command {
public cssClass: string;
public canExecute: () => boolean;
public show: () => boolean;
constructor(cssClass: string, public text: string, public execute: Function, canExecute?: () => boolean, show?: () => boolean) {
this.cssClass = "icon-" + cssClass;
this.canExecute = canExecute || trueFunc;
this.show = show || trueFunc;
@markrendle
markrendle / teaser.cs
Created June 4, 2014 14:21
Simple.Data v2 teaser
class Tease
{
private readonly dynamic _db = Database.Open();
public async void DoSomeStuff()
{
// Async by default
Customer customer = await _db.Customers.Get(42).WithOrders();
// Batch operations
@markrendle
markrendle / mylib.d.ts
Last active June 25, 2017 09:18
Add CustomEvent to lib.d.ts Window interface and global window object
interface CustomEventParams {
bubbles?: boolean;
cancelable?: boolean;
detail?: any;
}
// Extend the lib.d.ts CustomEvent interface with the proper constructor
interface CustomEvent {
new(event: string, params?: CustomEventParams);
}
@markrendle
markrendle / abstract.md
Created May 6, 2014 10:21
AngularJS & TypeScript talk abstract

AngularJS is Google's answer to client-side JavaScript MVC application development.

TypeScript is Microsoft's answer to working large, complex JavaScript code-bases. It adds static typing and supports features from next-generation JavaScript, such as classes and modules.

Put them together and you get something a bit like WPF-style MVVM, but better. This talk will introduce AngularJS and TypeScript, and show how to combine them effectively to build real browser-based applications.

@markrendle
markrendle / 0-DEBUG-constant-in-TypeScript-with-Uglify.md
Last active February 28, 2017 09:23
Compile-time constants with TypeScript and UglifyJS

DEBUG constant in TypeScript with UglifyJS

One of the requested features in TypeScript is support for the kind of compilation constants that C#, for example, provides, where you can say

#if(DEBUG)
  MessageBox.Show(...);
#endif
@markrendle
markrendle / More.txt
Created February 27, 2014 14:35
Ultra-private field: force access of variable via property even within class
OK, so technically within the class you can still access the variable by calling getMyProperty or setMyProperty instead of via the property, but you still encapsulate the functionality with the getting and setting.
@markrendle
markrendle / eg.cs
Last active August 29, 2015 13:56
Destructuring arbitrary types with attributes
// Modifiers on primary constructor params would be nice :-)
struct Point(private readonly double x, private readonly double y)
{
[DestructuringPosition(0)]
public double X { get; } = x;
[DestructuringPosition(1)]
public double Y { get; } = y;
}