Skip to content

Instantly share code, notes, and snippets.

View donvito's full-sized avatar
🚀
solo dev building apps with AI. launched aidreamphoto.com

Melvin Vivas @DonvitoCodes donvito

🚀
solo dev building apps with AI. launched aidreamphoto.com
View GitHub Profile
@donvito
donvito / main.go
Created May 25, 2020 14:16
channel
package main
import "fmt"
func main(){
c := make(chan int)
go func(){
c <- 234
@donvito
donvito / main.go
Created May 25, 2020 13:47
interfaces
package main
import "fmt"
type animal interface {
Run() string
}
type dog struct {
Name string
@donvito
donvito / main.go
Last active April 21, 2020 01:34
print map as json
package main
import (
"encoding/json"
"fmt"
"log"
)
func main() {
@donvito
donvito / main.go
Last active April 4, 2025 15:56
AES-256 encrypt/decrypt in Go
package main
import (
"crypto/aes"
"crypto/cipher"
"crypto/rand"
"encoding/hex"
"fmt"
"io"
)
@donvito
donvito / gist:183486c9752ab11128f74f32cb0cd23f
Last active March 8, 2020 02:07
scrape jobs using colly
package main
import (
"fmt"
"github.com/gocolly/colly/v2"
)
func main() {
c := colly.NewCollector(
colly.AllowedDomains("www.indeed.com.sg", "indeed.com.sg", "sg.indeed.com"),
@donvito
donvito / main.go
Created November 25, 2019 02:12
Recursion
package main
import (
"fmt"
)
func sum(x int) int {
if x <= 0 {
return 0
} else {
@donvito
donvito / balance.go
Last active November 26, 2019 14:05
Higher order functions
package main
import (
"fmt"
)
func balanceFormula(paidLate bool) func(float64, float64) float64 {
if(paidLate == true){
fn := func(principal float64, lateFee float64) float64{
@donvito
donvito / main.go
Created November 21, 2019 11:27
AWS Lambda Go example - retrieve environment variables
package main
import (
"encoding/json"
"fmt"
"log"
"os"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
@donvito
donvito / main.go
Created October 29, 2019 01:19
Go Interface example - print area of shapes
package main
import (
"fmt"
"reflect"
)
func main() {
r := Rectangle{length:5, width:10}
printArea(&r)
@donvito
donvito / main.go
Last active September 26, 2019 12:51
Go code to run a container and retrieve stdout
package main
import (
"context"
"os"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/client"
"github.com/docker/docker/pkg/stdcopy"