ก๊วนซอฟท์แวร์ </softganz> SoftGang (Gang Software)

Web &amp; Software Developer Gang.

602 items|« First « Prev 1 2 (3/61) 4 5 Next » Last »|
โดย Momo on 11 พ.ย. 64 23:02

ผลคือ ไม่ผ่าน

ไว้โอกาสหน้าค่อยเจอกันใหม่

โดย Little Bear on 8 พ.ย. 64 14:10

โดนบ่อย คือ เปิดเข้าเว็บที่ server อยู่ภายใน ม.อ. หาดใหญ่ไม่ได้ เข้า VPN ก็ไม่ได้ ยังหาสาเหตุไม่เจอ แต่พอเปลี่ยน wifi ไปใช้ตัวอื่น (เช่นใช้ hotspot ของมือถือ) ก็สามารถใช้งานได้

Error ตามนี้

Blocked because of IPS attack

An attack was detected, originating from your system. Please contact the system administrator.
โดย Little Bear on 4 ต.ค. 64 14:48

เดี๋ยวค่อยมาเขียนรายละเอียด

Install Apache

Location of Apache config file is /opt/homebrew/etc/httpd/httpd.conf Change www home folder

mv /opt/homebrew/var/www /opt/homebrew/var/www.bak
ln -s /Users/httpdocs /opt/homebrew/var/www
brew services restart apache2

brew tap shivammathur/php

เลือกมาสักเวอร์ชั่น

brew install shivammathur/php/php@5.6
brew install shivammathur/php/php@7.0
brew install shivammathur/php/php@7.1
brew install shivammathur/php/php@7.2
brew install shivammathur/php/php@7.3
brew install shivammathur/php/php@7.4
brew install shivammathur/php/php@8.0
brew install shivammathur/php/php@8.1
brew install shivammathur/php/php@8.2

Mac M1 : Config file อยู่ที่

/opt/homebrew/etc/php/7.0/php.ini
/opt/homebrew/etc/php/7.1/php.ini
/opt/homebrew/etc/php/7.2/php.ini
/opt/homebrew/etc/php/7.3/php.ini
/opt/homebrew/etc/php/7.4/php.ini
/opt/homebrew/etc/php/8.0/php.ini
/opt/homebrew/etc/php/8.1/php.ini
/opt/homebrew/etc/php/8.2/php.ini

Mac Intel : Config file อยู่ที่

/usr/local/etc/php/5.6/php.ini
/usr/local/etc/php/7.0/php.ini
/usr/local/etc/php/7.1/php.ini
/usr/local/etc/php/7.2/php.ini
/usr/local/etc/php/7.3/php.ini
/usr/local/etc/php/7.4/php.ini
/usr/local/etc/php/8.0/php.ini

ผลลัพท์ตอนติดตั้ง

To enable PHP in Apache add the following to httpd.conf and restart Apache:
    LoadModule php7_module /usr/local/opt/php@7.4/lib/httpd/modules/libphp7.so

&lt;FilesMatch .php$&gt;
    SetHandler application/x-httpd-php
&lt;/FilesMatch&gt;

Finally, check DirectoryIndex includes index.php DirectoryIndex index.php index.html

The php.ini and php-fpm.ini file can be found in: /usr/local/etc/php/7.4/

php@7.4 is keg-only, which means it was not symlinked into /usr/local, because this is an alternate version of another formula.

If you need to have php@7.4 first in your PATH, run: echo 'export PATH="/usr/local/opt/php@7.4/bin:$PATH"' >> ~/.zshrc echo 'export PATH="/usr/local/opt/php@7.4/sbin:$PATH"' >> ~/.zshrc

For compilers to find php@7.4 you may need to set: export LDFLAGS="-L/usr/local/opt/php@7.4/lib" export CPPFLAGS="-I/usr/local/opt/php@7.4/include"<br /> <br /> <br /> To start shivammathur/php/php@7.4: brew services start shivammathur/php/php@7.4 Or, if you don't want/need a background service you can just run: /usr/local/opt/php@7.4/sbin/php-fpm --nodaemonize

เปลี่ยนลิงก์

brew unlink php && brew link --overwrite --force php@7.4

Apache

แก้ไขไฟล์ /opt/homebrew/etc/httpd/httpd.conf /etc/apache2/httpd.conf หรือ /usr/local/etc/httpd/httpd.conf file scroll to the bottom of the LoadModule entries.

 LoadModule php5_module /usr/local/opt/php@5.6/lib/httpd/modules/libphp5.so
 <a class="hashtag" href="/tags/LoadModule">#LoadModule</a> php7_module /usr/local/opt/php@7.0/lib/httpd/modules/libphp7.so
 <a class="hashtag" href="/tags/LoadModule">#LoadModule</a> php7_module /usr/local/opt/php@7.1/lib/httpd/modules/libphp7.so
 <a class="hashtag" href="/tags/LoadModule">#LoadModule</a> php7_module /usr/local/opt/php@7.2/lib/httpd/modules/libphp7.so
 <a class="hashtag" href="/tags/LoadModule">#LoadModule</a> php7_module /usr/local/opt/php@7.3/lib/httpd/modules/libphp7.so
 <a class="hashtag" href="/tags/LoadModule">#LoadModule</a> php7_module /usr/local/opt/php@7.4/lib/httpd/modules/libphp7.so
 <a class="hashtag" href="/tags/LoadModule">#LoadModule</a> php_module /usr/local/opt/php@8.0/lib/httpd/modules/libphp.so
 <a class="hashtag" href="/tags/LoadModule">#LoadModule</a> php_module /usr/local/opt/php@8.1/lib/httpd/modules/libphp.so

ใช้ sphp เป็นตัวเปลี่ยน version จะสะดวกกว่า

curl -L https://gist.githubusercontent.com/rhukster/f4c04f1bf59e0b74e335ee5d186a98e2/raw/adc8c149876bff14a33e3ac351588fdbe8172c07/sphp.sh > /opt/homebrew/bin/sphp
chmod +x /opt/homebrew/bin/sphp
sphp 8.1

Install MariaDB

brew install mariadb

Restart MariaDB

Auto start

brew services start mariadb

Manual start

mysql.server restart

Location of database is /opt/homebrew/var/mysql, If you want to change use symbolic link to new location

brew services stop mariadb
cp -R /opt/homebrew/var/mysql /Users/mysql
mv /opt/homebrew/var/mysql /opt/homebrew/var/mysql.bak
mkdir /opt/homebrew/var/mysql
ln -s /Users/mysql /opt/homebrew/var/mysql
brew services start mariadb

MariaDB Configuration

แก้ไขไฟล์ /opt/homebrew/etc/my.cnf.d/my.cnf

[mysqld]
sqlmode="NOFIELDOPTIONS"
  # Avaliable Mode<br />
  # "NOFIELDOPTIONS,IGORESPACE,NOZEROINDATE,NOZERODATE,ERRORFORDIVISIONBYZERO,NOAUTOCREATEUSER,NOENGINESUBSTITUTION"
default-storage-engine = MYISAM
character-set-server = utf8
  <a class="hashtag" href="/tags/collation">#collation</a>-server = utf32unicodeci

หากไม่ต้องการให้ตรวจสอบการบันทึกข้อมูลของฟิลด์ เช่น ข้อมูลยาวเกินกว่าที่กำหนดในฟิลด์ ให้กำหนด mode เป็น NOFIELDOPTIONS

ที่มา

โดย Little Bear on 19 ก.ย. 64 21:24

มี 2 วิธี

  1. QuickTime
  2. Reflector with Airplay

พอดีว่าใช้ iPad Air 2020 แต่ Macbook Pro เป็นรุ่นปี 2015 ซึ่งยังหาวิธีเชื่อมต่อผ่าน Airplay ยังไม่ได้

เลยลอง mirror ผ่าน QuickTime ดู

ขั้นตอนในการ Mirroring With QuickTime

  1. จำเป็นต้องใช้สาย cable ต่อผ่าน USB ของ Mac กับ iPad

  2. เปิด QuickTime บน Mac ก่อน แล้วเลือกเมนู File แล้วเลือก New Movie Recording

  3. จะแสดงหน้าต่างสำหรับบันทึก Movie โดยค่า default จะถูกกำหนดให้เป็นกล้อง

  4. เปลี่ยนให้เป็น iOS device โดยคลิกที่ปุ่มลูกศรลงถัดจากปุ่มบันทึก (record button) แล้วเลือก iOS device จากรายการกล้องที่แสดง

แค่นี้เอง หน้าจอของ iPad ก็จะมีอยู่บนหน้าจอของ Mac เรียบร้อย

ข้อเสียคือต้องต่อสาย USB ระหว่าง Mac กับ iPad ซึ่งอาจจะไม่สะดวกในการใช้งานในบางสถานการณ์

โดย Little Bear on 16 ก.ค. 64 16:23

กำลังหาข้อมูลเกี่ยวกับการ 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
ดูข้อมูลในไฟล์ .jks
keytool -v -list -keystore appname.jks
ดูข้อมูลในไฟล์ .apk
keytool -printcert -jarfile appname.apk

#กำหนดการ 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,
           // so flutter 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


ที่มา:

โดย Little Bear on 17 มิ.ย. 64 14:16

1.ให้ความสำคัญที่สายพ่วงแบตฯ ต้องเส้นใหญ่ (โดยเฉพาะไส้ในต้องเป็นทองแดงเส้นใหญ่ หรือ มีจำนวนเส้นมากๆ) สายเส้นเล็กๆ ที่ขายตามห้าง หรือ ที่อื่นๆ ใช้งานจริงไม่ได้

2.เมื่อพ่วงแบตฯ ควรสตารท์ รถคันที่มาช่วย (เรียก ก) แล้วคีบสายไปรถที่ไฟหมด (เรียก ข) เริ่มที่ ขั้วบวก ก ไป ขั้วบวก ข ต่อมาที่ ลบ ก ไป ลบ ข หรือ คีบตรงเครื่องยนต์ (ส่วนที่มีขอเกี่ยวไว้ยกเครื่อง) เร่งเครื่องยนต์ รถ ก ที่ประมาณ 2000 รอบ ซักพัก (ให้ไฟเข้า) แล้วสตาร์ทรถ ข เมื่อเครื่องยนต์ติดแล้ว ให้ถอดสายพ่วงออกโดยย้อนกลับ เริ่มที่ ลบ ข ไป ลบ ก บวก ข ไป บวก ก เป็นอันจบ

หมายเหตุ 1.สีของสายพ่วงจะแบ่งเป็น แดง (ขั้วบวก) ดำ (ขั้วลบ) ห้ามต่อสลับกันเด็ดขาด ทำให้เกิดไฟช๊อต อาจทำให้ระบบ ไฟฟ้า และ ECU ในรถพังได้

2.เวลาพ่วงรถให้ใครต้องสตาร์ทรถ ก่อนพ่วงทุกครั้ง (ให้ไดร์ชาร์ทจ่ายกระแสไฟแทนหม้อแบตฯ) ป้องกันไฟกระชาก

ปล. copy เขามา

โดย Little Bear on 12 มิ.ย. 64 15:42
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),
        ],
      ),
    );
  }
}

ที่มา

โดย Little Bear on 26 พ.ค. 64 13:02

ติดตั้ง 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 mariadb

sudo nano /etc/mysql/conf.d/mysqld.cnf sudo systemctl restart mysql

debian : service mysqld restart

กรณีที่ติดตั้ง mariadb แล้วไม่ได้กำหนดรหัสของ root

mysql --version

systemctl 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



ที่มา

โดย Little Bear on 17 พ.ค. 64 14:04

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

ที่มา

602 items|« First « Prev 1 2 (3/61) 4 5 Next » Last »|