Skip to content

Instantly share code, notes, and snippets.

Avatar

Taylor Cooney tbcooney

View GitHub Profile
View authorization.md

Here is a plain-ruby approach for a flexible and expendable authorization solution to authorize actions that a user can? perform within an account or organization based on their access_level.

class CreateMembers < ActiveRecord::Migration[6.0]
  def change
    create_table :members do |t|
      t.references :account, null: false, foreign_key: true
      t.integer :access_level
      t.references :user, foreign_key: true
@tbcooney
tbcooney / sign-pdf.rb
Created Sep 24, 2020 — forked from matiaskorhonen/sign-pdf.rb
Quick and dirty PDF signing in Ruby (using Origami)
View sign-pdf.rb
#!/usr/bin/env ruby
require "openssl"
require "time"
begin
require "origami"
rescue LoadError
abort "origami not installed: gem install origami"
end
View heroku_deploy
-----> Ruby app detected
-----> Installing bundler 2.0.2
-----> Removing BUNDLED WITH version in the Gemfile.lock
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-2.7.0
-----> Installing dependencies using bundler 2.0.2
Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
[DEPRECATED] The `--deployment` flag is deprecated because it relies on being remembered across bundler invocations, which bundler will no longer do in future versions. Instead please use `bundle config set deployment 'true'`, and stop using this flag
[DEPRECATED] The `--path` flag is deprecated because it relies on being remembered across bundler invocations, which bundler will no longer do in future versions. Instead please use `bundle config set path 'vendor/bundle'`, and stop using this flag
[DEPRECATED] The `--without` flag is deprecated because it relies on being remembered across bundler invocations, which bundler will no longer do
View two_factor.html.haml
- @no_header = true
%section.login.w-full
%div
.branding.block
%div
%h2.mt-6.text-3xl.leading-9.font-extrabold.text-gray-900
= t('users.two_factor.two_factor_authentication')
- if @user.two_factor_otp_enabled?
View authenciates_with_two_factor.rb
# frozen_string_literal: true
# == AuthenticatesWithTwoFactor
#
# Controller concern to handle two-factor authentication
module AuthenticatesWithTwoFactor
extend ActiveSupport::Concern
def prompt_for_two_factor(user)
@user = user
View self_signed_pdf_certificate.rb
require 'openssl'
begin
require 'origami'
rescue LoadError
# ORIGAMIDIR = "C:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\origami-1.2.4\lib"
# $: << ORIGAMIDIR
# require 'origami'
end
include Origami
View chatroom.rb
# chatroom_channel.rb
class ChatroomsChannel < ApplicationCable::Channel
def subscribed
current_user.chatrooms.each do |chatroom|
stream_from "chatrooms:#{chatroom.id}"
end
end
def unsubscribed
stop_all_streams
View gist:e7fcf7b24b501b455a423b836ff54e4c
@messages.each do |day, messages|
%li.date_divider.w-full.block
.break
%span= "#{day.strftime("%B %d")}"
%ul
- messages.each do |message|
- if !unread_messages && @chatroom_user.last_read_at < message.created_at
- unread_messages = true
.strike
@tbcooney
tbcooney / _seating_plan.html.haml
Created Apr 20, 2020 — forked from ftes/_seating_plan.html.haml
Drag and drop in CSS grid with rails 6, stimulus and rails-ujs
View _seating_plan.html.haml
-# https://johnbeatty.co/2018/03/09/stimulus-js-tutorial-how-do-i-drag-and-drop-items-in-a-list/
.grid--draggable{ 'data-controller': 'seating-plan',
'data-seating-plan-endpoint': endpoint,
'data-action': 'dragstart->seating-plan#onDragStart dragover->seating-plan#onDragOver dragenter->seating-plan#onDragEnter drop->seating-plan#onDrop dragend->seating-plan#onDragEnd' }
- seating_plan.each do |seat|
- if seat[:is_empty]
.grid__item.grid__item--empty{ 'data-row': seat[:row],
'data-col': seat[:col],
style: "grid-row: #{seat[:row]}; grid-column: #{seat[:col]};",
class: ('grid__item--border' if seat[:is_border]) }
View gist:0960ce928808b1cad2e7c095ebc626cb
taylorcooney@Taylors-MacBook-Air:~/Code/openunit$ ⚡
bundle exec rails c
Running via Spring preloader in process 90646
Loading development environment (Rails 6.0.2.2)
irb(main):001:0> ActiveRecord::Base.connection.select_value("SEL
ECT users.unconfirmed_email FROM users")
/Users/taylorcooney/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activemodel-6.0.2.2/lib/active_model/type/integer.rb:13: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
/Users/taylorcooney/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activemodel-6.0.2.2/lib/active_model/type/value.rb:8: warning: The called method `initialize' is defined here
/Users/taylorcooney/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-6.0.2.2/lib/active_record/connection_adapters/postgresql/oid/specialized_string.rb:12: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call