Skip to content

Instantly share code, notes, and snippets.

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Diagnosers;
using System;
using System.Text;
[MemoryDiagnoser]
public class Benchmarks
{
StringBuilder builder = new StringBuilder();
@habbes
habbes / Benchmarks.cs
Last active March 1, 2024 09:33
sharpbench-benchmark-demo.cs
// visit https://benchmarkdotnet.org/ for more info on BenchmarkDotNet
using System.Numerics;
using System.Runtime.CompilerServices;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Diagnosers;
[CategoriesColumn]
public class Benchmarks
{
@habbes
habbes / PathHelpers.cs
Created December 1, 2023 13:55
Testing different implementations of generating a path string from a collection of segments
using System;
using System.Buffers;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SegmentsPathString
{
internal static class PathHelpers
@habbes
habbes / get_connection_degree.py
Created November 17, 2023 09:45
Get connection degree in a graph using BFS.
from collections import deque
# When you open LinkedIn profile, it displays a number that shows how closely
# you're connected to that person.
# 1st degree connection are people you're directly connected with
# 2nd degree connections are people who are connected to your first degree connections
# 3rd degree connections are people who are connected to your 2nd degree connections
# etc.
@habbes
habbes / MegaArray.js
Last active February 6, 2021 20:10
Class that allows you to treat multiple arrays as if they were one huge array. Allows merging arrays without creating new copies
class MegaArray {
constructor() {
this._arrays = [];
this._size = 0;
}
push(item) {
const array = this._getActiveArray();
@habbes
habbes / python_threading_test_io_cpu.py
Created April 27, 2020 05:06
Checking whether an I/O bound thread gets a chance to run if there's a CPU bound thread using the CPU
import multiprocessing
import threading
import time
import random
import math
def io_thread_run(val):
time.sleep(1)
while True:
print("thread ", val)
import multiprocessing
import threading
import time
def thread_runner(val):
while True:
print("thread ", val)
num_cpus = multiprocessing.cpu_count()
@habbes
habbes / test_mr_counter_results.py
Last active November 20, 2019 20:26
Verifies results of map reduce implementation for AOS project 4.
#!/usr/bin/python3
# this program verifies implementation of the map operation by checking
# the output results (intermediate_files and final result files) of the map reduce
# counter program against the specified input files
import os
import sys
import re
from collections import Counter
@habbes
habbes / index.js
Created March 17, 2019 20:32
WonderfulLeafyReality created by habbes1 - https://repl.it/@habbes1/WonderfulLeafyReality
const hasAtMostOneAllowedKey = (arg, allowedKeys) => {
const [firstKey, ...otherKeys] = allowedKeys;
if (!firstKey) {
return true;
}
if (firstKey in arg) {
return !otherKeys.some(otherKey => otherKey in arg);
}
else {
return hasAtMostOneAllowedKey(arg, otherKeys);