Skip to content

Instantly share code, notes, and snippets.

@psydvl
Last active November 3, 2023 19:21
Show Gist options
  • Save psydvl/9d8fcd31d4ad939eb44f3e4d639c0ea5 to your computer and use it in GitHub Desktop.
Save psydvl/9d8fcd31d4ad939eb44f3e4d639c0ea5 to your computer and use it in GitHub Desktop.
Playground folder with generating folders
*
!.gitignore
!template.go
!template.bash
!new.sh
#!/usr/bin/env bash
set -exu -o pipefail
ADDSUBL=''
ADDLAPCE=''
ADDTEMPLATE=()
main() {
for var in "$@"; do
echo "$var"
case $var in
s | a | subl) ADDSUBL=true ;;
l | lapce) ADDLAPCE=true ;;
g | go) ADDTEMPLATE+=("go") ;;
b | bash) ADDTEMPLATE+=("bash") ;;
esac
done
current=$(<./last.dir)
current=$(
printf "%03X\n" "$(echo "ibase=16;$current+1" | bc -l)"
)
mkdir "$current"
echo "$current" >last.dir
pushd "$current"
for var in "${ADDTEMPLATE[@]}"; do
case "$var" in
"go")
go mod init x
gofmt <../template.go >main.go
# echo -e 'package main;import("fmt");func main(){\nfmt.Println("Hello")}' | gofmt > main.go
popd
test $ADDSUBL && subl -a "./main.go"
;;
"bash")
cat <../template.bash >main.sh
chmod +x ./main.sh
test $ADDSUBL && subl -a "./main.sh"
;;
esac
done
popd
test $ADDSUBL && subl -a "$current"
test $ADDLAPCE && lapce "$current"
}
main "$@"
#!/usr/bin/env bash
#shellcheck disable=SC2207
set -exu
shopt -s nullglob #globstar
init() {
local scriptDir
scriptDir=$(dirname -- "$(readlink -f -- "${BASH_SOURCE[0]}")")
cd "$scriptDir"
# source "$scriptDir/x.sh"
}
init
set +x
main() {
:
}
main "$@"
// https://gist.github.com/psydvl/9d8fcd31d4ad939eb44f3e4d639c0ea5
package main
import (
"bufio"
"fmt"
"log"
"os"
stdTime "time"
)
var spent stdTime.Duration
func duration() func() {
start := stdTime.Now()
return func() {
spent += stdTime.Now().Sub(start)
}
}
func Sum(a, b int) int {
return a + b
}
func main() {
defer log.Println(&spent)
defer duration()()
// input := os.Stdin
input, _ := os.Open("input.txt")
defer input.Close()
in := bufio.NewReader(input)
output := os.Stdout
// output, _ := os.Create("output.txt")
defer output.Close()
out := bufio.NewWriter(output)
defer out.Flush()
var a, b int
fmt.Fscanf(in, "%d %d", &a, &b)
fmt.Fprintln(out, Sum(a, b))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment