Skip to content

Instantly share code, notes, and snippets.

@bitsprint
bitsprint / sql-row-level-security.sql
Created May 6, 2021 14:10
SQL Row level security
-- DROP FUNCTION [dbo].[fn_tenantSecurityPredicate]
CREATE FUNCTION [dbo].[fn_tenantSecurityPredicate](@tenantId UNIQUEIDENTIFIER)
RETURNS TABLE
WITH SCHEMABINDING
AS
RETURN SELECT 1 AS [predicateResult]
FROM [dbo].[Users]
WHERE [Username] = CURRENT_USER
AND ([TenantId] IS NULL OR ([TenantId] IS NOT NULL AND @tenantId = [TenantId]));
GO
@bitsprint
bitsprint / climb-the-dom.js
Created June 11, 2019 09:06
Climbs the DOM to find a parent element
var el = $('#some-element');
var selector = '#some-elements-parent-further-up-the-dom';
for ( ; el && el !== document; el = el.parentNode ) {
if ( el.matches( selector ) ) return el;
}
@bitsprint
bitsprint / WaitForElement.js
Created June 10, 2019 07:53
Wait for element to be available in DOM
function waitForElement(selector, time) {
if (document.querySelector(selector) !== null) {
alert("The element is displayed, you can put your code instead of this alert.")
return;
}
else {
setTimeout(function() {
waitForElementToDisplay(selector, time);
}, time);
}
@bitsprint
bitsprint / Clientside-File-Download.js
Last active May 2, 2019 11:09
Automatically initiate a file download in the user's browser
const generateDownload = report => {
var downloadLink = document.createElement('a');
downloadLink.style = 'display: none';
document.body.appendChild(downloadLink);
var blob = new Blob([report.data], {
type: 'application/octet-stream',
});
var url = window.URL.createObjectURL(blob);
@bitsprint
bitsprint / gitignore
Created December 19, 2018 14:02
Create a global .gitignore
touch ~/.gitignore_global
git config --global core.excludesfile ~/.gitignore_global
@bitsprint
bitsprint / RetryUtility.cs
Created August 9, 2018 08:21
Retry Utility
public class RetryUtility
{
public void Do(Action action, int retryInterval = 100, int maxAttemptCount = 3)
{
Do<object>(() =>
{
action();
return null;
}, retryInterval, maxAttemptCount);
}
@bitsprint
bitsprint / Nancy-Linqpad.linq
Created July 29, 2018 13:24
Nancy in Linqpad - simple script to get a quick endpoint up and running
<Query Kind="Program">
<NuGetReference>Nancy.Hosting.Self</NuGetReference>
<Namespace>Nancy</Namespace>
<Namespace>Nancy.Bootstrapper</Namespace>
<Namespace>Nancy.Conventions</Namespace>
<Namespace>Nancy.Cookies</Namespace>
<Namespace>Nancy.Cryptography</Namespace>
<Namespace>Nancy.Culture</Namespace>
<Namespace>Nancy.Diagnostics</Namespace>
<Namespace>Nancy.Diagnostics.Modules</Namespace>
@bitsprint
bitsprint / Kill-Kibana.linq
Created July 29, 2018 13:22
LinqPad script to Kill Kibana process
<Query Kind="Program">
<Namespace>System.Diagnostics</Namespace>
<Namespace>System.Runtime.InteropServices</Namespace>
</Query>
void Main()
{
const string fileLocked = @"C:\elasticsearch\kibana-4.2.0-windows\node\node.exe";
var processes = FileUtil.WhoIsLocking(fileLocked);
@bitsprint
bitsprint / Add-ElasticWatch.ps1
Created July 29, 2018 13:12
Add an Elastic Watch
function Add-ElasticWatch-v2($name, $body) {
$uri = "http://localhost:9200/_watcher/watch/" + $name
Add-ElasticWatch($name, $uri, $body)
}
function Add-ElasticWatch-v5($name, $body) {
$uri = "http://localhost:9200/_xpack/watcher/watch/" + $name
Add-ElasticWatch($name, $uri, $body)
@bitsprint
bitsprint / robocopy_directory.bat
Created July 29, 2018 06:32
Robycopy move directory and subfolders with retry
robocopy [From] [TO] /MOVE /S /Z /R:3