Skip to content

Instantly share code, notes, and snippets.

View damuz91's full-sized avatar
🎯
Focusing

David Muñoz damuz91

🎯
Focusing
View GitHub Profile
@eatoncw
eatoncw / gist:2deb6a62e3056e5e53b0af8cd39a1c36
Last active June 7, 2019 01:44
PDF to JPG conversion using Rails 5, Paperclip. Improved resolution of output
#Accepts all image files and pdfs. If the upload is a pdf, it is converted to a jpg
#Paperclip incorporates ImageMagick. If a multipage page PDF, only the first page is converted
#Model
#here the original style needs to be given source_file_options. It's critical that the original file is not passed geometry
#or the resolution won't really improve
has_attached_file :avatar,
styles: lambda { |attachment|
styles = {}
@rdetert
rdetert / action_mailer.rb
Created August 22, 2014 04:15
AOL and Yahoo! now use DMARC to force email services like SendGrid and MailChimp to reject emails if the FROM field gets 'spoofed' for their domain. To get around this, we will check for the `p=reject` key/value combo in the TXT record on _dmarc.domain.com. Here is a quick and dirty way to check if the DMARC field is set using ActionMailer on Ru…
class ActionMailer::Base
def dmarc(email)
domain = email.split('@')[1]
dmarc_domain = "_dmarc.#{domain}"
Resolv::DNS.open do |dns|
records = dns.getresources(dmarc_domain, Resolv::DNS::Resource::IN::TXT)
records.empty? ? nil : records.map(&:data).join(" ")
end
@ascot21
ascot21 / active_admin.js
Created January 6, 2014 03:44
Inline Editing in ActiveAdmin with Best In Place Gem
//= require jquery
//= require best_in_place
//= require jquery.purr
//= require active_admin/base
$(document).ready(function() {
$(".best_in_place").best_in_place()
$('.best_in_place').bind("ajax:success", function () {$(this).closest('tr').effect('highlight'); });
$(document).on('best_in_place:error', function(event, request, error) {
@skozz
skozz / devise_authentication_api.rb
Last active July 21, 2022 21:34 — forked from marcomd/gist:3129118
Authenticate your API with Devise gem, token by header. Ruby on Rails 4. Read the comments.
#Session controller provides a token
#/controllers/api/sessions_controller.rb
class Api::SessionsController < Devise::SessionsController
before_filter :authenticate_user!, :except => [:create]
before_filter :ensure_params_exist, :except => [:destroy]
respond_to :json
def create
resource = User.find_for_database_authentication(:email => params[:user_login][:email])
return invalid_login_attempt unless resource