Skip to content

Instantly share code, notes, and snippets.

View kevinastone's full-sized avatar

Kevin Stone kevinastone

View GitHub Profile
#!/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
@kevinastone
kevinastone / staticfiles.py
Created November 18, 2020 03:27
Support for Range header requests in Starlette
import os
import re
import stat
import typing as t
from urllib.parse import quote
import aiofiles
from aiofiles.os import stat as aio_stat
from starlette.datastructures import Headers
from starlette.exceptions import HTTPException
@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 / 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
@kevinastone
kevinastone / Gruntfile.coffee
Created October 19, 2015 17:29
Gruntfile for ES6 with babel and browserify
path = require 'path'
module.exports = (grunt) ->
pkg = grunt.file.readJSON('package.json')
nodePackages = Object.keys(pkg.dependencies or {})
grunt.initConfig
pkg: pkg
@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 / 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:
x = 1
class A(object):
y = x + 1
a = A()
a.y
class A(object):
y = x + 1
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
#