Skip to content

Instantly share code, notes, and snippets.

View dterracino's full-sized avatar
🐢
I may be slow to respond…

David Terracino dterracino

🐢
I may be slow to respond…
View GitHub Profile
/// <summary>
/// These are short programming challenges, can be solved with a single LINQ expression. Of course, that might not
/// always make for the most readable code, so feel free to solve these with or without the help of LINQ, and of course
/// solutions in other languages are welcome. If you're using LINQ, then the MoreLINQ library often has extension
/// methods that simplify the task.
/// </summary>
/// <remarks>https://markheath.net/post/linq-challenge-3</remarks>
/// <remarks>https://github.com/morelinq/MoreLINQ</remarks>
public class LinqChallenge3
{
@johnazariah
johnazariah / LinqExtensions.cs
Last active November 15, 2024 13:04
Maybe Monad in C#
public static partial class LinqExtensions
{
public static Maybe<C> SelectMany<A, B, C>(this Maybe<A> ma, Func<A, Maybe<B>> f, Func<A, B, C> select) => ma.Bind(a => f(a).Map(b => select(a, b)));
}
@pedoc
pedoc / ExtensionMethods.cs
Created July 2, 2018 10:03
byte[] -> hex string(with reversal)
public static class ExtensionMethods {
public static string ToHex(this byte[] data) {
return ToHex(data, "");
}
public static string ToHex(this byte[] data, string prefix) {
char[] lookup = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
int i = 0, p = prefix.Length, l = data.Length;
char[] c = new char[l * 2 + p];
byte d;
for(; i < p; ++i) c[i] = prefix[i];
@Quahu
Quahu / purge.cs
Created June 2, 2018 16:52
An example purge command that removes messages from the channel it's used in.
[Command("purge")]
[Alias("clean")]
[Summary("Downloads and removes X messages from the current channel.")]
[RequireUserPermission(ChannelPermission.ManageMessages)]
[RequireBotPermission(ChannelPermission.ManageMessages)]
public async Task PurgeAsync(int amount)
{
// Check if the amount provided by the user is positive.
if (amount <= 0)
{
@UweKeim
UweKeim / convert-wildcards-to-regex.cs
Last active January 28, 2024 21:32
Convert wildcards to Regular Expressions.
private static string convertWildcardToRegex(string pattern)
{
// http://stackoverflow.com/a/6907849/107625
// http://www.codeproject.com/Articles/11556/Converting-Wildcards-to-Regexes
return "^" + Regex.Escape(pattern).
Replace("\\*", ".*").
Replace("\\?", ".") + "$";
}
@shackra
shackra / genres.json
Created April 21, 2018 01:58
Video game genres
{
"__comment": "Took from http://tvtropes.org/pmwiki/pmwiki.php/Main/VideogameGenres you need to do the grouping in your script to combine the incompatible genres!",
"genres":
{
"Action-Adventure": "A game that combines parts from Adventure Games and Action Games together.",
"Metroidvania": "A game that combines parts from Adventure Action Games and Platform Games together. Features emphasis on exploring an interconnected environment and obtaining skills necessary to reach new areas of said environment.",
"Stealth-Based Game": "A game in which the player character must hide and sneak through the level while avoiding notice from much more powerful enemies that the player character cannot take head-on.",
"Survival Sandbox": "A game where the primary objective is to survive for as long as possible in a hostile environment. Also known as Survival Game.",
"Survival Horror": "A game that features overwhelmed protagonist(s), oppressive atmosphere based on Horror conventions and a need for c
@sergiosusa
sergiosusa / steam-profile-showcase-organizer.user.js
Created April 20, 2018 20:51
Add an option to organize the showcases movind up and down
// ==UserScript==
// @name Steam Profile Showcase Organizer
// @namespace http://sergiosusa.com
// @version 0.1
// @description Add some features to the profile edit page on Steam.
// @author Sergio Susa ([email protected])
// @match https://steamcommunity.com/id/*/edit
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
// @grant none
// ==/UserScript==
[data-tag=replied] {
background-color: #ebdbde!important;
color: #662e37 !important;
}
[data-tags=red] {
background-color: #fffafb !important;
color: #942335 !important;
font-weight: normal !important;
}
[data-tags=red] [data-tag] {
border: solid 1px #e6cbcb
}
using System.Collections.Generic;
using UnityEngine;
public static class ExtensionMethods
{
#region List
public static void ShuffleList<T>(this List<T> list)
{
List<T> tempList = list;
for (int i = 0; i < tempList.Count; i++)