Skip to content

Instantly share code, notes, and snippets.

View pdarragh's full-sized avatar

Pierce Darragh pdarragh

View GitHub Profile
@pdarragh
pdarragh / Instructions.txt
Last active August 29, 2015 14:07
Install Python3 and Pygame via Homebrew on OS X
####
## I do not guarantee that this works. Use at your own risk.
## I am *fairly* certain that these are all the steps I took to get Python3 and Pygame
## installed on OS X, but I may be forgetting something.
####
# Install Homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew doctor
@pdarragh
pdarragh / Jekyll Static Highlighting Navigation Menu.md
Last active September 30, 2023 10:43
Jekyll navigation bar with automatic highlighting.

Jekyll NavBar

In building a site powered by Jekyll and hosted by GitHub, I wanted the ability to highlight the current page's tab in the bar. I also wanted the bar to support second-level items (i.e. a dropdown), which proved somewhat tricky. This is the solution I arrived at after a few hours of fiddling around.

Construction

The contents of the navigation bar are contained in a data file located at _data/navigation.yml. This makes it accessible via the site-wide Liquid element {{ site.data.navigation}}. You can see the file for the formatting I used.

How it Works

@pdarragh
pdarragh / get_serial.py
Last active June 11, 2021 17:20
Short PyObjC script to get a Mac's serial number without calling `system_profiler`.
#!/usr/bin/python
# (Note that we must use system Python on a Mac.)
####
# Quick script to get the computer's serial number.
#
# Written for @john.e.lamb on the MacAdmins Slack team.
import objc
import CoreFoundation
#!/usr/bin/env python3.6
import random
from abc import ABC, abstractmethod
from copy import copy
from typing import Any, Callable, Dict, Iterable, List, NamedTuple, Optional, Tuple, Type
CROSS_VALIDATION_TRAINING_EPOCHS = 10
@pdarragh
pdarragh / Example usage
Created April 28, 2020 03:18
A simple script to extract colors from iTerm color profiles as hexadecimal values.
$ ./iterm2hex.py "Solarized Dark Higher Contrast.itermcolors"
#002731 // Ansi 0 Color
#D01B24 // Ansi 1 Color
#50EE84 // Ansi 10 Color
#B17E28 // Ansi 11 Color
#178DC7 // Ansi 12 Color
#E14D8E // Ansi 13 Color
#00B29E // Ansi 14 Color
#FCF4DC // Ansi 15 Color
#6BBE6C // Ansi 2 Color
@pdarragh
pdarragh / argparse_tutorial.py
Created September 17, 2020 18:52
A brief tutorial of the fundamental functionality of the `argparse` module in the Python standard library.
#!/usr/bin/env python3
from shlex import split as split_args # This is used for splitting strings in
# the way the shell does it.
# The `argparse` module in the standard library provides a ton of functionality
# for easily parsing command-line arguments when invoking Python programs. The
# full documentation is available here:
#
# https://docs.python.org/3/library/argparse.html
@pdarragh
pdarragh / keymap.c
Created October 23, 2020 17:49
Current keymap for Preonic keyboard
/* Copyright 2015-2017 Jack Humbert
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@pdarragh
pdarragh / PythonListyDataTypes.hs
Created November 6, 2020 04:22
Haskell implementations of Python's built-in Iterator, Iterable, and Sequence types and their associated functions
{-# LANGUAGE ConstrainedClassMethods #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
import Prelude hiding (all, any, length, map)
import Data.Bool (Bool(..), not, otherwise)
import Data.List (reverse)
import qualified Data.List (length)
@pdarragh
pdarragh / migrate_repo.sh
Created January 26, 2021 22:35
Move commits from one repository to another without squashing
#!/usr/bin/env sh
# I TAKE NO RESPONSIBILITY FOR YOUR CHOICE TO USE THIS SCRIPT.
# It's probably a better idea to just read the commands and enter
# them by hand one-by-one. But I've used this script and it works
# for me, so here it is.
# Migrates the commits from an old repository to a new one using
# a rebase.
#
@pdarragh
pdarragh / spelling_bee.py
Created February 1, 2021 22:47
New York Times Spelling Bee Solver
#!/usr/bin/env python3
"""This module provides functions for solving the New York Times Spelling Bee
puzzles using a given dictionary file.
"""
import re