Skip to content

Instantly share code, notes, and snippets.

View crgimenes's full-sized avatar
🏠
Working from home

Cesar Gimenes crgimenes

🏠
Working from home
View GitHub Profile
@crgimenes
crgimenes / main.go
Created March 3, 2024 02:09
Simple http dump server
package main
import (
"flag"
"fmt"
"log"
"net/http"
"net/http/httputil"
)
@crgimenes
crgimenes / fullauto.cpp
Created February 2, 2024 03:36 — forked from felipemanga/fullauto.cpp
Improved devterm automatic gearbox
// Compile like this: g++ fullauto.cpp --std=c++17 -o fullauto
// Run like this: sudo fullauto &
#include <thread>
#include <chrono>
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
@crgimenes
crgimenes / Update Golang *Nix
Last active November 16, 2023 12:26 — forked from jniltinho/update-golang.sh
update-golang.sh
#!/bin/bash
## Update Golang (Linux/Mac)
go version
## Get Last Stable Version
LAST_VERSION=$(curl -s 'https://go.dev/VERSION?m=text'|head -n1)
os="linux"
if [ "$(uname -s)" = "Darwin" ]; then
@crgimenes
crgimenes / json2tuple.py
Created February 14, 2023 14:29
Convert json to tuple (to be used in CSV generation for example)
import json
def json_titles_tuple(payload_json, prefix=''):
jsonobj = json.loads(payload_json)
titles = ()
for key, value in jsonobj.items():
if isinstance(value, dict):
titles += json_titles_tuple(json.dumps(value), prefix + key + '_')
else:
titles += (prefix + key,)
@crgimenes
crgimenes / main.go
Created September 5, 2021 12:58
AWS Lambda to return client ip
package main
import (
"net/http"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
)
func handler(request events.APIGatewayProxyRequest) (*events.APIGatewayProxyResponse, error) {
@crgimenes
crgimenes / exemple.go
Created September 15, 2020 21:19
Simple function example
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 21:11
Detect server and client ip and port
package main
import (
"fmt"
"net"
"net/http"
"github.com/gorilla/mux"
)
@crgimenes
crgimenes / main.go
Last active February 6, 2023 23:18
Web Scraping with Golang
package main
import (
"context"
"log"
"github.com/chromedp/chromedp"
)
func main() {
@crgimenes
crgimenes / strarray.go
Last active December 14, 2023 21:17
Golang Example of Receiving Arrays or Strings in Same JSON Object
package strarray
import (
"encoding/json"
"errors"
)
var (
// ErrUnsupportedType is returned if the type is not implemented
ErrUnsupportedType = errors.New("unsupported type")
@crgimenes
crgimenes / README.md
Last active July 12, 2023 09:42
Example of pagination using PostgreSQL, Golang and SQLx

Configure environment variable

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

Run in CLI

go run main.go -page 1