Skip to content

Instantly share code, notes, and snippets.

View towry's full-sized avatar
🎯
Focusing

Towry Wang towry

🎯
Focusing
View GitHub Profile
@towry
towry / playground-example.swift
Last active January 5, 2018 08:50
How to run the code in swift in infinite mode.
import PlaygroundSupport
public func playgroundShouldContinueIndefinitely() {
PlaygroundPage.current.needsInfiniteExecution = true
}
@towry
towry / rust_lifetime.md
Created November 9, 2017 01:06
rust lifetime.

Lifetime explained

fn main() {
    let x = "hi";   // lifetime a.
    let e;       // e should have a lifetime a.

    {
        let y = "you";   // lifetime b.
        e = check(&x, &y); // here we returned lifetime b.
@towry
towry / TestableJavaScript.md
Created September 11, 2017 13:09 — forked from jbranchaud/TestableJavaScript.md
Resources on writing testable JavaScript

Testable JavaScript Resources

Testing JavaScript isn't just a thing you can read about in children's fairy tales.

This is just a scratch pad of everything I find. As the really good resources start to float to the top, I'll transition them to a more permanent GitHub repo.

General

@towry
towry / .ackrc
Created September 4, 2017 02:19 — forked from kevinold/.ackrc
#ack is a tool like grep, designed for programmers with large trees of heterogeneous source code
#to install ack, see http://betterthangrep.com/
#to use ack, launch terminal (mac osx) and type 'ack <some_keywords>'
#ack will search all files in the current directory & sub-directories
#here's how I have my config file setup. this file is located on mac osx here
# ~/.ackrc
# Always sort the files
@towry
towry / context.rb
Last active July 21, 2017 07:33
describe the DCI(Data, context, interaction) architecture in Ruby.
require_relative "customer"
require_relative "user"
# context bind role to object.
# by using the extend method in ruby.
# now the data object has some behaviors that get from the role class(Customer).
class Context
def initialize(user, book)
@customer, @book = user, book
@customer.extend(Customer)
@towry
towry / date_from_string.swift
Created July 17, 2017 05:52
convert date string into date in swift.
//: Playground - noun: a place where people can play
import AppKit
let dateFormatter = DateFormatter()
dateFormatter.dateStyle = .long
dateFormatter.timeStyle = .none
let dateStr = "2017-10-12"
@towry
towry / ioslocaleidentifiers.csv
Created July 17, 2017 05:32 — forked from jacobbubu/ioslocaleidentifiers.csv
iOS Locale Identifiers
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
mr Marathi
bs Bosnian
ee_TG Ewe (Togo)
ms Malay
kam_KE Kamba (Kenya)
mt Maltese
ha Hausa
es_HN Spanish (Honduras)
ml_IN Malayalam (India)
ro_MD Romanian (Moldova)
@towry
towry / proxy_syntax_pattern.swift
Last active July 12, 2017 09:08
swift proxy pattern demo.
//
// https://medium.com/@jegnux/safe-collection-subsripting-in-swift-3771f16f883
// https://github.com/ReactiveX/RxSwift/issues/826
//
import Foundation
// we define a fire protocol.
protocol FireProtocol {
@towry
towry / associatedobject.swift
Created July 12, 2017 08:09
associated objects demo in swift. objc_setAssociatedObject, objc_getAssociatedObject
// So associated objects just store object in anoter place, use property to
// associate the object with the class object.
import Foundation
let data: Data?
var dataKey: Void?
data = Data(count: 10)
data?.insert(9, at: 0)
/// https://github.com/apple/swift-evolution/blob/master/proposals/0142-associated-types-constraints.md
protocol SubContainer: Container {
associatedtype Item: Equatable
}
protocol Container {
associatedtype Item
// error: 'where' clause cannot be attached to an associated type declaration
// error: type may not reference itself as a requirement