Skip to content

Instantly share code, notes, and snippets.

View jfarmer's full-sized avatar
🐢

Jesse Farmer jfarmer

🐢
View GitHub Profile
@jfarmer
jfarmer / python-hash.md
Created August 19, 2023 15:58
Explaining Python's hash() function and __hash__ magic method

Python's hash()

Authors's Note

This is an outline of how I'd explain hash to a novice programmer. I've given versions of this explanation hundreds of times to thousands of students, beginners and experts alike.

Students tell me they find it compelling because it helps them connect w/ what's really going on by emphasizing both the technical and human/design elements.

I'm assuming the student is comfortable with:

@jfarmer
jfarmer / README.md
Last active September 8, 2023 12:07
Given a linked list and a non-negative integer k, add k to every kth element from the end of the linked list

Keybase proof

I hereby claim:

  • I am jfarmer on github.
  • I am jfarmer (https://keybase.io/jfarmer) on keybase.
  • I have a public key ASCxNmuHrckOs4s9PC96DGZLqh98V1LsYzD5ysU3uVO_Awo

To claim this, I am signing this object:

@jfarmer
jfarmer / nyt_homepage_.yesterday.sh
Last active December 5, 2020 21:12
Create PNG of yesterday's NYTimes homepage
# The -1d in the date command means yesterday, so, e.g., -2d would be two days ago
# Change the output file extension if you want another image type
# "-resize 1440x" resizes to 1440px wide while preserving aspect ratio
curl "https://static01.nyt.com/images/$(date -v -1d +"%Y/%m/%d")/nytfrontpage/scan.pdf" | convert -density 600x600 -antialias - -resize 1440x -quality 100 "output_file_name.png" nyt_homepage_yesterday.png
@jfarmer
jfarmer / key.md
Created November 22, 2020 05:20
Twitter (un)official Consumer Key

Twitter Official Consumer Key

Twitter for Android

type:            PIN
Consumer key:    3nVuSoBZnx6U4vzUxf5w
Consumer secret: Bcs59EFbbsdF6Sl9Ng71smgStWEGwXXKSjYvPVt7qys

Twitter for iPhone

type:            PIN

Consumer key: IQKbtAYlXLripLGPWd0HUA

Scavenger Hunt

Every item below refers to a specific function built into the JavaScript language. For each item, find:

  1. The relevant page and section on MDN's official JavaScript documentation
  2. At least one online resource (tutorial, etc.) other than Stack Overflow, w3cshools, or geekforgeeks explaining the function

Scavenger Items

  1. Given two numbers, tell me how to get the remainder after dividing the former by the latter.
@jfarmer
jfarmer / README.md
Last active February 15, 2024 19:23
A demonstration of the power of the command line

The Power Of The Command Line

If you all want to learn more about the command line, one thing we didn't really touch on is input/output redirection, which is ultimately what makes the command line so powerful. On the command line, you can take the output of one program and feed it as input to another program.

The power of the command line lies in its composability. The command line has general mechanisms for taking existing programs and combining them to produce new programs.

Think of this as a system-wide API that you get "for free" by using the command line. You can chain a sequence of programs together, each one feeding its output as the input to the next one in the chain, to produce a "new" program. None of the programs involved need to know they're being used in this way.

This kind of "composability" is much harder with a GUI, so programs tend to be monolithic and only interact with other programs in pre-defined, pre-sanctioned ways.

@jfarmer
jfarmer / index.html
Last active February 25, 2020 00:46 — forked from keithjng/css
todos
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="./main.css">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TODO List</title>
</head>
<body>
<section>
@jfarmer
jfarmer / README.md
Created February 21, 2019 18:20
Fibonacci implementations in Ruby

Fibonacci in Ruby

Here's a benchmark for four Ruby implementations of a method to calculation the nth Fibonacci number. The implementations:

  1. fib_recursive - A memoized recursive version
  2. fib_iterative - An iterative version
  3. fib_phi - A version using Binet's formula via an implementation of the arithmetic of ℚ(φ)
  4. fib_matrix - A version using Matrix exponentiation

While fib_phi is slower than fib_matrix, you can see that it has the same rate of growth.

Casual Raiding and Deliberate Learning

Note: I wrote this in 2015 when I was raiding with a casual guild in WoW.

de·lib·er·ate (adj.)

  • done consciously and intentionally: a deliberate attempt to provoke conflict.

  • fully considered; not impulsive: a deliberate decision.

    synonyms: intentional, calculated, conscious, intended, purposeful