Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python3
#
# Copyright (c) 2021 Jasper Lievisse Adriaanse <j@jasper.la>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
@george-hawkins
george-hawkins / wake-issue.md
Last active March 9, 2024 19:35
After installing Ubuntu 20.04 my machine frequently wakes from sleep for no obvious reason. This gist describes my attempts to resolve this.

Diagnosing spurious wakes

This gist documents my attempts to get to the bottom of spurious wakes after installing Ubuntu 20.04 LTS on my system.

Initially, I thought it might be another system on my network sending Wake-on-LAN (WoL) packets. Then I thought it might be a known XHCI spurious wake kernel issue. And lastly, I finally resolved things by actively disabling the ability of USB devices, e.g. the mouse, to wake the system.

Update: I later came up with a better way of disabling wake-on-mouse that's covered here.

Note: as one of these steps, I upgraded the system BIOS - while this didn't resolve this particular issue, it did resolve an annoying issue with the graphic state not being properly restored for certain applications after wake-up.

@gvtulder
gvtulder / encrypting-without-reinstalling-ubuntu.txt
Last active February 8, 2023 03:22
Encrypting hard drives without reinstalling Ubuntu
Encrypting hard drives without reinstalling Ubuntu
===================================================
Gijs van Tulder, 26.02.2019, last update 04.03.2019
This is a list of the steps I took to encrypt the partitions on my
Ubuntu 16.04 laptop with the LUKS encryption system. Encrypting the
partitions took some time but was relatively easy. Getting the system
to boot afterwards was a little trickier, but doable.
Obviously, these steps might not work for you. Follow them at your
@CMCDragonkai
CMCDragonkai / matplotlib_interactive_mode.md
Last active December 1, 2023 05:39
Interactive Matplotlib (while in REPL) #python #matplotlib

Interactive Matplotlib (while in REPL)

Matplotlib can be used in an interactive manner either in the REPL or as part of a script. Let's assume you're using export MPLBACKEND='Qt4Agg'.

To do this you need to switch on interactive mode:

import matplotlib.pyplot as plt
plt.ion()
@ajdruff
ajdruff / fix-git-line-endings
Last active May 28, 2024 15:15
Forces all line endings to LF in your git repo.
#####################
#
# Use this with or without the .gitattributes snippet with this Gist
# create a fixle.sh file, paste this in and run it.
# Why do you want this ? Because Git will see diffs between files shared between Linux and Windows due to differences in line ending handling ( Windows uses CRLF and Unix LF)
# This Gist normalizes handling by forcing everything to use Unix style.
#####################
# Fix Line Endings - Force All Line Endings to LF and Not Windows Default CR or CRLF
@gabrielelana
gabrielelana / Vagrantfile
Last active January 2, 2024 18:58
How to create a VirtualBox machine with encrypted storage with Vagrant
# -*- mode: ruby -*-
# vi: set ft=ruby :
PASSWORD_PATH = ".password"
PASSWORD_ID_PATH = ".password_id"
# Make sure to have installed vagrant-triggers plugin
# > vagrant plugin install vagrant-triggers
# After the first `vagrant up` stop the VM and execute the following steps
import requests
from requests.adapters import HTTPAdapter
from threading import Thread
import logging
logging.basicConfig(filename='out.txt', level=logging.DEBUG, filemode='w')
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True
@toolness
toolness / adventures-in-python-core-dumping.md
Last active May 25, 2024 04:10
Adventures in Python Core Dumping

Adventures in Python Core Dumping

After watching Bryan Cantrill's presentation on [Running Aground: Debugging Docker in Production][aground] I got all excited (and strangely nostalgic) about the possibility of core-dumping server-side Python apps whenever they go awry. This would theoretically allow me to fully inspect the state of the program at the point it exploded, rather than relying solely on the information of a stack trace.

#!/usr/bin/env python
import sys
import argparse
import sh
def check_result(ret):
if ret.exit_code != 0:
print "Command returned with value:", ret.exit_code
return False
@pombredanne
pombredanne / select_requirements.py
Created August 1, 2014 10:04
Select Python pip requirements files based on os, platform or else
#!/usr/bin/python
# #
# Copyright (c) 2014 by nexB, Inc. http://www.nexb.com/ - All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,