Skip to content

Instantly share code, notes, and snippets.

Bryan Davis brydavis

Block or report user

Report or block brydavis

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@brydavis
brydavis / serve.go
Created Sep 25, 2019
Basic Root Folder File / Webserver for Static Site Testing
View serve.go
package main
import (
"log"
"net/http"
)
func main() {
http.Handle("/", http.FileServer(http.Dir(".")))
@brydavis
brydavis / progress_bar.js
Created Sep 24, 2019
Progress Bar Snippet
View progress_bar.js
// 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 Sep 24, 2019
Race condition in Go (see `letter` variable)
View race_conditions.go
package main
import (
"fmt"
"sync"
)
const numThreads = 5
var ch chan string
@brydavis
brydavis / cors.xml
Created Sep 17, 2019
Example of AWS CORS policy
View cors.xml
<?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 Aug 27, 2019
Examples of using recursion in Python
View recursion_example.ipynb
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 Aug 27, 2019
Examples of creating and using decorators in Python
View decorators.ipynb
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 Aug 27, 2019
Examples creating and using custom context managers in Python
View context_managers.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@brydavis
brydavis / logify.py
Created Aug 27, 2019
Set logging levels for every function using a "decontextor" (decorator + context manager)
View logify.py
import argparse
import logging, sys
# https://docs.python.org/3/howto/logging-cookbook.html
logger = logging.getLogger('app')
logify_level = logging.ERROR
help_statement = """
Accepts integers of corresponding logging levels
@brydavis
brydavis / find_files.py
Created Aug 27, 2019
Finding files within subfolders without using `os.walk` or `glob` libraries
View find_files.py
import os
from pprint import pprint
data = {}
def find_files(folder, file_extension):
for item in os.listdir(folder):
item = "/".join([folder, item])
if os.path.isdir(item):
data[item] = []
@brydavis
brydavis / mongo_context_manager.py
Last active Aug 27, 2019
Using a context manager to work with Mongo
View mongo_context_manager.py
from pymongo import MongoClient
# https://medium.com/@ramojol/python-context-managers-and-the-with-statement-8f53d4d9f87
class MongoDBConnection(object):
"""MongoDB Connection"""
def __init__(self, host='localhost', port='27017'):
self.host = f"mongodb://{host}:{port}"
self.connection = None
def __enter__(self):
You can’t perform that action at this time.