Skip to content

Instantly share code, notes, and snippets.

View tenderlove's full-sized avatar
©️
 ​[object Object] :trollface:

Aaron Patterson tenderlove

©️
 ​[object Object] :trollface:
View GitHub Profile
@tenderlove
tenderlove / test.rb
Last active September 27, 2023 16:00
require "strscan"
class Lexer
IDENTIFIER = /[_A-Za-z][_0-9A-Za-z]*\b/
IGNORE = %r{
(?:
[, \c\r\n\t]+ |
\#.*$
)*
}x
@tenderlove
tenderlove / h2_puma.rb
Last active September 4, 2023 17:30
Demo HTTP/2 server with Puma
require 'socket'
require 'openssl'
require 'puma/server'
require 'ds9'
class Server < DS9::Server
def initialize socket, app
@app = app
@read_streams = {}
@write_streams = {}
# An example of calculating least-squares linear regression fit in Ruby
#
# This is free and unencumbered software released into the public domain.
#
# Anyone is free to copy, modify, publish, use, compile, sell, or
# distribute this software, either in source code form or as a compiled
# binary, for any purpose, commercial or non-commercial, and by any
# means.
#
# In jurisdictions that recognize copyright laws, the author or authors
#!/usr/bin/env ruby -KU
TIMES = 100000
require 'rubygems'
gem 'addressable', '~>2.0'
gem 'faker', '~>0.3.1'
gem 'rbench', '~>0.2.3'
require 'addressable/uri'
@tenderlove
tenderlove / z-wave-uart.md
Created February 4, 2018 00:41
Aeotec Z-Wave Z-Stick Gen 5 UART protocol

Z-Stick Serial API

The Z-Stick does bi-directional communication over a UART. The connection speed is 115200, '8N1'. There are "requests" and "responses". The client software can make requests to the Z-Stick, and it will send responses. But it seems the Z-Stick can make requests of the client software too. I have yet to figure out the requests the Z-Stick sends to the client software.

Packets

cons = fn (a, b) -> fn x -> x.(a, b) end end
car = fn (p) -> p.(fn (q, _) -> q end) end
cdr = fn (p) -> p.(fn (_, q) -> q end) end
each = fn (list, func) ->
iter = fn (list, func, next) ->
(fn (a, nil) -> func.(a)
(a, b) -> func.(a); next.(b, func, next)
end).(car.(list), cdr.(list))
end
iter.(list, func, iter)
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<link type="text/css" rel="stylesheet" href="style.css"/>
<script src="http://d3js.org/d3.v3.min.js"></script>
<style>
.node circle {
cursor: pointer;
fill: #fff;
require "benchmark/ips"
require "graphql/language/lexer"
require "graphql/language/token"
require "graphql/language/block_string"
schema = DATA.read
Benchmark.ips { |x|
x.report("graphql") { GraphQL::Language::Lexer.tokenize(schema) }
}
# Okasaki style Functional Red Black Tree
# https://www.cs.tufts.edu/comp/150FP/archive/chris-okasaki/redblack99.pdf
#
# leaves and root are black
# BST
# No red node has a red child
# Every path from the root to a leaf has the same number of black nodes
module RBTree
class Leaf
From b5aeef5703dab7da9ebb47cc20e4c8b64f7f5866 Mon Sep 17 00:00:00 2001
From: Aaron Patterson <aaron.patterson@gmail.com>
Date: Thu, 12 Mar 2020 10:25:48 -0700
Subject: [PATCH] Fix possible XSS vector in JS escape helper
This commit escapes dollar signs and backticks to prevent JS XSS issues
when using the `j` or `javascript_escape` helper
CVE-2020-5267
---