Skip to content

Instantly share code, notes, and snippets.

@amantix
amantix / Program.cs
Created October 3, 2024 16:10
Simple web api example using aspnet core
using Microsoft.AspNetCore.Mvc;
namespace WebApplication1;
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
@amantix
amantix / Program.cs
Created October 3, 2024 16:06
Simple web api using HttpListener
using System.Net;
using System.Text.Json;
namespace HttpListenerApplication;
class Program
{
private record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
{
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
static void LinqObj76()
{
var goods = ReadItems<Item>("goods.txt");
var prices = ReadItems<Cost>("prices.txt");
var result = goods
.GroupJoin(prices, g => g.Article, p => p.ItemArticle,
(g, p) => p.DefaultIfEmpty().Select(y => new {g.Country, y?.ShopName, y?.Price}))
.SelectMany(x => x)
.GroupBy(x => x.Country)
@amantix
amantix / LinqBegin54.cs
Created March 27, 2018 17:58
Left outer join
public static void LinqBegin54()
{
IEnumerable<string> a
= new[] {"AA", "B21", "A32", "VS", "S", "AAA"};
IEnumerable<string> b
= new[] {"B2", "BSS3", "AD6", "SSS"};
/*
var result =
a.GroupJoin(b, x => x[0], x => x[0],
@amantix
amantix / permutation.cs
Created February 26, 2018 11:14
Read names (lines of text) from text file, permute them and write result to another text file.
using System;
using System.Collections.Generic;
using System.IO;
namespace AssignmentRandomizer
{
class Program
{
static void Main()
{
@amantix
amantix / ConsoleGameEngine.cs
Last active April 5, 2023 13:19
Пример того, как можно реализовывать консольную игру. Показаны самые основы на примере перемещающейся собачки по нажатию стрелок на клавиатуре. Escape - выход.
using System;
using System.Diagnostics;
using System.Threading;
namespace ConsoleGame
{
class Program
{
public class At
{
<!DOCTYPE HTML>
<html>
<head>
<script>
function WebSocketTest()
{
if ("WebSocket" in window) {
report("WebSocket поддерживается вашим браузером!");
// Открыть WebSocket
var ws = new WebSocket("ws://localhost:8080");
using System;
using System.Net;
using System.Net.WebSockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace WebTest
{
class Program
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<div id="infoPane" />
<script>
var infoPane = document.getElementById('infoPane');
var report = function (msg) {
using System;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace WebTest
{
class Program
{
static void Main(string[] args)