Skip to content

Instantly share code, notes, and snippets.

@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 / README.md
Last active Feb 25, 2022
An explanation of `git rebase --onto`
View README.md

git rebase onto fu

Looking at the following git history, there are a few commits that were accidentally made on top of env/dev-auth that should be on a feature branch named experiments/sso-login-app (1. in the command below):

[0][~/Projects/openslate/thing(env/dev-auth:feb0ee9)]
$ git log
commit feb0ee98c8b77e929b9cc23442c5664c9d4986c9 (HEAD -> env/dev-auth)  # this is `0.` in the command below
Author: Roberto Aguilar <roberto@openslate.com>
Date:   Thu Sep 26 00:25:15 2019 -0400
@rca
rca / tasks.py
Created Mar 27, 2012
break a big celery job into smaller, batched, chunks
View tasks.py
"""
Celery tasks that batch a job with many tasks into smaller work sets.
The problem I'm attempting to solve is one where a job comprised of many
tasks (say 100) will snub out a job comprised of only a few tasks (say 5). It
appears as though by default celery will queue up the second job's 5 tasks
behind the first job's 100 and it will have to wait until the first job's
completion before it even begins.
@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 / 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.
#