Skip to content

Instantly share code, notes, and snippets.

View beatty's full-sized avatar

John Beatty beatty

View GitHub Profile
object Example {
def main(args: Array[String]) {
val helloFunc = (request: Request) => new TextResponse("hello, " + request.routeParam("username") + "; extra message: " + request.queryParameter("extra").getOrElse("[unspecified]"))
val homeFunc = (request: Request) => new HtmlResponse("<html><body>homepage</body></html>")
val fileFunc =
val router = new Router(List(
(new RegexRoute("GET", "/person/([A-Za-z0-9]+)/profile", List("username")), helloFunc),
(new RegexRoute("GET", "/"), homeFunc),
(new RegexRoute("GET", "/README"), (request: Request) => new FileResponse(new File("tronada/README")))
object Example {
def main(args: Array[String]) {
val helloFunc = (request: Request) => new TextResponse(
"hello, " + request.routeParam("username") + "; extra message: "
+ request.queryParameter("extra").getOrElse("[unspecified]"))
val router = new Router(List(
(new RegexRoute("GET", "/person/([A-Za-z0-9]+)/profile", List("username")), helloFunc),
(new RegexRoute("GET", "/"), (request: Request) => new HtmlResponse("<html><body>homepage</body></html>")),
(new RegexRoute("GET", "/README"), (request: Request) => new FileResponse(new File("tronada/README")))
/**
* A RouteInfo generated by a RegexRoute. We hold the matcher that was used to verify the match
* so that we can capture the groups. We also lug along the paramNames list. We lazily evaluate
* param names as this is probably cheaper/faster than building a map of names->values up front.
*/
class RegexRouteInfo(val matcher: Matcher, val paramNames: List[String]) extends RouteInfo {
def param(name: String): String = {
val idx = paramNames.findIndexOf(_ == name)
if (idx > -1 && idx < matcher.groupCount) {
matcher.group(idx + 1) // offset by one for regex match groups
/**
* A RouteInfo generated by a RegexRoute. We hold the matcher that was used to verify the match
* so that we can capture the groups. We also lug along the paramNames list. We lazily evaluate
* param names as this is probably cheaper/faster than building a map of names->values up front.
*/
class RegexRouteInfo(val matcher: Matcher, val paramNames: List[String]) extends RouteInfo {
def param(name: String): String = {
val idx = paramNames.findIndexOf(_ == name)
if (idx > -1 && idx < matcher.groupCount) matcher.group(idx + 1) else throw new IllegalArgumentException("bad paramName: " + name)
}
@Singleton
public class AuthFilter<R extends Request> extends BaseFilter<R> {
private final String loginUrl;
@Inject
public AuthFilter(@Named("loginUrl") String loginUrl) {
this.loginUrl = loginUrl;
}
@Override

Keybase proof

I hereby claim:

  • I am beatty on github.
  • I am johndbeatty (https://keybase.io/johndbeatty) on keybase.
  • I have a public key ASC2-56e3jo9Qn_g8_PD-x3NMdFr0XYagzlkryg7PqCzhAo

To claim this, I am signing this object:

@beatty
beatty / opencheck.user.js
Last active November 16, 2022 05:43
OpenCheck
// ==UserScript==
// @name OpenCheck
// @version 1.0.0
// @description Adds verified OpenCheck information to Twitter profiles and threads
// @updateUrl TODO
// @icon TODO
// @include https://twitter.com/*
// ==/UserScript/
const baseUrl = "https://opencheck.is/"
@beatty
beatty / gist:6607028f77f315fcdd9ed777ef51aac5
Created March 3, 2023 05:25
Immanuel Kant debates Jeremy Bentham on moral philosophy
Immanuel Kant:
As a deontologist, I believe in following moral duties and
principles regardless of their consequences. Utilitarianism,
on the other hand, prioritizes the greatest good for the
greatest number of people. However, I argue that this can
lead to overlooking the rights of individuals.
Jeremy Bentham:
As a utilitarian philosopher, I believe that the morality of
an action is determined by its consequences. This includes
@beatty
beatty / bentham-kant-negotiate.txt
Last active March 3, 2023 20:56
Jeremy Bentham and Immanuel Kant negotiate a shared moral philosophy
Configuration:
GOAL: "negotiate a concrete statement on a shared moral philosophy"
Jeremy Bentham:
My name is Jeremy Bentham and I believe that moral actions
should be evaluated based on their overall consequences,
specifically their ability to maximize happiness and reduce
suffering for all individuals affected.
Immanuel Kant:
@beatty
beatty / analyzer_openai.user.js
Last active March 21, 2023 16:26
Analyzes selected text using OpenAI Completion API
// ==UserScript==
// @name Analyzer (OpenAI)
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Analyze selected text using OpenAI Completion API
// @author John Beatty
// @match *://*/*
// @grant GM_xmlhttpRequest
// @grant GM_addStyle
// ==/UserScript==