Skip to content

Instantly share code, notes, and snippets.

View fractaledmind's full-sized avatar

Stephen Margheim fractaledmind

View GitHub Profile
@virolea
virolea / url_validator.rb
Last active February 16, 2023 17:01
Rails Custom URL validator
# Use this validator like this
#
# class User < ApplicationRecord
# validates :profile_link, url: true
# end
class UrlValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
unless valid_url?(value)
record.errors.add(attribute, :invalid_url)

OpenBSD logo     Rails logo     Falcon logo


Choose OpenBSD for your Unix needs. OpenBSD -- the world's simplest and most secure Unix-like OS. A safe alternatve to the frequent vulnerabilities and overengineering of Linux and related software (NGiNX & Apache (httpd-asiabsdcon2015.pdf), OpenSSL, iptables/nftables, systemd, BIND, Postfix, Docker etc.)

OpenBSD -- the cleanest kernel, the cleanest userland and the cleanest config

@jaredcwhite
jaredcwhite / turbo_transitions.js
Created September 13, 2022 15:49
Nice transitions using Turbo
document.addEventListener("turbo:visit", () => {
let main = document.querySelector("main");
if (main.dataset.turboTransition == "false") return;
let [movement, scale] = ["-12px", "0.99"];
if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
[movement, scale] = ["-6px", "1"]
};
import { Controller } from '@hotwired/stimulus'
import autoAnimate from '@formkit/auto-animate'
export default class extends Controller {
connect () {
autoAnimate(this.element)
}
}
import { Controller } from "@hotwired/stimulus"
import SignaturePad from 'signature_pad'
export default class extends Controller {
static targets = ["canvas", "input"]
connect() {
this.signaturePad = new SignaturePad(this.canvasTarget)
this.signaturePad.addEventListener("endStroke", this.endStroke)
this.resizeCanvas()
if (this.inputTarget.value) {
@baweaver
baweaver / deep_group.rb
Created August 2, 2022 05:53
Deep grouping, because I keep doing something like this by hand and it gets hard to keep track of.
module DeepGroup
class Grouping
IDENTITY = -> v { v }
def initialize(state)
@state = state
@groupings = []
@mapping = IDENTITY
end
@leastbad
leastbad / channel.rb
Last active July 24, 2022 11:10
Action Cable Channels setup
module ApplicationCable
class Channel < ActionCable::Channel::Base
include CableReady::Broadcaster
delegate :render, to: :ApplicationController
end
end
class Chart < ApplicationRecord
validate do |chart|
schema = Rails.cache.fetch("vega_lite_schema/v5") do
Faraday.get("https://vega.github.io/schema/vega-lite/v5.json").body
end
JsonSchemaValidator.new(chart, schema: schema, json: vega_json, field: :vega_json).validate
end
end
@hopsoft
hopsoft / README.md
Last active June 20, 2024 09:27
Heroku Review Apps managed by GitHub Actions

Heroku Review Apps managed by GitHub Actions

This gist aims to provide a simple solution for managing Heroku Review Apps with GitHub Actions due to the security incident that continues to disrupt Heroku's GitHub integration.

.github
├── workflows
│   ├── heroku_review_app_create.yml
│   └── heroku_review_app_destroy.yml

Untitled CSS Library RFP

Untitled CSS Library is a CSS library that, so far as I can tell, does not exist.

It offers the following features:

  • It renders well out of the box with Vanilla HTML, like a classless CSS library such as pico
  • It takes advantage of semantic, lesser used tags such as nav, main and section to allow for more elaborate layouts in pure HTML
  • It offers "High Power" classes that capture high level components in, as much as is possible, a single CSS class