Skip to content

Instantly share code, notes, and snippets.

@PatrickWalker
PatrickWalker / string_map.go
Last active May 3, 2020 19:25
String to Map
func convertStringToMap(in string) map[string]int32 {
rA := []rune(in)
strMap := map[string]int32{}
for _, v := range rA {
if count,ok := strMap[string(v)]; ok {
strMap[string(v)]=count+1
}else{
strMap[string(v)]=1
}
}
@PatrickWalker
PatrickWalker / string_asc.go
Created May 3, 2020 18:38
String Ascending Go
func ascString(in string) string {
rA := []rune(in)
strArr := make([]string, len(rA))
for k, v := range rA {
strArr[k] = string(v)
}
sort.Strings(strArr)
return strings.Join(strArr, "")
}
//from the changelog
DB::Query Tasks \value -> value.iscomplete != true
// Where tasks is my db store
@PatrickWalker
PatrickWalker / postman_prereq_auth.js
Created March 19, 2019 15:58
Postman Prerequest Script to store an auth token before each API request
// we use this to set an expiry on the token
var currTime = new Date().getTime();
// If there is an expiry value and it's before current time then we've expired
if (pm.globals.get("tokenExpiry") !== '' && pm.globals.get("tokenExpiry") <= currTime){
console.log('Token Expiry Exceeded. Clearing token');
pm.globals.set("token",'')
}
// If we have a valid token then we don't need to request it we'll reuse it
if (pm.globals.get("token") !== ''){
console.log("Auth Token. Set So Not logging in again");
@PatrickWalker
PatrickWalker / main.go
Last active October 5, 2018 14:34
Renaming Files in Go using a rename function
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"strings"
)
package main
import (
"fmt"
tf "github.com/tensorflow/tensorflow/tensorflow/go"
"github.com/tensorflow/tensorflow/tensorflow/go/op"
)
func main() {
<link rel="import" href="my-element.html">