This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Simple Factory:把创建方法放到单独的类(工厂类),此方法根据传入的参数来决定实例化哪一个类。 | |
class Shape{draw(){}} | |
class Rect extends Shape{draw(){}} | |
class Circle extends Shape{draw(){}} | |
class ShapeFactory{ | |
createShape(type){ | |
if (shape == "rect"){ | |
return new Rect() | |
}else{ | |
return new Circle() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import XCTest | |
@testable import lang6 | |
class lang6Tests: XCTestCase { | |
override func setUp() { | |
super.setUp() | |
// Put setup code here. This method is called before the invocation of each test method in the class. | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// lang6Tests.swift | |
// lang6Tests | |
// | |
// Created by lcj on 2017/11/15. | |
// Copyright © 2017年 lcj. All rights reserved. | |
// | |
import XCTest | |
@testable import lang6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
typealias callbackJsonError = (_ json:[String:Any],_ error : Error?)-> Void | |
@UIApplicationMain | |
class AppDelegate: UIResponder, UIApplicationDelegate,URLSessionDelegate { | |
var window: UIWindow? | |
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { | |
loadJSON("https://httpbin.org/ip"){(json,error )in | |
var j = JSONData() | |
j.loadFrom(json) | |
print(j.origin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Building a router</title> | |
<script> | |
var routes = {}; | |
function route (path, innerHTML) { | |
routes[path] = {innerHTML: innerHTML}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
window.onload = function() { | |
var current, | |
screen, | |
output, | |
limit, | |
zero, | |
period, | |
operator; | |
screen = document.getElementById("result"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe("Int Checker", function() { | |
describe("isInt suite", function() { | |
beforeEach(function() { | |
}); | |
it("输入案例123返回true", function() { | |
var result = isInt("123") | |
expect(result).toEqual(true); | |
// expect(result).toBeFalsy(); | |
// expect(player).not.toBePlaying(song); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isInt(str){ | |
var i | |
for (i = 0; i < str.length; i++) { | |
var c = str[i] | |
if (!"0123456789-".includes(c)) | |
return false | |
} | |
if (str.includes("-") && str[0]!="-" || str.length==1) | |
return false | |
return true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
@UIApplicationMain | |
class AppDelegate: UIResponder, UIApplicationDelegate { | |
var window: UIWindow? | |
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { | |
self.window = UIWindow(frame: UIScreen.main.bounds) | |
let page = Page1() | |
self.window!.rootViewController = page | |
self.window?.makeKeyAndVisible() | |
return true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import appbase | |
@UIApplicationMain | |
class App: AppBase{ | |
override func run(){ | |
let http = Http() | |
http.get("https://httpbin11111.org/ip11"){(data) in | |
do{ | |
let json = try JSONSerialization.jsonObject(with: data, options:[]) | |
print("json: \(json)") |