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
@zonble
zonble / KKSimplePlayer.swift
Created April 21, 2016 16:34
Using AudioQueue and Swift to do a simple stream player
import Foundation
import AudioToolbox
class KKSimplePlayer: NSObject {
var URL: NSURL
var URLSession: NSURLSession!
var packets = [NSData]()
var audioFileStreamID: AudioFileStreamID = nil
var outputQueue: AudioQueueRef = nil
var streamDescription: AudioStreamBasicDescription?
# To solve https://scontent-tpe1-1.xx.fbcdn.net/hphotos-xpt1/v/t1.0-9/12140762_10206383163957694_3005844752527088716_n.jpg?oh=b08035a7d4b6e98257a7b4cbc773a883&oe=579521DB
valid_p = 0
def check(a, b, c, d, g, h):
global valid_p # I always hate to use global vars...
ef = (a * 10 + b) - (c * 10 + d)
e = ef / 10;
f = ef % 10
@zonble
zonble / MethodRemoval.h
Created August 29, 2013 04:21
How to remove Objective-C instance methods
#import <Foundation/Foundation.h>
void removeInstanceMethod(Class cls, SEL _cmd);
@zonble
zonble / parser.php
Created April 16, 2012 17:22
PHP MP3 Parser
<?php
/*
* A tiny parser which parses ID3 tags and MP3 frames.
*/
function parseMP3($mp3file) {
function _parseID3TagsV2($data) {
define("HEADER_LENGTH", 10);
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])
#import <Foundation/Foundation.h>
@interface KKSimpleAirPlay2Player : NSObject
- (id)initWithURL:(NSURL *)inURL;
- (void)play;
- (void)pause;
@property (readonly, getter=isStopped) BOOL stopped;
@end
let response = GCDWebServerStreamedResponse(contentType: "video/mp4", asyncStreamBlock: { block in
/// Fetch data
})
let begin = request.hasByteRaange ? request.byteRange.lowerBound : 0
let end = request.hasByteRaange ? request.byteRange.higherBound : clipFileSize
var readHead = begin
let response = GCDWebServerStreamedResponse(contentType: "video/mp4", asyncStreamBlock: { block in
if readHead < end {
let data = getData(readHead, chunkSize)
block(data, nil)
readHead += data.count
} else {
block(nil, nil)
let response = GCDWebServerStreamedResponse(contentType: "video/mp4", asyncStreamBlock: { block in
 let begin = request.hasByteRaange ? request.byteRange.lowerBound : 0
 let end = request.hasByteRaange ? request.byteRange.higherBound : clipFileSize
 var readHead = begin
 while readHead < end {
 let data = getData(readHead, chunkSize)
 block(data, nil)
 readHead += data.count
 }
})
let response = GCDWebServerStreamedResponse(contentType: "video/mp4", asyncStreamBlock: { block in
 /// Fetch data 
})