Skip to content

Instantly share code, notes, and snippets.

@peterhurford
peterhurford / pytest-fixture-modularization.md
Created July 28, 2016 15:48
How to modularize your py.test fixtures

Using py.test is great and the support for test fixtures is pretty awesome. However, in order to share your fixtures across your entire module, py.test suggests you define all your fixtures within one single conftest.py file. This is impractical if you have a large quantity of fixtures -- for better organization and readibility, you would much rather define your fixtures across multiple, well-named files. But how do you do that? ...No one on the internet seemed to know.

Turns out, however, you can define fixtures in individual files like this:

tests/fixtures/add.py

import pytest

@pytest.fixture
@peterhurford
peterhurford / install_xelatex_on_mac.txt
Last active June 17, 2024 15:02
How to install latex and xelatex on Mac so that Jupyter "Download as PDF" will work
brew install pandoc
brew tap homebrew/cask
brew install --cask basictex
eval "$(/usr/libexec/path_helper)"
# Update $PATH to include `/usr/local/texlive/2022basic/bin/universal-darwin`
sudo tlmgr update --self
sudo tlmgr install texliveonfly
sudo tlmgr install xelatex
sudo tlmgr install adjustbox
sudo tlmgr install tcolorbox
@peterhurford
peterhurford / readable-code.md
Last active May 16, 2024 12:15
How do you write readable code?: 13 Principles

How do you write readable code?: 13 Principles

"Programs should be written for people to read, and only incidentally for machines to execute." -- Structure and Interpretation of Computer Programs

"How would you define good code? [...] After lots of interviews we started wondering if we could come out with a definition of good code following a pseudo-scientific method. [...] The population is defined by all the software developers. The sample consists of 65 developers chosen by convenience. [...] The questionnaire consists in a single question: “What do you feel makes code good? How would you define good code?”. [...] Of those, the most common answer by far was that the code has to be Readable (78.46%), almost 8 of each 10 developers believe that good code should be easy to read and understand." -- "What is Good Code: A Scientific Definition"

@peterhurford
peterhurford / how_to_release_a_new_python_package.md
Last active October 19, 2023 01:09
How to release a new Python package

Nothing novel here, just want these instructions all in one place for my own use.

1.) Ensure everything is pushed to master and is working

2.) Ensure CHANGES.md is up to date with latest

3.) Ensure version in setup.py is incremented

4.) Tag the repo - e.g., git tag 0.2 && git push origin 0.2

@peterhurford
peterhurford / git-101-exercises.md
Last active July 29, 2023 04:30
Git 101, with Exercises

Git 101, with Exercises

Git is the key tool we use to allow multiple people to work on the same code base. Git takes care of merging everyone's contributions smoothly. Hence, learning how to use Git is critical to contributing to open source.

Exercises

Exercise 1: Go through the Try Git Guide

Exercise 2: Learn How to file a github issue.

@peterhurford
peterhurford / gist:8602d9fb334baa71d983
Last active April 9, 2023 15:22
How to use XAMPP to test PHP on your own computer

So this is a guide for how to use XAMPP to test any PHP website on your own computer. Well, actually, it's more a guide of guides than an actual guide. I personally didn't find the process to be bad, but it also wasn't straightforward, and it involved a lot of googling separate problems. There was no One Guide for the Entire Process, but a bunch of separate things.

So I decided to put everything together. Here are the steps:

Step 1: Install XAMPP. Download from here.

Step 2: Set up XAMPP. Follow instructions here.

Step 3: Go to PhpMyAdmin and create any relevant MySQL tables, if any.

@peterhurford
peterhurford / num_rows_csv.R
Last active September 5, 2022 09:37
What's the fastest way to determine the number of rows of a CSV in R?
# What's the fastest way to determine the number of rows of a CSV in R?
# ...Reading the entire CSV to only get the dimensions is likely too slow. Is there a faster way?
# Benchmarks done on a EC2 r3.8xlarge
# Cowritten with Abel Castillo <github.com/abelcastilloavant>
m <- 1000000
d <- data.frame(id = seq(m), a = rnorm(m), b = runif(m))
dim(d)
# [1] 1000000 3
pryr::object_size(d)
@peterhurford
peterhurford / better-programming.md
Last active June 28, 2022 23:46
One Year Out: How I Became a Better Programmer

I've been coding professionally for a year now, having started work on the 30th of June. In that year I've programmed professionally in Ruby on Rails, R, and JavaScript / Coffeescript using both the Knockout and Angular frameworks.

I'd like to think I've become a much better programmer over the past year. Looking back at my old code, I can tell that I grew a lot.

Here's how I did it.

Spend Time Programming

## Slack watcher - makes sure you only have Slack running if you should to avoid being distracted
## by Patrick Brinich-Langois, Ben Kuhn, and Peter Wildeford
## To install: (1) save this script as `~/bin/slack_watcher.applescript`.
## (2) Use `crontab -e` and add `*/22 * * * * osascript $HOME/bin/slack_watcher.applescript` to your crontab
## (this will run every 22 minutes while Slack is open - Slack will be closed if you press `No`)
tell application "System Events"
set activeApp to name of first process whose frontmost is true
end tell
## Taskmaster - nudges you onto the most important task - by Peter Wildeford
## To install: (1) save this script as `~/bin/taskmaster.applescript`.
## (2) Use `crontab -e` and add `*/40 09-19 * * 0-5 osascript $HOME/bin/taskmaster.applescript` to your crontab
## (this will run the crontab every 40 minutes between 9am and 7pm on Mondays through Fridays - use https://crontab.guru/ to customize)
tell application "Finder"
activate
display alert "Taskmaster" message "Are you working on the most important task?" buttons ["No", "Yes"] default button 1
end tell