Skip to content

Instantly share code, notes, and snippets.

View MyklClason's full-sized avatar

Mykl Clason MyklClason

  • Wisconsin, United States
View GitHub Profile
@MyklClason
MyklClason / rails_guide.md
Last active April 26, 2024 18:49
AWS Cloud9 Rails Setup Guide (and migration from c9.io) for Rails 7.1

Overview

Warning: This guide intended for Rails 6.1. (It may not be complete)

This is direction for Migration from c9.io to AWS Cloud9 or to simply setup AWS Cloud9 for Rails Development, after you follow the cloud9 migration directions and created a workspace, keeping in mind the Workspace settings Section below.

Be sure you are using the right version of rails. You may need to remove rails and rail-ties and install rails 6.1. Check online for how (search how to reinstall rails with a specific version)

@MyklClason
MyklClason / c9pg.txt
Last active April 26, 2024 18:41
Cloud9 workspace setup with Rails and Postgresql | Copy/Pastable Script
sudo service postgresql start
sudo sudo -u postgres psql
CREATE USER username SUPERUSER PASSWORD 'password';
\q
. ~/.bashrc
echo "export USERNAME=username" >> ~/.bashrc
echo "export PASSWORD=password" >> ~/.bashrc
. ~/.bashrc
sudo sudo -u postgres psql
@MyklClason
MyklClason / readme.md
Last active February 11, 2024 15:06
List of useful terminal bash aliases for Ruby On Rails, Cloud9, Git and more. What are bash aliases: http://www.tldp.org/LDP/abs/html/aliases.html What does && and ; do? http://unix.stackexchange.com/a/304258
@MyklClason
MyklClason / graph.rb
Last active December 20, 2023 05:00
Basic graph utility functions class (Ruby)
# This is a very simple hash based graph utility class.
# By Mykl Clason
# https://gist.github.com/MyklClason/fe603a6005a1dedc6ec65fda7ff47f68
class Graph
def self.undirected_graph_from_edges(edges)
# Edges are (a,b) pairs with a => b and b => a relationships.
edges.each_with_object(Hash.new { |h, k| h[k] = Set.new }) { |(k, v), h| h[k] << v }
end
def self.directed_graph_from_edges(edges)
@MyklClason
MyklClason / .erb-lint.yml
Last active February 1, 2023 23:44
Code Quality Config. Copy the files
# https://github.com/Shopify/erb-lint
linters:
DeprecatedClasses:
enabled: true
FinalNewline:
enabled: true
ErbSafety:
enabled: true
exclude:
- '**/node_modules/**'
@MyklClason
MyklClason / bootstrap_nav_helper.rb
Last active July 29, 2022 04:59
Bootstrap Nav Helper (Bootstrap 4/5)
module BootstrapNavHelper
def navbar_text(nav_text)
content_tag :span, class: "navbar_text" do
nav_text
end
end
def navbar_link_to(nav_text, nav_path, link_options = {})
is_active = current_page?(nav_path)
link_options[:class] = "#{link_options[:class]} nav-link"
@MyklClason
MyklClason / select2.html.erb
Last active July 23, 2022 22:56
select2 scripts
<script>
$(document).on('turbolinks:before-cache', function(e) {
$('.form-control.select2, .form-control.select2-taggable, .form-control.select2-w-100').each(function() {
if ($(this).data('select2')) {
$(this).select2('destroy');
}
});
});
$('.form-control.select2, .form-control.select2-taggable, .form-control.select2-w-100').each(function() {
@MyklClason
MyklClason / bootstrap_flash_helper.rb
Last active June 4, 2022 21:23
Bootstrap Flash Helper Bootstrap 4/5
# Modified from the Twitter Bootstrap Rails gem's Bootstrap Flash Helper (bootstrap 3) for Bootstrap 4
# Place in the helpers folder
module BootstrapFlashHelper
ALERT_TYPES = [
:primary,
:secondary,
:success,
:danger,
:warning,
:info,
@MyklClason
MyklClason / pretty_helper.rb
Last active March 20, 2022 00:44
Pretty Helper
module PrettyHelper
def pretty_boolean(boolean)
boolean ? "Yes" : "No"
end
def pretty_array(array, seperator: ";")
array.to_a.join("; ")
end
def pretty_linked_record_array(array, field, new_window: true)
@MyklClason
MyklClason / gist:f6ac68ca4ce1faa5d655abfb0abe788b
Last active December 11, 2021 00:05
CSV Export (Rails)
# Good solution for exporting to CSV in rails.
# Source: https://www.codementor.io/victorhazbun/export-records-to-csv-files-ruby-on-rails-vda8323q0
class UsersController < ApplicationController
def index
@users = User.all
respond_to do |format|
format.html
format.csv { send_data @users.to_csv, filename: "users-#{Date.today}.csv" }