Skip to content

Instantly share code, notes, and snippets.

@ktlim
ktlim / LogRedirect.py
Last active Jun 26, 2019
Log to Jupyter cell
View LogRedirect.py
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 Jun 26, 2019
Log to Jupyter widget
View LogWidget.py
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 Oct 29, 2015
Change in-file notices to new, shorter form.
View copyfix.pl
#!/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) {