Skip to content

Instantly share code, notes, and snippets.

View jfarmer's full-sized avatar
🐢

Jesse Farmer jfarmer

🐢
View GitHub Profile

And here's an argument for why you want your non-varying arguments to come first in your function signature.

Many languages have the concept of "partial application", where supplying a function with fewer arguments than it expects doesn't raise an error, but instead returns a function that is waiting for the remaining arguments.

For example, imagine if you had a function add(x,y) and add(1) didn't throw an error, but returned a function that was waiting for y and returned 1 + y when you supplied it with that single argument, e.g.,

def add(x, y):
    return x + y
@jfarmer
jfarmer / LICENSE
Created June 11, 2024 19:01
Python function to calculate the FIRST sets from a context-free grammar given in BNF
MIT License
Copyright (c) 2024 Jesse Farmer <https://github.com/jfarmer>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@jfarmer
jfarmer / license.java
Created May 4, 2024 15:13 — forked from Chino-chan/license.java
Bloated code?
//Various Messages
final String boxMessage = "License Game";
final String welcomeMessage = "Welcome to License Game";
//Questions
final String question1 = "What does this mean... A: text B: text C: ";
final String question2 = "What does this mean... A: text B: text C: ";
final String question3 = "What does this mean... A: text B: text C: ";
final String question4 = "What does this mean... A: text B: text C: ";
final String question5 = "What does this mean... A: text B: text C: ";
@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.