Skip to content

Instantly share code, notes, and snippets.

View caseydm's full-sized avatar

Casey Meyer caseydm

View GitHub Profile
@caseydm
caseydm / gist:5096447
Last active December 14, 2015 13:49
Rails Single Table Inheritance
# model finance.rb
class Finance < ActiveRecord::Base
attr_accessible :amount, :date, :description, :type
belongs_to :users, :dependent => :destroy
end
# model income.rb
@caseydm
caseydm / gist:5149089
Last active December 14, 2015 21:09
Rails STI
# model finance.rb
class Finance < ActiveRecord::Base
# Attributes
attr_accessible :amount, :date, :description, :type
# Associations
belongs_to :users, :dependent => :destroy
@caseydm
caseydm / gist:116f1407f26ccdb88902
Created April 22, 2015 22:14
Python Management Command
from django.core.management.base import BaseCommand
from django.conf import settings
import csv
from bah_api.models import withDependents, withOutDependents, ZipMHA
class Command(BaseCommand):
def handle(self, *args, **options):
# Populate CSV file into model
def LoadCSV(file_location, my_model, delim):
f = open(file_location)
# read file
with open('names.txt') as f:
file_data = f.read()
@caseydm
caseydm / zappa_deployer.json
Created July 6, 2017 13:36
Zappa IAM Policy
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"iam:GetRole",
"iam:PutRolePolicy"
],
"Resource": [
@caseydm
caseydm / Dockerfile
Last active March 24, 2018 13:53
Docker local development
FROM python:2.7.14
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
ADD . /code/
ADD requirements /requirements
RUN pip install -r /requirements/local.txt
@caseydm
caseydm / employees.py (version 5)
Created June 29, 2020 01:31
Elasticsearch 5 to 6 upgrade
from decimal import Decimal
from django_elasticsearch_dsl import DocType, Index, fields
from record.templatetags.record_tags import currency
from .models import Employee, Jurisdiction
# Name of the Elasticsearch index
employee = Index('employees')
# See Elasticsearch Indices API reference for available settings
employee.settings(
number_of_shards=1,
@caseydm
caseydm / app.py
Last active September 27, 2021 14:48
Flask API Pagination
from flask import Flask
from flask_marshmallow import Marshmallow
from flask_sqlalchemy import SQLAlchemy
from models import Magazine
from utils import build_link_header, validate_per_page
app = Flask(__name__)
db = SQLAlchemy(app)
ma = Marshmallow(app)
@caseydm
caseydm / global_south.py
Last active June 5, 2022 20:09
global south stats from openalex api
import requests
from iso3166 import countries
GLOBAL_SOUTH_COUNTRIES = [
# source https://meta.wikimedia.org/wiki/List_of_countries_by_regional_classification
"Afghanistan",
"Algeria",
"American Samoa",
"Angola",
"Anguilla",
@caseydm
caseydm / citation_count.py
Created July 1, 2022 20:09
OpenAlex citation counts
import requests
def get_citation_counts():
# sample author
author_id = "https://openalex.org/A2151238091"
# get up to 50 works for this author
r2 = requests.get(
f"https://api.openalex.org/works?filter=authorships.author.id:{author_id}"