Skip to content

Instantly share code, notes, and snippets.

View TimothyLoyer's full-sized avatar
🧙‍♂️
Wizarding, I think?

Tim Loyer TimothyLoyer

🧙‍♂️
Wizarding, I think?
View GitHub Profile
@TimothyLoyer
TimothyLoyer / main.py
Created December 1, 2022 15:01
Advent of Code 2022 - Day 1
"""Advent of Code 2022: Day 1"""
def get_input(path):
with open(path) as i:
return i.read()
def get_input_lines(path):
i = get_input(path)
@TimothyLoyer
TimothyLoyer / sn-convert-img
Last active May 8, 2023 16:36
Bash script to convert images for use with Supernote A6X and A5X
#!/usr/bin/bash
################################################################################
#
# Description:
# Convert images for compatibility with the Supernote A6X and A5X.
#
# If an original image's size exceeds the ratio required to be compatible
# with the Supernote, it will automatically be centered and cropped.
#
# Usage:
@TimothyLoyer
TimothyLoyer / mfa-env
Created April 22, 2020 20:48
Bash script to set MFA IAM session in environment variables
#!/bin/bash
#description : Set MFA session in environment variables
#usage : source mfa-env [token-from-mfa-device]
#requirements : Install aws-cli v2
mfa_config=~/.aws/mfa
mfa_device_arn=""
mfa_token="${1-}"
if [ ! -f $mfa_config ]; then
@TimothyLoyer
TimothyLoyer / tf.sh
Last active April 9, 2020 17:04
A Terraform wrapper that allows use of `-exclude=` arguments to skip slow resources
#!/bin/bash
#description :This script will make a header for a bash script.
#usage :tf plan -exclude=route53 -exclude=s3
#requirements :Install Terraform
get_local_state() {
# List all Terraform resource, data, and module objects in a directory.
# Note: This ignores 'module' objects!
state="$(grep -rho --include="*.tf" -E "^(resource|data).*\"" .)"
def wrap_log_output(message: str, line_char: str = "#", log: logger = logger.info):
if not isatty(sys.stdin.fileno()):
log(message)
else:
_, columns = subprocess.check_output(["stty", "size"]).split()
def hr():
print(line_char * int(columns))
hr()
@TimothyLoyer
TimothyLoyer / progress_bar.py
Created September 17, 2019 18:23
Python CLI Progress Bar
class ProgressBar:
def __init__(self, total_items=None, title="Progress", bar_length=60):
self.title = title
self.bar_length = bar_length
self.total_items = total_items
self.start_time = timer()
self.is_tty = isatty(sys.stdin.fileno())
def get_time_elapsed(self):
elapsed = timer() - self.start_time
@TimothyLoyer
TimothyLoyer / print_runtime.py
Created September 17, 2019 18:23
Print Runtime Decorator
def print_runtime(func):
"""
Decorator to log the name and runtime in seconds for a callable.
:param func:
:return:
"""
def wrapper(*args, **kwargs):
start = timer()
@TimothyLoyer
TimothyLoyer / test.html
Created August 8, 2018 15:58
Direct Employers Tests - Tim Loyer
<!doctype html>
<html class="no-js" lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Direct Employers Tests - Tim Loyer</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
</head>
@TimothyLoyer
TimothyLoyer / EncodeListener.php
Created October 2, 2014 16:03
QueueInterface Depency Injection fails with "BindingResolutionException"
<?php namespace Acme\V1\Handlers;
use Acme\V1\Eventing\EventListener;
use Acme\V1\Eventing\Events\AssetHasBeenUploaded;
use Acme\V1\Eventing\Events\ProductionHasBeenUploaded;
use Illuminate\Queue\QueueInterface as Queue;
class EncodeListener extends EventListener {
protected $queue;

Putting all the knowledge I find on CORS, needs of various HTTP verbs, and specific browser needs here.

Options

Access-Control-Allow-Headers should be set to "*" only for OPTIONS requests. If you return it for POST requests Chrome will cancel the request.

Works for GET preflight: Access-Control-Allow-Origin: {origin} Access-Control-Allow-Methods: GET, POST, PUT, DELETE Access-Control-Allow-Headers: Authorization, Content-Type