Skip to content

Instantly share code, notes, and snippets.

View TimothyLoyer's full-sized avatar
👨‍🚀
my brain is in the stars

Tim Loyer TimothyLoyer

👨‍🚀
my brain is in the stars
View GitHub Profile
@TimothyLoyer
TimothyLoyer / iOS Upload Bug.md
Last active August 29, 2015 14:04
iOS 7 Multiple-File Upload Issue

Description

Files uploaded with Safari on iOS 7 fail or result in 0 kilobyte files on the server.

Conditions

  • Using any device running iOS 7
  • Browsing from Safari or Chrome
  • When using a multiple-upload form (even if only one file is uploaded)
@TimothyLoyer
TimothyLoyer / VideoDNA.bat
Last active August 29, 2015 14:04
12 Stars Media Vidpainter
@echo off
echo ____ _____ ______ _________ ________ ______ ______
echo /___/\ /_____/\ /_____/\ /________/\/_______/\ /_____/\ /_____/\
echo \_::\ \ \:::_:\ \ \::::_\/_\__.::.__\/\::: _ \ \\:::_ \ \ \::::_\/_
echo \::\ \ _\:\^| \:\/___/\ \::\ \ \::(_) \ \\:(_) ) )_\:\/___/\
echo _\: \ \__ /::_/__ \_::._\:\ \::\ \ \:: __ \ \\: __ `\ \\_::._\:\
echo /__\: \__/\\:\____/\ /____\:\ \::\ \ \:.\ \ \ \\ \ `\ \ \ /____\:\
echo \________\/_\_____\/_____\_____\/__ \__\/___ \__\/\__\/ \_\/ \_\/ \_____\/
echo.

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

@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;
@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 / 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 / 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
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 / 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).*\"" .)"
@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