Skip to content

Instantly share code, notes, and snippets.

View ZeekoZhu's full-sized avatar
📖
Learning

Zeeko ZeekoZhu

📖
Learning
View GitHub Profile
ALTER TABLE TableName
CHARSET = 'utf8mb4',
MODIFY COLUMN ColumnName LONGTEXT CHARACTER SET 'utf8mb4';
@ZeekoZhu
ZeekoZhu / ElmArch.ts
Last active September 17, 2019 21:15
An Elm LIKE state management approach based on RxJS
import 'rxjs/add/operator/scan';
import 'rxjs/add/operator/do';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { Subject } from 'rxjs/Subject';
type UpdateResult<TState, TMsgType> = TState | [TState, TMsgType[]];
type Pattern<TMsg, TState, TMsgType> =
[new (...args: any[]) => TMsg, (acc: TState, msg: TMsg, $msg: Subject<TMsgType>) => UpdateResult<TState, TMsgType>];
alias stls="sudo systemctl start"
alias stlr="sudo systemctl restart"
alias stlR="sudo systemctl daemon-reload"
alias stlp="sudo systemctl stop"
alias stl="sudo systemctl status"
@ZeekoZhu
ZeekoZhu / .vimrc
Created February 21, 2018 03:39
My Vim
set cursorline
set cursorcolumn
highlight CursorColumn ctermbg=darkgrey
"显示行号
set nu
"启动时隐去援助提示
set shortmess=atI
"语法高亮
syntax on
"不需要备份
@ZeekoZhu
ZeekoZhu / arch_init.sh
Last active December 7, 2018 09:19
Arch Linux Initialization
#!/bin/bash
USERNAME='zeeko'
HOSTNAME='hostodo'
SS_PORTNO='2333'
SS_METHOD='aes-256-gcm'
SS_PASSWD='password'
# Repo
cat >> /etc/pacman.conf << EOF

Keybase proof

I hereby claim:

  • I am ZeekoZhu on github.
  • I am zeeko (https://keybase.io/zeeko) on keybase.
  • I have a public key whose fingerprint is 9FBD B6A1 696B 5F41 4A54 D91C 24F6 64AA AC87 4752

To claim this, I am signing this object:

#http://jongurgul.com/blog/get-stringhash-get-filehash/
Function FixEncoding ([parameter(ValueFromPipeline)][String] $string) {
$utf8 = [System.Text.Encoding]::UTF8
$iso88591 = [System.Text.Encoding]::GetEncoding(28591)
$wrongBytes = $utf8.GetBytes($string)
$rightBytes = [System.Text.Encoding]::Convert($utf8, $iso88591, $wrongBytes)
$utf8.GetString($rightBytes)
}
Function TryConnectWifi($wlanProfile) {
$res = Invoke-Command -ScriptBlock {netsh wlan connect $wlanProfile}
eval = (\char reducer fn -> String.split char >> List.map (String.trim >> fn) >> List.foldr reducer (if char == "+" || char == "-" then 0 else 1)) |> \op -> (String.toFloat >> Maybe.withDefault 0) |> op "*" (*) |> op "/" (/) |> op "-" (-) |> op "+" (+)
@ZeekoZhu
ZeekoZhu / arch_init.sh
Last active November 29, 2018 12:25 — forked from rocka/arch_init.sh
Arch Linux VPS initialize script
#!/bin/bash
USERNAME='zeeko'
HOSTNAME='arch'
# pacman Color
sed -i 's/#Color/Color/g' /etc/pacman.conf
# Repo
cat >> /etc/pacman.conf << EOF
@ZeekoZhu
ZeekoZhu / Content.md
Last active December 8, 2018 05:34
[Angular Forms - 自定义 ngModel 绑定值的方式] #Angular

Angular Forms - 自定义 ngModel 绑定值的方式

在 Angular 应用中,我们有两种方式来实现表单绑定——“模板驱动表单”与“响应式表单”。这两种方式通常能够很好的处理大部分的情况,但是对于一些特殊的表单控件,例如input[type=datetime]input[type=file],我们需要重写默认的表单绑定方式,让我们绑定的变量不再仅仅只是一个字符串,而是一个 Date 或者 File 对象。为了达成这一目的,我们需要自定义表单控件的 ControlValueAccessor

ControlValueAccessor 接口是 Angular Forms API 与 DOM 之间的桥梁,通过提供不同的 ControlValueAccessor,我们就可以使用统一的 Angular Forms API 来操作不同的 HTML 表单元素。

在我们使用 ngModel 或者 formControl 的时候,这两个 Directive 会向 Angular 的依赖注入容器申请实现了 ControlValueAccessor 接口的对象,这是一种典型的面向接口编程的设计。例如,如果我们需要为 input[type=file] 提供一个用来绑定 File 对象的 ControlValueAccessor,只需要在依赖注入容器中提供一个 FileControlValueAccessor 的实现就可以了。不过,我们并不想覆盖其他类型 input 元素的 ControlValueAccessor,因为那样肯定会对已有代码造成大范围的破坏。所以在这里,我们需要使用 Angular 的分层注入能力——在 ElementInjector 中提供 FileControlValueAccessor。关于 ElementInjector 更多的内容,请看这里 a-curios-case-of-the-host-decorator-and-element-injectors-in-angular

下面演