Skip to content

Instantly share code, notes, and snippets.

@rca
rca / openldap_passwd.py
Last active Jan 21, 2022
Python hashing and test functions for user passwords stored in OpenLDAP.
View openldap_passwd.py
#!/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
@rca
rca / git_whitespace
Created Feb 13, 2018
get rid of whitespace in your uncommitted work
View git_whitespace
#!/usr/bin/env python2.7
"""
Ensure new lines added to git do not have whitespace
"""
import os
import sys
import time
import traceback
from optparse import OptionParser
@rca
rca / fsm.py
Last active Dec 12, 2021
Python Finite State Machine implementation; logic mostly extracted from https://github.com/kmmbvnr/django-fsm
View fsm.py
"""
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 / save_requests_session.py
Created Sep 18, 2013
Persist a requests session between uses.
View save_requests_session.py
#!/usr/bin/env python
import pickle
import requests
URL = 'http://foo.com'
# create a session object
session = requests.Session()
@rca
rca / repath_dylib.sh
Created Oct 7, 2012
Repath the references in an OS X .dylib file for packaging within an application.
View repath_dylib.sh
#!/bin/bash
# Repathing .dylib's references for packaging within an application
# Author: Roberto Aguilar <roberto.c.aguilar@gmail.com>
#
# With help from Nick Jensen's blog at:
# http://goto11.net/how-to-bundle-a-c-library-with-a-cocoa-application/
#
# All references within the dylib except ones to files in /usr/lib are
# converted over to reference the given root.
@rca
rca / gstash.sh
Created Sep 30, 2012
Git stash helper functions.
View gstash.sh
#!/bin/bash
#
# Helper functions around "git stash"
#
# Use this file by sourcing it into your shell environment. For example:
#
# source /path/to/gstash.sh
#
# Once sourced in you can run the commands:
#
@rca
rca / iso2unix.py
Created Sep 11, 2012
Convert an ISO 8601 timestamp to unix timestamp
View iso2unix.py
import calendar
from iso8601 import parse_date
def iso2unix(timestamp):
"""
Convert a UTC timestamp formatted in ISO 8601 into a UNIX timestamp
"""
# use iso8601.parse_date to convert the timestamp into a datetime object.
@rca
rca / shelltools.sh
Created Aug 21, 2012
Semi-useful Shell functions
View shelltools.sh
# Copyright (c) 2004-2008, Roberto Aguilar <berto at chamaco dot org>
# 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 / mpm_prefork.conf
Created Aug 25, 2017
MySQL and Apache configuration on a small DigitalOcean Droplet for a low-traffic Wordpress site
View mpm_prefork.conf
# /etc/apache2/mods-enabled/mpm_prefork.conf
# prefork MPM
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# MaxRequestWorkers: maximum number of server processes allowed to start
# MaxConnectionsPerChild: maximum number of requests a server process serves
<IfModule mpm_prefork_module>
StartServers 3
@rca
rca / ajax_setup.js
Created Jan 29, 2012
Setup Django CSRF token in JQuery AJAX requests
View ajax_setup.js
/**
* setup JQuery's AJAX methods to setup CSRF token in the request before sending it off.
* http://stackoverflow.com/questions/5100539/django-csrf-check-failing-with-an-ajax-post-request
*/
function getCookie(name)
{
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');