Skip to content

Instantly share code, notes, and snippets.

{
"products":[
{
"id":"eea560e7-86f3-4a9c-86ce-b57b8fdbc11a",
"name":"Mid-Century Modern Accent Chair",
"description":"This mid-century modern accent chair is a timeless piece that will add a touch of elegance to any room. It features a sleek, walnut frame and a comfortable, mustard yellow cushion. The chair is in excellent condition and has been well-maintained.",
"picture":"https://storage.googleapis.com/online-boutique-product-data/Mid-Century%20Modern%20Accent%20Chair165",
"priceUsd":{
"currencyCode":"USD",
"units":3884,
colorTable:
colorWhite: &colorWhite
rgb: [255, 255, 255]
hex: "FFFFFF"
colorRed100: &colorRed100
rgb: [255, 255, 255]
hex: "FFFFFF"
colorRed300: &colorRed300
rgb: [255, 255, 255]
hex: "FFFFFF"
require 'graph'
require 'psych'
steps = Psych.load(File.read(ARGV[0]))["steps"]
previous_steps = []
digraph do
steps.each do |step|
id = step["id"] || step["name"]
data = File.read(ARGV[0]).split("\n").map { |l| l.split(": ").map(&:to_i) }
layers = {}
data.each do |a, b|
layers[a] = b
end
max = ARGV[1].to_i
# A greedy algorithm for bin packing
class Array
def rest
self[1..-1]
end
end
def optimize_pack inventory, order
loop do
require "google/cloud/monitoring/v3/metric_service_client"
client = Google::Cloud::Monitoring::V3::MetricServiceClient.new
project = Google::Cloud::Monitoring::V3::MetricServiceClient.project_path(PROJECT_ID)
interval = Google::Monitoring::V3::TimeInterval.new
interval.start_time = Google::Protobuf::Timestamp.new(seconds: start_time)
interval.end_time = Google::Protobuf::Timestamp.new(seconds: end_time)
require "google/cloud/monitoring/v3/metric_service_client"
client = Google::Cloud::Monitoring::V3::MetricServiceClient.new
project = Google::Cloud::Monitoring::V3::MetricServiceClient.project_path(PROJECT_ID)
metric = "appengine.googleapis.com/system/memory/usage"
end_time = Time.now.to_i
start_time = end_time - (60 * 10) # 10 minutes
@thagomizer
thagomizer / LICENSE
Last active January 12, 2017 17:55
Code to go with my Authenticating Google Cloud Ruby Gems blog post
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
require "google/cloud/storage"
gcloud = Google::Cloud.new "Your Project", "Path To Your Key"
storage = gcloud.storage
bucket = storage.create_bucket "my_goat_pictures"
bucket.create_file "goat.jpg", "uploaded_goat.jpg"