Skip to content

Instantly share code, notes, and snippets.

@andyg0808
andyg0808 / git-annex-downloader
Created April 9, 2013 02:24
Two-line script to make Git Annex able to be a download manager for FlashGot (although it doesn't provide user-visible status). To use, install FlashGot (http://flashgot.net/) and add a new download manager. Specify this script as the download manager executable and use something like [FOLDER] [URL] as the template for its command line arguments.
#!/bin/bash
# $1=folder to cd to (must be a git annex repo)
# $2=URL to download
cd "$1"
git-annex addurl "$2"
@andyg0808
andyg0808 / strategy.md
Last active March 5, 2020 06:45
Strategy Pattern

Note: I'm not 100% certain of my descriptions vs. how others might define things; hopefully this is enough to get an intuative idea of what's going on.

The Strategy pattern lets you change how a function or method does its job. It might be helpful to think of it in terms of refactoring shapes. When you have two functions with similar parts at the top, you break that top part out into a new function. When they have similar parts at the bottom, you break that out into a new function. In both of those cases, you can replace the original function call with a call to the new "top half" function followed by a call to the new "bottom half" function. But if the similar parts are in the middle of the function, you can break them out into a strategy. This lets you replace a call to each of the specialized methods with a call to the new combined function, passing the appropriate strategy to handle the bit in the middle.

Consider the following two functions:

/*
@andyg0808
andyg0808 / heaps.py
Created May 31, 2020 01:33
Heap's algorithm in Python
from typing import List
def swap(A, i, j):
temp = A[i]
A[i] = A[j]
A[j] = temp
def generate(k: int, A: List):
@andyg0808
andyg0808 / README.md
Last active June 25, 2020 23:05
Git prepare-commit-msg hook

Summary

This hook automatically inserts an appropriate filename description in the suggested commit message for each commit you make which touches a single file.

Examples

These are inserted as the first line of the message opened in your editor when running git commit. Messages entered with -m will not be affected:

If you've only touched a single static method

User::create: 
@andyg0808
andyg0808 / Guide.ts
Last active June 15, 2022 17:12
iFixit API TypeScript types: Guide, generated by https://app.quicktype.io/
export interface Guide {
conclusion_raw: string;
conclusion_rendered: string;
difficulty: string;
documents: any[];
flags: Flag[];
guideid: number;
image: Image;
introduction_raw: string;
introduction_rendered: string;