Skip to content

Instantly share code, notes, and snippets.

View ryanlid's full-sized avatar
🎯
Focusing

ryanlid ryanlid

🎯
Focusing
View GitHub Profile
@ryanlid
ryanlid / main.dart
Created June 26, 2019 08:08
dart class
void main() {
Human jenny = Human(startingHeight: 15);
print(jenny.height);
Human jemes = Human(startingHeight: 20);
print(jemes.height);
jemes.talk("hello");
}
void main() {
Human jenny = Human(15, 40);
print(jenny.height);
Human jemes = Human(110, 10);
print(jemes.height);
print(jemes.weight);
jemes.talk("hello");
}
@ryanlid
ryanlid / main.dart
Created July 3, 2019 00:43
Flutter Navigator
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Screen1(),
);
@ryanlid
ryanlid / main.dart
Created July 3, 2019 09:27
navigation named route demo
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
initialRoute: "/",
routes: {
@ryanlid
ryanlid / main.dart
Created July 6, 2019 10:50
dart async await Future (flutter)
import 'dart:io';
void main() {
performTask();
}
void performTask() async {
task1();
String task2result = await task2();
task3(task2result);
void main() {
Car myCar = Car();
print(myCar.numberOfSeat);
myCar.drive();
ElectriCar myTesla = ElectriCar();
myTesla.drive();
print(myTesla.batteryLevel);
}
@ryanlid
ryanlid / server.js
Created August 3, 2019 16:18
http sever && https server
const http = require("http");
const https = require("https");
const fs = require("fs");
const express = require("express");
const app = express();
// http server
const http_server = http.createServer(app);
http_server.listen(80, "0.0.0.0");
const options = {
@ryanlid
ryanlid / promise.js
Created August 9, 2019 04:24
promise ajax
function ajax(method, url, data) {
var request = new XMLHttpRequest();
return new Promise(function (resolve, reject) {
request.onreadystatechange = function () {
if (request.readyState === 4) {
if (request.status === 200) {
resolve(request.responseText);
} else {
reject(reject(reject.status));
}
@ryanlid
ryanlid / app.js
Created August 12, 2019 10:07
使用中间件获取响应时间
const koa = require("koa");
const app = new koa();
app.use(async (ctx, next) => {
let stime = new Date().getTime();
await next();
let etime = new Date().getTime();
ctx.response.type = "text/html";
ctx.response.body = "<h1>Hello World</h1>";
console.log(`请求地址:${ctx.path},响应时间:${etime - stime}`);
});
@ryanlid
ryanlid / app.js
Created August 13, 2019 01:27
使用 koa-bodyparser 中间件解析POST请求参数
const koa = require("koa");
const app = new koa();
const bodyParser = require("koa-bodyparser");
app.use(bodyParser());
app.use(async ctx => {
if (ctx.url === "/" && ctx.method === "GET") {
ctx.type = "html";
let html = `
<h1>登录</h1>