Skip to content

Instantly share code, notes, and snippets.

View arxdsilva's full-sized avatar
:octocat:
Working from home

Arthur Silva arxdsilva

:octocat:
Working from home
View GitHub Profile
@arxdsilva
arxdsilva / tokenGeneratorExample.go
Last active March 22, 2024 06:23
Golang - How to generate a random Token
package main
// https://play.golang.org/p/5VsRVVtyo-J
import (
"crypto/rand"
"fmt"
)
func tokenGenerator() string {
@arxdsilva
arxdsilva / working_directory.go
Last active February 12, 2024 13:30
How to get the current working directory in golang
package main
// More info on Getwd()
// https://golang.org/src/os/getwd.go
//
import(
"os"
"fmt"
"log"
)
@arxdsilva
arxdsilva / embed-video-and-chat.md
Created December 14, 2016 16:28
Embedding Twitch LiveStream and chat

##Parameters: Channel: the target live streamer you want to use; height: in pixels the height you want the video to be; width: in pixels the width you want the video to be.

##Video Code:

<iframe src="http://player.twitch.tv/?channel={CHANNEL}" allowfullscreen height="X" width="Y" *class="col-md-12">
</iframe>
package main
import (
"bytes"
"context"
"fmt"
"io/ioutil"
"log"
"os"
"path"
@arxdsilva
arxdsilva / not_uuid.pgsql
Last active February 18, 2022 11:18
return text if not uuid
CREATE OR REPLACE FUNCTION public.null_or_not_uuid(str text)
RETURNS text
LANGUAGE plpgsql
AS $function$
declare
struuid uuid;
begin
struuid = str::uuid;
RETURN null;
EXCEPTION WHEN invalid_text_representation THEN

Keybase proof

I hereby claim:

  • I am arxdsilva on github.
  • I am arxdsilva (https://keybase.io/arxdsilva) on keybase.
  • I have a public key ASCzXbVUKxXNY62FR-O9gUY7YH4LxVEkHEU5VHtZ1pGnTAo

To claim this, I am signing this object:

@arxdsilva
arxdsilva / URLvalidatorExample.go
Last active June 24, 2021 09:17
Golang - How to validate URL
import (
"fmt"
"github.com/asaskevich/govalidator"
)
// You can use as well instead of *url.URL a string with your URL, in this case you might drop `u.String()`
// - transformation to string in method call.
func validateURL(u *url.URL) error {
valid := govalidator.IsRequestURL(u.String())
if valid == false {
package main
import (
"context"
"database/sql"
"encoding/json"
"github.com/heroiclabs/nakama-common/runtime"
)
// InitModule registers the RPC function into the game server
@arxdsilva
arxdsilva / main.go
Last active March 20, 2021 19:11
golang struct composition
package main
import (
"fmt"
)
type A struct {
Name string
Age string
}
@arxdsilva
arxdsilva / timeout.go
Last active May 6, 2020 14:03
request timeout in golang
package main
import (
"fmt"
"io/ioutil"
"net/http"
"time"
)
func main() {