Skip to content

Instantly share code, notes, and snippets.

View KelvinJin's full-sized avatar
🎯
Focusing

Jin Wang KelvinJin

🎯
Focusing
  • Uthoft
  • Melbourne
View GitHub Profile

###Note Apple will reject apps that are using private url schemes (Ugh, Apple....) if they are pretty much obvius. Some apps are rejected and others are not, so, be aware of this issue before implementing any of those URL's in your app as a feature.

[UPDATE : Not yet tested in iOS 10. It will fail because of policies changes in URL scheme handling.]

[UPDATE 2:The openURL() method of UIApplication is now deprecated. You should use application(_:open:options:) instead]

##[UPDATE 3: For now you just can use url schemes to open your apps's settings with Swift 3.0 (Xcode 8). I'll keep you informed when OS preferences can be reached]

@KelvinJin
KelvinJin / Logs.md
Created February 2, 2017 23:38
Logs printed out after running jupyter console
iMac:Jupyter jin$ jupyter console --Session.key="b''" --debug --Session.debug=True --kernel=LocalKernel
[ZMQTerminalIPythonApp] Searching ['/Users/jin/Projects/Python/Jupyter', '/Users/jin/.jupyter', '/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/etc/jupyter', '/usr/local/etc/jupyter', '/etc/jupyter'] for config files
[ZMQTerminalIPythonApp] Looking for jupyter_config in /etc/jupyter
[ZMQTerminalIPythonApp] Looking for jupyter_config in /usr/local/etc/jupyter
[ZMQTerminalIPythonApp] Looking for jupyter_config in /usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/etc/jupyter
[ZMQTerminalIPythonApp] Looking for jupyter_config in /Users/jin/.jupyter
[ZMQTerminalIPythonApp] Looking for jupyter_config in /Users/jin/Projects/Python/Jupyter
[ZMQTerminalIPythonApp] Looking for jupyter_console_config in /etc/jupyter
[ZMQTerminalIPythonApp] Looking for jupyter_console_config in /usr/local/etc/jupyter
import UIKit
class ParallaxCollectionViewLayout: UICollectionViewFlowLayout {
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
return super.layoutAttributesForElements(in: rect)?.flatMap { $0.copy() as? UICollectionViewLayoutAttributes }.flatMap(addParallaxToAttributes)
}
// We need to return true here so that everytime we scroll the collection view, the attributes are updated.
override public func shouldInvalidateLayout(forBoundsChange newBounds: CGRect) -> Bool {
return true
import UIKit
class ParallaxCollectionViewLayout: UICollectionViewFlowLayout {
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
return super.layoutAttributesForElements(in: rect)?.flatMap { $0.copy() as? UICollectionViewLayoutAttributes }.flatMap(addParallaxToAttributes)
}
private func addParallaxToAttributes(_ attributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes {
return attributes
}
import UIKit
class SimpleCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var titleLabel: UILabel!
func bind(color: String) {
titleLabel.text = "\(arc4random_uniform(1000))"
backgroundColor = .clear
contentView.backgroundColor = color.hexColor
interface RxBusSubscriber<in T> {
fun onReceived(notification: T)
}
open private class RxBusSubscriberHolder<out T>(t: T) {
private val ref: WeakReference<T> = WeakReference(t)
fun get(): T? = ref.get()
@KelvinJin
KelvinJin / AttributedHTMLFont.swift
Created October 18, 2017 04:31 — forked from chrislonge/AttributedHTMLFont.swift
Attributed HTML With Custom Font Parsing (Playground)
import UIKit
import XCPlayground
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true
let containerView = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 375.0, height: 667.0))
containerView.backgroundColor = UIColor.whiteColor()
XCPlaygroundPage.currentPage.liveView = containerView
var aboutTextView = UITextView(frame: CGRect(x: 12.0, y: 20.0, width: containerView.frame.size.width - 12.0, height: 200.0))
aboutTextView.textAlignment = .Left
<Playlist>
<Preroll>
<Ad>
<![CDATA[https://gist.githubusercontent.com/KelvinJin/ff06196b6d981802372461971281f3da/raw/vast.xml]]>
</Ad>
<Ad>
<![CDATA[https://gist.githubusercontent.com/KelvinJin/ff06196b6d981802372461971281f3da/raw/vast.xml]]>
</Ad>
</Preroll>
<Midroll timeOffset="00:09:00">
@KelvinJin
KelvinJin / content.mpd
Last active April 17, 2019 03:18
android.tv
<?xml version="1.0" encoding="UTF-8"?>
<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" profiles="urn:mpeg:dash:profile:isoff-live:2011" type="static" mediaPresentationDuration="PT1H9M10.403S" minBufferTime="PT2.000S">
<Period id="0" duration="PT28S">
<AdaptationSet mimeType="audio/mp4" segmentAlignment="true" startWithSAP="1" lang="en">
<Role schemeIdUri="urn:mpeg:dash:role:2011" value="main"></Role>
<SegmentTemplate initialization="https://ssaiplayback.ap-southeast-2.prod.boltdns.net/playback/once/redirect/v1/5303576322001/5b947f87-2c38-40f2-8591-caa404bcdb52/x109/$RepresentationID$/init0.m4f" media="https://ssaiplayback.ap-southeast-2.prod.boltdns.net/playback/once/redirect/v1/5303576322001/5b947f87-2c38-40f2-8591-caa404bcdb52/x109/$RepresentationID$/segment$Number$.m4f" startNumber="0" timescale="48000">
<SegmentTimeline>
<S d="95232" r="13"></S>
<S d="11264"></S>
</SegmentTimeline>
@KelvinJin
KelvinJin / sample_hls_android_tv_master.m3u8
Last active September 9, 2019 02:12
sample_hls_android_tv_master.m3u8
#EXTM3U
#EXT-X-VERSION:4
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio-0",NAME="en (Main)",DEFAULT=YES,AUTOSELECT=YES,LANGUAGE="en",URI="https://manifest.prod.boltdns.net/manifest/v1/hls/v5/aes128/5303576322001/7affc152-4e44-42af-8076-9200c5276050/0b240357-30a0-4f47-90a9-6aac5d343808/10s/rendition.m3u8?behavior_id=cce7c9bf-8bda-4c83-9e5c-9795a96fdf14&fastly_token=NWQ3NWM1MDRfZTY3ZmY0ZDVkMDNiNDJhYmQ0N2ZhZTY1NzY0MjlkMTBlYzkxNmJkYTBkMmU4ODFkY2ZlMGQ2ZTc2ZTU3NTU3Ng%3D%3D"
#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subtitles-0",NAME="EN",DEFAULT=NO,LANGUAGE="en",URI="https://manifest.prod.boltdns.net/manifest/v1/hls/v5/clear/5303576322001/7affc152-4e44-42af-8076-9200c5276050/000a8d6d-49c4-434d-abb0-16739dc44c4b/rendition.m3u8?behavior_id=cce7c9bf-8bda-4c83-9e5c-9795a96fdf14&fastly_token=NWQ3NWM1MDRfMTc3YTdkNDE3MTJjYjQ0ZjY1Mjg1MzA0YmRmMTg4YzM2YmI3MmZjYTQwYTY4MTY1MWZlNjM2NWIxMjBiZGQwNQ%3D%3D"
#EXT-X-STREAM-INF:PROGRAM-ID=0,BANDWIDTH=289300,CODECS="mp4a.40.2,avc1.4d000c",RESOLUTION=256x144,AUDIO="audio-0",CLOSED-CAPTIONS=NONE,SU