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 / ad_utils.py
Created July 28, 2016 02:03
Get Active Directory group members using python
View ad_utils.py
#! /bin/env python
#
# USAGE
# $ python ad_utils.py "My Group Name"
#
# Author:
# Trinh Nguyen
# dangtrinhnt@gmail.com
# www.dangtrinh.com
@dangtrinhnt
dangtrinhnt / clean_comments.sh
Last active September 2, 2023 00:33
Delete all pending comment using WP-CLI
View clean_comments.sh
#! /bin/bash
for blog_path in $(wp site list --field=path)
do
path_wo_slashes="${blog_path////""}"
url="http://your.blog.address/$path_wo_slashes"
# status = approve, hold, trash, spam
tmp_ids=$(wp comment list --status=hold --format=ids --url=$url)
# clean the string
pending_ids="$(echo -e "${tmp_ids}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
@dangtrinhnt
dangtrinhnt / img_utils.python
Last active July 11, 2023 05:38
Autorotate and autoresize images in mass with Python and PIL
View img_utils.python
#!/usr/bin/env python
"""
File: autorotate.py
Origial Author: Damien Riquet <d.riquet@gmail.com>
Current Maintainer: Trinh Nguyen <dangtrinhnt[at]gmail[dot]com>
Description: This script provides an auto-rotate feature of pictures
USAGE: autorotate.py [-h] [--recursive] directory [directory ...]
positional arguments:
@dangtrinhnt
dangtrinhnt / utils.gs
Created November 19, 2014 14:10
Convert row data to dictionary using Google Apps Script
View utils.gs
function rowToDict(sheet, rownumber) {
var columns = sheet.getRange(1,1,1, sheet.getMaxColumns()).getValues()[0];
var data = sheet.getDataRange().getValues()[rownumber-1];
var dict_data = {};
for (var keys in columns) {
var key = columns[keys];
dict_data[key] = data[keys];
}
return dict_data;
}
@dangtrinhnt
dangtrinhnt / .zshrc
Created April 2, 2014 06:31
.zshrc template
View .zshrc
autoload -U compinit promptinit colors
compinit
promptinit
colors
# set completion style
export ZLS_COLORS=$LS_COLORS
zstyle ':completion:*' menu select
zstyle -e ':completion:*:default' list-colors 'reply=("${PREFIX:+=(#bi)($PREFIX:t)(?)*==34=34}:${(s.:.)LS_COLORS}")';
@dangtrinhnt
dangtrinhnt / sheet_to_dict.gs
Created September 25, 2015 09:11
Google Spreadsheet to dictionary in Google Apps Script
View sheet_to_dict.gs
// dictionary of columns (list)
// thedict = {'<col_header0>': ['<row0>','<row1>',...], '<col_header1>': ['<row0', '<row1>',...]...}
function sheet_to_dict(spreadsheetid, sheetname) {
var result_dict = {};
var dataspreadsheet = SpreadsheetApp.openById(spreadsheetid);
var sheet = dataspreadsheet.getSheetByName(sheetname);
var cols = sheet.getLastColumn();
var rows = sheet.getLastRow();
var data = sheet.getDataRange().getValues();
@dangtrinhnt
dangtrinhnt / excel_utils.py
Created August 8, 2015 00:59
Excel file to list of dictionaries in Python
View excel_utils.py
import openpyxl
import string
def index_to_col(index):
return string.uppercase[index]
def excel_to_dict(excel_path, headers=[]):
wb = openpyxl.load_workbook(excel_path)
sheet = wb.get_sheet_by_name('Sheet1')
@dangtrinhnt
dangtrinhnt / update_moodle_photo.php
Created November 19, 2015 02:00
Update moodle user's photo programmatically
View update_moodle_photo.php
#!/usr/bin/php
<?php
// USAGE:
// $ php update_moodle_photo.php <user-id-number>
//
// to be able to run this file as command line script
define('CLI_SCRIPT', true);
// include config.php from your moodle's docroot
require_once('/var/www/moodle/config.php');
@dangtrinhnt
dangtrinhnt / Dockerfile
Last active April 5, 2021 15:49
Sample Windows container Dockerfile running a Java application
View Dockerfile
FROM mcr.microsoft.com/windows/servercore:ltsc2019
# everything will be installed inside this directory inside the container
WORKDIR "C:/ProgramData"
# install chocolately package manager
RUN @powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin" -Y
RUN choco install openjdk8 -Y
RUN refreshenv
@dangtrinhnt
dangtrinhnt / Dockerfile
Created April 5, 2021 15:14
Running Selenium with Chromedriver inside Windows container
View Dockerfile
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