Skip to content

Instantly share code, notes, and snippets.

View radleta's full-sized avatar

Richard Adleta radleta

View GitHub Profile
@radleta
radleta / ListRolesAndGroupsForUser.sql
Created March 27, 2020 13:57
List all the groups and permissions assigned to a user in SQL Server.
select
[principal_id]
, [name]
, [type_desc]
, is_member(name) as [is_member]
from [sys].[server_principals]
where [type] in ('R','G')
order by [is_member] desc,[type],[name]
Emoji Description Shortcut
Smiley (smile)
Big smile (laugh)
Heart (heart)
Kiss (kiss)
Sad (sad)
Smiley with tongue out (tongueout)
Winking (wink)
Crying (cry)
In love (inlove)
@radleta
radleta / CountTwoLevelReduce.js
Last active December 3, 2019 14:57
The map and reduce functions for Couchbase view to count the number of documents set to expire on a specific number of days from today by their key prefix with two levels.
function (keys, values, rereduce) {
var result = {};
if (rereduce) {
values.forEach(function (firstIndex) {
for (var firstKey in firstIndex) {
// try to get the result associated with this key
var firstResult = result[firstKey];
@radleta
radleta / Map.js
Last active December 2, 2019 15:58
The map and reduce functions for a Couchbase view to show the stats on the size of the documents in a bucket grouped by the key prefix when it is either an underscore or colon.
function (doc, meta) {
// calculate the size of the document
var size;
if (meta.type == "json") {
size = JSON.stringify(doc).length;
} else if (meta.type == "base64") {
size = decodeBase64(doc).length;
}
@radleta
radleta / Map.js
Last active November 26, 2019 19:40
The map and reduce functions for Couchbase View to count the prefix of a cache key separated with an underscore.
function (doc, meta) {
var firstSeparator = meta.id.indexOf('_');
if (firstSeparator > -1) {
var firstKeyPart = meta.id.substring(0, firstSeparator);
emit(firstKeyPart, null);
} else {
emit('n/a', null);
}
}
@radleta
radleta / IEnumerableExtensions.cs
Created November 18, 2019 14:00
Useful extensions for C#.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RichardAdleta
{
public static class IEnumerableExtensions
@radleta
radleta / AsyncLockCookie.cs
Created November 18, 2019 13:55
Ensures exclusive execution of an async method.
using Nito.AsyncEx;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace RichardAdleta
{
/// <summary>
/// The cookie that holds an <see cref="Lock"/> with an <see cref="Completed"/>. The <see cref="Intialized"/> property
/// is set when <see cref="Completed"/> is already initailized.
@radleta
radleta / AsyncTimer.cs
Created November 18, 2019 13:53
A thread safe wrapper for the Timer to ensure only one callback is executing at a time. This prevents long running callbacks from overlapping their execution. Also, provides a wrapper to ensure exceptions are properly logged when they are thrown from the callback.
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace RichardAdleta
{
/// <summary>
/// A thread safe wrapper for the <see cref="Timer"/> to ensure only one callback is executing at a time.
@radleta
radleta / Cargo.cs
Created November 18, 2019 13:50
Cargo is a fire and forget processing queue that ensures items are run in payloads of a fixed size when possible based on currency and delay.
using System.Collections.Concurrent;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Nito.AsyncEx;
namespace RichardAdleta
{
@radleta
radleta / ProgramAsync.cs
Last active November 25, 2019 18:03
C# Async vs Sync Examples
using System;
using System.Threading.Tasks;
using System.Threading;
using System.IO;
namespace AsyncTechTalk
{
class ProgramAsync
{
static int number = 0;