Skip to content

Instantly share code, notes, and snippets.

View gustavohenrique's full-sized avatar

Gustavo Henrique gustavohenrique

View GitHub Profile
@gustavohenrique
gustavohenrique / postgres-python-recommendation.md
Created October 27, 2021 12:33
Building a recommendation engine inside Postgres with python and pandas

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

@gustavohenrique
gustavohenrique / wireguard-docker.sh
Created October 4, 2021 18:31
Run Wireguard VPN peer
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 July 9, 2021 14:35
Seafile is an open source alternative to Dropbox

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 June 29, 2021 10:11
HTML + JS + SharedWorker

SharedWorker

Remember:

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

index.html

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 April 25, 2024 21:06
Basic commands to run LXD containers

install

sudo snap install lxd && lxd init

Init

lxd init --preseed <<EOF

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 April 14, 2023 23:23
Arch Linux installation and setup

Installation

loadkeys us-acentos

Network

Wireless connection

@gustavohenrique
gustavohenrique / read-file-performance-golang.go
Created July 14, 2020 22:48
Its very good for large files
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]
@gustavohenrique
gustavohenrique / udev-rules.md
Created May 7, 2020 17:46
Writing udev rules for development boards

When developing hardware, one encounters two problems:

The JTAG adapter (or the like) isn’t visible to the JTAG programmer running as a process under an unprivileged user.
There are approximately eleven USB-Serial adapters plugged in and they arrange themselves through a fair dice roll on every reboot.

Sometimes coughFTDIcough you could even encounter both with the same device! Exciting!

This note is Linux-specific.

Matching a device series