Skip to content

Instantly share code, notes, and snippets.

View bryant1410's full-sized avatar

Santiago Castro bryant1410

View GitHub Profile
bryant1410 / etserver
Created May 8, 2023 17:47
System V init script for an EternalTerminal server (place under `/etc/init.d`)
View etserver
#!/usr/bin/env bash
# chkconfig: 35 90 12
# description: EternalTerminal server
# Get function from functions library
. /etc/init.d/functions
start() {
bryant1410 /
Created March 13, 2022 18:14
LaTeX style for Matplotlib in Google Colab
# First: sudo apt install cm-super dvipng texlive-latex-extra texlive-latex-recommended texlive-science
import matplotlib as mpl
import matplotlib.pyplot as plt
plt.rcParams["text.usetex"] = False # True # It looks better with the default font.
mpl.rcParams["text.latex.preamble"] = (r"\usepackage{siunitx}"
r" \sisetup{detect-all}"
r" \usepackage{helvet}"
r" \usepackage{sansmath}"
bryant1410 /
Last active April 26, 2022 06:31
Quick workaround to change PyCharm's remote terminal width
# See
width = 215; print("Terminal width:", width)
if sys.stdout.isatty():
import fcntl, struct, sys, termios; fcntl.ioctl(sys.stdin, termios.TIOCSWINSZ, struct.pack("HHHH", 0, width, 0, 0))
else: # In case it's not remote.
import os; os.environ["COLUMNS"] = str(width) # It doesn't work everywhere, but it's something.
os.environ["LINES"] = "21" # Some programs need both env vars set for any to work.
bryant1410 /
Created April 13, 2020 04:54
Script to change the terminal width (passed by arg) from Python.
#!/usr/bin/env python
"""Script to change the terminal width (passed by arg) from Python."""
import argparse
import fcntl
import struct
import sys
import termios
from array import array
from typing import IO
bryant1410 /
Created February 20, 2020 01:54
Find any commit from any repo for a given author and between given dates
#!/usr/bin/env bash
for d in ~/repos/*; do
pushd "$d" > /dev/null
if [ -d .git ]; then
echo $d
echo "branch $(git rev-parse --abbrev-ref HEAD)"
git --no-pager log --color=always --all --oneline --graph --decorate --after 2019-04-20 --before 2019-05-15 --author='Santiago Castro'
popd > /dev/null
#!/usr/bin/env python
import argparse
import heapq
def parse_args():
parser = argparse.ArgumentParser(description="Analyze bashstart log for speed.")
parser.add_argument('filename', help="often /tmp/bashstart.<PID>.log")
parser.add_argument('-n', default=20, help="number of results to show")
return parser.parse_args()
View conda-python
#!/usr/bin/env bash
set -e
if [[ $# -eq 0 ]]; then
echo "Illegal number of arguments. Usage: ${0} env_name_or_prefix [args]..."
exit 2
import time
import torch
import torch.nn as nn
from apex.normalization import FusedLayerNorm
torch.backends.cudnn.benchmark = True
bryant1410 /
Last active November 20, 2018 18:25
This script is a workaround to refresh the snaps under a NFS /home directory with root_squash option (the default).
#!/usr/bin/env bash
# This script is a workaround to refresh the snaps under a NFS /home directory with root_squash option (the default).
# Note that using no_root_squash is insecure.
# The bug was already filed:
set -ex
bryant1410 /
Created June 14, 2018 18:06
Load protobuf in tensorboard
# import tensorflow as tf
# from tensorflow.python.platform import gfile
# with tf.Session() as sess:
# model_filename ='aaa.pb'
# with gfile.FastGFile(model_filename, 'rb') as f:
# graph_def = tf.GraphDef()
# graph_def.ParseFromString(
# g_in = tf.import_graph_def(graph_def)
# LOGDIR='logsst2'
# train_writer = tf.summary.FileWriter(LOGDIR)