Skip to content

Instantly share code, notes, and snippets.

@tsvayer
tsvayer / Benchmarks.cs
Created July 18, 2021 15:21
Benchmark MaxBy
using System;
using System.Collections.Generic;
using System.Linq;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Running;
using NUnit.Framework;
namespace TestProject1
{
@tsvayer
tsvayer / ToListTakeWhile.cs
Created August 29, 2020 14:41
Veli Extensions
public static class VeliExtensions
{
public static IEnumerable<T> ToListTakeWhile<T>(this IEnumerable<T> source, Predicate<T> predicate)
{
return source.TakeWhile(item => !predicate(item));
}
}
public class VeliExtensionTests
{
# Two perfect logicians, S and P, are told that integers x and y have been chosen such that 1 < x < y and x+y < 100.
# S is given the value x+y and P is given the value xy. They then have the following conversation.
# P: I cannot determine the two numbers.
# S: I knew that.
# P: Now I can determine them.
# S: So can I.
# Given that the above statements are true, what are the two numbers?
require 'prime'
check_sum = ->(x) { (2..x / 2).any? { |a| Prime.prime?(a) && Prime.prime?(x - a) }}
build_variation = ->(x) { (2..x / 2).map { |a| [a * (x - a), x, a] }}
@tsvayer
tsvayer / docker-compose.yml
Created March 6, 2018 15:12
Docker Compose Elasticsearch cluster example (with Kibana)
version: '3.1'
services:
elasticsearch:
image: elasticsearch
container_name: elasticsearch
environment:
- bootstrap.memory_lock=true
- ES_JAVA_OPTS=-Xms512m -Xmx512m
command:
- "-Etransport.host=0.0.0.0"
@tsvayer
tsvayer / delete_archives_from_aws_glacier_vault.fish
Last active December 27, 2017 09:05
delete all archives from aws glacier vault (fish function)
# put it under ~/.config/fish/functions
function delete_archives_from_aws_glacier_vault -a ACCID VAULT
set JOBID ( \
aws glacier initiate-job \
--account-id $ACCID \
--vault-name $VAULT \
--job-parameters '{"Type": "inventory-retrieval"}' \
| jq -r '.jobId' \
)
@tsvayer
tsvayer / gist:6bb0f361803c8b434eeb
Created May 26, 2014 15:34
limit file size on windows hg commit
[hooks]
precommit.bigfile = hg diff | powershell -c "$input |?{$_.StartsWith('diff')}| %{$_.Split(' ')[3]}| %{if((gi $_).length -ge 1000000){ write-host $_ ":" (gi $_).length "bytes, must be less than 1Mb"; exit 1;}}"