Skip to content

Instantly share code, notes, and snippets.

View mstefarov's full-sized avatar

Matvei Stefarov mstefarov

View GitHub Profile
[MediumRunJob]
[MemoryDiagnoser]
public class StringDictBench
{
System.Collections.Generic.Dictionary<ReadOnlyMemory<char>, string> mem = new();
System.Collections.Generic.Dictionary<string, string> str = new();
string key = "key";
public StringDictBench()
{
[MediumRunJob]
[MemoryDiagnoser]
public class ToTest
{
Dictionary<string,IntPtr> stringKeys = new();
Dictionary<TileKey,IntPtr> structKeys = new();
public ToTest()
{
for (int x = -4; x < 5; x++)
@mstefarov
mstefarov / ReplaceCrs84WithEpsg4326.cs
Last active May 1, 2018 00:17
Example how ArcGISHttpClientHandler.HttpRequestBegin event can be used to rewrite WMS requests.
private static void ReplaceCrs84WithEpsg4326(object sender, HttpRequestMessage e)
{
string rawQuery = e.RequestUri.Query;
// Skip requests without a query
if (string.IsNullOrEmpty(rawQuery))
return;
// For convenience, parse query as a Dictionary
var queryParameters = System.Web.HttpUtility.ParseQueryString(rawQuery);
// Redirects requests to a given file
class FileBasedHttpResponder : HttpClientHandler
{
private readonly FileInfo _targetFileInfo;
public FileBasedHttpResponder(string targetPath)
{
_targetFileInfo = new FileInfo(targetPath);
}
var op = new SphereDrawOperation(player);
op.Brush = new NormalBrush(new Block[]{ fillBlockHere });
op.Prepare(marksArrayHere);
op.Begin();
// Copyright 2013 Matvei Stefarov <me@matvei.org>
using System;
using JetBrains.Annotations;
using RgbColor = System.Drawing.Color;
namespace fCraft.Drawing {
/// <summary> Represents a palette of Minecraft blocks,
/// that allows matching RGB colors to their closest block equivalents. </summary>
public class BlockPalette {
<?xml version="1.0" encoding="utf-8"?>
<fCraftAutoRank>
<!-- Each <Criterion> tag is a rule. Either short or fully-qualified rank names can be used.
This example automatically promotes players from builder to veteran rank if
they meet either of the two condition sets. -->
<Criterion fromRank="builder#mTaSFlmnBk1QYVqN" toRank="veteran#yuSfyiJ7AvuE0nc8">
<!-- Tags like <OR>, <AND>, <NOR>, and <NAND> logically combine conditions.
In this example, two alternative sets of conditions are grouped with <AND>.
These groups are then combined by <OR>, which will trigger the promotion
if either of the condition sets is met. -->
public static void takeVote()
{
World[] voteWorlds = PropHuntWorlds.OrderBy(x => randWorld.Next())
.Take(3)
.ToArray();
NewVote();
Server.Players.Message("&S--------------------------------------------------------------");
Server.Players.Message("Vote for the next map!");
Server.Players.Message("&S/Vote &c1&S for {0}&S, &c2&S for {1}&S, and &c3&S for {2}",
// step 1: find index of largest value
// If there is a tie, the last of the tied worlds will be chosen
World chosenWorld;
int maxVotes = int.MinValue, i = 0;
foreach (int votes in voteList) {
if ((chosenWorld == null) || (votes > maxVotes)) {
maxVotes = votes;
chosenWorld = worldList[i];
}
i++;
public static void main(String[] args) { //1. main method. In the main program declare a Scanner variable that is hooked up to System.in.
//You need to include the line of code import java.util.Scanner; at the top of your program. Pass the Scanner object you create as a
//parameter to any methods that need it.
//The main method should not have a lot of statements, instead it shall call other methods.
RockPaperScissors();
}
public static void RockPaperScissors() {
System.out.println("Welcome to Rock Paper Scissors. I, Computer, will be your opponent.");