Skip to content

Instantly share code, notes, and snippets.

Avatar

Gustavo Henrique gustavohenrique

View GitHub Profile
View openurl.go
func openURL(url string) error {
var err error
switch runtime.GOOS {
case "linux":
err = exec.Command("xdg-open", url).Start()
case "windows":
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", "http://localhost:4001/").Start()
case "darwin":
err = exec.Command("open", url).Start()
default:
@gustavohenrique
gustavohenrique / postgres-python-recommendation.md
Created Oct 27, 2021
Building a recommendation engine inside Postgres with python and pandas
View postgres-python-recommendation.md

I'm a big fan of data in general. It can tell you a lot about what users are doing and help gain all sorts of insights. One such aspect is in making recommendations based on past history or others that have made similar choices. Years ago in fact I wrote a small app that I used among some friends to see if I could recommend wines based on how other ones were rated. It was a small app I shared among just a handful of friends, some with similar taste some with different taste. It at first was largely an academic exercise of writing a recommendation engine, but if I could find some new wines I liked along the way great. Turns out it was a lot more effective at recommending things than I expected, even with only a small handful of wines rated.

The other thing I'm a fan of is Postgres (not a big surprise there), and earlier today I was starting to wonder why couldn't I do more machine learning directly inside it. Yeah, there is madlib, but what if I wanted to write my own recommendation engine. So I set out

View wireguard-docker.sh
export WG_ADMIN_PASSWORD=`xxd -l4 -ps /dev/urandom`
export WG_WIREGUARD_PRIVATE_KEY=`docker run --rm place1/wg-access-server wg genkey` # OC+tBxEc/OFBFEO6Kcn92CWjaahBNBtcAgfhkjNII0E=
docker run \
-d \
--name wireguard \
--cap-add NET_ADMIN \
--device /dev/net/tun:/dev/net/tun \
-v wg-access-server-data:/data \
-e "WG_ADMIN_PASSWORD=$WG_ADMIN_PASSWORD" \
@gustavohenrique
gustavohenrique / seafile-cloud-storage.md
Last active Jul 9, 2021
Seafile is an open source alternative to Dropbox
View seafile-cloud-storage.md

Seafile

Server

Create the LXD container

# Create LXD profile for data storage
mkdir /home/gustavo/Cloud
cat > ~/Cloud/cloud.profile <<EOF
@gustavohenrique
gustavohenrique / sharedworker.md
Created Jun 29, 2021
HTML + JS + SharedWorker
View sharedworker.md

SharedWorker

Remember:

  • Worker does not have DOM access
  • console.log does not work
  • The state is shared between tabs

index.html

View dgraph-client.go
package main
import (
"context"
"fmt"
"log"
"net/http"
"github.com/dgraph-io/dgo/v210"
"github.com/dgraph-io/dgo/v210/protos/api"
@gustavohenrique
gustavohenrique / lxd-snippets.md
Last active Nov 27, 2021
Basic commands to run LXD containers
View lxd-snippets.md

install

sudo snap install lxd && lxd init

images

Default repositories:

View shell-variables.md

How do I set and unset shell variable options?

I use -o to set and +o to unset. Example:

# Exit immediately
set -o errexit

# Don't exit immediately
set +o errexit
@gustavohenrique
gustavohenrique / archlinux.md
Last active Dec 7, 2021
Arch Linux installation and setup
View archlinux.md

Installation

loadkeys us-acentos

Network

Wireless connection

View read-file-performance-golang.go
func main() {
s := time.Now()
args := os.Args[1:]
if len(args) != 6 { // for format LogExtractor.exe -f "From Time" -t "To Time" -i "Log file directory location"
fmt.Println("Please give proper command line arguments")
return
}
startTimeArg := args[1]
finishTimeArg := args[3]