Skip to content

Instantly share code, notes, and snippets.

@hyrmn
hyrmn / 0_ColorBoxes.cs
Created September 22, 2021 05:18
Some algos to draw things from things. For all of these, Install-Package SixLabors.ImageSharp.Drawing -Version 1.0.0-beta11
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Processing;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
var destWidth = 1920;
var destHeight = 1080;
using var image = new Image<Rgba32>(destWidth, destHeight);
@davidfowl
davidfowl / MinimalAPIs.md
Last active October 24, 2024 13:39
Minimal APIs at a glance
using System;
using System.Threading.Tasks;
namespace System.Collections.Concurrent
{
public static class ConcurrentDictionaryExtensions
{
/// <summary>
/// Provides an alternative to <see cref="ConcurrentDictionary{TKey, TValue}.GetOrAdd(TKey, Func{TKey, TValue})"/> that disposes values that implement <see cref="IDisposable"/>.
/// </summary>
@hyrmn
hyrmn / capslockwarning.js
Created October 4, 2019 17:46
Show a little capslock warning if the user tries to log in while their capslock key is on.
<script>
(function() {
var capsLockEnabled = false;
document.onkeypress = function (e) {
e = e || window.event;
var s = String.fromCharCode(e.keyCode || e.which);
if (s.toLowerCase() === s.toUpperCase()) {
return;
}
@aarondandy
aarondandy / ChannelSample.cs
Created January 1, 2019 23:16
Simple Sample for System.Threading.Channels
// Install System.Threading.Channels
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Threading.Channels;
using System.Threading.Tasks;
myStuff.forEach(function stuff){
var subStuff = stuff.subStuff;
doSomething({
success: (function(subStuff) { // creates a function scope
return function(results) { // the actual success callback with subStuff scoped
// subStuff and results are now function scoped
};
@Buildstarted
Buildstarted / BloomFilter.cs
Last active January 3, 2019 04:05
Basic Bloom Filter implementation inspired by Kellabyte
namespace BST
{
using System;
using System.Collections;
public class BloomFilter<T>
{
private readonly int _size;
//how many times to run the hash method
@jlong
jlong / uri.js
Created April 20, 2012 13:29
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"