Skip to content

Instantly share code, notes, and snippets.

View gigkokman's full-sized avatar

Songkran Nethan gigkokman

View GitHub Profile
@gigkokman
gigkokman / get_nested_value.py
Last active November 9, 2020 14:14
Python function get dictionary's value from nested with dot annotation key
from functools import reduce
def get_nested_value(nested_dict, str_key):
"""
Get value from nested-dict via dot-annotation key
Parameters:
nested_dict: dict
str_key: str
Example:
@gigkokman
gigkokman / jq csv with header
Created March 17, 2020 01:29
Export json to csv with header via jq script
echo '{"a":"aa", "b":"bb"}' | jq -r -s '. | (map(keys) | add | unique) as $cols | map(. as $row | $cols | map($row[.])) as $rows | $cols, $rows[]'
@gigkokman
gigkokman / storageclass.yaml
Last active December 19, 2018 10:14
Fixed "pod has unbound PersistentVolumeClaims" cause of pod status pending
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: standard
provisioner: docker.io/hostpath
@gigkokman
gigkokman / elasticsearch-reindex-api-request
Created August 31, 2018 03:30
Reindexing Elasticsearch for daily indices
POST _reindex
{
"source": {
"index":"test_fields-*",
"_source": {
"includes": ["field1", "field2"]
}
},
"dest": {
"index": "test_fields"
Using git rebase first
```git rebase -i --root```
And then mark all commit that you want to change it's author with "edit" and run
```git commit --amend --author "New Author Name <email@address.com>" --no-edit && \
git rebase --continue```
@gigkokman
gigkokman / Python logging for Kafka
Created July 24, 2017 05:06
Python logging for Kafka
import logging
import sys
logger = logging.getLogger('kafka')
logger.addHandler(logging.StreamHandler(sys.stdout))
logger.setLevel(logging.DEBUG)
@gigkokman
gigkokman / fixing-failed-building-psycopg2-mac
Last active September 20, 2019 19:19
Failed building wheel for psycopg2 <ld: library not found for -lssl> with pip
``` ld: library not found for -lssl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command 'clang' failed with exit status 1```
Point LDFLAGS to OpenSSL's lib & include directories
```env LDFLAGS="-L$(brew --prefix openssl)/lib" CFLAGS="-I$(brew --prefix openssl)/include" pip install -r environments/development.txt```
org.elasticsearch.common.netty.handler.codec.frame.TooLongFrameException: HTTP content length exceeded 104857600 bytes.
Update: I increased size in /etc/elasticsearch/elasticsearch.yml and it works again
# Set a custom allowed content length:
#
http.max_content_length: 500mb
# /etc/sysctl.conf
# set swap to 1k
```vm.swappiness = 1```
# reload config
```sysctl -p /etc/sysctl.conf```
# check config
```cat /proc/sys/vm/swappiness```
@gigkokman
gigkokman / es_setting_default_field.txt
Created August 13, 2015 08:00
Error: IndexPattern's configured pattern does not match any indices [Solved]
## Kibana Discover tab show error:
Error: IndexPattern's configured pattern does not match any indices
Solved:
Setting index.query.default_field to _all
1. Close index
POST <index>/_close
2. Setting default_field
PUT <index>/_setting
{"index.query.default_field" :"_all"}