Skip to content

Instantly share code, notes, and snippets.

View Descent098's full-sized avatar
🐍
Writing Python

Kieran Wood Descent098

🐍
Writing Python
View GitHub Profile
@Descent098
Descent098 / Berkley Sockets.md
Last active November 16, 2022 00:44
Sockets

Example in python can be seen here: https://github.com/Descent098/ezcv-http/tree/main/socket%20testing

Uses ezcv to generate html and then sockets as the http server

Endian formats

Networking data is in big endian, meaning the integers in hex values go from left to right So for example int x = 0xAABBCCDD would be understood as AA, BB, CC, DD (where each 2 letters is a byte value) In some host systems they operate using little endian meaning the order is reversed DD, CC, BB, AA and the values need to be reversed before being sent

@Descent098
Descent098 / Native windows shortcuts.md
Created September 23, 2021 22:49
Creating shortcuts natively on windows
@Descent098
Descent098 / count_letters.py
Created September 6, 2021 21:05
counting letters
import string
filename = "test.txt" # Replace with filename
def count_words_starting_with_letters(filename:str) -> dict:
"""Take in a filename and return a dict with the count of how many words began with each letter
Parameters
----------
filename : str
@Descent098
Descent098 / Split to subfolders.md
Last active September 6, 2021 20:17
A Quick script to take in a folder and split the files into even groups

This script was written to answer this question, thought it was useful so I decided to post a gist of it also.

This explanation is ripped straight from the question:

Explanation

Since this is a little more involved I will explain my solution in steps. If you don't care about the explanation and just want the code scroll down to see the full example python file below.

Essentially there are a few things we need:

  1. A list of all the absolute paths to the files
@Descent098
Descent098 / Readme.md
Created September 2, 2021 22:55
Python embeddable version

Can be downloaded by going to latest release on https://python.org/download and finding the embeddable version

Setting up pip

Step 1 path fix

Unzip the archive and inside there is a file called pythonXY._pth, where XY is replaced by version number (so for python 3.9 it would be python39._pth). Open the file and it should look like this:

pythonXY.zip
@Descent098
Descent098 / for-loops.py
Last active August 22, 2021 18:52
An overview of python for loops
from timeit import timeit
from random import randint
items = [randint(0,100) for i in range(10000)]
native_loop="""
for item in items:
@Descent098
Descent098 / Word Similarity in Python.md
Last active July 16, 2023 14:12
Word Similarity Methods in Python

This gist describes various methods of getting similarity in python, and the advantages/disadvantages of each.

Pure Python

There is an implementation in python for the Ratcliff-Obershelp similarity algorith, that can be used to give a ratio of the fimilarity between two strings:

from difflib import SequenceMatcher
@Descent098
Descent098 / background.md
Created September 12, 2020 22:15
Stack overflow question 63865065

This post: https://stackoverflow.com/questions/63865065/missing-some-information-in-my-results-why was removed from stack overflow. I get the decision but I wanted to answer it anyway.

There are 3 files in this gist op.py op-better.py and op-best.py these get progressively better. The explanations for each can be found below.

issues in op.py

  1. From lines 2-6 this isn't how you want to define what attributes a class has
  2. final_answer is not a method of Laptops, but instead just a random function that's hanging out
  3. from 12-16 you don't want to just randomly add attributes to a class because it can cause errors down the line

op-better.py

@Descent098
Descent098 / macro.md
Last active September 10, 2020 20:04
Course Template Enhancements

Compression macro

There are a few options for setting up a macro to compress your notes before git push'ing.

Prerequisites

  1. 7Zip and the 7Zip CLI (It's not installed by default for windows) for your operating system.

Options for setup

  1. Use a system I designed called ahd (requires Python 3.6+) see [here] for setup
@Descent098
Descent098 / FE-master-list.md
Last active May 25, 2020 03:21
List of front end frameworks and UI Kits