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 / urls.py
Created March 8, 2019 22:07
DRF by Example Root URLs Module
from django.urls import path
from django.conf.urls import include
from django.conf import settings
from django.contrib import admin
from rest_framework_swagger.views import get_swagger_view
from .views import api_root
schema_view = get_swagger_view(title='DRF by Example')
# url list
@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 / 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()
@craigderington
craigderington / hash_file.py
Created May 6, 2019 17:52
Create a Hash of a File
import os
import hashlib
def sha256sum(filename):
"""
Create a file hash
:param: str (file path)
:return: str (md5 hash)
"""
h = hashlib.sha256()