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 / 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;
@leppie
leppie / Program.cs
Created May 20, 2016 16:09
current bench
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running;
[Config(typeof(Config))]
public class Program
{
static void Main(string[] args)
{
@leppie
leppie / results.md
Last active May 17, 2016 17:21
just playing
Total time: 00:19:30 (1170.69 sec)

// * Summary *

BenchmarkDotNet-Dev=v0.9.4.0+
OS=Microsoft Windows NT 6.2.9200.0
Processor=Intel(R) Core(TM) i7-3770K CPU @ 3.50GHz, ProcessorCount=8
Frequency=3246781 ticks, Resolution=307.9974 ns, Timer=TSC
HostCLR=MS.NET 4.0.30319.42000, Arch=64-bit RELEASE [RyuJIT]
@leppie
leppie / dick.sps
Created April 26, 2016 19:00
R6RS test
(import (rnrs))
(display "I am a dick")
(newline)
#!eof
(display "I am a cat")
(newline)
(display "Moeiw")
(newline)