Skip to content

Instantly share code, notes, and snippets.

View jaredcwhite's full-sized avatar
🌲

Jared White jaredcwhite

🌲
View GitHub Profile
@jaredcwhite
jaredcwhite / ruby_3_kwargs_error.rb
Created November 5, 2021 19:08
Ruby 2.7.2 vs. 3.0.2 discrepancy
# This file runs fine in Ruby 2.7.2 and errors out in Ruby 3.0.2 with:
# testkwargs.rb:15:in `method_missing': no implicit conversion of Foo into Hash (TypeError)
# from testkwargs.rb:31:in `<main>'
class Helpers
end
class Foo
def wee(a=1, b:2)
puts a
@jaredcwhite
jaredcwhite / .zshrc
Created June 17, 2021 23:22
Switch RAILS_ENV based on the presence of a dot file
load-rails-env() {
if [ -f ".rails_env" ]; then
export RAILS_ENV=$(cat .rails_env)
else
export RAILS_ENV=production
fi
}
add-zsh-hook chpwd load-rails-env
@jaredcwhite
jaredcwhite / cable_car_example.html
Last active June 9, 2021 17:31
CableCar + web component
<cable-car href="/cc/cable_car" csrf-token="94IkWdvagUHWPGVkD+VeBFVjGoM0zXAf6tgm6BPU+kEpOj2BTtI6bXJQzEDXGAF+R6Dc1ek7oNouatTMrbUy">
<button
onclick="this.closest('cable-car').post(this, {extra: 123})"
data-x="1"
output="#show-the-things"
>
Do a thing!
</button>
<section id="show-the-things"></section>
@jaredcwhite
jaredcwhite / string_voodoo.rb
Last active June 23, 2021 18:14
JS in Ruby?!
### The Setup
Kernel.define_method(:"`") do |val|
val
end
def const(val)
val
end
@jaredcwhite
jaredcwhite / hello.rb
Last active May 17, 2021 22:00
Hello I am Ruby
class Ruby
end
def am(input)
"am #{input}"
end
def I(input)
"I #{input}"
end
@jaredcwhite
jaredcwhite / semantics.html
Last active March 23, 2023 23:10
Example of how I write HTML markup in 2021
<timeline-post post-id="54235" source-id="13" >
<sl-card style="margin-bottom: var(--sl-spacing-large)">
<a href="https://appleinsider.com/articles/21/05/11/jamf-acquires-zero-trust-cloud-security-startup-wandera-in-400m-deal?utm_medium=rss" target="_blank" slot="image"><img
src="https://photos5.appleinsider.com/gallery/41951-81380-34258-61556-jamf-pro-head-xl-xl.jpg"
alt="article thumbnail"
class="post-thumbnail"
/></a>
<h3><a target="_blank" class="link" href="https://appleinsider.com/articles/21/05/11/jamf-acquires-zero-trust-cloud-security-startup-wandera-in-400m-deal?utm_medium=rss">Jamf acquires 'zero trust' cloud security startup Wandera in $400M deal</a></h3>
@jaredcwhite
jaredcwhite / funky.config.js
Last active May 20, 2021 03:40
Personal configuration of Funky class-less utility CSS. https://native-elements.dev/#/docs/funky/introduction
module.exports = {
minify: false,
outputPath: "frontend/styles/funky-utilities.css",
breakpoints: {
xs: { max: "575px" },
sm: { min: "576px", max: "767px" },
md: { min: "768px", max: "991px" },
lg: { min: "992px", max: "1199px" },
xl: { min: "1200px", max: "1399px" },
xxl: "1400px"
@jaredcwhite
jaredcwhite / node-hi-ruby.rb
Last active April 6, 2021 21:38
Easiest way to run a Node script from Ruby?!
require "json"
def execjs(js)
IO.popen(["node", "--input-type=module"], "r+") do |pipe|
pipe.puts js
pipe.close_write
pipe.read
end
end
@jaredcwhite
jaredcwhite / settings.json
Created February 22, 2021 18:39
File Watcher setup for the Bridgetown repo
{
"filewatcher.commands": [
{
"match": "test/test_.*\\.rb",
"isAsync": true,
"cmd": "/bin/zsh --login -c \"cd ${fileDirname}; cd ..; SKIP_COV=true script/test ${file}\" && echo 'Test run completed.'",
"event": "onFileChange"
}
]
}
@jaredcwhite
jaredcwhite / datauri_builder.rb
Created January 21, 2021 21:20
Embed PNG images as data URIs right in your Bridgetown website
# Use in Liquid or ERB templates like this:
#
# Liquid: <img src="{% datauri myimage.png %}">
# ERB: <img src="<%= datauri "myimage.png" %>">
class DatauriBuilder < SiteBuilder
def build
liquid_tag "datauri", :datauri
helper "datauri", :datauri
end