reset git history

This commit is contained in:
Noah Masur
2020-06-03 08:31:58 -06:00
commit a368fda34d
37 changed files with 8031 additions and 0 deletions

13
bin/calc Executable file
View File

@ -0,0 +1,13 @@
#!/usr/bin/env ruby
#
# Run a quick calculation with Ruby
#
# Usage: calc "1/2"
class Integer
def /(other)
fdiv(other)
end
end
puts eval(ARGV.join(""))

View File

@ -0,0 +1,16 @@
FROM alpine:latest
COPY requirements.txt /
RUN apk update && \
apk add \
openssh \
python \
py-pip \
&& \
pip install -r requirements.txt
COPY connect_cloud.sh /
COPY connect_cloud.py /
ENTRYPOINT ["/connect_cloud.sh"]

View File

@ -0,0 +1,85 @@
#!/usr/bin/env python
"""Connect to Cloud instances"""
import os
import sys
import argparse
import boto3
# Initiate the parser
parser = argparse.ArgumentParser("Type the name of the connection you want")
parser.add_argument('profile', metavar='P', nargs='?',
help='an account to use')
parser.add_argument('environment', metavar='E', nargs='?',
help='an environment to specify')
args = parser.parse_args()
# Get AWS credentials profile
profile_map = {
'gs' : {
'profile': 'ghoststory',
'prod': 'id_rsa_gstory_prod.pem',
'dev': 'id_rsa_gstory_prod.pem',
'username': 'centos',
},
'di' : {
'profile': 't2indies',
'prod': 'disintegration-prod.pem',
'dev': 'disintegration-dev.pem',
'username': 'centos',
},
'pd' : {
'profile': 't2indies',
'prod': 't2indies-prod.pem',
'dev': 't2indies-dev.pem',
'username': 'centos',
},
'corp' : {
'profile': 't2corp',
'prod': 'take2games-corp.pem',
'dev': 'take2games-corp.pem',
'username': 'ec2-user',
},
'ksp' : {
'profile': 'kerbal',
'prod': 'kerbal_prod_key.pem',
'dev': 'kerbal_dev_key.pem',
'username': 'centos',
},
}
profile_dict = profile_map.get(args.profile)
profile = profile_dict['profile']
# Connect to AWS
session = boto3.Session(profile_name=profile)
client = session.client('ec2', verify=False)
response = client.describe_instances()
print(len(response['Reservations']), "total instances\n")
matched_instances = []
for instance_wrapper in response['Reservations']:
instance = instance_wrapper['Instances'][0]
is_matched_env = False
is_matched_role = False
for tag in instance.get('Tags', []):
if tag['Key'] == "site_env" and args.environment in tag['Value']:
is_matched_env = True
if tag['Key'] == "role" and tag['Value'] == 'host':
is_matched_role = True
if tag['Key'] == "Name":
instance['Name'] = tag['Value']
if is_matched_env and is_matched_role:
matched_instances.append(instance)
for instance in matched_instances:
print(instance['Name'])
print(instance['PublicIpAddress'])
print("")
with open("aws_connect", 'w') as outfile:
outfile.write("ssh-keyscan {} >> ~/.ssh/known_hosts\n".format(matched_instances[0]['PublicIpAddress']))
outfile.write("ssh -i ~/.ssh/{} {}@{}".format(profile_dict[args.environment], profile_dict['username'], matched_instances[0]['PublicIpAddress']))
os.chmod("aws_connect", 0o755)

View File

@ -0,0 +1,5 @@
#!/bin/sh
python connect_cloud.py "$@"
/aws_connect

View File

@ -0,0 +1,8 @@
boto3==1.9.239
botocore==1.12.239
docutils==0.15.2
jmespath==0.9.4
python-dateutil==2.8.0
s3transfer==0.2.1
six==1.12.0
urllib3==1.25.6

26
bin/docker_cleanup Executable file
View File

@ -0,0 +1,26 @@
#!/bin/sh
# Stop all containers
if [ "$(docker ps -a -q)" ]; then
echo "Stopping docker containers..."
docker stop $(docker ps -a -q)
else
echo "No running docker containers."
fi
# Remove all stopped containers
if [ "$(docker ps -a -q)" ]; then
echo "Removing docker containers..."
docker rm $(docker ps -a -q)
else
echo "No stopped docker containers."
fi
# Remove all untagged images
if [[ $(docker images | grep "^<none>") ]]; then
docker rmi $(docker images | rg "^<none>" | awk '{print $3}')
else
echo "No untagged docker images."
fi
echo "Cleaned up docker."

16
bin/emacs_env Executable file
View File

@ -0,0 +1,16 @@
#!/usr/bin/env bash
function export-emacs {
if [ "$(emacsclient -e t)" != 't' ]; then
return 1
fi
for name in "${@}"; do
value=$(eval echo \"\$${name}\")
emacsclient -e "(setenv \"${name}\" \"${value}\")" >/dev/null
done
}
for i in $(python -c $"import os; [print(k) for k in os.environ.keys()]"); do
export-emacs "$i"
done

3
bin/notify Executable file
View File

@ -0,0 +1,3 @@
#!/usr/bin/env ruby
system %{osascript -e 'display notification "#{ARGV.join(' ')}"'}

3
bin/save_env Executable file
View File

@ -0,0 +1,3 @@
#!/usr/bin/env bash
python -c $"import os; [print(k) for k in os.environ.keys()]" > ~/Document/GitHub/dotfiles/env.txt

22
bin/watchit Executable file
View File

@ -0,0 +1,22 @@
#!/usr/bin/env ruby
require "digest"
def compute_sha
contents = Dir["./**/*.rs"].map do |file|
File.read(file)
end.join("\n")
Digest::MD5.hexdigest(contents)
end
sha = compute_sha
loop do
new_sha = compute_sha
if sha != new_sha
sha = new_sha
system "clear && echo '#{'-'*80}' && cargo test"
end
sleep 1
end

25
bin/youtube Executable file
View File

@ -0,0 +1,25 @@
#!/usr/bin/env ruby
require "uri"
module Clipboard
class << self
def paste
`pbpaste`.chomp
end
end
end
def parse_params(url)
url.query.split("&").each_with_object({}) do |param, acc|
key, value = *param.split("=", 2)
acc[key] = value
end
end
url = URI.parse Clipboard.paste
params = parse_params url
id = params.fetch("v") { raise "Probably not a youtube URL" }
clean_url = "https://www.youtube.com/watch?v=#{id}"
system "(cd ~/Downloads && youtube-dl -f best \"#{clean_url}\")"