Skip to content

Instantly share code, notes, and snippets.

View dangtrinhnt's full-sized avatar
😎
Busy changing the world

Trinh Nguyen dangtrinhnt

😎
Busy changing the world
View GitHub Profile
@dangtrinhnt
dangtrinhnt / Dockerfile
Created April 5, 2021 15:14
Running Selenium with Chromedriver inside Windows container
FROM mcr.microsoft.com/windows/servercore:ltsc2019
# install needed fonts for googlechrome to run properly
ADD files/fonts.tar /Fonts/
WORKDIR /Fonts/
RUN @powershell -NoProfile -ExecutionPolicy Bypass -Command ".\Add-Font.ps1 Fonts"
WORKDIR "C:/ProgramData"
# enable Web-WebSockets
@dangtrinhnt
dangtrinhnt / moodle_course_utils.php
Created August 1, 2016 08:52
Get Moodle courses by category ID
#! /usr/bin/php
<?php
define('CLI_SCRIPT', true);
/*
Author: Trinh Nguyen
Last update: August 1st, 2016
NOTES:
* Place this file inside a folder inside moodle root. E.g.g: /var/www/moodle/your-script/moodle_course_utils.php
*/
@dangtrinhnt
dangtrinhnt / googleemailscript.gs
Last active January 6, 2021 15:24
Google Apps Script to send email when submitting form
// Trinh Nguyen, Nov 18, 2014
function EmailFormConfirmation() {
// name of the response sheet
var sheetname = "sheet1"
// insert a blank column at the end of the response sheet
// store the sent mail result
// add this formula to the first row of this column:
// =indirect("AG"&counta(A1:A))
var columnnumber = 34
@dangtrinhnt
dangtrinhnt / server-vars.yml
Last active December 31, 2020 15:51
Open edX server-vars.yml variables
# variables common to the lms role, automatically loaded
# when the role is included
---
# These are variables that default to a localhost
# setup and are meant to be overwritten for
# different environments.
#
# Variables in all caps are environment specific
# Lowercase variables are internal to the role
@dangtrinhnt
dangtrinhnt / find_robot_area_bfs.py
Created December 26, 2020 11:36
Find the accessible area of a robot in a 2D graph using BFS algorithm
#! /usr/bin/env python
# Author: Trinh Nguyen (Jin)
# 12 Dec 2020
from queue import Queue
SAFE_RANGE = 23
AXIS_LEN = 1000
@dangtrinhnt
dangtrinhnt / gen_sockproxy.sh
Created May 3, 2020 14:49
Create a sock proxy at a random port that helps you to connect to a private network from your computer
#! /bin/bash
SSH_KEY=$1
BASTION_IP=$2
USERNAME=$3
PROXY_PORT=`comm -23 <(seq 13000 13999 | sort) <(netstat -tan | awk '{print $4}' | cut -d':' -f2 | sort -u) | shuf | head -n 1`
ssh -i "$SSH_KEY" -CND "${PROXY_PORT}" -q "${USERNAME}@${BASTION_IP}" &
echo "socks5://localhost:$PROXY_PORT"
@dangtrinhnt
dangtrinhnt / test-Dockerfile
Created May 10, 2020 14:04
A sample Dockerfile for testing your application
FROM python:3.7-stretch
LABEL maintainer="Trinh Nguyen <dangtrinhnt@gmail.com>"
WORKDIR /keycloak_flask
COPY . /keycloak_flask
ENV FLASK_APP=keycloak_flask.user
ENV FLASK_DEBUG=1
@dangtrinhnt
dangtrinhnt / Dockerfile
Created May 10, 2020 13:47
Sample Dockerfile to run a python application
FROM python:3.7-stretch
LABEL maintainer="Trinh Nguyen <dangtrinhnt@gmail.com>"
WORKDIR /keycloak_flask
COPY . /keycloak_flask
ENV FLASK_APP=apps.keycloak_flask.user
ENV KEYCLOAK_FLASK_SETTINGS=local_settings.py
@dangtrinhnt
dangtrinhnt / clean_all_kong_targets.sh
Created May 3, 2020 15:19
Delete all Kong targets
#! /bin/bash
# Run this script inside a bastion instance
# $1: kong address and administration port, e.g., kong.dangtrinh.com:8001
KONG_URL=$1
# get all hosts of the services
latest_hosts=( $(curl ${KONG_URL}/services | jq -r '.["data"][] | .host') )
# list all upstream names
all_upstreams=( $(curl ${KONG_URL}/upstreams | jq -r '.["data"][] | .name') )
@dangtrinhnt
dangtrinhnt / mass_scale_ecs_svc.sh
Created May 3, 2020 15:00
Scale multiple ecs services
#!/bin/bash
# service_text_file is the path to a text file that contains a list of service names, each service name is on each line
cluster=$1
service_text_file=$2
desired_count=$3
while IFS= read -r line
do
echo "$line"