Skip to content

Instantly share code, notes, and snippets.

View Justfile
# 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 Apr 8, 2021
Help refresh the Walgreens covid vaccine appointment page
View Walgreens-covid-userscript.md

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 Nov 17, 2019
cue installer/runner
View cue
#!/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 Sep 13, 2018
A critique of go 2 error handling draft design proposal
View go-2-error-handling-draft-design-issues.md

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 Sep 19, 2018
Go 2 error inspection for error groups.
View error-inspection-composition.md

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 Oct 3, 2018
Go 2 error handling alternative: handlers as normal functions and an error return?
View go2-error-handling-functions-with-check.md

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 Oct 13, 2015
WAI static page generator with Yesod example
View StaticRewrite.hs
-- 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
View combine.html.hamlet
$with scripts <- ["Prelude", "Config", "KV"]
^{combineScripts "app" scripts}
@gregwebs
gregwebs / static-pages.hs
Created Feb 6, 2012
Yesod Static File generator.
View static-pages.hs
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
@gregwebs
gregwebs / External.hs
Created Nov 5, 2011
addDependentFile
View External.hs
module External where
import Language.Haskell.TH.Syntax
import Language.Haskell.TH.Lib
loadStringFromFile :: Q Exp
loadStringFromFile = do
let externalDependency = "external.txt"
qAddDependentFile externalDependency
s <- qRunIO $ readFile externalDependency