Skip to content

Instantly share code, notes, and snippets.

@AnsonT
AnsonT / dir_sizes.sh
Created February 11, 2019 18:17
Displaying directory sizes (e.g. .git, node_modules, etc)
function dir_sizes() {
find $1 -type d -name $2 -prune | while read line; do du -sh $line; done
}
alias ds=dir_sizes # ds {start_dir} {name_pattern}
# e.g. list node_modules sizes recursively
# ds . node_modules
#
# output:
@AnsonT
AnsonT / sshpass.rb
Last active March 22, 2019 18:06
SSH Brew Setup
require 'formula'
class Sshpass < Formula
url 'http://sourceforge.net/projects/sshpass/files/sshpass/1.06/sshpass-1.06.tar.gz'
homepage 'http://sourceforge.net/projects/sshpass'
sha256 'c6324fcee608b99a58f9870157dfa754837f8c48be3df0f5e2f3accf145dee60'
def install
system "./configure", "--disable-debug", "--disable-dependency-tracking",
"--prefix=#{prefix}"
@AnsonT
AnsonT / kebase.md
Created September 9, 2019 17:25
Keybase proof

Keybase proof

I hereby claim:

  • I am ansont on github.
  • I am ansont (https://keybase.io/ansont) on keybase.
  • I have a public key ASDU_EBl_KrTegICgj2_-TdmFr4RBFlsDuA6Zada0RqK3wo

To claim this, I am signing this object:

@AnsonT
AnsonT / Basic Python Notes.py
Last active October 1, 2021 16:13
Basic Python Usage Notes
# -----------------------------------------------
# Loops
# -----------------------------------------------
aList = ['apple', 'orange', 'pear']
## print all fruits
for fruit in aList:
print(fruit)
## skip 'apple'
@AnsonT
AnsonT / chat.ts
Created May 15, 2023 18:15
Stream OpenAI response though NextJS API route
import { NextApiRequest, NextApiResponse } from 'next'
import { Readable } from 'node:stream'
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const { authorization } = req.headers
if (!authorization || authorization !== process.env.AUTHORIZATION_HEADER) {
return res.status(401).json({ error: 'Unauthorized' })
}
const openAIUrl = process.env.OPENAI_URL as string
@AnsonT
AnsonT / AutoScrollList.tsx
Last active July 25, 2023 19:10
Autoscroll to last item in React-Native flat list
const AutoScrollList: FC<ListProps> = (props) => {
const listRef = useRef<FlatList>()
const [contentHeight, setContentHeight] = useState<number>()
useEffect(() => {
if (props.data?.lenngth > 0) {
listRef.current?.scrollToOffset({ offset: contentHeight })
}
}, [props.data, contentHeight])
@AnsonT
AnsonT / proxmox-create-shared-data.sh
Last active December 2, 2023 22:06
Create a Logical Volume in Proxmox for shared data between LXCs
# Create a LV-Thin volume named 'shared-data'
# Not visible in Proxmox gui
# Visibel with `lvs`
lvcreate -V 256G -n shared-data pve/data
# Create ext4 fs in the volume
mkfs.ext4 /dev/pve/shared-data
# Create directory mount point
mkdir /shared-data