Skip to content

Instantly share code, notes, and snippets.

Peter Hurford peterhurford

Block or report user

Report or block peterhurford

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@peterhurford
peterhurford / git-101-exercises.md
Last active Apr 1, 2020
Git 101, with Exercises
View git-101-exercises.md

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 / r-interview.md
Last active Mar 30, 2020
R Interview Questions
View r-interview.md

1.) If I have a data.frame df <- data.frame(a = c(1, 2, 3), b = c(4, 5, 6), c(7, 8, 9))...

1a.) How do I select the c(4, 5, 6)?

1b.) How do I select the 1?

1c.) How do I select the 5?

1d.) What is df[, 3]?

@peterhurford
peterhurford / better-programming.md
Last active Mar 17, 2020
One Year Out: How I Became a Better Programmer
View better-programming.md

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

@peterhurford
peterhurford / pytest-fixture-modularization.md
Created Jul 28, 2016
How to modularize your py.test fixtures
View pytest-fixture-modularization.md

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 / parallelization.md
Created Oct 17, 2015
How does code get parallelized?
View parallelization.md

Computer code is a series of executed statements. Frequently, these statements are executed one at a time. If one part of your code takes a long time to run, the rest of your code won't run until that part is finished.

However, this isn't how it has to be. We can often make the exact same code go much faster through parallelization, which is simply running different parts of the computer code simaltaneously.

Asynchronous Code

The first example of this is asynchronous code. The idea here is that many times you do things like send a call to another computer, perhaps over the internet, using an API. Normally, code then has to simply wait for the other computer to give it a response over the API. But asynchronous code can simply keep on going and then the API call returns later.

This makes code harder to reason about and handle because you don't know when the API call will return or what your code will be like when it returns, but it makes your code faster because you don't have to wait arou

@peterhurford
peterhurford / programming-checklist.md
Last active Mar 5, 2020
A programming checklist for you to fill out every time you make a pull request to make sure you end up with good code
View programming-checklist.md
  • Did you write tests? Are they mutually exclusive and collectively exhaustive? Do they pass?
  • Did you get a code review?
  • Have you verified that your code works, outside of tests?
  • Is your code DRY?
  • Did you follow the single responsibility principle at different levels of detail throughout all your functions, objects, files, folders, repositories, etc.?
  • Is your code readable? Can someone else tell you what it does?
  • Is your code self-documenting? Did you explain strange choices? Did you write documentation about how it works?
  • Do all your variables have self-explaining names?
  • Did you avoid writing overly long functions?
  • Do you document what your function inputs are? Are you explicit about what preconditions must be true about your function inputs? Are you explicit about what postconditions will hold about your function outputs, if the preconditions hold?
@peterhurford
peterhurford / open-source.md
Last active Nov 29, 2019
What is on an open source project website?: Five case studies
View open-source.md

What is on an open source project website?: Five case studies

Looking at Rails, Angular, jQuery, Prediction.io, and Redis pages to find commonalities.

Lessons Learned

  • Layout matters. A nice layout inspires trust in your project.
  • Layout is similar. All the sites had a top bar with the prominent navigation. All the main pages had introductory text.
  • GitHub Issues is used ubiquitously for bug tracking.
  • IRC seems important for communities. Gitter seems like a good choice.
@peterhurford
peterhurford / num_rows_csv.R
Last active Oct 4, 2019
What's the fastest way to determine the number of rows of a CSV in R?
View num_rows_csv.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 / readable-code.md
Last active Mar 20, 2019
How do you write readable code?: 13 Principles
View readable-code.md

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 / mint.R
Last active Feb 3, 2019
Look at Mint transaction data via R
View mint.R
## Load libraries
if (!require(readr)) { install.packages("readr") }; library(readr)
if (!require(magrittr)) { install.packages("magrittr") }; library(magrittr)
if (!require(dplyr)) { install.packages("dplyr") }; library(dplyr)
if (!require(tibbletime)) { install.packages("tibbletime") }; library(tibbletime)
if (!require(lubridate)) { install.packages("lubridate") }; library(lubridate)
if (!require(devtools)) { install.packages("devtools") }; library(devtools)
if (!require(shinyview)) { install_github("peterhurford/shinyview") }; library(shinyview)
## Load Mint transactions
You can’t perform that action at this time.