Giter Club home page Giter Club logo

blog's Introduction

blog

blog's People

Contributors

jkmiva avatar

Stargazers

 avatar

Watchers

 avatar  avatar

blog's Issues

dig into typescript-01

1. index signatures

interface SquareConfig {
    color?: string;
    width?: number;
    [propertyName: string]: any;
}

here we are saying a SquareConfig can have any number of properties, and as long as they are not color or width, their types don't matter.

interface StringArray {
    [index: number]: string;
}
let myArray: StringArray;
myArray = ["Bob", "Fred"];

let myStr: string = myArray[0];

This index signature states that when a StringArray is indexed with a number, it will return a string

2. function types

interface SearchFunc {
    (source: string, subString: string): boolean;
}
let mySearch: SearchFunc;
mySearch = function(source: string, subString: string) {
    let result = source.search(subString);
    return result > -1;
}

3.hybrid types

interface Counter {
    (start: number): string;
    interval: number;
    reset(): void;
}

function getCounter(): Counter {
    let counter = <Counter>function (start: number) { };
    counter.interval = 123;
    counter.reset = function () { };
    return counter;
}

let c = getCounter();
c(10);
c.reset();
c.interval = 5.0;

an object that acts as both a function and an object, with additional properties

availableReplicas vs readyReplicas

任何pod处于“健康”状态下(至少container要运行正常)即为 ready 状态
ready 状态持续了 minReadySeconds 以后就同时也是available状态。

That's to say, availableReplicas is any readyRelicas that last for at least minReadySeconds seconds.

ES7

ES7 contains only two new features.
Any proposal at stage 4 will be included in new release of ECMA-262

Array.prototype.includes

[1,2,3].includes(1) // return true
[1,2,3].includes(99) // return false

exponentiation operator (**)

2 ** 3 === 8

settability of reflection object in golang

var a float64 = 3.14
v := reflect.ValueOf(a)
v.SetFloat(5.6)    // Error, will panic

This code does not work which means v is not settable.
Settability is a property of reflection object, the CatSet method can check settability of a Value.
Settability is determined by whether the reflection object holds the original item. When we say

var a float64 = 3.14
v := reflect.ValueOf(a)

We pass a copy of a to reflect.Value, so the Interface value created as the argument to
reflect.ValueOf is a copy of a, not a itself.

The correct version:

var a float64 = 3.14
p := reflect.ValueOf(&a) // Note: take the address of a.
fmt.Println("type of p:", p.Type())
fmt.Println("settability of p:", p.CanSet()) // Note: p it self is a pointer copy, so p is not settable)
v := p.Elem() // get what p points to
fmt.Println("settability of v:", v.CanSet()) // print 'true'
v.SetFloat(7.1)
fmt.Println(v.Interface()) // print 7.1
fmt.Println(x) // print 7.1

Concerning a struct T, the fields name of T shoud be Uppercase(exported) because only exported
fields of a struct are settable

channel communication of golang

  • The closing of a channel happens before a receive that returns a zero value because the channel is closed
  • The kth receive on a channel with capacity C happens before the k+Cth send from that
    channel completes
// at most three are running work at a time
var limit = make(chan int, 3)
func main() {
    for _, w := range works {
        go func(w func()) {
            limit <- 1
            w()
            <- limit
        }(w)
    }
    select{}
}

logger based on proxy

之前写的一个demo用proxy实现了简单的logger效果, 监听 构造函数(new) 和 send 方法

let WebSocketLogger = new Proxy(window.WebSocket,{
    construct: function(target, args, recver) {
        ret = Reflect.construct(target, args)
        let oFn = e=>console.log('WSOpen: ', e)
        let mFn = e=>console.log('WSMessage: ', e)
        let cFn = e=>console.log('WSClose: ', e)
        let eFn = e=>console.error('WSError: ', e)
        ret.addEventListener('open',oFn)
        ret.addEventListener('message',mFn)
        ret.addEventListener('close',cFn)
        ret.addEventListener('error',eFn)
        let sendProxy = new Proxy(ret.send, {
            apply: function(target, thisArg, args) {
                console.log('[WSSending] ', ...args)
                Reflect.apply(...arguments)
            }
        })
        ret.send = sendProxy
        return ret
    }
})

z-index

  • z-index only applies on positioned element and its descendants.
  • Values
    • auto The box doesn't create a new local stacking context. The stack level of the generated box in the current stacking context is the same as its parent's box.
    • integer This integer is the stack level of the generated box in the current stacking context. The box also establishes a local stacking context in which its stack level is 0. This means that the z-indexes of descendants are not compared to the z-indexes of elements outside this element.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.