Skip to content

Instantly share code, notes, and snippets.

@suguanYang
suguanYang / prototype.md
Last active May 25, 2019 03:21
Javascript prototype

prototype

The prototype is a property of a functionconstructor function or classes6. It used for define class's members, like fields and methods, and it's instance(new) will inherit these members. When an instance calls the members it inherited from a class, it dosent look for it's prototype, beacuse an instance dosent has prototype property. What are the members come form? The __proto__ do this, so we talk about 'protorype chain' more likes __proto__.__proto__.__proto__ than protorype.protorype.protorype, the instance.__proto_ === class.prototype is true. we find members from it! So what the prototype is? from the above, we know when we create a instance, the __proto__ will refers to prototype object, we also can say it is used for create __proto__

@suguanYang
suguanYang / module.md
Last active April 26, 2019 12:46
module.md

1 Overview

JavaScript has had modules for a long time. However, they were implemented via libraries, not built into the language. ES6 is the first time that JavaScript has built-in modules.

ES6 modules are stored in files. There is exactly one module per file and one file per module. You have two ways of exporting things from a module. These two ways can be mixed, but it is usually better to use them separately.

1.1 Multiple named exports

There can be multiple named exports:

@suguanYang
suguanYang / fcg.md
Created May 5, 2019 07:36
Free-context grammar

What is grammar?

Grammas are the language of languages. A grammar defines a language. Behind every language, there is a grammar that determines its structure.

Context-free grammar

In computer science, the most common type of grammar is the context-free grammar. Context-free grammars have sufficent richness to describle the recursive syntactic structure of many languages.

Components of a context-free grammar.

A set of rules is the core components of a grammar. Each rule has two parts: (1)a name and (2) an expression of the name. For instance, if we were creating a grammar to handle english text, we might add a rule like: noun-phras may expand into article noun

The idea of *shunting yard algorithm* is to keep operators on a stack until their operands have been parsed. The operands are
kept on a second stack. The *shunting yard algorithm* can be used to directly evaluate expressions as they are parsed, to create
a reverse Polish notation of an infix expression, or to create an AST. I'll create an AST, so my operand stacks will contain trees
The key to the algorithm is to keep the operators on the operator stack odered by precedence(lowest at bottom and highest at the top)
at least in the absence of parenthese. Before pushing an operator onto the operator stack, all higher precedence operators are cleard
from the stack. Clearing an operator consists of removing the operator from the operator stack and its operands from the operand stack
making a new tree, and pushing that tree onto the operand stack. At the end of an expression the remaining operators are put into
trees with their operands and that is that.
@suguanYang
suguanYang / solustion.md
Last active May 23, 2019 04:01
gem install libxml-ruby fail

The error is

Building native extensions.  This could take a while...
ERROR:  Error installing libxml-ruby:
	ERROR: Failed to build gem native extension.

    current directory: /Users/<username>/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/libxml-ruby-3.1.0/ext/libxml
/Users/<username>/.rbenv/versions/2.3.7/bin/ruby -r ./siteconf20190523-40908-1mq6z0c.rb extconf.rb
checking for libxml/xmlversion.h in /opt/include/libxml2,/opt/local/include/libxml2,/usr/local/include/libxml2,/usr/include/libxml2... no
*** extconf.rb failed ***
@suguanYang
suguanYang / postgres-brew.md
Created October 12, 2019 07:46 — forked from ibraheem4/postgres-brew.md
Installing Postgres via Brew (OSX)

Installing Postgres via Brew

Pre-Reqs

Brew Package Manager

In your command-line run the following commands:

  1. brew doctor
  2. brew update
@suguanYang
suguanYang / golang snippets
Last active December 8, 2019 09:15
golang
__dirname
```
_, filename, _, ok := runtime.Caller(0)
if !ok {
panic("No caller information")
}
__dirname := path.Dir(filename)
```
telnet exampledomain.com 25
Trying 1.1.1.1...
Connected to exampledomain.com (1.1.1.1).
Escape character is '^]'.
220-server1.exampledomain.com ESMTP Exim 4.66 #1 Wed, 01 Jua 2020 23:55:12 +0200
220-We do not authorize the use of this system to transport unsolicited,
220 and/or bulk e-mail.
EHLO exampledomain.com
250-server1.exampledomain.com Hello [1.1.1.2]
250-SIZE 52428800
#!/bin/bash
set -e
curl -L -O http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country-CSV.zip
unzip GeoLite2-Country-CSV.zip
rm GeoLite2-Country-CSV.zip
when do migrations, if want make Backward Compatibility, you can add the new function above the old one