Skip to content

Instantly share code, notes, and snippets.

public static class VarInt {
public static bool TryRead(ReadOnlySpan < byte > slice, out int value, out int readBytes) {
readBytes = 0;
value = 0;
var shift = 0;
while (true) {
if (readBytes >= slice.Length)
return false;
var nextByte = slice[readBytes++];
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
BenchmarkRunner.Run<BenchmarkArraySplit>();
[MemoryDiagnoser]
public class BenchmarkArraySplit
{
[Benchmark]
public string Vabka()
// And same for IQueryable
public static class EnumerableExtensions
{
public static T? SingleOrNull<T>(this IEnumerable<T> seq, Func<T, bool> predicate) where T : struct
{
var data = seq.Where(predicate).Take(2).ToArray();
if (data.Length == 2)
throw new InvalidOperationException();
if (data.Length == 0)
return null;
@vabka
vabka / test.js
Created September 24, 2021 21:57
function helloWorld() {
return "hello"
}
module ExhangeRatesAPI.Service
open ExhangeRatesAPI.Types
open ExhangeRatesAPI.Common
type Rate =
{ Left: Symbol
Right: Symbol
Value: decimal }
export class CalendarDate {
private readonly date: Date;
constructor(date: Date) {
this.date = new Date(date);
}
public static today(): CalendarDate {
return new CalendarDate(new Date());
}
type Container<T> = Readonly<{ value: T, pipe<U>(f: (value: T) => U): Container<T> }>;
class PersistentContainer<T> implements Container<T> {
private readonly _value: T;
public get value() {
return this._value;
}
constructor(value: T) {
@vabka
vabka / Tree.cs
Last active January 15, 2020 14:37
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace _
{
public sealed class Tree<TKey, TValue> : IEnumerable<KeyValuePair<TKey, Tree<TKey, TValue>.Node>>
where TKey : IEquatable<TKey>
{
@vabka
vabka / Main.cs
Created November 28, 2019 14:42
Как скачать файл при помощи puppeteersharp, чтобы он скачался в нужную папку
using System;
using System.IO;
using System.Threading.Tasks;
using PuppeteerSharp;
namespace pptrTest
{
class Program
{
static async Task Main()
@vabka
vabka / main.rs
Last active November 10, 2019 00:35
use actix_web::web::Json;
use actix_web::{get, App, HttpServer, Result};
use chrono::prelude::*;
use log::LevelFilter;
use serde::Serialize;
use std::io;
fn main() -> Result<(), io::Error> {
env_logger::builder().filter_level(LevelFilter::Info).init();
let service = HttpServer::new(|| App::new().service(today))