Skip to content

Instantly share code, notes, and snippets.

View ab's full-sized avatar

Andy Brody ab

View GitHub Profile
# Colorizes the output of the standard library logger, depending on the logger level:
# To adjust the colors, look at Logger::Colors::SCHEMA and Logger::Colors::constants
require 'logger'
class Logger
module Colors
VERSION = '1.0.0'
NOTHING = '0;0'
@EBNull
EBNull / relations.py
Created August 17, 2011 19:21
Returns all foreign key relations to a django model and their accessors
#Some utilities to work with django models and foreign keys.
#Especially useful for finding (and writing out) code to illuminate information about relations.
#
#To try it out, run show_relation_accessors(model) in a python prompt, or to be more general, get_related_instance_ids_code(model)
#
#-2011 CBWhiz
#
#
#Usage sample:
# from django.db import transaction
@rustymyers
rustymyers / postflight
Created September 26, 2011 16:04
CreateUserLion fix for ARD
#!/usr/bin/python
#
# Payload free package to create a user on a 10.7 system.
import sys
import os
import re
import time
import subprocess
@zed
zed / urllib2_ssl.py
Created November 8, 2011 05:09
SSL client/server certificates verification for `urllib2`. :python:ssl:
"""SSL client/server certificates verification for `urllib2`.
It works on Python 2.6, 2.7, 3.1, 3.2
It also works on Python 2.4, 2.5 if `ssl` is installed (``pip install ssl``)
Example::
>>> import urllib2, urllib2_ssl
>>> opener = urllib2.build_opener(urllib2_ssl.HTTPSHandler(
... key_file='clientkey.pem',
#!/usr/bin/python
import os
import subprocess
import sqlite3
desktop_picture_path = '/Library/Desktop Pictures/Wave.jpg'
database_location = os.path.expanduser(
'~/Library/Application Support/Dock/desktoppicture.db')
@kergoth
kergoth / trap-set-e-test.sh
Last active June 22, 2023 16:33
Experimental verbose set -e handler for both bash and non-bash cases, with example use of BASH_ARG & BASH_ARGV. I realize enabling extdebug for an exceptional case isn't efficient, but I wanted sane example usage of those variables, so here it is.
#!/bin/sh
. $(dirname "$0")/trap.sh
set -e
foo () {
bar "$@" alpha beta
}
@eighthave
eighthave / find-https-debian-archives.py
Last active May 26, 2024 03:45
Script to find official Debian mirrors that support HTTPS
#!/usr/bin/env python3
import urllib.request
import re
import ssl
import sys
# # find generic mirrors
mirrors = urllib.request.urlopen('http://www.debian.org/mirror/list')
https = []
@sodabrew
sodabrew / ec2_vpc.rb
Created December 16, 2013 21:34
Add EC2 VPC facts to Facter 1.7, drop this file into `/etc/facter/facts.d/`
require 'facter/ec2'
# We might be in a VPC, which fails the normal EC2 MAC address checks
if !Facter.value('ec2_instance_id') && Facter.value('virtual') =~ /xen/ && Facter::Util::EC2.can_connect?(0.2)
Facter.debug "This is an EC2 VPC instance"
metadata
userdata
# vpc-id is in a newer metadata api rev than the usual EC2 facts
Facter.add(:ec2_vpc_id) do
#!/usr/bin/env ruby
#
# Syncs Ruby binstubs for ruby-communal-gems.
# Run this everytime you install a new Ruby, or when you install a new gem
# with a bin/ command. (ie, when you typically do rbenv rehash)
#
# See: https://github.com/tpope/rbenv-communal-gems/issues/5
#
require 'fileutils'
#!/usr/bin/env python
import imaplib
import os
import logging
import optparse
# LABEL = 'support'
# QUERY = 'before:2015-06-01 -label:to-delete'
# DEST = 'to-delete'
LABEL = 'to-delete'