Skip to content

Instantly share code, notes, and snippets.

View joshmn's full-sized avatar
🔒
@ FCI Thompson

joshmn joshmn

🔒
@ FCI Thompson
View GitHub Profile
@joshmn
joshmn / application.rb
Created May 22, 2023 00:43
ActiveStorage with ordered attachments using acts_as_list
module MyApp
class Application < Rails::Application
config.to_prepare do
ActiveStorage::Attachment.include OrderedAttachments
end
end
end
<!-- posts/_form.html.erb -->
<%= simple_form_for @form do |f| %>
<%= f.input :user_id %>
<%= f.input :subject %>
<%= f.input :content %>
<%= f.submit %>
<% end %>
@joshmn
joshmn / serializer.rb
Last active November 23, 2020 19:17
simple serializer pattern
class ApplicationSerializer
attr_reader :object
def initialize(object, options = {})
@object = object
@options = options
end
def to_json
JSON.generate(as_json)
end
@joshmn
joshmn / routes.rb
Created September 28, 2018 21:48
actual routes
class SiteConstraint
def matches?(request)
request.subdomain != 'my' && request.domain != 'localhost'
end
end
class AppConstraint
def matches?(request)
request.subdomain === 'my' || request.domain == 'localhost'
end
@joshmn
joshmn / config.ru
Last active June 5, 2018 08:09
this rack app will return whatever http status code you want, too.
# https://gist.github.com/wwalexander/febbc1ba76c8eafa9f94f5cb2573b34d
# https://news.ycombinator.com/item?id=17235270
#
# Make sure this is named config.ru
# install the gem with
# $ gem install rack
#
# Usage: rackup
require 'rack'
@joshmn
joshmn / gemfile_sort.rb
Created August 1, 2017 20:10
sort your gemfile lol
file = File.read("test.gemfile")
open_group = false
default_groups = [:general]
current_groups = default_groups
gem_groups = {}
gems = {}
file.split("\n").each do |line|
@joshmn
joshmn / contact.rb
Created May 4, 2017 20:24 — forked from endymion/contact.rb
Example of integrating a Ruby on Rails app with Zapier using the REST hooks pattern. With support for triggering the REST hooks from Resque background jobs.
class Contact < ActiveRecord::Base
...
def after_create
if Hook.hooks_exist?('new_contact', self)
Resque.enqueue(Hook, self.class.name, self.id)
# To trigger directly without Resque: Hook.trigger('new_contact', self)
end
end
@joshmn
joshmn / fish.conf
Created May 5, 2016 18:16 — forked from Epigene/fish.conf
Fish2 configuration file
# Path to Oh My Fish install.
set -gx OMF_PATH /Users/augusts/.local/share/omf
source $OMF_PATH/init.fish
# Path to your oh-my-fish.
set PATH /Applications/Postgres.app/Contents/Versions/9.4/bin $PATH
set PATH ~/bin $PATH
set PATH /usr/local/bin $PATH
set -x RACK_ENV development
set -x EDITOR atom
@joshmn
joshmn / powerball.json
Created January 13, 2016 21:18
Powerball winners
[{
"date": "2016-01-09",
"winners": [16, 19, 32, 34, 57],
"powerball": 13
}, {
"date": "2016-01-06",
"winners": [2, 11, 47, 62, 63],
"powerball": 17
}, {
"date": "2016-01-02",