Skip to content

Instantly share code, notes, and snippets.

View macfanatic's full-sized avatar

Matthew Millsaps-Brewer macfanatic

View GitHub Profile
module ActiveAdmin
module Inputs
class FilterCountryInput < FilterSelectInput
include FilterBase
def collection
::ActionView::Helpers::FormOptionsHelper::COUNTRIES
end
end
module ActiveAdmin
module Inputs
class FilterStateInput < FilterSelectInput
include FilterBase
def collection
{
'AL' => 'Alabama',
'AK' => 'Alaska',
'AZ' => 'Arizona',
#!/bin/sh
### BEGIN INIT INFO
# Provides:
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable service provided by daemon.
### END INIT INFO
[Unit]
Description=udp-listener
After=multi-user.target
[Service]
Type=idle
WorkingDirectory=/var/apps/our-software
ExecStart=/var/apps/our-software/bin/udp-listener
User=pi
Group=pi
@macfanatic
macfanatic / simplest_indicator.rb
Last active July 7, 2016 19:58
Simple indicator class showing how we might implement managing state definitions
class StatusIndicator
OFF = 'off'.freeze
CHARGING = 'charging'.freeze
CHARGED = 'charged'.freeze
def self.states
[ OFF, CHARGING, CHARGED ]
end
def self.renderings
# app/models/post.rb
class Post < ActiveRecord::Base
attr_accessible :body, :status, :title
validates :title, presence: true, uniqueness: true
validates :body, presence: true
DRAFT = 'draft'
REVIEWED = 'reviewed'
PUBLISHED = 'published'
module ActiveAdmin
module StateMachine
module DSL
#
# Easily tie into a state_machine action
#
# @param [Symbol] state machine event, ie: :publish
# @param [Hash] options
# - permission [Symbol] permission to check authorization against
@macfanatic
macfanatic / account.rb
Created March 3, 2017 21:55
See usage.rb below for an example of Rails Association Extensions at their finest
class Account < ActiveRecord::Base
has_many :conversations, dependent: :destroy, extend: Voting::Resource::AssociationActions
end