Skip to content

Instantly share code, notes, and snippets.

View rvhuang's full-sized avatar
🎮
Super Smash Bros!

Robert Vandenberg Huang rvhuang

🎮
Super Smash Bros!
View GitHub Profile
@rvhuang
rvhuang / Extensions.cs
Last active January 8, 2017 12:41
The Backward Version of Knuth–Morris–Pratt Algorithm
using System;
using System.Collections.Generic;
namespace AlgorithmForce.Searching
{
/*
* Full implementation:
* https://github.com/rvhuang/kmp-algorithm/blob/master/src/AlgorithmForce.Searching/Extensions.cs
*/
public static class Extensions
@rvhuang
rvhuang / ValuesController.cs
Created January 19, 2017 03:20
An example of streaming a large array of objects in JSON via ASP.NET Web API.
using Newtonsoft.Json;
using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
namespace WebApplication1.Controllers
{
@rvhuang
rvhuang / RedisCollectionEnumerator.cs
Created February 13, 2017 08:28
A Redis list enumerator based on StackExchange.Redis library.
using StackExchange.Redis;
using System;
using System.Collections;
using System.Collections.Generic;
namespace ModelWorkshop.Scheduling.Redis
{
internal class RedisCollectionEnumerator<TItem> : IEnumerator<TItem>
{
#region Fields
@rvhuang
rvhuang / ColumnWrapper.cs
Last active February 28, 2017 01:41
A wrapper that enables user to access specific column in a two-dimension array as a collection.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace GitHub.Gist
{
public class ColumnWrapper<T> : IList<T>, IReadOnlyList<T>
{
private readonly T[][] array;
@rvhuang
rvhuang / 0_reuse_code.js
Created March 22, 2017 08:33
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@rvhuang
rvhuang / run.csx
Last active March 31, 2017 14:22
The source code of Coins Flipping AI live demo running on Azure Functions
// https://rvhuang.github.io/livedemo/coinsflipping.html
#r "..\Shared\AlgorithmForce.HeuristicSuite.Portable.dll"
using System;
using System.Collections.Generic;
using System.Net;
using System.Web.Http;
using AlgorithmForce.HeuristicSuite;
public static IEnumerable<bool[]> Run(Request req, TraceWriter log)
@rvhuang
rvhuang / FileUploadOperation.cs
Created September 7, 2017 05:48
Enable file upload button on Swagger's page.
using Swashbuckle.Swagger;
using System;
using System.Web.Http.Description;
namespace UploadingFileFromSwagger.Models
{
/* How to use:
GlobalConfiguration.Configuration
.EnableSwagger(c =>
{
@rvhuang
rvhuang / PermutationsExtension.cs
Last active September 28, 2017 06:16
A set of extension methods enumerating all permutations using Heap's algorithm.
namespace Extensions
{
public static class PermutationsExtension
{
public static IEnumerable<string> GetPermutations(this string str)
{
return GetPermutations<string, char>(str, array => new string(array));
}
public static IEnumerable<TCollection> GetPermutations<TCollection, TElement>(this TCollection elements,
@rvhuang
rvhuang / AStar.cs
Last active May 30, 2018 14:09
A* Algorithm in Generic Programming Style
// Full source code - https://github.com/rvhuang/linq-to-astar/
public static Node<TFactor, TStep> Run<TFactor, TStep>(HeuristicSearchBase<TFactor, TStep> source)
{
var open = new List<Node<TFactor, TStep>>(source.ConvertToNodes(source.From, 0));
if (open.Count == 0)
return null;
open.Sort(source.NodeComparer);