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 / execHelper.go
Created April 20, 2018 12:45
simple exec example
func execHelper(path, name string, arg ...string) (err error) {
cmd := exec.Command(name, arg...)
cmd.Dir = path
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err = cmd.Run()
return
}
@crgimenes
crgimenes / closer.go
Created June 14, 2018 19:11
closer and tests
package helper
// closer close descriptor and log error
func closer(f io.Closer) {
err := f.Close()
if err != nil {
log.Errorln("closing ", err)
}
}
@crgimenes
crgimenes / draftFilesystem.go
Created July 13, 2018 00:38
simple filesystem example
package main
import (
"context"
"flag"
"fmt"
"io"
"os"
"syscall"
@crgimenes
crgimenes / tempFileName.go
Created August 3, 2018 19:54
Filename for temp files
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 / 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 / gates.lisp
Last active May 21, 2021 02:12
Creates a fake NAND gate and then creates all gates from NAND.
;;;; Creates a fake NAND gate and then creates all gates from NAND.
;;;; This is just an exercise, obviously has no practical application.
;;; NAND
(defun !& (a b) (if (and (= a 1) (= b 1)) 0 1))
;;; NOT
(defun ! (a) (!& a 1))
;;; AND
@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 / 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 / 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,)