Skip to content

Instantly share code, notes, and snippets.

View mdecourse's full-sized avatar

KMOLab mdecourse

  • KMOL
  • Taiwan
View GitHub Profile
@mdecourse
mdecourse / classes_ex1.dart
Created September 8, 2019 12:08
Dart 2 程式語法集結
import "dart:math" as math;
class Point {
/*
Declare a constructor by creating a function with the same name as its class (plus, optionally, an additional identifier as described in Named constructors)
*/
num x, y;
// Constructor
//Point(num x, num y) {
// The "this" keyword refers to the current instance.
@mdecourse
mdecourse / helloworldfancy.dart
Last active September 9, 2019 23:57
ch2 - Dart for absolute begineers
// 導入 dart:html
// 注意每一段可執行的程式敘述句最後要有 ;
import 'dart:html';
// 每一個 dart 程式都從 main() 主函式開始執行, void 表示此函式沒有傳回值, void 在此可以省略
void main() {
// 超過一行的程式區段, 以大括號區隔
// querySelector 函式屬於 dart:html 中的一員, 專門用來取 html 中的特定 Element
// 當 id 為 button 的 Element 被按下後 (onClick 為 Element 的 properties 之一), 會傳回 stream, 交給 listen 方法, 用來啟動 sayHello 函式
querySelector("#button").onClick.listen(sayHello);
}
@mdecourse
mdecourse / flutter_kmol.dart
Last active September 10, 2019 01:28
Flutter web ex1
import 'package:flutter_web/material.dart';
import 'package:flutter_web_ui/ui.dart' as ui;
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Hi Kmol',
home: Scaffold(
appBar: AppBar(
@mdecourse
mdecourse / flutter web demo on dartpad.dart
Last active September 10, 2019 01:58
Flutter Web demo on dartpad
import 'package:flutter_web/material.dart';
import 'package:flutter_web_ui/ui.dart' as ui;
Future<void> main() async {
await ui.webOnlyInitializePlatform();
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@mdecourse
mdecourse / bmi_ex.dart
Created September 11, 2019 00:25
BMI dartpad example
// Copyright 2014 David Kopec
// Created for Dart for Absolute Beginners, an Apress title
// This source code is released under the terms outlined in license.txt in the
// source code respository's root directory.
import 'dart:html';
bool imperial = true;
const int IMPERIAL_MULTIPLIER = 703;
@mdecourse
mdecourse / Point_and_Line.dart
Last active September 17, 2019 00:31
dart program
import "dart:math" as math;
class Point {
// x, y are both final, can not be set to new coordinate
final num x, y;
Point(this.x, this.y);
Point.origin()
: x = 0,
y = 0;
num distanceTo(Point other) {
@mdecourse
mdecourse / index.html
Created September 17, 2019 02:23
Canvas in dartpad
<canvas id="dart_canvas_example" height='500' width='500'>
Your browser does not support Canvas
</canvas>
@mdecourse
mdecourse / oop.dart
Last active September 18, 2019 00:49
Dart 物件導向
// 導入 dart 的核心數學程式庫, 並設其名稱為 math
import "dart:math" as math;
// 定義一個類別, 名稱為 Point
class Point{
// 定應兩個案例變數 x 與 y 資料型別為 num, 表示可以是整數或幅點數
num x;
num y;
// 定義一個與類別名稱相同的建構子 (建立案例時, 會自動執行此一建構子方法內容), 具有兩個輸入變數
@mdecourse
mdecourse / get_links_of_repo_and_site.dart
Last active September 20, 2019 09:33
Convert string into list
@mdecourse
mdecourse / upgrade_all_modules.py
Created September 27, 2019 00:11
upgrade all python installed modules
import pkg_resources
from subprocess import call
packages = [dist.project_name for dist in pkg_resources.working_set]
print(packages)
print()
call("python -m pip install --upgrade " + ' '.join(packages), shell=True)