Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Making an impact

Mark McDonnell Integralist

🎯
Making an impact
View GitHub Profile
@Integralist
Integralist / difference between URL host and Request Header Host.md
Created Jul 29, 2021
[difference between URL host and Request Header Host] #go #golang #http #url #host
View difference between URL host and Request Header Host.md

The r.URL field is created by parsing the HTTP request URI.

The r.Host field is the value of the Host request header. It's the same value as calling r.Header.Get("Host").

If the HTTP request on the wire is:

GET /pub/WWW/TheProject.html HTTP/1.1
Host: www.example.org:8080
@Integralist
Integralist / word-motion-to-be-camelcase-sensitive.viml
Created Jul 27, 2021
[Vim word motion to be camelcase sensitive] #vim #viml
View word-motion-to-be-camelcase-sensitive.viml
function! Word()
" Get cursor current position
let curpos = getpos(".")
" Apply movement
normal! w
" Get cursor potential next position
let wcurpos = getpos(".")
" Return cursor to original place
call setpos(".", curpos)
" Get the string between the two cursor positions
@Integralist
Integralist / Go API JSON Issues.md
Created Jun 23, 2021
[Go API JSON Issues] #go #golang #json #api #omitempty
View Go API JSON Issues.md

Reference: https://willnorris.com/2014/05/go-rest-apis-and-pointers/

If a struct field isn't populated, and is marshalled to JSON, then the field's zero value will be used (e.g. type string zero value == "", type int zero value == 0).

You can use omitempty to prevent the field from being marshalled, but then you won't know if the zero value was intentional or not (e.g. a user might want to set an type int field to zero or a type string field to an empty string).

To avoid that situation you need to have the field be set to a pointer of the type. This is because the zero value for a pointer is nil. This means if the field is nil then the field was never set but if it looks like a zero value for the type being pointed to, then you know it was set to the zero value intentionally.

@Integralist
Integralist / kbd vs code vs pre vs samp.md
Last active Jun 22, 2021
[kbd vs code vs pre vs samp] #kbd #markup #render #code
View kbd vs code vs pre vs samp.md
  • <kbd> represents keyboard input.
  • <samp> represents sample computer output.
  • <code> represents programming code input as an inline element.
  • <pre> represents programming code input as a block-level markup.
@Integralist
Integralist / PHP - setup Composer with local code.md
Last active Jun 10, 2021
[PHP: setup Composer with local code] #php #composer #local
View PHP - setup Composer with local code.md

Install Composer

  • macOS comes with php version 7.3.24
  • Download composer (instructions) and move binary to your $PATH
  • Create a new project directory (e.g. ~/path/to/your/code/project)
  • Run $ composer init and select the 'project' package type.

Debugging

For debugging use https://github.com/tacnoman/dephpugger (e.g. composer require tacnoman/dephpugger).

@Integralist
Integralist / go type asserting coercing.go
Created Jun 8, 2021
[go type asserting/coercing] #go #golang #type #assert #coerce
View go type asserting coercing.go
/*
bar and baz are structs with pointer reference to a foo struct.
there's a fooer interface for the foo struct
we also have a function that accepts a fooer
the purpose of the function is to coerce the arg from an interface type to a concrete type
*/
package main
import (
"fmt"
@Integralist
Integralist / golang embed static file inside of compiled binary.go
Last active Jun 2, 2021
[golang embed static file inside of compiled binary] #go #golang #embed #static
View golang embed static file inside of compiled binary.go
// Refer to https://tip.golang.org/pkg/embed/ for lots of examples
//
// Here are some embed patterns to try (these can be layered on top of each other with a single variable!):
//
// downloads/* -> embed.FS
// image/ css/ js/ -> embed.FS
// favicon.ico robots.txt index.html -> embed.FS
//
// When using `var f embed.FS` you can then utilise that type's methods:
//
@Integralist
Integralist / README.md
Last active Jun 3, 2021
[golang custom http client] #go #golang #http #client #timeouts
View README.md
@Integralist
Integralist / git multiple branches.bash
Created Jun 2, 2021
[git multiple branches] #git
View git multiple branches.bash
# do some work
cd ./repo
git checkout some_feature
# I need to make a hotfix, but I don't want to disturn my messy 'some_feature' branch
# I don't want to have to stash things and get things cleaned up
# So I create a new 'worktree'
git worktree list
git worktree add ../hotfix
@Integralist
Integralist / Nested struct embedding.go
Created May 25, 2021
[Go nested struct embedding] #go #golang #struct #embed
View Nested struct embedding.go
package main
import (
"fmt"
)
type Optional struct {
WasSet bool
}