Skip to content

Instantly share code, notes, and snippets.

View johnmeehan's full-sized avatar
:octocat:

John Meehan johnmeehan

:octocat:
  • Meetyl
  • Ireland
View GitHub Profile
@johnmeehan
johnmeehan / grouped_select.coffee
Created November 1, 2016 11:26
Grouped Select Example
# :coffeescript
jQuery ->
designs = $('.design').html()
$('.style').change ->
style = $('.style option:selected').text()
options = $(designs).filter("optgroup[label='" + style + "']").html()
$('.design').html(options)
@johnmeehan
johnmeehan / _modal.html.haml
Last active February 14, 2023 19:20
Rails + Reform + Bootstrap + Ajax Modal Form
# simple_form Reform Form for creating a basic postal address
# errors will be shown on the violating fields
= simple_form_for(@form, remote: true) do |f|
.modal-dialog
.modal-content
.modal-header
%button.close{"aria-hidden" => "true", "data-dismiss" => "modal", :type => "button"} ×
%h3.modal-title
New Address for
= @customer.name
@johnmeehan
johnmeehan / bootstrap_tabs.haml
Created October 5, 2016 11:27
example to bootstrap tabs switching out the tab and its contents
#tabs
%ul.nav.nav-tabs.nav-justified
%li.active
= link_to 'Quotes', '#quotes', data: { toggle: "tab" }
%li
= link_to 'Draft', '#drafts', data: { toggle: "tab" }
%li
= link_to 'Submitted', '#submitted', data: { toggle: "tab" }
%li
= link_to 'Accepted', '#accepted', data: { toggle: "tab" }
@johnmeehan
johnmeehan / reform_prepopulators.rb
Created August 29, 2016 15:40
Reform prepopulator and allow for deletion
collection :side_panels, form: SidePanelForm,
prepopulator: ->(options) {
if side_panels.count == 0
self.side_panels << SidePanel.new(sales_order_id: sales_order_id, collection: sales_order.collection)
end
},
populator: ->(fragment:, index:, **) {
if fragment['panel_id'] == "" #'0' # or 'None' => nil then wouldn't need to make a None on the DB then.
deserialized_panel = side_panels.find { |p| p.id.to_s == fragment["id"] }
if deserialized_panel
@johnmeehan
johnmeehan / ansi-terminal-colours.rb
Created March 14, 2016 21:01
ANSI Colours for coloured terminal output.
# ANSI Colours for coloured terminal output.
# John Meehan 2016
# foreground color
"\033[30m" #BLACK_TEXT
"\033[31m" #RED_TEXT
"\033[32m" #GREEN_TEXT
"\033[33m" #BROWN_TEXT
"\033[34m" #BLUE_TEXT
"\033[35m" #MAGENTA_TEXT
@johnmeehan
johnmeehan / atom-setup.rb
Last active March 14, 2016 21:08
Atom packages setup
# Atom packages set up.
# John Meehan 2016
# ruby atom-setup.rb
[ "emmet",
"editor-stats",
"language-haml",
"linter",
"linter-ruby",
"linter-rubocop",
"linter-scss-lint",
@johnmeehan
johnmeehan / git_source_tree.sh
Created March 11, 2016 13:28
Git source tree
git log --graph --oneline --decorate
@johnmeehan
johnmeehan / ubunutu_setup.sh
Last active March 16, 2016 13:04
Setup a clean ubuntu install
#!/bin/sh
# John Meehan 9/3/2016
# Setup a clean ubuntu install
# run with . <filename>.sh
# Get password to be used with sudo commands
# Script still requires password entry during rvm and heroku installs
echo -n "Enter password to be used for sudo commands:"
read -s password
@johnmeehan
johnmeehan / basic_rails_setup.rb
Last active May 1, 2018 21:49
Basic Rails Setup (template)
# Rails Project Template
# Run with:
# rails new MyApp -T -m http://.............
# John Meehan 2016,2018
# Set the ruby version to that of the RVM
def set_ruby_version
insert_into_file('Gemfile', "ruby '#{RUBY_VERSION}'\n", :before => /^ *gem 'rails'/, :force => false)
# Set the Gemset name based on the Rails app name
insert_into_file('Gemfile', "#ruby-gemset=#{@app_name}\n", :before => /^ *gem 'rails'/, :force => false)
@johnmeehan
johnmeehan / Image_downloader.rb
Created March 9, 2015 16:50
Save 100 simularly named images stored remotely
require 'nokogiri'
require 'open-uri'
require 'net/http'
require 'uri'
###
# Purpose:
# Needed to save 100 simularly named images stored remotely
# Result: Saves 100 png to the local ./icons/ folder
###