Skip to content

Instantly share code, notes, and snippets.

View imhuwq's full-sized avatar

Hu WQ imhuwq

View GitHub Profile
@imhuwq
imhuwq / console.save.js
Created March 12, 2020 04:24 — forked from raecoo/console.save.js
Save JSON object to file in Chrome Devtool
// e.g. console.save({hello: 'world'})
(function(console){
console.save = function(data, filename){
if(!data) {
console.error('Console.save: No data')
return;
}
if(!filename) filename = 'console.json'
if(typeof data === "object"){
data = JSON.stringify(data, undefined, 4)
@imhuwq
imhuwq / install_nginx_macos_source.md
Created February 25, 2020 09:50 — forked from beatfactor/install_nginx_macos_source.md
Install Nginx on Mac OS from source (without brew)

Install Nginx on Mac OS from source

no Homebrew required

1. Download Nginx

$ cd /usr/local/src
$ curl -OL http://nginx.org/download/nginx-1.12.2.tar.gz
$ tar -xvzf nginx-1.12.2.tar.gz && rm nginx-1.12.2.tar.gz
@imhuwq
imhuwq / build_ffmpeg.sh
Last active November 9, 2019 06:40
ubuntu 从源码编译 ffmpeg
apt-get update
# 一些常用工具包
apt-get install -y --no-install-recommends lsb-core net-tools dnsutils iputils-ping iftop htop telnet sudo openssh-server curl wget git vim locate
# 安装 ffmpeg 依赖
apt-get install -y --no-install-recommends autoconf automake build-essential cmake git-core libass-dev libfreetype6-dev
apt-get install -y --no-install-recommends libsdl2-dev libtool libva-dev libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev
apt-get install -y --no-install-recommends libxcb-xfixes0-dev pkg-config texinfo wget zlib1g-dev
apt-get install -y --no-install-recommends nasm yasm libx264-dev libx265-dev libnuma-dev libvpx-dev libfdk-aac-dev libmp3lame-dev libopus-dev
# 编译 ffmpeg 4.2.1
wget https://download-public-imhuwq.oss-cn-shenzhen.aliyuncs.com/ffmpeg/ffmpeg.4.2.1.tar.gz
@imhuwq
imhuwq / Recursion to Iteration.cpp
Created May 29, 2019 12:05
手动压栈循环替代非固定递归的通用方法
template<int resolve_order_, int num_child_stack_>
struct StackFrame {
typedef shared_ptr<StackFrame> StackFramePtr;
typedef shared_ptr<const StackFrame> kStackFramePtr;
// arguments
long long min;
long long max;
TreeNode *node;
@imhuwq
imhuwq / find_element_range_in_sorted_array.cpp
Created April 3, 2019 04:14
从一个有序 array 中找出目标的范围,要求 O(log(n)) 的时间复杂度。
#include <iostream>
#include <string>
#include <vector>
using namespace std;
// 给定一个排好序的数组,以及一个数字,求该数字在数组里面的任意一个可能位置。时间复杂度要求O(log(n))
int find_pos(const vector<int>& input_vec, int target, int lo, int hi) {
if (lo > hi) return -1;
@imhuwq
imhuwq / query_docker_images.py
Created April 2, 2019 06:52
查询 docker registry 里面都有哪些 docker 镜像
import os
import requests
def parse_authenticate(authenticate):
rv = dict()
pairs = authenticate.split(" ", 1)[-1]
pairs = pairs.split(",")
for pair in pairs:
name, value = pair.split("=")
@imhuwq
imhuwq / compute_prime.cpp
Last active April 2, 2019 06:55
筛选法获取质数
#include <malloc.h>
#include <iostream>
#include <vector>
#include <chrono>
using namespace std;
uint8_t *generate_bit_map(size_t length) {
size_t bytes_count = length / 8;
if (length % 8 != 0) bytes_count += 1;
@imhuwq
imhuwq / remove_linked_list_duplicated_elements.py
Created April 2, 2019 06:11
移除单向链表中的所有重复元素
class Node:
def __init__(self):
self.next = None
self.val = None
@classmethod
def from_list(cls, l):
pre = Node()
head = pre
for i in l:
@imhuwq
imhuwq / show_bits.cpp
Created April 2, 2019 05:09
显示变量的二进制形式
#include <stdio.h>
#include <iostream>
using namespace std;
typedef unsigned char *byte_pointer;
void show_bytes(byte_pointer start, size_t len) {
for (size_t i = 0; i < len; i++) {
printf(" %.2x", start[i]);
@imhuwq
imhuwq / Renew_ultraEdit.sh
Last active April 2, 2019 05:09
Ubuntu 重新开始试用 UltraEdit
rm -rfd ~/.idm/uex
rm -rf ~/.idm/*.spl
rm -rf /tmp/*.spl