Sunday, April 13, 2025

Link libraries script for MSX-2 Basic code

PowerShell Script: linklib.ps1

Script Requirements

  • The script must be named linklib.ps1.
  • Accept named parameters:
    • -FilePath: Full path to a .bas file (required)
    • -LibFolder: Optional path to a folder containing library files
    • -TargetFile: Optional output file path; if not provided, overwrite the original file
  • Process the input file line by line.
  • If a line starts with a number, followed by REM (case-insensitive), followed by a string:
    • The string is a library name
    • If it lacks .bas suffix, append it
    • Try to resolve it as a file path
    • If not found, try LibFolder + filename if LibFolder is provided
    • If still not found, terminate with an error
    • If found, replace the original line with contents of the library file
  • Use the actual script name in all output messages (using $MyInvocation.MyCommand.Name)

Script Code

<#
.SYNOPSIS
    Replaces library include lines in a .bas file with actual file content.

.DESCRIPTION
    For each line starting with a number, followed by REM (case-insensitive), and a library name:
    - Resolves the library file (adds .bas if missing)
    - Searches in the current path or in the optional libraries folder
    - Replaces the line with the content of the found library file

.PARAMETER FilePath
    The full path to the .bas file to process.

.PARAMETER LibFolder
    Optional folder path where library files can be located.

.PARAMETER TargetFile
    Optional path to write the result. If not provided, overwrites the source file.

.EXAMPLE
    .linklib.ps1 -FilePath "C:codemain.bas" -LibFolder "C:codelibs" -TargetFile "C:codelinked.bas"
#>

param (
    [Parameter(Mandatory = $true)]
    [string]$FilePath,

    [Parameter(Mandatory = $false)]
    [string]$LibFolder,

    [Parameter(Mandatory = $false)]
    [string]$TargetFile
)

$scriptName = $MyInvocation.MyCommand.Name

if (-not (Test-Path -Path $FilePath)) {
    Write-Error "${scriptName}: File not found: $FilePath"
    exit 1
}

if (-not $TargetFile) {
    $TargetFile = $FilePath
}

try {
    $lines = Get-Content -LiteralPath $FilePath
    $output = @()

    foreach ($line in $lines) {
        if ($line -match '^s*(d+)s+REMs+(.*)$') {
            $lineNumber = $matches[1]
            $libName = $matches[2].Trim()

            if (-not $libName.ToLower().EndsWith(".bas")) {
                $libName += ".bas"
            }

            $resolvedPath = $libName

            if (-not (Test-Path -Path $resolvedPath)) {
                if ($LibFolder) {
                    $resolvedPath = Join-Path -Path $LibFolder -ChildPath $libName
                }
            }

            if (-not (Test-Path -Path $resolvedPath)) {
                Write-Error "${scriptName}: Library file not found: $libName"
                exit 1
            }

            Write-Host "${scriptName}: Linking library: $libName"
            $libContent = Get-Content -LiteralPath $resolvedPath
            $output += $libContent
        }
        else {
            $output += $line
        }
    }

    Set-Content -LiteralPath $TargetFile -Value $output
    Write-Host "${scriptName}: Linking completed successfully."
    Write-Host "${scriptName}: Output written to: $TargetFile"
}
catch {
    Write-Error "${scriptName}: Error during processing - $_"
    exit 1
}

Saturday, April 12, 2025

Passover 2025

Passover and Cosmonautics Day celebration

MSX-2 SCREEN Concept

# MSX-2 SCREEN Concept

The **MSX-2 SCREEN concept** revolves around *multiple screen modes*, each tailored for different use cases like text, tile-based graphics, bitmapped images, and sprites. MSX-2 greatly expanded upon the original MSX video capabilities by leveraging the **Yamaha V9938** video display processor (VDP), allowing for higher resolution, more colors, and multiple VRAM pages.

---

## πŸŽ¨ Overview of SCREEN Modes in MSX-2

| Mode       | Type     | Resolution     | Colors           | Description                                  |
|------------|----------|----------------|------------------|----------------------------------------------|
| SCREEN 0   | Text     | 40Γ—24 (text)    | 2 colors         | Default text screen (40 columns)             |
| SCREEN 1   | Text     | 32Γ—24 (text)    | 15 colors (limited) | Colorful, 32-column text mode             |
| SCREEN 2   | Tile     | 256Γ—192         | 16 (per 8Γ—1 area) | Tile-based mode for games                    |
| SCREEN 4   | Tile     | 256Γ—212         | 16 (fixed palette) | MSX2 version of SCREEN 2                     |
| SCREEN 5   | Bitmap   | 256Γ—212         | 16 (from 512)     | Direct pixel graphics                         |
| SCREEN 6   | Bitmap   | 512Γ—212         | 4 (from 512)      | High-res graphics mode                        |
| SCREEN 7   | Bitmap   | 512Γ—212         | 16 (from 512)     | High-res, 16-color mode                       |
| SCREEN 8   | Bitmap   | 256Γ—212         | 256 (fixed)       | 8-bit color mode (no sprite support)         |
| SCREEN 10  | YJK      | 256Γ—212         | ~12,000 (YJK)     | Photo-realistic color encoding               |
| SCREEN 11  | YJK+PAL  | 256Γ—212         | ~12,000 + 16      | YJK with palette override                    |
| SCREEN 12  | YJK      | 512Γ—212         | ~12,000           | Hi-res YJK mode (MSX2+)                      |

---

## πŸ“¦ Concepts Behind the SCREEN System

### 1. Tile Modes vs Bitmap Modes
- **Tile-based (SCREEN 1–4):**
  - Use **character patterns** and **name tables**.
  - Efficient and fastβ€”perfect for retro-style games.

- **Bitmap modes (SCREEN 5–8, 10–12):**
  - Allow **per-pixel** control.
  - Best for drawing, images, or artistic apps.

---

### 2. Color System
- MSX-1: fixed 16-color palette.
- MSX-2:
  - **512-color palette**
  - Custom palette via `COLOR=` or `VDP` register.
  - Bitmap screens can use these with up to 16 or 256 colors.
  - YJK modes allow 12,000+ virtual colors.

---

### 3. Pages
- Most modes support **multiple VRAM pages**.
- You can:
  - Draw on one page.
  - Show another page.
  - Swap for **smooth animation** (double-buffering).

---

### 4. Sprites
- Used in SCREEN 1–7.
- **32 hardware sprites**, up to 16 colors.
- Limit: **4 sprites per scanline**.

---

### 5. VRAM Layout
- Use `VPOKE`, `VPEEK`, and `COPY` to directly manage VRAM:
  - Tiles, bitmaps, sprite patterns, palettes, etc.

---

## πŸ§ͺ Example: Draw a Pixel in SCREEN 5

```basic
SCREEN 5
PSET (100, 100), 15  ' White pixel

Build labels resolving script for MSX Basic with chatGpt

<#
.SYNOPSIS
    Processes a text file by adding line numbers and replacing label-based GOTO/GOSUB commands.

.DESCRIPTION
    - Each line is numbered sequentially starting from a given Start, with an increment of Step.
    - Labels (lines starting with ':') are replaced with a numbered line containing "REM :label".
    - GOSUB and GOTO commands referencing a label (e.g., "gosub myLabel") are replaced with the numeric line.
    - Case-insensitive matching for labels and commands.

.PARAMETER FilePath
    Path to the file to process.

.PARAMETER Start
    Starting number for line numbering (default: 10).

.PARAMETER Step
    Increment step for line numbering (default: 10).

.EXAMPLE
    .RenumberWithLabels.ps1 -FilePath "C:codescript.bas" -Start 10 -Step 10
#>

param(
    [string]$FilePath,
    [int]$Start = 10,
    [int]$Step = 10
)

if (-not (Test-Path $FilePath)) {
    Write-Error "File not found: $FilePath"
    exit 1
}

$lines = Get-Content $FilePath
$output = @()
$labelMap = @{}
$lineNumber = $Start

# First pass: assign line numbers and store label mappings
foreach ($line in $lines) {
    $trimmed = $line.Trim()
    if ($trimmed -match '^:([a-zA-Z_][w]*)$') {
        $label = $matches[1]
        $labelMap[$label.ToLower()] = $lineNumber
        $output += "$lineNumber REM :$label"
    }
    else {
        $output += "$lineNumber $line"
    }
    $lineNumber += $Step
}

# Second pass: replace GOSUB/GOTO label references
for ($i = 0; $i -lt $output.Count; $i++) {
    $line = $output[$i]
    foreach ($label in $labelMap.Keys) {
        $line = $line -replace "(?i)bgosubs+:?$labelb", "gosub $($labelMap[$label])"
        $line = $line -replace "(?i)bgotos+:?$labelb", "GOTO $($labelMap[$label])"
    }
    $output[$i] = $line
}

# Save to file or print
$output | Set-Content "$FilePath.processed"
Write-Host "Processed file saved as: $FilePath.processed"

Friday, April 11, 2025

Create MSX-2 deploy script with AI. (Draft)

MSX-2 Disk Deployment Script Requirements

This document outlines the complete functionality for a PowerShell script that builds a bootable MSX-2 .dsk image from a BASIC project.

Input Parameters

  • MainBasPath (Required, String): Full path to the main .BAS file.
  • ProjectName (Optional, String): Optional project name. Defaults to the base name of the .BAS file.

Folder and File Structure

Work Folder

  • Location: Sibling to the folder containing MainBasPath.
  • Name Format: ProjectName_Hash (the hash is 6 characters from a GUID).
  • Contents: Renumbered .BAS files and AUTOEXEC.BAS.

Disk Image

  • Name: ProjectName.dsk.
  • Location: Same parent folder as the folder containing MainBasPath.
  • Base: Created by copying the "New 720KB Boot Disk.dsk" template.
  • Overwrite: If the file already exists, it is overwritten.

Steps

  1. Resolve and Print All Paths
    • Compute all paths (folders, tools, and output) at the top of the script and print them.
  2. Create Work Folder
    • Create a work folder as a sibling to the project folder using the format: ProjectName_Hash.
  3. Create AUTOEXEC.BAS
    • Create AUTOEXEC.BAS in the work folder.
    • The file content should be: RUN "MainFile.BAS" (using the actual main file name), written in ASCII.
  4. Copy and Renumber .BAS Files
    1. Copy all .BAS files from the folder containing MainBasPath to the work folder.
    2. Renumber each .BAS file by calling the external renumbering script:
      D:WorkspaceMSXtoolsrenumber.ps1 -FilePath -Step 10 -Start 10
  5. Create and Populate Disk Image
    1. Copy the template image "New 720KB Boot Disk.dsk" to the destination DiskImage path, overwriting any existing file.
    2. Add each file from the work folder to the disk image using the command:
      dsktool.exe A "C:pathtoimage.dsk" "C:pathtofile.ext"
    3. If adding a file fails, print the exact command used for troubleshooting.
  6. Cleanup or Error Handling
    1. If all files are added successfully, delete the work folder and print "Deployment Complete".
    2. If any file fails to add, do not delete the work folder and print "Deployment Failed" along with the error information and the failed command.

Additional Notes

  • All paths are fully resolved and printed before any processing begins.
  • Original file casing is preserved in the disk image.
  • The final disk image will overwrite any existing file with the same name.
  • Failures in file addition are clearly reported along with the command used.

Monday, February 17, 2025

Amazon Rekognition

## 3. How to Implement Amazon Rekognition for Your Web App

### Step 1: Set Up Amazon Rekognition on AWS
1. Sign up for AWS.
2. Create an IAM Role with Rekognition and S3 permissions.
3. Create a Face Collection (used for storing and matching faces).
4. Obtain API Credentials (Access Key & Secret Key).

Saturday, February 15, 2025

БританскиС ΡƒΡ‡Ρ‘Π½Ρ‹Π΅ Π΄ΠΎΠΊΠ°Π·Π°Π»ΠΈ

dalle-2025-02-15-114452-a-humorous-digital-illustration-comparing-dumplings-of-different-sizes-with-clear-mathematical-formulas-overlayed-including-integral-signs-and-mathem.webp
УмСньшСниС Π»ΠΈΠ½Π΅ΠΉΠ½ΠΎΠ³ΠΎ Ρ€Π°Π·ΠΌΠ΅Ρ€Π° пСльмСня Π² Π΄Π²Π° Ρ€Π°Π·Π° ΠΏΡ€ΠΈΠ²ΠΎΠ΄ΠΈΡ‚ ΠΊ ΡΠΎΠΊΡ€Π°Ρ‰Π΅Π½ΠΈΡŽ ΠΏΠ»ΠΎΡ‰Π°Π΄ΠΈ тСста Π² Ρ‡Π΅Ρ‚Ρ‹Ρ€Π΅ Ρ€Π°Π·Π°, Π° объСма Π½Π°Ρ‡ΠΈΠ½ΠΊΠΈ – Π² восСмь Ρ€Π°Π·. Π­Ρ‚ΠΎ ΡΠΎΠΎΡ‚Π½ΠΎΡˆΠ΅Π½ΠΈΠ΅ ΠΎΠ±ΡŠΡΡΠ½ΡΠ΅Ρ‚ ΡΠΊΠΎΠ½ΠΎΠΌΠΈΡ‡Π΅ΡΠΊΡƒΡŽ Π²Ρ‹Π³ΠΎΠ΄Ρƒ для ΠΏΡ€ΠΎΠΈΠ·Π²ΠΎΠ΄ΠΈΡ‚Π΅Π»Π΅ΠΉ, ΡΠ²ΡΠ·Π°Π½Π½ΡƒΡŽ с ΡƒΠΌΠ΅Π½ΡŒΡˆΠ΅Π½ΠΈΠ΅ΠΌ Π΄ΠΎΠ»ΠΈ Π½Π°Ρ‡ΠΈΠ½ΠΊΠΈ ΠΏΡ€ΠΈ сохранСнии ΠΎΠ±Ρ‰Π΅Π³ΠΎ количСства ΠΈΠ·Π΄Π΅Π»ΠΈΠΉ.

Π”Π°Π½Π½Ρ‹ΠΉ эффСкт подтвСрТдаСтся матСматичСским ΡΠΎΠΎΡ‚Π½ΠΎΡˆΠ΅Π½ΠΈΠ΅ΠΌ: Π΄Π²ΠΎΠΉΠ½ΠΎΠΉ ΠΊΡ€ΠΈΠ²ΠΎΠ»ΠΈΠ½Π΅ΠΉΠ½Ρ‹ΠΉ ΠΈΠ½Ρ‚Π΅Π³Ρ€Π°Π» ΠΏΠΎ повСрхности эквивалСнтСн Ρ‚Ρ€ΠΎΠΉΠ½ΠΎΠΌΡƒ ΠΈΠ½Ρ‚Π΅Π³Ρ€Π°Π»Ρƒ ΠΏΠΎ ΠΎΠ±ΡŠΠ΅ΠΌΡƒ, ΠΎΠ³Ρ€Π°Π½ΠΈΡ‡Π΅Π½Π½ΠΎΠΌΡƒ Π΄Π°Π½Π½ΠΎΠΉ ΠΏΠΎΠ²Π΅Ρ€Ρ…Π½ΠΎΡΡ‚ΡŒΡŽ. Π’ Ρ€Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚Π΅ ΡƒΠΌΠ΅Π½ΡŒΡˆΠ΅Π½ΠΈΠ΅ Ρ€Π°Π·ΠΌΠ΅Ρ€Π° пСльмСнСй Π²Π΅Π΄Π΅Ρ‚ ΠΊ Π·Π½Π°Ρ‡ΠΈΡ‚Π΅Π»ΡŒΠ½ΠΎΠΌΡƒ ΡΠΎΠΊΡ€Π°Ρ‰Π΅Π½ΠΈΡŽ объСма Π½Π°Ρ‡ΠΈΠ½ΠΊΠΈ, Ρ‡Ρ‚ΠΎ ΠΌΠΎΠΆΠ΅Ρ‚ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒΡΡ ΠΊΠ°ΠΊ экономичСская стратСгия.

Π’ ΠΏΡ€ΠΈΠΊΠ»Π°Π΄Π½ΠΎΠΌ аспСктС Π΄Π°Π½Π½ΠΎΠ΅ явлСниС ΠΌΠΎΠΆΠ΅Ρ‚ ΠΈΠ½Ρ‚Π΅Ρ€ΠΏΡ€Π΅Ρ‚ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒΡΡ ΠΊΠ°ΠΊ стратСгия сниТСния сСбСстоимости производства Π·Π° счСт ΡƒΠΌΠ΅Π½ΡŒΡˆΠ΅Π½ΠΈΡ содСрТания Π½Π°Ρ‡ΠΈΠ½ΠΊΠΈ ΠΏΡ€ΠΈ сохранСнии ΠΎΠ±Ρ‰Π΅Π³ΠΎ количСства ΠΈΠ·Π΄Π΅Π»ΠΈΠΉ.

Monday, January 6, 2025

Π‘Ρ€Π°Π²Π½Π΅Π½ΠΈΠ΅ ΠΏΠΎΠΊΠΎΠ»Π΅Π½ΠΈΠΉ X ΠΈ МиллСниалов

Π‘Ρ€Π°Π²Π½Π΅Π½ΠΈΠ΅ ΠΏΠΎΠΊΠΎΠ»Π΅Π½ΠΈΠΉ X ΠΈ ΠΌΠΈΠ»Π»Π΅Π½ΠΈΠ°Π»ΠΎΠ²

Π₯арактСристика ПоколСниС X ПоколСниС ΠΌΠΈΠ»Π»Π΅Π½ΠΈΠ°Π»ΠΎΠ² (Y)
Π“ΠΎΠ΄Ρ‹ роТдСния 1965–1983 1984–1999
ΠšΠ»ΡŽΡ‡Π΅Π²Ρ‹Π΅ события эпохи ΠŸΠ΅Ρ€ΠΈΠΎΠ΄ пСрСстройки, экономичСская Π½Π΅ΡΡ‚Π°Π±ΠΈΠ»ΡŒΠ½ΠΎΡΡ‚ΡŒ, ΠΏΠ΅Ρ€Π΅Ρ…ΠΎΠ΄ ΠΊ Ρ€Ρ‹Π½ΠΎΡ‡Π½ΠΎΠΉ экономикС Распад Π‘Π‘Π‘Π , Ρ€Π°Π·Π²ΠΈΡ‚ΠΈΠ΅ ΠΈΠ½Ρ‚Π΅Ρ€Π½Π΅Ρ‚Π°, глобализация
ΠžΡ‚Π½ΠΎΡˆΠ΅Π½ΠΈΠ΅ ΠΊ тСхнологиям Осваивали Ρ‚Π΅Ρ…Π½ΠΎΠ»ΠΎΠ³ΠΈΠΈ Π² Π·Ρ€Π΅Π»ΠΎΠΌ возрастС; ΠΏΡ€Π΅Π΄ΠΏΠΎΡ‡ΠΈΡ‚Π°ΡŽΡ‚ Ρ‚Ρ€Π°Π΄ΠΈΡ†ΠΈΠΎΠ½Π½Ρ‹Π΅ Ρ„ΠΎΡ€ΠΌΡ‹ общСния ΠŸΠ΅Ρ€Π²ΠΎΠ΅ Ρ†ΠΈΡ„Ρ€ΠΎΠ²ΠΎΠ΅ ΠΏΠΎΠΊΠΎΠ»Π΅Π½ΠΈΠ΅; Π°ΠΊΡ‚ΠΈΠ²Π½ΠΎ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡŽΡ‚ ΠΈΠ½Ρ‚Π΅Ρ€Π½Π΅Ρ‚ ΠΈ ΡΠΎΡ†ΠΈΠ°Π»ΡŒΠ½Ρ‹Π΅ сСти
ЦСнности Π‘Π°ΠΌΠΎΡΡ‚ΠΎΡΡ‚Π΅Π»ΡŒΠ½ΠΎΡΡ‚ΡŒ, ΠΏΡ€Π°Π³ΠΌΠ°Ρ‚ΠΈΠ·ΠΌ, стрСмлСниС ΠΊ ΡΡ‚Π°Π±ΠΈΠ»ΡŒΠ½ΠΎΡΡ‚ΠΈ ΠΈ ΠΊΠ°Ρ€ΡŒΠ΅Ρ€Π½ΠΎΠΌΡƒ росту БаморСализация, баланс ΠΌΠ΅ΠΆΠ΄Ρƒ Ρ€Π°Π±ΠΎΡ‚ΠΎΠΉ ΠΈ Π»ΠΈΡ‡Π½ΠΎΠΉ Тизнью, ΡΠΎΡ†ΠΈΠ°Π»ΡŒΠ½Π°Ρ ΠΎΡ‚Π²Π΅Ρ‚ΡΡ‚Π²Π΅Π½Π½ΠΎΡΡ‚ΡŒ
ΠžΠ±Ρ€Π°Π·ΠΎΠ²Π°Π½ΠΈΠ΅ ΠΈ ΠΊΠ°Ρ€ΡŒΠ΅Ρ€Π° Π‘Ρ‚Ρ€Π΅ΠΌΠ»Π΅Π½ΠΈΠ΅ ΠΊ ΠΏΠΎΠ»ΡƒΡ‡Π΅Π½ΠΈΡŽ Π²Ρ‹ΡΡˆΠ΅Π³ΠΎ образования; Π»ΠΎΡΠ»ΡŒΠ½ΠΎΡΡ‚ΡŒ ΠΊ Ρ€Π°Π±ΠΎΡ‚ΠΎΠ΄Π°Ρ‚Π΅Π»ΡŽ; цСнят ΡΡ‚Π°Π±ΠΈΠ»ΡŒΠ½ΠΎΡΡ‚ΡŒ ΠžΡ€ΠΈΠ΅Π½Ρ‚ΠΈΡ€ΠΎΠ²Π°Π½Ρ‹ Π½Π° постоянноС ΠΎΠ±ΡƒΡ‡Π΅Π½ΠΈΠ΅ ΠΈ Ρ€Π°Π·Π²ΠΈΡ‚ΠΈΠ΅; склонны ΠΌΠ΅Π½ΡΡ‚ΡŒ Ρ€Π°Π±ΠΎΡ‚Ρƒ Π² поисках Π»ΡƒΡ‡ΡˆΠΈΡ… возмоТностСй
ЀинансовыС ΠΏΡ€ΠΈΠ²Ρ‹Ρ‡ΠΊΠΈ Π‘ΠΊΠ»ΠΎΠ½Π½Ρ‹ ΠΊ сбСрСТСниям ΠΈ инвСстициям Π² Π½Π΅Π΄Π²ΠΈΠΆΠΈΠΌΠΎΡΡ‚ΡŒ; остороТны Π² расходах ΠžΡ€ΠΈΠ΅Π½Ρ‚ΠΈΡ€ΠΎΠ²Π°Π½Ρ‹ Π½Π° ΠΎΠΏΡ‹Ρ‚ ΠΈ впСчатлСния; Π³ΠΎΡ‚ΠΎΠ²Ρ‹ Ρ‚Ρ€Π°Ρ‚ΠΈΡ‚ΡŒ Π½Π° ΠΏΡƒΡ‚Π΅ΡˆΠ΅ΡΡ‚Π²ΠΈΡ ΠΈ Ρ‚Π΅Ρ…Π½ΠΎΠ»ΠΎΠ³ΠΈΠΈ
Π‘Π΅ΠΌΠ΅ΠΉΠ½Ρ‹Π΅ цСнности ЦСнят сСмСйныС Ρ‚Ρ€Π°Π΄ΠΈΡ†ΠΈΠΈ; стрСмятся ΠΎΠ±Π΅ΡΠΏΠ΅Ρ‡ΠΈΡ‚ΡŒ сСмью ΠΌΠ°Ρ‚Π΅Ρ€ΠΈΠ°Π»ΡŒΠ½ΠΎ ΠžΡ‚ΠΊΠ»Π°Π΄Ρ‹Π²Π°ΡŽΡ‚ созданиС сСмьи; ΠΎΡ€ΠΈΠ΅Π½Ρ‚ΠΈΡ€ΠΎΠ²Π°Π½Ρ‹ Π½Π° личностноС Ρ€Π°Π·Π²ΠΈΡ‚ΠΈΠ΅ ΠΈ ΠΊΠ°Ρ€ΡŒΠ΅Ρ€Ρƒ
ΠžΡ‚Π½ΠΎΡˆΠ΅Π½ΠΈΠ΅ ΠΊ Ρ€Π°Π±ΠΎΡ‚Π΅ Π“ΠΎΡ‚ΠΎΠ²Ρ‹ Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ свСрхурочно для достиТСния Ρ†Π΅Π»Π΅ΠΉ; цСнят ΠΈΠ΅Ρ€Π°Ρ€Ρ…ΠΈΡŽ ΠΈ Ρ‡Π΅Ρ‚ΠΊΠΈΠ΅ инструкции ΠŸΡ€Π΅Π΄ΠΏΠΎΡ‡ΠΈΡ‚Π°ΡŽΡ‚ Π³ΠΈΠ±ΠΊΠΈΠΉ Π³Ρ€Π°Ρ„ΠΈΠΊ ΠΈ творчСскиС Π·Π°Π΄Π°Ρ‡ΠΈ; ΠΈΡ‰ΡƒΡ‚ смысл Π² Ρ€Π°Π±ΠΎΡ‚Π΅ ΠΈ возмоТности для саморСализации
Π‘ΠΎΡ†ΠΈΠ°Π»ΡŒΠ½Π°Ρ Π°ΠΊΡ‚ΠΈΠ²Π½ΠΎΡΡ‚ΡŒ МСнСС Π²ΠΎΠ²Π»Π΅Ρ‡Π΅Π½Ρ‹ Π² общСствСнныС двиТСния; скСптичСски относятся ΠΊ ΠΏΠΎΠ»ΠΈΡ‚ΠΈΠΊΠ΅ Активно ΡƒΡ‡Π°ΡΡ‚Π²ΡƒΡŽΡ‚ Π² ΡΠΎΡ†ΠΈΠ°Π»ΡŒΠ½Ρ‹Ρ… ΠΈ экологичСских ΠΈΠ½ΠΈΡ†ΠΈΠ°Ρ‚ΠΈΠ²Π°Ρ…; ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΈΠ²Π°ΡŽΡ‚ Ρ€Π°Π·Π½ΠΎΠΎΠ±Ρ€Π°Π·ΠΈΠ΅ ΠΈ ΠΈΠ½ΠΊΠ»ΡŽΠ·ΠΈΠ²Π½ΠΎΡΡ‚ΡŒ
ΠœΠΎΡ‚ΠΈΠ²Π°Ρ†ΠΈΡ Ѐинансовая ΡΡ‚Π°Π±ΠΈΠ»ΡŒΠ½ΠΎΡΡ‚ΡŒ, ΠΊΠ°Ρ€ΡŒΠ΅Ρ€Π½Ρ‹ΠΉ рост, ΠΏΡ€ΠΈΠ·Π½Π°Π½ΠΈΠ΅ ВозмоТности для развития, смысл Ρ€Π°Π±ΠΎΡ‚Ρ‹, Π²ΠΊΠ»Π°Π΄ Π² общСство

Tuesday, August 20, 2024

PHP: Why fgetcsv() and not file()

When handling CSV files in PHP, you have multiple options for reading the data, with fgetcsv() and the file() function being two common approaches. Each method has its advantages and disadvantages, depending on what you need to do with the CSV data. Let’s compare these two methods:

1. Using fgetcsv()

Advantages:

  • Built for CSVs: fgetcsv() is specifically designed to read CSV files. It automatically handles CSV formatting, including encapsulated fields with commas, quotes, and escaped characters.
  • Memory Efficiency: It reads one line at a time, which is memory efficient, especially useful for large files.
  • Convenient Parsing: Automatically parses the line into an array based on the delimiter, which is very handy for direct data manipulation.

Disadvantages:

  • Limited to CSV Format: Only useful for CSV files and cannot be easily used for other file formats.
  • Less Flexible: You’re mostly stuck with the structure of how fgetcsv() parses each line (though you can specify custom delimiters, escape characters, and enclosures).

Example Usage of fgetcsv():

$handle = fopen('path/to/file.csv', 'r');
while (($data = fgetcsv($handle, 1000, ",")) !== false) {
    print_r($data);
}
fclose($handle);

2. Using file()

Advantages:

  • Simplicity: file() reads the entire file into an array, where each line is an element of the array, simplifying the process of file reading.
  • Flexible Post-Processing: Useful if you need to process each line as a whole string or perform non-CSV specific parsing.
  • Convenient for Smaller Files: Quickly reads smaller files into memory, making it easier to manipulate content that isn’t strictly structured as CSV.

Disadvantages:

  • Memory Usage: Since it reads the entire file into memory at once, it can be inefficient or impractical for very large files.
  • Manual Parsing Required: Does not handle CSV complexity such as commas in fields, quoted fields, etc., without additional parsing logic.

Example Usage of file():

$lines = file('path/to/file.csv');
foreach ($lines as $line) {
    $data = str_getcsv($line); // Convert line to array similar to fgetcsv
    print_r($data);
}

Decision Factors:

  • File Size: Use fgetcsv() for large files to keep memory usage down. Use file() for smaller files where quick access to all lines is more convenient.
  • Complexity of CSV: If the CSV data includes lots of special cases (like fields containing commas, quotes, or newlines), fgetcsv() handles these natively. If your data is simpler or requires custom processing, file() might be sufficient with manual parsing.
  • Processing Needs: If you need to process or analyze each line of text beyond simple CSV parsing (like complex checks or multiple parsing passes), file() can be advantageous.

Friday, April 12, 2024

12 апрСля 2024, дСнь космонавтики ΠΈ Π±ΠΎΠ»ΡŒΡˆΠΈΡ… Π½Π°Π΄Π΅ΠΆΠ΄

Для Ρ‚Π΅Ρ… ΠΊΡ‚ΠΎ Ρ‡ΠΈΡ‚Π°Π΅Ρ‚ этот пост Π½Π΅ 12 апрСля 2024 контСкст: Π² Ρ€Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚Π΅ извСстных событий 7 октября 2023Π³, послС 6 мСсяцСв Π²ΠΎΠΉΠ½Ρ‹, Π˜Π·Ρ€Π°ΠΈΠ»ΡŒ Ρ€Π΅ΡˆΠΈΠ» Ρ€Π°Π·Π±ΠΎΠΌΠ±ΠΈΡ‚ΡŒ ΠΏΠΎΡΠΎΠ»ΡŒΡΡ‚Π²ΠΎ Π˜Ρ€Π°Π½Π° Π½Π° Ρ‚Π΅Ρ€Ρ€ΠΈΡ‚ΠΎΡ€ΠΈΠΈ Π‘ΠΈΡ€ΠΈΠΈ. Π’ Ρ€Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚Π΅ ΡƒΠΆΠ΅ нСдСлю вся страна сидит Π½Π° ΠΈΠ·ΠΌΠ΅Π½Π΅ ΠΈ ΠΆΠ΄Ρ‘Ρ‚ ΠΊΠΎΠ³Π΄Π° Π˜Ρ€Π°Π½ Π΄ΠΎΠ»Π±Π°Π½Ρ‘Ρ‚ Π² ΠΎΡ‚Π²Π΅Ρ‚.
Π˜Π·Ρ€Π°ΠΈΠ»ΡŒΡΠΊΠ°Ρ прСсса, Π° Ρ‚ΠΎΡ‡Π½Π΅Π΅ ΠΏΠΎΡ€Ρ‚Π°Π» УайНСт (Π±Ρ‹Π²ΡˆΠΈΠΉ Π―Π΄ΠΈΠΉΠΎΡ‚ Ахаронот), ΠΏΡ‹Ρ‚Π°ΡΡΡŒ ΡƒΡΠΏΠΎΠΊΠΎΠΈΡ‚ΡŒ насСлСниС, запостил ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΡƒ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰Π΅Π³ΠΎ содСрТания: НСбо Π·Π°ΠΊΡ€Ρ‹Ρ‚ΠΎ! Π§Π΅Ρ‚Ρ‹Ρ€Π΅ уровня Π·Π°Ρ‰ΠΈΡ‚Ρ‹!
437865525_10161078265945053_4135937047973701258_n.jpgНСбо Π·Π°ΠΊΡ€Ρ‹Ρ‚ΠΎ! Π§Π΅Ρ‚Ρ‹Ρ€Π΅ уровня Π·Π°Ρ‰ΠΈΡ‚Ρ‹![/img]

Π’ связи с этим, рассказ…

Как Ρ‚ΠΎ Ρ€Π°Π· наш “ΠΏΠΎΠ»ΠΊ” ΠŸΠ’Πž Ρ€Π΅ΡˆΠΈΠ» провСсти учСния. Π‘ΠΎΠ±Ρ€Π°Π»ΠΈ всСх Π±ΠΎΠ»Π΅Π·Π½Ρ‹Ρ…, ΠΎΡ‚ΠΎΠ±Ρ€Π°Π»ΠΈ Ρƒ Π½ΠΈΡ… “освобоТдСния ΠΎΡ‚ Ρ„ΠΈΠ·ΠΊΡƒΠ»ΡŒΡ‚ΡƒΡ€Ρ‹”, ΠΏΠΎΠ³Ρ€ΡƒΠ·ΠΈΠ»ΠΈ Π² Π³Ρ€ΡƒΠ·ΠΎΠ²ΠΈΠΊΠΈ ΠΈ ΠΎΡ‚ΠΏΡ€Π°Π²ΠΈΠ»ΠΈ Ρ‚ΡƒΠ΄Π° ΠΊΡƒΠ΄Π° хуситы Π½Π΅ стрСляли, Ρ‚ΠΎ Π΅ΡΡ‚ΡŒ Ρ‚ΡƒΠ΄Π° Π³Π΄Π΅ написано “ΠΊΠΎΠ½Π΅Ρ† свСта” ΠΈ ΠΎΡ‚Ρ‚ΡƒΠ΄Π° Π΅Ρ‰Π΅ 15ΠΊΠΌ Π½Π°Π»Π΅Π²ΠΎ.

По ΠΏΡ€ΠΈΠ±Ρ‹Ρ‚ΠΈΠΈ Ρ€Π°Π·Π²Π΅Ρ€Π½ΡƒΠ»ΠΈ ΠΎΠ½ΠΈ Ρ‚Π°ΠΌ свои Π·Π°ΠΌΠ΅Ρ‡Π°Ρ‚Π΅Π»ΡŒΠ½Ρ‹Π΅ амСриканскиС вооруТСния, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ ΡƒΠΆΠ΅ Ρ‚ΠΎΠ³Π΄Π° ΠΏΠΎΡ€Π° Π±Ρ‹Π»ΠΎ ΠΎΡ‚ΠΏΡ€Π°Π²ΠΈΡ‚ΡŒ Π²ΠΎ Π’ΡŒΠ΅Ρ‚Π½Π°ΠΌ Π½Π° выставку “Π‘ ΠΏΠΎΠΌΠΎΡ‰ΡŒΡŽ этого ΠΈ Π‘Π‘Π‘Π  ΠΌΡ‹ ΠΏΠΎΠ±Π΅Π΄ΠΈΠ»ΠΈ БША 25 Π»Π΅Ρ‚ Π½Π°Π·Π°Π΄”. Натянули Ρ‚Π΅Π½Ρ‚, достали ΠΏΠΈΠ²ΠΎ ΠΈ сСли ΠΆΠ΄Π°Ρ‚ΡŒ ΠΊΠΎΠ³Π΄Π° Ρ€Π°Π΄Π°Ρ€ подаст Π·Π²ΡƒΠΊΠΎΠ²ΠΎΠΉ сигнал ΠΎΠ± ΠΎΠ±Π½Π°Ρ€ΡƒΠΆΠ΅Π½ΠΈΠΈ ΡƒΡ‡Π΅Π±Π½ΠΎΠΉ Ρ†Π΅Π»ΠΈ.

Π‘ΠΈΠ³Π½Π°Π» Π½Π΅ заставил сСбя ΠΆΠ΄Π°Ρ‚ΡŒ! Волько исходил ΠΎΠ½ Π½Π΅ ΠΎΡ‚ Ρ€Π°Π΄Π°Ρ€Π½ΠΎΠΉ установки, Π° ΠΎΡ‚ Ρ‚Π΅Π»Π΅Ρ„ΠΎΠ½Π° Π½Π° ΠΊΠΎΠΎΡ€Π΄ΠΈΠ½Ρ†ΠΈΠΎΠ½Π½ΠΎΠΌ ΠΏΡƒΠ½ΠΊΡ‚Π΅, Π·Π° 70ΠΊΠΌ ΠΎΡ‚ пусковой установки. Π£ΠΆΠ΅ Ρ‚ΠΎΠ³Π΄Π° Ρƒ нас Π·Π½Π°Π»ΠΈ Ρ‡Ρ‚ΠΎ Ρ‚Π°ΠΊΠΎΠ΅ Ρ€Π°Π±ΠΎΡ‚Π° Π½Π° ΡƒΠ΄Π°Π»Ρ‘Π½ΠΊΠ΅. Π€ΠΎΡ€ΠΌΠ°Ρ‚ сигнала Π±Ρ‹Π» Ρ‚Π°ΠΊΠΎΠΉ: Π·Π²ΠΎΠ½ΠΎΠΊ-Π·Π²ΠΎΠ½ΠΎΠΊ-рядовой Π Π°Π±ΠΈΠ½ΠΎΠ²ΠΈΡ‡ слухаэ!

Как Π²Ρ‹ Π½Π°Π²Π΅Ρ€Π½ΠΎΠ΅ догадались (знаю Ρ‡Ρ‚ΠΎ Π½Π΅Ρ‚) Π·Π²ΠΎΠ½ΠΈΠ» ΠΊΠΎΠΌΠ°Π½Π΄ΡƒΡŽΡ‰ΠΈΠΉ ΠŸΠ’Πž ΠΈ ΡΠΏΡ€Π°ΡˆΠΈΠ²Π°Π», ΡƒΠ΄Π°Π»ΠΎΡΡŒ Π»ΠΈ Π½Π°ΠΌ Π·Π°ΡΠ΅Ρ‡ΡŒ Ρ†Π΅Π»ΡŒ ΠΈ провСсти “пуск”, ΠΏΠΎΡ‚ΠΎΠΌΡƒ Ρ‡Ρ‚ΠΎ ΠΏΠΈΠ»ΠΎΡ‚ ΡƒΡ‡Π΅Π±Π½ΠΎΠΉ Ρ†Π΅Π»ΠΈ ΡƒΠΆΠ΅ ΠΏΠΎΠΎΠ±Π΅Π΄Π°Π», Π΄ΠΎΠΏΠΈΠ» ΠΊΠΎΠΌΠΏΠΎΡ‚ ΠΈ Ρ…ΠΎΡ‡Π΅Ρ‚ Π΅Ρ…Π°Ρ‚ΡŒ Π΄ΠΎΠΌΠΎΠΉ ΠΊ ΠΌΠ°ΠΌΠ΅.

Π’ ΠΎΠ±Ρ‰Π΅ΠΌ ΠΏΠΈΠ»ΠΎΡ‚ Π½Π°Ρ€Π΅Π·Π°Π» Π΅Ρ‰Π΅ 3 ΠΊΡ€ΡƒΠ³Π° ΠΈ ΠΊ Π΄ΠΎΠΌΠΎΠΉ Π½Π΅ ΠΏΠΎΠ΅Ρ…Π°Π», ΠΏΠΎΡ‚ΠΎΠΌΡƒ ΠΊΠ°ΠΊ Π¨Π°Π±Π°Ρ‚ ΠΈ автобусов большС Π½Π΅Ρ‚.

ΠšΠ°ΠΌΠ΅Π½Ρ‚Ρ‹ ΠΏΠΈΡΠ°Ρ‚ΡŒ здСсь