Skip to content

Instantly share code, notes, and snippets.

View jaredcwhite's full-sized avatar
🌲

Jared White jaredcwhite

🌲
View GitHub Profile
@jaredcwhite
jaredcwhite / knockout_view.rb
Last active August 29, 2015 14:01
First draft of an Opal-based KnockoutView wrapper for Knockout.js
# KnockoutView provides a simple Opal-based Ruby wrapper around Knockout.js, a popular
# front-end data-binding and events library. It uses the Observable module from Vienna,
# another front-end library written in Ruby using Opal.
#
# Run one or more of these class methods in a KnockoutView subclass, aka
#
# ko_vars :somevar, :anothervar
# ko_methods :clickme
#
# and then wrappers will be created for the JS model that is passed to Knockout
@jaredcwhite
jaredcwhite / js_front_matter.rb
Last active May 10, 2020 06:31
Add Javascript Front Matter to a layout template in Bridgetown 😊 https://www.bridgetownrb.com
# Add node-runner to your site's Gemfile
# Then place this file in your plugins folder…
require "node-runner"
class JSFrontMatter
def initialize
Bridgetown::Hooks.register :site, :pre_render do |site, payload|
docs = (site.documents + site.pages).map{|doc| doc.to_liquid.to_h}
@jaredcwhite
jaredcwhite / graphlient_github_query.rb
Last active May 18, 2020 00:11
Remembering how to use Graphlient for future reference
client = Graphlient::Client.new("https://api.github.com/graphql", headers: {"Authorization" => "bearer #{token}"})
resp = client.query do
query do
repository(owner: "jaredcwhite", name: "test-ruby-on-vercel") do
description
createdAt
end
end
end
@jaredcwhite
jaredcwhite / bridgetown.automation.rb
Created May 20, 2020 07:29
An error-filled automation
run "filedoesnotexist"
@jaredcwhite
jaredcwhite / bridgetown.automation.rb
Last active May 22, 2020 08:20
Testing out running a remote Thor actions script
say "I am a script from GitHub!"
empty_directory "gh_dir"
create_file "gh_dir/fun_party.rb" do
hostname = ask("What is the virtual hostname I should use?")
"vhost.name = #{hostname}"
end
@jaredcwhite
jaredcwhite / upcasereverse.js
Created May 25, 2020 02:22
LitElement web component which converts HTML markup to an uppercase and reversed string
import { LitElement, html } from "lit-element"
class UpcaseReverse extends LitElement {
connectedCallback() {
super.connectedCallback()
const observer = new MutationObserver(this.requestUpdate.bind(this));
observer.observe(this, { characterData: true, subtree: true })
}
module I
class Have
def self.a
ruby = Struct.new(:Ruby)
joke = Struct.new(:joke)
ruby.new(joke.new("HAHA"))
end
end
end
@jaredcwhite
jaredcwhite / svg-sprite.sh
Last active August 21, 2020 17:23
Example of how to use the svg-sprite Node tool
#!/usr/bin/env bash
# Utilize https://github.com/jkphl/svg-sprite
svg-sprite --symbol --dest=src/images --symbol-dest="" --symbol-sprite="icons.svg" frontend/icons/*.svg
@jaredcwhite
jaredcwhite / one_liner.rb
Last active September 29, 2020 03:33
One-liner anonymous class method in Ruby 3
one_liner = Class.new { def self.print_me!() = puts("A class method on one line!") }
one_liner.print_me!
# Copy and try it out at https://rubyapi.org/repl
@jaredcwhite
jaredcwhite / index.js
Created October 21, 2020 17:18
Ruby2JS output
import { LitElement, html } from "lit-element";
// Lambda for determining default node action
let defaultActionForNode = (node) => {
switch (node.nodeName.toLowerCase()) {
case "form":
return "submit";
case "input":
case "textarea":