Skip to content

Instantly share code, notes, and snippets.

View leppie's full-sized avatar
🤡

Llewellyn Pritchard leppie

🤡
  • Cape Town, South Africa
View GitHub Profile
@leppie
leppie / bench.cs
Last active October 29, 2016 00:46
int32 rotation in ironscheme
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
public class Program
{
static void Main(string[] args)
{
BenchmarkRunner.Run<Program>();
}
@leppie
leppie / report.tab
Created September 27, 2016 10:56
IronScheme issues for .NET Standard 2.0
Target type Target member Assembly .NET Standard Recommended changes
T:System.CodeDom.Compiler.CompilerResults T:System.CodeDom.Compiler.CompilerResults IronScheme Not supported
T:System.CodeDom.Compiler.CompilerResults M:System.CodeDom.Compiler.CompilerResults.get_Errors IronScheme Not supported
T:System.Security.CodeAccessPermission T:System.Security.CodeAccessPermission IronScheme Not supported Remove usage.
T:System.Security.CodeAccessPermission M:System.Security.CodeAccessPermission.Demand IronScheme Not supported Remove usage.
T:System.Runtime.Remoting.ObjectHandle T:System.Runtime.Remoting.ObjectHandle IronScheme Not supported
T:System.Runtime.Remoting.ObjectHandle M:System.Runtime.Remoting.ObjectHandle.#ctor(System.Object) IronScheme Not supported
T:System.CodeDom.Compiler.CompilerErrorCollection T:System.CodeDom.Compiler.CompilerErrorCollection IronScheme Not supported
T:System.CodeDom.Compiler.CompilerParameters T:System.CodeDom.Compiler.CompilerParameters IronScheme Not supported
T:System.Cod
class Foo
{
public string Bar {get;set;}
}
string Baz<T>(T t, Func<T, string> sel)
{
return sel(t);
}
@leppie
leppie / posttags_importer.cs
Created August 2, 2016 15:25
Importing post tags like a boss!
using System;
using System.Data.SqlClient;
using System.Linq;
using System.Text.RegularExpressions;
using System.Xml.Linq;
using System.Xml;
using Dapper;
namespace SOImporter
{
class Program
{
// first argument needs to be a reference type...
public static int Add(object a, int b) => (int) a + b;
static void Main(string[] args)
{
var a = 1;
var add1 = (Func<int, int>)Delegate.CreateDelegate(typeof(Func<int, int>), a, typeof(Program).GetMethod("Add"));
-- setup
CREATE DATABASE test
( EDITION = 'basic', MAXSIZE = 2 GB ); --SERVICE_OBJECTIVE = 'S0',
WAITFOR DELAY '00:01';
ALTER DATABASE test
SET QUERY_STORE = ON (OPERATION_MODE = READ_WRITE, INTERVAL_LENGTH_MINUTES = 1);
USE test
@leppie
leppie / azure.md
Last active July 19, 2016 12:57
Creating a high performance Azure web app on the cheap (WIP)

Goal

Get the best possible performance from the Developer Program Benefit subscription on Azure. Around R450 of Azure credits per month for free.

Using

  • App service - D1 Shared (Free is OK, but only 160MB data a day, so AppInsights will eat that up very quickly. Costs R166, above $$$)
  • Database - B Basic (cheap! only R86, good value for money)

Tips

@leppie
leppie / wtf.cs
Created July 12, 2016 11:33
What do you think is being printed?
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
public class MyAttribute : Attribute
{
public int Type { get; set; }
public string Name { get; set; }
}
public class YourAttribute : MyAttribute
{
public YourAttribute()
public static SqlConnection Connection
{
get
{
var ctx = HttpContext.Current;
var con = (SqlConnection) ctx.Items["Connection"];
if (con == null)
{
ctx.Items["Connection"] = con = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString);
ctx.AddOnRequestCompleted(_ => con.Dispose());
using Microsoft.Diagnostics.Tracing;
using Microsoft.Diagnostics.Tracing.Parsers;
using Microsoft.Diagnostics.Tracing.Parsers.Clr;
using Microsoft.Diagnostics.Tracing.Session;
using System;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;