Skip to content

Instantly share code, notes, and snippets.

@ItalyPaleAle
ItalyPaleAle / components---localstorage.yaml
Last active December 21, 2022 01:28
Subtle Crypto test app
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: jwks
spec:
type: crypto.localstorage
version: v1
metadata:
- name: path
value: keys
@ItalyPaleAle
ItalyPaleAle / build-dapr.sh
Last active July 31, 2023 23:51
build-dapr.sh
#!/bin/bash
set -e
DIR=$(dirname "$BASH_SOURCE")
echo "Getting into directory ${DIR}/dapr"
cd "${DIR}/dapr"
#DEBUG=1 make build
CGO_ENABLED=0 \
// Copyright (C) 2020 Alessandro Segala (ItalyPaleAle)
// License: MIT
package main
// Import the package to access the Wasm environment
import (
"syscall/js"
)
// Copyright (C) 2020 Alessandro Segala (ItalyPaleAle)
// License: MIT
// MyGoFunc returns a Go time.Time to JavaScript
func MyGoFunc() js.Func {
return js.FuncOf(func(this js.Value, args []js.Value) interface{} {
// Get the current time as a Go time.Time object
now := time.Now()
// Get the Date object constructor from JavaScript
dateConstructor := js.Global().Get("Date")
// Copyright (C) 2020 Alessandro Segala (ItalyPaleAle)
// License: MIT
// MyGoFunc returns a Promise that resolves after 3 seconds with a message
func MyGoFunc() js.Func {
return js.FuncOf(func(this js.Value, args []js.Value) interface{} {
// Handler for the Promise: this is a JS function
// It receives two arguments, which are JS functions themselves: resolve and reject
handler := js.FuncOf(func(this js.Value, args []js.Value) interface{} {
resolve := args[0]
// Copyright (C) 2020 Alessandro Segala (ItalyPaleAle)
// License: MIT
// MyGoFunc returns a Promise that fails with an exception about 50% of times
func MyGoFunc() js.Func {
return js.FuncOf(func(this js.Value, args []js.Value) interface{} {
// Handler for the Promise
handler := js.FuncOf(func(this js.Value, args []js.Value) interface{} {
resolve := args[0]
reject := args[1]
// Copyright (C) 2020 Alessandro Segala (ItalyPaleAle)
// License: MIT
// MyGoFunc fetches an external resource by making a HTTP request from Go
// The JavaScript method accepts one argument, which is the URL to request
func MyGoFunc() js.Func {
return js.FuncOf(func(this js.Value, args []js.Value) interface{} {
// Get the URL as argument
// args[0] is a js.Value, so we need to get a string out of it
requestUrl := args[0].String()
// Copyright (C) 2020 Alessandro Segala (ItalyPaleAle)
// License: MIT
// MyGoFunc fetches an external resource by making a HTTP request from Go
// The JavaScript method accepts one argument, which is the URL to request
func MyGoFunc() js.Func {
return js.FuncOf(func(this js.Value, args []js.Value) interface{} {
// Get the URL as argument
// args[0] is a js.Value, so we need to get a string out of it
requestUrl := args[0].String()
# The MIT License
Copyright (c) 2020, Alessandro Segala
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@ItalyPaleAle
ItalyPaleAle / authorize.go
Created February 7, 2020 02:21
Authorize Azure SDKs for Go with a Service Principal (Azure AD token), including Azure Storage SDK for Go
package main
import (
"fmt"
"time"
"github.com/Azure/azure-storage-blob-go/azblob"
"github.com/Azure/go-autorest/autorest"
"github.com/Azure/go-autorest/autorest/adal"
"github.com/Azure/go-autorest/autorest/azure"