Skip to content

Instantly share code, notes, and snippets.

Avatar

Kelson Ball KelsonBall

View GitHub Profile
View scan.js
// assuming "Board" has a getTokenAt(row, column) function
// that returns "red", "blue", or null for each position
// and an isInBounds(row, column) function that returns
// true if row and column are valid, false if they are off the board
// returns number of players tokens that are connected in a direction
// (Board, string, int, int, int, int) -> int
function countConnectedInDirection(board, player, newTokenRow, newTokenColumn, directionX, directionY) {
var count = 1; // number connected, starts at 1 because of the new token
// scan "forward" in direction
@KelsonBall
KelsonBall / ConsoleApp1.csproj
Last active Dec 20, 2020
Curly Bracketn't Todos List API in C#
View ConsoleApp1.csproj
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<LangVersion>preview</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
@KelsonBall
KelsonBall / main.rs
Last active Dec 30, 2019
words that are 💯
View main.rs
use std::fs::File;
use std::io::{BufReader, BufRead};
fn score(a : &String) -> i32 {
a.chars()
.map(|c| (c as i32) - ('a' as i32) + 1)
.sum::<i32>()
}
fn main() {
@KelsonBall
KelsonBall / Comparison.txt
Created Nov 30, 2018
Generic Raymarching Fragment Shader
View Comparison.txt
OpenGL/Glsl result on left, simulated C# result on the right
https://media.discordapp.net/attachments/439873163497832449/517899042055782410/unknown.png
View bit mask as functional collection
bool HasBit(int mask, int index)
{
return (mask & (1 << index)) != 0;
}
int SetBit(int mask, int index)
{
return mask | (1 << index);
}
View CharSpanExtensions.cs
using System;
// include prerelease nuget package 'System.Memory'
public static class CharSpanExtensions
{
public static DateTime ConsumeDateTime(this ReadOnlySpan<char> source, out ReadOnlySpan<char> remaining)
{
// date time parsing is a nightmare, so take the heap allocation hit and have DateTime.Parse do it
int i = 0;
while (i < source.Length)
@KelsonBall
KelsonBall / switch_case_example.cs
Last active Apr 29, 2018
examples of switch case statements
View switch_case_example.cs
// a switch-case must be in a method
public int GetColorRank(String color)
{
switch (color)
{
case "green":
return 1;
case "blue":
return 2;
case "yellow":
View PImage.cs
using System;
using System.IO;
using ImageSharp;
using ImageSharp.Processing;
using SixLabors.Primitives;
using OpenTK.Graphics.OpenGL;
using Processing.OpenTk.Core.Extensions;
namespace Processing.OpenTk.Core.Textures
{
View PImage.cs
using System;
using System.IO;
using ImageSharp;
using ImageSharp.Processing;
using SixLabors.Primitives;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
using static OpenTK.DisplayDevice;
using Processing.OpenTk.Core.Extensions;