Skip to main content

Posts

Showing posts from January, 2020

Check string has uniq characters or not

Approach1: Set : set is unordered collections of unique elements. a = 'abcdd' if set(a) == a:     print 1 else:     print 0   Approach 2: Note : Approach 2 is with help of another data structure. a = 'abcd' def uni(a):     d = dict()     for i in a:         if i in d:             return False         else:             d[i] = 1     return True print(uni(a))

Upload and Download from S3 in ruby on rails

Upload: s3 = Aws::S3::Resource.new(region: ENV['AWS_REGION']) obj = s3.bucket(ENV['S3_BUCKET']).object("path/"+Time.now.strftime("%Y%m%d") +"/" + "file.html") obj.put body: response.body       Download: data = open(obj.presigned_url("get"))       send_data data.read, filename: "path/#{Time.now.strftime("%Y%m%d%h%M")}.html"