Skip to content

Instantly share code, notes, and snippets.

View ryenski's full-sized avatar
🎯
Focusing

Ryan Heneise ryenski

🎯
Focusing
  • Austin, TX
View GitHub Profile
@ryenski
ryenski / add_feature_flags_to_users.rb
Last active June 28, 2019 17:08
Feature Flags with Pundit
# Migration...
class AddFeatureFlagsToUsers < ActiveRecord::Migration[5.2]
def change
add_column :users, :feature_flags, :string, array: true, default: []
end
end
.card {
@apply bg-white shadow rounded-lg;
@media print {
@apply shadow-none;
}
}
.card-header {
@apply bg-gray-100 border-b border-gray-200 h-16 px-4 rounded-lg rounded-b-none flex justify-between items-center;
@media print {
assert_difference(Stock.value, +100) do
stock.increment
end
module Trashable
extend ActiveSupport::Concern
included do
scope :trashed, ->{ unscope(where: :trashed_at).where.not(trashed_at: nil) }
scope :without_trashed, ->{ where(trashed_at: nil) }
scope :with_trashed, ->{ unscope(where: :trashed_at) }
default_scope { without_trashed }
# TODO: scope for items older than 30 days for reaping by the rake task:
module Archivable
extend ActiveSupport::Concern
included do
scope :archived, ->{ unscope(where: :archived_at).where.not(archived_at: nil) }
scope :without_archived, ->{ where(archived_at: nil) }
scope :with_archived, ->{ unscope(where: :archived_at) }
default_scope { without_archived }
end
@ryenski
ryenski / activity.rb
Last active December 5, 2018 12:36
Audit trail activity tracker, similar to PaperTrail, but without undo.
# == Schema Information
#
# Table name: activities
#
# id :uuid not null, primary key
# user_id :uuid
# tenant_id :uuid
# trackable_type :string
# trackable_id :uuid
# app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
before_action :authenticate_user!
include CurrentTenant
end
# Let's simulate a DripService object that will give us some output:
class DripService
include ActiveModel::Model
attr_accessor :entry
def call
print "You passed in an entry: #{entry.email}"
end
end
@ryenski
ryenski / identities.rb
Created July 27, 2018 14:41
Oauth Identities
# == Schema Information
#
# Table name: identities
#
# id :integer not null, primary key
# user_id :integer
# provider :string
# uid :string
# created_at :datetime not null
# updated_at :datetime not null
@ryenski
ryenski / hello.vue
Last active April 7, 2025 21:28
Stimulus.js + Vue.js
<template>
<div id="app">
<p>{{ message }}</p>
</div>
</template>
<script>
export default {
data: function () {
return {