Skip to content

Instantly share code, notes, and snippets.

View brydavis's full-sized avatar

Bryan Davis brydavis

View GitHub Profile
@brydavis
brydavis / regexs.md
Last active January 11, 2024 08:30
Regex for URLs in Go

Regexs

Quick reference for regexs in Golang that match common string patterns out there in the wild.

URLs

^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/|\/|\/\/)?[A-z0-9_-]*?[:]?[A-z0-9_-]*?[@]?[A-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$

Emails

@brydavis
brydavis / 00-README.md
Created October 20, 2018 02:35 — forked from guumaster/00-README.md
How to upload a file with $.ajax to AWS S3 with a pre-signed url

Upload a file with $.ajax to AWS S3 with a pre-signed url

When you read about how to create and consume a pre-signed url on this guide, everything is really easy. You get your Postman and it works like a charm in the first run.

Then you open your browser, try your usual $.ajax() and send your PUT operation, and you hit the cold iced wall of AWS error message, a simple <Code>SignatureDoesNotMatch</Code> that will steal hours from your productivity.

So here I come to save you and give you a free working example of how to upload a file directly to AWS S3 from your browser. You are wellcome :).

@brydavis
brydavis / data_uri.go
Created August 9, 2020 08:47
Generate Data URI from HTML Text
package main
import (
"encoding/base64"
"fmt"
)
func main() {
data := []byte(`<!DOCTYPE html>
<html>
@brydavis
brydavis / comprehend.go
Created April 3, 2018 06:58
Example of AWS Comprehend with Go
package main
import (
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/comprehend"
)
function move(pb) {
pb.style.width = "0%"
setTimeout(function () {
console.log("start")
var width = 1;
var id = setInterval(frame, 50);
function frame() {
if (width >= 100) {
clearInterval(id);
@brydavis
brydavis / serve.go
Created September 25, 2019 01:20
Basic Root Folder File / Webserver for Static Site Testing
package main
import (
"log"
"net/http"
)
func main() {
http.Handle("/", http.FileServer(http.Dir(".")))
@brydavis
brydavis / progress_bar.js
Created September 24, 2019 00:32
Progress Bar Snippet
// pb is a DIV that respresents the progress bar itself
// this example is a demo; update it to track actually progress
function move(pb) {
pb.style.width = "0%"
setTimeout(function () {
console.log("start")
var width = 1;
var id = setInterval(frame, 50);
@brydavis
brydavis / race_conditions.go
Created September 24, 2019 00:18
Race condition in Go (see `letter` variable)
package main
import (
"fmt"
"sync"
)
const numThreads = 5
var ch chan string
@brydavis
brydavis / cors.xml
Created September 17, 2019 01:41
Example of AWS CORS policy
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>DELETE</AllowedMethod>
<AllowedMethod>HEAD</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
@brydavis
brydavis / recursion_example.ipynb
Created August 27, 2019 17:58
Examples of using recursion in Python
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.