Skip to content

Instantly share code, notes, and snippets.

@zhmxx
zhmxx / linux-command-cheatsheet.md
Last active September 27, 2021 11:49
Commonly used Linux commands

Network

ifconfig
lsof
ssh
ping

Text Processing

cat
vi/vim
less \

@zhmxx
zhmxx / .bash_aliases
Last active October 19, 2021 01:28
Frequently used bash resources
#!/bin/bash
# Aliases added to shell
alias vi='vim'
alias pg='ps aux|grep'
alias ll='ls -alFh'
// This is used to check if native JavaScript methods are overridden by a third-party source
function checkObject() {
['assign', 'create', 'defineProperty', 'defineProperties', 'entries', 'freeze',
'getOwnPropertyDescriptor', 'getOwnPropertyNames', 'getOwnPropertySymbols',
'getPrototypeOf', 'is', 'isExtensible', 'isFrozen', 'isSealed', 'keys',
'preventExtensions', 'seal', 'setPrototypeOf', 'values'].forEach(method => {
if (!Object[method]) {
console.warn(`Object.${method} method is missing.`);
} else if (Object[method].toString() !== `function ${method}() { [native code] }`) { // For Safari, the code is `function ${method}() {\n [native code]\n}`
@zhmxx
zhmxx / online-tools.md
Last active December 16, 2021 05:40
Online Tools
@zhmxx
zhmxx / cpp.md
Last active September 28, 2020 01:23
C++ cheat sheet

Smart Pointer

How to implement a smart pointer class which can automatically convert smart pointer of derived class to smart pointer of base class?

For example:

template <class T>
class smart_ptr { ... };

class Shape {};

class Circle : public Shape {};

@zhmxx
zhmxx / laravel.md
Last active September 15, 2020 11:52
Work with Laravel

Install composer on Ubuntu

apt install composer

Install dependencies

cd laravel
composer install

Create database in MySQL

Initialize DB

In MySQL 5.7, it uses auth_socket for authentication if we don't provide root password when installing MySQL. We can use below code to swith back to password authentication:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'MyNewPassword';
For details, see: https://www.percona.com/blog/2016/03/16/change-user-password-in-mysql-5-7-with-plugin-auth_socket/
@zhmxx
zhmxx / gist:5cf0f738330e69f1c35d3219d2179427
Created September 11, 2020 12:07
Vue behind a corporate proxy
const HttpProxyAgent = require('http-proxy-agent');
const proxyServer = 'http://corporate.proxy:8080';
...
'/api': {
target: 'http://a.b.c',
secure:false,
pathRewrite: {'^/api':''},
agent:new HttpProxyAgent(proxyServer),
}
@zhmxx
zhmxx / gist:b9a02aadfa40ed50afbde2a2655a82e3
Last active September 14, 2020 02:06
微信支付对接流程
1. 注册微信支付商户号
2. 购买域名并备案,然后在微信商户号中进行配置
3. 注册微信开放平台账号,申请App/网站应用,并进行开发者资质认证
4. 在微信支付商户号中关联开放平台的App ID
5. 开发对接
@zhmxx
zhmxx / FormattedOutputDebugString.cpp
Created September 10, 2020 01:46
Formatted OutputDebugString (Windows, Win32)
void DebugOut(wchar_t *fmt, ...)
{
va_list argp;
va_start(argp, fmt);
wchar_t dbg_out[4096];
vswprintf_s(dbg_out, fmt, argp);
va_end(argp);
OutputDebugString(dbg_out);
}