Skip to content

Instantly share code, notes, and snippets.

View kevinastone's full-sized avatar

Kevin Stone kevinastone

View GitHub Profile
@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
@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 / 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 / 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:
class A(object):
y = x + 1
x = 1
a = A()
a.y
x = 1
class A(object):
y = x + 1
a = A()
a.y
#
# Author:: Adam Jacob (<adam@opscode.com>)
# Author:: Seth Chisamore (<schisamo@opscode.com>)
# 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
#