Skip to content

Instantly share code, notes, and snippets.

View danielRomero's full-sized avatar

Daniel Romero danielRomero

View GitHub Profile

Keybase proof

I hereby claim:

  • I am danielromero on github.
  • I am danielromero (https://keybase.io/danielromero) on keybase.
  • I have a public key ASBxCKptskvGkbX3002uMvlQV6LnK2eO41UfnOWApGyF8go

To claim this, I am signing this object:

@danielRomero
danielRomero / execute_command_ec2_aws.sh
Last active March 29, 2017 11:21
Execute command in all AWS EC2 instances with capistrano
#!/bin/bash
# Get all hosts (change regex to fit your structure)
targets=($(cap production ec2:status | egrep -o "ec2.*com"))
for host in `echo $targets`
do
echo fetching logs from ${host}
# Command to execute (example, download logs from all machines)
scp ubuntu@${host}:/var/www/my_app_name/shared/log/production.log ./production${host}.log
done
echo done!
@danielRomero
danielRomero / octocat_downloader.rb
Created March 14, 2016 14:52
Download all Octocats (https://octodex.github.com/) to local folder
#!/usr/bin/env ruby
require 'nokogiri'
require 'open-uri'
require 'etc'
# home user path
home_path = Etc.getpwnam(Etc.getlogin).dir
wallpaper_folder = "#{home_path}/Pictures/wallpapers"
@danielRomero
danielRomero / _flashes.html.erb
Last active August 31, 2015 11:18
Rails partial for render flashes with Bootstrap classes, Font Awesome icons and autoclose
<% if !flash.blank? %>
<% if flash[:notice] %>
<div class="alert alert-success auto_close">
<div aria-hidden="true" class="close" data-dismiss="alert">
<div class="fa fa-times"></div>
</div>
<div class="fa fa-check"></div>
<%= raw flash[:notice] %>
</div>
<% end %>
@danielRomero
danielRomero / sessions_helper.rb
Last active August 29, 2015 14:23
Manage rails sessions and current_user
module SessionsHelper
def sign_in(user)
logger.debug "Starting session..."
reset_session
remember_token = SecureRandom.urlsafe_base64.to_s
create_session_cookie(remember_token)
user.update_attribute(:remember_token, Digest::SHA2.hexdigest(remember_token))
current_user = user
logger.debug "Session started for #{user.class.to_s} with id #{user.id}"