Skip to content

Instantly share code, notes, and snippets.

@1000copy
1000copy / factory3.js
Last active December 13, 2017 10:24
工厂三姐妹的介绍,for humans
// 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()
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.
}
//
// lang6Tests.swift
// lang6Tests
//
// Created by lcj on 2017/11/15.
// Copyright © 2017年 lcj. All rights reserved.
//
import XCTest
@testable import lang6
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)
@1000copy
1000copy / router.html
Last active November 14, 2017 08:14
client routers
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Building a router</title>
<script>
var routes = {};
function route (path, innerHTML) {
routes[path] = {innerHTML: innerHTML};
}
<script type="text/javascript">
window.onload = function() {
var current,
screen,
output,
limit,
zero,
period,
operator;
screen = document.getElementById("result");
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);
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
@1000copy
1000copy / setimage.swift
Last active October 23, 2017 10:31
swift setImage with nscache and file cache
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
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)")