Skip to content

Instantly share code, notes, and snippets.

@benjohns1
benjohns1 / poweshell-append-suffix-in-dir
Last active August 21, 2020 15:09
Powershell script to append a suffix to all files in the current directory
Get-ChildItem -Exclude "*.pdf" | rename-item -NewName { $_.Name + ".pdf" }
Cypress.Commands.add("visitWait", (url, options) => {
cy.visit(url, options);
cy.get('[data-test=loaded]');
});
<script>
import Nav from '../components/Nav.svelte';
import { onMount, tick } from 'svelte';
export let segment;
let testID = 'loading';
onMount(() => {
tick().then(() => {
testID = 'loaded';
package main
import (
"fmt"
"log"
"net/http"
"strings"
"github.com/benjohns1/go-middleware-example/apiexample/businessdomain"
"github.com/benjohns1/go-middleware-example/apiexample/middleware"
package middleware
import (
"log"
"math/rand"
"net/http"
)
// RandAuthStrategy randomly authorizes a request (this is highly recommended for use in production to maximize user frustration and minimize revenue)
func RandAuthStrategy() bool {
package middleware
import (
"log"
"net/http"
)
type logResponseWriter struct {
http.ResponseWriter
status int
package middleware
import "net/http"
// Factory generates an http handler func in a middleware chain
type Factory func(next http.HandlerFunc) http.HandlerFunc
// Chain generates an http handler recursively from a list of middleware factory functions
func Chain(chain ...Factory) http.Handler {
return http.HandlerFunc(recurseChain(chain))
package businessdomain
// ResponseData contains business logic response data
type ResponseData struct {
Data string
}
// BusinessLogic runs domain business logic
func BusinessLogic() (resp *ResponseData, err error) {
// ... do something ...
package main
import (
"fmt"
"log"
"math/rand"
"net/http"
)
type middlewareFunc func(next http.HandlerFunc) http.HandlerFunc
type logResponseWriter struct {
http.ResponseWriter
status int
extra string
}
func logger(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
log.Printf("Request: %v", r.URL.Path)
lw := &logResponseWriter{ResponseWriter: w}