Skip to content

Instantly share code, notes, and snippets.

# config/initializer/elasticsearch.rb
config = {
transport_options: { request: { timeout: 5 } }
}
if File.exist?('config/elasticsearch.yml')
template = ERB.new(File.new('config/elasticsearch.yml').read)
processed = YAML.safe_load(template.result(binding))
config.merge!(processed[Rails.env].symbolize_keys)
end
class SendNewMessageNotifications
include Interactor #this is the gem
def call
Mailer.send_message(destination, message).deliver_later
AndroidNotification.send_message(destination, message)
AppleNotification.send_message(destination, message)
end
end
def create
conversation = Conversation.find(params[:conversation_id])
if message = conversation.messages.create(params)
Mailer.send_message(destination, message).deliver_later
AndroidNotification.sent_message(destination, message)
AppleNotification.sent_message(destination, message)
#render success
else
#render error
end
class MessagesController < BaseController
def create
conversation = Conversation.find(params[:conversation_id])
message = conversation.messages.create(params)
if message.valid?
Mailer.send_message(destination, message).deliver_later
#render success
else
#render error
end
@diegoy
diegoy / addCacheControl.awk
Last active September 23, 2016 19:20
Add cache control to all files in a folder
awk 'BEGIN { for (i = 1; i <= 315; ++i) system("s3cmd --recursive modify --add-header=\"Cache-Control:public ,max-age= 31536000\" --dry-run s3://yourbucket/users/avatars/000/"sprintf("%03d", i)) }'
@diegoy
diegoy / MaskWatcher.java
Last active November 22, 2021 08:41
Apply masks to Android's Edit text adding this TextWatcher
/*
MIT License
Copyright (c) 2016 Diego Yasuhiko Kurisaki
*/
/* Example:
mEmailView.addTextChangedListener(new MaskWatcher("###-##"));
*/
import android.text.Editable;
/**
* This binder is needed to prevent a NullPointerException cases when
* Android's Data Binding Library Binder class tries to bind the value
* for rating when the model isn't setted yet.
* */
public class RatingBinder {
@BindingAdapter({"rating"})
public static void setRating(RatingBar ratingBar, Float rating) {
if (rating != null) {
ratingBar.setRating(rating);
@diegoy
diegoy / c3.js
Last active August 29, 2015 14:22
C3.js using json data to populate x axis
//http://jsfiddle.net/r0hydxpb/2/
var chart = c3.generate({
data:{
json:[
{"key":2000,"value":100},{"key":2001,"value":200},
{"key":2003,"value":300},{"key":2004,"value":400},
{"key":2005,"value":500},{"key":2006,"value":600},
{"key":2007,"value":700}
],
@diegoy
diegoy / nginx.conf
Last active September 17, 2015 20:57
nginx.conf localhost config
#user nobody;
worker_processes 5;
error_log /var/log/nginx/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
@diegoy
diegoy / .gtkrc-2.0
Created May 29, 2014 22:32
gtk config files
#~/.gtkrc-2.0
gtk-theme-name = "MediterraneanLight"
gtk-font-name = "DejaVu Sans 10"
gtk-icon-theme-name = "Faenza-Dark"