Skip to content

Instantly share code, notes, and snippets.

View eric-hemasystems's full-sized avatar

Eric Anderson eric-hemasystems

View GitHub Profile
@eric-hemasystems
eric-hemasystems / js.rb
Last active July 26, 2023 19:15
JS Sandbox
# A module to execute JS in a safe sandbox. The JS engine is Spidermonkey
# (the engine used in Firefox). The sandbox is wasmer.
#
# This module assume the compiled wasm spidermonkey binary is in the same
# directory. Use one of the binaries from Mozilla directly listed here:
#
# https://github.com/mozilla-spidermonkey/sm-wasi-demo/blob/main/data.json
#
# The one on wapm is very out-dated and will not work with this module.
#
@eric-hemasystems
eric-hemasystems / add_async_submit_listener.js
Last active May 3, 2022 18:03
addEventListener for submit with async cancel
/*
* My ideal would be something like this:
*
* form.addEventListener('submit', async function(event) {
* const shouldCancel = await someAsyncActivity()
* if( shouldCancel ) event.preventDefault()
* })
*
* Unfortuantly calling `preventDefault` AFTER any async activity will not work
* AFAIK. This function provides an abstraction to work around this. Usage
@eric-hemasystems
eric-hemasystems / README.md
Last active January 31, 2022 21:47
Encode Complex Data for URLSearchParams

It's great that JavaScript now has the URLSearchParams object to help manage query string manipulation. Unfortunately the common conventions for encoding complex data (I think started by PHP) are not supported.

This provides a utility function to do that encoding. Might later add a similar function to do parsing. This allows you to keep using the built-in URLSearchParams object (which is integrated into other APIs such as URL), while also not being limited to simple values.

Tests used to verify correct functionality are included. See the tests for usage examples.

@eric-hemasystems
eric-hemasystems / hash_delegate.rb
Created August 16, 2021 16:43
Rails `delegate to:` for hashes
module HashDelegate
# Like `delegate :foo, to: :bar` only for hashes instead
# of objects. So these are the same:
#
# def foo
# bar[:foo]
# end
#
# hash_delegate :foo, to: :bar
@eric-hemasystems
eric-hemasystems / README.md
Created October 5, 2018 14:31
Screenshot Support in Solano for Rails 5.1+

Hook into RSpec via:

config.include SolanoHelpers, type: :system