Skip to content

Instantly share code, notes, and snippets.

Andy Lee aglee

Block or report user

Report or block aglee

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
@aglee
aglee / AoC2018Day07.swift
Created Dec 7, 2018
Advent of Code Day 07
View AoC2018Day07.swift
import Foundation
let USING_TEST_INPUT = false
let commandURL = URL(fileURLWithPath: CommandLine.arguments[0])
let inputFileName = USING_TEST_INPUT ? "test.txt" : "input.txt"
let inputFileURL = commandURL.deletingLastPathComponent().appendingPathComponent(inputFileName)
let inputText = try! String(contentsOf: inputFileURL, encoding: .utf8).trimmingCharacters(in: .whitespacesAndNewlines)
let inputLines = inputText.split(separator: "\n")
@aglee
aglee / main.swift
Last active Dec 6, 2018
Advent of Code 2018 day 06
View main.swift
import Foundation
let commandURL = URL(fileURLWithPath: CommandLine.arguments[0])
let inputFileURL = commandURL.deletingLastPathComponent().appendingPathComponent("input.txt")
let inputText = try! String(contentsOf: inputFileURL, encoding: .utf8).trimmingCharacters(in: .whitespacesAndNewlines)
let inputLines = inputText.split(separator: "\n")
// I will call the input coordinates "pins", as in pins on a map (is clearer to my mind than "coordinates").
// I will call the index of a pin in allPins its "pinID".
View NSSet-Pitfalls.m
#import <Foundation/Foundation.h>
// Two things to know about NSSet:
//
// - NSSet assumes its elements will never mutate. It breaks if they do.
// - Unlike NSDictionary, NSSet does not copy its unique objects. It stores
// the original pointers.
//
// Bottom line: DO NOT MUTATE OBJECTS THAT ARE ELEMENTS OF AN NSSET. The
// code below demonstrates the kind of bugs you could run into if you
View ij.py
# Expects i and j to be 1-based row and column indexes, respectively.
def f(i, j):
return (((i+j-1) * (i+j))/2) - (i if ((i+j-1) & 1 == 0) else j) + 1
# Test: use f() to generate matrix and visually inspect it
# to see that the numbers are correct.
for i in range(10):
line = ""
for j in range(10):
line += "%5d" % (f(i+1, j+1))
View ij.swift
import Foundation
// Expects i and j to be 1-based row and column indexes, respectively.
func f(_ i: Int, _ j: Int) -> Int {
return ((i+j-1) * (i+j))/2 - (((i+j-1) & 1 == 0) ? i : j) + 1
}
// Test: use f() to generate matrix and visually inspect it
// to see that the numbers are correct.
for i in 1...10 {
View TreeDiff.py
#!/usr/bin/python
"""
https://www.hackerrank.com/challenges/cut-the-tree
"""
class Node(object):
def __init__(self, weight):
self.weight = weight
self.adjacent_nodes = []
@aglee
aglee / TreeSearch.swift
Last active Jun 22, 2016
A Swift exercise
View TreeSearch.swift
func ==(lhs: Node, rhs: Node) -> Bool {
return lhs === rhs
}
class Node: Equatable {
var value: String
var children: [Node] = []
init(_ value: String) {
self.value = value
View RVNReceiptValidation.m
//
// RVNReceiptValidation.m
//
// Created by Satoshi Numata on 12/06/30.
// Copyright (c) 2012 Sazameki and Satoshi Numata, Ph.D. All rights reserved.
//
// This sample shows how to write the Mac App Store receipt validation code.
// Replace kRVNBundleID and kRVNBundleVersion with your own ones.
//
// This sample is provided because the coding sample found in "Validating Mac App Store Receipts"
@aglee
aglee / NSApplication+MarkdownCredits.h
Created Dec 22, 2013
Category on NSApplication that makes it easy to use a Markdown-formatted Credits file, or to use your README as the Credits file.
View NSApplication+MarkdownCredits.h
//
// NSApplication+MarkdownCredits.h
// ALUtilities
//
// Copyright (c) 2013 Andy Lee
//
// 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
@aglee
aglee / gap-stores-autism-discount.htm
Created Sep 28, 2012
What you get when you ask Excel to save as a .htm file
View gap-stores-autism-discount.htm
<html>
<head>
<meta http-equiv=Content-Type content="text/html; charset=macintosh">
<meta name=ProgId content=Excel.Sheet>
<meta name=Generator content="Microsoft Excel 14">
<link rel=File-List href="gap-stores-autism-discount_files/filelist.xml">
<style>
<!--table
{mso-displayed-decimal-separator:"\.";
You can’t perform that action at this time.