Skip to content

Instantly share code, notes, and snippets.

View cuongnv23's full-sized avatar
๐Ÿƒ

cuongnv23

๐Ÿƒ
View GitHub Profile
@cuongnv23
cuongnv23 / ansrole.sh
Last active March 10, 2016 09:57
Tiny script create ansible role dirs
#!/bin/sh
### Simple shell script to create Ansible role folders
sub_dirs="meta tasks vars handlers templates"
[ -z "$1" ] && echo "Usage: $0 your_role " && exit 1
for role in "$@"; do
@cuongnv23
cuongnv23 / ansible-linefile-endofline
Last active March 28, 2018 19:00
Ansible - Insert to end of line with lineinfile module
#handlers/main.yml
---
- name: Restart apache
service: name=apache2 state=restarted enabled=yes
tags:
- apache
#task/main.yml
---
- name: Enable apache modules
lineinfile: >
@cuongnv23
cuongnv23 / ansinit
Created May 10, 2016 14:36
ansible-playbook-init
#!/usr/bin/env bash
ANS_FILES="inventory site.yml config.yml"
ANS_DIRS="group_vars host_vars roles yml"
for f in ${ANS_FILES}; do
echo "touch ${f}"
touch ${f}
done
@cuongnv23
cuongnv23 / chiasenhac-dowloader.py
Created June 20, 2016 10:38
Python script to download mp3 files from chiasenhac.com
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import re
import argparse
import errno
import requests
from bs4 import BeautifulSoup
@cuongnv23
cuongnv23 / bobp-python.md
Created July 29, 2016 00:22 — forked from sloria/bobp-python.md
A "Best of the Best Practices" (BOBP) guide to developing in Python.

The Best of the Best Practices (BOBP) Guide for Python

A "Best of the Best Practices" (BOBP) guide to developing in Python.

In General

Values

  • "Build tools for others that you want to be built for you." - Kenneth Reitz
  • "Simplicity is alway better than functionality." - Pieter Hintjens
@cuongnv23
cuongnv23 / letsencrypt_2016.md
Created September 25, 2016 00:25 — forked from cecilemuller/letsencrypt_2020.md
How to setup Let's Encrypt for Nginx on Ubuntu 16.04 (including IPv6, HTTP/2 and A+ SLL rating)

How to setup Let's Encrypt for Nginx on Ubuntu 16.04 (including IPv6, HTTP/2 and A+ SLL rating)

There are two modes when you don't want Certbot to edit your configuration:

  • Standalone: replaces the webserver to respond to ACME challenges
  • Webroot: needs your webserver to serve challenges from a known folder.

Webroot is better because it doesn't need to replace Nginx (to bind to port 80) to renew certificates.

In the following, we're setting up mydomain.com to be served from /var/www/mydomain, and challenges will be served from /var/www/letsencrypt.

@cuongnv23
cuongnv23 / speed
Created January 5, 2017 03:39
speed script for tmux
#!/bin/bash
iface=$1
RXB=$(</sys/class/net/"$iface"/statistics/rx_bytes)
TXB=$(</sys/class/net/"$iface"/statistics/tx_bytes)
sleep 1
RXBN=$(</sys/class/net/"$iface"/statistics/rx_bytes)
TXBN=$(</sys/class/net/"$iface"/statistics/tx_bytes)
RXDIF=$(echo $((RXBN - RXB)) )
TXDIF=$(echo $((TXBN - TXB)) )
# vim:ft=ansible
- hosts: localhost
remote_user: admin
become: True
become_user: root
vars:
nginx_root_dir: "/var/www/html"
tasks:
- name: Install nginx

How to run

This app is highly recommended to run in a virtualenv.

  • Install requirements:
$ pip install -r requirements.txt
  • Run the app, this app listens on port 5000 by default, ensure port available
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>Hello World</p>'; ?>
</body>
</html>