Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Cesar Gimenes crgimenes

🏠
Working from home
View GitHub Profile
@crgimenes
crgimenes / exemple.go
Created Sep 15, 2020
Simple function example
View exemple.go
package exemple
func MapIntervalFloat64(value, fromLow, fromHigh, toLow, toHigh float64) (ret float64) {
ret = (value-fromLow)*(toHigh-toLow)/(fromHigh-fromLow) + toLow
return
}
func SimpleMapIntervalFloat64(value, fromHigh, toHigh float64) (ret float64) {
ret = value * toHigh / fromHigh
return
@crgimenes
crgimenes / main.go
Created May 21, 2020
Detect server and client ip and port
View main.go
package main
import (
"fmt"
"net"
"net/http"
"github.com/gorilla/mux"
)
@crgimenes
crgimenes / main.go
Last active Oct 22, 2020
Web Scraping with Golang
View main.go
package main
import (
"context"
"log"
"github.com/chromedp/chromedp"
)
func main() {
@crgimenes
crgimenes / strarray.go
Last active Sep 6, 2019
Golang Example of Receiving Arrays or Strings in Same JSON Object
View strarray.go
package strarray
import (
"encoding/json"
"errors"
)
var (
// ErrUnsupportedType is returned if the type is not implemented
ErrUnsupportedType = errors.New("unsupported type")
@crgimenes
crgimenes / jwk.sql
Created Aug 9, 2019
triggers and default values (PostgreSQL)
View jwk.sql
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE OR REPLACE FUNCTION updated_datetime()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = now();
RETURN NEW;
END;
$$ language 'plpgsql';
@crgimenes
crgimenes / README.md
Last active Feb 17, 2021
Example of pagination using PostgreSQL, Golang and SQLx
View README.md

Configure environment variable

export DATABASE_URL=postgres://postgres@localhost/dbname?sslmode=disable 

Run in CLI

go run main.go -page 1
View gist:8d42ac542dba80d9fa0a71280ce2ce07

1. Clone your fork:

git clone git@github.com:YOUR-USERNAME/YOUR-FORKED-REPO.git

2. Add remote from original repository in your forked repository:

cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream
@crgimenes
crgimenes / .travis.yml
Created Oct 30, 2018 — forked from ryboe/.travis.yml
Example .travis.yml for Golang
View .travis.yml
# This is a weird way of telling Travis to use the fast container-based test
# runner instead of the slow VM-based runner.
sudo: false
language: go
# Force-enable Go modules. This will be unnecessary when Go 1.12 lands.
env:
- GO111MODULE=on
@crgimenes
crgimenes / tempFileName.go
Created Aug 3, 2018
Filename for temp files
View tempFileName.go
func newFileName() string {
buff := make([]byte, 6)
rand.Read(buff)
return fmt.Sprintf("%v-%X\n", time.Now().UTC().Format("2006-01-02T150405"), buff)
}
@crgimenes
crgimenes / draftFilesystem.go
Created Jul 13, 2018
simple filesystem example
View draftFilesystem.go
package main
import (
"context"
"flag"
"fmt"
"io"
"os"
"syscall"