Skip to content

Instantly share code, notes, and snippets.

defmodule HtmlLintNative do
use Rustler, otp_app: :platform, crate: "platform_plugs_htmllintnative"
def add(_a, _b), do: error()
def lint(_html_string), do: error()
defp error(), do: :erlang.nif_error(:nif_not_loaded)
end
#[rustler::nif]
fn lint(env: Env, input: String) -> Result<Term, Error> {
let parse_errors = lint_html::lint(input);
return convert_errors(env, parse_errors);
}
fn convert_errors(env: Env, parse_errors: Vec<(u64, String)>) -> Result<Term, Error> {
if parse_errors.len() == 0 {
return Ok(ok().to_term(env));
} else {
@addrummond
addrummond / html_lint.ex
Last active March 17, 2021 09:10
Example HTML lint plug code
defmodule HtmlLintPlug do
require Logger
def init(opts), do: opts
def call(conn, _opts) do
Plug.Conn.register_before_send(conn, &lint/1)
end
defmodule Error do
// Set up the following environment variables and then run with the path to the 'deploy' dir as the first and only argument.
//
// export IBEXFARM_DATABASE_URL=postgresql://postgres:password@localhost:6432/nmibex_dev
// export IBEXFARM_QUOTA_ID=1
// export IBEXFARM_S3_HOST=http://localhost:9000
// export IBEXFARM_S3_BUCKET=nmibex-dev
// export IBEXFARM_NO_S3_SSL=true
// export IBEXFARM_USE_MINIO=true
// export AWS_ACCESS_KEY_ID=key
// export AWS_SECRET_ACCESS_KEY=password

Appendix to the blog post.

The following assumes that the alphabet is {A, B}. The results easily generalize.

Lemma 1: Two strings S1 and S2 have no string lexicographically between them iff S1 = S2A or S2 = S1A. (Proof at end.)

Definitions:

  • Two strings S1 and S2 are adjacent iff S1 ≠ S2 and there is no S3 such that S1 < S3 < S2 or S2 < S3 < S1.

Keybase proof

I hereby claim:

  • I am addrummond on github.
  • I am alexdrummond (https://keybase.io/alexdrummond) on keybase.
  • I have a public key ASAMFkJCiG1DjIEFh9ywx_lXhw8ViQsJtN7any7dRyN2Hwo

To claim this, I am signing this object:

// ========== START OF CODE TO COPY INTO YOUR DATA FILE ==========
var IMAGES_TO_PRELOAD = [
// CHANGE THESE TO THE URLS OF THE IMAGES THAT YOU WANT TO PRELOAD
"https://upload.wikimedia.org/wikipedia/commons/thumb/e/ea/Capra_ibex_nubiana_near_Mitzpe_Ramon_in_summer_2011_%284%29.JPG/1200px-Capra_ibex_nubiana_near_Mitzpe_Ramon_in_summer_2011_%284%29.JPG",
"http://elelur.com/data_images/mammals/alpine-ibex/alpine-ibex-01.jpg"
];
define_ibex_controller({
name: "Preloader",
jqueryWidget: {