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 / gist:92520a990c9503b7718d9b7e281a1838
Created June 29, 2019 02:04 — forked from loisaidasam/gist:2774350
One liner for counting unique IP addresses from nginx logs
# One liner for counting unique IP addresses from nginx logs
# Feel free to comment with better ideas - I'm sure it's not the best way of doing this (I'm no awk ninja!)
#
# Sample output:
#
# $ cat example.com.access.log | awk -F " " '{a[$1]++ } END { for (b in a) { print b, "\t", a[b] } }'
# 66.65.145.220 49
# 92.63.28.68 126
cat example.com.access.log | awk -F " " '{a[$1]++ } END { for (b in a) { print b, "\t", a[b] } }'
@tuantranf
tuantranf / pytest-enable-click-enable-clirunner-to-show-stdout-stderr.md
Created June 28, 2019 07:49
Pytest - Click - Enable CliRunner to echo output to stdout/stderr

Enable CliRunner to echo output to stdout/stderr

Workaround

Referrence pallets/click#737

import functools
import pytest
@tuantranf
tuantranf / configmap-recursive-directories-support.md
Last active June 25, 2019 07:36
A workaround solution for ConfigMap recursive directory issues
@tuantranf
tuantranf / README.md
Created June 19, 2019 09:51 — forked from dannguyen/README.md
Using Python 3.x and Google Cloud Vision API to OCR scanned documents to extract structured data

Using Python 3 + Google Cloud Vision API's OCR to extract text from photos and scanned documents

Just a quickie test in Python 3 (using Requests) to see if Google Cloud Vision can be used to effectively OCR a scanned data table and preserve its structure, in the way that products such as ABBYY FineReader can OCR an image and provide Excel-ready output.

The short answer: No. While Cloud Vision provides bounding polygon coordinates in its output, it doesn't provide it at the word or region level, which would be needed to then calculate the data delimiters.

On the other hand, the OCR quality is pretty good, if you just need to identify text anywhere in an image, without regards to its physical coordinates. I've included two examples:

####### 1. A low-resolution photo of road signs

@tuantranf
tuantranf / check-if-user-is-root.go
Created May 28, 2019 07:00
check if user is root
package helpers
import (
"os/exec"
"strconv"
)
sub func02 {
my ( $a, $b ) = @_;
if ( $a eq 'g' ) {
if ( $b eq 'c' ) {
print "win";
} elsif ( $b eq 'p' ) {
print "lose";
} else {
print "draw";
@tuantranf
tuantranf / Readme.md
Last active December 11, 2018 10:32
Laravel mysql docker composer template

Laravel mysql docker composer template

  1. Make docker directory inside your application directory
  2. Save docker-compose.yml, app.dockerfile, nginx.conf to docker directory
  3. Change directory to dockder
  4. docker-composer up
@tuantranf
tuantranf / docker-network-inspection.md
Created December 11, 2018 10:28
Inspect a docker network

Docker network inspection

➜  docker git:(master) ✗ docker network ls
NETWORK ID          NAME                         DRIVER              SCOPE
4333e0dd52ab        bridge                       bridge              local
81f9dfb35871        docker_default               bridge              local
a95912ab4a52        host                         host                local
02cc13496457        hsbc-poc-cron_default        bridge              local
5ad54ece802f        hsbc-poc_default             bridge              local
@tuantranf
tuantranf / install-composer.sh
Created December 7, 2018 08:06
Composer installation shell script for Mac OS
#!/usr/bin/env bash
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '93b54496392c062774670ac18b134c3b3a95e5a5e5c8f1a9f115f203b75bf9a129d5daa8ba6a13e2cc8a1da0806388a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
mv composer.phar /usr/local/bin/composer
echo "Composer installation finished."
// replace your-folder below with the folder for which you want a listing
function listFolderContents() {
var id = 'xxxxx';
var folders = DriveApp.getFolderById(id).getFolders()
Logger.log(folders);
while (folders.hasNext()) {
var folder = folders.next();
Logger.log(folder.getName());
var contents = folder.getFiles();