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
class Customer < ActiveRecord::Base
has_one :auto_created, dependent: :destroy
def self.register(params)
new(params).tap do |customer|
customer.save!
customer.send_welcome_email
end
end
@kivanio
kivanio / README.md
Created March 3, 2016 18:15 — forked from derwiki/README.md
Ruby module that you can use in a `before_action` on sensitive controllers for which you'd like a usage audit trail

Adding an audit log to your Rails app

If you have any sort of administrative interface on your web site, you can easily imagine an intruder gaining access and mucking about. How do you know the extent of the damage? Adding an audit log to your app is one quick solution. An audit log should record a few things:

  • controller entry points with parameter values
  • permanent information about the user, like user_id
  • transient information about the user, like IP and user_agent

Using the Rails framework, this is as simple as adding a before_action to your admin controllers. Here’s a basic version that I’m using in production.

@kivanio
kivanio / KM-instructions.md
Last active January 28, 2016 19:00 — forked from kippjb/KM-instructions.md
Instructions for downloading, compiling, and parsing KISSmetrics data exports by event

##Instructions for downloading, compiling, and parsing KISSmetrics data exports by event

####Summary: The KISSmetrics data export feature does not allow users an easy way to analyze data by event. This Gist outlines instructions for downloading and parsing KISSmetrics data for event-level analysis.

#####Step 1: Export data from KISSmetrics

Set up AWS S3 bucket.

@kivanio
kivanio / export_processor.md
Created January 28, 2016 19:00 — forked from clay-whitley/export_processor.md
km-export-processor Documentation

km-export-processor gem

The purpose of this gem is to consume the JSON that KISSmetrics exports to an S3 bucket, and transform it in a variety of useful ways.

The core features are:

  • JSON compiler : Aggregates all KISSmetrics JSON files in a directory, into a single (nonstandard) file.
  • JSON to JSON converter : Converts a nonstandard JSON file into standard format.
  • JSON to CSV converter : Converts a nonstandard JSON file into a CSV file, where each row is an event/property/alias.
  • Reimporter : Takes a nonstandard JSON file, and an API key, and sends the data in the JSON file to the product using the KMTS gem.
ActiveAdmin.register Product do
permit_params :name, :category_id, :description, :text, :slug, :in_slider, :tag_ids => []
filter :category
filter :base_tags
filter :name
filter :text
filter :created_at
filter :updated_at
ActiveAdmin.setup do |config|
# == Site Title
#
# Set the title that is displayed on the main layout
# for each of the active admin pages.
#
config.site_title = "Balance Cafe"
# Set the link url for the title. For example, to take
ActiveAdmin.register Article do
filter :site
index do
column ("Site") { |article| article.site.name }
column ("Author"), sortable: :author do |article|
article.author
end
column ("Title"), sortable: :title do |article|
ActiveAdmin.register Shipment do
def generate_shipment(shipment)
# Generate Shipment
Prawn::Document.generate @shipment.shipment_location do |pdf|
# Title
pdf.text "Shipment ##{shipment.code}", :size => 25
# Sender info
pdf.text shipment.sender.first_name
pdf.text shipment.sender.address
# app/models/OnlyAdminsAuthorization.rb
class OnlyAdminsAuthorization < ActiveAdmin::AuthorizationAdapter
def authorized?(action, subject = nil)
classname = (subject.is_a? Class)? subject.name : subject.class.name
account = Account.current
# check if expired
module ActiveAdmin
module Reports
module DSL
def enable_reports
action_item only: :index do
link_to("Download", {action: :report, params: params}, {method: :post, data: { confirm: "Are you sure you want to generate this report?"}})
end
collection_action :report, method: :post do