Skip to content

Instantly share code, notes, and snippets.

View LeftofZen's full-sized avatar

Benjamin Sutas LeftofZen

  • Wisetech Global
  • Australia
View GitHub Profile
@LeftofZen
LeftofZen / car_park.cpp
Last active August 10, 2017 00:09
An efficient data structure for caching a small number of tokens
#include <array>
#include <cstddef>
#include <stack>
template <typename T, size_t SIZE>
class CarPark
{
public:
CarPark()
@LeftofZen
LeftofZen / max_decimal_expansion length.cs
Created August 10, 2017 00:04
Solves the max decimal expansion length from 1 to N in a general way using the discrete logarithm. O(n^4)
using System;
namespace Test
{
class RepeatingDecimalLength
{
// Solves the discrete logarithm problem in O(n^3). See https://arxiv.org/ftp/arxiv/papers/0912/0912.2269.pdf
// Returns k that solves for x^k = y (mod p)
public static UInt64 DiscreteLogarithm(UInt64 x, UInt64 y, UInt64 p)
{
@LeftofZen
LeftofZen / Fold expressions
Created October 9, 2017 03:35
C++17 Fold expressions in C++11/14
#pragma once
#include <functional>
struct fold_base
{
template <typename T>
static T fold(T arg)
{
return arg;
@LeftofZen
LeftofZen / openloco-obj-webserver
Last active August 13, 2022 15:35
A simple file server in asp.net 6 that servers openloco obj files in base64 encoding
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
@LeftofZen
LeftofZen / cs
Created January 9, 2023 13:59
rsforum_scraper_for_aussies
using System.Net;
using System.Text.RegularExpressions;
while (true)
{
Console.WriteLine("scraping");
using WebClient client = new();
var url = @$"https://secure.runescape.com/m=forum/forums?320,321,123,65921801,goto,9999";
string html = client.DownloadString(url);