Skip to content

Instantly share code, notes, and snippets.

@brianhempel
brianhempel / all_s3_objects.rb
Created March 21, 2012 15:21
List/fetch all objects in a bucket with AWS::S3 Ruby gem
# by default you only get 1000 objects at a time
# so you have to roll your own cursor
S3.connect!
objects = []
last_key = nil
begin
new_objects = AWS::S3::Bucket.objects(bucket_name, :marker => last_key)
objects += new_objects
@shunchu
shunchu / convert-seconds-into-hh-mm-ss-in-ruby.rb
Created July 25, 2012 07:58
Convert seconds into HH:MM:SS in Ruby
t = 236 # seconds
Time.at(t).utc.strftime("%H:%M:%S")
=> "00:03:56"
# Reference
# http://stackoverflow.com/questions/3963930/ruby-rails-how-to-convert-seconds-to-time
@adrianwebb
adrianwebb / ssl_cert_generation_template
Last active April 23, 2016 13:32
Bash script to generate SSL key, passwordless pem, csr, and crt files
#!/bin/bash
function generate_ssl_cert {
cert_name=$1
(
openssl genrsa -des3 -out ${cert_name}.key 1024
openssl rsa -in ${cert_name}.key -out ${cert_name}.pem
openssl req -new -key ${cert_name}.pem -out ${cert_name}.csr
openssl x509 -req -days 365 -in ${cert_name}.csr -signkey ${cert_name}.pem -out ${cert_name}.crt
@jmontross
jmontross / gist:5647271
Created May 24, 2013 23:46
how to get more than 1000 s3 assets using fog gem in ruby
storage = Fog::Storage.new({:provider => 'AWS', :aws_access_key_id => ACCESS_KEY_ID, :aws_secret_access_key => SECRET_ACCESS_KEY})
files = storage.get_bucket("lessonOverFlow",{'max-keys' =>'100000'})
truncated = files.body['IsTruncated']
the_response = files.body['Contents']
while truncated
files = storage.get_bucket("lessonOverFlow",{'max-keys' =>'100000', 'marker' => files.body['Contents'].last["Key"]})
truncated = files.body['IsTruncated']
the_response = the_response + files.body['Contents']
end
@freemanirl
freemanirl / create pem.sh
Created November 5, 2016 13:58
Creating a PEM file for deployment users.
su - deploy
mkdir .ssh && cd .ssh
ssh-keygen -b 2048 -t rsa -f key -C deploy
cat > authorized_keys < key.pub
chmod 0700 ~/.ssh; chmod 0600 ~/.ssh/authorized_keys