Skip to content

Instantly share code, notes, and snippets.

@gregwebs
gregwebs / index.html
Created October 24, 2024 17:54
OCR drag and drop files in browser with Tesseract.js
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Image to Text Converter</title>
<script src="https://cdn.jsdelivr.net/npm/tesseract.js@2.1.1/dist/tesseract.min.js"></script>
<style>
body {
font-family: Arial, sans-serif;
# This is as Justfile: https://github.com/casey/just#readme
tiup:
TZ=UTC tiup playground --db 1 --kv 1 --pd 1
tidb-erase-data:
rm -r ~/tidb/tikv/data
rm -r ~/go/src/github.com/tikv/pd/data
aws-local +args:
@env DOCKER_TERM_ARGS="--network=host" AWS_PROFILE=localstack AWS_VAULT=OFF AWS_ACCESS_KEY_ID=test AWS_SECRET_ACCESS_KEY=test {{args}}
@gregwebs
gregwebs / Walgreens-covid-userscript.md
Last active December 25, 2021 14:01
Help refresh the Walgreens covid vaccine appointment page

UserScript for refreshing the Walgreens covid vaccine appointment page

Please note that you must be eligible to get the vaccine. If you are not eligible for the vaccine, this will not help you. In that case the only thing you can do is try showing up at the end of the day at a vaccination site to see if they have any leftovers that need to be used up.

This script will check a box stating that you are elligible according to your state.

Installation

@gregwebs
gregwebs / cue
Created November 17, 2019 01:16
cue installer/runner
#!/usr/bin/env bash
set -euo pipefail
CUE_VERSION=${CUE_VERSION:-"0.0.14"}
export PATH="./bin:$PATH"
function extract() {
set -x
if ! [[ -f bin/"cue-${CUE_VERSION}" ]] ; then
@gregwebs
gregwebs / go-2-error-handling-draft-design-issues.md
Last active September 13, 2018 22:09
A critique of go 2 error handling draft design proposal

go 2 has laid out the problem of error handling (Please read first). A wiki page was suggested for feedback. The feedback overwhelmingly suggested ways to not use scoped handlers, essentially creating alternative proposals

It is amazing to see the error handling problem being properly addressed. The existing proposal is good, but I think we can iterate to make it better. I think we can simplify it and address these issues:

  • Defining handlers as a stack is presumptious: it forces handlers to be side-effecting, and ruins interop with defer.
  • return statements are placed in handlers, ruining composition.
  • using check as a prefix function reduces code clarity.
  • a new anonymous function syntax is introduced into the proposal, but only avail
@gregwebs
gregwebs / error-inspection-composition.md
Last active September 19, 2018 09:58
Go 2 error inspection for error groups.

The current error proposal for inspection is great. I have two minor suggestions:

  • rename Wrapper to Unwrapper
  • change the function name from "As" to "Find"

The words "As" someties indicates casting, but we are just doing a retrieval.

Handling error groups

The current error inspection proposal laments not having a way to deal with error groups.

@gregwebs
gregwebs / go2-error-handling-functions-with-check.md
Last active October 3, 2018 20:52
Go 2 error handling alternative: handlers as normal functions and an error return?

Its amazing to see the error handling problem being properly addressed. The existing proposal is good, but I think we can iterate to make it better. I think we can simplify it and address these issues:

  • Defining handlers as a stack is presumptious: it forces handlers to be side-effecting, and ruins interop with defer.
  • return statements are placed in handlers, ruining composition.
  • using check as a prefix function reduces code clarity.
  • a new anonymous function syntax is introduced into the proposal, but only available to handle.
  • the proposal introduces two keywords, but one may suffice

It's useful to take a step back and clearly state what we are trying to do:

@gregwebs
gregwebs / StaticRewrite.hs
Last active October 13, 2015 11:48
WAI static page generator with Yesod example
-- something like this can be used to make friendlier urls for the static pages
-- import Network.Wai.Middleware.Rewrite (rewritePure)
-- rewritePure rewriteConvert
rewriteConvert :: [Text] -> H.RequestHeaders -> [Text]
rewriteConvert pieces _ = staticRewrite pieces
where
staticRewrite :: [Text] -> [Text]
staticRewrite [] = homePage
staticRewrite ("static":"html":_) = homePage -- prevent direct access, not really necessary
staticRewrite route@("pages":_) | ".html" `T.isSuffixOf` last route = staticHtml ++ route
$with scripts <- ["Prelude", "Config", "KV"]
^{combineScripts "app" scripts}
@gregwebs
gregwebs / static-pages.hs
Created February 6, 2012 12:13
Yesod Static File generator.
import Prelude
import Yesod.Routes.Parse (staticPageRoutes)
import Yesod hiding (Request)
import Text.Hamlet
import Network.Wai
import Network.Wai.Test
import Data.Conduit (runResourceT)
import Blaze.ByteString.Builder (toLazyByteString)
import qualified Data.ByteString.Char8 as BS8
import qualified Data.ByteString.Lazy as LBS