Skip to content

Instantly share code, notes, and snippets.

@thomaswilley
thomaswilley / gist:d15aa6c65fbaa130b8e46c6d247df7c3
Created September 19, 2023 22:04
One-liner to get python root packages from pip, for a cleaner requirements.txt
pip freeze | cut -d= -f1 | while read pkg; do pip show "$pkg" | grep "Required-by:" | awk -v pkgname="$pkg" -F': ' '!$2 {print pkgname}'; done
@thomaswilley
thomaswilley / gist:cd23db295f118b1596c0547a5cb098e1
Created September 19, 2023 02:56
Enable WSL2 Host access from any device on the local network [via SSH tunnel] (e.g., for x-device testing, etc)

WSL2 host access for local development & testing from other devices in the LAN

1. Get some input info

Get the ip address of the wsl2 host. Note: worth considering if you have multiple, to do a wsl --shutdown && wsl to clean it up, and also set the preferred host/distro directly using wsl (see: wsl --help about setting defaults).

Anyway, to get that ip (note the -I and not the -i):

@thomaswilley
thomaswilley / checkswap.sh
Created December 8, 2022 02:11
quick bash script to explain what's using swap (all credits included)
#!/bin/bash
# Get current swap usage for all running processes
# Erik Ljungstrom 27/05/2011
# Modified by Mikko Rantalainen 2012-08-09
# Pipe the output to "sort -nk3" to get sorted output
# Modified by Marc Methot 2014-09-18
# removed the need for sudo
SUM=0
OVERALL=0
@thomaswilley
thomaswilley / .sh
Last active February 14, 2021 05:17
1-liner to generate arbitrary number of random alphanumeric chars.
# generate 5000 chars
tr -dc A-Za-z0-9 </dev/urandom | head -c 5000 ; echo ''
# WSL2_PORT_FORWARDING.ps1
# This script created by Brian Ketelsen (https://www.brianketelsen.com/blog/ssh-to-wsl2/
# and trivially patched by Thomas Willey 12/2020
# PURPOSE: Enable local development in WSL2 and expose webservers/services over IP from w/in WSL2 to local network of windows machine
# Use example scenario:
# 1. open WSL2, start server (e.g., python3 http.server 0.0.0.0:8000), and try to visit from win machine (e.g., http://localhost:8000) - notice it fails to resolve.
# 2. open powershell as administrator and run this script
# 3. refresh the page on your win machine's browser (http://localhost:8000) and see that it loads up.
# 4. bonus: mDNS should work. So you can access from e.g., your phone on local wifi to http://<windows hostname>.local:8000
@thomaswilley
thomaswilley / gist:f6716d960364879635825e5831fb2341
Created October 12, 2020 01:39
Get NICE DCV client (dcvviewer) working on ubuntu 20.04
```txt
- download old libssl1.0 from https://packages.ubuntu.com/bionic/libssl1.0.0
- follow the steps on this gist [https://gist.github.com/thomaswilley/1f109a3936990ac48326faf0fd917c24] to retrieve the needed files from "data.tar.xz"
- figure out where libssl1.1* got installed
$ dpkg -L libssl1.1
# on my system I see:
# /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1
# /usr/lib/x86_64-linux-gnu/libssl.so.1.1
- figure out where dcvviewer is keeping its sort of 'local' libraries (so we don't have to make this old ssl globally available)
$ dpkg -L nice-dcv-viewer
@thomaswilley
thomaswilley / gist:1f109a3936990ac48326faf0fd917c24
Last active October 12, 2020 01:39
How to edit .deb packages in debian/ubuntu (example from getting NICE DCV to work on 20.04)
# unpack the package
ar x nice-dcv-viewer_2020.1.1545-1_amd64.ubuntu1804.deb
# untar the control info
xz -d control.tar.xz
tar xf control.tar
# edit control (replace libssl dependency with "libssl1.1 (>= 1.0.2~beta3)"
vim control # make those edits ^
# tar up the control info
tar c postinst postrm shlibs triggers md5sums control | xz -c > control.tar.xz
# repackage the package (this time replacing 1804 w/2004)
@thomaswilley
thomaswilley / .vimrc
Created April 5, 2020 00:22
wsl vimrc
inoremap kj <Esc>
syntax enable
let g:solarized_termcolors=16
set t_Co=16
set background=light
colorscheme solarized
set lines=40
set columns=80
@thomaswilley
thomaswilley / gist:ac0df1c1473f1454dd3a614c015b1d4c
Last active April 8, 2020 09:26
Zero to rotating cube in opengl / glut
$ git clone https://git.samba.org/samba.git
$ brew install jansson
$ brew install readline && brew link --force readline
$ cpan # then w/in cpan install Parse::Yapp module (might be 'install Term::Parse::Yapp')
$ brew intsall libarchive
$ export LDFLAGS="-L/usr/local/opt/libarchive/lib"
$ export CPPFLAGS="-I/usr/local/opt/libarchive/include"
$ ./configure --prefix=/opt/samba --without-ad-dc --without-acl-support