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
@guanguans
guanguans / 1 Types.md
Created July 30, 2024 02:01 — forked from MrPunyapal/1 Types.md
Types In PHP

Atomic Types (Built-in and Scalar)

// Built-in types
$variable = null;             // null type

// Scalar types
$boolVar = true;              // bool type
$intVar = 42;                 // int type
$floatVar = 3.14;             // float type
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH

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 |