Skip to content

Instantly share code, notes, and snippets.

View cinhtau's full-sized avatar

Tan-Vinh Nguyen cinhtau

View GitHub Profile
@cinhtau
cinhtau / purge-config.sh
Created April 30, 2017 08:18
Purge configuration from removed packages in Debian/Ubuntu
sudo dpkg --purge $(dpkg --list | grep ^rc | awk '{ print $2; }')
# alternative
# dpkg --list | grep '^rc\b' | awk '{ print $2 }' | xargs sudo dpkg -P
@cinhtau
cinhtau / convert-resize-image.sh
Created May 28, 2017 12:49
Resize images with ImageMagick for srcset usage for Responsive Designs/Images
#!/usr/bin/env bash
if [ ! $# == 1 ]; then
echo "Missing input param, file name."
exit 1;
fi
sizes=(1280 1024 640 320)
# make sizes readonly
declare -r sizes
@cinhtau
cinhtau / upgrade-deb-playbook.yml
Created February 3, 2018 14:18
Playbook for upgrading my Raspberry Pi Cluster with Raspbian Stretch Lite
---
- hosts: pi-cluster
tasks:
- ping: ~
- name: Update repositories cache
apt:
update_cache: yes
- name: Upgrade all packages to the latest version
apt:
name: "*"
@cinhtau
cinhtau / reindex.py
Created February 5, 2018 16:03
Simple Reindex script using the Elasticsearch Reindex API, loop over a month, for each day print respective index and create target index for reindex. The target index has only 1 shard.
import requests
from datetime import timedelta, date
def daterange(start_date, end_date):
for n in range(int ((end_date - start_date).days)):
yield start_date + timedelta(n)
headers={'Content-Type', 'application/json'}
base_url='http://elasticsearch:9200'
@cinhtau
cinhtau / host_inventory.py
Created February 15, 2018 13:52
Read yaml in python with PyYAML, install requirements with pip, hosts.yml contains some ip addresses of dns servers, perform a nslookup on the ip
#!/usr/bin/python
import yaml
def read_hosts_file(file):
try:
stream = open(file, 'r')
hosts = yaml.load(stream)
return hosts
except IOError:
@cinhtau
cinhtau / decision-server.sh
Last active February 16, 2018 11:44
Bash script for RiskShield Decision Server, use it as template 😉 License=https://choosealicense.com/licenses/mit/
#!/usr/bin/env bash
STAGE="test"
CHANNEL="issuing"
RSS="/opt/RiskShield/Resources/RS-Server/$CHANNEL/$STAGE/current"
jdbc="/opt/RiskShield/Resources/JDBC/ojdbc6.jar"
JMS="/opt/RiskShield/Resources/JmsQueue"
# works with symlink
RSH="/opt/RiskShield/$CHANNEL/$STAGE/DecisionServer"
@cinhtau
cinhtau / data-server.sh
Last active February 16, 2018 11:44
Bash script for RiskShield Data Server, use it as template 😉 License=https://choosealicense.com/licenses/mit/
#!/usr/bin/env bash
STAGE="test"
CHANNEL="issuing"
RSS="/opt/RiskShield/Resources/RS-Server/$CHANNEL/$STAGE/current"
jdbc="/opt/RiskShield/Resources/JDBC/ojdbc6.jar"
# works with symlink
RSH="/opt/RiskShield/$CHANNEL/$STAGE/DataServer"
GCLOG="/var/log/RiskShield//$CHANNEL/$STAGE/cur/data_server_gc-$(date +'%Y%m%d%H%M').log"
@cinhtau
cinhtau / boc.sh
Last active February 16, 2018 11:43
Bash script for RiskShield Backoffice Component, use it as template 😉 License=https://choosealicense.com/licenses/mit/
#!/usr/bin/env bash
# ---------------------------------------------------------------------------------------------
# Batch file to start the RiskShield Back Office Component (BOC)
# ----------------------------------------------------------------------------------------------
export LANG="en_US"
STAGE="test"
CHANNEL="issuing"
@cinhtau
cinhtau / elastic-download.yml
Last active May 2, 2018 09:45
Ansible playbook to download Elasticsearch, Kibana and the commercial X-Pack extension. Usually needed for safe-guarded environments. The download could utilize checksum, but currently elastic provides `sha512` and ansible only `sha256` and `sha1`.
# Download playbook for Elasticsearch
---
- hosts: localhost
connection: local
vars:
version: 6.2.4
target_dir: /home/tan/downloads
elastic_base_url: https://artifacts.elastic.co/downloads
@cinhtau
cinhtau / logrange-copy.sh
Created February 26, 2018 10:52
Copies all log files for a specific date range to another directory
#!/usr/bin/env bash
#
# Usage: logrange-copy.sh myApp 2017-10-17 /srv/nas/logs/myApp/
# param 1: myApp is a prefix and has multiple folders
# param 2: 2017-10-17 the upper range for daily iteration
# param 3: target directory to copy the files, could also be AWS S3
#
# program is used to copy jboss logs for reindexing with elasticsearch
# used for logstash
#