Skip to content

Instantly share code, notes, and snippets.

@hughlilly
hughlilly / BoxCalculator.py
Last active October 12, 2022 05:38
Testing
'''
Task 1: Box calculator
This table shows available box sizes and the number of items each can hold:
+--------+-------+
| Size | Items |
+--------+-------+
| Big | 5 |
| Medium | 3 |
@hughlilly
hughlilly / extract.py
Last active June 1, 2022 06:23
IMDbExtractor.py
# Based on https://github.com/yogeshp1426/IMDB_Top_50_Web_Scrapper/blob/master/IMDB_csv_out.ipynb
from bs4 import BeautifulSoup as soup
from urllib.request import urlopen
import csv
IMDb_url = (
"https://www.imdb.com/search/title/?sort=num_votes,desc&start=1&title_type=feature&year=1950,1960")
connection = urlopen(IMDb_url)
page_html = connection.read()
@hughlilly
hughlilly / full_calculator.py
Last active January 24, 2022 19:01
learn_python_extras
# This time let's not use a string for the operation parameter.
# Since it's an either-or choice, a Boolean will do nicely.
# For an explanation of the use of the "*" in the definition block, see
# https://ivergara.github.io/boolean-arguments-to-functions-in-python.html
def calculate(x: int, y: int = 1, *, subtract: bool = False) -> int:
"""Calculates the sum (or difference) of two numbers.
@hughlilly
hughlilly / 10files.sh
Last active July 28, 2022 21:41
zsh scripts
for ((i = 1; i < 11; i++)); do touch io$i.py; done
@hughlilly
hughlilly / MāoriTextReplacements.plist
Created September 28, 2021 23:05
plist export of 2 te reo Māori text replacements for macOS
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>phrase</key>
<string>Māori</string>
<key>shortcut</key>
<string>maori</string>
</dict>
Overall: https://regex101.com/r/kh1HG2/1
Inner: https://regex101.com/r/fMwcsz/1
@hughlilly
hughlilly / WD_WMC_AM.sparql
Last active September 13, 2021 22:29
Wikidata/WMC SPARQL queries for AM data
# https://wcqs-beta.wmflabs.org/
SELECT ?pageid ?file ?title
(GROUP_CONCAT(DISTINCT ?mi_label;separator="; ") as ?miLabel)
(GROUP_CONCAT(DISTINCT ?en_label;separator="; ") as ?enLabel)
WITH {
SELECT * WHERE {
SERVICE wikibase:mwapi
{
@hughlilly
hughlilly / Copy_from_list.ps1
Last active September 6, 2021 22:12
Powershell script using Get-Content to open text file containing filenames/partial paths and copy to current dir
# Prepends "J:\" to each line, copies to current directory -- specify with -Destination param, per
# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/copy-item
# Add "-wi" (or ("--WhatIf") for a dry run
Get-Content .\list.txt | ForEach {Copy-Item J:\$_ -verbose}
@hughlilly
hughlilly / IterateOverFiles.py
Last active August 5, 2021 23:19
Uses Python's iglob iterator to work on files in sequence.
import glob
num_files = len(glob.glob('*.jpg'))
if num_files > 0:
print("Found {0} JPEG files".format(num_files))
jpeg_files = glob.iglob('*.jpg')
for count, filename in enumerate(jpeg_files, start=1):
print("----\n")
percent_complete = int((count * 100) / num_files)
print("File: {0} ({1} of {2}; {3}%).".format(
@hughlilly
hughlilly / CheckExists.vba
Last active December 14, 2021 01:23
Check file/dir exists in MS Excel
' From https://stackoverflow.com/questions/67066414/
Public Function checkExists(fPath As String) As Boolean
If fPath <> "" Then
If Dir(fPath, vbNormal + vbDirectory) <> "" Then
checkExists = True
End If
End If
End Function