Skip to content

Instantly share code, notes, and snippets.

@hsavit1
hsavit1 / YouTubePlayerViaTVJS.swift
Created July 6, 2016 00:34 — forked from nickv2002/YouTubePlayerViaTVJS.swift
Swift code to play YouTube videos on AppleTV tvOS via a TVJS call using XCDYouTubeKit
//
// Created by Nick Vance on 12/4/15.
// Copyright © 2015 ToWatchList. All rights reserved.
//
import AVKit
import XCDYouTubeKit
import TVMLKit
class YTPlayerViewController: AVPlayerViewController, AVPlayerViewControllerDelegate {
@hsavit1
hsavit1 / bbtree.py
Created June 27, 2016 02:55 — forked from olomix/bbtree.py
Balanced binary tree in Python
#!/usr/bin/env python2.7
import random
import subprocess
class Node(object):
def __init__(self, key, value):
self.key = key
self.value = value
extension Selector {
static let coffeeMadeNotification = #selector(Customer.drink(_:))
}
class Customer {
@objc func drink(notification: NSNotification) {
print("Mmm... Coffee")
}
}
@hsavit1
hsavit1 / fibs_gen.swift
Created April 3, 2016 05:11
Fibonacci GeneratorType
class FibsGenerator: GeneratorType {
var state = (0, 1)
func next() -> Int? {
let upcomingNumber = state.0
state = (state.1, state.0 + state.1)
return upcomingNumber
}
}
@hsavit1
hsavit1 / Makefile
Created April 2, 2016 21:57 — forked from isaacs/Makefile
# Hello, and welcome to makefile basics.
#
# You will learn why `make` is so great, and why, despite its "weird" syntax,
# it is actually a highly expressive, efficient, and powerful way to build
# programs.
#
# Once you're done here, go to
# http://www.gnu.org/software/make/manual/make.html
# to learn SOOOO much more.
@hsavit1
hsavit1 / makemake.pl
Created April 2, 2016 21:56 — forked from roop/makemake.pl
Script to create a Makefile to build your Swift project
#!/usr/bin/perl -w
use strict;
# Makefile generator for quick compilation of Swift projects
# By: Roopesh Chander
# Thanks: Andy Matuschak
# Works only for swift-only projects.
# Usage:
# > perl makemake.pl
# > make
@hsavit1
hsavit1 / Makefile
Created April 2, 2016 21:55 — forked from zachwhaley/Makefile
Simple C++ Makefile
CXXFLAGS = -g -Wall -Werror -std=c++11
LDLIBS =
PRGM = project
SRCS := $(wildcard *.cpp)
OBJS := $(SRCS:.cpp=.o)
DEPS := $(OBJS:.o=.d)
.PHONY: all clean
@hsavit1
hsavit1 / Equatable.swift
Created February 29, 2016 15:22
Equatable protocol in swift
protocol Equatable {
/// Reflexive - `x == x` is `true`
/// Symmetric - `x == y` then `y == x`
/// Transitive - `x == y` and `y == z` then `x == z`
func ==(lhs: Self, rhs: Self) -> Bool
}
@hsavit1
hsavit1 / sieve.swift
Created February 29, 2016 15:19
Sieve of Eratosthenes
func primes(n: Int) -> [Int] {
var numbers = [Int](2..<n)
for i in 0..<n-2 {
guard let prime = numbers[i] where prime > 0 else { continue }
for multiple in stride(from: 2 * prime-2, to: n-2, by: prime) {
numbers[multiple] = 0
}
}
return numbers.filter { $0 > 0 }
}
@hsavit1
hsavit1 / ModelViewUpdate.swift
Created February 7, 2016 04:44
Model View Update in Swift
protocol Component {
typealias M // Model
typealias A // Action
typealias C // Context
static func initModel() -> M
static func update(action: A, model: M) -> M
static func view(model: M, context: C, base: Base) -> Node
}