Skip to content

Instantly share code, notes, and snippets.

View kevinastone's full-sized avatar

Kevin Stone kevinastone

View GitHub Profile
#
# Author:: Adam Jacob (<[email protected]>)
# Author:: Seth Chisamore (<[email protected]>)
# Copyright:: Copyright (c) 2010-2011 Opscode, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
x = 1
class A(object):
y = x + 1
a = A()
a.y
class A(object):
y = x + 1
x = 1
a = A()
a.y
@kevinastone
kevinastone / mount.sls
Created October 21, 2013 21:45
Macro for mounting devices for Salt Stack.
{% macro mount_device(app, device, dir) -%}
{{ app }}-formatted:
cmd.run:
- name: "mkfs.ext4 /dev/{{ device }}"
- unless: "file -sL /dev/{{ device }} | grep -q ext4"
{{ app }}-mounted:
mount.mounted:
@kevinastone
kevinastone / decorators.py
Created November 3, 2013 22:21
Decorator to skip functions during a test environment for python/django.
from functools import wraps
def skip_when_testing(func=None):
"""
Provides a way to provide functionality that only applies in the real production environment, otherwise stubs out the function.
Use this with **care** as this makes testability difficult and can lead to errors/bugs leaking into production. This should really only be used for non-functional (fire-and-forget) components like error logging or analytics.
"""
def wrapper(func):
@kevinastone
kevinastone / resample_crash.py
Last active December 27, 2015 08:29
Demonstration of a bug in Pandas with a Series localized to a timezone crossing a daylight savings boundary and using 'period' for resampling.
import pytz
import pandas as pd
series = pd.Series.from_csv('series_crash.csv')
# My actual data is already in UTC, but need to localize due to CSV source
series = series.tz_localize(pytz.UTC)
# Convert from UTC to Local Timezone (PST in this case)
local_timezone = pytz.timezone('America/Los_Angeles')
@kevinastone
kevinastone / workon.bash
Last active August 29, 2015 13:55
Bash function and completion script to allow quick switching between projects (especially if they share a relative virtualenv dir)
# Change this to your base projects path [$WORKON_BASE_DIR/{project1,project2,...}]
WORKON_BASE_DIR=/mnt/hgfs
# Change this to your relative virtual_env dir (if exists) [$WORKON_BASE_DIR/{project}/$VENV_DIR]
VENV_DIR=".env"
function workon() {
[ -z "$VIRTUAL_ENV" ] || deactivate
cd $WORKON_BASE_DIR/$1 &&
[ -d $VENV_DIR ] && source $VENV_DIR/bin/activate
#!/bin/bash
BASE_DIR=${TMPDIR:-/var/tmp}
ORIG_DIR=$PWD
HASH_CMD="md5sum"
DIR_NAME=`echo $PWD | $HASH_CMD | cut -f1 -d " "`
TMP_DIR=$BASE_DIR/$DIR_NAME
mkdir -p $TMP_DIR

Keybase proof

I hereby claim:

  • I am kevinastone on github.
  • I am kevinastone (https://keybase.io/kevinastone) on keybase.
  • I have the public key with fingerprint FC0C AEC9 3398 1A2D 56BF  9619 6344 9238 5969 5C55

To claim this, I am signing this object:

@kevinastone
kevinastone / migrate_branches.py
Last active August 3, 2017 15:36
Run South Migrations between Branches
#!/usr/bin/env python
import subprocess
import itertools
import sys
from south.migration import all_migrations
from south.models import MigrationHistory