Skip to content

Instantly share code, notes, and snippets.

Avatar

Evan Light elight

  • Heroku
  • Washington, DC
View GitHub Profile
View dabbling_with_statelessness.rb
cf = Redrax::CloudFiles.new
cf.configure!(
user: ENV['RAX_USERNAME'],
api_key: ENV['RAX_API_KEY'],
region: :iad
)
cf.authenticate!
container_name = "test_container"
file_name = "test_file"
View gist:026e203471adcd403237
require 'aviator'
configuration = {
:provider => 'openstack',
:auth_service => {
:name => 'identity',
:host_uri => 'http://devstack:5000/v2.0',
:request => 'create_token',
:validator => 'list_tenants'
},
View cloud_files_sdk_brainstorming.rb
# containers
cf.containers.create("new_container")
cf.containers.create("new_container", metadata: { "you're on your own here bud": "because you wanted all of the power" }) # Should we even offer metadata mutation at create time????
container = cf.containers["my-test-dir"]
container.delete
# metadata (Hash-like protocol)
container.metadata # Return a Hash of the metadata less the X-Container-Meta- prefixes
container.metadata["price"] = "4.20"
container.metadata.delete("price")
View rax_auth.txt
export body="{\"auth\":{\"RAX-KSKEY\":\"apiKeyCredentials\":{\"username\":\"$RAX_USERNAME\", \"apiKey\":\"$RAX_API_KEY\"}}}"
echo $body
echo
curl -v -s https://identity.api.rackspacecloud.com/v2.0/tokens -X 'POST' \
-d $body \
-H 'Content-Type: application/json' | python -m json.tool
View create_access_rule.rb
module Fog
module Rackspace
class LoadBalancers
class Real
def create_access_rule(load_balancer_id, address, type)
#TODO - This can actually support adding multiple access rules.
data = {
'accessList' => [
{
'address' => address,
View bob.rb
class Bob
def hey(what)
what = forget_that_noise(what)
if saying_a_whole_lotta_nothing?(what)
"Fine. Be that way!"
elsif shouting_at_me?(what)
"Woah, chill out!"
elsif asking_me_something?(what)
"Sure."
View raindrops.go
package raindrops
import (
"bytes"
"fmt"
)
func Convert(v int) string {
fs := findRelevantFactorsFor(v)
return formatFactorsOf(v, fs)
View example.rb
module SomeRequest
class Real
def do_something
RequestCommon.base_request(...)
end
end
end
View list_entities.rb
module Fog
module Rackspace
class Monitoring
class Real
def list_entities(options={})
request(
:expects => [200, 203],
:method => 'GET',
:path => 'entities',
View compute.rb
def request(params)
begin
response = @connection.request(params.merge({
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'X-Auth-Token' => @auth_token
}.merge!(params[:headers] || {}),
:path => "#{@path}/#{@tenant_id}/#{params[:path]}",
:query => params[:query]