Skip to content

Instantly share code, notes, and snippets.

View guanguans's full-sized avatar
🏠
Working from home

guanguans guanguans

🏠
Working from home
View GitHub Profile

Localizable.strings

lint

<?php

declare(strict_types=1);

require __DIR__.'/vendor/autoload.php';
@guanguans
guanguans / json-error.php
Last active February 24, 2023 13:38
#json #php
<?php
// json_decode returns NULL with validated json data, error: "Control character error, possibly incorrectly encoded"
json_decode(preg_replace('/[[:cntrl:]]/mu', '', $json), true);
@guanguans
guanguans / long-running-curl-sse.php
Created December 16, 2022 09:48 — forked from kinlane/long-running-curl-sse.php
Long Running PHP CURL Requests To Handle Server Sent Events (SSE)
<?php
// prepare headers for API call
$request_headers = array();
// prepare the url of the api I am calling
$api_url = "http://api.example.com?parameters=whatever";
// append streamdata sandbox proxy
$url = 'https://streamdata.motwin.net/' . $api_url;
@guanguans
guanguans / groupByTopN.md
Last active December 15, 2022 07:55
groupByTopN
<?php
// 子查询
ServerNotice::query()
  ->select('*')
  ->whereRaw('(SELECT COUNT(*) FROM xb_server_notice AS sn WHERE xb_server_notice.zone_id = sn.zone_id AND xb_server_notice.updated_at < sn.updated_at) < 2')
  ->orderBy('zone_id')
  ->orderByDesc('updated_at')
 -&gt;get()
@guanguans
guanguans / HandlerStack.md
Last active November 9, 2022 10:39
#HandlerStack

使用

示例

<?php

use App\HandlerStack;
@guanguans
guanguans / curl-multi.php
Last active November 3, 2022 07:32
#curl
<?php
/**
* curl 并发请求示例
*/
$startTime = microtime(true);
$curls = [];
for ($i = 1; $i <= 10; $i++) {
// 创建 curl 句柄
$curls[$i] = $curl = curl_init();
@guanguans
guanguans / Pimple.md
Last active June 30, 2022 10:00
#php #Pimple #Container

本文由 简悦 SimpRead 转码, 原文地址 github.com

Caution!

This is the documentation for Pimple 3.x. If you are using Pimple 1.x, read the Pimple 1.x documentation. Reading the Pimple 1.x code is also a good way to learn more about how to create a simple Dependency Injection Container (recent versions of Pimple are more focused on performance).

Pimple 是一个简单的 PHP 依赖注入容器 (Dependency Injection Container)。

安装

@guanguans
guanguans / Mist.php
Created June 30, 2022 06:20
#php #mist
<?php
/**
* 薄雾算法
*
* 1 2 48 56 64
* +------+-----------------------------------------------------+----------+----------+
* retain | increas | salt | sequence |
* +------+-----------------------------------------------------+----------+----------+
* 0 | 0000000000 0000000000 0000000000 0000000000 0000000 | 00000000 | 00000000 |
@guanguans
guanguans / export.md
Last active May 18, 2022 03:35
#excel ajax 导出

Excel ajax 导出

Export

<?php

namespace App\Exports;

use App\Models\Product;
@guanguans
guanguans / Laravel-Container.md
Created March 2, 2022 19:15
Laravel's Dependency Injection Container in Depth

Laravel's Dependency Injection Container in Depth

Translations: Korean (by Yongwoo Lee)

Laravel has a powerful Inversion of Control (IoC) / Dependency Injection (DI) Container. Unfortunately the official documentation doesn't cover all of the available functionality, so I decided to experiment with it and document it for myself. The following is based on Laravel 5.4.26 - other versions may vary.

Introduction to Dependency Injection

I won't attempt to explain the principles behind DI / IoC here - if you're not familiar with them you might want to read What is Dependency Injection? by Fabien Potencier (creator of the Symfony framework).