Skip to content

Instantly share code, notes, and snippets.

@Moln
Moln / parse_url_query-functions.sql
Last active December 25, 2022 00:54
Postgresql from url_query to json function
CREATE OR REPLACE FUNCTION urldecode(p varchar) RETURNS varchar AS $$
SELECT convert_from( CAST(E'\\x' || string_agg( CASE WHEN length(r.m[1]) = 1 THEN encode(convert_to(r.m[1], 'SQL_ASCII'), 'hex') ELSE substring(r.m[1] from 2 for 2) END, '') AS bytea), 'UTF8')
FROM regexp_matches(replace($1, '+', ' '), '%[0-9a-f][0-9a-f]|.', 'gi') AS r(m);
$$ LANGUAGE SQL STRICT;
CREATE OR REPLACE FUNCTION parse_url_query(p varchar) RETURNS json AS $$
with kv as (
select urldecode(kv[1]) k, urldecode(kv[2]) v from (select string_to_array(i, '=') kv from unnest(string_to_array(TRIM(BOTH '&' FROM $1), '&')) as s(i))
)
select json_object(array(select k from kv), array(select v from kv));
@Moln
Moln / DoctrineOrmPool.php
Created December 22, 2022 01:22
swoole doctrine orm pool example
<?php
use Doctrine\DBAL\Exception\ConnectionLost;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Swoole\ConnectionPool;
/**
*/
@Moln
Moln / wsl2-net.bat
Created April 13, 2022 14:06
WSL2 固定局域网IP
wsl -d Ubuntu-20.04 -u root ip addr del $(ip addr show eth0 ^| grep 'inet\b' ^| awk '{print $2}' ^| head -n 1) dev eth0
wsl -d Ubuntu-20.04 -u root ip addr add 192.168.50.2/24 broadcast 192.168.50.255 dev eth0
wsl -d Ubuntu-20.04 -u root ip route add 0.0.0.0/0 via 192.168.50.1 dev eth0
wsl -d Ubuntu-20.04 -u root echo nameserver 192.168.50.1 ^> /etc/resolv.conf
powershell -c "Get-NetAdapter 'vEthernet (WSL)' | Get-NetIPAddress | Remove-NetIPAddress -Confirm:$False; New-NetIPAddress -IPAddress 192.168.50.1 -PrefixLength 24 -InterfaceAlias 'vEthernet (WSL)'; Get-NetNat | ? Name -Eq WSLNat | Remove-NetNat -Confirm:$False; New-NetNat -Name WSLNat -InternalIPInterfaceAddressPrefix 192.168.50.0/24;"
@Moln
Moln / Api-platform研究记录.md
Last active January 17, 2020 04:57
Api-platform研究记录
  • Entity 生成路由

    • ApiPlatform 会根据 Entity 的 @ApiResource 注解, 自动生成路由.
    • 路由名称, 由 Inflector::pluralize(Greeting::class) 自动生成 /greetings 复数形式的资源名称
    • 单词间默认是 _ 分隔, 文档有记录更改单词分隔符
  • 自定义资源方式?

  • 过滤器原理?

  • 迁移Expressive 方案?

@Moln
Moln / shell_notes.md
Created January 14, 2019 09:14
Linux Shell 笔记

本地代理开放给外网服务器

ssh -NfT -D 10080 root@localhost
ssh -N -f -b 0.0.0.0 -R 10080:localhost:10080 root@remote.host
@Moln
Moln / 系统服务收集.md
Created June 27, 2018 00:50
系统服务收集

上监控系统:

  • Zabbix
  • Open-Falcon
  • Prometheus
  • Grafana
  • elk
@Moln
Moln / Vue 文件打包错误.md
Created March 7, 2018 09:30
Vue 文件打包错误
Vue packages version mismatch:

- vue@2.5.10
- vue-template-compiler@2.5.13

This may cause things to work incorrectly. Make sure to use the same version for both.
If you are using vue-loader@>=10.0, simply update vue-template-compiler.
If you are using vue-loader@<10.0 or vueify, re-installing vue-loader/vueify should bump vue-template-compiler to the latest.
@Moln
Moln / PHP面试题.md
Last active December 27, 2018 10:36
PHP面试题

PHP面试题

PHP基础

1. 请写出以下结果:

echo json_encode(['a' => 1] + ['b' => 2, 'a' => 3, 'b']);

Html_video倒序播放功能

HTMLVideoElement.prototype.playBackwards = function() {
    this.pause();
    var video = this;
    var fps = video.fps || 25;
    var wait = 1000 / fps;
 var intervalRewind = setInterval(function() {
@Moln
Moln / mysql_note.md
Last active September 15, 2017 01:40
Mysql 处理大数据那些坑

数据 insert 效率只有每秒300

原因: mysql innodb引擎开启了日志事务功能,参数配置:my.cnf 默认 innodb_flush_log_at_trx_commit=1 调整为0;

修改后 insert 大概每秒 5000,

Delete 后的数据表,影响索引?

发现一数据总数据1700万, 由于程序脚本编写BUG导致, 向数据表误导入500+万数据. 经 Delete 语法删除尾部多余的 500+万数据后.