Skip to content

Instantly share code, notes, and snippets.

View peschkaj's full-sized avatar

Jeremiah Peschka peschkaj

View GitHub Profile
@peschkaj
peschkaj / match_queries_by_hash.sql
Created March 24, 2014 01:24
This will match SQL Server statements to the appropriate portion of the execution plan based on the query_plan_hash
SELECT QueryPlanHash,
CASE WHEN QueryType LIKE '%Stored Procedure%' THEN
QueryPlan.value('declare namespace p="http://schemas.microsoft.com/sqlserver/2004/07/showplan";
sum(//p:StmtSimple/@StatementSubTreeCost)', 'float')
ELSE
QueryPlan.value('declare namespace p="http://schemas.microsoft.com/sqlserver/2004/07/showplan";
sum(//p:StmtSimple[xs:hexBinary(substring(@QueryPlanHash, 3)) = xs:hexBinary(sql:column("QueryPlanHash"))]/@StatementSubTreeCost)', 'float')
END AS cost, *
FROM #procs
@peschkaj
peschkaj / dynamic.sql
Last active December 25, 2015 16:39
An exciting adventure with dynamic SQL
SELECT * FROM Sales.SalesOrderHeader AS soh
CREATE INDEX jp_filters_not_offline
ON Sales.SalesOrderHeader (OrderDate)
INCLUDE (SalesOrderID)
WHERE OnlineOrderFlag <> 0
GO

generated.cs is produced by Protobuf-net - you'll notice line 5's hilarious half-complete enumeration. This happens because CLR enums are value types and can't technically be null.

Corrected.cs contains my corrections on line 5. I think that this should let us get around these problems - it's good to know, though, because these do occur in a few other places in the protocol buffers interface.

# -*- shell-script -*-
function riak_dev_cleanup_stage() {
for d in ~/Projects/riak/dev/dev{2,3,4,5}; do
$d/bin/riak-admin cluster leave;
done
~/Projects/riak/dev/dev1/bin/riak-admin cluster plan
}
using System;
using CorrugatedIron;
using CorrugatedIron.Models;
using CorrugatedIron.Util;
using ProtoBuf;
namespace TestAllowMult
{
public class MainClass
{
function riak_dev_cleanup_stage() {
for d in ~/Projects/riak/dev/dev{2,3,4,5}; do
$d/bin/riak-admin cluster leave;
done
~/Projects/riak/dev/dev1/bin/riak-admin cluster plan
}
function riak_dev_cleanup_commit() {
~/Projects/riak/dev/dev1/bin/riak-admin cluster commit
@peschkaj
peschkaj / riak.sh
Created July 18, 2013 21:44
Riak start/stop/teardown scripts
function riak_dev_cleanup_stage() {
for d in ~/Projects/riak/dev/dev{2,3,4,5}; do
$d/bin/riak-admin cluster leave;
done
~/Projects/riak/dev/dev1/bin/riak-admin cluster plan
}
function riak_dev_cleanup_commit() {
~/Projects/riak/dev/dev1/bin/riak-admin cluster commit
@peschkaj
peschkaj / DatastaxDriverTest.cs
Created July 8, 2013 22:39
Cassandra C# driver CassandraNoHostException
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cassandra;
using Cassandra.Data;
using Cassandra.Data.Linq;
using metrics.Core;
using metrics.Reporting;
using System.Diagnostics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cassandra;
using Cassandra.Data;
using Cassandra.Data.Linq;
using metrics.Core;
using metrics.Reporting;
using System.Diagnostics;
public RiakResult<IEnumerable<string>> StreamListBuckets()
{
var lbReq = new RpbListBucketsReq { stream = true };
var result = UseDelayedConnection((conn, onFinish) =>
conn.PbcWriteStreamRead<RpbListBucketsReq, RpbListBucketsResp>(lbReq, lbr => lbr.IsSuccess && !lbr.Value.done, onFinish));
if(result.IsSuccess)
{
var buckets = result.Value.Where(r => r.IsSuccess).SelectMany(r => r.Value.buckets).Select(k => k.FromRiakString());
return RiakResult<IEnumerable<string>>.Success(buckets);