#codingexercise
Given two sorted linked lists, find their intersection as a new list
For example 1,2,3,4,5,6 with 2,4,6,8 should result in 2,4,6
Node sortedIntersect(node a, node b)
{
Node dummy;
dummy.next = null;
Node tail = dummy;
While (a != null && b != null)
{
If(a.data ==b.data){
Copy(tail.next, a.data);
A=a.next;
B=b.next;
Tail = tail.next;
}else if (a.data < b.data){
a.=a.next;
}else{ b = b.next;}
}
Return dummy.next;
}
#data structure discussion : https://1drv.ms/w/s!Ashlm-Nw-wnWk1i1yfh79Kw_ki7O
Given two sorted linked lists, find their intersection as a new list
For example 1,2,3,4,5,6 with 2,4,6,8 should result in 2,4,6
Node sortedIntersect(node a, node b)
{
Node dummy;
dummy.next = null;
Node tail = dummy;
While (a != null && b != null)
{
If(a.data ==b.data){
Copy(tail.next, a.data);
A=a.next;
B=b.next;
Tail = tail.next;
}else if (a.data < b.data){
a.=a.next;
}else{ b = b.next;}
}
Return dummy.next;
}
Cloudian Storage and s3 api example
Most online documentation skip over the example of a programmatic access to Cloudian storage saying that what works for AWS works for Cloudian. It’s true that both support S3 api but there are some caveats. First, the key/secret pairs are not universal. Cloudian servers cut their own keys and do not make them available to others. Second the direct REST API calls to the server do not appear to be straightforward as the AWS s3 3 documentation states. While it might be possible to capture the packets from tools such as s3cmd in order to dump the API calls made, the s3 sdks seem to work seamlessly. So here are some examples to show how to use them.
First an example with a tool:
Download the s3cmd tool and modify the configuration file with these values
[default]
access_key = your_access_key_goes_here
host_base = cloudianserver.com
host_bucket = %(bucket)s.cloudianserver.com
secret_key = your_secret_key_here
website_endpoint = http://%(bucket)s.cloudianserver.com/
Then issue “s3cmd ls” to see the following kind of output:
2016-06-24 17:55 s3://bucket1
2016-06-24 17:55 s3://bucket2
2016-04-22 17:32 s3://bucket3
Second try the boto sdk:
def listS3():
import boto
import boto.s3
import sys
import os
import math
from boto.s3.key import Key
try:
from urllib.parse import quote_plus
except:
from urllib import quote_plus
try:
from ConfigParser import RawConfigParser
except:
from configparser import RawConfigParser
parser = RawConfigParser()
parser.read('config.ini')
Cloudian_ACCESS_KEY_ID = parser.get('Cloudian', 'key')
Cloudian_SECRET_ACCESS_KEY = parser.get('Cloudian', 'secret')
conn = boto.connect_s3(
aws_access_key_id= Cloudian_ACCESS_KEY_ID,
aws_secret_access_key = Cloudian_SECRET_ACCESS_KEY,
host = ‘cloudianserver.com')
bucket_name = 'bucket1'
bucket = conn.get_bucket(bucket_name, validate=False)
print('bucket_list='+repr(bucket.list()))
for item in bucket.list():
print(repr(item))
listS3()
This should give an output like following:
<Key: bucket1,1424338922-Tulips.jpg>
<Key: bucket1,1424344182-Hydrangeas.jpg>
No comments:
Post a Comment