Skip to content

Instantly share code, notes, and snippets.

@dudeNumber4
dudeNumber4 / metadata.json
Last active November 13, 2021 00:06
BasicTransfer
{"valueParameterInfo":[],"slotParameterDescriptions":[],"roleDescriptions":[],"contractType":"Other","contractShortDescription":"","contractName":"","contractLongDescription":"","choiceInfo":[]}
@dudeNumber4
dudeNumber4 / metadata.json
Last active November 8, 2021 22:11
JavascriptSwap
{"valueParameterInfo":[["Amount of Ada",{"valueParameterFormat":{"contents":[0,"₳"],"tag":"DecimalFormat"},"valueParameterDescription":"Amount of Ada to be exchanged for dollars."}],["Amount of dollars",{"valueParameterFormat":{"contents":[2,"$"],"tag":"DecimalFormat"},"valueParameterDescription":"Amount of dollar tokens to be exchanged for Ada."}]],"slotParameterDescriptions":[["Timeout for Ada deposit","Deadline by which Ada must be deposited."],["Timeout for dollar deposit","Deadline by which dollar tokens must be deposited (must be after the deadline for Ada deposit)."]],"roleDescriptions":[["Ada provider","The party that provides the Ada."],["Dollar provider","The party that provides the dollar tokens."]],"contractType":"S","contractShortDescription":"Atomically exchange of Ada and dollar tokens.","contractName":"Swap of Ada and dollar tokens","contractLongDescription":"Waits until one party deposits Ada and the other party deposits dollar tokens. If both parties collaborate it carries the exchange atomi
@dudeNumber4
dudeNumber4 / metadata.json
Last active November 13, 2021 00:33
LoanSample
{"valueParameterInfo":[],"slotParameterDescriptions":[],"roleDescriptions":[],"contractType":"Other","contractShortDescription":"","contractName":"","contractLongDescription":"","choiceInfo":[]}
@dudeNumber4
dudeNumber4 / ShowPartitionRowCounts.sql
Created April 26, 2019 19:25
Script to show table partition row counts.
-- Show partition row counts
SELECT $PARTITION.PartitionTable_PartitionFunc(PartitionedColumn) as Partition_Number, COUNT(1) as Row_Count
FROM PartionedTable
GROUP BY $PARTITION.order_PartitionFunc(PartitionedColumn)
@dudeNumber4
dudeNumber4 / GetPartitionQueryDate.sql
Created April 26, 2019 19:24
A simple function returning a date for partition queries.
create function GetPartitionQueryDate() returns date as
-- Provides the date that we will always query partitioned tables on.
-- Dates within the past 90 days should always be in the operational partition of any partitioned table.
begin
return GETDATE() - 90
end
$CypressCommand = 'npx cypress run --spec ' + "'" + $('$(Build.SourcesDirectory)').Replace('\', '/') + '/AutomatedTests/Cypress/cypress/integration/ci_test.js' + "'"
Invoke-Expression $CypressCommand
@dudeNumber4
dudeNumber4 / GetExecutableStatementFromQueryPlan.sql
Last active March 18, 2019 16:14
Get Executable Statement From TSQL Query Plan
-- Helper function. Drop If Exists depends on v16.
drop function if exists RemoveLeadingTuple;
go
create function RemoveLeadingTuple(@s varchar(max)) returns varchar(max) as
-- If @s contains a leading tuple, e.g., '((xx))', remove the string with that tuple removed
begin
declare @result varchar(max) = @s;
declare @leftParens int = 0;
declare @rightParens int = 0;
if (LEFT(@s, 1) = '(')
---------------------------------- Change database name [Sandbox] to whatever you please (or create it) ------------------------------------------
---------------------------------- Change paths to files below to whatever you please. ------------------------------------------
---------------------------------- Cleanup shrinkfile commands at very bottom assume file names as well. ------------------------------------------
---------------------------------- Create Files/File Groups -------------------------------------------------------------------------
-- We will want 2 new filegroups/files four our partitions:
-- PRIMARY: Partition 2; operational data
-- History: Partition 1; historical data
-- Split: Partition N; temp during split/merge of partitions.
ALTER DATABASE [Sandbox] ADD FILEGROUP [History]
----------------------------------- Create a regular Table for Demo ------------------------------------------------------------------------
-- Adapted from https://www.mssqltips.com/sqlservertip/2888/how-to-partition-an-existing-sql-server-table/
--Table/Index creation. Create table as it would exist before partitioning.
CREATE TABLE [dbo].[TABLE1]
([pkcol] [int] NOT NULL,
[datacol] [int] NULL,
[partitioncol] datetime)
GO
ALTER TABLE dbo.TABLE1 ADD CONSTRAINT PK_TABLE1 PRIMARY KEY CLUSTERED (pkcol)
GO
@dudeNumber4
dudeNumber4 / ShardContextSample.cs
Created October 24, 2018 15:35
Sample Usage of ShardContext
ShardManagement.TrySetShardMapManager();
// true in this sample means first shard (operational).
using (var context = new ShardContext(true))
{
var customer = context.Customers.FirstOrDefault();
if (customer != null)
{
Console.WriteLine($"First operational customer: {customer.CustomerId}");
}