Mirror iPad to a Mac

มี 2 วิธี
- QuickTime
- Reflector with Airplay
พอดีว่าใช้ iPad Air 2020 แต่ Macbook Pro เป็นรุ่นปี 2015 ซึ่งยังหาวิธีเชื่อมต่อผ่าน Airplay ยังไม่ได้
เลยลอง mirror ผ่าน QuickTime ดู
ขั้นตอนในการ Mirroring With QuickTime
จำเป็นต้องใช้สาย cable ต่อผ่าน USB ของ Mac กับ iPad
เปิด QuickTime บน Mac ก่อน แล้วเลือกเมนู File แล้วเลือก New Movie Recording
จะแสดงหน้าต่างสำหรับบันทึก Movie โดยค่า default จะถูกกำหนดให้เป็นกล้อง
เปลี่ยนให้เป็น iOS device โดยคลิกที่ปุ่มลูกศรลงถัดจากปุ่มบันทึก (record button) แล้วเลือก iOS device จากรายการกล้องที่แสดง
แค่นี้เอง หน้าจอของ iPad ก็จะมีอยู่บนหน้าจอของ Mac เรียบร้อย
ข้อเสียคือต้องต่อสาย USB ระหว่าง Mac กับ iPad ซึ่งอาจจะไม่สะดวกในการใช้งานในบางสถานการณ์
Build App & Upload to store
กำลังหาข้อมูลเกี่ยวกับการ build app with signed เพื่อส่งขึ้น Play Store
ทำตามขั้นตอนในเว็บ flutter.dev
ถ้ายังไม่มี java หรือ error ให้ลอง openjdk ก่อน
brew install openjdk export JAVA_HOME="/opt/homebrew/opt/openjdk/libexec/openjdk.jdk/Contents/Home" java --version
สร้าง key : ถ้ายังไม่มีการสร้างไฟล์ .jks ให้สร้างขึ้นมาก่อน
keytool -genkey -v -keystore /Users/name/appname.jks -keyalg RSA -keysize 2048 -validity 10000 -alias release
#กำหนดการ keystore ไว้ใน app สร้างไฟล์ [project]/android/key.properties แล้ว copy code ด้านล่างไปใส่
storePassword=<password from previous step> keyPassword=<password from previous step> keyAlias=upload storeFile=<location of the key store file, such as /Users/<user name>/upload-keystore.jks>
คำเตือน เก็บรักษาไฟล์ key.properties ไว้ให้ดี อย่างส่งขึ้น git เด็ดขาด
กำหนดค่าเพื่อ signing ใน gradle
1.แก้ไขไฟล์ [project]/android/app/build.gradle
def keystoreProperties = new Properties() def keystorePropertiesFile = rootProject.file('key.properties') if (keystorePropertiesFile.exists()) { keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) }android { ... }
2.หา buildTypes
แทนที่ด้วยbuildTypes { release { // TODO: Add your own signing config for the release build. // Signing with the debug keys for now, // soflutter run --release
works. signingConfig signingConfigs.debug } }
signingConfigs { release { keyAlias keystoreProperties['keyAlias'] keyPassword keystoreProperties['keyPassword'] storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null storePassword keystoreProperties['storePassword'] } } buildTypes { release { signingConfig signingConfigs.release } }
Build
flutter build appbundle
ผลลัพท์ของการ build จะอยู่ที่
build/app/outputs/bundle/release/app-release.aab
ติดขั้นตอนอัพโหลดขึ้น play store
"Your Android App Bundle is signed with the wrong key. Ensure that your App Bundle is signed with the correct signing key and try again. Your App Bundle is expected to be signed with the certificate with fingerprint"
ลองหาทางแก้ไข ก็ไม่หาย แต่พอลองอัพหลายครั้ง ก็ยังขึ้น error แต่ปุ่มให้ SAVE สามารถใช้งานได้ ก็เลยผ่าน
ลองอัพ version ใหม่ ปรากฎว่า ไม่ขึ้น error
ที่มา:
เทคนิคการพ่วงแบต
1.ให้ความสำคัญที่สายพ่วงแบตฯ ต้องเส้นใหญ่ (โดยเฉพาะไส้ในต้องเป็นทองแดงเส้นใหญ่ หรือ มีจำนวนเส้นมากๆ) สายเส้นเล็กๆ ที่ขายตามห้าง หรือ ที่อื่นๆ ใช้งานจริงไม่ได้
2.เมื่อพ่วงแบตฯ ควรสตารท์ รถคันที่มาช่วย (เรียก ก) แล้วคีบสายไปรถที่ไฟหมด (เรียก ข) เริ่มที่ ขั้วบวก ก ไป ขั้วบวก ข ต่อมาที่ ลบ ก ไป ลบ ข หรือ คีบตรงเครื่องยนต์ (ส่วนที่มีขอเกี่ยวไว้ยกเครื่อง) เร่งเครื่องยนต์ รถ ก ที่ประมาณ 2000 รอบ ซักพัก (ให้ไฟเข้า) แล้วสตาร์ทรถ ข เมื่อเครื่องยนต์ติดแล้ว ให้ถอดสายพ่วงออกโดยย้อนกลับ เริ่มที่ ลบ ข ไป ลบ ก บวก ข ไป บวก ก เป็นอันจบ
หมายเหตุ 1.สีของสายพ่วงจะแบ่งเป็น แดง (ขั้วบวก) ดำ (ขั้วลบ) ห้ามต่อสลับกันเด็ดขาด ทำให้เกิดไฟช๊อต อาจทำให้ระบบ ไฟฟ้า และ ECU ในรถพังได้
2.เวลาพ่วงรถให้ใครต้องสตาร์ทรถ ก่อนพ่วงทุกครั้ง (ให้ไดร์ชาร์ทจ่ายกระแสไฟแทนหม้อแบตฯ) ป้องกันไฟกระชาก
ปล. copy เขามา
Flutter :: Package Info for About us
import 'dart:developer'; import 'package:flutter/material.dart'; import 'package:package_info/package_info.dart'; class AboutScreen extends StatefulWidget { static String routeName = "/about"; @override _AboutScreenState createState() => _AboutScreenState(); } class _AboutScreenState extends State<AboutScreen> { PackageInfo _packageInfo = PackageInfo( appName: 'Unknown', packageName: 'Unknown', version: 'Unknown', buildNumber: 'Unknown', ); //SharedPreferences.setMockInitialValues({}); @override initState() { super.initState(); _initPackageInfo(); } Future<void> _initPackageInfo() async { final PackageInfo info = await PackageInfo.fromPlatform(); log(info.toString()); setState(() { _packageInfo = info; }); } Widget _infoTile(String title, String subtitle) { return ListTile( title: Text(title), subtitle: Text(subtitle.isNotEmpty ? subtitle : 'Not set'), ); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( // title: Text(widget.title), title: Text('About us'), ), body: Column( // mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ _infoTile('App name', _packageInfo.appName), _infoTile('Package name', _packageInfo.packageName), _infoTile('App version', _packageInfo.version), _infoTile('Build number', _packageInfo.buildNumber), ], ), ); } }
ที่มา
Ubuntu Server Installation
ติดตั้ง Server ใหม่ของ Ubuntu Server เขียนบันทึกคำสั่งไว้สักหน่อย
Apache Installation
sudo apt update sudo apt upgrade sudo apt install apache2 -y systemctl status apache2 sudo a2dismod ssl sudo a2enmod ssl sudo a2enmod rewrite
Apache config
sudo nano /etc/apache2/sites-available/000-default.conf
เพิ่ม AllowOverride Al
<Directory /home/> Options Indexes FollowSymLinks Options FollowSymLinks AllowOverride All Order allow,deny allow from all Require all granted </Directory>
sudo apt-get install mariadb-server mariadb-client systemctl status mariadbsudo nano /etc/mysql/conf.d/mysqld.cnf sudo systemctl restart mysql
debian : service mysqld restart
กรณีที่ติดตั้ง mariadb แล้วไม่ได้กำหนดรหัสของ root
mysql --versionsystemctl stop mariadb systemctl set-environment MYSQLD_OPTS="--skip-grant-tables --skip-networking" systemctl start mariadb mysql -u root
mysql> FLUSH PRIVILEGES; mysql> SET PASSWORD FOR 'root'@localhost = PASSWORD("newpassword"); mysql> quit
sudo systemctl unset-environment MYSQLD_OPTS sudo systemctl restart mariadb
mysql -u root -p
mysql> CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password'; mysql> GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';
#MySql Config
ตรวจสอบว่าควรกำหนดค่า keybuffersize สักเท่าไหร่ดี
SELECT CONCAT(ROUND(KBS/POWER(1024, -> IF(PowerOf1024<0,0,IF(PowerOf1024>3,0,PowerOf1024)))+0.4999), -> SUBSTR(' KMG',IF(PowerOf1024<0,0, -> IF(PowerOf1024>3,0,PowerOf1024))+1,1)) -> recommendedkeybuffersize FROM -> (SELECT LEAST(POWER(2,32),KBS1) KBS -> FROM (SELECT SUM(indexlength) KBS1 -> FROM informationschema.tables -> WHERE engine='MyISAM' AND -> tableschema NOT IN ('information_schema','mysql')) AA ) A, -> (SELECT 2 PowerOf1024) B;
name /etc/my.cnf
<a class="hashtag" href="/tags/MyISAM">#MyISAM</a> key_buffer_size=4096M join_buffer_size=256K # from 140M for row pointers thread_cache_size=40 # from 8 to avoid thread starvation query_cache_limit=8M # from 4M since you have QC turned OFF key_cache_age_threshold=7200 # from 300 seconds to reduce key_reads RPS key_cache_division_limit=50 # from 100 percent for HOT/WARM caches key_cache_block_size=16K # from 1K to evict bigger block when full open_files_limit=30000 # from 1024 to reduce opened_files RPS table_open_cache=10000 # from 407 to reduce opened_tables RPS table_definition_cache=2000 # from 603 to reduce opened_table_definitions RPS max_heap_table_size=48M # from 32M for additional capacity tmp_table_size=48M # from 32M to reduce created_tmp_disk_tables count innodb_io_capacity=1600 # from 200 to allow more IOPS read_rnd_buffer_size=192K # from 256K to reduce handler_read_rnd_next RPS sort_buffer_size=2M # from 256K to reduce sort_merge_passes count <a class="hashtag" href="/tags/Innodb">#Innodb</a> <a class="hashtag" href="/tags/innodb">#innodb</a>_buffer_pool_size = 6144M innodb_log_file_size = 512M innodb_lru_scan_depth=100 # from 1024 to reduce CPU busy every SE$ max_connections = 500 key_buffer_size = 512M
ติดตั้ง PHP => How to install PHP 7.4 on Ubuntu 22.04 LTS Jammy Linux
sudo apt update && sudo apt upgrade sudo apt install software-properties-common sudo add-apt-repository ppa:ondrej/php -y sudo apt install php7.4 sudo apt install php7.4-{cli,common,curl,zip,gd,mysql,xml,mbstring,json,intl} sudo update-alternatives --config php
sudo apt-get install php7.4 php7.4-mysql php-common php7.4-cli php7.4-json php7.4-common php7.4-opcache libapache2-mod-php7.4 sudo nano /etc/php/7.4/fpm/php.ini sudo systemctl restart apache2 sudo systemctl restart mysql wget -r --ask-password ftp://user:example.com/
Install phpMyAdmin
sudo apt install phpmyadmin php-mbstring php-zip php-gd php-json php-curl
Mount volumn จาก server เดิม มาไว้ใน server ใหม่ เพื่อทำการ copy file
sudo apt install sshfs mkdir folder sshfs -p 22 username@example.com:/home/folder/ folder
ใช้งานเสร็จก็ un mount
umount folder
Configuration
ที่มา
- How to install LAMP stack web server on Ubuntu 20.04
- How To Create a New User and Grant Permissions in MySQL
- How to recursively download a folder via FTP on Linux
- How can I disable and enable SSL in Apache
- How To Reset Your MySQL or MariaDB Root Password on Ubuntu 18.04
- How to enable mod_rewrite in apache ubuntu
- How to install PHP 7.4 on Ubuntu 22.04 LTS Jammy Linux
Flutter Permission
iOS: in ios/Runner/Info.plist
ขอสิทธิ์ Location
<key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key><true/> </dict>
ขอสิทธิ์ใช้กล้อง
<key>NSCameraUsageDescription</key> <string>Explanation on why the camera access is needed.</string>
ขอสิทธิ์ไมโครโฟน
<key>NSMicrophoneUsageDescription</key> <string>Flutter requires acess to microphone.</string>
Android: android/app/build.gradle
defaultConfig { minSdkVersion 21
Android: android/app/src/main/AndroidManifest.xml
<application> <provider android:name="com.pichillilorenzo.flutterinappwebview.InAppWebViewFileProvider" android:authorities="${applicationId}.flutterinappwebview.fileprovider" android:exported="false" android:grantUriPermissions="true"> <meta-data android:name="android.support.FILEPROVIDERPATHS" android:resource="@xml/provider_paths" /> </provider> </application>
Create file res/values/provider_paths.xml
<?xml version="1.0" encoding="utf-8"?> <paths> </paths>
main.dart
import 'package:permission_handler/permission_handler.dart'; Future main() async { WidgetsFlutterBinding.ensureInitialized(); await Permission.camera.request(); runApp(MyApp()); }
สิทธิ์อื่นดูได้จาก Enable camera for HTML inputs
ที่มา
Flutter App Lifecycle
Step 1. Create a new application. The main screen in which will be StatefulWidget. Which should implement the WidgetsBindingObserver interface. Next, we get the instance of WidgetBinding and add an observer to it.
class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( primarySwatch: Colors.blue, ), home: MyHomePage(), ); } } class MyHomePage extends StatefulWidget { @override _MyHomePageState createState() => _MyHomePageState(); } class _MyHomePageState extends State<MyHomePage> with WidgetsBindingObserver { @override void initState() { WidgetsBinding.instance.addObserver(this); super.initState(); } @override void dispose() { WidgetsBinding.instance.removeObserver(this); super.dispose(); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Flutter Tutorial Lifecycle'), ), body: Center(), ); } }
Step 2. Now we have the didChangeAppLifecycleState method available. In this example, we simply print a state change to the thermal.
@override void didChangeAppLifecycleState(AppLifecycleState state) { print('state = $state'); }
ที่มา Flutter App Lifecycle
My First Flutter App
เขียน Flutter App
Create new app
flutter create --org com.yourdomain appname
Set App signing team to your email
Open app using VSCode and run
Then build iodopen ios/Runner.xcworkspace
flutter build ios
In Runner / Targets/Runner -> select Team
If have already created a project: Change package name by add dependencies changeapppackagename: and run
apppackagename:main com.package.appnameflutter pub run change
Run in release mode
flutter run --release
Settings
- เปลี่ยนชื่อ App Icon
- Add permission: กำหนด Permission ด้วยนะ ไม่อย่างนั้นจะเปิด WebView เข้าเน็ตไม่ได้
iOS: แก้ไขไฟล์ ios/Runner/info.plist
<key>CFBundleName</key> <string>APP NAME</string> <key>io.flutter.embeddedviewspreview</key> <string>YES</string>
Android manifest: แก้ไขไฟล์ android/app/src/main/AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" /> <application android:label="APP NAME" >
macOS: in macos/Runner/DebugProfile.entitlements and macos/Runner/Release.entitlements
<key>com.apple.security.network.client</key> <true/>
App Icon:
File : pubspec.yaml
dependencies: ... flutter_launcher_icons: ^0.9.0
flutter_icons:<br /> image_path: "assets/icon/logo_192.png"<br /> android: true ios: true remove_alpha_ios: true
# flutter pub run flutter_launcher_icons:main
เอาคำว่า "DEBUG" ของเธอคืนไป
ใส่ไว้ใน MaterialApp
debugShowCheckedModeBanner: false
Add dependencies แล้ว แต่ import package ไม่ได้
close project and re-open projectflutter packages get
Upgrade version iOS แล้วมองไม่เห็น device
ให้ดาวน์โหลดไฟล์จาก GitHub แล้วนำไฟล์มาวางไว้ที่ (~/Application/) Xcode app ใน path Contents/Developer/Platform/iPhoneOS.platform/DeviceSupport
แล้วก็ Flutter Clean
flutter clean
App Permission
หัวข้ออื่น
ที่มา
- มาลองสร้าง Flutter App กันเถอะ
- ประสบการณ์ Build flutter on iOS ครั้งแรก
- webview_flutter 2.0.2
- Different ways to change the status bar and navigation bar color (iOS and Android) in Flutter
- Flutter Launcher Icons
- How to use user-agent in webview-flutter Flutter?
- Flutter webview intercept and add headers to all requests
- Webview in flutter not working getting a platform error
- Flutter BottomNavigationBar not working with more than three items
Server Down : Mysql error 28 no space left on the device
เกิดอาการนี้มาเป็นวันที่ 2 แล้ว เมื่อวานสั่ง reboot แล้วหาย แต่วันนี้ reboot แล้วยังคงมีอาการอยู่
ที่เคยเจออาการนี้ คือ harddisk เต็ม ซึ่งปกติจะตรวจพื้นที่เหลือใน harddisk ก่อน ด้วย df -h ผลออกมาว่ายังมีพื้นที่เหลืออีกเพียบ จนในที่สุดก็พบว่าที่เต็มนั้นไม่ใช่พื้นที่ แต่เป็น inode ลองตรวจดูด้วยคำสั่ง df -i พบว่า / เต็ม 100%
สาเหตุของครั้งนี้คือ inode ที่มีไว้สำหรับเก็บตำแหน่ง folder/file เต็ม เท่าที่อ่านดู ยังไม่สามารถขยายเพิ่มได้ (ต้องทำตอน format harddisk) จึงต้องค้นหาว่า folder ไหนที่มีไฟล์เป็นจำนวนมาก แล้วก็ลบ/ย้ายไปไว้ที่อื่นที่ใช้คนละ inode กัน
# df -i
Filesystem Inodes IUsed IFree IUse% Mounted on udev 1275949 357 1275592 1% /dev tmpfs 1278745 553 1278192 1% /run /dev/sda1 1831424 1831424 0 100% / tmpfs 1278745 1 1278744 1% /dev/shm tmpfs 1278745 3 1278742 1% /run/lock tmpfs 1278745 15 1278730 1% /sys/fs/cgroup /dev/sdb1 122093568 8699755 113393813 8% /backup /dev/sda4 119996416 4748787 115247629 4% /home /dev/sda2 122400 337 122063 1% /boot tmpfs 1278745 10 1278735 1% /run/user/1004
คำสั่ง ls เพื่อดูว่าแต่ละ file มี inode หมายเลขอะไร
# ls -lai
คำสั่งสำหรับนับจำนวนไฟล์ในแต่ละ folder
# for i in /*; do echo $i; find $i |wc -l; done
# echo "Detailed Inodes usage for: $(pwd)" ; for d in `find -maxdepth 1 -type d |cut -d/ -f2 |grep -xv . |sort`; do c=$(find $d |wc -l) ; printf "$c - $d " ; done ; printf "Total: $(find $(pwd) | wc -l) "
พบว่า folder usr/local/directadmin/data/tickets มี folder/file จำนวนมาก ซึ่งสะสมมาจาก ticket ที่ระบบอัตโนมัตของ directadmin สร้างขึ้นมา จึงทำการลบไฟล์ทิ้งทั้งหมด
# rm -rm /usr/local/directadmin/data/tickets[code] แล้วย้าย folder tickets ไปไว้ใน /backup (ซึ่งอยู่คนละ harddisk ก็จะไม่มีผลต่อ inode ของ /) [code] # mkdir /backup/usr # mkdir /backup/usr/local # mkdir /backup/usr/local/directadmin # mkdir /backup/usr/local/directadmin/data # mkdir /backup/usr/local/directadmin/data/tickets [code] เปลี่ยน owner/group ให้เป็นของ DirectAdmin [code] # chown diradmin:diradmin /backup/usr/local/directadmin # chown diradmin:diradmin /backup/usr/local/directadmin/data # chown diradmin:diradmin /backup/usr/local/directadmin/data/template # chown diradmin:diradmin /backup/usr/local/directadmin/data/tickets
สร้างลิงก์ tickets ไปที่ใหม่
# cd /usr/local/directadmin/data # mv tickets tickets.old # ln -s /backup/usr/local/directadmin/data/tickets tickets # chown -h diradmin:diradmin tickets
ปล. เขาบอกว่าให้ลบไฟล์ session ทิ้งด้วย
# find . -type f -name sess_\* -delete
ที่มา