Skip to content

Instantly share code, notes, and snippets.

Avatar

Nick Glynn 17twenty

View GitHub Profile
@17twenty
17twenty / generate.go
Created Aug 14, 2020
Generate an embeddable zip file that can be included in your Golang project that auto extracts at runtime.
View generate.go
package main
import (
"fmt"
"io/ioutil"
"os"
"strings"
)
func main() {
View enumerated.go.tmpl
package {{.Package}}
import (
"database/sql/driver"
"encoding/json"
"fmt"
"strings"
)
// {{.Type}}Enum is the status code of an {{.Type}} (must be int64)
@17twenty
17twenty / SEO-Guide.md
Last active Jul 13, 2020
Creating and building an SEO strategy for your site
View SEO-Guide.md

Hey guys!

There's a TON of content out there on SEO - guides, articles, courses, videos, scams, people yelling about it on online forums, etc etc..

Most of it, however, is super impractical. If you want to start doing SEO TODAY and start getting results ASAP, you'll need to do a TON of digging to figure out what's important and what's not.

So we wanted to make everyone's lives super easy and distill our EXACT process of working w/ clients into a stupid-simple, step-by-step practical guide. And so we did. Here we are.

A bit of backstory:

@17twenty
17twenty / jsonfilter.go
Last active Jul 2, 2020
JSONFilteredByWhitelist filters an incoming JSON payload against a while list then applies the filtered payload to the destination struct.
View jsonfilter.go
package types
import (
"encoding/json"
"io"
"reflect"
"strings"
)
// JSONFilteredByWhitelist filters an incoming JSON payload against a while list,
@17twenty
17twenty / camelsnake.go
Created May 26, 2020
Snake To Camel and Camel To Snake Case In Go Golang
View camelsnake.go
package main
import (
"fmt"
"regexp"
"strings"
)
// Regex
@17twenty
17twenty / demo.go
Created May 21, 2020
Implementing Custom Marshal / Unmarshal for a custom type (and using an interface)
View demo.go
package main
import (
"bytes"
"encoding/json"
"fmt"
"log"
"os"
"strconv"
)
@17twenty
17twenty / reader.go
Created May 19, 2020
CGo and Shared Memory
View reader.go
package main
// #include <stdlib.h>
// #include <string.h>
// #include <sys/shm.h>
// #include <sys/types.h>
// #include <stddef.h>
// int my_shm_open(char* filename, int open_flag){
// int shm_id;
// key_t key;
@17twenty
17twenty / the_marshal.go
Created May 7, 2020
Custom marshal/unmarshal leveraging Scan/Value() for JSON and Database usage
View the_marshal.go
package main
import (
"database/sql/driver"
"encoding/json"
"fmt"
"strings"
)
type paymentOption int64
@17twenty
17twenty / accounting.go
Created Mar 2, 2020
Accounting and Formatting for Golang Shopspring decimal library
View accounting.go
package quicka
import (
"fmt"
"strings"
"github.com/shopspring/decimal"
)
// FormatMoneyDecimal ...
@17twenty
17twenty / gist:ca503d3be60330e3b3d07799fcdbdc33
Created Nov 14, 2019 — forked from chanks/gist:7585810
Turning PostgreSQL into a queue serving 10,000 jobs per second
View gist:ca503d3be60330e3b3d07799fcdbdc33

Turning PostgreSQL into a queue serving 10,000 jobs per second

RDBMS-based job queues have been criticized recently for being unable to handle heavy loads. And they deserve it, to some extent, because the queries used to safely lock a job have been pretty hairy. SELECT FOR UPDATE followed by an UPDATE works fine at first, but then you add more workers, and each is trying to SELECT FOR UPDATE the same row (and maybe throwing NOWAIT in there, then catching the errors and retrying), and things slow down.

On top of that, they have to actually update the row to mark it as locked, so the rest of your workers are sitting there waiting while one of them propagates its lock to disk (and the disks of however many servers you're replicating to). QueueClassic got some mileage out of the novel idea of randomly picking a row near the front of the queue to lock, but I can't still seem to get more than an an extra few hundred jobs per second out of it under heavy load.

So, many developers have started going straight t

You can’t perform that action at this time.