Skip to content

Instantly share code, notes, and snippets.

View zonble's full-sized avatar

Weizhong Yang a.k.a zonble zonble

View GitHub Profile
import UIKit
enum Op {
case add, minus, multiply, divide
}
@_functionBuilder
class MathBuilder {
static func buildBlock(_ op: Op, _ items:Int...) -> Int {
switch op {
import UIKit
import CryptoKit
func jwt(header: String, payload: String, secret: String) -> String {
func base64URLencode(_ s: String) -> String {
return s.replacingOccurrences(of: "/", with: "_").replacingOccurrences(of: "+", with: "-")
}
let headerData = base64URLencode(header).data(using: .utf8)!.base64EncodedString()
import UIKit
import CryptoKit
import CommonCrypto
let str = "Boom boom boom boom boom boom"
// CryptoKit
func MD5CryptoKit(string: String) -> Data {
string.data(using:.utf8)!.withUnsafeBytes { ptr in
Data(Insecure.MD5.hash(bufferPointer: ptr).map { $0 }[0..<Insecure.MD5.byteCount])
class Range(object):
'An object with a start and a length.'
def __init__(self, start, length):
self.start = start
self.length = length
def contains(self, another):
'If the range contains another range.'
import Foundation
func solution(_ n: Int) -> Int {
func fac(_ n: Int) -> Int {
if n == 1 {
return 1
}
return (1...n).reduce(1, *)
}
@zonble
zonble / 3.swift
Last active January 31, 2018 17:24
import Foundation
func solution(_ n:Int) -> Int {
let sorted_n = "\(n)".sorted()
let i = Int(pow(Double(10), Double("\(n)".count)))
return Array(0...i).filter { "\($0)".sorted() == sorted_n }.count
}
print(solution(0))
print(solution(1))
@zonble
zonble / 3.py
Last active January 31, 2018 17:05
def solution(n):
sorted_n = sorted(str(n))
i = pow(10, len(str(n)))
return len([x for x in range(0, i) if sorted(str(x)) == sorted_n])
import UIKit
import AVFoundation
class ViewController: UIViewController {
var audioEngine = AVAudioEngine()
var audioData = Data()
override func viewDidLoad() {
super.viewDidLoad()
import Foundation
enum ConverterError: Error {
case outOfBounds
}
func UTF8ToUTF16(_ data: Data) -> [unichar] {
func decode(index: Int, length: Int) throws -> unichar {
if index + length > data.count {
throw ConverterError.outOfBounds
function upload_to_app_store()
{
IPA_FILE="${JOB_NAME}_${BUILD_NUMBER}.ipa"
IPA_FILENAME=$(basename $IPA_FILE)
MD5=$(md5 -q $IPA_FILE)
BYTESIZE=$(stat -f "%z" $IPA_FILE)
ITMSP_DIR="itmsp_${AppTarget}"
rm -rf "${ITMSP_DIR}"
mkdir "${ITMSP_DIR}"