This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This bit of code is from a recent rust project where I'm making the board game snakes and ladders. Specifically, it's the code that creates a new "board" which contains pawns, tiles, and connections (the snakes and ladders). | |
https://github.com/dyllandry/ladders-and-slides/blob/f79a28fb057f8839dd9b1d2f09fa9c136c118d35/src/ladders_and_slides.rs#L132 | |
The reason I like this function is because: | |
- It's not complex. It hides enough complexity to be useful & the interface it exposes is simple. | |
- It includes argument validation with errors, so you catch issues during development. | |
- It lacks side-effects, just receives and returns data. | |
- Includes a comment to communicate something non-obvious in the code. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
test_fibonacci(10); | |
} | |
fn test_fibonacci(n: u32) { | |
println!("fibonacci({}) -> {}", n, fibonacci(n)); | |
} | |
fn fibonacci(n: u32) -> u32 { | |
// Whenever I use recursion, I think of it in terms of what are the |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Stripe doesn't provide an endpoint to get all upcoming invoices, | |
* instead you have to fetch them one by one for each subscriber. | |
* This script gets all upcoming stripe invoices and puts them in | |
* an easy to read CSV file you can open in excel. | |
* | |
* This tool can be useful for companies with few subscriptions to | |
* see which customer's subscriptions will renew soon so they can maybe | |
* get ahead of it, maybe provide some extra customer service | |
* in advance or something. | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "opengl-api.h" | |
#include <dlfcn.h> | |
#include <stdio.h> | |
/* Here we define pointers to each of the opengl functions we use by defining a | |
* function-like macro "GL_FUNC" and applying it to each "GL_FUNC" macro | |
* contained by "GL_FUNC_LIST". This xmacro is defined in our header. */ | |
#define GL_FUNC(returnType, funcName, ...) funcName##Type * funcName; | |
GL_FUNC_LIST | |
#undef GL_FUNC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* I got this recursion question during an interview and totally blew it. I | |
* forgot recursion existed, and my implementation didn't go smoothly. Here's | |
* another try. | |
* | |
* Question: Print a triangle of stars without using any loops, iteration, etc. | |
* | |
* Input: n = 3 | |
* Output: * | |
* ** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<title>Site Maintenance</title> | |
<style> | |
body { text-align: center; padding: 150px; } | |
h1 { font-size: 50px; } | |
body { font: 20px Helvetica, sans-serif; color: #333; } | |
article { display: block; text-align: left; width: 650px; margin: 0 auto; } | |
a { color: #dc8100; text-decoration: none; } | |
a:hover { color: #333; text-decoration: none; } | |
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Toggles a touchpad on/off. | |
# Might only work computers that use xinput. | |
DEVICE_NAME="SynPS/2 Synaptics TouchPad" | |
ID=$(xinput list --id-only "$DEVICE_NAME") | |
IS_ENABLED=$(xinput --list-props "$DEVICE_NAME" | grep "Device Enabled" | grep -o "[01]$") | |
if [ $IS_ENABLED -eq 0 ]; then | |
xinput set-prop $ID "Device Enabled" 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Title: Doubly Linked List | |
* Author: Dylan Landry | |
* Date: Wed 26 Jun 2019 16:00:15 EDT | |
* Permalink: https://gist.github.com/dyllandry/12d0a2f7f1b1cfc22169b1990bd89c2d | |
* | |
* Description: | |
* A kind of data structure similar to a train. | |
* Each node, a container for a value, knows of the node ahead of it and behind | |
* it. The list keeps references to the head node, the tail node, and the total |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Title: Singly Linked List | |
* Author: Dylan Landry | |
* Date: Wed 26 Jun 2019 13:38:38 EDT | |
* Permalink: https://gist.github.com/dyllandry/371505391a608abb9d979a1ea258cff9 | |
* | |
* Description: | |
* A kind of data structure similar to a train. | |
* Each node, a container for a value, knows only of the node ahead of it. | |
* The list keeps references to the head node, the tail node, and the total |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Radix Sort: Radix (or base) means: "the base of a | |
* system of numeration." Radix sorts by analyzing the | |
* place values of each number. Each number must be a | |
* whole number, or positive integer. Radix sort can be used | |
* with a variety of base values, though here I focus | |
* only on our decimal base 10 system. | |
* | |
* Process: | |
* Create an auxiliary array with a length of ten (one |
NewerOlder