Skip to content

Instantly share code, notes, and snippets.

View johnliu55tw's full-sized avatar

John Liu johnliu55tw

View GitHub Profile
#!/usr/bin/env python3
import subprocess
# Need VPN to get this image
image = 'registry.suse.de/suse/containers/suse-microos/5.2/containers/suse/sle-micro-rancher/5.2:latest'
def get_zypper_packages(dockerfile):
with open(dockerfile, 'r') as f:
@johnliu55tw
johnliu55tw / test_utils.py
Created January 11, 2019 01:41
Utility functions for testing Python importability
import sys
import shutil
import tempfile
from os.path import dirname as p_dirname
from os.path import join as p_join
from types import GeneratorType
import unittest
import mock

The symbol of connman services

  • * favorite (saved) network
  • A autoconnectable
  • O online
  • R ready

If no letter is shown in the O/R column, the network is not connected.

A network is in state 'ready' once it has obtained an IPv4 or IPv6 address or both. The addresses can be acquired via DHCPv4 or DHCPv6, IPv6 address autoconfiguration, IPv4 link local assignment or statically configured for IPv4 or IPv6. A network is in state 'online' if ConnMan has verified connectivity to Internet, i.e. it has managed to look up and connect to ipv4.connman.net or ipv6.connman.net. For all practical purposes 'ready' and 'online' are usually equivalent for the intended connectivity experience. The 'ready' state gives and indication that the network might need a proxy set up to get connected from a company intranet, airport WiFi or similar. In the worst case the network really has limited outside connectivity for one or another reason.

@johnliu55tw
johnliu55tw / tips_and_commands.md
Last active August 30, 2018 03:23
Useful Tips/Commands/...

Change the passphrase of a private RSA/DSA key

$ ssh-keygen -p -f ~/.ssh/id_rsa

Full system backup/restore

Refer to Rsync#Full_system_backup for details.

Backup

@johnliu55tw
johnliu55tw / first_time_setup.sh
Created August 16, 2018 06:22
The attempt to replace First Time Setup with shell script.
#!/bin/bash
SCRIPT_NAME="first_time_setup.sh"
info() {
printf -- "$SCRIPT_NAME INFO: $*\n" >&2
}
error() {
printf -- "$SCRIPT_NAME ERROR: $*\n" >&2
@johnliu55tw
johnliu55tw / FullSystemBackupRestore.md
Created May 28, 2018 16:07
Full system backup/restore

Full System Backup and Restore

Refer to Rsync#Full_system_backup for details.

Backup

# rsync -aAXv --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} / /path/to/backup/folder
@johnliu55tw
johnliu55tw / asynchronously.py
Created April 18, 2018 13:20
Fetch track name and its artist from several track IDs using asyncio.
import time
import asyncio
import aiohttp
TOKEN = 'Your access token here'
async def fetch_track(track_id):
"""Async. fetch track data using a track ID."""
@johnliu55tw
johnliu55tw / synchrounously.py
Created April 18, 2018 12:03
Fetch track name and its artist from several track IDs.
import time
import requests
TOKEN = 'Your access token here'
def fetch_track(track_id):
"""Fetch track data using a track ID."""
resp = requests.get(
@johnliu55tw
johnliu55tw / mp3_player.py
Last active April 10, 2018 04:35
Python MP3 player powered by madplay
import logging
import select
import signal
import pty
import os
logger = logging.getLogger(__name__)
@johnliu55tw
johnliu55tw / pty_fork_test.py
Last active April 7, 2018 06:58
Testing pty.fork()
import pty
import time
import os
import sys
pid, fd = pty.fork()
if pid == 0:
# Child process
while True: