Sunday, October 5, 2025

使用 Multipass(官方轻量虚拟 Ubuntu)

 

轻量方案:使用 Multipass(官方轻量虚拟 Ubuntu)

如果你只是想运行命令行版 Ubuntu(不需要桌面),可以用 Canonical 官方工具 Multipass

安装:

brew install --cask multipass


创建 Ubuntu 虚拟机:

multipass launch --name ubuntu --mem 4G --disk 20G

 

进入虚拟机:

multipass shell ubuntu


删除虚拟机:
multipass delete ubuntu && multipass purge


👉 它运行的是 Ubuntu LTS,启动秒级,非常轻量。

Wednesday, November 13, 2024

docker host name/address

if don't wanna use the ip address

docker get IP address command:

docker inspect -f '{{range. NetworkSettings. Networks}}{{. IPAddress}}{{end}}' container_name_or_id

use host.docker.internal

 


Monday, November 11, 2024

.Net Core connect to postgresql

 1. appsettings.json

  "ConnectionStrings": {
    "DefaultConnection": ""
  }

2. Program.cs
builder.Services.AddDbContext<ApiDbCopntext>(options => options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));

3. Models/ folder
add Table Class
namespace ReactAPIApp.Server.Models
{
    public class Driver
    {
        public int Id { get; set; }
        public string Name { get; set; } = null!;
        public int DriverNumber { get; set; }
    }
}

4. Add Context for example add Data folder

Data/ApiDbContext.cs

using Microsoft.EntityFrameworkCore;

using ReactAPIApp.Server.Models;

namespace ReactAPIApp.Server.Data
{
    public class ApiDbContext : DbContext
    {
        public ApiDbContext(DbContextOptions<ApiDbContext> options) : base(options){}
        public DbSet<Driver> Drivers { get; set; }
    }
}

5. run migrate command
if from package manager console
PM> Add-Migration initial

if from package manager console

Friday, November 8, 2024

js function 严格模式 use strict

 禁止function 内部的this指向winodows

class 中的function,都已默认开启了严格模式



Tuesday, October 29, 2024

.Net seed migration

dbcontext command lines:

  1. Using the Package Manager Console in Visual Studio:

Add-Migration initial 

remove-database

update-database

  1. Using the .NET Command Line Interface (.NET CLI):
dotnet ef migrations add Initial
dotnet ef database update

Saturday, July 20, 2024

Multi column searching

 scopeSearch

collect(explode(' ', $terms))->filter()->each(function ($tiem)use ($query) {

    $term = '%' . $term . '%';

    $query->where(function($query) use ($term) {

        $query->where('first_name', 'like', $term)

            ->orWhere('last_name', 'like', $term)

            ->orWhereHas('company', function($query) use ($term) {

                $query->where('name', like', $term);

            });

    });

});

to SQL it is



SELECT * FROM 'users'

WHERE 'first_name' LIKE '%bill%'

    OR 'last_name' LIKE '%bill%'

    OR EXISTS (

        SELECT * FROM 'companies'

        WHERE 'users'.'company_id' = 'companies'.'id'

    )

Optimizing Circular Relationships

 model/Comment.php

public function isAuthor() {// n + 1 issue

     return $this-->feature->comments->first()->user_id === $this->user_id;

}

Improves

in controllor

$feature->load('comments.user', 'comments.feature.comments');


Improves more

$feature->load('comments.user');

$feature->comments->each->setRelation('feature', $feature);