Skip to content

Instantly share code, notes, and snippets.

@rca
rca / fsm.py
Last active September 29, 2023 16:41
Python Finite State Machine implementation; logic mostly extracted from https://github.com/kmmbvnr/django-fsm
"""
Finite State Machine
This FSM implementation is extracted from the django-fsm package and licensed
under the same BSD-like license at:
https://github.com/kmmbvnr/django-fsm/blob/master/LICENSE
Basic usage:
@rca
rca / ssh.sh
Last active December 27, 2015 19:49
ssh aliases
# Copyright (c) 2007, Roberto Aguilar <roberto@baremetal.io>
# All rights reserved.
#
# Redistribution and use of this software in source and binary forms, with or
# without modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
@rca
rca / openldap_passwd.py
Last active January 21, 2022 14:00
Python hashing and test functions for user passwords stored in OpenLDAP.
#!/usr/bin/env python
"""
http://www.openldap.org/faq/data/cache/347.html
As seen working on Ubuntu 12.04 with OpenLDAP 2.4.28-1.1ubuntu4
Author: Roberto Aguilar <roberto@baremetal.io>
"""
import hashlib
import os
On etcd server:
```
[berto@scratch]$ pgrep -l -f etcd
30453 /usr/bin/etcd -n scratch.vb.baremetal.io -d /var/lib/etcd -s 192.168.42.143:7001 -c 192.168.42.143:4001
[berto@scratch]$ watch 'sudo ls /proc/$(pgrep etcd)/fd | wc -l'
```
On etcd client:
@rca
rca / save_requests_session.py
Created September 18, 2013 18:38
Persist a requests session between uses.
#!/usr/bin/env python
import pickle
import requests
URL = 'http://foo.com'
# create a session object
session = requests.Session()
{
'version': 1,
'disable_existing_loggers': True,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
},
},
'formatters': {
'default': {'format': '%(asctime)s %(levelname)s %(name)s.%(funcName)s %(message)s'}
@rca
rca / dump_google_group
Created August 5, 2013 19:12
Dump addresses from a google group
#!/usr/bin/env python
"""python dump_google_group [options] [groupname@mydomain.tld [filename]]
Dump addresses from a Google Group
==================================
This script allows you to easily retrieve the addresses in a Google Group. You
will need to have an administrator account for the Google Apps domain.
First, store your credentials to a file. Create the credentials file with the
@rca
rca / twitter_name.py
Created August 5, 2013 10:58
Find an available name on Twitter
#!/usr/bin/env python
"""
Find a name in Twitter's packed namespace
Type in a word like your name and get some variations.
"""
import os
import sys
@rca
rca / foo
Last active December 20, 2015 12:09
{{ salt['baremetal.ssl_cert_path'](domain) }}:
file.managed:
- contents: |
{{ domain['ssl_cert'] | indent(0) }}
@rca
rca / models.py
Created July 30, 2013 23:37
A working post_save signal handler
class Repository(BaremetalModel):
account = models.ForeignKey('Account')
url = GitURIField()
def __unicode__(self):
return unicode(self.url)
def do_something(self):
pass