Skip to content

Instantly share code, notes, and snippets.

@flyinghyrax
flyinghyrax / Cycle.swift
Last active August 24, 2016 15:39
Implementing the cycle function for sequences in Swift
/* Copied from a playground file */
// Produce a list of length N by cycling an original list
func cycleN<T>(base: [T], length: Int) -> [T] {
var buildup: [T] = []
while buildup.count < length {
buildup.appendContentsOf(base)
}
return Array(buildup.prefix(length))
}
/// A protocol with an associated type requirement
protocol SomeProtocol {
associatedtype SomePAT
func someFunction(param: SomePAT)
}
/// A generic class which satisfies the associated type with its generic parameter
class Base<T>: SomeProtocol {
func someFunction(param: T) {
@flyinghyrax
flyinghyrax / FirebaseValue.swift
Last active April 2, 2017 08:41
Some firebase binding code
// FirebaseValue.swift
// Created by Matt Seiler on 7/14/16.
// Copyright © 2016 Matthew Seiler. All rights reserved.
import FitnetUtils
import FirebaseDatabase
import Foundation
class FirebaseValue<T>: Observable<T?> {

Keybase proof

I hereby claim:

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

To claim this, I am signing this object:

@flyinghyrax
flyinghyrax / maccdc_colors.py
Last active April 4, 2016 03:53
Demo using Python to talk to badges from MACCDC2016
import socket
import time
import colorsys
# address of badge
ADDR = "192.168.0.16"
# found in src/main.cpp
PORT = 11337
@flyinghyrax
flyinghyrax / AnonTest.java
Last active April 1, 2016 01:21
Poking at anonymous inner classes
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
public class AnonTest {
public static void main(String[] args) {
//
System.out.printf("i\tNamed\tAnonymous%n");
for (int i = 0; i < 10; i += 1) {
@flyinghyrax
flyinghyrax / spiral.rkt
Created March 1, 2016 00:08
Racket code for drawing mildly interesting, spirally nested circles
#lang racket
(require pict)
;;;; The original code (it works alright)
#|
(define faces '(N S E W))
(define (next-face f)
@flyinghyrax
flyinghyrax / Spiral.hs
Created February 17, 2016 17:13
It draws an ASCII spiral
module Spiral where
import System.Environment
import qualified Data.List as List
import qualified Data.Set as Set
{- Process outline:
- 1. Create infinite sequence of points on the spiral
- 2. Take a finite subsequence
- 3. Shift all the points so the origin is in the top left
@flyinghyrax
flyinghyrax / step_buckets.log
Created November 12, 2015 18:04
Step Count 30-day daily aggregate log output
: Connected!!!
: Found 31 buckets
: Bucket: 2015-10-13 00:00 - 2015-10-14 00:00
: Data Sets:
: Data returned for Data type: com.google.step_count.delta
: Bucket: 2015-10-14 00:00 - 2015-10-15 00:00
: Data Sets:
: Data returned for Data type: com.google.step_count.delta
: Bucket: 2015-10-15 00:00 - 2015-10-16 00:00
: Data Sets:
@flyinghyrax
flyinghyrax / observation.swift
Last active August 29, 2015 14:27
Copy into a playground and open the debug area with Cmd+Shift+Y to see output
import Foundation
/*
Demonstrates creating and avoiding retention cycles in callbacks
*/
/* UTILITIES */
/// Wraps a something in a class
class Box<T> {