Skip to content

Instantly share code, notes, and snippets.

@mikemcduffie
mikemcduffie / download.py
Created September 22, 2025 20:37 — forked from mjohnsullivan/download.py
Python HTTP download with resume and optional MD5 hash checking
import os.path
import shutil
import hashlib
import logging
# Support both Python 2 and 3 urllib2 importing
try:
from urllib.request import urlopen, Request
except ImportError:
from urllib2 import urlopen, Request
@mikemcduffie
mikemcduffie / morse.py
Created September 22, 2025 10:26 — forked from Saluev/morse.py
Morse code with Python unary + and - operators
# -*- coding: utf-8 -*-
morse_alphabet = {
"А" : ".-",
"Б" : "-...",
"В" : ".--",
"Г" : "--.",
"Д" : "-..",
"Е" : ".",
"Ж" : "...-",
@mikemcduffie
mikemcduffie / emoji.py
Created September 22, 2025 10:25 — forked from Saluev/emoji.py
Emoji regular expression for Python
"""
Regular expressions for matching emoji sequences.
For parsing single emoji, use either
re.match(EMOJI_SEQUENCE, string)
# or
EMOJI_REGEXP.match(string)
To match multiple emojis or custom patterns, insert `EMOJI_SEQUENCE` into pattern:
#!/bin/bash
# We can find the index of the item in the array by extracting the key, finding the lines with
# 'string' in them, and then finding the search string.
cd /System/Volumes/Data/.Spotlight-V100
search_string=$1
let index="`plutil -extract Exclusions xml1 -o - VolumeConfiguration.plist | grep string | grep -wn "${search_string}" | cut -d ':' -f 1` - 1"
!/bin/bash
launchctl stop com.apple.metadata.mds && launchctl start com.apple.metadata.mds
vers=$( sw_vers | grep BuildVersion | awk '{print substr($2,0,2)}' )
sdir="/.Spotlight-V100"
if [[ "${vers}" > "18" ]]; then
sdir="/System/Volumes/Data${sdir}"
@mikemcduffie
mikemcduffie / extractSubtitles.sh
Created September 18, 2025 10:24 — forked from FurloSK/extractSubtitles.sh
Extract subtitles from MKV/MP4 videos
#!/bin/sh
# Extract subtitles from each MKV/MP4 file in the given directory
# [updated 2024-01-09 by FurloSK]
# Permanent gist address: https://gist.github.com/FurloSK/7f52303a10ab7478e3cddfe4bcc50881
#
# ===== Usage =====
# extractSubtitles.sh [-i] [<fileOrDirectory>]
# -i
# Supplying this option will skip extraction and only print information about subtitles in file
# <fileOrDirectory>
@mikemcduffie
mikemcduffie / GitHubFileDownloader.sh
Created September 10, 2025 11:51 — forked from electblake/GitHubFileDownloader.sh
Github File Downloader
#!/bin/bash
# Script: GitHubFileDownloader.sh
# Author: electblake <https://github.com/electblake>
# Version: 1.0
# Description: This script converts a GitHub repository file URL to its GitHub API URL for file contents, checks if the user is logged into GitHub CLI, and downloads the file.
# Source: https://gist.github.com/electblake/7ef3a63e20b3c8db67d9d66f7021d727
# Credits:
# - Inspired by answers on: https://stackoverflow.com/questions/9159894/download-specific-files-from-github-in-command-line-not-clone-the-entire-repo
# - Used "Bash Script" GPT by Widenex for script creation assistance.
@mikemcduffie
mikemcduffie / run_app_from_terminal.md
Created September 8, 2025 05:01 — forked from valosekj/run_app_from_terminal.md
Run arbitrary application from terminal on MacOS #blog

Run arbitrary application from terminal on MacOS

Sometimes, it is convenient to have possibility to start/run any application (like your internet browser or text editor) directly from your terminal. Most of these applications however do not create shortcut for easy run from terminal during their installation. Below is short manual how to create this shortcut manually.

Steps

  1. Open terminal (cmd + space --> type terminal)

  2. Navigate to a directory where you have your code/scripts. For example ~/code or /usr/local/bin:

@mikemcduffie
mikemcduffie / ssh_configuration.md
Created September 8, 2025 04:58 — forked from valosekj/ssh_configuration.md
Configuration of `ssh` connection #blog

Configuration of ssh connection

Unix and MacOS

Let's say we want to configure an ssh connection between machine alpha and beta.

  1. Go to your home folder at machine alpha:
$ cd ~
@mikemcduffie
mikemcduffie / string_manipulation.md
Created September 8, 2025 04:54 — forked from valosekj/string_manipulation.md
Useful string manipulation examples for bash and zsh #blog

Useful string manipulation examples for bash and zsh

I need very often to modify filenames or replace/delete their parts across huge number of files. I was using sed command for these purposes but recently I have found out that all these tasks can be easily done directly in bash (or zsh) because both of them support so called string manipulation operations.

String manipulations

Define some example string:

$ file=some_file_name.txt