Skip to content

Instantly share code, notes, and snippets.

#! /usr/bin/env python
import MySQLdb
host = "localhost"
passwd = ""
user = "root"
dbname = "mydbname"
db = MySQLdb.connect(host=host, user=user, passwd=passwd, db=dbname)
cursor = db.cursor()
@centum
centum / yaml_ordered_dict.py
Last active August 29, 2015 14:26 — forked from enaeseth/yaml_ordered_dict.py
Load YAML mappings as ordered dictionaries
import yaml
import yaml.constructor
try:
# included in standard lib from Python 2.7
from collections import OrderedDict
except ImportError:
# try importing the backported drop-in replacement
# it's available on PyPI
from ordereddict import OrderedDict
@centum
centum / docker-sentry.sh
Created April 9, 2019 14:48
Start sentry by docker image
#!/bin/bash
set -e
IMG=${SENTRY_IMAGE:-'sentry:9.0'}
if [ "${1:0:1}" = '-' ] || [ "$1" = "" ]; then
CMD="uwsgi"
ARGS=$@
@centum
centum / tokens.md
Created December 4, 2019 08:52 — forked from zmts/tokens.md
Про токены, JSON Web Tokens (JWT), аутентификацию и авторизацию. Token-Based Authentication

Про токены, JSON Web Tokens (JWT), аутентификацию и авторизацию. Token-Based Authentication

Last major update: 21.10.2019

Основы:

Аутентификация(authentication, от греч. αὐθεντικός [authentikos] – реальный, подлинный; от αὐθέντης [authentes] – автор) - это процесс проверки учётных данных пользователя (логин/пароль). Проверка подлинности пользователя путём сравнения введённого им логина/пароля с данными сохранёнными в базе данных.

Авторизация(authorization — разрешение, уполномочивание) - это проверка прав пользователя на доступ к определенным ресурсам.

Например после аутентификации юзер sasha получает право обращатся и получать от ресурса "super.com/vip" некие данные. Во время обращения юзера sasha к ресурсу vip система авторизации проверит имеет ли право юзер обращатся к этому ресурсу (проще говоря переходить по неким разрешенным ссылкам)

@centum
centum / sign.py
Last active March 4, 2020 09:18
Make sign data by MD5
from hashlib import md5
def sign(status, addr, value, txid, apiKey):
return md5("{}{}{}{}{}".format(status, addr, value, txid, apiKey)).hexdigest()
if __name__ == "__main__":
print(sign(
2,

Kafka 0.11.0.0 (Confluent 3.3.0) added support to manipulate offsets for a consumer group via cli kafka-consumer-groups command.

  1. List the topics to which the group is subscribed
kafka-consumer-groups --bootstrap-server <kafkahost:port> --group <group_id> --describe

Note the values under "CURRENT-OFFSET" and "LOG-END-OFFSET". "CURRENT-OFFSET" is the offset where this consumer group is currently at in each of the partitions.

  1. Reset the consumer offset for a topic (preview)
@centum
centum / commands.sh
Created May 21, 2020 13:16
Kafka commands
# Install Java
brew tap homebrew/cask-versions
brew tap adoptopenjdk/openjdk
brew cask install java
java --version
# Get Kafka
wget https://www2.apache.paket.ua/kafka/2.5.0/kafka_2.12-2.5.0.tgz
# Unpack
@centum
centum / custom_keys_git_ssh
Created June 20, 2020 18:52 — forked from vhermecz/custom_keys_git_ssh
Allow configuring multiple ssh deploy keys with git
#!/bin/bash
# Script to use custom ssh keys for various git repositories
# Run without arguments to get usage info.
#
# How it works:
# When used with SSH, git sends the path to the repository in the SSH command.
# @see: https://github.com/git/git/blob/e870325/connect.c#L1268
# We extract this info and search for a key with the name.
# Based on the source, this seems to be used format since v2.0 at least.
# @see: https://github.com/git/git/commit/a2036d7
@centum
centum / .bashrc
Created June 20, 2020 19:45
Multiple repositories github deployment ssh keys
# Github deploy keys
export GIT_SSH_COMMAND=~/.ssh/git-keys/repo-ssh-custom-key.sh
export GIT_SSH_COMMAND_DEBUGLOG=~/.ssh/git-keys/repo-ssh-custom-key.log
@centum
centum / mk_gif.py
Created October 3, 2022 12:48
Make animated gif from images
from PIL import Image
DURATION = 1000 # ms
im_list = [
Image.open(f)
for f in [
"center.jpeg",