Skip to content

Instantly share code, notes, and snippets.

@ThatRendle
ThatRendle / 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
@ThatRendle
ThatRendle / 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.
@ThatRendle
ThatRendle / 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;
}
class Bobbins
{
[CallStackLocal]
public static string Value = "Foo";
public static void Write()
{
Console.WriteLine(Value);
}
}
@ThatRendle
ThatRendle / fail.html
Created October 29, 2013 00:43
The following HTML page works, except in IE11 when launched from Visual Studio 2012 or 2013
<!DOCTYPE html>
<html>
<head>
<title>IE + VS == FAIL</title>
<style type='text/css'>
#drop-area { width: 300px; height: 300px; background-color: #ccc; }
</style>
<script type='text/javascript'>
document.addEventListener("DOMContentLoaded", function() {
var dropArea = document.getElementById("drop-area");
@ThatRendle
ThatRendle / article.sql
Last active December 24, 2015 09:59
Singular Support files
CREATE TABLE [dbo].[Article]
(
[Id] INT NOT NULL IDENTITY(1,1) PRIMARY KEY,
[Title] NVARCHAR(200) NOT NULL,
[Content] NVARCHAR(MAX) NOT NULL DEFAULT '',
[Created] DATETIME NOT NULL DEFAULT GETDATE()
)
@ThatRendle
ThatRendle / CorsModule.cs
Last active May 28, 2017 07:38
Very basic CORS HttpModule
using System;
using System.Web;
namespace MyOtherSite
{
public class CorsModule : IHttpModule
{
public void Init(HttpApplication application)
{
application.BeginRequest += ApplicationOnBeginRequest;
namespace Simple.Web.Xml
{
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using System.Xml.Linq;
using Inflector;
using Helpers;
using Links;
using MediaTypeHandling;
public List<Ship> GetShips(ShipFlags flags)
{
var db = Database.Open();
// Something impossible
var criteria = db.Ship.Id == null;
if (flags.HasValue(ShipFlags.Cargo))
{
criteria = criteria || db.Ship.Cargo == "Y";
}
if (flags.HasValue(ShipFlags.Intergalactic))
@ThatRendle
ThatRendle / Fix2.cs
Created August 29, 2013 20:08
Quick example for Fix
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Fix2
{
using Env = IDictionary<string, object>;
using ComponentFunc = Func<IDictionary<string, object>, Func<Task>, Task>;
using AppFunc = Func<IDictionary<string, object>, Task>;