Skip to content

Instantly share code, notes, and snippets.

View sevaa's full-sized avatar

Seva Alekseyev (he/him) sevaa

View GitHub Profile
@sevaa
sevaa / ToBase64.bas
Created November 7, 2016 17:04
Base64 encoding in Visual Basic for Applications (VBA)
Public Function ToBase64(Src() As Byte) As String
Const ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
Dim SrcLen As Long, i As Long, Remainder As Long
Dim RLen As Long, Triad As Long, LastSrcIndex As Long
SrcLen = UBound(Src) - LBound(Src) + 1
Remainder = SrcLen Mod 3
'Index of the first byte of the leftover 1- or 2-byte chunk
RLen = LBound(Src) + SrcLen - Remainder
LastSrcIndex = RLen - 3
@sevaa
sevaa / ExportCurlCookies.js
Created January 25, 2017 02:01
CurlCookies
var sys = require("system"), fs = require("fs");
if(sys.args.length < 2)
{
console.log("ExportCurlCookies requires a parameter - cookie file name.");
phantom.exit(1);
}
var Dest = sys.args[1];
var f = fs.open(Dest, {mode:"w"});
@sevaa
sevaa / GenerateTone.js
Last active April 15, 2017 21:59
Generating a simple musical tone purely from JavaScript
function GenerateTone(frequency, duration, volume, rate)
{
if (!volume)
volume = 30000;
if (!rate)
rate = 8000;
var nSamples = rate * duration,
i, w = (2 * Math.PI * frequency) / rate,
wav = new ArrayBuffer(44 + nSamples*2);
@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 / 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 / MurMurHash64B,sql
Created November 7, 2016 17:02
MurMurHash64B in Transact-SQL
create function [dbo].[MurmurHash64B]
(
@s varbinary(max),
@seed bigint = 0
)
returns bigint
as
begin
declare @len int = datalength(@s), @i int = 1
declare @m bigint = 0x5bd1e995
@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 / 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