This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- returns (row, col, value) table for specified csv, rows and cols are 1-based | |
create function string_split_csv(@string varchar(max), @field_separator char(1), @row_separator char(1)) returns table as | |
return | |
select a.row, b.col, b.s value | |
from (select row_number() over (order by (select 1)) row, * from string_split(@string, @row_separator)) a | |
cross apply (select row_number() over (order by (select 1)), iif(left(value, 1) in (char(10), char(13)), substring(value, 2, len(value) - 1), value) | |
from string_split(a.value, @field_separator)) b(col, s) | |
create function string_split_csv_quoted(@string varchar(max), @field_separator char(1), @row_separator char(1), @text_qualifier char(1)) returns table as | |
return |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
XmlElement JsonToXml(string json, string root = "root", string unnamed_array_item = "item") | |
{ | |
var r = new Regex(@"\s*([\[\]{}]|""([^""]*)""\s*:|(true|false|null|-?\d+(?:\.\d+)?|""[^""]*"")\s*),?", RegexOptions.Multiline | RegexOptions.Compiled); | |
var doc = new XmlDocument(); var n = doc.CreateElement(root); var s = new Stack<XmlElement>(); string name = null, value = ""; | |
var m = r.Match(json); | |
while (m.Success) | |
{ | |
if (m.Groups[1].Value == "]") name = null; | |
else if (m.Groups[1].Value == "[") name = name ?? unnamed_array_item; | |
else if (m.Groups[1].Value.EndsWith(":")) name = m.Groups[2].Value; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$doc = [xml]'<opml version="2.0"><body/></opml>' | |
$body = $doc.selectSingleNode('//body') | |
# somafm.com channels.. | |
foreach($ch in (irm http://somafm.com/channels.xml).selectNodes('//channels/*')) { | |
$x = $doc.createElement('outline') | |
$x.setAttribute('text', "SomaFM - $($ch.title.innerText)") | |
$x.setAttribute('description', $ch.description.innerText) | |
$x.setAttribute('category', "$($ch.genre)/AAC/128k/") | |
$x.setAttribute('type', 'link') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Trie<T> : Dictionary<T, Trie<T>> | |
{ | |
public KeyValuePair<T, Trie<T>> Parent; | |
public bool ContainsParts(IEnumerable<T> parts, out int index) | |
{ | |
index = 0; | |
Trie<T> t = this, n = null; | |
foreach (var p in parts) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create function imul(@a bigint, @b bigint) returns table as return | |
with | |
_0 as (select a = convert(binary(8), @a), b = convert(binary(8), @b)), | |
_1 as (select | |
hi_a = convert(bigint, substring(a, 1, 4)), lo_a = @a & 0xFFFFFFFF, | |
hi_b = convert(bigint, substring(b, 1, 4)), lo_b = @b & 0xFFFFFFFF from _0), | |
_2 as (select *, x = convert(binary(8), lo_a * lo_b) from _1), | |
_3 as (select s0 = substring(x, 5, 4), x = convert(bigint, substring(x, 1, 4)), hi_a, hi_b, lo_a, lo_b from _2), | |
_4 as (select x = (hi_a * lo_b + x) & 0xFFFFFFFF, s0, hi_b, lo_a from _3) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |
<Target Name="JankyDacpac" AfterTargets="Build"> | |
<JankyDacpac AssemblyName="$(AssemblyName)" InputFile="$(OutputPath)$(AssemblyName).dll" OutputFile="$(OutputPath)$(AssemblyName).dacpac" /> | |
</Target> | |
<UsingTask TaskName="JankyDacpac" TaskFactory="RoslynCodeTaskFactory" AssemblyName="Microsoft.Build.Tasks.Core"> | |
<ParameterGroup> | |
<InputFile ParameterType="System.String" Required="true" /> | |
<OutputFile ParameterType="System.String" Required="true" /> | |
<AssemblyName ParameterType="System.String" Required="true" /> | |
</ParameterGroup> |