EExcel 丞燕快速查詢2

EExcel 丞燕快速查詢2
EExcel 丞燕快速查詢2 https://sandk.ffbizs.com/

Livewire form and outside form with button action maybe different your think

In liveiwre word some button action and alpine @click action be clicked, livewire 3 update (ajax) is different your think. Component

    public $test_input=1;

    public function tt()
    {
        info('tt');
        info($this->test_input);
    }
blade

        <div class="row row-cols-1 row-cols-md-3 g-4" x-data>
            <form wire:submit="tt">
                <input type="text" wire:model='test_input'>
                <button type="submit">form type=submit</button> {{-- // update (ajax) --}}
                <button type="button">form type=button</button> {{-- // No update (ajax) --}}

                <button wire:click='tt; $wire.test_input=3;'>form wire:click</button> {{-- // update (ajax) and run twice --}}
                <button @click='$wire.tt; $wire.test_input=3;'>form @click</button> {{-- // update (ajax) and run twice --}}
            </form>

            <button type="submit">out form type=submit</button> {{-- // No update (ajax) --}}
            <button type="button">out form type=button</button> {{-- // No update (ajax) --}}

            <button wire:click='tt; $wire.test_input=3;'>out form wire:click</button> {{-- // update (ajax)  --}}
            <button @click='$wire.tt; $wire.test_input=3;'>out form @click</button> {{-- // update (ajax)  --}}
        </div>
So be careful and try to understand
1. what time public variable have value or be set value
2. run twice, not run one.

[轉] Powershell Script for Sending Email via Remote SMTP

https://tecadmin.net/powershell-sending-email-via-smtp/

# Define the sender, recipient, subject, and body of the email
$From = "sender@example.com"
$To = "recipient@example.com"
$Subject = "Test Email"
$Body = "This is a test email sent via remote SMTP using PowerShell."
 
# Define the SMTP server details
$SMTPServer = "smtp.example.com"
$SMTPPort = 587
$SMTPUsername = "username"
$SMTPPassword = "password"
 
# Create a new email object
$Email = New-Object System.Net.Mail.MailMessage
$Email.From = $From
$Email.To.Add($To)
$Email.Subject = $Subject
$Email.Body = $Body
# Uncomment below to send HTML formatted email
#$Email.IsBodyHTML = $true
 
# Create an SMTP client object and send the email
$SMTPClient = New-Object System.Net.Mail.SmtpClient($SMTPServer, $SMTPPort)
$SMTPClient.EnableSsl = $true
 
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential($SMTPUsername, $SMTPPassword)
$SMTPClient.Send($Email)
 
# Output a message indicating that the email was sent successfully
Write-Host "Email sent successfully to $($Email.To.ToString())"

gitlab runner 【x509: certificate relies on legacy Common Name field, use SANs instead】 And 【x509: certificate signed by unknown authority】

https://gitlab.com/gitlab-org/gitlab-runner/-/issues/28841

【x509: certificate relies on legacy Common Name field, use SANs instead】

1. Change all example.com for your domain

openssl genrsa -out ca.key 2048

openssl req -new -x509 -days 365 -key ca.key -subj "/C=CN/ST=GD/L=SZ/O=Acme, Inc./CN=Acme Root CA" -out ca.crt

openssl req -newkey rsa:2048 -nodes -keyout example.com.key -subj "/C=CN/ST=GD/L=SZ/O=Acme, Inc./CN=*.example.com" -out example.com.csr

openssl x509 -req -extfile <(printf "subjectAltName=DNS:example.com,DNS:www.example.com") -days 365 -in example.com.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out example.com.crt

2. Put crt and key to gitlab ssl. Stop gitlab. Start gitlab.

Check gitlab have new DNS

openssl s_client -connect example.com:443 /dev/null | openssl x509 -noout -text | grep DNS:
3. if have 【x509: certificate signed by unknown authority】


gitlab-runner register --tls-ca-file="Use just create crt file"

laravel socialite line How to

Thank

https://medium.com/laravel-news/adding-auth-providers-to-laravel-socialite-ca0335929e42

This have problems https://socialiteproviders.com/Line/

1.


composer require socialiteproviders/line

2. create app/Providers/LineProvider.php

https://github.com/SocialiteProviders/Line/blob/master/Provider.php


namespace App\Providers;

use GuzzleHttp\RequestOptions;
use Laravel\Socialite\Two\InvalidStateException;
use \SocialiteProviders\Manager\OAuth2\AbstractProvider;
use \SocialiteProviders\Manager\OAuth2\User;

class LineProvider extends AbstractProvider
{
    public const IDENTIFIER = 'LINE';

    /**
     * The separating character for the requested scopes.
     *
     * @var string
     */
    protected $scopeSeparator = ' ';

    /**
     * The scopes being requested.
     *
     * @var array
     */
    protected $scopes = [
        'openid',
        'profile',
        'email',
    ];

    /**
     * Get the authentication URL for the provider.
     *
     * @param  string  $state
     * @return string
     */
    protected function getAuthUrl($state)
    {
        return $this->buildAuthUrlFromBase(
            'https://access.line.me/oauth2/v2.1/authorize',
            $state
        );
    }

    /**
     * Get the token URL for the provider.
     *
     * @return string
     */
    protected function getTokenUrl()
    {
        return 'https://api.line.me/oauth2/v2.1/token';
    }

    /**
     * Get the raw user for the given access token.
     *
     * @param  string  $token
     * @return array
     */
    protected function getUserByToken($token)
    {
        $response = $this->getHttpClient()->get(
            'https://api.line.me/v2/profile',
            [
                RequestOptions::HEADERS => [
                    'Authorization' => 'Bearer '.$token,
                ],
            ]
        );

        return json_decode((string) $response->getBody(), true);
    }

    /**
     * Map the raw user array to a Socialite User instance.
     *
     * @param  array  $user
     * @return \Laravel\Socialite\User
     */
    protected function mapUserToObject(array $user)
    {
        return (new User())->setRaw($user)->map([
            'id'       => $user['userId'] ?? $user['sub'] ?? null,
            'nickname' => null,
            'name'     => $user['displayName'] ?? $user['name'] ?? null,
            'avatar'   => $user['pictureUrl'] ?? $user['picture'] ?? null,
            'email'    => $user['email'] ?? null,
        ]);
    }

    // /**
    //  * Get the POST fields for the token request.
    //  *
    //  * @param string $code
    //  *
    //  * @return array
    //  */
    // protected function getTokenFields($code)
    // {
    //     return array_merge(parent::getTokenFields($code), [
    //         'grant_type' => 'authorization_code',
    //     ]);
    // }

    /**
     * @return \SocialiteProviders\Manager\OAuth2\User
     */
    public function user()
    {
        if ($this->hasInvalidState()) {
            throw new InvalidStateException();
        }

        $response = $this->getAccessTokenResponse($this->getCode());

        if ($jwt = $response['id_token'] ?? null) {
            $bodyb64 = explode('.', $jwt)[1];
            $user = $this->mapUserToObject(json_decode(base64_decode(strtr($bodyb64, '-_', '+/')), true));
        } else {
            $user = $this->mapUserToObject($this->getUserByToken(
                $token = $this->parseAccessToken($response)
            ));
        }

        $this->credentialsResponseBody = $response;

        if ($user instanceof User) {
            $user->setAccessTokenResponseBody($this->credentialsResponseBody);
        }

        return $user->setToken($this->parseAccessToken($response))
            ->setRefreshToken($this->parseRefreshToken($response))
            ->setExpiresIn($this->parseExpiresIn($response));
    }
}

3. edit app/Providers/AppServiceProvider.php


namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     */
    public function register(): void
    {
        //
    }

    /**
     * Bootstrap any application services.
     */
    public function boot(): void
    {
        $this->bootLineSocialite();
    }

    public function bootLineSocialite(): void
    {
        // // laravel Socialite 和 Socialite Line 有問題,就是 在初始載入不了
        // // 看Socialite Line 作者還有在3星期前維謢,所以就不知道怎麼回事
        // // https://medium.com/laravel-news/adding-auth-providers-to-laravel-socialite-ca0335929e42
        $socialite = $this->app->make('Laravel\Socialite\Contracts\Factory');

        $socialite->extend(
            'line',
            function ($app) use ($socialite) {
                $config = config('services.line');

                // https://github.com/SocialiteProviders/Line/blob/master/Provider.php
                return $socialite->buildProvider(LineProvider::class, $config); // \SocialiteProviders\Line\Provider::class
            }
        );
    }
}

4. routes/web.php


Route::get('/auth/redirect', function () {
    return Socialite::driver('line')->redirect();
});

Route::get('/auth/callback', function () {
    $user = Socialite::driver('line')->user();

    dd($user);
});

[轉]美国教授在雅典论坛上,为中国说点公道话,让香港学生差点喘不过气来【视频11分9秒处】

https://www.youtube.com/watch?v=aYTsDSoePGI

@tanguemaxime4706 5 個月前 (已編輯)

我出生在中国农村,经历过根植于我记忆中的贫穷;大学之后赴法国学习、生活和工作了15年;后来又在不同的非洲国家工作了多年。我去过30个不同的亚洲、非洲欧洲国家,包括绝大多数东欧国家。我是历史和哲学系出身,我的爱人是哲学本科出身而且硕士和博士都是研究中国政治和法律系统的法国汉学家,她的专业也为了提供了很特别和有价值的视角。我非常赞同这位教授的基本观点:

首先西方一直试图告诉人们这个世界的主要矛盾就是民主和专制的斗争,但是事实远非如此。如果你在非洲最贫困和混乱的国家诸如乍得、中非共和国、马里等地居住过,你才能明白世界的现实究竟是什么。世界的主要矛盾是新自由主义指导下的全球化在世界范围内的不公。这种不公被诸如知识产权、强权利益引导的军事和政治干预等诸多因素决定,在第三世界导致大量的赤贫、污染、动荡。绝大多数国家在全球化分工体系中都不能突破技术壁垒,只能被迫居于工业增值链的最低端。西方霸权会在任何场合提及“民主-独裁”问题,但不会把“每年全世界5岁以下的儿童因饥饿和营养不良死亡3到5百万”这个问题放在人类亟待解决的首位。因为对后者的分析才会揭示这个世界真正的主要矛盾在哪里,会动摇西方主导的全球化秩序。这个世界的基础是财富的创造(生产力)和财富的分配机制(生产关系),很多发达世界的年轻人根本没承受过真正的苦难,被西方政治宣传洗脑的香港年轻人也是这样,就像温室里的花,以为“民主”是一切病症的中心,说出来的都是那种“何不食肉糜”的蠢话。

第二,民主或者不民主本来就是一个非常复杂而且在历史中不断变动的概念。这些东西是“理念”,而不是可以客观观察的“一只猫”或者“一条狗”,其内涵不是不变的,而是不同时代的人们反思他们的时代,从而为其不断注入或者减去内涵。熊彼得之前和熊彼得之后的民主能是一样的吗?希腊的民主和当代的民主是一样的吗?这个教授说的很好,政治形式更值得关注的是细节,有那么多细节需要讨论和关注。要真正讨论民主自由这些东西,你至少要从古希腊、博丹、格劳秀斯、启蒙运动、康德、黑格尔一路读到以赛亚柏林、波普、熊彼得。但是这太难了,对于那些只知道喊口号的懒惰的年轻人而言。

第三,历史传统。我记得以前上学的时候有个法国教授跟我们说:如果西方对于中国的政治史有一些基本了解的话,那么就应该谦虚一些。中国唐代中书、门下、尚书省和皇帝在诏书的颁布和实施就已经非常具有严谨的制衡机制;谏台、监察等制度;中央和地方的关系、军制、劳役和税制等等,都是复杂和让人惊叹的严谨。很多知识匮乏的年轻人就觉得西方那套照搬到什么地方都好用,完全看不到这套制度在绝大多数地方的运行都是失败的。实际上,政治制度之于政治文化就像一个外壳、表象,或者冰山露出水面的部分。没有外力干扰的情况下,政治文化会自然的孕育政治制度。而政治文化是民族千百年来积累下来的、有机态的生长的结果。它是根植于血肉和土地的东西。比如利比亚,就是独特的历史和地理环境造成了这个国家以贝都因人部族为单位形成了一个复杂的制衡、联姻、竞争的权力和利益分配体。这是深层的政治文化,产生于千百年来“人”和“历史”、“地理”、“生产技术”的磨合。西方要在利比亚搞西方民主,那就是个表皮,这个表皮下面继续运作的还是原来的政治文化。西方的制度之所以在西方适合也是因为他们经历了一千多年从中世纪以来特别是200多年以来的各种摸索和磨合建立起来的,很多西方政治的机制都能在中世纪甚至更早的时代找到根源。政治制度的有效运行需要同历史、经济现实以及政治文化相契合。

最后,我想补充一点个人的看法。中国人并非一个封闭的民族,我们从古至今都不排斥学习别的民族。民主、自由、公平、正义、主权在民等等现代政治学的理念我们并不排斥。马克思也是西方的,中国排斥了吗?我们反对的是将它们神话,或者形而上学化。

周虽旧邦其命维新,古老的中华民族之所以能够穿越几千年还能保持其活力,根本就在于能够同时兼顾两个方面,即“接受新鲜的合理事物”同时又能“不失其本体”。

孙中山接受了民族主义,但是能很快适应中国的现实转而宣传“五族共和-中华民族”;毛泽东的革命胜利建立在对于马克思主义的修正使其的中国化,反对“教条主义”,走农村路线,而不是死板地依靠工人阶级;邓小平的改革开放也是将西方的市场经济融入马克思理论。一个民族但凡对于自身的智慧有一点信心,也要会动动脑子,不至于像个脑瘫一样照囫囵吞枣,闭着眼睛搬照抄别人的。

set alpine data out side of the component

https://tonylea.com/setting-alpine-data-outside-of-the-component


<div x-data="{good_id: '', good_name: ''}" id="good_info" class="w-full" @set_good_data="
    good_id = $event.detail.good_id;
    good_name = $event.detail.good_name;
">
    <div x-text="good_id"></div>
    <div x-text="good_name"></div>
</div>

<script>
    document.getElementById('good_info').dispatchEvent(new CustomEvent('set_good_data', { 
	    detail: { 
		    good_id: 1234,
		    good_name: 'Apple',
		} 
    }));
</script>

Laravel Livewire with WinNMP

1. winNMP for Windows

a. create project livewire (Database and user auto create livewire)

b. https://winnmp.wtriple.com/tutorial/laravel

2. update composer


  a. mkdir new directory "t"
  b. cd t
  c. https://getcomposer.org/download/
    c1. php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
	c2. php -r "if (hash_file('sha384', 'composer-setup.php') === '55ce33d7678c5a611085589f1f3ddf8b3c52d662cd01d4ba75c0ee0459970c2200a51f492d557530c71c15d8dba01eae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
	c3. php composer-setup.php
	c4. php -r "unlink('composer-setup.php');"
	c5. mv composer.phar to C:\WinNMP\bin\composer
  d. rmdir t
  
3. cd \WinNMP\WWW\livewire


  a. delete index.php
  b. composer create-project --prefer-dist laravel/laravel .
  c. composer require laravel/ui
  d. composer install
  e. edit .env
    e1. DB_DATABASE=livewire
        DB_USERNAME=livewire
  f. php artisan ui bootstrap --auth
  g. php artisan migrate
  h. developer tools
    composer require doctrine/dbal
	composer require --dev barryvdh/laravel-ide-helper
	composer require --dev beyondcode/laravel-dump-server
	composer require --dev barryvdh/laravel-debugbar
	composer require --dev roave/security-advisories:dev-master
	php artisan vendor:publish --provider="BeyondCode\DumpServer\DumpServerServiceProvider"
	php artisan vendor:publish --provider="Barryvdh\Debugbar\ServiceProvider"
  I. php artisan key:generate
  
4. install node.js for windows


  a. https://nodejs.org/zh-tw/download
  b. npm install
  c. npm run dev
  
5. nginx setting

a. https://laravel.com/docs/10.x/deployment#nginx

b. WinNMP Projects -> project Setup -> Edit Nginx Virtual Server



6. open http://livewire.test


  a. register

b. check db livewire table users have new reocd

7. install livewire


  a. use other cmd 
  b. cd \WinNMP\WWW\livewire
  
c.

  composer dump-autoload
  php artisan package:discover
  php artisan vendor:publish --tag=livewire:config
  composer require livewire/livewire
  
d. https://laravel-livewire.com/docs/2.x/quickstart

d1. edit resources\views\layouts\app.blade.php

put content

d2.

    php artisan make:livewire counter
    
edit resources\views\layouts\app.blade.php

put


    <livewire:counter /> in <main class="py-4"> </main>

d3. edit app\Http\Livewire\Counter.php

    public $count = 0;
 
    public function increment()
    {
        $this->count++;
    }

    public function render()
    {
        return view('livewire.counter');
    }
    
d4. edit resources\views\livewire\counter.blade.php

    <div style="text-align: center">
        <button wire:click="increment">+</button>
        <h1>{{ $count }}</h1>
    </div>
    

Codeigniter 4.2 with Eloquent ORM


composer require "illuminate/database"
composer require "illuminate/events"
Config/Events.php

use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Events\Dispatcher;
use Illuminate\Container\Container;

function boostEloquent() {
  $capsule = new Capsule;

  $capsule->addConnection([
    'driver' => 'mysql',
    'host' => 'localhost',
    'database' => 'database',
    'username' => 'root',
    'password' => 'password',
    'charset' => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix' => '',
  ]);

  // Set the event dispatcher used by Eloquent models... (optional)
  $capsule->setEventDispatcher(new Dispatcher(new Container));

  // Make this Capsule instance available globally via static methods... (optional)
  $capsule->setAsGlobal();

  // Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher())
  $capsule->bootEloquent();
}

Events::on('pre_system', function () {
    boostEloquent();

    if (ENVIRONMENT !== 'testing')
    ...
}

https://www.modb.pro/db/49966

golang gin windows service

Golang Gin Api become Windows Service Use github.com/kardianos/service

package main

import (
    "errors"
    "fmt"
    "io"
    "log"
    "net"
    "net/http"
    "os"
    "path/filepath"
    "strings"
    "time"
    
    "github.com/gin-gonic/gin"
    "github.com/joho/godotenv"
    "github.com/kardianos/service"
)

// Process Windows Service  // github.com/kardianos/service 

var logger service.Logger

type program struct{}


func (p *program) Start(s service.Service) error {
	// Start should not block. Do the actual work async.
	go p.run()
	return nil
}

func (p *program) Stop(s service.Service) error {
	// Stop should not block. Return with a few seconds.
	return nil
}

func ExecPath() string {
	ex, err := os.Executable()
	if err != nil {
		panic(err)
	}

	exPath := filepath.Dir(ex)
	return exPath
}

func main() {
    File, err := os.Create(ExecPath() + "\\gin_service_run.log")
    if err != nil {
        File = os.Stdout
    }
    defer File.Close()

    log.SetOutput(File)

    var s service.Service

    svcConfig := service.Config{
        Name:        "GinAPI",
        DisplayName: "Gin API Service",
        Description: "Gin API Server Converter Windows Service",
    }

    prg := &program{}

    s, err = service.New(prg, &svcConfig)
    if err != nil {
        log.Fatalln(err)
    }

    logger, err = s.Logger(nil)
    if err != nil {
        log.Fatalln(err)
    }

    if len(os.Args) > 1 {
      switch os.Args[1] {
        case "install":
            err := s.Install()
            if err != nil {
                logger.Errorf("Install Service Fail!", err.Error())
                return
            }
            fmt.Printf("Install Service Success!")
        case "uninstall":
            err := s.Uninstall()
            if err != nil {
                logger.Errorf("Uninstall Service Fail!", err.Error())
                return
            }
            fmt.Printf("Uninstall Service Success!")
        case "start":
            err := s.Start()
            if err != nil {
                logger.Errorf("Start Service Fail!", err.Error())
                return
            }
            fmt.Printf("Start Service Success!")
        case "stop":
            err := s.Stop()
            if err != nil {
                logger.Errorf("Stop Service Fail!", err.Error())
                return
            }
            fmt.Printf("Stop Service Success!")
        }
        return
    }
    
    err = s.Run()
        if err != nil {
            logger.Error(err)
        }
    }
    
func (p *program) run() {
    //
    // Create Error logger
    //
    errFile, err := os.OpenFile(ExecPath()+"\\errors.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
    if err != nil {
        log.Fatalf("打開日誌文件失敗:", err)
    }

    Error = log.New(io.MultiWriter(errFile, os.Stderr), "【Error】", log.Ldate|log.Ltime|log.Lshortfile)


    //
    // Get .env
    //
    err = godotenv.Load(ExecPath() + "\\.env")
    if err != nil {
    	msg := "找不到 .env 檔案"
    	logger.Errorf(msg, err)
    	Error.Printf(msg, err)
    }

    web_port := os.Getenv("WEB_PORT")
    
    
    //
    // Start Gin
    //
    router := gin.Default()
    
    corsConfig := cors.DefaultConfig()
	corsConfig.AllowAllOrigins = true
	router.Use(cors.New(corsConfig))
    
    router.GET("/", func(c *gin.Context) {
      c.JSON(http.StatusOK, gin.H{"status": "Gin Api Success!"})
	})
    
    log.Fatal(http.ListenAndServe(":"+web_port, router))
    
}
    
1. run server.exe can run Gin Api Server right now.

2. run server install, server uninstall, server start, server stop.

2.1 【Install and Start】run server install Then server start

2.2 【Stop and uninstall】run server stop Then server uninstall

3. log file use absolute path. ExecPath() can get absolute path.

4. .env must use absolute path. Try to use


  svcConfig.EnvVars = map[string]string{
    "WEB_PORT": web port
  }
see register Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\GinAPI have EnvVars Data.

But err := godotenv.Load() can't get anything, just No Error. So must use absolute path.

5. log have two method.

5.1 File, err := os.Create(ExecPath() + "\\gin_service_run.log")

5.2 【logger.Errorf】 This Error Msg showed at Windows Servce and have Error tag.

OK~ Just try. Hope this blog can help.