Skip to content

Instantly share code, notes, and snippets.

function extend(Child, Parent) {
  var F = function(){};
  F.prototype = Parent.prototype;
  Child.prototype = new F();
  Child.prototype.constructor = Child;
  Child.uber = Parent.prototype;
}
function Animal(cat){
  this.species = "动物";
###
#Step 1 - Generate server certificates etc... (most of this code is horribly ripped off from nodejs docs currently -> http://nodejs.org/docs/latest/api/tls.html)
###
#Assuming your starting from a clean directory
mkdir server
cd server
#generate private key
@1000copy
1000copy / tableviewdemo.m
Last active September 18, 2015 08:33
cocoa tableview datasource demo
#import "ViewController.h"
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self createTableView];
}
NSString* const c1 =@"folder";
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)")
@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
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
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);
<script type="text/javascript">
window.onload = function() {
var current,
screen,
output,
limit,
zero,
period,
operator;
screen = document.getElementById("result");
@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};
}
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)