Skip to content

Instantly share code, notes, and snippets.

View zkan's full-sized avatar
🐻
Stay Hungry. Stay Foolish.

Kan Ouivirach zkan

🐻
Stay Hungry. Stay Foolish.
View GitHub Profile
@zkan
zkan / airflow_json_variables.py
Created April 30, 2021 05:42 — forked from kaxil/airflow_json_variables.py
Using Airflow Json Variables
from airflow.models import Variable
# Common (Not-so-nice way)
# 3 DB connections when the file is parsed
var1 = Variable.get("var1")
var2 = Variable.get("var2")
var3 = Variable.get("var3")
# Recommended Way
# Just 1 Database call
# -*- coding: utf-8 -*-
from airflow.operators.http_operator import SimpleHttpOperator
from airflow.operators.postgres_operator import PostgresOperator
from airflow.operators.dummy_operator import DummyOperator
from airflow.hooks.postgres_hook import PostgresHook
from airflow.models import Variable, DAG
from datetime import date, datetime, timedelta
@zkan
zkan / big_dag_example.py
Created March 21, 2021 00:43 — forked from turbaszek/big_dag_example.py
Sample big dag
import random
from airflow.operators.dummy_operator import DummyOperator
from airflow.models import DAG
from airflow.utils.dates import days_ago
with DAG(
"big_dag",
start_date=days_ago(1),
schedule_interval=None,
@zkan
zkan / datasourcetocsv_operator.py
Created February 21, 2021 09:03 — forked from ganapathichidambaram/datasourcetocsv_operator.py
Airflow - Postgresql DataSource to CSV export
from airflow.hooks.postgres_hook import PostgresHook
from airflow.models import BaseOperator
from airflow.utils.decorators import apply_defaults
from datetime import datetime, timedelta
from os import environ
import csv
class DataSourceToCsvOperator(BaseOperator):
"""
@zkan
zkan / heart.py
Last active February 14, 2021 15:38 — forked from gatukgl/heart.py
Drawing heart with turtle in Python
import turtle
turtle.pensize(3)
def draw_heart_curve():
for i in range(200):
turtle.right(1)
turtle.forward(1)
turtle.color("pink", "pink")
@zkan
zkan / check_multiple_strings_in_another_string.py
Last active January 19, 2021 05:02
Check if multiple strings exist in another string
key = 'process-id and depapi-endpoint'
def check1(key):
if 'process-id' in key or 'source-path' in key or 'depapi-endpoint' in key:
return True
def check2(key):
matches = [

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)
@zkan
zkan / circleci-trigger-jobs.sh
Created April 19, 2020 15:56
CircleCI trigger jobs script
# https://circleci.com/docs/2.0/api-job-trigger/
function trigger_job() {
job_name=$1
curl --user ${CIRCLE_API_TOKEN}: \
--data build_parameters[CIRCLE_JOB]=$job_name \
--data revision=$CIRCLE_SHA1 \
https://circleci.com/api/v1.1/project/github/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/tree/$CIRCLE_BRANCH
}
@zkan
zkan / release.sh
Created April 2, 2020 08:28
Release script to WordPress.org
#!/bin/sh
# The script updates the Wordpress.org SVN repository after pushing
# the latest release from Github
# Credit: https://guh.me/how-to-publish-a-wordpress-plugin-from-github
# Semantic Versioning: http://semver.org/
GITHUB_PLUGIN_NAME=woocommerce-cart-count-shortcode
WP_PLUGIN_NAME=woo-cart-count-shortcode
BASE_DIR=`pwd`
@zkan
zkan / alter_athena_table.sh
Last active January 7, 2020 01:53
Change the location for the Athena table
ALTER TABLE pw_accounts_accountstatuslogentry SET LOCATION 's3://data-swarm/pronto-world/prontoworlddb/accounts_accountstatuslogentry';