Skip to content

Instantly share code, notes, and snippets.

View jay18001's full-sized avatar

J Anderson jay18001

View GitHub Profile
@jay18001
jay18001 / ReceiptController.swift
Created March 3, 2019 04:37
verifies apple app store receipt using vapor
//
// ReceiptController.swift
// App
//
// Created by Justin Anderson on 3/2/19.
//
import Foundation
import Vapor
@jay18001
jay18001 / MegaMillions.swift
Created October 24, 2018 00:27
Mega Millions Checker
import Foundation
extension Array {
func choose(_ n: Int) -> Array { return Array(shuffled().prefix(n)) }
}
struct Ticket {
let numbers: [Int]
let bonus: Int
}
@jay18001
jay18001 / Blackjack.swift
Created October 19, 2018 02:18
Blackjack
import Foundation
enum Card {
case ace
case face(value: Int)
case jack
case queen
case king
}
@jay18001
jay18001 / SquareRoot.c
Created December 28, 2017 05:14
Square Root With WebAssembly
#include <stdio.h>
#include <stdint.h>
#include <emscripten/emscripten.h>
double EMSCRIPTEN_KEEPALIVE sq_root(double count) {
if (count == 0) {
return 1;
} else if (count == 1) {
return 2;
}
@jay18001
jay18001 / Matrix4.swift
Created February 24, 2017 02:57
Swift version of helper class from Ray Wenderlich: Metal Tutorial with Swift 3 Part 2
import UIKit
import GLKit
extension Float {
var radians: Float {
return GLKMathDegreesToRadians(self)
}
}
class Matrix4 {
@jay18001
jay18001 / RandomNumber.swift
Created February 10, 2017 16:27
Script to generate a random number
import Foundation
let maxValue: UInt32
if CommandLine.arguments.count >= 2 {
maxValue = UInt32(CommandLine.arguments[1]) ?? 100
} else {
maxValue = 100
}
@jay18001
jay18001 / gist:3678f8e9ba8859f443a8785340a99fb9
Created November 10, 2016 12:47
Installing Swift on raspberry pi
wget http://swift-arm.ddns.net/job/Swift-3.0-ARMv7-ubuntu1410/29/artifact/swift-3.0-2016-11-03-armv7-ubuntu14.04.tar.gz
mkdir swift-3.0
cd swift-3.0 && tar -xzf ../swift-3.0-2016-10-21-RPi23-ubuntu16.04.tar.gz
export PATH=$HOME/swift-3.0/usr/bin:$PATH
sudo nano /etc/apt/sources.list
#uncomment this line
deb-src http://archive.raspbian.org/raspbian/ jessie main contrib non-free rpi
sudo apt-get update
@jay18001
jay18001 / StoryboardInitialization.swift
Last active May 23, 2018 04:14
Protocol StoryboardInitialization
public protocol StoryboardInitialization {
static var storyboardIdentifier: String { get }
}
public extension UIStoryboard {
public func instantiateViewController<T: StoryboardInitialization>(withType classIdent: T.Type) -> T? {
return self.instantiateViewController(withIdentifier: classIdent.storyboardIdentifier) as? T
}
}
func test() -> Int {
func test() -> Int {
func test() -> Int {
func test() -> Int {
func test() -> Int {
func test() -> Int {
func test() -> Int {
func test() -> Int {
func test() -> Int {
func test() -> Int {