Skip to content

Instantly share code, notes, and snippets.

@gitcnd
gitcnd / chatgpt_to_text.py
Last active November 9, 2024 23:09
program to read "conversations.json" export datafiles from a ChatGPT export, saving each thread into a new text file (suitable for uploading them all into a RAG AI system.)
#!/usr/bin/env python3
__version__ = '1.20241110'
"""
chatgpt_to_text.py program reads "conversations.json" ChatGPT export files,
and turns them into text files suitable for uploading into a RAG AI system.
Usage:
mkdir txt
cd txt
@gitcnd
gitcnd / ejectusb.py
Created December 4, 2022 12:33
Windows commandline to eject a USB drive
#!/usr/bin/python3
# From DOS commandline, run this as follows:-
# python3 ejectusb.py
# -or- create C:\windows\ejectusb.bat to do the above in fewer characters.
#
# From WSL bash, run it as follows:-
# cmd.exe /c start python3 C:\\windows\\ejectusb.py
# -or- create /usr/local/bin/ejectusb to do the above in fewer characters.
@gitcnd
gitcnd / get_local_addr.py
Created November 12, 2021 01:36
Returns the current IPv4 LAN (or WAN if that's the default route) IP address. Can also do IPv6 if you want (remove the ipv6=False for that)
#!/usr/bin/env python3
import errno, socket, logging # for get_local_addr
# localhost prefixes
_local_networks = ("127.", "0:0:0:0:0:0:0:1")
# ignore these prefixes -- localhost, unspecified, and link-local
_ignored_networks = _local_networks + ("0.", "0:0:0:0:0:0:0:0", "169.254.", "fe80:")
@gitcnd
gitcnd / nowrap.pl
Last active November 9, 2024 22:38
nowrap - truncates input lines longer than the current terminal width - Usage: cat somefile_with_long_lines.txt | nowrap.pl
#!/usr/bin/perl -w
use strict;
my $cols=`tput cols`; chomp $cols;
while(<>){
chompnl($_); my $l=0; my $out=''; my $ansi='';
while($_ ne '' && $l<$cols) {
if(/(.*?)(\t|\033\[[\d\;]+m)(.*)/) {