This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Load this in a Rails console session with: | |
# play ~/Desktop/reflect_on.rb | |
def reflect_on(clazz) | |
result = { | |
column_names: clazz.column_names.sort, | |
associations: clazz.reflect_on_all_associations.map(&:name).sort, | |
class_methods: clazz.methods().find_all do |m_sym| | |
m = clazz.method(m_sym) | |
m.source_location && m.source_location[0].include?('/app/') | |
end.sort, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import click | |
import json | |
@click.command() | |
@click.argument("input_source", type=click.File("rt")) | |
def flatten(input_source): | |
""" | |
Creates a flattened representation of a BigQuery JSON schema. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# ----------------------------------------------------------------------------- | |
# A jq filter that converts an array objects with a nested array into | |
# CSV-formatted output with one row for each of the nested arrays and the | |
# common from the parent object duplicated. | |
# ----------------------------------------------------------------------------- | |
jq -r '.Items[] | {"Sku": .Sku} + (.Locations[]|{"WarehouseCode": .WarehouseCode, "LocationCode": .LocationCode, "Quantity": .Quantity}) | ["\(.Sku)", "\(.WarehouseCode)", "\(.LocationCode)", .Quantity] | @csv' <<-EOF | |
{ | |
"Items": [ | |
{ |