Skip to content

Instantly share code, notes, and snippets.

View plembo's full-sized avatar

Phil Lembo plembo

View GitHub Profile
@plembo
plembo / backup-gitlab-repos.md
Last active March 19, 2020 18:27
Backup gitlab repos

Backup Gitlab Repositories

This is a quick and dirty script I came up with for a singular purpose: Back up my own repos on Gitlab to a directory on my home server. The idea is to preserve project files somewhere, independent of where they might live on the cloud.

Some will question the lack of any error handling and the cowardly use of shell commands, and rightly so. But this is a work in progress. Stay tuned for improvements!

My Gitlab API private token is currently set as an environment variable in my home directory (not the best security, for sure).

I only wrote this because I couldn't find anything better that I could grok (which is a progressively lowering bar).

See the docs for python-gitlab for more in-depth. FYI, this is an entirely different library from gitlab. Install python-gitlab with pip install python-gitlab (or sudo pip3 python-gitlab if you're on a Linux distro like Ubuntu and

@plembo
plembo / gitpython-clone-git.md
Last active September 19, 2024 02:17
Clone git repo using GitPython

Git clone using GitPython

In general, I find GitPython's doc to be difficult to parse, mostly because the examples are written in the same kind of manpage notation that gave me a steep learning curve back when I was first learning Unix.

After searching for awhile, I found this page of the doc that tries to show how to clone a remote repo:

https://gitpython.readthedocs.io/en/stable/tutorial.html#examining-references

I didn't find it that obvious, and had to do some trial and error in the python shell before I got it right.

Here's an actual working example you can try:

@plembo
plembo / embed-crypt-rclone.md
Last active April 25, 2025 17:05
Embedding an encrypted folder with rclone

Embedding an encypted folder with rclone

There are many use cases for rclone. Mine was to "sync" with my "free" 15 GB Google Drive on Linux. While most of my files aren't particularly sensitive, there are a number that are. Until recently, I encrypted these manually using 7-zip. The problem with that was having to decrypt manually every time I wanted to look at them.

The Problem

Rclone has an encryption overlay that can be used to encrypt either a single folder or all folders in a configured remote (a networked storage system like Google Drive, OneDrive, AWS S3 or GCS). Setting it up is pretty easy, but an unintended consequence not discussed in any of the many tutorials on rclone encryption is that if your encrypted folder is a folder on an already existing remote (which is my preferred setup), using sync on the whole remote will remove the unencrypted files in the local copy of the folder and replace them with encrypted files.

The Solution

The solution to this conundrum isn't

@plembo
plembo / r-install-bionic.md
Last active March 26, 2020 14:50
Installing R on Ubuntu LTS

Installing R on Ubuntu LTS

The version of R that ships with Ubuntu 18.04 LTS (Bionic), 3.4.4, is perfectly fine for many projects.

But to get the latest R binaries and packages from CRAN (Comprehensive R Archive Network) without having to mess around with static binaries and source, you'll need to add their apt repo:

https://cloud.r-project.org/bin/linux/ubuntu/README.html

This repo does not include all the packages you might need, so CRAN recommends adding this PPA from Michael Rutter:

https://launchpad.net/~marutter/+archive/ubuntu/c2d4u3.5

@plembo
plembo / win10-corrupt-reg-audio-drivers.md
Last active July 14, 2023 00:26
Corrupted registry borks audio on Windows 10

Corrupted registry borks audio on Windows 10

WARNING: Proceed with caution, or at least in the presence of a former desktop engineer having 25 years or so of experience with Windows systems (like a Windows NT 3.51 era MCSE).

My son the game developer tried using a (very) old Logitech eyeball webcam on Windows 10 yesterday. After plugging it in he obediently rebooted when prompted by the O/S.

This, it turns out, was a mistake.

For the next couple of hours we struggled mightily with the system to get audio working again. Initially, Device Manager barked "Code 39" when we examined each audio device (Realtek HD, a USB mic and NVIDIA card audio). After several attempted re-installs and upgrades of drivers for each device (my erroneously diagnosing the problem as having to do with outdated Realtek audio drivers), he found a couple of links that provided a way out that didn't involve re-imaging the machine.

Windows Core Isolation

@plembo
plembo / ubuntultsdesknetplannm.md
Last active April 23, 2022 04:46
Ubuntu LTS Desktop with netplan and NetworkManager

Ubuntu LTS Desktop with netplan and NetworkManager

Until recently, I was happily running netplan and networkd on my personal Ubuntu 18.04 LTS Desktop, pretty much identical to the way things are set up on my server machines (except with those I start with a minimal setup using the Ubuntu Server iso).

Then something Gnome Shell-related came along that required NetworkManager. Turns out that when it comes to network status, the only piece of software the Gnome Shell can work with is NetworkManager. Thanks, freedesktop.org!

But the good news was that Canonical's netplan can work just just as well with NetworkManager as it can with networkd. https://netplan.io/examples.

Of course it can.

All I had to do was:

@plembo
plembo / SetDefAudioInUbuntu1804.md
Last active May 3, 2025 15:21
Set the default audio device(s) in Ubuntu 18.04 LTS

Setting the default audio device in Ubuntu 18.04 LTS

The problem: When you log in, Gnome picks whatever it damn pleases to make the active audio device(s). In my situation this was a little used but electrically problematic (bad grounding caused it to introduce an annoying hum) Dell Sound Bar. I fiddled with the gui interfaces (both Gnome's built-in and the add-on pavucontrol), with no success.

NOTE: No longer using this as I've moved on to Ubuntu 22.04 with pipewire. I'm back to working with pavucontrol to try keeping things under control.

Some brief notes to bring together what I've personally found to work.

@plembo
plembo / DisableMFAForAADUser.md
Last active April 24, 2025 01:36
Disable MFA for an individual Azure AD User

Disabling MFA for an Azure AD User

Azure AD MFA is not enabled by default for AAD and Microsoft 365 users, but it will be if during setup an admin chooses to Enable Security Defaults on Azure AD (as most will when prompted to do so: after all, who in their right mind wouldn't require MFA?).

However, there are situations where being able to toggle MFA on or off for a particular user can be useful. For example, in a development or test tenant when working with sample code from Microsoft that doesn't account for MFA (like a simple Microsoft Graph console app). This procedure involves disabling Security Defaults on AAD.

@plembo
plembo / ga-a320m-s2h-lmsensors.md
Last active April 29, 2024 16:18
Gigabyte GA-A320M-S2H motherboard and lm_sensors

Gigabyte GA-A320M-S2H motherboard and lm_sensors

This motherboard appears to use the ITE IT8686E super I/O controller for temperature and other sensors.

"Out of the box", lm_sensors on Ubuntu 18.04.4 LTS does not detect any sensors.

While the it87 driver required to address ITE controllers is included in the latest kernels, the version shipped for Ubuntu does not support the IT8686.

But forcing modprobe to use the id 0x8628 does return results, albeit mislabeled (none of the temps reported are labelled as cpu, but it it looks like temp1 is a match for the overall CPU temp).

Therefore, to enable support on Ubuntu 18.04.4 LTS:

@plembo
plembo / PythonReadingEnvFile.md
Last active May 4, 2023 23:16
Python reading .env file

Reading a .env file in Python

The os.environ.get method is usually what I used to read configuration information in the system environment, including secrets, in my python scripts. But sometimes (like during testing) it's convenient to use a local file instead. That's where the python-dotenv library comes in handy.

The library leverages os.environ.get to load variables from a .env file like the system loads them from .profile or .bashrc (in Unix-like systems). By default dotenv looks for the .env file in the same directory as the running program. Note: Always remmember to exclude it from your repo by adding ".env" to your .gitignore. Github's own sample Python.gitignore already does that.

Install: