Skip to content

Instantly share code, notes, and snippets.

@moon03432
moon03432 / sets.py
Last active October 12, 2019 07:32
manipulate sets union / intersection
#!/usr/bin/env python3
# coding=utf-8 (for Python 2)
# return: a list of lists. inner list performs intersection, outer list performs union
# for example: [[1,2], [3,4]] means (1 ∩ 2) ∪ (3 ∩ 4)
def union(groups, operators):
if len(groups) == 1:
return [groups]
if len(groups) == 2 and len(operators) == 1:
if operators[0] == '∪':
@arkady-emelyanov
arkady-emelyanov / haproxy.cfg
Last active October 25, 2023 22:02
haproxy check: postgresql is master
# Sample haproxy postgresql master check
#
# haproxy listen: 5431
# pg, instance #1 listen: 5432 (master node)
# pg, instance #2 listen: 5433 (replica node)
# external failover, promoting replica to master in case of failure
# passwordless auth for user web
# template1 database is accessible by user web
#
# haproxy will pass connection to postgresql master node:
@r0l1
r0l1 / copy.go
Last active March 23, 2024 12:38
Copy a directory tree (preserving permissions) in Go.
/* MIT License
*
* Copyright (c) 2017 Roland Singer [roland.singer@desertbit.com]
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
@ursuad
ursuad / kafka-cheat-sheet.md
Last active March 14, 2024 10:32
Quick command reference for Apache Kafka

Kafka Topics

List existing topics

bin/kafka-topics.sh --zookeeper localhost:2181 --list

Describe a topic

bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic mytopic

Purge a topic

bin/kafka-topics.sh --zookeeper localhost:2181 --alter --topic mytopic --config retention.ms=1000

... wait a minute ...

@ato
ato / TempoDirectory.java
Created October 1, 2013 05:55
TempDirectory java temporary directory delete on exit
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
class TempDirectory {
final Path path;