Skip to content

Instantly share code, notes, and snippets.

View craigderington's full-sized avatar
🚀
Automate Everything

Craig Derington craigderington

🚀
Automate Everything
View GitHub Profile
@craigderington
craigderington / async_socket_server.py
Last active May 4, 2021 23:51
Async Socket Server
import asyncio, socket
async def handle_client(reader, writer):
request = None
while request != 'quit':
request = (await reader.read(255)).decode('utf8')
response = str(eval(request)) + '\n'
writer.write(response.encode('utf8'))
await writer.drain()
writer.close()
#!/usr/bin/env python3.4
import asyncio
class EchoServer(asyncio.Protocol):
def connection_made(self, transport):
peername = transport.get_extra_info('peername')
print('connection from {}'.format(peername))
self.transport = transport
def data_received(self, data):
#!/usr/bin/env python3.4
import asyncio
class EchoClient(asyncio.Protocol):
message = 'Client Echo'
def connection_made(self, transport):
transport.write(self.message.encode())
print('data sent: {}'.format(self.message))
# alacritty
env:
TERM: xterm-256color
window:
dimensions:
columns: 120
lines: 48
padding:
x: 10
# ~/.config/starship.toml
add_newline = false
[line_break]
disabled = true
[username]
format = "[$user]($style)"
style_user = "bold bright blue"
show_always = true
# convert all downloaded media to mp3
# rename all converted files to remove {webm,mkv,mp4} from filenames
# echo file conversion list
# then delete everything but the newly converted mp3
echo "starting up, get list of files, please be patient..."
ls | echo "Found $(wc -l) media files for conversion in the present working directory." | xargs
echo "starting mp3 conversion with ffmpeg and libmp3lame."
for i in *.{webm,mkv,mp4}; do
ffmpeg -i "$i" -acodec libmp3lame "$(basename "${i/.{webm,mkv,mp4}")".mp3
@craigderington
craigderington / restapi_load_from_csv.py
Last active October 29, 2019 21:00
Read in a CSV file and POST the data to an API Endpoint
#!/usr/bin/python
import argparse
import csv
import json
import os
import requests
import sys
from requests.auth import HTTPBasicAuth
from urllib.parse import urlparse
@craigderington
craigderington / app.py
Created September 12, 2019 21:40
Python + Flask + Redis - Page Hit Counter
#!/usr/bin/python
from flask import Flask
from redis import Redis
app = Flask(__name__)
redis = Redis(host="172.17.0.2", port=6379)
@app.route("/", methods=["GET"])
@craigderington
craigderington / Dockerfile
Last active June 24, 2021 00:56
Build image for Flask Redis Counter
FROM python:3.6-alpine
LABEL maintainer="Craig Derington <craigderington17@gmail.com>"
RUN apk update && apk upgrade
RUN apk add screen curl
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
EXPOSE 8000
CMD ["python", "app.py"]
@craigderington
craigderington / strings_compare.py
Created July 12, 2019 17:34
Python while True loop updating Incoming Message UUID when Certain Conditions Exist
import os
import time
import uuid
import random
from datetime import datetime, timedelta
def get_message():
return uuid.uuid4()