Skip to content

Instantly share code, notes, and snippets.

View kleinron's full-sized avatar
🦉
C'est moi

Ron Klein kleinron

🦉
C'est moi
View GitHub Profile
static void Main(string[] args)
{
Console.WriteLine("started ClockCounter example");
var clockCounter = new ClockCounter(22, 59, 59);
Console.WriteLine(clockCounter.Time);
clockCounter.IncreaseSecond();
Console.WriteLine(clockCounter.Time);
Console.WriteLine("now let's try again");
clockCounter = new ClockCounter(23, 59, 59);
using System.Threading;
namespace Pepperoni.Lib
{
public class SafeValueSeldomWrites<T>
{
private T innerValue;
private readonly ReaderWriterLockSlim locker = new ReaderWriterLockSlim();
public SafeValueSeldomWrites()
void Application_Start(object sender, EventArgs e)
{
MyGlobals.Wish.Value = 1234;
MyGlobals.Wall.Value = "numb";
}
using System.Threading;
using System.Threading.Tasks;
namespace Bronze.Lib
{
public class ParallelWithInterlock
{
public int Sum(int[,] matrix)
{
var outerUpperBound = matrix.GetLength(0);
private static char[] digits = new[]
{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
public static char ToChar(int digit)
{
return digits[digit];
}
public class CustomersFetcher
{
public IEnumerable<CustomerDetails> GetSleepingCustomers()
{
List<CustomerDetails> result = new List<CustomerDetails>();
var connectionString = "...";
using (var connection = new OleDbConnection(connectionString))
{
connection.Open();
var command = new OleDbCommand("select * from Customers where LastPurchasedAt < ?", connection);
namespace Canberra.InterfacesDemo.Lib
{
public class CustomersReminder
{
public void Remind(ICustomersFetcher customersFetcher, IEmailSender emailSender)
{
foreach (var customer in customersFetcher.GetSleepingCustomers())
{
emailSender.SendRemindMessage(customer.FirstName, customer.LastName, customer.EmailAddress);
}
Pattern phoneNumber = Pattern.With
.AtBeginning.Choice.Either(
Pattern.With.Literal("02"),
Pattern.With.Literal("03"),
Pattern.With.Literal("04"),
Pattern.With.Literal("08"),
Pattern.With.Literal("09"),
Pattern.With.Literal("072"),
Pattern.With.Literal("073"),
Pattern.With.Literal("074"),
@kleinron
kleinron / testWithHttp.js
Created December 5, 2021 10:02
nodejs test server
const http = require('http');
const incomingRequests = [];
const requestListener = function (req, res) {
let data = '';
req.on('data', chunk => {
data += chunk;
});
req.on('end', () => {
@kleinron
kleinron / LinkedQueue.js
Last active November 14, 2021 15:38
minimal implementation for a queue backed by a singly linked list
class LinkedQueue {
constructor() {
this._newest = null;
this._oldest = null;
this._size = 0;
}
enqueue(item) {
if (this._size === 0) {
this._newest = {value: item, next: null};