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 / setup-electron.py
Created July 16, 2022 23:46
A Script to setup electron apps using the quick start guide https://www.electronjs.org/docs/latest/tutorial/quick-start
"""A script that automates the process found on https://www.electronjs.org/docs/latest/tutorial/quick-start
Interactive Usage:
python setup-electron.py
To pre-specify an app name use:
python setup-electron.py <app_name>
To run fully headlessly (without forge use):
python setup-electron.py <app_name> --headless
@Descent098
Descent098 / expressions.md
Created May 5, 2022 18:13
Useful regex expressions

Quoting

Terms inside single quotes: (?s)'(\\\\|\\[0-7]+|\\.|[^'\\])*' Terms inside double quotes: (?s)"(\\\\|\\[0-7]+|\\.|[^"\\])*"

Operators

Finds (not content seperated by them though) * / + - / < > <= >= % = /=: (\*\*|\*|\+|-|\/|<|>|<=|>=|==|\/=|=|%)

Finds True or False (and uncapitalized): (true|false|True|False)

@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 / 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