Author: gsiv1mgyj72u

  • eot-server.net

    eot-server.net

    介绍

    本开源库为物联网边缘终端EOBox大数据平台服务.NET版本。eoiot开源项目分为五大模块,从边缘终端到服务器,从前端到后台,从Web服务到App,提供全方位开源代码,MIT许可协议,可无任何后顾之忧直接用于商业项目。本项目的目的在于打造一个专用于小微型用途的低成本的、高弹性的物联网实用平台。

    采用多线程Socket异步IO模型,支持大规模终端并发。支持多线程MySQL数据库操作。支持网络包日志文件。支持TCP/HJ212环保协议。可直接对接基于STM32 F407嵌入式数采仪终端(EOBox,请参考另一开源库eot-embdtub)

    采用.NET Core API实现对终端信息的存储、编辑,状态管理,物联网数据参数实时数据查询,历史数据查询。实现了API访问权限底层架构,以及建立在架构之上的基础框架功能,包括账号、部门、角色、权限、菜单等功能。(前后端分离,依赖于前端Vue3.0界面,请参考另一开源库eot-webui3)

    全部模块使用原生代码,不依赖于第三方,能从原理上理解整个系统核心要点,做到安全可控可扩展。

    详细信息请查看API参考注释

    软件架构

    目前暂为预览版本,后续进一步完善,使用Microsoft Visual Studio Community 2022,.NET 6.0进行开发

    eot-server.net分为两大模块,EOTServer采用C/S架构,TCP Server为物联网终端提供网络数据采集服务,目前以实现HJ212协议,可进行多协议扩展。另一模块EOTWebService采用B/S架构,Web API为前端管理页面提供功能接口。

    两大模块既可以用于小型应用合并执行,EOTServer也可独立启动 C/S和B/S分开运行,后面我们会提供分布式大规模弹性多服务器部署方案,可实现百万级终端大数据并发处理。

    使用说明

    代码使用Microsoft Visual Studio Community 2022 (64 位) 个人社区版本(免费)直接打开,无需下载依赖任何第三方库。

    数据库使用Oracle MySQL Community Server(开源免费)8.0,推荐官方免费的MySQL Workbench可视化工具,直接导入db/eotgate.sql脚本。本系统提供了独立的SQL语句执行系统,不再使用存储过程,避免过多依赖于数据库,可更好的进行多数据库迁移。

    为了和终端兼容,并扩展方便,采用了yml配置文件格式。平台一共使用两个配置文件server.yml和web.yml分别对应C/S模块和B/S模块。

    完善扩展了HJ212协议,可通过HJ212进行终端固件版本升级,预留了版本回滚机制。采用Base64可见字符传输二进制版本文件,虽然加大了传输量,但很好的兼容了HJ212协议和移远EC模块指令。

    参与贡献

    1. Fork 本仓库
    2. 新建 Feat_xxx 分支
    3. 提交代码
    4. 新建 Pull Request

    特技

    1. 使用 Readme_XXX.md 来支持不同的语言,例如 Readme_en.md, Readme_zh.md
    2. Gitee 官方博客 blog.gitee.com
    3. 你可以 https://gitee.com/explore 这个地址来了解 Gitee 上的优秀开源项目
    4. GVP 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
    5. Gitee 官方提供的使用手册 https://gitee.com/help
    6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 https://gitee.com/gitee-stars/

    Visit original content creator repository
    https://github.com/bigbook2000/eot-server.net

  • Introduction-to-Bayesian-Statistical-Learning

    Introduction to Bayesian Statistical Learning

    Table of Contents

    1. Description
    2. Information
    3. File descriptions
    4. Certificate

    Description

    When observing data, the key question is: What can I learn from the observation? Bayesian inference treats all parameters of the model as random variables. The main task is to update their distribution as new data is observed. Hence, quantifying uncertainty of the parameter estimation is always part of the task. In this course we will introduce the basic theoretical concepts of Bayesian Statistics and Bayesian inference. We discuss the computational techniques and their implementations, different types of models as well as model selection procedures. We will exercise on the existing datasets using the PyMC3 framework for practicals.

    Information

    The overall goals of this course were the following:

    • Bayes theorem, Prior and Posterior distributions;
    • Computational challenges and techniques: MCMC, variational approaches;
    • Models: mixture models, Gaussian processes, neural networks;
    • Bayesian model selection: Bayes factor and others;
    • PyMC3 framework for Bayesian computation;
    • Running Bayesian models on a Supercomputer;

    More detailed information, links and software setup for the course can be found on the course website.

    File descriptions

    The description of the files in this repository can be found below:


    • Day 3 – Markov chain Monte Carlo (MCMC) methods:

    • Day 4 – Bayesian optimization and variational inference:
      • avb_gaussian – Notebook (Analytic Variational Bayes, Inferring a single Gaussian);
      • svb_gaussian_tf2 – Notebook (Stochastic Variational Bayes);
      • svb_biexp_tf2 – Notebook (Stochastic Variational Bayes – example nonlinear model);
      • BLcourse3 – Slides;

    • Day 5 – Bayes and generative ML models: Variational autoencoders, Normalizing flows, Gaussian processes, other topics not covered yet:

    Certificate

    The certificate for the workshop can be found below:

    “Introduction to Bayesian Statistical Learning” – Jülich Supercomputing Centre (JSC) (Issued On: April 2023)

    Visit original content creator repository https://github.com/HROlive/Introduction-to-Bayesian-Statistical-Learning
  • babel-plugin-extract-text

    babel-plugin-extract-text

    Babel plugin to extract strings from React components and gettext-like functions into a gettext PO file.

    npm version CircleCI codecov David

    Features

    • Extraction from React components
      • Verbose style: <LocalizedString id="Nice cat!" idPlural="Nice cats!" count={numCats} />
      • Shortform style: <LocalizedString i18n={_n('Nice cat!', 'Nice cats!', numCats)} />
    • Extraction from gettext-like functions
      • _('Hello World')
    • Customizable extraction (e.g. component name, function names and function argument positions)
    • Supports translator comments and context
    • Validation (e.g. props missing on component, non-string literals are used for call expression arguments)

    Setup

    Begin with installing this plugin and the JSX plugin for Babel

    yarn add --dev babel-plugin-extract-text @babel/syntax-jsx
    

    In a babel configuration, add both plugins and set the options

    { plugins: ['@babel/syntax-jsx', ['extract-text', { ... options ... }]] }
    

    Options

    This plugin allows a number of configurations to be passed:

    • outputFile: Output PO file name (default is the ${currentFileProcessed}.po)
    • outputDir: Output directory (default is dir of the current file being processed)
    • includeReference: Whether to include a file reference for PO entries (default false)
    • baseReferenceDir: Directory that should be used as a staring point for reference paths
    • charset: Character set for the PO (default UTF-8)
    • headers: Object indicating all PO headers to include. See the default headers here.
    • component/function: Objects customizing the extraction for component/function respectively. This includes the React component name to look for, the function names, and so on. See the default configuration here.

    Example

    Plugin Configuration

    const babel = require('babel-core')
    
    babel.transformFile('someCode.js', {
      plugins: [
        '@babel/syntax-jsx',
        ['extract-text', {
          includeReference: true,
          headers: {
            'po-revision-date': new Date().toISOString(),
          },
          component: {
            name: 'Message',
            singular: 'id',
            plural: 'idPlural',
            context: 'context',
            comment: 'comment',
            shortform: 'i18n',
          },
        }],
      ],
    }, (error) => error ? console.log(error) : console.log('Done!'))

    Input (someCode.js)

    // Verbose style, specifying gettext args via props
    <Message
        id="You have a cat."
        idPlural="You have {cats} cats!"
        comment="User profile description for a public profile"
        count={numCats}
        cats={numCatsFormatted} />
    
    // Shortform style, using gettext function directly
    <Message i18n={_('Hello World')} />
    
    _c('Flag', 'Physical Object')

    Output (someCode.js.po)

    msgid ""
    msgstr ""
    "Content-Type: text/plain; charset=utf-8\n"
    "Plural-Forms: nplurals=2; plural=(n!=1);\n"
    "Language: en_US\n"
    "PO-Revision-Date: 2017-02-08T05:27:35.094Z\n"
    
    #: someCode.js
    #. User profile description for a public profile
    msgid "You have a cat."
    msgid_plural "You have {cats} cats!"
    msgstr[0] ""
    msgstr[1] ""
    
    #: someCode.js
    msgctxt "Physical Object"
    msgid "Flag"
    msgstr ""
    
    #: someCode.js
    msgid "Hello World"
    msgstr ""
    

    Next Steps

    You can use my other library react-translations, which plays nicely with this babel plugin. Otherwise you’ll need to build out these components and hook them up to a basic gettext client such as Jed.

    Motivation

    1. Why not use ICU MessageFormat?

    ICU patterns strings, while pretty powerful, can become clunkly very fast. Gettext style strings should be enough to cover the typical use cases and are easy to use and understand. More importantly, ICU strings are not always supported by translators and translation providers, whereas the PO format is a de facto standard.

    1. Why not use xgettext to extract?

    xgettext is a difficult dependency to install and manage since it’s not native to the JS ecosystem. Also, xgettext will only support extraction from call expressions. Regardless, the tool definitely does not support JSX/ES6, so you’ll be running your code through Babel anyway.

    1. Why not use a simple JSON format for strings (or some format X)?

    Many extraction tools invent their own format, or use a basic JSON structure, which either ends up being too simple (e.g. not able to support pluralization) and/or not translator friendly (translators are used to working with certain formats). Gettext/PO is a proven method for translation that satisfies everyone: translators, developers, product, and users.

    Acknowledgements

    Thanks to the folks over at Sentry for their blog post, and their extractor tool, both of which served as an inspiration for me to utilize Babel to extend the extraction process to React.

    Visit original content creator repository https://github.com/rtymchyk/babel-plugin-extract-text
  • iswoc-treebank

    As of April 2023, releases of the ISWOC Treebank have moved to
    https://github.com/syntacticus/syntacticus-treebank-data.

    The ISWOC Treebank

    The ISWOC Treebank is a dependency treebank with morphosyntactic and
    information-structure annotation. It includes texts in several older
    Indo-European languages and is freely available under a Creative Commons
    Attribution-NonCommercial-ShareAlike 3.0 License
    .

    Please cite as

    Bech, Kristin and Kristine Eide. 2014. The ISWOC corpus. Department of Literature, Area Studies and European Languages, University of Oslo. http://iswoc.github.com.

    Releases of the ISWOC Treebank are hosted on
    Github.

    Contents

    The following texts are included in this release of the treebank:

    Text Language Filename Size
    Ælfric’s Lives of Saints Old English æls 3137 tokens
    Apollonius of Tyre Old English apt 5541 tokens
    Anglo-Saxon Chronicles Old English chrona 5939 tokens
    Orosius Old English or 1728 tokens
    West-Saxon Gospels Old English wscp 13061 tokens
    La Vie Saint Eustace Old French eustace 2340 tokens
    Crónica Geral de Espanha 2-12 Portuguese cge1 12074 tokens
    Crónica Geral de Espanha 155-167 Portuguese cge2 10547 tokens
    Décadas Livro 5, VIII, 9-14 Portuguese coutdec-v-8 13794 tokens
    Crónica de Alfonso XI Spanish alfonso-xi 7942 tokens
    Crónica de España Spanish ce 4627 tokens
    El Conde Lucanor Spanish cdeluc 17551 tokens
    Estoria de Espanna I Spanish ee1 9488 tokens
    General Estoria parte IV Daniel Spanish ge4 9233 tokens
    Libro delos claros varones Spanish varones 5820 tokens

    (The ‘size’ column in the table above shows the number of annotated tokens in
    a text. The number of tokens will be slightly larger than the number of words
    in the original printed edition as some words have been split into multiple
    tokens and some tokens have been inserted during annotation.)

    Please see the XML files for detailed metadata and a full list of contributors.

    Data formats

    The texts are available on two formats:

    1. PROIEL XML: These files are the authoritative source files and the only ones
      that contain all available annotation. They contain the complete morphological,
      syntactic and information-structure annotation, as well as the complete text,
      including punctuation, section headers etc. The schema is defined in
      proiel.xsd.

    2. CoNLL-X format

    Visit original content creator repository
    https://github.com/iswoc/iswoc-treebank

  • RenameBot-Premium

    Rename Bot Premium Repo. Give a star and Use the Repo as your need.


    Features

    • Renames very fast .
    • Permanent Thumbnail support.
    • Supports Broadcasts.
    • Set custom caption.
    • Force subscribe available.
    • Deploy on any PaaS.
    • Developer Service 24×7. 🔥

    Required Configs

    • TOKEN – Get bot token from @BotFather

    • API_ID – From my.telegram.org

    • API_HASH – From my.telegram.org

    • ADMIN – Your User ID

    • DB_URL – Mongo Database URL from https://cloud.mongodb.com/

    • DB_NAME – optional Your database name from mongoDB. Default will be ‘my’

    • STRING – optional Session String For Premium Users To Upload 4GB File

    • LOG_CHANNEL – Channel Id to Store Files renamed files. Act as a Dump

    Commands

    Copy and paste the command in Botfather

    start - Start Messsage 
    viewthumb - View Your Saved thumbnail
    delthumb - Delete Your Thumbnail
    about - About Bot 
    broadcast - (Admin Use Only)Send Message To All Users
    addpremium - (Admin Use Only)Add Users To Rename More Then 4Gb Files and Remove Time Limit 
    
    

    Deploy on VPS

    • Clone the Repo
    git clone https://github.com/WebX-Divin/RenameBot-Premium
    
    • Move to the Repo Folder
    cd RenameBot-Premium
    
    • Update the instance
    apt update && upgrade
    
    • Install the requirements
    pip install -r requirements.txt
    
    • Create the nested environment
    apt install tmux
    
    • Open the nested environment
    tmux
    
    • Run the Bot
    python3 bot.py
    

    Join Telegram Channel

    Visit original content creator repository
    https://github.com/WebX-Divin/RenameBot-Premium

  • og-tag-scrapper

    og-tag-scrapper

    og tag scrapper is an api to scrap og tags / meta tags
    and return title, description, images in the api

    Description

    Og Tag Scrapper exposes an api that will take a site url and return the meta tags values of title, description, and images used in the site. It will first try to find the Open Graph (og) meta tags on the site.
    If there any above of og tags not found it will fallback to site meta tags.

    POST  / 
    payload {"url": ""}

    Sample CURL to use the API

    curl --location --request POST 'https://hl82j05f4m.execute-api.us-east-1.amazonaws.com/dev/api/v1/meta-tag' \
    --header 'Authorization: *********' \
    --header 'Content-Type: application/json' \
    --data-raw '{
        "url": "https://www.npmjs.com/package/dotenv"
    }'
    

    Note: This api has basic auth enabled. Without authentication, it will throw 401 error.

    • To use the api need to add valid basic auth credentials in the place of *********
    • In the api the url can be sent in the url attribute of request body’s to scrap and retrieve meta tags

    • Basic Auth cred is added as environment variable for basic security on API layer.
    • and meta tags are added in environment variable too to update meta params dynamically if needed in future.

    Release Notes:

    • Currently this is deployed in dev env.
    • Caching layer like Elasticache / DAX can be added for performance improvement ( Future scope)

    Visit original content creator repository
    https://github.com/tejomayonline/og-tag-scrapper

  • file

    Logo logo

    File manipulations

    GitHub Issues GitHub Pull Requests Test PHP codecov GitHub release (latest by date) LICENSE Renovate


    Table of Contents

    Installation

    composer require alexskrypnyk/file

    Usage

    This library provides a comprehensive set of static methods for file and directory operations, including high-performance batch operations for processing multiple files efficiently.

    All methods are available through the AlexSkrypnyk\File\File class.

    use AlexSkrypnyk\File\Exception\FileException;use AlexSkrypnyk\File\ExtendedSplFileInfo;use AlexSkrypnyk\File\File;
    
    try {
      // Get current working directory
      $cwd = File::cwd();
    
      // Copy a directory recursively
      File::copy('/path/to/source', '/path/to/destination');
    
      // Check if a file contains a string
      if (File::contains('/path/to/file.txt', 'search term')) {
        // Do something
      }
    
      // Process string content directly
      $content = File::read('/path/to/file.txt');
      $processed = File::replaceContent($content, 'old', 'new');
      $processed = File::removeToken($processed, '# BEGIN', '# END');
      File::dump('/path/to/file.txt', $processed);
    
      // Or use batch operations for better performance
      File::addTaskDirectory(function(ExtendedSplFileInfo $file_info): ExtendedSplFileInfo {
        $content = File::replaceContent($file_info->getContent(), 'old', 'new');
        $file_info->setContent($content);
        return $file_info;
      });
      File::runTaskDirectory('/path/to/directory');
    
    } catch (FileException $exception) {
      // Handle any file operation errors
      echo $exception->getMessage();
    }

    Available Functions

    Function Description
    absolute() Get absolute path for provided absolute or relative file.
    compare() Compare files between source and destination directories.
    contains() Check if file contains a specific string or matches a pattern.
    containsInDir() Find all files in directory containing a specific string.
    copy() Copy file or directory.
    copyIfExists() Copy file or directory if it exists.
    cwd() Get current working directory with absolute path.
    diff() Create diff files between baseline and destination directories. See Diff Operations below.
    dir() Get absolute path for existing directory.
    dirIsEmpty() Check if directory is empty.
    dump() Write content to a file.
    exists() Check if file or directory exists.
    findMatchingPath() Find first path that matches a needle among provided paths.
    mkdir() Creates a directory if it doesn’t exist.
    patch() Apply patch files to a baseline and produce a destination.
    read() Read file contents.
    realpath() Replacement for PHP’s realpath resolves non-existing paths.
    remove() Remove file or directory.
    removeLine() Remove lines containing a specific string from a file.
    removeToken() Remove tokens and optionally content between tokens from a string.
    removeTokenInFile() Remove tokens and optionally content between tokens from a file.
    removeTokenInDir() Remove tokens and optionally content between tokens from all files in a directory.
    renameInDir() Rename files in directory by replacing part of the filename.
    replaceContent() Replace content in a string.
    replaceContentCallback() Replace content in a string using a callback processor.
    replaceContentInFile() Replace content in a file.
    replaceContentCallbackInFile() Replace content in a file using a callback processor.
    replaceContentInDir() Replace content in all files in a directory.
    replaceContentCallbackInDir() Replace content in all files in a directory using a callback processor.
    collapseRepeatedEmptyLines() Remove multiple consecutive empty lines, keeping at most one empty line between content blocks.
    rmdir() Remove directory recursively.
    rmdirEmpty() Remove directory recursively if empty.
    scandirRecursive() Recursively scan directory for files.
    sync() Synchronize files from source to destination directory.
    tmpdir() Create temporary directory.

    Batch Operations

    For improved performance when processing multiple files, the library provides batch operations that minimize directory scans and optimize I/O operations:

    Function Description
    addTaskDirectory() Add a batch task to be executed on all files in a directory.
    runTaskDirectory() Execute all queued tasks on files in a directory with optimized I/O.
    clearTaskDirectory() Clear all queued batch tasks.
    replaceContent() Replace content in a string (base method for batch processing).
    replaceContentCallback() Replace content in a string using a callback processor (base method for batch processing).
    removeToken() Remove tokens from a string (base method for batch processing).
    collapseRepeatedEmptyLines() Remove multiple consecutive empty lines from a string (base method for batch processing).

    Performance Benefits

    The batch operations provide significant performance improvements over traditional file operations:

    • Single directory scan: Instead of scanning the directory multiple times
    • Single I/O per file: Each file is read once, processed by all tasks, then written once
    • Memory efficient: Uses generators to handle large file sets without loading everything into memory

    Usage Example

    use AlexSkrypnyk\File\ExtendedSplFileInfo;use AlexSkrypnyk\File\File;
    
    // Traditional approach (slow for multiple operations)
    File::replaceContentInDir('/path/to/dir', 'old1', 'new1');
    File::replaceContentInDir('/path/to/dir', 'old2', 'new2');
    File::removeTokenInDir('/path/to/dir', '# token');
    
    // Callback approach for custom processing
    File::replaceContentCallbackInDir('/path/to/dir', function(string $content, string $file_path): string {
      // Custom processing logic with access to file path
      $content = str_replace('old1', 'new1', $content);
      $content = preg_replace('/pattern/', 'replacement', $content);
      // Example: different processing based on file type
      if (str_ends_with($file_path, '.md')) {
        $content = '# ' . $content;
      }
      return strtoupper($content);
    });
    
    // Batch approach (significantly faster)
    File::addTaskDirectory(function(ExtendedSplFileInfo $file_info): ExtendedSplFileInfo {
      $content = File::replaceContent($file_info->getContent(), 'old1', 'new1');
      $content = File::replaceContent($content, 'old2', 'new2');
      $content = File::removeToken($content, '# token');
      $content = File::collapseRepeatedEmptyLines($content);
      $file_info->setContent($content);
      return $file_info;
    });
    
    // Batch approach with callback processing
    File::addTaskDirectory(function(ExtendedSplFileInfo $file_info): ExtendedSplFileInfo {
      $content = File::replaceContentCallback($file_info->getContent(), function(string $content): string {
        return strtoupper(str_replace('old', 'new', $content));
      });
      $file_info->setContent($content);
      return $file_info;
    });
    
    File::runTaskDirectory('/path/to/dir');

    Performance Results: In tests with 5,000 files across 100 directories performing 10 operations per file:

    • Traditional approach: ~16s (multiple directory scans, multiple I/O per file)
    • Batch approach: ~1.7s (~89% faster, single directory scan, single I/O per file)

    Architecture

    The batch operations are powered by an internal Tasker queue management system that:

    • Uses PHP generators for memory-efficient processing of large file sets
    • Implements a two-way communication pattern between the queue and file processors
    • Leverages ExtendedSplFileInfo objects for rich file context and metadata
    • Provides type-safe object validation to ensure data integrity
    • Maintains complete separation between the generic queue system and file-specific operations

    This architecture allows the library to scale efficiently from small single-file operations to large-scale batch processing scenarios.

    Diff Operations

    The diff(), patch(), and compare() functions provide powerful tools for working with file differences between directories:

    use AlexSkrypnyk\File\File;
    use AlexSkrypnyk\File\Exception\PatchException;
    
    // Generate diff files between baseline and destination directories
    File::diff('/path/to/baseline', '/path/to/destination', '/path/to/diff');
    
    // Compare directories to determine if they're equal
    $result = File::compare('/path/to/source', '/path/to/destination');
    
    // Apply patches to transform a baseline directory
    try {
      File::patch('/path/to/baseline', '/path/to/diff', '/path/to/patched');
    } catch (PatchException $exception) {
      echo $exception->getMessage(); // Returns a detailed error message.
    
      // Additional contextual information
      $path = $exception->getFilePath();    // Gets the affected file path.
      $line_number = $exception->getLineNumber(); // Gets the line number where the error occurred.
      $line_content = $exception->getLineContent(); // Gets the content of the problematic line.
    }

    The diff functionality allows you to:

    1. Generate differences between two directory structures
    2. Store those differences as patch files
    3. Apply those patches to recreate directory structures elsewhere

    The PatchException provides detailed error messages with contextual information when patch operations fail, making debugging easier.

    Ignoring Files and Content Changes

    You can create a .ignorecontent file in your directories to specify patterns for files or content that should be ignored during comparison. This is useful for timestamps, randomly generated values, or files that shouldn’t be compared.

    The syntax for .ignorecontent file is similar to .gitignore with additional content ignoring capabilities:

    # Comments start with #
    file.txt        # Ignore this specific file
    logs/           # Ignore this directory and all subdirectories
    temp/*          # Ignore all files in directory, but not subdirectories
    ^config.json    # Ignore content changes in this file, but check file exists
    ^data/          # Ignore content changes in all files in dir and subdirs
    ^cache/*        # Ignore content changes in all files in dir, but not subdirs
    !important.txt  # Do not ignore this file (exception)
    !^settings.php  # Do not ignore content changes in this file
    

    Prefix meanings:

    • No prefix: Ignore file/directory completely
    • ^: Ignore content changes but verify file/directory exists
    • !: Exception – do not ignore this file/directory
    • !^: Exception – do not ignore content changes in this file/directory

    When parsing these rules, the library may throw a RulesException if there are issues:

    use AlexSkrypnyk\File\File;
    use AlexSkrypnyk\File\Exception\RulesException;
    
    try {
      // Operations using .ignorecontent rules
      File::compare('/path/to/source', '/path/to/destination');
    } catch (RulesException $exception) {
      // Handle rules parsing errors
      echo $exception->getMessage();
    }

    Assertion Traits

    The library includes PHPUnit traits for testing files and directories:

    Directory Assertions Trait

    Assertion Method Description
    assertDirectoryContainsString() Assert that a directory contains files with a specific string.
    assertDirectoryNotContainsString() Assert that a directory does not contain files with a specific string.
    assertDirectoryContainsWord() Assert that a directory contains files with a specific word (bounded by word boundaries).
    assertDirectoryNotContainsWord() Assert that a directory does not contain files with a specific word.
    assertDirectoryEqualsDirectory() Assert that two directories have identical structure and content.
    assertDirectoryEqualsPatchedBaseline() Assert that a directory is equal to the patched baseline (baseline + diff).

    Usage example:

    use PHPUnit\Framework\TestCase;
    use AlexSkrypnyk\File\Tests\Traits\DirectoryAssertionsTrait;
    
    class MyTest extends TestCase {
      use DirectoryAssertionsTrait;
    
      public function testDirectories(): void {
        // Assert directory contains "example" string in at least one file
        $this->assertDirectoryContainsString('example', '/path/to/directory');
    
        // Assert two directories are identical
        $this->assertDirectoryEqualsDirectory('/path/to/dir1', '/path/to/dir2');
      }
    }

    File Assertions Trait

    Assertion Method Description
    assertFileContainsString() Assert that a file contains a specific string.
    assertFileNotContainsString() Assert that a file does not contain a specific string.
    assertFileContainsWord() Assert that a file contains a specific word (bounded by word boundaries).
    assertFileNotContainsWord() Assert that a file does not contain a specific word.
    assertFileEqualsFile() Assert that a file equals another file in contents.
    assertFileNotEqualsFile() Assert that a file does not equal another file in contents.

    Usage example:

    use PHPUnit\Framework\TestCase;
    use AlexSkrypnyk\File\Tests\Traits\FileAssertionsTrait;
    
    class MyTest extends TestCase {
      use FileAssertionsTrait;
    
      public function testFiles(): void {
        // Assert file contains "example" string
        $this->assertFileContainsString('example', '/path/to/file.txt');
    
        // Assert file contains "test" as a complete word
        $this->assertFileContainsWord('test', '/path/to/file.txt');
    
        // Assert file does not contain a partial word
        $this->assertFileNotContainsWord('exampl', '/path/to/file.txt');
    
        // Assert two files have identical content
        $this->assertFileEqualsFile('/path/to/expected.txt', '/path/to/actual.txt');
    
        // Assert two files have different content
        $this->assertFileNotEqualsFile('/path/to/expected.txt', '/path/to/actual.txt');
      }
    }

    Maintenance

    composer install
    composer lint
    composer test
    
    # Run performance tests
    ./vendor/bin/phpunit --testsuite=performance

    This repository was created using the Scaffold project template

    Visit original content creator repository https://github.com/AlexSkrypnyk/file
  • file

    Logo logo

    File manipulations

    GitHub Issues GitHub Pull Requests Test PHP codecov GitHub release (latest by date) LICENSE Renovate


    Table of Contents

    Installation

    composer require alexskrypnyk/file

    Usage

    This library provides a comprehensive set of static methods for file and directory operations, including high-performance batch operations for processing multiple files efficiently.

    All methods are available through the AlexSkrypnyk\File\File class.

    use AlexSkrypnyk\File\Exception\FileException;use AlexSkrypnyk\File\ExtendedSplFileInfo;use AlexSkrypnyk\File\File;
    
    try {
      // Get current working directory
      $cwd = File::cwd();
    
      // Copy a directory recursively
      File::copy('/path/to/source', '/path/to/destination');
    
      // Check if a file contains a string
      if (File::contains('/path/to/file.txt', 'search term')) {
        // Do something
      }
    
      // Process string content directly
      $content = File::read('/path/to/file.txt');
      $processed = File::replaceContent($content, 'old', 'new');
      $processed = File::removeToken($processed, '# BEGIN', '# END');
      File::dump('/path/to/file.txt', $processed);
    
      // Or use batch operations for better performance
      File::addTaskDirectory(function(ExtendedSplFileInfo $file_info): ExtendedSplFileInfo {
        $content = File::replaceContent($file_info->getContent(), 'old', 'new');
        $file_info->setContent($content);
        return $file_info;
      });
      File::runTaskDirectory('/path/to/directory');
    
    } catch (FileException $exception) {
      // Handle any file operation errors
      echo $exception->getMessage();
    }

    Available Functions

    Function Description
    absolute() Get absolute path for provided absolute or relative file.
    compare() Compare files between source and destination directories.
    contains() Check if file contains a specific string or matches a pattern.
    containsInDir() Find all files in directory containing a specific string.
    copy() Copy file or directory.
    copyIfExists() Copy file or directory if it exists.
    cwd() Get current working directory with absolute path.
    diff() Create diff files between baseline and destination directories. See Diff Operations below.
    dir() Get absolute path for existing directory.
    dirIsEmpty() Check if directory is empty.
    dump() Write content to a file.
    exists() Check if file or directory exists.
    findMatchingPath() Find first path that matches a needle among provided paths.
    mkdir() Creates a directory if it doesn’t exist.
    patch() Apply patch files to a baseline and produce a destination.
    read() Read file contents.
    realpath() Replacement for PHP’s realpath resolves non-existing paths.
    remove() Remove file or directory.
    removeLine() Remove lines containing a specific string from a file.
    removeToken() Remove tokens and optionally content between tokens from a string.
    removeTokenInFile() Remove tokens and optionally content between tokens from a file.
    removeTokenInDir() Remove tokens and optionally content between tokens from all files in a directory.
    renameInDir() Rename files in directory by replacing part of the filename.
    replaceContent() Replace content in a string.
    replaceContentCallback() Replace content in a string using a callback processor.
    replaceContentInFile() Replace content in a file.
    replaceContentCallbackInFile() Replace content in a file using a callback processor.
    replaceContentInDir() Replace content in all files in a directory.
    replaceContentCallbackInDir() Replace content in all files in a directory using a callback processor.
    collapseRepeatedEmptyLines() Remove multiple consecutive empty lines, keeping at most one empty line between content blocks.
    rmdir() Remove directory recursively.
    rmdirEmpty() Remove directory recursively if empty.
    scandirRecursive() Recursively scan directory for files.
    sync() Synchronize files from source to destination directory.
    tmpdir() Create temporary directory.

    Batch Operations

    For improved performance when processing multiple files, the library provides batch operations that minimize directory scans and optimize I/O operations:

    Function Description
    addTaskDirectory() Add a batch task to be executed on all files in a directory.
    runTaskDirectory() Execute all queued tasks on files in a directory with optimized I/O.
    clearTaskDirectory() Clear all queued batch tasks.
    replaceContent() Replace content in a string (base method for batch processing).
    replaceContentCallback() Replace content in a string using a callback processor (base method for batch processing).
    removeToken() Remove tokens from a string (base method for batch processing).
    collapseRepeatedEmptyLines() Remove multiple consecutive empty lines from a string (base method for batch processing).

    Performance Benefits

    The batch operations provide significant performance improvements over traditional file operations:

    • Single directory scan: Instead of scanning the directory multiple times
    • Single I/O per file: Each file is read once, processed by all tasks, then written once
    • Memory efficient: Uses generators to handle large file sets without loading everything into memory

    Usage Example

    use AlexSkrypnyk\File\ExtendedSplFileInfo;use AlexSkrypnyk\File\File;
    
    // Traditional approach (slow for multiple operations)
    File::replaceContentInDir('/path/to/dir', 'old1', 'new1');
    File::replaceContentInDir('/path/to/dir', 'old2', 'new2');
    File::removeTokenInDir('/path/to/dir', '# token');
    
    // Callback approach for custom processing
    File::replaceContentCallbackInDir('/path/to/dir', function(string $content, string $file_path): string {
      // Custom processing logic with access to file path
      $content = str_replace('old1', 'new1', $content);
      $content = preg_replace('/pattern/', 'replacement', $content);
      // Example: different processing based on file type
      if (str_ends_with($file_path, '.md')) {
        $content = '# ' . $content;
      }
      return strtoupper($content);
    });
    
    // Batch approach (significantly faster)
    File::addTaskDirectory(function(ExtendedSplFileInfo $file_info): ExtendedSplFileInfo {
      $content = File::replaceContent($file_info->getContent(), 'old1', 'new1');
      $content = File::replaceContent($content, 'old2', 'new2');
      $content = File::removeToken($content, '# token');
      $content = File::collapseRepeatedEmptyLines($content);
      $file_info->setContent($content);
      return $file_info;
    });
    
    // Batch approach with callback processing
    File::addTaskDirectory(function(ExtendedSplFileInfo $file_info): ExtendedSplFileInfo {
      $content = File::replaceContentCallback($file_info->getContent(), function(string $content): string {
        return strtoupper(str_replace('old', 'new', $content));
      });
      $file_info->setContent($content);
      return $file_info;
    });
    
    File::runTaskDirectory('/path/to/dir');

    Performance Results: In tests with 5,000 files across 100 directories performing 10 operations per file:

    • Traditional approach: ~16s (multiple directory scans, multiple I/O per file)
    • Batch approach: ~1.7s (~89% faster, single directory scan, single I/O per file)

    Architecture

    The batch operations are powered by an internal Tasker queue management system that:

    • Uses PHP generators for memory-efficient processing of large file sets
    • Implements a two-way communication pattern between the queue and file processors
    • Leverages ExtendedSplFileInfo objects for rich file context and metadata
    • Provides type-safe object validation to ensure data integrity
    • Maintains complete separation between the generic queue system and file-specific operations

    This architecture allows the library to scale efficiently from small single-file operations to large-scale batch processing scenarios.

    Diff Operations

    The diff(), patch(), and compare() functions provide powerful tools for working with file differences between directories:

    use AlexSkrypnyk\File\File;
    use AlexSkrypnyk\File\Exception\PatchException;
    
    // Generate diff files between baseline and destination directories
    File::diff('/path/to/baseline', '/path/to/destination', '/path/to/diff');
    
    // Compare directories to determine if they're equal
    $result = File::compare('/path/to/source', '/path/to/destination');
    
    // Apply patches to transform a baseline directory
    try {
      File::patch('/path/to/baseline', '/path/to/diff', '/path/to/patched');
    } catch (PatchException $exception) {
      echo $exception->getMessage(); // Returns a detailed error message.
    
      // Additional contextual information
      $path = $exception->getFilePath();    // Gets the affected file path.
      $line_number = $exception->getLineNumber(); // Gets the line number where the error occurred.
      $line_content = $exception->getLineContent(); // Gets the content of the problematic line.
    }

    The diff functionality allows you to:

    1. Generate differences between two directory structures
    2. Store those differences as patch files
    3. Apply those patches to recreate directory structures elsewhere

    The PatchException provides detailed error messages with contextual information when patch operations fail, making debugging easier.

    Ignoring Files and Content Changes

    You can create a .ignorecontent file in your directories to specify patterns for files or content that should be ignored during comparison. This is useful for timestamps, randomly generated values, or files that shouldn’t be compared.

    The syntax for .ignorecontent file is similar to .gitignore with additional content ignoring capabilities:

    # Comments start with #
    file.txt        # Ignore this specific file
    logs/           # Ignore this directory and all subdirectories
    temp/*          # Ignore all files in directory, but not subdirectories
    ^config.json    # Ignore content changes in this file, but check file exists
    ^data/          # Ignore content changes in all files in dir and subdirs
    ^cache/*        # Ignore content changes in all files in dir, but not subdirs
    !important.txt  # Do not ignore this file (exception)
    !^settings.php  # Do not ignore content changes in this file
    

    Prefix meanings:

    • No prefix: Ignore file/directory completely
    • ^: Ignore content changes but verify file/directory exists
    • !: Exception – do not ignore this file/directory
    • !^: Exception – do not ignore content changes in this file/directory

    When parsing these rules, the library may throw a RulesException if there are issues:

    use AlexSkrypnyk\File\File;
    use AlexSkrypnyk\File\Exception\RulesException;
    
    try {
      // Operations using .ignorecontent rules
      File::compare('/path/to/source', '/path/to/destination');
    } catch (RulesException $exception) {
      // Handle rules parsing errors
      echo $exception->getMessage();
    }

    Assertion Traits

    The library includes PHPUnit traits for testing files and directories:

    Directory Assertions Trait

    Assertion Method Description
    assertDirectoryContainsString() Assert that a directory contains files with a specific string.
    assertDirectoryNotContainsString() Assert that a directory does not contain files with a specific string.
    assertDirectoryContainsWord() Assert that a directory contains files with a specific word (bounded by word boundaries).
    assertDirectoryNotContainsWord() Assert that a directory does not contain files with a specific word.
    assertDirectoryEqualsDirectory() Assert that two directories have identical structure and content.
    assertDirectoryEqualsPatchedBaseline() Assert that a directory is equal to the patched baseline (baseline + diff).

    Usage example:

    use PHPUnit\Framework\TestCase;
    use AlexSkrypnyk\File\Tests\Traits\DirectoryAssertionsTrait;
    
    class MyTest extends TestCase {
      use DirectoryAssertionsTrait;
    
      public function testDirectories(): void {
        // Assert directory contains "example" string in at least one file
        $this->assertDirectoryContainsString('example', '/path/to/directory');
    
        // Assert two directories are identical
        $this->assertDirectoryEqualsDirectory('/path/to/dir1', '/path/to/dir2');
      }
    }

    File Assertions Trait

    Assertion Method Description
    assertFileContainsString() Assert that a file contains a specific string.
    assertFileNotContainsString() Assert that a file does not contain a specific string.
    assertFileContainsWord() Assert that a file contains a specific word (bounded by word boundaries).
    assertFileNotContainsWord() Assert that a file does not contain a specific word.
    assertFileEqualsFile() Assert that a file equals another file in contents.
    assertFileNotEqualsFile() Assert that a file does not equal another file in contents.

    Usage example:

    use PHPUnit\Framework\TestCase;
    use AlexSkrypnyk\File\Tests\Traits\FileAssertionsTrait;
    
    class MyTest extends TestCase {
      use FileAssertionsTrait;
    
      public function testFiles(): void {
        // Assert file contains "example" string
        $this->assertFileContainsString('example', '/path/to/file.txt');
    
        // Assert file contains "test" as a complete word
        $this->assertFileContainsWord('test', '/path/to/file.txt');
    
        // Assert file does not contain a partial word
        $this->assertFileNotContainsWord('exampl', '/path/to/file.txt');
    
        // Assert two files have identical content
        $this->assertFileEqualsFile('/path/to/expected.txt', '/path/to/actual.txt');
    
        // Assert two files have different content
        $this->assertFileNotEqualsFile('/path/to/expected.txt', '/path/to/actual.txt');
      }
    }

    Maintenance

    composer install
    composer lint
    composer test
    
    # Run performance tests
    ./vendor/bin/phpunit --testsuite=performance

    This repository was created using the Scaffold project template

    Visit original content creator repository https://github.com/AlexSkrypnyk/file
  • pinkoi-coins-bot

    Pinkoi 簽到機器人

    release github docker

    💰💰 每日簽到 Pinkoi 的機器人 💰💰

    執行方式

    請先安裝 dockerpodman。映像可於 Docker Hub hyperbola/pinkoi-coins-bot 或 GitHub Container Registry (ghcr) ghcr.io/wdzeng/pinkoi-coins-bot 取得。最新的 tag 為 1,tag 清單可見於 Docker Hub 或 ghcr。

    Pinkoi 登入的方式眾多。由於沒有辦法模擬 Google 帳號以及其他第三方平台登入的情況,使用者需要自備 cookie 給機器人登入。請將 cookie 字串存在檔案中餵給機器人。Pinkoi 的 cookie 通常會長得像下面這樣,注意一定只有一行。

    slocale=1; lang=zh_TW; b=20220603xxxxxxxx; __zlcmid=xxxxxxxxxxxxx; sessionid=xxxxxxxxxxxxxxxxxxxxxxxxxxx; sv=1.0; stv=1.0; ad=0; geo=TW; ci=HSQ; tz="Asia/Taipei"; c=TWD; country_code=TW; st=b'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; campaign=mission_game

    關於 cookie 的取得方式,請參考這份文件或這個影片

    Warning Cookie 是機密資訊,請妥善保存。

    使用說明

    使用 --help 參數。

    docker run -it hyperbola/pinkoi-coins-bot:1 --help

    每日簽到

    使用 --checkin 參數。

    docker run [-it] \
        -v /path/to/cookie:/cookie \
        hyperbola/pinkoi-coins-bot:1 --cookie /cookie --checkin

    解週末任務

    使用 --solve-weekly-mission 參數。

    docker run [-it] \
        -v /path/to/cookie:/cookie \
        hyperbola/pinkoi-coins-bot:1 --cookie /cookie --solve-weekly-mission

    參數

    執行機器人時,必須從 --checkin--solve-weekly-mission 中選擇恰一個執行。Cookie 是必填。

    • -c, --cookie: cookie 檔案位置
    • -s, --checkin: 每日簽到
    • -m, --solve-weekly-mission: 解週末任務
    • -q, --quiet: 不要印出訊息;警告和錯誤訊息仍會印出
    • -V, --version: 印出版本
    • -h, --help: 印出使用方式

    Exit Code

    Exit Code 解釋
    0 簽到或任務成功。
    1 簽到或任務失敗。
    69 登入失敗。這表示 cookie 有問題。
    87 參數錯誤。
    255 不明錯誤。

    姊妹機器人

    Visit original content creator repository https://github.com/wdzeng/pinkoi-coins-bot
  • glimpse

    glimpse Glacier Image Particle Sequencer

    tests coverage code style: black

    glimpse is a Python package built for quickly and precisely analyzing time-lapse photographs of glaciers. Some useful things one can do with glimpse:

    Camera calibration

    • glimpse.Camera: Model a distorted camera and perform incoming and outgoing ray projections, accounting for earth curvature and atmospheric refraction.
    • glimpse.convert: Convert between MATLAB, OpenCV, Agisoft PhotoScan, PhotoModeler, and glimpse camera formats, accounting for uncertainties in camera parameters.
    • glimpse.optimize: Perform single and multi-camera calibrations (controlling which parameters are fixed, varied, or synched across multiple cameras) using points and lines in image and world coordinates.
    • glimpse.svg: Load manual vector image annotations as inputs for camera calibration.
    • glimpse.Raster.horizon(): Compute the visible horizon from a position as input for camera calibration.
    • glimpse.Camera.project_dem(): Generate photorealistic synthetic images (and depth maps) from a camera model, gridded elevations, and optional orthophoto for automated control point collection and camera model validation.
    • glimpse.optimize.KeypointMatcher: Stabilize photographic sequences of arbitrary length using automatic image matching and globally optimal orientation estimates.

    Velocity tracking

    • glimpse.Tracker: Compute the velocity (and corresponding uncertainty) of points visible in photographs taken from one or more positions.
    • glimpse.Raster.viewshed(): Compute the viewshed of a position, for tracking point selection.

    References

    The methods implemented in this software are described in great detail across two PhD dissertations.

    • Douglas Brinkerhoff (2017): Bayesian methods in glaciology, chapter 4. Uses particle filtering to extract velocities from one year of oblique time-lapse images of Columbia Glacier, Alaska.

    • Ethan Welty (2018): High-precision photogrammetry for glaciology. Calibrates and stabilizes time-lapse cameras using landscape cues, extends the particle filter from 2-d to 3-d (to account for uncertain surface elevations), and uses the methods on thirteen years of oblique time-lapse images of Columbia Glacier, Alaska.

    Installation

    glimpse has not yet been released for distribution, but can still be installed with pip from the source code on GitHub:

    pip install git+https://github.com/ezwelty/glimpse

    The installation requires gdal to be present. The simplest way of achieving this is to install gdal into a conda environment:

    conda create -n glimpse -c conda-forge python=3.8 gdal=3.2.0
    conda activate glimpse
    pip install git+https://github.com/ezwelty/glimpse

    Contribute

    Thank you for considering contributing to glimpse!

    What follows is intended to make contribution more accessible by codifying conventions. Don’t be afraid to open unfinished pull requests or to ask questions if something is unclear!

    • No contribution is too small.
    • Try to limit each pull request to one change only (one bug fix, one new feature).
    • Always add tests and docstrings for your code.
    • Make sure your changes pass the continuous integration tests.

    Code & docstrings

    Code follows PEP 8. It is formatted (automatically, if you use the pre-commit hooks) to conform to the black code style and import order with a maximum line length of 88 characters.

    Docstrings follow PEP 257 and the Google style, with the exception of using section title "Arguments:" instead of "Args:". Argument and return types are specified as type annotations and not included in the docstrings. Examples are formatted for testing by doctest. Unless the docstring fits in a single line, the """ are on separate lines.

    def xyz_to_uv(xyz: np.ndarray) -> np.ndarray:
        """
        Convert world coordinates to image coordinates.
    
        Arguments:
            xyz: World coordinates (n, [x, y, z]).
    
        Returns:
            Image coordinates (n, 2).
    
        Examples:
            >>> xyz = np.array([[0., 1., 0.]])
            >>> xyz_to_uv(xyz)
            array([[ 50.,  50.]])
        """

    Tests

    Unit tests are written for pytest. As with the rest of the code, they should include type annotations and good docstrings.

    To run the full test suite on the current Python version, simply run:

    make test

    if you have make installed, or run the equivalent:

    poetry run pytest --doctest-modules src tests

    The package manager poetry (see below) will manage the virtual environment and dependencies for you. To easily install and switch between different Python versions, consider using pyenv.

    Development environment

    Before you begin, you will need to have gdal, a modern stable release of Python 3, and the package manager poetry. For example, using conda:

    conda activate base
    conda install -c conda-forge python=3.8 gdal=3.2.0 poetry=1

    First, clone the glimpse repository and change into the newly created directory:

    git clone https://github.com/ezwelty/glimpse
    cd glimpse

    Use poetry to install glimpse (and its dependencies) into a new virtual environment linked to your current Python version:

    poetry install

    Run commands on this virtual environment using poetry run. For example, run unit tests with:

    poetry run pytest
    

    or open a Python console with:

    poetry run python

    To avoid committing code that breaks tests or violates the style guide, consider installing pre-commit (if needed) and installing the hooks:

    pre-commit install

    You can run the pre-commit hooks anytime using:

    pre-commit run --all-files

    Other useful commands are listed in the Makefile. For example, to build the documentation:

    make docs
    # Equivalent to:
    # poetry run sphinx-build docs docs/build
    Visit original content creator repository https://github.com/ezwelty/glimpse