Skip to content

Instantly share code, notes, and snippets.

View tuantranf's full-sized avatar
🎯
Focusing

Tuan (Mike) Tran tuantranf

🎯
Focusing
View GitHub Profile
@tuantranf
tuantranf / create-pid-to-run-a-bash-job.sh
Created November 29, 2018 07:14
Run a shell script with pid file
#!/bin/bash
if [ ! -d "tmp" ]; then
echo "tmp not exist. Creating tmp"
mkdir -p tmp
fi
PIDFILE=tmp/run.pid
if [ -f $PIDFILE ]
then
@tuantranf
tuantranf / get-script-current-directory.sh
Created November 29, 2018 07:11
Get directory path of script
#!/bin/bash
echo "The script you are running has basename `basename "$0"`, dirname `dirname "$0"`"
echo "The present working directory is `pwd`"
@tuantranf
tuantranf / merge_multiple_pdf_page_to_1image.py
Created November 29, 2018 07:05
Merge multiple pages of PDF file to 1 image (vertical)
def pdf_to_image(self, pdf_file, image_file):
try:
images = convert_from_path(pdf_file)
# pdf has 1 page
print (len(images))
if len(images) == 1:
images[0].save(image_file)
else:
widths, heights = zip(*(i.size for i in images))
max_width = max(widths)
@tuantranf
tuantranf / merger.py
Created November 29, 2018 07:03 — forked from ericmjl/merger.py
A Python script for merging PDF files together.
"""
Author: Eric J. Ma
Purpose: To merge PDFs together in an automated fashion.
"""
import os
from PyPDF2 import PdfFileReader, PdfFileMerger
@tuantranf
tuantranf / mysql.py
Created September 17, 2018 13:50 — forked from abg/mysql.py
Run queries directly against MySQL via subprocess, rather than using MySQLdb
"""Examples fetching data from MySQL via /usr/bin/mysql"""
import subprocess
def get_innodb_log_file_size():
"""Run SELECT @@innodb_log_file_size and return the value as an integer"""
process = subprocess.Popen(['mysql', '-ss'],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
@tuantranf
tuantranf / kubeadm-install-offline.md
Last active August 15, 2019 09:13 — forked from onuryilmaz/kubeadm-install-offline.md
Offline Kubeadm install
@tuantranf
tuantranf / Dockerfile
Created July 30, 2018 17:46 — forked from kyleferguson/Dockerfile
Example Laravel deployment for Kubernetes
FROM php:7.1-apache
ADD . /var/www
ADD ./site.conf /etc/apache2/sites-enabled/000-default.conf
RUN apt-get update && apt-get install -y libmcrypt-dev mysql-client && \
docker-php-ext-install mcrypt pdo_mysql opcache && \
pecl install redis-3.1.2 && docker-php-ext-enable redis && \
a2enmod rewrite
@tuantranf
tuantranf / mkdir_p.js
Created June 13, 2018 03:28 — forked from bpedro/mkdir_p.js
nodejs implementation of recursive directory creation (https://brunopedro.com/2010/12/15/recursive-directory-nodejs/)
var fs = require('fs');
/**
* Offers functionality similar to mkdir -p
*
* Asynchronous operation. No arguments other than a possible exception
* are given to the completion callback.
*/
function mkdir_p(path, mode, callback, position) {
mode = mode || 0777;
@tuantranf
tuantranf / eb_deploy_and_notify.sh
Created March 28, 2018 16:33 — forked from ijin/eb_deploy_and_notify.sh
Deploy to Elastic Beanstalk and notify via Slack
#!/bin/bash
set -x
export SHA1=`echo ${CIRCLE_SHA1} | cut -c1-7`
export ENV=`echo $1 | rev | cut -d \- -f1 | rev`
function dd_mute() {
if [[ ${DD_MUTE_ID+x} ]]; then
echo "muting DD monitor id: ${DD_MUTE_ID}"
curl -X POST "https://app.datadoghq.com/api/v1/monitor/${DD_MUTE_ID}/mute?api_key=${DD_API_KEY}&application_key=${DD_APP_KEY}"
@tuantranf
tuantranf / circle.yml
Created March 23, 2018 22:06
Nice setup for testing using Circle CI
machine:
php:
version: 7.1.3
dependencies:
pre:
- mkdir -p ~/.composer/cache
- mkdir -p ~/.php-cs-fixer
- echo "memory_limit = 256M" > /opt/circleci/php/$(phpenv global)/etc/conf.d/memory.ini
override: