Skip to content

Instantly share code, notes, and snippets.

View cgbeutler's full-sized avatar

Cory Beutler cgbeutler

View GitHub Profile
@cgbeutler
cgbeutler / degrees.json
Last active April 4, 2016 18:24
A randomization of stats surrounding majors for a website prototype. Note: Any long decimals are randomized
{
"schools": [
{
"name": "BYU",
"majors": [
{
"avgGradIncome": 47933.83985587071,
"avgIncome": 80235.65865481534,
"creditHours": 70.52513178928457,
"departments": [
@cgbeutler
cgbeutler / NullCoalescense.cpp
Last active March 16, 2018 22:44
Null coalescense in C++ a bit like in C#, but admittedly not as good.
#include <iostream>
using namespace std;
#define Q(a, b) ([&](){ auto val = (a); if (val) (val->b); }());
#define QQ(a, b) ([&](){ auto val = (a); return ((val) == NULL ? (b) : (val)); }())
class A {
public: void sayHello() { cout << "Hello World\n"; }
};
@cgbeutler
cgbeutler / Program.cs
Created April 16, 2018 17:09
Programming Challenge: Comment in the async or sync version of each function so the output spells "EVIL" then try again to get it to spell "VILE"
using System;
using System.Threading;
using System.Threading.Tasks;
namespace AsyncChallenge
{
internal class Program
{
// Comment in the async or sync version to try to get the program to print out:
// EVIL
@cgbeutler
cgbeutler / CardGame.py
Created January 5, 2019 19:39
Card Game
from random import randint
club = u'\u2663'
diamond = u'\u2666'
heart = u'\u2665'
spade = u'\u2660'
card_suits = [club, diamond, heart, spade]
card_values = [
@cgbeutler
cgbeutler / Enumeration.cs
Created March 22, 2019 17:09
C# generic enumeration
public sealed class ExampleEnumeration : Enumeration<ExampleEnumeration, string>
{
public static readonly ExampleEnumeration Value = new ExampleEnumeration(nameof(Value));
public static readonly ExampleEnumeration Value2 = new ExampleEnumeration(nameof(Value2), "Value 2");
private ExampleEnumeration(string value, string name = null) : base(value, name ?? value) {}
}
/// <summary>
/// Enumeration representation that can take all types
@cgbeutler
cgbeutler / StringEnumeration.cs
Last active May 1, 2019 16:47
String Enumeration class for C#
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
public sealed class ExampleEnum : StringEnumeration<ExampleEnum>
{
public static readonly ExampleEnum Value1 = new ExampleEnum(nameof(Value1));
public static readonly ExampleEnum Value2 = new ExampleEnum(nameof(Value2));
public static readonly ExampleEnum Value3 = new ExampleEnum(nameof(Value3));
@cgbeutler
cgbeutler / FunctionalIf.cs
Last active April 12, 2019 01:33
Functional if statements for C# that pass the calling object into the conditional function, then function, and else function.
// Use like so:
// Console.WriteLine("hello".If(s => s.length == 5, s => s + " world"));
// var newObj = someObj.If(null, new Foo(), o => o.bar());
// return response
// .If(r => r?.Content == null, "", r => r.Content.ReadAsStringAsync().Response)
// .If(string.IsNullOrWhiteSpace, "", content => $"----\n\t{content}\n----")
namespace FuncIf
{
public static class FuncIfExtensions
{
tool
extends CollisionShape2D
export var draw := false setget set_draw
func set_draw( value :bool ) -> void:
draw = value
update()
export var color := Color.white setget set_color
func set_color( value :Color ) -> void:
# Singleton Time
extends Node
##
# Set this class as a singleton in Godot named Time or similar.
# Setting it near the top will ensure it is processed before
# everything else, giving you consistent values for all nodes
# that use this class.
# this class has a global process and physics process count
# that is very useful when doing things less often.
# A wrapper has provided to make that even quicker:
@cgbeutler
cgbeutler / ExportAsAttribute.cs
Last active June 3, 2020 23:46
ExportAs Attribute for Godot CSharp Projects.
using System.Linq;
using Godot;
using Godot.Collections;
namespace Vial.Export {
[System.AttributeUsage(System.AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
public sealed class ExportAsAttribute : System.Attribute {