Skip to content

Instantly share code, notes, and snippets.

@rfinz
rfinz / ModelDB.py
Last active December 20, 2015 12:09
Snippet that initializes a DB with all the tables defined in a peewee ORM model... in this case "MariaModel". Add tables to the model at any point and the program should be able to set up the DB programmatically.
for t in [ name for name,c in \
inspect.getmembers(sys.modules[__name__],inspect.isclass) \
if issubclass(c, MariaModel) and not c is MariaModel]:
try:
globals()[t].create_table()
except Exception as e:
print e
@rfinz
rfinz / indicators.md
Last active January 1, 2016 12:09
Finzel Indicators, a list of personal indicators for tracking taste and lifestyle over the next indeterminate number of years.Fill out a new one before looking at any past answers.

Personal Culture:

  1. What is your favorite band?
  2. What is the genre of music you listen to most?
  3. What is your favorite pastime?
  4. How do you spend most of your free time?
  5. What is the most irksome thing in your day-to-day?
  6. What do you admire?
  7. Where do you work?
  8. Is there anywhere you'd rather work? Where?
find . -name .DS_Store -print0 | xargs -0 git rm --ignore-unmatch
git rev-list --all|tail -n1|xargs git show|grep -v diff|head -n1|cut -f1-3 -d' '
git rev-list HEAD -1 -- path/to/file # show commit hash of most recent revision of file
find /path/to/files* -mtime +5 -exec rm {} \; # delete files older than 5 days
find /path/to/files* -type d -mtime +5 -mindepth 1 -exec rm -r {} \; # delete folders older than 5 days
find ~salsa-server/.salsa.d/latest -regextype posix-egrep -regex '^TPMRO1Agile-cpdec[0-9]{3}-[0-9]{1}-[0-9]{10}-PictureDescription\.[0-9a-zA-Z]+-[0-9a-zA-Z_-]+(Response|\.txt)$' -exec cp {} /home/data/tpmdata/PD \; #find files matching regex and copy them to new folder
tar cf - /folder-with-big-files -P | pv -s $(du -sb /folder-with-big-files | awk '{print $1}') | gzip > big-files.tar.gz # see progress when compressing large data
pdftotext my.pdf - | grep 'pattern' # grep in pdf
find /path -iname '*.pdf' -exec pdfgrep pattern {} + # another grep in pdf solution using pdfgrep
for i in *.txt; do content=$(<$i); echo "{\"text\": \"${content}\"}" >> texts.jsonl; done # echo all txt files into a jsonl file
for i in *.xml; do mv $i "${i%.xml}.txt"; done # change the extension of a bunch of files (in this case xml to txt)
for i in *.txt
@rfinz
rfinz / nap.rb
Created January 12, 2016 22:22 — forked from siers/nap.rb
a more natural alarm clock command line interface
#!/usr/bin/env ruby
require 'time'
def die(str)
$stderr.puts str
exit
end
def usage
@rfinz
rfinz / DigitalOceanFreeBSDrc.subr
Created October 20, 2017 22:54
rc.subr for DO in case in gets borked in a merge
# $NetBSD: rc.subr,v 1.67 2006/10/07 11:25:15 elad Exp $
# $FreeBSD: releng/11.1/etc/rc.subr 310010 2016-12-13 04:50:45Z dteske $
#
# Copyright (c) 1997-2004 The NetBSD Foundation, Inc.
# All rights reserved.
#
# This code is derived from software contributed to The NetBSD Foundation
# by Luke Mewburn.
#
# Redistribution and use in source and binary forms, with or without
@rfinz
rfinz / send-region-to-sh.el
Created May 15, 2018 19:18
Saving a fun snippet from Stack Overflow for sending emacs regions to shell
;;;; https://stackoverflow.com/a/7053298/1096485
(defun sh-send-line-or-region (&optional step)
(interactive ())
(let ((proc (get-process "shell"))
pbuf min max command)
(unless proc
(let ((currbuff (current-buffer)))
(shell)
(switch-to-buffer currbuff)