Skip to content

Instantly share code, notes, and snippets.

package users
import (
"encoding/json"
)
// UserProfile contains all the information details of a given user
type UserProfile struct {
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
package main
import (
"fmt"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
)
func main() {
// https://play.golang.org/p/2LBJbIBVw37
package main
import (
"fmt"
)
type Foo struct {
name string
}
// https://play.golang.org/p/jUzWcBiO4xJ
// Output:
// B 0
// A 0
// end
package main
import (
"fmt"
@suzuki-shunsuke
suzuki-shunsuke / check-broken-url.sh
Created December 1, 2018 09:29
shell script to check whether broken urls are included in files
s=0
for url in `find ./test -name "*" -type f | xargs xurls | grep -v "ldap.*"`; do
if ! `curl -LI $url -o /dev/null --fail -s`; then
echo $url
s=1
fi
done
if [ $s -ne 0 ]; then
exit 1
fi
@suzuki-shunsuke
suzuki-shunsuke / check-broken-url.sh
Last active December 1, 2018 09:30
shell script to check whether broken urls are included in files
# xurls: https://github.com/mvdan/xurls
s=0
for url in `find . -name "*" -type f | xargs xurls | grep -v "ldap.*"`; do
if ! `curl -LI $url -o /dev/null --fail -s`; then
echo $url
s=1
fi
done
if [ $s -ne 0 ]; then
exit 1
@suzuki-shunsuke
suzuki-shunsuke / create-docker-config-json.sh
Last active August 4, 2019 03:07
The one liner to create a ~/.docker/config.json for CI/CD. The environment variables USER_NAME, PASSWORD, and REGISTRY are parameters to login the Docker registry.
docker run -v /var/run/docker.sock:/var/run/docker.sock -ti --rm -e USER_NAME=$USER_NAME -e PASSWORD=$PASSWORD docker:19.03.1 sh -c 'echo $PASSWORD | docker login $REGISTRY --username $USER_NAME --password-stdin > /dev/null 2> /tmp/error.txt && cat /root/.docker/config.json || (cat /tmp/error.txt >&2 && exit 1)'
@suzuki-shunsuke
suzuki-shunsuke / dctag.sh
Created August 7, 2019 11:09
The shell function to list Docker image tags. It depends on https://github.com/genuinetools/reg .
dctag() {
if [ $# -eq 0 -o "$1" = "help" -o "$1" = "--help" -o "$1" = "-help" ]; then
cat << EOS
List Docker image tags
Usage: $ dctag <image name>
ex. $ dctag alpine
EOS
return 0
fi
if [ $# -ne 1 ]; then
@suzuki-shunsuke
suzuki-shunsuke / send-pr.sh
Last active September 20, 2019 12:56
The shell function to create a pull request from the current feature branch.
send-pr() {
local remote=`git config branch.master.remote`
local remote_url=`git config remote.${remote}.url`
case "$remote_url" in
https://github.com*)
git-pr
;;
https://ghe.example.com*)
ghe-pr
;;
package main
import (
"fmt"
"os"
"os/exec"
)
func main() {
cmd := exec.Command("sh", "-c", "ls | fzf")