Skip to content

Instantly share code, notes, and snippets.

View kivanio's full-sized avatar
🏠
Working from home

Kivanio Barbosa kivanio

🏠
Working from home
View GitHub Profile
@kivanio
kivanio / a4-css-page-template.markdown
Created March 20, 2019 13:36
A4 CSS page template
@kivanio
kivanio / 0001_sidekiq.rb
Created May 25, 2017 11:50 — forked from rob-race/0001_sidekiq.rb
Elastic BeanStalk Sidekiq scripts
# Sidekiq interaction and startup script
commands:
create_post_dir:
command: "mkdir -p /opt/elasticbeanstalk/hooks/appdeploy/post"
ignoreErrors: true
files:
"/opt/elasticbeanstalk/hooks/appdeploy/post/50_restart_sidekiq.sh":
mode: "000755"
owner: root
group: root
@kivanio
kivanio / upload-images-s3-sdk-ruby
Created February 8, 2017 19:27 — forked from Bijendra/upload-images-s3-sdk-ruby
Upload images to AWS S3 in rails application using aws-sdk
Using gem aws-sdk for a ror application for uploading images to s3
Uploading images to a fixed bucket with different folders for each object or application.
The s3 keeps a limitation on the number of buckets creattion whereas there is no
limitation for content inside a bucket.
This code will upload image for a user to s3 using aws-sdk gem. The bucket and the image uploaded are made public
so that the images uploaded are directly accessible. The input it takes is the image complete path
where it is present, folder in which it should be uploaded and user_id for whom it should
be uploaded.
@kivanio
kivanio / estimate.rb
Created February 8, 2017 19:21 — forked from micahroberson/estimate.rb
Generate and save a pdf to S3 with wicked_pdf and paperclip
# Main reference was lascarides' post at http://stackoverflow.com/questions/14743447/getting-pdf-from-wickedpdf-for-attachment-via-carrierwave
# estimate.rb
# ...
has_attached_file :pdf,
storage: :s3,
s3_credentials: {
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
bucket: ENV['AWS_BUCKET']
sudo service elasticsearch stop
if ! [ -e .semaphore-cache/elasticsearch-2.4.4.deb ]; then (cd .semaphore-cache; curl -OL https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/deb/elasticsearch/2.4.4/elasticsearch-2.4.4.deb); fi
echo Y | sudo dpkg -i .semaphore-cache/elasticsearch-2.4.4.deb
sudo sh -c "echo 'script.inline: true' >> /etc/elasticsearch/elasticsearch.yml"
sudo sh -c "echo 'script.groovy.sandbox.enabled: true' >> /etc/elasticsearch/elasticsearch.yml"
sudo sh -c "echo 'index.number_of_replicas: 0' >> /etc/elasticsearch/elasticsearch.yml"
sudo sh -c "echo 'index.number_of_shards: 1' >> /etc/elasticsearch/elasticsearch.yml"
sudo service elasticsearch start
sleep 10 && curl -XGET 'localhost:9200'
@kivanio
kivanio / semaphore-es.sh
Created January 27, 2017 17:54 — forked from BlackFoks/semaphore-es.sh
A script for installing ES on SemaphoreCI
#!/bin/bash
# Install a custom ElasticSearch version - https://www.elastic.co/products/elasticsearch
#
# To run this script on SemaphoreCI, add the following command to your project's build setup:
# \curl -sSL <RAW_URL_FOR_THIS_SCRIPT> | bash -s
#
ELASTICSEARCH_VERSION="0.90.13"
ELASTICSEARCH_PORT="9200"
ELASTICSEARCH_DIR="$SEMAPHORE_PROJECT_DIR/elasticsearch"
ELASTICSEARCH_WAIT_TIME="15"
@kivanio
kivanio / form_user.rb
Created December 28, 2016 12:17
Happy_seed omniauth with devise
class FormUser < User
attr_accessor :current_password
validates_presence_of :email, if: :email_required?
validates_uniqueness_of :email, allow_blank: true, if: :email_changed?
validates_format_of :email, with: Devise.email_regexp, allow_blank: true, if: :email_changed?
validates_presence_of :password, if: :password_required?
validates_confirmation_of :password, if: :password_required?
validates_length_of :password, within: Devise.password_length, allow_blank: true
@kivanio
kivanio / gcal_chk.rb
Created December 22, 2016 18:05 — forked from vivahiraj/gcal_chk.rb
LINE BOT APIを利用してGoogle Calendarの情報を送る
# coding: utf-8
require 'rest-client'
require 'json'
require 'date'
require 'gmail'
require 'yaml'
#google-api-clientはv0.6.4が必要です
require "google/api_client"
@kivanio
kivanio / contact_importer.rb
Created December 22, 2016 17:54 — forked from maletor/contact_importer.rb
Use OAuth to import contacts
require 'oauth'
require 'oauth2'
class ContactImporter
def initialize(importer)
@importer = importer
end
def authorize_url
case @importer
@kivanio
kivanio / token.rb
Created December 22, 2016 17:53 — forked from GregBaugues/token.rb
Google API OAuth 2.0 refresh token (Ruby on Rails)
# The OAuth access token provided by the Google API expires in 60 minutes. After expiration,
# you must exchange a refresh token for a new access token. Unfortunately, the the Google API
# ruby gem does not include a method for refreshing access tokens.
# You can read up on how to refresh an access token here:
# https://developers.google.com/accounts/docs/OAuth2WebServer#refresh
# This Token model implements that process. It's based off of a Token model that can be created
# by running:
# rails g model Token token:text refresh_token:string expires_at:datetime