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
def fibonacci():
current_value, next_value = 0, 1
while True:
yield current_value
current_value, next_value = next_value, current_value + next_value
result = fibonacci()
for _ in range(10000000000000):
print(next(result))
@zkan
zkan / sentiment_analysis.py
Created February 28, 2019 12:26
Sentiment Analysis with Scikit-Learn
import pandas as pd
from sklearn.feature_extraction.text import CountVectorizer
text = [
'Promptly answer to my request.',
'great turnaround time!',
'Fast response and great service!',
'As usual you took the request and completed in as few steps as possible and well done!',
'Very quick turnaround time and great communication. Thank you!',
@zkan
zkan / create_backup.sh
Created January 3, 2020 02:20
Create backup for WordPress site (Pronto-specific)
#!/bin/bash
cp docker-compose.yml backup/
cp get-docker.sh backup/
cp uploads.ini backup/
rsync -av --delete www/ backup/www/
sudo rsync -av --delete /var/lib/docker/volumes/rocket_db_data/ backup/rocket_db_data/
@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';
@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 / 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
}

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 / 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 = [
@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 / 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):
"""