Skip to content

Instantly share code, notes, and snippets.

View Jakub3628800's full-sized avatar
:shipit:

Jakub Kriz Jakub3628800

:shipit:
View GitHub Profile
@Jakub3628800
Jakub3628800 / make_commit.py
Created July 13, 2023 19:23
Create commit on github using github api
import requests
import argparse
import os
GH_USERNAME = "Jakub3628800"
GH_REPO = "repository123"
MAIN_BRANCH = "master"
auth_header = {
@Jakub3628800
Jakub3628800 / Example: Tuple unpacking
Created January 8, 2023 17:10
Example: Tuple unpacking
# Example 0: Unpack a tuple
weeks = ('monday', 'tuesday', 'wednesday')
first, second, third = weeks
print(first, second, third)
# monday tuesday wednesday
weeks = ('monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday')
first, second, *other = weeks
print(first, second, other)
# monday tuesday ['wednesday', 'thursday', 'friday', 'saturday', 'sunday']
# Tuples can be defined with or without brackets
weekdays = "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"
print(weekdays)
# ('monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday')
for week in weekdays:
print(week)
# monday
# tuesday
from collections import Counter
items = ["apple", "orange", "apple", "pear", "orange", "apple"]
item_counts = Counter(items)
print(item_counts)
# Counter({'apple': 3, 'orange': 2, 'pear': 1})
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Jakub3628800
Jakub3628800 / gist:50090ae1e59a8cfd771737ab3082aa2d
Created November 10, 2020 12:33 — forked from hest/gist:8798884
Fast SQLAlchemy counting (avoid query.count() subquery)
def get_count(q):
count_q = q.statement.with_only_columns([func.count()]).order_by(None)
count = q.session.execute(count_q).scalar()
return count
q = session.query(TestModel).filter(...).order_by(...)
# Slow: SELECT COUNT(*) FROM (SELECT ... FROM TestModel WHERE ...) ...
print q.count()

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)
@Jakub3628800
Jakub3628800 / curl.md
Created September 21, 2020 12:58 — forked from subfuzion/curl.md
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.