Skip to content

Instantly share code, notes, and snippets.

@DamnedFacts
DamnedFacts / MagnetURLHandler.scpt
Created May 15, 2013 20:56
This AppleScript runs a handler script that responds to the "magnet:" URL. It will read in the passed URL, execute a shell script to parse the relevant content and save a torrent file into a directory specified by watch_dir property. The variable magnet_script is a terse embedded bash script that quickly parses the URL and writes the torrent fil…
(*
Copyright (c) 2013, Richard Emile Sarkis <[email protected]>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
# Quick 2-liner that sets a mail log to check, searches the log for a postfix-style mail ID (in field #6)
# then uses xargs to grep that same log again to pull out all instances of that mail ID.
# A great way to get context on how a particular mail log entry is behaving if you don't know its mail ID or if there are
# multiple IDs to content with, but one easily searchable attribute (like a from or to address)
# Warning: not intended to be scalable for very large mail logs!
MAILFILE="/var/log/mail.log"
grep -i "from=<[email protected]>" ${MAILFILE} | grep -v "NOQUEUE" | awk '{ print $6 }' | sed 's/://g' | xargs -I % grep % ${MAILFILE}
@DamnedFacts
DamnedFacts / argumentor.py
Last active February 4, 2021 19:38 — forked from Ed-von-Schleck/gist:6391140
Generating a Command Line Interface from Function Definitions. Source link: https://tech.pro/tutorial/1548/generating-a-command-line-interface-from-function-definitions
import sys
if sys.version_info.major != 3 or sys.version_info.minor < 3:
print("This module requires Python version 3.3 or later")
sys.exit(1)
import argparse
import inspect
class Argumentor:
@DamnedFacts
DamnedFacts / gist:6688802
Created September 24, 2013 18:00
Read stdin and colorize Python code in RTF format, and copy to OS X Pasteboard
pygmentize -O style=solarizeddark,fontface="Source Code Pro for Powerline:45" -l python -f rtf | pbcopy
@DamnedFacts
DamnedFacts / mailtest.py
Created December 9, 2013 21:11
Test SASL Auth with mail server easily. This is was created for use with a postfix server.
#!env python
import smtplib
import getpass
server = smtplib.SMTP('localhost', 25)
server.set_debuglevel(1)
server.ehlo()
server.starttls()
server.ehlo()
usernm = raw_input("*** Username: ")
@DamnedFacts
DamnedFacts / ldap_groups.patch
Last active January 9, 2020 16:27
A patch for MoinMoin 1.9 that implements Wiki group lookups through LDAP. Derived from source: https://moinmo.in/Groups2009
diff -rupN a/MoinMoin/auth/ldap_login.py b/MoinMoin/auth/ldap_login.py
--- a/MoinMoin/auth/ldap_login.py 2013-10-16 15:46:01.000000000 -0400
+++ b/MoinMoin/auth/ldap_login.py 2014-02-06 14:40:32.526635988 -0500
@@ -41,26 +41,18 @@ class LDAPAuth(BaseAuth):
name = 'ldap'
def __init__(self,
- server_uri='ldap://localhost', # ldap / active directory server URI
- # use ldaps://server:636 url for ldaps,
- # use ldap://server for ldap without tls (and set start_tls to 0),
@DamnedFacts
DamnedFacts / gist:9f58fb8bba2d2b9b1928
Last active August 29, 2015 14:01
A one-liner for searching Maildirs for a particular strings over a particular date range.
# Change {0,0} to pick the relative date range to search, i.e. {3,5} searches 3-5 days ago.
# Change <hostname> to be the base name used in naming your Maildir files
for i in {0..0}; do find . -name \*<hostname>\* -mtime $i -exec grep -m1 -Hi "^Subject:" {} \; ; done
@DamnedFacts
DamnedFacts / gist:67e6ccbdd70fc59ea6ba
Created May 16, 2014 23:20
A natural sort using Collections
import re,collections
def sort_naturally(l):
""" Sort the given list in the way that humans expect.
"""
convert = lambda text: int(text) if text.isdigit() else text
alphanum_key = lambda key: [convert(c) for c in re.split('([0-9]+)', key[0])]
l.sort( key=alphanum_key )
return l
collections.OrderedDict(sort_naturally(a_dict.items()))
@DamnedFacts
DamnedFacts / gist:2ef7e5a9ff5a359fc89f
Created May 19, 2014 21:46
Trick to execute Bash scripts line-by-line
#!/usr/bin/env bash
set -x
trap read debug
< YOUR CODE HERE >
function cd {
if [ -f "$1" ]; then
# Sometimes I drag-n-drop files onto the terminal because it's easy
# so I can 'cd <filename>' and have it cd to the parent directory of that file
builtin cd "`dirname \"$1\"`"
elif [ $# == 0 ]; then
# If a virtualenv is activated then a no-parameter 'cd' will take you
# to the virtualenv root.
if [ -n $VIRTUAL_ENV ]; then
builtin cd $VIRTUAL_ENV