Skip to content

Instantly share code, notes, and snippets.

@ktlim
ktlim / switch-to-main.py
Last active December 15, 2021 16:32
Script to switch the default branch in all repos within a set of GitHub organizations. Requires an env var GITHUB_TOKEN that points to a file containing a PAT with admin permissions. Set REAL to True to actually change things rather than just say what would be done.
import github
import logging
import os
import re
import requests
import sys
import time
REAL = False
GITHUB_API = "https://api.github.com"
@ktlim
ktlim / LogRedirect.py
Last active June 26, 2019 18:00
Log to Jupyter cell
import os
import sys
import threading
class LogRedirect:
def __init__(self, fd=1, dest=sys.stderr, encoding="utf-8", errors="strict"):
# Save original handle so we can restore it later.
self.saved_handle = os.dup(fd)
self.saved_fd = fd
self.saved_dest = dest
@ktlim
ktlim / LogWidget.py
Created June 26, 2019 17:53
Log to Jupyter widget
import ipywidgets as widgets
import os
import sys
import threading
class LogWidget:
def __init__(self):
layout = {
'width': '100%',
'height': '160px',
@ktlim
ktlim / copyfix.pl
Last active October 29, 2015 22:50
Change in-file notices to new, shorter form.
#!/usr/bin/perl -i.bak
$skipping = 0;
while (<>) {
if ($skipping == 0 && /^(.+) Copyright /) {
print "$1 See the COPYRIGHT and LICENSE files in the top-level directory of this\n";
print "$1 package for notices and licensing terms.\n";
$skipping = 1;
}
elsif ($skipping == 1) {