Skip to content

Instantly share code, notes, and snippets.

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

Joshua Rubin joshuarubin

🏠
Working from home
View GitHub Profile
Verifying my Blockstack ID is secured with the address 1KtZbxfSncmJSwXUdsmAVgJfksZW6xhTWT https://explorer.blockstack.org/address/1KtZbxfSncmJSwXUdsmAVgJfksZW6xhTWT
@joshuarubin
joshuarubin / init.vim
Last active February 7, 2023 06:28
Minimal neovim configuration for go (golang)
" Minimal neovim configuration for go
"
" deoplete requires neovim, so this will not work with regular vim
"
" prereqs:
" - neovim
" - neovim python3 (pip3 install --upgrade neovim)
"
" includes:
" - syntax checking on save (using neomake, go and gometalinter)
@joshuarubin
joshuarubin / zsh-unicode9.patch
Created November 29, 2016 07:55
zsh unicode9
diff --git a/Src/compat.c b/Src/compat.c
index 81afd4d..02412b3 100644
--- a/Src/compat.c
+++ b/Src/compat.c
@@ -635,7 +635,18 @@ strtoul(nptr, endptr, base)
#endif /* HAVE_STRTOUL */
/**/
-#if defined(BROKEN_WCWIDTH) && (defined(__STDC_ISO_10646__) || defined(__APPLE__))
+#ifdef ENABLE_UNICODE9
// Replace reimplements bytes.Replace in a way that can reuse the buffer
func Replace(s, old, new []byte, n int, buf *bytes.Buffer) error {
m := 0
if n != 0 {
// Compute number of replacements.
m = bytes.Count(s, old)
}
if buf == nil {
@joshuarubin
joshuarubin / hodor7.go
Last active September 29, 2016 19:59
hodor7
// Processor implements an io.Reader
type Processor struct {
Src io.Reader
Old, New []byte
ChunkSize int
buf, rbuf bytes.Buffer
}
// Reset the processor
func (m *Processor) Reset(src io.Reader) {
@joshuarubin
joshuarubin / hodor6.go
Last active July 18, 2016 18:28
hodor6
func Process(w io.Writer, r io.Reader) error {
var buf, rbuf bytes.Buffer
for {
_, err := io.CopyN(&buf, r, DefaultChunkSize)
if err != nil && err != io.EOF {
return err
}
if rerr := Replace(buf.Bytes(), []byte("hodor"), []byte("hold the door"), -1, &rbuf); rerr != nil {
return rerr
@joshuarubin
joshuarubin / hodor5.go
Last active July 18, 2016 18:04
hodor5
// DefaultChunkSize is the default amount of data read from an io.Reader
const DefaultChunkSize = 1024 * 16
// Process starts to stream data
func Process(r io.Reader) (io.Reader, error) {
var buf, rbuf, result bytes.Buffer
for {
_, err := io.CopyN(&buf, r, DefaultChunkSize)
if err != nil && err != io.EOF {
func process(r io.Reader) (io.Reader, error) {
data, err := ioutil.ReadAll(r)
if err != nil {
return nil, err
}
return strings.NewReader(strings.Replace(string(data), "hodor", "hold the door", -1)), nil
}
@joshuarubin
joshuarubin / hodor3.go
Last active July 17, 2016 22:23
hodor3
func process(text string) string {
return strings.Replace(text, "hodor", "hold the door", -1)
}
@joshuarubin
joshuarubin / hodor2.go
Last active July 17, 2016 22:21
hodor2
var re = regexp.MustCompile(`hodor`)
func process(text string) string {
return re.ReplaceAllString(text, `hold the door`)
}