Skip to content

Instantly share code, notes, and snippets.

View tstepanski's full-sized avatar

Timothy M. Stepanski tstepanski

View GitHub Profile
@tstepanski
tstepanski / StringBuilderAggregateLinqExtension.cs
Last active October 18, 2016 16:49
More Efficient String Concatenation Using Linq Aggregate
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public static class StringBuilderAggregateLinqExtension {
public static string Concatenate(this IEnumerable<string> strings)
=> strings.Concatenate((builder, nextValue) => builder.Append(nextValue));
public static string ConcatenateLines(this IEnumerable<string> strings)
using System;
using System.Collections.Generic;
using System.Linq;
namespace KattisPhoneList
{
internal static class Program
{
public static void Main()
{
@tstepanski
tstepanski / main.c
Created September 5, 2019 14:32
Circle Bounding Box
#include <stdio.h>
#include <stdlib.h>
#include <zconf.h>
static const int MAX_INPUT_LENGTH = 30;
static const int MAX_CIRCLE_COUNT = 3;
struct Point {
long x;
long y;
public class Example
{
public static void main(String[] args)
{
double twoFiftyInTheAfternoonUTC = 14.5d;
double acstTimeZoneOffset = 9.3;
double twoFiftyInTheAfternoonUTCInACST = add(twoFiftyInTheAfternoonUTC, acstTimeZoneOffset);
System.out.print(twoFiftyInTheAfternoonUTCInACST);
}
@tstepanski
tstepanski / BinaryCalculatorTests.cs
Last active January 30, 2020 01:21
Calculates the longest Binary Gap in an positive 32-bit integer value using a bit shifting technique
using System.Diagnostics;
using Xunit;
using Xunit.Abstractions;
namespace Tests
{
public sealed class CalculatorTests
{
private readonly ITestOutputHelper _testOutputHelper;
@tstepanski
tstepanski / JoeEncoder.cs
Created May 1, 2020 20:14
Encode Tight Keys
using System;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Xunit;
using Xunit.Abstractions;
namespace JoeEncoder
{
@tstepanski
tstepanski / Boulders.java
Created December 7, 2021 04:16
Strategy Swapping
public class JavaFiddle
{
public static void main(String[] args)
{
BoulderMenu menu = new BoulderMenu(2, 4);
menu.showMenu();
System.out.println("now....");
.idea
.dockerignore
Dockerfile
**/obj/
**/bin/
@tstepanski
tstepanski / MessageDebounceSimulation.cs
Created December 1, 2023 01:32
Message Debounce Simulation
using System.Collections.Concurrent;
using System.Text.Json;
using System.Text.Json.Serialization;
var messageService = new MessageService();
var noisyThings = new NoisyThings(messageService);
var cancellationTokenSource = new CancellationTokenSource(Constants.RunSimulationFor);
var runningTasks = noisyThings
.GetNoisyThings()
@tstepanski
tstepanski / Program.cs
Created June 5, 2025 16:06
Semaphore Demonstration
const int countOfWorkersToRunInParallel = 3;
const int countOfWorkersToRunConcurrently = 12;
var cancellationTokenSource = new CancellationTokenSource();
var cancellationToken = cancellationTokenSource.Token;
var semaphore = new SemaphoreSlim(countOfWorkersToRunInParallel);
_ = Task.Run(async () =>
{
await Console.In.ReadLineAsync(cancellationToken);