Skip to content

Instantly share code, notes, and snippets.

View ApolloZhu's full-sized avatar
🐣
Improving Swift Platform Experience

Zhiyu Zhu/朱智语 ApolloZhu

🐣
Improving Swift Platform Experience
View GitHub Profile
@ApolloZhu
ApolloZhu / HueGradientLayer.swift
Last active June 26, 2017 04:51
[Rainbow Layer] Implementing "rainbow" layer with Swift Playground on iPad #swift #playground #iOS
//#-editable-code
// Additional Comments
//#-end-editable-code
// Contents.swift
// Rainbow
//
// Created by Apollo Zhu (https://github.com/ApolloZhu) on 2016/11/25.
// Copyright (c) 2015-2017 WWITDC. All rights reserved.
//
@ApolloZhu
ApolloZhu / AZProportionalView.swift
Last active June 26, 2017 04:35
[AZProportionalView] A view that always maintains a certain ratio. #swift #iOS
//
// AZProportionalView.swift
// AZProportionalView
//
// Created by Apollo Zhu on 10/10/16.
// Copyright © 2014-2017 WWITDC. All rights reserved.
//
import UIKit
@ApolloZhu
ApolloZhu / Lau.kt
Created October 8, 2017 19:53
Lau Board Android
import android.content.Context
import android.media.MediaPlayer
import android.os.AsyncTask
/**
* Created by Apollonian on 9/16/17.
*/
object Lau {
val quotes = arrayOf(
R.raw.allright to "Alrigth",
//
// ViewController.swift
// layout
//
// Created by Liuliet.Lee on 10/8/2017.
// Copyright © 2017 Liuliet.Lee. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
@ApolloZhu
ApolloZhu / AZTwoWayDictionary.swift
Last active December 7, 2017 23:44
Swifty BiMap / Two way / One to One Dictionary (双向映射)
//
// AZBiDictionary.swift
// Bimap
//
// Created by Apollo Zhu on 10/26/16.
//
import Foundation
extension Dictionary {
let c={String(repeating:$0,count:$1)};func d(_ n:Int,_ i:Int=0)->String{let b=c(" ",i)+c("*",n)+"\n";return n>1 ?b+d(n-2,i+1)+b:b}
print(d(5))
@ApolloZhu
ApolloZhu / Compute Eulerian number.swift
Created January 13, 2018 15:52
codegolf.stackexchange.com/questions/96747/compute-the-eulerian-number
func A(_ n:Int,_ m:Int)->Int{return m<1 ? 1 : n>m ? (n-m)*A(n-1,m-1)+(m+1)*A(n-1,m) : 0}
print("n\tm\tA(n,m)")
_ = zip([0,1,1,2,2,2,3,3,3,3,4,4,4,4,4,5,7,9,10,10,10,12,15,17,20,42],[0,0,1,0,1,2,0,1,2,3,0,1,2,3,4,1,4,5,5,7,10,2,6,1,16,42]).map {
print("\($0)\t\($1)\t\(A($0,$1))")
}
@ApolloZhu
ApolloZhu / Merge Sorted.swift
Created January 13, 2018 15:53
Merge two sorted array into one in the same order
func mergeSorted<T:Comparable>(_ x: [T], _ y: [T], inOrder cmp: (T, T) -> Bool = (<) ) -> [T] {
var z = [T]()
var i = 0, j = 0
while i < x.count || j < y.count {
if j == y.count || cmp(x[i], y[j]) {
z.append(x[i])
i += 1
} else {
z.append(y[j])
j += 1
import Foundation
let c={(s:String) in s.utf8.map{String(format:"%02d",$0-96)}.joined()}
_ = ["helloworld","codegolf","alphabetcipher","johncena"].map{print(c($0))}
print(" ")
print("codegolf".utf8.map{String(format:"%02d",$0-96)}.joined())