C# input reading

This page summarizes the projects mentioned and recommended in the original post on /r/adventofcode

InfluxDB - Power Real-Time Data Analytics at Scale
Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
www.influxdata.com
featured
SaaSHub - Software Alternatives and Reviews
SaaSHub helps you find the best software and product alternatives
www.saashub.com
featured
  • advent-of-code-jq

    Solving Advent of Code with jq

  • internal static class Tools { private static Uri AoCUrl { get; } = new Uri("https://adventofcode.com/"); // Will make sure the files end up in the main project directory private static string ProjectDirectory => Directory.GetParent(path: Environment.CurrentDirectory)?.Parent?.Parent?.FullName ?? throw new FileNotFoundException(); /// /// Attempts to read the input from file given a year and a day, example is set when running test runs using the provided example for each part /// /// 2023 for this year /// 2 for day 2 /// 1 for example of part 1, 2 for example of part 2 /// All provided input as a single string /// public static async Task ReadInput(int year, int day, int? example) { var yearAsString = year.ToString(); // The examples has to be added manually with the name following the following format: {day}_{example}.txt // So for Day 1 part 2 the file would be called 1_2.txt var filePath = Path.Combine(ProjectDirectory, "Inputs", yearAsString, string.Format("{0}{1}.txt", day, example.HasValue ? $"_{example}" : string.Empty)); // If the file doesn't exist we need to request and create it from the server if (!File.Exists(filePath)) { // If the file doesn't exist and example is set we throw an exception to remind you to create it if (example.HasValue) { throw new FileNotFoundException(filePath); } var dirPath = Path.GetDirectoryName(filePath) ?? throw new DirectoryNotFoundException(Path.GetDirectoryName(filePath)); if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } await RequestInput(year, day, filePath); } return await File.ReadAllTextAsync(filePath); } /// /// Makes a request using your session cookie to get the given input and store it in a file for future runs /// /// 2023 for this year /// 2 for day 2 /// Path of the file we want to create private static async Task RequestInput(int year, int day, string path) { // The session_cookie.txt file has to be placed in your project directory // Make sure to add the file to .gitignore so you won't share it with the world var session = await File.ReadAllTextAsync(Path.Combine(ProjectDirectory, "session_cookie.txt")); var cookies = new CookieContainer(); cookies.Add(AoCUrl, new Cookie("session", session)); using var file = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None); using var handler = new HttpClientHandler { CookieContainer = cookies }; using var client = new HttpClient(handler) { BaseAddress = AoCUrl }; using var response = await client.GetAsync($"{year}/day/{day}/input"); using var stream = await response.Content.ReadAsStreamAsync(); await stream.CopyToAsync(file); } }

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

    InfluxDB logo
NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts

  • Ask HN: How do I get better at programming as a hobbyist?

    1 project | news.ycombinator.com | 23 Apr 2024
  • What Happens After Agile Dies?

    1 project | dev.to | 11 Apr 2024
  • When was the last time you used this? - Part 2: Algorithms

    1 project | dev.to | 28 Mar 2024
  • 2023, a year in images

    1 project | dev.to | 8 Mar 2024
  • Having a Game I'm into Makes Every Day Enjoyable

    1 project | news.ycombinator.com | 24 Dec 2023