this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

{urldecode,urlencode}: add things

+82
+43
urldecode/main.go
··· 1 + package main 2 + 3 + import ( 4 + "bufio" 5 + "context" 6 + "fmt" 7 + "io" 8 + "net/url" 9 + "os" 10 + "os/signal" 11 + ) 12 + 13 + func main() { 14 + ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt) 15 + defer cancel() 16 + 17 + if err := realMain( 18 + ctx, 19 + os.Stdin, 20 + os.Stdout, 21 + os.Stderr, 22 + os.Args, 23 + ); err != nil { 24 + fmt.Fprintf(os.Stderr, "%s\n", err) 25 + os.Exit(1) 26 + } 27 + } 28 + 29 + func realMain(_ context.Context, stdin io.Reader, stdout io.Writer, _ io.Writer, _ []string) error { 30 + buf := make([]byte, 0, 64*1024) 31 + scanner := bufio.NewScanner(stdin) 32 + scanner.Buffer(buf, 10*1024*1024) 33 + for scanner.Scan() { 34 + line := scanner.Text() 35 + encoded, err := url.QueryUnescape(line) 36 + if err != nil { 37 + fmt.Fprintf(os.Stderr, "Error decoding URL: %s\n", err) 38 + } 39 + fmt.Fprintln(stdout, encoded) 40 + } 41 + 42 + return scanner.Err() 43 + }
+39
urlencode/main.go
··· 1 + package main 2 + 3 + import ( 4 + "bufio" 5 + "context" 6 + "fmt" 7 + "io" 8 + "net/url" 9 + "os" 10 + "os/signal" 11 + ) 12 + 13 + func main() { 14 + ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt) 15 + defer cancel() 16 + 17 + if err := realMain( 18 + ctx, 19 + os.Stdin, 20 + os.Stdout, 21 + os.Stderr, 22 + os.Args, 23 + ); err != nil { 24 + fmt.Fprintf(os.Stderr, "%s\n", err) 25 + os.Exit(1) 26 + } 27 + } 28 + 29 + func realMain(_ context.Context, stdin io.Reader, stdout io.Writer, _ io.Writer, _ []string) error { 30 + scanner := bufio.NewScanner(stdin) 31 + 32 + for scanner.Scan() { 33 + line := scanner.Text() 34 + encoded := url.QueryEscape(line) 35 + fmt.Fprintln(stdout, encoded) 36 + } 37 + 38 + return scanner.Err() 39 + }