Skip to content

Instantly share code, notes, and snippets.

@thagomizer
thagomizer / strafe.rb
Created May 22, 2013 02:19
StrafeBot
class Strafe < RTanque::Bot::Brain
NAME = 'Strafe Master'
include RTanque::Bot::BrainHelper
TICKS_BETWEEN_SWEEPS = 500
RUN_AWAY_TICKS = 1200
def initialize(arena)
super
@run_away_dest = nil
class Strafe < RTanque::Bot::Brain
NAME = 'Strafe Master'
include RTanque::Bot::BrainHelper
TICKS_BETWEEN_SWEEPS = 500
RUN_AWAY_TICKS = 1200
def initialize(arena)
super
@run_away_dest = nil
@thagomizer
thagomizer / gist:6542064
Created September 12, 2013 18:43
Patch for graph to add deleting nodes
diff -r old/lib/graph.rb new/lib/graph.rb
--- old/lib/graph.rb
+++ new/lib/graph.rb
@@ -371,6 +371,13 @@
end
##
+ # Deletes a node from the graph
+ def delete_node node_name
+ nodes.delete(node_name)
@thagomizer
thagomizer / fib
Created March 21, 2014 01:36
fib in prolog
fib(0,1).
fib(1,1).
fib(N,F):-
N > 1,
X is N - 2,
Y is N - 1,
fib(X,A),
fib(Y,B),
F is A + B.
require "net/http"
url = URI.parse("http://metadata.google.internal/computeMetadata/v1/project/attributes/")
req = Net::HTTP::Get.new(url.path)
req.add_field("Metadata-Flavor", "Google")
res = Net::HTTP.new(url.host, url.port).start do |http|
http.request(req)
end
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"
@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/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
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)