Skip to content

Instantly share code, notes, and snippets.

View brydavis's full-sized avatar

Bryan Davis brydavis

View GitHub Profile
@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 / 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

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.
@brydavis
brydavis / decorators.ipynb
Created August 27, 2019 17:53
Examples of creating and using decorators in Python
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@brydavis
brydavis / context_managers.ipynb
Last active August 27, 2019 17:53
Examples creating and using custom context managers in Python
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.