Skip to content

Instantly share code, notes, and snippets.

@rebelweb
rebelweb / axlsx_report.rb
Last active August 29, 2015 14:07
Axlsx Report Object Oriented Style
require 'axlsx'
module Reports
class AxlsxReport < Reports::Report
##call from irb (or anything ruby for that matter) to generate report (i.e. Reports::AxlsxReport.generate)
def self.generate
Alsx::Package.new do |p|
p.workbook.add_worksheet(:name => 'Users') {|ws| users_worksheet(ws)}
p.workbook.add_worksheet(:name => 'User Groups') {|ws| user_groups_worksheet(ws)}
@rebelweb
rebelweb / prawn_report.rb
Created October 2, 2014 04:58
Object Oriented Prawn Report
require 'prawn'
module Reports
class PrawnReport < Reports::Report
#call this from irb or any ruby code for that matter (i.e. Reports::PrawnReport.generate)
def self.generate
Prawn::Document.generate('prawn.pdf') do |pdf|
report_header(pdf)
report_body(pdf)
@rebelweb
rebelweb / rails_helper.rb
Last active May 14, 2021 01:13
Brakeman/RSpec Inegration
ENV["RAILS_ENV"] ||= 'test'
require 'spec_helper'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'brakeman'
ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
config.use_transactional_fixtures = true
@rebelweb
rebelweb / archive.rb
Last active August 29, 2015 14:13
Simple Archive for Rails
class Archive < ActiveRecord::Base
#model will be read only!
def self.posts
Post.where('published = ? and published_date >= ? and published_date <= ?', true, Date.civil(a.year, a.month, 1), Date.civil(a.year, a.month, -1))
end
end
<%= form_for @playlist do |f| %>
<%= f.text_field :name, placeholder: 'Name' %>
<%= f.text_area :description %>
<%= f.date_field :date_in %>
<%= f.date_field :date_out %>
<%= f.fields_for :media_files do |ff| %>
<%= ff.collection_select :media_file_id, MediaFile.all, :id, :name, {}, {} %>
<%= ff.select :position, options_for_select((1..50).step(1) {}
<%= ff.link_to_remove 'Remove from Playlist' %>
<% end %>
@rebelweb
rebelweb / atom_packages.txt
Created December 7, 2015 15:24
Atom Configuration
packages:
- advanced-open-file
- color-picker
- emmet
- erb-helper
- file-icons
- filesize
- git-plus
- markdown-preview-plus
- minimap
#!/bin/bash
#
# Copyright:: Copyright (c) 2015 Gitlab.com
# Copyright:: Copyright (c) 2016 Amusement SMART, LLC
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
@rebelweb
rebelweb / application_decorator.rb
Created June 23, 2017 15:14
Decorator using simple delegator that follows most of draper syntax
require 'delegate'
class ApplicationDecorator < SimpleDelegator
def self.decorate(instance)
return nil if instance.blank?
new instance
end
def self.decorate_collection(collection)
return [] if collection.nil? || collection.length.zero?
@rebelweb
rebelweb / notification_type.rb
Last active July 19, 2017 23:47
Basic Object
class NotificationType
attr_accessor :id, :load_id
def initialize(id, load_id)
self.id = id
self.load_id = load_id
check_valid_id
end
def description
@rebelweb
rebelweb / .gitlab-ci.yml
Created August 2, 2017 17:36
Gitlab Ci for Rails with Docker
stages:
- test
- build
variables:
DB_HOST: postgres
DB_PASS: postgres
DB_USER: postgres
brakeman: