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
# Run every day at midnight
# cd into the Rails app directory
# run the rake task `logs:prune`
0 0 * * * cd /Users/you/projects/myrailsapp && /usr/local/bin/rake RAILS_ENV=production logs:prune
<script src="http://<BEACON_HOST>/v1/config?configuration_id=<CONFIG_ID"></script>
<script src="http://<BEACON_HOST>/v1/config?configuration_id=<CONFIG_ID"></script>
<%= f.collection_select(:shipping_method, @ship_method_options, :id, :name) %>
<%= f.input :shipping_method_other %>
@ryenski
ryenski / index.html.slim
Last active January 13, 2022 04:08
Tabbed interface with Stimulus.js
div data-controller='tabs' data-tabs-index='1'
.tabs.is-boxed.is-marginless
ul
li data-target='tabs.tab'
a data={action: "tabs#change"} Tab 1
li data-target='tabs.tab'
a data={action: "tabs#change"} Tab 2
.tab.box data={target: 'tabs.tabPanel'} Tab panel 1
.tab.box data={target: 'tabs.tabPanel'} Tab panel 2
@ryenski
ryenski / _row.html.erb
Created January 26, 2018 21:55
Clickable table rows with Stimulus.js
<tr data-action="click->table#click" data-controller="table">
<td> 2018-01-11 </td>
<td>
<a data-target="table.url" href="/invoices/1">$7,000.00</a>
</td>
</tr>
module Sequential
extend ActiveSupport::Concern
module ClassMethods
def next_custom_id_for_tenant(tenant_id)
raise "Tenant is required" unless tenant_id.present?
# FIXME: Should probably store this value in some external resource, as this could cause race conditions and/or performance issues due to transaction locking.
# Possibly use PG Triggers?
@ryenski
ryenski / parallax.js
Last active August 5, 2017 20:43
Pure-css version of the parallax effect from Bourbon Refills (http://refills.bourbon.io/components/)
document.addEventListener('turbolinks:load', function(){
var el = document.getElementById('js-parallax-window')
if (el) {
parallax(el);
}
window.addEventListener('scroll', function(e){
if (el) {
parallax(el);
}
@ryenski
ryenski / comment_creator_test.rb
Created June 27, 2017 19:05
Testing service objects
describe CommentCreator do
it 'should persist record' do
assert_difference 'Comment.count', +1 do
CommentCreator.new(comment_params).call
end
end
end
@ryenski
ryenski / signups_controller.rb
Created June 27, 2017 18:58
Calling TenantCreator service object in SignupController
class SignupsController < ActionController::Base
def create
@signup = TenantCreator.new(signup_params)
if @signup.call
redirect_to welcome_url(account_id: @signup.tenant.subdomain, auth_token: @signup.user.auth_token)
else
flash.now[:error] = @signup.errors.full_messages.join(', ')
render action: :index
end
end