Skip to content

Instantly share code, notes, and snippets.

View peterkos's full-sized avatar
:octocat:

Peter Kos peterkos

:octocat:
View GitHub Profile
@peterkos
peterkos / markov1.swift
Created April 21, 2019 07:54
1st order markov chain of the melody to "Mary Had A Little Lamb".
//
// main.swift
// MarkovTest
//
// Created by Peter Kos on 4/20/19.
// Copyright © 2019 UW. All rights reserved.
//
import Foundation
import UIKit
let array = [5, 16, 67, 2, 9]
// "Manual" way
for index in stride(from: 0, to: array.count, by: 2) {
print(array[index])
}
@peterkos
peterkos / iosdev_dubstech_aut18_week1.swift
Last active October 17, 2018 01:10
Code written on Week 1 of the iOS Development Workshop, Autumn 2018, w/ Dubstech
// -----------------------------------------
// Playground Code
// -----------------------------------------
import UIKit
var str = "Hello, playground"
// sayHello() prints "hello, person!"
@peterkos
peterkos / iosdev_dubstech_aut18_week0.swift
Created October 15, 2018 03:27
Code written on Week 0 of the iOS Development Workshop, Autumn 2018, w/ Dubstech
import UIKit
// var -- Variable (value can change)
// let -- Constant (value cannot change)
var str = "Hello, playground"
str = "My New String"
@peterkos
peterkos / canvasquizcover.css
Created November 27, 2017 03:07
On Canvas LMS, hides "correct/wrong" answer arrows to allow reviewing of quizzes without being influenced by answers
.answer {
opacity: 1 !important;
}
.answer_arrow {
display: none;
}
.answer.wrong_answer {
border-top: 1px solid #ddd !important;
@peterkos
peterkos / PCBinaryTree.java
Created April 25, 2017 17:41
Binary tree with inorder traversal.
import static java.lang.System.*;
import java.util.ArrayList;
public class PCLegitBinaryTree {
public static void main(String[] args) {
@peterkos
peterkos / PCTree.java
Created April 25, 2017 16:18
Generic tree with breadth-first search.
import static java.lang.System.*;
import java.util.ArrayList;
public class PCBTree {
public static void main(String[] args) {
@peterkos
peterkos / StringOps.swift
Last active June 16, 2016 01:19
Adds -=, /=, and *= operation to Strings in Swift.
func -= ( left: inout String, right: String) -> String {
let index = left.index(left.endIndex, offsetBy: -right.characters.count)
return left.substring(to: index)
}
func *= ( left: inout String, right: String) -> String {
var finalString = left
@peterkos
peterkos / InheritingInheritance.java
Last active November 12, 2017 22:15
Changed title.
// Created by @peterkos
// Ported from Swift, originally by Apple
import java.util.*;
public class InheritingInheritance {
public static void main(String[] args) {
Car car = new Car("red");
RaceCar raceCar = new RaceCar("blue", true);
// My hack
ArrayList<Integer> arrayListOfIntegers = new ArrayList<Integer>();
for (char numAsChar : tempArray1AsChar) {
if (numAsChar != ' ') {
arrayListOfIntegers.add(Character.getNumericValue(numAsChar));
}
}
// Julian's hack