Skip to content

Instantly share code, notes, and snippets.

@thelinuxkid
thelinuxkid / subprocess_stream.py
Last active December 4, 2023 06:43
Get a Python subprocess' output without buffering. Normally when you want to get the output of a subprocess in Python you have to wait until the process finishes. This is bad for long running processes. Here's a way to get the output unbuffered (in real-time.)
import contextlib
import subprocess
# Unix, Windows and old Macintosh end-of-line
newlines = ['\n', '\r\n', '\r']
def unbuffered(proc, stream='stdout'):
stream = getattr(proc, stream)
with contextlib.closing(stream):
while True:
out = []
@thelinuxkid
thelinuxkid / 99-tmux-ssh.sh
Last active December 18, 2015 15:28
Automatically open tmux when ssh'ing into a server if the LC_TMUX variable has been set by the ssh client, e.g., ssh -o SendEnv=LC_TMUX user@server. If a session does not exist then a new one is created. Otherwise, the last session is attached. This should always be run last either in .bashrc or as a script in .bashrc.d. The user is logged out f…
# This script should be the last one run in .bashrc.d. Run if
# the LC_TMUX variable has been set by the ssh client, e.g.,
# ssh -o SendEnv=LC_TMUX user@server.
if [[ -z "$TMUX" ]] && [[ -n "$LC_TMUX" ]]; then
tmux has-session &> /dev/null
if [ $? -eq 1 ]; then
exec tmux new
exit
else
exec tmux attach
!/bin/sh
# WARNING: this script is unfinished.
# With this script you don't have to keep third-packages in your repo.
# You just run it when you need to install, update or remove dependencies.
# Call it like:
# dependencies install < packages.dep
# where packages.deb is a file that looks like:
@thelinuxkid
thelinuxkid / go-manager.sh
Created October 21, 2014 16:55
Minimalistic Go package manager
!/bin/sh
# WARNING: this script is unfinished.
# With this script you don't have to keep third-packages in your repo.
# You just run it when you need to install, update or remove dependencies.
# Call it like:
# dependencies install < packages.dep
# where packages.deb is a file that looks like:
ipfs:
image: jbenet/go-ipfs
container_name: ipfs_daemon
ports:
- "5001:5001"
- "4001:4001"
volumes:
- ./data/ipfs:/data/ipfs
registry:
image: thelinuxkid/registry

Keybase proof

I hereby claim:

  • I am thelinuxkid on github.
  • I am thelinuxkid (https://keybase.io/thelinuxkid) on keybase.
  • I have a public key whose fingerprint is 675C 176D 14A7 7E52 294D 579C D021 FE8F C82A D747

To claim this, I am signing this object:

@thelinuxkid
thelinuxkid / newrelic-re-enable-dynamic.sh
Last active December 12, 2016 03:29
Enable dynamic method lookup for New Relic in Swift
#!/bin/bash
# Enable dynamic method lookup for Swift as explained here:
# https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile-ios/install-configure/enabling-swift-interaction-traces
srcdir="$1"
if [ -z "$srcdir" ]; then
echo Please provide a source directory;
exit 1;
fi
info - Generating static pages (1/1)
info - Finalizing page optimization
Page Size First Load JS
┌ λ / 11.8 kB 368 kB
├ └ 80.202101.52cc03.chunk.css 10.3 kB
├ /_app 0 B 196 kB
├ λ /[seoPageLevel1] 255 B 280 kB
├ λ /[seoPageLevel1]/[seoPageLevel2] 261 B 280 kB
├ λ /[seoPageLevel1]/[seoPageLevel2]/[seoPageLevel3] 264 B 280 kB