Skip to content

Instantly share code, notes, and snippets.

@sevaa
sevaa / MurMur.sql
Last active July 7, 2020 17:28
MurMurHash64B in MySQL dialect of SQL
drop function if exists MurmurHash64B;
delimiter $$
create function MurmurHash64B(s longblob, seed int unsigned)
returns bigint unsigned
deterministic no sql
begin
declare m int unsigned default 0x5bd1e995;
declare r int default 24;
declare len int default length(s);
@sevaa
sevaa / MurMur.pas
Last active February 14, 2020 22:45
MurMurHash64B in Pascal
unit MurMur;
interface
function MurmurHash64B(s: PAnsiChar; Len: Integer; Seed: UInt32) : UInt64;
implementation
function MurmurHash64B(s: PAnsiChar; Len: Integer; Seed: UInt32) : UInt64;
const
m = $5bd1e995;
@sevaa
sevaa / Delta.cs
Created October 18, 2019 14:48
C# wrapper around MSDelta's ApplyDeltaB API
class Delta
{
[StructLayout(LayoutKind.Sequential)]
private struct DELTA_INPUT
{
public IntPtr lpcStart;
public UIntPtr uSize;
[MarshalAs(UnmanagedType.Bool)]
public bool Editable;
}
@sevaa
sevaa / FromUTF8.sql
Last active November 7, 2021 21:28
Converting a VARBINARY data block in UTF-8 to a NVARCHAR string in pure Transact-SQL
create function dbo.FromUTF8(@s varbinary(max))
returns nvarchar(max)
as
begin
declare @i int = 1, @n int = datalength(@s), @r nvarchar(max) = N''
declare @c int, @c2 int, @c3 int, @c4 int, @u int
while @i <= @n
begin
set @c = ascii(substring(@s, @i, 1))
@sevaa
sevaa / ImportTFSTable.sql
Last active July 31, 2020 16:14
Creates a federating view of all instances of a TFS table in a separate database, for cross-collection queries
CREATE PROC dbo.ImportTFSTable(@Owner varchar(100), @Table as varchar(100), @WithConfig as int = 0)
AS
declare @SQL varchar(max), @FieldSet varchar(max)
set @FieldSet = (select '[' + name + ']' as a from Tfs_DefaultCollection.sys.columns
where [object_id]=object_id('Tfs_Contracts.'+@Owner+'.'+@Table)
order by column_id
for xml path(''))
set @FieldSet = replace(substring(@FieldSet, 4, len(@FieldSet) - 7), '</a><a>', ',')
set @SQL = (select 'select {guid'''+cast(HostId as varchar(36))+'''} as CollID, ' + @FieldSet + ' from [' + replace(substring(DatabaseName, charindex(';', DatabaseName) + 1, 200), '"', '') + '].' + @Owner+ '.' + @Table as a
@sevaa
sevaa / tfsmyscopes.aspx
Created April 27, 2018 15:51
This page retrieves the scopes for a TFS issued OAuth token
<%@ Page Language="C#"%>
<%@ Import namespace="System.IdentityModel.Tokens" %>
<%
Response.ContentType = "text/plain";
string Token;
if((Token = Request.QueryString.Get("Token")) != null)
{
Response.Write(new JwtSecurityToken(Token).Payload["scp"]);
}
%>
@sevaa
sevaa / TFS_UploadExt.ps1
Last active March 27, 2019 17:58
A Powershell script to upload a TFS extension to an on-prem TFS instance with NTLM auth
param
(
[string]$Server,
[string]$File
)
try
{
Add-Type -Assembly "System.IO.Compression.FileSystem"
Add-Type -Assembly "System.Xml"
@sevaa
sevaa / tfsscopes.aspx
Last active April 26, 2019 17:51
See the OAuth scopes of TFS
<%@ Page Language="C#"%>
<%@ Import namespace="Microsoft.VisualStudio.Services.DelegatedAuthorization" %>
<%@ Import namespace="System.Collections.Generic" %>
<%@ Import namespace="System.Linq" %>
<html><body>
<%
AuthorizationScopeDefinitions Defs = AuthorizationScopeDefinitions.Default;
foreach(AuthorizationScopeDefinition Sc in Defs.scopes)
Response.Write("<b>"+Sc.scope +"</b><br/>\n<ul>\n<li>" + string.Join("</li>\n<li>", Sc.patterns) + "</li>\n</ul>\n");
%>
@sevaa
sevaa / Dispatcher.cpp
Created November 2, 2017 14:50
Native process isolation using COM and ROT
#include <windows.h>
#include <process.h>
#include <comdef.h>
#include "..\\Worker\\Protocol.h"
#include <string>
using namespace std;
volatile static unsigned int s_CookieGen = 0;
@sevaa
sevaa / GoogleIAPSignatureCheck.java
Last active November 7, 2022 19:19
Hand-checking the digital signature of Android in-app purchase against the Google public key
//The modulus of the IAP public key, as Base64.
//The public exponent is 65537, we'll hard-code it.
private static final String GMOD = "APXj+9V6Mrp7DwDVLP2yIDhuMiB30R+NQ9JO14jg42S3TcJFhURQZ2RD21GIbp5S7RLy7YDcxOjH765HM7FWUJgJegvL01lYtzFkXv0XRcnL05m5sgTp58i9fYOJt1QKar2k4FI/a6iv7sjT4qGLOcX3drjDx6WKwZdnu6q5rA94rycHoe+BdELsy1eKBp/iI4KIe/Y3WePYfVgynL4mrJOHutf1tvy6WL04zG61yl3PBlwh6uy1K+RBqEXeiznS0ee4Xq3fe3puq6HgEZKw8PQIihxk8odbg1lneqAk51JZ8vuQi9WEZMdvqWK+p4jT+q7mTYQO18NH1MP5y2/fj8k=";
//d is the value of the IAP result intent's string extra "INAPP_PURCHASE_DATA"
//s is the value of the IAP result intent's string extra "INAPP_DATA_SIGNATURE"
private static boolean PowModThenCheck(String d, String c)
{
try