Skip to content

Instantly share code, notes, and snippets.

View wudi's full-sized avatar
🎯
Focusing

Di Wu wudi

🎯
Focusing
View GitHub Profile
<?php
function distance($data1, $data2) {
$num = 0;
for ($i = 0; $i < sizeof($data1); $i++) {
$num += pow($data1[$i] - $data2[$i], 2);
}
return sqrt($num);
}

集群

CLUSTER INFO 打印集群的信息

CLUSTER NODES 列出集群当前已知的所有节点(node),以及这些节点的相关信息。

节点

127.0.0.1:12345> TTL key # 尚未过期
(integer) 3
127.0.0.1:12345> TTL key
(integer) 1
127.0.0.1:12345> TTL key # 虽然键已经过期,但因为我阻塞住了主服务器,
(integer) 0 # 而主服务器没办法向从服务器发送 DEL 命令,所以值会一直滞留在从服务器里面。
127.0.0.1:12345> GET key
"value"
127.0.0.1:12345> TTL key
(integer) 0
@wudi
wudi / nginxvarcore.md
Created December 12, 2015 08:52 — forked from esfand/nginxvarcore.md
Nginx Variables

Embedded Variables

The ngx_http_core_module module supports embedded variables with names matching the Apache Server variables. First of all, these are variables representing client request header fields, such as $http_user_agent, $http_cookie, and so on. Also there are other variables:

  • $arg_name
    argument name in the request line
@wudi
wudi / Makefile.golang
Created June 13, 2016 03:29 — forked from dnishimura/Makefile.golang
Makefile for Golang projects
# Makefile for a go project
#
# Author: Jon Eisen
# site: joneisen.me
#
# Targets:
# all: Builds the code
# build: Builds the code
# fmt: Formats the source files
# clean: cleans the code
@wudi
wudi / benchmark+go+nginx.md
Created August 29, 2016 14:51 — forked from hgfischer/benchmark+go+nginx.md
Benchmarking Nginx with Go

Benchmarking Nginx with Go

There are a lot of ways to serve a Go HTTP application. The best choices depend on each use case. Currently nginx looks to be the standard web server for every new project even though there are other great web servers as well. However, how much is the overhead of serving a Go application behind an nginx server? Do we need some nginx features (vhosts, load balancing, cache, etc) or can you serve directly from Go? If you need nginx, what is the fastest connection mechanism? This are the kind of questions I'm intended to answer here. The purpose of this benchmark is not to tell that Go is faster or slower than nginx. That would be stupid.

So, these are the different settings we are going to compare:

  • Go HTTP standalone (as the control group)
  • Nginx proxy to Go HTTP
  • Nginx fastcgi to Go TCP FastCGI
  • Nginx fastcgi to Go Unix Socket FastCGI
@wudi
wudi / main.go
Created January 8, 2018 03:06 — forked from petergloor/main.go
MaxInt, MinInt, MaxUint and MinUint in Go (golang)
package main
import "fmt"
// Constant definitions
const MaxUint = ^uint(0)
const MinUint = 0
const MaxInt = int(^uint(0) >> 1)
const MinInt = -MaxInt - 1
@wudi
wudi / parallels_tools_ubuntu_new_kernel_fix.md
Created June 13, 2018 02:51 — forked from rudolfratusinski/parallels_tools_ubuntu_new_kernel_fix.md
Parallels Tools fix for Ubuntu 18.04 and other Linux distributions with Kernel version >= 4.15

Preparation

  • In open Ubuntu 18.04 machine click Parallels Actions -> "Install Parallels Tools"

  • A "Parallels Tools" CD will popup on your Ubuntu desktop.

  • Open it by double mouse click, copy all the content to a new, empty directory on a desktop, name it for e.g. "parallels_fixed"

  • Open terminal, change directory to parallels_fixed (cd ~/Desktop/parallels_fixed)

  • Make command line installer executable (chmod +x install)

  • Change directory to "installer" (cd installer)

  • Make few other scripts executable: chmod +x installer.* *.sh prl_*

@wudi
wudi / nospm.user.js
Created June 14, 2018 08:18 — forked from ambar/nospm.user.js
nospm 移除虾米、淘宝和天猫网址中的 spm 参数(包括地址栏和页面中的链接):https://chrome.google.com/webstore/detail/nospm/dlkfdpdjhnonlhjhelnfaninbdggnkgl
// ==UserScript==
// @name nospm
// @version 1.1
// @description 移除虾米、淘宝和天猫网址中的 spm 参数(包括地址栏和页面中的链接)
// @include *://*.xiami.com/*
// @include *://*.taobao.com/*
// @include *://*.tmall.com/*
// ==/UserScript==
let forEach = Function.call.bind([].forEach)
@wudi
wudi / Laravel-Container.md
Created June 29, 2018 09:39
Laravel's Dependency Injection Container in Depth

Laravel's Dependency Injection Container in Depth

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).

Accessing the Container