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 / lefthook.yml
Created June 1, 2025 23:35
Standardrb with lefthook
# .lefthook.yml
# 1) Define a “common” map of commands
.common: &common_commands
check_clean:
run: |
if [ -n "$(git status --porcelain)" ]; then
echo "❌ Uncommitted changes detected. Please commit or stash before pushing."
exit 1
fi
@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 / 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 / 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 / .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 / handlebars_render.js
Last active September 25, 2019 23:23
Handlebars/Mustache helpers
/* global $, HandlebarsTemplates */
// For use with https://github.com/leshill/handlebars_assets
function renderTemplate(template, context) {
return HandlebarsTemplates[template](context)
}
function renderTemplateAt(query, template, context) {
return (
$(query).html(
renderTemplate(template, context)
// Note: Must use `var self = this` to access stuff within the success/error functions
Rails.ajax({
url: action_path,
type: "PATCH",
data: $.param(data),
dataType: 'script',
processData: false,
contentType: false,
success: function(data) { },
error: function(data) { }
@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 / stimulusjs.md
Last active July 21, 2019 22:03
Rails StimulusJS setup

Yarn

https://yarnpkg.com/lang/en/docs/install/#debian-stable

Run Commands

curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update && sudo apt-get install --no-install-recommends yarn