Skip to content

Instantly share code, notes, and snippets.

Извините за недоразумение. Вы правильно заметили, что вам неизвестно, легче или тяжелее фальшивая монета. Давайте попробуем другой метод:
1. Разделите 12 монет на три группы по 4 монеты.
2. Первое взвешивание:
- Взвесьте две из этих трех групп. Если они весят одинаково, перейдите к шагу 3.
- Если одна из групп легче, перейдите к шагу 4.
3. Возьмите оставшиеся 4 монеты (2 из каждой из первых двух групп) и разделите их на две группы по 2 монеты. Сравните их вес.
Для решения этой головоломки можно использовать следующий метод:
1. Разделите 12 монет на три равные группы по 4 монеты.
2. Первое взвешивание:
- Взвесьте две из этих трех групп. Если они весят одинаково, перейдите к шагу 3.
- Если одна из групп легче, то одна из четырех монет в этой группе фальшивая. Перейдите к шагу 3.
3. Возьмите три монеты из группы, в которой была обнаружена фальшивая монета. Пометьте их как A, B и C.
@icu0755
icu0755 / gist:e5886653c3d1a7e699b69ea298cdb218
Created August 21, 2023 09:43
Sort and limit mongo collection by parent docs then add corresponding children docs
[
{
'$match': {
'app': 'nametestsig',
'lang': 'en',
'label_name': '',
'label_value': '',
'content_id': {
'$ne': '0'
}
@icu0755
icu0755 / nginx.conf
Created August 11, 2023 05:45
nginx responding hello nginx with max throughput
user www-data;
worker_processes 8;
error_log off;
pid logs/nginx.pid;
events {
worker_connections 4096;
use epoll;
}
@icu0755
icu0755 / benchmark_latency.sh
Created August 9, 2023 16:19
bash script that runs wrk2 against url with rate parameter from 1000 to 20000. The output is a table rate vs latency
#!/bin/bash
# Check if wrk2 is installed
if ! command -v wrk2 &> /dev/null; then
echo "wrk2 is not installed. Please install it: https://github.com/giltene/wrk2"
exit 1
fi
# Check if an argument (URL) is provided
if [ -z "$1" ]; then
If your Docker containers cannot connect to each other using public IP addresses and there's a firewall on the host machine, there are several factors you should consider:
1. **Docker Networking**: Docker containers are typically assigned private IP addresses by Docker's internal networking system. Directly using public IP addresses to communicate between containers is not the usual practice. Docker containers are designed to communicate with each other using internal IP addresses, service names, or Docker's internal DNS.
2. **Firewall Rules**: If there's a firewall on the host machine, you need to ensure that the required ports for communication between containers are open. By default, Docker uses various ports for communication, and if those ports are blocked by the firewall, communication between containers might be affected.
3. **Docker Network Configuration**: Ensure that your containers are connected to the same Docker network if you want them to communicate with each other. Docker provides bridge ne
@icu0755
icu0755 / benchmark.sh
Created August 9, 2023 15:30
Below is an example of a Bash script that takes a URL as input and uses the wrk2 tool to run benchmarking against that URL. Please make sure you have wrk2 installed on your system before using this script.
#!/bin/bash
# Check if wrk2 is installed
if ! command -v wrk2 &> /dev/null; then
echo "wrk2 is not installed. Please install it: https://github.com/giltene/wrk2"
exit 1
fi
# Check if an argument (URL) is provided
if [ -z "$1" ]; then
<!DOCTYPE html>
<html>
<head>
<!--Import Google Icon Font-->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!--Import materialize.css-->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<!--Let browser know website is optimized for mobile-->
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
@icu0755
icu0755 / reinstall.log
Last active July 7, 2020 19:59
force reinstall python mysqlclient
$ ./manage.py showmigrations --settings=mashup.settings.prod
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/vladimir/PycharmProjects/buzzhearts/env27/lib/python2.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/Users/vladimir/PycharmProjects/buzzhearts/env27/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute
django.setup()
File "/Users/vladimir/PycharmProjects/buzzhearts/env27/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
@icu0755
icu0755 / brief.md
Created August 4, 2018 07:48
Purelab Task Vladimir Ivanov

The solution is good enough for data.txt provided. In production there can be the way larger files, thus I would implement a generator that reads an input file in chunks and returns tokens that can be accumulated in a hash table instead of keeping everything in the memory.