Skip to content

Instantly share code, notes, and snippets.

View bgadrian's full-sized avatar
✍️
available for OSS Go packages

B.G.Adrian bgadrian

✍️
available for OSS Go packages
View GitHub Profile
@bgadrian
bgadrian / mockclient.js
Created September 20, 2023 08:37
mock client
// Static strings.
const UNEXPECTED_ERROR_MESSAGE = "An unexpected error occurred while processing your request.";
//define a type of Config
class Client {
constructor(config) {
this.dry_run = config.dry_run;
this.api_key = config.api_key;
this.base_path = config.base_path;
@bgadrian
bgadrian / slicestricks.go
Created May 14, 2020 21:22
go slices more tricks
// StringToImmutableBytes returns a slice of bytes from a string without allocating memory
// it is the caller's responsibility not to mutate the bytes returned.
func StringToImmutableBytes(s string) []byte {
if len(s) == 0 {
return nil
}
// NB(xichen): We need to declare a real byte slice so internally the compiler
// knows to use an unsafe.Pointer to keep track of the underlying memory so that
@bgadrian
bgadrian / docker.datadirectory
Created November 23, 2019 18:32
Docker change the data directory (Images, containers) on Ubuntu
According to the official documentation, as of Feb 2019, there are no --graph, -g options. These were renamed to the single argument --data-root.
vim /lib/systemd/system/docker.service so that the ExecStart takes into consideration that argument
ExecStart=/usr/bin/dockerd --data-root /mnt/data/docker -H fd://
systemctl daemon-reload
service docker restart
bytes := []bytes //string here, can be reused or kept on stack
stringVal := *(*string)(unsafe.Pointer(&bytes))
@bgadrian
bgadrian / publicip.sh
Created January 1, 2019 19:24
Get my public IP
dig @resolver1.opendns.com ANY myip.opendns.com +short
@bgadrian
bgadrian / hugo.yml
Created December 28, 2018 15:15
Hugo deployment to gitlab/github eg: .gitlab-ci.yml
image:
name: klakegg/hugo:0.53-ext-alpine
entrypoint: [""]
pages:
script:
- hugo
artifacts:
paths:
- public
@bgadrian
bgadrian / hugo_lazy_img.md
Last active May 1, 2020 19:46
Hugo lazy image loading

I presume the images are bundled as post resources in the ./images/ folder.

It creates a new version at 5% of its original quality that is fetched in the initial page load. When and if the original image is loaded by the browser it will replace the low quality one.

{{< lazyimg "images/1.jpeg" >}} {{< lazyimg "images/1.jpeg" "caption" >}}

@bgadrian
bgadrian / .gitignore
Created December 19, 2018 20:15
Global git ignore for any system
.idea/
.vs/
.env
.pk
.pem
.pub
@bgadrian
bgadrian / http.request_mock.go
Created December 15, 2018 15:57
Fake a HTTP Request/Client.Do response w/o a webserver.
type recordingTransport struct {
req *http.Request
}
func (t *recordingTransport) RoundTrip(req *http.Request) (resp *http.Response, err error) {
t.req = req
return &http.Response{
Body: ioutil.NopCloser(bytes.NewBufferString("alfa")),
}, nil
@bgadrian
bgadrian / Makefile
Last active November 5, 2018 05:49
Go 1.11 makefile example
# Makefile example from https://github.com/bgadrian/pseudoservice
# GO111MODULE is required only when inside GOPATH
source := ./cmd/pseudo-service-server/main.go
#this will be triggered before any command, or when just calling $ make
pre:
mkdir -p ./build/
env GO111MODULE=on go get -d ./
env GO111MODULE=on go test -race ./...