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 / 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 / findSubmatch.go
Created June 12, 2017 12:15
Simple regex submatch function example
func FindSubmatch(text string, regex string, submatch int) (ret string) {
var r = regexp.MustCompile(regex)
a := r.FindStringSubmatch(text)
if len(a) <= submatch {
ret = ""
return
}
ret = a[submatch]
ret = strings.TrimSpace(ret)
return
@crgimenes
crgimenes / parsearray.go
Last active June 1, 2017 14:24
Experimental function to parse array/slice to string compatible with array of postgresql
func parseArray(value interface{}) string {
switch value.(type) {
case []interface{}:
var aux string
for _, v := range value.([]interface{}) {
if aux != "" {
aux += ","
}
aux += parseArray(v)
}
@crgimenes
crgimenes / client.go
Created April 26, 2017 22:09 — forked from spikebike/client.go
TLS server and client
package main
import (
"crypto/tls"
"crypto/x509"
"fmt"
"io"
"log"
)
@crgimenes
crgimenes / readFromStdin.go
Created February 2, 2017 12:07
Simplest way to read from stdin
package main
import (
"fmt"
"io/ioutil"
"os"
)
func main() {
input, err := ioutil.ReadAll(os.Stdin)
@crgimenes
crgimenes / util.go
Last active January 25, 2017 08:39
Create random string with pre-defined size.
import "crypto/rand"
func RandStr(strSize int) (ret string, err error) {
alphanum := "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
var bytes = make([]byte, strSize)
_, err = rand.Read(bytes)
if err != nil {
return
}
for k, v := range bytes {
@crgimenes
crgimenes / util.go
Created January 18, 2017 10:39
create directory if not exist, also create all missing tree entries
func createDirIfNotExist(pathName string) (err error) {
if _, err = os.Stat(pathName); err != nil {
if os.IsNotExist(err) {
err = os.MkdirAll(pathName, os.ModePerm)
return
}
}
return
}