Skip to content

Instantly share code, notes, and snippets.

--drop table if exists #seq
--;with t(date,status) as (
-- select convert(date,dateadd(d,row_number() over (order by @@dbts),{d'2018-12-31'}))
-- ,abs(sign(BINARY_CHECKSUM(newid())%2))
--from string_split(REPLICATE('1,',30),',') a
--)
--select * into #seq from t
select s1.date
@mburbea
mburbea / Bits.cs
Last active February 24, 2019 12:51
namespace System {
// Little-Endian based approaches most likely do not work on big-endian hardware.
// Code based on examples found in
// Bit Twiddling hacks:
// https://graphics.stanford.edu/~seander/bithacks.html
// Chess programming wiki:
// https://chessprogramming.wikispaces.com/BitScan
public static class Bits
{
@mburbea
mburbea / DeBruijnBenchmark.cs
Last active October 6, 2016 16:56
Redux test
using BenchmarkDotNet.Attributes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using BenchmarkDotNet.Configs;
@mburbea
mburbea / string_split_perf_into_table_is_poor.sql
Created April 13, 2016 18:25
Sql 2016's string_split function screams when you don't need to save the elements into a table. If you do need to do that, then it's slow! Almost as slow as an optimized t-sql split func.
if object_id('dbo.fn_split') is not null drop function fn_split;
if object_id('dbo.splitVarbinary') is not null drop function dbo.splitvarbinary;
if exists (select 1 from sys.assemblies where name='split') drop assembly split;
CREATE ASSEMBLY [Split]
AUTHORIZATION [dbo]
FROM 0x4D5A90000300000004000000FFFF0000B800000000000000400000000000000000000000000000000000000000000000000000000000000000000000800000000E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6E6F742062652072756E20696E20444F53206D6F64652E0D0D0A2400000000000000504500004C010300673BF4560000000000000000E00002210B010B00000C00000006000000000000AE2B0000002000000040000000000010002000000002000004000000000000000600000000000000008000000002000000000000030060850000100000100000000010000010000000000000100000000000000000000000582B00005300000000400000A002000000000000000000000000000000000000006000000C000000202A00001C0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000080000000000000000000000082000004800000000
@mburbea
mburbea / CreateSplit.sql
Last active April 13, 2016 18:05
Hybrid Split 2015
if object_id('dbo.fn_split') is not null drop function fn_split;
if object_id('dbo.splitVarbinary') is not null drop function dbo.splitvarbinary;
if exists (select 1 from sys.assemblies where name='split') drop assembly split;
CREATE ASSEMBLY [Split]
AUTHORIZATION [dbo]
FROM 0x4D5A90000300000004000000FFFF0000B800000000000000400000000000000000000000000000000000000000000000000000000000000000000000800000000E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6E6F742062652072756E20696E20444F53206D6F64652E0D0D0A2400000000000000504500004C010300673BF4560000000000000000E00002210B010B00000C00000006000000000000AE2B0000002000000040000000000010002000000002000004000000000000000600000000000000008000000002000000000000030060850000100000100000000010000010000000000000100000000000000000000000582B00005300000000400000A002000000000000000000000000000000000000006000000C000000202A00001C0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000080000000000000000000000082000004800000000
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Threading;
namespace ConsoleApplication2
{
public static class CachingIEnumerable
{
@mburbea
mburbea / program.cs
Created February 4, 2015 06:26
ArrayByteIndexIsSlow
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
namespace ConsoleApplication1
{
@mburbea
mburbea / program.cs
Created January 22, 2015 16:36
StructEnumerator
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
namespace ConsoleApplication1
{
@mburbea
mburbea / SpecifiedConverterContractResolver.cs
Created December 10, 2014 22:23
SpecifiedConverterContractResolver
public class SpecifiedConverterContractResolver : DefaultContractResolver
{
readonly List<JsonConverter> _converters;
readonly bool _camelCaseProperties;
public SpecifiedConverterContractResolver(bool camelCaseProperties, IEnumerable<JsonConverter> converters)
{
if (converters == null)
{
throw new ArgumentNullException("converters");
@mburbea
mburbea / FlagEnumConverter.cs
Last active September 4, 2017 18:07
FlagEnumConverter
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections.Concurrent;
using System.Globalization;
using System.Runtime.Serialization;
namespace Extensions
{